@orpc/openapi 2.0.0-beta.3 → 2.0.0-beta.30
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 +71 -101
- package/dist/adapters/aws-lambda/index.d.mts +26 -0
- package/dist/adapters/aws-lambda/index.d.ts +26 -0
- package/dist/adapters/aws-lambda/index.mjs +21 -0
- package/dist/adapters/fastify/index.d.mts +23 -0
- package/dist/adapters/fastify/index.d.ts +23 -0
- package/dist/adapters/fastify/index.mjs +21 -0
- package/dist/adapters/fetch/index.d.mts +12 -2
- package/dist/adapters/fetch/index.d.ts +12 -2
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +7 -2
- package/dist/adapters/node/index.d.ts +7 -2
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +10 -46
- package/dist/adapters/standard/index.d.ts +10 -46
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/extensions/route.d.mts +2 -2
- package/dist/extensions/route.d.ts +2 -2
- package/dist/helpers/index.d.mts +9 -1
- package/dist/helpers/index.d.ts +9 -1
- package/dist/helpers/index.mjs +1 -1
- package/dist/index.d.mts +70 -36
- package/dist/index.d.ts +70 -36
- package/dist/index.mjs +701 -738
- package/dist/plugins/index.d.mts +10 -1
- package/dist/plugins/index.d.ts +10 -1
- package/dist/shared/{openapi.DmAa7YPO.mjs → openapi.0yE-t1W-.mjs} +120 -42
- package/dist/shared/{openapi.DuDd2iQz.d.mts → openapi.9smDzQwj.d.mts} +10 -7
- package/dist/shared/{openapi.B3H7yHQa.mjs → openapi.BaqI61Xi.mjs} +91 -42
- package/dist/shared/openapi.Bd9icEUa.d.mts +45 -0
- package/dist/shared/{openapi.B2SK0ZAr.mjs → openapi.BlHXe8vI.mjs} +21 -29
- package/dist/shared/openapi.D1CqEIRy.d.ts +45 -0
- package/dist/shared/{openapi.BQzzr4-4.d.ts → openapi.DTYZZ6Ph.d.ts} +36 -10
- package/dist/shared/{openapi.CYgMBSUF.d.mts → openapi.DfTTLtn5.d.mts} +19 -5
- package/dist/shared/{openapi.CYgMBSUF.d.ts → openapi.DfTTLtn5.d.ts} +19 -5
- package/dist/shared/{openapi.BcEtAxQj.d.mts → openapi.Drcd0PuL.d.mts} +36 -10
- package/dist/shared/{openapi.C7m7NAmH.d.mts → openapi.Dz-JaXHo.d.mts} +13 -2
- package/dist/shared/{openapi.C7m7NAmH.d.ts → openapi.Dz-JaXHo.d.ts} +13 -2
- package/dist/shared/{openapi.DBYxUpK8.d.ts → openapi.YCiBHaJ-.d.ts} +10 -7
- package/dist/shared/{openapi.Bt87OzTt.mjs → openapi.s_p5sN-P.mjs} +20 -15
- package/package.json +54 -14
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { isORPCErrorJson, createORPCErrorFromJson
|
|
1
|
+
import { createORPCErrorFromMalformedResponse, isORPCErrorJson, createORPCErrorFromJson } from '@orpc/client';
|
|
2
2
|
import { getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
3
3
|
import { unlazy } from '@orpc/server';
|
|
4
4
|
import { value, pathToHttpPath, mergeHttpPath, isTypescriptObject, stringifyJSON } from '@orpc/shared';
|
|
5
|
-
import { mergeStandardHeaders, parseStandardUrl
|
|
5
|
+
import { mergeStandardHeaders, parseStandardUrl } from '@standardserver/core';
|
|
6
6
|
import { toStandardHeaders } from '@standardserver/fetch';
|
|
7
|
-
import { O as OpenAPISerializer, D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, g as getDynamicPathParams, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.
|
|
7
|
+
import { O as OpenAPISerializer, D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, g as getDynamicPathParams, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.0yE-t1W-.mjs';
|
|
8
8
|
import { g as getOpenAPIMeta } from './openapi.B9PQzqBn.mjs';
|
|
9
|
+
import { s as serializeHeaders } from './openapi.BaqI61Xi.mjs';
|
|
9
10
|
|
|
10
|
-
class OpenAPILinkCodecError extends TypeError {
|
|
11
|
-
}
|
|
12
11
|
const END_SLASH_REGEX = /\/$/;
|
|
13
12
|
class OpenAPILinkCodec {
|
|
14
13
|
constructor(router, options = {}) {
|
|
@@ -42,7 +41,7 @@ class OpenAPILinkCodec {
|
|
|
42
41
|
let data = input;
|
|
43
42
|
if (dynamicParams?.length) {
|
|
44
43
|
if (!isTypescriptObject(input)) {
|
|
45
|
-
throw new
|
|
44
|
+
throw new TypeError(
|
|
46
45
|
`Input must be an object with "compact" input structure when the path has dynamic params (${dynamicParams.map((p) => p.parameterName).join(", ")}) in call to procedure (${path.join(".")}).`
|
|
47
46
|
);
|
|
48
47
|
}
|
|
@@ -56,7 +55,7 @@ class OpenAPILinkCodec {
|
|
|
56
55
|
data = Object.keys(remaining).length > 0 ? remaining : void 0;
|
|
57
56
|
}
|
|
58
57
|
pathname = `${basePathname.replace(END_SLASH_REGEX, "")}${pathname}`;
|
|
59
|
-
if (method
|
|
58
|
+
if (isBodylessMethod(method)) {
|
|
60
59
|
const queryString2 = this.serializeQueryString(data, meta?.queryStyles);
|
|
61
60
|
const search2 = combineSearch(baseSearch, queryString2);
|
|
62
61
|
const url3 = `${pathname}${search2 ?? ""}${baseHash ?? ""}`;
|
|
@@ -78,12 +77,12 @@ class OpenAPILinkCodec {
|
|
|
78
77
|
};
|
|
79
78
|
}
|
|
80
79
|
if (!isValidDetailedInput(input)) {
|
|
81
|
-
throw new
|
|
80
|
+
throw new TypeError(`
|
|
82
81
|
Invalid "detailed" input structure in call to procedure (${path.join(".")}):
|
|
83
82
|
\u2022 Expected an object or undefined with optional properties:
|
|
84
83
|
- params (object, required when the path has dynamic params)
|
|
85
84
|
- query (object)
|
|
86
|
-
- headers (
|
|
85
|
+
- headers (object)
|
|
87
86
|
- body (any)
|
|
88
87
|
|
|
89
88
|
Actual value:
|
|
@@ -92,7 +91,7 @@ class OpenAPILinkCodec {
|
|
|
92
91
|
}
|
|
93
92
|
if (dynamicParams?.length) {
|
|
94
93
|
if (!input?.params) {
|
|
95
|
-
throw new
|
|
94
|
+
throw new TypeError(
|
|
96
95
|
`The "params" property is required for "detailed" input when the path has dynamic params (${dynamicParams.map((p) => p.parameterName).join(", ")}) in call to procedure (${path.join(".")}).`
|
|
97
96
|
);
|
|
98
97
|
}
|
|
@@ -104,13 +103,13 @@ class OpenAPILinkCodec {
|
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
if (input?.headers) {
|
|
107
|
-
headers = mergeStandardHeaders(headers, input.headers);
|
|
106
|
+
headers = mergeStandardHeaders(headers, serializeHeaders(input.headers, this.serializer));
|
|
108
107
|
}
|
|
109
108
|
pathname = `${basePathname.replace(END_SLASH_REGEX, "")}${pathname}`;
|
|
110
109
|
const queryString = this.serializeQueryString(input?.query, meta?.queryStyles);
|
|
111
110
|
const search = combineSearch(baseSearch, queryString);
|
|
112
111
|
const url = `${pathname}${search ?? ""}${baseHash ?? ""}`;
|
|
113
|
-
if (method
|
|
112
|
+
if (isBodylessMethod(method)) {
|
|
114
113
|
return {
|
|
115
114
|
body: void 0,
|
|
116
115
|
method,
|
|
@@ -144,7 +143,7 @@ class OpenAPILinkCodec {
|
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
if (!encoded) {
|
|
147
|
-
throw new
|
|
146
|
+
throw new TypeError(`Path param "${param.parameterName}" cannot be empty in call to procedure (${path.join(".")}).`);
|
|
148
147
|
}
|
|
149
148
|
return encoded;
|
|
150
149
|
}
|
|
@@ -243,22 +242,17 @@ class OpenAPILinkCodec {
|
|
|
243
242
|
return query || void 0;
|
|
244
243
|
}
|
|
245
244
|
async decodeResponse(response, path, _options) {
|
|
246
|
-
const isOk = response.status
|
|
245
|
+
const isOk = response.status < 400;
|
|
247
246
|
const procedure = await this.resolveProcedure(path);
|
|
248
247
|
const meta = getOpenAPIMeta(procedure);
|
|
248
|
+
const body = await response.resolveBody(meta?.responseBodyHint);
|
|
249
249
|
const deserialized = await (async () => {
|
|
250
|
-
let isBodyOk = false;
|
|
251
250
|
try {
|
|
252
|
-
const body = await response.resolveBody(meta?.responseBodyHint);
|
|
253
|
-
isBodyOk = true;
|
|
254
251
|
return this.serializer.deserialize(body);
|
|
255
252
|
} catch (error) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
throw new Error("Invalid OpenAPI response format.", {
|
|
253
|
+
throw createORPCErrorFromMalformedResponse({
|
|
254
|
+
message: "Invalid OpenAPI response format.",
|
|
255
|
+
response: { status: response.status, headers: response.headers, body },
|
|
262
256
|
cause: error
|
|
263
257
|
});
|
|
264
258
|
}
|
|
@@ -273,9 +267,7 @@ class OpenAPILinkCodec {
|
|
|
273
267
|
}
|
|
274
268
|
return {
|
|
275
269
|
kind: "error",
|
|
276
|
-
error:
|
|
277
|
-
data: { headers: response.headers, status: response.status, body: deserialized }
|
|
278
|
-
})
|
|
270
|
+
error: createORPCErrorFromMalformedResponse({ response: { headers: response.headers, status: response.status, body } })
|
|
279
271
|
};
|
|
280
272
|
}
|
|
281
273
|
const outputStructure = meta?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
@@ -291,7 +283,7 @@ class OpenAPILinkCodec {
|
|
|
291
283
|
async resolveProcedure(path) {
|
|
292
284
|
const { default: maybeProcedure } = await unlazy(getRouterContract(this.router, path));
|
|
293
285
|
if (!(maybeProcedure instanceof ProcedureContract)) {
|
|
294
|
-
throw new
|
|
286
|
+
throw new TypeError(`Expected a procedure or contract at path (${path.join(".")})`);
|
|
295
287
|
}
|
|
296
288
|
return maybeProcedure;
|
|
297
289
|
}
|
|
@@ -324,7 +316,7 @@ function isValidDetailedInput(input) {
|
|
|
324
316
|
if (input.query !== void 0 && !isTypescriptObject(input.query)) {
|
|
325
317
|
return false;
|
|
326
318
|
}
|
|
327
|
-
if (input.headers !== void 0 && !
|
|
319
|
+
if (input.headers !== void 0 && !isTypescriptObject(input.headers)) {
|
|
328
320
|
return false;
|
|
329
321
|
}
|
|
330
322
|
return true;
|
|
@@ -356,4 +348,4 @@ function encodeDelimitedObject(entries, encodedDelimiter) {
|
|
|
356
348
|
).join(encodedDelimiter);
|
|
357
349
|
}
|
|
358
350
|
|
|
359
|
-
export { OpenAPILinkCodec as O
|
|
351
|
+
export { OpenAPILinkCodec as O };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
2
|
+
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
3
|
+
import { RouterContract } from '@orpc/contract';
|
|
4
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
5
|
+
import { StandardUrl, StandardHeaders, StandardLazyResponse, StandardRequest } from '@standardserver/core';
|
|
6
|
+
import { O as OpenAPISerializer } from './openapi.Dz-JaXHo.js';
|
|
7
|
+
|
|
8
|
+
interface OpenAPILinkCodecOptions<T extends ClientContext> {
|
|
9
|
+
/**
|
|
10
|
+
* Base URL for all requests, without origin. Should match the OpenAPI handler mount path.
|
|
11
|
+
*
|
|
12
|
+
* @example '/api'
|
|
13
|
+
* @default '/'
|
|
14
|
+
*/
|
|
15
|
+
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
16
|
+
/**
|
|
17
|
+
* Inject headers into the request.
|
|
18
|
+
*/
|
|
19
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
20
|
+
/**
|
|
21
|
+
* Override the default OpenAPI serializer.
|
|
22
|
+
*/
|
|
23
|
+
serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer>;
|
|
24
|
+
/**
|
|
25
|
+
* Customize how an error response body is converted into an ORPC error.
|
|
26
|
+
* Return `null` or `undefined` to fall back to the default decoding behavior.
|
|
27
|
+
*/
|
|
28
|
+
customErrorResponseBodyDecoder?: (deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined;
|
|
29
|
+
}
|
|
30
|
+
declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
31
|
+
private readonly router;
|
|
32
|
+
private readonly baseUrl;
|
|
33
|
+
private readonly headers;
|
|
34
|
+
private readonly serializer;
|
|
35
|
+
private readonly customErrorResponseBodyDecoder;
|
|
36
|
+
constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
|
|
37
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
38
|
+
private encodePathParam;
|
|
39
|
+
private serializeQueryString;
|
|
40
|
+
decodeResponse(response: StandardLazyResponse, path: string[], _options: ClientOptions<T>): Promise<StandardLinkCodecDecodedResponse>;
|
|
41
|
+
private resolveProcedure;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { OpenAPILinkCodec as a };
|
|
45
|
+
export type { OpenAPILinkCodecOptions as O };
|
|
@@ -2,7 +2,7 @@ import { AnySchema, ErrorMap, MetaPlugin, AnyProcedureContract } from '@orpc/con
|
|
|
2
2
|
import { Lazy } from '@orpc/server';
|
|
3
3
|
import { Value } from '@orpc/shared';
|
|
4
4
|
import { StandardBodyHint } from '@standardserver/core';
|
|
5
|
-
import {
|
|
5
|
+
import { d as OpenAPIOperationObject } from './openapi.DfTTLtn5.js';
|
|
6
6
|
|
|
7
7
|
interface OpenAPIMeta {
|
|
8
8
|
/**
|
|
@@ -10,11 +10,12 @@ interface OpenAPIMeta {
|
|
|
10
10
|
*
|
|
11
11
|
* @default 'POST'
|
|
12
12
|
*/
|
|
13
|
-
method?: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | undefined;
|
|
13
|
+
method?: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'QUERY' | undefined;
|
|
14
14
|
/**
|
|
15
|
-
* URL path for this procedure. Supports dynamic
|
|
15
|
+
* URL path for this procedure. Supports dynamic parameters via `{param}` syntax,
|
|
16
|
+
* and `{+param}` to allow slashes in the matched value.
|
|
16
17
|
*
|
|
17
|
-
* @example `/users`, `/users
|
|
18
|
+
* @example `/users`, `/users/{id}`, `/files/{+path}`
|
|
18
19
|
* @default Router segments joined by `'/`
|
|
19
20
|
*/
|
|
20
21
|
path?: `/${string}` | undefined;
|
|
@@ -39,11 +40,13 @@ interface OpenAPIMeta {
|
|
|
39
40
|
/**
|
|
40
41
|
* Tags associated with this procedure.
|
|
41
42
|
*
|
|
42
|
-
* **
|
|
43
|
+
* **Merging**: When defined multiple times, tags are concatenated in definition order.
|
|
44
|
+
* Explicitly setting `undefined` resets the tags instead of merging.
|
|
43
45
|
*/
|
|
44
46
|
tags?: string[] | undefined;
|
|
45
47
|
/**
|
|
46
|
-
* HTTP status code returned on success.
|
|
48
|
+
* HTTP status code returned on success.
|
|
49
|
+
* Should be in the `2xx` range and must be less than `400`.
|
|
47
50
|
*
|
|
48
51
|
* @default 200
|
|
49
52
|
*/
|
|
@@ -57,7 +60,9 @@ interface OpenAPIMeta {
|
|
|
57
60
|
/**
|
|
58
61
|
* Controls how individual path parameters are decoded.
|
|
59
62
|
*
|
|
60
|
-
* **
|
|
63
|
+
* **Merging**: When defined multiple times, styles are merged per parameter.
|
|
64
|
+
* The most recent style defined for a parameter wins.
|
|
65
|
+
* Explicitly setting `undefined` resets the styles instead of merging.
|
|
61
66
|
*
|
|
62
67
|
* Each key maps a path parameter name to one of the following strategies:
|
|
63
68
|
*
|
|
@@ -102,7 +107,9 @@ interface OpenAPIMeta {
|
|
|
102
107
|
/**
|
|
103
108
|
* Controls how individual query parameters are encoding/decoding.
|
|
104
109
|
*
|
|
105
|
-
* **
|
|
110
|
+
* **Merging**: When defined multiple times, styles are merged per parameter.
|
|
111
|
+
* The most recent style defined for a parameter wins.
|
|
112
|
+
* Explicitly setting `undefined` resets the styles instead of merging.
|
|
106
113
|
*
|
|
107
114
|
* Each key maps a query parameter name to one of the following strategies:
|
|
108
115
|
*
|
|
@@ -260,13 +267,20 @@ interface OpenAPIMeta {
|
|
|
260
267
|
* Pass a plain object to replace entire operation object, or a function that receives the current
|
|
261
268
|
* operation object and returns the modified version.
|
|
262
269
|
*
|
|
263
|
-
* **
|
|
270
|
+
* **Merging**: When defined multiple times:
|
|
271
|
+
*
|
|
272
|
+
* - Two functions are chained: the most recent function receives the result of the previous one.
|
|
273
|
+
* - A function combined with an object: the function is applied to that object.
|
|
274
|
+
* - Two objects: the most recent object wins.
|
|
275
|
+
*
|
|
276
|
+
* Explicitly setting `undefined` resets the spec instead of merging.
|
|
264
277
|
*/
|
|
265
278
|
spec?: Value<OpenAPIOperationObject, [current: OpenAPIOperationObject]>;
|
|
266
279
|
/**
|
|
267
280
|
* Prefix for the path. Useful when you want to apply a common path prefix across multiple procedures.
|
|
268
281
|
*
|
|
269
|
-
* **
|
|
282
|
+
* **Merging**: When defined multiple times, prefixes are concatenated in definition order.
|
|
283
|
+
* Explicitly setting `undefined` resets the prefix instead of merging.
|
|
270
284
|
*/
|
|
271
285
|
prefix?: `/${string}` | undefined;
|
|
272
286
|
}
|
|
@@ -292,7 +306,19 @@ interface OpenAPIFunction {
|
|
|
292
306
|
spec(method: OpenAPIMeta['spec']): OpenAPISpecMetaPlugin<any, any, any>;
|
|
293
307
|
prefix(method: OpenAPIMeta['prefix']): OpenAPIPrefixMetaPlugin<any, any, any>;
|
|
294
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Creates OpenAPI meta plugins that control how a procedure is exposed over HTTP,
|
|
311
|
+
* such as its method, path, prefix, and OpenAPI operation spec.
|
|
312
|
+
*
|
|
313
|
+
* @see {@link https://orpc.dev/docs/openapi/routing | OpenAPI Routing}
|
|
314
|
+
* @see {@link https://orpc.dev/docs/openapi/specification | OpenAPI Specification}
|
|
315
|
+
*/
|
|
295
316
|
declare const openapi: OpenAPIFunction;
|
|
317
|
+
/**
|
|
318
|
+
* Retrieves the OpenAPI metadata attached to a procedure or router, or `undefined` if not set.
|
|
319
|
+
*
|
|
320
|
+
* @see {@link https://orpc.dev/docs/rpc/handler#enabling-the-get-method | RPC Handler - Enabling the GET Method}
|
|
321
|
+
*/
|
|
296
322
|
declare function getOpenAPIMeta(procedureOrLazy: AnyProcedureContract | Lazy<any>): OpenAPIMeta | undefined;
|
|
297
323
|
|
|
298
324
|
export { getOpenAPIMeta as g, openapi as o };
|
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
import { OpenAPIV3_1 } from '@hey-api/spec-types';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyNestedClient, Client, ORPCError } from '@orpc/client';
|
|
3
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
3
4
|
|
|
4
|
-
type OpenAPIDocument = OpenAPIV3_1.Document;
|
|
5
5
|
type OpenAPIOperationObject = OpenAPIV3_1.OperationObject;
|
|
6
|
+
/**
|
|
7
|
+
* An OpenAPI 3.1 document with the OpenAPI 3.2 QUERY additions used by oRPC.
|
|
8
|
+
* This type does not claim support for the complete OpenAPI 3.2 specification.
|
|
9
|
+
*/
|
|
10
|
+
type OpenAPIDocument = Omit<OpenAPIV3_1.Document, 'openapi' | 'paths'> & {
|
|
11
|
+
openapi: OpenAPIV3_1.Document['openapi'] | '3.2.0';
|
|
12
|
+
paths?: undefined | (OpenAPIV3_1.PathsObject & {
|
|
13
|
+
[path: `/${string}`]: OpenAPIV3_1.PathItemObject & {
|
|
14
|
+
query?: OpenAPIOperationObject | undefined;
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
};
|
|
6
18
|
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
7
19
|
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
8
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
20
|
+
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
9
21
|
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
10
22
|
type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : T;
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
24
|
+
* Client type whose outputs and error data replace types JSON cannot represent with their JSON equivalents.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
|
|
13
27
|
*/
|
|
14
28
|
type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : {
|
|
15
29
|
[K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K];
|
|
16
30
|
};
|
|
17
31
|
|
|
18
|
-
export type {
|
|
32
|
+
export type { JsonifiedClient as J, OpenAPIDocument as O, JsonifiedArray as a, JsonifiedClientError as b, JsonifiedValue as c, OpenAPIOperationObject as d };
|
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
import { OpenAPIV3_1 } from '@hey-api/spec-types';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyNestedClient, Client, ORPCError } from '@orpc/client';
|
|
3
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
3
4
|
|
|
4
|
-
type OpenAPIDocument = OpenAPIV3_1.Document;
|
|
5
5
|
type OpenAPIOperationObject = OpenAPIV3_1.OperationObject;
|
|
6
|
+
/**
|
|
7
|
+
* An OpenAPI 3.1 document with the OpenAPI 3.2 QUERY additions used by oRPC.
|
|
8
|
+
* This type does not claim support for the complete OpenAPI 3.2 specification.
|
|
9
|
+
*/
|
|
10
|
+
type OpenAPIDocument = Omit<OpenAPIV3_1.Document, 'openapi' | 'paths'> & {
|
|
11
|
+
openapi: OpenAPIV3_1.Document['openapi'] | '3.2.0';
|
|
12
|
+
paths?: undefined | (OpenAPIV3_1.PathsObject & {
|
|
13
|
+
[path: `/${string}`]: OpenAPIV3_1.PathItemObject & {
|
|
14
|
+
query?: OpenAPIOperationObject | undefined;
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
};
|
|
6
18
|
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
7
19
|
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
8
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
20
|
+
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
9
21
|
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
10
22
|
type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : T;
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
24
|
+
* Client type whose outputs and error data replace types JSON cannot represent with their JSON equivalents.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
|
|
13
27
|
*/
|
|
14
28
|
type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : {
|
|
15
29
|
[K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K];
|
|
16
30
|
};
|
|
17
31
|
|
|
18
|
-
export type {
|
|
32
|
+
export type { JsonifiedClient as J, OpenAPIDocument as O, JsonifiedArray as a, JsonifiedClientError as b, JsonifiedValue as c, OpenAPIOperationObject as d };
|
|
@@ -2,7 +2,7 @@ import { AnySchema, ErrorMap, MetaPlugin, AnyProcedureContract } from '@orpc/con
|
|
|
2
2
|
import { Lazy } from '@orpc/server';
|
|
3
3
|
import { Value } from '@orpc/shared';
|
|
4
4
|
import { StandardBodyHint } from '@standardserver/core';
|
|
5
|
-
import {
|
|
5
|
+
import { d as OpenAPIOperationObject } from './openapi.DfTTLtn5.mjs';
|
|
6
6
|
|
|
7
7
|
interface OpenAPIMeta {
|
|
8
8
|
/**
|
|
@@ -10,11 +10,12 @@ interface OpenAPIMeta {
|
|
|
10
10
|
*
|
|
11
11
|
* @default 'POST'
|
|
12
12
|
*/
|
|
13
|
-
method?: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | undefined;
|
|
13
|
+
method?: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'QUERY' | undefined;
|
|
14
14
|
/**
|
|
15
|
-
* URL path for this procedure. Supports dynamic
|
|
15
|
+
* URL path for this procedure. Supports dynamic parameters via `{param}` syntax,
|
|
16
|
+
* and `{+param}` to allow slashes in the matched value.
|
|
16
17
|
*
|
|
17
|
-
* @example `/users`, `/users
|
|
18
|
+
* @example `/users`, `/users/{id}`, `/files/{+path}`
|
|
18
19
|
* @default Router segments joined by `'/`
|
|
19
20
|
*/
|
|
20
21
|
path?: `/${string}` | undefined;
|
|
@@ -39,11 +40,13 @@ interface OpenAPIMeta {
|
|
|
39
40
|
/**
|
|
40
41
|
* Tags associated with this procedure.
|
|
41
42
|
*
|
|
42
|
-
* **
|
|
43
|
+
* **Merging**: When defined multiple times, tags are concatenated in definition order.
|
|
44
|
+
* Explicitly setting `undefined` resets the tags instead of merging.
|
|
43
45
|
*/
|
|
44
46
|
tags?: string[] | undefined;
|
|
45
47
|
/**
|
|
46
|
-
* HTTP status code returned on success.
|
|
48
|
+
* HTTP status code returned on success.
|
|
49
|
+
* Should be in the `2xx` range and must be less than `400`.
|
|
47
50
|
*
|
|
48
51
|
* @default 200
|
|
49
52
|
*/
|
|
@@ -57,7 +60,9 @@ interface OpenAPIMeta {
|
|
|
57
60
|
/**
|
|
58
61
|
* Controls how individual path parameters are decoded.
|
|
59
62
|
*
|
|
60
|
-
* **
|
|
63
|
+
* **Merging**: When defined multiple times, styles are merged per parameter.
|
|
64
|
+
* The most recent style defined for a parameter wins.
|
|
65
|
+
* Explicitly setting `undefined` resets the styles instead of merging.
|
|
61
66
|
*
|
|
62
67
|
* Each key maps a path parameter name to one of the following strategies:
|
|
63
68
|
*
|
|
@@ -102,7 +107,9 @@ interface OpenAPIMeta {
|
|
|
102
107
|
/**
|
|
103
108
|
* Controls how individual query parameters are encoding/decoding.
|
|
104
109
|
*
|
|
105
|
-
* **
|
|
110
|
+
* **Merging**: When defined multiple times, styles are merged per parameter.
|
|
111
|
+
* The most recent style defined for a parameter wins.
|
|
112
|
+
* Explicitly setting `undefined` resets the styles instead of merging.
|
|
106
113
|
*
|
|
107
114
|
* Each key maps a query parameter name to one of the following strategies:
|
|
108
115
|
*
|
|
@@ -260,13 +267,20 @@ interface OpenAPIMeta {
|
|
|
260
267
|
* Pass a plain object to replace entire operation object, or a function that receives the current
|
|
261
268
|
* operation object and returns the modified version.
|
|
262
269
|
*
|
|
263
|
-
* **
|
|
270
|
+
* **Merging**: When defined multiple times:
|
|
271
|
+
*
|
|
272
|
+
* - Two functions are chained: the most recent function receives the result of the previous one.
|
|
273
|
+
* - A function combined with an object: the function is applied to that object.
|
|
274
|
+
* - Two objects: the most recent object wins.
|
|
275
|
+
*
|
|
276
|
+
* Explicitly setting `undefined` resets the spec instead of merging.
|
|
264
277
|
*/
|
|
265
278
|
spec?: Value<OpenAPIOperationObject, [current: OpenAPIOperationObject]>;
|
|
266
279
|
/**
|
|
267
280
|
* Prefix for the path. Useful when you want to apply a common path prefix across multiple procedures.
|
|
268
281
|
*
|
|
269
|
-
* **
|
|
282
|
+
* **Merging**: When defined multiple times, prefixes are concatenated in definition order.
|
|
283
|
+
* Explicitly setting `undefined` resets the prefix instead of merging.
|
|
270
284
|
*/
|
|
271
285
|
prefix?: `/${string}` | undefined;
|
|
272
286
|
}
|
|
@@ -292,7 +306,19 @@ interface OpenAPIFunction {
|
|
|
292
306
|
spec(method: OpenAPIMeta['spec']): OpenAPISpecMetaPlugin<any, any, any>;
|
|
293
307
|
prefix(method: OpenAPIMeta['prefix']): OpenAPIPrefixMetaPlugin<any, any, any>;
|
|
294
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Creates OpenAPI meta plugins that control how a procedure is exposed over HTTP,
|
|
311
|
+
* such as its method, path, prefix, and OpenAPI operation spec.
|
|
312
|
+
*
|
|
313
|
+
* @see {@link https://orpc.dev/docs/openapi/routing | OpenAPI Routing}
|
|
314
|
+
* @see {@link https://orpc.dev/docs/openapi/specification | OpenAPI Specification}
|
|
315
|
+
*/
|
|
295
316
|
declare const openapi: OpenAPIFunction;
|
|
317
|
+
/**
|
|
318
|
+
* Retrieves the OpenAPI metadata attached to a procedure or router, or `undefined` if not set.
|
|
319
|
+
*
|
|
320
|
+
* @see {@link https://orpc.dev/docs/rpc/handler#enabling-the-get-method | RPC Handler - Enabling the GET Method}
|
|
321
|
+
*/
|
|
296
322
|
declare function getOpenAPIMeta(procedureOrLazy: AnyProcedureContract | Lazy<any>): OpenAPIMeta | undefined;
|
|
297
323
|
|
|
298
324
|
export { getOpenAPIMeta as g, openapi as o };
|
|
@@ -95,10 +95,15 @@ interface OpenAPIJsonSerializerOptions {
|
|
|
95
95
|
omitUndefinedProperties?: boolean | undefined;
|
|
96
96
|
}
|
|
97
97
|
declare class OpenAPIJsonSerializer {
|
|
98
|
-
private readonly
|
|
98
|
+
private readonly inlineBuiltInHandlers;
|
|
99
|
+
private readonly handlerEntries;
|
|
99
100
|
private readonly omitUndefinedProperties;
|
|
100
101
|
constructor(options?: OpenAPIJsonSerializerOptions);
|
|
101
102
|
serialize(data: unknown): OpenAPIJsonSerialization;
|
|
103
|
+
/**
|
|
104
|
+
* `segments` is a shared mutable stack (push/pop while walking),
|
|
105
|
+
* so it must be copied before being stored in `maps`.
|
|
106
|
+
*/
|
|
102
107
|
private serializeValue;
|
|
103
108
|
deserialize(serialized: OpenAPIJsonSerialization): unknown;
|
|
104
109
|
}
|
|
@@ -118,7 +123,7 @@ interface OpenAPISerializerSerializeOptions {
|
|
|
118
123
|
*/
|
|
119
124
|
asFormData?: boolean | undefined;
|
|
120
125
|
}
|
|
121
|
-
interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions
|
|
126
|
+
interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
|
|
122
127
|
/**
|
|
123
128
|
* Options for bracket notation serializer, like maxExplicitDeserializingArrayIndex
|
|
124
129
|
*/
|
|
@@ -128,6 +133,12 @@ interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions, OpenAPI
|
|
|
128
133
|
*/
|
|
129
134
|
serialize?: OpenAPISerializerSerializeOptions | undefined;
|
|
130
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Handles one-way serialization of oRPC payloads into JSON-friendly formats,
|
|
138
|
+
* partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
|
|
141
|
+
*/
|
|
131
142
|
declare class OpenAPISerializer {
|
|
132
143
|
private readonly jsonSerializer;
|
|
133
144
|
private readonly bracketNotation;
|
|
@@ -95,10 +95,15 @@ interface OpenAPIJsonSerializerOptions {
|
|
|
95
95
|
omitUndefinedProperties?: boolean | undefined;
|
|
96
96
|
}
|
|
97
97
|
declare class OpenAPIJsonSerializer {
|
|
98
|
-
private readonly
|
|
98
|
+
private readonly inlineBuiltInHandlers;
|
|
99
|
+
private readonly handlerEntries;
|
|
99
100
|
private readonly omitUndefinedProperties;
|
|
100
101
|
constructor(options?: OpenAPIJsonSerializerOptions);
|
|
101
102
|
serialize(data: unknown): OpenAPIJsonSerialization;
|
|
103
|
+
/**
|
|
104
|
+
* `segments` is a shared mutable stack (push/pop while walking),
|
|
105
|
+
* so it must be copied before being stored in `maps`.
|
|
106
|
+
*/
|
|
102
107
|
private serializeValue;
|
|
103
108
|
deserialize(serialized: OpenAPIJsonSerialization): unknown;
|
|
104
109
|
}
|
|
@@ -118,7 +123,7 @@ interface OpenAPISerializerSerializeOptions {
|
|
|
118
123
|
*/
|
|
119
124
|
asFormData?: boolean | undefined;
|
|
120
125
|
}
|
|
121
|
-
interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions
|
|
126
|
+
interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
|
|
122
127
|
/**
|
|
123
128
|
* Options for bracket notation serializer, like maxExplicitDeserializingArrayIndex
|
|
124
129
|
*/
|
|
@@ -128,6 +133,12 @@ interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions, OpenAPI
|
|
|
128
133
|
*/
|
|
129
134
|
serialize?: OpenAPISerializerSerializeOptions | undefined;
|
|
130
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Handles one-way serialization of oRPC payloads into JSON-friendly formats,
|
|
138
|
+
* partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
|
|
141
|
+
*/
|
|
131
142
|
declare class OpenAPISerializer {
|
|
132
143
|
private readonly jsonSerializer;
|
|
133
144
|
private readonly bracketNotation;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyORPCError } from '@orpc/client';
|
|
2
2
|
import { AnyProcedure, AnyRouter, Context } from '@orpc/server';
|
|
3
|
-
import {
|
|
3
|
+
import { StandardHandlerCodec, StandardHandlerHandleOptions, StandardHandlerCodecResolvedProcedure } from '@orpc/server/standard';
|
|
4
4
|
import { Value, Promisable } from '@orpc/shared';
|
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
6
6
|
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { O as OpenAPISerializer } from './openapi.
|
|
7
|
+
import { O as OpenAPISerializer } from './openapi.Dz-JaXHo.js';
|
|
8
8
|
|
|
9
9
|
interface OpenAPIMatcherOptions {
|
|
10
10
|
/**
|
|
@@ -18,7 +18,7 @@ declare class OpenAPIMatcher {
|
|
|
18
18
|
private readonly filter;
|
|
19
19
|
private readonly rootRouter;
|
|
20
20
|
private readonly tree;
|
|
21
|
-
private pendingLazyRouters;
|
|
21
|
+
private readonly pendingLazyRouters;
|
|
22
22
|
constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
|
|
23
23
|
private index;
|
|
24
24
|
match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
@@ -26,8 +26,10 @@ declare class OpenAPIMatcher {
|
|
|
26
26
|
procedure: AnyProcedure;
|
|
27
27
|
params?: Record<string, string> | undefined;
|
|
28
28
|
} | undefined>;
|
|
29
|
-
private matchPathname;
|
|
30
29
|
private resolvePendingLazyRouters;
|
|
30
|
+
private loadPendingLazyRouters;
|
|
31
|
+
private loadPendingLazyRouter;
|
|
32
|
+
private indexPendingLazyRouter;
|
|
31
33
|
private resolveProcedure;
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -38,8 +40,9 @@ interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
|
38
40
|
serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer>;
|
|
39
41
|
/**
|
|
40
42
|
* Mapping ORPCError Code -> HTTP Status Code
|
|
43
|
+
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
41
44
|
*
|
|
42
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
45
|
+
* @default COMMON_ERROR_STATUS_MAP
|
|
43
46
|
*/
|
|
44
47
|
errorStatusMap?: Record<string, number> | undefined;
|
|
45
48
|
/**
|
|
@@ -65,8 +68,8 @@ declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
|
65
68
|
/**
|
|
66
69
|
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
67
70
|
*/
|
|
68
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]
|
|
69
|
-
encodeError(error: AnyORPCError
|
|
71
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
|
|
72
|
+
encodeError(error: AnyORPCError): Promisable<StandardResponse>;
|
|
70
73
|
private deserializeQuery;
|
|
71
74
|
private deserializeParams;
|
|
72
75
|
}
|