@orpc/server 0.0.0-next.c29cb6d → 0.0.0-next.c40d0c9
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 +131 -0
- package/dist/adapters/fetch/index.d.mts +54 -0
- package/dist/adapters/fetch/index.d.ts +54 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +22 -0
- package/dist/adapters/hono/index.d.ts +22 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +29 -0
- package/dist/adapters/next/index.d.ts +29 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +53 -0
- package/dist/adapters/node/index.d.ts +53 -0
- package/dist/adapters/node/index.mjs +85 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/index.mjs +363 -0
- package/dist/plugins/index.d.mts +30 -0
- package/dist/plugins/index.d.ts +30 -0
- package/dist/plugins/index.mjs +107 -0
- package/dist/shared/server.B77ImKAP.d.mts +8 -0
- package/dist/shared/server.BHlRCrf_.d.ts +66 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.Cud5qk0c.d.ts +10 -0
- package/dist/shared/server.CzxlqYZL.d.mts +66 -0
- package/dist/shared/server.DCCkTG29.mjs +162 -0
- package/dist/shared/server.DGnN7q3R.d.mts +10 -0
- package/dist/shared/server.DLt5njUb.d.mts +143 -0
- package/dist/shared/server.DLt5njUb.d.ts +143 -0
- package/dist/shared/server.DUF89eb-.d.ts +8 -0
- package/dist/shared/server.Prfzu_zf.mjs +98 -0
- package/dist/shared/server.e3W6AG3-.mjs +370 -0
- package/package.json +43 -15
- package/dist/chunk-YAVPFNPF.js +0 -182
- package/dist/fetch.js +0 -286
- package/dist/index.js +0 -518
- package/dist/src/builder.d.ts +0 -35
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/index.d.ts +0 -6
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/orpc-payload-codec.d.ts +0 -9
- package/dist/src/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/fetch/super-json.d.ts +0 -12
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/hidden.d.ts +0 -6
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/index.d.ts +0 -23
- package/dist/src/lazy-decorated.d.ts +0 -10
- package/dist/src/lazy-utils.d.ts +0 -4
- package/dist/src/lazy.d.ts +0 -18
- package/dist/src/middleware-decorated.d.ts +0 -8
- package/dist/src/middleware.d.ts +0 -23
- package/dist/src/procedure-builder.d.ts +0 -22
- package/dist/src/procedure-client.d.ts +0 -34
- package/dist/src/procedure-decorated.d.ts +0 -14
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/procedure.d.ts +0 -23
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-client.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/router.d.ts +0 -16
- package/dist/src/types.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -3
package/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
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/server">
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fserver?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, ensuring a smooth and enjoyable developer experience.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
29
|
+
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
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, Svelte), Pinia Colada, and more.
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
46
|
+
|
47
|
+
## Documentation
|
48
|
+
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
50
|
+
|
51
|
+
## Packages
|
52
|
+
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
57
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
58
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
59
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
60
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
61
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
62
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
63
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
64
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
65
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
66
|
+
|
67
|
+
## `@orpc/server`
|
68
|
+
|
69
|
+
Build your API or implement API contract. Read the [documentation](https://orpc.unnoq.com/docs/getting-started) for more information.
|
70
|
+
|
71
|
+
```ts
|
72
|
+
import type { IncomingHttpHeaders } from 'node:http'
|
73
|
+
import { ORPCError, os } from '@orpc/server'
|
74
|
+
import { z } from 'zod'
|
75
|
+
|
76
|
+
const PlanetSchema = z.object({
|
77
|
+
id: z.number().int().min(1),
|
78
|
+
name: z.string(),
|
79
|
+
description: z.string().optional(),
|
80
|
+
})
|
81
|
+
|
82
|
+
export const listPlanet = os
|
83
|
+
.input(
|
84
|
+
z.object({
|
85
|
+
limit: z.number().int().min(1).max(100).optional(),
|
86
|
+
cursor: z.number().int().min(0).default(0),
|
87
|
+
}),
|
88
|
+
)
|
89
|
+
.handler(async ({ input }) => {
|
90
|
+
// your list code here
|
91
|
+
return [{ id: 1, name: 'name' }]
|
92
|
+
})
|
93
|
+
|
94
|
+
export const findPlanet = os
|
95
|
+
.input(PlanetSchema.pick({ id: true }))
|
96
|
+
.handler(async ({ input }) => {
|
97
|
+
// your find code here
|
98
|
+
return { id: 1, name: 'name' }
|
99
|
+
})
|
100
|
+
|
101
|
+
export const createPlanet = os
|
102
|
+
.$context<{ headers: IncomingHttpHeaders }>()
|
103
|
+
.use(({ context, next }) => {
|
104
|
+
const user = parseJWT(context.headers.authorization?.split(' ')[1])
|
105
|
+
|
106
|
+
if (user) {
|
107
|
+
return next({ context: { user } })
|
108
|
+
}
|
109
|
+
|
110
|
+
throw new ORPCError('UNAUTHORIZED')
|
111
|
+
})
|
112
|
+
.input(PlanetSchema.omit({ id: true }))
|
113
|
+
.handler(async ({ input, context }) => {
|
114
|
+
// your create code here
|
115
|
+
return { id: 1, name: 'name' }
|
116
|
+
})
|
117
|
+
|
118
|
+
export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
|
119
|
+
```
|
120
|
+
|
121
|
+
## Sponsors
|
122
|
+
|
123
|
+
<p align="center">
|
124
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
125
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
126
|
+
</a>
|
127
|
+
</p>
|
128
|
+
|
129
|
+
## License
|
130
|
+
|
131
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DLt5njUb.mjs';
|
2
|
+
import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.CzxlqYZL.mjs';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.DGnN7q3R.mjs';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.B77ImKAP.mjs';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
type FetchHandleResult = {
|
13
|
+
matched: true;
|
14
|
+
response: Response;
|
15
|
+
} | {
|
16
|
+
matched: false;
|
17
|
+
response: undefined;
|
18
|
+
};
|
19
|
+
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
20
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
21
|
+
}
|
22
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
23
|
+
request: Request;
|
24
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
25
|
+
}
|
26
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
27
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, ThrowableError>[];
|
28
|
+
plugins?: FetchHandlerPlugin<T>[];
|
29
|
+
}
|
30
|
+
declare class FetchHandler<T extends Context> {
|
31
|
+
private readonly standardHandler;
|
32
|
+
private readonly toFetchResponseOptions;
|
33
|
+
private readonly adapterInterceptors;
|
34
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
35
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
|
+
}
|
37
|
+
|
38
|
+
interface BodyLimitPluginOptions {
|
39
|
+
/**
|
40
|
+
* The maximum size of the body in bytes.
|
41
|
+
*/
|
42
|
+
maxBodySize: number;
|
43
|
+
}
|
44
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
45
|
+
private readonly maxBodySize;
|
46
|
+
constructor(options: BodyLimitPluginOptions);
|
47
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
48
|
+
}
|
49
|
+
|
50
|
+
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
51
|
+
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
52
|
+
}
|
53
|
+
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DLt5njUb.js';
|
2
|
+
import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.BHlRCrf_.js';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.Cud5qk0c.js';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DUF89eb-.js';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
type FetchHandleResult = {
|
13
|
+
matched: true;
|
14
|
+
response: Response;
|
15
|
+
} | {
|
16
|
+
matched: false;
|
17
|
+
response: undefined;
|
18
|
+
};
|
19
|
+
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
20
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
21
|
+
}
|
22
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
23
|
+
request: Request;
|
24
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
25
|
+
}
|
26
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
27
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, ThrowableError>[];
|
28
|
+
plugins?: FetchHandlerPlugin<T>[];
|
29
|
+
}
|
30
|
+
declare class FetchHandler<T extends Context> {
|
31
|
+
private readonly standardHandler;
|
32
|
+
private readonly toFetchResponseOptions;
|
33
|
+
private readonly adapterInterceptors;
|
34
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
35
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
|
+
}
|
37
|
+
|
38
|
+
interface BodyLimitPluginOptions {
|
39
|
+
/**
|
40
|
+
* The maximum size of the body in bytes.
|
41
|
+
*/
|
42
|
+
maxBodySize: number;
|
43
|
+
}
|
44
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
45
|
+
private readonly maxBodySize;
|
46
|
+
constructor(options: BodyLimitPluginOptions);
|
47
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
48
|
+
}
|
49
|
+
|
50
|
+
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
51
|
+
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
52
|
+
}
|
53
|
+
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Prfzu_zf.mjs';
|
2
|
+
import '@orpc/client';
|
3
|
+
import '@orpc/client/standard';
|
4
|
+
import '../../shared/server.DCCkTG29.mjs';
|
5
|
+
import '@orpc/shared';
|
6
|
+
import '../../shared/server.e3W6AG3-.mjs';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
|
+
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
|
+
import { C as Context } from '../../shared/server.DLt5njUb.mjs';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.CzxlqYZL.mjs';
|
7
|
+
import '../../shared/server.DGnN7q3R.mjs';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.B77ImKAP.mjs';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
import '@orpc/client';
|
12
|
+
import '@orpc/contract';
|
13
|
+
import '@orpc/standard-server';
|
14
|
+
|
15
|
+
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
+
context?: Value<T, [Context$1]>;
|
17
|
+
} : {
|
18
|
+
context: Value<T, [Context$1]>;
|
19
|
+
});
|
20
|
+
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
21
|
+
|
22
|
+
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.js';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
|
+
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
|
+
import { C as Context } from '../../shared/server.DLt5njUb.js';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.BHlRCrf_.js';
|
7
|
+
import '../../shared/server.Cud5qk0c.js';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.DUF89eb-.js';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
import '@orpc/client';
|
12
|
+
import '@orpc/contract';
|
13
|
+
import '@orpc/standard-server';
|
14
|
+
|
15
|
+
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
+
context?: Value<T, [Context$1]>;
|
17
|
+
} : {
|
18
|
+
context: Value<T, [Context$1]>;
|
19
|
+
});
|
20
|
+
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
21
|
+
|
22
|
+
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Prfzu_zf.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
import '@orpc/client';
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DCCkTG29.mjs';
|
6
|
+
import '../../shared/server.e3W6AG3-.mjs';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
10
|
+
|
11
|
+
function createMiddleware(handler, ...[options]) {
|
12
|
+
return async (c, next) => {
|
13
|
+
const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
|
14
|
+
const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
|
15
|
+
// https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
|
16
|
+
get(target, prop) {
|
17
|
+
if (bodyProps.has(prop)) {
|
18
|
+
return () => c.req[prop]();
|
19
|
+
}
|
20
|
+
return Reflect.get(target, prop, target);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
const context = await value(options?.context ?? {}, c);
|
24
|
+
const { matched, response } = await handler.handle(request, { ...options, context });
|
25
|
+
if (matched) {
|
26
|
+
return c.newResponse(response.body, response);
|
27
|
+
}
|
28
|
+
await next();
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
export { createMiddleware };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
|
+
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { NextRequest } from 'next/server';
|
5
|
+
import { C as Context } from '../../shared/server.DLt5njUb.mjs';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.CzxlqYZL.mjs';
|
7
|
+
import '../../shared/server.DGnN7q3R.mjs';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.B77ImKAP.mjs';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
import '@orpc/client';
|
12
|
+
import '@orpc/contract';
|
13
|
+
import '@orpc/standard-server';
|
14
|
+
|
15
|
+
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
+
context?: Value<T, [NextRequest]>;
|
17
|
+
} : {
|
18
|
+
context: Value<T, [NextRequest]>;
|
19
|
+
});
|
20
|
+
interface ServeResult {
|
21
|
+
GET(req: NextRequest): Promise<Response>;
|
22
|
+
POST(req: NextRequest): Promise<Response>;
|
23
|
+
PUT(req: NextRequest): Promise<Response>;
|
24
|
+
PATCH(req: NextRequest): Promise<Response>;
|
25
|
+
DELETE(req: NextRequest): Promise<Response>;
|
26
|
+
}
|
27
|
+
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
28
|
+
|
29
|
+
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.js';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
|
+
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { NextRequest } from 'next/server';
|
5
|
+
import { C as Context } from '../../shared/server.DLt5njUb.js';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.BHlRCrf_.js';
|
7
|
+
import '../../shared/server.Cud5qk0c.js';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.DUF89eb-.js';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
import '@orpc/client';
|
12
|
+
import '@orpc/contract';
|
13
|
+
import '@orpc/standard-server';
|
14
|
+
|
15
|
+
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
+
context?: Value<T, [NextRequest]>;
|
17
|
+
} : {
|
18
|
+
context: Value<T, [NextRequest]>;
|
19
|
+
});
|
20
|
+
interface ServeResult {
|
21
|
+
GET(req: NextRequest): Promise<Response>;
|
22
|
+
POST(req: NextRequest): Promise<Response>;
|
23
|
+
PUT(req: NextRequest): Promise<Response>;
|
24
|
+
PATCH(req: NextRequest): Promise<Response>;
|
25
|
+
DELETE(req: NextRequest): Promise<Response>;
|
26
|
+
}
|
27
|
+
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
28
|
+
|
29
|
+
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Prfzu_zf.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
import '@orpc/client';
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DCCkTG29.mjs';
|
6
|
+
import '../../shared/server.e3W6AG3-.mjs';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
10
|
+
|
11
|
+
function serve(handler, ...[options]) {
|
12
|
+
const main = async (req) => {
|
13
|
+
const context = await value(options?.context ?? {}, req);
|
14
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
15
|
+
if (matched) {
|
16
|
+
return response;
|
17
|
+
}
|
18
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
19
|
+
};
|
20
|
+
return {
|
21
|
+
GET: main,
|
22
|
+
POST: main,
|
23
|
+
PUT: main,
|
24
|
+
PATCH: main,
|
25
|
+
DELETE: main
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
export { serve };
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DLt5njUb.mjs';
|
2
|
+
import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.CzxlqYZL.mjs';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.DGnN7q3R.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.B77ImKAP.mjs';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
type NodeHttpHandleResult = {
|
13
|
+
matched: true;
|
14
|
+
} | {
|
15
|
+
matched: false;
|
16
|
+
};
|
17
|
+
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
|
+
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
19
|
+
}
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
25
|
+
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, ThrowableError>[];
|
27
|
+
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
|
+
}
|
29
|
+
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
30
|
+
private readonly standardHandler;
|
31
|
+
private readonly sendStandardResponseOptions;
|
32
|
+
private readonly adapterInterceptors;
|
33
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
34
|
+
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
|
+
}
|
36
|
+
|
37
|
+
interface BodyLimitPluginOptions {
|
38
|
+
/**
|
39
|
+
* The maximum size of the body in bytes.
|
40
|
+
*/
|
41
|
+
maxBodySize: number;
|
42
|
+
}
|
43
|
+
declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
44
|
+
private readonly maxBodySize;
|
45
|
+
constructor(options: BodyLimitPluginOptions);
|
46
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
47
|
+
}
|
48
|
+
|
49
|
+
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
50
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
51
|
+
}
|
52
|
+
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DLt5njUb.js';
|
2
|
+
import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.BHlRCrf_.js';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.Cud5qk0c.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DUF89eb-.js';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
type NodeHttpHandleResult = {
|
13
|
+
matched: true;
|
14
|
+
} | {
|
15
|
+
matched: false;
|
16
|
+
};
|
17
|
+
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
|
+
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
19
|
+
}
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
25
|
+
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, ThrowableError>[];
|
27
|
+
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
|
+
}
|
29
|
+
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
30
|
+
private readonly standardHandler;
|
31
|
+
private readonly sendStandardResponseOptions;
|
32
|
+
private readonly adapterInterceptors;
|
33
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
34
|
+
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
|
+
}
|
36
|
+
|
37
|
+
interface BodyLimitPluginOptions {
|
38
|
+
/**
|
39
|
+
* The maximum size of the body in bytes.
|
40
|
+
*/
|
41
|
+
maxBodySize: number;
|
42
|
+
}
|
43
|
+
declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
44
|
+
private readonly maxBodySize;
|
45
|
+
constructor(options: BodyLimitPluginOptions);
|
46
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
47
|
+
}
|
48
|
+
|
49
|
+
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
50
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
51
|
+
}
|
52
|
+
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BVwwTHyO.mjs';
|
5
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
6
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from '../../shared/server.DCCkTG29.mjs';
|
7
|
+
import '../../shared/server.e3W6AG3-.mjs';
|
8
|
+
import '@orpc/contract';
|
9
|
+
|
10
|
+
class BodyLimitPlugin {
|
11
|
+
maxBodySize;
|
12
|
+
constructor(options) {
|
13
|
+
this.maxBodySize = options.maxBodySize;
|
14
|
+
}
|
15
|
+
initRuntimeAdapter(options) {
|
16
|
+
options.adapterInterceptors ??= [];
|
17
|
+
options.adapterInterceptors.push(async (options2) => {
|
18
|
+
let isHeaderChecked = false;
|
19
|
+
const checkHeader = () => {
|
20
|
+
if (!isHeaderChecked && Number(options2.request.headers["content-length"]) > this.maxBodySize) {
|
21
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
22
|
+
}
|
23
|
+
isHeaderChecked = true;
|
24
|
+
};
|
25
|
+
const originalEmit = options2.request.emit.bind(options2.request);
|
26
|
+
let currentBodySize = 0;
|
27
|
+
options2.request.emit = (event, ...args) => {
|
28
|
+
if (event === "data") {
|
29
|
+
checkHeader();
|
30
|
+
currentBodySize += args[0].length;
|
31
|
+
if (currentBodySize > this.maxBodySize) {
|
32
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return originalEmit(event, ...args);
|
36
|
+
};
|
37
|
+
return options2.next();
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
class NodeHttpHandler {
|
43
|
+
constructor(standardHandler, options = {}) {
|
44
|
+
this.standardHandler = standardHandler;
|
45
|
+
for (const plugin of toArray(options.plugins)) {
|
46
|
+
plugin.initRuntimeAdapter?.(options);
|
47
|
+
}
|
48
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
49
|
+
this.sendStandardResponseOptions = options;
|
50
|
+
}
|
51
|
+
sendStandardResponseOptions;
|
52
|
+
adapterInterceptors;
|
53
|
+
async handle(request, response, ...rest) {
|
54
|
+
return intercept(
|
55
|
+
this.adapterInterceptors,
|
56
|
+
{
|
57
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
58
|
+
request,
|
59
|
+
response,
|
60
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
61
|
+
},
|
62
|
+
async ({ request: request2, response: response2, sendStandardResponseOptions, ...options }) => {
|
63
|
+
const standardRequest = toStandardLazyRequest(request2, response2);
|
64
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
65
|
+
if (!result.matched) {
|
66
|
+
return { matched: false };
|
67
|
+
}
|
68
|
+
await sendStandardResponse(response2, result.response, sendStandardResponseOptions);
|
69
|
+
return { matched: true };
|
70
|
+
}
|
71
|
+
);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
class RPCHandler extends NodeHttpHandler {
|
76
|
+
constructor(router, options = {}) {
|
77
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
78
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
79
|
+
const matcher = new StandardRPCMatcher();
|
80
|
+
const codec = new StandardRPCCodec(serializer);
|
81
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
export { BodyLimitPlugin, NodeHttpHandler, RPCHandler };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.CzxlqYZL.mjs';
|
2
|
+
export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.CzxlqYZL.mjs';
|
3
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
|
+
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
+
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.DLt5njUb.mjs';
|
7
|
+
export { S as StandardRPCHandlerOptions } from '../../shared/server.B77ImKAP.mjs';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/shared';
|
10
|
+
|
11
|
+
declare class StandardRPCCodec implements StandardCodec {
|
12
|
+
private readonly serializer;
|
13
|
+
constructor(serializer: StandardRPCSerializer);
|
14
|
+
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
15
|
+
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
16
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
17
|
+
}
|
18
|
+
|
19
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
20
|
+
private readonly tree;
|
21
|
+
private pendingRouters;
|
22
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
23
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
24
|
+
}
|
25
|
+
|
26
|
+
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|