@ucdjs/schema-gen 0.2.1 → 0.2.3-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![codecov][codecov-src]][codecov-href]
5
6
 
6
7
  Utilities for working with the Unicode Character Database (UCD).
7
8
 
@@ -19,3 +20,5 @@ Published under [MIT License](./LICENSE).
19
20
  [npm-version-href]: https://npmjs.com/package/@ucdjs/schema-gen
20
21
  [npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs/schema-gen?style=flat&colorA=18181B&colorB=4169E1
21
22
  [npm-downloads-href]: https://npmjs.com/package/@ucdjs/schema-gen
23
+ [codecov-src]: https://img.shields.io/codecov/c/gh/ucdjs/ucd?style=flat&colorA=18181B&colorB=4169E1
24
+ [codecov-href]: https://codecov.io/gh/ucdjs/ucd
@@ -0,0 +1,48 @@
1
+ import { LanguageModel } from "ai";
2
+
3
+ //#region src/index.d.ts
4
+ interface SchemaGenFile {
5
+ /**
6
+ * The filePath to the data file.
7
+ */
8
+ filePath: string;
9
+ /**
10
+ * The version of the data file.
11
+ */
12
+ version: string;
13
+ }
14
+ interface ProcessedFile {
15
+ fields: {
16
+ type: string;
17
+ name: string;
18
+ description: string;
19
+ }[];
20
+ code: string;
21
+ fileName: string;
22
+ version: string;
23
+ }
24
+ interface SchemaGenOptions {
25
+ /**
26
+ * Files to generate structures for.
27
+ */
28
+ files: SchemaGenFile[];
29
+ /**
30
+ * The OpenAI API key to use for generating the schema.
31
+ */
32
+ openaiKey?: string;
33
+ /**
34
+ * The OpenAI model to use for generating fields.
35
+ * NOTE:
36
+ * This is good for testing purposes, where you
37
+ * can provide a mock model to test the generation.
38
+ *
39
+ * If not provided, it will create a new OpenAI instance
40
+ * with the default model.
41
+ *
42
+ * SEE: https://ai-sdk.dev/docs/ai-sdk-core/testing
43
+ */
44
+ model?: LanguageModel;
45
+ }
46
+ declare function runSchemagen(options: SchemaGenOptions): Promise<ProcessedFile[]>;
47
+ //#endregion
48
+ export { ProcessedFile, SchemaGenFile, SchemaGenOptions, runSchemagen };
@@ -1,9 +1,9 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { RawDataFile } from "@luxass/unicode-utils";
3
+ import { RawDataFile } from "@luxass/unicode-utils-old";
4
4
  import { dedent, sanitizeIdentifier, toPascalCase, toSnakeCase } from "@luxass/utils";
5
+ import { createConcurrencyLimiter } from "@ucdjs-internal/shared";
5
6
  import { genArrayFromRaw, genInterface } from "knitwork";
6
- import pLimit from "p-limit";
7
7
  import { createOpenAI } from "@ai-sdk/openai";
8
8
  import { generateObject } from "ai";
9
9
  import { z } from "zod";
@@ -168,7 +168,7 @@ async function generateFields(options) {
168
168
  if (!apiKey && !model) return null;
169
169
  const openai = model != null ? null : createOpenAI({ apiKey });
170
170
  try {
171
- const result = await generateObject({
171
+ return (await generateObject({
172
172
  model: model ?? openai("gpt-4o-mini"),
173
173
  schema: z.object({ fields: z.array(z.object({
174
174
  name: z.string(),
@@ -176,8 +176,7 @@ async function generateFields(options) {
176
176
  description: z.string()
177
177
  })) }),
178
178
  prompt: SYSTEM_PROMPT.replace("{{INPUT}}", datafile.heading)
179
- });
180
- return result.object.fields;
179
+ })).object.fields;
181
180
  } catch (err) {
182
181
  console.error("error generating fields:", err);
183
182
  return null;
@@ -188,7 +187,7 @@ async function generateFields(options) {
188
187
  //#region src/index.ts
189
188
  async function runSchemagen(options) {
190
189
  const inputFiles = options.files;
191
- const limit = pLimit(10);
190
+ const limit = createConcurrencyLimiter(10);
192
191
  if (!options.openaiKey && !options.model) throw new Error("Either openaiKey or model must be provided");
193
192
  const processPromises = inputFiles.map(({ filePath, version }) => limit(() => processFile({
194
193
  filePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucdjs/schema-gen",
3
- "version": "0.2.1",
3
+ "version": "0.2.3-beta.2",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Lucas Nørgård",
@@ -18,40 +18,43 @@
18
18
  "url": "https://github.com/ucdjs/ucd/issues"
19
19
  },
20
20
  "exports": {
21
- ".": "./dist/index.js",
21
+ ".": "./dist/index.mjs",
22
22
  "./package.json": "./package.json"
23
23
  },
24
- "main": "./dist/index.js",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.ts",
24
+ "types": "./dist/index.d.mts",
27
25
  "files": [
28
26
  "dist"
29
27
  ],
28
+ "engines": {
29
+ "node": ">=22.18"
30
+ },
30
31
  "dependencies": {
31
- "@ai-sdk/openai": "^1.3.22",
32
- "@luxass/unicode-utils": "^0.9.0",
33
- "@luxass/utils": "^2.2.1",
34
- "ai": "^4.3.16",
35
- "knitwork": "^1.2.0",
36
- "p-limit": "^6.2.0",
37
- "zod": "^3.25.17"
32
+ "@ai-sdk/openai": "3.0.26",
33
+ "@luxass/unicode-utils-old": "npm:@luxass/unicode-utils@0.11.0",
34
+ "@luxass/utils": "2.7.3",
35
+ "ai": "6.0.79",
36
+ "knitwork": "1.3.0",
37
+ "zod": "4.3.6",
38
+ "@ucdjs-internal/shared": "0.1.1-beta.2"
38
39
  },
39
40
  "devDependencies": {
40
- "@luxass/eslint-config": "^4.18.1",
41
- "eslint": "^9.27.0",
42
- "publint": "^0.3.12",
43
- "tsdown": "v0.9.3",
44
- "typescript": "^5.8.3",
45
- "vitest-testdirs": "^4.0.0"
41
+ "@luxass/eslint-config": "7.2.0",
42
+ "eslint": "10.0.0",
43
+ "publint": "0.3.17",
44
+ "tsdown": "0.20.3",
45
+ "typescript": "5.9.3",
46
+ "vitest-testdirs": "4.4.2",
47
+ "@ucdjs-tooling/tsconfig": "1.0.0",
48
+ "@ucdjs-tooling/tsdown-config": "1.0.0"
46
49
  },
47
50
  "publishConfig": {
48
51
  "access": "public"
49
52
  },
50
53
  "scripts": {
51
- "build": "tsdown",
54
+ "build": "tsdown --tsconfig=./tsconfig.build.json",
52
55
  "dev": "tsdown --watch",
53
56
  "clean": "git clean -xdf dist node_modules",
54
57
  "lint": "eslint .",
55
- "typecheck": "tsc --noEmit"
58
+ "typecheck": "tsc --noEmit -p tsconfig.build.json"
56
59
  }
57
60
  }
package/dist/index.d.ts DELETED
@@ -1,49 +0,0 @@
1
- import { LanguageModelV1 } from "ai";
2
-
3
- //#region src/index.d.ts
4
- interface SchemaGenFile {
5
- /**
6
- * The filePath to the data file.
7
- */
8
- filePath: string;
9
- /**
10
- * The version of the data file.
11
- */
12
- version: string;
13
- }
14
- interface ProcessedFile {
15
- fields: {
16
- type: string;
17
- name: string;
18
- description: string;
19
- }[];
20
- code: string;
21
- fileName: string;
22
- version: string;
23
- }
24
- interface SchemaGenOptions {
25
- /**
26
- * Files to generate structures for.
27
- */
28
- files: SchemaGenFile[];
29
- /**
30
- * The OpenAI API key to use for generating the schema.
31
- */
32
- openaiKey?: string;
33
- /**
34
- * The OpenAI model to use for generating fields.
35
- * NOTE:
36
- * This is good for testing purposes, where you
37
- * can provide a mock model to test the generation.
38
- *
39
- * If not provided, it will create a new OpenAI instance
40
- * with the default model.
41
- *
42
- * SEE: https://ai-sdk.dev/docs/ai-sdk-core/testing
43
- */
44
- model?: LanguageModelV1;
45
- }
46
- declare function runSchemagen(options: SchemaGenOptions): Promise<ProcessedFile[]>;
47
-
48
- //#endregion
49
- export { ProcessedFile, SchemaGenFile, SchemaGenOptions, runSchemagen };