sizuku 0.3.2 → 0.4.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 (204) hide show
  1. package/README.md +103 -0
  2. package/dist/config/index.d.mts +58 -0
  3. package/dist/config/index.mjs +95 -0
  4. package/dist/index.d.mts +10 -0
  5. package/dist/index.mjs +1615 -0
  6. package/package.json +31 -17
  7. package/dist/cli/main.d.ts +0 -10
  8. package/dist/cli/main.js +0 -61
  9. package/dist/cli.d.ts +0 -2
  10. package/dist/cli.js +0 -51
  11. package/dist/config/index.d.ts +0 -27
  12. package/dist/config/index.js +0 -85
  13. package/dist/config/loader.d.ts +0 -19
  14. package/dist/config/loader.js +0 -30
  15. package/dist/generator/engine.d.ts +0 -3
  16. package/dist/generator/engine.js +0 -63
  17. package/dist/generator/mermaid-er/config/index.d.ts +0 -10
  18. package/dist/generator/mermaid-er/config/index.js +0 -12
  19. package/dist/generator/mermaid-er/core/extract-relations.d.ts +0 -8
  20. package/dist/generator/mermaid-er/core/extract-relations.js +0 -17
  21. package/dist/generator/mermaid-er/core.d.ts +0 -6
  22. package/dist/generator/mermaid-er/core.js +0 -54
  23. package/dist/generator/mermaid-er/generator/er-content.d.ts +0 -20
  24. package/dist/generator/mermaid-er/generator/er-content.js +0 -23
  25. package/dist/generator/mermaid-er/generator/index.d.ts +0 -2
  26. package/dist/generator/mermaid-er/generator/index.js +0 -2
  27. package/dist/generator/mermaid-er/generator/relation-line.d.ts +0 -12
  28. package/dist/generator/mermaid-er/generator/relation-line.js +0 -13
  29. package/dist/generator/mermaid-er/generator.d.ts +0 -3
  30. package/dist/generator/mermaid-er/generator.js +0 -14
  31. package/dist/generator/mermaid-er/index.d.ts +0 -12
  32. package/dist/generator/mermaid-er/index.js +0 -33
  33. package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -14
  34. package/dist/generator/mermaid-er/relationship/build-relation-line.js +0 -34
  35. package/dist/generator/mermaid-er/types.d.ts +0 -21
  36. package/dist/generator/mermaid-er/types.js +0 -1
  37. package/dist/generator/mermaid-er/validator/index.d.ts +0 -8
  38. package/dist/generator/mermaid-er/validator/index.js +0 -74
  39. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +0 -7
  40. package/dist/generator/mermaid-er/validator/is-relationship.js +0 -8
  41. package/dist/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -12
  42. package/dist/generator/mermaid-er/validator/parse-relation-line.js +0 -20
  43. package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +0 -2
  44. package/dist/generator/mermaid-er/validator/parse-table-info.js +0 -71
  45. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
  46. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
  47. package/dist/generator/valibot/config/index.d.ts +0 -7
  48. package/dist/generator/valibot/config/index.js +0 -13
  49. package/dist/generator/valibot/core/extract-schema.d.ts +0 -5
  50. package/dist/generator/valibot/core/extract-schema.js +0 -173
  51. package/dist/generator/valibot/core.d.ts +0 -5
  52. package/dist/generator/valibot/core.js +0 -39
  53. package/dist/generator/valibot/generator/infer-input.d.ts +0 -5
  54. package/dist/generator/valibot/generator/infer-input.js +0 -8
  55. package/dist/generator/valibot/generator/relation-valibot-code.d.ts +0 -13
  56. package/dist/generator/valibot/generator/relation-valibot-code.js +0 -19
  57. package/dist/generator/valibot/generator/valibot-code.d.ts +0 -15
  58. package/dist/generator/valibot/generator/valibot-code.js +0 -16
  59. package/dist/generator/valibot/generator/valibot.d.ts +0 -14
  60. package/dist/generator/valibot/generator/valibot.js +0 -15
  61. package/dist/generator/valibot/generator.d.ts +0 -3
  62. package/dist/generator/valibot/generator.js +0 -14
  63. package/dist/generator/valibot/index.d.ts +0 -14
  64. package/dist/generator/valibot/index.js +0 -50
  65. package/dist/generator/zod/config/index.d.ts +0 -8
  66. package/dist/generator/zod/config/index.js +0 -14
  67. package/dist/generator/zod/core/extract-schema.d.ts +0 -7
  68. package/dist/generator/zod/core/extract-schema.js +0 -243
  69. package/dist/generator/zod/core.d.ts +0 -5
  70. package/dist/generator/zod/core.js +0 -39
  71. package/dist/generator/zod/generator/infer.d.ts +0 -5
  72. package/dist/generator/zod/generator/infer.js +0 -8
  73. package/dist/generator/zod/generator/relation-zod-code.d.ts +0 -13
  74. package/dist/generator/zod/generator/relation-zod-code.js +0 -19
  75. package/dist/generator/zod/generator/zod-code.d.ts +0 -17
  76. package/dist/generator/zod/generator/zod-code.js +0 -18
  77. package/dist/generator/zod/generator/zod.d.ts +0 -16
  78. package/dist/generator/zod/generator/zod.js +0 -16
  79. package/dist/generator/zod/generator.d.ts +0 -3
  80. package/dist/generator/zod/generator.js +0 -14
  81. package/dist/generator/zod/index.d.ts +0 -15
  82. package/dist/generator/zod/index.js +0 -54
  83. package/dist/index.d.ts +0 -7
  84. package/dist/index.js +0 -73
  85. package/dist/shared/config/index.d.ts +0 -13
  86. package/dist/shared/config/index.js +0 -10
  87. package/dist/shared/format/index.d.ts +0 -13
  88. package/dist/shared/format/index.js +0 -24
  89. package/dist/shared/fs/index.d.ts +0 -7
  90. package/dist/shared/fs/index.js +0 -16
  91. package/dist/shared/fsp/index.d.ts +0 -27
  92. package/dist/shared/fsp/index.js +0 -38
  93. package/dist/shared/generator/field-definitions.d.ts +0 -12
  94. package/dist/shared/generator/field-definitions.js +0 -12
  95. package/dist/shared/helper/ast-parser.d.ts +0 -3
  96. package/dist/shared/helper/ast-parser.js +0 -202
  97. package/dist/shared/helper/build-schema-extractor.d.ts +0 -25
  98. package/dist/shared/helper/build-schema-extractor.js +0 -33
  99. package/dist/shared/helper/create-extract-field-from-property.d.ts +0 -15
  100. package/dist/shared/helper/create-extract-field-from-property.js +0 -20
  101. package/dist/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
  102. package/dist/shared/helper/create-extract-fields-from-call-expression.js +0 -14
  103. package/dist/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
  104. package/dist/shared/helper/create-extract-relation-field-from-property.js +0 -27
  105. package/dist/shared/helper/extract-schemas.d.ts +0 -133
  106. package/dist/shared/helper/extract-schemas.js +0 -445
  107. package/dist/shared/helper/file-writer.d.ts +0 -3
  108. package/dist/shared/helper/file-writer.js +0 -25
  109. package/dist/shared/helper/find-object-literal-expression.d.ts +0 -12
  110. package/dist/shared/helper/find-object-literal-expression.js +0 -31
  111. package/dist/shared/helper/find-object-literalIn-args.d.ts +0 -2
  112. package/dist/shared/helper/find-object-literalIn-args.js +0 -8
  113. package/dist/shared/helper/is-relation-function.d.ts +0 -10
  114. package/dist/shared/helper/is-relation-function.js +0 -16
  115. package/dist/shared/types.d.ts +0 -9
  116. package/dist/shared/types.js +0 -1
  117. package/dist/shared/utils/capitalize.d.ts +0 -18
  118. package/dist/shared/utils/capitalize.js +0 -20
  119. package/dist/shared/utils/compose.d.ts +0 -101
  120. package/dist/shared/utils/compose.js +0 -124
  121. package/dist/shared/utils/file.d.ts +0 -92
  122. package/dist/shared/utils/file.js +0 -177
  123. package/dist/shared/utils/functional.d.ts +0 -118
  124. package/dist/shared/utils/functional.js +0 -96
  125. package/dist/shared/utils/index.d.ts +0 -20
  126. package/dist/shared/utils/index.js +0 -48
  127. package/dist/shared/utils/string-utils.d.ts +0 -8
  128. package/dist/shared/utils/string-utils.js +0 -28
  129. package/dist/shared/utils/types.d.ts +0 -32
  130. package/dist/shared/utils/types.js +0 -2
  131. package/dist/shared/utils/validation-utils.d.ts +0 -8
  132. package/dist/shared/utils/validation-utils.js +0 -25
  133. package/dist/src/config/index.d.ts +0 -18
  134. package/dist/src/config/index.js +0 -13
  135. package/dist/src/generator/mermaid-er/core/extract-relations.d.ts +0 -8
  136. package/dist/src/generator/mermaid-er/core/extract-relations.js +0 -12
  137. package/dist/src/generator/mermaid-er/generator/er-content.d.ts +0 -9
  138. package/dist/src/generator/mermaid-er/generator/er-content.js +0 -25
  139. package/dist/src/generator/mermaid-er/generator/index.d.ts +0 -2
  140. package/dist/src/generator/mermaid-er/generator/index.js +0 -2
  141. package/dist/src/generator/mermaid-er/generator/relation-line.d.ts +0 -8
  142. package/dist/src/generator/mermaid-er/generator/relation-line.js +0 -14
  143. package/dist/src/generator/mermaid-er/index.d.ts +0 -6
  144. package/dist/src/generator/mermaid-er/index.js +0 -16
  145. package/dist/src/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -15
  146. package/dist/src/generator/mermaid-er/relationship/build-relation-line.js +0 -35
  147. package/dist/src/generator/mermaid-er/types.d.ts +0 -21
  148. package/dist/src/generator/mermaid-er/types.js +0 -1
  149. package/dist/src/generator/mermaid-er/validator/index.d.ts +0 -4
  150. package/dist/src/generator/mermaid-er/validator/index.js +0 -4
  151. package/dist/src/generator/mermaid-er/validator/is-relationship.d.ts +0 -8
  152. package/dist/src/generator/mermaid-er/validator/is-relationship.js +0 -9
  153. package/dist/src/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -13
  154. package/dist/src/generator/mermaid-er/validator/parse-relation-line.js +0 -21
  155. package/dist/src/generator/mermaid-er/validator/parse-table-info.d.ts +0 -8
  156. package/dist/src/generator/mermaid-er/validator/parse-table-info.js +0 -91
  157. package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
  158. package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
  159. package/dist/src/generator/valibot/generator/infer-input.d.ts +0 -5
  160. package/dist/src/generator/valibot/generator/infer-input.js +0 -8
  161. package/dist/src/generator/valibot/generator/valibot-code.d.ts +0 -14
  162. package/dist/src/generator/valibot/generator/valibot-code.js +0 -16
  163. package/dist/src/generator/valibot/generator/valibot.d.ts +0 -13
  164. package/dist/src/generator/valibot/generator/valibot.js +0 -11
  165. package/dist/src/generator/valibot/index.d.ts +0 -9
  166. package/dist/src/generator/valibot/index.js +0 -34
  167. package/dist/src/generator/zod/generator/infer.d.ts +0 -5
  168. package/dist/src/generator/zod/generator/infer.js +0 -8
  169. package/dist/src/generator/zod/generator/zod-code.d.ts +0 -16
  170. package/dist/src/generator/zod/generator/zod-code.js +0 -18
  171. package/dist/src/generator/zod/generator/zod.d.ts +0 -15
  172. package/dist/src/generator/zod/generator/zod.js +0 -12
  173. package/dist/src/generator/zod/index.d.ts +0 -10
  174. package/dist/src/generator/zod/index.js +0 -40
  175. package/dist/src/index.d.ts +0 -10
  176. package/dist/src/index.js +0 -35
  177. package/dist/src/shared/format/index.d.ts +0 -2
  178. package/dist/src/shared/format/index.js +0 -10
  179. package/dist/src/shared/fs/index.d.ts +0 -2
  180. package/dist/src/shared/fs/index.js +0 -10
  181. package/dist/src/shared/fsp/index.d.ts +0 -3
  182. package/dist/src/shared/fsp/index.js +0 -8
  183. package/dist/src/shared/generator/field-definitions.d.ts +0 -12
  184. package/dist/src/shared/generator/field-definitions.js +0 -12
  185. package/dist/src/shared/helper/build-schema-extractor.d.ts +0 -25
  186. package/dist/src/shared/helper/build-schema-extractor.js +0 -33
  187. package/dist/src/shared/helper/create-extract-field-from-property.d.ts +0 -15
  188. package/dist/src/shared/helper/create-extract-field-from-property.js +0 -20
  189. package/dist/src/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
  190. package/dist/src/shared/helper/create-extract-fields-from-call-expression.js +0 -14
  191. package/dist/src/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
  192. package/dist/src/shared/helper/create-extract-relation-field-from-property.js +0 -27
  193. package/dist/src/shared/helper/extract-schemas.d.ts +0 -16
  194. package/dist/src/shared/helper/extract-schemas.js +0 -19
  195. package/dist/src/shared/helper/find-object-literal-expression.d.ts +0 -12
  196. package/dist/src/shared/helper/find-object-literal-expression.js +0 -31
  197. package/dist/src/shared/helper/find-object-literalIn-args.d.ts +0 -2
  198. package/dist/src/shared/helper/find-object-literalIn-args.js +0 -8
  199. package/dist/src/shared/helper/is-relation-function.d.ts +0 -10
  200. package/dist/src/shared/helper/is-relation-function.js +0 -16
  201. package/dist/src/shared/utils/index.d.ts +0 -33
  202. package/dist/src/shared/utils/index.js +0 -61
  203. package/dist/utils/index.d.ts +0 -144
  204. package/dist/utils/index.js +0 -250
@@ -1,27 +0,0 @@
1
- import { Node } from 'ts-morph';
2
- import { extractFieldComments, schemaName } from '../utils/index.js';
3
- export const createExtractRelationFieldFromProperty = (parseFieldComments, prefix) => {
4
- return (property, sourceText) => {
5
- if (!Node.isPropertyAssignment(property))
6
- return null;
7
- const name = property.getName();
8
- if (!name)
9
- return null;
10
- const init = property.getInitializer();
11
- if (!Node.isCallExpression(init))
12
- return { name, definition: '', description: undefined };
13
- const expr = init.getExpression();
14
- if (!Node.isIdentifier(expr))
15
- return { name, definition: '', description: undefined };
16
- const fnName = expr.getText();
17
- const args = init.getArguments();
18
- if (!(args.length && Node.isIdentifier(args[0]))) {
19
- return { name, definition: '', description: undefined };
20
- }
21
- const refTable = args[0].getText();
22
- const schema = schemaName(refTable);
23
- const definition = fnName === 'many' ? `${prefix}.array(${schema})` : fnName === 'one' ? schema : '';
24
- const { description } = parseFieldComments(extractFieldComments(sourceText, property.getStart()));
25
- return { name, definition, description };
26
- };
27
- };
@@ -1,16 +0,0 @@
1
- import type { Node } from 'ts-morph';
2
- export declare function extractSchemas(lines: string[], extractFn: (declaration: Node, sourceText: string) => {
3
- name: string;
4
- fields: {
5
- name: string;
6
- definition: string;
7
- description?: string;
8
- }[];
9
- } | null): {
10
- name: string;
11
- fields: {
12
- name: string;
13
- definition: string;
14
- description?: string;
15
- }[];
16
- }[];
@@ -1,19 +0,0 @@
1
- import { Project } from 'ts-morph';
2
- export function extractSchemas(lines, extractFn) {
3
- const sourceCode = lines.join('\n');
4
- const project = new Project({
5
- useInMemoryFileSystem: true,
6
- compilerOptions: {
7
- allowJs: true,
8
- skipLibCheck: true,
9
- },
10
- });
11
- const sourceFile = project.createSourceFile('temp.ts', sourceCode);
12
- const sourceText = sourceFile.getFullText();
13
- return sourceFile
14
- .getVariableStatements()
15
- .filter((stmt) => stmt.hasExportKeyword())
16
- .flatMap((stmt) => stmt.getDeclarations())
17
- .map((decl) => extractFn(decl, sourceText))
18
- .filter((schema) => schema !== null);
19
- }
@@ -1,12 +0,0 @@
1
- import type { ObjectLiteralExpression } from 'ts-morph';
2
- import { Node } from 'ts-morph';
3
- /**
4
- * Recursively extracts an `ObjectLiteralExpression` from a given AST node.
5
- *
6
- * Supports direct object literals, parenthesized expressions,
7
- * arrow functions returning object literals (including wrapped and block bodies).
8
- *
9
- * @param expr - The root `Node` to search.
10
- * @returns The found `ObjectLiteralExpression`, or `null` if not found.
11
- */
12
- export declare function findObjectLiteralExpression(expr: Node): ObjectLiteralExpression | null;
@@ -1,31 +0,0 @@
1
- import { Node } from 'ts-morph';
2
- /**
3
- * Recursively extracts an `ObjectLiteralExpression` from a given AST node.
4
- *
5
- * Supports direct object literals, parenthesized expressions,
6
- * arrow functions returning object literals (including wrapped and block bodies).
7
- *
8
- * @param expr - The root `Node` to search.
9
- * @returns The found `ObjectLiteralExpression`, or `null` if not found.
10
- */
11
- export function findObjectLiteralExpression(expr) {
12
- if (Node.isObjectLiteralExpression(expr))
13
- return expr;
14
- if (Node.isParenthesizedExpression(expr))
15
- return findObjectLiteralExpression(expr.getExpression());
16
- if (Node.isArrowFunction(expr)) {
17
- const body = expr.getBody();
18
- if (Node.isObjectLiteralExpression(body))
19
- return body;
20
- if (Node.isParenthesizedExpression(body))
21
- return findObjectLiteralExpression(body.getExpression());
22
- if (Node.isBlock(body)) {
23
- const ret = body.getStatements().find(Node.isReturnStatement);
24
- if (ret && Node.isReturnStatement(ret)) {
25
- const re = ret.getExpression();
26
- return re && Node.isObjectLiteralExpression(re) ? re : null;
27
- }
28
- }
29
- }
30
- return null;
31
- }
@@ -1,2 +0,0 @@
1
- import type { CallExpression, Node, ObjectLiteralExpression } from 'ts-morph';
2
- export declare function findObjectLiteralInArgs(call: CallExpression, finder: (expr: Node) => ObjectLiteralExpression | null): ObjectLiteralExpression | null;
@@ -1,8 +0,0 @@
1
- export function findObjectLiteralInArgs(call, finder) {
2
- for (const arg of call.getArguments()) {
3
- const obj = finder(arg);
4
- if (obj)
5
- return obj;
6
- }
7
- return null;
8
- }
@@ -1,10 +0,0 @@
1
- import type { CallExpression } from 'ts-morph';
2
- /**
3
- * Determines whether a given `CallExpression` is a relation-related function call.
4
- *
5
- * This checks if the function name is either `"relations"` or contains the substring `"relation"`.
6
- *
7
- * @param callExpr - The call expression node to check.
8
- * @returns `true` if the function is a relation function; otherwise, `false`.
9
- */
10
- export declare function isRelationFunctionCall(callExpr: CallExpression): boolean;
@@ -1,16 +0,0 @@
1
- import { Node } from 'ts-morph';
2
- /**
3
- * Determines whether a given `CallExpression` is a relation-related function call.
4
- *
5
- * This checks if the function name is either `"relations"` or contains the substring `"relation"`.
6
- *
7
- * @param callExpr - The call expression node to check.
8
- * @returns `true` if the function is a relation function; otherwise, `false`.
9
- */
10
- export function isRelationFunctionCall(callExpr) {
11
- const expression = callExpr.getExpression();
12
- if (!Node.isIdentifier(expression))
13
- return false;
14
- const functionName = expression.getText();
15
- return functionName === 'relations' || functionName.includes('relation');
16
- }
@@ -1,33 +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
- * Generate schema name from table name.
10
- *
11
- * @param str - The table name.
12
- * @returns A schema name with PascalCase and Schema suffix.
13
- */
14
- export declare function schemaName(str: string): string;
15
- /**
16
- * Parse field comments and extract definition line and description.
17
- *
18
- * @param commentLines - Raw comment lines (e.g., from source text)
19
- * @param tag - The tag to look for (e.g., '@v.' or '@z.')
20
- * @returns Parsed definition and description
21
- */
22
- export declare function parseFieldComments(commentLines: string[], tag: '@v.' | '@z.'): {
23
- definition: string;
24
- description?: string;
25
- };
26
- /**
27
- * Extract field comments from source text.
28
- *
29
- * @param sourceText - The source text to extract comments from.
30
- * @param fieldStartPos - The start position of the field.
31
- * @returns Array of comment lines.
32
- */
33
- export declare function extractFieldComments(sourceText: string, fieldStartPos: number): string[];
@@ -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 function capitalize(str) {
8
- return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
9
- }
10
- /**
11
- * Generate schema name from table name.
12
- *
13
- * @param str - The table name.
14
- * @returns A schema name with PascalCase and Schema suffix.
15
- */
16
- export function schemaName(str) {
17
- return `${capitalize(str)}Schema`;
18
- }
19
- /**
20
- * Parse field comments and extract definition line and description.
21
- *
22
- * @param commentLines - Raw comment lines (e.g., from source text)
23
- * @param tag - The tag to look for (e.g., '@v.' or '@z.')
24
- * @returns Parsed definition and description
25
- */
26
- export function parseFieldComments(commentLines, tag) {
27
- const cleaned = commentLines.map((line) => line.replace(/^\/\/\/\s*/, '').trim()).filter(Boolean);
28
- const definition = cleaned.find((line) => line.startsWith(tag))?.replace(/^@/, '') ?? '';
29
- const descriptionLines = cleaned.filter((line) => !(line.includes('@z.') || line.includes('@v.') || line.includes('@relation.')));
30
- const description = descriptionLines.length ? descriptionLines.join(' ') : undefined;
31
- return { definition, description };
32
- }
33
- /**
34
- * Extract field comments from source text.
35
- *
36
- * @param sourceText - The source text to extract comments from.
37
- * @param fieldStartPos - The start position of the field.
38
- * @returns Array of comment lines.
39
- */
40
- export function extractFieldComments(sourceText, fieldStartPos) {
41
- const beforeField = sourceText.substring(0, fieldStartPos);
42
- const lines = beforeField.split('\n');
43
- const reverseIndex = lines
44
- .map((line, index) => ({ line: line.trim(), index }))
45
- .reverse()
46
- .reduce((acc, { line }) => {
47
- if (acc.shouldStop)
48
- return acc;
49
- if (line.startsWith('///')) {
50
- return {
51
- commentLines: [line, ...acc.commentLines],
52
- shouldStop: false,
53
- };
54
- }
55
- if (line === '') {
56
- return acc;
57
- }
58
- return { commentLines: acc.commentLines, shouldStop: true };
59
- }, { commentLines: [], shouldStop: false });
60
- return reverseIndex.commentLines;
61
- }
@@ -1,144 +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
- * Remove triple slash prefix from a string.
10
- *
11
- * @param str - The input string.
12
- * @returns String with triple slash prefix removed.
13
- */
14
- export declare function removeTripleSlash(str: string): string;
15
- /**
16
- * Check if a string is non-empty.
17
- *
18
- * @param str - The input string.
19
- * @returns True if string is non-empty.
20
- */
21
- export declare function isNonEmpty(str: string): boolean;
22
- /**
23
- * Check if a string contains a substring.
24
- *
25
- * @param str - The input string.
26
- * @param substr - The substring to search for.
27
- * @returns True if string contains substring.
28
- */
29
- export declare function containsSubstring(str: string, substr: string): boolean;
30
- /**
31
- * Check if a string starts with a prefix.
32
- *
33
- * @param str - The input string.
34
- * @param prefix - The prefix to check.
35
- * @returns True if string starts with prefix.
36
- */
37
- export declare function startsWith(str: string, prefix: string): boolean;
38
- /**
39
- * Remove @ sign from the beginning of a string.
40
- *
41
- * @param str - The input string.
42
- * @returns String with @ sign removed.
43
- */
44
- export declare function removeAtSign(str: string): string;
45
- /**
46
- * Join array of strings with space separator.
47
- *
48
- * @param arr - Array of strings to join.
49
- * @returns Joined string with spaces.
50
- */
51
- export declare function joinWithSpace(arr: readonly string[]): string;
52
- /**
53
- * Split string by newline character.
54
- *
55
- * @param str - The input string.
56
- * @returns Array of strings split by newline.
57
- */
58
- export declare function splitByNewline(str: string): readonly string[];
59
- /**
60
- * Trim whitespace from string.
61
- *
62
- * @param str - The input string.
63
- * @returns Trimmed string.
64
- */
65
- export declare function trimString(str: string): string;
66
- /**
67
- * Parse relation line and extract components.
68
- *
69
- * @param line - The line to parse.
70
- * @returns Parsed relation or null if not a relation line.
71
- */
72
- export declare function parseRelationLine(line: string): {
73
- fromModel: string;
74
- toModel: string;
75
- fromField: string;
76
- toField: string;
77
- type: string;
78
- } | null;
79
- /**
80
- * Split string by '-to-' delimiter.
81
- *
82
- * @param str - The input string.
83
- * @returns Array with two parts or null if not found.
84
- */
85
- export declare function splitByTo(str: string): [string, string] | null;
86
- /**
87
- * Remove optional suffix from string.
88
- *
89
- * @param str - The input string.
90
- * @returns String with optional suffix removed.
91
- */
92
- export declare function removeOptionalSuffix(str: string): string;
93
- /**
94
- * Split string by whitespace.
95
- *
96
- * @param str - The input string.
97
- * @returns Array of strings split by whitespace.
98
- */
99
- export declare function splitByWhitespace(str: string): readonly string[];
100
- /**
101
- * Split string by dot character.
102
- *
103
- * @param str - The input string.
104
- * @returns Array of strings split by dot.
105
- */
106
- export declare function splitByDot(str: string): readonly string[];
107
- /**
108
- * Parse field comments and extract definition line and description.
109
- *
110
- * @param commentLines - Raw comment lines (e.g., from source text)
111
- * @param tag - The tag to look for (e.g., '@v.' or '@z.')
112
- * @returns Parsed definition and description
113
- */
114
- export declare function parseFieldComments(commentLines: string[], tag: '@v.' | '@z.'): {
115
- definition: string;
116
- description?: string;
117
- objectType?: 'strict' | 'loose';
118
- };
119
- /**
120
- * Extract field comments from source text.
121
- *
122
- * @param sourceText - The source text to extract comments from.
123
- * @param fieldStartPos - The position of the field in the source text.
124
- * @returns An array of comment lines.
125
- */
126
- export declare function extractFieldComments(sourceText: string, fieldStartPos: number): string[];
127
- /**
128
- * @param name
129
- * @returns
130
- */
131
- export declare function infer(name: string): string;
132
- export declare function inferInput(name: string): string;
133
- /**
134
- * @param schema
135
- * @returns
136
- */
137
- export declare function fieldDefinitions(schema: {
138
- readonly name: string;
139
- readonly fields: {
140
- readonly name: string;
141
- readonly definition: string;
142
- readonly description?: string;
143
- }[];
144
- }, comment: boolean): string;
@@ -1,250 +0,0 @@
1
- /* ========================================================================== *
2
- * text
3
- * ========================================================================== */
4
- /**
5
- * Capitalize the first letter of a string.
6
- *
7
- * @param str - The input string.
8
- * @returns A new string with the first letter capitalized.
9
- */
10
- export function capitalize(str) {
11
- return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
12
- }
13
- /**
14
- * Remove triple slash prefix from a string.
15
- *
16
- * @param str - The input string.
17
- * @returns String with triple slash prefix removed.
18
- */
19
- export function removeTripleSlash(str) {
20
- return str.startsWith('///') ? str.substring(3) : str;
21
- }
22
- /**
23
- * Check if a string is non-empty.
24
- *
25
- * @param str - The input string.
26
- * @returns True if string is non-empty.
27
- */
28
- export function isNonEmpty(str) {
29
- return str.length > 0;
30
- }
31
- /**
32
- * Check if a string contains a substring.
33
- *
34
- * @param str - The input string.
35
- * @param substr - The substring to search for.
36
- * @returns True if string contains substring.
37
- */
38
- export function containsSubstring(str, substr) {
39
- return str.indexOf(substr) !== -1;
40
- }
41
- /**
42
- * Check if a string starts with a prefix.
43
- *
44
- * @param str - The input string.
45
- * @param prefix - The prefix to check.
46
- * @returns True if string starts with prefix.
47
- */
48
- export function startsWith(str, prefix) {
49
- return str.indexOf(prefix) === 0;
50
- }
51
- /**
52
- * Remove @ sign from the beginning of a string.
53
- *
54
- * @param str - The input string.
55
- * @returns String with @ sign removed.
56
- */
57
- export function removeAtSign(str) {
58
- return str.startsWith('@') ? str.substring(1) : str;
59
- }
60
- /**
61
- * Join array of strings with space separator.
62
- *
63
- * @param arr - Array of strings to join.
64
- * @returns Joined string with spaces.
65
- */
66
- export function joinWithSpace(arr) {
67
- return arr.join(' ');
68
- }
69
- /**
70
- * Split string by newline character.
71
- *
72
- * @param str - The input string.
73
- * @returns Array of strings split by newline.
74
- */
75
- export function splitByNewline(str) {
76
- return str.split('\n');
77
- }
78
- /**
79
- * Trim whitespace from string.
80
- *
81
- * @param str - The input string.
82
- * @returns Trimmed string.
83
- */
84
- export function trimString(str) {
85
- return str.trim();
86
- }
87
- /**
88
- * Parse relation line and extract components.
89
- *
90
- * @param line - The line to parse.
91
- * @returns Parsed relation or null if not a relation line.
92
- */
93
- export function parseRelationLine(line) {
94
- if (!line.startsWith('@relation'))
95
- return null;
96
- const parts = line.trim().split(/\s+/);
97
- if (parts.length < 5)
98
- return null;
99
- const fromParts = parts[1].split('.');
100
- const toParts = parts[2].split('.');
101
- if (fromParts.length !== 2 || toParts.length !== 2)
102
- return null;
103
- return {
104
- fromModel: fromParts[0],
105
- fromField: fromParts[1],
106
- toModel: toParts[0],
107
- toField: toParts[1],
108
- type: parts[3],
109
- };
110
- }
111
- /**
112
- * Split string by '-to-' delimiter.
113
- *
114
- * @param str - The input string.
115
- * @returns Array with two parts or null if not found.
116
- */
117
- export function splitByTo(str) {
118
- const index = str.indexOf('-to-');
119
- if (index === -1)
120
- return null;
121
- return [str.substring(0, index), str.substring(index + 4)];
122
- }
123
- /**
124
- * Remove optional suffix from string.
125
- *
126
- * @param str - The input string.
127
- * @returns String with optional suffix removed.
128
- */
129
- export function removeOptionalSuffix(str) {
130
- const index = str.indexOf('-optional');
131
- return index !== -1 ? str.substring(0, index) : str;
132
- }
133
- /**
134
- * Split string by whitespace.
135
- *
136
- * @param str - The input string.
137
- * @returns Array of strings split by whitespace.
138
- */
139
- export function splitByWhitespace(str) {
140
- return str
141
- .trim()
142
- .split(/\s+/)
143
- .filter((s) => s.length > 0);
144
- }
145
- /**
146
- * Split string by dot character.
147
- *
148
- * @param str - The input string.
149
- * @returns Array of strings split by dot.
150
- */
151
- export function splitByDot(str) {
152
- return str.split('.');
153
- }
154
- /* ========================================================================== *
155
- * parse
156
- * ========================================================================== */
157
- /**
158
- * Parse field comments and extract definition line and description.
159
- *
160
- * @param commentLines - Raw comment lines (e.g., from source text)
161
- * @param tag - The tag to look for (e.g., '@v.' or '@z.')
162
- * @returns Parsed definition and description
163
- */
164
- export function parseFieldComments(commentLines, tag) {
165
- const cleaned = commentLines
166
- .map((line) => (line.startsWith('///') ? line.substring(3) : line).trim())
167
- .filter((line) => line.length > 0);
168
- const objectTypeLine = cleaned.find((line) => line.includes(`${tag.slice(1)}strictObject`) || line.includes(`${tag.slice(1)}looseObject`));
169
- const objectType = objectTypeLine
170
- ? objectTypeLine.includes('strictObject')
171
- ? 'strict'
172
- : objectTypeLine.includes('looseObject')
173
- ? 'loose'
174
- : undefined
175
- : undefined;
176
- const definitionLine = cleaned.find((line) => line.startsWith(tag) && !line.includes('strictObject') && !line.includes('looseObject'));
177
- const definition = definitionLine
178
- ? definitionLine.startsWith('@')
179
- ? definitionLine.substring(1)
180
- : definitionLine
181
- : '';
182
- const descriptionLines = cleaned.filter((line) => !(line.includes('@z.') || line.includes('@v.') || line.includes('@relation.')));
183
- const description = descriptionLines.length > 0 ? descriptionLines.join(' ') : undefined;
184
- return { definition, description, objectType };
185
- }
186
- /* ========================================================================== *
187
- * extractFieldComments
188
- * ========================================================================== */
189
- /**
190
- * Extract field comments from source text.
191
- *
192
- * @param sourceText - The source text to extract comments from.
193
- * @param fieldStartPos - The position of the field in the source text.
194
- * @returns An array of comment lines.
195
- */
196
- export function extractFieldComments(sourceText, fieldStartPos) {
197
- const beforeField = sourceText.substring(0, fieldStartPos);
198
- const lines = beforeField.split('\n');
199
- const reverseIndex = lines
200
- .map((line, index) => ({ line: line.trim(), index }))
201
- .reverse()
202
- .reduce((acc, { line }) => {
203
- if (acc.shouldStop)
204
- return acc;
205
- if (line.startsWith('///')) {
206
- return {
207
- commentLines: [line, ...acc.commentLines],
208
- shouldStop: false,
209
- };
210
- }
211
- if (line === '') {
212
- return acc;
213
- }
214
- return { commentLines: acc.commentLines, shouldStop: true };
215
- }, { commentLines: [], shouldStop: false });
216
- return reverseIndex.commentLines;
217
- }
218
- /* ========================================================================== *
219
- * zod
220
- * ========================================================================== */
221
- /**
222
- * @param name
223
- * @returns
224
- */
225
- export function infer(name) {
226
- const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
227
- return `export type ${capitalizedName} = z.infer<typeof ${capitalizedName}Schema>`;
228
- }
229
- /* ========================================================================== *
230
- * valibot
231
- * ========================================================================== */
232
- export function inferInput(name) {
233
- const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
234
- return `export type ${capitalizedName} = v.InferInput<typeof ${capitalizedName}Schema>`;
235
- }
236
- /* ========================================================================== *
237
- * schema
238
- * ========================================================================== */
239
- /**
240
- * @param schema
241
- * @returns
242
- */
243
- export function fieldDefinitions(schema, comment) {
244
- return schema.fields
245
- .map(({ name, definition, description }) => {
246
- const commentCode = description && comment ? `/**\n* ${description}\n*/\n` : '';
247
- return `${commentCode}${name}:${definition}`;
248
- })
249
- .join(',\n');
250
- }