next-openapi-gen 1.4.1 → 1.4.2
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 +164 -51
- package/dist/index.js +164 -51
- package/dist/next/index.js +164 -51
- package/dist/react-router/index.js +164 -51
- package/dist/vite/index.js +164 -51
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2868,23 +2868,58 @@ var SymbolResolver = class {
|
|
|
2868
2868
|
}
|
|
2869
2869
|
/**
|
|
2870
2870
|
* Returns a simple literal value (string/number/boolean/null) for a `const` declarator,
|
|
2871
|
-
*
|
|
2871
|
+
* following imports and re-exports when the name is not declared locally.
|
|
2872
2872
|
*/
|
|
2873
2873
|
resolveLiteral(filePath, name) {
|
|
2874
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2875
|
+
return this.resolveLiteralInternal(filePath, name, visited);
|
|
2876
|
+
}
|
|
2877
|
+
resolveLiteralInternal(filePath, name, visited) {
|
|
2878
|
+
if (visited.has(filePath))
|
|
2879
|
+
return void 0;
|
|
2880
|
+
visited.add(filePath);
|
|
2874
2881
|
const index = this.getIndex(filePath);
|
|
2875
2882
|
if (!index)
|
|
2876
2883
|
return void 0;
|
|
2877
2884
|
const literal2 = index.constLiterals.get(name);
|
|
2878
|
-
if (
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2885
|
+
if (literal2) {
|
|
2886
|
+
if (t3.isStringLiteral(literal2))
|
|
2887
|
+
return literal2.value;
|
|
2888
|
+
if (t3.isNumericLiteral(literal2))
|
|
2889
|
+
return literal2.value;
|
|
2890
|
+
if (t3.isBooleanLiteral(literal2))
|
|
2891
|
+
return literal2.value;
|
|
2892
|
+
if (t3.isNullLiteral(literal2))
|
|
2893
|
+
return null;
|
|
2894
|
+
}
|
|
2895
|
+
const imports = this.getImports(filePath);
|
|
2896
|
+
const importInfo = imports?.get(name);
|
|
2897
|
+
if (importInfo) {
|
|
2898
|
+
const resolved = this.resolveImportPath(filePath, importInfo.source);
|
|
2899
|
+
if (resolved) {
|
|
2900
|
+
const targetName = importInfo.importedName === "default" ? name : importInfo.importedName;
|
|
2901
|
+
const result = this.resolveLiteralInternal(resolved, targetName, visited);
|
|
2902
|
+
if (result !== void 0)
|
|
2903
|
+
return result;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
const reExport = index.namedReExports.get(name);
|
|
2907
|
+
if (reExport) {
|
|
2908
|
+
const resolved = this.resolveImportPath(filePath, reExport.source);
|
|
2909
|
+
if (resolved) {
|
|
2910
|
+
const result = this.resolveLiteralInternal(resolved, reExport.importedName, visited);
|
|
2911
|
+
if (result !== void 0)
|
|
2912
|
+
return result;
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
for (const starSrc of index.exportsStar) {
|
|
2916
|
+
const resolved = this.resolveImportPath(filePath, starSrc);
|
|
2917
|
+
if (!resolved)
|
|
2918
|
+
continue;
|
|
2919
|
+
const result = this.resolveLiteralInternal(resolved, name, visited);
|
|
2920
|
+
if (result !== void 0)
|
|
2921
|
+
return result;
|
|
2922
|
+
}
|
|
2888
2923
|
return void 0;
|
|
2889
2924
|
}
|
|
2890
2925
|
/**
|
|
@@ -13207,6 +13242,58 @@ var ZodSchemaConverter = class {
|
|
|
13207
13242
|
this.symbolResolver.primeAST(this.currentFilePath, this.currentAST);
|
|
13208
13243
|
return this.symbolResolver.resolveLiteral(this.currentFilePath, name);
|
|
13209
13244
|
}
|
|
13245
|
+
/**
|
|
13246
|
+
* Unwrap a possible `TSAsExpression` / `TSSatisfiesExpression` to get the
|
|
13247
|
+
* underlying expression node. Returns the node itself when no wrapper is
|
|
13248
|
+
* present.
|
|
13249
|
+
*/
|
|
13250
|
+
unwrapTypeAssertion(node) {
|
|
13251
|
+
if (!node)
|
|
13252
|
+
return void 0;
|
|
13253
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
13254
|
+
return node.expression;
|
|
13255
|
+
}
|
|
13256
|
+
return node;
|
|
13257
|
+
}
|
|
13258
|
+
/**
|
|
13259
|
+
* Resolve a numeric value from a call-expression argument.
|
|
13260
|
+
* Handles: numeric literals, identifier references to const numbers,
|
|
13261
|
+
* and `x as number` / `x satisfies number` wrappers around either.
|
|
13262
|
+
*/
|
|
13263
|
+
resolveNumericArg(arg) {
|
|
13264
|
+
if (!arg)
|
|
13265
|
+
return void 0;
|
|
13266
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
13267
|
+
if (t10.isNumericLiteral(node))
|
|
13268
|
+
return node.value;
|
|
13269
|
+
if (t10.isUnaryExpression(node) && node.operator === "-" && t10.isNumericLiteral(node.argument)) {
|
|
13270
|
+
return -node.argument.value;
|
|
13271
|
+
}
|
|
13272
|
+
if (t10.isIdentifier(node)) {
|
|
13273
|
+
const val = this.resolveLiteralValue(node.name);
|
|
13274
|
+
if (typeof val === "number")
|
|
13275
|
+
return val;
|
|
13276
|
+
}
|
|
13277
|
+
return void 0;
|
|
13278
|
+
}
|
|
13279
|
+
/**
|
|
13280
|
+
* Resolve a string value from a call-expression argument.
|
|
13281
|
+
* Handles: string literals, identifier references to const strings,
|
|
13282
|
+
* and `x as string` / `x satisfies string` wrappers around either.
|
|
13283
|
+
*/
|
|
13284
|
+
resolveStringArg(arg) {
|
|
13285
|
+
if (!arg)
|
|
13286
|
+
return void 0;
|
|
13287
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
13288
|
+
if (t10.isStringLiteral(node))
|
|
13289
|
+
return node.value;
|
|
13290
|
+
if (t10.isIdentifier(node)) {
|
|
13291
|
+
const val = this.resolveLiteralValue(node.name);
|
|
13292
|
+
if (typeof val === "string")
|
|
13293
|
+
return val;
|
|
13294
|
+
}
|
|
13295
|
+
return void 0;
|
|
13296
|
+
}
|
|
13210
13297
|
/**
|
|
13211
13298
|
* Resolve an identifier referring to a `z.object({...})` (or similar) call expression.
|
|
13212
13299
|
* This lets callers inline the referenced object's shape.
|
|
@@ -13275,6 +13362,14 @@ var ZodSchemaConverter = class {
|
|
|
13275
13362
|
if (t10.isNullLiteral(node)) {
|
|
13276
13363
|
return null;
|
|
13277
13364
|
}
|
|
13365
|
+
if (t10.isIdentifier(node)) {
|
|
13366
|
+
const val = this.resolveLiteralValue(node.name);
|
|
13367
|
+
if (val !== void 0)
|
|
13368
|
+
return val;
|
|
13369
|
+
}
|
|
13370
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
13371
|
+
return this.extractStaticJsonValue(node.expression);
|
|
13372
|
+
}
|
|
13278
13373
|
if (t10.isArrayExpression(node)) {
|
|
13279
13374
|
const values = [];
|
|
13280
13375
|
for (const element of node.elements) {
|
|
@@ -13373,53 +13468,60 @@ var ZodSchemaConverter = class {
|
|
|
13373
13468
|
schema.nullable = true;
|
|
13374
13469
|
}
|
|
13375
13470
|
break;
|
|
13376
|
-
case "describe":
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
if (
|
|
13471
|
+
case "describe": {
|
|
13472
|
+
const descVal = this.resolveStringArg(node.arguments[0]);
|
|
13473
|
+
if (descVal !== void 0) {
|
|
13474
|
+
if (descVal.startsWith("@deprecated")) {
|
|
13380
13475
|
schema.deprecated = true;
|
|
13381
|
-
schema.description =
|
|
13476
|
+
schema.description = descVal.replace("@deprecated", "").trim();
|
|
13382
13477
|
} else {
|
|
13383
|
-
schema.description =
|
|
13478
|
+
schema.description = descVal;
|
|
13384
13479
|
}
|
|
13385
13480
|
}
|
|
13386
13481
|
break;
|
|
13482
|
+
}
|
|
13387
13483
|
case "deprecated":
|
|
13388
13484
|
schema.deprecated = true;
|
|
13389
13485
|
break;
|
|
13390
|
-
case "min":
|
|
13391
|
-
|
|
13486
|
+
case "min": {
|
|
13487
|
+
const minVal = this.resolveNumericArg(node.arguments[0]);
|
|
13488
|
+
if (minVal !== void 0) {
|
|
13392
13489
|
if (schema.type === "string") {
|
|
13393
|
-
schema.minLength =
|
|
13490
|
+
schema.minLength = minVal;
|
|
13394
13491
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
13395
|
-
schema.minimum =
|
|
13492
|
+
schema.minimum = minVal;
|
|
13396
13493
|
} else if (schema.type === "array") {
|
|
13397
|
-
schema.minItems =
|
|
13494
|
+
schema.minItems = minVal;
|
|
13398
13495
|
}
|
|
13399
13496
|
}
|
|
13400
13497
|
break;
|
|
13401
|
-
|
|
13402
|
-
|
|
13498
|
+
}
|
|
13499
|
+
case "max": {
|
|
13500
|
+
const maxVal = this.resolveNumericArg(node.arguments[0]);
|
|
13501
|
+
if (maxVal !== void 0) {
|
|
13403
13502
|
if (schema.type === "string") {
|
|
13404
|
-
schema.maxLength =
|
|
13503
|
+
schema.maxLength = maxVal;
|
|
13405
13504
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
13406
|
-
schema.maximum =
|
|
13505
|
+
schema.maximum = maxVal;
|
|
13407
13506
|
} else if (schema.type === "array") {
|
|
13408
|
-
schema.maxItems =
|
|
13507
|
+
schema.maxItems = maxVal;
|
|
13409
13508
|
}
|
|
13410
13509
|
}
|
|
13411
13510
|
break;
|
|
13412
|
-
|
|
13413
|
-
|
|
13511
|
+
}
|
|
13512
|
+
case "length": {
|
|
13513
|
+
const lenVal = this.resolveNumericArg(node.arguments[0]);
|
|
13514
|
+
if (lenVal !== void 0) {
|
|
13414
13515
|
if (schema.type === "string") {
|
|
13415
|
-
schema.minLength =
|
|
13416
|
-
schema.maxLength =
|
|
13516
|
+
schema.minLength = lenVal;
|
|
13517
|
+
schema.maxLength = lenVal;
|
|
13417
13518
|
} else if (schema.type === "array") {
|
|
13418
|
-
schema.minItems =
|
|
13419
|
-
schema.maxItems =
|
|
13519
|
+
schema.minItems = lenVal;
|
|
13520
|
+
schema.maxItems = lenVal;
|
|
13420
13521
|
}
|
|
13421
13522
|
}
|
|
13422
13523
|
break;
|
|
13524
|
+
}
|
|
13423
13525
|
case "nonempty":
|
|
13424
13526
|
if (schema.type === "array") {
|
|
13425
13527
|
schema.minItems = Math.max(schema.minItems ?? 0, 1);
|
|
@@ -13495,21 +13597,27 @@ var ZodSchemaConverter = class {
|
|
|
13495
13597
|
schema.pattern = node.arguments[0].pattern;
|
|
13496
13598
|
}
|
|
13497
13599
|
break;
|
|
13498
|
-
case "startsWith":
|
|
13499
|
-
|
|
13500
|
-
|
|
13600
|
+
case "startsWith": {
|
|
13601
|
+
const swVal = this.resolveStringArg(node.arguments[0]);
|
|
13602
|
+
if (swVal !== void 0) {
|
|
13603
|
+
schema.pattern = `^${this.escapeRegExp(swVal)}`;
|
|
13501
13604
|
}
|
|
13502
13605
|
break;
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13606
|
+
}
|
|
13607
|
+
case "endsWith": {
|
|
13608
|
+
const ewVal = this.resolveStringArg(node.arguments[0]);
|
|
13609
|
+
if (ewVal !== void 0) {
|
|
13610
|
+
schema.pattern = `${this.escapeRegExp(ewVal)}$`;
|
|
13506
13611
|
}
|
|
13507
13612
|
break;
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13613
|
+
}
|
|
13614
|
+
case "includes": {
|
|
13615
|
+
const incVal = this.resolveStringArg(node.arguments[0]);
|
|
13616
|
+
if (incVal !== void 0) {
|
|
13617
|
+
schema.pattern = this.escapeRegExp(incVal);
|
|
13511
13618
|
}
|
|
13512
13619
|
break;
|
|
13620
|
+
}
|
|
13513
13621
|
case "int":
|
|
13514
13622
|
schema.type = "integer";
|
|
13515
13623
|
break;
|
|
@@ -13533,17 +13641,22 @@ var ZodSchemaConverter = class {
|
|
|
13533
13641
|
break;
|
|
13534
13642
|
case "default":
|
|
13535
13643
|
if (node.arguments.length > 0) {
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13644
|
+
const defaultArg = this.unwrapTypeAssertion(node.arguments[0]);
|
|
13645
|
+
if (t10.isStringLiteral(defaultArg)) {
|
|
13646
|
+
schema.default = defaultArg.value;
|
|
13647
|
+
} else if (t10.isNumericLiteral(defaultArg)) {
|
|
13648
|
+
schema.default = defaultArg.value;
|
|
13649
|
+
} else if (t10.isBooleanLiteral(defaultArg)) {
|
|
13650
|
+
schema.default = defaultArg.value;
|
|
13651
|
+
} else if (t10.isNullLiteral(defaultArg)) {
|
|
13543
13652
|
schema.default = null;
|
|
13544
|
-
} else if (t10.
|
|
13653
|
+
} else if (t10.isIdentifier(defaultArg)) {
|
|
13654
|
+
const val = this.resolveLiteralValue(defaultArg.name);
|
|
13655
|
+
if (val !== void 0)
|
|
13656
|
+
schema.default = val;
|
|
13657
|
+
} else if (t10.isObjectExpression(defaultArg)) {
|
|
13545
13658
|
const defaultObj = {};
|
|
13546
|
-
|
|
13659
|
+
defaultArg.properties.forEach((prop) => {
|
|
13547
13660
|
if (t10.isObjectProperty(prop) && (t10.isIdentifier(prop.key) || t10.isStringLiteral(prop.key)) && (t10.isStringLiteral(prop.value) || t10.isNumericLiteral(prop.value) || t10.isBooleanLiteral(prop.value))) {
|
|
13548
13661
|
const key = t10.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
13549
13662
|
const value = t10.isStringLiteral(prop.value) ? prop.value.value : t10.isNumericLiteral(prop.value) ? prop.value.value : t10.isBooleanLiteral(prop.value) ? prop.value.value : null;
|
package/dist/index.js
CHANGED
|
@@ -2417,23 +2417,58 @@ var SymbolResolver = class {
|
|
|
2417
2417
|
}
|
|
2418
2418
|
/**
|
|
2419
2419
|
* Returns a simple literal value (string/number/boolean/null) for a `const` declarator,
|
|
2420
|
-
*
|
|
2420
|
+
* following imports and re-exports when the name is not declared locally.
|
|
2421
2421
|
*/
|
|
2422
2422
|
resolveLiteral(filePath, name) {
|
|
2423
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2424
|
+
return this.resolveLiteralInternal(filePath, name, visited);
|
|
2425
|
+
}
|
|
2426
|
+
resolveLiteralInternal(filePath, name, visited) {
|
|
2427
|
+
if (visited.has(filePath))
|
|
2428
|
+
return void 0;
|
|
2429
|
+
visited.add(filePath);
|
|
2423
2430
|
const index = this.getIndex(filePath);
|
|
2424
2431
|
if (!index)
|
|
2425
2432
|
return void 0;
|
|
2426
2433
|
const literal2 = index.constLiterals.get(name);
|
|
2427
|
-
if (
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2434
|
+
if (literal2) {
|
|
2435
|
+
if (t3.isStringLiteral(literal2))
|
|
2436
|
+
return literal2.value;
|
|
2437
|
+
if (t3.isNumericLiteral(literal2))
|
|
2438
|
+
return literal2.value;
|
|
2439
|
+
if (t3.isBooleanLiteral(literal2))
|
|
2440
|
+
return literal2.value;
|
|
2441
|
+
if (t3.isNullLiteral(literal2))
|
|
2442
|
+
return null;
|
|
2443
|
+
}
|
|
2444
|
+
const imports = this.getImports(filePath);
|
|
2445
|
+
const importInfo = imports?.get(name);
|
|
2446
|
+
if (importInfo) {
|
|
2447
|
+
const resolved = this.resolveImportPath(filePath, importInfo.source);
|
|
2448
|
+
if (resolved) {
|
|
2449
|
+
const targetName = importInfo.importedName === "default" ? name : importInfo.importedName;
|
|
2450
|
+
const result = this.resolveLiteralInternal(resolved, targetName, visited);
|
|
2451
|
+
if (result !== void 0)
|
|
2452
|
+
return result;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
const reExport = index.namedReExports.get(name);
|
|
2456
|
+
if (reExport) {
|
|
2457
|
+
const resolved = this.resolveImportPath(filePath, reExport.source);
|
|
2458
|
+
if (resolved) {
|
|
2459
|
+
const result = this.resolveLiteralInternal(resolved, reExport.importedName, visited);
|
|
2460
|
+
if (result !== void 0)
|
|
2461
|
+
return result;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
for (const starSrc of index.exportsStar) {
|
|
2465
|
+
const resolved = this.resolveImportPath(filePath, starSrc);
|
|
2466
|
+
if (!resolved)
|
|
2467
|
+
continue;
|
|
2468
|
+
const result = this.resolveLiteralInternal(resolved, name, visited);
|
|
2469
|
+
if (result !== void 0)
|
|
2470
|
+
return result;
|
|
2471
|
+
}
|
|
2437
2472
|
return void 0;
|
|
2438
2473
|
}
|
|
2439
2474
|
/**
|
|
@@ -12756,6 +12791,58 @@ var ZodSchemaConverter = class {
|
|
|
12756
12791
|
this.symbolResolver.primeAST(this.currentFilePath, this.currentAST);
|
|
12757
12792
|
return this.symbolResolver.resolveLiteral(this.currentFilePath, name);
|
|
12758
12793
|
}
|
|
12794
|
+
/**
|
|
12795
|
+
* Unwrap a possible `TSAsExpression` / `TSSatisfiesExpression` to get the
|
|
12796
|
+
* underlying expression node. Returns the node itself when no wrapper is
|
|
12797
|
+
* present.
|
|
12798
|
+
*/
|
|
12799
|
+
unwrapTypeAssertion(node) {
|
|
12800
|
+
if (!node)
|
|
12801
|
+
return void 0;
|
|
12802
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
12803
|
+
return node.expression;
|
|
12804
|
+
}
|
|
12805
|
+
return node;
|
|
12806
|
+
}
|
|
12807
|
+
/**
|
|
12808
|
+
* Resolve a numeric value from a call-expression argument.
|
|
12809
|
+
* Handles: numeric literals, identifier references to const numbers,
|
|
12810
|
+
* and `x as number` / `x satisfies number` wrappers around either.
|
|
12811
|
+
*/
|
|
12812
|
+
resolveNumericArg(arg) {
|
|
12813
|
+
if (!arg)
|
|
12814
|
+
return void 0;
|
|
12815
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
12816
|
+
if (t10.isNumericLiteral(node))
|
|
12817
|
+
return node.value;
|
|
12818
|
+
if (t10.isUnaryExpression(node) && node.operator === "-" && t10.isNumericLiteral(node.argument)) {
|
|
12819
|
+
return -node.argument.value;
|
|
12820
|
+
}
|
|
12821
|
+
if (t10.isIdentifier(node)) {
|
|
12822
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12823
|
+
if (typeof val === "number")
|
|
12824
|
+
return val;
|
|
12825
|
+
}
|
|
12826
|
+
return void 0;
|
|
12827
|
+
}
|
|
12828
|
+
/**
|
|
12829
|
+
* Resolve a string value from a call-expression argument.
|
|
12830
|
+
* Handles: string literals, identifier references to const strings,
|
|
12831
|
+
* and `x as string` / `x satisfies string` wrappers around either.
|
|
12832
|
+
*/
|
|
12833
|
+
resolveStringArg(arg) {
|
|
12834
|
+
if (!arg)
|
|
12835
|
+
return void 0;
|
|
12836
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
12837
|
+
if (t10.isStringLiteral(node))
|
|
12838
|
+
return node.value;
|
|
12839
|
+
if (t10.isIdentifier(node)) {
|
|
12840
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12841
|
+
if (typeof val === "string")
|
|
12842
|
+
return val;
|
|
12843
|
+
}
|
|
12844
|
+
return void 0;
|
|
12845
|
+
}
|
|
12759
12846
|
/**
|
|
12760
12847
|
* Resolve an identifier referring to a `z.object({...})` (or similar) call expression.
|
|
12761
12848
|
* This lets callers inline the referenced object's shape.
|
|
@@ -12824,6 +12911,14 @@ var ZodSchemaConverter = class {
|
|
|
12824
12911
|
if (t10.isNullLiteral(node)) {
|
|
12825
12912
|
return null;
|
|
12826
12913
|
}
|
|
12914
|
+
if (t10.isIdentifier(node)) {
|
|
12915
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12916
|
+
if (val !== void 0)
|
|
12917
|
+
return val;
|
|
12918
|
+
}
|
|
12919
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
12920
|
+
return this.extractStaticJsonValue(node.expression);
|
|
12921
|
+
}
|
|
12827
12922
|
if (t10.isArrayExpression(node)) {
|
|
12828
12923
|
const values = [];
|
|
12829
12924
|
for (const element of node.elements) {
|
|
@@ -12922,53 +13017,60 @@ var ZodSchemaConverter = class {
|
|
|
12922
13017
|
schema.nullable = true;
|
|
12923
13018
|
}
|
|
12924
13019
|
break;
|
|
12925
|
-
case "describe":
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
if (
|
|
13020
|
+
case "describe": {
|
|
13021
|
+
const descVal = this.resolveStringArg(node.arguments[0]);
|
|
13022
|
+
if (descVal !== void 0) {
|
|
13023
|
+
if (descVal.startsWith("@deprecated")) {
|
|
12929
13024
|
schema.deprecated = true;
|
|
12930
|
-
schema.description =
|
|
13025
|
+
schema.description = descVal.replace("@deprecated", "").trim();
|
|
12931
13026
|
} else {
|
|
12932
|
-
schema.description =
|
|
13027
|
+
schema.description = descVal;
|
|
12933
13028
|
}
|
|
12934
13029
|
}
|
|
12935
13030
|
break;
|
|
13031
|
+
}
|
|
12936
13032
|
case "deprecated":
|
|
12937
13033
|
schema.deprecated = true;
|
|
12938
13034
|
break;
|
|
12939
|
-
case "min":
|
|
12940
|
-
|
|
13035
|
+
case "min": {
|
|
13036
|
+
const minVal = this.resolveNumericArg(node.arguments[0]);
|
|
13037
|
+
if (minVal !== void 0) {
|
|
12941
13038
|
if (schema.type === "string") {
|
|
12942
|
-
schema.minLength =
|
|
13039
|
+
schema.minLength = minVal;
|
|
12943
13040
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
12944
|
-
schema.minimum =
|
|
13041
|
+
schema.minimum = minVal;
|
|
12945
13042
|
} else if (schema.type === "array") {
|
|
12946
|
-
schema.minItems =
|
|
13043
|
+
schema.minItems = minVal;
|
|
12947
13044
|
}
|
|
12948
13045
|
}
|
|
12949
13046
|
break;
|
|
12950
|
-
|
|
12951
|
-
|
|
13047
|
+
}
|
|
13048
|
+
case "max": {
|
|
13049
|
+
const maxVal = this.resolveNumericArg(node.arguments[0]);
|
|
13050
|
+
if (maxVal !== void 0) {
|
|
12952
13051
|
if (schema.type === "string") {
|
|
12953
|
-
schema.maxLength =
|
|
13052
|
+
schema.maxLength = maxVal;
|
|
12954
13053
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
12955
|
-
schema.maximum =
|
|
13054
|
+
schema.maximum = maxVal;
|
|
12956
13055
|
} else if (schema.type === "array") {
|
|
12957
|
-
schema.maxItems =
|
|
13056
|
+
schema.maxItems = maxVal;
|
|
12958
13057
|
}
|
|
12959
13058
|
}
|
|
12960
13059
|
break;
|
|
12961
|
-
|
|
12962
|
-
|
|
13060
|
+
}
|
|
13061
|
+
case "length": {
|
|
13062
|
+
const lenVal = this.resolveNumericArg(node.arguments[0]);
|
|
13063
|
+
if (lenVal !== void 0) {
|
|
12963
13064
|
if (schema.type === "string") {
|
|
12964
|
-
schema.minLength =
|
|
12965
|
-
schema.maxLength =
|
|
13065
|
+
schema.minLength = lenVal;
|
|
13066
|
+
schema.maxLength = lenVal;
|
|
12966
13067
|
} else if (schema.type === "array") {
|
|
12967
|
-
schema.minItems =
|
|
12968
|
-
schema.maxItems =
|
|
13068
|
+
schema.minItems = lenVal;
|
|
13069
|
+
schema.maxItems = lenVal;
|
|
12969
13070
|
}
|
|
12970
13071
|
}
|
|
12971
13072
|
break;
|
|
13073
|
+
}
|
|
12972
13074
|
case "nonempty":
|
|
12973
13075
|
if (schema.type === "array") {
|
|
12974
13076
|
schema.minItems = Math.max(schema.minItems ?? 0, 1);
|
|
@@ -13044,21 +13146,27 @@ var ZodSchemaConverter = class {
|
|
|
13044
13146
|
schema.pattern = node.arguments[0].pattern;
|
|
13045
13147
|
}
|
|
13046
13148
|
break;
|
|
13047
|
-
case "startsWith":
|
|
13048
|
-
|
|
13049
|
-
|
|
13149
|
+
case "startsWith": {
|
|
13150
|
+
const swVal = this.resolveStringArg(node.arguments[0]);
|
|
13151
|
+
if (swVal !== void 0) {
|
|
13152
|
+
schema.pattern = `^${this.escapeRegExp(swVal)}`;
|
|
13050
13153
|
}
|
|
13051
13154
|
break;
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13155
|
+
}
|
|
13156
|
+
case "endsWith": {
|
|
13157
|
+
const ewVal = this.resolveStringArg(node.arguments[0]);
|
|
13158
|
+
if (ewVal !== void 0) {
|
|
13159
|
+
schema.pattern = `${this.escapeRegExp(ewVal)}$`;
|
|
13055
13160
|
}
|
|
13056
13161
|
break;
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13162
|
+
}
|
|
13163
|
+
case "includes": {
|
|
13164
|
+
const incVal = this.resolveStringArg(node.arguments[0]);
|
|
13165
|
+
if (incVal !== void 0) {
|
|
13166
|
+
schema.pattern = this.escapeRegExp(incVal);
|
|
13060
13167
|
}
|
|
13061
13168
|
break;
|
|
13169
|
+
}
|
|
13062
13170
|
case "int":
|
|
13063
13171
|
schema.type = "integer";
|
|
13064
13172
|
break;
|
|
@@ -13082,17 +13190,22 @@ var ZodSchemaConverter = class {
|
|
|
13082
13190
|
break;
|
|
13083
13191
|
case "default":
|
|
13084
13192
|
if (node.arguments.length > 0) {
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13193
|
+
const defaultArg = this.unwrapTypeAssertion(node.arguments[0]);
|
|
13194
|
+
if (t10.isStringLiteral(defaultArg)) {
|
|
13195
|
+
schema.default = defaultArg.value;
|
|
13196
|
+
} else if (t10.isNumericLiteral(defaultArg)) {
|
|
13197
|
+
schema.default = defaultArg.value;
|
|
13198
|
+
} else if (t10.isBooleanLiteral(defaultArg)) {
|
|
13199
|
+
schema.default = defaultArg.value;
|
|
13200
|
+
} else if (t10.isNullLiteral(defaultArg)) {
|
|
13092
13201
|
schema.default = null;
|
|
13093
|
-
} else if (t10.
|
|
13202
|
+
} else if (t10.isIdentifier(defaultArg)) {
|
|
13203
|
+
const val = this.resolveLiteralValue(defaultArg.name);
|
|
13204
|
+
if (val !== void 0)
|
|
13205
|
+
schema.default = val;
|
|
13206
|
+
} else if (t10.isObjectExpression(defaultArg)) {
|
|
13094
13207
|
const defaultObj = {};
|
|
13095
|
-
|
|
13208
|
+
defaultArg.properties.forEach((prop) => {
|
|
13096
13209
|
if (t10.isObjectProperty(prop) && (t10.isIdentifier(prop.key) || t10.isStringLiteral(prop.key)) && (t10.isStringLiteral(prop.value) || t10.isNumericLiteral(prop.value) || t10.isBooleanLiteral(prop.value))) {
|
|
13097
13210
|
const key = t10.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
13098
13211
|
const value = t10.isStringLiteral(prop.value) ? prop.value.value : t10.isNumericLiteral(prop.value) ? prop.value.value : t10.isBooleanLiteral(prop.value) ? prop.value.value : null;
|