hekireki 0.0.2 → 0.0.4
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/common/format/index.js +6 -6
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +3 -1
- package/dist/common/helper/get-camel-case-schema-name-helper.js +2 -2
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +3 -1
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +2 -2
- package/dist/common/helper/get-variable-name-helper.d.ts +4 -1
- package/dist/common/helper/get-variable-name-helper.js +3 -3
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +4 -1
- package/dist/common/helper/get-variable-schema-name-helper.js +7 -3
- package/dist/common/helper/group-by-model-helper.d.ts +3 -1
- package/dist/common/helper/group-by-model-helper.js +7 -7
- package/dist/common/text/capitalize.js +1 -1
- package/dist/common/text/decapitalize.js +1 -1
- package/dist/common/type/index.d.ts +8 -8
- package/dist/common/validator/is-fields-validation.d.ts +9 -7
- package/dist/common/validator/is-fields-validation.js +1 -3
- package/dist/generator/mermaid/generator/generate-er-content.js +14 -8
- package/dist/generator/mermaid/generator/generate-model-fields.js +21 -16
- package/dist/generator/mermaid/generator/generate-model-info.js +5 -5
- package/dist/generator/mermaid/generator/generate-relation-line.js +5 -5
- package/dist/generator/mermaid/index.d.ts +2 -2
- package/dist/generator/mermaid/index.js +52 -52
- package/dist/generator/mermaid/output/index.js +17 -13
- package/dist/generator/mermaid/type/index.d.ts +30 -6
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +3 -1
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +1 -1
- package/dist/generator/mermaid/validator/extract-relations.js +15 -13
- package/dist/generator/mermaid/validator/is-relation.js +25 -25
- package/dist/generator/mermaid/validator/parse-relation.js +17 -16
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +3 -1
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +1 -1
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +4 -1
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +10 -3
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +10 -7
- package/dist/generator/valibot/generator/generate-valibot-properties.js +21 -15
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +5 -1
- package/dist/generator/valibot/generator/generate-valibot-schema.js +6 -2
- package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +10 -7
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +14 -7
- package/dist/generator/valibot/generator/generate-valibot.d.ts +4 -1
- package/dist/generator/valibot/generator/generate-valibot.js +51 -36
- package/dist/generator/valibot/index.d.ts +6 -6
- package/dist/generator/valibot/index.js +46 -40
- package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +3 -1
- package/dist/generator/valibot/validator/is-valibot-documentation.js +8 -7
- package/dist/generator/valibot/validator/is-valibot-validation.d.ts +3 -1
- package/dist/generator/valibot/validator/is-valibot-validation.js +3 -4
- package/dist/generator/zod/generator/generate-zod-infer.d.ts +4 -1
- package/dist/generator/zod/generator/generate-zod-infer.js +10 -3
- package/dist/generator/zod/generator/generate-zod-properties.d.ts +10 -7
- package/dist/generator/zod/generator/generate-zod-properties.js +21 -15
- package/dist/generator/zod/generator/generate-zod-schema.d.ts +5 -1
- package/dist/generator/zod/generator/generate-zod-schema.js +6 -2
- package/dist/generator/zod/generator/generate-zod-schemas.d.ts +10 -7
- package/dist/generator/zod/generator/generate-zod-schemas.js +14 -7
- package/dist/generator/zod/generator/generate-zod.d.ts +4 -1
- package/dist/generator/zod/generator/generate-zod.js +51 -36
- package/dist/generator/zod/index.d.ts +6 -6
- package/dist/generator/zod/index.js +46 -40
- package/dist/generator/zod/validator/is-zod-documentation.d.ts +3 -1
- package/dist/generator/zod/validator/is-zod-documentation.js +8 -7
- package/dist/generator/zod/validator/is-zod-validation.js +3 -4
- package/package.json +1 -1
|
@@ -9,20 +9,21 @@ const is_relation_1 = require("./is-relation");
|
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
function parseRelation(line) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
const relationRegex =
|
|
13
|
+
/^@relation\s+(\w+)\.(\w+)\s+(\w+)\.(\w+)\s+(\w+-to-\w+)$/;
|
|
14
|
+
const match = line.trim().match(relationRegex);
|
|
15
|
+
if (!match) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const [, fromModel, fromField, toModel, toField, relationType] = match;
|
|
19
|
+
if (!(0, is_relation_1.isRelation)(relationType)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
fromModel,
|
|
24
|
+
fromField,
|
|
25
|
+
toModel,
|
|
26
|
+
toField,
|
|
27
|
+
type: relationType,
|
|
28
|
+
};
|
|
28
29
|
}
|
|
@@ -5,4 +5,7 @@ import type { Config } from "..";
|
|
|
5
5
|
* @param config - The configuration for the generator
|
|
6
6
|
* @returns The generated infer input type
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateValibotInferInput(
|
|
8
|
+
export declare function generateValibotInferInput(
|
|
9
|
+
modelName: string,
|
|
10
|
+
config: Config,
|
|
11
|
+
): string;
|
|
@@ -10,7 +10,14 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated infer input type
|
|
11
11
|
*/
|
|
12
12
|
function generateValibotInferInput(modelName, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const typeName = (0, get_variable_name_helper_1.getVariableNameHelper)(
|
|
14
|
+
modelName,
|
|
15
|
+
config,
|
|
16
|
+
);
|
|
17
|
+
const schemaName = (0,
|
|
18
|
+
get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(
|
|
19
|
+
modelName,
|
|
20
|
+
config,
|
|
21
|
+
);
|
|
22
|
+
return `export type ${typeName} = v.InferInput<typeof ${schemaName}>`;
|
|
16
23
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Config } from "..";
|
|
2
|
-
export declare function generateValibotProperties(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export declare function generateValibotProperties(
|
|
3
|
+
modelFields: {
|
|
4
|
+
documentation: string;
|
|
5
|
+
modelName: string;
|
|
6
|
+
fieldName: string;
|
|
7
|
+
validation: string | null;
|
|
8
|
+
comment: string[];
|
|
9
|
+
}[],
|
|
10
|
+
config?: Config,
|
|
11
|
+
): string;
|
|
@@ -2,19 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateValibotProperties = generateValibotProperties;
|
|
4
4
|
function generateValibotProperties(modelFields, config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
const fields = modelFields
|
|
6
|
+
.filter((field) => field.validation)
|
|
7
|
+
.map((field) => {
|
|
8
|
+
// @relation, @v, @z exclude
|
|
9
|
+
const cleanDoc = field.comment
|
|
10
|
+
.filter(
|
|
11
|
+
(line) =>
|
|
12
|
+
!(
|
|
13
|
+
line.includes("@relation") ||
|
|
14
|
+
line.includes("@v") ||
|
|
15
|
+
line.includes("@z")
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
.join("\n")
|
|
19
|
+
.trim();
|
|
20
|
+
const docComment =
|
|
21
|
+
config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : "";
|
|
22
|
+
return `${docComment} ${field.fieldName}: v.${field.validation}`;
|
|
23
|
+
})
|
|
24
|
+
.join(",\n");
|
|
25
|
+
return fields;
|
|
20
26
|
}
|
|
@@ -6,4 +6,8 @@ import type { Config } from "..";
|
|
|
6
6
|
* @param config - The configuration for the generator
|
|
7
7
|
* @returns The generated Valibot schema
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateValibotSchema(
|
|
9
|
+
export declare function generateValibotSchema(
|
|
10
|
+
modelName: string,
|
|
11
|
+
fields: string,
|
|
12
|
+
config: Config,
|
|
13
|
+
): string;
|
|
@@ -10,6 +10,10 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated Valibot schema
|
|
11
11
|
*/
|
|
12
12
|
function generateValibotSchema(modelName, fields, config) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const schemaName = (0,
|
|
14
|
+
get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(
|
|
15
|
+
modelName,
|
|
16
|
+
config,
|
|
17
|
+
);
|
|
18
|
+
return `export const ${schemaName} = v.object({\n${fields}\n})`;
|
|
15
19
|
}
|
|
@@ -6,10 +6,13 @@ import type { Config } from "..";
|
|
|
6
6
|
* @param config
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateValibotSchemas(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export declare function generateValibotSchemas(
|
|
10
|
+
modelFields: {
|
|
11
|
+
documentation: string;
|
|
12
|
+
modelName: string;
|
|
13
|
+
fieldName: string;
|
|
14
|
+
validation: string | null;
|
|
15
|
+
comment: string[];
|
|
16
|
+
}[],
|
|
17
|
+
config: Config,
|
|
18
|
+
): string;
|
|
@@ -11,11 +11,18 @@ const generate_valibot_schema_1 = require("./generate-valibot-schema");
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
function generateValibotSchemas(modelFields, config) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const modelName = modelFields[0].modelName;
|
|
15
|
+
const modelDoc = modelFields[0].documentation || "";
|
|
16
|
+
const fields = (0, generate_valibot_properties_1.generateValibotProperties)(
|
|
17
|
+
modelFields,
|
|
18
|
+
config,
|
|
19
|
+
);
|
|
20
|
+
if (!(modelDoc || !config?.comment)) {
|
|
21
|
+
return (0, generate_valibot_schema_1.generateValibotSchema)(
|
|
22
|
+
modelName,
|
|
23
|
+
fields,
|
|
24
|
+
config,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return `${(0, generate_valibot_schema_1.generateValibotSchema)(modelName, fields, config)}`;
|
|
21
28
|
}
|
|
@@ -6,4 +6,7 @@ import type { Model } from "../../../common/type";
|
|
|
6
6
|
* @param config - The configuration for the generator
|
|
7
7
|
* @returns The generated Valibot schemas and types
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateValibot(
|
|
9
|
+
export declare function generateValibot(
|
|
10
|
+
models: readonly Model[],
|
|
11
|
+
config: Config,
|
|
12
|
+
): string;
|
|
@@ -15,40 +15,55 @@ const VALIBOT_IMPORT = `import * as v from 'valibot'\n`;
|
|
|
15
15
|
* @returns The generated Valibot schemas and types
|
|
16
16
|
*/
|
|
17
17
|
function generateValibot(models, config) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
18
|
+
const modelInfos = models.map((model) => {
|
|
19
|
+
return {
|
|
20
|
+
documentation: model.documentation ?? "",
|
|
21
|
+
name: model.name,
|
|
22
|
+
fields: model.fields,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const modelFields = modelInfos.map((model) => {
|
|
26
|
+
const fields = model.fields.map((field) => ({
|
|
27
|
+
documentation: model.documentation,
|
|
28
|
+
modelName: model.name,
|
|
29
|
+
fieldName: field.name,
|
|
30
|
+
comment: (0, is_valibot_documentation_1.isValibotDocumentValidation)(
|
|
31
|
+
field.documentation,
|
|
32
|
+
),
|
|
33
|
+
validation: (0, is_valibot_validation_1.isValibotValidation)(
|
|
34
|
+
field.documentation,
|
|
35
|
+
),
|
|
36
|
+
}));
|
|
37
|
+
return fields;
|
|
38
|
+
});
|
|
39
|
+
// null exclude
|
|
40
|
+
const validFields = (0, is_fields_validation_1.isFieldsValidation)(
|
|
41
|
+
modelFields,
|
|
42
|
+
);
|
|
43
|
+
// group by model
|
|
44
|
+
const groupedByModel = (0, group_by_model_helper_1.groupByModelHelper)(
|
|
45
|
+
validFields,
|
|
46
|
+
);
|
|
47
|
+
const valibots = Object.values(groupedByModel).map((fields) => {
|
|
48
|
+
return {
|
|
49
|
+
generateValibotSchema: (0,
|
|
50
|
+
generate_valibot_schemas_1.generateValibotSchemas)(fields, config),
|
|
51
|
+
generateValibotInfer:
|
|
52
|
+
config.type === "true"
|
|
53
|
+
? (0, generate_valibot_infer_input_1.generateValibotInferInput)(
|
|
54
|
+
fields[0].modelName,
|
|
55
|
+
config,
|
|
56
|
+
)
|
|
57
|
+
: "",
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return [
|
|
61
|
+
VALIBOT_IMPORT,
|
|
62
|
+
"",
|
|
63
|
+
valibots
|
|
64
|
+
.flatMap(({ generateValibotSchema, generateValibotInfer }) =>
|
|
65
|
+
[generateValibotSchema, generateValibotInfer].filter(Boolean),
|
|
66
|
+
)
|
|
67
|
+
.join("\n\n"),
|
|
68
|
+
].join("\n");
|
|
54
69
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { GeneratorOptions } from "@prisma/generator-helper";
|
|
2
2
|
export type Config = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
output?: string;
|
|
4
|
+
file?: string | string[];
|
|
5
|
+
schemaName?: "PascalCase" | "camelCase" | string | string[];
|
|
6
|
+
typeName?: "PascalCase" | "camelCase" | string | string[];
|
|
7
|
+
type?: boolean | string | string[];
|
|
8
|
+
comment?: boolean | string | string[];
|
|
9
9
|
};
|
|
10
10
|
export declare function main(options: GeneratorOptions): Promise<void>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.main = main;
|
|
7
9
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
@@ -9,45 +11,49 @@ const generate_valibot_1 = require("./generator/generate-valibot");
|
|
|
9
11
|
const prettier_1 = require("prettier");
|
|
10
12
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
13
|
const DEFAULT_CONFIG = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
output: "./valibot",
|
|
15
|
+
file: "index.ts",
|
|
16
|
+
schemaName: "PascalCase",
|
|
17
|
+
typeName: "PascalCase",
|
|
18
|
+
type: false,
|
|
19
|
+
comment: false,
|
|
18
20
|
};
|
|
19
21
|
async function main(options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
22
|
+
const config = {
|
|
23
|
+
output: options.generator.output?.value ?? DEFAULT_CONFIG.output,
|
|
24
|
+
file: options.generator.config?.file ?? DEFAULT_CONFIG.file,
|
|
25
|
+
schemaName:
|
|
26
|
+
options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
|
|
27
|
+
typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
|
|
28
|
+
type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
|
|
29
|
+
comment: options.generator.config?.comment === "true",
|
|
30
|
+
};
|
|
31
|
+
const content = (0, generate_valibot_1.generateValibot)(
|
|
32
|
+
options.dmmf.datamodel.models,
|
|
33
|
+
config,
|
|
34
|
+
);
|
|
35
|
+
const code = await (0, prettier_1.format)(content, {
|
|
36
|
+
parser: "typescript",
|
|
37
|
+
printWidth: 100,
|
|
38
|
+
singleQuote: true,
|
|
39
|
+
semi: false,
|
|
40
|
+
});
|
|
41
|
+
if (!config.output) {
|
|
42
|
+
throw new Error("output is required");
|
|
43
|
+
}
|
|
44
|
+
if (!node_fs_1.default.existsSync(config.output)) {
|
|
45
|
+
node_fs_1.default.mkdirSync(config.output, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
const file = config.file ?? "index.ts";
|
|
48
|
+
const filePath = `${config.output}/${file}`;
|
|
49
|
+
node_fs_1.default.writeFileSync(filePath, code);
|
|
44
50
|
}
|
|
45
51
|
(0, generator_helper_1.generatorHandler)({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
onManifest() {
|
|
53
|
+
return {
|
|
54
|
+
defaultOutput: "./valibot/",
|
|
55
|
+
prettyName: "Hekireki-Valibot",
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
onGenerate: main,
|
|
53
59
|
});
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isValibotDocumentValidation = isValibotDocumentValidation;
|
|
4
4
|
const VALIDATION_PATTERNS = ["@v."];
|
|
5
5
|
function isValibotDocumentValidation(documentation) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
if (!documentation) return [];
|
|
7
|
+
return documentation
|
|
8
|
+
.split("\n")
|
|
9
|
+
.filter(
|
|
10
|
+
(line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)),
|
|
11
|
+
)
|
|
12
|
+
.map((line) => line.trim())
|
|
13
|
+
.filter(Boolean);
|
|
13
14
|
}
|
|
@@ -8,8 +8,7 @@ exports.isValibotValidation = isValibotValidation;
|
|
|
8
8
|
* @returns string | null
|
|
9
9
|
*/
|
|
10
10
|
function isValibotValidation(documentation) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return match ? match[1].trim() : null;
|
|
11
|
+
if (!documentation) return null;
|
|
12
|
+
const match = documentation.match(/@v\.(.+?)(?:\n|$)/);
|
|
13
|
+
return match ? match[1].trim() : null;
|
|
15
14
|
}
|
|
@@ -5,4 +5,7 @@ import type { Config } from "..";
|
|
|
5
5
|
* @param config - The configuration for the generator
|
|
6
6
|
* @returns The generated Zod infer
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateZodInfer(
|
|
8
|
+
export declare function generateZodInfer(
|
|
9
|
+
modelName: string,
|
|
10
|
+
config: Config,
|
|
11
|
+
): string;
|
|
@@ -10,7 +10,14 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated Zod infer
|
|
11
11
|
*/
|
|
12
12
|
function generateZodInfer(modelName, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const typeName = (0, get_variable_name_helper_1.getVariableNameHelper)(
|
|
14
|
+
modelName,
|
|
15
|
+
config,
|
|
16
|
+
);
|
|
17
|
+
const schemaName = (0,
|
|
18
|
+
get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(
|
|
19
|
+
modelName,
|
|
20
|
+
config,
|
|
21
|
+
);
|
|
22
|
+
return `export type ${typeName} = z.infer<typeof ${schemaName}>`;
|
|
16
23
|
}
|
|
@@ -5,10 +5,13 @@ import type { Config } from "..";
|
|
|
5
5
|
* @param config - The configuration for the generator
|
|
6
6
|
* @returns The generated Zod properties
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateZodProperties(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export declare function generateZodProperties(
|
|
9
|
+
modelFields: {
|
|
10
|
+
documentation: string;
|
|
11
|
+
modelName: string;
|
|
12
|
+
fieldName: string;
|
|
13
|
+
validation: string | null;
|
|
14
|
+
comment: string[];
|
|
15
|
+
}[],
|
|
16
|
+
config?: Config,
|
|
17
|
+
): string;
|
|
@@ -8,19 +8,25 @@ exports.generateZodProperties = generateZodProperties;
|
|
|
8
8
|
* @returns The generated Zod properties
|
|
9
9
|
*/
|
|
10
10
|
function generateZodProperties(modelFields, config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
const fields = modelFields
|
|
12
|
+
.filter((field) => field.validation)
|
|
13
|
+
.map((field) => {
|
|
14
|
+
// @relation, @v, @z exclude
|
|
15
|
+
const cleanDoc = field.comment
|
|
16
|
+
.filter(
|
|
17
|
+
(line) =>
|
|
18
|
+
!(
|
|
19
|
+
line.includes("@relation") ||
|
|
20
|
+
line.includes("@v") ||
|
|
21
|
+
line.includes("@z")
|
|
22
|
+
),
|
|
23
|
+
)
|
|
24
|
+
.join("\n")
|
|
25
|
+
.trim();
|
|
26
|
+
const docComment =
|
|
27
|
+
config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : "";
|
|
28
|
+
return `${docComment} ${field.fieldName}: z.${field.validation}`;
|
|
29
|
+
})
|
|
30
|
+
.join(",\n");
|
|
31
|
+
return fields;
|
|
26
32
|
}
|
|
@@ -6,4 +6,8 @@ import type { Config } from "..";
|
|
|
6
6
|
* @param config - The configuration for the generator
|
|
7
7
|
* @returns The generated Zod schema
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateZodSchema(
|
|
9
|
+
export declare function generateZodSchema(
|
|
10
|
+
modelName: string,
|
|
11
|
+
fields: string,
|
|
12
|
+
config: Config,
|
|
13
|
+
): string;
|
|
@@ -10,6 +10,10 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated Zod schema
|
|
11
11
|
*/
|
|
12
12
|
function generateZodSchema(modelName, fields, config) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const schemaName = (0,
|
|
14
|
+
get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(
|
|
15
|
+
modelName,
|
|
16
|
+
config,
|
|
17
|
+
);
|
|
18
|
+
return `export const ${schemaName} = z.object({\n${fields}\n})`;
|
|
15
19
|
}
|
|
@@ -5,10 +5,13 @@ import type { Config } from "..";
|
|
|
5
5
|
* @param config - The configuration for the generator
|
|
6
6
|
* @returns The generated Zod schemas
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateZodSchemas(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export declare function generateZodSchemas(
|
|
9
|
+
modelFields: {
|
|
10
|
+
documentation: string;
|
|
11
|
+
modelName: string;
|
|
12
|
+
fieldName: string;
|
|
13
|
+
validation: string | null;
|
|
14
|
+
comment: string[];
|
|
15
|
+
}[],
|
|
16
|
+
config: Config,
|
|
17
|
+
): string;
|