@trpc/server 11.0.0-next.91 → 11.0.0-next.92

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.
@@ -14,6 +14,7 @@ require('../../config-60fc2667.js');
14
14
  require('../../transformTRPCResponse-e65f34e9.js');
15
15
  require('../../contentType-90bad7bb.js');
16
16
  require('../../observable-464116ac.js');
17
+ require('../../parseTRPCMessage-1377f305.js');
17
18
 
18
19
  async function fastifyRequestHandler(opts) {
19
20
  const createContext = async (innerOpts)=>{
@@ -10,6 +10,7 @@ import '../../config-ab4c1c6b.mjs';
10
10
  import '../../transformTRPCResponse-1153b421.mjs';
11
11
  import '../../contentType-93515a46.mjs';
12
12
  import '../../observable-ade1bad8.mjs';
13
+ import '../../parseTRPCMessage-a0f17853.mjs';
13
14
 
14
15
  async function fastifyRequestHandler(opts) {
15
16
  const createContext = async (innerOpts)=>{
@@ -4,11 +4,8 @@ import { IncomingMessage } from 'http';
4
4
  import ws from 'ws';
5
5
  import { AnyRouter, inferRouterContext } from '../core';
6
6
  import { BaseHandlerOptions } from '../internals/types';
7
- import { TRPCClientOutgoingMessage } from '../rpc';
8
- import { CombinedDataTransformer } from '../transformer';
9
7
  import { MaybePromise } from '../types';
10
8
  import { NodeHTTPCreateContextFnOptions } from './node-http';
11
- export declare function parseMessage(obj: unknown, transformer: CombinedDataTransformer): TRPCClientOutgoingMessage;
12
9
  /**
13
10
  * @public
14
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/adapters/ws.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,SAAS,EAET,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAEL,yBAAyB,EAG1B,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAyC7D,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,uBAAuB,GACnC,yBAAyB,CA2B3B;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,8BAA8B,CAAC,eAAe,EAAE,EAAE,CAAC,EACnD,MAAM,CACP,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1D,IAAI,EAAE,yBAAyB,KAC5B,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IAAI,kBAAkB,CAC3E,OAAO,EACP,eAAe,CAChB,GACC,CAAC,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,GACvC;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CAC7C,GACD;IACE;;QAEI;IACJ,aAAa,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CAC5C,CAAC,GAAG;IACP,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CAC1B,CAAC;AAEJ,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EAwQjC"}
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/adapters/ws.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,SAAS,EAAiB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAWxD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,8BAA8B,CAAC,eAAe,EAAE,EAAE,CAAC,EACnD,MAAM,CACP,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1D,IAAI,EAAE,yBAAyB,KAC5B,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IAAI,kBAAkB,CAC3E,OAAO,EACP,eAAe,CAChB,GACC,CAAC,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,GACvC;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CAC7C,GACD;IACE;;QAEI;IACJ,aAAa,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CAC5C,CAAC,GAAG;IACP,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CAC1B,CAAC;AAEJ,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EAwQjC"}
@@ -6,62 +6,11 @@ var router = require('../router-3c22fe56.js');
6
6
  var TRPCError = require('../TRPCError-ae7b67e8.js');
7
7
  require('../config-60fc2667.js');
8
8
  var observable = require('../observable-464116ac.js');
9
+ require('../codes-87f6824b.js');
10
+ var parseTRPCMessage = require('../parseTRPCMessage-1377f305.js');
9
11
  var transformTRPCResponse = require('../transformTRPCResponse-e65f34e9.js');
10
12
  require('../index-784ff647.js');
11
- require('../codes-87f6824b.js');
12
13
 
13
- /* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
14
- if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
15
- throw new Error('Not an object');
16
- }
17
- }
18
- /* istanbul ignore next -- @preserve */ function assertIsProcedureType(obj) {
19
- if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
20
- throw new Error('Invalid procedure type');
21
- }
22
- }
23
- /* istanbul ignore next -- @preserve */ function assertIsRequestId(obj) {
24
- if (obj !== null && typeof obj === 'number' && isNaN(obj) && typeof obj !== 'string') {
25
- throw new Error('Invalid request id');
26
- }
27
- }
28
- /* istanbul ignore next -- @preserve */ function assertIsString(obj) {
29
- if (typeof obj !== 'string') {
30
- throw new Error('Invalid string');
31
- }
32
- }
33
- /* istanbul ignore next -- @preserve */ function assertIsJSONRPC2OrUndefined(obj) {
34
- if (typeof obj !== 'undefined' && obj !== '2.0') {
35
- throw new Error('Must be JSONRPC 2.0');
36
- }
37
- }
38
- function parseMessage(obj, transformer) {
39
- assertIsObject(obj);
40
- const { method , params , id , jsonrpc } = obj;
41
- assertIsRequestId(id);
42
- assertIsJSONRPC2OrUndefined(jsonrpc);
43
- if (method === 'subscription.stop') {
44
- return {
45
- id,
46
- jsonrpc,
47
- method
48
- };
49
- }
50
- assertIsProcedureType(method);
51
- assertIsObject(params);
52
- const { input: rawInput , path } = params;
53
- assertIsString(path);
54
- const input = transformer.input.deserialize(rawInput);
55
- return {
56
- id,
57
- jsonrpc,
58
- method,
59
- params: {
60
- input,
61
- path
62
- }
63
- };
64
- }
65
14
  function applyWSSHandler(opts) {
66
15
  const { wss , createContext , router: router$1 } = opts;
67
16
  const { transformer } = router$1._def._config;
@@ -236,7 +185,7 @@ function applyWSSHandler(opts) {
236
185
  const msgs = Array.isArray(msgJSON) ? msgJSON : [
237
186
  msgJSON
238
187
  ];
239
- const promises = msgs.map((raw)=>parseMessage(raw, transformer)).map(handleRequest);
188
+ const promises = msgs.map((raw)=>parseTRPCMessage.parseTRPCMessage(raw, transformer)).map(handleRequest);
240
189
  await Promise.all(promises);
241
190
  } catch (cause) {
242
191
  const error = new TRPCError.TRPCError({
@@ -325,4 +274,3 @@ function applyWSSHandler(opts) {
325
274
  }
326
275
 
327
276
  exports.applyWSSHandler = applyWSSHandler;
328
- exports.parseMessage = parseMessage;
@@ -2,62 +2,11 @@ import { b as callProcedure } from '../router-5274e533.mjs';
2
2
  import { T as TRPCError, g as getTRPCErrorFromUnknown } from '../TRPCError-816ff32e.mjs';
3
3
  import '../config-ab4c1c6b.mjs';
4
4
  import { i as isObservable } from '../observable-ade1bad8.mjs';
5
+ import '../codes-c924c3db.mjs';
6
+ import { p as parseTRPCMessage } from '../parseTRPCMessage-a0f17853.mjs';
5
7
  import { g as getErrorShape, t as transformTRPCResponse } from '../transformTRPCResponse-1153b421.mjs';
6
8
  import '../index-f91d720c.mjs';
7
- import '../codes-c924c3db.mjs';
8
9
 
9
- /* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
10
- if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
11
- throw new Error('Not an object');
12
- }
13
- }
14
- /* istanbul ignore next -- @preserve */ function assertIsProcedureType(obj) {
15
- if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
16
- throw new Error('Invalid procedure type');
17
- }
18
- }
19
- /* istanbul ignore next -- @preserve */ function assertIsRequestId(obj) {
20
- if (obj !== null && typeof obj === 'number' && isNaN(obj) && typeof obj !== 'string') {
21
- throw new Error('Invalid request id');
22
- }
23
- }
24
- /* istanbul ignore next -- @preserve */ function assertIsString(obj) {
25
- if (typeof obj !== 'string') {
26
- throw new Error('Invalid string');
27
- }
28
- }
29
- /* istanbul ignore next -- @preserve */ function assertIsJSONRPC2OrUndefined(obj) {
30
- if (typeof obj !== 'undefined' && obj !== '2.0') {
31
- throw new Error('Must be JSONRPC 2.0');
32
- }
33
- }
34
- function parseMessage(obj, transformer) {
35
- assertIsObject(obj);
36
- const { method , params , id , jsonrpc } = obj;
37
- assertIsRequestId(id);
38
- assertIsJSONRPC2OrUndefined(jsonrpc);
39
- if (method === 'subscription.stop') {
40
- return {
41
- id,
42
- jsonrpc,
43
- method
44
- };
45
- }
46
- assertIsProcedureType(method);
47
- assertIsObject(params);
48
- const { input: rawInput , path } = params;
49
- assertIsString(path);
50
- const input = transformer.input.deserialize(rawInput);
51
- return {
52
- id,
53
- jsonrpc,
54
- method,
55
- params: {
56
- input,
57
- path
58
- }
59
- };
60
- }
61
10
  function applyWSSHandler(opts) {
62
11
  const { wss , createContext , router } = opts;
63
12
  const { transformer } = router._def._config;
@@ -232,7 +181,7 @@ function applyWSSHandler(opts) {
232
181
  const msgs = Array.isArray(msgJSON) ? msgJSON : [
233
182
  msgJSON
234
183
  ];
235
- const promises = msgs.map((raw)=>parseMessage(raw, transformer)).map(handleRequest);
184
+ const promises = msgs.map((raw)=>parseTRPCMessage(raw, transformer)).map(handleRequest);
236
185
  await Promise.all(promises);
237
186
  } catch (cause) {
238
187
  const error = new TRPCError({
@@ -320,4 +269,4 @@ function applyWSSHandler(opts) {
320
269
  };
321
270
  }
322
271
 
323
- export { applyWSSHandler, parseMessage };
272
+ export { applyWSSHandler };
@@ -1,21 +1,20 @@
1
1
  {
2
- "bundleSize": 96893,
3
- "bundleOrigSize": 150082,
4
- "bundleReduction": 35.44,
2
+ "bundleSize": 96932,
3
+ "bundleOrigSize": 150259,
4
+ "bundleReduction": 35.49,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/adapters/ws.ts",
8
- "size": 11355,
9
- "origSize": 10725,
8
+ "size": 9757,
9
+ "origSize": 8857,
10
10
  "renderedExports": [
11
- "parseMessage",
12
11
  "applyWSSHandler"
13
12
  ],
14
13
  "removedExports": [],
15
14
  "dependents": [
16
15
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
17
16
  ],
18
- "percent": 11.72,
17
+ "percent": 10.07,
19
18
  "reduction": 0
20
19
  },
21
20
  {
@@ -103,7 +102,7 @@
103
102
  "dependents": [
104
103
  "/home/runner/work/trpc/trpc/node_modules/.pnpm/@web3-storage+multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js"
105
104
  ],
106
- "percent": 4.6,
105
+ "percent": 4.59,
107
106
  "reduction": 35.63
108
107
  },
109
108
  {
@@ -264,7 +263,7 @@
264
263
  ],
265
264
  "removedExports": [],
266
265
  "dependents": [],
267
- "percent": 1.75,
266
+ "percent": 1.74,
268
267
  "reduction": 0
269
268
  },
270
269
  {
@@ -282,6 +281,20 @@
282
281
  "percent": 1.69,
283
282
  "reduction": 34.21
284
283
  },
284
+ {
285
+ "id": "/src/rpc/parseTRPCMessage.ts",
286
+ "size": 1637,
287
+ "origSize": 2009,
288
+ "renderedExports": [
289
+ "parseTRPCMessage"
290
+ ],
291
+ "removedExports": [],
292
+ "dependents": [
293
+ "/src/rpc/index.ts"
294
+ ],
295
+ "percent": 1.69,
296
+ "reduction": 18.52
297
+ },
285
298
  {
286
299
  "id": "/src/error/TRPCError.ts",
287
300
  "size": 1604,
@@ -303,7 +316,7 @@
303
316
  "/src/http/resolveHTTPResponse.ts",
304
317
  "/src/http/contentType.ts"
305
318
  ],
306
- "percent": 1.66,
319
+ "percent": 1.65,
307
320
  "reduction": 10.69
308
321
  },
309
322
  {
@@ -335,7 +348,7 @@
335
348
  "/src/shared/index.ts",
336
349
  "/src/core/router.ts"
337
350
  ],
338
- "percent": 1.56,
351
+ "percent": 1.55,
339
352
  "reduction": 5.58
340
353
  },
341
354
  {
@@ -409,7 +422,7 @@
409
422
  "dependents": [
410
423
  "/src/observable/index.ts"
411
424
  ],
412
- "percent": 1.23,
425
+ "percent": 1.22,
413
426
  "reduction": 0
414
427
  },
415
428
  {
@@ -860,10 +873,11 @@
860
873
  {
861
874
  "id": "/src/rpc/index.ts",
862
875
  "size": 0,
863
- "origSize": 54,
876
+ "origSize": 90,
864
877
  "renderedExports": [],
865
878
  "removedExports": [],
866
879
  "dependents": [
880
+ "/src/adapters/ws.ts",
867
881
  "/src/core/router.ts",
868
882
  "/src/http/getHTTPStatusCode.ts",
869
883
  "/src/shared/getErrorShape.ts"
@@ -906,5 +920,5 @@
906
920
  "reduction": 100
907
921
  }
908
922
  ],
909
- "moduleCount": 61
923
+ "moduleCount": 62
910
924
  }
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ /* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
4
+ if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
5
+ throw new Error('Not an object');
6
+ }
7
+ }
8
+ /* istanbul ignore next -- @preserve */ function assertIsProcedureType(obj) {
9
+ if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
10
+ throw new Error('Invalid procedure type');
11
+ }
12
+ }
13
+ /* istanbul ignore next -- @preserve */ function assertIsRequestId(obj) {
14
+ if (obj !== null && typeof obj === 'number' && isNaN(obj) && typeof obj !== 'string') {
15
+ throw new Error('Invalid request id');
16
+ }
17
+ }
18
+ /* istanbul ignore next -- @preserve */ function assertIsString(obj) {
19
+ if (typeof obj !== 'string') {
20
+ throw new Error('Invalid string');
21
+ }
22
+ }
23
+ /* istanbul ignore next -- @preserve */ function assertIsJSONRPC2OrUndefined(obj) {
24
+ if (typeof obj !== 'undefined' && obj !== '2.0') {
25
+ throw new Error('Must be JSONRPC 2.0');
26
+ }
27
+ }
28
+ /** @public */ function parseTRPCMessage(obj, transformer) {
29
+ assertIsObject(obj);
30
+ const { id , jsonrpc , method , params } = obj;
31
+ assertIsRequestId(id);
32
+ assertIsJSONRPC2OrUndefined(jsonrpc);
33
+ if (method === 'subscription.stop') {
34
+ return {
35
+ id,
36
+ jsonrpc,
37
+ method
38
+ };
39
+ }
40
+ assertIsProcedureType(method);
41
+ assertIsObject(params);
42
+ const { input: rawInput , path } = params;
43
+ assertIsString(path);
44
+ const input = transformer.input.deserialize(rawInput);
45
+ return {
46
+ id,
47
+ jsonrpc,
48
+ method,
49
+ params: {
50
+ input,
51
+ path
52
+ }
53
+ };
54
+ }
55
+
56
+ exports.parseTRPCMessage = parseTRPCMessage;
@@ -0,0 +1,63 @@
1
+ /* istanbul ignore next -- @preserve */
2
+ function assertIsObject(obj) {
3
+ if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
4
+ throw new Error('Not an object');
5
+ }
6
+ }
7
+ /* istanbul ignore next -- @preserve */
8
+ function assertIsProcedureType(obj) {
9
+ if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
10
+ throw new Error('Invalid procedure type');
11
+ }
12
+ }
13
+ /* istanbul ignore next -- @preserve */
14
+ function assertIsRequestId(obj) {
15
+ if (obj !== null &&
16
+ typeof obj === 'number' &&
17
+ isNaN(obj) &&
18
+ typeof obj !== 'string') {
19
+ throw new Error('Invalid request id');
20
+ }
21
+ }
22
+ /* istanbul ignore next -- @preserve */
23
+ function assertIsString(obj) {
24
+ if (typeof obj !== 'string') {
25
+ throw new Error('Invalid string');
26
+ }
27
+ }
28
+ /* istanbul ignore next -- @preserve */
29
+ function assertIsJSONRPC2OrUndefined(obj) {
30
+ if (typeof obj !== 'undefined' && obj !== '2.0') {
31
+ throw new Error('Must be JSONRPC 2.0');
32
+ }
33
+ }
34
+ /** @public */
35
+ function parseTRPCMessage(obj, transformer) {
36
+ assertIsObject(obj);
37
+ const { id, jsonrpc, method, params } = obj;
38
+ assertIsRequestId(id);
39
+ assertIsJSONRPC2OrUndefined(jsonrpc);
40
+ if (method === 'subscription.stop') {
41
+ return {
42
+ id,
43
+ jsonrpc,
44
+ method,
45
+ };
46
+ }
47
+ assertIsProcedureType(method);
48
+ assertIsObject(params);
49
+ const { input: rawInput, path } = params;
50
+ assertIsString(path);
51
+ const input = transformer.input.deserialize(rawInput);
52
+ return {
53
+ id,
54
+ jsonrpc,
55
+ method,
56
+ params: {
57
+ input,
58
+ path,
59
+ },
60
+ };
61
+ }
62
+
63
+ export { parseTRPCMessage as p };
@@ -0,0 +1,54 @@
1
+ /* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
2
+ if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
3
+ throw new Error('Not an object');
4
+ }
5
+ }
6
+ /* istanbul ignore next -- @preserve */ function assertIsProcedureType(obj) {
7
+ if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
8
+ throw new Error('Invalid procedure type');
9
+ }
10
+ }
11
+ /* istanbul ignore next -- @preserve */ function assertIsRequestId(obj) {
12
+ if (obj !== null && typeof obj === 'number' && isNaN(obj) && typeof obj !== 'string') {
13
+ throw new Error('Invalid request id');
14
+ }
15
+ }
16
+ /* istanbul ignore next -- @preserve */ function assertIsString(obj) {
17
+ if (typeof obj !== 'string') {
18
+ throw new Error('Invalid string');
19
+ }
20
+ }
21
+ /* istanbul ignore next -- @preserve */ function assertIsJSONRPC2OrUndefined(obj) {
22
+ if (typeof obj !== 'undefined' && obj !== '2.0') {
23
+ throw new Error('Must be JSONRPC 2.0');
24
+ }
25
+ }
26
+ /** @public */ function parseTRPCMessage(obj, transformer) {
27
+ assertIsObject(obj);
28
+ const { id , jsonrpc , method , params } = obj;
29
+ assertIsRequestId(id);
30
+ assertIsJSONRPC2OrUndefined(jsonrpc);
31
+ if (method === 'subscription.stop') {
32
+ return {
33
+ id,
34
+ jsonrpc,
35
+ method
36
+ };
37
+ }
38
+ assertIsProcedureType(method);
39
+ assertIsObject(params);
40
+ const { input: rawInput , path } = params;
41
+ assertIsString(path);
42
+ const input = transformer.input.deserialize(rawInput);
43
+ return {
44
+ id,
45
+ jsonrpc,
46
+ method,
47
+ params: {
48
+ input,
49
+ path
50
+ }
51
+ };
52
+ }
53
+
54
+ export { parseTRPCMessage as p };
@@ -1,3 +1,4 @@
1
1
  export * from './codes';
2
2
  export * from './envelopes';
3
+ export * from './parseTRPCMessage';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
package/dist/rpc/index.js CHANGED
@@ -3,8 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var codes = require('../codes-87f6824b.js');
6
+ var parseTRPCMessage = require('../parseTRPCMessage-1377f305.js');
6
7
 
7
8
 
8
9
 
9
10
  exports.TRPC_ERROR_CODES_BY_KEY = codes.TRPC_ERROR_CODES_BY_KEY;
10
11
  exports.TRPC_ERROR_CODES_BY_NUMBER = codes.TRPC_ERROR_CODES_BY_NUMBER;
12
+ exports.parseTRPCMessage = parseTRPCMessage.parseTRPCMessage;
@@ -1 +1,2 @@
1
1
  export { T as TRPC_ERROR_CODES_BY_KEY, a as TRPC_ERROR_CODES_BY_NUMBER } from '../codes-c924c3db.mjs';
2
+ export { p as parseTRPCMessage } from '../parseTRPCMessage-a0f17853.mjs';
@@ -0,0 +1,5 @@
1
+ import type { CombinedDataTransformer } from '../transformer';
2
+ import type { TRPCClientOutgoingMessage } from './envelopes';
3
+ /** @public */
4
+ export declare function parseTRPCMessage(obj: unknown, transformer: CombinedDataTransformer): TRPCClientOutgoingMessage;
5
+ //# sourceMappingURL=parseTRPCMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseTRPCMessage.d.ts","sourceRoot":"","sources":["../../src/rpc/parseTRPCMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AA8C7D,cAAc;AACd,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,uBAAuB,GACnC,yBAAyB,CA+B3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-next.91+ca021e61",
3
+ "version": "11.0.0-next.92+06cebb01",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -179,5 +179,5 @@
179
179
  "funding": [
180
180
  "https://trpc.io/sponsor"
181
181
  ],
182
- "gitHead": "ca021e61ba8e6eb6e1715f124489cda75a00b5aa"
182
+ "gitHead": "06cebb015144e438281edace5dc4a5328477e495"
183
183
  }
@@ -1,97 +1,21 @@
1
1
  import { IncomingMessage } from 'http';
2
2
  import ws from 'ws';
3
- import {
4
- AnyRouter,
5
- callProcedure,
6
- inferRouterContext,
7
- ProcedureType,
8
- } from '../core';
3
+ import { AnyRouter, callProcedure, inferRouterContext } from '../core';
9
4
  import { getTRPCErrorFromUnknown, TRPCError } from '../error/TRPCError';
10
5
  import { BaseHandlerOptions } from '../internals/types';
11
6
  import { isObservable, Unsubscribable } from '../observable';
12
7
  import {
13
8
  JSONRPC2,
9
+ parseTRPCMessage,
14
10
  TRPCClientOutgoingMessage,
15
11
  TRPCReconnectNotification,
16
12
  TRPCResponseMessage,
17
13
  } from '../rpc';
18
14
  import { getErrorShape } from '../shared/getErrorShape';
19
15
  import { transformTRPCResponse } from '../shared/transformTRPCResponse';
20
- import { CombinedDataTransformer } from '../transformer';
21
16
  import { MaybePromise } from '../types';
22
17
  import { NodeHTTPCreateContextFnOptions } from './node-http';
23
18
 
24
- /* istanbul ignore next -- @preserve */
25
- function assertIsObject(obj: unknown): asserts obj is Record<string, unknown> {
26
- if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
27
- throw new Error('Not an object');
28
- }
29
- }
30
- /* istanbul ignore next -- @preserve */
31
- function assertIsProcedureType(obj: unknown): asserts obj is ProcedureType {
32
- if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
33
- throw new Error('Invalid procedure type');
34
- }
35
- }
36
- /* istanbul ignore next -- @preserve */
37
- function assertIsRequestId(
38
- obj: unknown,
39
- ): asserts obj is number | string | null {
40
- if (
41
- obj !== null &&
42
- typeof obj === 'number' &&
43
- isNaN(obj) &&
44
- typeof obj !== 'string'
45
- ) {
46
- throw new Error('Invalid request id');
47
- }
48
- }
49
- /* istanbul ignore next -- @preserve */
50
- function assertIsString(obj: unknown): asserts obj is string {
51
- if (typeof obj !== 'string') {
52
- throw new Error('Invalid string');
53
- }
54
- }
55
- /* istanbul ignore next -- @preserve */
56
- function assertIsJSONRPC2OrUndefined(
57
- obj: unknown,
58
- ): asserts obj is '2.0' | undefined {
59
- if (typeof obj !== 'undefined' && obj !== '2.0') {
60
- throw new Error('Must be JSONRPC 2.0');
61
- }
62
- }
63
- export function parseMessage(
64
- obj: unknown,
65
- transformer: CombinedDataTransformer,
66
- ): TRPCClientOutgoingMessage {
67
- assertIsObject(obj);
68
- const { method, params, id, jsonrpc } = obj;
69
- assertIsRequestId(id);
70
- assertIsJSONRPC2OrUndefined(jsonrpc);
71
- if (method === 'subscription.stop') {
72
- return {
73
- id,
74
- jsonrpc,
75
- method,
76
- };
77
- }
78
- assertIsProcedureType(method);
79
- assertIsObject(params);
80
-
81
- const { input: rawInput, path } = params;
82
- assertIsString(path);
83
- const input = transformer.input.deserialize(rawInput);
84
- return {
85
- id,
86
- jsonrpc,
87
- method,
88
- params: {
89
- input,
90
- path,
91
- },
92
- };
93
- }
94
-
95
19
  /**
96
20
  * @public
97
21
  */
@@ -304,7 +228,7 @@ export function applyWSSHandler<TRouter extends AnyRouter>(
304
228
  const msgJSON: unknown = JSON.parse(message.toString());
305
229
  const msgs: unknown[] = Array.isArray(msgJSON) ? msgJSON : [msgJSON];
306
230
  const promises = msgs
307
- .map((raw) => parseMessage(raw, transformer))
231
+ .map((raw) => parseTRPCMessage(raw, transformer))
308
232
  .map(handleRequest);
309
233
  await Promise.all(promises);
310
234
  } catch (cause) {
package/src/rpc/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './codes';
2
2
  export * from './envelopes';
3
+ export * from './parseTRPCMessage';
@@ -0,0 +1,84 @@
1
+ import type { ProcedureType } from '../core';
2
+ import type { CombinedDataTransformer } from '../transformer';
3
+ import type { TRPCClientOutgoingMessage } from './envelopes';
4
+
5
+ /* istanbul ignore next -- @preserve */
6
+ function assertIsObject(obj: unknown): asserts obj is Record<string, unknown> {
7
+ if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
8
+ throw new Error('Not an object');
9
+ }
10
+ }
11
+
12
+ /* istanbul ignore next -- @preserve */
13
+ function assertIsProcedureType(obj: unknown): asserts obj is ProcedureType {
14
+ if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
15
+ throw new Error('Invalid procedure type');
16
+ }
17
+ }
18
+
19
+ /* istanbul ignore next -- @preserve */
20
+ function assertIsRequestId(
21
+ obj: unknown,
22
+ ): asserts obj is number | string | null {
23
+ if (
24
+ obj !== null &&
25
+ typeof obj === 'number' &&
26
+ isNaN(obj) &&
27
+ typeof obj !== 'string'
28
+ ) {
29
+ throw new Error('Invalid request id');
30
+ }
31
+ }
32
+
33
+ /* istanbul ignore next -- @preserve */
34
+ function assertIsString(obj: unknown): asserts obj is string {
35
+ if (typeof obj !== 'string') {
36
+ throw new Error('Invalid string');
37
+ }
38
+ }
39
+
40
+ /* istanbul ignore next -- @preserve */
41
+ function assertIsJSONRPC2OrUndefined(
42
+ obj: unknown,
43
+ ): asserts obj is '2.0' | undefined {
44
+ if (typeof obj !== 'undefined' && obj !== '2.0') {
45
+ throw new Error('Must be JSONRPC 2.0');
46
+ }
47
+ }
48
+
49
+ /** @public */
50
+ export function parseTRPCMessage(
51
+ obj: unknown,
52
+ transformer: CombinedDataTransformer,
53
+ ): TRPCClientOutgoingMessage {
54
+ assertIsObject(obj);
55
+
56
+ const { id, jsonrpc, method, params } = obj;
57
+ assertIsRequestId(id);
58
+ assertIsJSONRPC2OrUndefined(jsonrpc);
59
+
60
+ if (method === 'subscription.stop') {
61
+ return {
62
+ id,
63
+ jsonrpc,
64
+ method,
65
+ };
66
+ }
67
+ assertIsProcedureType(method);
68
+ assertIsObject(params);
69
+ const { input: rawInput, path } = params;
70
+
71
+ assertIsString(path);
72
+
73
+ const input = transformer.input.deserialize(rawInput);
74
+
75
+ return {
76
+ id,
77
+ jsonrpc,
78
+ method,
79
+ params: {
80
+ input,
81
+ path,
82
+ },
83
+ };
84
+ }