From 99704dda5281b6d17822176a66291c26639c7313 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 16:09:56 -0400 Subject: [PATCH 01/22] Fix types on project embed --- src/routes/stories/project-embed.stories.svelte | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/routes/stories/project-embed.stories.svelte b/src/routes/stories/project-embed.stories.svelte index 9da2da7b0..14d6a8e65 100644 --- a/src/routes/stories/project-embed.stories.svelte +++ b/src/routes/stories/project-embed.stories.svelte @@ -1,4 +1,6 @@ - Date: Tue, 16 Apr 2024 16:18:46 -0400 Subject: [PATCH 02/22] types in note embed --- .../(embed)/documents/[id]/pages/[page]/+page.js | 6 ++---- src/routes/stories/page-embed.stories.svelte | 12 ++++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/routes/(embed)/documents/[id]/pages/[page]/+page.js b/src/routes/(embed)/documents/[id]/pages/[page]/+page.js index 2fb53c484..a8d04399b 100644 --- a/src/routes/(embed)/documents/[id]/pages/[page]/+page.js +++ b/src/routes/(embed)/documents/[id]/pages/[page]/+page.js @@ -10,11 +10,9 @@ export async function load({ params, fetch }) { notesApi.list(params.id, fetch), ]); - notes = notes.results.filter((note) => note.page_number === page - 1); - return { document, - notes, - page, + notes: notes.results.filter((note) => note.page_number === page - 1), + page: +page, }; } diff --git a/src/routes/stories/page-embed.stories.svelte b/src/routes/stories/page-embed.stories.svelte index 334d8e4f3..bd15b9566 100644 --- a/src/routes/stories/page-embed.stories.svelte +++ b/src/routes/stories/page-embed.stories.svelte @@ -1,4 +1,5 @@ - From 4a7946b5ed3e1599d5b8a9eac0103972f11e36ed Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 16:21:36 -0400 Subject: [PATCH 03/22] move embed stories under embed group --- src/routes/{ => (embed)}/stories/note-embed.stories.svelte | 0 src/routes/{ => (embed)}/stories/page-embed.stories.svelte | 0 src/routes/{ => (embed)}/stories/project-embed.stories.svelte | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/routes/{ => (embed)}/stories/note-embed.stories.svelte (100%) rename src/routes/{ => (embed)}/stories/page-embed.stories.svelte (100%) rename src/routes/{ => (embed)}/stories/project-embed.stories.svelte (100%) diff --git a/src/routes/stories/note-embed.stories.svelte b/src/routes/(embed)/stories/note-embed.stories.svelte similarity index 100% rename from src/routes/stories/note-embed.stories.svelte rename to src/routes/(embed)/stories/note-embed.stories.svelte diff --git a/src/routes/stories/page-embed.stories.svelte b/src/routes/(embed)/stories/page-embed.stories.svelte similarity index 100% rename from src/routes/stories/page-embed.stories.svelte rename to src/routes/(embed)/stories/page-embed.stories.svelte diff --git a/src/routes/stories/project-embed.stories.svelte b/src/routes/(embed)/stories/project-embed.stories.svelte similarity index 100% rename from src/routes/stories/project-embed.stories.svelte rename to src/routes/(embed)/stories/project-embed.stories.svelte From 45ccbfb2b3300a1076efbea85d9beb03628cc5cf Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 16:44:14 -0400 Subject: [PATCH 04/22] fix note embed types --- .../(embed)/stories/note-embed.stories.svelte | 18 ++++++++++++++---- .../(embed)/stories/page-embed.stories.svelte | 2 +- .../stories/project-embed.stories.svelte | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/routes/(embed)/stories/note-embed.stories.svelte b/src/routes/(embed)/stories/note-embed.stories.svelte index bf5a75f98..f9bf020ab 100644 --- a/src/routes/(embed)/stories/note-embed.stories.svelte +++ b/src/routes/(embed)/stories/note-embed.stories.svelte @@ -1,10 +1,12 @@ - @@ -25,5 +35,5 @@ - + diff --git a/src/routes/(embed)/stories/page-embed.stories.svelte b/src/routes/(embed)/stories/page-embed.stories.svelte index bd15b9566..30419da81 100644 --- a/src/routes/(embed)/stories/page-embed.stories.svelte +++ b/src/routes/(embed)/stories/page-embed.stories.svelte @@ -5,7 +5,7 @@ import "@/style/global.css"; import { Story } from "@storybook/addon-svelte-csf"; - import PageEmbed from "../(embed)/documents/[id]/pages/[page]/+page.svelte"; + import PageEmbed from "../documents/[id]/pages/[page]/+page.svelte"; import document from "$lib/api/fixtures/documents/document-expanded.json"; import { results } from "$lib/api/fixtures/notes/notes-expanded.json"; diff --git a/src/routes/(embed)/stories/project-embed.stories.svelte b/src/routes/(embed)/stories/project-embed.stories.svelte index 14d6a8e65..8dfc82365 100644 --- a/src/routes/(embed)/stories/project-embed.stories.svelte +++ b/src/routes/(embed)/stories/project-embed.stories.svelte @@ -6,7 +6,7 @@ import "@/style/global.css"; import { Story } from "@storybook/addon-svelte-csf"; - import ProjectEmbed from "../(embed)/projects/[project_id]/+page.svelte"; + import ProjectEmbed from "../projects/[project_id]/+page.svelte"; import documents from "$lib/api/fixtures/projects/project-documents-expanded.json"; import project from "$lib/api/fixtures/projects/project.json"; From ededd32521918ef5ed8fdfadf61c2f0c3de08f1e Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 17:23:43 -0400 Subject: [PATCH 05/22] Fix more embed types. Ignore TS errors on code we're not keeping. --- src/api/session.js | 1 + src/api/viewer.js | 1 + src/lib/api/addons.ts | 10 ++++++---- .../documents/[id]/pages/[page]/+page.svelte | 5 ++++- .../(embed)/projects/[project_id]/+page.svelte | 15 ++++++++------- src/routes/app/sidebar/AddOns.svelte | 6 ++++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/api/session.js b/src/api/session.js index cf7e7837f..110cfeac6 100644 --- a/src/api/session.js +++ b/src/api/session.js @@ -86,6 +86,7 @@ export class SessionCache { const sessionCache = new SessionCache(); +// @ts-ignore session.getStatic = async function getStatic(url) { if (sessionCache.has(url)) { return sessionCache.lookup(url); diff --git a/src/api/viewer.js b/src/api/viewer.js index d83c2c1be..bd88b4b72 100644 --- a/src/api/viewer.js +++ b/src/api/viewer.js @@ -12,6 +12,7 @@ export function documentDimensionUrl(document) { function getDesiredSize(desiredWidth) { for (let i = 0; i < IMAGE_WIDTHS.length; i++) { const [width, name] = IMAGE_WIDTHS[i]; + // @ts-ignore if (desiredWidth <= width) return name; } return IMAGE_WIDTHS[IMAGE_WIDTHS.length - 1][1]; diff --git a/src/lib/api/addons.ts b/src/lib/api/addons.ts index 61ffddb2c..73ebb9a37 100644 --- a/src/lib/api/addons.ts +++ b/src/lib/api/addons.ts @@ -1,8 +1,10 @@ +import type { Page } from "@/api/types/common"; +import type { AddOnListItem } from "@/addons/types"; + import { error } from "@sveltejs/kit"; + import { BASE_API_URL } from "@/config/config.js"; -import { type AddOnListItem } from "@/addons/types"; import { isErrorCode } from "../utils"; -import type { Page } from "@/api/types/common"; export async function getPinnedAddons( fetch = globalThis.fetch, @@ -15,7 +17,7 @@ export async function getPinnedAddons( if (isErrorCode(resp.status)) { error(resp.status, resp.statusText); } - return resp.json(); + return resp.json() as Promise>; } export async function getAddons( @@ -26,5 +28,5 @@ export async function getAddons( if (isErrorCode(resp.status)) { error(resp.status, resp.statusText); } - return resp.json(); + return resp.json() as Promise>; } diff --git a/src/routes/(embed)/documents/[id]/pages/[page]/+page.svelte b/src/routes/(embed)/documents/[id]/pages/[page]/+page.svelte index 74e95e28e..f5a030ebd 100644 --- a/src/routes/(embed)/documents/[id]/pages/[page]/+page.svelte +++ b/src/routes/(embed)/documents/[id]/pages/[page]/+page.svelte @@ -1,4 +1,5 @@ - @@ -51,11 +48,11 @@ - {#if note.description} - + {#if note.content} + {/if} @@ -63,7 +60,7 @@
diff --git a/src/routes/(pages)/[...path]/+page.js b/src/routes/(pages)/[...path]/+page.ts similarity index 77% rename from src/routes/(pages)/[...path]/+page.js rename to src/routes/(pages)/[...path]/+page.ts index 19b8c2c83..bb93e349b 100644 --- a/src/routes/(pages)/[...path]/+page.js +++ b/src/routes/(pages)/[...path]/+page.ts @@ -1,5 +1,5 @@ // load data for flatpages -import { error, redirect } from "@sveltejs/kit"; +import { error, redirect, type NumericRange } from "@sveltejs/kit"; import { marked } from "marked"; import { gfmHeadingId } from "marked-gfm-heading-id"; import DOMPurify from "isomorphic-dompurify"; @@ -17,12 +17,15 @@ export async function load({ fetch, params }) { const resp = await fetch(endpoint, { credentials: "include" }); if (resp.status > 400) { - error(resp.status, resp.statusText); + error(resp.status as NumericRange<400, 599>, resp.statusText); } // we should be following redirects, so this shouldn't happen if (resp.status > 300) { - redirect(resp.status, resp.headers.get("Location")); + redirect( + resp.status as NumericRange<300, 308>, + resp.headers.get("Location"), + ); } const page = await resp.json(); diff --git a/src/routes/(pages)/home/+page.js b/src/routes/(pages)/home/+page.ts similarity index 85% rename from src/routes/(pages)/home/+page.js rename to src/routes/(pages)/home/+page.ts index eb5540c9d..51a8b0f8f 100644 --- a/src/routes/(pages)/home/+page.js +++ b/src/routes/(pages)/home/+page.ts @@ -1,5 +1,5 @@ // load homepage data -import { error } from "@sveltejs/kit"; +import { error, type NumericRange } from "@sveltejs/kit"; import { marked } from "marked"; import { gfmHeadingId } from "marked-gfm-heading-id"; import DOMPurify from "isomorphic-dompurify"; @@ -16,7 +16,7 @@ export async function load({ fetch }) { const resp = await fetch(endpoint, { credentials: "include" }); if (!resp.ok) { - error(resp.status, resp.statusText); + error(resp.status as NumericRange<400, 599>, resp.statusText); } const page = await resp.json(); diff --git a/src/routes/app/upload/+page.server.ts b/src/routes/app/upload/+page.server.ts index d6133e224..3526e0e80 100644 --- a/src/routes/app/upload/+page.server.ts +++ b/src/routes/app/upload/+page.server.ts @@ -1,15 +1,6 @@ import type { Actions } from "./$types"; -import type { - Access, - Document, - DocumentUpload, - OCREngine, - Project, -} from "$lib/api/types"; -import { CSRF_COOKIE_NAME, DEFAULT_LANGUAGE } from "@/config/config.js"; -import * as documents from "$lib/api/documents"; -import { unwrap } from "$lib/components/inputs/Select.svelte"; +import { CSRF_COOKIE_NAME } from "@/config/config.js"; import { upload } from "$lib/components/forms/DocumentUpload.svelte"; export function load({ cookies }) { @@ -23,6 +14,6 @@ export const actions = { const csrf_token = cookies.get(CSRF_COOKIE_NAME); const form = await request.formData(); - return upload(form, csrf_token, fetch); + return upload(form, csrf_token, null, fetch); }, } satisfies Actions; From 615249cd0d5acb6b1bb531f2aa0cfd405dec45c1 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 17:41:57 -0400 Subject: [PATCH 07/22] eventually everything will be typescript --- src/lib/api/notes.js | 2 +- src/lib/components/forms/tests/DocumentUpload.test.ts | 4 ++-- .../[id]/annotations/[note_id]/{+page.js => +page.ts} | 4 ++-- .../documents/[id]/pages/[page]/{+page.js => +page.ts} | 6 +++--- .../(embed)/projects/[project_id]/{+page.js => +page.ts} | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/routes/(embed)/documents/[id]/annotations/[note_id]/{+page.js => +page.ts} (77%) rename src/routes/(embed)/documents/[id]/pages/[page]/{+page.js => +page.ts} (79%) rename src/routes/(embed)/projects/[project_id]/{+page.js => +page.ts} (74%) diff --git a/src/lib/api/notes.js b/src/lib/api/notes.js index 0b4b24326..c3c87152a 100644 --- a/src/lib/api/notes.js +++ b/src/lib/api/notes.js @@ -37,7 +37,7 @@ export async function list(doc_id, fetch) { * @param {globalThis.fetch} fetch * @returns {Promise} */ -export async function get(doc_id, note_id, fetch) { +export async function get(doc_id, note_id, fetch = globalThis.fetch) { const endpoint = new URL( `documents/${doc_id}/notes/${note_id}.json`, BASE_API_URL, diff --git a/src/lib/components/forms/tests/DocumentUpload.test.ts b/src/lib/components/forms/tests/DocumentUpload.test.ts index d92a9c535..d1fba0209 100644 --- a/src/lib/components/forms/tests/DocumentUpload.test.ts +++ b/src/lib/components/forms/tests/DocumentUpload.test.ts @@ -23,7 +23,7 @@ describe("DocumentUpload form", () => { }); await act(() => fireEvent(dropElement, dropEvent)); const fileListItem = screen.getByRole("listitem"); - expect(fileListItem).toContainHTML("128 kB"); + expect(fileListItem).toContain("128 kB"); }); it("provides feedback when a file is too large", async () => { render(DocumentUploadForm); @@ -39,6 +39,6 @@ describe("DocumentUpload form", () => { }); await act(() => fireEvent(dropElement, dropEvent)); const fileListItem = screen.getByRole("listitem"); - expect(fileListItem).toContainHTML("The maximum size for a PDF is 500MB"); + expect(fileListItem).toContain("The maximum size for a PDF is 500MB"); }); }); diff --git a/src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.js b/src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.ts similarity index 77% rename from src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.js rename to src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.ts index a9de0b125..a40fdb573 100644 --- a/src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.js +++ b/src/routes/(embed)/documents/[id]/annotations/[note_id]/+page.ts @@ -5,8 +5,8 @@ import * as notesApi from "$lib/api/notes.js"; /** @type {import('./$types').PageLoad} */ export async function load({ params, url, fetch }) { const [document, note] = await Promise.all([ - documents.get(params.id, fetch), - notesApi.get(params.id, params.note_id), + documents.get(+params.id, fetch), + notesApi.get(+params.id, params.note_id, fetch), ]); return { diff --git a/src/routes/(embed)/documents/[id]/pages/[page]/+page.js b/src/routes/(embed)/documents/[id]/pages/[page]/+page.ts similarity index 79% rename from src/routes/(embed)/documents/[id]/pages/[page]/+page.js rename to src/routes/(embed)/documents/[id]/pages/[page]/+page.ts index a8d04399b..44adc1917 100644 --- a/src/routes/(embed)/documents/[id]/pages/[page]/+page.js +++ b/src/routes/(embed)/documents/[id]/pages/[page]/+page.ts @@ -4,10 +4,10 @@ import * as notesApi from "$lib/api/notes.js"; /** @type {import('./$types').PageLoad} */ export async function load({ params, fetch }) { - const { page } = params; + const page = +params.page; let [document, notes] = await Promise.all([ - documents.get(params.id, fetch), - notesApi.list(params.id, fetch), + documents.get(+params.id, fetch), + notesApi.list(+params.id, fetch), ]); return { diff --git a/src/routes/(embed)/projects/[project_id]/+page.js b/src/routes/(embed)/projects/[project_id]/+page.ts similarity index 74% rename from src/routes/(embed)/projects/[project_id]/+page.js rename to src/routes/(embed)/projects/[project_id]/+page.ts index 3b57f6277..ce79d3155 100644 --- a/src/routes/(embed)/projects/[project_id]/+page.js +++ b/src/routes/(embed)/projects/[project_id]/+page.ts @@ -5,8 +5,8 @@ import * as projects from "$lib/api/projects.js"; /** @type {import('./$types').PageLoad} */ export async function load({ params, fetch }) { const [project, documents] = await Promise.all([ - projects.get(params.project_id, fetch), - projects.documents(params.project_id, fetch), + projects.get(+params.project_id, fetch), + projects.documents(+params.project_id, fetch), ]); return { From f0474efb9505f130788cc6f30f26651ec31bd223 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 16 Apr 2024 18:14:32 -0400 Subject: [PATCH 08/22] Forgot I hadn't done projects.get yet --- jsconfig.json | 3 +- src/lib/api/{projects.js => projects.ts} | 61 ++++++++++++------- src/lib/components/common/Logo.svelte | 1 - .../(embed)/projects/[project_id]/+page.ts | 2 +- src/routes/app/+layout.ts | 2 +- src/routes/app/upload/+layout.ts | 2 +- 6 files changed, 45 insertions(+), 26 deletions(-) rename src/lib/api/{projects.js => projects.ts} (50%) diff --git a/jsconfig.json b/jsconfig.json index 97939e152..63c97a632 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -9,7 +9,8 @@ "skipLibCheck": true, "sourceMap": true, "strict": false, - "moduleResolution": "bundler" + "moduleResolution": "bundler", + "types": ["@testing-library/jest-dom"] }, // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files // diff --git a/src/lib/api/projects.js b/src/lib/api/projects.ts similarity index 50% rename from src/lib/api/projects.js rename to src/lib/api/projects.ts index c894d910f..4fe942d11 100644 --- a/src/lib/api/projects.js +++ b/src/lib/api/projects.ts @@ -1,5 +1,7 @@ // api methods for projects -import { error } from "@sveltejs/kit"; +import type { Project, ProjectResults, ProjectMembershipList } from "./types"; + +import { error, type NumericRange } from "@sveltejs/kit"; import { BASE_API_URL } from "@/config/config.js"; /** @@ -8,9 +10,26 @@ import { BASE_API_URL } from "@/config/config.js"; * @export * @param {number} id * @param {globalThis.fetch} fetch - * @returns {import('./types').Project} + * @returns {Promise} */ -export async function get(id, fetch) {} +export async function get( + id: number, + fetch = globalThis.fetch, +): Promise { + const endpoint = new URL(`projects/${id}/`, BASE_API_URL); + + const res = await fetch(endpoint, { credentials: "include" }).catch((e) => { + error(500, { message: e }); + }); + + if (!res.ok) { + error(res.status as NumericRange<400, 599>, { + message: res.statusText, + }); + } + + return res.json(); +} /** * Get a list of projects @@ -18,24 +37,24 @@ export async function get(id, fetch) {} * @export * @param {any} params filter params * @param {globalThis.fetch} fetch - * @returns {Promise} */ -export async function list(params = {}, fetch) { +export async function list( + params: any = {}, + fetch = globalThis.fetch, +): Promise { const endpoint = new URL("projects/", BASE_API_URL); for (const [k, v] of Object.entries(params)) { - endpoint.searchParams.set(k, v); + endpoint.searchParams.set(k, String(v)); } - const res = await fetch(endpoint, { credentials: "include" }).catch((e) => ({ - ok: false, - error: e, - })); + const res = await fetch(endpoint, { credentials: "include" }).catch((e) => { + error(500, { message: e }); + }); if (!res.ok) { - error(res.status, { + error(res.status as NumericRange<400, 599>, { message: res.statusText, - error: res.error, }); } @@ -48,26 +67,26 @@ export async function list(params = {}, fetch) { * @export * @param {number} id * @param {globalThis.fetch} fetch - * @returns {import('./types').ProjectMembershipList} */ -export async function documents(id, fetch) { +export async function documents( + id: number | string, + fetch = globalThis.fetch, +): Promise { const endpoint = new URL(`projects/${id}/documents/`, BASE_API_URL); const expand = ["user", "organization", "document"]; // might make these configurable later endpoint.searchParams.set("expand", expand.join(",")); endpoint.searchParams.set("ordering", "-created_at"); - endpoint.searchParams.set("per_page", 12); + endpoint.searchParams.set("per_page", "12"); - const res = await fetch(endpoint, { credentials: "include" }).catch((e) => ({ - ok: false, - error: e, - })); + const res = await fetch(endpoint, { credentials: "include" }).catch((e) => { + error(500, { message: e }); + }); if (!res.ok) { - error(res.status, { + error(res.status as NumericRange<400, 599>, { message: res.statusText, - error: res.error, }); } diff --git a/src/lib/components/common/Logo.svelte b/src/lib/components/common/Logo.svelte index 1ccabdb0c..fecaab696 100644 --- a/src/lib/components/common/Logo.svelte +++ b/src/lib/components/common/Logo.svelte @@ -2,7 +2,6 @@ viewBox="0 0 182 32" fill="none" xmlns="http://www.w3.org/2000/svg" - title="DocumentCloud" class="icon" > Date: Wed, 17 Apr 2024 09:02:56 -0400 Subject: [PATCH 09/22] Apply previous check fixes I've made --- src/api/{session.js => session.ts} | 21 +++-- src/api/types/document.ts | 11 ++- src/api/{viewer.js => viewer.ts} | 0 src/common/ProgressiveImage.svelte | 2 +- src/pages/app/Document.svelte | 2 +- src/pages/embed/note/Note.svelte | 2 +- src/pages/embed/page/Page.svelte | 2 +- src/pages/entities/Entities.svelte | 2 +- src/pages/viewer/AllText.svelte | 2 +- src/pages/viewer/InternalPage.svelte | 2 +- src/pages/viewer/ModifyImage.svelte | 2 +- src/pages/viewer/SearchResults.svelte | 2 +- src/pages/viewer/Sidebar.svelte | 2 +- src/pages/viewer/Viewer.svelte | 2 +- .../(embed)/stories/note-embed.stories.svelte | 1 + .../(embed)/stories/page-embed.stories.svelte | 4 +- .../documents/[id]-[slug]/+layout.svelte | 2 +- src/test/fixtures/documents.ts | 76 +++++++++++++++++++ vite.config.js | 1 + 19 files changed, 113 insertions(+), 25 deletions(-) rename src/api/{session.js => session.ts} (88%) rename src/api/{viewer.js => viewer.ts} (100%) diff --git a/src/api/session.js b/src/api/session.ts similarity index 88% rename from src/api/session.js rename to src/api/session.ts index 110cfeac6..3ed07a6e6 100644 --- a/src/api/session.js +++ b/src/api/session.ts @@ -1,4 +1,4 @@ -import axios from "axios"; +import axios, { type AxiosInstance } from "axios"; import axiosRetry from "axios-retry"; import { DC_BASE } from "../config/config.js"; @@ -30,11 +30,12 @@ export function getCsrfToken() { return token; } -const session = axios.create({ - xsrfCookieName: CSRF_COOKIE_NAME, - xsrfHeaderName: CSRF_HEADER_NAME, - withCredentials: cookiesEnabled, -}); +const session: AxiosInstance & { getStatic?: (url: string) => any } = + axios.create({ + xsrfCookieName: CSRF_COOKIE_NAME, + xsrfHeaderName: CSRF_HEADER_NAME, + withCredentials: cookiesEnabled, + }); session.interceptors.response.use( (response) => { @@ -55,6 +56,11 @@ session.interceptors.response.use( const CACHE_LIMIT = 50; +export interface SessionCache { + cached: any[]; + cachedByUrl: Record; +} + export class SessionCache { constructor() { this.cached = []; @@ -86,8 +92,7 @@ export class SessionCache { const sessionCache = new SessionCache(); -// @ts-ignore -session.getStatic = async function getStatic(url) { +session.getStatic = async function getStatic(url: string) { if (sessionCache.has(url)) { return sessionCache.lookup(url); } diff --git a/src/api/types/document.ts b/src/api/types/document.ts index 0f03fc923..ec6a85949 100644 --- a/src/api/types/document.ts +++ b/src/api/types/document.ts @@ -4,6 +4,13 @@ import type { Project } from "./project"; export type DocumentAccess = "public" | "organization" | "private"; +export type DocumentStatus = + | "success" + | "readable" + | "pending" + | "error" + | "nofile"; + export interface DocumentRevision { version: number; user: number; @@ -19,7 +26,7 @@ export interface Document { asset_url: string; canonical_url: string; created_at: string; - data: Record; + data: Record; description: string; edit_access: boolean; file_hash: string; @@ -39,7 +46,7 @@ export interface Document { revisions?: DocumentRevision[]; slug: string; source: string; - status: "success" | "failure" | "queued" | "in_progress"; + status: DocumentStatus; title: string; updated_at: string; user: User | number; diff --git a/src/api/viewer.js b/src/api/viewer.ts similarity index 100% rename from src/api/viewer.js rename to src/api/viewer.ts diff --git a/src/common/ProgressiveImage.svelte b/src/common/ProgressiveImage.svelte index c7dc18c34..3f54d6890 100644 --- a/src/common/ProgressiveImage.svelte +++ b/src/common/ProgressiveImage.svelte @@ -1,7 +1,7 @@