@orpc/server 0.0.0-next.bc564a6 → 0.0.0-next.bf323bf

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 (51) hide show
  1. package/dist/chunk-6TBBWYQ3.js +351 -0
  2. package/dist/{chunk-KK4SDLC7.js → chunk-RDEUEBK3.js} +86 -27
  3. package/dist/chunk-SVWPMCP4.js +32 -0
  4. package/dist/chunk-XI6WGCB3.js +125 -0
  5. package/dist/fetch.js +6 -11
  6. package/dist/hono.js +17 -13
  7. package/dist/index.js +20 -3
  8. package/dist/next.js +5 -10
  9. package/dist/node.js +18 -74
  10. package/dist/plugins.js +11 -0
  11. package/dist/src/adapters/fetch/index.d.ts +1 -4
  12. package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
  13. package/dist/src/adapters/fetch/types.d.ts +3 -10
  14. package/dist/src/adapters/hono/middleware.d.ts +5 -5
  15. package/dist/src/adapters/next/serve.d.ts +5 -5
  16. package/dist/src/adapters/node/index.d.ts +1 -3
  17. package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
  18. package/dist/src/adapters/node/types.d.ts +14 -14
  19. package/dist/src/adapters/standard/handler.d.ts +51 -0
  20. package/dist/src/adapters/standard/index.d.ts +7 -0
  21. package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
  22. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  23. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  24. package/dist/src/adapters/standard/rpc-serializer.d.ts +22 -0
  25. package/dist/src/adapters/standard/types.d.ts +20 -0
  26. package/dist/src/implementer-procedure.d.ts +5 -4
  27. package/dist/src/implementer-variants.d.ts +6 -5
  28. package/dist/src/implementer.d.ts +7 -6
  29. package/dist/src/index.d.ts +4 -1
  30. package/dist/src/middleware.d.ts +4 -4
  31. package/dist/src/plugins/base.d.ts +13 -0
  32. package/dist/src/plugins/cors.d.ts +19 -0
  33. package/dist/src/plugins/index.d.ts +4 -0
  34. package/dist/src/plugins/response-headers.d.ts +10 -0
  35. package/dist/src/procedure-client.d.ts +19 -8
  36. package/dist/src/procedure-decorated.d.ts +5 -4
  37. package/dist/src/procedure-utils.d.ts +4 -3
  38. package/dist/src/procedure.d.ts +2 -1
  39. package/dist/src/router-client.d.ts +6 -17
  40. package/dist/src/router.d.ts +1 -0
  41. package/dist/src/utils.d.ts +24 -0
  42. package/dist/standard.js +17 -0
  43. package/package.json +19 -3
  44. package/dist/chunk-ESTRJAOX.js +0 -299
  45. package/dist/chunk-WUOGVGWG.js +0 -1
  46. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  47. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  48. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  49. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  50. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  51. package/dist/src/adapters/node/request-listener.d.ts +0 -28
@@ -0,0 +1,351 @@
1
+ import {
2
+ convertPathToHttpPath,
3
+ createContractedProcedure,
4
+ createProcedureClient,
5
+ eachContractProcedure,
6
+ getRouterChild,
7
+ isProcedure,
8
+ unlazy
9
+ } from "./chunk-RDEUEBK3.js";
10
+ import {
11
+ CompositePlugin
12
+ } from "./chunk-XI6WGCB3.js";
13
+
14
+ // src/adapters/standard/handler.ts
15
+ import { ORPCError, toORPCError } from "@orpc/contract";
16
+ import { intercept, trim } from "@orpc/shared";
17
+ var StandardHandler = class {
18
+ constructor(router, matcher, codec, options = {}) {
19
+ this.matcher = matcher;
20
+ this.codec = codec;
21
+ this.options = options;
22
+ this.plugin = new CompositePlugin(options?.plugins);
23
+ this.plugin.init(this.options);
24
+ this.matcher.init(router);
25
+ }
26
+ plugin;
27
+ handle(request, ...[options]) {
28
+ return intercept(
29
+ this.options.interceptorsRoot ?? [],
30
+ {
31
+ request,
32
+ ...options,
33
+ context: options?.context ?? {}
34
+ // context is optional only when all fields are optional so we can safely force it to have a context
35
+ },
36
+ async (interceptorOptions) => {
37
+ let isDecoding = false;
38
+ try {
39
+ return await intercept(
40
+ this.options.interceptors ?? [],
41
+ interceptorOptions,
42
+ async (interceptorOptions2) => {
43
+ const method = interceptorOptions2.request.method;
44
+ const url = interceptorOptions2.request.url;
45
+ const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
46
+ const match = await this.matcher.match(method, pathname);
47
+ if (!match) {
48
+ return { matched: false, response: void 0 };
49
+ }
50
+ const clientOptions = {
51
+ context: interceptorOptions2.context,
52
+ path: match.path
53
+ };
54
+ this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
55
+ const client = createProcedureClient(match.procedure, clientOptions);
56
+ isDecoding = true;
57
+ const input = await this.codec.decode(request, match.params, match.procedure);
58
+ isDecoding = false;
59
+ const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
60
+ const output = await client(input, { signal: request.signal, lastEventId });
61
+ const response = this.codec.encode(output, match.procedure);
62
+ return {
63
+ matched: true,
64
+ response
65
+ };
66
+ }
67
+ );
68
+ } catch (e) {
69
+ const error = isDecoding ? new ORPCError("BAD_REQUEST", {
70
+ message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
71
+ cause: e
72
+ }) : toORPCError(e);
73
+ const response = this.codec.encodeError(error);
74
+ return {
75
+ matched: true,
76
+ response
77
+ };
78
+ }
79
+ }
80
+ );
81
+ }
82
+ };
83
+
84
+ // src/adapters/standard/rpc-serializer.ts
85
+ import { mapEventIterator, ORPCError as ORPCError2, toORPCError as toORPCError2 } from "@orpc/contract";
86
+ import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
87
+ import { findDeepMatches, isObject, set } from "@orpc/shared";
88
+ var RPCSerializer = class {
89
+ serialize(data) {
90
+ if (isAsyncIteratorObject(data)) {
91
+ return mapEventIterator(data, {
92
+ value: async (value) => serializeRPCJson(value),
93
+ error: async (e) => {
94
+ if (e instanceof ErrorEvent) {
95
+ return new ErrorEvent({
96
+ data: serializeRPCJson(e.data),
97
+ cause: e
98
+ });
99
+ }
100
+ return new ErrorEvent({
101
+ data: serializeRPCJson(toORPCError2(e).toJSON()),
102
+ cause: e
103
+ });
104
+ }
105
+ });
106
+ }
107
+ const serializedJSON = serializeRPCJson(data);
108
+ const { maps, values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON.json);
109
+ if (blobs.length === 0) {
110
+ return serializedJSON;
111
+ }
112
+ const form = new FormData();
113
+ form.set("data", JSON.stringify(serializedJSON));
114
+ form.set("maps", JSON.stringify(maps));
115
+ for (const i in blobs) {
116
+ form.set(i, blobs[i]);
117
+ }
118
+ return form;
119
+ }
120
+ deserialize(serialized) {
121
+ if (isAsyncIteratorObject(serialized)) {
122
+ return mapEventIterator(serialized, {
123
+ value: async (value) => deserializeRPCJson(value),
124
+ error: async (e) => {
125
+ if (!(e instanceof ErrorEvent)) {
126
+ return e;
127
+ }
128
+ const deserialized = deserializeRPCJson(e.data);
129
+ if (ORPCError2.isValidJSON(deserialized)) {
130
+ return ORPCError2.fromJSON(deserialized, { cause: e });
131
+ }
132
+ return new ErrorEvent({
133
+ data: deserialized,
134
+ cause: e
135
+ });
136
+ }
137
+ });
138
+ }
139
+ if (!(serialized instanceof FormData)) {
140
+ return deserializeRPCJson(serialized);
141
+ }
142
+ const data = JSON.parse(serialized.get("data"));
143
+ const maps = JSON.parse(serialized.get("maps"));
144
+ for (const i in maps) {
145
+ data.json = set(data.json, maps[i], serialized.get(i));
146
+ }
147
+ return deserializeRPCJson(data);
148
+ }
149
+ };
150
+ function serializeRPCJson(value, segments = [], meta = []) {
151
+ if (typeof value === "bigint") {
152
+ meta.push(["bigint", segments]);
153
+ return { json: value.toString(), meta };
154
+ }
155
+ if (value instanceof Date) {
156
+ meta.push(["date", segments]);
157
+ const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
158
+ return { json: data, meta };
159
+ }
160
+ if (Number.isNaN(value)) {
161
+ meta.push(["nan", segments]);
162
+ return { json: "NaN", meta };
163
+ }
164
+ if (value instanceof RegExp) {
165
+ meta.push(["regexp", segments]);
166
+ return { json: value.toString(), meta };
167
+ }
168
+ if (value instanceof URL) {
169
+ meta.push(["url", segments]);
170
+ return { json: value.toString(), meta };
171
+ }
172
+ if (isObject(value)) {
173
+ const json = {};
174
+ for (const k in value) {
175
+ json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
176
+ }
177
+ return { json, meta };
178
+ }
179
+ if (Array.isArray(value)) {
180
+ const json = value.map((v, i) => {
181
+ if (v === void 0) {
182
+ meta.push(["undefined", [...segments, i]]);
183
+ return null;
184
+ }
185
+ return serializeRPCJson(v, [...segments, i], meta).json;
186
+ });
187
+ return { json, meta };
188
+ }
189
+ if (value instanceof Set) {
190
+ const result = serializeRPCJson(Array.from(value), segments, meta);
191
+ meta.push(["set", segments]);
192
+ return result;
193
+ }
194
+ if (value instanceof Map) {
195
+ const result = serializeRPCJson(Array.from(value.entries()), segments, meta);
196
+ meta.push(["map", segments]);
197
+ return result;
198
+ }
199
+ return { json: value, meta };
200
+ }
201
+ function deserializeRPCJson({
202
+ json,
203
+ meta
204
+ }) {
205
+ if (meta.length === 0) {
206
+ return json;
207
+ }
208
+ const ref = { data: json };
209
+ for (const [type, segments] of meta) {
210
+ let currentRef = ref;
211
+ let preSegment = "data";
212
+ for (let i = 0; i < segments.length; i++) {
213
+ currentRef = currentRef[preSegment];
214
+ preSegment = segments[i];
215
+ }
216
+ switch (type) {
217
+ case "nan":
218
+ currentRef[preSegment] = Number.NaN;
219
+ break;
220
+ case "bigint":
221
+ currentRef[preSegment] = BigInt(currentRef[preSegment]);
222
+ break;
223
+ case "date":
224
+ currentRef[preSegment] = new Date(currentRef[preSegment]);
225
+ break;
226
+ case "regexp": {
227
+ const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
228
+ currentRef[preSegment] = new RegExp(pattern, flags);
229
+ break;
230
+ }
231
+ case "url":
232
+ currentRef[preSegment] = new URL(currentRef[preSegment]);
233
+ break;
234
+ case "undefined":
235
+ currentRef[preSegment] = void 0;
236
+ break;
237
+ case "map":
238
+ currentRef[preSegment] = new Map(currentRef[preSegment]);
239
+ break;
240
+ case "set":
241
+ currentRef[preSegment] = new Set(currentRef[preSegment]);
242
+ break;
243
+ /* v8 ignore next 3 */
244
+ default: {
245
+ const _expected = type;
246
+ }
247
+ }
248
+ }
249
+ return ref.data;
250
+ }
251
+
252
+ // src/adapters/standard/rpc-codec.ts
253
+ var RPCCodec = class {
254
+ serializer;
255
+ constructor(options = {}) {
256
+ this.serializer = options.serializer ?? new RPCSerializer();
257
+ }
258
+ async decode(request, _params, _procedure) {
259
+ const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
260
+ return this.serializer.deserialize(serialized);
261
+ }
262
+ encode(output, _procedure) {
263
+ return {
264
+ status: 200,
265
+ headers: {},
266
+ body: this.serializer.serialize(output)
267
+ };
268
+ }
269
+ encodeError(error) {
270
+ return {
271
+ status: error.status,
272
+ headers: {},
273
+ body: this.serializer.serialize(error.toJSON())
274
+ };
275
+ }
276
+ };
277
+
278
+ // src/adapters/standard/rpc-matcher.ts
279
+ var RPCMatcher = class {
280
+ tree = {};
281
+ pendingRouters = [];
282
+ init(router, path = []) {
283
+ const laziedOptions = eachContractProcedure({
284
+ router,
285
+ path
286
+ }, ({ path: path2, contract }) => {
287
+ const httpPath = convertPathToHttpPath(path2);
288
+ if (isProcedure(contract)) {
289
+ this.tree[httpPath] = {
290
+ path: path2,
291
+ contract,
292
+ procedure: contract,
293
+ // this mean dev not used contract-first so we can used contract as procedure directly
294
+ router
295
+ };
296
+ } else {
297
+ this.tree[httpPath] = {
298
+ path: path2,
299
+ contract,
300
+ procedure: void 0,
301
+ router
302
+ };
303
+ }
304
+ });
305
+ this.pendingRouters.push(...laziedOptions.map((option) => ({
306
+ ...option,
307
+ httpPathPrefix: convertPathToHttpPath(option.path)
308
+ })));
309
+ }
310
+ async match(_method, pathname) {
311
+ if (this.pendingRouters.length) {
312
+ const newPendingRouters = [];
313
+ for (const pendingRouter of this.pendingRouters) {
314
+ if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
315
+ const { default: router } = await unlazy(pendingRouter.lazied);
316
+ this.init(router, pendingRouter.path);
317
+ } else {
318
+ newPendingRouters.push(pendingRouter);
319
+ }
320
+ }
321
+ this.pendingRouters = newPendingRouters;
322
+ }
323
+ const match = this.tree[pathname];
324
+ if (!match) {
325
+ return void 0;
326
+ }
327
+ if (!match.procedure) {
328
+ const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
329
+ if (!isProcedure(maybeProcedure)) {
330
+ throw new Error(`
331
+ [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
332
+ Ensure that the procedure is correctly defined and matches the expected contract.
333
+ `);
334
+ }
335
+ match.procedure = createContractedProcedure(match.contract, maybeProcedure);
336
+ }
337
+ return {
338
+ path: match.path,
339
+ procedure: match.procedure
340
+ };
341
+ }
342
+ };
343
+
344
+ export {
345
+ StandardHandler,
346
+ RPCSerializer,
347
+ serializeRPCJson,
348
+ RPCCodec,
349
+ RPCMatcher
350
+ };
351
+ //# sourceMappingURL=chunk-6TBBWYQ3.js.map
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/lazy.ts
8
2
  var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
9
3
  function lazy(loader) {
@@ -69,30 +63,29 @@ function middlewareOutputFn(output) {
69
63
 
70
64
  // src/procedure-client.ts
71
65
  import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
72
- import { executeWithHooks, toError, value } from "@orpc/shared";
66
+ import { intercept, toError, value } from "@orpc/shared";
73
67
  function createProcedureClient(lazyableProcedure, ...[options]) {
74
68
  return async (...[input, callerOptions]) => {
75
69
  const path = options?.path ?? [];
76
70
  const { default: procedure } = await unlazy(lazyableProcedure);
77
- const context = await value(options?.context ?? {}, callerOptions?.context);
71
+ const clientContext = callerOptions?.context ?? {};
72
+ const context = await value(options?.context ?? {}, clientContext);
78
73
  const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
79
- const executeOptions = {
80
- input,
81
- context,
82
- errors,
83
- path,
84
- procedure,
85
- signal: callerOptions?.signal
86
- };
87
74
  try {
88
- const output = await executeWithHooks({
89
- hooks: options,
90
- input,
91
- context,
92
- meta: executeOptions,
93
- execute: () => executeProcedureInternal(procedure, executeOptions)
94
- });
95
- return output;
75
+ return await intercept(
76
+ options?.interceptors ?? [],
77
+ {
78
+ context,
79
+ input,
80
+ // input only optional when it undefinable so we can safely cast it
81
+ errors,
82
+ path,
83
+ procedure,
84
+ signal: callerOptions?.signal,
85
+ lastEventId: callerOptions?.lastEventId
86
+ },
87
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
88
+ );
96
89
  } catch (e) {
97
90
  if (!(e instanceof ORPCError)) {
98
91
  throw toError(e);
@@ -296,8 +289,70 @@ function createAccessibleLazyRouter(lazied) {
296
289
  return recursive;
297
290
  }
298
291
 
292
+ // src/utils.ts
293
+ import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
294
+ function eachContractProcedure(options, callback, laziedOptions = []) {
295
+ const hiddenContract = getRouterContract(options.router);
296
+ if (hiddenContract) {
297
+ return eachContractProcedure(
298
+ {
299
+ router: hiddenContract,
300
+ path: options.path
301
+ },
302
+ callback,
303
+ laziedOptions
304
+ );
305
+ }
306
+ if (isLazy(options.router)) {
307
+ laziedOptions.push({
308
+ lazied: options.router,
309
+ path: options.path
310
+ });
311
+ } else if (isContractProcedure2(options.router)) {
312
+ callback({
313
+ contract: options.router,
314
+ path: options.path
315
+ });
316
+ } else {
317
+ for (const key in options.router) {
318
+ eachContractProcedure(
319
+ {
320
+ router: options.router[key],
321
+ path: [...options.path, key]
322
+ },
323
+ callback,
324
+ laziedOptions
325
+ );
326
+ }
327
+ }
328
+ return laziedOptions;
329
+ }
330
+ async function eachAllContractProcedure(options, callback) {
331
+ const pending = [options];
332
+ for (const item of pending) {
333
+ const lazies = eachContractProcedure(item, callback);
334
+ for (const lazy2 of lazies) {
335
+ const { default: router } = await unlazy(lazy2.lazied);
336
+ pending.push({
337
+ path: lazy2.path,
338
+ router
339
+ });
340
+ }
341
+ }
342
+ }
343
+ function convertPathToHttpPath(path) {
344
+ return `/${path.map(encodeURIComponent).join("/")}`;
345
+ }
346
+ function createContractedProcedure(contract, procedure) {
347
+ return new Procedure({
348
+ ...procedure["~orpc"],
349
+ errorMap: contract["~orpc"].errorMap,
350
+ route: contract["~orpc"].route,
351
+ meta: contract["~orpc"].meta
352
+ });
353
+ }
354
+
299
355
  export {
300
- __export,
301
356
  LAZY_LOADER_SYMBOL,
302
357
  lazy,
303
358
  isLazy,
@@ -315,6 +370,10 @@ export {
315
370
  getLazyRouterPrefix,
316
371
  createAccessibleLazyRouter,
317
372
  adaptRouter,
318
- getRouterChild
373
+ getRouterChild,
374
+ eachContractProcedure,
375
+ eachAllContractProcedure,
376
+ convertPathToHttpPath,
377
+ createContractedProcedure
319
378
  };
320
- //# sourceMappingURL=chunk-KK4SDLC7.js.map
379
+ //# sourceMappingURL=chunk-RDEUEBK3.js.map
@@ -0,0 +1,32 @@
1
+ import {
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ StandardHandler
5
+ } from "./chunk-6TBBWYQ3.js";
6
+
7
+ // src/adapters/fetch/rpc-handler.ts
8
+ import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
9
+ var RPCHandler = class {
10
+ standardHandler;
11
+ constructor(router, options) {
12
+ const matcher = options?.matcher ?? new RPCMatcher();
13
+ const codec = options?.codec ?? new RPCCodec();
14
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
15
+ }
16
+ async handle(request, ...rest) {
17
+ const standardRequest = toStandardRequest(request);
18
+ const result = await this.standardHandler.handle(standardRequest, ...rest);
19
+ if (!result.matched) {
20
+ return result;
21
+ }
22
+ return {
23
+ matched: true,
24
+ response: toFetchResponse(result.response)
25
+ };
26
+ }
27
+ };
28
+
29
+ export {
30
+ RPCHandler
31
+ };
32
+ //# sourceMappingURL=chunk-SVWPMCP4.js.map
@@ -0,0 +1,125 @@
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
+ };
17
+
18
+ // src/plugins/cors.ts
19
+ import { value } from "@orpc/shared";
20
+ var CORSPlugin = class {
21
+ options;
22
+ constructor(options) {
23
+ const defaults = {
24
+ origin: (origin) => origin,
25
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
26
+ };
27
+ this.options = {
28
+ ...defaults,
29
+ ...options
30
+ };
31
+ }
32
+ init(options) {
33
+ options.interceptorsRoot ??= [];
34
+ options.interceptorsRoot.unshift(async (interceptorOptions) => {
35
+ if (interceptorOptions.request.method === "OPTIONS") {
36
+ const resHeaders = {};
37
+ if (this.options.maxAge !== void 0) {
38
+ resHeaders["access-control-max-age"] = this.options.maxAge.toString();
39
+ }
40
+ if (this.options.allowMethods?.length) {
41
+ resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
42
+ }
43
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
44
+ if (Array.isArray(allowHeaders) && allowHeaders.length) {
45
+ resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
46
+ } else if (typeof allowHeaders === "string") {
47
+ resHeaders["access-control-allow-headers"] = allowHeaders;
48
+ }
49
+ return {
50
+ matched: true,
51
+ response: {
52
+ status: 204,
53
+ headers: resHeaders,
54
+ body: void 0
55
+ }
56
+ };
57
+ }
58
+ return interceptorOptions.next();
59
+ });
60
+ options.interceptorsRoot.unshift(async (interceptorOptions) => {
61
+ const result = await interceptorOptions.next();
62
+ if (!result.matched) {
63
+ return result;
64
+ }
65
+ const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
66
+ const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
67
+ const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
68
+ if (allowedOriginArr.includes("*")) {
69
+ result.response.headers["access-control-allow-origin"] = "*";
70
+ } else {
71
+ if (allowedOriginArr.includes(origin)) {
72
+ result.response.headers["access-control-allow-origin"] = origin;
73
+ }
74
+ result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
75
+ }
76
+ const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
77
+ const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
78
+ if (allowedTimingOriginArr.includes("*")) {
79
+ result.response.headers["timing-allow-origin"] = "*";
80
+ } else if (allowedTimingOriginArr.includes(origin)) {
81
+ result.response.headers["timing-allow-origin"] = origin;
82
+ }
83
+ if (this.options.credentials) {
84
+ result.response.headers["access-control-allow-credentials"] = "true";
85
+ }
86
+ if (this.options.exposeHeaders?.length) {
87
+ result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
88
+ }
89
+ return result;
90
+ });
91
+ }
92
+ };
93
+
94
+ // src/plugins/response-headers.ts
95
+ var ResponseHeadersPlugin = class {
96
+ init(options) {
97
+ options.interceptorsRoot ??= [];
98
+ options.interceptorsRoot.push(async (interceptorOptions) => {
99
+ const headers = new Headers();
100
+ interceptorOptions.context.resHeaders = headers;
101
+ const result = await interceptorOptions.next();
102
+ if (!result.matched) {
103
+ return result;
104
+ }
105
+ const responseHeaders = result.response.headers;
106
+ for (const [key, value2] of headers) {
107
+ if (Array.isArray(responseHeaders[key])) {
108
+ responseHeaders[key].push(value2);
109
+ } else if (responseHeaders[key] !== void 0) {
110
+ responseHeaders[key] = [responseHeaders[key], value2];
111
+ } else {
112
+ responseHeaders[key] = value2;
113
+ }
114
+ }
115
+ return result;
116
+ });
117
+ }
118
+ };
119
+
120
+ export {
121
+ CompositePlugin,
122
+ CORSPlugin,
123
+ ResponseHeadersPlugin
124
+ };
125
+ //# sourceMappingURL=chunk-XI6WGCB3.js.map
package/dist/fetch.js CHANGED
@@ -1,15 +1,10 @@
1
- import "./chunk-WUOGVGWG.js";
2
1
  import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
2
+ RPCHandler
3
+ } from "./chunk-SVWPMCP4.js";
4
+ import "./chunk-6TBBWYQ3.js";
5
+ import "./chunk-RDEUEBK3.js";
6
+ import "./chunk-XI6WGCB3.js";
9
7
  export {
10
- ORPCPayloadCodec,
11
- ORPCProcedureMatcher,
12
- RPCHandler,
13
- super_json_exports as SuperJSON
8
+ RPCHandler
14
9
  };
15
10
  //# sourceMappingURL=fetch.js.map