@famgia/omnify-typescript 0.0.148 → 0.0.149
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/{chunk-PA7B7ZFK.js → chunk-VLDDJNHY.js} +18 -13
- package/dist/chunk-VLDDJNHY.js.map +1 -0
- package/dist/index.cjs +25 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -66
- package/dist/index.d.ts +29 -66
- package/dist/index.js +9 -51
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs +56 -166
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +27 -55
- package/dist/plugin.d.ts +27 -55
- package/dist/plugin.js +39 -144
- package/dist/plugin.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-PA7B7ZFK.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,21 +15,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var index_exports = {};
|
|
32
22
|
__export(index_exports, {
|
|
33
23
|
DEFAULT_VALIDATION_TEMPLATES: () => DEFAULT_VALIDATION_TEMPLATES,
|
|
34
|
-
STUB_FILES: () => STUB_FILES,
|
|
35
24
|
copyStubs: () => copyStubs,
|
|
36
25
|
enumToUnionType: () => enumToUnionType,
|
|
37
26
|
extractInlineEnums: () => extractInlineEnums,
|
|
@@ -49,7 +38,6 @@ __export(index_exports, {
|
|
|
49
38
|
generateTypeScript: () => generateTypeScript,
|
|
50
39
|
generateTypeScriptFiles: () => generateTypeScript,
|
|
51
40
|
getPropertyType: () => getPropertyType,
|
|
52
|
-
getStubPaths: () => getStubPaths,
|
|
53
41
|
getValidationMessages: () => getValidationMessages,
|
|
54
42
|
mergeValidationTemplates: () => mergeValidationTemplates,
|
|
55
43
|
pluginEnumToTSEnum: () => pluginEnumToTSEnum,
|
|
@@ -387,6 +375,10 @@ function resolveDisplayName2(value, options = {}) {
|
|
|
387
375
|
config: options.localeConfig
|
|
388
376
|
});
|
|
389
377
|
}
|
|
378
|
+
function toPascalCase(value) {
|
|
379
|
+
const normalized = value.replace(/([a-z])([A-Z])/g, "$1_$2");
|
|
380
|
+
return normalized.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
381
|
+
}
|
|
390
382
|
function toEnumMemberName(value) {
|
|
391
383
|
let result = value.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
392
384
|
if (/^\d/.test(result)) {
|
|
@@ -674,7 +666,7 @@ function extractInlineEnums(schemas, options = {}) {
|
|
|
674
666
|
if (property.type === "Enum") {
|
|
675
667
|
const enumProp = property;
|
|
676
668
|
if (Array.isArray(enumProp.enum) && enumProp.enum.length > 0) {
|
|
677
|
-
const typeName = `${schema.name}${
|
|
669
|
+
const typeName = `${schema.name}${toPascalCase(propName)}`;
|
|
678
670
|
const displayName = resolveDisplayName2(enumProp.displayName, options);
|
|
679
671
|
const hasLabels = enumProp.enum.some((v) => typeof v !== "string" && v.label !== void 0);
|
|
680
672
|
if (hasLabels) {
|
|
@@ -703,7 +695,7 @@ function extractInlineEnums(schemas, options = {}) {
|
|
|
703
695
|
if (property.type === "Select") {
|
|
704
696
|
const selectProp = property;
|
|
705
697
|
if (selectProp.options && selectProp.options.length > 0) {
|
|
706
|
-
const typeName = `${schema.name}${
|
|
698
|
+
const typeName = `${schema.name}${toPascalCase(propName)}`;
|
|
707
699
|
const displayName = resolveDisplayName2(selectProp.displayName, options);
|
|
708
700
|
const hasLabels = selectProp.options.some((v) => typeof v !== "string" && v.label !== void 0);
|
|
709
701
|
if (hasLabels) {
|
|
@@ -1100,15 +1092,15 @@ function applyValidationRules(schema, rules, propType) {
|
|
|
1100
1092
|
if (!rules) return schema;
|
|
1101
1093
|
let result = schema;
|
|
1102
1094
|
if (rules.url) {
|
|
1103
|
-
result = "z.url()";
|
|
1095
|
+
result = "z.string().url()";
|
|
1104
1096
|
} else if (rules.uuid) {
|
|
1105
|
-
result = "z.uuid()";
|
|
1097
|
+
result = "z.string().uuid()";
|
|
1106
1098
|
} else if (rules.ip) {
|
|
1107
|
-
result = "z.ip()";
|
|
1099
|
+
result = "z.string().ip()";
|
|
1108
1100
|
} else if (rules.ipv4) {
|
|
1109
|
-
result =
|
|
1101
|
+
result = 'z.string().ip({ version: "v4" })';
|
|
1110
1102
|
} else if (rules.ipv6) {
|
|
1111
|
-
result =
|
|
1103
|
+
result = 'z.string().ip({ version: "v6" })';
|
|
1112
1104
|
}
|
|
1113
1105
|
const isStringType = ["String", "Text", "MediumText", "LongText", "Password", "Email"].includes(propType);
|
|
1114
1106
|
if (isStringType) {
|
|
@@ -1225,7 +1217,7 @@ function getZodSchemaForType(propDef, fieldName, customTypes) {
|
|
|
1225
1217
|
}
|
|
1226
1218
|
break;
|
|
1227
1219
|
case "Email":
|
|
1228
|
-
schema = "z.email()";
|
|
1220
|
+
schema = "z.string().email()";
|
|
1229
1221
|
if (def.maxLength || def.length) {
|
|
1230
1222
|
schema += `.max(${def.maxLength ?? def.length ?? 255})`;
|
|
1231
1223
|
}
|
|
@@ -1330,9 +1322,9 @@ function generateCompoundTypeSchemas(propName, propDef, customType, options) {
|
|
|
1330
1322
|
const format = overrideRules?.format ?? pluginRules?.format;
|
|
1331
1323
|
let schema = "z.string()";
|
|
1332
1324
|
if (format === "email") {
|
|
1333
|
-
schema = "z.email()";
|
|
1325
|
+
schema = "z.string().email()";
|
|
1334
1326
|
} else if (format === "url") {
|
|
1335
|
-
schema = "z.url()";
|
|
1327
|
+
schema = "z.string().url()";
|
|
1336
1328
|
} else if (format === "phone") {
|
|
1337
1329
|
schema = "z.string()";
|
|
1338
1330
|
} else if (format === "postal_code") {
|
|
@@ -1837,7 +1829,7 @@ function generateBaseInterfaceFile(schemaName, schemas, options) {
|
|
|
1837
1829
|
`);
|
|
1838
1830
|
}
|
|
1839
1831
|
if (iface.enumDependencies && iface.enumDependencies.length > 0) {
|
|
1840
|
-
const schemaEnumPrefix = options.schemaEnumImportPrefix ?? (options.enumImportPrefix ? `../${options.enumImportPrefix}` : "../enum");
|
|
1832
|
+
const schemaEnumPrefix = options.schemaEnumImportPrefix ?? (options.enumImportPrefix?.startsWith("@") ? options.enumImportPrefix : options.enumImportPrefix ? `../${options.enumImportPrefix}` : "../enum");
|
|
1841
1833
|
const pluginEnumNames = new Set(
|
|
1842
1834
|
options.pluginEnums ? Array.from(options.pluginEnums.keys()) : []
|
|
1843
1835
|
);
|
|
@@ -2186,6 +2178,7 @@ function generateIndexFile(schemas, enums, pluginEnums, typeAliases, options) {
|
|
|
2186
2178
|
const ext = getImportExt2(options);
|
|
2187
2179
|
const isNodeModulesBase = options.baseImportPrefix?.startsWith("@");
|
|
2188
2180
|
const commonImportPath = isNodeModulesBase ? `${options.baseImportPrefix}/common` : "./common";
|
|
2181
|
+
const i18nImportPath = isNodeModulesBase ? `${options.baseImportPrefix}/i18n` : "./i18n";
|
|
2189
2182
|
parts.push(`// Common Types
|
|
2190
2183
|
`);
|
|
2191
2184
|
parts.push(`export type { LocaleMap, Locale, ValidationRule, DateTimeString, DateString } from '${commonImportPath}${ext}';
|
|
@@ -2207,7 +2200,7 @@ function generateIndexFile(schemas, enums, pluginEnums, typeAliases, options) {
|
|
|
2207
2200
|
`);
|
|
2208
2201
|
parts.push(` getMessages,
|
|
2209
2202
|
`);
|
|
2210
|
-
parts.push(`} from '
|
|
2203
|
+
parts.push(`} from '${i18nImportPath}${ext}';
|
|
2211
2204
|
|
|
2212
2205
|
`);
|
|
2213
2206
|
const enumPrefix = options.enumImportPrefix ?? "./enum";
|
|
@@ -2419,55 +2412,6 @@ Hint: Rename your schema enum to avoid conflict with plugin-provided enums`
|
|
|
2419
2412
|
return files;
|
|
2420
2413
|
}
|
|
2421
2414
|
|
|
2422
|
-
// src/stubs.ts
|
|
2423
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
2424
|
-
var import_path = __toESM(require("path"), 1);
|
|
2425
|
-
var import_url = require("url");
|
|
2426
|
-
var import_meta = {};
|
|
2427
|
-
var __filename = (0, import_url.fileURLToPath)(import_meta.url);
|
|
2428
|
-
var __dirname = import_path.default.dirname(__filename);
|
|
2429
|
-
var STUB_FILES = [];
|
|
2430
|
-
function copyStubs(options) {
|
|
2431
|
-
const { targetDir, skipIfExists = false } = options;
|
|
2432
|
-
const stubsDir = import_path.default.join(__dirname, "..", "stubs");
|
|
2433
|
-
const result = { copied: [], skipped: [] };
|
|
2434
|
-
const directories = /* @__PURE__ */ new Map();
|
|
2435
|
-
for (const { stub, output, indexExport } of STUB_FILES) {
|
|
2436
|
-
const stubPath = import_path.default.join(stubsDir, stub);
|
|
2437
|
-
const outputPath = import_path.default.join(targetDir, output);
|
|
2438
|
-
const outputDir = import_path.default.dirname(outputPath);
|
|
2439
|
-
const dirName = import_path.default.dirname(output).split("/")[0];
|
|
2440
|
-
if (!directories.has(dirName)) {
|
|
2441
|
-
directories.set(dirName, "");
|
|
2442
|
-
}
|
|
2443
|
-
directories.set(dirName, directories.get(dirName) + indexExport);
|
|
2444
|
-
if (!import_fs.default.existsSync(outputDir)) {
|
|
2445
|
-
import_fs.default.mkdirSync(outputDir, { recursive: true });
|
|
2446
|
-
}
|
|
2447
|
-
if (skipIfExists && import_fs.default.existsSync(outputPath)) {
|
|
2448
|
-
result.skipped.push(output);
|
|
2449
|
-
continue;
|
|
2450
|
-
}
|
|
2451
|
-
if (import_fs.default.existsSync(stubPath)) {
|
|
2452
|
-
const content = import_fs.default.readFileSync(stubPath, "utf-8");
|
|
2453
|
-
import_fs.default.writeFileSync(outputPath, content);
|
|
2454
|
-
result.copied.push(output);
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
for (const [dirName, exports2] of directories) {
|
|
2458
|
-
const indexPath = import_path.default.join(targetDir, dirName, "index.ts");
|
|
2459
|
-
if (skipIfExists && import_fs.default.existsSync(indexPath)) {
|
|
2460
|
-
continue;
|
|
2461
|
-
}
|
|
2462
|
-
import_fs.default.writeFileSync(indexPath, exports2);
|
|
2463
|
-
result.copied.push(`${dirName}/index.ts`);
|
|
2464
|
-
}
|
|
2465
|
-
return result;
|
|
2466
|
-
}
|
|
2467
|
-
function getStubPaths() {
|
|
2468
|
-
return STUB_FILES.map((s) => s.output);
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
2415
|
// src/ai-guides/generator.ts
|
|
2472
2416
|
var import_node_fs = require("fs");
|
|
2473
2417
|
var import_node_path = require("path");
|
|
@@ -2519,10 +2463,17 @@ function shouldGenerateAIGuides(rootDir) {
|
|
|
2519
2463
|
return true;
|
|
2520
2464
|
}
|
|
2521
2465
|
}
|
|
2466
|
+
|
|
2467
|
+
// src/stubs.ts
|
|
2468
|
+
function copyStubs(_options) {
|
|
2469
|
+
return {
|
|
2470
|
+
copied: [],
|
|
2471
|
+
skipped: []
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2522
2474
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2523
2475
|
0 && (module.exports = {
|
|
2524
2476
|
DEFAULT_VALIDATION_TEMPLATES,
|
|
2525
|
-
STUB_FILES,
|
|
2526
2477
|
copyStubs,
|
|
2527
2478
|
enumToUnionType,
|
|
2528
2479
|
extractInlineEnums,
|
|
@@ -2540,7 +2491,6 @@ function shouldGenerateAIGuides(rootDir) {
|
|
|
2540
2491
|
generateTypeScript,
|
|
2541
2492
|
generateTypeScriptFiles,
|
|
2542
2493
|
getPropertyType,
|
|
2543
|
-
getStubPaths,
|
|
2544
2494
|
getValidationMessages,
|
|
2545
2495
|
mergeValidationTemplates,
|
|
2546
2496
|
pluginEnumToTSEnum,
|