@orpc/server 2.0.0-beta.47 → 2.0.0-beta.49
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 -7
- package/dist/adapters/aws-lambda/handler.d.ts +25 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +10 -45
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
- package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
- package/dist/adapters/crossws/handler.d.ts +45 -0
- package/dist/adapters/crossws/handler.js +60 -0
- package/dist/adapters/crossws/index.d.ts +2 -63
- package/dist/adapters/crossws/index.js +2 -0
- package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
- package/dist/adapters/crossws/rpc-handler.js +15 -0
- package/dist/adapters/fastify/handler.d.ts +21 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +2 -42
- package/dist/adapters/fastify/index.js +2 -0
- package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
- package/dist/adapters/fastify/rpc-handler.js +14 -0
- package/dist/adapters/fetch/handler.d.ts +23 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +5 -45
- package/dist/adapters/fetch/index.js +7 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +16 -0
- package/dist/adapters/message-port/{index.d.mts → handler.d.ts} +17 -30
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -77
- package/dist/adapters/message-port/index.js +2 -0
- package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
- package/dist/adapters/message-port/rpc-handler.js +15 -0
- package/dist/adapters/node/handler.d.ts +21 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +5 -42
- package/dist/adapters/node/index.js +7 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +15 -0
- package/dist/adapters/standard/codec.d.ts +16 -0
- package/dist/adapters/standard/codec.js +1 -0
- package/dist/adapters/standard/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +6 -95
- package/dist/adapters/standard/index.js +5 -0
- package/dist/adapters/standard/plugin.d.ts +32 -0
- package/dist/adapters/standard/plugin.js +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
- package/dist/adapters/standard/rpc-handler-codec.js +51 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +152 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +6 -0
- package/dist/adapters/standard-peer/index.d.ts +1 -11
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/utils.d.ts +4 -0
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/{index.d.mts → handler.d.ts} +11 -29
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -77
- package/dist/adapters/websocket/index.js +2 -0
- package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
- package/dist/adapters/websocket/rpc-handler.js +15 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder-variants.js +1 -0
- package/dist/builder.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +1 -0
- package/dist/extensions/callable.d.ts +6 -5
- package/dist/extensions/callable.js +7 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +53 -0
- package/dist/helpers/cookie.d.ts +51 -0
- package/dist/helpers/cookie.js +69 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +80 -0
- package/dist/helpers/index.d.ts +4 -167
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +88 -0
- package/dist/implementer-procedure.d.ts +16 -0
- package/dist/implementer-procedure.js +44 -0
- package/dist/implementer-router.d.ts +40 -0
- package/dist/implementer-router.js +117 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +37 -0
- package/dist/index.d.ts +45 -460
- package/dist/index.js +48 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +31 -0
- package/dist/middleware-decorated.d.ts +10 -0
- package/dist/middleware-decorated.js +71 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/middleware.js +1 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +405 -0
- package/dist/plugins/cors.d.ts +73 -0
- package/dist/plugins/cors.js +112 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
- package/dist/plugins/get-method-csrf-protection.js +64 -0
- package/dist/plugins/head-method.d.ts +23 -0
- package/dist/plugins/head-method.js +104 -0
- package/dist/plugins/index.d.ts +29 -422
- package/dist/plugins/index.js +29 -0
- package/dist/plugins/method-override.d.ts +38 -0
- package/dist/plugins/method-override.js +50 -0
- package/dist/plugins/request-compression.d.ts +16 -0
- package/dist/plugins/request-compression.js +82 -0
- package/dist/plugins/request-headers.d.ts +22 -0
- package/dist/plugins/request-headers.js +30 -0
- package/dist/{shared/server.CgBF3Vj1.d.ts → plugins/request-limit.d.ts} +4 -8
- package/dist/plugins/request-limit.js +68 -0
- package/dist/plugins/response-compression.d.ts +59 -0
- package/dist/plugins/response-compression.js +209 -0
- package/dist/plugins/response-headers.d.ts +30 -0
- package/dist/plugins/response-headers.js +47 -0
- package/dist/plugins/rethrow.d.ts +33 -0
- package/dist/plugins/rethrow.js +59 -0
- package/dist/plugins/signal-sync.d.ts +13 -0
- package/dist/plugins/signal-sync.js +91 -0
- package/dist/plugins/timeout.d.ts +37 -0
- package/dist/plugins/timeout.js +59 -0
- package/dist/procedure-client.d.ts +19 -0
- package/dist/procedure-client.js +175 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +44 -0
- package/dist/procedure-utils.d.ts +41 -0
- package/dist/procedure-utils.js +49 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +24 -0
- package/dist/router-client.d.ts +23 -0
- package/dist/router-client.js +43 -0
- package/dist/router-hidden.d.ts +5 -0
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/{shared/server.Dz7j9BEh.d.ts → router.d.ts} +14 -15
- package/dist/router.js +1 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/index.d.mts +0 -51
- package/dist/adapters/aws-lambda/index.mjs +0 -39
- package/dist/adapters/crossws/index.d.mts +0 -63
- package/dist/adapters/crossws/index.mjs +0 -68
- package/dist/adapters/fastify/index.d.mts +0 -42
- package/dist/adapters/fastify/index.mjs +0 -39
- package/dist/adapters/fetch/index.d.mts +0 -47
- package/dist/adapters/fetch/index.mjs +0 -42
- package/dist/adapters/message-port/index.mjs +0 -87
- package/dist/adapters/node/index.d.mts +0 -44
- package/dist/adapters/node/index.mjs +0 -41
- package/dist/adapters/standard/index.d.mts +0 -95
- package/dist/adapters/standard/index.mjs +0 -8
- package/dist/adapters/standard-peer/index.d.mts +0 -11
- package/dist/adapters/standard-peer/index.mjs +0 -10
- package/dist/adapters/websocket/index.mjs +0 -87
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/helpers/index.d.mts +0 -167
- package/dist/helpers/index.mjs +0 -200
- package/dist/index.d.mts +0 -476
- package/dist/index.mjs +0 -463
- package/dist/plugins/index.d.mts +0 -432
- package/dist/plugins/index.mjs +0 -965
- package/dist/shared/server.1ExWFMze.mjs +0 -69
- package/dist/shared/server.9B1jEm5a.d.mts +0 -105
- package/dist/shared/server.BB464y-6.mjs +0 -207
- package/dist/shared/server.BC5BIu02.d.mts +0 -73
- package/dist/shared/server.BSYGskId.d.ts +0 -14
- package/dist/shared/server.BvG3boBj.d.mts +0 -14
- package/dist/shared/server.CTV_mC2P.d.mts +0 -34
- package/dist/shared/server.CYbIpHbH.mjs +0 -239
- package/dist/shared/server.Chq5FpXf.mjs +0 -353
- package/dist/shared/server.DFPxP2v3.d.mts +0 -166
- package/dist/shared/server.DFPxP2v3.d.ts +0 -166
- package/dist/shared/server.DOg7ke6y.d.ts +0 -105
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.sBQSgqK3.mjs +0 -41
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isNonPrimitive } from '@orpc/shared';
|
|
2
|
+
import { createRouterImplementer } from './implementer-router.js';
|
|
3
|
+
/**
|
|
4
|
+
* Turns a contract into an implementer, used to implement the contract's
|
|
5
|
+
* procedures, routers, and middleware with full type safety.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://orpc.dev/docs/contract/implementation#implementer | Contract Implementation - Implementer}
|
|
8
|
+
*/
|
|
9
|
+
export function implement(contract, config = {}) {
|
|
10
|
+
// Using `& object` avoids "has no properties in common with type" errors
|
|
11
|
+
// when combining procedures or routers with compatible but non-overlapping contexts.
|
|
12
|
+
const routerImplementer = createRouterImplementer(contract, config);
|
|
13
|
+
const implementer = new Proxy(routerImplementer, {
|
|
14
|
+
get(_, p) {
|
|
15
|
+
let method;
|
|
16
|
+
if (p === '$context') {
|
|
17
|
+
method = () => implementer;
|
|
18
|
+
}
|
|
19
|
+
else if (p === '$config') {
|
|
20
|
+
method = (incoming) => implement(contract, { ...config, ...incoming });
|
|
21
|
+
}
|
|
22
|
+
const value = Reflect.get(routerImplementer, p);
|
|
23
|
+
if (method) {
|
|
24
|
+
if (!isNonPrimitive(value)) {
|
|
25
|
+
return method;
|
|
26
|
+
}
|
|
27
|
+
return new Proxy(method, {
|
|
28
|
+
get(_, p) {
|
|
29
|
+
return Reflect.get(value, p);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return implementer;
|
|
37
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,476 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
declare class DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> {
|
|
20
|
-
meta(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
21
|
-
errors<T extends ErrorMap>(errors: T): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
22
|
-
use<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): DecoratedProcedure<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type AugmentedRouter<T extends AnyRouter, TErrorMap extends ErrorMap> = T extends Procedure<infer $InitialContext, infer $CurrentContext, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<$InitialContext, $CurrentContext, $InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $ErrorMap>> : {
|
|
26
|
-
[K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouter<$, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouter<T[K], TErrorMap> : never;
|
|
27
|
-
};
|
|
28
|
-
type AugmentedRouterWithMiddlewares<T extends AnyRouter, TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> = T extends Procedure<infer $InitialContext, infer $CurrentContext, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<MergedInitialContext<TInitialContext, TInjectedContext, $InitialContext>, $CurrentContext, $InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $ErrorMap>> : {
|
|
29
|
-
[K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouterWithMiddlewares<$, TInitialContext, TInjectedContext, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouterWithMiddlewares<T[K], TInitialContext, TInjectedContext, TErrorMap> : never;
|
|
30
|
-
};
|
|
1
|
+
export * from './builder.ts';
|
|
2
|
+
export * from './builder-variants.ts';
|
|
3
|
+
export * from './constants.ts';
|
|
4
|
+
export * from './context.ts';
|
|
5
|
+
export * from './implementer.ts';
|
|
6
|
+
export * from './implementer-procedure.ts';
|
|
7
|
+
export { SharedRouterImplementer } from './implementer-router.ts';
|
|
8
|
+
export type { RouterImplementer, RouterImplementerWithMiddlewares, SharedRouterImplementerWithMiddlewares, } from './implementer-router.ts';
|
|
9
|
+
export * from './lazy.ts';
|
|
10
|
+
export * from './middleware.ts';
|
|
11
|
+
export type { DecoratedMiddleware } from './middleware-decorated.ts';
|
|
12
|
+
export * from './procedure.ts';
|
|
13
|
+
export * from './procedure-client.ts';
|
|
14
|
+
export * from './procedure-decorated.ts';
|
|
15
|
+
export { call } from './procedure-utils.ts';
|
|
16
|
+
export type { CallOptions, CallRest } from './procedure-utils.ts';
|
|
17
|
+
export * from './router.ts';
|
|
18
|
+
export type {
|
|
31
19
|
/**
|
|
32
|
-
*
|
|
33
|
-
* or the implementation of a contract-first procedure, looked up by its path.
|
|
34
|
-
*
|
|
35
|
-
* @throws {TypeError} If a contract-first procedure has no valid implementation.
|
|
36
|
-
*/
|
|
37
|
-
declare function resolveContractProcedure(router: AnyRouter, contract: AnyProcedureContract, path: readonly string[]): Promise<AnyProcedure>;
|
|
38
|
-
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
39
|
-
interface WalkProcedureContractsLazyResult {
|
|
40
|
-
router: Lazy<AnyRouter>;
|
|
41
|
-
path: string[];
|
|
42
|
-
}
|
|
43
|
-
declare function walkProcedureContractsSync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => void, path?: string[]): WalkProcedureContractsLazyResult[];
|
|
44
|
-
declare function walkProcedureContractsAsync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => Promisable<void>, path?: string[]): Promise<void>;
|
|
45
|
-
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
46
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Fully resolves all lazy routers inside a router, returning a plain router.
|
|
50
|
-
* Useful for making a router with lazy parts contract-compatible.
|
|
51
|
-
*
|
|
52
|
-
* @see {@link https://orpc.dev/docs/contract/router#router-to-contract | Router Contract - Router to Contract}
|
|
53
|
-
*/
|
|
54
|
-
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The builder variant returned after `.use` is called.
|
|
58
|
-
* `.$context` and `.$config` are no longer available once middleware is applied.
|
|
59
|
-
*
|
|
60
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
61
|
-
*/
|
|
62
|
-
interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
|
|
63
|
-
'~orpc': BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
|
|
64
|
-
/**
|
|
65
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
68
|
-
*/
|
|
69
|
-
'meta'(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
70
|
-
/**
|
|
71
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
72
|
-
* via the `errors` utility in handlers and middleware.
|
|
73
|
-
*
|
|
74
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
75
|
-
*/
|
|
76
|
-
'errors'<T extends ErrorMap>(errors: T): BuilderWithMiddlewares<TInitialContext, TInjectedContext, MergedErrorMap<TErrorMap, T>>;
|
|
77
|
-
/**
|
|
78
|
-
* Applies a middleware that runs before the handler of every procedure
|
|
79
|
-
* built from this builder.
|
|
80
|
-
*
|
|
81
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
82
|
-
*/
|
|
83
|
-
'use'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
84
|
-
/**
|
|
85
|
-
* Creates a standalone middleware that can be composed and applied to any
|
|
86
|
-
* compatible builder or procedure with `.use`.
|
|
87
|
-
*
|
|
88
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
89
|
-
*/
|
|
90
|
-
'middleware'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $Input, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $Output = any>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, $Input, $Output, TErrorMap>;
|
|
91
|
-
/**
|
|
92
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
93
|
-
*
|
|
94
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
95
|
-
*/
|
|
96
|
-
'input'<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, T, TErrorMap>;
|
|
97
|
-
/**
|
|
98
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
99
|
-
*
|
|
100
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
101
|
-
*/
|
|
102
|
-
'output'<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, T, TErrorMap>;
|
|
103
|
-
/**
|
|
104
|
-
* Defines the function that implements the procedure and completes the
|
|
105
|
-
* chain, returning a callable procedure.
|
|
106
|
-
*
|
|
107
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
108
|
-
*/
|
|
109
|
-
'handler'<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<T>, TErrorMap>;
|
|
110
|
-
/**
|
|
111
|
-
* Applies the builder's middleware, errors, and metadata to every procedure
|
|
112
|
-
* in the given router.
|
|
113
|
-
*
|
|
114
|
-
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
115
|
-
*/
|
|
116
|
-
'router'<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(router: T): AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>;
|
|
117
|
-
/**
|
|
118
|
-
* Like `.router`, but loads the router lazily on first access, which helps
|
|
119
|
-
* reduce startup time for large applications.
|
|
120
|
-
*
|
|
121
|
-
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
122
|
-
*/
|
|
123
|
-
'lazy'<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(loader: () => Promise<{
|
|
124
|
-
default: T;
|
|
125
|
-
}>): Lazy<AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>>;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* The builder variant returned after `.input` is called.
|
|
129
|
-
* Only procedure-level methods remain available once an input schema is defined.
|
|
130
|
-
*
|
|
131
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
132
|
-
*/
|
|
133
|
-
interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
134
|
-
'~orpc': BuilderDefinition<TInputSchema, InitialOutputSchema, TErrorMap>;
|
|
135
|
-
/**
|
|
136
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
137
|
-
*
|
|
138
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
139
|
-
*/
|
|
140
|
-
'meta'(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
141
|
-
/**
|
|
142
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
143
|
-
* via the `errors` utility in handlers and middleware.
|
|
144
|
-
*
|
|
145
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
146
|
-
*/
|
|
147
|
-
'errors'<T extends ErrorMap>(errors: T): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
148
|
-
/**
|
|
149
|
-
* Applies a middleware that runs before the handler and can access the
|
|
150
|
-
* validated input.
|
|
151
|
-
*
|
|
152
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
153
|
-
*/
|
|
154
|
-
'use'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithInput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
155
|
-
/**
|
|
156
|
-
* Adds an additional input schema, merged with the previously defined one.
|
|
157
|
-
*
|
|
158
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
159
|
-
*/
|
|
160
|
-
'input'<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
161
|
-
/**
|
|
162
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
163
|
-
*
|
|
164
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
165
|
-
*/
|
|
166
|
-
'output'<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, T, TErrorMap>;
|
|
167
|
-
/**
|
|
168
|
-
* Defines the function that implements the procedure and completes the
|
|
169
|
-
* chain, returning a callable procedure.
|
|
170
|
-
*
|
|
171
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
172
|
-
*/
|
|
173
|
-
'handler'<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<T>, TErrorMap>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* The builder variant returned after `.output` is called.
|
|
177
|
-
* Only procedure-level methods remain available once an output schema is defined.
|
|
178
|
-
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
180
|
-
*/
|
|
181
|
-
interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
182
|
-
'~orpc': BuilderDefinition<InitialInputSchema, TOutputSchema, TErrorMap>;
|
|
183
|
-
/**
|
|
184
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
185
|
-
*
|
|
186
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
187
|
-
*/
|
|
188
|
-
'meta'(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
189
|
-
/**
|
|
190
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
191
|
-
* via the `errors` utility in handlers and middleware.
|
|
192
|
-
*
|
|
193
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
194
|
-
*/
|
|
195
|
-
'errors'<T extends ErrorMap>(errors: T): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
196
|
-
/**
|
|
197
|
-
* Applies a middleware that runs before the handler and can access the
|
|
198
|
-
* typed output.
|
|
199
|
-
*
|
|
200
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
201
|
-
*/
|
|
202
|
-
'use'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
203
|
-
/**
|
|
204
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
205
|
-
*
|
|
206
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
207
|
-
*/
|
|
208
|
-
'input'<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, T, TOutputSchema, TErrorMap>;
|
|
209
|
-
/**
|
|
210
|
-
* Adds an additional output schema, merged with the previously defined one.
|
|
211
|
-
*
|
|
212
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
213
|
-
*/
|
|
214
|
-
'output'<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
215
|
-
/**
|
|
216
|
-
* Defines the function that implements the procedure and completes the
|
|
217
|
-
* chain, returning a callable procedure.
|
|
218
|
-
*
|
|
219
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
220
|
-
*/
|
|
221
|
-
'handler'<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap>;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* The builder variant returned after both `.input` and `.output` are called.
|
|
225
|
-
* Only procedure-level methods remain available.
|
|
226
|
-
*
|
|
227
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
228
|
-
*/
|
|
229
|
-
interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
230
|
-
'~orpc': BuilderDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
231
|
-
/**
|
|
232
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
233
|
-
*
|
|
234
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
235
|
-
*/
|
|
236
|
-
'meta'(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
237
|
-
/**
|
|
238
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
239
|
-
* via the `errors` utility in handlers and middleware.
|
|
240
|
-
*
|
|
241
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
242
|
-
*/
|
|
243
|
-
'errors'<T extends ErrorMap>(errors: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
244
|
-
/**
|
|
245
|
-
* Applies a middleware that runs before the handler and can access the
|
|
246
|
-
* validated input and typed output.
|
|
247
|
-
*
|
|
248
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
249
|
-
*/
|
|
250
|
-
'use'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithInputOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
251
|
-
/**
|
|
252
|
-
* Adds an additional input schema, merged with the previously defined one.
|
|
253
|
-
*
|
|
254
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
255
|
-
*/
|
|
256
|
-
'input'<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
257
|
-
/**
|
|
258
|
-
* Adds an additional output schema, merged with the previously defined one.
|
|
259
|
-
*
|
|
260
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
261
|
-
*/
|
|
262
|
-
'output'<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
263
|
-
/**
|
|
264
|
-
* Defines the function that implements the procedure and completes the
|
|
265
|
-
* chain, returning a callable procedure.
|
|
266
|
-
*
|
|
267
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
268
|
-
*/
|
|
269
|
-
'handler'<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* The initial context type used when `.$context` is not called.
|
|
274
|
-
* Augment this interface with `declare module '@orpc/server'` to define
|
|
275
|
-
* a default initial context type globally.
|
|
276
|
-
*
|
|
277
|
-
* @see {@link https://orpc.dev/docs/context#default-initial-context | Context - Default Initial Context}
|
|
20
|
+
* @deprecated Use `InferRouterFinalContexts` instead.
|
|
278
21
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
22
|
+
InferRouterFinalContexts as InferRouterCurrentContexts, } from './router.ts';
|
|
23
|
+
export * from './router-client.ts';
|
|
24
|
+
export { getRouter, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync, } from './router-utils.ts';
|
|
25
|
+
export type { AugmentedRouter, AugmentedRouterWithMiddlewares, UnlaziedRouter, WalkProcedureContractsLazyResult, } from './router-utils.ts';
|
|
26
|
+
export type { AnyORPCError, AnyORPCErrorJSON, Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, RPCJsonSerialization, RPCJsonSerializationMeta, RPCJsonSerializerHandler, RPCJsonSerializerOptions, RPCSerializerOptions, RPCSerializerSerializeOptions, SafeResult, } from '@orpc/client';
|
|
27
|
+
export { COMMON_ERROR_STATUS_MAP, isDefinedError, ORPCError, RPCJsonSerializer, RPCSerializer, safe, toORPCError, } from '@orpc/client';
|
|
28
|
+
export type { AnyMetaPlugin, AnySchema, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, Meta, MetaPlugin, MetaPluginDefinition, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, ORPCErrorFromErrorMap, ProcedureContract, ProcedureContractDefinition, RouterContract, Schema, } from '@orpc/contract';
|
|
29
|
+
export { asyncIteratorObject, defineMeta, error, eventIterator, type, ValidationError, } from '@orpc/contract';
|
|
30
|
+
export type { AsyncCleanupFn, AsyncIteratorClassNextFn, DistributiveOmit, IntersectPick, MaybeOptionalOptions, PromiseWithError, Public, Registry, ThrowableError, } from '@orpc/shared';
|
|
31
|
+
export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream,
|
|
284
32
|
/**
|
|
285
|
-
*
|
|
286
|
-
* context, middleware, errors, schemas, and finally a handler or router.
|
|
287
|
-
*
|
|
288
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
33
|
+
* @deprecated Use `asyncIteratorToStream` instead.
|
|
289
34
|
*/
|
|
290
|
-
|
|
291
|
-
'~orpc': BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
|
|
292
|
-
/**
|
|
293
|
-
* Private constructor to prevent direct instantiation.
|
|
294
|
-
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
295
|
-
*/
|
|
296
|
-
private constructor();
|
|
297
|
-
/**
|
|
298
|
-
* Creates a fresh builder with an empty definition.
|
|
299
|
-
* Prefer the exported `os` instance over calling this directly.
|
|
300
|
-
*
|
|
301
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
302
|
-
*/
|
|
303
|
-
static create<T extends Context = DefaultInitialContext>(): Builder<T & object, Record<never, never>>;
|
|
304
|
-
/**
|
|
305
|
-
* Declares the initial context type that must be provided when executing
|
|
306
|
-
* procedures built from this builder.
|
|
307
|
-
*
|
|
308
|
-
* @see {@link https://orpc.dev/docs/context#initial-context | Context - Initial Context}
|
|
309
|
-
*/
|
|
310
|
-
$context<T extends Context = DefaultInitialContext>(): Builder<T & object, TErrorMap>;
|
|
311
|
-
/**
|
|
312
|
-
* Overrides the procedure configuration, such as disabling runtime
|
|
313
|
-
* input/output validation.
|
|
314
|
-
*
|
|
315
|
-
* @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
|
|
316
|
-
*/
|
|
317
|
-
$config(config: ProcedureConfig): Builder<TInitialContext, TErrorMap>;
|
|
318
|
-
/**
|
|
319
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
320
|
-
*
|
|
321
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
322
|
-
*/
|
|
323
|
-
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): Builder<TInitialContext, TErrorMap>;
|
|
324
|
-
/**
|
|
325
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
326
|
-
* via the `errors` utility in handlers and middleware.
|
|
327
|
-
*
|
|
328
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
329
|
-
*/
|
|
330
|
-
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, MergedErrorMap<TErrorMap, U>>;
|
|
331
|
-
/**
|
|
332
|
-
* Applies a middleware that runs before the handler of every procedure
|
|
333
|
-
* built from this builder.
|
|
334
|
-
*
|
|
335
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
336
|
-
*/
|
|
337
|
-
use<$OutContext extends IntersectPick<TInitialContext, $OutContext>, $InContext extends Context = TInitialContext, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | TInitialContext, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, object, $InContext>, $OutContext, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
338
|
-
/**
|
|
339
|
-
* Creates a standalone middleware that can be composed and applied to any
|
|
340
|
-
* compatible builder or procedure with `.use`.
|
|
341
|
-
*
|
|
342
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
343
|
-
*/
|
|
344
|
-
middleware<$OutContext extends IntersectPick<TInitialContext, $OutContext>, $Input, $Output = any>(middleware: Middleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>;
|
|
345
|
-
/**
|
|
346
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
347
|
-
*
|
|
348
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
349
|
-
*/
|
|
350
|
-
input<$ extends AnySchema>(schema: $): BuilderWithInput<TInitialContext, object, $, TErrorMap>;
|
|
351
|
-
/**
|
|
352
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
353
|
-
*
|
|
354
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
355
|
-
*/
|
|
356
|
-
output<$ extends AnySchema>(schema: $): BuilderWithOutput<TInitialContext, object, $, TErrorMap>;
|
|
357
|
-
/**
|
|
358
|
-
* Defines the function that implements the procedure and completes the
|
|
359
|
-
* chain, returning a callable procedure.
|
|
360
|
-
*
|
|
361
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
362
|
-
*/
|
|
363
|
-
handler<T>(handler: ProcedureHandler<TInitialContext, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<T>, TErrorMap>;
|
|
364
|
-
/**
|
|
365
|
-
* Applies the builder's middleware, errors, and metadata to every procedure
|
|
366
|
-
* in the given router.
|
|
367
|
-
*
|
|
368
|
-
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
369
|
-
*/
|
|
370
|
-
router<T extends AnyRouter>(router: T): AugmentedRouter<T, TErrorMap>;
|
|
371
|
-
/**
|
|
372
|
-
* Like `.router`, but loads the router lazily on first access, which helps
|
|
373
|
-
* reduce startup time for large applications.
|
|
374
|
-
*
|
|
375
|
-
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
376
|
-
*/
|
|
377
|
-
lazy<T extends AnyRouter>(loader: () => Promise<{
|
|
378
|
-
default: T;
|
|
379
|
-
}>): Lazy<AugmentedRouter<T, TErrorMap>>;
|
|
380
|
-
}
|
|
35
|
+
asyncIteratorToStream as eventIteratorToStream,
|
|
381
36
|
/**
|
|
382
|
-
*
|
|
383
|
-
* to define procedures, then compose them into routers.
|
|
384
|
-
*
|
|
385
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
37
|
+
* @deprecated Use `asyncIteratorToUnproxiedDataStream` instead.
|
|
386
38
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
declare const DEFAULT_SUCCESS_STATUS = 200;
|
|
390
|
-
declare const DEFAULT_ERROR_STATUS = 400;
|
|
391
|
-
|
|
392
|
-
declare class ProcedureImplementer<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
393
|
-
'~orpc': BuilderDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
394
|
-
constructor(definition: BuilderDefinition<TInputSchema, TOutputSchema, TErrorMap>);
|
|
395
|
-
'use'<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): ProcedureImplementer<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, TErrorMap>;
|
|
396
|
-
'handler'(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ImplementedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
397
|
-
}
|
|
398
|
-
declare class ImplementedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> {
|
|
399
|
-
use<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): ImplementedProcedure<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, TErrorMap>;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
declare class SharedRouterImplementer<TContract extends RouterContract, TInitialContext extends Context> {
|
|
403
|
-
private readonly contract;
|
|
404
|
-
private readonly config;
|
|
405
|
-
private readonly middlewares;
|
|
406
|
-
private constructor();
|
|
407
|
-
static create<TContract extends RouterContract, TInitialContext extends Context>(contract: TContract, config: ProcedureConfig): SharedRouterImplementer<TContract, TInitialContext>;
|
|
408
|
-
static create<TContract extends RouterContract, TInitialContext extends Context, TInjectedContext extends Context>(contract: TContract, config: ProcedureConfig, middlewares: AnyMiddleware[]): SharedRouterImplementerWithMiddlewares<TContract, TInitialContext, TInjectedContext>;
|
|
409
|
-
use<$OutContext extends IntersectPick<TInitialContext, $OutContext>, $InContext extends Context = TInitialContext, $ErrorMap extends ErrorMap = InferRouterContractErrorMap<TContract>>(middleware: Middleware<$InContext | TInitialContext, $OutContext, unknown, unknown, $ErrorMap>): RouterImplementerWithMiddlewares<TContract, MergedInitialContext<TInitialContext, object, $InContext>, $OutContext>;
|
|
410
|
-
middleware<$OutContext extends IntersectPick<TInitialContext, $OutContext>, $Input, $InContext extends Context = TInitialContext, $Output = any>(middleware: Middleware<$InContext | TInitialContext, $OutContext, $Input, $Output, InferRouterContractErrorMap<TContract>>): DecoratedMiddleware<MergedInitialContext<TInitialContext, object, $InContext>, $OutContext, $Input, $Output, object>;
|
|
411
|
-
router<T extends ContractedRouter<TContract, any>>(router: T): T;
|
|
412
|
-
lazy<T extends ContractedRouter<TContract, any>>(loader: () => Promise<{
|
|
413
|
-
default: T;
|
|
414
|
-
}>): Lazy<T>;
|
|
415
|
-
}
|
|
416
|
-
interface SharedRouterImplementerWithMiddlewares<TContract extends RouterContract, TInitialContext extends Context, TInjectedContext extends Context> {
|
|
417
|
-
use<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $ErrorMap extends ErrorMap = InferRouterContractErrorMap<TContract>>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, unknown, unknown, $ErrorMap>): RouterImplementerWithMiddlewares<TContract, MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>>;
|
|
418
|
-
middleware<$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>, $Input, $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>, $Output = any>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, $Input, $Output, InferRouterContractErrorMap<TContract>>): DecoratedMiddleware<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, $Input, $Output, object>;
|
|
419
|
-
router<T extends ContractedRouter<TContract, MergedContext<TInitialContext, TInjectedContext>>>(router: T): AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, object>;
|
|
420
|
-
lazy<T extends ContractedRouter<TContract, any>>(loader: () => Promise<{
|
|
421
|
-
default: T;
|
|
422
|
-
}>): Lazy<AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, object>>;
|
|
423
|
-
}
|
|
424
|
-
type RouterImplementer<TContract extends RouterContract, TInitialContext extends Context> = TContract extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureImplementer<TInitialContext, object, $InputSchema, $OutputSchema, $ErrorMap> : Public<SharedRouterImplementer<TContract, TInitialContext>> & {
|
|
425
|
-
[K in keyof TContract]: TContract[K] extends RouterContract ? RouterImplementer<TContract[K], TInitialContext> : never;
|
|
426
|
-
};
|
|
427
|
-
type RouterImplementerWithMiddlewares<TContract extends RouterContract, TInitialContext extends Context, TInjectedContext extends Context> = TContract extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureImplementer<TInitialContext, TInjectedContext, $InputSchema, $OutputSchema, $ErrorMap> : SharedRouterImplementerWithMiddlewares<TContract, TInitialContext, TInjectedContext> & {
|
|
428
|
-
[K in keyof TContract]: TContract[K] extends RouterContract ? RouterImplementerWithMiddlewares<TContract[K], TInitialContext, TInjectedContext> : never;
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
type Implementer<TContract extends RouterContract, TInitialContext extends Context> = {
|
|
432
|
-
$context<T extends Context = DefaultInitialContext>(): Implementer<TContract, T & object>;
|
|
433
|
-
$config(config: ProcedureConfig): Implementer<TContract, TInitialContext>;
|
|
434
|
-
} & RouterImplementer<TContract, TInitialContext>;
|
|
39
|
+
asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject,
|
|
435
40
|
/**
|
|
436
|
-
*
|
|
437
|
-
* procedures, routers, and middleware with full type safety.
|
|
438
|
-
*
|
|
439
|
-
* @see {@link https://orpc.dev/docs/contract/implementation#implementer | Contract Implementation - Implementer}
|
|
41
|
+
* @deprecated Use `streamToAsyncIteratorObject` instead.
|
|
440
42
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
type CallRest<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = object extends CallOptions<TInitialContext, TOutputSchema, TErrorMap> ? undefined extends InferSchemaInput<TInputSchema> ? [input?: InferSchemaInput<TInputSchema>, options?: CallOptions<TInitialContext, TOutputSchema, TErrorMap>] : [input: InferSchemaInput<TInputSchema>, options?: CallOptions<TInitialContext, TOutputSchema, TErrorMap>] : [input: InferSchemaInput<TInputSchema>, options: CallOptions<TInitialContext, TOutputSchema, TErrorMap>];
|
|
43
|
+
streamToAsyncIteratorObject as streamToEventIterator, } from '@orpc/shared';
|
|
44
|
+
export type { EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, } from '@standard-server/core';
|
|
45
|
+
export {
|
|
445
46
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* @example
|
|
449
|
-
* ```ts
|
|
450
|
-
* const output = await call(getting, 'input')
|
|
451
|
-
* const output = await call(getting, 'input', { context: { db: 'postgres' } })
|
|
452
|
-
* ```
|
|
453
|
-
*
|
|
454
|
-
* @see {@link https://orpc.dev/docs/client/server-side#one-off-calls | Server-Side Clients - One-Off Calls}
|
|
47
|
+
* @deprecated Use `EventStreamErrorEvent` instead.
|
|
455
48
|
*/
|
|
456
|
-
|
|
457
|
-
|
|
49
|
+
EventStreamErrorEvent as ErrorEvent, EventStreamErrorEvent,
|
|
458
50
|
/**
|
|
459
|
-
*
|
|
460
|
-
* function while preserving the router's shape.
|
|
51
|
+
* Retrieves metadata attached to a single iterator event value.
|
|
461
52
|
*
|
|
462
|
-
* @see {@link https://orpc.dev/docs/
|
|
53
|
+
* @see {@link https://orpc.dev/docs/helpers/publisher | Publisher Helpers}
|
|
463
54
|
*/
|
|
464
|
-
|
|
465
|
-
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
|
466
|
-
};
|
|
55
|
+
getEventMeta, unwrapEvent,
|
|
467
56
|
/**
|
|
468
|
-
*
|
|
469
|
-
* within the same process, without any network layer.
|
|
57
|
+
* Returns a new iterator event value with attached, validated metadata.
|
|
470
58
|
*
|
|
471
|
-
* @see {@link https://orpc.dev/docs/
|
|
59
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object#last-event-id--event-metadata | AsyncIteratorObject (SSE) - Last Event ID & Event Metadata}
|
|
472
60
|
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, ContractedRouter, DEFAULT_ERROR_STATUS, DEFAULT_SUCCESS_STATUS, DecoratedProcedure, ImplementedProcedure, InferRouterInitialContext, Lazy, Lazyable, MergedContext, MergedInitialContext, Middleware, OrderedMiddleware, Procedure, ProcedureClient, ProcedureClientOptions, ProcedureConfig, ProcedureHandler, ProcedureImplementer, Router, SharedRouterImplementer, call, createRouterClient, getRouter, implement, os, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync };
|
|
476
|
-
export type { AugmentedRouter, AugmentedRouterWithMiddlewares, BuilderDefinition, BuilderWithInput, BuilderWithInputOutput, BuilderWithMiddlewares, BuilderWithOutput, CallOptions, CallRest, DecoratedMiddleware, DefaultInitialContext, Implementer, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, SharedRouterImplementerWithMiddlewares, UnlaziedRouter, WalkProcedureContractsLazyResult };
|
|
61
|
+
withEventMeta, } from '@standard-server/core';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export * from './builder.js';
|
|
2
|
+
export * from './builder-variants.js';
|
|
3
|
+
export * from './constants.js';
|
|
4
|
+
export * from './context.js';
|
|
5
|
+
export * from './implementer.js';
|
|
6
|
+
export * from './implementer-procedure.js';
|
|
7
|
+
export { SharedRouterImplementer } from './implementer-router.js';
|
|
8
|
+
export * from './lazy.js';
|
|
9
|
+
export * from './middleware.js';
|
|
10
|
+
export * from './procedure.js';
|
|
11
|
+
export * from './procedure-client.js';
|
|
12
|
+
export * from './procedure-decorated.js';
|
|
13
|
+
export { call } from './procedure-utils.js';
|
|
14
|
+
export * from './router.js';
|
|
15
|
+
export * from './router-client.js';
|
|
16
|
+
export { getRouter, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync, } from './router-utils.js';
|
|
17
|
+
export { COMMON_ERROR_STATUS_MAP, isDefinedError, ORPCError, RPCJsonSerializer, RPCSerializer, safe, toORPCError, } from '@orpc/client';
|
|
18
|
+
export { asyncIteratorObject, defineMeta, error, eventIterator, type, ValidationError, } from '@orpc/contract';
|
|
19
|
+
export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream,
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `asyncIteratorToStream` instead.
|
|
22
|
+
*/
|
|
23
|
+
asyncIteratorToStream as eventIteratorToStream,
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `asyncIteratorToUnproxiedDataStream` instead.
|
|
26
|
+
*/
|
|
27
|
+
asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject,
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use `streamToAsyncIteratorObject` instead.
|
|
30
|
+
*/
|
|
31
|
+
streamToAsyncIteratorObject as streamToEventIterator, } from '@orpc/shared';
|
|
32
|
+
export {
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use `EventStreamErrorEvent` instead.
|
|
35
|
+
*/
|
|
36
|
+
EventStreamErrorEvent as ErrorEvent, EventStreamErrorEvent,
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves metadata attached to a single iterator event value.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://orpc.dev/docs/helpers/publisher | Publisher Helpers}
|
|
41
|
+
*/
|
|
42
|
+
getEventMeta, unwrapEvent,
|
|
43
|
+
/**
|
|
44
|
+
* Returns a new iterator event value with attached, validated metadata.
|
|
45
|
+
*
|
|
46
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object#last-event-id--event-metadata | AsyncIteratorObject (SSE) - Last Event ID & Event Metadata}
|
|
47
|
+
*/
|
|
48
|
+
withEventMeta, } from '@standard-server/core';
|