@orpc/server 0.0.0-next.9b9ade5 → 0.0.0-next.9cd157a

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 (39) hide show
  1. package/README.md +25 -17
  2. package/dist/adapters/fetch/index.d.mts +54 -10
  3. package/dist/adapters/fetch/index.d.ts +54 -10
  4. package/dist/adapters/fetch/index.mjs +104 -8
  5. package/dist/adapters/node/index.d.mts +56 -21
  6. package/dist/adapters/node/index.d.ts +56 -21
  7. package/dist/adapters/node/index.mjs +82 -23
  8. package/dist/adapters/standard/index.d.mts +11 -10
  9. package/dist/adapters/standard/index.d.ts +11 -10
  10. package/dist/adapters/standard/index.mjs +6 -4
  11. package/dist/index.d.mts +625 -65
  12. package/dist/index.d.ts +625 -65
  13. package/dist/index.mjs +165 -34
  14. package/dist/plugins/index.d.mts +140 -15
  15. package/dist/plugins/index.d.ts +140 -15
  16. package/dist/plugins/index.mjs +156 -7
  17. package/dist/shared/{server.CSZRzcSW.mjs → server.BM1HMJGg.mjs} +62 -30
  18. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  19. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  20. package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
  21. package/dist/shared/server.CzSMXd8y.d.mts +18 -0
  22. package/dist/shared/server.DEgjJVit.d.ts +18 -0
  23. package/dist/shared/{server.CMrS28Go.mjs → server.DG7Tamti.mjs} +45 -24
  24. package/dist/shared/{server.CPteJIPP.d.mts → server.DPWk5pjW.d.mts} +71 -22
  25. package/dist/shared/{server.CPteJIPP.d.ts → server.DPWk5pjW.d.ts} +71 -22
  26. package/dist/shared/server.QUe9N8P4.d.mts +10 -0
  27. package/dist/shared/server.YZzrREz9.d.ts +74 -0
  28. package/dist/shared/server.eWLxY3lq.d.mts +74 -0
  29. package/package.json +9 -22
  30. package/dist/adapters/hono/index.d.mts +0 -19
  31. package/dist/adapters/hono/index.d.ts +0 -19
  32. package/dist/adapters/hono/index.mjs +0 -32
  33. package/dist/adapters/next/index.d.mts +0 -26
  34. package/dist/adapters/next/index.d.ts +0 -26
  35. package/dist/adapters/next/index.mjs +0 -29
  36. package/dist/shared/server.CM3tWr3C.d.mts +0 -75
  37. package/dist/shared/server.Cq3B6PoL.mjs +0 -28
  38. package/dist/shared/server.DmW25ynm.d.ts +0 -75
  39. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -1,31 +1,156 @@
1
- import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DmW25ynm.js';
2
- export { C as CompositePlugin } from '../shared/server.DmW25ynm.js';
3
1
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.CPteJIPP.js';
5
- import '@orpc/contract';
6
- import '@orpc/standard-server';
7
- import '@orpc/client';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.YZzrREz9.js';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.js';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
8
 
9
- interface CORSOptions<TContext extends Context> {
10
- origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
9
+ interface BatchHandlerOptions<T extends Context> {
10
+ /**
11
+ * The max size of the batch allowed.
12
+ *
13
+ * @default 10
14
+ */
15
+ maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
16
+ /**
17
+ * Map the request before processing it.
18
+ *
19
+ * @default merged back batch request headers into the request
20
+ */
21
+ mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
22
+ /**
23
+ * Success batch response status code.
24
+ *
25
+ * @default 207
26
+ */
27
+ successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
+ /**
29
+ * success batch response headers.
30
+ *
31
+ * @default {}
32
+ */
33
+ headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
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
+ */
41
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
42
+ private readonly maxSize;
43
+ private readonly mapRequestItem;
44
+ private readonly successStatus;
45
+ private readonly headers;
46
+ order: number;
47
+ constructor(options?: BatchHandlerOptions<T>);
48
+ init(options: StandardHandlerOptions<T>): void;
49
+ }
50
+
51
+ interface CORSOptions<T extends Context> {
52
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
53
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
12
54
  allowMethods?: readonly string[];
13
55
  allowHeaders?: readonly string[];
14
56
  maxAge?: number;
15
57
  credentials?: boolean;
16
58
  exposeHeaders?: readonly string[];
17
59
  }
18
- declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
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
+ */
65
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
66
  private readonly options;
20
- constructor(options?: CORSOptions<TContext>);
21
- init(options: StandardHandlerOptions<TContext>): void;
67
+ order: number;
68
+ constructor(options?: CORSOptions<T>);
69
+ init(options: StandardHandlerOptions<T>): void;
22
70
  }
23
71
 
24
72
  interface ResponseHeadersPluginContext {
25
73
  resHeaders?: Headers;
26
74
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
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
+ */
81
+ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
+ init(options: StandardHandlerOptions<T>): void;
83
+ }
84
+
85
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
86
+ /**
87
+ * The name of the header to check.
88
+ *
89
+ * @default 'x-csrf-token'
90
+ */
91
+ headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
92
+ /**
93
+ * The value of the header to check.
94
+ *
95
+ * @default 'orpc'
96
+ *
97
+ */
98
+ headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
99
+ /**
100
+ * Exclude a procedure from the plugin.
101
+ *
102
+ * @default false
103
+ *
104
+ */
105
+ exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
106
+ /**
107
+ * The error thrown when the CSRF token is invalid.
108
+ *
109
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
110
+ * status: 403,
111
+ * message: 'Invalid CSRF token',
112
+ * })
113
+ */
114
+ error?: InstanceType<typeof ORPCError>;
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
+ */
123
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
+ private readonly headerName;
125
+ private readonly headerValue;
126
+ private readonly exclude;
127
+ private readonly error;
128
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
129
+ order: number;
130
+ init(options: StandardHandlerOptions<T>): void;
131
+ }
132
+
133
+ interface StrictGetMethodPluginOptions {
134
+ /**
135
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
136
+ *
137
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
138
+ */
139
+ error?: InstanceType<typeof ORPCError$1>;
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
+ */
148
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
149
+ private readonly error;
150
+ order: number;
151
+ constructor(options?: StrictGetMethodPluginOptions);
152
+ init(options: StandardHandlerOptions<T>): void;
29
153
  }
30
154
 
31
- export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
155
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,8 +1,109 @@
1
- export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
2
- import { value } from '@orpc/shared';
1
+ import { value, isAsyncIteratorObject } from '@orpc/shared';
2
+ import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
3
+ import { ORPCError } from '@orpc/client';
4
+ export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
5
+ import '@orpc/contract';
6
+
7
+ class BatchHandlerPlugin {
8
+ maxSize;
9
+ mapRequestItem;
10
+ successStatus;
11
+ headers;
12
+ order = 5e6;
13
+ constructor(options = {}) {
14
+ this.maxSize = options.maxSize ?? 10;
15
+ this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
16
+ ...request,
17
+ headers: {
18
+ ...batchRequest.headers,
19
+ ...request.headers
20
+ }
21
+ }));
22
+ this.successStatus = options.successStatus ?? 207;
23
+ this.headers = options.headers ?? {};
24
+ }
25
+ init(options) {
26
+ options.rootInterceptors ??= [];
27
+ options.rootInterceptors.unshift(async (options2) => {
28
+ if (options2.request.headers["x-orpc-batch"] !== "1") {
29
+ return options2.next();
30
+ }
31
+ let isParsing = false;
32
+ try {
33
+ isParsing = true;
34
+ const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
35
+ isParsing = false;
36
+ const maxSize = await value(this.maxSize, options2);
37
+ if (parsed.length > maxSize) {
38
+ return {
39
+ matched: true,
40
+ response: {
41
+ status: 413,
42
+ headers: {},
43
+ body: "Batch request size exceeds the maximum allowed size"
44
+ }
45
+ };
46
+ }
47
+ const responses = parsed.map(
48
+ (request, index) => {
49
+ const mapped = this.mapRequestItem(request, options2);
50
+ return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
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
+ }
60
+ return { ...response2, index };
61
+ }
62
+ return { index, status: 404, headers: {}, body: "No procedure matched" };
63
+ }).catch(() => {
64
+ return { index, status: 500, headers: {}, body: "Internal server error" };
65
+ });
66
+ }
67
+ );
68
+ await Promise.race(responses);
69
+ const status = await value(this.successStatus, responses, options2);
70
+ const headers = await value(this.headers, responses, options2);
71
+ const response = toBatchResponse({
72
+ status,
73
+ headers,
74
+ body: async function* () {
75
+ const promises = [...responses];
76
+ while (true) {
77
+ const handling = promises.filter((p) => p !== void 0);
78
+ if (handling.length === 0) {
79
+ return;
80
+ }
81
+ const result = await Promise.race(handling);
82
+ promises[result.index] = void 0;
83
+ yield result;
84
+ }
85
+ }()
86
+ });
87
+ return {
88
+ matched: true,
89
+ response
90
+ };
91
+ } catch (cause) {
92
+ if (isParsing) {
93
+ return {
94
+ matched: true,
95
+ response: { status: 400, headers: {}, body: "Invalid batch request, this could be caused by a malformed request body or a missing header" }
96
+ };
97
+ }
98
+ throw cause;
99
+ }
100
+ });
101
+ }
102
+ }
3
103
 
4
104
  class CORSPlugin {
5
105
  options;
106
+ order = 9e6;
6
107
  constructor(options = {}) {
7
108
  const defaults = {
8
109
  origin: (origin) => origin,
@@ -79,14 +180,19 @@ class ResponseHeadersPlugin {
79
180
  init(options) {
80
181
  options.rootInterceptors ??= [];
81
182
  options.rootInterceptors.push(async (interceptorOptions) => {
82
- const headers = new Headers();
83
- interceptorOptions.context.resHeaders = headers;
84
- const result = await interceptorOptions.next();
183
+ const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
184
+ const result = await interceptorOptions.next({
185
+ ...interceptorOptions,
186
+ context: {
187
+ ...interceptorOptions.context,
188
+ resHeaders
189
+ }
190
+ });
85
191
  if (!result.matched) {
86
192
  return result;
87
193
  }
88
194
  const responseHeaders = result.response.headers;
89
- for (const [key, value] of headers) {
195
+ for (const [key, value] of resHeaders) {
90
196
  if (Array.isArray(responseHeaders[key])) {
91
197
  responseHeaders[key].push(value);
92
198
  } else if (responseHeaders[key] !== void 0) {
@@ -100,4 +206,47 @@ class ResponseHeadersPlugin {
100
206
  }
101
207
  }
102
208
 
103
- export { CORSPlugin, ResponseHeadersPlugin };
209
+ const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
210
+ class SimpleCsrfProtectionHandlerPlugin {
211
+ headerName;
212
+ headerValue;
213
+ exclude;
214
+ error;
215
+ constructor(options = {}) {
216
+ this.headerName = options.headerName ?? "x-csrf-token";
217
+ this.headerValue = options.headerValue ?? "orpc";
218
+ this.exclude = options.exclude ?? false;
219
+ this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
220
+ status: 403,
221
+ message: "Invalid CSRF token"
222
+ });
223
+ }
224
+ order = 8e6;
225
+ init(options) {
226
+ options.rootInterceptors ??= [];
227
+ options.clientInterceptors ??= [];
228
+ options.rootInterceptors.unshift(async (options2) => {
229
+ const headerName = await value(this.headerName, options2);
230
+ const headerValue = await value(this.headerValue, options2);
231
+ return options2.next({
232
+ ...options2,
233
+ context: {
234
+ ...options2.context,
235
+ [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
236
+ }
237
+ });
238
+ });
239
+ options.clientInterceptors.unshift(async (options2) => {
240
+ if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
241
+ throw new TypeError("[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor");
242
+ }
243
+ const excluded = await value(this.exclude, options2);
244
+ if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
245
+ throw this.error;
246
+ }
247
+ return options2.next();
248
+ });
249
+ }
250
+ }
251
+
252
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -1,51 +1,68 @@
1
+ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
+ import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
+ import '@orpc/standard-server/batch';
1
4
  import { ORPCError, toORPCError } from '@orpc/client';
2
- import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
3
- import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
4
- import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.CMrS28Go.mjs';
5
+ import { S as StrictGetMethodPlugin } from './server.BW-nUGgA.mjs';
6
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DG7Tamti.mjs';
7
+
8
+ class CompositeStandardHandlerPlugin {
9
+ plugins;
10
+ constructor(plugins = []) {
11
+ this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
12
+ }
13
+ init(options, router) {
14
+ for (const plugin of this.plugins) {
15
+ plugin.init?.(options, router);
16
+ }
17
+ }
18
+ }
5
19
 
6
20
  class StandardHandler {
7
21
  constructor(router, matcher, codec, options) {
8
22
  this.matcher = matcher;
9
23
  this.codec = codec;
10
- this.options = options;
11
- this.plugin = new CompositePlugin(options.plugins);
12
- this.plugin.init(this.options);
24
+ const plugins = new CompositeStandardHandlerPlugin(options.plugins);
25
+ plugins.init(options, router);
26
+ this.interceptors = toArray(options.interceptors);
27
+ this.clientInterceptors = toArray(options.clientInterceptors);
28
+ this.rootInterceptors = toArray(options.rootInterceptors);
13
29
  this.matcher.init(router);
14
30
  }
15
- plugin;
16
- handle(request, ...[options]) {
31
+ interceptors;
32
+ clientInterceptors;
33
+ rootInterceptors;
34
+ async handle(request, options) {
35
+ const prefix = options.prefix?.replace(/\/$/, "") || void 0;
36
+ if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
37
+ return { matched: false, response: void 0 };
38
+ }
17
39
  return intercept(
18
- this.options.rootInterceptors ?? [],
19
- {
20
- request,
21
- ...options,
22
- context: options?.context ?? {}
23
- // context is optional only when all fields are optional so we can safely force it to have a context
24
- },
40
+ this.rootInterceptors,
41
+ { ...options, request, prefix },
25
42
  async (interceptorOptions) => {
26
43
  let isDecoding = false;
27
44
  try {
28
45
  return await intercept(
29
- this.options.interceptors ?? [],
46
+ this.interceptors,
30
47
  interceptorOptions,
31
- async (interceptorOptions2) => {
32
- const method = interceptorOptions2.request.method;
33
- const url = interceptorOptions2.request.url;
34
- const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
35
- const match = await this.matcher.match(method, pathname);
48
+ async ({ request: request2, context, prefix: prefix2 }) => {
49
+ const method = request2.method;
50
+ const url = request2.url;
51
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
52
+ const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
36
53
  if (!match) {
37
54
  return { matched: false, response: void 0 };
38
55
  }
39
56
  const client = createProcedureClient(match.procedure, {
40
- context: interceptorOptions2.context,
57
+ context,
41
58
  path: match.path,
42
- interceptors: this.options.clientInterceptors
59
+ interceptors: this.clientInterceptors
43
60
  });
44
61
  isDecoding = true;
45
- const input = await this.codec.decode(request, match.params, match.procedure);
62
+ const input = await this.codec.decode(request2, match.params, match.procedure);
46
63
  isDecoding = false;
47
- const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
48
- const output = await client(input, { signal: request.signal, lastEventId });
64
+ const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
65
+ const output = await client(input, { signal: request2.signal, lastEventId });
49
66
  const response = this.codec.encode(output, match.procedure);
50
67
  return {
51
68
  matched: true,
@@ -54,7 +71,7 @@ class StandardHandler {
54
71
  }
55
72
  );
56
73
  } catch (e) {
57
- const error = isDecoding ? new ORPCError("BAD_REQUEST", {
74
+ const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
58
75
  message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
59
76
  cause: e
60
77
  }) : toORPCError(e);
@@ -69,7 +86,7 @@ class StandardHandler {
69
86
  }
70
87
  }
71
88
 
72
- class RPCCodec {
89
+ class StandardRPCCodec {
73
90
  constructor(serializer) {
74
91
  this.serializer = serializer;
75
92
  }
@@ -93,7 +110,7 @@ class RPCCodec {
93
110
  }
94
111
  }
95
112
 
96
- class RPCMatcher {
113
+ class StandardRPCMatcher {
97
114
  tree = {};
98
115
  pendingRouters = [];
99
116
  init(router, path = []) {
@@ -155,4 +172,19 @@ class RPCMatcher {
155
172
  }
156
173
  }
157
174
 
158
- export { RPCCodec as R, StandardHandler as S, RPCMatcher as a };
175
+ class StandardRPCHandler extends StandardHandler {
176
+ constructor(router, options) {
177
+ options.plugins ??= [];
178
+ const strictGetMethodPluginEnabled = options.strictGetMethodPluginEnabled ?? true;
179
+ if (strictGetMethodPluginEnabled) {
180
+ options.plugins.push(new StrictGetMethodPlugin());
181
+ }
182
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
183
+ const serializer = new StandardRPCSerializer(jsonSerializer);
184
+ const matcher = new StandardRPCMatcher();
185
+ const codec = new StandardRPCCodec(serializer);
186
+ super(router, matcher, codec, options);
187
+ }
188
+ }
189
+
190
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
@@ -0,0 +1,9 @@
1
+ function resolveFriendlyStandardHandleOptions(options) {
2
+ return {
3
+ ...options,
4
+ context: options?.context ?? {}
5
+ // Context only optional if all fields are optional
6
+ };
7
+ }
8
+
9
+ export { resolveFriendlyStandardHandleOptions as r };
@@ -0,0 +1,36 @@
1
+ import { ORPCError, fallbackContractConfig } from '@orpc/contract';
2
+
3
+ const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
4
+ class StrictGetMethodPlugin {
5
+ error;
6
+ order = 7e6;
7
+ constructor(options = {}) {
8
+ this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
9
+ }
10
+ init(options) {
11
+ options.rootInterceptors ??= [];
12
+ options.clientInterceptors ??= [];
13
+ options.rootInterceptors.unshift((options2) => {
14
+ const isGetMethod = options2.request.method === "GET";
15
+ return options2.next({
16
+ ...options2,
17
+ context: {
18
+ ...options2.context,
19
+ [STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL]: isGetMethod
20
+ }
21
+ });
22
+ });
23
+ options.clientInterceptors.unshift((options2) => {
24
+ if (typeof options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] !== "boolean") {
25
+ throw new TypeError("[StrictGetMethodPlugin] strict GET method context has been corrupted or modified by another plugin or interceptor");
26
+ }
27
+ const procedureMethod = fallbackContractConfig("defaultMethod", options2.procedure["~orpc"].route.method);
28
+ if (options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] && procedureMethod !== "GET") {
29
+ throw this.error;
30
+ }
31
+ return options2.next();
32
+ });
33
+ }
34
+ }
35
+
36
+ export { StrictGetMethodPlugin as S };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DPWk5pjW.js';
2
+ import { g as StandardHandleOptions } from './server.YZzrREz9.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,18 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.mjs';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.eWLxY3lq.mjs';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ /**
7
+ * Enables or disables the StrictGetMethodPlugin.
8
+ *
9
+ * @default true
10
+ */
11
+ strictGetMethodPluginEnabled?: boolean;
12
+ }
13
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
+ constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
+ }
16
+
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };
@@ -0,0 +1,18 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.js';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.YZzrREz9.js';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ /**
7
+ * Enables or disables the StrictGetMethodPlugin.
8
+ *
9
+ * @default true
10
+ */
11
+ strictGetMethodPluginEnabled?: boolean;
12
+ }
13
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
+ constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
+ }
16
+
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };