sizuku 0.0.5 → 0.0.7
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 +3 -3
- package/dist/generator/mermaid-er/generator/generate-relation-line.js +2 -2
- package/dist/generator/mermaid-er/index.d.ts +0 -2
- package/dist/generator/mermaid-er/index.js +1 -30
- package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +14 -0
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +37 -0
- package/dist/generator/mermaid-er/type/index.d.ts +1 -2
- package/dist/generator/mermaid-er/validator/is-relation.d.ts +2 -2
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +7 -0
- package/dist/generator/mermaid-er/validator/is-relationship.js +11 -0
- package/dist/generator/mermaid-er/validator/parse-relation-line.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/parse-relation-line.js +0 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -290,9 +290,9 @@ output:
|
|
|
290
290
|
|
|
291
291
|
```mermaid
|
|
292
292
|
erDiagram
|
|
293
|
-
user
|
|
294
|
-
post
|
|
295
|
-
user
|
|
293
|
+
user ||--}| post : "(id) - (userId)"
|
|
294
|
+
post ||--}| likes : "(id) - (postId)"
|
|
295
|
+
user ||--}| likes : "(id) - (userId)"
|
|
296
296
|
user {
|
|
297
297
|
varchar id "(PK) Unique identifier for the user."
|
|
298
298
|
varchar username "Username of the user."
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRelationLine = generateRelationLine;
|
|
4
|
-
const
|
|
4
|
+
const build_relation_line_1 = require("../relationship/build-relation-line");
|
|
5
5
|
/**
|
|
6
6
|
* Generate a relation line for a relation
|
|
7
7
|
* @param relation - The relation to generate a line for
|
|
8
8
|
* @returns The generated relation line
|
|
9
9
|
*/
|
|
10
10
|
function generateRelationLine(relation) {
|
|
11
|
-
const cardinality =
|
|
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,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { Config } from './config';
|
|
3
|
-
import type { RelationType } from './type';
|
|
4
|
-
export declare const CARDINALITY_MAP: Record<RelationType, string>;
|
|
5
3
|
export declare const ER_HEADER: readonly ["```mermaid", "erDiagram"];
|
|
6
4
|
export declare const ER_FOOTER: readonly ["```"];
|
|
7
5
|
export declare function main(dev?: boolean, config?: Config): Promise<boolean>;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ER_FOOTER = exports.ER_HEADER =
|
|
7
|
+
exports.ER_FOOTER = exports.ER_HEADER = void 0;
|
|
8
8
|
exports.main = main;
|
|
9
9
|
const node_fs_1 = require("node:fs");
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -13,35 +13,6 @@ const parse_table_info_1 = require("./validator/parse-table-info");
|
|
|
13
13
|
const extract_relations_1 = require("./core/extract-relations");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
15
|
const node_process_1 = require("node:process");
|
|
16
|
-
exports.CARDINALITY_MAP = {
|
|
17
|
-
// Required Relationships
|
|
18
|
-
"one-to-one": "||--||", // 1 --- 1
|
|
19
|
-
"one-to-many": "||--|{", // 1 --- 0..*
|
|
20
|
-
"many-to-one": "}|--||", // * --- 1
|
|
21
|
-
"many-to-many": "}|--|{", // * --- *
|
|
22
|
-
"one-to-zero-one": "||--o|", // 1 --- 0..1
|
|
23
|
-
"zero-one-to-one": "o|--||", // 0..1 --- 1
|
|
24
|
-
"zero-to-one": "o|--o|", // 0..1 --- 0..1
|
|
25
|
-
"zero-to-zero-one": "o|--o|", // Alias for zero-to-one
|
|
26
|
-
"zero-to-many": "o|--o{", // 0..1 --- 0..*
|
|
27
|
-
"zero-one-to-many": "o|--o{", // 0..1 --- *
|
|
28
|
-
"many-to-zero-one": "}|--o|", // * --- 0..1
|
|
29
|
-
// Optional Relationships (dotted lines)
|
|
30
|
-
"one-to-one-optional": "||..||", // 1 --- 1 optional
|
|
31
|
-
"one-to-many-optional": "||..o{", // 1 --- 0..* optional
|
|
32
|
-
"many-to-one-optional": "}|..||", // * --- 1 optional
|
|
33
|
-
"many-to-many-optional": "}|..o{", // * --- 0..* optional
|
|
34
|
-
"one-to-zero-one-optional": "||..o|", // 1 --- 0..1 optional
|
|
35
|
-
"zero-one-to-one-optional": "o|..||", // 0..1 --- 1 optional
|
|
36
|
-
"zero-to-one-optional": "o|..o|", // 0..1 --- 0..1 optional
|
|
37
|
-
"zero-to-many-optional": "o|..o{", // 0..1 --- 0..* optional
|
|
38
|
-
"zero-one-to-many-optional": "o|..o{", // 0..1 --- * optional
|
|
39
|
-
"many-to-zero-one-optional": "}|..o|", // * --- 0..1 optional
|
|
40
|
-
// Nuanced Patterns (Aliases)
|
|
41
|
-
"many-to-zero-many": "}|..o{", // * --- 0..*
|
|
42
|
-
"zero-many-to-many": "o{--|{", // 0..* --- *
|
|
43
|
-
"zero-many-to-zero-many": "o{--o{", // 0..* --- 0..*
|
|
44
|
-
};
|
|
45
16
|
// ER diagram header
|
|
46
17
|
exports.ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
47
18
|
// ER diagram footer
|
|
@@ -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
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
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";
|
|
2
1
|
export type Relation = {
|
|
3
2
|
fromModel: string;
|
|
4
3
|
toModel: string;
|
|
5
4
|
fromField: string;
|
|
6
5
|
toField: string;
|
|
7
|
-
type:
|
|
6
|
+
type: string;
|
|
8
7
|
};
|
|
9
8
|
export type ERContent = readonly string[];
|
|
10
9
|
export type TableInfo = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RelationType } from '../type'
|
|
1
|
+
import type { RelationType } from '../type'
|
|
2
2
|
/**
|
|
3
3
|
* Validate if a value is a valid relation type
|
|
4
4
|
* @param value - The value to validate
|
|
5
5
|
* @returns True if the value is a valid relation type, false otherwise
|
|
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,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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRelationLine = parseRelationLine;
|
|
4
|
-
const is_relation_1 = require("./is-relation");
|
|
5
4
|
/**
|
|
6
5
|
* Parse a relation line
|
|
7
6
|
* @param line - The line to parse
|
|
@@ -12,10 +11,6 @@ function parseRelationLine(line) {
|
|
|
12
11
|
const relationMatch = line.match(/@relation\s+(\w+)\.(\w+)\s+(\w+)\.(\w+)\s+(\w+-to-\w+)/);
|
|
13
12
|
if (relationMatch) {
|
|
14
13
|
const [_, fromModel, fromField, toModel, toField, type] = relationMatch;
|
|
15
|
-
// Validate the relation type
|
|
16
|
-
if (!(0, is_relation_1.isRelation)(type)) {
|
|
17
|
-
throw new Error(`Unknown relation type: ${type}`);
|
|
18
|
-
}
|
|
19
14
|
return {
|
|
20
15
|
fromModel,
|
|
21
16
|
fromField,
|
package/package.json
CHANGED