hekireki 0.0.6 → 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.
Files changed (57) 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 +3 -4
  11. package/dist/generator/mermaid/generator/generate-er-content.js +2 -3
  12. package/dist/generator/mermaid/generator/generate-model-fields.d.ts +3 -4
  13. package/dist/generator/mermaid/generator/generate-model-fields.js +9 -11
  14. package/dist/generator/mermaid/generator/generate-model-info.d.ts +1 -1
  15. package/dist/generator/mermaid/generator/generate-model-info.js +1 -5
  16. package/dist/generator/mermaid/generator/generate-relation-line.d.ts +1 -1
  17. package/dist/generator/mermaid/generator/generate-relation-line.js +2 -2
  18. package/dist/generator/mermaid/index.d.ts +1 -3
  19. package/dist/generator/mermaid/index.js +8 -37
  20. package/dist/generator/mermaid/output/index.d.ts +2 -2
  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 +2 -3
  27. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +1 -1
  28. package/dist/generator/mermaid/validator/extract-relations.d.ts +1 -1
  29. package/dist/generator/mermaid/validator/extract-relations.js +1 -1
  30. package/dist/generator/mermaid/validator/is-relation.d.ts +2 -2
  31. package/dist/generator/mermaid/validator/is-relationship.d.ts +7 -0
  32. package/dist/generator/mermaid/validator/is-relationship.js +11 -0
  33. package/dist/generator/mermaid/validator/parse-relation.d.ts +1 -1
  34. package/dist/generator/mermaid/validator/parse-relation.js +0 -4
  35. package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +1 -1
  36. package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +1 -1
  37. package/dist/generator/valibot/generator/generate-valibot-properties.js +4 -6
  38. package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +1 -1
  39. package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +1 -1
  40. package/dist/generator/valibot/generator/generate-valibot-schemas.js +1 -1
  41. package/dist/generator/valibot/generator/generate-valibot.d.ts +2 -2
  42. package/dist/generator/valibot/generator/generate-valibot.js +5 -7
  43. package/dist/generator/valibot/index.d.ts +3 -3
  44. package/dist/generator/valibot/index.js +10 -10
  45. package/dist/generator/valibot/validator/is-valibot-documentation.js +2 -2
  46. package/dist/generator/zod/generator/generate-zod-infer.d.ts +1 -1
  47. package/dist/generator/zod/generator/generate-zod-properties.d.ts +1 -1
  48. package/dist/generator/zod/generator/generate-zod-properties.js +4 -6
  49. package/dist/generator/zod/generator/generate-zod-schema.d.ts +1 -1
  50. package/dist/generator/zod/generator/generate-zod-schemas.d.ts +1 -1
  51. package/dist/generator/zod/generator/generate-zod-schemas.js +1 -1
  52. package/dist/generator/zod/generator/generate-zod.d.ts +2 -2
  53. package/dist/generator/zod/generator/generate-zod.js +5 -7
  54. package/dist/generator/zod/index.d.ts +3 -3
  55. package/dist/generator/zod/index.js +10 -10
  56. package/dist/generator/zod/validator/is-zod-documentation.js +2 -2
  57. 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
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
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,4 +1,4 @@
1
- import type { Model } from "../type";
1
+ import type { Model } from '../type';
2
2
  /**
3
3
  * generate model info
4
4
  * @function generateModelInfo
@@ -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,4 +1,4 @@
1
- import type { Relation } from "../type";
1
+ import type { Relation } from '../type';
2
2
  /**
3
3
  * generate relation line
4
4
  * @param { Relation } relation
@@ -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
4
  output?: string;
6
5
  file?: string | string[];
7
6
  };
8
- export declare const CARDINALITY_MAP: Record<RelationType, string>;
9
7
  export declare const ER_HEADER: readonly ["```mermaid", "erDiagram"];
10
8
  export declare const ER_FOOTER: readonly ["```"];
11
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,5 +1,5 @@
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
@@ -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
3
  fromModel: string;
5
4
  toModel: string;
6
5
  fromField: string;
7
6
  toField: string;
8
- type: RelationType;
7
+ type: string;
9
8
  };
10
9
  export type Model = Readonly<DMMF.Model>;
11
10
  export type ERContent = 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,4 +1,4 @@
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
@@ -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,4 +1,4 @@
1
- import type { Relation } from "../type";
1
+ import type { Relation } from '../type';
2
2
  /**
3
3
  * parse relation
4
4
  * @function parseRelation
@@ -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,
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate the infer input type for the model
4
4
  * @param modelName - The name of the model
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  export declare function generateValibotProperties(modelFields: {
3
3
  documentation: string;
4
4
  modelName: string;
@@ -7,14 +7,12 @@ function generateValibotProperties(modelFields, config) {
7
7
  .map((field) => {
8
8
  // @relation, @v, @z exclude
9
9
  const cleanDoc = field.comment
10
- .filter((line) => !(line.includes("@relation") ||
11
- line.includes("@v") ||
12
- line.includes("@z")))
13
- .join("\n")
10
+ .filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
11
+ .join('\n')
14
12
  .trim();
15
- const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : "";
13
+ const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
16
14
  return `${docComment} ${field.fieldName}: v.${field.validation}`;
17
15
  })
18
- .join(",\n");
16
+ .join(',\n');
19
17
  return fields;
20
18
  }
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate Valibot schema
4
4
  * @param modelName - The name of the model
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * generate valibot schemas
4
4
  * @function generateValibotSchemas
@@ -12,7 +12,7 @@ const generate_valibot_schema_1 = require("./generate-valibot-schema");
12
12
  */
13
13
  function generateValibotSchemas(modelFields, config) {
14
14
  const modelName = modelFields[0].modelName;
15
- const modelDoc = modelFields[0].documentation || "";
15
+ const modelDoc = modelFields[0].documentation || '';
16
16
  const fields = (0, generate_valibot_properties_1.generateValibotProperties)(modelFields, config);
17
17
  if (!(modelDoc || !config?.comment)) {
18
18
  return (0, generate_valibot_schema_1.generateValibotSchema)(modelName, fields, config);
@@ -1,5 +1,5 @@
1
- import type { Config } from "..";
2
- import type { Model } from "../../../common/type";
1
+ import type { Config } from '..';
2
+ import type { Model } from '../../../common/type';
3
3
  /**
4
4
  * Generate Valibot schemas and types
5
5
  * @param models - The models to generate the Valibot schemas and types for
@@ -17,7 +17,7 @@ const VALIBOT_IMPORT = `import * as v from 'valibot'\n`;
17
17
  function generateValibot(models, config) {
18
18
  const modelInfos = models.map((model) => {
19
19
  return {
20
- documentation: model.documentation ?? "",
20
+ documentation: model.documentation ?? '',
21
21
  name: model.name,
22
22
  fields: model.fields,
23
23
  };
@@ -39,16 +39,14 @@ function generateValibot(models, config) {
39
39
  const valibots = Object.values(groupedByModel).map((fields) => {
40
40
  return {
41
41
  generateValibotSchema: (0, generate_valibot_schemas_1.generateValibotSchemas)(fields, config),
42
- generateValibotInfer: config.type === "true"
43
- ? (0, generate_valibot_infer_input_1.generateValibotInferInput)(fields[0].modelName, config)
44
- : "",
42
+ generateValibotInfer: config.type === 'true' ? (0, generate_valibot_infer_input_1.generateValibotInferInput)(fields[0].modelName, config) : '',
45
43
  };
46
44
  });
47
45
  return [
48
46
  VALIBOT_IMPORT,
49
- "",
47
+ '',
50
48
  valibots
51
49
  .flatMap(({ generateValibotSchema, generateValibotInfer }) => [generateValibotSchema, generateValibotInfer].filter(Boolean))
52
- .join("\n\n"),
53
- ].join("\n");
50
+ .join('\n\n'),
51
+ ].join('\n');
54
52
  }
@@ -1,10 +1,10 @@
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
4
  output?: string;
5
5
  file?: string | string[];
6
- schemaName?: "PascalCase" | "camelCase" | string | string[];
7
- typeName?: "PascalCase" | "camelCase" | string | string[];
6
+ schemaName?: 'PascalCase' | 'camelCase' | string | string[];
7
+ typeName?: 'PascalCase' | 'camelCase' | string | string[];
8
8
  type?: boolean | string | string[];
9
9
  comment?: boolean | string | string[];
10
10
  };
@@ -10,10 +10,10 @@ const generate_valibot_1 = require("./generator/generate-valibot");
10
10
  const prettier_1 = require("prettier");
11
11
  const node_fs_1 = __importDefault(require("node:fs"));
12
12
  const DEFAULT_CONFIG = {
13
- output: "./valibot",
14
- file: "index.ts",
15
- schemaName: "PascalCase",
16
- typeName: "PascalCase",
13
+ output: './valibot',
14
+ file: 'index.ts',
15
+ schemaName: 'PascalCase',
16
+ typeName: 'PascalCase',
17
17
  type: false,
18
18
  comment: false,
19
19
  };
@@ -24,30 +24,30 @@ async function main(options) {
24
24
  schemaName: options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
25
25
  typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
26
26
  type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
27
- comment: options.generator.config?.comment === "true",
27
+ comment: options.generator.config?.comment === 'true',
28
28
  };
29
29
  const content = (0, generate_valibot_1.generateValibot)(options.dmmf.datamodel.models, config);
30
30
  const code = await (0, prettier_1.format)(content, {
31
- parser: "typescript",
31
+ parser: 'typescript',
32
32
  printWidth: 100,
33
33
  singleQuote: true,
34
34
  semi: false,
35
35
  });
36
36
  if (!config.output) {
37
- throw new Error("output is required");
37
+ throw new Error('output is required');
38
38
  }
39
39
  if (!node_fs_1.default.existsSync(config.output)) {
40
40
  node_fs_1.default.mkdirSync(config.output, { recursive: true });
41
41
  }
42
- const file = config.file ?? "index.ts";
42
+ const file = config.file ?? 'index.ts';
43
43
  const filePath = `${config.output}/${file}`;
44
44
  node_fs_1.default.writeFileSync(filePath, code);
45
45
  }
46
46
  (0, generator_helper_1.generatorHandler)({
47
47
  onManifest() {
48
48
  return {
49
- defaultOutput: "./valibot/",
50
- prettyName: "Hekireki-Valibot",
49
+ defaultOutput: './valibot/',
50
+ prettyName: 'Hekireki-Valibot',
51
51
  };
52
52
  },
53
53
  onGenerate: main,
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isValibotDocumentValidation = isValibotDocumentValidation;
4
- const VALIDATION_PATTERNS = ["@v."];
4
+ const VALIDATION_PATTERNS = ['@v.'];
5
5
  function isValibotDocumentValidation(documentation) {
6
6
  if (!documentation)
7
7
  return [];
8
8
  return documentation
9
- .split("\n")
9
+ .split('\n')
10
10
  .filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
11
11
  .map((line) => line.trim())
12
12
  .filter(Boolean);
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate Zod infer
4
4
  * @param modelName - The name of the model
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate Zod properties
4
4
  * @param modelFields - The fields of the model
@@ -13,14 +13,12 @@ function generateZodProperties(modelFields, config) {
13
13
  .map((field) => {
14
14
  // @relation, @v, @z exclude
15
15
  const cleanDoc = field.comment
16
- .filter((line) => !(line.includes("@relation") ||
17
- line.includes("@v") ||
18
- line.includes("@z")))
19
- .join("\n")
16
+ .filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
17
+ .join('\n')
20
18
  .trim();
21
- const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : "";
19
+ const docComment = config?.comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
22
20
  return `${docComment} ${field.fieldName}: z.${field.validation}`;
23
21
  })
24
- .join(",\n");
22
+ .join(',\n');
25
23
  return fields;
26
24
  }
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate Zod schema
4
4
  * @param modelName - The name of the model
@@ -1,4 +1,4 @@
1
- import type { Config } from "..";
1
+ import type { Config } from '..';
2
2
  /**
3
3
  * Generate Zod schemas
4
4
  * @param modelFields - The fields of the model
@@ -11,7 +11,7 @@ const generate_zod_schema_1 = require("./generate-zod-schema");
11
11
  */
12
12
  function generateZodSchemas(modelFields, config) {
13
13
  const modelName = modelFields[0].modelName;
14
- const modelDoc = modelFields[0].documentation || "";
14
+ const modelDoc = modelFields[0].documentation || '';
15
15
  const fields = (0, generate_zod_properties_1.generateZodProperties)(modelFields, config);
16
16
  if (!(modelDoc || !config?.comment)) {
17
17
  return (0, generate_zod_schema_1.generateZodSchema)(modelName, fields, config);
@@ -1,5 +1,5 @@
1
- import type { Config } from "..";
2
- import type { Model } from "../../../common/type";
1
+ import type { Config } from '..';
2
+ import type { Model } from '../../../common/type';
3
3
  /**
4
4
  * Generate Zod schemas and types
5
5
  * @param models - The models to generate the Zod schemas and types for
@@ -17,7 +17,7 @@ const ZOD_IMPORT = `import { z } from 'zod'\n`;
17
17
  function generateZod(models, config) {
18
18
  const modelInfos = models.map((model) => {
19
19
  return {
20
- documentation: model.documentation ?? "",
20
+ documentation: model.documentation ?? '',
21
21
  name: model.name,
22
22
  fields: model.fields,
23
23
  };
@@ -39,16 +39,14 @@ function generateZod(models, config) {
39
39
  const zods = Object.values(groupedByModel).map((fields) => {
40
40
  return {
41
41
  generateZodSchema: (0, generate_zod_schemas_1.generateZodSchemas)(fields, config),
42
- generateZodInfer: config.type === "true"
43
- ? (0, generate_zod_infer_1.generateZodInfer)(fields[0].modelName, config)
44
- : "",
42
+ generateZodInfer: config.type === 'true' ? (0, generate_zod_infer_1.generateZodInfer)(fields[0].modelName, config) : '',
45
43
  };
46
44
  });
47
45
  return [
48
46
  ZOD_IMPORT,
49
- "",
47
+ '',
50
48
  zods
51
49
  .flatMap(({ generateZodSchema, generateZodInfer }) => [generateZodSchema, generateZodInfer].filter(Boolean))
52
- .join("\n\n"),
53
- ].join("\n");
50
+ .join('\n\n'),
51
+ ].join('\n');
54
52
  }
@@ -1,10 +1,10 @@
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
4
  output?: string;
5
5
  file?: string | string[];
6
- schemaName?: "PascalCase" | "camelCase" | string | string[];
7
- typeName?: "PascalCase" | "camelCase" | string | string[];
6
+ schemaName?: 'PascalCase' | 'camelCase' | string | string[];
7
+ typeName?: 'PascalCase' | 'camelCase' | string | string[];
8
8
  type?: boolean | string | string[];
9
9
  comment?: boolean | string | string[];
10
10
  };
@@ -10,10 +10,10 @@ const generate_zod_1 = require("./generator/generate-zod");
10
10
  const prettier_1 = require("prettier");
11
11
  const node_fs_1 = __importDefault(require("node:fs"));
12
12
  const DEFAULT_CONFIG = {
13
- output: "./zod",
14
- file: "index.ts",
15
- schemaName: "PascalCase",
16
- typeName: "PascalCase",
13
+ output: './zod',
14
+ file: 'index.ts',
15
+ schemaName: 'PascalCase',
16
+ typeName: 'PascalCase',
17
17
  type: false,
18
18
  comment: false,
19
19
  };
@@ -24,30 +24,30 @@ async function main(options) {
24
24
  schemaName: options.generator.config?.schemaName ?? DEFAULT_CONFIG.schemaName,
25
25
  typeName: options.generator.config?.typeName ?? DEFAULT_CONFIG.typeName,
26
26
  type: options.generator.config?.type ?? DEFAULT_CONFIG.type,
27
- comment: options.generator.config?.comment === "true",
27
+ comment: options.generator.config?.comment === 'true',
28
28
  };
29
29
  const content = (0, generate_zod_1.generateZod)(options.dmmf.datamodel.models, config);
30
30
  const code = await (0, prettier_1.format)(content, {
31
- parser: "typescript",
31
+ parser: 'typescript',
32
32
  printWidth: 100,
33
33
  singleQuote: true,
34
34
  semi: false,
35
35
  });
36
36
  if (!config.output) {
37
- throw new Error("output is required");
37
+ throw new Error('output is required');
38
38
  }
39
39
  if (!node_fs_1.default.existsSync(config.output)) {
40
40
  node_fs_1.default.mkdirSync(config.output, { recursive: true });
41
41
  }
42
- const file = config.file ?? "index.ts";
42
+ const file = config.file ?? 'index.ts';
43
43
  const filePath = `${config.output}/${file}`;
44
44
  node_fs_1.default.writeFileSync(filePath, code);
45
45
  }
46
46
  (0, generator_helper_1.generatorHandler)({
47
47
  onManifest() {
48
48
  return {
49
- defaultOutput: "./zod/",
50
- prettyName: "Hekireki-Zod",
49
+ defaultOutput: './zod/',
50
+ prettyName: 'Hekireki-Zod',
51
51
  };
52
52
  },
53
53
  onGenerate: main,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isZodDocumentValidation = isZodDocumentValidation;
4
- const VALIDATION_PATTERNS = ["@z."];
4
+ const VALIDATION_PATTERNS = ['@z.'];
5
5
  /**
6
6
  * Is Zod documentation
7
7
  * @param documentation - The documentation of the field
@@ -11,7 +11,7 @@ function isZodDocumentValidation(documentation) {
11
11
  if (!documentation)
12
12
  return [];
13
13
  return documentation
14
- .split("\n")
14
+ .split('\n')
15
15
  .filter((line) => !VALIDATION_PATTERNS.some((pattern) => line.includes(pattern)))
16
16
  .map((line) => line.trim())
17
17
  .filter(Boolean);
package/package.json CHANGED
@@ -1,56 +1,56 @@
1
1
  {
2
- "name": "hekireki",
3
- "version": "0.0.6",
4
- "license": "MIT",
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
- "keywords": [
7
- "prisma",
8
- "zod",
9
- "valibot",
10
- "mermaid"
11
- ],
12
- "homepage": "https://github.com/nakita628/hekireki",
13
- "publishConfig": {
14
- "access": "public"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/nakita628/hekireki.git"
19
- },
20
- "bugs": {
21
- "url": "https://github.com/nakita628/hekireki/issues"
22
- },
23
- "main": "dist/index.js",
24
- "types": "dist/index.d.ts",
25
- "files": [
26
- "dist"
27
- ],
28
- "bin": {
29
- "hekireki-zod": "dist/generator/zod/index.js",
30
- "hekireki-valibot": "dist/generator/valibot/index.js",
31
- "hekireki-mermaid-er": "dist/generator/mermaid/index.js"
32
- },
33
- "scripts": {
34
- "generate": "prisma generate",
35
- "deps": "rm -rf node_modules && pnpm install",
36
- "build": "tsc",
37
- "typecheck": "tsc --noEmit",
38
- "test": "vitest run",
39
- "coverage": "vitest run --coverage",
40
- "release": "npm pkg fix && pnpm build && npm publish"
41
- },
42
- "devDependencies": {
43
- "@types/node": "^22.13.10",
44
- "@vitest/coverage-v8": "^3.0.8",
45
- "prisma": "^6.5.0",
46
- "@prisma/client": "6.5.0",
47
- "tsx": "^4.19.3",
48
- "valibot": "1.0.0-rc.3",
49
- "vitest": "^3.0.8",
50
- "zod": "^3.24.2"
51
- },
52
- "dependencies": {
53
- "@prisma/generator-helper": "^6.5.0",
54
- "prettier": "^3.5.3"
55
- }
2
+ "name": "hekireki",
3
+ "version": "0.0.7",
4
+ "license": "MIT",
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
+ "keywords": [
7
+ "prisma",
8
+ "zod",
9
+ "valibot",
10
+ "mermaid"
11
+ ],
12
+ "homepage": "https://github.com/nakita628/hekireki",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/nakita628/hekireki.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/nakita628/hekireki/issues"
22
+ },
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "bin": {
29
+ "hekireki-zod": "dist/generator/zod/index.js",
30
+ "hekireki-valibot": "dist/generator/valibot/index.js",
31
+ "hekireki-mermaid-er": "dist/generator/mermaid/index.js"
32
+ },
33
+ "scripts": {
34
+ "generate": "prisma generate",
35
+ "deps": "rm -rf node_modules && pnpm install",
36
+ "build": "tsc",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "vitest run",
39
+ "coverage": "vitest run --coverage",
40
+ "release": "npm pkg fix && pnpm build && npm publish"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.13.10",
44
+ "@vitest/coverage-v8": "^3.0.8",
45
+ "prisma": "^6.5.0",
46
+ "@prisma/client": "6.5.0",
47
+ "tsx": "^4.19.3",
48
+ "valibot": "1.0.0-rc.3",
49
+ "vitest": "^3.0.8",
50
+ "zod": "^3.24.2"
51
+ },
52
+ "dependencies": {
53
+ "@prisma/generator-helper": "^6.5.0",
54
+ "prettier": "^3.5.3"
55
+ }
56
56
  }