@trpc/server 11.0.0-next-beta.302 → 11.0.0-next-beta.304

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 (55) hide show
  1. package/dist/adapters/aws-lambda/index.js +0 -1
  2. package/dist/adapters/aws-lambda/index.mjs +0 -1
  3. package/dist/adapters/aws-lambda/utils.js +0 -1
  4. package/dist/adapters/aws-lambda/utils.mjs +0 -1
  5. package/dist/adapters/fastify/fastifyRequestHandler.js +0 -1
  6. package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -1
  7. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  8. package/dist/adapters/fastify/fastifyTRPCPlugin.js +3 -7
  9. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +4 -8
  10. package/dist/adapters/fetch/fetchRequestHandler.js +0 -1
  11. package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -1
  12. package/dist/adapters/next.js +0 -1
  13. package/dist/adapters/next.mjs +0 -1
  14. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  15. package/dist/adapters/node-http/content-type/json/getPostBody.js +3 -4
  16. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -4
  17. package/dist/adapters/node-http/content-type/json/index.js +0 -1
  18. package/dist/adapters/node-http/content-type/json/index.mjs +0 -1
  19. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -1
  20. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -1
  21. package/dist/adapters/standalone.js +0 -1
  22. package/dist/adapters/standalone.mjs +0 -1
  23. package/dist/adapters/ws.d.ts +7 -5
  24. package/dist/adapters/ws.d.ts.map +1 -1
  25. package/dist/adapters/ws.js +14 -7
  26. package/dist/adapters/ws.mjs +14 -8
  27. package/dist/bundle-analysis.json +97 -98
  28. package/dist/http.js +0 -1
  29. package/dist/http.mjs +0 -1
  30. package/dist/index.js +0 -1
  31. package/dist/index.mjs +0 -1
  32. package/dist/shared.js +0 -1
  33. package/dist/shared.mjs +0 -1
  34. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +1 -1
  35. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -1
  36. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
  37. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +1 -0
  38. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +1 -0
  39. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +8 -15
  40. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -1
  41. package/dist/unstable-core-do-not-import/rpc/codes.js +19 -3
  42. package/dist/unstable-core-do-not-import/rpc/codes.mjs +19 -3
  43. package/dist/unstable-core-do-not-import/utils.d.ts +0 -11
  44. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  45. package/dist/unstable-core-do-not-import/utils.js +0 -11
  46. package/dist/unstable-core-do-not-import/utils.mjs +1 -11
  47. package/dist/unstable-core-do-not-import.js +0 -1
  48. package/dist/unstable-core-do-not-import.mjs +1 -1
  49. package/package.json +2 -2
  50. package/src/adapters/fastify/fastifyTRPCPlugin.ts +6 -7
  51. package/src/adapters/node-http/content-type/json/getPostBody.ts +6 -5
  52. package/src/adapters/ws.ts +37 -25
  53. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +1 -0
  54. package/src/unstable-core-do-not-import/rpc/codes.ts +29 -2
  55. package/src/unstable-core-do-not-import/utils.ts +0 -21
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
4
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
6
5
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,4 +1,3 @@
1
- import '../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
2
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
4
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
4
  require('../../unstable-core-do-not-import/rootConfig.js');
6
5
 
@@ -1,4 +1,3 @@
1
- import '../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
2
  import '../../unstable-core-do-not-import/rootConfig.mjs';
4
3
 
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var node_stream = require('node:stream');
4
- require('../../unstable-core-do-not-import/rpc/codes.js');
5
4
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
6
5
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
7
6
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,5 +1,4 @@
1
1
  import { Readable } from 'node:stream';
2
- import '../../unstable-core-do-not-import/rpc/codes.mjs';
3
2
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
4
3
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
5
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAE/C,OAA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AgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,QAmC5B"}
@@ -20,7 +20,6 @@ function fastifyTRPCPlugin(fastify, opts, done) {
20
20
  _done(null, body);
21
21
  });
22
22
  let prefix = opts.prefix ?? '';
23
- const websocketPrefix = prefix;
24
23
  // https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
25
24
  // @ts-expect-error property 'default' does not exists on type ...
26
25
  if (typeof fastifyTRPCPlugin.default !== 'function') {
@@ -36,15 +35,12 @@ function fastifyTRPCPlugin(fastify, opts, done) {
36
35
  });
37
36
  });
38
37
  if (opts.useWSS) {
39
- ws.applyWSSHandler({
40
- ...opts.trpcOptions,
41
- prefix: websocketPrefix,
42
- wss: fastify.websocketServer
38
+ const onConnection = ws.getWSConnectionHandler({
39
+ ...opts.trpcOptions
43
40
  });
44
- // eslint-disable-next-line @typescript-eslint/no-empty-function
45
41
  fastify.get(prefix ?? '/', {
46
42
  websocket: true
47
- }, ()=>{});
43
+ }, ({ socket }, req)=>onConnection(socket, req.raw));
48
44
  }
49
45
  done();
50
46
  }
@@ -1,4 +1,4 @@
1
- import { applyWSSHandler } from '../ws.mjs';
1
+ import { getWSConnectionHandler } from '../ws.mjs';
2
2
  import { fastifyRequestHandler } from './fastifyRequestHandler.mjs';
3
3
 
4
4
  /**
@@ -18,7 +18,6 @@ function fastifyTRPCPlugin(fastify, opts, done) {
18
18
  _done(null, body);
19
19
  });
20
20
  let prefix = opts.prefix ?? '';
21
- const websocketPrefix = prefix;
22
21
  // https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
23
22
  // @ts-expect-error property 'default' does not exists on type ...
24
23
  if (typeof fastifyTRPCPlugin.default !== 'function') {
@@ -34,15 +33,12 @@ function fastifyTRPCPlugin(fastify, opts, done) {
34
33
  });
35
34
  });
36
35
  if (opts.useWSS) {
37
- applyWSSHandler({
38
- ...opts.trpcOptions,
39
- prefix: websocketPrefix,
40
- wss: fastify.websocketServer
36
+ const onConnection = getWSConnectionHandler({
37
+ ...opts.trpcOptions
41
38
  });
42
- // eslint-disable-next-line @typescript-eslint/no-empty-function
43
39
  fastify.get(prefix ?? '/', {
44
40
  websocket: true
45
- }, ()=>{});
41
+ }, ({ socket }, req)=>onConnection(socket, req.raw));
46
42
  }
47
43
  done();
48
44
  }
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
4
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
6
5
  var toURL = require('../../unstable-core-do-not-import/http/toURL.js');
@@ -1,4 +1,3 @@
1
- import '../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
2
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
4
3
  import { toURL } from '../../unstable-core-do-not-import/http/toURL.mjs';
@@ -2,7 +2,6 @@
2
2
 
3
3
  var getErrorShape = require('../unstable-core-do-not-import/error/getErrorShape.js');
4
4
  var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
5
- require('../unstable-core-do-not-import/rpc/codes.js');
6
5
  require('../unstable-core-do-not-import/rootConfig.js');
7
6
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
8
7
 
@@ -1,6 +1,5 @@
1
1
  import { getErrorShape } from '../unstable-core-do-not-import/error/getErrorShape.mjs';
2
2
  import { TRPCError } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
- import '../unstable-core-do-not-import/rpc/codes.mjs';
4
3
  import '../unstable-core-do-not-import/rootConfig.mjs';
5
4
  import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
6
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgDtB"}
1
+ {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiDtB"}
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
5
4
  require('../../../../unstable-core-do-not-import/rootConfig.js');
6
5
 
@@ -8,12 +7,12 @@ require('../../../../unstable-core-do-not-import/rootConfig.js');
8
7
  async function getPostBody(opts) {
9
8
  const { req , maxBodySize =Infinity } = opts;
10
9
  return new Promise((resolve)=>{
11
- if (!req.headers['content-type']?.startsWith('application/json') && req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD') {
10
+ if (!req.headers['content-type']?.startsWith('application/json') && (!req.method || req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD')) {
12
11
  resolve({
13
12
  ok: false,
14
13
  error: new TRPCError.TRPCError({
15
- code: 'BAD_REQUEST',
16
- message: 'Invalid content-type header (expected application/json)'
14
+ code: 'UNSUPPORTED_MEDIA_TYPE',
15
+ message: 'Invalid Content-Type header (expected application/json)'
17
16
  })
18
17
  });
19
18
  return;
@@ -1,4 +1,3 @@
1
- import '../../../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
3
2
  import '../../../../unstable-core-do-not-import/rootConfig.mjs';
4
3
 
@@ -6,12 +5,12 @@ import '../../../../unstable-core-do-not-import/rootConfig.mjs';
6
5
  async function getPostBody(opts) {
7
6
  const { req , maxBodySize =Infinity } = opts;
8
7
  return new Promise((resolve)=>{
9
- if (!req.headers['content-type']?.startsWith('application/json') && req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD') {
8
+ if (!req.headers['content-type']?.startsWith('application/json') && (!req.method || req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD')) {
10
9
  resolve({
11
10
  ok: false,
12
11
  error: new TRPCError({
13
- code: 'BAD_REQUEST',
14
- message: 'Invalid content-type header (expected application/json)'
12
+ code: 'UNSUPPORTED_MEDIA_TYPE',
13
+ message: 'Invalid Content-Type header (expected application/json)'
15
14
  })
16
15
  });
17
16
  return;
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var contentType$1 = require('../../../../unstable-core-do-not-import/http/contentType.js');
5
4
  require('../../../../unstable-core-do-not-import/rootConfig.js');
6
5
  var contentType = require('../../internals/contentType.js');
@@ -1,4 +1,3 @@
1
- import '../../../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { getJsonContentTypeInputs } from '../../../../unstable-core-do-not-import/http/contentType.mjs';
3
2
  import '../../../../unstable-core-do-not-import/rootConfig.mjs';
4
3
  import { createNodeHTTPContentTypeHandler } from '../../internals/contentType.mjs';
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('../../unstable-core-do-not-import/rpc/codes.js');
4
3
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
4
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
6
5
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,4 +1,3 @@
1
- import '../../unstable-core-do-not-import/rpc/codes.mjs';
2
1
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
2
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
4
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var http = require('node:http');
4
- require('../unstable-core-do-not-import/rpc/codes.js');
5
4
  var toURL = require('../unstable-core-do-not-import/http/toURL.js');
6
5
  require('../unstable-core-do-not-import/rootConfig.js');
7
6
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
@@ -1,5 +1,4 @@
1
1
  import http from 'node:http';
2
- import '../unstable-core-do-not-import/rpc/codes.mjs';
3
2
  import { toURL } from '../unstable-core-do-not-import/http/toURL.mjs';
4
3
  import '../unstable-core-do-not-import/rootConfig.mjs';
5
4
  import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
@@ -15,10 +15,7 @@ export type CreateWSSContextFnOptions = Omit<NodeHTTPCreateContextFnOptions<Inco
15
15
  * @public
16
16
  */
17
17
  export type CreateWSSContextFn<TRouter extends AnyRouter> = (opts: CreateWSSContextFnOptions) => MaybePromise<inferRouterContext<TRouter>>;
18
- /**
19
- * Web socket server handler
20
- */
21
- export type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TRouter, IncomingMessage> & (object extends inferRouterContext<TRouter> ? {
18
+ export type WSConnectionHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TRouter, IncomingMessage> & (object extends inferRouterContext<TRouter> ? {
22
19
  /**
23
20
  * @link https://trpc.io/docs/v11/context
24
21
  **/
@@ -28,11 +25,16 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TR
28
25
  * @link https://trpc.io/docs/v11/context
29
26
  **/
30
27
  createContext: CreateWSSContextFn<TRouter>;
31
- }) & {
28
+ });
29
+ /**
30
+ * Web socket server handler
31
+ */
32
+ export type WSSHandlerOptions<TRouter extends AnyRouter> = WSConnectionHandlerOptions<TRouter> & {
32
33
  wss: ws.WebSocketServer;
33
34
  process?: NodeJS.Process;
34
35
  prefix?: string;
35
36
  };
37
+ export declare function getWSConnectionHandler<TRouter extends AnyRouter>(opts: WSConnectionHandlerOptions<TRouter>): (client: ws.WebSocket, req: IncomingMessage) => Promise<void>;
36
38
  export declare function applyWSSHandler<TRouter extends AnyRouter>(opts: WSSHandlerOptions<TRouter>): {
37
39
  broadcastReconnectNotification: () => void;
38
40
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/adapters/ws.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAY/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAQlE;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,8BAA8B,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,C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B,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,EAC7D,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,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,kBAAkB,CAAC,OAAO,EAAE,eAAe,CAAC,GAC1C,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,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IACrD,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEJ,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,YAKnB,YAAY,OAAO,eAAe,mBAoPzD;AAED,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EA2BjC"}
@@ -2,7 +2,6 @@
2
2
 
3
3
  var getErrorShape = require('../unstable-core-do-not-import/error/getErrorShape.js');
4
4
  var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
5
- require('../unstable-core-do-not-import/rpc/codes.js');
6
5
  var parseTRPCMessage = require('../unstable-core-do-not-import/rpc/parseTRPCMessage.js');
7
6
  var router = require('../unstable-core-do-not-import/router.js');
8
7
  var transformer = require('../unstable-core-do-not-import/transformer.js');
@@ -13,13 +12,10 @@ var observable = require('../observable/observable.js');
13
12
  * Importing ws causes a build error
14
13
  * @link https://github.com/trpc/trpc/pull/5279
15
14
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
16
- function applyWSSHandler(opts) {
17
- const { wss , createContext , router: router$1 , prefix } = opts;
15
+ function getWSConnectionHandler(opts) {
16
+ const { createContext , router: router$1 } = opts;
18
17
  const { transformer: transformer$1 } = router$1._def._config;
19
- wss.on('connection', async (client, req)=>{
20
- if (prefix && !req.url?.startsWith(prefix)) {
21
- return;
22
- }
18
+ return async (client, req)=>{
23
19
  const clientSubscriptions = new Map();
24
20
  function respond(untransformedJSON) {
25
21
  client.send(JSON.stringify(transformer.transformTRPCResponse(router$1._def._config, untransformedJSON)));
@@ -261,6 +257,16 @@ function applyWSSHandler(opts) {
261
257
  }
262
258
  }
263
259
  await createContextAsync();
260
+ };
261
+ }
262
+ function applyWSSHandler(opts) {
263
+ const { wss , prefix } = opts;
264
+ const onConnection = getWSConnectionHandler(opts);
265
+ wss.on('connection', async (client, req)=>{
266
+ if (prefix && !req.url?.startsWith(prefix)) {
267
+ return;
268
+ }
269
+ await onConnection(client, req);
264
270
  });
265
271
  return {
266
272
  broadcastReconnectNotification: ()=>{
@@ -279,3 +285,4 @@ function applyWSSHandler(opts) {
279
285
  }
280
286
 
281
287
  exports.applyWSSHandler = applyWSSHandler;
288
+ exports.getWSConnectionHandler = getWSConnectionHandler;
@@ -1,6 +1,5 @@
1
1
  import { getErrorShape } from '../unstable-core-do-not-import/error/getErrorShape.mjs';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
- import '../unstable-core-do-not-import/rpc/codes.mjs';
4
3
  import { parseTRPCMessage } from '../unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
5
4
  import { callProcedure } from '../unstable-core-do-not-import/router.mjs';
6
5
  import { transformTRPCResponse } from '../unstable-core-do-not-import/transformer.mjs';
@@ -11,13 +10,10 @@ import { isObservable } from '../observable/observable.mjs';
11
10
  * Importing ws causes a build error
12
11
  * @link https://github.com/trpc/trpc/pull/5279
13
12
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
14
- function applyWSSHandler(opts) {
15
- const { wss , createContext , router , prefix } = opts;
13
+ function getWSConnectionHandler(opts) {
14
+ const { createContext , router } = opts;
16
15
  const { transformer } = router._def._config;
17
- wss.on('connection', async (client, req)=>{
18
- if (prefix && !req.url?.startsWith(prefix)) {
19
- return;
20
- }
16
+ return async (client, req)=>{
21
17
  const clientSubscriptions = new Map();
22
18
  function respond(untransformedJSON) {
23
19
  client.send(JSON.stringify(transformTRPCResponse(router._def._config, untransformedJSON)));
@@ -259,6 +255,16 @@ function applyWSSHandler(opts) {
259
255
  }
260
256
  }
261
257
  await createContextAsync();
258
+ };
259
+ }
260
+ function applyWSSHandler(opts) {
261
+ const { wss , prefix } = opts;
262
+ const onConnection = getWSConnectionHandler(opts);
263
+ wss.on('connection', async (client, req)=>{
264
+ if (prefix && !req.url?.startsWith(prefix)) {
265
+ return;
266
+ }
267
+ await onConnection(client, req);
262
268
  });
263
269
  return {
264
270
  broadcastReconnectNotification: ()=>{
@@ -276,4 +282,4 @@ function applyWSSHandler(opts) {
276
282
  };
277
283
  }
278
284
 
279
- export { applyWSSHandler };
285
+ export { applyWSSHandler, getWSConnectionHandler };