@orpc/server 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/adapters/aws-lambda/handler.d.mts +25 -0
- package/dist/adapters/aws-lambda/handler.mjs +21 -0
- package/dist/adapters/aws-lambda/index.d.mts +14 -49
- package/dist/adapters/aws-lambda/index.mjs +2 -39
- package/dist/adapters/aws-lambda/rpc-handler.d.mts +18 -0
- package/dist/adapters/aws-lambda/rpc-handler.mjs +10 -0
- package/dist/adapters/crossws/handler.d.mts +41 -0
- package/dist/adapters/crossws/handler.mjs +38 -0
- package/dist/adapters/crossws/index.d.mts +2 -63
- package/dist/adapters/crossws/index.mjs +2 -68
- package/dist/adapters/crossws/rpc-handler.d.mts +15 -0
- package/dist/adapters/crossws/rpc-handler.mjs +10 -0
- package/dist/adapters/fastify/handler.d.mts +21 -0
- package/dist/adapters/fastify/handler.mjs +20 -0
- package/dist/adapters/fastify/index.d.mts +2 -42
- package/dist/adapters/fastify/index.mjs +2 -39
- package/dist/adapters/fastify/rpc-handler.d.mts +14 -0
- package/dist/adapters/fastify/rpc-handler.mjs +10 -0
- package/dist/adapters/fetch/handler.d.mts +23 -0
- package/dist/adapters/fetch/handler.mjs +22 -0
- package/dist/adapters/fetch/index.d.mts +6 -46
- package/dist/adapters/fetch/index.mjs +4 -41
- package/dist/adapters/fetch/rpc-handler.d.mts +16 -0
- package/dist/adapters/fetch/rpc-handler.mjs +10 -0
- package/dist/adapters/message-port/handler.d.mts +57 -0
- package/dist/adapters/message-port/handler.mjs +62 -0
- package/dist/adapters/message-port/index.d.mts +2 -77
- package/dist/adapters/message-port/index.mjs +2 -87
- package/dist/adapters/message-port/rpc-handler.d.mts +15 -0
- package/dist/adapters/message-port/rpc-handler.mjs +10 -0
- package/dist/adapters/node/handler.d.mts +21 -0
- package/dist/adapters/node/handler.mjs +20 -0
- package/dist/adapters/node/index.d.mts +6 -43
- package/dist/adapters/node/index.mjs +4 -40
- package/dist/adapters/node/rpc-handler.d.mts +15 -0
- package/dist/adapters/node/rpc-handler.mjs +10 -0
- package/dist/adapters/standard/codec.d.mts +16 -0
- package/dist/adapters/standard/codec.mjs +1 -0
- package/dist/adapters/standard/handler.d.mts +68 -0
- package/dist/adapters/standard/handler.mjs +185 -0
- package/dist/adapters/standard/index.d.mts +6 -95
- package/dist/adapters/standard/index.mjs +5 -8
- package/dist/adapters/standard/plugin.d.mts +32 -0
- package/dist/adapters/standard/plugin.mjs +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.mts +42 -0
- package/dist/adapters/standard/rpc-handler-codec.mjs +51 -0
- package/dist/adapters/standard/rpc-matcher.d.mts +53 -0
- package/dist/adapters/standard/rpc-matcher.mjs +140 -0
- package/dist/adapters/standard/utils.d.mts +10 -0
- package/dist/adapters/standard/utils.mjs +6 -0
- package/dist/adapters/standard-peer/index.d.mts +1 -11
- package/dist/adapters/standard-peer/index.mjs +1 -10
- package/dist/adapters/standard-peer/utils.d.mts +4 -0
- package/dist/adapters/standard-peer/utils.mjs +11 -0
- package/dist/adapters/websocket/handler.d.mts +55 -0
- package/dist/adapters/websocket/handler.mjs +55 -0
- package/dist/adapters/websocket/index.d.mts +2 -77
- package/dist/adapters/websocket/index.mjs +2 -87
- package/dist/adapters/websocket/rpc-handler.d.mts +15 -0
- package/dist/adapters/websocket/rpc-handler.mjs +10 -0
- package/dist/builder-variants.d.mts +267 -0
- package/dist/builder-variants.mjs +1 -0
- package/dist/builder.d.mts +141 -0
- package/dist/builder.mjs +145 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.mjs +2 -0
- package/dist/context.d.mts +13 -0
- package/dist/context.mjs +1 -0
- package/dist/extensions/callable.d.mts +16 -9
- package/dist/extensions/callable.mjs +5 -9
- package/dist/helpers/base64url.d.mts +31 -0
- package/dist/helpers/base64url.mjs +25 -0
- package/dist/helpers/cookie.d.mts +50 -0
- package/dist/helpers/cookie.mjs +35 -0
- package/dist/helpers/encryption.d.mts +28 -0
- package/dist/helpers/encryption.mjs +62 -0
- package/dist/helpers/index.d.mts +4 -167
- package/dist/helpers/index.mjs +4 -200
- package/dist/helpers/signing.d.mts +50 -0
- package/dist/helpers/signing.mjs +43 -0
- package/dist/implementer-procedure.d.mts +36 -0
- package/dist/implementer-procedure.mjs +38 -0
- package/dist/implementer-router.d.mts +78 -0
- package/dist/implementer-router.mjs +77 -0
- package/dist/implementer.d.mts +22 -0
- package/dist/implementer.mjs +30 -0
- package/dist/index.d.mts +57 -476
- package/dist/index.mjs +25 -458
- package/dist/lazy.d.mts +20 -0
- package/dist/lazy.mjs +22 -0
- package/dist/middleware-decorated.d.mts +27 -0
- package/dist/middleware-decorated.mjs +65 -0
- package/dist/middleware.d.mts +70 -0
- package/dist/middleware.mjs +1 -0
- package/dist/plugins/batch.d.mts +104 -0
- package/dist/plugins/batch.mjs +373 -0
- package/dist/plugins/cors.d.mts +67 -0
- package/dist/plugins/cors.mjs +134 -0
- package/dist/plugins/get-method-csrf-protection.d.mts +23 -0
- package/dist/plugins/get-method-csrf-protection.mjs +45 -0
- package/dist/plugins/head-method.d.mts +23 -0
- package/dist/plugins/head-method.mjs +95 -0
- package/dist/plugins/index.d.mts +39 -432
- package/dist/plugins/index.mjs +23 -967
- package/dist/plugins/method-override.d.mts +38 -0
- package/dist/plugins/method-override.mjs +50 -0
- package/dist/plugins/request-compression.d.mts +16 -0
- package/dist/plugins/request-compression.mjs +67 -0
- package/dist/plugins/request-headers.d.mts +22 -0
- package/dist/plugins/request-headers.mjs +21 -0
- package/dist/plugins/request-limit.d.mts +30 -0
- package/dist/plugins/request-limit.mjs +53 -0
- package/dist/plugins/response-compression.d.mts +59 -0
- package/dist/plugins/response-compression.mjs +172 -0
- package/dist/plugins/response-headers.d.mts +30 -0
- package/dist/plugins/response-headers.mjs +34 -0
- package/dist/plugins/rethrow.d.mts +33 -0
- package/dist/plugins/rethrow.mjs +46 -0
- package/dist/plugins/signal-sync.d.mts +13 -0
- package/dist/plugins/signal-sync.mjs +84 -0
- package/dist/plugins/timeout.d.mts +37 -0
- package/dist/plugins/timeout.mjs +56 -0
- package/dist/procedure-client.d.mts +41 -0
- package/dist/procedure-client.mjs +157 -0
- package/dist/procedure-decorated.d.mts +20 -0
- package/dist/procedure-decorated.mjs +41 -0
- package/dist/procedure-utils.d.mts +52 -0
- package/dist/procedure-utils.mjs +33 -0
- package/dist/procedure.d.mts +93 -0
- package/dist/procedure.mjs +20 -0
- package/dist/router-client.d.mts +27 -0
- package/dist/router-client.mjs +35 -0
- package/dist/router-hidden.d.mts +5 -0
- package/dist/router-hidden.mjs +12 -0
- package/dist/router-utils.d.mts +59 -0
- package/dist/router-utils.mjs +191 -0
- package/dist/router.d.mts +61 -0
- package/dist/router.mjs +1 -0
- package/package.json +11 -11
- package/dist/adapters/aws-lambda/index.d.ts +0 -51
- package/dist/adapters/crossws/index.d.ts +0 -63
- package/dist/adapters/fastify/index.d.ts +0 -42
- package/dist/adapters/fetch/index.d.ts +0 -47
- package/dist/adapters/message-port/index.d.ts +0 -77
- package/dist/adapters/node/index.d.ts +0 -44
- package/dist/adapters/standard/index.d.ts +0 -95
- package/dist/adapters/standard-peer/index.d.ts +0 -11
- package/dist/adapters/websocket/index.d.ts +0 -77
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/helpers/index.d.ts +0 -167
- package/dist/index.d.ts +0 -476
- package/dist/plugins/index.d.ts +0 -432
- package/dist/shared/server.1ExWFMze.mjs +0 -69
- package/dist/shared/server.9B1jEm5a.d.mts +0 -105
- package/dist/shared/server.BB464y-6.mjs +0 -207
- package/dist/shared/server.BC5BIu02.d.mts +0 -73
- package/dist/shared/server.BSYGskId.d.ts +0 -14
- package/dist/shared/server.BvG3boBj.d.mts +0 -14
- package/dist/shared/server.CTV_mC2P.d.mts +0 -34
- package/dist/shared/server.CYbIpHbH.mjs +0 -239
- package/dist/shared/server.CgBF3Vj1.d.ts +0 -34
- package/dist/shared/server.Chq5FpXf.mjs +0 -353
- package/dist/shared/server.DFPxP2v3.d.mts +0 -166
- package/dist/shared/server.DFPxP2v3.d.ts +0 -166
- package/dist/shared/server.DOg7ke6y.d.ts +0 -105
- package/dist/shared/server.Dz7j9BEh.d.ts +0 -73
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.sBQSgqK3.mjs +0 -41
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ClientContext } from "@orpc/client";
|
|
2
|
+
import type { ErrorMap, Schema } from "@orpc/contract";
|
|
3
|
+
import type { MaybeOptionalOptions } from "@orpc/shared";
|
|
4
|
+
import type { Lazyable } from "./lazy.mjs";
|
|
5
|
+
import type { ProcedureClient, ProcedureClientOptions } from "./procedure-client.mjs";
|
|
6
|
+
import type { AnyRouter, InferRouterInitialContext } from "./router.mjs";
|
|
7
|
+
import { Procedure } from "./procedure.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* The client type derived from a router, exposing every procedure as a callable
|
|
10
|
+
* function while preserving the router's shape.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/client/client-side#creating-a-client | Client-Side Clients - Creating a Client}
|
|
13
|
+
*/
|
|
14
|
+
export type RouterClient<
|
|
15
|
+
TRouter extends AnyRouter,
|
|
16
|
+
TClientContext extends ClientContext = object
|
|
17
|
+
> = TRouter extends Procedure<any, any, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureClient<TClientContext, $InputSchema, $OutputSchema, $ErrorMap> : { [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never };
|
|
18
|
+
/**
|
|
19
|
+
* Creates a server-side client that calls the router's procedures directly,
|
|
20
|
+
* within the same process, without any network layer.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link https://orpc.dev/docs/client/server-side#router-clients | Server-Side Clients - Router Clients}
|
|
23
|
+
*/
|
|
24
|
+
export declare function createRouterClient<
|
|
25
|
+
T extends AnyRouter,
|
|
26
|
+
TClientContext extends ClientContext = object
|
|
27
|
+
>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown>, ErrorMap, TClientContext>>): RouterClient<T, TClientContext>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
|
|
2
|
+
import { resolveMaybeOptionalOptions, toArray } from "@orpc/shared";
|
|
3
|
+
import { Lazy } from "./lazy.mjs";
|
|
4
|
+
import { Procedure } from "./procedure.mjs";
|
|
5
|
+
import { createProcedureClient } from "./procedure-client.mjs";
|
|
6
|
+
import { createGuardedProcedureLazy } from "./procedure-utils.mjs";
|
|
7
|
+
import { getRouter } from "./router-utils.mjs";
|
|
8
|
+
|
|
9
|
+
export function createRouterClient(router, ...rest) {
|
|
10
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
11
|
+
if (router instanceof Procedure) {
|
|
12
|
+
return createProcedureClient(router, options);
|
|
13
|
+
}
|
|
14
|
+
const procedureCaller = router instanceof Lazy ? createProcedureClient(createGuardedProcedureLazy(router), options) : {};
|
|
15
|
+
const cache = new Map();
|
|
16
|
+
const recursive = new Proxy(procedureCaller, { get(target, key) {
|
|
17
|
+
if (typeof key !== "string" || router instanceof Lazy && RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
|
|
18
|
+
return Reflect.get(target, key);
|
|
19
|
+
}
|
|
20
|
+
let nextClient = cache.get(key);
|
|
21
|
+
if (nextClient === undefined) {
|
|
22
|
+
const next = getRouter(router, [key]);
|
|
23
|
+
if (!next) {
|
|
24
|
+
return Reflect.get(target, key);
|
|
25
|
+
}
|
|
26
|
+
nextClient = createRouterClient(next, {
|
|
27
|
+
...options,
|
|
28
|
+
path: [...toArray(options.path), key]
|
|
29
|
+
});
|
|
30
|
+
cache.set(key, nextClient);
|
|
31
|
+
}
|
|
32
|
+
return nextClient;
|
|
33
|
+
} });
|
|
34
|
+
return recursive;
|
|
35
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RouterContract } from "@orpc/contract";
|
|
2
|
+
import type { Lazyable } from "./lazy.mjs";
|
|
3
|
+
import type { AnyRouter } from "./router.mjs";
|
|
4
|
+
export declare function withHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: RouterContract): T;
|
|
5
|
+
export declare function getHiddenRouterContract(router: Lazyable<AnyRouter | RouterContract>): RouterContract | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
2
|
+
export function withHiddenRouterContract(router, contract) {
|
|
3
|
+
return new Proxy(router, { get(target, key) {
|
|
4
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
5
|
+
return contract;
|
|
6
|
+
}
|
|
7
|
+
return Reflect.get(target, key);
|
|
8
|
+
} });
|
|
9
|
+
}
|
|
10
|
+
export function getHiddenRouterContract(router) {
|
|
11
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
12
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AnyProcedureContract, AugmentContractRouterOptions, ErrorMap, MergedErrorMap, RouterContract } from "@orpc/contract";
|
|
2
|
+
import type { Promisable } from "@orpc/shared";
|
|
3
|
+
import type { Context, MergedInitialContext } from "./context.mjs";
|
|
4
|
+
import type { Lazyable } from "./lazy.mjs";
|
|
5
|
+
import type { AnyMiddleware } from "./middleware.mjs";
|
|
6
|
+
import type { AnyProcedure, ProcedureConfig } from "./procedure.mjs";
|
|
7
|
+
import type { AnyRouter } from "./router.mjs";
|
|
8
|
+
import { Lazy } from "./lazy.mjs";
|
|
9
|
+
import { Procedure } from "./procedure.mjs";
|
|
10
|
+
export type AugmentedRouter<
|
|
11
|
+
T extends AnyRouter,
|
|
12
|
+
TErrorMap extends ErrorMap
|
|
13
|
+
> = T extends Procedure<infer $InitialContext, infer $CurrentContext, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<$InitialContext, $CurrentContext, $InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $ErrorMap>> : { [K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouter<$, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouter<T[K], TErrorMap> : never };
|
|
14
|
+
export type AugmentedRouterWithMiddlewares<
|
|
15
|
+
T extends AnyRouter,
|
|
16
|
+
TInitialContext extends Context,
|
|
17
|
+
TInjectedContext extends Context,
|
|
18
|
+
TErrorMap extends ErrorMap
|
|
19
|
+
> = T extends Procedure<infer $InitialContext, infer $CurrentContext, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<MergedInitialContext<TInitialContext, TInjectedContext, $InitialContext>, $CurrentContext, $InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $ErrorMap>> : { [K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouterWithMiddlewares<$, TInitialContext, TInjectedContext, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouterWithMiddlewares<T[K], TInitialContext, TInjectedContext, TErrorMap> : never };
|
|
20
|
+
interface AugmentRouterOptions<TErrorMap extends ErrorMap> extends AugmentContractRouterOptions<TErrorMap>, ProcedureConfig {
|
|
21
|
+
middlewares: AnyMiddleware[];
|
|
22
|
+
}
|
|
23
|
+
export declare function augmentRouter<
|
|
24
|
+
T extends AnyRouter,
|
|
25
|
+
TInitialContext extends Context,
|
|
26
|
+
TCurrentContext extends Context,
|
|
27
|
+
TErrorMap extends ErrorMap
|
|
28
|
+
>(router: T, options: AugmentRouterOptions<TErrorMap>): AugmentedRouter<T, TErrorMap> | AugmentedRouterWithMiddlewares<T, TInitialContext, TCurrentContext, TErrorMap>;
|
|
29
|
+
interface AugmentImplementedRouterOptions extends ProcedureConfig {
|
|
30
|
+
middlewares: AnyMiddleware[];
|
|
31
|
+
}
|
|
32
|
+
export declare function augmentImplementedRouter<
|
|
33
|
+
T extends AnyRouter,
|
|
34
|
+
TInitialContext extends Context,
|
|
35
|
+
TCurrentContext extends Context
|
|
36
|
+
>(router: T, options: AugmentImplementedRouterOptions): AugmentedRouter<T, object> | AugmentedRouterWithMiddlewares<T, TInitialContext, TCurrentContext, object>;
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the procedure of a contract walked from a router: the procedure itself,
|
|
39
|
+
* or the implementation of a contract-first procedure, looked up by its path.
|
|
40
|
+
*
|
|
41
|
+
* @throws {TypeError} If a contract-first procedure has no valid implementation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveContractProcedure(router: AnyRouter, contract: AnyProcedureContract, path: readonly string[]): Promise<AnyProcedure>;
|
|
44
|
+
export declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
45
|
+
export interface WalkProcedureContractsLazyResult {
|
|
46
|
+
router: Lazy<AnyRouter>;
|
|
47
|
+
path: string[];
|
|
48
|
+
}
|
|
49
|
+
export declare function walkProcedureContractsSync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => void, path?: string[]): WalkProcedureContractsLazyResult[];
|
|
50
|
+
export declare function walkProcedureContractsAsync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => Promisable<void>, path?: string[]): Promise<void>;
|
|
51
|
+
export type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never };
|
|
52
|
+
/**
|
|
53
|
+
* Fully resolves all lazy routers inside a router, returning a plain router.
|
|
54
|
+
* Useful for making a router with lazy parts contract-compatible.
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/contract/router#router-to-contract | Router Contract - Router to Contract}
|
|
57
|
+
*/
|
|
58
|
+
export declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { mergeErrorMap, ProcedureContract, resolveMetaPlugins } from "@orpc/contract";
|
|
2
|
+
import { getOwn, isTypescriptObject, omit } from "@orpc/shared";
|
|
3
|
+
import { Lazy, unlazy } from "./lazy.mjs";
|
|
4
|
+
import { Procedure } from "./procedure.mjs";
|
|
5
|
+
import { createContractProcedure } from "./procedure-utils.mjs";
|
|
6
|
+
import { getHiddenRouterContract } from "./router-hidden.mjs";
|
|
7
|
+
export function augmentRouter(router, options) {
|
|
8
|
+
if (router instanceof Lazy) {
|
|
9
|
+
const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router["~orpc"].metaPlugins);
|
|
10
|
+
const enhanced = new Lazy({
|
|
11
|
+
meta,
|
|
12
|
+
metaPlugins,
|
|
13
|
+
async loader() {
|
|
14
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
15
|
+
const enhanced = augmentRouter(unlaziedRouter, options);
|
|
16
|
+
return unlazy(enhanced);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return enhanced;
|
|
20
|
+
}
|
|
21
|
+
if (router instanceof Procedure) {
|
|
22
|
+
const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router["~orpc"].metaPlugins);
|
|
23
|
+
const enhanced = new Procedure({
|
|
24
|
+
...omit(options, [
|
|
25
|
+
"middlewares",
|
|
26
|
+
"errorMap",
|
|
27
|
+
"meta",
|
|
28
|
+
"metaPlugins"
|
|
29
|
+
]),
|
|
30
|
+
...router["~orpc"],
|
|
31
|
+
meta,
|
|
32
|
+
metaPlugins,
|
|
33
|
+
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
34
|
+
orderedMiddlewares: [...options.middlewares.map((middleware) => ({
|
|
35
|
+
middleware,
|
|
36
|
+
inputSchemasLengthAtUse: 0,
|
|
37
|
+
outputSchemasLengthAtUse: 0
|
|
38
|
+
})), ...router["~orpc"].orderedMiddlewares]
|
|
39
|
+
});
|
|
40
|
+
return enhanced;
|
|
41
|
+
}
|
|
42
|
+
if (!isTypescriptObject(router)) {
|
|
43
|
+
return router;
|
|
44
|
+
}
|
|
45
|
+
const enhanced = {};
|
|
46
|
+
for (const [key, child] of Object.entries(router)) {
|
|
47
|
+
enhanced[key] = augmentRouter(child, options);
|
|
48
|
+
}
|
|
49
|
+
return enhanced;
|
|
50
|
+
}
|
|
51
|
+
export function augmentImplementedRouter(router, options) {
|
|
52
|
+
if (router instanceof Lazy) {
|
|
53
|
+
const enhanced = new Lazy({
|
|
54
|
+
...router["~orpc"],
|
|
55
|
+
async loader() {
|
|
56
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
57
|
+
const enhanced = augmentImplementedRouter(unlaziedRouter, options);
|
|
58
|
+
return unlazy(enhanced);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return enhanced;
|
|
62
|
+
}
|
|
63
|
+
if (router instanceof Procedure) {
|
|
64
|
+
const enhanced = new Procedure({
|
|
65
|
+
...omit(options, ["middlewares"]),
|
|
66
|
+
...router["~orpc"],
|
|
67
|
+
orderedMiddlewares: [...options.middlewares.map((middleware) => ({
|
|
68
|
+
middleware,
|
|
69
|
+
inputSchemasLengthAtUse: 0,
|
|
70
|
+
outputSchemasLengthAtUse: 0
|
|
71
|
+
})), ...router["~orpc"].orderedMiddlewares]
|
|
72
|
+
});
|
|
73
|
+
return enhanced;
|
|
74
|
+
}
|
|
75
|
+
if (!isTypescriptObject(router)) {
|
|
76
|
+
return router;
|
|
77
|
+
}
|
|
78
|
+
const enhanced = {};
|
|
79
|
+
for (const [key, child] of Object.entries(router)) {
|
|
80
|
+
enhanced[key] = augmentImplementedRouter(child, options);
|
|
81
|
+
}
|
|
82
|
+
return enhanced;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function resolveContractProcedure(router, contract, path) {
|
|
86
|
+
if (contract instanceof Procedure) {
|
|
87
|
+
return contract;
|
|
88
|
+
}
|
|
89
|
+
const { default: maybeProcedure } = await unlazy(getRouter(router, path));
|
|
90
|
+
if (!(maybeProcedure instanceof Procedure)) {
|
|
91
|
+
throw new TypeError(`[Contract-First] Missing or invalid implementation for procedure at path: "${path.join(".")}". ` + `Ensure the procedure is correctly implemented and matches its contract.`);
|
|
92
|
+
}
|
|
93
|
+
return createContractProcedure(maybeProcedure, contract);
|
|
94
|
+
}
|
|
95
|
+
export function getRouter(router, path) {
|
|
96
|
+
let current = router;
|
|
97
|
+
for (let i = 0; i < path.length; i++) {
|
|
98
|
+
const segment = path[i];
|
|
99
|
+
if (!isTypescriptObject(current)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (current instanceof Procedure) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
if (!(current instanceof Lazy)) {
|
|
106
|
+
current = getOwn(current, segment);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const lazied = current;
|
|
110
|
+
const rest = path.slice(i);
|
|
111
|
+
return new Lazy({
|
|
112
|
+
...lazied["~orpc"],
|
|
113
|
+
async loader() {
|
|
114
|
+
const unwrapped = await unlazy(lazied);
|
|
115
|
+
const next = getRouter(unwrapped.default, rest);
|
|
116
|
+
return await unlazy(next);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!isTypescriptObject(current)) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
return current;
|
|
124
|
+
}
|
|
125
|
+
export function walkProcedureContractsSync(router, callback, path = []) {
|
|
126
|
+
const lazyResults = [];
|
|
127
|
+
walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
|
|
128
|
+
return lazyResults;
|
|
129
|
+
}
|
|
130
|
+
function walkProcedureContractsSyncInternal(router, callback, path, lazyResults) {
|
|
131
|
+
const hiddenContract = getHiddenRouterContract(router);
|
|
132
|
+
if (hiddenContract !== undefined) {
|
|
133
|
+
router = hiddenContract;
|
|
134
|
+
}
|
|
135
|
+
if (router instanceof ProcedureContract) {
|
|
136
|
+
callback(router, path.slice());
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!isTypescriptObject(router)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const [key, value] of Object.entries(router)) {
|
|
143
|
+
path.push(key);
|
|
144
|
+
if (value instanceof Lazy) {
|
|
145
|
+
lazyResults.push({
|
|
146
|
+
router: value,
|
|
147
|
+
path: path.slice()
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
|
|
151
|
+
}
|
|
152
|
+
path.pop();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export async function walkProcedureContractsAsync(router, callback, path = []) {
|
|
156
|
+
const hiddenContract = getHiddenRouterContract(router);
|
|
157
|
+
if (hiddenContract !== undefined) {
|
|
158
|
+
router = hiddenContract;
|
|
159
|
+
}
|
|
160
|
+
if (router instanceof ProcedureContract) {
|
|
161
|
+
await callback(router, path);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (!isTypescriptObject(router)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
for (const [key, value] of Object.entries(router)) {
|
|
168
|
+
if (value instanceof Lazy) {
|
|
169
|
+
const { default: router } = await unlazy(value);
|
|
170
|
+
await walkProcedureContractsAsync(router, callback, [...path, key]);
|
|
171
|
+
} else {
|
|
172
|
+
await walkProcedureContractsAsync(value, callback, [...path, key]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function unlazyRouter(router) {
|
|
178
|
+
if (router instanceof Procedure) {
|
|
179
|
+
return router;
|
|
180
|
+
}
|
|
181
|
+
if (!isTypescriptObject(router)) {
|
|
182
|
+
return router;
|
|
183
|
+
}
|
|
184
|
+
const unlazied = {};
|
|
185
|
+
for (const key of Object.keys(router)) {
|
|
186
|
+
const item = router[key];
|
|
187
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
|
188
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
189
|
+
}
|
|
190
|
+
return unlazied;
|
|
191
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, ThrowableError } from "@orpc/contract";
|
|
2
|
+
import type { Context, MergedContext } from "./context.mjs";
|
|
3
|
+
import type { Lazyable } from "./lazy.mjs";
|
|
4
|
+
import type { Procedure } from "./procedure.mjs";
|
|
5
|
+
export type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
|
|
6
|
+
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
7
|
+
};
|
|
8
|
+
export type ContractedRouter<
|
|
9
|
+
T extends RouterContract,
|
|
10
|
+
TInitialContext extends Context
|
|
11
|
+
> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : { [K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never };
|
|
12
|
+
export type AnyRouter = Router<any>;
|
|
13
|
+
export type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $> ? $ : never;
|
|
14
|
+
/**
|
|
15
|
+
* Infer all initial context of the router.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* **Note**: A procedure is a router too.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
|
|
21
|
+
*/
|
|
22
|
+
export type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never };
|
|
23
|
+
/**
|
|
24
|
+
* Infer all current context of the router.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* **Note**: A procedure is a router too.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
|
|
30
|
+
*/
|
|
31
|
+
export type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never };
|
|
32
|
+
/**
|
|
33
|
+
* Infer all router inputs.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* **Note**: A procedure is a router too.
|
|
37
|
+
*
|
|
38
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
|
|
39
|
+
*/
|
|
40
|
+
export type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never };
|
|
41
|
+
/**
|
|
42
|
+
* Infer all router outputs.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* **Note**: A procedure is a router too.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
|
|
48
|
+
*/
|
|
49
|
+
export type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never };
|
|
50
|
+
/**
|
|
51
|
+
* Infer the union of throwable errors for entire router.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
|
|
54
|
+
*/
|
|
55
|
+
export type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never }[keyof T];
|
|
56
|
+
/**
|
|
57
|
+
* Infer throwable errors for each procedure, preserving the router shape.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
|
|
60
|
+
*/
|
|
61
|
+
export type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never };
|
package/dist/router.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.48",
|
|
5
5
|
"description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -117,19 +117,19 @@
|
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
"dependencies": {
|
|
120
|
-
"@orpc/client": "2.0.0-beta.
|
|
121
|
-
"@orpc/contract": "2.0.0-beta.
|
|
122
|
-
"@orpc/shared": "2.0.0-beta.
|
|
123
|
-
"@standard-server/aws-lambda": "~0.
|
|
124
|
-
"@standard-server/core": "~0.
|
|
125
|
-
"@standard-server/fastify": "~0.
|
|
126
|
-
"@standard-server/fetch": "~0.
|
|
127
|
-
"@standard-server/node": "~0.
|
|
128
|
-
"@standard-server/peer": "~0.
|
|
120
|
+
"@orpc/client": "2.0.0-beta.48",
|
|
121
|
+
"@orpc/contract": "2.0.0-beta.48",
|
|
122
|
+
"@orpc/shared": "2.0.0-beta.48",
|
|
123
|
+
"@standard-server/aws-lambda": "~0.14.0",
|
|
124
|
+
"@standard-server/core": "~0.14.0",
|
|
125
|
+
"@standard-server/fastify": "~0.14.0",
|
|
126
|
+
"@standard-server/fetch": "~0.14.0",
|
|
127
|
+
"@standard-server/node": "~0.14.0",
|
|
128
|
+
"@standard-server/peer": "~0.14.0",
|
|
129
129
|
"cookie": "^2.0.1"
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
|
-
"crossws": "^0.4.
|
|
132
|
+
"crossws": "^0.4.17",
|
|
133
133
|
"fastify": "^5.12.7",
|
|
134
134
|
"supertest": "^7.3.1",
|
|
135
135
|
"ws": "^8.22.0",
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { SendStandardResponseOptions, AnyAPIGatewayProxyEvent, HttpResponseStream } from '@standard-server/aws-lambda';
|
|
3
|
-
export { APIGatewayProxyEvent, APIGatewayProxyEventV2, AnyAPIGatewayProxyEvent, AwsLambdaGlobal, HttpResponseStream } from '@standard-server/aws-lambda';
|
|
4
|
-
import { Context } from '../../index.js';
|
|
5
|
-
import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
|
|
6
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
7
|
-
import { Router } from '../../index.js';
|
|
8
|
-
import { RPCHandlerCodecOptions } from '../standard/index.js';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standard-server/core';
|
|
12
|
-
|
|
13
|
-
type AwsLambdaHandlerHandleResult = {
|
|
14
|
-
matched: true;
|
|
15
|
-
} | {
|
|
16
|
-
matched: false;
|
|
17
|
-
};
|
|
18
|
-
interface AwsLambdaHandlerOptions<_T extends Context> {
|
|
19
|
-
/**
|
|
20
|
-
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
21
|
-
*/
|
|
22
|
-
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Requires the AWS Lambda Node.js runtime with response streaming enabled,
|
|
26
|
-
* handlers should be wrapped with `awslambda.streamifyResponse`.
|
|
27
|
-
*/
|
|
28
|
-
declare class AwsLambdaHandler<T extends Context> {
|
|
29
|
-
private readonly standardHandler;
|
|
30
|
-
private readonly sendStandardResponseOptions;
|
|
31
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<AwsLambdaHandlerOptions<T>>);
|
|
32
|
-
handle(event: AnyAPIGatewayProxyEvent, responseStream: HttpResponseStream, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<AwsLambdaHandlerHandleResult>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface RPCHandlerOptions<T extends Context> extends AwsLambdaHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Serves an oRPC router over the RPC protocol on AWS Lambda,
|
|
39
|
-
* behind API Gateway or Lambda Function URLs.
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* **Warning**: Requires the Lambda Node.js runtime with response streaming enabled, so handlers must be wrapped with `awslambda.streamifyResponse`.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.dev/docs/adapters/aws-lambda | AWS Lambda Adapter}
|
|
45
|
-
*/
|
|
46
|
-
declare class RPCHandler<T extends Context> extends AwsLambdaHandler<T> {
|
|
47
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { AwsLambdaHandler, RPCHandler };
|
|
51
|
-
export type { AwsLambdaHandlerHandleResult, AwsLambdaHandlerOptions, RPCHandlerOptions };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
|
|
3
|
-
import { Message, Peer } from 'crossws';
|
|
4
|
-
import { Context } from '../../index.js';
|
|
5
|
-
import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
|
|
6
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
7
|
-
import { Router } from '../../index.js';
|
|
8
|
-
import { RPCHandlerCodecOptions } from '../standard/index.js';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standard-server/core';
|
|
12
|
-
|
|
13
|
-
type CrosswsPeerLike = Pick<Peer, 'send'>;
|
|
14
|
-
type CrosswsMessageLike = Pick<Message, 'rawData' | 'uint8Array'>;
|
|
15
|
-
interface experimental_CrosswsHandlerOptions<_T extends Context> {
|
|
16
|
-
/**
|
|
17
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
18
|
-
*/
|
|
19
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
22
|
-
*/
|
|
23
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
24
|
-
}
|
|
25
|
-
declare class experimental_CrosswsHandler<T extends Context> {
|
|
26
|
-
private readonly handler;
|
|
27
|
-
private readonly peers;
|
|
28
|
-
private readonly encodePeerMessageOptions;
|
|
29
|
-
private readonly decodePeerMessageOptions;
|
|
30
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
|
|
31
|
-
/**
|
|
32
|
-
* Handles a single WebSocket message.
|
|
33
|
-
*
|
|
34
|
-
* Message order matters. Call this immediately after receiving a message,
|
|
35
|
-
* before any other async work, to preserve ordering.
|
|
36
|
-
*
|
|
37
|
-
* @param ws The crossws peer instance. Use the same instance for all messages.
|
|
38
|
-
*/
|
|
39
|
-
message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
|
|
40
|
-
matched: boolean;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Cleans up peer state for a closed WebSocket.
|
|
44
|
-
*
|
|
45
|
-
* @param ws The same crossws peer instance passed to `.message()`.
|
|
46
|
-
*/
|
|
47
|
-
close(ws: CrosswsPeerLike): Promise<void>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Serves an oRPC router over the RPC protocol on a WebSocket connection
|
|
54
|
-
* managed by [crossws](https://github.com/h3js/crossws).
|
|
55
|
-
*
|
|
56
|
-
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
57
|
-
*/
|
|
58
|
-
declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
|
|
59
|
-
constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { experimental_CrosswsHandler, experimental_RPCHandler };
|
|
63
|
-
export type { CrosswsMessageLike, CrosswsPeerLike, experimental_CrosswsHandlerOptions, experimental_RPCHandlerOptions };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { SendStandardResponseOptions, AnyFastifyRequest, AnyFastifyReply } from '@standard-server/fastify';
|
|
3
|
-
import { Context } from '../../index.js';
|
|
4
|
-
import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
|
|
5
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
-
import { Router } from '../../index.js';
|
|
7
|
-
import { RPCHandlerCodecOptions } from '../standard/index.js';
|
|
8
|
-
import '@orpc/client';
|
|
9
|
-
import '@orpc/contract';
|
|
10
|
-
import '@standard-server/core';
|
|
11
|
-
|
|
12
|
-
type FastifyHandlerHandleResult = {
|
|
13
|
-
matched: true;
|
|
14
|
-
} | {
|
|
15
|
-
matched: false;
|
|
16
|
-
};
|
|
17
|
-
interface FastifyHandlerOptions<_T extends Context> {
|
|
18
|
-
/**
|
|
19
|
-
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
20
|
-
*/
|
|
21
|
-
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
22
|
-
}
|
|
23
|
-
declare class FastifyHandler<T extends Context> {
|
|
24
|
-
private readonly standardHandler;
|
|
25
|
-
private readonly sendStandardResponseOptions;
|
|
26
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
|
|
27
|
-
handle(request: AnyFastifyRequest, reply: AnyFastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FastifyHandlerHandleResult>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Serves an oRPC router over the RPC protocol inside a Fastify server.
|
|
34
|
-
*
|
|
35
|
-
* @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
|
|
36
|
-
*/
|
|
37
|
-
declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
|
|
38
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { FastifyHandler, RPCHandler };
|
|
42
|
-
export type { FastifyHandlerHandleResult, FastifyHandlerOptions, RPCHandlerOptions };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export { R as BodyLimitPlugin } from '../../shared/server.CgBF3Vj1.js';
|
|
2
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { ToFetchResponseOptions } from '@standard-server/fetch';
|
|
4
|
-
import { Context } from '../../index.js';
|
|
5
|
-
import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
|
|
6
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
7
|
-
import { Router } from '../../index.js';
|
|
8
|
-
import { RPCHandlerCodecOptions } from '../standard/index.js';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standard-server/core';
|
|
12
|
-
|
|
13
|
-
type FetchHandlerHandleResult = {
|
|
14
|
-
matched: true;
|
|
15
|
-
response: Response;
|
|
16
|
-
} | {
|
|
17
|
-
matched: false;
|
|
18
|
-
response?: undefined;
|
|
19
|
-
};
|
|
20
|
-
interface FetchHandlerOptions<_T extends Context> {
|
|
21
|
-
/**
|
|
22
|
-
* Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
|
|
23
|
-
*/
|
|
24
|
-
toFetchResponse?: ToFetchResponseOptions | undefined;
|
|
25
|
-
}
|
|
26
|
-
declare class FetchHandler<T extends Context> {
|
|
27
|
-
private readonly standardHandler;
|
|
28
|
-
private readonly toFetchResponseOptions;
|
|
29
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
30
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FetchHandlerHandleResult>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Serves an oRPC router over the RPC protocol using the Fetch API
|
|
37
|
-
* (Request/Response), supported by modern runtimes like Deno, Bun,
|
|
38
|
-
* Cloudflare Workers, and browsers.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
41
|
-
*/
|
|
42
|
-
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
43
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { FetchHandler, RPCHandler };
|
|
47
|
-
export type { FetchHandlerHandleResult, FetchHandlerOptions, RPCHandlerOptions };
|