sizuku 0.0.5 → 0.0.6

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.
@@ -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 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 = __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,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 = exports.CARDINALITY_MAP = void 0;
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: RelationType;
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,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
+ }
@@ -8,5 +8,5 @@ export declare function parseRelationLine(line: string): {
8
8
  fromField: string;
9
9
  toModel: string;
10
10
  toField: string;
11
- type: import("../type").RelationType;
11
+ type: string;
12
12
  } | null;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sizuku",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Sizuku is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Drizzle schemas annotated with comments.",
5
5
  "license": "MIT",
6
6
  "keywords": [