Skip to content

Commit 820d23d

Browse files
committed
chore: update dependencies, fix lint warnings
1 parent 15c8f74 commit 820d23d

6 files changed

Lines changed: 130 additions & 126 deletions

File tree

bun.lock

Lines changed: 64 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
"gen": "bun run --sequential gen:schemas gen:client format",
3232
"test": "bun test",
3333
"typecheck": "tsgo --noEmit",
34-
"lint": "biome check ./src",
34+
"lint": "biome check",
3535
"format": "biome check --write --linter-enabled=false",
3636
"build": "bunx --bun tsdown",
3737
"prepublishOnly": "bun run build"
3838
},
3939
"dependencies": {
40-
"minizod": "^0.0.3"
40+
"minizod": "0.0.3"
4141
},
4242
"devDependencies": {
43-
"@biomejs/biome": "2.4.12",
44-
"@gameroman/config": "^0.1.0",
45-
"@types/bun": "^1.3.11",
46-
"@typescript/native-preview": "^7.0.0-dev.20260401.1",
47-
"tsdown": "^0.21.7",
48-
"zod": "^4.3.6"
43+
"@biomejs/biome": "2.4.15",
44+
"@gameroman/config": "0.1.0",
45+
"@types/bun": "1.3.14",
46+
"@typescript/native-preview": "7.0.0-dev.20260517.1",
47+
"tsdown": "0.22.0",
48+
"zod": "4.4.3"
4949
},
5050
"engines": {
5151
"node": ">=24"

scripts/gen-client.ts

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
OperationParameterBase,
77
OperationQueryParameterSchema,
88
type QueryParamSchemaSchema,
9+
recordToObject,
10+
refToName,
911
type Schema,
1012
SchemaSchema,
1113
SchemaSchemaBoolean,
@@ -334,7 +336,7 @@ const TagSchemaSchemaPut = BaseTagSchemaOperation.extend({
334336

335337
const TagSchemaSchema = z
336338
.object({
337-
// servers: LichessServersSchema.optional(),
339+
servers: LichessServersSchema.optional(),
338340
parameters: z
339341
.array(OperationPathParameterSchema)
340342
.transform((s) => ({ parameters: s, __id: "__parameters" as const }))
@@ -464,13 +466,13 @@ function schemaToTypescriptTypes(
464466
case "$ref":
465467
case "notverified:reftoprimitive": {
466468
const ref = schema.$ref;
467-
const name = ref.split("/").pop()!.replace(".yaml", "");
469+
const name = refToName(ref);
468470
const typescriptSchema = `schemas.${name}` as const;
469471
return typescriptSchema;
470472
}
471473
case "notverified:reftoprimitive:nullable": {
472474
const ref = schema.allOf[0].$ref;
473-
const name = ref.split("/").pop()!.replace(".yaml", "");
475+
const name = refToName(ref);
474476
const typescriptSchema = `schemas.${name} | null` as const;
475477
return typescriptSchema;
476478
}
@@ -485,15 +487,7 @@ function schemaToTypescriptTypes(
485487
: (`?: ${typescriptSchema}` as const);
486488
objectRecord[k] = propStr;
487489
}
488-
const entries = Object.entries(objectRecord);
489-
if (entries.length === 1) {
490-
return `{ "${entries[0]![0]}" ${entries[0]![1]} }` as const;
491-
}
492-
return (
493-
"{\n" +
494-
entries.map(([k, v]) => ` "${k}" ${v},` as const).join("\n") +
495-
"\n}"
496-
);
490+
return recordToObject(objectRecord, { colon: false });
497491
}
498492
case "boolean":
499493
case "boolean-like": {
@@ -535,7 +529,7 @@ function schemaToTypescriptTypes(
535529
}
536530
case "array:notverified:reftoprimitive": {
537531
const ref = schema.items.$ref;
538-
const name = ref.split("/").pop()!.replace(".yaml", "");
532+
const name = refToName(ref);
539533
const typescriptSchema = `schemas.${name}` as const;
540534
return `(${typescriptSchema})[]` as const;
541535
}
@@ -563,32 +557,15 @@ function extractQueryParams(queryParams: OperationQueryParameter[]) {
563557
? `: ${typescriptSchema}`
564558
: `?: ${typescriptSchema}`;
565559
}
566-
const entries = Object.entries(params);
567-
if (entries.length === 1) {
568-
return `{ "${entries[0]![0]}" ${entries[0]![1]} }` as const;
569-
}
570-
return (
571-
"{\n" +
572-
entries.map(([k, v]) => ` "${k}" ${v},` as const).join("\n") +
573-
"\n}"
574-
);
560+
return recordToObject(params, { colon: false });
575561
}
576562

577563
function extractPathParams(pathParams: OperationPathParameter[]) {
578564
const params: Record<string, string> = {};
579565
for (const param of pathParams) {
580-
const typescriptSchema = schemaToTypescriptTypes(param.schema);
581-
params[param.name] = `: ${typescriptSchema}` as const;
582-
}
583-
const entries = Object.entries(params);
584-
if (entries.length === 1) {
585-
return `{ "${entries[0]![0]}" ${entries[0]![1]} }` as const;
566+
params[param.name] = schemaToTypescriptTypes(param.schema);
586567
}
587-
return (
588-
"{\n" +
589-
entries.map(([k, v]) => ` "${k}" ${v},` as const).join("\n") +
590-
"\n}"
591-
);
568+
return recordToObject(params);
592569
}
593570

594571
function extractBodyTypes(bodySchema: Schema) {
@@ -614,10 +591,10 @@ function processOperation(
614591
return { parameters, __type: "__parameters" } as const;
615592
}
616593

617-
// if (operation.__id === "__servers") {
618-
// const baseUrl = operation.url;
619-
// return { baseUrl, __type: "__servers" } as const;
620-
// }
594+
if (operation.__id === "__servers") {
595+
const baseUrl = operation.url;
596+
return { baseUrl, __type: "__servers" } as const;
597+
}
621598

622599
const { processedPath, hasPathParams } = processRawPath(rawApiPath);
623600
const pathLiteral = hasPathParams

scripts/gen-schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as fs from "node:fs/promises";
33
import * as path from "node:path";
44
import { ZodError } from "zod";
55
import { prettifyError } from "zod/mini";
6-
import { convertToZod, SchemaSchema } from "./shared";
6+
import { convertToZod, refToName, SchemaSchema, StringYamlRef } from "./shared";
77

88
async function processFile(filePath: string) {
99
const normalizedFilePath = filePath.replaceAll("\\", "/");
10-
const fileName = normalizedFilePath.split("/").pop()!.replace(".yaml", "");
10+
const fileName = refToName(StringYamlRef.parse(normalizedFilePath));
1111
const yamlStr = await Bun.file(normalizedFilePath).text();
1212
const yamlContent = Bun.YAML.parse(yamlStr);
1313
const parsedSchema = SchemaSchema.safeParse(yamlContent);

scripts/shared.ts

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from "node:path";
12
import * as z from "zod";
23

34
const SchemaUnparsed = z
@@ -29,6 +30,8 @@ const StringYamlRef = z
2930
.templateLiteral([z.string(), ".yaml"])
3031
.brand("StringYamlRef");
3132

33+
type StringYamlRef = z.infer<typeof StringYamlRef>;
34+
3235
const SchemaSchemaRef = BaseSchema.extend({
3336
type: z.literal("object").optional(),
3437
$ref: StringYamlRef,
@@ -240,6 +243,33 @@ function parseUnparsed(schema: Unparsed) {
240243

241244
type ConvertResult = { readonly zodSchema: string; readonly refs: string[] };
242245

246+
function refToName(ref: StringYamlRef) {
247+
return path.basename(ref).replace(".yaml", "");
248+
}
249+
250+
function recordToObject(
251+
object: Record<string, string>,
252+
options = { colon: true },
253+
) {
254+
const entries = Object.entries(object);
255+
256+
const colon = options.colon ? ":" : "";
257+
258+
if (entries.length <= 1) {
259+
const firstEntry = entries[0];
260+
if (firstEntry) {
261+
return `{ "${firstEntry[0]}"${colon} ${firstEntry[1]} }`;
262+
}
263+
return "Record<string, never>";
264+
}
265+
266+
const entriesKv = entries
267+
.map(([k, v]) => ` "${k}"${colon} ${v},`)
268+
.join("\n");
269+
270+
return `{\n${entriesKv}\n}`;
271+
}
272+
243273
function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
244274
if (schema.const !== undefined) {
245275
return {
@@ -252,7 +282,7 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
252282
switch (schema.__schema) {
253283
case "$ref": {
254284
const ref = schema.$ref;
255-
const name = ref.split("/").pop()!.replace(".yaml", "");
285+
const name = refToName(ref);
256286
const prefixedName = `${prefix}${name}` as const;
257287
return { zodSchema: prefixedName, refs: prefix ? [] : [name] } as const;
258288
}
@@ -262,7 +292,9 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
262292
);
263293
const zodSchemas = subResults.map((r) => r.zodSchema);
264294
const allRefs = new Set<string>();
265-
subResults.forEach((r) => r.refs.forEach((ref) => allRefs.add(ref)));
295+
subResults.forEach(
296+
(r) => void r.refs.forEach((ref) => void allRefs.add(ref)),
297+
);
266298
return {
267299
zodSchema: `z.union([${zodSchemas.join(", ")}])`,
268300
refs: Array.from(allRefs),
@@ -286,10 +318,8 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
286318
case "anyOf": {
287319
const refNames: string[] = [];
288320
const allRefs = new Set<string>();
289-
for (const [_, refYaml] of Object.entries(
290-
schema.discriminator.mapping,
291-
)) {
292-
const name = refYaml.split("/").pop()!.replace(".yaml", "");
321+
for (const [_, ref] of Object.entries(schema.discriminator.mapping)) {
322+
const name = refToName(ref);
293323
refNames.push(prefix + name);
294324
if (!prefix) allRefs.add(name);
295325
}
@@ -387,20 +417,14 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
387417
parseUnparsed(v),
388418
prefix,
389419
);
390-
propRefs.forEach((r) => allRefs.add(r));
420+
propRefs.forEach((r) => void allRefs.add(r));
391421
let propStr = sch;
392422
if (!required.has(k)) {
393423
propStr = `z.optional(${propStr})`;
394424
}
395425
zodProps[k] = propStr;
396426
}
397-
const entries = Object.entries(zodProps);
398-
const inner =
399-
entries.length === 1
400-
? `{ "${entries[0]![0]}": ${entries[0]![1]} }`
401-
: "{\n" +
402-
entries.map(([k, v]) => ` "${k}": ${v},`).join("\n") +
403-
"\n}";
427+
const inner = recordToObject(zodProps);
404428
return {
405429
zodSchema: `z.object(${inner})`,
406430
refs: Array.from(allRefs),
@@ -471,6 +495,9 @@ export {
471495
assertNever,
472496
convertToZod,
473497
QueryParamSchemaSchema,
498+
recordToObject,
499+
refToName,
474500
SchemaSchema,
475501
SchemaSchemaRef,
502+
StringYamlRef,
476503
};

src/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ export class Lichess {
31473147
"clock.increment": number;
31483148
}
31493149
| { days: 1 | 2 | 3 | 5 | 7 | 10 | 14 }
3150-
| {}
3150+
| Record<string, never>
31513151
) & {
31523152
rated?: boolean;
31533153
color?: schemas.ChallengeColor;

0 commit comments

Comments
 (0)