@orpc/server 0.52.0 → 0.53.0

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/dist/adapters/fetch/index.d.mts +11 -7
  2. package/dist/adapters/fetch/index.d.ts +11 -7
  3. package/dist/adapters/fetch/index.mjs +6 -4
  4. package/dist/adapters/hono/index.d.mts +5 -5
  5. package/dist/adapters/hono/index.d.ts +5 -5
  6. package/dist/adapters/hono/index.mjs +10 -7
  7. package/dist/adapters/next/index.d.mts +5 -5
  8. package/dist/adapters/next/index.d.ts +5 -5
  9. package/dist/adapters/next/index.mjs +10 -7
  10. package/dist/adapters/node/index.d.mts +11 -7
  11. package/dist/adapters/node/index.d.ts +11 -7
  12. package/dist/adapters/node/index.mjs +17 -12
  13. package/dist/adapters/standard/index.d.mts +3 -3
  14. package/dist/adapters/standard/index.d.ts +3 -3
  15. package/dist/adapters/standard/index.mjs +6 -4
  16. package/dist/index.d.mts +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.mjs +7 -7
  19. package/dist/plugins/index.d.mts +100 -6
  20. package/dist/plugins/index.d.ts +100 -6
  21. package/dist/plugins/index.mjs +138 -1
  22. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  23. package/dist/shared/{server.T5WmDoWQ.mjs → server.Bm0UqHzd.mjs} +16 -11
  24. package/dist/shared/{server.e3W6AG3-.mjs → server.C37gDhSZ.mjs} +16 -22
  25. package/dist/shared/server.C8NkqxHo.d.ts +17 -0
  26. package/dist/shared/{server.DGnN7q3R.d.mts → server.CGCwEAt_.d.mts} +1 -1
  27. package/dist/shared/server.DCQgF_JR.d.mts +17 -0
  28. package/dist/shared/{server.BHlRCrf_.d.ts → server.DFFT_EZo.d.ts} +11 -4
  29. package/dist/shared/{server.Dfx1jV-K.mjs → server.DFuJLDuo.mjs} +43 -14
  30. package/dist/shared/{server.CzxlqYZL.d.mts → server.DOYDVeMX.d.mts} +11 -4
  31. package/dist/shared/{server.Cud5qk0c.d.ts → server._2UufoXA.d.ts} +1 -1
  32. package/package.json +7 -7
  33. package/dist/shared/server.B77ImKAP.d.mts +0 -8
  34. package/dist/shared/server.DUF89eb-.d.ts +0 -8
@@ -1,15 +1,28 @@
1
- import { ORPCError, toORPCError } from '@orpc/client';
1
+ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
2
  import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.e3W6AG3-.mjs';
4
- import { toHttpPath } from '@orpc/client/standard';
3
+ import '@orpc/standard-server/batch';
4
+ import { ORPCError, toORPCError } from '@orpc/client';
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.C37gDhSZ.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) {
14
+ for (const plugin of this.plugins) {
15
+ plugin.init?.(options);
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
- for (const plugin of toArray(options.plugins)) {
11
- plugin.init?.(options);
12
- }
24
+ const plugins = new CompositeStandardHandlerPlugin(options.plugins);
25
+ plugins.init(options);
13
26
  this.interceptors = toArray(options.interceptors);
14
27
  this.clientInterceptors = toArray(options.clientInterceptors);
15
28
  this.rootInterceptors = toArray(options.rootInterceptors);
@@ -18,23 +31,24 @@ class StandardHandler {
18
31
  interceptors;
19
32
  clientInterceptors;
20
33
  rootInterceptors;
21
- handle(request, options) {
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
+ }
22
39
  return intercept(
23
40
  this.rootInterceptors,
24
- { ...options, request },
41
+ { ...options, request, prefix },
25
42
  async (interceptorOptions) => {
26
43
  let isDecoding = false;
27
44
  try {
28
45
  return await intercept(
29
46
  this.interceptors,
30
47
  interceptorOptions,
31
- async ({ request: request2, context, prefix }) => {
48
+ async ({ request: request2, context, prefix: prefix2 }) => {
32
49
  const method = request2.method;
33
50
  const url = request2.url;
34
- if (prefix && !url.pathname.startsWith(prefix)) {
35
- return { matched: false, response: void 0 };
36
- }
37
- const pathname = prefix ? url.pathname.replace(prefix, "") : url.pathname;
51
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
38
52
  const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
39
53
  if (!match) {
40
54
  return { matched: false, response: void 0 };
@@ -158,4 +172,19 @@ class StandardRPCMatcher {
158
172
  }
159
173
  }
160
174
 
161
- export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
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 };
@@ -20,6 +20,16 @@ interface StandardCodec {
20
20
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
21
  }
22
22
 
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
+
23
33
  interface StandardHandleOptions<T extends Context> {
24
34
  prefix?: HTTPPath;
25
35
  context: T;
@@ -31,9 +41,6 @@ type StandardHandleResult = {
31
41
  matched: false;
32
42
  response: undefined;
33
43
  };
34
- interface StandardHandlerPlugin<TContext extends Context> {
35
- init?(options: StandardHandlerOptions<TContext>): void;
36
- }
37
44
  interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
45
  request: StandardLazyRequest;
39
46
  }
@@ -63,4 +70,4 @@ declare class StandardHandler<T extends Context> {
63
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
71
  }
65
72
 
66
- export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
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 };
@@ -1,5 +1,5 @@
1
1
  import { C as Context } from './server.DLt5njUb.js';
2
- import { S as StandardHandleOptions } from './server.BHlRCrf_.js';
2
+ import { S as StandardHandleOptions } from './server.DFFT_EZo.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.52.0",
4
+ "version": "0.53.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -58,12 +58,12 @@
58
58
  "next": ">=14.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@orpc/client": "0.52.0",
62
- "@orpc/contract": "0.52.0",
63
- "@orpc/shared": "0.52.0",
64
- "@orpc/standard-server": "0.52.0",
65
- "@orpc/standard-server-fetch": "0.52.0",
66
- "@orpc/standard-server-node": "0.52.0"
61
+ "@orpc/client": "0.53.0",
62
+ "@orpc/shared": "0.53.0",
63
+ "@orpc/contract": "0.53.0",
64
+ "@orpc/standard-server-fetch": "0.53.0",
65
+ "@orpc/standard-server": "0.53.0",
66
+ "@orpc/standard-server-node": "0.53.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "supertest": "^7.0.0"
@@ -1,8 +0,0 @@
1
- import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context } from './server.DLt5njUb.mjs';
3
- import { a as StandardHandlerOptions } from './server.CzxlqYZL.mjs';
4
-
5
- interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardRPCHandlerOptions as S };
@@ -1,8 +0,0 @@
1
- import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context } from './server.DLt5njUb.js';
3
- import { a as StandardHandlerOptions } from './server.BHlRCrf_.js';
4
-
5
- interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardRPCHandlerOptions as S };