@miroir-framework/jzod-ts 0.8.0 → 0.8.3
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 +2 -2
- package/dist/index.cjs +20 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +21 -6
- package/package.json +3 -15
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Jzod-ts
|
|
2
|
-
|
|
1
|
+
# Jzod-ts
|
|
2
|
+
|
|
3
3
|
see [Jzod](https://github.com/miroir-framework/jzod) for usage information.
|
package/dist/index.cjs
CHANGED
|
@@ -53,14 +53,20 @@ module.exports = __toCommonJS(index_exports);
|
|
|
53
53
|
// src/JzodToTs.ts
|
|
54
54
|
var import_zod_to_ts = require("zod-to-ts");
|
|
55
55
|
var import_jzod = require("@miroir-framework/jzod");
|
|
56
|
+
var typeScriptLazyReferenceConverter = (innerReference, relativeReference) => (0, import_zod_to_ts.withGetType)(innerReference, (ts) => {
|
|
57
|
+
const actualTypeName = relativeReference ? relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
|
|
58
|
+
return ts.factory.createTypeReferenceNode(
|
|
59
|
+
ts.factory.createIdentifier(actualTypeName ?? "RELATIVEPATH_NOT_DEFINED"),
|
|
60
|
+
void 0
|
|
61
|
+
);
|
|
62
|
+
});
|
|
56
63
|
function jzodToZodTextAndZodSchemaForTsGeneration(element, context = {}) {
|
|
57
64
|
const contextFunction = () => context;
|
|
58
65
|
const elementZodSchemaAndDescription = (0, import_jzod.jzodToZodTextAndZodSchema)(
|
|
59
66
|
element,
|
|
60
67
|
contextFunction,
|
|
61
68
|
contextFunction,
|
|
62
|
-
|
|
63
|
-
// typeScriptGeneration
|
|
69
|
+
{ typeScriptLazyConverter: typeScriptLazyReferenceConverter }
|
|
64
70
|
);
|
|
65
71
|
return elementZodSchemaAndDescription;
|
|
66
72
|
}
|
|
@@ -75,7 +81,6 @@ function jzodToZodTextAndTsTypeText(element, context = {}, typeName) {
|
|
|
75
81
|
const tsNode = (0, import_zod_to_ts.zodToTs)(curr[1], typeName).node;
|
|
76
82
|
const typeAlias = (0, import_zod_to_ts.createTypeAlias)(tsNode, actualTypeName2);
|
|
77
83
|
const tsTypeString2 = (0, import_zod_to_ts.printNode)(typeAlias);
|
|
78
|
-
console.log("jzodToZodTextAndTsTypeText producing TS type for contextElement", curr[0]);
|
|
79
84
|
return [curr[0], tsTypeString2];
|
|
80
85
|
})
|
|
81
86
|
);
|
|
@@ -135,9 +140,19 @@ function jzodToZodTextAndTsTypeAliases(element, context = {}, typeName) {
|
|
|
135
140
|
};
|
|
136
141
|
}
|
|
137
142
|
function jzodToTsCode(typeName, jzodElement2, context = {}, exportPrefix = true, headerForZodImports = true, typeAnotationForSchema = [], extendedTsTypesText = "") {
|
|
143
|
+
console.log(
|
|
144
|
+
"################################### jzodToTsCodeeeeeeee typeName",
|
|
145
|
+
typeName,
|
|
146
|
+
"jzodElement",
|
|
147
|
+
jzodElement2 && jzodElement2.context ? JSON.stringify(
|
|
148
|
+
Object.entries(jzodElement2.context).map(([key, value]) => [key, !value]).map(([key, value]) => key + ": " + value),
|
|
149
|
+
null,
|
|
150
|
+
2
|
|
151
|
+
) : void 0
|
|
152
|
+
);
|
|
138
153
|
const schemaName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c) : "";
|
|
139
154
|
const actualTypeName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
|
|
140
|
-
const header = headerForZodImports ? `import { ZodType, ZodTypeAny, z } from "zod";` : "";
|
|
155
|
+
const header = typeof headerForZodImports == "string" ? headerForZodImports : headerForZodImports ? `import { ZodType, ZodTypeAny, z } from "zod";` : "";
|
|
141
156
|
const tsTypeStringsAndZodText = jzodToZodTextAndTsTypeText(jzodElement2, context, actualTypeName);
|
|
142
157
|
const contextTsTypesString = tsTypeStringsAndZodText.contextTsTypeText ? Object.entries(tsTypeStringsAndZodText.contextTsTypeText).reduce((acc, curr) => {
|
|
143
158
|
return exportPrefix ? `${acc}
|
|
@@ -187,7 +202,7 @@ var jzodRecord = import_zod.z.object({ optional: import_zod.z.boolean().optional
|
|
|
187
202
|
var jzodReference = import_zod.z.object({ optional: import_zod.z.boolean().optional(), nullable: import_zod.z.boolean().optional(), extra: import_zod.z.any().optional(), tag: import_zod.z.object({ value: import_zod.z.any(), schema: import_zod.z.object({ optional: import_zod.z.boolean().optional(), metaSchema: import_zod.z.lazy(() => jzodElement).optional(), valueSchema: import_zod.z.lazy(() => jzodElement).optional() }).strict().optional(), optional: import_zod.z.boolean().optional() }).strict().optional(), type: import_zod.z.literal("schemaReference"), context: import_zod.z.record(import_zod.z.string(), import_zod.z.lazy(() => jzodElement)).optional(), carryOn: import_zod.z.union([import_zod.z.lazy(() => jzodObject), import_zod.z.lazy(() => jzodUnion)]).optional(), definition: import_zod.z.object({ eager: import_zod.z.boolean().optional(), partial: import_zod.z.boolean().optional(), relativePath: import_zod.z.string().optional(), absolutePath: import_zod.z.string().optional() }).strict() }).strict();
|
|
188
203
|
var jzodSet = import_zod.z.object({ optional: import_zod.z.boolean().optional(), nullable: import_zod.z.boolean().optional(), extra: import_zod.z.any().optional(), tag: import_zod.z.object({ value: import_zod.z.any(), schema: import_zod.z.object({ optional: import_zod.z.boolean().optional(), metaSchema: import_zod.z.lazy(() => jzodElement).optional(), valueSchema: import_zod.z.lazy(() => jzodElement).optional() }).strict().optional(), optional: import_zod.z.boolean().optional() }).strict().optional(), type: import_zod.z.literal("set"), definition: import_zod.z.lazy(() => jzodElement) }).strict();
|
|
189
204
|
var jzodTuple = import_zod.z.object({ optional: import_zod.z.boolean().optional(), nullable: import_zod.z.boolean().optional(), extra: import_zod.z.any().optional(), tag: import_zod.z.object({ value: import_zod.z.any(), schema: import_zod.z.object({ optional: import_zod.z.boolean().optional(), metaSchema: import_zod.z.lazy(() => jzodElement).optional(), valueSchema: import_zod.z.lazy(() => jzodElement).optional() }).strict().optional(), optional: import_zod.z.boolean().optional() }).strict().optional(), type: import_zod.z.literal("tuple"), definition: import_zod.z.array(import_zod.z.lazy(() => jzodElement)) }).strict();
|
|
190
|
-
var jzodUnion = import_zod.z.object({ optional: import_zod.z.boolean().optional(), nullable: import_zod.z.boolean().optional(), extra: import_zod.z.any().optional(), tag: import_zod.z.object({ value: import_zod.z.any(), schema: import_zod.z.object({ optional: import_zod.z.boolean().optional(), metaSchema: import_zod.z.lazy(() => jzodElement).optional(), valueSchema: import_zod.z.lazy(() => jzodElement).optional() }).strict().optional(), optional: import_zod.z.boolean().optional() }).strict().optional(), type: import_zod.z.literal("union"), discriminator: import_zod.z.union([import_zod.z.object({ discriminatorType: import_zod.z.literal("string"), value: import_zod.z.string() }).strict(), import_zod.z.object({ discriminatorType: import_zod.z.literal("array"), value: import_zod.z.array(import_zod.z.string()) }).strict()]).optional(), carryOn: import_zod.z.union([import_zod.z.lazy(() => jzodObject), import_zod.z.lazy(() => jzodUnion)]).optional(), definition: import_zod.z.array(import_zod.z.lazy(() => jzodElement)) }).strict();
|
|
205
|
+
var jzodUnion = import_zod.z.object({ optional: import_zod.z.boolean().optional(), nullable: import_zod.z.boolean().optional(), extra: import_zod.z.any().optional(), tag: import_zod.z.object({ value: import_zod.z.any(), schema: import_zod.z.object({ optional: import_zod.z.boolean().optional(), metaSchema: import_zod.z.lazy(() => jzodElement).optional(), valueSchema: import_zod.z.lazy(() => jzodElement).optional() }).strict().optional(), optional: import_zod.z.boolean().optional() }).strict().optional(), type: import_zod.z.literal("union"), optInDiscriminator: import_zod.z.boolean().optional(), discriminator: import_zod.z.union([import_zod.z.object({ discriminatorType: import_zod.z.literal("string"), value: import_zod.z.string() }).strict(), import_zod.z.object({ discriminatorType: import_zod.z.literal("array"), value: import_zod.z.array(import_zod.z.string()) }).strict()]).optional(), carryOn: import_zod.z.union([import_zod.z.lazy(() => jzodObject), import_zod.z.lazy(() => jzodUnion)]).optional(), definition: import_zod.z.array(import_zod.z.lazy(() => jzodElement)) }).strict();
|
|
191
206
|
var jzodBootstrapElementSchema = import_zod.z.lazy(() => jzodElement);
|
|
192
207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
193
208
|
0 && (module.exports = {
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ context?: ZodTextAndZodSchemaRecord, typeName?: string): TsTypeAliasesAndZodText
|
|
|
27
27
|
* @returns a string containing the resulting TS code
|
|
28
28
|
*/
|
|
29
29
|
declare function jzodToTsCode(typeName: string, jzodElement: any, // to avoid circulatity on JzodElement
|
|
30
|
-
context?: ZodTextAndZodSchemaRecord, exportPrefix?: boolean, headerForZodImports?: boolean, typeAnotationForSchema?: string[], extendedTsTypesText?: string): string;
|
|
30
|
+
context?: ZodTextAndZodSchemaRecord, exportPrefix?: boolean, headerForZodImports?: boolean | string, typeAnotationForSchema?: string[], extendedTsTypesText?: string): string;
|
|
31
31
|
|
|
32
32
|
type JzodArray = {
|
|
33
33
|
optional?: boolean | undefined;
|
|
@@ -366,6 +366,7 @@ type JzodUnion = {
|
|
|
366
366
|
optional?: boolean | undefined;
|
|
367
367
|
} | undefined;
|
|
368
368
|
type: "union";
|
|
369
|
+
optInDiscriminator?: boolean | undefined;
|
|
369
370
|
discriminator?: ({
|
|
370
371
|
discriminatorType: "string";
|
|
371
372
|
value: string;
|
package/dist/index.js
CHANGED
|
@@ -6,18 +6,24 @@ const __dirname = dirname(__filename)
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// src/JzodToTs.ts
|
|
9
|
-
import { createTypeAlias, printNode, zodToTs } from "zod-to-ts";
|
|
9
|
+
import { createTypeAlias, printNode, withGetType, zodToTs } from "zod-to-ts";
|
|
10
10
|
import {
|
|
11
11
|
jzodToZodTextAndZodSchema
|
|
12
12
|
} from "@miroir-framework/jzod";
|
|
13
|
+
var typeScriptLazyReferenceConverter = (innerReference, relativeReference) => withGetType(innerReference, (ts) => {
|
|
14
|
+
const actualTypeName = relativeReference ? relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
|
|
15
|
+
return ts.factory.createTypeReferenceNode(
|
|
16
|
+
ts.factory.createIdentifier(actualTypeName ?? "RELATIVEPATH_NOT_DEFINED"),
|
|
17
|
+
void 0
|
|
18
|
+
);
|
|
19
|
+
});
|
|
13
20
|
function jzodToZodTextAndZodSchemaForTsGeneration(element, context = {}) {
|
|
14
21
|
const contextFunction = () => context;
|
|
15
22
|
const elementZodSchemaAndDescription = jzodToZodTextAndZodSchema(
|
|
16
23
|
element,
|
|
17
24
|
contextFunction,
|
|
18
25
|
contextFunction,
|
|
19
|
-
|
|
20
|
-
// typeScriptGeneration
|
|
26
|
+
{ typeScriptLazyConverter: typeScriptLazyReferenceConverter }
|
|
21
27
|
);
|
|
22
28
|
return elementZodSchemaAndDescription;
|
|
23
29
|
}
|
|
@@ -32,7 +38,6 @@ function jzodToZodTextAndTsTypeText(element, context = {}, typeName) {
|
|
|
32
38
|
const tsNode = zodToTs(curr[1], typeName).node;
|
|
33
39
|
const typeAlias = createTypeAlias(tsNode, actualTypeName2);
|
|
34
40
|
const tsTypeString2 = printNode(typeAlias);
|
|
35
|
-
console.log("jzodToZodTextAndTsTypeText producing TS type for contextElement", curr[0]);
|
|
36
41
|
return [curr[0], tsTypeString2];
|
|
37
42
|
})
|
|
38
43
|
);
|
|
@@ -92,9 +97,19 @@ function jzodToZodTextAndTsTypeAliases(element, context = {}, typeName) {
|
|
|
92
97
|
};
|
|
93
98
|
}
|
|
94
99
|
function jzodToTsCode(typeName, jzodElement2, context = {}, exportPrefix = true, headerForZodImports = true, typeAnotationForSchema = [], extendedTsTypesText = "") {
|
|
100
|
+
console.log(
|
|
101
|
+
"################################### jzodToTsCodeeeeeeee typeName",
|
|
102
|
+
typeName,
|
|
103
|
+
"jzodElement",
|
|
104
|
+
jzodElement2 && jzodElement2.context ? JSON.stringify(
|
|
105
|
+
Object.entries(jzodElement2.context).map(([key, value]) => [key, !value]).map(([key, value]) => key + ": " + value),
|
|
106
|
+
null,
|
|
107
|
+
2
|
|
108
|
+
) : void 0
|
|
109
|
+
);
|
|
95
110
|
const schemaName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c) : "";
|
|
96
111
|
const actualTypeName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
|
|
97
|
-
const header = headerForZodImports ? `import { ZodType, ZodTypeAny, z } from "zod";` : "";
|
|
112
|
+
const header = typeof headerForZodImports == "string" ? headerForZodImports : headerForZodImports ? `import { ZodType, ZodTypeAny, z } from "zod";` : "";
|
|
98
113
|
const tsTypeStringsAndZodText = jzodToZodTextAndTsTypeText(jzodElement2, context, actualTypeName);
|
|
99
114
|
const contextTsTypesString = tsTypeStringsAndZodText.contextTsTypeText ? Object.entries(tsTypeStringsAndZodText.contextTsTypeText).reduce((acc, curr) => {
|
|
100
115
|
return exportPrefix ? `${acc}
|
|
@@ -144,7 +159,7 @@ var jzodRecord = z.object({ optional: z.boolean().optional(), nullable: z.boolea
|
|
|
144
159
|
var jzodReference = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.any().optional(), tag: z.object({ value: z.any(), schema: z.object({ optional: z.boolean().optional(), metaSchema: z.lazy(() => jzodElement).optional(), valueSchema: z.lazy(() => jzodElement).optional() }).strict().optional(), optional: z.boolean().optional() }).strict().optional(), type: z.literal("schemaReference"), context: z.record(z.string(), z.lazy(() => jzodElement)).optional(), carryOn: z.union([z.lazy(() => jzodObject), z.lazy(() => jzodUnion)]).optional(), definition: z.object({ eager: z.boolean().optional(), partial: z.boolean().optional(), relativePath: z.string().optional(), absolutePath: z.string().optional() }).strict() }).strict();
|
|
145
160
|
var jzodSet = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.any().optional(), tag: z.object({ value: z.any(), schema: z.object({ optional: z.boolean().optional(), metaSchema: z.lazy(() => jzodElement).optional(), valueSchema: z.lazy(() => jzodElement).optional() }).strict().optional(), optional: z.boolean().optional() }).strict().optional(), type: z.literal("set"), definition: z.lazy(() => jzodElement) }).strict();
|
|
146
161
|
var jzodTuple = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.any().optional(), tag: z.object({ value: z.any(), schema: z.object({ optional: z.boolean().optional(), metaSchema: z.lazy(() => jzodElement).optional(), valueSchema: z.lazy(() => jzodElement).optional() }).strict().optional(), optional: z.boolean().optional() }).strict().optional(), type: z.literal("tuple"), definition: z.array(z.lazy(() => jzodElement)) }).strict();
|
|
147
|
-
var jzodUnion = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.any().optional(), tag: z.object({ value: z.any(), schema: z.object({ optional: z.boolean().optional(), metaSchema: z.lazy(() => jzodElement).optional(), valueSchema: z.lazy(() => jzodElement).optional() }).strict().optional(), optional: z.boolean().optional() }).strict().optional(), type: z.literal("union"), discriminator: z.union([z.object({ discriminatorType: z.literal("string"), value: z.string() }).strict(), z.object({ discriminatorType: z.literal("array"), value: z.array(z.string()) }).strict()]).optional(), carryOn: z.union([z.lazy(() => jzodObject), z.lazy(() => jzodUnion)]).optional(), definition: z.array(z.lazy(() => jzodElement)) }).strict();
|
|
162
|
+
var jzodUnion = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.any().optional(), tag: z.object({ value: z.any(), schema: z.object({ optional: z.boolean().optional(), metaSchema: z.lazy(() => jzodElement).optional(), valueSchema: z.lazy(() => jzodElement).optional() }).strict().optional(), optional: z.boolean().optional() }).strict().optional(), type: z.literal("union"), optInDiscriminator: z.boolean().optional(), discriminator: z.union([z.object({ discriminatorType: z.literal("string"), value: z.string() }).strict(), z.object({ discriminatorType: z.literal("array"), value: z.array(z.string()) }).strict()]).optional(), carryOn: z.union([z.lazy(() => jzodObject), z.lazy(() => jzodUnion)]).optional(), definition: z.array(z.lazy(() => jzodElement)) }).strict();
|
|
148
163
|
var jzodBootstrapElementSchema = z.lazy(() => jzodElement);
|
|
149
164
|
export {
|
|
150
165
|
jzodArray,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miroir-framework/jzod-ts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.3",
|
|
5
5
|
"description": "The Typescript-related functionalities of Jzod.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -36,25 +36,13 @@
|
|
|
36
36
|
"test": "cross-env NODE_ENV=test vitest run --poolOptions.threads.singleThread --passWithNoTests -t"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@miroir-framework/jzod": "0.8.
|
|
39
|
+
"@miroir-framework/jzod": "0.8.3",
|
|
40
40
|
"zod": "^3.24.2",
|
|
41
41
|
"zod-to-ts": "^1.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
|
|
46
|
-
"@babel/preset-env": "^7.22.5",
|
|
47
|
-
"@babel/types": "^7.26.10",
|
|
48
|
-
"@jest/globals": "^29.3.1",
|
|
49
|
-
"@rollup/plugin-commonjs": "^24.0.1",
|
|
50
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
51
|
-
"@types/jest": "^29.2.4",
|
|
52
|
-
"babel-jest": "^29.4.0",
|
|
44
|
+
"@types/node": "^25.6.0",
|
|
53
45
|
"path": "^0.12.7",
|
|
54
|
-
"rollup": "^3.10.1",
|
|
55
|
-
"rollup-plugin-dts": "^5.1.1",
|
|
56
|
-
"rollup-plugin-typescript2": "^0.34.1",
|
|
57
|
-
"ts-jest": "^29.0.3",
|
|
58
46
|
"tsconfig-paths": "^4.1.2",
|
|
59
47
|
"tsup": "^8.4.0",
|
|
60
48
|
"tsx": "^4.19.3",
|