@orpc/server 0.0.0-next.fd13879 → 0.0.0-next.fd1ee2a
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 +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +41 -0
- 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 +7 -6
- package/dist/adapters/fetch/index.d.ts +7 -6
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/message-port/index.d.mts +31 -0
- package/dist/adapters/message-port/index.d.ts +31 -0
- package/dist/adapters/message-port/index.mjs +41 -0
- package/dist/adapters/node/index.d.mts +7 -6
- package/dist/adapters/node/index.d.ts +7 -6
- 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 +23 -8
- package/dist/plugins/index.d.mts +13 -13
- package/dist/plugins/index.d.ts +13 -13
- 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.YZzrREz9.d.ts → server.DHgXKx3q.d.mts} +8 -8
- package/dist/shared/server.DOwaI1le.d.ts +32 -0
- package/dist/shared/{server.eWLxY3lq.d.mts → server.DVBSOxWU.d.ts} +8 -8
- 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.DPWk5pjW.d.mts → server.wMv480px.d.mts} +7 -7
- package/dist/shared/{server.DPWk5pjW.d.ts → server.wMv480px.d.ts} +7 -7
- package/package.json +33 -12
- package/dist/shared/server.BRoxSiSC.d.mts +0 -12
- package/dist/shared/server.BjiJH9Vo.d.ts +0 -10
- package/dist/shared/server.Cy1vfSiG.d.ts +0 -12
- package/dist/shared/server.QUe9N8P4.d.mts +0 -10
@@ -0,0 +1,44 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DVBSOxWU.js';
|
3
|
+
import { experimental_HibernationEventIterator } from '@orpc/standard-server';
|
4
|
+
export { experimental_HibernationEventIterator, experimental_HibernationEventIteratorCallback } from '@orpc/standard-server';
|
5
|
+
import { C as Context, R as Router } from '../shared/server.wMv480px.js';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/shared';
|
9
|
+
|
10
|
+
interface experimental_EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
|
11
|
+
/**
|
12
|
+
* The type of event, each type corresponds a different operation
|
13
|
+
*
|
14
|
+
* - 'message' = 'yield'
|
15
|
+
* - 'error' = 'throw'
|
16
|
+
* - 'done' = 'return'
|
17
|
+
*
|
18
|
+
* @default 'message'
|
19
|
+
*/
|
20
|
+
event?: 'message' | 'error' | 'done';
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Encodes a Hibernation RPC Event
|
24
|
+
*
|
25
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
26
|
+
*/
|
27
|
+
declare function experimental_encodeHibernationRPCEvent(id: string, payload: unknown, options?: experimental_EncodeHibernationRPCEventOptions): string;
|
28
|
+
|
29
|
+
interface experimental_HibernationPluginContext {
|
30
|
+
iterator?: experimental_HibernationEventIterator<any>;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Enable Hibernation APIs
|
34
|
+
*
|
35
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
36
|
+
*/
|
37
|
+
declare class experimental_HibernationPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
38
|
+
readonly CONTEXT_SYMBOL: symbol;
|
39
|
+
order: number;
|
40
|
+
init(options: StandardHandlerOptions<T>, _router: Router<any, T>): void;
|
41
|
+
}
|
42
|
+
|
43
|
+
export { experimental_HibernationPlugin, experimental_encodeHibernationRPCEvent };
|
44
|
+
export type { experimental_EncodeHibernationRPCEventOptions, experimental_HibernationPluginContext };
|
@@ -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,10 +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 { EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
8
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
9
10
|
|
10
11
|
const DEFAULT_CONFIG = {
|
@@ -150,7 +151,7 @@ class Builder {
|
|
150
151
|
/**
|
151
152
|
* Sets or overrides the config.
|
152
153
|
*
|
153
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
154
155
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
155
156
|
*/
|
156
157
|
$config(config) {
|
@@ -447,12 +448,26 @@ function implement(contract, config = {}) {
|
|
447
448
|
return impl;
|
448
449
|
}
|
449
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
|
+
|
450
464
|
function createRouterClient(router, ...rest) {
|
465
|
+
const options = resolveMaybeOptionalOptions(rest);
|
451
466
|
if (isProcedure(router)) {
|
452
|
-
const caller = createProcedureClient(router,
|
467
|
+
const caller = createProcedureClient(router, options);
|
453
468
|
return caller;
|
454
469
|
}
|
455
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router),
|
470
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
456
471
|
const recursive = new Proxy(procedureCaller, {
|
457
472
|
get(target, key) {
|
458
473
|
if (typeof key !== "string") {
|
@@ -471,4 +486,4 @@ function createRouterClient(router, ...rest) {
|
|
471
486
|
return recursive;
|
472
487
|
}
|
473
488
|
|
474
|
-
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
|
-
import { Value } from '@orpc/shared';
|
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
|
|
@@ -12,7 +12,7 @@ interface BatchHandlerOptions<T extends Context> {
|
|
12
12
|
*
|
13
13
|
* @default 10
|
14
14
|
*/
|
15
|
-
maxSize?: Value<number
|
15
|
+
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
16
16
|
/**
|
17
17
|
* Map the request before processing it.
|
18
18
|
*
|
@@ -24,19 +24,19 @@ interface BatchHandlerOptions<T extends Context> {
|
|
24
24
|
*
|
25
25
|
* @default 207
|
26
26
|
*/
|
27
|
-
successStatus?: Value<number
|
27
|
+
successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
28
28
|
/**
|
29
29
|
* success batch response headers.
|
30
30
|
*
|
31
31
|
* @default {}
|
32
32
|
*/
|
33
|
-
headers?: Value<StandardHeaders
|
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;
|
@@ -49,8 +49,8 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
|
|
49
49
|
}
|
50
50
|
|
51
51
|
interface CORSOptions<T extends Context> {
|
52
|
-
origin?: Value<string | readonly string[] | null | undefined
|
53
|
-
timingOrigin?: Value<string | readonly string[] | null | undefined
|
52
|
+
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
53
|
+
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
54
54
|
allowMethods?: readonly string[];
|
55
55
|
allowHeaders?: readonly string[];
|
56
56
|
maxAge?: number;
|
@@ -88,21 +88,21 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
88
88
|
*
|
89
89
|
* @default 'x-csrf-token'
|
90
90
|
*/
|
91
|
-
headerName?: Value<string
|
91
|
+
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
92
92
|
/**
|
93
93
|
* The value of the header to check.
|
94
94
|
*
|
95
95
|
* @default 'orpc'
|
96
96
|
*
|
97
97
|
*/
|
98
|
-
headerValue?: Value<string
|
98
|
+
headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
99
99
|
/**
|
100
100
|
* Exclude a procedure from the plugin.
|
101
101
|
*
|
102
102
|
* @default false
|
103
103
|
*
|
104
104
|
*/
|
105
|
-
exclude?: Value<boolean
|
105
|
+
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
106
106
|
/**
|
107
107
|
* The error thrown when the CSRF token is invalid.
|
108
108
|
*
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Value } from '@orpc/shared';
|
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
|
|
@@ -12,7 +12,7 @@ interface BatchHandlerOptions<T extends Context> {
|
|
12
12
|
*
|
13
13
|
* @default 10
|
14
14
|
*/
|
15
|
-
maxSize?: Value<number
|
15
|
+
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
16
16
|
/**
|
17
17
|
* Map the request before processing it.
|
18
18
|
*
|
@@ -24,19 +24,19 @@ interface BatchHandlerOptions<T extends Context> {
|
|
24
24
|
*
|
25
25
|
* @default 207
|
26
26
|
*/
|
27
|
-
successStatus?: Value<number
|
27
|
+
successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
28
28
|
/**
|
29
29
|
* success batch response headers.
|
30
30
|
*
|
31
31
|
* @default {}
|
32
32
|
*/
|
33
|
-
headers?: Value<StandardHeaders
|
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;
|
@@ -49,8 +49,8 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
|
|
49
49
|
}
|
50
50
|
|
51
51
|
interface CORSOptions<T extends Context> {
|
52
|
-
origin?: Value<string | readonly string[] | null | undefined
|
53
|
-
timingOrigin?: Value<string | readonly string[] | null | undefined
|
52
|
+
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
53
|
+
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
54
54
|
allowMethods?: readonly string[];
|
55
55
|
allowHeaders?: readonly string[];
|
56
56
|
maxAge?: number;
|
@@ -88,21 +88,21 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
88
88
|
*
|
89
89
|
* @default 'x-csrf-token'
|
90
90
|
*/
|
91
|
-
headerName?: Value<string
|
91
|
+
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
92
92
|
/**
|
93
93
|
* The value of the header to check.
|
94
94
|
*
|
95
95
|
* @default 'orpc'
|
96
96
|
*
|
97
97
|
*/
|
98
|
-
headerValue?: Value<string
|
98
|
+
headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
99
99
|
/**
|
100
100
|
* Exclude a procedure from the plugin.
|
101
101
|
*
|
102
102
|
* @default false
|
103
103
|
*
|
104
104
|
*/
|
105
|
-
exclude?: Value<boolean
|
105
|
+
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
106
106
|
/**
|
107
107
|
* The error thrown when the CSRF token is invalid.
|
108
108
|
*
|