@orpc/server 0.0.0-next.a419c18 → 0.0.0-next.a439c82

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 (49) hide show
  1. package/README.md +14 -17
  2. package/dist/adapters/bun-ws/index.d.mts +35 -0
  3. package/dist/adapters/bun-ws/index.d.ts +35 -0
  4. package/dist/adapters/bun-ws/index.mjs +50 -0
  5. package/dist/adapters/crossws/index.d.mts +30 -0
  6. package/dist/adapters/crossws/index.d.ts +30 -0
  7. package/dist/adapters/crossws/index.mjs +50 -0
  8. package/dist/adapters/fetch/index.d.mts +35 -11
  9. package/dist/adapters/fetch/index.d.ts +35 -11
  10. package/dist/adapters/fetch/index.mjs +109 -8
  11. package/dist/adapters/node/index.d.mts +35 -11
  12. package/dist/adapters/node/index.d.ts +35 -11
  13. package/dist/adapters/node/index.mjs +22 -12
  14. package/dist/adapters/standard/index.d.mts +6 -6
  15. package/dist/adapters/standard/index.d.ts +6 -6
  16. package/dist/adapters/standard/index.mjs +3 -2
  17. package/dist/adapters/websocket/index.d.mts +27 -0
  18. package/dist/adapters/websocket/index.d.ts +27 -0
  19. package/dist/adapters/websocket/index.mjs +37 -0
  20. package/dist/adapters/ws/index.d.mts +28 -0
  21. package/dist/adapters/ws/index.d.ts +28 -0
  22. package/dist/adapters/ws/index.mjs +37 -0
  23. package/dist/index.d.mts +592 -40
  24. package/dist/index.d.ts +592 -40
  25. package/dist/index.mjs +147 -15
  26. package/dist/plugins/index.d.mts +132 -6
  27. package/dist/plugins/index.d.ts +132 -6
  28. package/dist/plugins/index.mjs +153 -9
  29. package/dist/shared/server.BRoxSiSC.d.mts +12 -0
  30. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  31. package/dist/shared/{server.BG5ftPWa.d.ts → server.BjiJH9Vo.d.ts} +2 -2
  32. package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
  33. package/dist/shared/{server.BtxZnWJ9.mjs → server.DG7Tamti.mjs} +22 -29
  34. package/dist/shared/{server.MZvbGc3n.d.mts → server.DPWk5pjW.d.mts} +61 -12
  35. package/dist/shared/{server.MZvbGc3n.d.ts → server.DPWk5pjW.d.ts} +61 -12
  36. package/dist/shared/{server.C-CCcROC.d.mts → server.QUe9N8P4.d.mts} +2 -2
  37. package/dist/shared/{server.DnR6v9pj.mjs → server.SxlTJfG2.mjs} +35 -12
  38. package/dist/shared/{server.23VRZIfj.d.ts → server.YZzrREz9.d.ts} +19 -11
  39. package/dist/shared/{server.DJqfB27m.d.mts → server.eWLxY3lq.d.mts} +19 -11
  40. package/package.json +35 -20
  41. package/dist/adapters/hono/index.d.mts +0 -22
  42. package/dist/adapters/hono/index.d.ts +0 -22
  43. package/dist/adapters/hono/index.mjs +0 -32
  44. package/dist/adapters/next/index.d.mts +0 -29
  45. package/dist/adapters/next/index.d.ts +0 -29
  46. package/dist/adapters/next/index.mjs +0 -29
  47. package/dist/shared/server.B4eSvRkD.mjs +0 -98
  48. package/dist/shared/server.CIbpOMZX.d.mts +0 -8
  49. package/dist/shared/server.DCcCuA52.d.ts +0 -8
@@ -1,14 +1,26 @@
1
+ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
1
2
  import { ORPCError, toORPCError } from '@orpc/client';
2
3
  import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
- import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
4
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DG7Tamti.mjs';
5
+
6
+ class CompositeStandardHandlerPlugin {
7
+ plugins;
8
+ constructor(plugins = []) {
9
+ this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
10
+ }
11
+ init(options, router) {
12
+ for (const plugin of this.plugins) {
13
+ plugin.init?.(options, router);
14
+ }
15
+ }
16
+ }
4
17
 
5
18
  class StandardHandler {
6
19
  constructor(router, matcher, codec, options) {
7
20
  this.matcher = matcher;
8
21
  this.codec = codec;
9
- for (const plugin of toArray(options.plugins)) {
10
- plugin.init?.(options);
11
- }
22
+ const plugins = new CompositeStandardHandlerPlugin(options.plugins);
23
+ plugins.init(options, router);
12
24
  this.interceptors = toArray(options.interceptors);
13
25
  this.clientInterceptors = toArray(options.clientInterceptors);
14
26
  this.rootInterceptors = toArray(options.rootInterceptors);
@@ -17,23 +29,24 @@ class StandardHandler {
17
29
  interceptors;
18
30
  clientInterceptors;
19
31
  rootInterceptors;
20
- handle(request, options) {
32
+ async handle(request, options) {
33
+ const prefix = options.prefix?.replace(/\/$/, "") || void 0;
34
+ if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
35
+ return { matched: false, response: void 0 };
36
+ }
21
37
  return intercept(
22
38
  this.rootInterceptors,
23
- { ...options, request },
39
+ { ...options, request, prefix },
24
40
  async (interceptorOptions) => {
25
41
  let isDecoding = false;
26
42
  try {
27
43
  return await intercept(
28
44
  this.interceptors,
29
45
  interceptorOptions,
30
- async ({ request: request2, context, prefix }) => {
46
+ async ({ request: request2, context, prefix: prefix2 }) => {
31
47
  const method = request2.method;
32
48
  const url = request2.url;
33
- if (prefix && !url.pathname.startsWith(prefix)) {
34
- return { matched: false, response: void 0 };
35
- }
36
- const pathname = prefix ? url.pathname.replace(prefix, "") : url.pathname;
49
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
37
50
  const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
38
51
  if (!match) {
39
52
  return { matched: false, response: void 0 };
@@ -157,4 +170,14 @@ class StandardRPCMatcher {
157
170
  }
158
171
  }
159
172
 
160
- export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
173
+ class StandardRPCHandler extends StandardHandler {
174
+ constructor(router, options = {}) {
175
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
176
+ const serializer = new StandardRPCSerializer(jsonSerializer);
177
+ const matcher = new StandardRPCMatcher();
178
+ const codec = new StandardRPCCodec(serializer);
179
+ super(router, matcher, codec, options);
180
+ }
181
+ }
182
+
183
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
@@ -1,8 +1,18 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor } from '@orpc/shared';
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
3
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.js';
5
- import { ORPCError } from '@orpc/client';
5
+ import { C as Context, R as Router, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DPWk5pjW.js';
6
+
7
+ interface StandardHandlerPlugin<T extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): 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>, router: Router<any, T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -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
  }
@@ -42,16 +49,16 @@ interface StandardHandlerOptions<TContext extends Context> {
42
49
  /**
43
50
  * Interceptors at the request level, helpful when you want catch errors
44
51
  */
45
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
46
53
  /**
47
54
  * Interceptors at the root level, helpful when you want override the request/response
48
55
  */
49
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
50
57
  /**
51
58
  *
52
59
  * Interceptors for procedure client.
53
60
  */
54
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
55
62
  }
56
63
  declare class StandardHandler<T extends Context> {
57
64
  private readonly matcher;
@@ -63,4 +70,5 @@ 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, 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 };
@@ -1,8 +1,18 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor } from '@orpc/shared';
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
3
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.mjs';
5
- import { ORPCError } from '@orpc/client';
5
+ import { C as Context, R as Router, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DPWk5pjW.mjs';
6
+
7
+ interface StandardHandlerPlugin<T extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): 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>, router: Router<any, T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -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
  }
@@ -42,16 +49,16 @@ interface StandardHandlerOptions<TContext extends Context> {
42
49
  /**
43
50
  * Interceptors at the request level, helpful when you want catch errors
44
51
  */
45
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
46
53
  /**
47
54
  * Interceptors at the root level, helpful when you want override the request/response
48
55
  */
49
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
50
57
  /**
51
58
  *
52
59
  * Interceptors for procedure client.
53
60
  */
54
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
55
62
  }
56
63
  declare class StandardHandler<T extends Context> {
57
64
  private readonly matcher;
@@ -63,4 +70,5 @@ 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, 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.a419c18",
4
+ "version": "0.0.0-next.a439c82",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,39 +34,54 @@
34
34
  "import": "./dist/adapters/fetch/index.mjs",
35
35
  "default": "./dist/adapters/fetch/index.mjs"
36
36
  },
37
- "./hono": {
38
- "types": "./dist/adapters/hono/index.d.mts",
39
- "import": "./dist/adapters/hono/index.mjs",
40
- "default": "./dist/adapters/hono/index.mjs"
41
- },
42
- "./next": {
43
- "types": "./dist/adapters/next/index.d.mts",
44
- "import": "./dist/adapters/next/index.mjs",
45
- "default": "./dist/adapters/next/index.mjs"
46
- },
47
37
  "./node": {
48
38
  "types": "./dist/adapters/node/index.d.mts",
49
39
  "import": "./dist/adapters/node/index.mjs",
50
40
  "default": "./dist/adapters/node/index.mjs"
41
+ },
42
+ "./websocket": {
43
+ "types": "./dist/adapters/websocket/index.d.mts",
44
+ "import": "./dist/adapters/websocket/index.mjs",
45
+ "default": "./dist/adapters/websocket/index.mjs"
46
+ },
47
+ "./crossws": {
48
+ "types": "./dist/adapters/crossws/index.d.mts",
49
+ "import": "./dist/adapters/crossws/index.mjs",
50
+ "default": "./dist/adapters/crossws/index.mjs"
51
+ },
52
+ "./ws": {
53
+ "types": "./dist/adapters/ws/index.d.mts",
54
+ "import": "./dist/adapters/ws/index.mjs",
55
+ "default": "./dist/adapters/ws/index.mjs"
56
+ },
57
+ "./bun-ws": {
58
+ "types": "./dist/adapters/bun-ws/index.d.mts",
59
+ "import": "./dist/adapters/bun-ws/index.mjs",
60
+ "default": "./dist/adapters/bun-ws/index.mjs"
51
61
  }
52
62
  },
53
63
  "files": [
54
64
  "dist"
55
65
  ],
56
66
  "peerDependencies": {
57
- "hono": ">=4.6.0",
58
- "next": ">=14.0.0"
67
+ "crossws": ">=0.3.4",
68
+ "ws": ">=8.18.1"
59
69
  },
60
70
  "dependencies": {
61
- "@orpc/client": "0.0.0-next.a419c18",
62
- "@orpc/shared": "0.0.0-next.a419c18",
63
- "@orpc/contract": "0.0.0-next.a419c18",
64
- "@orpc/standard-server": "0.0.0-next.a419c18",
65
- "@orpc/standard-server-fetch": "0.0.0-next.a419c18",
66
- "@orpc/standard-server-node": "0.0.0-next.a419c18"
71
+ "@orpc/client": "0.0.0-next.a439c82",
72
+ "@orpc/contract": "0.0.0-next.a439c82",
73
+ "@orpc/standard-server": "0.0.0-next.a439c82",
74
+ "@orpc/standard-server-fetch": "0.0.0-next.a439c82",
75
+ "@orpc/standard-server-node": "0.0.0-next.a439c82",
76
+ "@orpc/standard-server-peer": "0.0.0-next.a439c82",
77
+ "@orpc/shared": "0.0.0-next.a439c82"
67
78
  },
68
79
  "devDependencies": {
69
- "supertest": "^7.0.0"
80
+ "@types/ws": "^8.18.1",
81
+ "crossws": "^0.3.4",
82
+ "next": "^15.3.0",
83
+ "supertest": "^7.1.0",
84
+ "ws": "^8.18.1"
70
85
  },
71
86
  "scripts": {
72
87
  "build": "unbuild",
@@ -1,22 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.mjs';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context as Context$1, MiddlewareHandler } from 'hono';
5
- import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
6
- import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
7
- import '../../shared/server.C-CCcROC.mjs';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.CIbpOMZX.mjs';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [Context$1]>;
17
- } : {
18
- context: Value<T, [Context$1]>;
19
- });
20
- declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
21
-
22
- export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
@@ -1,22 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.js';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context as Context$1, MiddlewareHandler } from 'hono';
5
- import { C as Context } from '../../shared/server.MZvbGc3n.js';
6
- import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
7
- import '../../shared/server.BG5ftPWa.js';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.DCcCuA52.js';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [Context$1]>;
17
- } : {
18
- context: Value<T, [Context$1]>;
19
- });
20
- declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
21
-
22
- export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
@@ -1,32 +0,0 @@
1
- export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
2
- import { value } from '@orpc/shared';
3
- import '@orpc/client';
4
- import '@orpc/client/standard';
5
- import '../../shared/server.DnR6v9pj.mjs';
6
- import '../../shared/server.BtxZnWJ9.mjs';
7
- import '@orpc/contract';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.BVwwTHyO.mjs';
10
-
11
- function createMiddleware(handler, ...[options]) {
12
- return async (c, next) => {
13
- const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
14
- const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
15
- // https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
16
- get(target, prop) {
17
- if (bodyProps.has(prop)) {
18
- return () => c.req[prop]();
19
- }
20
- return Reflect.get(target, prop, target);
21
- }
22
- });
23
- const context = await value(options?.context ?? {}, c);
24
- const { matched, response } = await handler.handle(request, { ...options, context });
25
- if (matched) {
26
- return c.newResponse(response.body, response);
27
- }
28
- await next();
29
- };
30
- }
31
-
32
- export { createMiddleware };
@@ -1,29 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.mjs';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { NextRequest } from 'next/server';
5
- import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
6
- import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
7
- import '../../shared/server.C-CCcROC.mjs';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.CIbpOMZX.mjs';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [NextRequest]>;
17
- } : {
18
- context: Value<T, [NextRequest]>;
19
- });
20
- interface ServeResult {
21
- GET(req: NextRequest): Promise<Response>;
22
- POST(req: NextRequest): Promise<Response>;
23
- PUT(req: NextRequest): Promise<Response>;
24
- PATCH(req: NextRequest): Promise<Response>;
25
- DELETE(req: NextRequest): Promise<Response>;
26
- }
27
- declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
28
-
29
- export { FetchHandler, type ServeOptions, type ServeResult, serve };
@@ -1,29 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.js';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { NextRequest } from 'next/server';
5
- import { C as Context } from '../../shared/server.MZvbGc3n.js';
6
- import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
7
- import '../../shared/server.BG5ftPWa.js';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.DCcCuA52.js';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [NextRequest]>;
17
- } : {
18
- context: Value<T, [NextRequest]>;
19
- });
20
- interface ServeResult {
21
- GET(req: NextRequest): Promise<Response>;
22
- POST(req: NextRequest): Promise<Response>;
23
- PUT(req: NextRequest): Promise<Response>;
24
- PATCH(req: NextRequest): Promise<Response>;
25
- DELETE(req: NextRequest): Promise<Response>;
26
- }
27
- declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
28
-
29
- export { FetchHandler, type ServeOptions, type ServeResult, serve };
@@ -1,29 +0,0 @@
1
- export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
2
- import { value } from '@orpc/shared';
3
- import '@orpc/client';
4
- import '@orpc/client/standard';
5
- import '../../shared/server.DnR6v9pj.mjs';
6
- import '../../shared/server.BtxZnWJ9.mjs';
7
- import '@orpc/contract';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.BVwwTHyO.mjs';
10
-
11
- function serve(handler, ...[options]) {
12
- const main = async (req) => {
13
- const context = await value(options?.context ?? {}, req);
14
- const { matched, response } = await handler.handle(req, { ...options, context });
15
- if (matched) {
16
- return response;
17
- }
18
- return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
19
- };
20
- return {
21
- GET: main,
22
- POST: main,
23
- PUT: main,
24
- PATCH: main,
25
- DELETE: main
26
- };
27
- }
28
-
29
- export { serve };
@@ -1,98 +0,0 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
3
- import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DnR6v9pj.mjs';
4
- import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
5
- import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
6
- import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
7
-
8
- class BodyLimitPlugin {
9
- maxBodySize;
10
- constructor(options) {
11
- this.maxBodySize = options.maxBodySize;
12
- }
13
- initRuntimeAdapter(options) {
14
- options.adapterInterceptors ??= [];
15
- options.adapterInterceptors.push(async (options2) => {
16
- if (!options2.request.body) {
17
- return options2.next();
18
- }
19
- let currentBodySize = 0;
20
- const rawReader = options2.request.body.getReader();
21
- const reader = new ReadableStream({
22
- start: async (controller) => {
23
- try {
24
- if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
25
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
26
- return;
27
- }
28
- while (true) {
29
- const { done, value } = await rawReader.read();
30
- if (done) {
31
- break;
32
- }
33
- currentBodySize += value.length;
34
- if (currentBodySize > this.maxBodySize) {
35
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
36
- break;
37
- }
38
- controller.enqueue(value);
39
- }
40
- } finally {
41
- controller.close();
42
- }
43
- }
44
- });
45
- const requestInit = { body: reader, duplex: "half" };
46
- return options2.next({
47
- ...options2,
48
- request: new Request(options2.request, requestInit)
49
- });
50
- });
51
- }
52
- }
53
-
54
- class FetchHandler {
55
- constructor(standardHandler, options = {}) {
56
- this.standardHandler = standardHandler;
57
- for (const plugin of toArray(options.plugins)) {
58
- plugin.initRuntimeAdapter?.(options);
59
- }
60
- this.adapterInterceptors = toArray(options.adapterInterceptors);
61
- this.toFetchResponseOptions = options;
62
- }
63
- toFetchResponseOptions;
64
- adapterInterceptors;
65
- async handle(request, ...rest) {
66
- return intercept(
67
- this.adapterInterceptors,
68
- {
69
- ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
70
- request,
71
- toFetchResponseOptions: this.toFetchResponseOptions
72
- },
73
- async ({ request: request2, toFetchResponseOptions, ...options }) => {
74
- const standardRequest = toStandardLazyRequest(request2);
75
- const result = await this.standardHandler.handle(standardRequest, options);
76
- if (!result.matched) {
77
- return result;
78
- }
79
- return {
80
- matched: true,
81
- response: toFetchResponse(result.response, toFetchResponseOptions)
82
- };
83
- }
84
- );
85
- }
86
- }
87
-
88
- class RPCHandler extends FetchHandler {
89
- constructor(router, options = {}) {
90
- const jsonSerializer = new StandardRPCJsonSerializer(options);
91
- const serializer = new StandardRPCSerializer(jsonSerializer);
92
- const matcher = new StandardRPCMatcher();
93
- const codec = new StandardRPCCodec(serializer);
94
- super(new StandardHandler(router, matcher, codec, options), options);
95
- }
96
- }
97
-
98
- export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
@@ -1,8 +0,0 @@
1
- import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context } from './server.MZvbGc3n.mjs';
3
- import { a as StandardHandlerOptions } from './server.DJqfB27m.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.MZvbGc3n.js';
3
- import { a as StandardHandlerOptions } from './server.23VRZIfj.js';
4
-
5
- interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardRPCHandlerOptions as S };