@orpc/server 0.0.0-next.6affcc9 → 0.0.0-next.6c5bfe4

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 +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 +269 -0
  18. package/dist/index.d.ts +269 -0
  19. package/dist/{index.js → index.mjs} +60 -133
  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/shared/server.BZRSVRDu.d.ts +77 -0
  24. package/dist/shared/server.CPteJIPP.d.mts +143 -0
  25. package/dist/shared/server.CPteJIPP.d.ts +143 -0
  26. package/dist/shared/server.CXu_v2vM.mjs +28 -0
  27. package/dist/shared/server.N2ttmv6r.mjs +158 -0
  28. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  29. package/dist/shared/server.iM8li30u.d.mts +77 -0
  30. package/dist/{chunk-XXBE6CYD.js → shared/server.kPUGzsdw.mjs} +171 -193
  31. package/package.json +29 -33
  32. package/dist/chunk-L4ESXQX7.js +0 -32
  33. package/dist/chunk-NXEANHUK.js +0 -351
  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 -22
  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 -8
  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 -24
  63. package/dist/src/lazy-utils.d.ts +0 -6
  64. package/dist/src/lazy.d.ts +0 -22
  65. package/dist/src/middleware-decorated.d.ts +0 -10
  66. package/dist/src/middleware-utils.d.ts +0 -5
  67. package/dist/src/middleware.d.ts +0 -37
  68. package/dist/src/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 -31
  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 -30
  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-XXBE6CYD.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.kPUGzsdw.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.kPUGzsdw.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,48 +128,54 @@ 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
  });
160
135
  }
136
+ $input(initialInputSchema) {
137
+ return new Builder({
138
+ ...this["~orpc"],
139
+ inputSchema: initialInputSchema
140
+ });
141
+ }
161
142
  middleware(middleware) {
162
143
  return decorateMiddleware(middleware);
163
144
  }
164
145
  errors(errors) {
165
- return new _Builder({
146
+ return new Builder({
166
147
  ...this["~orpc"],
167
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
148
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
168
149
  });
169
150
  }
170
151
  use(middleware, mapInput) {
171
152
  const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
172
- return new _Builder({
153
+ return new Builder({
173
154
  ...this["~orpc"],
174
155
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
175
156
  });
176
157
  }
177
158
  meta(meta) {
178
- return new _Builder({
159
+ return new Builder({
179
160
  ...this["~orpc"],
180
- meta: mergeMeta2(this["~orpc"].meta, meta)
161
+ meta: mergeMeta(this["~orpc"].meta, meta)
181
162
  });
182
163
  }
183
164
  route(route) {
184
- return new _Builder({
165
+ return new Builder({
185
166
  ...this["~orpc"],
186
- route: mergeRoute2(this["~orpc"].route, route)
167
+ route: mergeRoute(this["~orpc"].route, route)
187
168
  });
188
169
  }
189
170
  input(schema) {
190
- return new _Builder({
171
+ return new Builder({
191
172
  ...this["~orpc"],
192
173
  inputSchema: schema,
193
174
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
194
175
  });
195
176
  }
196
177
  output(schema) {
197
- return new _Builder({
178
+ return new Builder({
198
179
  ...this["~orpc"],
199
180
  outputSchema: schema,
200
181
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
@@ -207,43 +188,38 @@ var Builder = class _Builder {
207
188
  });
208
189
  }
209
190
  prefix(prefix) {
210
- return new _Builder({
191
+ return new Builder({
211
192
  ...this["~orpc"],
212
193
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
213
194
  });
214
195
  }
215
196
  tag(...tags) {
216
- return new _Builder({
197
+ return new Builder({
217
198
  ...this["~orpc"],
218
199
  tags: mergeTags(this["~orpc"].tags, tags)
219
200
  });
220
201
  }
221
202
  router(router) {
222
- return adaptRouter(router, this["~orpc"]);
203
+ return enhanceRouter(router, this["~orpc"]);
223
204
  }
224
205
  lazy(loader) {
225
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
206
+ return enhanceRouter(lazy(loader), this["~orpc"]);
226
207
  }
227
- };
228
- var os = new Builder({
208
+ }
209
+ const os = new Builder({
229
210
  config: {},
230
211
  route: {},
231
212
  meta: {},
232
213
  errorMap: {},
233
- inputSchema: void 0,
234
- outputSchema: void 0,
235
214
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
236
215
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
237
216
  middlewares: []
238
217
  });
239
218
 
240
- // src/context.ts
241
219
  function mergeContext(context, other) {
242
220
  return { ...context, ...other };
243
221
  }
244
222
 
245
- // src/implementer.ts
246
- import { isContractProcedure } from "@orpc/contract";
247
223
  function implementerInternal(contract, config, middlewares) {
248
224
  if (isContractProcedure(contract)) {
249
225
  const impl2 = new Builder({
@@ -257,6 +233,9 @@ function implementerInternal(contract, config, middlewares) {
257
233
  }
258
234
  const impl = new Proxy(contract, {
259
235
  get: (target, key) => {
236
+ if (typeof key !== "string") {
237
+ return Reflect.get(target, key);
238
+ }
260
239
  let method;
261
240
  if (key === "middleware") {
262
241
  method = (mid) => decorateMiddleware(mid);
@@ -270,23 +249,27 @@ function implementerInternal(contract, config, middlewares) {
270
249
  };
271
250
  } else if (key === "router") {
272
251
  method = (router) => {
273
- const adapted = adaptRouter(router, {
252
+ const adapted = enhanceRouter(router, {
274
253
  middlewares,
275
- errorMap: {}
254
+ errorMap: {},
255
+ prefix: void 0,
256
+ tags: void 0
276
257
  });
277
- return setRouterContract(adapted, contract);
258
+ return setHiddenRouterContract(adapted, contract);
278
259
  };
279
260
  } else if (key === "lazy") {
280
261
  method = (loader) => {
281
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
262
+ const adapted = enhanceRouter(lazy(loader), {
282
263
  middlewares,
283
- errorMap: {}
264
+ errorMap: {},
265
+ prefix: void 0,
266
+ tags: void 0
284
267
  });
285
- return setRouterContract(adapted, contract);
268
+ return setHiddenRouterContract(adapted, contract);
286
269
  };
287
270
  }
288
- const next = Reflect.get(target, key);
289
- if (!next || typeof next !== "function" && typeof next !== "object") {
271
+ const next = getContractRouter(target, [key]);
272
+ if (!next) {
290
273
  return method ?? next;
291
274
  }
292
275
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -329,28 +312,21 @@ function implement(contract, config = {}) {
329
312
  return impl;
330
313
  }
331
314
 
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) {
315
+ function createRouterClient(router, ...[options]) {
339
316
  if (isProcedure(router)) {
340
- const caller = createProcedureClient(router, ...rest);
317
+ const caller = createProcedureClient(router, options);
341
318
  return caller;
342
319
  }
343
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
320
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
344
321
  const recursive = new Proxy(procedureCaller, {
345
322
  get(target, key) {
346
323
  if (typeof key !== "string") {
347
324
  return Reflect.get(target, key);
348
325
  }
349
- const next = getRouterChild(router, key);
326
+ const next = getRouter(router, [key]);
350
327
  if (!next) {
351
328
  return Reflect.get(target, key);
352
329
  }
353
- const [options] = rest;
354
330
  return createRouterClient(next, {
355
331
  ...options,
356
332
  path: [...options?.path ?? [], key]
@@ -360,53 +336,4 @@ function createRouterClient(router, ...rest) {
360
336
  return recursive;
361
337
  }
362
338
 
363
- // src/index.ts
364
- import { eventIterator, isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
365
- import { getEventMeta, withEventMeta } from "@orpc/server-standard";
366
- import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
367
- export {
368
- Builder,
369
- DecoratedProcedure,
370
- LAZY_LOADER_SYMBOL,
371
- ORPCError,
372
- Procedure,
373
- ValidationError,
374
- adaptRouter,
375
- call,
376
- convertPathToHttpPath,
377
- createAccessibleLazyRouter,
378
- createContractedProcedure,
379
- createLazyProcedureFormAnyLazy,
380
- createProcedureClient,
381
- createRouterClient,
382
- decorateMiddleware,
383
- deepSetLazyRouterPrefix,
384
- eachAllContractProcedure,
385
- eachContractProcedure,
386
- eventIterator,
387
- fallbackConfig,
388
- flatLazy,
389
- getEventMeta,
390
- getLazyRouterPrefix,
391
- getRouterChild,
392
- getRouterContract,
393
- implement,
394
- implementerInternal,
395
- isDefinedError,
396
- isLazy,
397
- isProcedure,
398
- lazy,
399
- mergeContext,
400
- middlewareOutputFn,
401
- onError,
402
- onFinish,
403
- onStart,
404
- onSuccess,
405
- os,
406
- safe,
407
- setRouterContract,
408
- type,
409
- unlazy,
410
- withEventMeta
411
- };
412
- //# sourceMappingURL=index.js.map
339
+ 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.iM8li30u.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.iM8li30u.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 | 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.BZRSVRDu.js';
2
+ export { C as CompositePlugin } from '../shared/server.BZRSVRDu.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 | 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 };
@@ -0,0 +1,77 @@
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.js';
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 WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
31
+ context: T;
32
+ };
33
+ type StandardHandleResult = {
34
+ matched: true;
35
+ response: StandardResponse;
36
+ } | {
37
+ matched: false;
38
+ response: undefined;
39
+ };
40
+ type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
41
+ request: StandardLazyRequest;
42
+ };
43
+ interface StandardHandlerOptions<TContext extends Context> {
44
+ plugins?: HandlerPlugin<TContext>[];
45
+ /**
46
+ * Interceptors at the request level, helpful when you want catch errors
47
+ */
48
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
49
+ /**
50
+ * Interceptors at the root level, helpful when you want override the request/response
51
+ */
52
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
53
+ /**
54
+ *
55
+ * Interceptors for procedure client.
56
+ */
57
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
58
+ }
59
+ declare class StandardHandler<T extends Context> {
60
+ private readonly matcher;
61
+ private readonly codec;
62
+ private readonly options;
63
+ private readonly plugin;
64
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
65
+ handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
66
+ }
67
+
68
+ interface HandlerPlugin<TContext extends Context> {
69
+ init?(options: StandardHandlerOptions<TContext>): void;
70
+ }
71
+ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
72
+ private readonly plugins;
73
+ constructor(plugins?: HandlerPlugin<TContext>[]);
74
+ init(options: StandardHandlerOptions<TContext>): void;
75
+ }
76
+
77
+ export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type WellStandardHandleOptions as W, 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 };