@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50

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 (65) hide show
  1. package/dist/adapters/aws-lambda/index.d.ts +3 -15
  2. package/dist/adapters/aws-lambda/index.js +1 -1
  3. package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
  4. package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
  5. package/dist/adapters/fastify/index.d.ts +2 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
  8. package/dist/adapters/fastify/openapi-handler.js +16 -14
  9. package/dist/adapters/fetch/index.d.ts +3 -2
  10. package/dist/adapters/fetch/index.js +2 -2
  11. package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
  12. package/dist/adapters/fetch/openapi-handler.js +16 -14
  13. package/dist/adapters/fetch/openapi-link.d.ts +9 -10
  14. package/dist/adapters/fetch/openapi-link.js +21 -19
  15. package/dist/adapters/node/index.d.ts +2 -1
  16. package/dist/adapters/node/index.js +1 -1
  17. package/dist/adapters/node/openapi-handler.d.ts +8 -9
  18. package/dist/adapters/node/openapi-handler.js +16 -14
  19. package/dist/adapters/standard/index.d.ts +4 -3
  20. package/dist/adapters/standard/index.js +3 -3
  21. package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
  22. package/dist/adapters/standard/openapi-handler-codec.js +143 -205
  23. package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
  24. package/dist/adapters/standard/openapi-link-codec.js +262 -377
  25. package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
  26. package/dist/adapters/standard/openapi-matcher.js +78 -108
  27. package/dist/adapters/standard/utils.js +28 -44
  28. package/dist/bracket-notation.d.ts +22 -22
  29. package/dist/bracket-notation.js +123 -173
  30. package/dist/client-factory.d.ts +12 -12
  31. package/dist/client-factory.js +13 -11
  32. package/dist/constants.d.ts +1 -4
  33. package/dist/constants.js +5 -4
  34. package/dist/extensions/route.d.ts +36 -36
  35. package/dist/extensions/route.js +7 -6
  36. package/dist/helpers/form-data.d.ts +1 -1
  37. package/dist/helpers/form-data.js +74 -86
  38. package/dist/helpers/index.d.ts +2 -1
  39. package/dist/helpers/index.js +1 -1
  40. package/dist/index.d.ts +15 -13
  41. package/dist/index.js +11 -11
  42. package/dist/meta.d.ts +298 -298
  43. package/dist/meta.js +54 -72
  44. package/dist/openapi-generator-components.d.ts +2 -31
  45. package/dist/openapi-generator-components.js +200 -248
  46. package/dist/openapi-generator-operation.d.ts +12 -33
  47. package/dist/openapi-generator-operation.js +369 -437
  48. package/dist/openapi-generator.d.ts +75 -80
  49. package/dist/openapi-generator.js +114 -142
  50. package/dist/openapi-json-serializer.d.ts +65 -65
  51. package/dist/openapi-json-serializer.js +218 -257
  52. package/dist/openapi-serializer.d.ts +31 -32
  53. package/dist/openapi-serializer.js +68 -92
  54. package/dist/plugins/index.d.ts +2 -1
  55. package/dist/plugins/index.js +1 -1
  56. package/dist/plugins/openapi-reference.d.ts +99 -102
  57. package/dist/plugins/openapi-reference.js +109 -132
  58. package/dist/router-utils.d.ts +7 -10
  59. package/dist/router-utils.js +30 -34
  60. package/dist/types.d.ts +8 -12
  61. package/dist/utils.d.ts +5 -10
  62. package/dist/utils.js +39 -42
  63. package/package.json +12 -12
  64. package/dist/adapters/standard/utils.d.ts +0 -4
  65. package/dist/types.js +0 -1
@@ -1,260 +1,221 @@
1
- import { copyOnWrite, isPlainObject, NullProtoObj } from '@orpc/shared';
1
+ import { NullProtoObj, copyOnWrite, isPlainObject } from "@orpc/shared";
2
+ // src/openapi-json-serializer.ts
2
3
  const DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS = {
3
- undefined: {
4
- condition(data) {
5
- return data === undefined;
6
- },
7
- serialize() {
8
- return null;
9
- },
10
- isTerminal: true,
11
- },
12
- bigint: {
13
- condition(data) {
14
- return typeof data === 'bigint';
15
- },
16
- serialize(data) {
17
- return data.toString();
18
- },
19
- isTerminal: true,
20
- },
21
- date: {
22
- condition(data) {
23
- return data instanceof Date;
24
- },
25
- serialize(data) {
26
- if (Number.isNaN(data.getTime())) {
27
- return null;
28
- }
29
- return data.toISOString();
30
- },
31
- isTerminal: true,
32
- },
33
- nan: {
34
- condition(data) {
35
- return typeof data === 'number' && Number.isNaN(data);
36
- },
37
- serialize() {
38
- return null;
39
- },
40
- isTerminal: true,
41
- },
42
- infinity: {
43
- condition(data) {
44
- return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
45
- },
46
- serialize() {
47
- return null;
48
- },
49
- isTerminal: true,
50
- },
51
- url: {
52
- condition(data) {
53
- return data instanceof URL;
54
- },
55
- serialize(data) {
56
- return data.toString();
57
- },
58
- isTerminal: true,
59
- },
60
- set: {
61
- condition(data) {
62
- return data instanceof Set;
63
- },
64
- serialize(data) {
65
- return Array.from(data);
66
- },
67
- },
68
- map: {
69
- condition(data) {
70
- return data instanceof Map;
71
- },
72
- serialize(data) {
73
- return Array.from(data.entries());
74
- },
75
- },
4
+ undefined: {
5
+ condition(data) {
6
+ return data === void 0;
7
+ },
8
+ serialize() {
9
+ return null;
10
+ },
11
+ isTerminal: true
12
+ },
13
+ bigint: {
14
+ condition(data) {
15
+ return typeof data === "bigint";
16
+ },
17
+ serialize(data) {
18
+ return data.toString();
19
+ },
20
+ isTerminal: true
21
+ },
22
+ date: {
23
+ condition(data) {
24
+ return data instanceof Date;
25
+ },
26
+ serialize(data) {
27
+ if (Number.isNaN(data.getTime())) return null;
28
+ return data.toISOString();
29
+ },
30
+ isTerminal: true
31
+ },
32
+ nan: {
33
+ condition(data) {
34
+ return typeof data === "number" && Number.isNaN(data);
35
+ },
36
+ serialize() {
37
+ return null;
38
+ },
39
+ isTerminal: true
40
+ },
41
+ infinity: {
42
+ condition(data) {
43
+ return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
44
+ },
45
+ serialize() {
46
+ return null;
47
+ },
48
+ isTerminal: true
49
+ },
50
+ url: {
51
+ condition(data) {
52
+ return data instanceof URL;
53
+ },
54
+ serialize(data) {
55
+ return data.toString();
56
+ },
57
+ isTerminal: true
58
+ },
59
+ set: {
60
+ condition(data) {
61
+ return data instanceof Set;
62
+ },
63
+ serialize(data) {
64
+ return Array.from(data);
65
+ }
66
+ },
67
+ map: {
68
+ condition(data) {
69
+ return data instanceof Map;
70
+ },
71
+ serialize(data) {
72
+ return Array.from(data.entries());
73
+ }
74
+ }
76
75
  };
77
76
  /**
78
- * The JSON layer behind `OpenAPISerializer`: one-way serialization of types like `Date`, `BigInt`,
79
- * and `Set` into JSON-friendly values, for places that only accept JSON.
80
- *
81
- * @see {@link https://orpc.dev/docs/openapi/serializer#openapi-json-serializer | OpenAPI Serializer - OpenAPI JSON Serializer}
82
- */
83
- export class OpenAPIJsonSerializer {
84
- inlineBuiltInHandlers;
85
- handlerEntries;
86
- constructor(options = {}) {
87
- const customHandlers = options.handlers;
88
- if (customHandlers === undefined) {
89
- this.inlineBuiltInHandlers = true;
90
- return;
91
- }
92
- let inlineBuiltInHandlers = true;
93
- let handlerEntries = [];
94
- for (const key of Object.keys(customHandlers)) {
95
- const handler = customHandlers[key];
96
- if (inlineBuiltInHandlers && key in DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS) {
97
- inlineBuiltInHandlers = false;
98
- break;
99
- }
100
- if (handler !== undefined) {
101
- handlerEntries.push(handler);
102
- }
103
- }
104
- if (!inlineBuiltInHandlers) {
105
- handlerEntries = [];
106
- for (const handler of Object.values({
107
- ...DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS,
108
- ...customHandlers,
109
- })) {
110
- if (handler !== undefined) {
111
- handlerEntries.push(handler);
112
- }
113
- }
114
- }
115
- this.inlineBuiltInHandlers = inlineBuiltInHandlers;
116
- // undefined = no handlers to check, so the inline path can return primitives early
117
- this.handlerEntries = handlerEntries.length === 0 ? undefined : handlerEntries;
118
- }
119
- serializeJson(data) {
120
- const maps = [];
121
- const blobs = [];
122
- const json = this.serializeValue(data, [], maps, blobs);
123
- return { json, maps, blobs };
124
- }
125
- /**
126
- * `segments` is a shared mutable stack (push/pop while walking),
127
- * so it must be copied before being stored in `maps`.
128
- */
129
- serializeValue(data, segments, maps, blobs) {
130
- const handlerEntries = this.handlerEntries;
131
- /**
132
- * Inlined version of DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS: primitives
133
- * are dispatched on typeof and skip every handler condition check.
134
- * Must match the built-in handlers exactly.
135
- * Primitives without a built-in handler return early unless custom handlers must see them.
136
- */
137
- if (this.inlineBuiltInHandlers) {
138
- switch (typeof data) {
139
- case 'string':
140
- case 'boolean':
141
- if (handlerEntries === undefined) {
142
- return data;
143
- }
144
- break;
145
- case 'number':
146
- if (!Number.isFinite(data)) {
147
- return null;
148
- }
149
- if (handlerEntries === undefined) {
150
- return data;
151
- }
152
- break;
153
- case 'undefined':
154
- return null;
155
- case 'bigint':
156
- return data.toString();
157
- case 'object': {
158
- if (data === null) {
159
- if (handlerEntries === undefined) {
160
- return data;
161
- }
162
- break;
163
- }
164
- if (data instanceof Date) {
165
- return Number.isNaN(data.getTime()) ? null : data.toISOString();
166
- }
167
- if (data instanceof URL) {
168
- return data.toString();
169
- }
170
- if (data instanceof Set) {
171
- return this.serializeValue(Array.from(data), segments, maps, blobs);
172
- }
173
- if (data instanceof Map) {
174
- return this.serializeValue(Array.from(data.entries()), segments, maps, blobs);
175
- }
176
- }
177
- }
178
- }
179
- if (handlerEntries) {
180
- for (let i = 0; i < handlerEntries.length; i++) {
181
- const handler = handlerEntries[i];
182
- if (handler.condition(data)) {
183
- const serialized = handler.serialize(data);
184
- if (handler.isTerminal) {
185
- if (serialized instanceof Blob) {
186
- maps.push(segments.slice());
187
- blobs.push(serialized);
188
- }
189
- return serialized;
190
- }
191
- return this.serializeValue(serialized, segments, maps, blobs);
192
- }
193
- }
194
- }
195
- if (typeof data !== 'object' || data === null) {
196
- return data;
197
- }
198
- if (data instanceof Blob) {
199
- maps.push(segments.slice());
200
- blobs.push(data);
201
- return data;
202
- }
203
- if (Array.isArray(data)) {
204
- const json = [];
205
- for (let i = 0; i < data.length; i++) {
206
- segments.push(i);
207
- json.push(this.serializeValue(data[i], segments, maps, blobs));
208
- segments.pop();
209
- }
210
- return json;
211
- }
212
- if (isPlainObject(data)) {
213
- const json = new NullProtoObj();
214
- for (const k of Object.keys(data)) {
215
- const v = data[k];
216
- /**
217
- * Skip custom toJSON methods to avoid JSON.stringify invoking them,
218
- * which could cause meta and serialized data mismatches during deserialization.
219
- * Instead, rely on custom handlers.
220
- */
221
- if (k === 'toJSON' && typeof v === 'function') {
222
- continue;
223
- }
224
- if (v === undefined) {
225
- continue;
226
- }
227
- segments.push(k);
228
- json[k] = this.serializeValue(v, segments, maps, blobs);
229
- segments.pop();
230
- }
231
- return json;
232
- }
233
- return data;
234
- }
235
- deserializeJson(serialized) {
236
- const ref = { json: serialized.json };
237
- if (serialized.blobs?.length) {
238
- for (let i = 0; i < serialized.maps.length; i++) {
239
- const blob = serialized.blobs[i];
240
- if (!(blob instanceof Blob)) {
241
- throw new TypeError(`Invalid OpenAPI serialized data: blob ${i} is not a Blob.`);
242
- }
243
- const segments = serialized.maps[i];
244
- let original = serialized;
245
- let currentRef = ref;
246
- let preSegment = 'json';
247
- for (let j = 0; j < segments.length; j++) {
248
- original = original[preSegment];
249
- currentRef = copyOnWrite(currentRef, preSegment, original);
250
- preSegment = segments[j];
251
- if (!Object.hasOwn(currentRef, preSegment)) {
252
- throw new TypeError(`Invalid OpenAPI serialized data: segment "${preSegment}" does not exist.`);
253
- }
254
- }
255
- currentRef[preSegment] = blob;
256
- }
257
- }
258
- return ref.json;
259
- }
260
- }
77
+ * The JSON layer behind `OpenAPISerializer`: one-way serialization of types like `Date`, `BigInt`,
78
+ * and `Set` into JSON-friendly values, for places that only accept JSON.
79
+ *
80
+ * @see {@link https://orpc.dev/docs/openapi/serializer#openapi-json-serializer | OpenAPI Serializer - OpenAPI JSON Serializer}
81
+ */
82
+ var OpenAPIJsonSerializer = class {
83
+ inlineBuiltInHandlers;
84
+ handlerEntries;
85
+ constructor(options = {}) {
86
+ const customHandlers = options.handlers;
87
+ if (customHandlers === void 0) {
88
+ this.inlineBuiltInHandlers = true;
89
+ return;
90
+ }
91
+ let inlineBuiltInHandlers = true;
92
+ let handlerEntries = [];
93
+ for (const key of Object.keys(customHandlers)) {
94
+ const handler = customHandlers[key];
95
+ if (inlineBuiltInHandlers && key in DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS) {
96
+ inlineBuiltInHandlers = false;
97
+ break;
98
+ }
99
+ if (handler !== void 0) handlerEntries.push(handler);
100
+ }
101
+ if (!inlineBuiltInHandlers) {
102
+ handlerEntries = [];
103
+ for (const handler of Object.values({
104
+ ...DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS,
105
+ ...customHandlers
106
+ })) if (handler !== void 0) handlerEntries.push(handler);
107
+ }
108
+ this.inlineBuiltInHandlers = inlineBuiltInHandlers;
109
+ this.handlerEntries = handlerEntries.length === 0 ? void 0 : handlerEntries;
110
+ }
111
+ serializeJson(data) {
112
+ const maps = [];
113
+ const blobs = [];
114
+ return {
115
+ json: this.serializeValue(data, [], maps, blobs),
116
+ maps,
117
+ blobs
118
+ };
119
+ }
120
+ /**
121
+ * `segments` is a shared mutable stack (push/pop while walking),
122
+ * so it must be copied before being stored in `maps`.
123
+ */
124
+ serializeValue(data, segments, maps, blobs) {
125
+ const handlerEntries = this.handlerEntries;
126
+ /**
127
+ * Inlined version of DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS: primitives
128
+ * are dispatched on typeof and skip every handler condition check.
129
+ * Must match the built-in handlers exactly.
130
+ * Primitives without a built-in handler return early unless custom handlers must see them.
131
+ */
132
+ if (this.inlineBuiltInHandlers) switch (typeof data) {
133
+ case "string":
134
+ case "boolean":
135
+ if (handlerEntries === void 0) return data;
136
+ break;
137
+ case "number":
138
+ if (!Number.isFinite(data)) return null;
139
+ if (handlerEntries === void 0) return data;
140
+ break;
141
+ case "undefined": return null;
142
+ case "bigint": return data.toString();
143
+ case "object":
144
+ if (data === null) {
145
+ if (handlerEntries === void 0) return data;
146
+ break;
147
+ }
148
+ if (data instanceof Date) return Number.isNaN(data.getTime()) ? null : data.toISOString();
149
+ if (data instanceof URL) return data.toString();
150
+ if (data instanceof Set) return this.serializeValue(Array.from(data), segments, maps, blobs);
151
+ if (data instanceof Map) return this.serializeValue(Array.from(data.entries()), segments, maps, blobs);
152
+ }
153
+ if (handlerEntries) for (let i = 0; i < handlerEntries.length; i++) {
154
+ const handler = handlerEntries[i];
155
+ if (handler.condition(data)) {
156
+ const serialized = handler.serialize(data);
157
+ if (handler.isTerminal) {
158
+ if (serialized instanceof Blob) {
159
+ maps.push(segments.slice());
160
+ blobs.push(serialized);
161
+ }
162
+ return serialized;
163
+ }
164
+ return this.serializeValue(serialized, segments, maps, blobs);
165
+ }
166
+ }
167
+ if (typeof data !== "object" || data === null) return data;
168
+ if (data instanceof Blob) {
169
+ maps.push(segments.slice());
170
+ blobs.push(data);
171
+ return data;
172
+ }
173
+ if (Array.isArray(data)) {
174
+ const json = [];
175
+ for (let i = 0; i < data.length; i++) {
176
+ segments.push(i);
177
+ json.push(this.serializeValue(data[i], segments, maps, blobs));
178
+ segments.pop();
179
+ }
180
+ return json;
181
+ }
182
+ if (isPlainObject(data)) {
183
+ const json = new NullProtoObj();
184
+ for (const k of Object.keys(data)) {
185
+ const v = data[k];
186
+ /**
187
+ * Skip custom toJSON methods to avoid JSON.stringify invoking them,
188
+ * which could cause meta and serialized data mismatches during deserialization.
189
+ * Instead, rely on custom handlers.
190
+ */
191
+ if (k === "toJSON" && typeof v === "function") continue;
192
+ if (v === void 0) continue;
193
+ segments.push(k);
194
+ json[k] = this.serializeValue(v, segments, maps, blobs);
195
+ segments.pop();
196
+ }
197
+ return json;
198
+ }
199
+ return data;
200
+ }
201
+ deserializeJson(serialized) {
202
+ const ref = { json: serialized.json };
203
+ if (serialized.blobs?.length) for (let i = 0; i < serialized.maps.length; i++) {
204
+ const blob = serialized.blobs[i];
205
+ if (!(blob instanceof Blob)) throw new TypeError(`Invalid OpenAPI serialized data: blob ${i} is not a Blob.`);
206
+ const segments = serialized.maps[i];
207
+ let original = serialized;
208
+ let currentRef = ref;
209
+ let preSegment = "json";
210
+ for (let j = 0; j < segments.length; j++) {
211
+ original = original[preSegment];
212
+ currentRef = copyOnWrite(currentRef, preSegment, original);
213
+ preSegment = segments[j];
214
+ if (!Object.hasOwn(currentRef, preSegment)) throw new TypeError(`Invalid OpenAPI serialized data: segment "${preSegment}" does not exist.`);
215
+ }
216
+ currentRef[preSegment] = blob;
217
+ }
218
+ return ref.json;
219
+ }
220
+ };
221
+ export { OpenAPIJsonSerializer };
@@ -1,31 +1,30 @@
1
- import type { StandardBody } from '@standard-server/core';
2
- import type { BracketNotationSerializerOptions } from './bracket-notation.ts';
3
- import type { OpenAPIJsonSerializerOptions } from './openapi-json-serializer.ts';
4
- import { OpenAPIJsonSerializer } from './openapi-json-serializer.ts';
1
+ import { BracketNotationSerializerOptions } from "./bracket-notation.js";
2
+ import { OpenAPIJsonSerializer, OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.js";
3
+ import { StandardBody } from "@standard-server/core";
5
4
  export interface OpenAPISerializerSerializeOptions {
6
- /**
7
- * Use FormData for serialization when nested blobs are present.
8
- * Does not apply to root-level Blob values.
9
- *
10
- * @default true
11
- */
12
- useFormDataForBlobFields?: boolean | undefined;
13
- /**
14
- * When enabled, the serialized output is always returned as a FormData instance using bracket notation.
15
- *
16
- * @default false
17
- */
18
- asFormData?: boolean | undefined;
5
+ /**
6
+ * Use FormData for serialization when nested blobs are present.
7
+ * Does not apply to root-level Blob values.
8
+ *
9
+ * @default true
10
+ */
11
+ useFormDataForBlobFields?: boolean | undefined;
12
+ /**
13
+ * When enabled, the serialized output is always returned as a FormData instance using bracket notation.
14
+ *
15
+ * @default false
16
+ */
17
+ asFormData?: boolean | undefined;
19
18
  }
20
19
  export interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
21
- /**
22
- * Options for bracket notation serializer, like maxDeserializingEmptySlots
23
- */
24
- bracketNotation?: BracketNotationSerializerOptions | undefined;
25
- /**
26
- * Default options for serialize method
27
- */
28
- serialize?: OpenAPISerializerSerializeOptions | undefined;
20
+ /**
21
+ * Options for bracket notation serializer, like maxDeserializingEmptySlots
22
+ */
23
+ bracketNotation?: BracketNotationSerializerOptions | undefined;
24
+ /**
25
+ * Default options for serialize method
26
+ */
27
+ serialize?: OpenAPISerializerSerializeOptions | undefined;
29
28
  }
30
29
  /**
31
30
  * Handles one-way serialization of oRPC payloads into JSON-friendly formats,
@@ -34,10 +33,10 @@ export interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
34
33
  * @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
35
34
  */
36
35
  export declare class OpenAPISerializer extends OpenAPIJsonSerializer {
37
- private readonly bracketNotation;
38
- private readonly defaultSerializeOptions;
39
- constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
40
- serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
41
- private serializePayload;
42
- deserialize(data: StandardBody): unknown;
43
- }
36
+ private readonly bracketNotation;
37
+ private readonly defaultSerializeOptions;
38
+ constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
39
+ serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
40
+ private serializePayload;
41
+ deserialize(data: StandardBody): unknown;
42
+ }