@miroir-framework/jzod-ts 0.6.2 → 0.6.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/LICENSE.md +21 -0
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.js +1 -1
- package/package.json +8 -2
- package/babel.config.cjs +0 -13
- package/dist/out-tsc/dts/src/JzodToTs.d.ts +0 -17
- package/dist/out-tsc/dts/src/generated_jzodBootstrapElementSchema.d.ts +0 -250
- package/dist/out-tsc/dts/src/index.d.ts +0 -3
- package/dist/out-tsc/dts/src/preBuild.d.ts +0 -1
- package/dist/out-tsc/dts/src/tools.d.ts +0 -4
- package/dist/src/JzodToTs.d.ts +0 -17
- package/dist/src/generated_jzodBootstrapElementSchema.d.ts +0 -250
- package/dist/src/index.d.ts +0 -3
- package/dist/src/preBuild.d.ts +0 -1
- package/dist/src/tools.d.ts +0 -4
- package/jest.config.js +0 -63
- package/rollup.config.js +0 -36
- package/src/JzodToTs.ts +0 -118
- package/src/generated_jzodBootstrapElementSchema.ts +0 -253
- package/src/index.ts +0 -60
- package/src/preBuild.ts +0 -59
- package/src/tools.ts +0 -25
- package/tests/jzod-ts.test.ts +0 -107
- package/tests/resources/tsTypeGeneration-testJzodSchema1 - reference.ts +0 -5
- package/tests/resources/tsTypeGeneration-testJzodSchema2 - reference.ts +0 -11
- package/tests/resources/tsTypeGeneration-testJzodSchema3 - reference.ts +0 -19
- package/tests/resources/tsTypeGeneration-testJzodSchema4 - reference.ts +0 -254
- package/tsconfig.json +0 -26
package/jest.config.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// import { pathsToModuleNameMapper } from 'ts-jest';
|
|
2
|
-
// import compilerOptions from './tsconfig'
|
|
3
|
-
|
|
4
|
-
const esModules = ['uuid'].join('|');
|
|
5
|
-
|
|
6
|
-
export default (path, options) =>({
|
|
7
|
-
"verbose": true,
|
|
8
|
-
"rootDir": ".",
|
|
9
|
-
"moduleDirectories": [
|
|
10
|
-
"node_modules",
|
|
11
|
-
],
|
|
12
|
-
transformIgnorePatterns: [`<rootDir>\/(?!(/node_modules/(?!${esModules})))\/`],
|
|
13
|
-
// modulePaths: ["./packages/miroir-standalone-app/src/"], // <-- This will be set to 'baseUrl' value
|
|
14
|
-
modulePaths: ["./src/"], // <-- This will be set to 'baseUrl' value
|
|
15
|
-
// modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value
|
|
16
|
-
moduleNameMapper:
|
|
17
|
-
// Object.assign(
|
|
18
|
-
{
|
|
19
|
-
// "^miroir-fwk(.*)$": "<rootDir>/src/$1",
|
|
20
|
-
// "^(.*)$": "$1",
|
|
21
|
-
'\\.(css|scss|sass)$': 'identity-obj-proxy',
|
|
22
|
-
}
|
|
23
|
-
// pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '<rootDir>/' } */)
|
|
24
|
-
// )
|
|
25
|
-
,
|
|
26
|
-
// resolver:options.defaultResolver(path, {...options}),
|
|
27
|
-
testEnvironment: "node",
|
|
28
|
-
moduleFileExtensions:[
|
|
29
|
-
"ts", "tsx", "js", "mjs", "cjs", "jsx", "json", "node"
|
|
30
|
-
],
|
|
31
|
-
// preset:'ts-jest/presets/default-esm',
|
|
32
|
-
"transform": {
|
|
33
|
-
"^.+\\.tsx?$": [
|
|
34
|
-
"ts-jest",
|
|
35
|
-
{
|
|
36
|
-
// useESM:true,
|
|
37
|
-
// tsconfig: "../../tsconfig.json"
|
|
38
|
-
tsconfig:
|
|
39
|
-
{
|
|
40
|
-
resolveJsonModule: true,
|
|
41
|
-
esModuleInterop: true,
|
|
42
|
-
allowSyntheticDefaultImports:true,
|
|
43
|
-
allowJs: true,
|
|
44
|
-
moduleResolution: "node",
|
|
45
|
-
// module: "ESNext",
|
|
46
|
-
// target: "ES2017",
|
|
47
|
-
// rootDir: "./src/",
|
|
48
|
-
traceResolution: true,
|
|
49
|
-
module:"commonjs"
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"^.+\\.js?$": ["babel-jest"],
|
|
54
|
-
},
|
|
55
|
-
// moduleNameMapper: {
|
|
56
|
-
// "^miroir-fwk\/(.+)$": "<rootDir>/src/$1",
|
|
57
|
-
// '\\.(css|scss|sass)$': 'identity-obj-proxy',
|
|
58
|
-
// },
|
|
59
|
-
"testPathIgnorePatterns": [
|
|
60
|
-
"./node_modules/",
|
|
61
|
-
"./.cache/"
|
|
62
|
-
],
|
|
63
|
-
})
|
package/rollup.config.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import typescript from 'rollup-plugin-typescript2';
|
|
2
|
-
import dts from 'rollup-plugin-dts';
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
{
|
|
6
|
-
input: ["src/index.ts"],
|
|
7
|
-
external: [
|
|
8
|
-
'zod',
|
|
9
|
-
'zod-to-ts',
|
|
10
|
-
'@miroir-framework/jzod',
|
|
11
|
-
],
|
|
12
|
-
output: [
|
|
13
|
-
{
|
|
14
|
-
file: `dist/bundle.js`,
|
|
15
|
-
entryFileNames: "[name].js",
|
|
16
|
-
format: "es",
|
|
17
|
-
exports: "named"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
plugins: [
|
|
21
|
-
typescript(),
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
input: ["dist/src/index.d.ts"],
|
|
26
|
-
output: [
|
|
27
|
-
{
|
|
28
|
-
file: `dist/bundle.d.ts`,
|
|
29
|
-
format: 'es',
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
plugins: [
|
|
33
|
-
dts(),
|
|
34
|
-
],
|
|
35
|
-
}
|
|
36
|
-
];
|
package/src/JzodToTs.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { ZodTypeAny } from "zod";
|
|
3
|
-
import { GetType, createTypeAlias, printNode, withGetType, zodToTs } from "zod-to-ts";
|
|
4
|
-
|
|
5
|
-
import { jzodElementSchemaToZodSchemaAndDescription } from "@miroir-framework/jzod";
|
|
6
|
-
|
|
7
|
-
import { JzodElement } from "./generated_jzodBootstrapElementSchema";
|
|
8
|
-
|
|
9
|
-
import { printTsTypeAliases } from "./tools";
|
|
10
|
-
// ################################################################################################
|
|
11
|
-
export type TsTypeAliases = {
|
|
12
|
-
[k: string]: ts.TypeAliasDeclaration;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ################################################################################################
|
|
16
|
-
export interface TsTypeAliasesAndZodText {
|
|
17
|
-
contextTsTypeAliases: { [k: string]: ts.TypeAliasDeclaration },
|
|
18
|
-
contextZodText: { [k: string]: string },
|
|
19
|
-
mainTsTypeAlias: ts.TypeAliasDeclaration,
|
|
20
|
-
mainZodText: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ################################################################################################
|
|
24
|
-
export function jzodToTsTypeAliasesAndZodText(
|
|
25
|
-
element: JzodElement,
|
|
26
|
-
typeName?: string,
|
|
27
|
-
): TsTypeAliasesAndZodText
|
|
28
|
-
{
|
|
29
|
-
const elementZodSchemaAndDescription = jzodElementSchemaToZodSchemaAndDescription(
|
|
30
|
-
element as any,
|
|
31
|
-
() => ({}),
|
|
32
|
-
() => ({}),
|
|
33
|
-
(innerReference: ZodTypeAny & GetType, relativeReference: string | undefined) =>
|
|
34
|
-
withGetType(innerReference, (ts:any) => {
|
|
35
|
-
const actualTypeName = relativeReference?relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
36
|
-
return ts.factory.createTypeReferenceNode(
|
|
37
|
-
ts.factory.createIdentifier(actualTypeName ?? "RELATIVEPATH_NOT_DEFINED"),
|
|
38
|
-
undefined
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const contextTsTypesString = Object.fromEntries(
|
|
45
|
-
Object.entries(elementZodSchemaAndDescription.contextZodSchema ?? {}).map((curr) => {
|
|
46
|
-
const actualTypeName = curr[0]?curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
47
|
-
const tsNode = zodToTs(curr[1], typeName).node;
|
|
48
|
-
const typeAlias = createTypeAlias(tsNode, actualTypeName);
|
|
49
|
-
return [curr[0], typeAlias];
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const tsTypeStringNode = zodToTs(elementZodSchemaAndDescription.zodSchema, typeName).node;
|
|
54
|
-
const tsTypeStringTypeAlias = createTypeAlias(tsTypeStringNode, typeName??"");
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
contextTsTypeAliases: contextTsTypesString,
|
|
58
|
-
contextZodText: elementZodSchemaAndDescription.contextZodText??{},
|
|
59
|
-
mainZodText: elementZodSchemaAndDescription.zodText,
|
|
60
|
-
mainTsTypeAlias: tsTypeStringTypeAlias,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// ################################################################################################
|
|
66
|
-
export function jzodToTsCode (
|
|
67
|
-
jzodElement: JzodElement,
|
|
68
|
-
exportPrefix: boolean = true,
|
|
69
|
-
typeName?: string,
|
|
70
|
-
// typeSchema: boolean = false,
|
|
71
|
-
typeAnotationForSchema: string[] = [],
|
|
72
|
-
): string {
|
|
73
|
-
// console.log(
|
|
74
|
-
// "################################### jzodToTsCode ",
|
|
75
|
-
// "jzodElement",
|
|
76
|
-
// JSON.stringify(jzodElement, null, 2)
|
|
77
|
-
// );
|
|
78
|
-
|
|
79
|
-
const schemaName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c):"";
|
|
80
|
-
const actualTypeName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
81
|
-
|
|
82
|
-
// console.log("jzodToTsCode typeAnotationForSchema", typeAnotationForSchema);
|
|
83
|
-
|
|
84
|
-
const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
|
|
85
|
-
|
|
86
|
-
const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, actualTypeName);
|
|
87
|
-
|
|
88
|
-
const bodyJsCode = typeAnotationForSchema.includes(schemaName??"")
|
|
89
|
-
? `export const ${schemaName}: z.ZodType<${actualTypeName}> = ${typeAliasesAndZodText.mainZodText};`
|
|
90
|
-
: `export const ${schemaName} = ${typeAliasesAndZodText.mainZodText};`;
|
|
91
|
-
|
|
92
|
-
const contextTsTypesString = printTsTypeAliases(typeAliasesAndZodText.contextTsTypeAliases, exportPrefix);
|
|
93
|
-
// console.log("jzodToTsCode zod text for converted jzodElement",typeAliasesAndZodText.contextZodText);
|
|
94
|
-
|
|
95
|
-
const contextJsCode = typeAliasesAndZodText.contextZodText
|
|
96
|
-
? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
|
|
97
|
-
const contextTypeName = curr[0]?curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
98
|
-
return typeAnotationForSchema.includes(curr[0])?
|
|
99
|
-
`${acc}
|
|
100
|
-
export const ${curr[0]}: z.ZodType<${contextTypeName}> = ${curr[1]};`
|
|
101
|
-
:
|
|
102
|
-
`${acc}
|
|
103
|
-
export const ${curr[0]} = ${curr[1]};`
|
|
104
|
-
;
|
|
105
|
-
}, "")
|
|
106
|
-
: ""
|
|
107
|
-
;
|
|
108
|
-
|
|
109
|
-
const tsTypesString = (exportPrefix?"export ":"") + printNode(typeAliasesAndZodText.mainTsTypeAlias);
|
|
110
|
-
// console.log("getTsCodeCorrespondingToZodSchemaAndDescription tsTypeString",tsTypesString);
|
|
111
|
-
|
|
112
|
-
return `${header}
|
|
113
|
-
${contextTsTypesString}
|
|
114
|
-
${tsTypesString}
|
|
115
|
-
${contextJsCode}
|
|
116
|
-
${bodyJsCode}
|
|
117
|
-
`;
|
|
118
|
-
}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
-
|
|
3
|
-
export type JzodBaseObject = {
|
|
4
|
-
optional?: boolean | undefined;
|
|
5
|
-
nullable?: boolean | undefined;
|
|
6
|
-
extra?: {
|
|
7
|
-
[x: string]: any;
|
|
8
|
-
} | undefined;
|
|
9
|
-
};
|
|
10
|
-
export type JzodArray = {
|
|
11
|
-
optional?: boolean | undefined;
|
|
12
|
-
nullable?: boolean | undefined;
|
|
13
|
-
extra?: {
|
|
14
|
-
[x: string]: any;
|
|
15
|
-
} | undefined;
|
|
16
|
-
type: "array";
|
|
17
|
-
definition: JzodElement;
|
|
18
|
-
};
|
|
19
|
-
export type JzodAttribute = {
|
|
20
|
-
optional?: boolean | undefined;
|
|
21
|
-
nullable?: boolean | undefined;
|
|
22
|
-
extra?: {
|
|
23
|
-
[x: string]: any;
|
|
24
|
-
} | undefined;
|
|
25
|
-
type: "simpleType";
|
|
26
|
-
coerce?: boolean | undefined;
|
|
27
|
-
definition: JzodEnumAttributeTypes;
|
|
28
|
-
};
|
|
29
|
-
export type JzodAttributeDateValidations = {
|
|
30
|
-
extra?: {
|
|
31
|
-
[x: string]: any;
|
|
32
|
-
} | undefined;
|
|
33
|
-
type: "min" | "max";
|
|
34
|
-
parameter?: any;
|
|
35
|
-
};
|
|
36
|
-
export type JzodAttributeDateWithValidations = {
|
|
37
|
-
optional?: boolean | undefined;
|
|
38
|
-
nullable?: boolean | undefined;
|
|
39
|
-
extra?: {
|
|
40
|
-
[x: string]: any;
|
|
41
|
-
} | undefined;
|
|
42
|
-
type: "simpleType";
|
|
43
|
-
definition: "date";
|
|
44
|
-
coerce?: boolean | undefined;
|
|
45
|
-
validations: JzodAttributeDateValidations[];
|
|
46
|
-
};
|
|
47
|
-
export type JzodAttributeNumberValidations = {
|
|
48
|
-
extra?: {
|
|
49
|
-
[x: string]: any;
|
|
50
|
-
} | undefined;
|
|
51
|
-
type: "gt" | "gte" | "lt" | "lte" | "int" | "positive" | "nonpositive" | "negative" | "nonnegative" | "multipleOf" | "finite" | "safe";
|
|
52
|
-
parameter?: any;
|
|
53
|
-
};
|
|
54
|
-
export type JzodAttributeNumberWithValidations = {
|
|
55
|
-
optional?: boolean | undefined;
|
|
56
|
-
nullable?: boolean | undefined;
|
|
57
|
-
extra?: {
|
|
58
|
-
[x: string]: any;
|
|
59
|
-
} | undefined;
|
|
60
|
-
type: "simpleType";
|
|
61
|
-
definition: "number";
|
|
62
|
-
coerce?: boolean | undefined;
|
|
63
|
-
validations: JzodAttributeNumberValidations[];
|
|
64
|
-
};
|
|
65
|
-
export type JzodAttributeStringValidations = {
|
|
66
|
-
extra?: {
|
|
67
|
-
[x: string]: any;
|
|
68
|
-
} | undefined;
|
|
69
|
-
type: "max" | "min" | "length" | "email" | "url" | "emoji" | "uuid" | "cuid" | "cuid2" | "ulid" | "regex" | "includes" | "startsWith" | "endsWith" | "datetime" | "ip";
|
|
70
|
-
parameter?: any;
|
|
71
|
-
};
|
|
72
|
-
export type JzodAttributeStringWithValidations = {
|
|
73
|
-
optional?: boolean | undefined;
|
|
74
|
-
nullable?: boolean | undefined;
|
|
75
|
-
extra?: {
|
|
76
|
-
[x: string]: any;
|
|
77
|
-
} | undefined;
|
|
78
|
-
type: "simpleType";
|
|
79
|
-
definition: "string";
|
|
80
|
-
coerce?: boolean | undefined;
|
|
81
|
-
validations: JzodAttributeStringValidations[];
|
|
82
|
-
};
|
|
83
|
-
export type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodObject | JzodPromise | JzodRecord | JzodReference | JzodSet | JzodTuple | JzodUnion;
|
|
84
|
-
export type JzodEnum = {
|
|
85
|
-
optional?: boolean | undefined;
|
|
86
|
-
nullable?: boolean | undefined;
|
|
87
|
-
extra?: {
|
|
88
|
-
[x: string]: any;
|
|
89
|
-
} | undefined;
|
|
90
|
-
type: "enum";
|
|
91
|
-
definition: string[];
|
|
92
|
-
};
|
|
93
|
-
export type JzodEnumAttributeTypes = "any" | "bigint" | "boolean" | "date" | "never" | "null" | "number" | "string" | "uuid" | "undefined" | "unknown" | "void";
|
|
94
|
-
export type JzodEnumElementTypes = "array" | "enum" | "function" | "lazy" | "literal" | "intersection" | "map" | "object" | "promise" | "record" | "schemaReference" | "set" | "simpleType" | "tuple" | "union";
|
|
95
|
-
export type JzodFunction = {
|
|
96
|
-
optional?: boolean | undefined;
|
|
97
|
-
nullable?: boolean | undefined;
|
|
98
|
-
extra?: {
|
|
99
|
-
[x: string]: any;
|
|
100
|
-
} | undefined;
|
|
101
|
-
type: "function";
|
|
102
|
-
definition: {
|
|
103
|
-
args: JzodElement[];
|
|
104
|
-
returns?: JzodElement | undefined;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
export type JzodLazy = {
|
|
108
|
-
optional?: boolean | undefined;
|
|
109
|
-
nullable?: boolean | undefined;
|
|
110
|
-
extra?: {
|
|
111
|
-
[x: string]: any;
|
|
112
|
-
} | undefined;
|
|
113
|
-
type: "lazy";
|
|
114
|
-
definition: JzodFunction;
|
|
115
|
-
};
|
|
116
|
-
export type JzodLiteral = {
|
|
117
|
-
optional?: boolean | undefined;
|
|
118
|
-
nullable?: boolean | undefined;
|
|
119
|
-
extra?: {
|
|
120
|
-
[x: string]: any;
|
|
121
|
-
} | undefined;
|
|
122
|
-
type: "literal";
|
|
123
|
-
definition: string | number | bigint | boolean;
|
|
124
|
-
};
|
|
125
|
-
export type JzodIntersection = {
|
|
126
|
-
optional?: boolean | undefined;
|
|
127
|
-
nullable?: boolean | undefined;
|
|
128
|
-
extra?: {
|
|
129
|
-
[x: string]: any;
|
|
130
|
-
} | undefined;
|
|
131
|
-
type: "intersection";
|
|
132
|
-
definition: {
|
|
133
|
-
left: JzodElement;
|
|
134
|
-
right: JzodElement;
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
export type JzodMap = {
|
|
138
|
-
optional?: boolean | undefined;
|
|
139
|
-
nullable?: boolean | undefined;
|
|
140
|
-
extra?: {
|
|
141
|
-
[x: string]: any;
|
|
142
|
-
} | undefined;
|
|
143
|
-
type: "map";
|
|
144
|
-
definition: [
|
|
145
|
-
JzodElement,
|
|
146
|
-
JzodElement
|
|
147
|
-
];
|
|
148
|
-
};
|
|
149
|
-
export type JzodObject = {
|
|
150
|
-
optional?: boolean | undefined;
|
|
151
|
-
nullable?: boolean | undefined;
|
|
152
|
-
extra?: {
|
|
153
|
-
[x: string]: any;
|
|
154
|
-
} | undefined;
|
|
155
|
-
extend?: (JzodReference | JzodObject) | undefined;
|
|
156
|
-
type: "object";
|
|
157
|
-
nonStrict?: boolean | undefined;
|
|
158
|
-
partial?: boolean | undefined;
|
|
159
|
-
definition: {
|
|
160
|
-
[x: string]: JzodElement;
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
export type JzodPromise = {
|
|
164
|
-
optional?: boolean | undefined;
|
|
165
|
-
nullable?: boolean | undefined;
|
|
166
|
-
extra?: {
|
|
167
|
-
[x: string]: any;
|
|
168
|
-
} | undefined;
|
|
169
|
-
type: "promise";
|
|
170
|
-
definition: JzodElement;
|
|
171
|
-
};
|
|
172
|
-
export type JzodRecord = {
|
|
173
|
-
optional?: boolean | undefined;
|
|
174
|
-
nullable?: boolean | undefined;
|
|
175
|
-
extra?: {
|
|
176
|
-
[x: string]: any;
|
|
177
|
-
} | undefined;
|
|
178
|
-
type: "record";
|
|
179
|
-
definition: JzodElement;
|
|
180
|
-
};
|
|
181
|
-
export type JzodReference = {
|
|
182
|
-
optional?: boolean | undefined;
|
|
183
|
-
nullable?: boolean | undefined;
|
|
184
|
-
extra?: {
|
|
185
|
-
[x: string]: any;
|
|
186
|
-
} | undefined;
|
|
187
|
-
type: "schemaReference";
|
|
188
|
-
context?: {
|
|
189
|
-
[x: string]: JzodElement;
|
|
190
|
-
} | undefined;
|
|
191
|
-
definition: {
|
|
192
|
-
eager?: boolean | undefined;
|
|
193
|
-
relativePath?: string | undefined;
|
|
194
|
-
absolutePath?: string | undefined;
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
export type JzodSet = {
|
|
198
|
-
optional?: boolean | undefined;
|
|
199
|
-
nullable?: boolean | undefined;
|
|
200
|
-
extra?: {
|
|
201
|
-
[x: string]: any;
|
|
202
|
-
} | undefined;
|
|
203
|
-
type: "set";
|
|
204
|
-
definition: JzodElement;
|
|
205
|
-
};
|
|
206
|
-
export type JzodTuple = {
|
|
207
|
-
optional?: boolean | undefined;
|
|
208
|
-
nullable?: boolean | undefined;
|
|
209
|
-
extra?: {
|
|
210
|
-
[x: string]: any;
|
|
211
|
-
} | undefined;
|
|
212
|
-
type: "tuple";
|
|
213
|
-
definition: JzodElement[];
|
|
214
|
-
};
|
|
215
|
-
export type JzodUnion = {
|
|
216
|
-
optional?: boolean | undefined;
|
|
217
|
-
nullable?: boolean | undefined;
|
|
218
|
-
extra?: {
|
|
219
|
-
[x: string]: any;
|
|
220
|
-
} | undefined;
|
|
221
|
-
type: "union";
|
|
222
|
-
discriminator?: string | undefined;
|
|
223
|
-
definition: JzodElement[];
|
|
224
|
-
};
|
|
225
|
-
export type JzodBootstrapElementSchema = JzodElement;
|
|
226
|
-
|
|
227
|
-
export const jzodBaseObject: z.ZodType<JzodBaseObject> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict();
|
|
228
|
-
export const jzodArray: z.ZodType<JzodArray> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("array"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
229
|
-
export const jzodAttribute: z.ZodType<JzodAttribute> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("simpleType"), coerce:z.boolean().optional(), definition:z.lazy(() =>jzodEnumAttributeTypes)}).strict();
|
|
230
|
-
export const jzodAttributeDateValidations: z.ZodType<JzodAttributeDateValidations> = z.object({extra:z.record(z.string(),z.any()).optional(), type:z.enum(["min","max"]), parameter:z.any()}).strict();
|
|
231
|
-
export const jzodAttributeDateWithValidations: z.ZodType<JzodAttributeDateWithValidations> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("simpleType"), definition:z.literal("date"), coerce:z.boolean().optional(), validations:z.array(z.lazy(() =>jzodAttributeDateValidations))}).strict();
|
|
232
|
-
export const jzodAttributeNumberValidations: z.ZodType<JzodAttributeNumberValidations> = z.object({extra:z.record(z.string(),z.any()).optional(), type:z.enum(["gt","gte","lt","lte","int","positive","nonpositive","negative","nonnegative","multipleOf","finite","safe"]), parameter:z.any()}).strict();
|
|
233
|
-
export const jzodAttributeNumberWithValidations: z.ZodType<JzodAttributeNumberWithValidations> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("simpleType"), definition:z.literal("number"), coerce:z.boolean().optional(), validations:z.array(z.lazy(() =>jzodAttributeNumberValidations))}).strict();
|
|
234
|
-
export const jzodAttributeStringValidations: z.ZodType<JzodAttributeStringValidations> = z.object({extra:z.record(z.string(),z.any()).optional(), type:z.enum(["max","min","length","email","url","emoji","uuid","cuid","cuid2","ulid","regex","includes","startsWith","endsWith","datetime","ip"]), parameter:z.any()}).strict();
|
|
235
|
-
export const jzodAttributeStringWithValidations: z.ZodType<JzodAttributeStringWithValidations> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("simpleType"), definition:z.literal("string"), coerce:z.boolean().optional(), validations:z.array(z.lazy(() =>jzodAttributeStringValidations))}).strict();
|
|
236
|
-
export const jzodElement: z.ZodType<JzodElement> = z.union([z.lazy(() =>jzodArray), z.lazy(() =>jzodAttribute), z.lazy(() =>jzodAttributeDateWithValidations), z.lazy(() =>jzodAttributeNumberWithValidations), z.lazy(() =>jzodAttributeStringWithValidations), z.lazy(() =>jzodEnum), z.lazy(() =>jzodFunction), z.lazy(() =>jzodLazy), z.lazy(() =>jzodLiteral), z.lazy(() =>jzodIntersection), z.lazy(() =>jzodMap), z.lazy(() =>jzodObject), z.lazy(() =>jzodPromise), z.lazy(() =>jzodRecord), z.lazy(() =>jzodReference), z.lazy(() =>jzodSet), z.lazy(() =>jzodTuple), z.lazy(() =>jzodUnion)]);
|
|
237
|
-
export const jzodEnum: z.ZodType<JzodEnum> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("enum"), definition:z.array(z.string())}).strict();
|
|
238
|
-
export const jzodEnumAttributeTypes: z.ZodType<JzodEnumAttributeTypes> = z.enum(["any","bigint","boolean","date","never","null","number","string","uuid","undefined","unknown","void"]);
|
|
239
|
-
export const jzodEnumElementTypes: z.ZodType<JzodEnumElementTypes> = z.enum(["array","enum","function","lazy","literal","intersection","map","object","promise","record","schemaReference","set","simpleType","tuple","union"]);
|
|
240
|
-
export const jzodFunction: z.ZodType<JzodFunction> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("function"), definition:z.object({args:z.array(z.lazy(() =>jzodElement)), returns:z.lazy(() =>jzodElement).optional()}).strict()}).strict();
|
|
241
|
-
export const jzodLazy: z.ZodType<JzodLazy> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("lazy"), definition:z.lazy(() =>jzodFunction)}).strict();
|
|
242
|
-
export const jzodLiteral: z.ZodType<JzodLiteral> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("literal"), definition:z.union([z.string(), z.number(), z.bigint(), z.boolean()])}).strict();
|
|
243
|
-
export const jzodIntersection: z.ZodType<JzodIntersection> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("intersection"), definition:z.object({left:z.lazy(() =>jzodElement), right:z.lazy(() =>jzodElement)}).strict()}).strict();
|
|
244
|
-
export const jzodMap: z.ZodType<JzodMap> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("map"), definition:z.tuple([z.lazy(() =>jzodElement), z.lazy(() =>jzodElement)])}).strict();
|
|
245
|
-
export const jzodObject: z.ZodType<JzodObject> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({extend:z.union([z.lazy(() =>jzodReference), z.lazy(() =>jzodObject)]).optional(), type:z.literal("object"), nonStrict:z.boolean().optional(), partial:z.boolean().optional(), definition:z.record(z.string(),z.lazy(() =>jzodElement))}).strict();
|
|
246
|
-
export const jzodPromise: z.ZodType<JzodPromise> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("promise"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
247
|
-
export const jzodRecord: z.ZodType<JzodRecord> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("record"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
248
|
-
export const jzodReference: z.ZodType<JzodReference> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("schemaReference"), context:z.record(z.string(),z.lazy(() =>jzodElement)).optional(), definition:z.object({eager:z.boolean().optional(), relativePath:z.string().optional(), absolutePath:z.string().optional()}).strict()}).strict();
|
|
249
|
-
export const jzodSet: z.ZodType<JzodSet> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("set"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
250
|
-
export const jzodTuple: z.ZodType<JzodTuple> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("tuple"), definition:z.array(z.lazy(() =>jzodElement))}).strict();
|
|
251
|
-
export const jzodUnion: z.ZodType<JzodUnion> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("union"), discriminator:z.string().optional(), definition:z.array(z.lazy(() =>jzodElement))}).strict();
|
|
252
|
-
export const jzodBootstrapElementSchema = z.lazy(() =>jzodElement);
|
|
253
|
-
|
package/src/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { jzodBootstrapElementSchema } from '@miroir-framework/jzod';
|
|
3
|
-
|
|
4
|
-
import { jzodToTsCode } from './JzodToTs.js';
|
|
5
|
-
|
|
6
|
-
export function generateZodSchemaFileFromJzodSchema(
|
|
7
|
-
jzodElement: any, //JzodElement,
|
|
8
|
-
targetFileName: string,
|
|
9
|
-
jzodSchemaVariableName:string,
|
|
10
|
-
) {
|
|
11
|
-
// console.log("generateZodSchemaFileFromJzodSchema called!");
|
|
12
|
-
|
|
13
|
-
const newFileContentsNotFormated = jzodToTsCode(jzodElement, true, jzodSchemaVariableName,Object.keys(jzodElement.context))
|
|
14
|
-
// const newFileContents = `import { JzodObject, jzodObject } from "@miroir-framework/jzod-ts";
|
|
15
|
-
const newFileContents = `${newFileContentsNotFormated}
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
if (targetFileName && existsSync(targetFileName)) {
|
|
19
|
-
const oldFileContents = readFileSync(targetFileName).toString()
|
|
20
|
-
if (newFileContents != oldFileContents) {
|
|
21
|
-
// console.log("generateZodSchemaFileFromJzodSchema newFileContents",newFileContents);
|
|
22
|
-
writeFileSync(targetFileName,newFileContents);
|
|
23
|
-
} else {
|
|
24
|
-
console.log("generateZodSchemaFileFromJzodSchema entityDefinitionReport old contents equal new contents, no file generation needed.");
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
writeFileSync(targetFileName,newFileContents);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ################################################################################################
|
|
32
|
-
const jzodSchemaConversion
|
|
33
|
-
: {
|
|
34
|
-
jzodElement: any,
|
|
35
|
-
targetFileName: string,
|
|
36
|
-
jzodSchemaVariableName:string,
|
|
37
|
-
}[]
|
|
38
|
-
= [
|
|
39
|
-
{
|
|
40
|
-
jzodElement: jzodBootstrapElementSchema,
|
|
41
|
-
targetFileName: "./src/generated_jzodBootstrapElementSchema.ts",
|
|
42
|
-
jzodSchemaVariableName: "jzodBootstrapElementSchema",
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
console.info("Prebuild!");
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
for (const schema of jzodSchemaConversion) {
|
|
50
|
-
generateZodSchemaFileFromJzodSchema(schema.jzodElement,schema.targetFileName,schema.jzodSchemaVariableName)
|
|
51
|
-
console.info("GENERATING",jzodBootstrapElementSchema);
|
|
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
|
-
|
|
59
|
-
console.info("Prebuild end!");
|
package/src/tools.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { printNode } from "zod-to-ts";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { TsTypeAliases } from "./JzodToTs";
|
|
5
|
-
|
|
6
|
-
// ################################################################################################
|
|
7
|
-
export function printTsTypeAlias(
|
|
8
|
-
typeAlias: ts.TypeAliasDeclaration,
|
|
9
|
-
exportPrefix: boolean = true,
|
|
10
|
-
): string {
|
|
11
|
-
return (exportPrefix?"export ":"")+printNode(typeAlias)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ################################################################################################
|
|
15
|
-
export function printTsTypeAliases(
|
|
16
|
-
typeAliases: TsTypeAliases,
|
|
17
|
-
exportPrefix: boolean = true,
|
|
18
|
-
): string {
|
|
19
|
-
const result = Object.entries(typeAliases).reduce((acc, curr) => {
|
|
20
|
-
// console.log("printTypeAliases ", JSON.stringify(curr));
|
|
21
|
-
return `${acc}
|
|
22
|
-
${printTsTypeAlias(curr[1],exportPrefix)}`;
|
|
23
|
-
}, "");
|
|
24
|
-
return result;
|
|
25
|
-
}
|