Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/update-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ jobs:
- name: Generate files
run: bun run gen

- name: Build
run: bun run build

- name: Run tests
run: bun run test

- name: Create or update Pull Request
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@lichess/api",
"version": "0.0.2",
"type": "module",
"author": "GameRoMan",
"author": "gameroman",
"license": "MIT",
"scripts": {
"gen:schemas": "bun ./scripts/gen-schemas",
Expand All @@ -15,6 +15,14 @@
"build": "bunx --bun tsdown",
"prepublishOnly": "bun run build"
},
"keywords": [
"api",
"lichess"
],
"imports": {
"#lib/*": "./src/lib/*.ts",
"#schemas": "./src/schemas/index.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lichess-api/typescript.git"
Expand Down
6 changes: 3 additions & 3 deletions scripts/gen-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,11 @@ async function processSchema(schema: OpenApiSchema): Promise<void> {

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

const clientCodeTs = `import * as z from "zod";
const clientCodeTs = `import * as z from "zod/mini";

import { ndjsonStream } from "~/lib/ndjson";
import { ndjsonStream } from "#lib/ndjson";

import * as schemas from "~/schemas";
import * as schemas from "#schemas";

import { Requestor } from "./requestor";

Expand Down
2 changes: 1 addition & 1 deletion scripts/gen-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function processFile(filePath: string) {
? (`\n${refImports}\n` as const)
: ("" as const);

const tsCode = `import * as z from "zod";
const tsCode = `import * as z from "zod/mini";
${spacedRefImports}
const ${fileName} = ${zodSchema};

Expand Down
22 changes: 11 additions & 11 deletions scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
}
let schemaStr = "z.string()";
if (schema.minLength !== undefined) {
schemaStr += `.min(${schema.minLength})`;
schemaStr += `.check(z.minLength(${schema.minLength}))`;
}
if (schema.maxLength !== undefined) {
schemaStr += `.max(${schema.maxLength})`;
schemaStr += `.check(z.maxLength(${schema.maxLength}))`;
}
return { zodSchema: schemaStr, refs: [] } as const;
}
case "string:nullable": {
return { zodSchema: "z.string().nullable()", refs: [] } as const;
return { zodSchema: "z.nullable(z.string())", refs: [] } as const;
}
case "enum:number": {
const literals = schema.enum.map((v) => JSON.stringify(v)).join(", ");
Expand All @@ -331,23 +331,23 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
}
}
if (schema.minimum !== undefined) {
schemaStr += `.min(${schema.minimum})`;
schemaStr += `.check(z.minimum(${schema.minimum}))`;
}
if (schema.maximum !== undefined) {
schemaStr += `.max(${schema.maximum})`;
schemaStr += `.check(z.maximum(${schema.maximum}))`;
}
return { zodSchema: schemaStr, refs: [] } as const;
}
case "integer:nullable": {
return { zodSchema: "z.int().nullable()", refs: [] } as const;
return { zodSchema: "z.nullable(z.int())", refs: [] } as const;
}
case "number": {
let schemaStr = "z.number()";
if (schema.minimum !== undefined) {
schemaStr += `.min(${schema.minimum})`;
schemaStr += `.check(z.minimum(${schema.minimum}))`;
}
if (schema.maximum !== undefined) {
schemaStr += `.max(${schema.maximum})`;
schemaStr += `.check(z.maximum(${schema.maximum}))`;
}
return { zodSchema: schemaStr, refs: [] } as const;
}
Expand Down Expand Up @@ -377,7 +377,7 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
propRefs.forEach((r) => allRefs.add(r));
let propStr = sch;
if (!required.has(k)) {
propStr += ".optional()";
propStr = `z.optional(${propStr})`;
}
zodProps[k] = propStr;
}
Expand Down Expand Up @@ -422,10 +422,10 @@ function convertToZod(schema: Schema, prefix: string = ""): ConvertResult {
inner += `.length(${schema.minItems})`;
} else {
if (schema.minItems !== undefined) {
inner += `.min(${schema.minItems})`;
inner += `.check(z.minLength(${schema.minItems}))`;
}
if (schema.maxItems !== undefined) {
inner += `.max(${schema.maxItems})`;
inner += `.check(z.maxLength(${schema.maxItems}))`;
}
}
zodSchemaStr = inner;
Expand Down
Loading