@orpc/server 0.0.0-next.cba521d → 0.0.0-next.ccd4e42
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6RSW63UJ.js +136 -0
- package/dist/chunk-JHLUGXCM.js +294 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/fetch.js +11 -9
- package/dist/hono.js +13 -11
- package/dist/index.js +224 -382
- package/dist/next.js +13 -11
- package/dist/node.js +148 -62
- package/dist/src/adapters/fetch/index.d.ts +2 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +3 -11
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/middleware.d.ts +5 -4
- package/dist/src/adapters/next/serve.d.ts +10 -9
- package/dist/src/adapters/node/index.d.ts +2 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +14 -15
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +33 -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 +50 -29
- 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 +10 -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 +22 -21
- package/dist/src/procedure-client.d.ts +6 -8
- package/dist/src/procedure-decorated.d.ts +10 -15
- package/dist/src/procedure-utils.d.ts +2 -2
- package/dist/src/procedure.d.ts +19 -34
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +6 -10
- package/dist/src/router.d.ts +25 -12
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +16 -0
- package/package.json +12 -3
- package/dist/chunk-3EVCPLVI.js +0 -301
- package/dist/chunk-OUPZ7QGV.js +0 -245
- 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/error.d.ts +0 -10
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-implementer.d.ts +0 -20
- 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 -14
package/dist/chunk-OUPZ7QGV.js
DELETED
@@ -1,245 +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
|
-
if (!errors) {
|
40
|
-
return constructors;
|
41
|
-
}
|
42
|
-
for (const code in errors) {
|
43
|
-
const config = errors[code];
|
44
|
-
if (!config) {
|
45
|
-
continue;
|
46
|
-
}
|
47
|
-
const constructor = (...[options]) => {
|
48
|
-
return new ORPCError({
|
49
|
-
code,
|
50
|
-
defined: true,
|
51
|
-
status: config.status,
|
52
|
-
message: options?.message ?? config.message,
|
53
|
-
data: options?.data,
|
54
|
-
cause: options?.cause
|
55
|
-
});
|
56
|
-
};
|
57
|
-
constructors[code] = constructor;
|
58
|
-
}
|
59
|
-
return constructors;
|
60
|
-
}
|
61
|
-
|
62
|
-
// src/lazy.ts
|
63
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
64
|
-
function lazy(loader) {
|
65
|
-
return {
|
66
|
-
[LAZY_LOADER_SYMBOL]: loader
|
67
|
-
};
|
68
|
-
}
|
69
|
-
function isLazy(item) {
|
70
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
71
|
-
}
|
72
|
-
function unlazy(lazied) {
|
73
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
74
|
-
}
|
75
|
-
function flatLazy(lazied) {
|
76
|
-
const flattenLoader = async () => {
|
77
|
-
let current = await unlazy(lazied);
|
78
|
-
while (true) {
|
79
|
-
if (!isLazy(current.default)) {
|
80
|
-
break;
|
81
|
-
}
|
82
|
-
current = await unlazy(current.default);
|
83
|
-
}
|
84
|
-
return current;
|
85
|
-
};
|
86
|
-
return lazy(flattenLoader);
|
87
|
-
}
|
88
|
-
|
89
|
-
// src/middleware.ts
|
90
|
-
function middlewareOutputFn(output) {
|
91
|
-
return { output, context: void 0 };
|
92
|
-
}
|
93
|
-
|
94
|
-
// src/procedure-client.ts
|
95
|
-
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
96
|
-
import { executeWithHooks, toError, value } from "@orpc/shared";
|
97
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
98
|
-
return async (...[input, callerOptions]) => {
|
99
|
-
const path = options?.path ?? [];
|
100
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
101
|
-
const context = await value(options?.context, callerOptions?.context);
|
102
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap);
|
103
|
-
const executeOptions = {
|
104
|
-
input,
|
105
|
-
context,
|
106
|
-
errors,
|
107
|
-
path,
|
108
|
-
procedure,
|
109
|
-
signal: callerOptions?.signal
|
110
|
-
};
|
111
|
-
try {
|
112
|
-
const output = await executeWithHooks({
|
113
|
-
hooks: options,
|
114
|
-
input,
|
115
|
-
context,
|
116
|
-
meta: executeOptions,
|
117
|
-
execute: () => executeProcedureInternal(procedure, executeOptions)
|
118
|
-
});
|
119
|
-
return output;
|
120
|
-
} catch (e) {
|
121
|
-
if (!(e instanceof ORPCError2)) {
|
122
|
-
throw toError(e);
|
123
|
-
}
|
124
|
-
const validated = await validateORPCError(procedure["~orpc"].contract["~orpc"].errorMap, e);
|
125
|
-
throw validated;
|
126
|
-
}
|
127
|
-
};
|
128
|
-
}
|
129
|
-
async function validateInput(procedure, input) {
|
130
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
131
|
-
if (!schema)
|
132
|
-
return input;
|
133
|
-
const result = await schema["~standard"].validate(input);
|
134
|
-
if (result.issues) {
|
135
|
-
throw new ORPCError2({
|
136
|
-
message: "Input validation failed",
|
137
|
-
code: "BAD_REQUEST",
|
138
|
-
data: {
|
139
|
-
issues: result.issues
|
140
|
-
},
|
141
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
142
|
-
});
|
143
|
-
}
|
144
|
-
return result.value;
|
145
|
-
}
|
146
|
-
async function validateOutput(procedure, output) {
|
147
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
148
|
-
if (!schema)
|
149
|
-
return output;
|
150
|
-
const result = await schema["~standard"].validate(output);
|
151
|
-
if (result.issues) {
|
152
|
-
throw new ORPCError2({
|
153
|
-
message: "Output validation failed",
|
154
|
-
code: "INTERNAL_SERVER_ERROR",
|
155
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
156
|
-
});
|
157
|
-
}
|
158
|
-
return result.value;
|
159
|
-
}
|
160
|
-
function executeMiddlewareChain(middlewares, opt, input) {
|
161
|
-
let currentIndex = 0;
|
162
|
-
let currentContext = opt.context;
|
163
|
-
const executeMiddlewareChain2 = async (nextOptions) => {
|
164
|
-
const mid = middlewares[currentIndex];
|
165
|
-
currentIndex += 1;
|
166
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
167
|
-
if (mid) {
|
168
|
-
return await mid({ ...opt, context: currentContext, next: executeMiddlewareChain2 }, input, middlewareOutputFn);
|
169
|
-
}
|
170
|
-
return opt.next({ context: currentContext });
|
171
|
-
};
|
172
|
-
return executeMiddlewareChain2({});
|
173
|
-
}
|
174
|
-
async function executeProcedureInternal(procedure, options) {
|
175
|
-
const executeHandler = async (context, input) => {
|
176
|
-
return await procedure["~orpc"].handler({ ...options, context, input });
|
177
|
-
};
|
178
|
-
const executePostMiddlewares = async (context, input) => {
|
179
|
-
const validatedInput = await validateInput(procedure, input);
|
180
|
-
const result2 = await executeMiddlewareChain(procedure["~orpc"].postMiddlewares, {
|
181
|
-
...options,
|
182
|
-
context,
|
183
|
-
next: async ({ context: context2 }) => {
|
184
|
-
return middlewareOutputFn(
|
185
|
-
await executeHandler(context2, validatedInput)
|
186
|
-
);
|
187
|
-
}
|
188
|
-
}, validatedInput);
|
189
|
-
const validatedOutput = await validateOutput(procedure, result2.output);
|
190
|
-
return { ...result2, output: validatedOutput };
|
191
|
-
};
|
192
|
-
const result = await executeMiddlewareChain(procedure["~orpc"].preMiddlewares, {
|
193
|
-
...options,
|
194
|
-
context: options.context,
|
195
|
-
next: ({ context }) => executePostMiddlewares(context, options.input)
|
196
|
-
}, options.input);
|
197
|
-
return result.output;
|
198
|
-
}
|
199
|
-
|
200
|
-
// src/router.ts
|
201
|
-
function getRouterChild(router, ...path) {
|
202
|
-
let current = router;
|
203
|
-
for (let i = 0; i < path.length; i++) {
|
204
|
-
const segment = path[i];
|
205
|
-
if (!current) {
|
206
|
-
return void 0;
|
207
|
-
}
|
208
|
-
if (isProcedure(current)) {
|
209
|
-
return void 0;
|
210
|
-
}
|
211
|
-
if (!isLazy(current)) {
|
212
|
-
current = current[segment];
|
213
|
-
continue;
|
214
|
-
}
|
215
|
-
const lazied = current;
|
216
|
-
const rest = path.slice(i);
|
217
|
-
const newLazy = lazy(async () => {
|
218
|
-
const unwrapped = await unlazy(lazied);
|
219
|
-
if (!unwrapped.default) {
|
220
|
-
return unwrapped;
|
221
|
-
}
|
222
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
223
|
-
return { default: next };
|
224
|
-
});
|
225
|
-
return flatLazy(newLazy);
|
226
|
-
}
|
227
|
-
return current;
|
228
|
-
}
|
229
|
-
|
230
|
-
export {
|
231
|
-
__export,
|
232
|
-
mergeContext,
|
233
|
-
Procedure,
|
234
|
-
isProcedure,
|
235
|
-
createORPCErrorConstructorMap,
|
236
|
-
LAZY_LOADER_SYMBOL,
|
237
|
-
lazy,
|
238
|
-
isLazy,
|
239
|
-
unlazy,
|
240
|
-
flatLazy,
|
241
|
-
middlewareOutputFn,
|
242
|
-
createProcedureClient,
|
243
|
-
getRouterChild
|
244
|
-
};
|
245
|
-
//# sourceMappingURL=chunk-OUPZ7QGV.js.map
|
package/dist/chunk-WUOGVGWG.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
//# sourceMappingURL=chunk-WUOGVGWG.js.map
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { Hooks } from '@orpc/shared';
|
2
|
-
import type { Router } from '../../router';
|
3
|
-
import type { Context } from '../../types';
|
4
|
-
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
|
-
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
-
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
-
signal?: AbortSignal;
|
9
|
-
}> & {
|
10
|
-
procedureMatcher?: PublicORPCProcedureMatcher;
|
11
|
-
payloadCodec?: PublicORPCPayloadCodec;
|
12
|
-
};
|
13
|
-
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
-
private readonly options?;
|
15
|
-
private readonly procedureMatcher;
|
16
|
-
private readonly payloadCodec;
|
17
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
|
18
|
-
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
|
-
}
|
20
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { type HTTPMethod } from '@orpc/contract';
|
2
|
-
export declare class ORPCPayloadCodec {
|
3
|
-
/**
|
4
|
-
* If method is GET, the payload will be encoded as query string.
|
5
|
-
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
6
|
-
*/
|
7
|
-
encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
|
8
|
-
query?: URLSearchParams;
|
9
|
-
body?: FormData | string;
|
10
|
-
headers?: Headers;
|
11
|
-
method: HTTPMethod;
|
12
|
-
};
|
13
|
-
decode(re: Request | Response): Promise<unknown>;
|
14
|
-
}
|
15
|
-
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
16
|
-
//# 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,12 +0,0 @@
|
|
1
|
-
import type { ServerResponse } from 'node:http';
|
2
|
-
import type { Router } from '../../router';
|
3
|
-
import type { Context } from '../../types';
|
4
|
-
import type { RPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
-
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
-
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
-
export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
|
8
|
-
private readonly orpcFetchHandler;
|
9
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
10
|
-
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
|
-
}
|
12
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
-
export interface ExpressableIncomingMessage extends IncomingMessage {
|
3
|
-
originalUrl?: string;
|
4
|
-
}
|
5
|
-
/**
|
6
|
-
* Creates a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object from a Node.js
|
7
|
-
* [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) and
|
8
|
-
* [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) pair.
|
9
|
-
*
|
10
|
-
*/
|
11
|
-
export declare function createRequest(req: ExpressableIncomingMessage, res: ServerResponse): Request;
|
12
|
-
/**
|
13
|
-
* Creates a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object from the headers
|
14
|
-
* in a Node.js [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
|
15
|
-
*
|
16
|
-
* @param req The incoming request object.
|
17
|
-
* @returns A headers object.
|
18
|
-
*/
|
19
|
-
export declare function createHeaders(req: IncomingMessage): Headers;
|
20
|
-
/**
|
21
|
-
* Sends a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to the client using the
|
22
|
-
* Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) object.
|
23
|
-
*
|
24
|
-
* @param res The server response object.
|
25
|
-
* @param response The response to send.
|
26
|
-
*/
|
27
|
-
export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
|
28
|
-
//# sourceMappingURL=request-listener.d.ts.map
|
package/dist/src/error.d.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import { ORPCError } from '@orpc/contract';
|
3
|
-
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
|
-
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
5
|
-
export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
|
6
|
-
export type ORPCErrorConstructorMap<T extends ErrorMap> = T extends undefined ? Record<string, unknown> : {
|
7
|
-
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
|
-
};
|
9
|
-
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
10
|
-
//# sourceMappingURL=error.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, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
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, Record<string, unknown>>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
|
-
//# sourceMappingURL=implementer-chainable.d.ts.map
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { Lazy } from './lazy';
|
2
|
-
import { type ANY_ROUTER } from './router';
|
3
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
|
4
|
-
[K in keyof T]: DecoratedLazy<T[K]>;
|
5
|
-
} : unknown);
|
6
|
-
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
7
|
-
//# sourceMappingURL=lazy-decorated.d.ts.map
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { ORPCErrorConstructorMap } from './error';
|
3
|
-
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
-
import type { ProcedureHandler } from './procedure';
|
5
|
-
import type { Context, MergeContext } from './types';
|
6
|
-
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
8
|
-
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
-
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
11
|
-
}
|
12
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
13
|
-
'~type': "ProcedureBuilder";
|
14
|
-
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
-
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
-
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
18
|
-
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
19
|
-
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, UErrorMap>;
|
20
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
21
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
22
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
23
|
-
}
|
24
|
-
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { ORPCErrorConstructorMap } from './error';
|
3
|
-
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
-
import type { ProcedureHandler } from './procedure';
|
5
|
-
import type { Context, MergeContext } from './types';
|
6
|
-
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
-
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
-
preMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
10
|
-
postMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, Record<string, unknown>>[];
|
11
|
-
};
|
12
|
-
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
13
|
-
'~type': "ProcedureImplementer";
|
14
|
-
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
-
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
18
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
19
|
-
}
|
20
|
-
//# 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 { 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, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
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, Record<string, unknown>>[];
|
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, Record<string, 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, Record<string, unknown>>[];
|
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, Record<string, 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,14 +0,0 @@
|
|
1
|
-
import type { FindGlobalInstanceType } from '@orpc/shared';
|
2
|
-
import type { ANY_PROCEDURE } from './procedure';
|
3
|
-
export type Context = Record<string, any> | undefined;
|
4
|
-
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
5
|
-
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
6
|
-
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
7
|
-
export interface WithSignal {
|
8
|
-
signal?: AbortSignal;
|
9
|
-
}
|
10
|
-
export interface Meta extends WithSignal {
|
11
|
-
path: string[];
|
12
|
-
procedure: ANY_PROCEDURE;
|
13
|
-
}
|
14
|
-
//# sourceMappingURL=types.d.ts.map
|