hekireki 0.4.2 → 0.5.0

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 (72) hide show
  1. package/README.md +180 -20
  2. package/dist/dbml-content-D3ioOw2D.js +151 -0
  3. package/dist/fsp-DYtOxLN_.js +68 -0
  4. package/dist/generator/arktype/index.d.ts +6 -0
  5. package/dist/generator/arktype/index.js +94 -0
  6. package/dist/generator/dbml/index.d.ts +6 -0
  7. package/dist/generator/dbml/index.js +49 -0
  8. package/dist/generator/ecto/index.d.ts +6 -3
  9. package/dist/generator/ecto/index.js +150 -13
  10. package/dist/generator/effect/index.d.ts +6 -0
  11. package/dist/generator/effect/index.js +94 -0
  12. package/dist/generator/mermaid-er/index.d.ts +6 -3
  13. package/dist/generator/mermaid-er/index.js +136 -21
  14. package/dist/generator/svg/index.d.ts +6 -0
  15. package/dist/generator/svg/index.js +74 -0
  16. package/dist/generator/valibot/index.d.ts +6 -3
  17. package/dist/generator/valibot/index.js +91 -45
  18. package/dist/generator/zod/index.d.ts +6 -3
  19. package/dist/generator/zod/index.js +98 -56
  20. package/dist/relations-CxeKj9KD.js +12 -0
  21. package/dist/utils-CXBzdZih.js +134 -0
  22. package/package.json +29 -17
  23. package/dist/generator/ecto/generator/ecto.d.ts +0 -3
  24. package/dist/generator/ecto/generator/ecto.js +0 -131
  25. package/dist/generator/ecto/utils/index.d.ts +0 -1
  26. package/dist/generator/ecto/utils/index.js +0 -1
  27. package/dist/generator/ecto/utils/prisma-type-to-ecto-type.d.ts +0 -1
  28. package/dist/generator/ecto/utils/prisma-type-to-ecto-type.js +0 -11
  29. package/dist/generator/mermaid-er/generator/er-content.d.ts +0 -8
  30. package/dist/generator/mermaid-er/generator/er-content.js +0 -23
  31. package/dist/generator/mermaid-er/generator/index.d.ts +0 -4
  32. package/dist/generator/mermaid-er/generator/index.js +0 -4
  33. package/dist/generator/mermaid-er/generator/model-fields.d.ts +0 -8
  34. package/dist/generator/mermaid-er/generator/model-fields.js +0 -25
  35. package/dist/generator/mermaid-er/generator/model-info.d.ts +0 -8
  36. package/dist/generator/mermaid-er/generator/model-info.js +0 -10
  37. package/dist/generator/mermaid-er/generator/relation-line.d.ts +0 -13
  38. package/dist/generator/mermaid-er/generator/relation-line.js +0 -14
  39. package/dist/generator/mermaid-er/helper/build-relation-line.d.ts +0 -9
  40. package/dist/generator/mermaid-er/helper/build-relation-line.js +0 -37
  41. package/dist/generator/mermaid-er/helper/extract-relations.d.ts +0 -8
  42. package/dist/generator/mermaid-er/helper/extract-relations.js +0 -22
  43. package/dist/generator/mermaid-er/utils/index.d.ts +0 -34
  44. package/dist/generator/mermaid-er/utils/index.js +0 -48
  45. package/dist/generator/valibot/generator/index.d.ts +0 -3
  46. package/dist/generator/valibot/generator/index.js +0 -3
  47. package/dist/generator/valibot/generator/schema.d.ts +0 -16
  48. package/dist/generator/valibot/generator/schema.js +0 -51
  49. package/dist/generator/valibot/generator/schemas.d.ts +0 -13
  50. package/dist/generator/valibot/generator/schemas.js +0 -17
  51. package/dist/generator/valibot/generator/valibot.d.ts +0 -9
  52. package/dist/generator/valibot/generator/valibot.js +0 -42
  53. package/dist/generator/valibot/utils/index.d.ts +0 -44
  54. package/dist/generator/valibot/utils/index.js +0 -75
  55. package/dist/generator/zod/generator/index.d.ts +0 -3
  56. package/dist/generator/zod/generator/index.js +0 -3
  57. package/dist/generator/zod/generator/schema.d.ts +0 -17
  58. package/dist/generator/zod/generator/schema.js +0 -38
  59. package/dist/generator/zod/generator/schemas.d.ts +0 -13
  60. package/dist/generator/zod/generator/schemas.js +0 -17
  61. package/dist/generator/zod/generator/zod.d.ts +0 -9
  62. package/dist/generator/zod/generator/zod.js +0 -47
  63. package/dist/generator/zod/utils/index.d.ts +0 -46
  64. package/dist/generator/zod/utils/index.js +0 -75
  65. package/dist/shared/format/index.d.ts +0 -1
  66. package/dist/shared/format/index.js +0 -9
  67. package/dist/shared/generator/index.d.ts +0 -11
  68. package/dist/shared/generator/index.js +0 -23
  69. package/dist/shared/helper/relations.d.ts +0 -7
  70. package/dist/shared/helper/relations.js +0 -5
  71. package/dist/shared/utils/index.d.ts +0 -61
  72. package/dist/shared/utils/index.js +0 -63
@@ -1,44 +0,0 @@
1
- /**
2
- * Generates a `v.InferInput` type for the specified model.
3
- *
4
- * @param modelName - The name of the model.
5
- * @returns The generated TypeScript type definition line.
6
- */
7
- export declare function inferInput(modelName: string): string;
8
- /**
9
- * Generates Valibot property definitions from model fields.
10
- *
11
- * Filters out fields without validation, removes documentation tags like
12
- * @relation, @v, @z, and optionally includes doc comments.
13
- *
14
- * @param modelFields - The list of model fields with metadata.
15
- * @param comment - Whether to include documentation comments.
16
- * @returns A string containing formatted Valibot property definitions.
17
- */
18
- export declare function properties(modelFields: {
19
- documentation: string;
20
- modelName: string;
21
- fieldName: string;
22
- validation: string | null;
23
- comment: string[];
24
- }[], comment: boolean): string;
25
- /**
26
- * Parses documentation lines and filters out Valibot validation entries.
27
- *
28
- * Lines containing "@v." will be excluded.
29
- *
30
- * @param documentation - The raw documentation string.
31
- * @returns An array of non-Valibot documentation lines.
32
- */
33
- export declare function isValibotDocument(documentation?: string): string[];
34
- /**
35
- * Extracts the Valibot validation expression from a documentation string.
36
- *
37
- * Searches for a line starting with "@v." and returns the expression that follows.
38
- *
39
- * @param documentation - The documentation string to search.
40
- * @returns The Valibot expression without "@v." prefix, or null if not found.
41
- */
42
- export declare function isValibot(documentation?: string): string | null;
43
- export declare const extractAnno: (doc: string, tag: "@z." | "@v.") => string | null;
44
- export declare const jsdoc: (doc?: string) => string;
@@ -1,75 +0,0 @@
1
- /**
2
- * Generates a `v.InferInput` type for the specified model.
3
- *
4
- * @param modelName - The name of the model.
5
- * @returns The generated TypeScript type definition line.
6
- */
7
- export function inferInput(modelName) {
8
- return `export type ${modelName} = v.InferInput<typeof ${modelName}Schema>`;
9
- }
10
- /**
11
- * Generates Valibot property definitions from model fields.
12
- *
13
- * Filters out fields without validation, removes documentation tags like
14
- * @relation, @v, @z, and optionally includes doc comments.
15
- *
16
- * @param modelFields - The list of model fields with metadata.
17
- * @param comment - Whether to include documentation comments.
18
- * @returns A string containing formatted Valibot property definitions.
19
- */
20
- export function properties(modelFields, comment) {
21
- const fields = modelFields
22
- .filter((field) => field.validation)
23
- .map((field) => {
24
- const cleanDoc = field.comment
25
- .filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
26
- .join('\n')
27
- .trim();
28
- const docComment = comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
29
- return `${docComment} ${field.fieldName}: v.${field.validation}`;
30
- })
31
- .join(',\n');
32
- return fields;
33
- }
34
- /**
35
- * Parses documentation lines and filters out Valibot validation entries.
36
- *
37
- * Lines containing "@v." will be excluded.
38
- *
39
- * @param documentation - The raw documentation string.
40
- * @returns An array of non-Valibot documentation lines.
41
- */
42
- export function isValibotDocument(documentation) {
43
- return (documentation
44
- ?.split('\n')
45
- .map((line) => line.trim())
46
- .filter((line) => line && !line.includes('@v.')) ?? []);
47
- }
48
- /**
49
- * Extracts the Valibot validation expression from a documentation string.
50
- *
51
- * Searches for a line starting with "@v." and returns the expression that follows.
52
- *
53
- * @param documentation - The documentation string to search.
54
- * @returns The Valibot expression without "@v." prefix, or null if not found.
55
- */
56
- export function isValibot(documentation) {
57
- if (!documentation)
58
- return null;
59
- const match = documentation.match(/@v\.(.+?)(?:\n|$)/);
60
- return match ? match[1].trim() : null;
61
- }
62
- export const extractAnno = (doc, tag) => {
63
- const line = doc
64
- .split('\n')
65
- .map((s) => s.trim())
66
- .find((l) => l.startsWith(tag));
67
- return line ? line.slice(tag.length) : null;
68
- };
69
- export const jsdoc = (doc) => {
70
- const lines = (doc ?? '')
71
- .split('\n')
72
- .map((s) => s.trim())
73
- .filter((l) => l && !l.startsWith('@z.') && !l.startsWith('@v.'));
74
- return lines.length ? `/**\n * ${lines.join('\n * ')}\n */\n` : '';
75
- };
@@ -1,3 +0,0 @@
1
- export { schema } from './schema.js';
2
- export { schemas } from './schemas.js';
3
- export { zod } from './zod.js';
@@ -1,3 +0,0 @@
1
- export { schema } from './schema.js';
2
- export { schemas } from './schemas.js';
3
- export { zod } from './zod.js';
@@ -1,17 +0,0 @@
1
- import type { DMMF } from '@prisma/generator-helper';
2
- export declare function buildZodModel(model: DMMF.Model): Readonly<string>;
3
- export declare function buildZodRelations(model: DMMF.Model, relProps: readonly {
4
- key: string;
5
- targetModel: string;
6
- isMany: boolean;
7
- }[], options?: Readonly<{
8
- includeType?: boolean;
9
- }>): string | null;
10
- /**
11
- * Generate Zod schema
12
- * @param modelName - The name of the model
13
- * @param fields - The fields of the model
14
- * @param config - The configuration for the generator
15
- * @returns The generated Zod schema
16
- */
17
- export declare function schema(modelName: string, fields: string): string;
@@ -1,38 +0,0 @@
1
- import { buildZodObject, extractAnno, jsdoc, wrapCardinality } from '../utils/index.js';
2
- const zPrim = (f) => {
3
- const anno = extractAnno(f.documentation ?? '', '@z.');
4
- return wrapCardinality(`z.${anno}`, f);
5
- };
6
- // moved to utils
7
- export function buildZodModel(model) {
8
- const fields = model.fields
9
- .filter((f) => f.kind !== 'object')
10
- .map((f) => `${jsdoc(f.documentation)} ${f.name}: ${zPrim(f)},`)
11
- .join('\n');
12
- const objectDef = buildZodObject(fields, model.documentation);
13
- return `export const ${model.name}Schema = ${objectDef}\n\nexport type ${model.name} = z.infer<typeof ${model.name}Schema>`;
14
- }
15
- export function buildZodRelations(model, relProps, options) {
16
- if (relProps.length === 0)
17
- return null;
18
- const base = `...${model.name}Schema.shape`;
19
- const rels = relProps
20
- .map((r) => `${r.key}:${r.isMany ? `z.array(${r.targetModel}Schema)` : `${r.targetModel}Schema`}`)
21
- .join(',');
22
- const objectDef = buildZodObject(`${base},${rels}`, model.documentation);
23
- const typeLine = options?.includeType
24
- ? `\n\nexport type ${model.name}Relations = z.infer<typeof ${model.name}RelationsSchema>`
25
- : '';
26
- return `export const ${model.name}RelationsSchema = ${objectDef}${typeLine}`;
27
- }
28
- // moved to utils
29
- /**
30
- * Generate Zod schema
31
- * @param modelName - The name of the model
32
- * @param fields - The fields of the model
33
- * @param config - The configuration for the generator
34
- * @returns The generated Zod schema
35
- */
36
- export function schema(modelName, fields) {
37
- return `export const ${modelName}Schema = z.object({\n${fields}\n})`;
38
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Generate Zod schemas
3
- * @param modelFields - The fields of the model
4
- * @param config - The configuration for the generator
5
- * @returns The generated Zod schemas
6
- */
7
- export declare function schemas(modelFields: {
8
- documentation: string;
9
- modelName: string;
10
- fieldName: string;
11
- validation: string | null;
12
- comment: string[];
13
- }[], comment: boolean): string;
@@ -1,17 +0,0 @@
1
- import { properties } from '../utils/index.js';
2
- import { schema } from './index.js';
3
- /**
4
- * Generate Zod schemas
5
- * @param modelFields - The fields of the model
6
- * @param config - The configuration for the generator
7
- * @returns The generated Zod schemas
8
- */
9
- export function schemas(modelFields, comment) {
10
- const modelName = modelFields[0].modelName;
11
- const modelDoc = modelFields[0].documentation || '';
12
- const fields = properties(modelFields, comment);
13
- if (!(modelDoc || !comment)) {
14
- return schema(modelName, fields);
15
- }
16
- return `${schema(modelName, fields)}`;
17
- }
@@ -1,9 +0,0 @@
1
- import type { DMMF } from '@prisma/generator-helper';
2
- /**
3
- * Generate Zod schemas and types
4
- * @param models - The models to generate the Zod schemas and types for
5
- * @param type - Whether to generate types
6
- * @param comment - Whether to include comments in the generated code
7
- * @returns The generated Zod schemas and types
8
- */
9
- export declare function zod(models: readonly Readonly<DMMF.Model>[], type: boolean, comment: boolean, zodVersion?: string | string[]): string;
@@ -1,47 +0,0 @@
1
- import { groupByModel, isFields } from '../../../shared/utils/index.js';
2
- import { infer, isZod, isZodDocument } from '../utils/index.js';
3
- import { schemas } from './schemas.js';
4
- /**
5
- * Generate Zod schemas and types
6
- * @param models - The models to generate the Zod schemas and types for
7
- * @param type - Whether to generate types
8
- * @param comment - Whether to include comments in the generated code
9
- * @returns The generated Zod schemas and types
10
- */
11
- export function zod(models, type, comment, zodVersion) {
12
- const modelInfos = models.map((model) => {
13
- return {
14
- documentation: model.documentation ?? '',
15
- name: model.name,
16
- fields: model.fields,
17
- };
18
- });
19
- const modelFields = modelInfos.map((model) => {
20
- const fields = model.fields.map((field) => ({
21
- documentation: model.documentation,
22
- modelName: model.name,
23
- fieldName: field.name,
24
- comment: isZodDocument(field.documentation),
25
- validation: isZod(field.documentation),
26
- }));
27
- return fields;
28
- });
29
- const zods = Object.values(groupByModel(isFields(modelFields))).map((fields) => {
30
- return {
31
- generateZodSchema: schemas(fields, comment),
32
- generateZodInfer: type ? infer(fields[0].modelName) : '',
33
- };
34
- });
35
- const importStatement = zodVersion === 'mini'
36
- ? `import * as z from 'zod/mini'`
37
- : zodVersion === '@hono/zod-openapi'
38
- ? `import { z } from '@hono/zod-openapi'`
39
- : `import * as z from 'zod'`;
40
- return [
41
- importStatement,
42
- '',
43
- zods
44
- .flatMap(({ generateZodSchema, generateZodInfer }) => [generateZodSchema, generateZodInfer].filter(Boolean))
45
- .join('\n\n'),
46
- ].join('\n');
47
- }
@@ -1,46 +0,0 @@
1
- import type { DMMF } from '@prisma/generator-helper';
2
- /**
3
- * Generates a `z.infer` type for the specified model.
4
- *
5
- * @param modelName - The name of the model.
6
- * @returns The generated TypeScript type definition line using Zod.
7
- */
8
- export declare function infer(modelName: string): string;
9
- /**
10
- * Generates Zod property definitions from model fields.
11
- *
12
- * Filters out fields without validation, removes documentation lines
13
- * that include @relation, @v, or @z, and optionally includes doc comments.
14
- *
15
- * @param modelFields - The list of model fields with documentation and validation info.
16
- * @param comment - Whether to include JSDoc comments for each field.
17
- * @returns A string containing formatted Zod property definitions.
18
- */
19
- export declare function properties(modelFields: {
20
- documentation: string;
21
- modelName: string;
22
- fieldName: string;
23
- validation: string | null;
24
- comment: string[];
25
- }[], comment: boolean): string;
26
- /**
27
- * Parses documentation and removes Zod validation lines.
28
- *
29
- * Lines containing "@z." are excluded from the result.
30
- *
31
- * @param documentation - The documentation string to parse.
32
- * @returns An array of non-Zod documentation lines.
33
- */
34
- export declare function isZodDocument(documentation?: string): string[];
35
- /**
36
- * Extracts the Zod validation expression from documentation.
37
- *
38
- * Searches for a line starting with "@z." and returns the expression part.
39
- *
40
- * @param documentation - The documentation string to parse.
41
- * @returns The Zod validation string without the "@z." prefix, or null if not found.
42
- */
43
- export declare function isZod(documentation?: string): string | null;
44
- export { extractAnno, jsdoc } from '../../../shared/utils/index.js';
45
- export declare const wrapCardinality: (expr: string, field: DMMF.Field) => string;
46
- export declare const buildZodObject: (inner: string, documentation?: string) => string;
@@ -1,75 +0,0 @@
1
- import { extractAnno } from '../../../shared/utils/index.js';
2
- /**
3
- * Generates a `z.infer` type for the specified model.
4
- *
5
- * @param modelName - The name of the model.
6
- * @returns The generated TypeScript type definition line using Zod.
7
- */
8
- export function infer(modelName) {
9
- return `export type ${modelName} = z.infer<typeof ${modelName}Schema>`;
10
- }
11
- /**
12
- * Generates Zod property definitions from model fields.
13
- *
14
- * Filters out fields without validation, removes documentation lines
15
- * that include @relation, @v, or @z, and optionally includes doc comments.
16
- *
17
- * @param modelFields - The list of model fields with documentation and validation info.
18
- * @param comment - Whether to include JSDoc comments for each field.
19
- * @returns A string containing formatted Zod property definitions.
20
- */
21
- export function properties(modelFields, comment) {
22
- const fields = modelFields
23
- .filter((field) => field.validation)
24
- .map((field) => {
25
- const cleanDoc = field.comment
26
- .filter((line) => !(line.includes('@relation') || line.includes('@v') || line.includes('@z')))
27
- .join('\n')
28
- .trim();
29
- const docComment = comment && cleanDoc ? ` /**\n * ${cleanDoc}\n */\n` : '';
30
- return `${docComment} ${field.fieldName}: z.${field.validation}`;
31
- })
32
- .join(',\n');
33
- return fields;
34
- }
35
- /**
36
- * Parses documentation and removes Zod validation lines.
37
- *
38
- * Lines containing "@z." are excluded from the result.
39
- *
40
- * @param documentation - The documentation string to parse.
41
- * @returns An array of non-Zod documentation lines.
42
- */
43
- export function isZodDocument(documentation) {
44
- return (documentation
45
- ?.split('\n')
46
- .map((line) => line.trim())
47
- .filter((line) => line && !line.includes('@z.')) ?? []);
48
- }
49
- /**
50
- * Extracts the Zod validation expression from documentation.
51
- *
52
- * Searches for a line starting with "@z." and returns the expression part.
53
- *
54
- * @param documentation - The documentation string to parse.
55
- * @returns The Zod validation string without the "@z." prefix, or null if not found.
56
- */
57
- export function isZod(documentation) {
58
- if (!documentation)
59
- return null;
60
- const match = documentation.match(/@z\.(.+?)(?:\n|$)/);
61
- return match ? match[1].trim() : null;
62
- }
63
- export { extractAnno, jsdoc } from '../../../shared/utils/index.js';
64
- export const wrapCardinality = (expr, field) => {
65
- const withList = field.isList ? `z.array(${expr})` : expr;
66
- return field.isRequired ? withList : `${withList}.optional()`;
67
- };
68
- export const buildZodObject = (inner, documentation) => {
69
- const anno = extractAnno(documentation ?? '', '@z.');
70
- return anno === 'strictObject'
71
- ? `z.strictObject({${inner}})`
72
- : anno === 'looseObject'
73
- ? `z.looseObject({${inner}})`
74
- : `z.object({${inner}})`;
75
- };
@@ -1 +0,0 @@
1
- export declare function fmt(code: string): Promise<string>;
@@ -1,9 +0,0 @@
1
- import { format } from 'prettier';
2
- export async function fmt(code) {
3
- return await format(code, {
4
- parser: 'typescript',
5
- printWidth: 100,
6
- singleQuote: true,
7
- semi: false,
8
- });
9
- }
@@ -1,11 +0,0 @@
1
- import type { DMMF, GeneratorOptions } from '@prisma/generator-helper';
2
- export declare function schemaGenerator(outDir: Readonly<string>, dmmf: Readonly<GeneratorOptions['dmmf']>, importCode: string, buildSchema: (model: DMMF.Model) => Readonly<string>, buildRelations: (model: DMMF.Model, relProps: readonly {
3
- key: string;
4
- targetModel: string;
5
- isMany: boolean;
6
- }[]) => Readonly<string>, collectRelationProps: (models: readonly DMMF.Model[]) => Readonly<{
7
- model: string;
8
- key: string;
9
- targetModel: string;
10
- isMany: boolean;
11
- }[]>): Promise<void>;
@@ -1,23 +0,0 @@
1
- import fsp from 'node:fs/promises';
2
- import path from 'node:path';
3
- export async function schemaGenerator(outDir, dmmf, importCode, buildSchema, buildRelations, collectRelationProps) {
4
- const models = dmmf.datamodel.models;
5
- const relIndex = collectRelationProps(models);
6
- const relByModel = Object.groupBy(relIndex, (r) => r.model);
7
- const baseSchemas = models.map((m) => buildSchema(m)).join('\n\n');
8
- const relationSchemas = models
9
- .map((m) => {
10
- const relProps = (relByModel[m.name] ?? []).map(({ key, targetModel, isMany }) => ({
11
- key,
12
- targetModel,
13
- isMany,
14
- }));
15
- return buildRelations(m, relProps);
16
- })
17
- .filter(Boolean)
18
- .join('\n\n');
19
- const body = relationSchemas ? `${baseSchemas}\n\n${relationSchemas}` : baseSchemas;
20
- const code = `${importCode}\n${body}\n`;
21
- await fsp.mkdir(outDir, { recursive: true });
22
- await fsp.writeFile(path.join(outDir, 'index.ts'), code, 'utf8');
23
- }
@@ -1,7 +0,0 @@
1
- import type { DMMF } from '@prisma/generator-helper';
2
- export declare function collectRelationProps(models: readonly DMMF.Model[]): Readonly<{
3
- model: string;
4
- key: string;
5
- targetModel: string;
6
- isMany: boolean;
7
- }[]>;
@@ -1,5 +0,0 @@
1
- export function collectRelationProps(models) {
2
- return models.flatMap((m) => m.fields
3
- .filter((f) => f.kind === 'object')
4
- .map((f) => ({ model: m.name, key: f.name, targetModel: f.type, isMany: f.isList })));
5
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Capitalize the first letter of a string.
3
- *
4
- * @param str - The input string.
5
- * @returns A new string with the first letter capitalized.
6
- */
7
- export declare function capitalize(str: string): string;
8
- /**
9
- * Convert a camelCase or PascalCase string to snake_case.
10
- *
11
- * @param name - The input string in camelCase or PascalCase.
12
- * @returns The converted string in snake_case.
13
- */
14
- export declare function snakeCase(name: string): string;
15
- /**
16
- * Group valid fields by their model name.
17
- *
18
- * @param validFields - An array of field objects with validation metadata.
19
- * @returns An object mapping each model name to its corresponding array of fields.
20
- */
21
- export declare function groupByModel(validFields: Required<{
22
- documentation: string;
23
- modelName: string;
24
- fieldName: string;
25
- comment: string[];
26
- validation: string | null;
27
- }>[]): Record<string, {
28
- documentation: string;
29
- modelName: string;
30
- fieldName: string;
31
- comment: string[];
32
- validation: string | null;
33
- }[]>;
34
- /**
35
- * Extract fields with validation from a nested array of model fields.
36
- *
37
- * @param modelFields - A nested array of model field definitions.
38
- * @returns A flat array of fields that include a non-null `validation` property.
39
- */
40
- export declare function isFields(modelFields: {
41
- documentation: string | undefined;
42
- modelName: string;
43
- fieldName: string;
44
- comment: string[];
45
- validation: string | null;
46
- }[][]): Required<{
47
- documentation: string;
48
- modelName: string;
49
- fieldName: string;
50
- comment: string[];
51
- validation: string | null;
52
- }>[];
53
- /**
54
- * Extracts annotation content from documentation lines.
55
- * Returns the substring after the tag (e.g. '@z.' or '@v.').
56
- */
57
- export declare const extractAnno: (doc: string, tag: "@z." | "@v.") => string | null;
58
- /**
59
- * Builds JSDoc from documentation, excluding annotation lines like '@z.' and '@v.'.
60
- */
61
- export declare const jsdoc: (doc?: string) => string;
@@ -1,63 +0,0 @@
1
- /**
2
- * Capitalize the first letter of a string.
3
- *
4
- * @param str - The input string.
5
- * @returns A new string with the first letter capitalized.
6
- */
7
- export function capitalize(str) {
8
- return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
9
- }
10
- /**
11
- * Convert a camelCase or PascalCase string to snake_case.
12
- *
13
- * @param name - The input string in camelCase or PascalCase.
14
- * @returns The converted string in snake_case.
15
- */
16
- export function snakeCase(name) {
17
- return `${name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase()}`;
18
- }
19
- /**
20
- * Group valid fields by their model name.
21
- *
22
- * @param validFields - An array of field objects with validation metadata.
23
- * @returns An object mapping each model name to its corresponding array of fields.
24
- */
25
- export function groupByModel(validFields) {
26
- return validFields.reduce((acc, field) => {
27
- if (!acc[field.modelName]) {
28
- acc[field.modelName] = [];
29
- }
30
- acc[field.modelName].push(field);
31
- return acc;
32
- }, {});
33
- }
34
- /**
35
- * Extract fields with validation from a nested array of model fields.
36
- *
37
- * @param modelFields - A nested array of model field definitions.
38
- * @returns A flat array of fields that include a non-null `validation` property.
39
- */
40
- export function isFields(modelFields) {
41
- return modelFields.flat().filter((field) => field.validation !== null);
42
- }
43
- /**
44
- * Extracts annotation content from documentation lines.
45
- * Returns the substring after the tag (e.g. '@z.' or '@v.').
46
- */
47
- export const extractAnno = (doc, tag) => {
48
- const line = doc
49
- .split('\n')
50
- .map((s) => s.trim())
51
- .find((l) => l.startsWith(tag));
52
- return line ? line.slice(tag.length) : null;
53
- };
54
- /**
55
- * Builds JSDoc from documentation, excluding annotation lines like '@z.' and '@v.'.
56
- */
57
- export const jsdoc = (doc) => {
58
- const lines = (doc ?? '')
59
- .split('\n')
60
- .map((s) => s.trim())
61
- .filter((l) => l && !l.startsWith('@z.') && !l.startsWith('@v.'));
62
- return lines.length ? `/**\n * ${lines.join('\n * ')}\n */\n` : '';
63
- };