every-plugin 0.4.13 → 0.4.15

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.
Files changed (87) hide show
  1. package/dist/build/rspack/index.cjs +82 -80
  2. package/dist/build/rspack/index.cjs.map +1 -0
  3. package/dist/build/rspack/index.d.cts +1 -1
  4. package/dist/build/rspack/index.d.cts.map +1 -0
  5. package/dist/build/rspack/index.d.mts +1 -1
  6. package/dist/build/rspack/index.d.mts.map +1 -0
  7. package/dist/build/rspack/index.mjs +82 -80
  8. package/dist/build/rspack/index.mjs.map +1 -0
  9. package/dist/errors-9sNpYLv5.d.mts +1 -1
  10. package/dist/errors-9sNpYLv5.d.mts.map +1 -0
  11. package/dist/errors-CVnoPl9v.cjs +1 -1
  12. package/dist/errors-CVnoPl9v.cjs.map +1 -0
  13. package/dist/errors-D7keKf7a.mjs +1 -1
  14. package/dist/errors-D7keKf7a.mjs.map +1 -0
  15. package/dist/errors-DKPPPYYT.d.cts +1 -1
  16. package/dist/errors-DKPPPYYT.d.cts.map +1 -0
  17. package/dist/fetch-8DauUFDh.mjs +335 -0
  18. package/dist/fetch-8DauUFDh.mjs.map +1 -0
  19. package/dist/fetch-CrBvwsZ4.cjs +336 -0
  20. package/dist/fetch-CrBvwsZ4.cjs.map +1 -0
  21. package/dist/index-Coz54d1B.d.mts +387 -0
  22. package/dist/index-Coz54d1B.d.mts.map +1 -0
  23. package/dist/index-G63gBZIY.d.cts +386 -0
  24. package/dist/index-G63gBZIY.d.cts.map +1 -0
  25. package/dist/index.cjs +3 -3
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +1 -1
  28. package/dist/index.d.mts +1 -1
  29. package/dist/index.mjs +3 -3
  30. package/dist/index.mjs.map +1 -0
  31. package/dist/normalize-BW7kk8Lk.d.cts +1 -1
  32. package/dist/normalize-BW7kk8Lk.d.cts.map +1 -0
  33. package/dist/normalize-D4Qh0wVk.cjs +1 -1
  34. package/dist/normalize-D4Qh0wVk.cjs.map +1 -0
  35. package/dist/normalize-D7nae0Hn.mjs +1 -1
  36. package/dist/normalize-D7nae0Hn.mjs.map +1 -0
  37. package/dist/normalize-eB_j86fm.d.mts +1 -1
  38. package/dist/normalize-eB_j86fm.d.mts.map +1 -0
  39. package/dist/package-BoyftHDo.mjs +150 -0
  40. package/dist/package-BoyftHDo.mjs.map +1 -0
  41. package/dist/package-CgNIVjVe.cjs +155 -0
  42. package/dist/package-CgNIVjVe.cjs.map +1 -0
  43. package/dist/plugins-C6MGKdD-.mjs +790 -0
  44. package/dist/plugins-C6MGKdD-.mjs.map +1 -0
  45. package/dist/plugins-DNaNtkG7.cjs +791 -0
  46. package/dist/plugins-DNaNtkG7.cjs.map +1 -0
  47. package/dist/runtime/index.cjs +2 -2
  48. package/dist/runtime/index.d.cts +1 -1
  49. package/dist/runtime/index.d.mts +1 -1
  50. package/dist/runtime/index.mjs +2 -2
  51. package/dist/runtime-60AkNpI0.mjs +476 -0
  52. package/dist/runtime-60AkNpI0.mjs.map +1 -0
  53. package/dist/runtime-BcksCIA1.cjs +541 -0
  54. package/dist/runtime-BcksCIA1.cjs.map +1 -0
  55. package/dist/standard-CkH8zNkx.mjs +584 -0
  56. package/dist/standard-CkH8zNkx.mjs.map +1 -0
  57. package/dist/standard-v75BC6Z5.cjs +685 -0
  58. package/dist/standard-v75BC6Z5.cjs.map +1 -0
  59. package/dist/testing/index.cjs +3 -3
  60. package/dist/testing/index.cjs.map +1 -0
  61. package/dist/testing/index.d.cts +2 -2
  62. package/dist/testing/index.d.cts.map +1 -0
  63. package/dist/testing/index.d.mts +2 -2
  64. package/dist/testing/index.d.mts.map +1 -0
  65. package/dist/testing/index.mjs +3 -3
  66. package/dist/testing/index.mjs.map +1 -0
  67. package/dist/zod-A7Pti5IV.d.cts +1 -1
  68. package/dist/zod-A7Pti5IV.d.cts.map +1 -0
  69. package/dist/zod-BVo51kgJ.mjs +1 -1
  70. package/dist/zod-BVo51kgJ.mjs.map +1 -0
  71. package/dist/zod-DYghWCz1.cjs +1 -1
  72. package/dist/zod-DYghWCz1.cjs.map +1 -0
  73. package/dist/zod-Zw8dlP3j.d.mts +1 -1
  74. package/dist/zod-Zw8dlP3j.d.mts.map +1 -0
  75. package/package.json +1 -1
  76. package/dist/fetch-CGzn1Uf7.cjs +0 -336
  77. package/dist/fetch-ycs0raYN.mjs +0 -335
  78. package/dist/index-matrPV4m.d.cts +0 -382
  79. package/dist/index-qxKsRmCb.d.mts +0 -383
  80. package/dist/package-CMoV9xVN.cjs +0 -155
  81. package/dist/package-WZ0vKAyb.mjs +0 -150
  82. package/dist/plugins-Cmsm3gW1.cjs +0 -791
  83. package/dist/plugins-hpi2GlaX.mjs +0 -790
  84. package/dist/runtime-B4AItsDQ.mjs +0 -458
  85. package/dist/runtime-D5bSEcHa.cjs +0 -523
  86. package/dist/standard-0wBehDUp.cjs +0 -685
  87. package/dist/standard-CYaRay89.mjs +0 -584
@@ -0,0 +1,791 @@
1
+ const require_chunk = require('./chunk-zltIcp7o.cjs');
2
+ const require_standard = require('./standard-v75BC6Z5.cjs');
3
+ let __orpc_server = require("@orpc/server");
4
+ let __orpc_contract = require("@orpc/contract");
5
+
6
+ //#region ../../node_modules/.bun/@orpc+interop@1.10.4/node_modules/@orpc/interop/dist/json-schema-typed/index.mjs
7
+ var ContentEncoding;
8
+ (function(ContentEncoding1) {
9
+ ContentEncoding1["7bit"] = "7bit";
10
+ ContentEncoding1["8bit"] = "8bit";
11
+ ContentEncoding1["Base64"] = "base64";
12
+ ContentEncoding1["Binary"] = "binary";
13
+ ContentEncoding1["IETFToken"] = "ietf-token";
14
+ ContentEncoding1["QuotedPrintable"] = "quoted-printable";
15
+ ContentEncoding1["XToken"] = "x-token";
16
+ })(ContentEncoding || (ContentEncoding = {}));
17
+ var Format;
18
+ (function(Format1) {
19
+ Format1["Date"] = "date";
20
+ Format1["DateTime"] = "date-time";
21
+ Format1["Duration"] = "duration";
22
+ Format1["Email"] = "email";
23
+ Format1["Hostname"] = "hostname";
24
+ Format1["IDNEmail"] = "idn-email";
25
+ Format1["IDNHostname"] = "idn-hostname";
26
+ Format1["IPv4"] = "ipv4";
27
+ Format1["IPv6"] = "ipv6";
28
+ Format1["IRI"] = "iri";
29
+ Format1["IRIReference"] = "iri-reference";
30
+ Format1["JSONPointer"] = "json-pointer";
31
+ Format1["JSONPointerURIFragment"] = "json-pointer-uri-fragment";
32
+ Format1["RegEx"] = "regex";
33
+ Format1["RelativeJSONPointer"] = "relative-json-pointer";
34
+ Format1["Time"] = "time";
35
+ Format1["URI"] = "uri";
36
+ Format1["URIReference"] = "uri-reference";
37
+ Format1["URITemplate"] = "uri-template";
38
+ Format1["UUID"] = "uuid";
39
+ })(Format || (Format = {}));
40
+ var TypeName;
41
+ (function(TypeName1) {
42
+ TypeName1["Array"] = "array";
43
+ TypeName1["Boolean"] = "boolean";
44
+ TypeName1["Integer"] = "integer";
45
+ TypeName1["Null"] = "null";
46
+ TypeName1["Number"] = "number";
47
+ TypeName1["Object"] = "object";
48
+ TypeName1["String"] = "string";
49
+ })(TypeName || (TypeName = {}));
50
+
51
+ //#endregion
52
+ //#region ../../node_modules/.bun/@orpc+openapi@1.10.4+64f0629d09b745d9/node_modules/@orpc/openapi/dist/shared/openapi.DrTcell5.mjs
53
+ const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
54
+ function getCustomOpenAPIOperation(o) {
55
+ return o[OPERATION_EXTENDER_SYMBOL];
56
+ }
57
+ function applyCustomOpenAPIOperation(operation, contract) {
58
+ const operationCustoms = [];
59
+ for (const errorItem of Object.values(contract["~orpc"].errorMap)) {
60
+ const maybeExtender = errorItem ? getCustomOpenAPIOperation(errorItem) : void 0;
61
+ if (maybeExtender) operationCustoms.push(maybeExtender);
62
+ }
63
+ if ((0, __orpc_server.isProcedure)(contract)) for (const middleware of contract["~orpc"].middlewares) {
64
+ const maybeExtender = getCustomOpenAPIOperation(middleware);
65
+ if (maybeExtender) operationCustoms.push(maybeExtender);
66
+ }
67
+ let currentOperation = operation;
68
+ for (const custom of operationCustoms) if (typeof custom === "function") currentOperation = custom(currentOperation, contract);
69
+ else currentOperation = {
70
+ ...currentOperation,
71
+ ...custom
72
+ };
73
+ return currentOperation;
74
+ }
75
+ const LOGIC_KEYWORDS = [
76
+ "$dynamicRef",
77
+ "$ref",
78
+ "additionalItems",
79
+ "additionalProperties",
80
+ "allOf",
81
+ "anyOf",
82
+ "const",
83
+ "contains",
84
+ "contentEncoding",
85
+ "contentMediaType",
86
+ "contentSchema",
87
+ "dependencies",
88
+ "dependentRequired",
89
+ "dependentSchemas",
90
+ "else",
91
+ "enum",
92
+ "exclusiveMaximum",
93
+ "exclusiveMinimum",
94
+ "format",
95
+ "if",
96
+ "items",
97
+ "maxContains",
98
+ "maximum",
99
+ "maxItems",
100
+ "maxLength",
101
+ "maxProperties",
102
+ "minContains",
103
+ "minimum",
104
+ "minItems",
105
+ "minLength",
106
+ "minProperties",
107
+ "multipleOf",
108
+ "not",
109
+ "oneOf",
110
+ "pattern",
111
+ "patternProperties",
112
+ "prefixItems",
113
+ "properties",
114
+ "propertyNames",
115
+ "required",
116
+ "then",
117
+ "type",
118
+ "unevaluatedItems",
119
+ "unevaluatedProperties",
120
+ "uniqueItems"
121
+ ];
122
+ function isFileSchema(schema) {
123
+ return require_standard.isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
124
+ }
125
+ function isObjectSchema(schema) {
126
+ return require_standard.isObject(schema) && schema.type === "object";
127
+ }
128
+ function isAnySchema(schema) {
129
+ if (schema === true) return true;
130
+ if (Object.keys(schema).every((k) => !LOGIC_KEYWORDS.includes(k))) return true;
131
+ return false;
132
+ }
133
+ function separateObjectSchema(schema, separatedProperties) {
134
+ if (Object.keys(schema).some((k) => ![
135
+ "type",
136
+ "properties",
137
+ "required",
138
+ "additionalProperties"
139
+ ].includes(k) && LOGIC_KEYWORDS.includes(k) && schema[k] !== void 0)) return [{ type: "object" }, schema];
140
+ const matched = { ...schema };
141
+ const rest = { ...schema };
142
+ matched.properties = separatedProperties.reduce((acc, key) => {
143
+ const keySchema = schema.properties?.[key] ?? schema.additionalProperties;
144
+ if (keySchema !== void 0) acc[key] = keySchema;
145
+ return acc;
146
+ }, {});
147
+ matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
148
+ matched.examples = schema.examples?.map((example) => {
149
+ if (!require_standard.isObject(example)) return example;
150
+ return Object.entries(example).reduce((acc, [key, value$1]) => {
151
+ if (separatedProperties.includes(key)) acc[key] = value$1;
152
+ return acc;
153
+ }, {});
154
+ });
155
+ rest.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value$1]) => {
156
+ acc[key] = value$1;
157
+ return acc;
158
+ }, {});
159
+ rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
160
+ rest.examples = schema.examples?.map((example) => {
161
+ if (!require_standard.isObject(example)) return example;
162
+ return Object.entries(example).reduce((acc, [key, value$1]) => {
163
+ if (!separatedProperties.includes(key)) acc[key] = value$1;
164
+ return acc;
165
+ }, {});
166
+ });
167
+ return [matched, rest];
168
+ }
169
+ function filterSchemaBranches(schema, check, matches = []) {
170
+ if (check(schema)) {
171
+ matches.push(schema);
172
+ return [matches, void 0];
173
+ }
174
+ if (require_standard.isObject(schema)) {
175
+ for (const keyword of ["anyOf", "oneOf"]) if (schema[keyword] && Object.keys(schema).every((k) => k === keyword || !LOGIC_KEYWORDS.includes(k))) {
176
+ const rest = schema[keyword].map((s) => filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
177
+ if (rest.length === 1 && typeof rest[0] === "object") return [matches, {
178
+ ...schema,
179
+ [keyword]: void 0,
180
+ ...rest[0]
181
+ }];
182
+ return [matches, {
183
+ ...schema,
184
+ [keyword]: rest
185
+ }];
186
+ }
187
+ }
188
+ return [matches, schema];
189
+ }
190
+ function applySchemaOptionality(required, schema) {
191
+ if (required) return schema;
192
+ return { anyOf: [schema, { not: {} }] };
193
+ }
194
+ function expandUnionSchema(schema) {
195
+ if (typeof schema === "object") {
196
+ for (const keyword of ["anyOf", "oneOf"]) if (schema[keyword] && Object.keys(schema).every((k) => k === keyword || !LOGIC_KEYWORDS.includes(k))) return schema[keyword].flatMap((s) => expandUnionSchema(s));
197
+ }
198
+ return [schema];
199
+ }
200
+ function expandArrayableSchema(schema) {
201
+ const schemas = expandUnionSchema(schema);
202
+ if (schemas.length !== 2) return;
203
+ const arraySchema = schemas.find((s) => typeof s === "object" && s.type === "array" && Object.keys(s).filter((k) => LOGIC_KEYWORDS.includes(k)).every((k) => k === "type" || k === "items"));
204
+ if (arraySchema === void 0) return;
205
+ const items1 = arraySchema.items;
206
+ const items2 = schemas.find((s) => s !== arraySchema);
207
+ if (require_standard.stringifyJSON(items1) !== require_standard.stringifyJSON(items2)) return;
208
+ return [items2, arraySchema];
209
+ }
210
+ const PRIMITIVE_SCHEMA_TYPES = /* @__PURE__ */ new Set([
211
+ TypeName.String,
212
+ TypeName.Number,
213
+ TypeName.Integer,
214
+ TypeName.Boolean,
215
+ TypeName.Null
216
+ ]);
217
+ function isPrimitiveSchema(schema) {
218
+ return expandUnionSchema(schema).every((s) => {
219
+ if (typeof s === "boolean") return false;
220
+ if (typeof s.type === "string" && PRIMITIVE_SCHEMA_TYPES.has(s.type)) return true;
221
+ if (s.const !== void 0) return true;
222
+ return false;
223
+ });
224
+ }
225
+ function toOpenAPIPath(path) {
226
+ return require_standard.standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
227
+ }
228
+ function toOpenAPIMethod(method) {
229
+ return method.toLocaleLowerCase();
230
+ }
231
+ function toOpenAPIContent(schema) {
232
+ const content = {};
233
+ const [matches, restSchema] = filterSchemaBranches(schema, isFileSchema);
234
+ for (const file of matches) content[file.contentMediaType] = { schema: toOpenAPISchema(file) };
235
+ if (restSchema !== void 0) {
236
+ content["application/json"] = { schema: toOpenAPISchema(restSchema) };
237
+ if (require_standard.findDeepMatches((v) => require_standard.isObject(v) && isFileSchema(v), restSchema).values.length > 0) content["multipart/form-data"] = { schema: toOpenAPISchema(restSchema) };
238
+ }
239
+ return content;
240
+ }
241
+ function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema], [returnsRequired, returnsSchema]) {
242
+ return { "text/event-stream": { schema: toOpenAPISchema({ oneOf: [
243
+ {
244
+ type: "object",
245
+ properties: {
246
+ event: { const: "message" },
247
+ data: yieldsSchema,
248
+ id: { type: "string" },
249
+ retry: { type: "number" }
250
+ },
251
+ required: yieldsRequired ? ["event", "data"] : ["event"]
252
+ },
253
+ {
254
+ type: "object",
255
+ properties: {
256
+ event: { const: "done" },
257
+ data: returnsSchema,
258
+ id: { type: "string" },
259
+ retry: { type: "number" }
260
+ },
261
+ required: returnsRequired ? ["event", "data"] : ["event"]
262
+ },
263
+ {
264
+ type: "object",
265
+ properties: {
266
+ event: { const: "error" },
267
+ data: {},
268
+ id: { type: "string" },
269
+ retry: { type: "number" }
270
+ },
271
+ required: ["event"]
272
+ }
273
+ ] }) } };
274
+ }
275
+ function toOpenAPIParameters(schema, parameterIn) {
276
+ const parameters = [];
277
+ for (const key in schema.properties) {
278
+ const keySchema = schema.properties[key];
279
+ let isDeepObjectStyle = true;
280
+ if (parameterIn !== "query") isDeepObjectStyle = false;
281
+ else if (isPrimitiveSchema(keySchema)) isDeepObjectStyle = false;
282
+ else {
283
+ const [item] = expandArrayableSchema(keySchema) ?? [];
284
+ if (item !== void 0 && isPrimitiveSchema(item)) isDeepObjectStyle = false;
285
+ }
286
+ parameters.push({
287
+ name: key,
288
+ in: parameterIn,
289
+ required: schema.required?.includes(key),
290
+ schema: toOpenAPISchema(keySchema),
291
+ style: isDeepObjectStyle ? "deepObject" : void 0,
292
+ explode: isDeepObjectStyle ? true : void 0,
293
+ allowEmptyValue: parameterIn === "query" ? true : void 0,
294
+ allowReserved: parameterIn === "query" ? true : void 0
295
+ });
296
+ }
297
+ return parameters;
298
+ }
299
+ function checkParamsSchema(schema, params) {
300
+ const properties = Object.keys(schema.properties ?? {});
301
+ const required = schema.required ?? [];
302
+ if (properties.length !== params.length || properties.some((v) => !params.includes(v))) return false;
303
+ if (required.length !== params.length || required.some((v) => !params.includes(v))) return false;
304
+ return true;
305
+ }
306
+ function toOpenAPISchema(schema) {
307
+ return schema === true ? {} : schema === false ? { not: {} } : schema;
308
+ }
309
+ const OPENAPI_JSON_SCHEMA_REF_PREFIX = "#/components/schemas/";
310
+ function resolveOpenAPIJsonSchemaRef(doc, schema) {
311
+ if (typeof schema !== "object" || !schema.$ref?.startsWith(OPENAPI_JSON_SCHEMA_REF_PREFIX)) return schema;
312
+ const name = schema.$ref.slice(21);
313
+ return doc.components?.schemas?.[name] ?? schema;
314
+ }
315
+ var CompositeSchemaConverter = class {
316
+ converters;
317
+ constructor(converters) {
318
+ this.converters = converters;
319
+ }
320
+ async convert(schema, options) {
321
+ for (const converter of this.converters) if (await converter.condition(schema, options)) return converter.convert(schema, options);
322
+ return [false, {}];
323
+ }
324
+ };
325
+ var OpenAPIGeneratorError = class extends Error {};
326
+ var OpenAPIGenerator = class {
327
+ serializer;
328
+ converter;
329
+ constructor(options = {}) {
330
+ this.serializer = new require_standard.StandardOpenAPIJsonSerializer(options);
331
+ this.converter = new CompositeSchemaConverter(require_standard.toArray(options.schemaConverters));
332
+ }
333
+ /**
334
+ * Generates OpenAPI specifications from oRPC routers/contracts.
335
+ *
336
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
337
+ */
338
+ async generate(router, { customErrorResponseBodySchema, commonSchemas, filter: baseFilter, exclude,...baseDoc } = {}) {
339
+ const filter = baseFilter ?? (({ contract, path }) => {
340
+ return !(exclude?.(contract, path) ?? false);
341
+ });
342
+ const doc = {
343
+ ...require_standard.clone(baseDoc),
344
+ info: baseDoc.info ?? {
345
+ title: "API Reference",
346
+ version: "0.0.0"
347
+ },
348
+ openapi: "3.1.1"
349
+ };
350
+ const { baseSchemaConvertOptions, undefinedErrorJsonSchema } = await this.#resolveCommonSchemas(doc, commonSchemas);
351
+ const contracts = [];
352
+ await (0, __orpc_server.resolveContractProcedures)({
353
+ path: [],
354
+ router
355
+ }, (traverseOptions) => {
356
+ if (!require_standard.value(filter, traverseOptions)) return;
357
+ contracts.push(traverseOptions);
358
+ });
359
+ const errors = [];
360
+ for (const { contract, path } of contracts) {
361
+ const stringPath = path.join(".");
362
+ try {
363
+ const def = contract["~orpc"];
364
+ const method = toOpenAPIMethod((0, __orpc_contract.fallbackContractConfig)("defaultMethod", def.route.method));
365
+ const httpPath = toOpenAPIPath(def.route.path ?? require_standard.toHttpPath(path));
366
+ let operationObjectRef;
367
+ if (def.route.spec !== void 0 && typeof def.route.spec !== "function") operationObjectRef = def.route.spec;
368
+ else {
369
+ operationObjectRef = {
370
+ operationId: def.route.operationId ?? stringPath,
371
+ summary: def.route.summary,
372
+ description: def.route.description,
373
+ deprecated: def.route.deprecated,
374
+ tags: def.route.tags?.map((tag) => tag)
375
+ };
376
+ await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
377
+ await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
378
+ await this.#errorResponse(operationObjectRef, def, baseSchemaConvertOptions, undefinedErrorJsonSchema, customErrorResponseBodySchema);
379
+ }
380
+ if (typeof def.route.spec === "function") operationObjectRef = def.route.spec(operationObjectRef);
381
+ doc.paths ??= {};
382
+ doc.paths[httpPath] ??= {};
383
+ doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
384
+ } catch (e) {
385
+ if (!(e instanceof OpenAPIGeneratorError)) throw e;
386
+ errors.push(`[OpenAPIGenerator] Error occurred while generating OpenAPI for procedure at path: ${stringPath}
387
+ ${e.message}`);
388
+ }
389
+ }
390
+ if (errors.length) throw new OpenAPIGeneratorError(`Some error occurred during OpenAPI generation:
391
+
392
+ ${errors.join("\n\n")}`);
393
+ return this.serializer.serialize(doc)[0];
394
+ }
395
+ async #resolveCommonSchemas(doc, commonSchemas) {
396
+ let undefinedErrorJsonSchema = {
397
+ type: "object",
398
+ properties: {
399
+ defined: { const: false },
400
+ code: { type: "string" },
401
+ status: { type: "number" },
402
+ message: { type: "string" },
403
+ data: {}
404
+ },
405
+ required: [
406
+ "defined",
407
+ "code",
408
+ "status",
409
+ "message"
410
+ ]
411
+ };
412
+ const baseSchemaConvertOptions = {};
413
+ if (commonSchemas) {
414
+ baseSchemaConvertOptions.components = [];
415
+ for (const key in commonSchemas) {
416
+ const options = commonSchemas[key];
417
+ if (options.schema === void 0) continue;
418
+ const { schema, strategy = "input" } = options;
419
+ const [required, json] = await this.converter.convert(schema, { strategy });
420
+ const allowedStrategies = [strategy];
421
+ if (strategy === "input") {
422
+ const [outputRequired, outputJson] = await this.converter.convert(schema, { strategy: "output" });
423
+ if (outputRequired === required && require_standard.stringifyJSON(outputJson) === require_standard.stringifyJSON(json)) allowedStrategies.push("output");
424
+ } else if (strategy === "output") {
425
+ const [inputRequired, inputJson] = await this.converter.convert(schema, { strategy: "input" });
426
+ if (inputRequired === required && require_standard.stringifyJSON(inputJson) === require_standard.stringifyJSON(json)) allowedStrategies.push("input");
427
+ }
428
+ baseSchemaConvertOptions.components.push({
429
+ schema,
430
+ required,
431
+ ref: `#/components/schemas/${key}`,
432
+ allowedStrategies
433
+ });
434
+ }
435
+ doc.components ??= {};
436
+ doc.components.schemas ??= {};
437
+ for (const key in commonSchemas) {
438
+ const options = commonSchemas[key];
439
+ if (options.schema === void 0) {
440
+ if (options.error === "UndefinedError") {
441
+ doc.components.schemas[key] = toOpenAPISchema(undefinedErrorJsonSchema);
442
+ undefinedErrorJsonSchema = { $ref: `#/components/schemas/${key}` };
443
+ }
444
+ continue;
445
+ }
446
+ const { schema, strategy = "input" } = options;
447
+ const [, json] = await this.converter.convert(schema, {
448
+ ...baseSchemaConvertOptions,
449
+ strategy,
450
+ minStructureDepthForRef: 1
451
+ });
452
+ doc.components.schemas[key] = toOpenAPISchema(json);
453
+ }
454
+ }
455
+ return {
456
+ baseSchemaConvertOptions,
457
+ undefinedErrorJsonSchema
458
+ };
459
+ }
460
+ async #request(doc, ref, def, baseSchemaConvertOptions) {
461
+ const method = (0, __orpc_contract.fallbackContractConfig)("defaultMethod", def.route.method);
462
+ const details = (0, __orpc_contract.getEventIteratorSchemaDetails)(def.inputSchema);
463
+ if (details) {
464
+ ref.requestBody = {
465
+ required: true,
466
+ content: toOpenAPIEventIteratorContent(await this.converter.convert(details.yields, {
467
+ ...baseSchemaConvertOptions,
468
+ strategy: "input"
469
+ }), await this.converter.convert(details.returns, {
470
+ ...baseSchemaConvertOptions,
471
+ strategy: "input"
472
+ }))
473
+ };
474
+ return;
475
+ }
476
+ const dynamicParams = require_standard.getDynamicParams(def.route.path)?.map((v) => v.name);
477
+ const inputStructure = (0, __orpc_contract.fallbackContractConfig)("defaultInputStructure", def.route.inputStructure);
478
+ let [required, schema] = await this.converter.convert(def.inputSchema, {
479
+ ...baseSchemaConvertOptions,
480
+ strategy: "input",
481
+ minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
482
+ });
483
+ if (isAnySchema(schema) && !dynamicParams?.length) return;
484
+ if (inputStructure === "compact") {
485
+ if (dynamicParams?.length) {
486
+ const error2 = new OpenAPIGeneratorError("When input structure is \"compact\", and path has dynamic params, input schema must be an object with all dynamic params as required.");
487
+ if (!isObjectSchema(schema)) throw error2;
488
+ const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
489
+ schema = rest;
490
+ required = rest.required ? rest.required.length !== 0 : false;
491
+ if (!checkParamsSchema(paramsSchema, dynamicParams)) throw error2;
492
+ ref.parameters ??= [];
493
+ ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
494
+ }
495
+ if (method === "GET") {
496
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
497
+ if (!isObjectSchema(resolvedSchema)) throw new OpenAPIGeneratorError("When method is \"GET\", input schema must satisfy: object | any | unknown");
498
+ ref.parameters ??= [];
499
+ ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
500
+ } else ref.requestBody = {
501
+ required,
502
+ content: toOpenAPIContent(schema)
503
+ };
504
+ return;
505
+ }
506
+ const error = new OpenAPIGeneratorError("When input structure is \"detailed\", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }");
507
+ if (!isObjectSchema(schema)) throw error;
508
+ const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
509
+ if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) throw new OpenAPIGeneratorError("When input structure is \"detailed\" and path has dynamic params, the \"params\" schema must be an object with all dynamic params as required.");
510
+ for (const from of [
511
+ "params",
512
+ "query",
513
+ "headers"
514
+ ]) {
515
+ const fromSchema = schema.properties?.[from];
516
+ if (fromSchema !== void 0) {
517
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
518
+ if (!isObjectSchema(resolvedSchema)) throw error;
519
+ const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
520
+ ref.parameters ??= [];
521
+ ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
522
+ }
523
+ }
524
+ if (schema.properties?.body !== void 0) ref.requestBody = {
525
+ required: schema.required?.includes("body"),
526
+ content: toOpenAPIContent(schema.properties.body)
527
+ };
528
+ }
529
+ async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
530
+ const outputSchema = def.outputSchema;
531
+ const status = (0, __orpc_contract.fallbackContractConfig)("defaultSuccessStatus", def.route.successStatus);
532
+ const description = (0, __orpc_contract.fallbackContractConfig)("defaultSuccessDescription", def.route?.successDescription);
533
+ const eventIteratorSchemaDetails = (0, __orpc_contract.getEventIteratorSchemaDetails)(outputSchema);
534
+ const outputStructure = (0, __orpc_contract.fallbackContractConfig)("defaultOutputStructure", def.route.outputStructure);
535
+ if (eventIteratorSchemaDetails) {
536
+ ref.responses ??= {};
537
+ ref.responses[status] = {
538
+ description,
539
+ content: toOpenAPIEventIteratorContent(await this.converter.convert(eventIteratorSchemaDetails.yields, {
540
+ ...baseSchemaConvertOptions,
541
+ strategy: "output"
542
+ }), await this.converter.convert(eventIteratorSchemaDetails.returns, {
543
+ ...baseSchemaConvertOptions,
544
+ strategy: "output"
545
+ }))
546
+ };
547
+ return;
548
+ }
549
+ const [required, json] = await this.converter.convert(outputSchema, {
550
+ ...baseSchemaConvertOptions,
551
+ strategy: "output",
552
+ minStructureDepthForRef: outputStructure === "detailed" ? 1 : 0
553
+ });
554
+ if (outputStructure === "compact") {
555
+ ref.responses ??= {};
556
+ ref.responses[status] = { description };
557
+ ref.responses[status].content = toOpenAPIContent(applySchemaOptionality(required, json));
558
+ return;
559
+ }
560
+ const handledStatuses = /* @__PURE__ */ new Set();
561
+ for (const item of expandUnionSchema(json)) {
562
+ const error = new OpenAPIGeneratorError(`
563
+ When output structure is "detailed", output schema must satisfy:
564
+ {
565
+ status?: number, // must be a literal number and in the range of 200-399
566
+ headers?: Record<string, unknown>,
567
+ body?: unknown
568
+ }
569
+
570
+ But got: ${require_standard.stringifyJSON(item)}
571
+ `);
572
+ if (!isObjectSchema(item)) throw error;
573
+ let schemaStatus;
574
+ let schemaDescription;
575
+ if (item.properties?.status !== void 0) {
576
+ const statusSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.status);
577
+ if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || require_standard.isORPCErrorStatus(statusSchema.const)) throw error;
578
+ schemaStatus = statusSchema.const;
579
+ schemaDescription = statusSchema.description;
580
+ }
581
+ const itemStatus = schemaStatus ?? status;
582
+ const itemDescription = schemaDescription ?? description;
583
+ if (handledStatuses.has(itemStatus)) throw new OpenAPIGeneratorError(`
584
+ When output structure is "detailed", each success status must be unique.
585
+ But got status: ${itemStatus} used more than once.
586
+ `);
587
+ handledStatuses.add(itemStatus);
588
+ ref.responses ??= {};
589
+ ref.responses[itemStatus] = { description: itemDescription };
590
+ if (item.properties?.headers !== void 0) {
591
+ const headersSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.headers);
592
+ if (!isObjectSchema(headersSchema)) throw error;
593
+ for (const key in headersSchema.properties) {
594
+ const headerSchema = headersSchema.properties[key];
595
+ if (headerSchema !== void 0) {
596
+ ref.responses[itemStatus].headers ??= {};
597
+ ref.responses[itemStatus].headers[key] = {
598
+ schema: toOpenAPISchema(headerSchema),
599
+ required: item.required?.includes("headers") && headersSchema.required?.includes(key)
600
+ };
601
+ }
602
+ }
603
+ }
604
+ if (item.properties?.body !== void 0) ref.responses[itemStatus].content = toOpenAPIContent(applySchemaOptionality(item.required?.includes("body") ?? false, item.properties.body));
605
+ }
606
+ }
607
+ async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema, customErrorResponseBodySchema) {
608
+ const errorMap = def.errorMap;
609
+ const errorResponsesByStatus = {};
610
+ for (const code in errorMap) {
611
+ const config = errorMap[code];
612
+ if (!config) continue;
613
+ const status = require_standard.fallbackORPCErrorStatus(code, config.status);
614
+ const defaultMessage = require_standard.fallbackORPCErrorMessage(code, config.message);
615
+ errorResponsesByStatus[status] ??= {
616
+ status,
617
+ definedErrorDefinitions: [],
618
+ errorSchemaVariants: []
619
+ };
620
+ const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
621
+ ...baseSchemaConvertOptions,
622
+ strategy: "output"
623
+ });
624
+ errorResponsesByStatus[status].definedErrorDefinitions.push([
625
+ code,
626
+ defaultMessage,
627
+ dataRequired,
628
+ dataSchema
629
+ ]);
630
+ errorResponsesByStatus[status].errorSchemaVariants.push({
631
+ type: "object",
632
+ properties: {
633
+ defined: { const: true },
634
+ code: { const: code },
635
+ status: { const: status },
636
+ message: {
637
+ type: "string",
638
+ default: defaultMessage
639
+ },
640
+ data: dataSchema
641
+ },
642
+ required: dataRequired ? [
643
+ "defined",
644
+ "code",
645
+ "status",
646
+ "message",
647
+ "data"
648
+ ] : [
649
+ "defined",
650
+ "code",
651
+ "status",
652
+ "message"
653
+ ]
654
+ });
655
+ }
656
+ ref.responses ??= {};
657
+ for (const statusString in errorResponsesByStatus) {
658
+ const errorResponse = errorResponsesByStatus[statusString];
659
+ const customBodySchema = require_standard.value(customErrorResponseBodySchema, errorResponse.definedErrorDefinitions, errorResponse.status);
660
+ ref.responses[statusString] = {
661
+ description: statusString,
662
+ content: toOpenAPIContent(customBodySchema ?? { oneOf: [...errorResponse.errorSchemaVariants, undefinedErrorSchema] })
663
+ };
664
+ }
665
+ }
666
+ };
667
+
668
+ //#endregion
669
+ //#region ../../node_modules/.bun/@orpc+openapi@1.10.4+64f0629d09b745d9/node_modules/@orpc/openapi/dist/plugins/index.mjs
670
+ var OpenAPIReferencePlugin = class {
671
+ generator;
672
+ specGenerateOptions;
673
+ specPath;
674
+ docsPath;
675
+ docsTitle;
676
+ docsHead;
677
+ docsProvider;
678
+ docsScriptUrl;
679
+ docsCssUrl;
680
+ docsConfig;
681
+ renderDocsHtml;
682
+ constructor(options = {}) {
683
+ this.specGenerateOptions = options.specGenerateOptions;
684
+ this.docsPath = options.docsPath ?? "/";
685
+ this.docsTitle = options.docsTitle ?? "API Reference";
686
+ this.docsConfig = options.docsConfig ?? void 0;
687
+ this.docsProvider = options.docsProvider ?? "scalar";
688
+ this.docsScriptUrl = options.docsScriptUrl ?? (this.docsProvider === "swagger" ? "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js" : "https://cdn.jsdelivr.net/npm/@scalar/api-reference");
689
+ this.docsCssUrl = options.docsCssUrl ?? (this.docsProvider === "swagger" ? "https://unpkg.com/swagger-ui-dist/swagger-ui.css" : void 0);
690
+ this.docsHead = options.docsHead ?? "";
691
+ this.specPath = options.specPath ?? "/spec.json";
692
+ this.generator = new OpenAPIGenerator(options);
693
+ const esc = (s) => s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
694
+ this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec, docsProvider, cssUrl) => {
695
+ let body;
696
+ if (docsProvider === "swagger") {
697
+ const swaggerConfig = {
698
+ dom_id: "#app",
699
+ spec,
700
+ deepLinking: true,
701
+ presets: ["SwaggerUIBundle.presets.apis", "SwaggerUIBundle.presets.standalone"],
702
+ plugins: ["SwaggerUIBundle.plugins.DownloadUrl"],
703
+ ...config
704
+ };
705
+ body = `
706
+ <body>
707
+ <div id="app"></div>
708
+
709
+ <script src="${esc(scriptUrl)}"><\/script>
710
+
711
+ <script>
712
+ window.onload = () => {
713
+ window.ui = SwaggerUIBundle(${require_standard.stringifyJSON(swaggerConfig).replace(/"(SwaggerUIBundle\.[^"]+)"/g, "$1")})
714
+ }
715
+ <\/script>
716
+ </body>
717
+ `;
718
+ } else body = `
719
+ <body>
720
+ <div id="app" data-config="${esc(require_standard.stringifyJSON({
721
+ content: require_standard.stringifyJSON(spec),
722
+ ...config
723
+ }))}"></div>
724
+
725
+ <script src="${esc(scriptUrl)}"><\/script>
726
+
727
+ <script>
728
+ Scalar.createApiReference('#app', JSON.parse(document.getElementById('app').dataset.config))
729
+ <\/script>
730
+ </body>
731
+ `;
732
+ return `
733
+ <!doctype html>
734
+ <html>
735
+ <head>
736
+ <meta charset="utf-8" />
737
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
738
+ <title>${esc(title)}</title>
739
+ ${cssUrl ? `<link rel="stylesheet" type="text/css" href="${esc(cssUrl)}" />` : ""}
740
+ ${head}
741
+ </head>
742
+ ${body}
743
+ </html>
744
+ `;
745
+ });
746
+ }
747
+ init(options, router) {
748
+ options.interceptors ??= [];
749
+ options.interceptors.push(async (options2) => {
750
+ const res = await options2.next();
751
+ if (res.matched || options2.request.method !== "GET") return res;
752
+ const prefix = options2.prefix ?? "";
753
+ const requestPathname = options2.request.url.pathname.replace(/\/$/, "") || "/";
754
+ const docsUrl = new URL(`${prefix}${this.docsPath}`.replace(/\/$/, ""), options2.request.url.origin);
755
+ const specUrl = new URL(`${prefix}${this.specPath}`.replace(/\/$/, ""), options2.request.url.origin);
756
+ const generateSpec = require_standard.once(async () => {
757
+ return await this.generator.generate(router, {
758
+ servers: [{ url: new URL(prefix, options2.request.url.origin).toString() }],
759
+ ...await require_standard.value(this.specGenerateOptions, options2)
760
+ });
761
+ });
762
+ if (requestPathname === specUrl.pathname) {
763
+ const spec = await generateSpec();
764
+ return {
765
+ matched: true,
766
+ response: {
767
+ status: 200,
768
+ headers: {},
769
+ body: new File([require_standard.stringifyJSON(spec)], "spec.json", { type: "application/json" })
770
+ }
771
+ };
772
+ }
773
+ if (requestPathname === docsUrl.pathname) {
774
+ const html = this.renderDocsHtml(specUrl.toString(), await require_standard.value(this.docsTitle, options2), await require_standard.value(this.docsHead, options2), await require_standard.value(this.docsScriptUrl, options2), await require_standard.value(this.docsConfig, options2), await generateSpec(), this.docsProvider, await require_standard.value(this.docsCssUrl, options2));
775
+ return {
776
+ matched: true,
777
+ response: {
778
+ status: 200,
779
+ headers: {},
780
+ body: new File([html], "api-reference.html", { type: "text/html" })
781
+ }
782
+ };
783
+ }
784
+ return res;
785
+ });
786
+ }
787
+ };
788
+
789
+ //#endregion
790
+ exports.OpenAPIReferencePlugin = OpenAPIReferencePlugin;
791
+ //# sourceMappingURL=plugins-DNaNtkG7.cjs.map