@trpc/server 11.0.0-alpha-tmp.233 → 11.0.0-alpha-tmp-v11-trpc-sveltekit.191

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 (103) hide show
  1. package/README.md +4 -4
  2. package/dist/{unstableDoNotImportThis.d.ts → @trpc-core-unstable-do-not-import-this-please.d.ts} +1 -1
  3. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
  4. package/dist/@trpc-server/http.d.ts +2 -0
  5. package/dist/@trpc-server/http.d.ts.map +1 -0
  6. package/dist/@trpc-server.d.ts +45 -0
  7. package/dist/@trpc-server.d.ts.map +1 -0
  8. package/dist/adapters/aws-lambda/index.d.ts +12 -2
  9. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  10. package/dist/adapters/aws-lambda/index.js +20 -0
  11. package/dist/adapters/aws-lambda/index.mjs +20 -0
  12. package/dist/adapters/aws-lambda/utils.d.ts +14 -5
  13. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  14. package/dist/adapters/express.d.ts +12 -2
  15. package/dist/adapters/express.d.ts.map +1 -1
  16. package/dist/adapters/express.js +2 -2
  17. package/dist/adapters/express.mjs +2 -2
  18. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +4 -4
  19. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  20. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +14 -4
  21. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  22. package/dist/adapters/fastify/index.js +11 -2
  23. package/dist/adapters/fastify/index.mjs +11 -2
  24. package/dist/adapters/fetch/fetchRequestHandler.d.ts +12 -2
  25. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  26. package/dist/adapters/fetch/index.js +10 -0
  27. package/dist/adapters/fetch/index.mjs +10 -0
  28. package/dist/adapters/fetch/types.d.ts +14 -4
  29. package/dist/adapters/fetch/types.d.ts.map +1 -1
  30. package/dist/adapters/next.d.ts +12 -2
  31. package/dist/adapters/next.d.ts.map +1 -1
  32. package/dist/adapters/next.js +12 -2
  33. package/dist/adapters/next.mjs +12 -2
  34. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +1 -1
  35. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -1
  36. package/dist/adapters/node-http/content-type/form-data/index.d.ts +3 -3
  37. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
  38. package/dist/adapters/node-http/content-type/form-data/index.js +2 -2
  39. package/dist/adapters/node-http/content-type/form-data/index.mjs +2 -2
  40. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +2 -2
  41. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -1
  42. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +2 -1
  43. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
  44. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +2 -2
  45. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -1
  46. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +2 -2
  47. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  48. package/dist/adapters/node-http/content-type/json/index.js +2 -1
  49. package/dist/adapters/node-http/content-type/json/index.mjs +2 -1
  50. package/dist/adapters/node-http/index.js +2 -2
  51. package/dist/adapters/node-http/index.mjs +2 -2
  52. package/dist/adapters/node-http/internals/contentType.d.ts +3 -3
  53. package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
  54. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +12 -2
  55. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  56. package/dist/adapters/node-http/types.d.ts +17 -6
  57. package/dist/adapters/node-http/types.d.ts.map +1 -1
  58. package/dist/adapters/standalone.d.ts +12 -2
  59. package/dist/adapters/standalone.d.ts.map +1 -1
  60. package/dist/adapters/standalone.js +2 -2
  61. package/dist/adapters/standalone.mjs +2 -2
  62. package/dist/adapters/ws.d.ts +10 -9
  63. package/dist/adapters/ws.d.ts.map +1 -1
  64. package/dist/adapters/ws.js +7 -3
  65. package/dist/adapters/ws.mjs +7 -3
  66. package/dist/bundle-analysis.json +80 -80
  67. package/dist/{contentType-3194ed5f.mjs → contentType-72ed9df5.mjs} +1 -0
  68. package/dist/{contentType-8c16408e.js → contentType-d9d22104.js} +1 -0
  69. package/dist/http.d.ts +1 -1
  70. package/dist/http.d.ts.map +1 -1
  71. package/dist/index.d.ts +1 -19
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +28 -8
  74. package/dist/index.mjs +1 -1
  75. package/dist/{nodeHTTPRequestHandler-36974696.mjs → nodeHTTPRequestHandler-0223fac5.mjs} +10 -0
  76. package/dist/{nodeHTTPRequestHandler-30028c9a.js → nodeHTTPRequestHandler-83441c73.js} +10 -0
  77. package/package.json +4 -20
  78. package/src/@trpc-server/http.ts +2 -0
  79. package/src/@trpc-server.ts +71 -0
  80. package/src/adapters/aws-lambda/index.ts +20 -5
  81. package/src/adapters/aws-lambda/utils.ts +22 -6
  82. package/src/adapters/express.ts +14 -3
  83. package/src/adapters/fastify/fastifyRequestHandler.ts +16 -6
  84. package/src/adapters/fastify/fastifyTRPCPlugin.ts +17 -5
  85. package/src/adapters/fetch/fetchRequestHandler.ts +15 -5
  86. package/src/adapters/fetch/types.ts +19 -4
  87. package/src/adapters/next.ts +16 -3
  88. package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +3 -2
  89. package/src/adapters/node-http/content-type/form-data/index.ts +7 -9
  90. package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +3 -2
  91. package/src/adapters/node-http/content-type/form-data/streamSlice.ts +2 -1
  92. package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +2 -2
  93. package/src/adapters/node-http/content-type/json/getPostBody.ts +4 -3
  94. package/src/adapters/node-http/internals/contentType.ts +5 -3
  95. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +16 -6
  96. package/src/adapters/node-http/types.ts +23 -6
  97. package/src/adapters/standalone.ts +14 -3
  98. package/src/adapters/ws.ts +29 -22
  99. package/src/http.ts +1 -2
  100. package/src/index.ts +1 -34
  101. package/dist/unstableDoNotImportThis.d.ts.map +0 -1
  102. /package/dist/{nodeHTTPRequestHandler-640c1f60.js → nodeHTTPRequestHandler-aa0dce4e.js} +0 -0
  103. /package/src/{unstableDoNotImportThis.ts → @trpc-core-unstable-do-not-import-this-please.ts} +0 -0
@@ -1,5 +1,13 @@
1
- import type { AnyRouter, inferRouterContext } from '@trpc/core';
2
- import { TRPCError } from '@trpc/core';
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
3
11
  import type {
4
12
  APIGatewayProxyEvent,
5
13
  APIGatewayProxyEventV2,
@@ -7,8 +15,16 @@ import type {
7
15
  APIGatewayProxyStructuredResultV2,
8
16
  Context as APIGWContext,
9
17
  } from 'aws-lambda';
10
- import { TRPCRequestInfo } from '../../http';
11
- import type { HTTPHeaders, OnErrorFunction, ResponseMetaFn } from '../../http';
18
+ import type { AnyRouter, inferRouterContext } from '../../@trpc-server'; // import @trpc/server
19
+
20
+ // @trpc/server
21
+ import { TRPCError } from '../../@trpc-server';
22
+ import type {
23
+ HTTPHeaders,
24
+ OnErrorFunction,
25
+ ResponseMetaFn,
26
+ TRPCRequestInfo,
27
+ } from '../../http';
12
28
 
13
29
  export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
14
30
  export type APIGatewayResult =
@@ -45,13 +61,13 @@ export type AWSLambdaOptions<
45
61
  } & (
46
62
  | {
47
63
  /**
48
- * @link https://trpc.io/docs/context
64
+ * @link https://trpc.io/docs/v11/context
49
65
  **/
50
66
  createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
51
67
  }
52
68
  | {
53
69
  /**
54
- * @link https://trpc.io/docs/context
70
+ * @link https://trpc.io/docs/v11/context
55
71
  **/
56
72
  createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
57
73
  }
@@ -1,10 +1,21 @@
1
- import { AnyRouter } from '@trpc/core';
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
2
11
  import type * as express from 'express';
3
- import {
12
+ // @trpc/server
13
+ import type { AnyRouter } from '../@trpc-server';
14
+ import type {
4
15
  NodeHTTPCreateContextFnOptions,
5
16
  NodeHTTPHandlerOptions,
6
- nodeHTTPRequestHandler,
7
17
  } from './node-http';
18
+ import { nodeHTTPRequestHandler } from './node-http';
8
19
 
9
20
  export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<
10
21
  express.Request,
@@ -1,16 +1,26 @@
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
1
11
  import { Readable } from 'node:stream';
2
- import { AnyRouter } from '@trpc/core';
3
- import { FastifyReply, FastifyRequest } from 'fastify';
4
- import {
5
- getBatchStreamFormatter,
12
+ import type { FastifyReply, FastifyRequest } from 'fastify';
13
+ // @trpc/server
14
+ import type { AnyRouter } from '../../@trpc-server';
15
+ import type {
6
16
  HTTPBaseHandlerOptions,
7
17
  HTTPRequest,
8
18
  HTTPResponse,
9
19
  ResolveHTTPRequestOptionsContextFn,
10
- resolveHTTPResponse,
11
20
  ResponseChunk,
12
21
  } from '../../http';
13
- import { NodeHTTPCreateContextOption } from '../node-http';
22
+ import { getBatchStreamFormatter, resolveHTTPResponse } from '../../http';
23
+ import type { NodeHTTPCreateContextOption } from '../node-http';
14
24
 
15
25
  export type FastifyHandlerOptions<
16
26
  TRouter extends AnyRouter,
@@ -1,9 +1,21 @@
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
1
11
  /// <reference types="@fastify/websocket" />
2
- import { AnyRouter } from '@trpc/core';
3
- import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
4
- import { FastifyHandlerOptions } from '.';
5
- import { NodeHTTPCreateContextFnOptions } from '../node-http';
6
- import { applyWSSHandler, WSSHandlerOptions } from '../ws';
12
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
13
+ import type { FastifyHandlerOptions } from '.';
14
+ // @trpc/server
15
+ import type { AnyRouter } from '../../@trpc-server';
16
+ import type { NodeHTTPCreateContextFnOptions } from '../node-http';
17
+ import type { WSSHandlerOptions } from '../ws';
18
+ import { applyWSSHandler } from '../ws';
7
19
  import { fastifyRequestHandler } from './fastifyRequestHandler';
8
20
 
9
21
  export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
@@ -1,13 +1,23 @@
1
- import { AnyRouter } from '@trpc/core';
2
- import {
3
- getBatchStreamFormatter,
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
11
+ // @trpc/server
12
+ import type { AnyRouter } from '../../@trpc-server';
13
+ import type {
4
14
  HTTPRequest,
5
15
  HTTPResponse,
6
16
  ResolveHTTPRequestOptionsContextFn,
7
- resolveHTTPResponse,
8
17
  ResponseChunk,
9
18
  } from '../../http';
10
- import { FetchHandlerOptions } from './types';
19
+ import { getBatchStreamFormatter, resolveHTTPResponse } from '../../http';
20
+ import type { FetchHandlerOptions } from './types';
11
21
 
12
22
  export type FetchHandlerRequestOptions<TRouter extends AnyRouter> =
13
23
  FetchHandlerOptions<TRouter> & {
@@ -1,5 +1,20 @@
1
- import { AnyRouter, inferRouterContext } from '@trpc/core';
2
- import { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../http';
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
11
+ // @trpc/server
12
+ import type { AnyRouter, inferRouterContext } from '../../@trpc-server';
13
+ // @trpc/server/http
14
+ import type {
15
+ HTTPBaseHandlerOptions,
16
+ TRPCRequestInfo,
17
+ } from '../../@trpc-server/http';
3
18
 
4
19
  export type FetchCreateContextFnOptions = {
5
20
  req: Request;
@@ -15,13 +30,13 @@ export type FetchCreateContextOption<TRouter extends AnyRouter> =
15
30
  unknown extends inferRouterContext<TRouter>
16
31
  ? {
17
32
  /**
18
- * @link https://trpc.io/docs/context
33
+ * @link https://trpc.io/docs/v11/context
19
34
  **/
20
35
  createContext?: FetchCreateContextFn<TRouter>;
21
36
  }
22
37
  : {
23
38
  /**
24
- * @link https://trpc.io/docs/context
39
+ * @link https://trpc.io/docs/v11/context
25
40
  **/
26
41
  createContext: FetchCreateContextFn<TRouter>;
27
42
  };
@@ -1,10 +1,23 @@
1
- import { AnyRouter, getErrorShape, TRPCError } from '@trpc/core';
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
2
11
  import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
3
- import {
12
+ // @trpc/server
13
+ import type { AnyRouter } from '../@trpc-server';
14
+ // @trpc/server
15
+ import { getErrorShape, TRPCError } from '../@trpc-server';
16
+ import type {
4
17
  NodeHTTPCreateContextFnOptions,
5
18
  NodeHTTPHandlerOptions,
6
- nodeHTTPRequestHandler,
7
19
  } from './node-http';
20
+ import { nodeHTTPRequestHandler } from './node-http';
8
21
 
9
22
  export type CreateNextContextOptions = NodeHTTPCreateContextFnOptions<
10
23
  NextApiRequest,
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  /**
11
- * @see https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-node/upload/fileUploadHandler.ts
11
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-node/upload/fileUploadHandler.ts
12
12
  */
13
13
  import { randomBytes } from 'node:crypto';
14
14
  import { createReadStream, createWriteStream, statSync } from 'node:fs';
@@ -18,7 +18,8 @@ import { basename, dirname, extname, resolve as resolvePath } from 'node:path';
18
18
  import { finished, Readable } from 'node:stream';
19
19
  import { promisify } from 'node:util';
20
20
  import { streamSlice } from './streamSlice';
21
- import { MaxPartSizeExceededError, UploadHandler } from './uploadHandler';
21
+ import type { UploadHandler } from './uploadHandler';
22
+ import { MaxPartSizeExceededError } from './uploadHandler';
22
23
 
23
24
  export async function readableStreamToString(
24
25
  stream: ReadableStream<Uint8Array>,
@@ -6,22 +6,20 @@
6
6
  */
7
7
 
8
8
  /**
9
- * @see https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
9
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
10
10
  */
11
11
  import * as fs from 'fs/promises';
12
12
  import { Readable } from 'node:stream';
13
- import { CombinedDataTransformer } from '@trpc/core';
14
13
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15
14
  // @ts-ignore the type definitions for this package are borked
16
15
  import { streamMultipart } from '@web3-storage/multipart-parser';
16
+ // @trpc/server
17
+ import type { CombinedDataTransformer } from '../../../../@trpc-server';
17
18
  import { createNodeHTTPContentTypeHandler } from '../../internals/contentType';
18
- import { NodeHTTPRequest } from '../../types';
19
+ import type { NodeHTTPRequest } from '../../types';
19
20
  import { NodeOnDiskFile } from './fileUploadHandler';
20
- import {
21
- MaxBodySizeExceededError,
22
- UploadHandler,
23
- UploadHandlerPart,
24
- } from './uploadHandler';
21
+ import type { UploadHandler, UploadHandlerPart } from './uploadHandler';
22
+ import { MaxBodySizeExceededError } from './uploadHandler';
25
23
 
26
24
  const utfTextDecoder = new TextDecoder('utf-8');
27
25
 
@@ -33,7 +31,7 @@ const utfTextDecoder = new TextDecoder('utf-8');
33
31
  * @param uploadHandler A function that handles file uploads and returns a value to be used in the request body. If uploaded to disk, the returned value is a NodeOnDiskFile. If uploaded to memory, the returned value is a File.
34
32
  * @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
35
33
  *
36
- * @see https://remix.run/utils/parse-multipart-form-data
34
+ * @link https://remix.run/utils/parse-multipart-form-data
37
35
  */
38
36
  async function parseMultipartFormData(
39
37
  request: NodeHTTPRequest,
@@ -6,9 +6,10 @@
6
6
  */
7
7
 
8
8
  /**
9
- * @see https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
9
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
10
10
  */
11
- import { MaxPartSizeExceededError, UploadHandler } from './uploadHandler';
11
+ import type { UploadHandler } from './uploadHandler';
12
+ import { MaxPartSizeExceededError } from './uploadHandler';
12
13
 
13
14
  export type MemoryUploadHandlerFilterArgs = {
14
15
  filename?: string;
@@ -1,4 +1,5 @@
1
- import { Transform, TransformCallback } from 'node:stream';
1
+ import type { TransformCallback } from 'node:stream';
2
+ import { Transform } from 'node:stream';
2
3
 
3
4
  class SliceStream extends Transform {
4
5
  private indexOffset = 0;
@@ -1,7 +1,7 @@
1
- import { NodeOnDiskFile } from './fileUploadHandler';
1
+ import type { NodeOnDiskFile } from './fileUploadHandler';
2
2
 
3
3
  /**
4
- * @see https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
4
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
5
5
  */
6
6
  export type UploadHandlerPart = {
7
7
  name: string;
@@ -1,6 +1,7 @@
1
- import { TRPCError } from '@trpc/core';
2
- import { BodyResult } from '../../../../http';
3
- import { NodeHTTPRequest } from '../../types';
1
+ // @trpc/server
2
+ import { TRPCError } from '../../../../@trpc-server';
3
+ import type { BodyResult } from '../../../../http';
4
+ import type { NodeHTTPRequest } from '../../types';
4
5
 
5
6
  export async function getPostBody(opts: {
6
7
  req: NodeHTTPRequest;
@@ -1,6 +1,8 @@
1
- import { AnyRouter } from '@trpc/core';
2
- import { BaseContentTypeHandler } from '../../../http';
3
- import {
1
+ // @trpc/server
2
+ import type { AnyRouter } from '../../../@trpc-server';
3
+ // @trpc/server/http
4
+ import type { BaseContentTypeHandler } from '../../../@trpc-server/http';
5
+ import type {
4
6
  NodeHTTPRequest,
5
7
  NodeHTTPRequestHandlerOptions,
6
8
  NodeHTTPResponse,
@@ -1,16 +1,26 @@
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
1
11
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { AnyRouter } from '@trpc/core';
3
- import {
4
- getBatchStreamFormatter,
12
+ // @trpc/server
13
+ import type { AnyRouter } from '../../@trpc-server';
14
+ import type {
5
15
  HTTPRequest,
6
16
  HTTPResponse,
7
17
  ResolveHTTPRequestOptionsContextFn,
8
- resolveHTTPResponse,
9
18
  ResponseChunk,
10
19
  } from '../../http';
20
+ import { getBatchStreamFormatter, resolveHTTPResponse } from '../../http';
11
21
  import { nodeHTTPJSONContentTypeHandler } from './content-type/json';
12
- import { NodeHTTPContentTypeHandler } from './internals/contentType';
13
- import {
22
+ import type { NodeHTTPContentTypeHandler } from './internals/contentType';
23
+ import type {
14
24
  NodeHTTPRequest,
15
25
  NodeHTTPRequestHandlerOptions,
16
26
  NodeHTTPResponse,
@@ -1,7 +1,24 @@
1
- import { IncomingMessage, ServerResponse } from 'http';
2
- import { AnyRouter, inferRouterContext, MaybePromise } from '@trpc/core';
3
- import { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../http';
4
- import { NodeHTTPContentTypeHandler } from './internals/contentType';
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
11
+ import type { IncomingMessage, ServerResponse } from 'http';
12
+ // eslint-disable-next-line no-restricted-imports
13
+ import type { MaybePromise } from '@trpc/core';
14
+ // @trpc/server
15
+ import type { AnyRouter, inferRouterContext } from '../../@trpc-server';
16
+ // @trpc/server/http
17
+ import type {
18
+ HTTPBaseHandlerOptions,
19
+ TRPCRequestInfo,
20
+ } from '../../@trpc-server/http';
21
+ import type { NodeHTTPContentTypeHandler } from './internals/contentType';
5
22
 
6
23
  interface ParsedQs {
7
24
  [key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
@@ -30,13 +47,13 @@ export type NodeHTTPCreateContextOption<
30
47
  > = object extends inferRouterContext<TRouter>
31
48
  ? {
32
49
  /**
33
- * @link https://trpc.io/docs/context
50
+ * @link https://trpc.io/docs/v11/context
34
51
  **/
35
52
  createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
36
53
  }
37
54
  : {
38
55
  /**
39
- * @link https://trpc.io/docs/context
56
+ * @link https://trpc.io/docs/v11/context
40
57
  **/
41
58
  createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
42
59
  };
@@ -1,11 +1,22 @@
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * Do **not** import from `@trpc/core`
5
+ * @example
6
+ * ```ts
7
+ * import type { AnyTRPCRouter } from '@trpc/server'
8
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
+ * ```
10
+ */
1
11
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
12
  import http from 'http';
3
- import { AnyRouter } from '@trpc/core';
4
- import {
13
+ // @trpc/server
14
+ import type { AnyRouter } from '../@trpc-server';
15
+ import type {
5
16
  NodeHTTPCreateContextFnOptions,
6
17
  NodeHTTPHandlerOptions,
7
- nodeHTTPRequestHandler,
8
18
  } from './node-http';
19
+ import { nodeHTTPRequestHandler } from './node-http';
9
20
 
10
21
  export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> =
11
22
  NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
@@ -1,31 +1,38 @@
1
- import { IncomingMessage } from 'http';
1
+ import type { IncomingMessage } from 'http';
2
+ // eslint-disable-next-line no-restricted-imports
3
+ import type { MaybePromise } from '@trpc/core';
4
+ import type { BaseHandlerOptions } from '@trpc/core/http';
5
+ import type { Unsubscribable } from '@trpc/core/observable';
6
+ import { isObservable } from '@trpc/core/observable';
7
+ import type {
8
+ JSONRPC2,
9
+ TRPCClientOutgoingMessage,
10
+ TRPCReconnectNotification,
11
+ TRPCResponseMessage,
12
+ } from '@trpc/core/rpc';
13
+ import { parseTRPCMessage } from '@trpc/core/rpc';
14
+ import type ws from 'ws';
15
+ import type { AnyRouter, inferRouterContext } from '../@trpc-server';
2
16
  import {
3
- AnyRouter,
4
17
  callProcedure,
5
18
  getErrorShape,
6
19
  getTRPCErrorFromUnknown,
7
- inferRouterContext,
8
- MaybePromise,
9
20
  transformTRPCResponse,
10
21
  TRPCError,
11
- } from '@trpc/core';
12
- import { BaseHandlerOptions } from '@trpc/core/http';
13
- import { isObservable, Unsubscribable } from '@trpc/core/observable';
14
- import {
15
- JSONRPC2,
16
- parseTRPCMessage,
17
- TRPCClientOutgoingMessage,
18
- TRPCReconnectNotification,
19
- TRPCResponseMessage,
20
- } from '@trpc/core/rpc';
21
- import { WebSocket, WebSocketServer } from 'ws';
22
- import { NodeHTTPCreateContextFnOptions } from './node-http';
22
+ } from '../@trpc-server';
23
+ import type { NodeHTTPCreateContextFnOptions } from './node-http';
24
+
25
+ /**
26
+ * Importing ws causes a build error
27
+ * @link https://github.com/trpc/trpc/pull/5279
28
+ */
29
+ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
23
30
 
24
31
  /**
25
32
  * @public
26
33
  */
27
34
  export type CreateWSSContextFnOptions = Omit<
28
- NodeHTTPCreateContextFnOptions<IncomingMessage, WebSocket>,
35
+ NodeHTTPCreateContextFnOptions<IncomingMessage, ws.WebSocket>,
29
36
  'info'
30
37
  >;
31
38
 
@@ -46,17 +53,17 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<
46
53
  (object extends inferRouterContext<TRouter>
47
54
  ? {
48
55
  /**
49
- * @link https://trpc.io/docs/context
56
+ * @link https://trpc.io/docs/v11/context
50
57
  **/
51
58
  createContext?: CreateWSSContextFn<TRouter>;
52
59
  }
53
60
  : {
54
61
  /**
55
- * @link https://trpc.io/docs/context
62
+ * @link https://trpc.io/docs/v11/context
56
63
  **/
57
64
  createContext: CreateWSSContextFn<TRouter>;
58
65
  }) & {
59
- wss: WebSocketServer;
66
+ wss: ws.WebSocketServer;
60
67
  process?: NodeJS.Process;
61
68
  };
62
69
 
@@ -184,7 +191,7 @@ export function applyWSSHandler<TRouter extends AnyRouter>(
184
191
  },
185
192
  });
186
193
  /* istanbul ignore next -- @preserve */
187
- if (client.readyState !== client.OPEN) {
194
+ if (client.readyState !== WEBSOCKET_OPEN) {
188
195
  // if the client got disconnected whilst initializing the subscription
189
196
  // no need to send stopped message if the client is disconnected
190
197
  sub.unsubscribe();
@@ -319,7 +326,7 @@ export function applyWSSHandler<TRouter extends AnyRouter>(
319
326
  };
320
327
  const data = JSON.stringify(response);
321
328
  for (const client of wss.clients) {
322
- if (client.readyState === 1 /* ws.OPEN */) {
329
+ if (client.readyState === WEBSOCKET_OPEN) {
323
330
  client.send(data);
324
331
  }
325
332
  }
package/src/http.ts CHANGED
@@ -1,2 +1 @@
1
- // This should be moved to a like `@trpc/plugin`-package
2
- export * from '@trpc/core/http';
1
+ export * from './@trpc-server/http';
package/src/index.ts CHANGED
@@ -1,34 +1 @@
1
- export {
2
- TRPCError,
3
- /**
4
- * @deprecated use `experimental_trpcMiddleware` instead
5
- */
6
- experimental_standaloneMiddleware,
7
- experimental_standaloneMiddleware as experimental_trpcMiddleware,
8
- initTRPC,
9
- type inferProcedureInput,
10
- type inferProcedureOutput,
11
- type inferRouterError,
12
- type inferRouterInputs,
13
- type inferRouterOutputs,
14
- type AnyProcedure as AnyTRPCProcedure,
15
- type AnyRouter as AnyTRPCRouter,
16
- } from './unstableDoNotImportThis';
17
-
18
- export type {
19
- /**
20
- * @deprecated use `AnyTRPCProcedure` instead
21
- */
22
- AnyProcedure,
23
- /**
24
- * @deprecated use `AnyTRPCRouter` instead
25
- */
26
- AnyRouter,
27
- } from '@trpc/core';
28
-
29
- /**
30
- * @deprecated
31
- * Use `Awaited<ReturnType<typeof myFunction>>` instead
32
- */
33
- export type inferAsyncReturnType<TFunction extends (...args: any[]) => any> =
34
- Awaited<ReturnType<TFunction>>;
1
+ export * from './@trpc-server';
@@ -1 +0,0 @@
1
- {"version":3,"file":"unstableDoNotImportThis.d.ts","sourceRoot":"","sources":["../src/unstableDoNotImportThis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC"}