hekireki 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/format/index.js +6 -6
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +1 -3
- package/dist/common/helper/get-camel-case-schema-name-helper.js +2 -2
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +1 -3
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +2 -2
- package/dist/common/helper/get-variable-name-helper.d.ts +1 -4
- package/dist/common/helper/get-variable-name-helper.js +3 -3
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +1 -4
- package/dist/common/helper/get-variable-schema-name-helper.js +3 -7
- package/dist/common/helper/group-by-model-helper.d.ts +1 -3
- package/dist/common/helper/group-by-model-helper.js +7 -7
- package/dist/common/text/capitalize.js +1 -1
- package/dist/common/text/decapitalize.js +1 -1
- package/dist/common/type/index.d.ts +8 -8
- package/dist/common/validator/is-fields-validation.d.ts +7 -9
- package/dist/common/validator/is-fields-validation.js +3 -1
- package/dist/generator/mermaid/generator/generate-er-content.js +8 -14
- package/dist/generator/mermaid/generator/generate-model-fields.js +16 -21
- package/dist/generator/mermaid/generator/generate-model-info.js +5 -5
- package/dist/generator/mermaid/generator/generate-relation-line.js +5 -5
- package/dist/generator/mermaid/index.d.ts +3 -2
- package/dist/generator/mermaid/index.js +53 -52
- package/dist/generator/mermaid/output/index.js +13 -17
- package/dist/generator/mermaid/type/index.d.ts +6 -30
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +1 -3
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +1 -1
- package/dist/generator/mermaid/validator/extract-relations.js +13 -15
- package/dist/generator/mermaid/validator/is-relation.js +25 -25
- package/dist/generator/mermaid/validator/parse-relation.js +16 -17
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +1 -3
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +1 -1
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +1 -4
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +3 -10
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +7 -10
- package/dist/generator/valibot/generator/generate-valibot-properties.js +15 -21
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +1 -5
- package/dist/generator/valibot/generator/generate-valibot-schema.js +2 -6
- package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +7 -10
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +7 -14
- package/dist/generator/valibot/generator/generate-valibot.d.ts +1 -4
- package/dist/generator/valibot/generator/generate-valibot.js +36 -51
- package/dist/generator/valibot/index.d.ts +7 -6
- package/dist/generator/valibot/index.js +41 -46
- package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +1 -3
- package/dist/generator/valibot/validator/is-valibot-documentation.js +7 -8
- package/dist/generator/valibot/validator/is-valibot-validation.d.ts +1 -3
- package/dist/generator/valibot/validator/is-valibot-validation.js +4 -3
- package/dist/generator/zod/generator/generate-zod-infer.d.ts +1 -4
- package/dist/generator/zod/generator/generate-zod-infer.js +3 -10
- package/dist/generator/zod/generator/generate-zod-properties.d.ts +7 -10
- package/dist/generator/zod/generator/generate-zod-properties.js +15 -21
- package/dist/generator/zod/generator/generate-zod-schema.d.ts +1 -5
- package/dist/generator/zod/generator/generate-zod-schema.js +2 -6
- package/dist/generator/zod/generator/generate-zod-schemas.d.ts +7 -10
- package/dist/generator/zod/generator/generate-zod-schemas.js +7 -14
- package/dist/generator/zod/generator/generate-zod.d.ts +1 -4
- package/dist/generator/zod/generator/generate-zod.js +36 -51
- package/dist/generator/zod/index.d.ts +7 -6
- package/dist/generator/zod/index.js +41 -46
- package/dist/generator/zod/validator/is-zod-documentation.d.ts +1 -3
- package/dist/generator/zod/validator/is-zod-documentation.js +7 -8
- package/dist/generator/zod/validator/is-zod-validation.js +4 -3
- package/package.json +2 -2
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRelation = isRelation;
|
|
4
4
|
const VALID_RELATIONS = new Set([
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
"one-to-one",
|
|
6
|
+
"one-to-many",
|
|
7
|
+
"many-to-one",
|
|
8
|
+
"many-to-many",
|
|
9
|
+
"one-to-zero-one",
|
|
10
|
+
"zero-one-to-one",
|
|
11
|
+
"zero-to-one",
|
|
12
|
+
"zero-to-zero-one",
|
|
13
|
+
"zero-to-many",
|
|
14
|
+
"zero-one-to-many",
|
|
15
|
+
"many-to-zero-one",
|
|
16
|
+
"one-to-one-optional",
|
|
17
|
+
"one-to-many-optional",
|
|
18
|
+
"many-to-one-optional",
|
|
19
|
+
"many-to-many-optional",
|
|
20
|
+
"one-to-zero-one-optional",
|
|
21
|
+
"zero-one-to-one-optional",
|
|
22
|
+
"zero-to-one-optional",
|
|
23
|
+
"zero-to-many-optional",
|
|
24
|
+
"zero-one-to-many-optional",
|
|
25
|
+
"many-to-zero-one-optional",
|
|
26
|
+
"many-to-zero-many",
|
|
27
|
+
"zero-many-to-many",
|
|
28
|
+
"zero-many-to-zero-many",
|
|
29
29
|
]);
|
|
30
30
|
function isRelation(value) {
|
|
31
|
-
|
|
31
|
+
return typeof value === "string" && VALID_RELATIONS.has(value);
|
|
32
32
|
}
|
|
@@ -9,21 +9,20 @@ const is_relation_1 = require("./is-relation");
|
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
function parseRelation(line) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
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
|
+
};
|
|
29
28
|
}
|
|
@@ -5,7 +5,4 @@ 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(
|
|
9
|
-
modelName: string,
|
|
10
|
-
config: Config,
|
|
11
|
-
): string;
|
|
8
|
+
export declare function generateValibotInferInput(modelName: string, config: Config): string;
|
|
@@ -10,14 +10,7 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated infer input type
|
|
11
11
|
*/
|
|
12
12
|
function generateValibotInferInput(modelName, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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}>`;
|
|
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}>`;
|
|
23
16
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Config } from "..";
|
|
2
|
-
export declare function generateValibotProperties(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}[],
|
|
10
|
-
config?: Config,
|
|
11
|
-
): string;
|
|
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,25 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateValibotProperties = generateValibotProperties;
|
|
4
4
|
function generateValibotProperties(modelFields, config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
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;
|
|
26
20
|
}
|
|
@@ -6,8 +6,4 @@ 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(
|
|
10
|
-
modelName: string,
|
|
11
|
-
fields: string,
|
|
12
|
-
config: Config,
|
|
13
|
-
): string;
|
|
9
|
+
export declare function generateValibotSchema(modelName: string, fields: string, config: Config): string;
|
|
@@ -10,10 +10,6 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated Valibot schema
|
|
11
11
|
*/
|
|
12
12
|
function generateValibotSchema(modelName, fields, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
modelName,
|
|
16
|
-
config,
|
|
17
|
-
);
|
|
18
|
-
return `export const ${schemaName} = v.object({\n${fields}\n})`;
|
|
13
|
+
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(modelName, config);
|
|
14
|
+
return `export const ${schemaName} = v.object({\n${fields}\n})`;
|
|
19
15
|
}
|
|
@@ -6,13 +6,10 @@ import type { Config } from "..";
|
|
|
6
6
|
* @param config
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateValibotSchemas(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}[],
|
|
17
|
-
config: Config,
|
|
18
|
-
): string;
|
|
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;
|
|
@@ -11,18 +11,11 @@ const generate_valibot_schema_1 = require("./generate-valibot-schema");
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
function generateValibotSchemas(modelFields, config) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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)}`;
|
|
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)}`;
|
|
28
21
|
}
|
|
@@ -6,7 +6,4 @@ 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(
|
|
10
|
-
models: readonly Model[],
|
|
11
|
-
config: Config,
|
|
12
|
-
): string;
|
|
9
|
+
export declare function generateValibot(models: readonly Model[], config: Config): string;
|
|
@@ -15,55 +15,40 @@ const VALIBOT_IMPORT = `import * as v from 'valibot'\n`;
|
|
|
15
15
|
* @returns The generated Valibot schemas and types
|
|
16
16
|
*/
|
|
17
17
|
function generateValibot(models, config) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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");
|
|
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");
|
|
69
54
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import type { GeneratorOptions } from "@prisma/generator-helper";
|
|
2
3
|
export type Config = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
output?: string;
|
|
5
|
+
file?: string | string[];
|
|
6
|
+
schemaName?: "PascalCase" | "camelCase" | string | string[];
|
|
7
|
+
typeName?: "PascalCase" | "camelCase" | string | string[];
|
|
8
|
+
type?: boolean | string | string[];
|
|
9
|
+
comment?: boolean | string | string[];
|
|
9
10
|
};
|
|
10
11
|
export declare function main(options: GeneratorOptions): Promise<void>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
"use strict";
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
-
};
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
7
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
7
|
exports.main = main;
|
|
9
8
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
@@ -11,49 +10,45 @@ const generate_valibot_1 = require("./generator/generate-valibot");
|
|
|
11
10
|
const prettier_1 = require("prettier");
|
|
12
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
12
|
const DEFAULT_CONFIG = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
output: "./valibot",
|
|
14
|
+
file: "index.ts",
|
|
15
|
+
schemaName: "PascalCase",
|
|
16
|
+
typeName: "PascalCase",
|
|
17
|
+
type: false,
|
|
18
|
+
comment: false,
|
|
20
19
|
};
|
|
21
20
|
async function main(options) {
|
|
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
|
-
const file = config.file ?? "index.ts";
|
|
48
|
-
const filePath = `${config.output}/${file}`;
|
|
49
|
-
node_fs_1.default.writeFileSync(filePath, code);
|
|
21
|
+
const config = {
|
|
22
|
+
output: options.generator.output?.value ?? DEFAULT_CONFIG.output,
|
|
23
|
+
file: options.generator.config?.file ?? DEFAULT_CONFIG.file,
|
|
24
|
+
schemaName: options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
|
|
25
|
+
typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
|
|
26
|
+
type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
|
|
27
|
+
comment: options.generator.config?.comment === "true",
|
|
28
|
+
};
|
|
29
|
+
const content = (0, generate_valibot_1.generateValibot)(options.dmmf.datamodel.models, config);
|
|
30
|
+
const code = await (0, prettier_1.format)(content, {
|
|
31
|
+
parser: "typescript",
|
|
32
|
+
printWidth: 100,
|
|
33
|
+
singleQuote: true,
|
|
34
|
+
semi: false,
|
|
35
|
+
});
|
|
36
|
+
if (!config.output) {
|
|
37
|
+
throw new Error("output is required");
|
|
38
|
+
}
|
|
39
|
+
if (!node_fs_1.default.existsSync(config.output)) {
|
|
40
|
+
node_fs_1.default.mkdirSync(config.output, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
const file = config.file ?? "index.ts";
|
|
43
|
+
const filePath = `${config.output}/${file}`;
|
|
44
|
+
node_fs_1.default.writeFileSync(filePath, code);
|
|
50
45
|
}
|
|
51
46
|
(0, generator_helper_1.generatorHandler)({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
onManifest() {
|
|
48
|
+
return {
|
|
49
|
+
defaultOutput: "./valibot/",
|
|
50
|
+
prettyName: "Hekireki-Valibot",
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
onGenerate: main,
|
|
59
54
|
});
|
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isValibotDocumentValidation = isValibotDocumentValidation;
|
|
4
4
|
const VALIDATION_PATTERNS = ["@v."];
|
|
5
5
|
function isValibotDocumentValidation(documentation) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.filter(Boolean);
|
|
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);
|
|
14
13
|
}
|
|
@@ -8,7 +8,8 @@ exports.isValibotValidation = isValibotValidation;
|
|
|
8
8
|
* @returns string | null
|
|
9
9
|
*/
|
|
10
10
|
function isValibotValidation(documentation) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!documentation)
|
|
12
|
+
return null;
|
|
13
|
+
const match = documentation.match(/@v\.(.+?)(?:\n|$)/);
|
|
14
|
+
return match ? match[1].trim() : null;
|
|
14
15
|
}
|
|
@@ -5,7 +5,4 @@ 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(
|
|
9
|
-
modelName: string,
|
|
10
|
-
config: Config,
|
|
11
|
-
): string;
|
|
8
|
+
export declare function generateZodInfer(modelName: string, config: Config): string;
|
|
@@ -10,14 +10,7 @@ const get_variable_schema_name_helper_1 = require("../../../common/helper/get-va
|
|
|
10
10
|
* @returns The generated Zod infer
|
|
11
11
|
*/
|
|
12
12
|
function generateZodInfer(modelName, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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}>`;
|
|
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}>`;
|
|
23
16
|
}
|
|
@@ -5,13 +5,10 @@ import type { Config } from "..";
|
|
|
5
5
|
* @param config - The configuration for the generator
|
|
6
6
|
* @returns The generated Zod properties
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateZodProperties(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}[],
|
|
16
|
-
config?: Config,
|
|
17
|
-
): string;
|
|
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,25 +8,19 @@ exports.generateZodProperties = generateZodProperties;
|
|
|
8
8
|
* @returns The generated Zod properties
|
|
9
9
|
*/
|
|
10
10
|
function generateZodProperties(modelFields, config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
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;
|
|
32
26
|
}
|