hekireki 0.7.3 → 0.7.5

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 CHANGED
@@ -257,7 +257,7 @@ export const UserSchema = v.object({
257
257
  name: v.pipe(v.string(), v.minLength(1), v.maxLength(50)),
258
258
  })
259
259
 
260
- export type User = v.InferInput<typeof UserSchema>
260
+ export type User = v.InferOutput<typeof UserSchema>
261
261
 
262
262
  export const PostSchema = v.object({
263
263
  /**
@@ -278,21 +278,21 @@ export const PostSchema = v.object({
278
278
  userId: v.pipe(v.string(), v.uuid()),
279
279
  })
280
280
 
281
- export type Post = v.InferInput<typeof PostSchema>
281
+ export type Post = v.InferOutput<typeof PostSchema>
282
282
 
283
283
  export const UserRelationsSchema = v.object({
284
284
  ...UserSchema.entries,
285
285
  posts: v.array(PostSchema),
286
286
  })
287
287
 
288
- export type UserRelations = v.InferInput<typeof UserRelationsSchema>
288
+ export type UserRelations = v.InferOutput<typeof UserRelationsSchema>
289
289
 
290
290
  export const PostRelationsSchema = v.object({
291
291
  ...PostSchema.entries,
292
292
  user: UserSchema,
293
293
  })
294
294
 
295
- export type PostRelations = v.InferInput<typeof PostRelationsSchema>
295
+ export type PostRelations = v.InferOutput<typeof PostRelationsSchema>
296
296
  ```
297
297
 
298
298
  ### ArkType
@@ -301,22 +301,34 @@ export type PostRelations = v.InferInput<typeof PostRelationsSchema>
301
301
  import { type } from 'arktype'
302
302
 
303
303
  export const UserSchema = type({
304
- /** Primary key */
304
+ /**
305
+ * Primary key
306
+ */
305
307
  id: 'string.uuid',
306
- /** Display name */
308
+ /**
309
+ * Display name
310
+ */
307
311
  name: '1 <= string <= 50',
308
312
  })
309
313
 
310
314
  export type User = typeof UserSchema.infer
311
315
 
312
316
  export const PostSchema = type({
313
- /** Primary key */
317
+ /**
318
+ * Primary key
319
+ */
314
320
  id: 'string.uuid',
315
- /** Article title */
321
+ /**
322
+ * Article title
323
+ */
316
324
  title: '1 <= string <= 100',
317
- /** Body content (no length limit) */
325
+ /**
326
+ * Body content (no length limit)
327
+ */
318
328
  content: 'string',
319
- /** Foreign key referencing User.id */
329
+ /**
330
+ * Foreign key referencing User.id
331
+ */
320
332
  userId: 'string.uuid',
321
333
  })
322
334
 
@@ -329,26 +341,38 @@ export type Post = typeof PostSchema.infer
329
341
  import { Schema } from 'effect'
330
342
 
331
343
  export const UserSchema = Schema.Struct({
332
- /** Primary key */
344
+ /**
345
+ * Primary key
346
+ */
333
347
  id: Schema.UUID,
334
- /** Display name */
348
+ /**
349
+ * Display name
350
+ */
335
351
  name: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50)),
336
352
  })
337
353
 
338
- export type User = Schema.Schema.Type<typeof UserSchema>
354
+ export type UserEncoded = typeof UserSchema.Encoded
339
355
 
340
356
  export const PostSchema = Schema.Struct({
341
- /** Primary key */
357
+ /**
358
+ * Primary key
359
+ */
342
360
  id: Schema.UUID,
343
- /** Article title */
361
+ /**
362
+ * Article title
363
+ */
344
364
  title: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(100)),
345
- /** Body content (no length limit) */
365
+ /**
366
+ * Body content (no length limit)
367
+ */
346
368
  content: Schema.String,
347
- /** Foreign key referencing User.id */
369
+ /**
370
+ * Foreign key referencing User.id
371
+ */
348
372
  userId: Schema.UUID,
349
373
  })
350
374
 
351
- export type Post = Schema.Schema.Type<typeof PostSchema>
375
+ export type PostEncoded = typeof PostSchema.Encoded
352
376
  ```
353
377
 
354
378
  ### TypeBox
@@ -357,22 +381,34 @@ export type Post = Schema.Schema.Type<typeof PostSchema>
357
381
  import { type Static, Type } from '@sinclair/typebox'
358
382
 
359
383
  export const UserSchema = Type.Object({
360
- /** Primary key */
384
+ /**
385
+ * Primary key
386
+ */
361
387
  id: Type.String({ format: 'uuid' }),
362
- /** Display name */
388
+ /**
389
+ * Display name
390
+ */
363
391
  name: Type.String({ minLength: 1, maxLength: 50 }),
364
392
  })
365
393
 
366
394
  export type User = Static<typeof UserSchema>
367
395
 
368
396
  export const PostSchema = Type.Object({
369
- /** Primary key */
397
+ /**
398
+ * Primary key
399
+ */
370
400
  id: Type.String({ format: 'uuid' }),
371
- /** Article title */
401
+ /**
402
+ * Article title
403
+ */
372
404
  title: Type.String({ minLength: 1, maxLength: 100 }),
373
- /** Body content (no length limit) */
405
+ /**
406
+ * Body content (no length limit)
407
+ */
374
408
  content: Type.String(),
375
- /** Foreign key referencing User.id */
409
+ /**
410
+ * Foreign key referencing User.id
411
+ */
376
412
  userId: Type.String({ format: 'uuid' }),
377
413
  })
378
414
 
@@ -393,7 +429,7 @@ export const PostRelationsSchema = Type.Object({
393
429
  export type PostRelations = Static<typeof PostRelationsSchema>
394
430
  ```
395
431
 
396
- ### AJV (JSON Schema)
432
+ ### AJV
397
433
 
398
434
  ```ts
399
435
  import type { FromSchema } from 'json-schema-to-ts'
@@ -401,9 +437,13 @@ import type { FromSchema } from 'json-schema-to-ts'
401
437
  export const UserSchema = {
402
438
  type: 'object' as const,
403
439
  properties: {
404
- /** Primary key */
440
+ /**
441
+ * Primary key
442
+ */
405
443
  id: { type: 'string' as const, format: 'uuid' as const },
406
- /** Display name */
444
+ /**
445
+ * Display name
446
+ */
407
447
  name: { type: 'string' as const, minLength: 1, maxLength: 50 },
408
448
  },
409
449
  required: ['id', 'name'] as const,
@@ -415,13 +455,21 @@ export type User = FromSchema<typeof UserSchema>
415
455
  export const PostSchema = {
416
456
  type: 'object' as const,
417
457
  properties: {
418
- /** Primary key */
458
+ /**
459
+ * Primary key
460
+ */
419
461
  id: { type: 'string' as const, format: 'uuid' as const },
420
- /** Article title */
462
+ /**
463
+ * Article title
464
+ */
421
465
  title: { type: 'string' as const, minLength: 1, maxLength: 100 },
422
- /** Body content (no length limit) */
466
+ /**
467
+ * Body content (no length limit)
468
+ */
423
469
  content: { type: 'string' as const },
424
- /** Foreign key referencing User.id */
470
+ /**
471
+ * Foreign key referencing User.id
472
+ */
425
473
  userId: { type: 'string' as const, format: 'uuid' as const },
426
474
  },
427
475
  required: ['id', 'title', 'content', 'userId'] as const,
@@ -1,6 +1,10 @@
1
1
  import { GeneratorOptions } from "@prisma/generator-helper";
2
2
 
3
3
  //#region src/generator/ajv/index.d.ts
4
+ /**
5
+ * Prisma generator entry point for AJV JSON Schema generation
6
+ * @param options - The Prisma generator options
7
+ */
4
8
  declare function main(options: GeneratorOptions): Promise<void>;
5
9
  //#endregion
6
10
  export { main };
@@ -1,17 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { a as makeCommentBlock, c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, p as writeFile, t as getBool } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
8
8
  //#region src/helper/ajv.ts
9
+ /**
10
+ * Generate AJV type inference using FromSchema
11
+ * @param modelName - The model name to generate type inference for
12
+ */
9
13
  function makeAjvInfer(modelName) {
10
14
  return `export type ${modelName} = FromSchema<typeof ${modelName}Schema>`;
11
15
  }
16
+ /**
17
+ * Generate JSON Schema enum expression for AJV
18
+ * @param values - The enum values to generate expression for
19
+ */
12
20
  function makeAjvEnumExpression(values) {
13
21
  return `{ enum: [${values.map((v) => `'${v}'`).join(", ")}] as const }`;
14
22
  }
23
+ /** Mapping from Prisma scalar types to JSON Schema type expressions */
15
24
  const PRISMA_TO_AJV = {
16
25
  String: "{ type: 'string' as const }",
17
26
  Int: "{ type: 'integer' as const }",
@@ -23,14 +32,25 @@ const PRISMA_TO_AJV = {
23
32
  Json: "{}",
24
33
  Bytes: "{ type: 'string' as const }"
25
34
  };
35
+ /**
36
+ * Generate JSON Schema object definition for a model
37
+ * @param modelFields - The fields of the model
38
+ * @param comment - Whether to include JSDoc comments in the generated code
39
+ */
26
40
  function makeAjvSchemas(modelFields, comment) {
27
41
  const modelName = modelFields[0].modelName;
28
42
  const properties = modelFields.map((field) => {
29
- return `${comment && field.comment.length > 0 ? `${field.comment.map((c) => ` /** ${c} */`).join("\n")}\n` : ""} ${field.fieldName}: ${field.validation ?? "{ type: 'unknown' as const }"},`;
43
+ return `${comment ? makeCommentBlock(field.comment, 4) : ""} ${field.fieldName}: ${field.validation ?? "{ type: 'unknown' as const }"},`;
30
44
  }).join("\n");
31
45
  const requiredFields = modelFields.filter((f) => f.isRequired).map((f) => f.fieldName);
32
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`;
33
47
  }
48
+ /**
49
+ * Generate JSON Schema relation object definition
50
+ * @param model - The model to generate relations for
51
+ * @param relProps - The relation properties
52
+ * @param options - Options for type export generation
53
+ */
34
54
  function makeAjvRelations(model, relProps, options) {
35
55
  if (relProps.length === 0) return null;
36
56
  const base = ` ...${model.name}Schema.properties,`;
@@ -38,6 +58,13 @@ function makeAjvRelations(model, relProps, options) {
38
58
  const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = FromSchema<typeof ${model.name}RelationsSchema>` : "";
39
59
  return `export const ${model.name}RelationsSchema = {\n type: 'object' as const,\n properties: {\n${base}\n${rels}\n },\n additionalProperties: false,\n} as const${typeLine}`;
40
60
  }
61
+ /**
62
+ * Generate AJV-compatible JSON Schema validation code from Prisma models
63
+ * @param models - The Prisma data models
64
+ * @param type - Whether to include type inference using FromSchema
65
+ * @param comment - Whether to include JSDoc comments in the generated code
66
+ * @param enums - The Prisma enum definitions
67
+ */
41
68
  function ajv(models, type, comment, enums) {
42
69
  return validationSchemas(models, type, comment, {
43
70
  importStatement: type ? `import type { FromSchema } from 'json-schema-to-ts'` : "",
@@ -55,6 +82,10 @@ function ajv(models, type, comment, enums) {
55
82
  //#endregion
56
83
  //#region src/generator/ajv/index.ts
57
84
  const { generatorHandler } = pkg;
85
+ /**
86
+ * Prisma generator entry point for AJV JSON Schema generation
87
+ * @param options - The Prisma generator options
88
+ */
58
89
  async function main(options) {
59
90
  if (!(options.generator.isCustomOutput && options.generator.output?.value)) throw new Error("output is required for Hekireki-AJV. Please specify output in your generator config.");
60
91
  const output = options.generator.output.value;
@@ -1,6 +1,10 @@
1
1
  import { GeneratorOptions } from "@prisma/generator-helper";
2
2
 
3
3
  //#region src/generator/arktype/index.d.ts
4
+ /**
5
+ * Prisma generator entry point for ArkType schema generation
6
+ * @param options - The Prisma generator options
7
+ */
4
8
  declare function main(options: GeneratorOptions): Promise<void>;
5
9
  //#endregion
6
10
  export { main };
@@ -1,25 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, l as schemaFromFields, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { a as makeCommentBlock, c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, p as writeFile, t as getBool, u as schemaFromFields } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
8
8
  //#region src/helper/arktype.ts
9
+ /**
10
+ * Generate ArkType type inference
11
+ * @param modelName - The model name to generate type inference for
12
+ */
9
13
  function makeArktypeInfer(modelName) {
10
14
  return `export type ${modelName} = typeof ${modelName}Schema.infer`;
11
15
  }
16
+ /**
17
+ * Generate ArkType type() schema definition
18
+ * @param modelName - The model name for the schema
19
+ * @param fields - The formatted field definitions string
20
+ */
12
21
  function makeArktypeSchema(modelName, fields) {
13
22
  return `export const ${modelName}Schema = type({\n${fields}\n})`;
14
23
  }
24
+ /**
25
+ * Generate ArkType property definitions
26
+ * @param fields - The fields to generate properties for
27
+ * @param comment - Whether to include JSDoc comments in the generated code
28
+ */
15
29
  function makeArktypeProperties(fields, comment) {
16
30
  return fields.map((field) => {
17
- return `${comment && field.comment.length > 0 ? `${field.comment.map((c) => ` /** ${c} */`).join("\n")}\n` : ""} ${field.fieldName}: ${field.validation ?? "\"unknown\""},`;
31
+ return `${comment ? makeCommentBlock(field.comment, 2) : ""} ${field.fieldName}: ${field.validation ?? "\"unknown\""},`;
18
32
  }).join("\n");
19
33
  }
34
+ /**
35
+ * Generate ArkType enum expression using union string syntax
36
+ * @param values - The enum values to generate expression for
37
+ */
20
38
  function makeArktypeEnumExpression(values) {
21
39
  return `"${values.map((v) => `'${v}'`).join(" | ")}"`;
22
40
  }
41
+ /** Mapping from Prisma scalar types to ArkType type expressions */
23
42
  const PRISMA_TO_ARKTYPE = {
24
43
  String: "\"string\"",
25
44
  Int: "\"number\"",
@@ -31,15 +50,33 @@ const PRISMA_TO_ARKTYPE = {
31
50
  Json: "\"unknown\"",
32
51
  Bytes: "\"unknown\""
33
52
  };
53
+ /**
54
+ * Generate ArkType type() schema from model fields
55
+ * @param modelFields - The fields of the model
56
+ * @param comment - Whether to include JSDoc comments in the generated code
57
+ */
34
58
  function makeArktypeSchemas(modelFields, comment) {
35
59
  return schemaFromFields(modelFields, comment, makeArktypeSchema, makeArktypeProperties);
36
60
  }
61
+ /**
62
+ * Generate ArkType relation schema definition
63
+ * @param model - The model to generate relations for
64
+ * @param relProps - The relation properties
65
+ * @param options - Options for type export generation
66
+ */
37
67
  function makeArktypeRelations(model, relProps, options) {
38
68
  if (relProps.length === 0) return null;
39
69
  const fields = `${`...${model.name}Schema.t,`}${relProps.map((r) => `${r.key}:${r.isMany ? `${r.targetModel}Schema.array()` : `${r.targetModel}Schema`},`).join("")}`;
40
70
  const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = typeof ${model.name}RelationsSchema.infer` : "";
41
71
  return `export const ${model.name}RelationsSchema = type({${fields}})${typeLine}`;
42
72
  }
73
+ /**
74
+ * Generate ArkType validation code from Prisma models
75
+ * @param models - The Prisma data models
76
+ * @param type - Whether to include type inference
77
+ * @param comment - Whether to include JSDoc comments in the generated code
78
+ * @param enums - The Prisma enum definitions
79
+ */
43
80
  function arktype(models, type, comment, enums) {
44
81
  return validationSchemas(models, type, comment, {
45
82
  importStatement: `import { type } from 'arktype'`,
@@ -57,6 +94,10 @@ function arktype(models, type, comment, enums) {
57
94
  //#endregion
58
95
  //#region src/generator/arktype/index.ts
59
96
  const { generatorHandler } = pkg;
97
+ /**
98
+ * Prisma generator entry point for ArkType schema generation
99
+ * @param options - The Prisma generator options
100
+ */
60
101
  async function main(options) {
61
102
  if (!(options.generator.isCustomOutput && options.generator.output?.value)) throw new Error("output is required for Hekireki-ArkType. Please specify output in your generator config.");
62
103
  const output = options.generator.output.value;
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as mkdir, f as writeFile, n as getString, p as writeFileBinary, u as stripAnnotations } from "../../utils-0tE5jzYR.js";
2
+ import { d as stripAnnotations, f as mkdir, m as writeFileBinary, n as getString, p as writeFile } from "../../utils-BGe939v0.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 { d as mkdir, f as writeFile, o as makeSnakeCase } from "../../utils-0tE5jzYR.js";
3
+ import { f as mkdir, p as writeFile, s as makeSnakeCase } from "../../utils-BGe939v0.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 { d as mkdir, f as writeFile, o as makeSnakeCase } from "../../utils-0tE5jzYR.js";
2
+ import { f as mkdir, p as writeFile, s as makeSnakeCase } from "../../utils-BGe939v0.js";
3
3
  import { join } from "node:path";
4
4
  import pkg from "@prisma/generator-helper";
5
5
 
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, l as schemaFromFields, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { a as makeCommentBlock, c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, p as writeFile, t as getBool, u as schemaFromFields } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
8
8
  //#region src/helper/effect.ts
9
9
  function makeEffectInfer(modelName) {
10
- return `export type ${modelName} = Schema.Schema.Type<typeof ${modelName}Schema>`;
10
+ return `export type ${modelName}Encoded = typeof ${modelName}Schema.Encoded`;
11
11
  }
12
12
  function makeEffectSchema(modelName, fields) {
13
13
  return `export const ${modelName}Schema = Schema.Struct({\n${fields}\n})`;
14
14
  }
15
15
  function makeEffectProperties(fields, comment) {
16
16
  return fields.map((field) => {
17
- return `${comment && field.comment.length > 0 ? `${field.comment.map((c) => ` /** ${c} */`).join("\n")}\n` : ""} ${field.fieldName}: ${field.validation ?? "Schema.Unknown"},`;
17
+ return `${comment ? makeCommentBlock(field.comment, 2) : ""} ${field.fieldName}: ${field.validation ?? "Schema.Unknown"},`;
18
18
  }).join("\n");
19
19
  }
20
20
  function makeEffectEnumExpression(values) {
@@ -37,7 +37,7 @@ function makeEffectSchemas(modelFields, comment) {
37
37
  function makeEffectRelations(model, relProps, options) {
38
38
  if (relProps.length === 0) return null;
39
39
  const fields = `${`...${model.name}Schema.fields,`}${relProps.map((r) => `${r.key}:${r.isMany ? `Schema.Array(${r.targetModel}Schema)` : `${r.targetModel}Schema`},`).join("")}`;
40
- const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = Schema.Schema.Type<typeof ${model.name}RelationsSchema>` : "";
40
+ const typeLine = options?.includeType ? `\n\nexport type ${model.name}RelationsEncoded = typeof ${model.name}RelationsSchema.Encoded` : "";
41
41
  return `export const ${model.name}RelationsSchema = Schema.Struct({${fields}})${typeLine}`;
42
42
  }
43
43
  function effect(models, type, comment, enums) {
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as mkdir, f as writeFile, n as getString, o as makeSnakeCase } from "../../utils-0tE5jzYR.js";
2
+ import { f as mkdir, n as getString, p as writeFile, s as makeSnakeCase } from "../../utils-BGe939v0.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 { d as mkdir, f as writeFile, u as stripAnnotations } from "../../utils-0tE5jzYR.js";
2
+ import { d as stripAnnotations, f as mkdir, p as writeFile } from "../../utils-BGe939v0.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 { d as mkdir, f as writeFile, n as getString, o as makeSnakeCase } from "../../utils-0tE5jzYR.js";
2
+ import { f as mkdir, n as getString, p as writeFile, s as makeSnakeCase } from "../../utils-BGe939v0.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 { d as mkdir, f as writeFile, o as makeSnakeCase } from "../../utils-0tE5jzYR.js";
2
+ import { f as mkdir, p as writeFile, s as makeSnakeCase } from "../../utils-BGe939v0.js";
3
3
  import path, { dirname } from "node:path";
4
4
  import pkg from "@prisma/generator-helper";
5
5
 
@@ -1,6 +1,10 @@
1
1
  import { GeneratorOptions } from "@prisma/generator-helper";
2
2
 
3
3
  //#region src/generator/typebox/index.d.ts
4
+ /**
5
+ * Prisma generator entry point for TypeBox schema generation
6
+ * @param options - The Prisma generator options
7
+ */
4
8
  declare function main(options: GeneratorOptions): Promise<void>;
5
9
  //#endregion
6
10
  export { main };
@@ -1,28 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, l as schemaFromFields, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { a as makeCommentBlock, c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, p as writeFile, t as getBool, u as schemaFromFields } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
8
8
  //#region src/helper/typebox.ts
9
+ /**
10
+ * Generate TypeBox type inference using Static
11
+ * @param modelName - The model name to generate type inference for
12
+ */
9
13
  function makeTypeBoxInfer(modelName) {
10
14
  return `export type ${modelName} = Static<typeof ${modelName}Schema>`;
11
15
  }
16
+ /**
17
+ * Generate TypeBox Type.Object schema definition
18
+ * @param modelName - The model name for the schema
19
+ * @param fields - The formatted field definitions string
20
+ */
12
21
  function makeTypeBoxSchema(modelName, fields) {
13
22
  return `export const ${modelName}Schema = Type.Object({\n${fields}\n})`;
14
23
  }
24
+ /**
25
+ * Generate TypeBox property definitions with optional wrapping
26
+ * @param fields - The fields to generate properties for
27
+ * @param comment - Whether to include JSDoc comments in the generated code
28
+ */
15
29
  function makeTypeBoxProperties(fields, comment) {
16
30
  return fields.map((field) => {
17
- const commentLines = comment && field.comment.length > 0 ? `${field.comment.map((c) => ` /** ${c} */`).join("\n")}\n` : "";
31
+ const commentBlock = comment ? makeCommentBlock(field.comment, 2) : "";
18
32
  const expr = field.validation ?? "Type.Unknown()";
19
33
  const wrapped = field.isRequired ? expr : `Type.Optional(${expr})`;
20
- return `${commentLines} ${field.fieldName}: ${wrapped},`;
34
+ return `${commentBlock} ${field.fieldName}: ${wrapped},`;
21
35
  }).join("\n");
22
36
  }
37
+ /**
38
+ * Generate TypeBox enum expression using Type.Union with Type.Literal
39
+ * @param values - The enum values to generate expression for
40
+ */
23
41
  function makeTypeBoxEnumExpression(values) {
24
42
  return `Type.Union([${values.map((v) => `Type.Literal('${v}')`).join(", ")}])`;
25
43
  }
44
+ /** Mapping from Prisma scalar types to TypeBox type expressions */
26
45
  const PRISMA_TO_TYPEBOX = {
27
46
  String: "Type.String()",
28
47
  Int: "Type.Integer()",
@@ -34,9 +53,20 @@ const PRISMA_TO_TYPEBOX = {
34
53
  Json: "Type.Unknown()",
35
54
  Bytes: "Type.Any()"
36
55
  };
56
+ /**
57
+ * Generate TypeBox Type.Object schema from model fields
58
+ * @param modelFields - The fields of the model
59
+ * @param comment - Whether to include JSDoc comments in the generated code
60
+ */
37
61
  function makeTypeBoxSchemas(modelFields, comment) {
38
62
  return schemaFromFields(modelFields, comment, makeTypeBoxSchema, makeTypeBoxProperties);
39
63
  }
64
+ /**
65
+ * Generate TypeBox relation schema definition
66
+ * @param model - The model to generate relations for
67
+ * @param relProps - The relation properties
68
+ * @param options - Options for type export generation
69
+ */
40
70
  function makeTypeBoxRelations(model, relProps, options) {
41
71
  if (relProps.length === 0) return null;
42
72
  const base = ` ...${model.name}Schema.properties,`;
@@ -44,6 +74,13 @@ function makeTypeBoxRelations(model, relProps, options) {
44
74
  const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = Static<typeof ${model.name}RelationsSchema>` : "";
45
75
  return `export const ${model.name}RelationsSchema = Type.Object({\n${base}\n${rels}\n})${typeLine}`;
46
76
  }
77
+ /**
78
+ * Generate TypeBox validation code from Prisma models
79
+ * @param models - The Prisma data models
80
+ * @param type - Whether to include type inference using Static
81
+ * @param comment - Whether to include JSDoc comments in the generated code
82
+ * @param enums - The Prisma enum definitions
83
+ */
47
84
  function typebox(models, type, comment, enums) {
48
85
  return validationSchemas(models, type, comment, {
49
86
  importStatement: type ? `import { type Static, Type } from '@sinclair/typebox'` : `import { Type } from '@sinclair/typebox'`,
@@ -61,6 +98,10 @@ function typebox(models, type, comment, enums) {
61
98
  //#endregion
62
99
  //#region src/generator/typebox/index.ts
63
100
  const { generatorHandler } = pkg;
101
+ /**
102
+ * Prisma generator entry point for TypeBox schema generation
103
+ * @param options - The Prisma generator options
104
+ */
64
105
  async function main(options) {
65
106
  if (!(options.generator.isCustomOutput && options.generator.output?.value)) throw new Error("output is required for Hekireki-TypeBox. Please specify output in your generator config.");
66
107
  const output = options.generator.output.value;
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { a as makePropertiesGenerator, c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, l as schemaFromFields, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, o as makePropertiesGenerator, p as writeFile, t as getBool, u as schemaFromFields } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
8
8
  //#region src/helper/valibot.ts
9
9
  function makeValibotInfer(modelName) {
10
- return `export type ${modelName} = v.InferInput<typeof ${modelName}Schema>`;
10
+ return `export type ${modelName} = v.InferOutput<typeof ${modelName}Schema>`;
11
11
  }
12
12
  function makeValibotSchema(modelName, fields) {
13
13
  return `export const ${modelName}Schema = v.object({\n${fields}\n})`;
@@ -33,7 +33,7 @@ function makeValibotRelations(model, relProps, options) {
33
33
  if (relProps.length === 0) return null;
34
34
  const base = ` ...${model.name}Schema.entries,`;
35
35
  const rels = relProps.map((r) => ` ${r.key}: ${r.isMany ? `v.array(${r.targetModel}Schema)` : `${r.targetModel}Schema`},`).join("\n");
36
- const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = v.InferInput<typeof ${model.name}RelationsSchema>` : "";
36
+ const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = v.InferOutput<typeof ${model.name}RelationsSchema>` : "";
37
37
  return `export const ${model.name}RelationsSchema = v.object({\n${base}\n${rels}\n})${typeLine}`;
38
38
  }
39
39
  function valibot(models, type, comment, enums) {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as fmt } from "../../format-DwiYldCm.js";
3
- import { a as makePropertiesGenerator, c as parseDocumentWithoutAnnotations, d as mkdir, f as writeFile, l as schemaFromFields, n as getString, s as makeValidationExtractor, t as getBool } from "../../utils-0tE5jzYR.js";
4
- import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-DHllEbMR.js";
3
+ import { c as makeValidationExtractor, f as mkdir, l as parseDocumentWithoutAnnotations, n as getString, o as makePropertiesGenerator, p as writeFile, t as getBool, u as schemaFromFields } from "../../utils-BGe939v0.js";
4
+ import { n as validationSchemas, t as makeRelationsOnly } from "../../prisma-CfcdmYJs.js";
5
5
  import path from "node:path";
6
6
  import pkg from "@prisma/generator-helper";
7
7
 
@@ -1,4 +1,4 @@
1
- import { i as isFields, r as groupByModel } from "./utils-0tE5jzYR.js";
1
+ import { i as isFields, r as groupByModel } from "./utils-BGe939v0.js";
2
2
 
3
3
  //#region src/helper/prisma.ts
4
4
  function collectRelationProps(models) {
@@ -56,11 +56,21 @@ function stripAnnotations(doc) {
56
56
  }).join("\n").trim();
57
57
  return result.length > 0 ? result : void 0;
58
58
  }
59
+ /**
60
+ * Generate a JSDoc comment block from comment lines
61
+ * @param lines - The comment lines to include
62
+ * @param indent - The indentation level in spaces
63
+ */
64
+ function makeCommentBlock(lines, indent) {
65
+ if (lines.length === 0) return "";
66
+ const prefix = " ".repeat(indent);
67
+ return `${prefix}/**\n${lines.map((c) => `${prefix} * ${c}`).join("\n")}\n${prefix} */\n`;
68
+ }
59
69
  function makePropertiesGenerator(libraryPrefix, wrapCardinality) {
60
70
  return function makeProperties(modelFields, includeComments) {
61
71
  return modelFields.filter((field) => field.validation).map((field) => {
62
72
  const cleanLines = field.comment.filter((line) => !(line.includes("@relation") || line.includes("@z") || line.includes("@v") || line.includes("@a") || line.includes("@e") || line.includes("@t") || line.includes("@j")));
63
- const docComment = includeComments && cleanLines.length > 0 ? ` /**\n${cleanLines.map((line) => ` * ${line}`).join("\n")}\n */\n` : "";
73
+ const docComment = includeComments ? makeCommentBlock(cleanLines, 2) : "";
64
74
  const base = `${libraryPrefix}.${field.validation}`;
65
75
  const wrapped = wrapCardinality ? wrapCardinality(base, field.isRequired) : base;
66
76
  return `${docComment} ${field.fieldName}: ${wrapped}`;
@@ -80,4 +90,4 @@ function schemaFromFields(modelFields, comment, schemaBuilder, propertiesGenerat
80
90
  }
81
91
 
82
92
  //#endregion
83
- export { makePropertiesGenerator as a, parseDocumentWithoutAnnotations as c, mkdir as d, writeFile as f, isFields as i, schemaFromFields as l, getString as n, makeSnakeCase as o, writeFileBinary as p, groupByModel as r, makeValidationExtractor as s, getBool as t, stripAnnotations as u };
93
+ export { makeCommentBlock as a, makeValidationExtractor as c, stripAnnotations as d, mkdir as f, isFields as i, parseDocumentWithoutAnnotations as l, writeFileBinary as m, getString as n, makePropertiesGenerator as o, writeFile as p, groupByModel as r, makeSnakeCase as s, getBool as t, schemaFromFields as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hekireki",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
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",