hekireki 0.7.5 → 0.7.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.
- package/dist/cli/index.d.ts +48 -5
- package/dist/cli/index.js +9 -4
- package/dist/generator/ajv/index.js +4 -4
- package/dist/generator/arktype/index.js +6 -6
- package/dist/generator/dbml/index.js +1 -1
- package/dist/generator/drizzle/index.js +1 -1
- package/dist/generator/ecto/index.js +1 -1
- package/dist/generator/effect/index.js +2 -2
- package/dist/generator/gorm/index.js +1 -1
- package/dist/generator/mermaid-er/index.js +1 -1
- package/dist/generator/sea-orm/index.js +1 -1
- package/dist/generator/sqlalchemy/index.js +1 -1
- package/dist/generator/typebox/index.js +7 -6
- package/dist/generator/valibot/index.js +6 -6
- package/dist/generator/zod/index.js +6 -6
- package/dist/{prisma-CfcdmYJs.js → prisma-o4IvnEUh.js} +8 -5
- package/dist/{utils-BGe939v0.js → utils-3ot3YB3D.js} +15 -3
- package/package.json +1 -1
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,14 +1,57 @@
|
|
|
1
1
|
//#region src/cli/index.d.ts
|
|
2
|
-
|
|
2
|
+
declare const HELP_TEXT = "\u26A1\uFE0F hekireki - Prisma schema tools\n\nUsage:\n hekireki <command> [options]\n\nCommands:\n docs serve Start a local server to view the documentation\n\nOptions:\n -p, --port <port> Specify the port (default: 5858)\n -h, --help Show help\n\nExamples:\n hekireki docs serve\n hekireki docs serve -p 3000";
|
|
3
|
+
declare const DOCS_HELP_TEXT = "\u26A1\uFE0F hekireki docs - Documentation tools\n\nUsage:\n hekireki docs serve [options]\n\nCommands:\n serve Start a local server to view the documentation\n\nOptions:\n -p, --port <port> Specify the port (default: 5858)\n -h, --help Show help\n\nExamples:\n hekireki docs serve\n hekireki docs serve -p 3000";
|
|
4
|
+
/**
|
|
5
|
+
* Parse port from CLI arguments.
|
|
6
|
+
*/
|
|
7
|
+
declare const parsePort: (args: readonly string[]) => {
|
|
8
|
+
readonly ok: true;
|
|
9
|
+
readonly value: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly ok: false;
|
|
12
|
+
readonly error: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Parse CLI arguments for docs serve command.
|
|
16
|
+
*/
|
|
17
|
+
declare const parseDocsServeArgs: (args: readonly string[]) => {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly value: {
|
|
20
|
+
readonly port: number;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
readonly ok: false;
|
|
24
|
+
readonly error: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Handle docs subcommand.
|
|
28
|
+
*/
|
|
29
|
+
declare const handleDocs: (args: readonly string[]) => {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly value: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly ok: false;
|
|
34
|
+
readonly error: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Main CLI dispatcher (pure — takes args, returns Result).
|
|
38
|
+
*/
|
|
39
|
+
declare const hekirekiCli: (args: readonly string[]) => {
|
|
3
40
|
readonly ok: true;
|
|
4
|
-
readonly value:
|
|
41
|
+
readonly value: string;
|
|
5
42
|
} | {
|
|
6
43
|
readonly ok: false;
|
|
7
44
|
readonly error: string;
|
|
8
45
|
};
|
|
9
46
|
/**
|
|
10
|
-
* Main CLI entry point for hekireki.
|
|
47
|
+
* Main CLI entry point for hekireki (reads process.argv).
|
|
11
48
|
*/
|
|
12
|
-
declare const hekireki: () =>
|
|
49
|
+
declare const hekireki: () => {
|
|
50
|
+
readonly ok: true;
|
|
51
|
+
readonly value: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly ok: false;
|
|
54
|
+
readonly error: string;
|
|
55
|
+
};
|
|
13
56
|
//#endregion
|
|
14
|
-
export { hekireki };
|
|
57
|
+
export { DOCS_HELP_TEXT, HELP_TEXT, handleDocs, hekireki, hekirekiCli, parseDocsServeArgs, parsePort };
|
package/dist/cli/index.js
CHANGED
|
@@ -137,10 +137,9 @@ const handleDocs = (args) => {
|
|
|
137
137
|
*/
|
|
138
138
|
const commands = { docs: handleDocs };
|
|
139
139
|
/**
|
|
140
|
-
* Main CLI
|
|
140
|
+
* Main CLI dispatcher (pure — takes args, returns Result).
|
|
141
141
|
*/
|
|
142
|
-
const
|
|
143
|
-
const args = process.argv.slice(2);
|
|
142
|
+
const hekirekiCli = (args) => {
|
|
144
143
|
const command = args[0];
|
|
145
144
|
if (!command || command === "-h" || command === "--help") return {
|
|
146
145
|
ok: true,
|
|
@@ -153,6 +152,12 @@ const hekireki = () => {
|
|
|
153
152
|
};
|
|
154
153
|
return handler(args.slice(1));
|
|
155
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* Main CLI entry point for hekireki (reads process.argv).
|
|
157
|
+
*/
|
|
158
|
+
const hekireki = () => {
|
|
159
|
+
return hekirekiCli(process.argv.slice(2));
|
|
160
|
+
};
|
|
156
161
|
const result = hekireki();
|
|
157
162
|
if (result.ok) console.log(result.value);
|
|
158
163
|
else {
|
|
@@ -161,4 +166,4 @@ else {
|
|
|
161
166
|
}
|
|
162
167
|
|
|
163
168
|
//#endregion
|
|
164
|
-
export { hekireki };
|
|
169
|
+
export { DOCS_HELP_TEXT, HELP_TEXT, handleDocs, hekireki, hekirekiCli, parseDocsServeArgs, parsePort };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { l as makeValidationExtractor, m as writeFile, n as getBool, o as makeCommentBlock, p as mkdir, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -37,13 +37,13 @@ const PRISMA_TO_AJV = {
|
|
|
37
37
|
* @param modelFields - The fields of the model
|
|
38
38
|
* @param comment - Whether to include JSDoc comments in the generated code
|
|
39
39
|
*/
|
|
40
|
-
function makeAjvSchemas(modelFields, comment) {
|
|
40
|
+
function makeAjvSchemas(modelFields, comment, objectType) {
|
|
41
41
|
const modelName = modelFields[0].modelName;
|
|
42
42
|
const properties = modelFields.map((field) => {
|
|
43
43
|
return `${comment ? makeCommentBlock(field.comment, 4) : ""} ${field.fieldName}: ${field.validation ?? "{ type: 'unknown' as const }"},`;
|
|
44
44
|
}).join("\n");
|
|
45
45
|
const requiredFields = modelFields.filter((f) => f.isRequired).map((f) => f.fieldName);
|
|
46
|
-
return `export const ${modelName}Schema = {\n type: 'object' as const,\n properties: {\n${properties}\n },${requiredFields.length > 0 ? `\n required: [${requiredFields.map((f) => `'${f}'`).join(", ")}] as const,` : ""}\n additionalProperties: false,\n} as const`;
|
|
46
|
+
return `export const ${modelName}Schema = {\n type: 'object' as const,\n properties: {\n${properties}\n },${requiredFields.length > 0 ? `\n required: [${requiredFields.map((f) => `'${f}'`).join(", ")}] as const,` : ""}\n additionalProperties: ${objectType === "loose" ? "true" : "false"},\n} as const`;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Generate JSON Schema relation object definition
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { d as schemaFromFields, l as makeValidationExtractor, m as writeFile, n as getBool, o as makeCommentBlock, p as mkdir, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -18,8 +18,8 @@ function makeArktypeInfer(modelName) {
|
|
|
18
18
|
* @param modelName - The model name for the schema
|
|
19
19
|
* @param fields - The formatted field definitions string
|
|
20
20
|
*/
|
|
21
|
-
function makeArktypeSchema(modelName, fields) {
|
|
22
|
-
return `export const ${modelName}Schema = type({\n${fields}\n})`;
|
|
21
|
+
function makeArktypeSchema(modelName, fields, objectType) {
|
|
22
|
+
return `export const ${modelName}Schema = type({${objectType === "strict" ? "\n \"+\": \"reject\",\n" : objectType === "loose" ? "\n \"+\": \"ignore\",\n" : "\n"}${fields}\n})`;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Generate ArkType property definitions
|
|
@@ -55,8 +55,8 @@ const PRISMA_TO_ARKTYPE = {
|
|
|
55
55
|
* @param modelFields - The fields of the model
|
|
56
56
|
* @param comment - Whether to include JSDoc comments in the generated code
|
|
57
57
|
*/
|
|
58
|
-
function makeArktypeSchemas(modelFields, comment) {
|
|
59
|
-
return schemaFromFields(modelFields, comment, makeArktypeSchema, makeArktypeProperties);
|
|
58
|
+
function makeArktypeSchemas(modelFields, comment, objectType) {
|
|
59
|
+
return schemaFromFields(modelFields, comment, makeArktypeSchema, makeArktypeProperties, objectType);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Generate ArkType relation schema definition
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { f as stripAnnotations, h as writeFileBinary, m as writeFile, p as mkdir, r as getString } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
import { Resvg } from "@resvg/resvg-js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
3
|
+
import { c as makeSnakeCase, m as writeFile, p as mkdir } from "../../utils-3ot3YB3D.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import pkg from "@prisma/generator-helper";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as makeSnakeCase, m as writeFile, p as mkdir } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { d as schemaFromFields, l as makeValidationExtractor, m as writeFile, n as getBool, o as makeCommentBlock, p as mkdir, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as makeSnakeCase, m as writeFile, p as mkdir, r as getString } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import path, { dirname } from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { f as stripAnnotations, m as writeFile, p as mkdir } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as makeSnakeCase, m as writeFile, p as mkdir, r as getString } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as makeSnakeCase, m as writeFile, p as mkdir } from "../../utils-3ot3YB3D.js";
|
|
3
3
|
import path, { dirname } from "node:path";
|
|
4
4
|
import pkg from "@prisma/generator-helper";
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { d as schemaFromFields, l as makeValidationExtractor, m as writeFile, n as getBool, o as makeCommentBlock, p as mkdir, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -18,8 +18,9 @@ function makeTypeBoxInfer(modelName) {
|
|
|
18
18
|
* @param modelName - The model name for the schema
|
|
19
19
|
* @param fields - The formatted field definitions string
|
|
20
20
|
*/
|
|
21
|
-
function makeTypeBoxSchema(modelName, fields) {
|
|
22
|
-
|
|
21
|
+
function makeTypeBoxSchema(modelName, fields, objectType) {
|
|
22
|
+
const obj = `Type.Object({\n${fields}\n})`;
|
|
23
|
+
return objectType === "strict" ? `export const ${modelName}Schema = Type.Strict(${obj})` : `export const ${modelName}Schema = ${obj}`;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Generate TypeBox property definitions with optional wrapping
|
|
@@ -58,8 +59,8 @@ const PRISMA_TO_TYPEBOX = {
|
|
|
58
59
|
* @param modelFields - The fields of the model
|
|
59
60
|
* @param comment - Whether to include JSDoc comments in the generated code
|
|
60
61
|
*/
|
|
61
|
-
function makeTypeBoxSchemas(modelFields, comment) {
|
|
62
|
-
return schemaFromFields(modelFields, comment, makeTypeBoxSchema, makeTypeBoxProperties);
|
|
62
|
+
function makeTypeBoxSchemas(modelFields, comment, objectType) {
|
|
63
|
+
return schemaFromFields(modelFields, comment, makeTypeBoxSchema, makeTypeBoxProperties, objectType);
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Generate TypeBox relation schema definition
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { d as schemaFromFields, l as makeValidationExtractor, m as writeFile, n as getBool, p as mkdir, s as makePropertiesGenerator, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -9,8 +9,8 @@ import pkg from "@prisma/generator-helper";
|
|
|
9
9
|
function makeValibotInfer(modelName) {
|
|
10
10
|
return `export type ${modelName} = v.InferOutput<typeof ${modelName}Schema>`;
|
|
11
11
|
}
|
|
12
|
-
function makeValibotSchema(modelName, fields) {
|
|
13
|
-
return `export const ${modelName}Schema = v
|
|
12
|
+
function makeValibotSchema(modelName, fields, objectType) {
|
|
13
|
+
return `export const ${modelName}Schema = v.${objectType === "strict" ? "strictObject" : objectType === "loose" ? "looseObject" : "object"}({\n${fields}\n})`;
|
|
14
14
|
}
|
|
15
15
|
function makeValibotEnumExpression(values) {
|
|
16
16
|
return `picklist([${values.map((v) => `'${v}'`).join(", ")}])`;
|
|
@@ -26,8 +26,8 @@ const PRISMA_TO_VALIBOT = {
|
|
|
26
26
|
Json: "unknown()",
|
|
27
27
|
Bytes: "any()"
|
|
28
28
|
};
|
|
29
|
-
function makeValibotSchemas(modelFields, comment) {
|
|
30
|
-
return schemaFromFields(modelFields, comment, makeValibotSchema, makePropertiesGenerator("v", (expr, isRequired) => isRequired ? expr : `v.exactOptional(${expr})`));
|
|
29
|
+
function makeValibotSchemas(modelFields, comment, objectType) {
|
|
30
|
+
return schemaFromFields(modelFields, comment, makeValibotSchema, makePropertiesGenerator("v", (expr, isRequired) => isRequired ? expr : `v.exactOptional(${expr})`), objectType);
|
|
31
31
|
}
|
|
32
32
|
function makeValibotRelations(model, relProps, options) {
|
|
33
33
|
if (relProps.length === 0) return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as fmt } from "../../format-DwiYldCm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-
|
|
3
|
+
import { d as schemaFromFields, l as makeValidationExtractor, m as writeFile, n as getBool, p as mkdir, r as getString, s as makePropertiesGenerator, u as parseDocumentWithoutAnnotations } from "../../utils-3ot3YB3D.js";
|
|
4
|
+
import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-o4IvnEUh.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import pkg from "@prisma/generator-helper";
|
|
7
7
|
|
|
@@ -9,8 +9,8 @@ import pkg from "@prisma/generator-helper";
|
|
|
9
9
|
function makeZodInfer(modelName) {
|
|
10
10
|
return `export type ${modelName} = z.infer<typeof ${modelName}Schema>`;
|
|
11
11
|
}
|
|
12
|
-
function makeZodSchema(modelName, fields) {
|
|
13
|
-
return `export const ${modelName}Schema = z
|
|
12
|
+
function makeZodSchema(modelName, fields, objectType) {
|
|
13
|
+
return `export const ${modelName}Schema = z.${objectType === "strict" ? "strictObject" : objectType === "loose" ? "looseObject" : "object"}({\n${fields}\n})`;
|
|
14
14
|
}
|
|
15
15
|
function makeZodEnumExpression(values) {
|
|
16
16
|
return `enum([${values.map((v) => `'${v}'`).join(", ")}])`;
|
|
@@ -26,8 +26,8 @@ const PRISMA_TO_ZOD = {
|
|
|
26
26
|
Json: "unknown()",
|
|
27
27
|
Bytes: "any()"
|
|
28
28
|
};
|
|
29
|
-
function makeZodSchemas(modelFields, comment) {
|
|
30
|
-
return schemaFromFields(modelFields, comment, makeZodSchema, makePropertiesGenerator("z", (expr, isRequired) => isRequired ? expr : `${expr}.exactOptional()`));
|
|
29
|
+
function makeZodSchemas(modelFields, comment, objectType) {
|
|
30
|
+
return schemaFromFields(modelFields, comment, makeZodSchema, makePropertiesGenerator("z", (expr, isRequired) => isRequired ? expr : `${expr}.exactOptional()`), objectType);
|
|
31
31
|
}
|
|
32
32
|
function makeZodRelations(model, relProps, options) {
|
|
33
33
|
if (relProps.length === 0) return null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as isFields, i as groupByModel, t as extractObjectType } from "./utils-3ot3YB3D.js";
|
|
2
2
|
|
|
3
3
|
//#region src/helper/prisma.ts
|
|
4
4
|
function collectRelationProps(models) {
|
|
@@ -61,10 +61,13 @@ function validationSchemas(models, type, comment, config) {
|
|
|
61
61
|
fieldName: f.name
|
|
62
62
|
})));
|
|
63
63
|
if (config.onWarning) for (const { modelName, fieldName } of missing) config.onWarning(`Warning: Field "${modelName}.${fieldName}" has no ${config.annotationPrefix} annotation and will be omitted from the schema`);
|
|
64
|
-
const schemas = Object.values(groupByModel(isFields(modelFields))).map((fields) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
const schemas = Object.values(groupByModel(isFields(modelFields))).map((fields) => {
|
|
65
|
+
const objectType = extractObjectType(fields[0].documentation, config.annotationPrefix);
|
|
66
|
+
return {
|
|
67
|
+
schema: config.schemas(fields, comment, objectType),
|
|
68
|
+
inferType: type ? config.inferType(fields[0].modelName) : ""
|
|
69
|
+
};
|
|
70
|
+
}).flatMap(({ schema, inferType }) => [schema, inferType].filter(Boolean)).join("\n\n");
|
|
68
71
|
return config.importStatement ? [
|
|
69
72
|
config.importStatement,
|
|
70
73
|
"",
|
|
@@ -84,10 +84,22 @@ function groupByModel(validFields) {
|
|
|
84
84
|
function isFields(modelFields) {
|
|
85
85
|
return modelFields.flat().filter((field) => field.validation !== null);
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Extract object type (strict/loose) from model documentation.
|
|
89
|
+
*/
|
|
90
|
+
function extractObjectType(documentation, prefix) {
|
|
91
|
+
if (!documentation) return void 0;
|
|
92
|
+
const lines = documentation.split("\n").map((l) => l.trim());
|
|
93
|
+
const prefixWithoutAt = prefix.slice(1);
|
|
94
|
+
const match = lines.find((line) => line.includes(`${prefixWithoutAt}strictObject`) || line.includes(`${prefixWithoutAt}looseObject`));
|
|
95
|
+
if (!match) return void 0;
|
|
96
|
+
if (match.includes("strictObject")) return "strict";
|
|
97
|
+
if (match.includes("looseObject")) return "loose";
|
|
98
|
+
}
|
|
99
|
+
function schemaFromFields(modelFields, comment, schemaBuilder, propertiesGenerator, objectType) {
|
|
88
100
|
const modelName = modelFields[0].modelName;
|
|
89
|
-
return schemaBuilder(modelName, propertiesGenerator(modelFields, comment));
|
|
101
|
+
return schemaBuilder(modelName, propertiesGenerator(modelFields, comment), objectType);
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
//#endregion
|
|
93
|
-
export {
|
|
105
|
+
export { isFields as a, makeSnakeCase as c, schemaFromFields as d, stripAnnotations as f, writeFileBinary as h, groupByModel as i, makeValidationExtractor as l, writeFile as m, getBool as n, makeCommentBlock as o, mkdir as p, getString as r, makePropertiesGenerator as s, extractObjectType as t, parseDocumentWithoutAnnotations as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hekireki",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "Hekireki is a tool that generates validation schemas for Zod, Valibot, ArkType, and Effect Schema, as well as ER diagrams and DBML, from Prisma schemas annotated with comments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ajv",
|