@polkadot/rpc-core 6.6.2-10 → 6.6.2-11
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/bundle.cjs +36 -31
- package/bundle.js +22 -50
- package/package.json +5 -5
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
package/bundle.cjs
CHANGED
|
@@ -19,9 +19,9 @@ Object.defineProperty(exports, "packageInfo", {
|
|
|
19
19
|
|
|
20
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _classPrivateFieldGet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldGet"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _classPrivateFieldSet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldSet"));
|
|
25
25
|
|
|
26
26
|
var _rxjs = require("rxjs");
|
|
27
27
|
|
|
@@ -45,9 +45,9 @@ Object.keys(_index).forEach(function (key) {
|
|
|
45
45
|
|
|
46
46
|
var _packageInfo = require("./packageInfo.cjs");
|
|
47
47
|
|
|
48
|
-
function
|
|
48
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
49
49
|
|
|
50
|
-
function
|
|
50
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
51
51
|
|
|
52
52
|
const l = (0, _util.logger)('rpc-core');
|
|
53
53
|
const EMPTY_META = {
|
|
@@ -113,13 +113,13 @@ function isTreatAsHex(key) {
|
|
|
113
113
|
*/
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
var _instanceId = /*#__PURE__*/
|
|
116
|
+
var _instanceId = /*#__PURE__*/new WeakMap();
|
|
117
117
|
|
|
118
|
-
var _registryDefault = /*#__PURE__*/
|
|
118
|
+
var _registryDefault = /*#__PURE__*/new WeakMap();
|
|
119
119
|
|
|
120
|
-
var _getBlockRegistry = /*#__PURE__*/
|
|
120
|
+
var _getBlockRegistry = /*#__PURE__*/new WeakMap();
|
|
121
121
|
|
|
122
|
-
var _storageCache = /*#__PURE__*/
|
|
122
|
+
var _storageCache = /*#__PURE__*/new WeakMap();
|
|
123
123
|
|
|
124
124
|
class RpcCore {
|
|
125
125
|
/**
|
|
@@ -129,29 +129,34 @@ class RpcCore {
|
|
|
129
129
|
*/
|
|
130
130
|
constructor(instanceId, registry, provider) {
|
|
131
131
|
let userRpc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
132
|
-
|
|
132
|
+
|
|
133
|
+
_classPrivateFieldInitSpec(this, _instanceId, {
|
|
133
134
|
writable: true,
|
|
134
135
|
value: void 0
|
|
135
136
|
});
|
|
136
|
-
|
|
137
|
+
|
|
138
|
+
_classPrivateFieldInitSpec(this, _registryDefault, {
|
|
137
139
|
writable: true,
|
|
138
140
|
value: void 0
|
|
139
141
|
});
|
|
140
|
-
|
|
142
|
+
|
|
143
|
+
_classPrivateFieldInitSpec(this, _getBlockRegistry, {
|
|
141
144
|
writable: true,
|
|
142
145
|
value: void 0
|
|
143
146
|
});
|
|
144
|
-
|
|
147
|
+
|
|
148
|
+
_classPrivateFieldInitSpec(this, _storageCache, {
|
|
145
149
|
writable: true,
|
|
146
150
|
value: new Map()
|
|
147
151
|
});
|
|
148
|
-
|
|
149
|
-
this
|
|
150
|
-
this
|
|
152
|
+
|
|
153
|
+
(0, _defineProperty2.default)(this, "mapping", new Map());
|
|
154
|
+
(0, _defineProperty2.default)(this, "provider", void 0);
|
|
155
|
+
(0, _defineProperty2.default)(this, "sections", []);
|
|
151
156
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
152
157
|
(0, _util.assert)(provider && (0, _util.isFunction)(provider.send), 'Expected Provider to API create');
|
|
153
|
-
(0,
|
|
154
|
-
(0,
|
|
158
|
+
(0, _classPrivateFieldSet2.default)(this, _instanceId, instanceId);
|
|
159
|
+
(0, _classPrivateFieldSet2.default)(this, _registryDefault, registry);
|
|
155
160
|
this.provider = provider;
|
|
156
161
|
const sectionNames = Object.keys(_types.rpcDefinitions); // these are the base keys (i.e. part of jsonrpc)
|
|
157
162
|
|
|
@@ -189,9 +194,9 @@ class RpcCore {
|
|
|
189
194
|
|
|
190
195
|
|
|
191
196
|
setRegistrySwap(registrySwap) {
|
|
192
|
-
(0,
|
|
193
|
-
getInstanceId: () => (0,
|
|
194
|
-
});
|
|
197
|
+
(0, _classPrivateFieldSet2.default)(this, _getBlockRegistry, (0, _util.memoize)(registrySwap, {
|
|
198
|
+
getInstanceId: () => (0, _classPrivateFieldGet2.default)(this, _instanceId)
|
|
199
|
+
}));
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
addUserInterfaces(userRpc) {
|
|
@@ -203,7 +208,9 @@ class RpcCore {
|
|
|
203
208
|
|
|
204
209
|
(_ref3 = this)[_ref4 = sectionName] || (_ref3[_ref4] = {});
|
|
205
210
|
const section = this[sectionName];
|
|
206
|
-
Object.entries(
|
|
211
|
+
Object.entries({ ...this._createInterface(sectionName, _types.rpcDefinitions[sectionName] || {}),
|
|
212
|
+
...this._createInterface(sectionName, userRpc[sectionName] || {})
|
|
213
|
+
}).forEach(_ref5 => {
|
|
207
214
|
let [key, value] = _ref5;
|
|
208
215
|
section[key] || (section[key] = value);
|
|
209
216
|
});
|
|
@@ -223,12 +230,12 @@ class RpcCore {
|
|
|
223
230
|
const def = methods[method];
|
|
224
231
|
const isSubscription = !!def.pubsub;
|
|
225
232
|
const jsonrpc = endpoint || `${section}_${method}`;
|
|
226
|
-
this.mapping.set(jsonrpc,
|
|
233
|
+
this.mapping.set(jsonrpc, { ...def,
|
|
227
234
|
isSubscription,
|
|
228
235
|
jsonrpc,
|
|
229
236
|
method,
|
|
230
237
|
section
|
|
231
|
-
})
|
|
238
|
+
});
|
|
232
239
|
exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
|
|
233
240
|
return exposed;
|
|
234
241
|
}, {});
|
|
@@ -236,7 +243,7 @@ class RpcCore {
|
|
|
236
243
|
|
|
237
244
|
_memomize(creator, def) {
|
|
238
245
|
const memoOpts = {
|
|
239
|
-
getInstanceId: () => (0,
|
|
246
|
+
getInstanceId: () => (0, _classPrivateFieldGet2.default)(this, _instanceId)
|
|
240
247
|
};
|
|
241
248
|
const memoized = (0, _util.memoize)(creator(true), memoOpts);
|
|
242
249
|
memoized.raw = (0, _util.memoize)(creator(false), memoOpts);
|
|
@@ -262,8 +269,8 @@ class RpcCore {
|
|
|
262
269
|
const blockHash = hashIndex === -1 ? null : values[hashIndex];
|
|
263
270
|
const {
|
|
264
271
|
registry
|
|
265
|
-
} = isScale && blockHash && (0,
|
|
266
|
-
registry: (0,
|
|
272
|
+
} = isScale && blockHash && (0, _classPrivateFieldGet2.default)(this, _getBlockRegistry) ? await (0, _classPrivateFieldGet2.default)(this, _getBlockRegistry).call(this, (0, _util.u8aToU8a)(blockHash)) : {
|
|
273
|
+
registry: (0, _classPrivateFieldGet2.default)(this, _registryDefault)
|
|
267
274
|
};
|
|
268
275
|
|
|
269
276
|
const params = this._formatInputs(registry, null, def, values);
|
|
@@ -335,8 +342,7 @@ class RpcCore {
|
|
|
335
342
|
return new _rxjs.Observable(observer => {
|
|
336
343
|
// Have at least an empty promise, as used in the unsubscribe
|
|
337
344
|
let subscriptionPromise = Promise.resolve(null);
|
|
338
|
-
|
|
339
|
-
const registry = (0, _classPrivateFieldLooseBase2.default)(_this, _registryDefault)[_registryDefault];
|
|
345
|
+
const registry = (0, _classPrivateFieldGet2.default)(_this, _registryDefault);
|
|
340
346
|
|
|
341
347
|
const errorHandler = error => {
|
|
342
348
|
logErrorMessage(method, def, error);
|
|
@@ -456,14 +462,13 @@ class RpcCore {
|
|
|
456
462
|
// - if a single result value, don't fill - it is not an update hole
|
|
457
463
|
// - fallback to an empty option in all cases
|
|
458
464
|
|
|
459
|
-
const value = (0, _util.isUndefined)(found) ? witCache && (0,
|
|
465
|
+
const value = (0, _util.isUndefined)(found) ? witCache && (0, _classPrivateFieldGet2.default)(this, _storageCache).get(hexKey) || null : found[1];
|
|
460
466
|
const isEmpty = (0, _util.isNull)(value);
|
|
461
467
|
const input = isEmpty || isTreatAsHex(key) ? value : (0, _util.u8aToU8a)(value); // store the retrieved result - the only issue with this cache is that there is no
|
|
462
468
|
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
|
463
469
|
// will increase memory beyond what is allowed.
|
|
464
470
|
|
|
465
|
-
(0,
|
|
466
|
-
|
|
471
|
+
(0, _classPrivateFieldGet2.default)(this, _storageCache).set(hexKey, value);
|
|
467
472
|
return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
|
|
468
473
|
}
|
|
469
474
|
|
package/bundle.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
3
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
4
|
-
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
-
|
|
9
1
|
// Copyright 2017-2021 @polkadot/rpc-core authors & contributors
|
|
10
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
3
|
import { Observable, publishReplay, refCount } from 'rxjs';
|
|
@@ -74,44 +66,24 @@ function isTreatAsHex(key) {
|
|
|
74
66
|
*/
|
|
75
67
|
|
|
76
68
|
|
|
77
|
-
var _instanceId = /*#__PURE__*/_classPrivateFieldLooseKey("instanceId");
|
|
78
|
-
|
|
79
|
-
var _registryDefault = /*#__PURE__*/_classPrivateFieldLooseKey("registryDefault");
|
|
80
|
-
|
|
81
|
-
var _getBlockRegistry = /*#__PURE__*/_classPrivateFieldLooseKey("getBlockRegistry");
|
|
82
|
-
|
|
83
|
-
var _storageCache = /*#__PURE__*/_classPrivateFieldLooseKey("storageCache");
|
|
84
|
-
|
|
85
69
|
export class RpcCore {
|
|
70
|
+
#instanceId;
|
|
71
|
+
#registryDefault;
|
|
72
|
+
#getBlockRegistry;
|
|
73
|
+
#storageCache = new Map();
|
|
74
|
+
mapping = new Map();
|
|
75
|
+
sections = [];
|
|
86
76
|
/**
|
|
87
77
|
* @constructor
|
|
88
78
|
* Default constructor for the Api Object
|
|
89
79
|
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
|
|
90
80
|
*/
|
|
81
|
+
|
|
91
82
|
constructor(instanceId, registry, provider, userRpc = {}) {
|
|
92
|
-
Object.defineProperty(this, _instanceId, {
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(this, _registryDefault, {
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(this, _getBlockRegistry, {
|
|
101
|
-
writable: true,
|
|
102
|
-
value: void 0
|
|
103
|
-
});
|
|
104
|
-
Object.defineProperty(this, _storageCache, {
|
|
105
|
-
writable: true,
|
|
106
|
-
value: new Map()
|
|
107
|
-
});
|
|
108
|
-
this.mapping = new Map();
|
|
109
|
-
this.provider = void 0;
|
|
110
|
-
this.sections = [];
|
|
111
83
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
112
84
|
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
|
|
113
|
-
|
|
114
|
-
|
|
85
|
+
this.#instanceId = instanceId;
|
|
86
|
+
this.#registryDefault = registry;
|
|
115
87
|
this.provider = provider;
|
|
116
88
|
const sectionNames = Object.keys(rpcDefinitions); // these are the base keys (i.e. part of jsonrpc)
|
|
117
89
|
|
|
@@ -149,8 +121,8 @@ export class RpcCore {
|
|
|
149
121
|
|
|
150
122
|
|
|
151
123
|
setRegistrySwap(registrySwap) {
|
|
152
|
-
|
|
153
|
-
getInstanceId: () =>
|
|
124
|
+
this.#getBlockRegistry = memoize(registrySwap, {
|
|
125
|
+
getInstanceId: () => this.#instanceId
|
|
154
126
|
});
|
|
155
127
|
}
|
|
156
128
|
|
|
@@ -163,7 +135,9 @@ export class RpcCore {
|
|
|
163
135
|
|
|
164
136
|
(_ref = this)[_ref2 = sectionName] || (_ref[_ref2] = {});
|
|
165
137
|
const section = this[sectionName];
|
|
166
|
-
Object.entries(
|
|
138
|
+
Object.entries({ ...this._createInterface(sectionName, rpcDefinitions[sectionName] || {}),
|
|
139
|
+
...this._createInterface(sectionName, userRpc[sectionName] || {})
|
|
140
|
+
}).forEach(([key, value]) => {
|
|
167
141
|
section[key] || (section[key] = value);
|
|
168
142
|
});
|
|
169
143
|
});
|
|
@@ -178,12 +152,12 @@ export class RpcCore {
|
|
|
178
152
|
const def = methods[method];
|
|
179
153
|
const isSubscription = !!def.pubsub;
|
|
180
154
|
const jsonrpc = endpoint || `${section}_${method}`;
|
|
181
|
-
this.mapping.set(jsonrpc,
|
|
155
|
+
this.mapping.set(jsonrpc, { ...def,
|
|
182
156
|
isSubscription,
|
|
183
157
|
jsonrpc,
|
|
184
158
|
method,
|
|
185
159
|
section
|
|
186
|
-
})
|
|
160
|
+
});
|
|
187
161
|
exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
|
|
188
162
|
return exposed;
|
|
189
163
|
}, {});
|
|
@@ -191,7 +165,7 @@ export class RpcCore {
|
|
|
191
165
|
|
|
192
166
|
_memomize(creator, def) {
|
|
193
167
|
const memoOpts = {
|
|
194
|
-
getInstanceId: () =>
|
|
168
|
+
getInstanceId: () => this.#instanceId
|
|
195
169
|
};
|
|
196
170
|
const memoized = memoize(creator(true), memoOpts);
|
|
197
171
|
memoized.raw = memoize(creator(false), memoOpts);
|
|
@@ -214,8 +188,8 @@ export class RpcCore {
|
|
|
214
188
|
const blockHash = hashIndex === -1 ? null : values[hashIndex];
|
|
215
189
|
const {
|
|
216
190
|
registry
|
|
217
|
-
} = isScale && blockHash &&
|
|
218
|
-
registry:
|
|
191
|
+
} = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry(u8aToU8a(blockHash)) : {
|
|
192
|
+
registry: this.#registryDefault
|
|
219
193
|
};
|
|
220
194
|
|
|
221
195
|
const params = this._formatInputs(registry, null, def, values);
|
|
@@ -276,8 +250,7 @@ export class RpcCore {
|
|
|
276
250
|
return new Observable(observer => {
|
|
277
251
|
// Have at least an empty promise, as used in the unsubscribe
|
|
278
252
|
let subscriptionPromise = Promise.resolve(null);
|
|
279
|
-
|
|
280
|
-
const registry = _classPrivateFieldLooseBase(this, _registryDefault)[_registryDefault];
|
|
253
|
+
const registry = this.#registryDefault;
|
|
281
254
|
|
|
282
255
|
const errorHandler = error => {
|
|
283
256
|
logErrorMessage(method, def, error);
|
|
@@ -388,14 +361,13 @@ export class RpcCore {
|
|
|
388
361
|
// - if a single result value, don't fill - it is not an update hole
|
|
389
362
|
// - fallback to an empty option in all cases
|
|
390
363
|
|
|
391
|
-
const value = isUndefined(found) ? witCache &&
|
|
364
|
+
const value = isUndefined(found) ? witCache && this.#storageCache.get(hexKey) || null : found[1];
|
|
392
365
|
const isEmpty = isNull(value);
|
|
393
366
|
const input = isEmpty || isTreatAsHex(key) ? value : u8aToU8a(value); // store the retrieved result - the only issue with this cache is that there is no
|
|
394
367
|
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
|
395
368
|
// will increase memory beyond what is allowed.
|
|
396
369
|
|
|
397
|
-
|
|
398
|
-
|
|
370
|
+
this.#storageCache.set(hexKey, value);
|
|
399
371
|
return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
|
|
400
372
|
}
|
|
401
373
|
|
package/package.json
CHANGED
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"./detectPackage.cjs"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "6.6.2-
|
|
23
|
+
"version": "6.6.2-11",
|
|
24
24
|
"main": "index.js",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.16.0",
|
|
27
|
-
"@polkadot/rpc-provider": "6.6.2-
|
|
28
|
-
"@polkadot/types": "6.6.2-
|
|
29
|
-
"@polkadot/util": "^7.7.
|
|
27
|
+
"@polkadot/rpc-provider": "6.6.2-11",
|
|
28
|
+
"@polkadot/types": "6.6.2-11",
|
|
29
|
+
"@polkadot/util": "^7.7.2-4",
|
|
30
30
|
"rxjs": "^7.4.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@polkadot/keyring": "^7.7.
|
|
33
|
+
"@polkadot/keyring": "^7.7.2-4"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED