hekireki 0.0.6 → 0.0.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.
Files changed (85) hide show
  1. package/dist/common/format/index.js +1 -1
  2. package/dist/common/helper/get-variable-name-helper.d.ts +1 -1
  3. package/dist/common/helper/get-variable-name-helper.js +1 -3
  4. package/dist/common/helper/get-variable-schema-name-helper.d.ts +1 -1
  5. package/dist/common/helper/get-variable-schema-name-helper.js +1 -1
  6. package/dist/common/helper/group-by-model-helper.d.ts +1 -1
  7. package/dist/common/type/index.d.ts +2 -2
  8. package/dist/common/validator/is-fields-validation.d.ts +1 -1
  9. package/dist/common/validator/is-fields-validation.js +1 -3
  10. package/dist/generator/mermaid/generator/generate-er-content.d.ts +4 -5
  11. package/dist/generator/mermaid/generator/generate-er-content.js +2 -3
  12. package/dist/generator/mermaid/generator/generate-model-fields.d.ts +4 -5
  13. package/dist/generator/mermaid/generator/generate-model-fields.js +9 -11
  14. package/dist/generator/mermaid/generator/generate-model-info.d.ts +2 -2
  15. package/dist/generator/mermaid/generator/generate-model-info.js +1 -5
  16. package/dist/generator/mermaid/generator/generate-relation-line.d.ts +2 -2
  17. package/dist/generator/mermaid/generator/generate-relation-line.js +2 -2
  18. package/dist/generator/mermaid/index.d.ts +7 -9
  19. package/dist/generator/mermaid/index.js +8 -37
  20. package/dist/generator/mermaid/output/index.d.ts +3 -3
  21. package/dist/generator/mermaid/output/index.js +3 -3
  22. package/dist/generator/mermaid/relationship/build-relation-line.d.ts +14 -0
  23. package/dist/generator/mermaid/relationship/build-relation-line.js +37 -0
  24. package/dist/generator/mermaid/relationship/index.d.ts +12 -0
  25. package/dist/generator/mermaid/relationship/index.js +30 -0
  26. package/dist/generator/mermaid/type/index.d.ts +9 -10
  27. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +1 -1
  28. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +1 -1
  29. package/dist/generator/mermaid/validator/extract-relations.d.ts +2 -2
  30. package/dist/generator/mermaid/validator/extract-relations.js +1 -1
  31. package/dist/generator/mermaid/validator/is-relation.d.ts +2 -2
  32. package/dist/generator/mermaid/validator/is-relationship.d.ts +7 -0
  33. package/dist/generator/mermaid/validator/is-relationship.js +11 -0
  34. package/dist/generator/mermaid/validator/parse-relation.d.ts +2 -2
  35. package/dist/generator/mermaid/validator/parse-relation.js +0 -4
  36. package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +1 -1
  37. package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +7 -0
  38. package/dist/generator/mermaid-er/generator/generate-er-content.js +22 -0
  39. package/dist/generator/mermaid-er/generator/generate-model-fields.d.ts +7 -0
  40. package/dist/generator/mermaid-er/generator/generate-model-fields.js +27 -0
  41. package/dist/generator/mermaid-er/generator/generate-model-info.d.ts +8 -0
  42. package/dist/generator/mermaid-er/generator/generate-model-info.js +13 -0
  43. package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +7 -0
  44. package/dist/generator/mermaid-er/generator/generate-relation-line.js +16 -0
  45. package/dist/generator/mermaid-er/index.d.ts +9 -0
  46. package/dist/generator/mermaid-er/index.js +39 -0
  47. package/dist/generator/mermaid-er/output/index.d.ts +8 -0
  48. package/dist/generator/mermaid-er/output/index.js +24 -0
  49. package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +14 -0
  50. package/dist/generator/mermaid-er/relationship/build-relation-line.js +37 -0
  51. package/dist/generator/mermaid-er/type/index.d.ts +10 -0
  52. package/dist/generator/mermaid-er/type/index.js +2 -0
  53. package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.d.ts +7 -0
  54. package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +12 -0
  55. package/dist/generator/mermaid-er/validator/extract-relations.d.ts +7 -0
  56. package/dist/generator/mermaid-er/validator/extract-relations.js +25 -0
  57. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +7 -0
  58. package/dist/generator/mermaid-er/validator/is-relationship.js +11 -0
  59. package/dist/generator/mermaid-er/validator/parse-relation.d.ts +8 -0
  60. package/dist/generator/mermaid-er/validator/parse-relation.js +24 -0
  61. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +6 -0
  62. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +11 -0
  63. package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +1 -1
  64. package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +1 -1
  65. package/dist/generator/valibot/generator/generate-valibot-properties.js +4 -6
  66. package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +1 -1
  67. package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +1 -1
  68. package/dist/generator/valibot/generator/generate-valibot-schemas.js +1 -1
  69. package/dist/generator/valibot/generator/generate-valibot.d.ts +2 -2
  70. package/dist/generator/valibot/generator/generate-valibot.js +5 -7
  71. package/dist/generator/valibot/index.d.ts +3 -3
  72. package/dist/generator/valibot/index.js +10 -10
  73. package/dist/generator/valibot/validator/is-valibot-documentation.js +2 -2
  74. package/dist/generator/zod/generator/generate-zod-infer.d.ts +1 -1
  75. package/dist/generator/zod/generator/generate-zod-properties.d.ts +1 -1
  76. package/dist/generator/zod/generator/generate-zod-properties.js +4 -6
  77. package/dist/generator/zod/generator/generate-zod-schema.d.ts +1 -1
  78. package/dist/generator/zod/generator/generate-zod-schemas.d.ts +1 -1
  79. package/dist/generator/zod/generator/generate-zod-schemas.js +1 -1
  80. package/dist/generator/zod/generator/generate-zod.d.ts +2 -2
  81. package/dist/generator/zod/generator/generate-zod.js +5 -7
  82. package/dist/generator/zod/index.d.ts +3 -3
  83. package/dist/generator/zod/index.js +10 -10
  84. package/dist/generator/zod/validator/is-zod-documentation.js +2 -2
  85. package/package.json +54 -54
@@ -4,7 +4,7 @@ exports.formatCode = formatCode;
4
4
  const prettier_1 = require("prettier");
5
5
  async function formatCode(code) {
6
6
  return await (0, prettier_1.format)(code, {
7
- parser: "typescript",
7
+ parser: 'typescript',
8
8
  printWidth: 100,
9
9
  singleQuote: true,
10
10
  semi: false,
@@ -1,4 +1,4 @@
1
- import type { Config } from "../../generator/zod";
1
+ import type { Config } from '../../generator/zod';
2
2
  /**
3
3
  * Generates a variable name based on the given name and configuration.
4
4
  *
@@ -11,7 +11,5 @@ const decapitalize_1 = require("../text/decapitalize");
11
11
  * @returns The variable name.
12
12
  */
13
13
  function getVariableNameHelper(name, config) {
14
- return config.typeName === "camelCase"
15
- ? (0, decapitalize_1.decapitalize)(name)
16
- : (0, capitalize_1.capitalize)(name);
14
+ return config.typeName === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
17
15
  }
@@ -1,4 +1,4 @@
1
- import type { Config } from "../../generator/zod";
1
+ import type { Config } from '../../generator/zod';
2
2
  /**
3
3
  * Generates a variable schema name based on the given name and configuration.
4
4
  *
@@ -11,7 +11,7 @@ const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-n
11
11
  * @returns The variable schema name.
12
12
  */
13
13
  function getVariableSchemaNameHelper(name, config) {
14
- return config.schemaName === "camelCase"
14
+ return config.schemaName === 'camelCase'
15
15
  ? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaNameHelper)(name)
16
16
  : (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaNameHelper)(name);
17
17
  }
@@ -1,4 +1,4 @@
1
- import type { GroupedFields, ValidField } from "../type";
1
+ import type { GroupedFields, ValidField } from '../type';
2
2
  /**
3
3
  * Groups valid fields by model name.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { DMMF } from "@prisma/generator-helper";
1
+ import type { DMMF } from '@prisma/generator-helper';
2
2
  export type Field = {
3
3
  documentation: string;
4
4
  modelName: string;
@@ -12,5 +12,5 @@ export type Model = Readonly<DMMF.Model>;
12
12
  export type ModelInfo = {
13
13
  documentation: string;
14
14
  name: string;
15
- fields: Model["fields"];
15
+ fields: Model['fields'];
16
16
  };
@@ -1,4 +1,4 @@
1
- import type { ReadonlyDeep } from "@prisma/generator-helper";
1
+ import type { ReadonlyDeep } from '@prisma/generator-helper';
2
2
  /**
3
3
  * Is fields validation
4
4
  * @param modelFields - The model fields
@@ -7,7 +7,5 @@ exports.isFieldsValidation = isFieldsValidation;
7
7
  * @returns The fields validation
8
8
  */
9
9
  function isFieldsValidation(modelFields) {
10
- return modelFields
11
- .flat()
12
- .filter((field) => field.validation !== null);
10
+ return modelFields.flat().filter((field) => field.validation !== null);
13
11
  }
@@ -1,8 +1,7 @@
1
- import type { ERContent, Model } from "../type";
1
+ import type { ERContent, Model } from '../type'
2
2
  /**
3
3
  * generate ER content
4
- * @function generateERContent
5
- * @param models
6
- * @returns ER content
4
+ * @param { readonly Model[] } models - models
5
+ * @returns { ERContent } - ER content
7
6
  */
8
- export declare function generateERContent(models: readonly Model[]): ERContent;
7
+ export declare function generateERContent(models: readonly Model[]): ERContent
@@ -7,9 +7,8 @@ const generate_model_info_1 = require("../generator/generate-model-info");
7
7
  const remove_duplicate_relations_1 = require("../validator/remove-duplicate-relations");
8
8
  /**
9
9
  * generate ER content
10
- * @function generateERContent
11
- * @param models
12
- * @returns ER content
10
+ * @param { readonly Model[] } models - models
11
+ * @returns { ERContent } - ER content
13
12
  */
14
13
  function generateERContent(models) {
15
14
  // extract all relations
@@ -1,8 +1,7 @@
1
- import type { DMMF } from "@prisma/generator-helper";
1
+ import type { DMMF } from '@prisma/generator-helper'
2
2
  /**
3
3
  * generate model fields
4
- * @function generateModelFields
5
- * @param model
6
- * @returns
4
+ * @param { DMMF.Model } model
5
+ * @returns { string[] }
7
6
  */
8
- export declare function generateModelFields(model: DMMF.Model): string[];
7
+ export declare function generateModelFields(model: DMMF.Model): string[]
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateModelFields = generateModelFields;
4
- const ZOD_ANNOTATION = "@z.";
5
- const VALIBOT_ANNOTATION = "@v.";
4
+ const ZOD_ANNOTATION = '@z.';
5
+ const VALIBOT_ANNOTATION = '@v.';
6
6
  /**
7
7
  * generate model fields
8
- * @function generateModelFields
9
- * @param model
10
- * @returns
8
+ * @param { DMMF.Model } model
9
+ * @returns { string[] }
11
10
  */
12
11
  function generateModelFields(model) {
13
12
  return model.fields
@@ -17,13 +16,12 @@ function generateModelFields(model) {
17
16
  }
18
17
  const commentPart = field.documentation
19
18
  ? field.documentation
20
- .split("\n")
21
- .filter((line) => !(line.includes(ZOD_ANNOTATION) ||
22
- line.includes(VALIBOT_ANNOTATION)))
23
- .join("\n")
19
+ .split('\n')
20
+ .filter((line) => !(line.includes(ZOD_ANNOTATION) || line.includes(VALIBOT_ANNOTATION)))
21
+ .join('\n')
24
22
  .trim()
25
- : "";
26
- return ` ${field.type} ${field.name} ${commentPart ? `"${commentPart}"` : ""}`;
23
+ : '';
24
+ return ` ${field.type} ${field.name} ${commentPart ? `"${commentPart}"` : ''}`;
27
25
  })
28
26
  .filter((field) => field !== null);
29
27
  }
@@ -1,8 +1,8 @@
1
- import type { Model } from "../type";
1
+ import type { Model } from '../type'
2
2
  /**
3
3
  * generate model info
4
4
  * @function generateModelInfo
5
5
  * @param model
6
6
  * @returns
7
7
  */
8
- export declare function generateModelInfo(model: Model): readonly string[];
8
+ export declare function generateModelInfo(model: Model): readonly string[]
@@ -9,9 +9,5 @@ const generate_model_fields_1 = require("./generate-model-fields");
9
9
  * @returns
10
10
  */
11
11
  function generateModelInfo(model) {
12
- return [
13
- ` ${model.name} {`,
14
- ...(0, generate_model_fields_1.generateModelFields)(model),
15
- " }",
16
- ];
12
+ return [` ${model.name} {`, ...(0, generate_model_fields_1.generateModelFields)(model), ' }'];
17
13
  }
@@ -1,7 +1,7 @@
1
- import type { Relation } from "../type";
1
+ import type { Relation } from '../type'
2
2
  /**
3
3
  * generate relation line
4
4
  * @param { Relation } relation
5
5
  * @returns { string } relation line
6
6
  */
7
- export declare function generateRelationLine(relation: Relation): string;
7
+ export declare function generateRelationLine(relation: Relation): string
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateRelationLine = generateRelationLine;
4
- const __1 = require("..");
4
+ const build_relation_line_1 = require("../relationship/build-relation-line");
5
5
  /**
6
6
  * generate relation line
7
7
  * @param { Relation } relation
8
8
  * @returns { string } relation line
9
9
  */
10
10
  function generateRelationLine(relation) {
11
- const cardinality = __1.CARDINALITY_MAP[relation.type];
11
+ const cardinality = (0, build_relation_line_1.buildRelationLine)(relation.type);
12
12
  if (!cardinality) {
13
13
  throw new Error(`Unknown relation type: ${relation.type}`);
14
14
  }
@@ -1,11 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import type { GeneratorOptions } from "@prisma/generator-helper";
3
- import type { RelationType } from "./type";
2
+ import type { GeneratorOptions } from '@prisma/generator-helper'
4
3
  export type Config = {
5
- output?: string;
6
- file?: string | string[];
7
- };
8
- export declare const CARDINALITY_MAP: Record<RelationType, string>;
9
- export declare const ER_HEADER: readonly ["```mermaid", "erDiagram"];
10
- export declare const ER_FOOTER: readonly ["```"];
11
- export declare function main(options: GeneratorOptions): Promise<void>;
4
+ output?: string
5
+ file?: string | string[]
6
+ }
7
+ export declare const ER_HEADER: readonly ['```mermaid', 'erDiagram']
8
+ export declare const ER_FOOTER: readonly ['```']
9
+ export declare function main(options: GeneratorOptions): Promise<void>
@@ -1,48 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ER_FOOTER = exports.ER_HEADER = exports.CARDINALITY_MAP = void 0;
4
+ exports.ER_FOOTER = exports.ER_HEADER = void 0;
5
5
  exports.main = main;
6
6
  const output_1 = require("./output");
7
7
  const generator_helper_1 = require("@prisma/generator-helper");
8
8
  const generate_er_content_1 = require("./generator/generate-er-content");
9
9
  const DEFAULT_CONFIG = {
10
- output: "./mermaid-er",
11
- file: "ER.md",
12
- };
13
- exports.CARDINALITY_MAP = {
14
- // Required Relationships
15
- "one-to-one": "||--||", // 1 --- 1
16
- "one-to-many": "||--|{", // 1 --- 0..*
17
- "many-to-one": "}|--||", // * --- 1
18
- "many-to-many": "}|--|{", // * --- *
19
- "one-to-zero-one": "||--o|", // 1 --- 0..1
20
- "zero-one-to-one": "o|--||", // 0..1 --- 1
21
- "zero-to-one": "o|--o|", // 0..1 --- 0..1
22
- "zero-to-zero-one": "o|--o|", // Alias for zero-to-one
23
- "zero-to-many": "o|--o{", // 0..1 --- 0..*
24
- "zero-one-to-many": "o|--o{", // 0..1 --- *
25
- "many-to-zero-one": "}|--o|", // * --- 0..1
26
- // Optional Relationships (dotted lines)
27
- "one-to-one-optional": "||..||", // 1 --- 1 optional
28
- "one-to-many-optional": "||..o{", // 1 --- 0..* optional
29
- "many-to-one-optional": "}|..||", // * --- 1 optional
30
- "many-to-many-optional": "}|..o{", // * --- 0..* optional
31
- "one-to-zero-one-optional": "||..o|", // 1 --- 0..1 optional
32
- "zero-one-to-one-optional": "o|..||", // 0..1 --- 1 optional
33
- "zero-to-one-optional": "o|..o|", // 0..1 --- 0..1 optional
34
- "zero-to-many-optional": "o|..o{", // 0..1 --- 0..* optional
35
- "zero-one-to-many-optional": "o|..o{", // 0..1 --- * optional
36
- "many-to-zero-one-optional": "}|..o|", // * --- 0..1 optional
37
- // Nuanced Patterns (Aliases)
38
- "many-to-zero-many": "}|..o{", // * --- 0..*
39
- "zero-many-to-many": "o{--|{", // 0..* --- *
40
- "zero-many-to-zero-many": "o{--o{", // 0..* --- 0..*
10
+ output: './mermaid-er',
11
+ file: 'ER.md',
41
12
  };
42
13
  // ER diagram header
43
- exports.ER_HEADER = ["```mermaid", "erDiagram"];
14
+ exports.ER_HEADER = ['```mermaid', 'erDiagram'];
44
15
  // ER diagram footer
45
- exports.ER_FOOTER = ["```"];
16
+ exports.ER_FOOTER = ['```'];
46
17
  // main function
47
18
  async function main(options) {
48
19
  const config = {
@@ -52,7 +23,7 @@ async function main(options) {
52
23
  const models = options.dmmf.datamodel.models;
53
24
  const content = (0, generate_er_content_1.generateERContent)(models);
54
25
  if (!config.output) {
55
- throw new Error("output is required");
26
+ throw new Error('output is required');
56
27
  }
57
28
  (0, output_1.OutputFile)(content, config);
58
29
  }
@@ -60,8 +31,8 @@ async function main(options) {
60
31
  (0, generator_helper_1.generatorHandler)({
61
32
  onManifest() {
62
33
  return {
63
- defaultOutput: "./mermaid-er",
64
- prettyName: "ekireki-ER",
34
+ defaultOutput: './mermaid-er',
35
+ prettyName: 'Hekireki-ER',
65
36
  };
66
37
  },
67
38
  onGenerate: main,
@@ -1,8 +1,8 @@
1
- import type { Config } from "..";
2
- import type { ERContent } from "../type";
1
+ import type { Config } from '..'
2
+ import type { ERContent } from '../type'
3
3
  /**
4
4
  * Output the ER content to a file
5
5
  * @param content - The ER content
6
6
  * @param config - The configuration
7
7
  */
8
- export declare function OutputFile(content: ERContent, config: Config): void;
8
+ export declare function OutputFile(content: ERContent, config: Config): void
@@ -13,12 +13,12 @@ const node_fs_1 = __importDefault(require("node:fs"));
13
13
  function OutputFile(content, config) {
14
14
  const outputDir = config.output;
15
15
  if (!outputDir) {
16
- throw new Error("output is required");
16
+ throw new Error('output is required');
17
17
  }
18
18
  if (!node_fs_1.default.existsSync(outputDir)) {
19
19
  node_fs_1.default.mkdirSync(outputDir, { recursive: true });
20
20
  }
21
- const file = config.file ?? "ER.md";
21
+ const file = config.file ?? 'ER.md';
22
22
  const filePath = `${outputDir}/${file}`;
23
- node_fs_1.default.writeFileSync(filePath, content.join("\n"), { encoding: "utf-8" });
23
+ node_fs_1.default.writeFileSync(filePath, content.join('\n'), { encoding: 'utf-8' });
24
24
  }
@@ -0,0 +1,14 @@
1
+ declare const RELATIONSHIPS: {
2
+ readonly 'zero-one': '|o'
3
+ readonly one: '||'
4
+ readonly 'zero-many': '}o'
5
+ readonly many: '}|'
6
+ }
7
+ export type Relationship = keyof typeof RELATIONSHIPS
8
+ /**
9
+ * Builds a relationship line for mermaid from a string.
10
+ * @param { string } input
11
+ * @returns { string }
12
+ */
13
+ export declare function buildRelationLine(input: string): string
14
+ export {}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRelationLine = buildRelationLine;
4
+ const is_relationship_1 = require("../validator/is-relationship");
5
+ const RELATIONSHIPS = {
6
+ 'zero-one': '|o',
7
+ one: '||',
8
+ 'zero-many': '}o',
9
+ many: '}|',
10
+ };
11
+ /**
12
+ * Builds a relationship line for mermaid from a string.
13
+ * @param { string } input
14
+ * @returns { string }
15
+ */
16
+ function buildRelationLine(input) {
17
+ const parts = input.split('-to-');
18
+ if (parts.length !== 2) {
19
+ throw new Error(`Invalid input format: ${input}`);
20
+ }
21
+ const [toRaw, optionalFlag] = parts[1].includes('-optional')
22
+ ? [parts[1].replace('-optional', ''), 'optional']
23
+ : [parts[1], ''];
24
+ const from = parts[0];
25
+ const to = toRaw;
26
+ const isOptional = optionalFlag === 'optional';
27
+ if (!((0, is_relationship_1.isRelationship)(from) && (0, is_relationship_1.isRelationship)(to))) {
28
+ throw new Error(`Invalid relationship string: ${input}`);
29
+ }
30
+ const fromSymbol = RELATIONSHIPS[from];
31
+ const toSymbol = RELATIONSHIPS[to];
32
+ if (!(fromSymbol && toSymbol)) {
33
+ throw new Error(`Invalid relationship string: ${input}`);
34
+ }
35
+ const connector = isOptional ? '..' : '--';
36
+ return `${fromSymbol}${connector}${toSymbol}`;
37
+ }
@@ -0,0 +1,12 @@
1
+ export declare const RELATION_SHIPS: {
2
+ readonly 'zero-one': '|o'
3
+ readonly one: '||'
4
+ readonly 'zero-many': '|o{'
5
+ readonly many: '|{'
6
+ }
7
+ /**
8
+ * Builds a relationship line for mermaid from a string.
9
+ * @param { string } input
10
+ * @returns { string }
11
+ */
12
+ export declare function buildRelationLine(input: string): string
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RELATION_SHIPS = void 0;
4
+ exports.buildRelationLine = buildRelationLine;
5
+ exports.RELATION_SHIPS = {
6
+ 'zero-one': '|o',
7
+ one: '||',
8
+ 'zero-many': '|o{',
9
+ many: '|{',
10
+ };
11
+ /**
12
+ * Builds a relationship line for mermaid from a string.
13
+ * @param { string } input
14
+ * @returns { string }
15
+ */
16
+ function buildRelationLine(input) {
17
+ console.log(input);
18
+ const parts = input.split('-to-');
19
+ const toParts = parts[1].split('-');
20
+ const from = parts[0];
21
+ const to = toParts[0];
22
+ const isOptional = toParts.includes('optional');
23
+ const fromSymbol = exports.RELATION_SHIPS[from];
24
+ const toSymbol = exports.RELATION_SHIPS[to];
25
+ if (!(fromSymbol || !toSymbol)) {
26
+ throw new Error(`Invalid relationship string: ${input}`);
27
+ }
28
+ const connector = isOptional ? '..' : '--';
29
+ return `${fromSymbol}${connector}${toSymbol}`;
30
+ }
@@ -1,11 +1,10 @@
1
- import type { DMMF } from "@prisma/generator-helper";
2
- export type RelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many" | "one-to-zero-one" | "zero-one-to-one" | "zero-to-one" | "zero-to-zero-one" | "zero-to-many" | "zero-one-to-many" | "many-to-zero-one" | "one-to-one-optional" | "one-to-many-optional" | "many-to-one-optional" | "many-to-many-optional" | "one-to-zero-one-optional" | "zero-one-to-one-optional" | "zero-to-one-optional" | "zero-to-many-optional" | "zero-one-to-many-optional" | "many-to-zero-one-optional" | "many-to-zero-many" | "zero-many-to-many" | "zero-many-to-zero-many";
1
+ import type { DMMF } from '@prisma/generator-helper'
3
2
  export type Relation = {
4
- fromModel: string;
5
- toModel: string;
6
- fromField: string;
7
- toField: string;
8
- type: RelationType;
9
- };
10
- export type Model = Readonly<DMMF.Model>;
11
- export type ERContent = readonly string[];
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[]
@@ -4,4 +4,4 @@
4
4
  * @param relations
5
5
  * @returns
6
6
  */
7
- export declare function excludeManyToOneRelations(relations: readonly string[]): readonly string[];
7
+ export declare function excludeManyToOneRelations(relations: readonly string[]): readonly string[]
@@ -8,5 +8,5 @@ exports.excludeManyToOneRelations = excludeManyToOneRelations;
8
8
  * @returns
9
9
  */
10
10
  function excludeManyToOneRelations(relations) {
11
- return [...new Set(relations)].filter((r) => !r.includes("many-to-one"));
11
+ return [...new Set(relations)].filter((r) => !r.includes('many-to-one'));
12
12
  }
@@ -1,7 +1,7 @@
1
- import type { Model } from "../type";
1
+ import type { Model } from '../type'
2
2
  /**
3
3
  * extract relations from model
4
4
  * @param { Model } model
5
5
  * @returns { readonly string[] }
6
6
  */
7
- export declare function extractRelations(model: Model): readonly string[];
7
+ export declare function extractRelations(model: Model): readonly string[]
@@ -13,7 +13,7 @@ function extractRelations(model) {
13
13
  // @relation annotation
14
14
  if (model.documentation) {
15
15
  const annotationRelations = model.documentation
16
- .split("\n")
16
+ .split('\n')
17
17
  .map((line) => {
18
18
  const relation = (0, parse_relation_1.parseRelation)(line);
19
19
  return relation ? (0, generate_relation_line_1.generateRelationLine)(relation) : null;
@@ -1,7 +1,7 @@
1
- import type { RelationType } from "../type";
1
+ import type { RelationType } from '../type'
2
2
  /**
3
3
  * check if the value is a valid relation
4
4
  * @param { unknown } value
5
5
  * @returns { boolean }
6
6
  */
7
- export declare function isRelation(value: unknown): value is RelationType;
7
+ export declare function isRelation(value: unknown): value is RelationType
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRelationship = isRelationship;
4
+ /**
5
+ * isRelationship
6
+ * @param { string } key
7
+ * @returns { key is Relationship }
8
+ */
9
+ function isRelationship(key) {
10
+ return ['zero-one', 'one', 'zero-many', 'many'].includes(key);
11
+ }
@@ -1,8 +1,8 @@
1
- import type { Relation } from "../type";
1
+ import type { Relation } from '../type'
2
2
  /**
3
3
  * parse relation
4
4
  * @function parseRelation
5
5
  * @param line
6
6
  * @returns
7
7
  */
8
- export declare function parseRelation(line: string): Relation | null;
8
+ export declare function parseRelation(line: string): Relation | null
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseRelation = parseRelation;
4
- const is_relation_1 = require("./is-relation");
5
4
  /**
6
5
  * parse relation
7
6
  * @function parseRelation
@@ -15,9 +14,6 @@ function parseRelation(line) {
15
14
  return null;
16
15
  }
17
16
  const [, fromModel, fromField, toModel, toField, relationType] = match;
18
- if (!(0, is_relation_1.isRelation)(relationType)) {
19
- return null;
20
- }
21
17
  return {
22
18
  fromModel,
23
19
  fromField,
@@ -3,4 +3,4 @@
3
3
  * @param { readonly string[] } relations
4
4
  * @returns { readonly string[] }
5
5
  */
6
- export declare function removeDuplicateRelations(relations: readonly string[]): readonly string[];
6
+ export declare function removeDuplicateRelations(relations: readonly string[]): readonly string[]
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ import type { DMMF } from '@prisma/generator-helper';
2
+ /**
3
+ * generate model fields
4
+ * @param { DMMF.Model } model
5
+ * @returns { string[] }
6
+ */
7
+ export declare function generateModelFields(model: DMMF.Model): string[];
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateModelFields = generateModelFields;
4
+ const ZOD_ANNOTATION = '@z.';
5
+ const VALIBOT_ANNOTATION = '@v.';
6
+ /**
7
+ * generate model fields
8
+ * @param { DMMF.Model } model
9
+ * @returns { string[] }
10
+ */
11
+ function generateModelFields(model) {
12
+ return model.fields
13
+ .map((field) => {
14
+ if (field.relationName) {
15
+ return null;
16
+ }
17
+ const commentPart = field.documentation
18
+ ? field.documentation
19
+ .split('\n')
20
+ .filter((line) => !(line.includes(ZOD_ANNOTATION) || line.includes(VALIBOT_ANNOTATION)))
21
+ .join('\n')
22
+ .trim()
23
+ : '';
24
+ return ` ${field.type} ${field.name} ${commentPart ? `"${commentPart}"` : ''}`;
25
+ })
26
+ .filter((field) => field !== null);
27
+ }