@orpc/server 1.0.0-beta.6 → 1.0.3

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 (34) hide show
  1. package/README.md +13 -17
  2. package/dist/adapters/fetch/index.d.mts +17 -5
  3. package/dist/adapters/fetch/index.d.ts +17 -5
  4. package/dist/adapters/fetch/index.mjs +101 -7
  5. package/dist/adapters/node/index.d.mts +17 -5
  6. package/dist/adapters/node/index.d.ts +17 -5
  7. package/dist/adapters/node/index.mjs +2 -2
  8. package/dist/adapters/standard/index.d.mts +4 -4
  9. package/dist/adapters/standard/index.d.ts +4 -4
  10. package/dist/adapters/standard/index.mjs +2 -2
  11. package/dist/index.d.mts +545 -7
  12. package/dist/index.d.ts +545 -7
  13. package/dist/index.mjs +114 -6
  14. package/dist/plugins/index.d.mts +35 -3
  15. package/dist/plugins/index.d.ts +35 -3
  16. package/dist/plugins/index.mjs +9 -1
  17. package/dist/shared/{server.DCQgF_JR.d.mts → server.CN0534_m.d.mts} +4 -3
  18. package/dist/shared/{server._2UufoXA.d.ts → server.CjlA3NKP.d.ts} +2 -2
  19. package/dist/shared/{server.C8NkqxHo.d.ts → server.CuD15qZB.d.ts} +4 -3
  20. package/dist/shared/{server.DFFT_EZo.d.ts → server.D5fBlF9j.d.ts} +13 -12
  21. package/dist/shared/{server.C37gDhSZ.mjs → server.DG7Tamti.mjs} +3 -0
  22. package/dist/shared/{server.DLt5njUb.d.mts → server.DPWk5pjW.d.mts} +54 -5
  23. package/dist/shared/{server.DLt5njUb.d.ts → server.DPWk5pjW.d.ts} +54 -5
  24. package/dist/shared/{server.DOYDVeMX.d.mts → server.DY7OKEoj.d.mts} +13 -12
  25. package/dist/shared/{server.CGCwEAt_.d.mts → server.DjgtLwKi.d.mts} +2 -2
  26. package/dist/shared/{server.DFuJLDuo.mjs → server.qf03T-Xn.mjs} +1 -1
  27. package/package.json +8 -22
  28. package/dist/adapters/hono/index.d.mts +0 -22
  29. package/dist/adapters/hono/index.d.ts +0 -22
  30. package/dist/adapters/hono/index.mjs +0 -35
  31. package/dist/adapters/next/index.d.mts +0 -29
  32. package/dist/adapters/next/index.d.ts +0 -29
  33. package/dist/adapters/next/index.mjs +0 -32
  34. package/dist/shared/server.Bm0UqHzd.mjs +0 -103
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
2
2
  export { ValidationError, eventIterator, type } from '@orpc/contract';
3
- import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.C37gDhSZ.mjs';
4
- export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.C37gDhSZ.mjs';
3
+ import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.DG7Tamti.mjs';
4
+ export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.DG7Tamti.mjs';
5
5
  import { toORPCError } from '@orpc/client';
6
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
7
  export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
@@ -57,18 +57,38 @@ function createActionableClient(client) {
57
57
  }
58
58
 
59
59
  class DecoratedProcedure extends Procedure {
60
+ /**
61
+ * Adds type-safe custom errors.
62
+ * The provided errors are spared-merged with any existing errors.
63
+ *
64
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
65
+ */
60
66
  errors(errors) {
61
67
  return new DecoratedProcedure({
62
68
  ...this["~orpc"],
63
69
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
64
70
  });
65
71
  }
72
+ /**
73
+ * Sets or updates the metadata.
74
+ * The provided metadata is spared-merged with any existing metadata.
75
+ *
76
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
77
+ */
66
78
  meta(meta) {
67
79
  return new DecoratedProcedure({
68
80
  ...this["~orpc"],
69
81
  meta: mergeMeta(this["~orpc"].meta, meta)
70
82
  });
71
83
  }
84
+ /**
85
+ * Sets or updates the route definition.
86
+ * The provided route is spared-merged with any existing route.
87
+ * This option is typically relevant when integrating with OpenAPI.
88
+ *
89
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
90
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
91
+ */
72
92
  route(route) {
73
93
  return new DecoratedProcedure({
74
94
  ...this["~orpc"],
@@ -84,6 +104,8 @@ class DecoratedProcedure extends Procedure {
84
104
  }
85
105
  /**
86
106
  * Make this procedure callable (works like a function while still being a procedure).
107
+ *
108
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
87
109
  */
88
110
  callable(...rest) {
89
111
  const client = createProcedureClient(this, ...rest);
@@ -98,6 +120,8 @@ class DecoratedProcedure extends Procedure {
98
120
  }
99
121
  /**
100
122
  * Make this procedure compatible with server action.
123
+ *
124
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
101
125
  */
102
126
  actionable(...rest) {
103
127
  const action = createActionableClient(createProcedureClient(this, ...rest));
@@ -113,12 +137,18 @@ class DecoratedProcedure extends Procedure {
113
137
  }
114
138
 
115
139
  class Builder {
140
+ /**
141
+ * This property holds the defined options.
142
+ */
116
143
  "~orpc";
117
144
  constructor(def) {
118
145
  this["~orpc"] = def;
119
146
  }
120
147
  /**
121
- * Reset config
148
+ * Sets or overrides the config.
149
+ *
150
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
151
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
122
152
  */
123
153
  $config(config) {
124
154
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -132,7 +162,9 @@ class Builder {
132
162
  });
133
163
  }
134
164
  /**
135
- * Reset initial context
165
+ * Set or override the initial context.
166
+ *
167
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
136
168
  */
137
169
  $context() {
138
170
  return new Builder({
@@ -143,7 +175,9 @@ class Builder {
143
175
  });
144
176
  }
145
177
  /**
146
- * Reset initial meta
178
+ * Sets or overrides the initial meta.
179
+ *
180
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
147
181
  */
148
182
  $meta(initialMeta) {
149
183
  return new Builder({
@@ -152,7 +186,11 @@ class Builder {
152
186
  });
153
187
  }
154
188
  /**
155
- * Reset initial route
189
+ * Sets or overrides the initial route.
190
+ * This option is typically relevant when integrating with OpenAPI.
191
+ *
192
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
193
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
156
194
  */
157
195
  $route(initialRoute) {
158
196
  return new Builder({
@@ -160,15 +198,31 @@ class Builder {
160
198
  route: initialRoute
161
199
  });
162
200
  }
201
+ /**
202
+ * Sets or overrides the initial input schema.
203
+ *
204
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
205
+ */
163
206
  $input(initialInputSchema) {
164
207
  return new Builder({
165
208
  ...this["~orpc"],
166
209
  inputSchema: initialInputSchema
167
210
  });
168
211
  }
212
+ /**
213
+ * Creates a middleware.
214
+ *
215
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
216
+ */
169
217
  middleware(middleware) {
170
218
  return decorateMiddleware(middleware);
171
219
  }
220
+ /**
221
+ * Adds type-safe custom errors.
222
+ * The provided errors are spared-merged with any existing errors.
223
+ *
224
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
225
+ */
172
226
  errors(errors) {
173
227
  return new Builder({
174
228
  ...this["~orpc"],
@@ -182,18 +236,37 @@ class Builder {
182
236
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
183
237
  });
184
238
  }
239
+ /**
240
+ * Sets or updates the metadata.
241
+ * The provided metadata is spared-merged with any existing metadata.
242
+ *
243
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
244
+ */
185
245
  meta(meta) {
186
246
  return new Builder({
187
247
  ...this["~orpc"],
188
248
  meta: mergeMeta(this["~orpc"].meta, meta)
189
249
  });
190
250
  }
251
+ /**
252
+ * Sets or updates the route definition.
253
+ * The provided route is spared-merged with any existing route.
254
+ * This option is typically relevant when integrating with OpenAPI.
255
+ *
256
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
257
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
258
+ */
191
259
  route(route) {
192
260
  return new Builder({
193
261
  ...this["~orpc"],
194
262
  route: mergeRoute(this["~orpc"].route, route)
195
263
  });
196
264
  }
265
+ /**
266
+ * Defines the input validation schema.
267
+ *
268
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
269
+ */
197
270
  input(schema) {
198
271
  return new Builder({
199
272
  ...this["~orpc"],
@@ -201,6 +274,11 @@ class Builder {
201
274
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
202
275
  });
203
276
  }
277
+ /**
278
+ * Defines the output validation schema.
279
+ *
280
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
281
+ */
204
282
  output(schema) {
205
283
  return new Builder({
206
284
  ...this["~orpc"],
@@ -208,27 +286,57 @@ class Builder {
208
286
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
209
287
  });
210
288
  }
289
+ /**
290
+ * Defines the handler of the procedure.
291
+ *
292
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
293
+ */
211
294
  handler(handler) {
212
295
  return new DecoratedProcedure({
213
296
  ...this["~orpc"],
214
297
  handler
215
298
  });
216
299
  }
300
+ /**
301
+ * Prefixes all procedures in the router.
302
+ * The provided prefix is post-appended to any existing router prefix.
303
+ *
304
+ * @note This option does not affect procedures that do not define a path in their route definition.
305
+ *
306
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
307
+ */
217
308
  prefix(prefix) {
218
309
  return new Builder({
219
310
  ...this["~orpc"],
220
311
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
221
312
  });
222
313
  }
314
+ /**
315
+ * Adds tags to all procedures in the router.
316
+ * This helpful when you want to group procedures together in the OpenAPI specification.
317
+ *
318
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
319
+ */
223
320
  tag(...tags) {
224
321
  return new Builder({
225
322
  ...this["~orpc"],
226
323
  tags: mergeTags(this["~orpc"].tags, tags)
227
324
  });
228
325
  }
326
+ /**
327
+ * Applies all of the previously defined options to the specified router.
328
+ *
329
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
330
+ */
229
331
  router(router) {
230
332
  return enhanceRouter(router, this["~orpc"]);
231
333
  }
334
+ /**
335
+ * Create a lazy router
336
+ * And applies all of the previously defined options to the specified router.
337
+ *
338
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
339
+ */
232
340
  lazy(loader) {
233
341
  return enhanceRouter(lazy(loader), this["~orpc"]);
234
342
  }
@@ -1,8 +1,8 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { h as StandardHandlerInterceptorOptions, i as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DOYDVeMX.mjs';
5
- import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.DLt5njUb.mjs';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DY7OKEoj.mjs';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.mjs';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -32,6 +32,12 @@ interface BatchHandlerOptions<T extends Context> {
32
32
  */
33
33
  headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Request/Response Plugin allows you to combine multiple requests and responses into a single batch,
37
+ * reducing the overhead of sending each one separately.
38
+ *
39
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-request-response Batch Request/Response Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -51,6 +57,11 @@ interface CORSOptions<T extends Context> {
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
60
+ /**
61
+ * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
+ *
63
+ * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
64
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -61,6 +72,12 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
61
72
  interface ResponseHeadersPluginContext {
62
73
  resHeaders?: Headers;
63
74
  }
75
+ /**
76
+ * The Response Headers Plugin allows you to set response headers in oRPC.
77
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
80
+ */
64
81
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
82
  init(options: StandardHandlerOptions<T>): void;
66
83
  }
@@ -96,6 +113,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
113
  */
97
114
  error?: InstanceType<typeof ORPCError>;
98
115
  }
116
+ /**
117
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
118
+ * It helps ensure that requests to your procedures originate from JavaScript code,
119
+ * not from other sources like standard HTML forms or direct browser navigation.
120
+ *
121
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
+ */
99
123
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
124
  private readonly headerName;
101
125
  private readonly headerValue;
@@ -114,6 +138,13 @@ interface StrictGetMethodPluginOptions {
114
138
  */
115
139
  error?: InstanceType<typeof ORPCError$1>;
116
140
  }
141
+ /**
142
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
143
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
+ * Cross-Site Request Forgery (CSRF) attacks.
145
+ *
146
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
+ */
117
148
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
149
  private readonly error;
119
150
  order: number;
@@ -121,4 +152,5 @@ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandle
121
152
  init(options: StandardHandlerOptions<T>): void;
122
153
  }
123
154
 
124
- export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };
155
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,8 +1,8 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { h as StandardHandlerInterceptorOptions, i as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DFFT_EZo.js';
5
- import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.DLt5njUb.js';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.D5fBlF9j.js';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.js';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -32,6 +32,12 @@ interface BatchHandlerOptions<T extends Context> {
32
32
  */
33
33
  headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Request/Response Plugin allows you to combine multiple requests and responses into a single batch,
37
+ * reducing the overhead of sending each one separately.
38
+ *
39
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-request-response Batch Request/Response Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -51,6 +57,11 @@ interface CORSOptions<T extends Context> {
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
60
+ /**
61
+ * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
+ *
63
+ * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
64
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -61,6 +72,12 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
61
72
  interface ResponseHeadersPluginContext {
62
73
  resHeaders?: Headers;
63
74
  }
75
+ /**
76
+ * The Response Headers Plugin allows you to set response headers in oRPC.
77
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
80
+ */
64
81
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
82
  init(options: StandardHandlerOptions<T>): void;
66
83
  }
@@ -96,6 +113,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
113
  */
97
114
  error?: InstanceType<typeof ORPCError>;
98
115
  }
116
+ /**
117
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
118
+ * It helps ensure that requests to your procedures originate from JavaScript code,
119
+ * not from other sources like standard HTML forms or direct browser navigation.
120
+ *
121
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
+ */
99
123
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
124
  private readonly headerName;
101
125
  private readonly headerValue;
@@ -114,6 +138,13 @@ interface StrictGetMethodPluginOptions {
114
138
  */
115
139
  error?: InstanceType<typeof ORPCError$1>;
116
140
  }
141
+ /**
142
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
143
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
+ * Cross-Site Request Forgery (CSRF) attacks.
145
+ *
146
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
+ */
117
148
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
149
  private readonly error;
119
150
  order: number;
@@ -121,4 +152,5 @@ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandle
121
152
  init(options: StandardHandlerOptions<T>): void;
122
153
  }
123
154
 
124
- export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };
155
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,4 +1,4 @@
1
- import { value } from '@orpc/shared';
1
+ import { value, isAsyncIteratorObject } from '@orpc/shared';
2
2
  import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
3
3
  import { ORPCError } from '@orpc/client';
4
4
  export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
@@ -49,6 +49,14 @@ class BatchHandlerPlugin {
49
49
  const mapped = this.mapRequestItem(request, options2);
50
50
  return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
51
51
  if (matched) {
52
+ if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
53
+ return {
54
+ index,
55
+ status: 500,
56
+ headers: {},
57
+ body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
58
+ };
59
+ }
52
60
  return { ...response2, index };
53
61
  }
54
62
  return { index, status: 404, headers: {}, body: "No procedure matched" };
@@ -1,6 +1,6 @@
1
- import { C as Context, R as Router } from './server.DLt5njUb.mjs';
2
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
3
- import { a as StandardHandlerOptions, b as StandardHandler } from './server.DOYDVeMX.mjs';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.mjs';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.DY7OKEoj.mjs';
4
4
 
5
5
  interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
6
  /**
@@ -14,4 +14,5 @@ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
14
  constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
15
  }
16
16
 
17
- export { type StandardRPCHandlerOptions as S, StandardRPCHandler as a };
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.DLt5njUb.js';
2
- import { S as StandardHandleOptions } from './server.DFFT_EZo.js';
1
+ import { C as Context } from './server.DPWk5pjW.js';
2
+ import { g as StandardHandleOptions } from './server.D5fBlF9j.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -1,6 +1,6 @@
1
- import { C as Context, R as Router } from './server.DLt5njUb.js';
2
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
3
- import { a as StandardHandlerOptions, b as StandardHandler } from './server.DFFT_EZo.js';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.js';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.D5fBlF9j.js';
4
4
 
5
5
  interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
6
  /**
@@ -14,4 +14,5 @@ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
14
  constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
15
  }
16
16
 
17
- export { type StandardRPCHandlerOptions as S, StandardRPCHandler as a };
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };
@@ -2,7 +2,17 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
5
+ import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.DPWk5pjW.js';
6
+
7
+ interface StandardHandlerPlugin<TContext extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<TContext>): void;
10
+ }
11
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
+ protected readonly plugins: TPlugin[];
13
+ constructor(plugins?: readonly TPlugin[]);
14
+ init(options: StandardHandlerOptions<T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -20,16 +30,6 @@ interface StandardCodec {
20
30
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
31
  }
22
32
 
23
- interface StandardHandlerPlugin<TContext extends Context> {
24
- order?: number;
25
- init?(options: StandardHandlerOptions<TContext>): void;
26
- }
27
- declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
28
- protected readonly plugins: TPlugin[];
29
- constructor(plugins?: readonly TPlugin[]);
30
- init(options: StandardHandlerOptions<T>): void;
31
- }
32
-
33
33
  interface StandardHandleOptions<T extends Context> {
34
34
  prefix?: HTTPPath;
35
35
  context: T;
@@ -70,4 +70,5 @@ declare class StandardHandler<T extends Context> {
70
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
71
71
  }
72
72
 
73
- export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, StandardHandler as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, type StandardHandlerInterceptorOptions as h, type StandardHandlerPlugin as i };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
74
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
@@ -46,6 +46,9 @@ function addMiddleware(middlewares, addition) {
46
46
  }
47
47
 
48
48
  class Procedure {
49
+ /**
50
+ * This property holds the defined options.
51
+ */
49
52
  "~orpc";
50
53
  constructor(def) {
51
54
  this["~orpc"] = def;
@@ -1,6 +1,6 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
- import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
2
  import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
4
4
 
5
5
  type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
@@ -28,6 +28,9 @@ interface Lazy<T> {
28
28
  };
29
29
  }
30
30
  type Lazyable<T> = T | Lazy<T>;
31
+ /**
32
+ * Create a lazy thing.
33
+ */
31
34
  declare function lazy<T>(loader: () => Promise<{
32
35
  default: T;
33
36
  }>, meta?: LazyMeta): Lazy<T>;
@@ -56,7 +59,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
56
59
  outputValidationIndex: number;
57
60
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
61
  }
62
+ /**
63
+ * This class represents a procedure.
64
+ *
65
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ */
59
67
  declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
+ /**
69
+ * This property holds the defined options.
70
+ */
60
71
  '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
72
  constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
73
  }
@@ -87,6 +98,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
87
98
  next: MiddlewareNextFn<TOutput>;
88
99
  errors: TErrorConstructorMap;
89
100
  }
101
+ /**
102
+ * A function that represents a middleware.
103
+ *
104
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ */
90
106
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
107
  (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
108
  }
@@ -106,9 +122,6 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
106
122
  signal?: AbortSignal;
107
123
  lastEventId: string | undefined;
108
124
  }
109
- /**
110
- * Options for creating a procedure caller with comprehensive type safety
111
- */
112
125
  type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
126
  /**
114
127
  * This is helpful for logging and analytics.
@@ -120,24 +133,60 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
120
133
  } : {
121
134
  context: Value<TInitialContext, [clientContext: TClientContext]>;
122
135
  });
136
+ /**
137
+ * Create Server-side client from a procedure.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ */
123
141
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
142
 
143
+ /**
144
+ * Represents a router, which defines a hierarchical structure of procedures.
145
+ *
146
+ * @info A procedure is a router too.
147
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ */
125
149
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
150
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
151
  };
128
152
  type AnyRouter = Router<any, any>;
129
153
  type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
154
+ /**
155
+ * Infer all initial context of the router.
156
+ *
157
+ * @info A procedure is a router too.
158
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ */
130
160
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
161
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
162
  };
163
+ /**
164
+ * Infer all current context of the router.
165
+ *
166
+ * @info A procedure is a router too.
167
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ */
133
169
  type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
170
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
171
  };
172
+ /**
173
+ * Infer all router inputs
174
+ *
175
+ * @info A procedure is a router too.
176
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ */
136
178
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
179
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
180
  };
181
+ /**
182
+ * Infer all router outputs
183
+ *
184
+ * @info A procedure is a router too.
185
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ */
139
187
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
188
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
189
  };
142
190
 
143
- export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
191
+ export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
192
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };