@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
package/dist/procedure.d.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Context } from "./context.js";
|
|
2
|
+
import { AnyMiddleware } from "./middleware.js";
|
|
3
|
+
import { AnySchema, ErrorMap, ORPCErrorConstructorMap, ProcedureContractDefinition } from "@orpc/contract";
|
|
4
|
+
import { Promisable } from "@orpc/shared";
|
|
5
5
|
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
context: TCurrentContext;
|
|
7
|
+
input: TInput;
|
|
8
|
+
path: string[];
|
|
9
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap>;
|
|
10
|
+
signal?: AbortSignal | undefined;
|
|
11
|
+
lastEventId?: string | undefined;
|
|
12
|
+
errors: TErrorConstructorMap;
|
|
13
13
|
}
|
|
14
14
|
export interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
15
|
-
|
|
15
|
+
(opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Promisable<THandlerOutput>;
|
|
16
16
|
}
|
|
17
17
|
export interface OrderedMiddleware {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Snapshot of `inputSchemas.length`
|
|
20
|
+
* at the time this middleware was used.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
inputSchemasLengthAtUse?: number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Snapshot of `outputSchemas.length`
|
|
27
|
+
* at the time this middleware was used.
|
|
28
|
+
*
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
outputSchemasLengthAtUse?: number | undefined;
|
|
32
|
+
middleware: AnyMiddleware;
|
|
33
33
|
}
|
|
34
34
|
export interface ProcedureConfig {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
/**
|
|
36
|
+
* When enabled, input schemas are not validated at runtime.
|
|
37
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
41
|
+
*
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
disableInputValidation?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* When enabled, output schemas are not validated at runtime.
|
|
47
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
48
|
+
*
|
|
49
|
+
* Useful when output schemas exist only for specification generation.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
disableOutputValidation?: boolean | undefined;
|
|
57
57
|
}
|
|
58
58
|
export interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
__TInitialContext?: (type: TInitialContext) => unknown;
|
|
60
|
+
__TInjectedContext?: (type: TInjectedContext) => unknown;
|
|
61
|
+
orderedMiddlewares: OrderedMiddleware[];
|
|
62
|
+
handler: ProcedureHandler<any, any, any, any>;
|
|
63
63
|
}
|
|
64
64
|
export declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
"~orpc": ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
66
|
+
"constructor"(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>);
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
69
|
+
*/
|
|
70
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
71
71
|
}
|
|
72
|
-
export type AnyProcedure = Procedure<any, any, any, any, any>;
|
|
72
|
+
export type AnyProcedure = Procedure<any, any, any, any, any>;
|
package/dist/procedure.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import { ProcedureContract } from
|
|
2
|
-
import { getConstructor } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return (instance instanceof ProcedureContract &&
|
|
21
|
-
Array.isArray(instance['~orpc'].orderedMiddlewares) &&
|
|
22
|
-
typeof instance['~orpc'].handler === 'function');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { ProcedureContract } from "@orpc/contract";
|
|
2
|
+
import { getConstructor } from "@orpc/shared";
|
|
3
|
+
// src/procedure.ts
|
|
4
|
+
var Procedure = class Procedure {
|
|
5
|
+
"~orpc";
|
|
6
|
+
"constructor"(def) {
|
|
7
|
+
this["~orpc"] = def;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
11
|
+
*/
|
|
12
|
+
static [Symbol.hasInstance](instance) {
|
|
13
|
+
if (this !== Procedure) return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
14
|
+
if (getConstructor(instance) === Procedure) return true;
|
|
15
|
+
return instance instanceof ProcedureContract && Array.isArray(instance["~orpc"].orderedMiddlewares) && typeof instance["~orpc"].handler === "function";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { Procedure };
|
package/dist/router-client.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
1
|
+
import { Lazyable } from "./lazy.js";
|
|
2
|
+
import { Procedure } from "./procedure.js";
|
|
3
|
+
import { ProcedureClient, ProcedureClientOptions } from "./procedure-client.js";
|
|
4
|
+
import { AnyRouter, InferRouterInitialContext } from "./router.js";
|
|
5
|
+
import { ErrorMap, Schema } from "@orpc/contract";
|
|
6
|
+
import { MaybeOptionalOptions } from "@orpc/shared";
|
|
7
|
+
import { ClientContext } from "@orpc/client";
|
|
8
8
|
/**
|
|
9
9
|
* The client type derived from a router, exposing every procedure as a callable
|
|
10
10
|
* function while preserving the router's shape.
|
|
11
11
|
*
|
|
12
12
|
* @see {@link https://orpc.dev/docs/client/client-side#creating-a-client | Client-Side Clients - Creating a Client}
|
|
13
13
|
*/
|
|
14
|
-
export type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = object> = TRouter extends Procedure<any, any, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureClient<TClientContext, $InputSchema, $OutputSchema, $ErrorMap> : {
|
|
15
|
-
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
|
16
|
-
};
|
|
14
|
+
export type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = object> = TRouter extends Procedure<any, any, infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureClient<TClientContext, $InputSchema, $OutputSchema, $ErrorMap> : { [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never; };
|
|
17
15
|
/**
|
|
18
16
|
* Creates a server-side client that calls the router's procedures directly,
|
|
19
17
|
* within the same process, without any network layer.
|
|
20
18
|
*
|
|
21
19
|
* @see {@link https://orpc.dev/docs/client/server-side#router-clients | Server-Side Clients - Router Clients}
|
|
22
20
|
*/
|
|
23
|
-
export declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext = object>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown>, ErrorMap, TClientContext>>): RouterClient<T, TClientContext>;
|
|
21
|
+
export declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext = object>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown>, ErrorMap, TClientContext>>): RouterClient<T, TClientContext>;
|
package/dist/router-client.js
CHANGED
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { Lazy } from "./lazy.js";
|
|
2
|
+
import { Procedure } from "./procedure.js";
|
|
3
|
+
import { createProcedureClient } from "./procedure-client.js";
|
|
4
|
+
import { createGuardedProcedureLazy } from "./procedure-utils.js";
|
|
5
|
+
import { getRouter } from "./router-utils.js";
|
|
6
|
+
import { resolveMaybeOptionalOptions, toArray } from "@orpc/shared";
|
|
7
|
+
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
|
|
8
|
+
// src/router-client.ts
|
|
8
9
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
nextClient = createRouterClient(next, {
|
|
34
|
-
...options,
|
|
35
|
-
path: [...toArray(options.path), key],
|
|
36
|
-
});
|
|
37
|
-
cache.set(key, nextClient);
|
|
38
|
-
}
|
|
39
|
-
return nextClient;
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
return recursive;
|
|
10
|
+
* Creates a server-side client that calls the router's procedures directly,
|
|
11
|
+
* within the same process, without any network layer.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/client/server-side#router-clients | Server-Side Clients - Router Clients}
|
|
14
|
+
*/
|
|
15
|
+
function createRouterClient(router, ...rest) {
|
|
16
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
17
|
+
if (router instanceof Procedure) return createProcedureClient(router, options);
|
|
18
|
+
const procedureCaller = router instanceof Lazy ? createProcedureClient(createGuardedProcedureLazy(router), options) : {};
|
|
19
|
+
const cache = /* @__PURE__ */ new Map();
|
|
20
|
+
return new Proxy(procedureCaller, { get(target, key) {
|
|
21
|
+
if (typeof key !== "string" || router instanceof Lazy && RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) return Reflect.get(target, key);
|
|
22
|
+
let nextClient = cache.get(key);
|
|
23
|
+
if (nextClient === void 0) {
|
|
24
|
+
const next = getRouter(router, [key]);
|
|
25
|
+
if (!next) return Reflect.get(target, key);
|
|
26
|
+
nextClient = createRouterClient(next, {
|
|
27
|
+
...options,
|
|
28
|
+
path: [...toArray(options.path), key]
|
|
29
|
+
});
|
|
30
|
+
cache.set(key, nextClient);
|
|
31
|
+
}
|
|
32
|
+
return nextClient;
|
|
33
|
+
} });
|
|
43
34
|
}
|
|
35
|
+
export { createRouterClient };
|
package/dist/router-hidden.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return Reflect.get(target, key);
|
|
9
|
-
},
|
|
10
|
-
});
|
|
1
|
+
// src/router-hidden.ts
|
|
2
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
3
|
+
function withHiddenRouterContract(router, contract) {
|
|
4
|
+
return new Proxy(router, { get(target, key) {
|
|
5
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) return contract;
|
|
6
|
+
return Reflect.get(target, key);
|
|
7
|
+
} });
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
function getHiddenRouterContract(router) {
|
|
10
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
14
11
|
}
|
|
12
|
+
export { getHiddenRouterContract, withHiddenRouterContract };
|
package/dist/router-utils.d.ts
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export 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>> : {
|
|
11
|
-
[K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouter<$, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouter<T[K], TErrorMap> : never;
|
|
12
|
-
};
|
|
13
|
-
export 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>> : {
|
|
14
|
-
[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;
|
|
15
|
-
};
|
|
16
|
-
interface AugmentRouterOptions<TErrorMap extends ErrorMap> extends AugmentContractRouterOptions<TErrorMap>, ProcedureConfig {
|
|
17
|
-
middlewares: AnyMiddleware[];
|
|
18
|
-
}
|
|
19
|
-
export declare function augmentRouter<T extends AnyRouter, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: AugmentRouterOptions<TErrorMap>): AugmentedRouter<T, TErrorMap> | AugmentedRouterWithMiddlewares<T, TInitialContext, TCurrentContext, TErrorMap>;
|
|
20
|
-
interface AugmentImplementedRouterOptions extends ProcedureConfig {
|
|
21
|
-
middlewares: AnyMiddleware[];
|
|
22
|
-
}
|
|
23
|
-
export declare function augmentImplementedRouter<T extends AnyRouter, TInitialContext extends Context, TCurrentContext extends Context>(router: T, options: AugmentImplementedRouterOptions): AugmentedRouter<T, object> | AugmentedRouterWithMiddlewares<T, TInitialContext, TCurrentContext, object>;
|
|
1
|
+
import { Context, MergedInitialContext } from "./context.js";
|
|
2
|
+
import { Lazy, Lazyable } from "./lazy.js";
|
|
3
|
+
import "./middleware.js";
|
|
4
|
+
import { AnyProcedure, Procedure } from "./procedure.js";
|
|
5
|
+
import { AnyRouter } from "./router.js";
|
|
6
|
+
import { AnyProcedureContract, ErrorMap, MergedErrorMap, RouterContract } from "@orpc/contract";
|
|
7
|
+
import { Promisable } from "@orpc/shared";
|
|
8
|
+
export 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>> : { [K in keyof T]: T[K] extends Lazy<infer $ extends AnyRouter> ? Lazy<AugmentedRouter<$, TErrorMap>> : T[K] extends AnyRouter ? AugmentedRouter<T[K], TErrorMap> : never; };
|
|
9
|
+
export 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>> : { [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; };
|
|
24
10
|
/**
|
|
25
11
|
* Resolves the procedure of a contract walked from a router: the procedure itself,
|
|
26
12
|
* or the implementation of a contract-first procedure, looked up by its path.
|
|
@@ -30,19 +16,16 @@ export declare function augmentImplementedRouter<T extends AnyRouter, TInitialCo
|
|
|
30
16
|
export declare function resolveContractProcedure(router: AnyRouter, contract: AnyProcedureContract, path: readonly string[]): Promise<AnyProcedure>;
|
|
31
17
|
export declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
32
18
|
export interface WalkProcedureContractsLazyResult {
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
router: Lazy<AnyRouter>;
|
|
20
|
+
path: string[];
|
|
35
21
|
}
|
|
36
22
|
export declare function walkProcedureContractsSync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => void, path?: string[]): WalkProcedureContractsLazyResult[];
|
|
37
23
|
export declare function walkProcedureContractsAsync(router: RouterContract | AnyRouter, callback: (contract: AnyProcedureContract | AnyProcedure, path: string[]) => Promisable<void>, path?: string[]): Promise<void>;
|
|
38
|
-
export type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
39
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
40
|
-
};
|
|
24
|
+
export type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never; };
|
|
41
25
|
/**
|
|
42
26
|
* Fully resolves all lazy routers inside a router, returning a plain router.
|
|
43
27
|
* Useful for making a router with lazy parts contract-compatible.
|
|
44
28
|
*
|
|
45
29
|
* @see {@link https://orpc.dev/docs/contract/router#router-to-contract | Router Contract - Router to Contract}
|
|
46
30
|
*/
|
|
47
|
-
export declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
48
|
-
export {};
|
|
31
|
+
export declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|