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