routesync 1.0.30 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +11 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8976,11 +8976,7 @@ var SchemaGenerator = class {
|
|
|
8976
8976
|
lines.push(`export const ${schemaName} = z.object({`);
|
|
8977
8977
|
for (const [field, rules] of Object.entries(route.schema.rules)) {
|
|
8978
8978
|
const ruleStr = Array.isArray(rules) ? rules.join("|") : String(rules);
|
|
8979
|
-
let zodRule =
|
|
8980
|
-
if (ruleStr.includes("string")) zodRule = "z.string()";
|
|
8981
|
-
if (ruleStr.includes("numeric") || ruleStr.includes("integer") || ruleStr.includes("int")) zodRule = "z.number()";
|
|
8982
|
-
if (ruleStr.includes("boolean") || ruleStr.includes("bool")) zodRule = "z.boolean()";
|
|
8983
|
-
if (ruleStr.includes("array")) zodRule = "z.array(z.unknown())";
|
|
8979
|
+
let zodRule = this.mapRulesToZod(ruleStr);
|
|
8984
8980
|
if (!ruleStr.includes("required")) {
|
|
8985
8981
|
zodRule += ".optional()";
|
|
8986
8982
|
}
|
|
@@ -8998,6 +8994,16 @@ var SchemaGenerator = class {
|
|
|
8998
8994
|
}
|
|
8999
8995
|
await import_fs_extra5.default.writeFile(import_path4.default.join(outputDir, "schemas.ts"), lines.join("\n"));
|
|
9000
8996
|
}
|
|
8997
|
+
/**
|
|
8998
|
+
* Map a Laravel validation rule string to a Zod type.
|
|
8999
|
+
* Default is z.string() — HTTP inputs are strings unless explicitly typed.
|
|
9000
|
+
*/
|
|
9001
|
+
static mapRulesToZod(ruleStr) {
|
|
9002
|
+
if (ruleStr.includes("array")) return "z.array(z.unknown())";
|
|
9003
|
+
if (ruleStr.includes("integer") || ruleStr.includes("numeric") || ruleStr.includes("digits")) return "z.number()";
|
|
9004
|
+
if (ruleStr.includes("boolean") || ruleStr.includes("bool")) return "z.boolean()";
|
|
9005
|
+
return "z.string()";
|
|
9006
|
+
}
|
|
9001
9007
|
static mapSqlTypeToZod(sqlType) {
|
|
9002
9008
|
const type = sqlType.toLowerCase();
|
|
9003
9009
|
if (type.includes("int") || type.includes("float") || type.includes("double") || type.includes("decimal") || type.includes("numeric")) {
|