hekireki 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +71 -214
  2. package/dist/generator/mermaid-er/generator/er-content.d.ts +2 -0
  3. package/dist/generator/mermaid-er/generator/er-content.js +21 -0
  4. package/dist/generator/mermaid-er/generator/index.d.ts +4 -0
  5. package/dist/generator/mermaid-er/generator/index.js +4 -0
  6. package/dist/generator/mermaid-er/generator/{generate-model-fields.d.ts → model-fields.d.ts} +1 -1
  7. package/dist/generator/mermaid-er/generator/{generate-model-fields.js → model-fields.js} +1 -4
  8. package/dist/generator/mermaid-er/generator/model-info.d.ts +7 -0
  9. package/dist/generator/mermaid-er/generator/model-info.js +9 -0
  10. package/dist/generator/mermaid-er/generator/relation-line.d.ts +7 -0
  11. package/dist/generator/mermaid-er/generator/relation-line.js +13 -0
  12. package/dist/generator/mermaid-er/index.d.ts +0 -6
  13. package/dist/generator/mermaid-er/index.js +11 -28
  14. package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -5
  15. package/dist/generator/mermaid-er/relationship/build-relation-line.js +7 -15
  16. package/dist/generator/mermaid-er/types.js +1 -0
  17. package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +1 -4
  18. package/dist/generator/mermaid-er/validator/extract-relations.d.ts +1 -1
  19. package/dist/generator/mermaid-er/validator/extract-relations.js +5 -8
  20. package/dist/generator/mermaid-er/validator/index.d.ts +5 -0
  21. package/dist/generator/mermaid-er/validator/index.js +5 -0
  22. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +1 -1
  23. package/dist/generator/mermaid-er/validator/is-relationship.js +1 -4
  24. package/dist/generator/mermaid-er/validator/parse-relation.d.ts +1 -1
  25. package/dist/generator/mermaid-er/validator/parse-relation.js +1 -4
  26. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
  27. package/dist/generator/valibot/generator/index.d.ts +5 -0
  28. package/dist/generator/valibot/generator/index.js +5 -0
  29. package/dist/generator/valibot/generator/{generate-valibot-infer-input.d.ts → infer-input.d.ts} +1 -2
  30. package/dist/generator/valibot/generator/infer-input.js +9 -0
  31. package/dist/generator/valibot/generator/properties.d.ts +7 -0
  32. package/dist/generator/valibot/generator/{generate-valibot-properties.js → properties.js} +2 -5
  33. package/dist/generator/valibot/generator/schema.d.ts +7 -0
  34. package/dist/generator/valibot/generator/schema.js +9 -0
  35. package/dist/generator/valibot/generator/{generate-valibot-schemas.d.ts → schemas.d.ts} +2 -4
  36. package/dist/generator/valibot/generator/schemas.js +17 -0
  37. package/dist/generator/valibot/generator/valibot.d.ts +9 -0
  38. package/dist/generator/valibot/generator/valibot.js +50 -0
  39. package/dist/generator/valibot/index.d.ts +0 -8
  40. package/dist/generator/valibot/index.js +13 -44
  41. package/dist/generator/valibot/validator/index.d.ts +2 -0
  42. package/dist/generator/valibot/validator/index.js +2 -0
  43. package/dist/generator/valibot/validator/is-valibot-document.d.ts +1 -0
  44. package/dist/generator/valibot/validator/{is-valibot-documentation.js → is-valibot-document.js} +1 -4
  45. package/dist/generator/valibot/validator/is-valibot.d.ts +6 -0
  46. package/dist/generator/valibot/validator/{is-valibot-validation.js → is-valibot.js} +1 -5
  47. package/dist/generator/zod/generator/index.d.ts +5 -0
  48. package/dist/generator/zod/generator/index.js +5 -0
  49. package/dist/generator/zod/generator/{generate-zod-infer.d.ts → infer.d.ts} +1 -2
  50. package/dist/generator/zod/generator/infer.js +9 -0
  51. package/dist/generator/zod/generator/{generate-zod-properties.d.ts → properties.d.ts} +2 -3
  52. package/dist/generator/zod/generator/{generate-zod-properties.js → properties.js} +2 -5
  53. package/dist/generator/zod/generator/{generate-zod-schema.d.ts → schema.d.ts} +1 -2
  54. package/dist/generator/zod/generator/schema.js +10 -0
  55. package/dist/generator/zod/generator/{generate-zod-schemas.d.ts → schemas.d.ts} +2 -3
  56. package/dist/generator/zod/generator/schemas.js +16 -0
  57. package/dist/generator/zod/generator/zod.d.ts +9 -0
  58. package/dist/generator/zod/generator/zod.js +55 -0
  59. package/dist/generator/zod/index.d.ts +0 -8
  60. package/dist/generator/zod/index.js +14 -44
  61. package/dist/generator/zod/validator/index.d.ts +2 -0
  62. package/dist/generator/zod/validator/index.js +2 -0
  63. package/dist/generator/zod/validator/{is-zod-documentation.d.ts → is-zod-document.d.ts} +1 -1
  64. package/dist/generator/zod/validator/{is-zod-documentation.js → is-zod-document.js} +1 -4
  65. package/dist/generator/zod/validator/{is-zod-validation.d.ts → is-zod.d.ts} +1 -1
  66. package/dist/generator/zod/validator/{is-zod-validation.js → is-zod.js} +1 -4
  67. package/dist/shared/format/index.d.ts +1 -0
  68. package/dist/shared/format/index.js +9 -0
  69. package/dist/shared/helper/group-by-model.d.ts +8 -0
  70. package/dist/{common/helper/group-by-model-helper.js → shared/helper/group-by-model.js} +1 -4
  71. package/dist/shared/types.js +1 -0
  72. package/dist/{common/text → shared/utils}/capitalize.d.ts +3 -5
  73. package/dist/{common/text → shared/utils}/capitalize.js +4 -9
  74. package/dist/shared/utils/index.d.ts +1 -0
  75. package/dist/shared/utils/index.js +1 -0
  76. package/dist/{common/validator/is-fields-validation.d.ts → shared/validator/is-fields.d.ts} +2 -2
  77. package/dist/{common/validator/is-fields-validation.js → shared/validator/is-fields.js} +1 -4
  78. package/package.json +12 -11
  79. package/dist/common/format/index.d.ts +0 -1
  80. package/dist/common/format/index.js +0 -12
  81. package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +0 -7
  82. package/dist/common/helper/get-camel-case-schema-name-helper.js +0 -14
  83. package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +0 -8
  84. package/dist/common/helper/get-pascal-case-schema-name-helper.js +0 -15
  85. package/dist/common/helper/get-variable-name-helper.d.ts +0 -9
  86. package/dist/common/helper/get-variable-name-helper.js +0 -15
  87. package/dist/common/helper/get-variable-schema-name-helper.d.ts +0 -9
  88. package/dist/common/helper/get-variable-schema-name-helper.js +0 -17
  89. package/dist/common/helper/group-by-model-helper.d.ts +0 -8
  90. package/dist/common/text/decapitalize.d.ts +0 -17
  91. package/dist/common/text/decapitalize.js +0 -22
  92. package/dist/common/type/index.js +0 -2
  93. package/dist/generator/mermaid/generator/generate-er-content.d.ts +0 -7
  94. package/dist/generator/mermaid/generator/generate-er-content.js +0 -22
  95. package/dist/generator/mermaid/generator/generate-model-fields.d.ts +0 -7
  96. package/dist/generator/mermaid/generator/generate-model-fields.js +0 -27
  97. package/dist/generator/mermaid/generator/generate-model-info.d.ts +0 -8
  98. package/dist/generator/mermaid/generator/generate-model-info.js +0 -13
  99. package/dist/generator/mermaid/generator/generate-relation-line.d.ts +0 -7
  100. package/dist/generator/mermaid/generator/generate-relation-line.js +0 -16
  101. package/dist/generator/mermaid/index.d.ts +0 -9
  102. package/dist/generator/mermaid/index.js +0 -39
  103. package/dist/generator/mermaid/output/index.d.ts +0 -8
  104. package/dist/generator/mermaid/output/index.js +0 -24
  105. package/dist/generator/mermaid/relationship/build-relation-line.d.ts +0 -14
  106. package/dist/generator/mermaid/relationship/build-relation-line.js +0 -37
  107. package/dist/generator/mermaid/relationship/index.d.ts +0 -12
  108. package/dist/generator/mermaid/relationship/index.js +0 -30
  109. package/dist/generator/mermaid/type/index.d.ts +0 -10
  110. package/dist/generator/mermaid/type/index.js +0 -2
  111. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +0 -7
  112. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +0 -12
  113. package/dist/generator/mermaid/validator/extract-relations.d.ts +0 -7
  114. package/dist/generator/mermaid/validator/extract-relations.js +0 -25
  115. package/dist/generator/mermaid/validator/is-relation.d.ts +0 -7
  116. package/dist/generator/mermaid/validator/is-relation.js +0 -37
  117. package/dist/generator/mermaid/validator/is-relationship.d.ts +0 -7
  118. package/dist/generator/mermaid/validator/is-relationship.js +0 -11
  119. package/dist/generator/mermaid/validator/parse-relation.d.ts +0 -8
  120. package/dist/generator/mermaid/validator/parse-relation.js +0 -24
  121. package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +0 -6
  122. package/dist/generator/mermaid/validator/remove-duplicate-relations.js +0 -11
  123. package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +0 -7
  124. package/dist/generator/mermaid-er/generator/generate-er-content.js +0 -22
  125. package/dist/generator/mermaid-er/generator/generate-model-info.d.ts +0 -8
  126. package/dist/generator/mermaid-er/generator/generate-model-info.js +0 -13
  127. package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +0 -7
  128. package/dist/generator/mermaid-er/generator/generate-relation-line.js +0 -16
  129. package/dist/generator/mermaid-er/output/index.d.ts +0 -8
  130. package/dist/generator/mermaid-er/output/index.js +0 -24
  131. package/dist/generator/mermaid-er/type/index.js +0 -2
  132. package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
  133. package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +0 -8
  134. package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
  135. package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -15
  136. package/dist/generator/valibot/generator/generate-valibot-schemas.js +0 -21
  137. package/dist/generator/valibot/generator/generate-valibot.d.ts +0 -9
  138. package/dist/generator/valibot/generator/generate-valibot.js +0 -52
  139. package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +0 -1
  140. package/dist/generator/valibot/validator/is-valibot-validation.d.ts +0 -7
  141. package/dist/generator/zod/generator/generate-zod-infer.js +0 -16
  142. package/dist/generator/zod/generator/generate-zod-schema.js +0 -15
  143. package/dist/generator/zod/generator/generate-zod-schemas.js +0 -20
  144. package/dist/generator/zod/generator/generate-zod.d.ts +0 -9
  145. package/dist/generator/zod/generator/generate-zod.js +0 -52
  146. /package/dist/generator/mermaid-er/{type/index.d.ts → types.d.ts} +0 -0
  147. /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,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- /**
2
- * exclude many-to-one relations
3
- * @function excludeManyToOneRelations
4
- * @param relations
5
- * @returns
6
- */
7
- export declare function excludeManyToOneRelations(relations: readonly string[]): 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,7 +0,0 @@
1
- import type { Model } from '../type'
2
- /**
3
- * extract relations from model
4
- * @param { Model } model
5
- * @returns { readonly string[] }
6
- */
7
- export declare function extractRelations(model: Model): readonly string[]
@@ -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,7 +0,0 @@
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
@@ -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,7 +0,0 @@
1
- import type { Relationship } from '../../mermaid/relationship/build-relation-line'
2
- /**
3
- * isRelationship
4
- * @param { string } key
5
- * @returns { key is Relationship }
6
- */
7
- export declare function isRelationship(key: string): key is Relationship
@@ -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,8 +0,0 @@
1
- import type { Relation } from '../type'
2
- /**
3
- * parse relation
4
- * @function parseRelation
5
- * @param line
6
- * @returns
7
- */
8
- export declare function parseRelation(line: string): Relation | null
@@ -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,6 +0,0 @@
1
- /**
2
- * remove duplicate relations
3
- * @param { readonly string[] } relations
4
- * @returns { readonly string[] }
5
- */
6
- export declare function removeDuplicateRelations(relations: readonly string[]): readonly string[]
@@ -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,7 +0,0 @@
1
- import type { ERContent, Model } from '../type';
2
- /**
3
- * generate ER content
4
- * @param { readonly Model[] } models - models
5
- * @returns { ERContent } - ER content
6
- */
7
- export declare function generateERContent(models: readonly Model[]): ERContent;
@@ -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,8 +0,0 @@
1
- import type { Model } from '../type';
2
- /**
3
- * generate model info
4
- * @function generateModelInfo
5
- * @param model
6
- * @returns
7
- */
8
- export declare function generateModelInfo(model: Model): readonly string[];
@@ -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,7 +0,0 @@
1
- import type { Relation } from '../type';
2
- /**
3
- * generate relation line
4
- * @param { Relation } relation
5
- * @returns { string } relation line
6
- */
7
- export declare function generateRelationLine(relation: Relation): string;
@@ -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,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,8 +0,0 @@
1
- import type { Config } from '..';
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;
@@ -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,7 +0,0 @@
1
- /**
2
- * Check if the documentation is a Valibot validation
3
- * @function isValibotValidation
4
- * @param documentation
5
- * @returns string | null
6
- */
7
- export declare function isValibotValidation(documentation?: string): string | null;
@@ -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
- }