@orpc/server 0.0.0-next.7d3bd71 → 0.0.0-next.7db48bf

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 (116) hide show
  1. package/README.md +131 -0
  2. package/dist/adapters/aws-lambda/index.d.mts +46 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +46 -0
  4. package/dist/adapters/aws-lambda/index.mjs +42 -0
  5. package/dist/adapters/bun-ws/index.d.mts +36 -0
  6. package/dist/adapters/bun-ws/index.d.ts +36 -0
  7. package/dist/adapters/bun-ws/index.mjs +47 -0
  8. package/dist/adapters/crossws/index.d.mts +33 -0
  9. package/dist/adapters/crossws/index.d.ts +33 -0
  10. package/dist/adapters/crossws/index.mjs +45 -0
  11. package/dist/adapters/fastify/index.d.mts +53 -0
  12. package/dist/adapters/fastify/index.d.ts +53 -0
  13. package/dist/adapters/fastify/index.mjs +54 -0
  14. package/dist/adapters/fetch/index.d.mts +124 -0
  15. package/dist/adapters/fetch/index.d.ts +124 -0
  16. package/dist/adapters/fetch/index.mjs +180 -0
  17. package/dist/adapters/message-port/index.d.mts +57 -0
  18. package/dist/adapters/message-port/index.d.ts +57 -0
  19. package/dist/adapters/message-port/index.mjs +55 -0
  20. package/dist/adapters/node/index.d.mts +99 -0
  21. package/dist/adapters/node/index.d.ts +99 -0
  22. package/dist/adapters/node/index.mjs +152 -0
  23. package/dist/adapters/standard/index.d.mts +21 -0
  24. package/dist/adapters/standard/index.d.ts +21 -0
  25. package/dist/adapters/standard/index.mjs +8 -0
  26. package/dist/adapters/standard-peer/index.d.mts +18 -0
  27. package/dist/adapters/standard-peer/index.d.ts +18 -0
  28. package/dist/adapters/standard-peer/index.mjs +7 -0
  29. package/dist/adapters/websocket/index.d.mts +56 -0
  30. package/dist/adapters/websocket/index.d.ts +56 -0
  31. package/dist/adapters/websocket/index.mjs +67 -0
  32. package/dist/adapters/ws/index.d.mts +31 -0
  33. package/dist/adapters/ws/index.d.ts +31 -0
  34. package/dist/adapters/ws/index.mjs +37 -0
  35. package/dist/helpers/index.d.mts +149 -0
  36. package/dist/helpers/index.d.ts +149 -0
  37. package/dist/helpers/index.mjs +198 -0
  38. package/dist/hibernation/index.d.mts +44 -0
  39. package/dist/hibernation/index.d.ts +44 -0
  40. package/dist/hibernation/index.mjs +65 -0
  41. package/dist/index.d.mts +803 -0
  42. package/dist/index.d.ts +803 -0
  43. package/dist/index.mjs +492 -0
  44. package/dist/plugins/index.d.mts +172 -0
  45. package/dist/plugins/index.d.ts +172 -0
  46. package/dist/plugins/index.mjs +287 -0
  47. package/dist/shared/server.B4BGqy3Y.d.mts +193 -0
  48. package/dist/shared/server.B4BGqy3Y.d.ts +193 -0
  49. package/dist/shared/server.Bxx6tqNe.mjs +219 -0
  50. package/dist/shared/server.COL12UTb.d.ts +32 -0
  51. package/dist/shared/server.CVKCo60T.d.mts +12 -0
  52. package/dist/shared/server.Cb6yD7DZ.d.ts +42 -0
  53. package/dist/shared/server.Ck-gOLzq.d.mts +32 -0
  54. package/dist/shared/server.DBCUJijK.d.mts +74 -0
  55. package/dist/shared/server.DNtJ-p60.d.ts +12 -0
  56. package/dist/shared/server.DPIFWpxG.d.ts +74 -0
  57. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  58. package/dist/shared/server.Ds4HPpvH.mjs +409 -0
  59. package/dist/shared/server.DzV1hr3z.d.mts +42 -0
  60. package/dist/shared/server.TEVCLCFC.mjs +39 -0
  61. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  62. package/package.json +94 -39
  63. package/dist/chunk-47YYO5JS.js +0 -32
  64. package/dist/chunk-77FU7QSO.js +0 -181
  65. package/dist/chunk-MHVECKBC.js +0 -421
  66. package/dist/chunk-WQNNSBXW.js +0 -120
  67. package/dist/fetch.js +0 -10
  68. package/dist/hono.js +0 -34
  69. package/dist/index.js +0 -413
  70. package/dist/next.js +0 -31
  71. package/dist/node.js +0 -31
  72. package/dist/plugins.js +0 -11
  73. package/dist/src/adapters/fetch/index.d.ts +0 -3
  74. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  75. package/dist/src/adapters/fetch/types.d.ts +0 -14
  76. package/dist/src/adapters/hono/index.d.ts +0 -3
  77. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  78. package/dist/src/adapters/next/index.d.ts +0 -3
  79. package/dist/src/adapters/next/serve.d.ts +0 -19
  80. package/dist/src/adapters/node/index.d.ts +0 -3
  81. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  82. package/dist/src/adapters/node/types.d.ts +0 -22
  83. package/dist/src/adapters/standard/handler.d.ts +0 -53
  84. package/dist/src/adapters/standard/index.d.ts +0 -6
  85. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  86. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  87. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  88. package/dist/src/adapters/standard/types.d.ts +0 -21
  89. package/dist/src/builder-variants.d.ts +0 -75
  90. package/dist/src/builder.d.ts +0 -58
  91. package/dist/src/config.d.ts +0 -6
  92. package/dist/src/context.d.ts +0 -8
  93. package/dist/src/error.d.ts +0 -12
  94. package/dist/src/hidden.d.ts +0 -8
  95. package/dist/src/implementer-procedure.d.ts +0 -33
  96. package/dist/src/implementer-variants.d.ts +0 -18
  97. package/dist/src/implementer.d.ts +0 -29
  98. package/dist/src/index.d.ts +0 -25
  99. package/dist/src/lazy-utils.d.ts +0 -6
  100. package/dist/src/lazy.d.ts +0 -22
  101. package/dist/src/middleware-decorated.d.ts +0 -11
  102. package/dist/src/middleware-utils.d.ts +0 -5
  103. package/dist/src/middleware.d.ts +0 -38
  104. package/dist/src/plugins/base.d.ts +0 -11
  105. package/dist/src/plugins/cors.d.ts +0 -19
  106. package/dist/src/plugins/index.d.ts +0 -4
  107. package/dist/src/plugins/response-headers.d.ts +0 -10
  108. package/dist/src/procedure-client.d.ts +0 -33
  109. package/dist/src/procedure-decorated.d.ts +0 -24
  110. package/dist/src/procedure-utils.d.ts +0 -19
  111. package/dist/src/procedure.d.ts +0 -31
  112. package/dist/src/router-accessible-lazy.d.ts +0 -8
  113. package/dist/src/router-client.d.ts +0 -12
  114. package/dist/src/router.d.ts +0 -30
  115. package/dist/src/utils.d.ts +0 -24
  116. package/dist/standard.js +0 -13
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.7d3bd71",
4
+ "version": "0.0.0-next.7db48bf",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,66 +15,121 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
+ },
22
+ "./helpers": {
23
+ "types": "./dist/helpers/index.d.mts",
24
+ "import": "./dist/helpers/index.mjs",
25
+ "default": "./dist/helpers/index.mjs"
21
26
  },
22
27
  "./plugins": {
23
- "types": "./dist/src/plugins/index.d.ts",
24
- "import": "./dist/plugins.js",
25
- "default": "./dist/plugins.js"
28
+ "types": "./dist/plugins/index.d.mts",
29
+ "import": "./dist/plugins/index.mjs",
30
+ "default": "./dist/plugins/index.mjs"
31
+ },
32
+ "./hibernation": {
33
+ "types": "./dist/hibernation/index.d.mts",
34
+ "import": "./dist/hibernation/index.mjs",
35
+ "default": "./dist/hibernation/index.mjs"
26
36
  },
27
37
  "./standard": {
28
- "types": "./dist/src/adapters/standard/index.d.ts",
29
- "import": "./dist/standard.js",
30
- "default": "./dist/standard.js"
38
+ "types": "./dist/adapters/standard/index.d.mts",
39
+ "import": "./dist/adapters/standard/index.mjs",
40
+ "default": "./dist/adapters/standard/index.mjs"
41
+ },
42
+ "./standard-peer": {
43
+ "types": "./dist/adapters/standard-peer/index.d.mts",
44
+ "import": "./dist/adapters/standard-peer/index.mjs",
45
+ "default": "./dist/adapters/standard-peer/index.mjs"
31
46
  },
32
47
  "./fetch": {
33
- "types": "./dist/src/adapters/fetch/index.d.ts",
34
- "import": "./dist/fetch.js",
35
- "default": "./dist/fetch.js"
48
+ "types": "./dist/adapters/fetch/index.d.mts",
49
+ "import": "./dist/adapters/fetch/index.mjs",
50
+ "default": "./dist/adapters/fetch/index.mjs"
36
51
  },
37
- "./hono": {
38
- "types": "./dist/src/adapters/hono/index.d.ts",
39
- "import": "./dist/hono.js",
40
- "default": "./dist/hono.js"
52
+ "./node": {
53
+ "types": "./dist/adapters/node/index.d.mts",
54
+ "import": "./dist/adapters/node/index.mjs",
55
+ "default": "./dist/adapters/node/index.mjs"
41
56
  },
42
- "./next": {
43
- "types": "./dist/src/adapters/next/index.d.ts",
44
- "import": "./dist/next.js",
45
- "default": "./dist/next.js"
57
+ "./fastify": {
58
+ "types": "./dist/adapters/fastify/index.d.mts",
59
+ "import": "./dist/adapters/fastify/index.mjs",
60
+ "default": "./dist/adapters/fastify/index.mjs"
46
61
  },
47
- "./node": {
48
- "types": "./dist/src/adapters/node/index.d.ts",
49
- "import": "./dist/node.js",
50
- "default": "./dist/node.js"
62
+ "./aws-lambda": {
63
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
64
+ "import": "./dist/adapters/aws-lambda/index.mjs",
65
+ "default": "./dist/adapters/aws-lambda/index.mjs"
66
+ },
67
+ "./websocket": {
68
+ "types": "./dist/adapters/websocket/index.d.mts",
69
+ "import": "./dist/adapters/websocket/index.mjs",
70
+ "default": "./dist/adapters/websocket/index.mjs"
51
71
  },
52
- "./🔒/*": {
53
- "types": "./dist/src/*.d.ts"
72
+ "./crossws": {
73
+ "types": "./dist/adapters/crossws/index.d.mts",
74
+ "import": "./dist/adapters/crossws/index.mjs",
75
+ "default": "./dist/adapters/crossws/index.mjs"
76
+ },
77
+ "./ws": {
78
+ "types": "./dist/adapters/ws/index.d.mts",
79
+ "import": "./dist/adapters/ws/index.mjs",
80
+ "default": "./dist/adapters/ws/index.mjs"
81
+ },
82
+ "./bun-ws": {
83
+ "types": "./dist/adapters/bun-ws/index.d.mts",
84
+ "import": "./dist/adapters/bun-ws/index.mjs",
85
+ "default": "./dist/adapters/bun-ws/index.mjs"
86
+ },
87
+ "./message-port": {
88
+ "types": "./dist/adapters/message-port/index.d.mts",
89
+ "import": "./dist/adapters/message-port/index.mjs",
90
+ "default": "./dist/adapters/message-port/index.mjs"
54
91
  }
55
92
  },
56
93
  "files": [
57
- "!**/*.map",
58
- "!**/*.tsbuildinfo",
59
94
  "dist"
60
95
  ],
61
96
  "peerDependencies": {
62
- "hono": ">=4.6.0",
63
- "next": ">=14.0.0"
97
+ "crossws": ">=0.3.4",
98
+ "ws": ">=8.18.1"
99
+ },
100
+ "peerDependenciesMeta": {
101
+ "crossws": {
102
+ "optional": true
103
+ },
104
+ "ws": {
105
+ "optional": true
106
+ }
64
107
  },
65
108
  "dependencies": {
66
- "@orpc/server-standard": "^0.4.0",
67
- "@orpc/server-standard-fetch": "^0.4.0",
68
- "@orpc/server-standard-node": "^0.4.0",
69
- "@orpc/shared": "0.0.0-next.7d3bd71",
70
- "@orpc/contract": "0.0.0-next.7d3bd71",
71
- "@orpc/client": "0.0.0-next.7d3bd71"
109
+ "cookie": "^1.0.2",
110
+ "@orpc/client": "0.0.0-next.7db48bf",
111
+ "@orpc/contract": "0.0.0-next.7db48bf",
112
+ "@orpc/interop": "0.0.0-next.7db48bf",
113
+ "@orpc/shared": "0.0.0-next.7db48bf",
114
+ "@orpc/standard-server": "0.0.0-next.7db48bf",
115
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.7db48bf",
116
+ "@orpc/standard-server-fetch": "0.0.0-next.7db48bf",
117
+ "@orpc/standard-server-fastify": "0.0.0-next.7db48bf",
118
+ "@orpc/standard-server-node": "0.0.0-next.7db48bf",
119
+ "@orpc/standard-server-peer": "0.0.0-next.7db48bf"
72
120
  },
73
121
  "devDependencies": {
74
- "light-my-request": "^6.5.1"
122
+ "@tanstack/router-core": "^1.133.36",
123
+ "@types/ws": "^8.18.1",
124
+ "crossws": "^0.4.1",
125
+ "fastify": "^5.6.1",
126
+ "next": "^16.0.1",
127
+ "supertest": "^7.1.4",
128
+ "ws": "^8.18.3",
129
+ "zod": "^4.1.12"
75
130
  },
76
131
  "scripts": {
77
- "build": "tsup --onSuccess='tsc -b --noCheck'",
132
+ "build": "unbuild",
78
133
  "build:watch": "pnpm run build --watch",
79
134
  "type:check": "tsc -b"
80
135
  }
@@ -1,32 +0,0 @@
1
- import {
2
- RPCCodec,
3
- RPCMatcher,
4
- StandardHandler
5
- } from "./chunk-77FU7QSO.js";
6
-
7
- // src/adapters/fetch/rpc-handler.ts
8
- import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
9
- var RPCHandler = class {
10
- standardHandler;
11
- constructor(router, options) {
12
- const matcher = options?.matcher ?? new RPCMatcher();
13
- const codec = options?.codec ?? new RPCCodec();
14
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
15
- }
16
- async handle(request, ...rest) {
17
- const standardRequest = toStandardRequest(request);
18
- const result = await this.standardHandler.handle(standardRequest, ...rest);
19
- if (!result.matched) {
20
- return result;
21
- }
22
- return {
23
- matched: true,
24
- response: toFetchResponse(result.response)
25
- };
26
- }
27
- };
28
-
29
- export {
30
- RPCHandler
31
- };
32
- //# sourceMappingURL=chunk-47YYO5JS.js.map
@@ -1,181 +0,0 @@
1
- import {
2
- convertPathToHttpPath,
3
- createContractedProcedure,
4
- createProcedureClient,
5
- eachContractProcedure,
6
- getRouterChild,
7
- isProcedure,
8
- unlazy
9
- } from "./chunk-MHVECKBC.js";
10
- import {
11
- CompositePlugin
12
- } from "./chunk-WQNNSBXW.js";
13
-
14
- // src/adapters/standard/handler.ts
15
- import { ORPCError, toORPCError } from "@orpc/client";
16
- import { intercept, trim } from "@orpc/shared";
17
- var StandardHandler = class {
18
- constructor(router, matcher, codec, options = {}) {
19
- this.matcher = matcher;
20
- this.codec = codec;
21
- this.options = options;
22
- this.plugin = new CompositePlugin(options.plugins);
23
- this.plugin.init(this.options);
24
- this.matcher.init(router);
25
- }
26
- plugin;
27
- handle(request, ...[options]) {
28
- return intercept(
29
- this.options.rootInterceptors ?? [],
30
- {
31
- request,
32
- ...options,
33
- context: options?.context ?? {}
34
- // context is optional only when all fields are optional so we can safely force it to have a context
35
- },
36
- async (interceptorOptions) => {
37
- let isDecoding = false;
38
- try {
39
- return await intercept(
40
- this.options.interceptors ?? [],
41
- interceptorOptions,
42
- async (interceptorOptions2) => {
43
- const method = interceptorOptions2.request.method;
44
- const url = interceptorOptions2.request.url;
45
- const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
46
- const match = await this.matcher.match(method, pathname);
47
- if (!match) {
48
- return { matched: false, response: void 0 };
49
- }
50
- const client = createProcedureClient(match.procedure, {
51
- context: interceptorOptions2.context,
52
- path: match.path,
53
- interceptors: this.options.clientInterceptors
54
- });
55
- isDecoding = true;
56
- const input = await this.codec.decode(request, match.params, match.procedure);
57
- isDecoding = false;
58
- const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
59
- const output = await client(input, { signal: request.signal, lastEventId });
60
- const response = this.codec.encode(output, match.procedure);
61
- return {
62
- matched: true,
63
- response
64
- };
65
- }
66
- );
67
- } catch (e) {
68
- const error = isDecoding ? new ORPCError("BAD_REQUEST", {
69
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
70
- cause: e
71
- }) : toORPCError(e);
72
- const response = this.codec.encodeError(error);
73
- return {
74
- matched: true,
75
- response
76
- };
77
- }
78
- }
79
- );
80
- }
81
- };
82
-
83
- // src/adapters/standard/rpc-codec.ts
84
- import { RPCSerializer } from "@orpc/client/rpc";
85
- var RPCCodec = class {
86
- serializer;
87
- constructor(options = {}) {
88
- this.serializer = options.serializer ?? new RPCSerializer();
89
- }
90
- async decode(request, _params, _procedure) {
91
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
92
- return this.serializer.deserialize(serialized);
93
- }
94
- encode(output, _procedure) {
95
- return {
96
- status: 200,
97
- headers: {},
98
- body: this.serializer.serialize(output)
99
- };
100
- }
101
- encodeError(error) {
102
- return {
103
- status: error.status,
104
- headers: {},
105
- body: this.serializer.serialize(error.toJSON())
106
- };
107
- }
108
- };
109
-
110
- // src/adapters/standard/rpc-matcher.ts
111
- var RPCMatcher = class {
112
- tree = {};
113
- pendingRouters = [];
114
- init(router, path = []) {
115
- const laziedOptions = eachContractProcedure({
116
- router,
117
- path
118
- }, ({ path: path2, contract }) => {
119
- const httpPath = convertPathToHttpPath(path2);
120
- if (isProcedure(contract)) {
121
- this.tree[httpPath] = {
122
- path: path2,
123
- contract,
124
- procedure: contract,
125
- // this mean dev not used contract-first so we can used contract as procedure directly
126
- router
127
- };
128
- } else {
129
- this.tree[httpPath] = {
130
- path: path2,
131
- contract,
132
- procedure: void 0,
133
- router
134
- };
135
- }
136
- });
137
- this.pendingRouters.push(...laziedOptions.map((option) => ({
138
- ...option,
139
- httpPathPrefix: convertPathToHttpPath(option.path)
140
- })));
141
- }
142
- async match(_method, pathname) {
143
- if (this.pendingRouters.length) {
144
- const newPendingRouters = [];
145
- for (const pendingRouter of this.pendingRouters) {
146
- if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
147
- const { default: router } = await unlazy(pendingRouter.lazied);
148
- this.init(router, pendingRouter.path);
149
- } else {
150
- newPendingRouters.push(pendingRouter);
151
- }
152
- }
153
- this.pendingRouters = newPendingRouters;
154
- }
155
- const match = this.tree[pathname];
156
- if (!match) {
157
- return void 0;
158
- }
159
- if (!match.procedure) {
160
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
161
- if (!isProcedure(maybeProcedure)) {
162
- throw new Error(`
163
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
164
- Ensure that the procedure is correctly defined and matches the expected contract.
165
- `);
166
- }
167
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
168
- }
169
- return {
170
- path: match.path,
171
- procedure: match.procedure
172
- };
173
- }
174
- };
175
-
176
- export {
177
- StandardHandler,
178
- RPCCodec,
179
- RPCMatcher
180
- };
181
- //# sourceMappingURL=chunk-77FU7QSO.js.map