@trpc/client 10.0.0-alpha.4 → 10.0.0-alpha.8
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/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals/dataLoader.d.ts +3 -1
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +4 -1
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +11 -5
- package/dist/links/httpBatchLink.mjs +11 -5
- package/dist/links/wsLink.js +4 -3
- package/dist/links/wsLink.mjs +3 -3
- package/package.json +4 -4
- package/src/internals/dataLoader.ts +13 -1
- package/src/links/httpBatchLink.ts +9 -3
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ var ObservableAbortError = /*#__PURE__*/function (_Error) {
|
|
|
94
94
|
return _this;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
return ObservableAbortError;
|
|
97
|
+
return _createClass__default["default"](ObservableAbortError);
|
|
98
98
|
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
99
99
|
/** @internal */
|
|
100
100
|
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,9 @@ declare type BatchLoadFn<TKey, TValue> = (keys: TKey[]) => {
|
|
|
8
8
|
* Less configuration, no caching, and allows you to cancel requests
|
|
9
9
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
10
10
|
*/
|
|
11
|
-
export declare function dataLoader<TKey, TValue>(fetchMany: BatchLoadFn<TKey, TValue
|
|
11
|
+
export declare function dataLoader<TKey, TValue>(fetchMany: BatchLoadFn<TKey, TValue>, opts?: {
|
|
12
|
+
maxBatchSize?: number;
|
|
13
|
+
}): {
|
|
12
14
|
load: (key: TKey) => PromiseAndCancel<TValue>;
|
|
13
15
|
};
|
|
14
16
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAY5D,aAAK,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK;IACjD,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3B,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAY5D,aAAK,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK;IACjD,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3B,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,SAAS,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EACpC,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE;gBA8Bb,IAAI,KAAG,iBAAiB,MAAM,CAAC;EAiDnD"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCLink } from './types';
|
|
3
3
|
import { HTTPLinkOptions } from './httpUtils';
|
|
4
|
-
export
|
|
4
|
+
export interface HttpBatchLinkOptions extends HTTPLinkOptions {
|
|
5
|
+
maxBatchSize?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function httpBatchLink<TRouter extends AnyRouter>(opts: HttpBatchLinkOptions): TRPCLink<TRouter>;
|
|
5
8
|
//# sourceMappingURL=httpBatchLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAE1E,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAE1E,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AACD,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,GACzB,QAAQ,CAAC,OAAO,CAAC,CA+DnB"}
|
|
@@ -17,7 +17,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
17
17
|
* Less configuration, no caching, and allows you to cancel requests
|
|
18
18
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
19
19
|
*/
|
|
20
|
-
function dataLoader(fetchMany) {
|
|
20
|
+
function dataLoader(fetchMany, opts) {
|
|
21
21
|
var batch = null;
|
|
22
22
|
var dispatchTimer = null;
|
|
23
23
|
|
|
@@ -82,6 +82,11 @@ function dataLoader(fetchMany) {
|
|
|
82
82
|
item.reject = reject;
|
|
83
83
|
item.resolve = resolve;
|
|
84
84
|
thisBatch.items.push(item);
|
|
85
|
+
|
|
86
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
87
|
+
dispatch();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
85
90
|
});
|
|
86
91
|
|
|
87
92
|
if (!dispatchTimer) {
|
|
@@ -113,7 +118,8 @@ function dataLoader(fetchMany) {
|
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
function httpBatchLink(opts) {
|
|
116
|
-
var url = opts.url;
|
|
121
|
+
var url = opts.url; // initialized config
|
|
122
|
+
|
|
117
123
|
return function (runtime) {
|
|
118
124
|
var fetcher = function fetcher(type) {
|
|
119
125
|
return function (keyInputPairs) {
|
|
@@ -152,9 +158,9 @@ function httpBatchLink(opts) {
|
|
|
152
158
|
};
|
|
153
159
|
};
|
|
154
160
|
|
|
155
|
-
var query = dataLoader(fetcher('query'));
|
|
156
|
-
var mutation = dataLoader(fetcher('mutation'));
|
|
157
|
-
var subscription = dataLoader(fetcher('subscription'));
|
|
161
|
+
var query = dataLoader(fetcher('query'), opts);
|
|
162
|
+
var mutation = dataLoader(fetcher('mutation'), opts);
|
|
163
|
+
var subscription = dataLoader(fetcher('subscription'), opts);
|
|
158
164
|
var loaders = {
|
|
159
165
|
query: query,
|
|
160
166
|
subscription: subscription,
|
|
@@ -13,7 +13,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
13
13
|
* Less configuration, no caching, and allows you to cancel requests
|
|
14
14
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
15
15
|
*/
|
|
16
|
-
function dataLoader(fetchMany) {
|
|
16
|
+
function dataLoader(fetchMany, opts) {
|
|
17
17
|
var batch = null;
|
|
18
18
|
var dispatchTimer = null;
|
|
19
19
|
|
|
@@ -78,6 +78,11 @@ function dataLoader(fetchMany) {
|
|
|
78
78
|
item.reject = reject;
|
|
79
79
|
item.resolve = resolve;
|
|
80
80
|
thisBatch.items.push(item);
|
|
81
|
+
|
|
82
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
83
|
+
dispatch();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
81
86
|
});
|
|
82
87
|
|
|
83
88
|
if (!dispatchTimer) {
|
|
@@ -109,7 +114,8 @@ function dataLoader(fetchMany) {
|
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
function httpBatchLink(opts) {
|
|
112
|
-
var url = opts.url;
|
|
117
|
+
var url = opts.url; // initialized config
|
|
118
|
+
|
|
113
119
|
return function (runtime) {
|
|
114
120
|
var fetcher = function fetcher(type) {
|
|
115
121
|
return function (keyInputPairs) {
|
|
@@ -148,9 +154,9 @@ function httpBatchLink(opts) {
|
|
|
148
154
|
};
|
|
149
155
|
};
|
|
150
156
|
|
|
151
|
-
var query = dataLoader(fetcher('query'));
|
|
152
|
-
var mutation = dataLoader(fetcher('mutation'));
|
|
153
|
-
var subscription = dataLoader(fetcher('subscription'));
|
|
157
|
+
var query = dataLoader(fetcher('query'), opts);
|
|
158
|
+
var mutation = dataLoader(fetcher('mutation'), opts);
|
|
159
|
+
var subscription = dataLoader(fetcher('subscription'), opts);
|
|
154
160
|
var loaders = {
|
|
155
161
|
query: query,
|
|
156
162
|
subscription: subscription,
|
package/dist/links/wsLink.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
5
6
|
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
6
7
|
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
7
8
|
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
@@ -11,10 +12,10 @@ var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
|
11
12
|
var observable = require('../observable-85669100.js');
|
|
12
13
|
var TRPCClientError = require('../TRPCClientError-ec6bd2ca.js');
|
|
13
14
|
require('@babel/runtime/helpers/defineProperty');
|
|
14
|
-
require('@babel/runtime/helpers/createClass');
|
|
15
15
|
|
|
16
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
17
|
|
|
18
|
+
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
18
19
|
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
19
20
|
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
20
21
|
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
@@ -306,7 +307,7 @@ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
|
|
|
306
307
|
return _this;
|
|
307
308
|
}
|
|
308
309
|
|
|
309
|
-
return TRPCWebSocketClosedError;
|
|
310
|
+
return _createClass__default["default"](TRPCWebSocketClosedError);
|
|
310
311
|
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
311
312
|
|
|
312
313
|
var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
@@ -325,7 +326,7 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
|
325
326
|
return _this2;
|
|
326
327
|
}
|
|
327
328
|
|
|
328
|
-
return TRPCSubscriptionEndedError;
|
|
329
|
+
return _createClass__default["default"](TRPCSubscriptionEndedError);
|
|
329
330
|
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
330
331
|
|
|
331
332
|
function wsLink(opts) {
|
package/dist/links/wsLink.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
1
2
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
3
|
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
3
4
|
import _inherits from '@babel/runtime/helpers/inherits';
|
|
@@ -7,7 +8,6 @@ import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
|
7
8
|
import { o as observable } from '../observable-7e66cb56.mjs';
|
|
8
9
|
import { T as TRPCClientError } from '../TRPCClientError-17b117e1.mjs';
|
|
9
10
|
import '@babel/runtime/helpers/defineProperty';
|
|
10
|
-
import '@babel/runtime/helpers/createClass';
|
|
11
11
|
|
|
12
12
|
/* istanbul ignore next */
|
|
13
13
|
var retryDelay = function retryDelay(attemptIndex) {
|
|
@@ -293,7 +293,7 @@ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
|
|
|
293
293
|
return _this;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
return TRPCWebSocketClosedError;
|
|
296
|
+
return _createClass(TRPCWebSocketClosedError);
|
|
297
297
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
298
298
|
|
|
299
299
|
var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
@@ -312,7 +312,7 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
|
312
312
|
return _this2;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
return TRPCSubscriptionEndedError;
|
|
315
|
+
return _createClass(TRPCSubscriptionEndedError);
|
|
316
316
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
317
317
|
|
|
318
318
|
function wsLink(opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.8",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"@babel/runtime": "^7.9.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@trpc/server": "10.0.0-alpha.
|
|
77
|
+
"@trpc/server": "10.0.0-alpha.8"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@trpc/server": "10.0.0-alpha.
|
|
80
|
+
"@trpc/server": "10.0.0-alpha.8"
|
|
81
81
|
},
|
|
82
82
|
"publishConfig": {
|
|
83
83
|
"access": "public"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "e5ded22d38809f6de68df26ed069ca3cf93bb368"
|
|
86
86
|
}
|
|
@@ -20,7 +20,10 @@ type BatchLoadFn<TKey, TValue> = (keys: TKey[]) => {
|
|
|
20
20
|
* Less configuration, no caching, and allows you to cancel requests
|
|
21
21
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
22
22
|
*/
|
|
23
|
-
export function dataLoader<TKey, TValue>(
|
|
23
|
+
export function dataLoader<TKey, TValue>(
|
|
24
|
+
fetchMany: BatchLoadFn<TKey, TValue>,
|
|
25
|
+
opts?: { maxBatchSize?: number },
|
|
26
|
+
) {
|
|
24
27
|
let batch: Batch<TKey, TValue> | null = null;
|
|
25
28
|
let dispatchTimer: NodeJS.Timer | number | null = null;
|
|
26
29
|
|
|
@@ -69,7 +72,16 @@ export function dataLoader<TKey, TValue>(fetchMany: BatchLoadFn<TKey, TValue>) {
|
|
|
69
72
|
item.reject = reject;
|
|
70
73
|
item.resolve = resolve;
|
|
71
74
|
thisBatch.items.push(item);
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
typeof opts?.maxBatchSize !== 'undefined' &&
|
|
78
|
+
thisBatch.items.length >= opts.maxBatchSize
|
|
79
|
+
) {
|
|
80
|
+
dispatch();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
72
83
|
});
|
|
84
|
+
|
|
73
85
|
if (!dispatchTimer) {
|
|
74
86
|
dispatchTimer = setTimeout(dispatch);
|
|
75
87
|
}
|
|
@@ -4,12 +4,17 @@ import { observable } from '../rx/observable';
|
|
|
4
4
|
import { TRPCLink } from './types';
|
|
5
5
|
import { HTTPLinkOptions, httpRequest, ResponseShape } from './httpUtils';
|
|
6
6
|
|
|
7
|
+
export interface HttpBatchLinkOptions extends HTTPLinkOptions {
|
|
8
|
+
maxBatchSize?: number;
|
|
9
|
+
}
|
|
7
10
|
export function httpBatchLink<TRouter extends AnyRouter>(
|
|
8
|
-
opts:
|
|
11
|
+
opts: HttpBatchLinkOptions,
|
|
9
12
|
): TRPCLink<TRouter> {
|
|
10
13
|
const { url } = opts;
|
|
14
|
+
// initialized config
|
|
11
15
|
return (runtime) => {
|
|
12
16
|
type Key = { id: number; path: string; input: unknown };
|
|
17
|
+
|
|
13
18
|
const fetcher = (type: ProcedureType) => (keyInputPairs: Key[]) => {
|
|
14
19
|
const path = keyInputPairs.map((op) => op.path).join(',');
|
|
15
20
|
const inputs = keyInputPairs.map((op) => op.input);
|
|
@@ -38,10 +43,11 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
38
43
|
cancel,
|
|
39
44
|
};
|
|
40
45
|
};
|
|
41
|
-
const query = dataLoader<Key, ResponseShape>(fetcher('query'));
|
|
42
|
-
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'));
|
|
46
|
+
const query = dataLoader<Key, ResponseShape>(fetcher('query'), opts);
|
|
47
|
+
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'), opts);
|
|
43
48
|
const subscription = dataLoader<Key, ResponseShape>(
|
|
44
49
|
fetcher('subscription'),
|
|
50
|
+
opts,
|
|
45
51
|
);
|
|
46
52
|
|
|
47
53
|
const loaders = { query, subscription, mutation };
|