Skip to content

Commit 6d75e2d

Browse files
committed
Use zod mini
1 parent 3b6df42 commit 6d75e2d

190 files changed

Lines changed: 1194 additions & 1174 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/update-api.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ jobs:
5050
- name: Generate files
5151
run: bun run gen
5252

53-
- name: Build
54-
run: bun run build
55-
56-
- name: Run tests
57-
run: bun run test
58-
5953
- name: Create or update Pull Request
6054
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
6155
with:

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@lichess/api",
33
"version": "0.0.2",
44
"type": "module",
5-
"author": "GameRoMan",
5+
"author": "gameroman",
66
"license": "MIT",
77
"scripts": {
88
"gen:schemas": "bun ./scripts/gen-schemas",
@@ -15,6 +15,14 @@
1515
"build": "bunx --bun tsdown",
1616
"prepublishOnly": "bun run build"
1717
},
18+
"keywords": [
19+
"api",
20+
"lichess"
21+
],
22+
"imports": {
23+
"#lib/*": "./src/lib/*.ts",
24+
"#schemas": "./src/schemas/index.ts"
25+
},
1826
"repository": {
1927
"type": "git",
2028
"url": "git+https://github.com/lichess-api/typescript.git"

scripts/gen-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,11 @@ async function processSchema(schema: OpenApiSchema): Promise<void> {
804804

805805
const API_URL = schema.servers[0].url;
806806

807-
const clientCodeTs = `import * as z from "zod";
807+
const clientCodeTs = `import * as z from "zod/mini";
808808
809-
import { ndjsonStream } from "~/lib/ndjson";
809+
import { ndjsonStream } from "#lib/ndjson";
810810
811-
import * as schemas from "~/schemas";
811+
import * as schemas from "#schemas";
812812
813813
import { Requestor } from "./requestor";
814814

scripts/gen-schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function processFile(filePath: string) {
3636
? (`\n${refImports}\n` as const)
3737
: ("" as const);
3838

39-
const tsCode = `import * as z from "zod";
39+
const tsCode = `import * as z from "zod/mini";
4040
${spacedRefImports}
4141
const ${fileName} = ${zodSchema};
4242

scripts/shared.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
303303
}
304304
let schemaStr = "z.string()";
305305
if (schema.minLength !== undefined) {
306-
schemaStr += `.min(${schema.minLength})`;
306+
schemaStr += `.check(z.minLength(${schema.minLength}))`;
307307
}
308308
if (schema.maxLength !== undefined) {
309-
schemaStr += `.max(${schema.maxLength})`;
309+
schemaStr += `.check(z.maxLength(${schema.maxLength}))`;
310310
}
311311
return { zodSchema: schemaStr, refs: [] } as const;
312312
}
313313
case "string:nullable": {
314-
return { zodSchema: "z.string().nullable()", refs: [] } as const;
314+
return { zodSchema: "z.nullable(z.string())", refs: [] } as const;
315315
}
316316
case "enum:number": {
317317
const literals = schema.enum.map((v) => JSON.stringify(v)).join(", ");
@@ -331,23 +331,23 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
331331
}
332332
}
333333
if (schema.minimum !== undefined) {
334-
schemaStr += `.min(${schema.minimum})`;
334+
schemaStr += `.check(z.minimum(${schema.minimum}))`;
335335
}
336336
if (schema.maximum !== undefined) {
337-
schemaStr += `.max(${schema.maximum})`;
337+
schemaStr += `.check(z.maximum(${schema.maximum}))`;
338338
}
339339
return { zodSchema: schemaStr, refs: [] } as const;
340340
}
341341
case "integer:nullable": {
342-
return { zodSchema: "z.int().nullable()", refs: [] } as const;
342+
return { zodSchema: "z.nullable(z.int())", refs: [] } as const;
343343
}
344344
case "number": {
345345
let schemaStr = "z.number()";
346346
if (schema.minimum !== undefined) {
347-
schemaStr += `.min(${schema.minimum})`;
347+
schemaStr += `.check(z.minimum(${schema.minimum}))`;
348348
}
349349
if (schema.maximum !== undefined) {
350-
schemaStr += `.max(${schema.maximum})`;
350+
schemaStr += `.check(z.maximum(${schema.maximum}))`;
351351
}
352352
return { zodSchema: schemaStr, refs: [] } as const;
353353
}
@@ -377,7 +377,7 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
377377
propRefs.forEach((r) => allRefs.add(r));
378378
let propStr = sch;
379379
if (!required.has(k)) {
380-
propStr += ".optional()";
380+
propStr = `z.optional(${propStr})`;
381381
}
382382
zodProps[k] = propStr;
383383
}
@@ -422,10 +422,10 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
422422
inner += `.length(${schema.minItems})`;
423423
} else {
424424
if (schema.minItems !== undefined) {
425-
inner += `.min(${schema.minItems})`;
425+
inner += `.check(z.minLength(${schema.minItems}))`;
426426
}
427427
if (schema.maxItems !== undefined) {
428-
inner += `.max(${schema.maxItems})`;
428+
inner += `.check(z.maxLength(${schema.maxItems}))`;
429429
}
430430
}
431431
zodSchemaStr = inner;

0 commit comments

Comments
 (0)