diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ad1551..f59eb47 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,6 +23,6 @@ jobs: run: | git config user.name "Github Actions" git config user.email "actions@users.noreply.github.com" - git add -f --all + git add -f ./exporter.js git commit -m "Build files" git push diff --git a/exporter.ts b/exporter.ts index 985d694..ba791bf 100644 --- a/exporter.ts +++ b/exporter.ts @@ -1,3 +1,5 @@ +import { ZodInfer } from "./types"; + (async () => { const version = "5"; @@ -106,6 +108,7 @@ log("creating db") + // TODO interface dbSchema extends DBSchema { "misc-data": { key: string, value: any } } @@ -752,7 +755,8 @@ "deliverySeenByRecipient": z.boolean(), "ts": z.string(), }) - type Mift = typeof z.infer + + type Mift = ZodInfer const store_addMift = async (mift: Mift, priv: boolean) => await db.put(priv ? 'mifts-private' : 'mifts-public', mift, mift._id); const store_getMift = async (miftId: string, priv: boolean) => await db.get(priv ? 'mifts-private' : 'mifts-public', miftId); @@ -793,7 +797,9 @@ } if (page.results.length < 5) break; - lastDate = page.results.at(-1).ts; + const lastPage = page.results.at(-1); + if (!lastPage) break; + lastDate = lastPage.ts; await sleep(SLEEP_MIFT_PAGE); } } @@ -808,7 +814,7 @@ shortCode: z.string(), loc: z.object({ p: z.coerce.number(), a: z.coerce.string(), x: z.coerce.number(), y: z.coerce.number() }) }); - type Snap = typeof z.infer + type Snap = ZodInfer const schema_snapPage = z.object({ visitedLocation: schema_snap.optional(), moreResults: z.boolean() @@ -825,7 +831,7 @@ while (true) { const rawData = await getSnap(index++); - const result = schema_snap.safeParse(rawData); + const result = schema_snapPage.safeParse(rawData); log(rawData, result) if (result.success === false) { diff --git a/globals.d.ts b/globals.d.ts index d490c8d..156064f 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -1,8 +1,10 @@ declare var JSZip: typeof import('jszip/index.d.ts'); declare var Zod: typeof import('zod/lib/index.d.ts'); -declare var csv_stringify_sync: typeof import('csv-stringify/sync'); +//type ZodInfer = Zod.infer; +//type ZodInfer_ = typeof import('zod/lib/types').infer; +declare var csv_stringify_sync: typeof import('csv-stringify/lib/sync'); declare var saveAs: typeof import('file-saver'); -declare var redom: typeof import('redom'); +declare var redom: typeof import('redom/index'); declare var idb: typeof import('idb/build/index.d.ts'); type DBSchema = import('idb/build/index.d.ts').DBSchema; type IDBPDatabase = import('idb/build/index.d.ts').IDBPDatabase; diff --git a/package.json b/package.json index 9f75a88..b3cf289 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "module": "exporter.js", "type": "module", "scripts": { - "build": "tsc" + "build": "tsc ; sed -i '1,2d' exporter.js" }, "devDependencies": { "bun-types": "latest" diff --git a/tsconfig.json b/tsconfig.json index 507c644..d199ac2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,14 +3,19 @@ "strict": true, "target": "ESNext", "lib": [ "ESNext", "dom" ], - "moduleResolution": "nodenext", - "module": "nodenext", + "module": "None", + "moduleResolution": "Classic", + "isolatedModules": true, + "paths": { + "*": ["./node_modules/*"], + }, "checkJs": true, "noEmit": false, "skipLibCheck": true }, "include": [ "exporter.ts", + "types.ts", "globals.d.ts" ], "exclude": [ diff --git a/types.ts b/types.ts new file mode 100644 index 0000000..cecfbd4 --- /dev/null +++ b/types.ts @@ -0,0 +1 @@ +export type { infer as ZodInfer } from "zod/lib/types"; \ No newline at end of file