@trpc/client 10.0.0-alpha.13 → 10.0.0-alpha.16
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 +972 -35
- package/dist/index.mjs +953 -21
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/observable/index.js +3 -5
- package/dist/observable/index.mjs +1 -3
- package/dist/observable/{util → internals}/identity.d.ts +0 -0
- package/dist/observable/internals/identity.d.ts.map +1 -0
- package/dist/observable/{util → internals}/observableToPromise.d.ts +0 -0
- package/dist/observable/internals/observableToPromise.d.ts.map +1 -0
- package/dist/observable/{util → internals}/pipe.d.ts +0 -0
- package/dist/observable/internals/pipe.d.ts.map +1 -0
- package/dist/{share-9f12d26c.mjs → tap-4bc60fb0.mjs} +131 -1
- package/dist/{share-4afc084f.js → tap-fcd41ae6.js} +132 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +11 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +16 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +11 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +16 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +11 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +16 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +11 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +16 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +11 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +16 -0
- package/package.json +43 -8
- package/src/internals/TRPCClient.ts +1 -1
- package/src/links/wsLink.ts +1 -2
- package/src/observable/{util → internals}/identity.ts +0 -0
- package/src/observable/{util → internals}/observableToPromise.ts +0 -0
- package/src/observable/{util → internals}/pipe.ts +0 -0
- package/src/observable/observable.ts +1 -1
- package/dist/httpUtils-27640b42.js +0 -97
- package/dist/httpUtils-b92552af.mjs +0 -91
- package/dist/links/httpBatchLink.js +0 -195
- package/dist/links/httpBatchLink.mjs +0 -191
- package/dist/links/httpBatchLink.ts.js +0 -1
- package/dist/links/httpLink.js +0 -44
- package/dist/links/httpLink.mjs +0 -40
- package/dist/links/httpLink.ts.js +0 -1
- package/dist/links/loggerLink.js +0 -108
- package/dist/links/loggerLink.mjs +0 -99
- package/dist/links/loggerLink.ts.js +0 -1
- package/dist/links/splitLink.js +0 -10
- package/dist/links/splitLink.mjs +0 -2
- package/dist/links/splitLink.ts.js +0 -1
- package/dist/links/transformerLink.js +0 -79
- package/dist/links/transformerLink.mjs +0 -71
- package/dist/links/transformerLink.ts.js +0 -1
- package/dist/links/wsLink.js +0 -19
- package/dist/links/wsLink.mjs +0 -10
- package/dist/links/wsLink.ts.js +0 -1
- package/dist/observable/util/identity.d.ts.map +0 -1
- package/dist/observable/util/observableToPromise.d.ts.map +0 -1
- package/dist/observable/util/pipe.d.ts.map +0 -1
- package/dist/observable-16fde241.mjs +0 -102
- package/dist/observable-9aaca086.js +0 -104
- package/dist/splitLink-8635d455.js +0 -52
- package/dist/splitLink-a736378a.mjs +0 -49
- package/dist/tap-aacf31bf.js +0 -32
- package/dist/tap-f567ea97.mjs +0 -30
- package/dist/wsLink-a6a0f3a8.mjs +0 -440
- package/dist/wsLink-c9323097.js +0 -455
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
-
|
|
5
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
-
|
|
7
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
8
|
-
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
|
|
11
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
|
|
13
|
-
// https://github.com/trpc/trpc/pull/669
|
|
14
|
-
function arrayToDict(array) {
|
|
15
|
-
var dict = {};
|
|
16
|
-
|
|
17
|
-
for (var index = 0; index < array.length; index++) {
|
|
18
|
-
var element = array[index];
|
|
19
|
-
dict[index] = element;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return dict;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var METHOD = {
|
|
26
|
-
query: 'GET',
|
|
27
|
-
mutation: 'POST',
|
|
28
|
-
subscription: 'PATCH'
|
|
29
|
-
};
|
|
30
|
-
function httpRequest(props) {
|
|
31
|
-
var type = props.type,
|
|
32
|
-
rt = props.runtime,
|
|
33
|
-
path = props.path;
|
|
34
|
-
var ac = rt.AbortController ? new rt.AbortController() : null;
|
|
35
|
-
var input = 'input' in props ? props.input : arrayToDict(props.inputs);
|
|
36
|
-
|
|
37
|
-
function getUrl() {
|
|
38
|
-
var url = props.url + '/' + path;
|
|
39
|
-
var queryParts = [];
|
|
40
|
-
|
|
41
|
-
if ('inputs' in props) {
|
|
42
|
-
queryParts.push('batch=1');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (type === 'query' && input !== undefined) {
|
|
46
|
-
queryParts.push("input=".concat(encodeURIComponent(JSON.stringify(input))));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (queryParts.length) {
|
|
50
|
-
url += '?' + queryParts.join('&');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return url;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getBody() {
|
|
57
|
-
if (type === 'query') {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
var promise = new Promise(function (resolve, reject) {
|
|
65
|
-
var url = getUrl();
|
|
66
|
-
var meta = {};
|
|
67
|
-
Promise.resolve(rt.headers()).then(function (headers) {
|
|
68
|
-
return rt.fetch(url, {
|
|
69
|
-
method: METHOD[type],
|
|
70
|
-
signal: ac === null || ac === void 0 ? void 0 : ac.signal,
|
|
71
|
-
body: getBody(),
|
|
72
|
-
headers: _objectSpread({
|
|
73
|
-
'content-type': 'application/json'
|
|
74
|
-
}, headers)
|
|
75
|
-
});
|
|
76
|
-
}).then(function (_res) {
|
|
77
|
-
meta.response = _res;
|
|
78
|
-
return _res.json();
|
|
79
|
-
}).then(function (json) {
|
|
80
|
-
resolve({
|
|
81
|
-
json: json,
|
|
82
|
-
meta: meta
|
|
83
|
-
});
|
|
84
|
-
}).catch(reject);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
var cancel = function cancel() {
|
|
88
|
-
ac === null || ac === void 0 ? void 0 : ac.abort();
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
promise: promise,
|
|
93
|
-
cancel: cancel
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.httpRequest = httpRequest;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
// https://github.com/trpc/trpc/pull/669
|
|
8
|
-
function arrayToDict(array) {
|
|
9
|
-
var dict = {};
|
|
10
|
-
|
|
11
|
-
for (var index = 0; index < array.length; index++) {
|
|
12
|
-
var element = array[index];
|
|
13
|
-
dict[index] = element;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return dict;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var METHOD = {
|
|
20
|
-
query: 'GET',
|
|
21
|
-
mutation: 'POST',
|
|
22
|
-
subscription: 'PATCH'
|
|
23
|
-
};
|
|
24
|
-
function httpRequest(props) {
|
|
25
|
-
var type = props.type,
|
|
26
|
-
rt = props.runtime,
|
|
27
|
-
path = props.path;
|
|
28
|
-
var ac = rt.AbortController ? new rt.AbortController() : null;
|
|
29
|
-
var input = 'input' in props ? props.input : arrayToDict(props.inputs);
|
|
30
|
-
|
|
31
|
-
function getUrl() {
|
|
32
|
-
var url = props.url + '/' + path;
|
|
33
|
-
var queryParts = [];
|
|
34
|
-
|
|
35
|
-
if ('inputs' in props) {
|
|
36
|
-
queryParts.push('batch=1');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (type === 'query' && input !== undefined) {
|
|
40
|
-
queryParts.push("input=".concat(encodeURIComponent(JSON.stringify(input))));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (queryParts.length) {
|
|
44
|
-
url += '?' + queryParts.join('&');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return url;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getBody() {
|
|
51
|
-
if (type === 'query') {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var promise = new Promise(function (resolve, reject) {
|
|
59
|
-
var url = getUrl();
|
|
60
|
-
var meta = {};
|
|
61
|
-
Promise.resolve(rt.headers()).then(function (headers) {
|
|
62
|
-
return rt.fetch(url, {
|
|
63
|
-
method: METHOD[type],
|
|
64
|
-
signal: ac === null || ac === void 0 ? void 0 : ac.signal,
|
|
65
|
-
body: getBody(),
|
|
66
|
-
headers: _objectSpread({
|
|
67
|
-
'content-type': 'application/json'
|
|
68
|
-
}, headers)
|
|
69
|
-
});
|
|
70
|
-
}).then(function (_res) {
|
|
71
|
-
meta.response = _res;
|
|
72
|
-
return _res.json();
|
|
73
|
-
}).then(function (json) {
|
|
74
|
-
resolve({
|
|
75
|
-
json: json,
|
|
76
|
-
meta: meta
|
|
77
|
-
});
|
|
78
|
-
}).catch(reject);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
var cancel = function cancel() {
|
|
82
|
-
ac === null || ac === void 0 ? void 0 : ac.abort();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
promise: promise,
|
|
87
|
-
cancel: cancel
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { httpRequest as h };
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var observable = require('../observable-9aaca086.js');
|
|
6
|
-
var httpUtils = require('../httpUtils-27640b42.js');
|
|
7
|
-
require('@babel/runtime/helpers/defineProperty');
|
|
8
|
-
|
|
9
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
|
-
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
17
|
-
* Less configuration, no caching, and allows you to cancel requests
|
|
18
|
-
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
19
|
-
*/
|
|
20
|
-
function dataLoader(fetchMany, opts) {
|
|
21
|
-
var batch = null;
|
|
22
|
-
var dispatchTimer = null;
|
|
23
|
-
|
|
24
|
-
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
25
|
-
clearTimeout(dispatchTimer);
|
|
26
|
-
dispatchTimer = null;
|
|
27
|
-
batch = null;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function dispatch() {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
32
|
-
var batchCopy = batch;
|
|
33
|
-
destroyTimerAndBatch();
|
|
34
|
-
|
|
35
|
-
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
36
|
-
return v.key;
|
|
37
|
-
})),
|
|
38
|
-
promise = _fetchMany.promise,
|
|
39
|
-
cancel = _fetchMany.cancel;
|
|
40
|
-
|
|
41
|
-
batchCopy.cancel = cancel;
|
|
42
|
-
promise.then(function (result) {
|
|
43
|
-
for (var i = 0; i < result.length; i++) {
|
|
44
|
-
var _value = result[i];
|
|
45
|
-
batchCopy.items[i].resolve(_value);
|
|
46
|
-
}
|
|
47
|
-
}).catch(function (cause) {
|
|
48
|
-
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
49
|
-
_step;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
-
var item = _step.value;
|
|
54
|
-
item.reject(cause);
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
_iterator.e(err);
|
|
58
|
-
} finally {
|
|
59
|
-
_iterator.f();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function load(key) {
|
|
65
|
-
var batchItem = {
|
|
66
|
-
cancelled: false,
|
|
67
|
-
key: key
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
if (!batch) {
|
|
71
|
-
batch = {
|
|
72
|
-
items: [],
|
|
73
|
-
cancel: function cancel() {
|
|
74
|
-
destroyTimerAndBatch();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var thisBatch = batch;
|
|
80
|
-
var promise = new Promise(function (resolve, reject) {
|
|
81
|
-
var item = batchItem;
|
|
82
|
-
item.reject = reject;
|
|
83
|
-
item.resolve = resolve;
|
|
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
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (!dispatchTimer) {
|
|
93
|
-
dispatchTimer = setTimeout(dispatch);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var cancel = function cancel() {
|
|
97
|
-
batchItem.cancelled = true;
|
|
98
|
-
|
|
99
|
-
if (thisBatch.items.some(function (item) {
|
|
100
|
-
return !item.cancelled;
|
|
101
|
-
})) {
|
|
102
|
-
// there are still things that can be resolved
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
thisBatch.cancel();
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
promise: promise,
|
|
111
|
-
cancel: cancel
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
load: load
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function httpBatchLink(opts) {
|
|
121
|
-
var url = opts.url; // initialized config
|
|
122
|
-
|
|
123
|
-
return function (runtime) {
|
|
124
|
-
var fetcher = function fetcher(type) {
|
|
125
|
-
return function (keyInputPairs) {
|
|
126
|
-
var path = keyInputPairs.map(function (op) {
|
|
127
|
-
return op.path;
|
|
128
|
-
}).join(',');
|
|
129
|
-
var inputs = keyInputPairs.map(function (op) {
|
|
130
|
-
return op.input;
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
var _httpRequest = httpUtils.httpRequest({
|
|
134
|
-
url: url,
|
|
135
|
-
inputs: inputs,
|
|
136
|
-
path: path,
|
|
137
|
-
runtime: runtime,
|
|
138
|
-
type: type
|
|
139
|
-
}),
|
|
140
|
-
promise = _httpRequest.promise,
|
|
141
|
-
cancel = _httpRequest.cancel;
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
promise: promise.then(function (res) {
|
|
145
|
-
var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
|
|
146
|
-
return res.json;
|
|
147
|
-
});
|
|
148
|
-
var result = resJSON.map(function (item) {
|
|
149
|
-
return {
|
|
150
|
-
meta: res.meta,
|
|
151
|
-
json: item
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
return result;
|
|
155
|
-
}),
|
|
156
|
-
cancel: cancel
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
var query = dataLoader(fetcher('query'), opts);
|
|
162
|
-
var mutation = dataLoader(fetcher('mutation'), opts);
|
|
163
|
-
var subscription = dataLoader(fetcher('subscription'), opts);
|
|
164
|
-
var loaders = {
|
|
165
|
-
query: query,
|
|
166
|
-
subscription: subscription,
|
|
167
|
-
mutation: mutation
|
|
168
|
-
};
|
|
169
|
-
return function (_ref) {
|
|
170
|
-
var op = _ref.op;
|
|
171
|
-
return observable.observable(function (observer) {
|
|
172
|
-
var loader = loaders[op.type];
|
|
173
|
-
|
|
174
|
-
var _loader$load = loader.load(op),
|
|
175
|
-
promise = _loader$load.promise,
|
|
176
|
-
cancel = _loader$load.cancel;
|
|
177
|
-
|
|
178
|
-
promise.then(function (res) {
|
|
179
|
-
observer.next({
|
|
180
|
-
context: res.meta,
|
|
181
|
-
data: res.json
|
|
182
|
-
});
|
|
183
|
-
observer.complete();
|
|
184
|
-
}).catch(function (err) {
|
|
185
|
-
return observer.error(err);
|
|
186
|
-
});
|
|
187
|
-
return function () {
|
|
188
|
-
cancel();
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
exports.httpBatchLink = httpBatchLink;
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { o as observable } from '../observable-16fde241.mjs';
|
|
2
|
-
import { h as httpRequest } from '../httpUtils-b92552af.mjs';
|
|
3
|
-
import '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
|
|
5
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
13
|
-
* Less configuration, no caching, and allows you to cancel requests
|
|
14
|
-
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
15
|
-
*/
|
|
16
|
-
function dataLoader(fetchMany, opts) {
|
|
17
|
-
var batch = null;
|
|
18
|
-
var dispatchTimer = null;
|
|
19
|
-
|
|
20
|
-
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
21
|
-
clearTimeout(dispatchTimer);
|
|
22
|
-
dispatchTimer = null;
|
|
23
|
-
batch = null;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function dispatch() {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
|
-
var batchCopy = batch;
|
|
29
|
-
destroyTimerAndBatch();
|
|
30
|
-
|
|
31
|
-
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
32
|
-
return v.key;
|
|
33
|
-
})),
|
|
34
|
-
promise = _fetchMany.promise,
|
|
35
|
-
cancel = _fetchMany.cancel;
|
|
36
|
-
|
|
37
|
-
batchCopy.cancel = cancel;
|
|
38
|
-
promise.then(function (result) {
|
|
39
|
-
for (var i = 0; i < result.length; i++) {
|
|
40
|
-
var _value = result[i];
|
|
41
|
-
batchCopy.items[i].resolve(_value);
|
|
42
|
-
}
|
|
43
|
-
}).catch(function (cause) {
|
|
44
|
-
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
45
|
-
_step;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
49
|
-
var item = _step.value;
|
|
50
|
-
item.reject(cause);
|
|
51
|
-
}
|
|
52
|
-
} catch (err) {
|
|
53
|
-
_iterator.e(err);
|
|
54
|
-
} finally {
|
|
55
|
-
_iterator.f();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function load(key) {
|
|
61
|
-
var batchItem = {
|
|
62
|
-
cancelled: false,
|
|
63
|
-
key: key
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
if (!batch) {
|
|
67
|
-
batch = {
|
|
68
|
-
items: [],
|
|
69
|
-
cancel: function cancel() {
|
|
70
|
-
destroyTimerAndBatch();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var thisBatch = batch;
|
|
76
|
-
var promise = new Promise(function (resolve, reject) {
|
|
77
|
-
var item = batchItem;
|
|
78
|
-
item.reject = reject;
|
|
79
|
-
item.resolve = resolve;
|
|
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
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!dispatchTimer) {
|
|
89
|
-
dispatchTimer = setTimeout(dispatch);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
var cancel = function cancel() {
|
|
93
|
-
batchItem.cancelled = true;
|
|
94
|
-
|
|
95
|
-
if (thisBatch.items.some(function (item) {
|
|
96
|
-
return !item.cancelled;
|
|
97
|
-
})) {
|
|
98
|
-
// there are still things that can be resolved
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
thisBatch.cancel();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
promise: promise,
|
|
107
|
-
cancel: cancel
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
load: load
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function httpBatchLink(opts) {
|
|
117
|
-
var url = opts.url; // initialized config
|
|
118
|
-
|
|
119
|
-
return function (runtime) {
|
|
120
|
-
var fetcher = function fetcher(type) {
|
|
121
|
-
return function (keyInputPairs) {
|
|
122
|
-
var path = keyInputPairs.map(function (op) {
|
|
123
|
-
return op.path;
|
|
124
|
-
}).join(',');
|
|
125
|
-
var inputs = keyInputPairs.map(function (op) {
|
|
126
|
-
return op.input;
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
var _httpRequest = httpRequest({
|
|
130
|
-
url: url,
|
|
131
|
-
inputs: inputs,
|
|
132
|
-
path: path,
|
|
133
|
-
runtime: runtime,
|
|
134
|
-
type: type
|
|
135
|
-
}),
|
|
136
|
-
promise = _httpRequest.promise,
|
|
137
|
-
cancel = _httpRequest.cancel;
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
promise: promise.then(function (res) {
|
|
141
|
-
var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
|
|
142
|
-
return res.json;
|
|
143
|
-
});
|
|
144
|
-
var result = resJSON.map(function (item) {
|
|
145
|
-
return {
|
|
146
|
-
meta: res.meta,
|
|
147
|
-
json: item
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
return result;
|
|
151
|
-
}),
|
|
152
|
-
cancel: cancel
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
var query = dataLoader(fetcher('query'), opts);
|
|
158
|
-
var mutation = dataLoader(fetcher('mutation'), opts);
|
|
159
|
-
var subscription = dataLoader(fetcher('subscription'), opts);
|
|
160
|
-
var loaders = {
|
|
161
|
-
query: query,
|
|
162
|
-
subscription: subscription,
|
|
163
|
-
mutation: mutation
|
|
164
|
-
};
|
|
165
|
-
return function (_ref) {
|
|
166
|
-
var op = _ref.op;
|
|
167
|
-
return observable(function (observer) {
|
|
168
|
-
var loader = loaders[op.type];
|
|
169
|
-
|
|
170
|
-
var _loader$load = loader.load(op),
|
|
171
|
-
promise = _loader$load.promise,
|
|
172
|
-
cancel = _loader$load.cancel;
|
|
173
|
-
|
|
174
|
-
promise.then(function (res) {
|
|
175
|
-
observer.next({
|
|
176
|
-
context: res.meta,
|
|
177
|
-
data: res.json
|
|
178
|
-
});
|
|
179
|
-
observer.complete();
|
|
180
|
-
}).catch(function (err) {
|
|
181
|
-
return observer.error(err);
|
|
182
|
-
});
|
|
183
|
-
return function () {
|
|
184
|
-
cancel();
|
|
185
|
-
};
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export { httpBatchLink };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/links/httpLink.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var observable = require('../observable-9aaca086.js');
|
|
6
|
-
var httpUtils = require('../httpUtils-27640b42.js');
|
|
7
|
-
require('@babel/runtime/helpers/defineProperty');
|
|
8
|
-
|
|
9
|
-
function httpLink(opts) {
|
|
10
|
-
var url = opts.url;
|
|
11
|
-
return function (runtime) {
|
|
12
|
-
return function (_ref) {
|
|
13
|
-
var op = _ref.op;
|
|
14
|
-
return observable.observable(function (observer) {
|
|
15
|
-
var path = op.path,
|
|
16
|
-
input = op.input,
|
|
17
|
-
type = op.type;
|
|
18
|
-
|
|
19
|
-
var _httpRequest = httpUtils.httpRequest({
|
|
20
|
-
runtime: runtime,
|
|
21
|
-
path: path,
|
|
22
|
-
input: input,
|
|
23
|
-
type: type,
|
|
24
|
-
url: url
|
|
25
|
-
}),
|
|
26
|
-
promise = _httpRequest.promise,
|
|
27
|
-
cancel = _httpRequest.cancel;
|
|
28
|
-
|
|
29
|
-
promise.then(function (res) {
|
|
30
|
-
observer.next({
|
|
31
|
-
context: res.meta,
|
|
32
|
-
data: res.json
|
|
33
|
-
});
|
|
34
|
-
observer.complete();
|
|
35
|
-
}).catch(observer.error);
|
|
36
|
-
return function () {
|
|
37
|
-
cancel();
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.httpLink = httpLink;
|
package/dist/links/httpLink.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { o as observable } from '../observable-16fde241.mjs';
|
|
2
|
-
import { h as httpRequest } from '../httpUtils-b92552af.mjs';
|
|
3
|
-
import '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
|
|
5
|
-
function httpLink(opts) {
|
|
6
|
-
var url = opts.url;
|
|
7
|
-
return function (runtime) {
|
|
8
|
-
return function (_ref) {
|
|
9
|
-
var op = _ref.op;
|
|
10
|
-
return observable(function (observer) {
|
|
11
|
-
var path = op.path,
|
|
12
|
-
input = op.input,
|
|
13
|
-
type = op.type;
|
|
14
|
-
|
|
15
|
-
var _httpRequest = httpRequest({
|
|
16
|
-
runtime: runtime,
|
|
17
|
-
path: path,
|
|
18
|
-
input: input,
|
|
19
|
-
type: type,
|
|
20
|
-
url: url
|
|
21
|
-
}),
|
|
22
|
-
promise = _httpRequest.promise,
|
|
23
|
-
cancel = _httpRequest.cancel;
|
|
24
|
-
|
|
25
|
-
promise.then(function (res) {
|
|
26
|
-
observer.next({
|
|
27
|
-
context: res.meta,
|
|
28
|
-
data: res.json
|
|
29
|
-
});
|
|
30
|
-
observer.complete();
|
|
31
|
-
}).catch(observer.error);
|
|
32
|
-
return function () {
|
|
33
|
-
cancel();
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { httpLink };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|