sizuku 0.0.7 → 0.1.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.
- package/README.md +87 -341
- package/dist/config/index.d.ts +18 -0
- package/dist/config/index.js +13 -0
- package/dist/generator/mermaid-er/config/index.d.ts +4 -4
- package/dist/generator/mermaid-er/config/index.js +4 -10
- package/dist/generator/mermaid-er/core/extract-relations.d.ts +1 -1
- package/dist/generator/mermaid-er/core/extract-relations.js +3 -6
- package/dist/generator/mermaid-er/generator/{generate-er-content.d.ts → er-content.d.ts} +2 -3
- package/dist/generator/mermaid-er/generator/{generate-er-content.js → er-content.js} +3 -7
- package/dist/generator/mermaid-er/generator/index.d.ts +2 -0
- package/dist/generator/mermaid-er/generator/index.js +2 -0
- package/dist/generator/mermaid-er/generator/{generate-relation-line.d.ts → relation-line.d.ts} +2 -2
- package/dist/generator/mermaid-er/generator/{generate-relation-line.js → relation-line.js} +3 -6
- package/dist/generator/mermaid-er/index.d.ts +6 -5
- package/dist/generator/mermaid-er/index.js +15 -76
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +3 -6
- package/dist/generator/mermaid-er/types.js +1 -0
- package/dist/generator/mermaid-er/validator/index.d.ts +4 -0
- package/dist/generator/mermaid-er/validator/index.js +4 -0
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/is-relationship.js +1 -4
- package/dist/generator/mermaid-er/validator/parse-relation-line.js +1 -4
- package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +1 -7
- package/dist/generator/mermaid-er/validator/parse-table-info.js +69 -89
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
- package/dist/generator/valibot/config/index.d.ts +2 -2
- package/dist/generator/valibot/config/index.js +6 -12
- package/dist/generator/valibot/core/extract-schema.d.ts +2 -5
- package/dist/generator/valibot/core/extract-schema.js +162 -81
- package/dist/generator/valibot/generator/infer-input.d.ts +5 -0
- package/dist/generator/valibot/generator/infer-input.js +8 -0
- package/dist/generator/valibot/generator/valibot-code.d.ts +8 -0
- package/dist/generator/valibot/generator/valibot-code.js +16 -0
- package/dist/generator/valibot/generator/valibot.d.ts +7 -0
- package/dist/generator/valibot/generator/valibot.js +11 -0
- package/dist/generator/valibot/index.d.ts +9 -3
- package/dist/generator/valibot/index.js +21 -76
- package/dist/generator/zod/config/index.d.ts +2 -2
- package/dist/generator/zod/config/index.js +6 -12
- package/dist/generator/zod/core/extract-schema.d.ts +1 -2
- package/dist/generator/zod/core/extract-schema.js +228 -81
- package/dist/generator/zod/generator/infer.d.ts +5 -0
- package/dist/generator/zod/generator/infer.js +8 -0
- package/dist/generator/zod/generator/{generate-zod-code.d.ts → zod-code.d.ts} +2 -3
- package/dist/generator/zod/generator/zod-code.js +18 -0
- package/dist/generator/zod/generator/{generate-zod-schema.d.ts → zod.d.ts} +2 -4
- package/dist/generator/zod/generator/zod.js +12 -0
- package/dist/generator/zod/index.d.ts +10 -3
- package/dist/generator/zod/index.js +29 -76
- package/dist/index.d.ts +3 -0
- package/dist/index.js +54 -0
- package/dist/shared/config/index.d.ts +13 -0
- package/dist/{common → shared}/config/index.js +1 -4
- package/dist/shared/format/index.d.ts +2 -0
- package/dist/shared/format/index.js +10 -0
- package/dist/shared/fs/index.d.ts +2 -0
- package/dist/shared/fs/index.js +10 -0
- package/dist/shared/fsp/index.d.ts +3 -0
- package/dist/shared/fsp/index.js +8 -0
- package/dist/shared/generator/field-definitions.d.ts +6 -0
- package/dist/shared/generator/field-definitions.js +12 -0
- package/dist/shared/types.js +1 -0
- package/dist/{common/text → shared/utils}/capitalize.js +1 -4
- package/dist/shared/utils/compose.d.ts +101 -0
- package/dist/shared/utils/compose.js +124 -0
- package/dist/shared/utils/file.d.ts +92 -0
- package/dist/shared/utils/file.js +177 -0
- package/dist/shared/utils/functional.d.ts +118 -0
- package/dist/shared/utils/functional.js +96 -0
- package/package.json +11 -10
- package/dist/common/config/index.d.ts +0 -13
- package/dist/common/format/index.d.ts +0 -1
- package/dist/common/format/index.js +0 -12
- package/dist/common/generator/generate-field-definitions.d.ts +0 -8
- package/dist/common/generator/generate-field-definitions.js +0 -16
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +0 -7
- package/dist/common/helper/get-camel-case-schema-name-helper.js +0 -14
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +0 -8
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +0 -15
- package/dist/common/helper/get-variable-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-name-helper.js +0 -15
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-schema-name-helper.js +0 -17
- package/dist/common/text/decapitalize.d.ts +0 -17
- package/dist/common/text/decapitalize.js +0 -22
- package/dist/common/type/index.js +0 -2
- package/dist/generator/mermaid-er/type/index.js +0 -2
- package/dist/generator/mermaid-er/validator/is-relation.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/is-relation.js +0 -40
- package/dist/generator/valibot/generator/generate-valibot-code.d.ts +0 -11
- package/dist/generator/valibot/generator/generate-valibot-code.js +0 -21
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -16
- package/dist/generator/zod/generator/generate-z-infer.d.ts +0 -11
- package/dist/generator/zod/generator/generate-z-infer.js +0 -18
- package/dist/generator/zod/generator/generate-zod-code.js +0 -21
- package/dist/generator/zod/generator/generate-zod-schema.js +0 -17
- /package/dist/generator/mermaid-er/{type/index.d.ts → types.d.ts} +0 -0
- /package/dist/{common/type/index.d.ts → shared/types.d.ts} +0 -0
- /package/dist/{common/text → shared/utils}/capitalize.d.ts +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Test run
|
|
2
|
+
// pnpm vitest run src/shared/utils/functional.test.ts
|
|
3
|
+
import { Result, ok, err } from 'neverthrow';
|
|
4
|
+
/**
|
|
5
|
+
* Functional programming utility functions
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Compose functions (right to left)
|
|
9
|
+
* compose(f, g)(x) = f(g(x))
|
|
10
|
+
*/
|
|
11
|
+
export function compose(f, g) {
|
|
12
|
+
return (a) => f(g(a));
|
|
13
|
+
}
|
|
14
|
+
export function pipe(value, ...fns) {
|
|
15
|
+
return fns.reduce((acc, fn) => fn(acc), value);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Function composition using Result type
|
|
19
|
+
*/
|
|
20
|
+
export function composeResult(f, g) {
|
|
21
|
+
return (a) => g(a).andThen(f);
|
|
22
|
+
}
|
|
23
|
+
export function pipeResult(value, ...fns) {
|
|
24
|
+
return fns.reduce((acc, fn) => acc.andThen(fn), value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Wrap operations with side effects in Result type
|
|
28
|
+
*/
|
|
29
|
+
export function tryCatch(fn, errorHandler) {
|
|
30
|
+
try {
|
|
31
|
+
return ok(fn());
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (errorHandler) {
|
|
35
|
+
return err(errorHandler(error));
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
return err(error);
|
|
39
|
+
}
|
|
40
|
+
return err(new Error(String(error)));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wrap asynchronous operations with side effects in Result type
|
|
45
|
+
*/
|
|
46
|
+
export async function tryCatchAsync(fn, errorHandler) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await fn();
|
|
49
|
+
return ok(result);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (errorHandler) {
|
|
53
|
+
return err(errorHandler(error));
|
|
54
|
+
}
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
return err(error);
|
|
57
|
+
}
|
|
58
|
+
return err(new Error(String(error)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply Result type function to each element of array, return result only if all succeed
|
|
63
|
+
*/
|
|
64
|
+
export function mapResult(items, fn) {
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const item of items) {
|
|
67
|
+
const result = fn(item);
|
|
68
|
+
if (result.isErr()) {
|
|
69
|
+
return err(result.error);
|
|
70
|
+
}
|
|
71
|
+
results.push(result.value);
|
|
72
|
+
}
|
|
73
|
+
return ok(results);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return Result type based on condition
|
|
77
|
+
*/
|
|
78
|
+
export function fromPredicate(predicate, value, errorFactory) {
|
|
79
|
+
return predicate(value) ? ok(value) : err(errorFactory(value));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Maybe-like null/undefined check
|
|
83
|
+
*/
|
|
84
|
+
export function fromNullable(value, errorFactory) {
|
|
85
|
+
return value != null ? ok(value) : err(errorFactory());
|
|
86
|
+
}
|
|
87
|
+
export function combine(...results) {
|
|
88
|
+
const values = [];
|
|
89
|
+
for (const result of results) {
|
|
90
|
+
if (result.isErr()) {
|
|
91
|
+
return err(result.error);
|
|
92
|
+
}
|
|
93
|
+
values.push(result.value);
|
|
94
|
+
}
|
|
95
|
+
return ok(values);
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sizuku",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
4
5
|
"description": "Sizuku is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Drizzle schemas annotated with comments.",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"keywords": [
|
|
@@ -26,9 +27,7 @@
|
|
|
26
27
|
"dist"
|
|
27
28
|
],
|
|
28
29
|
"bin": {
|
|
29
|
-
"sizuku
|
|
30
|
-
"sizuku-valibot": "dist/generator/valibot/index.js",
|
|
31
|
-
"sizuku-mermaid-er": "dist/generator/mermaid-er/index.js"
|
|
30
|
+
"sizuku": "dist/index.js"
|
|
32
31
|
},
|
|
33
32
|
"scripts": {
|
|
34
33
|
"deps": "rm -rf node_modules && pnpm install",
|
|
@@ -43,14 +42,16 @@
|
|
|
43
42
|
"release": "npm pkg fix && pnpm build && npm publish"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^22.
|
|
47
|
-
"@vitest/coverage-v8": "^3.
|
|
48
|
-
"drizzle-orm": "^0.40.
|
|
45
|
+
"@types/node": "^22.15.34",
|
|
46
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
47
|
+
"drizzle-orm": "^0.40.1",
|
|
49
48
|
"valibot": "1.0.0-rc.3",
|
|
50
|
-
"vitest": "^3.
|
|
51
|
-
"zod": "^3.
|
|
49
|
+
"vitest": "^3.2.4",
|
|
50
|
+
"zod": "^3.25.67"
|
|
52
51
|
},
|
|
53
52
|
"dependencies": {
|
|
54
|
-
"
|
|
53
|
+
"neverthrow": "^8.2.0",
|
|
54
|
+
"prettier": "^3.6.2",
|
|
55
|
+
"ts-morph": "^26.0.0"
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type Config = {
|
|
2
|
-
schema: {
|
|
3
|
-
name: 'PascalCase' | 'camelCase';
|
|
4
|
-
};
|
|
5
|
-
type: {
|
|
6
|
-
name: 'PascalCase' | 'camelCase';
|
|
7
|
-
export: boolean;
|
|
8
|
-
};
|
|
9
|
-
input?: string;
|
|
10
|
-
output?: string;
|
|
11
|
-
comment?: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare const DEFAULT_CONFIG: Config;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatCode(code: string): Promise<string>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatCode = formatCode;
|
|
4
|
-
const prettier_1 = require("prettier");
|
|
5
|
-
async function formatCode(code) {
|
|
6
|
-
return await (0, prettier_1.format)(code, {
|
|
7
|
-
parser: 'typescript',
|
|
8
|
-
printWidth: 100,
|
|
9
|
-
singleQuote: true,
|
|
10
|
-
semi: false,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFieldDefinitions = generateFieldDefinitions;
|
|
4
|
-
/**
|
|
5
|
-
* @function generateFieldDefinitions
|
|
6
|
-
* @param schema
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
function generateFieldDefinitions(schema, config) {
|
|
10
|
-
return schema.fields
|
|
11
|
-
.map(({ name, definition, description }) => {
|
|
12
|
-
const comment = description && config.comment ? `/**\n* ${description}\n*/\n` : '';
|
|
13
|
-
return `${comment}${name}:${definition}`;
|
|
14
|
-
})
|
|
15
|
-
.join(',\n');
|
|
16
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCamelCaseSchemaNameHelper = getCamelCaseSchemaNameHelper;
|
|
4
|
-
const decapitalize_1 = require("../text/decapitalize");
|
|
5
|
-
/**
|
|
6
|
-
* Generates a camelCase schema name from a given schema name.
|
|
7
|
-
*
|
|
8
|
-
* @param schemaName - The original schema name.
|
|
9
|
-
* @returns The camelCase schema name.
|
|
10
|
-
*/
|
|
11
|
-
function getCamelCaseSchemaNameHelper(schemaName) {
|
|
12
|
-
const decapitalizedSchemaName = (0, decapitalize_1.decapitalize)(schemaName);
|
|
13
|
-
return `${decapitalizedSchemaName}Schema`;
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a PascalCase schema name from a given schema name.
|
|
3
|
-
*
|
|
4
|
-
* @function getPascalCaseSchemaName
|
|
5
|
-
* @param schemaName - The original schema name.
|
|
6
|
-
* @returns The PascalCase schema name.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getPascalCaseSchemaNameHelper(schemaName: string): string;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPascalCaseSchemaNameHelper = getPascalCaseSchemaNameHelper;
|
|
4
|
-
const capitalize_1 = require("../text/capitalize");
|
|
5
|
-
/**
|
|
6
|
-
* Generates a PascalCase schema name from a given schema name.
|
|
7
|
-
*
|
|
8
|
-
* @function getPascalCaseSchemaName
|
|
9
|
-
* @param schemaName - The original schema name.
|
|
10
|
-
* @returns The PascalCase schema name.
|
|
11
|
-
*/
|
|
12
|
-
function getPascalCaseSchemaNameHelper(schemaName) {
|
|
13
|
-
const capitalizedSchemaName = (0, capitalize_1.capitalize)(schemaName);
|
|
14
|
-
return `${capitalizedSchemaName}Schema`;
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../config';
|
|
2
|
-
/**
|
|
3
|
-
* Get the variable name helper
|
|
4
|
-
*
|
|
5
|
-
* @param name - The name of the schema
|
|
6
|
-
* @param config - The config
|
|
7
|
-
* @returns The variable name helper
|
|
8
|
-
*/
|
|
9
|
-
export declare function getVariableNameHelper(name: string, config: Config): string;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariableNameHelper = getVariableNameHelper;
|
|
4
|
-
const capitalize_1 = require("../text/capitalize");
|
|
5
|
-
const decapitalize_1 = require("../text/decapitalize");
|
|
6
|
-
/**
|
|
7
|
-
* Get the variable name helper
|
|
8
|
-
*
|
|
9
|
-
* @param name - The name of the schema
|
|
10
|
-
* @param config - The config
|
|
11
|
-
* @returns The variable name helper
|
|
12
|
-
*/
|
|
13
|
-
function getVariableNameHelper(name, config) {
|
|
14
|
-
return config.type.name === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../config';
|
|
2
|
-
/**
|
|
3
|
-
* Get the variable schema name helper
|
|
4
|
-
*
|
|
5
|
-
* @param name - The name of the schema
|
|
6
|
-
* @param config - The config
|
|
7
|
-
* @returns The variable schema name helper
|
|
8
|
-
*/
|
|
9
|
-
export declare function getVariableSchemaNameHelper(name: string, config: Config): string;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariableSchemaNameHelper = getVariableSchemaNameHelper;
|
|
4
|
-
const get_camel_case_schema_name_helper_1 = require("./get-camel-case-schema-name-helper");
|
|
5
|
-
const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-name-helper");
|
|
6
|
-
/**
|
|
7
|
-
* Get the variable schema name helper
|
|
8
|
-
*
|
|
9
|
-
* @param name - The name of the schema
|
|
10
|
-
* @param config - The config
|
|
11
|
-
* @returns The variable schema name helper
|
|
12
|
-
*/
|
|
13
|
-
function getVariableSchemaNameHelper(name, config) {
|
|
14
|
-
return config.schema.name === 'camelCase'
|
|
15
|
-
? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaNameHelper)(name)
|
|
16
|
-
: (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaNameHelper)(name);
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decapitalizes the first letter of a string
|
|
3
|
-
*
|
|
4
|
-
* @function decapitalize
|
|
5
|
-
* @param str - String to decapitalize
|
|
6
|
-
* @returns String with the first letter in lowercase
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* decapitalize('Posts') // Returns: 'posts'
|
|
10
|
-
* decapitalize('User') // Returns: 'user'
|
|
11
|
-
* decapitalize('Api') // Returns: 'api'
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* - Leaves the rest of the string unchanged
|
|
15
|
-
* - Returns an empty string if the input is empty
|
|
16
|
-
*/
|
|
17
|
-
export declare function decapitalize(str: string): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decapitalize = decapitalize;
|
|
4
|
-
/**
|
|
5
|
-
* Decapitalizes the first letter of a string
|
|
6
|
-
*
|
|
7
|
-
* @function decapitalize
|
|
8
|
-
* @param str - String to decapitalize
|
|
9
|
-
* @returns String with the first letter in lowercase
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* decapitalize('Posts') // Returns: 'posts'
|
|
13
|
-
* decapitalize('User') // Returns: 'user'
|
|
14
|
-
* decapitalize('Api') // Returns: 'api'
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* - Leaves the rest of the string unchanged
|
|
18
|
-
* - Returns an empty string if the input is empty
|
|
19
|
-
*/
|
|
20
|
-
function decapitalize(str) {
|
|
21
|
-
return `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
|
|
22
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { RelationType } from '../type'
|
|
2
|
-
/**
|
|
3
|
-
* Validate if a value is a valid relation type
|
|
4
|
-
* @param value - The value to validate
|
|
5
|
-
* @returns True if the value is a valid relation type, false otherwise
|
|
6
|
-
*/
|
|
7
|
-
export declare function isRelation(value: unknown): value is RelationType
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRelation = isRelation;
|
|
4
|
-
const VALID_RELATIONS = new Set([
|
|
5
|
-
// Required Relationships
|
|
6
|
-
'one-to-one',
|
|
7
|
-
'one-to-many',
|
|
8
|
-
'many-to-one',
|
|
9
|
-
'many-to-many',
|
|
10
|
-
'one-to-zero-one',
|
|
11
|
-
'zero-one-to-one',
|
|
12
|
-
'zero-to-one',
|
|
13
|
-
'zero-to-zero-one',
|
|
14
|
-
'zero-to-many',
|
|
15
|
-
'zero-one-to-many',
|
|
16
|
-
'many-to-zero-one',
|
|
17
|
-
// Optional Relationships (using dotted lines)
|
|
18
|
-
'one-to-one-optional',
|
|
19
|
-
'one-to-many-optional',
|
|
20
|
-
'many-to-one-optional',
|
|
21
|
-
'many-to-many-optional',
|
|
22
|
-
'one-to-zero-one-optional',
|
|
23
|
-
'zero-one-to-one-optional',
|
|
24
|
-
'zero-to-one-optional',
|
|
25
|
-
'zero-to-many-optional',
|
|
26
|
-
'zero-one-to-many-optional',
|
|
27
|
-
'many-to-zero-one-optional',
|
|
28
|
-
// Nuanced Patterns (Aliases)
|
|
29
|
-
'many-to-zero-many',
|
|
30
|
-
'zero-many-to-many',
|
|
31
|
-
'zero-many-to-zero-many',
|
|
32
|
-
]);
|
|
33
|
-
/**
|
|
34
|
-
* Validate if a value is a valid relation type
|
|
35
|
-
* @param value - The value to validate
|
|
36
|
-
* @returns True if the value is a valid relation type, false otherwise
|
|
37
|
-
*/
|
|
38
|
-
function isRelation(value) {
|
|
39
|
-
return typeof value === 'string' && VALID_RELATIONS.has(value);
|
|
40
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '../../../common/type';
|
|
2
|
-
import type { Config } from '../../../common/config';
|
|
3
|
-
/**
|
|
4
|
-
* Generates Valibot code for a given schema and config.
|
|
5
|
-
*
|
|
6
|
-
* @function generateValibotCode
|
|
7
|
-
* @param schema - The schema to generate code for.
|
|
8
|
-
* @param config - The configuration for the code generation.
|
|
9
|
-
* @returns The generated Valibot code.
|
|
10
|
-
*/
|
|
11
|
-
export declare function generateValibotCode(schema: Schema, config: Config): string;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotCode = generateValibotCode;
|
|
4
|
-
const generate_valibot_infer_input_1 = require("./generate-valibot-infer-input");
|
|
5
|
-
const generate_valibot_schema_1 = require("./generate-valibot-schema");
|
|
6
|
-
/**
|
|
7
|
-
* Generates Valibot code for a given schema and config.
|
|
8
|
-
*
|
|
9
|
-
* @function generateValibotCode
|
|
10
|
-
* @param schema - The schema to generate code for.
|
|
11
|
-
* @param config - The configuration for the code generation.
|
|
12
|
-
* @returns The generated Valibot code.
|
|
13
|
-
*/
|
|
14
|
-
function generateValibotCode(schema, config) {
|
|
15
|
-
const valibotSchema = (0, generate_valibot_schema_1.generateValibotSchema)(schema, config);
|
|
16
|
-
const valibotInfer = (0, generate_valibot_infer_input_1.generateValibotInferInput)(schema, config);
|
|
17
|
-
if (config.type.export) {
|
|
18
|
-
return `${valibotSchema}\n\n${valibotInfer}\n`;
|
|
19
|
-
}
|
|
20
|
-
return `${valibotSchema}\n`;
|
|
21
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '../../../common/type';
|
|
2
|
-
import type { Config } from '../../../common/config';
|
|
3
|
-
/**
|
|
4
|
-
* @function generateValibotInferInput
|
|
5
|
-
* @param schema
|
|
6
|
-
* @param config
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateValibotInferInput(schema: Schema, config: Config): string;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotInferInput = generateValibotInferInput;
|
|
4
|
-
const get_variable_name_helper_1 = require("../../../common/helper/get-variable-name-helper");
|
|
5
|
-
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
6
|
-
/**
|
|
7
|
-
* @function generateValibotInferInput
|
|
8
|
-
* @param schema
|
|
9
|
-
* @param config
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function generateValibotInferInput(schema, config) {
|
|
13
|
-
const typeName = (0, get_variable_name_helper_1.getVariableNameHelper)(schema.name, config);
|
|
14
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(schema.name, config);
|
|
15
|
-
return `export type ${typeName} = v.InferInput<typeof ${schemaName}>`;
|
|
16
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '../../../common/type';
|
|
2
|
-
import type { Config } from '../../../common/config';
|
|
3
|
-
/**
|
|
4
|
-
* @function generateValibotSchema
|
|
5
|
-
* @param schema
|
|
6
|
-
* @param config
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateValibotSchema(schema: Schema, config: Config): string;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateValibotSchema = generateValibotSchema;
|
|
4
|
-
const generate_field_definitions_1 = require("../../../common/generator/generate-field-definitions");
|
|
5
|
-
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
6
|
-
/**
|
|
7
|
-
* @function generateValibotSchema
|
|
8
|
-
* @param schema
|
|
9
|
-
* @param config
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function generateValibotSchema(schema, config) {
|
|
13
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(schema.name, config);
|
|
14
|
-
const res = (0, generate_field_definitions_1.generateFieldDefinitions)(schema, config);
|
|
15
|
-
return `export const ${schemaName} = v.object({${res}})`;
|
|
16
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '../../../common/type';
|
|
2
|
-
import type { Config } from '../../../common/config';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a Zod infer type for a given schema and config.
|
|
5
|
-
*
|
|
6
|
-
* @function generateZInfer
|
|
7
|
-
* @param schema - The schema to generate code for.
|
|
8
|
-
* @param config - The configuration for the code generation.
|
|
9
|
-
* @returns The generated Zod infer type.
|
|
10
|
-
*/
|
|
11
|
-
export declare function generateZInfer(schema: Schema, config: Config): string;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateZInfer = generateZInfer;
|
|
4
|
-
const get_variable_name_helper_1 = require("../../../common/helper/get-variable-name-helper");
|
|
5
|
-
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
6
|
-
/**
|
|
7
|
-
* Generates a Zod infer type for a given schema and config.
|
|
8
|
-
*
|
|
9
|
-
* @function generateZInfer
|
|
10
|
-
* @param schema - The schema to generate code for.
|
|
11
|
-
* @param config - The configuration for the code generation.
|
|
12
|
-
* @returns The generated Zod infer type.
|
|
13
|
-
*/
|
|
14
|
-
function generateZInfer(schema, config) {
|
|
15
|
-
const typeName = (0, get_variable_name_helper_1.getVariableNameHelper)(schema.name, config);
|
|
16
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(schema.name, config);
|
|
17
|
-
return `export type ${typeName} = z.infer<typeof ${schemaName}>`;
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateZodCode = generateZodCode;
|
|
4
|
-
const generate_z_infer_1 = require("./generate-z-infer");
|
|
5
|
-
const generate_zod_schema_1 = require("./generate-zod-schema");
|
|
6
|
-
/**
|
|
7
|
-
* Generates Zod code for a given schema and config.
|
|
8
|
-
*
|
|
9
|
-
* @function generateZodCode
|
|
10
|
-
* @param schema - The schema to generate code for.
|
|
11
|
-
* @param config - The configuration for the code generation.
|
|
12
|
-
* @returns The generated Zod code.
|
|
13
|
-
*/
|
|
14
|
-
function generateZodCode(schema, config) {
|
|
15
|
-
const zodSchema = (0, generate_zod_schema_1.generateZodSchema)(schema, config);
|
|
16
|
-
const zInfer = (0, generate_z_infer_1.generateZInfer)(schema, config);
|
|
17
|
-
if (config.type.export) {
|
|
18
|
-
return `${zodSchema}\n\n${zInfer}\n`;
|
|
19
|
-
}
|
|
20
|
-
return `${zodSchema}\n`;
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateZodSchema = generateZodSchema;
|
|
4
|
-
const get_variable_schema_name_helper_1 = require("../../../common/helper/get-variable-schema-name-helper");
|
|
5
|
-
const generate_field_definitions_1 = require("../../../common/generator/generate-field-definitions");
|
|
6
|
-
/**
|
|
7
|
-
* Generates a Zod schema for a given schema and config.
|
|
8
|
-
*
|
|
9
|
-
* @function generateZodSchema
|
|
10
|
-
* @param schema - The schema to generate code for.
|
|
11
|
-
* @param config - The configuration for the code generation.
|
|
12
|
-
* @returns The generated Zod schema.
|
|
13
|
-
*/
|
|
14
|
-
function generateZodSchema(schema, config) {
|
|
15
|
-
const schemaName = (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(schema.name, config);
|
|
16
|
-
return `export const ${schemaName} = z.object({${(0, generate_field_definitions_1.generateFieldDefinitions)(schema, config)}})`;
|
|
17
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|