@orpc/server 0.0.0-next.cba521d → 0.0.0-next.cc8802c

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 (75) 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/adapters/hono/index.mjs +32 -0
  8. package/dist/adapters/next/index.d.mts +26 -0
  9. package/dist/adapters/next/index.d.ts +26 -0
  10. package/dist/adapters/next/index.mjs +29 -0
  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.mjs +343 -0
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/plugins/index.mjs +103 -0
  23. package/dist/shared/server.CM3tWr3C.d.mts +75 -0
  24. package/dist/shared/server.CMrS28Go.mjs +346 -0
  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 +36 -24
  32. package/dist/chunk-3EVCPLVI.js +0 -301
  33. package/dist/chunk-OUPZ7QGV.js +0 -245
  34. package/dist/chunk-WUOGVGWG.js +0 -1
  35. package/dist/fetch.js +0 -15
  36. package/dist/hono.js +0 -30
  37. package/dist/index.js +0 -562
  38. package/dist/next.js +0 -36
  39. package/dist/node.js +0 -87
  40. package/dist/src/adapters/fetch/index.d.ts +0 -6
  41. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  42. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  43. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  44. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  45. package/dist/src/adapters/fetch/types.d.ts +0 -21
  46. package/dist/src/adapters/hono/index.d.ts +0 -3
  47. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  48. package/dist/src/adapters/next/index.d.ts +0 -3
  49. package/dist/src/adapters/next/serve.d.ts +0 -19
  50. package/dist/src/adapters/node/index.d.ts +0 -5
  51. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  52. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  53. package/dist/src/adapters/node/types.d.ts +0 -22
  54. package/dist/src/builder.d.ts +0 -36
  55. package/dist/src/error.d.ts +0 -10
  56. package/dist/src/hidden.d.ts +0 -6
  57. package/dist/src/implementer-chainable.d.ts +0 -10
  58. package/dist/src/index.d.ts +0 -25
  59. package/dist/src/lazy-decorated.d.ts +0 -7
  60. package/dist/src/lazy-utils.d.ts +0 -4
  61. package/dist/src/lazy.d.ts +0 -18
  62. package/dist/src/middleware-decorated.d.ts +0 -9
  63. package/dist/src/middleware.d.ts +0 -36
  64. package/dist/src/procedure-builder.d.ts +0 -24
  65. package/dist/src/procedure-client.d.ts +0 -22
  66. package/dist/src/procedure-decorated.d.ts +0 -26
  67. package/dist/src/procedure-implementer.d.ts +0 -20
  68. package/dist/src/procedure-utils.d.ts +0 -17
  69. package/dist/src/procedure.d.ts +0 -44
  70. package/dist/src/router-builder.d.ts +0 -29
  71. package/dist/src/router-client.d.ts +0 -26
  72. package/dist/src/router-implementer.d.ts +0 -21
  73. package/dist/src/router.d.ts +0 -16
  74. package/dist/src/types.d.ts +0 -14
  75. package/dist/src/utils.d.ts +0 -3
package/dist/index.mjs ADDED
@@ -0,0 +1,343 @@
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';
8
+
9
+ const DEFAULT_CONFIG = {
10
+ initialInputValidationIndex: 0,
11
+ initialOutputValidationIndex: 0
12
+ };
13
+ function fallbackConfig(key, value) {
14
+ if (value === void 0) {
15
+ return DEFAULT_CONFIG[key];
16
+ }
17
+ return value;
18
+ }
19
+
20
+ function decorateMiddleware(middleware) {
21
+ const decorated = (...args) => middleware(...args);
22
+ decorated.mapInput = (mapInput) => {
23
+ const mapped = decorateMiddleware(
24
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
25
+ );
26
+ return mapped;
27
+ };
28
+ decorated.concat = (concatMiddleware, mapInput) => {
29
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
30
+ const concatted = decorateMiddleware((options, 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);
39
+ return merged;
40
+ });
41
+ return concatted;
42
+ };
43
+ return decorated;
44
+ }
45
+
46
+ class DecoratedProcedure extends Procedure {
47
+ errors(errors) {
48
+ return new DecoratedProcedure({
49
+ ...this["~orpc"],
50
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
51
+ });
52
+ }
53
+ meta(meta) {
54
+ return new DecoratedProcedure({
55
+ ...this["~orpc"],
56
+ meta: mergeMeta(this["~orpc"].meta, meta)
57
+ });
58
+ }
59
+ route(route) {
60
+ return new DecoratedProcedure({
61
+ ...this["~orpc"],
62
+ route: mergeRoute(this["~orpc"].route, route)
63
+ });
64
+ }
65
+ use(middleware, mapInput) {
66
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
67
+ return new DecoratedProcedure({
68
+ ...this["~orpc"],
69
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
70
+ });
71
+ }
72
+ /**
73
+ * Make this procedure callable (works like a function while still being a procedure).
74
+ */
75
+ callable(...rest) {
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
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
87
+ */
88
+ actionable(...rest) {
89
+ return this.callable(...rest);
90
+ }
91
+ }
92
+
93
+ class Builder {
94
+ "~orpc";
95
+ constructor(def) {
96
+ this["~orpc"] = def;
97
+ }
98
+ /**
99
+ * Reset config
100
+ */
101
+ $config(config) {
102
+ const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
103
+ const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
104
+ return new Builder({
105
+ ...this["~orpc"],
106
+ config,
107
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
108
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
109
+ });
110
+ }
111
+ /**
112
+ * Reset initial context
113
+ */
114
+ $context() {
115
+ return new Builder({
116
+ ...this["~orpc"],
117
+ middlewares: [],
118
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
119
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
120
+ });
121
+ }
122
+ /**
123
+ * Reset initial meta
124
+ */
125
+ $meta(initialMeta) {
126
+ return new Builder({
127
+ ...this["~orpc"],
128
+ meta: initialMeta
129
+ });
130
+ }
131
+ /**
132
+ * Reset initial route
133
+ */
134
+ $route(initialRoute) {
135
+ return new Builder({
136
+ ...this["~orpc"],
137
+ route: initialRoute
138
+ });
139
+ }
140
+ $input(initialInputSchema) {
141
+ return new Builder({
142
+ ...this["~orpc"],
143
+ inputSchema: initialInputSchema
144
+ });
145
+ }
146
+ middleware(middleware) {
147
+ return decorateMiddleware(middleware);
148
+ }
149
+ errors(errors) {
150
+ return new Builder({
151
+ ...this["~orpc"],
152
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
153
+ });
154
+ }
155
+ use(middleware, mapInput) {
156
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
157
+ return new Builder({
158
+ ...this["~orpc"],
159
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
160
+ });
161
+ }
162
+ meta(meta) {
163
+ return new Builder({
164
+ ...this["~orpc"],
165
+ meta: mergeMeta(this["~orpc"].meta, meta)
166
+ });
167
+ }
168
+ route(route) {
169
+ return new Builder({
170
+ ...this["~orpc"],
171
+ route: mergeRoute(this["~orpc"].route, route)
172
+ });
173
+ }
174
+ input(schema) {
175
+ return new Builder({
176
+ ...this["~orpc"],
177
+ inputSchema: schema,
178
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
179
+ });
180
+ }
181
+ output(schema) {
182
+ return new Builder({
183
+ ...this["~orpc"],
184
+ outputSchema: schema,
185
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
186
+ });
187
+ }
188
+ handler(handler) {
189
+ return new DecoratedProcedure({
190
+ ...this["~orpc"],
191
+ handler
192
+ });
193
+ }
194
+ prefix(prefix) {
195
+ return new Builder({
196
+ ...this["~orpc"],
197
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
198
+ });
199
+ }
200
+ tag(...tags) {
201
+ return new Builder({
202
+ ...this["~orpc"],
203
+ tags: mergeTags(this["~orpc"].tags, tags)
204
+ });
205
+ }
206
+ router(router) {
207
+ return enhanceRouter(router, this["~orpc"]);
208
+ }
209
+ lazy(loader) {
210
+ return enhanceRouter(lazy(loader), this["~orpc"]);
211
+ }
212
+ }
213
+ const os = new Builder({
214
+ config: {},
215
+ route: {},
216
+ meta: {},
217
+ errorMap: {},
218
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
219
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
220
+ middlewares: []
221
+ });
222
+
223
+ function mergeContext(context, other) {
224
+ return { ...context, ...other };
225
+ }
226
+
227
+ function implementerInternal(contract, config, middlewares) {
228
+ if (isContractProcedure(contract)) {
229
+ const impl2 = new Builder({
230
+ ...contract["~orpc"],
231
+ config,
232
+ middlewares,
233
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
234
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
235
+ });
236
+ return impl2;
237
+ }
238
+ const impl = new Proxy(contract, {
239
+ get: (target, key) => {
240
+ if (typeof key !== "string") {
241
+ return Reflect.get(target, key);
242
+ }
243
+ let method;
244
+ if (key === "middleware") {
245
+ method = (mid) => decorateMiddleware(mid);
246
+ } else if (key === "use") {
247
+ method = (mid) => {
248
+ return implementerInternal(
249
+ contract,
250
+ config,
251
+ addMiddleware(middlewares, mid)
252
+ );
253
+ };
254
+ } else if (key === "router") {
255
+ method = (router) => {
256
+ const adapted = enhanceRouter(router, {
257
+ middlewares,
258
+ errorMap: {},
259
+ prefix: void 0,
260
+ tags: void 0
261
+ });
262
+ return setHiddenRouterContract(adapted, contract);
263
+ };
264
+ } else if (key === "lazy") {
265
+ method = (loader) => {
266
+ const adapted = enhanceRouter(lazy(loader), {
267
+ middlewares,
268
+ errorMap: {},
269
+ prefix: void 0,
270
+ tags: void 0
271
+ });
272
+ return setHiddenRouterContract(adapted, contract);
273
+ };
274
+ }
275
+ const next = getContractRouter(target, [key]);
276
+ if (!next) {
277
+ return method ?? next;
278
+ }
279
+ const nextImpl = implementerInternal(next, config, middlewares);
280
+ if (method) {
281
+ return new Proxy(method, {
282
+ get(_, key2) {
283
+ return Reflect.get(nextImpl, key2);
284
+ }
285
+ });
286
+ }
287
+ return nextImpl;
288
+ }
289
+ });
290
+ return impl;
291
+ }
292
+ function implement(contract, config = {}) {
293
+ const implInternal = implementerInternal(contract, config, []);
294
+ const impl = new Proxy(implInternal, {
295
+ get: (target, key) => {
296
+ let method;
297
+ if (key === "$context") {
298
+ method = () => impl;
299
+ } else if (key === "$config") {
300
+ method = (config2) => implement(contract, config2);
301
+ }
302
+ const next = Reflect.get(target, key);
303
+ if (!next || typeof next !== "function" && typeof next !== "object") {
304
+ return method ?? next;
305
+ }
306
+ if (method) {
307
+ return new Proxy(method, {
308
+ get(_, key2) {
309
+ return Reflect.get(next, key2);
310
+ }
311
+ });
312
+ }
313
+ return next;
314
+ }
315
+ });
316
+ return impl;
317
+ }
318
+
319
+ function createRouterClient(router, ...[options]) {
320
+ if (isProcedure(router)) {
321
+ const caller = createProcedureClient(router, options);
322
+ return caller;
323
+ }
324
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
325
+ const recursive = new Proxy(procedureCaller, {
326
+ get(target, key) {
327
+ if (typeof key !== "string") {
328
+ return Reflect.get(target, key);
329
+ }
330
+ const next = getRouter(router, [key]);
331
+ if (!next) {
332
+ return Reflect.get(target, key);
333
+ }
334
+ return createRouterClient(next, {
335
+ ...options,
336
+ path: [...options?.path ?? [], key]
337
+ });
338
+ }
339
+ });
340
+ return recursive;
341
+ }
342
+
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 };
@@ -0,0 +1,103 @@
1
+ export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
2
+ import { value } from '@orpc/shared';
3
+
4
+ class CORSPlugin {
5
+ options;
6
+ constructor(options = {}) {
7
+ const defaults = {
8
+ origin: (origin) => origin,
9
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
10
+ };
11
+ this.options = {
12
+ ...defaults,
13
+ ...options
14
+ };
15
+ }
16
+ init(options) {
17
+ options.rootInterceptors ??= [];
18
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
19
+ if (interceptorOptions.request.method === "OPTIONS") {
20
+ const resHeaders = {};
21
+ if (this.options.maxAge !== void 0) {
22
+ resHeaders["access-control-max-age"] = this.options.maxAge.toString();
23
+ }
24
+ if (this.options.allowMethods?.length) {
25
+ resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
26
+ }
27
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
28
+ if (Array.isArray(allowHeaders) && allowHeaders.length) {
29
+ resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
30
+ } else if (typeof allowHeaders === "string") {
31
+ resHeaders["access-control-allow-headers"] = allowHeaders;
32
+ }
33
+ return {
34
+ matched: true,
35
+ response: {
36
+ status: 204,
37
+ headers: resHeaders,
38
+ body: void 0
39
+ }
40
+ };
41
+ }
42
+ return interceptorOptions.next();
43
+ });
44
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
45
+ const result = await interceptorOptions.next();
46
+ if (!result.matched) {
47
+ return result;
48
+ }
49
+ const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
50
+ const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
51
+ const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
52
+ if (allowedOriginArr.includes("*")) {
53
+ result.response.headers["access-control-allow-origin"] = "*";
54
+ } else {
55
+ if (allowedOriginArr.includes(origin)) {
56
+ result.response.headers["access-control-allow-origin"] = origin;
57
+ }
58
+ result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
59
+ }
60
+ const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
61
+ const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
62
+ if (allowedTimingOriginArr.includes("*")) {
63
+ result.response.headers["timing-allow-origin"] = "*";
64
+ } else if (allowedTimingOriginArr.includes(origin)) {
65
+ result.response.headers["timing-allow-origin"] = origin;
66
+ }
67
+ if (this.options.credentials) {
68
+ result.response.headers["access-control-allow-credentials"] = "true";
69
+ }
70
+ if (this.options.exposeHeaders?.length) {
71
+ result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
72
+ }
73
+ return result;
74
+ });
75
+ }
76
+ }
77
+
78
+ class ResponseHeadersPlugin {
79
+ init(options) {
80
+ options.rootInterceptors ??= [];
81
+ options.rootInterceptors.push(async (interceptorOptions) => {
82
+ const headers = new Headers();
83
+ interceptorOptions.context.resHeaders = headers;
84
+ const result = await interceptorOptions.next();
85
+ if (!result.matched) {
86
+ return result;
87
+ }
88
+ const responseHeaders = result.response.headers;
89
+ for (const [key, value] of headers) {
90
+ if (Array.isArray(responseHeaders[key])) {
91
+ responseHeaders[key].push(value);
92
+ } else if (responseHeaders[key] !== void 0) {
93
+ responseHeaders[key] = [responseHeaders[key], value];
94
+ } else {
95
+ responseHeaders[key] = value;
96
+ }
97
+ }
98
+ return result;
99
+ });
100
+ }
101
+ }
102
+
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 };