@trpc/server 11.0.0-alpha-tmp-export-from-main.218 → 11.0.0-alpha-tmp-export-from-main-nuke-core.239
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/index.d.ts +69 -0
- 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 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -2
- 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 +1 -3
- 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/internals/contentType.d.ts.map +1 -1
- 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 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -26
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -21
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +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 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -13
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +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 +53 -125
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- 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 +2 -4
- 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 +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- 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 -26
- 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 -10
- 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/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -30
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MonoTypeOperatorFunction,
|
|
3
|
+
Observer,
|
|
4
|
+
OperatorFunction,
|
|
5
|
+
Unsubscribable,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
export function map<TValueBefore, TError, TValueAfter>(
|
|
9
|
+
project: (value: TValueBefore, index: number) => TValueAfter,
|
|
10
|
+
): OperatorFunction<TValueBefore, TError, TValueAfter, TError> {
|
|
11
|
+
return (originalObserver) => {
|
|
12
|
+
return {
|
|
13
|
+
subscribe(observer) {
|
|
14
|
+
let index = 0;
|
|
15
|
+
const subscription = originalObserver.subscribe({
|
|
16
|
+
next(value) {
|
|
17
|
+
observer.next?.(project(value, index++));
|
|
18
|
+
},
|
|
19
|
+
error(error) {
|
|
20
|
+
observer.error?.(error);
|
|
21
|
+
},
|
|
22
|
+
complete() {
|
|
23
|
+
observer.complete?.();
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return subscription;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ShareConfig {}
|
|
33
|
+
export function share<TValue, TError>(
|
|
34
|
+
_opts?: ShareConfig,
|
|
35
|
+
): MonoTypeOperatorFunction<TValue, TError> {
|
|
36
|
+
return (originalObserver) => {
|
|
37
|
+
let refCount = 0;
|
|
38
|
+
|
|
39
|
+
let subscription: Unsubscribable | null = null;
|
|
40
|
+
const observers: Partial<Observer<TValue, TError>>[] = [];
|
|
41
|
+
|
|
42
|
+
function startIfNeeded() {
|
|
43
|
+
if (subscription) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
subscription = originalObserver.subscribe({
|
|
47
|
+
next(value) {
|
|
48
|
+
for (const observer of observers) {
|
|
49
|
+
observer.next?.(value);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
error(error) {
|
|
53
|
+
for (const observer of observers) {
|
|
54
|
+
observer.error?.(error);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
complete() {
|
|
58
|
+
for (const observer of observers) {
|
|
59
|
+
observer.complete?.();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function resetIfNeeded() {
|
|
65
|
+
// "resetOnRefCountZero"
|
|
66
|
+
if (refCount === 0 && subscription) {
|
|
67
|
+
const _sub = subscription;
|
|
68
|
+
subscription = null;
|
|
69
|
+
_sub.unsubscribe();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
subscribe(observer) {
|
|
75
|
+
refCount++;
|
|
76
|
+
|
|
77
|
+
observers.push(observer);
|
|
78
|
+
startIfNeeded();
|
|
79
|
+
return {
|
|
80
|
+
unsubscribe() {
|
|
81
|
+
refCount--;
|
|
82
|
+
resetIfNeeded();
|
|
83
|
+
|
|
84
|
+
const index = observers.findIndex((v) => v === observer);
|
|
85
|
+
|
|
86
|
+
if (index > -1) {
|
|
87
|
+
observers.splice(index, 1);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function tap<TValue, TError>(
|
|
97
|
+
observer: Partial<Observer<TValue, TError>>,
|
|
98
|
+
): MonoTypeOperatorFunction<TValue, TError> {
|
|
99
|
+
return (originalObserver) => {
|
|
100
|
+
return {
|
|
101
|
+
subscribe(observer2) {
|
|
102
|
+
return originalObserver.subscribe({
|
|
103
|
+
next(v) {
|
|
104
|
+
observer.next?.(v);
|
|
105
|
+
observer2.next?.(v);
|
|
106
|
+
},
|
|
107
|
+
error(v) {
|
|
108
|
+
observer.error?.(v);
|
|
109
|
+
observer2.error?.(v);
|
|
110
|
+
},
|
|
111
|
+
complete() {
|
|
112
|
+
observer.complete?.();
|
|
113
|
+
observer2.complete?.();
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface Unsubscribable {
|
|
2
|
+
unsubscribe(): void;
|
|
3
|
+
}
|
|
4
|
+
export type UnsubscribeFn = () => void;
|
|
5
|
+
interface Subscribable<TValue, TError> {
|
|
6
|
+
subscribe(observer: Partial<Observer<TValue, TError>>): Unsubscribable;
|
|
7
|
+
}
|
|
8
|
+
export interface Observable<TValue, TError>
|
|
9
|
+
extends Subscribable<TValue, TError> {
|
|
10
|
+
pipe(): Observable<TValue, TError>;
|
|
11
|
+
pipe<TValue1, TError1>(
|
|
12
|
+
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
13
|
+
): Observable<TValue1, TError1>;
|
|
14
|
+
pipe<TValue1, TError1, TValue2, TError2>(
|
|
15
|
+
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
16
|
+
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
17
|
+
): Observable<TValue2, TError2>;
|
|
18
|
+
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3>(
|
|
19
|
+
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
20
|
+
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
21
|
+
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
22
|
+
): Observable<TValue2, TError2>;
|
|
23
|
+
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4>(
|
|
24
|
+
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
25
|
+
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
26
|
+
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
27
|
+
op4: OperatorFunction<TValue3, TError3, TValue4, TError4>,
|
|
28
|
+
): Observable<TValue2, TError2>;
|
|
29
|
+
pipe<
|
|
30
|
+
TValue1,
|
|
31
|
+
TError1,
|
|
32
|
+
TValue2,
|
|
33
|
+
TError2,
|
|
34
|
+
TValue3,
|
|
35
|
+
TError3,
|
|
36
|
+
TValue4,
|
|
37
|
+
TError4,
|
|
38
|
+
TValue5,
|
|
39
|
+
TError5,
|
|
40
|
+
>(
|
|
41
|
+
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
42
|
+
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
43
|
+
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
44
|
+
op4: OperatorFunction<TValue3, TError3, TValue4, TError4>,
|
|
45
|
+
op5: OperatorFunction<TValue4, TError4, TValue5, TError5>,
|
|
46
|
+
): Observable<TValue2, TError2>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface Observer<TValue, TError> {
|
|
50
|
+
next: (value: TValue) => void;
|
|
51
|
+
error: (err: TError) => void;
|
|
52
|
+
complete: () => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type TeardownLogic =
|
|
56
|
+
// | SubscriptionLike
|
|
57
|
+
Unsubscribable | UnsubscribeFn | void;
|
|
58
|
+
|
|
59
|
+
export type UnaryFunction<TSource, TReturn> = (source: TSource) => TReturn;
|
|
60
|
+
|
|
61
|
+
export type OperatorFunction<
|
|
62
|
+
TValueBefore,
|
|
63
|
+
TErrorBefore,
|
|
64
|
+
TValueAfter,
|
|
65
|
+
TErrorAfter,
|
|
66
|
+
> = UnaryFunction<
|
|
67
|
+
Subscribable<TValueBefore, TErrorBefore>,
|
|
68
|
+
Subscribable<TValueAfter, TErrorAfter>
|
|
69
|
+
>;
|
|
70
|
+
|
|
71
|
+
export type MonoTypeOperatorFunction<TValue, TError> = OperatorFunction<
|
|
72
|
+
TValue,
|
|
73
|
+
TError,
|
|
74
|
+
TValue,
|
|
75
|
+
TError
|
|
76
|
+
>;
|
package/src/rpc.ts
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
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 './@trpc-core-unstable-do-not-import-this-please';
|
|
22
|
-
export {
|
|
23
|
-
TRPC_ERROR_CODES_BY_KEY,
|
|
24
|
-
TRPC_ERROR_CODES_BY_NUMBER,
|
|
25
|
-
parseTRPCMessage,
|
|
26
|
-
} from './@trpc-core-unstable-do-not-import-this-please';
|
|
1
|
+
export * from './@trpc/server/rpc';
|
package/src/shared.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyRootConfig } from './rootConfig';
|
|
2
|
+
import type { AnyRouter } from './router';
|
|
3
|
+
|
|
4
|
+
export type TRPCInferrable = AnyRouter | AnyRootConfig;
|
|
5
|
+
export type inferConfig<TInferrable extends TRPCInferrable> =
|
|
6
|
+
TInferrable extends AnyRouter ? TInferrable['_def']['_config'] : TInferrable;
|
|
7
|
+
|
|
8
|
+
export type inferErrorShape<TInferrable extends TRPCInferrable> =
|
|
9
|
+
inferConfig<TInferrable>['$types']['errorShape'];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface ProxyCallbackOptions {
|
|
2
|
+
path: string[];
|
|
3
|
+
args: unknown[];
|
|
4
|
+
}
|
|
5
|
+
type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
|
|
6
|
+
|
|
7
|
+
const noop = () => {
|
|
8
|
+
// noop
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function createInnerProxy(callback: ProxyCallback, path: string[]) {
|
|
12
|
+
const proxy: unknown = new Proxy(noop, {
|
|
13
|
+
get(_obj, key) {
|
|
14
|
+
if (typeof key !== 'string' || key === 'then') {
|
|
15
|
+
// special case for if the proxy is accidentally treated
|
|
16
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return createInnerProxy(callback, [...path, key]);
|
|
20
|
+
},
|
|
21
|
+
apply(_1, _2, args) {
|
|
22
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
23
|
+
return callback({
|
|
24
|
+
args: isApply ? (args.length >= 2 ? args[1] : []) : args,
|
|
25
|
+
path: isApply ? path.slice(0, -1) : path,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return proxy;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a proxy that calls the callback with the path and arguments
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export const createRecursiveProxy = (callback: ProxyCallback) =>
|
|
39
|
+
createInnerProxy(callback, []);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export const createFlatProxy = <TFaux>(
|
|
47
|
+
callback: (path: string & keyof TFaux) => any,
|
|
48
|
+
): TFaux => {
|
|
49
|
+
return new Proxy(noop, {
|
|
50
|
+
get(_obj, name) {
|
|
51
|
+
if (typeof name !== 'string' || name === 'then') {
|
|
52
|
+
// special case for if the proxy is accidentally treated
|
|
53
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return callback(name as any);
|
|
57
|
+
},
|
|
58
|
+
}) as TFaux;
|
|
59
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
|
|
2
|
+
import { isObject } from '../utils';
|
|
3
|
+
|
|
4
|
+
class UnknownCauseError extends Error {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export function getCauseFromUnknown(cause: unknown): Error | undefined {
|
|
8
|
+
if (cause instanceof Error) {
|
|
9
|
+
return cause;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const type = typeof cause;
|
|
13
|
+
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Primitive types just get wrapped in an error
|
|
18
|
+
if (type !== 'object') {
|
|
19
|
+
return new Error(String(cause));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If it's an object, we'll create a synthetic error
|
|
23
|
+
if (isObject(cause)) {
|
|
24
|
+
const err = new UnknownCauseError();
|
|
25
|
+
for (const key in cause) {
|
|
26
|
+
err[key] = cause[key];
|
|
27
|
+
}
|
|
28
|
+
return err;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
|
|
35
|
+
if (cause instanceof TRPCError) {
|
|
36
|
+
return cause;
|
|
37
|
+
}
|
|
38
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
39
|
+
// https://github.com/trpc/trpc/pull/4848
|
|
40
|
+
return cause as TRPCError;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const trpcError = new TRPCError({
|
|
44
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
45
|
+
cause,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Inherit stack from error
|
|
49
|
+
if (cause instanceof Error && cause.stack) {
|
|
50
|
+
trpcError.stack = cause.stack;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return trpcError;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class TRPCError extends Error {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
+
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
|
|
59
|
+
public override readonly cause?: Error;
|
|
60
|
+
public readonly code;
|
|
61
|
+
|
|
62
|
+
constructor(opts: {
|
|
63
|
+
message?: string;
|
|
64
|
+
code: TRPC_ERROR_CODE_KEY;
|
|
65
|
+
cause?: unknown;
|
|
66
|
+
}) {
|
|
67
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
68
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
72
|
+
super(message, { cause });
|
|
73
|
+
|
|
74
|
+
this.code = opts.code;
|
|
75
|
+
this.name = 'TRPCError';
|
|
76
|
+
|
|
77
|
+
if (!this.cause) {
|
|
78
|
+
// < ES2022 / < Node 16.9.0 compatability
|
|
79
|
+
this.cause = cause;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ProcedureType } from '../procedure';
|
|
2
|
+
import type {
|
|
3
|
+
TRPC_ERROR_CODE_KEY,
|
|
4
|
+
TRPC_ERROR_CODE_NUMBER,
|
|
5
|
+
TRPCErrorShape,
|
|
6
|
+
} from '../rpc';
|
|
7
|
+
import type { TRPCError } from './TRPCError';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type ErrorFormatter<
|
|
13
|
+
TContext,
|
|
14
|
+
TShape extends TRPCErrorShape<number>,
|
|
15
|
+
> = (args: {
|
|
16
|
+
error: TRPCError;
|
|
17
|
+
type: ProcedureType | 'unknown';
|
|
18
|
+
path: string | undefined;
|
|
19
|
+
input: unknown;
|
|
20
|
+
ctx: TContext | undefined;
|
|
21
|
+
shape: DefaultErrorShape;
|
|
22
|
+
}) => TShape;
|
|
23
|
+
|
|
24
|
+
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
25
|
+
any,
|
|
26
|
+
infer TShape
|
|
27
|
+
>
|
|
28
|
+
? TShape
|
|
29
|
+
: DefaultErrorShape;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export type DefaultErrorData = {
|
|
34
|
+
code: TRPC_ERROR_CODE_KEY;
|
|
35
|
+
httpStatus: number;
|
|
36
|
+
path?: string;
|
|
37
|
+
stack?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export interface DefaultErrorShape
|
|
44
|
+
extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, DefaultErrorData> {
|
|
45
|
+
message: string;
|
|
46
|
+
code: TRPC_ERROR_CODE_NUMBER;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const defaultFormatter: ErrorFormatter<any, any> = ({ shape }) => {
|
|
50
|
+
return shape;
|
|
51
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getHTTPStatusCodeFromError } from '../http/getHTTPStatusCode';
|
|
2
|
+
import type { ProcedureType } from '../procedure';
|
|
3
|
+
import type { AnyRootConfig } from '../rootConfig';
|
|
4
|
+
import { TRPC_ERROR_CODES_BY_KEY } from '../rpc';
|
|
5
|
+
import type { DefaultErrorShape } from './formatter';
|
|
6
|
+
import type { TRPCError } from './TRPCError';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
12
|
+
config: TConfig;
|
|
13
|
+
error: TRPCError;
|
|
14
|
+
type: ProcedureType | 'unknown';
|
|
15
|
+
path: string | undefined;
|
|
16
|
+
input: unknown;
|
|
17
|
+
ctx: TConfig['$types']['ctx'] | undefined;
|
|
18
|
+
}): TConfig['$types']['errorShape'] {
|
|
19
|
+
const { path, error, config } = opts;
|
|
20
|
+
const { code } = opts.error;
|
|
21
|
+
const shape: DefaultErrorShape = {
|
|
22
|
+
message: error.message,
|
|
23
|
+
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
24
|
+
data: {
|
|
25
|
+
code,
|
|
26
|
+
httpStatus: getHTTPStatusCodeFromError(error),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
30
|
+
shape.data.stack = opts.error.stack;
|
|
31
|
+
}
|
|
32
|
+
if (typeof path === 'string') {
|
|
33
|
+
shape.data.path = path;
|
|
34
|
+
}
|
|
35
|
+
return config.errorFormatter({ ...opts, shape });
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a batch response as a line-delimited JSON stream
|
|
3
|
+
* that the `unstable_httpBatchStreamLink` can parse:
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const formatter = getBatchStreamFormatter();
|
|
8
|
+
* res.send(formatter(1, 'response #2'));
|
|
9
|
+
* res.send(formatter(0, 'response #1'));
|
|
10
|
+
* res.send(formatter.end());
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Expected format:
|
|
14
|
+
* ```json
|
|
15
|
+
* {"1":"response #2"
|
|
16
|
+
* ,"0":"response #1"
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function getBatchStreamFormatter() {
|
|
21
|
+
let first = true;
|
|
22
|
+
function format(index: number, string: string) {
|
|
23
|
+
const prefix = first ? '{' : ',';
|
|
24
|
+
first = false;
|
|
25
|
+
return `${prefix}"${index}":${string}\n`;
|
|
26
|
+
}
|
|
27
|
+
format.end = () => '}';
|
|
28
|
+
return format;
|
|
29
|
+
}
|