@orpc/openapi 2.0.0-beta.43 → 2.0.0-beta.45
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 +56 -57
- package/dist/adapters/aws-lambda/index.d.mts +1 -1
- package/dist/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.mjs +2 -2
- package/dist/adapters/fastify/index.d.mts +1 -1
- package/dist/adapters/fastify/index.d.ts +1 -1
- package/dist/adapters/fastify/index.mjs +2 -2
- package/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.d.ts +1 -1
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +1 -1
- package/dist/adapters/node/index.d.ts +1 -1
- package/dist/adapters/node/index.mjs +2 -2
- package/dist/adapters/standard/index.d.mts +5 -5
- package/dist/adapters/standard/index.d.ts +5 -5
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.mjs +19 -43
- package/dist/plugins/index.d.mts +12 -12
- package/dist/plugins/index.d.ts +12 -12
- package/dist/shared/{openapi.BSLqRCwO.d.mts → openapi.B8v9IrIK.d.mts} +6 -5
- package/dist/shared/{openapi.C6KG7fwg.mjs → openapi.BNe1y1cD.mjs} +14 -9
- package/dist/shared/{openapi.r98bZ3Ig.d.ts → openapi.B_SoJfYz.d.mts} +1 -1
- package/dist/shared/{openapi.r98bZ3Ig.d.mts → openapi.B_SoJfYz.d.ts} +1 -1
- package/dist/shared/{openapi.aoP0G_Bv.d.ts → openapi.C1MLxqih.d.ts} +5 -5
- package/dist/shared/{openapi.BVt3NPfo.d.mts → openapi.CCZPbgOq.d.mts} +5 -5
- package/dist/shared/{openapi.1UQkZGBs.d.ts → openapi.C_r_fZl2.d.ts} +6 -5
- package/dist/shared/{openapi.DjGhiceP.d.mts → openapi.D42Ps1fQ.d.mts} +9 -10
- package/dist/shared/{openapi.DjGhiceP.d.ts → openapi.D42Ps1fQ.d.ts} +9 -10
- package/dist/shared/{openapi.DcQKf6ur.mjs → openapi.DXqJL3gB.mjs} +11 -22
- package/dist/shared/{openapi.PXVenYpE.mjs → openapi.E3ZBiweM.mjs} +12 -13
- package/package.json +13 -13
|
@@ -15,7 +15,7 @@ interface BracketNotationSerializerOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* @default 1_000
|
|
17
17
|
*/
|
|
18
|
-
maxDeserializingEmptySlots?: number;
|
|
18
|
+
maxDeserializingEmptySlots?: number | undefined;
|
|
19
19
|
}
|
|
20
20
|
declare class BracketNotationSerializer {
|
|
21
21
|
private readonly maxDeserializingEmptySlots;
|
|
@@ -47,7 +47,7 @@ interface OpenAPIJsonSerializerHandler {
|
|
|
47
47
|
*
|
|
48
48
|
* @default false
|
|
49
49
|
*/
|
|
50
|
-
isTerminal?: boolean;
|
|
50
|
+
isTerminal?: boolean | undefined;
|
|
51
51
|
}
|
|
52
52
|
interface OpenAPIJsonSerializerOptions {
|
|
53
53
|
/**
|
|
@@ -98,13 +98,13 @@ declare class OpenAPIJsonSerializer {
|
|
|
98
98
|
private readonly handlerEntries;
|
|
99
99
|
private readonly omitUndefinedProperties;
|
|
100
100
|
constructor(options?: OpenAPIJsonSerializerOptions);
|
|
101
|
-
|
|
101
|
+
serializeJson(data: unknown): OpenAPIJsonSerialization;
|
|
102
102
|
/**
|
|
103
103
|
* `segments` is a shared mutable stack (push/pop while walking),
|
|
104
104
|
* so it must be copied before being stored in `maps`.
|
|
105
105
|
*/
|
|
106
106
|
private serializeValue;
|
|
107
|
-
|
|
107
|
+
deserializeJson(serialized: OpenAPIJsonSerialization): unknown;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
interface OpenAPISerializerSerializeOptions {
|
|
@@ -114,7 +114,7 @@ interface OpenAPISerializerSerializeOptions {
|
|
|
114
114
|
*
|
|
115
115
|
* @default true
|
|
116
116
|
*/
|
|
117
|
-
useFormDataForBlobFields?: boolean;
|
|
117
|
+
useFormDataForBlobFields?: boolean | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* When enabled, the serialized output is always returned as a FormData instance using bracket notation.
|
|
120
120
|
*
|
|
@@ -138,15 +138,14 @@ interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
|
|
|
138
138
|
*
|
|
139
139
|
* @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
|
|
140
140
|
*/
|
|
141
|
-
declare class OpenAPISerializer {
|
|
142
|
-
private readonly jsonSerializer;
|
|
141
|
+
declare class OpenAPISerializer extends OpenAPIJsonSerializer {
|
|
143
142
|
private readonly bracketNotation;
|
|
144
143
|
private readonly defaultSerializeOptions;
|
|
145
144
|
constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
|
|
146
145
|
serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
|
|
147
|
-
private
|
|
146
|
+
private serializePayload;
|
|
148
147
|
deserialize(data: StandardBody): unknown;
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
export {
|
|
152
|
-
export type { BracketNotationSerializeResult as B, BracketNotationSerializerOptions as
|
|
150
|
+
export { OpenAPIJsonSerializer as O, OpenAPISerializer as a, BracketNotationSerializer as b };
|
|
151
|
+
export type { BracketNotationSerializeResult as B, BracketNotationSerializerOptions as c, OpenAPIJsonSerialization as d, OpenAPIJsonSerializerHandler as e, OpenAPIJsonSerializerOptions as f, OpenAPISerializerOptions as g, OpenAPISerializerSerializeOptions as h };
|
|
@@ -15,7 +15,7 @@ interface BracketNotationSerializerOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* @default 1_000
|
|
17
17
|
*/
|
|
18
|
-
maxDeserializingEmptySlots?: number;
|
|
18
|
+
maxDeserializingEmptySlots?: number | undefined;
|
|
19
19
|
}
|
|
20
20
|
declare class BracketNotationSerializer {
|
|
21
21
|
private readonly maxDeserializingEmptySlots;
|
|
@@ -47,7 +47,7 @@ interface OpenAPIJsonSerializerHandler {
|
|
|
47
47
|
*
|
|
48
48
|
* @default false
|
|
49
49
|
*/
|
|
50
|
-
isTerminal?: boolean;
|
|
50
|
+
isTerminal?: boolean | undefined;
|
|
51
51
|
}
|
|
52
52
|
interface OpenAPIJsonSerializerOptions {
|
|
53
53
|
/**
|
|
@@ -98,13 +98,13 @@ declare class OpenAPIJsonSerializer {
|
|
|
98
98
|
private readonly handlerEntries;
|
|
99
99
|
private readonly omitUndefinedProperties;
|
|
100
100
|
constructor(options?: OpenAPIJsonSerializerOptions);
|
|
101
|
-
|
|
101
|
+
serializeJson(data: unknown): OpenAPIJsonSerialization;
|
|
102
102
|
/**
|
|
103
103
|
* `segments` is a shared mutable stack (push/pop while walking),
|
|
104
104
|
* so it must be copied before being stored in `maps`.
|
|
105
105
|
*/
|
|
106
106
|
private serializeValue;
|
|
107
|
-
|
|
107
|
+
deserializeJson(serialized: OpenAPIJsonSerialization): unknown;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
interface OpenAPISerializerSerializeOptions {
|
|
@@ -114,7 +114,7 @@ interface OpenAPISerializerSerializeOptions {
|
|
|
114
114
|
*
|
|
115
115
|
* @default true
|
|
116
116
|
*/
|
|
117
|
-
useFormDataForBlobFields?: boolean;
|
|
117
|
+
useFormDataForBlobFields?: boolean | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* When enabled, the serialized output is always returned as a FormData instance using bracket notation.
|
|
120
120
|
*
|
|
@@ -138,15 +138,14 @@ interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
|
|
|
138
138
|
*
|
|
139
139
|
* @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
|
|
140
140
|
*/
|
|
141
|
-
declare class OpenAPISerializer {
|
|
142
|
-
private readonly jsonSerializer;
|
|
141
|
+
declare class OpenAPISerializer extends OpenAPIJsonSerializer {
|
|
143
142
|
private readonly bracketNotation;
|
|
144
143
|
private readonly defaultSerializeOptions;
|
|
145
144
|
constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
|
|
146
145
|
serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
|
|
147
|
-
private
|
|
146
|
+
private serializePayload;
|
|
148
147
|
deserialize(data: StandardBody): unknown;
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
export {
|
|
152
|
-
export type { BracketNotationSerializeResult as B, BracketNotationSerializerOptions as
|
|
150
|
+
export { OpenAPIJsonSerializer as O, OpenAPISerializer as a, BracketNotationSerializer as b };
|
|
151
|
+
export type { BracketNotationSerializeResult as B, BracketNotationSerializerOptions as c, OpenAPIJsonSerialization as d, OpenAPIJsonSerializerHandler as e, OpenAPIJsonSerializerOptions as f, OpenAPISerializerOptions as g, OpenAPISerializerSerializeOptions as h };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
2
|
-
import { walkProcedureContractsSync, unlazy,
|
|
2
|
+
import { walkProcedureContractsSync, unlazy, resolveContractProcedure, Procedure, DEFAULT_SUCCESS_STATUS, DEFAULT_ERROR_STATUS } from '@orpc/server';
|
|
3
3
|
import { value, pathToHttpPath, mergeHttpPath, safeDecodeURIComponent, safeEncodeURIComponent, setOwn, NullProtoObj, isTypescriptObject, isPlainObject, stringifyJSON, getOwn, parseEmptyableJSON } from '@orpc/shared';
|
|
4
4
|
import { parseStandardUrl } from '@standard-server/core';
|
|
5
|
-
import { D as DEFAULT_OPENAPI_METHOD, g as getDynamicPathParams, O as OpenAPISerializer, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.
|
|
5
|
+
import { D as DEFAULT_OPENAPI_METHOD, g as getDynamicPathParams, O as OpenAPISerializer, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.E3ZBiweM.mjs';
|
|
6
6
|
import { g as getOpenAPIMeta } from './openapi.B9PQzqBn.mjs';
|
|
7
7
|
import { createRouter, addRoute, findRoute, findAllRoutes, routeToRegExp } from 'rou3';
|
|
8
8
|
|
|
@@ -71,19 +71,12 @@ class OpenAPIMatcher {
|
|
|
71
71
|
return void 0;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
pathname = normalizeRou3Path(pathname);
|
|
74
75
|
const loading = this.resolvePendingLazyRouters(pathname);
|
|
75
76
|
if (loading !== void 0) {
|
|
76
77
|
await loading;
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
-
if (match === void 0 && NORMALIZABLE_PATHNAME_REGEX.test(pathname)) {
|
|
80
|
-
const normalizedPathname = normalizeRou3Path(pathname);
|
|
81
|
-
const normalizedLoading = this.resolvePendingLazyRouters(normalizedPathname);
|
|
82
|
-
if (normalizedLoading !== void 0) {
|
|
83
|
-
await normalizedLoading;
|
|
84
|
-
}
|
|
85
|
-
match = this.findMatch(method, normalizedPathname);
|
|
86
|
-
}
|
|
79
|
+
const match = this.findMatch(method, pathname);
|
|
87
80
|
if (match === void 0) {
|
|
88
81
|
return void 0;
|
|
89
82
|
}
|
|
@@ -130,13 +123,7 @@ class OpenAPIMatcher {
|
|
|
130
123
|
this.pendingLazyRouters.delete(pending);
|
|
131
124
|
}
|
|
132
125
|
async resolveProcedure(entry) {
|
|
133
|
-
|
|
134
|
-
if (!(maybeProcedure instanceof Procedure)) {
|
|
135
|
-
throw new TypeError(
|
|
136
|
-
`[Contract-First] Missing or invalid implementation for procedure at path: "${entry.path.join(".")}". Ensure the procedure is correctly implemented and matches its contract.`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
entry.procedure = createContractProcedure(maybeProcedure, entry.contract);
|
|
126
|
+
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
140
127
|
return entry.procedure;
|
|
141
128
|
}
|
|
142
129
|
}
|
|
@@ -169,11 +156,13 @@ function toRou3Route(path) {
|
|
|
169
156
|
}
|
|
170
157
|
const ROU3_SYNTAX_REGEX = /[\\:*?+(){}]|(?<![^/])\.(?=\.?(?:\/|$))/g;
|
|
171
158
|
function toRou3Literal(text) {
|
|
172
|
-
|
|
173
|
-
return normalized.replace(ROU3_SYNTAX_REGEX, "\\$&");
|
|
159
|
+
return normalizeRou3Path(text).replace(ROU3_SYNTAX_REGEX, "\\$&");
|
|
174
160
|
}
|
|
175
161
|
function normalizeRou3Path(path) {
|
|
176
|
-
|
|
162
|
+
if (!NORMALIZABLE_PATHNAME_REGEX.test(path)) {
|
|
163
|
+
return path;
|
|
164
|
+
}
|
|
165
|
+
return path.split("/").map((segment) => NORMALIZABLE_PATHNAME_REGEX.test(segment) ? safeDecodeURIComponent(segment).replace(ROU3_ENCODED_SEGMENT_TEXT_REGEX, safeEncodeURIComponent) : segment).join("/");
|
|
177
166
|
}
|
|
178
167
|
function toRou3PrefixMatcher(prefix) {
|
|
179
168
|
const catchAll = getDynamicPathParams(prefix)?.find((param) => param.allowsSlash);
|
|
@@ -213,7 +202,7 @@ function serializeHeaders(headers, serializer) {
|
|
|
213
202
|
return result;
|
|
214
203
|
}
|
|
215
204
|
function serializeHeaderValue(value, serializer) {
|
|
216
|
-
const serialized = serializer.
|
|
205
|
+
const serialized = serializer.serializeJson(value).json;
|
|
217
206
|
if (Array.isArray(serialized)) {
|
|
218
207
|
return serialized.filter((item) => item !== void 0 && item !== null).map(String).join(",");
|
|
219
208
|
}
|
|
@@ -117,7 +117,7 @@ class OpenAPIJsonSerializer {
|
|
|
117
117
|
this.inlineBuiltInHandlers = inlineBuiltInHandlers;
|
|
118
118
|
this.handlerEntries = handlerEntries;
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
serializeJson(data) {
|
|
121
121
|
const maps = [];
|
|
122
122
|
const blobs = [];
|
|
123
123
|
const json = this.serializeValue(data, [], maps, blobs);
|
|
@@ -207,7 +207,7 @@ class OpenAPIJsonSerializer {
|
|
|
207
207
|
}
|
|
208
208
|
return data;
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
deserializeJson(serialized) {
|
|
211
211
|
const ref = { json: serialized.json };
|
|
212
212
|
if (serialized.blobs?.length) {
|
|
213
213
|
for (let i = 0; i < serialized.maps.length; i++) {
|
|
@@ -234,12 +234,11 @@ class OpenAPIJsonSerializer {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
class OpenAPISerializer {
|
|
238
|
-
jsonSerializer;
|
|
237
|
+
class OpenAPISerializer extends OpenAPIJsonSerializer {
|
|
239
238
|
bracketNotation;
|
|
240
239
|
defaultSerializeOptions;
|
|
241
240
|
constructor({ bracketNotation, serialize, ...options } = {}) {
|
|
242
|
-
|
|
241
|
+
super(options);
|
|
243
242
|
this.bracketNotation = new BracketNotationSerializer(bracketNotation);
|
|
244
243
|
this.defaultSerializeOptions = serialize;
|
|
245
244
|
}
|
|
@@ -254,10 +253,10 @@ class OpenAPISerializer {
|
|
|
254
253
|
if (result.value === void 0) {
|
|
255
254
|
return result;
|
|
256
255
|
}
|
|
257
|
-
return { done: result.done, value: this.
|
|
256
|
+
return { done: result.done, value: this.serializePayload(result.value, false, false) };
|
|
258
257
|
},
|
|
259
258
|
mapError: (e) => new ErrorEvent(
|
|
260
|
-
this.
|
|
259
|
+
this.serializePayload(toORPCError(e).toJSON(), false, false),
|
|
261
260
|
{ cause: e }
|
|
262
261
|
)
|
|
263
262
|
});
|
|
@@ -265,10 +264,10 @@ class OpenAPISerializer {
|
|
|
265
264
|
}
|
|
266
265
|
const useFormDataForBlobFields = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
|
|
267
266
|
const asFormData = options.asFormData ?? this.defaultSerializeOptions?.asFormData ?? false;
|
|
268
|
-
return this.
|
|
267
|
+
return this.serializePayload(data, useFormDataForBlobFields, asFormData);
|
|
269
268
|
}
|
|
270
|
-
|
|
271
|
-
const { json, blobs } = this.
|
|
269
|
+
serializePayload(value, useFormDataForBlobFields, asFormData) {
|
|
270
|
+
const { json, blobs } = this.serializeJson(value);
|
|
272
271
|
if (!asFormData && (json instanceof Blob || json === void 0 || !blobs?.length || !useFormDataForBlobFields)) {
|
|
273
272
|
return json;
|
|
274
273
|
}
|
|
@@ -292,11 +291,11 @@ class OpenAPISerializer {
|
|
|
292
291
|
if (result.value === void 0) {
|
|
293
292
|
return result;
|
|
294
293
|
}
|
|
295
|
-
return { done: result.done, value: this.
|
|
294
|
+
return { done: result.done, value: this.deserializeJson({ json: result.value }) };
|
|
296
295
|
},
|
|
297
296
|
mapError: (e) => {
|
|
298
297
|
if (e instanceof ErrorEvent) {
|
|
299
|
-
const deserialized = this.
|
|
298
|
+
const deserialized = this.deserializeJson({ json: e.data });
|
|
300
299
|
if (isORPCErrorJson(deserialized)) {
|
|
301
300
|
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
302
301
|
}
|
|
@@ -308,7 +307,7 @@ class OpenAPISerializer {
|
|
|
308
307
|
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
309
308
|
data = this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
310
309
|
}
|
|
311
|
-
return this.
|
|
310
|
+
return this.deserializeJson({ json: data });
|
|
312
311
|
}
|
|
313
312
|
}
|
|
314
313
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.45",
|
|
5
5
|
"description": "Generate OpenAPI specs from oRPC routers and serve OpenAPI-compliant APIs with end-to-end type safety",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -99,22 +99,22 @@
|
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"@openapi-spec/downgrader": "~0.3.0",
|
|
101
101
|
"@openapi-spec/types": "~0.3.0",
|
|
102
|
-
"@orpc/client": "2.0.0-beta.
|
|
103
|
-
"@orpc/contract": "2.0.0-beta.
|
|
104
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
105
|
-
"@orpc/server": "2.0.0-beta.
|
|
106
|
-
"@orpc/shared": "2.0.0-beta.
|
|
107
|
-
"@standard-server/core": "~0.
|
|
108
|
-
"@standard-server/fetch": "~0.
|
|
102
|
+
"@orpc/client": "2.0.0-beta.45",
|
|
103
|
+
"@orpc/contract": "2.0.0-beta.45",
|
|
104
|
+
"@orpc/json-schema": "2.0.0-beta.45",
|
|
105
|
+
"@orpc/server": "2.0.0-beta.45",
|
|
106
|
+
"@orpc/shared": "2.0.0-beta.45",
|
|
107
|
+
"@standard-server/core": "~0.11.0",
|
|
108
|
+
"@standard-server/fetch": "~0.11.0",
|
|
109
109
|
"rou3": "^1.0.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@scalar/api-reference": "^1.
|
|
113
|
-
"@standard-server/aws-lambda": "~0.
|
|
112
|
+
"@scalar/api-reference": "^1.74.0",
|
|
113
|
+
"@standard-server/aws-lambda": "~0.11.0",
|
|
114
114
|
"@types/swagger-ui": "^5.32.0",
|
|
115
|
-
"fastify": "^5.12.
|
|
116
|
-
"swagger-ui": "^5.
|
|
117
|
-
"zod": "^4.
|
|
115
|
+
"fastify": "^5.12.7",
|
|
116
|
+
"swagger-ui": "^5.33.2",
|
|
117
|
+
"zod": "^4.6.7"
|
|
118
118
|
},
|
|
119
119
|
"scripts": {
|
|
120
120
|
"type:check": "tsc -b"
|