@orpc/server 0.0.0-next.2ba0691 → 0.0.0-next.31590a1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-CVIWJKJC.js +308 -0
- package/dist/chunk-EYGVJA7A.js +136 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/chunk-OXB4YX67.js +111 -0
- package/dist/fetch.js +14 -299
- package/dist/hono.js +42 -0
- package/dist/index.js +269 -383
- package/dist/next.js +39 -0
- package/dist/node.js +175 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +4 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +13 -0
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +4 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +21 -0
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +47 -0
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +15 -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/rpc-serializer.d.ts +16 -0
- package/dist/src/adapters/standard/types.d.ts +44 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +52 -30
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +6 -4
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +11 -11
- 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 -5
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -14
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +18 -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 +8 -22
- package/dist/src/procedure-decorated.d.ts +18 -11
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +24 -18
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +7 -10
- package/dist/src/router.d.ts +25 -12
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +17 -0
- package/package.json +36 -6
- package/dist/chunk-37HIYNDO.js +0 -182
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/index.d.ts +0 -6
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/orpc-payload-codec.d.ts +0 -11
- package/dist/src/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/fetch/super-json.d.ts +0 -12
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -10
- package/dist/src/procedure-builder.d.ts +0 -22
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/types.d.ts +0 -12
@@ -1,15 +1,12 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Hooks, Value } from '@orpc/shared';
|
3
2
|
import type { Lazy } from './lazy';
|
4
3
|
import type { Procedure } from './procedure';
|
5
|
-
import type { ProcedureClient } from './procedure-client';
|
6
|
-
import type {
|
7
|
-
|
8
|
-
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER | ContractRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { AnyRouter, Router } from './router';
|
6
|
+
export type RouterClient<TRouter extends AnyRouter, TClientContext> = 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> : {
|
7
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
10
8
|
};
|
11
|
-
export type CreateRouterClientOptions<TRouter extends
|
12
|
-
router: TRouter | Lazy<undefined>;
|
9
|
+
export type CreateRouterClientOptions<TRouter extends AnyRouter> = {
|
13
10
|
/**
|
14
11
|
* This is helpful for logging and analytics.
|
15
12
|
*
|
@@ -20,6 +17,6 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
|
20
17
|
context?: Value<UContext>;
|
21
18
|
} : {
|
22
19
|
context: Value<UContext>;
|
23
|
-
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never,
|
24
|
-
export declare function createRouterClient<TRouter extends
|
20
|
+
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, any>;
|
21
|
+
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
25
22
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,16 +1,29 @@
|
|
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 InferRouterInputs<T extends
|
10
|
-
[K in keyof T]: T[K] extends
|
11
|
+
export type AnyRouter = Router<any, any>;
|
12
|
+
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> : {
|
13
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
11
14
|
};
|
12
|
-
export type InferRouterOutputs<T extends
|
13
|
-
[K in keyof T]: T[K] extends
|
15
|
+
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> : {
|
16
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
14
17
|
};
|
15
|
-
export
|
18
|
+
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> : {
|
19
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
20
|
+
};
|
21
|
+
export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
22
|
+
middlewares: AnyMiddleware[];
|
23
|
+
tags?: readonly string[];
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
errorMap: TErrorMap;
|
26
|
+
}
|
27
|
+
export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
28
|
+
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
29
|
//# 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
@@ -0,0 +1,17 @@
|
|
1
|
+
import {
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
RPCSerializer,
|
5
|
+
StandardHandler,
|
6
|
+
serializeRPCJson
|
7
|
+
} from "./chunk-CVIWJKJC.js";
|
8
|
+
import "./chunk-NOA3GBJQ.js";
|
9
|
+
import "./chunk-OXB4YX67.js";
|
10
|
+
export {
|
11
|
+
RPCCodec,
|
12
|
+
RPCMatcher,
|
13
|
+
RPCSerializer,
|
14
|
+
StandardHandler,
|
15
|
+
serializeRPCJson
|
16
|
+
};
|
17
|
+
//# sourceMappingURL=standard.js.map
|
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.31590a1",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,11 +19,36 @@
|
|
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
|
-
"types": "./dist/src/fetch/index.d.ts",
|
33
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
34
|
"import": "./dist/fetch.js",
|
25
35
|
"default": "./dist/fetch.js"
|
26
36
|
},
|
37
|
+
"./hono": {
|
38
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
39
|
+
"import": "./dist/hono.js",
|
40
|
+
"default": "./dist/hono.js"
|
41
|
+
},
|
42
|
+
"./next": {
|
43
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
44
|
+
"import": "./dist/next.js",
|
45
|
+
"default": "./dist/next.js"
|
46
|
+
},
|
47
|
+
"./node": {
|
48
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
49
|
+
"import": "./dist/node.js",
|
50
|
+
"default": "./dist/node.js"
|
51
|
+
},
|
27
52
|
"./🔒/*": {
|
28
53
|
"types": "./dist/src/*.d.ts"
|
29
54
|
}
|
@@ -33,15 +58,20 @@
|
|
33
58
|
"!**/*.tsbuildinfo",
|
34
59
|
"dist"
|
35
60
|
],
|
61
|
+
"peerDependencies": {
|
62
|
+
"hono": ">=4.6.0",
|
63
|
+
"next": ">=14.0.0"
|
64
|
+
},
|
36
65
|
"dependencies": {
|
37
|
-
"
|
38
|
-
"@orpc/
|
66
|
+
"content-disposition": "^0.5.4",
|
67
|
+
"@orpc/contract": "0.0.0-next.31590a1",
|
68
|
+
"@orpc/shared": "0.0.0-next.31590a1"
|
39
69
|
},
|
40
70
|
"devDependencies": {
|
41
|
-
"
|
71
|
+
"light-my-request": "^6.5.1"
|
42
72
|
},
|
43
73
|
"scripts": {
|
44
|
-
"build": "tsup --
|
74
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
45
75
|
"build:watch": "pnpm run build --watch",
|
46
76
|
"type:check": "tsc -b"
|
47
77
|
}
|
package/dist/chunk-37HIYNDO.js
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
// src/utils.ts
|
2
|
-
function mergeContext(a, b) {
|
3
|
-
if (!a)
|
4
|
-
return b;
|
5
|
-
if (!b)
|
6
|
-
return a;
|
7
|
-
return {
|
8
|
-
...a,
|
9
|
-
...b
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/procedure.ts
|
14
|
-
import { isContractProcedure } from "@orpc/contract";
|
15
|
-
var Procedure = class {
|
16
|
-
"~type" = "Procedure";
|
17
|
-
"~orpc";
|
18
|
-
constructor(def) {
|
19
|
-
this["~orpc"] = def;
|
20
|
-
}
|
21
|
-
};
|
22
|
-
function isProcedure(item) {
|
23
|
-
if (item instanceof Procedure) {
|
24
|
-
return true;
|
25
|
-
}
|
26
|
-
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";
|
27
|
-
}
|
28
|
-
|
29
|
-
// src/lazy.ts
|
30
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
31
|
-
function lazy(loader) {
|
32
|
-
return {
|
33
|
-
[LAZY_LOADER_SYMBOL]: loader
|
34
|
-
};
|
35
|
-
}
|
36
|
-
function isLazy(item) {
|
37
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
38
|
-
}
|
39
|
-
function unlazy(lazied) {
|
40
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
41
|
-
}
|
42
|
-
function flatLazy(lazied) {
|
43
|
-
const flattenLoader = async () => {
|
44
|
-
let current = await unlazy(lazied);
|
45
|
-
while (true) {
|
46
|
-
if (!isLazy(current.default)) {
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
current = await unlazy(current.default);
|
50
|
-
}
|
51
|
-
return current;
|
52
|
-
};
|
53
|
-
return lazy(flattenLoader);
|
54
|
-
}
|
55
|
-
|
56
|
-
// src/procedure-client.ts
|
57
|
-
import { executeWithHooks, value } from "@orpc/shared";
|
58
|
-
import { ORPCError } from "@orpc/shared/error";
|
59
|
-
function createProcedureClient(options) {
|
60
|
-
return async (...[input, callerOptions]) => {
|
61
|
-
const path = options.path ?? [];
|
62
|
-
const { default: procedure } = await unlazy(options.procedure);
|
63
|
-
const context = await value(options.context);
|
64
|
-
const meta = {
|
65
|
-
path,
|
66
|
-
procedure,
|
67
|
-
signal: callerOptions?.signal
|
68
|
-
};
|
69
|
-
const executeWithValidation = async () => {
|
70
|
-
const validInput = await validateInput(procedure, input);
|
71
|
-
const output = await executeMiddlewareChain(
|
72
|
-
procedure,
|
73
|
-
validInput,
|
74
|
-
context,
|
75
|
-
meta
|
76
|
-
);
|
77
|
-
return validateOutput(procedure, output);
|
78
|
-
};
|
79
|
-
return executeWithHooks({
|
80
|
-
hooks: options,
|
81
|
-
input,
|
82
|
-
context,
|
83
|
-
meta,
|
84
|
-
execute: executeWithValidation
|
85
|
-
});
|
86
|
-
};
|
87
|
-
}
|
88
|
-
async function validateInput(procedure, input) {
|
89
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
90
|
-
if (!schema)
|
91
|
-
return input;
|
92
|
-
const result = await schema["~standard"].validate(input);
|
93
|
-
if (result.issues) {
|
94
|
-
throw new ORPCError({
|
95
|
-
message: "Input validation failed",
|
96
|
-
code: "BAD_REQUEST",
|
97
|
-
issues: result.issues
|
98
|
-
});
|
99
|
-
}
|
100
|
-
return result.value;
|
101
|
-
}
|
102
|
-
async function validateOutput(procedure, output) {
|
103
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
104
|
-
if (!schema)
|
105
|
-
return output;
|
106
|
-
const result = await schema["~standard"].validate(output);
|
107
|
-
if (result.issues) {
|
108
|
-
throw new ORPCError({
|
109
|
-
message: "Output validation failed",
|
110
|
-
code: "INTERNAL_SERVER_ERROR",
|
111
|
-
issues: result.issues
|
112
|
-
});
|
113
|
-
}
|
114
|
-
return result.value;
|
115
|
-
}
|
116
|
-
async function executeMiddlewareChain(procedure, input, context, meta) {
|
117
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
118
|
-
let currentMidIndex = 0;
|
119
|
-
let currentContext = context;
|
120
|
-
const next = async (nextOptions) => {
|
121
|
-
const mid = middlewares[currentMidIndex];
|
122
|
-
currentMidIndex += 1;
|
123
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
124
|
-
if (mid) {
|
125
|
-
return await mid(input, currentContext, {
|
126
|
-
...meta,
|
127
|
-
next,
|
128
|
-
output: (output) => ({ output, context: void 0 })
|
129
|
-
});
|
130
|
-
}
|
131
|
-
const result = {
|
132
|
-
output: await procedure["~orpc"].handler(input, currentContext, meta),
|
133
|
-
context: currentContext
|
134
|
-
};
|
135
|
-
return result;
|
136
|
-
};
|
137
|
-
return (await next({})).output;
|
138
|
-
}
|
139
|
-
|
140
|
-
// src/router.ts
|
141
|
-
function getRouterChild(router, ...path) {
|
142
|
-
let current = router;
|
143
|
-
for (let i = 0; i < path.length; i++) {
|
144
|
-
const segment = path[i];
|
145
|
-
if (!current) {
|
146
|
-
return void 0;
|
147
|
-
}
|
148
|
-
if (isProcedure(current)) {
|
149
|
-
return void 0;
|
150
|
-
}
|
151
|
-
if (!isLazy(current)) {
|
152
|
-
current = current[segment];
|
153
|
-
continue;
|
154
|
-
}
|
155
|
-
const lazied = current;
|
156
|
-
const rest = path.slice(i);
|
157
|
-
const newLazy = lazy(async () => {
|
158
|
-
const unwrapped = await unlazy(lazied);
|
159
|
-
if (!unwrapped.default) {
|
160
|
-
return unwrapped;
|
161
|
-
}
|
162
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
163
|
-
return { default: next };
|
164
|
-
});
|
165
|
-
return flatLazy(newLazy);
|
166
|
-
}
|
167
|
-
return current;
|
168
|
-
}
|
169
|
-
|
170
|
-
export {
|
171
|
-
mergeContext,
|
172
|
-
Procedure,
|
173
|
-
isProcedure,
|
174
|
-
LAZY_LOADER_SYMBOL,
|
175
|
-
lazy,
|
176
|
-
isLazy,
|
177
|
-
unlazy,
|
178
|
-
flatLazy,
|
179
|
-
createProcedureClient,
|
180
|
-
getRouterChild
|
181
|
-
};
|
182
|
-
//# sourceMappingURL=chunk-37HIYNDO.js.map
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import type { Context } from '../types';
|
2
|
-
import type { ConditionalFetchHandler, FetchHandler, FetchOptions } from './types';
|
3
|
-
export declare class CompositeHandler<T extends Context> implements FetchHandler<T> {
|
4
|
-
private readonly handlers;
|
5
|
-
constructor(handlers: ConditionalFetchHandler<T>[]);
|
6
|
-
fetch(request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
7
|
-
}
|
8
|
-
//# sourceMappingURL=composite-handler.d.ts.map
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { Hooks } from '@orpc/shared';
|
2
|
-
import type { Router } from '../router';
|
3
|
-
import type { Context, WithSignal } from '../types';
|
4
|
-
import type { ConditionalFetchHandler, FetchOptions } from './types';
|
5
|
-
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
-
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type ORPCHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
8
|
-
procedureMatcher?: PublicORPCProcedureMatcher;
|
9
|
-
payloadCodec?: PublicORPCPayloadCodec;
|
10
|
-
};
|
11
|
-
export declare class ORPCHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
12
|
-
readonly router: Router<T, any>;
|
13
|
-
readonly options?: NoInfer<ORPCHandlerOptions<T>> | undefined;
|
14
|
-
private readonly procedureMatcher;
|
15
|
-
private readonly payloadCodec;
|
16
|
-
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
|
17
|
-
condition(request: Request): boolean;
|
18
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
19
|
-
}
|
20
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { HTTPMethod } from '@orpc/contract';
|
2
|
-
export declare class ORPCPayloadCodec {
|
3
|
-
encode(payload: unknown, method?: HTTPMethod): {
|
4
|
-
query?: URLSearchParams;
|
5
|
-
body?: FormData | string;
|
6
|
-
headers?: Headers;
|
7
|
-
};
|
8
|
-
decode(re: Request | Response): Promise<unknown>;
|
9
|
-
}
|
10
|
-
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
11
|
-
//# sourceMappingURL=orpc-payload-codec.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { ANY_PROCEDURE } from '../procedure';
|
2
|
-
import { type ANY_ROUTER } from '../router';
|
3
|
-
export declare class ORPCProcedureMatcher {
|
4
|
-
private readonly router;
|
5
|
-
constructor(router: ANY_ROUTER);
|
6
|
-
match(pathname: string): Promise<{
|
7
|
-
path: string[];
|
8
|
-
procedure: ANY_PROCEDURE;
|
9
|
-
} | undefined>;
|
10
|
-
}
|
11
|
-
export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
|
12
|
-
//# sourceMappingURL=orpc-procedure-matcher.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { Segment } from '@orpc/shared';
|
2
|
-
export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
|
3
|
-
export type JSONMeta = [JSONExtraType, Segment[]][];
|
4
|
-
export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
|
5
|
-
data: unknown;
|
6
|
-
meta: JSONMeta;
|
7
|
-
};
|
8
|
-
export declare function deserialize({ data, meta, }: {
|
9
|
-
data: unknown;
|
10
|
-
meta: JSONMeta;
|
11
|
-
}): unknown;
|
12
|
-
//# sourceMappingURL=super-json.d.ts.map
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Context, WithSignal } from '../types';
|
3
|
-
export type FetchOptions<T extends Context> = WithSignal & {
|
4
|
-
prefix?: HTTPPath;
|
5
|
-
} & (undefined extends T ? {
|
6
|
-
context?: T;
|
7
|
-
} : {
|
8
|
-
context: T;
|
9
|
-
});
|
10
|
-
export interface FetchHandler<T extends Context> {
|
11
|
-
fetch: (request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)) => Promise<Response>;
|
12
|
-
}
|
13
|
-
export interface ConditionalFetchHandler<T extends Context> extends FetchHandler<T> {
|
14
|
-
condition: (request: Request) => boolean;
|
15
|
-
}
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { Middleware } from './middleware';
|
2
|
-
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
3
|
-
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
5
|
-
import { RouterImplementer } from './router-implementer';
|
6
|
-
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : {
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
8
|
-
} & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
|
9
|
-
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter = any>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
|
-
//# sourceMappingURL=implementer-chainable.d.ts.map
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { Lazy } from './lazy';
|
3
|
-
import type { Procedure } from './procedure';
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
5
|
-
import { type ANY_ROUTER } from './router';
|
6
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends Procedure<infer UContext, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? undefined extends UContext ? ProcedureClient<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, unknown> : unknown : {
|
7
|
-
[K in keyof T]: T[K] extends object ? DecoratedLazy<T[K]> : never;
|
8
|
-
});
|
9
|
-
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
10
|
-
//# sourceMappingURL=lazy-decorated.d.ts.map
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
import type { DecoratedProcedure } from './procedure-decorated';
|
3
|
-
import type { Context, MergeContext } from './types';
|
4
|
-
import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
5
|
-
import { type ProcedureFunc } from './procedure';
|
6
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
7
|
-
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
8
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
9
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any>[];
|
10
|
-
}
|
11
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
12
|
-
'~type': "ProcedureBuilder";
|
13
|
-
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
14
|
-
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
15
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
16
|
-
input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema>;
|
17
|
-
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U>;
|
18
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
19
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
20
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
21
|
-
}
|
22
|
-
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type { ProcedureFunc } from './procedure';
|
4
|
-
import type { DecoratedProcedure } from './procedure-decorated';
|
5
|
-
import type { Context, MergeContext } from './types';
|
6
|
-
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> = {
|
7
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
8
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>[];
|
9
|
-
};
|
10
|
-
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
11
|
-
'~type': "ProcedureImplementer";
|
12
|
-
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
13
|
-
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
14
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
15
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
16
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
17
|
-
}
|
18
|
-
//# sourceMappingURL=procedure-implementer.d.ts.map
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { FlattenLazy, Lazy } from './lazy';
|
3
|
-
import type { Middleware } from './middleware';
|
4
|
-
import type { Procedure } from './procedure';
|
5
|
-
import type { ANY_ROUTER, Router } from './router';
|
6
|
-
import type { Context, MergeContext } from './types';
|
7
|
-
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
-
import { type DecoratedProcedure } from './procedure-decorated';
|
9
|
-
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : {
|
10
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
|
11
|
-
};
|
12
|
-
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
13
|
-
prefix?: HTTPPath;
|
14
|
-
tags?: readonly string[];
|
15
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any>[];
|
16
|
-
};
|
17
|
-
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
18
|
-
'~type': "RouterBuilder";
|
19
|
-
'~orpc': RouterBuilderDef<TContext, TExtraContext>;
|
20
|
-
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
21
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
22
|
-
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown>): RouterBuilder<TContext, MergeContext<TExtraContext, U>>;
|
24
|
-
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
25
|
-
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
26
|
-
default: U;
|
27
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
28
|
-
}
|
29
|
-
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
2
|
-
import type { FlattenLazy } from './lazy';
|
3
|
-
import type { Middleware } from './middleware';
|
4
|
-
import type { Router } from './router';
|
5
|
-
import type { AdaptedRouter } from './router-builder';
|
6
|
-
import type { Context, MergeContext } from './types';
|
7
|
-
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
8
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any>[];
|
9
|
-
contract: TContract;
|
10
|
-
}
|
11
|
-
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
12
|
-
'~type': "RouterImplementer";
|
13
|
-
'~orpc': RouterImplementerDef<TContext, TExtraContext, TContract>;
|
14
|
-
constructor(def: RouterImplementerDef<TContext, TExtraContext, TContract>);
|
15
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown>): RouterImplementer<TContext, MergeContext<TExtraContext, U>, TContract>;
|
16
|
-
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U>;
|
17
|
-
lazy<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(loader: () => Promise<{
|
18
|
-
default: U;
|
19
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
20
|
-
}
|
21
|
-
//# sourceMappingURL=router-implementer.d.ts.map
|
package/dist/src/types.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { ANY_PROCEDURE } from './procedure';
|
2
|
-
export type Context = Record<string, any> | undefined;
|
3
|
-
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
4
|
-
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
5
|
-
export interface WithSignal {
|
6
|
-
signal?: AbortSignal;
|
7
|
-
}
|
8
|
-
export interface Meta extends WithSignal {
|
9
|
-
path: string[];
|
10
|
-
procedure: ANY_PROCEDURE;
|
11
|
-
}
|
12
|
-
//# sourceMappingURL=types.d.ts.map
|