@orpc/server 0.0.0-next.380dcaa → 0.0.0-next.3afb521

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 (79) hide show
  1. package/README.md +118 -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 +264 -0
  18. package/dist/index.d.ts +264 -0
  19. package/dist/{index.js → index.mjs} +54 -132
  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} +16 -38
  23. package/dist/{chunk-LXOL226G.js → shared/server.3cSam35R.mjs} +28 -52
  24. package/dist/{chunk-MHVECKBC.js → shared/server.BFBhsdJr.mjs} +134 -210
  25. package/dist/shared/server.C99bm-AA.d.mts +143 -0
  26. package/dist/shared/server.C99bm-AA.d.ts +143 -0
  27. package/dist/shared/server.CjB_m7jG.mjs +28 -0
  28. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  29. package/dist/shared/server.SegZfF38.d.ts +77 -0
  30. package/dist/shared/server.rcYTv2pz.d.mts +77 -0
  31. package/package.json +29 -34
  32. package/dist/chunk-KPT6FDBK.js +0 -32
  33. package/dist/fetch.js +0 -10
  34. package/dist/node.js +0 -31
  35. package/dist/plugins.js +0 -11
  36. package/dist/src/adapters/fetch/index.d.ts +0 -3
  37. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  38. package/dist/src/adapters/fetch/types.d.ts +0 -14
  39. package/dist/src/adapters/hono/index.d.ts +0 -3
  40. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  41. package/dist/src/adapters/next/index.d.ts +0 -3
  42. package/dist/src/adapters/next/serve.d.ts +0 -19
  43. package/dist/src/adapters/node/index.d.ts +0 -3
  44. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  45. package/dist/src/adapters/node/types.d.ts +0 -22
  46. package/dist/src/adapters/standard/handler.d.ts +0 -51
  47. package/dist/src/adapters/standard/index.d.ts +0 -6
  48. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  49. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  50. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  51. package/dist/src/adapters/standard/types.d.ts +0 -21
  52. package/dist/src/builder-variants.d.ts +0 -75
  53. package/dist/src/builder.d.ts +0 -58
  54. package/dist/src/config.d.ts +0 -6
  55. package/dist/src/context.d.ts +0 -8
  56. package/dist/src/error.d.ts +0 -12
  57. package/dist/src/hidden.d.ts +0 -8
  58. package/dist/src/implementer-procedure.d.ts +0 -33
  59. package/dist/src/implementer-variants.d.ts +0 -18
  60. package/dist/src/implementer.d.ts +0 -29
  61. package/dist/src/index.d.ts +0 -25
  62. package/dist/src/lazy-utils.d.ts +0 -6
  63. package/dist/src/lazy.d.ts +0 -22
  64. package/dist/src/middleware-decorated.d.ts +0 -11
  65. package/dist/src/middleware-utils.d.ts +0 -5
  66. package/dist/src/middleware.d.ts +0 -38
  67. package/dist/src/plugins/base.d.ts +0 -13
  68. package/dist/src/plugins/cors.d.ts +0 -19
  69. package/dist/src/plugins/index.d.ts +0 -4
  70. package/dist/src/plugins/response-headers.d.ts +0 -10
  71. package/dist/src/procedure-client.d.ts +0 -33
  72. package/dist/src/procedure-decorated.d.ts +0 -24
  73. package/dist/src/procedure-utils.d.ts +0 -19
  74. package/dist/src/procedure.d.ts +0 -31
  75. package/dist/src/router-accessible-lazy.d.ts +0 -8
  76. package/dist/src/router-client.d.ts +0 -12
  77. package/dist/src/router.d.ts +0 -30
  78. package/dist/src/utils.d.ts +0 -24
  79. package/dist/standard.js +0 -13
@@ -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-MHVECKBC.js";
1
+ import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
2
+ export { ValidationError, eventIterator, type } from '@orpc/contract';
3
+ import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BFBhsdJr.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 } from './shared/server.BFBhsdJr.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,7 +17,6 @@ function fallbackConfig(key, value) {
38
17
  return value;
39
18
  }
40
19
 
41
- // src/middleware-decorated.ts
42
20
  function decorateMiddleware(middleware) {
43
21
  const decorated = middleware;
44
22
  decorated.mapInput = (mapInput) => {
@@ -65,30 +43,28 @@ function decorateMiddleware(middleware) {
65
43
  return decorated;
66
44
  }
67
45
 
68
- // src/procedure-decorated.ts
69
- import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
70
- var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
46
+ class DecoratedProcedure extends Procedure {
71
47
  errors(errors) {
72
- return new _DecoratedProcedure({
48
+ return new DecoratedProcedure({
73
49
  ...this["~orpc"],
74
50
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
75
51
  });
76
52
  }
77
53
  meta(meta) {
78
- return new _DecoratedProcedure({
54
+ return new DecoratedProcedure({
79
55
  ...this["~orpc"],
80
56
  meta: mergeMeta(this["~orpc"].meta, meta)
81
57
  });
82
58
  }
83
59
  route(route) {
84
- return new _DecoratedProcedure({
60
+ return new DecoratedProcedure({
85
61
  ...this["~orpc"],
86
62
  route: mergeRoute(this["~orpc"].route, route)
87
63
  });
88
64
  }
89
65
  use(middleware, mapInput) {
90
66
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
91
- return new _DecoratedProcedure({
67
+ return new DecoratedProcedure({
92
68
  ...this["~orpc"],
93
69
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
94
70
  });
@@ -108,10 +84,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
108
84
  actionable(...rest) {
109
85
  return this.callable(...rest);
110
86
  }
111
- };
87
+ }
112
88
 
113
- // src/builder.ts
114
- var Builder = class _Builder {
89
+ class Builder {
115
90
  "~orpc";
116
91
  constructor(def) {
117
92
  this["~orpc"] = def;
@@ -122,7 +97,7 @@ var Builder = class _Builder {
122
97
  $config(config) {
123
98
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
124
99
  const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
125
- return new _Builder({
100
+ return new Builder({
126
101
  ...this["~orpc"],
127
102
  config,
128
103
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
@@ -133,7 +108,7 @@ var Builder = class _Builder {
133
108
  * Reset initial context
134
109
  */
135
110
  $context() {
136
- return new _Builder({
111
+ return new Builder({
137
112
  ...this["~orpc"],
138
113
  middlewares: [],
139
114
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
@@ -144,7 +119,7 @@ var Builder = class _Builder {
144
119
  * Reset initial meta
145
120
  */
146
121
  $meta(initialMeta) {
147
- return new _Builder({
122
+ return new Builder({
148
123
  ...this["~orpc"],
149
124
  meta: initialMeta
150
125
  });
@@ -153,7 +128,7 @@ var Builder = class _Builder {
153
128
  * Reset initial route
154
129
  */
155
130
  $route(initialRoute) {
156
- return new _Builder({
131
+ return new Builder({
157
132
  ...this["~orpc"],
158
133
  route: initialRoute
159
134
  });
@@ -162,39 +137,39 @@ var Builder = class _Builder {
162
137
  return decorateMiddleware(middleware);
163
138
  }
164
139
  errors(errors) {
165
- return new _Builder({
140
+ return new Builder({
166
141
  ...this["~orpc"],
167
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
142
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
168
143
  });
169
144
  }
170
145
  use(middleware, mapInput) {
171
146
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
172
- return new _Builder({
147
+ return new Builder({
173
148
  ...this["~orpc"],
174
149
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
175
150
  });
176
151
  }
177
152
  meta(meta) {
178
- return new _Builder({
153
+ return new Builder({
179
154
  ...this["~orpc"],
180
- meta: mergeMeta2(this["~orpc"].meta, meta)
155
+ meta: mergeMeta(this["~orpc"].meta, meta)
181
156
  });
182
157
  }
183
158
  route(route) {
184
- return new _Builder({
159
+ return new Builder({
185
160
  ...this["~orpc"],
186
- route: mergeRoute2(this["~orpc"].route, route)
161
+ route: mergeRoute(this["~orpc"].route, route)
187
162
  });
188
163
  }
189
164
  input(schema) {
190
- return new _Builder({
165
+ return new Builder({
191
166
  ...this["~orpc"],
192
167
  inputSchema: schema,
193
168
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
194
169
  });
195
170
  }
196
171
  output(schema) {
197
- return new _Builder({
172
+ return new Builder({
198
173
  ...this["~orpc"],
199
174
  outputSchema: schema,
200
175
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
@@ -207,25 +182,25 @@ var Builder = class _Builder {
207
182
  });
208
183
  }
209
184
  prefix(prefix) {
210
- return new _Builder({
185
+ return new Builder({
211
186
  ...this["~orpc"],
212
187
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
213
188
  });
214
189
  }
215
190
  tag(...tags) {
216
- return new _Builder({
191
+ return new Builder({
217
192
  ...this["~orpc"],
218
193
  tags: mergeTags(this["~orpc"].tags, tags)
219
194
  });
220
195
  }
221
196
  router(router) {
222
- return adaptRouter(router, this["~orpc"]);
197
+ return enhanceRouter(router, this["~orpc"]);
223
198
  }
224
199
  lazy(loader) {
225
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
200
+ return enhanceRouter(lazy(loader), this["~orpc"]);
226
201
  }
227
- };
228
- var os = new Builder({
202
+ }
203
+ const os = new Builder({
229
204
  config: {},
230
205
  route: {},
231
206
  meta: {},
@@ -237,13 +212,10 @@ var os = new Builder({
237
212
  middlewares: []
238
213
  });
239
214
 
240
- // src/context.ts
241
215
  function mergeContext(context, other) {
242
216
  return { ...context, ...other };
243
217
  }
244
218
 
245
- // src/implementer.ts
246
- import { isContractProcedure } from "@orpc/contract";
247
219
  function implementerInternal(contract, config, middlewares) {
248
220
  if (isContractProcedure(contract)) {
249
221
  const impl2 = new Builder({
@@ -257,6 +229,9 @@ function implementerInternal(contract, config, middlewares) {
257
229
  }
258
230
  const impl = new Proxy(contract, {
259
231
  get: (target, key) => {
232
+ if (typeof key !== "string") {
233
+ return Reflect.get(target, key);
234
+ }
260
235
  let method;
261
236
  if (key === "middleware") {
262
237
  method = (mid) => decorateMiddleware(mid);
@@ -270,23 +245,27 @@ function implementerInternal(contract, config, middlewares) {
270
245
  };
271
246
  } else if (key === "router") {
272
247
  method = (router) => {
273
- const adapted = adaptRouter(router, {
248
+ const adapted = enhanceRouter(router, {
274
249
  middlewares,
275
- errorMap: {}
250
+ errorMap: {},
251
+ prefix: void 0,
252
+ tags: void 0
276
253
  });
277
- return setRouterContract(adapted, contract);
254
+ return setHiddenRouterContract(adapted, contract);
278
255
  };
279
256
  } else if (key === "lazy") {
280
257
  method = (loader) => {
281
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
258
+ const adapted = enhanceRouter(lazy(loader), {
282
259
  middlewares,
283
- errorMap: {}
260
+ errorMap: {},
261
+ prefix: void 0,
262
+ tags: void 0
284
263
  });
285
- return setRouterContract(adapted, contract);
264
+ return setHiddenRouterContract(adapted, contract);
286
265
  };
287
266
  }
288
- const next = Reflect.get(target, key);
289
- if (!next || typeof next !== "function" && typeof next !== "object") {
267
+ const next = getContractRouter(target, [key]);
268
+ if (!next) {
290
269
  return method ?? next;
291
270
  }
292
271
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -329,28 +308,21 @@ function implement(contract, config = {}) {
329
308
  return impl;
330
309
  }
331
310
 
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) {
311
+ function createRouterClient(router, ...[options]) {
339
312
  if (isProcedure(router)) {
340
- const caller = createProcedureClient(router, ...rest);
313
+ const caller = createProcedureClient(router, options);
341
314
  return caller;
342
315
  }
343
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
316
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
344
317
  const recursive = new Proxy(procedureCaller, {
345
318
  get(target, key) {
346
319
  if (typeof key !== "string") {
347
320
  return Reflect.get(target, key);
348
321
  }
349
- const next = getRouterChild(router, key);
322
+ const next = getRouter(router, [key]);
350
323
  if (!next) {
351
324
  return Reflect.get(target, key);
352
325
  }
353
- const [options] = rest;
354
326
  return createRouterClient(next, {
355
327
  ...options,
356
328
  path: [...options?.path ?? [], key]
@@ -360,54 +332,4 @@ function createRouterClient(router, ...rest) {
360
332
  return recursive;
361
333
  }
362
334
 
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
335
+ 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.rcYTv2pz.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.rcYTv2pz.mjs';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.C99bm-AA.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 | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: string[];
13
+ allowHeaders?: string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: Partial<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.SegZfF38.js';
2
+ export { C as CompositePlugin } from '../shared/server.SegZfF38.js';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.C99bm-AA.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 | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: string[];
13
+ allowHeaders?: string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: Partial<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,23 +1,7 @@
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
6
  constructor(options) {
23
7
  const defaults = {
@@ -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 };
@@ -1,32 +1,21 @@
1
- import {
2
- convertPathToHttpPath,
3
- createContractedProcedure,
4
- createProcedureClient,
5
- eachContractProcedure,
6
- getRouterChild,
7
- isProcedure,
8
- unlazy
9
- } from "./chunk-MHVECKBC.js";
10
- import {
11
- CompositePlugin
12
- } from "./chunk-XI6WGCB3.js";
1
+ import { ORPCError, toORPCError } from '@orpc/client';
2
+ import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
3
+ import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
4
+ import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BFBhsdJr.mjs';
13
5
 
14
- // src/adapters/standard/handler.ts
15
- import { ORPCError, toORPCError } from "@orpc/client";
16
- import { intercept, trim } from "@orpc/shared";
17
- var StandardHandler = class {
18
- constructor(router, matcher, codec, options = {}) {
6
+ class StandardHandler {
7
+ constructor(router, matcher, codec, options) {
19
8
  this.matcher = matcher;
20
9
  this.codec = codec;
21
10
  this.options = options;
22
- this.plugin = new CompositePlugin(options?.plugins);
11
+ this.plugin = new CompositePlugin(options.plugins);
23
12
  this.plugin.init(this.options);
24
13
  this.matcher.init(router);
25
14
  }
26
15
  plugin;
27
16
  handle(request, ...[options]) {
28
17
  return intercept(
29
- this.options.interceptorsRoot ?? [],
18
+ this.options.rootInterceptors ?? [],
30
19
  {
31
20
  request,
32
21
  ...options,
@@ -47,12 +36,11 @@ var StandardHandler = class {
47
36
  if (!match) {
48
37
  return { matched: false, response: void 0 };
49
38
  }
50
- const clientOptions = {
39
+ const client = createProcedureClient(match.procedure, {
51
40
  context: interceptorOptions2.context,
52
- path: match.path
53
- };
54
- this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
55
- const client = createProcedureClient(match.procedure, clientOptions);
41
+ path: match.path,
42
+ interceptors: this.options.clientInterceptors
43
+ });
56
44
  isDecoding = true;
57
45
  const input = await this.codec.decode(request, match.params, match.procedure);
58
46
  isDecoding = false;
@@ -79,17 +67,14 @@ var StandardHandler = class {
79
67
  }
80
68
  );
81
69
  }
82
- };
70
+ }
83
71
 
84
- // src/adapters/standard/rpc-codec.ts
85
- import { RPCSerializer } from "@orpc/client/rpc";
86
- var RPCCodec = class {
87
- serializer;
88
- constructor(options = {}) {
89
- this.serializer = options.serializer ?? new RPCSerializer();
72
+ class RPCCodec {
73
+ constructor(serializer) {
74
+ this.serializer = serializer;
90
75
  }
91
76
  async decode(request, _params, _procedure) {
92
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
77
+ const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
93
78
  return this.serializer.deserialize(serialized);
94
79
  }
95
80
  encode(output, _procedure) {
@@ -106,18 +91,14 @@ var RPCCodec = class {
106
91
  body: this.serializer.serialize(error.toJSON())
107
92
  };
108
93
  }
109
- };
94
+ }
110
95
 
111
- // src/adapters/standard/rpc-matcher.ts
112
- var RPCMatcher = class {
96
+ class RPCMatcher {
113
97
  tree = {};
114
98
  pendingRouters = [];
115
99
  init(router, path = []) {
116
- const laziedOptions = eachContractProcedure({
117
- router,
118
- path
119
- }, ({ path: path2, contract }) => {
120
- const httpPath = convertPathToHttpPath(path2);
100
+ const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
101
+ const httpPath = toHttpPath(path2);
121
102
  if (isProcedure(contract)) {
122
103
  this.tree[httpPath] = {
123
104
  path: path2,
@@ -137,7 +118,7 @@ var RPCMatcher = class {
137
118
  });
138
119
  this.pendingRouters.push(...laziedOptions.map((option) => ({
139
120
  ...option,
140
- httpPathPrefix: convertPathToHttpPath(option.path)
121
+ httpPathPrefix: toHttpPath(option.path)
141
122
  })));
142
123
  }
143
124
  async match(_method, pathname) {
@@ -145,7 +126,7 @@ var RPCMatcher = class {
145
126
  const newPendingRouters = [];
146
127
  for (const pendingRouter of this.pendingRouters) {
147
128
  if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
148
- const { default: router } = await unlazy(pendingRouter.lazied);
129
+ const { default: router } = await unlazy(pendingRouter.router);
149
130
  this.init(router, pendingRouter.path);
150
131
  } else {
151
132
  newPendingRouters.push(pendingRouter);
@@ -158,25 +139,20 @@ var RPCMatcher = class {
158
139
  return void 0;
159
140
  }
160
141
  if (!match.procedure) {
161
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
142
+ const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
162
143
  if (!isProcedure(maybeProcedure)) {
163
144
  throw new Error(`
164
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
145
+ [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
165
146
  Ensure that the procedure is correctly defined and matches the expected contract.
166
147
  `);
167
148
  }
168
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
149
+ match.procedure = createContractedProcedure(maybeProcedure, match.contract);
169
150
  }
170
151
  return {
171
152
  path: match.path,
172
153
  procedure: match.procedure
173
154
  };
174
155
  }
175
- };
156
+ }
176
157
 
177
- export {
178
- StandardHandler,
179
- RPCCodec,
180
- RPCMatcher
181
- };
182
- //# sourceMappingURL=chunk-LXOL226G.js.map
158
+ export { RPCCodec as R, StandardHandler as S, RPCMatcher as a };