hekireki 0.1.0 → 0.2.0
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 +71 -214
- package/dist/generator/mermaid-er/generator/er-content.d.ts +2 -0
- package/dist/generator/mermaid-er/generator/er-content.js +21 -0
- package/dist/generator/mermaid-er/generator/index.d.ts +4 -0
- package/dist/generator/mermaid-er/generator/index.js +4 -0
- package/dist/generator/mermaid-er/generator/{generate-model-fields.d.ts → model-fields.d.ts} +1 -1
- package/dist/generator/mermaid-er/generator/{generate-model-fields.js → model-fields.js} +1 -4
- package/dist/generator/mermaid-er/generator/model-info.d.ts +7 -0
- package/dist/generator/mermaid-er/generator/model-info.js +9 -0
- package/dist/generator/mermaid-er/generator/relation-line.d.ts +7 -0
- package/dist/generator/mermaid-er/generator/relation-line.js +13 -0
- package/dist/generator/mermaid-er/index.d.ts +0 -6
- package/dist/generator/mermaid-er/index.js +11 -28
- package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -5
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +7 -15
- package/dist/generator/mermaid-er/types.js +1 -0
- package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +1 -4
- package/dist/generator/mermaid-er/validator/extract-relations.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/extract-relations.js +5 -8
- package/dist/generator/mermaid-er/validator/index.d.ts +5 -0
- package/dist/generator/mermaid-er/validator/index.js +5 -0
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/is-relationship.js +1 -4
- package/dist/generator/mermaid-er/validator/parse-relation.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/parse-relation.js +1 -4
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
- package/dist/generator/valibot/generator/index.d.ts +5 -0
- package/dist/generator/valibot/generator/index.js +5 -0
- package/dist/generator/valibot/generator/{generate-valibot-infer-input.d.ts → infer-input.d.ts} +1 -2
- package/dist/generator/valibot/generator/infer-input.js +9 -0
- package/dist/generator/valibot/generator/properties.d.ts +7 -0
- package/dist/generator/valibot/generator/{generate-valibot-properties.js → properties.js} +2 -5
- package/dist/generator/valibot/generator/schema.d.ts +7 -0
- package/dist/generator/valibot/generator/schema.js +9 -0
- package/dist/generator/valibot/generator/{generate-valibot-schemas.d.ts → schemas.d.ts} +2 -4
- package/dist/generator/valibot/generator/schemas.js +17 -0
- package/dist/generator/valibot/generator/valibot.d.ts +9 -0
- package/dist/generator/valibot/generator/valibot.js +50 -0
- package/dist/generator/valibot/index.d.ts +0 -8
- package/dist/generator/valibot/index.js +13 -44
- package/dist/generator/valibot/validator/index.d.ts +2 -0
- package/dist/generator/valibot/validator/index.js +2 -0
- package/dist/generator/valibot/validator/is-valibot-document.d.ts +1 -0
- package/dist/generator/valibot/validator/{is-valibot-documentation.js → is-valibot-document.js} +1 -4
- package/dist/generator/valibot/validator/is-valibot.d.ts +6 -0
- package/dist/generator/valibot/validator/{is-valibot-validation.js → is-valibot.js} +1 -5
- package/dist/generator/zod/generator/index.d.ts +5 -0
- package/dist/generator/zod/generator/index.js +5 -0
- package/dist/generator/zod/generator/{generate-zod-infer.d.ts → infer.d.ts} +1 -2
- package/dist/generator/zod/generator/infer.js +9 -0
- package/dist/generator/zod/generator/{generate-zod-properties.d.ts → properties.d.ts} +2 -3
- package/dist/generator/zod/generator/{generate-zod-properties.js → properties.js} +2 -5
- package/dist/generator/zod/generator/{generate-zod-schema.d.ts → schema.d.ts} +1 -2
- package/dist/generator/zod/generator/schema.js +10 -0
- package/dist/generator/zod/generator/{generate-zod-schemas.d.ts → schemas.d.ts} +2 -3
- package/dist/generator/zod/generator/schemas.js +16 -0
- package/dist/generator/zod/generator/zod.d.ts +9 -0
- package/dist/generator/zod/generator/zod.js +55 -0
- package/dist/generator/zod/index.d.ts +0 -8
- package/dist/generator/zod/index.js +14 -44
- package/dist/generator/zod/validator/index.d.ts +2 -0
- package/dist/generator/zod/validator/index.js +2 -0
- package/dist/generator/zod/validator/{is-zod-documentation.d.ts → is-zod-document.d.ts} +1 -1
- package/dist/generator/zod/validator/{is-zod-documentation.js → is-zod-document.js} +1 -4
- package/dist/generator/zod/validator/{is-zod-validation.d.ts → is-zod.d.ts} +1 -1
- package/dist/generator/zod/validator/{is-zod-validation.js → is-zod.js} +1 -4
- package/dist/shared/format/index.d.ts +1 -0
- package/dist/shared/format/index.js +9 -0
- package/dist/shared/helper/group-by-model.d.ts +8 -0
- package/dist/{common/helper/group-by-model-helper.js → shared/helper/group-by-model.js} +1 -4
- package/dist/shared/types.js +1 -0
- package/dist/{common/text → shared/utils}/capitalize.d.ts +3 -5
- package/dist/{common/text → shared/utils}/capitalize.js +4 -9
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/index.js +1 -0
- package/dist/{common/validator/is-fields-validation.d.ts → shared/validator/is-fields.d.ts} +2 -2
- package/dist/{common/validator/is-fields-validation.js → shared/validator/is-fields.js} +1 -4
- package/package.json +12 -11
- package/dist/common/format/index.d.ts +0 -1
- package/dist/common/format/index.js +0 -12
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +0 -7
- package/dist/common/helper/get-camel-case-schema-name-helper.js +0 -14
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +0 -8
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +0 -15
- package/dist/common/helper/get-variable-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-name-helper.js +0 -15
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-schema-name-helper.js +0 -17
- package/dist/common/helper/group-by-model-helper.d.ts +0 -8
- package/dist/common/text/decapitalize.d.ts +0 -17
- package/dist/common/text/decapitalize.js +0 -22
- package/dist/common/type/index.js +0 -2
- package/dist/generator/mermaid/generator/generate-er-content.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-er-content.js +0 -22
- package/dist/generator/mermaid/generator/generate-model-fields.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-model-fields.js +0 -27
- package/dist/generator/mermaid/generator/generate-model-info.d.ts +0 -8
- package/dist/generator/mermaid/generator/generate-model-info.js +0 -13
- package/dist/generator/mermaid/generator/generate-relation-line.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-relation-line.js +0 -16
- package/dist/generator/mermaid/index.d.ts +0 -9
- package/dist/generator/mermaid/index.js +0 -39
- package/dist/generator/mermaid/output/index.d.ts +0 -8
- package/dist/generator/mermaid/output/index.js +0 -24
- package/dist/generator/mermaid/relationship/build-relation-line.d.ts +0 -14
- package/dist/generator/mermaid/relationship/build-relation-line.js +0 -37
- package/dist/generator/mermaid/relationship/index.d.ts +0 -12
- package/dist/generator/mermaid/relationship/index.js +0 -30
- package/dist/generator/mermaid/type/index.d.ts +0 -10
- package/dist/generator/mermaid/type/index.js +0 -2
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +0 -7
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +0 -12
- package/dist/generator/mermaid/validator/extract-relations.d.ts +0 -7
- package/dist/generator/mermaid/validator/extract-relations.js +0 -25
- package/dist/generator/mermaid/validator/is-relation.d.ts +0 -7
- package/dist/generator/mermaid/validator/is-relation.js +0 -37
- package/dist/generator/mermaid/validator/is-relationship.d.ts +0 -7
- package/dist/generator/mermaid/validator/is-relationship.js +0 -11
- package/dist/generator/mermaid/validator/parse-relation.d.ts +0 -8
- package/dist/generator/mermaid/validator/parse-relation.js +0 -24
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +0 -6
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +0 -11
- package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +0 -7
- package/dist/generator/mermaid-er/generator/generate-er-content.js +0 -22
- package/dist/generator/mermaid-er/generator/generate-model-info.d.ts +0 -8
- package/dist/generator/mermaid-er/generator/generate-model-info.js +0 -13
- package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +0 -7
- package/dist/generator/mermaid-er/generator/generate-relation-line.js +0 -16
- package/dist/generator/mermaid-er/output/index.d.ts +0 -8
- package/dist/generator/mermaid-er/output/index.js +0 -24
- package/dist/generator/mermaid-er/type/index.js +0 -2
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +0 -8
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -15
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +0 -21
- package/dist/generator/valibot/generator/generate-valibot.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot.js +0 -52
- package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +0 -1
- package/dist/generator/valibot/validator/is-valibot-validation.d.ts +0 -7
- package/dist/generator/zod/generator/generate-zod-infer.js +0 -16
- package/dist/generator/zod/generator/generate-zod-schema.js +0 -15
- package/dist/generator/zod/generator/generate-zod-schemas.js +0 -20
- package/dist/generator/zod/generator/generate-zod.d.ts +0 -9
- package/dist/generator/zod/generator/generate-zod.js +0 -52
- /package/dist/generator/mermaid-er/{type/index.d.ts → types.d.ts} +0 -0
- /package/dist/{common/type/index.d.ts → shared/types.d.ts} +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
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.OutputFile = OutputFile;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
/**
|
|
9
|
-
* Output the ER content to a file
|
|
10
|
-
* @param content - The ER content
|
|
11
|
-
* @param config - The configuration
|
|
12
|
-
*/
|
|
13
|
-
function OutputFile(content, config) {
|
|
14
|
-
const outputDir = config.output;
|
|
15
|
-
if (!outputDir) {
|
|
16
|
-
throw new Error('output is required');
|
|
17
|
-
}
|
|
18
|
-
if (!node_fs_1.default.existsSync(outputDir)) {
|
|
19
|
-
node_fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
const file = config.file ?? 'ER.md';
|
|
22
|
-
const filePath = `${outputDir}/${file}`;
|
|
23
|
-
node_fs_1.default.writeFileSync(filePath, content.join('\n'), { encoding: 'utf-8' });
|
|
24
|
-
}
|
|
@@ -1,14 +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
|
-
/**
|
|
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 {}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1,30 +0,0 @@
|
|
|
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,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,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.excludeManyToOneRelations = excludeManyToOneRelations;
|
|
4
|
-
/**
|
|
5
|
-
* exclude many-to-one relations
|
|
6
|
-
* @function excludeManyToOneRelations
|
|
7
|
-
* @param relations
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
function excludeManyToOneRelations(relations) {
|
|
11
|
-
return [...new Set(relations)].filter((r) => !r.includes('many-to-one'));
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractRelations = extractRelations;
|
|
4
|
-
const generate_relation_line_1 = require("../generator/generate-relation-line");
|
|
5
|
-
const parse_relation_1 = require("./parse-relation");
|
|
6
|
-
/**
|
|
7
|
-
* extract relations from model
|
|
8
|
-
* @param { Model } model
|
|
9
|
-
* @returns { readonly string[] }
|
|
10
|
-
*/
|
|
11
|
-
function extractRelations(model) {
|
|
12
|
-
const relations = [];
|
|
13
|
-
// @relation annotation
|
|
14
|
-
if (model.documentation) {
|
|
15
|
-
const annotationRelations = model.documentation
|
|
16
|
-
.split('\n')
|
|
17
|
-
.map((line) => {
|
|
18
|
-
const relation = (0, parse_relation_1.parseRelation)(line);
|
|
19
|
-
return relation ? (0, generate_relation_line_1.generateRelationLine)(relation) : null;
|
|
20
|
-
})
|
|
21
|
-
.filter((line) => line !== null);
|
|
22
|
-
relations.push(...annotationRelations);
|
|
23
|
-
}
|
|
24
|
-
return relations;
|
|
25
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRelation = isRelation;
|
|
4
|
-
const VALID_RELATIONS = new Set([
|
|
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
|
-
]);
|
|
30
|
-
/**
|
|
31
|
-
* check if the value is a valid relation
|
|
32
|
-
* @param { unknown } value
|
|
33
|
-
* @returns { boolean }
|
|
34
|
-
*/
|
|
35
|
-
function isRelation(value) {
|
|
36
|
-
return typeof value === "string" && VALID_RELATIONS.has(value);
|
|
37
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRelation = parseRelation;
|
|
4
|
-
/**
|
|
5
|
-
* parse relation
|
|
6
|
-
* @function parseRelation
|
|
7
|
-
* @param line
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
function parseRelation(line) {
|
|
11
|
-
const relationRegex = /^@relation\s+(\w+)\.(\w+)\s+(\w+)\.(\w+)\s+(\w+-to-\w+)$/;
|
|
12
|
-
const match = line.trim().match(relationRegex);
|
|
13
|
-
if (!match) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
const [, fromModel, fromField, toModel, toField, relationType] = match;
|
|
17
|
-
return {
|
|
18
|
-
fromModel,
|
|
19
|
-
fromField,
|
|
20
|
-
toModel,
|
|
21
|
-
toField,
|
|
22
|
-
type: relationType,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeDuplicateRelations = removeDuplicateRelations;
|
|
4
|
-
/**
|
|
5
|
-
* remove duplicate relations
|
|
6
|
-
* @param { readonly string[] } relations
|
|
7
|
-
* @returns { readonly string[] }
|
|
8
|
-
*/
|
|
9
|
-
function removeDuplicateRelations(relations) {
|
|
10
|
-
return [...new Set(relations)];
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateERContent = generateERContent;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const extract_relations_1 = require("../validator/extract-relations");
|
|
6
|
-
const generate_model_info_1 = require("../generator/generate-model-info");
|
|
7
|
-
const remove_duplicate_relations_1 = require("../validator/remove-duplicate-relations");
|
|
8
|
-
/**
|
|
9
|
-
* generate ER content
|
|
10
|
-
* @param { readonly Model[] } models - models
|
|
11
|
-
* @returns { ERContent } - ER content
|
|
12
|
-
*/
|
|
13
|
-
function generateERContent(models) {
|
|
14
|
-
// extract all relations
|
|
15
|
-
const allRelations = models.flatMap(extract_relations_1.extractRelations);
|
|
16
|
-
// remove duplicate relations
|
|
17
|
-
const uniqueRelations = (0, remove_duplicate_relations_1.removeDuplicateRelations)(allRelations);
|
|
18
|
-
// collect all model info
|
|
19
|
-
const modelInfos = models.flatMap(generate_model_info_1.generateModelInfo);
|
|
20
|
-
// build ER diagram
|
|
21
|
-
return [...__1.ER_HEADER, ...uniqueRelations, ...modelInfos, ...__1.ER_FOOTER];
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateModelInfo = generateModelInfo;
|
|
4
|
-
const generate_model_fields_1 = require("./generate-model-fields");
|
|
5
|
-
/**
|
|
6
|
-
* generate model info
|
|
7
|
-
* @function generateModelInfo
|
|
8
|
-
* @param model
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
function generateModelInfo(model) {
|
|
12
|
-
return [` ${model.name} {`, ...(0, generate_model_fields_1.generateModelFields)(model), ' }'];
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRelationLine = generateRelationLine;
|
|
4
|
-
const build_relation_line_1 = require("../relationship/build-relation-line");
|
|
5
|
-
/**
|
|
6
|
-
* generate relation line
|
|
7
|
-
* @param { Relation } relation
|
|
8
|
-
* @returns { string } relation line
|
|
9
|
-
*/
|
|
10
|
-
function generateRelationLine(relation) {
|
|
11
|
-
const cardinality = (0, build_relation_line_1.buildRelationLine)(relation.type);
|
|
12
|
-
if (!cardinality) {
|
|
13
|
-
throw new Error(`Unknown relation type: ${relation.type}`);
|
|
14
|
-
}
|
|
15
|
-
return ` ${relation.fromModel} ${cardinality} ${relation.toModel} : "(${relation.fromField}) - (${relation.toField})"`;
|
|
16
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Config } from '..';
|
|
2
|
-
import type { ERContent } from '../type';
|
|
3
|
-
/**
|
|
4
|
-
* Output the ER content to a file
|
|
5
|
-
* @param content - The ER content
|
|
6
|
-
* @param config - The configuration
|
|
7
|
-
*/
|
|
8
|
-
export declare function OutputFile(content: ERContent, config: Config): void;
|
|
@@ -1,24 +0,0 @@
|
|
|
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.OutputFile = OutputFile;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
/**
|
|
9
|
-
* Output the ER content to a file
|
|
10
|
-
* @param content - The ER content
|
|
11
|
-
* @param config - The configuration
|
|
12
|
-
*/
|
|
13
|
-
function OutputFile(content, config) {
|
|
14
|
-
const outputDir = config.output;
|
|
15
|
-
if (!outputDir) {
|
|
16
|
-
throw new Error('output is required');
|
|
17
|
-
}
|
|
18
|
-
if (!node_fs_1.default.existsSync(outputDir)) {
|
|
19
|
-
node_fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
const file = config.file ?? 'ER.md';
|
|
22
|
-
const filePath = `${outputDir}/${file}`;
|
|
23
|
-
node_fs_1.default.writeFileSync(filePath, content.join('\n'), { encoding: 'utf-8' });
|
|
24
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotInferInput = generateValibotInferInput;
|
|
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 the infer input type for the model
|
|
8
|
-
* @param modelName - The name of the model
|
|
9
|
-
* @param config - The configuration for the generator
|
|
10
|
-
* @returns The generated infer input type
|
|
11
|
-
*/
|
|
12
|
-
function generateValibotInferInput(modelName, config) {
|
|
13
|
-
const typeName = (0, get_variable_name_helper_1.getVariableNameHelper)(modelName, config);
|
|
14
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(modelName, config);
|
|
15
|
-
return `export type ${typeName} = v.InferInput<typeof ${schemaName}>`;
|
|
16
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Config } from '..';
|
|
2
|
-
/**
|
|
3
|
-
* Generate Valibot 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 Valibot schema
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateValibotSchema(modelName: string, fields: string, config: Config): string;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotSchema = generateValibotSchema;
|
|
4
|
-
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
5
|
-
/**
|
|
6
|
-
* Generate Valibot 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 Valibot schema
|
|
11
|
-
*/
|
|
12
|
-
function generateValibotSchema(modelName, fields, config) {
|
|
13
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(modelName, config);
|
|
14
|
-
return `export const ${schemaName} = v.object({\n${fields}\n})`;
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotSchemas = generateValibotSchemas;
|
|
4
|
-
const generate_valibot_properties_1 = require("./generate-valibot-properties");
|
|
5
|
-
const generate_valibot_schema_1 = require("./generate-valibot-schema");
|
|
6
|
-
/**
|
|
7
|
-
* generate valibot schemas
|
|
8
|
-
* @function generateValibotSchemas
|
|
9
|
-
* @param modelFields
|
|
10
|
-
* @param config
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
function generateValibotSchemas(modelFields, config) {
|
|
14
|
-
const modelName = modelFields[0].modelName;
|
|
15
|
-
const modelDoc = modelFields[0].documentation || '';
|
|
16
|
-
const fields = (0, generate_valibot_properties_1.generateValibotProperties)(modelFields, config);
|
|
17
|
-
if (!(modelDoc || !config?.comment)) {
|
|
18
|
-
return (0, generate_valibot_schema_1.generateValibotSchema)(modelName, fields, config);
|
|
19
|
-
}
|
|
20
|
-
return `${(0, generate_valibot_schema_1.generateValibotSchema)(modelName, fields, config)}`;
|
|
21
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Config } from '..';
|
|
2
|
-
import type { Model } from '../../../common/type';
|
|
3
|
-
/**
|
|
4
|
-
* Generate Valibot schemas and types
|
|
5
|
-
* @param models - The models to generate the Valibot schemas and types for
|
|
6
|
-
* @param config - The configuration for the generator
|
|
7
|
-
* @returns The generated Valibot schemas and types
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateValibot(models: readonly Model[], config: Config): string;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibot = generateValibot;
|
|
4
|
-
const is_valibot_documentation_1 = require("../validator/is-valibot-documentation");
|
|
5
|
-
const is_valibot_validation_1 = require("../validator/is-valibot-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_valibot_schemas_1 = require("./generate-valibot-schemas");
|
|
9
|
-
const generate_valibot_infer_input_1 = require("./generate-valibot-infer-input");
|
|
10
|
-
const VALIBOT_IMPORT = `import * as v from 'valibot'\n`;
|
|
11
|
-
/**
|
|
12
|
-
* Generate Valibot schemas and types
|
|
13
|
-
* @param models - The models to generate the Valibot schemas and types for
|
|
14
|
-
* @param config - The configuration for the generator
|
|
15
|
-
* @returns The generated Valibot schemas and types
|
|
16
|
-
*/
|
|
17
|
-
function generateValibot(models, config) {
|
|
18
|
-
const modelInfos = models.map((model) => {
|
|
19
|
-
return {
|
|
20
|
-
documentation: model.documentation ?? '',
|
|
21
|
-
name: model.name,
|
|
22
|
-
fields: model.fields,
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
const modelFields = modelInfos.map((model) => {
|
|
26
|
-
const fields = model.fields.map((field) => ({
|
|
27
|
-
documentation: model.documentation,
|
|
28
|
-
modelName: model.name,
|
|
29
|
-
fieldName: field.name,
|
|
30
|
-
comment: (0, is_valibot_documentation_1.isValibotDocumentValidation)(field.documentation),
|
|
31
|
-
validation: (0, is_valibot_validation_1.isValibotValidation)(field.documentation),
|
|
32
|
-
}));
|
|
33
|
-
return fields;
|
|
34
|
-
});
|
|
35
|
-
// null exclude
|
|
36
|
-
const validFields = (0, is_fields_validation_1.isFieldsValidation)(modelFields);
|
|
37
|
-
// group by model
|
|
38
|
-
const groupedByModel = (0, group_by_model_helper_1.groupByModelHelper)(validFields);
|
|
39
|
-
const valibots = Object.values(groupedByModel).map((fields) => {
|
|
40
|
-
return {
|
|
41
|
-
generateValibotSchema: (0, generate_valibot_schemas_1.generateValibotSchemas)(fields, config),
|
|
42
|
-
generateValibotInfer: config.type === 'true' ? (0, generate_valibot_infer_input_1.generateValibotInferInput)(fields[0].modelName, config) : '',
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
return [
|
|
46
|
-
VALIBOT_IMPORT,
|
|
47
|
-
'',
|
|
48
|
-
valibots
|
|
49
|
-
.flatMap(({ generateValibotSchema, generateValibotInfer }) => [generateValibotSchema, generateValibotInfer].filter(Boolean))
|
|
50
|
-
.join('\n\n'),
|
|
51
|
-
].join('\n');
|
|
52
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValibotDocumentValidation(documentation?: string): string[];
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|