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

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 (169) hide show
  1. package/README.md +2 -3
  2. package/dist/adapters/aws-lambda/handler.d.mts +25 -0
  3. package/dist/adapters/aws-lambda/handler.mjs +21 -0
  4. package/dist/adapters/aws-lambda/index.d.mts +14 -49
  5. package/dist/adapters/aws-lambda/index.mjs +2 -39
  6. package/dist/adapters/aws-lambda/rpc-handler.d.mts +18 -0
  7. package/dist/adapters/aws-lambda/rpc-handler.mjs +10 -0
  8. package/dist/adapters/crossws/handler.d.mts +41 -0
  9. package/dist/adapters/crossws/handler.mjs +38 -0
  10. package/dist/adapters/crossws/index.d.mts +2 -63
  11. package/dist/adapters/crossws/index.mjs +2 -68
  12. package/dist/adapters/crossws/rpc-handler.d.mts +15 -0
  13. package/dist/adapters/crossws/rpc-handler.mjs +10 -0
  14. package/dist/adapters/fastify/handler.d.mts +21 -0
  15. package/dist/adapters/fastify/handler.mjs +20 -0
  16. package/dist/adapters/fastify/index.d.mts +2 -42
  17. package/dist/adapters/fastify/index.mjs +2 -39
  18. package/dist/adapters/fastify/rpc-handler.d.mts +14 -0
  19. package/dist/adapters/fastify/rpc-handler.mjs +10 -0
  20. package/dist/adapters/fetch/handler.d.mts +23 -0
  21. package/dist/adapters/fetch/handler.mjs +22 -0
  22. package/dist/adapters/fetch/index.d.mts +6 -46
  23. package/dist/adapters/fetch/index.mjs +4 -41
  24. package/dist/adapters/fetch/rpc-handler.d.mts +16 -0
  25. package/dist/adapters/fetch/rpc-handler.mjs +10 -0
  26. package/dist/adapters/message-port/handler.d.mts +57 -0
  27. package/dist/adapters/message-port/handler.mjs +62 -0
  28. package/dist/adapters/message-port/index.d.mts +2 -77
  29. package/dist/adapters/message-port/index.mjs +2 -87
  30. package/dist/adapters/message-port/rpc-handler.d.mts +15 -0
  31. package/dist/adapters/message-port/rpc-handler.mjs +10 -0
  32. package/dist/adapters/node/handler.d.mts +21 -0
  33. package/dist/adapters/node/handler.mjs +20 -0
  34. package/dist/adapters/node/index.d.mts +6 -43
  35. package/dist/adapters/node/index.mjs +4 -40
  36. package/dist/adapters/node/rpc-handler.d.mts +15 -0
  37. package/dist/adapters/node/rpc-handler.mjs +10 -0
  38. package/dist/adapters/standard/codec.d.mts +16 -0
  39. package/dist/adapters/standard/codec.mjs +1 -0
  40. package/dist/adapters/standard/handler.d.mts +68 -0
  41. package/dist/adapters/standard/handler.mjs +185 -0
  42. package/dist/adapters/standard/index.d.mts +6 -95
  43. package/dist/adapters/standard/index.mjs +5 -8
  44. package/dist/adapters/standard/plugin.d.mts +32 -0
  45. package/dist/adapters/standard/plugin.mjs +16 -0
  46. package/dist/adapters/standard/rpc-handler-codec.d.mts +42 -0
  47. package/dist/adapters/standard/rpc-handler-codec.mjs +51 -0
  48. package/dist/adapters/standard/rpc-matcher.d.mts +53 -0
  49. package/dist/adapters/standard/rpc-matcher.mjs +140 -0
  50. package/dist/adapters/standard/utils.d.mts +10 -0
  51. package/dist/adapters/standard/utils.mjs +6 -0
  52. package/dist/adapters/standard-peer/index.d.mts +1 -11
  53. package/dist/adapters/standard-peer/index.mjs +1 -10
  54. package/dist/adapters/standard-peer/utils.d.mts +4 -0
  55. package/dist/adapters/standard-peer/utils.mjs +11 -0
  56. package/dist/adapters/websocket/handler.d.mts +55 -0
  57. package/dist/adapters/websocket/handler.mjs +55 -0
  58. package/dist/adapters/websocket/index.d.mts +2 -77
  59. package/dist/adapters/websocket/index.mjs +2 -87
  60. package/dist/adapters/websocket/rpc-handler.d.mts +15 -0
  61. package/dist/adapters/websocket/rpc-handler.mjs +10 -0
  62. package/dist/builder-variants.d.mts +267 -0
  63. package/dist/builder-variants.mjs +1 -0
  64. package/dist/builder.d.mts +141 -0
  65. package/dist/builder.mjs +145 -0
  66. package/dist/constants.d.mts +2 -0
  67. package/dist/constants.mjs +2 -0
  68. package/dist/context.d.mts +13 -0
  69. package/dist/context.mjs +1 -0
  70. package/dist/extensions/callable.d.mts +16 -9
  71. package/dist/extensions/callable.mjs +5 -9
  72. package/dist/helpers/base64url.d.mts +31 -0
  73. package/dist/helpers/base64url.mjs +25 -0
  74. package/dist/helpers/cookie.d.mts +50 -0
  75. package/dist/helpers/cookie.mjs +35 -0
  76. package/dist/helpers/encryption.d.mts +28 -0
  77. package/dist/helpers/encryption.mjs +62 -0
  78. package/dist/helpers/index.d.mts +4 -167
  79. package/dist/helpers/index.mjs +4 -200
  80. package/dist/helpers/signing.d.mts +50 -0
  81. package/dist/helpers/signing.mjs +43 -0
  82. package/dist/implementer-procedure.d.mts +36 -0
  83. package/dist/implementer-procedure.mjs +38 -0
  84. package/dist/implementer-router.d.mts +78 -0
  85. package/dist/implementer-router.mjs +77 -0
  86. package/dist/implementer.d.mts +22 -0
  87. package/dist/implementer.mjs +30 -0
  88. package/dist/index.d.mts +57 -476
  89. package/dist/index.mjs +25 -458
  90. package/dist/lazy.d.mts +20 -0
  91. package/dist/lazy.mjs +22 -0
  92. package/dist/middleware-decorated.d.mts +27 -0
  93. package/dist/middleware-decorated.mjs +65 -0
  94. package/dist/middleware.d.mts +70 -0
  95. package/dist/middleware.mjs +1 -0
  96. package/dist/plugins/batch.d.mts +104 -0
  97. package/dist/plugins/batch.mjs +373 -0
  98. package/dist/plugins/cors.d.mts +67 -0
  99. package/dist/plugins/cors.mjs +134 -0
  100. package/dist/plugins/get-method-csrf-protection.d.mts +23 -0
  101. package/dist/plugins/get-method-csrf-protection.mjs +45 -0
  102. package/dist/plugins/head-method.d.mts +23 -0
  103. package/dist/plugins/head-method.mjs +95 -0
  104. package/dist/plugins/index.d.mts +39 -432
  105. package/dist/plugins/index.mjs +23 -965
  106. package/dist/plugins/method-override.d.mts +38 -0
  107. package/dist/plugins/method-override.mjs +50 -0
  108. package/dist/plugins/request-compression.d.mts +16 -0
  109. package/dist/plugins/request-compression.mjs +67 -0
  110. package/dist/plugins/request-headers.d.mts +22 -0
  111. package/dist/plugins/request-headers.mjs +21 -0
  112. package/dist/plugins/request-limit.d.mts +30 -0
  113. package/dist/plugins/request-limit.mjs +53 -0
  114. package/dist/plugins/response-compression.d.mts +59 -0
  115. package/dist/plugins/response-compression.mjs +172 -0
  116. package/dist/plugins/response-headers.d.mts +30 -0
  117. package/dist/plugins/response-headers.mjs +34 -0
  118. package/dist/plugins/rethrow.d.mts +33 -0
  119. package/dist/plugins/rethrow.mjs +46 -0
  120. package/dist/plugins/signal-sync.d.mts +13 -0
  121. package/dist/plugins/signal-sync.mjs +84 -0
  122. package/dist/plugins/timeout.d.mts +37 -0
  123. package/dist/plugins/timeout.mjs +56 -0
  124. package/dist/procedure-client.d.mts +41 -0
  125. package/dist/procedure-client.mjs +157 -0
  126. package/dist/procedure-decorated.d.mts +20 -0
  127. package/dist/procedure-decorated.mjs +41 -0
  128. package/dist/procedure-utils.d.mts +52 -0
  129. package/dist/procedure-utils.mjs +33 -0
  130. package/dist/procedure.d.mts +93 -0
  131. package/dist/procedure.mjs +20 -0
  132. package/dist/router-client.d.mts +27 -0
  133. package/dist/router-client.mjs +35 -0
  134. package/dist/router-hidden.d.mts +5 -0
  135. package/dist/router-hidden.mjs +12 -0
  136. package/dist/router-utils.d.mts +59 -0
  137. package/dist/router-utils.mjs +191 -0
  138. package/dist/router.d.mts +61 -0
  139. package/dist/router.mjs +1 -0
  140. package/package.json +11 -11
  141. package/dist/adapters/aws-lambda/index.d.ts +0 -51
  142. package/dist/adapters/crossws/index.d.ts +0 -63
  143. package/dist/adapters/fastify/index.d.ts +0 -42
  144. package/dist/adapters/fetch/index.d.ts +0 -47
  145. package/dist/adapters/message-port/index.d.ts +0 -77
  146. package/dist/adapters/node/index.d.ts +0 -44
  147. package/dist/adapters/standard/index.d.ts +0 -95
  148. package/dist/adapters/standard-peer/index.d.ts +0 -11
  149. package/dist/adapters/websocket/index.d.ts +0 -77
  150. package/dist/extensions/callable.d.ts +0 -10
  151. package/dist/helpers/index.d.ts +0 -167
  152. package/dist/index.d.ts +0 -476
  153. package/dist/plugins/index.d.ts +0 -432
  154. package/dist/shared/server.1ExWFMze.mjs +0 -69
  155. package/dist/shared/server.9B1jEm5a.d.mts +0 -105
  156. package/dist/shared/server.BB464y-6.mjs +0 -207
  157. package/dist/shared/server.BC5BIu02.d.mts +0 -73
  158. package/dist/shared/server.BSYGskId.d.ts +0 -14
  159. package/dist/shared/server.BvG3boBj.d.mts +0 -14
  160. package/dist/shared/server.CTV_mC2P.d.mts +0 -34
  161. package/dist/shared/server.CYbIpHbH.mjs +0 -239
  162. package/dist/shared/server.CgBF3Vj1.d.ts +0 -34
  163. package/dist/shared/server.Chq5FpXf.mjs +0 -353
  164. package/dist/shared/server.DFPxP2v3.d.mts +0 -166
  165. package/dist/shared/server.DFPxP2v3.d.ts +0 -166
  166. package/dist/shared/server.DOg7ke6y.d.ts +0 -105
  167. package/dist/shared/server.Dz7j9BEh.d.ts +0 -73
  168. package/dist/shared/server.W91HSRkE.mjs +0 -9
  169. package/dist/shared/server.sBQSgqK3.mjs +0 -41
@@ -0,0 +1,267 @@
1
+ import type { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, MetaPlugin, ORPCErrorConstructorMap, Schema } from "@orpc/contract";
2
+ import type { IntersectPick } from "@orpc/shared";
3
+ import type { BuilderDefinition } from "./builder.mjs";
4
+ import type { Context, MergedContext, MergedInitialContext } from "./context.mjs";
5
+ import type { Lazy } from "./lazy.mjs";
6
+ import type { Middleware } from "./middleware.mjs";
7
+ import type { DecoratedMiddleware } from "./middleware-decorated.mjs";
8
+ import type { ProcedureHandler } from "./procedure.mjs";
9
+ import type { DecoratedProcedure } from "./procedure-decorated.mjs";
10
+ import type { Router } from "./router.mjs";
11
+ import type { AugmentedRouterWithMiddlewares } from "./router-utils.mjs";
12
+ /**
13
+ * The builder variant returned after `.use` is called.
14
+ * `.$context` and `.$config` are no longer available once middleware is applied.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
17
+ */
18
+ export interface BuilderWithMiddlewares<
19
+ TInitialContext extends Context,
20
+ TInjectedContext extends Context,
21
+ TErrorMap extends ErrorMap
22
+ > {
23
+ "~orpc": BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
24
+ /**
25
+ * Applies metadata plugins to procedures built from this builder.
26
+ *
27
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
28
+ */
29
+ "meta"(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
30
+ /**
31
+ * Defines typesafe errors that procedures built from this builder can throw
32
+ * via the `errors` utility in handlers and middleware.
33
+ *
34
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
35
+ */
36
+ "errors"<T extends ErrorMap>(errors: T): BuilderWithMiddlewares<TInitialContext, TInjectedContext, MergedErrorMap<TErrorMap, T>>;
37
+ /**
38
+ * Applies a middleware that runs before the handler of every procedure
39
+ * built from this builder.
40
+ *
41
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
42
+ */
43
+ "use"<
44
+ $OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
45
+ $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
46
+ $ErrorMap extends ErrorMap = TErrorMap
47
+ >(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, MergedErrorMap<$ErrorMap, TErrorMap>>;
48
+ /**
49
+ * Creates a standalone middleware that can be composed and applied to any
50
+ * compatible builder or procedure with `.use`.
51
+ *
52
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
53
+ */
54
+ "middleware"<
55
+ $OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
56
+ $Input,
57
+ $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
58
+ $Output = any
59
+ >(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, $Input, $Output, TErrorMap>;
60
+ /**
61
+ * Defines the input schema used to validate and type the procedure input.
62
+ *
63
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
64
+ */
65
+ "input"<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, T, TErrorMap>;
66
+ /**
67
+ * Defines the output schema used to validate and type the procedure output.
68
+ *
69
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
70
+ */
71
+ "output"<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, T, TErrorMap>;
72
+ /**
73
+ * Defines the function that implements the procedure and completes the
74
+ * chain, returning a callable procedure.
75
+ *
76
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
77
+ */
78
+ "handler"<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<T>, TErrorMap>;
79
+ /**
80
+ * Applies the builder's middleware, errors, and metadata to every procedure
81
+ * in the given router.
82
+ *
83
+ * @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
84
+ */
85
+ "router"<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(router: T): AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>;
86
+ /**
87
+ * Like `.router`, but loads the router lazily on first access, which helps
88
+ * reduce startup time for large applications.
89
+ *
90
+ * @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
91
+ */
92
+ "lazy"<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(loader: () => Promise<{
93
+ default: T;
94
+ }>): Lazy<AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>>;
95
+ }
96
+ /**
97
+ * The builder variant returned after `.input` is called.
98
+ * Only procedure-level methods remain available once an input schema is defined.
99
+ *
100
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
101
+ */
102
+ export interface BuilderWithInput<
103
+ TInitialContext extends Context,
104
+ TInjectedContext extends Context,
105
+ TInputSchema extends AnySchema,
106
+ TErrorMap extends ErrorMap
107
+ > {
108
+ "~orpc": BuilderDefinition<TInputSchema, InitialOutputSchema, TErrorMap>;
109
+ /**
110
+ * Applies metadata plugins to procedures built from this builder.
111
+ *
112
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
113
+ */
114
+ "meta"(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
115
+ /**
116
+ * Defines typesafe errors that procedures built from this builder can throw
117
+ * via the `errors` utility in handlers and middleware.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
120
+ */
121
+ "errors"<T extends ErrorMap>(errors: T): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, MergedErrorMap<TErrorMap, T>>;
122
+ /**
123
+ * Applies a middleware that runs before the handler and can access the
124
+ * validated input.
125
+ *
126
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
127
+ */
128
+ "use"<
129
+ $OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
130
+ $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
131
+ $ErrorMap extends ErrorMap = TErrorMap
132
+ >(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithInput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
133
+ /**
134
+ * Adds an additional input schema, merged with the previously defined one.
135
+ *
136
+ * @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
137
+ */
138
+ "input"<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TErrorMap>;
139
+ /**
140
+ * Defines the output schema used to validate and type the procedure output.
141
+ *
142
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
143
+ */
144
+ "output"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, T, TErrorMap>;
145
+ /**
146
+ * Defines the function that implements the procedure and completes the
147
+ * chain, returning a callable procedure.
148
+ *
149
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
150
+ */
151
+ "handler"<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<T>, TErrorMap>;
152
+ }
153
+ /**
154
+ * The builder variant returned after `.output` is called.
155
+ * Only procedure-level methods remain available once an output schema is defined.
156
+ *
157
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
158
+ */
159
+ export interface BuilderWithOutput<
160
+ TInitialContext extends Context,
161
+ TInjectedContext extends Context,
162
+ TOutputSchema extends AnySchema,
163
+ TErrorMap extends ErrorMap
164
+ > {
165
+ "~orpc": BuilderDefinition<InitialInputSchema, TOutputSchema, TErrorMap>;
166
+ /**
167
+ * Applies metadata plugins to procedures built from this builder.
168
+ *
169
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
170
+ */
171
+ "meta"(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
172
+ /**
173
+ * Defines typesafe errors that procedures built from this builder can throw
174
+ * via the `errors` utility in handlers and middleware.
175
+ *
176
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
177
+ */
178
+ "errors"<T extends ErrorMap>(errors: T): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
179
+ /**
180
+ * Applies a middleware that runs before the handler and can access the
181
+ * typed output.
182
+ *
183
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
184
+ */
185
+ "use"<
186
+ $OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
187
+ $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
188
+ $ErrorMap extends ErrorMap = TErrorMap
189
+ >(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
190
+ /**
191
+ * Defines the input schema used to validate and type the procedure input.
192
+ *
193
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
194
+ */
195
+ "input"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, T, TOutputSchema, TErrorMap>;
196
+ /**
197
+ * Adds an additional output schema, merged with the previously defined one.
198
+ *
199
+ * @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
200
+ */
201
+ "output"<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, MergedSchema<T, TOutputSchema>, TErrorMap>;
202
+ /**
203
+ * Defines the function that implements the procedure and completes the
204
+ * chain, returning a callable procedure.
205
+ *
206
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
207
+ */
208
+ "handler"<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap>;
209
+ }
210
+ /**
211
+ * The builder variant returned after both `.input` and `.output` are called.
212
+ * Only procedure-level methods remain available.
213
+ *
214
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
215
+ */
216
+ export interface BuilderWithInputOutput<
217
+ TInitialContext extends Context,
218
+ TInjectedContext extends Context,
219
+ TInputSchema extends AnySchema,
220
+ TOutputSchema extends AnySchema,
221
+ TErrorMap extends ErrorMap
222
+ > {
223
+ "~orpc": BuilderDefinition<TInputSchema, TOutputSchema, TErrorMap>;
224
+ /**
225
+ * Applies metadata plugins to procedures built from this builder.
226
+ *
227
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
228
+ */
229
+ "meta"(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
230
+ /**
231
+ * Defines typesafe errors that procedures built from this builder can throw
232
+ * via the `errors` utility in handlers and middleware.
233
+ *
234
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
235
+ */
236
+ "errors"<T extends ErrorMap>(errors: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
237
+ /**
238
+ * Applies a middleware that runs before the handler and can access the
239
+ * validated input and typed output.
240
+ *
241
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
242
+ */
243
+ "use"<
244
+ $OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
245
+ $InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
246
+ $ErrorMap extends ErrorMap = TErrorMap
247
+ >(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithInputOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
248
+ /**
249
+ * Adds an additional input schema, merged with the previously defined one.
250
+ *
251
+ * @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
252
+ */
253
+ "input"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
254
+ /**
255
+ * Adds an additional output schema, merged with the previously defined one.
256
+ *
257
+ * @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
258
+ */
259
+ "output"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
260
+ /**
261
+ * Defines the function that implements the procedure and completes the
262
+ * chain, returning a callable procedure.
263
+ *
264
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
265
+ */
266
+ "handler"<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
267
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
1
+ import type { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MetaPlugin, ORPCErrorConstructorMap, ProcedureContractDefinition, Schema } from "@orpc/contract";
2
+ import type { IntersectPick } from "@orpc/shared";
3
+ import type { BuilderWithInput, BuilderWithMiddlewares, BuilderWithOutput } from "./builder-variants.mjs";
4
+ import type { Context, MergedInitialContext } from "./context.mjs";
5
+ import type { Middleware } from "./middleware.mjs";
6
+ import type { DecoratedMiddleware } from "./middleware-decorated.mjs";
7
+ import type { OrderedMiddleware, ProcedureConfig, ProcedureHandler } from "./procedure.mjs";
8
+ import type { AnyRouter } from "./router.mjs";
9
+ import type { AugmentedRouter } from "./router-utils.mjs";
10
+ import { Lazy } from "./lazy.mjs";
11
+ import { DecoratedProcedure } from "./procedure-decorated.mjs";
12
+ /**
13
+ * The initial context type used when `.$context` is not called.
14
+ * Augment this interface with `declare module '@orpc/server'` to define
15
+ * a default initial context type globally.
16
+ *
17
+ * @see {@link https://orpc.dev/docs/context#default-initial-context | Context - Default Initial Context}
18
+ */
19
+ export interface DefaultInitialContext {}
20
+ export interface BuilderDefinition<
21
+ TInputSchema extends AnySchema,
22
+ TInjectedContext extends AnySchema,
23
+ TErrorMap extends ErrorMap
24
+ > extends ProcedureContractDefinition<TInputSchema, TInjectedContext, TErrorMap>, ProcedureConfig {
25
+ orderedMiddlewares: OrderedMiddleware[];
26
+ }
27
+ /**
28
+ * The procedure builder behind `os`. Chain its methods to gradually define
29
+ * context, middleware, errors, schemas, and finally a handler or router.
30
+ *
31
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
32
+ */
33
+ export declare class Builder<
34
+ TInitialContext extends Context,
35
+ TErrorMap extends ErrorMap
36
+ > {
37
+ "~orpc": BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
38
+ /**
39
+ * Private constructor to prevent direct instantiation.
40
+ * Use the static `create` method to initialize a new instance with a safe initial definition.
41
+ */
42
+ private constructor();
43
+ /**
44
+ * Creates a fresh builder with an empty definition.
45
+ * Prefer the exported `os` instance over calling this directly.
46
+ *
47
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
48
+ */
49
+ static create<T extends Context = DefaultInitialContext>(): Builder<T & object, Record<never, never>>;
50
+ /**
51
+ * Declares the initial context type that must be provided when executing
52
+ * procedures built from this builder.
53
+ *
54
+ * @see {@link https://orpc.dev/docs/context#initial-context | Context - Initial Context}
55
+ */
56
+ $context<T extends Context = DefaultInitialContext>(): Builder<T & object, TErrorMap>;
57
+ /**
58
+ * Overrides the procedure configuration, such as disabling runtime
59
+ * input/output validation.
60
+ *
61
+ * @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
62
+ */
63
+ $config(config: ProcedureConfig): Builder<TInitialContext, TErrorMap>;
64
+ /**
65
+ * Applies metadata plugins to procedures built from this builder.
66
+ *
67
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
68
+ */
69
+ meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): Builder<TInitialContext, TErrorMap>;
70
+ /**
71
+ * Defines typesafe errors that procedures built from this builder can throw
72
+ * via the `errors` utility in handlers and middleware.
73
+ *
74
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
75
+ */
76
+ errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, MergedErrorMap<TErrorMap, U>>;
77
+ /**
78
+ * Applies a middleware that runs before the handler of every procedure
79
+ * built from this builder.
80
+ *
81
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
82
+ */
83
+ use<
84
+ $OutContext extends IntersectPick<TInitialContext, $OutContext>,
85
+ $InContext extends Context = TInitialContext,
86
+ $ErrorMap extends ErrorMap = TErrorMap
87
+ >(middleware: Middleware<$InContext | TInitialContext, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, object, $InContext>, $OutContext, MergedErrorMap<$ErrorMap, TErrorMap>>;
88
+ /**
89
+ * Creates a standalone middleware that can be composed and applied to any
90
+ * compatible builder or procedure with `.use`.
91
+ *
92
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
93
+ */
94
+ middleware<
95
+ $OutContext extends IntersectPick<TInitialContext, $OutContext>,
96
+ $Input,
97
+ $Output = any
98
+ >(middleware: Middleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>;
99
+ /**
100
+ * Defines the input schema used to validate and type the procedure input.
101
+ *
102
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
103
+ */
104
+ input<$ extends AnySchema>(schema: $): BuilderWithInput<TInitialContext, object, $, TErrorMap>;
105
+ /**
106
+ * Defines the output schema used to validate and type the procedure output.
107
+ *
108
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
109
+ */
110
+ output<$ extends AnySchema>(schema: $): BuilderWithOutput<TInitialContext, object, $, TErrorMap>;
111
+ /**
112
+ * Defines the function that implements the procedure and completes the
113
+ * chain, returning a callable procedure.
114
+ *
115
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
116
+ */
117
+ handler<T>(handler: ProcedureHandler<TInitialContext, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<T>, TErrorMap>;
118
+ /**
119
+ * Applies the builder's middleware, errors, and metadata to every procedure
120
+ * in the given router.
121
+ *
122
+ * @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
123
+ */
124
+ router<T extends AnyRouter>(router: T): AugmentedRouter<T, TErrorMap>;
125
+ /**
126
+ * Like `.router`, but loads the router lazily on first access, which helps
127
+ * reduce startup time for large applications.
128
+ *
129
+ * @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
130
+ */
131
+ lazy<T extends AnyRouter>(loader: () => Promise<{
132
+ default: T;
133
+ }>): Lazy<AugmentedRouter<T, TErrorMap>>;
134
+ }
135
+ /**
136
+ * The oRPC procedure builder. Chain methods like `.input`, `.use`, and `.handler`
137
+ * to define procedures, then compose them into routers.
138
+ *
139
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
140
+ */
141
+ export declare const os: Builder<DefaultInitialContext & object, Record<never, never>>;
@@ -0,0 +1,145 @@
1
+ import { getHiddenMetaPlugins, mergeErrorMap, resolveMetaPlugins } from "@orpc/contract";
2
+ import { toArray } from "@orpc/shared";
3
+ import { Lazy } from "./lazy.mjs";
4
+ import { decorateMiddleware } from "./middleware-decorated.mjs";
5
+ import { DecoratedProcedure } from "./procedure-decorated.mjs";
6
+ import { augmentRouter } from "./router-utils.mjs";
7
+
8
+ export class Builder {
9
+ "~orpc";
10
+
11
+ constructor(definition) {
12
+ this["~orpc"] = definition;
13
+ }
14
+
15
+ static create() {
16
+
17
+
18
+ return new Builder({
19
+ errorMap: {},
20
+ meta: {},
21
+ orderedMiddlewares: []
22
+ });
23
+ }
24
+
25
+ $context() {
26
+
27
+
28
+
29
+ return this;
30
+ }
31
+
32
+ $config(config) {
33
+ return new Builder({
34
+ ...this["~orpc"],
35
+ ...config
36
+ });
37
+ }
38
+
39
+ meta(...plugins) {
40
+ const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
41
+ return new Builder({
42
+ ...this["~orpc"],
43
+ meta,
44
+ metaPlugins
45
+ });
46
+ }
47
+
48
+ errors(errors) {
49
+ let builder = new Builder({
50
+ ...this["~orpc"],
51
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
52
+ });
53
+ const plugins = getHiddenMetaPlugins(errors);
54
+ if (plugins) {
55
+ builder = builder.meta(...plugins);
56
+ }
57
+ return builder;
58
+ }
59
+
60
+ use(middleware) {
61
+ let builder = new Builder({
62
+ ...this["~orpc"],
63
+ errorMap: mergeErrorMap(middleware["~orpc"]?.errorMap ?? {}, this["~orpc"].errorMap),
64
+ orderedMiddlewares: [...this["~orpc"].orderedMiddlewares, {
65
+ middleware,
66
+ inputSchemasLengthAtUse: this["~orpc"].inputSchemas?.length,
67
+ outputSchemasLengthAtUse: this["~orpc"].outputSchemas?.length
68
+ }]
69
+ });
70
+ if (middleware["~orpc"]?.metaPlugins) {
71
+ builder = builder.meta(...middleware["~orpc"]?.metaPlugins);
72
+ }
73
+ return builder;
74
+ }
75
+
76
+ middleware(middleware) {
77
+ const allMiddlewares = [...this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware), middleware];
78
+ let current = decorateMiddleware(allMiddlewares.shift());
79
+ for (const mid of allMiddlewares) {
80
+ current = current.use(mid);
81
+ }
82
+ current["~orpc"] = {
83
+ ...current["~orpc"],
84
+ errorMap: this["~orpc"].errorMap,
85
+ metaPlugins: [...toArray(this["~orpc"].metaPlugins), ...toArray(middleware["~orpc"]?.metaPlugins)]
86
+ };
87
+ return current;
88
+ }
89
+
90
+ input(schema) {
91
+ let builder = new Builder({
92
+ ...this["~orpc"],
93
+ inputSchemas: [...toArray(this["~orpc"].inputSchemas), schema]
94
+ });
95
+ const plugins = getHiddenMetaPlugins(schema);
96
+ if (plugins) {
97
+ builder = builder.meta(...plugins);
98
+ }
99
+ return builder;
100
+ }
101
+
102
+ output(schema) {
103
+ let builder = new Builder({
104
+ ...this["~orpc"],
105
+ outputSchemas: [...toArray(this["~orpc"].outputSchemas), schema]
106
+ });
107
+ const plugins = getHiddenMetaPlugins(schema);
108
+ if (plugins) {
109
+ builder = builder.meta(...plugins);
110
+ }
111
+ return builder;
112
+ }
113
+
114
+ handler(handler) {
115
+ let procedure = new DecoratedProcedure({
116
+ ...this["~orpc"],
117
+ handler
118
+ });
119
+ const plugins = getHiddenMetaPlugins(handler);
120
+ if (plugins) {
121
+ procedure = procedure.meta(...plugins);
122
+ }
123
+ return procedure;
124
+ }
125
+
126
+ router(router) {
127
+ return augmentRouter(router, {
128
+ ...this["~orpc"],
129
+ middlewares: this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware)
130
+ });
131
+ }
132
+
133
+ lazy(loader) {
134
+ return new Lazy({
135
+ loader: async () => {
136
+ const { default: router } = await loader();
137
+ return { default: this.router(router) };
138
+ },
139
+ meta: this["~orpc"].meta,
140
+ metaPlugins: this["~orpc"].metaPlugins
141
+ });
142
+ }
143
+ }
144
+
145
+ export const os = /* @__PURE__ */ Builder.create();
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_SUCCESS_STATUS = 200;
2
+ export declare const DEFAULT_ERROR_STATUS = 400;
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_SUCCESS_STATUS = 200;
2
+ export const DEFAULT_ERROR_STATUS = 400;
@@ -0,0 +1,13 @@
1
+ import type { DistributiveOmit } from "@orpc/shared";
2
+ export interface Context {
3
+ [key: PropertyKey]: any;
4
+ }
5
+ export type MergedInitialContext<
6
+ TInitial extends Context,
7
+ TOutContext extends Context,
8
+ TInContext extends Context
9
+ > = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
10
+ export type MergedContext<
11
+ TCurrent extends Context,
12
+ TOutContext extends Context
13
+ > = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,17 @@
1
- import { ClientContext } from '@orpc/client';
2
- import { AnySchema, ErrorMap } from '@orpc/contract';
3
- import { MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context, ProcedureClientOptions, Procedure, ProcedureClient } from '../index.mjs';
5
-
6
- declare module '@orpc/server' {
7
- interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
8
- callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
9
- }
1
+ import type { ClientContext } from "@orpc/client";
2
+ import type { AnySchema, ErrorMap } from "@orpc/contract";
3
+ import type { MaybeOptionalOptions } from "@orpc/shared";
4
+ import type { Context } from "../context.mjs";
5
+ import type { Procedure } from "../procedure.mjs";
6
+ import type { ProcedureClient, ProcedureClientOptions } from "../procedure-client.mjs";
7
+ declare module "@orpc/server" {
8
+ interface DecoratedProcedure<
9
+ TInitialContext extends Context,
10
+ TInjectedContext extends Context,
11
+ TInputSchema extends AnySchema,
12
+ TOutputSchema extends AnySchema,
13
+ TErrorMap extends ErrorMap
14
+ > {
15
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
16
+ }
10
17
  }
@@ -1,11 +1,7 @@
1
- import { c as createProcedureClient } from '../shared/server.BB464y-6.mjs';
2
- import { D as DecoratedProcedure } from '../shared/server.sBQSgqK3.mjs';
3
- import '@orpc/client';
4
- import '@orpc/contract';
5
- import '@orpc/shared';
6
-
1
+ import { createProcedureClient } from "../procedure-client.mjs";
2
+ import { DecoratedProcedure } from "../procedure-decorated.mjs";
7
3
  DecoratedProcedure.prototype.callable = function callable(...rest) {
8
- const callable2 = createProcedureClient(this, ...rest);
9
- callable2["~orpc"] = this["~orpc"];
10
- return callable2;
4
+ const callable = createProcedureClient(this, ...rest);
5
+ callable["~orpc"] = this["~orpc"];
6
+ return callable;
11
7
  };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Encodes a Uint8Array to base64url format
3
+ * Base64url is URL-safe and doesn't use padding
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const text = "Hello World"
8
+ * const encoded = encodeBase64url(new TextEncoder().encode(text))
9
+ * const decoded = decodeBase64url(encoded)
10
+ * expect(new TextDecoder().decode(decoded)).toEqual(text)
11
+ * ```
12
+ *
13
+ * @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
14
+ */
15
+ export declare function encodeBase64url(data: Uint8Array): string;
16
+ /**
17
+ * Decodes a base64url string to Uint8Array
18
+ * Only accepts canonical, unpadded base64url (the form produced by `encodeBase64url`),
19
+ * returns undefined for anything else, including padded or standard base64 input
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const text = "Hello World"
24
+ * const encoded = encodeBase64url(new TextEncoder().encode(text))
25
+ * const decoded = decodeBase64url(encoded)
26
+ * expect(new TextDecoder().decode(decoded)).toEqual(text)
27
+ * ```
28
+ *
29
+ * @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
30
+ */
31
+ export declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;