@orpc/server 0.0.0-next.93e6063 → 0.0.0-next.93fa264

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.
Files changed (64) hide show
  1. package/README.md +28 -20
  2. package/dist/adapters/aws-lambda/index.d.mts +45 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +45 -0
  4. package/dist/adapters/aws-lambda/index.mjs +41 -0
  5. package/dist/adapters/bun-ws/index.d.mts +35 -0
  6. package/dist/adapters/bun-ws/index.d.ts +35 -0
  7. package/dist/adapters/bun-ws/index.mjs +46 -0
  8. package/dist/adapters/crossws/index.d.mts +30 -0
  9. package/dist/adapters/crossws/index.d.ts +30 -0
  10. package/dist/adapters/crossws/index.mjs +46 -0
  11. package/dist/adapters/fetch/index.d.mts +62 -11
  12. package/dist/adapters/fetch/index.d.ts +62 -11
  13. package/dist/adapters/fetch/index.mjs +108 -7
  14. package/dist/adapters/message-port/index.d.mts +28 -0
  15. package/dist/adapters/message-port/index.d.ts +28 -0
  16. package/dist/adapters/message-port/index.mjs +41 -0
  17. package/dist/adapters/node/index.d.mts +64 -22
  18. package/dist/adapters/node/index.d.ts +64 -22
  19. package/dist/adapters/node/index.mjs +86 -21
  20. package/dist/adapters/standard/index.d.mts +12 -15
  21. package/dist/adapters/standard/index.d.ts +12 -15
  22. package/dist/adapters/standard/index.mjs +4 -4
  23. package/dist/adapters/websocket/index.d.mts +51 -0
  24. package/dist/adapters/websocket/index.d.ts +51 -0
  25. package/dist/adapters/websocket/index.mjs +69 -0
  26. package/dist/adapters/ws/index.d.mts +28 -0
  27. package/dist/adapters/ws/index.d.ts +28 -0
  28. package/dist/adapters/ws/index.mjs +39 -0
  29. package/dist/hibernation/index.d.mts +44 -0
  30. package/dist/hibernation/index.d.ts +44 -0
  31. package/dist/hibernation/index.mjs +65 -0
  32. package/dist/index.d.mts +711 -132
  33. package/dist/index.d.ts +711 -132
  34. package/dist/index.mjs +207 -52
  35. package/dist/plugins/index.d.mts +144 -19
  36. package/dist/plugins/index.d.ts +144 -19
  37. package/dist/plugins/index.mjs +165 -15
  38. package/dist/shared/server.-ACo36I0.d.ts +74 -0
  39. package/dist/shared/server.BPAWobQg.d.ts +12 -0
  40. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  41. package/dist/shared/server.Bd52nNaH.d.mts +12 -0
  42. package/dist/shared/server.BliFSTnG.d.mts +10 -0
  43. package/dist/shared/{server.BBGuTxHE.mjs → server.CHvOkcM3.mjs} +69 -46
  44. package/dist/shared/server.DD2C4ujN.d.mts +192 -0
  45. package/dist/shared/server.DD2C4ujN.d.ts +192 -0
  46. package/dist/shared/{server.V6zT5iYQ.mjs → server.DG7Tamti.mjs} +161 -173
  47. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  48. package/dist/shared/server.Dq8xr7PQ.d.mts +74 -0
  49. package/dist/shared/server.IG2MjhrD.d.ts +10 -0
  50. package/package.json +59 -20
  51. package/dist/adapters/hono/index.d.mts +0 -20
  52. package/dist/adapters/hono/index.d.ts +0 -20
  53. package/dist/adapters/hono/index.mjs +0 -32
  54. package/dist/adapters/next/index.d.mts +0 -27
  55. package/dist/adapters/next/index.d.ts +0 -27
  56. package/dist/adapters/next/index.mjs +0 -29
  57. package/dist/shared/server.B-ewprcf.d.ts +0 -77
  58. package/dist/shared/server.CA-o8cUY.d.mts +0 -9
  59. package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
  60. package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
  61. package/dist/shared/server.DJrh0Ceu.d.mts +0 -77
  62. package/dist/shared/server.DPQt9YYq.d.ts +0 -9
  63. package/dist/shared/server.KwueCzFr.mjs +0 -26
  64. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -1,21 +1,54 @@
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
- import { value, intercept, toError } from '@orpc/shared';
3
+ import { value, intercept } from '@orpc/shared';
4
4
 
5
- const LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
6
- function lazy(loader) {
5
+ const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
+ function lazy(loader, meta = {}) {
7
7
  return {
8
- [LAZY_LOADER_SYMBOL]: loader
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 && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
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[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: 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 {
49
+ /**
50
+ * This property holds the defined options.
51
+ */
19
52
  "~orpc";
20
53
  constructor(def) {
21
54
  this["~orpc"] = def;
@@ -28,50 +61,8 @@ function isProcedure(item) {
28
61
  return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
29
62
  }
30
63
 
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
- 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];
64
+ function mergeCurrentContext(context, other) {
65
+ return { ...context, ...other };
75
66
  }
76
67
 
77
68
  function createORPCErrorConstructorMap(errors) {
@@ -139,7 +130,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
139
130
  );
140
131
  } catch (e) {
141
132
  if (!(e instanceof ORPCError)) {
142
- throw toError(e);
133
+ throw e;
143
134
  }
144
135
  const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
145
136
  throw validated;
@@ -181,193 +172,187 @@ async function executeProcedureInternal(procedure, options) {
181
172
  const middlewares = procedure["~orpc"].middlewares;
182
173
  const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
183
174
  const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
184
- let currentIndex = 0;
185
- let currentContext = options.context;
186
- let currentInput = options.input;
187
- const next = async (...[nextOptions]) => {
188
- const index = currentIndex;
189
- currentIndex += 1;
190
- currentContext = { ...currentContext, ...nextOptions?.context };
175
+ const next = async (index, context, input) => {
176
+ let currentInput = input;
191
177
  if (index === inputValidationIndex) {
192
178
  currentInput = await validateInput(procedure, currentInput);
193
179
  }
194
180
  const mid = middlewares[index];
195
- const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
181
+ const output = mid ? (await mid({
182
+ ...options,
183
+ context,
184
+ next: async (...[nextOptions]) => {
185
+ const nextContext = nextOptions?.context ?? {};
186
+ return {
187
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
188
+ context: nextContext
189
+ };
190
+ }
191
+ }, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
196
192
  if (index === outputValidationIndex) {
197
- const validatedOutput = await validateOutput(procedure, result.output);
198
- return {
199
- ...result,
200
- output: validatedOutput
201
- };
193
+ return await validateOutput(procedure, output);
202
194
  }
203
- return result;
195
+ return output;
204
196
  };
205
- return (await next({})).output;
197
+ return next(0, options.context, options.input);
206
198
  }
207
199
 
208
- const ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
209
- function setRouterContract(obj, contract) {
210
- return new Proxy(obj, {
200
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
201
+ function setHiddenRouterContract(router, contract) {
202
+ return new Proxy(router, {
211
203
  get(target, key) {
212
- if (key === ROUTER_CONTRACT_SYMBOL) {
204
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
213
205
  return contract;
214
206
  }
215
207
  return Reflect.get(target, key);
216
208
  }
217
209
  });
218
210
  }
219
- function getRouterContract(obj) {
220
- return obj[ROUTER_CONTRACT_SYMBOL];
211
+ function getHiddenRouterContract(router) {
212
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
221
213
  }
222
- const LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
223
- function deepSetLazyRouterPrefix(router, prefix) {
224
- return new Proxy(router, {
225
- get(target, key) {
226
- if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
227
- const val = Reflect.get(target, key);
228
- if (isLazy(val)) {
229
- return deepSetLazyRouterPrefix(val, prefix);
230
- }
231
- return val;
232
- }
233
- return prefix;
214
+
215
+ function getRouter(router, path) {
216
+ let current = router;
217
+ for (let i = 0; i < path.length; i++) {
218
+ const segment = path[i];
219
+ if (!current) {
220
+ return void 0;
234
221
  }
235
- });
236
- }
237
- function getLazyRouterPrefix(obj) {
238
- return obj[LAZY_ROUTER_PREFIX_SYMBOL];
222
+ if (isProcedure(current)) {
223
+ return void 0;
224
+ }
225
+ if (!isLazy(current)) {
226
+ current = current[segment];
227
+ continue;
228
+ }
229
+ const lazied = current;
230
+ const rest = path.slice(i);
231
+ return lazy(async () => {
232
+ const unwrapped = await unlazy(lazied);
233
+ const next = getRouter(unwrapped.default, rest);
234
+ return unlazy(next);
235
+ }, getLazyMeta(lazied));
236
+ }
237
+ return current;
239
238
  }
240
-
241
239
  function createAccessibleLazyRouter(lazied) {
242
- const flattenLazy = flatLazy(lazied);
243
- const recursive = new Proxy(flattenLazy, {
240
+ const recursive = new Proxy(lazied, {
244
241
  get(target, key) {
245
242
  if (typeof key !== "string") {
246
243
  return Reflect.get(target, key);
247
244
  }
248
- const next = getRouterChild(flattenLazy, key);
245
+ const next = getRouter(lazied, [key]);
249
246
  return createAccessibleLazyRouter(next);
250
247
  }
251
248
  });
252
249
  return recursive;
253
250
  }
254
-
255
- function adaptRouter(router, options) {
251
+ function enhanceRouter(router, options) {
256
252
  if (isLazy(router)) {
257
- const adapted2 = lazy(async () => {
258
- const unlaziedRouter = (await unlazy(router)).default;
259
- const adapted3 = adaptRouter(unlaziedRouter, options);
260
- return { default: adapted3 };
253
+ const laziedMeta = getLazyMeta(router);
254
+ const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
255
+ const enhanced2 = lazy(async () => {
256
+ const { default: unlaziedRouter } = await unlazy(router);
257
+ const enhanced3 = enhanceRouter(unlaziedRouter, options);
258
+ return unlazy(enhanced3);
259
+ }, {
260
+ ...laziedMeta,
261
+ prefix: enhancedPrefix
261
262
  });
262
- const accessible = createAccessibleLazyRouter(adapted2);
263
- const currentPrefix = getLazyRouterPrefix(router);
264
- const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
265
- if (prefix) {
266
- return deepSetLazyRouterPrefix(accessible, prefix);
267
- }
263
+ const accessible = createAccessibleLazyRouter(enhanced2);
268
264
  return accessible;
269
265
  }
270
266
  if (isProcedure(router)) {
271
- const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
267
+ const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
272
268
  const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
273
- const adapted2 = new Procedure({
269
+ const enhanced2 = new Procedure({
274
270
  ...router["~orpc"],
275
- route: adaptRoute(router["~orpc"].route, options),
271
+ route: enhanceRoute(router["~orpc"].route, options),
276
272
  errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
277
273
  middlewares: newMiddlewares,
278
274
  inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
279
275
  outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
280
276
  });
281
- return adapted2;
277
+ return enhanced2;
282
278
  }
283
- const adapted = {};
279
+ const enhanced = {};
284
280
  for (const key in router) {
285
- adapted[key] = adaptRouter(router[key], options);
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);
281
+ enhanced[key] = enhanceRouter(router[key], options);
314
282
  }
315
- return current;
283
+ return enhanced;
316
284
  }
317
-
318
- function eachContractProcedure(options, callback, laziedOptions = []) {
319
- const hiddenContract = getRouterContract(options.router);
320
- if (hiddenContract) {
321
- return eachContractProcedure(
322
- {
323
- router: hiddenContract,
324
- path: options.path
325
- },
326
- callback,
327
- laziedOptions
328
- );
285
+ function traverseContractProcedures(options, callback, lazyOptions = []) {
286
+ let currentRouter = options.router;
287
+ const hiddenContract = getHiddenRouterContract(options.router);
288
+ if (hiddenContract !== void 0) {
289
+ currentRouter = hiddenContract;
329
290
  }
330
- if (isLazy(options.router)) {
331
- laziedOptions.push({
332
- lazied: options.router,
291
+ if (isLazy(currentRouter)) {
292
+ lazyOptions.push({
293
+ router: currentRouter,
333
294
  path: options.path
334
295
  });
335
- } else if (isContractProcedure(options.router)) {
296
+ } else if (isContractProcedure(currentRouter)) {
336
297
  callback({
337
- contract: options.router,
298
+ contract: currentRouter,
338
299
  path: options.path
339
300
  });
340
301
  } else {
341
- for (const key in options.router) {
342
- eachContractProcedure(
302
+ for (const key in currentRouter) {
303
+ traverseContractProcedures(
343
304
  {
344
- router: options.router[key],
305
+ router: currentRouter[key],
345
306
  path: [...options.path, key]
346
307
  },
347
308
  callback,
348
- laziedOptions
309
+ lazyOptions
349
310
  );
350
311
  }
351
312
  }
352
- return laziedOptions;
313
+ return lazyOptions;
353
314
  }
354
- async function eachAllContractProcedure(options, callback) {
315
+ async function resolveContractProcedures(options, callback) {
355
316
  const pending = [options];
356
- for (const item of pending) {
357
- const lazies = eachContractProcedure(item, callback);
358
- for (const lazy of lazies) {
359
- const { default: router } = await unlazy(lazy.lazied);
317
+ for (const options2 of pending) {
318
+ const lazyOptions = traverseContractProcedures(options2, callback);
319
+ for (const options3 of lazyOptions) {
320
+ const { default: router } = await unlazy(options3.router);
360
321
  pending.push({
361
- path: lazy.path,
362
- router
322
+ router,
323
+ path: options3.path
363
324
  });
364
325
  }
365
326
  }
366
327
  }
367
- function convertPathToHttpPath(path) {
368
- return `/${path.map(encodeURIComponent).join("/")}`;
328
+ async function unlazyRouter(router) {
329
+ if (isProcedure(router)) {
330
+ return router;
331
+ }
332
+ const unlazied = {};
333
+ for (const key in router) {
334
+ const item = router[key];
335
+ const { default: unlaziedRouter } = await unlazy(item);
336
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
337
+ }
338
+ return unlazied;
369
339
  }
370
- function createContractedProcedure(contract, procedure) {
340
+
341
+ function createAssertedLazyProcedure(lazied) {
342
+ const lazyProcedure = lazy(async () => {
343
+ const { default: maybeProcedure } = await unlazy(lazied);
344
+ if (!isProcedure(maybeProcedure)) {
345
+ throw new Error(`
346
+ Expected a lazy<procedure> but got lazy<unknown>.
347
+ This should be caught by TypeScript compilation.
348
+ Please report this issue if this makes you feel uncomfortable.
349
+ `);
350
+ }
351
+ return { default: maybeProcedure };
352
+ }, getLazyMeta(lazied));
353
+ return lazyProcedure;
354
+ }
355
+ function createContractedProcedure(procedure, contract) {
371
356
  return new Procedure({
372
357
  ...procedure["~orpc"],
373
358
  errorMap: contract["~orpc"].errorMap,
@@ -375,5 +360,8 @@ function createContractedProcedure(contract, procedure) {
375
360
  meta: contract["~orpc"].meta
376
361
  });
377
362
  }
363
+ function call(procedure, input, ...rest) {
364
+ return createProcedureClient(procedure, ...rest)(input);
365
+ }
378
366
 
379
- export { LAZY_LOADER_SYMBOL as L, Procedure as P, convertPathToHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, eachContractProcedure as e, adaptRouter as f, getRouterChild as g, flatLazy as h, isProcedure as i, isLazy as j, createLazyProcedureFormAnyLazy as k, lazy as l, getRouterContract as m, deepSetLazyRouterPrefix as n, getLazyRouterPrefix as o, middlewareOutputFn as p, createAccessibleLazyRouter as q, eachAllContractProcedure as r, setRouterContract as s, unlazy as u };
367
+ 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,9 @@
1
+ function resolveFriendlyStandardHandleOptions(options) {
2
+ return {
3
+ ...options,
4
+ context: options.context ?? {}
5
+ // Context only optional if all fields are optional
6
+ };
7
+ }
8
+
9
+ export { resolveFriendlyStandardHandleOptions as r };
@@ -0,0 +1,74 @@
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta } from '@orpc/contract';
3
+ import { Interceptor } from '@orpc/shared';
4
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
+ import { C as Context, R as Router, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DD2C4ujN.mjs';
6
+
7
+ interface StandardHandlerPlugin<T extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): 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>, router: Router<any, 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>, Promise<StandardHandleResult>>[];
53
+ /**
54
+ * Interceptors at the root level, helpful when you want override the request/response
55
+ */
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
57
+ /**
58
+ *
59
+ * Interceptors for procedure client.
60
+ */
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
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 };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DD2C4ujN.js';
2
+ import { g as StandardHandleOptions } from './server.-ACo36I0.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };
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.93e6063",
4
+ "version": "0.0.0-next.93fa264",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -24,6 +24,11 @@
24
24
  "import": "./dist/plugins/index.mjs",
25
25
  "default": "./dist/plugins/index.mjs"
26
26
  },
27
+ "./hibernation": {
28
+ "types": "./dist/hibernation/index.d.mts",
29
+ "import": "./dist/hibernation/index.mjs",
30
+ "default": "./dist/hibernation/index.mjs"
31
+ },
27
32
  "./standard": {
28
33
  "types": "./dist/adapters/standard/index.d.mts",
29
34
  "import": "./dist/adapters/standard/index.mjs",
@@ -34,39 +39,73 @@
34
39
  "import": "./dist/adapters/fetch/index.mjs",
35
40
  "default": "./dist/adapters/fetch/index.mjs"
36
41
  },
37
- "./hono": {
38
- "types": "./dist/adapters/hono/index.d.mts",
39
- "import": "./dist/adapters/hono/index.mjs",
40
- "default": "./dist/adapters/hono/index.mjs"
41
- },
42
- "./next": {
43
- "types": "./dist/adapters/next/index.d.mts",
44
- "import": "./dist/adapters/next/index.mjs",
45
- "default": "./dist/adapters/next/index.mjs"
46
- },
47
42
  "./node": {
48
43
  "types": "./dist/adapters/node/index.d.mts",
49
44
  "import": "./dist/adapters/node/index.mjs",
50
45
  "default": "./dist/adapters/node/index.mjs"
46
+ },
47
+ "./aws-lambda": {
48
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
49
+ "import": "./dist/adapters/aws-lambda/index.mjs",
50
+ "default": "./dist/adapters/aws-lambda/index.mjs"
51
+ },
52
+ "./websocket": {
53
+ "types": "./dist/adapters/websocket/index.d.mts",
54
+ "import": "./dist/adapters/websocket/index.mjs",
55
+ "default": "./dist/adapters/websocket/index.mjs"
56
+ },
57
+ "./crossws": {
58
+ "types": "./dist/adapters/crossws/index.d.mts",
59
+ "import": "./dist/adapters/crossws/index.mjs",
60
+ "default": "./dist/adapters/crossws/index.mjs"
61
+ },
62
+ "./ws": {
63
+ "types": "./dist/adapters/ws/index.d.mts",
64
+ "import": "./dist/adapters/ws/index.mjs",
65
+ "default": "./dist/adapters/ws/index.mjs"
66
+ },
67
+ "./bun-ws": {
68
+ "types": "./dist/adapters/bun-ws/index.d.mts",
69
+ "import": "./dist/adapters/bun-ws/index.mjs",
70
+ "default": "./dist/adapters/bun-ws/index.mjs"
71
+ },
72
+ "./message-port": {
73
+ "types": "./dist/adapters/message-port/index.d.mts",
74
+ "import": "./dist/adapters/message-port/index.mjs",
75
+ "default": "./dist/adapters/message-port/index.mjs"
51
76
  }
52
77
  },
53
78
  "files": [
54
79
  "dist"
55
80
  ],
56
81
  "peerDependencies": {
57
- "hono": ">=4.6.0",
58
- "next": ">=14.0.0"
82
+ "crossws": ">=0.3.4",
83
+ "ws": ">=8.18.1"
84
+ },
85
+ "peerDependenciesMeta": {
86
+ "crossws": {
87
+ "optional": true
88
+ },
89
+ "ws": {
90
+ "optional": true
91
+ }
59
92
  },
60
93
  "dependencies": {
61
- "@orpc/client": "0.0.0-next.93e6063",
62
- "@orpc/contract": "0.0.0-next.93e6063",
63
- "@orpc/shared": "0.0.0-next.93e6063",
64
- "@orpc/standard-server": "0.0.0-next.93e6063",
65
- "@orpc/standard-server-fetch": "0.0.0-next.93e6063",
66
- "@orpc/standard-server-node": "0.0.0-next.93e6063"
94
+ "@orpc/client": "0.0.0-next.93fa264",
95
+ "@orpc/contract": "0.0.0-next.93fa264",
96
+ "@orpc/shared": "0.0.0-next.93fa264",
97
+ "@orpc/standard-server": "0.0.0-next.93fa264",
98
+ "@orpc/standard-server-fetch": "0.0.0-next.93fa264",
99
+ "@orpc/standard-server-node": "0.0.0-next.93fa264",
100
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.93fa264",
101
+ "@orpc/standard-server-peer": "0.0.0-next.93fa264"
67
102
  },
68
103
  "devDependencies": {
69
- "light-my-request": "^6.5.1"
104
+ "@types/ws": "^8.18.1",
105
+ "crossws": "^0.4.1",
106
+ "next": "^15.3.0",
107
+ "supertest": "^7.1.0",
108
+ "ws": "^8.18.1"
70
109
  },
71
110
  "scripts": {
72
111
  "build": "unbuild",
@@ -1,20 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.mjs';
2
- export { FetchHandleResult, RPCHandler } from '../fetch/index.mjs';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context as Context$1, MiddlewareHandler } from 'hono';
5
- import { C as Context } from '../../shared/server.Cn9ybJtE.mjs';
6
- import { S as StandardHandleOptions } from '../../shared/server.DJrh0Ceu.mjs';
7
- import '@orpc/standard-server-fetch';
8
- import '../../shared/server.CA-o8cUY.mjs';
9
- import '@orpc/client';
10
- import '@orpc/contract';
11
- import '@orpc/standard-server';
12
-
13
- type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
14
- context?: Value<T, [Context$1]>;
15
- } : {
16
- context: Value<T, [Context$1]>;
17
- });
18
- declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
19
-
20
- export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };