hekireki 0.2.7 → 0.2.8
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 +2 -2
- package/dist/generator/ecto/generator/ecto.js +17 -11
- package/dist/generator/mermaid-er/generator/er-content.d.ts +8 -2
- package/dist/generator/mermaid-er/generator/er-content.js +8 -6
- package/dist/generator/mermaid-er/generator/index.d.ts +1 -1
- package/dist/generator/mermaid-er/generator/index.js +1 -1
- package/dist/generator/mermaid-er/generator/model-fields.d.ts +4 -3
- package/dist/generator/mermaid-er/generator/model-fields.js +4 -3
- package/dist/generator/mermaid-er/generator/model-info.d.ts +6 -5
- package/dist/generator/mermaid-er/generator/model-info.js +4 -3
- package/dist/generator/mermaid-er/generator/relation-line.d.ts +11 -5
- package/dist/generator/mermaid-er/generator/relation-line.js +5 -4
- package/dist/generator/mermaid-er/helper/build-relation-line.d.ts +9 -0
- package/dist/generator/mermaid-er/{relationship → helper}/build-relation-line.js +9 -1
- package/dist/generator/mermaid-er/helper/extract-relations.d.ts +8 -0
- package/dist/generator/mermaid-er/{validator → helper}/extract-relations.js +5 -5
- package/dist/generator/mermaid-er/index.js +1 -1
- package/dist/generator/mermaid-er/utils/index.d.ts +34 -0
- package/dist/generator/mermaid-er/utils/index.js +48 -0
- package/dist/generator/valibot/generator/index.d.ts +0 -2
- package/dist/generator/valibot/generator/index.js +0 -2
- package/dist/generator/valibot/generator/schemas.js +1 -1
- package/dist/generator/valibot/generator/valibot.d.ts +2 -2
- package/dist/generator/valibot/generator/valibot.js +4 -12
- package/dist/generator/valibot/index.js +1 -1
- package/dist/generator/valibot/utils/index.d.ts +42 -0
- package/dist/generator/valibot/utils/index.js +61 -0
- package/dist/generator/zod/generator/index.d.ts +1 -3
- package/dist/generator/zod/generator/index.js +1 -3
- package/dist/generator/zod/generator/schemas.js +2 -1
- package/dist/generator/zod/generator/zod.d.ts +2 -2
- package/dist/generator/zod/generator/zod.js +8 -16
- package/dist/generator/zod/index.js +1 -1
- package/dist/generator/zod/utils/index.d.ts +42 -0
- package/dist/generator/zod/utils/index.js +61 -0
- package/dist/shared/utils/index.d.ts +52 -3
- package/dist/shared/utils/index.js +42 -3
- package/package.json +6 -6
- package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -9
- package/dist/generator/mermaid-er/types.d.ts +0 -10
- package/dist/generator/mermaid-er/types.js +0 -1
- package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +0 -9
- package/dist/generator/mermaid-er/validator/extract-relations.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/index.d.ts +0 -5
- package/dist/generator/mermaid-er/validator/index.js +0 -5
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/is-relationship.js +0 -8
- package/dist/generator/mermaid-er/validator/parse-relation.d.ts +0 -8
- package/dist/generator/mermaid-er/validator/parse-relation.js +0 -21
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -6
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -8
- package/dist/generator/valibot/generator/infer-input.d.ts +0 -7
- package/dist/generator/valibot/generator/infer-input.js +0 -9
- package/dist/generator/valibot/generator/properties.d.ts +0 -7
- package/dist/generator/valibot/generator/properties.js +0 -15
- package/dist/generator/valibot/validator/index.d.ts +0 -2
- package/dist/generator/valibot/validator/index.js +0 -2
- package/dist/generator/valibot/validator/is-valibot-document.d.ts +0 -1
- package/dist/generator/valibot/validator/is-valibot-document.js +0 -10
- package/dist/generator/valibot/validator/is-valibot.d.ts +0 -6
- package/dist/generator/valibot/validator/is-valibot.js +0 -11
- package/dist/generator/zod/generator/infer.d.ts +0 -7
- package/dist/generator/zod/generator/infer.js +0 -9
- package/dist/generator/zod/generator/properties.d.ts +0 -13
- package/dist/generator/zod/generator/properties.js +0 -21
- package/dist/generator/zod/validator/index.d.ts +0 -2
- package/dist/generator/zod/validator/index.js +0 -2
- package/dist/generator/zod/validator/is-zod-document.d.ts +0 -6
- package/dist/generator/zod/validator/is-zod-document.js +0 -15
- package/dist/generator/zod/validator/is-zod.d.ts +0 -6
- package/dist/generator/zod/validator/is-zod.js +0 -11
- package/dist/shared/helper/group-by-model.d.ts +0 -8
- package/dist/shared/helper/group-by-model.js +0 -15
- package/dist/shared/types.d.ts +0 -16
- package/dist/shared/types.js +0 -1
- package/dist/shared/utils/capitalize.d.ts +0 -16
- package/dist/shared/utils/capitalize.js +0 -18
- package/dist/shared/utils/decapitalize.d.ts +0 -15
- package/dist/shared/utils/decapitalize.js +0 -17
- package/dist/shared/utils/snake-case.d.ts +0 -1
- package/dist/shared/utils/snake-case.js +0 -3
- package/dist/shared/validator/is-fields.d.ts +0 -12
- package/dist/shared/validator/is-fields.js +0 -8
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a `z.infer` type for the specified model.
|
|
3
|
+
*
|
|
4
|
+
* @param modelName - The name of the model.
|
|
5
|
+
* @returns The generated TypeScript type definition line using Zod.
|
|
6
|
+
*/
|
|
7
|
+
export declare function infer(modelName: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates Zod property definitions from model fields.
|
|
10
|
+
*
|
|
11
|
+
* Filters out fields without validation, removes documentation lines
|
|
12
|
+
* that include @relation, @v, or @z, and optionally includes doc comments.
|
|
13
|
+
*
|
|
14
|
+
* @param modelFields - The list of model fields with documentation and validation info.
|
|
15
|
+
* @param comment - Whether to include JSDoc comments for each field.
|
|
16
|
+
* @returns A string containing formatted Zod property definitions.
|
|
17
|
+
*/
|
|
18
|
+
export declare function properties(modelFields: {
|
|
19
|
+
documentation: string;
|
|
20
|
+
modelName: string;
|
|
21
|
+
fieldName: string;
|
|
22
|
+
validation: string | null;
|
|
23
|
+
comment: string[];
|
|
24
|
+
}[], comment: boolean): string;
|
|
25
|
+
/**
|
|
26
|
+
* Parses documentation and removes Zod validation lines.
|
|
27
|
+
*
|
|
28
|
+
* Lines containing "@z." are excluded from the result.
|
|
29
|
+
*
|
|
30
|
+
* @param documentation - The documentation string to parse.
|
|
31
|
+
* @returns An array of non-Zod documentation lines.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isZodDocument(documentation?: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the Zod validation expression from documentation.
|
|
36
|
+
*
|
|
37
|
+
* Searches for a line starting with "@z." and returns the expression part.
|
|
38
|
+
*
|
|
39
|
+
* @param documentation - The documentation string to parse.
|
|
40
|
+
* @returns The Zod validation string without the "@z." prefix, or null if not found.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isZod(documentation?: string): string | null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a `z.infer` type for the specified model.
|
|
3
|
+
*
|
|
4
|
+
* @param modelName - The name of the model.
|
|
5
|
+
* @returns The generated TypeScript type definition line using Zod.
|
|
6
|
+
*/
|
|
7
|
+
export function infer(modelName) {
|
|
8
|
+
return `export type ${modelName} = z.infer<typeof ${modelName}Schema>`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates Zod property definitions from model fields.
|
|
12
|
+
*
|
|
13
|
+
* Filters out fields without validation, removes documentation lines
|
|
14
|
+
* that include @relation, @v, or @z, and optionally includes doc comments.
|
|
15
|
+
*
|
|
16
|
+
* @param modelFields - The list of model fields with documentation and validation info.
|
|
17
|
+
* @param comment - Whether to include JSDoc comments for each field.
|
|
18
|
+
* @returns A string containing formatted Zod property definitions.
|
|
19
|
+
*/
|
|
20
|
+
export function properties(modelFields, comment) {
|
|
21
|
+
const fields = modelFields
|
|
22
|
+
.filter((field) => field.validation)
|
|
23
|
+
.map((field) => {
|
|
24
|
+
const cleanDoc = field.comment
|
|
25
|
+
.filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
|
|
26
|
+
.join('\n')
|
|
27
|
+
.trim();
|
|
28
|
+
const docComment = comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
|
|
29
|
+
return `${docComment} ${field.fieldName}: z.${field.validation}`;
|
|
30
|
+
})
|
|
31
|
+
.join(',\n');
|
|
32
|
+
return fields;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses documentation and removes Zod validation lines.
|
|
36
|
+
*
|
|
37
|
+
* Lines containing "@z." are excluded from the result.
|
|
38
|
+
*
|
|
39
|
+
* @param documentation - The documentation string to parse.
|
|
40
|
+
* @returns An array of non-Zod documentation lines.
|
|
41
|
+
*/
|
|
42
|
+
export function isZodDocument(documentation) {
|
|
43
|
+
return (documentation
|
|
44
|
+
?.split('\n')
|
|
45
|
+
.map((line) => line.trim())
|
|
46
|
+
.filter((line) => line && !line.includes('@z.')) ?? []);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extracts the Zod validation expression from documentation.
|
|
50
|
+
*
|
|
51
|
+
* Searches for a line starting with "@z." and returns the expression part.
|
|
52
|
+
*
|
|
53
|
+
* @param documentation - The documentation string to parse.
|
|
54
|
+
* @returns The Zod validation string without the "@z." prefix, or null if not found.
|
|
55
|
+
*/
|
|
56
|
+
export function isZod(documentation) {
|
|
57
|
+
if (!documentation)
|
|
58
|
+
return null;
|
|
59
|
+
const match = documentation.match(/@z\.(.+?)(?:\n|$)/);
|
|
60
|
+
return match ? match[1].trim() : null;
|
|
61
|
+
}
|
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Capitalize the first letter of a string.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The input string.
|
|
5
|
+
* @returns A new string with the first letter capitalized.
|
|
6
|
+
*/
|
|
7
|
+
export declare function capitalize(str: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a camelCase or PascalCase string to snake_case.
|
|
10
|
+
*
|
|
11
|
+
* @param name - The input string in camelCase or PascalCase.
|
|
12
|
+
* @returns The converted string in snake_case.
|
|
13
|
+
*/
|
|
14
|
+
export declare function snakeCase(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Group valid fields by their model name.
|
|
17
|
+
*
|
|
18
|
+
* @param validFields - An array of field objects with validation metadata.
|
|
19
|
+
* @returns An object mapping each model name to its corresponding array of fields.
|
|
20
|
+
*/
|
|
21
|
+
export declare function groupByModel(validFields: Required<{
|
|
22
|
+
documentation: string;
|
|
23
|
+
modelName: string;
|
|
24
|
+
fieldName: string;
|
|
25
|
+
comment: string[];
|
|
26
|
+
validation: string | null;
|
|
27
|
+
}>[]): Record<string, {
|
|
28
|
+
documentation: string;
|
|
29
|
+
modelName: string;
|
|
30
|
+
fieldName: string;
|
|
31
|
+
comment: string[];
|
|
32
|
+
validation: string | null;
|
|
33
|
+
}[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Extract fields with validation from a nested array of model fields.
|
|
36
|
+
*
|
|
37
|
+
* @param modelFields - A nested array of model field definitions.
|
|
38
|
+
* @returns A flat array of fields that include a non-null `validation` property.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isFields(modelFields: {
|
|
41
|
+
documentation: string | undefined;
|
|
42
|
+
modelName: string;
|
|
43
|
+
fieldName: string;
|
|
44
|
+
comment: string[];
|
|
45
|
+
validation: string | null;
|
|
46
|
+
}[][]): Required<{
|
|
47
|
+
documentation: string;
|
|
48
|
+
modelName: string;
|
|
49
|
+
fieldName: string;
|
|
50
|
+
comment: string[];
|
|
51
|
+
validation: string | null;
|
|
52
|
+
}>[];
|
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Capitalize the first letter of a string.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The input string.
|
|
5
|
+
* @returns A new string with the first letter capitalized.
|
|
6
|
+
*/
|
|
7
|
+
export function capitalize(str) {
|
|
8
|
+
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Convert a camelCase or PascalCase string to snake_case.
|
|
12
|
+
*
|
|
13
|
+
* @param name - The input string in camelCase or PascalCase.
|
|
14
|
+
* @returns The converted string in snake_case.
|
|
15
|
+
*/
|
|
16
|
+
export function snakeCase(name) {
|
|
17
|
+
return `${name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase()}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Group valid fields by their model name.
|
|
21
|
+
*
|
|
22
|
+
* @param validFields - An array of field objects with validation metadata.
|
|
23
|
+
* @returns An object mapping each model name to its corresponding array of fields.
|
|
24
|
+
*/
|
|
25
|
+
export function groupByModel(validFields) {
|
|
26
|
+
return validFields.reduce((acc, field) => {
|
|
27
|
+
if (!acc[field.modelName]) {
|
|
28
|
+
acc[field.modelName] = [];
|
|
29
|
+
}
|
|
30
|
+
acc[field.modelName].push(field);
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract fields with validation from a nested array of model fields.
|
|
36
|
+
*
|
|
37
|
+
* @param modelFields - A nested array of model field definitions.
|
|
38
|
+
* @returns A flat array of fields that include a non-null `validation` property.
|
|
39
|
+
*/
|
|
40
|
+
export function isFields(modelFields) {
|
|
41
|
+
return modelFields.flat().filter((field) => field.validation !== null);
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hekireki",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Hekireki is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Prisma schemas annotated with comments.",
|
|
7
7
|
"keywords": [
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
"coverage": "vitest run --coverage",
|
|
43
43
|
"release": "npm pkg fix && pnpm build && npm publish"
|
|
44
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@prisma/generator-helper": "^6.10.1",
|
|
47
|
+
"prettier": "^3.6.2"
|
|
48
|
+
},
|
|
45
49
|
"devDependencies": {
|
|
46
50
|
"@prisma/client": "^6.10.1",
|
|
47
51
|
"@types/node": "^22.15.34",
|
|
@@ -50,10 +54,6 @@
|
|
|
50
54
|
"tsx": "^4.20.3",
|
|
51
55
|
"valibot": "1.1.0",
|
|
52
56
|
"vitest": "^3.2.4",
|
|
53
|
-
"zod": "^
|
|
54
|
-
},
|
|
55
|
-
"dependencies": {
|
|
56
|
-
"@prisma/generator-helper": "^6.10.1",
|
|
57
|
-
"prettier": "^3.6.2"
|
|
57
|
+
"zod": "^4.0.5"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
export declare function buildRelationLine(input: string): string;
|
|
9
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
export type Relation = {
|
|
3
|
-
fromModel: string;
|
|
4
|
-
toModel: string;
|
|
5
|
-
fromField: string;
|
|
6
|
-
toField: string;
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
|
-
export type Model = Readonly<DMMF.Model>;
|
|
10
|
-
export type ERContent = readonly string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { excludeManyToOneRelations } from './exclude-many-to-one-relations.js';
|
|
2
|
-
export { extractRelations } from './extract-relations.js';
|
|
3
|
-
export { isRelationship } from './is-relationship.js';
|
|
4
|
-
export { parseRelation } from './parse-relation.js';
|
|
5
|
-
export { removeDuplicateRelations } from './remove-duplicate-relations.js';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { excludeManyToOneRelations } from './exclude-many-to-one-relations.js';
|
|
2
|
-
export { extractRelations } from './extract-relations.js';
|
|
3
|
-
export { isRelationship } from './is-relationship.js';
|
|
4
|
-
export { parseRelation } from './parse-relation.js';
|
|
5
|
-
export { removeDuplicateRelations } from './remove-duplicate-relations.js';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* parse relation
|
|
3
|
-
* @function parseRelation
|
|
4
|
-
* @param line
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export function parseRelation(line) {
|
|
8
|
-
const relationRegex = /^@relation\s+(\w+)\.(\w+)\s+(\w+)\.(\w+)\s+(\w+-to-\w+)$/;
|
|
9
|
-
const match = line.trim().match(relationRegex);
|
|
10
|
-
if (!match) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const [, fromModel, fromField, toModel, toField, relationType] = match;
|
|
14
|
-
return {
|
|
15
|
-
fromModel,
|
|
16
|
-
fromField,
|
|
17
|
-
toModel,
|
|
18
|
-
toField,
|
|
19
|
-
type: relationType,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate the infer input type for the model
|
|
3
|
-
* @param modelName - The name of the model
|
|
4
|
-
* @param config - The configuration for the generator
|
|
5
|
-
* @returns The generated infer input type
|
|
6
|
-
*/
|
|
7
|
-
export function inferInput(modelName) {
|
|
8
|
-
return `export type ${modelName} = v.InferInput<typeof ${modelName}Schema>`;
|
|
9
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function properties(modelFields, comment) {
|
|
2
|
-
const fields = modelFields
|
|
3
|
-
.filter((field) => field.validation)
|
|
4
|
-
.map((field) => {
|
|
5
|
-
// @relation, @v, @z exclude
|
|
6
|
-
const cleanDoc = field.comment
|
|
7
|
-
.filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
|
|
8
|
-
.join('\n')
|
|
9
|
-
.trim();
|
|
10
|
-
const docComment = comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
|
|
11
|
-
return `${docComment} ${field.fieldName}: v.${field.validation}`;
|
|
12
|
-
})
|
|
13
|
-
.join(',\n');
|
|
14
|
-
return fields;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValibotDocument(documentation?: string): string[];
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const VALIDATION_PATTERNS = ['@v.'];
|
|
2
|
-
export function isValibotDocument(documentation) {
|
|
3
|
-
if (!documentation)
|
|
4
|
-
return [];
|
|
5
|
-
return documentation
|
|
6
|
-
.split('\n')
|
|
7
|
-
.filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
|
|
8
|
-
.map((line) => line.trim())
|
|
9
|
-
.filter(Boolean);
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if the documentation is a Valibot validation
|
|
3
|
-
* @param documentation
|
|
4
|
-
* @returns string | null
|
|
5
|
-
*/
|
|
6
|
-
export function isValibot(documentation) {
|
|
7
|
-
if (!documentation)
|
|
8
|
-
return null;
|
|
9
|
-
const match = documentation.match(/@v\.(.+?)(?:\n|$)/);
|
|
10
|
-
return match ? match[1].trim() : null;
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Zod infer
|
|
3
|
-
* @param modelName - The name of the model
|
|
4
|
-
* @param config - The configuration for the generator
|
|
5
|
-
* @returns The generated Zod infer
|
|
6
|
-
*/
|
|
7
|
-
export function infer(modelName) {
|
|
8
|
-
return `export type ${modelName} = z.infer<typeof ${modelName}Schema>`;
|
|
9
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Zod properties
|
|
3
|
-
* @param modelFields - The fields of the model
|
|
4
|
-
* @param config - The configuration for the generator
|
|
5
|
-
* @returns The generated Zod properties
|
|
6
|
-
*/
|
|
7
|
-
export declare function properties(modelFields: {
|
|
8
|
-
documentation: string;
|
|
9
|
-
modelName: string;
|
|
10
|
-
fieldName: string;
|
|
11
|
-
validation: string | null;
|
|
12
|
-
comment: string[];
|
|
13
|
-
}[], comment: boolean): string;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Zod properties
|
|
3
|
-
* @param modelFields - The fields of the model
|
|
4
|
-
* @param config - The configuration for the generator
|
|
5
|
-
* @returns The generated Zod properties
|
|
6
|
-
*/
|
|
7
|
-
export function properties(modelFields, comment) {
|
|
8
|
-
const fields = modelFields
|
|
9
|
-
.filter((field) => field.validation)
|
|
10
|
-
.map((field) => {
|
|
11
|
-
// @relation, @v, @z exclude
|
|
12
|
-
const cleanDoc = field.comment
|
|
13
|
-
.filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
|
|
14
|
-
.join('\n')
|
|
15
|
-
.trim();
|
|
16
|
-
const docComment = comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
|
|
17
|
-
return `${docComment} ${field.fieldName}: z.${field.validation}`;
|
|
18
|
-
})
|
|
19
|
-
.join(',\n');
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const VALIDATION_PATTERNS = ['@z.'];
|
|
2
|
-
/**
|
|
3
|
-
* Is Zod documentation
|
|
4
|
-
* @param documentation - The documentation of the field
|
|
5
|
-
* @returns The Zod documentation
|
|
6
|
-
*/
|
|
7
|
-
export function isZodDocument(documentation) {
|
|
8
|
-
if (!documentation)
|
|
9
|
-
return [];
|
|
10
|
-
return documentation
|
|
11
|
-
.split('\n')
|
|
12
|
-
.filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
|
|
13
|
-
.map((line) => line.trim())
|
|
14
|
-
.filter(Boolean);
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is Zod validation
|
|
3
|
-
* @param documentation - The documentation of the field
|
|
4
|
-
* @returns The Zod validation
|
|
5
|
-
*/
|
|
6
|
-
export function isZod(documentation) {
|
|
7
|
-
if (!documentation)
|
|
8
|
-
return null;
|
|
9
|
-
const match = documentation.match(/@z\.(.+?)(?:\n|$)/);
|
|
10
|
-
return match ? match[1].trim() : null;
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { GroupedFields, ValidField } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Groups valid fields by model name.
|
|
4
|
-
*
|
|
5
|
-
* @param validFields - The array of valid fields.
|
|
6
|
-
* @returns The grouped fields.
|
|
7
|
-
*/
|
|
8
|
-
export declare function groupByModel(validFields: ValidField[]): GroupedFields;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Groups valid fields by model name.
|
|
3
|
-
*
|
|
4
|
-
* @param validFields - The array of valid fields.
|
|
5
|
-
* @returns The grouped fields.
|
|
6
|
-
*/
|
|
7
|
-
export function groupByModel(validFields) {
|
|
8
|
-
return validFields.reduce((acc, field) => {
|
|
9
|
-
if (!acc[field.modelName]) {
|
|
10
|
-
acc[field.modelName] = [];
|
|
11
|
-
}
|
|
12
|
-
acc[field.modelName].push(field);
|
|
13
|
-
return acc;
|
|
14
|
-
}, {});
|
|
15
|
-
}
|
package/dist/shared/types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
export type Field = {
|
|
3
|
-
documentation: string;
|
|
4
|
-
modelName: string;
|
|
5
|
-
fieldName: string;
|
|
6
|
-
comment: string[];
|
|
7
|
-
validation: string | null;
|
|
8
|
-
};
|
|
9
|
-
export type ValidField = Required<Field>;
|
|
10
|
-
export type GroupedFields = Record<string, Field[]>;
|
|
11
|
-
export type Model = Readonly<DMMF.Model>;
|
|
12
|
-
export type ModelInfo = {
|
|
13
|
-
documentation: string;
|
|
14
|
-
name: string;
|
|
15
|
-
fields: Model['fields'];
|
|
16
|
-
};
|
package/dist/shared/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capitalize the first letter of a string
|
|
3
|
-
* @param { string } str - String to capitalize
|
|
4
|
-
* @returns { string } String with first letter capitalized
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* capitalize('posts') // Returns: 'Posts'
|
|
8
|
-
* capitalize('user') // Returns: 'User'
|
|
9
|
-
* capitalize('api') // Returns: 'Api'
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* - Leaves rest of the string unchanged
|
|
13
|
-
* - Returns empty string if input is empty
|
|
14
|
-
* - Commonly used for generating type names and class names
|
|
15
|
-
*/
|
|
16
|
-
export declare function capitalize(str: string): string;
|