pubo-utils 1.0.129 → 1.0.142

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.
@@ -1,177 +1,203 @@
1
1
  "use strict";
2
2
 
3
- var __extends = this && this.__extends || function () {
4
- var _extendStatics = function extendStatics(d, b) {
5
- _extendStatics = Object.setPrototypeOf || {
6
- __proto__: []
7
- } instanceof Array && function (d, b) {
8
- d.__proto__ = b;
9
- } || function (d, b) {
10
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
11
- };
12
- return _extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
- _extendStatics(d, b);
17
- function __() {
18
- this.constructor = d;
3
+ function _empty() {}
4
+ function _awaitIgnored(value, direct) {
5
+ if (!direct) {
6
+ return value && value.then ? value.then(_empty) : Promise.resolve();
7
+ }
8
+ }
9
+ function _invokeIgnored(body) {
10
+ var result = body();
11
+ if (result && result.then) {
12
+ return result.then(_empty);
13
+ }
14
+ }
15
+ var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
16
+ function _settle(pact, state, value) {
17
+ if (!pact.s) {
18
+ if (value instanceof _Pact) {
19
+ if (value.s) {
20
+ if (state & 1) {
21
+ state = value.s;
22
+ }
23
+ value = value.v;
24
+ } else {
25
+ value.o = _settle.bind(null, pact, state);
26
+ return;
27
+ }
19
28
  }
20
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
21
- };
22
- }();
23
- var __assign = this && this.__assign || function () {
24
- __assign = Object.assign || function (t) {
25
- for (var s, i = 1, n = arguments.length; i < n; i++) {
26
- s = arguments[i];
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
29
+ if (value && value.then) {
30
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
31
+ return;
32
+ }
33
+ pact.s = state;
34
+ pact.v = value;
35
+ var observer = pact.o;
36
+ if (observer) {
37
+ observer(pact);
28
38
  }
29
- return t;
30
- };
31
- return __assign.apply(this, arguments);
32
- };
33
- var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
34
- function adopt(value) {
35
- return value instanceof P ? value : new P(function (resolve) {
36
- resolve(value);
37
- });
38
39
  }
39
- return new (P || (P = Promise))(function (resolve, reject) {
40
- function fulfilled(value) {
41
- try {
42
- step(generator.next(value));
43
- } catch (e) {
44
- reject(e);
40
+ }
41
+ var _Pact = /*#__PURE__*/function () {
42
+ function _Pact() {}
43
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
44
+ var result = new _Pact();
45
+ var state = this.s;
46
+ if (state) {
47
+ var callback = state & 1 ? onFulfilled : onRejected;
48
+ if (callback) {
49
+ try {
50
+ _settle(result, 1, callback(this.v));
51
+ } catch (e) {
52
+ _settle(result, 2, e);
53
+ }
54
+ return result;
55
+ } else {
56
+ return this;
45
57
  }
46
58
  }
47
- function rejected(value) {
59
+ this.o = function (_this) {
48
60
  try {
49
- step(generator["throw"](value));
61
+ var value = _this.v;
62
+ if (_this.s & 1) {
63
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
64
+ } else if (onRejected) {
65
+ _settle(result, 1, onRejected(value));
66
+ } else {
67
+ _settle(result, 2, value);
68
+ }
50
69
  } catch (e) {
51
- reject(e);
70
+ _settle(result, 2, e);
52
71
  }
53
- }
54
- function step(result) {
55
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
56
- }
57
- step((generator = generator.apply(thisArg, _arguments || [])).next());
58
- });
59
- };
60
- var __generator = this && this.__generator || function (thisArg, body) {
61
- var _ = {
62
- label: 0,
63
- sent: function sent() {
64
- if (t[0] & 1) throw t[1];
65
- return t[1];
66
- },
67
- trys: [],
68
- ops: []
69
- },
70
- f,
71
- y,
72
- t,
73
- g;
74
- return g = {
75
- next: verb(0),
76
- "throw": verb(1),
77
- "return": verb(2)
78
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
79
- return this;
80
- }), g;
81
- function verb(n) {
82
- return function (v) {
83
- return step([n, v]);
84
72
  };
85
- }
86
- function step(op) {
87
- if (f) throw new TypeError("Generator is already executing.");
88
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
89
- 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;
90
- if (y = 0, t) op = [op[0] & 2, t.value];
91
- switch (op[0]) {
92
- case 0:
93
- case 1:
94
- t = op;
95
- break;
96
- case 4:
97
- _.label++;
98
- return {
99
- value: op[1],
100
- done: false
101
- };
102
- case 5:
103
- _.label++;
104
- y = op[1];
105
- op = [0];
106
- continue;
107
- case 7:
108
- op = _.ops.pop();
109
- _.trys.pop();
110
- continue;
111
- default:
112
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
113
- _ = 0;
114
- continue;
115
- }
116
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
117
- _.label = op[1];
118
- break;
119
- }
120
- if (op[0] === 6 && _.label < t[1]) {
121
- _.label = t[1];
122
- t = op;
123
- break;
124
- }
125
- if (t && _.label < t[2]) {
126
- _.label = t[2];
127
- _.ops.push(op);
128
- break;
73
+ return result;
74
+ };
75
+ return _Pact;
76
+ }();
77
+ function _isSettledPact(thenable) {
78
+ return thenable instanceof _Pact && thenable.s & 1;
79
+ }
80
+ function _forTo(array, body, check) {
81
+ var i = -1,
82
+ pact,
83
+ reject;
84
+ function _cycle(result) {
85
+ try {
86
+ while (++i < array.length && (!check || !check())) {
87
+ result = body(i);
88
+ if (result && result.then) {
89
+ if (_isSettledPact(result)) {
90
+ result = result.v;
91
+ } else {
92
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
93
+ return;
129
94
  }
130
- if (t[2]) _.ops.pop();
131
- _.trys.pop();
132
- continue;
95
+ }
96
+ }
97
+ if (pact) {
98
+ _settle(pact, 1, result);
99
+ } else {
100
+ pact = result;
133
101
  }
134
- op = body.call(thisArg, _);
135
102
  } catch (e) {
136
- op = [6, e];
137
- y = 0;
138
- } finally {
139
- f = t = 0;
103
+ _settle(pact || (pact = new _Pact()), 2, e);
140
104
  }
141
- if (op[0] & 5) throw op[1];
142
- return {
143
- value: op[0] ? op[1] : void 0,
144
- done: true
145
- };
146
105
  }
147
- };
148
- var __values = this && this.__values || function (o) {
149
- var s = typeof Symbol === "function" && Symbol.iterator,
150
- m = s && o[s],
151
- i = 0;
152
- if (m) return m.call(o);
153
- if (o && typeof o.length === "number") return {
154
- next: function next() {
155
- if (o && i >= o.length) o = void 0;
156
- return {
157
- value: o && o[i++],
158
- done: !o
106
+ _cycle();
107
+ return pact;
108
+ }
109
+ function _forOf(target, body, check) {
110
+ if (typeof target[_iteratorSymbol] === "function") {
111
+ var _cycle = function _cycle(result) {
112
+ try {
113
+ while (!(step = iterator.next()).done && (!check || !check())) {
114
+ result = body(step.value);
115
+ if (result && result.then) {
116
+ if (_isSettledPact(result)) {
117
+ result = result.v;
118
+ } else {
119
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
120
+ return;
121
+ }
122
+ }
123
+ }
124
+ if (pact) {
125
+ _settle(pact, 1, result);
126
+ } else {
127
+ pact = result;
128
+ }
129
+ } catch (e) {
130
+ _settle(pact || (pact = new _Pact()), 2, e);
131
+ }
132
+ };
133
+ var iterator = target[_iteratorSymbol](),
134
+ step,
135
+ pact,
136
+ reject;
137
+ _cycle();
138
+ if (iterator["return"]) {
139
+ var _fixup = function _fixup(value) {
140
+ try {
141
+ if (!step.done) {
142
+ iterator["return"]();
143
+ }
144
+ } catch (e) {}
145
+ return value;
159
146
  };
147
+ if (pact && pact.then) {
148
+ return pact.then(_fixup, function (e) {
149
+ throw _fixup(e);
150
+ });
151
+ }
152
+ _fixup();
160
153
  }
161
- };
162
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
163
- };
154
+ return pact;
155
+ }
156
+ // No support for Symbol.iterator
157
+ if (!("length" in target)) {
158
+ throw new TypeError("Object is not iterable");
159
+ }
160
+ // Handle live collections properly
161
+ var values = [];
162
+ for (var i = 0; i < target.length; i++) {
163
+ values.push(target[i]);
164
+ }
165
+ return _forTo(values, function (i) {
166
+ return body(values[i]);
167
+ }, check);
168
+ }
169
+ function _continueIgnored(value) {
170
+ if (value && value.then) {
171
+ return value.then(_empty);
172
+ }
173
+ }
174
+ function _await(value, then, direct) {
175
+ if (direct) {
176
+ return then ? then(value) : value;
177
+ }
178
+ if (!value || !value.then) {
179
+ value = Promise.resolve(value);
180
+ }
181
+ return then ? value.then(then) : value;
182
+ }
183
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
184
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
185
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
186
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
187
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
188
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
164
189
  Object.defineProperty(exports, "__esModule", {
165
190
  value: true
166
191
  });
167
192
  exports.CacheEmitter = exports.Emitter = void 0;
168
193
  var random_1 = require("../random");
169
- var Emitter = /** @class */function () {
194
+ var Emitter = /*#__PURE__*/function () {
170
195
  function Emitter() {
171
196
  this.state = {};
172
197
  this.ids = {};
173
198
  }
174
- Emitter.prototype.on = function (event, func) {
199
+ var _proto = Emitter.prototype;
200
+ _proto.on = function on(event, func) {
175
201
  if (!this.state[event]) {
176
202
  this.state[event] = [];
177
203
  }
@@ -186,15 +212,15 @@ var Emitter = /** @class */function () {
186
212
  };
187
213
  return key;
188
214
  };
189
- Emitter.prototype.cancel = function (id) {
215
+ _proto.cancel = function cancel(id) {
190
216
  var _this = this;
191
217
  if (!id) {
192
218
  this.clear();
193
219
  return;
194
220
  }
195
- var _a = this.ids[id] || {},
196
- event = _a.event,
197
- index = _a.index;
221
+ var _ref = this.ids[id] || {},
222
+ event = _ref.event,
223
+ index = _ref.index;
198
224
  if (!event) {
199
225
  return;
200
226
  }
@@ -209,103 +235,67 @@ var Emitter = /** @class */function () {
209
235
  }
210
236
  });
211
237
  };
212
- Emitter.prototype.clear = function () {
238
+ _proto.clear = function clear() {
213
239
  this.state.length = 0;
214
240
  };
215
- Emitter.prototype.emit = function (event, payload) {
216
- var e_1, _a;
241
+ _proto.emit = function emit(event, payload) {
217
242
  if (Array.isArray(this.state[event])) {
218
- try {
219
- for (var _b = __values(this.state[event]), _c = _b.next(); !_c.done; _c = _b.next()) {
220
- var func = _c.value;
221
- if (typeof func === 'function') {
222
- func(payload);
223
- }
224
- }
225
- } catch (e_1_1) {
226
- e_1 = {
227
- error: e_1_1
228
- };
229
- } finally {
230
- try {
231
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
232
- } finally {
233
- if (e_1) throw e_1.error;
243
+ for (var _iterator = _createForOfIteratorHelperLoose(this.state[event]), _step; !(_step = _iterator()).done;) {
244
+ var func = _step.value;
245
+ if (typeof func === 'function') {
246
+ func(payload);
234
247
  }
235
248
  }
236
249
  }
237
250
  };
238
- Emitter.prototype.emitSync = function (event, payload) {
239
- return __awaiter(this, void 0, void 0, function () {
240
- var _a, _b, func, e_2_1;
241
- var e_2, _c;
242
- return __generator(this, function (_d) {
243
- switch (_d.label) {
244
- case 0:
245
- if (!Array.isArray(this.state[event])) return [3 /*break*/, 8];
246
- _d.label = 1;
247
- case 1:
248
- _d.trys.push([1, 6, 7, 8]);
249
- _a = __values(this.state[event]), _b = _a.next();
250
- _d.label = 2;
251
- case 2:
252
- if (!!_b.done) return [3 /*break*/, 5];
253
- func = _b.value;
254
- if (!(typeof func === 'function')) return [3 /*break*/, 4];
255
- return [4 /*yield*/, func(payload)];
256
- case 3:
257
- _d.sent();
258
- _d.label = 4;
259
- case 4:
260
- _b = _a.next();
261
- return [3 /*break*/, 2];
262
- case 5:
263
- return [3 /*break*/, 8];
264
- case 6:
265
- e_2_1 = _d.sent();
266
- e_2 = {
267
- error: e_2_1
268
- };
269
- return [3 /*break*/, 8];
270
- case 7:
271
- try {
272
- if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
273
- } finally {
274
- if (e_2) throw e_2.error;
275
- }
276
- return [7 /*endfinally*/];
277
- case 8:
278
- return [2 /*return*/];
251
+ _proto.emitSync = function emitSync(event, payload) {
252
+ try {
253
+ var _this2 = this;
254
+ return _await(_invokeIgnored(function () {
255
+ if (Array.isArray(_this2.state[event])) {
256
+ return _continueIgnored(_forOf(_this2.state[event], function (func) {
257
+ return _invokeIgnored(function () {
258
+ if (typeof func === 'function') {
259
+ return _awaitIgnored(func(payload));
260
+ }
261
+ });
262
+ }));
279
263
  }
280
- });
281
- });
264
+ }));
265
+ } catch (e) {
266
+ return Promise.reject(e);
267
+ }
282
268
  };
283
-
284
- Emitter.prototype.clone = function () {
269
+ _proto.clone = function clone() {
285
270
  return {
286
- state: __assign({}, this.state),
287
- ids: __assign({}, this.ids)
271
+ state: _extends({}, this.state),
272
+ ids: _extends({}, this.ids)
288
273
  };
289
274
  };
290
- Emitter.prototype.restore = function (snapshot) {
275
+ _proto.restore = function restore(snapshot) {
291
276
  this.state = snapshot.state;
292
277
  this.ids = snapshot.ids;
293
278
  };
294
279
  return Emitter;
295
280
  }();
296
281
  exports.Emitter = Emitter;
297
- var CacheEmitter = /** @class */function (_super) {
298
- __extends(CacheEmitter, _super);
282
+ var CacheEmitter = /*#__PURE__*/function (_Emitter) {
283
+ _inheritsLoose(CacheEmitter, _Emitter);
299
284
  function CacheEmitter() {
300
- var _this = _super !== null && _super.apply(this, arguments) || this;
301
- _this._cache = {};
302
- return _this;
285
+ var _this3;
286
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
287
+ args[_key] = arguments[_key];
288
+ }
289
+ _this3 = _Emitter.call.apply(_Emitter, [this].concat(args)) || this;
290
+ _this3._cache = {};
291
+ return _this3;
303
292
  }
304
- CacheEmitter.prototype.emit = function (event, payload) {
293
+ var _proto2 = CacheEmitter.prototype;
294
+ _proto2.emit = function emit(event, payload) {
305
295
  this._cache[event] = payload;
306
- _super.prototype.emit.call(this, event, payload);
296
+ _Emitter.prototype.emit.call(this, event, payload);
307
297
  };
308
- CacheEmitter.prototype.getState = function (event) {
298
+ _proto2.getState = function getState(event) {
309
299
  return this._cache[event];
310
300
  };
311
301
  return CacheEmitter;
@@ -1,21 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var __values = this && this.__values || function (o) {
4
- var s = typeof Symbol === "function" && Symbol.iterator,
5
- m = s && o[s],
6
- i = 0;
7
- if (m) return m.call(o);
8
- if (o && typeof o.length === "number") return {
9
- next: function next() {
10
- if (o && i >= o.length) o = void 0;
11
- return {
12
- value: o && o[i++],
13
- done: !o
14
- };
15
- }
16
- };
17
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
18
- };
19
3
  Object.defineProperty(exports, "__esModule", {
20
4
  value: true
21
5
  });
@@ -28,23 +12,10 @@ exports.superFactory = void 0;
28
12
  */
29
13
  var superFactory = function superFactory(factory) {
30
14
  return function (options) {
31
- var e_1, _a;
32
15
  var product = {};
33
- try {
34
- for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
35
- var key = _c.value;
36
- product[key] = factory(options[key], key);
37
- }
38
- } catch (e_1_1) {
39
- e_1 = {
40
- error: e_1_1
41
- };
42
- } finally {
43
- try {
44
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
45
- } finally {
46
- if (e_1) throw e_1.error;
47
- }
16
+ for (var _i = 0, _Object$keys = Object.keys(options); _i < _Object$keys.length; _i++) {
17
+ var key = _Object$keys[_i];
18
+ product[key] = factory(options[key], key);
48
19
  }
49
20
  return product;
50
21
  };