@pezkuwi/ui-keyring 3.16.6
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/README.md +136 -0
- package/build/Base.d.ts +30 -0
- package/build/Base.js +109 -0
- package/build/Keyring.d.ts +49 -0
- package/build/Keyring.js +304 -0
- package/build/LICENSE +201 -0
- package/build/README.md +136 -0
- package/build/bundle-pezkuwi-ui-keyring.js +2751 -0
- package/build/bundle.d.ts +4 -0
- package/build/bundle.js +4 -0
- package/build/cjs/Base.d.ts +30 -0
- package/build/cjs/Base.js +113 -0
- package/build/cjs/Keyring.d.ts +49 -0
- package/build/cjs/Keyring.js +308 -0
- package/build/cjs/bundle.d.ts +4 -0
- package/build/cjs/bundle.js +8 -0
- package/build/cjs/defaults.d.ts +6 -0
- package/build/cjs/defaults.js +28 -0
- package/build/cjs/index.d.ts +4 -0
- package/build/cjs/index.js +7 -0
- package/build/cjs/observable/accounts.d.ts +1 -0
- package/build/cjs/observable/accounts.js +6 -0
- package/build/cjs/observable/addresses.d.ts +1 -0
- package/build/cjs/observable/addresses.js +6 -0
- package/build/cjs/observable/contracts.d.ts +1 -0
- package/build/cjs/observable/contracts.js +6 -0
- package/build/cjs/observable/env.d.ts +6 -0
- package/build/cjs/observable/env.js +12 -0
- package/build/cjs/observable/genericSubject.d.ts +2 -0
- package/build/cjs/observable/genericSubject.js +47 -0
- package/build/cjs/observable/index.d.ts +8 -0
- package/build/cjs/observable/index.js +16 -0
- package/build/cjs/observable/types.d.ts +15 -0
- package/build/cjs/observable/types.js +2 -0
- package/build/cjs/options/index.d.ts +15 -0
- package/build/cjs/options/index.js +116 -0
- package/build/cjs/options/item.d.ts +2 -0
- package/build/cjs/options/item.js +16 -0
- package/build/cjs/options/types.d.ts +15 -0
- package/build/cjs/options/types.js +2 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +6 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/stores/Browser.d.ts +7 -0
- package/build/cjs/stores/Browser.js +24 -0
- package/build/cjs/stores/File.d.ts +12 -0
- package/build/cjs/stores/File.js +72 -0
- package/build/cjs/stores/index.d.ts +2 -0
- package/build/cjs/stores/index.js +7 -0
- package/build/cjs/types.d.ts +78 -0
- package/build/cjs/types.js +2 -0
- package/build/defaults.d.ts +6 -0
- package/build/defaults.js +22 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/observable/accounts.d.ts +1 -0
- package/build/observable/accounts.js +3 -0
- package/build/observable/addresses.d.ts +1 -0
- package/build/observable/addresses.js +3 -0
- package/build/observable/contracts.d.ts +1 -0
- package/build/observable/contracts.js +3 -0
- package/build/observable/env.d.ts +6 -0
- package/build/observable/env.js +9 -0
- package/build/observable/genericSubject.d.ts +2 -0
- package/build/observable/genericSubject.js +44 -0
- package/build/observable/index.d.ts +8 -0
- package/build/observable/index.js +13 -0
- package/build/observable/types.d.ts +15 -0
- package/build/observable/types.js +1 -0
- package/build/options/index.d.ts +15 -0
- package/build/options/index.js +112 -0
- package/build/options/item.d.ts +2 -0
- package/build/options/item.js +13 -0
- package/build/options/types.d.ts +15 -0
- package/build/options/types.js +1 -0
- package/build/package.json +355 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +4 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/stores/Browser.d.ts +7 -0
- package/build/stores/Browser.js +19 -0
- package/build/stores/File.d.ts +12 -0
- package/build/stores/File.js +67 -0
- package/build/stores/index.d.ts +2 -0
- package/build/stores/index.js +2 -0
- package/build/types.d.ts +78 -0
- package/build/types.js +1 -0
- package/build-tsc/Base.d.ts +30 -0
- package/build-tsc/Keyring.d.ts +49 -0
- package/build-tsc/bundle.d.ts +4 -0
- package/build-tsc/defaults.d.ts +6 -0
- package/build-tsc/index.d.ts +4 -0
- package/build-tsc/observable/accounts.d.ts +1 -0
- package/build-tsc/observable/addresses.d.ts +1 -0
- package/build-tsc/observable/contracts.d.ts +1 -0
- package/build-tsc/observable/env.d.ts +6 -0
- package/build-tsc/observable/genericSubject.d.ts +2 -0
- package/build-tsc/observable/index.d.ts +8 -0
- package/build-tsc/observable/types.d.ts +15 -0
- package/build-tsc/options/index.d.ts +15 -0
- package/build-tsc/options/item.d.ts +2 -0
- package/build-tsc/options/types.d.ts +15 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/stores/Browser.d.ts +7 -0
- package/build-tsc/stores/File.d.ts +12 -0
- package/build-tsc/stores/index.d.ts +2 -0
- package/build-tsc/types.d.ts +78 -0
- package/build-tsc-cjs/Base.js +113 -0
- package/build-tsc-cjs/Keyring.js +308 -0
- package/build-tsc-cjs/bundle.js +8 -0
- package/build-tsc-cjs/defaults.js +28 -0
- package/build-tsc-cjs/index.js +7 -0
- package/build-tsc-cjs/observable/accounts.js +6 -0
- package/build-tsc-cjs/observable/addresses.js +6 -0
- package/build-tsc-cjs/observable/contracts.js +6 -0
- package/build-tsc-cjs/observable/env.js +12 -0
- package/build-tsc-cjs/observable/genericSubject.js +47 -0
- package/build-tsc-cjs/observable/index.js +16 -0
- package/build-tsc-cjs/observable/types.js +2 -0
- package/build-tsc-cjs/options/index.js +116 -0
- package/build-tsc-cjs/options/item.js +16 -0
- package/build-tsc-cjs/options/types.js +2 -0
- package/build-tsc-cjs/packageDetect.js +6 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/stores/Browser.js +24 -0
- package/build-tsc-cjs/stores/File.js +72 -0
- package/build-tsc-cjs/stores/index.js +7 -0
- package/build-tsc-cjs/types.js +2 -0
- package/build-tsc-esm/Base.js +109 -0
- package/build-tsc-esm/Keyring.js +304 -0
- package/build-tsc-esm/bundle.js +4 -0
- package/build-tsc-esm/defaults.js +22 -0
- package/build-tsc-esm/index.js +4 -0
- package/build-tsc-esm/observable/accounts.js +3 -0
- package/build-tsc-esm/observable/addresses.js +3 -0
- package/build-tsc-esm/observable/contracts.js +3 -0
- package/build-tsc-esm/observable/env.js +9 -0
- package/build-tsc-esm/observable/genericSubject.js +44 -0
- package/build-tsc-esm/observable/index.js +13 -0
- package/build-tsc-esm/observable/types.js +1 -0
- package/build-tsc-esm/options/index.js +112 -0
- package/build-tsc-esm/options/item.js +13 -0
- package/build-tsc-esm/options/types.js +1 -0
- package/build-tsc-esm/packageDetect.js +4 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/stores/Browser.js +19 -0
- package/build-tsc-esm/stores/File.js +67 -0
- package/build-tsc-esm/stores/index.js +2 -0
- package/build-tsc-esm/types.js +1 -0
- package/package.json +41 -0
- package/src/Base.ts +156 -0
- package/src/Keyring.ts +420 -0
- package/src/bundle.ts +10 -0
- package/src/defaults.ts +34 -0
- package/src/index.ts +10 -0
- package/src/json.d.ts +11 -0
- package/src/observable/accounts.ts +7 -0
- package/src/observable/addresses.ts +7 -0
- package/src/observable/contracts.ts +7 -0
- package/src/observable/env.ts +15 -0
- package/src/observable/genericSubject.ts +66 -0
- package/src/observable/index.ts +28 -0
- package/src/observable/types.ts +21 -0
- package/src/options/index.ts +150 -0
- package/src/options/item.ts +22 -0
- package/src/options/types.ts +23 -0
- package/src/packageDetect.ts +12 -0
- package/src/packageInfo.ts +6 -0
- package/src/stores/Browser.ts +28 -0
- package/src/stores/File.ts +94 -0
- package/src/stores/index.ts +5 -0
- package/src/types.ts +91 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +16 -0
|
@@ -0,0 +1,2751 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pezkuwi/keyring'), require('@pezkuwi/ui-settings'), require('@pezkuwi/util'), require('@pezkuwi/util-crypto')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@pezkuwi/keyring', '@pezkuwi/ui-settings', '@pezkuwi/util', '@pezkuwi/util-crypto'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pezkuwiUiKeyring = {}, global.pezkuwiKeyring, global.pezkuwiUiSettings, global.pezkuwiUtil, global.pezkuwiUtilCrypto));
|
|
5
|
+
})(this, (function (exports, keyring$1, uiSettings, util$7, utilCrypto) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : window;
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
var extendStatics = function(d, b) {
|
|
11
|
+
extendStatics = Object.setPrototypeOf ||
|
|
12
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
13
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
14
|
+
return extendStatics(d, b);
|
|
15
|
+
};
|
|
16
|
+
function __extends(d, b) {
|
|
17
|
+
if (typeof b !== "function" && b !== null)
|
|
18
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
19
|
+
extendStatics(d, b);
|
|
20
|
+
function __() { this.constructor = d; }
|
|
21
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
+
}
|
|
23
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function __generator(thisArg, body) {
|
|
33
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
34
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
35
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
36
|
+
function step(op) {
|
|
37
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
38
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
39
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
40
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
41
|
+
switch (op[0]) {
|
|
42
|
+
case 0: case 1: t = op; break;
|
|
43
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
44
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
45
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
46
|
+
default:
|
|
47
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
48
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
49
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
50
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
51
|
+
if (t[2]) _.ops.pop();
|
|
52
|
+
_.trys.pop(); continue;
|
|
53
|
+
}
|
|
54
|
+
op = body.call(thisArg, _);
|
|
55
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
56
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function __values(o) {
|
|
60
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
61
|
+
if (m) return m.call(o);
|
|
62
|
+
if (o && typeof o.length === "number") return {
|
|
63
|
+
next: function () {
|
|
64
|
+
if (o && i >= o.length) o = void 0;
|
|
65
|
+
return { value: o && o[i++], done: !o };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
69
|
+
}
|
|
70
|
+
function __read(o, n) {
|
|
71
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
72
|
+
if (!m) return o;
|
|
73
|
+
var i = m.call(o), r, ar = [], e;
|
|
74
|
+
try {
|
|
75
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
76
|
+
}
|
|
77
|
+
catch (error) { e = { error: error }; }
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e) throw e.error; }
|
|
83
|
+
}
|
|
84
|
+
return ar;
|
|
85
|
+
}
|
|
86
|
+
function __spreadArray(to, from, pack) {
|
|
87
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
88
|
+
if (ar || !(i in from)) {
|
|
89
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
90
|
+
ar[i] = from[i];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
94
|
+
}
|
|
95
|
+
function __await(v) {
|
|
96
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
97
|
+
}
|
|
98
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
99
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
100
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
101
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
102
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
103
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
104
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
105
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
106
|
+
function fulfill(value) { resume("next", value); }
|
|
107
|
+
function reject(value) { resume("throw", value); }
|
|
108
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
109
|
+
}
|
|
110
|
+
function __asyncValues(o) {
|
|
111
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
112
|
+
var m = o[Symbol.asyncIterator], i;
|
|
113
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
114
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
115
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
116
|
+
}
|
|
117
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
118
|
+
var e = new Error(message);
|
|
119
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
function isFunction$2(value) {
|
|
123
|
+
return typeof value === 'function';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createErrorClass(createImpl) {
|
|
127
|
+
var _super = function (instance) {
|
|
128
|
+
Error.call(instance);
|
|
129
|
+
instance.stack = new Error().stack;
|
|
130
|
+
};
|
|
131
|
+
var ctorFunc = createImpl(_super);
|
|
132
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
133
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
134
|
+
return ctorFunc;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
138
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
139
|
+
_super(this);
|
|
140
|
+
this.message = errors
|
|
141
|
+
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
142
|
+
: '';
|
|
143
|
+
this.name = 'UnsubscriptionError';
|
|
144
|
+
this.errors = errors;
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
function arrRemove(arr, item) {
|
|
149
|
+
if (arr) {
|
|
150
|
+
var index = arr.indexOf(item);
|
|
151
|
+
0 <= index && arr.splice(index, 1);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var Subscription = (function () {
|
|
156
|
+
function Subscription(initialTeardown) {
|
|
157
|
+
this.initialTeardown = initialTeardown;
|
|
158
|
+
this.closed = false;
|
|
159
|
+
this._parentage = null;
|
|
160
|
+
this._finalizers = null;
|
|
161
|
+
}
|
|
162
|
+
Subscription.prototype.unsubscribe = function () {
|
|
163
|
+
var e_1, _a, e_2, _b;
|
|
164
|
+
var errors;
|
|
165
|
+
if (!this.closed) {
|
|
166
|
+
this.closed = true;
|
|
167
|
+
var _parentage = this._parentage;
|
|
168
|
+
if (_parentage) {
|
|
169
|
+
this._parentage = null;
|
|
170
|
+
if (Array.isArray(_parentage)) {
|
|
171
|
+
try {
|
|
172
|
+
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
173
|
+
var parent_1 = _parentage_1_1.value;
|
|
174
|
+
parent_1.remove(this);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
178
|
+
finally {
|
|
179
|
+
try {
|
|
180
|
+
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
181
|
+
}
|
|
182
|
+
finally { if (e_1) throw e_1.error; }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
_parentage.remove(this);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
var initialFinalizer = this.initialTeardown;
|
|
190
|
+
if (isFunction$2(initialFinalizer)) {
|
|
191
|
+
try {
|
|
192
|
+
initialFinalizer();
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
var _finalizers = this._finalizers;
|
|
199
|
+
if (_finalizers) {
|
|
200
|
+
this._finalizers = null;
|
|
201
|
+
try {
|
|
202
|
+
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
203
|
+
var finalizer = _finalizers_1_1.value;
|
|
204
|
+
try {
|
|
205
|
+
execFinalizer(finalizer);
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
209
|
+
if (err instanceof UnsubscriptionError) {
|
|
210
|
+
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
errors.push(err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
219
|
+
finally {
|
|
220
|
+
try {
|
|
221
|
+
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
222
|
+
}
|
|
223
|
+
finally { if (e_2) throw e_2.error; }
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (errors) {
|
|
227
|
+
throw new UnsubscriptionError(errors);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
Subscription.prototype.add = function (teardown) {
|
|
232
|
+
var _a;
|
|
233
|
+
if (teardown && teardown !== this) {
|
|
234
|
+
if (this.closed) {
|
|
235
|
+
execFinalizer(teardown);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (teardown instanceof Subscription) {
|
|
239
|
+
if (teardown.closed || teardown._hasParent(this)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
teardown._addParent(this);
|
|
243
|
+
}
|
|
244
|
+
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
Subscription.prototype._hasParent = function (parent) {
|
|
249
|
+
var _parentage = this._parentage;
|
|
250
|
+
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
251
|
+
};
|
|
252
|
+
Subscription.prototype._addParent = function (parent) {
|
|
253
|
+
var _parentage = this._parentage;
|
|
254
|
+
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
255
|
+
};
|
|
256
|
+
Subscription.prototype._removeParent = function (parent) {
|
|
257
|
+
var _parentage = this._parentage;
|
|
258
|
+
if (_parentage === parent) {
|
|
259
|
+
this._parentage = null;
|
|
260
|
+
}
|
|
261
|
+
else if (Array.isArray(_parentage)) {
|
|
262
|
+
arrRemove(_parentage, parent);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
Subscription.prototype.remove = function (teardown) {
|
|
266
|
+
var _finalizers = this._finalizers;
|
|
267
|
+
_finalizers && arrRemove(_finalizers, teardown);
|
|
268
|
+
if (teardown instanceof Subscription) {
|
|
269
|
+
teardown._removeParent(this);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
Subscription.EMPTY = (function () {
|
|
273
|
+
var empty = new Subscription();
|
|
274
|
+
empty.closed = true;
|
|
275
|
+
return empty;
|
|
276
|
+
})();
|
|
277
|
+
return Subscription;
|
|
278
|
+
}());
|
|
279
|
+
var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
|
280
|
+
function isSubscription(value) {
|
|
281
|
+
return (value instanceof Subscription ||
|
|
282
|
+
(value && 'closed' in value && isFunction$2(value.remove) && isFunction$2(value.add) && isFunction$2(value.unsubscribe)));
|
|
283
|
+
}
|
|
284
|
+
function execFinalizer(finalizer) {
|
|
285
|
+
if (isFunction$2(finalizer)) {
|
|
286
|
+
finalizer();
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
finalizer.unsubscribe();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
var config = {
|
|
294
|
+
onUnhandledError: null,
|
|
295
|
+
onStoppedNotification: null,
|
|
296
|
+
Promise: undefined,
|
|
297
|
+
useDeprecatedSynchronousErrorHandling: false,
|
|
298
|
+
useDeprecatedNextContext: false,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
var timeoutProvider = {
|
|
302
|
+
setTimeout: function (handler, timeout) {
|
|
303
|
+
var args = [];
|
|
304
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
305
|
+
args[_i - 2] = arguments[_i];
|
|
306
|
+
}
|
|
307
|
+
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
308
|
+
},
|
|
309
|
+
clearTimeout: function (handle) {
|
|
310
|
+
var delegate = timeoutProvider.delegate;
|
|
311
|
+
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
312
|
+
},
|
|
313
|
+
delegate: undefined,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
function reportUnhandledError(err) {
|
|
317
|
+
timeoutProvider.setTimeout(function () {
|
|
318
|
+
{
|
|
319
|
+
throw err;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function noop() { }
|
|
325
|
+
|
|
326
|
+
function errorContext(cb) {
|
|
327
|
+
{
|
|
328
|
+
cb();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
var Subscriber = (function (_super) {
|
|
333
|
+
__extends(Subscriber, _super);
|
|
334
|
+
function Subscriber(destination) {
|
|
335
|
+
var _this = _super.call(this) || this;
|
|
336
|
+
_this.isStopped = false;
|
|
337
|
+
if (destination) {
|
|
338
|
+
_this.destination = destination;
|
|
339
|
+
if (isSubscription(destination)) {
|
|
340
|
+
destination.add(_this);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
_this.destination = EMPTY_OBSERVER;
|
|
345
|
+
}
|
|
346
|
+
return _this;
|
|
347
|
+
}
|
|
348
|
+
Subscriber.create = function (next, error, complete) {
|
|
349
|
+
return new SafeSubscriber(next, error, complete);
|
|
350
|
+
};
|
|
351
|
+
Subscriber.prototype.next = function (value) {
|
|
352
|
+
if (this.isStopped) ;
|
|
353
|
+
else {
|
|
354
|
+
this._next(value);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
Subscriber.prototype.error = function (err) {
|
|
358
|
+
if (this.isStopped) ;
|
|
359
|
+
else {
|
|
360
|
+
this.isStopped = true;
|
|
361
|
+
this._error(err);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
Subscriber.prototype.complete = function () {
|
|
365
|
+
if (this.isStopped) ;
|
|
366
|
+
else {
|
|
367
|
+
this.isStopped = true;
|
|
368
|
+
this._complete();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
Subscriber.prototype.unsubscribe = function () {
|
|
372
|
+
if (!this.closed) {
|
|
373
|
+
this.isStopped = true;
|
|
374
|
+
_super.prototype.unsubscribe.call(this);
|
|
375
|
+
this.destination = null;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
Subscriber.prototype._next = function (value) {
|
|
379
|
+
this.destination.next(value);
|
|
380
|
+
};
|
|
381
|
+
Subscriber.prototype._error = function (err) {
|
|
382
|
+
try {
|
|
383
|
+
this.destination.error(err);
|
|
384
|
+
}
|
|
385
|
+
finally {
|
|
386
|
+
this.unsubscribe();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
Subscriber.prototype._complete = function () {
|
|
390
|
+
try {
|
|
391
|
+
this.destination.complete();
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
this.unsubscribe();
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
return Subscriber;
|
|
398
|
+
}(Subscription));
|
|
399
|
+
var _bind = Function.prototype.bind;
|
|
400
|
+
function bind$2(fn, thisArg) {
|
|
401
|
+
return _bind.call(fn, thisArg);
|
|
402
|
+
}
|
|
403
|
+
var ConsumerObserver = (function () {
|
|
404
|
+
function ConsumerObserver(partialObserver) {
|
|
405
|
+
this.partialObserver = partialObserver;
|
|
406
|
+
}
|
|
407
|
+
ConsumerObserver.prototype.next = function (value) {
|
|
408
|
+
var partialObserver = this.partialObserver;
|
|
409
|
+
if (partialObserver.next) {
|
|
410
|
+
try {
|
|
411
|
+
partialObserver.next(value);
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
handleUnhandledError(error);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
ConsumerObserver.prototype.error = function (err) {
|
|
419
|
+
var partialObserver = this.partialObserver;
|
|
420
|
+
if (partialObserver.error) {
|
|
421
|
+
try {
|
|
422
|
+
partialObserver.error(err);
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
handleUnhandledError(error);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
handleUnhandledError(err);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
ConsumerObserver.prototype.complete = function () {
|
|
433
|
+
var partialObserver = this.partialObserver;
|
|
434
|
+
if (partialObserver.complete) {
|
|
435
|
+
try {
|
|
436
|
+
partialObserver.complete();
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
handleUnhandledError(error);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
return ConsumerObserver;
|
|
444
|
+
}());
|
|
445
|
+
var SafeSubscriber = (function (_super) {
|
|
446
|
+
__extends(SafeSubscriber, _super);
|
|
447
|
+
function SafeSubscriber(observerOrNext, error, complete) {
|
|
448
|
+
var _this = _super.call(this) || this;
|
|
449
|
+
var partialObserver;
|
|
450
|
+
if (isFunction$2(observerOrNext) || !observerOrNext) {
|
|
451
|
+
partialObserver = {
|
|
452
|
+
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
453
|
+
error: error !== null && error !== void 0 ? error : undefined,
|
|
454
|
+
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
var context_1;
|
|
459
|
+
if (_this && config.useDeprecatedNextContext) {
|
|
460
|
+
context_1 = Object.create(observerOrNext);
|
|
461
|
+
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
462
|
+
partialObserver = {
|
|
463
|
+
next: observerOrNext.next && bind$2(observerOrNext.next, context_1),
|
|
464
|
+
error: observerOrNext.error && bind$2(observerOrNext.error, context_1),
|
|
465
|
+
complete: observerOrNext.complete && bind$2(observerOrNext.complete, context_1),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
partialObserver = observerOrNext;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
_this.destination = new ConsumerObserver(partialObserver);
|
|
473
|
+
return _this;
|
|
474
|
+
}
|
|
475
|
+
return SafeSubscriber;
|
|
476
|
+
}(Subscriber));
|
|
477
|
+
function handleUnhandledError(error) {
|
|
478
|
+
{
|
|
479
|
+
reportUnhandledError(error);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function defaultErrorHandler(err) {
|
|
483
|
+
throw err;
|
|
484
|
+
}
|
|
485
|
+
var EMPTY_OBSERVER = {
|
|
486
|
+
closed: true,
|
|
487
|
+
next: noop,
|
|
488
|
+
error: defaultErrorHandler,
|
|
489
|
+
complete: noop,
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
493
|
+
|
|
494
|
+
function identity(x) {
|
|
495
|
+
return x;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function pipeFromArray(fns) {
|
|
499
|
+
if (fns.length === 0) {
|
|
500
|
+
return identity;
|
|
501
|
+
}
|
|
502
|
+
if (fns.length === 1) {
|
|
503
|
+
return fns[0];
|
|
504
|
+
}
|
|
505
|
+
return function piped(input) {
|
|
506
|
+
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
var Observable = (function () {
|
|
511
|
+
function Observable(subscribe) {
|
|
512
|
+
if (subscribe) {
|
|
513
|
+
this._subscribe = subscribe;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
Observable.prototype.lift = function (operator) {
|
|
517
|
+
var observable = new Observable();
|
|
518
|
+
observable.source = this;
|
|
519
|
+
observable.operator = operator;
|
|
520
|
+
return observable;
|
|
521
|
+
};
|
|
522
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
523
|
+
var _this = this;
|
|
524
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
525
|
+
errorContext(function () {
|
|
526
|
+
var _a = _this, operator = _a.operator, source = _a.source;
|
|
527
|
+
subscriber.add(operator
|
|
528
|
+
?
|
|
529
|
+
operator.call(subscriber, source)
|
|
530
|
+
: source
|
|
531
|
+
?
|
|
532
|
+
_this._subscribe(subscriber)
|
|
533
|
+
:
|
|
534
|
+
_this._trySubscribe(subscriber));
|
|
535
|
+
});
|
|
536
|
+
return subscriber;
|
|
537
|
+
};
|
|
538
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
539
|
+
try {
|
|
540
|
+
return this._subscribe(sink);
|
|
541
|
+
}
|
|
542
|
+
catch (err) {
|
|
543
|
+
sink.error(err);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
547
|
+
var _this = this;
|
|
548
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
549
|
+
return new promiseCtor(function (resolve, reject) {
|
|
550
|
+
var subscriber = new SafeSubscriber({
|
|
551
|
+
next: function (value) {
|
|
552
|
+
try {
|
|
553
|
+
next(value);
|
|
554
|
+
}
|
|
555
|
+
catch (err) {
|
|
556
|
+
reject(err);
|
|
557
|
+
subscriber.unsubscribe();
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
error: reject,
|
|
561
|
+
complete: resolve,
|
|
562
|
+
});
|
|
563
|
+
_this.subscribe(subscriber);
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
567
|
+
var _a;
|
|
568
|
+
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
569
|
+
};
|
|
570
|
+
Observable.prototype[observable] = function () {
|
|
571
|
+
return this;
|
|
572
|
+
};
|
|
573
|
+
Observable.prototype.pipe = function () {
|
|
574
|
+
var operations = [];
|
|
575
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
576
|
+
operations[_i] = arguments[_i];
|
|
577
|
+
}
|
|
578
|
+
return pipeFromArray(operations)(this);
|
|
579
|
+
};
|
|
580
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
581
|
+
var _this = this;
|
|
582
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
583
|
+
return new promiseCtor(function (resolve, reject) {
|
|
584
|
+
var value;
|
|
585
|
+
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
586
|
+
});
|
|
587
|
+
};
|
|
588
|
+
Observable.create = function (subscribe) {
|
|
589
|
+
return new Observable(subscribe);
|
|
590
|
+
};
|
|
591
|
+
return Observable;
|
|
592
|
+
}());
|
|
593
|
+
function getPromiseCtor(promiseCtor) {
|
|
594
|
+
var _a;
|
|
595
|
+
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
596
|
+
}
|
|
597
|
+
function isObserver(value) {
|
|
598
|
+
return value && isFunction$2(value.next) && isFunction$2(value.error) && isFunction$2(value.complete);
|
|
599
|
+
}
|
|
600
|
+
function isSubscriber(value) {
|
|
601
|
+
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function hasLift(source) {
|
|
605
|
+
return isFunction$2(source === null || source === void 0 ? void 0 : source.lift);
|
|
606
|
+
}
|
|
607
|
+
function operate(init) {
|
|
608
|
+
return function (source) {
|
|
609
|
+
if (hasLift(source)) {
|
|
610
|
+
return source.lift(function (liftedSource) {
|
|
611
|
+
try {
|
|
612
|
+
return init(liftedSource, this);
|
|
613
|
+
}
|
|
614
|
+
catch (err) {
|
|
615
|
+
this.error(err);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
throw new TypeError('Unable to lift unknown Observable type');
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
624
|
+
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
625
|
+
}
|
|
626
|
+
var OperatorSubscriber = (function (_super) {
|
|
627
|
+
__extends(OperatorSubscriber, _super);
|
|
628
|
+
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
629
|
+
var _this = _super.call(this, destination) || this;
|
|
630
|
+
_this.onFinalize = onFinalize;
|
|
631
|
+
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
632
|
+
_this._next = onNext
|
|
633
|
+
? function (value) {
|
|
634
|
+
try {
|
|
635
|
+
onNext(value);
|
|
636
|
+
}
|
|
637
|
+
catch (err) {
|
|
638
|
+
destination.error(err);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
: _super.prototype._next;
|
|
642
|
+
_this._error = onError
|
|
643
|
+
? function (err) {
|
|
644
|
+
try {
|
|
645
|
+
onError(err);
|
|
646
|
+
}
|
|
647
|
+
catch (err) {
|
|
648
|
+
destination.error(err);
|
|
649
|
+
}
|
|
650
|
+
finally {
|
|
651
|
+
this.unsubscribe();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
: _super.prototype._error;
|
|
655
|
+
_this._complete = onComplete
|
|
656
|
+
? function () {
|
|
657
|
+
try {
|
|
658
|
+
onComplete();
|
|
659
|
+
}
|
|
660
|
+
catch (err) {
|
|
661
|
+
destination.error(err);
|
|
662
|
+
}
|
|
663
|
+
finally {
|
|
664
|
+
this.unsubscribe();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
: _super.prototype._complete;
|
|
668
|
+
return _this;
|
|
669
|
+
}
|
|
670
|
+
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
671
|
+
var _a;
|
|
672
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
673
|
+
var closed_1 = this.closed;
|
|
674
|
+
_super.prototype.unsubscribe.call(this);
|
|
675
|
+
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
return OperatorSubscriber;
|
|
679
|
+
}(Subscriber));
|
|
680
|
+
|
|
681
|
+
var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
|
682
|
+
return function ObjectUnsubscribedErrorImpl() {
|
|
683
|
+
_super(this);
|
|
684
|
+
this.name = 'ObjectUnsubscribedError';
|
|
685
|
+
this.message = 'object unsubscribed';
|
|
686
|
+
};
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
var Subject = (function (_super) {
|
|
690
|
+
__extends(Subject, _super);
|
|
691
|
+
function Subject() {
|
|
692
|
+
var _this = _super.call(this) || this;
|
|
693
|
+
_this.closed = false;
|
|
694
|
+
_this.currentObservers = null;
|
|
695
|
+
_this.observers = [];
|
|
696
|
+
_this.isStopped = false;
|
|
697
|
+
_this.hasError = false;
|
|
698
|
+
_this.thrownError = null;
|
|
699
|
+
return _this;
|
|
700
|
+
}
|
|
701
|
+
Subject.prototype.lift = function (operator) {
|
|
702
|
+
var subject = new AnonymousSubject(this, this);
|
|
703
|
+
subject.operator = operator;
|
|
704
|
+
return subject;
|
|
705
|
+
};
|
|
706
|
+
Subject.prototype._throwIfClosed = function () {
|
|
707
|
+
if (this.closed) {
|
|
708
|
+
throw new ObjectUnsubscribedError();
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
Subject.prototype.next = function (value) {
|
|
712
|
+
var _this = this;
|
|
713
|
+
errorContext(function () {
|
|
714
|
+
var e_1, _a;
|
|
715
|
+
_this._throwIfClosed();
|
|
716
|
+
if (!_this.isStopped) {
|
|
717
|
+
if (!_this.currentObservers) {
|
|
718
|
+
_this.currentObservers = Array.from(_this.observers);
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
722
|
+
var observer = _c.value;
|
|
723
|
+
observer.next(value);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
727
|
+
finally {
|
|
728
|
+
try {
|
|
729
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
730
|
+
}
|
|
731
|
+
finally { if (e_1) throw e_1.error; }
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
Subject.prototype.error = function (err) {
|
|
737
|
+
var _this = this;
|
|
738
|
+
errorContext(function () {
|
|
739
|
+
_this._throwIfClosed();
|
|
740
|
+
if (!_this.isStopped) {
|
|
741
|
+
_this.hasError = _this.isStopped = true;
|
|
742
|
+
_this.thrownError = err;
|
|
743
|
+
var observers = _this.observers;
|
|
744
|
+
while (observers.length) {
|
|
745
|
+
observers.shift().error(err);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
};
|
|
750
|
+
Subject.prototype.complete = function () {
|
|
751
|
+
var _this = this;
|
|
752
|
+
errorContext(function () {
|
|
753
|
+
_this._throwIfClosed();
|
|
754
|
+
if (!_this.isStopped) {
|
|
755
|
+
_this.isStopped = true;
|
|
756
|
+
var observers = _this.observers;
|
|
757
|
+
while (observers.length) {
|
|
758
|
+
observers.shift().complete();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
};
|
|
763
|
+
Subject.prototype.unsubscribe = function () {
|
|
764
|
+
this.isStopped = this.closed = true;
|
|
765
|
+
this.observers = this.currentObservers = null;
|
|
766
|
+
};
|
|
767
|
+
Object.defineProperty(Subject.prototype, "observed", {
|
|
768
|
+
get: function () {
|
|
769
|
+
var _a;
|
|
770
|
+
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
771
|
+
},
|
|
772
|
+
enumerable: false,
|
|
773
|
+
configurable: true
|
|
774
|
+
});
|
|
775
|
+
Subject.prototype._trySubscribe = function (subscriber) {
|
|
776
|
+
this._throwIfClosed();
|
|
777
|
+
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
778
|
+
};
|
|
779
|
+
Subject.prototype._subscribe = function (subscriber) {
|
|
780
|
+
this._throwIfClosed();
|
|
781
|
+
this._checkFinalizedStatuses(subscriber);
|
|
782
|
+
return this._innerSubscribe(subscriber);
|
|
783
|
+
};
|
|
784
|
+
Subject.prototype._innerSubscribe = function (subscriber) {
|
|
785
|
+
var _this = this;
|
|
786
|
+
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
787
|
+
if (hasError || isStopped) {
|
|
788
|
+
return EMPTY_SUBSCRIPTION;
|
|
789
|
+
}
|
|
790
|
+
this.currentObservers = null;
|
|
791
|
+
observers.push(subscriber);
|
|
792
|
+
return new Subscription(function () {
|
|
793
|
+
_this.currentObservers = null;
|
|
794
|
+
arrRemove(observers, subscriber);
|
|
795
|
+
});
|
|
796
|
+
};
|
|
797
|
+
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
|
798
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
799
|
+
if (hasError) {
|
|
800
|
+
subscriber.error(thrownError);
|
|
801
|
+
}
|
|
802
|
+
else if (isStopped) {
|
|
803
|
+
subscriber.complete();
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
Subject.prototype.asObservable = function () {
|
|
807
|
+
var observable = new Observable();
|
|
808
|
+
observable.source = this;
|
|
809
|
+
return observable;
|
|
810
|
+
};
|
|
811
|
+
Subject.create = function (destination, source) {
|
|
812
|
+
return new AnonymousSubject(destination, source);
|
|
813
|
+
};
|
|
814
|
+
return Subject;
|
|
815
|
+
}(Observable));
|
|
816
|
+
var AnonymousSubject = (function (_super) {
|
|
817
|
+
__extends(AnonymousSubject, _super);
|
|
818
|
+
function AnonymousSubject(destination, source) {
|
|
819
|
+
var _this = _super.call(this) || this;
|
|
820
|
+
_this.destination = destination;
|
|
821
|
+
_this.source = source;
|
|
822
|
+
return _this;
|
|
823
|
+
}
|
|
824
|
+
AnonymousSubject.prototype.next = function (value) {
|
|
825
|
+
var _a, _b;
|
|
826
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
827
|
+
};
|
|
828
|
+
AnonymousSubject.prototype.error = function (err) {
|
|
829
|
+
var _a, _b;
|
|
830
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
831
|
+
};
|
|
832
|
+
AnonymousSubject.prototype.complete = function () {
|
|
833
|
+
var _a, _b;
|
|
834
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
835
|
+
};
|
|
836
|
+
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
|
837
|
+
var _a, _b;
|
|
838
|
+
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
|
839
|
+
};
|
|
840
|
+
return AnonymousSubject;
|
|
841
|
+
}(Subject));
|
|
842
|
+
|
|
843
|
+
var BehaviorSubject = (function (_super) {
|
|
844
|
+
__extends(BehaviorSubject, _super);
|
|
845
|
+
function BehaviorSubject(_value) {
|
|
846
|
+
var _this = _super.call(this) || this;
|
|
847
|
+
_this._value = _value;
|
|
848
|
+
return _this;
|
|
849
|
+
}
|
|
850
|
+
Object.defineProperty(BehaviorSubject.prototype, "value", {
|
|
851
|
+
get: function () {
|
|
852
|
+
return this.getValue();
|
|
853
|
+
},
|
|
854
|
+
enumerable: false,
|
|
855
|
+
configurable: true
|
|
856
|
+
});
|
|
857
|
+
BehaviorSubject.prototype._subscribe = function (subscriber) {
|
|
858
|
+
var subscription = _super.prototype._subscribe.call(this, subscriber);
|
|
859
|
+
!subscription.closed && subscriber.next(this._value);
|
|
860
|
+
return subscription;
|
|
861
|
+
};
|
|
862
|
+
BehaviorSubject.prototype.getValue = function () {
|
|
863
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
|
|
864
|
+
if (hasError) {
|
|
865
|
+
throw thrownError;
|
|
866
|
+
}
|
|
867
|
+
this._throwIfClosed();
|
|
868
|
+
return _value;
|
|
869
|
+
};
|
|
870
|
+
BehaviorSubject.prototype.next = function (value) {
|
|
871
|
+
_super.prototype.next.call(this, (this._value = value));
|
|
872
|
+
};
|
|
873
|
+
return BehaviorSubject;
|
|
874
|
+
}(Subject));
|
|
875
|
+
|
|
876
|
+
function isScheduler(value) {
|
|
877
|
+
return value && isFunction$2(value.schedule);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
function last(arr) {
|
|
881
|
+
return arr[arr.length - 1];
|
|
882
|
+
}
|
|
883
|
+
function popResultSelector(args) {
|
|
884
|
+
return isFunction$2(last(args)) ? args.pop() : undefined;
|
|
885
|
+
}
|
|
886
|
+
function popScheduler(args) {
|
|
887
|
+
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
891
|
+
|
|
892
|
+
function isPromise(value) {
|
|
893
|
+
return isFunction$2(value === null || value === void 0 ? void 0 : value.then);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function isInteropObservable(input) {
|
|
897
|
+
return isFunction$2(input[observable]);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function isAsyncIterable(obj) {
|
|
901
|
+
return Symbol.asyncIterator && isFunction$2(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function createInvalidObservableTypeError(input) {
|
|
905
|
+
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
function getSymbolIterator() {
|
|
909
|
+
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
910
|
+
return '@@iterator';
|
|
911
|
+
}
|
|
912
|
+
return Symbol.iterator;
|
|
913
|
+
}
|
|
914
|
+
var iterator = getSymbolIterator();
|
|
915
|
+
|
|
916
|
+
function isIterable(input) {
|
|
917
|
+
return isFunction$2(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
921
|
+
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
922
|
+
var reader, _a, value, done;
|
|
923
|
+
return __generator(this, function (_b) {
|
|
924
|
+
switch (_b.label) {
|
|
925
|
+
case 0:
|
|
926
|
+
reader = readableStream.getReader();
|
|
927
|
+
_b.label = 1;
|
|
928
|
+
case 1:
|
|
929
|
+
_b.trys.push([1, , 9, 10]);
|
|
930
|
+
_b.label = 2;
|
|
931
|
+
case 2:
|
|
932
|
+
return [4, __await(reader.read())];
|
|
933
|
+
case 3:
|
|
934
|
+
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
935
|
+
if (!done) return [3, 5];
|
|
936
|
+
return [4, __await(void 0)];
|
|
937
|
+
case 4: return [2, _b.sent()];
|
|
938
|
+
case 5: return [4, __await(value)];
|
|
939
|
+
case 6: return [4, _b.sent()];
|
|
940
|
+
case 7:
|
|
941
|
+
_b.sent();
|
|
942
|
+
return [3, 2];
|
|
943
|
+
case 8: return [3, 10];
|
|
944
|
+
case 9:
|
|
945
|
+
reader.releaseLock();
|
|
946
|
+
return [7];
|
|
947
|
+
case 10: return [2];
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
function isReadableStreamLike(obj) {
|
|
953
|
+
return isFunction$2(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function innerFrom(input) {
|
|
957
|
+
if (input instanceof Observable) {
|
|
958
|
+
return input;
|
|
959
|
+
}
|
|
960
|
+
if (input != null) {
|
|
961
|
+
if (isInteropObservable(input)) {
|
|
962
|
+
return fromInteropObservable(input);
|
|
963
|
+
}
|
|
964
|
+
if (isArrayLike(input)) {
|
|
965
|
+
return fromArrayLike(input);
|
|
966
|
+
}
|
|
967
|
+
if (isPromise(input)) {
|
|
968
|
+
return fromPromise(input);
|
|
969
|
+
}
|
|
970
|
+
if (isAsyncIterable(input)) {
|
|
971
|
+
return fromAsyncIterable(input);
|
|
972
|
+
}
|
|
973
|
+
if (isIterable(input)) {
|
|
974
|
+
return fromIterable(input);
|
|
975
|
+
}
|
|
976
|
+
if (isReadableStreamLike(input)) {
|
|
977
|
+
return fromReadableStreamLike(input);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
throw createInvalidObservableTypeError(input);
|
|
981
|
+
}
|
|
982
|
+
function fromInteropObservable(obj) {
|
|
983
|
+
return new Observable(function (subscriber) {
|
|
984
|
+
var obs = obj[observable]();
|
|
985
|
+
if (isFunction$2(obs.subscribe)) {
|
|
986
|
+
return obs.subscribe(subscriber);
|
|
987
|
+
}
|
|
988
|
+
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
function fromArrayLike(array) {
|
|
992
|
+
return new Observable(function (subscriber) {
|
|
993
|
+
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
994
|
+
subscriber.next(array[i]);
|
|
995
|
+
}
|
|
996
|
+
subscriber.complete();
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
function fromPromise(promise) {
|
|
1000
|
+
return new Observable(function (subscriber) {
|
|
1001
|
+
promise
|
|
1002
|
+
.then(function (value) {
|
|
1003
|
+
if (!subscriber.closed) {
|
|
1004
|
+
subscriber.next(value);
|
|
1005
|
+
subscriber.complete();
|
|
1006
|
+
}
|
|
1007
|
+
}, function (err) { return subscriber.error(err); })
|
|
1008
|
+
.then(null, reportUnhandledError);
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
function fromIterable(iterable) {
|
|
1012
|
+
return new Observable(function (subscriber) {
|
|
1013
|
+
var e_1, _a;
|
|
1014
|
+
try {
|
|
1015
|
+
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
1016
|
+
var value = iterable_1_1.value;
|
|
1017
|
+
subscriber.next(value);
|
|
1018
|
+
if (subscriber.closed) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1024
|
+
finally {
|
|
1025
|
+
try {
|
|
1026
|
+
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
1027
|
+
}
|
|
1028
|
+
finally { if (e_1) throw e_1.error; }
|
|
1029
|
+
}
|
|
1030
|
+
subscriber.complete();
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
function fromAsyncIterable(asyncIterable) {
|
|
1034
|
+
return new Observable(function (subscriber) {
|
|
1035
|
+
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
function fromReadableStreamLike(readableStream) {
|
|
1039
|
+
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
1040
|
+
}
|
|
1041
|
+
function process(asyncIterable, subscriber) {
|
|
1042
|
+
var asyncIterable_1, asyncIterable_1_1;
|
|
1043
|
+
var e_2, _a;
|
|
1044
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1045
|
+
var value, e_2_1;
|
|
1046
|
+
return __generator(this, function (_b) {
|
|
1047
|
+
switch (_b.label) {
|
|
1048
|
+
case 0:
|
|
1049
|
+
_b.trys.push([0, 5, 6, 11]);
|
|
1050
|
+
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
1051
|
+
_b.label = 1;
|
|
1052
|
+
case 1: return [4, asyncIterable_1.next()];
|
|
1053
|
+
case 2:
|
|
1054
|
+
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
1055
|
+
value = asyncIterable_1_1.value;
|
|
1056
|
+
subscriber.next(value);
|
|
1057
|
+
if (subscriber.closed) {
|
|
1058
|
+
return [2];
|
|
1059
|
+
}
|
|
1060
|
+
_b.label = 3;
|
|
1061
|
+
case 3: return [3, 1];
|
|
1062
|
+
case 4: return [3, 11];
|
|
1063
|
+
case 5:
|
|
1064
|
+
e_2_1 = _b.sent();
|
|
1065
|
+
e_2 = { error: e_2_1 };
|
|
1066
|
+
return [3, 11];
|
|
1067
|
+
case 6:
|
|
1068
|
+
_b.trys.push([6, , 9, 10]);
|
|
1069
|
+
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
1070
|
+
return [4, _a.call(asyncIterable_1)];
|
|
1071
|
+
case 7:
|
|
1072
|
+
_b.sent();
|
|
1073
|
+
_b.label = 8;
|
|
1074
|
+
case 8: return [3, 10];
|
|
1075
|
+
case 9:
|
|
1076
|
+
if (e_2) throw e_2.error;
|
|
1077
|
+
return [7];
|
|
1078
|
+
case 10: return [7];
|
|
1079
|
+
case 11:
|
|
1080
|
+
subscriber.complete();
|
|
1081
|
+
return [2];
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1088
|
+
if (delay === void 0) { delay = 0; }
|
|
1089
|
+
if (repeat === void 0) { repeat = false; }
|
|
1090
|
+
var scheduleSubscription = scheduler.schedule(function () {
|
|
1091
|
+
work();
|
|
1092
|
+
if (repeat) {
|
|
1093
|
+
parentSubscription.add(this.schedule(null, delay));
|
|
1094
|
+
}
|
|
1095
|
+
else {
|
|
1096
|
+
this.unsubscribe();
|
|
1097
|
+
}
|
|
1098
|
+
}, delay);
|
|
1099
|
+
parentSubscription.add(scheduleSubscription);
|
|
1100
|
+
if (!repeat) {
|
|
1101
|
+
return scheduleSubscription;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function observeOn(scheduler, delay) {
|
|
1106
|
+
if (delay === void 0) { delay = 0; }
|
|
1107
|
+
return operate(function (source, subscriber) {
|
|
1108
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
function subscribeOn(scheduler, delay) {
|
|
1113
|
+
if (delay === void 0) { delay = 0; }
|
|
1114
|
+
return operate(function (source, subscriber) {
|
|
1115
|
+
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function scheduleObservable(input, scheduler) {
|
|
1120
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function schedulePromise(input, scheduler) {
|
|
1124
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function scheduleArray(input, scheduler) {
|
|
1128
|
+
return new Observable(function (subscriber) {
|
|
1129
|
+
var i = 0;
|
|
1130
|
+
return scheduler.schedule(function () {
|
|
1131
|
+
if (i === input.length) {
|
|
1132
|
+
subscriber.complete();
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
subscriber.next(input[i++]);
|
|
1136
|
+
if (!subscriber.closed) {
|
|
1137
|
+
this.schedule();
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function scheduleIterable(input, scheduler) {
|
|
1145
|
+
return new Observable(function (subscriber) {
|
|
1146
|
+
var iterator$1;
|
|
1147
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1148
|
+
iterator$1 = input[iterator]();
|
|
1149
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1150
|
+
var _a;
|
|
1151
|
+
var value;
|
|
1152
|
+
var done;
|
|
1153
|
+
try {
|
|
1154
|
+
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1155
|
+
}
|
|
1156
|
+
catch (err) {
|
|
1157
|
+
subscriber.error(err);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (done) {
|
|
1161
|
+
subscriber.complete();
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
subscriber.next(value);
|
|
1165
|
+
}
|
|
1166
|
+
}, 0, true);
|
|
1167
|
+
});
|
|
1168
|
+
return function () { return isFunction$2(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function scheduleAsyncIterable(input, scheduler) {
|
|
1173
|
+
if (!input) {
|
|
1174
|
+
throw new Error('Iterable cannot be null');
|
|
1175
|
+
}
|
|
1176
|
+
return new Observable(function (subscriber) {
|
|
1177
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1178
|
+
var iterator = input[Symbol.asyncIterator]();
|
|
1179
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1180
|
+
iterator.next().then(function (result) {
|
|
1181
|
+
if (result.done) {
|
|
1182
|
+
subscriber.complete();
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
subscriber.next(result.value);
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
}, 0, true);
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function scheduleReadableStreamLike(input, scheduler) {
|
|
1194
|
+
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function scheduled(input, scheduler) {
|
|
1198
|
+
if (input != null) {
|
|
1199
|
+
if (isInteropObservable(input)) {
|
|
1200
|
+
return scheduleObservable(input, scheduler);
|
|
1201
|
+
}
|
|
1202
|
+
if (isArrayLike(input)) {
|
|
1203
|
+
return scheduleArray(input, scheduler);
|
|
1204
|
+
}
|
|
1205
|
+
if (isPromise(input)) {
|
|
1206
|
+
return schedulePromise(input, scheduler);
|
|
1207
|
+
}
|
|
1208
|
+
if (isAsyncIterable(input)) {
|
|
1209
|
+
return scheduleAsyncIterable(input, scheduler);
|
|
1210
|
+
}
|
|
1211
|
+
if (isIterable(input)) {
|
|
1212
|
+
return scheduleIterable(input, scheduler);
|
|
1213
|
+
}
|
|
1214
|
+
if (isReadableStreamLike(input)) {
|
|
1215
|
+
return scheduleReadableStreamLike(input, scheduler);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
throw createInvalidObservableTypeError(input);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
function from(input, scheduler) {
|
|
1222
|
+
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
function map$1(project, thisArg) {
|
|
1226
|
+
return operate(function (source, subscriber) {
|
|
1227
|
+
var index = 0;
|
|
1228
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1229
|
+
subscriber.next(project.call(thisArg, value, index++));
|
|
1230
|
+
}));
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
var isArray$1 = Array.isArray;
|
|
1235
|
+
function callOrApply(fn, args) {
|
|
1236
|
+
return isArray$1(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
|
|
1237
|
+
}
|
|
1238
|
+
function mapOneOrManyArgs(fn) {
|
|
1239
|
+
return map$1(function (args) { return callOrApply(fn, args); });
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
var isArray = Array.isArray;
|
|
1243
|
+
var getPrototypeOf = Object.getPrototypeOf, objectProto = Object.prototype, getKeys = Object.keys;
|
|
1244
|
+
function argsArgArrayOrObject(args) {
|
|
1245
|
+
if (args.length === 1) {
|
|
1246
|
+
var first_1 = args[0];
|
|
1247
|
+
if (isArray(first_1)) {
|
|
1248
|
+
return { args: first_1, keys: null };
|
|
1249
|
+
}
|
|
1250
|
+
if (isPOJO(first_1)) {
|
|
1251
|
+
var keys = getKeys(first_1);
|
|
1252
|
+
return {
|
|
1253
|
+
args: keys.map(function (key) { return first_1[key]; }),
|
|
1254
|
+
keys: keys,
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
return { args: args, keys: null };
|
|
1259
|
+
}
|
|
1260
|
+
function isPOJO(obj) {
|
|
1261
|
+
return obj && typeof obj === 'object' && getPrototypeOf(obj) === objectProto;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function createObject(keys, values) {
|
|
1265
|
+
return keys.reduce(function (result, key, i) { return ((result[key] = values[i]), result); }, {});
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function combineLatest() {
|
|
1269
|
+
var args = [];
|
|
1270
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1271
|
+
args[_i] = arguments[_i];
|
|
1272
|
+
}
|
|
1273
|
+
var scheduler = popScheduler(args);
|
|
1274
|
+
var resultSelector = popResultSelector(args);
|
|
1275
|
+
var _a = argsArgArrayOrObject(args), observables = _a.args, keys = _a.keys;
|
|
1276
|
+
if (observables.length === 0) {
|
|
1277
|
+
return from([], scheduler);
|
|
1278
|
+
}
|
|
1279
|
+
var result = new Observable(combineLatestInit(observables, scheduler, keys
|
|
1280
|
+
?
|
|
1281
|
+
function (values) { return createObject(keys, values); }
|
|
1282
|
+
:
|
|
1283
|
+
identity));
|
|
1284
|
+
return resultSelector ? result.pipe(mapOneOrManyArgs(resultSelector)) : result;
|
|
1285
|
+
}
|
|
1286
|
+
function combineLatestInit(observables, scheduler, valueTransform) {
|
|
1287
|
+
if (valueTransform === void 0) { valueTransform = identity; }
|
|
1288
|
+
return function (subscriber) {
|
|
1289
|
+
maybeSchedule(scheduler, function () {
|
|
1290
|
+
var length = observables.length;
|
|
1291
|
+
var values = new Array(length);
|
|
1292
|
+
var active = length;
|
|
1293
|
+
var remainingFirstValues = length;
|
|
1294
|
+
var _loop_1 = function (i) {
|
|
1295
|
+
maybeSchedule(scheduler, function () {
|
|
1296
|
+
var source = from(observables[i], scheduler);
|
|
1297
|
+
var hasFirstValue = false;
|
|
1298
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1299
|
+
values[i] = value;
|
|
1300
|
+
if (!hasFirstValue) {
|
|
1301
|
+
hasFirstValue = true;
|
|
1302
|
+
remainingFirstValues--;
|
|
1303
|
+
}
|
|
1304
|
+
if (!remainingFirstValues) {
|
|
1305
|
+
subscriber.next(valueTransform(values.slice()));
|
|
1306
|
+
}
|
|
1307
|
+
}, function () {
|
|
1308
|
+
if (!--active) {
|
|
1309
|
+
subscriber.complete();
|
|
1310
|
+
}
|
|
1311
|
+
}));
|
|
1312
|
+
}, subscriber);
|
|
1313
|
+
};
|
|
1314
|
+
for (var i = 0; i < length; i++) {
|
|
1315
|
+
_loop_1(i);
|
|
1316
|
+
}
|
|
1317
|
+
}, subscriber);
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
function maybeSchedule(scheduler, execute, subscription) {
|
|
1321
|
+
if (scheduler) {
|
|
1322
|
+
executeSchedule(subscription, scheduler, execute);
|
|
1323
|
+
}
|
|
1324
|
+
else {
|
|
1325
|
+
execute();
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
const subject = new BehaviorSubject(false);
|
|
1330
|
+
const env = {
|
|
1331
|
+
isDevelopment: () => subject.getValue(),
|
|
1332
|
+
set: (isDevelopment) => {
|
|
1333
|
+
subject.next(isDevelopment);
|
|
1334
|
+
},
|
|
1335
|
+
subject
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
const ACCOUNT_PREFIX = 'account:';
|
|
1339
|
+
const ADDRESS_PREFIX = 'address:';
|
|
1340
|
+
const CONTRACT_PREFIX = 'contract:';
|
|
1341
|
+
function toHex(address) {
|
|
1342
|
+
return util$7.u8aToHex(
|
|
1343
|
+
keyring$1.decodeAddress(address, true));
|
|
1344
|
+
}
|
|
1345
|
+
function accountKey(address) {
|
|
1346
|
+
return `${ACCOUNT_PREFIX}${toHex(address)}`;
|
|
1347
|
+
}
|
|
1348
|
+
function addressKey(address) {
|
|
1349
|
+
return `${ADDRESS_PREFIX}${toHex(address)}`;
|
|
1350
|
+
}
|
|
1351
|
+
function contractKey(address) {
|
|
1352
|
+
return `${CONTRACT_PREFIX}${toHex(address)}`;
|
|
1353
|
+
}
|
|
1354
|
+
const accountRegex = new RegExp(`^${ACCOUNT_PREFIX}0x[0-9a-f]*`, '');
|
|
1355
|
+
const addressRegex = new RegExp(`^${ADDRESS_PREFIX}0x[0-9a-f]*`, '');
|
|
1356
|
+
const contractRegex = new RegExp(`^${CONTRACT_PREFIX}0x[0-9a-f]*`, '');
|
|
1357
|
+
|
|
1358
|
+
function createOptionItem(address, _name) {
|
|
1359
|
+
const name = util$7.isUndefined(_name)
|
|
1360
|
+
? ((address.length > 15)
|
|
1361
|
+
? `${address.slice(0, 6)}…${address.slice(-6)}`
|
|
1362
|
+
: address)
|
|
1363
|
+
: _name;
|
|
1364
|
+
return {
|
|
1365
|
+
key: address,
|
|
1366
|
+
name,
|
|
1367
|
+
value: address
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
function callNext(current, subject, withTest) {
|
|
1372
|
+
const isDevMode = env.isDevelopment();
|
|
1373
|
+
const filtered = {};
|
|
1374
|
+
Object.keys(current).forEach((key) => {
|
|
1375
|
+
const { json: { meta: { isTesting = false } = {} } = {} } = current[key];
|
|
1376
|
+
if (!withTest || isDevMode || isTesting !== true) {
|
|
1377
|
+
filtered[key] = current[key];
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
subject.next(filtered);
|
|
1381
|
+
}
|
|
1382
|
+
function genericSubject(keyCreator, withTest = false) {
|
|
1383
|
+
let current = {};
|
|
1384
|
+
const subject = new BehaviorSubject({});
|
|
1385
|
+
const next = () => callNext(current, subject, withTest);
|
|
1386
|
+
env.subject.subscribe(next);
|
|
1387
|
+
return {
|
|
1388
|
+
add: (store, address, json, type) => {
|
|
1389
|
+
current = util$7.objectCopy(current);
|
|
1390
|
+
current[address] = {
|
|
1391
|
+
json: util$7.objectSpread({}, json, { address }),
|
|
1392
|
+
option: createOptionItem(address, json.meta.name),
|
|
1393
|
+
type
|
|
1394
|
+
};
|
|
1395
|
+
if (!json.meta.isInjected && (!json.meta.isTesting || env.isDevelopment())) {
|
|
1396
|
+
store.set(keyCreator(address), json);
|
|
1397
|
+
}
|
|
1398
|
+
next();
|
|
1399
|
+
return current[address];
|
|
1400
|
+
},
|
|
1401
|
+
remove: (store, address) => {
|
|
1402
|
+
current = util$7.objectCopy(current);
|
|
1403
|
+
delete current[address];
|
|
1404
|
+
store.remove(keyCreator(address));
|
|
1405
|
+
next();
|
|
1406
|
+
},
|
|
1407
|
+
subject
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
const accounts = genericSubject(accountKey, true);
|
|
1412
|
+
|
|
1413
|
+
const addresses = genericSubject(addressKey);
|
|
1414
|
+
|
|
1415
|
+
const contracts = genericSubject(contractKey);
|
|
1416
|
+
|
|
1417
|
+
const obervableAll = combineLatest([
|
|
1418
|
+
accounts.subject,
|
|
1419
|
+
addresses.subject,
|
|
1420
|
+
contracts.subject
|
|
1421
|
+
]).pipe(map$1(([accounts, addresses, contracts]) => ({
|
|
1422
|
+
accounts,
|
|
1423
|
+
addresses,
|
|
1424
|
+
contracts
|
|
1425
|
+
})));
|
|
1426
|
+
|
|
1427
|
+
let hasCalledInitOptions = false;
|
|
1428
|
+
const sortByName = (a, b) => {
|
|
1429
|
+
const valueA = a.option.name;
|
|
1430
|
+
const valueB = b.option.name;
|
|
1431
|
+
return valueA.localeCompare(valueB);
|
|
1432
|
+
};
|
|
1433
|
+
const sortByCreated = (a, b) => {
|
|
1434
|
+
const valueA = a.json.meta.whenCreated || 0;
|
|
1435
|
+
const valueB = b.json.meta.whenCreated || 0;
|
|
1436
|
+
if (valueA < valueB) {
|
|
1437
|
+
return 1;
|
|
1438
|
+
}
|
|
1439
|
+
if (valueA > valueB) {
|
|
1440
|
+
return -1;
|
|
1441
|
+
}
|
|
1442
|
+
return 0;
|
|
1443
|
+
};
|
|
1444
|
+
class KeyringOption {
|
|
1445
|
+
#allSub = null;
|
|
1446
|
+
optionsSubject = new BehaviorSubject(this.emptyOptions());
|
|
1447
|
+
createOptionHeader(name) {
|
|
1448
|
+
return {
|
|
1449
|
+
key: `header-${name.toLowerCase()}`,
|
|
1450
|
+
name,
|
|
1451
|
+
value: null
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
init(keyring) {
|
|
1455
|
+
if (hasCalledInitOptions) {
|
|
1456
|
+
throw new Error('Unable to initialise options more than once');
|
|
1457
|
+
}
|
|
1458
|
+
this.#allSub = obervableAll.subscribe(() => {
|
|
1459
|
+
const opts = this.emptyOptions();
|
|
1460
|
+
this.addAccounts(keyring, opts);
|
|
1461
|
+
this.addAddresses(keyring, opts);
|
|
1462
|
+
this.addContracts(keyring, opts);
|
|
1463
|
+
opts.address = this.linkItems({ Addresses: opts.address, Recent: opts.recent });
|
|
1464
|
+
opts.account = this.linkItems({ Accounts: opts.account, Development: opts.testing });
|
|
1465
|
+
opts.contract = this.linkItems({ Contracts: opts.contract });
|
|
1466
|
+
opts.all = [].concat(opts.account, opts.address);
|
|
1467
|
+
opts.allPlus = [].concat(opts.account, opts.address, opts.contract);
|
|
1468
|
+
this.optionsSubject.next(opts);
|
|
1469
|
+
});
|
|
1470
|
+
hasCalledInitOptions = true;
|
|
1471
|
+
}
|
|
1472
|
+
clear() {
|
|
1473
|
+
if (this.#allSub) {
|
|
1474
|
+
this.#allSub.unsubscribe();
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
linkItems(items) {
|
|
1478
|
+
return Object.keys(items).reduce((result, header) => {
|
|
1479
|
+
const options = items[header];
|
|
1480
|
+
return result.concat(options.length
|
|
1481
|
+
? [this.createOptionHeader(header)]
|
|
1482
|
+
: [], options);
|
|
1483
|
+
}, []);
|
|
1484
|
+
}
|
|
1485
|
+
addAccounts(keyring, options) {
|
|
1486
|
+
const available = keyring.accounts.subject.getValue();
|
|
1487
|
+
Object
|
|
1488
|
+
.values(available)
|
|
1489
|
+
.sort(sortByName)
|
|
1490
|
+
.forEach(({ json: { meta: { isTesting = false } }, option }) => {
|
|
1491
|
+
if (!isTesting) {
|
|
1492
|
+
options.account.push(option);
|
|
1493
|
+
}
|
|
1494
|
+
else {
|
|
1495
|
+
options.testing.push(option);
|
|
1496
|
+
}
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
addAddresses(keyring, options) {
|
|
1500
|
+
const available = keyring.addresses.subject.getValue();
|
|
1501
|
+
Object
|
|
1502
|
+
.values(available)
|
|
1503
|
+
.filter(({ json }) => !!json.meta.isRecent)
|
|
1504
|
+
.sort(sortByCreated)
|
|
1505
|
+
.forEach(({ option }) => {
|
|
1506
|
+
options.recent.push(option);
|
|
1507
|
+
});
|
|
1508
|
+
Object
|
|
1509
|
+
.values(available)
|
|
1510
|
+
.filter(({ json }) => !json.meta.isRecent)
|
|
1511
|
+
.sort(sortByName)
|
|
1512
|
+
.forEach(({ option }) => {
|
|
1513
|
+
options.address.push(option);
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
addContracts(keyring, options) {
|
|
1517
|
+
const available = keyring.contracts.subject.getValue();
|
|
1518
|
+
Object
|
|
1519
|
+
.values(available)
|
|
1520
|
+
.sort(sortByName)
|
|
1521
|
+
.forEach(({ option }) => {
|
|
1522
|
+
options.contract.push(option);
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
emptyOptions() {
|
|
1526
|
+
return {
|
|
1527
|
+
account: [],
|
|
1528
|
+
address: [],
|
|
1529
|
+
all: [],
|
|
1530
|
+
allPlus: [],
|
|
1531
|
+
contract: [],
|
|
1532
|
+
recent: [],
|
|
1533
|
+
testing: []
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1539
|
+
|
|
1540
|
+
function getDefaultExportFromCjs (x) {
|
|
1541
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
var assign = make_assign();
|
|
1545
|
+
var create$1 = make_create();
|
|
1546
|
+
var trim$1 = make_trim();
|
|
1547
|
+
var Global$5 = (typeof window !== 'undefined' ? window : commonjsGlobal);
|
|
1548
|
+
var util$6 = {
|
|
1549
|
+
assign: assign,
|
|
1550
|
+
create: create$1,
|
|
1551
|
+
trim: trim$1,
|
|
1552
|
+
bind: bind$1,
|
|
1553
|
+
slice: slice$1,
|
|
1554
|
+
each: each$7,
|
|
1555
|
+
map: map,
|
|
1556
|
+
pluck: pluck$1,
|
|
1557
|
+
isList: isList$1,
|
|
1558
|
+
isFunction: isFunction$1,
|
|
1559
|
+
isObject: isObject$1,
|
|
1560
|
+
Global: Global$5
|
|
1561
|
+
};
|
|
1562
|
+
function make_assign() {
|
|
1563
|
+
if (Object.assign) {
|
|
1564
|
+
return Object.assign
|
|
1565
|
+
} else {
|
|
1566
|
+
return function shimAssign(obj, props1, props2, etc) {
|
|
1567
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1568
|
+
each$7(Object(arguments[i]), function(val, key) {
|
|
1569
|
+
obj[key] = val;
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return obj
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
function make_create() {
|
|
1577
|
+
if (Object.create) {
|
|
1578
|
+
return function create(obj, assignProps1, assignProps2, etc) {
|
|
1579
|
+
var assignArgsList = slice$1(arguments, 1);
|
|
1580
|
+
return assign.apply(this, [Object.create(obj)].concat(assignArgsList))
|
|
1581
|
+
}
|
|
1582
|
+
} else {
|
|
1583
|
+
function F() {}
|
|
1584
|
+
return function create(obj, assignProps1, assignProps2, etc) {
|
|
1585
|
+
var assignArgsList = slice$1(arguments, 1);
|
|
1586
|
+
F.prototype = obj;
|
|
1587
|
+
return assign.apply(this, [new F()].concat(assignArgsList))
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function make_trim() {
|
|
1592
|
+
if (String.prototype.trim) {
|
|
1593
|
+
return function trim(str) {
|
|
1594
|
+
return String.prototype.trim.call(str)
|
|
1595
|
+
}
|
|
1596
|
+
} else {
|
|
1597
|
+
return function trim(str) {
|
|
1598
|
+
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
function bind$1(obj, fn) {
|
|
1603
|
+
return function() {
|
|
1604
|
+
return fn.apply(obj, Array.prototype.slice.call(arguments, 0))
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
function slice$1(arr, index) {
|
|
1608
|
+
return Array.prototype.slice.call(arr, index || 0)
|
|
1609
|
+
}
|
|
1610
|
+
function each$7(obj, fn) {
|
|
1611
|
+
pluck$1(obj, function(val, key) {
|
|
1612
|
+
fn(val, key);
|
|
1613
|
+
return false
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
function map(obj, fn) {
|
|
1617
|
+
var res = (isList$1(obj) ? [] : {});
|
|
1618
|
+
pluck$1(obj, function(v, k) {
|
|
1619
|
+
res[k] = fn(v, k);
|
|
1620
|
+
return false
|
|
1621
|
+
});
|
|
1622
|
+
return res
|
|
1623
|
+
}
|
|
1624
|
+
function pluck$1(obj, fn) {
|
|
1625
|
+
if (isList$1(obj)) {
|
|
1626
|
+
for (var i=0; i<obj.length; i++) {
|
|
1627
|
+
if (fn(obj[i], i)) {
|
|
1628
|
+
return obj[i]
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
} else {
|
|
1632
|
+
for (var key in obj) {
|
|
1633
|
+
if (obj.hasOwnProperty(key)) {
|
|
1634
|
+
if (fn(obj[key], key)) {
|
|
1635
|
+
return obj[key]
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function isList$1(val) {
|
|
1642
|
+
return (val != null && typeof val != 'function' && typeof val.length == 'number')
|
|
1643
|
+
}
|
|
1644
|
+
function isFunction$1(val) {
|
|
1645
|
+
return val && {}.toString.call(val) === '[object Function]'
|
|
1646
|
+
}
|
|
1647
|
+
function isObject$1(val) {
|
|
1648
|
+
return val && {}.toString.call(val) === '[object Object]'
|
|
1649
|
+
}
|
|
1650
|
+
getDefaultExportFromCjs(util$6);
|
|
1651
|
+
|
|
1652
|
+
var util$5 = util$6;
|
|
1653
|
+
var slice = util$5.slice;
|
|
1654
|
+
var pluck = util$5.pluck;
|
|
1655
|
+
var each$6 = util$5.each;
|
|
1656
|
+
var bind = util$5.bind;
|
|
1657
|
+
var create = util$5.create;
|
|
1658
|
+
var isList = util$5.isList;
|
|
1659
|
+
var isFunction = util$5.isFunction;
|
|
1660
|
+
var isObject = util$5.isObject;
|
|
1661
|
+
var storeEngine = {
|
|
1662
|
+
createStore: createStore
|
|
1663
|
+
};
|
|
1664
|
+
var storeAPI = {
|
|
1665
|
+
version: '2.0.12',
|
|
1666
|
+
enabled: false,
|
|
1667
|
+
get: function(key, optionalDefaultValue) {
|
|
1668
|
+
var data = this.storage.read(this._namespacePrefix + key);
|
|
1669
|
+
return this._deserialize(data, optionalDefaultValue)
|
|
1670
|
+
},
|
|
1671
|
+
set: function(key, value) {
|
|
1672
|
+
if (value === undefined) {
|
|
1673
|
+
return this.remove(key)
|
|
1674
|
+
}
|
|
1675
|
+
this.storage.write(this._namespacePrefix + key, this._serialize(value));
|
|
1676
|
+
return value
|
|
1677
|
+
},
|
|
1678
|
+
remove: function(key) {
|
|
1679
|
+
this.storage.remove(this._namespacePrefix + key);
|
|
1680
|
+
},
|
|
1681
|
+
each: function(callback) {
|
|
1682
|
+
var self = this;
|
|
1683
|
+
this.storage.each(function(val, namespacedKey) {
|
|
1684
|
+
callback.call(self, self._deserialize(val), (namespacedKey || '').replace(self._namespaceRegexp, ''));
|
|
1685
|
+
});
|
|
1686
|
+
},
|
|
1687
|
+
clearAll: function() {
|
|
1688
|
+
this.storage.clearAll();
|
|
1689
|
+
},
|
|
1690
|
+
hasNamespace: function(namespace) {
|
|
1691
|
+
return (this._namespacePrefix == '__storejs_'+namespace+'_')
|
|
1692
|
+
},
|
|
1693
|
+
createStore: function() {
|
|
1694
|
+
return createStore.apply(this, arguments)
|
|
1695
|
+
},
|
|
1696
|
+
addPlugin: function(plugin) {
|
|
1697
|
+
this._addPlugin(plugin);
|
|
1698
|
+
},
|
|
1699
|
+
namespace: function(namespace) {
|
|
1700
|
+
return createStore(this.storage, this.plugins, namespace)
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
function _warn() {
|
|
1704
|
+
var _console = (typeof console == 'undefined' ? null : console);
|
|
1705
|
+
if (!_console) { return }
|
|
1706
|
+
var fn = (_console.warn ? _console.warn : _console.log);
|
|
1707
|
+
fn.apply(_console, arguments);
|
|
1708
|
+
}
|
|
1709
|
+
function createStore(storages, plugins, namespace) {
|
|
1710
|
+
if (!namespace) {
|
|
1711
|
+
namespace = '';
|
|
1712
|
+
}
|
|
1713
|
+
if (storages && !isList(storages)) {
|
|
1714
|
+
storages = [storages];
|
|
1715
|
+
}
|
|
1716
|
+
if (plugins && !isList(plugins)) {
|
|
1717
|
+
plugins = [plugins];
|
|
1718
|
+
}
|
|
1719
|
+
var namespacePrefix = (namespace ? '__storejs_'+namespace+'_' : '');
|
|
1720
|
+
var namespaceRegexp = (namespace ? new RegExp('^'+namespacePrefix) : null);
|
|
1721
|
+
var legalNamespaces = /^[a-zA-Z0-9_\-]*$/;
|
|
1722
|
+
if (!legalNamespaces.test(namespace)) {
|
|
1723
|
+
throw new Error('store.js namespaces can only have alphanumerics + underscores and dashes')
|
|
1724
|
+
}
|
|
1725
|
+
var _privateStoreProps = {
|
|
1726
|
+
_namespacePrefix: namespacePrefix,
|
|
1727
|
+
_namespaceRegexp: namespaceRegexp,
|
|
1728
|
+
_testStorage: function(storage) {
|
|
1729
|
+
try {
|
|
1730
|
+
var testStr = '__storejs__test__';
|
|
1731
|
+
storage.write(testStr, testStr);
|
|
1732
|
+
var ok = (storage.read(testStr) === testStr);
|
|
1733
|
+
storage.remove(testStr);
|
|
1734
|
+
return ok
|
|
1735
|
+
} catch(e) {
|
|
1736
|
+
return false
|
|
1737
|
+
}
|
|
1738
|
+
},
|
|
1739
|
+
_assignPluginFnProp: function(pluginFnProp, propName) {
|
|
1740
|
+
var oldFn = this[propName];
|
|
1741
|
+
this[propName] = function pluginFn() {
|
|
1742
|
+
var args = slice(arguments, 0);
|
|
1743
|
+
var self = this;
|
|
1744
|
+
function super_fn() {
|
|
1745
|
+
if (!oldFn) { return }
|
|
1746
|
+
each$6(arguments, function(arg, i) {
|
|
1747
|
+
args[i] = arg;
|
|
1748
|
+
});
|
|
1749
|
+
return oldFn.apply(self, args)
|
|
1750
|
+
}
|
|
1751
|
+
var newFnArgs = [super_fn].concat(args);
|
|
1752
|
+
return pluginFnProp.apply(self, newFnArgs)
|
|
1753
|
+
};
|
|
1754
|
+
},
|
|
1755
|
+
_serialize: function(obj) {
|
|
1756
|
+
return JSON.stringify(obj)
|
|
1757
|
+
},
|
|
1758
|
+
_deserialize: function(strVal, defaultVal) {
|
|
1759
|
+
if (!strVal) { return defaultVal }
|
|
1760
|
+
var val = '';
|
|
1761
|
+
try { val = JSON.parse(strVal); }
|
|
1762
|
+
catch(e) { val = strVal; }
|
|
1763
|
+
return (val !== undefined ? val : defaultVal)
|
|
1764
|
+
},
|
|
1765
|
+
_addStorage: function(storage) {
|
|
1766
|
+
if (this.enabled) { return }
|
|
1767
|
+
if (this._testStorage(storage)) {
|
|
1768
|
+
this.storage = storage;
|
|
1769
|
+
this.enabled = true;
|
|
1770
|
+
}
|
|
1771
|
+
},
|
|
1772
|
+
_addPlugin: function(plugin) {
|
|
1773
|
+
var self = this;
|
|
1774
|
+
if (isList(plugin)) {
|
|
1775
|
+
each$6(plugin, function(plugin) {
|
|
1776
|
+
self._addPlugin(plugin);
|
|
1777
|
+
});
|
|
1778
|
+
return
|
|
1779
|
+
}
|
|
1780
|
+
var seenPlugin = pluck(this.plugins, function(seenPlugin) {
|
|
1781
|
+
return (plugin === seenPlugin)
|
|
1782
|
+
});
|
|
1783
|
+
if (seenPlugin) {
|
|
1784
|
+
return
|
|
1785
|
+
}
|
|
1786
|
+
this.plugins.push(plugin);
|
|
1787
|
+
if (!isFunction(plugin)) {
|
|
1788
|
+
throw new Error('Plugins must be function values that return objects')
|
|
1789
|
+
}
|
|
1790
|
+
var pluginProperties = plugin.call(this);
|
|
1791
|
+
if (!isObject(pluginProperties)) {
|
|
1792
|
+
throw new Error('Plugins must return an object of function properties')
|
|
1793
|
+
}
|
|
1794
|
+
each$6(pluginProperties, function(pluginFnProp, propName) {
|
|
1795
|
+
if (!isFunction(pluginFnProp)) {
|
|
1796
|
+
throw new Error('Bad plugin property: '+propName+' from plugin '+plugin.name+'. Plugins should only return functions.')
|
|
1797
|
+
}
|
|
1798
|
+
self._assignPluginFnProp(pluginFnProp, propName);
|
|
1799
|
+
});
|
|
1800
|
+
},
|
|
1801
|
+
addStorage: function(storage) {
|
|
1802
|
+
_warn('store.addStorage(storage) is deprecated. Use createStore([storages])');
|
|
1803
|
+
this._addStorage(storage);
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
var store = create(_privateStoreProps, storeAPI, {
|
|
1807
|
+
plugins: []
|
|
1808
|
+
});
|
|
1809
|
+
store.raw = {};
|
|
1810
|
+
each$6(store, function(prop, propName) {
|
|
1811
|
+
if (isFunction(prop)) {
|
|
1812
|
+
store.raw[propName] = bind(store, prop);
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
each$6(storages, function(storage) {
|
|
1816
|
+
store._addStorage(storage);
|
|
1817
|
+
});
|
|
1818
|
+
each$6(plugins, function(plugin) {
|
|
1819
|
+
store._addPlugin(plugin);
|
|
1820
|
+
});
|
|
1821
|
+
return store
|
|
1822
|
+
}
|
|
1823
|
+
getDefaultExportFromCjs(storeEngine);
|
|
1824
|
+
|
|
1825
|
+
var util$4 = util$6;
|
|
1826
|
+
var Global$4 = util$4.Global;
|
|
1827
|
+
var localStorage_1 = {
|
|
1828
|
+
name: 'localStorage',
|
|
1829
|
+
read: read$5,
|
|
1830
|
+
write: write$5,
|
|
1831
|
+
each: each$5,
|
|
1832
|
+
remove: remove$5,
|
|
1833
|
+
clearAll: clearAll$5,
|
|
1834
|
+
};
|
|
1835
|
+
function localStorage() {
|
|
1836
|
+
return Global$4.localStorage
|
|
1837
|
+
}
|
|
1838
|
+
function read$5(key) {
|
|
1839
|
+
return localStorage().getItem(key)
|
|
1840
|
+
}
|
|
1841
|
+
function write$5(key, data) {
|
|
1842
|
+
return localStorage().setItem(key, data)
|
|
1843
|
+
}
|
|
1844
|
+
function each$5(fn) {
|
|
1845
|
+
for (var i = localStorage().length - 1; i >= 0; i--) {
|
|
1846
|
+
var key = localStorage().key(i);
|
|
1847
|
+
fn(read$5(key), key);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function remove$5(key) {
|
|
1851
|
+
return localStorage().removeItem(key)
|
|
1852
|
+
}
|
|
1853
|
+
function clearAll$5() {
|
|
1854
|
+
return localStorage().clear()
|
|
1855
|
+
}
|
|
1856
|
+
getDefaultExportFromCjs(localStorage_1);
|
|
1857
|
+
|
|
1858
|
+
var util$3 = util$6;
|
|
1859
|
+
var Global$3 = util$3.Global;
|
|
1860
|
+
var oldFFGlobalStorage = {
|
|
1861
|
+
name: 'oldFF-globalStorage',
|
|
1862
|
+
read: read$4,
|
|
1863
|
+
write: write$4,
|
|
1864
|
+
each: each$4,
|
|
1865
|
+
remove: remove$4,
|
|
1866
|
+
clearAll: clearAll$4,
|
|
1867
|
+
};
|
|
1868
|
+
var globalStorage = Global$3.globalStorage;
|
|
1869
|
+
function read$4(key) {
|
|
1870
|
+
return globalStorage[key]
|
|
1871
|
+
}
|
|
1872
|
+
function write$4(key, data) {
|
|
1873
|
+
globalStorage[key] = data;
|
|
1874
|
+
}
|
|
1875
|
+
function each$4(fn) {
|
|
1876
|
+
for (var i = globalStorage.length - 1; i >= 0; i--) {
|
|
1877
|
+
var key = globalStorage.key(i);
|
|
1878
|
+
fn(globalStorage[key], key);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
function remove$4(key) {
|
|
1882
|
+
return globalStorage.removeItem(key)
|
|
1883
|
+
}
|
|
1884
|
+
function clearAll$4() {
|
|
1885
|
+
each$4(function(key, _) {
|
|
1886
|
+
delete globalStorage[key];
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
getDefaultExportFromCjs(oldFFGlobalStorage);
|
|
1890
|
+
|
|
1891
|
+
var util$2 = util$6;
|
|
1892
|
+
var Global$2 = util$2.Global;
|
|
1893
|
+
var oldIEUserDataStorage = {
|
|
1894
|
+
name: 'oldIE-userDataStorage',
|
|
1895
|
+
write: write$3,
|
|
1896
|
+
read: read$3,
|
|
1897
|
+
each: each$3,
|
|
1898
|
+
remove: remove$3,
|
|
1899
|
+
clearAll: clearAll$3,
|
|
1900
|
+
};
|
|
1901
|
+
var storageName = 'storejs';
|
|
1902
|
+
var doc$1 = Global$2.document;
|
|
1903
|
+
var _withStorageEl = _makeIEStorageElFunction();
|
|
1904
|
+
var disable = (Global$2.navigator ? Global$2.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\./);
|
|
1905
|
+
function write$3(unfixedKey, data) {
|
|
1906
|
+
if (disable) { return }
|
|
1907
|
+
var fixedKey = fixKey(unfixedKey);
|
|
1908
|
+
_withStorageEl(function(storageEl) {
|
|
1909
|
+
storageEl.setAttribute(fixedKey, data);
|
|
1910
|
+
storageEl.save(storageName);
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
function read$3(unfixedKey) {
|
|
1914
|
+
if (disable) { return }
|
|
1915
|
+
var fixedKey = fixKey(unfixedKey);
|
|
1916
|
+
var res = null;
|
|
1917
|
+
_withStorageEl(function(storageEl) {
|
|
1918
|
+
res = storageEl.getAttribute(fixedKey);
|
|
1919
|
+
});
|
|
1920
|
+
return res
|
|
1921
|
+
}
|
|
1922
|
+
function each$3(callback) {
|
|
1923
|
+
_withStorageEl(function(storageEl) {
|
|
1924
|
+
var attributes = storageEl.XMLDocument.documentElement.attributes;
|
|
1925
|
+
for (var i=attributes.length-1; i>=0; i--) {
|
|
1926
|
+
var attr = attributes[i];
|
|
1927
|
+
callback(storageEl.getAttribute(attr.name), attr.name);
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
function remove$3(unfixedKey) {
|
|
1932
|
+
var fixedKey = fixKey(unfixedKey);
|
|
1933
|
+
_withStorageEl(function(storageEl) {
|
|
1934
|
+
storageEl.removeAttribute(fixedKey);
|
|
1935
|
+
storageEl.save(storageName);
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
function clearAll$3() {
|
|
1939
|
+
_withStorageEl(function(storageEl) {
|
|
1940
|
+
var attributes = storageEl.XMLDocument.documentElement.attributes;
|
|
1941
|
+
storageEl.load(storageName);
|
|
1942
|
+
for (var i=attributes.length-1; i>=0; i--) {
|
|
1943
|
+
storageEl.removeAttribute(attributes[i].name);
|
|
1944
|
+
}
|
|
1945
|
+
storageEl.save(storageName);
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
var forbiddenCharsRegex = new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]", "g");
|
|
1949
|
+
function fixKey(key) {
|
|
1950
|
+
return key.replace(/^\d/, '___$&').replace(forbiddenCharsRegex, '___')
|
|
1951
|
+
}
|
|
1952
|
+
function _makeIEStorageElFunction() {
|
|
1953
|
+
if (!doc$1 || !doc$1.documentElement || !doc$1.documentElement.addBehavior) {
|
|
1954
|
+
return null
|
|
1955
|
+
}
|
|
1956
|
+
var scriptTag = 'script',
|
|
1957
|
+
storageOwner,
|
|
1958
|
+
storageContainer,
|
|
1959
|
+
storageEl;
|
|
1960
|
+
try {
|
|
1961
|
+
storageContainer = new ActiveXObject('htmlfile');
|
|
1962
|
+
storageContainer.open();
|
|
1963
|
+
storageContainer.write('<'+scriptTag+'>document.w=window</'+scriptTag+'><iframe src="/favicon.ico"></iframe>');
|
|
1964
|
+
storageContainer.close();
|
|
1965
|
+
storageOwner = storageContainer.w.frames[0].document;
|
|
1966
|
+
storageEl = storageOwner.createElement('div');
|
|
1967
|
+
} catch(e) {
|
|
1968
|
+
storageEl = doc$1.createElement('div');
|
|
1969
|
+
storageOwner = doc$1.body;
|
|
1970
|
+
}
|
|
1971
|
+
return function(storeFunction) {
|
|
1972
|
+
var args = [].slice.call(arguments, 0);
|
|
1973
|
+
args.unshift(storageEl);
|
|
1974
|
+
storageOwner.appendChild(storageEl);
|
|
1975
|
+
storageEl.addBehavior('#default#userData');
|
|
1976
|
+
storageEl.load(storageName);
|
|
1977
|
+
storeFunction.apply(this, args);
|
|
1978
|
+
storageOwner.removeChild(storageEl);
|
|
1979
|
+
return
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
getDefaultExportFromCjs(oldIEUserDataStorage);
|
|
1983
|
+
|
|
1984
|
+
var util$1 = util$6;
|
|
1985
|
+
var Global$1 = util$1.Global;
|
|
1986
|
+
var trim = util$1.trim;
|
|
1987
|
+
var cookieStorage = {
|
|
1988
|
+
name: 'cookieStorage',
|
|
1989
|
+
read: read$2,
|
|
1990
|
+
write: write$2,
|
|
1991
|
+
each: each$2,
|
|
1992
|
+
remove: remove$2,
|
|
1993
|
+
clearAll: clearAll$2,
|
|
1994
|
+
};
|
|
1995
|
+
var doc = Global$1.document;
|
|
1996
|
+
function read$2(key) {
|
|
1997
|
+
if (!key || !_has(key)) { return null }
|
|
1998
|
+
var regexpStr = "(?:^|.*;\\s*)" +
|
|
1999
|
+
escape(key).replace(/[\-\.\+\*]/g, "\\$&") +
|
|
2000
|
+
"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
|
|
2001
|
+
return unescape(doc.cookie.replace(new RegExp(regexpStr), "$1"))
|
|
2002
|
+
}
|
|
2003
|
+
function each$2(callback) {
|
|
2004
|
+
var cookies = doc.cookie.split(/; ?/g);
|
|
2005
|
+
for (var i = cookies.length - 1; i >= 0; i--) {
|
|
2006
|
+
if (!trim(cookies[i])) {
|
|
2007
|
+
continue
|
|
2008
|
+
}
|
|
2009
|
+
var kvp = cookies[i].split('=');
|
|
2010
|
+
var key = unescape(kvp[0]);
|
|
2011
|
+
var val = unescape(kvp[1]);
|
|
2012
|
+
callback(val, key);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
function write$2(key, data) {
|
|
2016
|
+
if(!key) { return }
|
|
2017
|
+
doc.cookie = escape(key) + "=" + escape(data) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
|
|
2018
|
+
}
|
|
2019
|
+
function remove$2(key) {
|
|
2020
|
+
if (!key || !_has(key)) {
|
|
2021
|
+
return
|
|
2022
|
+
}
|
|
2023
|
+
doc.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
|
|
2024
|
+
}
|
|
2025
|
+
function clearAll$2() {
|
|
2026
|
+
each$2(function(_, key) {
|
|
2027
|
+
remove$2(key);
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
function _has(key) {
|
|
2031
|
+
return (new RegExp("(?:^|;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(doc.cookie)
|
|
2032
|
+
}
|
|
2033
|
+
getDefaultExportFromCjs(cookieStorage);
|
|
2034
|
+
|
|
2035
|
+
var util = util$6;
|
|
2036
|
+
var Global = util.Global;
|
|
2037
|
+
var sessionStorage_1 = {
|
|
2038
|
+
name: 'sessionStorage',
|
|
2039
|
+
read: read$1,
|
|
2040
|
+
write: write$1,
|
|
2041
|
+
each: each$1,
|
|
2042
|
+
remove: remove$1,
|
|
2043
|
+
clearAll: clearAll$1
|
|
2044
|
+
};
|
|
2045
|
+
function sessionStorage() {
|
|
2046
|
+
return Global.sessionStorage
|
|
2047
|
+
}
|
|
2048
|
+
function read$1(key) {
|
|
2049
|
+
return sessionStorage().getItem(key)
|
|
2050
|
+
}
|
|
2051
|
+
function write$1(key, data) {
|
|
2052
|
+
return sessionStorage().setItem(key, data)
|
|
2053
|
+
}
|
|
2054
|
+
function each$1(fn) {
|
|
2055
|
+
for (var i = sessionStorage().length - 1; i >= 0; i--) {
|
|
2056
|
+
var key = sessionStorage().key(i);
|
|
2057
|
+
fn(read$1(key), key);
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
function remove$1(key) {
|
|
2061
|
+
return sessionStorage().removeItem(key)
|
|
2062
|
+
}
|
|
2063
|
+
function clearAll$1() {
|
|
2064
|
+
return sessionStorage().clear()
|
|
2065
|
+
}
|
|
2066
|
+
getDefaultExportFromCjs(sessionStorage_1);
|
|
2067
|
+
|
|
2068
|
+
var memoryStorage_1 = {
|
|
2069
|
+
name: 'memoryStorage',
|
|
2070
|
+
read: read,
|
|
2071
|
+
write: write,
|
|
2072
|
+
each: each,
|
|
2073
|
+
remove: remove,
|
|
2074
|
+
clearAll: clearAll,
|
|
2075
|
+
};
|
|
2076
|
+
var memoryStorage = {};
|
|
2077
|
+
function read(key) {
|
|
2078
|
+
return memoryStorage[key]
|
|
2079
|
+
}
|
|
2080
|
+
function write(key, data) {
|
|
2081
|
+
memoryStorage[key] = data;
|
|
2082
|
+
}
|
|
2083
|
+
function each(callback) {
|
|
2084
|
+
for (var key in memoryStorage) {
|
|
2085
|
+
if (memoryStorage.hasOwnProperty(key)) {
|
|
2086
|
+
callback(memoryStorage[key], key);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
function remove(key) {
|
|
2091
|
+
delete memoryStorage[key];
|
|
2092
|
+
}
|
|
2093
|
+
function clearAll(key) {
|
|
2094
|
+
memoryStorage = {};
|
|
2095
|
+
}
|
|
2096
|
+
getDefaultExportFromCjs(memoryStorage_1);
|
|
2097
|
+
|
|
2098
|
+
var all = [
|
|
2099
|
+
localStorage_1,
|
|
2100
|
+
oldFFGlobalStorage,
|
|
2101
|
+
oldIEUserDataStorage,
|
|
2102
|
+
cookieStorage,
|
|
2103
|
+
sessionStorage_1,
|
|
2104
|
+
memoryStorage_1
|
|
2105
|
+
];
|
|
2106
|
+
getDefaultExportFromCjs(all);
|
|
2107
|
+
|
|
2108
|
+
var json2$1 = {};
|
|
2109
|
+
|
|
2110
|
+
var hasRequiredJson2;
|
|
2111
|
+
function requireJson2 () {
|
|
2112
|
+
if (hasRequiredJson2) return json2$1;
|
|
2113
|
+
hasRequiredJson2 = 1;
|
|
2114
|
+
if (typeof JSON !== "object") {
|
|
2115
|
+
JSON = {};
|
|
2116
|
+
}
|
|
2117
|
+
(function () {
|
|
2118
|
+
var rx_one = /^[\],:{}\s]*$/;
|
|
2119
|
+
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
|
2120
|
+
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
|
2121
|
+
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
|
|
2122
|
+
var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
2123
|
+
var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
2124
|
+
function f(n) {
|
|
2125
|
+
return n < 10
|
|
2126
|
+
? "0" + n
|
|
2127
|
+
: n;
|
|
2128
|
+
}
|
|
2129
|
+
function this_value() {
|
|
2130
|
+
return this.valueOf();
|
|
2131
|
+
}
|
|
2132
|
+
if (typeof Date.prototype.toJSON !== "function") {
|
|
2133
|
+
Date.prototype.toJSON = function () {
|
|
2134
|
+
return isFinite(this.valueOf())
|
|
2135
|
+
? this.getUTCFullYear() + "-" +
|
|
2136
|
+
f(this.getUTCMonth() + 1) + "-" +
|
|
2137
|
+
f(this.getUTCDate()) + "T" +
|
|
2138
|
+
f(this.getUTCHours()) + ":" +
|
|
2139
|
+
f(this.getUTCMinutes()) + ":" +
|
|
2140
|
+
f(this.getUTCSeconds()) + "Z"
|
|
2141
|
+
: null;
|
|
2142
|
+
};
|
|
2143
|
+
Boolean.prototype.toJSON = this_value;
|
|
2144
|
+
Number.prototype.toJSON = this_value;
|
|
2145
|
+
String.prototype.toJSON = this_value;
|
|
2146
|
+
}
|
|
2147
|
+
var gap;
|
|
2148
|
+
var indent;
|
|
2149
|
+
var meta;
|
|
2150
|
+
var rep;
|
|
2151
|
+
function quote(string) {
|
|
2152
|
+
rx_escapable.lastIndex = 0;
|
|
2153
|
+
return rx_escapable.test(string)
|
|
2154
|
+
? "\"" + string.replace(rx_escapable, function (a) {
|
|
2155
|
+
var c = meta[a];
|
|
2156
|
+
return typeof c === "string"
|
|
2157
|
+
? c
|
|
2158
|
+
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
2159
|
+
}) + "\""
|
|
2160
|
+
: "\"" + string + "\"";
|
|
2161
|
+
}
|
|
2162
|
+
function str(key, holder) {
|
|
2163
|
+
var i;
|
|
2164
|
+
var k;
|
|
2165
|
+
var v;
|
|
2166
|
+
var length;
|
|
2167
|
+
var mind = gap;
|
|
2168
|
+
var partial;
|
|
2169
|
+
var value = holder[key];
|
|
2170
|
+
if (value && typeof value === "object" &&
|
|
2171
|
+
typeof value.toJSON === "function") {
|
|
2172
|
+
value = value.toJSON(key);
|
|
2173
|
+
}
|
|
2174
|
+
if (typeof rep === "function") {
|
|
2175
|
+
value = rep.call(holder, key, value);
|
|
2176
|
+
}
|
|
2177
|
+
switch (typeof value) {
|
|
2178
|
+
case "string":
|
|
2179
|
+
return quote(value);
|
|
2180
|
+
case "number":
|
|
2181
|
+
return isFinite(value)
|
|
2182
|
+
? String(value)
|
|
2183
|
+
: "null";
|
|
2184
|
+
case "boolean":
|
|
2185
|
+
case "null":
|
|
2186
|
+
return String(value);
|
|
2187
|
+
case "object":
|
|
2188
|
+
if (!value) {
|
|
2189
|
+
return "null";
|
|
2190
|
+
}
|
|
2191
|
+
gap += indent;
|
|
2192
|
+
partial = [];
|
|
2193
|
+
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
2194
|
+
length = value.length;
|
|
2195
|
+
for (i = 0; i < length; i += 1) {
|
|
2196
|
+
partial[i] = str(i, value) || "null";
|
|
2197
|
+
}
|
|
2198
|
+
v = partial.length === 0
|
|
2199
|
+
? "[]"
|
|
2200
|
+
: gap
|
|
2201
|
+
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
|
|
2202
|
+
: "[" + partial.join(",") + "]";
|
|
2203
|
+
gap = mind;
|
|
2204
|
+
return v;
|
|
2205
|
+
}
|
|
2206
|
+
if (rep && typeof rep === "object") {
|
|
2207
|
+
length = rep.length;
|
|
2208
|
+
for (i = 0; i < length; i += 1) {
|
|
2209
|
+
if (typeof rep[i] === "string") {
|
|
2210
|
+
k = rep[i];
|
|
2211
|
+
v = str(k, value);
|
|
2212
|
+
if (v) {
|
|
2213
|
+
partial.push(quote(k) + (
|
|
2214
|
+
gap
|
|
2215
|
+
? ": "
|
|
2216
|
+
: ":"
|
|
2217
|
+
) + v);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
} else {
|
|
2222
|
+
for (k in value) {
|
|
2223
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
2224
|
+
v = str(k, value);
|
|
2225
|
+
if (v) {
|
|
2226
|
+
partial.push(quote(k) + (
|
|
2227
|
+
gap
|
|
2228
|
+
? ": "
|
|
2229
|
+
: ":"
|
|
2230
|
+
) + v);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
v = partial.length === 0
|
|
2236
|
+
? "{}"
|
|
2237
|
+
: gap
|
|
2238
|
+
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
|
2239
|
+
: "{" + partial.join(",") + "}";
|
|
2240
|
+
gap = mind;
|
|
2241
|
+
return v;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
if (typeof JSON.stringify !== "function") {
|
|
2245
|
+
meta = {
|
|
2246
|
+
"\b": "\\b",
|
|
2247
|
+
"\t": "\\t",
|
|
2248
|
+
"\n": "\\n",
|
|
2249
|
+
"\f": "\\f",
|
|
2250
|
+
"\r": "\\r",
|
|
2251
|
+
"\"": "\\\"",
|
|
2252
|
+
"\\": "\\\\"
|
|
2253
|
+
};
|
|
2254
|
+
JSON.stringify = function (value, replacer, space) {
|
|
2255
|
+
var i;
|
|
2256
|
+
gap = "";
|
|
2257
|
+
indent = "";
|
|
2258
|
+
if (typeof space === "number") {
|
|
2259
|
+
for (i = 0; i < space; i += 1) {
|
|
2260
|
+
indent += " ";
|
|
2261
|
+
}
|
|
2262
|
+
} else if (typeof space === "string") {
|
|
2263
|
+
indent = space;
|
|
2264
|
+
}
|
|
2265
|
+
rep = replacer;
|
|
2266
|
+
if (replacer && typeof replacer !== "function" &&
|
|
2267
|
+
(typeof replacer !== "object" ||
|
|
2268
|
+
typeof replacer.length !== "number")) {
|
|
2269
|
+
throw new Error("JSON.stringify");
|
|
2270
|
+
}
|
|
2271
|
+
return str("", {"": value});
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
if (typeof JSON.parse !== "function") {
|
|
2275
|
+
JSON.parse = function (text, reviver) {
|
|
2276
|
+
var j;
|
|
2277
|
+
function walk(holder, key) {
|
|
2278
|
+
var k;
|
|
2279
|
+
var v;
|
|
2280
|
+
var value = holder[key];
|
|
2281
|
+
if (value && typeof value === "object") {
|
|
2282
|
+
for (k in value) {
|
|
2283
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
2284
|
+
v = walk(value, k);
|
|
2285
|
+
if (v !== undefined) {
|
|
2286
|
+
value[k] = v;
|
|
2287
|
+
} else {
|
|
2288
|
+
delete value[k];
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
return reviver.call(holder, key, value);
|
|
2294
|
+
}
|
|
2295
|
+
text = String(text);
|
|
2296
|
+
rx_dangerous.lastIndex = 0;
|
|
2297
|
+
if (rx_dangerous.test(text)) {
|
|
2298
|
+
text = text.replace(rx_dangerous, function (a) {
|
|
2299
|
+
return "\\u" +
|
|
2300
|
+
("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
if (
|
|
2304
|
+
rx_one.test(
|
|
2305
|
+
text
|
|
2306
|
+
.replace(rx_two, "@")
|
|
2307
|
+
.replace(rx_three, "]")
|
|
2308
|
+
.replace(rx_four, "")
|
|
2309
|
+
)
|
|
2310
|
+
) {
|
|
2311
|
+
j = eval("(" + text + ")");
|
|
2312
|
+
return (typeof reviver === "function")
|
|
2313
|
+
? walk({"": j}, "")
|
|
2314
|
+
: j;
|
|
2315
|
+
}
|
|
2316
|
+
throw new SyntaxError("JSON.parse");
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
}());
|
|
2320
|
+
return json2$1;
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
var json2 = json2Plugin;
|
|
2324
|
+
function json2Plugin() {
|
|
2325
|
+
requireJson2();
|
|
2326
|
+
return {}
|
|
2327
|
+
}
|
|
2328
|
+
getDefaultExportFromCjs(json2);
|
|
2329
|
+
|
|
2330
|
+
var engine = storeEngine;
|
|
2331
|
+
var storages = all;
|
|
2332
|
+
var plugins = [json2];
|
|
2333
|
+
var store_legacy = engine.createStore(storages, plugins);
|
|
2334
|
+
const store = getDefaultExportFromCjs(store_legacy);
|
|
2335
|
+
|
|
2336
|
+
class BrowserStore {
|
|
2337
|
+
all(fn) {
|
|
2338
|
+
store.each((value, key) => {
|
|
2339
|
+
fn(key, value);
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
get(key, fn) {
|
|
2343
|
+
fn(store.get(key));
|
|
2344
|
+
}
|
|
2345
|
+
remove(key, fn) {
|
|
2346
|
+
store.remove(key);
|
|
2347
|
+
fn && fn();
|
|
2348
|
+
}
|
|
2349
|
+
set(key, value, fn) {
|
|
2350
|
+
store.set(key, value);
|
|
2351
|
+
fn && fn();
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
class Base {
|
|
2356
|
+
#accounts;
|
|
2357
|
+
#addresses;
|
|
2358
|
+
#contracts;
|
|
2359
|
+
#isEthereum;
|
|
2360
|
+
#keyring;
|
|
2361
|
+
_store;
|
|
2362
|
+
_genesisHash;
|
|
2363
|
+
_genesisHashAdd = [];
|
|
2364
|
+
constructor() {
|
|
2365
|
+
this.#accounts = accounts;
|
|
2366
|
+
this.#addresses = addresses;
|
|
2367
|
+
this.#contracts = contracts;
|
|
2368
|
+
this.#isEthereum = false;
|
|
2369
|
+
this._store = new BrowserStore();
|
|
2370
|
+
}
|
|
2371
|
+
get accounts() {
|
|
2372
|
+
return this.#accounts;
|
|
2373
|
+
}
|
|
2374
|
+
get addresses() {
|
|
2375
|
+
return this.#addresses;
|
|
2376
|
+
}
|
|
2377
|
+
get contracts() {
|
|
2378
|
+
return this.#contracts;
|
|
2379
|
+
}
|
|
2380
|
+
get isEthereum() {
|
|
2381
|
+
return this.#isEthereum;
|
|
2382
|
+
}
|
|
2383
|
+
get keyring() {
|
|
2384
|
+
if (this.#keyring) {
|
|
2385
|
+
return this.#keyring;
|
|
2386
|
+
}
|
|
2387
|
+
throw new Error('Keyring should be initialised via \'loadAll\' before use');
|
|
2388
|
+
}
|
|
2389
|
+
get genesisHash() {
|
|
2390
|
+
return this._genesisHash;
|
|
2391
|
+
}
|
|
2392
|
+
get genesisHashes() {
|
|
2393
|
+
return this._genesisHash
|
|
2394
|
+
? [this._genesisHash, ...this._genesisHashAdd]
|
|
2395
|
+
: [...this._genesisHashAdd];
|
|
2396
|
+
}
|
|
2397
|
+
decodeAddress = (key, ignoreChecksum, ss58Format) => {
|
|
2398
|
+
return this.keyring.decodeAddress(key, ignoreChecksum, ss58Format);
|
|
2399
|
+
};
|
|
2400
|
+
encodeAddress = (key, ss58Format) => {
|
|
2401
|
+
return this.keyring.encodeAddress(key, ss58Format);
|
|
2402
|
+
};
|
|
2403
|
+
getPair(address) {
|
|
2404
|
+
return this.keyring.getPair(address);
|
|
2405
|
+
}
|
|
2406
|
+
getPairs() {
|
|
2407
|
+
return this.keyring.getPairs().filter((pair) => env.isDevelopment() || pair.meta.isTesting !== true);
|
|
2408
|
+
}
|
|
2409
|
+
isAvailable(_address) {
|
|
2410
|
+
const accountsValue = this.accounts.subject.getValue();
|
|
2411
|
+
const addressesValue = this.addresses.subject.getValue();
|
|
2412
|
+
const contractsValue = this.contracts.subject.getValue();
|
|
2413
|
+
const address = util$7.isString(_address)
|
|
2414
|
+
? _address
|
|
2415
|
+
: this.encodeAddress(_address);
|
|
2416
|
+
return !accountsValue[address] && !addressesValue[address] && !contractsValue[address];
|
|
2417
|
+
}
|
|
2418
|
+
isPassValid(password) {
|
|
2419
|
+
return password.length > 0;
|
|
2420
|
+
}
|
|
2421
|
+
setSS58Format(ss58Format) {
|
|
2422
|
+
if (this.#keyring && util$7.isNumber(ss58Format)) {
|
|
2423
|
+
this.#keyring.setSS58Format(ss58Format);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
setDevMode(isDevelopment) {
|
|
2427
|
+
env.set(isDevelopment);
|
|
2428
|
+
}
|
|
2429
|
+
initKeyring(options) {
|
|
2430
|
+
const keyring = keyring$1.createTestKeyring(options, true);
|
|
2431
|
+
if (util$7.isBoolean(options.isDevelopment)) {
|
|
2432
|
+
this.setDevMode(options.isDevelopment);
|
|
2433
|
+
}
|
|
2434
|
+
this.#isEthereum = keyring.type === 'ethereum';
|
|
2435
|
+
this.#keyring = keyring;
|
|
2436
|
+
this._genesisHash = options.genesisHash && (util$7.isString(options.genesisHash)
|
|
2437
|
+
? options.genesisHash.toString()
|
|
2438
|
+
: options.genesisHash.toHex());
|
|
2439
|
+
this._genesisHashAdd = options.genesisHashAdd || [];
|
|
2440
|
+
this._store = options.store || this._store;
|
|
2441
|
+
this.addAccountPairs();
|
|
2442
|
+
}
|
|
2443
|
+
addAccountPairs() {
|
|
2444
|
+
this.keyring
|
|
2445
|
+
.getPairs()
|
|
2446
|
+
.forEach(({ address, meta }) => {
|
|
2447
|
+
this.accounts.add(this._store, address, { address, meta });
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
addTimestamp(pair) {
|
|
2451
|
+
if (!pair.meta.whenCreated) {
|
|
2452
|
+
pair.setMeta({ whenCreated: Date.now() });
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
const RECENT_EXPIRY = 24 * 60 * 60;
|
|
2458
|
+
class Keyring extends Base {
|
|
2459
|
+
keyringOption = new KeyringOption();
|
|
2460
|
+
#stores = {
|
|
2461
|
+
account: () => this.accounts,
|
|
2462
|
+
address: () => this.addresses,
|
|
2463
|
+
contract: () => this.contracts
|
|
2464
|
+
};
|
|
2465
|
+
addExternal(address, meta = {}) {
|
|
2466
|
+
const pair = this.keyring.addFromAddress(address, util$7.objectSpread({}, meta, { isExternal: true }), null, meta?.type);
|
|
2467
|
+
return {
|
|
2468
|
+
json: this.saveAccount(pair),
|
|
2469
|
+
pair
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
addHardware(address, hardwareType, meta = {}) {
|
|
2473
|
+
return this.addExternal(address, util$7.objectSpread({}, meta, { hardwareType, isHardware: true }));
|
|
2474
|
+
}
|
|
2475
|
+
addMultisig(addresses, threshold, meta = {}) {
|
|
2476
|
+
let address = utilCrypto.createKeyMulti(addresses, threshold);
|
|
2477
|
+
if (this.isEthereum) {
|
|
2478
|
+
address = address.slice(0, 20);
|
|
2479
|
+
}
|
|
2480
|
+
const who = util$7.u8aSorted(addresses.map((who) => this.decodeAddress(who))).map((who) => this.encodeAddress(who));
|
|
2481
|
+
return this.addExternal(address, util$7.objectSpread({}, meta, { isMultisig: true, threshold: util$7.bnToBn(threshold).toNumber(), who }));
|
|
2482
|
+
}
|
|
2483
|
+
addPair(pair, password) {
|
|
2484
|
+
this.keyring.addPair(pair);
|
|
2485
|
+
return {
|
|
2486
|
+
json: this.saveAccount(pair, password),
|
|
2487
|
+
pair
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
addUri(suri, password, meta = {}, type) {
|
|
2491
|
+
const pair = this.keyring.addFromUri(suri, meta, type);
|
|
2492
|
+
return {
|
|
2493
|
+
json: this.saveAccount(pair, password),
|
|
2494
|
+
pair
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
backupAccount(pair, password) {
|
|
2498
|
+
if (!pair.isLocked) {
|
|
2499
|
+
pair.lock();
|
|
2500
|
+
}
|
|
2501
|
+
pair.decodePkcs8(password);
|
|
2502
|
+
return pair.toJson(password);
|
|
2503
|
+
}
|
|
2504
|
+
async backupAccounts(addresses, password) {
|
|
2505
|
+
const accountPromises = addresses.map((address) => {
|
|
2506
|
+
return new Promise((resolve) => {
|
|
2507
|
+
this._store.get(accountKey(address), resolve);
|
|
2508
|
+
});
|
|
2509
|
+
});
|
|
2510
|
+
const accounts = await Promise.all(accountPromises);
|
|
2511
|
+
return util$7.objectSpread({}, utilCrypto.jsonEncrypt(util$7.stringToU8a(JSON.stringify(accounts)), ['batch-pkcs8'], password), {
|
|
2512
|
+
accounts: accounts.map((account) => ({
|
|
2513
|
+
address: account.address,
|
|
2514
|
+
meta: account.meta
|
|
2515
|
+
}))
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
createFromJson(json, meta = {}) {
|
|
2519
|
+
return this.keyring.createFromJson(util$7.objectSpread({}, json, {
|
|
2520
|
+
meta: util$7.objectSpread({}, json.meta, meta)
|
|
2521
|
+
}));
|
|
2522
|
+
}
|
|
2523
|
+
createFromUri(suri, meta = {}, type) {
|
|
2524
|
+
return this.keyring.createFromUri(suri, meta, type);
|
|
2525
|
+
}
|
|
2526
|
+
encryptAccount(pair, password) {
|
|
2527
|
+
const json = pair.toJson(password);
|
|
2528
|
+
json.meta.whenEdited = Date.now();
|
|
2529
|
+
this.keyring.addFromJson(json);
|
|
2530
|
+
this.accounts.add(this._store, pair.address, json, pair.type);
|
|
2531
|
+
}
|
|
2532
|
+
forgetAccount(address) {
|
|
2533
|
+
this.keyring.removePair(address);
|
|
2534
|
+
this.accounts.remove(this._store, address);
|
|
2535
|
+
}
|
|
2536
|
+
forgetAddress(address) {
|
|
2537
|
+
this.addresses.remove(this._store, address);
|
|
2538
|
+
}
|
|
2539
|
+
forgetContract(address) {
|
|
2540
|
+
this.contracts.remove(this._store, address);
|
|
2541
|
+
}
|
|
2542
|
+
getAccount(address) {
|
|
2543
|
+
return this.getAddress(address, 'account');
|
|
2544
|
+
}
|
|
2545
|
+
getAccounts() {
|
|
2546
|
+
const available = this.accounts.subject.getValue();
|
|
2547
|
+
return Object
|
|
2548
|
+
.keys(available)
|
|
2549
|
+
.map((address) => this.getAddress(address, 'account'))
|
|
2550
|
+
.filter((account) => !!account &&
|
|
2551
|
+
(env.isDevelopment() ||
|
|
2552
|
+
account.meta.isTesting !== true));
|
|
2553
|
+
}
|
|
2554
|
+
getAddress(_address, type = null) {
|
|
2555
|
+
const address = util$7.isString(_address)
|
|
2556
|
+
? _address
|
|
2557
|
+
: this.encodeAddress(_address);
|
|
2558
|
+
const publicKey = this.decodeAddress(address);
|
|
2559
|
+
const stores = type
|
|
2560
|
+
? [this.#stores[type]]
|
|
2561
|
+
: Object.values(this.#stores);
|
|
2562
|
+
const info = stores.reduce((lastInfo, store) => (store().subject.getValue()[address] || lastInfo), undefined);
|
|
2563
|
+
return info && {
|
|
2564
|
+
address,
|
|
2565
|
+
meta: info.json.meta,
|
|
2566
|
+
publicKey
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
getAddresses() {
|
|
2570
|
+
const available = this.addresses.subject.getValue();
|
|
2571
|
+
return Object
|
|
2572
|
+
.keys(available)
|
|
2573
|
+
.map((address) => this.getAddress(address))
|
|
2574
|
+
.filter((account) => !!account);
|
|
2575
|
+
}
|
|
2576
|
+
getContract(address) {
|
|
2577
|
+
return this.getAddress(address, 'contract');
|
|
2578
|
+
}
|
|
2579
|
+
getContracts() {
|
|
2580
|
+
const available = this.contracts.subject.getValue();
|
|
2581
|
+
return Object
|
|
2582
|
+
.entries(available)
|
|
2583
|
+
.filter(([, { json: { meta: { contract } } }]) => !!contract && contract.genesisHash === this.genesisHash)
|
|
2584
|
+
.map(([address]) => this.getContract(address))
|
|
2585
|
+
.filter((account) => !!account);
|
|
2586
|
+
}
|
|
2587
|
+
rewriteKey(json, key, hexAddr, creator) {
|
|
2588
|
+
if (hexAddr.startsWith('0x')) {
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
this._store.remove(key);
|
|
2592
|
+
this._store.set(creator(hexAddr), json);
|
|
2593
|
+
}
|
|
2594
|
+
loadAccount(json, key) {
|
|
2595
|
+
if (!json.meta.isTesting && json.encoded) {
|
|
2596
|
+
const pair = this.keyring.addFromJson(json, true);
|
|
2597
|
+
this.accounts.add(this._store, pair.address, json, pair.type);
|
|
2598
|
+
}
|
|
2599
|
+
const [, hexAddr] = key.split(':');
|
|
2600
|
+
this.rewriteKey(json, key, hexAddr.trim(), accountKey);
|
|
2601
|
+
}
|
|
2602
|
+
loadAddress(json, key) {
|
|
2603
|
+
const { isRecent, whenCreated = 0 } = json.meta;
|
|
2604
|
+
if (isRecent && (Date.now() - whenCreated) > RECENT_EXPIRY) {
|
|
2605
|
+
this._store.remove(key);
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
const address = util$7.isHex(json.address) && json.address.length !== 66
|
|
2609
|
+
? json.address
|
|
2610
|
+
: this.encodeAddress(util$7.isHex(json.address)
|
|
2611
|
+
? util$7.hexToU8a(json.address)
|
|
2612
|
+
: this.decodeAddress(json.address, true));
|
|
2613
|
+
const [, hexAddr] = key.split(':');
|
|
2614
|
+
this.addresses.add(this._store, address, json);
|
|
2615
|
+
this.rewriteKey(json, key, hexAddr, addressKey);
|
|
2616
|
+
}
|
|
2617
|
+
loadContract(json, key) {
|
|
2618
|
+
const address = this.encodeAddress(this.decodeAddress(json.address));
|
|
2619
|
+
const [, hexAddr] = key.split(':');
|
|
2620
|
+
json.meta.genesisHash = json.meta.genesisHash || (json.meta.contract?.genesisHash);
|
|
2621
|
+
this.contracts.add(this._store, address, json);
|
|
2622
|
+
this.rewriteKey(json, key, hexAddr, contractKey);
|
|
2623
|
+
}
|
|
2624
|
+
loadInjected(address, meta, type) {
|
|
2625
|
+
const json = {
|
|
2626
|
+
address,
|
|
2627
|
+
meta: util$7.objectSpread({}, meta, { isInjected: true })
|
|
2628
|
+
};
|
|
2629
|
+
const pair = this.keyring.addFromAddress(address, json.meta, null, type);
|
|
2630
|
+
this.accounts.add(this._store, pair.address, json, pair.type);
|
|
2631
|
+
}
|
|
2632
|
+
allowGenesis(json) {
|
|
2633
|
+
if (json?.meta && this.genesisHash) {
|
|
2634
|
+
const hashes = Object.values(uiSettings.chains).find((hashes) => hashes.includes(this.genesisHash || '')) || [this.genesisHash];
|
|
2635
|
+
if (json.meta.genesisHash) {
|
|
2636
|
+
return hashes.includes(json.meta.genesisHash) || this.genesisHashes.includes(json.meta.genesisHash);
|
|
2637
|
+
}
|
|
2638
|
+
else if (json.meta.contract) {
|
|
2639
|
+
return hashes.includes(json.meta.contract.genesisHash);
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
return true;
|
|
2643
|
+
}
|
|
2644
|
+
loadAll(options, injected = []) {
|
|
2645
|
+
super.initKeyring(options);
|
|
2646
|
+
this._store.all((key, json) => {
|
|
2647
|
+
if (!util$7.isFunction(options.filter) || options.filter(json)) {
|
|
2648
|
+
try {
|
|
2649
|
+
if (this.allowGenesis(json)) {
|
|
2650
|
+
if (accountRegex.test(key)) {
|
|
2651
|
+
this.loadAccount(json, key);
|
|
2652
|
+
}
|
|
2653
|
+
else if (addressRegex.test(key)) {
|
|
2654
|
+
this.loadAddress(json, key);
|
|
2655
|
+
}
|
|
2656
|
+
else if (contractRegex.test(key)) {
|
|
2657
|
+
this.loadContract(json, key);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
catch {
|
|
2662
|
+
console.warn(`Keyring: Unable to load ${key}:${util$7.stringify(json)}`);
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
});
|
|
2666
|
+
injected.forEach((account) => {
|
|
2667
|
+
if (this.allowGenesis(account)) {
|
|
2668
|
+
try {
|
|
2669
|
+
this.loadInjected(account.address, account.meta, account.type);
|
|
2670
|
+
}
|
|
2671
|
+
catch {
|
|
2672
|
+
console.warn(`Keyring: Unable to inject ${util$7.stringify(account)}`);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2676
|
+
this.keyringOption.init(this);
|
|
2677
|
+
}
|
|
2678
|
+
restoreAccount(json, password) {
|
|
2679
|
+
const cryptoType = Array.isArray(json.encoding.content) ? json.encoding.content[1] : 'ed25519';
|
|
2680
|
+
const encType = Array.isArray(json.encoding.type) ? json.encoding.type : [json.encoding.type];
|
|
2681
|
+
const pair = keyring$1.createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey: this.decodeAddress(json.address, true) }, json.meta, util$7.isHex(json.encoded) ? util$7.hexToU8a(json.encoded) : utilCrypto.base64Decode(json.encoded), encType);
|
|
2682
|
+
pair.decodePkcs8(password);
|
|
2683
|
+
this.addPair(pair, password);
|
|
2684
|
+
pair.lock();
|
|
2685
|
+
return pair;
|
|
2686
|
+
}
|
|
2687
|
+
restoreAccounts(json, password) {
|
|
2688
|
+
const accounts = JSON.parse(util$7.u8aToString(utilCrypto.jsonDecrypt(json, password)));
|
|
2689
|
+
accounts.forEach((account) => {
|
|
2690
|
+
this.loadAccount(account, accountKey(account.address));
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
saveAccount(pair, password) {
|
|
2694
|
+
this.addTimestamp(pair);
|
|
2695
|
+
const json = pair.toJson(password);
|
|
2696
|
+
this.keyring.addFromJson(json);
|
|
2697
|
+
this.accounts.add(this._store, pair.address, json, pair.type);
|
|
2698
|
+
return json;
|
|
2699
|
+
}
|
|
2700
|
+
saveAccountMeta(pair, meta) {
|
|
2701
|
+
const address = pair.address;
|
|
2702
|
+
this._store.get(accountKey(address), (json) => {
|
|
2703
|
+
pair.setMeta(meta);
|
|
2704
|
+
json.meta = pair.meta;
|
|
2705
|
+
this.accounts.add(this._store, address, json, pair.type);
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
saveAddress(address, meta, type = 'address') {
|
|
2709
|
+
const available = this.addresses.subject.getValue();
|
|
2710
|
+
const json = available[address]?.json || {
|
|
2711
|
+
address,
|
|
2712
|
+
meta: {
|
|
2713
|
+
isRecent: undefined,
|
|
2714
|
+
whenCreated: Date.now()
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2717
|
+
Object.keys(meta).forEach((key) => {
|
|
2718
|
+
json.meta[key] = meta[key];
|
|
2719
|
+
});
|
|
2720
|
+
delete json.meta.isRecent;
|
|
2721
|
+
this.#stores[type]().add(this._store, address, json);
|
|
2722
|
+
return json;
|
|
2723
|
+
}
|
|
2724
|
+
saveContract(address, meta) {
|
|
2725
|
+
return this.saveAddress(address, meta, 'contract');
|
|
2726
|
+
}
|
|
2727
|
+
saveRecent(address) {
|
|
2728
|
+
const available = this.addresses.subject.getValue();
|
|
2729
|
+
if (!available[address]) {
|
|
2730
|
+
this.addresses.add(this._store, address, {
|
|
2731
|
+
address,
|
|
2732
|
+
meta: {
|
|
2733
|
+
genesisHash: this.genesisHash,
|
|
2734
|
+
isRecent: true,
|
|
2735
|
+
whenCreated: Date.now()
|
|
2736
|
+
}
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
return this.addresses.subject.getValue()[address];
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
const packageInfo = { name: '@pezkuwi/ui-keyring', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-ui-keyring.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-ui-keyring.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-ui-keyring.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-ui-keyring.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '3.16.6' };
|
|
2744
|
+
|
|
2745
|
+
const keyring = new Keyring();
|
|
2746
|
+
|
|
2747
|
+
exports.Keyring = Keyring;
|
|
2748
|
+
exports.keyring = keyring;
|
|
2749
|
+
exports.packageInfo = packageInfo;
|
|
2750
|
+
|
|
2751
|
+
}));
|