@trpc/server 10.27.2 → 10.28.0
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/adapters/aws-lambda/index.js +4 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/express.js +5 -5
- package/dist/adapters/express.mjs +5 -5
- package/dist/adapters/fastify/index.js +4 -4
- package/dist/adapters/fastify/index.mjs +4 -4
- package/dist/adapters/fetch/index.js +4 -4
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/next.js +5 -5
- package/dist/adapters/next.mjs +5 -5
- package/dist/adapters/node-http/index.js +5 -5
- package/dist/adapters/node-http/index.mjs +5 -5
- package/dist/adapters/standalone.js +5 -5
- package/dist/adapters/standalone.mjs +5 -5
- package/dist/adapters/ws.js +3 -3
- package/dist/adapters/ws.mjs +3 -3
- package/dist/{config-91ab0b1d.js → config-1a5a494d.js} +4 -28
- package/dist/{config-d1cf9de0.mjs → config-65c5b6d1.mjs} +5 -28
- package/dist/{config-f355c4d8.js → config-f3ce0144.js} +5 -28
- package/dist/core/router.d.ts +2 -2
- package/dist/core/router.d.ts.map +1 -1
- package/dist/http/index.js +4 -4
- package/dist/http/index.mjs +4 -4
- package/dist/{index-315a9f08.mjs → index-044a193b.mjs} +3 -2
- package/dist/{index-8e243a74.js → index-4a823936.js} +3 -2
- package/dist/{index-cddfa242.js → index-6d5795e9.js} +3 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +3 -3
- package/dist/{nodeHTTPRequestHandler-8a261b10.mjs → nodeHTTPRequestHandler-0f979796.mjs} +1 -1
- package/dist/{nodeHTTPRequestHandler-7762c7d4.js → nodeHTTPRequestHandler-5bbf93f1.js} +1 -1
- package/dist/{nodeHTTPRequestHandler-fc509b47.js → nodeHTTPRequestHandler-e424955c.js} +1 -1
- package/dist/{resolveHTTPResponse-5f8945d7.js → resolveHTTPResponse-4e05c4f8.js} +3 -3
- package/dist/{resolveHTTPResponse-36f4e729.mjs → resolveHTTPResponse-4e576698.mjs} +3 -3
- package/dist/{resolveHTTPResponse-27fe1108.js → resolveHTTPResponse-9523b4e3.js} +3 -3
- package/dist/shared/createProxy/index.d.ts.map +1 -1
- package/dist/shared/index.js +2 -2
- package/dist/shared/index.mjs +2 -2
- package/dist/{transformTRPCResponse-6887ae6d.mjs → transformTRPCResponse-3dca0b20.mjs} +1 -1
- package/dist/{transformTRPCResponse-f7b2ffd1.js → transformTRPCResponse-48d70ef6.js} +1 -1
- package/dist/{transformTRPCResponse-8cb7e890.js → transformTRPCResponse-64a4fd96.js} +1 -1
- package/package.json +8 -3
- package/src/core/router.ts +6 -41
- package/src/shared/createProxy/index.ts +3 -2
- package/src/adapters/node-http/content-type/json/getPostBody.test.ts +0 -49
- package/src/observable/observable.test.ts +0 -100
- package/src/observable/operators/map.test.ts +0 -91
- package/src/observable/operators/share.test.ts +0 -60
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var TRPCError = require('../../TRPCError-16b2e52d.js');
|
|
6
|
-
require('../../index-
|
|
6
|
+
require('../../index-4a823936.js');
|
|
7
7
|
require('../../codes-0eeb600d.js');
|
|
8
|
-
require('../../config-
|
|
9
|
-
var resolveHTTPResponse = require('../../resolveHTTPResponse-
|
|
10
|
-
require('../../transformTRPCResponse-
|
|
8
|
+
require('../../config-f3ce0144.js');
|
|
9
|
+
var resolveHTTPResponse = require('../../resolveHTTPResponse-9523b4e3.js');
|
|
10
|
+
require('../../transformTRPCResponse-48d70ef6.js');
|
|
11
11
|
require('../../contentType-8356d528.js');
|
|
12
12
|
|
|
13
13
|
function isPayloadV1(event) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { T as TRPCError } from '../../TRPCError-2b10c8d2.mjs';
|
|
2
|
-
import '../../index-
|
|
2
|
+
import '../../index-044a193b.mjs';
|
|
3
3
|
import '../../codes-24aa1ce1.mjs';
|
|
4
|
-
import '../../config-
|
|
5
|
-
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-
|
|
6
|
-
import '../../transformTRPCResponse-
|
|
4
|
+
import '../../config-65c5b6d1.mjs';
|
|
5
|
+
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-4e576698.mjs';
|
|
6
|
+
import '../../transformTRPCResponse-3dca0b20.mjs';
|
|
7
7
|
import '../../contentType-acc3be52.mjs';
|
|
8
8
|
|
|
9
9
|
function isPayloadV1(event) {
|
package/dist/adapters/express.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-
|
|
6
|
-
require('../resolveHTTPResponse-
|
|
7
|
-
require('../config-
|
|
5
|
+
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-5bbf93f1.js');
|
|
6
|
+
require('../resolveHTTPResponse-9523b4e3.js');
|
|
7
|
+
require('../config-f3ce0144.js');
|
|
8
8
|
require('../TRPCError-16b2e52d.js');
|
|
9
|
-
require('../index-
|
|
9
|
+
require('../index-4a823936.js');
|
|
10
10
|
require('../codes-0eeb600d.js');
|
|
11
|
-
require('../transformTRPCResponse-
|
|
11
|
+
require('../transformTRPCResponse-48d70ef6.js');
|
|
12
12
|
require('../contentType-8356d528.js');
|
|
13
13
|
require('./node-http/content-type/json/index.js');
|
|
14
14
|
require('../contentType-8c16408e.js');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-
|
|
2
|
-
import '../resolveHTTPResponse-
|
|
3
|
-
import '../config-
|
|
1
|
+
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-0f979796.mjs';
|
|
2
|
+
import '../resolveHTTPResponse-4e576698.mjs';
|
|
3
|
+
import '../config-65c5b6d1.mjs';
|
|
4
4
|
import '../TRPCError-2b10c8d2.mjs';
|
|
5
|
-
import '../index-
|
|
5
|
+
import '../index-044a193b.mjs';
|
|
6
6
|
import '../codes-24aa1ce1.mjs';
|
|
7
|
-
import '../transformTRPCResponse-
|
|
7
|
+
import '../transformTRPCResponse-3dca0b20.mjs';
|
|
8
8
|
import '../contentType-acc3be52.mjs';
|
|
9
9
|
import './node-http/content-type/json/index.mjs';
|
|
10
10
|
import '../contentType-3194ed5f.mjs';
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var resolveHTTPResponse = require('../../resolveHTTPResponse-
|
|
5
|
+
var resolveHTTPResponse = require('../../resolveHTTPResponse-9523b4e3.js');
|
|
6
6
|
var adapters_ws = require('../ws.js');
|
|
7
|
-
require('../../config-
|
|
7
|
+
require('../../config-f3ce0144.js');
|
|
8
8
|
require('../../TRPCError-16b2e52d.js');
|
|
9
|
-
require('../../index-
|
|
9
|
+
require('../../index-4a823936.js');
|
|
10
10
|
require('../../codes-0eeb600d.js');
|
|
11
|
-
require('../../transformTRPCResponse-
|
|
11
|
+
require('../../transformTRPCResponse-48d70ef6.js');
|
|
12
12
|
require('../../contentType-8356d528.js');
|
|
13
13
|
require('../../observable-464116ac.js');
|
|
14
14
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-
|
|
1
|
+
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-4e576698.mjs';
|
|
2
2
|
import { applyWSSHandler } from '../ws.mjs';
|
|
3
|
-
import '../../config-
|
|
3
|
+
import '../../config-65c5b6d1.mjs';
|
|
4
4
|
import '../../TRPCError-2b10c8d2.mjs';
|
|
5
|
-
import '../../index-
|
|
5
|
+
import '../../index-044a193b.mjs';
|
|
6
6
|
import '../../codes-24aa1ce1.mjs';
|
|
7
|
-
import '../../transformTRPCResponse-
|
|
7
|
+
import '../../transformTRPCResponse-3dca0b20.mjs';
|
|
8
8
|
import '../../contentType-acc3be52.mjs';
|
|
9
9
|
import '../../observable-ade1bad8.mjs';
|
|
10
10
|
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var resolveHTTPResponse = require('../../resolveHTTPResponse-
|
|
6
|
-
require('../../config-
|
|
5
|
+
var resolveHTTPResponse = require('../../resolveHTTPResponse-9523b4e3.js');
|
|
6
|
+
require('../../config-f3ce0144.js');
|
|
7
7
|
require('../../TRPCError-16b2e52d.js');
|
|
8
|
-
require('../../index-
|
|
8
|
+
require('../../index-4a823936.js');
|
|
9
9
|
require('../../codes-0eeb600d.js');
|
|
10
|
-
require('../../transformTRPCResponse-
|
|
10
|
+
require('../../transformTRPCResponse-48d70ef6.js');
|
|
11
11
|
require('../../contentType-8356d528.js');
|
|
12
12
|
|
|
13
13
|
async function fetchRequestHandler(opts) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-
|
|
2
|
-
import '../../config-
|
|
1
|
+
import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-4e576698.mjs';
|
|
2
|
+
import '../../config-65c5b6d1.mjs';
|
|
3
3
|
import '../../TRPCError-2b10c8d2.mjs';
|
|
4
|
-
import '../../index-
|
|
4
|
+
import '../../index-044a193b.mjs';
|
|
5
5
|
import '../../codes-24aa1ce1.mjs';
|
|
6
|
-
import '../../transformTRPCResponse-
|
|
6
|
+
import '../../transformTRPCResponse-3dca0b20.mjs';
|
|
7
7
|
import '../../contentType-acc3be52.mjs';
|
|
8
8
|
|
|
9
9
|
async function fetchRequestHandler(opts) {
|
package/dist/adapters/next.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var TRPCError = require('../TRPCError-16b2e52d.js');
|
|
6
|
-
var transformTRPCResponse = require('../transformTRPCResponse-
|
|
7
|
-
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-
|
|
8
|
-
require('../index-
|
|
6
|
+
var transformTRPCResponse = require('../transformTRPCResponse-48d70ef6.js');
|
|
7
|
+
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-5bbf93f1.js');
|
|
8
|
+
require('../index-4a823936.js');
|
|
9
9
|
require('../codes-0eeb600d.js');
|
|
10
|
-
require('../resolveHTTPResponse-
|
|
11
|
-
require('../config-
|
|
10
|
+
require('../resolveHTTPResponse-9523b4e3.js');
|
|
11
|
+
require('../config-f3ce0144.js');
|
|
12
12
|
require('../contentType-8356d528.js');
|
|
13
13
|
require('./node-http/content-type/json/index.js');
|
|
14
14
|
require('../contentType-8c16408e.js');
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { T as TRPCError } from '../TRPCError-2b10c8d2.mjs';
|
|
2
|
-
import { g as getErrorShape } from '../transformTRPCResponse-
|
|
3
|
-
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-
|
|
4
|
-
import '../index-
|
|
2
|
+
import { g as getErrorShape } from '../transformTRPCResponse-3dca0b20.mjs';
|
|
3
|
+
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-0f979796.mjs';
|
|
4
|
+
import '../index-044a193b.mjs';
|
|
5
5
|
import '../codes-24aa1ce1.mjs';
|
|
6
|
-
import '../resolveHTTPResponse-
|
|
7
|
-
import '../config-
|
|
6
|
+
import '../resolveHTTPResponse-4e576698.mjs';
|
|
7
|
+
import '../config-65c5b6d1.mjs';
|
|
8
8
|
import '../contentType-acc3be52.mjs';
|
|
9
9
|
import './node-http/content-type/json/index.mjs';
|
|
10
10
|
import '../contentType-3194ed5f.mjs';
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-
|
|
6
|
-
require('../../resolveHTTPResponse-
|
|
7
|
-
require('../../config-
|
|
5
|
+
var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-5bbf93f1.js');
|
|
6
|
+
require('../../resolveHTTPResponse-9523b4e3.js');
|
|
7
|
+
require('../../config-f3ce0144.js');
|
|
8
8
|
require('../../TRPCError-16b2e52d.js');
|
|
9
|
-
require('../../index-
|
|
9
|
+
require('../../index-4a823936.js');
|
|
10
10
|
require('../../codes-0eeb600d.js');
|
|
11
|
-
require('../../transformTRPCResponse-
|
|
11
|
+
require('../../transformTRPCResponse-48d70ef6.js');
|
|
12
12
|
require('../../contentType-8356d528.js');
|
|
13
13
|
require('./content-type/json/index.js');
|
|
14
14
|
require('../../contentType-8c16408e.js');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-
|
|
2
|
-
import '../../resolveHTTPResponse-
|
|
3
|
-
import '../../config-
|
|
1
|
+
export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-0f979796.mjs';
|
|
2
|
+
import '../../resolveHTTPResponse-4e576698.mjs';
|
|
3
|
+
import '../../config-65c5b6d1.mjs';
|
|
4
4
|
import '../../TRPCError-2b10c8d2.mjs';
|
|
5
|
-
import '../../index-
|
|
5
|
+
import '../../index-044a193b.mjs';
|
|
6
6
|
import '../../codes-24aa1ce1.mjs';
|
|
7
|
-
import '../../transformTRPCResponse-
|
|
7
|
+
import '../../transformTRPCResponse-3dca0b20.mjs';
|
|
8
8
|
import '../../contentType-acc3be52.mjs';
|
|
9
9
|
import './content-type/json/index.mjs';
|
|
10
10
|
import '../../contentType-3194ed5f.mjs';
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var http = require('node:http');
|
|
6
|
-
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-
|
|
7
|
-
require('../resolveHTTPResponse-
|
|
8
|
-
require('../config-
|
|
6
|
+
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-5bbf93f1.js');
|
|
7
|
+
require('../resolveHTTPResponse-9523b4e3.js');
|
|
8
|
+
require('../config-f3ce0144.js');
|
|
9
9
|
require('../TRPCError-16b2e52d.js');
|
|
10
|
-
require('../index-
|
|
10
|
+
require('../index-4a823936.js');
|
|
11
11
|
require('../codes-0eeb600d.js');
|
|
12
|
-
require('../transformTRPCResponse-
|
|
12
|
+
require('../transformTRPCResponse-48d70ef6.js');
|
|
13
13
|
require('../contentType-8356d528.js');
|
|
14
14
|
require('./node-http/content-type/json/index.js');
|
|
15
15
|
require('../contentType-8c16408e.js');
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-
|
|
3
|
-
import '../resolveHTTPResponse-
|
|
4
|
-
import '../config-
|
|
2
|
+
import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-0f979796.mjs';
|
|
3
|
+
import '../resolveHTTPResponse-4e576698.mjs';
|
|
4
|
+
import '../config-65c5b6d1.mjs';
|
|
5
5
|
import '../TRPCError-2b10c8d2.mjs';
|
|
6
|
-
import '../index-
|
|
6
|
+
import '../index-044a193b.mjs';
|
|
7
7
|
import '../codes-24aa1ce1.mjs';
|
|
8
|
-
import '../transformTRPCResponse-
|
|
8
|
+
import '../transformTRPCResponse-3dca0b20.mjs';
|
|
9
9
|
import '../contentType-acc3be52.mjs';
|
|
10
10
|
import './node-http/content-type/json/index.mjs';
|
|
11
11
|
import '../contentType-3194ed5f.mjs';
|
package/dist/adapters/ws.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var config = require('../config-
|
|
5
|
+
var config = require('../config-f3ce0144.js');
|
|
6
6
|
var TRPCError = require('../TRPCError-16b2e52d.js');
|
|
7
7
|
var observable = require('../observable-464116ac.js');
|
|
8
|
-
var transformTRPCResponse = require('../transformTRPCResponse-
|
|
9
|
-
require('../index-
|
|
8
|
+
var transformTRPCResponse = require('../transformTRPCResponse-48d70ef6.js');
|
|
9
|
+
require('../index-4a823936.js');
|
|
10
10
|
require('../codes-0eeb600d.js');
|
|
11
11
|
|
|
12
12
|
/* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
|
package/dist/adapters/ws.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as callProcedure } from '../config-
|
|
1
|
+
import { b as callProcedure } from '../config-65c5b6d1.mjs';
|
|
2
2
|
import { T as TRPCError, g as getCauseFromUnknown, a as getTRPCErrorFromUnknown } from '../TRPCError-2b10c8d2.mjs';
|
|
3
3
|
import { i as isObservable } from '../observable-ade1bad8.mjs';
|
|
4
|
-
import { g as getErrorShape, t as transformTRPCResponse } from '../transformTRPCResponse-
|
|
5
|
-
import '../index-
|
|
4
|
+
import { g as getErrorShape, t as transformTRPCResponse } from '../transformTRPCResponse-3dca0b20.mjs';
|
|
5
|
+
import '../index-044a193b.mjs';
|
|
6
6
|
import '../codes-24aa1ce1.mjs';
|
|
7
7
|
|
|
8
8
|
/* istanbul ignore next -- @preserve */ function assertIsObject(obj) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { T as TRPCError } from './TRPCError-61026c9a.js';
|
|
2
|
-
import { a as createRecursiveProxy, g as getHTTPStatusCodeFromError } from './index-
|
|
2
|
+
import { a as createRecursiveProxy, g as getHTTPStatusCodeFromError } from './index-6d5795e9.js';
|
|
3
3
|
import { T as TRPC_ERROR_CODES_BY_KEY } from './codes-b3c262d8.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -37,9 +37,6 @@ const procedureTypes = ['query', 'mutation', 'subscription'];
|
|
|
37
37
|
function isRouter(procedureOrRouter) {
|
|
38
38
|
return 'router' in procedureOrRouter._def;
|
|
39
39
|
}
|
|
40
|
-
function isNestedRouter(procedureOrRouter) {
|
|
41
|
-
return !('_def' in procedureOrRouter);
|
|
42
|
-
}
|
|
43
40
|
const emptyRouter = {
|
|
44
41
|
_ctx: null,
|
|
45
42
|
_errorShape: null,
|
|
@@ -59,10 +56,6 @@ const reservedWords = [
|
|
|
59
56
|
* since JS will think that `.then` is something that exists
|
|
60
57
|
*/
|
|
61
58
|
'then',
|
|
62
|
-
/**
|
|
63
|
-
* `_def` is a reserved word because it's used internally a lot
|
|
64
|
-
*/
|
|
65
|
-
'_def',
|
|
66
59
|
];
|
|
67
60
|
/**
|
|
68
61
|
* @internal
|
|
@@ -74,27 +67,10 @@ function createRouterFactory(config) {
|
|
|
74
67
|
throw new Error('Reserved words used in `router({})` call: ' +
|
|
75
68
|
Array.from(reservedWordsUsed).join(', '));
|
|
76
69
|
}
|
|
77
|
-
const newProcedures = {};
|
|
78
|
-
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})) {
|
|
79
|
-
const value = procedures[key] ?? {};
|
|
80
|
-
if (isNestedRouter(value)) {
|
|
81
|
-
newProcedures[key] = createRouterInner(value);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (isRouter(value)) {
|
|
85
|
-
newProcedures[key] = procedureOrRouter;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
newProcedures[key] = procedureOrRouter;
|
|
89
|
-
}
|
|
90
70
|
const routerProcedures = omitPrototype({});
|
|
91
71
|
function recursiveGetPaths(procedures, path = '') {
|
|
92
72
|
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})) {
|
|
93
73
|
const newPath = `${path}${key}`;
|
|
94
|
-
if (isNestedRouter(procedureOrRouter)) {
|
|
95
|
-
recursiveGetPaths(procedureOrRouter, `${newPath}.`);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
74
|
if (isRouter(procedureOrRouter)) {
|
|
99
75
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
100
76
|
continue;
|
|
@@ -105,13 +81,13 @@ function createRouterFactory(config) {
|
|
|
105
81
|
routerProcedures[newPath] = procedureOrRouter;
|
|
106
82
|
}
|
|
107
83
|
}
|
|
108
|
-
recursiveGetPaths(
|
|
84
|
+
recursiveGetPaths(procedures);
|
|
109
85
|
const _def = {
|
|
110
86
|
_config: config,
|
|
111
87
|
router: true,
|
|
112
88
|
procedures: routerProcedures,
|
|
113
89
|
...emptyRouter,
|
|
114
|
-
record:
|
|
90
|
+
record: procedures,
|
|
115
91
|
queries: Object.entries(routerProcedures)
|
|
116
92
|
.filter((pair) => pair[1]._def.query)
|
|
117
93
|
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}),
|
|
@@ -123,7 +99,7 @@ function createRouterFactory(config) {
|
|
|
123
99
|
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}),
|
|
124
100
|
};
|
|
125
101
|
const router = {
|
|
126
|
-
...
|
|
102
|
+
...procedures,
|
|
127
103
|
_def,
|
|
128
104
|
createCaller(ctx) {
|
|
129
105
|
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { T as TRPCError } from './TRPCError-2b10c8d2.mjs';
|
|
2
|
-
import { a as createRecursiveProxy, g as getHTTPStatusCodeFromError } from './index-
|
|
2
|
+
import { a as createRecursiveProxy, g as getHTTPStatusCodeFromError } from './index-044a193b.mjs';
|
|
3
3
|
import { T as TRPC_ERROR_CODES_BY_KEY } from './codes-24aa1ce1.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -49,9 +49,6 @@ const procedureTypes = [
|
|
|
49
49
|
function isRouter(procedureOrRouter) {
|
|
50
50
|
return 'router' in procedureOrRouter._def;
|
|
51
51
|
}
|
|
52
|
-
function isNestedRouter(procedureOrRouter) {
|
|
53
|
-
return !('_def' in procedureOrRouter);
|
|
54
|
-
}
|
|
55
52
|
const emptyRouter = {
|
|
56
53
|
_ctx: null,
|
|
57
54
|
_errorShape: null,
|
|
@@ -68,10 +65,7 @@ const emptyRouter = {
|
|
|
68
65
|
/**
|
|
69
66
|
* Then is a reserved word because otherwise we can't return a promise that returns a Proxy
|
|
70
67
|
* since JS will think that `.then` is something that exists
|
|
71
|
-
*/ 'then'
|
|
72
|
-
/**
|
|
73
|
-
* `_def` is a reserved word because it's used internally a lot
|
|
74
|
-
*/ '_def'
|
|
68
|
+
*/ 'then'
|
|
75
69
|
];
|
|
76
70
|
/**
|
|
77
71
|
* @internal
|
|
@@ -81,27 +75,10 @@ const emptyRouter = {
|
|
|
81
75
|
if (reservedWordsUsed.size > 0) {
|
|
82
76
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
83
77
|
}
|
|
84
|
-
const newProcedures = {};
|
|
85
|
-
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
86
|
-
const value = procedures[key] ?? {};
|
|
87
|
-
if (isNestedRouter(value)) {
|
|
88
|
-
newProcedures[key] = createRouterInner(value);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (isRouter(value)) {
|
|
92
|
-
newProcedures[key] = procedureOrRouter;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
newProcedures[key] = procedureOrRouter;
|
|
96
|
-
}
|
|
97
78
|
const routerProcedures = omitPrototype({});
|
|
98
79
|
function recursiveGetPaths(procedures, path = '') {
|
|
99
80
|
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
100
81
|
const newPath = `${path}${key}`;
|
|
101
|
-
if (isNestedRouter(procedureOrRouter)) {
|
|
102
|
-
recursiveGetPaths(procedureOrRouter, `${newPath}.`);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
82
|
if (isRouter(procedureOrRouter)) {
|
|
106
83
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
107
84
|
continue;
|
|
@@ -112,13 +89,13 @@ const emptyRouter = {
|
|
|
112
89
|
routerProcedures[newPath] = procedureOrRouter;
|
|
113
90
|
}
|
|
114
91
|
}
|
|
115
|
-
recursiveGetPaths(
|
|
92
|
+
recursiveGetPaths(procedures);
|
|
116
93
|
const _def = {
|
|
117
94
|
_config: config,
|
|
118
95
|
router: true,
|
|
119
96
|
procedures: routerProcedures,
|
|
120
97
|
...emptyRouter,
|
|
121
|
-
record:
|
|
98
|
+
record: procedures,
|
|
122
99
|
queries: Object.entries(routerProcedures).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
123
100
|
...acc,
|
|
124
101
|
[key]: val
|
|
@@ -133,7 +110,7 @@ const emptyRouter = {
|
|
|
133
110
|
}), {})
|
|
134
111
|
};
|
|
135
112
|
const router = {
|
|
136
|
-
...
|
|
113
|
+
...procedures,
|
|
137
114
|
_def,
|
|
138
115
|
createCaller (ctx) {
|
|
139
116
|
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var TRPCError = require('./TRPCError-16b2e52d.js');
|
|
4
|
-
var index = require('./index-
|
|
4
|
+
var index = require('./index-4a823936.js');
|
|
5
5
|
var codes = require('./codes-0eeb600d.js');
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -51,9 +51,6 @@ const procedureTypes = [
|
|
|
51
51
|
function isRouter(procedureOrRouter) {
|
|
52
52
|
return 'router' in procedureOrRouter._def;
|
|
53
53
|
}
|
|
54
|
-
function isNestedRouter(procedureOrRouter) {
|
|
55
|
-
return !('_def' in procedureOrRouter);
|
|
56
|
-
}
|
|
57
54
|
const emptyRouter = {
|
|
58
55
|
_ctx: null,
|
|
59
56
|
_errorShape: null,
|
|
@@ -70,10 +67,7 @@ const emptyRouter = {
|
|
|
70
67
|
/**
|
|
71
68
|
* Then is a reserved word because otherwise we can't return a promise that returns a Proxy
|
|
72
69
|
* since JS will think that `.then` is something that exists
|
|
73
|
-
*/ 'then'
|
|
74
|
-
/**
|
|
75
|
-
* `_def` is a reserved word because it's used internally a lot
|
|
76
|
-
*/ '_def'
|
|
70
|
+
*/ 'then'
|
|
77
71
|
];
|
|
78
72
|
/**
|
|
79
73
|
* @internal
|
|
@@ -83,27 +77,10 @@ const emptyRouter = {
|
|
|
83
77
|
if (reservedWordsUsed.size > 0) {
|
|
84
78
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
85
79
|
}
|
|
86
|
-
const newProcedures = {};
|
|
87
|
-
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
88
|
-
const value = procedures[key] ?? {};
|
|
89
|
-
if (isNestedRouter(value)) {
|
|
90
|
-
newProcedures[key] = createRouterInner(value);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (isRouter(value)) {
|
|
94
|
-
newProcedures[key] = procedureOrRouter;
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
newProcedures[key] = procedureOrRouter;
|
|
98
|
-
}
|
|
99
80
|
const routerProcedures = omitPrototype({});
|
|
100
81
|
function recursiveGetPaths(procedures, path = '') {
|
|
101
82
|
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
102
83
|
const newPath = `${path}${key}`;
|
|
103
|
-
if (isNestedRouter(procedureOrRouter)) {
|
|
104
|
-
recursiveGetPaths(procedureOrRouter, `${newPath}.`);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
84
|
if (isRouter(procedureOrRouter)) {
|
|
108
85
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
109
86
|
continue;
|
|
@@ -114,13 +91,13 @@ const emptyRouter = {
|
|
|
114
91
|
routerProcedures[newPath] = procedureOrRouter;
|
|
115
92
|
}
|
|
116
93
|
}
|
|
117
|
-
recursiveGetPaths(
|
|
94
|
+
recursiveGetPaths(procedures);
|
|
118
95
|
const _def = {
|
|
119
96
|
_config: config,
|
|
120
97
|
router: true,
|
|
121
98
|
procedures: routerProcedures,
|
|
122
99
|
...emptyRouter,
|
|
123
|
-
record:
|
|
100
|
+
record: procedures,
|
|
124
101
|
queries: Object.entries(routerProcedures).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
125
102
|
...acc,
|
|
126
103
|
[key]: val
|
|
@@ -135,7 +112,7 @@ const emptyRouter = {
|
|
|
135
112
|
}), {})
|
|
136
113
|
};
|
|
137
114
|
const router = {
|
|
138
|
-
...
|
|
115
|
+
...procedures,
|
|
139
116
|
_def,
|
|
140
117
|
createCaller (ctx) {
|
|
141
118
|
const proxy = index.createRecursiveProxy(({ path , args })=>{
|
package/dist/core/router.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ProcedureType, inferHandlerInput, inferProcedureOutput } from './types'
|
|
|
6
6
|
/** @internal **/
|
|
7
7
|
export declare type ProcedureRecord = Record<string, AnyProcedure>;
|
|
8
8
|
export interface ProcedureRouterRecord {
|
|
9
|
-
[key: string]: AnyProcedure | AnyRouter
|
|
9
|
+
[key: string]: AnyProcedure | AnyRouter;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* @deprecated
|
|
@@ -55,7 +55,7 @@ declare type DecorateProcedure<TProcedure extends AnyProcedure> = (input: Proced
|
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
57
|
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
58
|
-
[TKey in keyof TProcedures]: TProcedures[TKey] extends
|
|
58
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
59
59
|
};
|
|
60
60
|
/**
|
|
61
61
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAEjB,iBAAiB;AACjB,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"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"}
|
package/dist/http/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../index-
|
|
6
|
-
var resolveHTTPResponse = require('../resolveHTTPResponse-
|
|
5
|
+
var index = require('../index-4a823936.js');
|
|
6
|
+
var resolveHTTPResponse = require('../resolveHTTPResponse-9523b4e3.js');
|
|
7
7
|
require('../codes-0eeb600d.js');
|
|
8
|
-
require('../config-
|
|
8
|
+
require('../config-f3ce0144.js');
|
|
9
9
|
require('../TRPCError-16b2e52d.js');
|
|
10
|
-
require('../transformTRPCResponse-
|
|
10
|
+
require('../transformTRPCResponse-48d70ef6.js');
|
|
11
11
|
require('../contentType-8356d528.js');
|
|
12
12
|
|
|
13
13
|
|
package/dist/http/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { T as TRPC_ERROR_CODES_BY_NUMBER, b as getHTTPStatusCode, g as getHTTPStatusCodeFromError } from '../index-
|
|
2
|
-
export { r as resolveHTTPResponse } from '../resolveHTTPResponse-
|
|
1
|
+
export { T as TRPC_ERROR_CODES_BY_NUMBER, b as getHTTPStatusCode, g as getHTTPStatusCodeFromError } from '../index-044a193b.mjs';
|
|
2
|
+
export { r as resolveHTTPResponse } from '../resolveHTTPResponse-4e576698.mjs';
|
|
3
3
|
import '../codes-24aa1ce1.mjs';
|
|
4
|
-
import '../config-
|
|
4
|
+
import '../config-65c5b6d1.mjs';
|
|
5
5
|
import '../TRPCError-2b10c8d2.mjs';
|
|
6
|
-
import '../transformTRPCResponse-
|
|
6
|
+
import '../transformTRPCResponse-3dca0b20.mjs';
|
|
7
7
|
import '../contentType-acc3be52.mjs';
|
|
@@ -63,9 +63,10 @@ function createInnerProxy(callback, path) {
|
|
|
63
63
|
]);
|
|
64
64
|
},
|
|
65
65
|
apply (_1, _2, args) {
|
|
66
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
66
67
|
return callback({
|
|
67
|
-
args,
|
|
68
|
-
path
|
|
68
|
+
args: isApply ? args.length >= 2 ? args[1] : [] : args,
|
|
69
|
+
path: isApply ? path.slice(0, -1) : path
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
});
|
|
@@ -65,9 +65,10 @@ function createInnerProxy(callback, path) {
|
|
|
65
65
|
]);
|
|
66
66
|
},
|
|
67
67
|
apply (_1, _2, args) {
|
|
68
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
68
69
|
return callback({
|
|
69
|
-
args,
|
|
70
|
-
path
|
|
70
|
+
args: isApply ? args.length >= 2 ? args[1] : [] : args,
|
|
71
|
+
path: isApply ? path.slice(0, -1) : path
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
});
|
|
@@ -58,9 +58,10 @@ function createInnerProxy(callback, path) {
|
|
|
58
58
|
return createInnerProxy(callback, [...path, key]);
|
|
59
59
|
},
|
|
60
60
|
apply(_1, _2, args) {
|
|
61
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
61
62
|
return callback({
|
|
62
|
-
args,
|
|
63
|
-
path,
|
|
63
|
+
args: isApply ? (args.length >= 2 ? args[1] : []) : args,
|
|
64
|
+
path: isApply ? path.slice(0, -1) : path,
|
|
64
65
|
});
|
|
65
66
|
},
|
|
66
67
|
});
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var config = require('./config-
|
|
5
|
+
var config = require('./config-f3ce0144.js');
|
|
6
6
|
var TRPCError = require('./TRPCError-16b2e52d.js');
|
|
7
|
-
var index = require('./index-
|
|
7
|
+
var index = require('./index-4a823936.js');
|
|
8
8
|
var codes = require('./codes-0eeb600d.js');
|
|
9
9
|
|
|
10
10
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as createRouterFactory, d as defaultFormatter, a as defaultTransformer, g as getDataTransformer$1, i as isServerDefault } from './config-
|
|
2
|
-
export { b as callProcedure, a as defaultTransformer, g as getDataTransformer, p as procedureTypes } from './config-
|
|
1
|
+
import { c as createRouterFactory, d as defaultFormatter, a as defaultTransformer, g as getDataTransformer$1, i as isServerDefault } from './config-65c5b6d1.mjs';
|
|
2
|
+
export { b as callProcedure, a as defaultTransformer, g as getDataTransformer, p as procedureTypes } from './config-65c5b6d1.mjs';
|
|
3
3
|
import { T as TRPCError, g as getCauseFromUnknown, a as getTRPCErrorFromUnknown } from './TRPCError-2b10c8d2.mjs';
|
|
4
4
|
export { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-2b10c8d2.mjs';
|
|
5
|
-
import { g as getHTTPStatusCodeFromError, c as createFlatProxy } from './index-
|
|
5
|
+
import { g as getHTTPStatusCodeFromError, c as createFlatProxy } from './index-044a193b.mjs';
|
|
6
6
|
import { T as TRPC_ERROR_CODES_BY_KEY } from './codes-24aa1ce1.mjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from './resolveHTTPResponse-
|
|
1
|
+
import { r as resolveHTTPResponse } from './resolveHTTPResponse-4e576698.mjs';
|
|
2
2
|
import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.mjs';
|
|
3
3
|
|
|
4
4
|
const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var resolveHTTPResponse = require('./resolveHTTPResponse-
|
|
3
|
+
var resolveHTTPResponse = require('./resolveHTTPResponse-9523b4e3.js');
|
|
4
4
|
var adapters_nodeHttp_contentType_json_index = require('./adapters/node-http/content-type/json/index.js');
|
|
5
5
|
|
|
6
6
|
const defaultJSONContentTypeHandler = adapters_nodeHttp_contentType_json_index.nodeHTTPJSONContentTypeHandler();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from './resolveHTTPResponse-
|
|
1
|
+
import { r as resolveHTTPResponse } from './resolveHTTPResponse-4e05c4f8.js';
|
|
2
2
|
import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.js';
|
|
3
3
|
|
|
4
4
|
const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as callProcedure } from './config-
|
|
1
|
+
import { b as callProcedure } from './config-1a5a494d.js';
|
|
2
2
|
import { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-61026c9a.js';
|
|
3
|
-
import { g as getErrorShape, t as transformTRPCResponse } from './transformTRPCResponse-
|
|
3
|
+
import { g as getErrorShape, t as transformTRPCResponse } from './transformTRPCResponse-64a4fd96.js';
|
|
4
4
|
import { g as getJsonContentTypeInputs } from './contentType-a75c990c.js';
|
|
5
|
-
import { b as getHTTPStatusCode } from './index-
|
|
5
|
+
import { b as getHTTPStatusCode } from './index-6d5795e9.js';
|
|
6
6
|
|
|
7
7
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
8
8
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as callProcedure } from './config-
|
|
1
|
+
import { b as callProcedure } from './config-65c5b6d1.mjs';
|
|
2
2
|
import { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-2b10c8d2.mjs';
|
|
3
|
-
import { g as getErrorShape, t as transformTRPCResponse } from './transformTRPCResponse-
|
|
3
|
+
import { g as getErrorShape, t as transformTRPCResponse } from './transformTRPCResponse-3dca0b20.mjs';
|
|
4
4
|
import { g as getJsonContentTypeInputs } from './contentType-acc3be52.mjs';
|
|
5
|
-
import { b as getHTTPStatusCode } from './index-
|
|
5
|
+
import { b as getHTTPStatusCode } from './index-044a193b.mjs';
|
|
6
6
|
|
|
7
7
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
8
8
|
GET: 'query',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var config = require('./config-
|
|
3
|
+
var config = require('./config-f3ce0144.js');
|
|
4
4
|
var TRPCError = require('./TRPCError-16b2e52d.js');
|
|
5
|
-
var transformTRPCResponse = require('./transformTRPCResponse-
|
|
5
|
+
var transformTRPCResponse = require('./transformTRPCResponse-48d70ef6.js');
|
|
6
6
|
var contentType = require('./contentType-8356d528.js');
|
|
7
|
-
var index = require('./index-
|
|
7
|
+
var index = require('./index-4a823936.js');
|
|
8
8
|
|
|
9
9
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
10
10
|
GET: 'query',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/createProxy/index.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/createProxy/index.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,aAAK,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"}
|
package/dist/shared/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../index-
|
|
6
|
-
var transformTRPCResponse = require('../transformTRPCResponse-
|
|
5
|
+
var index = require('../index-4a823936.js');
|
|
6
|
+
var transformTRPCResponse = require('../transformTRPCResponse-48d70ef6.js');
|
|
7
7
|
require('../codes-0eeb600d.js');
|
|
8
8
|
|
|
9
9
|
|
package/dist/shared/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { c as createFlatProxy, a as createRecursiveProxy } from '../index-
|
|
2
|
-
export { g as getErrorShape, t as transformTRPCResponse } from '../transformTRPCResponse-
|
|
1
|
+
export { c as createFlatProxy, a as createRecursiveProxy } from '../index-044a193b.mjs';
|
|
2
|
+
export { g as getErrorShape, t as transformTRPCResponse } from '../transformTRPCResponse-3dca0b20.mjs';
|
|
3
3
|
import '../codes-24aa1ce1.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.28.0",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -130,7 +130,8 @@
|
|
|
130
130
|
"rpc",
|
|
131
131
|
"observable",
|
|
132
132
|
"subscription",
|
|
133
|
-
"shared"
|
|
133
|
+
"shared",
|
|
134
|
+
"!**/*.test.*"
|
|
134
135
|
],
|
|
135
136
|
"publishConfig": {
|
|
136
137
|
"access": "public"
|
|
@@ -168,5 +169,9 @@
|
|
|
168
169
|
"ws": "^8.0.0",
|
|
169
170
|
"yup": "^1.0.0",
|
|
170
171
|
"zod": "^3.0.0"
|
|
171
|
-
}
|
|
172
|
+
},
|
|
173
|
+
"funding": [
|
|
174
|
+
"https://trpc.io/sponsor"
|
|
175
|
+
],
|
|
176
|
+
"gitHead": "7aadb24ce0bc20ae27f32bd80891ef6da5885e5e"
|
|
172
177
|
}
|
package/src/core/router.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
export type ProcedureRecord = Record<string, AnyProcedure>;
|
|
26
26
|
|
|
27
27
|
export interface ProcedureRouterRecord {
|
|
28
|
-
[key: string]: AnyProcedure | AnyRouter
|
|
28
|
+
[key: string]: AnyProcedure | AnyRouter;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -97,9 +97,7 @@ type DecorateProcedure<TProcedure extends AnyProcedure> = (
|
|
|
97
97
|
* @internal
|
|
98
98
|
*/
|
|
99
99
|
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
100
|
-
[TKey in keyof TProcedures]: TProcedures[TKey] extends
|
|
101
|
-
? DecoratedProcedureRecord<TProcedures[TKey]>
|
|
102
|
-
: TProcedures[TKey] extends AnyRouter
|
|
100
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
103
101
|
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
104
102
|
: TProcedures[TKey] extends AnyProcedure
|
|
105
103
|
? DecorateProcedure<TProcedures[TKey]>
|
|
@@ -146,17 +144,11 @@ export interface Router<TDef extends AnyRouterDef> {
|
|
|
146
144
|
export type AnyRouter = Router<AnyRouterDef>;
|
|
147
145
|
|
|
148
146
|
function isRouter(
|
|
149
|
-
procedureOrRouter: AnyProcedure | AnyRouter
|
|
147
|
+
procedureOrRouter: AnyProcedure | AnyRouter,
|
|
150
148
|
): procedureOrRouter is AnyRouter {
|
|
151
149
|
return 'router' in procedureOrRouter._def;
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
function isNestedRouter(
|
|
155
|
-
procedureOrRouter: AnyProcedure | AnyRouter | ProcedureRouterRecord,
|
|
156
|
-
): procedureOrRouter is ProcedureRouterRecord {
|
|
157
|
-
return !('_def' in procedureOrRouter);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
152
|
const emptyRouter = {
|
|
161
153
|
_ctx: null as any,
|
|
162
154
|
_errorShape: null as any,
|
|
@@ -177,10 +169,6 @@ const reservedWords = [
|
|
|
177
169
|
* since JS will think that `.then` is something that exists
|
|
178
170
|
*/
|
|
179
171
|
'then',
|
|
180
|
-
/**
|
|
181
|
-
* `_def` is a reserved word because it's used internally a lot
|
|
182
|
-
*/
|
|
183
|
-
'_def',
|
|
184
172
|
];
|
|
185
173
|
|
|
186
174
|
/**
|
|
@@ -216,33 +204,11 @@ export function createRouterFactory<TConfig extends AnyRootConfig>(
|
|
|
216
204
|
);
|
|
217
205
|
}
|
|
218
206
|
|
|
219
|
-
const newProcedures: ProcedureRouterRecord = {};
|
|
220
|
-
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})) {
|
|
221
|
-
const value = procedures[key] ?? {};
|
|
222
|
-
|
|
223
|
-
if (isNestedRouter(value)) {
|
|
224
|
-
newProcedures[key] = createRouterInner(value);
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (isRouter(value)) {
|
|
229
|
-
newProcedures[key] = procedureOrRouter;
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
newProcedures[key] = procedureOrRouter;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
207
|
const routerProcedures: ProcedureRecord = omitPrototype({});
|
|
237
208
|
function recursiveGetPaths(procedures: ProcedureRouterRecord, path = '') {
|
|
238
209
|
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})) {
|
|
239
210
|
const newPath = `${path}${key}`;
|
|
240
211
|
|
|
241
|
-
if (isNestedRouter(procedureOrRouter)) {
|
|
242
|
-
recursiveGetPaths(procedureOrRouter, `${newPath}.`);
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
212
|
if (isRouter(procedureOrRouter)) {
|
|
247
213
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
248
214
|
continue;
|
|
@@ -255,14 +221,14 @@ export function createRouterFactory<TConfig extends AnyRootConfig>(
|
|
|
255
221
|
routerProcedures[newPath] = procedureOrRouter;
|
|
256
222
|
}
|
|
257
223
|
}
|
|
258
|
-
recursiveGetPaths(
|
|
224
|
+
recursiveGetPaths(procedures);
|
|
259
225
|
|
|
260
226
|
const _def: AnyRouterDef<TConfig> = {
|
|
261
227
|
_config: config,
|
|
262
228
|
router: true,
|
|
263
229
|
procedures: routerProcedures,
|
|
264
230
|
...emptyRouter,
|
|
265
|
-
record:
|
|
231
|
+
record: procedures,
|
|
266
232
|
queries: Object.entries(routerProcedures)
|
|
267
233
|
.filter((pair) => (pair[1] as any)._def.query)
|
|
268
234
|
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}),
|
|
@@ -275,7 +241,7 @@ export function createRouterFactory<TConfig extends AnyRootConfig>(
|
|
|
275
241
|
};
|
|
276
242
|
|
|
277
243
|
const router: AnyRouter = {
|
|
278
|
-
...
|
|
244
|
+
...procedures,
|
|
279
245
|
_def,
|
|
280
246
|
createCaller(ctx) {
|
|
281
247
|
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
@@ -333,7 +299,6 @@ export function createRouterFactory<TConfig extends AnyRootConfig>(
|
|
|
333
299
|
return this._def._config.errorFormatter({ ...opts, shape });
|
|
334
300
|
},
|
|
335
301
|
};
|
|
336
|
-
|
|
337
302
|
return router as any;
|
|
338
303
|
};
|
|
339
304
|
}
|
|
@@ -19,9 +19,10 @@ function createInnerProxy(callback: ProxyCallback, path: string[]) {
|
|
|
19
19
|
return createInnerProxy(callback, [...path, key]);
|
|
20
20
|
},
|
|
21
21
|
apply(_1, _2, args) {
|
|
22
|
+
const isApply = path[path.length - 1] === 'apply';
|
|
22
23
|
return callback({
|
|
23
|
-
args,
|
|
24
|
-
path,
|
|
24
|
+
args: isApply ? (args.length >= 2 ? args[1] : []) : args,
|
|
25
|
+
path: isApply ? path.slice(0, -1) : path,
|
|
25
26
|
});
|
|
26
27
|
},
|
|
27
28
|
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { getPostBody } from './getPostBody';
|
|
3
|
-
|
|
4
|
-
test('has body', async () => {
|
|
5
|
-
const body = {};
|
|
6
|
-
const resolvedBody = await getPostBody({
|
|
7
|
-
req: {
|
|
8
|
-
body,
|
|
9
|
-
headers: {
|
|
10
|
-
'content-type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
} as any);
|
|
14
|
-
expect(resolvedBody).toMatchInlineSnapshot(`
|
|
15
|
-
Object {
|
|
16
|
-
"data": Object {},
|
|
17
|
-
"ok": true,
|
|
18
|
-
"preprocessed": true,
|
|
19
|
-
}
|
|
20
|
-
`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('req as eventemitter', async () => {
|
|
24
|
-
const events = new EventEmitter();
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
events.emit(
|
|
27
|
-
'data',
|
|
28
|
-
JSON.stringify({
|
|
29
|
-
hello: 'there',
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
events.emit('end');
|
|
33
|
-
}, 5);
|
|
34
|
-
|
|
35
|
-
(events as any).headers = {};
|
|
36
|
-
const result = await getPostBody({
|
|
37
|
-
req: events,
|
|
38
|
-
} as any);
|
|
39
|
-
|
|
40
|
-
expect(result.ok).toBeTruthy();
|
|
41
|
-
expect((result as any).data).toBeTruthy();
|
|
42
|
-
expect(result).toMatchInlineSnapshot(`
|
|
43
|
-
Object {
|
|
44
|
-
"data": "{\\"hello\\":\\"there\\"}",
|
|
45
|
-
"ok": true,
|
|
46
|
-
"preprocessed": false,
|
|
47
|
-
}
|
|
48
|
-
`);
|
|
49
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { observable, share, tap } from '.';
|
|
2
|
-
|
|
3
|
-
test('vanilla observable - complete()', () => {
|
|
4
|
-
const obs = observable<number, Error>((observer) => {
|
|
5
|
-
observer.next(1);
|
|
6
|
-
observer.complete();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const next = vi.fn();
|
|
10
|
-
const error = vi.fn();
|
|
11
|
-
const complete = vi.fn();
|
|
12
|
-
obs.subscribe({
|
|
13
|
-
next,
|
|
14
|
-
error,
|
|
15
|
-
complete,
|
|
16
|
-
});
|
|
17
|
-
expect(next.mock.calls).toHaveLength(1);
|
|
18
|
-
expect(complete.mock.calls).toHaveLength(1);
|
|
19
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
20
|
-
expect(next.mock.calls[0]![0]!).toBe(1);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('vanilla observable - unsubscribe()', () => {
|
|
24
|
-
const obs$ = observable<number, Error>((observer) => {
|
|
25
|
-
observer.next(1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const next = vi.fn();
|
|
29
|
-
const error = vi.fn();
|
|
30
|
-
const complete = vi.fn();
|
|
31
|
-
const sub = obs$.subscribe({
|
|
32
|
-
next,
|
|
33
|
-
error,
|
|
34
|
-
complete,
|
|
35
|
-
});
|
|
36
|
-
sub.unsubscribe();
|
|
37
|
-
expect(next.mock.calls).toHaveLength(1);
|
|
38
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
39
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
40
|
-
expect(next.mock.calls[0]![0]!).toBe(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('pipe - combine operators', () => {
|
|
44
|
-
const taps = {
|
|
45
|
-
next: vi.fn(),
|
|
46
|
-
complete: vi.fn(),
|
|
47
|
-
error: vi.fn(),
|
|
48
|
-
};
|
|
49
|
-
const obs = observable<number, Error>((observer) => {
|
|
50
|
-
observer.next(1);
|
|
51
|
-
}).pipe(
|
|
52
|
-
// operators:
|
|
53
|
-
share(),
|
|
54
|
-
tap(taps),
|
|
55
|
-
);
|
|
56
|
-
{
|
|
57
|
-
const next = vi.fn();
|
|
58
|
-
const error = vi.fn();
|
|
59
|
-
const complete = vi.fn();
|
|
60
|
-
obs.subscribe({
|
|
61
|
-
next,
|
|
62
|
-
error,
|
|
63
|
-
complete,
|
|
64
|
-
});
|
|
65
|
-
expect(next.mock.calls).toHaveLength(1);
|
|
66
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
67
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
68
|
-
expect(next.mock.calls[0]![0]!).toBe(1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
const next = vi.fn();
|
|
73
|
-
const error = vi.fn();
|
|
74
|
-
const complete = vi.fn();
|
|
75
|
-
obs.subscribe({
|
|
76
|
-
next,
|
|
77
|
-
error,
|
|
78
|
-
complete,
|
|
79
|
-
});
|
|
80
|
-
expect(next.mock.calls).toHaveLength(0);
|
|
81
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
82
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
expect({
|
|
86
|
-
next: taps.next.mock.calls,
|
|
87
|
-
error: taps.error.mock.calls,
|
|
88
|
-
complete: taps.complete.mock.calls,
|
|
89
|
-
}).toMatchInlineSnapshot(`
|
|
90
|
-
Object {
|
|
91
|
-
"complete": Array [],
|
|
92
|
-
"error": Array [],
|
|
93
|
-
"next": Array [
|
|
94
|
-
Array [
|
|
95
|
-
1,
|
|
96
|
-
],
|
|
97
|
-
],
|
|
98
|
-
}
|
|
99
|
-
`);
|
|
100
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { map } from '.';
|
|
3
|
-
import { observable } from '../observable';
|
|
4
|
-
|
|
5
|
-
interface SubscriptionEvents<TOutput> {
|
|
6
|
-
data: (data: TOutput) => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare interface CustomEventEmitter<TOutput> {
|
|
10
|
-
on<U extends keyof SubscriptionEvents<TOutput>>(
|
|
11
|
-
event: U,
|
|
12
|
-
listener: SubscriptionEvents<TOutput>[U],
|
|
13
|
-
): this;
|
|
14
|
-
|
|
15
|
-
once<U extends keyof SubscriptionEvents<TOutput>>(
|
|
16
|
-
event: U,
|
|
17
|
-
listener: SubscriptionEvents<TOutput>[U],
|
|
18
|
-
): this;
|
|
19
|
-
|
|
20
|
-
emit<U extends keyof SubscriptionEvents<TOutput>>(
|
|
21
|
-
event: U,
|
|
22
|
-
...args: Parameters<SubscriptionEvents<TOutput>[U]>
|
|
23
|
-
): boolean;
|
|
24
|
-
}
|
|
25
|
-
class CustomEventEmitter<TOutput>
|
|
26
|
-
extends EventEmitter
|
|
27
|
-
implements CustomEventEmitter<TOutput> {}
|
|
28
|
-
test('map', () => {
|
|
29
|
-
type EventShape = { num: number };
|
|
30
|
-
const ee = new CustomEventEmitter<EventShape>();
|
|
31
|
-
const eventObservable = observable<EventShape, unknown>((observer) => {
|
|
32
|
-
const callback = (data: EventShape) => {
|
|
33
|
-
observer.next(data);
|
|
34
|
-
};
|
|
35
|
-
ee.on('data', callback);
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
ee.off('data', callback);
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
const pipeCalls = vi.fn();
|
|
42
|
-
const piped = eventObservable.pipe(
|
|
43
|
-
map((...args) => {
|
|
44
|
-
pipeCalls(...args);
|
|
45
|
-
const [value] = args;
|
|
46
|
-
return value.num;
|
|
47
|
-
}),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const next = vi.fn();
|
|
51
|
-
const subscription = piped.subscribe({
|
|
52
|
-
next(value) {
|
|
53
|
-
expectTypeOf<number>(value);
|
|
54
|
-
next(value);
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
expect(next).not.toHaveBeenCalled();
|
|
58
|
-
ee.emit('data', { num: 1 });
|
|
59
|
-
ee.emit('data', { num: 2 });
|
|
60
|
-
expect(next).toHaveBeenCalledTimes(2);
|
|
61
|
-
expect(next.mock.calls).toMatchInlineSnapshot(`
|
|
62
|
-
Array [
|
|
63
|
-
Array [
|
|
64
|
-
1,
|
|
65
|
-
],
|
|
66
|
-
Array [
|
|
67
|
-
2,
|
|
68
|
-
],
|
|
69
|
-
]
|
|
70
|
-
`);
|
|
71
|
-
expect(pipeCalls.mock.calls).toMatchInlineSnapshot(`
|
|
72
|
-
Array [
|
|
73
|
-
Array [
|
|
74
|
-
Object {
|
|
75
|
-
"num": 1,
|
|
76
|
-
},
|
|
77
|
-
0,
|
|
78
|
-
],
|
|
79
|
-
Array [
|
|
80
|
-
Object {
|
|
81
|
-
"num": 2,
|
|
82
|
-
},
|
|
83
|
-
1,
|
|
84
|
-
],
|
|
85
|
-
]
|
|
86
|
-
`);
|
|
87
|
-
|
|
88
|
-
expect(ee.listeners('data')).toHaveLength(1);
|
|
89
|
-
subscription.unsubscribe();
|
|
90
|
-
expect(ee.listeners('data')).toHaveLength(0);
|
|
91
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-var */
|
|
2
|
-
import { observable } from '../observable';
|
|
3
|
-
import { share } from './share';
|
|
4
|
-
|
|
5
|
-
test('share', () => {
|
|
6
|
-
const obs = share()(
|
|
7
|
-
observable<number, Error>((observer) => {
|
|
8
|
-
observer.next(1);
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
const next = vi.fn();
|
|
14
|
-
const error = vi.fn();
|
|
15
|
-
const complete = vi.fn();
|
|
16
|
-
var subscription1 = obs.subscribe({
|
|
17
|
-
next,
|
|
18
|
-
error,
|
|
19
|
-
complete,
|
|
20
|
-
});
|
|
21
|
-
expect(next.mock.calls).toHaveLength(1);
|
|
22
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
23
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
24
|
-
expect(next.mock.calls[0]![0]!).toBe(1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
// subscribe again - it's shared so should not propagate any results
|
|
29
|
-
const next = vi.fn();
|
|
30
|
-
const error = vi.fn();
|
|
31
|
-
const complete = vi.fn();
|
|
32
|
-
var subscription2 = obs.subscribe({
|
|
33
|
-
next,
|
|
34
|
-
error,
|
|
35
|
-
complete,
|
|
36
|
-
});
|
|
37
|
-
expect(next.mock.calls).toHaveLength(0);
|
|
38
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
39
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
subscription1.unsubscribe();
|
|
43
|
-
subscription2.unsubscribe();
|
|
44
|
-
// now it should be reset so we can do a new subscription
|
|
45
|
-
{
|
|
46
|
-
const next = vi.fn();
|
|
47
|
-
const error = vi.fn();
|
|
48
|
-
const complete = vi.fn();
|
|
49
|
-
var subscription3 = obs.subscribe({
|
|
50
|
-
next,
|
|
51
|
-
error,
|
|
52
|
-
complete,
|
|
53
|
-
});
|
|
54
|
-
expect(next.mock.calls).toHaveLength(1);
|
|
55
|
-
expect(complete.mock.calls).toHaveLength(0);
|
|
56
|
-
expect(error.mock.calls).toHaveLength(0);
|
|
57
|
-
expect(next.mock.calls[0]![0]!).toBe(1);
|
|
58
|
-
subscription3.unsubscribe();
|
|
59
|
-
}
|
|
60
|
-
});
|