hekireki 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +361 -0
- package/dist/common/format/index.d.ts +1 -0
- package/dist/common/format/index.js +12 -0
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +7 -0
- package/dist/common/helper/get-camel-case-schema-name-helper.js +14 -0
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +8 -0
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +15 -0
- package/dist/common/helper/get-variable-name-helper.d.ts +9 -0
- package/dist/common/helper/get-variable-name-helper.js +17 -0
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +9 -0
- package/dist/common/helper/get-variable-schema-name-helper.js +17 -0
- package/dist/common/helper/group-by-model-helper.d.ts +8 -0
- package/dist/common/helper/group-by-model-helper.js +18 -0
- package/dist/common/text/capitalize.d.ts +18 -0
- package/dist/common/text/capitalize.js +23 -0
- package/dist/common/text/decapitalize.d.ts +17 -0
- package/dist/common/text/decapitalize.js +22 -0
- package/dist/common/type/index.d.ts +16 -0
- package/dist/common/type/index.js +2 -0
- package/dist/common/validator/is-fields-validation.d.ts +13 -0
- package/dist/common/validator/is-fields-validation.js +13 -0
- package/dist/generator/mermaid/generator/generate-er-content.d.ts +8 -0
- package/dist/generator/mermaid/generator/generate-er-content.js +23 -0
- package/dist/generator/mermaid/generator/generate-model-fields.d.ts +8 -0
- package/dist/generator/mermaid/generator/generate-model-fields.js +29 -0
- package/dist/generator/mermaid/generator/generate-model-info.d.ts +8 -0
- package/dist/generator/mermaid/generator/generate-model-info.js +17 -0
- package/dist/generator/mermaid/generator/generate-relation-line.d.ts +8 -0
- package/dist/generator/mermaid/generator/generate-relation-line.js +17 -0
- package/dist/generator/mermaid/index.d.ts +10 -0
- package/dist/generator/mermaid/index.js +73 -0
- package/dist/generator/mermaid/output/index.d.ts +8 -0
- package/dist/generator/mermaid/output/index.js +24 -0
- package/dist/generator/mermaid/type/index.d.ts +11 -0
- package/dist/generator/mermaid/type/index.js +2 -0
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +7 -0
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +12 -0
- package/dist/generator/mermaid/validator/extract-relations.d.ts +8 -0
- package/dist/generator/mermaid/validator/extract-relations.js +26 -0
- package/dist/generator/mermaid/validator/is-relation.d.ts +2 -0
- package/dist/generator/mermaid/validator/is-relation.js +32 -0
- package/dist/generator/mermaid/validator/parse-relation.d.ts +8 -0
- package/dist/generator/mermaid/validator/parse-relation.js +28 -0
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +7 -0
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +12 -0
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +8 -0
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +16 -0
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +8 -0
- package/dist/generator/valibot/generator/generate-valibot-properties.js +20 -0
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +9 -0
- package/dist/generator/valibot/generator/generate-valibot-schema.js +15 -0
- package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +15 -0
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +21 -0
- package/dist/generator/valibot/generator/generate-valibot.d.ts +9 -0
- package/dist/generator/valibot/generator/generate-valibot.js +54 -0
- package/dist/generator/valibot/index.d.ts +10 -0
- package/dist/generator/valibot/index.js +53 -0
- package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +1 -0
- package/dist/generator/valibot/validator/is-valibot-documentation.js +13 -0
- package/dist/generator/valibot/validator/is-valibot-validation.d.ts +7 -0
- package/dist/generator/valibot/validator/is-valibot-validation.js +15 -0
- package/dist/generator/zod/generator/generate-zod-infer.d.ts +8 -0
- package/dist/generator/zod/generator/generate-zod-infer.js +16 -0
- package/dist/generator/zod/generator/generate-zod-properties.d.ts +14 -0
- package/dist/generator/zod/generator/generate-zod-properties.js +26 -0
- package/dist/generator/zod/generator/generate-zod-schema.d.ts +9 -0
- package/dist/generator/zod/generator/generate-zod-schema.js +15 -0
- package/dist/generator/zod/generator/generate-zod-schemas.d.ts +14 -0
- package/dist/generator/zod/generator/generate-zod-schemas.js +20 -0
- package/dist/generator/zod/generator/generate-zod.d.ts +9 -0
- package/dist/generator/zod/generator/generate-zod.js +54 -0
- package/dist/generator/zod/index.d.ts +10 -0
- package/dist/generator/zod/index.js +53 -0
- package/dist/generator/zod/validator/is-zod-documentation.d.ts +6 -0
- package/dist/generator/zod/validator/is-zod-documentation.js +18 -0
- package/dist/generator/zod/validator/is-zod-validation.d.ts +6 -0
- package/dist/generator/zod/validator/is-zod-validation.js +14 -0
- package/package.json +56 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.main = main;
|
|
7
|
+
const generator_helper_1 = require("@prisma/generator-helper");
|
|
8
|
+
const generate_valibot_1 = require("./generator/generate-valibot");
|
|
9
|
+
const prettier_1 = require("prettier");
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
output: "./valibot",
|
|
13
|
+
file: "index.ts",
|
|
14
|
+
schemaName: "PascalCase",
|
|
15
|
+
typeName: "PascalCase",
|
|
16
|
+
type: false,
|
|
17
|
+
comment: false,
|
|
18
|
+
};
|
|
19
|
+
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);
|
|
44
|
+
}
|
|
45
|
+
(0, generator_helper_1.generatorHandler)({
|
|
46
|
+
onManifest() {
|
|
47
|
+
return {
|
|
48
|
+
defaultOutput: "./valibot/",
|
|
49
|
+
prettyName: "Hekireki-Valibot",
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
onGenerate: main,
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValibotDocumentValidation(documentation?: string): string[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValibotDocumentValidation = isValibotDocumentValidation;
|
|
4
|
+
const VALIDATION_PATTERNS = ["@v."];
|
|
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);
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValibotValidation = isValibotValidation;
|
|
4
|
+
/**
|
|
5
|
+
* Check if the documentation is a Valibot validation
|
|
6
|
+
* @function isValibotValidation
|
|
7
|
+
* @param documentation
|
|
8
|
+
* @returns string | null
|
|
9
|
+
*/
|
|
10
|
+
function isValibotValidation(documentation) {
|
|
11
|
+
if (!documentation)
|
|
12
|
+
return null;
|
|
13
|
+
const match = documentation.match(/@v\.(.+?)(?:\n|$)/);
|
|
14
|
+
return match ? match[1].trim() : null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Config } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Generate Zod infer
|
|
4
|
+
* @param modelName - The name of the model
|
|
5
|
+
* @param config - The configuration for the generator
|
|
6
|
+
* @returns The generated Zod infer
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateZodInfer(modelName: string, config: Config): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodInfer = generateZodInfer;
|
|
4
|
+
const get_variable_name_helper_1 = require("../../../common/helper/get-variable-name-helper");
|
|
5
|
+
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
6
|
+
/**
|
|
7
|
+
* Generate Zod infer
|
|
8
|
+
* @param modelName - The name of the model
|
|
9
|
+
* @param config - The configuration for the generator
|
|
10
|
+
* @returns The generated Zod infer
|
|
11
|
+
*/
|
|
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}>`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Generate Zod properties
|
|
4
|
+
* @param modelFields - The fields of the model
|
|
5
|
+
* @param config - The configuration for the generator
|
|
6
|
+
* @returns The generated Zod properties
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodProperties = generateZodProperties;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod properties
|
|
6
|
+
* @param modelFields - The fields of the model
|
|
7
|
+
* @param config - The configuration for the generator
|
|
8
|
+
* @returns The generated Zod properties
|
|
9
|
+
*/
|
|
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;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Generate Zod schema
|
|
4
|
+
* @param modelName - The name of the model
|
|
5
|
+
* @param fields - The fields of the model
|
|
6
|
+
* @param config - The configuration for the generator
|
|
7
|
+
* @returns The generated Zod schema
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateZodSchema(modelName: string, fields: string, config: Config): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodSchema = generateZodSchema;
|
|
4
|
+
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
5
|
+
/**
|
|
6
|
+
* Generate Zod schema
|
|
7
|
+
* @param modelName - The name of the model
|
|
8
|
+
* @param fields - The fields of the model
|
|
9
|
+
* @param config - The configuration for the generator
|
|
10
|
+
* @returns The generated Zod schema
|
|
11
|
+
*/
|
|
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})`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Generate Zod schemas
|
|
4
|
+
* @param modelFields - The fields of the model
|
|
5
|
+
* @param config - The configuration for the generator
|
|
6
|
+
* @returns The generated Zod schemas
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodSchemas = generateZodSchemas;
|
|
4
|
+
const generate_zod_properties_1 = require("./generate-zod-properties");
|
|
5
|
+
const generate_zod_schema_1 = require("./generate-zod-schema");
|
|
6
|
+
/**
|
|
7
|
+
* Generate Zod schemas
|
|
8
|
+
* @param modelFields - The fields of the model
|
|
9
|
+
* @param config - The configuration for the generator
|
|
10
|
+
* @returns The generated Zod schemas
|
|
11
|
+
*/
|
|
12
|
+
function generateZodSchemas(modelFields, config) {
|
|
13
|
+
const modelName = modelFields[0].modelName;
|
|
14
|
+
const modelDoc = modelFields[0].documentation || "";
|
|
15
|
+
const fields = (0, generate_zod_properties_1.generateZodProperties)(modelFields, config);
|
|
16
|
+
if (!(modelDoc || !config?.comment)) {
|
|
17
|
+
return (0, generate_zod_schema_1.generateZodSchema)(modelName, fields, config);
|
|
18
|
+
}
|
|
19
|
+
return `${(0, generate_zod_schema_1.generateZodSchema)(modelName, fields, config)}`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from "..";
|
|
2
|
+
import type { Model } from "../../../common/type";
|
|
3
|
+
/**
|
|
4
|
+
* Generate Zod schemas and types
|
|
5
|
+
* @param models - The models to generate the Zod schemas and types for
|
|
6
|
+
* @param config - The configuration for the generator
|
|
7
|
+
* @returns The generated Zod schemas and types
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateZod(models: readonly Model[], config: Config): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZod = generateZod;
|
|
4
|
+
const is_zod_documentation_1 = require("../validator/is-zod-documentation");
|
|
5
|
+
const is_zod_validation_1 = require("../validator/is-zod-validation");
|
|
6
|
+
const is_fields_validation_1 = require("../../../common/validator/is-fields-validation");
|
|
7
|
+
const group_by_model_helper_1 = require("../../../common/helper/group-by-model-helper");
|
|
8
|
+
const generate_zod_schemas_1 = require("./generate-zod-schemas");
|
|
9
|
+
const generate_zod_infer_1 = require("./generate-zod-infer");
|
|
10
|
+
const ZOD_IMPORT = `import { z } from 'zod'\n`;
|
|
11
|
+
/**
|
|
12
|
+
* Generate Zod schemas and types
|
|
13
|
+
* @param models - The models to generate the Zod schemas and types for
|
|
14
|
+
* @param config - The configuration for the generator
|
|
15
|
+
* @returns The generated Zod schemas and types
|
|
16
|
+
*/
|
|
17
|
+
function generateZod(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_zod_documentation_1.isZodDocumentValidation)(field.documentation),
|
|
31
|
+
validation: (0, is_zod_validation_1.isZodValidation)(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 zods = Object.values(groupedByModel).map((fields) => {
|
|
40
|
+
return {
|
|
41
|
+
generateZodSchema: (0, generate_zod_schemas_1.generateZodSchemas)(fields, config),
|
|
42
|
+
generateZodInfer: config.type === "true"
|
|
43
|
+
? (0, generate_zod_infer_1.generateZodInfer)(fields[0].modelName, config)
|
|
44
|
+
: "",
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
return [
|
|
48
|
+
ZOD_IMPORT,
|
|
49
|
+
"",
|
|
50
|
+
zods
|
|
51
|
+
.flatMap(({ generateZodSchema, generateZodInfer }) => [generateZodSchema, generateZodInfer].filter(Boolean))
|
|
52
|
+
.join("\n\n"),
|
|
53
|
+
].join("\n");
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GeneratorOptions } from "@prisma/generator-helper";
|
|
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[];
|
|
9
|
+
};
|
|
10
|
+
export declare function main(options: GeneratorOptions): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.main = main;
|
|
7
|
+
const generator_helper_1 = require("@prisma/generator-helper");
|
|
8
|
+
const generate_zod_1 = require("./generator/generate-zod");
|
|
9
|
+
const prettier_1 = require("prettier");
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
output: "./zod",
|
|
13
|
+
file: "index.ts",
|
|
14
|
+
schemaName: "PascalCase",
|
|
15
|
+
typeName: "PascalCase",
|
|
16
|
+
type: false,
|
|
17
|
+
comment: false,
|
|
18
|
+
};
|
|
19
|
+
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_zod_1.generateZod)(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);
|
|
44
|
+
}
|
|
45
|
+
(0, generator_helper_1.generatorHandler)({
|
|
46
|
+
onManifest() {
|
|
47
|
+
return {
|
|
48
|
+
defaultOutput: "./zod/",
|
|
49
|
+
prettyName: "Hekireki-Zod",
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
onGenerate: main,
|
|
53
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isZodDocumentValidation = isZodDocumentValidation;
|
|
4
|
+
const VALIDATION_PATTERNS = ["@z."];
|
|
5
|
+
/**
|
|
6
|
+
* Is Zod documentation
|
|
7
|
+
* @param documentation - The documentation of the field
|
|
8
|
+
* @returns The Zod documentation
|
|
9
|
+
*/
|
|
10
|
+
function isZodDocumentValidation(documentation) {
|
|
11
|
+
if (!documentation)
|
|
12
|
+
return [];
|
|
13
|
+
return documentation
|
|
14
|
+
.split("\n")
|
|
15
|
+
.filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
|
|
16
|
+
.map((line) => line.trim())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isZodValidation = isZodValidation;
|
|
4
|
+
/**
|
|
5
|
+
* Is Zod validation
|
|
6
|
+
* @param documentation - The documentation of the field
|
|
7
|
+
* @returns The Zod validation
|
|
8
|
+
*/
|
|
9
|
+
function isZodValidation(documentation) {
|
|
10
|
+
if (!documentation)
|
|
11
|
+
return null;
|
|
12
|
+
const match = documentation.match(/@z\.(.+?)(?:\n|$)/);
|
|
13
|
+
return match ? match[1].trim() : null;
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hekireki",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Prisma generator that creates Zod and Valibot schemas with Mermaid ER diagrams from your Prisma schema.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"prisma",
|
|
8
|
+
"zod",
|
|
9
|
+
"valibot",
|
|
10
|
+
"mermaid"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/nakita628/hekireki",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/nakita628/hekireki.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/nakita628/hekireki/issues"
|
|
22
|
+
},
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"bin": {
|
|
29
|
+
"hekireki-zod": "dist/generator/zod/index.js",
|
|
30
|
+
"hekireki-valibot": "dist/generator/valibot/index.js",
|
|
31
|
+
"hekireki-mermaid-er": "dist/generator/mermaid/index.js"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"generate": "prisma generate",
|
|
35
|
+
"deps": "rm -rf node_modules && pnpm install",
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"coverage": "vitest run --coverage",
|
|
40
|
+
"release": "npm pkg fix && npm publish"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.13.10",
|
|
44
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
45
|
+
"prisma": "^6.5.0",
|
|
46
|
+
"@prisma/client": "6.5.0",
|
|
47
|
+
"tsx": "^4.19.3",
|
|
48
|
+
"valibot": "1.0.0-rc.3",
|
|
49
|
+
"vitest": "^3.0.8",
|
|
50
|
+
"zod": "^3.24.2"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@prisma/generator-helper": "^6.5.0",
|
|
54
|
+
"prettier": "^3.5.3"
|
|
55
|
+
}
|
|
56
|
+
}
|