@orpc/server 0.0.0-next.f17a1a0 → 0.0.0-next.f4d410a

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 (81) hide show
  1. package/README.md +4 -2
  2. package/dist/adapters/fetch/index.d.mts +28 -0
  3. package/dist/adapters/fetch/index.d.ts +28 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +21 -0
  6. package/dist/adapters/hono/index.d.ts +21 -0
  7. package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
  8. package/dist/adapters/next/index.d.mts +28 -0
  9. package/dist/adapters/next/index.d.ts +28 -0
  10. package/dist/{next.js → adapters/next/index.mjs} +11 -13
  11. package/dist/adapters/node/index.d.mts +36 -0
  12. package/dist/adapters/node/index.d.ts +36 -0
  13. package/dist/adapters/node/index.mjs +32 -0
  14. package/dist/adapters/standard/index.d.mts +26 -0
  15. package/dist/adapters/standard/index.d.ts +26 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +278 -0
  18. package/dist/index.d.ts +278 -0
  19. package/dist/{index.js → index.mjs} +84 -155
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/{chunk-WQNNSBXW.js → plugins/index.mjs} +12 -29
  23. package/dist/shared/server.B3Tm0IXY.d.ts +75 -0
  24. package/dist/shared/server.BYTulgUc.d.mts +144 -0
  25. package/dist/shared/server.BYTulgUc.d.ts +144 -0
  26. package/dist/shared/server.BeJithK4.d.mts +75 -0
  27. package/dist/{chunk-MHVECKBC.js → shared/server.BtxZnWJ9.mjs} +165 -212
  28. package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
  29. package/dist/shared/server.DoP20NVH.mjs +29 -0
  30. package/dist/shared/server.EhgR_5_I.d.ts +8 -0
  31. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  32. package/dist/{chunk-7A2ZRAPK.js → shared/server.jG7ZuX3S.mjs} +21 -45
  33. package/package.json +29 -34
  34. package/dist/chunk-MEBJNUSY.js +0 -32
  35. package/dist/fetch.js +0 -10
  36. package/dist/node.js +0 -31
  37. package/dist/plugins.js +0 -11
  38. package/dist/src/adapters/fetch/index.d.ts +0 -3
  39. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  40. package/dist/src/adapters/fetch/types.d.ts +0 -14
  41. package/dist/src/adapters/hono/index.d.ts +0 -3
  42. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  43. package/dist/src/adapters/next/index.d.ts +0 -3
  44. package/dist/src/adapters/next/serve.d.ts +0 -19
  45. package/dist/src/adapters/node/index.d.ts +0 -3
  46. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  47. package/dist/src/adapters/node/types.d.ts +0 -22
  48. package/dist/src/adapters/standard/handler.d.ts +0 -53
  49. package/dist/src/adapters/standard/index.d.ts +0 -6
  50. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  51. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  52. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  53. package/dist/src/adapters/standard/types.d.ts +0 -21
  54. package/dist/src/builder-variants.d.ts +0 -75
  55. package/dist/src/builder.d.ts +0 -58
  56. package/dist/src/config.d.ts +0 -6
  57. package/dist/src/context.d.ts +0 -8
  58. package/dist/src/error.d.ts +0 -12
  59. package/dist/src/hidden.d.ts +0 -8
  60. package/dist/src/implementer-procedure.d.ts +0 -33
  61. package/dist/src/implementer-variants.d.ts +0 -18
  62. package/dist/src/implementer.d.ts +0 -29
  63. package/dist/src/index.d.ts +0 -25
  64. package/dist/src/lazy-utils.d.ts +0 -6
  65. package/dist/src/lazy.d.ts +0 -22
  66. package/dist/src/middleware-decorated.d.ts +0 -11
  67. package/dist/src/middleware-utils.d.ts +0 -5
  68. package/dist/src/middleware.d.ts +0 -38
  69. package/dist/src/plugins/base.d.ts +0 -11
  70. package/dist/src/plugins/cors.d.ts +0 -19
  71. package/dist/src/plugins/index.d.ts +0 -4
  72. package/dist/src/plugins/response-headers.d.ts +0 -10
  73. package/dist/src/procedure-client.d.ts +0 -33
  74. package/dist/src/procedure-decorated.d.ts +0 -24
  75. package/dist/src/procedure-utils.d.ts +0 -19
  76. package/dist/src/procedure.d.ts +0 -31
  77. package/dist/src/router-accessible-lazy.d.ts +0 -8
  78. package/dist/src/router-client.d.ts +0 -12
  79. package/dist/src/router.d.ts +0 -30
  80. package/dist/src/utils.d.ts +0 -24
  81. package/dist/standard.js +0 -13
@@ -1,35 +1,15 @@
1
- import {
2
- LAZY_LOADER_SYMBOL,
3
- Procedure,
4
- adaptRouter,
5
- addMiddleware,
6
- convertPathToHttpPath,
7
- createAccessibleLazyRouter,
8
- createContractedProcedure,
9
- createLazyProcedureFormAnyLazy,
10
- createProcedureClient,
11
- deepSetLazyRouterPrefix,
12
- eachAllContractProcedure,
13
- eachContractProcedure,
14
- flatLazy,
15
- getLazyRouterPrefix,
16
- getRouterChild,
17
- getRouterContract,
18
- isLazy,
19
- isProcedure,
20
- lazy,
21
- middlewareOutputFn,
22
- setRouterContract,
23
- unlazy
24
- } from "./chunk-MHVECKBC.js";
1
+ import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
2
+ export { ValidationError, eventIterator, type } from '@orpc/contract';
3
+ import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BtxZnWJ9.mjs';
4
+ export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.mjs';
5
+ export { ORPCError, isDefinedError, safe } from '@orpc/client';
6
+ export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
+ export { getEventMeta, withEventMeta } from '@orpc/standard-server';
25
8
 
26
- // src/builder.ts
27
- import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
28
-
29
- // src/config.ts
30
- var DEFAULT_CONFIG = {
9
+ const DEFAULT_CONFIG = {
31
10
  initialInputValidationIndex: 0,
32
- initialOutputValidationIndex: 0
11
+ initialOutputValidationIndex: 0,
12
+ dedupeLeadingMiddlewares: true
33
13
  };
34
14
  function fallbackConfig(key, value) {
35
15
  if (value === void 0) {
@@ -38,9 +18,8 @@ function fallbackConfig(key, value) {
38
18
  return value;
39
19
  }
40
20
 
41
- // src/middleware-decorated.ts
42
21
  function decorateMiddleware(middleware) {
43
- const decorated = middleware;
22
+ const decorated = (...args) => middleware(...args);
44
23
  decorated.mapInput = (mapInput) => {
45
24
  const mapped = decorateMiddleware(
46
25
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -65,30 +44,28 @@ function decorateMiddleware(middleware) {
65
44
  return decorated;
66
45
  }
67
46
 
68
- // src/procedure-decorated.ts
69
- import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
70
- var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
47
+ class DecoratedProcedure extends Procedure {
71
48
  errors(errors) {
72
- return new _DecoratedProcedure({
49
+ return new DecoratedProcedure({
73
50
  ...this["~orpc"],
74
51
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
75
52
  });
76
53
  }
77
54
  meta(meta) {
78
- return new _DecoratedProcedure({
55
+ return new DecoratedProcedure({
79
56
  ...this["~orpc"],
80
57
  meta: mergeMeta(this["~orpc"].meta, meta)
81
58
  });
82
59
  }
83
60
  route(route) {
84
- return new _DecoratedProcedure({
61
+ return new DecoratedProcedure({
85
62
  ...this["~orpc"],
86
63
  route: mergeRoute(this["~orpc"].route, route)
87
64
  });
88
65
  }
89
66
  use(middleware, mapInput) {
90
67
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
91
- return new _DecoratedProcedure({
68
+ return new DecoratedProcedure({
92
69
  ...this["~orpc"],
93
70
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
94
71
  });
@@ -97,9 +74,13 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
97
74
  * Make this procedure callable (works like a function while still being a procedure).
98
75
  */
99
76
  callable(...rest) {
100
- return Object.assign(createProcedureClient(this, ...rest), {
101
- "~type": "Procedure",
102
- "~orpc": this["~orpc"]
77
+ return new Proxy(createProcedureClient(this, ...rest), {
78
+ get: (target, key) => {
79
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
80
+ },
81
+ has: (target, key) => {
82
+ return Reflect.has(this, key) || Reflect.has(target, key);
83
+ }
103
84
  });
104
85
  }
105
86
  /**
@@ -108,10 +89,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
108
89
  actionable(...rest) {
109
90
  return this.callable(...rest);
110
91
  }
111
- };
92
+ }
112
93
 
113
- // src/builder.ts
114
- var Builder = class _Builder {
94
+ class Builder {
115
95
  "~orpc";
116
96
  constructor(def) {
117
97
  this["~orpc"] = def;
@@ -122,9 +102,10 @@ var Builder = class _Builder {
122
102
  $config(config) {
123
103
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
124
104
  const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
125
- return new _Builder({
105
+ return new Builder({
126
106
  ...this["~orpc"],
127
107
  config,
108
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
128
109
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
129
110
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
130
111
  });
@@ -133,7 +114,7 @@ var Builder = class _Builder {
133
114
  * Reset initial context
134
115
  */
135
116
  $context() {
136
- return new _Builder({
117
+ return new Builder({
137
118
  ...this["~orpc"],
138
119
  middlewares: [],
139
120
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
@@ -144,7 +125,7 @@ var Builder = class _Builder {
144
125
  * Reset initial meta
145
126
  */
146
127
  $meta(initialMeta) {
147
- return new _Builder({
128
+ return new Builder({
148
129
  ...this["~orpc"],
149
130
  meta: initialMeta
150
131
  });
@@ -153,48 +134,54 @@ var Builder = class _Builder {
153
134
  * Reset initial route
154
135
  */
155
136
  $route(initialRoute) {
156
- return new _Builder({
137
+ return new Builder({
157
138
  ...this["~orpc"],
158
139
  route: initialRoute
159
140
  });
160
141
  }
142
+ $input(initialInputSchema) {
143
+ return new Builder({
144
+ ...this["~orpc"],
145
+ inputSchema: initialInputSchema
146
+ });
147
+ }
161
148
  middleware(middleware) {
162
149
  return decorateMiddleware(middleware);
163
150
  }
164
151
  errors(errors) {
165
- return new _Builder({
152
+ return new Builder({
166
153
  ...this["~orpc"],
167
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
154
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
168
155
  });
169
156
  }
170
157
  use(middleware, mapInput) {
171
158
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
172
- return new _Builder({
159
+ return new Builder({
173
160
  ...this["~orpc"],
174
161
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
175
162
  });
176
163
  }
177
164
  meta(meta) {
178
- return new _Builder({
165
+ return new Builder({
179
166
  ...this["~orpc"],
180
- meta: mergeMeta2(this["~orpc"].meta, meta)
167
+ meta: mergeMeta(this["~orpc"].meta, meta)
181
168
  });
182
169
  }
183
170
  route(route) {
184
- return new _Builder({
171
+ return new Builder({
185
172
  ...this["~orpc"],
186
- route: mergeRoute2(this["~orpc"].route, route)
173
+ route: mergeRoute(this["~orpc"].route, route)
187
174
  });
188
175
  }
189
176
  input(schema) {
190
- return new _Builder({
177
+ return new Builder({
191
178
  ...this["~orpc"],
192
179
  inputSchema: schema,
193
180
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
194
181
  });
195
182
  }
196
183
  output(schema) {
197
- return new _Builder({
184
+ return new Builder({
198
185
  ...this["~orpc"],
199
186
  outputSchema: schema,
200
187
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
@@ -207,43 +194,35 @@ var Builder = class _Builder {
207
194
  });
208
195
  }
209
196
  prefix(prefix) {
210
- return new _Builder({
197
+ return new Builder({
211
198
  ...this["~orpc"],
212
199
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
213
200
  });
214
201
  }
215
202
  tag(...tags) {
216
- return new _Builder({
203
+ return new Builder({
217
204
  ...this["~orpc"],
218
205
  tags: mergeTags(this["~orpc"].tags, tags)
219
206
  });
220
207
  }
221
208
  router(router) {
222
- return adaptRouter(router, this["~orpc"]);
209
+ return enhanceRouter(router, this["~orpc"]);
223
210
  }
224
211
  lazy(loader) {
225
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
212
+ return enhanceRouter(lazy(loader), this["~orpc"]);
226
213
  }
227
- };
228
- var os = new Builder({
214
+ }
215
+ const os = new Builder({
229
216
  config: {},
230
217
  route: {},
231
218
  meta: {},
232
219
  errorMap: {},
233
- inputSchema: void 0,
234
- outputSchema: void 0,
235
220
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
236
221
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
237
- middlewares: []
222
+ middlewares: [],
223
+ dedupeLeadingMiddlewares: true
238
224
  });
239
225
 
240
- // src/context.ts
241
- function mergeContext(context, other) {
242
- return { ...context, ...other };
243
- }
244
-
245
- // src/implementer.ts
246
- import { isContractProcedure } from "@orpc/contract";
247
226
  function implementerInternal(contract, config, middlewares) {
248
227
  if (isContractProcedure(contract)) {
249
228
  const impl2 = new Builder({
@@ -251,12 +230,16 @@ function implementerInternal(contract, config, middlewares) {
251
230
  config,
252
231
  middlewares,
253
232
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
254
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
233
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
234
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
255
235
  });
256
236
  return impl2;
257
237
  }
258
238
  const impl = new Proxy(contract, {
259
239
  get: (target, key) => {
240
+ if (typeof key !== "string") {
241
+ return Reflect.get(target, key);
242
+ }
260
243
  let method;
261
244
  if (key === "middleware") {
262
245
  method = (mid) => decorateMiddleware(mid);
@@ -270,23 +253,29 @@ function implementerInternal(contract, config, middlewares) {
270
253
  };
271
254
  } else if (key === "router") {
272
255
  method = (router) => {
273
- const adapted = adaptRouter(router, {
256
+ const adapted = enhanceRouter(router, {
274
257
  middlewares,
275
- errorMap: {}
258
+ errorMap: {},
259
+ prefix: void 0,
260
+ tags: void 0,
261
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
276
262
  });
277
- return setRouterContract(adapted, contract);
263
+ return setHiddenRouterContract(adapted, contract);
278
264
  };
279
265
  } else if (key === "lazy") {
280
266
  method = (loader) => {
281
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
267
+ const adapted = enhanceRouter(lazy(loader), {
282
268
  middlewares,
283
- errorMap: {}
269
+ errorMap: {},
270
+ prefix: void 0,
271
+ tags: void 0,
272
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
284
273
  });
285
- return setRouterContract(adapted, contract);
274
+ return setHiddenRouterContract(adapted, contract);
286
275
  };
287
276
  }
288
- const next = Reflect.get(target, key);
289
- if (!next || typeof next !== "function" && typeof next !== "object") {
277
+ const next = getContractRouter(target, [key]);
278
+ if (!next) {
290
279
  return method ?? next;
291
280
  }
292
281
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -313,44 +302,34 @@ function implement(contract, config = {}) {
313
302
  method = (config2) => implement(contract, config2);
314
303
  }
315
304
  const next = Reflect.get(target, key);
316
- if (!next || typeof next !== "function" && typeof next !== "object") {
317
- return method ?? next;
305
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
306
+ return method || next;
318
307
  }
319
- if (method) {
320
- return new Proxy(method, {
321
- get(_, key2) {
322
- return Reflect.get(next, key2);
323
- }
324
- });
325
- }
326
- return next;
308
+ return new Proxy(method, {
309
+ get(_, key2) {
310
+ return Reflect.get(next, key2);
311
+ }
312
+ });
327
313
  }
328
314
  });
329
315
  return impl;
330
316
  }
331
317
 
332
- // src/procedure-utils.ts
333
- function call(procedure, input, ...rest) {
334
- return createProcedureClient(procedure, ...rest)(input);
335
- }
336
-
337
- // src/router-client.ts
338
- function createRouterClient(router, ...rest) {
318
+ function createRouterClient(router, ...[options]) {
339
319
  if (isProcedure(router)) {
340
- const caller = createProcedureClient(router, ...rest);
320
+ const caller = createProcedureClient(router, options);
341
321
  return caller;
342
322
  }
343
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
323
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
344
324
  const recursive = new Proxy(procedureCaller, {
345
325
  get(target, key) {
346
326
  if (typeof key !== "string") {
347
327
  return Reflect.get(target, key);
348
328
  }
349
- const next = getRouterChild(router, key);
329
+ const next = getRouter(router, [key]);
350
330
  if (!next) {
351
331
  return Reflect.get(target, key);
352
332
  }
353
- const [options] = rest;
354
333
  return createRouterClient(next, {
355
334
  ...options,
356
335
  path: [...options?.path ?? [], key]
@@ -360,54 +339,4 @@ function createRouterClient(router, ...rest) {
360
339
  return recursive;
361
340
  }
362
341
 
363
- // src/index.ts
364
- import { isDefinedError, ORPCError, safe } from "@orpc/client";
365
- import { eventIterator, type, ValidationError } from "@orpc/contract";
366
- import { getEventMeta, withEventMeta } from "@orpc/server-standard";
367
- import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
368
- export {
369
- Builder,
370
- DecoratedProcedure,
371
- LAZY_LOADER_SYMBOL,
372
- ORPCError,
373
- Procedure,
374
- ValidationError,
375
- adaptRouter,
376
- call,
377
- convertPathToHttpPath,
378
- createAccessibleLazyRouter,
379
- createContractedProcedure,
380
- createLazyProcedureFormAnyLazy,
381
- createProcedureClient,
382
- createRouterClient,
383
- decorateMiddleware,
384
- deepSetLazyRouterPrefix,
385
- eachAllContractProcedure,
386
- eachContractProcedure,
387
- eventIterator,
388
- fallbackConfig,
389
- flatLazy,
390
- getEventMeta,
391
- getLazyRouterPrefix,
392
- getRouterChild,
393
- getRouterContract,
394
- implement,
395
- implementerInternal,
396
- isDefinedError,
397
- isLazy,
398
- isProcedure,
399
- lazy,
400
- mergeContext,
401
- middlewareOutputFn,
402
- onError,
403
- onFinish,
404
- onStart,
405
- onSuccess,
406
- os,
407
- safe,
408
- setRouterContract,
409
- type,
410
- unlazy,
411
- withEventMeta
412
- };
413
- //# sourceMappingURL=index.js.map
342
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
@@ -0,0 +1,31 @@
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BeJithK4.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.BeJithK4.mjs';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.BYTulgUc.mjs';
5
+ import '@orpc/contract';
6
+ import '@orpc/standard-server';
7
+ import '@orpc/client';
8
+
9
+ interface CORSOptions<TContext extends Context> {
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: readonly string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: CORSOptions<TContext>);
21
+ init(options: StandardHandlerOptions<TContext>): void;
22
+ }
23
+
24
+ interface ResponseHeadersPluginContext {
25
+ resHeaders?: Headers;
26
+ }
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
+ init(options: StandardHandlerOptions<TContext>): void;
29
+ }
30
+
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -0,0 +1,31 @@
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.B3Tm0IXY.js';
2
+ export { C as CompositePlugin } from '../shared/server.B3Tm0IXY.js';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.BYTulgUc.js';
5
+ import '@orpc/contract';
6
+ import '@orpc/standard-server';
7
+ import '@orpc/client';
8
+
9
+ interface CORSOptions<TContext extends Context> {
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: readonly string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: CORSOptions<TContext>);
21
+ init(options: StandardHandlerOptions<TContext>): void;
22
+ }
23
+
24
+ interface ResponseHeadersPluginContext {
25
+ resHeaders?: Headers;
26
+ }
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
+ init(options: StandardHandlerOptions<TContext>): void;
29
+ }
30
+
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -1,20 +1,9 @@
1
- // src/plugins/base.ts
2
- var CompositePlugin = class {
3
- constructor(plugins = []) {
4
- this.plugins = plugins;
5
- }
6
- init(options) {
7
- for (const plugin of this.plugins) {
8
- plugin.init?.(options);
9
- }
10
- }
11
- };
1
+ export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
2
+ import { value } from '@orpc/shared';
12
3
 
13
- // src/plugins/cors.ts
14
- import { value } from "@orpc/shared";
15
- var CORSPlugin = class {
4
+ class CORSPlugin {
16
5
  options;
17
- constructor(options) {
6
+ constructor(options = {}) {
18
7
  const defaults = {
19
8
  origin: (origin) => origin,
20
9
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
@@ -84,10 +73,9 @@ var CORSPlugin = class {
84
73
  return result;
85
74
  });
86
75
  }
87
- };
76
+ }
88
77
 
89
- // src/plugins/response-headers.ts
90
- var ResponseHeadersPlugin = class {
78
+ class ResponseHeadersPlugin {
91
79
  init(options) {
92
80
  options.rootInterceptors ??= [];
93
81
  options.rootInterceptors.push(async (interceptorOptions) => {
@@ -98,23 +86,18 @@ var ResponseHeadersPlugin = class {
98
86
  return result;
99
87
  }
100
88
  const responseHeaders = result.response.headers;
101
- for (const [key, value2] of headers) {
89
+ for (const [key, value] of headers) {
102
90
  if (Array.isArray(responseHeaders[key])) {
103
- responseHeaders[key].push(value2);
91
+ responseHeaders[key].push(value);
104
92
  } else if (responseHeaders[key] !== void 0) {
105
- responseHeaders[key] = [responseHeaders[key], value2];
93
+ responseHeaders[key] = [responseHeaders[key], value];
106
94
  } else {
107
- responseHeaders[key] = value2;
95
+ responseHeaders[key] = value;
108
96
  }
109
97
  }
110
98
  return result;
111
99
  });
112
100
  }
113
- };
101
+ }
114
102
 
115
- export {
116
- CompositePlugin,
117
- CORSPlugin,
118
- ResponseHeadersPlugin
119
- };
120
- //# sourceMappingURL=chunk-WQNNSBXW.js.map
103
+ export { CORSPlugin, ResponseHeadersPlugin };
@@ -0,0 +1,75 @@
1
+ import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
+ import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
5
+ import { ORPCError } from '@orpc/client';
6
+
7
+ type StandardParams = Record<string, string>;
8
+ type StandardMatchResult = {
9
+ path: readonly string[];
10
+ procedure: AnyProcedure;
11
+ params?: StandardParams;
12
+ } | undefined;
13
+ interface StandardMatcher {
14
+ init(router: AnyRouter): void;
15
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
16
+ }
17
+ interface StandardCodec {
18
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
+ encodeError(error: ORPCError<any, any>): StandardResponse;
20
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
+ }
22
+
23
+ type StandardHandleOptions<T extends Context> = {
24
+ prefix?: HTTPPath;
25
+ } & (Record<never, never> extends T ? {
26
+ context?: T;
27
+ } : {
28
+ context: T;
29
+ });
30
+ type StandardHandleResult = {
31
+ matched: true;
32
+ response: StandardResponse;
33
+ } | {
34
+ matched: false;
35
+ response: undefined;
36
+ };
37
+ type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
+ context: T;
39
+ request: StandardLazyRequest;
40
+ };
41
+ interface StandardHandlerOptions<TContext extends Context> {
42
+ plugins?: HandlerPlugin<TContext>[];
43
+ /**
44
+ * Interceptors at the request level, helpful when you want catch errors
45
+ */
46
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
47
+ /**
48
+ * Interceptors at the root level, helpful when you want override the request/response
49
+ */
50
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
51
+ /**
52
+ *
53
+ * Interceptors for procedure client.
54
+ */
55
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
+ }
57
+ declare class StandardHandler<T extends Context> {
58
+ private readonly matcher;
59
+ private readonly codec;
60
+ private readonly options;
61
+ private readonly plugin;
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
+ handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
64
+ }
65
+
66
+ interface HandlerPlugin<TContext extends Context> {
67
+ init?(options: StandardHandlerOptions<TContext>): void;
68
+ }
69
+ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
70
+ private readonly plugins;
71
+ constructor(plugins?: HandlerPlugin<TContext>[]);
72
+ init(options: StandardHandlerOptions<TContext>): void;
73
+ }
74
+
75
+ export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };