Skip to content

Commit

Permalink
fix types, bash the tooling
Browse files Browse the repository at this point in the history
i SWEAR i hate tooling. The `sed` in the build script is needed because
since I use `import type`, tsc figures that `exporter.ts` is a module
(even though types are supposed to be "erased at compile time"), so it
includes some annoying shim one-liner that tries to define a module,
except that breaks in browser because it's not actually a module.

I need to use `import type` because I couldn't figure out any other way
to have tsc figure out the type of z.infer while keeping the other
globals defined.

All in all this works well enough, if you're a tooling genius god please
fix this, otherwise I give up this is good enough. If you're
developping, you'll just need to not copy/paste the first two lines of
the built exporter.js file.
  • Loading branch information
Eselvire committed Dec 7, 2023
1 parent a54eb48 commit 78b05d7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
run: |
git config user.name "Github Actions"
git config user.email "[email protected]"
git add -f --all
git add -f ./exporter.js
git commit -m "Build files"
git push
14 changes: 10 additions & 4 deletions exporter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ZodInfer } from "./types";

(async () => {
const version = "5";

Expand Down Expand Up @@ -106,6 +108,7 @@


log("creating db")
// TODO
interface dbSchema extends DBSchema {
"misc-data": { key: string, value: any }
}
Expand Down Expand Up @@ -752,7 +755,8 @@
"deliverySeenByRecipient": z.boolean(),
"ts": z.string(),
})
type Mift = typeof z.infer<typeof schema_mift>

type Mift = ZodInfer<typeof schema_mift>

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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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<typeof schema_snap>
type Snap = ZodInfer<typeof schema_snap>
const schema_snapPage = z.object({
visitedLocation: schema_snap.optional(),
moreResults: z.boolean()
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"module": "exporter.js",
"type": "module",
"scripts": {
"build": "tsc"
"build": "tsc ; sed -i '1,2d' exporter.js"
},
"devDependencies": {
"bun-types": "latest"
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { infer as ZodInfer } from "zod/lib/types";

0 comments on commit 78b05d7

Please sign in to comment.