@orpc/openapi 2.0.0-beta.2 → 2.0.0-beta.4
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 +8 -7
- package/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.d.ts +1 -1
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/node/index.d.mts +1 -1
- package/dist/adapters/node/index.d.ts +1 -1
- package/dist/adapters/node/index.mjs +1 -1
- package/dist/adapters/standard/index.d.mts +1 -1
- package/dist/adapters/standard/index.d.ts +1 -1
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.mjs +37 -8
- package/dist/shared/{openapi.BYcWgK1j.d.ts → openapi.7vgmPxca.d.ts} +15 -12
- package/dist/shared/{openapi.DR-y5p-D.mjs → openapi.CTlpLuKN.mjs} +26 -23
- package/dist/shared/{openapi.XeW6_5tm.d.mts → openapi.CX6Ri5dP.d.mts} +15 -12
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -37,18 +37,19 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
37
37
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
|
|
38
38
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
|
|
39
39
|
|
|
40
|
-
**Framework & ecosystem integrations**
|
|
41
|
-
|
|
42
|
-
- [@orpc/next](https://www.npmjs.com/package/@orpc/react): Use oRPC with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
43
|
-
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
44
|
-
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
45
|
-
|
|
46
40
|
**Built-in features**
|
|
47
41
|
|
|
48
42
|
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub.
|
|
49
43
|
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting.
|
|
50
44
|
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
51
45
|
|
|
46
|
+
**Framework & ecosystem integrations**
|
|
47
|
+
|
|
48
|
+
- [@orpc/next](https://www.npmjs.com/package/@orpc/react): Use oRPC with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
49
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
50
|
+
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
51
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
52
|
+
|
|
52
53
|
**Observability**
|
|
53
54
|
|
|
54
55
|
- [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry): Instrument your API with [OpenTelemetry](https://opentelemetry.io/).
|
|
@@ -150,7 +151,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
150
151
|
<a href="https://github.com/theoludwig?ref=orpc" target="_blank" rel="noopener" title="Théo LUDWIG"><img src="https://avatars.githubusercontent.com/u/25207499?u=a6a9653725a2f574c07893748806668e0598cdbe&v=4" width="32" height="32" alt="Théo LUDWIG" /></a>
|
|
151
152
|
<a href="https://github.com/abhay-ramesh?ref=orpc" target="_blank" rel="noopener" title="Abhay Ramesh"><img src="https://avatars.githubusercontent.com/u/66196314?u=c5c2b0327b26606c2efcfaf17046ab18c3d25c57&v=4" width="32" height="32" alt="Abhay Ramesh" /></a>
|
|
152
153
|
<a href="https://github.com/shr-ink?ref=orpc" target="_blank" rel="noopener" title="shr.ink oü"><img src="https://avatars.githubusercontent.com/u/139700438?v=4" width="32" height="32" alt="shr.ink oü" /></a>
|
|
153
|
-
<a href="https://github.com/johngerome?ref=orpc" target="_blank" rel="noopener" title="0x4e32"><img src="https://avatars.githubusercontent.com/u/2002000?u=
|
|
154
|
+
<a href="https://github.com/johngerome?ref=orpc" target="_blank" rel="noopener" title="0x4e32"><img src="https://avatars.githubusercontent.com/u/2002000?u=505e54608466ab53754f702973687b04c6424c1f&v=4" width="32" height="32" alt="0x4e32" /></a>
|
|
154
155
|
<a href="https://github.com/yzuyr?ref=orpc" target="_blank" rel="noopener" title="Ryuz"><img src="https://avatars.githubusercontent.com/u/196539378?u=d38374588d219b6748b16406982f6559411466d4&v=4" width="32" height="32" alt="Ryuz" /></a>
|
|
155
156
|
<a href="https://github.com/happyboy2022?ref=orpc" target="_blank" rel="noopener" title="happyboy"><img src="https://avatars.githubusercontent.com/u/103669586?u=65b49c4b893ed3703909fbb3a7a22313f3f9c121&v=4" width="32" height="32" alt="happyboy" /></a>
|
|
156
157
|
<a href="https://github.com/YiCChi?ref=orpc" target="_blank" rel="noopener" title="yicchi"><img src="https://avatars.githubusercontent.com/u/86967274?u=6c2756f09fe15dd94d572f560e979cd157982852&v=4" width="32" height="32" alt="yicchi" /></a>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
2
|
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
3
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
-
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.
|
|
4
|
+
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.CX6Ri5dP.mjs';
|
|
5
5
|
import { ClientContext } from '@orpc/client';
|
|
6
6
|
import { FetchLinkTransportOptions } from '@orpc/client/fetch';
|
|
7
7
|
import { StandardLink, StandardLinkOptions } from '@orpc/client/standard';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
2
|
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
3
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
-
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.
|
|
4
|
+
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.7vgmPxca.js';
|
|
5
5
|
import { ClientContext } from '@orpc/client';
|
|
6
6
|
import { FetchLinkTransportOptions } from '@orpc/client/fetch';
|
|
7
7
|
import { StandardLink, StandardLinkOptions } from '@orpc/client/standard';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FetchHandler } from '@orpc/server/fetch';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.CTlpLuKN.mjs';
|
|
4
4
|
import { FetchLinkTransport } from '@orpc/client/fetch';
|
|
5
5
|
import { StandardLink } from '@orpc/client/standard';
|
|
6
6
|
import { O as OpenAPILinkCodec } from '../../shared/openapi.B2SK0ZAr.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
2
|
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
3
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
-
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.
|
|
4
|
+
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.CX6Ri5dP.mjs';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@standardserver/core';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
2
|
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
3
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
-
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.
|
|
4
|
+
import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.7vgmPxca.js';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@standardserver/core';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeHttpHandler } from '@orpc/server/node';
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.
|
|
3
|
+
import { O as OpenAPIHandlerCodec } from '../../shared/openapi.CTlpLuKN.mjs';
|
|
4
4
|
import '@orpc/client';
|
|
5
5
|
import '@orpc/server';
|
|
6
6
|
import '@orpc/shared';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as OpenAPIHandlerCodec, b as
|
|
1
|
+
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.CX6Ri5dP.mjs';
|
|
2
2
|
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
3
3
|
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
4
4
|
import { RouterContract } from '@orpc/contract';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as OpenAPIHandlerCodec, b as
|
|
1
|
+
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.7vgmPxca.js';
|
|
2
2
|
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
3
3
|
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
4
4
|
import { RouterContract } from '@orpc/contract';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { O as OpenAPIHandlerCodec, a as
|
|
1
|
+
export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecCore, b as OpenAPIMatcher } from '../../shared/openapi.CTlpLuKN.mjs';
|
|
2
2
|
export { O as OpenAPILinkCodec, a as OpenAPILinkCodecError } from '../../shared/openapi.B2SK0ZAr.mjs';
|
|
3
3
|
import '@orpc/client';
|
|
4
4
|
import '@orpc/server';
|
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/opena
|
|
|
9
9
|
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.BcEtAxQj.mjs';
|
|
10
10
|
import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
|
|
11
11
|
import { AnyRouter, AnyProcedure } from '@orpc/server';
|
|
12
|
-
|
|
12
|
+
export { StandardBodyHint } from '@standardserver/core';
|
|
13
13
|
import '@hey-api/spec-types';
|
|
14
14
|
|
|
15
15
|
interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
|
|
@@ -89,6 +89,23 @@ declare class OpenAPIGenerator {
|
|
|
89
89
|
private errorResponse;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
|
|
93
|
+
[K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
|
|
94
|
+
};
|
|
95
|
+
interface PopulateRouterContractOpenAPIPathsOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Base path segments.
|
|
98
|
+
*/
|
|
99
|
+
path?: undefined | string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Automatically populates missing openapi.path using router structure.
|
|
103
|
+
*
|
|
104
|
+
* Builds paths by joining router keys with `/`.
|
|
105
|
+
* Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
|
|
106
|
+
*/
|
|
107
|
+
declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
|
|
108
|
+
|
|
92
109
|
/**
|
|
93
110
|
* Dynamic parameters are always returned in path order.
|
|
94
111
|
*/
|
|
@@ -99,5 +116,5 @@ declare function getDynamicPathParams(path: `/${string}`): {
|
|
|
99
116
|
allowsSlash: boolean;
|
|
100
117
|
}[] | undefined;
|
|
101
118
|
|
|
102
|
-
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
|
|
103
|
-
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };
|
|
119
|
+
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams, populateRouterContractOpenAPIPaths };
|
|
120
|
+
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/opena
|
|
|
9
9
|
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.BQzzr4-4.js';
|
|
10
10
|
import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
|
|
11
11
|
import { AnyRouter, AnyProcedure } from '@orpc/server';
|
|
12
|
-
|
|
12
|
+
export { StandardBodyHint } from '@standardserver/core';
|
|
13
13
|
import '@hey-api/spec-types';
|
|
14
14
|
|
|
15
15
|
interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
|
|
@@ -89,6 +89,23 @@ declare class OpenAPIGenerator {
|
|
|
89
89
|
private errorResponse;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
|
|
93
|
+
[K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
|
|
94
|
+
};
|
|
95
|
+
interface PopulateRouterContractOpenAPIPathsOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Base path segments.
|
|
98
|
+
*/
|
|
99
|
+
path?: undefined | string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Automatically populates missing openapi.path using router structure.
|
|
103
|
+
*
|
|
104
|
+
* Builds paths by joining router keys with `/`.
|
|
105
|
+
* Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
|
|
106
|
+
*/
|
|
107
|
+
declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
|
|
108
|
+
|
|
92
109
|
/**
|
|
93
110
|
* Dynamic parameters are always returned in path order.
|
|
94
111
|
*/
|
|
@@ -99,5 +116,5 @@ declare function getDynamicPathParams(path: `/${string}`): {
|
|
|
99
116
|
allowsSlash: boolean;
|
|
100
117
|
}[] | undefined;
|
|
101
118
|
|
|
102
|
-
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
|
|
103
|
-
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };
|
|
119
|
+
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams, populateRouterContractOpenAPIPaths };
|
|
120
|
+
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export { B as BracketNotationSerializer } from './shared/openapi.Bt87OzTt.mjs';
|
|
2
|
-
import { createContractCaller, getEventIteratorSchemaDetails } from '@orpc/contract';
|
|
2
|
+
import { createContractCaller, getEventIteratorSchemaDetails, ProcedureContract, resolveMetaPlugins } from '@orpc/contract';
|
|
3
3
|
import { O as OpenAPISerializer, D as DEFAULT_OPENAPI_METHOD, g as getDynamicPathParams, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, c as DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './shared/openapi.DmAa7YPO.mjs';
|
|
4
4
|
export { d as OpenAPIJsonSerializer } from './shared/openapi.DmAa7YPO.mjs';
|
|
5
|
-
import { g as getOpenAPIMeta } from './shared/openapi.B9PQzqBn.mjs';
|
|
6
|
-
export { o as openapi } from './shared/openapi.B9PQzqBn.mjs';
|
|
5
|
+
import { g as getOpenAPIMeta, o as openapi } from './shared/openapi.B9PQzqBn.mjs';
|
|
7
6
|
import { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
8
7
|
export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
9
|
-
import { DelegatingJsonSchemaConverter, StandardJsonSchemaConverter, combineJsonSchemasWithComposition, isUnconstrainedSchema, extractJsonObjectSchemaEntries, combineJsonObjectSchemaEntries, isJsonPrimitiveSchema, matchArrayableJsonSchema,
|
|
8
|
+
import { DelegatingJsonSchemaConverter, StandardJsonSchemaConverter, combineJsonSchemasWithComposition, isUnconstrainedSchema, extractJsonObjectSchemaEntries, combineJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonPrimitiveSchema, matchArrayableJsonSchema, ensureJsonSchemaObject, isJsonFileSchema, mapJsonSchemaRefs, encodeJsonPointerSegment, decodeJsonPointerSegment } from '@orpc/json-schema';
|
|
10
9
|
import { walkProcedureContractsAsync, DEFAULT_SUCCESS_STATUS, DEFAULT_ERROR_STATUS } from '@orpc/server';
|
|
11
|
-
import { toArray, clone, value, pathToHttpPath, mergeHttpPath, stringifyJSON, findDeepMatches, isPlainObject, isDeepEqual } from '@orpc/shared';
|
|
10
|
+
import { toArray, clone, value, pathToHttpPath, mergeHttpPath, stringifyJSON, findDeepMatches, isPlainObject, isDeepEqual, isTypescriptObject } from '@orpc/shared';
|
|
12
11
|
import '@standardserver/core';
|
|
13
12
|
|
|
14
13
|
function createContractJsonifiedCaller(link, options = {}) {
|
|
@@ -202,9 +201,9 @@ ${errors.join("\n\n")}`
|
|
|
202
201
|
};
|
|
203
202
|
delete parameter.schema;
|
|
204
203
|
} else if (style === void 0) {
|
|
205
|
-
if (!isJsonPrimitiveSchema(
|
|
204
|
+
if (flattenJsonUnionSchema(schema2).some((s) => !isJsonPrimitiveSchema(s))) {
|
|
206
205
|
const arrayable = matchArrayableJsonSchema(schema2);
|
|
207
|
-
if (!arrayable ||
|
|
206
|
+
if (!arrayable || flattenJsonUnionSchema(arrayable[0]).some((s) => !isJsonPrimitiveSchema(s))) {
|
|
208
207
|
parameter.style = "deepObject";
|
|
209
208
|
parameter.explode = true;
|
|
210
209
|
}
|
|
@@ -898,4 +897,34 @@ function rewriteComponentSchemaRefs(schema, renameMap) {
|
|
|
898
897
|
});
|
|
899
898
|
}
|
|
900
899
|
|
|
901
|
-
|
|
900
|
+
function populateRouterContractOpenAPIPaths(router, options = {}) {
|
|
901
|
+
const path = toArray(options.path);
|
|
902
|
+
if (router instanceof ProcedureContract) {
|
|
903
|
+
if (getOpenAPIMeta(router)?.path !== void 0) {
|
|
904
|
+
return router;
|
|
905
|
+
}
|
|
906
|
+
const [meta, metaPlugins] = resolveMetaPlugins(
|
|
907
|
+
router["~orpc"].meta,
|
|
908
|
+
router["~orpc"].metaPlugins,
|
|
909
|
+
[openapi({ path: pathToHttpPath(path) })]
|
|
910
|
+
);
|
|
911
|
+
return new ProcedureContract({
|
|
912
|
+
...router["~orpc"],
|
|
913
|
+
meta,
|
|
914
|
+
metaPlugins
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
if (!isTypescriptObject(router)) {
|
|
918
|
+
return router;
|
|
919
|
+
}
|
|
920
|
+
const populated = {};
|
|
921
|
+
for (const key in router) {
|
|
922
|
+
populated[key] = populateRouterContractOpenAPIPaths(
|
|
923
|
+
router[key],
|
|
924
|
+
{ ...options, path: [...path, key] }
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
return populated;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams, getOpenAPIMeta, openapi, populateRouterContractOpenAPIPaths };
|
|
@@ -31,9 +31,7 @@ declare class OpenAPIMatcher {
|
|
|
31
31
|
private resolveProcedure;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
interface OpenAPIHandlerCodecOptions<_T extends Context> extends OpenAPIMatcherOptions {
|
|
34
|
+
interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
37
35
|
/**
|
|
38
36
|
* Override the default OpenAPI serializer.
|
|
39
37
|
*/
|
|
@@ -55,25 +53,30 @@ interface OpenAPIHandlerCodecOptions<_T extends Context> extends OpenAPIMatcherO
|
|
|
55
53
|
*/
|
|
56
54
|
customErrorResponseBodyEncoder?: (error: AnyORPCError) => unknown;
|
|
57
55
|
}
|
|
58
|
-
declare class
|
|
59
|
-
private readonly matcher;
|
|
56
|
+
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
60
57
|
private readonly serializer;
|
|
61
58
|
private readonly errorStatusMap;
|
|
62
59
|
private readonly customErrorResponseBodySerializer;
|
|
63
|
-
constructor(
|
|
60
|
+
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
64
61
|
decodeInput(matched: {
|
|
65
62
|
procedure: AnyProcedure;
|
|
66
63
|
params?: undefined | Record<string, string>;
|
|
67
64
|
}, request: StandardLazyRequest): Promise<unknown>;
|
|
68
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
69
65
|
/**
|
|
70
|
-
* @throws {
|
|
66
|
+
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
71
67
|
*/
|
|
72
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]
|
|
73
|
-
encodeError(error: AnyORPCError
|
|
68
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
|
|
69
|
+
encodeError(error: AnyORPCError): Promisable<StandardResponse>;
|
|
74
70
|
private deserializeQuery;
|
|
75
71
|
private deserializeParams;
|
|
76
72
|
}
|
|
73
|
+
interface OpenAPIHandlerCodecOptions<T extends Context> extends OpenAPIHandlerCodecCoreOptions<T>, OpenAPIMatcherOptions {
|
|
74
|
+
}
|
|
75
|
+
declare class OpenAPIHandlerCodec<T extends Context> extends OpenAPIHandlerCodecCore<T> implements StandardHandlerCodec<T> {
|
|
76
|
+
private readonly matcher;
|
|
77
|
+
constructor(router: AnyRouter, options?: OpenAPIHandlerCodecOptions<T>);
|
|
78
|
+
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
79
|
+
}
|
|
77
80
|
|
|
78
|
-
export { OpenAPIHandlerCodec as a,
|
|
79
|
-
export type { OpenAPIHandlerCodecOptions as O, OpenAPIMatcherOptions as
|
|
81
|
+
export { OpenAPIHandlerCodec as a, OpenAPIHandlerCodecCore as b, OpenAPIMatcher as d };
|
|
82
|
+
export type { OpenAPIHandlerCodecOptions as O, OpenAPIHandlerCodecCoreOptions as c, OpenAPIMatcherOptions as e };
|
|
@@ -124,15 +124,11 @@ function decodeParams(params) {
|
|
|
124
124
|
return Object.fromEntries(Object.entries(params).map(([key, val]) => [key, tryDecodeURIComponent(val)]));
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
class
|
|
128
|
-
}
|
|
129
|
-
class OpenAPIHandlerCodec {
|
|
130
|
-
matcher;
|
|
127
|
+
class OpenAPIHandlerCodecCore {
|
|
131
128
|
serializer;
|
|
132
129
|
errorStatusMap;
|
|
133
130
|
customErrorResponseBodySerializer;
|
|
134
|
-
constructor(
|
|
135
|
-
this.matcher = new OpenAPIMatcher(router, options);
|
|
131
|
+
constructor(options = {}) {
|
|
136
132
|
this.serializer = options.serializer ?? new OpenAPISerializer();
|
|
137
133
|
this.errorStatusMap = options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP;
|
|
138
134
|
this.customErrorResponseBodySerializer = options.customErrorResponseBodyEncoder;
|
|
@@ -166,22 +162,10 @@ class OpenAPIHandlerCodec {
|
|
|
166
162
|
body: this.serializer.deserialize(await request.resolveBody(meta?.requestBodyHint))
|
|
167
163
|
};
|
|
168
164
|
}
|
|
169
|
-
async resolveProcedure(request, options) {
|
|
170
|
-
const [pathname] = parseStandardUrl(request.url);
|
|
171
|
-
const matched = await this.matcher.match(request.method, pathname, options.prefix);
|
|
172
|
-
if (!matched) {
|
|
173
|
-
return void 0;
|
|
174
|
-
}
|
|
175
|
-
return {
|
|
176
|
-
procedure: matched.procedure,
|
|
177
|
-
path: matched.path,
|
|
178
|
-
decodeInput: () => this.decodeInput(matched, request)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
165
|
/**
|
|
182
|
-
* @throws {
|
|
166
|
+
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
183
167
|
*/
|
|
184
|
-
encodeOutput(output, procedure, path
|
|
168
|
+
encodeOutput(output, procedure, path) {
|
|
185
169
|
const meta = getOpenAPIMeta(procedure);
|
|
186
170
|
const successStatus = meta?.successStatus ?? DEFAULT_SUCCESS_STATUS;
|
|
187
171
|
const outputStructure = meta?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
@@ -193,7 +177,7 @@ class OpenAPIHandlerCodec {
|
|
|
193
177
|
};
|
|
194
178
|
}
|
|
195
179
|
if (!isValidDetailedOutput(output)) {
|
|
196
|
-
throw new
|
|
180
|
+
throw new TypeError(`
|
|
197
181
|
Invalid "detailed" output structure returned by procedure (${path.join(".")}):
|
|
198
182
|
\u2022 Expected an object with optional properties:
|
|
199
183
|
- status (number 200-399)
|
|
@@ -211,7 +195,7 @@ class OpenAPIHandlerCodec {
|
|
|
211
195
|
body: this.serializer.serialize(output.body)
|
|
212
196
|
};
|
|
213
197
|
}
|
|
214
|
-
encodeError(error
|
|
198
|
+
encodeError(error) {
|
|
215
199
|
const status = this.errorStatusMap[error.code] ?? DEFAULT_ERROR_STATUS;
|
|
216
200
|
return {
|
|
217
201
|
status,
|
|
@@ -278,6 +262,25 @@ class OpenAPIHandlerCodec {
|
|
|
278
262
|
return parsed;
|
|
279
263
|
}
|
|
280
264
|
}
|
|
265
|
+
class OpenAPIHandlerCodec extends OpenAPIHandlerCodecCore {
|
|
266
|
+
matcher;
|
|
267
|
+
constructor(router, options = {}) {
|
|
268
|
+
super(options);
|
|
269
|
+
this.matcher = new OpenAPIMatcher(router, options);
|
|
270
|
+
}
|
|
271
|
+
async resolveProcedure(request, options) {
|
|
272
|
+
const [pathname] = parseStandardUrl(request.url);
|
|
273
|
+
const matched = await this.matcher.match(request.method, pathname, options.prefix);
|
|
274
|
+
if (!matched) {
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
procedure: matched.procedure,
|
|
279
|
+
path: matched.path,
|
|
280
|
+
decodeInput: () => this.decodeInput(matched, request)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
281
284
|
function isValidDetailedOutput(output) {
|
|
282
285
|
if (!isTypescriptObject(output)) {
|
|
283
286
|
return false;
|
|
@@ -312,4 +315,4 @@ function decodeDelimitedObject(value, delimiter) {
|
|
|
312
315
|
return obj;
|
|
313
316
|
}
|
|
314
317
|
|
|
315
|
-
export { OpenAPIHandlerCodec as O,
|
|
318
|
+
export { OpenAPIHandlerCodec as O, OpenAPIHandlerCodecCore as a, OpenAPIMatcher as b };
|
|
@@ -31,9 +31,7 @@ declare class OpenAPIMatcher {
|
|
|
31
31
|
private resolveProcedure;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
interface OpenAPIHandlerCodecOptions<_T extends Context> extends OpenAPIMatcherOptions {
|
|
34
|
+
interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
37
35
|
/**
|
|
38
36
|
* Override the default OpenAPI serializer.
|
|
39
37
|
*/
|
|
@@ -55,25 +53,30 @@ interface OpenAPIHandlerCodecOptions<_T extends Context> extends OpenAPIMatcherO
|
|
|
55
53
|
*/
|
|
56
54
|
customErrorResponseBodyEncoder?: (error: AnyORPCError) => unknown;
|
|
57
55
|
}
|
|
58
|
-
declare class
|
|
59
|
-
private readonly matcher;
|
|
56
|
+
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
60
57
|
private readonly serializer;
|
|
61
58
|
private readonly errorStatusMap;
|
|
62
59
|
private readonly customErrorResponseBodySerializer;
|
|
63
|
-
constructor(
|
|
60
|
+
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
64
61
|
decodeInput(matched: {
|
|
65
62
|
procedure: AnyProcedure;
|
|
66
63
|
params?: undefined | Record<string, string>;
|
|
67
64
|
}, request: StandardLazyRequest): Promise<unknown>;
|
|
68
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
69
65
|
/**
|
|
70
|
-
* @throws {
|
|
66
|
+
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
71
67
|
*/
|
|
72
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]
|
|
73
|
-
encodeError(error: AnyORPCError
|
|
68
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
|
|
69
|
+
encodeError(error: AnyORPCError): Promisable<StandardResponse>;
|
|
74
70
|
private deserializeQuery;
|
|
75
71
|
private deserializeParams;
|
|
76
72
|
}
|
|
73
|
+
interface OpenAPIHandlerCodecOptions<T extends Context> extends OpenAPIHandlerCodecCoreOptions<T>, OpenAPIMatcherOptions {
|
|
74
|
+
}
|
|
75
|
+
declare class OpenAPIHandlerCodec<T extends Context> extends OpenAPIHandlerCodecCore<T> implements StandardHandlerCodec<T> {
|
|
76
|
+
private readonly matcher;
|
|
77
|
+
constructor(router: AnyRouter, options?: OpenAPIHandlerCodecOptions<T>);
|
|
78
|
+
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
79
|
+
}
|
|
77
80
|
|
|
78
|
-
export { OpenAPIHandlerCodec as a,
|
|
79
|
-
export type { OpenAPIHandlerCodecOptions as O, OpenAPIMatcherOptions as
|
|
81
|
+
export { OpenAPIHandlerCodec as a, OpenAPIHandlerCodecCore as b, OpenAPIMatcher as d };
|
|
82
|
+
export type { OpenAPIHandlerCodecOptions as O, OpenAPIHandlerCodecCoreOptions as c, OpenAPIMatcherOptions as e };
|
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.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"@types/swagger-ui": "^5.32.0",
|
|
66
66
|
"rou3": "^0.8.1",
|
|
67
67
|
"swagger-ui": "^5.32.6",
|
|
68
|
-
"@orpc/client": "2.0.0-beta.
|
|
69
|
-
"@orpc/
|
|
70
|
-
"@orpc/server": "2.0.0-beta.
|
|
71
|
-
"@orpc/
|
|
72
|
-
"@orpc/
|
|
68
|
+
"@orpc/client": "2.0.0-beta.4",
|
|
69
|
+
"@orpc/contract": "2.0.0-beta.4",
|
|
70
|
+
"@orpc/server": "2.0.0-beta.4",
|
|
71
|
+
"@orpc/json-schema": "2.0.0-beta.4",
|
|
72
|
+
"@orpc/shared": "2.0.0-beta.4"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"fastify": "^5.6.2",
|