@orpc/server 0.0.0-next.cba521d → 0.0.0-next.cc8802c
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 +118 -0
- package/dist/adapters/fetch/index.d.mts +26 -0
- package/dist/adapters/fetch/index.d.ts +26 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +19 -0
- package/dist/adapters/hono/index.d.ts +19 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +26 -0
- package/dist/adapters/next/index.d.ts +26 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +34 -0
- package/dist/adapters/node/index.d.ts +34 -0
- package/dist/adapters/node/index.mjs +31 -0
- package/dist/adapters/standard/index.d.mts +25 -0
- package/dist/adapters/standard/index.d.ts +25 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.mjs +343 -0
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.CM3tWr3C.d.mts +75 -0
- package/dist/shared/server.CMrS28Go.mjs +346 -0
- package/dist/shared/server.CPteJIPP.d.mts +143 -0
- package/dist/shared/server.CPteJIPP.d.ts +143 -0
- package/dist/shared/server.CSZRzcSW.mjs +158 -0
- package/dist/shared/server.Cq3B6PoL.mjs +28 -0
- package/dist/shared/server.DmW25ynm.d.ts +75 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/package.json +36 -24
- package/dist/chunk-3EVCPLVI.js +0 -301
- package/dist/chunk-OUPZ7QGV.js +0 -245
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/fetch.js +0 -15
- package/dist/hono.js +0 -30
- package/dist/index.js +0 -562
- package/dist/next.js +0 -36
- package/dist/node.js +0 -87
- package/dist/src/adapters/fetch/index.d.ts +0 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/fetch/types.d.ts +0 -21
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -5
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/builder.d.ts +0 -36
- package/dist/src/error.d.ts +0 -10
- package/dist/src/hidden.d.ts +0 -6
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/index.d.ts +0 -25
- package/dist/src/lazy-decorated.d.ts +0 -7
- 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 -9
- package/dist/src/middleware.d.ts +0 -36
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-client.d.ts +0 -22
- package/dist/src/procedure-decorated.d.ts +0 -26
- package/dist/src/procedure-implementer.d.ts +0 -20
- package/dist/src/procedure-utils.d.ts +0 -17
- package/dist/src/procedure.d.ts +0 -44
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-client.d.ts +0 -26
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/router.d.ts +0 -16
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
package/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
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), 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-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
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
|
+
- [@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
|
+
|
62
|
+
## `@orpc/server`
|
63
|
+
|
64
|
+
Build your API or implement API contract. Read the [documentation](https://orpc.unnoq.com/docs/getting-started) for more information.
|
65
|
+
|
66
|
+
```ts
|
67
|
+
import type { IncomingHttpHeaders } from 'node:http'
|
68
|
+
import { ORPCError, os } from '@orpc/server'
|
69
|
+
import { z } from 'zod'
|
70
|
+
|
71
|
+
const PlanetSchema = z.object({
|
72
|
+
id: z.number().int().min(1),
|
73
|
+
name: z.string(),
|
74
|
+
description: z.string().optional(),
|
75
|
+
})
|
76
|
+
|
77
|
+
export const listPlanet = os
|
78
|
+
.input(
|
79
|
+
z.object({
|
80
|
+
limit: z.number().int().min(1).max(100).optional(),
|
81
|
+
cursor: z.number().int().min(0).default(0),
|
82
|
+
}),
|
83
|
+
)
|
84
|
+
.handler(async ({ input }) => {
|
85
|
+
// your list code here
|
86
|
+
return [{ id: 1, name: 'name' }]
|
87
|
+
})
|
88
|
+
|
89
|
+
export const findPlanet = os
|
90
|
+
.input(PlanetSchema.pick({ id: true }))
|
91
|
+
.handler(async ({ input }) => {
|
92
|
+
// your find code here
|
93
|
+
return { id: 1, name: 'name' }
|
94
|
+
})
|
95
|
+
|
96
|
+
export const createPlanet = os
|
97
|
+
.$context<{ headers: IncomingHttpHeaders }>()
|
98
|
+
.use(({ context, next }) => {
|
99
|
+
const user = parseJWT(context.headers.authorization?.split(' ')[1])
|
100
|
+
|
101
|
+
if (user) {
|
102
|
+
return next({ context: { user } })
|
103
|
+
}
|
104
|
+
|
105
|
+
throw new ORPCError('UNAUTHORIZED')
|
106
|
+
})
|
107
|
+
.input(PlanetSchema.omit({ id: true }))
|
108
|
+
.handler(async ({ input, context }) => {
|
109
|
+
// your create code here
|
110
|
+
return { id: 1, name: 'name' }
|
111
|
+
})
|
112
|
+
|
113
|
+
export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
|
114
|
+
```
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CPteJIPP.mjs';
|
4
|
+
import { S as StandardHandleOptions, b as StandardHandlerOptions } from '../../shared/server.CM3tWr3C.mjs';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import '@orpc/standard-server';
|
8
|
+
|
9
|
+
type FetchHandleResult = {
|
10
|
+
matched: true;
|
11
|
+
response: Response;
|
12
|
+
} | {
|
13
|
+
matched: false;
|
14
|
+
response: undefined;
|
15
|
+
};
|
16
|
+
interface FetchHandler<T extends Context> {
|
17
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
18
|
+
}
|
19
|
+
|
20
|
+
declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
21
|
+
private readonly standardHandler;
|
22
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
23
|
+
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
24
|
+
}
|
25
|
+
|
26
|
+
export { type FetchHandleResult, type FetchHandler, RPCHandler };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CPteJIPP.js';
|
4
|
+
import { S as StandardHandleOptions, b as StandardHandlerOptions } from '../../shared/server.DmW25ynm.js';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import '@orpc/standard-server';
|
8
|
+
|
9
|
+
type FetchHandleResult = {
|
10
|
+
matched: true;
|
11
|
+
response: Response;
|
12
|
+
} | {
|
13
|
+
matched: false;
|
14
|
+
response: undefined;
|
15
|
+
};
|
16
|
+
interface FetchHandler<T extends Context> {
|
17
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
18
|
+
}
|
19
|
+
|
20
|
+
declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
21
|
+
private readonly standardHandler;
|
22
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
23
|
+
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
24
|
+
}
|
25
|
+
|
26
|
+
export { type FetchHandleResult, type FetchHandler, RPCHandler };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export { R as RPCHandler } from '../../shared/server.Cq3B6PoL.mjs';
|
2
|
+
import '@orpc/client/standard';
|
3
|
+
import '@orpc/standard-server-fetch';
|
4
|
+
import '../../shared/server.CSZRzcSW.mjs';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '@orpc/shared';
|
7
|
+
import '../../shared/server.Q6ZmnTgO.mjs';
|
8
|
+
import '../../shared/server.CMrS28Go.mjs';
|
9
|
+
import '@orpc/contract';
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
+
export { FetchHandleResult, 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.CPteJIPP.mjs';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.CM3tWr3C.mjs';
|
7
|
+
import '@orpc/standard-server-fetch';
|
8
|
+
import '@orpc/client';
|
9
|
+
import '@orpc/contract';
|
10
|
+
import '@orpc/standard-server';
|
11
|
+
|
12
|
+
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
13
|
+
context?: Value<T, [Context$1]>;
|
14
|
+
} : {
|
15
|
+
context: Value<T, [Context$1]>;
|
16
|
+
});
|
17
|
+
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
18
|
+
|
19
|
+
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.js';
|
2
|
+
export { FetchHandleResult, 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.CPteJIPP.js';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.DmW25ynm.js';
|
7
|
+
import '@orpc/standard-server-fetch';
|
8
|
+
import '@orpc/client';
|
9
|
+
import '@orpc/contract';
|
10
|
+
import '@orpc/standard-server';
|
11
|
+
|
12
|
+
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
13
|
+
context?: Value<T, [Context$1]>;
|
14
|
+
} : {
|
15
|
+
context: Value<T, [Context$1]>;
|
16
|
+
});
|
17
|
+
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
18
|
+
|
19
|
+
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export { R as RPCHandler } from '../../shared/server.Cq3B6PoL.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
import '@orpc/client/standard';
|
4
|
+
import '@orpc/standard-server-fetch';
|
5
|
+
import '../../shared/server.CSZRzcSW.mjs';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '../../shared/server.Q6ZmnTgO.mjs';
|
8
|
+
import '../../shared/server.CMrS28Go.mjs';
|
9
|
+
import '@orpc/contract';
|
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,26 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
+
export { FetchHandleResult, 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.CPteJIPP.mjs';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.CM3tWr3C.mjs';
|
7
|
+
import '@orpc/standard-server-fetch';
|
8
|
+
import '@orpc/client';
|
9
|
+
import '@orpc/contract';
|
10
|
+
import '@orpc/standard-server';
|
11
|
+
|
12
|
+
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
13
|
+
context?: Value<T, [NextRequest]>;
|
14
|
+
} : {
|
15
|
+
context: Value<T, [NextRequest]>;
|
16
|
+
});
|
17
|
+
interface ServeResult {
|
18
|
+
GET(req: NextRequest): Promise<Response>;
|
19
|
+
POST(req: NextRequest): Promise<Response>;
|
20
|
+
PUT(req: NextRequest): Promise<Response>;
|
21
|
+
PATCH(req: NextRequest): Promise<Response>;
|
22
|
+
DELETE(req: NextRequest): Promise<Response>;
|
23
|
+
}
|
24
|
+
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
25
|
+
|
26
|
+
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { FetchHandler } from '../fetch/index.js';
|
2
|
+
export { FetchHandleResult, 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.CPteJIPP.js';
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.DmW25ynm.js';
|
7
|
+
import '@orpc/standard-server-fetch';
|
8
|
+
import '@orpc/client';
|
9
|
+
import '@orpc/contract';
|
10
|
+
import '@orpc/standard-server';
|
11
|
+
|
12
|
+
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
13
|
+
context?: Value<T, [NextRequest]>;
|
14
|
+
} : {
|
15
|
+
context: Value<T, [NextRequest]>;
|
16
|
+
});
|
17
|
+
interface ServeResult {
|
18
|
+
GET(req: NextRequest): Promise<Response>;
|
19
|
+
POST(req: NextRequest): Promise<Response>;
|
20
|
+
PUT(req: NextRequest): Promise<Response>;
|
21
|
+
PATCH(req: NextRequest): Promise<Response>;
|
22
|
+
DELETE(req: NextRequest): Promise<Response>;
|
23
|
+
}
|
24
|
+
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
25
|
+
|
26
|
+
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export { R as RPCHandler } from '../../shared/server.Cq3B6PoL.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
import '@orpc/client/standard';
|
4
|
+
import '@orpc/standard-server-fetch';
|
5
|
+
import '../../shared/server.CSZRzcSW.mjs';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '../../shared/server.Q6ZmnTgO.mjs';
|
8
|
+
import '../../shared/server.CMrS28Go.mjs';
|
9
|
+
import '@orpc/contract';
|
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,34 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CPteJIPP.mjs';
|
4
|
+
import { S as StandardHandleOptions, b as StandardHandlerOptions } from '../../shared/server.CM3tWr3C.mjs';
|
5
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
6
|
+
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
|
11
|
+
type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
12
|
+
/**
|
13
|
+
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
14
|
+
* This is useful for `express.js` middleware.
|
15
|
+
*/
|
16
|
+
originalUrl?: string;
|
17
|
+
};
|
18
|
+
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
19
|
+
type NodeHttpHandleResult = {
|
20
|
+
matched: true;
|
21
|
+
} | {
|
22
|
+
matched: false;
|
23
|
+
};
|
24
|
+
interface NodeHttpHandler<T extends Context> {
|
25
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
26
|
+
}
|
27
|
+
|
28
|
+
declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
29
|
+
private readonly standardHandler;
|
30
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
31
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
32
|
+
}
|
33
|
+
|
34
|
+
export { type NodeHttpHandleResult, type NodeHttpHandler, type NodeHttpRequest, type NodeHttpResponse, RPCHandler };
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CPteJIPP.js';
|
4
|
+
import { S as StandardHandleOptions, b as StandardHandlerOptions } from '../../shared/server.DmW25ynm.js';
|
5
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
6
|
+
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
|
11
|
+
type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
12
|
+
/**
|
13
|
+
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
14
|
+
* This is useful for `express.js` middleware.
|
15
|
+
*/
|
16
|
+
originalUrl?: string;
|
17
|
+
};
|
18
|
+
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
19
|
+
type NodeHttpHandleResult = {
|
20
|
+
matched: true;
|
21
|
+
} | {
|
22
|
+
matched: false;
|
23
|
+
};
|
24
|
+
interface NodeHttpHandler<T extends Context> {
|
25
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
26
|
+
}
|
27
|
+
|
28
|
+
declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
29
|
+
private readonly standardHandler;
|
30
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardHandlerOptions<T>>);
|
31
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
32
|
+
}
|
33
|
+
|
34
|
+
export { type NodeHttpHandleResult, type NodeHttpHandler, type NodeHttpRequest, type NodeHttpResponse, RPCHandler };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { RPCSerializer } from '@orpc/client/standard';
|
2
|
+
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
3
|
+
import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from '../../shared/server.CSZRzcSW.mjs';
|
4
|
+
import '@orpc/client';
|
5
|
+
import '@orpc/shared';
|
6
|
+
import '../../shared/server.Q6ZmnTgO.mjs';
|
7
|
+
import '../../shared/server.CMrS28Go.mjs';
|
8
|
+
import '@orpc/contract';
|
9
|
+
|
10
|
+
class RPCHandler {
|
11
|
+
standardHandler;
|
12
|
+
constructor(router, options = {}) {
|
13
|
+
const serializer = new RPCSerializer();
|
14
|
+
const matcher = new RPCMatcher();
|
15
|
+
const codec = new RPCCodec(serializer);
|
16
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
17
|
+
}
|
18
|
+
async handle(req, res, ...[
|
19
|
+
options = {}
|
20
|
+
]) {
|
21
|
+
const standardRequest = toStandardLazyRequest(req, res);
|
22
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
23
|
+
if (!result.matched) {
|
24
|
+
return { matched: false };
|
25
|
+
}
|
26
|
+
await sendStandardResponse(res, result.response, options);
|
27
|
+
return { matched: true };
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
export { RPCHandler };
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.CM3tWr3C.mjs';
|
2
|
+
export { S as StandardHandleOptions, g as StandardHandleResult, h as StandardHandler, a as StandardHandlerInterceptorOptions, b as StandardHandlerOptions } from '../../shared/server.CM3tWr3C.mjs';
|
3
|
+
import { ORPCError } from '@orpc/client';
|
4
|
+
import { RPCSerializer } from '@orpc/client/standard';
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
+
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.CPteJIPP.mjs';
|
7
|
+
import { HTTPPath } from '@orpc/contract';
|
8
|
+
import '@orpc/shared';
|
9
|
+
|
10
|
+
declare class RPCCodec implements StandardCodec {
|
11
|
+
private readonly serializer;
|
12
|
+
constructor(serializer: RPCSerializer);
|
13
|
+
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
14
|
+
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
15
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class RPCMatcher implements StandardMatcher {
|
19
|
+
private readonly tree;
|
20
|
+
private pendingRouters;
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
export { RPCCodec, RPCMatcher, StandardCodec, StandardMatchResult, StandardMatcher, StandardParams };
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.DmW25ynm.js';
|
2
|
+
export { S as StandardHandleOptions, g as StandardHandleResult, h as StandardHandler, a as StandardHandlerInterceptorOptions, b as StandardHandlerOptions } from '../../shared/server.DmW25ynm.js';
|
3
|
+
import { ORPCError } from '@orpc/client';
|
4
|
+
import { RPCSerializer } from '@orpc/client/standard';
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
+
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.CPteJIPP.js';
|
7
|
+
import { HTTPPath } from '@orpc/contract';
|
8
|
+
import '@orpc/shared';
|
9
|
+
|
10
|
+
declare class RPCCodec implements StandardCodec {
|
11
|
+
private readonly serializer;
|
12
|
+
constructor(serializer: RPCSerializer);
|
13
|
+
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
14
|
+
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
15
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class RPCMatcher implements StandardMatcher {
|
19
|
+
private readonly tree;
|
20
|
+
private pendingRouters;
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
export { RPCCodec, RPCMatcher, StandardCodec, StandardMatchResult, StandardMatcher, StandardParams };
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export { R as RPCCodec, a as RPCMatcher, S as StandardHandler } from '../../shared/server.CSZRzcSW.mjs';
|
2
|
+
import '@orpc/client';
|
3
|
+
import '@orpc/shared';
|
4
|
+
import '../../shared/server.Q6ZmnTgO.mjs';
|
5
|
+
import '../../shared/server.CMrS28Go.mjs';
|
6
|
+
import '@orpc/contract';
|