@orpc/server 0.0.0-next.df024bb → 0.0.0-next.df486d6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/adapters/fetch/index.d.mts +43 -11
- package/dist/adapters/fetch/index.d.ts +43 -11
- package/dist/adapters/fetch/index.mjs +103 -7
- package/dist/adapters/node/index.d.mts +45 -22
- package/dist/adapters/node/index.d.ts +45 -22
- package/dist/adapters/node/index.mjs +81 -21
- package/dist/adapters/standard/index.d.mts +12 -15
- package/dist/adapters/standard/index.d.ts +12 -15
- package/dist/adapters/standard/index.mjs +6 -5
- package/dist/index.d.mts +161 -124
- package/dist/index.d.ts +161 -124
- package/dist/index.mjs +78 -48
- package/dist/plugins/index.d.mts +112 -18
- package/dist/plugins/index.d.ts +112 -18
- package/dist/plugins/index.mjs +157 -8
- package/dist/shared/server.B1oIHH_j.d.mts +74 -0
- package/dist/shared/server.BVHsfJ99.d.mts +144 -0
- package/dist/shared/server.BVHsfJ99.d.ts +144 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BuLPHTX1.d.mts +18 -0
- package/dist/shared/{server.V6zT5iYQ.mjs → server.C37gDhSZ.mjs} +158 -173
- package/dist/shared/server.CaWivVk3.d.ts +74 -0
- package/dist/shared/server.DFuJLDuo.mjs +190 -0
- package/dist/shared/server.DMhSfHk1.d.ts +10 -0
- package/dist/shared/server.D_vpYits.d.ts +18 -0
- package/dist/shared/server.Dwnm6cSk.d.mts +10 -0
- package/package.json +8 -22
- package/dist/adapters/hono/index.d.mts +0 -20
- package/dist/adapters/hono/index.d.ts +0 -20
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -27
- package/dist/adapters/next/index.d.ts +0 -27
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.BBGuTxHE.mjs +0 -163
- package/dist/shared/server.BMaJxq9W.d.mts +0 -9
- package/dist/shared/server.BT-fqIEm.d.mts +0 -77
- package/dist/shared/server.DpdgHO1j.d.ts +0 -9
- package/dist/shared/server.KwueCzFr.mjs +0 -26
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
- package/dist/shared/server.ptXwNGQr.d.mts +0 -158
- package/dist/shared/server.ptXwNGQr.d.ts +0 -158
- package/dist/shared/server.xL87pHsk.d.ts +0 -77
@@ -1,18 +1,48 @@
|
|
1
|
+
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
1
2
|
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import { value, intercept, toError } from '@orpc/shared';
|
3
|
+
import { value, intercept } 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 &&
|
15
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
16
|
+
}
|
17
|
+
function getLazyMeta(lazied) {
|
18
|
+
return lazied[LAZY_SYMBOL].meta;
|
13
19
|
}
|
14
20
|
function unlazy(lazied) {
|
15
|
-
return isLazy(lazied) ? lazied[
|
21
|
+
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
22
|
+
}
|
23
|
+
|
24
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
25
|
+
if (compare.length > middlewares.length) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
for (let i = 0; i < middlewares.length; i++) {
|
29
|
+
if (compare[i] === void 0) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (middlewares[i] !== compare[i]) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
function mergeMiddlewares(first, second, options) {
|
39
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
40
|
+
return second;
|
41
|
+
}
|
42
|
+
return [...first, ...second];
|
43
|
+
}
|
44
|
+
function addMiddleware(middlewares, addition) {
|
45
|
+
return [...middlewares, addition];
|
16
46
|
}
|
17
47
|
|
18
48
|
class Procedure {
|
@@ -28,50 +58,8 @@ function isProcedure(item) {
|
|
28
58
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
29
59
|
}
|
30
60
|
|
31
|
-
function
|
32
|
-
|
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;
|
57
|
-
}
|
58
|
-
|
59
|
-
function dedupeMiddlewares(compare, middlewares) {
|
60
|
-
let min = 0;
|
61
|
-
for (let i = 0; i < middlewares.length; i++) {
|
62
|
-
const index = compare.indexOf(middlewares[i], min);
|
63
|
-
if (index === -1) {
|
64
|
-
return middlewares.slice(i);
|
65
|
-
}
|
66
|
-
min = index + 1;
|
67
|
-
}
|
68
|
-
return [];
|
69
|
-
}
|
70
|
-
function mergeMiddlewares(first, second) {
|
71
|
-
return [...first, ...dedupeMiddlewares(first, second)];
|
72
|
-
}
|
73
|
-
function addMiddleware(middlewares, addition) {
|
74
|
-
return [...middlewares, addition];
|
61
|
+
function mergeCurrentContext(context, other) {
|
62
|
+
return { ...context, ...other };
|
75
63
|
}
|
76
64
|
|
77
65
|
function createORPCErrorConstructorMap(errors) {
|
@@ -139,7 +127,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
139
127
|
);
|
140
128
|
} catch (e) {
|
141
129
|
if (!(e instanceof ORPCError)) {
|
142
|
-
throw
|
130
|
+
throw e;
|
143
131
|
}
|
144
132
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
145
133
|
throw validated;
|
@@ -181,193 +169,187 @@ async function executeProcedureInternal(procedure, options) {
|
|
181
169
|
const middlewares = procedure["~orpc"].middlewares;
|
182
170
|
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
183
171
|
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
184
|
-
|
185
|
-
|
186
|
-
let currentInput = options.input;
|
187
|
-
const next = async (...[nextOptions]) => {
|
188
|
-
const index = currentIndex;
|
189
|
-
currentIndex += 1;
|
190
|
-
currentContext = { ...currentContext, ...nextOptions?.context };
|
172
|
+
const next = async (index, context, input) => {
|
173
|
+
let currentInput = input;
|
191
174
|
if (index === inputValidationIndex) {
|
192
175
|
currentInput = await validateInput(procedure, currentInput);
|
193
176
|
}
|
194
177
|
const mid = middlewares[index];
|
195
|
-
const
|
178
|
+
const output = mid ? (await mid({
|
179
|
+
...options,
|
180
|
+
context,
|
181
|
+
next: async (...[nextOptions]) => {
|
182
|
+
const nextContext = nextOptions?.context ?? {};
|
183
|
+
return {
|
184
|
+
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
185
|
+
context: nextContext
|
186
|
+
};
|
187
|
+
}
|
188
|
+
}, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
|
196
189
|
if (index === outputValidationIndex) {
|
197
|
-
|
198
|
-
return {
|
199
|
-
...result,
|
200
|
-
output: validatedOutput
|
201
|
-
};
|
190
|
+
return await validateOutput(procedure, output);
|
202
191
|
}
|
203
|
-
return
|
192
|
+
return output;
|
204
193
|
};
|
205
|
-
return (
|
194
|
+
return next(0, options.context, options.input);
|
206
195
|
}
|
207
196
|
|
208
|
-
const
|
209
|
-
function
|
210
|
-
return new Proxy(
|
197
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
198
|
+
function setHiddenRouterContract(router, contract) {
|
199
|
+
return new Proxy(router, {
|
211
200
|
get(target, key) {
|
212
|
-
if (key ===
|
201
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
213
202
|
return contract;
|
214
203
|
}
|
215
204
|
return Reflect.get(target, key);
|
216
205
|
}
|
217
206
|
});
|
218
207
|
}
|
219
|
-
function
|
220
|
-
return
|
208
|
+
function getHiddenRouterContract(router) {
|
209
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
221
210
|
}
|
222
|
-
|
223
|
-
function
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
230
|
-
}
|
231
|
-
return val;
|
232
|
-
}
|
233
|
-
return prefix;
|
211
|
+
|
212
|
+
function getRouter(router, path) {
|
213
|
+
let current = router;
|
214
|
+
for (let i = 0; i < path.length; i++) {
|
215
|
+
const segment = path[i];
|
216
|
+
if (!current) {
|
217
|
+
return void 0;
|
234
218
|
}
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
219
|
+
if (isProcedure(current)) {
|
220
|
+
return void 0;
|
221
|
+
}
|
222
|
+
if (!isLazy(current)) {
|
223
|
+
current = current[segment];
|
224
|
+
continue;
|
225
|
+
}
|
226
|
+
const lazied = current;
|
227
|
+
const rest = path.slice(i);
|
228
|
+
return lazy(async () => {
|
229
|
+
const unwrapped = await unlazy(lazied);
|
230
|
+
const next = getRouter(unwrapped.default, rest);
|
231
|
+
return unlazy(next);
|
232
|
+
}, getLazyMeta(lazied));
|
233
|
+
}
|
234
|
+
return current;
|
239
235
|
}
|
240
|
-
|
241
236
|
function createAccessibleLazyRouter(lazied) {
|
242
|
-
const
|
243
|
-
const recursive = new Proxy(flattenLazy, {
|
237
|
+
const recursive = new Proxy(lazied, {
|
244
238
|
get(target, key) {
|
245
239
|
if (typeof key !== "string") {
|
246
240
|
return Reflect.get(target, key);
|
247
241
|
}
|
248
|
-
const next =
|
242
|
+
const next = getRouter(lazied, [key]);
|
249
243
|
return createAccessibleLazyRouter(next);
|
250
244
|
}
|
251
245
|
});
|
252
246
|
return recursive;
|
253
247
|
}
|
254
|
-
|
255
|
-
function adaptRouter(router, options) {
|
248
|
+
function enhanceRouter(router, options) {
|
256
249
|
if (isLazy(router)) {
|
257
|
-
const
|
258
|
-
|
259
|
-
|
260
|
-
|
250
|
+
const laziedMeta = getLazyMeta(router);
|
251
|
+
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
252
|
+
const enhanced2 = lazy(async () => {
|
253
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
254
|
+
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
255
|
+
return unlazy(enhanced3);
|
256
|
+
}, {
|
257
|
+
...laziedMeta,
|
258
|
+
prefix: enhancedPrefix
|
261
259
|
});
|
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
|
-
}
|
260
|
+
const accessible = createAccessibleLazyRouter(enhanced2);
|
268
261
|
return accessible;
|
269
262
|
}
|
270
263
|
if (isProcedure(router)) {
|
271
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
264
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
272
265
|
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
273
|
-
const
|
266
|
+
const enhanced2 = new Procedure({
|
274
267
|
...router["~orpc"],
|
275
|
-
route:
|
268
|
+
route: enhanceRoute(router["~orpc"].route, options),
|
276
269
|
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
277
270
|
middlewares: newMiddlewares,
|
278
271
|
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
279
272
|
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
280
273
|
});
|
281
|
-
return
|
274
|
+
return enhanced2;
|
282
275
|
}
|
283
|
-
const
|
276
|
+
const enhanced = {};
|
284
277
|
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);
|
278
|
+
enhanced[key] = enhanceRouter(router[key], options);
|
314
279
|
}
|
315
|
-
return
|
280
|
+
return enhanced;
|
316
281
|
}
|
317
|
-
|
318
|
-
|
319
|
-
const hiddenContract =
|
320
|
-
if (hiddenContract) {
|
321
|
-
|
322
|
-
{
|
323
|
-
router: hiddenContract,
|
324
|
-
path: options.path
|
325
|
-
},
|
326
|
-
callback,
|
327
|
-
laziedOptions
|
328
|
-
);
|
282
|
+
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
283
|
+
let currentRouter = options.router;
|
284
|
+
const hiddenContract = getHiddenRouterContract(options.router);
|
285
|
+
if (hiddenContract !== void 0) {
|
286
|
+
currentRouter = hiddenContract;
|
329
287
|
}
|
330
|
-
if (isLazy(
|
331
|
-
|
332
|
-
|
288
|
+
if (isLazy(currentRouter)) {
|
289
|
+
lazyOptions.push({
|
290
|
+
router: currentRouter,
|
333
291
|
path: options.path
|
334
292
|
});
|
335
|
-
} else if (isContractProcedure(
|
293
|
+
} else if (isContractProcedure(currentRouter)) {
|
336
294
|
callback({
|
337
|
-
contract:
|
295
|
+
contract: currentRouter,
|
338
296
|
path: options.path
|
339
297
|
});
|
340
298
|
} else {
|
341
|
-
for (const key in
|
342
|
-
|
299
|
+
for (const key in currentRouter) {
|
300
|
+
traverseContractProcedures(
|
343
301
|
{
|
344
|
-
router:
|
302
|
+
router: currentRouter[key],
|
345
303
|
path: [...options.path, key]
|
346
304
|
},
|
347
305
|
callback,
|
348
|
-
|
306
|
+
lazyOptions
|
349
307
|
);
|
350
308
|
}
|
351
309
|
}
|
352
|
-
return
|
310
|
+
return lazyOptions;
|
353
311
|
}
|
354
|
-
async function
|
312
|
+
async function resolveContractProcedures(options, callback) {
|
355
313
|
const pending = [options];
|
356
|
-
for (const
|
357
|
-
const
|
358
|
-
for (const
|
359
|
-
const { default: router } = await unlazy(
|
314
|
+
for (const options2 of pending) {
|
315
|
+
const lazyOptions = traverseContractProcedures(options2, callback);
|
316
|
+
for (const options3 of lazyOptions) {
|
317
|
+
const { default: router } = await unlazy(options3.router);
|
360
318
|
pending.push({
|
361
|
-
|
362
|
-
|
319
|
+
router,
|
320
|
+
path: options3.path
|
363
321
|
});
|
364
322
|
}
|
365
323
|
}
|
366
324
|
}
|
367
|
-
function
|
368
|
-
|
325
|
+
async function unlazyRouter(router) {
|
326
|
+
if (isProcedure(router)) {
|
327
|
+
return router;
|
328
|
+
}
|
329
|
+
const unlazied = {};
|
330
|
+
for (const key in router) {
|
331
|
+
const item = router[key];
|
332
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
333
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
334
|
+
}
|
335
|
+
return unlazied;
|
369
336
|
}
|
370
|
-
|
337
|
+
|
338
|
+
function createAssertedLazyProcedure(lazied) {
|
339
|
+
const lazyProcedure = lazy(async () => {
|
340
|
+
const { default: maybeProcedure } = await unlazy(lazied);
|
341
|
+
if (!isProcedure(maybeProcedure)) {
|
342
|
+
throw new Error(`
|
343
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
344
|
+
This should be caught by TypeScript compilation.
|
345
|
+
Please report this issue if this makes you feel uncomfortable.
|
346
|
+
`);
|
347
|
+
}
|
348
|
+
return { default: maybeProcedure };
|
349
|
+
}, getLazyMeta(lazied));
|
350
|
+
return lazyProcedure;
|
351
|
+
}
|
352
|
+
function createContractedProcedure(procedure, contract) {
|
371
353
|
return new Procedure({
|
372
354
|
...procedure["~orpc"],
|
373
355
|
errorMap: contract["~orpc"].errorMap,
|
@@ -375,5 +357,8 @@ function createContractedProcedure(contract, procedure) {
|
|
375
357
|
meta: contract["~orpc"].meta
|
376
358
|
});
|
377
359
|
}
|
360
|
+
function call(procedure, input, ...rest) {
|
361
|
+
return createProcedureClient(procedure, ...rest)(input);
|
362
|
+
}
|
378
363
|
|
379
|
-
export {
|
364
|
+
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
+
import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
|
3
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
4
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
5
|
+
import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.js';
|
6
|
+
|
7
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
8
|
+
order?: number;
|
9
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
10
|
+
}
|
11
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
12
|
+
protected readonly plugins: TPlugin[];
|
13
|
+
constructor(plugins?: readonly TPlugin[]);
|
14
|
+
init(options: StandardHandlerOptions<T>): void;
|
15
|
+
}
|
16
|
+
|
17
|
+
type StandardParams = Record<string, string>;
|
18
|
+
type StandardMatchResult = {
|
19
|
+
path: readonly string[];
|
20
|
+
procedure: AnyProcedure;
|
21
|
+
params?: StandardParams;
|
22
|
+
} | undefined;
|
23
|
+
interface StandardMatcher {
|
24
|
+
init(router: AnyRouter): void;
|
25
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
26
|
+
}
|
27
|
+
interface StandardCodec {
|
28
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
29
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
30
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
31
|
+
}
|
32
|
+
|
33
|
+
interface StandardHandleOptions<T extends Context> {
|
34
|
+
prefix?: HTTPPath;
|
35
|
+
context: T;
|
36
|
+
}
|
37
|
+
type StandardHandleResult = {
|
38
|
+
matched: true;
|
39
|
+
response: StandardResponse;
|
40
|
+
} | {
|
41
|
+
matched: false;
|
42
|
+
response: undefined;
|
43
|
+
};
|
44
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
45
|
+
request: StandardLazyRequest;
|
46
|
+
}
|
47
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
48
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
49
|
+
/**
|
50
|
+
* Interceptors at the request level, helpful when you want catch errors
|
51
|
+
*/
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
53
|
+
/**
|
54
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
55
|
+
*/
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
57
|
+
/**
|
58
|
+
*
|
59
|
+
* Interceptors for procedure client.
|
60
|
+
*/
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
62
|
+
}
|
63
|
+
declare class StandardHandler<T extends Context> {
|
64
|
+
private readonly matcher;
|
65
|
+
private readonly codec;
|
66
|
+
private readonly interceptors;
|
67
|
+
private readonly clientInterceptors;
|
68
|
+
private readonly rootInterceptors;
|
69
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
70
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
71
|
+
}
|
72
|
+
|
73
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
|
74
|
+
export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
|