@orpc/openapi 0.0.0-next.e98b833 → 0.0.0-next.ea0903c
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 +12 -1
- package/dist/adapters/fetch/index.d.mts +6 -8
- package/dist/adapters/fetch/index.d.ts +6 -8
- package/dist/adapters/fetch/index.mjs +4 -5
- package/dist/adapters/hono/index.d.mts +2 -2
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.mjs +4 -5
- package/dist/adapters/next/index.d.mts +2 -2
- package/dist/adapters/next/index.d.ts +2 -2
- package/dist/adapters/next/index.mjs +4 -5
- package/dist/adapters/node/index.d.mts +6 -8
- package/dist/adapters/node/index.d.ts +6 -8
- package/dist/adapters/node/index.mjs +12 -23
- package/dist/adapters/standard/index.d.mts +7 -7
- package/dist/adapters/standard/index.d.ts +7 -7
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +5 -11
- package/dist/index.d.ts +5 -11
- package/dist/index.mjs +229 -9
- package/dist/shared/openapi.By1hOIbk.mjs +17 -0
- package/dist/shared/openapi.IfmmOyba.d.mts +8 -0
- package/dist/shared/openapi.IfmmOyba.d.ts +8 -0
- package/dist/shared/{openapi.CJTe38Ya.mjs → openapi.rzdlmBcy.mjs} +6 -5
- package/package.json +7 -9
- package/dist/shared/openapi.CbzTVvGL.mjs +0 -31
- package/dist/shared/openapi.DZzpQAb-.mjs +0 -231
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
33
|
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
34
|
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
|
35
|
-
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid), Pinia Colada, and more.
|
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
36
36
|
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
37
|
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
38
|
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
@@ -56,9 +56,12 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
56
56
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
57
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
58
|
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
59
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
59
60
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
60
61
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
61
62
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
63
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
64
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
62
65
|
|
|
63
66
|
## `@orpc/openapi`
|
|
64
67
|
|
|
@@ -87,6 +90,14 @@ const server = createServer(async (req, res) => {
|
|
|
87
90
|
server.listen(3000, '127.0.0.1', () => console.log('Listening on 127.0.0.1:3000'))
|
|
88
91
|
```
|
|
89
92
|
|
|
93
|
+
## Sponsors
|
|
94
|
+
|
|
95
|
+
<p align="center">
|
|
96
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
97
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
98
|
+
</a>
|
|
99
|
+
</p>
|
|
100
|
+
|
|
90
101
|
## License
|
|
91
102
|
|
|
92
103
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
|
-
import { FetchHandler,
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
6
|
|
|
7
|
-
declare class OpenAPIHandler<T extends Context>
|
|
8
|
-
|
|
9
|
-
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
|
10
|
-
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
|
7
|
+
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export { OpenAPIHandler };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
|
-
import { FetchHandler,
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
6
|
|
|
7
|
-
declare class OpenAPIHandler<T extends Context>
|
|
8
|
-
|
|
9
|
-
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
|
10
|
-
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
|
7
|
+
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export { OpenAPIHandler };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.By1hOIbk.mjs';
|
|
2
2
|
import '@orpc/openapi-client/standard';
|
|
3
|
+
import '@orpc/server/fetch';
|
|
3
4
|
import '@orpc/server/standard';
|
|
4
|
-
import '
|
|
5
|
-
import '../../shared/openapi.CJTe38Ya.mjs';
|
|
5
|
+
import '../../shared/openapi.rzdlmBcy.mjs';
|
|
6
6
|
import '@orpc/contract';
|
|
7
7
|
import '@orpc/shared';
|
|
8
|
+
import '@orpc/client/standard';
|
|
8
9
|
import '@orpc/server';
|
|
9
10
|
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.DZzpQAb-.mjs';
|
|
11
|
-
import 'json-schema-typed/draft-2020-12';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { OpenAPIHandler } from '../fetch/index.mjs';
|
|
2
2
|
import '@orpc/server';
|
|
3
3
|
import '@orpc/server/fetch';
|
|
4
|
+
import '../../shared/openapi.IfmmOyba.mjs';
|
|
5
|
+
import '@orpc/openapi-client/standard';
|
|
4
6
|
import '@orpc/server/standard';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@orpc/standard-server-fetch';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { OpenAPIHandler } from '../fetch/index.js';
|
|
2
2
|
import '@orpc/server';
|
|
3
3
|
import '@orpc/server/fetch';
|
|
4
|
+
import '../../shared/openapi.IfmmOyba.js';
|
|
5
|
+
import '@orpc/openapi-client/standard';
|
|
4
6
|
import '@orpc/server/standard';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@orpc/standard-server-fetch';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.By1hOIbk.mjs';
|
|
2
2
|
import '@orpc/openapi-client/standard';
|
|
3
|
+
import '@orpc/server/fetch';
|
|
3
4
|
import '@orpc/server/standard';
|
|
4
|
-
import '
|
|
5
|
-
import '../../shared/openapi.CJTe38Ya.mjs';
|
|
5
|
+
import '../../shared/openapi.rzdlmBcy.mjs';
|
|
6
6
|
import '@orpc/contract';
|
|
7
7
|
import '@orpc/shared';
|
|
8
|
+
import '@orpc/client/standard';
|
|
8
9
|
import '@orpc/server';
|
|
9
10
|
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.DZzpQAb-.mjs';
|
|
11
|
-
import 'json-schema-typed/draft-2020-12';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { OpenAPIHandler } from '../fetch/index.mjs';
|
|
2
2
|
import '@orpc/server';
|
|
3
3
|
import '@orpc/server/fetch';
|
|
4
|
+
import '../../shared/openapi.IfmmOyba.mjs';
|
|
5
|
+
import '@orpc/openapi-client/standard';
|
|
4
6
|
import '@orpc/server/standard';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@orpc/standard-server-fetch';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { OpenAPIHandler } from '../fetch/index.js';
|
|
2
2
|
import '@orpc/server';
|
|
3
3
|
import '@orpc/server/fetch';
|
|
4
|
+
import '../../shared/openapi.IfmmOyba.js';
|
|
5
|
+
import '@orpc/openapi-client/standard';
|
|
4
6
|
import '@orpc/server/standard';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@orpc/standard-server-fetch';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.By1hOIbk.mjs';
|
|
2
2
|
import '@orpc/openapi-client/standard';
|
|
3
|
+
import '@orpc/server/fetch';
|
|
3
4
|
import '@orpc/server/standard';
|
|
4
|
-
import '
|
|
5
|
-
import '../../shared/openapi.CJTe38Ya.mjs';
|
|
5
|
+
import '../../shared/openapi.rzdlmBcy.mjs';
|
|
6
6
|
import '@orpc/contract';
|
|
7
7
|
import '@orpc/shared';
|
|
8
|
+
import '@orpc/client/standard';
|
|
8
9
|
import '@orpc/server';
|
|
9
10
|
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.DZzpQAb-.mjs';
|
|
11
|
-
import 'json-schema-typed/draft-2020-12';
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
|
-
import { NodeHttpHandler,
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
6
|
|
|
7
|
-
declare class OpenAPIHandler<T extends Context>
|
|
8
|
-
|
|
9
|
-
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
|
10
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
|
7
|
+
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export { OpenAPIHandler };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
|
2
|
-
import { NodeHttpHandler,
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
6
|
|
|
7
|
-
declare class OpenAPIHandler<T extends Context>
|
|
8
|
-
|
|
9
|
-
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
|
10
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
|
7
|
+
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export { OpenAPIHandler };
|
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { NodeHttpHandler } from '@orpc/server/node';
|
|
2
3
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import {
|
|
4
|
-
import { a as OpenAPIMatcher, O as OpenAPICodec } from '../../shared/openapi.CJTe38Ya.mjs';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import 'json-schema-typed/draft-2020-12';
|
|
4
|
+
import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from '../../shared/openapi.rzdlmBcy.mjs';
|
|
7
5
|
import '@orpc/contract';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/client/standard';
|
|
8
8
|
import '@orpc/server';
|
|
9
9
|
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.DZzpQAb-.mjs';
|
|
11
10
|
|
|
12
|
-
class OpenAPIHandler {
|
|
13
|
-
standardHandler;
|
|
11
|
+
class OpenAPIHandler extends NodeHttpHandler {
|
|
14
12
|
constructor(router, options = {}) {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
options = {}
|
|
22
|
-
]) {
|
|
23
|
-
const standardRequest = toStandardLazyRequest(req, res);
|
|
24
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
25
|
-
if (!result.matched) {
|
|
26
|
-
return { matched: false };
|
|
27
|
-
}
|
|
28
|
-
await sendStandardResponse(res, result.response, options);
|
|
29
|
-
return { matched: true };
|
|
13
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
14
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
15
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
16
|
+
const matcher = new StandardOpenAPIMatcher();
|
|
17
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
18
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
|
30
19
|
}
|
|
31
20
|
}
|
|
32
21
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
2
|
-
import {
|
|
1
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
3
3
|
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
4
|
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
-
|
|
6
|
+
export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
|
7
7
|
|
|
8
|
-
declare class
|
|
8
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
9
9
|
private readonly serializer;
|
|
10
|
-
constructor(serializer:
|
|
10
|
+
constructor(serializer: StandardOpenAPISerializer);
|
|
11
11
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
12
12
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
13
13
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare class
|
|
16
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
17
17
|
private readonly tree;
|
|
18
18
|
private pendingRouters;
|
|
19
19
|
init(router: AnyRouter, path?: readonly string[]): void;
|
|
@@ -31,4 +31,4 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
|
31
31
|
*/
|
|
32
32
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
33
33
|
|
|
34
|
-
export {
|
|
34
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
2
|
-
import {
|
|
1
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
3
3
|
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
4
|
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
-
|
|
6
|
+
export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
|
7
7
|
|
|
8
|
-
declare class
|
|
8
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
9
9
|
private readonly serializer;
|
|
10
|
-
constructor(serializer:
|
|
10
|
+
constructor(serializer: StandardOpenAPISerializer);
|
|
11
11
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
12
12
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
13
13
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare class
|
|
16
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
17
17
|
private readonly tree;
|
|
18
18
|
private pendingRouters;
|
|
19
19
|
init(router: AnyRouter, path?: readonly string[]): void;
|
|
@@ -31,4 +31,4 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
|
31
31
|
*/
|
|
32
32
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
33
33
|
|
|
34
|
-
export {
|
|
34
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { S as StandardOpenAPICodec, a as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.rzdlmBcy.mjs';
|
|
2
2
|
import '@orpc/contract';
|
|
3
3
|
import '@orpc/shared';
|
|
4
|
+
import '@orpc/client/standard';
|
|
4
5
|
import '@orpc/server';
|
|
5
6
|
import 'rou3';
|
|
6
|
-
import '
|
|
7
|
-
import 'json-schema-typed/draft-2020-12';
|
|
7
|
+
import '@orpc/openapi-client/standard';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { AnyContractProcedure, AnySchema, AnyContractRouter
|
|
1
|
+
import { AnyContractProcedure, AnySchema, AnyContractRouter } from '@orpc/contract';
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
4
5
|
import { AnyRouter } from '@orpc/server';
|
|
5
6
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
6
7
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
8
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
7
9
|
|
|
8
10
|
type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
|
|
9
11
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
@@ -43,7 +45,7 @@ declare class CompositeSchemaConverter implements SchemaConverter {
|
|
|
43
45
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
interface OpenAPIGeneratorOptions {
|
|
48
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
47
49
|
schemaConverters?: ConditionalSchemaConverter[];
|
|
48
50
|
}
|
|
49
51
|
declare class OpenAPIGenerator {
|
|
@@ -54,10 +56,6 @@ declare class OpenAPIGenerator {
|
|
|
54
56
|
generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
61
59
|
/**
|
|
62
60
|
* @internal
|
|
63
61
|
*/
|
|
@@ -66,10 +64,6 @@ declare function toOpenAPIPath(path: HTTPPath): string;
|
|
|
66
64
|
* @internal
|
|
67
65
|
*/
|
|
68
66
|
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
declare function getDynamicParams(path: HTTPPath | undefined): string[] | undefined;
|
|
73
67
|
/**
|
|
74
68
|
* @internal
|
|
75
69
|
*/
|
|
@@ -116,4 +110,4 @@ declare const oo: {
|
|
|
116
110
|
spec: typeof customOpenAPIOperation;
|
|
117
111
|
};
|
|
118
112
|
|
|
119
|
-
export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation,
|
|
113
|
+
export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { AnyContractProcedure, AnySchema, AnyContractRouter
|
|
1
|
+
import { AnyContractProcedure, AnySchema, AnyContractRouter } from '@orpc/contract';
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
4
5
|
import { AnyRouter } from '@orpc/server';
|
|
5
6
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
6
7
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
8
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
7
9
|
|
|
8
10
|
type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
|
|
9
11
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
@@ -43,7 +45,7 @@ declare class CompositeSchemaConverter implements SchemaConverter {
|
|
|
43
45
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
interface OpenAPIGeneratorOptions {
|
|
48
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
47
49
|
schemaConverters?: ConditionalSchemaConverter[];
|
|
48
50
|
}
|
|
49
51
|
declare class OpenAPIGenerator {
|
|
@@ -54,10 +56,6 @@ declare class OpenAPIGenerator {
|
|
|
54
56
|
generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
61
59
|
/**
|
|
62
60
|
* @internal
|
|
63
61
|
*/
|
|
@@ -66,10 +64,6 @@ declare function toOpenAPIPath(path: HTTPPath): string;
|
|
|
66
64
|
* @internal
|
|
67
65
|
*/
|
|
68
66
|
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
declare function getDynamicParams(path: HTTPPath | undefined): string[] | undefined;
|
|
73
67
|
/**
|
|
74
68
|
* @internal
|
|
75
69
|
*/
|
|
@@ -116,4 +110,4 @@ declare const oo: {
|
|
|
116
110
|
spec: typeof customOpenAPIOperation;
|
|
117
111
|
};
|
|
118
112
|
|
|
119
|
-
export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation,
|
|
113
|
+
export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { isProcedure, resolveContractProcedures
|
|
1
|
+
import { isProcedure, resolveContractProcedures } from '@orpc/server';
|
|
2
2
|
import { fallbackORPCErrorStatus, fallbackORPCErrorMessage } from '@orpc/client';
|
|
3
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
3
4
|
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@orpc/contract';
|
|
4
|
-
import {
|
|
5
|
-
import { clone } from '@orpc/shared';
|
|
6
|
-
import { t as toOpenAPIMethod, a as toOpenAPIPath, b as toOpenAPIEventIteratorContent, g as getDynamicParams, i as isAnySchema, c as isObjectSchema, d as separateObjectSchema, e as checkParamsSchema, f as toOpenAPIParameters, h as toOpenAPIContent, j as toOpenAPISchema } from './shared/openapi.DZzpQAb-.mjs';
|
|
7
|
-
export { L as LOGIC_KEYWORDS, l as filterSchemaBranches, k as isFileSchema, s as standardizeHTTPPath } from './shared/openapi.DZzpQAb-.mjs';
|
|
5
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, getDynamicParams } from '@orpc/openapi-client/standard';
|
|
6
|
+
import { isObject, findDeepMatches, clone } from '@orpc/shared';
|
|
8
7
|
export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
9
8
|
|
|
10
9
|
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
@@ -51,6 +50,227 @@ function applyCustomOpenAPIOperation(operation, contract) {
|
|
|
51
50
|
return currentOperation;
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
const LOGIC_KEYWORDS = [
|
|
54
|
+
"$dynamicRef",
|
|
55
|
+
"$ref",
|
|
56
|
+
"additionalItems",
|
|
57
|
+
"additionalProperties",
|
|
58
|
+
"allOf",
|
|
59
|
+
"anyOf",
|
|
60
|
+
"const",
|
|
61
|
+
"contains",
|
|
62
|
+
"contentEncoding",
|
|
63
|
+
"contentMediaType",
|
|
64
|
+
"contentSchema",
|
|
65
|
+
"dependencies",
|
|
66
|
+
"dependentRequired",
|
|
67
|
+
"dependentSchemas",
|
|
68
|
+
"else",
|
|
69
|
+
"enum",
|
|
70
|
+
"exclusiveMaximum",
|
|
71
|
+
"exclusiveMinimum",
|
|
72
|
+
"format",
|
|
73
|
+
"if",
|
|
74
|
+
"items",
|
|
75
|
+
"maxContains",
|
|
76
|
+
"maximum",
|
|
77
|
+
"maxItems",
|
|
78
|
+
"maxLength",
|
|
79
|
+
"maxProperties",
|
|
80
|
+
"minContains",
|
|
81
|
+
"minimum",
|
|
82
|
+
"minItems",
|
|
83
|
+
"minLength",
|
|
84
|
+
"minProperties",
|
|
85
|
+
"multipleOf",
|
|
86
|
+
"not",
|
|
87
|
+
"oneOf",
|
|
88
|
+
"pattern",
|
|
89
|
+
"patternProperties",
|
|
90
|
+
"prefixItems",
|
|
91
|
+
"properties",
|
|
92
|
+
"propertyNames",
|
|
93
|
+
"required",
|
|
94
|
+
"then",
|
|
95
|
+
"type",
|
|
96
|
+
"unevaluatedItems",
|
|
97
|
+
"unevaluatedProperties",
|
|
98
|
+
"uniqueItems"
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
function isFileSchema(schema) {
|
|
102
|
+
return isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
103
|
+
}
|
|
104
|
+
function isObjectSchema(schema) {
|
|
105
|
+
return isObject(schema) && schema.type === "object";
|
|
106
|
+
}
|
|
107
|
+
function isAnySchema(schema) {
|
|
108
|
+
if (schema === true) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (Object.keys(schema).every((k) => !LOGIC_KEYWORDS.includes(k))) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function separateObjectSchema(schema, separatedProperties) {
|
|
117
|
+
if (Object.keys(schema).some((k) => k !== "type" && k !== "properties" && k !== "required" && LOGIC_KEYWORDS.includes(k))) {
|
|
118
|
+
return [{ type: "object" }, schema];
|
|
119
|
+
}
|
|
120
|
+
const matched = { ...schema };
|
|
121
|
+
const rest = { ...schema };
|
|
122
|
+
matched.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
123
|
+
acc[key] = value;
|
|
124
|
+
return acc;
|
|
125
|
+
}, {});
|
|
126
|
+
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
127
|
+
matched.examples = schema.examples?.map((example) => {
|
|
128
|
+
if (!isObject(example)) {
|
|
129
|
+
return example;
|
|
130
|
+
}
|
|
131
|
+
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
132
|
+
if (separatedProperties.includes(key)) {
|
|
133
|
+
acc[key] = value;
|
|
134
|
+
}
|
|
135
|
+
return acc;
|
|
136
|
+
}, {});
|
|
137
|
+
});
|
|
138
|
+
rest.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
139
|
+
acc[key] = value;
|
|
140
|
+
return acc;
|
|
141
|
+
}, {});
|
|
142
|
+
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
143
|
+
rest.examples = schema.examples?.map((example) => {
|
|
144
|
+
if (!isObject(example)) {
|
|
145
|
+
return example;
|
|
146
|
+
}
|
|
147
|
+
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
148
|
+
if (!separatedProperties.includes(key)) {
|
|
149
|
+
acc[key] = value;
|
|
150
|
+
}
|
|
151
|
+
return acc;
|
|
152
|
+
}, {});
|
|
153
|
+
});
|
|
154
|
+
return [matched, rest];
|
|
155
|
+
}
|
|
156
|
+
function filterSchemaBranches(schema, check, matches = []) {
|
|
157
|
+
if (check(schema)) {
|
|
158
|
+
matches.push(schema);
|
|
159
|
+
return [matches, void 0];
|
|
160
|
+
}
|
|
161
|
+
if (isObject(schema)) {
|
|
162
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
163
|
+
if (schema[keyword] && Object.keys(schema).every(
|
|
164
|
+
(k) => k === keyword || !LOGIC_KEYWORDS.includes(k)
|
|
165
|
+
)) {
|
|
166
|
+
const rest = schema[keyword].map((s) => filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
167
|
+
if (rest.length === 1 && typeof rest[0] === "object") {
|
|
168
|
+
return [matches, { ...schema, [keyword]: void 0, ...rest[0] }];
|
|
169
|
+
}
|
|
170
|
+
return [matches, { ...schema, [keyword]: rest }];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return [matches, schema];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function toOpenAPIPath(path) {
|
|
178
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
|
|
179
|
+
}
|
|
180
|
+
function toOpenAPIMethod(method) {
|
|
181
|
+
return method.toLocaleLowerCase();
|
|
182
|
+
}
|
|
183
|
+
function toOpenAPIContent(schema) {
|
|
184
|
+
const content = {};
|
|
185
|
+
const [matches, restSchema] = filterSchemaBranches(schema, isFileSchema);
|
|
186
|
+
for (const file of matches) {
|
|
187
|
+
content[file.contentMediaType] = {
|
|
188
|
+
schema: toOpenAPISchema(file)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (restSchema !== void 0) {
|
|
192
|
+
content["application/json"] = {
|
|
193
|
+
schema: toOpenAPISchema(restSchema)
|
|
194
|
+
};
|
|
195
|
+
const isStillHasFileSchema = findDeepMatches((v) => isObject(v) && isFileSchema(v), restSchema).values.length > 0;
|
|
196
|
+
if (isStillHasFileSchema) {
|
|
197
|
+
content["multipart/form-data"] = {
|
|
198
|
+
schema: toOpenAPISchema(restSchema)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return content;
|
|
203
|
+
}
|
|
204
|
+
function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema], [returnsRequired, returnsSchema]) {
|
|
205
|
+
return {
|
|
206
|
+
"text/event-stream": {
|
|
207
|
+
schema: toOpenAPISchema({
|
|
208
|
+
oneOf: [
|
|
209
|
+
{
|
|
210
|
+
type: "object",
|
|
211
|
+
properties: {
|
|
212
|
+
event: { const: "message" },
|
|
213
|
+
data: yieldsSchema,
|
|
214
|
+
id: { type: "string" },
|
|
215
|
+
retry: { type: "number" }
|
|
216
|
+
},
|
|
217
|
+
required: yieldsRequired ? ["event", "data"] : ["event"]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
event: { const: "done" },
|
|
223
|
+
data: returnsSchema,
|
|
224
|
+
id: { type: "string" },
|
|
225
|
+
retry: { type: "number" }
|
|
226
|
+
},
|
|
227
|
+
required: returnsRequired ? ["event", "data"] : ["event"]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {
|
|
232
|
+
event: { const: "error" },
|
|
233
|
+
data: {},
|
|
234
|
+
id: { type: "string" },
|
|
235
|
+
retry: { type: "number" }
|
|
236
|
+
},
|
|
237
|
+
required: ["event"]
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function toOpenAPIParameters(schema, parameterIn) {
|
|
245
|
+
const parameters = [];
|
|
246
|
+
for (const key in schema.properties) {
|
|
247
|
+
const keySchema = schema.properties[key];
|
|
248
|
+
parameters.push({
|
|
249
|
+
name: key,
|
|
250
|
+
in: parameterIn,
|
|
251
|
+
required: schema.required?.includes(key),
|
|
252
|
+
style: parameterIn === "query" ? "deepObject" : void 0,
|
|
253
|
+
explode: parameterIn === "query" ? true : void 0,
|
|
254
|
+
schema: toOpenAPISchema(keySchema)
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return parameters;
|
|
258
|
+
}
|
|
259
|
+
function checkParamsSchema(schema, params) {
|
|
260
|
+
const properties = Object.keys(schema.properties ?? {});
|
|
261
|
+
const required = schema.required ?? [];
|
|
262
|
+
if (properties.length !== params.length || properties.some((v) => !params.includes(v))) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
if (required.length !== params.length || required.some((v) => !params.includes(v))) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
function toOpenAPISchema(schema) {
|
|
271
|
+
return schema === true ? {} : schema === false ? { not: {} } : schema;
|
|
272
|
+
}
|
|
273
|
+
|
|
54
274
|
class CompositeSchemaConverter {
|
|
55
275
|
converters;
|
|
56
276
|
constructor(converters) {
|
|
@@ -72,7 +292,7 @@ class OpenAPIGenerator {
|
|
|
72
292
|
serializer;
|
|
73
293
|
converter;
|
|
74
294
|
constructor(options = {}) {
|
|
75
|
-
this.serializer = new
|
|
295
|
+
this.serializer = new StandardOpenAPIJsonSerializer(options);
|
|
76
296
|
this.converter = new CompositeSchemaConverter(options.schemaConverters ?? []);
|
|
77
297
|
}
|
|
78
298
|
async generate(router, base) {
|
|
@@ -115,7 +335,7 @@ ${e.message}`
|
|
|
115
335
|
${errors.join("\n\n")}`
|
|
116
336
|
);
|
|
117
337
|
}
|
|
118
|
-
return this.serializer.serialize(doc);
|
|
338
|
+
return this.serializer.serialize(doc)[0];
|
|
119
339
|
}
|
|
120
340
|
#request(ref, def) {
|
|
121
341
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
@@ -130,7 +350,7 @@ ${errors.join("\n\n")}`
|
|
|
130
350
|
};
|
|
131
351
|
return;
|
|
132
352
|
}
|
|
133
|
-
const dynamicParams = getDynamicParams(def.route.path);
|
|
353
|
+
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
134
354
|
const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
|
|
135
355
|
let [required, schema] = this.converter.convert(def.inputSchema, { strategy: "input" });
|
|
136
356
|
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
@@ -300,4 +520,4 @@ const oo = {
|
|
|
300
520
|
spec: customOpenAPIOperation
|
|
301
521
|
};
|
|
302
522
|
|
|
303
|
-
export { CompositeSchemaConverter, OpenAPIGenerator, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation,
|
|
523
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { FetchHandler } from '@orpc/server/fetch';
|
|
3
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.rzdlmBcy.mjs';
|
|
5
|
+
|
|
6
|
+
class OpenAPIHandler extends FetchHandler {
|
|
7
|
+
constructor(router, options = {}) {
|
|
8
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
9
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
10
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
11
|
+
const matcher = new StandardOpenAPIMatcher();
|
|
12
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
13
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPIHandler as O };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
2
|
import { isObject } from '@orpc/shared';
|
|
3
|
-
import {
|
|
3
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
4
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
4
5
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
5
|
-
import {
|
|
6
|
+
import { standardizeHTTPPath } from '@orpc/openapi-client/standard';
|
|
6
7
|
|
|
7
|
-
class
|
|
8
|
+
class StandardOpenAPICodec {
|
|
8
9
|
constructor(serializer) {
|
|
9
10
|
this.serializer = serializer;
|
|
10
11
|
}
|
|
@@ -77,7 +78,7 @@ function decodeParams(params) {
|
|
|
77
78
|
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
class
|
|
81
|
+
class StandardOpenAPIMatcher {
|
|
81
82
|
tree = createRouter();
|
|
82
83
|
pendingRouters = [];
|
|
83
84
|
init(router, path = []) {
|
|
@@ -142,4 +143,4 @@ class OpenAPIMatcher {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
export {
|
|
146
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, decodeParams as d, toRou3Pattern as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.ea0903c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -52,14 +52,12 @@
|
|
|
52
52
|
"json-schema-typed": "^8.0.1",
|
|
53
53
|
"openapi-types": "^12.1.3",
|
|
54
54
|
"rou3": "^0.5.1",
|
|
55
|
-
"@orpc/client": "0.0.0-next.
|
|
56
|
-
"@orpc/
|
|
57
|
-
"@orpc/
|
|
58
|
-
"@orpc/
|
|
59
|
-
"@orpc/
|
|
60
|
-
"@orpc/standard-server
|
|
61
|
-
"@orpc/standard-server": "0.0.0-next.e98b833",
|
|
62
|
-
"@orpc/standard-server-node": "0.0.0-next.e98b833"
|
|
55
|
+
"@orpc/client": "0.0.0-next.ea0903c",
|
|
56
|
+
"@orpc/openapi-client": "0.0.0-next.ea0903c",
|
|
57
|
+
"@orpc/server": "0.0.0-next.ea0903c",
|
|
58
|
+
"@orpc/shared": "0.0.0-next.ea0903c",
|
|
59
|
+
"@orpc/contract": "0.0.0-next.ea0903c",
|
|
60
|
+
"@orpc/standard-server": "0.0.0-next.ea0903c"
|
|
63
61
|
},
|
|
64
62
|
"devDependencies": {
|
|
65
63
|
"zod": "^3.24.2"
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
-
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
|
4
|
-
import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.CJTe38Ya.mjs';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import 'json-schema-typed/draft-2020-12';
|
|
7
|
-
|
|
8
|
-
class OpenAPIHandler {
|
|
9
|
-
standardHandler;
|
|
10
|
-
constructor(router, options = {}) {
|
|
11
|
-
const serializer = new OpenAPISerializer();
|
|
12
|
-
const matcher = new OpenAPIMatcher();
|
|
13
|
-
const codec = new OpenAPICodec(serializer);
|
|
14
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
|
-
}
|
|
16
|
-
async handle(request, ...[
|
|
17
|
-
options = {}
|
|
18
|
-
]) {
|
|
19
|
-
const standardRequest = toStandardLazyRequest(request);
|
|
20
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
21
|
-
if (!result.matched) {
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
matched: true,
|
|
26
|
-
response: toFetchResponse(result.response, options)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { OpenAPIHandler as O };
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { isObject, findDeepMatches } from '@orpc/shared';
|
|
2
|
-
import 'json-schema-typed/draft-2020-12';
|
|
3
|
-
|
|
4
|
-
const LOGIC_KEYWORDS = [
|
|
5
|
-
"$dynamicRef",
|
|
6
|
-
"$ref",
|
|
7
|
-
"additionalItems",
|
|
8
|
-
"additionalProperties",
|
|
9
|
-
"allOf",
|
|
10
|
-
"anyOf",
|
|
11
|
-
"const",
|
|
12
|
-
"contains",
|
|
13
|
-
"contentEncoding",
|
|
14
|
-
"contentMediaType",
|
|
15
|
-
"contentSchema",
|
|
16
|
-
"dependencies",
|
|
17
|
-
"dependentRequired",
|
|
18
|
-
"dependentSchemas",
|
|
19
|
-
"else",
|
|
20
|
-
"enum",
|
|
21
|
-
"exclusiveMaximum",
|
|
22
|
-
"exclusiveMinimum",
|
|
23
|
-
"format",
|
|
24
|
-
"if",
|
|
25
|
-
"items",
|
|
26
|
-
"maxContains",
|
|
27
|
-
"maximum",
|
|
28
|
-
"maxItems",
|
|
29
|
-
"maxLength",
|
|
30
|
-
"maxProperties",
|
|
31
|
-
"minContains",
|
|
32
|
-
"minimum",
|
|
33
|
-
"minItems",
|
|
34
|
-
"minLength",
|
|
35
|
-
"minProperties",
|
|
36
|
-
"multipleOf",
|
|
37
|
-
"not",
|
|
38
|
-
"oneOf",
|
|
39
|
-
"pattern",
|
|
40
|
-
"patternProperties",
|
|
41
|
-
"prefixItems",
|
|
42
|
-
"properties",
|
|
43
|
-
"propertyNames",
|
|
44
|
-
"required",
|
|
45
|
-
"then",
|
|
46
|
-
"type",
|
|
47
|
-
"unevaluatedItems",
|
|
48
|
-
"unevaluatedProperties",
|
|
49
|
-
"uniqueItems"
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
function isFileSchema(schema) {
|
|
53
|
-
return isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
54
|
-
}
|
|
55
|
-
function isObjectSchema(schema) {
|
|
56
|
-
return isObject(schema) && schema.type === "object";
|
|
57
|
-
}
|
|
58
|
-
function isAnySchema(schema) {
|
|
59
|
-
if (schema === true) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
if (Object.keys(schema).every((k) => !LOGIC_KEYWORDS.includes(k))) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
function separateObjectSchema(schema, separatedProperties) {
|
|
68
|
-
if (Object.keys(schema).some((k) => k !== "type" && k !== "properties" && k !== "required" && LOGIC_KEYWORDS.includes(k))) {
|
|
69
|
-
return [{ type: "object" }, schema];
|
|
70
|
-
}
|
|
71
|
-
const matched = { ...schema };
|
|
72
|
-
const rest = { ...schema };
|
|
73
|
-
matched.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
74
|
-
acc[key] = value;
|
|
75
|
-
return acc;
|
|
76
|
-
}, {});
|
|
77
|
-
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
78
|
-
matched.examples = schema.examples?.map((example) => {
|
|
79
|
-
if (!isObject(example)) {
|
|
80
|
-
return example;
|
|
81
|
-
}
|
|
82
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
83
|
-
if (separatedProperties.includes(key)) {
|
|
84
|
-
acc[key] = value;
|
|
85
|
-
}
|
|
86
|
-
return acc;
|
|
87
|
-
}, {});
|
|
88
|
-
});
|
|
89
|
-
rest.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
90
|
-
acc[key] = value;
|
|
91
|
-
return acc;
|
|
92
|
-
}, {});
|
|
93
|
-
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
94
|
-
rest.examples = schema.examples?.map((example) => {
|
|
95
|
-
if (!isObject(example)) {
|
|
96
|
-
return example;
|
|
97
|
-
}
|
|
98
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
99
|
-
if (!separatedProperties.includes(key)) {
|
|
100
|
-
acc[key] = value;
|
|
101
|
-
}
|
|
102
|
-
return acc;
|
|
103
|
-
}, {});
|
|
104
|
-
});
|
|
105
|
-
return [matched, rest];
|
|
106
|
-
}
|
|
107
|
-
function filterSchemaBranches(schema, check, matches = []) {
|
|
108
|
-
if (check(schema)) {
|
|
109
|
-
matches.push(schema);
|
|
110
|
-
return [matches, void 0];
|
|
111
|
-
}
|
|
112
|
-
if (isObject(schema)) {
|
|
113
|
-
for (const keyword of ["anyOf", "oneOf"]) {
|
|
114
|
-
if (schema[keyword] && Object.keys(schema).every(
|
|
115
|
-
(k) => k === keyword || !LOGIC_KEYWORDS.includes(k)
|
|
116
|
-
)) {
|
|
117
|
-
const rest = schema[keyword].map((s) => filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
118
|
-
if (rest.length === 1 && typeof rest[0] === "object") {
|
|
119
|
-
return [matches, { ...schema, [keyword]: void 0, ...rest[0] }];
|
|
120
|
-
}
|
|
121
|
-
return [matches, { ...schema, [keyword]: rest }];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return [matches, schema];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function standardizeHTTPPath(path) {
|
|
129
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
130
|
-
}
|
|
131
|
-
function toOpenAPIPath(path) {
|
|
132
|
-
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
|
|
133
|
-
}
|
|
134
|
-
function toOpenAPIMethod(method) {
|
|
135
|
-
return method.toLocaleLowerCase();
|
|
136
|
-
}
|
|
137
|
-
function getDynamicParams(path) {
|
|
138
|
-
return path ? standardizeHTTPPath(path).match(/\/\{([^}]+)\}/g)?.map((v) => v.match(/\{\+?([^}]+)\}/)[1]) : void 0;
|
|
139
|
-
}
|
|
140
|
-
function toOpenAPIContent(schema) {
|
|
141
|
-
const content = {};
|
|
142
|
-
const [matches, restSchema] = filterSchemaBranches(schema, isFileSchema);
|
|
143
|
-
for (const file of matches) {
|
|
144
|
-
content[file.contentMediaType] = {
|
|
145
|
-
schema: toOpenAPISchema(file)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (restSchema !== void 0) {
|
|
149
|
-
content["application/json"] = {
|
|
150
|
-
schema: toOpenAPISchema(restSchema)
|
|
151
|
-
};
|
|
152
|
-
const isStillHasFileSchema = findDeepMatches((v) => isObject(v) && isFileSchema(v), restSchema).values.length > 0;
|
|
153
|
-
if (isStillHasFileSchema) {
|
|
154
|
-
content["multipart/form-data"] = {
|
|
155
|
-
schema: toOpenAPISchema(restSchema)
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return content;
|
|
160
|
-
}
|
|
161
|
-
function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema], [returnsRequired, returnsSchema]) {
|
|
162
|
-
return {
|
|
163
|
-
"text/event-stream": {
|
|
164
|
-
schema: toOpenAPISchema({
|
|
165
|
-
oneOf: [
|
|
166
|
-
{
|
|
167
|
-
type: "object",
|
|
168
|
-
properties: {
|
|
169
|
-
event: { const: "message" },
|
|
170
|
-
data: yieldsSchema,
|
|
171
|
-
id: { type: "string" },
|
|
172
|
-
retry: { type: "number" }
|
|
173
|
-
},
|
|
174
|
-
required: yieldsRequired ? ["event", "data"] : ["event"]
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
type: "object",
|
|
178
|
-
properties: {
|
|
179
|
-
event: { const: "done" },
|
|
180
|
-
data: returnsSchema,
|
|
181
|
-
id: { type: "string" },
|
|
182
|
-
retry: { type: "number" }
|
|
183
|
-
},
|
|
184
|
-
required: returnsRequired ? ["event", "data"] : ["event"]
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
type: "object",
|
|
188
|
-
properties: {
|
|
189
|
-
event: { const: "error" },
|
|
190
|
-
data: {},
|
|
191
|
-
id: { type: "string" },
|
|
192
|
-
retry: { type: "number" }
|
|
193
|
-
},
|
|
194
|
-
required: ["event"]
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function toOpenAPIParameters(schema, parameterIn) {
|
|
202
|
-
const parameters = [];
|
|
203
|
-
for (const key in schema.properties) {
|
|
204
|
-
const keySchema = schema.properties[key];
|
|
205
|
-
parameters.push({
|
|
206
|
-
name: key,
|
|
207
|
-
in: parameterIn,
|
|
208
|
-
required: schema.required?.includes(key),
|
|
209
|
-
style: parameterIn === "query" ? "deepObject" : void 0,
|
|
210
|
-
explode: parameterIn === "query" ? true : void 0,
|
|
211
|
-
schema: toOpenAPISchema(keySchema)
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return parameters;
|
|
215
|
-
}
|
|
216
|
-
function checkParamsSchema(schema, params) {
|
|
217
|
-
const properties = Object.keys(schema.properties ?? {});
|
|
218
|
-
const required = schema.required ?? [];
|
|
219
|
-
if (properties.length !== params.length || properties.some((v) => !params.includes(v))) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
if (required.length !== params.length || required.some((v) => !params.includes(v))) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
function toOpenAPISchema(schema) {
|
|
228
|
-
return schema === true ? {} : schema === false ? { not: {} } : schema;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { LOGIC_KEYWORDS as L, toOpenAPIPath as a, toOpenAPIEventIteratorContent as b, isObjectSchema as c, separateObjectSchema as d, checkParamsSchema as e, toOpenAPIParameters as f, getDynamicParams as g, toOpenAPIContent as h, isAnySchema as i, toOpenAPISchema as j, isFileSchema as k, filterSchemaBranches as l, standardizeHTTPPath as s, toOpenAPIMethod as t };
|