@trpc/server 11.0.0-next-beta.216 → 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
package/dist/rpc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from './@trpc/server/rpc';
|
|
2
2
|
//# sourceMappingURL=rpc.d.ts.map
|
package/dist/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
package/dist/rpc.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var codes = require('./unstable-core-do-not-import/rpc/codes.js');
|
|
4
|
+
var parseTRPCMessage = require('./unstable-core-do-not-import/rpc/parseTRPCMessage.js');
|
|
5
|
+
require('./unstable-core-do-not-import/rootConfig.js');
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
get: function () { return rpc[k]; }
|
|
11
|
-
});
|
|
12
|
-
});
|
|
9
|
+
exports.TRPC_ERROR_CODES_BY_KEY = codes.TRPC_ERROR_CODES_BY_KEY;
|
|
10
|
+
exports.TRPC_ERROR_CODES_BY_NUMBER = codes.TRPC_ERROR_CODES_BY_NUMBER;
|
|
11
|
+
exports.parseTRPCMessage = parseTRPCMessage.parseTRPCMessage;
|
package/dist/rpc.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { TRPC_ERROR_CODES_BY_KEY, TRPC_ERROR_CODES_BY_NUMBER } from './unstable-core-do-not-import/rpc/codes.mjs';
|
|
2
|
+
export { parseTRPCMessage } from './unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
|
|
3
|
+
import './unstable-core-do-not-import/rootConfig.mjs';
|
package/dist/shared.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ getErrorShape,
|
|
|
22
22
|
/**
|
|
23
23
|
* @deprecated `import { createTRPCFlatProxy } from '@trpc/server'` instead
|
|
24
24
|
*/
|
|
25
|
-
createTRPCFlatProxy as createFlatProxy, } from './@trpc
|
|
25
|
+
createTRPCFlatProxy as createFlatProxy, } from './@trpc/server';
|
|
26
26
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
|
|
4
|
+
var createProxy = require('./unstable-core-do-not-import/createProxy.js');
|
|
5
|
+
require('./unstable-core-do-not-import/rootConfig.js');
|
|
6
|
+
require('./unstable-core-do-not-import/rpc/codes.js');
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get: function () { return core.createFlatProxy; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "getErrorShape", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return core.getErrorShape; }
|
|
14
|
-
});
|
|
10
|
+
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
11
|
+
exports.createFlatProxy = createProxy.createFlatProxy;
|
package/dist/shared.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
2
|
+
export { createFlatProxy } from './unstable-core-do-not-import/createProxy.mjs';
|
|
3
|
+
import './unstable-core-do-not-import/rootConfig.mjs';
|
|
4
|
+
import './unstable-core-do-not-import/rpc/codes.mjs';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AnyRootConfig } from './rootConfig';
|
|
2
|
+
import type { AnyRouter } from './router';
|
|
3
|
+
export type TRPCInferrable = AnyRouter | AnyRootConfig;
|
|
4
|
+
export type inferConfig<TInferrable extends TRPCInferrable> = TInferrable extends AnyRouter ? TInferrable['_def']['_config'] : TInferrable;
|
|
5
|
+
export type inferErrorShape<TInferrable extends TRPCInferrable> = inferConfig<TInferrable>['$types']['errorShape'];
|
|
6
|
+
//# sourceMappingURL=TRPCInferrable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TRPCInferrable.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/TRPCInferrable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,aAAa,CAAC;AACvD,MAAM,MAAM,WAAW,CAAC,WAAW,SAAS,cAAc,IACxD,WAAW,SAAS,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC;AAE/E,MAAM,MAAM,eAAe,CAAC,WAAW,SAAS,cAAc,IAC5D,WAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface ProxyCallbackOptions {
|
|
2
|
+
path: string[];
|
|
3
|
+
args: unknown[];
|
|
4
|
+
}
|
|
5
|
+
type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a proxy that calls the callback with the path and arguments
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const createRecursiveProxy: (callback: ProxyCallback) => unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const createFlatProxy: <TFaux>(callback: (path: string & keyof TFaux) => any) => TFaux;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=createProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProxy.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/createProxy.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;AA4B7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAAc,aAAa,YAC5B,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,eAAe,oDACgB,GAAG,UAY9C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const noop = ()=>{
|
|
4
|
+
// noop
|
|
5
|
+
};
|
|
6
|
+
function createInnerProxy(callback, path) {
|
|
7
|
+
const proxy = new Proxy(noop, {
|
|
8
|
+
get (_obj, key) {
|
|
9
|
+
if (typeof key !== 'string' || key === 'then') {
|
|
10
|
+
// special case for if the proxy is accidentally treated
|
|
11
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return createInnerProxy(callback, [
|
|
15
|
+
...path,
|
|
16
|
+
key
|
|
17
|
+
]);
|
|
18
|
+
},
|
|
19
|
+
apply (_1, _2, args) {
|
|
20
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
21
|
+
return callback({
|
|
22
|
+
args: isApply ? args.length >= 2 ? args[1] : [] : args,
|
|
23
|
+
path: isApply ? path.slice(0, -1) : path
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return proxy;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a proxy that calls the callback with the path and arguments
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []);
|
|
34
|
+
/**
|
|
35
|
+
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/ const createFlatProxy = (callback)=>{
|
|
39
|
+
return new Proxy(noop, {
|
|
40
|
+
get (_obj, name) {
|
|
41
|
+
if (typeof name !== 'string' || name === 'then') {
|
|
42
|
+
// special case for if the proxy is accidentally treated
|
|
43
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return callback(name);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.createFlatProxy = createFlatProxy;
|
|
52
|
+
exports.createRecursiveProxy = createRecursiveProxy;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const noop = ()=>{
|
|
2
|
+
// noop
|
|
3
|
+
};
|
|
4
|
+
function createInnerProxy(callback, path) {
|
|
5
|
+
const proxy = new Proxy(noop, {
|
|
6
|
+
get (_obj, key) {
|
|
7
|
+
if (typeof key !== 'string' || key === 'then') {
|
|
8
|
+
// special case for if the proxy is accidentally treated
|
|
9
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return createInnerProxy(callback, [
|
|
13
|
+
...path,
|
|
14
|
+
key
|
|
15
|
+
]);
|
|
16
|
+
},
|
|
17
|
+
apply (_1, _2, args) {
|
|
18
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
19
|
+
return callback({
|
|
20
|
+
args: isApply ? args.length >= 2 ? args[1] : [] : args,
|
|
21
|
+
path: isApply ? path.slice(0, -1) : path
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return proxy;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a proxy that calls the callback with the path and arguments
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []);
|
|
32
|
+
/**
|
|
33
|
+
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/ const createFlatProxy = (callback)=>{
|
|
37
|
+
return new Proxy(noop, {
|
|
38
|
+
get (_obj, name) {
|
|
39
|
+
if (typeof name !== 'string' || name === 'then') {
|
|
40
|
+
// special case for if the proxy is accidentally treated
|
|
41
|
+
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return callback(name);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { createFlatProxy, createRecursiveProxy };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
|
|
2
|
+
export declare function getCauseFromUnknown(cause: unknown): Error | undefined;
|
|
3
|
+
export declare function getTRPCErrorFromUnknown(cause: unknown): TRPCError;
|
|
4
|
+
export declare class TRPCError extends Error {
|
|
5
|
+
readonly cause?: Error;
|
|
6
|
+
readonly code: "INTERNAL_SERVER_ERROR" | "PARSE_ERROR" | "BAD_REQUEST" | "NOT_IMPLEMENTED" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
|
|
7
|
+
constructor(opts: {
|
|
8
|
+
message?: string;
|
|
9
|
+
code: TRPC_ERROR_CODE_KEY;
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=TRPCError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TRPCError.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/TRPCError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAMxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAyBrE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAoBjE;AAED,qBAAa,SAAU,SAAQ,KAAK;IAGlC,SAAyB,KAAK,CAAC,EAAE,KAAK,CAAC;IACvC,SAAgB,IAAI,qSAAC;gBAET,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,mBAAmB,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAgBF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('../utils.js');
|
|
4
|
+
|
|
5
|
+
class UnknownCauseError extends Error {
|
|
6
|
+
}
|
|
7
|
+
function getCauseFromUnknown(cause) {
|
|
8
|
+
if (cause instanceof Error) {
|
|
9
|
+
return cause;
|
|
10
|
+
}
|
|
11
|
+
const type = typeof cause;
|
|
12
|
+
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
// Primitive types just get wrapped in an error
|
|
16
|
+
if (type !== 'object') {
|
|
17
|
+
return new Error(String(cause));
|
|
18
|
+
}
|
|
19
|
+
// If it's an object, we'll create a synthetic error
|
|
20
|
+
if (utils.isObject(cause)) {
|
|
21
|
+
const err = new UnknownCauseError();
|
|
22
|
+
for(const key in cause){
|
|
23
|
+
err[key] = cause[key];
|
|
24
|
+
}
|
|
25
|
+
return err;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function getTRPCErrorFromUnknown(cause) {
|
|
30
|
+
if (cause instanceof TRPCError) {
|
|
31
|
+
return cause;
|
|
32
|
+
}
|
|
33
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
34
|
+
// https://github.com/trpc/trpc/pull/4848
|
|
35
|
+
return cause;
|
|
36
|
+
}
|
|
37
|
+
const trpcError = new TRPCError({
|
|
38
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
39
|
+
cause
|
|
40
|
+
});
|
|
41
|
+
// Inherit stack from error
|
|
42
|
+
if (cause instanceof Error && cause.stack) {
|
|
43
|
+
trpcError.stack = cause.stack;
|
|
44
|
+
}
|
|
45
|
+
return trpcError;
|
|
46
|
+
}
|
|
47
|
+
class TRPCError extends Error {
|
|
48
|
+
constructor(opts){
|
|
49
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
50
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
53
|
+
super(message, {
|
|
54
|
+
cause
|
|
55
|
+
});
|
|
56
|
+
this.code = opts.code;
|
|
57
|
+
this.name = 'TRPCError';
|
|
58
|
+
if (!this.cause) {
|
|
59
|
+
// < ES2022 / < Node 16.9.0 compatability
|
|
60
|
+
this.cause = cause;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.TRPCError = TRPCError;
|
|
66
|
+
exports.getCauseFromUnknown = getCauseFromUnknown;
|
|
67
|
+
exports.getTRPCErrorFromUnknown = getTRPCErrorFromUnknown;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isObject } from '../utils.mjs';
|
|
2
|
+
|
|
3
|
+
class UnknownCauseError extends Error {
|
|
4
|
+
}
|
|
5
|
+
function getCauseFromUnknown(cause) {
|
|
6
|
+
if (cause instanceof Error) {
|
|
7
|
+
return cause;
|
|
8
|
+
}
|
|
9
|
+
const type = typeof cause;
|
|
10
|
+
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
// Primitive types just get wrapped in an error
|
|
14
|
+
if (type !== 'object') {
|
|
15
|
+
return new Error(String(cause));
|
|
16
|
+
}
|
|
17
|
+
// If it's an object, we'll create a synthetic error
|
|
18
|
+
if (isObject(cause)) {
|
|
19
|
+
const err = new UnknownCauseError();
|
|
20
|
+
for(const key in cause){
|
|
21
|
+
err[key] = cause[key];
|
|
22
|
+
}
|
|
23
|
+
return err;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function getTRPCErrorFromUnknown(cause) {
|
|
28
|
+
if (cause instanceof TRPCError) {
|
|
29
|
+
return cause;
|
|
30
|
+
}
|
|
31
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
32
|
+
// https://github.com/trpc/trpc/pull/4848
|
|
33
|
+
return cause;
|
|
34
|
+
}
|
|
35
|
+
const trpcError = new TRPCError({
|
|
36
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
37
|
+
cause
|
|
38
|
+
});
|
|
39
|
+
// Inherit stack from error
|
|
40
|
+
if (cause instanceof Error && cause.stack) {
|
|
41
|
+
trpcError.stack = cause.stack;
|
|
42
|
+
}
|
|
43
|
+
return trpcError;
|
|
44
|
+
}
|
|
45
|
+
class TRPCError extends Error {
|
|
46
|
+
constructor(opts){
|
|
47
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
48
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
50
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
51
|
+
super(message, {
|
|
52
|
+
cause
|
|
53
|
+
});
|
|
54
|
+
this.code = opts.code;
|
|
55
|
+
this.name = 'TRPCError';
|
|
56
|
+
if (!this.cause) {
|
|
57
|
+
// < ES2022 / < Node 16.9.0 compatability
|
|
58
|
+
this.cause = cause;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { TRPCError, getCauseFromUnknown, getTRPCErrorFromUnknown };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ProcedureType } from '../procedure';
|
|
2
|
+
import type { TRPC_ERROR_CODE_KEY, TRPC_ERROR_CODE_NUMBER, TRPCErrorShape } from '../rpc';
|
|
3
|
+
import type { TRPCError } from './TRPCError';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape<number>> = (args: {
|
|
8
|
+
error: TRPCError;
|
|
9
|
+
type: ProcedureType | 'unknown';
|
|
10
|
+
path: string | undefined;
|
|
11
|
+
input: unknown;
|
|
12
|
+
ctx: TContext | undefined;
|
|
13
|
+
shape: DefaultErrorShape;
|
|
14
|
+
}) => TShape;
|
|
15
|
+
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<any, infer TShape> ? TShape : DefaultErrorShape;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type DefaultErrorData = {
|
|
20
|
+
code: TRPC_ERROR_CODE_KEY;
|
|
21
|
+
httpStatus: number;
|
|
22
|
+
path?: string;
|
|
23
|
+
stack?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export interface DefaultErrorShape extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, DefaultErrorData> {
|
|
29
|
+
message: string;
|
|
30
|
+
code: TRPC_ERROR_CODE_NUMBER;
|
|
31
|
+
}
|
|
32
|
+
export declare const defaultFormatter: ErrorFormatter<any, any>;
|
|
33
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,cAAc,CACxB,QAAQ,EACR,MAAM,SAAS,cAAc,CAAC,MAAM,CAAC,IACnC,CAAC,IAAI,EAAE;IACT,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAC;CAC1B,KAAK,MAAM,CAAC;AAEb,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,KAAK,SAAS,cAAc,CACnE,GAAG,EACH,MAAM,MAAM,CACb,GACG,MAAM,GACN,iBAAiB,CAAC;AACtB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBACf,SAAQ,cAAc,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAErD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProcedureType } from '../procedure';
|
|
2
|
+
import type { AnyRootConfig } from '../rootConfig';
|
|
3
|
+
import type { TRPCError } from './TRPCError';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
8
|
+
config: TConfig;
|
|
9
|
+
error: TRPCError;
|
|
10
|
+
type: ProcedureType | 'unknown';
|
|
11
|
+
path: string | undefined;
|
|
12
|
+
input: unknown;
|
|
13
|
+
ctx: TConfig['$types']['ctx'] | undefined;
|
|
14
|
+
}): TConfig['$types']['errorShape'];
|
|
15
|
+
//# sourceMappingURL=getErrorShape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorShape.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/getErrorShape.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,aAAa,EAAE,IAAI,EAAE;IACjE,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAkBlC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getHTTPStatusCode = require('../http/getHTTPStatusCode.js');
|
|
4
|
+
var codes = require('../rpc/codes.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/ function getErrorShape(opts) {
|
|
9
|
+
const { path , error , config } = opts;
|
|
10
|
+
const { code } = opts.error;
|
|
11
|
+
const shape = {
|
|
12
|
+
message: error.message,
|
|
13
|
+
code: codes.TRPC_ERROR_CODES_BY_KEY[code],
|
|
14
|
+
data: {
|
|
15
|
+
code,
|
|
16
|
+
httpStatus: getHTTPStatusCode.getHTTPStatusCodeFromError(error)
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
20
|
+
shape.data.stack = opts.error.stack;
|
|
21
|
+
}
|
|
22
|
+
if (typeof path === 'string') {
|
|
23
|
+
shape.data.path = path;
|
|
24
|
+
}
|
|
25
|
+
return config.errorFormatter({
|
|
26
|
+
...opts,
|
|
27
|
+
shape
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.getErrorShape = getErrorShape;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getHTTPStatusCodeFromError } from '../http/getHTTPStatusCode.mjs';
|
|
2
|
+
import { TRPC_ERROR_CODES_BY_KEY } from '../rpc/codes.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/ function getErrorShape(opts) {
|
|
7
|
+
const { path , error , config } = opts;
|
|
8
|
+
const { code } = opts.error;
|
|
9
|
+
const shape = {
|
|
10
|
+
message: error.message,
|
|
11
|
+
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
12
|
+
data: {
|
|
13
|
+
code,
|
|
14
|
+
httpStatus: getHTTPStatusCodeFromError(error)
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
18
|
+
shape.data.stack = opts.error.stack;
|
|
19
|
+
}
|
|
20
|
+
if (typeof path === 'string') {
|
|
21
|
+
shape.data.path = path;
|
|
22
|
+
}
|
|
23
|
+
return config.errorFormatter({
|
|
24
|
+
...opts,
|
|
25
|
+
shape
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { getErrorShape };
|
|
@@ -0,0 +1,24 @@
|
|
|
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 declare function getBatchStreamFormatter(): {
|
|
21
|
+
(index: number, string: string): string;
|
|
22
|
+
end(): string;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=batchStreamFormatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batchStreamFormatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/batchStreamFormatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB;YAEd,MAAM,UAAU,MAAM;;EAO9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format a batch response as a line-delimited JSON stream
|
|
5
|
+
* that the `unstable_httpBatchStreamLink` can parse:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const formatter = getBatchStreamFormatter();
|
|
10
|
+
* res.send(formatter(1, 'response #2'));
|
|
11
|
+
* res.send(formatter(0, 'response #1'));
|
|
12
|
+
* res.send(formatter.end());
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Expected format:
|
|
16
|
+
* ```json
|
|
17
|
+
* {"1":"response #2"
|
|
18
|
+
* ,"0":"response #1"
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/ function getBatchStreamFormatter() {
|
|
22
|
+
let first = true;
|
|
23
|
+
function format(index, string) {
|
|
24
|
+
const prefix = first ? '{' : ',';
|
|
25
|
+
first = false;
|
|
26
|
+
return `${prefix}"${index}":${string}\n`;
|
|
27
|
+
}
|
|
28
|
+
format.end = ()=>'}';
|
|
29
|
+
return format;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.getBatchStreamFormatter = getBatchStreamFormatter;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
*/ function getBatchStreamFormatter() {
|
|
20
|
+
let first = true;
|
|
21
|
+
function format(index, string) {
|
|
22
|
+
const prefix = first ? '{' : ',';
|
|
23
|
+
first = false;
|
|
24
|
+
return `${prefix}"${index}":${string}\n`;
|
|
25
|
+
}
|
|
26
|
+
format.end = ()=>'}';
|
|
27
|
+
return format;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { getBatchStreamFormatter };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TRPCError } from '../error/TRPCError';
|
|
2
|
+
import type { AnyRouter } from '../router';
|
|
3
|
+
import type { MaybePromise } from '../types';
|
|
4
|
+
import type { HTTPRequest } from './types';
|
|
5
|
+
type GetInputs = (opts: {
|
|
6
|
+
req: HTTPRequest;
|
|
7
|
+
isBatchCall: boolean;
|
|
8
|
+
router: AnyRouter;
|
|
9
|
+
preprocessedBody: boolean;
|
|
10
|
+
}) => MaybePromise<Record<number, unknown>>;
|
|
11
|
+
export type BodyResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
data: unknown;
|
|
14
|
+
/**
|
|
15
|
+
* If the HTTP handler has already parsed the body
|
|
16
|
+
*/
|
|
17
|
+
preprocessed: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
error: TRPCError;
|
|
21
|
+
};
|
|
22
|
+
export type BaseContentTypeHandler<TOptions> = {
|
|
23
|
+
isMatch(opts: TOptions): boolean;
|
|
24
|
+
getBody: (opts: TOptions) => MaybePromise<BodyResult>;
|
|
25
|
+
getInputs: GetInputs;
|
|
26
|
+
};
|
|
27
|
+
export declare const getJsonContentTypeInputs: GetInputs;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=contentType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,SAAS,GAAG,CAAC,IAAI,EAAE;IACtB,GAAG,EAAE,WAAW,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,KAAK,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5C,MAAM,MAAM,UAAU,GAClB;IACE,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,sBAAsB,CAAC,QAAQ,IAAI;IAC7C,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC,UAAU,CAAC,CAAC;IACtD,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,wBAAwB,EAAE,SAgCtC,CAAC"}
|