hekireki 0.0.5 → 0.0.7
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 +4 -4
- package/dist/common/format/index.js +1 -1
- package/dist/common/helper/get-variable-name-helper.d.ts +1 -1
- package/dist/common/helper/get-variable-name-helper.js +1 -3
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +1 -1
- package/dist/common/helper/get-variable-schema-name-helper.js +1 -1
- package/dist/common/helper/group-by-model-helper.d.ts +1 -1
- package/dist/common/type/index.d.ts +2 -2
- package/dist/common/validator/is-fields-validation.d.ts +1 -1
- package/dist/common/validator/is-fields-validation.js +1 -3
- package/dist/generator/mermaid/generator/generate-er-content.d.ts +3 -4
- package/dist/generator/mermaid/generator/generate-er-content.js +2 -3
- package/dist/generator/mermaid/generator/generate-model-fields.d.ts +3 -4
- package/dist/generator/mermaid/generator/generate-model-fields.js +9 -11
- package/dist/generator/mermaid/generator/generate-model-info.d.ts +1 -1
- package/dist/generator/mermaid/generator/generate-model-info.js +1 -5
- package/dist/generator/mermaid/generator/generate-relation-line.d.ts +3 -4
- package/dist/generator/mermaid/generator/generate-relation-line.js +4 -5
- package/dist/generator/mermaid/index.d.ts +1 -3
- package/dist/generator/mermaid/index.js +8 -43
- package/dist/generator/mermaid/output/index.d.ts +2 -2
- package/dist/generator/mermaid/output/index.js +3 -3
- package/dist/generator/mermaid/relationship/build-relation-line.d.ts +14 -0
- package/dist/generator/mermaid/relationship/build-relation-line.js +37 -0
- package/dist/generator/mermaid/relationship/index.d.ts +12 -0
- package/dist/generator/mermaid/relationship/index.js +30 -0
- package/dist/generator/mermaid/type/index.d.ts +2 -3
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +1 -1
- package/dist/generator/mermaid/validator/extract-relations.d.ts +3 -4
- package/dist/generator/mermaid/validator/extract-relations.js +4 -5
- package/dist/generator/mermaid/validator/is-relation.d.ts +7 -2
- package/dist/generator/mermaid/validator/is-relation.js +5 -0
- package/dist/generator/mermaid/validator/is-relationship.d.ts +7 -0
- package/dist/generator/mermaid/validator/is-relationship.js +11 -0
- package/dist/generator/mermaid/validator/parse-relation.d.ts +1 -1
- package/dist/generator/mermaid/validator/parse-relation.js +0 -4
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +2 -3
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +2 -3
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +1 -1
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +1 -1
- package/dist/generator/valibot/generator/generate-valibot-properties.js +4 -6
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +1 -1
- package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +1 -1
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +1 -1
- package/dist/generator/valibot/generator/generate-valibot.d.ts +2 -2
- package/dist/generator/valibot/generator/generate-valibot.js +5 -7
- package/dist/generator/valibot/index.d.ts +3 -3
- package/dist/generator/valibot/index.js +10 -10
- package/dist/generator/valibot/validator/is-valibot-documentation.js +2 -2
- package/dist/generator/zod/generator/generate-zod-infer.d.ts +1 -1
- package/dist/generator/zod/generator/generate-zod-properties.d.ts +1 -1
- package/dist/generator/zod/generator/generate-zod-properties.js +4 -6
- package/dist/generator/zod/generator/generate-zod-schema.d.ts +1 -1
- package/dist/generator/zod/generator/generate-zod-schemas.d.ts +1 -1
- package/dist/generator/zod/generator/generate-zod-schemas.js +1 -1
- package/dist/generator/zod/generator/generate-zod.d.ts +2 -2
- package/dist/generator/zod/generator/generate-zod.js +5 -7
- package/dist/generator/zod/index.d.ts +3 -3
- package/dist/generator/zod/index.js +10 -10
- package/dist/generator/zod/validator/is-zod-documentation.js +2 -2
- package/package.json +54 -54
package/README.md
CHANGED
|
@@ -129,7 +129,7 @@ model Like {
|
|
|
129
129
|
|
|
130
130
|
## Generate
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
## Zod
|
|
133
133
|
|
|
134
134
|
```ts
|
|
135
135
|
import { z } from 'zod'
|
|
@@ -294,9 +294,9 @@ export type Like = v.InferInput<typeof LikeSchema>
|
|
|
294
294
|
|
|
295
295
|
```mermaid
|
|
296
296
|
erDiagram
|
|
297
|
-
User
|
|
298
|
-
Post
|
|
299
|
-
User
|
|
297
|
+
User ||--|{ Post : "(id) - (userId)"
|
|
298
|
+
Post ||--|{ Like : "(id) - (postId)"
|
|
299
|
+
User ||--|{ Like : "(id) - (userId)"
|
|
300
300
|
User {
|
|
301
301
|
String id "Unique identifier for the user."
|
|
302
302
|
String username "Username of the user."
|
|
@@ -11,7 +11,5 @@ const decapitalize_1 = require("../text/decapitalize");
|
|
|
11
11
|
* @returns The variable name.
|
|
12
12
|
*/
|
|
13
13
|
function getVariableNameHelper(name, config) {
|
|
14
|
-
return config.typeName ===
|
|
15
|
-
? (0, decapitalize_1.decapitalize)(name)
|
|
16
|
-
: (0, capitalize_1.capitalize)(name);
|
|
14
|
+
return config.typeName === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
|
|
17
15
|
}
|
|
@@ -11,7 +11,7 @@ const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-n
|
|
|
11
11
|
* @returns The variable schema name.
|
|
12
12
|
*/
|
|
13
13
|
function getVariableSchemaNameHelper(name, config) {
|
|
14
|
-
return config.schemaName ===
|
|
14
|
+
return config.schemaName === 'camelCase'
|
|
15
15
|
? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaNameHelper)(name)
|
|
16
16
|
: (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaNameHelper)(name);
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DMMF } from
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
export type Field = {
|
|
3
3
|
documentation: string;
|
|
4
4
|
modelName: string;
|
|
@@ -12,5 +12,5 @@ export type Model = Readonly<DMMF.Model>;
|
|
|
12
12
|
export type ModelInfo = {
|
|
13
13
|
documentation: string;
|
|
14
14
|
name: string;
|
|
15
|
-
fields: Model[
|
|
15
|
+
fields: Model['fields'];
|
|
16
16
|
};
|
|
@@ -7,7 +7,5 @@ exports.isFieldsValidation = isFieldsValidation;
|
|
|
7
7
|
* @returns The fields validation
|
|
8
8
|
*/
|
|
9
9
|
function isFieldsValidation(modelFields) {
|
|
10
|
-
return modelFields
|
|
11
|
-
.flat()
|
|
12
|
-
.filter((field) => field.validation !== null);
|
|
10
|
+
return modelFields.flat().filter((field) => field.validation !== null);
|
|
13
11
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { ERContent, Model } from
|
|
1
|
+
import type { ERContent, Model } from '../type';
|
|
2
2
|
/**
|
|
3
3
|
* generate ER content
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @returns ER content
|
|
4
|
+
* @param { readonly Model[] } models - models
|
|
5
|
+
* @returns { ERContent } - ER content
|
|
7
6
|
*/
|
|
8
7
|
export declare function generateERContent(models: readonly Model[]): ERContent;
|
|
@@ -7,9 +7,8 @@ const generate_model_info_1 = require("../generator/generate-model-info");
|
|
|
7
7
|
const remove_duplicate_relations_1 = require("../validator/remove-duplicate-relations");
|
|
8
8
|
/**
|
|
9
9
|
* generate ER content
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @returns ER content
|
|
10
|
+
* @param { readonly Model[] } models - models
|
|
11
|
+
* @returns { ERContent } - ER content
|
|
13
12
|
*/
|
|
14
13
|
function generateERContent(models) {
|
|
15
14
|
// extract all relations
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { DMMF } from
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
/**
|
|
3
3
|
* generate model fields
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @returns
|
|
4
|
+
* @param { DMMF.Model } model
|
|
5
|
+
* @returns { string[] }
|
|
7
6
|
*/
|
|
8
7
|
export declare function generateModelFields(model: DMMF.Model): string[];
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateModelFields = generateModelFields;
|
|
4
|
-
const ZOD_ANNOTATION =
|
|
5
|
-
const VALIBOT_ANNOTATION =
|
|
4
|
+
const ZOD_ANNOTATION = '@z.';
|
|
5
|
+
const VALIBOT_ANNOTATION = '@v.';
|
|
6
6
|
/**
|
|
7
7
|
* generate model fields
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @returns
|
|
8
|
+
* @param { DMMF.Model } model
|
|
9
|
+
* @returns { string[] }
|
|
11
10
|
*/
|
|
12
11
|
function generateModelFields(model) {
|
|
13
12
|
return model.fields
|
|
@@ -17,13 +16,12 @@ function generateModelFields(model) {
|
|
|
17
16
|
}
|
|
18
17
|
const commentPart = field.documentation
|
|
19
18
|
? field.documentation
|
|
20
|
-
.split(
|
|
21
|
-
.filter((line) => !(line.includes(ZOD_ANNOTATION) ||
|
|
22
|
-
|
|
23
|
-
.join("\n")
|
|
19
|
+
.split('\n')
|
|
20
|
+
.filter((line) => !(line.includes(ZOD_ANNOTATION) || line.includes(VALIBOT_ANNOTATION)))
|
|
21
|
+
.join('\n')
|
|
24
22
|
.trim()
|
|
25
|
-
:
|
|
26
|
-
return ` ${field.type} ${field.name} ${commentPart ? `"${commentPart}"` :
|
|
23
|
+
: '';
|
|
24
|
+
return ` ${field.type} ${field.name} ${commentPart ? `"${commentPart}"` : ''}`;
|
|
27
25
|
})
|
|
28
26
|
.filter((field) => field !== null);
|
|
29
27
|
}
|
|
@@ -9,9 +9,5 @@ const generate_model_fields_1 = require("./generate-model-fields");
|
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
function generateModelInfo(model) {
|
|
12
|
-
return [
|
|
13
|
-
` ${model.name} {`,
|
|
14
|
-
...(0, generate_model_fields_1.generateModelFields)(model),
|
|
15
|
-
" }",
|
|
16
|
-
];
|
|
12
|
+
return [` ${model.name} {`, ...(0, generate_model_fields_1.generateModelFields)(model), ' }'];
|
|
17
13
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Relation } from
|
|
1
|
+
import type { Relation } from '../type';
|
|
2
2
|
/**
|
|
3
3
|
* generate relation line
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @returns string
|
|
4
|
+
* @param { Relation } relation
|
|
5
|
+
* @returns { string } relation line
|
|
7
6
|
*/
|
|
8
7
|
export declare function generateRelationLine(relation: Relation): string;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRelationLine = generateRelationLine;
|
|
4
|
-
const
|
|
4
|
+
const build_relation_line_1 = require("../relationship/build-relation-line");
|
|
5
5
|
/**
|
|
6
6
|
* generate relation line
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @returns string
|
|
7
|
+
* @param { Relation } relation
|
|
8
|
+
* @returns { string } relation line
|
|
10
9
|
*/
|
|
11
10
|
function generateRelationLine(relation) {
|
|
12
|
-
const cardinality =
|
|
11
|
+
const cardinality = (0, build_relation_line_1.buildRelationLine)(relation.type);
|
|
13
12
|
if (!cardinality) {
|
|
14
13
|
throw new Error(`Unknown relation type: ${relation.type}`);
|
|
15
14
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { GeneratorOptions } from
|
|
3
|
-
import type { RelationType } from "./type";
|
|
2
|
+
import type { GeneratorOptions } from '@prisma/generator-helper';
|
|
4
3
|
export type Config = {
|
|
5
4
|
output?: string;
|
|
6
5
|
file?: string | string[];
|
|
7
6
|
};
|
|
8
|
-
export declare const CARDINALITY_MAP: Record<RelationType, string>;
|
|
9
7
|
export declare const ER_HEADER: readonly ["```mermaid", "erDiagram"];
|
|
10
8
|
export declare const ER_FOOTER: readonly ["```"];
|
|
11
9
|
export declare function main(options: GeneratorOptions): Promise<void>;
|
|
@@ -1,54 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ER_FOOTER = exports.ER_HEADER =
|
|
4
|
+
exports.ER_FOOTER = exports.ER_HEADER = void 0;
|
|
5
5
|
exports.main = main;
|
|
6
6
|
const output_1 = require("./output");
|
|
7
7
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
8
8
|
const generate_er_content_1 = require("./generator/generate-er-content");
|
|
9
9
|
const DEFAULT_CONFIG = {
|
|
10
|
-
output:
|
|
11
|
-
file:
|
|
12
|
-
};
|
|
13
|
-
exports.CARDINALITY_MAP = {
|
|
14
|
-
// Required Relationships
|
|
15
|
-
// Both sides required (one-to-one)
|
|
16
|
-
"one-to-one": "||--||", // 1 --- 1
|
|
17
|
-
// One side singular, the other multiple
|
|
18
|
-
"one-to-many": "||--o{", // 1 --- * (also known as one-to-zero-many)
|
|
19
|
-
"many-to-one": "}o--||", // * --- 1
|
|
20
|
-
// Both sides multiple (many-to-many)
|
|
21
|
-
"many-to-many": "}o--o{", // * --- *
|
|
22
|
-
// One side required, one side optional (0..1)
|
|
23
|
-
"one-to-zero-one": "||--o|", // 1 --- 0..1
|
|
24
|
-
"zero-one-to-one": "o|--||", // 0..1 --- 1
|
|
25
|
-
// Both sides optional singular (0..1 on both sides)
|
|
26
|
-
"zero-to-one": "o|--o|", // 0..1 --- 0..1
|
|
27
|
-
"zero-to-zero-one": "o|--o|", // Alias for zero-to-one
|
|
28
|
-
// One side optional singular, the other multiple
|
|
29
|
-
"zero-to-many": "o|--o{", // 0 --- *
|
|
30
|
-
"zero-one-to-many": "o|--o{", // 0..1 --- *
|
|
31
|
-
"many-to-zero-one": "}o--o|", // * --- 0..1
|
|
32
|
-
// Optional Relationships (using dotted lines)
|
|
33
|
-
"one-to-one-optional": "||..||", // 1..1
|
|
34
|
-
"one-to-many-optional": "||..o{", // 1..*
|
|
35
|
-
"many-to-one-optional": "}o..||", // *..1
|
|
36
|
-
"many-to-many-optional": "}o..o{", // *..*
|
|
37
|
-
"one-to-zero-one-optional": "||..o|", // 1..0..1
|
|
38
|
-
"zero-one-to-one-optional": "o|..||", // 0..1..1
|
|
39
|
-
"zero-to-one-optional": "o|..o|", // 0..1 (both sides optional singular)
|
|
40
|
-
"zero-to-many-optional": "o|..o{", // 0..* (optional multiple)
|
|
41
|
-
"zero-one-to-many-optional": "o|..o{", // 0..1 --- * (optional)
|
|
42
|
-
"many-to-zero-one-optional": "}o..o|", // *..0..1
|
|
43
|
-
// Nuanced Patterns (Aliases)
|
|
44
|
-
"many-to-zero-many": "}o..o{", // * --- 0..* (equivalent to many-to-many-optional)
|
|
45
|
-
"zero-many-to-many": "o{..}o", // 0..* --- * (left side optional multiple, right side required multiple)
|
|
46
|
-
"zero-many-to-zero-many": "o{..o{", // both sides optional multiple
|
|
10
|
+
output: './mermaid-er',
|
|
11
|
+
file: 'ER.md',
|
|
47
12
|
};
|
|
48
13
|
// ER diagram header
|
|
49
|
-
exports.ER_HEADER = [
|
|
14
|
+
exports.ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
50
15
|
// ER diagram footer
|
|
51
|
-
exports.ER_FOOTER = [
|
|
16
|
+
exports.ER_FOOTER = ['```'];
|
|
52
17
|
// main function
|
|
53
18
|
async function main(options) {
|
|
54
19
|
const config = {
|
|
@@ -58,7 +23,7 @@ async function main(options) {
|
|
|
58
23
|
const models = options.dmmf.datamodel.models;
|
|
59
24
|
const content = (0, generate_er_content_1.generateERContent)(models);
|
|
60
25
|
if (!config.output) {
|
|
61
|
-
throw new Error(
|
|
26
|
+
throw new Error('output is required');
|
|
62
27
|
}
|
|
63
28
|
(0, output_1.OutputFile)(content, config);
|
|
64
29
|
}
|
|
@@ -66,8 +31,8 @@ async function main(options) {
|
|
|
66
31
|
(0, generator_helper_1.generatorHandler)({
|
|
67
32
|
onManifest() {
|
|
68
33
|
return {
|
|
69
|
-
defaultOutput:
|
|
70
|
-
prettyName:
|
|
34
|
+
defaultOutput: './mermaid-er',
|
|
35
|
+
prettyName: 'Hekireki-ER',
|
|
71
36
|
};
|
|
72
37
|
},
|
|
73
38
|
onGenerate: main,
|
|
@@ -13,12 +13,12 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
13
13
|
function OutputFile(content, config) {
|
|
14
14
|
const outputDir = config.output;
|
|
15
15
|
if (!outputDir) {
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error('output is required');
|
|
17
17
|
}
|
|
18
18
|
if (!node_fs_1.default.existsSync(outputDir)) {
|
|
19
19
|
node_fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
20
20
|
}
|
|
21
|
-
const file = config.file ??
|
|
21
|
+
const file = config.file ?? 'ER.md';
|
|
22
22
|
const filePath = `${outputDir}/${file}`;
|
|
23
|
-
node_fs_1.default.writeFileSync(filePath, content.join(
|
|
23
|
+
node_fs_1.default.writeFileSync(filePath, content.join('\n'), { encoding: 'utf-8' });
|
|
24
24
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const RELATIONSHIPS: {
|
|
2
|
+
readonly 'zero-one': "|o";
|
|
3
|
+
readonly one: "||";
|
|
4
|
+
readonly 'zero-many': "}o";
|
|
5
|
+
readonly many: "}|";
|
|
6
|
+
};
|
|
7
|
+
export type Relationship = keyof typeof RELATIONSHIPS;
|
|
8
|
+
/**
|
|
9
|
+
* Builds a relationship line for mermaid from a string.
|
|
10
|
+
* @param { string } input
|
|
11
|
+
* @returns { string }
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildRelationLine(input: string): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRelationLine = buildRelationLine;
|
|
4
|
+
const is_relationship_1 = require("../validator/is-relationship");
|
|
5
|
+
const RELATIONSHIPS = {
|
|
6
|
+
'zero-one': '|o',
|
|
7
|
+
one: '||',
|
|
8
|
+
'zero-many': '}o',
|
|
9
|
+
many: '}|',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Builds a relationship line for mermaid from a string.
|
|
13
|
+
* @param { string } input
|
|
14
|
+
* @returns { string }
|
|
15
|
+
*/
|
|
16
|
+
function buildRelationLine(input) {
|
|
17
|
+
const parts = input.split('-to-');
|
|
18
|
+
if (parts.length !== 2) {
|
|
19
|
+
throw new Error(`Invalid input format: ${input}`);
|
|
20
|
+
}
|
|
21
|
+
const [toRaw, optionalFlag] = parts[1].includes('-optional')
|
|
22
|
+
? [parts[1].replace('-optional', ''), 'optional']
|
|
23
|
+
: [parts[1], ''];
|
|
24
|
+
const from = parts[0];
|
|
25
|
+
const to = toRaw;
|
|
26
|
+
const isOptional = optionalFlag === 'optional';
|
|
27
|
+
if (!((0, is_relationship_1.isRelationship)(from) && (0, is_relationship_1.isRelationship)(to))) {
|
|
28
|
+
throw new Error(`Invalid relationship string: ${input}`);
|
|
29
|
+
}
|
|
30
|
+
const fromSymbol = RELATIONSHIPS[from];
|
|
31
|
+
const toSymbol = RELATIONSHIPS[to];
|
|
32
|
+
if (!(fromSymbol && toSymbol)) {
|
|
33
|
+
throw new Error(`Invalid relationship string: ${input}`);
|
|
34
|
+
}
|
|
35
|
+
const connector = isOptional ? '..' : '--';
|
|
36
|
+
return `${fromSymbol}${connector}${toSymbol}`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const RELATION_SHIPS: {
|
|
2
|
+
readonly 'zero-one': '|o'
|
|
3
|
+
readonly one: '||'
|
|
4
|
+
readonly 'zero-many': '|o{'
|
|
5
|
+
readonly many: '|{'
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Builds a relationship line for mermaid from a string.
|
|
9
|
+
* @param { string } input
|
|
10
|
+
* @returns { string }
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildRelationLine(input: string): string
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RELATION_SHIPS = void 0;
|
|
4
|
+
exports.buildRelationLine = buildRelationLine;
|
|
5
|
+
exports.RELATION_SHIPS = {
|
|
6
|
+
'zero-one': '|o',
|
|
7
|
+
one: '||',
|
|
8
|
+
'zero-many': '|o{',
|
|
9
|
+
many: '|{',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Builds a relationship line for mermaid from a string.
|
|
13
|
+
* @param { string } input
|
|
14
|
+
* @returns { string }
|
|
15
|
+
*/
|
|
16
|
+
function buildRelationLine(input) {
|
|
17
|
+
console.log(input);
|
|
18
|
+
const parts = input.split('-to-');
|
|
19
|
+
const toParts = parts[1].split('-');
|
|
20
|
+
const from = parts[0];
|
|
21
|
+
const to = toParts[0];
|
|
22
|
+
const isOptional = toParts.includes('optional');
|
|
23
|
+
const fromSymbol = exports.RELATION_SHIPS[from];
|
|
24
|
+
const toSymbol = exports.RELATION_SHIPS[to];
|
|
25
|
+
if (!(fromSymbol || !toSymbol)) {
|
|
26
|
+
throw new Error(`Invalid relationship string: ${input}`);
|
|
27
|
+
}
|
|
28
|
+
const connector = isOptional ? '..' : '--';
|
|
29
|
+
return `${fromSymbol}${connector}${toSymbol}`;
|
|
30
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { DMMF } from
|
|
2
|
-
export type RelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many" | "one-to-zero-one" | "zero-one-to-one" | "zero-to-one" | "zero-to-zero-one" | "zero-to-many" | "zero-one-to-many" | "many-to-zero-one" | "one-to-one-optional" | "one-to-many-optional" | "many-to-one-optional" | "many-to-many-optional" | "one-to-zero-one-optional" | "zero-one-to-one-optional" | "zero-to-one-optional" | "zero-to-many-optional" | "zero-one-to-many-optional" | "many-to-zero-one-optional" | "many-to-zero-many" | "zero-many-to-many" | "zero-many-to-zero-many";
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
3
2
|
export type Relation = {
|
|
4
3
|
fromModel: string;
|
|
5
4
|
toModel: string;
|
|
6
5
|
fromField: string;
|
|
7
6
|
toField: string;
|
|
8
|
-
type:
|
|
7
|
+
type: string;
|
|
9
8
|
};
|
|
10
9
|
export type Model = Readonly<DMMF.Model>;
|
|
11
10
|
export type ERContent = readonly string[];
|
|
@@ -8,5 +8,5 @@ exports.excludeManyToOneRelations = excludeManyToOneRelations;
|
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
10
|
function excludeManyToOneRelations(relations) {
|
|
11
|
-
return [...new Set(relations)].filter((r) => !r.includes(
|
|
11
|
+
return [...new Set(relations)].filter((r) => !r.includes('many-to-one'));
|
|
12
12
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Model } from
|
|
1
|
+
import type { Model } from '../type';
|
|
2
2
|
/**
|
|
3
3
|
* extract relations from model
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @returns
|
|
4
|
+
* @param { Model } model
|
|
5
|
+
* @returns { readonly string[] }
|
|
7
6
|
*/
|
|
8
7
|
export declare function extractRelations(model: Model): readonly string[];
|
|
@@ -5,16 +5,15 @@ const generate_relation_line_1 = require("../generator/generate-relation-line");
|
|
|
5
5
|
const parse_relation_1 = require("./parse-relation");
|
|
6
6
|
/**
|
|
7
7
|
* extract relations from model
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @returns
|
|
8
|
+
* @param { Model } model
|
|
9
|
+
* @returns { readonly string[] }
|
|
11
10
|
*/
|
|
12
11
|
function extractRelations(model) {
|
|
13
12
|
const relations = [];
|
|
14
|
-
// @
|
|
13
|
+
// @relation annotation
|
|
15
14
|
if (model.documentation) {
|
|
16
15
|
const annotationRelations = model.documentation
|
|
17
|
-
.split(
|
|
16
|
+
.split('\n')
|
|
18
17
|
.map((line) => {
|
|
19
18
|
const relation = (0, parse_relation_1.parseRelation)(line);
|
|
20
19
|
return relation ? (0, generate_relation_line_1.generateRelationLine)(relation) : null;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import type { RelationType } from
|
|
2
|
-
|
|
1
|
+
import type { RelationType } from '../type'
|
|
2
|
+
/**
|
|
3
|
+
* check if the value is a valid relation
|
|
4
|
+
* @param { unknown } value
|
|
5
|
+
* @returns { boolean }
|
|
6
|
+
*/
|
|
7
|
+
export declare function isRelation(value: unknown): value is RelationType
|
|
@@ -27,6 +27,11 @@ const VALID_RELATIONS = new Set([
|
|
|
27
27
|
"zero-many-to-many",
|
|
28
28
|
"zero-many-to-zero-many",
|
|
29
29
|
]);
|
|
30
|
+
/**
|
|
31
|
+
* check if the value is a valid relation
|
|
32
|
+
* @param { unknown } value
|
|
33
|
+
* @returns { boolean }
|
|
34
|
+
*/
|
|
30
35
|
function isRelation(value) {
|
|
31
36
|
return typeof value === "string" && VALID_RELATIONS.has(value);
|
|
32
37
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRelationship = isRelationship;
|
|
4
|
+
/**
|
|
5
|
+
* isRelationship
|
|
6
|
+
* @param { string } key
|
|
7
|
+
* @returns { key is Relationship }
|
|
8
|
+
*/
|
|
9
|
+
function isRelationship(key) {
|
|
10
|
+
return ['zero-one', 'one', 'zero-many', 'many'].includes(key);
|
|
11
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRelation = parseRelation;
|
|
4
|
-
const is_relation_1 = require("./is-relation");
|
|
5
4
|
/**
|
|
6
5
|
* parse relation
|
|
7
6
|
* @function parseRelation
|
|
@@ -15,9 +14,6 @@ function parseRelation(line) {
|
|
|
15
14
|
return null;
|
|
16
15
|
}
|
|
17
16
|
const [, fromModel, fromField, toModel, toField, relationType] = match;
|
|
18
|
-
if (!(0, is_relation_1.isRelation)(relationType)) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
17
|
return {
|
|
22
18
|
fromModel,
|
|
23
19
|
fromField,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* remove duplicate relations
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
-
* @returns
|
|
3
|
+
* @param { readonly string[] } relations
|
|
4
|
+
* @returns { readonly string[] }
|
|
6
5
|
*/
|
|
7
6
|
export declare function removeDuplicateRelations(relations: readonly string[]): readonly string[];
|
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.removeDuplicateRelations = removeDuplicateRelations;
|
|
4
4
|
/**
|
|
5
5
|
* remove duplicate relations
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @returns
|
|
6
|
+
* @param { readonly string[] } relations
|
|
7
|
+
* @returns { readonly string[] }
|
|
9
8
|
*/
|
|
10
9
|
function removeDuplicateRelations(relations) {
|
|
11
10
|
return [...new Set(relations)];
|
|
@@ -7,14 +7,12 @@ function generateValibotProperties(modelFields, config) {
|
|
|
7
7
|
.map((field) => {
|
|
8
8
|
// @relation, @v, @z exclude
|
|
9
9
|
const cleanDoc = field.comment
|
|
10
|
-
.filter((line) => !(line.includes(
|
|
11
|
-
|
|
12
|
-
line.includes("@z")))
|
|
13
|
-
.join("\n")
|
|
10
|
+
.filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
|
|
11
|
+
.join('\n')
|
|
14
12
|
.trim();
|
|
15
|
-
const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` :
|
|
13
|
+
const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
|
|
16
14
|
return `${docComment} ${field.fieldName}: v.${field.validation}`;
|
|
17
15
|
})
|
|
18
|
-
.join(
|
|
16
|
+
.join(',\n');
|
|
19
17
|
return fields;
|
|
20
18
|
}
|
|
@@ -12,7 +12,7 @@ const generate_valibot_schema_1 = require("./generate-valibot-schema");
|
|
|
12
12
|
*/
|
|
13
13
|
function generateValibotSchemas(modelFields, config) {
|
|
14
14
|
const modelName = modelFields[0].modelName;
|
|
15
|
-
const modelDoc = modelFields[0].documentation ||
|
|
15
|
+
const modelDoc = modelFields[0].documentation || '';
|
|
16
16
|
const fields = (0, generate_valibot_properties_1.generateValibotProperties)(modelFields, config);
|
|
17
17
|
if (!(modelDoc || !config?.comment)) {
|
|
18
18
|
return (0, generate_valibot_schema_1.generateValibotSchema)(modelName, fields, config);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Config } from
|
|
2
|
-
import type { Model } from
|
|
1
|
+
import type { Config } from '..';
|
|
2
|
+
import type { Model } from '../../../common/type';
|
|
3
3
|
/**
|
|
4
4
|
* Generate Valibot schemas and types
|
|
5
5
|
* @param models - The models to generate the Valibot schemas and types for
|
|
@@ -17,7 +17,7 @@ const VALIBOT_IMPORT = `import * as v from 'valibot'\n`;
|
|
|
17
17
|
function generateValibot(models, config) {
|
|
18
18
|
const modelInfos = models.map((model) => {
|
|
19
19
|
return {
|
|
20
|
-
documentation: model.documentation ??
|
|
20
|
+
documentation: model.documentation ?? '',
|
|
21
21
|
name: model.name,
|
|
22
22
|
fields: model.fields,
|
|
23
23
|
};
|
|
@@ -39,16 +39,14 @@ function generateValibot(models, config) {
|
|
|
39
39
|
const valibots = Object.values(groupedByModel).map((fields) => {
|
|
40
40
|
return {
|
|
41
41
|
generateValibotSchema: (0, generate_valibot_schemas_1.generateValibotSchemas)(fields, config),
|
|
42
|
-
generateValibotInfer: config.type ===
|
|
43
|
-
? (0, generate_valibot_infer_input_1.generateValibotInferInput)(fields[0].modelName, config)
|
|
44
|
-
: "",
|
|
42
|
+
generateValibotInfer: config.type === 'true' ? (0, generate_valibot_infer_input_1.generateValibotInferInput)(fields[0].modelName, config) : '',
|
|
45
43
|
};
|
|
46
44
|
});
|
|
47
45
|
return [
|
|
48
46
|
VALIBOT_IMPORT,
|
|
49
|
-
|
|
47
|
+
'',
|
|
50
48
|
valibots
|
|
51
49
|
.flatMap(({ generateValibotSchema, generateValibotInfer }) => [generateValibotSchema, generateValibotInfer].filter(Boolean))
|
|
52
|
-
.join(
|
|
53
|
-
].join(
|
|
50
|
+
.join('\n\n'),
|
|
51
|
+
].join('\n');
|
|
54
52
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { GeneratorOptions } from
|
|
2
|
+
import type { GeneratorOptions } from '@prisma/generator-helper';
|
|
3
3
|
export type Config = {
|
|
4
4
|
output?: string;
|
|
5
5
|
file?: string | string[];
|
|
6
|
-
schemaName?:
|
|
7
|
-
typeName?:
|
|
6
|
+
schemaName?: 'PascalCase' | 'camelCase' | string | string[];
|
|
7
|
+
typeName?: 'PascalCase' | 'camelCase' | string | string[];
|
|
8
8
|
type?: boolean | string | string[];
|
|
9
9
|
comment?: boolean | string | string[];
|
|
10
10
|
};
|
|
@@ -10,10 +10,10 @@ const generate_valibot_1 = require("./generator/generate-valibot");
|
|
|
10
10
|
const prettier_1 = require("prettier");
|
|
11
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
12
|
const DEFAULT_CONFIG = {
|
|
13
|
-
output:
|
|
14
|
-
file:
|
|
15
|
-
schemaName:
|
|
16
|
-
typeName:
|
|
13
|
+
output: './valibot',
|
|
14
|
+
file: 'index.ts',
|
|
15
|
+
schemaName: 'PascalCase',
|
|
16
|
+
typeName: 'PascalCase',
|
|
17
17
|
type: false,
|
|
18
18
|
comment: false,
|
|
19
19
|
};
|
|
@@ -24,30 +24,30 @@ async function main(options) {
|
|
|
24
24
|
schemaName: options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
|
|
25
25
|
typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
|
|
26
26
|
type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
|
|
27
|
-
comment: options.generator.config?.comment ===
|
|
27
|
+
comment: options.generator.config?.comment === 'true',
|
|
28
28
|
};
|
|
29
29
|
const content = (0, generate_valibot_1.generateValibot)(options.dmmf.datamodel.models, config);
|
|
30
30
|
const code = await (0, prettier_1.format)(content, {
|
|
31
|
-
parser:
|
|
31
|
+
parser: 'typescript',
|
|
32
32
|
printWidth: 100,
|
|
33
33
|
singleQuote: true,
|
|
34
34
|
semi: false,
|
|
35
35
|
});
|
|
36
36
|
if (!config.output) {
|
|
37
|
-
throw new Error(
|
|
37
|
+
throw new Error('output is required');
|
|
38
38
|
}
|
|
39
39
|
if (!node_fs_1.default.existsSync(config.output)) {
|
|
40
40
|
node_fs_1.default.mkdirSync(config.output, { recursive: true });
|
|
41
41
|
}
|
|
42
|
-
const file = config.file ??
|
|
42
|
+
const file = config.file ?? 'index.ts';
|
|
43
43
|
const filePath = `${config.output}/${file}`;
|
|
44
44
|
node_fs_1.default.writeFileSync(filePath, code);
|
|
45
45
|
}
|
|
46
46
|
(0, generator_helper_1.generatorHandler)({
|
|
47
47
|
onManifest() {
|
|
48
48
|
return {
|
|
49
|
-
defaultOutput:
|
|
50
|
-
prettyName:
|
|
49
|
+
defaultOutput: './valibot/',
|
|
50
|
+
prettyName: 'Hekireki-Valibot',
|
|
51
51
|
};
|
|
52
52
|
},
|
|
53
53
|
onGenerate: main,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isValibotDocumentValidation = isValibotDocumentValidation;
|
|
4
|
-
const VALIDATION_PATTERNS = [
|
|
4
|
+
const VALIDATION_PATTERNS = ['@v.'];
|
|
5
5
|
function isValibotDocumentValidation(documentation) {
|
|
6
6
|
if (!documentation)
|
|
7
7
|
return [];
|
|
8
8
|
return documentation
|
|
9
|
-
.split(
|
|
9
|
+
.split('\n')
|
|
10
10
|
.filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
|
|
11
11
|
.map((line) => line.trim())
|
|
12
12
|
.filter(Boolean);
|
|
@@ -13,14 +13,12 @@ function generateZodProperties(modelFields, config) {
|
|
|
13
13
|
.map((field) => {
|
|
14
14
|
// @relation, @v, @z exclude
|
|
15
15
|
const cleanDoc = field.comment
|
|
16
|
-
.filter((line) => !(line.includes(
|
|
17
|
-
|
|
18
|
-
line.includes("@z")))
|
|
19
|
-
.join("\n")
|
|
16
|
+
.filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
|
|
17
|
+
.join('\n')
|
|
20
18
|
.trim();
|
|
21
|
-
const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` :
|
|
19
|
+
const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
|
|
22
20
|
return `${docComment} ${field.fieldName}: z.${field.validation}`;
|
|
23
21
|
})
|
|
24
|
-
.join(
|
|
22
|
+
.join(',\n');
|
|
25
23
|
return fields;
|
|
26
24
|
}
|
|
@@ -11,7 +11,7 @@ const generate_zod_schema_1 = require("./generate-zod-schema");
|
|
|
11
11
|
*/
|
|
12
12
|
function generateZodSchemas(modelFields, config) {
|
|
13
13
|
const modelName = modelFields[0].modelName;
|
|
14
|
-
const modelDoc = modelFields[0].documentation ||
|
|
14
|
+
const modelDoc = modelFields[0].documentation || '';
|
|
15
15
|
const fields = (0, generate_zod_properties_1.generateZodProperties)(modelFields, config);
|
|
16
16
|
if (!(modelDoc || !config?.comment)) {
|
|
17
17
|
return (0, generate_zod_schema_1.generateZodSchema)(modelName, fields, config);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Config } from
|
|
2
|
-
import type { Model } from
|
|
1
|
+
import type { Config } from '..';
|
|
2
|
+
import type { Model } from '../../../common/type';
|
|
3
3
|
/**
|
|
4
4
|
* Generate Zod schemas and types
|
|
5
5
|
* @param models - The models to generate the Zod schemas and types for
|
|
@@ -17,7 +17,7 @@ const ZOD_IMPORT = `import { z } from 'zod'\n`;
|
|
|
17
17
|
function generateZod(models, config) {
|
|
18
18
|
const modelInfos = models.map((model) => {
|
|
19
19
|
return {
|
|
20
|
-
documentation: model.documentation ??
|
|
20
|
+
documentation: model.documentation ?? '',
|
|
21
21
|
name: model.name,
|
|
22
22
|
fields: model.fields,
|
|
23
23
|
};
|
|
@@ -39,16 +39,14 @@ function generateZod(models, config) {
|
|
|
39
39
|
const zods = Object.values(groupedByModel).map((fields) => {
|
|
40
40
|
return {
|
|
41
41
|
generateZodSchema: (0, generate_zod_schemas_1.generateZodSchemas)(fields, config),
|
|
42
|
-
generateZodInfer: config.type ===
|
|
43
|
-
? (0, generate_zod_infer_1.generateZodInfer)(fields[0].modelName, config)
|
|
44
|
-
: "",
|
|
42
|
+
generateZodInfer: config.type === 'true' ? (0, generate_zod_infer_1.generateZodInfer)(fields[0].modelName, config) : '',
|
|
45
43
|
};
|
|
46
44
|
});
|
|
47
45
|
return [
|
|
48
46
|
ZOD_IMPORT,
|
|
49
|
-
|
|
47
|
+
'',
|
|
50
48
|
zods
|
|
51
49
|
.flatMap(({ generateZodSchema, generateZodInfer }) => [generateZodSchema, generateZodInfer].filter(Boolean))
|
|
52
|
-
.join(
|
|
53
|
-
].join(
|
|
50
|
+
.join('\n\n'),
|
|
51
|
+
].join('\n');
|
|
54
52
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { GeneratorOptions } from
|
|
2
|
+
import type { GeneratorOptions } from '@prisma/generator-helper';
|
|
3
3
|
export type Config = {
|
|
4
4
|
output?: string;
|
|
5
5
|
file?: string | string[];
|
|
6
|
-
schemaName?:
|
|
7
|
-
typeName?:
|
|
6
|
+
schemaName?: 'PascalCase' | 'camelCase' | string | string[];
|
|
7
|
+
typeName?: 'PascalCase' | 'camelCase' | string | string[];
|
|
8
8
|
type?: boolean | string | string[];
|
|
9
9
|
comment?: boolean | string | string[];
|
|
10
10
|
};
|
|
@@ -10,10 +10,10 @@ const generate_zod_1 = require("./generator/generate-zod");
|
|
|
10
10
|
const prettier_1 = require("prettier");
|
|
11
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
12
|
const DEFAULT_CONFIG = {
|
|
13
|
-
output:
|
|
14
|
-
file:
|
|
15
|
-
schemaName:
|
|
16
|
-
typeName:
|
|
13
|
+
output: './zod',
|
|
14
|
+
file: 'index.ts',
|
|
15
|
+
schemaName: 'PascalCase',
|
|
16
|
+
typeName: 'PascalCase',
|
|
17
17
|
type: false,
|
|
18
18
|
comment: false,
|
|
19
19
|
};
|
|
@@ -24,30 +24,30 @@ async function main(options) {
|
|
|
24
24
|
schemaName: options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
|
|
25
25
|
typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
|
|
26
26
|
type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
|
|
27
|
-
comment: options.generator.config?.comment ===
|
|
27
|
+
comment: options.generator.config?.comment === 'true',
|
|
28
28
|
};
|
|
29
29
|
const content = (0, generate_zod_1.generateZod)(options.dmmf.datamodel.models, config);
|
|
30
30
|
const code = await (0, prettier_1.format)(content, {
|
|
31
|
-
parser:
|
|
31
|
+
parser: 'typescript',
|
|
32
32
|
printWidth: 100,
|
|
33
33
|
singleQuote: true,
|
|
34
34
|
semi: false,
|
|
35
35
|
});
|
|
36
36
|
if (!config.output) {
|
|
37
|
-
throw new Error(
|
|
37
|
+
throw new Error('output is required');
|
|
38
38
|
}
|
|
39
39
|
if (!node_fs_1.default.existsSync(config.output)) {
|
|
40
40
|
node_fs_1.default.mkdirSync(config.output, { recursive: true });
|
|
41
41
|
}
|
|
42
|
-
const file = config.file ??
|
|
42
|
+
const file = config.file ?? 'index.ts';
|
|
43
43
|
const filePath = `${config.output}/${file}`;
|
|
44
44
|
node_fs_1.default.writeFileSync(filePath, code);
|
|
45
45
|
}
|
|
46
46
|
(0, generator_helper_1.generatorHandler)({
|
|
47
47
|
onManifest() {
|
|
48
48
|
return {
|
|
49
|
-
defaultOutput:
|
|
50
|
-
prettyName:
|
|
49
|
+
defaultOutput: './zod/',
|
|
50
|
+
prettyName: 'Hekireki-Zod',
|
|
51
51
|
};
|
|
52
52
|
},
|
|
53
53
|
onGenerate: main,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isZodDocumentValidation = isZodDocumentValidation;
|
|
4
|
-
const VALIDATION_PATTERNS = [
|
|
4
|
+
const VALIDATION_PATTERNS = ['@z.'];
|
|
5
5
|
/**
|
|
6
6
|
* Is Zod documentation
|
|
7
7
|
* @param documentation - The documentation of the field
|
|
@@ -11,7 +11,7 @@ function isZodDocumentValidation(documentation) {
|
|
|
11
11
|
if (!documentation)
|
|
12
12
|
return [];
|
|
13
13
|
return documentation
|
|
14
|
-
.split(
|
|
14
|
+
.split('\n')
|
|
15
15
|
.filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
|
|
16
16
|
.map((line) => line.trim())
|
|
17
17
|
.filter(Boolean);
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
2
|
+
"name": "hekireki",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Hekireki is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Prisma schemas annotated with comments.",
|
|
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 && pnpm build && 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
56
|
}
|