@trpc/server 11.0.0-next-beta.208 → 11.0.0-next-beta.218
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.
- package/dist/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/{@trpc-server.d.ts → @trpc/server/index.d.ts} +4 -4
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -3
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +5 -4
- package/dist/adapters/aws-lambda/utils.mjs +3 -2
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +6 -3
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +4 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +6 -4
- package/dist/adapters/fetch/fetchRequestHandler.mjs +4 -2
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +4 -2
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +6 -4
- package/dist/adapters/next.mjs +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +6 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +4 -2
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.d.ts +3 -3
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +30 -25
- package/dist/adapters/ws.mjs +8 -3
- package/dist/bundle-analysis.json +416 -75
- package/dist/http.d.ts +1 -1
- package/dist/http.js +11 -7
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -41
- package/dist/index.mjs +8 -1
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -7
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +6 -9
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +11 -8
- package/src/@trpc/server/http.ts +26 -0
- package/src/{@trpc-server.ts → @trpc/server/index.ts} +3 -3
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +6 -3
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +15 -14
- package/src/http.ts +1 -1
- package/src/index.ts +1 -1
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -2
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -9
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/@trpc-server.d.ts.map +0 -1
- package/dist/observable.d.ts +0 -2
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -12
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -9
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export {
|
|
2
|
+
getHTTPStatusCode,
|
|
3
|
+
getHTTPStatusCodeFromError,
|
|
4
|
+
} from '../../unstable-core-do-not-import';
|
|
5
|
+
export { resolveHTTPResponse } from '../../unstable-core-do-not-import';
|
|
6
|
+
export type {
|
|
7
|
+
BaseHandlerOptions,
|
|
8
|
+
HTTPBaseHandlerOptions,
|
|
9
|
+
HTTPHeaders,
|
|
10
|
+
HTTPRequest,
|
|
11
|
+
HTTPResponse,
|
|
12
|
+
OnErrorFunction,
|
|
13
|
+
ProcedureCall,
|
|
14
|
+
ResolveHTTPRequestOptionsContextFn,
|
|
15
|
+
ResponseChunk,
|
|
16
|
+
ResponseMeta,
|
|
17
|
+
ResponseMetaFn,
|
|
18
|
+
TRPCRequestInfo,
|
|
19
|
+
} from '../../unstable-core-do-not-import';
|
|
20
|
+
|
|
21
|
+
export { getBatchStreamFormatter } from '../../unstable-core-do-not-import';
|
|
22
|
+
export type {
|
|
23
|
+
BaseContentTypeHandler,
|
|
24
|
+
BodyResult,
|
|
25
|
+
} from '../../unstable-core-do-not-import';
|
|
26
|
+
export { getJsonContentTypeInputs } from '../../unstable-core-do-not-import';
|
|
@@ -29,7 +29,7 @@ export {
|
|
|
29
29
|
type ProcedureRouterRecord as TRPCProcedureRouterRecord,
|
|
30
30
|
type ProcedureArgs as TRPCProcedureArgs,
|
|
31
31
|
type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure,
|
|
32
|
-
} from '
|
|
32
|
+
} from '../../unstable-core-do-not-import';
|
|
33
33
|
|
|
34
34
|
export type {
|
|
35
35
|
/**
|
|
@@ -83,7 +83,7 @@ export type {
|
|
|
83
83
|
* @deprecated use `AnyTRPCSubscriptionProcedure` instead
|
|
84
84
|
*/
|
|
85
85
|
AnySubscriptionProcedure,
|
|
86
|
-
} from '
|
|
86
|
+
} from '../../unstable-core-do-not-import';
|
|
87
87
|
|
|
88
88
|
export {
|
|
89
89
|
/**
|
|
@@ -95,7 +95,7 @@ export {
|
|
|
95
95
|
* @deprecated use `callTRPCProcedure` instead
|
|
96
96
|
*/
|
|
97
97
|
callProcedure,
|
|
98
|
-
} from '
|
|
98
|
+
} from '../../unstable-core-do-not-import';
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* @deprecated
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Note: this should likely be moved to a sort of `@trpc/plugin` package
|
|
2
|
+
export type {
|
|
3
|
+
JSONRPC2,
|
|
4
|
+
TRPCClientIncomingMessage,
|
|
5
|
+
TRPCClientIncomingRequest,
|
|
6
|
+
TRPCClientOutgoingMessage,
|
|
7
|
+
TRPCClientOutgoingRequest,
|
|
8
|
+
TRPCErrorResponse,
|
|
9
|
+
TRPCErrorShape,
|
|
10
|
+
TRPCReconnectNotification,
|
|
11
|
+
TRPCRequest,
|
|
12
|
+
TRPCRequestMessage,
|
|
13
|
+
TRPCResponse,
|
|
14
|
+
TRPCResponseMessage,
|
|
15
|
+
TRPCResult,
|
|
16
|
+
TRPCResultMessage,
|
|
17
|
+
TRPCSubscriptionStopNotification,
|
|
18
|
+
TRPCSuccessResponse,
|
|
19
|
+
TRPC_ERROR_CODE_KEY,
|
|
20
|
+
TRPC_ERROR_CODE_NUMBER,
|
|
21
|
+
} from '../../unstable-core-do-not-import';
|
|
22
|
+
export {
|
|
23
|
+
TRPC_ERROR_CODES_BY_KEY,
|
|
24
|
+
TRPC_ERROR_CODES_BY_NUMBER,
|
|
25
|
+
parseTRPCMessage,
|
|
26
|
+
} from '../../unstable-core-do-not-import';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -16,15 +15,15 @@ import type {
|
|
|
16
15
|
Context as APIGWContext,
|
|
17
16
|
} from 'aws-lambda';
|
|
18
17
|
// @trpc/server
|
|
19
|
-
import type { AnyRouter } from '../../@trpc
|
|
18
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
20
19
|
// @trpc/server
|
|
21
|
-
import { TRPCError } from '../../@trpc
|
|
20
|
+
import { TRPCError } from '../../@trpc/server';
|
|
22
21
|
import type {
|
|
23
22
|
HTTPRequest,
|
|
24
23
|
HTTPResponse,
|
|
25
24
|
ResolveHTTPRequestOptionsContextFn,
|
|
26
|
-
} from '
|
|
27
|
-
import { resolveHTTPResponse } from '
|
|
25
|
+
} from '../../@trpc/server/http';
|
|
26
|
+
import { resolveHTTPResponse } from '../../@trpc/server/http';
|
|
28
27
|
import type {
|
|
29
28
|
APIGatewayEvent,
|
|
30
29
|
APIGatewayResult,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -15,16 +14,16 @@ import type {
|
|
|
15
14
|
APIGatewayProxyStructuredResultV2,
|
|
16
15
|
Context as APIGWContext,
|
|
17
16
|
} from 'aws-lambda';
|
|
18
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc
|
|
17
|
+
import type { AnyRouter, inferRouterContext } from '../../@trpc/server'; // import @trpc/server
|
|
19
18
|
|
|
20
19
|
// @trpc/server
|
|
21
|
-
import { TRPCError } from '../../@trpc
|
|
20
|
+
import { TRPCError } from '../../@trpc/server';
|
|
22
21
|
import type {
|
|
23
22
|
HTTPHeaders,
|
|
24
23
|
OnErrorFunction,
|
|
25
24
|
ResponseMetaFn,
|
|
26
25
|
TRPCRequestInfo,
|
|
27
|
-
} from '
|
|
26
|
+
} from '../../@trpc/server/http';
|
|
28
27
|
|
|
29
28
|
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
30
29
|
export type APIGatewayResult =
|
package/src/adapters/express.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -9,8 +8,7 @@
|
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
10
|
import type * as express from 'express';
|
|
12
|
-
|
|
13
|
-
import type { AnyRouter } from '../@trpc-server';
|
|
11
|
+
import type { AnyRouter } from '../@trpc/server';
|
|
14
12
|
import type {
|
|
15
13
|
NodeHTTPCreateContextFnOptions,
|
|
16
14
|
NodeHTTPHandlerOptions,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -11,15 +10,18 @@
|
|
|
11
10
|
import { Readable } from 'node:stream';
|
|
12
11
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
13
12
|
// @trpc/server
|
|
14
|
-
import type { AnyRouter } from '../../@trpc
|
|
13
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
15
14
|
import type {
|
|
16
15
|
HTTPBaseHandlerOptions,
|
|
17
16
|
HTTPRequest,
|
|
18
17
|
HTTPResponse,
|
|
19
18
|
ResolveHTTPRequestOptionsContextFn,
|
|
20
19
|
ResponseChunk,
|
|
21
|
-
} from '
|
|
22
|
-
import {
|
|
20
|
+
} from '../../@trpc/server/http';
|
|
21
|
+
import {
|
|
22
|
+
getBatchStreamFormatter,
|
|
23
|
+
resolveHTTPResponse,
|
|
24
|
+
} from '../../@trpc/server/http';
|
|
23
25
|
import type { NodeHTTPCreateContextOption } from '../node-http';
|
|
24
26
|
|
|
25
27
|
export type FastifyHandlerOptions<
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -12,7 +11,7 @@
|
|
|
12
11
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
13
12
|
import type { FastifyHandlerOptions } from '.';
|
|
14
13
|
// @trpc/server
|
|
15
|
-
import type { AnyRouter } from '../../@trpc
|
|
14
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
16
15
|
import type { NodeHTTPCreateContextFnOptions } from '../node-http';
|
|
17
16
|
import type { WSSHandlerOptions } from '../ws';
|
|
18
17
|
import { applyWSSHandler } from '../ws';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -9,14 +8,17 @@
|
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
10
|
// @trpc/server
|
|
12
|
-
import type { AnyRouter } from '../../@trpc
|
|
11
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
13
12
|
import type {
|
|
14
13
|
HTTPRequest,
|
|
15
14
|
HTTPResponse,
|
|
16
15
|
ResolveHTTPRequestOptionsContextFn,
|
|
17
16
|
ResponseChunk,
|
|
18
|
-
} from '
|
|
19
|
-
import {
|
|
17
|
+
} from '../../@trpc/server/http';
|
|
18
|
+
import {
|
|
19
|
+
getBatchStreamFormatter,
|
|
20
|
+
resolveHTTPResponse,
|
|
21
|
+
} from '../../@trpc/server/http';
|
|
20
22
|
import type { FetchHandlerOptions } from './types';
|
|
21
23
|
|
|
22
24
|
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> =
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -9,12 +8,12 @@
|
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
10
|
// @trpc/server
|
|
12
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc
|
|
11
|
+
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
13
12
|
// @trpc/server/http
|
|
14
13
|
import type {
|
|
15
14
|
HTTPBaseHandlerOptions,
|
|
16
15
|
TRPCRequestInfo,
|
|
17
|
-
} from '../../@trpc
|
|
16
|
+
} from '../../@trpc/server/http';
|
|
18
17
|
|
|
19
18
|
export type FetchCreateContextFnOptions = {
|
|
20
19
|
req: Request;
|
package/src/adapters/next.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -10,9 +9,9 @@
|
|
|
10
9
|
*/
|
|
11
10
|
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
12
11
|
// @trpc/server
|
|
13
|
-
import type { AnyRouter } from '../@trpc
|
|
12
|
+
import type { AnyRouter } from '../@trpc/server';
|
|
14
13
|
// @trpc/server
|
|
15
|
-
import { getErrorShape, TRPCError } from '../@trpc
|
|
14
|
+
import { getErrorShape, TRPCError } from '../@trpc/server';
|
|
16
15
|
import type {
|
|
17
16
|
NodeHTTPCreateContextFnOptions,
|
|
18
17
|
NodeHTTPHandlerOptions,
|
|
@@ -23,6 +22,10 @@ export type CreateNextContextOptions = NodeHTTPCreateContextFnOptions<
|
|
|
23
22
|
NextApiRequest,
|
|
24
23
|
NextApiResponse
|
|
25
24
|
>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Preventing "TypeScript where it's tough not to get "The inferred type of 'xxxx' cannot be named without a reference to [...]"
|
|
28
|
+
*/
|
|
26
29
|
export type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
27
30
|
|
|
28
31
|
export function createNextApiHandler<TRouter extends AnyRouter>(
|
|
@@ -14,7 +14,7 @@ import { Readable } from 'node:stream';
|
|
|
14
14
|
// @ts-ignore the type definitions for this package are borked
|
|
15
15
|
import { streamMultipart } from '@web3-storage/multipart-parser';
|
|
16
16
|
// @trpc/server
|
|
17
|
-
import type { CombinedDataTransformer } from '../../../../@trpc
|
|
17
|
+
import type { CombinedDataTransformer } from '../../../../@trpc/server';
|
|
18
18
|
import { createNodeHTTPContentTypeHandler } from '../../internals/contentType';
|
|
19
19
|
import type { NodeHTTPRequest } from '../../types';
|
|
20
20
|
import { NodeOnDiskFile } from './fileUploadHandler';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @trpc/server
|
|
2
|
-
import { TRPCError } from '../../../../@trpc
|
|
3
|
-
import type { BodyResult } from '
|
|
2
|
+
import { TRPCError } from '../../../../@trpc/server';
|
|
3
|
+
import type { BodyResult } from '../../../../@trpc/server/http';
|
|
4
4
|
import type { NodeHTTPRequest } from '../../types';
|
|
5
5
|
|
|
6
6
|
export async function getPostBody(opts: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @trpc/server
|
|
2
|
-
import type { AnyRouter } from '../../../@trpc
|
|
2
|
+
import type { AnyRouter } from '../../../@trpc/server';
|
|
3
3
|
// @trpc/server/http
|
|
4
|
-
import type { BaseContentTypeHandler } from '../../../@trpc
|
|
4
|
+
import type { BaseContentTypeHandler } from '../../../@trpc/server/http';
|
|
5
5
|
import type {
|
|
6
6
|
NodeHTTPRequest,
|
|
7
7
|
NodeHTTPRequestHandlerOptions,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -10,14 +9,17 @@
|
|
|
10
9
|
*/
|
|
11
10
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
12
11
|
// @trpc/server
|
|
13
|
-
import type { AnyRouter } from '../../@trpc
|
|
12
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
14
13
|
import type {
|
|
15
14
|
HTTPRequest,
|
|
16
15
|
HTTPResponse,
|
|
17
16
|
ResolveHTTPRequestOptionsContextFn,
|
|
18
17
|
ResponseChunk,
|
|
19
|
-
} from '
|
|
20
|
-
import {
|
|
18
|
+
} from '../../@trpc/server/http';
|
|
19
|
+
import {
|
|
20
|
+
getBatchStreamFormatter,
|
|
21
|
+
resolveHTTPResponse,
|
|
22
|
+
} from '../../@trpc/server/http';
|
|
21
23
|
import { nodeHTTPJSONContentTypeHandler } from './content-type/json';
|
|
22
24
|
import type { NodeHTTPContentTypeHandler } from './internals/contentType';
|
|
23
25
|
import type {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -9,15 +8,15 @@
|
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
10
|
import type { IncomingMessage, ServerResponse } from 'http';
|
|
12
|
-
// eslint-disable-next-line no-restricted-imports
|
|
13
|
-
import type { MaybePromise } from '@trpc/core';
|
|
14
11
|
// @trpc/server
|
|
15
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc
|
|
12
|
+
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
16
13
|
// @trpc/server/http
|
|
17
14
|
import type {
|
|
18
15
|
HTTPBaseHandlerOptions,
|
|
19
16
|
TRPCRequestInfo,
|
|
20
|
-
} from '../../@trpc
|
|
17
|
+
} from '../../@trpc/server/http';
|
|
18
|
+
// eslint-disable-next-line no-restricted-imports
|
|
19
|
+
import type { MaybePromise } from '../../unstable-core-do-not-import';
|
|
21
20
|
import type { NodeHTTPContentTypeHandler } from './internals/contentType';
|
|
22
21
|
|
|
23
22
|
interface ParsedQs {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -11,7 +10,7 @@
|
|
|
11
10
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
12
11
|
import http from 'http';
|
|
13
12
|
// @trpc/server
|
|
14
|
-
import type { AnyRouter } from '../@trpc
|
|
13
|
+
import type { AnyRouter } from '../@trpc/server';
|
|
15
14
|
import type {
|
|
16
15
|
NodeHTTPCreateContextFnOptions,
|
|
17
16
|
NodeHTTPHandlerOptions,
|
|
@@ -37,6 +36,7 @@ export function createHTTPHandler<TRouter extends AnyRouter>(
|
|
|
37
36
|
await nodeHTTPRequestHandler({
|
|
38
37
|
// FIXME: no typecasting should be needed here
|
|
39
38
|
...(opts as CreateHTTPHandlerOptions<AnyRouter>),
|
|
39
|
+
...(opts as any),
|
|
40
40
|
req,
|
|
41
41
|
res,
|
|
42
42
|
path,
|
package/src/adapters/ws.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
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
2
|
import type ws from 'ws';
|
|
15
|
-
import type { AnyRouter, inferRouterContext } from '../@trpc
|
|
3
|
+
import type { AnyRouter, inferRouterContext } from '../@trpc/server';
|
|
16
4
|
import {
|
|
17
5
|
callProcedure,
|
|
18
6
|
getErrorShape,
|
|
19
7
|
getTRPCErrorFromUnknown,
|
|
20
8
|
transformTRPCResponse,
|
|
21
9
|
TRPCError,
|
|
22
|
-
} from '../@trpc
|
|
10
|
+
} from '../@trpc/server';
|
|
11
|
+
import type { BaseHandlerOptions } from '../@trpc/server/http';
|
|
12
|
+
import { parseTRPCMessage } from '../@trpc/server/rpc';
|
|
13
|
+
// @trpc/server/rpc
|
|
14
|
+
import type {
|
|
15
|
+
JSONRPC2,
|
|
16
|
+
TRPCClientOutgoingMessage,
|
|
17
|
+
TRPCReconnectNotification,
|
|
18
|
+
TRPCResponseMessage,
|
|
19
|
+
} from '../@trpc/server/rpc';
|
|
20
|
+
import { isObservable } from '../observable';
|
|
21
|
+
import type { Unsubscribable } from '../observable';
|
|
22
|
+
// eslint-disable-next-line no-restricted-imports
|
|
23
|
+
import type { MaybePromise } from '../unstable-core-do-not-import';
|
|
23
24
|
import type { NodeHTTPCreateContextFnOptions } from './node-http';
|
|
24
25
|
|
|
25
26
|
/**
|
package/src/http.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './@trpc
|
|
1
|
+
export * from './@trpc/server/http';
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './@trpc
|
|
1
|
+
export * from './@trpc/server';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { inferObservableValue } from './observable';
|
|
2
|
+
export { isObservable, observable, observableToPromise } from './observable';
|
|
3
|
+
export { map, share, tap } from './operators';
|
|
4
|
+
export type {
|
|
5
|
+
Observable,
|
|
6
|
+
Observer,
|
|
7
|
+
TeardownLogic,
|
|
8
|
+
Unsubscribable,
|
|
9
|
+
UnsubscribeFn,
|
|
10
|
+
} from './types';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Observable,
|
|
3
|
+
Observer,
|
|
4
|
+
OperatorFunction,
|
|
5
|
+
TeardownLogic,
|
|
6
|
+
UnaryFunction,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
function identity<TType>(x: TType): TType {
|
|
10
|
+
return x;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @public */
|
|
14
|
+
export type inferObservableValue<TObservable> = TObservable extends Observable<
|
|
15
|
+
infer TValue,
|
|
16
|
+
unknown
|
|
17
|
+
>
|
|
18
|
+
? TValue
|
|
19
|
+
: never;
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export function isObservable(x: unknown): x is Observable<unknown, unknown> {
|
|
23
|
+
return typeof x === 'object' && x !== null && 'subscribe' in x;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export function observable<TValue, TError = unknown>(
|
|
28
|
+
subscribe: (observer: Observer<TValue, TError>) => TeardownLogic,
|
|
29
|
+
): Observable<TValue, TError> {
|
|
30
|
+
const self: Observable<TValue, TError> = {
|
|
31
|
+
subscribe(observer) {
|
|
32
|
+
let teardownRef: TeardownLogic | null = null;
|
|
33
|
+
let isDone = false;
|
|
34
|
+
let unsubscribed = false;
|
|
35
|
+
let teardownImmediately = false;
|
|
36
|
+
function unsubscribe() {
|
|
37
|
+
if (teardownRef === null) {
|
|
38
|
+
teardownImmediately = true;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (unsubscribed) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
unsubscribed = true;
|
|
45
|
+
|
|
46
|
+
if (typeof teardownRef === 'function') {
|
|
47
|
+
teardownRef();
|
|
48
|
+
} else if (teardownRef) {
|
|
49
|
+
teardownRef.unsubscribe();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
teardownRef = subscribe({
|
|
53
|
+
next(value) {
|
|
54
|
+
if (isDone) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
observer.next?.(value);
|
|
58
|
+
},
|
|
59
|
+
error(err) {
|
|
60
|
+
if (isDone) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
isDone = true;
|
|
64
|
+
observer.error?.(err);
|
|
65
|
+
unsubscribe();
|
|
66
|
+
},
|
|
67
|
+
complete() {
|
|
68
|
+
if (isDone) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
isDone = true;
|
|
72
|
+
observer.complete?.();
|
|
73
|
+
unsubscribe();
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (teardownImmediately) {
|
|
77
|
+
unsubscribe();
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
unsubscribe,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
pipe(
|
|
84
|
+
...operations: OperatorFunction<any, any, any, any>[]
|
|
85
|
+
): Observable<any, any> {
|
|
86
|
+
return pipeFromArray(operations)(self) as any;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
return self;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pipeFromArray<TSource, TReturn>(
|
|
93
|
+
fns: UnaryFunction<TSource, TReturn>[],
|
|
94
|
+
): UnaryFunction<TSource, TReturn> {
|
|
95
|
+
if (fns.length === 0) {
|
|
96
|
+
return identity as UnaryFunction<any, any>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (fns.length === 1) {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
101
|
+
return fns[0]!;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return function piped(input: TSource): TReturn {
|
|
105
|
+
return fns.reduce(
|
|
106
|
+
(prev: any, fn: UnaryFunction<TSource, TReturn>) => fn(prev),
|
|
107
|
+
input as any,
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class ObservableAbortError extends Error {
|
|
113
|
+
constructor(message: string) {
|
|
114
|
+
super(message);
|
|
115
|
+
this.name = 'ObservableAbortError';
|
|
116
|
+
Object.setPrototypeOf(this, ObservableAbortError.prototype);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @internal */
|
|
121
|
+
export function observableToPromise<TValue>(
|
|
122
|
+
observable: Observable<TValue, unknown>,
|
|
123
|
+
) {
|
|
124
|
+
let abort: () => void;
|
|
125
|
+
const promise = new Promise<TValue>((resolve, reject) => {
|
|
126
|
+
let isDone = false;
|
|
127
|
+
function onDone() {
|
|
128
|
+
if (isDone) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
isDone = true;
|
|
132
|
+
reject(new ObservableAbortError('This operation was aborted.'));
|
|
133
|
+
obs$.unsubscribe();
|
|
134
|
+
}
|
|
135
|
+
const obs$ = observable.subscribe({
|
|
136
|
+
next(data) {
|
|
137
|
+
isDone = true;
|
|
138
|
+
resolve(data);
|
|
139
|
+
onDone();
|
|
140
|
+
},
|
|
141
|
+
error(data) {
|
|
142
|
+
isDone = true;
|
|
143
|
+
reject(data);
|
|
144
|
+
onDone();
|
|
145
|
+
},
|
|
146
|
+
complete() {
|
|
147
|
+
isDone = true;
|
|
148
|
+
onDone();
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
abort = onDone;
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
promise,
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
156
|
+
abort: abort!,
|
|
157
|
+
};
|
|
158
|
+
}
|