@ucdjs/schema-gen 0.1.0
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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +69 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Lucas Nørgård
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @ucdjs/schema-gen
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
|
|
6
|
+
Utilities for working with the Unicode Character Database (UCD).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @ucdjs/schema-gen
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 📄 License
|
|
15
|
+
|
|
16
|
+
Published under [MIT License](./LICENSE).
|
|
17
|
+
|
|
18
|
+
[npm-version-src]: https://img.shields.io/npm/v/@ucdjs/schema-gen?style=flat&colorA=18181B&colorB=4169E1
|
|
19
|
+
[npm-version-href]: https://npmjs.com/package/@ucdjs/schema-gen
|
|
20
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs/schema-gen?style=flat&colorA=18181B&colorB=4169E1
|
|
21
|
+
[npm-downloads-href]: https://npmjs.com/package/@ucdjs/schema-gen
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RawDataFile } from "@luxass/unicode-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/fields.d.ts
|
|
4
|
+
interface GenerateFieldsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The data file to generate fields for.
|
|
7
|
+
*/
|
|
8
|
+
datafile: RawDataFile;
|
|
9
|
+
/**
|
|
10
|
+
* The OpenAI API key to use for generating fields.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
}
|
|
14
|
+
declare function generateFields(options: GenerateFieldsOptions): Promise<string | null>;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { generateFields };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
2
|
+
import { dedent } from "@luxass/utils";
|
|
3
|
+
import { generateObject } from "ai";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/fields.ts
|
|
7
|
+
const SYSTEM_PROMOT = dedent`
|
|
8
|
+
<system_prompt>
|
|
9
|
+
<role>Expert TypeScript code generator specializing in interfaces and documentation</role>
|
|
10
|
+
|
|
11
|
+
<task>
|
|
12
|
+
<input>Text description: {{INPUT}}</input>
|
|
13
|
+
<output>TypeScript interface with comprehensive JSDoc comments</output>
|
|
14
|
+
</task>
|
|
15
|
+
|
|
16
|
+
<requirements>
|
|
17
|
+
<field_processing>
|
|
18
|
+
- Extract all relevant fields from text
|
|
19
|
+
- Convert field names to snake_case
|
|
20
|
+
- Preserve original order
|
|
21
|
+
</field_processing>
|
|
22
|
+
|
|
23
|
+
<documentation>
|
|
24
|
+
- JSDoc for each property only
|
|
25
|
+
- Document union types with double quotes (no enums)
|
|
26
|
+
- Explain constraints and formats with examples
|
|
27
|
+
- No JSDoc for the main interface
|
|
28
|
+
</documentation>
|
|
29
|
+
|
|
30
|
+
<structure>
|
|
31
|
+
- Single interface named after the input file name without version numbers (e.g., ArabicShaping not ArabicShaping-16.0.0)
|
|
32
|
+
- No additional interfaces or arrays
|
|
33
|
+
- Create ordered keys array named [INTERFACE_NAME]_FIELDS using SCREAMING_SNAKE_CASE
|
|
34
|
+
- Convert the interface name to SCREAMING_SNAKE_CASE by inserting underscores between camelCase words
|
|
35
|
+
- Use double quotes for field names in the keys array
|
|
36
|
+
- No example data or additional declarations
|
|
37
|
+
- Export all variables and interfaces
|
|
38
|
+
</structure>
|
|
39
|
+
</requirements>
|
|
40
|
+
|
|
41
|
+
<format>Single TypeScript code block containing only the interface and fields array, both exported</format>
|
|
42
|
+
|
|
43
|
+
<examples>
|
|
44
|
+
- Interface: NamedSequences -> Fields array: NAMED_SEQUENCES_FIELDS
|
|
45
|
+
- Interface: NamedSequencesProv -> Fields array: NAMED_SEQUENCES_PROV_FIELDS
|
|
46
|
+
- Interface: ArabicShaping -> Fields array: ARABIC_SHAPING_FIELDS
|
|
47
|
+
</examples>
|
|
48
|
+
</system_prompt>
|
|
49
|
+
`;
|
|
50
|
+
async function generateFields(options) {
|
|
51
|
+
const { datafile, apiKey } = options;
|
|
52
|
+
if (datafile.heading == null) return null;
|
|
53
|
+
if (!apiKey) return null;
|
|
54
|
+
const openai = createOpenAI({ apiKey });
|
|
55
|
+
try {
|
|
56
|
+
const result = await generateObject({
|
|
57
|
+
model: openai("gpt-4o-mini"),
|
|
58
|
+
schema: z.object({ code: z.string().describe("A TypeScript code block containing the JSDoc commented interface definition and the corresponding keys array with original casing.") }),
|
|
59
|
+
prompt: SYSTEM_PROMOT.replace("{{INPUT}}", datafile.heading)
|
|
60
|
+
});
|
|
61
|
+
return result.object.code;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error("error generating fields:", err);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { generateFields };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ucdjs/schema-gen",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Lucas Nørgård",
|
|
7
|
+
"email": "lucasnrgaard@gmail.com",
|
|
8
|
+
"url": "https://luxass.dev"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://github.com/ucdjs/ucd",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/ucdjs/ucd.git",
|
|
15
|
+
"directory": "packages/schema-gen"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ucdjs/ucd/issues"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.js",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@ai-sdk/openai": "^1.3.20",
|
|
32
|
+
"@luxass/unicode-utils": "^0.4.1",
|
|
33
|
+
"@luxass/utils": "^1.4.0",
|
|
34
|
+
"ai": "^4.3.10",
|
|
35
|
+
"zod": "^3.24.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@luxass/eslint-config": "^4.18.1",
|
|
39
|
+
"eslint": "^9.25.1",
|
|
40
|
+
"publint": "^0.3.12",
|
|
41
|
+
"tsdown": "v0.9.3",
|
|
42
|
+
"typescript": "^5.8.3",
|
|
43
|
+
"vitest-testdirs": "^3.0.1"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsdown",
|
|
50
|
+
"dev": "tsdown --watch",
|
|
51
|
+
"clean": "git clean -xdf dist node_modules",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
54
|
+
}
|
|
55
|
+
}
|