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

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 (178) hide show
  1. package/README.md +6 -7
  2. package/dist/adapters/aws-lambda/handler.d.ts +25 -0
  3. package/dist/adapters/aws-lambda/handler.js +24 -0
  4. package/dist/adapters/aws-lambda/index.d.ts +10 -45
  5. package/dist/adapters/aws-lambda/index.js +2 -0
  6. package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
  7. package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
  8. package/dist/adapters/crossws/handler.d.ts +45 -0
  9. package/dist/adapters/crossws/handler.js +60 -0
  10. package/dist/adapters/crossws/index.d.ts +2 -63
  11. package/dist/adapters/crossws/index.js +2 -0
  12. package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
  13. package/dist/adapters/crossws/rpc-handler.js +15 -0
  14. package/dist/adapters/fastify/handler.d.ts +21 -0
  15. package/dist/adapters/fastify/handler.js +20 -0
  16. package/dist/adapters/fastify/index.d.ts +2 -42
  17. package/dist/adapters/fastify/index.js +2 -0
  18. package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
  19. package/dist/adapters/fastify/rpc-handler.js +14 -0
  20. package/dist/adapters/fetch/handler.d.ts +23 -0
  21. package/dist/adapters/fetch/handler.js +22 -0
  22. package/dist/adapters/fetch/index.d.ts +5 -45
  23. package/dist/adapters/fetch/index.js +7 -0
  24. package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
  25. package/dist/adapters/fetch/rpc-handler.js +16 -0
  26. package/dist/adapters/message-port/{index.d.mts → handler.d.ts} +17 -30
  27. package/dist/adapters/message-port/handler.js +86 -0
  28. package/dist/adapters/message-port/index.d.ts +2 -77
  29. package/dist/adapters/message-port/index.js +2 -0
  30. package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
  31. package/dist/adapters/message-port/rpc-handler.js +15 -0
  32. package/dist/adapters/node/handler.d.ts +21 -0
  33. package/dist/adapters/node/handler.js +20 -0
  34. package/dist/adapters/node/index.d.ts +5 -42
  35. package/dist/adapters/node/index.js +7 -0
  36. package/dist/adapters/node/rpc-handler.d.ts +16 -0
  37. package/dist/adapters/node/rpc-handler.js +15 -0
  38. package/dist/adapters/standard/codec.d.ts +16 -0
  39. package/dist/adapters/standard/codec.js +1 -0
  40. package/dist/adapters/standard/handler.d.ts +68 -0
  41. package/dist/adapters/standard/handler.js +205 -0
  42. package/dist/adapters/standard/index.d.ts +6 -95
  43. package/dist/adapters/standard/index.js +5 -0
  44. package/dist/adapters/standard/plugin.d.ts +32 -0
  45. package/dist/adapters/standard/plugin.js +16 -0
  46. package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
  47. package/dist/adapters/standard/rpc-handler-codec.js +51 -0
  48. package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
  49. package/dist/adapters/standard/rpc-matcher.js +152 -0
  50. package/dist/adapters/standard/utils.d.ts +10 -0
  51. package/dist/adapters/standard/utils.js +6 -0
  52. package/dist/adapters/standard-peer/index.d.ts +1 -11
  53. package/dist/adapters/standard-peer/index.js +1 -0
  54. package/dist/adapters/standard-peer/utils.d.ts +4 -0
  55. package/dist/adapters/standard-peer/utils.js +7 -0
  56. package/dist/adapters/websocket/{index.d.mts → handler.d.ts} +11 -29
  57. package/dist/adapters/websocket/handler.js +85 -0
  58. package/dist/adapters/websocket/index.d.ts +2 -77
  59. package/dist/adapters/websocket/index.js +2 -0
  60. package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
  61. package/dist/adapters/websocket/rpc-handler.js +15 -0
  62. package/dist/builder-variants.d.ts +226 -0
  63. package/dist/builder-variants.js +1 -0
  64. package/dist/builder.d.ts +127 -0
  65. package/dist/builder.js +226 -0
  66. package/dist/constants.d.ts +2 -0
  67. package/dist/constants.js +2 -0
  68. package/dist/context.d.ts +6 -0
  69. package/dist/context.js +1 -0
  70. package/dist/extensions/callable.d.ts +6 -5
  71. package/dist/extensions/callable.js +7 -0
  72. package/dist/helpers/base64url.d.ts +31 -0
  73. package/dist/helpers/base64url.js +53 -0
  74. package/dist/helpers/cookie.d.ts +51 -0
  75. package/dist/helpers/cookie.js +69 -0
  76. package/dist/helpers/encryption.d.ts +28 -0
  77. package/dist/helpers/encryption.js +80 -0
  78. package/dist/helpers/index.d.ts +4 -167
  79. package/dist/helpers/index.js +4 -0
  80. package/dist/helpers/signing.d.ts +50 -0
  81. package/dist/helpers/signing.js +88 -0
  82. package/dist/implementer-procedure.d.ts +16 -0
  83. package/dist/implementer-procedure.js +44 -0
  84. package/dist/implementer-router.d.ts +40 -0
  85. package/dist/implementer-router.js +117 -0
  86. package/dist/implementer.d.ts +16 -0
  87. package/dist/implementer.js +37 -0
  88. package/dist/index.d.ts +45 -460
  89. package/dist/index.js +48 -0
  90. package/dist/lazy.d.ts +20 -0
  91. package/dist/lazy.js +31 -0
  92. package/dist/middleware-decorated.d.ts +10 -0
  93. package/dist/middleware-decorated.js +71 -0
  94. package/dist/middleware.d.ts +54 -0
  95. package/dist/middleware.js +1 -0
  96. package/dist/plugins/batch.d.ts +102 -0
  97. package/dist/plugins/batch.js +405 -0
  98. package/dist/plugins/cors.d.ts +73 -0
  99. package/dist/plugins/cors.js +112 -0
  100. package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
  101. package/dist/plugins/get-method-csrf-protection.js +64 -0
  102. package/dist/plugins/head-method.d.ts +23 -0
  103. package/dist/plugins/head-method.js +104 -0
  104. package/dist/plugins/index.d.ts +29 -422
  105. package/dist/plugins/index.js +29 -0
  106. package/dist/plugins/method-override.d.ts +38 -0
  107. package/dist/plugins/method-override.js +50 -0
  108. package/dist/plugins/request-compression.d.ts +16 -0
  109. package/dist/plugins/request-compression.js +82 -0
  110. package/dist/plugins/request-headers.d.ts +22 -0
  111. package/dist/plugins/request-headers.js +30 -0
  112. package/dist/{shared/server.CgBF3Vj1.d.ts → plugins/request-limit.d.ts} +4 -8
  113. package/dist/plugins/request-limit.js +68 -0
  114. package/dist/plugins/response-compression.d.ts +59 -0
  115. package/dist/plugins/response-compression.js +209 -0
  116. package/dist/plugins/response-headers.d.ts +30 -0
  117. package/dist/plugins/response-headers.js +47 -0
  118. package/dist/plugins/rethrow.d.ts +33 -0
  119. package/dist/plugins/rethrow.js +59 -0
  120. package/dist/plugins/signal-sync.d.ts +13 -0
  121. package/dist/plugins/signal-sync.js +91 -0
  122. package/dist/plugins/timeout.d.ts +37 -0
  123. package/dist/plugins/timeout.js +59 -0
  124. package/dist/procedure-client.d.ts +19 -0
  125. package/dist/procedure-client.js +175 -0
  126. package/dist/procedure-decorated.d.ts +10 -0
  127. package/dist/procedure-decorated.js +44 -0
  128. package/dist/procedure-utils.d.ts +41 -0
  129. package/dist/procedure-utils.js +49 -0
  130. package/dist/procedure.d.ts +72 -0
  131. package/dist/procedure.js +24 -0
  132. package/dist/router-client.d.ts +23 -0
  133. package/dist/router-client.js +43 -0
  134. package/dist/router-hidden.d.ts +5 -0
  135. package/dist/router-hidden.js +14 -0
  136. package/dist/router-utils.d.ts +48 -0
  137. package/dist/router-utils.js +202 -0
  138. package/dist/{shared/server.Dz7j9BEh.d.ts → router.d.ts} +14 -15
  139. package/dist/router.js +1 -0
  140. package/package.json +84 -86
  141. package/dist/adapters/aws-lambda/index.d.mts +0 -51
  142. package/dist/adapters/aws-lambda/index.mjs +0 -39
  143. package/dist/adapters/crossws/index.d.mts +0 -63
  144. package/dist/adapters/crossws/index.mjs +0 -68
  145. package/dist/adapters/fastify/index.d.mts +0 -42
  146. package/dist/adapters/fastify/index.mjs +0 -39
  147. package/dist/adapters/fetch/index.d.mts +0 -47
  148. package/dist/adapters/fetch/index.mjs +0 -42
  149. package/dist/adapters/message-port/index.mjs +0 -87
  150. package/dist/adapters/node/index.d.mts +0 -44
  151. package/dist/adapters/node/index.mjs +0 -41
  152. package/dist/adapters/standard/index.d.mts +0 -95
  153. package/dist/adapters/standard/index.mjs +0 -8
  154. package/dist/adapters/standard-peer/index.d.mts +0 -11
  155. package/dist/adapters/standard-peer/index.mjs +0 -10
  156. package/dist/adapters/websocket/index.mjs +0 -87
  157. package/dist/extensions/callable.d.mts +0 -10
  158. package/dist/extensions/callable.mjs +0 -11
  159. package/dist/helpers/index.d.mts +0 -167
  160. package/dist/helpers/index.mjs +0 -200
  161. package/dist/index.d.mts +0 -476
  162. package/dist/index.mjs +0 -463
  163. package/dist/plugins/index.d.mts +0 -432
  164. package/dist/plugins/index.mjs +0 -965
  165. package/dist/shared/server.1ExWFMze.mjs +0 -69
  166. package/dist/shared/server.9B1jEm5a.d.mts +0 -105
  167. package/dist/shared/server.BB464y-6.mjs +0 -207
  168. package/dist/shared/server.BC5BIu02.d.mts +0 -73
  169. package/dist/shared/server.BSYGskId.d.ts +0 -14
  170. package/dist/shared/server.BvG3boBj.d.mts +0 -14
  171. package/dist/shared/server.CTV_mC2P.d.mts +0 -34
  172. package/dist/shared/server.CYbIpHbH.mjs +0 -239
  173. package/dist/shared/server.Chq5FpXf.mjs +0 -353
  174. package/dist/shared/server.DFPxP2v3.d.mts +0 -166
  175. package/dist/shared/server.DFPxP2v3.d.ts +0 -166
  176. package/dist/shared/server.DOg7ke6y.d.ts +0 -105
  177. package/dist/shared/server.W91HSRkE.mjs +0 -9
  178. package/dist/shared/server.sBQSgqK3.mjs +0 -41
@@ -1,166 +0,0 @@
1
- import { ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
- import { DistributiveOmit, MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
-
5
- interface Context {
6
- [key: PropertyKey]: any;
7
- }
8
- type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
9
- type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
10
-
11
- type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
12
- output: TOutput;
13
- context: TOutContext;
14
- }>;
15
- type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
16
- context?: TOutContext | undefined;
17
- } : {
18
- context: TOutContext;
19
- }) & {
20
- /** Overrides the signal for the rest of the chain. */
21
- signal?: AbortSignal | undefined;
22
- };
23
- interface MiddlewareNext<TOutput> {
24
- <T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
25
- }
26
- type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
27
- context?: TOutContext | undefined;
28
- } : {
29
- context: TOutContext;
30
- }) & {
31
- output: TOutput;
32
- };
33
- interface MiddlewareDone<TOutput> {
34
- /**
35
- * Create a successful result and terminate the middleware chain early.
36
- */
37
- <TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
38
- }
39
- interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
40
- context: TInContext;
41
- path: string[];
42
- procedure: AnyProcedure;
43
- signal?: AbortSignal | undefined;
44
- lastEventId: string | undefined;
45
- /**
46
- * Invoke to continue the middleware chain.
47
- */
48
- next: MiddlewareNext<TOutput>;
49
- errors: TErrorConstructorMap;
50
- }
51
- interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
52
- errorMap?: TErrorMap | undefined;
53
- metaPlugins?: AnyMetaPlugin[] | undefined;
54
- }
55
- interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
56
- /** this property should be optional to support inline middleware */
57
- '~orpc'?: MiddlewareDefinition<TErrorMap> | undefined;
58
- (opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
59
- }
60
- type AnyMiddleware = Middleware<any, any, any, any, any>;
61
-
62
- interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
63
- context: TCurrentContext;
64
- input: TInput;
65
- path: string[];
66
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap>;
67
- signal?: AbortSignal | undefined;
68
- lastEventId?: string | undefined;
69
- errors: TErrorConstructorMap;
70
- }
71
- interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
72
- (opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Promisable<THandlerOutput>;
73
- }
74
- interface OrderedMiddleware {
75
- /**
76
- * Snapshot of `inputSchemas.length`
77
- * at the time this middleware was used.
78
- *
79
- * @default 0
80
- */
81
- inputSchemasLengthAtUse?: number | undefined;
82
- /**
83
- * Snapshot of `outputSchemas.length`
84
- * at the time this middleware was used.
85
- *
86
- * @default 0
87
- */
88
- outputSchemasLengthAtUse?: number | undefined;
89
- middleware: AnyMiddleware;
90
- }
91
- interface ProcedureConfig {
92
- /**
93
- * When enabled, input schemas are not validated at runtime.
94
- * Schemas are still used for type inference and OpenAPI generation.
95
- *
96
- * @remarks
97
- * **Warning**: Do not disable validation for schemas that transform values.
98
- *
99
- * @default false
100
- */
101
- disableInputValidation?: boolean | undefined;
102
- /**
103
- * When enabled, output schemas are not validated at runtime.
104
- * Schemas are still used for type inference and OpenAPI generation.
105
- *
106
- * Useful when output schemas exist only for specification generation.
107
- *
108
- * @remarks
109
- * **Warning**: Do not disable validation for schemas that transform values.
110
- *
111
- * @default false
112
- */
113
- disableOutputValidation?: boolean | undefined;
114
- }
115
- interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
116
- __TInitialContext?: (type: TInitialContext) => unknown;
117
- __TInjectedContext?: (type: TInjectedContext) => unknown;
118
- orderedMiddlewares: OrderedMiddleware[];
119
- handler: ProcedureHandler<any, any, any, any>;
120
- }
121
- declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
122
- '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
123
- constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>);
124
- /**
125
- * Checks if the given instance satisfies the {@link Procedure} class/interface.
126
- */
127
- static [Symbol.hasInstance](instance: unknown): boolean;
128
- }
129
- type AnyProcedure = Procedure<any, any, any, any, any>;
130
-
131
- interface LazyDefinition<T> {
132
- meta: Meta;
133
- metaPlugins?: AnyMetaPlugin[] | undefined;
134
- loader: () => Promise<{
135
- default: T;
136
- }>;
137
- }
138
- declare class Lazy<T> {
139
- '~orpc': LazyDefinition<T>;
140
- constructor(def: LazyDefinition<T>);
141
- /**
142
- * Checks if the given instance satisfies the {@link Lazy} class/interface.
143
- */
144
- static [Symbol.hasInstance](instance: unknown): boolean;
145
- }
146
- type Lazyable<T> = T | Lazy<T>;
147
- declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
148
- default: T extends Lazy<infer U> ? U : T;
149
- }>;
150
-
151
- type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
152
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
153
- }
154
- type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
155
- type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext> = {
156
- path?: string[] | undefined;
157
- interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap>[] | undefined;
158
- } & (object extends TInitialContext ? {
159
- context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]> | undefined;
160
- } : {
161
- context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
162
- });
163
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
164
-
165
- export { Procedure as a, Lazy as f, createProcedureClient as u, unlazy as v };
166
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureHandler as g, ProcedureConfig as h, AnyMiddleware as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
@@ -1,166 +0,0 @@
1
- import { ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
- import { DistributiveOmit, MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
-
5
- interface Context {
6
- [key: PropertyKey]: any;
7
- }
8
- type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
9
- type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
10
-
11
- type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
12
- output: TOutput;
13
- context: TOutContext;
14
- }>;
15
- type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
16
- context?: TOutContext | undefined;
17
- } : {
18
- context: TOutContext;
19
- }) & {
20
- /** Overrides the signal for the rest of the chain. */
21
- signal?: AbortSignal | undefined;
22
- };
23
- interface MiddlewareNext<TOutput> {
24
- <T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
25
- }
26
- type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
27
- context?: TOutContext | undefined;
28
- } : {
29
- context: TOutContext;
30
- }) & {
31
- output: TOutput;
32
- };
33
- interface MiddlewareDone<TOutput> {
34
- /**
35
- * Create a successful result and terminate the middleware chain early.
36
- */
37
- <TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
38
- }
39
- interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
40
- context: TInContext;
41
- path: string[];
42
- procedure: AnyProcedure;
43
- signal?: AbortSignal | undefined;
44
- lastEventId: string | undefined;
45
- /**
46
- * Invoke to continue the middleware chain.
47
- */
48
- next: MiddlewareNext<TOutput>;
49
- errors: TErrorConstructorMap;
50
- }
51
- interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
52
- errorMap?: TErrorMap | undefined;
53
- metaPlugins?: AnyMetaPlugin[] | undefined;
54
- }
55
- interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
56
- /** this property should be optional to support inline middleware */
57
- '~orpc'?: MiddlewareDefinition<TErrorMap> | undefined;
58
- (opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
59
- }
60
- type AnyMiddleware = Middleware<any, any, any, any, any>;
61
-
62
- interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
63
- context: TCurrentContext;
64
- input: TInput;
65
- path: string[];
66
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap>;
67
- signal?: AbortSignal | undefined;
68
- lastEventId?: string | undefined;
69
- errors: TErrorConstructorMap;
70
- }
71
- interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
72
- (opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Promisable<THandlerOutput>;
73
- }
74
- interface OrderedMiddleware {
75
- /**
76
- * Snapshot of `inputSchemas.length`
77
- * at the time this middleware was used.
78
- *
79
- * @default 0
80
- */
81
- inputSchemasLengthAtUse?: number | undefined;
82
- /**
83
- * Snapshot of `outputSchemas.length`
84
- * at the time this middleware was used.
85
- *
86
- * @default 0
87
- */
88
- outputSchemasLengthAtUse?: number | undefined;
89
- middleware: AnyMiddleware;
90
- }
91
- interface ProcedureConfig {
92
- /**
93
- * When enabled, input schemas are not validated at runtime.
94
- * Schemas are still used for type inference and OpenAPI generation.
95
- *
96
- * @remarks
97
- * **Warning**: Do not disable validation for schemas that transform values.
98
- *
99
- * @default false
100
- */
101
- disableInputValidation?: boolean | undefined;
102
- /**
103
- * When enabled, output schemas are not validated at runtime.
104
- * Schemas are still used for type inference and OpenAPI generation.
105
- *
106
- * Useful when output schemas exist only for specification generation.
107
- *
108
- * @remarks
109
- * **Warning**: Do not disable validation for schemas that transform values.
110
- *
111
- * @default false
112
- */
113
- disableOutputValidation?: boolean | undefined;
114
- }
115
- interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
116
- __TInitialContext?: (type: TInitialContext) => unknown;
117
- __TInjectedContext?: (type: TInjectedContext) => unknown;
118
- orderedMiddlewares: OrderedMiddleware[];
119
- handler: ProcedureHandler<any, any, any, any>;
120
- }
121
- declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
122
- '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
123
- constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>);
124
- /**
125
- * Checks if the given instance satisfies the {@link Procedure} class/interface.
126
- */
127
- static [Symbol.hasInstance](instance: unknown): boolean;
128
- }
129
- type AnyProcedure = Procedure<any, any, any, any, any>;
130
-
131
- interface LazyDefinition<T> {
132
- meta: Meta;
133
- metaPlugins?: AnyMetaPlugin[] | undefined;
134
- loader: () => Promise<{
135
- default: T;
136
- }>;
137
- }
138
- declare class Lazy<T> {
139
- '~orpc': LazyDefinition<T>;
140
- constructor(def: LazyDefinition<T>);
141
- /**
142
- * Checks if the given instance satisfies the {@link Lazy} class/interface.
143
- */
144
- static [Symbol.hasInstance](instance: unknown): boolean;
145
- }
146
- type Lazyable<T> = T | Lazy<T>;
147
- declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
148
- default: T extends Lazy<infer U> ? U : T;
149
- }>;
150
-
151
- type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
152
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
153
- }
154
- type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
155
- type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext> = {
156
- path?: string[] | undefined;
157
- interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap>[] | undefined;
158
- } & (object extends TInitialContext ? {
159
- context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]> | undefined;
160
- } : {
161
- context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
162
- });
163
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
164
-
165
- export { Procedure as a, Lazy as f, createProcedureClient as u, unlazy as v };
166
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureHandler as g, ProcedureConfig as h, AnyMiddleware as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
@@ -1,105 +0,0 @@
1
- import { AnyORPCError } from '@orpc/client';
2
- import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
3
- import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.DFPxP2v3.js';
5
- import { Schema, ErrorMap } from '@orpc/contract';
6
-
7
- interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
8
- /**
9
- * Initializes the plugin and returns new handler options.
10
- * Called once per plugin instance during composition.
11
- *
12
- * This method allows plugins to wrap, extend, or transform handler options
13
- * such as interceptors, or configuration.
14
- *
15
- * @param options - The current handler options from previous plugins or base configuration
16
- * @returns Transformed handler options with plugin's modifications applied
17
- *
18
- * @example
19
- * ```ts
20
- * init(options) {
21
- * return {
22
- * ...options,
23
- * interceptors: [...(options.interceptors || []), myInterceptor]
24
- * }
25
- * }
26
- * ```
27
- */
28
- init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
29
- }
30
-
31
- interface StandardHandlerHandleOptions<T extends Context> {
32
- prefix?: `/${string}` | undefined;
33
- /**
34
- * The initial context, or a function (sync or async) that receives the request and returns it.
35
- * The function only runs once the request passes the prefix check.
36
- */
37
- context: Value<Promisable<T>, [request: StandardLazyRequest]>;
38
- }
39
- /**
40
- * `StandardHandlerHandleOptions` after the context has been resolved,
41
- * this is what interceptors and codecs receive.
42
- */
43
- interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, 'context'> {
44
- context: T;
45
- }
46
- type StandardHandlerHandleResult = {
47
- matched: true;
48
- response: StandardResponse;
49
- } | {
50
- matched: false;
51
- response?: undefined;
52
- };
53
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
54
- request: StandardLazyRequest;
55
- }
56
- type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
57
- interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
58
- request: StandardLazyRequest;
59
- }
60
- type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
61
- interface StandardHandlerOptions<TContext extends Context> {
62
- /**
63
- * Fired on every request before routing, useful when you want
64
- * to intercept all requests regardless of whether they match a procedure or not.
65
- *
66
- * @examples
67
- * - batch plugins - separate one request into multiple and call multiple next
68
- * - openapi spec plugin - to intercept a request and early response
69
- */
70
- routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[] | undefined;
71
- /**
72
- * interceptor run after routing and before error handler,
73
- * useful for error handling, logging, metrics, etc.
74
- */
75
- interceptors?: StandardHandlerInterceptor<TContext>[] | undefined;
76
- /**
77
- *
78
- * ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
79
- * useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
80
- */
81
- clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[] | undefined;
82
- plugins?: StandardHandlerPlugin<TContext>[] | undefined;
83
- }
84
- declare class StandardHandler<T extends Context> {
85
- private readonly codec;
86
- private readonly routingInterceptors;
87
- private readonly interceptors;
88
- private readonly clientInterceptors;
89
- constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
90
- handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
91
- }
92
-
93
- interface StandardHandlerCodecResolvedProcedure {
94
- path: string[];
95
- procedure: AnyProcedure;
96
- decodeInput: () => Promise<unknown>;
97
- }
98
- interface StandardHandlerCodec<T extends Context> {
99
- resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
100
- encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
- encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
102
- }
103
-
104
- export { StandardHandler as S };
105
- export type { ResolvedStandardHandlerHandleOptions as R, StandardHandlerHandleOptions as a, StandardHandlerPlugin as b, StandardHandlerOptions as c, StandardHandlerRoutingInterceptorOptions as d, StandardHandlerInterceptorOptions as e, StandardHandlerCodec as f, StandardHandlerCodecResolvedProcedure as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
@@ -1,9 +0,0 @@
1
- function resolveFriendlyStandardHandlerHandleOptions(options) {
2
- return {
3
- ...options,
4
- context: options.context ?? {}
5
- // Context only optional if all fields are optional
6
- };
7
- }
8
-
9
- export { resolveFriendlyStandardHandlerHandleOptions as r };
@@ -1,41 +0,0 @@
1
- import { resolveMetaPlugins, mergeErrorMap, getHiddenMetaPlugins } from '@orpc/contract';
2
- import { P as Procedure } from './server.BB464y-6.mjs';
3
-
4
- class DecoratedProcedure extends Procedure {
5
- meta(...plugins) {
6
- const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
7
- return new DecoratedProcedure({
8
- ...this["~orpc"],
9
- meta,
10
- metaPlugins
11
- });
12
- }
13
- errors(errors) {
14
- let procedure = new DecoratedProcedure({
15
- ...this["~orpc"],
16
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
17
- });
18
- const plugins = getHiddenMetaPlugins(errors);
19
- if (plugins) {
20
- procedure = procedure.meta(...plugins);
21
- }
22
- return procedure;
23
- }
24
- use(middleware) {
25
- let procedure = new DecoratedProcedure({
26
- ...this["~orpc"],
27
- errorMap: mergeErrorMap(middleware["~orpc"]?.errorMap, this["~orpc"].errorMap),
28
- orderedMiddlewares: [...this["~orpc"].orderedMiddlewares, {
29
- middleware,
30
- inputSchemasLengthAtUse: this["~orpc"].inputSchemas?.length,
31
- outputSchemasLengthAtUse: this["~orpc"].outputSchemas?.length
32
- }]
33
- });
34
- if (middleware["~orpc"]?.metaPlugins) {
35
- procedure = procedure.meta(...middleware["~orpc"]?.metaPlugins);
36
- }
37
- return procedure;
38
- }
39
- }
40
-
41
- export { DecoratedProcedure as D };