@miroir-framework/jzod-ts 0.5.3 → 0.6.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/dist/bundle.d.ts +177 -337
- package/dist/bundle.js +42 -257
- package/dist/out-tsc/dts/src/JzodToTs.d.ts +17 -0
- package/dist/out-tsc/dts/src/JzodTsInterface.d.ts +397 -0
- package/dist/out-tsc/dts/src/index.d.ts +3 -0
- package/dist/out-tsc/dts/src/preBuild.d.ts +1 -0
- package/dist/out-tsc/dts/src/tools.d.ts +4 -0
- package/dist/out-tsc/src/JzodToTs.js +47 -0
- package/dist/out-tsc/src/JzodTsInterface.js +250 -0
- package/dist/out-tsc/src/index.js +34 -0
- package/dist/out-tsc/src/preBuild.js +42 -0
- package/dist/out-tsc/src/tools.js +17 -0
- package/dist/src/JzodToTs.d.ts +2 -2
- package/dist/src/generated_jzodBootstrapElementSchema.d.ts +246 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/preBuild.d.ts +1 -0
- package/package.json +40 -38
- package/src/JzodToTs.ts +114 -109
- package/src/generated_jzodBootstrapElementSchema.ts +249 -0
- package/src/index.ts +60 -60
- package/src/preBuild.ts +58 -0
- package/tests/jzod-ts.test.ts +108 -108
- package/tests/resources/tsTypeGeneration-testJzodSchema1 - reference.ts +5 -5
- package/tests/resources/tsTypeGeneration-testJzodSchema2 - reference.ts +11 -11
- package/tests/resources/tsTypeGeneration-testJzodSchema3 - reference.ts +19 -19
- package/tests/resources/tsTypeGeneration-testJzodSchema4 - reference.ts +250 -250
- package/tsconfig.json +25 -25
- package/src/JzodTsInterface.ts +0 -450
package/src/index.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
export {
|
|
2
|
-
jzodToTsCode,
|
|
3
|
-
jzodToTsTypeAliasesAndZodText,
|
|
4
|
-
TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText,
|
|
5
|
-
TsTypeAliases,
|
|
6
|
-
} from "./JzodToTs";
|
|
7
|
-
export { printTsTypeAlias, printTsTypeAliases } from "./tools";
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
// SCHEMAS (const)
|
|
11
|
-
jzodArray,
|
|
12
|
-
jzodAttribute,
|
|
13
|
-
jzodAttributeDateValidations,
|
|
14
|
-
jzodAttributeDateWithValidations,
|
|
15
|
-
jzodAttributeNumberValidations,
|
|
16
|
-
jzodAttributeNumberWithValidations,
|
|
17
|
-
jzodAttributeStringValidations,
|
|
18
|
-
jzodAttributeStringWithValidations,
|
|
19
|
-
jzodElement,
|
|
20
|
-
jzodEnumAttributeTypes,
|
|
21
|
-
jzodEnumElementTypes,
|
|
22
|
-
jzodEnum,
|
|
23
|
-
jzodFunction,
|
|
24
|
-
jzodIntersection,
|
|
25
|
-
jzodLazy,
|
|
26
|
-
jzodLiteral,
|
|
27
|
-
|
|
28
|
-
jzodObject,
|
|
29
|
-
jzodPromise,
|
|
30
|
-
jzodRecord,
|
|
31
|
-
jzodReference,
|
|
32
|
-
jzodSet,
|
|
33
|
-
jzodTuple,
|
|
34
|
-
jzodUnion,
|
|
35
|
-
// TYPES
|
|
36
|
-
JzodArray,
|
|
37
|
-
JzodAttribute,
|
|
38
|
-
JzodAttributeDateValidations,
|
|
39
|
-
JzodAttributeDateWithValidations,
|
|
40
|
-
JzodAttributeNumberValidations,
|
|
41
|
-
JzodAttributeNumberWithValidations,
|
|
42
|
-
JzodAttributeStringValidations,
|
|
43
|
-
JzodAttributeStringWithValidations,
|
|
44
|
-
JzodElement,
|
|
45
|
-
JzodEnum,
|
|
46
|
-
|
|
47
|
-
JzodFunction,
|
|
48
|
-
JzodEnumElementTypes,
|
|
49
|
-
JzodIntersection,
|
|
50
|
-
JzodLazy,
|
|
51
|
-
JzodLiteral,
|
|
52
|
-
JzodMap,
|
|
53
|
-
JzodObject,
|
|
54
|
-
JzodPromise,
|
|
55
|
-
JzodRecord,
|
|
56
|
-
JzodReference,
|
|
57
|
-
JzodSet,
|
|
58
|
-
JzodUnion,
|
|
59
|
-
JzodTuple,
|
|
60
|
-
} from "./
|
|
1
|
+
export {
|
|
2
|
+
jzodToTsCode,
|
|
3
|
+
jzodToTsTypeAliasesAndZodText,
|
|
4
|
+
TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText,
|
|
5
|
+
TsTypeAliases,
|
|
6
|
+
} from "./JzodToTs";
|
|
7
|
+
export { printTsTypeAlias, printTsTypeAliases } from "./tools";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
// SCHEMAS (const)
|
|
11
|
+
jzodArray,
|
|
12
|
+
jzodAttribute,
|
|
13
|
+
jzodAttributeDateValidations,
|
|
14
|
+
jzodAttributeDateWithValidations,
|
|
15
|
+
jzodAttributeNumberValidations,
|
|
16
|
+
jzodAttributeNumberWithValidations,
|
|
17
|
+
jzodAttributeStringValidations,
|
|
18
|
+
jzodAttributeStringWithValidations,
|
|
19
|
+
jzodElement,
|
|
20
|
+
jzodEnumAttributeTypes,
|
|
21
|
+
jzodEnumElementTypes,
|
|
22
|
+
jzodEnum,
|
|
23
|
+
jzodFunction,
|
|
24
|
+
jzodIntersection,
|
|
25
|
+
jzodLazy,
|
|
26
|
+
jzodLiteral,
|
|
27
|
+
jzodMap,
|
|
28
|
+
jzodObject,
|
|
29
|
+
jzodPromise,
|
|
30
|
+
jzodRecord,
|
|
31
|
+
jzodReference,
|
|
32
|
+
jzodSet,
|
|
33
|
+
jzodTuple,
|
|
34
|
+
jzodUnion,
|
|
35
|
+
// TYPES
|
|
36
|
+
JzodArray,
|
|
37
|
+
JzodAttribute,
|
|
38
|
+
JzodAttributeDateValidations,
|
|
39
|
+
JzodAttributeDateWithValidations,
|
|
40
|
+
JzodAttributeNumberValidations,
|
|
41
|
+
JzodAttributeNumberWithValidations,
|
|
42
|
+
JzodAttributeStringValidations,
|
|
43
|
+
JzodAttributeStringWithValidations,
|
|
44
|
+
JzodElement,
|
|
45
|
+
JzodEnum,
|
|
46
|
+
JzodEnumAttributeTypes,
|
|
47
|
+
JzodFunction,
|
|
48
|
+
JzodEnumElementTypes,
|
|
49
|
+
JzodIntersection,
|
|
50
|
+
JzodLazy,
|
|
51
|
+
JzodLiteral,
|
|
52
|
+
JzodMap,
|
|
53
|
+
JzodObject,
|
|
54
|
+
JzodPromise,
|
|
55
|
+
JzodRecord,
|
|
56
|
+
JzodReference,
|
|
57
|
+
JzodSet,
|
|
58
|
+
JzodUnion,
|
|
59
|
+
JzodTuple,
|
|
60
|
+
} from "./generated_jzodBootstrapElementSchema";
|
package/src/preBuild.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { jzodBootstrapElementSchema } from '@miroir-framework/jzod';
|
|
3
|
+
|
|
4
|
+
import { jzodToTsCode } from './JzodToTs';
|
|
5
|
+
|
|
6
|
+
export function generateZodSchemaFileFromJzodSchema(
|
|
7
|
+
// jzodElement,
|
|
8
|
+
// targetFileName,
|
|
9
|
+
// jzodSchemaVariableName,
|
|
10
|
+
jzodElement: any, //JzodElement,
|
|
11
|
+
targetFileName: string,
|
|
12
|
+
jzodSchemaVariableName:string,
|
|
13
|
+
) {
|
|
14
|
+
// console.log("generateZodSchemaFileFromJzodSchema called!");
|
|
15
|
+
|
|
16
|
+
const newFileContentsNotFormated = jzodToTsCode(jzodElement, true, jzodSchemaVariableName,true)
|
|
17
|
+
// const newFileContents = `import { JzodObject, jzodObject } from "@miroir-framework/jzod-ts";
|
|
18
|
+
const newFileContents = `${newFileContentsNotFormated}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
if (targetFileName && existsSync(targetFileName)) {
|
|
22
|
+
const oldFileContents = readFileSync(targetFileName).toString()
|
|
23
|
+
if (newFileContents != oldFileContents) {
|
|
24
|
+
// console.log("generateZodSchemaFileFromJzodSchema newFileContents",newFileContents);
|
|
25
|
+
writeFileSync(targetFileName,newFileContents);
|
|
26
|
+
} else {
|
|
27
|
+
console.log("generateZodSchemaFileFromJzodSchema entityDefinitionReport old contents equal new contents, no file generation needed.");
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
writeFileSync(targetFileName,newFileContents);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ################################################################################################
|
|
35
|
+
const jzodSchemaConversion
|
|
36
|
+
: {
|
|
37
|
+
jzodElement: any,
|
|
38
|
+
targetFileName: string,
|
|
39
|
+
jzodSchemaVariableName:string,
|
|
40
|
+
}[]
|
|
41
|
+
= [
|
|
42
|
+
{
|
|
43
|
+
jzodElement: jzodBootstrapElementSchema,
|
|
44
|
+
targetFileName: "./src/generated_jzodBootstrapElementSchema.ts",
|
|
45
|
+
jzodSchemaVariableName: "jzodBootstrapElementSchema",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
for (const schema of jzodSchemaConversion) {
|
|
51
|
+
generateZodSchemaFileFromJzodSchema(schema.jzodElement,schema.targetFileName,schema.jzodSchemaVariableName)
|
|
52
|
+
console.info("GENERATED",schema.targetFileName);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("could not generate TS files from Jzod schemas", error);
|
|
57
|
+
|
|
58
|
+
}
|
package/tests/jzod-ts.test.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
|
-
import { jzodBootstrapElementSchema } from "@miroir-framework/jzod";
|
|
5
|
-
import { jzodToTsCode } from "../src/JzodToTs";
|
|
6
|
-
import { JzodElement, jzodElement } from "../src/JzodTsInterface";
|
|
7
|
-
|
|
8
|
-
const refsPath = "./tests/resources"
|
|
9
|
-
const tmpPath = "./tests/tmp";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const testJzodToTs = (
|
|
13
|
-
// testDirectory: string,
|
|
14
|
-
referenceFileName: string,
|
|
15
|
-
testFileName: string,
|
|
16
|
-
testJzodSchema:JzodElement,
|
|
17
|
-
exportPrefix: boolean,
|
|
18
|
-
typeName: string
|
|
19
|
-
) => {
|
|
20
|
-
console.log("testJzodToTs:", typeName);
|
|
21
|
-
|
|
22
|
-
const testResultSchemaFilePath = path.join(tmpPath,testFileName);
|
|
23
|
-
const expectedSchemaFilePath = path.join(refsPath,referenceFileName);
|
|
24
|
-
|
|
25
|
-
const result = jzodToTsCode(testJzodSchema,exportPrefix,typeName)
|
|
26
|
-
fs.writeFileSync(testResultSchemaFilePath,result);
|
|
27
|
-
|
|
28
|
-
const resultContents = result.replace(/(\r\n|\n|\r)/gm, "");
|
|
29
|
-
// console.log("ts Type generation resultContents", resultContents);
|
|
30
|
-
|
|
31
|
-
const expectedFileContents = fs.readFileSync(expectedSchemaFilePath).toString().replace(/(\r\n|\n|\r)/gm, "")
|
|
32
|
-
expect(resultContents).toEqual(expectedFileContents);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
describe(
|
|
37
|
-
'Jzod-Ts',
|
|
38
|
-
() => {
|
|
39
|
-
// ############################################################################################
|
|
40
|
-
it(
|
|
41
|
-
"Jzod to TS Type",
|
|
42
|
-
async() => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// ########################################################################################
|
|
46
|
-
const testJzodSchema1: JzodElement = { type: "simpleType", definition: "string" };
|
|
47
|
-
|
|
48
|
-
testJzodToTs(
|
|
49
|
-
"tsTypeGeneration-testJzodSchema1 - reference.ts",
|
|
50
|
-
"tsTypeGeneration-testJzodSchema1.ts",
|
|
51
|
-
testJzodSchema1,
|
|
52
|
-
true,
|
|
53
|
-
"testJzodSchema1"
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// ########################################################################################
|
|
57
|
-
const testJzodSchema2: JzodElement = {
|
|
58
|
-
type: "schemaReference",
|
|
59
|
-
context: {
|
|
60
|
-
a: { type: "simpleType", definition: "string" },
|
|
61
|
-
b: {
|
|
62
|
-
type: "object",
|
|
63
|
-
definition: {
|
|
64
|
-
test: { type: "schemaReference", definition: { relativePath: "a" } }
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
definition: { relativePath: "b" },
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
testJzodToTs(
|
|
72
|
-
"tsTypeGeneration-testJzodSchema2 - reference.ts",
|
|
73
|
-
"tsTypeGeneration-testJzodSchema2.ts",
|
|
74
|
-
testJzodSchema2,
|
|
75
|
-
true,
|
|
76
|
-
"testJzodSchema2"
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// ########################################################################################
|
|
80
|
-
const testJzodSchema4:JzodElement =
|
|
81
|
-
{
|
|
82
|
-
type: "schemaReference",
|
|
83
|
-
context: {
|
|
84
|
-
...jzodBootstrapElementSchema.context,
|
|
85
|
-
a: {
|
|
86
|
-
type: "array",
|
|
87
|
-
definition: { type: "schemaReference", definition: {relativePath: "jzodArray"} }
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
definition: {
|
|
91
|
-
relativePath: "a"
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
testJzodToTs(
|
|
96
|
-
"tsTypeGeneration-testJzodSchema4 - reference.ts",
|
|
97
|
-
"tsTypeGeneration-testJzodSchema4.ts",
|
|
98
|
-
testJzodSchema4,
|
|
99
|
-
true,
|
|
100
|
-
"testJzodSchema4"
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import { jzodBootstrapElementSchema } from "@miroir-framework/jzod";
|
|
5
|
+
import { jzodToTsCode } from "../src/JzodToTs";
|
|
6
|
+
import { JzodElement, jzodElement } from "../src/JzodTsInterface";
|
|
7
|
+
|
|
8
|
+
const refsPath = "./tests/resources"
|
|
9
|
+
const tmpPath = "./tests/tmp";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const testJzodToTs = (
|
|
13
|
+
// testDirectory: string,
|
|
14
|
+
referenceFileName: string,
|
|
15
|
+
testFileName: string,
|
|
16
|
+
testJzodSchema:JzodElement,
|
|
17
|
+
exportPrefix: boolean,
|
|
18
|
+
typeName: string
|
|
19
|
+
) => {
|
|
20
|
+
console.log("testJzodToTs:", typeName);
|
|
21
|
+
|
|
22
|
+
const testResultSchemaFilePath = path.join(tmpPath,testFileName);
|
|
23
|
+
const expectedSchemaFilePath = path.join(refsPath,referenceFileName);
|
|
24
|
+
|
|
25
|
+
const result = jzodToTsCode(testJzodSchema,exportPrefix,typeName)
|
|
26
|
+
fs.writeFileSync(testResultSchemaFilePath,result);
|
|
27
|
+
|
|
28
|
+
const resultContents = result.replace(/(\r\n|\n|\r)/gm, "");
|
|
29
|
+
// console.log("ts Type generation resultContents", resultContents);
|
|
30
|
+
|
|
31
|
+
const expectedFileContents = fs.readFileSync(expectedSchemaFilePath).toString().replace(/(\r\n|\n|\r)/gm, "")
|
|
32
|
+
expect(resultContents).toEqual(expectedFileContents);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
describe(
|
|
37
|
+
'Jzod-Ts',
|
|
38
|
+
() => {
|
|
39
|
+
// ############################################################################################
|
|
40
|
+
it(
|
|
41
|
+
"Jzod to TS Type",
|
|
42
|
+
async() => {
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// ########################################################################################
|
|
46
|
+
const testJzodSchema1: JzodElement = { type: "simpleType", definition: "string" };
|
|
47
|
+
|
|
48
|
+
testJzodToTs(
|
|
49
|
+
"tsTypeGeneration-testJzodSchema1 - reference.ts",
|
|
50
|
+
"tsTypeGeneration-testJzodSchema1.ts",
|
|
51
|
+
testJzodSchema1,
|
|
52
|
+
true,
|
|
53
|
+
"testJzodSchema1"
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// ########################################################################################
|
|
57
|
+
const testJzodSchema2: JzodElement = {
|
|
58
|
+
type: "schemaReference",
|
|
59
|
+
context: {
|
|
60
|
+
a: { type: "simpleType", definition: "string" },
|
|
61
|
+
b: {
|
|
62
|
+
type: "object",
|
|
63
|
+
definition: {
|
|
64
|
+
test: { type: "schemaReference", definition: { relativePath: "a" } }
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
definition: { relativePath: "b" },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
testJzodToTs(
|
|
72
|
+
"tsTypeGeneration-testJzodSchema2 - reference.ts",
|
|
73
|
+
"tsTypeGeneration-testJzodSchema2.ts",
|
|
74
|
+
testJzodSchema2,
|
|
75
|
+
true,
|
|
76
|
+
"testJzodSchema2"
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// ########################################################################################
|
|
80
|
+
const testJzodSchema4:JzodElement =
|
|
81
|
+
{
|
|
82
|
+
type: "schemaReference",
|
|
83
|
+
context: {
|
|
84
|
+
...jzodBootstrapElementSchema.context,
|
|
85
|
+
a: {
|
|
86
|
+
type: "array",
|
|
87
|
+
definition: { type: "schemaReference", definition: {relativePath: "jzodArray"} }
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
definition: {
|
|
91
|
+
relativePath: "a"
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
testJzodToTs(
|
|
96
|
+
"tsTypeGeneration-testJzodSchema4 - reference.ts",
|
|
97
|
+
"tsTypeGeneration-testJzodSchema4.ts",
|
|
98
|
+
testJzodSchema4,
|
|
99
|
+
true,
|
|
100
|
+
"testJzodSchema4"
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
-
|
|
3
|
-
export type TestJzodSchema1 = string;
|
|
4
|
-
|
|
5
|
-
export const testJzodSchema1
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type TestJzodSchema1 = string;
|
|
4
|
+
|
|
5
|
+
export const testJzodSchema1 = z.string();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
-
|
|
3
|
-
export type A = string;
|
|
4
|
-
export type B = {
|
|
5
|
-
test
|
|
6
|
-
};
|
|
7
|
-
export type TestJzodSchema2 = B;
|
|
8
|
-
|
|
9
|
-
export const a
|
|
10
|
-
export const b
|
|
11
|
-
export const testJzodSchema2
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type A = string;
|
|
4
|
+
export type B = {
|
|
5
|
+
test: A;
|
|
6
|
+
};
|
|
7
|
+
export type TestJzodSchema2 = B;
|
|
8
|
+
|
|
9
|
+
export const a = z.string();
|
|
10
|
+
export const b = z.object({test:z.lazy(() =>a)}).strict();
|
|
11
|
+
export const testJzodSchema2 = z.lazy(() =>b);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type jzodLiteral = {
|
|
5
|
-
optional?: boolean | undefined;
|
|
6
|
-
extra?: {
|
|
7
|
-
[x: string]: any;
|
|
8
|
-
} | undefined;
|
|
9
|
-
type: "literal";
|
|
10
|
-
definition: string;
|
|
11
|
-
};
|
|
12
|
-
type jzodElement = jzodLiteral;
|
|
13
|
-
type testJzodSchema3 = {
|
|
14
|
-
b: jzodElement[];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const jzodLiteral=z.object({optional:z.boolean().optional(),extra:z.record(z.string(),z.any()).optional(),type:z.literal("literal"),definition:z.string(),}).strict();
|
|
18
|
-
export const jzodElement=z.union([z.lazy(() =>jzodLiteral),]);
|
|
19
|
-
export const testJzodSchema3 = z.object({b:z.array(z.lazy(() =>jzodElement)),}).strict();
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
type jzodLiteral = {
|
|
5
|
+
optional?: boolean | undefined;
|
|
6
|
+
extra?: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
} | undefined;
|
|
9
|
+
type: "literal";
|
|
10
|
+
definition: string;
|
|
11
|
+
};
|
|
12
|
+
type jzodElement = jzodLiteral;
|
|
13
|
+
type testJzodSchema3 = {
|
|
14
|
+
b: jzodElement[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const jzodLiteral=z.object({optional:z.boolean().optional(),extra:z.record(z.string(),z.any()).optional(),type:z.literal("literal"),definition:z.string(),}).strict();
|
|
18
|
+
export const jzodElement=z.union([z.lazy(() =>jzodLiteral),]);
|
|
19
|
+
export const testJzodSchema3 = z.object({b:z.array(z.lazy(() =>jzodElement)),}).strict();
|