hekireki 0.0.7 → 0.0.9

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 (41) hide show
  1. package/README.md +3 -3
  2. package/dist/generator/mermaid/generator/generate-er-content.d.ts +2 -2
  3. package/dist/generator/mermaid/generator/generate-model-fields.d.ts +2 -2
  4. package/dist/generator/mermaid/generator/generate-model-info.d.ts +2 -2
  5. package/dist/generator/mermaid/generator/generate-relation-line.d.ts +2 -2
  6. package/dist/generator/mermaid/index.d.ts +7 -7
  7. package/dist/generator/mermaid/output/index.d.ts +3 -3
  8. package/dist/generator/mermaid/relationship/build-relation-line.d.ts +8 -8
  9. package/dist/generator/mermaid/type/index.d.ts +9 -9
  10. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +1 -1
  11. package/dist/generator/mermaid/validator/extract-relations.d.ts +2 -2
  12. package/dist/generator/mermaid/validator/is-relationship.d.ts +2 -2
  13. package/dist/generator/mermaid/validator/parse-relation.d.ts +2 -2
  14. package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +1 -1
  15. package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +7 -0
  16. package/dist/generator/mermaid-er/generator/generate-er-content.js +22 -0
  17. package/dist/generator/mermaid-er/generator/generate-model-fields.d.ts +7 -0
  18. package/dist/generator/mermaid-er/generator/generate-model-fields.js +27 -0
  19. package/dist/generator/mermaid-er/generator/generate-model-info.d.ts +8 -0
  20. package/dist/generator/mermaid-er/generator/generate-model-info.js +13 -0
  21. package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +7 -0
  22. package/dist/generator/mermaid-er/generator/generate-relation-line.js +16 -0
  23. package/dist/generator/mermaid-er/index.d.ts +9 -0
  24. package/dist/generator/mermaid-er/index.js +39 -0
  25. package/dist/generator/mermaid-er/output/index.d.ts +8 -0
  26. package/dist/generator/mermaid-er/output/index.js +24 -0
  27. package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +14 -0
  28. package/dist/generator/mermaid-er/relationship/build-relation-line.js +37 -0
  29. package/dist/generator/mermaid-er/type/index.d.ts +10 -0
  30. package/dist/generator/mermaid-er/type/index.js +2 -0
  31. package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.d.ts +7 -0
  32. package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +12 -0
  33. package/dist/generator/mermaid-er/validator/extract-relations.d.ts +7 -0
  34. package/dist/generator/mermaid-er/validator/extract-relations.js +25 -0
  35. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +7 -0
  36. package/dist/generator/mermaid-er/validator/is-relationship.js +11 -0
  37. package/dist/generator/mermaid-er/validator/parse-relation.d.ts +8 -0
  38. package/dist/generator/mermaid-er/validator/parse-relation.js +24 -0
  39. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +6 -0
  40. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +11 -0
  41. package/package.json +2 -2
package/README.md CHANGED
@@ -294,9 +294,9 @@ export type Like = v.InferInput<typeof LikeSchema>
294
294
 
295
295
  ```mermaid
296
296
  erDiagram
297
- User ||--|{ Post : "(id) - (userId)"
298
- Post ||--|{ Like : "(id) - (postId)"
299
- User ||--|{ Like : "(id) - (userId)"
297
+ User ||--}| Post : "(id) - (userId)"
298
+ Post ||--}| Like : "(id) - (postId)"
299
+ User ||--}| Like : "(id) - (userId)"
300
300
  User {
301
301
  String id "Unique identifier for the user."
302
302
  String username "Username of the user."
@@ -1,7 +1,7 @@
1
- import type { ERContent, Model } from '../type';
1
+ import type { ERContent, Model } from '../type'
2
2
  /**
3
3
  * generate ER content
4
4
  * @param { readonly Model[] } models - models
5
5
  * @returns { ERContent } - ER content
6
6
  */
7
- export declare function generateERContent(models: readonly Model[]): ERContent;
7
+ export declare function generateERContent(models: readonly Model[]): ERContent
@@ -1,7 +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
4
  * @param { DMMF.Model } model
5
5
  * @returns { string[] }
6
6
  */
7
- export declare function generateModelFields(model: DMMF.Model): string[];
7
+ export declare function generateModelFields(model: DMMF.Model): string[]
@@ -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[]
@@ -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,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import type { GeneratorOptions } from '@prisma/generator-helper';
2
+ import type { GeneratorOptions } from '@prisma/generator-helper'
3
3
  export type Config = {
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>;
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,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
@@ -1,14 +1,14 @@
1
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;
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
8
  /**
9
9
  * Builds a relationship line for mermaid from a string.
10
10
  * @param { string } input
11
11
  * @returns { string }
12
12
  */
13
- export declare function buildRelationLine(input: string): string;
14
- export {};
13
+ export declare function buildRelationLine(input: string): string
14
+ export {}
@@ -1,10 +1,10 @@
1
- import type { DMMF } from '@prisma/generator-helper';
1
+ import type { DMMF } from '@prisma/generator-helper'
2
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[];
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[]
@@ -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[]
@@ -1,7 +1,7 @@
1
- import type { Relationship } from '../../mermaid/relationship/build-relation-line';
1
+ import type { Relationship } from '../../mermaid/relationship/build-relation-line'
2
2
  /**
3
3
  * isRelationship
4
4
  * @param { string } key
5
5
  * @returns { key is Relationship }
6
6
  */
7
- export declare function isRelationship(key: string): key is Relationship;
7
+ export declare function isRelationship(key: string): key is Relationship
@@ -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
@@ -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
+ }
@@ -0,0 +1,8 @@
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[];
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import type { GeneratorOptions } from '@prisma/generator-helper';
3
+ export type Config = {
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>;
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ER_FOOTER = exports.ER_HEADER = void 0;
5
+ exports.main = main;
6
+ const output_1 = require("./output");
7
+ const generator_helper_1 = require("@prisma/generator-helper");
8
+ const generate_er_content_1 = require("./generator/generate-er-content");
9
+ const DEFAULT_CONFIG = {
10
+ output: './mermaid-er',
11
+ file: 'ER.md',
12
+ };
13
+ // ER diagram header
14
+ exports.ER_HEADER = ['```mermaid', 'erDiagram'];
15
+ // ER diagram footer
16
+ exports.ER_FOOTER = ['```'];
17
+ // main function
18
+ async function main(options) {
19
+ const config = {
20
+ output: options.generator.output?.value ?? DEFAULT_CONFIG.output,
21
+ file: options.generator.config?.file ?? DEFAULT_CONFIG.file,
22
+ };
23
+ const models = options.dmmf.datamodel.models;
24
+ const content = (0, generate_er_content_1.generateERContent)(models);
25
+ if (!config.output) {
26
+ throw new Error('output is required');
27
+ }
28
+ (0, output_1.OutputFile)(content, config);
29
+ }
30
+ // prisma generator handler
31
+ (0, generator_helper_1.generatorHandler)({
32
+ onManifest() {
33
+ return {
34
+ defaultOutput: './mermaid-er',
35
+ prettyName: 'Hekireki-ER',
36
+ };
37
+ },
38
+ onGenerate: main,
39
+ });
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,24 @@
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
+ }
@@ -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,10 @@
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[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
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[];
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,7 @@
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[];
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ import type { Relationship } from '../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
+ }
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,6 @@
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[];
@@ -0,0 +1,11 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hekireki",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "description": "Hekireki is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Prisma schemas annotated with comments.",
6
6
  "keywords": [
@@ -28,7 +28,7 @@
28
28
  "bin": {
29
29
  "hekireki-zod": "dist/generator/zod/index.js",
30
30
  "hekireki-valibot": "dist/generator/valibot/index.js",
31
- "hekireki-mermaid-er": "dist/generator/mermaid/index.js"
31
+ "hekireki-mermaid-er": "dist/generator/mermaid-er/index.js"
32
32
  },
33
33
  "scripts": {
34
34
  "generate": "prisma generate",