@orpc/server 0.0.0-next.68378b4 → 0.0.0-next.69674a7
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/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/hono/index.d.mts +2 -2
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.mjs +3 -3
- package/dist/adapters/next/index.d.mts +2 -2
- package/dist/adapters/next/index.d.ts +2 -2
- package/dist/adapters/next/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +2 -2
- package/dist/adapters/standard/index.d.mts +4 -4
- package/dist/adapters/standard/index.d.ts +4 -4
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +117 -103
- package/dist/index.d.ts +117 -103
- package/dist/index.mjs +38 -28
- package/dist/plugins/index.d.mts +12 -12
- package/dist/plugins/index.d.ts +12 -12
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/{server.Drm1Lma3.d.ts → server.CM3tWr3C.d.mts} +12 -14
- package/dist/shared/server.CPteJIPP.d.mts +143 -0
- package/dist/shared/server.CPteJIPP.d.ts +143 -0
- package/dist/shared/{server.BHIDiY4a.mjs → server.CXu_v2vM.mjs} +1 -1
- package/dist/shared/{server.CtBp-i4f.d.mts → server.DmW25ynm.d.ts} +12 -14
- package/dist/shared/{server.DKrKGnk2.mjs → server.N2ttmv6r.mjs} +8 -11
- package/dist/shared/{server.V6zT5iYQ.mjs → server.kPUGzsdw.mjs} +130 -152
- package/package.json +7 -7
- package/dist/shared/server.ptXwNGQr.d.mts +0 -158
- package/dist/shared/server.ptXwNGQr.d.ts +0 -158
@@ -1,59 +1,24 @@
|
|
1
|
+
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
1
2
|
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
2
|
-
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, adaptRoute } from '@orpc/contract';
|
3
3
|
import { value, intercept, toError } from '@orpc/shared';
|
4
4
|
|
5
|
-
const
|
6
|
-
function lazy(loader) {
|
5
|
+
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
6
|
+
function lazy(loader, meta = {}) {
|
7
7
|
return {
|
8
|
-
[
|
8
|
+
[LAZY_SYMBOL]: {
|
9
|
+
loader,
|
10
|
+
meta
|
11
|
+
}
|
9
12
|
};
|
10
13
|
}
|
11
14
|
function isLazy(item) {
|
12
|
-
return (typeof item === "object" || typeof item === "function") && item !== null &&
|
13
|
-
}
|
14
|
-
function unlazy(lazied) {
|
15
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
15
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
16
16
|
}
|
17
|
-
|
18
|
-
|
19
|
-
"~orpc";
|
20
|
-
constructor(def) {
|
21
|
-
this["~orpc"] = def;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
function isProcedure(item) {
|
25
|
-
if (item instanceof Procedure) {
|
26
|
-
return true;
|
27
|
-
}
|
28
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
17
|
+
function getLazyMeta(lazied) {
|
18
|
+
return lazied[LAZY_SYMBOL].meta;
|
29
19
|
}
|
30
|
-
|
31
|
-
|
32
|
-
const flattenLoader = async () => {
|
33
|
-
let current = await unlazy(lazied);
|
34
|
-
while (true) {
|
35
|
-
if (!isLazy(current.default)) {
|
36
|
-
break;
|
37
|
-
}
|
38
|
-
current = await unlazy(current.default);
|
39
|
-
}
|
40
|
-
return current;
|
41
|
-
};
|
42
|
-
return lazy(flattenLoader);
|
43
|
-
}
|
44
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
45
|
-
const lazyProcedure = lazy(async () => {
|
46
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
47
|
-
if (!isProcedure(maybeProcedure)) {
|
48
|
-
throw new Error(`
|
49
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
50
|
-
This should be caught by TypeScript compilation.
|
51
|
-
Please report this issue if this makes you feel uncomfortable.
|
52
|
-
`);
|
53
|
-
}
|
54
|
-
return { default: maybeProcedure };
|
55
|
-
});
|
56
|
-
return lazyProcedure;
|
20
|
+
function unlazy(lazied) {
|
21
|
+
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
57
22
|
}
|
58
23
|
|
59
24
|
function dedupeMiddlewares(compare, middlewares) {
|
@@ -74,6 +39,19 @@ function addMiddleware(middlewares, addition) {
|
|
74
39
|
return [...middlewares, addition];
|
75
40
|
}
|
76
41
|
|
42
|
+
class Procedure {
|
43
|
+
"~orpc";
|
44
|
+
constructor(def) {
|
45
|
+
this["~orpc"] = def;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
function isProcedure(item) {
|
49
|
+
if (item instanceof Procedure) {
|
50
|
+
return true;
|
51
|
+
}
|
52
|
+
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
53
|
+
}
|
54
|
+
|
77
55
|
function createORPCErrorConstructorMap(errors) {
|
78
56
|
const proxy = new Proxy(errors, {
|
79
57
|
get(target, code) {
|
@@ -205,169 +183,162 @@ async function executeProcedureInternal(procedure, options) {
|
|
205
183
|
return (await next({})).output;
|
206
184
|
}
|
207
185
|
|
208
|
-
const
|
209
|
-
function
|
210
|
-
return new Proxy(
|
186
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
187
|
+
function setHiddenRouterContract(router, contract) {
|
188
|
+
return new Proxy(router, {
|
211
189
|
get(target, key) {
|
212
|
-
if (key ===
|
190
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
213
191
|
return contract;
|
214
192
|
}
|
215
193
|
return Reflect.get(target, key);
|
216
194
|
}
|
217
195
|
});
|
218
196
|
}
|
219
|
-
function
|
220
|
-
return
|
197
|
+
function getHiddenRouterContract(router) {
|
198
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
221
199
|
}
|
222
|
-
|
223
|
-
function
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
230
|
-
}
|
231
|
-
return val;
|
232
|
-
}
|
233
|
-
return prefix;
|
200
|
+
|
201
|
+
function getRouter(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;
|
234
207
|
}
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
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
|
+
return lazy(async () => {
|
218
|
+
const unwrapped = await unlazy(lazied);
|
219
|
+
const next = getRouter(unwrapped.default, rest);
|
220
|
+
return unlazy(next);
|
221
|
+
}, getLazyMeta(lazied));
|
222
|
+
}
|
223
|
+
return current;
|
239
224
|
}
|
240
|
-
|
241
225
|
function createAccessibleLazyRouter(lazied) {
|
242
|
-
const
|
243
|
-
const recursive = new Proxy(flattenLazy, {
|
226
|
+
const recursive = new Proxy(lazied, {
|
244
227
|
get(target, key) {
|
245
228
|
if (typeof key !== "string") {
|
246
229
|
return Reflect.get(target, key);
|
247
230
|
}
|
248
|
-
const next =
|
231
|
+
const next = getRouter(lazied, [key]);
|
249
232
|
return createAccessibleLazyRouter(next);
|
250
233
|
}
|
251
234
|
});
|
252
235
|
return recursive;
|
253
236
|
}
|
254
|
-
|
255
|
-
function adaptRouter(router, options) {
|
237
|
+
function enhanceRouter(router, options) {
|
256
238
|
if (isLazy(router)) {
|
257
|
-
const
|
258
|
-
|
259
|
-
|
260
|
-
|
239
|
+
const laziedMeta = getLazyMeta(router);
|
240
|
+
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
241
|
+
const enhanced2 = lazy(async () => {
|
242
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
243
|
+
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
244
|
+
return unlazy(enhanced3);
|
245
|
+
}, {
|
246
|
+
...laziedMeta,
|
247
|
+
prefix: enhancedPrefix
|
261
248
|
});
|
262
|
-
const accessible = createAccessibleLazyRouter(
|
263
|
-
const currentPrefix = getLazyRouterPrefix(router);
|
264
|
-
const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
|
265
|
-
if (prefix) {
|
266
|
-
return deepSetLazyRouterPrefix(accessible, prefix);
|
267
|
-
}
|
249
|
+
const accessible = createAccessibleLazyRouter(enhanced2);
|
268
250
|
return accessible;
|
269
251
|
}
|
270
252
|
if (isProcedure(router)) {
|
271
253
|
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
272
254
|
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
273
|
-
const
|
255
|
+
const enhanced2 = new Procedure({
|
274
256
|
...router["~orpc"],
|
275
|
-
route:
|
257
|
+
route: enhanceRoute(router["~orpc"].route, options),
|
276
258
|
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
277
259
|
middlewares: newMiddlewares,
|
278
260
|
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
279
261
|
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
280
262
|
});
|
281
|
-
return
|
263
|
+
return enhanced2;
|
282
264
|
}
|
283
|
-
const
|
265
|
+
const enhanced = {};
|
284
266
|
for (const key in router) {
|
285
|
-
|
286
|
-
}
|
287
|
-
return adapted;
|
288
|
-
}
|
289
|
-
function getRouterChild(router, ...path) {
|
290
|
-
let current = router;
|
291
|
-
for (let i = 0; i < path.length; i++) {
|
292
|
-
const segment = path[i];
|
293
|
-
if (!current) {
|
294
|
-
return void 0;
|
295
|
-
}
|
296
|
-
if (isProcedure(current)) {
|
297
|
-
return void 0;
|
298
|
-
}
|
299
|
-
if (!isLazy(current)) {
|
300
|
-
current = current[segment];
|
301
|
-
continue;
|
302
|
-
}
|
303
|
-
const lazied = current;
|
304
|
-
const rest = path.slice(i);
|
305
|
-
const newLazy = lazy(async () => {
|
306
|
-
const unwrapped = await unlazy(lazied);
|
307
|
-
if (!unwrapped.default) {
|
308
|
-
return unwrapped;
|
309
|
-
}
|
310
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
311
|
-
return { default: next };
|
312
|
-
});
|
313
|
-
return flatLazy(newLazy);
|
267
|
+
enhanced[key] = enhanceRouter(router[key], options);
|
314
268
|
}
|
315
|
-
return
|
269
|
+
return enhanced;
|
316
270
|
}
|
317
|
-
|
318
|
-
|
319
|
-
const hiddenContract =
|
320
|
-
if (hiddenContract) {
|
321
|
-
|
322
|
-
{
|
323
|
-
router: hiddenContract,
|
324
|
-
path: options.path
|
325
|
-
},
|
326
|
-
callback,
|
327
|
-
laziedOptions
|
328
|
-
);
|
271
|
+
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
272
|
+
let currentRouter = options.router;
|
273
|
+
const hiddenContract = getHiddenRouterContract(options.router);
|
274
|
+
if (hiddenContract !== void 0) {
|
275
|
+
currentRouter = hiddenContract;
|
329
276
|
}
|
330
|
-
if (isLazy(
|
331
|
-
|
332
|
-
|
277
|
+
if (isLazy(currentRouter)) {
|
278
|
+
lazyOptions.push({
|
279
|
+
router: currentRouter,
|
333
280
|
path: options.path
|
334
281
|
});
|
335
|
-
} else if (isContractProcedure(
|
282
|
+
} else if (isContractProcedure(currentRouter)) {
|
336
283
|
callback({
|
337
|
-
contract:
|
284
|
+
contract: currentRouter,
|
338
285
|
path: options.path
|
339
286
|
});
|
340
287
|
} else {
|
341
|
-
for (const key in
|
342
|
-
|
288
|
+
for (const key in currentRouter) {
|
289
|
+
traverseContractProcedures(
|
343
290
|
{
|
344
|
-
router:
|
291
|
+
router: currentRouter[key],
|
345
292
|
path: [...options.path, key]
|
346
293
|
},
|
347
294
|
callback,
|
348
|
-
|
295
|
+
lazyOptions
|
349
296
|
);
|
350
297
|
}
|
351
298
|
}
|
352
|
-
return
|
299
|
+
return lazyOptions;
|
353
300
|
}
|
354
|
-
async function
|
301
|
+
async function resolveContractProcedures(options, callback) {
|
355
302
|
const pending = [options];
|
356
|
-
for (const
|
357
|
-
const
|
358
|
-
for (const
|
359
|
-
const { default: router } = await unlazy(
|
303
|
+
for (const options2 of pending) {
|
304
|
+
const lazyOptions = traverseContractProcedures(options2, callback);
|
305
|
+
for (const options3 of lazyOptions) {
|
306
|
+
const { default: router } = await unlazy(options3.router);
|
360
307
|
pending.push({
|
361
|
-
|
362
|
-
|
308
|
+
router,
|
309
|
+
path: options3.path
|
363
310
|
});
|
364
311
|
}
|
365
312
|
}
|
366
313
|
}
|
367
|
-
function
|
368
|
-
|
314
|
+
async function unlazyRouter(router) {
|
315
|
+
if (isProcedure(router)) {
|
316
|
+
return router;
|
317
|
+
}
|
318
|
+
const unlazied = {};
|
319
|
+
for (const key in router) {
|
320
|
+
const item = router[key];
|
321
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
322
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
323
|
+
}
|
324
|
+
return unlazied;
|
369
325
|
}
|
370
|
-
|
326
|
+
|
327
|
+
function createAssertedLazyProcedure(lazied) {
|
328
|
+
const lazyProcedure = lazy(async () => {
|
329
|
+
const { default: maybeProcedure } = await unlazy(lazied);
|
330
|
+
if (!isProcedure(maybeProcedure)) {
|
331
|
+
throw new Error(`
|
332
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
333
|
+
This should be caught by TypeScript compilation.
|
334
|
+
Please report this issue if this makes you feel uncomfortable.
|
335
|
+
`);
|
336
|
+
}
|
337
|
+
return { default: maybeProcedure };
|
338
|
+
}, getLazyMeta(lazied));
|
339
|
+
return lazyProcedure;
|
340
|
+
}
|
341
|
+
function createContractedProcedure(procedure, contract) {
|
371
342
|
return new Procedure({
|
372
343
|
...procedure["~orpc"],
|
373
344
|
errorMap: contract["~orpc"].errorMap,
|
@@ -375,5 +346,12 @@ function createContractedProcedure(contract, procedure) {
|
|
375
346
|
meta: contract["~orpc"].meta
|
376
347
|
});
|
377
348
|
}
|
349
|
+
function call(procedure, input, ...rest) {
|
350
|
+
return createProcedureClient(procedure, ...rest)(input);
|
351
|
+
}
|
352
|
+
|
353
|
+
function toHttpPath(path) {
|
354
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
355
|
+
}
|
378
356
|
|
379
|
-
export {
|
357
|
+
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, getLazyMeta as j, call as k, lazy as l, middlewareOutputFn as m, getHiddenRouterContract as n, createAccessibleLazyRouter as o, unlazyRouter as p, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };
|
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.69674a7",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,12 +58,12 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/
|
66
|
-
"@orpc/
|
61
|
+
"@orpc/standard-server": "0.0.0-next.69674a7",
|
62
|
+
"@orpc/standard-server-fetch": "0.0.0-next.69674a7",
|
63
|
+
"@orpc/standard-server-node": "0.0.0-next.69674a7",
|
64
|
+
"@orpc/client": "0.0.0-next.69674a7",
|
65
|
+
"@orpc/shared": "0.0.0-next.69674a7",
|
66
|
+
"@orpc/contract": "0.0.0-next.69674a7"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"light-my-request": "^6.5.1"
|
@@ -1,158 +0,0 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
-
import { ErrorMap, ErrorMapItem, SchemaInput, HTTPPath, Meta, Schema, ContractProcedureDef, SchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure, MergedErrorMap } from '@orpc/contract';
|
4
|
-
|
5
|
-
type Context = Record<string, any>;
|
6
|
-
type MergedContext<T extends Context, U extends Context> = T & U;
|
7
|
-
declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
8
|
-
type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
9
|
-
[K in keyof T]: IsNever<T[K]>;
|
10
|
-
}[keyof T] ? never : unknown;
|
11
|
-
|
12
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
|
-
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
16
|
-
};
|
17
|
-
|
18
|
-
declare const LAZY_LOADER_SYMBOL: unique symbol;
|
19
|
-
interface LazyMeta {
|
20
|
-
prefix?: HTTPPath;
|
21
|
-
}
|
22
|
-
interface Lazy<T> {
|
23
|
-
[LAZY_LOADER_SYMBOL](): Promise<{
|
24
|
-
default: T;
|
25
|
-
}>;
|
26
|
-
}
|
27
|
-
type Lazyable<T> = T | Lazy<T>;
|
28
|
-
interface LazyOptions {
|
29
|
-
prefix?: HTTPPath;
|
30
|
-
}
|
31
|
-
declare function lazy<T>(loader: () => Promise<{
|
32
|
-
default: T;
|
33
|
-
}>): Lazy<T>;
|
34
|
-
declare function isLazy(item: unknown): item is Lazy<any>;
|
35
|
-
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
36
|
-
default: T extends Lazy<infer U> ? U : T;
|
37
|
-
}>;
|
38
|
-
|
39
|
-
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
40
|
-
output: TOutput;
|
41
|
-
context: TOutContext;
|
42
|
-
}>;
|
43
|
-
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
44
|
-
context?: TOutContext;
|
45
|
-
} : {
|
46
|
-
context: TOutContext;
|
47
|
-
};
|
48
|
-
interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
49
|
-
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
50
|
-
}
|
51
|
-
interface MiddlewareOutputFn<TOutput> {
|
52
|
-
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
53
|
-
}
|
54
|
-
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
55
|
-
context: TInContext;
|
56
|
-
path: string[];
|
57
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
58
|
-
signal?: AbortSignal;
|
59
|
-
lastEventId: string | undefined;
|
60
|
-
next: MiddlewareNextFn<TInContext, TOutput>;
|
61
|
-
errors: TErrorConstructorMap;
|
62
|
-
}
|
63
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
64
|
-
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
65
|
-
}
|
66
|
-
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
67
|
-
interface MapInputMiddleware<TInput, TMappedInput> {
|
68
|
-
(input: TInput): TMappedInput;
|
69
|
-
}
|
70
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
71
|
-
|
72
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
73
|
-
context: TCurrentContext;
|
74
|
-
input: TInput;
|
75
|
-
path: string[];
|
76
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
77
|
-
signal?: AbortSignal;
|
78
|
-
lastEventId: string | undefined;
|
79
|
-
errors: TErrorConstructorMap;
|
80
|
-
}
|
81
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
82
|
-
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
83
|
-
}
|
84
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
85
|
-
__initialContext?: (type: TInitialContext) => unknown;
|
86
|
-
middlewares: AnyMiddleware[];
|
87
|
-
inputValidationIndex: number;
|
88
|
-
outputValidationIndex: number;
|
89
|
-
handler: ProcedureHandler<TCurrentContext, any, THandlerOutput, any, any>;
|
90
|
-
}
|
91
|
-
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
92
|
-
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
93
|
-
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
94
|
-
}
|
95
|
-
type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
96
|
-
declare function isProcedure(item: unknown): item is AnyProcedure;
|
97
|
-
|
98
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
99
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
100
|
-
context: TInitialContext;
|
101
|
-
input: SchemaInput<TInputSchema>;
|
102
|
-
errors: ORPCErrorConstructorMap<TErrorMap>;
|
103
|
-
path: string[];
|
104
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
105
|
-
signal?: AbortSignal;
|
106
|
-
lastEventId: string | undefined;
|
107
|
-
}
|
108
|
-
/**
|
109
|
-
* Options for creating a procedure caller with comprehensive type safety
|
110
|
-
*/
|
111
|
-
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
112
|
-
/**
|
113
|
-
* This is helpful for logging and analytics.
|
114
|
-
*/
|
115
|
-
path?: string[];
|
116
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
|
117
|
-
} & (Record<never, never> extends TInitialContext ? {
|
118
|
-
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
119
|
-
} : {
|
120
|
-
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
-
});
|
122
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
123
|
-
|
124
|
-
type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
125
|
-
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
126
|
-
});
|
127
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
128
|
-
|
129
|
-
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> : {
|
130
|
-
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
131
|
-
}>;
|
132
|
-
type AnyRouter = Router<any, any>;
|
133
|
-
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
|
134
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : T extends Procedure<infer UInitialContext, any, any, any, any, any, any> ? UInitialContext : {
|
135
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInitialContexts<T[K]> : never;
|
136
|
-
};
|
137
|
-
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : T extends Procedure<any, infer UCurrentContext, any, any, any, any, any> ? UCurrentContext : {
|
138
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterCurrentContexts<T[K]> : never;
|
139
|
-
};
|
140
|
-
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> : {
|
141
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
142
|
-
};
|
143
|
-
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> : {
|
144
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
145
|
-
};
|
146
|
-
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> : {
|
147
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
148
|
-
};
|
149
|
-
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
150
|
-
middlewares: AnyMiddleware[];
|
151
|
-
tags?: readonly string[];
|
152
|
-
prefix?: HTTPPath;
|
153
|
-
errorMap: TErrorMap;
|
154
|
-
}
|
155
|
-
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
156
|
-
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;
|
157
|
-
|
158
|
-
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInitialContexts as F, type InferRouterCurrentContexts as G, type InferRouterInputs as H, type InferRouterInitialContext as I, type InferRouterOutputs as J, adaptRouter as K, type Lazy as L, type Middleware as M, getRouterChild as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type AccessibleLazyRouter as Q, type Router as R, createAccessibleLazyRouter as S, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type ProcedureHandler as h, type AdaptRouterOptions as i, type AdaptedRouter as j, type AnyMiddleware as k, type Lazyable as l, mergeContext as m, LAZY_LOADER_SYMBOL as n, type LazyMeta as o, type LazyOptions as p, lazy as q, isLazy as r, type MiddlewareResult as s, type MiddlewareNextFnOptions as t, unlazy as u, type MiddlewareNextFn as v, type MiddlewareOutputFn as w, type MiddlewareOptions as x, middlewareOutputFn as y, type ProcedureHandlerOptions as z };
|