@orpc/server 0.0.0-next.32cb70c → 0.0.0-next.32f3296

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 (74) hide show
  1. package/README.md +120 -0
  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/adapters/hono/index.mjs +32 -0
  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 -18
  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} +93 -137
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/plugins/index.mjs +103 -0
  23. package/dist/shared/server.BXfgvxK8.d.ts +8 -0
  24. package/dist/shared/server.B_5ZADvP.mjs +363 -0
  25. package/dist/shared/server.D1vPuPwc.mjs +29 -0
  26. package/dist/shared/server.DKCNBSd-.d.mts +8 -0
  27. package/dist/shared/server.DisswUB5.mjs +158 -0
  28. package/dist/shared/server.Dj89-yLZ.d.ts +75 -0
  29. package/dist/shared/server.DnmJuN02.d.mts +144 -0
  30. package/dist/shared/server.DnmJuN02.d.ts +144 -0
  31. package/dist/shared/server.DpIMjOfC.d.mts +75 -0
  32. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  33. package/package.json +36 -24
  34. package/dist/chunk-ESTRJAOX.js +0 -299
  35. package/dist/chunk-KK4SDLC7.js +0 -320
  36. package/dist/chunk-WUOGVGWG.js +0 -1
  37. package/dist/fetch.js +0 -15
  38. package/dist/hono.js +0 -30
  39. package/dist/node.js +0 -87
  40. package/dist/src/adapters/fetch/index.d.ts +0 -6
  41. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  42. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  43. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  44. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  45. package/dist/src/adapters/fetch/types.d.ts +0 -21
  46. package/dist/src/adapters/hono/index.d.ts +0 -3
  47. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  48. package/dist/src/adapters/next/index.d.ts +0 -3
  49. package/dist/src/adapters/next/serve.d.ts +0 -19
  50. package/dist/src/adapters/node/index.d.ts +0 -5
  51. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  52. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  53. package/dist/src/adapters/node/types.d.ts +0 -22
  54. package/dist/src/builder-variants.d.ts +0 -74
  55. package/dist/src/builder.d.ts +0 -57
  56. package/dist/src/config.d.ts +0 -6
  57. package/dist/src/context.d.ts +0 -9
  58. package/dist/src/hidden.d.ts +0 -8
  59. package/dist/src/implementer-procedure.d.ts +0 -30
  60. package/dist/src/implementer-variants.d.ts +0 -16
  61. package/dist/src/implementer.d.ts +0 -27
  62. package/dist/src/index.d.ts +0 -21
  63. package/dist/src/lazy-utils.d.ts +0 -6
  64. package/dist/src/lazy.d.ts +0 -22
  65. package/dist/src/middleware-decorated.d.ts +0 -10
  66. package/dist/src/middleware-utils.d.ts +0 -5
  67. package/dist/src/middleware.d.ts +0 -37
  68. package/dist/src/procedure-client.d.ts +0 -20
  69. package/dist/src/procedure-decorated.d.ts +0 -21
  70. package/dist/src/procedure-utils.d.ts +0 -17
  71. package/dist/src/procedure.d.ts +0 -29
  72. package/dist/src/router-accessible-lazy.d.ts +0 -8
  73. package/dist/src/router-client.d.ts +0 -22
  74. package/dist/src/router.d.ts +0 -29
@@ -1,31 +1,15 @@
1
- import {
2
- LAZY_LOADER_SYMBOL,
3
- Procedure,
4
- adaptRouter,
5
- addMiddleware,
6
- createAccessibleLazyRouter,
7
- createLazyProcedureFormAnyLazy,
8
- createProcedureClient,
9
- deepSetLazyRouterPrefix,
10
- flatLazy,
11
- getLazyRouterPrefix,
12
- getRouterChild,
13
- getRouterContract,
14
- isLazy,
15
- isProcedure,
16
- lazy,
17
- middlewareOutputFn,
18
- setRouterContract,
19
- unlazy
20
- } from "./chunk-KK4SDLC7.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.B_5ZADvP.mjs';
4
+ export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, q as getHiddenRouterContract, k as getLazyMeta, n as isStartWithMiddlewares, o as mergeMiddlewares, m as middlewareOutputFn, w as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.B_5ZADvP.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';
21
8
 
22
- // src/builder.ts
23
- import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
24
-
25
- // src/config.ts
26
- var DEFAULT_CONFIG = {
9
+ const DEFAULT_CONFIG = {
27
10
  initialInputValidationIndex: 0,
28
- initialOutputValidationIndex: 0
11
+ initialOutputValidationIndex: 0,
12
+ dedupeLeadingMiddlewares: true
29
13
  };
30
14
  function fallbackConfig(key, value) {
31
15
  if (value === void 0) {
@@ -34,9 +18,8 @@ function fallbackConfig(key, value) {
34
18
  return value;
35
19
  }
36
20
 
37
- // src/middleware-decorated.ts
38
21
  function decorateMiddleware(middleware) {
39
- const decorated = middleware;
22
+ const decorated = (...args) => middleware(...args);
40
23
  decorated.mapInput = (mapInput) => {
41
24
  const mapped = decorateMiddleware(
42
25
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -46,10 +29,14 @@ function decorateMiddleware(middleware) {
46
29
  decorated.concat = (concatMiddleware, mapInput) => {
47
30
  const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
48
31
  const concatted = decorateMiddleware((options, input, output, ...rest) => {
49
- const next = async (...[nextOptions]) => {
50
- return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
51
- };
52
- const merged = middleware({ ...options, next }, input, output, ...rest);
32
+ const merged = middleware({
33
+ ...options,
34
+ next: (...[nextOptions1]) => mapped({
35
+ ...options,
36
+ context: { ...options.context, ...nextOptions1?.context },
37
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
38
+ }, input, output, ...rest)
39
+ }, input, output, ...rest);
53
40
  return merged;
54
41
  });
55
42
  return concatted;
@@ -57,30 +44,28 @@ function decorateMiddleware(middleware) {
57
44
  return decorated;
58
45
  }
59
46
 
60
- // src/procedure-decorated.ts
61
- import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
62
- var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
47
+ class DecoratedProcedure extends Procedure {
63
48
  errors(errors) {
64
- return new _DecoratedProcedure({
49
+ return new DecoratedProcedure({
65
50
  ...this["~orpc"],
66
51
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
67
52
  });
68
53
  }
69
54
  meta(meta) {
70
- return new _DecoratedProcedure({
55
+ return new DecoratedProcedure({
71
56
  ...this["~orpc"],
72
57
  meta: mergeMeta(this["~orpc"].meta, meta)
73
58
  });
74
59
  }
75
60
  route(route) {
76
- return new _DecoratedProcedure({
61
+ return new DecoratedProcedure({
77
62
  ...this["~orpc"],
78
63
  route: mergeRoute(this["~orpc"].route, route)
79
64
  });
80
65
  }
81
66
  use(middleware, mapInput) {
82
67
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
83
- return new _DecoratedProcedure({
68
+ return new DecoratedProcedure({
84
69
  ...this["~orpc"],
85
70
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
86
71
  });
@@ -89,9 +74,13 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
89
74
  * Make this procedure callable (works like a function while still being a procedure).
90
75
  */
91
76
  callable(...rest) {
92
- return Object.assign(createProcedureClient(this, ...rest), {
93
- "~type": "Procedure",
94
- "~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
+ }
95
84
  });
96
85
  }
97
86
  /**
@@ -100,10 +89,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
100
89
  actionable(...rest) {
101
90
  return this.callable(...rest);
102
91
  }
103
- };
92
+ }
104
93
 
105
- // src/builder.ts
106
- var Builder = class _Builder {
94
+ class Builder {
107
95
  "~orpc";
108
96
  constructor(def) {
109
97
  this["~orpc"] = def;
@@ -114,9 +102,10 @@ var Builder = class _Builder {
114
102
  $config(config) {
115
103
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
116
104
  const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
117
- return new _Builder({
105
+ return new Builder({
118
106
  ...this["~orpc"],
119
107
  config,
108
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
120
109
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
121
110
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
122
111
  });
@@ -125,7 +114,7 @@ var Builder = class _Builder {
125
114
  * Reset initial context
126
115
  */
127
116
  $context() {
128
- return new _Builder({
117
+ return new Builder({
129
118
  ...this["~orpc"],
130
119
  middlewares: [],
131
120
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
@@ -136,7 +125,7 @@ var Builder = class _Builder {
136
125
  * Reset initial meta
137
126
  */
138
127
  $meta(initialMeta) {
139
- return new _Builder({
128
+ return new Builder({
140
129
  ...this["~orpc"],
141
130
  meta: initialMeta
142
131
  });
@@ -145,48 +134,54 @@ var Builder = class _Builder {
145
134
  * Reset initial route
146
135
  */
147
136
  $route(initialRoute) {
148
- return new _Builder({
137
+ return new Builder({
149
138
  ...this["~orpc"],
150
139
  route: initialRoute
151
140
  });
152
141
  }
142
+ $input(initialInputSchema) {
143
+ return new Builder({
144
+ ...this["~orpc"],
145
+ inputSchema: initialInputSchema
146
+ });
147
+ }
153
148
  middleware(middleware) {
154
149
  return decorateMiddleware(middleware);
155
150
  }
156
151
  errors(errors) {
157
- return new _Builder({
152
+ return new Builder({
158
153
  ...this["~orpc"],
159
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
154
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
160
155
  });
161
156
  }
162
157
  use(middleware, mapInput) {
163
158
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
164
- return new _Builder({
159
+ return new Builder({
165
160
  ...this["~orpc"],
166
161
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
167
162
  });
168
163
  }
169
164
  meta(meta) {
170
- return new _Builder({
165
+ return new Builder({
171
166
  ...this["~orpc"],
172
- meta: mergeMeta2(this["~orpc"].meta, meta)
167
+ meta: mergeMeta(this["~orpc"].meta, meta)
173
168
  });
174
169
  }
175
170
  route(route) {
176
- return new _Builder({
171
+ return new Builder({
177
172
  ...this["~orpc"],
178
- route: mergeRoute2(this["~orpc"].route, route)
173
+ route: mergeRoute(this["~orpc"].route, route)
179
174
  });
180
175
  }
181
176
  input(schema) {
182
- return new _Builder({
177
+ return new Builder({
183
178
  ...this["~orpc"],
184
179
  inputSchema: schema,
185
180
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
186
181
  });
187
182
  }
188
183
  output(schema) {
189
- return new _Builder({
184
+ return new Builder({
190
185
  ...this["~orpc"],
191
186
  outputSchema: schema,
192
187
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
@@ -199,43 +194,39 @@ var Builder = class _Builder {
199
194
  });
200
195
  }
201
196
  prefix(prefix) {
202
- return new _Builder({
197
+ return new Builder({
203
198
  ...this["~orpc"],
204
199
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
205
200
  });
206
201
  }
207
202
  tag(...tags) {
208
- return new _Builder({
203
+ return new Builder({
209
204
  ...this["~orpc"],
210
205
  tags: mergeTags(this["~orpc"].tags, tags)
211
206
  });
212
207
  }
213
208
  router(router) {
214
- return adaptRouter(router, this["~orpc"]);
209
+ return enhanceRouter(router, this["~orpc"]);
215
210
  }
216
211
  lazy(loader) {
217
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
212
+ return enhanceRouter(lazy(loader), this["~orpc"]);
218
213
  }
219
- };
220
- var os = new Builder({
214
+ }
215
+ const os = new Builder({
221
216
  config: {},
222
217
  route: {},
223
218
  meta: {},
224
219
  errorMap: {},
225
- inputSchema: void 0,
226
- outputSchema: void 0,
227
220
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
228
221
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
229
- middlewares: []
222
+ middlewares: [],
223
+ dedupeLeadingMiddlewares: true
230
224
  });
231
225
 
232
- // src/context.ts
233
- function mergeContext(context, other) {
226
+ function mergeCurrentContext(context, other) {
234
227
  return { ...context, ...other };
235
228
  }
236
229
 
237
- // src/implementer.ts
238
- import { isContractProcedure } from "@orpc/contract";
239
230
  function implementerInternal(contract, config, middlewares) {
240
231
  if (isContractProcedure(contract)) {
241
232
  const impl2 = new Builder({
@@ -243,12 +234,16 @@ function implementerInternal(contract, config, middlewares) {
243
234
  config,
244
235
  middlewares,
245
236
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
246
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
237
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
238
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
247
239
  });
248
240
  return impl2;
249
241
  }
250
242
  const impl = new Proxy(contract, {
251
243
  get: (target, key) => {
244
+ if (typeof key !== "string") {
245
+ return Reflect.get(target, key);
246
+ }
252
247
  let method;
253
248
  if (key === "middleware") {
254
249
  method = (mid) => decorateMiddleware(mid);
@@ -262,23 +257,29 @@ function implementerInternal(contract, config, middlewares) {
262
257
  };
263
258
  } else if (key === "router") {
264
259
  method = (router) => {
265
- const adapted = adaptRouter(router, {
260
+ const adapted = enhanceRouter(router, {
266
261
  middlewares,
267
- errorMap: {}
262
+ errorMap: {},
263
+ prefix: void 0,
264
+ tags: void 0,
265
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
268
266
  });
269
- return setRouterContract(adapted, contract);
267
+ return setHiddenRouterContract(adapted, contract);
270
268
  };
271
269
  } else if (key === "lazy") {
272
270
  method = (loader) => {
273
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
271
+ const adapted = enhanceRouter(lazy(loader), {
274
272
  middlewares,
275
- errorMap: {}
273
+ errorMap: {},
274
+ prefix: void 0,
275
+ tags: void 0,
276
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
276
277
  });
277
- return setRouterContract(adapted, contract);
278
+ return setHiddenRouterContract(adapted, contract);
278
279
  };
279
280
  }
280
- const next = Reflect.get(target, key);
281
- if (!next || typeof next !== "function" && typeof next !== "object") {
281
+ const next = getContractRouter(target, [key]);
282
+ if (!next) {
282
283
  return method ?? next;
283
284
  }
284
285
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -305,44 +306,34 @@ function implement(contract, config = {}) {
305
306
  method = (config2) => implement(contract, config2);
306
307
  }
307
308
  const next = Reflect.get(target, key);
308
- if (!next || typeof next !== "function" && typeof next !== "object") {
309
- return method ?? next;
310
- }
311
- if (method) {
312
- return new Proxy(method, {
313
- get(_, key2) {
314
- return Reflect.get(next, key2);
315
- }
316
- });
309
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
310
+ return method || next;
317
311
  }
318
- return next;
312
+ return new Proxy(method, {
313
+ get(_, key2) {
314
+ return Reflect.get(next, key2);
315
+ }
316
+ });
319
317
  }
320
318
  });
321
319
  return impl;
322
320
  }
323
321
 
324
- // src/procedure-utils.ts
325
- function call(procedure, input, ...rest) {
326
- return createProcedureClient(procedure, ...rest)(input);
327
- }
328
-
329
- // src/router-client.ts
330
- function createRouterClient(router, ...rest) {
322
+ function createRouterClient(router, ...[options]) {
331
323
  if (isProcedure(router)) {
332
- const caller = createProcedureClient(router, ...rest);
324
+ const caller = createProcedureClient(router, options);
333
325
  return caller;
334
326
  }
335
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
327
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
336
328
  const recursive = new Proxy(procedureCaller, {
337
329
  get(target, key) {
338
330
  if (typeof key !== "string") {
339
331
  return Reflect.get(target, key);
340
332
  }
341
- const next = getRouterChild(router, key);
333
+ const next = getRouter(router, [key]);
342
334
  if (!next) {
343
335
  return Reflect.get(target, key);
344
336
  }
345
- const [options] = rest;
346
337
  return createRouterClient(next, {
347
338
  ...options,
348
339
  path: [...options?.path ?? [], key]
@@ -352,39 +343,4 @@ function createRouterClient(router, ...rest) {
352
343
  return recursive;
353
344
  }
354
345
 
355
- // src/index.ts
356
- import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
357
- export {
358
- Builder,
359
- DecoratedProcedure,
360
- LAZY_LOADER_SYMBOL,
361
- ORPCError,
362
- Procedure,
363
- adaptRouter,
364
- call,
365
- createAccessibleLazyRouter,
366
- createLazyProcedureFormAnyLazy,
367
- createProcedureClient,
368
- createRouterClient,
369
- decorateMiddleware,
370
- deepSetLazyRouterPrefix,
371
- fallbackConfig,
372
- flatLazy,
373
- getLazyRouterPrefix,
374
- getRouterChild,
375
- getRouterContract,
376
- implement,
377
- implementerInternal,
378
- isDefinedError,
379
- isLazy,
380
- isProcedure,
381
- lazy,
382
- mergeContext,
383
- middlewareOutputFn,
384
- os,
385
- safe,
386
- setRouterContract,
387
- type,
388
- unlazy
389
- };
390
- //# sourceMappingURL=index.js.map
346
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, mergeCurrentContext, os, setHiddenRouterContract };
@@ -0,0 +1,31 @@
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DpIMjOfC.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.DpIMjOfC.mjs';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.DnmJuN02.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.Dj89-yLZ.js';
2
+ export { C as CompositePlugin } from '../shared/server.Dj89-yLZ.js';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.DnmJuN02.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 };
@@ -0,0 +1,103 @@
1
+ export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
2
+ import { value } from '@orpc/shared';
3
+
4
+ class CORSPlugin {
5
+ options;
6
+ constructor(options = {}) {
7
+ const defaults = {
8
+ origin: (origin) => origin,
9
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
10
+ };
11
+ this.options = {
12
+ ...defaults,
13
+ ...options
14
+ };
15
+ }
16
+ init(options) {
17
+ options.rootInterceptors ??= [];
18
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
19
+ if (interceptorOptions.request.method === "OPTIONS") {
20
+ const resHeaders = {};
21
+ if (this.options.maxAge !== void 0) {
22
+ resHeaders["access-control-max-age"] = this.options.maxAge.toString();
23
+ }
24
+ if (this.options.allowMethods?.length) {
25
+ resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
26
+ }
27
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
28
+ if (Array.isArray(allowHeaders) && allowHeaders.length) {
29
+ resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
30
+ } else if (typeof allowHeaders === "string") {
31
+ resHeaders["access-control-allow-headers"] = allowHeaders;
32
+ }
33
+ return {
34
+ matched: true,
35
+ response: {
36
+ status: 204,
37
+ headers: resHeaders,
38
+ body: void 0
39
+ }
40
+ };
41
+ }
42
+ return interceptorOptions.next();
43
+ });
44
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
45
+ const result = await interceptorOptions.next();
46
+ if (!result.matched) {
47
+ return result;
48
+ }
49
+ const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
50
+ const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
51
+ const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
52
+ if (allowedOriginArr.includes("*")) {
53
+ result.response.headers["access-control-allow-origin"] = "*";
54
+ } else {
55
+ if (allowedOriginArr.includes(origin)) {
56
+ result.response.headers["access-control-allow-origin"] = origin;
57
+ }
58
+ result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
59
+ }
60
+ const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
61
+ const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
62
+ if (allowedTimingOriginArr.includes("*")) {
63
+ result.response.headers["timing-allow-origin"] = "*";
64
+ } else if (allowedTimingOriginArr.includes(origin)) {
65
+ result.response.headers["timing-allow-origin"] = origin;
66
+ }
67
+ if (this.options.credentials) {
68
+ result.response.headers["access-control-allow-credentials"] = "true";
69
+ }
70
+ if (this.options.exposeHeaders?.length) {
71
+ result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
72
+ }
73
+ return result;
74
+ });
75
+ }
76
+ }
77
+
78
+ class ResponseHeadersPlugin {
79
+ init(options) {
80
+ options.rootInterceptors ??= [];
81
+ options.rootInterceptors.push(async (interceptorOptions) => {
82
+ const headers = new Headers();
83
+ interceptorOptions.context.resHeaders = headers;
84
+ const result = await interceptorOptions.next();
85
+ if (!result.matched) {
86
+ return result;
87
+ }
88
+ const responseHeaders = result.response.headers;
89
+ for (const [key, value] of headers) {
90
+ if (Array.isArray(responseHeaders[key])) {
91
+ responseHeaders[key].push(value);
92
+ } else if (responseHeaders[key] !== void 0) {
93
+ responseHeaders[key] = [responseHeaders[key], value];
94
+ } else {
95
+ responseHeaders[key] = value;
96
+ }
97
+ }
98
+ return result;
99
+ });
100
+ }
101
+ }
102
+
103
+ export { CORSPlugin, ResponseHeadersPlugin };
@@ -0,0 +1,8 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context } from './server.DnmJuN02.js';
3
+ import { a as StandardHandlerOptions } from './server.Dj89-yLZ.js';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ }
7
+
8
+ export type { StandardRPCHandlerOptions as S };