@orpc/server 0.0.0-next.989a435 → 0.0.0-next.999d654

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