@hey-api/openapi-ts 0.92.4 → 0.93.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.
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { StructureModel, detectInteractiveSession, fromRef, isNode, isRef, isSymbol, loadConfigFile, log, nodeBrand, ref, refs } from "@hey-api/codegen-core";
3
- import { ConfigError, OperationPath, OperationStrategy, applyNaming, createOperationKey, createSchemaProcessor, deduplicateSchema, definePluginConfig, dependencyFactory, ensureDirSync, escapeComment, findTsConfigPath, getInput, getLogs, getParser, hasOperationDataRequired, hasParameterGroupObjectRequired, loadTsConfig, mappers, operationPagination, operationResponsesMap, parseUrl, pathToJsonPointer, pathToName, refToName, resolveSource, satisfies, statusCodeToGroup, toCase, valueToObject } from "@hey-api/shared";
3
+ import { ConfigError, OperationPath, OperationStrategy, applyNaming, childContext, createOperationKey, createSchemaProcessor, createSchemaWalker, deduplicateSchema, definePluginConfig, dependencyFactory, ensureDirSync, escapeComment, findTsConfigPath, getInput, getLogs, getParser, hasOperationDataRequired, hasParameterGroupObjectRequired, loadTsConfig, mappers, operationPagination, operationResponsesMap, parseUrl, pathToJsonPointer, pathToName, refToName, resolveSource, satisfies, statusCodeToGroup, toCase, valueToObject } from "@hey-api/shared";
4
4
  import colors from "ansi-colors";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -2627,18 +2627,18 @@ f.await.set((...args) => new AwaitTsDsl(...args));
2627
2627
  const Mixed$27 = ArgsMixin(AsMixin(ExprMixin(TypeArgsMixin(TsDsl))));
2628
2628
  var CallTsDsl = class extends Mixed$27 {
2629
2629
  "~dsl" = "CallTsDsl";
2630
- _callExpr;
2631
- constructor(expr, ...args) {
2630
+ _callee;
2631
+ constructor(callee, ...args) {
2632
2632
  super();
2633
- this._callExpr = ref(expr);
2633
+ this._callee = ref(callee);
2634
2634
  this.args(...args);
2635
2635
  }
2636
2636
  analyze(ctx$1) {
2637
2637
  super.analyze(ctx$1);
2638
- ctx$1.analyze(this._callExpr);
2638
+ ctx$1.analyze(this._callee);
2639
2639
  }
2640
2640
  toAst() {
2641
- return ts.factory.createCallExpression(this.$node(this._callExpr), this.$generics(), this.$args());
2641
+ return ts.factory.createCallExpression(this.$node(this._callee), this.$generics(), this.$args());
2642
2642
  }
2643
2643
  };
2644
2644
  f.call.set((...args) => new CallTsDsl(...args));
@@ -4827,7 +4827,7 @@ function implementFn(args) {
4827
4827
  role: "response"
4828
4828
  }), (t$1, s) => t$1.extends(s).default(s), (t$1) => t$1.default("undefined"))), (m) => m.generic("ThrowOnError", (t) => t.extends("boolean").default(("throwOnError" in client.config ? client.config.throwOnError : false) ?? false))).params(...opParameters.parameters).do(...statements);
4829
4829
  }
4830
- function toNode(model, plugin) {
4830
+ function toNode$1(model, plugin) {
4831
4831
  if (model.virtual) {
4832
4832
  const nodes$1 = [];
4833
4833
  for (const item of model.itemsFrom(source$1)) {
@@ -5337,6 +5337,16 @@ function getClientBundlePaths(pluginName) {
5337
5337
  };
5338
5338
  }
5339
5339
  /**
5340
+ * Converts an {@link OutputHeader} value to a string prefix for file content.
5341
+ * Returns an empty string when the header is null, undefined, or a function
5342
+ * (functions require a render context which is not available for bundled files).
5343
+ */
5344
+ function outputHeaderToPrefix(header) {
5345
+ if (header == null || typeof header === "function") return "";
5346
+ const content = (typeof header === "string" ? header.split(/\r?\n/) : header.flatMap((line) => line.split(/\r?\n/))).join("\n");
5347
+ return content ? `${content}\n\n` : "";
5348
+ }
5349
+ /**
5340
5350
  * Returns absolute path to the client folder. This is hard-coded for now.
5341
5351
  */
5342
5352
  function clientFolderAbsolutePath(config) {
@@ -5372,7 +5382,7 @@ function renameFile({ filePath, project, renamed }) {
5372
5382
  renamed.set(name, renamedName);
5373
5383
  }
5374
5384
  }
5375
- function replaceImports({ filePath, isDevMode: isDevMode$1, meta, renamed }) {
5385
+ function replaceImports({ filePath, header, isDevMode: isDevMode$1, meta, renamed }) {
5376
5386
  let content = fs.readFileSync(filePath, "utf8");
5377
5387
  if (isDevMode$1) {
5378
5388
  content = content.replace(/from\s+['"]\.\.\/\.\.\/client-core\/bundle\//g, "from '../core/");
@@ -5386,17 +5396,16 @@ function replaceImports({ filePath, isDevMode: isDevMode$1, meta, renamed }) {
5386
5396
  const replacedName = (renamed.get(fileName) ?? fileName) + (meta.importFileExtension ? meta.importFileExtension : extension);
5387
5397
  return match.slice(0, importIndex) + [importDir, replacedName].filter(Boolean).join("/") + match.slice(importIndex + importPath.length);
5388
5398
  });
5389
- content = `// This file is auto-generated by @hey-api/openapi-ts
5390
-
5391
- ${content}`;
5399
+ content = `${header ?? ""}${content}`;
5392
5400
  fs.writeFileSync(filePath, content, "utf8");
5393
5401
  }
5394
5402
  /**
5395
5403
  * Creates a `client` folder containing the same modules as the client package.
5396
5404
  */
5397
- function generateClientBundle({ meta, outputPath, plugin, project }) {
5405
+ function generateClientBundle({ header, meta, outputPath, plugin, project }) {
5398
5406
  const renamed = /* @__PURE__ */ new Map();
5399
5407
  const devMode = isDevMode();
5408
+ const headerPrefix = outputHeaderToPrefix(header);
5400
5409
  if (plugin.name.startsWith("@hey-api/client-")) {
5401
5410
  const { clientPath, corePath } = getClientBundlePaths(plugin.name);
5402
5411
  const coreOutputPath = path.resolve(outputPath, "core");
@@ -5422,6 +5431,7 @@ function generateClientBundle({ meta, outputPath, plugin, project }) {
5422
5431
  const coreFiles = fs.readdirSync(coreOutputPath);
5423
5432
  for (const file of coreFiles) replaceImports({
5424
5433
  filePath: path.resolve(coreOutputPath, file),
5434
+ header: headerPrefix,
5425
5435
  isDevMode: devMode,
5426
5436
  meta,
5427
5437
  renamed
@@ -5429,6 +5439,7 @@ function generateClientBundle({ meta, outputPath, plugin, project }) {
5429
5439
  const clientFiles = fs.readdirSync(clientOutputPath);
5430
5440
  for (const file of clientFiles) replaceImports({
5431
5441
  filePath: path.resolve(clientOutputPath, file),
5442
+ header: headerPrefix,
5432
5443
  isDevMode: devMode,
5433
5444
  meta,
5434
5445
  renamed
@@ -6185,7 +6196,7 @@ const handlerV1$2 = ({ plugin }) => {
6185
6196
  const allDependencies = [];
6186
6197
  const allNodes = [];
6187
6198
  for (const node of structure.walk()) {
6188
- const { dependencies, nodes } = toNode(node, plugin);
6199
+ const { dependencies, nodes } = toNode$1(node, plugin);
6189
6200
  allDependencies.push(...dependencies ?? []);
6190
6201
  allNodes.push(...nodes);
6191
6202
  }
@@ -6646,7 +6657,7 @@ const operationToDataType$1 = ({ operation, plugin, state }) => {
6646
6657
  tags: fromRef(state.tags),
6647
6658
  tool: "typescript"
6648
6659
  } });
6649
- const node = $.type.alias(symbol).export().type(irSchemaToAst$5({
6660
+ const node = $.type.alias(symbol).export().type(irSchemaToAst$1({
6650
6661
  plugin,
6651
6662
  schema: data,
6652
6663
  state
@@ -6670,7 +6681,7 @@ const operationToType = ({ operation, plugin, state }) => {
6670
6681
  tags: fromRef(state.tags),
6671
6682
  tool: "typescript"
6672
6683
  } });
6673
- const node = $.type.alias(symbolErrors).export().type(irSchemaToAst$5({
6684
+ const node = $.type.alias(symbolErrors).export().type(irSchemaToAst$1({
6674
6685
  plugin,
6675
6686
  schema: errors,
6676
6687
  state
@@ -6703,7 +6714,7 @@ const operationToType = ({ operation, plugin, state }) => {
6703
6714
  tags: fromRef(state.tags),
6704
6715
  tool: "typescript"
6705
6716
  } });
6706
- const node = $.type.alias(symbolResponses).export().type(irSchemaToAst$5({
6717
+ const node = $.type.alias(symbolResponses).export().type(irSchemaToAst$1({
6707
6718
  plugin,
6708
6719
  schema: responses,
6709
6720
  state
@@ -6747,7 +6758,7 @@ const operationToDataType = ({ operation, plugin, state }) => {
6747
6758
  tags: fromRef(state.tags),
6748
6759
  tool: "typescript"
6749
6760
  } });
6750
- const node$1 = $.type.alias(symbolWebhookPayload).export().$if(plugin.config.comments && createSchemaComment(operation.body.schema), (t, v) => t.doc(v)).type(irSchemaToAst$5({
6761
+ const node$1 = $.type.alias(symbolWebhookPayload).export().$if(plugin.config.comments && createSchemaComment(operation.body.schema), (t, v) => t.doc(v)).type(irSchemaToAst$1({
6751
6762
  plugin,
6752
6763
  schema: operation.body.schema,
6753
6764
  state
@@ -6773,7 +6784,7 @@ const operationToDataType = ({ operation, plugin, state }) => {
6773
6784
  tags: fromRef(state.tags),
6774
6785
  tool: "typescript"
6775
6786
  } });
6776
- const node = $.type.alias(symbolWebhookRequest).export().type(irSchemaToAst$5({
6787
+ const node = $.type.alias(symbolWebhookRequest).export().type(irSchemaToAst$1({
6777
6788
  plugin,
6778
6789
  schema: data,
6779
6790
  state
@@ -6791,7 +6802,7 @@ const webhookToType = ({ operation, plugin, state }) => {
6791
6802
 
6792
6803
  //#endregion
6793
6804
  //#region src/plugins/@hey-api/typescript/v1/toAst/array.ts
6794
- const arrayToAst$4 = ({ plugin, schema, state }) => {
6805
+ function arrayToAst$3({ plugin, schema, state }) {
6795
6806
  if (!schema.items) return $.type("Array").generic($.type(plugin.config.topType));
6796
6807
  schema = deduplicateSchema({
6797
6808
  detectFormat: true,
@@ -6799,7 +6810,7 @@ const arrayToAst$4 = ({ plugin, schema, state }) => {
6799
6810
  });
6800
6811
  const itemTypes = [];
6801
6812
  if (schema.items) schema.items.forEach((item, index) => {
6802
- const type = irSchemaToAst$5({
6813
+ const type = irSchemaToAst$1({
6803
6814
  plugin,
6804
6815
  schema: item,
6805
6816
  state: {
@@ -6815,19 +6826,19 @@ const arrayToAst$4 = ({ plugin, schema, state }) => {
6815
6826
  });
6816
6827
  if (itemTypes.length === 1) return $.type("Array").generic(itemTypes[0]);
6817
6828
  return schema.logicalOperator === "and" ? $.type("Array").generic($.type.and(...itemTypes)) : $.type("Array").generic($.type.or(...itemTypes));
6818
- };
6829
+ }
6819
6830
 
6820
6831
  //#endregion
6821
6832
  //#region src/plugins/@hey-api/typescript/v1/toAst/boolean.ts
6822
- function booleanToAst$4({ schema }) {
6833
+ function booleanToAst$3({ schema }) {
6823
6834
  if (schema.const !== void 0) return $.type.literal(schema.const);
6824
6835
  return $.type("boolean");
6825
6836
  }
6826
6837
 
6827
6838
  //#endregion
6828
6839
  //#region src/plugins/@hey-api/typescript/v1/toAst/enum.ts
6829
- const enumToAst$4 = ({ plugin, schema, state }) => {
6830
- return irSchemaToAst$5({
6840
+ function enumToAst$3({ plugin, schema, state }) {
6841
+ return irSchemaToAst$1({
6831
6842
  plugin,
6832
6843
  schema: {
6833
6844
  ...schema,
@@ -6835,17 +6846,17 @@ const enumToAst$4 = ({ plugin, schema, state }) => {
6835
6846
  },
6836
6847
  state
6837
6848
  });
6838
- };
6849
+ }
6839
6850
 
6840
6851
  //#endregion
6841
6852
  //#region src/plugins/@hey-api/typescript/v1/toAst/never.ts
6842
- const neverToAst$4 = (_args) => {
6853
+ const neverToAst$3 = (_args) => {
6843
6854
  return $.type("never");
6844
6855
  };
6845
6856
 
6846
6857
  //#endregion
6847
6858
  //#region src/plugins/@hey-api/typescript/v1/toAst/null.ts
6848
- const nullToAst$5 = (_args) => {
6859
+ const nullToAst$4 = (_args) => {
6849
6860
  return $.type.literal(null);
6850
6861
  };
6851
6862
 
@@ -6861,14 +6872,14 @@ const numberToAst = ({ plugin, schema }) => {
6861
6872
 
6862
6873
  //#endregion
6863
6874
  //#region src/plugins/@hey-api/typescript/v1/toAst/object.ts
6864
- const objectToAst$5 = ({ plugin, schema, state }) => {
6875
+ function objectToAst$4({ plugin, schema, state }) {
6865
6876
  const shape = $.type.object();
6866
6877
  const required = schema.required ?? [];
6867
6878
  let indexSchemas = [];
6868
6879
  let hasOptionalProperties = false;
6869
6880
  for (const name in schema.properties) {
6870
6881
  const property = schema.properties[name];
6871
- const propertyType = irSchemaToAst$5({
6882
+ const propertyType = irSchemaToAst$1({
6872
6883
  plugin,
6873
6884
  schema: property,
6874
6885
  state: {
@@ -6897,11 +6908,11 @@ const objectToAst$5 = ({ plugin, schema, state }) => {
6897
6908
  if (addProps && addProps.type !== "never") indexSchemas.unshift(addProps);
6898
6909
  else if (!hasPatterns && !indexSchemas.length && addProps && addProps.type === "never") indexSchemas = [addProps];
6899
6910
  if (hasOptionalProperties) indexSchemas.push({ type: "undefined" });
6900
- const type = indexSchemas.length === 1 ? irSchemaToAst$5({
6911
+ const type = indexSchemas.length === 1 ? irSchemaToAst$1({
6901
6912
  plugin,
6902
6913
  schema: indexSchemas[0],
6903
6914
  state
6904
- }) : irSchemaToAst$5({
6915
+ }) : irSchemaToAst$1({
6905
6916
  plugin,
6906
6917
  schema: {
6907
6918
  items: indexSchemas,
@@ -6909,7 +6920,7 @@ const objectToAst$5 = ({ plugin, schema, state }) => {
6909
6920
  },
6910
6921
  state
6911
6922
  });
6912
- if (schema.propertyNames?.$ref) return $.type.mapped("key").key(irSchemaToAst$5({
6923
+ if (schema.propertyNames?.$ref) return $.type.mapped("key").key(irSchemaToAst$1({
6913
6924
  plugin,
6914
6925
  schema: { $ref: schema.propertyNames.$ref },
6915
6926
  state
@@ -6917,7 +6928,7 @@ const objectToAst$5 = ({ plugin, schema, state }) => {
6917
6928
  shape.idxSig("key", (i) => i.key("string").type(type));
6918
6929
  }
6919
6930
  return shape;
6920
- };
6931
+ }
6921
6932
 
6922
6933
  //#endregion
6923
6934
  //#region src/plugins/@hey-api/typescript/v1/toAst/string.ts
@@ -6964,11 +6975,11 @@ const stringToAst$1 = ({ plugin, schema }) => {
6964
6975
 
6965
6976
  //#endregion
6966
6977
  //#region src/plugins/@hey-api/typescript/v1/toAst/tuple.ts
6967
- const tupleToAst$4 = ({ plugin, schema, state }) => {
6978
+ function tupleToAst$3({ plugin, schema, state }) {
6968
6979
  let itemTypes = [];
6969
6980
  if (schema.const && Array.isArray(schema.const)) itemTypes = schema.const.map((value) => $.type.fromValue(value));
6970
6981
  else if (schema.items) schema.items.forEach((item, index) => {
6971
- const type = irSchemaToAst$5({
6982
+ const type = irSchemaToAst$1({
6972
6983
  plugin,
6973
6984
  schema: item,
6974
6985
  state: {
@@ -6983,44 +6994,44 @@ const tupleToAst$4 = ({ plugin, schema, state }) => {
6983
6994
  itemTypes.push(type);
6984
6995
  });
6985
6996
  return $.type.tuple(...itemTypes);
6986
- };
6997
+ }
6987
6998
 
6988
6999
  //#endregion
6989
7000
  //#region src/plugins/@hey-api/typescript/v1/toAst/undefined.ts
6990
- const undefinedToAst$4 = (_args) => {
7001
+ const undefinedToAst$3 = (_args) => {
6991
7002
  return $.type("undefined");
6992
7003
  };
6993
7004
 
6994
7005
  //#endregion
6995
7006
  //#region src/plugins/@hey-api/typescript/v1/toAst/unknown.ts
6996
- const unknownToAst$4 = ({ plugin }) => {
7007
+ function unknownToAst$3({ plugin }) {
6997
7008
  return $.type(plugin.config.topType);
6998
- };
7009
+ }
6999
7010
 
7000
7011
  //#endregion
7001
7012
  //#region src/plugins/@hey-api/typescript/v1/toAst/void.ts
7002
- const voidToAst$4 = (_args) => {
7013
+ const voidToAst$3 = (_args) => {
7003
7014
  return $.type("void");
7004
7015
  };
7005
7016
 
7006
7017
  //#endregion
7007
7018
  //#region src/plugins/@hey-api/typescript/v1/toAst/index.ts
7008
- function irSchemaWithTypeToAst$5({ schema, ...args }) {
7019
+ function irSchemaWithTypeToAst$1({ schema, ...args }) {
7009
7020
  const transformersPlugin = args.plugin.getPlugin("@hey-api/transformers");
7010
7021
  if (transformersPlugin?.config.typeTransformers) for (const typeTransformer of transformersPlugin.config.typeTransformers) {
7011
7022
  const typeNode = typeTransformer({ schema });
7012
7023
  if (typeNode) return typeNode;
7013
7024
  }
7014
7025
  switch (schema.type) {
7015
- case "array": return arrayToAst$4({
7026
+ case "array": return arrayToAst$3({
7016
7027
  ...args,
7017
7028
  schema
7018
7029
  });
7019
- case "boolean": return booleanToAst$4({
7030
+ case "boolean": return booleanToAst$3({
7020
7031
  ...args,
7021
7032
  schema
7022
7033
  });
7023
- case "enum": return enumToAst$4({
7034
+ case "enum": return enumToAst$3({
7024
7035
  ...args,
7025
7036
  schema
7026
7037
  });
@@ -7029,15 +7040,15 @@ function irSchemaWithTypeToAst$5({ schema, ...args }) {
7029
7040
  ...args,
7030
7041
  schema
7031
7042
  });
7032
- case "never": return neverToAst$4({
7043
+ case "never": return neverToAst$3({
7033
7044
  ...args,
7034
7045
  schema
7035
7046
  });
7036
- case "null": return nullToAst$5({
7047
+ case "null": return nullToAst$4({
7037
7048
  ...args,
7038
7049
  schema
7039
7050
  });
7040
- case "object": return objectToAst$5({
7051
+ case "object": return objectToAst$4({
7041
7052
  ...args,
7042
7053
  schema
7043
7054
  });
@@ -7045,19 +7056,19 @@ function irSchemaWithTypeToAst$5({ schema, ...args }) {
7045
7056
  ...args,
7046
7057
  schema
7047
7058
  });
7048
- case "tuple": return tupleToAst$4({
7059
+ case "tuple": return tupleToAst$3({
7049
7060
  ...args,
7050
7061
  schema
7051
7062
  });
7052
- case "undefined": return undefinedToAst$4({
7063
+ case "undefined": return undefinedToAst$3({
7053
7064
  ...args,
7054
7065
  schema
7055
7066
  });
7056
- case "unknown": return unknownToAst$4({
7067
+ case "unknown": return unknownToAst$3({
7057
7068
  ...args,
7058
7069
  schema
7059
7070
  });
7060
- case "void": return voidToAst$4({
7071
+ case "void": return voidToAst$3({
7061
7072
  ...args,
7062
7073
  schema
7063
7074
  });
@@ -7066,7 +7077,7 @@ function irSchemaWithTypeToAst$5({ schema, ...args }) {
7066
7077
 
7067
7078
  //#endregion
7068
7079
  //#region src/plugins/@hey-api/typescript/v1/plugin.ts
7069
- function irSchemaToAst$5({ plugin, schema, schemaExtractor, state }) {
7080
+ function irSchemaToAst$1({ plugin, schema, schemaExtractor, state }) {
7070
7081
  if (schemaExtractor && !schema.$ref) {
7071
7082
  const extracted = schemaExtractor({
7072
7083
  meta: {
@@ -7099,7 +7110,7 @@ function irSchemaToAst$5({ plugin, schema, schemaExtractor, state }) {
7099
7110
  }
7100
7111
  return baseType;
7101
7112
  }
7102
- if (schema.type) return irSchemaWithTypeToAst$5({
7113
+ if (schema.type) return irSchemaWithTypeToAst$1({
7103
7114
  plugin,
7104
7115
  schema,
7105
7116
  state
@@ -7110,20 +7121,20 @@ function irSchemaToAst$5({ plugin, schema, schemaExtractor, state }) {
7110
7121
  schema
7111
7122
  });
7112
7123
  if (schema.items) {
7113
- const itemTypes = schema.items.map((item) => irSchemaToAst$5({
7124
+ const itemTypes = schema.items.map((item) => irSchemaToAst$1({
7114
7125
  plugin,
7115
7126
  schema: item,
7116
7127
  state
7117
7128
  }));
7118
7129
  return schema.logicalOperator === "and" ? $.type.and(...itemTypes) : $.type.or(...itemTypes);
7119
7130
  }
7120
- return irSchemaToAst$5({
7131
+ return irSchemaToAst$1({
7121
7132
  plugin,
7122
7133
  schema,
7123
7134
  state
7124
7135
  });
7125
7136
  }
7126
- return irSchemaWithTypeToAst$5({
7137
+ return irSchemaWithTypeToAst$1({
7127
7138
  plugin,
7128
7139
  schema: { type: "unknown" },
7129
7140
  state
@@ -7134,7 +7145,7 @@ function handleComponent$1({ plugin, schema, state }) {
7134
7145
  plugin,
7135
7146
  schema,
7136
7147
  state,
7137
- type: irSchemaToAst$5({
7148
+ type: irSchemaToAst$1({
7138
7149
  plugin,
7139
7150
  schema,
7140
7151
  state
@@ -7213,7 +7224,7 @@ const handlerV1$1 = ({ plugin }) => {
7213
7224
  //#region src/plugins/@hey-api/typescript/api.ts
7214
7225
  var Api$3 = class {
7215
7226
  schemaToType(args) {
7216
- return irSchemaToAst$5(args);
7227
+ return irSchemaToAst$1(args);
7217
7228
  }
7218
7229
  };
7219
7230
 
@@ -8556,7 +8567,7 @@ function exportAst$2({ ast, plugin, schema, symbol, typeInferSymbol }) {
8556
8567
 
8557
8568
  //#endregion
8558
8569
  //#region src/plugins/arktype/v2/toAst/null.ts
8559
- const nullToAst$4 = (_args) => {
8570
+ const nullToAst$3 = (_args) => {
8560
8571
  const result = {};
8561
8572
  result.def = identifiers$2.primitives.null;
8562
8573
  return result;
@@ -8564,14 +8575,14 @@ const nullToAst$4 = (_args) => {
8564
8575
 
8565
8576
  //#endregion
8566
8577
  //#region src/plugins/arktype/v2/toAst/object.ts
8567
- const objectToAst$4 = ({ plugin, schema, state }) => {
8578
+ function objectToAst$3({ plugin, schema, state }) {
8568
8579
  const result = {};
8569
8580
  const shape = $.object().pretty();
8570
8581
  const required = schema.required ?? [];
8571
8582
  for (const name in schema.properties) {
8572
8583
  const property = schema.properties[name];
8573
8584
  const isRequired = required.includes(name);
8574
- const propertyAst = irSchemaToAst$4({
8585
+ const propertyAst = irSchemaToAst({
8575
8586
  optional: !isRequired,
8576
8587
  plugin,
8577
8588
  schema: property,
@@ -8588,7 +8599,7 @@ const objectToAst$4 = ({ plugin, schema, state }) => {
8588
8599
  shape.prop(isRequired ? name : `${name}?`, propertyAst.expression);
8589
8600
  }
8590
8601
  if (schema.additionalProperties && (!schema.properties || !Object.keys(schema.properties).length)) {
8591
- const additionalAst = irSchemaToAst$4({
8602
+ const additionalAst = irSchemaToAst({
8592
8603
  plugin,
8593
8604
  schema: schema.additionalProperties,
8594
8605
  state: {
@@ -8606,7 +8617,7 @@ const objectToAst$4 = ({ plugin, schema, state }) => {
8606
8617
  typeName: "TODO"
8607
8618
  };
8608
8619
  return result;
8609
- };
8620
+ }
8610
8621
 
8611
8622
  //#endregion
8612
8623
  //#region src/plugins/arktype/v2/toAst/string.ts
@@ -8651,13 +8662,13 @@ const stringToAst = ({ schema }) => {
8651
8662
 
8652
8663
  //#endregion
8653
8664
  //#region src/plugins/arktype/v2/toAst/index.ts
8654
- function irSchemaWithTypeToAst$4({ schema, ...args }) {
8665
+ function irSchemaWithTypeToAst({ schema, ...args }) {
8655
8666
  switch (schema.type) {
8656
- case "null": return nullToAst$4({
8667
+ case "null": return nullToAst$3({
8657
8668
  ...args,
8658
8669
  schema
8659
8670
  });
8660
- case "object": return objectToAst$4({
8671
+ case "object": return objectToAst$3({
8661
8672
  ...args,
8662
8673
  schema
8663
8674
  });
@@ -8675,7 +8686,7 @@ function irSchemaWithTypeToAst$4({ schema, ...args }) {
8675
8686
 
8676
8687
  //#endregion
8677
8688
  //#region src/plugins/arktype/v2/plugin.ts
8678
- function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8689
+ function irSchemaToAst({ plugin, schema, schemaExtractor, state }) {
8679
8690
  if (schemaExtractor && !schema.$ref) {
8680
8691
  const extracted = schemaExtractor({
8681
8692
  meta: {
@@ -8706,7 +8717,7 @@ function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8706
8717
  state.hasLazyExpression["~ref"] = true;
8707
8718
  }
8708
8719
  } else if (schema.type) {
8709
- const typeAst = irSchemaWithTypeToAst$4({
8720
+ const typeAst = irSchemaWithTypeToAst({
8710
8721
  plugin,
8711
8722
  schema,
8712
8723
  state
@@ -8717,13 +8728,13 @@ function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8717
8728
  if (plugin.config.metadata && schema.description) {}
8718
8729
  } else if (schema.items) {
8719
8730
  schema = deduplicateSchema({ schema });
8720
- if (schema.items) {} else ast = irSchemaToAst$4({
8731
+ if (schema.items) {} else ast = irSchemaToAst({
8721
8732
  plugin,
8722
8733
  schema,
8723
8734
  state
8724
8735
  });
8725
8736
  } else {
8726
- const typeAst = irSchemaWithTypeToAst$4({
8737
+ const typeAst = irSchemaWithTypeToAst({
8727
8738
  plugin,
8728
8739
  schema: { type: "unknown" },
8729
8740
  state
@@ -8732,7 +8743,7 @@ function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8732
8743
  ast.expression = typeAst.expression;
8733
8744
  }
8734
8745
  if (!ast.expression) {
8735
- const typeAst = irSchemaWithTypeToAst$4({
8746
+ const typeAst = irSchemaWithTypeToAst({
8736
8747
  plugin,
8737
8748
  schema: { type: "unknown" },
8738
8749
  state
@@ -8743,7 +8754,7 @@ function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8743
8754
  }
8744
8755
  function handleComponent({ plugin, schema, state }) {
8745
8756
  const $ref = pathToJsonPointer(fromRef(state.path));
8746
- const ast = irSchemaToAst$4({
8757
+ const ast = irSchemaToAst({
8747
8758
  plugin,
8748
8759
  schema,
8749
8760
  state
@@ -9476,23 +9487,33 @@ const identifiers$1 = {
9476
9487
 
9477
9488
  //#endregion
9478
9489
  //#region src/plugins/valibot/shared/pipes.ts
9479
- const pipesToNode = (pipes$1, plugin) => {
9490
+ function push(target, result) {
9491
+ if (result === void 0) return target;
9492
+ if (result instanceof Array) target.push(...result);
9493
+ else target.push(result);
9494
+ return target;
9495
+ }
9496
+ function toNode(pipes$1, plugin) {
9480
9497
  if (!(pipes$1 instanceof Array)) return pipes$1;
9498
+ if (pipes$1.length === 0) return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.unknown).call();
9481
9499
  if (pipes$1.length === 1) return pipes$1[0];
9482
9500
  return $(plugin.external("valibot.v")).attr(identifiers$1.methods.pipe).call(...pipes$1);
9483
- };
9484
- const pushPipes = (target, pipes$1) => {
9485
- if (pipes$1 instanceof Array) target.push(...pipes$1);
9486
- else target.push(pipes$1);
9487
- return target;
9488
- };
9501
+ }
9489
9502
  /**
9490
9503
  * Functions for working with pipes.
9491
9504
  */
9492
9505
  const pipes = {
9493
- push: pushPipes,
9494
- toNode: pipesToNode
9506
+ push,
9507
+ toNode
9495
9508
  };
9509
+ /**
9510
+ * Convenience function for converting pipes to a node.
9511
+ *
9512
+ * Re-exported for backward compatibility.
9513
+ */
9514
+ function pipesToNode(p, plugin) {
9515
+ return toNode(p, plugin);
9516
+ }
9496
9517
 
9497
9518
  //#endregion
9498
9519
  //#region src/plugins/valibot/v1/api.ts
@@ -9572,19 +9593,6 @@ var Api$1 = class {
9572
9593
  }
9573
9594
  };
9574
9595
 
9575
- //#endregion
9576
- //#region src/plugins/shared/utils/coerce.ts
9577
- const shouldCoerceToBigInt = (format) => format === "int64" || format === "uint64";
9578
- const maybeBigInt = (value, format) => {
9579
- if (!shouldCoerceToBigInt(format)) return $.fromValue(value);
9580
- if (typeof value === "string") {
9581
- if (value.endsWith("n")) value = value.slice(0, -1);
9582
- return $("BigInt").call($.fromValue(value));
9583
- }
9584
- if (typeof value === "number") return $("BigInt").call($.fromValue(value));
9585
- return $.fromValue(value);
9586
- };
9587
-
9588
9596
  //#endregion
9589
9597
  //#region src/plugins/valibot/shared/operation-schema.ts
9590
9598
  function buildOperationSchema$1(operation) {
@@ -9694,7 +9702,7 @@ function irWebhookToAst$1({ operation, path: path$1, plugin, processor, tags })
9694
9702
 
9695
9703
  //#endregion
9696
9704
  //#region src/plugins/valibot/shared/export.ts
9697
- function exportAst$1({ ast, meta, naming, namingAnchor, path: path$1, plugin, schema, state, tags }) {
9705
+ function exportAst$1({ final, meta, naming, namingAnchor, path: path$1, plugin, schema, tags }) {
9698
9706
  const v = plugin.external("valibot.v");
9699
9707
  const name = pathToName(path$1, { anchor: namingAnchor });
9700
9708
  const symbol = plugin.symbol(applyNaming(name, naming), { meta: {
@@ -9704,132 +9712,114 @@ function exportAst$1({ ast, meta, naming, namingAnchor, path: path$1, plugin, sc
9704
9712
  tool: "valibot",
9705
9713
  ...meta
9706
9714
  } });
9707
- const statement = $.const(symbol).export().$if(plugin.config.comments && createSchemaComment(schema), (c, v$1) => c.doc(v$1)).$if(state.hasLazyExpression["~ref"], (c) => c.type($.type(v).attr(ast.typeName || identifiers$1.types.GenericSchema))).assign(pipesToNode(ast.pipes, plugin));
9715
+ const statement = $.const(symbol).export().$if(plugin.config.comments && createSchemaComment(schema), (c, v$1) => c.doc(v$1)).$if(final.typeName, (c) => c.type($.type(v).attr(final.typeName))).assign(pipesToNode(final.pipes, plugin));
9708
9716
  plugin.node(statement);
9709
9717
  }
9710
9718
 
9711
9719
  //#endregion
9712
- //#region src/plugins/valibot/v1/processor.ts
9713
- function createProcessor$3(plugin) {
9714
- const processor = createSchemaProcessor();
9715
- const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
9716
- function extractor(ctx$1) {
9717
- if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
9718
- for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
9719
- process$1({
9720
- namingAnchor: processor.context.anchor,
9721
- tags: processor.context.tags,
9722
- ...ctx$1
9723
- });
9724
- return { $ref: pathToJsonPointer(ctx$1.path) };
9725
- }
9726
- return ctx$1.schema;
9727
- }
9728
- function process$1(ctx$1) {
9729
- if (!processor.markEmitted(ctx$1.path)) return;
9730
- processor.withContext({
9731
- anchor: ctx$1.namingAnchor,
9732
- tags: ctx$1.tags
9733
- }, () => {
9734
- const state = refs({
9735
- hasLazyExpression: false,
9736
- path: ctx$1.path,
9737
- tags: ctx$1.tags
9738
- });
9739
- const ast = irSchemaToAst$3({
9740
- plugin,
9741
- schema: ctx$1.schema,
9742
- schemaExtractor: extractor,
9743
- state
9744
- });
9745
- exportAst$1({
9746
- ...ctx$1,
9747
- ast,
9748
- plugin,
9749
- state
9750
- });
9751
- });
9720
+ //#region src/plugins/shared/utils/coerce.ts
9721
+ const shouldCoerceToBigInt = (format) => format === "int64" || format === "uint64";
9722
+ const maybeBigInt = (value, format) => {
9723
+ if (!shouldCoerceToBigInt(format)) return $.fromValue(value);
9724
+ if (typeof value === "string") {
9725
+ if (value.endsWith("n")) value = value.slice(0, -1);
9726
+ return $("BigInt").call($.fromValue(value));
9752
9727
  }
9753
- return { process: process$1 };
9728
+ if (typeof value === "number") return $("BigInt").call($.fromValue(value));
9729
+ return $.fromValue(value);
9730
+ };
9731
+
9732
+ //#endregion
9733
+ //#region src/plugins/valibot/shared/meta.ts
9734
+ /**
9735
+ * Creates default metadata from a schema.
9736
+ */
9737
+ function defaultMeta(schema) {
9738
+ return {
9739
+ default: schema.default,
9740
+ format: schema.format,
9741
+ hasLazy: false,
9742
+ nullable: false,
9743
+ readonly: schema.accessScope === "read"
9744
+ };
9745
+ }
9746
+ /**
9747
+ * Composes metadata from child results.
9748
+ *
9749
+ * Automatically propagates hasLazy, nullable, readonly from children.
9750
+ *
9751
+ * @param children - Results from walking child schemas
9752
+ * @param overrides - Explicit overrides (e.g., from parent schema)
9753
+ */
9754
+ function composeMeta(children, overrides) {
9755
+ return {
9756
+ default: overrides?.default,
9757
+ format: overrides?.format,
9758
+ hasLazy: overrides?.hasLazy ?? children.some((c) => c.meta.hasLazy),
9759
+ nullable: overrides?.nullable ?? children.some((c) => c.meta.nullable),
9760
+ readonly: overrides?.readonly ?? children.some((c) => c.meta.readonly)
9761
+ };
9762
+ }
9763
+ /**
9764
+ * Merges parent schema metadata with composed child metadata.
9765
+ *
9766
+ * @param parent - The parent schema
9767
+ * @param children - Results from walking child schemas
9768
+ */
9769
+ function inheritMeta(parent, children) {
9770
+ return composeMeta(children, {
9771
+ default: parent.default,
9772
+ format: parent.format,
9773
+ nullable: false,
9774
+ readonly: parent.accessScope === "read"
9775
+ });
9754
9776
  }
9755
9777
 
9756
9778
  //#endregion
9757
9779
  //#region src/plugins/valibot/v1/toAst/unknown.ts
9758
- function unknownToAst$3({ plugin }) {
9780
+ function unknownToPipes({ plugin }) {
9759
9781
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.unknown).call();
9760
9782
  }
9761
9783
 
9762
9784
  //#endregion
9763
9785
  //#region src/plugins/valibot/v1/toAst/array.ts
9764
- function arrayToAst$3(options) {
9765
- const { plugin } = options;
9766
- let { schema } = options;
9767
- const result = { pipes: [] };
9786
+ function arrayToPipes(ctx$1) {
9787
+ const { plugin, walk, walkerCtx } = ctx$1;
9788
+ let { schema } = ctx$1;
9768
9789
  const v = plugin.external("valibot.v");
9769
- const functionName = $(v).attr(identifiers$1.schemas.array);
9770
- if (!schema.items) {
9771
- const expression = functionName.call(unknownToAst$3({
9772
- ...options,
9773
- schema: { type: "unknown" }
9774
- }));
9775
- result.pipes.push(expression);
9776
- } else {
9790
+ const arrayFn = $(v).attr(identifiers$1.schemas.array);
9791
+ const childResults = [];
9792
+ const resultPipes = [];
9793
+ if (!schema.items) resultPipes.push(arrayFn.call(unknownToPipes({ plugin })));
9794
+ else {
9777
9795
  schema = deduplicateSchema({ schema });
9778
- const itemExpressions = schema.items.map((item, index) => {
9779
- const itemAst = irSchemaToAst$3({
9780
- ...options,
9781
- schema: item,
9782
- state: {
9783
- ...options.state,
9784
- path: ref([
9785
- ...fromRef(options.state.path),
9786
- "items",
9787
- index
9788
- ])
9789
- }
9790
- });
9791
- if (itemAst.hasLazyExpression) result.hasLazyExpression = true;
9792
- return pipesToNode(itemAst.pipes, plugin);
9793
- });
9794
- if (itemExpressions.length === 1) {
9795
- const expression = functionName.call(...itemExpressions);
9796
- result.pipes.push(expression);
9797
- } else {
9798
- if (schema.logicalOperator === "and") {}
9799
- const expression = functionName.call(unknownToAst$3({
9800
- ...options,
9801
- schema: { type: "unknown" }
9802
- }));
9803
- result.pipes.push(expression);
9796
+ for (let i = 0; i < schema.items.length; i++) {
9797
+ const item = schema.items[i];
9798
+ const result = walk(item, childContext(walkerCtx, "items", i));
9799
+ childResults.push(result);
9804
9800
  }
9801
+ if (childResults.length === 1) {
9802
+ const itemNode = pipesToNode(ctx$1.applyModifiers(childResults[0]).pipes, plugin);
9803
+ resultPipes.push(arrayFn.call(itemNode));
9804
+ } else resultPipes.push(arrayFn.call(unknownToPipes({ plugin })));
9805
9805
  }
9806
- if (schema.minItems === schema.maxItems && schema.minItems !== void 0) {
9807
- const expression = $(v).attr(identifiers$1.actions.length).call($.fromValue(schema.minItems));
9808
- result.pipes.push(expression);
9809
- } else {
9810
- if (schema.minItems !== void 0) {
9811
- const expression = $(v).attr(identifiers$1.actions.minLength).call($.fromValue(schema.minItems));
9812
- result.pipes.push(expression);
9813
- }
9814
- if (schema.maxItems !== void 0) {
9815
- const expression = $(v).attr(identifiers$1.actions.maxLength).call($.fromValue(schema.maxItems));
9816
- result.pipes.push(expression);
9817
- }
9806
+ if (schema.minItems === schema.maxItems && schema.minItems !== void 0) resultPipes.push($(v).attr(identifiers$1.actions.length).call($.fromValue(schema.minItems)));
9807
+ else {
9808
+ if (schema.minItems !== void 0) resultPipes.push($(v).attr(identifiers$1.actions.minLength).call($.fromValue(schema.minItems)));
9809
+ if (schema.maxItems !== void 0) resultPipes.push($(v).attr(identifiers$1.actions.maxLength).call($.fromValue(schema.maxItems)));
9818
9810
  }
9819
- return result;
9811
+ return {
9812
+ childResults,
9813
+ pipes: resultPipes
9814
+ };
9820
9815
  }
9821
9816
 
9822
9817
  //#endregion
9823
9818
  //#region src/plugins/valibot/v1/toAst/boolean.ts
9824
- function booleanToAst$3({ plugin, schema }) {
9825
- const pipes$1 = [];
9819
+ function booleanToPipes({ plugin, schema }) {
9826
9820
  const v = plugin.external("valibot.v");
9827
- if (typeof schema.const === "boolean") {
9828
- pipes$1.push($(v).attr(identifiers$1.schemas.literal).call($.literal(schema.const)));
9829
- return pipesToNode(pipes$1, plugin);
9830
- }
9831
- pipes$1.push($(v).attr(identifiers$1.schemas.boolean).call());
9832
- return pipesToNode(pipes$1, plugin);
9821
+ if (typeof schema.const === "boolean") return $(v).attr(identifiers$1.schemas.literal).call($.literal(schema.const));
9822
+ return $(v).attr(identifiers$1.schemas.boolean).call();
9833
9823
  }
9834
9824
 
9835
9825
  //#endregion
@@ -9851,31 +9841,20 @@ function baseNode$15(ctx$1) {
9851
9841
  const { enumMembers } = ctx$1.nodes.items(ctx$1);
9852
9842
  return $(v).attr(identifiers$1.schemas.picklist).call($.array(...enumMembers));
9853
9843
  }
9854
- function nullableNode$3(ctx$1) {
9855
- const { symbols } = ctx$1;
9856
- const { v } = symbols;
9857
- const { isNullable } = ctx$1.nodes.items(ctx$1);
9858
- if (!isNullable) return;
9859
- const currentNode = ctx$1.pipes.toNode(ctx$1.pipes.current, ctx$1.plugin);
9860
- return $(v).attr(identifiers$1.schemas.nullable).call(currentNode);
9861
- }
9862
9844
  function enumResolver$3(ctx$1) {
9863
9845
  const { enumMembers } = ctx$1.nodes.items(ctx$1);
9864
9846
  if (!enumMembers.length) return ctx$1.pipes.current;
9865
9847
  const baseExpression = ctx$1.nodes.base(ctx$1);
9866
9848
  ctx$1.pipes.push(ctx$1.pipes.current, baseExpression);
9867
- const nullableExpression = ctx$1.nodes.nullable(ctx$1);
9868
- if (nullableExpression) return nullableExpression;
9869
9849
  return ctx$1.pipes.current;
9870
9850
  }
9871
- function enumToAst$3({ plugin, schema, state }) {
9851
+ function enumToPipes({ plugin, schema }) {
9872
9852
  const v = plugin.external("valibot.v");
9873
- const { enumMembers } = itemsNode$3({
9853
+ const { enumMembers, isNullable } = itemsNode$3({
9874
9854
  $,
9875
9855
  nodes: {
9876
9856
  base: baseNode$15,
9877
- items: itemsNode$3,
9878
- nullable: nullableNode$3
9857
+ items: itemsNode$3
9879
9858
  },
9880
9859
  pipes: {
9881
9860
  ...pipes,
@@ -9883,20 +9862,17 @@ function enumToAst$3({ plugin, schema, state }) {
9883
9862
  },
9884
9863
  plugin,
9885
9864
  schema,
9886
- symbols: { v },
9887
- utils: { state }
9888
- });
9889
- if (!enumMembers.length) return unknownToAst$3({
9890
- plugin,
9891
- schema: { type: "unknown" },
9892
- state
9865
+ symbols: { v }
9893
9866
  });
9867
+ if (!enumMembers.length) return {
9868
+ isNullable,
9869
+ pipe: unknownToPipes({ plugin })
9870
+ };
9894
9871
  const ctx$1 = {
9895
9872
  $,
9896
9873
  nodes: {
9897
9874
  base: baseNode$15,
9898
- items: itemsNode$3,
9899
- nullable: nullableNode$3
9875
+ items: itemsNode$3
9900
9876
  },
9901
9877
  pipes: {
9902
9878
  ...pipes,
@@ -9904,23 +9880,25 @@ function enumToAst$3({ plugin, schema, state }) {
9904
9880
  },
9905
9881
  plugin,
9906
9882
  schema,
9907
- symbols: { v },
9908
- utils: { state }
9883
+ symbols: { v }
9909
9884
  };
9910
9885
  const resolver = plugin.config["~resolvers"]?.enum;
9911
9886
  const node = resolver?.(ctx$1) ?? enumResolver$3(ctx$1);
9912
- return ctx$1.pipes.toNode(node, plugin);
9887
+ return {
9888
+ isNullable,
9889
+ pipe: ctx$1.pipes.toNode(node, plugin)
9890
+ };
9913
9891
  }
9914
9892
 
9915
9893
  //#endregion
9916
9894
  //#region src/plugins/valibot/v1/toAst/never.ts
9917
- function neverToAst$3({ plugin }) {
9895
+ function neverToPipes({ plugin }) {
9918
9896
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.never).call();
9919
9897
  }
9920
9898
 
9921
9899
  //#endregion
9922
9900
  //#region src/plugins/valibot/v1/toAst/null.ts
9923
- function nullToAst$3({ plugin }) {
9901
+ function nullToPipes({ plugin }) {
9924
9902
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.null).call();
9925
9903
  }
9926
9904
 
@@ -9958,10 +9936,10 @@ function baseNode$14(ctx$1) {
9958
9936
  const { schema, symbols } = ctx$1;
9959
9937
  const { v } = symbols;
9960
9938
  if (ctx$1.utils.shouldCoerceToBigInt(schema.format)) return [$(v).attr(identifiers$1.schemas.union).call($.array($(v).attr(identifiers$1.schemas.number).call(), $(v).attr(identifiers$1.schemas.string).call(), $(v).attr(identifiers$1.schemas.bigInt).call())), $(v).attr(identifiers$1.actions.transform).call($.func().param("x").do($("BigInt").call("x").return()))];
9961
- const pipes$1 = [];
9962
- pipes$1.push($(v).attr(identifiers$1.schemas.number).call());
9963
- if (schema.type === "integer") pipes$1.push($(v).attr(identifiers$1.actions.integer).call());
9964
- return pipes$1;
9939
+ const result = [];
9940
+ result.push($(v).attr(identifiers$1.schemas.number).call());
9941
+ if (schema.type === "integer") result.push($(v).attr(identifiers$1.actions.integer).call());
9942
+ return result;
9965
9943
  }
9966
9944
  function constNode$7(ctx$1) {
9967
9945
  const { schema, symbols } = ctx$1;
@@ -9986,17 +9964,17 @@ function minNode$3(ctx$1) {
9986
9964
  if (limit) return $(v).attr(identifiers$1.actions.minValue).call(ctx$1.utils.maybeBigInt(limit.minValue, schema.format), $.literal(limit.minError));
9987
9965
  }
9988
9966
  function numberResolver$3(ctx$1) {
9989
- const constNode$8 = ctx$1.nodes.const(ctx$1);
9990
- if (constNode$8) return ctx$1.pipes.push(ctx$1.pipes.current, constNode$8);
9991
- const baseNode$16 = ctx$1.nodes.base(ctx$1);
9992
- if (baseNode$16) ctx$1.pipes.push(ctx$1.pipes.current, baseNode$16);
9993
- const minNode$4 = ctx$1.nodes.min(ctx$1);
9994
- if (minNode$4) ctx$1.pipes.push(ctx$1.pipes.current, minNode$4);
9995
- const maxNode$4 = ctx$1.nodes.max(ctx$1);
9996
- if (maxNode$4) ctx$1.pipes.push(ctx$1.pipes.current, maxNode$4);
9967
+ const constResult = ctx$1.nodes.const(ctx$1);
9968
+ if (constResult) return ctx$1.pipes.push(ctx$1.pipes.current, constResult);
9969
+ const baseResult = ctx$1.nodes.base(ctx$1);
9970
+ if (baseResult) ctx$1.pipes.push(ctx$1.pipes.current, baseResult);
9971
+ const minResult = ctx$1.nodes.min(ctx$1);
9972
+ if (minResult) ctx$1.pipes.push(ctx$1.pipes.current, minResult);
9973
+ const maxResult = ctx$1.nodes.max(ctx$1);
9974
+ if (maxResult) ctx$1.pipes.push(ctx$1.pipes.current, maxResult);
9997
9975
  return ctx$1.pipes.current;
9998
9976
  }
9999
- function numberToNode$3({ plugin, schema }) {
9977
+ function numberToPipes({ plugin, schema }) {
10000
9978
  const ctx$1 = {
10001
9979
  $,
10002
9980
  nodes: {
@@ -10026,25 +10004,17 @@ function numberToNode$3({ plugin, schema }) {
10026
10004
  //#endregion
10027
10005
  //#region src/plugins/valibot/v1/toAst/object.ts
10028
10006
  function additionalPropertiesNode$3(ctx$1) {
10029
- const { plugin, schema } = ctx$1;
10007
+ const { schema } = ctx$1;
10030
10008
  if (!schema.additionalProperties || !schema.additionalProperties.type) return;
10031
10009
  if (schema.additionalProperties.type === "never") return null;
10032
- const additionalAst = irSchemaToAst$3({
10033
- ...ctx$1,
10034
- schema: schema.additionalProperties,
10035
- state: {
10036
- ...ctx$1.utils.state,
10037
- path: ref([...fromRef(ctx$1.utils.state.path), "additionalProperties"])
10038
- }
10039
- });
10040
- if (additionalAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
10041
- return pipes.toNode(additionalAst.pipes, plugin);
10010
+ const additionalResult = ctx$1.walk(schema.additionalProperties, childContext(ctx$1.walkerCtx, "additionalProperties"));
10011
+ ctx$1._childResults.push(additionalResult);
10012
+ return pipesToNode(additionalResult.pipes, ctx$1.plugin);
10042
10013
  }
10043
10014
  function baseNode$13(ctx$1) {
10044
- const { nodes, symbols } = ctx$1;
10045
- const { v } = symbols;
10046
- const additional = nodes.additionalProperties(ctx$1);
10047
- const shape = nodes.shape(ctx$1);
10015
+ const { v } = ctx$1.symbols;
10016
+ const additional = ctx$1.nodes.additionalProperties(ctx$1);
10017
+ const shape = ctx$1.nodes.shape(ctx$1);
10048
10018
  if (additional === null) return $(v).attr(identifiers$1.schemas.strictObject).call(shape);
10049
10019
  if (additional) {
10050
10020
  if (shape.isEmpty) return $(v).attr(identifiers$1.schemas.record).call($(v).attr(identifiers$1.schemas.string).call(), additional);
@@ -10056,33 +10026,25 @@ function objectResolver$3(ctx$1) {
10056
10026
  return ctx$1.nodes.base(ctx$1);
10057
10027
  }
10058
10028
  function shapeNode$3(ctx$1) {
10059
- const { plugin, schema } = ctx$1;
10029
+ const { schema } = ctx$1;
10060
10030
  const shape = $.object().pretty();
10061
10031
  for (const name in schema.properties) {
10062
10032
  const property = schema.properties[name];
10063
- const propertyAst = irSchemaToAst$3({
10064
- ...ctx$1,
10065
- optional: !schema.required?.includes(name),
10066
- schema: property,
10067
- state: {
10068
- ...ctx$1.utils.state,
10069
- path: ref([
10070
- ...fromRef(ctx$1.utils.state.path),
10071
- "properties",
10072
- name
10073
- ])
10074
- }
10075
- });
10076
- if (propertyAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
10077
- shape.prop(name, pipes.toNode(propertyAst.pipes, plugin));
10033
+ const isOptional = !schema.required?.includes(name);
10034
+ const propertyResult = ctx$1.walk(property, childContext(ctx$1.walkerCtx, "properties", name));
10035
+ ctx$1._childResults.push(propertyResult);
10036
+ const finalExpr = ctx$1.applyModifiers(propertyResult, { optional: isOptional });
10037
+ shape.prop(name, pipesToNode(finalExpr.pipes, ctx$1.plugin));
10078
10038
  }
10079
10039
  return shape;
10080
10040
  }
10081
- function objectToAst$3(options) {
10082
- const { plugin } = options;
10083
- const ctx$1 = {
10084
- ...options,
10041
+ function objectToPipes(ctx$1) {
10042
+ const { applyModifiers, plugin, schema, walk, walkerCtx } = ctx$1;
10043
+ const childResults = [];
10044
+ const extendedCtx = {
10085
10045
  $,
10046
+ _childResults: childResults,
10047
+ applyModifiers,
10086
10048
  nodes: {
10087
10049
  additionalProperties: additionalPropertiesNode$3,
10088
10050
  base: baseNode$13,
@@ -10092,16 +10054,19 @@ function objectToAst$3(options) {
10092
10054
  ...pipes,
10093
10055
  current: []
10094
10056
  },
10057
+ plugin,
10058
+ schema,
10095
10059
  symbols: { v: plugin.external("valibot.v") },
10096
- utils: {
10097
- ast: {},
10098
- state: options.state
10099
- }
10060
+ utils: { ast: {} },
10061
+ walk,
10062
+ walkerCtx
10100
10063
  };
10101
10064
  const resolver = plugin.config["~resolvers"]?.object;
10102
- const node = resolver?.(ctx$1) ?? objectResolver$3(ctx$1);
10103
- ctx$1.utils.ast.pipes = [ctx$1.pipes.toNode(node, plugin)];
10104
- return ctx$1.utils.ast;
10065
+ const node = resolver?.(extendedCtx) ?? objectResolver$3(extendedCtx);
10066
+ return {
10067
+ childResults,
10068
+ pipes: [extendedCtx.pipes.toNode(node, plugin)]
10069
+ };
10105
10070
  }
10106
10071
 
10107
10072
  //#endregion
@@ -10173,7 +10138,14 @@ function stringResolver$3(ctx$1) {
10173
10138
  if (patternNode$4) ctx$1.pipes.push(ctx$1.pipes.current, patternNode$4);
10174
10139
  return ctx$1.pipes.current;
10175
10140
  }
10176
- function stringToNode$3({ plugin, schema }) {
10141
+ function stringToPipes({ plugin, schema }) {
10142
+ if (shouldCoerceToBigInt(schema.format)) return numberToPipes({
10143
+ plugin,
10144
+ schema: {
10145
+ ...schema,
10146
+ type: "number"
10147
+ }
10148
+ });
10177
10149
  const ctx$1 = {
10178
10150
  $,
10179
10151
  nodes: {
@@ -10200,215 +10172,361 @@ function stringToNode$3({ plugin, schema }) {
10200
10172
 
10201
10173
  //#endregion
10202
10174
  //#region src/plugins/valibot/v1/toAst/tuple.ts
10203
- function tupleToAst$3(options) {
10204
- const { plugin, schema } = options;
10205
- const result = {};
10175
+ function tupleToPipes(ctx$1) {
10176
+ const { plugin, schema, walk, walkerCtx } = ctx$1;
10206
10177
  const v = plugin.external("valibot.v");
10178
+ const childResults = [];
10207
10179
  if (schema.const && Array.isArray(schema.const)) {
10208
10180
  const tupleElements = schema.const.map((value) => $(v).attr(identifiers$1.schemas.literal).call($.fromValue(value)));
10209
- result.pipes = [$(v).attr(identifiers$1.schemas.tuple).call($.array(...tupleElements))];
10210
- return result;
10181
+ return {
10182
+ childResults: [],
10183
+ pipes: [$(v).attr(identifiers$1.schemas.tuple).call($.array(...tupleElements))]
10184
+ };
10211
10185
  }
10212
10186
  if (schema.items) {
10213
- const tupleElements = schema.items.map((item, index) => {
10214
- const schemaPipes = irSchemaToAst$3({
10215
- ...options,
10216
- schema: item,
10217
- state: {
10218
- ...options.state,
10219
- path: ref([
10220
- ...fromRef(options.state.path),
10221
- "items",
10222
- index
10223
- ])
10224
- }
10225
- });
10226
- if (schemaPipes.hasLazyExpression) result.hasLazyExpression = true;
10227
- return pipesToNode(schemaPipes.pipes, plugin);
10228
- });
10229
- result.pipes = [$(v).attr(identifiers$1.schemas.tuple).call($.array(...tupleElements))];
10230
- return result;
10187
+ for (let i = 0; i < schema.items.length; i++) {
10188
+ const item = schema.items[i];
10189
+ const result = walk(item, childContext(walkerCtx, "items", i));
10190
+ childResults.push(result);
10191
+ }
10192
+ const tupleElements = childResults.map((r) => pipesToNode(ctx$1.applyModifiers(r).pipes, plugin));
10193
+ return {
10194
+ childResults,
10195
+ pipes: [$(v).attr(identifiers$1.schemas.tuple).call($.array(...tupleElements))]
10196
+ };
10231
10197
  }
10232
- return { pipes: [unknownToAst$3({
10233
- ...options,
10234
- schema: { type: "unknown" }
10235
- })] };
10198
+ return {
10199
+ childResults: [],
10200
+ pipes: [unknownToPipes({ plugin })]
10201
+ };
10236
10202
  }
10237
10203
 
10238
10204
  //#endregion
10239
10205
  //#region src/plugins/valibot/v1/toAst/undefined.ts
10240
- function undefinedToAst$3({ plugin }) {
10206
+ function undefinedToPipes({ plugin }) {
10241
10207
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.undefined).call();
10242
10208
  }
10243
10209
 
10244
10210
  //#endregion
10245
10211
  //#region src/plugins/valibot/v1/toAst/void.ts
10246
- function voidToAst$3({ plugin }) {
10212
+ function voidToPipes({ plugin }) {
10247
10213
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.void).call();
10248
10214
  }
10249
10215
 
10250
10216
  //#endregion
10251
- //#region src/plugins/valibot/v1/toAst/index.ts
10252
- function irSchemaWithTypeToAst$3({ schema, ...args }) {
10253
- switch (schema.type) {
10254
- case "array": return { expression: pipesToNode(arrayToAst$3({
10255
- ...args,
10256
- schema
10257
- }).pipes, args.plugin) };
10258
- case "boolean": return { expression: booleanToAst$3({
10259
- ...args,
10260
- schema
10261
- }) };
10262
- case "enum": return { expression: enumToAst$3({
10263
- ...args,
10264
- schema
10265
- }) };
10266
- case "integer":
10267
- case "number": return { expression: numberToNode$3({
10268
- ...args,
10269
- schema
10270
- }) };
10271
- case "never": return { expression: neverToAst$3({
10272
- ...args,
10273
- schema
10274
- }) };
10275
- case "null": return { expression: nullToAst$3({
10276
- ...args,
10277
- schema
10278
- }) };
10279
- case "object": return { expression: pipesToNode(objectToAst$3({
10280
- ...args,
10281
- schema
10282
- }).pipes, args.plugin) };
10283
- case "string": return { expression: shouldCoerceToBigInt(schema.format) ? numberToNode$3({
10284
- ...args,
10285
- schema: {
10286
- ...schema,
10287
- type: "number"
10288
- }
10289
- }) : stringToNode$3({
10290
- ...args,
10291
- schema
10292
- }) };
10293
- case "tuple": return { expression: pipesToNode(tupleToAst$3({
10294
- ...args,
10295
- schema
10296
- }).pipes, args.plugin) };
10297
- case "undefined": return { expression: undefinedToAst$3({
10298
- ...args,
10299
- schema
10300
- }) };
10301
- case "unknown": return { expression: unknownToAst$3({
10302
- ...args,
10303
- schema
10304
- }) };
10305
- case "void": return { expression: voidToAst$3({
10306
- ...args,
10307
- schema
10308
- }) };
10309
- }
10217
+ //#region src/plugins/valibot/v1/walker.ts
10218
+ function getDefaultValue(meta) {
10219
+ return meta.format ? maybeBigInt(meta.default, meta.format) : $.fromValue(meta.default);
10310
10220
  }
10311
-
10312
- //#endregion
10313
- //#region src/plugins/valibot/v1/plugin.ts
10314
- function irSchemaToAst$3({ optional, plugin, schema, schemaExtractor, state }) {
10315
- if (schemaExtractor && !schema.$ref) {
10316
- const extracted = schemaExtractor({
10317
- meta: {
10318
- resource: "definition",
10319
- resourceId: pathToJsonPointer(fromRef(state.path))
10320
- },
10321
- naming: plugin.config.definitions,
10322
- path: fromRef(state.path),
10323
- plugin,
10324
- schema
10325
- });
10326
- if (extracted !== schema) schema = extracted;
10327
- }
10328
- const ast = { pipes: [] };
10329
- const v = plugin.external("valibot.v");
10330
- if (schema.$ref) {
10331
- const query = {
10332
- category: "schema",
10333
- resource: "definition",
10334
- resourceId: schema.$ref,
10335
- tool: "valibot"
10336
- };
10337
- const refSymbol = plugin.referenceSymbol(query);
10338
- if (plugin.isSymbolRegistered(query)) {
10339
- const ref$1 = $(refSymbol);
10340
- ast.pipes.push(ref$1);
10341
- } else {
10342
- const lazyExpression = $(v).attr(identifiers$1.schemas.lazy).call($.func().do($(refSymbol).return()));
10343
- ast.pipes.push(lazyExpression);
10344
- state.hasLazyExpression["~ref"] = true;
10345
- }
10346
- } else if (schema.type) {
10347
- const typeAst = irSchemaWithTypeToAst$3({
10348
- plugin,
10349
- schema,
10350
- schemaExtractor,
10351
- state
10352
- });
10353
- ast.typeName = typeAst.anyType;
10354
- ast.pipes.push(typeAst.expression);
10355
- if (plugin.config.metadata && schema.description) {
10356
- const expression = $(v).attr(identifiers$1.actions.metadata).call($.object().prop("description", $.literal(schema.description)));
10357
- ast.pipes.push(expression);
10358
- }
10359
- } else if (schema.items) {
10360
- schema = deduplicateSchema({ schema });
10361
- if (schema.items) {
10362
- const itemsAst = schema.items.map((item, index) => {
10363
- return pipesToNode(irSchemaToAst$3({
10364
- plugin,
10365
- schema: item,
10366
- schemaExtractor,
10367
- state: {
10368
- ...state,
10369
- path: ref([
10370
- ...fromRef(state.path),
10371
- "items",
10372
- index
10373
- ])
10374
- }
10375
- }).pipes, plugin);
10221
+ function createVisitor$3(config) {
10222
+ const { schemaExtractor } = config;
10223
+ return {
10224
+ applyModifiers(result, ctx$1, options = {}) {
10225
+ const { optional } = options;
10226
+ const v = ctx$1.plugin.external("valibot.v");
10227
+ const pipes$1 = [...result.pipes];
10228
+ if (result.meta.readonly) pipes$1.push($(v).attr(identifiers$1.actions.readonly).call());
10229
+ const hasDefault = result.meta.default !== void 0;
10230
+ const needsOptional = optional || hasDefault;
10231
+ const needsNullable = result.meta.nullable;
10232
+ const innerNode = pipesToNode(pipes$1, ctx$1.plugin);
10233
+ let finalPipes;
10234
+ if (needsOptional && needsNullable) if (hasDefault) finalPipes = [$(v).attr(identifiers$1.schemas.nullish).call(innerNode, getDefaultValue(result.meta))];
10235
+ else finalPipes = [$(v).attr(identifiers$1.schemas.nullish).call(innerNode)];
10236
+ else if (needsOptional) if (hasDefault) finalPipes = [$(v).attr(identifiers$1.schemas.optional).call(innerNode, getDefaultValue(result.meta))];
10237
+ else finalPipes = [$(v).attr(identifiers$1.schemas.optional).call(innerNode)];
10238
+ else if (needsNullable) finalPipes = [$(v).attr(identifiers$1.schemas.nullable).call(innerNode)];
10239
+ else finalPipes = pipes$1;
10240
+ return {
10241
+ pipes: finalPipes,
10242
+ typeName: result.meta.hasLazy ? identifiers$1.types.GenericSchema : void 0
10243
+ };
10244
+ },
10245
+ array(schema, ctx$1, walk) {
10246
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
10247
+ const { childResults, pipes: pipes$1 } = arrayToPipes({
10248
+ applyModifiers,
10249
+ plugin: ctx$1.plugin,
10250
+ schema,
10251
+ walk,
10252
+ walkerCtx: ctx$1
10253
+ });
10254
+ return {
10255
+ meta: inheritMeta(schema, childResults),
10256
+ pipes: pipes$1
10257
+ };
10258
+ },
10259
+ boolean(schema, ctx$1) {
10260
+ const pipe = booleanToPipes({
10261
+ plugin: ctx$1.plugin,
10262
+ schema
10263
+ });
10264
+ return {
10265
+ meta: defaultMeta(schema),
10266
+ pipes: [pipe]
10267
+ };
10268
+ },
10269
+ enum(schema, ctx$1) {
10270
+ const { isNullable, pipe } = enumToPipes({
10271
+ plugin: ctx$1.plugin,
10272
+ schema
10273
+ });
10274
+ return {
10275
+ meta: {
10276
+ ...defaultMeta(schema),
10277
+ nullable: isNullable
10278
+ },
10279
+ pipes: [pipe]
10280
+ };
10281
+ },
10282
+ integer(schema, ctx$1) {
10283
+ const pipe = numberToPipes({
10284
+ plugin: ctx$1.plugin,
10285
+ schema
10376
10286
  });
10377
- if (schema.logicalOperator === "and") {
10378
- const intersectExpression = $(v).attr(identifiers$1.schemas.intersect).call($.array(...itemsAst));
10379
- ast.pipes.push(intersectExpression);
10380
- } else {
10381
- const unionExpression = $(v).attr(identifiers$1.schemas.union).call($.array(...itemsAst));
10382
- ast.pipes.push(unionExpression);
10287
+ return {
10288
+ meta: defaultMeta(schema),
10289
+ pipes: [pipe]
10290
+ };
10291
+ },
10292
+ intercept(schema, ctx$1, walk) {
10293
+ if (schemaExtractor && !schema.$ref) {
10294
+ const extracted = schemaExtractor({
10295
+ meta: {
10296
+ resource: "definition",
10297
+ resourceId: pathToJsonPointer(fromRef(ctx$1.path))
10298
+ },
10299
+ naming: ctx$1.plugin.config.definitions,
10300
+ path: fromRef(ctx$1.path),
10301
+ plugin: ctx$1.plugin,
10302
+ schema
10303
+ });
10304
+ if (extracted !== schema) return walk(extracted, ctx$1);
10383
10305
  }
10384
- } else {
10385
- const schemaPipes = irSchemaToAst$3({
10386
- plugin,
10306
+ },
10307
+ intersection(items, schemas, parentSchema, ctx$1) {
10308
+ const v = ctx$1.plugin.external("valibot.v");
10309
+ const itemNodes = items.map((item) => pipesToNode(item.pipes, ctx$1.plugin));
10310
+ return {
10311
+ meta: composeMeta(items, { default: parentSchema.default }),
10312
+ pipes: [$(v).attr(identifiers$1.schemas.intersect).call($.array(...itemNodes))]
10313
+ };
10314
+ },
10315
+ never(schema, ctx$1) {
10316
+ const pipe = neverToPipes({
10317
+ plugin: ctx$1.plugin,
10318
+ schema
10319
+ });
10320
+ return {
10321
+ meta: {
10322
+ ...defaultMeta(schema),
10323
+ nullable: false,
10324
+ readonly: false
10325
+ },
10326
+ pipes: [pipe]
10327
+ };
10328
+ },
10329
+ null(schema, ctx$1) {
10330
+ const pipe = nullToPipes({
10331
+ plugin: ctx$1.plugin,
10332
+ schema
10333
+ });
10334
+ return {
10335
+ meta: {
10336
+ ...defaultMeta(schema),
10337
+ nullable: false,
10338
+ readonly: false
10339
+ },
10340
+ pipes: [pipe]
10341
+ };
10342
+ },
10343
+ number(schema, ctx$1) {
10344
+ const pipe = numberToPipes({
10345
+ plugin: ctx$1.plugin,
10346
+ schema
10347
+ });
10348
+ return {
10349
+ meta: defaultMeta(schema),
10350
+ pipes: [pipe]
10351
+ };
10352
+ },
10353
+ object(schema, ctx$1, walk) {
10354
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
10355
+ const { childResults, pipes: pipes$1 } = objectToPipes({
10356
+ applyModifiers,
10357
+ plugin: ctx$1.plugin,
10387
10358
  schema,
10388
- state
10359
+ walk,
10360
+ walkerCtx: ctx$1
10361
+ });
10362
+ return {
10363
+ meta: inheritMeta(schema, childResults),
10364
+ pipes: pipes$1
10365
+ };
10366
+ },
10367
+ postProcess(result, schema, ctx$1) {
10368
+ if (ctx$1.plugin.config.metadata && schema.description) {
10369
+ const metadataExpr = $(ctx$1.plugin.external("valibot.v")).attr(identifiers$1.actions.metadata).call($.object().prop("description", $.literal(schema.description)));
10370
+ return {
10371
+ meta: result.meta,
10372
+ pipes: [...result.pipes, metadataExpr]
10373
+ };
10374
+ }
10375
+ return result;
10376
+ },
10377
+ reference($ref, schema, ctx$1) {
10378
+ const v = ctx$1.plugin.external("valibot.v");
10379
+ const query = {
10380
+ category: "schema",
10381
+ resource: "definition",
10382
+ resourceId: $ref,
10383
+ tool: "valibot"
10384
+ };
10385
+ const refSymbol = ctx$1.plugin.referenceSymbol(query);
10386
+ if (ctx$1.plugin.isSymbolRegistered(query)) return {
10387
+ meta: defaultMeta(schema),
10388
+ pipes: [$(refSymbol)]
10389
+ };
10390
+ return {
10391
+ meta: {
10392
+ ...defaultMeta(schema),
10393
+ hasLazy: true
10394
+ },
10395
+ pipes: [$(v).attr(identifiers$1.schemas.lazy).call($.func().do($(refSymbol).return()))]
10396
+ };
10397
+ },
10398
+ string(schema, ctx$1) {
10399
+ const pipe = stringToPipes({
10400
+ plugin: ctx$1.plugin,
10401
+ schema
10402
+ });
10403
+ return {
10404
+ meta: defaultMeta(schema),
10405
+ pipes: [pipe]
10406
+ };
10407
+ },
10408
+ tuple(schema, ctx$1, walk) {
10409
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
10410
+ const { childResults, pipes: pipes$1 } = tupleToPipes({
10411
+ applyModifiers,
10412
+ plugin: ctx$1.plugin,
10413
+ schema,
10414
+ walk,
10415
+ walkerCtx: ctx$1
10416
+ });
10417
+ return {
10418
+ meta: inheritMeta(schema, childResults),
10419
+ pipes: pipes$1
10420
+ };
10421
+ },
10422
+ undefined(schema, ctx$1) {
10423
+ const pipe = undefinedToPipes({
10424
+ plugin: ctx$1.plugin,
10425
+ schema
10426
+ });
10427
+ return {
10428
+ meta: {
10429
+ ...defaultMeta(schema),
10430
+ nullable: false,
10431
+ readonly: false
10432
+ },
10433
+ pipes: [pipe]
10434
+ };
10435
+ },
10436
+ union(items, schemas, parentSchema, ctx$1) {
10437
+ const v = ctx$1.plugin.external("valibot.v");
10438
+ const hasNull = schemas.some((s) => s.type === "null") || items.some((i) => i.meta.nullable);
10439
+ const nonNullItems = [];
10440
+ items.forEach((item, index) => {
10441
+ if (schemas[index].type !== "null") nonNullItems.push(item);
10442
+ });
10443
+ let pipes$1;
10444
+ if (nonNullItems.length === 0) pipes$1 = [$(v).attr(identifiers$1.schemas.null).call()];
10445
+ else if (nonNullItems.length === 1) pipes$1 = nonNullItems[0].pipes;
10446
+ else {
10447
+ const itemNodes = nonNullItems.map((i) => pipesToNode(i.pipes, ctx$1.plugin));
10448
+ pipes$1 = [$(v).attr(identifiers$1.schemas.union).call($.array(...itemNodes))];
10449
+ }
10450
+ return {
10451
+ meta: composeMeta(items, {
10452
+ default: parentSchema.default,
10453
+ nullable: hasNull
10454
+ }),
10455
+ pipes: pipes$1
10456
+ };
10457
+ },
10458
+ unknown(schema, ctx$1) {
10459
+ const pipe = unknownToPipes({ plugin: ctx$1.plugin });
10460
+ return {
10461
+ meta: {
10462
+ ...defaultMeta(schema),
10463
+ nullable: false,
10464
+ readonly: false
10465
+ },
10466
+ pipes: [pipe]
10467
+ };
10468
+ },
10469
+ void(schema, ctx$1) {
10470
+ const pipe = voidToPipes({
10471
+ plugin: ctx$1.plugin,
10472
+ schema
10389
10473
  });
10390
- ast.pipes.push(...schemaPipes.pipes);
10474
+ return {
10475
+ meta: {
10476
+ ...defaultMeta(schema),
10477
+ nullable: false,
10478
+ readonly: false
10479
+ },
10480
+ pipes: [pipe]
10481
+ };
10391
10482
  }
10392
- } else {
10393
- const typeAst = irSchemaWithTypeToAst$3({
10394
- plugin,
10395
- schema: { type: "unknown" },
10396
- schemaExtractor,
10397
- state
10398
- });
10399
- ast.typeName = typeAst.anyType;
10400
- ast.pipes.push(typeAst.expression);
10401
- }
10402
- if (ast.pipes.length) {
10403
- if (schema.accessScope === "read") {
10404
- const readonlyExpression = $(v).attr(identifiers$1.actions.readonly).call();
10405
- ast.pipes.push(readonlyExpression);
10483
+ };
10484
+ }
10485
+
10486
+ //#endregion
10487
+ //#region src/plugins/valibot/v1/processor.ts
10488
+ function createProcessor$3(plugin) {
10489
+ const processor = createSchemaProcessor();
10490
+ const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
10491
+ function extractor(ctx$1) {
10492
+ if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
10493
+ for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
10494
+ process$1({
10495
+ namingAnchor: processor.context.anchor,
10496
+ tags: processor.context.tags,
10497
+ ...ctx$1
10498
+ });
10499
+ return { $ref: pathToJsonPointer(ctx$1.path) };
10406
10500
  }
10407
- if (schema.default !== void 0) ast.pipes = [$(v).attr(identifiers$1.schemas.optional).call(pipesToNode(ast.pipes, plugin), schema.type === "integer" || schema.type === "number" ? maybeBigInt(schema.default, schema.format) : $.fromValue(schema.default))];
10408
- else if (optional) ast.pipes = [$(v).attr(identifiers$1.schemas.optional).call(pipesToNode(ast.pipes, plugin))];
10501
+ return ctx$1.schema;
10409
10502
  }
10410
- return ast;
10503
+ function process$1(ctx$1) {
10504
+ if (!processor.markEmitted(ctx$1.path)) return;
10505
+ processor.withContext({
10506
+ anchor: ctx$1.namingAnchor,
10507
+ tags: ctx$1.tags
10508
+ }, () => {
10509
+ const visitor = createVisitor$3({ schemaExtractor: extractor });
10510
+ const result = createSchemaWalker(visitor)(ctx$1.schema, {
10511
+ path: ref(ctx$1.path),
10512
+ plugin
10513
+ });
10514
+ const final = visitor.applyModifiers(result, {
10515
+ path: ref(ctx$1.path),
10516
+ plugin
10517
+ });
10518
+ exportAst$1({
10519
+ ...ctx$1,
10520
+ final,
10521
+ plugin
10522
+ });
10523
+ });
10524
+ }
10525
+ return { process: process$1 };
10411
10526
  }
10527
+
10528
+ //#endregion
10529
+ //#region src/plugins/valibot/v1/plugin.ts
10412
10530
  const handlerV1 = ({ plugin }) => {
10413
10531
  plugin.symbol("v", {
10414
10532
  external: "valibot",
@@ -10546,8 +10664,10 @@ const defineConfig$1 = definePluginConfig(defaultConfig$1);
10546
10664
  //#endregion
10547
10665
  //#region src/plugins/zod/constants.ts
10548
10666
  const identifiers = {
10667
+ AnyZodObject: "AnyZodObject",
10549
10668
  ZodMiniOptional: "ZodMiniOptional",
10550
10669
  ZodOptional: "ZodOptional",
10670
+ ZodTypeAny: "ZodTypeAny",
10551
10671
  _default: "_default",
10552
10672
  and: "and",
10553
10673
  array: "array",
@@ -10585,6 +10705,7 @@ const identifiers = {
10585
10705
  never: "never",
10586
10706
  null: "null",
10587
10707
  nullable: "nullable",
10708
+ nullish: "nullish",
10588
10709
  number: "number",
10589
10710
  object: "object",
10590
10711
  optional: "optional",
@@ -10945,7 +11066,7 @@ function irWebhookToAst({ operation, path: path$1, plugin, processor, tags }) {
10945
11066
 
10946
11067
  //#endregion
10947
11068
  //#region src/plugins/zod/shared/export.ts
10948
- function exportAst({ ast, meta, naming, namingAnchor, path: path$1, plugin, schema, tags }) {
11069
+ function exportAst({ ast, meta, naming, namingAnchor, path: path$1, plugin, schema, state, tags }) {
10949
11070
  const z = plugin.external("zod.z");
10950
11071
  const name = pathToName(path$1, { anchor: namingAnchor });
10951
11072
  const symbol = plugin.symbol(applyNaming(name, naming), { meta: {
@@ -10963,7 +11084,7 @@ function exportAst({ ast, meta, naming, namingAnchor, path: path$1, plugin, sche
10963
11084
  variant: "infer",
10964
11085
  ...meta
10965
11086
  } }) : void 0;
10966
- const statement = $.const(symbol).export().$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v)).$if(ast.typeName, (c, v) => c.type($.type(z).attr(v))).assign(ast.expression);
11087
+ const statement = $.const(symbol).export().$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v)).$if(state.hasLazyExpression["~ref"] && state.anyType?.["~ref"], (c, v) => c.type($.type(z).attr(v))).assign(ast.expression);
10967
11088
  plugin.node(statement);
10968
11089
  if (typeInferSymbol) {
10969
11090
  const inferType = $.type.alias(typeInferSymbol).export().type($.type(z).attr(identifiers.infer).generic($(symbol).typeofType()));
@@ -10971,88 +11092,36 @@ function exportAst({ ast, meta, naming, namingAnchor, path: path$1, plugin, sche
10971
11092
  }
10972
11093
  }
10973
11094
 
10974
- //#endregion
10975
- //#region src/plugins/zod/mini/processor.ts
10976
- function createProcessor$2(plugin) {
10977
- const processor = createSchemaProcessor();
10978
- const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
10979
- function extractor(ctx$1) {
10980
- if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
10981
- for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
10982
- process$1({
10983
- namingAnchor: processor.context.anchor,
10984
- tags: processor.context.tags,
10985
- ...ctx$1
10986
- });
10987
- return { $ref: pathToJsonPointer(ctx$1.path) };
10988
- }
10989
- return ctx$1.schema;
10990
- }
10991
- function process$1(ctx$1) {
10992
- if (!processor.markEmitted(ctx$1.path)) return;
10993
- processor.withContext({
10994
- anchor: ctx$1.namingAnchor,
10995
- tags: ctx$1.tags
10996
- }, () => {
10997
- const state = refs({
10998
- hasLazyExpression: false,
10999
- path: ctx$1.path,
11000
- tags: ctx$1.tags
11001
- });
11002
- const ast = irSchemaToAst$2({
11003
- plugin,
11004
- schema: ctx$1.schema,
11005
- schemaExtractor: extractor,
11006
- state
11007
- });
11008
- exportAst({
11009
- ...ctx$1,
11010
- ast,
11011
- plugin,
11012
- state
11013
- });
11014
- });
11015
- }
11016
- return { process: process$1 };
11017
- }
11018
-
11019
11095
  //#endregion
11020
11096
  //#region src/plugins/zod/mini/toAst/unknown.ts
11021
- const unknownToAst$2 = ({ plugin }) => {
11097
+ function unknownToAst$2({ plugin }) {
11022
11098
  const z = plugin.external("zod.z");
11023
11099
  const result = {};
11024
11100
  result.expression = $(z).attr(identifiers.unknown).call();
11025
11101
  return result;
11026
- };
11102
+ }
11027
11103
 
11028
11104
  //#endregion
11029
11105
  //#region src/plugins/zod/mini/toAst/array.ts
11030
- const arrayToAst$2 = ({ plugin, schema, state }) => {
11031
- const z = plugin.external("zod.z");
11106
+ function arrayToAst$2(options) {
11107
+ const { applyModifiers, plugin, walk } = options;
11108
+ let { schema } = options;
11032
11109
  const result = {};
11110
+ const z = plugin.external("zod.z");
11033
11111
  const functionName = $(z).attr(identifiers.array);
11034
11112
  if (!schema.items) result.expression = functionName.call(unknownToAst$2({
11035
- plugin,
11036
- schema: { type: "unknown" },
11037
- state
11113
+ ...options,
11114
+ schema: { type: "unknown" }
11038
11115
  }).expression);
11039
11116
  else {
11040
11117
  schema = deduplicateSchema({ schema });
11041
11118
  const itemExpressions = schema.items.map((item, index) => {
11042
- const itemAst = irSchemaToAst$2({
11043
- plugin,
11044
- schema: item,
11045
- state: {
11046
- ...state,
11047
- path: ref([
11048
- ...fromRef(state.path),
11049
- "items",
11050
- index
11051
- ])
11052
- }
11053
- });
11054
- if (itemAst.hasLazyExpression) result.hasLazyExpression = true;
11055
- return itemAst.expression;
11119
+ const itemResult = walk(item, childContext({
11120
+ path: options.state.path,
11121
+ plugin: options.plugin
11122
+ }, "items", index));
11123
+ if (itemResult.hasLazyExpression) result.hasLazyExpression = true;
11124
+ return applyModifiers(itemResult, { optional: false }).expression;
11056
11125
  });
11057
11126
  if (itemExpressions.length === 1) result.expression = functionName.call(...itemExpressions);
11058
11127
  else if (schema.logicalOperator === "and") {
@@ -11074,7 +11143,7 @@ const arrayToAst$2 = ({ plugin, schema, state }) => {
11074
11143
  }
11075
11144
  if (checks.length > 0) result.expression = result.expression.attr(identifiers.check).call(...checks);
11076
11145
  return result;
11077
- };
11146
+ }
11078
11147
 
11079
11148
  //#endregion
11080
11149
  //#region src/plugins/zod/mini/toAst/boolean.ts
@@ -11129,31 +11198,21 @@ function baseNode$11(ctx$1) {
11129
11198
  else if (literalMembers.length === 1) return literalMembers[0];
11130
11199
  else return $(z).attr(identifiers.union).call($.array(...literalMembers));
11131
11200
  }
11132
- function nullableNode$2(ctx$1) {
11133
- const { chain, symbols } = ctx$1;
11134
- const { z } = symbols;
11135
- const { isNullable } = ctx$1.nodes.items(ctx$1);
11136
- if (!isNullable) return;
11137
- return $(z).attr(identifiers.nullable).call(chain.current);
11138
- }
11139
11201
  function enumResolver$2(ctx$1) {
11140
11202
  const { literalMembers } = ctx$1.nodes.items(ctx$1);
11141
11203
  if (!literalMembers.length) return ctx$1.chain.current;
11142
11204
  const baseExpression = ctx$1.nodes.base(ctx$1);
11143
11205
  ctx$1.chain.current = baseExpression;
11144
- const nullableExpression = ctx$1.nodes.nullable(ctx$1);
11145
- if (nullableExpression) ctx$1.chain.current = nullableExpression;
11146
11206
  return ctx$1.chain.current;
11147
11207
  }
11148
- const enumToAst$2 = ({ plugin, schema, state }) => {
11208
+ function enumToAst$2({ plugin, schema, state }) {
11149
11209
  const z = plugin.external("zod.z");
11150
11210
  const { literalMembers } = itemsNode$2({
11151
11211
  $,
11152
11212
  chain: { current: $(z) },
11153
11213
  nodes: {
11154
11214
  base: baseNode$11,
11155
- items: itemsNode$2,
11156
- nullable: nullableNode$2
11215
+ items: itemsNode$2
11157
11216
  },
11158
11217
  plugin,
11159
11218
  schema,
@@ -11165,16 +11224,14 @@ const enumToAst$2 = ({ plugin, schema, state }) => {
11165
11224
  });
11166
11225
  if (!literalMembers.length) return unknownToAst$2({
11167
11226
  plugin,
11168
- schema: { type: "unknown" },
11169
- state
11227
+ schema: { type: "unknown" }
11170
11228
  });
11171
11229
  const ctx$1 = {
11172
11230
  $,
11173
11231
  chain: { current: $(z) },
11174
11232
  nodes: {
11175
11233
  base: baseNode$11,
11176
- items: itemsNode$2,
11177
- nullable: nullableNode$2
11234
+ items: itemsNode$2
11178
11235
  },
11179
11236
  plugin,
11180
11237
  schema,
@@ -11186,25 +11243,25 @@ const enumToAst$2 = ({ plugin, schema, state }) => {
11186
11243
  };
11187
11244
  const resolver = plugin.config["~resolvers"]?.enum;
11188
11245
  return { expression: resolver?.(ctx$1) ?? enumResolver$2(ctx$1) };
11189
- };
11246
+ }
11190
11247
 
11191
11248
  //#endregion
11192
11249
  //#region src/plugins/zod/mini/toAst/never.ts
11193
- const neverToAst$2 = ({ plugin }) => {
11250
+ function neverToAst$2({ plugin }) {
11194
11251
  const z = plugin.external("zod.z");
11195
11252
  const result = {};
11196
11253
  result.expression = $(z).attr(identifiers.never).call();
11197
11254
  return result;
11198
- };
11255
+ }
11199
11256
 
11200
11257
  //#endregion
11201
11258
  //#region src/plugins/zod/mini/toAst/null.ts
11202
- const nullToAst$2 = ({ plugin }) => {
11259
+ function nullToAst$2({ plugin }) {
11203
11260
  const z = plugin.external("zod.z");
11204
11261
  const result = {};
11205
11262
  result.expression = $(z).attr(identifiers.null).call();
11206
11263
  return result;
11207
- };
11264
+ }
11208
11265
 
11209
11266
  //#endregion
11210
11267
  //#region src/plugins/zod/mini/toAst/number.ts
@@ -11254,7 +11311,7 @@ function numberResolver$2(ctx$1) {
11254
11311
  if (checks.length > 0) ctx$1.chain.current = ctx$1.chain.current.attr(identifiers.check).call(...checks);
11255
11312
  return ctx$1.chain.current;
11256
11313
  }
11257
- const numberToNode$2 = ({ plugin, schema, state }) => {
11314
+ function numberToNode$2({ plugin, schema, state }) {
11258
11315
  const ast = {};
11259
11316
  const z = plugin.external("zod.z");
11260
11317
  const ctx$1 = {
@@ -11280,23 +11337,16 @@ const numberToNode$2 = ({ plugin, schema, state }) => {
11280
11337
  const resolver = plugin.config["~resolvers"]?.number;
11281
11338
  ast.expression = resolver?.(ctx$1) ?? numberResolver$2(ctx$1);
11282
11339
  return ast;
11283
- };
11340
+ }
11284
11341
 
11285
11342
  //#endregion
11286
11343
  //#region src/plugins/zod/mini/toAst/object.ts
11287
11344
  function additionalPropertiesNode$2(ctx$1) {
11288
- const { plugin, schema } = ctx$1;
11345
+ const { schema, walk, walkerCtx } = ctx$1;
11289
11346
  if (!schema.additionalProperties || schema.properties && Object.keys(schema.properties).length > 0) return;
11290
- const additionalAst = irSchemaToAst$2({
11291
- plugin,
11292
- schema: schema.additionalProperties,
11293
- state: {
11294
- ...ctx$1.utils.state,
11295
- path: ref([...fromRef(ctx$1.utils.state.path), "additionalProperties"])
11296
- }
11297
- });
11298
- if (additionalAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
11299
- return additionalAst.expression;
11347
+ const additionalResult = walk(schema.additionalProperties, childContext(walkerCtx, "additionalProperties"));
11348
+ if (additionalResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
11349
+ return additionalResult.expression.expression;
11300
11350
  }
11301
11351
  function baseNode$9(ctx$1) {
11302
11352
  const { nodes, symbols } = ctx$1;
@@ -11310,34 +11360,27 @@ function objectResolver$2(ctx$1) {
11310
11360
  return ctx$1.nodes.base(ctx$1);
11311
11361
  }
11312
11362
  function shapeNode$2(ctx$1) {
11313
- const { plugin, schema } = ctx$1;
11363
+ const { applyModifiers, schema, walk, walkerCtx } = ctx$1;
11314
11364
  const shape = $.object().pretty();
11315
11365
  for (const name in schema.properties) {
11316
11366
  const property = schema.properties[name];
11317
- const propertyAst = irSchemaToAst$2({
11318
- optional: !schema.required?.includes(name),
11319
- plugin,
11320
- schema: property,
11321
- state: {
11322
- ...ctx$1.utils.state,
11323
- path: ref([
11324
- ...fromRef(ctx$1.utils.state.path),
11325
- "properties",
11326
- name
11327
- ])
11328
- }
11329
- });
11330
- if (propertyAst.hasLazyExpression) {
11367
+ const isOptional = !schema.required?.includes(name);
11368
+ const propertyResult = walk(property, childContext(walkerCtx, "properties", name));
11369
+ if (propertyResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
11370
+ const ast = applyModifiers(propertyResult, { optional: isOptional });
11371
+ if (ast.hasLazyExpression) {
11331
11372
  ctx$1.utils.ast.hasLazyExpression = true;
11332
- shape.getter(name, propertyAst.expression.return());
11333
- } else shape.prop(name, propertyAst.expression);
11373
+ shape.getter(name, ast.expression.return());
11374
+ } else shape.prop(name, ast.expression);
11334
11375
  }
11335
11376
  return shape;
11336
11377
  }
11337
- const objectToAst$2 = ({ plugin, schema, state }) => {
11378
+ function objectToAst$2(options) {
11379
+ const { plugin } = options;
11338
11380
  const ast = {};
11339
11381
  const z = plugin.external("zod.z");
11340
11382
  const ctx$1 = {
11383
+ ...options,
11341
11384
  $,
11342
11385
  chain: { current: $(z) },
11343
11386
  nodes: {
@@ -11346,17 +11389,16 @@ const objectToAst$2 = ({ plugin, schema, state }) => {
11346
11389
  shape: shapeNode$2
11347
11390
  },
11348
11391
  plugin,
11349
- schema,
11350
11392
  symbols: { z },
11351
11393
  utils: {
11352
11394
  ast,
11353
- state
11395
+ state: options.state
11354
11396
  }
11355
11397
  };
11356
11398
  const resolver = plugin.config["~resolvers"]?.object;
11357
11399
  ast.expression = resolver?.(ctx$1) ?? objectResolver$2(ctx$1);
11358
11400
  return ast;
11359
- };
11401
+ }
11360
11402
 
11361
11403
  //#endregion
11362
11404
  //#region src/plugins/zod/mini/toAst/string.ts
@@ -11435,7 +11477,7 @@ function stringResolver$2(ctx$1) {
11435
11477
  if (checks.length > 0) ctx$1.chain.current = ctx$1.chain.current.attr(identifiers.check).call(...checks);
11436
11478
  return ctx$1.chain.current;
11437
11479
  }
11438
- const stringToNode$2 = ({ plugin, schema }) => {
11480
+ function stringToNode$2({ plugin, schema }) {
11439
11481
  const z = plugin.external("zod.z");
11440
11482
  const ctx$1 = {
11441
11483
  $,
@@ -11455,13 +11497,14 @@ const stringToNode$2 = ({ plugin, schema }) => {
11455
11497
  };
11456
11498
  const resolver = plugin.config["~resolvers"]?.string;
11457
11499
  return { expression: resolver?.(ctx$1) ?? stringResolver$2(ctx$1) };
11458
- };
11500
+ }
11459
11501
 
11460
11502
  //#endregion
11461
11503
  //#region src/plugins/zod/mini/toAst/tuple.ts
11462
- const tupleToAst$2 = ({ plugin, schema, state }) => {
11463
- const z = plugin.external("zod.z");
11504
+ function tupleToAst$2(options) {
11505
+ const { applyModifiers, plugin, schema, walk } = options;
11464
11506
  const result = {};
11507
+ const z = plugin.external("zod.z");
11465
11508
  if (schema.const && Array.isArray(schema.const)) {
11466
11509
  const tupleElements$1 = schema.const.map((value) => $(z).attr(identifiers.literal).call($.fromValue(value)));
11467
11510
  result.expression = $(z).attr(identifiers.tuple).call($.array(...tupleElements$1));
@@ -11469,347 +11512,490 @@ const tupleToAst$2 = ({ plugin, schema, state }) => {
11469
11512
  }
11470
11513
  const tupleElements = [];
11471
11514
  if (schema.items) schema.items.forEach((item, index) => {
11472
- const itemSchema = irSchemaToAst$2({
11473
- plugin,
11474
- schema: item,
11475
- state: {
11476
- ...state,
11477
- path: ref([
11478
- ...fromRef(state.path),
11479
- "items",
11480
- index
11481
- ])
11482
- }
11483
- });
11484
- tupleElements.push(itemSchema.expression);
11485
- if (itemSchema.hasLazyExpression) result.hasLazyExpression = true;
11515
+ const itemResult = walk(item, childContext({
11516
+ path: options.state.path,
11517
+ plugin: options.plugin
11518
+ }, "items", index));
11519
+ if (itemResult.hasLazyExpression) result.hasLazyExpression = true;
11520
+ const finalExpr = applyModifiers(itemResult, { optional: false });
11521
+ tupleElements.push(finalExpr.expression);
11486
11522
  });
11487
11523
  result.expression = $(z).attr(identifiers.tuple).call($.array(...tupleElements));
11488
11524
  return result;
11489
- };
11525
+ }
11490
11526
 
11491
11527
  //#endregion
11492
11528
  //#region src/plugins/zod/mini/toAst/undefined.ts
11493
- const undefinedToAst$2 = ({ plugin }) => {
11529
+ function undefinedToAst$2({ plugin }) {
11494
11530
  const z = plugin.external("zod.z");
11495
11531
  const result = {};
11496
11532
  result.expression = $(z).attr(identifiers.undefined).call();
11497
11533
  return result;
11498
- };
11534
+ }
11499
11535
 
11500
11536
  //#endregion
11501
11537
  //#region src/plugins/zod/mini/toAst/void.ts
11502
- const voidToAst$2 = ({ plugin }) => {
11538
+ function voidToAst$2({ plugin }) {
11503
11539
  const z = plugin.external("zod.z");
11504
11540
  const result = {};
11505
11541
  result.expression = $(z).attr(identifiers.void).call();
11506
11542
  return result;
11507
- };
11508
-
11509
- //#endregion
11510
- //#region src/plugins/zod/mini/toAst/index.ts
11511
- function irSchemaWithTypeToAst$2({ schema, ...args }) {
11512
- switch (schema.type) {
11513
- case "array": return arrayToAst$2({
11514
- ...args,
11515
- schema
11516
- });
11517
- case "boolean": return booleanToAst$2({
11518
- ...args,
11519
- schema
11520
- });
11521
- case "enum": return enumToAst$2({
11522
- ...args,
11523
- schema
11524
- });
11525
- case "integer":
11526
- case "number": return numberToNode$2({
11527
- ...args,
11528
- schema
11529
- });
11530
- case "never": return neverToAst$2({
11531
- ...args,
11532
- schema
11533
- });
11534
- case "null": return nullToAst$2({
11535
- ...args,
11536
- schema
11537
- });
11538
- case "object": return objectToAst$2({
11539
- ...args,
11540
- schema
11541
- });
11542
- case "string": return shouldCoerceToBigInt(schema.format) ? numberToNode$2({
11543
- ...args,
11544
- schema: {
11545
- ...schema,
11546
- type: "number"
11547
- }
11548
- }) : stringToNode$2({
11549
- ...args,
11550
- schema
11551
- });
11552
- case "tuple": return tupleToAst$2({
11553
- ...args,
11554
- schema
11555
- });
11556
- case "undefined": return undefinedToAst$2({
11557
- ...args,
11558
- schema
11559
- });
11560
- case "unknown": return unknownToAst$2({
11561
- ...args,
11562
- schema
11563
- });
11564
- case "void": return voidToAst$2({
11565
- ...args,
11566
- schema
11567
- });
11568
- }
11569
- }
11570
-
11571
- //#endregion
11572
- //#region src/plugins/zod/mini/plugin.ts
11573
- function irSchemaToAst$2({ optional, plugin, schema, schemaExtractor, state }) {
11574
- if (schemaExtractor && !schema.$ref) {
11575
- const extracted = schemaExtractor({
11576
- meta: {
11577
- resource: "definition",
11578
- resourceId: pathToJsonPointer(fromRef(state.path))
11579
- },
11580
- naming: plugin.config.definitions,
11581
- path: fromRef(state.path),
11582
- plugin,
11583
- schema
11584
- });
11585
- if (extracted !== schema) schema = extracted;
11586
- }
11587
- let ast = {};
11588
- const z = plugin.external("zod.z");
11589
- if (schema.$ref) {
11590
- const query = {
11591
- category: "schema",
11592
- resource: "definition",
11593
- resourceId: schema.$ref,
11594
- tool: "zod"
11595
- };
11596
- const refSymbol = plugin.referenceSymbol(query);
11597
- if (plugin.isSymbolRegistered(query)) ast.expression = $(refSymbol);
11598
- else {
11599
- ast.expression = $(z).attr(identifiers.lazy).call($.func().returns("any").do($(refSymbol).return()));
11600
- ast.hasLazyExpression = true;
11601
- state.hasLazyExpression["~ref"] = true;
11602
- }
11603
- } else if (schema.type) {
11604
- const typeAst = irSchemaWithTypeToAst$2({
11605
- plugin,
11606
- schema,
11607
- state
11608
- });
11609
- ast.expression = typeAst.expression;
11610
- ast.hasLazyExpression = typeAst.hasLazyExpression;
11611
- if (plugin.config.metadata && schema.description) ast.expression = ast.expression.attr(identifiers.register).call($(z).attr(identifiers.globalRegistry), $.object().pretty().prop("description", $.literal(schema.description)));
11612
- } else if (schema.items) {
11613
- schema = deduplicateSchema({ schema });
11614
- if (schema.items) {
11615
- const itemSchemas = schema.items.map((item, index) => irSchemaToAst$2({
11616
- plugin,
11617
- schema: item,
11618
- state: {
11619
- ...state,
11620
- path: ref([
11621
- ...fromRef(state.path),
11622
- "items",
11623
- index
11624
- ])
11625
- }
11626
- }));
11627
- if (schema.logicalOperator === "and") {
11628
- const firstSchema = schema.items[0];
11629
- if (firstSchema.logicalOperator === "or" || firstSchema.type && firstSchema.type !== "object") ast.expression = $(z).attr(identifiers.intersection).call(...itemSchemas.map((schema$1) => schema$1.expression));
11630
- else {
11631
- ast.expression = itemSchemas[0].expression;
11632
- itemSchemas.slice(1).forEach((schema$1) => {
11633
- ast.expression = $(z).attr(identifiers.intersection).call(ast.expression, schema$1.hasLazyExpression ? $(z).attr(identifiers.lazy).call($.func().do(schema$1.expression.return())) : schema$1.expression);
11634
- });
11635
- }
11636
- } else ast.expression = $(z).attr(identifiers.union).call($.array().pretty().elements(...itemSchemas.map((schema$1) => schema$1.expression)));
11637
- } else ast = irSchemaToAst$2({
11638
- plugin,
11639
- schema,
11640
- state
11641
- });
11642
- } else {
11643
- const typeAst = irSchemaWithTypeToAst$2({
11644
- plugin,
11645
- schema: { type: "unknown" },
11646
- state
11647
- });
11648
- ast.expression = typeAst.expression;
11649
- }
11650
- if (ast.expression) {
11651
- if (schema.accessScope === "read") ast.expression = $(z).attr(identifiers.readonly).call(ast.expression);
11652
- if (optional) {
11653
- ast.expression = $(z).attr(identifiers.optional).call(ast.expression);
11654
- ast.typeName = identifiers.ZodMiniOptional;
11655
- }
11656
- if (schema.default !== void 0) ast.expression = $(z).attr(identifiers._default).call(ast.expression, schema.type === "integer" || schema.type === "number" ? maybeBigInt(schema.default, schema.format) : $.fromValue(schema.default));
11657
- }
11658
- return ast;
11659
11543
  }
11660
- const handlerMini = ({ plugin }) => {
11661
- plugin.symbol("z", {
11662
- external: getZodModule({ plugin }),
11663
- importKind: "namespace",
11664
- meta: {
11665
- category: "external",
11666
- resource: "zod.z"
11667
- }
11668
- });
11669
- const processor = createProcessor$2(plugin);
11670
- plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
11671
- switch (event.type) {
11672
- case "operation":
11673
- irOperationToAst({
11674
- operation: event.operation,
11675
- path: event._path,
11676
- plugin,
11677
- processor,
11678
- tags: event.tags
11679
- });
11680
- break;
11681
- case "parameter":
11682
- processor.process({
11683
- meta: {
11684
- resource: "definition",
11685
- resourceId: pathToJsonPointer(event._path)
11686
- },
11687
- naming: plugin.config.definitions,
11688
- path: event._path,
11689
- plugin,
11690
- schema: event.parameter.schema,
11691
- tags: event.tags
11692
- });
11693
- break;
11694
- case "requestBody":
11695
- processor.process({
11696
- meta: {
11697
- resource: "definition",
11698
- resourceId: pathToJsonPointer(event._path)
11699
- },
11700
- naming: plugin.config.definitions,
11701
- path: event._path,
11702
- plugin,
11703
- schema: event.requestBody.schema,
11704
- tags: event.tags
11705
- });
11706
- break;
11707
- case "schema":
11708
- processor.process({
11709
- meta: {
11710
- resource: "definition",
11711
- resourceId: pathToJsonPointer(event._path)
11712
- },
11713
- naming: plugin.config.definitions,
11714
- path: event._path,
11715
- plugin,
11716
- schema: event.schema,
11717
- tags: event.tags
11718
- });
11719
- break;
11720
- case "webhook":
11721
- irWebhookToAst({
11722
- operation: event.operation,
11723
- path: event._path,
11724
- plugin,
11725
- processor,
11726
- tags: event.tags
11727
- });
11728
- break;
11729
- }
11730
- });
11731
- };
11732
11544
 
11733
11545
  //#endregion
11734
- //#region src/plugins/zod/v3/processor.ts
11735
- function createProcessor$1(plugin) {
11736
- const processor = createSchemaProcessor();
11737
- const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
11738
- function extractor(ctx$1) {
11739
- if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
11740
- for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
11741
- process$1({
11742
- namingAnchor: processor.context.anchor,
11743
- tags: processor.context.tags,
11744
- ...ctx$1
11546
+ //#region src/plugins/zod/mini/walker.ts
11547
+ function createVisitor$2(config) {
11548
+ const { schemaExtractor, state } = config;
11549
+ return {
11550
+ applyModifiers(result, ctx$1, options = {}) {
11551
+ const { optional } = options;
11552
+ const z = ctx$1.plugin.external("zod.z");
11553
+ let expression = result.expression.expression;
11554
+ if (result.readonly) expression = $(z).attr(identifiers.readonly).call(expression);
11555
+ const hasDefault = result.default !== void 0;
11556
+ const needsNullable = result.nullable;
11557
+ if (optional && needsNullable) expression = $(z).attr(identifiers.nullish).call(expression);
11558
+ else if (optional) expression = $(z).attr(identifiers.optional).call(expression);
11559
+ else if (needsNullable) expression = $(z).attr(identifiers.nullable).call(expression);
11560
+ if (hasDefault) expression = $(z).attr(identifiers._default).call(expression, result.format ? maybeBigInt(result.default, result.format) : $.fromValue(result.default));
11561
+ return { expression };
11562
+ },
11563
+ array(schema, ctx$1, walk) {
11564
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
11565
+ const ast = arrayToAst$2({
11566
+ ...ctx$1,
11567
+ applyModifiers,
11568
+ schema,
11569
+ state,
11570
+ walk
11745
11571
  });
11746
- return { $ref: pathToJsonPointer(ctx$1.path) };
11747
- }
11748
- return ctx$1.schema;
11749
- }
11750
- function process$1(ctx$1) {
11751
- if (!processor.markEmitted(ctx$1.path)) return;
11752
- processor.withContext({
11753
- anchor: ctx$1.namingAnchor,
11754
- tags: ctx$1.tags
11755
- }, () => {
11756
- const state = refs({
11757
- hasLazyExpression: false,
11758
- path: ctx$1.path,
11759
- tags: ctx$1.tags
11572
+ return {
11573
+ default: schema.default,
11574
+ expression: ast,
11575
+ hasLazyExpression: state.hasLazyExpression["~ref"],
11576
+ nullable: false,
11577
+ readonly: schema.accessScope === "read"
11578
+ };
11579
+ },
11580
+ boolean(schema, ctx$1) {
11581
+ const ast = booleanToAst$2({
11582
+ ...ctx$1,
11583
+ schema
11760
11584
  });
11761
- const ast = irSchemaToAst$1({
11762
- plugin,
11763
- schema: ctx$1.schema,
11764
- schemaExtractor: extractor,
11585
+ return {
11586
+ default: schema.default,
11587
+ expression: ast,
11588
+ nullable: false,
11589
+ readonly: schema.accessScope === "read"
11590
+ };
11591
+ },
11592
+ enum(schema, ctx$1) {
11593
+ const ast = enumToAst$2({
11594
+ ...ctx$1,
11595
+ schema,
11765
11596
  state
11766
11597
  });
11767
- exportAst({
11598
+ const hasNull = schema.items?.some((item) => item.type === "null" || item.const === null) ?? false;
11599
+ return {
11600
+ default: schema.default,
11601
+ expression: ast,
11602
+ nullable: hasNull,
11603
+ readonly: schema.accessScope === "read"
11604
+ };
11605
+ },
11606
+ integer(schema, ctx$1) {
11607
+ const ast = numberToNode$2({
11768
11608
  ...ctx$1,
11769
- ast,
11770
- plugin,
11609
+ schema,
11771
11610
  state
11772
11611
  });
11773
- });
11774
- }
11775
- return { process: process$1 };
11776
- }
11777
-
11778
- //#endregion
11779
- //#region src/plugins/zod/v3/toAst/unknown.ts
11780
- const unknownToAst$1 = ({ plugin }) => {
11781
- return $(plugin.external("zod.z")).attr(identifiers.unknown).call();
11612
+ return {
11613
+ default: schema.default,
11614
+ expression: ast,
11615
+ format: schema.format,
11616
+ nullable: false,
11617
+ readonly: schema.accessScope === "read"
11618
+ };
11619
+ },
11620
+ intercept(schema, ctx$1, walk) {
11621
+ if (schemaExtractor && !schema.$ref) {
11622
+ const extracted = schemaExtractor({
11623
+ meta: {
11624
+ resource: "definition",
11625
+ resourceId: pathToJsonPointer(fromRef(ctx$1.path))
11626
+ },
11627
+ naming: ctx$1.plugin.config.definitions,
11628
+ path: fromRef(ctx$1.path),
11629
+ plugin: ctx$1.plugin,
11630
+ schema
11631
+ });
11632
+ if (extracted !== schema) return walk(extracted, ctx$1);
11633
+ }
11634
+ },
11635
+ intersection(items, schemas, parentSchema, ctx$1) {
11636
+ const z = ctx$1.plugin.external("zod.z");
11637
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
11638
+ let expression = items[0].expression.expression;
11639
+ items.slice(1).forEach((item) => {
11640
+ expression = $(z).attr(identifiers.intersection).call(expression, item.hasLazyExpression ? $(z).attr(identifiers.lazy).call($.func().do(item.expression.expression.return())) : item.expression.expression);
11641
+ });
11642
+ return {
11643
+ default: parentSchema.default,
11644
+ expression: { expression },
11645
+ hasLazyExpression: hasAnyLazy,
11646
+ nullable: items.some((i) => i.nullable),
11647
+ readonly: items.some((i) => i.readonly)
11648
+ };
11649
+ },
11650
+ never(schema, ctx$1) {
11651
+ const ast = neverToAst$2({
11652
+ ...ctx$1,
11653
+ schema
11654
+ });
11655
+ return {
11656
+ default: schema.default,
11657
+ expression: ast,
11658
+ nullable: false,
11659
+ readonly: false
11660
+ };
11661
+ },
11662
+ null(schema, ctx$1) {
11663
+ const ast = nullToAst$2({
11664
+ ...ctx$1,
11665
+ schema
11666
+ });
11667
+ return {
11668
+ default: schema.default,
11669
+ expression: ast,
11670
+ nullable: false,
11671
+ readonly: false
11672
+ };
11673
+ },
11674
+ number(schema, ctx$1) {
11675
+ const ast = numberToNode$2({
11676
+ ...ctx$1,
11677
+ schema,
11678
+ state
11679
+ });
11680
+ return {
11681
+ default: schema.default,
11682
+ expression: ast,
11683
+ format: schema.format,
11684
+ nullable: false,
11685
+ readonly: schema.accessScope === "read"
11686
+ };
11687
+ },
11688
+ object(schema, ctx$1, walk) {
11689
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
11690
+ const ast = objectToAst$2({
11691
+ applyModifiers,
11692
+ plugin: ctx$1.plugin,
11693
+ schema,
11694
+ state,
11695
+ walk,
11696
+ walkerCtx: ctx$1
11697
+ });
11698
+ return {
11699
+ default: schema.default,
11700
+ expression: ast,
11701
+ hasLazyExpression: state.hasLazyExpression["~ref"],
11702
+ nullable: false,
11703
+ readonly: schema.accessScope === "read"
11704
+ };
11705
+ },
11706
+ postProcess(result, schema, ctx$1) {
11707
+ if (ctx$1.plugin.config.metadata && schema.description) {
11708
+ const z = ctx$1.plugin.external("zod.z");
11709
+ return {
11710
+ ...result,
11711
+ expression: { expression: result.expression.expression.attr(identifiers.register).call($(z).attr(identifiers.globalRegistry), $.object().pretty().prop("description", $.literal(schema.description))) }
11712
+ };
11713
+ }
11714
+ return result;
11715
+ },
11716
+ reference($ref, schema, ctx$1) {
11717
+ const z = ctx$1.plugin.external("zod.z");
11718
+ const query = {
11719
+ category: "schema",
11720
+ resource: "definition",
11721
+ resourceId: $ref,
11722
+ tool: "zod"
11723
+ };
11724
+ const refSymbol = ctx$1.plugin.referenceSymbol(query);
11725
+ if (ctx$1.plugin.isSymbolRegistered(query)) return {
11726
+ default: schema.default,
11727
+ expression: { expression: $(refSymbol) },
11728
+ nullable: false,
11729
+ readonly: schema.accessScope === "read"
11730
+ };
11731
+ state.hasLazyExpression["~ref"] = true;
11732
+ return {
11733
+ default: schema.default,
11734
+ expression: { expression: $(z).attr(identifiers.lazy).call($.func().returns("any").do($(refSymbol).return())) },
11735
+ hasLazyExpression: true,
11736
+ nullable: false,
11737
+ readonly: schema.accessScope === "read"
11738
+ };
11739
+ },
11740
+ string(schema, ctx$1) {
11741
+ if (shouldCoerceToBigInt(schema.format)) {
11742
+ const ast$1 = numberToNode$2({
11743
+ plugin: ctx$1.plugin,
11744
+ schema: {
11745
+ ...schema,
11746
+ type: "number"
11747
+ },
11748
+ state
11749
+ });
11750
+ return {
11751
+ default: schema.default,
11752
+ expression: ast$1,
11753
+ nullable: false,
11754
+ readonly: schema.accessScope === "read"
11755
+ };
11756
+ }
11757
+ const ast = stringToNode$2({
11758
+ ...ctx$1,
11759
+ schema
11760
+ });
11761
+ return {
11762
+ default: schema.default,
11763
+ expression: ast,
11764
+ nullable: false,
11765
+ readonly: schema.accessScope === "read"
11766
+ };
11767
+ },
11768
+ tuple(schema, ctx$1, walk) {
11769
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
11770
+ const ast = tupleToAst$2({
11771
+ ...ctx$1,
11772
+ applyModifiers,
11773
+ schema,
11774
+ state,
11775
+ walk
11776
+ });
11777
+ return {
11778
+ default: schema.default,
11779
+ expression: ast,
11780
+ hasLazyExpression: state.hasLazyExpression["~ref"],
11781
+ nullable: false,
11782
+ readonly: schema.accessScope === "read"
11783
+ };
11784
+ },
11785
+ undefined(schema, ctx$1) {
11786
+ const ast = undefinedToAst$2({
11787
+ ...ctx$1,
11788
+ schema
11789
+ });
11790
+ return {
11791
+ default: schema.default,
11792
+ expression: ast,
11793
+ nullable: false,
11794
+ readonly: false
11795
+ };
11796
+ },
11797
+ union(items, schemas, parentSchema, ctx$1) {
11798
+ const z = ctx$1.plugin.external("zod.z");
11799
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
11800
+ const hasNull = schemas.some((s) => s.type === "null") || items.some((i) => i.nullable);
11801
+ const nonNullItems = [];
11802
+ items.forEach((item, index) => {
11803
+ if (schemas[index].type !== "null") nonNullItems.push(item);
11804
+ });
11805
+ let expression;
11806
+ if (nonNullItems.length === 0) expression = { expression: $(z).attr(identifiers.null).call() };
11807
+ else if (nonNullItems.length === 1) expression = nonNullItems[0].expression;
11808
+ else expression = { expression: $(z).attr(identifiers.union).call($.array().pretty().elements(...nonNullItems.map((item) => item.expression.expression))) };
11809
+ return {
11810
+ default: parentSchema.default,
11811
+ expression,
11812
+ hasLazyExpression: hasAnyLazy,
11813
+ nullable: hasNull,
11814
+ readonly: items.some((i) => i.readonly)
11815
+ };
11816
+ },
11817
+ unknown(schema, ctx$1) {
11818
+ const ast = unknownToAst$2({
11819
+ ...ctx$1,
11820
+ schema
11821
+ });
11822
+ return {
11823
+ default: schema.default,
11824
+ expression: ast,
11825
+ nullable: false,
11826
+ readonly: false
11827
+ };
11828
+ },
11829
+ void(schema, ctx$1) {
11830
+ const ast = voidToAst$2({
11831
+ ...ctx$1,
11832
+ schema
11833
+ });
11834
+ return {
11835
+ default: schema.default,
11836
+ expression: ast,
11837
+ nullable: false,
11838
+ readonly: false
11839
+ };
11840
+ }
11841
+ };
11842
+ }
11843
+
11844
+ //#endregion
11845
+ //#region src/plugins/zod/mini/processor.ts
11846
+ function createProcessor$2(plugin) {
11847
+ const processor = createSchemaProcessor();
11848
+ const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
11849
+ function extractor(ctx$1) {
11850
+ if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
11851
+ for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
11852
+ process$1({
11853
+ namingAnchor: processor.context.anchor,
11854
+ tags: processor.context.tags,
11855
+ ...ctx$1
11856
+ });
11857
+ return { $ref: pathToJsonPointer(ctx$1.path) };
11858
+ }
11859
+ return ctx$1.schema;
11860
+ }
11861
+ function process$1(ctx$1) {
11862
+ if (!processor.markEmitted(ctx$1.path)) return;
11863
+ processor.withContext({
11864
+ anchor: ctx$1.namingAnchor,
11865
+ tags: ctx$1.tags
11866
+ }, () => {
11867
+ const state = refs({
11868
+ hasLazyExpression: false,
11869
+ path: ctx$1.path,
11870
+ tags: ctx$1.tags
11871
+ });
11872
+ const visitor = createVisitor$2({
11873
+ schemaExtractor: extractor,
11874
+ state
11875
+ });
11876
+ const result = createSchemaWalker(visitor)(ctx$1.schema, {
11877
+ path: ref(ctx$1.path),
11878
+ plugin
11879
+ });
11880
+ const ast = visitor.applyModifiers(result, {
11881
+ path: ref(ctx$1.path),
11882
+ plugin
11883
+ }) ?? result.expression;
11884
+ if (result.hasLazyExpression) state.hasLazyExpression["~ref"] = true;
11885
+ exportAst({
11886
+ ...ctx$1,
11887
+ ast,
11888
+ plugin,
11889
+ state
11890
+ });
11891
+ });
11892
+ }
11893
+ return { process: process$1 };
11894
+ }
11895
+
11896
+ //#endregion
11897
+ //#region src/plugins/zod/mini/plugin.ts
11898
+ const handlerMini = ({ plugin }) => {
11899
+ plugin.symbol("z", {
11900
+ external: getZodModule({ plugin }),
11901
+ importKind: "namespace",
11902
+ meta: {
11903
+ category: "external",
11904
+ resource: "zod.z"
11905
+ }
11906
+ });
11907
+ const processor = createProcessor$2(plugin);
11908
+ plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
11909
+ switch (event.type) {
11910
+ case "operation":
11911
+ irOperationToAst({
11912
+ operation: event.operation,
11913
+ path: event._path,
11914
+ plugin,
11915
+ processor,
11916
+ tags: event.tags
11917
+ });
11918
+ break;
11919
+ case "parameter":
11920
+ processor.process({
11921
+ meta: {
11922
+ resource: "definition",
11923
+ resourceId: pathToJsonPointer(event._path)
11924
+ },
11925
+ naming: plugin.config.definitions,
11926
+ path: event._path,
11927
+ plugin,
11928
+ schema: event.parameter.schema,
11929
+ tags: event.tags
11930
+ });
11931
+ break;
11932
+ case "requestBody":
11933
+ processor.process({
11934
+ meta: {
11935
+ resource: "definition",
11936
+ resourceId: pathToJsonPointer(event._path)
11937
+ },
11938
+ naming: plugin.config.definitions,
11939
+ path: event._path,
11940
+ plugin,
11941
+ schema: event.requestBody.schema,
11942
+ tags: event.tags
11943
+ });
11944
+ break;
11945
+ case "schema":
11946
+ processor.process({
11947
+ meta: {
11948
+ resource: "definition",
11949
+ resourceId: pathToJsonPointer(event._path)
11950
+ },
11951
+ naming: plugin.config.definitions,
11952
+ path: event._path,
11953
+ plugin,
11954
+ schema: event.schema,
11955
+ tags: event.tags
11956
+ });
11957
+ break;
11958
+ case "webhook":
11959
+ irWebhookToAst({
11960
+ operation: event.operation,
11961
+ path: event._path,
11962
+ plugin,
11963
+ processor,
11964
+ tags: event.tags
11965
+ });
11966
+ break;
11967
+ }
11968
+ });
11782
11969
  };
11783
11970
 
11971
+ //#endregion
11972
+ //#region src/plugins/zod/v3/toAst/unknown.ts
11973
+ function unknownToAst$1({ plugin }) {
11974
+ return $(plugin.external("zod.z")).attr(identifiers.unknown).call();
11975
+ }
11976
+
11784
11977
  //#endregion
11785
11978
  //#region src/plugins/zod/v3/toAst/array.ts
11786
- const arrayToAst$1 = ({ plugin, schema, state }) => {
11979
+ function arrayToAst$1(options) {
11980
+ const { applyModifiers, plugin, walk } = options;
11981
+ let { schema } = options;
11787
11982
  const z = plugin.external("zod.z");
11788
11983
  const functionName = $(z).attr(identifiers.array);
11789
11984
  let arrayExpression;
11790
11985
  let hasLazyExpression = false;
11791
11986
  if (!schema.items) arrayExpression = functionName.call(unknownToAst$1({
11792
- plugin,
11793
- schema: { type: "unknown" },
11794
- state
11987
+ ...options,
11988
+ schema: { type: "unknown" }
11795
11989
  }));
11796
11990
  else {
11797
11991
  schema = deduplicateSchema({ schema });
11798
11992
  const itemExpressions = schema.items.map((item, index) => {
11799
- const itemAst = irSchemaToAst$1({
11800
- plugin,
11801
- schema: item,
11802
- state: {
11803
- ...state,
11804
- path: ref([
11805
- ...fromRef(state.path),
11806
- "items",
11807
- index
11808
- ])
11809
- }
11810
- });
11811
- if (itemAst.hasLazyExpression) hasLazyExpression = true;
11812
- return itemAst.expression;
11993
+ const itemResult = walk(item, childContext({
11994
+ path: options.state.path,
11995
+ plugin: options.plugin
11996
+ }, "items", index));
11997
+ if (itemResult.hasLazyExpression) hasLazyExpression = true;
11998
+ return applyModifiers(itemResult, { optional: false }).expression;
11813
11999
  });
11814
12000
  if (itemExpressions.length === 1) arrayExpression = functionName.call(...itemExpressions);
11815
12001
  else if (schema.logicalOperator === "and") {
@@ -11832,7 +12018,7 @@ const arrayToAst$1 = ({ plugin, schema, state }) => {
11832
12018
  expression: arrayExpression,
11833
12019
  hasLazyExpression
11834
12020
  };
11835
- };
12021
+ }
11836
12022
 
11837
12023
  //#endregion
11838
12024
  //#region src/plugins/zod/v3/toAst/boolean.ts
@@ -11884,30 +12070,21 @@ function baseNode$7(ctx$1) {
11884
12070
  else if (literalMembers.length === 1) return literalMembers[0];
11885
12071
  else return $(z).attr(identifiers.union).call($.array(...literalMembers));
11886
12072
  }
11887
- function nullableNode$1(ctx$1) {
11888
- const { chain } = ctx$1;
11889
- const { isNullable } = ctx$1.nodes.items(ctx$1);
11890
- if (!isNullable) return;
11891
- return chain.current.attr(identifiers.nullable).call();
11892
- }
11893
12073
  function enumResolver$1(ctx$1) {
11894
12074
  const { literalMembers } = ctx$1.nodes.items(ctx$1);
11895
12075
  if (!literalMembers.length) return ctx$1.chain.current;
11896
12076
  const baseExpression = ctx$1.nodes.base(ctx$1);
11897
12077
  ctx$1.chain.current = baseExpression;
11898
- const nullableExpression = ctx$1.nodes.nullable(ctx$1);
11899
- if (nullableExpression) ctx$1.chain.current = nullableExpression;
11900
12078
  return ctx$1.chain.current;
11901
12079
  }
11902
- const enumToAst$1 = ({ plugin, schema, state }) => {
12080
+ function enumToAst$1({ plugin, schema, state }) {
11903
12081
  const z = plugin.external("zod.z");
11904
12082
  const { literalMembers } = itemsNode$1({
11905
12083
  $,
11906
12084
  chain: { current: $(z) },
11907
12085
  nodes: {
11908
12086
  base: baseNode$7,
11909
- items: itemsNode$1,
11910
- nullable: nullableNode$1
12087
+ items: itemsNode$1
11911
12088
  },
11912
12089
  plugin,
11913
12090
  schema,
@@ -11919,16 +12096,14 @@ const enumToAst$1 = ({ plugin, schema, state }) => {
11919
12096
  });
11920
12097
  if (!literalMembers.length) return unknownToAst$1({
11921
12098
  plugin,
11922
- schema: { type: "unknown" },
11923
- state
12099
+ schema: { type: "unknown" }
11924
12100
  });
11925
12101
  const ctx$1 = {
11926
12102
  $,
11927
12103
  chain: { current: $(z) },
11928
12104
  nodes: {
11929
12105
  base: baseNode$7,
11930
- items: itemsNode$1,
11931
- nullable: nullableNode$1
12106
+ items: itemsNode$1
11932
12107
  },
11933
12108
  plugin,
11934
12109
  schema,
@@ -11940,19 +12115,19 @@ const enumToAst$1 = ({ plugin, schema, state }) => {
11940
12115
  };
11941
12116
  const resolver = plugin.config["~resolvers"]?.enum;
11942
12117
  return resolver?.(ctx$1) ?? enumResolver$1(ctx$1);
11943
- };
12118
+ }
11944
12119
 
11945
12120
  //#endregion
11946
12121
  //#region src/plugins/zod/v3/toAst/never.ts
11947
- const neverToAst$1 = ({ plugin }) => {
12122
+ function neverToAst$1({ plugin }) {
11948
12123
  return $(plugin.external("zod.z")).attr(identifiers.never).call();
11949
- };
12124
+ }
11950
12125
 
11951
12126
  //#endregion
11952
12127
  //#region src/plugins/zod/v3/toAst/null.ts
11953
- const nullToAst$1 = ({ plugin }) => {
12128
+ function nullToAst$1({ plugin }) {
11954
12129
  return $(plugin.external("zod.z")).attr(identifiers.null).call();
11955
- };
12130
+ }
11956
12131
 
11957
12132
  //#endregion
11958
12133
  //#region src/plugins/zod/v3/toAst/number.ts
@@ -11998,7 +12173,7 @@ function numberResolver$1(ctx$1) {
11998
12173
  if (maxNode$4) ctx$1.chain.current = maxNode$4;
11999
12174
  return ctx$1.chain.current;
12000
12175
  }
12001
- const numberToNode$1 = ({ plugin, schema, state }) => {
12176
+ function numberToNode$1({ plugin, schema, state }) {
12002
12177
  const ast = {};
12003
12178
  const z = plugin.external("zod.z");
12004
12179
  const ctx$1 = {
@@ -12023,23 +12198,16 @@ const numberToNode$1 = ({ plugin, schema, state }) => {
12023
12198
  };
12024
12199
  const resolver = plugin.config["~resolvers"]?.number;
12025
12200
  return resolver?.(ctx$1) ?? numberResolver$1(ctx$1);
12026
- };
12201
+ }
12027
12202
 
12028
12203
  //#endregion
12029
12204
  //#region src/plugins/zod/v3/toAst/object.ts
12030
12205
  function additionalPropertiesNode$1(ctx$1) {
12031
- const { plugin, schema } = ctx$1;
12206
+ const { schema, walk, walkerCtx } = ctx$1;
12032
12207
  if (!schema.additionalProperties || schema.properties && Object.keys(schema.properties).length > 0) return;
12033
- const additionalAst = irSchemaToAst$1({
12034
- plugin,
12035
- schema: schema.additionalProperties,
12036
- state: {
12037
- ...ctx$1.utils.state,
12038
- path: ref([...fromRef(ctx$1.utils.state.path), "additionalProperties"])
12039
- }
12040
- });
12041
- if (additionalAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12042
- return additionalAst.expression;
12208
+ const additionalResult = walk(schema.additionalProperties, childContext(walkerCtx, "additionalProperties"));
12209
+ if (additionalResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12210
+ return additionalResult.expression.expression;
12043
12211
  }
12044
12212
  function baseNode$5(ctx$1) {
12045
12213
  const { nodes, symbols } = ctx$1;
@@ -12053,32 +12221,25 @@ function objectResolver$1(ctx$1) {
12053
12221
  return ctx$1.nodes.base(ctx$1);
12054
12222
  }
12055
12223
  function shapeNode$1(ctx$1) {
12056
- const { plugin, schema } = ctx$1;
12224
+ const { applyModifiers, schema, walk, walkerCtx } = ctx$1;
12057
12225
  const shape = $.object().pretty();
12058
12226
  for (const name in schema.properties) {
12059
12227
  const property = schema.properties[name];
12060
- const propertyAst = irSchemaToAst$1({
12061
- optional: !schema.required?.includes(name),
12062
- plugin,
12063
- schema: property,
12064
- state: {
12065
- ...ctx$1.utils.state,
12066
- path: ref([
12067
- ...fromRef(ctx$1.utils.state.path),
12068
- "properties",
12069
- name
12070
- ])
12071
- }
12072
- });
12073
- if (propertyAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12074
- shape.prop(name, propertyAst.expression);
12228
+ const isOptional = !schema.required?.includes(name);
12229
+ const propertyResult = walk(property, childContext(walkerCtx, "properties", name));
12230
+ if (propertyResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12231
+ const ast = applyModifiers(propertyResult, { optional: isOptional });
12232
+ if (ast.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12233
+ shape.prop(name, ast.expression);
12075
12234
  }
12076
12235
  return shape;
12077
12236
  }
12078
- const objectToAst$1 = ({ plugin, schema, state }) => {
12237
+ function objectToAst$1(options) {
12238
+ const { plugin } = options;
12079
12239
  const ast = {};
12080
12240
  const z = plugin.external("zod.z");
12081
12241
  const ctx$1 = {
12242
+ ...options,
12082
12243
  $,
12083
12244
  chain: { current: $(z) },
12084
12245
  nodes: {
@@ -12087,20 +12248,19 @@ const objectToAst$1 = ({ plugin, schema, state }) => {
12087
12248
  shape: shapeNode$1
12088
12249
  },
12089
12250
  plugin,
12090
- schema,
12091
12251
  symbols: { z },
12092
12252
  utils: {
12093
12253
  ast,
12094
- state
12254
+ state: options.state
12095
12255
  }
12096
12256
  };
12097
12257
  const resolver = plugin.config["~resolvers"]?.object;
12098
12258
  ast.expression = resolver?.(ctx$1) ?? objectResolver$1(ctx$1);
12099
12259
  return {
12100
12260
  ...ast,
12101
- anyType: "AnyZodObject"
12261
+ anyType: identifiers.AnyZodObject
12102
12262
  };
12103
- };
12263
+ }
12104
12264
 
12105
12265
  //#endregion
12106
12266
  //#region src/plugins/zod/v3/toAst/string.ts
@@ -12172,7 +12332,7 @@ function stringResolver$1(ctx$1) {
12172
12332
  if (patternNode$4) ctx$1.chain.current = patternNode$4;
12173
12333
  return ctx$1.chain.current;
12174
12334
  }
12175
- const stringToNode$1 = ({ plugin, schema }) => {
12335
+ function stringToNode$1({ plugin, schema }) {
12176
12336
  const z = plugin.external("zod.z");
12177
12337
  const ctx$1 = {
12178
12338
  $,
@@ -12192,11 +12352,12 @@ const stringToNode$1 = ({ plugin, schema }) => {
12192
12352
  };
12193
12353
  const resolver = plugin.config["~resolvers"]?.string;
12194
12354
  return resolver?.(ctx$1) ?? stringResolver$1(ctx$1);
12195
- };
12355
+ }
12196
12356
 
12197
12357
  //#endregion
12198
12358
  //#region src/plugins/zod/v3/toAst/tuple.ts
12199
- const tupleToAst$1 = ({ plugin, schema, state }) => {
12359
+ function tupleToAst$1(options) {
12360
+ const { applyModifiers, plugin, schema, walk } = options;
12200
12361
  const z = plugin.external("zod.z");
12201
12362
  let hasLazyExpression = false;
12202
12363
  if (schema.const && Array.isArray(schema.const)) {
@@ -12208,193 +12369,391 @@ const tupleToAst$1 = ({ plugin, schema, state }) => {
12208
12369
  }
12209
12370
  const tupleElements = [];
12210
12371
  if (schema.items) schema.items.forEach((item, index) => {
12211
- const itemSchema = irSchemaToAst$1({
12212
- plugin,
12213
- schema: item,
12214
- state: {
12215
- ...state,
12216
- path: ref([
12217
- ...fromRef(state.path),
12218
- "items",
12219
- index
12220
- ])
12221
- }
12222
- });
12223
- tupleElements.push(itemSchema.expression);
12224
- if (itemSchema.hasLazyExpression) hasLazyExpression = true;
12372
+ const itemResult = walk(item, childContext({
12373
+ path: options.state.path,
12374
+ plugin: options.plugin
12375
+ }, "items", index));
12376
+ if (itemResult.hasLazyExpression) hasLazyExpression = true;
12377
+ const finalExpr = applyModifiers(itemResult, { optional: false });
12378
+ tupleElements.push(finalExpr.expression);
12225
12379
  });
12226
12380
  return {
12227
12381
  expression: $(z).attr(identifiers.tuple).call($.array(...tupleElements)),
12228
12382
  hasLazyExpression
12229
12383
  };
12230
- };
12384
+ }
12231
12385
 
12232
12386
  //#endregion
12233
12387
  //#region src/plugins/zod/v3/toAst/undefined.ts
12234
- const undefinedToAst$1 = ({ plugin }) => {
12388
+ function undefinedToAst$1({ plugin }) {
12235
12389
  return $(plugin.external("zod.z")).attr(identifiers.undefined).call();
12236
- };
12390
+ }
12237
12391
 
12238
12392
  //#endregion
12239
12393
  //#region src/plugins/zod/v3/toAst/void.ts
12240
- const voidToAst$1 = ({ plugin }) => {
12394
+ function voidToAst$1({ plugin }) {
12241
12395
  return $(plugin.external("zod.z")).attr(identifiers.void).call();
12242
- };
12396
+ }
12243
12397
 
12244
12398
  //#endregion
12245
- //#region src/plugins/zod/v3/toAst/index.ts
12246
- function irSchemaWithTypeToAst$1({ schema, ...args }) {
12247
- switch (schema.type) {
12248
- case "array": return arrayToAst$1({
12249
- ...args,
12250
- schema
12251
- });
12252
- case "boolean": return { expression: booleanToAst$1({
12253
- ...args,
12254
- schema
12255
- }) };
12256
- case "enum": return { expression: enumToAst$1({
12257
- ...args,
12258
- schema
12259
- }) };
12260
- case "integer":
12261
- case "number": return { expression: numberToNode$1({
12262
- ...args,
12263
- schema
12264
- }) };
12265
- case "never": return { expression: neverToAst$1({
12266
- ...args,
12267
- schema
12268
- }) };
12269
- case "null": return { expression: nullToAst$1({
12270
- ...args,
12271
- schema
12272
- }) };
12273
- case "object": return objectToAst$1({
12274
- ...args,
12275
- schema
12276
- });
12277
- case "string": return { expression: shouldCoerceToBigInt(schema.format) ? numberToNode$1({
12278
- ...args,
12279
- schema: {
12280
- ...schema,
12281
- type: "number"
12399
+ //#region src/plugins/zod/v3/walker.ts
12400
+ function createVisitor$1(config) {
12401
+ const { schemaExtractor, state } = config;
12402
+ return {
12403
+ applyModifiers(result, ctx$1, options = {}) {
12404
+ const { optional } = options;
12405
+ let expression = result.expression.expression;
12406
+ if (result.readonly) expression = expression.attr(identifiers.readonly).call();
12407
+ const hasDefault = result.default !== void 0;
12408
+ const needsNullable = result.nullable;
12409
+ if (optional && needsNullable) expression = expression.attr(identifiers.nullish).call();
12410
+ else if (optional) expression = expression.attr(identifiers.optional).call();
12411
+ else if (needsNullable) expression = expression.attr(identifiers.nullable).call();
12412
+ if (hasDefault) expression = expression.attr(identifiers.default).call(result.format ? maybeBigInt(result.default, result.format) : $.fromValue(result.default));
12413
+ return { expression };
12414
+ },
12415
+ array(schema, ctx$1, walk) {
12416
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
12417
+ const ast = arrayToAst$1({
12418
+ ...ctx$1,
12419
+ applyModifiers,
12420
+ schema,
12421
+ state,
12422
+ walk
12423
+ });
12424
+ return {
12425
+ default: schema.default,
12426
+ expression: ast,
12427
+ hasLazyExpression: state.hasLazyExpression["~ref"],
12428
+ nullable: false,
12429
+ readonly: schema.accessScope === "read"
12430
+ };
12431
+ },
12432
+ boolean(schema, ctx$1) {
12433
+ const ast = booleanToAst$1({
12434
+ ...ctx$1,
12435
+ schema
12436
+ });
12437
+ return {
12438
+ default: schema.default,
12439
+ expression: { expression: ast },
12440
+ nullable: false,
12441
+ readonly: schema.accessScope === "read"
12442
+ };
12443
+ },
12444
+ enum(schema, ctx$1) {
12445
+ const ast = enumToAst$1({
12446
+ ...ctx$1,
12447
+ schema,
12448
+ state
12449
+ });
12450
+ const hasNull = schema.items?.some((item) => item.type === "null" || item.const === null) ?? false;
12451
+ return {
12452
+ default: schema.default,
12453
+ expression: { expression: ast },
12454
+ nullable: hasNull,
12455
+ readonly: schema.accessScope === "read"
12456
+ };
12457
+ },
12458
+ integer(schema, ctx$1) {
12459
+ const ast = numberToNode$1({
12460
+ ...ctx$1,
12461
+ schema,
12462
+ state
12463
+ });
12464
+ return {
12465
+ default: schema.default,
12466
+ expression: { expression: ast },
12467
+ format: schema.format,
12468
+ nullable: false,
12469
+ readonly: schema.accessScope === "read"
12470
+ };
12471
+ },
12472
+ intercept(schema, ctx$1, walk) {
12473
+ if (schemaExtractor && !schema.$ref) {
12474
+ const extracted = schemaExtractor({
12475
+ meta: {
12476
+ resource: "definition",
12477
+ resourceId: pathToJsonPointer(fromRef(ctx$1.path))
12478
+ },
12479
+ naming: ctx$1.plugin.config.definitions,
12480
+ path: fromRef(ctx$1.path),
12481
+ plugin: ctx$1.plugin,
12482
+ schema
12483
+ });
12484
+ if (extracted !== schema) return walk(extracted, ctx$1);
12282
12485
  }
12283
- }) : stringToNode$1({
12284
- ...args,
12285
- schema
12286
- }) };
12287
- case "tuple": return tupleToAst$1({
12288
- ...args,
12289
- schema
12290
- });
12291
- case "undefined": return { expression: undefinedToAst$1({
12292
- ...args,
12293
- schema
12294
- }) };
12295
- case "unknown": return { expression: unknownToAst$1({
12296
- ...args,
12297
- schema
12298
- }) };
12299
- case "void": return { expression: voidToAst$1({
12300
- ...args,
12301
- schema
12302
- }) };
12303
- }
12486
+ },
12487
+ intersection(items, schemas, parentSchema, ctx$1) {
12488
+ const z = ctx$1.plugin.external("zod.z");
12489
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
12490
+ if (hasAnyLazy) state.anyType = ref(identifiers.ZodTypeAny);
12491
+ const firstSchema = schemas[0];
12492
+ let expression;
12493
+ if (firstSchema?.logicalOperator === "or" || firstSchema?.type && firstSchema.type !== "object") expression = { expression: $(z).attr(identifiers.intersection).call(...items.map((item) => item.expression.expression)) };
12494
+ else {
12495
+ expression = items[0].expression;
12496
+ items.slice(1).forEach((item) => {
12497
+ expression = { expression: expression.expression.attr(identifiers.and).call(item.hasLazyExpression && !item.isLazy ? $(z).attr(identifiers.lazy).call($.func().do(item.expression.expression.return())) : item.expression.expression) };
12498
+ });
12499
+ }
12500
+ return {
12501
+ default: parentSchema.default,
12502
+ expression,
12503
+ hasLazyExpression: hasAnyLazy,
12504
+ nullable: items.some((i) => i.nullable),
12505
+ readonly: items.some((i) => i.readonly)
12506
+ };
12507
+ },
12508
+ never(schema, ctx$1) {
12509
+ const ast = neverToAst$1({
12510
+ ...ctx$1,
12511
+ schema
12512
+ });
12513
+ return {
12514
+ default: schema.default,
12515
+ expression: { expression: ast },
12516
+ nullable: false,
12517
+ readonly: false
12518
+ };
12519
+ },
12520
+ null(schema, ctx$1) {
12521
+ const ast = nullToAst$1({
12522
+ ...ctx$1,
12523
+ schema
12524
+ });
12525
+ return {
12526
+ default: schema.default,
12527
+ expression: { expression: ast },
12528
+ nullable: false,
12529
+ readonly: false
12530
+ };
12531
+ },
12532
+ number(schema, ctx$1) {
12533
+ const ast = numberToNode$1({
12534
+ ...ctx$1,
12535
+ schema,
12536
+ state
12537
+ });
12538
+ return {
12539
+ default: schema.default,
12540
+ expression: { expression: ast },
12541
+ format: schema.format,
12542
+ nullable: false,
12543
+ readonly: schema.accessScope === "read"
12544
+ };
12545
+ },
12546
+ object(schema, ctx$1, walk) {
12547
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
12548
+ const ast = objectToAst$1({
12549
+ applyModifiers,
12550
+ plugin: ctx$1.plugin,
12551
+ schema,
12552
+ state,
12553
+ walk,
12554
+ walkerCtx: ctx$1
12555
+ });
12556
+ if (state.hasLazyExpression["~ref"] && ast.anyType) state.anyType = ref(ast.anyType);
12557
+ return {
12558
+ default: schema.default,
12559
+ expression: ast,
12560
+ hasLazyExpression: state.hasLazyExpression["~ref"],
12561
+ nullable: false,
12562
+ readonly: schema.accessScope === "read"
12563
+ };
12564
+ },
12565
+ postProcess(result, schema, ctx$1) {
12566
+ if (ctx$1.plugin.config.metadata && schema.description) return {
12567
+ ...result,
12568
+ expression: { expression: result.expression.expression.attr(identifiers.describe).call($.literal(schema.description)) }
12569
+ };
12570
+ return result;
12571
+ },
12572
+ reference($ref, schema, ctx$1) {
12573
+ const z = ctx$1.plugin.external("zod.z");
12574
+ const query = {
12575
+ category: "schema",
12576
+ resource: "definition",
12577
+ resourceId: $ref,
12578
+ tool: "zod"
12579
+ };
12580
+ const refSymbol = ctx$1.plugin.referenceSymbol(query);
12581
+ if (ctx$1.plugin.isSymbolRegistered(query)) return {
12582
+ default: schema.default,
12583
+ expression: { expression: $(refSymbol) },
12584
+ nullable: false,
12585
+ readonly: schema.accessScope === "read"
12586
+ };
12587
+ state.hasLazyExpression["~ref"] = true;
12588
+ state.anyType = ref(identifiers.ZodTypeAny);
12589
+ return {
12590
+ default: schema.default,
12591
+ expression: { expression: $(z).attr(identifiers.lazy).call($.func().do($(refSymbol).return())) },
12592
+ hasLazyExpression: true,
12593
+ isLazy: true,
12594
+ nullable: false,
12595
+ readonly: schema.accessScope === "read"
12596
+ };
12597
+ },
12598
+ string(schema, ctx$1) {
12599
+ if (shouldCoerceToBigInt(schema.format)) {
12600
+ const ast$1 = numberToNode$1({
12601
+ plugin: ctx$1.plugin,
12602
+ schema: {
12603
+ ...schema,
12604
+ type: "number"
12605
+ },
12606
+ state
12607
+ });
12608
+ return {
12609
+ default: schema.default,
12610
+ expression: { expression: ast$1 },
12611
+ nullable: false,
12612
+ readonly: schema.accessScope === "read"
12613
+ };
12614
+ }
12615
+ const ast = stringToNode$1({
12616
+ ...ctx$1,
12617
+ schema
12618
+ });
12619
+ return {
12620
+ default: schema.default,
12621
+ expression: { expression: ast },
12622
+ nullable: false,
12623
+ readonly: schema.accessScope === "read"
12624
+ };
12625
+ },
12626
+ tuple(schema, ctx$1, walk) {
12627
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
12628
+ const ast = tupleToAst$1({
12629
+ ...ctx$1,
12630
+ applyModifiers,
12631
+ schema,
12632
+ state,
12633
+ walk
12634
+ });
12635
+ return {
12636
+ default: schema.default,
12637
+ expression: ast,
12638
+ hasLazyExpression: state.hasLazyExpression["~ref"],
12639
+ nullable: false,
12640
+ readonly: schema.accessScope === "read"
12641
+ };
12642
+ },
12643
+ undefined(schema, ctx$1) {
12644
+ const ast = undefinedToAst$1({
12645
+ ...ctx$1,
12646
+ schema
12647
+ });
12648
+ return {
12649
+ default: schema.default,
12650
+ expression: { expression: ast },
12651
+ nullable: false,
12652
+ readonly: false
12653
+ };
12654
+ },
12655
+ union(items, schemas, parentSchema, ctx$1) {
12656
+ const z = ctx$1.plugin.external("zod.z");
12657
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
12658
+ const hasNull = schemas.some((s) => s.type === "null") || items.some((i) => i.nullable);
12659
+ if (hasAnyLazy) state.anyType = ref(identifiers.ZodTypeAny);
12660
+ const nonNullItems = [];
12661
+ items.forEach((item, index) => {
12662
+ if (schemas[index].type !== "null") nonNullItems.push(item);
12663
+ });
12664
+ let expression;
12665
+ if (nonNullItems.length === 0) expression = { expression: $(z).attr(identifiers.null).call() };
12666
+ else if (nonNullItems.length === 1) expression = nonNullItems[0].expression;
12667
+ else expression = { expression: $(z).attr(identifiers.union).call($.array().pretty().elements(...nonNullItems.map((item) => item.expression.expression))) };
12668
+ return {
12669
+ default: parentSchema.default,
12670
+ expression,
12671
+ hasLazyExpression: hasAnyLazy,
12672
+ nullable: hasNull,
12673
+ readonly: items.some((i) => i.readonly)
12674
+ };
12675
+ },
12676
+ unknown(schema, ctx$1) {
12677
+ const ast = unknownToAst$1({
12678
+ ...ctx$1,
12679
+ schema
12680
+ });
12681
+ return {
12682
+ default: schema.default,
12683
+ expression: { expression: ast },
12684
+ nullable: false,
12685
+ readonly: false
12686
+ };
12687
+ },
12688
+ void(schema, ctx$1) {
12689
+ const ast = voidToAst$1({
12690
+ ...ctx$1,
12691
+ schema
12692
+ });
12693
+ return {
12694
+ default: schema.default,
12695
+ expression: { expression: ast },
12696
+ nullable: false,
12697
+ readonly: false
12698
+ };
12699
+ }
12700
+ };
12304
12701
  }
12305
12702
 
12306
12703
  //#endregion
12307
- //#region src/plugins/zod/v3/plugin.ts
12308
- function irSchemaToAst$1({ optional, plugin, schema, schemaExtractor, state }) {
12309
- if (schemaExtractor && !schema.$ref) {
12310
- const extracted = schemaExtractor({
12311
- meta: {
12312
- resource: "definition",
12313
- resourceId: pathToJsonPointer(fromRef(state.path))
12314
- },
12315
- naming: plugin.config.definitions,
12316
- path: fromRef(state.path),
12317
- plugin,
12318
- schema
12319
- });
12320
- if (extracted !== schema) schema = extracted;
12321
- }
12322
- let ast = {};
12323
- const z = plugin.external("zod.z");
12324
- if (schema.$ref) {
12325
- const query = {
12326
- category: "schema",
12327
- resource: "definition",
12328
- resourceId: schema.$ref,
12329
- tool: "zod"
12330
- };
12331
- const refSymbol = plugin.referenceSymbol(query);
12332
- if (plugin.isSymbolRegistered(query)) ast.expression = $(refSymbol);
12333
- else {
12334
- ast.expression = $(z).attr(identifiers.lazy).call($.func().do($(refSymbol).return()));
12335
- ast.hasLazyExpression = true;
12336
- state.hasLazyExpression["~ref"] = true;
12704
+ //#region src/plugins/zod/v3/processor.ts
12705
+ function createProcessor$1(plugin) {
12706
+ const processor = createSchemaProcessor();
12707
+ const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
12708
+ function extractor(ctx$1) {
12709
+ if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
12710
+ for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
12711
+ process$1({
12712
+ namingAnchor: processor.context.anchor,
12713
+ tags: processor.context.tags,
12714
+ ...ctx$1
12715
+ });
12716
+ return { $ref: pathToJsonPointer(ctx$1.path) };
12337
12717
  }
12338
- } else if (schema.type) {
12339
- const typeAst = irSchemaWithTypeToAst$1({
12340
- plugin,
12341
- schema,
12342
- state
12343
- });
12344
- ast.expression = typeAst.expression;
12345
- ast.typeName = typeAst.anyType;
12346
- if (plugin.config.metadata && schema.description) ast.expression = ast.expression.attr(identifiers.describe).call($.literal(schema.description));
12347
- } else if (schema.items) {
12348
- schema = deduplicateSchema({ schema });
12349
- if (schema.items) {
12350
- const itemTypes = schema.items.map((item, index) => {
12351
- return irSchemaToAst$1({
12352
- plugin,
12353
- schema: item,
12354
- state: {
12355
- ...state,
12356
- path: ref([
12357
- ...fromRef(state.path),
12358
- "items",
12359
- index
12360
- ])
12361
- }
12362
- }).expression;
12718
+ return ctx$1.schema;
12719
+ }
12720
+ function process$1(ctx$1) {
12721
+ if (!processor.markEmitted(ctx$1.path)) return;
12722
+ processor.withContext({
12723
+ anchor: ctx$1.namingAnchor,
12724
+ tags: ctx$1.tags
12725
+ }, () => {
12726
+ const state = refs({
12727
+ hasLazyExpression: false,
12728
+ path: ctx$1.path,
12729
+ tags: ctx$1.tags
12730
+ });
12731
+ const visitor = createVisitor$1({
12732
+ schemaExtractor: extractor,
12733
+ state
12734
+ });
12735
+ const result = createSchemaWalker(visitor)(ctx$1.schema, {
12736
+ path: ref(ctx$1.path),
12737
+ plugin
12738
+ });
12739
+ const ast = visitor.applyModifiers(result, {
12740
+ path: ref(ctx$1.path),
12741
+ plugin
12742
+ }) ?? result.expression;
12743
+ if (result.hasLazyExpression) state.hasLazyExpression["~ref"] = true;
12744
+ exportAst({
12745
+ ...ctx$1,
12746
+ ast,
12747
+ plugin,
12748
+ state
12363
12749
  });
12364
- if (schema.logicalOperator === "and") {
12365
- const firstSchema = schema.items[0];
12366
- if (firstSchema.logicalOperator === "or" || firstSchema.type && firstSchema.type !== "object") ast.expression = $(z).attr(identifiers.intersection).call(...itemTypes);
12367
- else {
12368
- ast.expression = itemTypes[0];
12369
- itemTypes.slice(1).forEach((item) => {
12370
- ast.expression = ast.expression.attr(identifiers.and).call(item);
12371
- });
12372
- }
12373
- } else ast.expression = $(z).attr(identifiers.union).call($.array().pretty().elements(...itemTypes));
12374
- } else ast = irSchemaToAst$1({
12375
- plugin,
12376
- schema,
12377
- state
12378
- });
12379
- } else {
12380
- const typeAst = irSchemaWithTypeToAst$1({
12381
- plugin,
12382
- schema: { type: "unknown" },
12383
- state
12384
12750
  });
12385
- ast.expression = typeAst.expression;
12386
- ast.typeName = typeAst.anyType;
12387
- }
12388
- if (ast.expression) {
12389
- if (schema.accessScope === "read") ast.expression = ast.expression.attr(identifiers.readonly).call();
12390
- if (optional) ast.expression = ast.expression.attr(identifiers.optional).call();
12391
- if (schema.default !== void 0) ast.expression = ast.expression.attr(identifiers.default).call(schema.type === "integer" || schema.type === "number" ? maybeBigInt(schema.default, schema.format) : $.fromValue(schema.default));
12392
12751
  }
12393
- if (state.hasLazyExpression["~ref"]) {
12394
- if (!ast.typeName) ast.typeName = "ZodTypeAny";
12395
- } else if (ast.typeName) ast.typeName = void 0;
12396
- return ast;
12752
+ return { process: process$1 };
12397
12753
  }
12754
+
12755
+ //#endregion
12756
+ //#region src/plugins/zod/v3/plugin.ts
12398
12757
  const handlerV3 = ({ plugin }) => {
12399
12758
  plugin.symbol("z", {
12400
12759
  external: getZodModule({ plugin }),
@@ -12467,87 +12826,35 @@ const handlerV3 = ({ plugin }) => {
12467
12826
  });
12468
12827
  };
12469
12828
 
12470
- //#endregion
12471
- //#region src/plugins/zod/v4/processor.ts
12472
- function createProcessor(plugin) {
12473
- const processor = createSchemaProcessor();
12474
- const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
12475
- function extractor(ctx$1) {
12476
- if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
12477
- for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
12478
- process$1({
12479
- namingAnchor: processor.context.anchor,
12480
- tags: processor.context.tags,
12481
- ...ctx$1
12482
- });
12483
- return { $ref: pathToJsonPointer(ctx$1.path) };
12484
- }
12485
- return ctx$1.schema;
12486
- }
12487
- function process$1(ctx$1) {
12488
- if (!processor.markEmitted(ctx$1.path)) return;
12489
- processor.withContext({
12490
- anchor: ctx$1.namingAnchor,
12491
- tags: ctx$1.tags
12492
- }, () => {
12493
- const state = refs({
12494
- hasLazyExpression: false,
12495
- path: ctx$1.path,
12496
- tags: ctx$1.tags
12497
- });
12498
- const ast = irSchemaToAst({
12499
- plugin,
12500
- schema: ctx$1.schema,
12501
- schemaExtractor: extractor,
12502
- state
12503
- });
12504
- exportAst({
12505
- ...ctx$1,
12506
- ast,
12507
- plugin,
12508
- state
12509
- });
12510
- });
12511
- }
12512
- return { process: process$1 };
12513
- }
12514
-
12515
12829
  //#endregion
12516
12830
  //#region src/plugins/zod/v4/toAst/unknown.ts
12517
- const unknownToAst = ({ plugin }) => {
12831
+ function unknownToAst({ plugin }) {
12518
12832
  const result = {};
12519
12833
  result.expression = $(plugin.external("zod.z")).attr(identifiers.unknown).call();
12520
12834
  return result;
12521
- };
12835
+ }
12522
12836
 
12523
12837
  //#endregion
12524
12838
  //#region src/plugins/zod/v4/toAst/array.ts
12525
- const arrayToAst = ({ plugin, schema, state }) => {
12839
+ function arrayToAst(options) {
12840
+ const { applyModifiers, plugin, walk } = options;
12841
+ let { schema } = options;
12526
12842
  const result = {};
12527
12843
  const z = plugin.external("zod.z");
12528
12844
  const functionName = $(z).attr(identifiers.array);
12529
12845
  if (!schema.items) result.expression = functionName.call(unknownToAst({
12530
- plugin,
12531
- schema: { type: "unknown" },
12532
- state
12846
+ ...options,
12847
+ schema: { type: "unknown" }
12533
12848
  }).expression);
12534
12849
  else {
12535
12850
  schema = deduplicateSchema({ schema });
12536
12851
  const itemExpressions = schema.items.map((item, index) => {
12537
- const itemAst = irSchemaToAst({
12538
- plugin,
12539
- schema: item,
12540
- state: {
12541
- ...state,
12542
- path: ref([
12543
- ...fromRef(state.path),
12544
- "items",
12545
- index
12546
- ])
12547
- }
12548
- });
12549
- if (itemAst.hasLazyExpression) result.hasLazyExpression = true;
12550
- return itemAst.expression;
12852
+ const itemResult = walk(item, childContext({
12853
+ path: options.state.path,
12854
+ plugin: options.plugin
12855
+ }, "items", index));
12856
+ if (itemResult.hasLazyExpression) result.hasLazyExpression = true;
12857
+ return applyModifiers(itemResult, { optional: false }).expression;
12551
12858
  });
12552
12859
  if (itemExpressions.length === 1) result.expression = functionName.call(...itemExpressions);
12553
12860
  else if (schema.logicalOperator === "and") {
@@ -12567,7 +12874,7 @@ const arrayToAst = ({ plugin, schema, state }) => {
12567
12874
  if (schema.maxItems !== void 0) result.expression = result.expression.attr(identifiers.max).call($.fromValue(schema.maxItems));
12568
12875
  }
12569
12876
  return result;
12570
- };
12877
+ }
12571
12878
 
12572
12879
  //#endregion
12573
12880
  //#region src/plugins/zod/v4/toAst/boolean.ts
@@ -12622,31 +12929,21 @@ function baseNode$3(ctx$1) {
12622
12929
  else if (literalMembers.length === 1) return literalMembers[0];
12623
12930
  else return $(z).attr(identifiers.union).call($.array(...literalMembers));
12624
12931
  }
12625
- function nullableNode(ctx$1) {
12626
- const { chain, symbols } = ctx$1;
12627
- const { z } = symbols;
12628
- const { isNullable } = ctx$1.nodes.items(ctx$1);
12629
- if (!isNullable) return;
12630
- return $(z).attr(identifiers.nullable).call(chain.current);
12631
- }
12632
12932
  function enumResolver(ctx$1) {
12633
12933
  const { literalMembers } = ctx$1.nodes.items(ctx$1);
12634
12934
  if (!literalMembers.length) return ctx$1.chain.current;
12635
12935
  const baseExpression = ctx$1.nodes.base(ctx$1);
12636
12936
  ctx$1.chain.current = baseExpression;
12637
- const nullableExpression = ctx$1.nodes.nullable(ctx$1);
12638
- if (nullableExpression) ctx$1.chain.current = nullableExpression;
12639
12937
  return ctx$1.chain.current;
12640
12938
  }
12641
- const enumToAst = ({ plugin, schema, state }) => {
12939
+ function enumToAst({ plugin, schema, state }) {
12642
12940
  const z = plugin.external("zod.z");
12643
12941
  const { literalMembers } = itemsNode({
12644
12942
  $,
12645
12943
  chain: { current: $(z) },
12646
12944
  nodes: {
12647
12945
  base: baseNode$3,
12648
- items: itemsNode,
12649
- nullable: nullableNode
12946
+ items: itemsNode
12650
12947
  },
12651
12948
  plugin,
12652
12949
  schema,
@@ -12658,16 +12955,14 @@ const enumToAst = ({ plugin, schema, state }) => {
12658
12955
  });
12659
12956
  if (!literalMembers.length) return unknownToAst({
12660
12957
  plugin,
12661
- schema: { type: "unknown" },
12662
- state
12958
+ schema: { type: "unknown" }
12663
12959
  });
12664
12960
  const ctx$1 = {
12665
12961
  $,
12666
12962
  chain: { current: $(z) },
12667
12963
  nodes: {
12668
12964
  base: baseNode$3,
12669
- items: itemsNode,
12670
- nullable: nullableNode
12965
+ items: itemsNode
12671
12966
  },
12672
12967
  plugin,
12673
12968
  schema,
@@ -12679,23 +12974,23 @@ const enumToAst = ({ plugin, schema, state }) => {
12679
12974
  };
12680
12975
  const resolver = plugin.config["~resolvers"]?.enum;
12681
12976
  return { expression: resolver?.(ctx$1) ?? enumResolver(ctx$1) };
12682
- };
12977
+ }
12683
12978
 
12684
12979
  //#endregion
12685
12980
  //#region src/plugins/zod/v4/toAst/never.ts
12686
- const neverToAst = ({ plugin }) => {
12981
+ function neverToAst({ plugin }) {
12687
12982
  const result = {};
12688
12983
  result.expression = $(plugin.external("zod.z")).attr(identifiers.never).call();
12689
12984
  return result;
12690
- };
12985
+ }
12691
12986
 
12692
12987
  //#endregion
12693
12988
  //#region src/plugins/zod/v4/toAst/null.ts
12694
- const nullToAst = ({ plugin }) => {
12989
+ function nullToAst({ plugin }) {
12695
12990
  const result = {};
12696
12991
  result.expression = $(plugin.external("zod.z")).attr(identifiers.null).call();
12697
12992
  return result;
12698
- };
12993
+ }
12699
12994
 
12700
12995
  //#endregion
12701
12996
  //#region src/plugins/zod/v4/toAst/number.ts
@@ -12741,7 +13036,7 @@ function numberResolver(ctx$1) {
12741
13036
  if (maxNode$4) ctx$1.chain.current = maxNode$4;
12742
13037
  return ctx$1.chain.current;
12743
13038
  }
12744
- const numberToNode = ({ plugin, schema, state }) => {
13039
+ function numberToNode({ plugin, schema, state }) {
12745
13040
  const ast = {};
12746
13041
  const z = plugin.external("zod.z");
12747
13042
  const ctx$1 = {
@@ -12767,23 +13062,16 @@ const numberToNode = ({ plugin, schema, state }) => {
12767
13062
  const resolver = plugin.config["~resolvers"]?.number;
12768
13063
  ast.expression = resolver?.(ctx$1) ?? numberResolver(ctx$1);
12769
13064
  return ast;
12770
- };
13065
+ }
12771
13066
 
12772
13067
  //#endregion
12773
13068
  //#region src/plugins/zod/v4/toAst/object.ts
12774
13069
  function additionalPropertiesNode(ctx$1) {
12775
- const { plugin, schema } = ctx$1;
13070
+ const { schema, walk, walkerCtx } = ctx$1;
12776
13071
  if (!schema.additionalProperties || schema.properties && Object.keys(schema.properties).length > 0) return;
12777
- const additionalAst = irSchemaToAst({
12778
- plugin,
12779
- schema: schema.additionalProperties,
12780
- state: {
12781
- ...ctx$1.utils.state,
12782
- path: ref([...fromRef(ctx$1.utils.state.path), "additionalProperties"])
12783
- }
12784
- });
12785
- if (additionalAst.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
12786
- return additionalAst.expression;
13072
+ const additionalResult = walk(schema.additionalProperties, childContext(walkerCtx, "additionalProperties"));
13073
+ if (additionalResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
13074
+ return additionalResult.expression.expression;
12787
13075
  }
12788
13076
  function baseNode$1(ctx$1) {
12789
13077
  const { nodes, symbols } = ctx$1;
@@ -12797,34 +13085,27 @@ function objectResolver(ctx$1) {
12797
13085
  return ctx$1.nodes.base(ctx$1);
12798
13086
  }
12799
13087
  function shapeNode(ctx$1) {
12800
- const { plugin, schema } = ctx$1;
13088
+ const { applyModifiers, schema, walk, walkerCtx } = ctx$1;
12801
13089
  const shape = $.object().pretty();
12802
13090
  for (const name in schema.properties) {
12803
13091
  const property = schema.properties[name];
12804
- const propertyAst = irSchemaToAst({
12805
- optional: !schema.required?.includes(name),
12806
- plugin,
12807
- schema: property,
12808
- state: {
12809
- ...ctx$1.utils.state,
12810
- path: ref([
12811
- ...fromRef(ctx$1.utils.state.path),
12812
- "properties",
12813
- name
12814
- ])
12815
- }
12816
- });
12817
- if (propertyAst.hasLazyExpression) {
13092
+ const isOptional = !schema.required?.includes(name);
13093
+ const propertyResult = walk(property, childContext(walkerCtx, "properties", name));
13094
+ if (propertyResult.hasLazyExpression) ctx$1.utils.ast.hasLazyExpression = true;
13095
+ const ast = applyModifiers(propertyResult, { optional: isOptional });
13096
+ if (ast.hasLazyExpression) {
12818
13097
  ctx$1.utils.ast.hasLazyExpression = true;
12819
- shape.getter(name, propertyAst.expression.return());
12820
- } else shape.prop(name, propertyAst.expression);
13098
+ shape.getter(name, ast.expression.return());
13099
+ } else shape.prop(name, ast.expression);
12821
13100
  }
12822
13101
  return shape;
12823
13102
  }
12824
- const objectToAst = ({ plugin, schema, state }) => {
13103
+ function objectToAst(options) {
13104
+ const { plugin } = options;
12825
13105
  const ast = {};
12826
13106
  const z = plugin.external("zod.z");
12827
13107
  const ctx$1 = {
13108
+ ...options,
12828
13109
  $,
12829
13110
  chain: { current: $(z) },
12830
13111
  nodes: {
@@ -12833,17 +13114,16 @@ const objectToAst = ({ plugin, schema, state }) => {
12833
13114
  shape: shapeNode
12834
13115
  },
12835
13116
  plugin,
12836
- schema,
12837
13117
  symbols: { z },
12838
13118
  utils: {
12839
13119
  ast,
12840
- state
13120
+ state: options.state
12841
13121
  }
12842
13122
  };
12843
13123
  const resolver = plugin.config["~resolvers"]?.object;
12844
13124
  ast.expression = resolver?.(ctx$1) ?? objectResolver(ctx$1);
12845
13125
  return ast;
12846
- };
13126
+ }
12847
13127
 
12848
13128
  //#endregion
12849
13129
  //#region src/plugins/zod/v4/toAst/string.ts
@@ -12916,7 +13196,7 @@ function stringResolver(ctx$1) {
12916
13196
  if (patternNode$4) ctx$1.chain.current = patternNode$4;
12917
13197
  return ctx$1.chain.current;
12918
13198
  }
12919
- const stringToNode = ({ plugin, schema }) => {
13199
+ function stringToNode({ plugin, schema }) {
12920
13200
  const z = plugin.external("zod.z");
12921
13201
  const ctx$1 = {
12922
13202
  $,
@@ -12936,11 +13216,12 @@ const stringToNode = ({ plugin, schema }) => {
12936
13216
  };
12937
13217
  const resolver = plugin.config["~resolvers"]?.string;
12938
13218
  return { expression: resolver?.(ctx$1) ?? stringResolver(ctx$1) };
12939
- };
13219
+ }
12940
13220
 
12941
13221
  //#endregion
12942
13222
  //#region src/plugins/zod/v4/toAst/tuple.ts
12943
- const tupleToAst = ({ plugin, schema, state }) => {
13223
+ function tupleToAst(options) {
13224
+ const { applyModifiers, plugin, schema, walk } = options;
12944
13225
  const result = {};
12945
13226
  const z = plugin.external("zod.z");
12946
13227
  if (schema.const && Array.isArray(schema.const)) {
@@ -12950,192 +13231,391 @@ const tupleToAst = ({ plugin, schema, state }) => {
12950
13231
  }
12951
13232
  const tupleElements = [];
12952
13233
  if (schema.items) schema.items.forEach((item, index) => {
12953
- const itemSchema = irSchemaToAst({
12954
- plugin,
12955
- schema: item,
12956
- state: {
12957
- ...state,
12958
- path: ref([
12959
- ...fromRef(state.path),
12960
- "items",
12961
- index
12962
- ])
12963
- }
12964
- });
12965
- tupleElements.push(itemSchema.expression);
12966
- if (itemSchema.hasLazyExpression) result.hasLazyExpression = true;
13234
+ const itemResult = walk(item, childContext({
13235
+ path: options.state.path,
13236
+ plugin: options.plugin
13237
+ }, "items", index));
13238
+ if (itemResult.hasLazyExpression) result.hasLazyExpression = true;
13239
+ const finalExpr = applyModifiers(itemResult, { optional: false });
13240
+ tupleElements.push(finalExpr.expression);
12967
13241
  });
12968
13242
  result.expression = $(z).attr(identifiers.tuple).call($.array(...tupleElements));
12969
13243
  return result;
12970
- };
13244
+ }
12971
13245
 
12972
13246
  //#endregion
12973
13247
  //#region src/plugins/zod/v4/toAst/undefined.ts
12974
- const undefinedToAst = ({ plugin }) => {
13248
+ function undefinedToAst({ plugin }) {
12975
13249
  const result = {};
12976
13250
  result.expression = $(plugin.external("zod.z")).attr(identifiers.undefined).call();
12977
13251
  return result;
12978
- };
13252
+ }
12979
13253
 
12980
13254
  //#endregion
12981
13255
  //#region src/plugins/zod/v4/toAst/void.ts
12982
- const voidToAst = ({ plugin }) => {
13256
+ function voidToAst({ plugin }) {
12983
13257
  const result = {};
12984
13258
  result.expression = $(plugin.external("zod.z")).attr(identifiers.void).call();
12985
13259
  return result;
12986
- };
13260
+ }
12987
13261
 
12988
13262
  //#endregion
12989
- //#region src/plugins/zod/v4/toAst/index.ts
12990
- function irSchemaWithTypeToAst({ schema, ...args }) {
12991
- switch (schema.type) {
12992
- case "array": return arrayToAst({
12993
- ...args,
12994
- schema
12995
- });
12996
- case "boolean": return booleanToAst({
12997
- ...args,
12998
- schema
12999
- });
13000
- case "enum": return enumToAst({
13001
- ...args,
13002
- schema
13003
- });
13004
- case "integer":
13005
- case "number": return numberToNode({
13006
- ...args,
13007
- schema
13008
- });
13009
- case "never": return neverToAst({
13010
- ...args,
13011
- schema
13012
- });
13013
- case "null": return nullToAst({
13014
- ...args,
13015
- schema
13016
- });
13017
- case "object": return objectToAst({
13018
- ...args,
13019
- schema
13020
- });
13021
- case "string": return shouldCoerceToBigInt(schema.format) ? numberToNode({
13022
- ...args,
13023
- schema: {
13024
- ...schema,
13025
- type: "number"
13263
+ //#region src/plugins/zod/v4/walker.ts
13264
+ function createVisitor(config) {
13265
+ const { schemaExtractor, state } = config;
13266
+ return {
13267
+ applyModifiers(result, ctx$1, options = {}) {
13268
+ const { optional } = options;
13269
+ let expression = result.expression.expression;
13270
+ if (result.readonly) expression = expression.attr(identifiers.readonly).call();
13271
+ const hasDefault = result.default !== void 0;
13272
+ const needsNullable = result.nullable;
13273
+ if (optional && needsNullable) expression = expression.attr(identifiers.nullish).call();
13274
+ else if (optional) expression = expression.attr(identifiers.optional).call();
13275
+ else if (needsNullable) expression = expression.attr(identifiers.nullable).call();
13276
+ if (hasDefault) expression = expression.attr(identifiers.default).call(result.format ? maybeBigInt(result.default, result.format) : $.fromValue(result.default));
13277
+ return { expression };
13278
+ },
13279
+ array(schema, ctx$1, walk) {
13280
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
13281
+ const ast = arrayToAst({
13282
+ ...ctx$1,
13283
+ applyModifiers,
13284
+ schema,
13285
+ state,
13286
+ walk
13287
+ });
13288
+ return {
13289
+ default: schema.default,
13290
+ expression: ast,
13291
+ hasLazyExpression: state.hasLazyExpression["~ref"],
13292
+ nullable: false,
13293
+ readonly: schema.accessScope === "read"
13294
+ };
13295
+ },
13296
+ boolean(schema, ctx$1) {
13297
+ const ast = booleanToAst({
13298
+ ...ctx$1,
13299
+ schema
13300
+ });
13301
+ return {
13302
+ default: schema.default,
13303
+ expression: ast,
13304
+ nullable: false,
13305
+ readonly: schema.accessScope === "read"
13306
+ };
13307
+ },
13308
+ enum(schema, ctx$1) {
13309
+ const ast = enumToAst({
13310
+ ...ctx$1,
13311
+ schema,
13312
+ state
13313
+ });
13314
+ const hasNull = schema.items?.some((item) => item.type === "null" || item.const === null) ?? false;
13315
+ return {
13316
+ default: schema.default,
13317
+ expression: ast,
13318
+ nullable: hasNull,
13319
+ readonly: schema.accessScope === "read"
13320
+ };
13321
+ },
13322
+ integer(schema, ctx$1) {
13323
+ const ast = numberToNode({
13324
+ ...ctx$1,
13325
+ schema,
13326
+ state
13327
+ });
13328
+ return {
13329
+ default: schema.default,
13330
+ expression: ast,
13331
+ format: schema.format,
13332
+ nullable: false,
13333
+ readonly: schema.accessScope === "read"
13334
+ };
13335
+ },
13336
+ intercept(schema, ctx$1, walk) {
13337
+ if (schemaExtractor && !schema.$ref) {
13338
+ const extracted = schemaExtractor({
13339
+ meta: {
13340
+ resource: "definition",
13341
+ resourceId: pathToJsonPointer(fromRef(ctx$1.path))
13342
+ },
13343
+ naming: ctx$1.plugin.config.definitions,
13344
+ path: fromRef(ctx$1.path),
13345
+ plugin: ctx$1.plugin,
13346
+ schema
13347
+ });
13348
+ if (extracted !== schema) return walk(extracted, ctx$1);
13026
13349
  }
13027
- }) : stringToNode({
13028
- ...args,
13029
- schema
13030
- });
13031
- case "tuple": return tupleToAst({
13032
- ...args,
13033
- schema
13034
- });
13035
- case "undefined": return undefinedToAst({
13036
- ...args,
13037
- schema
13038
- });
13039
- case "unknown": return unknownToAst({
13040
- ...args,
13041
- schema
13042
- });
13043
- case "void": return voidToAst({
13044
- ...args,
13045
- schema
13046
- });
13047
- }
13350
+ },
13351
+ intersection(items, schemas, parentSchema, ctx$1) {
13352
+ const z = ctx$1.plugin.external("zod.z");
13353
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
13354
+ const firstSchema = schemas[0];
13355
+ let expression;
13356
+ if (firstSchema?.logicalOperator === "or" || firstSchema?.type && firstSchema.type !== "object") expression = { expression: $(z).attr(identifiers.intersection).call(...items.map((item) => item.expression.expression)) };
13357
+ else {
13358
+ expression = items[0].expression;
13359
+ items.slice(1).forEach((item) => {
13360
+ expression = { expression: expression.expression.attr(identifiers.and).call(item.hasLazyExpression ? $(z).attr(identifiers.lazy).call($.func().do(item.expression.expression.return())) : item.expression.expression) };
13361
+ });
13362
+ }
13363
+ return {
13364
+ default: parentSchema.default,
13365
+ expression,
13366
+ hasLazyExpression: hasAnyLazy,
13367
+ nullable: items.some((i) => i.nullable),
13368
+ readonly: items.some((i) => i.readonly)
13369
+ };
13370
+ },
13371
+ never(schema, ctx$1) {
13372
+ const ast = neverToAst({
13373
+ ...ctx$1,
13374
+ schema
13375
+ });
13376
+ return {
13377
+ default: schema.default,
13378
+ expression: ast,
13379
+ nullable: false,
13380
+ readonly: false
13381
+ };
13382
+ },
13383
+ null(schema, ctx$1) {
13384
+ const ast = nullToAst({
13385
+ ...ctx$1,
13386
+ schema
13387
+ });
13388
+ return {
13389
+ default: schema.default,
13390
+ expression: ast,
13391
+ nullable: false,
13392
+ readonly: false
13393
+ };
13394
+ },
13395
+ number(schema, ctx$1) {
13396
+ const ast = numberToNode({
13397
+ ...ctx$1,
13398
+ schema,
13399
+ state
13400
+ });
13401
+ return {
13402
+ default: schema.default,
13403
+ expression: ast,
13404
+ format: schema.format,
13405
+ nullable: false,
13406
+ readonly: schema.accessScope === "read"
13407
+ };
13408
+ },
13409
+ object(schema, ctx$1, walk) {
13410
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
13411
+ const ast = objectToAst({
13412
+ applyModifiers,
13413
+ plugin: ctx$1.plugin,
13414
+ schema,
13415
+ state,
13416
+ walk,
13417
+ walkerCtx: ctx$1
13418
+ });
13419
+ return {
13420
+ default: schema.default,
13421
+ expression: ast,
13422
+ hasLazyExpression: state.hasLazyExpression["~ref"],
13423
+ nullable: false,
13424
+ readonly: schema.accessScope === "read"
13425
+ };
13426
+ },
13427
+ postProcess(result, schema, ctx$1) {
13428
+ if (ctx$1.plugin.config.metadata && schema.description) {
13429
+ const z = ctx$1.plugin.external("zod.z");
13430
+ return {
13431
+ ...result,
13432
+ expression: { expression: result.expression.expression.attr(identifiers.register).call($(z).attr(identifiers.globalRegistry), $.object().pretty().prop("description", $.literal(schema.description))) }
13433
+ };
13434
+ }
13435
+ return result;
13436
+ },
13437
+ reference($ref, schema, ctx$1) {
13438
+ const z = ctx$1.plugin.external("zod.z");
13439
+ const query = {
13440
+ category: "schema",
13441
+ resource: "definition",
13442
+ resourceId: $ref,
13443
+ tool: "zod"
13444
+ };
13445
+ const refSymbol = ctx$1.plugin.referenceSymbol(query);
13446
+ if (ctx$1.plugin.isSymbolRegistered(query)) return {
13447
+ default: schema.default,
13448
+ expression: { expression: $(refSymbol) },
13449
+ nullable: false,
13450
+ readonly: schema.accessScope === "read"
13451
+ };
13452
+ state.hasLazyExpression["~ref"] = true;
13453
+ return {
13454
+ default: schema.default,
13455
+ expression: { expression: $(z).attr(identifiers.lazy).call($.func().returns("any").do($(refSymbol).return())) },
13456
+ hasLazyExpression: true,
13457
+ nullable: false,
13458
+ readonly: schema.accessScope === "read"
13459
+ };
13460
+ },
13461
+ string(schema, ctx$1) {
13462
+ if (shouldCoerceToBigInt(schema.format)) {
13463
+ const ast$1 = numberToNode({
13464
+ plugin: ctx$1.plugin,
13465
+ schema: {
13466
+ ...schema,
13467
+ type: "number"
13468
+ },
13469
+ state
13470
+ });
13471
+ return {
13472
+ default: schema.default,
13473
+ expression: ast$1,
13474
+ nullable: false,
13475
+ readonly: schema.accessScope === "read"
13476
+ };
13477
+ }
13478
+ const ast = stringToNode({
13479
+ ...ctx$1,
13480
+ schema
13481
+ });
13482
+ return {
13483
+ default: schema.default,
13484
+ expression: ast,
13485
+ nullable: false,
13486
+ readonly: schema.accessScope === "read"
13487
+ };
13488
+ },
13489
+ tuple(schema, ctx$1, walk) {
13490
+ const applyModifiers = (result, opts) => this.applyModifiers(result, ctx$1, opts);
13491
+ const ast = tupleToAst({
13492
+ ...ctx$1,
13493
+ applyModifiers,
13494
+ schema,
13495
+ state,
13496
+ walk
13497
+ });
13498
+ return {
13499
+ default: schema.default,
13500
+ expression: ast,
13501
+ hasLazyExpression: state.hasLazyExpression["~ref"],
13502
+ nullable: false,
13503
+ readonly: schema.accessScope === "read"
13504
+ };
13505
+ },
13506
+ undefined(schema, ctx$1) {
13507
+ const ast = undefinedToAst({
13508
+ ...ctx$1,
13509
+ schema
13510
+ });
13511
+ return {
13512
+ default: schema.default,
13513
+ expression: ast,
13514
+ nullable: false,
13515
+ readonly: false
13516
+ };
13517
+ },
13518
+ union(items, schemas, parentSchema, ctx$1) {
13519
+ const z = ctx$1.plugin.external("zod.z");
13520
+ const hasAnyLazy = items.some((item) => item.hasLazyExpression);
13521
+ const hasNull = schemas.some((s) => s.type === "null") || items.some((i) => i.nullable);
13522
+ const nonNullItems = [];
13523
+ items.forEach((item, index) => {
13524
+ if (schemas[index].type !== "null") nonNullItems.push(item);
13525
+ });
13526
+ let expression;
13527
+ if (nonNullItems.length === 0) expression = { expression: $(z).attr(identifiers.null).call() };
13528
+ else if (nonNullItems.length === 1) expression = nonNullItems[0].expression;
13529
+ else expression = { expression: $(z).attr(identifiers.union).call($.array().pretty().elements(...nonNullItems.map((item) => item.expression.expression))) };
13530
+ return {
13531
+ default: parentSchema.default,
13532
+ expression,
13533
+ hasLazyExpression: hasAnyLazy,
13534
+ nullable: hasNull,
13535
+ readonly: items.some((i) => i.readonly)
13536
+ };
13537
+ },
13538
+ unknown(schema, ctx$1) {
13539
+ const ast = unknownToAst({
13540
+ ...ctx$1,
13541
+ schema
13542
+ });
13543
+ return {
13544
+ default: schema.default,
13545
+ expression: ast,
13546
+ nullable: false,
13547
+ readonly: false
13548
+ };
13549
+ },
13550
+ void(schema, ctx$1) {
13551
+ const ast = voidToAst({
13552
+ ...ctx$1,
13553
+ schema
13554
+ });
13555
+ return {
13556
+ default: schema.default,
13557
+ expression: ast,
13558
+ nullable: false,
13559
+ readonly: false
13560
+ };
13561
+ }
13562
+ };
13048
13563
  }
13049
13564
 
13050
13565
  //#endregion
13051
- //#region src/plugins/zod/v4/plugin.ts
13052
- function irSchemaToAst({ optional, plugin, schema, schemaExtractor, state }) {
13053
- if (schemaExtractor && !schema.$ref) {
13054
- const extracted = schemaExtractor({
13055
- meta: {
13056
- resource: "definition",
13057
- resourceId: pathToJsonPointer(fromRef(state.path))
13058
- },
13059
- naming: plugin.config.definitions,
13060
- path: fromRef(state.path),
13061
- plugin,
13062
- schema
13063
- });
13064
- if (extracted !== schema) schema = extracted;
13065
- }
13066
- let ast = {};
13067
- const z = plugin.external("zod.z");
13068
- if (schema.$ref) {
13069
- const query = {
13070
- category: "schema",
13071
- resource: "definition",
13072
- resourceId: schema.$ref,
13073
- tool: "zod"
13074
- };
13075
- const refSymbol = plugin.referenceSymbol(query);
13076
- if (plugin.isSymbolRegistered(query)) ast.expression = $(refSymbol);
13077
- else {
13078
- ast.expression = $(z).attr(identifiers.lazy).call($.func().returns("any").do($(refSymbol).return()));
13079
- ast.hasLazyExpression = true;
13080
- state.hasLazyExpression["~ref"] = true;
13566
+ //#region src/plugins/zod/v4/processor.ts
13567
+ function createProcessor(plugin) {
13568
+ const processor = createSchemaProcessor();
13569
+ const hooks = [plugin.config["~hooks"]?.schemas, plugin.context.config.parser.hooks.schemas];
13570
+ function extractor(ctx$1) {
13571
+ if (processor.hasEmitted(ctx$1.path)) return ctx$1.schema;
13572
+ for (const hook of hooks) if (hook?.shouldExtract?.(ctx$1)) {
13573
+ process$1({
13574
+ namingAnchor: processor.context.anchor,
13575
+ tags: processor.context.tags,
13576
+ ...ctx$1
13577
+ });
13578
+ return { $ref: pathToJsonPointer(ctx$1.path) };
13081
13579
  }
13082
- } else if (schema.type) {
13083
- const typeAst = irSchemaWithTypeToAst({
13084
- plugin,
13085
- schema,
13086
- state
13087
- });
13088
- ast.expression = typeAst.expression;
13089
- ast.hasLazyExpression = typeAst.hasLazyExpression;
13090
- if (plugin.config.metadata && schema.description) ast.expression = ast.expression.attr(identifiers.register).call($(z).attr(identifiers.globalRegistry), $.object().pretty().prop("description", $.literal(schema.description)));
13091
- } else if (schema.items) {
13092
- schema = deduplicateSchema({ schema });
13093
- if (schema.items) {
13094
- const itemSchemas = schema.items.map((item, index) => irSchemaToAst({
13580
+ return ctx$1.schema;
13581
+ }
13582
+ function process$1(ctx$1) {
13583
+ if (!processor.markEmitted(ctx$1.path)) return;
13584
+ processor.withContext({
13585
+ anchor: ctx$1.namingAnchor,
13586
+ tags: ctx$1.tags
13587
+ }, () => {
13588
+ const state = refs({
13589
+ hasLazyExpression: false,
13590
+ path: ctx$1.path,
13591
+ tags: ctx$1.tags
13592
+ });
13593
+ const visitor = createVisitor({
13594
+ schemaExtractor: extractor,
13595
+ state
13596
+ });
13597
+ const result = createSchemaWalker(visitor)(ctx$1.schema, {
13598
+ path: ref(ctx$1.path),
13599
+ plugin
13600
+ });
13601
+ const ast = visitor.applyModifiers(result, {
13602
+ path: ref(ctx$1.path),
13603
+ plugin
13604
+ }) ?? result.expression;
13605
+ if (result.hasLazyExpression) state.hasLazyExpression["~ref"] = true;
13606
+ exportAst({
13607
+ ...ctx$1,
13608
+ ast,
13095
13609
  plugin,
13096
- schema: item,
13097
- state: {
13098
- ...state,
13099
- path: ref([
13100
- ...fromRef(state.path),
13101
- "items",
13102
- index
13103
- ])
13104
- }
13105
- }));
13106
- if (schema.logicalOperator === "and") {
13107
- const firstSchema = schema.items[0];
13108
- if (firstSchema.logicalOperator === "or" || firstSchema.type && firstSchema.type !== "object") ast.expression = $(z).attr(identifiers.intersection).call(...itemSchemas.map((schema$1) => schema$1.expression));
13109
- else {
13110
- ast.expression = itemSchemas[0].expression;
13111
- itemSchemas.slice(1).forEach((schema$1) => {
13112
- ast.expression = ast.expression.attr(identifiers.and).call(schema$1.hasLazyExpression ? $(z).attr(identifiers.lazy).call($.func().do(schema$1.expression.return())) : schema$1.expression);
13113
- });
13114
- }
13115
- } else ast.expression = $(z).attr(identifiers.union).call($.array().pretty().elements(...itemSchemas.map((schema$1) => schema$1.expression)));
13116
- } else ast = irSchemaToAst({
13117
- plugin,
13118
- schema,
13119
- state
13120
- });
13121
- } else {
13122
- const typeAst = irSchemaWithTypeToAst({
13123
- plugin,
13124
- schema: { type: "unknown" },
13125
- state
13610
+ state
13611
+ });
13126
13612
  });
13127
- ast.expression = typeAst.expression;
13128
- }
13129
- if (ast.expression) {
13130
- if (schema.accessScope === "read") ast.expression = ast.expression.attr(identifiers.readonly).call();
13131
- if (optional) {
13132
- ast.expression = $(z).attr(identifiers.optional).call(ast.expression);
13133
- ast.typeName = identifiers.ZodOptional;
13134
- }
13135
- if (schema.default !== void 0) ast.expression = ast.expression.attr(identifiers.default).call(schema.type === "integer" || schema.type === "number" ? maybeBigInt(schema.default, schema.format) : $.fromValue(schema.default));
13136
13613
  }
13137
- return ast;
13614
+ return { process: process$1 };
13138
13615
  }
13616
+
13617
+ //#endregion
13618
+ //#region src/plugins/zod/v4/plugin.ts
13139
13619
  const handlerV4 = ({ plugin }) => {
13140
13620
  plugin.symbol("z", {
13141
13621
  external: getZodModule({ plugin }),
@@ -13638,4 +14118,4 @@ async function resolveJobs({ logger, userConfigs }) {
13638
14118
 
13639
14119
  //#endregion
13640
14120
  export { postProcessors as _, clientDefaultConfig as a, TypeScriptRenderer as c, reserved as d, keywords as f, getTypedConfig as g, getClientPlugin as h, generateClientBundle as i, TsDslContext as l, TsDsl as m, defaultPlugins as n, clientDefaultMeta as o, regexp as p, clientPluginHandler as r, $ as s, resolveJobs as t, ctx as u };
13641
- //# sourceMappingURL=init-BxMu9GWq.mjs.map
14121
+ //# sourceMappingURL=init-BVQKw3ZX.mjs.map