@orpc/server 0.0.0-next.c099c92 → 0.0.0-next.c0ca4c7

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