@orpc/server 0.0.0-next.fd6982a → 0.0.0-next.fe5c63f
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 -8
- package/dist/adapters/aws-lambda/index.d.mts +7 -6
- package/dist/adapters/aws-lambda/index.d.ts +7 -6
- package/dist/adapters/aws-lambda/index.mjs +6 -6
- package/dist/adapters/bun-ws/index.d.mts +12 -11
- package/dist/adapters/bun-ws/index.d.ts +12 -11
- package/dist/adapters/bun-ws/index.mjs +16 -20
- package/dist/adapters/crossws/index.d.mts +8 -5
- package/dist/adapters/crossws/index.d.ts +8 -5
- package/dist/adapters/crossws/index.mjs +13 -17
- package/dist/adapters/fetch/index.d.mts +5 -4
- package/dist/adapters/fetch/index.d.ts +5 -4
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/message-port/index.d.mts +11 -8
- package/dist/adapters/message-port/index.d.ts +11 -8
- package/dist/adapters/message-port/index.mjs +16 -16
- package/dist/adapters/node/index.d.mts +5 -4
- package/dist/adapters/node/index.d.ts +5 -4
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/standard-peer/index.d.mts +14 -0
- package/dist/adapters/standard-peer/index.d.ts +14 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +36 -9
- package/dist/adapters/websocket/index.d.ts +36 -9
- package/dist/adapters/websocket/index.mjs +51 -20
- package/dist/adapters/ws/index.d.mts +11 -8
- package/dist/adapters/ws/index.d.ts +11 -8
- package/dist/adapters/ws/index.mjs +15 -14
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +21 -47
- package/dist/index.d.ts +21 -47
- package/dist/index.mjs +22 -8
- package/dist/plugins/index.d.mts +4 -4
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/index.mjs +14 -6
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/server.CC8z0B3U.d.mts +32 -0
- package/dist/shared/{server.4FnxLwwr.mjs → server.CIL9uKTN.mjs} +13 -5
- package/dist/shared/server.CNZgPgce.d.ts +12 -0
- package/dist/shared/server.Cu-7se50.d.mts +12 -0
- package/dist/shared/server.Cwq7K86l.d.mts +42 -0
- package/dist/shared/{server.Dq8xr7PQ.d.mts → server.DHgXKx3q.d.mts} +3 -3
- package/dist/shared/server.DOwaI1le.d.ts +32 -0
- package/dist/shared/{server.-ACo36I0.d.ts → server.DVBSOxWU.d.ts} +3 -3
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/{server.DG7Tamti.mjs → server.NeumLVdS.mjs} +13 -10
- package/dist/shared/server.a_VzWVCm.d.ts +42 -0
- package/dist/shared/{server.DD2C4ujN.d.mts → server.wMv480px.d.mts} +3 -3
- package/dist/shared/{server.DD2C4ujN.d.ts → server.wMv480px.d.ts} +3 -3
- package/package.json +23 -13
- package/dist/shared/server.BPAWobQg.d.ts +0 -12
- package/dist/shared/server.Bd52nNaH.d.mts +0 -12
- package/dist/shared/server.BliFSTnG.d.mts +0 -10
- package/dist/shared/server.IG2MjhrD.d.ts +0 -10
@@ -0,0 +1,65 @@
|
|
1
|
+
import { toORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer } from '@orpc/client/standard';
|
3
|
+
import { stringifyJSON } from '@orpc/shared';
|
4
|
+
import { getEventMeta, experimental_HibernationEventIterator } from '@orpc/standard-server';
|
5
|
+
export { experimental_HibernationEventIterator } from '@orpc/standard-server';
|
6
|
+
import { MessageType } from '@orpc/standard-server-peer';
|
7
|
+
|
8
|
+
function experimental_encodeHibernationRPCEvent(id, payload, options = {}) {
|
9
|
+
const { event = "message", ...rest } = options;
|
10
|
+
const serializer = new StandardRPCJsonSerializer(rest);
|
11
|
+
const data = event === "error" ? toORPCError(payload).toJSON() : payload;
|
12
|
+
const [json, meta] = serializer.serialize(data);
|
13
|
+
return stringifyJSON({
|
14
|
+
i: id,
|
15
|
+
t: MessageType.EVENT_ITERATOR,
|
16
|
+
p: {
|
17
|
+
e: event,
|
18
|
+
d: { json, meta: meta.length > 0 ? meta : void 0 },
|
19
|
+
m: getEventMeta(payload)
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
class experimental_HibernationPlugin {
|
25
|
+
CONTEXT_SYMBOL = Symbol("ORPC_HIBERNATION_CONTEXT");
|
26
|
+
order = 2e6;
|
27
|
+
// make sure execute after the batch plugin
|
28
|
+
init(options, _router) {
|
29
|
+
options.interceptors ??= [];
|
30
|
+
options.clientInterceptors ??= [];
|
31
|
+
options.interceptors.unshift(async (options2) => {
|
32
|
+
const hibernationContext = {};
|
33
|
+
const result = await options2.next({
|
34
|
+
...options2,
|
35
|
+
context: {
|
36
|
+
[this.CONTEXT_SYMBOL]: hibernationContext,
|
37
|
+
...options2.context
|
38
|
+
}
|
39
|
+
});
|
40
|
+
if (!result.matched || !hibernationContext.iterator) {
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
return {
|
44
|
+
...result,
|
45
|
+
response: {
|
46
|
+
...result.response,
|
47
|
+
body: hibernationContext.iterator
|
48
|
+
}
|
49
|
+
};
|
50
|
+
});
|
51
|
+
options.clientInterceptors.unshift(async (options2) => {
|
52
|
+
const hibernationContext = options2.context[this.CONTEXT_SYMBOL];
|
53
|
+
if (!hibernationContext) {
|
54
|
+
throw new TypeError("[HibernationPlugin] Hibernation context has been corrupted or modified by another plugin or interceptor");
|
55
|
+
}
|
56
|
+
const output = await options2.next();
|
57
|
+
if (output instanceof experimental_HibernationEventIterator) {
|
58
|
+
hibernationContext.iterator = output;
|
59
|
+
}
|
60
|
+
return output;
|
61
|
+
});
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export { experimental_HibernationPlugin, experimental_encodeHibernationRPCEvent };
|
package/dist/index.d.mts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientOptions, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
|
-
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route,
|
3
|
+
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, Schema, ContractRouter, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
5
|
import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
-
export { IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
-
import { C as Context, P as Procedure,
|
8
|
-
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs,
|
6
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, IntersectPick, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
7
|
+
import { C as Context, P as Procedure, e as Middleware, O as ORPCErrorConstructorMap, M as MergedInitialContext, f as MergedCurrentContext, g as MapInputMiddleware, h as CreateProcedureClientOptions, i as ProcedureClient, j as ProcedureHandler, R as Router, c as Lazy, a as AnyMiddleware, b as AnyRouter, A as AnyProcedure, L as Lazyable, I as InferRouterInitialContext } from './shared/server.wMv480px.mjs';
|
8
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, t as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, d as ProcedureClientInterceptorOptions, E as ProcedureDef, D as ProcedureHandlerOptions, n as createORPCErrorConstructorMap, G as createProcedureClient, s as getLazyMeta, r as isLazy, F as isProcedure, q as lazy, m as mergeCurrentContext, B as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.wMv480px.mjs';
|
9
|
+
import { E as EnhanceRouterOptions, a as EnhancedRouter } from './shared/server.Cwq7K86l.mjs';
|
10
|
+
export { A as AccessibleLazyRouter, C as ContractProcedureCallbackOptions, L as LazyTraverseContractProceduresOptions, T as TraverseContractProcedureCallbackOptions, b as TraverseContractProceduresOptions, U as UnlaziedRouter, c as createAccessibleLazyRouter, e as enhanceRouter, g as getRouter, r as resolveContractProcedures, t as traverseContractProcedures, u as unlazyRouter } from './shared/server.Cwq7K86l.mjs';
|
9
11
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
12
|
|
11
13
|
type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
@@ -80,39 +82,6 @@ declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContex
|
|
80
82
|
actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
|
81
83
|
}
|
82
84
|
|
83
|
-
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
84
|
-
type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
|
85
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
86
|
-
};
|
87
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
88
|
-
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
89
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
90
|
-
};
|
91
|
-
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
92
|
-
middlewares: readonly AnyMiddleware[];
|
93
|
-
errorMap: TErrorMap;
|
94
|
-
dedupeLeadingMiddlewares: boolean;
|
95
|
-
}
|
96
|
-
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
|
97
|
-
interface TraverseContractProceduresOptions {
|
98
|
-
router: AnyContractRouter | AnyRouter;
|
99
|
-
path: readonly string[];
|
100
|
-
}
|
101
|
-
interface ContractProcedureCallbackOptions {
|
102
|
-
contract: AnyContractProcedure;
|
103
|
-
path: readonly string[];
|
104
|
-
}
|
105
|
-
interface LazyTraverseContractProceduresOptions {
|
106
|
-
router: Lazy<AnyRouter>;
|
107
|
-
path: readonly string[];
|
108
|
-
}
|
109
|
-
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
110
|
-
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void): Promise<void>;
|
111
|
-
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
112
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
113
|
-
};
|
114
|
-
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
115
|
-
|
116
85
|
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
117
86
|
/**
|
118
87
|
* This property holds the defined options.
|
@@ -510,7 +479,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
510
479
|
/**
|
511
480
|
* Sets or overrides the config.
|
512
481
|
*
|
513
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
482
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
514
483
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
515
484
|
*/
|
516
485
|
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -730,9 +699,9 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
730
699
|
default: U;
|
731
700
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
732
701
|
}
|
733
|
-
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
702
|
+
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
734
703
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
735
|
-
}
|
704
|
+
};
|
736
705
|
|
737
706
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
738
707
|
/**
|
@@ -768,9 +737,9 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
768
737
|
default: U;
|
769
738
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
770
739
|
}
|
771
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
740
|
+
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
772
741
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
773
|
-
}
|
742
|
+
};
|
774
743
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
775
744
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
776
745
|
/**
|
@@ -782,13 +751,18 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
782
751
|
/**
|
783
752
|
* Sets or overrides the config.
|
784
753
|
*
|
785
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
754
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
786
755
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
787
756
|
*/
|
788
757
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
789
758
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
759
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
760
|
|
761
|
+
/**
|
762
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
763
|
+
*/
|
764
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
765
|
+
|
792
766
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
767
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
768
|
dedupeLeading: boolean;
|
@@ -810,7 +784,7 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
810
784
|
* ```
|
811
785
|
*
|
812
786
|
*/
|
813
|
-
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never
|
787
|
+
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
814
788
|
|
815
789
|
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
816
790
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
@@ -825,5 +799,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
799
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
800
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
801
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call,
|
829
|
-
export type {
|
802
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, fallbackConfig, getHiddenRouterContract, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
803
|
+
export type { ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, UnactionableError };
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientOptions, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
|
-
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route,
|
3
|
+
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, Schema, ContractRouter, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
5
|
import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
-
export { IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
-
import { C as Context, P as Procedure,
|
8
|
-
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs,
|
6
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, IntersectPick, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
7
|
+
import { C as Context, P as Procedure, e as Middleware, O as ORPCErrorConstructorMap, M as MergedInitialContext, f as MergedCurrentContext, g as MapInputMiddleware, h as CreateProcedureClientOptions, i as ProcedureClient, j as ProcedureHandler, R as Router, c as Lazy, a as AnyMiddleware, b as AnyRouter, A as AnyProcedure, L as Lazyable, I as InferRouterInitialContext } from './shared/server.wMv480px.js';
|
8
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, t as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, d as ProcedureClientInterceptorOptions, E as ProcedureDef, D as ProcedureHandlerOptions, n as createORPCErrorConstructorMap, G as createProcedureClient, s as getLazyMeta, r as isLazy, F as isProcedure, q as lazy, m as mergeCurrentContext, B as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.wMv480px.js';
|
9
|
+
import { E as EnhanceRouterOptions, a as EnhancedRouter } from './shared/server.a_VzWVCm.js';
|
10
|
+
export { A as AccessibleLazyRouter, C as ContractProcedureCallbackOptions, L as LazyTraverseContractProceduresOptions, T as TraverseContractProcedureCallbackOptions, b as TraverseContractProceduresOptions, U as UnlaziedRouter, c as createAccessibleLazyRouter, e as enhanceRouter, g as getRouter, r as resolveContractProcedures, t as traverseContractProcedures, u as unlazyRouter } from './shared/server.a_VzWVCm.js';
|
9
11
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
12
|
|
11
13
|
type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
@@ -80,39 +82,6 @@ declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContex
|
|
80
82
|
actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
|
81
83
|
}
|
82
84
|
|
83
|
-
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
84
|
-
type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
|
85
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
86
|
-
};
|
87
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
88
|
-
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
89
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
90
|
-
};
|
91
|
-
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
92
|
-
middlewares: readonly AnyMiddleware[];
|
93
|
-
errorMap: TErrorMap;
|
94
|
-
dedupeLeadingMiddlewares: boolean;
|
95
|
-
}
|
96
|
-
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
|
97
|
-
interface TraverseContractProceduresOptions {
|
98
|
-
router: AnyContractRouter | AnyRouter;
|
99
|
-
path: readonly string[];
|
100
|
-
}
|
101
|
-
interface ContractProcedureCallbackOptions {
|
102
|
-
contract: AnyContractProcedure;
|
103
|
-
path: readonly string[];
|
104
|
-
}
|
105
|
-
interface LazyTraverseContractProceduresOptions {
|
106
|
-
router: Lazy<AnyRouter>;
|
107
|
-
path: readonly string[];
|
108
|
-
}
|
109
|
-
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
110
|
-
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void): Promise<void>;
|
111
|
-
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
112
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
113
|
-
};
|
114
|
-
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
115
|
-
|
116
85
|
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
117
86
|
/**
|
118
87
|
* This property holds the defined options.
|
@@ -510,7 +479,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
510
479
|
/**
|
511
480
|
* Sets or overrides the config.
|
512
481
|
*
|
513
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
482
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
514
483
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
515
484
|
*/
|
516
485
|
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -730,9 +699,9 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
730
699
|
default: U;
|
731
700
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
732
701
|
}
|
733
|
-
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
702
|
+
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
734
703
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
735
|
-
}
|
704
|
+
};
|
736
705
|
|
737
706
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
738
707
|
/**
|
@@ -768,9 +737,9 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
768
737
|
default: U;
|
769
738
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
770
739
|
}
|
771
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
740
|
+
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
772
741
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
773
|
-
}
|
742
|
+
};
|
774
743
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
775
744
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
776
745
|
/**
|
@@ -782,13 +751,18 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
782
751
|
/**
|
783
752
|
* Sets or overrides the config.
|
784
753
|
*
|
785
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
754
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
786
755
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
787
756
|
*/
|
788
757
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
789
758
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
759
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
760
|
|
761
|
+
/**
|
762
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
763
|
+
*/
|
764
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
765
|
+
|
792
766
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
767
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
768
|
dedupeLeading: boolean;
|
@@ -810,7 +784,7 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
810
784
|
* ```
|
811
785
|
*
|
812
786
|
*/
|
813
|
-
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never
|
787
|
+
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
814
788
|
|
815
789
|
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
816
790
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
@@ -825,5 +799,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
799
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
800
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
801
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call,
|
829
|
-
export type {
|
802
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, fallbackConfig, getHiddenRouterContract, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
803
|
+
export type { ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, UnactionableError };
|
package/dist/index.mjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure
|
4
|
-
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures,
|
3
|
+
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.NeumLVdS.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.NeumLVdS.mjs';
|
5
5
|
import { toORPCError } from '@orpc/client';
|
6
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
7
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
8
|
-
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
8
|
+
export { EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
11
11
|
const DEFAULT_CONFIG = {
|
@@ -151,7 +151,7 @@ class Builder {
|
|
151
151
|
/**
|
152
152
|
* Sets or overrides the config.
|
153
153
|
*
|
154
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
155
155
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
156
156
|
*/
|
157
157
|
$config(config) {
|
@@ -448,12 +448,26 @@ function implement(contract, config = {}) {
|
|
448
448
|
return impl;
|
449
449
|
}
|
450
450
|
|
451
|
+
function inferRPCMethodFromRouter(router) {
|
452
|
+
return async (_, path) => {
|
453
|
+
const { default: procedure } = await unlazy(getRouter(router, path));
|
454
|
+
if (!isProcedure(procedure)) {
|
455
|
+
throw new Error(
|
456
|
+
`[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
|
457
|
+
);
|
458
|
+
}
|
459
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
460
|
+
return method === "HEAD" ? "GET" : method;
|
461
|
+
};
|
462
|
+
}
|
463
|
+
|
451
464
|
function createRouterClient(router, ...rest) {
|
465
|
+
const options = resolveMaybeOptionalOptions(rest);
|
452
466
|
if (isProcedure(router)) {
|
453
|
-
const caller = createProcedureClient(router,
|
467
|
+
const caller = createProcedureClient(router, options);
|
454
468
|
return caller;
|
455
469
|
}
|
456
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router),
|
470
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
457
471
|
const recursive = new Proxy(procedureCaller, {
|
458
472
|
get(target, key) {
|
459
473
|
if (typeof key !== "string") {
|
@@ -472,4 +486,4 @@ function createRouterClient(router, ...rest) {
|
|
472
486
|
return recursive;
|
473
487
|
}
|
474
488
|
|
475
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
489
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Value, Promisable } from '@orpc/shared';
|
2
2
|
import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
|
3
3
|
import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
|
4
|
-
import {
|
5
|
-
import { C as Context,
|
4
|
+
import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DHgXKx3q.mjs';
|
5
|
+
import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.wMv480px.mjs';
|
6
6
|
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
7
|
import { ORPCError } from '@orpc/client';
|
8
8
|
|
@@ -33,10 +33,10 @@ interface BatchHandlerOptions<T extends Context> {
|
|
33
33
|
headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
34
34
|
}
|
35
35
|
/**
|
36
|
-
* The Batch
|
36
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
37
37
|
* reducing the overhead of sending each one separately.
|
38
38
|
*
|
39
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-
|
39
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
40
40
|
*/
|
41
41
|
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
42
42
|
private readonly maxSize;
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Value, Promisable } from '@orpc/shared';
|
2
2
|
import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
|
3
3
|
import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
|
4
|
-
import {
|
5
|
-
import { C as Context,
|
4
|
+
import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DVBSOxWU.js';
|
5
|
+
import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.wMv480px.js';
|
6
6
|
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
7
|
import { ORPCError } from '@orpc/client';
|
8
8
|
|
@@ -33,10 +33,10 @@ interface BatchHandlerOptions<T extends Context> {
|
|
33
33
|
headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
34
34
|
}
|
35
35
|
/**
|
36
|
-
* The Batch
|
36
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
37
37
|
* reducing the overhead of sending each one separately.
|
38
38
|
*
|
39
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-
|
39
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
40
40
|
*/
|
41
41
|
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
42
42
|
private readonly maxSize;
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { value, isAsyncIteratorObject } from '@orpc/shared';
|
2
|
-
import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
|
1
|
+
import { value, isAsyncIteratorObject, clone } from '@orpc/shared';
|
3
2
|
import { flattenHeader } from '@orpc/standard-server';
|
3
|
+
import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
|
4
4
|
import { ORPCError } from '@orpc/client';
|
5
5
|
export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
|
6
6
|
import '@orpc/contract';
|
@@ -26,7 +26,8 @@ class BatchHandlerPlugin {
|
|
26
26
|
init(options) {
|
27
27
|
options.rootInterceptors ??= [];
|
28
28
|
options.rootInterceptors.unshift(async (options2) => {
|
29
|
-
|
29
|
+
const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
|
30
|
+
if (xHeader === void 0) {
|
30
31
|
return options2.next();
|
31
32
|
}
|
32
33
|
let isParsing = false;
|
@@ -69,9 +70,10 @@ class BatchHandlerPlugin {
|
|
69
70
|
await Promise.race(responses);
|
70
71
|
const status = await value(this.successStatus, responses, options2);
|
71
72
|
const headers = await value(this.headers, responses, options2);
|
72
|
-
const response = toBatchResponse({
|
73
|
+
const response = await toBatchResponse({
|
73
74
|
status,
|
74
75
|
headers,
|
76
|
+
mode: xHeader === "buffered" ? "buffered" : "streaming",
|
75
77
|
body: async function* () {
|
76
78
|
const promises = [...responses];
|
77
79
|
while (true) {
|
@@ -190,7 +192,7 @@ class ResponseHeadersPlugin {
|
|
190
192
|
if (!result.matched) {
|
191
193
|
return result;
|
192
194
|
}
|
193
|
-
const responseHeaders = result.response.headers;
|
195
|
+
const responseHeaders = clone(result.response.headers);
|
194
196
|
for (const [key, value] of resHeaders) {
|
195
197
|
if (Array.isArray(responseHeaders[key])) {
|
196
198
|
responseHeaders[key].push(value);
|
@@ -200,7 +202,13 @@ class ResponseHeadersPlugin {
|
|
200
202
|
responseHeaders[key] = value;
|
201
203
|
}
|
202
204
|
}
|
203
|
-
return
|
205
|
+
return {
|
206
|
+
...result,
|
207
|
+
response: {
|
208
|
+
...result.response,
|
209
|
+
headers: responseHeaders
|
210
|
+
}
|
211
|
+
};
|
204
212
|
});
|
205
213
|
}
|
206
214
|
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import '@orpc/client';
|
2
|
+
import '@orpc/shared';
|
3
|
+
import '@orpc/standard-server';
|
4
|
+
import '@orpc/contract';
|
5
|
+
import '@orpc/client/standard';
|
6
|
+
import { r as resolveFriendlyStandardHandleOptions } from './server.DZ5BIITo.mjs';
|
7
|
+
|
8
|
+
async function handleStandardServerPeerMessage(handler, peer, message, options) {
|
9
|
+
const [id, request] = await peer.message(message);
|
10
|
+
if (!request) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
const { response } = await handler.handle(
|
14
|
+
{ ...request, body: () => Promise.resolve(request.body) },
|
15
|
+
resolveFriendlyStandardHandleOptions(options)
|
16
|
+
);
|
17
|
+
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
18
|
+
}
|
19
|
+
|
20
|
+
export { handleStandardServerPeerMessage as h };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.wMv480px.mjs';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.DHgXKx3q.mjs';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.Cwq7K86l.mjs';
|
7
|
+
|
8
|
+
interface StandardRPCMatcherOptions {
|
9
|
+
/**
|
10
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
11
|
+
*
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
15
|
+
}
|
16
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
17
|
+
private readonly filter;
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
constructor(options?: StandardRPCMatcherOptions);
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
|
26
|
+
}
|
27
|
+
declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
|
28
|
+
constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
|
29
|
+
}
|
30
|
+
|
31
|
+
export { StandardRPCHandler as a, StandardRPCMatcher as c };
|
32
|
+
export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
2
|
import { ORPCError, toORPCError } from '@orpc/client';
|
3
|
-
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
+
import { toArray, intercept, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
|
4
4
|
import { flattenHeader } from '@orpc/standard-server';
|
5
|
-
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.
|
5
|
+
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.NeumLVdS.mjs';
|
6
6
|
|
7
7
|
class CompositeStandardHandlerPlugin {
|
8
8
|
plugins;
|
@@ -112,10 +112,18 @@ class StandardRPCCodec {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
class StandardRPCMatcher {
|
115
|
-
|
115
|
+
filter;
|
116
|
+
tree = new NullProtoObj();
|
116
117
|
pendingRouters = [];
|
118
|
+
constructor(options = {}) {
|
119
|
+
this.filter = options.filter ?? true;
|
120
|
+
}
|
117
121
|
init(router, path = []) {
|
118
|
-
const laziedOptions = traverseContractProcedures({ router, path }, (
|
122
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
123
|
+
if (!value(this.filter, traverseOptions)) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
const { path: path2, contract } = traverseOptions;
|
119
127
|
const httpPath = toHttpPath(path2);
|
120
128
|
if (isProcedure(contract)) {
|
121
129
|
this.tree[httpPath] = {
|
@@ -177,7 +185,7 @@ class StandardRPCHandler extends StandardHandler {
|
|
177
185
|
constructor(router, options = {}) {
|
178
186
|
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
179
187
|
const serializer = new StandardRPCSerializer(jsonSerializer);
|
180
|
-
const matcher = new StandardRPCMatcher();
|
188
|
+
const matcher = new StandardRPCMatcher(options);
|
181
189
|
const codec = new StandardRPCCodec(serializer);
|
182
190
|
super(router, matcher, codec, options);
|
183
191
|
}
|