@xube/kit-generator 0.2.8 → 0.2.12
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/dist/type/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import { GeneratedFilePath } from "./type-helpers";
|
|
3
3
|
/**
|
|
4
4
|
* Function that generates TS Type from Zod Schema
|
|
@@ -6,5 +6,5 @@ import { GeneratedFilePath } from "./type-helpers";
|
|
|
6
6
|
* @param name The name of the schema. The outputted compiled validation file will be <name>.ts
|
|
7
7
|
* @param schema The zod schema
|
|
8
8
|
*/
|
|
9
|
-
export declare const generateTypesFromZodSchema: (name: string, schema:
|
|
9
|
+
export declare const generateTypesFromZodSchema: (name: string, schema: z.ZodType, rootDir: string) => GeneratedFilePath;
|
|
10
10
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/type/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/type/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/type/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,SAC/B,MAAM,UACJ,CAAC,CAAC,OAAO,WACR,MAAM,KACd,iBAqCF,CAAC"}
|
package/dist/type/types.js
CHANGED
|
@@ -16,7 +16,8 @@ const generateTypesFromZodSchema = (name, schema, rootDir) => {
|
|
|
16
16
|
throw Error("Name must not be empty");
|
|
17
17
|
}
|
|
18
18
|
const identifier = (0, identifier_1.getIdentifierFromName)(name);
|
|
19
|
-
const
|
|
19
|
+
const auxiliaryTypeStore = (0, zod_to_ts_1.createAuxiliaryTypeStore)();
|
|
20
|
+
const typeAlias = (0, zod_to_ts_1.createTypeAlias)((0, zod_to_ts_1.zodToTs)(schema, { auxiliaryTypeStore }).node, identifier);
|
|
20
21
|
const dir = (0, path_1.join)(rootDir, "generated", "types");
|
|
21
22
|
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
22
23
|
const generatedFilePath = (0, path_1.join)(dir, `${name}.ts`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import { GeneratedFilePath } from "./type-helpers";
|
|
3
3
|
/**
|
|
4
4
|
* Function that generates compiled ajv validation for fast validation of unknown data
|
|
@@ -6,6 +6,6 @@ import { GeneratedFilePath } from "./type-helpers";
|
|
|
6
6
|
* @param name The name of the schema. The outputted compiled validation file will be <name>.js
|
|
7
7
|
* @param schema The zod schema
|
|
8
8
|
*/
|
|
9
|
-
export declare const generateValidatorsFromZodSchema: (name: string, schema: ZodType
|
|
9
|
+
export declare const generateValidatorsFromZodSchema: (name: string, schema: z.ZodType, rootDir: string) => GeneratedFilePath;
|
|
10
10
|
export declare const getImportableValidatorFilePathRelativeToGeneratedFolder: (name: string) => string;
|
|
11
11
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/type/validators.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/type/validators.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,SACpC,MAAM,UACJ,CAAC,CAAC,OAAO,WACR,MAAM,KACd,iBAiCF,CAAC;AAEF,eAAO,MAAM,uDAAuD,SAC5D,MAAM,WAGb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-generator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"pascal-case": "^3.1.2",
|
|
24
24
|
"ts-node": "^10.9.2",
|
|
25
25
|
"typescript": "^5.6.2",
|
|
26
|
-
"zod": "^
|
|
27
|
-
"zod-to-json-schema": "^3.
|
|
28
|
-
"zod-to-ts": "^
|
|
26
|
+
"zod": "^4.4.3",
|
|
27
|
+
"zod-to-json-schema": "^3.25.2",
|
|
28
|
+
"zod-to-ts": "^2.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@xube/kit-build": "^0.2.
|
|
31
|
+
"@xube/kit-build": "^0.2.12"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/type/types.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import {
|
|
5
|
+
createAuxiliaryTypeStore,
|
|
6
|
+
createTypeAlias,
|
|
7
|
+
printNode,
|
|
8
|
+
zodToTs,
|
|
9
|
+
} from "zod-to-ts";
|
|
5
10
|
import { GeneratedFilePath } from "./type-helpers";
|
|
6
11
|
import { getIdentifierFromName } from "./identifier";
|
|
7
12
|
/**
|
|
@@ -12,7 +17,7 @@ import { getIdentifierFromName } from "./identifier";
|
|
|
12
17
|
*/
|
|
13
18
|
export const generateTypesFromZodSchema = (
|
|
14
19
|
name: string,
|
|
15
|
-
schema:
|
|
20
|
+
schema: z.ZodType,
|
|
16
21
|
rootDir: string
|
|
17
22
|
): GeneratedFilePath => {
|
|
18
23
|
if (!name) {
|
|
@@ -21,7 +26,11 @@ export const generateTypesFromZodSchema = (
|
|
|
21
26
|
|
|
22
27
|
const identifier = getIdentifierFromName(name);
|
|
23
28
|
|
|
24
|
-
const
|
|
29
|
+
const auxiliaryTypeStore = createAuxiliaryTypeStore();
|
|
30
|
+
const typeAlias = createTypeAlias(
|
|
31
|
+
zodToTs(schema, { auxiliaryTypeStore }).node,
|
|
32
|
+
identifier,
|
|
33
|
+
);
|
|
25
34
|
|
|
26
35
|
const dir: string = join(rootDir, "generated", "types");
|
|
27
36
|
mkdirSync(dir, { recursive: true });
|
package/src/type/validators.ts
CHANGED
|
@@ -6,7 +6,7 @@ import standaloneCode from "ajv/dist/standalone";
|
|
|
6
6
|
import addFormats from "ajv-formats";
|
|
7
7
|
|
|
8
8
|
import zodToJsonSchema from "zod-to-json-schema";
|
|
9
|
-
import {
|
|
9
|
+
import { z } from "zod";
|
|
10
10
|
import { GeneratedFilePath } from "./type-helpers";
|
|
11
11
|
/**
|
|
12
12
|
* Function that generates compiled ajv validation for fast validation of unknown data
|
|
@@ -16,7 +16,7 @@ import { GeneratedFilePath } from "./type-helpers";
|
|
|
16
16
|
*/
|
|
17
17
|
export const generateValidatorsFromZodSchema = (
|
|
18
18
|
name: string,
|
|
19
|
-
schema: ZodType
|
|
19
|
+
schema: z.ZodType,
|
|
20
20
|
rootDir: string
|
|
21
21
|
): GeneratedFilePath => {
|
|
22
22
|
const ajv = new Ajv({
|
|
@@ -36,7 +36,7 @@ export const generateValidatorsFromZodSchema = (
|
|
|
36
36
|
addFormats(ajv);
|
|
37
37
|
const validationCode = standaloneCode(
|
|
38
38
|
ajv,
|
|
39
|
-
ajv.compile(zodToJsonSchema(schema, `${name.toLowerCase()}JsonSchema`))
|
|
39
|
+
ajv.compile(zodToJsonSchema(schema as any, `${name.toLowerCase()}JsonSchema`))
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
const dir: string = join(rootDir, "generated", "validators");
|