@hey-api/openapi-ts 0.92.2 → 0.92.4

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, deduplicateSchema, definePluginConfig, dependencyFactory, ensureDirSync, escapeComment, findTsConfigPath, getInput, getLogs, getParser, hasOperationDataRequired, hasParameterGroupObjectRequired, loadTsConfig, mappers, operationPagination, operationResponsesMap, parseUrl, pathToJsonPointer, refToName, resolveSource, satisfies, statusCodeToGroup, toCase, valueToObject } from "@hey-api/shared";
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";
4
4
  import colors from "ansi-colors";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -167,7 +167,7 @@ function getOutput(userConfig) {
167
167
  value: userOutput
168
168
  });
169
169
  output.tsConfig = loadTsConfig(findTsConfigPath(__dirname$1, output.tsConfigPath));
170
- if (output.importFileExtension === void 0 && (output.tsConfig?.options.moduleResolution === ts.ModuleResolutionKind.NodeNext || output.tsConfig?.options.moduleResolution === ts.ModuleResolutionKind.Node16)) output.importFileExtension = ".js";
170
+ if (output.importFileExtension === void 0 && (output.tsConfig?.options.moduleResolution === ts.ModuleResolutionKind.NodeNext || output.tsConfig?.options.moduleResolution === ts.ModuleResolutionKind.Node16 || output.tsConfig?.options.module === ts.ModuleKind.NodeNext || output.tsConfig?.options.module === ts.ModuleKind.Node16)) output.importFileExtension = ".js";
171
171
  if (output.importFileExtension && !output.importFileExtension.startsWith(".")) output.importFileExtension = `.${output.importFileExtension}`;
172
172
  output.postProcess = normalizePostProcess(userOutput.postProcess ?? legacyPostProcess);
173
173
  output.source = resolveSource(output);
@@ -5026,7 +5026,13 @@ function implementHttpRequestFn(args) {
5026
5026
  role: "data",
5027
5027
  tool: "typescript"
5028
5028
  });
5029
- return node.param("options", (p) => p.required(isRequiredOptions).type($.type(symbolOptions).generic(symbolDataType ?? "unknown").generic("ThrowOnError"))).generic("ThrowOnError", (g) => g.extends("boolean").default(false)).returns($.type(symbolHttpRequest).generic("unknown")).do($.return($("options").attr("client").optional().$if(symbolClient, (c, s) => c.coalesce(s)).attr("requestOptions").call($.object().prop("responseStyle", $.literal("data")).prop("method", $.literal(operation.method.toUpperCase())).prop("url", $.literal(operation.path)).spread("options"))));
5029
+ const symbolResponseType = plugin.querySymbol({
5030
+ category: "type",
5031
+ resource: "operation",
5032
+ resourceId: operation.id,
5033
+ role: "response"
5034
+ });
5035
+ return node.param("options", (p) => p.required(isRequiredOptions).type($.type(symbolOptions).generic(symbolDataType ?? "unknown").generic("ThrowOnError"))).generic("ThrowOnError", (g) => g.extends("boolean").default(false)).returns($.type(symbolHttpRequest).generic(symbolResponseType ?? "unknown")).do($.return($("options").attr("client").optional().$if(symbolClient, (c, s) => c.coalesce(s)).attr("requestOptions").call($.object().prop("responseStyle", $.literal("data")).prop("method", $.literal(operation.method.toUpperCase())).prop("url", $.literal(operation.path)).spread("options")).generic(symbolResponseType ?? "unknown").generic("ThrowOnError")));
5030
5036
  }
5031
5037
  function implementHttpResourceFn(args) {
5032
5038
  const { node, operation, plugin } = args;
@@ -5277,11 +5283,7 @@ const defaultConfig$22 = {
5277
5283
  enabled: true,
5278
5284
  name: "v{{name}}"
5279
5285
  },
5280
- mappers: {
5281
- boolean: (enabled) => ({ enabled }),
5282
- function: (name) => ({ name }),
5283
- string: (name) => ({ name })
5284
- },
5286
+ mappers,
5285
5287
  value: plugin.config.definitions
5286
5288
  });
5287
5289
  },
@@ -6365,13 +6367,19 @@ const processSchemaType = ({ dataExpression, plugin, schema }) => {
6365
6367
  return arrayNodes;
6366
6368
  }
6367
6369
  if (schema.type !== "enum") {
6368
- if (!(schema.items ?? []).every((item) => [
6370
+ const hasSimpleTypes = (schema.items ?? []).every((item) => [
6369
6371
  "boolean",
6370
6372
  "integer",
6371
6373
  "null",
6372
6374
  "number",
6373
6375
  "string"
6374
- ].includes(item.type))) console.warn(`❗️ Transformers warning: schema ${JSON.stringify(schema)} is too complex and won't be currently processed. This will likely produce an incomplete transformer which is not what you want. Please open an issue if you'd like this improved https://github.com/hey-api/openapi-ts/issues`);
6376
+ ].includes(item.type));
6377
+ const isProcessable = (schema.items ?? []).every((item) => {
6378
+ if (item.$ref) return true;
6379
+ if (item.logicalOperator === "and" && item.items) return true;
6380
+ return false;
6381
+ });
6382
+ if (!hasSimpleTypes && !isProcessable) console.warn(`❗️ Transformers warning: schema ${JSON.stringify(schema)} is too complex and won't be currently processed. This will likely produce an incomplete transformer which is not what you want. Please open an issue if you'd like this improved https://github.com/hey-api/openapi-ts/issues`);
6375
6383
  }
6376
6384
  }
6377
6385
  for (const transformer of plugin.config.transformers) {
@@ -6388,7 +6396,7 @@ const handler$8 = ({ plugin }) => {
6388
6396
  plugin.forEach("operation", ({ operation }) => {
6389
6397
  const { response } = operationResponsesMap(operation);
6390
6398
  if (!response) return;
6391
- if (response.items && response.items.length > 1) {
6399
+ if (response.items && response.items.length > 1 && response.logicalOperator !== "and") {
6392
6400
  if (plugin.context.config.logs.level === "debug") console.warn(`❗️ Transformers warning: route ${createOperationKey(operation)} has ${response.items.length} non-void success responses. This is currently not handled and we will not generate a response transformer. Please open an issue if you'd like this feature https://github.com/hey-api/openapi-ts/issues`);
6393
6401
  return;
6394
6402
  }
@@ -6484,6 +6492,7 @@ const createSchemaComment = (schema) => {
6484
6492
  //#endregion
6485
6493
  //#region src/plugins/@hey-api/typescript/shared/export.ts
6486
6494
  const schemaToEnumObject = ({ plugin, schema }) => {
6495
+ const keyCounts = {};
6487
6496
  const typeofItems = [];
6488
6497
  return {
6489
6498
  obj: (schema.items ?? []).map((item, index) => {
@@ -6499,6 +6508,19 @@ const schemaToEnumObject = ({ plugin, schema }) => {
6499
6508
  key = toCase(key, plugin.config.enums.case, { stripLeadingSeparators: false });
6500
6509
  regexp.number.lastIndex = 0;
6501
6510
  if (regexp.number.test(key) && plugin.config.enums.enabled && (plugin.config.enums.mode === "typescript" || plugin.config.enums.mode === "typescript-const")) key = `_${key}`;
6511
+ const keyCount = (keyCounts[key] ?? 0) + 1;
6512
+ keyCounts[key] = keyCount;
6513
+ if (keyCount > 1) {
6514
+ const nameConflictResolver = plugin.context.config.output?.nameConflictResolver;
6515
+ if (nameConflictResolver) {
6516
+ const resolvedName = nameConflictResolver({
6517
+ attempt: keyCount - 1,
6518
+ baseName: key
6519
+ });
6520
+ if (resolvedName !== null) key = resolvedName;
6521
+ else key = `${key}${keyCount}`;
6522
+ } else key = `${key}${keyCount}`;
6523
+ }
6502
6524
  }
6503
6525
  return {
6504
6526
  key,
@@ -6797,10 +6819,10 @@ const arrayToAst$4 = ({ plugin, schema, state }) => {
6797
6819
 
6798
6820
  //#endregion
6799
6821
  //#region src/plugins/@hey-api/typescript/v1/toAst/boolean.ts
6800
- const booleanToAst$4 = ({ schema }) => {
6822
+ function booleanToAst$4({ schema }) {
6801
6823
  if (schema.const !== void 0) return $.type.literal(schema.const);
6802
6824
  return $.type("boolean");
6803
- };
6825
+ }
6804
6826
 
6805
6827
  //#endregion
6806
6828
  //#region src/plugins/@hey-api/typescript/v1/toAst/enum.ts
@@ -6983,7 +7005,7 @@ const voidToAst$4 = (_args) => {
6983
7005
 
6984
7006
  //#endregion
6985
7007
  //#region src/plugins/@hey-api/typescript/v1/toAst/index.ts
6986
- const irSchemaWithTypeToAst$5 = ({ schema, ...args }) => {
7008
+ function irSchemaWithTypeToAst$5({ schema, ...args }) {
6987
7009
  const transformersPlugin = args.plugin.getPlugin("@hey-api/transformers");
6988
7010
  if (transformersPlugin?.config.typeTransformers) for (const typeTransformer of transformersPlugin.config.typeTransformers) {
6989
7011
  const typeNode = typeTransformer({ schema });
@@ -7040,11 +7062,22 @@ const irSchemaWithTypeToAst$5 = ({ schema, ...args }) => {
7040
7062
  schema
7041
7063
  });
7042
7064
  }
7043
- };
7065
+ }
7044
7066
 
7045
7067
  //#endregion
7046
7068
  //#region src/plugins/@hey-api/typescript/v1/plugin.ts
7047
- const irSchemaToAst$5 = ({ plugin, schema, state }) => {
7069
+ function irSchemaToAst$5({ plugin, schema, schemaExtractor, state }) {
7070
+ if (schemaExtractor && !schema.$ref) {
7071
+ const extracted = schemaExtractor({
7072
+ meta: {
7073
+ resource: "definition",
7074
+ resourceId: pathToJsonPointer(fromRef(state.path))
7075
+ },
7076
+ path: fromRef(state.path),
7077
+ schema
7078
+ });
7079
+ if (extracted !== schema) schema = extracted;
7080
+ }
7048
7081
  if (schema.symbolRef) {
7049
7082
  const baseType = $.type(schema.symbolRef);
7050
7083
  if (schema.omit && schema.omit.length > 0) {
@@ -7095,8 +7128,8 @@ const irSchemaToAst$5 = ({ plugin, schema, state }) => {
7095
7128
  schema: { type: "unknown" },
7096
7129
  state
7097
7130
  });
7098
- };
7099
- const handleComponent$5 = ({ plugin, schema, state }) => {
7131
+ }
7132
+ function handleComponent$1({ plugin, schema, state }) {
7100
7133
  exportType({
7101
7134
  plugin,
7102
7135
  schema,
@@ -7107,7 +7140,7 @@ const handleComponent$5 = ({ plugin, schema, state }) => {
7107
7140
  state
7108
7141
  })
7109
7142
  });
7110
- };
7143
+ }
7111
7144
  const handlerV1$1 = ({ plugin }) => {
7112
7145
  const nodeClientIndex = plugin.node(null);
7113
7146
  const nodeWebhooksIndex = plugin.node(null);
@@ -7127,21 +7160,21 @@ const handlerV1$1 = ({ plugin }) => {
7127
7160
  });
7128
7161
  break;
7129
7162
  case "parameter":
7130
- handleComponent$5({
7163
+ handleComponent$1({
7131
7164
  plugin,
7132
7165
  schema: event.parameter.schema,
7133
7166
  state
7134
7167
  });
7135
7168
  break;
7136
7169
  case "requestBody":
7137
- handleComponent$5({
7170
+ handleComponent$1({
7138
7171
  plugin,
7139
7172
  schema: event.requestBody.schema,
7140
7173
  state
7141
7174
  });
7142
7175
  break;
7143
7176
  case "schema":
7144
- handleComponent$5({
7177
+ handleComponent$1({
7145
7178
  plugin,
7146
7179
  schema: event.schema,
7147
7180
  state
@@ -7579,11 +7612,7 @@ const defaultConfig$10 = {
7579
7612
  enabled: true,
7580
7613
  name: "{{name}}Mutation"
7581
7614
  },
7582
- mappers: {
7583
- boolean: (enabled) => ({ enabled }),
7584
- function: (name) => ({ name }),
7585
- string: (name) => ({ name })
7586
- },
7615
+ mappers,
7587
7616
  value: plugin.config.mutationOptions
7588
7617
  });
7589
7618
  plugin.config.queryKeys = context.valueToObject({
@@ -7593,11 +7622,7 @@ const defaultConfig$10 = {
7593
7622
  name: "{{name}}QueryKey",
7594
7623
  tags: false
7595
7624
  },
7596
- mappers: {
7597
- boolean: (enabled) => ({ enabled }),
7598
- function: (name) => ({ name }),
7599
- string: (name) => ({ name })
7600
- },
7625
+ mappers,
7601
7626
  value: plugin.config.queryKeys
7602
7627
  });
7603
7628
  plugin.config.queryOptions = context.valueToObject({
@@ -7606,11 +7631,7 @@ const defaultConfig$10 = {
7606
7631
  enabled: true,
7607
7632
  name: "{{name}}Query"
7608
7633
  },
7609
- mappers: {
7610
- boolean: (enabled) => ({ enabled }),
7611
- function: (name) => ({ name }),
7612
- string: (name) => ({ name })
7613
- },
7634
+ mappers,
7614
7635
  value: plugin.config.queryOptions
7615
7636
  });
7616
7637
  }
@@ -8034,11 +8055,7 @@ const defaultConfig$9 = {
8034
8055
  name: "{{name}}InfiniteQueryKey",
8035
8056
  tags: false
8036
8057
  },
8037
- mappers: {
8038
- boolean: (enabled) => ({ enabled }),
8039
- function: (name) => ({ name }),
8040
- string: (name) => ({ name })
8041
- },
8058
+ mappers,
8042
8059
  value: plugin.config.infiniteQueryKeys
8043
8060
  });
8044
8061
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -8047,11 +8064,7 @@ const defaultConfig$9 = {
8047
8064
  enabled: true,
8048
8065
  name: "{{name}}InfiniteOptions"
8049
8066
  },
8050
- mappers: {
8051
- boolean: (enabled) => ({ enabled }),
8052
- function: (name) => ({ name }),
8053
- string: (name) => ({ name })
8054
- },
8067
+ mappers,
8055
8068
  value: plugin.config.infiniteQueryOptions
8056
8069
  });
8057
8070
  plugin.config.mutationOptions = context.valueToObject({
@@ -8060,11 +8073,7 @@ const defaultConfig$9 = {
8060
8073
  enabled: true,
8061
8074
  name: "{{name}}Mutation"
8062
8075
  },
8063
- mappers: {
8064
- boolean: (enabled) => ({ enabled }),
8065
- function: (name) => ({ name }),
8066
- string: (name) => ({ name })
8067
- },
8076
+ mappers,
8068
8077
  value: plugin.config.mutationOptions
8069
8078
  });
8070
8079
  plugin.config.queryKeys = context.valueToObject({
@@ -8074,11 +8083,7 @@ const defaultConfig$9 = {
8074
8083
  name: "{{name}}QueryKey",
8075
8084
  tags: false
8076
8085
  },
8077
- mappers: {
8078
- boolean: (enabled) => ({ enabled }),
8079
- function: (name) => ({ name }),
8080
- string: (name) => ({ name })
8081
- },
8086
+ mappers,
8082
8087
  value: plugin.config.queryKeys
8083
8088
  });
8084
8089
  plugin.config.queryOptions = context.valueToObject({
@@ -8088,11 +8093,7 @@ const defaultConfig$9 = {
8088
8093
  exported: true,
8089
8094
  name: "{{name}}Options"
8090
8095
  },
8091
- mappers: {
8092
- boolean: (enabled) => ({ enabled }),
8093
- function: (name) => ({ name }),
8094
- string: (name) => ({ name })
8095
- },
8096
+ mappers,
8096
8097
  value: plugin.config.queryOptions
8097
8098
  });
8098
8099
  }
@@ -8121,11 +8122,7 @@ const defaultConfig$8 = {
8121
8122
  name: "{{name}}InfiniteQueryKey",
8122
8123
  tags: false
8123
8124
  },
8124
- mappers: {
8125
- boolean: (enabled) => ({ enabled }),
8126
- function: (name) => ({ name }),
8127
- string: (name) => ({ name })
8128
- },
8125
+ mappers,
8129
8126
  value: plugin.config.infiniteQueryKeys
8130
8127
  });
8131
8128
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -8134,11 +8131,7 @@ const defaultConfig$8 = {
8134
8131
  enabled: true,
8135
8132
  name: "{{name}}InfiniteOptions"
8136
8133
  },
8137
- mappers: {
8138
- boolean: (enabled) => ({ enabled }),
8139
- function: (name) => ({ name }),
8140
- string: (name) => ({ name })
8141
- },
8134
+ mappers,
8142
8135
  value: plugin.config.infiniteQueryOptions
8143
8136
  });
8144
8137
  plugin.config.mutationOptions = context.valueToObject({
@@ -8147,11 +8140,7 @@ const defaultConfig$8 = {
8147
8140
  enabled: true,
8148
8141
  name: "{{name}}Mutation"
8149
8142
  },
8150
- mappers: {
8151
- boolean: (enabled) => ({ enabled }),
8152
- function: (name) => ({ name }),
8153
- string: (name) => ({ name })
8154
- },
8143
+ mappers,
8155
8144
  value: plugin.config.mutationOptions
8156
8145
  });
8157
8146
  plugin.config.queryKeys = context.valueToObject({
@@ -8161,11 +8150,7 @@ const defaultConfig$8 = {
8161
8150
  name: "{{name}}QueryKey",
8162
8151
  tags: false
8163
8152
  },
8164
- mappers: {
8165
- boolean: (enabled) => ({ enabled }),
8166
- function: (name) => ({ name }),
8167
- string: (name) => ({ name })
8168
- },
8153
+ mappers,
8169
8154
  value: plugin.config.queryKeys
8170
8155
  });
8171
8156
  plugin.config.queryOptions = context.valueToObject({
@@ -8175,11 +8160,7 @@ const defaultConfig$8 = {
8175
8160
  exported: true,
8176
8161
  name: "{{name}}Options"
8177
8162
  },
8178
- mappers: {
8179
- boolean: (enabled) => ({ enabled }),
8180
- function: (name) => ({ name }),
8181
- string: (name) => ({ name })
8182
- },
8163
+ mappers,
8183
8164
  value: plugin.config.queryOptions
8184
8165
  });
8185
8166
  plugin.config.useQuery = context.valueToObject({
@@ -8237,11 +8218,7 @@ const defaultConfig$7 = {
8237
8218
  name: "{{name}}InfiniteQueryKey",
8238
8219
  tags: false
8239
8220
  },
8240
- mappers: {
8241
- boolean: (enabled) => ({ enabled }),
8242
- function: (name) => ({ name }),
8243
- string: (name) => ({ name })
8244
- },
8221
+ mappers,
8245
8222
  value: plugin.config.infiniteQueryKeys
8246
8223
  });
8247
8224
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -8250,11 +8227,7 @@ const defaultConfig$7 = {
8250
8227
  enabled: true,
8251
8228
  name: "{{name}}InfiniteOptions"
8252
8229
  },
8253
- mappers: {
8254
- boolean: (enabled) => ({ enabled }),
8255
- function: (name) => ({ name }),
8256
- string: (name) => ({ name })
8257
- },
8230
+ mappers,
8258
8231
  value: plugin.config.infiniteQueryOptions
8259
8232
  });
8260
8233
  plugin.config.mutationOptions = context.valueToObject({
@@ -8263,11 +8236,7 @@ const defaultConfig$7 = {
8263
8236
  enabled: true,
8264
8237
  name: "{{name}}Mutation"
8265
8238
  },
8266
- mappers: {
8267
- boolean: (enabled) => ({ enabled }),
8268
- function: (name) => ({ name }),
8269
- string: (name) => ({ name })
8270
- },
8239
+ mappers,
8271
8240
  value: plugin.config.mutationOptions
8272
8241
  });
8273
8242
  plugin.config.queryKeys = context.valueToObject({
@@ -8277,11 +8246,7 @@ const defaultConfig$7 = {
8277
8246
  name: "{{name}}QueryKey",
8278
8247
  tags: false
8279
8248
  },
8280
- mappers: {
8281
- boolean: (enabled) => ({ enabled }),
8282
- function: (name) => ({ name }),
8283
- string: (name) => ({ name })
8284
- },
8249
+ mappers,
8285
8250
  value: plugin.config.queryKeys
8286
8251
  });
8287
8252
  plugin.config.queryOptions = context.valueToObject({
@@ -8291,11 +8256,7 @@ const defaultConfig$7 = {
8291
8256
  exported: true,
8292
8257
  name: "{{name}}Options"
8293
8258
  },
8294
- mappers: {
8295
- boolean: (enabled) => ({ enabled }),
8296
- function: (name) => ({ name }),
8297
- string: (name) => ({ name })
8298
- },
8259
+ mappers,
8299
8260
  value: plugin.config.queryOptions
8300
8261
  });
8301
8262
  }
@@ -8324,11 +8285,7 @@ const defaultConfig$6 = {
8324
8285
  name: "{{name}}InfiniteQueryKey",
8325
8286
  tags: false
8326
8287
  },
8327
- mappers: {
8328
- boolean: (enabled) => ({ enabled }),
8329
- function: (name) => ({ name }),
8330
- string: (name) => ({ name })
8331
- },
8288
+ mappers,
8332
8289
  value: plugin.config.infiniteQueryKeys
8333
8290
  });
8334
8291
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -8337,11 +8294,7 @@ const defaultConfig$6 = {
8337
8294
  enabled: true,
8338
8295
  name: "{{name}}InfiniteOptions"
8339
8296
  },
8340
- mappers: {
8341
- boolean: (enabled) => ({ enabled }),
8342
- function: (name) => ({ name }),
8343
- string: (name) => ({ name })
8344
- },
8297
+ mappers,
8345
8298
  value: plugin.config.infiniteQueryOptions
8346
8299
  });
8347
8300
  plugin.config.mutationOptions = context.valueToObject({
@@ -8350,11 +8303,7 @@ const defaultConfig$6 = {
8350
8303
  enabled: true,
8351
8304
  name: "{{name}}Mutation"
8352
8305
  },
8353
- mappers: {
8354
- boolean: (enabled) => ({ enabled }),
8355
- function: (name) => ({ name }),
8356
- string: (name) => ({ name })
8357
- },
8306
+ mappers,
8358
8307
  value: plugin.config.mutationOptions
8359
8308
  });
8360
8309
  plugin.config.queryKeys = context.valueToObject({
@@ -8364,11 +8313,7 @@ const defaultConfig$6 = {
8364
8313
  name: "{{name}}QueryKey",
8365
8314
  tags: false
8366
8315
  },
8367
- mappers: {
8368
- boolean: (enabled) => ({ enabled }),
8369
- function: (name) => ({ name }),
8370
- string: (name) => ({ name })
8371
- },
8316
+ mappers,
8372
8317
  value: plugin.config.queryKeys
8373
8318
  });
8374
8319
  plugin.config.queryOptions = context.valueToObject({
@@ -8378,11 +8323,7 @@ const defaultConfig$6 = {
8378
8323
  exported: true,
8379
8324
  name: "{{name}}Options"
8380
8325
  },
8381
- mappers: {
8382
- boolean: (enabled) => ({ enabled }),
8383
- function: (name) => ({ name }),
8384
- string: (name) => ({ name })
8385
- },
8326
+ mappers,
8386
8327
  value: plugin.config.queryOptions
8387
8328
  });
8388
8329
  }
@@ -8411,11 +8352,7 @@ const defaultConfig$5 = {
8411
8352
  name: "{{name}}InfiniteQueryKey",
8412
8353
  tags: false
8413
8354
  },
8414
- mappers: {
8415
- boolean: (enabled) => ({ enabled }),
8416
- function: (name) => ({ name }),
8417
- string: (name) => ({ name })
8418
- },
8355
+ mappers,
8419
8356
  value: plugin.config.infiniteQueryKeys
8420
8357
  });
8421
8358
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -8424,11 +8361,7 @@ const defaultConfig$5 = {
8424
8361
  enabled: true,
8425
8362
  name: "{{name}}InfiniteOptions"
8426
8363
  },
8427
- mappers: {
8428
- boolean: (enabled) => ({ enabled }),
8429
- function: (name) => ({ name }),
8430
- string: (name) => ({ name })
8431
- },
8364
+ mappers,
8432
8365
  value: plugin.config.infiniteQueryOptions
8433
8366
  });
8434
8367
  plugin.config.mutationOptions = context.valueToObject({
@@ -8437,11 +8370,7 @@ const defaultConfig$5 = {
8437
8370
  enabled: true,
8438
8371
  name: "{{name}}Mutation"
8439
8372
  },
8440
- mappers: {
8441
- boolean: (enabled) => ({ enabled }),
8442
- function: (name) => ({ name }),
8443
- string: (name) => ({ name })
8444
- },
8373
+ mappers,
8445
8374
  value: plugin.config.mutationOptions
8446
8375
  });
8447
8376
  plugin.config.queryKeys = context.valueToObject({
@@ -8451,11 +8380,7 @@ const defaultConfig$5 = {
8451
8380
  name: "{{name}}QueryKey",
8452
8381
  tags: false
8453
8382
  },
8454
- mappers: {
8455
- boolean: (enabled) => ({ enabled }),
8456
- function: (name) => ({ name }),
8457
- string: (name) => ({ name })
8458
- },
8383
+ mappers,
8459
8384
  value: plugin.config.queryKeys
8460
8385
  });
8461
8386
  plugin.config.queryOptions = context.valueToObject({
@@ -8465,11 +8390,7 @@ const defaultConfig$5 = {
8465
8390
  exported: true,
8466
8391
  name: "{{name}}Options"
8467
8392
  },
8468
- mappers: {
8469
- boolean: (enabled) => ({ enabled }),
8470
- function: (name) => ({ name }),
8471
- string: (name) => ({ name })
8472
- },
8393
+ mappers,
8473
8394
  value: plugin.config.queryOptions
8474
8395
  });
8475
8396
  }
@@ -8623,7 +8544,7 @@ const identifiers$2 = {
8623
8544
 
8624
8545
  //#endregion
8625
8546
  //#region src/plugins/arktype/shared/export.ts
8626
- const exportAst$2 = ({ ast, plugin, schema, symbol, typeInferSymbol }) => {
8547
+ function exportAst$2({ ast, plugin, schema, symbol, typeInferSymbol }) {
8627
8548
  const type = plugin.external("arktype.type");
8628
8549
  const statement = $.const(symbol).export().$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v)).assign($(type).call(ast.def ? $.literal(ast.def) : ast.expression));
8629
8550
  plugin.node(statement);
@@ -8631,7 +8552,7 @@ const exportAst$2 = ({ ast, plugin, schema, symbol, typeInferSymbol }) => {
8631
8552
  const inferType = $.type.alias(typeInferSymbol).export().type($.type(symbol).attr(identifiers$2.type.infer).typeofType());
8632
8553
  plugin.node(inferType);
8633
8554
  }
8634
- };
8555
+ }
8635
8556
 
8636
8557
  //#endregion
8637
8558
  //#region src/plugins/arktype/v2/toAst/null.ts
@@ -8730,7 +8651,7 @@ const stringToAst = ({ schema }) => {
8730
8651
 
8731
8652
  //#endregion
8732
8653
  //#region src/plugins/arktype/v2/toAst/index.ts
8733
- const irSchemaWithTypeToAst$4 = ({ schema, ...args }) => {
8654
+ function irSchemaWithTypeToAst$4({ schema, ...args }) {
8734
8655
  switch (schema.type) {
8735
8656
  case "null": return nullToAst$4({
8736
8657
  ...args,
@@ -8750,11 +8671,22 @@ const irSchemaWithTypeToAst$4 = ({ schema, ...args }) => {
8750
8671
  expression: $(args.plugin.external("arktype.type")).call($.object().prop("name", $.literal("string")).prop("platform", $.literal("'android' | 'ios'")).prop("versions?", $.literal("(number | string)[]"))),
8751
8672
  hasLazyExpression: false
8752
8673
  };
8753
- };
8674
+ }
8754
8675
 
8755
8676
  //#endregion
8756
8677
  //#region src/plugins/arktype/v2/plugin.ts
8757
- const irSchemaToAst$4 = ({ plugin, schema, state }) => {
8678
+ function irSchemaToAst$4({ plugin, schema, schemaExtractor, state }) {
8679
+ if (schemaExtractor && !schema.$ref) {
8680
+ const extracted = schemaExtractor({
8681
+ meta: {
8682
+ resource: "definition",
8683
+ resourceId: pathToJsonPointer(fromRef(state.path))
8684
+ },
8685
+ path: fromRef(state.path),
8686
+ schema
8687
+ });
8688
+ if (extracted !== schema) schema = extracted;
8689
+ }
8758
8690
  let ast = {};
8759
8691
  if (schema.$ref) {
8760
8692
  const query = {
@@ -8808,8 +8740,8 @@ const irSchemaToAst$4 = ({ plugin, schema, state }) => {
8808
8740
  ast.expression = typeAst.expression;
8809
8741
  }
8810
8742
  return ast;
8811
- };
8812
- const handleComponent$4 = ({ plugin, schema, state }) => {
8743
+ }
8744
+ function handleComponent({ plugin, schema, state }) {
8813
8745
  const $ref = pathToJsonPointer(fromRef(state.path));
8814
8746
  const ast = irSchemaToAst$4({
8815
8747
  plugin,
@@ -8838,7 +8770,7 @@ const handleComponent$4 = ({ plugin, schema, state }) => {
8838
8770
  variant: "infer"
8839
8771
  } }) : void 0
8840
8772
  });
8841
- };
8773
+ }
8842
8774
  const handlerV2$1 = ({ plugin }) => {
8843
8775
  plugin.symbol("type", {
8844
8776
  external: "arktype",
@@ -8855,21 +8787,21 @@ const handlerV2$1 = ({ plugin }) => {
8855
8787
  });
8856
8788
  switch (event.type) {
8857
8789
  case "parameter":
8858
- handleComponent$4({
8790
+ handleComponent({
8859
8791
  plugin,
8860
8792
  schema: event.parameter.schema,
8861
8793
  state
8862
8794
  });
8863
8795
  break;
8864
8796
  case "requestBody":
8865
- handleComponent$4({
8797
+ handleComponent({
8866
8798
  plugin,
8867
8799
  schema: event.requestBody.schema,
8868
8800
  state
8869
8801
  });
8870
8802
  break;
8871
8803
  case "schema":
8872
- handleComponent$4({
8804
+ handleComponent({
8873
8805
  plugin,
8874
8806
  schema: event.schema,
8875
8807
  state
@@ -9226,11 +9158,7 @@ const defaultConfig$2 = {
9226
9158
  name: "{{name}}InfiniteQueryKey",
9227
9159
  tags: false
9228
9160
  },
9229
- mappers: {
9230
- boolean: (enabled) => ({ enabled }),
9231
- function: (name) => ({ name }),
9232
- string: (name) => ({ name })
9233
- },
9161
+ mappers,
9234
9162
  value: plugin.config.infiniteQueryKeys
9235
9163
  });
9236
9164
  plugin.config.infiniteQueryOptions = context.valueToObject({
@@ -9239,11 +9167,7 @@ const defaultConfig$2 = {
9239
9167
  enabled: true,
9240
9168
  name: "{{name}}InfiniteOptions"
9241
9169
  },
9242
- mappers: {
9243
- boolean: (enabled) => ({ enabled }),
9244
- function: (name) => ({ name }),
9245
- string: (name) => ({ name })
9246
- },
9170
+ mappers,
9247
9171
  value: plugin.config.infiniteQueryOptions
9248
9172
  });
9249
9173
  plugin.config.mutationOptions = context.valueToObject({
@@ -9252,11 +9176,7 @@ const defaultConfig$2 = {
9252
9176
  enabled: true,
9253
9177
  name: "{{name}}Mutation"
9254
9178
  },
9255
- mappers: {
9256
- boolean: (enabled) => ({ enabled }),
9257
- function: (name) => ({ name }),
9258
- string: (name) => ({ name })
9259
- },
9179
+ mappers,
9260
9180
  value: plugin.config.mutationOptions
9261
9181
  });
9262
9182
  plugin.config.queryKeys = context.valueToObject({
@@ -9266,11 +9186,7 @@ const defaultConfig$2 = {
9266
9186
  name: "{{name}}QueryKey",
9267
9187
  tags: false
9268
9188
  },
9269
- mappers: {
9270
- boolean: (enabled) => ({ enabled }),
9271
- function: (name) => ({ name }),
9272
- string: (name) => ({ name })
9273
- },
9189
+ mappers,
9274
9190
  value: plugin.config.queryKeys
9275
9191
  });
9276
9192
  plugin.config.queryOptions = context.valueToObject({
@@ -9280,11 +9196,7 @@ const defaultConfig$2 = {
9280
9196
  exported: true,
9281
9197
  name: "{{name}}Options"
9282
9198
  },
9283
- mappers: {
9284
- boolean: (enabled) => ({ enabled }),
9285
- function: (name) => ({ name }),
9286
- string: (name) => ({ name })
9287
- },
9199
+ mappers,
9288
9200
  value: plugin.config.queryOptions
9289
9201
  });
9290
9202
  plugin.config.useSwr = context.valueToObject({
@@ -9674,243 +9586,203 @@ const maybeBigInt = (value, format) => {
9674
9586
  };
9675
9587
 
9676
9588
  //#endregion
9677
- //#region src/plugins/valibot/shared/export.ts
9678
- const exportAst$1 = ({ ast, plugin, schema, state, symbol }) => {
9679
- const v = plugin.external("valibot.v");
9680
- 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));
9681
- plugin.node(statement);
9682
- };
9589
+ //#region src/plugins/valibot/shared/operation-schema.ts
9590
+ function buildOperationSchema$1(operation) {
9591
+ const requiredProperties = /* @__PURE__ */ new Set();
9592
+ const schema = {
9593
+ properties: {
9594
+ body: { type: "never" },
9595
+ path: { type: "never" },
9596
+ query: { type: "never" }
9597
+ },
9598
+ type: "object"
9599
+ };
9600
+ if (operation.parameters) for (const location of [
9601
+ "header",
9602
+ "path",
9603
+ "query"
9604
+ ]) {
9605
+ const params = operation.parameters[location];
9606
+ if (!params) continue;
9607
+ const properties = {};
9608
+ const required = [];
9609
+ const propKey = location === "header" ? "headers" : location;
9610
+ for (const key in params) {
9611
+ const parameter = params[key];
9612
+ properties[parameter.name] = parameter.schema;
9613
+ if (parameter.required) {
9614
+ required.push(parameter.name);
9615
+ requiredProperties.add(propKey);
9616
+ }
9617
+ }
9618
+ if (Object.keys(properties).length) schema.properties[propKey] = {
9619
+ properties,
9620
+ required,
9621
+ type: "object"
9622
+ };
9623
+ }
9624
+ if (operation.body) {
9625
+ schema.properties.body = operation.body.schema;
9626
+ if (operation.body.required) requiredProperties.add("body");
9627
+ }
9628
+ schema.required = [...requiredProperties];
9629
+ return {
9630
+ required: schema.required,
9631
+ schema
9632
+ };
9633
+ }
9683
9634
 
9684
9635
  //#endregion
9685
9636
  //#region src/plugins/valibot/shared/operation.ts
9686
- const irOperationToAst$1 = ({ getAst, operation, plugin, state }) => {
9637
+ function irOperationToAst$1({ operation, path: path$1, plugin, processor, tags }) {
9687
9638
  if (plugin.config.requests.enabled) {
9688
- const requiredProperties = /* @__PURE__ */ new Set();
9689
- const schemaData = {
9690
- properties: {
9691
- body: { type: "never" },
9692
- path: { type: "never" },
9693
- query: { type: "never" }
9694
- },
9695
- type: "object"
9696
- };
9697
- if (operation.parameters) {
9698
- if (operation.parameters.header) {
9699
- const properties = {};
9700
- const required = [];
9701
- for (const key in operation.parameters.header) {
9702
- const parameter = operation.parameters.header[key];
9703
- properties[parameter.name] = parameter.schema;
9704
- if (parameter.required) {
9705
- required.push(parameter.name);
9706
- requiredProperties.add("headers");
9707
- }
9708
- }
9709
- if (Object.keys(properties).length) schemaData.properties.headers = {
9710
- properties,
9711
- required,
9712
- type: "object"
9713
- };
9714
- }
9715
- if (operation.parameters.path) {
9716
- const properties = {};
9717
- const required = [];
9718
- for (const key in operation.parameters.path) {
9719
- const parameter = operation.parameters.path[key];
9720
- properties[parameter.name] = parameter.schema;
9721
- if (parameter.required) {
9722
- required.push(parameter.name);
9723
- requiredProperties.add("path");
9724
- }
9725
- }
9726
- if (Object.keys(properties).length) schemaData.properties.path = {
9727
- properties,
9728
- required,
9729
- type: "object"
9730
- };
9731
- }
9732
- if (operation.parameters.query) {
9733
- const properties = {};
9734
- const required = [];
9735
- for (const key in operation.parameters.query) {
9736
- const parameter = operation.parameters.query[key];
9737
- properties[parameter.name] = parameter.schema;
9738
- if (parameter.required) {
9739
- required.push(parameter.name);
9740
- requiredProperties.add("query");
9741
- }
9742
- }
9743
- if (Object.keys(properties).length) schemaData.properties.query = {
9744
- properties,
9745
- required,
9746
- type: "object"
9747
- };
9748
- }
9749
- }
9750
- if (operation.body) {
9751
- schemaData.properties.body = operation.body.schema;
9752
- if (operation.body.required) requiredProperties.add("body");
9753
- }
9754
- schemaData.required = [...requiredProperties];
9755
- exportAst$1({
9756
- ast: getAst(schemaData, fromRef(state.path)),
9757
- plugin,
9758
- schema: schemaData,
9759
- state,
9760
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.requests), { meta: {
9761
- category: "schema",
9762
- path: fromRef(state.path),
9639
+ const { schema } = buildOperationSchema$1(operation);
9640
+ processor.process({
9641
+ meta: {
9763
9642
  resource: "operation",
9764
9643
  resourceId: operation.id,
9765
- role: "data",
9766
- tags: fromRef(state.tags),
9767
- tool: "valibot"
9768
- } })
9644
+ role: "data"
9645
+ },
9646
+ naming: plugin.config.requests,
9647
+ namingAnchor: operation.id,
9648
+ path: path$1,
9649
+ plugin,
9650
+ schema,
9651
+ tags
9769
9652
  });
9770
9653
  }
9771
9654
  if (plugin.config.responses.enabled) {
9772
9655
  if (operation.responses) {
9773
9656
  const { response } = operationResponsesMap(operation);
9774
- if (response) {
9775
- const path$1 = [...fromRef(state.path), "responses"];
9776
- exportAst$1({
9777
- ast: getAst(response, path$1),
9778
- plugin,
9779
- schema: response,
9780
- state,
9781
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.responses), { meta: {
9782
- category: "schema",
9783
- path: path$1,
9784
- resource: "operation",
9785
- resourceId: operation.id,
9786
- role: "responses",
9787
- tags: fromRef(state.tags),
9788
- tool: "valibot"
9789
- } })
9790
- });
9791
- }
9657
+ if (response) processor.process({
9658
+ meta: {
9659
+ resource: "operation",
9660
+ resourceId: operation.id,
9661
+ role: "responses"
9662
+ },
9663
+ naming: plugin.config.responses,
9664
+ namingAnchor: operation.id,
9665
+ path: [...path$1, "responses"],
9666
+ plugin,
9667
+ schema: response,
9668
+ tags
9669
+ });
9792
9670
  }
9793
9671
  }
9794
- };
9672
+ }
9795
9673
 
9796
9674
  //#endregion
9797
9675
  //#region src/plugins/valibot/shared/webhook.ts
9798
- const irWebhookToAst$1 = ({ getAst, operation, plugin, state }) => {
9676
+ function irWebhookToAst$1({ operation, path: path$1, plugin, processor, tags }) {
9799
9677
  if (plugin.config.webhooks.enabled) {
9800
- const requiredProperties = /* @__PURE__ */ new Set();
9801
- const schemaData = {
9802
- properties: {
9803
- body: { type: "never" },
9804
- path: { type: "never" },
9805
- query: { type: "never" }
9806
- },
9807
- type: "object"
9808
- };
9809
- if (operation.parameters) {
9810
- if (operation.parameters.header) {
9811
- const properties = {};
9812
- const required = [];
9813
- for (const key in operation.parameters.header) {
9814
- const parameter = operation.parameters.header[key];
9815
- properties[parameter.name] = parameter.schema;
9816
- if (parameter.required) {
9817
- required.push(parameter.name);
9818
- requiredProperties.add("headers");
9819
- }
9820
- }
9821
- if (Object.keys(properties).length) schemaData.properties.headers = {
9822
- properties,
9823
- required,
9824
- type: "object"
9825
- };
9826
- }
9827
- if (operation.parameters.path) {
9828
- const properties = {};
9829
- const required = [];
9830
- for (const key in operation.parameters.path) {
9831
- const parameter = operation.parameters.path[key];
9832
- properties[parameter.name] = parameter.schema;
9833
- if (parameter.required) {
9834
- required.push(parameter.name);
9835
- requiredProperties.add("path");
9836
- }
9837
- }
9838
- if (Object.keys(properties).length) schemaData.properties.path = {
9839
- properties,
9840
- required,
9841
- type: "object"
9842
- };
9843
- }
9844
- if (operation.parameters.query) {
9845
- const properties = {};
9846
- const required = [];
9847
- for (const key in operation.parameters.query) {
9848
- const parameter = operation.parameters.query[key];
9849
- properties[parameter.name] = parameter.schema;
9850
- if (parameter.required) {
9851
- required.push(parameter.name);
9852
- requiredProperties.add("query");
9853
- }
9854
- }
9855
- if (Object.keys(properties).length) schemaData.properties.query = {
9856
- properties,
9857
- required,
9858
- type: "object"
9859
- };
9860
- }
9861
- }
9862
- if (operation.body) {
9863
- schemaData.properties.body = operation.body.schema;
9864
- if (operation.body.required) requiredProperties.add("body");
9865
- }
9866
- schemaData.required = [...requiredProperties];
9867
- exportAst$1({
9868
- ast: getAst(schemaData, fromRef(state.path)),
9869
- plugin,
9870
- schema: schemaData,
9871
- state,
9872
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.webhooks), { meta: {
9873
- category: "schema",
9874
- path: fromRef(state.path),
9678
+ const { schema } = buildOperationSchema$1(operation);
9679
+ processor.process({
9680
+ meta: {
9875
9681
  resource: "webhook",
9876
9682
  resourceId: operation.id,
9877
- role: "data",
9878
- tags: fromRef(state.tags),
9879
- tool: "valibot"
9880
- } })
9683
+ role: "data"
9684
+ },
9685
+ naming: plugin.config.webhooks,
9686
+ namingAnchor: operation.id,
9687
+ path: path$1,
9688
+ plugin,
9689
+ schema,
9690
+ tags
9881
9691
  });
9882
9692
  }
9883
- };
9693
+ }
9694
+
9695
+ //#endregion
9696
+ //#region src/plugins/valibot/shared/export.ts
9697
+ function exportAst$1({ ast, meta, naming, namingAnchor, path: path$1, plugin, schema, state, tags }) {
9698
+ const v = plugin.external("valibot.v");
9699
+ const name = pathToName(path$1, { anchor: namingAnchor });
9700
+ const symbol = plugin.symbol(applyNaming(name, naming), { meta: {
9701
+ category: "schema",
9702
+ path: path$1,
9703
+ tags,
9704
+ tool: "valibot",
9705
+ ...meta
9706
+ } });
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));
9708
+ plugin.node(statement);
9709
+ }
9710
+
9711
+ //#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
+ });
9752
+ }
9753
+ return { process: process$1 };
9754
+ }
9884
9755
 
9885
9756
  //#endregion
9886
9757
  //#region src/plugins/valibot/v1/toAst/unknown.ts
9887
- const unknownToAst$3 = ({ plugin }) => {
9758
+ function unknownToAst$3({ plugin }) {
9888
9759
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.unknown).call();
9889
- };
9760
+ }
9890
9761
 
9891
9762
  //#endregion
9892
9763
  //#region src/plugins/valibot/v1/toAst/array.ts
9893
- const arrayToAst$3 = ({ plugin, schema, state }) => {
9764
+ function arrayToAst$3(options) {
9765
+ const { plugin } = options;
9766
+ let { schema } = options;
9894
9767
  const result = { pipes: [] };
9895
9768
  const v = plugin.external("valibot.v");
9896
9769
  const functionName = $(v).attr(identifiers$1.schemas.array);
9897
9770
  if (!schema.items) {
9898
9771
  const expression = functionName.call(unknownToAst$3({
9899
- plugin,
9900
- schema: { type: "unknown" },
9901
- state
9772
+ ...options,
9773
+ schema: { type: "unknown" }
9902
9774
  }));
9903
9775
  result.pipes.push(expression);
9904
9776
  } else {
9905
9777
  schema = deduplicateSchema({ schema });
9906
9778
  const itemExpressions = schema.items.map((item, index) => {
9907
9779
  const itemAst = irSchemaToAst$3({
9908
- plugin,
9780
+ ...options,
9909
9781
  schema: item,
9910
9782
  state: {
9911
- ...state,
9783
+ ...options.state,
9912
9784
  path: ref([
9913
- ...fromRef(state.path),
9785
+ ...fromRef(options.state.path),
9914
9786
  "items",
9915
9787
  index
9916
9788
  ])
@@ -9925,9 +9797,8 @@ const arrayToAst$3 = ({ plugin, schema, state }) => {
9925
9797
  } else {
9926
9798
  if (schema.logicalOperator === "and") {}
9927
9799
  const expression = functionName.call(unknownToAst$3({
9928
- plugin,
9929
- schema: { type: "unknown" },
9930
- state
9800
+ ...options,
9801
+ schema: { type: "unknown" }
9931
9802
  }));
9932
9803
  result.pipes.push(expression);
9933
9804
  }
@@ -9946,11 +9817,11 @@ const arrayToAst$3 = ({ plugin, schema, state }) => {
9946
9817
  }
9947
9818
  }
9948
9819
  return result;
9949
- };
9820
+ }
9950
9821
 
9951
9822
  //#endregion
9952
9823
  //#region src/plugins/valibot/v1/toAst/boolean.ts
9953
- const booleanToAst$3 = ({ plugin, schema }) => {
9824
+ function booleanToAst$3({ plugin, schema }) {
9954
9825
  const pipes$1 = [];
9955
9826
  const v = plugin.external("valibot.v");
9956
9827
  if (typeof schema.const === "boolean") {
@@ -9959,7 +9830,7 @@ const booleanToAst$3 = ({ plugin, schema }) => {
9959
9830
  }
9960
9831
  pipes$1.push($(v).attr(identifiers$1.schemas.boolean).call());
9961
9832
  return pipesToNode(pipes$1, plugin);
9962
- };
9833
+ }
9963
9834
 
9964
9835
  //#endregion
9965
9836
  //#region src/plugins/valibot/v1/toAst/enum.ts
@@ -9997,7 +9868,7 @@ function enumResolver$3(ctx$1) {
9997
9868
  if (nullableExpression) return nullableExpression;
9998
9869
  return ctx$1.pipes.current;
9999
9870
  }
10000
- const enumToAst$3 = ({ plugin, schema, state }) => {
9871
+ function enumToAst$3({ plugin, schema, state }) {
10001
9872
  const v = plugin.external("valibot.v");
10002
9873
  const { enumMembers } = itemsNode$3({
10003
9874
  $,
@@ -10039,19 +9910,19 @@ const enumToAst$3 = ({ plugin, schema, state }) => {
10039
9910
  const resolver = plugin.config["~resolvers"]?.enum;
10040
9911
  const node = resolver?.(ctx$1) ?? enumResolver$3(ctx$1);
10041
9912
  return ctx$1.pipes.toNode(node, plugin);
10042
- };
9913
+ }
10043
9914
 
10044
9915
  //#endregion
10045
9916
  //#region src/plugins/valibot/v1/toAst/never.ts
10046
- const neverToAst$3 = ({ plugin }) => {
9917
+ function neverToAst$3({ plugin }) {
10047
9918
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.never).call();
10048
- };
9919
+ }
10049
9920
 
10050
9921
  //#endregion
10051
9922
  //#region src/plugins/valibot/v1/toAst/null.ts
10052
- const nullToAst$3 = ({ plugin }) => {
9923
+ function nullToAst$3({ plugin }) {
10053
9924
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.null).call();
10054
- };
9925
+ }
10055
9926
 
10056
9927
  //#endregion
10057
9928
  //#region src/plugins/shared/utils/formats.ts
@@ -10125,7 +9996,7 @@ function numberResolver$3(ctx$1) {
10125
9996
  if (maxNode$4) ctx$1.pipes.push(ctx$1.pipes.current, maxNode$4);
10126
9997
  return ctx$1.pipes.current;
10127
9998
  }
10128
- const numberToNode$3 = ({ plugin, schema }) => {
9999
+ function numberToNode$3({ plugin, schema }) {
10129
10000
  const ctx$1 = {
10130
10001
  $,
10131
10002
  nodes: {
@@ -10150,7 +10021,7 @@ const numberToNode$3 = ({ plugin, schema }) => {
10150
10021
  const resolver = plugin.config["~resolvers"]?.number;
10151
10022
  const node = resolver?.(ctx$1) ?? numberResolver$3(ctx$1);
10152
10023
  return ctx$1.pipes.toNode(node, plugin);
10153
- };
10024
+ }
10154
10025
 
10155
10026
  //#endregion
10156
10027
  //#region src/plugins/valibot/v1/toAst/object.ts
@@ -10159,7 +10030,7 @@ function additionalPropertiesNode$3(ctx$1) {
10159
10030
  if (!schema.additionalProperties || !schema.additionalProperties.type) return;
10160
10031
  if (schema.additionalProperties.type === "never") return null;
10161
10032
  const additionalAst = irSchemaToAst$3({
10162
- plugin,
10033
+ ...ctx$1,
10163
10034
  schema: schema.additionalProperties,
10164
10035
  state: {
10165
10036
  ...ctx$1.utils.state,
@@ -10190,8 +10061,8 @@ function shapeNode$3(ctx$1) {
10190
10061
  for (const name in schema.properties) {
10191
10062
  const property = schema.properties[name];
10192
10063
  const propertyAst = irSchemaToAst$3({
10064
+ ...ctx$1,
10193
10065
  optional: !schema.required?.includes(name),
10194
- plugin,
10195
10066
  schema: property,
10196
10067
  state: {
10197
10068
  ...ctx$1.utils.state,
@@ -10207,8 +10078,10 @@ function shapeNode$3(ctx$1) {
10207
10078
  }
10208
10079
  return shape;
10209
10080
  }
10210
- const objectToAst$3 = ({ plugin, schema, state }) => {
10081
+ function objectToAst$3(options) {
10082
+ const { plugin } = options;
10211
10083
  const ctx$1 = {
10084
+ ...options,
10212
10085
  $,
10213
10086
  nodes: {
10214
10087
  additionalProperties: additionalPropertiesNode$3,
@@ -10219,19 +10092,17 @@ const objectToAst$3 = ({ plugin, schema, state }) => {
10219
10092
  ...pipes,
10220
10093
  current: []
10221
10094
  },
10222
- plugin,
10223
- schema,
10224
10095
  symbols: { v: plugin.external("valibot.v") },
10225
10096
  utils: {
10226
10097
  ast: {},
10227
- state
10098
+ state: options.state
10228
10099
  }
10229
10100
  };
10230
10101
  const resolver = plugin.config["~resolvers"]?.object;
10231
10102
  const node = resolver?.(ctx$1) ?? objectResolver$3(ctx$1);
10232
10103
  ctx$1.utils.ast.pipes = [ctx$1.pipes.toNode(node, plugin)];
10233
10104
  return ctx$1.utils.ast;
10234
- };
10105
+ }
10235
10106
 
10236
10107
  //#endregion
10237
10108
  //#region src/plugins/valibot/v1/toAst/string.ts
@@ -10302,7 +10173,7 @@ function stringResolver$3(ctx$1) {
10302
10173
  if (patternNode$4) ctx$1.pipes.push(ctx$1.pipes.current, patternNode$4);
10303
10174
  return ctx$1.pipes.current;
10304
10175
  }
10305
- const stringToNode$3 = ({ plugin, schema }) => {
10176
+ function stringToNode$3({ plugin, schema }) {
10306
10177
  const ctx$1 = {
10307
10178
  $,
10308
10179
  nodes: {
@@ -10325,11 +10196,12 @@ const stringToNode$3 = ({ plugin, schema }) => {
10325
10196
  const resolver = plugin.config["~resolvers"]?.string;
10326
10197
  const node = resolver?.(ctx$1) ?? stringResolver$3(ctx$1);
10327
10198
  return ctx$1.pipes.toNode(node, plugin);
10328
- };
10199
+ }
10329
10200
 
10330
10201
  //#endregion
10331
10202
  //#region src/plugins/valibot/v1/toAst/tuple.ts
10332
- const tupleToAst$3 = ({ plugin, schema, state }) => {
10203
+ function tupleToAst$3(options) {
10204
+ const { plugin, schema } = options;
10333
10205
  const result = {};
10334
10206
  const v = plugin.external("valibot.v");
10335
10207
  if (schema.const && Array.isArray(schema.const)) {
@@ -10340,12 +10212,12 @@ const tupleToAst$3 = ({ plugin, schema, state }) => {
10340
10212
  if (schema.items) {
10341
10213
  const tupleElements = schema.items.map((item, index) => {
10342
10214
  const schemaPipes = irSchemaToAst$3({
10343
- plugin,
10215
+ ...options,
10344
10216
  schema: item,
10345
10217
  state: {
10346
- ...state,
10218
+ ...options.state,
10347
10219
  path: ref([
10348
- ...fromRef(state.path),
10220
+ ...fromRef(options.state.path),
10349
10221
  "items",
10350
10222
  index
10351
10223
  ])
@@ -10358,27 +10230,26 @@ const tupleToAst$3 = ({ plugin, schema, state }) => {
10358
10230
  return result;
10359
10231
  }
10360
10232
  return { pipes: [unknownToAst$3({
10361
- plugin,
10362
- schema: { type: "unknown" },
10363
- state
10233
+ ...options,
10234
+ schema: { type: "unknown" }
10364
10235
  })] };
10365
- };
10236
+ }
10366
10237
 
10367
10238
  //#endregion
10368
10239
  //#region src/plugins/valibot/v1/toAst/undefined.ts
10369
- const undefinedToAst$3 = ({ plugin }) => {
10240
+ function undefinedToAst$3({ plugin }) {
10370
10241
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.undefined).call();
10371
- };
10242
+ }
10372
10243
 
10373
10244
  //#endregion
10374
10245
  //#region src/plugins/valibot/v1/toAst/void.ts
10375
- const voidToAst$3 = ({ plugin }) => {
10246
+ function voidToAst$3({ plugin }) {
10376
10247
  return $(plugin.external("valibot.v")).attr(identifiers$1.schemas.void).call();
10377
- };
10248
+ }
10378
10249
 
10379
10250
  //#endregion
10380
10251
  //#region src/plugins/valibot/v1/toAst/index.ts
10381
- const irSchemaWithTypeToAst$3 = ({ schema, ...args }) => {
10252
+ function irSchemaWithTypeToAst$3({ schema, ...args }) {
10382
10253
  switch (schema.type) {
10383
10254
  case "array": return { expression: pipesToNode(arrayToAst$3({
10384
10255
  ...args,
@@ -10436,11 +10307,24 @@ const irSchemaWithTypeToAst$3 = ({ schema, ...args }) => {
10436
10307
  schema
10437
10308
  }) };
10438
10309
  }
10439
- };
10310
+ }
10440
10311
 
10441
10312
  //#endregion
10442
10313
  //#region src/plugins/valibot/v1/plugin.ts
10443
- const irSchemaToAst$3 = ({ optional, plugin, schema, state }) => {
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
+ }
10444
10328
  const ast = { pipes: [] };
10445
10329
  const v = plugin.external("valibot.v");
10446
10330
  if (schema.$ref) {
@@ -10463,6 +10347,7 @@ const irSchemaToAst$3 = ({ optional, plugin, schema, state }) => {
10463
10347
  const typeAst = irSchemaWithTypeToAst$3({
10464
10348
  plugin,
10465
10349
  schema,
10350
+ schemaExtractor,
10466
10351
  state
10467
10352
  });
10468
10353
  ast.typeName = typeAst.anyType;
@@ -10478,6 +10363,7 @@ const irSchemaToAst$3 = ({ optional, plugin, schema, state }) => {
10478
10363
  return pipesToNode(irSchemaToAst$3({
10479
10364
  plugin,
10480
10365
  schema: item,
10366
+ schemaExtractor,
10481
10367
  state: {
10482
10368
  ...state,
10483
10369
  path: ref([
@@ -10507,6 +10393,7 @@ const irSchemaToAst$3 = ({ optional, plugin, schema, state }) => {
10507
10393
  const typeAst = irSchemaWithTypeToAst$3({
10508
10394
  plugin,
10509
10395
  schema: { type: "unknown" },
10396
+ schemaExtractor,
10510
10397
  state
10511
10398
  });
10512
10399
  ast.typeName = typeAst.anyType;
@@ -10521,30 +10408,7 @@ const irSchemaToAst$3 = ({ optional, plugin, schema, state }) => {
10521
10408
  else if (optional) ast.pipes = [$(v).attr(identifiers$1.schemas.optional).call(pipesToNode(ast.pipes, plugin))];
10522
10409
  }
10523
10410
  return ast;
10524
- };
10525
- const handleComponent$3 = ({ plugin, schema, state }) => {
10526
- const $ref = pathToJsonPointer(fromRef(state.path));
10527
- const ast = irSchemaToAst$3({
10528
- plugin,
10529
- schema,
10530
- state
10531
- });
10532
- const baseName = refToName($ref);
10533
- exportAst$1({
10534
- ast,
10535
- plugin,
10536
- schema,
10537
- state,
10538
- symbol: plugin.symbol(applyNaming(baseName, plugin.config.definitions), { meta: {
10539
- category: "schema",
10540
- path: fromRef(state.path),
10541
- resource: "definition",
10542
- resourceId: $ref,
10543
- tags: fromRef(state.tags),
10544
- tool: "valibot"
10545
- } })
10546
- });
10547
- };
10411
+ }
10548
10412
  const handlerV1 = ({ plugin }) => {
10549
10413
  plugin.symbol("v", {
10550
10414
  external: "valibot",
@@ -10554,68 +10418,64 @@ const handlerV1 = ({ plugin }) => {
10554
10418
  resource: "valibot.v"
10555
10419
  }
10556
10420
  });
10421
+ const processor = createProcessor$3(plugin);
10557
10422
  plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
10558
- const state = refs({
10559
- hasLazyExpression: false,
10560
- path: event._path,
10561
- tags: event.tags
10562
- });
10563
10423
  switch (event.type) {
10564
10424
  case "operation":
10565
10425
  irOperationToAst$1({
10566
- getAst: (schema, path$1) => {
10567
- return irSchemaToAst$3({
10568
- plugin,
10569
- schema,
10570
- state: refs({
10571
- hasLazyExpression: false,
10572
- path: path$1,
10573
- tags: event.tags
10574
- })
10575
- });
10576
- },
10577
10426
  operation: event.operation,
10427
+ path: event._path,
10578
10428
  plugin,
10579
- state
10429
+ processor,
10430
+ tags: event.tags
10580
10431
  });
10581
10432
  break;
10582
10433
  case "parameter":
10583
- handleComponent$3({
10434
+ processor.process({
10435
+ meta: {
10436
+ resource: "definition",
10437
+ resourceId: pathToJsonPointer(event._path)
10438
+ },
10439
+ naming: plugin.config.definitions,
10440
+ path: event._path,
10584
10441
  plugin,
10585
10442
  schema: event.parameter.schema,
10586
- state
10443
+ tags: event.tags
10587
10444
  });
10588
10445
  break;
10589
10446
  case "requestBody":
10590
- handleComponent$3({
10447
+ processor.process({
10448
+ meta: {
10449
+ resource: "definition",
10450
+ resourceId: pathToJsonPointer(event._path)
10451
+ },
10452
+ naming: plugin.config.definitions,
10453
+ path: event._path,
10591
10454
  plugin,
10592
10455
  schema: event.requestBody.schema,
10593
- state
10456
+ tags: event.tags
10594
10457
  });
10595
10458
  break;
10596
10459
  case "schema":
10597
- handleComponent$3({
10460
+ processor.process({
10461
+ meta: {
10462
+ resource: "definition",
10463
+ resourceId: pathToJsonPointer(event._path)
10464
+ },
10465
+ naming: plugin.config.definitions,
10466
+ path: event._path,
10598
10467
  plugin,
10599
10468
  schema: event.schema,
10600
- state
10469
+ tags: event.tags
10601
10470
  });
10602
10471
  break;
10603
10472
  case "webhook":
10604
10473
  irWebhookToAst$1({
10605
- getAst: (schema, path$1) => {
10606
- return irSchemaToAst$3({
10607
- plugin,
10608
- schema,
10609
- state: refs({
10610
- hasLazyExpression: false,
10611
- path: path$1,
10612
- tags: event.tags
10613
- })
10614
- });
10615
- },
10616
10474
  operation: event.operation,
10475
+ path: event._path,
10617
10476
  plugin,
10618
- state
10477
+ processor,
10478
+ tags: event.tags
10619
10479
  });
10620
10480
  break;
10621
10481
  }
@@ -10645,11 +10505,7 @@ const defaultConfig$1 = {
10645
10505
  enabled: true,
10646
10506
  name: "v{{name}}"
10647
10507
  },
10648
- mappers: {
10649
- boolean: (enabled) => ({ enabled }),
10650
- function: (name) => ({ name }),
10651
- string: (name) => ({ name })
10652
- },
10508
+ mappers,
10653
10509
  value: plugin.config.definitions
10654
10510
  });
10655
10511
  plugin.config.requests = context.valueToObject({
@@ -10658,11 +10514,7 @@ const defaultConfig$1 = {
10658
10514
  enabled: true,
10659
10515
  name: "v{{name}}Data"
10660
10516
  },
10661
- mappers: {
10662
- boolean: (enabled) => ({ enabled }),
10663
- function: (name) => ({ name }),
10664
- string: (name) => ({ name })
10665
- },
10517
+ mappers,
10666
10518
  value: plugin.config.requests
10667
10519
  });
10668
10520
  plugin.config.responses = context.valueToObject({
@@ -10671,11 +10523,7 @@ const defaultConfig$1 = {
10671
10523
  enabled: true,
10672
10524
  name: "v{{name}}Response"
10673
10525
  },
10674
- mappers: {
10675
- boolean: (enabled) => ({ enabled }),
10676
- function: (name) => ({ name }),
10677
- string: (name) => ({ name })
10678
- },
10526
+ mappers,
10679
10527
  value: plugin.config.responses
10680
10528
  });
10681
10529
  plugin.config.webhooks = context.valueToObject({
@@ -10684,11 +10532,7 @@ const defaultConfig$1 = {
10684
10532
  enabled: true,
10685
10533
  name: "v{{name}}WebhookRequest"
10686
10534
  },
10687
- mappers: {
10688
- boolean: (enabled) => ({ enabled }),
10689
- function: (name) => ({ name }),
10690
- string: (name) => ({ name })
10691
- },
10535
+ mappers,
10692
10536
  value: plugin.config.webhooks
10693
10537
  });
10694
10538
  },
@@ -10972,21 +10816,9 @@ var Api = class {
10972
10816
  }
10973
10817
  };
10974
10818
 
10975
- //#endregion
10976
- //#region src/plugins/zod/shared/export.ts
10977
- const exportAst = ({ ast, plugin, schema, symbol, typeInferSymbol }) => {
10978
- const z = plugin.external("zod.z");
10979
- 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);
10980
- plugin.node(statement);
10981
- if (typeInferSymbol) {
10982
- const inferType = $.type.alias(typeInferSymbol).export().type($.type(z).attr(identifiers.infer).generic($(symbol).typeofType()));
10983
- plugin.node(inferType);
10984
- }
10985
- };
10986
-
10987
10819
  //#endregion
10988
10820
  //#region src/plugins/zod/shared/module.ts
10989
- const getZodModule = ({ plugin }) => {
10821
+ function getZodModule({ plugin }) {
10990
10822
  const version = plugin.package.getVersion("zod");
10991
10823
  if (version) {
10992
10824
  if (plugin.package.satisfies(version, "<4.0.0")) switch (plugin.config.compatibilityVersion) {
@@ -11002,235 +10834,187 @@ const getZodModule = ({ plugin }) => {
11002
10834
  default: return "zod";
11003
10835
  case "mini": return "zod/mini";
11004
10836
  }
11005
- };
10837
+ }
11006
10838
 
11007
10839
  //#endregion
11008
- //#region src/plugins/zod/shared/operation.ts
11009
- const irOperationToAst = ({ getAst, operation, plugin, state }) => {
11010
- if (plugin.config.requests.enabled) {
11011
- const requiredProperties = /* @__PURE__ */ new Set();
11012
- const schemaData = {
11013
- properties: {
11014
- body: { type: "never" },
11015
- path: { type: "never" },
11016
- query: { type: "never" }
11017
- },
11018
- type: "object"
11019
- };
11020
- if (operation.parameters) {
11021
- if (operation.parameters.header) {
11022
- const properties = {};
11023
- const required = [];
11024
- for (const key in operation.parameters.header) {
11025
- const parameter = operation.parameters.header[key];
11026
- properties[parameter.name] = parameter.schema;
11027
- if (parameter.required) {
11028
- required.push(parameter.name);
11029
- requiredProperties.add("headers");
11030
- }
11031
- }
11032
- if (Object.keys(properties).length) schemaData.properties.headers = {
11033
- properties,
11034
- required,
11035
- type: "object"
11036
- };
11037
- }
11038
- if (operation.parameters.path) {
11039
- const properties = {};
11040
- const required = [];
11041
- for (const key in operation.parameters.path) {
11042
- const parameter = operation.parameters.path[key];
11043
- properties[parameter.name] = parameter.schema;
11044
- if (parameter.required) {
11045
- required.push(parameter.name);
11046
- requiredProperties.add("path");
11047
- }
11048
- }
11049
- if (Object.keys(properties).length) schemaData.properties.path = {
11050
- properties,
11051
- required,
11052
- type: "object"
11053
- };
11054
- }
11055
- if (operation.parameters.query) {
11056
- const properties = {};
11057
- const required = [];
11058
- for (const key in operation.parameters.query) {
11059
- const parameter = operation.parameters.query[key];
11060
- properties[parameter.name] = parameter.schema;
11061
- if (parameter.required) {
11062
- required.push(parameter.name);
11063
- requiredProperties.add("query");
11064
- }
11065
- }
11066
- if (Object.keys(properties).length) schemaData.properties.query = {
11067
- properties,
11068
- required,
11069
- type: "object"
11070
- };
10840
+ //#region src/plugins/zod/shared/operation-schema.ts
10841
+ function buildOperationSchema(operation) {
10842
+ const requiredProperties = /* @__PURE__ */ new Set();
10843
+ const schema = {
10844
+ properties: {
10845
+ body: { type: "never" },
10846
+ path: { type: "never" },
10847
+ query: { type: "never" }
10848
+ },
10849
+ type: "object"
10850
+ };
10851
+ if (operation.parameters) for (const location of [
10852
+ "header",
10853
+ "path",
10854
+ "query"
10855
+ ]) {
10856
+ const params = operation.parameters[location];
10857
+ if (!params) continue;
10858
+ const properties = {};
10859
+ const required = [];
10860
+ const propKey = location === "header" ? "headers" : location;
10861
+ for (const key in params) {
10862
+ const parameter = params[key];
10863
+ properties[parameter.name] = parameter.schema;
10864
+ if (parameter.required) {
10865
+ required.push(parameter.name);
10866
+ requiredProperties.add(propKey);
11071
10867
  }
11072
10868
  }
11073
- if (operation.body) {
11074
- schemaData.properties.body = operation.body.schema;
11075
- if (operation.body.required) requiredProperties.add("body");
11076
- }
11077
- schemaData.required = [...requiredProperties];
11078
- exportAst({
11079
- ast: getAst(schemaData, fromRef(state.path)),
11080
- plugin,
11081
- schema: schemaData,
11082
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.requests), { meta: {
11083
- category: "schema",
11084
- path: fromRef(state.path),
11085
- resource: "operation",
11086
- resourceId: operation.id,
11087
- role: "data",
11088
- tags: fromRef(state.tags),
11089
- tool: "zod"
11090
- } }),
11091
- typeInferSymbol: plugin.config.requests.types.infer.enabled ? plugin.symbol(applyNaming(operation.id, plugin.config.requests.types.infer), { meta: {
11092
- category: "type",
11093
- path: fromRef(state.path),
10869
+ if (Object.keys(properties).length) schema.properties[propKey] = {
10870
+ properties,
10871
+ required,
10872
+ type: "object"
10873
+ };
10874
+ }
10875
+ if (operation.body) {
10876
+ schema.properties.body = operation.body.schema;
10877
+ if (operation.body.required) requiredProperties.add("body");
10878
+ }
10879
+ schema.required = [...requiredProperties];
10880
+ return {
10881
+ required: schema.required,
10882
+ schema
10883
+ };
10884
+ }
10885
+
10886
+ //#endregion
10887
+ //#region src/plugins/zod/shared/operation.ts
10888
+ function irOperationToAst({ operation, path: path$1, plugin, processor, tags }) {
10889
+ if (plugin.config.requests.enabled) {
10890
+ const { schema } = buildOperationSchema(operation);
10891
+ processor.process({
10892
+ meta: {
11094
10893
  resource: "operation",
11095
10894
  resourceId: operation.id,
11096
- role: "data",
11097
- tags: fromRef(state.tags),
11098
- tool: "zod",
11099
- variant: "infer"
11100
- } }) : void 0
10895
+ role: "data"
10896
+ },
10897
+ naming: plugin.config.requests,
10898
+ namingAnchor: operation.id,
10899
+ path: path$1,
10900
+ plugin,
10901
+ schema,
10902
+ tags
11101
10903
  });
11102
10904
  }
11103
10905
  if (plugin.config.responses.enabled) {
11104
10906
  if (operation.responses) {
11105
10907
  const { response } = operationResponsesMap(operation);
11106
- if (response) {
11107
- const path$1 = [...fromRef(state.path), "responses"];
11108
- exportAst({
11109
- ast: getAst(response, path$1),
11110
- plugin,
11111
- schema: response,
11112
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.responses), { meta: {
11113
- category: "schema",
11114
- path: path$1,
11115
- resource: "operation",
11116
- resourceId: operation.id,
11117
- role: "responses",
11118
- tags: fromRef(state.tags),
11119
- tool: "zod"
11120
- } }),
11121
- typeInferSymbol: plugin.config.responses.types.infer.enabled ? plugin.symbol(applyNaming(operation.id, plugin.config.responses.types.infer), { meta: {
11122
- category: "type",
11123
- path: path$1,
11124
- resource: "operation",
11125
- resourceId: operation.id,
11126
- role: "responses",
11127
- tags: fromRef(state.tags),
11128
- tool: "zod",
11129
- variant: "infer"
11130
- } }) : void 0
11131
- });
11132
- }
10908
+ if (response) processor.process({
10909
+ meta: {
10910
+ resource: "operation",
10911
+ resourceId: operation.id,
10912
+ role: "responses"
10913
+ },
10914
+ naming: plugin.config.responses,
10915
+ namingAnchor: operation.id,
10916
+ path: [...path$1, "responses"],
10917
+ plugin,
10918
+ schema: response,
10919
+ tags
10920
+ });
11133
10921
  }
11134
10922
  }
11135
- };
10923
+ }
10924
+
10925
+ //#endregion
10926
+ //#region src/plugins/zod/shared/webhook.ts
10927
+ function irWebhookToAst({ operation, path: path$1, plugin, processor, tags }) {
10928
+ if (plugin.config.webhooks.enabled) {
10929
+ const { schema } = buildOperationSchema(operation);
10930
+ processor.process({
10931
+ meta: {
10932
+ resource: "webhook",
10933
+ resourceId: operation.id,
10934
+ role: "data"
10935
+ },
10936
+ naming: plugin.config.webhooks,
10937
+ namingAnchor: operation.id,
10938
+ path: path$1,
10939
+ plugin,
10940
+ schema,
10941
+ tags
10942
+ });
10943
+ }
10944
+ }
10945
+
10946
+ //#endregion
10947
+ //#region src/plugins/zod/shared/export.ts
10948
+ function exportAst({ ast, meta, naming, namingAnchor, path: path$1, plugin, schema, tags }) {
10949
+ const z = plugin.external("zod.z");
10950
+ const name = pathToName(path$1, { anchor: namingAnchor });
10951
+ const symbol = plugin.symbol(applyNaming(name, naming), { meta: {
10952
+ category: "schema",
10953
+ path: path$1,
10954
+ tags,
10955
+ tool: "zod",
10956
+ ...meta
10957
+ } });
10958
+ const typeInferSymbol = naming.types.infer.enabled ? plugin.symbol(applyNaming(name, naming.types.infer), { meta: {
10959
+ category: "type",
10960
+ path: path$1,
10961
+ tags,
10962
+ tool: "zod",
10963
+ variant: "infer",
10964
+ ...meta
10965
+ } }) : 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);
10967
+ plugin.node(statement);
10968
+ if (typeInferSymbol) {
10969
+ const inferType = $.type.alias(typeInferSymbol).export().type($.type(z).attr(identifiers.infer).generic($(symbol).typeofType()));
10970
+ plugin.node(inferType);
10971
+ }
10972
+ }
11136
10973
 
11137
10974
  //#endregion
11138
- //#region src/plugins/zod/shared/webhook.ts
11139
- const irWebhookToAst = ({ getAst, operation, plugin, state }) => {
11140
- if (plugin.config.webhooks.enabled) {
11141
- const requiredProperties = /* @__PURE__ */ new Set();
11142
- const schemaData = {
11143
- properties: {
11144
- body: { type: "never" },
11145
- path: { type: "never" },
11146
- query: { type: "never" }
11147
- },
11148
- type: "object"
11149
- };
11150
- if (operation.parameters) {
11151
- if (operation.parameters.header) {
11152
- const properties = {};
11153
- const required = [];
11154
- for (const key in operation.parameters.header) {
11155
- const parameter = operation.parameters.header[key];
11156
- properties[parameter.name] = parameter.schema;
11157
- if (parameter.required) {
11158
- required.push(parameter.name);
11159
- requiredProperties.add("headers");
11160
- }
11161
- }
11162
- if (Object.keys(properties).length) schemaData.properties.headers = {
11163
- properties,
11164
- required,
11165
- type: "object"
11166
- };
11167
- }
11168
- if (operation.parameters.path) {
11169
- const properties = {};
11170
- const required = [];
11171
- for (const key in operation.parameters.path) {
11172
- const parameter = operation.parameters.path[key];
11173
- properties[parameter.name] = parameter.schema;
11174
- if (parameter.required) {
11175
- required.push(parameter.name);
11176
- requiredProperties.add("path");
11177
- }
11178
- }
11179
- if (Object.keys(properties).length) schemaData.properties.path = {
11180
- properties,
11181
- required,
11182
- type: "object"
11183
- };
11184
- }
11185
- if (operation.parameters.query) {
11186
- const properties = {};
11187
- const required = [];
11188
- for (const key in operation.parameters.query) {
11189
- const parameter = operation.parameters.query[key];
11190
- properties[parameter.name] = parameter.schema;
11191
- if (parameter.required) {
11192
- required.push(parameter.name);
11193
- requiredProperties.add("query");
11194
- }
11195
- }
11196
- if (Object.keys(properties).length) schemaData.properties.query = {
11197
- properties,
11198
- required,
11199
- type: "object"
11200
- };
11201
- }
11202
- }
11203
- if (operation.body) {
11204
- schemaData.properties.body = operation.body.schema;
11205
- if (operation.body.required) requiredProperties.add("body");
11206
- }
11207
- schemaData.required = [...requiredProperties];
11208
- exportAst({
11209
- ast: getAst(schemaData, fromRef(state.path)),
11210
- plugin,
11211
- schema: schemaData,
11212
- symbol: plugin.symbol(applyNaming(operation.id, plugin.config.webhooks), { meta: {
11213
- category: "schema",
11214
- path: fromRef(state.path),
11215
- resource: "webhook",
11216
- resourceId: operation.id,
11217
- role: "data",
11218
- tags: fromRef(state.tags),
11219
- tool: "zod"
11220
- } }),
11221
- typeInferSymbol: plugin.config.webhooks.types.infer.enabled ? plugin.symbol(applyNaming(operation.id, plugin.config.webhooks.types.infer), { meta: {
11222
- category: "type",
11223
- path: fromRef(state.path),
11224
- resource: "webhook",
11225
- resourceId: operation.id,
11226
- role: "data",
11227
- tags: fromRef(state.tags),
11228
- tool: "zod",
11229
- variant: "infer"
11230
- } }) : void 0
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
+ });
11231
11014
  });
11232
11015
  }
11233
- };
11016
+ return { process: process$1 };
11017
+ }
11234
11018
 
11235
11019
  //#endregion
11236
11020
  //#region src/plugins/zod/mini/toAst/unknown.ts
@@ -11294,7 +11078,7 @@ const arrayToAst$2 = ({ plugin, schema, state }) => {
11294
11078
 
11295
11079
  //#endregion
11296
11080
  //#region src/plugins/zod/mini/toAst/boolean.ts
11297
- const booleanToAst$2 = ({ plugin, schema }) => {
11081
+ function booleanToAst$2({ plugin, schema }) {
11298
11082
  const result = {};
11299
11083
  let chain;
11300
11084
  const z = plugin.external("zod.z");
@@ -11306,7 +11090,7 @@ const booleanToAst$2 = ({ plugin, schema }) => {
11306
11090
  chain = $(z).attr(identifiers.boolean).call();
11307
11091
  result.expression = chain;
11308
11092
  return result;
11309
- };
11093
+ }
11310
11094
 
11311
11095
  //#endregion
11312
11096
  //#region src/plugins/zod/mini/toAst/enum.ts
@@ -11724,7 +11508,7 @@ const voidToAst$2 = ({ plugin }) => {
11724
11508
 
11725
11509
  //#endregion
11726
11510
  //#region src/plugins/zod/mini/toAst/index.ts
11727
- const irSchemaWithTypeToAst$2 = ({ schema, ...args }) => {
11511
+ function irSchemaWithTypeToAst$2({ schema, ...args }) {
11728
11512
  switch (schema.type) {
11729
11513
  case "array": return arrayToAst$2({
11730
11514
  ...args,
@@ -11782,11 +11566,24 @@ const irSchemaWithTypeToAst$2 = ({ schema, ...args }) => {
11782
11566
  schema
11783
11567
  });
11784
11568
  }
11785
- };
11569
+ }
11786
11570
 
11787
11571
  //#endregion
11788
11572
  //#region src/plugins/zod/mini/plugin.ts
11789
- const irSchemaToAst$2 = ({ optional, plugin, schema, state }) => {
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
+ }
11790
11587
  let ast = {};
11791
11588
  const z = plugin.external("zod.z");
11792
11589
  if (schema.$ref) {
@@ -11859,38 +11656,7 @@ const irSchemaToAst$2 = ({ optional, plugin, schema, state }) => {
11859
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));
11860
11657
  }
11861
11658
  return ast;
11862
- };
11863
- const handleComponent$2 = ({ plugin, schema, state }) => {
11864
- const $ref = pathToJsonPointer(fromRef(state.path));
11865
- const ast = irSchemaToAst$2({
11866
- plugin,
11867
- schema,
11868
- state
11869
- });
11870
- const baseName = refToName($ref);
11871
- exportAst({
11872
- ast,
11873
- plugin,
11874
- schema,
11875
- symbol: plugin.symbol(applyNaming(baseName, plugin.config.definitions), { meta: {
11876
- category: "schema",
11877
- path: fromRef(state.path),
11878
- resource: "definition",
11879
- resourceId: $ref,
11880
- tags: fromRef(state.tags),
11881
- tool: "zod"
11882
- } }),
11883
- typeInferSymbol: plugin.config.definitions.types.infer.enabled ? plugin.symbol(applyNaming(baseName, plugin.config.definitions.types.infer), { meta: {
11884
- category: "type",
11885
- path: fromRef(state.path),
11886
- resource: "definition",
11887
- resourceId: $ref,
11888
- tags: fromRef(state.tags),
11889
- tool: "zod",
11890
- variant: "infer"
11891
- } }) : void 0
11892
- });
11893
- };
11659
+ }
11894
11660
  const handlerMini = ({ plugin }) => {
11895
11661
  plugin.symbol("z", {
11896
11662
  external: getZodModule({ plugin }),
@@ -11900,74 +11666,115 @@ const handlerMini = ({ plugin }) => {
11900
11666
  resource: "zod.z"
11901
11667
  }
11902
11668
  });
11669
+ const processor = createProcessor$2(plugin);
11903
11670
  plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
11904
- const state = refs({
11905
- hasLazyExpression: false,
11906
- path: event._path,
11907
- tags: event.tags
11908
- });
11909
11671
  switch (event.type) {
11910
11672
  case "operation":
11911
11673
  irOperationToAst({
11912
- getAst: (schema, path$1) => {
11913
- return irSchemaToAst$2({
11914
- plugin,
11915
- schema,
11916
- state: refs({
11917
- hasLazyExpression: false,
11918
- path: path$1,
11919
- tags: event.tags
11920
- })
11921
- });
11922
- },
11923
11674
  operation: event.operation,
11675
+ path: event._path,
11924
11676
  plugin,
11925
- state
11677
+ processor,
11678
+ tags: event.tags
11926
11679
  });
11927
11680
  break;
11928
11681
  case "parameter":
11929
- handleComponent$2({
11682
+ processor.process({
11683
+ meta: {
11684
+ resource: "definition",
11685
+ resourceId: pathToJsonPointer(event._path)
11686
+ },
11687
+ naming: plugin.config.definitions,
11688
+ path: event._path,
11930
11689
  plugin,
11931
11690
  schema: event.parameter.schema,
11932
- state
11691
+ tags: event.tags
11933
11692
  });
11934
11693
  break;
11935
11694
  case "requestBody":
11936
- handleComponent$2({
11695
+ processor.process({
11696
+ meta: {
11697
+ resource: "definition",
11698
+ resourceId: pathToJsonPointer(event._path)
11699
+ },
11700
+ naming: plugin.config.definitions,
11701
+ path: event._path,
11937
11702
  plugin,
11938
11703
  schema: event.requestBody.schema,
11939
- state
11704
+ tags: event.tags
11940
11705
  });
11941
11706
  break;
11942
11707
  case "schema":
11943
- handleComponent$2({
11708
+ processor.process({
11709
+ meta: {
11710
+ resource: "definition",
11711
+ resourceId: pathToJsonPointer(event._path)
11712
+ },
11713
+ naming: plugin.config.definitions,
11714
+ path: event._path,
11944
11715
  plugin,
11945
11716
  schema: event.schema,
11946
- state
11717
+ tags: event.tags
11947
11718
  });
11948
11719
  break;
11949
11720
  case "webhook":
11950
11721
  irWebhookToAst({
11951
- getAst: (schema, path$1) => {
11952
- return irSchemaToAst$2({
11953
- plugin,
11954
- schema,
11955
- state: refs({
11956
- hasLazyExpression: false,
11957
- path: path$1,
11958
- tags: event.tags
11959
- })
11960
- });
11961
- },
11962
11722
  operation: event.operation,
11723
+ path: event._path,
11963
11724
  plugin,
11964
- state
11725
+ processor,
11726
+ tags: event.tags
11965
11727
  });
11966
11728
  break;
11967
11729
  }
11968
11730
  });
11969
11731
  };
11970
11732
 
11733
+ //#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
11745
+ });
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
11760
+ });
11761
+ const ast = irSchemaToAst$1({
11762
+ plugin,
11763
+ schema: ctx$1.schema,
11764
+ schemaExtractor: extractor,
11765
+ state
11766
+ });
11767
+ exportAst({
11768
+ ...ctx$1,
11769
+ ast,
11770
+ plugin,
11771
+ state
11772
+ });
11773
+ });
11774
+ }
11775
+ return { process: process$1 };
11776
+ }
11777
+
11971
11778
  //#endregion
11972
11779
  //#region src/plugins/zod/v3/toAst/unknown.ts
11973
11780
  const unknownToAst$1 = ({ plugin }) => {
@@ -12029,7 +11836,7 @@ const arrayToAst$1 = ({ plugin, schema, state }) => {
12029
11836
 
12030
11837
  //#endregion
12031
11838
  //#region src/plugins/zod/v3/toAst/boolean.ts
12032
- const booleanToAst$1 = ({ plugin, schema }) => {
11839
+ function booleanToAst$1({ plugin, schema }) {
12033
11840
  let chain;
12034
11841
  const z = plugin.external("zod.z");
12035
11842
  if (typeof schema.const === "boolean") {
@@ -12038,7 +11845,7 @@ const booleanToAst$1 = ({ plugin, schema }) => {
12038
11845
  }
12039
11846
  chain = $(z).attr(identifiers.boolean).call();
12040
11847
  return chain;
12041
- };
11848
+ }
12042
11849
 
12043
11850
  //#endregion
12044
11851
  //#region src/plugins/zod/v3/toAst/enum.ts
@@ -12436,7 +12243,7 @@ const voidToAst$1 = ({ plugin }) => {
12436
12243
 
12437
12244
  //#endregion
12438
12245
  //#region src/plugins/zod/v3/toAst/index.ts
12439
- const irSchemaWithTypeToAst$1 = ({ schema, ...args }) => {
12246
+ function irSchemaWithTypeToAst$1({ schema, ...args }) {
12440
12247
  switch (schema.type) {
12441
12248
  case "array": return arrayToAst$1({
12442
12249
  ...args,
@@ -12494,11 +12301,24 @@ const irSchemaWithTypeToAst$1 = ({ schema, ...args }) => {
12494
12301
  schema
12495
12302
  }) };
12496
12303
  }
12497
- };
12304
+ }
12498
12305
 
12499
12306
  //#endregion
12500
12307
  //#region src/plugins/zod/v3/plugin.ts
12501
- const irSchemaToAst$1 = ({ optional, plugin, schema, state }) => {
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
+ }
12502
12322
  let ast = {};
12503
12323
  const z = plugin.external("zod.z");
12504
12324
  if (schema.$ref) {
@@ -12574,38 +12394,7 @@ const irSchemaToAst$1 = ({ optional, plugin, schema, state }) => {
12574
12394
  if (!ast.typeName) ast.typeName = "ZodTypeAny";
12575
12395
  } else if (ast.typeName) ast.typeName = void 0;
12576
12396
  return ast;
12577
- };
12578
- const handleComponent$1 = ({ plugin, schema, state }) => {
12579
- const $ref = pathToJsonPointer(fromRef(state.path));
12580
- const ast = irSchemaToAst$1({
12581
- plugin,
12582
- schema,
12583
- state
12584
- });
12585
- const baseName = refToName($ref);
12586
- exportAst({
12587
- ast,
12588
- plugin,
12589
- schema,
12590
- symbol: plugin.symbol(applyNaming(baseName, plugin.config.definitions), { meta: {
12591
- category: "schema",
12592
- path: fromRef(state.path),
12593
- resource: "definition",
12594
- resourceId: $ref,
12595
- tags: fromRef(state.tags),
12596
- tool: "zod"
12597
- } }),
12598
- typeInferSymbol: plugin.config.definitions.types.infer.enabled ? plugin.symbol(applyNaming(baseName, plugin.config.definitions.types.infer), { meta: {
12599
- category: "type",
12600
- path: fromRef(state.path),
12601
- resource: "definition",
12602
- resourceId: $ref,
12603
- tags: fromRef(state.tags),
12604
- tool: "zod",
12605
- variant: "infer"
12606
- } }) : void 0
12607
- });
12608
- };
12397
+ }
12609
12398
  const handlerV3 = ({ plugin }) => {
12610
12399
  plugin.symbol("z", {
12611
12400
  external: getZodModule({ plugin }),
@@ -12614,74 +12403,115 @@ const handlerV3 = ({ plugin }) => {
12614
12403
  resource: "zod.z"
12615
12404
  }
12616
12405
  });
12406
+ const processor = createProcessor$1(plugin);
12617
12407
  plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
12618
- const state = refs({
12619
- hasLazyExpression: false,
12620
- path: event._path,
12621
- tags: event.tags
12622
- });
12623
12408
  switch (event.type) {
12624
12409
  case "operation":
12625
12410
  irOperationToAst({
12626
- getAst: (schema, path$1) => {
12627
- return irSchemaToAst$1({
12628
- plugin,
12629
- schema,
12630
- state: refs({
12631
- hasLazyExpression: false,
12632
- path: path$1,
12633
- tags: event.tags
12634
- })
12635
- });
12636
- },
12637
12411
  operation: event.operation,
12412
+ path: event._path,
12638
12413
  plugin,
12639
- state
12414
+ processor,
12415
+ tags: event.tags
12640
12416
  });
12641
12417
  break;
12642
12418
  case "parameter":
12643
- handleComponent$1({
12419
+ processor.process({
12420
+ meta: {
12421
+ resource: "definition",
12422
+ resourceId: pathToJsonPointer(event._path)
12423
+ },
12424
+ naming: plugin.config.definitions,
12425
+ path: event._path,
12644
12426
  plugin,
12645
12427
  schema: event.parameter.schema,
12646
- state
12428
+ tags: event.tags
12647
12429
  });
12648
12430
  break;
12649
12431
  case "requestBody":
12650
- handleComponent$1({
12432
+ processor.process({
12433
+ meta: {
12434
+ resource: "definition",
12435
+ resourceId: pathToJsonPointer(event._path)
12436
+ },
12437
+ naming: plugin.config.definitions,
12438
+ path: event._path,
12651
12439
  plugin,
12652
12440
  schema: event.requestBody.schema,
12653
- state
12441
+ tags: event.tags
12654
12442
  });
12655
12443
  break;
12656
12444
  case "schema":
12657
- handleComponent$1({
12445
+ processor.process({
12446
+ meta: {
12447
+ resource: "definition",
12448
+ resourceId: pathToJsonPointer(event._path)
12449
+ },
12450
+ naming: plugin.config.definitions,
12451
+ path: event._path,
12658
12452
  plugin,
12659
12453
  schema: event.schema,
12660
- state
12454
+ tags: event.tags
12661
12455
  });
12662
12456
  break;
12663
12457
  case "webhook":
12664
12458
  irWebhookToAst({
12665
- getAst: (schema, path$1) => {
12666
- return irSchemaToAst$1({
12667
- plugin,
12668
- schema,
12669
- state: refs({
12670
- hasLazyExpression: false,
12671
- path: path$1,
12672
- tags: event.tags
12673
- })
12674
- });
12675
- },
12676
12459
  operation: event.operation,
12460
+ path: event._path,
12677
12461
  plugin,
12678
- state
12462
+ processor,
12463
+ tags: event.tags
12679
12464
  });
12680
12465
  break;
12681
12466
  }
12682
12467
  });
12683
12468
  };
12684
12469
 
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
+
12685
12515
  //#endregion
12686
12516
  //#region src/plugins/zod/v4/toAst/unknown.ts
12687
12517
  const unknownToAst = ({ plugin }) => {
@@ -12741,7 +12571,7 @@ const arrayToAst = ({ plugin, schema, state }) => {
12741
12571
 
12742
12572
  //#endregion
12743
12573
  //#region src/plugins/zod/v4/toAst/boolean.ts
12744
- const booleanToAst = ({ plugin, schema }) => {
12574
+ function booleanToAst({ plugin, schema }) {
12745
12575
  const result = {};
12746
12576
  let chain;
12747
12577
  const z = plugin.external("zod.z");
@@ -12753,7 +12583,7 @@ const booleanToAst = ({ plugin, schema }) => {
12753
12583
  chain = $(z).attr(identifiers.boolean).call();
12754
12584
  result.expression = chain;
12755
12585
  return result;
12756
- };
12586
+ }
12757
12587
 
12758
12588
  //#endregion
12759
12589
  //#region src/plugins/zod/v4/toAst/enum.ts
@@ -13157,7 +12987,7 @@ const voidToAst = ({ plugin }) => {
13157
12987
 
13158
12988
  //#endregion
13159
12989
  //#region src/plugins/zod/v4/toAst/index.ts
13160
- const irSchemaWithTypeToAst = ({ schema, ...args }) => {
12990
+ function irSchemaWithTypeToAst({ schema, ...args }) {
13161
12991
  switch (schema.type) {
13162
12992
  case "array": return arrayToAst({
13163
12993
  ...args,
@@ -13215,11 +13045,24 @@ const irSchemaWithTypeToAst = ({ schema, ...args }) => {
13215
13045
  schema
13216
13046
  });
13217
13047
  }
13218
- };
13048
+ }
13219
13049
 
13220
13050
  //#endregion
13221
13051
  //#region src/plugins/zod/v4/plugin.ts
13222
- const irSchemaToAst = ({ optional, plugin, schema, state }) => {
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
+ }
13223
13066
  let ast = {};
13224
13067
  const z = plugin.external("zod.z");
13225
13068
  if (schema.$ref) {
@@ -13292,108 +13135,74 @@ const irSchemaToAst = ({ optional, plugin, schema, state }) => {
13292
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));
13293
13136
  }
13294
13137
  return ast;
13295
- };
13296
- const handleComponent = ({ plugin, schema, state }) => {
13297
- const $ref = pathToJsonPointer(fromRef(state.path));
13298
- const ast = irSchemaToAst({
13299
- plugin,
13300
- schema,
13301
- state
13302
- });
13303
- const baseName = refToName($ref);
13304
- exportAst({
13305
- ast,
13306
- plugin,
13307
- schema,
13308
- symbol: plugin.symbol(applyNaming(baseName, plugin.config.definitions), { meta: {
13309
- category: "schema",
13310
- path: fromRef(state.path),
13311
- resource: "definition",
13312
- resourceId: $ref,
13313
- tags: fromRef(state.tags),
13314
- tool: "zod"
13315
- } }),
13316
- typeInferSymbol: plugin.config.definitions.types.infer.enabled ? plugin.symbol(applyNaming(baseName, plugin.config.definitions.types.infer), { meta: {
13317
- category: "type",
13318
- path: fromRef(state.path),
13319
- resource: "definition",
13320
- resourceId: $ref,
13321
- tags: fromRef(state.tags),
13322
- tool: "zod",
13323
- variant: "infer"
13324
- } }) : void 0
13325
- });
13326
- };
13138
+ }
13327
13139
  const handlerV4 = ({ plugin }) => {
13328
13140
  plugin.symbol("z", {
13329
13141
  external: getZodModule({ plugin }),
13142
+ importKind: "namespace",
13330
13143
  meta: {
13331
13144
  category: "external",
13332
13145
  resource: "zod.z"
13333
13146
  }
13334
13147
  });
13148
+ const processor = createProcessor(plugin);
13335
13149
  plugin.forEach("operation", "parameter", "requestBody", "schema", "webhook", (event) => {
13336
- const state = refs({
13337
- hasLazyExpression: false,
13338
- path: event._path,
13339
- tags: event.tags
13340
- });
13341
13150
  switch (event.type) {
13342
13151
  case "operation":
13343
13152
  irOperationToAst({
13344
- getAst: (schema, path$1) => {
13345
- return irSchemaToAst({
13346
- plugin,
13347
- schema,
13348
- state: refs({
13349
- hasLazyExpression: false,
13350
- path: path$1,
13351
- tags: event.tags
13352
- })
13353
- });
13354
- },
13355
13153
  operation: event.operation,
13154
+ path: event._path,
13356
13155
  plugin,
13357
- state
13156
+ processor,
13157
+ tags: event.tags
13358
13158
  });
13359
13159
  break;
13360
13160
  case "parameter":
13361
- handleComponent({
13161
+ processor.process({
13162
+ meta: {
13163
+ resource: "definition",
13164
+ resourceId: pathToJsonPointer(event._path)
13165
+ },
13166
+ naming: plugin.config.definitions,
13167
+ path: event._path,
13362
13168
  plugin,
13363
13169
  schema: event.parameter.schema,
13364
- state
13170
+ tags: event.tags
13365
13171
  });
13366
13172
  break;
13367
13173
  case "requestBody":
13368
- handleComponent({
13174
+ processor.process({
13175
+ meta: {
13176
+ resource: "definition",
13177
+ resourceId: pathToJsonPointer(event._path)
13178
+ },
13179
+ naming: plugin.config.definitions,
13180
+ path: event._path,
13369
13181
  plugin,
13370
13182
  schema: event.requestBody.schema,
13371
- state
13183
+ tags: event.tags
13372
13184
  });
13373
13185
  break;
13374
13186
  case "schema":
13375
- handleComponent({
13187
+ processor.process({
13188
+ meta: {
13189
+ resource: "definition",
13190
+ resourceId: pathToJsonPointer(event._path)
13191
+ },
13192
+ naming: plugin.config.definitions,
13193
+ path: event._path,
13376
13194
  plugin,
13377
13195
  schema: event.schema,
13378
- state
13196
+ tags: event.tags
13379
13197
  });
13380
13198
  break;
13381
13199
  case "webhook":
13382
13200
  irWebhookToAst({
13383
- getAst: (schema, path$1) => {
13384
- return irSchemaToAst({
13385
- plugin,
13386
- schema,
13387
- state: refs({
13388
- hasLazyExpression: false,
13389
- path: path$1,
13390
- tags: event.tags
13391
- })
13392
- });
13393
- },
13394
13201
  operation: event.operation,
13202
+ path: event._path,
13395
13203
  plugin,
13396
- state
13204
+ processor,
13205
+ tags: event.tags
13397
13206
  });
13398
13207
  break;
13399
13208
  }
@@ -13829,4 +13638,4 @@ async function resolveJobs({ logger, userConfigs }) {
13829
13638
 
13830
13639
  //#endregion
13831
13640
  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 };
13832
- //# sourceMappingURL=init-DlaW5Djq.mjs.map
13641
+ //# sourceMappingURL=init-BxMu9GWq.mjs.map