@orpc/server 0.0.0-next.905e81c → 0.0.0-next.910f96e

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 (83) hide show
  1. package/README.md +15 -2
  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/{hono.js → adapters/hono/index.mjs} +11 -13
  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 -13
  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} +107 -157
  20. package/dist/plugins/index.d.mts +30 -0
  21. package/dist/plugins/index.d.ts +30 -0
  22. package/dist/{chunk-WQNNSBXW.js → plugins/index.mjs} +19 -32
  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/{chunk-77FU7QSO.js → shared/server.Dfx1jV-K.mjs} +49 -69
  33. package/dist/shared/server.T5WmDoWQ.mjs +98 -0
  34. package/dist/{chunk-MHVECKBC.js → shared/server.e3W6AG3-.mjs} +162 -213
  35. package/package.json +30 -35
  36. package/dist/chunk-47YYO5JS.js +0 -32
  37. package/dist/fetch.js +0 -10
  38. package/dist/node.js +0 -31
  39. package/dist/plugins.js +0 -11
  40. package/dist/src/adapters/fetch/index.d.ts +0 -3
  41. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  42. package/dist/src/adapters/fetch/types.d.ts +0 -14
  43. package/dist/src/adapters/hono/index.d.ts +0 -3
  44. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  45. package/dist/src/adapters/next/index.d.ts +0 -3
  46. package/dist/src/adapters/next/serve.d.ts +0 -19
  47. package/dist/src/adapters/node/index.d.ts +0 -3
  48. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  49. package/dist/src/adapters/node/types.d.ts +0 -22
  50. package/dist/src/adapters/standard/handler.d.ts +0 -53
  51. package/dist/src/adapters/standard/index.d.ts +0 -6
  52. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  53. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  54. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  55. package/dist/src/adapters/standard/types.d.ts +0 -21
  56. package/dist/src/builder-variants.d.ts +0 -75
  57. package/dist/src/builder.d.ts +0 -58
  58. package/dist/src/config.d.ts +0 -6
  59. package/dist/src/context.d.ts +0 -8
  60. package/dist/src/error.d.ts +0 -12
  61. package/dist/src/hidden.d.ts +0 -8
  62. package/dist/src/implementer-procedure.d.ts +0 -33
  63. package/dist/src/implementer-variants.d.ts +0 -18
  64. package/dist/src/implementer.d.ts +0 -29
  65. package/dist/src/index.d.ts +0 -25
  66. package/dist/src/lazy-utils.d.ts +0 -6
  67. package/dist/src/lazy.d.ts +0 -22
  68. package/dist/src/middleware-decorated.d.ts +0 -11
  69. package/dist/src/middleware-utils.d.ts +0 -5
  70. package/dist/src/middleware.d.ts +0 -38
  71. package/dist/src/plugins/base.d.ts +0 -11
  72. package/dist/src/plugins/cors.d.ts +0 -19
  73. package/dist/src/plugins/index.d.ts +0 -4
  74. package/dist/src/plugins/response-headers.d.ts +0 -10
  75. package/dist/src/procedure-client.d.ts +0 -33
  76. package/dist/src/procedure-decorated.d.ts +0 -24
  77. package/dist/src/procedure-utils.d.ts +0 -19
  78. package/dist/src/procedure.d.ts +0 -31
  79. package/dist/src/router-accessible-lazy.d.ts +0 -8
  80. package/dist/src/router-client.d.ts +0 -12
  81. package/dist/src/router.d.ts +0 -30
  82. package/dist/src/utils.d.ts +0 -24
  83. package/dist/standard.js +0 -13
@@ -1,35 +1,16 @@
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, 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';
25
9
 
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 = {
10
+ const DEFAULT_CONFIG = {
31
11
  initialInputValidationIndex: 0,
32
- initialOutputValidationIndex: 0
12
+ initialOutputValidationIndex: 0,
13
+ dedupeLeadingMiddlewares: true
33
14
  };
34
15
  function fallbackConfig(key, value) {
35
16
  if (value === void 0) {
@@ -38,9 +19,8 @@ function fallbackConfig(key, value) {
38
19
  return value;
39
20
  }
40
21
 
41
- // src/middleware-decorated.ts
42
22
  function decorateMiddleware(middleware) {
43
- const decorated = middleware;
23
+ const decorated = (...args) => middleware(...args);
44
24
  decorated.mapInput = (mapInput) => {
45
25
  const mapped = decorateMiddleware(
46
26
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -65,30 +45,39 @@ function decorateMiddleware(middleware) {
65
45
  return decorated;
66
46
  }
67
47
 
68
- // src/procedure-decorated.ts
69
- import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
70
- 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 {
71
60
  errors(errors) {
72
- return new _DecoratedProcedure({
61
+ return new DecoratedProcedure({
73
62
  ...this["~orpc"],
74
63
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
75
64
  });
76
65
  }
77
66
  meta(meta) {
78
- return new _DecoratedProcedure({
67
+ return new DecoratedProcedure({
79
68
  ...this["~orpc"],
80
69
  meta: mergeMeta(this["~orpc"].meta, meta)
81
70
  });
82
71
  }
83
72
  route(route) {
84
- return new _DecoratedProcedure({
73
+ return new DecoratedProcedure({
85
74
  ...this["~orpc"],
86
75
  route: mergeRoute(this["~orpc"].route, route)
87
76
  });
88
77
  }
89
78
  use(middleware, mapInput) {
90
79
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
91
- return new _DecoratedProcedure({
80
+ return new DecoratedProcedure({
92
81
  ...this["~orpc"],
93
82
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
94
83
  });
@@ -97,21 +86,33 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
97
86
  * Make this procedure callable (works like a function while still being a procedure).
98
87
  */
99
88
  callable(...rest) {
100
- return Object.assign(createProcedureClient(this, ...rest), {
101
- "~type": "Procedure",
102
- "~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
+ }
103
97
  });
104
98
  }
105
99
  /**
106
- * 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.
107
101
  */
108
102
  actionable(...rest) {
109
- 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
+ });
110
112
  }
111
- };
113
+ }
112
114
 
113
- // src/builder.ts
114
- var Builder = class _Builder {
115
+ class Builder {
115
116
  "~orpc";
116
117
  constructor(def) {
117
118
  this["~orpc"] = def;
@@ -122,9 +123,10 @@ var Builder = class _Builder {
122
123
  $config(config) {
123
124
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
124
125
  const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
125
- return new _Builder({
126
+ return new Builder({
126
127
  ...this["~orpc"],
127
128
  config,
129
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
128
130
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
129
131
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
130
132
  });
@@ -133,7 +135,7 @@ var Builder = class _Builder {
133
135
  * Reset initial context
134
136
  */
135
137
  $context() {
136
- return new _Builder({
138
+ return new Builder({
137
139
  ...this["~orpc"],
138
140
  middlewares: [],
139
141
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
@@ -144,7 +146,7 @@ var Builder = class _Builder {
144
146
  * Reset initial meta
145
147
  */
146
148
  $meta(initialMeta) {
147
- return new _Builder({
149
+ return new Builder({
148
150
  ...this["~orpc"],
149
151
  meta: initialMeta
150
152
  });
@@ -153,48 +155,54 @@ var Builder = class _Builder {
153
155
  * Reset initial route
154
156
  */
155
157
  $route(initialRoute) {
156
- return new _Builder({
158
+ return new Builder({
157
159
  ...this["~orpc"],
158
160
  route: initialRoute
159
161
  });
160
162
  }
163
+ $input(initialInputSchema) {
164
+ return new Builder({
165
+ ...this["~orpc"],
166
+ inputSchema: initialInputSchema
167
+ });
168
+ }
161
169
  middleware(middleware) {
162
170
  return decorateMiddleware(middleware);
163
171
  }
164
172
  errors(errors) {
165
- return new _Builder({
173
+ return new Builder({
166
174
  ...this["~orpc"],
167
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
175
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
168
176
  });
169
177
  }
170
178
  use(middleware, mapInput) {
171
179
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
172
- return new _Builder({
180
+ return new Builder({
173
181
  ...this["~orpc"],
174
182
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
175
183
  });
176
184
  }
177
185
  meta(meta) {
178
- return new _Builder({
186
+ return new Builder({
179
187
  ...this["~orpc"],
180
- meta: mergeMeta2(this["~orpc"].meta, meta)
188
+ meta: mergeMeta(this["~orpc"].meta, meta)
181
189
  });
182
190
  }
183
191
  route(route) {
184
- return new _Builder({
192
+ return new Builder({
185
193
  ...this["~orpc"],
186
- route: mergeRoute2(this["~orpc"].route, route)
194
+ route: mergeRoute(this["~orpc"].route, route)
187
195
  });
188
196
  }
189
197
  input(schema) {
190
- return new _Builder({
198
+ return new Builder({
191
199
  ...this["~orpc"],
192
200
  inputSchema: schema,
193
201
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
194
202
  });
195
203
  }
196
204
  output(schema) {
197
- return new _Builder({
205
+ return new Builder({
198
206
  ...this["~orpc"],
199
207
  outputSchema: schema,
200
208
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
@@ -207,43 +215,35 @@ var Builder = class _Builder {
207
215
  });
208
216
  }
209
217
  prefix(prefix) {
210
- return new _Builder({
218
+ return new Builder({
211
219
  ...this["~orpc"],
212
220
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
213
221
  });
214
222
  }
215
223
  tag(...tags) {
216
- return new _Builder({
224
+ return new Builder({
217
225
  ...this["~orpc"],
218
226
  tags: mergeTags(this["~orpc"].tags, tags)
219
227
  });
220
228
  }
221
229
  router(router) {
222
- return adaptRouter(router, this["~orpc"]);
230
+ return enhanceRouter(router, this["~orpc"]);
223
231
  }
224
232
  lazy(loader) {
225
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
233
+ return enhanceRouter(lazy(loader), this["~orpc"]);
226
234
  }
227
- };
228
- var os = new Builder({
235
+ }
236
+ const os = new Builder({
229
237
  config: {},
230
238
  route: {},
231
239
  meta: {},
232
240
  errorMap: {},
233
- inputSchema: void 0,
234
- outputSchema: void 0,
235
241
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
236
242
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
237
- middlewares: []
243
+ middlewares: [],
244
+ dedupeLeadingMiddlewares: true
238
245
  });
239
246
 
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
247
  function implementerInternal(contract, config, middlewares) {
248
248
  if (isContractProcedure(contract)) {
249
249
  const impl2 = new Builder({
@@ -251,12 +251,16 @@ function implementerInternal(contract, config, middlewares) {
251
251
  config,
252
252
  middlewares,
253
253
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
254
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
254
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
255
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
255
256
  });
256
257
  return impl2;
257
258
  }
258
259
  const impl = new Proxy(contract, {
259
260
  get: (target, key) => {
261
+ if (typeof key !== "string") {
262
+ return Reflect.get(target, key);
263
+ }
260
264
  let method;
261
265
  if (key === "middleware") {
262
266
  method = (mid) => decorateMiddleware(mid);
@@ -270,23 +274,29 @@ function implementerInternal(contract, config, middlewares) {
270
274
  };
271
275
  } else if (key === "router") {
272
276
  method = (router) => {
273
- const adapted = adaptRouter(router, {
277
+ const adapted = enhanceRouter(router, {
274
278
  middlewares,
275
- errorMap: {}
279
+ errorMap: {},
280
+ prefix: void 0,
281
+ tags: void 0,
282
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
276
283
  });
277
- return setRouterContract(adapted, contract);
284
+ return setHiddenRouterContract(adapted, contract);
278
285
  };
279
286
  } else if (key === "lazy") {
280
287
  method = (loader) => {
281
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
288
+ const adapted = enhanceRouter(lazy(loader), {
282
289
  middlewares,
283
- errorMap: {}
290
+ errorMap: {},
291
+ prefix: void 0,
292
+ tags: void 0,
293
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
284
294
  });
285
- return setRouterContract(adapted, contract);
295
+ return setHiddenRouterContract(adapted, contract);
286
296
  };
287
297
  }
288
- const next = Reflect.get(target, key);
289
- if (!next || typeof next !== "function" && typeof next !== "object") {
298
+ const next = getContractRouter(target, [key]);
299
+ if (!next) {
290
300
  return method ?? next;
291
301
  }
292
302
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -313,44 +323,34 @@ function implement(contract, config = {}) {
313
323
  method = (config2) => implement(contract, config2);
314
324
  }
315
325
  const next = Reflect.get(target, key);
316
- if (!next || typeof next !== "function" && typeof next !== "object") {
317
- return method ?? next;
326
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
327
+ return method || next;
318
328
  }
319
- if (method) {
320
- return new Proxy(method, {
321
- get(_, key2) {
322
- return Reflect.get(next, key2);
323
- }
324
- });
325
- }
326
- return next;
329
+ return new Proxy(method, {
330
+ get(_, key2) {
331
+ return Reflect.get(next, key2);
332
+ }
333
+ });
327
334
  }
328
335
  });
329
336
  return impl;
330
337
  }
331
338
 
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) {
339
+ function createRouterClient(router, ...[options]) {
339
340
  if (isProcedure(router)) {
340
- const caller = createProcedureClient(router, ...rest);
341
+ const caller = createProcedureClient(router, options);
341
342
  return caller;
342
343
  }
343
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
344
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
344
345
  const recursive = new Proxy(procedureCaller, {
345
346
  get(target, key) {
346
347
  if (typeof key !== "string") {
347
348
  return Reflect.get(target, key);
348
349
  }
349
- const next = getRouterChild(router, key);
350
+ const next = getRouter(router, [key]);
350
351
  if (!next) {
351
352
  return Reflect.get(target, key);
352
353
  }
353
- const [options] = rest;
354
354
  return createRouterClient(next, {
355
355
  ...options,
356
356
  path: [...options?.path ?? [], key]
@@ -360,54 +360,4 @@ function createRouterClient(router, ...rest) {
360
360
  return recursive;
361
361
  }
362
362
 
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
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 };
@@ -1,20 +1,8 @@
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
+ import { value } from '@orpc/shared';
12
2
 
13
- // src/plugins/cors.ts
14
- import { value } from "@orpc/shared";
15
- var CORSPlugin = class {
3
+ class CORSPlugin {
16
4
  options;
17
- constructor(options) {
5
+ constructor(options = {}) {
18
6
  const defaults = {
19
7
  origin: (origin) => origin,
20
8
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
@@ -84,37 +72,36 @@ var CORSPlugin = class {
84
72
  return result;
85
73
  });
86
74
  }
87
- };
75
+ }
88
76
 
89
- // src/plugins/response-headers.ts
90
- var ResponseHeadersPlugin = class {
77
+ class ResponseHeadersPlugin {
91
78
  init(options) {
92
79
  options.rootInterceptors ??= [];
93
80
  options.rootInterceptors.push(async (interceptorOptions) => {
94
- const headers = new Headers();
95
- interceptorOptions.context.resHeaders = headers;
96
- const result = await interceptorOptions.next();
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
+ });
97
89
  if (!result.matched) {
98
90
  return result;
99
91
  }
100
92
  const responseHeaders = result.response.headers;
101
- for (const [key, value2] of headers) {
93
+ for (const [key, value] of resHeaders) {
102
94
  if (Array.isArray(responseHeaders[key])) {
103
- responseHeaders[key].push(value2);
95
+ responseHeaders[key].push(value);
104
96
  } else if (responseHeaders[key] !== void 0) {
105
- responseHeaders[key] = [responseHeaders[key], value2];
97
+ responseHeaders[key] = [responseHeaders[key], value];
106
98
  } else {
107
- responseHeaders[key] = value2;
99
+ responseHeaders[key] = value;
108
100
  }
109
101
  }
110
102
  return result;
111
103
  });
112
104
  }
113
- };
105
+ }
114
106
 
115
- export {
116
- CompositePlugin,
117
- CORSPlugin,
118
- ResponseHeadersPlugin
119
- };
120
- //# sourceMappingURL=chunk-WQNNSBXW.js.map
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 };
@@ -0,0 +1,66 @@
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
4
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
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
+ interface StandardHandleOptions<T extends Context> {
24
+ prefix?: HTTPPath;
25
+ context: T;
26
+ }
27
+ type StandardHandleResult = {
28
+ matched: true;
29
+ response: StandardResponse;
30
+ } | {
31
+ matched: false;
32
+ response: undefined;
33
+ };
34
+ interface StandardHandlerPlugin<TContext extends Context> {
35
+ init?(options: StandardHandlerOptions<TContext>): void;
36
+ }
37
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
+ request: StandardLazyRequest;
39
+ }
40
+ interface StandardHandlerOptions<TContext extends Context> {
41
+ plugins?: StandardHandlerPlugin<TContext>[];
42
+ /**
43
+ * Interceptors at the request level, helpful when you want catch errors
44
+ */
45
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
46
+ /**
47
+ * Interceptors at the root level, helpful when you want override the request/response
48
+ */
49
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
50
+ /**
51
+ *
52
+ * Interceptors for procedure client.
53
+ */
54
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
55
+ }
56
+ declare class StandardHandler<T extends Context> {
57
+ private readonly matcher;
58
+ private readonly codec;
59
+ private readonly interceptors;
60
+ private readonly clientInterceptors;
61
+ private readonly rootInterceptors;
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
+ }
65
+
66
+ export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };