every-plugin 0.5.0 → 0.5.1

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