@orpc/openapi 0.0.0-next.ef3ba82 → 0.0.0-next.f16d90e
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 +101 -0
- package/dist/adapters/aws-lambda/index.d.mts +17 -0
- package/dist/adapters/aws-lambda/index.d.ts +17 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +17 -0
- package/dist/adapters/fetch/index.d.ts +17 -0
- package/dist/adapters/fetch/index.mjs +18 -0
- package/dist/adapters/node/index.d.mts +17 -0
- package/dist/adapters/node/index.d.ts +17 -0
- package/dist/adapters/node/index.mjs +18 -0
- package/dist/adapters/standard/index.d.mts +35 -0
- package/dist/adapters/standard/index.d.ts +35 -0
- package/dist/adapters/standard/index.mjs +9 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.mjs +41 -0
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.d.ts +69 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/openapi.C_UtQ8Us.mjs +179 -0
- package/dist/shared/openapi.D3j94c9n.d.mts +12 -0
- package/dist/shared/openapi.D3j94c9n.d.ts +12 -0
- package/dist/shared/openapi.DaYgbD_w.mjs +652 -0
- package/dist/shared/openapi.qZLdpE0a.d.mts +52 -0
- package/dist/shared/openapi.qZLdpE0a.d.ts +52 -0
- package/package.json +35 -21
- package/dist/fetch.js +0 -668
- package/dist/index.js +0 -4421
- package/dist/src/fetch/base-handler.d.ts +0 -14
- package/dist/src/fetch/index.d.ts +0 -3
- package/dist/src/fetch/server-handler.d.ts +0 -2
- package/dist/src/fetch/serverless-handler.d.ts +0 -2
- package/dist/src/generator.d.ts +0 -23
- package/dist/src/index.d.ts +0 -2
- package/dist/src/zod-to-json-schema.d.ts +0 -42
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/openapi">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fopenapi?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
29
|
+
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
|
+
|
|
43
|
+
## Documentation
|
|
44
|
+
|
|
45
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
46
|
+
|
|
47
|
+
## Packages
|
|
48
|
+
|
|
49
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
50
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
53
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
54
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
55
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
56
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
57
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
62
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
63
|
+
|
|
64
|
+
## `@orpc/openapi`
|
|
65
|
+
|
|
66
|
+
Generate OpenAPI specs and handle OpenAPI requests. Read the [documentation](https://orpc.unnoq.com/docs/openapi/getting-started) for more information.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createServer } from 'node:http'
|
|
70
|
+
import { OpenAPIHandler } from '@orpc/openapi/node'
|
|
71
|
+
import { CORSPlugin } from '@orpc/server/plugins'
|
|
72
|
+
|
|
73
|
+
const handler = new OpenAPIHandler(router, {
|
|
74
|
+
plugins: [new CORSPlugin()]
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const server = createServer(async (req, res) => {
|
|
78
|
+
const result = await handler.handle(req, res, {
|
|
79
|
+
context: { headers: req.headers }
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
if (!result.matched) {
|
|
83
|
+
res.statusCode = 404
|
|
84
|
+
res.end('No procedure matched')
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
server.listen(3000, '127.0.0.1', () => console.log('Listening on 127.0.0.1:3000'))
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Sponsors
|
|
92
|
+
|
|
93
|
+
<p align="center">
|
|
94
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
95
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
96
|
+
</a>
|
|
97
|
+
</p>
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for AWS Lambda.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class experimental_OpenAPIHandler<T extends Context> extends AwsLambdaHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & AwsLambdaHandlerOptions>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { experimental_OpenAPIHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for AWS Lambda.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class experimental_OpenAPIHandler<T extends Context> extends AwsLambdaHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & AwsLambdaHandlerOptions>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { experimental_OpenAPIHandler };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AwsLambdaHandler } from '@orpc/server/aws-lambda';
|
|
2
|
+
import '@orpc/client';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import '@orpc/shared';
|
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/server';
|
|
8
|
+
import 'rou3';
|
|
9
|
+
import '@orpc/openapi-client/standard';
|
|
10
|
+
import '@orpc/server/standard';
|
|
11
|
+
|
|
12
|
+
class experimental_OpenAPIHandler extends AwsLambdaHandler {
|
|
13
|
+
constructor(router, options = {}) {
|
|
14
|
+
super(new StandardOpenAPIHandler(router, options), options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { experimental_OpenAPIHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for Fetch Server
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for Fetch Server
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FetchHandler } from '@orpc/server/fetch';
|
|
2
|
+
import '@orpc/client';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import '@orpc/shared';
|
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/server';
|
|
8
|
+
import 'rou3';
|
|
9
|
+
import '@orpc/openapi-client/standard';
|
|
10
|
+
import '@orpc/server/standard';
|
|
11
|
+
|
|
12
|
+
class OpenAPIHandler extends FetchHandler {
|
|
13
|
+
constructor(router, options = {}) {
|
|
14
|
+
super(new StandardOpenAPIHandler(router, options), options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for Node Server
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
|
2
|
+
import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
|
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
|
4
|
+
import '@orpc/openapi-client/standard';
|
|
5
|
+
import '@orpc/server/standard';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI Handler for Node Server
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
|
12
|
+
*/
|
|
13
|
+
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NodeHttpHandler } from '@orpc/server/node';
|
|
2
|
+
import '@orpc/client';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import '@orpc/shared';
|
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/server';
|
|
8
|
+
import 'rou3';
|
|
9
|
+
import '@orpc/openapi-client/standard';
|
|
10
|
+
import '@orpc/server/standard';
|
|
11
|
+
|
|
12
|
+
class OpenAPIHandler extends NodeHttpHandler {
|
|
13
|
+
constructor(router, options = {}) {
|
|
14
|
+
super(new StandardOpenAPIHandler(router, options), options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { OpenAPIHandler };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
+
export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
|
7
|
+
|
|
8
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
9
|
+
#private;
|
|
10
|
+
private readonly serializer;
|
|
11
|
+
constructor(serializer: StandardOpenAPISerializer);
|
|
12
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
13
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
14
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
18
|
+
private readonly tree;
|
|
19
|
+
private pendingRouters;
|
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* {@link https://github.com/unjs/rou3}
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
34
|
+
|
|
35
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
+
export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
|
7
|
+
|
|
8
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
9
|
+
#private;
|
|
10
|
+
private readonly serializer;
|
|
11
|
+
constructor(serializer: StandardOpenAPISerializer);
|
|
12
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
13
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
14
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
18
|
+
private readonly tree;
|
|
19
|
+
private pendingRouters;
|
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* {@link https://github.com/unjs/rou3}
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
34
|
+
|
|
35
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.C_UtQ8Us.mjs';
|
|
2
|
+
import '@orpc/openapi-client/standard';
|
|
3
|
+
import '@orpc/server/standard';
|
|
4
|
+
import '@orpc/client';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/client/standard';
|
|
8
|
+
import '@orpc/server';
|
|
9
|
+
import 'rou3';
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
|
3
|
+
export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.qZLdpE0a.mjs';
|
|
4
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
5
|
+
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
7
|
+
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
8
|
+
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
9
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
10
|
+
import '@orpc/openapi-client/standard';
|
|
11
|
+
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
13
|
+
/**
|
|
14
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
17
|
+
*/
|
|
18
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
19
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type ObjectSchema = JSONSchema & {
|
|
26
|
+
type: 'object';
|
|
27
|
+
} & object;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
type FileSchema = JSONSchema & {
|
|
32
|
+
type: 'string';
|
|
33
|
+
contentMediaType: string;
|
|
34
|
+
} & object;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
68
|
+
|
|
69
|
+
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*@internal
|
|
73
|
+
*/
|
|
74
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
91
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
92
|
+
/**
|
|
93
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
94
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
95
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
96
|
+
*/
|
|
97
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
98
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
99
|
+
type: 'array';
|
|
100
|
+
items?: JSONSchema;
|
|
101
|
+
}];
|
|
102
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
103
|
+
|
|
104
|
+
declare const oo: {
|
|
105
|
+
spec: typeof customOpenAPIOperation;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
109
|
+
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
|
3
|
+
export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.qZLdpE0a.js';
|
|
4
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
5
|
+
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
7
|
+
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
8
|
+
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
9
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
10
|
+
import '@orpc/openapi-client/standard';
|
|
11
|
+
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
13
|
+
/**
|
|
14
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
17
|
+
*/
|
|
18
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
19
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type ObjectSchema = JSONSchema & {
|
|
26
|
+
type: 'object';
|
|
27
|
+
} & object;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
type FileSchema = JSONSchema & {
|
|
32
|
+
type: 'string';
|
|
33
|
+
contentMediaType: string;
|
|
34
|
+
} & object;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
68
|
+
|
|
69
|
+
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*@internal
|
|
73
|
+
*/
|
|
74
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
91
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
92
|
+
/**
|
|
93
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
94
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
95
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
96
|
+
*/
|
|
97
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
98
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
99
|
+
type: 'array';
|
|
100
|
+
items?: JSONSchema;
|
|
101
|
+
}];
|
|
102
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
103
|
+
|
|
104
|
+
declare const oo: {
|
|
105
|
+
spec: typeof customOpenAPIOperation;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
109
|
+
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { c as customOpenAPIOperation } from './shared/openapi.DaYgbD_w.mjs';
|
|
2
|
+
export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, n as applySchemaOptionality, h as checkParamsSchema, p as expandArrayableSchema, o as expandUnionSchema, m as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, q as isPrimitiveSchema, s as separateObjectSchema, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.DaYgbD_w.mjs';
|
|
3
|
+
import { createORPCErrorFromJson } from '@orpc/client';
|
|
4
|
+
import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
|
5
|
+
import { ORPCError, createRouterClient } from '@orpc/server';
|
|
6
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
7
|
+
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
8
|
+
import '@orpc/client/standard';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
|
|
11
|
+
function createJsonifiedRouterClient(router, ...rest) {
|
|
12
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
13
|
+
const serializer = new StandardOpenAPISerializer(new StandardOpenAPIJsonSerializer(), new StandardBracketNotationSerializer());
|
|
14
|
+
options.interceptors ??= [];
|
|
15
|
+
options.interceptors.unshift(async (options2) => {
|
|
16
|
+
try {
|
|
17
|
+
return serializer.deserialize(
|
|
18
|
+
serializer.serialize(
|
|
19
|
+
await options2.next()
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof ORPCError) {
|
|
24
|
+
throw createORPCErrorFromJson(serializer.deserialize(
|
|
25
|
+
serializer.serialize(
|
|
26
|
+
e.toJSON(),
|
|
27
|
+
{ outputFormat: "plain" }
|
|
28
|
+
)
|
|
29
|
+
));
|
|
30
|
+
}
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return createRouterClient(router, options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const oo = {
|
|
38
|
+
spec: customOpenAPIOperation
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { createJsonifiedRouterClient, customOpenAPIOperation, oo };
|