@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50

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 (139) hide show
  1. package/dist/adapters/aws-lambda/handler.d.ts +17 -15
  2. package/dist/adapters/aws-lambda/handler.js +23 -23
  3. package/dist/adapters/aws-lambda/index.d.ts +4 -16
  4. package/dist/adapters/aws-lambda/index.js +2 -2
  5. package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
  6. package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
  7. package/dist/adapters/crossws/handler.d.ts +44 -42
  8. package/dist/adapters/crossws/handler.js +53 -60
  9. package/dist/adapters/crossws/index.d.ts +3 -2
  10. package/dist/adapters/crossws/index.js +2 -2
  11. package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
  12. package/dist/adapters/crossws/rpc-handler.js +17 -14
  13. package/dist/adapters/fastify/handler.d.ts +17 -15
  14. package/dist/adapters/fastify/handler.js +20 -20
  15. package/dist/adapters/fastify/index.d.ts +3 -2
  16. package/dist/adapters/fastify/index.js +2 -2
  17. package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
  18. package/dist/adapters/fastify/rpc-handler.js +16 -13
  19. package/dist/adapters/fetch/handler.d.ts +19 -17
  20. package/dist/adapters/fetch/handler.js +22 -22
  21. package/dist/adapters/fetch/index.d.ts +4 -7
  22. package/dist/adapters/fetch/index.js +3 -7
  23. package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
  24. package/dist/adapters/fetch/rpc-handler.js +18 -15
  25. package/dist/adapters/message-port/handler.d.ts +58 -60
  26. package/dist/adapters/message-port/handler.js +72 -86
  27. package/dist/adapters/message-port/index.d.ts +3 -2
  28. package/dist/adapters/message-port/index.js +2 -2
  29. package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
  30. package/dist/adapters/message-port/rpc-handler.js +17 -14
  31. package/dist/adapters/node/handler.d.ts +17 -15
  32. package/dist/adapters/node/handler.js +20 -20
  33. package/dist/adapters/node/index.d.ts +4 -7
  34. package/dist/adapters/node/index.js +3 -7
  35. package/dist/adapters/node/rpc-handler.d.ts +9 -9
  36. package/dist/adapters/node/rpc-handler.js +17 -14
  37. package/dist/adapters/standard/codec.d.ts +13 -13
  38. package/dist/adapters/standard/handler.d.ts +49 -49
  39. package/dist/adapters/standard/handler.js +205 -205
  40. package/dist/adapters/standard/index.d.ts +7 -6
  41. package/dist/adapters/standard/index.js +4 -5
  42. package/dist/adapters/standard/plugin.d.ts +25 -31
  43. package/dist/adapters/standard/plugin.js +14 -16
  44. package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
  45. package/dist/adapters/standard/rpc-handler-codec.js +50 -51
  46. package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
  47. package/dist/adapters/standard/rpc-matcher.js +103 -149
  48. package/dist/adapters/standard/utils.d.ts +8 -8
  49. package/dist/adapters/standard/utils.js +7 -5
  50. package/dist/adapters/standard-peer/index.d.ts +2 -1
  51. package/dist/adapters/standard-peer/index.js +1 -1
  52. package/dist/adapters/standard-peer/utils.d.ts +6 -4
  53. package/dist/adapters/standard-peer/utils.js +12 -6
  54. package/dist/adapters/websocket/handler.d.ts +52 -50
  55. package/dist/adapters/websocket/handler.js +75 -85
  56. package/dist/adapters/websocket/index.d.ts +3 -2
  57. package/dist/adapters/websocket/index.js +2 -2
  58. package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
  59. package/dist/adapters/websocket/rpc-handler.js +17 -14
  60. package/dist/builder-variants.d.ts +195 -195
  61. package/dist/builder.d.ts +103 -104
  62. package/dist/builder.js +198 -224
  63. package/dist/constants.d.ts +1 -1
  64. package/dist/constants.js +4 -2
  65. package/dist/context.d.ts +3 -3
  66. package/dist/extensions/callable.d.ts +11 -11
  67. package/dist/extensions/callable.js +6 -5
  68. package/dist/helpers/base64url.d.ts +1 -1
  69. package/dist/helpers/base64url.js +44 -49
  70. package/dist/helpers/cookie.d.ts +10 -11
  71. package/dist/helpers/cookie.js +56 -63
  72. package/dist/helpers/encryption.d.ts +1 -1
  73. package/dist/helpers/encryption.js +80 -70
  74. package/dist/helpers/index.d.ts +5 -4
  75. package/dist/helpers/index.js +4 -4
  76. package/dist/helpers/signing.d.ts +1 -1
  77. package/dist/helpers/signing.js +72 -82
  78. package/dist/implementer-procedure.d.ts +12 -13
  79. package/dist/implementer-procedure.js +37 -44
  80. package/dist/implementer-router.d.ts +30 -36
  81. package/dist/implementer-router.js +92 -111
  82. package/dist/implementer.d.ts +8 -8
  83. package/dist/implementer.js +28 -35
  84. package/dist/index.d.ts +22 -61
  85. package/dist/index.js +16 -48
  86. package/dist/lazy.d.ts +14 -14
  87. package/dist/lazy.js +19 -30
  88. package/dist/middleware-decorated.d.ts +8 -9
  89. package/dist/middleware-decorated.js +66 -70
  90. package/dist/middleware.d.ts +34 -34
  91. package/dist/plugins/batch.d.ts +75 -75
  92. package/dist/plugins/batch.js +345 -379
  93. package/dist/plugins/cors.d.ts +60 -64
  94. package/dist/plugins/cors.js +118 -111
  95. package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
  96. package/dist/plugins/get-method-csrf-protection.js +47 -63
  97. package/dist/plugins/head-method.d.ts +11 -9
  98. package/dist/plugins/head-method.js +97 -94
  99. package/dist/plugins/index.d.ts +15 -39
  100. package/dist/plugins/index.js +14 -29
  101. package/dist/plugins/method-override.d.ts +30 -28
  102. package/dist/plugins/method-override.js +53 -49
  103. package/dist/plugins/request-compression.d.ts +11 -9
  104. package/dist/plugins/request-compression.js +52 -79
  105. package/dist/plugins/request-headers.d.ts +10 -8
  106. package/dist/plugins/request-headers.js +27 -29
  107. package/dist/plugins/request-limit.d.ts +21 -19
  108. package/dist/plugins/request-limit.js +60 -67
  109. package/dist/plugins/response-compression.d.ts +42 -39
  110. package/dist/plugins/response-compression.js +150 -202
  111. package/dist/plugins/response-headers.d.ts +15 -13
  112. package/dist/plugins/response-headers.js +43 -46
  113. package/dist/plugins/rethrow.d.ts +25 -23
  114. package/dist/plugins/rethrow.js +46 -58
  115. package/dist/plugins/signal-sync.d.ts +7 -5
  116. package/dist/plugins/signal-sync.js +71 -86
  117. package/dist/plugins/timeout.d.ts +29 -27
  118. package/dist/plugins/timeout.js +61 -58
  119. package/dist/procedure-client.d.ts +14 -15
  120. package/dist/procedure-client.js +149 -166
  121. package/dist/procedure-decorated.d.ts +9 -9
  122. package/dist/procedure-decorated.js +36 -44
  123. package/dist/procedure-utils.d.ts +10 -30
  124. package/dist/procedure-utils.js +39 -40
  125. package/dist/procedure.d.ts +60 -60
  126. package/dist/procedure.js +18 -24
  127. package/dist/router-client.d.ts +9 -11
  128. package/dist/router-client.js +33 -41
  129. package/dist/router-hidden.js +10 -12
  130. package/dist/router-utils.d.ts +13 -30
  131. package/dist/router-utils.js +146 -191
  132. package/dist/router.d.ts +12 -26
  133. package/package.json +10 -10
  134. package/dist/adapters/standard/codec.js +0 -1
  135. package/dist/builder-variants.js +0 -1
  136. package/dist/context.js +0 -1
  137. package/dist/middleware.js +0 -1
  138. package/dist/router-hidden.d.ts +0 -5
  139. package/dist/router.js +0 -1
package/dist/lazy.js CHANGED
@@ -1,31 +1,20 @@
1
- import { getConstructor, isNonPrimitive } from '@orpc/shared';
2
- export class Lazy {
3
- '~orpc';
4
- constructor(def) {
5
- this['~orpc'] = def;
6
- }
7
- /**
8
- * Checks if the given instance satisfies the {@link Lazy} class/interface.
9
- */
10
- static [Symbol.hasInstance](instance) {
11
- if (this !== Lazy) {
12
- // fallback to default instanceof check if this is extended class
13
- return Function.prototype[Symbol.hasInstance].call(this, instance);
14
- }
15
- const constructor = getConstructor(instance);
16
- if (constructor === Lazy) {
17
- return true;
18
- }
19
- return (isNonPrimitive(instance) &&
20
- isNonPrimitive(instance['~orpc']) &&
21
- isNonPrimitive(instance['~orpc'].meta) &&
22
- (instance['~orpc'].metaPlugins === undefined ||
23
- Array.isArray(instance['~orpc'].metaPlugins)) &&
24
- typeof instance['~orpc'].loader === 'function');
25
- }
26
- }
27
- export function unlazy(maybeLazy) {
28
- return maybeLazy instanceof Lazy
29
- ? maybeLazy['~orpc'].loader()
30
- : Promise.resolve({ default: maybeLazy });
1
+ import { getConstructor, isNonPrimitive } from "@orpc/shared";
2
+ // src/lazy.ts
3
+ var Lazy = class Lazy {
4
+ "~orpc";
5
+ "constructor"(def) {
6
+ this["~orpc"] = def;
7
+ }
8
+ /**
9
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
10
+ */
11
+ static [Symbol.hasInstance](instance) {
12
+ if (this !== Lazy) return Function.prototype[Symbol.hasInstance].call(this, instance);
13
+ if (getConstructor(instance) === Lazy) return true;
14
+ return isNonPrimitive(instance) && isNonPrimitive(instance["~orpc"]) && isNonPrimitive(instance["~orpc"].meta) && (instance["~orpc"].metaPlugins === void 0 || Array.isArray(instance["~orpc"].metaPlugins)) && typeof instance["~orpc"].loader === "function";
15
+ }
16
+ };
17
+ function unlazy(maybeLazy) {
18
+ return maybeLazy instanceof Lazy ? maybeLazy["~orpc"].loader() : Promise.resolve({ default: maybeLazy });
31
19
  }
20
+ export { Lazy, unlazy };
@@ -1,10 +1,9 @@
1
- import type { ErrorMap, MergedErrorMap } from '@orpc/contract';
2
- import type { IntersectPick } from '@orpc/shared';
3
- import type { Context, MergedContext, MergedInitialContext } from './context.ts';
4
- import type { Middleware } from './middleware.ts';
1
+ import { Context, MergedContext, MergedInitialContext } from "./context.js";
2
+ import { Middleware } from "./middleware.js";
3
+ import { ErrorMap, MergedErrorMap } from "@orpc/contract";
4
+ import { IntersectPick } from "@orpc/shared";
5
5
  export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap> {
6
- adaptInput<T>(adapt: (input: T) => TInput): DecoratedMiddleware<TInContext, TOutContext, T, TOutput, TErrorMap>;
7
- errors<T extends ErrorMap>(errors: T): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, MergedErrorMap<TErrorMap, T>>;
8
- use<$OutContext extends IntersectPick<MergedContext<TInContext, TOutContext>, $OutContext>, $Input extends TInput, $InContext extends Context = MergedContext<TInContext, TOutContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInContext, TOutContext>, $OutContext, $Input, TOutput, $ErrorMap>): DecoratedMiddleware<MergedInitialContext<TInContext, TOutContext, $InContext>, MergedContext<TOutContext, $OutContext>, $Input, TOutput, MergedErrorMap<$ErrorMap, TErrorMap>>;
9
- }
10
- export declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>;
6
+ adaptInput<T>(adapt: (input: T) => TInput): DecoratedMiddleware<TInContext, TOutContext, T, TOutput, TErrorMap>;
7
+ errors<T extends ErrorMap>(errors: T): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, MergedErrorMap<TErrorMap, T>>;
8
+ use<$OutContext extends IntersectPick<MergedContext<TInContext, TOutContext>, $OutContext>, $Input extends TInput, $InContext extends Context = MergedContext<TInContext, TOutContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInContext, TOutContext>, $OutContext, $Input, TOutput, $ErrorMap>): DecoratedMiddleware<MergedInitialContext<TInContext, TOutContext, $InContext>, MergedContext<TOutContext, $OutContext>, $Input, TOutput, MergedErrorMap<$ErrorMap, TErrorMap>>;
9
+ }
@@ -1,71 +1,67 @@
1
- import { mergeErrorMap } from '@orpc/contract';
2
- import { toArray } from '@orpc/shared';
3
- export function decorateMiddleware(middleware) {
4
- const decorated = ((...args) => middleware(...args));
5
- decorated['~orpc'] = middleware['~orpc'];
6
- Object.defineProperty(decorated, 'name', {
7
- value: middleware.name,
8
- });
9
- decorated.adaptInput = (adapt) => {
10
- const mapped = decorateMiddleware((opts, input, ...args) => {
11
- return middleware(opts, adapt(input), ...args);
12
- });
13
- mapped['~orpc'] = decorated['~orpc'];
14
- Object.defineProperty(mapped, 'name', {
15
- value: decorated.name,
16
- });
17
- return mapped;
18
- };
19
- decorated.errors = (errors) => {
20
- const newMiddleware = decorateMiddleware(decorated);
21
- newMiddleware['~orpc'] = {
22
- ...decorated['~orpc'],
23
- errorMap: mergeErrorMap(decorated['~orpc']?.errorMap, errors),
24
- };
25
- return newMiddleware;
26
- };
27
- decorated.use = (usedMiddleware) => {
28
- const merged = decorateMiddleware((opts, ...args) => {
29
- return middleware({
30
- ...opts,
31
- async next(nextOpts1) {
32
- const signal = nextOpts1?.signal ?? opts.signal;
33
- const result = await usedMiddleware({
34
- ...opts,
35
- context: { ...opts.context, ...nextOpts1?.context },
36
- signal,
37
- next(nextOpts2, ...args) {
38
- return opts.next({
39
- context: {
40
- ...nextOpts1?.context,
41
- ...nextOpts2?.context,
42
- },
43
- signal: nextOpts2?.signal ?? signal,
44
- }, ...args);
45
- },
46
- }, ...args);
47
- return {
48
- ...result,
49
- context: {
50
- ...nextOpts1?.context,
51
- ...result.context,
52
- },
53
- };
54
- },
55
- }, ...args);
56
- });
57
- merged['~orpc'] = {
58
- ...decorated['~orpc'],
59
- errorMap: mergeErrorMap(usedMiddleware['~orpc']?.errorMap, decorated['~orpc']?.errorMap),
60
- metaPlugins: [
61
- ...toArray(decorated['~orpc']?.metaPlugins),
62
- ...toArray(usedMiddleware['~orpc']?.metaPlugins),
63
- ],
64
- };
65
- Object.defineProperty(merged, 'name', {
66
- value: `${decorated.name} + ${usedMiddleware.name}`,
67
- });
68
- return merged;
69
- };
70
- return decorated;
1
+ import { mergeErrorMap } from "@orpc/contract";
2
+ import { toArray } from "@orpc/shared";
3
+ // src/middleware-decorated.ts
4
+ function decorateMiddleware(middleware) {
5
+ const decorated = ((...args) => middleware(...args));
6
+ decorated["~orpc"] = middleware["~orpc"];
7
+ Object.defineProperty(decorated, "name", { value: middleware.name });
8
+ decorated.adaptInput = (adapt) => {
9
+ const mapped = decorateMiddleware((opts, input, ...args) => {
10
+ return middleware(opts, adapt(input), ...args);
11
+ });
12
+ mapped["~orpc"] = decorated["~orpc"];
13
+ Object.defineProperty(mapped, "name", { value: decorated.name });
14
+ return mapped;
15
+ };
16
+ decorated.errors = (errors) => {
17
+ const newMiddleware = decorateMiddleware(decorated);
18
+ newMiddleware["~orpc"] = {
19
+ ...decorated["~orpc"],
20
+ errorMap: mergeErrorMap(decorated["~orpc"]?.errorMap, errors)
21
+ };
22
+ return newMiddleware;
23
+ };
24
+ decorated.use = (usedMiddleware) => {
25
+ const merged = decorateMiddleware((opts, ...args) => {
26
+ return middleware({
27
+ ...opts,
28
+ async next(nextOpts1) {
29
+ const signal = nextOpts1?.signal ?? opts.signal;
30
+ const result = await usedMiddleware({
31
+ ...opts,
32
+ context: {
33
+ ...opts.context,
34
+ ...nextOpts1?.context
35
+ },
36
+ signal,
37
+ next(nextOpts2, ...args) {
38
+ return opts.next({
39
+ context: {
40
+ ...nextOpts1?.context,
41
+ ...nextOpts2?.context
42
+ },
43
+ signal: nextOpts2?.signal ?? signal
44
+ }, ...args);
45
+ }
46
+ }, ...args);
47
+ return {
48
+ ...result,
49
+ context: {
50
+ ...nextOpts1?.context,
51
+ ...result.context
52
+ }
53
+ };
54
+ }
55
+ }, ...args);
56
+ });
57
+ merged["~orpc"] = {
58
+ ...decorated["~orpc"],
59
+ errorMap: mergeErrorMap(usedMiddleware["~orpc"]?.errorMap, decorated["~orpc"]?.errorMap),
60
+ metaPlugins: [...toArray(decorated["~orpc"]?.metaPlugins), ...toArray(usedMiddleware["~orpc"]?.metaPlugins)]
61
+ };
62
+ Object.defineProperty(merged, "name", { value: `${decorated.name} + ${usedMiddleware.name}` });
63
+ return merged;
64
+ };
65
+ return decorated;
71
66
  }
67
+ export { decorateMiddleware };
@@ -1,54 +1,54 @@
1
- import type { AnyMetaPlugin, ErrorMap, ORPCErrorConstructorMap } from '@orpc/contract';
2
- import type { MaybeOptionalOptions, Promisable } from '@orpc/shared';
3
- import type { Context } from './context.ts';
4
- import type { AnyProcedure } from './procedure.ts';
1
+ import { Context } from "./context.js";
2
+ import { AnyProcedure } from "./procedure.js";
3
+ import { AnyMetaPlugin, ErrorMap, ORPCErrorConstructorMap } from "@orpc/contract";
4
+ import { MaybeOptionalOptions, Promisable } from "@orpc/shared";
5
5
  export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
6
- output: TOutput;
7
- context: TOutContext;
6
+ output: TOutput;
7
+ context: TOutContext;
8
8
  }>;
9
9
  export type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
10
- context?: TOutContext | undefined;
10
+ context?: TOutContext | undefined;
11
11
  } : {
12
- context: TOutContext;
12
+ context: TOutContext;
13
13
  }) & {
14
- /** Overrides the signal for the rest of the chain. */
15
- signal?: AbortSignal | undefined;
14
+ /** Overrides the signal for the rest of the chain. */
15
+ signal?: AbortSignal | undefined;
16
16
  };
17
17
  export interface MiddlewareNext<TOutput> {
18
- <T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
18
+ <T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
19
19
  }
20
20
  export type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
21
- context?: TOutContext | undefined;
21
+ context?: TOutContext | undefined;
22
22
  } : {
23
- context: TOutContext;
23
+ context: TOutContext;
24
24
  }) & {
25
- output: TOutput;
25
+ output: TOutput;
26
26
  };
27
27
  export interface MiddlewareDone<TOutput> {
28
- /**
29
- * Create a successful result and terminate the middleware chain early.
30
- */
31
- <TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
28
+ /**
29
+ * Create a successful result and terminate the middleware chain early.
30
+ */
31
+ <TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
32
32
  }
33
33
  export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
34
- context: TInContext;
35
- path: string[];
36
- procedure: AnyProcedure;
37
- signal?: AbortSignal | undefined;
38
- lastEventId: string | undefined;
39
- /**
40
- * Invoke to continue the middleware chain.
41
- */
42
- next: MiddlewareNext<TOutput>;
43
- errors: TErrorConstructorMap;
34
+ context: TInContext;
35
+ path: string[];
36
+ procedure: AnyProcedure;
37
+ signal?: AbortSignal | undefined;
38
+ lastEventId: string | undefined;
39
+ /**
40
+ * Invoke to continue the middleware chain.
41
+ */
42
+ next: MiddlewareNext<TOutput>;
43
+ errors: TErrorConstructorMap;
44
44
  }
45
45
  export interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
46
- errorMap?: TErrorMap | undefined;
47
- metaPlugins?: AnyMetaPlugin[] | undefined;
46
+ errorMap?: TErrorMap | undefined;
47
+ metaPlugins?: AnyMetaPlugin[] | undefined;
48
48
  }
49
49
  export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
50
- /** this property should be optional to support inline middleware */
51
- '~orpc'?: MiddlewareDefinition<TErrorMap> | undefined;
52
- (opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
50
+ /** this property should be optional to support inline middleware */
51
+ "~orpc"?: MiddlewareDefinition<TErrorMap> | undefined;
52
+ (opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
53
53
  }
54
- export type AnyMiddleware = Middleware<any, any, any, any, any>;
54
+ export type AnyMiddleware = Middleware<any, any, any, any, any>;
@@ -1,7 +1,9 @@
1
- import type { Promisable, Value } from '@orpc/shared';
2
- import type { StandardHeaders, StandardLazyRequest, StandardResponse } from '@standard-server/core';
3
- import type { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from '../adapters/standard/index.ts';
4
- import type { Context } from '../context.ts';
1
+ import "../adapters/standard/index.js";
2
+ import { StandardHandlerPlugin } from "../adapters/standard/plugin.js";
3
+ import { StandardHandlerOptions, StandardHandlerRoutingInterceptorOptions } from "../adapters/standard/handler.js";
4
+ import { Context } from "../context.js";
5
+ import { Promisable, Value } from "@orpc/shared";
6
+ import { StandardHeaders, StandardLazyRequest, StandardResponse } from "@standard-server/core";
5
7
  /**
6
8
  * Content type for batch responses that use the length-prefixed binary framing,
7
9
  * which they do in `streaming` mode, or when any sub-response contains binary or is a stream.
@@ -11,64 +13,62 @@ import type { Context } from '../context.ts';
11
13
  */
12
14
  export declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
13
15
  export interface BatchHandlerPluginOptions<T extends Context> {
16
+ /**
17
+ * The max size of the batch allowed. Larger batches are rejected with a `413`,
18
+ * so keep the client Batch Link Plugin's `maxSize` at or below it.
19
+ *
20
+ * @default DEFAULT_BATCH_MAX_SIZE (10)
21
+ * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
22
+ */
23
+ maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
24
+ /**
25
+ * Map each subrequest in the batch before it is processed.
26
+ *
27
+ * @default merges the batch request headers into the subrequest, giving them priority over
28
+ * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
29
+ */
30
+ mapSubrequest?: ((subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest) | undefined;
31
+ /**
32
+ * Map each sub-response in the batch before it is sent.
33
+ *
34
+ * @default removes the headers the batch response already has with the same value, which the client
35
+ * merges back, and `set-cookie`, which the browser ignores there and JavaScript could read
36
+ */
37
+ mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, "status" | "headers">, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
38
+ /**
39
+ * Success batch response status code.
40
+ *
41
+ * @default 207
42
+ */
43
+ successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
44
+ /**
45
+ * Success batch response headers.
46
+ *
47
+ * In `buffered` mode, the batch response also gets the cookies its sub-responses set, and the headers they all share.
48
+ * In `streaming` mode, it gets only the cookies of the first sub-response to be ready.
49
+ * Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
50
+ *
51
+ * @default {}
52
+ */
53
+ headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
54
+ /**
55
+ * Keep-alive frames for batch responses that stream.
56
+ *
57
+ * A zero-length length-prefixed frame is sent periodically while the stream is idle
58
+ * (no message sent for `interval` ms). Clients ignore these frames.
59
+ *
60
+ * `false` disables it, an object customizes it.
61
+ *
62
+ * @default true
63
+ */
64
+ keepAlive?: boolean | {
14
65
  /**
15
- * The max size of the batch allowed. Larger batches are rejected with a `413`,
16
- * so keep the client Batch Link Plugin's `maxSize` at or below it.
66
+ * Interval (in milliseconds) between keep-alive frames after the last message.
17
67
  *
18
- * @default DEFAULT_BATCH_MAX_SIZE (10)
19
- * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
68
+ * @default 15000
20
69
  */
21
- maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
22
- /**
23
- * Map each subrequest in the batch before it is processed.
24
- *
25
- * @default merges the batch request headers into the subrequest, giving them priority over
26
- * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
27
- */
28
- mapSubrequest?: ((subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest) | undefined;
29
- /**
30
- * Map each sub-response in the batch before it is sent.
31
- *
32
- * @default removes the headers the batch response already has with the same value, which the client
33
- * merges back, and `set-cookie`, which the browser ignores there and JavaScript could read
34
- */
35
- mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, 'status' | 'headers'>, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
36
- /**
37
- * Success batch response status code.
38
- *
39
- * @default 207
40
- */
41
- successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
42
- /**
43
- * Success batch response headers.
44
- *
45
- * In `buffered` mode, the batch response also gets the cookies its sub-responses set, and the headers they all share.
46
- * In `streaming` mode, it gets only the cookies of the first sub-response to be ready.
47
- * Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
48
- *
49
- * @default {}
50
- */
51
- headers?: Value<Promisable<StandardHeaders>, [
52
- batchOptions: StandardHandlerRoutingInterceptorOptions<T>
53
- ]> | undefined;
54
- /**
55
- * Keep-alive frames for batch responses that stream.
56
- *
57
- * A zero-length length-prefixed frame is sent periodically while the stream is idle
58
- * (no message sent for `interval` ms). Clients ignore these frames.
59
- *
60
- * `false` disables it, an object customizes it.
61
- *
62
- * @default true
63
- */
64
- keepAlive?: boolean | {
65
- /**
66
- * Interval (in milliseconds) between keep-alive frames after the last message.
67
- *
68
- * @default 15000
69
- */
70
- interval?: number | undefined;
71
- } | undefined;
70
+ interval?: number | undefined;
71
+ } | undefined;
72
72
  }
73
73
  /**
74
74
  * Handles batch requests sent by the client Batch Link Plugin, splitting each
@@ -84,19 +84,19 @@ export interface BatchHandlerPluginOptions<T extends Context> {
84
84
  * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
85
85
  */
86
86
  export declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
87
- name: string;
88
- /**
89
- * Run batch interceptors inside the tracing interceptors
90
- * so each subrequest gets its own span instead of sharing one batch-level span.
91
- */
92
- after: string[];
93
- private readonly maxSize;
94
- private readonly mapSubrequest;
95
- private readonly mapSubresponse;
96
- private readonly successStatus;
97
- private readonly headers;
98
- private readonly keepAliveEnabled;
99
- private readonly keepAliveInterval;
100
- constructor(options?: BatchHandlerPluginOptions<T>);
101
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
102
- }
87
+ name: string;
88
+ /**
89
+ * Run batch interceptors inside the tracing interceptors
90
+ * so each subrequest gets its own span instead of sharing one batch-level span.
91
+ */
92
+ after: string[];
93
+ private readonly maxSize;
94
+ private readonly mapSubrequest;
95
+ private readonly mapSubresponse;
96
+ private readonly successStatus;
97
+ private readonly headers;
98
+ private readonly keepAliveEnabled;
99
+ private readonly keepAliveInterval;
100
+ constructor(options?: BatchHandlerPluginOptions<T>);
101
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
102
+ }