@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.215 → 11.0.0-alpha-tmp-export-from-main.211
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-core-unstable-do-not-import-this-please.d.ts +9 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
- package/dist/@trpc-server/http.d.ts +1 -1
- package/dist/@trpc-server/http.d.ts.map +1 -1
- package/dist/@trpc-server.d.ts +3 -3
- package/dist/@trpc-server.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.js +7 -12
- package/dist/adapters/aws-lambda/index.mjs +3 -8
- package/dist/adapters/aws-lambda/utils.d.ts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +2 -8
- package/dist/adapters/express.mjs +2 -8
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/index.js +4 -12
- package/dist/adapters/fastify/index.mjs +2 -10
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
- package/dist/adapters/fetch/index.js +4 -10
- package/dist/adapters/fetch/index.mjs +2 -8
- package/dist/adapters/fetch/types.d.ts +1 -1
- package/dist/adapters/next.d.ts +1 -1
- package/dist/adapters/next.js +5 -11
- package/dist/adapters/next.mjs +3 -9
- package/dist/adapters/node-http/content-type/json/index.js +3 -5
- package/dist/adapters/node-http/content-type/json/index.mjs +1 -3
- package/dist/adapters/node-http/index.js +2 -8
- package/dist/adapters/node-http/index.mjs +2 -8
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/types.d.ts +2 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -1
- package/dist/adapters/standalone.js +2 -8
- package/dist/adapters/standalone.mjs +2 -8
- package/dist/adapters/ws.d.ts +1 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +26 -31
- package/dist/adapters/ws.mjs +1 -6
- package/dist/http.d.ts +6 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +21 -12
- package/dist/http.mjs +1 -7
- package/dist/index.js +41 -15
- package/dist/index.mjs +1 -5
- package/dist/{nodeHTTPRequestHandler-257a3b5f.mjs → nodeHTTPRequestHandler-2d5c8791.mjs} +2 -4
- package/dist/{nodeHTTPRequestHandler-f4b7e374.js → nodeHTTPRequestHandler-55f05150.js} +4 -6
- package/dist/{nodeHTTPRequestHandler-29178135.js → nodeHTTPRequestHandler-7691fc79.js} +1 -3
- package/dist/observable.d.ts +2 -2
- package/dist/observable.d.ts.map +1 -1
- package/dist/observable.js +25 -9
- package/dist/observable.mjs +1 -3
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +13 -5
- package/dist/rpc.mjs +1 -2
- package/dist/shared.js +9 -4
- package/dist/shared.mjs +1 -2
- package/package.json +125 -53
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
- package/src/@trpc-server/http.ts +1 -2
- package/src/@trpc-server.ts +3 -3
- package/src/adapters/aws-lambda/index.ts +1 -1
- package/src/adapters/aws-lambda/utils.ts +1 -1
- package/src/adapters/express.ts +2 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/next.ts +1 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
- package/src/adapters/node-http/types.ts +3 -2
- package/src/adapters/standalone.ts +1 -1
- package/src/adapters/ws.ts +10 -9
- package/src/http.ts +6 -6
- package/src/observable.ts +2 -2
- package/src/rpc.ts +2 -2
- package/dist/TRPCError-10da405a.js +0 -61
- package/dist/TRPCError-14edcf88.mjs +0 -63
- package/dist/TRPCError-e2c8eb77.js +0 -67
- package/dist/batchStreamFormatter-1971db27.js +0 -32
- package/dist/batchStreamFormatter-378277dc.mjs +0 -30
- package/dist/batchStreamFormatter-4375dc8b.js +0 -31
- package/dist/bundle-analysis.json +0 -767
- package/dist/contentType-2ed02bef.mjs +0 -52
- package/dist/contentType-3a829011.js +0 -54
- package/dist/contentType-e4a2373e.js +0 -59
- package/dist/createProxy-0306dcaa.mjs +0 -121
- package/dist/createProxy-7e413449.js +0 -127
- package/dist/createProxy-dce0c414.js +0 -116
- package/dist/initTRPC-2cef03ab.js +0 -384
- package/dist/initTRPC-38faa18f.js +0 -371
- package/dist/initTRPC-fa1b3d57.mjs +0 -376
- package/dist/observable-2a5a96d5.js +0 -125
- package/dist/observable-62674916.js +0 -125
- package/dist/observable-6d025a37.mjs +0 -121
- package/dist/operators-0cc4956a.js +0 -99
- package/dist/operators-b08617cb.js +0 -103
- package/dist/operators-d0c3e794.mjs +0 -99
- package/dist/parseTRPCMessage-6e6c204e.js +0 -65
- package/dist/parseTRPCMessage-8eb0bbe9.mjs +0 -62
- package/dist/parseTRPCMessage-ebdfe3ca.js +0 -67
- package/dist/resolveHTTPResponse-833ca2b8.js +0 -265
- package/dist/resolveHTTPResponse-9322334c.mjs +0 -291
- package/dist/resolveHTTPResponse-d64c48e1.js +0 -293
- package/dist/rootConfig-3371c473.js +0 -89
- package/dist/rootConfig-571c9267.js +0 -94
- package/dist/rootConfig-6b04a6b8.mjs +0 -81
- package/dist/router-3344b52a.js +0 -262
- package/dist/router-919c37eb.js +0 -259
- package/dist/router-d6789e4b.mjs +0 -252
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.d.ts +0 -35
- package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.js +0 -51
- package/dist/unstable-core-do-not-import/index.mjs +0 -11
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/observable/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/observable.d.ts +0 -13
- package/dist/unstable-core-do-not-import/observable/observable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/operators.d.ts +0 -8
- package/dist/unstable-core-do-not-import/observable/operators.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/types.d.ts +0 -26
- package/dist/unstable-core-do-not-import/observable/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
- package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/router.d.ts +0 -85
- package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/types.d.ts +0 -98
- package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +0 -31
- package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
- package/src/unstable-core-do-not-import/createProxy.ts +0 -59
- package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
- package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
- package/src/unstable-core-do-not-import/http/index.ts +0 -23
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
- package/src/unstable-core-do-not-import/http/types.ts +0 -111
- package/src/unstable-core-do-not-import/index.ts +0 -108
- package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
- package/src/unstable-core-do-not-import/middleware.ts +0 -233
- package/src/unstable-core-do-not-import/observable/index.ts +0 -10
- package/src/unstable-core-do-not-import/observable/observable.ts +0 -155
- package/src/unstable-core-do-not-import/observable/operators.ts +0 -119
- package/src/unstable-core-do-not-import/observable/types.ts +0 -76
- package/src/unstable-core-do-not-import/parser.ts +0 -94
- package/src/unstable-core-do-not-import/procedure.ts +0 -108
- package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
- package/src/unstable-core-do-not-import/router.ts +0 -370
- package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
- package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
- package/src/unstable-core-do-not-import/serialize.ts +0 -122
- package/src/unstable-core-do-not-import/transformer.ts +0 -202
- package/src/unstable-core-do-not-import/types.ts +0 -151
- package/src/unstable-core-do-not-import/utils.ts +0 -66
- package/unstable-core-do-not-import/index.d.ts +0 -1
- package/unstable-core-do-not-import/index.js +0 -1
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var createProxy = require('./createProxy-7e413449.js');
|
|
4
|
-
var TRPCError = require('./TRPCError-e2c8eb77.js');
|
|
5
|
-
var router = require('./router-3344b52a.js');
|
|
6
|
-
var contentType = require('./contentType-3a829011.js');
|
|
7
|
-
|
|
8
|
-
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
9
|
-
GET: 'query',
|
|
10
|
-
POST: 'mutation'
|
|
11
|
-
};
|
|
12
|
-
const fallbackContentTypeHandler = {
|
|
13
|
-
getInputs: contentType.getJsonContentTypeInputs
|
|
14
|
-
};
|
|
15
|
-
function initResponse(initOpts) {
|
|
16
|
-
const { ctx , paths , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
|
|
17
|
-
let status = untransformedJSON ? createProxy.getHTTPStatusCode(untransformedJSON) : 200;
|
|
18
|
-
const headers = {
|
|
19
|
-
'Content-Type': 'application/json'
|
|
20
|
-
};
|
|
21
|
-
const eagerGeneration = !untransformedJSON;
|
|
22
|
-
const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
|
|
23
|
-
untransformedJSON
|
|
24
|
-
];
|
|
25
|
-
const meta = responseMeta?.({
|
|
26
|
-
ctx,
|
|
27
|
-
paths,
|
|
28
|
-
type,
|
|
29
|
-
data,
|
|
30
|
-
errors,
|
|
31
|
-
eagerGeneration
|
|
32
|
-
}) ?? {};
|
|
33
|
-
for (const [key, value] of Object.entries(meta.headers ?? {})){
|
|
34
|
-
headers[key] = value;
|
|
35
|
-
}
|
|
36
|
-
if (meta.status) {
|
|
37
|
-
status = meta.status;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
status,
|
|
41
|
-
headers
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async function inputToProcedureCall(procedureOpts) {
|
|
45
|
-
const { opts , ctx , type , input , path } = procedureOpts;
|
|
46
|
-
try {
|
|
47
|
-
const data = await router.callProcedure({
|
|
48
|
-
procedures: opts.router._def.procedures,
|
|
49
|
-
path,
|
|
50
|
-
getRawInput: async ()=>input,
|
|
51
|
-
ctx,
|
|
52
|
-
type
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
result: {
|
|
56
|
-
data
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
} catch (cause) {
|
|
60
|
-
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
61
|
-
opts.onError?.({
|
|
62
|
-
error,
|
|
63
|
-
path,
|
|
64
|
-
input,
|
|
65
|
-
ctx,
|
|
66
|
-
type: type,
|
|
67
|
-
req: opts.req
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
error: createProxy.getErrorShape({
|
|
71
|
-
config: opts.router._def._config,
|
|
72
|
-
error,
|
|
73
|
-
type,
|
|
74
|
-
path,
|
|
75
|
-
input,
|
|
76
|
-
ctx
|
|
77
|
-
})
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function caughtErrorToData(cause, errorOpts) {
|
|
82
|
-
const { router: router$1 , req , onError } = errorOpts.opts;
|
|
83
|
-
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
84
|
-
onError?.({
|
|
85
|
-
error,
|
|
86
|
-
path: errorOpts.path,
|
|
87
|
-
input: errorOpts.input,
|
|
88
|
-
ctx: errorOpts.ctx,
|
|
89
|
-
type: errorOpts.type,
|
|
90
|
-
req
|
|
91
|
-
});
|
|
92
|
-
const untransformedJSON = {
|
|
93
|
-
error: createProxy.getErrorShape({
|
|
94
|
-
config: router$1._def._config,
|
|
95
|
-
error,
|
|
96
|
-
type: errorOpts.type,
|
|
97
|
-
path: errorOpts.path,
|
|
98
|
-
input: errorOpts.input,
|
|
99
|
-
ctx: errorOpts.ctx
|
|
100
|
-
})
|
|
101
|
-
};
|
|
102
|
-
const transformedJSON = router.transformTRPCResponse(router$1._def._config, untransformedJSON);
|
|
103
|
-
const body = JSON.stringify(transformedJSON);
|
|
104
|
-
return {
|
|
105
|
-
error,
|
|
106
|
-
untransformedJSON,
|
|
107
|
-
body
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
// implementation
|
|
111
|
-
async function resolveHTTPResponse(opts) {
|
|
112
|
-
const { router: router$1 , req , unstable_onHead , unstable_onChunk } = opts;
|
|
113
|
-
if (req.method === 'HEAD') {
|
|
114
|
-
// can be used for lambda warmup
|
|
115
|
-
const headResponse = {
|
|
116
|
-
status: 204
|
|
117
|
-
};
|
|
118
|
-
unstable_onHead?.(headResponse, false);
|
|
119
|
-
unstable_onChunk?.([
|
|
120
|
-
-1,
|
|
121
|
-
''
|
|
122
|
-
]);
|
|
123
|
-
return headResponse;
|
|
124
|
-
}
|
|
125
|
-
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
126
|
-
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
127
|
-
const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
|
|
128
|
-
let ctx = undefined;
|
|
129
|
-
let paths;
|
|
130
|
-
const isBatchCall = !!req.query.get('batch');
|
|
131
|
-
const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
|
|
132
|
-
try {
|
|
133
|
-
if (opts.error) {
|
|
134
|
-
throw opts.error;
|
|
135
|
-
}
|
|
136
|
-
if (isBatchCall && !batchingEnabled) {
|
|
137
|
-
throw new Error(`Batching is not enabled on the server`);
|
|
138
|
-
}
|
|
139
|
-
/* istanbul ignore if -- @preserve */ if (type === 'subscription') {
|
|
140
|
-
throw new TRPCError.TRPCError({
|
|
141
|
-
message: 'Subscriptions should use wsLink',
|
|
142
|
-
code: 'METHOD_NOT_SUPPORTED'
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (type === 'unknown') {
|
|
146
|
-
throw new TRPCError.TRPCError({
|
|
147
|
-
message: `Unexpected request method ${req.method}`,
|
|
148
|
-
code: 'METHOD_NOT_SUPPORTED'
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
const inputs = await contentTypeHandler.getInputs({
|
|
152
|
-
isBatchCall,
|
|
153
|
-
req,
|
|
154
|
-
router: router$1,
|
|
155
|
-
preprocessedBody: opts.preprocessedBody ?? false
|
|
156
|
-
});
|
|
157
|
-
paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
|
|
158
|
-
opts.path
|
|
159
|
-
];
|
|
160
|
-
const info = {
|
|
161
|
-
isBatchCall,
|
|
162
|
-
calls: paths.map((path, idx)=>({
|
|
163
|
-
path,
|
|
164
|
-
type,
|
|
165
|
-
input: inputs[idx] ?? undefined
|
|
166
|
-
}))
|
|
167
|
-
};
|
|
168
|
-
ctx = await opts.createContext({
|
|
169
|
-
info
|
|
170
|
-
});
|
|
171
|
-
const promises = paths.map((path, index)=>inputToProcedureCall({
|
|
172
|
-
opts,
|
|
173
|
-
ctx,
|
|
174
|
-
type,
|
|
175
|
-
input: inputs[index],
|
|
176
|
-
path
|
|
177
|
-
}));
|
|
178
|
-
if (!isStreamCall) {
|
|
179
|
-
/**
|
|
180
|
-
* Non-streaming response:
|
|
181
|
-
* - await all responses in parallel, blocking on the slowest one
|
|
182
|
-
* - create headers with known response body
|
|
183
|
-
* - return a complete HTTPResponse
|
|
184
|
-
*/ const untransformedJSON = await Promise.all(promises);
|
|
185
|
-
const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
|
|
186
|
-
response.error
|
|
187
|
-
] : []);
|
|
188
|
-
const headResponse1 = initResponse({
|
|
189
|
-
ctx,
|
|
190
|
-
paths,
|
|
191
|
-
type,
|
|
192
|
-
responseMeta: opts.responseMeta,
|
|
193
|
-
untransformedJSON,
|
|
194
|
-
errors
|
|
195
|
-
});
|
|
196
|
-
unstable_onHead?.(headResponse1, false);
|
|
197
|
-
// return body stuff
|
|
198
|
-
const result = isBatchCall ? untransformedJSON : untransformedJSON[0]; // eslint-disable-line @typescript-eslint/no-non-null-assertion -- `untransformedJSON` should be the length of `paths` which should be at least 1 otherwise there wouldn't be a request at all
|
|
199
|
-
const transformedJSON = router.transformTRPCResponse(router$1._def._config, result);
|
|
200
|
-
const body = JSON.stringify(transformedJSON);
|
|
201
|
-
unstable_onChunk?.([
|
|
202
|
-
-1,
|
|
203
|
-
body
|
|
204
|
-
]);
|
|
205
|
-
return {
|
|
206
|
-
status: headResponse1.status,
|
|
207
|
-
headers: headResponse1.headers,
|
|
208
|
-
body
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Streaming response:
|
|
213
|
-
* - block on none, call `onChunk` as soon as each response is ready
|
|
214
|
-
* - create headers with minimal data (cannot know the response body in advance)
|
|
215
|
-
* - return void
|
|
216
|
-
*/ const headResponse2 = initResponse({
|
|
217
|
-
ctx,
|
|
218
|
-
paths,
|
|
219
|
-
type,
|
|
220
|
-
responseMeta: opts.responseMeta
|
|
221
|
-
});
|
|
222
|
-
unstable_onHead(headResponse2, true);
|
|
223
|
-
const indexedPromises = new Map(promises.map((promise, index)=>[
|
|
224
|
-
index,
|
|
225
|
-
promise.then((r)=>[
|
|
226
|
-
index,
|
|
227
|
-
r
|
|
228
|
-
])
|
|
229
|
-
]));
|
|
230
|
-
for (const _ of paths){
|
|
231
|
-
const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
|
|
232
|
-
indexedPromises.delete(index);
|
|
233
|
-
try {
|
|
234
|
-
const transformedJSON1 = router.transformTRPCResponse(router$1._def._config, untransformedJSON1);
|
|
235
|
-
const body1 = JSON.stringify(transformedJSON1);
|
|
236
|
-
unstable_onChunk([
|
|
237
|
-
index,
|
|
238
|
-
body1
|
|
239
|
-
]);
|
|
240
|
-
} catch (cause) {
|
|
241
|
-
const path = paths[index];
|
|
242
|
-
const input = inputs[index];
|
|
243
|
-
const { body: body2 } = caughtErrorToData(cause, {
|
|
244
|
-
opts,
|
|
245
|
-
ctx,
|
|
246
|
-
type,
|
|
247
|
-
path,
|
|
248
|
-
input
|
|
249
|
-
});
|
|
250
|
-
unstable_onChunk([
|
|
251
|
-
index,
|
|
252
|
-
body2
|
|
253
|
-
]);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return;
|
|
257
|
-
} catch (cause1) {
|
|
258
|
-
// we get here if
|
|
259
|
-
// - batching is called when it's not enabled
|
|
260
|
-
// - `createContext()` throws
|
|
261
|
-
// - `router._def._config.transformer.output.serialize()` throws
|
|
262
|
-
// - post body is too large
|
|
263
|
-
// - input deserialization fails
|
|
264
|
-
// - `errorFormatter` return value is malformed
|
|
265
|
-
const { error , untransformedJSON: untransformedJSON2 , body: body3 } = caughtErrorToData(cause1, {
|
|
266
|
-
opts,
|
|
267
|
-
ctx,
|
|
268
|
-
type
|
|
269
|
-
});
|
|
270
|
-
const headResponse3 = initResponse({
|
|
271
|
-
ctx,
|
|
272
|
-
paths,
|
|
273
|
-
type,
|
|
274
|
-
responseMeta: opts.responseMeta,
|
|
275
|
-
untransformedJSON: untransformedJSON2,
|
|
276
|
-
errors: [
|
|
277
|
-
error
|
|
278
|
-
]
|
|
279
|
-
});
|
|
280
|
-
unstable_onHead?.(headResponse3, false);
|
|
281
|
-
unstable_onChunk?.([
|
|
282
|
-
-1,
|
|
283
|
-
body3
|
|
284
|
-
]);
|
|
285
|
-
return {
|
|
286
|
-
status: headResponse3.status,
|
|
287
|
-
headers: headResponse3.headers,
|
|
288
|
-
body: body3
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
exports.resolveHTTPResponse = resolveHTTPResponse;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/ function invert(obj) {
|
|
6
|
-
const newObj = Object.create(null);
|
|
7
|
-
for(const key in obj){
|
|
8
|
-
const v = obj[key];
|
|
9
|
-
newObj[v] = key;
|
|
10
|
-
}
|
|
11
|
-
return newObj;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
15
|
-
* @internal
|
|
16
|
-
*/ function mergeWithoutOverrides(obj1, ...objs) {
|
|
17
|
-
const newObj = Object.assign(Object.create(null), obj1);
|
|
18
|
-
for (const overrides of objs){
|
|
19
|
-
for(const key in overrides){
|
|
20
|
-
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
21
|
-
throw new Error(`Duplicate key ${key}`);
|
|
22
|
-
}
|
|
23
|
-
newObj[key] = overrides[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return newObj;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Check that value is object
|
|
30
|
-
* @internal
|
|
31
|
-
*/ function isObject(value) {
|
|
32
|
-
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Create an object without inheriting anything from `Object.prototype`
|
|
36
|
-
* @internal
|
|
37
|
-
*/ function omitPrototype(obj) {
|
|
38
|
-
return Object.assign(Object.create(null), obj);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @internal
|
|
42
|
-
*/ function identity(x) {
|
|
43
|
-
return x;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// reference: https://www.jsonrpc.org/specification
|
|
47
|
-
/**
|
|
48
|
-
* JSON-RPC 2.0 Error codes
|
|
49
|
-
*
|
|
50
|
-
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
51
|
-
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
52
|
-
*/ const TRPC_ERROR_CODES_BY_KEY = {
|
|
53
|
-
/**
|
|
54
|
-
* Invalid JSON was received by the server.
|
|
55
|
-
* An error occurred on the server while parsing the JSON text.
|
|
56
|
-
*/ PARSE_ERROR: -32700,
|
|
57
|
-
/**
|
|
58
|
-
* The JSON sent is not a valid Request object.
|
|
59
|
-
*/ BAD_REQUEST: -32600,
|
|
60
|
-
// Internal JSON-RPC error
|
|
61
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
62
|
-
NOT_IMPLEMENTED: -32603,
|
|
63
|
-
// Implementation specific errors
|
|
64
|
-
UNAUTHORIZED: -32001,
|
|
65
|
-
FORBIDDEN: -32003,
|
|
66
|
-
NOT_FOUND: -32004,
|
|
67
|
-
METHOD_NOT_SUPPORTED: -32005,
|
|
68
|
-
TIMEOUT: -32008,
|
|
69
|
-
CONFLICT: -32009,
|
|
70
|
-
PRECONDITION_FAILED: -32012,
|
|
71
|
-
PAYLOAD_TOO_LARGE: -32013,
|
|
72
|
-
UNPROCESSABLE_CONTENT: -32022,
|
|
73
|
-
TOO_MANY_REQUESTS: -32029,
|
|
74
|
-
CLIENT_CLOSED_REQUEST: -32099
|
|
75
|
-
};
|
|
76
|
-
const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* The default check to see if we're in a server
|
|
80
|
-
*/ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
|
|
81
|
-
globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
82
|
-
|
|
83
|
-
exports.TRPC_ERROR_CODES_BY_KEY = TRPC_ERROR_CODES_BY_KEY;
|
|
84
|
-
exports.TRPC_ERROR_CODES_BY_NUMBER = TRPC_ERROR_CODES_BY_NUMBER;
|
|
85
|
-
exports.identity = identity;
|
|
86
|
-
exports.isObject = isObject;
|
|
87
|
-
exports.isServerDefault = isServerDefault;
|
|
88
|
-
exports.mergeWithoutOverrides = mergeWithoutOverrides;
|
|
89
|
-
exports.omitPrototype = omitPrototype;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
function invert(obj) {
|
|
5
|
-
const newObj = Object.create(null);
|
|
6
|
-
for (const key in obj) {
|
|
7
|
-
const v = obj[key];
|
|
8
|
-
newObj[v] = key;
|
|
9
|
-
}
|
|
10
|
-
return newObj;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
function mergeWithoutOverrides(obj1, ...objs) {
|
|
17
|
-
const newObj = Object.assign(Object.create(null), obj1);
|
|
18
|
-
for (const overrides of objs) {
|
|
19
|
-
for (const key in overrides) {
|
|
20
|
-
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
21
|
-
throw new Error(`Duplicate key ${key}`);
|
|
22
|
-
}
|
|
23
|
-
newObj[key] = overrides[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return newObj;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Check that value is object
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
function isObject(value) {
|
|
33
|
-
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Create an object without inheriting anything from `Object.prototype`
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
function omitPrototype(obj) {
|
|
40
|
-
return Object.assign(Object.create(null), obj);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
function identity(x) {
|
|
46
|
-
return x;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// reference: https://www.jsonrpc.org/specification
|
|
50
|
-
/**
|
|
51
|
-
* JSON-RPC 2.0 Error codes
|
|
52
|
-
*
|
|
53
|
-
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
54
|
-
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
55
|
-
*/
|
|
56
|
-
const TRPC_ERROR_CODES_BY_KEY = {
|
|
57
|
-
/**
|
|
58
|
-
* Invalid JSON was received by the server.
|
|
59
|
-
* An error occurred on the server while parsing the JSON text.
|
|
60
|
-
*/
|
|
61
|
-
PARSE_ERROR: -32700,
|
|
62
|
-
/**
|
|
63
|
-
* The JSON sent is not a valid Request object.
|
|
64
|
-
*/
|
|
65
|
-
BAD_REQUEST: -32600, // 400
|
|
66
|
-
// Internal JSON-RPC error
|
|
67
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
68
|
-
NOT_IMPLEMENTED: -32603,
|
|
69
|
-
// Implementation specific errors
|
|
70
|
-
UNAUTHORIZED: -32001, // 401
|
|
71
|
-
FORBIDDEN: -32003, // 403
|
|
72
|
-
NOT_FOUND: -32004, // 404
|
|
73
|
-
METHOD_NOT_SUPPORTED: -32005, // 405
|
|
74
|
-
TIMEOUT: -32008, // 408
|
|
75
|
-
CONFLICT: -32009, // 409
|
|
76
|
-
PRECONDITION_FAILED: -32012, // 412
|
|
77
|
-
PAYLOAD_TOO_LARGE: -32013, // 413
|
|
78
|
-
UNPROCESSABLE_CONTENT: -32022, // 422
|
|
79
|
-
TOO_MANY_REQUESTS: -32029, // 429
|
|
80
|
-
CLIENT_CLOSED_REQUEST: -32099, // 499
|
|
81
|
-
};
|
|
82
|
-
const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The default check to see if we're in a server
|
|
86
|
-
*/
|
|
87
|
-
const isServerDefault = typeof window === 'undefined' ||
|
|
88
|
-
'Deno' in window ||
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
90
|
-
globalThis.process?.env?.['NODE_ENV'] === 'test' ||
|
|
91
|
-
!!globalThis.process?.env?.['JEST_WORKER_ID'] ||
|
|
92
|
-
!!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
93
|
-
|
|
94
|
-
export { TRPC_ERROR_CODES_BY_NUMBER as T, TRPC_ERROR_CODES_BY_KEY as a, identity as b, isServerDefault as c, isObject as i, mergeWithoutOverrides as m, omitPrototype as o };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/ function invert(obj) {
|
|
4
|
-
const newObj = Object.create(null);
|
|
5
|
-
for(const key in obj){
|
|
6
|
-
const v = obj[key];
|
|
7
|
-
newObj[v] = key;
|
|
8
|
-
}
|
|
9
|
-
return newObj;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
13
|
-
* @internal
|
|
14
|
-
*/ function mergeWithoutOverrides(obj1, ...objs) {
|
|
15
|
-
const newObj = Object.assign(Object.create(null), obj1);
|
|
16
|
-
for (const overrides of objs){
|
|
17
|
-
for(const key in overrides){
|
|
18
|
-
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
19
|
-
throw new Error(`Duplicate key ${key}`);
|
|
20
|
-
}
|
|
21
|
-
newObj[key] = overrides[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return newObj;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Check that value is object
|
|
28
|
-
* @internal
|
|
29
|
-
*/ function isObject(value) {
|
|
30
|
-
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create an object without inheriting anything from `Object.prototype`
|
|
34
|
-
* @internal
|
|
35
|
-
*/ function omitPrototype(obj) {
|
|
36
|
-
return Object.assign(Object.create(null), obj);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @internal
|
|
40
|
-
*/ function identity(x) {
|
|
41
|
-
return x;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// reference: https://www.jsonrpc.org/specification
|
|
45
|
-
/**
|
|
46
|
-
* JSON-RPC 2.0 Error codes
|
|
47
|
-
*
|
|
48
|
-
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
49
|
-
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
50
|
-
*/ const TRPC_ERROR_CODES_BY_KEY = {
|
|
51
|
-
/**
|
|
52
|
-
* Invalid JSON was received by the server.
|
|
53
|
-
* An error occurred on the server while parsing the JSON text.
|
|
54
|
-
*/ PARSE_ERROR: -32700,
|
|
55
|
-
/**
|
|
56
|
-
* The JSON sent is not a valid Request object.
|
|
57
|
-
*/ BAD_REQUEST: -32600,
|
|
58
|
-
// Internal JSON-RPC error
|
|
59
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
60
|
-
NOT_IMPLEMENTED: -32603,
|
|
61
|
-
// Implementation specific errors
|
|
62
|
-
UNAUTHORIZED: -32001,
|
|
63
|
-
FORBIDDEN: -32003,
|
|
64
|
-
NOT_FOUND: -32004,
|
|
65
|
-
METHOD_NOT_SUPPORTED: -32005,
|
|
66
|
-
TIMEOUT: -32008,
|
|
67
|
-
CONFLICT: -32009,
|
|
68
|
-
PRECONDITION_FAILED: -32012,
|
|
69
|
-
PAYLOAD_TOO_LARGE: -32013,
|
|
70
|
-
UNPROCESSABLE_CONTENT: -32022,
|
|
71
|
-
TOO_MANY_REQUESTS: -32029,
|
|
72
|
-
CLIENT_CLOSED_REQUEST: -32099
|
|
73
|
-
};
|
|
74
|
-
const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* The default check to see if we're in a server
|
|
78
|
-
*/ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
|
|
79
|
-
globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
80
|
-
|
|
81
|
-
export { TRPC_ERROR_CODES_BY_NUMBER as T, TRPC_ERROR_CODES_BY_KEY as a, identity as b, isServerDefault as c, isObject as i, mergeWithoutOverrides as m, omitPrototype as o };
|