@orpc/openapi 2.0.0-beta.47 → 2.0.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/adapters/aws-lambda/index.d.mts +14 -26
- package/dist/adapters/aws-lambda/index.mjs +1 -21
- package/dist/adapters/aws-lambda/openapi-handler.d.mts +17 -0
- package/dist/adapters/aws-lambda/openapi-handler.mjs +11 -0
- package/dist/adapters/fastify/index.d.mts +1 -23
- package/dist/adapters/fastify/index.mjs +1 -21
- package/dist/adapters/fastify/openapi-handler.d.mts +14 -0
- package/dist/adapters/fastify/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/index.d.mts +2 -37
- package/dist/adapters/fetch/index.mjs +2 -34
- package/dist/adapters/fetch/openapi-handler.d.mts +14 -0
- package/dist/adapters/fetch/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/openapi-link.d.mts +15 -0
- package/dist/adapters/fetch/openapi-link.mjs +11 -0
- package/dist/adapters/node/index.d.mts +1 -23
- package/dist/adapters/node/index.mjs +1 -21
- package/dist/adapters/node/openapi-handler.d.mts +14 -0
- package/dist/adapters/node/openapi-handler.mjs +11 -0
- package/dist/adapters/standard/index.d.mts +3 -56
- package/dist/adapters/standard/index.mjs +3 -12
- package/dist/adapters/standard/openapi-handler-codec.d.mts +61 -0
- package/dist/adapters/standard/openapi-handler-codec.mjs +203 -0
- package/dist/adapters/standard/openapi-link-codec.d.mts +53 -0
- package/dist/adapters/standard/openapi-link-codec.mjs +356 -0
- package/dist/adapters/standard/openapi-matcher.d.mts +29 -0
- package/dist/adapters/standard/openapi-matcher.mjs +105 -0
- package/dist/adapters/standard/utils.d.mts +4 -0
- package/dist/adapters/standard/utils.mjs +36 -0
- package/dist/bracket-notation.d.mts +26 -0
- package/dist/bracket-notation.mjs +156 -0
- package/dist/client-factory.d.mts +24 -0
- package/dist/client-factory.mjs +5 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.mjs +4 -0
- package/dist/extensions/route.d.mts +74 -39
- package/dist/extensions/route.mjs +8 -10
- package/dist/helpers/form-data.d.mts +57 -0
- package/dist/helpers/form-data.mjs +36 -0
- package/dist/helpers/index.d.mts +1 -59
- package/dist/helpers/index.mjs +1 -39
- package/dist/index.d.mts +13 -166
- package/dist/index.mjs +11 -780
- package/dist/meta.d.mts +345 -0
- package/dist/meta.mjs +56 -0
- package/dist/openapi-generator-components.d.mts +24 -0
- package/dist/openapi-generator-components.mjs +227 -0
- package/dist/openapi-generator-operation.d.mts +29 -0
- package/dist/openapi-generator-operation.mjs +447 -0
- package/dist/openapi-generator.d.mts +87 -0
- package/dist/openapi-generator.mjs +115 -0
- package/dist/openapi-json-serializer.d.mts +86 -0
- package/dist/openapi-json-serializer.mjs +229 -0
- package/dist/openapi-serializer.d.mts +43 -0
- package/dist/openapi-serializer.mjs +87 -0
- package/dist/plugins/index.d.mts +1 -121
- package/dist/plugins/index.mjs +1 -167
- package/dist/plugins/openapi-reference.d.mts +118 -0
- package/dist/plugins/openapi-reference.mjs +157 -0
- package/dist/router-utils.d.mts +18 -0
- package/dist/router-utils.mjs +29 -0
- package/dist/types.d.mts +27 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.mts +14 -0
- package/dist/utils.mjs +40 -0
- package/package.json +15 -15
- package/dist/adapters/aws-lambda/index.d.ts +0 -27
- package/dist/adapters/fastify/index.d.ts +0 -23
- package/dist/adapters/fetch/index.d.ts +0 -37
- package/dist/adapters/node/index.d.ts +0 -23
- package/dist/adapters/standard/index.d.ts +0 -56
- package/dist/extensions/route.d.ts +0 -41
- package/dist/helpers/index.d.ts +0 -59
- package/dist/index.d.ts +0 -166
- package/dist/plugins/index.d.ts +0 -121
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.CQkXu1nY.mjs +0 -366
- package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
- package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
- package/dist/shared/openapi.DfmCR1pB.d.mts +0 -94
- package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
- package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
- package/dist/shared/openapi.Y4K_-I5W.d.ts +0 -94
- package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
- package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
- package/dist/shared/openapi.g7ucL05o.mjs +0 -410
- package/dist/shared/openapi.zGZlCOwp.d.mts +0 -329
- package/dist/shared/openapi.zGZlCOwp.d.ts +0 -329
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import { wrapAsyncIteratorPreservingEventMeta, toORPCError, isORPCErrorJson, createORPCErrorFromJson } from '@orpc/client';
|
|
2
|
-
import { isPlainObject, NullProtoObj, copyOnWrite, isAsyncIteratorObject } from '@orpc/shared';
|
|
3
|
-
import { ErrorEvent } from '@standard-server/core';
|
|
4
|
-
import { B as BracketNotationSerializer } from './openapi.DtEVcxuW.mjs';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_OPENAPI_METHOD = "POST";
|
|
7
|
-
const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = "OK";
|
|
8
|
-
const DEFAULT_OPENAPI_INPUT_STRUCTURE = "compact";
|
|
9
|
-
const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = "compact";
|
|
10
|
-
|
|
11
|
-
const DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS = {
|
|
12
|
-
undefined: {
|
|
13
|
-
condition(data) {
|
|
14
|
-
return data === void 0;
|
|
15
|
-
},
|
|
16
|
-
serialize() {
|
|
17
|
-
return null;
|
|
18
|
-
},
|
|
19
|
-
isTerminal: true
|
|
20
|
-
},
|
|
21
|
-
bigint: {
|
|
22
|
-
condition(data) {
|
|
23
|
-
return typeof data === "bigint";
|
|
24
|
-
},
|
|
25
|
-
serialize(data) {
|
|
26
|
-
return data.toString();
|
|
27
|
-
},
|
|
28
|
-
isTerminal: true
|
|
29
|
-
},
|
|
30
|
-
date: {
|
|
31
|
-
condition(data) {
|
|
32
|
-
return data instanceof Date;
|
|
33
|
-
},
|
|
34
|
-
serialize(data) {
|
|
35
|
-
if (Number.isNaN(data.getTime())) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return data.toISOString();
|
|
39
|
-
},
|
|
40
|
-
isTerminal: true
|
|
41
|
-
},
|
|
42
|
-
nan: {
|
|
43
|
-
condition(data) {
|
|
44
|
-
return typeof data === "number" && Number.isNaN(data);
|
|
45
|
-
},
|
|
46
|
-
serialize() {
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
isTerminal: true
|
|
50
|
-
},
|
|
51
|
-
infinity: {
|
|
52
|
-
condition(data) {
|
|
53
|
-
return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
|
|
54
|
-
},
|
|
55
|
-
serialize() {
|
|
56
|
-
return null;
|
|
57
|
-
},
|
|
58
|
-
isTerminal: true
|
|
59
|
-
},
|
|
60
|
-
url: {
|
|
61
|
-
condition(data) {
|
|
62
|
-
return data instanceof URL;
|
|
63
|
-
},
|
|
64
|
-
serialize(data) {
|
|
65
|
-
return data.toString();
|
|
66
|
-
},
|
|
67
|
-
isTerminal: true
|
|
68
|
-
},
|
|
69
|
-
set: {
|
|
70
|
-
condition(data) {
|
|
71
|
-
return data instanceof Set;
|
|
72
|
-
},
|
|
73
|
-
serialize(data) {
|
|
74
|
-
return Array.from(data);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
map: {
|
|
78
|
-
condition(data) {
|
|
79
|
-
return data instanceof Map;
|
|
80
|
-
},
|
|
81
|
-
serialize(data) {
|
|
82
|
-
return Array.from(data.entries());
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
class OpenAPIJsonSerializer {
|
|
87
|
-
inlineBuiltInHandlers;
|
|
88
|
-
handlerEntries;
|
|
89
|
-
omitUndefinedProperties;
|
|
90
|
-
constructor(options = {}) {
|
|
91
|
-
this.omitUndefinedProperties = options.omitUndefinedProperties !== false;
|
|
92
|
-
const customHandlers = options.handlers;
|
|
93
|
-
if (customHandlers === void 0) {
|
|
94
|
-
this.inlineBuiltInHandlers = true;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
let inlineBuiltInHandlers = true;
|
|
98
|
-
let handlerEntries = [];
|
|
99
|
-
for (const key of Object.keys(customHandlers)) {
|
|
100
|
-
const handler = customHandlers[key];
|
|
101
|
-
if (inlineBuiltInHandlers && key in DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS) {
|
|
102
|
-
inlineBuiltInHandlers = false;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
if (handler !== void 0) {
|
|
106
|
-
handlerEntries.push(handler);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (!inlineBuiltInHandlers) {
|
|
110
|
-
handlerEntries = [];
|
|
111
|
-
for (const handler of Object.values({ ...DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS, ...customHandlers })) {
|
|
112
|
-
if (handler !== void 0) {
|
|
113
|
-
handlerEntries.push(handler);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
this.inlineBuiltInHandlers = inlineBuiltInHandlers;
|
|
118
|
-
this.handlerEntries = handlerEntries;
|
|
119
|
-
}
|
|
120
|
-
serializeJson(data) {
|
|
121
|
-
const maps = [];
|
|
122
|
-
const blobs = [];
|
|
123
|
-
const json = this.serializeValue(data, [], maps, blobs);
|
|
124
|
-
return { json, maps, blobs };
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* `segments` is a shared mutable stack (push/pop while walking),
|
|
128
|
-
* so it must be copied before being stored in `maps`.
|
|
129
|
-
*/
|
|
130
|
-
serializeValue(data, segments, maps, blobs) {
|
|
131
|
-
if (this.inlineBuiltInHandlers) {
|
|
132
|
-
switch (typeof data) {
|
|
133
|
-
case "string":
|
|
134
|
-
case "boolean":
|
|
135
|
-
return data;
|
|
136
|
-
case "number":
|
|
137
|
-
return Number.isFinite(data) ? data : null;
|
|
138
|
-
case "undefined":
|
|
139
|
-
return null;
|
|
140
|
-
case "bigint":
|
|
141
|
-
return data.toString();
|
|
142
|
-
case "object": {
|
|
143
|
-
if (data === null) {
|
|
144
|
-
return data;
|
|
145
|
-
}
|
|
146
|
-
if (data instanceof Date) {
|
|
147
|
-
return Number.isNaN(data.getTime()) ? null : data.toISOString();
|
|
148
|
-
}
|
|
149
|
-
if (data instanceof URL) {
|
|
150
|
-
return data.toString();
|
|
151
|
-
}
|
|
152
|
-
if (data instanceof Set) {
|
|
153
|
-
return this.serializeValue(Array.from(data), segments, maps, blobs);
|
|
154
|
-
}
|
|
155
|
-
if (data instanceof Map) {
|
|
156
|
-
return this.serializeValue(Array.from(data.entries()), segments, maps, blobs);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const handlerEntries = this.handlerEntries;
|
|
162
|
-
if (handlerEntries) {
|
|
163
|
-
for (let i = 0; i < handlerEntries.length; i++) {
|
|
164
|
-
const handler = handlerEntries[i];
|
|
165
|
-
if (handler.condition(data)) {
|
|
166
|
-
const serialized = handler.serialize(data);
|
|
167
|
-
if (handler.isTerminal) {
|
|
168
|
-
if (serialized instanceof Blob) {
|
|
169
|
-
maps.push(segments.slice());
|
|
170
|
-
blobs.push(serialized);
|
|
171
|
-
}
|
|
172
|
-
return serialized;
|
|
173
|
-
}
|
|
174
|
-
return this.serializeValue(serialized, segments, maps, blobs);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (data instanceof Blob) {
|
|
179
|
-
maps.push(segments.slice());
|
|
180
|
-
blobs.push(data);
|
|
181
|
-
return data;
|
|
182
|
-
}
|
|
183
|
-
if (Array.isArray(data)) {
|
|
184
|
-
const json = [];
|
|
185
|
-
for (let i = 0; i < data.length; i++) {
|
|
186
|
-
segments.push(i);
|
|
187
|
-
json.push(this.serializeValue(data[i], segments, maps, blobs));
|
|
188
|
-
segments.pop();
|
|
189
|
-
}
|
|
190
|
-
return json;
|
|
191
|
-
}
|
|
192
|
-
if (isPlainObject(data)) {
|
|
193
|
-
const json = new NullProtoObj();
|
|
194
|
-
for (const k of Object.keys(data)) {
|
|
195
|
-
const v = data[k];
|
|
196
|
-
if (k === "toJSON" && typeof v === "function") {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (v === void 0 && this.omitUndefinedProperties) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
segments.push(k);
|
|
203
|
-
json[k] = this.serializeValue(v, segments, maps, blobs);
|
|
204
|
-
segments.pop();
|
|
205
|
-
}
|
|
206
|
-
return json;
|
|
207
|
-
}
|
|
208
|
-
return data;
|
|
209
|
-
}
|
|
210
|
-
deserializeJson(serialized) {
|
|
211
|
-
const ref = { json: serialized.json };
|
|
212
|
-
if (serialized.blobs?.length) {
|
|
213
|
-
for (let i = 0; i < serialized.maps.length; i++) {
|
|
214
|
-
const blob = serialized.blobs[i];
|
|
215
|
-
if (!(blob instanceof Blob)) {
|
|
216
|
-
throw new TypeError(`Invalid OpenAPI serialized data: blob ${i} is not a Blob.`);
|
|
217
|
-
}
|
|
218
|
-
const segments = serialized.maps[i];
|
|
219
|
-
let original = serialized;
|
|
220
|
-
let currentRef = ref;
|
|
221
|
-
let preSegment = "json";
|
|
222
|
-
for (let j = 0; j < segments.length; j++) {
|
|
223
|
-
original = original[preSegment];
|
|
224
|
-
currentRef = copyOnWrite(currentRef, preSegment, original);
|
|
225
|
-
preSegment = segments[j];
|
|
226
|
-
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
227
|
-
throw new TypeError(`Invalid OpenAPI serialized data: segment "${preSegment}" does not exist.`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
currentRef[preSegment] = blob;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return ref.json;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
class OpenAPISerializer extends OpenAPIJsonSerializer {
|
|
238
|
-
bracketNotation;
|
|
239
|
-
defaultSerializeOptions;
|
|
240
|
-
constructor({ bracketNotation, serialize, ...options } = {}) {
|
|
241
|
-
super(options);
|
|
242
|
-
this.bracketNotation = new BracketNotationSerializer(bracketNotation);
|
|
243
|
-
this.defaultSerializeOptions = serialize;
|
|
244
|
-
}
|
|
245
|
-
serialize(data, options = {}) {
|
|
246
|
-
if (!options.asFormData) {
|
|
247
|
-
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
248
|
-
return data;
|
|
249
|
-
}
|
|
250
|
-
if (isAsyncIteratorObject(data)) {
|
|
251
|
-
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
252
|
-
mapResult: (result) => {
|
|
253
|
-
if (result.value === void 0) {
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
return { done: result.done, value: this.serializePayload(result.value, false, false) };
|
|
257
|
-
},
|
|
258
|
-
mapError: (e) => new ErrorEvent(
|
|
259
|
-
this.serializePayload(toORPCError(e).toJSON(), false, false),
|
|
260
|
-
{ cause: e }
|
|
261
|
-
)
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const useFormDataForBlobFields = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
|
|
266
|
-
const asFormData = options.asFormData ?? this.defaultSerializeOptions?.asFormData ?? false;
|
|
267
|
-
return this.serializePayload(data, useFormDataForBlobFields, asFormData);
|
|
268
|
-
}
|
|
269
|
-
serializePayload(value, useFormDataForBlobFields, asFormData) {
|
|
270
|
-
const { json, blobs } = this.serializeJson(value);
|
|
271
|
-
if (!asFormData && (json instanceof Blob || json === void 0 || !blobs?.length || !useFormDataForBlobFields)) {
|
|
272
|
-
return json;
|
|
273
|
-
}
|
|
274
|
-
const form = new FormData();
|
|
275
|
-
for (const [path, value2] of this.bracketNotation.serialize(json)) {
|
|
276
|
-
if (value2 instanceof Blob) {
|
|
277
|
-
form.append(path, value2);
|
|
278
|
-
} else if (value2 !== void 0 && value2 !== null) {
|
|
279
|
-
form.append(path, String(value2));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return form;
|
|
283
|
-
}
|
|
284
|
-
deserialize(data) {
|
|
285
|
-
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
286
|
-
return data;
|
|
287
|
-
}
|
|
288
|
-
if (isAsyncIteratorObject(data)) {
|
|
289
|
-
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
290
|
-
mapResult: (result) => {
|
|
291
|
-
if (result.value === void 0) {
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
return { done: result.done, value: this.deserializeJson({ json: result.value }) };
|
|
295
|
-
},
|
|
296
|
-
mapError: (e) => {
|
|
297
|
-
if (e instanceof ErrorEvent) {
|
|
298
|
-
const deserialized = this.deserializeJson({ json: e.data });
|
|
299
|
-
if (isORPCErrorJson(deserialized)) {
|
|
300
|
-
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return e;
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
308
|
-
data = this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
309
|
-
}
|
|
310
|
-
return this.deserializeJson({ json: data });
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function isBodylessMethod(method) {
|
|
315
|
-
return method === "GET" || method === "HEAD";
|
|
316
|
-
}
|
|
317
|
-
const PARAMETER_NAME_REGEX = /^[\w-]+$/;
|
|
318
|
-
function getDynamicPathParams(path) {
|
|
319
|
-
if (!path.includes("{")) {
|
|
320
|
-
return void 0;
|
|
321
|
-
}
|
|
322
|
-
const len = path.length;
|
|
323
|
-
let params;
|
|
324
|
-
let index = 1;
|
|
325
|
-
while (index < len) {
|
|
326
|
-
const segmentStart = index;
|
|
327
|
-
const slashPos = path.indexOf("/", index);
|
|
328
|
-
const segmentEnd = slashPos === -1 ? len : slashPos;
|
|
329
|
-
if (segmentEnd > segmentStart && path.charCodeAt(segmentStart) === 123 && path.charCodeAt(segmentEnd - 1) === 125) {
|
|
330
|
-
let parameterStart = segmentStart + 1;
|
|
331
|
-
let allowsSlash = false;
|
|
332
|
-
const operator = path.charCodeAt(parameterStart);
|
|
333
|
-
if (operator === 43) {
|
|
334
|
-
allowsSlash = true;
|
|
335
|
-
parameterStart++;
|
|
336
|
-
}
|
|
337
|
-
const parameterName = path.slice(parameterStart, segmentEnd - 1);
|
|
338
|
-
if (PARAMETER_NAME_REGEX.test(parameterName)) {
|
|
339
|
-
params ??= [];
|
|
340
|
-
params.push({
|
|
341
|
-
segment: path.slice(segmentStart, segmentEnd),
|
|
342
|
-
startIndex: segmentStart,
|
|
343
|
-
parameterName,
|
|
344
|
-
allowsSlash
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
index = segmentEnd + 1;
|
|
349
|
-
}
|
|
350
|
-
return params;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export { DEFAULT_OPENAPI_METHOD as D, OpenAPISerializer as O, DEFAULT_OPENAPI_INPUT_STRUCTURE as a, DEFAULT_OPENAPI_OUTPUT_STRUCTURE as b, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION as c, OpenAPIJsonSerializer as d, getDynamicPathParams as g, isBodylessMethod as i };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { AnyProcedure, AnyRouter, Context } from '@orpc/server';
|
|
3
|
-
import { StandardHandlerCodec, ResolvedStandardHandlerHandleOptions, StandardHandlerCodecResolvedProcedure } from '@orpc/server/standard';
|
|
4
|
-
import { Value, Public, Promisable } from '@orpc/shared';
|
|
5
|
-
import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { O as OpenAPISerializer } from './openapi.YMRD3b4R.js';
|
|
8
|
-
|
|
9
|
-
interface OpenAPIMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
|
|
16
|
-
}
|
|
17
|
-
declare class OpenAPIMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private readonly pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
params?: Record<string, string> | undefined;
|
|
28
|
-
} | undefined>;
|
|
29
|
-
private findMatch;
|
|
30
|
-
private resolvePendingLazyRouters;
|
|
31
|
-
private loadPendingLazyRouters;
|
|
32
|
-
private loadPendingLazyRouter;
|
|
33
|
-
private indexPendingLazyRouter;
|
|
34
|
-
private resolveProcedure;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
38
|
-
/**
|
|
39
|
-
* Override the default OpenAPI serializer.
|
|
40
|
-
*/
|
|
41
|
-
serializer?: Public<OpenAPISerializer> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
44
|
-
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
45
|
-
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
|
46
|
-
*
|
|
47
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
48
|
-
*/
|
|
49
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Customize how an ORPC error is serialized into a response body.
|
|
52
|
-
* Use this if your API needs a different error output structure.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* - Return `null | undefined` to fallback to default behavior
|
|
56
|
-
*
|
|
57
|
-
* @default ((e) => e.toJSON())
|
|
58
|
-
*/
|
|
59
|
-
errorResponseBodyEncoder?: ((error: AnyORPCError) => unknown) | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* The `content-type` of error responses, e.g. `application/problem+json` for RFC 9457 Problem Details.
|
|
62
|
-
*
|
|
63
|
-
* @default 'application/json'
|
|
64
|
-
*/
|
|
65
|
-
errorResponseContentType?: string | undefined;
|
|
66
|
-
}
|
|
67
|
-
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
68
|
-
private readonly serializer;
|
|
69
|
-
private readonly errorStatusMap;
|
|
70
|
-
private readonly errorResponseBodyEncoder;
|
|
71
|
-
private readonly errorResponseContentType;
|
|
72
|
-
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
73
|
-
decodeInput(matched: {
|
|
74
|
-
procedure: AnyProcedure;
|
|
75
|
-
params?: Record<string, string> | undefined;
|
|
76
|
-
}, request: StandardLazyRequest): Promise<unknown>;
|
|
77
|
-
/**
|
|
78
|
-
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
79
|
-
*/
|
|
80
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
|
|
81
|
-
encodeError(error: AnyORPCError): Promisable<StandardResponse>;
|
|
82
|
-
private deserializeQuery;
|
|
83
|
-
private deserializeParams;
|
|
84
|
-
}
|
|
85
|
-
interface OpenAPIHandlerCodecOptions<T extends Context> extends OpenAPIHandlerCodecCoreOptions<T>, OpenAPIMatcherOptions {
|
|
86
|
-
}
|
|
87
|
-
declare class OpenAPIHandlerCodec<T extends Context> extends OpenAPIHandlerCodecCore<T> implements StandardHandlerCodec<T> {
|
|
88
|
-
private readonly matcher;
|
|
89
|
-
constructor(router: AnyRouter, options?: OpenAPIHandlerCodecOptions<T>);
|
|
90
|
-
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { OpenAPIHandlerCodec as a, OpenAPIHandlerCodecCore as b, OpenAPIMatcher as d };
|
|
94
|
-
export type { OpenAPIHandlerCodecOptions as O, OpenAPIHandlerCodecCoreOptions as c, OpenAPIMatcherOptions as e };
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { StandardBody } from '@standard-server/core';
|
|
2
|
-
import { Segment } from '@orpc/shared';
|
|
3
|
-
|
|
4
|
-
type BracketNotationSerializeResult = [string, unknown][];
|
|
5
|
-
interface BracketNotationSerializerOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Maximum number of empty slots that explicit array indexes may leave in total during deserialization
|
|
8
|
-
* (e.g., `a[0]=x&a[3]=y` leaves 2). An index that would exceed it turns its array into an object
|
|
9
|
-
* instead (e.g., `?arr[5000]=x` becomes `{ arr: { 5000: 'x' } }`).
|
|
10
|
-
*
|
|
11
|
-
* Empty slots take memory (a lone `?arr[999]=x` takes ~12KB in V8), and code iterating an array walks
|
|
12
|
-
* every one of them, so this keeps both in line with the input.
|
|
13
|
-
*
|
|
14
|
-
* NOTE: Append-style notation (e.g., `arr[]`) never leaves empty slots.
|
|
15
|
-
*
|
|
16
|
-
* @default 1_000
|
|
17
|
-
*/
|
|
18
|
-
maxDeserializingEmptySlots?: number | undefined;
|
|
19
|
-
}
|
|
20
|
-
declare class BracketNotationSerializer {
|
|
21
|
-
private readonly maxDeserializingEmptySlots;
|
|
22
|
-
constructor(options?: BracketNotationSerializerOptions);
|
|
23
|
-
serialize(data: unknown): BracketNotationSerializeResult;
|
|
24
|
-
private internalSerialize;
|
|
25
|
-
deserialize(serialized: BracketNotationSerializeResult): Record<string, unknown>;
|
|
26
|
-
stringifyPath(segments: readonly Segment[]): string;
|
|
27
|
-
parsePath(path: string): string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type OpenAPIJsonSerialization = {
|
|
31
|
-
json: unknown;
|
|
32
|
-
maps?: undefined;
|
|
33
|
-
blobs?: undefined;
|
|
34
|
-
} | {
|
|
35
|
-
json: unknown;
|
|
36
|
-
maps: Segment[][];
|
|
37
|
-
blobs: Blob[];
|
|
38
|
-
};
|
|
39
|
-
interface OpenAPIJsonSerializerHandler {
|
|
40
|
-
condition(value: unknown): boolean;
|
|
41
|
-
serialize(value: any): unknown;
|
|
42
|
-
/**
|
|
43
|
-
* If false, the result of this serializer will not be further processed by other serializers,
|
|
44
|
-
* even if it matches their conditions and treat it as final serialized value.
|
|
45
|
-
* This can be useful for serializers that return primitive values, which should not be further processed.
|
|
46
|
-
* to improve performance and avoid potential issues with other serializers.
|
|
47
|
-
*
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
isTerminal?: boolean | undefined;
|
|
51
|
-
}
|
|
52
|
-
interface OpenAPIJsonSerializerOptions {
|
|
53
|
-
/**
|
|
54
|
-
* Extend or override the built-in type handlers used during serialization.
|
|
55
|
-
*
|
|
56
|
-
* Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
|
|
57
|
-
* that defines how to detect and serialize values of that type.
|
|
58
|
-
*
|
|
59
|
-
* **Extending:** Add new keys to support custom types:
|
|
60
|
-
* ```ts
|
|
61
|
-
* handlers: {
|
|
62
|
-
* buffer: {
|
|
63
|
-
* condition: (v) => v instanceof Buffer,
|
|
64
|
-
* serialize: (v: Buffer) => v.toString('base64'),
|
|
65
|
-
* isTerminal: true,
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* **Overriding:** Use an existing key to replace a built-in handler:
|
|
71
|
-
* ```ts
|
|
72
|
-
* handlers: {
|
|
73
|
-
* date: {
|
|
74
|
-
* condition: (v) => v instanceof Date,
|
|
75
|
-
* serialize: (v: Date) => v.getTime(),
|
|
76
|
-
* isTerminal: true,
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* **Disabling:** Set a key to `undefined` to remove a built-in handler:
|
|
82
|
-
* ```ts
|
|
83
|
-
* handlers: { url: undefined }
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
|
|
87
|
-
*/
|
|
88
|
-
handlers?: Record<string, undefined | OpenAPIJsonSerializerHandler> | undefined;
|
|
89
|
-
/**
|
|
90
|
-
* If true, properties with undefined values will be omitted during serialization.
|
|
91
|
-
*
|
|
92
|
-
* @default true
|
|
93
|
-
*/
|
|
94
|
-
omitUndefinedProperties?: boolean | undefined;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The JSON layer behind `OpenAPISerializer`: one-way serialization of types like `Date`, `BigInt`,
|
|
98
|
-
* and `Set` into JSON-friendly values, for places that only accept JSON.
|
|
99
|
-
*
|
|
100
|
-
* @see {@link https://orpc.dev/docs/openapi/serializer#openapi-json-serializer | OpenAPI Serializer - OpenAPI JSON Serializer}
|
|
101
|
-
*/
|
|
102
|
-
declare class OpenAPIJsonSerializer {
|
|
103
|
-
private readonly inlineBuiltInHandlers;
|
|
104
|
-
private readonly handlerEntries;
|
|
105
|
-
private readonly omitUndefinedProperties;
|
|
106
|
-
constructor(options?: OpenAPIJsonSerializerOptions);
|
|
107
|
-
serializeJson(data: unknown): OpenAPIJsonSerialization;
|
|
108
|
-
/**
|
|
109
|
-
* `segments` is a shared mutable stack (push/pop while walking),
|
|
110
|
-
* so it must be copied before being stored in `maps`.
|
|
111
|
-
*/
|
|
112
|
-
private serializeValue;
|
|
113
|
-
deserializeJson(serialized: OpenAPIJsonSerialization): unknown;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
interface OpenAPISerializerSerializeOptions {
|
|
117
|
-
/**
|
|
118
|
-
* Use FormData for serialization when nested blobs are present.
|
|
119
|
-
* Does not apply to root-level Blob values.
|
|
120
|
-
*
|
|
121
|
-
* @default true
|
|
122
|
-
*/
|
|
123
|
-
useFormDataForBlobFields?: boolean | undefined;
|
|
124
|
-
/**
|
|
125
|
-
* When enabled, the serialized output is always returned as a FormData instance using bracket notation.
|
|
126
|
-
*
|
|
127
|
-
* @default false
|
|
128
|
-
*/
|
|
129
|
-
asFormData?: boolean | undefined;
|
|
130
|
-
}
|
|
131
|
-
interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
|
|
132
|
-
/**
|
|
133
|
-
* Options for bracket notation serializer, like maxDeserializingEmptySlots
|
|
134
|
-
*/
|
|
135
|
-
bracketNotation?: BracketNotationSerializerOptions | undefined;
|
|
136
|
-
/**
|
|
137
|
-
* Default options for serialize method
|
|
138
|
-
*/
|
|
139
|
-
serialize?: OpenAPISerializerSerializeOptions | undefined;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Handles one-way serialization of oRPC payloads into JSON-friendly formats,
|
|
143
|
-
* partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
|
|
144
|
-
*
|
|
145
|
-
* @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
|
|
146
|
-
*/
|
|
147
|
-
declare class OpenAPISerializer extends OpenAPIJsonSerializer {
|
|
148
|
-
private readonly bracketNotation;
|
|
149
|
-
private readonly defaultSerializeOptions;
|
|
150
|
-
constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
|
|
151
|
-
serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
|
|
152
|
-
private serializePayload;
|
|
153
|
-
deserialize(data: StandardBody): unknown;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export { OpenAPISerializer as O, OpenAPIJsonSerializer as a, BracketNotationSerializer as b };
|
|
157
|
-
export type { BracketNotationSerializeResult as B, BracketNotationSerializerOptions as c, OpenAPIJsonSerialization as d, OpenAPIJsonSerializerHandler as e, OpenAPIJsonSerializerOptions as f, OpenAPISerializerOptions as g, OpenAPISerializerSerializeOptions as h };
|