@orpc/server 0.0.0-next.d74cac4 → 0.0.0-next.d760838
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 +131 -0
- package/dist/adapters/fetch/index.d.mts +54 -0
- package/dist/adapters/fetch/index.d.ts +54 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +22 -0
- package/dist/adapters/hono/index.d.ts +22 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
- package/dist/adapters/next/index.d.mts +29 -0
- package/dist/adapters/next/index.d.ts +29 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -13
- package/dist/adapters/node/index.d.mts +53 -0
- package/dist/adapters/node/index.d.ts +53 -0
- package/dist/adapters/node/index.mjs +85 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/{index.js → index.mjs} +107 -156
- package/dist/plugins/index.d.mts +66 -0
- package/dist/plugins/index.d.ts +66 -0
- package/dist/plugins/index.mjs +196 -0
- package/dist/shared/server.BFt8M4Cr.d.ts +8 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.Bc6jnvPE.d.ts +10 -0
- package/dist/shared/server.BlxK0o8R.d.mts +66 -0
- package/dist/shared/server.C37gDhSZ.mjs +364 -0
- package/dist/shared/server.CCPFkKqC.mjs +98 -0
- package/dist/shared/server.CCgy73tk.d.mts +10 -0
- package/dist/shared/server.DJrRF9vD.mjs +162 -0
- package/dist/shared/server.DLt5njUb.d.mts +143 -0
- package/dist/shared/server.DLt5njUb.d.ts +143 -0
- package/dist/shared/server.DuTpqr2w.d.ts +66 -0
- package/dist/shared/server.JgWzFqlo.d.mts +8 -0
- package/package.json +30 -34
- package/dist/chunk-L4ESXQX7.js +0 -32
- package/dist/chunk-NXEANHUK.js +0 -351
- package/dist/chunk-XI6WGCB3.js +0 -125
- package/dist/chunk-XXBE6CYD.js +0 -379
- package/dist/fetch.js +0 -10
- package/dist/node.js +0 -31
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/fetch/types.d.ts +0 -14
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/adapters/standard/handler.d.ts +0 -51
- package/dist/src/adapters/standard/index.d.ts +0 -7
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -22
- package/dist/src/adapters/standard/types.d.ts +0 -20
- package/dist/src/builder-variants.d.ts +0 -74
- package/dist/src/builder.d.ts +0 -57
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -8
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -31
- package/dist/src/implementer-variants.d.ts +0 -17
- package/dist/src/implementer.d.ts +0 -28
- package/dist/src/index.d.ts +0 -24
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -10
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -37
- package/dist/src/plugins/base.d.ts +0 -13
- package/dist/src/plugins/cors.d.ts +0 -19
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/procedure-client.d.ts +0 -31
- package/dist/src/procedure-decorated.d.ts +0 -22
- package/dist/src/procedure-utils.d.ts +0 -18
- package/dist/src/procedure.d.ts +0 -30
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -11
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -17
package/dist/chunk-XXBE6CYD.js
DELETED
@@ -1,379 +0,0 @@
|
|
1
|
-
// src/lazy.ts
|
2
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
3
|
-
function lazy(loader) {
|
4
|
-
return {
|
5
|
-
[LAZY_LOADER_SYMBOL]: loader
|
6
|
-
};
|
7
|
-
}
|
8
|
-
function isLazy(item) {
|
9
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
10
|
-
}
|
11
|
-
function unlazy(lazied) {
|
12
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
13
|
-
}
|
14
|
-
|
15
|
-
// src/procedure.ts
|
16
|
-
import { isContractProcedure } from "@orpc/contract";
|
17
|
-
var Procedure = class {
|
18
|
-
"~orpc";
|
19
|
-
constructor(def) {
|
20
|
-
this["~orpc"] = def;
|
21
|
-
}
|
22
|
-
};
|
23
|
-
function isProcedure(item) {
|
24
|
-
if (item instanceof Procedure) {
|
25
|
-
return true;
|
26
|
-
}
|
27
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
28
|
-
}
|
29
|
-
|
30
|
-
// src/lazy-utils.ts
|
31
|
-
function flatLazy(lazied) {
|
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;
|
57
|
-
}
|
58
|
-
|
59
|
-
// src/middleware.ts
|
60
|
-
function middlewareOutputFn(output) {
|
61
|
-
return { output, context: {} };
|
62
|
-
}
|
63
|
-
|
64
|
-
// src/procedure-client.ts
|
65
|
-
import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
|
66
|
-
import { intercept, toError, value } from "@orpc/shared";
|
67
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
68
|
-
return async (...[input, callerOptions]) => {
|
69
|
-
const path = options?.path ?? [];
|
70
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
71
|
-
const clientContext = callerOptions?.context ?? {};
|
72
|
-
const context = await value(options?.context ?? {}, clientContext);
|
73
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
74
|
-
try {
|
75
|
-
return await intercept(
|
76
|
-
options?.interceptors ?? [],
|
77
|
-
{
|
78
|
-
context,
|
79
|
-
input,
|
80
|
-
// input only optional when it undefinable so we can safely cast it
|
81
|
-
errors,
|
82
|
-
path,
|
83
|
-
procedure,
|
84
|
-
signal: callerOptions?.signal,
|
85
|
-
lastEventId: callerOptions?.lastEventId
|
86
|
-
},
|
87
|
-
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
88
|
-
);
|
89
|
-
} catch (e) {
|
90
|
-
if (!(e instanceof ORPCError)) {
|
91
|
-
throw toError(e);
|
92
|
-
}
|
93
|
-
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
94
|
-
throw validated;
|
95
|
-
}
|
96
|
-
};
|
97
|
-
}
|
98
|
-
async function validateInput(procedure, input) {
|
99
|
-
const schema = procedure["~orpc"].inputSchema;
|
100
|
-
if (!schema) {
|
101
|
-
return input;
|
102
|
-
}
|
103
|
-
const result = await schema["~standard"].validate(input);
|
104
|
-
if (result.issues) {
|
105
|
-
throw new ORPCError("BAD_REQUEST", {
|
106
|
-
message: "Input validation failed",
|
107
|
-
data: {
|
108
|
-
issues: result.issues
|
109
|
-
},
|
110
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
111
|
-
});
|
112
|
-
}
|
113
|
-
return result.value;
|
114
|
-
}
|
115
|
-
async function validateOutput(procedure, output) {
|
116
|
-
const schema = procedure["~orpc"].outputSchema;
|
117
|
-
if (!schema) {
|
118
|
-
return output;
|
119
|
-
}
|
120
|
-
const result = await schema["~standard"].validate(output);
|
121
|
-
if (result.issues) {
|
122
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
123
|
-
message: "Output validation failed",
|
124
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
125
|
-
});
|
126
|
-
}
|
127
|
-
return result.value;
|
128
|
-
}
|
129
|
-
async function executeProcedureInternal(procedure, options) {
|
130
|
-
const middlewares = procedure["~orpc"].middlewares;
|
131
|
-
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
132
|
-
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
133
|
-
let currentIndex = 0;
|
134
|
-
let currentContext = options.context;
|
135
|
-
let currentInput = options.input;
|
136
|
-
const next = async (...[nextOptions]) => {
|
137
|
-
const index = currentIndex;
|
138
|
-
currentIndex += 1;
|
139
|
-
currentContext = { ...currentContext, ...nextOptions?.context };
|
140
|
-
if (index === inputValidationIndex) {
|
141
|
-
currentInput = await validateInput(procedure, currentInput);
|
142
|
-
}
|
143
|
-
const mid = middlewares[index];
|
144
|
-
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
145
|
-
if (index === outputValidationIndex) {
|
146
|
-
const validatedOutput = await validateOutput(procedure, result.output);
|
147
|
-
return {
|
148
|
-
...result,
|
149
|
-
output: validatedOutput
|
150
|
-
};
|
151
|
-
}
|
152
|
-
return result;
|
153
|
-
};
|
154
|
-
return (await next({})).output;
|
155
|
-
}
|
156
|
-
|
157
|
-
// src/hidden.ts
|
158
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
159
|
-
function setRouterContract(obj, contract) {
|
160
|
-
return new Proxy(obj, {
|
161
|
-
get(target, key) {
|
162
|
-
if (key === ROUTER_CONTRACT_SYMBOL) {
|
163
|
-
return contract;
|
164
|
-
}
|
165
|
-
return Reflect.get(target, key);
|
166
|
-
}
|
167
|
-
});
|
168
|
-
}
|
169
|
-
function getRouterContract(obj) {
|
170
|
-
return obj[ROUTER_CONTRACT_SYMBOL];
|
171
|
-
}
|
172
|
-
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
173
|
-
function deepSetLazyRouterPrefix(router, prefix) {
|
174
|
-
return new Proxy(router, {
|
175
|
-
get(target, key) {
|
176
|
-
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
177
|
-
const val = Reflect.get(target, key);
|
178
|
-
if (isLazy(val)) {
|
179
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
180
|
-
}
|
181
|
-
return val;
|
182
|
-
}
|
183
|
-
return prefix;
|
184
|
-
}
|
185
|
-
});
|
186
|
-
}
|
187
|
-
function getLazyRouterPrefix(obj) {
|
188
|
-
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
189
|
-
}
|
190
|
-
|
191
|
-
// src/router.ts
|
192
|
-
import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
|
193
|
-
|
194
|
-
// src/middleware-utils.ts
|
195
|
-
function dedupeMiddlewares(compare, middlewares) {
|
196
|
-
let min = 0;
|
197
|
-
for (let i = 0; i < middlewares.length; i++) {
|
198
|
-
const index = compare.indexOf(middlewares[i], min);
|
199
|
-
if (index === -1) {
|
200
|
-
return middlewares.slice(i);
|
201
|
-
}
|
202
|
-
min = index + 1;
|
203
|
-
}
|
204
|
-
return [];
|
205
|
-
}
|
206
|
-
function mergeMiddlewares(first, second) {
|
207
|
-
return [...first, ...dedupeMiddlewares(first, second)];
|
208
|
-
}
|
209
|
-
function addMiddleware(middlewares, addition) {
|
210
|
-
return [...middlewares, addition];
|
211
|
-
}
|
212
|
-
|
213
|
-
// src/router.ts
|
214
|
-
function adaptRouter(router, options) {
|
215
|
-
if (isLazy(router)) {
|
216
|
-
const adapted2 = lazy(async () => {
|
217
|
-
const unlaziedRouter = (await unlazy(router)).default;
|
218
|
-
const adapted3 = adaptRouter(unlaziedRouter, options);
|
219
|
-
return { default: adapted3 };
|
220
|
-
});
|
221
|
-
const accessible = createAccessibleLazyRouter(adapted2);
|
222
|
-
const currentPrefix = getLazyRouterPrefix(router);
|
223
|
-
const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
|
224
|
-
if (prefix) {
|
225
|
-
return deepSetLazyRouterPrefix(accessible, prefix);
|
226
|
-
}
|
227
|
-
return accessible;
|
228
|
-
}
|
229
|
-
if (isProcedure(router)) {
|
230
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
231
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
232
|
-
const adapted2 = new Procedure({
|
233
|
-
...router["~orpc"],
|
234
|
-
route: adaptRoute(router["~orpc"].route, options),
|
235
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
236
|
-
middlewares: newMiddlewares,
|
237
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
238
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
239
|
-
});
|
240
|
-
return adapted2;
|
241
|
-
}
|
242
|
-
const adapted = {};
|
243
|
-
for (const key in router) {
|
244
|
-
adapted[key] = adaptRouter(router[key], options);
|
245
|
-
}
|
246
|
-
return adapted;
|
247
|
-
}
|
248
|
-
function getRouterChild(router, ...path) {
|
249
|
-
let current = router;
|
250
|
-
for (let i = 0; i < path.length; i++) {
|
251
|
-
const segment = path[i];
|
252
|
-
if (!current) {
|
253
|
-
return void 0;
|
254
|
-
}
|
255
|
-
if (isProcedure(current)) {
|
256
|
-
return void 0;
|
257
|
-
}
|
258
|
-
if (!isLazy(current)) {
|
259
|
-
current = current[segment];
|
260
|
-
continue;
|
261
|
-
}
|
262
|
-
const lazied = current;
|
263
|
-
const rest = path.slice(i);
|
264
|
-
const newLazy = lazy(async () => {
|
265
|
-
const unwrapped = await unlazy(lazied);
|
266
|
-
if (!unwrapped.default) {
|
267
|
-
return unwrapped;
|
268
|
-
}
|
269
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
270
|
-
return { default: next };
|
271
|
-
});
|
272
|
-
return flatLazy(newLazy);
|
273
|
-
}
|
274
|
-
return current;
|
275
|
-
}
|
276
|
-
|
277
|
-
// src/router-accessible-lazy.ts
|
278
|
-
function createAccessibleLazyRouter(lazied) {
|
279
|
-
const flattenLazy = flatLazy(lazied);
|
280
|
-
const recursive = new Proxy(flattenLazy, {
|
281
|
-
get(target, key) {
|
282
|
-
if (typeof key !== "string") {
|
283
|
-
return Reflect.get(target, key);
|
284
|
-
}
|
285
|
-
const next = getRouterChild(flattenLazy, key);
|
286
|
-
return createAccessibleLazyRouter(next);
|
287
|
-
}
|
288
|
-
});
|
289
|
-
return recursive;
|
290
|
-
}
|
291
|
-
|
292
|
-
// src/utils.ts
|
293
|
-
import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
|
294
|
-
function eachContractProcedure(options, callback, laziedOptions = []) {
|
295
|
-
const hiddenContract = getRouterContract(options.router);
|
296
|
-
if (hiddenContract) {
|
297
|
-
return eachContractProcedure(
|
298
|
-
{
|
299
|
-
router: hiddenContract,
|
300
|
-
path: options.path
|
301
|
-
},
|
302
|
-
callback,
|
303
|
-
laziedOptions
|
304
|
-
);
|
305
|
-
}
|
306
|
-
if (isLazy(options.router)) {
|
307
|
-
laziedOptions.push({
|
308
|
-
lazied: options.router,
|
309
|
-
path: options.path
|
310
|
-
});
|
311
|
-
} else if (isContractProcedure2(options.router)) {
|
312
|
-
callback({
|
313
|
-
contract: options.router,
|
314
|
-
path: options.path
|
315
|
-
});
|
316
|
-
} else {
|
317
|
-
for (const key in options.router) {
|
318
|
-
eachContractProcedure(
|
319
|
-
{
|
320
|
-
router: options.router[key],
|
321
|
-
path: [...options.path, key]
|
322
|
-
},
|
323
|
-
callback,
|
324
|
-
laziedOptions
|
325
|
-
);
|
326
|
-
}
|
327
|
-
}
|
328
|
-
return laziedOptions;
|
329
|
-
}
|
330
|
-
async function eachAllContractProcedure(options, callback) {
|
331
|
-
const pending = [options];
|
332
|
-
for (const item of pending) {
|
333
|
-
const lazies = eachContractProcedure(item, callback);
|
334
|
-
for (const lazy2 of lazies) {
|
335
|
-
const { default: router } = await unlazy(lazy2.lazied);
|
336
|
-
pending.push({
|
337
|
-
path: lazy2.path,
|
338
|
-
router
|
339
|
-
});
|
340
|
-
}
|
341
|
-
}
|
342
|
-
}
|
343
|
-
function convertPathToHttpPath(path) {
|
344
|
-
return `/${path.map(encodeURIComponent).join("/")}`;
|
345
|
-
}
|
346
|
-
function createContractedProcedure(contract, procedure) {
|
347
|
-
return new Procedure({
|
348
|
-
...procedure["~orpc"],
|
349
|
-
errorMap: contract["~orpc"].errorMap,
|
350
|
-
route: contract["~orpc"].route,
|
351
|
-
meta: contract["~orpc"].meta
|
352
|
-
});
|
353
|
-
}
|
354
|
-
|
355
|
-
export {
|
356
|
-
LAZY_LOADER_SYMBOL,
|
357
|
-
lazy,
|
358
|
-
isLazy,
|
359
|
-
unlazy,
|
360
|
-
Procedure,
|
361
|
-
isProcedure,
|
362
|
-
flatLazy,
|
363
|
-
createLazyProcedureFormAnyLazy,
|
364
|
-
addMiddleware,
|
365
|
-
middlewareOutputFn,
|
366
|
-
createProcedureClient,
|
367
|
-
setRouterContract,
|
368
|
-
getRouterContract,
|
369
|
-
deepSetLazyRouterPrefix,
|
370
|
-
getLazyRouterPrefix,
|
371
|
-
createAccessibleLazyRouter,
|
372
|
-
adaptRouter,
|
373
|
-
getRouterChild,
|
374
|
-
eachContractProcedure,
|
375
|
-
eachAllContractProcedure,
|
376
|
-
convertPathToHttpPath,
|
377
|
-
createContractedProcedure
|
378
|
-
};
|
379
|
-
//# sourceMappingURL=chunk-XXBE6CYD.js.map
|
package/dist/fetch.js
DELETED
package/dist/node.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCCodec,
|
3
|
-
RPCMatcher,
|
4
|
-
StandardHandler
|
5
|
-
} from "./chunk-NXEANHUK.js";
|
6
|
-
import "./chunk-XXBE6CYD.js";
|
7
|
-
import "./chunk-XI6WGCB3.js";
|
8
|
-
|
9
|
-
// src/adapters/node/rpc-handler.ts
|
10
|
-
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
11
|
-
var RPCHandler = class {
|
12
|
-
standardHandler;
|
13
|
-
constructor(router, options) {
|
14
|
-
const codec = options?.codec ?? new RPCCodec();
|
15
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
16
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
17
|
-
}
|
18
|
-
async handle(req, res, ...rest) {
|
19
|
-
const standardRequest = toStandardRequest(req, res);
|
20
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
21
|
-
if (!result.matched) {
|
22
|
-
return { matched: false };
|
23
|
-
}
|
24
|
-
await sendStandardResponse(res, result.response);
|
25
|
-
return { matched: true };
|
26
|
-
}
|
27
|
-
};
|
28
|
-
export {
|
29
|
-
RPCHandler
|
30
|
-
};
|
31
|
-
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
-
import type { FetchHandler, FetchHandleResult } from './types';
|
6
|
-
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
7
|
-
private readonly standardHandler;
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
10
|
-
}
|
11
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { StandardHandleOptions } from '../standard';
|
4
|
-
export type FetchHandleResult = {
|
5
|
-
matched: true;
|
6
|
-
response: Response;
|
7
|
-
} | {
|
8
|
-
matched: false;
|
9
|
-
response: undefined;
|
10
|
-
};
|
11
|
-
export interface FetchHandler<T extends Context> {
|
12
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
13
|
-
}
|
14
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
-
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
3
|
-
import type { Context } from '../../context';
|
4
|
-
import type { FetchHandler } from '../fetch';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
-
context?: Value<T, [HonoContext]>;
|
8
|
-
} : {
|
9
|
-
context: Value<T, [HonoContext]>;
|
10
|
-
});
|
11
|
-
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
12
|
-
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
-
import type { NextRequest } from 'next/server';
|
3
|
-
import type { Context } from '../../context';
|
4
|
-
import type { FetchHandler } from '../fetch';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
-
context?: Value<T, [NextRequest]>;
|
8
|
-
} : {
|
9
|
-
context: Value<T, [NextRequest]>;
|
10
|
-
});
|
11
|
-
export interface ServeResult {
|
12
|
-
GET(req: NextRequest): Promise<Response>;
|
13
|
-
POST(req: NextRequest): Promise<Response>;
|
14
|
-
PUT(req: NextRequest): Promise<Response>;
|
15
|
-
PATCH(req: NextRequest): Promise<Response>;
|
16
|
-
DELETE(req: NextRequest): Promise<Response>;
|
17
|
-
}
|
18
|
-
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
19
|
-
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
-
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
6
|
-
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
7
|
-
private readonly standardHandler;
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
10
|
-
}
|
11
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
3
|
-
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
4
|
-
import type { Context } from '../../context';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
7
|
-
/**
|
8
|
-
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
9
|
-
* This is useful for `express.js` middleware.
|
10
|
-
*/
|
11
|
-
originalUrl?: string;
|
12
|
-
};
|
13
|
-
export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
14
|
-
export type NodeHttpHandleResult = {
|
15
|
-
matched: true;
|
16
|
-
} | {
|
17
|
-
matched: false;
|
18
|
-
};
|
19
|
-
export interface NodeHttpHandler<T extends Context> {
|
20
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
21
|
-
}
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
|
2
|
-
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
|
-
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import type { Context } from '../../context';
|
5
|
-
import type { Plugin } from '../../plugins';
|
6
|
-
import type { CreateProcedureClientOptions } from '../../procedure-client';
|
7
|
-
import type { Router } from '../../router';
|
8
|
-
import type { StandardCodec, StandardMatcher } from './types';
|
9
|
-
export type StandardHandleOptions<T extends Context> = {
|
10
|
-
prefix?: HTTPPath;
|
11
|
-
} & (Record<never, never> extends T ? {
|
12
|
-
context?: T;
|
13
|
-
} : {
|
14
|
-
context: T;
|
15
|
-
});
|
16
|
-
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
17
|
-
context: T;
|
18
|
-
};
|
19
|
-
export type StandardHandleResult = {
|
20
|
-
matched: true;
|
21
|
-
response: StandardResponse;
|
22
|
-
} | {
|
23
|
-
matched: false;
|
24
|
-
response: undefined;
|
25
|
-
};
|
26
|
-
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
27
|
-
request: StandardRequest;
|
28
|
-
};
|
29
|
-
export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
|
30
|
-
context: TContext;
|
31
|
-
};
|
32
|
-
export interface StandardHandlerOptions<TContext extends Context> {
|
33
|
-
plugins?: Plugin<TContext>[];
|
34
|
-
/**
|
35
|
-
* Interceptors at the request level, helpful when you want catch errors
|
36
|
-
*/
|
37
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
38
|
-
/**
|
39
|
-
* Interceptors at the root level, helpful when you want override the response
|
40
|
-
*/
|
41
|
-
interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
42
|
-
}
|
43
|
-
export declare class StandardHandler<T extends Context> {
|
44
|
-
private readonly matcher;
|
45
|
-
private readonly codec;
|
46
|
-
private readonly options;
|
47
|
-
private readonly plugin;
|
48
|
-
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
49
|
-
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
50
|
-
}
|
51
|
-
//# sourceMappingURL=handler.d.ts.map
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { ORPCError } from '@orpc/contract';
|
2
|
-
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
|
-
import type { AnyProcedure } from '../../procedure';
|
4
|
-
import type { StandardCodec, StandardParams } from './types';
|
5
|
-
import { RPCSerializer } from './rpc-serializer';
|
6
|
-
export interface StandardCodecOptions {
|
7
|
-
serializer?: RPCSerializer;
|
8
|
-
}
|
9
|
-
export declare class RPCCodec implements StandardCodec {
|
10
|
-
private readonly serializer;
|
11
|
-
constructor(options?: StandardCodecOptions);
|
12
|
-
decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
13
|
-
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
14
|
-
encodeError(error: ORPCError<any, any>): StandardResponse;
|
15
|
-
}
|
16
|
-
//# sourceMappingURL=rpc-codec.d.ts.map
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import type { Context } from '../../context';
|
2
|
-
import type { StandardHandlerOptions } from './handler';
|
3
|
-
import type { StandardCodec, StandardMatcher } from './types';
|
4
|
-
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
|
5
|
-
matcher?: StandardMatcher;
|
6
|
-
codec?: StandardCodec;
|
7
|
-
}
|
8
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { StandardMatcher, StandardMatchResult } from './types';
|
3
|
-
import { type AnyRouter } from '../../router';
|
4
|
-
export declare class RPCMatcher implements StandardMatcher {
|
5
|
-
private readonly tree;
|
6
|
-
private pendingRouters;
|
7
|
-
init(router: AnyRouter, path?: string[]): void;
|
8
|
-
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
9
|
-
}
|
10
|
-
//# sourceMappingURL=rpc-matcher.d.ts.map
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { Segment } from '@orpc/shared';
|
2
|
-
export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
|
3
|
-
export type RPCSerialized = {
|
4
|
-
json: unknown;
|
5
|
-
meta: RPCSerializedJsonMeta;
|
6
|
-
} | FormData | AsyncIteratorObject<{
|
7
|
-
json: unknown;
|
8
|
-
meta: RPCSerializedJsonMeta;
|
9
|
-
}, {
|
10
|
-
json: unknown;
|
11
|
-
meta: RPCSerializedJsonMeta;
|
12
|
-
}, void>;
|
13
|
-
export type RPCSerializedFormDataMaps = Segment[][];
|
14
|
-
export declare class RPCSerializer {
|
15
|
-
serialize(data: unknown): RPCSerialized;
|
16
|
-
deserialize(serialized: RPCSerialized): unknown;
|
17
|
-
}
|
18
|
-
export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
|
19
|
-
json: unknown;
|
20
|
-
meta: RPCSerializedJsonMeta;
|
21
|
-
};
|
22
|
-
//# sourceMappingURL=rpc-serializer.d.ts.map
|