@orpc/server 0.0.0-next.44bdf93 → 0.0.0-next.47e44e3
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 +118 -0
- package/dist/chunk-7A2ZRAPK.js +182 -0
- package/dist/chunk-MEBJNUSY.js +32 -0
- package/dist/chunk-MHVECKBC.js +421 -0
- package/dist/chunk-WQNNSBXW.js +120 -0
- package/dist/fetch.js +6 -11
- package/dist/hono.js +18 -14
- package/dist/index.js +216 -790
- package/dist/next.js +6 -11
- package/dist/node.js +19 -75
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +1 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/fetch/types.d.ts +4 -11
- package/dist/src/adapters/hono/middleware.d.ts +6 -6
- package/dist/src/adapters/next/serve.d.ts +11 -11
- package/dist/src/adapters/node/index.d.ts +1 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/node/types.d.ts +15 -15
- package/dist/src/adapters/standard/handler.d.ts +53 -0
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/types.d.ts +21 -0
- package/dist/src/builder-variants.d.ts +75 -0
- package/dist/src/builder.d.ts +51 -36
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +7 -10
- package/dist/src/error.d.ts +8 -6
- package/dist/src/hidden.d.ts +5 -3
- package/dist/src/implementer-procedure.d.ts +33 -0
- package/dist/src/implementer-variants.d.ts +18 -0
- package/dist/src/implementer.d.ts +29 -0
- package/dist/src/index.d.ts +12 -12
- package/dist/src/lazy-utils.d.ts +4 -2
- package/dist/src/lazy.d.ts +9 -5
- package/dist/src/middleware-decorated.d.ts +7 -6
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +23 -21
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +19 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +23 -12
- package/dist/src/procedure-decorated.d.ts +13 -15
- package/dist/src/procedure-utils.d.ts +6 -4
- package/dist/src/procedure.d.ts +18 -32
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +8 -22
- package/dist/src/router.d.ts +26 -12
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +13 -0
- package/package.json +20 -3
- package/dist/chunk-GK2Z6B6W.js +0 -230
- package/dist/chunk-SXUFCJBY.js +0 -301
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/builder-with-errors-middlewares.d.ts +0 -50
- package/dist/src/builder-with-errors.d.ts +0 -49
- package/dist/src/builder-with-middlewares.d.ts +0 -47
- package/dist/src/implementer-chainable.d.ts +0 -14
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/procedure-builder-with-input.d.ts +0 -34
- package/dist/src/procedure-builder-with-output.d.ts +0 -33
- package/dist/src/procedure-builder.d.ts +0 -27
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/router-builder.d.ts +0 -33
- package/dist/src/router-implementer.d.ts +0 -22
- package/dist/src/types.d.ts +0 -14
@@ -1,26 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ClientContext } from '@orpc/client';
|
2
|
+
import type { ErrorMap, Meta } from '@orpc/contract';
|
3
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
4
|
import type { Lazy } from './lazy';
|
3
5
|
import type { Procedure } from './procedure';
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
|
7
|
-
|
8
|
-
* FIXME: separate RouterClient and ContractRouterClient, don't mix them
|
9
|
-
*/
|
10
|
-
export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
11
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
|
6
|
+
import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
|
7
|
+
import type { AnyRouter, InferRouterInitialContext } from './router';
|
8
|
+
export type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
9
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
12
10
|
};
|
13
|
-
export
|
14
|
-
/**
|
15
|
-
* This is helpful for logging and analytics.
|
16
|
-
*
|
17
|
-
* @internal
|
18
|
-
*/
|
19
|
-
path?: string[];
|
20
|
-
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
21
|
-
context?: Value<UContext>;
|
22
|
-
} : {
|
23
|
-
context: Value<UContext>;
|
24
|
-
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
25
|
-
export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
11
|
+
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext>(router: TRouter | Lazy<undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<TRouter>, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>>): RouterClient<TRouter, TClientContext>;
|
26
12
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,16 +1,30 @@
|
|
1
|
-
import type { ContractProcedure,
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ErrorMap, HTTPPath, MergedErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { Lazy, Lazyable } from './lazy';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
import type { AnyProcedure } from './procedure';
|
6
|
+
import { Procedure } from './procedure';
|
7
|
+
import { type AccessibleLazyRouter } from './router-accessible-lazy';
|
8
|
+
export type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
9
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
7
10
|
}>;
|
8
|
-
export type
|
9
|
-
export type
|
10
|
-
|
11
|
+
export type AnyRouter = Router<any, any>;
|
12
|
+
export type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
|
13
|
+
export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
14
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
11
15
|
};
|
12
|
-
export type InferRouterOutputs<T extends
|
13
|
-
[K in keyof T]: T[K] extends
|
16
|
+
export type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
17
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
14
18
|
};
|
15
|
-
export
|
19
|
+
export type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
20
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
21
|
+
};
|
22
|
+
export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
23
|
+
middlewares: AnyMiddleware[];
|
24
|
+
tags?: readonly string[];
|
25
|
+
prefix?: HTTPPath;
|
26
|
+
errorMap: TErrorMap;
|
27
|
+
}
|
28
|
+
export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
29
|
+
export declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
16
30
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type { AnyContractProcedure, AnyContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { AnyProcedure } from './procedure';
|
4
|
+
import type { AnyRouter } from './router';
|
5
|
+
export interface EachContractProcedureOptions {
|
6
|
+
router: AnyRouter | AnyContractRouter;
|
7
|
+
path: string[];
|
8
|
+
}
|
9
|
+
export interface EachContractProcedureCallbackOptions {
|
10
|
+
contract: AnyContractProcedure;
|
11
|
+
path: string[];
|
12
|
+
}
|
13
|
+
export interface EachContractProcedureLaziedOptions {
|
14
|
+
lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
|
15
|
+
path: string[];
|
16
|
+
}
|
17
|
+
export declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
|
18
|
+
export declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
|
19
|
+
export declare function convertPathToHttpPath(path: string[]): HTTPPath;
|
20
|
+
/**
|
21
|
+
* Create a new procedure that ensure the contract is applied to the procedure.
|
22
|
+
*/
|
23
|
+
export declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
|
3
24
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/standard.js
ADDED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.47e44e3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,6 +19,16 @@
|
|
19
19
|
"import": "./dist/index.js",
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
|
+
"./plugins": {
|
23
|
+
"types": "./dist/src/plugins/index.d.ts",
|
24
|
+
"import": "./dist/plugins.js",
|
25
|
+
"default": "./dist/plugins.js"
|
26
|
+
},
|
27
|
+
"./standard": {
|
28
|
+
"types": "./dist/src/adapters/standard/index.d.ts",
|
29
|
+
"import": "./dist/standard.js",
|
30
|
+
"default": "./dist/standard.js"
|
31
|
+
},
|
22
32
|
"./fetch": {
|
23
33
|
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
34
|
"import": "./dist/fetch.js",
|
@@ -53,8 +63,15 @@
|
|
53
63
|
"next": ">=14.0.0"
|
54
64
|
},
|
55
65
|
"dependencies": {
|
56
|
-
"@orpc/
|
57
|
-
"@orpc/
|
66
|
+
"@orpc/server-standard": "^0.4.0",
|
67
|
+
"@orpc/server-standard-fetch": "^0.4.0",
|
68
|
+
"@orpc/server-standard-node": "^0.4.0",
|
69
|
+
"@orpc/client": "0.0.0-next.47e44e3",
|
70
|
+
"@orpc/contract": "0.0.0-next.47e44e3",
|
71
|
+
"@orpc/shared": "0.0.0-next.47e44e3"
|
72
|
+
},
|
73
|
+
"devDependencies": {
|
74
|
+
"light-my-request": "^6.5.1"
|
58
75
|
},
|
59
76
|
"scripts": {
|
60
77
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
package/dist/chunk-GK2Z6B6W.js
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __export = (target, all) => {
|
3
|
-
for (var name in all)
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
-
};
|
6
|
-
|
7
|
-
// src/utils.ts
|
8
|
-
function mergeContext(a, b) {
|
9
|
-
if (!a)
|
10
|
-
return b;
|
11
|
-
if (!b)
|
12
|
-
return a;
|
13
|
-
return {
|
14
|
-
...a,
|
15
|
-
...b
|
16
|
-
};
|
17
|
-
}
|
18
|
-
|
19
|
-
// src/procedure.ts
|
20
|
-
import { isContractProcedure } from "@orpc/contract";
|
21
|
-
var Procedure = class {
|
22
|
-
"~type" = "Procedure";
|
23
|
-
"~orpc";
|
24
|
-
constructor(def) {
|
25
|
-
this["~orpc"] = def;
|
26
|
-
}
|
27
|
-
};
|
28
|
-
function isProcedure(item) {
|
29
|
-
if (item instanceof Procedure) {
|
30
|
-
return true;
|
31
|
-
}
|
32
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
33
|
-
}
|
34
|
-
|
35
|
-
// src/error.ts
|
36
|
-
import { ORPCError } from "@orpc/contract";
|
37
|
-
function createORPCErrorConstructorMap(errors) {
|
38
|
-
const constructors = {};
|
39
|
-
for (const code in errors) {
|
40
|
-
const config = errors[code];
|
41
|
-
if (!config) {
|
42
|
-
continue;
|
43
|
-
}
|
44
|
-
const constructor = (...[options]) => {
|
45
|
-
return new ORPCError({
|
46
|
-
code,
|
47
|
-
defined: true,
|
48
|
-
status: config.status,
|
49
|
-
message: options?.message ?? config.message,
|
50
|
-
data: options?.data,
|
51
|
-
cause: options?.cause
|
52
|
-
});
|
53
|
-
};
|
54
|
-
constructors[code] = constructor;
|
55
|
-
}
|
56
|
-
return constructors;
|
57
|
-
}
|
58
|
-
|
59
|
-
// src/lazy.ts
|
60
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
61
|
-
function lazy(loader) {
|
62
|
-
return {
|
63
|
-
[LAZY_LOADER_SYMBOL]: loader
|
64
|
-
};
|
65
|
-
}
|
66
|
-
function isLazy(item) {
|
67
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
68
|
-
}
|
69
|
-
function unlazy(lazied) {
|
70
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
71
|
-
}
|
72
|
-
function flatLazy(lazied) {
|
73
|
-
const flattenLoader = async () => {
|
74
|
-
let current = await unlazy(lazied);
|
75
|
-
while (true) {
|
76
|
-
if (!isLazy(current.default)) {
|
77
|
-
break;
|
78
|
-
}
|
79
|
-
current = await unlazy(current.default);
|
80
|
-
}
|
81
|
-
return current;
|
82
|
-
};
|
83
|
-
return lazy(flattenLoader);
|
84
|
-
}
|
85
|
-
|
86
|
-
// src/middleware.ts
|
87
|
-
function middlewareOutputFn(output) {
|
88
|
-
return { output, context: void 0 };
|
89
|
-
}
|
90
|
-
|
91
|
-
// src/procedure-client.ts
|
92
|
-
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
93
|
-
import { executeWithHooks, toError, value } from "@orpc/shared";
|
94
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
95
|
-
return async (...[input, callerOptions]) => {
|
96
|
-
const path = options?.path ?? [];
|
97
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
98
|
-
const context = await value(options?.context, callerOptions?.context);
|
99
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap);
|
100
|
-
const executeOptions = {
|
101
|
-
input,
|
102
|
-
context,
|
103
|
-
errors,
|
104
|
-
path,
|
105
|
-
procedure,
|
106
|
-
signal: callerOptions?.signal
|
107
|
-
};
|
108
|
-
try {
|
109
|
-
const output = await executeWithHooks({
|
110
|
-
hooks: options,
|
111
|
-
input,
|
112
|
-
context,
|
113
|
-
meta: executeOptions,
|
114
|
-
execute: () => executeProcedureInternal(procedure, executeOptions)
|
115
|
-
});
|
116
|
-
return output;
|
117
|
-
} catch (e) {
|
118
|
-
if (!(e instanceof ORPCError2)) {
|
119
|
-
throw toError(e);
|
120
|
-
}
|
121
|
-
const validated = await validateORPCError(procedure["~orpc"].contract["~orpc"].errorMap, e);
|
122
|
-
throw validated;
|
123
|
-
}
|
124
|
-
};
|
125
|
-
}
|
126
|
-
async function validateInput(procedure, input) {
|
127
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
128
|
-
if (!schema)
|
129
|
-
return input;
|
130
|
-
const result = await schema["~standard"].validate(input);
|
131
|
-
if (result.issues) {
|
132
|
-
throw new ORPCError2({
|
133
|
-
message: "Input validation failed",
|
134
|
-
code: "BAD_REQUEST",
|
135
|
-
data: {
|
136
|
-
issues: result.issues
|
137
|
-
},
|
138
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
139
|
-
});
|
140
|
-
}
|
141
|
-
return result.value;
|
142
|
-
}
|
143
|
-
async function validateOutput(procedure, output) {
|
144
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
145
|
-
if (!schema)
|
146
|
-
return output;
|
147
|
-
const result = await schema["~standard"].validate(output);
|
148
|
-
if (result.issues) {
|
149
|
-
throw new ORPCError2({
|
150
|
-
message: "Output validation failed",
|
151
|
-
code: "INTERNAL_SERVER_ERROR",
|
152
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
153
|
-
});
|
154
|
-
}
|
155
|
-
return result.value;
|
156
|
-
}
|
157
|
-
async function executeProcedureInternal(procedure, options) {
|
158
|
-
const middlewares = procedure["~orpc"].middlewares;
|
159
|
-
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
160
|
-
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
161
|
-
let currentIndex = 0;
|
162
|
-
let currentContext = options.context;
|
163
|
-
let currentInput = options.input;
|
164
|
-
const next = async (nextOptions) => {
|
165
|
-
const index = currentIndex;
|
166
|
-
currentIndex += 1;
|
167
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
168
|
-
if (index === inputValidationIndex) {
|
169
|
-
currentInput = await validateInput(procedure, currentInput);
|
170
|
-
}
|
171
|
-
const mid = middlewares[index];
|
172
|
-
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
173
|
-
if (index === outputValidationIndex) {
|
174
|
-
const validatedOutput = await validateOutput(procedure, result.output);
|
175
|
-
return {
|
176
|
-
...result,
|
177
|
-
output: validatedOutput
|
178
|
-
};
|
179
|
-
}
|
180
|
-
return result;
|
181
|
-
};
|
182
|
-
return (await next({})).output;
|
183
|
-
}
|
184
|
-
|
185
|
-
// src/router.ts
|
186
|
-
function getRouterChild(router, ...path) {
|
187
|
-
let current = router;
|
188
|
-
for (let i = 0; i < path.length; i++) {
|
189
|
-
const segment = path[i];
|
190
|
-
if (!current) {
|
191
|
-
return void 0;
|
192
|
-
}
|
193
|
-
if (isProcedure(current)) {
|
194
|
-
return void 0;
|
195
|
-
}
|
196
|
-
if (!isLazy(current)) {
|
197
|
-
current = current[segment];
|
198
|
-
continue;
|
199
|
-
}
|
200
|
-
const lazied = current;
|
201
|
-
const rest = path.slice(i);
|
202
|
-
const newLazy = lazy(async () => {
|
203
|
-
const unwrapped = await unlazy(lazied);
|
204
|
-
if (!unwrapped.default) {
|
205
|
-
return unwrapped;
|
206
|
-
}
|
207
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
208
|
-
return { default: next };
|
209
|
-
});
|
210
|
-
return flatLazy(newLazy);
|
211
|
-
}
|
212
|
-
return current;
|
213
|
-
}
|
214
|
-
|
215
|
-
export {
|
216
|
-
__export,
|
217
|
-
mergeContext,
|
218
|
-
Procedure,
|
219
|
-
isProcedure,
|
220
|
-
createORPCErrorConstructorMap,
|
221
|
-
LAZY_LOADER_SYMBOL,
|
222
|
-
lazy,
|
223
|
-
isLazy,
|
224
|
-
unlazy,
|
225
|
-
flatLazy,
|
226
|
-
middlewareOutputFn,
|
227
|
-
createProcedureClient,
|
228
|
-
getRouterChild
|
229
|
-
};
|
230
|
-
//# sourceMappingURL=chunk-GK2Z6B6W.js.map
|