@orpc/openapi 2.0.0-beta.52 → 2.0.0-beta.53
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 +1 -1
- package/dist/adapters/standard/openapi-matcher.d.ts +1 -1
- package/dist/adapters/standard/openapi-matcher.js +5 -10
- package/dist/extensions/route.d.ts +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/meta.d.ts +18 -18
- package/dist/plugins/openapi-reference.d.ts +1 -1
- package/dist/router-utils.d.ts +3 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
63
63
|
|
|
64
64
|
| Package | Purpose | Docs |
|
|
65
65
|
| -------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
66
|
-
| [@orpc/contract](https://www.npmjs.com/package/@orpc/contract) | Define API contract as the single source of truth. | [Procedure Contract](https://orpc.dev/docs/contract/procedure), [Contract
|
|
66
|
+
| [@orpc/contract](https://www.npmjs.com/package/@orpc/contract) | Define API contract as the single source of truth. | [Procedure Contract](https://orpc.dev/docs/contract/procedure), [Router Contract](https://orpc.dev/docs/contract/router), [Implementation](https://orpc.dev/docs/contract/implementation), [Generate from OpenAPI](https://orpc.dev/docs/contract/generate-from-openapi) |
|
|
67
67
|
| [@orpc/server](https://www.npmjs.com/package/@orpc/server) | Build APIs or implement contracts. | [Procedure](https://orpc.dev/docs/procedure), [Router](https://orpc.dev/docs/router), [Middleware](https://orpc.dev/docs/middleware), [Context](https://orpc.dev/docs/context), [RPC Handler](https://orpc.dev/docs/rpc/handler) |
|
|
68
68
|
| [@orpc/client](https://www.npmjs.com/package/@orpc/client) | Consume APIs with end-to-end type safety. | [Client-Side Clients](https://orpc.dev/docs/client/client-side), [Server-Side Clients](https://orpc.dev/docs/client/server-side), [RPC Link](https://orpc.dev/docs/rpc/link), [Error Handling](https://orpc.dev/docs/client/error-handling) |
|
|
69
69
|
| [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi) | Add OpenAPI compatibility to APIs. | [OpenAPI Handler](https://orpc.dev/docs/openapi/handler), [OpenAPI Link](https://orpc.dev/docs/openapi/link), [Specification](https://orpc.dev/docs/openapi/specification), [Scalar](https://orpc.dev/docs/openapi/scalar) |
|
|
@@ -23,7 +23,7 @@ export declare class OpenAPIMatcher {
|
|
|
23
23
|
} | undefined>;
|
|
24
24
|
private resolvePendingLazyRouters;
|
|
25
25
|
private loadPendingLazyRouters;
|
|
26
|
-
|
|
26
|
+
/** Not shared across matches: on Cloudflare Workers, a promise never settles once its request ends. */
|
|
27
27
|
private indexPendingLazyRouter;
|
|
28
28
|
private resolveProcedure;
|
|
29
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../../constants.js";
|
|
2
2
|
import { getOpenAPIMeta } from "../../meta.js";
|
|
3
3
|
import { mergeHttpPath, pathToHttpPath, stripHttpPathPrefix, value } from "@orpc/shared";
|
|
4
|
-
import { Procedure,
|
|
4
|
+
import { Procedure, resolveContractedProcedure, unlazy, walkProcedureContractsSync } from "@orpc/server";
|
|
5
5
|
import { Router as Router$1, createPrefixMatcher } from "@openapi-spec/router";
|
|
6
6
|
// src/adapters/standard/openapi-matcher.ts
|
|
7
7
|
var OpenAPIMatcher = class {
|
|
@@ -56,22 +56,17 @@ var OpenAPIMatcher = class {
|
|
|
56
56
|
for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) return this.loadPendingLazyRouters(pathname);
|
|
57
57
|
}
|
|
58
58
|
async loadPendingLazyRouters(pathname) {
|
|
59
|
-
for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) await this.
|
|
60
|
-
}
|
|
61
|
-
loadPendingLazyRouter(pending) {
|
|
62
|
-
if (pending.loading === void 0) pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
|
|
63
|
-
pending.loading = void 0;
|
|
64
|
-
throw error;
|
|
65
|
-
});
|
|
66
|
-
return pending.loading;
|
|
59
|
+
for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) await this.indexPendingLazyRouter(pending);
|
|
67
60
|
}
|
|
61
|
+
/** Not shared across matches: on Cloudflare Workers, a promise never settles once its request ends. */
|
|
68
62
|
async indexPendingLazyRouter(pending) {
|
|
69
63
|
const { default: router } = await unlazy(pending.router);
|
|
64
|
+
if (!this.pendingLazyRouters.has(pending)) return;
|
|
70
65
|
this.index(router, pending.path);
|
|
71
66
|
this.pendingLazyRouters.delete(pending);
|
|
72
67
|
}
|
|
73
68
|
async resolveProcedure(entry) {
|
|
74
|
-
entry.procedure = await
|
|
69
|
+
entry.procedure = await resolveContractedProcedure(this.rootRouter, entry.contract, entry.path);
|
|
75
70
|
return entry.procedure;
|
|
76
71
|
}
|
|
77
72
|
};
|
|
@@ -5,14 +5,14 @@ declare module "@orpc/contract" {
|
|
|
5
5
|
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
6
6
|
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
7
7
|
}
|
|
8
|
-
interface
|
|
9
|
-
route(meta: OpenAPIMeta):
|
|
8
|
+
interface ContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
9
|
+
route(meta: OpenAPIMeta): ContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
10
10
|
}
|
|
11
|
-
interface
|
|
12
|
-
route(meta: OpenAPIMeta):
|
|
11
|
+
interface ContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
12
|
+
route(meta: OpenAPIMeta): ContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
13
13
|
}
|
|
14
|
-
interface
|
|
15
|
-
route(meta: OpenAPIMeta):
|
|
14
|
+
interface ContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
+
route(meta: OpenAPIMeta): ContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
declare module "@orpc/server" {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { OpenAPIFunction, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugi
|
|
|
5
5
|
import { OpenAPIGenerator, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions } from "./openapi-generator.js";
|
|
6
6
|
import { OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.js";
|
|
7
7
|
import { OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions } from "./openapi-serializer.js";
|
|
8
|
-
import { PopulateRouterContractOpenAPIPathsOptions,
|
|
8
|
+
import { PopulateRouterContractOpenAPIPathsOptions, PopulatedRouterContractOpenAPIPaths, PopulatedRouterContractOpenAPIPathsInternal, populateRouterContractOpenAPIPaths } from "./router-utils.js";
|
|
9
9
|
import { OpenAPIErrorBodyDefinition, OpenAPIGeneratorError } from "./openapi-generator-operation.js";
|
|
10
10
|
import { JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedClientInternal, JsonifiedValue, OpenAPIDocument, OpenAPIV3_0, OpenAPIV3_1, OpenAPIV3_2, OpenAPIVersion } from "./types.js";
|
|
11
11
|
import { getDynamicPathParams } from "./utils.js";
|
|
12
12
|
import { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|
|
13
13
|
import { JsonSchema } from "@orpc/json-schema";
|
|
14
14
|
import { StandardBodyHint } from "@standard-server/core";
|
|
15
|
-
export { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions, COMMON_ERROR_STATUS_MAP, ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, DEFAULT_OPENAPI_METHOD, type JsonSchema, JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedClientInternal, JsonifiedValue, OpenAPIDocument, type OpenAPIErrorBodyDefinition, OpenAPIFunction, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions, OpenAPISpecMetaPlugin, type OpenAPIV3_0, type OpenAPIV3_1, type OpenAPIV3_2, OpenAPIVersion, PopulateRouterContractOpenAPIPathsOptions,
|
|
15
|
+
export { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions, COMMON_ERROR_STATUS_MAP, ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, DEFAULT_OPENAPI_METHOD, type JsonSchema, JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedClientInternal, JsonifiedValue, OpenAPIDocument, type OpenAPIErrorBodyDefinition, OpenAPIFunction, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions, OpenAPISpecMetaPlugin, type OpenAPIV3_0, type OpenAPIV3_1, type OpenAPIV3_2, OpenAPIVersion, PopulateRouterContractOpenAPIPathsOptions, PopulatedRouterContractOpenAPIPaths, PopulatedRouterContractOpenAPIPathsInternal, type StandardBodyHint, createContractJsonifiedClientFactory, getDynamicPathParams, getOpenAPIMeta, openapi, populateRouterContractOpenAPIPaths };
|
package/dist/meta.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface OpenAPIMeta {
|
|
|
15
15
|
* and `{+param}` to allow slashes in the matched value.
|
|
16
16
|
*
|
|
17
17
|
* @example `/users`, `/users/{id}`, `/files/{+path}`
|
|
18
|
-
* @default Router segments joined by
|
|
18
|
+
* @default Router segments joined by `/`
|
|
19
19
|
*/
|
|
20
20
|
path?: `/${string}` | undefined;
|
|
21
21
|
/**
|
|
@@ -112,18 +112,18 @@ export interface OpenAPIMeta {
|
|
|
112
112
|
*
|
|
113
113
|
* Each key maps a query parameter name to one of the following strategies:
|
|
114
114
|
*
|
|
115
|
-
* | Strategy | Encoded | Decoded
|
|
116
|
-
*
|
|
117
|
-
* | `primitive` | `?a=1&a=2` | `{ a: '2' }`
|
|
118
|
-
* | `array` | `?a=1&a=2` | `{ a: ['1', '2'] }`
|
|
119
|
-
* | `comma-delimited-array` | `?a=1,2,3` | `{ a: ['1', '2', '3'] }`
|
|
120
|
-
* | `comma-delimited-object` | `?a=A,1,B,2` | `{ a: { A: '1', B: '2' } }`
|
|
121
|
-
* | `space-delimited-array` | `?a=1 2 3` | `{ a: ['1', '2', '3'] }`
|
|
122
|
-
* | `space-delimited-object` | `?a=A 1 B 2` | `{ a: { A: '1', B: '2' } }`
|
|
123
|
-
* | `pipe-delimited-array` | `?a=1\|2\|3` | `{ a: ['1', '2', '3'] }`
|
|
124
|
-
* | `pipe-delimited-object` | `?a=A\|1\|B\|2` | `{ a: { A: '1', B: '2' } }`
|
|
125
|
-
* | `json` | `?meta={"key":"value"}` | `{ meta: { key: 'value' } }`
|
|
126
|
-
* | _default_
|
|
115
|
+
* | Strategy | Encoded | Decoded | OpenAPI Parameter Style |
|
|
116
|
+
* |--------------------------|---------------------------|--------------------------------------------|------------------------------------------|
|
|
117
|
+
* | `primitive` | `?a=1&a=2` | `{ a: '2' }` | `form` / `explode: true` |
|
|
118
|
+
* | `array` | `?a=1&a=2` | `{ a: ['1', '2'] }` | `form` / `explode: true` |
|
|
119
|
+
* | `comma-delimited-array` | `?a=1,2,3` | `{ a: ['1', '2', '3'] }` | `form` / `explode: false` |
|
|
120
|
+
* | `comma-delimited-object` | `?a=A,1,B,2` | `{ a: { A: '1', B: '2' } }` | `form` / `explode: false` |
|
|
121
|
+
* | `space-delimited-array` | `?a=1 2 3` | `{ a: ['1', '2', '3'] }` | `spaceDelimited` / `explode: false` |
|
|
122
|
+
* | `space-delimited-object` | `?a=A 1 B 2` | `{ a: { A: '1', B: '2' } }` | `spaceDelimited` / `explode: false` |
|
|
123
|
+
* | `pipe-delimited-array` | `?a=1\|2\|3` | `{ a: ['1', '2', '3'] }` | `pipeDelimited` / `explode: false` |
|
|
124
|
+
* | `pipe-delimited-object` | `?a=A\|1\|B\|2` | `{ a: { A: '1', B: '2' } }` | `pipeDelimited` / `explode: false` |
|
|
125
|
+
* | `json` | `?meta={"key":"value"}` | `{ meta: { key: 'value' } }` | `content: application/json` |
|
|
126
|
+
* | _default_ | `?a[]=1&a[]=2&b=3&c[d]=4` | `{ a: ['1', '2'], b: '3', c: { d: '4' } }` | `form` or `deepObject` / `explode: true` |
|
|
127
127
|
*
|
|
128
128
|
* **Strategy details:**
|
|
129
129
|
*
|
|
@@ -132,7 +132,7 @@ export interface OpenAPIMeta {
|
|
|
132
132
|
* - **`*-delimited-array`**: Splits the last value on the delimiter (`,`, space, or `|`) into an array.
|
|
133
133
|
* - **`*-delimited-object`**: Splits the last value on the delimiter into alternating key–value pairs.
|
|
134
134
|
* - **`json`**: Parses the last value as JSON; falls back to the raw string if parsing fails.
|
|
135
|
-
* - **`undefined`**: Standard bracket-notation decoding This is the default.
|
|
135
|
+
* - **`undefined`**: Standard bracket-notation decoding. This is the default.
|
|
136
136
|
*
|
|
137
137
|
* **Note**: With `array` and `*-delimited-*`, a missing parameter is decoded as `[]` or `{}`. With the others, it is decoded as `undefined`.
|
|
138
138
|
*
|
|
@@ -141,7 +141,7 @@ export interface OpenAPIMeta {
|
|
|
141
141
|
* @example
|
|
142
142
|
* ```ts
|
|
143
143
|
* // GET /search?keyword=abc&tags=a,b,c&meta={"key":"value"}
|
|
144
|
-
* const
|
|
144
|
+
* const queryStyles = {
|
|
145
145
|
* keyword: 'primitive',
|
|
146
146
|
* tags: 'comma-delimited-array',
|
|
147
147
|
* meta: 'json',
|
|
@@ -307,9 +307,9 @@ export interface OpenAPIPrefixMetaPlugin<TInputSchema extends AnySchema, TOutput
|
|
|
307
307
|
export interface OpenAPIFunction {
|
|
308
308
|
(meta: OpenAPIMeta): OpenAPIMetaPlugin<any, any, any>;
|
|
309
309
|
method(method: OpenAPIMeta["method"]): OpenAPIMethodMetaPlugin<any, any, any>;
|
|
310
|
-
path(
|
|
311
|
-
spec(
|
|
312
|
-
prefix(
|
|
310
|
+
path(path: OpenAPIMeta["path"]): OpenAPIPathMetaPlugin<any, any, any>;
|
|
311
|
+
spec(spec: OpenAPIMeta["spec"]): OpenAPISpecMetaPlugin<any, any, any>;
|
|
312
|
+
prefix(prefix: OpenAPIMeta["prefix"]): OpenAPIPrefixMetaPlugin<any, any, any>;
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
315
|
* Creates OpenAPI meta plugins that control how a procedure is exposed over HTTP,
|
|
@@ -96,7 +96,7 @@ export interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvid
|
|
|
96
96
|
* @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
|
|
97
97
|
*/
|
|
98
98
|
export declare class OpenAPIReferenceHandlerPlugin<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> implements StandardHandlerPlugin<T> {
|
|
99
|
-
name
|
|
99
|
+
readonly name = "~openapi-reference";
|
|
100
100
|
private readonly spec;
|
|
101
101
|
private readonly allow;
|
|
102
102
|
private readonly specPath;
|
package/dist/router-utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProcedureContract, RouterContract } from "@orpc/contract";
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
2
|
+
export type PopulatedRouterContractOpenAPIPaths<T extends RouterContract> = PopulatedRouterContractOpenAPIPathsInternal<T>;
|
|
3
|
+
export type PopulatedRouterContractOpenAPIPathsInternal<T> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : { [K in keyof T]: PopulatedRouterContractOpenAPIPathsInternal<T[K] & {}>; };
|
|
4
4
|
export interface PopulateRouterContractOpenAPIPathsOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Base path segments.
|
|
@@ -15,4 +15,4 @@ export interface PopulateRouterContractOpenAPIPathsOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
|
|
17
17
|
*/
|
|
18
|
-
export declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions):
|
|
18
|
+
export declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedRouterContractOpenAPIPaths<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.53",
|
|
4
4
|
"description": "Generate OpenAPI specs from oRPC routers and serve OpenAPI-compliant APIs with end-to-end type safety",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"@openapi-spec/downgrader": "~0.8.0",
|
|
85
85
|
"@openapi-spec/router": "~0.8.0",
|
|
86
86
|
"@openapi-spec/types": "~0.8.0",
|
|
87
|
-
"@orpc/client": "2.0.0-beta.
|
|
88
|
-
"@orpc/contract": "2.0.0-beta.
|
|
89
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
90
|
-
"@orpc/server": "2.0.0-beta.
|
|
91
|
-
"@orpc/shared": "2.0.0-beta.
|
|
87
|
+
"@orpc/client": "2.0.0-beta.53",
|
|
88
|
+
"@orpc/contract": "2.0.0-beta.53",
|
|
89
|
+
"@orpc/json-schema": "2.0.0-beta.53",
|
|
90
|
+
"@orpc/server": "2.0.0-beta.53",
|
|
91
|
+
"@orpc/shared": "2.0.0-beta.53",
|
|
92
92
|
"@standard-server/core": "~0.16.0",
|
|
93
93
|
"@standard-server/fetch": "~0.16.0"
|
|
94
94
|
},
|