@zenflux/core 0.0.0-abc.2 → 0.0.0-abc.24

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,37 +1,614 @@
1
- class ForceMethodBase extends Error {
2
- constructor(className, methodName) {
3
- super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
1
+ function _typeof(obj) {
2
+ "@babel/helpers - typeof";
3
+
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
5
+ return typeof obj;
6
+ } : function (obj) {
7
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
8
+ }, _typeof(obj);
9
+ }
10
+
11
+ function _toPrimitive(input, hint) {
12
+ if (_typeof(input) !== "object" || input === null) return input;
13
+ var prim = input[Symbol.toPrimitive];
14
+ if (prim !== undefined) {
15
+ var res = prim.call(input, hint || "default");
16
+ if (_typeof(res) !== "object") return res;
17
+ throw new TypeError("@@toPrimitive must return a primitive value.");
18
+ }
19
+ return (hint === "string" ? String : Number)(input);
20
+ }
21
+
22
+ function _toPropertyKey(arg) {
23
+ var key = _toPrimitive(arg, "string");
24
+ return _typeof(key) === "symbol" ? key : String(key);
25
+ }
26
+
27
+ function _defineProperty(obj, key, value) {
28
+ key = _toPropertyKey(key);
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
4
38
  }
39
+ return obj;
40
+ }
41
+
42
+ function ownKeys(object, enumerableOnly) {
43
+ var keys = Object.keys(object);
44
+ if (Object.getOwnPropertySymbols) {
45
+ var symbols = Object.getOwnPropertySymbols(object);
46
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
47
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
48
+ })), keys.push.apply(keys, symbols);
49
+ }
50
+ return keys;
5
51
  }
6
- class ForceMethod extends Error {
7
- constructor(context, methodName) {
8
- super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
52
+ function _objectSpread2(target) {
53
+ for (var i = 1; i < arguments.length; i++) {
54
+ var source = null != arguments[i] ? arguments[i] : {};
55
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
56
+ _defineProperty(target, key, source[key]);
57
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
58
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
59
+ });
9
60
  }
61
+ return target;
10
62
  }
11
63
 
12
- /**
13
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
14
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
15
- */
16
- let IdCounter = 0;
17
- /**
18
- * Base class 4 *
19
- */
20
- class ObjectBase {
21
- virtualId = 0;
22
- static getName() {
23
- throw new ForceMethodBase("ObjectBase", "getName");
64
+ var name = "@zenflux/core";
65
+ var version = "0.0.0-alpha.0";
66
+ var description = "ZenFlux core";
67
+ var keywords = [
68
+ "zenflux",
69
+ "zen",
70
+ "flux",
71
+ "commands",
72
+ "manager",
73
+ "commands manager",
74
+ "core",
75
+ "zenflux-core"
76
+ ];
77
+ var repository = {
78
+ type: "git",
79
+ url: "git+https://github.com/zenflux/core.git"
80
+ };
81
+ var license = "MIT";
82
+ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
83
+ var main = "dist/cjs/zenflux-core.js";
84
+ var unpkg = "dist/umd/zenflux-core.js";
85
+ var module = "dist/es/zenflux-core.js";
86
+ var types = "types/index.d.ts";
87
+ var files = [
88
+ "dist",
89
+ "src",
90
+ "types"
91
+ ];
92
+ var scripts = {
93
+ test: "export flow_modules_logger=off && jest",
94
+ "toolkit-build": "node_modules/@zenflux/rollup-toolkit/bin/run @build",
95
+ "toolkit-build-dev": "node_modules/@zenflux/rollup-toolkit/bin/dev @build",
96
+ "toolkit-watch": "node_modules/@zenflux/rollup-toolkit/bin/run @watch",
97
+ "toolkit-watch-dev": "node_modules/@zenflux/rollup-toolkit/bin/dev @watch"
98
+ };
99
+ var devDependencies = {
100
+ "@babel/preset-env": "^7.20.2",
101
+ "@babel/preset-typescript": "^7.18.6",
102
+ "@types/jest": "^29.2.5",
103
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
104
+ "@typescript-eslint/parser": "^5.48.0",
105
+ "@zenflux/rollup-toolkit": "^0.0.0-alpha.0",
106
+ "babel-jest": "^29.3.1",
107
+ "ts-jest": "^29.0.3",
108
+ tslib: "^2.4.1"
109
+ };
110
+ var pkg = {
111
+ name: name,
112
+ version: version,
113
+ description: description,
114
+ keywords: keywords,
115
+ repository: repository,
116
+ license: license,
117
+ author: author,
118
+ main: main,
119
+ unpkg: unpkg,
120
+ module: module,
121
+ types: types,
122
+ files: files,
123
+ scripts: scripts,
124
+ devDependencies: devDependencies
125
+ };
126
+
127
+ function _regeneratorRuntime() {
128
+ _regeneratorRuntime = function _regeneratorRuntime() {
129
+ return exports;
130
+ };
131
+ var exports = {},
132
+ Op = Object.prototype,
133
+ hasOwn = Op.hasOwnProperty,
134
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
135
+ obj[key] = desc.value;
136
+ },
137
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
138
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
139
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
140
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
141
+ function define(obj, key, value) {
142
+ return Object.defineProperty(obj, key, {
143
+ value: value,
144
+ enumerable: !0,
145
+ configurable: !0,
146
+ writable: !0
147
+ }), obj[key];
148
+ }
149
+ try {
150
+ define({}, "");
151
+ } catch (err) {
152
+ define = function define(obj, key, value) {
153
+ return obj[key] = value;
154
+ };
24
155
  }
25
- constructor() {
26
- this.virtualId = IdCounter;
27
- APIIncreaseIdCounter();
156
+ function wrap(innerFn, outerFn, self, tryLocsList) {
157
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
158
+ generator = Object.create(protoGenerator.prototype),
159
+ context = new Context(tryLocsList || []);
160
+ return defineProperty(generator, "_invoke", {
161
+ value: makeInvokeMethod(innerFn, self, context)
162
+ }), generator;
163
+ }
164
+ function tryCatch(fn, obj, arg) {
165
+ try {
166
+ return {
167
+ type: "normal",
168
+ arg: fn.call(obj, arg)
169
+ };
170
+ } catch (err) {
171
+ return {
172
+ type: "throw",
173
+ arg: err
174
+ };
175
+ }
28
176
  }
29
- getName() {
30
- return this.constructor.getName();
177
+ exports.wrap = wrap;
178
+ var ContinueSentinel = {};
179
+ function Generator() {}
180
+ function GeneratorFunction() {}
181
+ function GeneratorFunctionPrototype() {}
182
+ var IteratorPrototype = {};
183
+ define(IteratorPrototype, iteratorSymbol, function () {
184
+ return this;
185
+ });
186
+ var getProto = Object.getPrototypeOf,
187
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
188
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
189
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
190
+ function defineIteratorMethods(prototype) {
191
+ ["next", "throw", "return"].forEach(function (method) {
192
+ define(prototype, method, function (arg) {
193
+ return this._invoke(method, arg);
194
+ });
195
+ });
31
196
  }
197
+ function AsyncIterator(generator, PromiseImpl) {
198
+ function invoke(method, arg, resolve, reject) {
199
+ var record = tryCatch(generator[method], generator, arg);
200
+ if ("throw" !== record.type) {
201
+ var result = record.arg,
202
+ value = result.value;
203
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
204
+ invoke("next", value, resolve, reject);
205
+ }, function (err) {
206
+ invoke("throw", err, resolve, reject);
207
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
208
+ result.value = unwrapped, resolve(result);
209
+ }, function (error) {
210
+ return invoke("throw", error, resolve, reject);
211
+ });
212
+ }
213
+ reject(record.arg);
214
+ }
215
+ var previousPromise;
216
+ defineProperty(this, "_invoke", {
217
+ value: function value(method, arg) {
218
+ function callInvokeWithMethodAndArg() {
219
+ return new PromiseImpl(function (resolve, reject) {
220
+ invoke(method, arg, resolve, reject);
221
+ });
222
+ }
223
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
224
+ }
225
+ });
226
+ }
227
+ function makeInvokeMethod(innerFn, self, context) {
228
+ var state = "suspendedStart";
229
+ return function (method, arg) {
230
+ if ("executing" === state) throw new Error("Generator is already running");
231
+ if ("completed" === state) {
232
+ if ("throw" === method) throw arg;
233
+ return doneResult();
234
+ }
235
+ for (context.method = method, context.arg = arg;;) {
236
+ var delegate = context.delegate;
237
+ if (delegate) {
238
+ var delegateResult = maybeInvokeDelegate(delegate, context);
239
+ if (delegateResult) {
240
+ if (delegateResult === ContinueSentinel) continue;
241
+ return delegateResult;
242
+ }
243
+ }
244
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
245
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
246
+ context.dispatchException(context.arg);
247
+ } else "return" === context.method && context.abrupt("return", context.arg);
248
+ state = "executing";
249
+ var record = tryCatch(innerFn, self, context);
250
+ if ("normal" === record.type) {
251
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
252
+ return {
253
+ value: record.arg,
254
+ done: context.done
255
+ };
256
+ }
257
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
258
+ }
259
+ };
260
+ }
261
+ function maybeInvokeDelegate(delegate, context) {
262
+ var methodName = context.method,
263
+ method = delegate.iterator[methodName];
264
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
265
+ var record = tryCatch(method, delegate.iterator, context.arg);
266
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
267
+ var info = record.arg;
268
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
269
+ }
270
+ function pushTryEntry(locs) {
271
+ var entry = {
272
+ tryLoc: locs[0]
273
+ };
274
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
275
+ }
276
+ function resetTryEntry(entry) {
277
+ var record = entry.completion || {};
278
+ record.type = "normal", delete record.arg, entry.completion = record;
279
+ }
280
+ function Context(tryLocsList) {
281
+ this.tryEntries = [{
282
+ tryLoc: "root"
283
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
284
+ }
285
+ function values(iterable) {
286
+ if (iterable) {
287
+ var iteratorMethod = iterable[iteratorSymbol];
288
+ if (iteratorMethod) return iteratorMethod.call(iterable);
289
+ if ("function" == typeof iterable.next) return iterable;
290
+ if (!isNaN(iterable.length)) {
291
+ var i = -1,
292
+ next = function next() {
293
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
294
+ return next.value = undefined, next.done = !0, next;
295
+ };
296
+ return next.next = next;
297
+ }
298
+ }
299
+ return {
300
+ next: doneResult
301
+ };
302
+ }
303
+ function doneResult() {
304
+ return {
305
+ value: undefined,
306
+ done: !0
307
+ };
308
+ }
309
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
310
+ value: GeneratorFunctionPrototype,
311
+ configurable: !0
312
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
313
+ value: GeneratorFunction,
314
+ configurable: !0
315
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
316
+ var ctor = "function" == typeof genFun && genFun.constructor;
317
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
318
+ }, exports.mark = function (genFun) {
319
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
320
+ }, exports.awrap = function (arg) {
321
+ return {
322
+ __await: arg
323
+ };
324
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
325
+ return this;
326
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
327
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
328
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
329
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
330
+ return result.done ? result.value : iter.next();
331
+ });
332
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
333
+ return this;
334
+ }), define(Gp, "toString", function () {
335
+ return "[object Generator]";
336
+ }), exports.keys = function (val) {
337
+ var object = Object(val),
338
+ keys = [];
339
+ for (var key in object) keys.push(key);
340
+ return keys.reverse(), function next() {
341
+ for (; keys.length;) {
342
+ var key = keys.pop();
343
+ if (key in object) return next.value = key, next.done = !1, next;
344
+ }
345
+ return next.done = !0, next;
346
+ };
347
+ }, exports.values = values, Context.prototype = {
348
+ constructor: Context,
349
+ reset: function reset(skipTempReset) {
350
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
351
+ },
352
+ stop: function stop() {
353
+ this.done = !0;
354
+ var rootRecord = this.tryEntries[0].completion;
355
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
356
+ return this.rval;
357
+ },
358
+ dispatchException: function dispatchException(exception) {
359
+ if (this.done) throw exception;
360
+ var context = this;
361
+ function handle(loc, caught) {
362
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
363
+ }
364
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
365
+ var entry = this.tryEntries[i],
366
+ record = entry.completion;
367
+ if ("root" === entry.tryLoc) return handle("end");
368
+ if (entry.tryLoc <= this.prev) {
369
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
370
+ hasFinally = hasOwn.call(entry, "finallyLoc");
371
+ if (hasCatch && hasFinally) {
372
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
373
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
374
+ } else if (hasCatch) {
375
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
376
+ } else {
377
+ if (!hasFinally) throw new Error("try statement without catch or finally");
378
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
379
+ }
380
+ }
381
+ }
382
+ },
383
+ abrupt: function abrupt(type, arg) {
384
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
385
+ var entry = this.tryEntries[i];
386
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
387
+ var finallyEntry = entry;
388
+ break;
389
+ }
390
+ }
391
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
392
+ var record = finallyEntry ? finallyEntry.completion : {};
393
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
394
+ },
395
+ complete: function complete(record, afterLoc) {
396
+ if ("throw" === record.type) throw record.arg;
397
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
398
+ },
399
+ finish: function finish(finallyLoc) {
400
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
401
+ var entry = this.tryEntries[i];
402
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
403
+ }
404
+ },
405
+ "catch": function _catch(tryLoc) {
406
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
407
+ var entry = this.tryEntries[i];
408
+ if (entry.tryLoc === tryLoc) {
409
+ var record = entry.completion;
410
+ if ("throw" === record.type) {
411
+ var thrown = record.arg;
412
+ resetTryEntry(entry);
413
+ }
414
+ return thrown;
415
+ }
416
+ }
417
+ throw new Error("illegal catch attempt");
418
+ },
419
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
420
+ return this.delegate = {
421
+ iterator: values(iterable),
422
+ resultName: resultName,
423
+ nextLoc: nextLoc
424
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
425
+ }
426
+ }, exports;
32
427
  }
33
- function APIIncreaseIdCounter() {
34
- return IdCounter++;
428
+
429
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
430
+ try {
431
+ var info = gen[key](arg);
432
+ var value = info.value;
433
+ } catch (error) {
434
+ reject(error);
435
+ return;
436
+ }
437
+ if (info.done) {
438
+ resolve(value);
439
+ } else {
440
+ Promise.resolve(value).then(_next, _throw);
441
+ }
442
+ }
443
+ function _asyncToGenerator(fn) {
444
+ return function () {
445
+ var self = this,
446
+ args = arguments;
447
+ return new Promise(function (resolve, reject) {
448
+ var gen = fn.apply(self, args);
449
+ function _next(value) {
450
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
451
+ }
452
+ function _throw(err) {
453
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
454
+ }
455
+ _next(undefined);
456
+ });
457
+ };
458
+ }
459
+
460
+ function _classCallCheck(instance, Constructor) {
461
+ if (!(instance instanceof Constructor)) {
462
+ throw new TypeError("Cannot call a class as a function");
463
+ }
464
+ }
465
+
466
+ function _defineProperties(target, props) {
467
+ for (var i = 0; i < props.length; i++) {
468
+ var descriptor = props[i];
469
+ descriptor.enumerable = descriptor.enumerable || false;
470
+ descriptor.configurable = true;
471
+ if ("value" in descriptor) descriptor.writable = true;
472
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
473
+ }
474
+ }
475
+ function _createClass(Constructor, protoProps, staticProps) {
476
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
477
+ if (staticProps) _defineProperties(Constructor, staticProps);
478
+ Object.defineProperty(Constructor, "prototype", {
479
+ writable: false
480
+ });
481
+ return Constructor;
482
+ }
483
+
484
+ function _assertThisInitialized(self) {
485
+ if (self === void 0) {
486
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
487
+ }
488
+ return self;
489
+ }
490
+
491
+ function _setPrototypeOf(o, p) {
492
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
493
+ o.__proto__ = p;
494
+ return o;
495
+ };
496
+ return _setPrototypeOf(o, p);
497
+ }
498
+
499
+ function _inherits(subClass, superClass) {
500
+ if (typeof superClass !== "function" && superClass !== null) {
501
+ throw new TypeError("Super expression must either be null or a function");
502
+ }
503
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
504
+ constructor: {
505
+ value: subClass,
506
+ writable: true,
507
+ configurable: true
508
+ }
509
+ });
510
+ Object.defineProperty(subClass, "prototype", {
511
+ writable: false
512
+ });
513
+ if (superClass) _setPrototypeOf(subClass, superClass);
514
+ }
515
+
516
+ function _getPrototypeOf(o) {
517
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
518
+ return o.__proto__ || Object.getPrototypeOf(o);
519
+ };
520
+ return _getPrototypeOf(o);
521
+ }
522
+
523
+ function _isNativeReflectConstruct() {
524
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
525
+ if (Reflect.construct.sham) return false;
526
+ if (typeof Proxy === "function") return true;
527
+ try {
528
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
529
+ return true;
530
+ } catch (e) {
531
+ return false;
532
+ }
533
+ }
534
+
535
+ function _possibleConstructorReturn(self, call) {
536
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
537
+ return call;
538
+ } else if (call !== void 0) {
539
+ throw new TypeError("Derived constructors may only return object or undefined");
540
+ }
541
+ return _assertThisInitialized(self);
542
+ }
543
+
544
+ function _createSuper(Derived) {
545
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
546
+ return function _createSuperInternal() {
547
+ var Super = _getPrototypeOf(Derived),
548
+ result;
549
+ if (hasNativeReflectConstruct) {
550
+ var NewTarget = _getPrototypeOf(this).constructor;
551
+ result = Reflect.construct(Super, arguments, NewTarget);
552
+ } else {
553
+ result = Super.apply(this, arguments);
554
+ }
555
+ return _possibleConstructorReturn(this, result);
556
+ };
557
+ }
558
+
559
+ function _arrayWithHoles(arr) {
560
+ if (Array.isArray(arr)) return arr;
561
+ }
562
+
563
+ function _iterableToArrayLimit(arr, i) {
564
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
565
+ if (null != _i) {
566
+ var _s,
567
+ _e,
568
+ _x,
569
+ _r,
570
+ _arr = [],
571
+ _n = !0,
572
+ _d = !1;
573
+ try {
574
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
575
+ if (Object(_i) !== _i) return;
576
+ _n = !1;
577
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
578
+ } catch (err) {
579
+ _d = !0, _e = err;
580
+ } finally {
581
+ try {
582
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
583
+ } finally {
584
+ if (_d) throw _e;
585
+ }
586
+ }
587
+ return _arr;
588
+ }
589
+ }
590
+
591
+ function _arrayLikeToArray(arr, len) {
592
+ if (len == null || len > arr.length) len = arr.length;
593
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
594
+ return arr2;
595
+ }
596
+
597
+ function _unsupportedIterableToArray(o, minLen) {
598
+ if (!o) return;
599
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
600
+ var n = Object.prototype.toString.call(o).slice(8, -1);
601
+ if (n === "Object" && o.constructor) n = o.constructor.name;
602
+ if (n === "Map" || n === "Set") return Array.from(o);
603
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
604
+ }
605
+
606
+ function _nonIterableRest() {
607
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
608
+ }
609
+
610
+ function _slicedToArray(arr, i) {
611
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
35
612
  }
36
613
 
37
614
  /**
@@ -39,10 +616,10 @@ function APIIncreaseIdCounter() {
39
616
  *
40
617
  * @copyright https://stackoverflow.com/a/53731154
41
618
  */
42
- const getCircularReplacer = () => {
43
- const seen = new WeakSet();
44
- return (key, value) => {
45
- if (typeof value === "object" && value !== null) {
619
+ var getCircularReplacer = function getCircularReplacer() {
620
+ var seen = new WeakSet();
621
+ return function (key, value) {
622
+ if (_typeof(value) === "object" && value !== null) {
46
623
  if (seen.has(value)) {
47
624
  return;
48
625
  }
@@ -57,109 +634,55 @@ const getCircularReplacer = () => {
57
634
  *
58
635
  * @copyright http://jsfiddle.net/96sME/
59
636
  */
60
- const hexColorDelta = function (hex1, hex2) {
637
+ var hexColorDelta = function hexColorDelta(hex1, hex2) {
61
638
  hex1 = hex1.replace("#", "");
62
639
  hex2 = hex2.replace("#", "");
640
+
63
641
  // Get red/green/blue int values of hex1
64
- const r1 = parseInt(hex1.substring(0, 2), 16);
65
- const g1 = parseInt(hex1.substring(2, 4), 16);
66
- const b1 = parseInt(hex1.substring(4, 6), 16);
642
+ var r1 = parseInt(hex1.substring(0, 2), 16);
643
+ var g1 = parseInt(hex1.substring(2, 4), 16);
644
+ var b1 = parseInt(hex1.substring(4, 6), 16);
645
+
67
646
  // Get red/green/blue int values of hex2
68
- const r2 = parseInt(hex2.substring(0, 2), 16);
69
- const g2 = parseInt(hex2.substring(2, 4), 16);
70
- const b2 = parseInt(hex2.substring(4, 6), 16);
647
+ var r2 = parseInt(hex2.substring(0, 2), 16);
648
+ var g2 = parseInt(hex2.substring(2, 4), 16);
649
+ var b2 = parseInt(hex2.substring(4, 6), 16);
650
+
71
651
  // Calculate differences between reds, greens and blues
72
- let r = 255 - Math.abs(r1 - r2);
73
- let g = 255 - Math.abs(g1 - g2);
74
- let b = 255 - Math.abs(b1 - b2);
652
+ var r = 255 - Math.abs(r1 - r2);
653
+ var g = 255 - Math.abs(g1 - g2);
654
+ var b = 255 - Math.abs(b1 - b2);
655
+
75
656
  // Limit differences between 0 and 1
657
+
76
658
  r /= 255;
77
659
  g /= 255;
78
660
  b /= 255;
661
+
79
662
  // 0 means opposite colors, 1 means same colors
80
663
  return (r + g + b) / 3;
81
664
  };
82
665
 
83
- var index$5 = /*#__PURE__*/Object.freeze({
666
+ var index$6 = /*#__PURE__*/Object.freeze({
84
667
  __proto__: null,
85
668
  getCircularReplacer: getCircularReplacer,
86
669
  hexColorDelta: hexColorDelta
87
670
  });
88
671
 
89
- /**
90
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
91
- * @description: Module for logging instances.
92
- * @TODO:
93
- * - Remove `@ts-ignore`, requires a refactor.
94
- * - Add night/white mode.
95
- */
96
672
  // TODO: Should by dynamic/configure-able.
97
- const MAX_WRAPPING_RECURSIVE_DEPTH = 4;
98
- class Logger {
99
- static wrappers = {};
100
- static wrapperDepth = 0;
101
- static sharedData = {};
102
- static colorsInUse = [];
103
- defaultStyle;
104
- color;
105
- outputHandler;
106
- args = {};
107
- name;
108
- state = false;
109
- static getName() {
110
- return 'Core/Modules/Logger';
111
- }
112
- /**
113
- * Function reset() : Reset logger globals.
114
- */
115
- static reset() {
116
- Logger.wrappers = {};
117
- Logger.wrapperDepth = 0;
118
- Logger.colorsInUse = [];
119
- Logger.sharedData = {};
120
- }
121
- /**
122
- * Function createCustomWrapper() : Creates custom wrapper for log entities.
123
- */
124
- static createCustomWrapper(classType, callback) {
125
- // @ts-ignore
126
- if (!Logger.wrappers[classType]) {
127
- // @ts-ignore
128
- Logger.wrappers[classType.name] = [];
129
- }
130
- // @ts-ignore
131
- Logger.wrappers[classType.name].push({
132
- classType,
133
- callback
134
- });
135
- }
136
- /**
137
- * Function getCallerName() : Return caller name.
138
- */
139
- static getCallerName() {
140
- const error = new Error(),
141
- caller = error.stack ? error.stack.split("\n")[3].trim() : '_UNKNOWN_CALLER_NAME_';
142
- if (caller.startsWith("at new")) {
143
- return "constructor";
144
- }
145
- return caller.split(".")[1].split(" ")[0];
146
- }
147
- /**
148
- * Function functionView() : Return function preview.
149
- */
150
- static getFunctionView(fn) {
151
- let fReturn = "anonymous function()";
152
- // TODO: Check if works.
153
- if (typeof fn !== "string" && fn.name.length !== 0) {
154
- fReturn = fn.name.split(" ")[1] + "()";
155
- }
156
- return fReturn;
157
- }
673
+ var MAX_WRAPPING_RECURSIVE_DEPTH = 4;
674
+ var Logger = /*#__PURE__*/function () {
158
675
  /**
159
676
  * Function constructor() : Create logger class.
160
677
  */
161
- constructor(owner, isActive = false, args = {}) {
162
- if ('off' === globalThis.process?.env['flow_modules_logger']) {
678
+ function Logger(owner) {
679
+ var _globalThis$process;
680
+ var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
681
+ var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
682
+ _classCallCheck(this, Logger);
683
+ _defineProperty(this, "args", {});
684
+ _defineProperty(this, "state", false);
685
+ if ('off' === ((_globalThis$process = globalThis.process) === null || _globalThis$process === void 0 ? void 0 : _globalThis$process.env['flow_modules_logger'])) {
163
686
  return;
164
687
  }
165
688
  this.state = isActive;
@@ -174,404 +697,478 @@ class Logger {
174
697
  this.initialize();
175
698
  }
176
699
  }
700
+
177
701
  /**
178
702
  * Function initialize() : Initialize logger class.
179
703
  */
180
- initialize() {
181
- // @ts-ignore
182
- if (this.args.sameColor) {
183
- if (!Logger.sharedData[this.name]) {
184
- Logger.sharedData[this.name] = this.getRandomColor();
704
+ _createClass(Logger, [{
705
+ key: "initialize",
706
+ value: function initialize() {
707
+ // @ts-ignore
708
+ if (this.args.sameColor) {
709
+ if (!Logger.sharedData[this.name]) {
710
+ Logger.sharedData[this.name] = this.getRandomColor();
711
+ }
712
+ this.color = Logger.sharedData[this.name];
713
+ } else {
714
+ this.color = this.getRandomColor();
715
+ Logger.colorsInUse.push(this.color);
185
716
  }
186
- this.color = Logger.sharedData[this.name];
187
- } else {
188
- this.color = this.getRandomColor();
189
- Logger.colorsInUse.push(this.color);
717
+ this.outputHandler = console.log;
718
+ this.defaultStyle = ["color: grey;font-size:7px", "display: block", "color: ".concat(this.color), "color: grey", "font-weight: bold", "color: #607D8B", "font-size: 16px;color: red;font-weight:800"];
190
719
  }
191
- this.outputHandler = console.log;
192
- this.defaultStyle = ["color: grey;font-size:7px", "display: block", `color: ${this.color}`, "color: grey", "font-weight: bold", "color: #607D8B", "font-size: 16px;color: red;font-weight:800"];
193
- }
194
- /**
195
- * Function setOutputHandler() : Set custom output handler.
196
- */
197
- setOutputHandler(outputHandler) {
198
- this.outputHandler = outputHandler;
199
- }
200
- /**
201
- * Function useWrapper() : Search for customized log view, each instance,
202
- * that typeof the instance was registered wrapper will have unique output
203
- * according to the registered callback.
204
- */
205
- useWrapper(obj, shouldHandleChildren = true) {
206
- if (!obj || 'object' !== typeof obj || Array.isArray(obj)) {
207
- return obj;
208
- }
209
- Logger.wrapperDepth++;
210
- // Result will lose classType (instanceOf will not work), now based on obj.
211
- let result = {
212
- ...obj
213
- };
214
- // @ts-ignore
215
- Object.values(Logger.wrappers).forEach(([wrapper]) => {
216
- if (obj instanceof wrapper.classType) {
217
- result = wrapper.callback(obj) || result;
720
+
721
+ /**
722
+ * Function setOutputHandler() : Set custom output handler.
723
+ */
724
+ }, {
725
+ key: "setOutputHandler",
726
+ value: function setOutputHandler(outputHandler) {
727
+ this.outputHandler = outputHandler;
728
+ }
729
+
730
+ /**
731
+ * Function useWrapper() : Search for customized log view, each instance,
732
+ * that typeof the instance was registered wrapper will have unique output
733
+ * according to the registered callback.
734
+ */
735
+ }, {
736
+ key: "useWrapper",
737
+ value: function useWrapper(obj) {
738
+ var _this = this;
739
+ var shouldHandleChildren = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
740
+ if (!obj || 'object' !== _typeof(obj) || Array.isArray(obj)) {
741
+ return obj;
742
+ }
743
+ Logger.wrapperDepth++;
744
+
745
+ // Result will lose classType (instanceOf will not work), now based on obj.
746
+ var result = _objectSpread2({}, obj);
747
+
748
+ // @ts-ignore
749
+ Object.values(Logger.wrappers).forEach(function (_ref) {
750
+ var _ref2 = _slicedToArray(_ref, 1),
751
+ wrapper = _ref2[0];
752
+ if (obj instanceof wrapper.classType) {
753
+ result = wrapper.callback(obj) || result;
754
+ }
755
+ });
756
+ if (Logger.wrapperDepth >= MAX_WRAPPING_RECURSIVE_DEPTH) {
757
+ Logger.wrapperDepth--;
758
+ return result;
759
+ }
760
+ if (shouldHandleChildren && result) {
761
+ Object.entries(result).forEach(function (_ref3) {
762
+ var _ref4 = _slicedToArray(_ref3, 2),
763
+ key = _ref4[0],
764
+ value = _ref4[1];
765
+ result[key] = _this.useWrapper(value, true);
766
+ });
218
767
  }
219
- });
220
- if (Logger.wrapperDepth >= MAX_WRAPPING_RECURSIVE_DEPTH) {
221
768
  Logger.wrapperDepth--;
222
769
  return result;
223
770
  }
224
- if (shouldHandleChildren && result) {
225
- Object.entries(result).forEach(([key, value]) => {
226
- result[key] = this.useWrapper(value, true);
227
- });
771
+
772
+ /**
773
+ * Function startEmpty() : Notify function start without args.
774
+ *
775
+ * @param {string} output
776
+ */
777
+ }, {
778
+ key: "startEmpty",
779
+ value: function startEmpty() {
780
+ var output = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
781
+ if (!this.state) return;
782
+ this.printFunctionNotify("se", Logger.getCallerName(), output);
228
783
  }
229
- Logger.wrapperDepth--;
230
- return result;
231
- }
232
- /**
233
- * Function startEmpty() : Notify function start without args.
234
- *
235
- * @param {string} output
236
- */
237
- startEmpty(output = "") {
238
- if (!this.state) return;
239
- this.printFunctionNotify("se", Logger.getCallerName(), output);
240
- }
241
- /**
242
- * Function startWith() : Notify function start with args.
243
- *
244
- * TODO: Rename to startsWith
245
- */
246
- startWith(params) {
247
- if (!this.state) return;
248
- params = Object.assign({}, params);
249
- const type = "se";
250
- const source = Logger.getCallerName();
251
- if (typeof params == "string") {
252
- this.printInLineString(type, source, params);
253
- } else if (Object.keys(params).length === 1) {
254
- const key = Object.keys(params)[0];
255
- let value = Object.values(params)[0];
256
- // TODO: Check is repeated logic, handle it.
257
- if (typeof value === "object") {
258
- this.printNextLineObject(type, source, key, value || {});
259
- } else if (typeof value == "function") {
260
- this.printInLineFunction(type, source, key, value);
784
+
785
+ /**
786
+ * Function startWith() : Notify function start with args.
787
+ *
788
+ * TODO: Rename to startsWith
789
+ */
790
+ }, {
791
+ key: "startWith",
792
+ value: function startWith(params) {
793
+ if (!this.state) return;
794
+ params = Object.assign({}, params);
795
+ var type = "se";
796
+ var source = Logger.getCallerName();
797
+ if (typeof params == "string") {
798
+ this.printInLineString(type, source, params);
799
+ } else if (Object.keys(params).length === 1) {
800
+ var _key = Object.keys(params)[0];
801
+ var value = Object.values(params)[0];
802
+
803
+ // TODO: Check is repeated logic, handle it.
804
+ if (_typeof(value) === "object") {
805
+ this.printNextLineObject(type, source, _key, value || {});
806
+ } else if (typeof value == "function") {
807
+ this.printInLineFunction(type, source, _key, value);
808
+ } else {
809
+ this.printInLineElement(type, source, _key, value);
810
+ }
261
811
  } else {
262
- this.printInLineElement(type, source, key, value);
812
+ this.printMultiLineObject(type, source, params);
263
813
  }
264
- } else {
265
- this.printMultiLineObject(type, source, params);
266
814
  }
267
- }
268
- /**
269
- * Function object() : Prints object.
270
- **/
271
- object(params = {}, notice = "") {
272
- if (!this.state) return;
273
- const source = Logger.getCallerName();
274
- params = Object.create(params);
275
- for (let key in params) {
276
- if (typeof params[key] === "object") {
277
- params[key] = JSON.stringify(this.useWrapper(params[key]), getCircularReplacer());
815
+
816
+ /**
817
+ * Function object() : Prints object.
818
+ **/
819
+ }, {
820
+ key: "object",
821
+ value: function object() {
822
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
823
+ var notice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
824
+ if (!this.state) return;
825
+ var source = Logger.getCallerName();
826
+ params = Object.create(params);
827
+ for (var _key2 in params) {
828
+ if (_typeof(params[_key2]) === "object") {
829
+ params[_key2] = JSON.stringify(this.useWrapper(params[_key2]), getCircularReplacer());
830
+ }
831
+ this.out.apply(this, ["%c(ob)-> %c%c".concat(this.name, "%c::%c").concat(source, "%c() [").concat(notice, "] ->> ").concat(_key2, ": '").concat(params[_key2], "'%c")].concat(this.defaultStyle));
278
832
  }
279
- this.out.apply(this, [`%c(ob)-> %c%c${this.name}%c::%c${source}%c() [${notice}] ->> ${key}: '${params[key]}'%c`].concat(this.defaultStyle));
280
833
  }
281
- }
282
- /**
283
- * Function debug() : Notify debug.
284
- */
285
- debug(output) {
286
- if (!this.state) return;
287
- this.printFunctionNotify("db", Logger.getCallerName(), output);
288
- }
289
- /**
290
- * Function drop : Preview as continue of log which drop ite.
291
- */
292
- drop(according, data) {
293
- if (!this.state) return;
294
- const source = Logger.getCallerName();
295
- for (let key in according) {
296
- this.out.apply(this, [`%c(dr)-> %c%c${this.name}%c::%c${source}%c() ->> corresponding ${key}: '${according[key]}' RESULT: %c↓`].concat(this.defaultStyle));
834
+
835
+ /**
836
+ * Function debug() : Notify debug.
837
+ */
838
+ }, {
839
+ key: "debug",
840
+ value: function debug(output) {
841
+ if (!this.state) return;
842
+ this.printFunctionNotify("db", Logger.getCallerName(), output);
297
843
  }
298
- this.out(data);
299
- }
300
- /**
301
- * Function throw() : Throws logged error.
302
- */
303
- throw(output, name = 'null', params = {}) {
304
- this.printFunctionNotify("tw", Logger.getCallerName(), output);
305
- if (params) this.printNextLineObject("tw", Logger.getCallerName(), name, params);
306
- throw new Error().stack;
307
- }
308
- /**
309
- * Function clone() : Create clone instance.
310
- */
311
- clone() {
312
- return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
313
- }
314
- /**
315
- * Function printFunctionNotify() : Print simple log for notify source (function).
316
- *
317
- */
318
- printFunctionNotify(type, source, output) {
319
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ${output}%c`].concat(this.defaultStyle));
320
- }
321
- /**
322
- * Function printInLineElement() : Print in line element.
323
- */
324
- printInLineElement(type, source, key, value) {
325
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ->> ${key}: '${value}'%c`].concat(this.defaultStyle));
326
- }
327
- /**
328
- * Function printInLineFunction() : Print in line function.
329
- */
330
- printInLineFunction(type, source, key, fn) {
331
- fn = Logger.getFunctionView(fn);
332
- this.printInLineElement(type, source, key, fn);
333
- }
334
- /**
335
- * Function printInLineString() : Print in line string.
336
- */
337
- printInLineString(type, source, string) {
338
- this.printInLineElement(type, source, "(string)", string);
339
- }
340
- /**
341
- * Function printNextLineObject() : Print object in next line.
342
- */
343
- printNextLineObject(type, source, key, obj) {
344
- obj = this.useWrapper(obj);
345
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ->> ${key} %c↓`].concat(this.defaultStyle));
346
- // print in next line
347
- this.out(obj);
348
- }
349
- /**
350
- * Function printMultiLineObject() : Print object in multiline format.
351
- */
352
- printMultiLineObject(type, source, obj) {
353
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c(${Object.keys(obj).join(", ")}) %c↓`].concat(this.defaultStyle));
354
- for (let key in obj) {
355
- let value = obj[key];
356
- if (typeof value === "object") {
357
- value = JSON.stringify(this.useWrapper(value), getCircularReplacer());
358
- } else if (typeof obj[key] == "function") {
359
- value = Logger.getFunctionView(value);
844
+
845
+ /**
846
+ * Function drop : Preview as continue of log which drop ite.
847
+ */
848
+ }, {
849
+ key: "drop",
850
+ value: function drop(according, data) {
851
+ if (!this.state) return;
852
+ var source = Logger.getCallerName();
853
+ for (var _key3 in according) {
854
+ this.out.apply(this, ["%c(dr)-> %c%c".concat(this.name, "%c::%c").concat(source, "%c() ->> corresponding ").concat(_key3, ": '").concat(according[_key3], "' RESULT: %c\u2193")].concat(this.defaultStyle));
360
855
  }
361
- this.out.apply(this, ["%c" + key + ": `" + this.useWrapper(value) + "`", "color: #a3a3a3"]);
856
+ this.out(data);
362
857
  }
363
- }
364
- /**
365
- * Function getRandomColor() : Return random color.
366
- */
367
- getRandomColor() {
368
- const letters = "0123456789ABCDEF";
369
- let color = "#";
370
- for (let i = 0; i < 6; i++) {
371
- color += letters[Math.floor(Math.random() * 16)];
372
- }
373
- let similar = Logger.colorsInUse.some(value => {
374
- // it returns the ratio of difference... closer to 1.0 is less difference.
375
- return hexColorDelta(color, value) >= 0.8;
376
- });
377
- // if the color is similar, try again.
378
- if (similar) {
379
- return this.getRandomColor();
858
+
859
+ /**
860
+ * Function throw() : Throws logged error.
861
+ */
862
+ }, {
863
+ key: "throw",
864
+ value: function _throw(output) {
865
+ var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'null';
866
+ var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
867
+ this.printFunctionNotify("tw", Logger.getCallerName(), output);
868
+ if (params) this.printNextLineObject("tw", Logger.getCallerName(), name, params);
869
+ throw new Error().stack;
380
870
  }
381
- return color;
382
- }
383
- /**
384
- * Function out() : Print console log with style
385
- */
386
- out(...args) {
387
- this.outputHandler.apply(this, args);
388
- }
389
- }
390
871
 
391
- /**
392
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
393
- * @description: Base for all commands, they are all will be managed by the `Commands` managers.
394
- * @TODO
395
- * - Add validateArgs method or find something better.
396
- */
397
- class CommandBase extends ObjectBase {
398
- args = {};
399
- options = {};
400
- logger;
401
- constructor(args = {}, options = {}) {
402
- super();
403
- const name = this.constructor.getName();
404
- this.logger = new Logger(name, true, {
405
- sameColor: true
406
- });
407
- this.logger.startWith({
408
- args,
409
- options
410
- });
411
- this.initialize(args, options);
412
- }
413
- initialize(args, options) {
414
- this.args = args;
415
- this.options = options;
416
- }
417
- apply(args = this.args, options = this.options) {
418
- throw new ForceMethod(this, "apply");
419
- }
420
- async run() {
421
- this.onBeforeApply && this.onBeforeApply();
422
- const result = await this.apply(this.args, this.options);
423
- this.onAfterApply && this.onAfterApply();
424
- return result;
425
- }
426
- getArgs() {
427
- return this.args;
428
- }
429
- getOptions() {
430
- return this.options;
431
- }
432
- }
872
+ /**
873
+ * Function clone() : Create clone instance.
874
+ */
875
+ }, {
876
+ key: "clone",
877
+ value: function clone() {
878
+ return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
879
+ }
433
880
 
434
- /**
435
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
436
- * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
437
- * */
438
- class CommandPublic extends CommandBase {
439
- static getName() {
440
- return 'Core/CommandBases/CommandPublic';
441
- }
442
- }
881
+ /**
882
+ * Function printFunctionNotify() : Print simple log for notify source (function).
883
+ *
884
+ */
885
+ }, {
886
+ key: "printFunctionNotify",
887
+ value: function printFunctionNotify(type, source, output) {
888
+ this.out.apply(this, ["%c(".concat(type, ")-> %c%c").concat(this.name, "%c::%c").concat(source, "%c() ").concat(output, "%c")].concat(this.defaultStyle));
889
+ }
443
890
 
444
- const managers = {
445
- commands: {},
446
- controllers: {},
447
- data: {},
448
- internal: {}
449
- };
891
+ /**
892
+ * Function printInLineElement() : Print in line element.
893
+ */
894
+ }, {
895
+ key: "printInLineElement",
896
+ value: function printInLineElement(type, source, key, value) {
897
+ this.out.apply(this, ["%c(".concat(type, ")-> %c%c").concat(this.name, "%c::%c").concat(source, "%c() ->> ").concat(key, ": '").concat(value, "'%c")].concat(this.defaultStyle));
898
+ }
450
899
 
451
- /**
452
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
453
- * @description: Each data command should represent a final REST endpoint.
454
- */
455
- class CommandData extends CommandBase {
456
- static getName() {
457
- return 'Core/CommandBases/CommandData';
458
- }
459
- /**
460
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
461
- * @example
462
- * ```
463
- * args = { query: { id: 1 } };
464
- * getEndpoint() = '/api/v1/users/{id}';
465
- * result = '/api/v1/users/1';
466
- * ```
467
- */
468
- getEndpoint() {
469
- throw new ForceMethod(this, 'getEndpoint');
470
- }
471
- apply(args = this.args, options = this.options) {
472
- const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
473
- return managers.data.getClient().fetch(endpoint, managers.data.currentHttpMethod, args || null);
474
- }
475
- applyEndpointFormat(endpoint, data = {}) {
476
- // Replace query with `magic` placeholders.
477
- if (endpoint.includes('{')) {
478
- endpoint = endpoint.split('/').map(endpointPart => {
479
- const match = endpointPart.match('\\{(.*?)\\}');
480
- if (match?.length && 'undefined' !== typeof data[match[1]]) {
481
- return data[match[1]];
900
+ /**
901
+ * Function printInLineFunction() : Print in line function.
902
+ */
903
+ }, {
904
+ key: "printInLineFunction",
905
+ value: function printInLineFunction(type, source, key, fn) {
906
+ fn = Logger.getFunctionView(fn);
907
+ this.printInLineElement(type, source, key, fn);
908
+ }
909
+
910
+ /**
911
+ * Function printInLineString() : Print in line string.
912
+ */
913
+ }, {
914
+ key: "printInLineString",
915
+ value: function printInLineString(type, source, string) {
916
+ this.printInLineElement(type, source, "(string)", string);
917
+ }
918
+
919
+ /**
920
+ * Function printNextLineObject() : Print object in next line.
921
+ */
922
+ }, {
923
+ key: "printNextLineObject",
924
+ value: function printNextLineObject(type, source, key, obj) {
925
+ obj = this.useWrapper(obj);
926
+ this.out.apply(this, ["%c(".concat(type, ")-> %c%c").concat(this.name, "%c::%c").concat(source, "%c() ->> ").concat(key, " %c\u2193")].concat(this.defaultStyle));
927
+ // print in next line
928
+ this.out(obj);
929
+ }
930
+
931
+ /**
932
+ * Function printMultiLineObject() : Print object in multiline format.
933
+ */
934
+ }, {
935
+ key: "printMultiLineObject",
936
+ value: function printMultiLineObject(type, source, obj) {
937
+ this.out.apply(this, ["%c(".concat(type, ")-> %c%c").concat(this.name, "%c::%c").concat(source, "%c(").concat(Object.keys(obj).join(", "), ") %c\u2193")].concat(this.defaultStyle));
938
+ for (var _key4 in obj) {
939
+ var value = obj[_key4];
940
+ if (_typeof(value) === "object") {
941
+ value = JSON.stringify(this.useWrapper(value), getCircularReplacer());
942
+ } else if (typeof obj[_key4] == "function") {
943
+ value = Logger.getFunctionView(value);
482
944
  }
483
- return endpointPart;
484
- }).join('/');
945
+ this.out.apply(this, ["%c" + _key4 + ": `" + this.useWrapper(value) + "`", "color: #a3a3a3"]);
946
+ }
485
947
  }
486
- return endpoint;
487
- }
948
+
949
+ /**
950
+ * Function getRandomColor() : Return random color.
951
+ */
952
+ }, {
953
+ key: "getRandomColor",
954
+ value: function getRandomColor() {
955
+ var letters = "0123456789ABCDEF";
956
+ var color = "#";
957
+ for (var i = 0; i < 6; i++) {
958
+ color += letters[Math.floor(Math.random() * 16)];
959
+ }
960
+ var similar = Logger.colorsInUse.some(function (value) {
961
+ // it returns the ratio of difference... closer to 1.0 is less difference.
962
+ return hexColorDelta(color, value) >= 0.8;
963
+ });
964
+
965
+ // if the color is similar, try again.
966
+ if (similar) {
967
+ return this.getRandomColor();
968
+ }
969
+ return color;
970
+ }
971
+
972
+ /**
973
+ * Function out() : Print console log with style
974
+ */
975
+ }, {
976
+ key: "out",
977
+ value: function out() {
978
+ for (var _len = arguments.length, args = new Array(_len), _key5 = 0; _key5 < _len; _key5++) {
979
+ args[_key5] = arguments[_key5];
980
+ }
981
+ this.outputHandler.apply(this, args);
982
+ }
983
+ }], [{
984
+ key: "getName",
985
+ value: function getName() {
986
+ return 'Core/Modules/Logger';
987
+ }
988
+
989
+ /**
990
+ * Function reset() : Reset logger globals.
991
+ */
992
+ }, {
993
+ key: "reset",
994
+ value: function reset() {
995
+ Logger.wrappers = {};
996
+ Logger.wrapperDepth = 0;
997
+ Logger.colorsInUse = [];
998
+ Logger.sharedData = {};
999
+ }
1000
+
1001
+ /**
1002
+ * Function createCustomWrapper() : Creates custom wrapper for log entities.
1003
+ */
1004
+ }, {
1005
+ key: "createCustomWrapper",
1006
+ value: function createCustomWrapper(classType, callback) {
1007
+ // @ts-ignore
1008
+ if (!Logger.wrappers[classType]) {
1009
+ // @ts-ignore
1010
+ Logger.wrappers[classType.name] = [];
1011
+ }
1012
+ // @ts-ignore
1013
+ Logger.wrappers[classType.name].push({
1014
+ classType: classType,
1015
+ callback: callback
1016
+ });
1017
+ }
1018
+
1019
+ /**
1020
+ * Function getCallerName() : Return caller name.
1021
+ */
1022
+ }, {
1023
+ key: "getCallerName",
1024
+ value: function getCallerName() {
1025
+ var error = new Error(),
1026
+ caller = error.stack ? error.stack.split("\n")[3].trim() : '_UNKNOWN_CALLER_NAME_';
1027
+ if (caller.startsWith("at new")) {
1028
+ return "constructor";
1029
+ }
1030
+ return caller.split(".")[1].split(" ")[0];
1031
+ }
1032
+
1033
+ /**
1034
+ * Function functionView() : Return function preview.
1035
+ */
1036
+ }, {
1037
+ key: "getFunctionView",
1038
+ value: function getFunctionView(fn) {
1039
+ var fReturn = "anonymous function()";
1040
+
1041
+ // TODO: Check if works.
1042
+ if (typeof fn !== "string" && fn.name.length !== 0) {
1043
+ fReturn = fn.name.split(" ")[1] + "()";
1044
+ }
1045
+ return fReturn;
1046
+ }
1047
+ }]);
1048
+ return Logger;
1049
+ }();
1050
+ _defineProperty(Logger, "wrappers", {});
1051
+ _defineProperty(Logger, "wrapperDepth", 0);
1052
+ _defineProperty(Logger, "sharedData", {});
1053
+ _defineProperty(Logger, "colorsInUse", []);
1054
+
1055
+ var index$5 = /*#__PURE__*/Object.freeze({
1056
+ __proto__: null,
1057
+ Logger: Logger
1058
+ });
1059
+
1060
+ function _isNativeFunction(fn) {
1061
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
488
1062
  }
489
1063
 
490
- /**
491
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
492
- * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
493
- */
494
- class CommandInternal extends CommandBase {
495
- static getName() {
496
- return 'Core/CommandBases/CommandInternal';
1064
+ function _construct(Parent, args, Class) {
1065
+ if (_isNativeReflectConstruct()) {
1066
+ _construct = Reflect.construct.bind();
1067
+ } else {
1068
+ _construct = function _construct(Parent, args, Class) {
1069
+ var a = [null];
1070
+ a.push.apply(a, args);
1071
+ var Constructor = Function.bind.apply(Parent, a);
1072
+ var instance = new Constructor();
1073
+ if (Class) _setPrototypeOf(instance, Class.prototype);
1074
+ return instance;
1075
+ };
497
1076
  }
1077
+ return _construct.apply(null, arguments);
1078
+ }
1079
+
1080
+ function _wrapNativeSuper(Class) {
1081
+ var _cache = typeof Map === "function" ? new Map() : undefined;
1082
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
1083
+ if (Class === null || !_isNativeFunction(Class)) return Class;
1084
+ if (typeof Class !== "function") {
1085
+ throw new TypeError("Super expression must either be null or a function");
1086
+ }
1087
+ if (typeof _cache !== "undefined") {
1088
+ if (_cache.has(Class)) return _cache.get(Class);
1089
+ _cache.set(Class, Wrapper);
1090
+ }
1091
+ function Wrapper() {
1092
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
1093
+ }
1094
+ Wrapper.prototype = Object.create(Class.prototype, {
1095
+ constructor: {
1096
+ value: Wrapper,
1097
+ enumerable: false,
1098
+ writable: true,
1099
+ configurable: true
1100
+ }
1101
+ });
1102
+ return _setPrototypeOf(Wrapper, Class);
1103
+ };
1104
+ return _wrapNativeSuper(Class);
498
1105
  }
499
1106
 
500
1107
  /**
501
1108
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
502
1109
  */
503
1110
 
504
- var index$4 = /*#__PURE__*/Object.freeze({
505
- __proto__: null,
506
- CommandBase: CommandBase,
507
- CommandData: CommandData,
508
- CommandInternal: CommandInternal,
509
- CommandPublic: CommandPublic
510
- });
1111
+ var CommandAlreadyRegistered = /*#__PURE__*/function (_Error) {
1112
+ _inherits(CommandAlreadyRegistered, _Error);
1113
+ var _super = _createSuper(CommandAlreadyRegistered);
1114
+ function CommandAlreadyRegistered(command) {
1115
+ _classCallCheck(this, CommandAlreadyRegistered);
1116
+ return _super.call(this, "Command: '".concat(command.getName(), "' is already registered"));
1117
+ }
1118
+ return _createClass(CommandAlreadyRegistered);
1119
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
511
1120
 
512
1121
  /**
513
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
514
- * @description: Responsible for commands, Aka ( CommandsSpace ).
515
- */
516
- class Controller extends ObjectBase {
517
- commands;
518
- data;
519
- internal;
520
- static getName() {
521
- return 'Core/Core/Controller';
522
- }
523
- constructor() {
524
- super();
525
- this.initialize();
526
- }
527
- initialize() {
528
- this.register();
529
- this.setupHooks && this.setupHooks();
530
- }
531
- register() {
532
- this.commands = managers.commands.register(this.getCommands(), this);
533
- this.data = managers.data.register(this.getData(), this);
534
- this.internal = managers.internal.register(this.getInternal(), this);
535
- }
536
- getCommands() {
537
- return {};
538
- }
539
- getData() {
540
- return {};
541
- }
542
- getInternal() {
543
- return {};
544
- }
545
- }
1122
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1123
+ */
1124
+ var CommandNotFound = /*#__PURE__*/function (_Error) {
1125
+ _inherits(CommandNotFound, _Error);
1126
+ var _super = _createSuper(CommandNotFound);
1127
+ function CommandNotFound(command) {
1128
+ _classCallCheck(this, CommandNotFound);
1129
+ return _super.call(this, "Command: '".concat(command, "' is not found"));
1130
+ }
1131
+ return _createClass(CommandNotFound);
1132
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
546
1133
 
547
- var index$3 = /*#__PURE__*/Object.freeze({
548
- __proto__: null,
549
- Controller: Controller,
550
- ObjectBase: ObjectBase
551
- });
1134
+ /**
1135
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1136
+ */
552
1137
 
553
- class CommandAlreadyRegistered extends Error {
554
- constructor(command) {
555
- super(`Command: '${command.getName()}' is already registered`);
556
- }
557
- }
1138
+ var ControllerAlreadyRegistered = /*#__PURE__*/function (_Error) {
1139
+ _inherits(ControllerAlreadyRegistered, _Error);
1140
+ var _super = _createSuper(ControllerAlreadyRegistered);
1141
+ function ControllerAlreadyRegistered(controller) {
1142
+ _classCallCheck(this, ControllerAlreadyRegistered);
1143
+ return _super.call(this, "Controller: '".concat(controller.getName(), "' is already registered"));
1144
+ }
1145
+ return _createClass(ControllerAlreadyRegistered);
1146
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
558
1147
 
559
1148
  /**
560
1149
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
561
1150
  */
562
- class CommandNotFound extends Error {
563
- constructor(command) {
564
- super(`Command: '${command}' is not found`);
565
- }
566
- }
567
1151
 
568
- class ControllerAlreadyRegistered extends Error {
569
- constructor(controller) {
570
- super(`Controller: '${controller.getName()}' is already registered`);
571
- }
572
- }
1152
+ var ForceMethodBase = /*#__PURE__*/function (_Error) {
1153
+ _inherits(ForceMethodBase, _Error);
1154
+ var _super = _createSuper(ForceMethodBase);
1155
+ function ForceMethodBase(className, methodName) {
1156
+ _classCallCheck(this, ForceMethodBase);
1157
+ return _super.call(this, "ForeMethod implementation: at '".concat(className, "' method: '").concat(methodName, "'"));
1158
+ }
1159
+ return _createClass(ForceMethodBase);
1160
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
1161
+ var ForceMethod = /*#__PURE__*/function (_Error2) {
1162
+ _inherits(ForceMethod, _Error2);
1163
+ var _super2 = _createSuper(ForceMethod);
1164
+ function ForceMethod(context, methodName) {
1165
+ _classCallCheck(this, ForceMethod);
1166
+ return _super2.call(this, "ForeMethod implementation: at '".concat(context.getName(), "' method: '").concat(methodName, "'"));
1167
+ }
1168
+ return _createClass(ForceMethod);
1169
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
573
1170
 
574
- var index$2 = /*#__PURE__*/Object.freeze({
1171
+ var index$4 = /*#__PURE__*/Object.freeze({
575
1172
  __proto__: null,
576
1173
  CommandAlreadyRegistered: CommandAlreadyRegistered,
577
1174
  CommandNotFound: CommandNotFound,
@@ -579,221 +1176,456 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
579
1176
  ForceMethod: ForceMethod
580
1177
  });
581
1178
 
582
- var index$1 = /*#__PURE__*/Object.freeze({
583
- __proto__: null,
584
- Logger: Logger
585
- });
1179
+ var IdCounter = 0;
586
1180
 
587
1181
  /**
588
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
589
- * @description: Responsible for manging/running/hooking commands.
1182
+ * Base class 4 *
590
1183
  */
591
- class Commands extends ObjectBase {
592
- static trace = [];
593
- current = {};
594
- currentArgs = {};
595
- trace = [];
596
- commands = {};
597
- onBeforeHooks = {};
598
- onBeforeUIHooks = {};
599
- onAfterHooks = {};
600
- onAfterOnceHooks = {};
601
- onAfterUIHooks = {};
602
- onAfterAffectHooks = {};
603
- logger;
604
- static getName() {
605
- return 'Core/Managers/Commands';
1184
+ var ObjectBase = /*#__PURE__*/function () {
1185
+ function ObjectBase() {
1186
+ _classCallCheck(this, ObjectBase);
1187
+ _defineProperty(this, "virtualId", 0);
1188
+ this.virtualId = IdCounter;
1189
+ APIIncreaseIdCounter();
606
1190
  }
607
- static async runCallbacks(callbacks, args = {}, options = {}) {
608
- const callbacksLength = callbacks?.length || 0;
609
- for (let i = 0; i < callbacksLength; ++i) {
610
- const callback = options.pop === true ? callbacks.pop() : callbacks[i];
611
- if (!callback) {
612
- throw new Error("Callback is not defined.");
1191
+ _createClass(ObjectBase, [{
1192
+ key: "getName",
1193
+ value: function getName() {
1194
+ return this.constructor.getName();
1195
+ }
1196
+ }], [{
1197
+ key: "getName",
1198
+ value: function getName() {
1199
+ throw new ForceMethodBase("ObjectBase", "getName");
1200
+ }
1201
+ }]);
1202
+ return ObjectBase;
1203
+ }();
1204
+ function APIIncreaseIdCounter() {
1205
+ return IdCounter++;
1206
+ }
1207
+
1208
+ var Commands = /*#__PURE__*/function (_ObjectBase) {
1209
+ _inherits(Commands, _ObjectBase);
1210
+ var _super = _createSuper(Commands);
1211
+ function Commands() {
1212
+ var _this;
1213
+ _classCallCheck(this, Commands);
1214
+ _this = _super.call(this);
1215
+ _defineProperty(_assertThisInitialized(_this), "current", {});
1216
+ _defineProperty(_assertThisInitialized(_this), "currentArgs", {});
1217
+ _defineProperty(_assertThisInitialized(_this), "trace", []);
1218
+ _defineProperty(_assertThisInitialized(_this), "commands", {});
1219
+ _defineProperty(_assertThisInitialized(_this), "onBeforeHooks", {});
1220
+ _defineProperty(_assertThisInitialized(_this), "onBeforeUIHooks", {});
1221
+ _defineProperty(_assertThisInitialized(_this), "onAfterHooks", {});
1222
+ _defineProperty(_assertThisInitialized(_this), "onAfterOnceHooks", {});
1223
+ _defineProperty(_assertThisInitialized(_this), "onAfterUIHooks", {});
1224
+ _defineProperty(_assertThisInitialized(_this), "onAfterAffectHooks", {});
1225
+ _this.logger = new Logger(_this.getName(), true);
1226
+ _this.logger.startEmpty();
1227
+ return _this;
1228
+ }
1229
+ _createClass(Commands, [{
1230
+ key: "run",
1231
+ value: function () {
1232
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(command) {
1233
+ var args,
1234
+ options,
1235
+ result,
1236
+ _args = arguments;
1237
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1238
+ while (1) switch (_context.prev = _context.next) {
1239
+ case 0:
1240
+ args = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
1241
+ options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
1242
+ if (typeof command === "string") {
1243
+ command = this.getCommandInstance(command, args, options);
1244
+ }
1245
+ this.attachCurrent(command, args);
1246
+ _context.next = 6;
1247
+ return this.runInstance(command, args, options);
1248
+ case 6:
1249
+ result = _context.sent;
1250
+ this.detachCurrent(command);
1251
+ return _context.abrupt("return", result);
1252
+ case 9:
1253
+ case "end":
1254
+ return _context.stop();
1255
+ }
1256
+ }, _callee, this);
1257
+ }));
1258
+ function run(_x) {
1259
+ return _run.apply(this, arguments);
613
1260
  }
614
- await callback(args, options);
1261
+ return run;
1262
+ }()
1263
+ }, {
1264
+ key: "register",
1265
+ value: function register(commands, controller) {
1266
+ var _this2 = this;
1267
+ // eslint-disable-line @typescript-eslint/no-unused-vars
1268
+ var result = {};
1269
+ Object.values(commands).forEach(function (command) {
1270
+ var commandName = command.getName();
1271
+ if (_this2.commands[commandName]) {
1272
+ throw new CommandAlreadyRegistered(command);
1273
+ }
1274
+ _this2.commands[commandName] = command;
1275
+ result[commandName] = command;
1276
+ });
1277
+ return result;
615
1278
  }
616
- }
617
- static hookCommand(stack, hookCommand, context) {
618
- if (!stack[hookCommand]) {
619
- stack[hookCommand] = [];
1279
+ }, {
1280
+ key: "getAll",
1281
+ value: function getAll() {
1282
+ return this.commands;
620
1283
  }
621
- stack[hookCommand].push(context);
622
- }
623
- constructor() {
624
- super();
625
- this.logger = new Logger(this.getName(), true);
626
- this.logger.startEmpty();
627
- }
628
- async run(command, args = {}, options = {}) {
629
- if (typeof command === "string") {
630
- command = this.getCommandInstance(command, args, options);
631
- }
632
- this.attachCurrent(command, args);
633
- const result = await this.runInstance(command, args, options);
634
- this.detachCurrent(command);
635
- return result;
636
- }
637
- register(commands, controller) {
638
- const result = {};
639
- Object.values(commands).forEach(command => {
640
- const commandName = command.getName();
641
- if (this.commands[commandName]) {
642
- throw new CommandAlreadyRegistered(command);
1284
+ }, {
1285
+ key: "getByName",
1286
+ value: function getByName(name) {
1287
+ return this.commands[name];
1288
+ }
1289
+ }, {
1290
+ key: "getLogger",
1291
+ value: function getLogger() {
1292
+ return this.logger;
1293
+ }
1294
+ }, {
1295
+ key: "getCommandInstance",
1296
+ value: function getCommandInstance(name) {
1297
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1298
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1299
+ var CommandClass = this.commands[name];
1300
+ if (!CommandClass) {
1301
+ throw new CommandNotFound(name);
643
1302
  }
644
- this.commands[commandName] = command;
645
- result[commandName] = command;
646
- });
647
- return result;
648
- }
649
- getAll() {
650
- return this.commands;
651
- }
652
- getByName(name) {
653
- return this.commands[name];
654
- }
655
- getLogger() {
656
- return this.logger;
657
- }
658
- getCommandInstance(name, args = {}, options = {}) {
659
- const CommandClass = this.commands[name];
660
- if (!CommandClass) {
661
- throw new CommandNotFound(name);
1303
+
1304
+ // @ts-ignore
1305
+ return new CommandClass(args, options);
662
1306
  }
663
- // @ts-ignore
664
- return new CommandClass(args, options);
665
- }
666
- /**
667
- * Function onBefore() : Used to set hooks that effects only data and not UI.
668
- */
669
- onBefore(hookCommand, callback) {
670
- Commands.hookCommand(this.onBeforeHooks, hookCommand, callback);
671
- }
672
- /**
673
- * Function onBeforeUI() : Used to set hooks that effects only UI.
674
- */
675
- onBeforeUI(hookCommand, callback) {
676
- Commands.hookCommand(this.onBeforeUIHooks, hookCommand, callback);
677
- }
678
- /**
679
- * Function onAfter() : Used to set hooks that effects only data and not UI.
680
- */
681
- onAfter(hookCommand, callback) {
682
- Commands.hookCommand(this.onAfterHooks, hookCommand, callback);
683
- }
684
- /**
685
- * Function onAfterUI() : Used to set hooks that effects only UI.
686
- */
687
- onAfterUI(command, callback) {
688
- Commands.hookCommand(this.onAfterUIHooks, command, callback);
689
- }
690
- /**
691
- * Function onAfterOnce() : Used to set hooks that effects only data and not UI.
692
- */
693
- onAfterOnce(command, callback) {
694
- Commands.hookCommand(this.onAfterOnceHooks, command, callback);
695
- }
696
- /**
697
- * Function onAfterAffect() : Used to register a trigger that runs command after `hookCommand` run's.
698
- */
699
- onAfterAffect(hookCommand, affectCommand) {
700
- Commands.hookCommand(this.onAfterAffectHooks, hookCommand, affectCommand);
701
- }
702
- onBeforeRun(command, args = {}, options = {}) {
703
- if (this.onBeforeHooks[command.getName()]) {
704
- const callbacks = this.onBeforeHooks[command.getName()];
705
- callbacks.forEach(callback => callback(args, options));
1307
+
1308
+ /**
1309
+ * Function onBefore() : Used to set hooks that effects only data and not UI.
1310
+ */
1311
+ }, {
1312
+ key: "onBefore",
1313
+ value: function onBefore(hookCommand, callback) {
1314
+ Commands.hookCommand(this.onBeforeHooks, hookCommand, callback);
706
1315
  }
707
- if (this.onBeforeUIHooks[command.getName()]) {
708
- const callbacks = this.onBeforeUIHooks[command.getName()];
709
- callbacks.forEach(callback => callback(args, options));
1316
+
1317
+ /**
1318
+ * Function onBeforeUI() : Used to set hooks that effects only UI.
1319
+ */
1320
+ }, {
1321
+ key: "onBeforeUI",
1322
+ value: function onBeforeUI(hookCommand, callback) {
1323
+ Commands.hookCommand(this.onBeforeUIHooks, hookCommand, callback);
710
1324
  }
711
- }
712
- async runInstance(command, args = {}, options = {}) {
713
- let result = null;
714
- // TODO: Maybe a logger method to handle such cases.
715
- if (Object.keys(args).length) {
716
- this.logger.startWith({
717
- command: command.getName(),
718
- options,
719
- CommandArgs: "->"
720
- });
721
- this.logger.debug("CommandArgs:");
722
- this.logger.object(args);
723
- } else {
724
- this.logger.startWith({
725
- command: command.getName(),
726
- options,
727
- args
728
- });
1325
+
1326
+ /**
1327
+ * Function onAfter() : Used to set hooks that effects only data and not UI.
1328
+ */
1329
+ }, {
1330
+ key: "onAfter",
1331
+ value: function onAfter(hookCommand, callback) {
1332
+ Commands.hookCommand(this.onAfterHooks, hookCommand, callback);
729
1333
  }
730
- this.onBeforeRun(command, args, options);
731
- result = await command.run();
732
- await this.onAfterRun(command, args, options, result);
733
- return result;
734
- }
735
- async onAfterRun(command, args, options, result) {
736
- options = Object.assign({}, options);
737
- if (this.onAfterAffectHooks[command.getName()]) {
738
- this.onAfterAffectHooks[command.getName()].forEach(command => {
739
- args.result = result;
740
- result = this.run(command.toString(), args, options);
741
- });
742
- result = await result;
1334
+
1335
+ /**
1336
+ * Function onAfterUI() : Used to set hooks that effects only UI.
1337
+ */
1338
+ }, {
1339
+ key: "onAfterUI",
1340
+ value: function onAfterUI(command, callback) {
1341
+ Commands.hookCommand(this.onAfterUIHooks, command, callback);
1342
+ }
1343
+
1344
+ /**
1345
+ * Function onAfterOnce() : Used to set hooks that effects only data and not UI.
1346
+ */
1347
+ }, {
1348
+ key: "onAfterOnce",
1349
+ value: function onAfterOnce(command, callback) {
1350
+ Commands.hookCommand(this.onAfterOnceHooks, command, callback);
743
1351
  }
744
- if (this.onAfterHooks) {
745
- args.result = result;
746
- await Commands.runCallbacks(Object.assign([], this.onAfterHooks[command.getName()]), args, options);
1352
+
1353
+ /**
1354
+ * Function onAfterAffect() : Used to register a trigger that runs command after `hookCommand` run's.
1355
+ */
1356
+ }, {
1357
+ key: "onAfterAffect",
1358
+ value: function onAfterAffect(hookCommand, affectCommand) {
1359
+ Commands.hookCommand(this.onAfterAffectHooks, hookCommand, affectCommand);
747
1360
  }
748
- if (this.onAfterOnceHooks) {
749
- await Commands.runCallbacks(this.onAfterOnceHooks[command.getName()], args, {
750
- ...options,
751
- pop: true // Delete after run.
752
- });
1361
+ }, {
1362
+ key: "onBeforeRun",
1363
+ value: function onBeforeRun(command) {
1364
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1365
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1366
+ if (this.onBeforeHooks[command.getName()]) {
1367
+ var callbacks = this.onBeforeHooks[command.getName()];
1368
+ callbacks.forEach(function (callback) {
1369
+ return callback(args, options);
1370
+ });
1371
+ }
1372
+ if (this.onBeforeUIHooks[command.getName()]) {
1373
+ var _callbacks = this.onBeforeUIHooks[command.getName()];
1374
+ _callbacks.forEach(function (callback) {
1375
+ return callback(args, options);
1376
+ });
1377
+ }
1378
+ }
1379
+ }, {
1380
+ key: "runInstance",
1381
+ value: function () {
1382
+ var _runInstance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(command) {
1383
+ var args,
1384
+ options,
1385
+ result,
1386
+ _args2 = arguments;
1387
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1388
+ while (1) switch (_context2.prev = _context2.next) {
1389
+ case 0:
1390
+ args = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
1391
+ options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
1392
+ result = null; // TODO: Maybe a logger method to handle such cases.
1393
+ if (Object.keys(args).length) {
1394
+ this.logger.startWith({
1395
+ command: command.getName(),
1396
+ options: options,
1397
+ CommandArgs: "->"
1398
+ });
1399
+ this.logger.debug("CommandArgs:");
1400
+ this.logger.object(args);
1401
+ } else {
1402
+ this.logger.startWith({
1403
+ command: command.getName(),
1404
+ options: options,
1405
+ args: args
1406
+ });
1407
+ }
1408
+ this.onBeforeRun(command, args, options);
1409
+ _context2.next = 7;
1410
+ return command.run();
1411
+ case 7:
1412
+ result = _context2.sent;
1413
+ _context2.next = 10;
1414
+ return this.onAfterRun(command, args, options, result);
1415
+ case 10:
1416
+ return _context2.abrupt("return", result);
1417
+ case 11:
1418
+ case "end":
1419
+ return _context2.stop();
1420
+ }
1421
+ }, _callee2, this);
1422
+ }));
1423
+ function runInstance(_x2) {
1424
+ return _runInstance.apply(this, arguments);
1425
+ }
1426
+ return runInstance;
1427
+ }()
1428
+ }, {
1429
+ key: "onAfterRun",
1430
+ value: function () {
1431
+ var _onAfterRun = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(command, args, options, result) {
1432
+ var _this3 = this;
1433
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1434
+ while (1) switch (_context3.prev = _context3.next) {
1435
+ case 0:
1436
+ options = Object.assign({}, options);
1437
+ if (!this.onAfterAffectHooks[command.getName()]) {
1438
+ _context3.next = 6;
1439
+ break;
1440
+ }
1441
+ this.onAfterAffectHooks[command.getName()].forEach(function (command) {
1442
+ args.result = result;
1443
+ result = _this3.run(command.toString(), args, options);
1444
+ });
1445
+ _context3.next = 5;
1446
+ return result;
1447
+ case 5:
1448
+ result = _context3.sent;
1449
+ case 6:
1450
+ if (!this.onAfterHooks) {
1451
+ _context3.next = 10;
1452
+ break;
1453
+ }
1454
+ args.result = result;
1455
+ _context3.next = 10;
1456
+ return Commands.runCallbacks(Object.assign([], this.onAfterHooks[command.getName()]), args, options);
1457
+ case 10:
1458
+ if (!this.onAfterOnceHooks) {
1459
+ _context3.next = 13;
1460
+ break;
1461
+ }
1462
+ _context3.next = 13;
1463
+ return Commands.runCallbacks(this.onAfterOnceHooks[command.getName()], args, _objectSpread2(_objectSpread2({}, options), {}, {
1464
+ pop: true // Delete after run.
1465
+ }));
1466
+ case 13:
1467
+ if (this.onAfterUIHooks) {
1468
+ Commands.runCallbacks(Object.assign([], this.onAfterUIHooks[command.getName()]), args, options);
1469
+ }
1470
+ return _context3.abrupt("return", result);
1471
+ case 15:
1472
+ case "end":
1473
+ return _context3.stop();
1474
+ }
1475
+ }, _callee3, this);
1476
+ }));
1477
+ function onAfterRun(_x3, _x4, _x5, _x6) {
1478
+ return _onAfterRun.apply(this, arguments);
1479
+ }
1480
+ return onAfterRun;
1481
+ }()
1482
+ }, {
1483
+ key: "attachCurrent",
1484
+ value: function attachCurrent(command) {
1485
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1486
+ this.current[command.getName()] = command;
1487
+ this.currentArgs[command.getName()] = args;
1488
+ this.trace.push(command.getName());
1489
+ Commands.trace.push(command.getName());
753
1490
  }
1491
+ }, {
1492
+ key: "detachCurrent",
1493
+ value: function detachCurrent(command) {
1494
+ delete this.current[command.getName()];
1495
+ delete this.currentArgs[command.getName()];
1496
+ Commands.trace.pop();
1497
+ this.trace.pop();
1498
+ }
1499
+ }], [{
1500
+ key: "getName",
1501
+ value: function getName() {
1502
+ return 'Core/Managers/Commands';
1503
+ }
1504
+ }, {
1505
+ key: "runCallbacks",
1506
+ value: function () {
1507
+ var _runCallbacks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(callbacks) {
1508
+ var args,
1509
+ options,
1510
+ callbacksLength,
1511
+ i,
1512
+ callback,
1513
+ _args4 = arguments;
1514
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1515
+ while (1) switch (_context4.prev = _context4.next) {
1516
+ case 0:
1517
+ args = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
1518
+ options = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
1519
+ callbacksLength = (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length) || 0;
1520
+ i = 0;
1521
+ case 4:
1522
+ if (!(i < callbacksLength)) {
1523
+ _context4.next = 13;
1524
+ break;
1525
+ }
1526
+ callback = options.pop === true ? callbacks.pop() : callbacks[i];
1527
+ if (callback) {
1528
+ _context4.next = 8;
1529
+ break;
1530
+ }
1531
+ throw new Error("Callback is not defined.");
1532
+ case 8:
1533
+ _context4.next = 10;
1534
+ return callback(args, options);
1535
+ case 10:
1536
+ ++i;
1537
+ _context4.next = 4;
1538
+ break;
1539
+ case 13:
1540
+ case "end":
1541
+ return _context4.stop();
1542
+ }
1543
+ }, _callee4);
1544
+ }));
1545
+ function runCallbacks(_x7) {
1546
+ return _runCallbacks.apply(this, arguments);
1547
+ }
1548
+ return runCallbacks;
1549
+ }()
1550
+ }, {
1551
+ key: "hookCommand",
1552
+ value: function hookCommand(stack, _hookCommand, context) {
1553
+ if (!stack[_hookCommand]) {
1554
+ stack[_hookCommand] = [];
1555
+ }
1556
+ stack[_hookCommand].push(context);
1557
+ }
1558
+ }]);
1559
+ return Commands;
1560
+ }(ObjectBase);
1561
+ _defineProperty(Commands, "trace", []);
754
1562
 
755
- if (this.onAfterUIHooks) {
756
- Commands.runCallbacks(Object.assign([], this.onAfterUIHooks[command.getName()]), args, options);
1563
+ var Controllers = /*#__PURE__*/function (_ObjectBase) {
1564
+ _inherits(Controllers, _ObjectBase);
1565
+ var _super = _createSuper(Controllers);
1566
+ function Controllers() {
1567
+ var _this;
1568
+ _classCallCheck(this, Controllers);
1569
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1570
+ args[_key] = arguments[_key];
757
1571
  }
758
- return result;
759
- }
760
- attachCurrent(command, args = {}) {
761
- this.current[command.getName()] = command;
762
- this.currentArgs[command.getName()] = args;
763
- this.trace.push(command.getName());
764
- Commands.trace.push(command.getName());
765
- }
766
- detachCurrent(command) {
767
- delete this.current[command.getName()];
768
- delete this.currentArgs[command.getName()];
769
- Commands.trace.pop();
770
- this.trace.pop();
1572
+ _this = _super.call.apply(_super, [this].concat(args));
1573
+ _defineProperty(_assertThisInitialized(_this), "controllers", {});
1574
+ return _this;
1575
+ }
1576
+ _createClass(Controllers, [{
1577
+ key: "get",
1578
+ value: function get(name) {
1579
+ return this.controllers[name];
1580
+ }
1581
+ }, {
1582
+ key: "getAll",
1583
+ value: function getAll() {
1584
+ return this.controllers;
1585
+ }
1586
+ }, {
1587
+ key: "register",
1588
+ value: function register(controller) {
1589
+ if (this.controllers[controller.getName()]) {
1590
+ throw new ControllerAlreadyRegistered(controller);
1591
+ }
1592
+
1593
+ // Register.
1594
+ this.controllers[controller.getName()] = controller;
1595
+ return controller;
1596
+ }
1597
+ }], [{
1598
+ key: "getName",
1599
+ value: function getName() {
1600
+ return 'Core/Managers/Controllers';
1601
+ }
1602
+ }]);
1603
+ return Controllers;
1604
+ }(ObjectBase);
1605
+
1606
+ function _superPropBase(object, property) {
1607
+ while (!Object.prototype.hasOwnProperty.call(object, property)) {
1608
+ object = _getPrototypeOf(object);
1609
+ if (object === null) break;
771
1610
  }
1611
+ return object;
772
1612
  }
773
1613
 
774
- /**
775
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
776
- * @description: Responsible for manging controllers, each controller is global singleton instance.
777
- */
778
- class Controllers extends ObjectBase {
779
- controllers = {};
780
- static getName() {
781
- return 'Core/Managers/Controllers';
782
- }
783
- get(name) {
784
- return this.controllers[name];
785
- }
786
- getAll() {
787
- return this.controllers;
788
- }
789
- register(controller) {
790
- if (this.controllers[controller.getName()]) {
791
- throw new ControllerAlreadyRegistered(controller);
792
- }
793
- // Register.
794
- this.controllers[controller.getName()] = controller;
795
- return controller;
1614
+ function _get() {
1615
+ if (typeof Reflect !== "undefined" && Reflect.get) {
1616
+ _get = Reflect.get.bind();
1617
+ } else {
1618
+ _get = function _get(target, property, receiver) {
1619
+ var base = _superPropBase(target, property);
1620
+ if (!base) return;
1621
+ var desc = Object.getOwnPropertyDescriptor(base, property);
1622
+ if (desc.get) {
1623
+ return desc.get.call(arguments.length < 3 ? target : receiver);
1624
+ }
1625
+ return desc.value;
1626
+ };
796
1627
  }
1628
+ return _get.apply(this, arguments);
797
1629
  }
798
1630
 
799
1631
  /**
@@ -810,141 +1642,501 @@ var HTTPMethodEnum;
810
1642
  HTTPMethodEnum["__EMPTY__"] = "";
811
1643
  })(HTTPMethodEnum || (HTTPMethodEnum = {}));
812
1644
 
813
- /**
814
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
815
- * @description: Providing a simple wrapper for fetch API.
816
- */
817
- class Http extends ObjectBase {
818
- logger;
819
- apiBaseUrl;
820
- static getName() {
821
- return 'Core/Clients/Http';
822
- }
1645
+ var Http = /*#__PURE__*/function (_ObjectBase) {
1646
+ _inherits(Http, _ObjectBase);
1647
+ var _super = _createSuper(Http);
823
1648
  /**
824
1649
  * Function constructor() : Create the http.
825
1650
  */
826
- constructor(apiBaseUrl = 'http://localhost') {
827
- super();
828
- this.logger = new Logger(Http.getName(), true);
829
- this.logger.startWith({
830
- apiBaseUrl
1651
+ function Http() {
1652
+ var _this;
1653
+ var apiBaseUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'http://localhost';
1654
+ _classCallCheck(this, Http);
1655
+ _this = _super.call(this);
1656
+ _this.logger = new Logger(Http.getName(), true);
1657
+ _this.logger.startWith({
1658
+ apiBaseUrl: apiBaseUrl
831
1659
  });
832
- this.apiBaseUrl = apiBaseUrl + '/';
1660
+ _this.apiBaseUrl = apiBaseUrl + '/';
1661
+ return _this;
833
1662
  }
1663
+
834
1664
  /**
835
1665
  * Function fetch() : Fetch api.
836
1666
  */
837
- async fetch(path, method, body = null) {
838
- this.logger.startWith({
839
- path,
840
- method,
841
- body
842
- });
843
- const params = {
844
- 'credentials': 'include'
845
- },
846
- // Support cookies.
847
- headers = {};
848
- if ([HTTPMethodEnum.POST, HTTPMethodEnum.PUT, HTTPMethodEnum.PATCH].includes(method)) {
849
- Object.assign(headers, {
850
- 'Content-Type': 'application/json'
851
- });
852
- Object.assign(params, {
853
- method,
854
- headers: headers,
855
- body: JSON.stringify(body)
856
- });
857
- } else {
858
- Object.assign(params, {
859
- headers
860
- });
1667
+ _createClass(Http, [{
1668
+ key: "fetch",
1669
+ value: function () {
1670
+ var _fetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, method) {
1671
+ var _data, _data2, _data3;
1672
+ var body,
1673
+ params,
1674
+ headers,
1675
+ response,
1676
+ data,
1677
+ _args = arguments;
1678
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1679
+ while (1) switch (_context.prev = _context.next) {
1680
+ case 0:
1681
+ body = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
1682
+ this.logger.startWith({
1683
+ path: path,
1684
+ method: method,
1685
+ body: body
1686
+ });
1687
+ params = {
1688
+ 'credentials': 'include'
1689
+ }, headers = {};
1690
+ if ([HTTPMethodEnum.POST, HTTPMethodEnum.PUT, HTTPMethodEnum.PATCH].includes(method)) {
1691
+ Object.assign(headers, {
1692
+ 'Content-Type': 'application/json'
1693
+ });
1694
+ Object.assign(params, {
1695
+ method: method,
1696
+ headers: headers,
1697
+ body: JSON.stringify(body)
1698
+ });
1699
+ } else {
1700
+ Object.assign(params, {
1701
+ headers: headers
1702
+ });
1703
+ }
1704
+ _context.next = 6;
1705
+ return globalThis.fetch(this.apiBaseUrl + path, params);
1706
+ case 6:
1707
+ response = _context.sent;
1708
+ data = undefined;
1709
+ _context.prev = 8;
1710
+ _context.next = 11;
1711
+ return response.json();
1712
+ case 11:
1713
+ data = _context.sent;
1714
+ _context.next = 18;
1715
+ break;
1716
+ case 14:
1717
+ _context.prev = 14;
1718
+ _context.t0 = _context["catch"](8);
1719
+ console.error(_context.t0);
1720
+ return _context.abrupt("return", false);
1721
+ case 18:
1722
+ if (!((_data = data) !== null && _data !== void 0 && _data.error && (_data2 = data) !== null && _data2 !== void 0 && _data2.global && (_data3 = data) !== null && _data3 !== void 0 && _data3.message)) {
1723
+ _context.next = 20;
1724
+ break;
1725
+ }
1726
+ throw new Error(data.message);
1727
+ case 20:
1728
+ this.logger.drop({
1729
+ path: path
1730
+ }, data);
1731
+ return _context.abrupt("return", data);
1732
+ case 22:
1733
+ case "end":
1734
+ return _context.stop();
1735
+ }
1736
+ }, _callee, this, [[8, 14]]);
1737
+ }));
1738
+ function fetch(_x, _x2) {
1739
+ return _fetch.apply(this, arguments);
1740
+ }
1741
+ return fetch;
1742
+ }()
1743
+ }], [{
1744
+ key: "getName",
1745
+ value: function getName() {
1746
+ return 'Core/Clients/Http';
861
1747
  }
862
- const response = await globalThis.fetch(this.apiBaseUrl + path, params);
863
- let data = undefined;
864
- try {
865
- data = await response.json();
866
- } catch (e) {
867
- console.error(e);
868
- return false;
869
- }
870
- // TODO: This is part should be modular and not hard coded.
871
- if (data?.error && data?.global && data?.message) {
872
- throw new Error(data.message);
873
- }
874
- this.logger.drop({
875
- path
876
- }, data);
877
- return data;
878
- }
879
- }
1748
+ }]);
1749
+ return Http;
1750
+ }(ObjectBase);
1751
+
1752
+ var Data = /*#__PURE__*/function (_Commands) {
1753
+ _inherits(Data, _Commands);
1754
+ var _super = _createSuper(Data);
1755
+ function Data(Config) {
1756
+ var _this;
1757
+ _classCallCheck(this, Data);
1758
+ _this = _super.call(this);
880
1759
 
881
- /**
882
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
883
- * @description: Responsible for manging data commands which are wrappers for HTTP requests.
884
- */
885
- class Data extends Commands {
886
- static client;
887
- currentHttpMethod;
888
- static getName() {
889
- return 'Core/Managers/Data';
890
- }
891
- constructor(Config) {
892
- super();
893
1760
  // @ts-ignore
894
1761
  Data.client = new Http(Config.baseURL);
1762
+ return _this;
895
1763
  }
896
- getClient() {
897
- return Data.client;
898
- }
899
- get(command, args = {}, options = {}) {
900
- this.currentHttpMethod = HTTPMethodEnum.GET;
901
- return super.run(command, args, options);
902
- }
903
- update(command, args = {}, options = {}) {
904
- this.currentHttpMethod = HTTPMethodEnum.PATCH;
905
- return super.run(command, args, options);
906
- }
907
- delete(command, args = {}, options = {}) {
908
- this.currentHttpMethod = HTTPMethodEnum.DELETE;
909
- return super.run(command, args, options);
910
- }
911
- create(command, args = {}, options = {}) {
912
- this.currentHttpMethod = HTTPMethodEnum.POST;
913
- return super.run(command, args, options);
914
- }
915
- async runInstance(command, args = {}, options = {}) {
916
- if (!this.currentHttpMethod) {
917
- throw new Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');
918
- }
919
- // New args.
920
- const newArgs = {
921
- type: this.currentHttpMethod,
922
- args: {
923
- query: {},
924
- data: {}
1764
+ _createClass(Data, [{
1765
+ key: "getClient",
1766
+ value: function getClient() {
1767
+ return Data.client;
1768
+ }
1769
+ }, {
1770
+ key: "get",
1771
+ value: function get(command) {
1772
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1773
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1774
+ this.currentHttpMethod = HTTPMethodEnum.GET;
1775
+ return _get(_getPrototypeOf(Data.prototype), "run", this).call(this, command, args, options);
1776
+ }
1777
+ }, {
1778
+ key: "update",
1779
+ value: function update(command) {
1780
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1781
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1782
+ this.currentHttpMethod = HTTPMethodEnum.PATCH;
1783
+ return _get(_getPrototypeOf(Data.prototype), "run", this).call(this, command, args, options);
1784
+ }
1785
+ }, {
1786
+ key: "delete",
1787
+ value: function _delete(command) {
1788
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1789
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1790
+ this.currentHttpMethod = HTTPMethodEnum.DELETE;
1791
+ return _get(_getPrototypeOf(Data.prototype), "run", this).call(this, command, args, options);
1792
+ }
1793
+ }, {
1794
+ key: "create",
1795
+ value: function create(command) {
1796
+ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1797
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1798
+ this.currentHttpMethod = HTTPMethodEnum.POST;
1799
+ return _get(_getPrototypeOf(Data.prototype), "run", this).call(this, command, args, options);
1800
+ }
1801
+ }, {
1802
+ key: "runInstance",
1803
+ value: function () {
1804
+ var _runInstance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(command) {
1805
+ var args,
1806
+ options,
1807
+ newArgs,
1808
+ _args = arguments;
1809
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1810
+ while (1) switch (_context.prev = _context.next) {
1811
+ case 0:
1812
+ args = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
1813
+ options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
1814
+ if (this.currentHttpMethod) {
1815
+ _context.next = 4;
1816
+ break;
1817
+ }
1818
+ throw new Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');
1819
+ case 4:
1820
+ // New args.
1821
+ newArgs = {
1822
+ type: this.currentHttpMethod,
1823
+ args: {
1824
+ query: {},
1825
+ data: {}
1826
+ }
1827
+ };
1828
+ if (HTTPMethodEnum.GET === this.currentHttpMethod) {
1829
+ newArgs.args.query = args;
1830
+ } else {
1831
+ newArgs.args.data = args;
1832
+ }
1833
+ _context.next = 8;
1834
+ return _get(_getPrototypeOf(Data.prototype), "runInstance", this).call(this, command, newArgs, options);
1835
+ case 8:
1836
+ args.result = _context.sent;
1837
+ // Clear method type.
1838
+ this.currentHttpMethod = HTTPMethodEnum.__EMPTY__;
1839
+ return _context.abrupt("return", args.result);
1840
+ case 11:
1841
+ case "end":
1842
+ return _context.stop();
1843
+ }
1844
+ }, _callee, this);
1845
+ }));
1846
+ function runInstance(_x) {
1847
+ return _runInstance.apply(this, arguments);
925
1848
  }
926
- };
927
- if (HTTPMethodEnum.GET === this.currentHttpMethod) {
928
- newArgs.args.query = args;
929
- } else {
930
- newArgs.args.data = args;
1849
+ return runInstance;
1850
+ }()
1851
+ }], [{
1852
+ key: "getName",
1853
+ value: function getName() {
1854
+ return 'Core/Managers/Data';
931
1855
  }
932
- args.result = await super.runInstance(command, newArgs, options);
933
- // Clear method type.
934
- this.currentHttpMethod = HTTPMethodEnum.__EMPTY__;
935
- return args.result;
936
- }
937
- }
1856
+ }]);
1857
+ return Data;
1858
+ }(Commands);
1859
+
1860
+ var Internal = /*#__PURE__*/function (_Commands) {
1861
+ _inherits(Internal, _Commands);
1862
+ var _super = _createSuper(Internal);
1863
+ function Internal() {
1864
+ _classCallCheck(this, Internal);
1865
+ return _super.apply(this, arguments);
1866
+ }
1867
+ _createClass(Internal, null, [{
1868
+ key: "getName",
1869
+ value: function getName() {
1870
+ return 'Core/Managers/Internal';
1871
+ }
1872
+ }]);
1873
+ return Internal;
1874
+ }(Commands);
938
1875
 
939
1876
  /**
940
1877
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
941
- * @description: Responsible for manging internal commands, To serve commands that are not triggered by user.
942
1878
  */
943
- class Internal extends Commands {
944
- static getName() {
945
- return 'Core/Managers/Internal';
946
- }
1879
+ var afterInitializeCallbacks = [];
1880
+ function initialize(config) {
1881
+ commands = new Commands();
1882
+ controllers = new Controllers();
1883
+ data = new Data(config);
1884
+ internal = new Internal();
947
1885
  }
1886
+ function destroy() {
1887
+ commands = {};
1888
+ controllers = {};
1889
+ data = {};
1890
+ internal = {};
1891
+ }
1892
+ var commands = {};
1893
+ var controllers = {};
1894
+ var data = {};
1895
+ var internal = {};
1896
+
1897
+ var index$3 = /*#__PURE__*/Object.freeze({
1898
+ __proto__: null,
1899
+ afterInitializeCallbacks: afterInitializeCallbacks,
1900
+ get commands () { return commands; },
1901
+ get controllers () { return controllers; },
1902
+ get data () { return data; },
1903
+ destroy: destroy,
1904
+ initialize: initialize,
1905
+ get internal () { return internal; }
1906
+ });
1907
+
1908
+ var CommandBase = /*#__PURE__*/function (_ObjectBase) {
1909
+ _inherits(CommandBase, _ObjectBase);
1910
+ var _super = _createSuper(CommandBase);
1911
+ function CommandBase() {
1912
+ var _this;
1913
+ var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1914
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1915
+ _classCallCheck(this, CommandBase);
1916
+ _this = _super.call(this);
1917
+ _defineProperty(_assertThisInitialized(_this), "args", {});
1918
+ _defineProperty(_assertThisInitialized(_this), "options", {});
1919
+ var name = _this.constructor.getName();
1920
+ _this.logger = new Logger(name, true, {
1921
+ sameColor: true
1922
+ });
1923
+ _this.logger.startWith({
1924
+ args: args,
1925
+ options: options
1926
+ });
1927
+ _this.initialize(args, options);
1928
+ return _this;
1929
+ }
1930
+ _createClass(CommandBase, [{
1931
+ key: "initialize",
1932
+ value: function initialize(args, options) {
1933
+ this.args = args;
1934
+ this.options = options;
1935
+ }
1936
+ }, {
1937
+ key: "apply",
1938
+ value: function apply() {
1939
+ arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.args;
1940
+ arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options;
1941
+ // eslint-disable-line @typescript-eslint/no-unused-vars
1942
+ throw new ForceMethod(this, "apply");
1943
+ }
1944
+ }, {
1945
+ key: "run",
1946
+ value: function () {
1947
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1948
+ var result;
1949
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1950
+ while (1) switch (_context.prev = _context.next) {
1951
+ case 0:
1952
+ this.onBeforeApply && this.onBeforeApply();
1953
+ _context.next = 3;
1954
+ return this.apply(this.args, this.options);
1955
+ case 3:
1956
+ result = _context.sent;
1957
+ this.onAfterApply && this.onAfterApply();
1958
+ return _context.abrupt("return", result);
1959
+ case 6:
1960
+ case "end":
1961
+ return _context.stop();
1962
+ }
1963
+ }, _callee, this);
1964
+ }));
1965
+ function run() {
1966
+ return _run.apply(this, arguments);
1967
+ }
1968
+ return run;
1969
+ }()
1970
+ }, {
1971
+ key: "getArgs",
1972
+ value: function getArgs() {
1973
+ return this.args;
1974
+ }
1975
+ }, {
1976
+ key: "getOptions",
1977
+ value: function getOptions() {
1978
+ return this.options;
1979
+ }
1980
+ }]);
1981
+ return CommandBase;
1982
+ }(ObjectBase);
1983
+
1984
+ var CommandPublic = /*#__PURE__*/function (_CommandBase) {
1985
+ _inherits(CommandPublic, _CommandBase);
1986
+ var _super = _createSuper(CommandPublic);
1987
+ function CommandPublic() {
1988
+ _classCallCheck(this, CommandPublic);
1989
+ return _super.apply(this, arguments);
1990
+ }
1991
+ _createClass(CommandPublic, null, [{
1992
+ key: "getName",
1993
+ value: function getName() {
1994
+ return 'Core/CommandBases/CommandPublic';
1995
+ }
1996
+ }]);
1997
+ return CommandPublic;
1998
+ }(CommandBase);
1999
+
2000
+ var CommandData = /*#__PURE__*/function (_CommandBase) {
2001
+ _inherits(CommandData, _CommandBase);
2002
+ var _super = _createSuper(CommandData);
2003
+ function CommandData() {
2004
+ _classCallCheck(this, CommandData);
2005
+ return _super.apply(this, arguments);
2006
+ }
2007
+ _createClass(CommandData, [{
2008
+ key: "getEndpoint",
2009
+ value:
2010
+ /**
2011
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
2012
+ * @example
2013
+ * ```
2014
+ * args = { query: { id: 1 } };
2015
+ * getEndpoint() = '/api/v1/users/{id}';
2016
+ * result = '/api/v1/users/1';
2017
+ * ```
2018
+ */
2019
+ function getEndpoint() {
2020
+ throw new ForceMethod(this, 'getEndpoint');
2021
+ }
2022
+ }, {
2023
+ key: "apply",
2024
+ value: function apply() {
2025
+ var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.args;
2026
+ arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options;
2027
+ // eslint-disable-line @typescript-eslint/no-unused-vars
2028
+ var endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
2029
+ return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
2030
+ }
2031
+ }, {
2032
+ key: "applyEndpointFormat",
2033
+ value: function applyEndpointFormat(endpoint) {
2034
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2035
+ // Replace query with `magic` placeholders.
2036
+ if (endpoint.includes('{')) {
2037
+ endpoint = endpoint.split('/').map(function (endpointPart) {
2038
+ var match = endpointPart.match('\\{(.*?)\\}');
2039
+ if (match !== null && match !== void 0 && match.length && 'undefined' !== typeof data[match[1]]) {
2040
+ return data[match[1]];
2041
+ }
2042
+ return endpointPart;
2043
+ }).join('/');
2044
+ }
2045
+ return endpoint;
2046
+ }
2047
+ }], [{
2048
+ key: "getName",
2049
+ value: function getName() {
2050
+ return 'Core/CommandBases/CommandData';
2051
+ }
2052
+ }]);
2053
+ return CommandData;
2054
+ }(CommandBase);
2055
+
2056
+ var CommandInternal = /*#__PURE__*/function (_CommandBase) {
2057
+ _inherits(CommandInternal, _CommandBase);
2058
+ var _super = _createSuper(CommandInternal);
2059
+ function CommandInternal() {
2060
+ _classCallCheck(this, CommandInternal);
2061
+ return _super.apply(this, arguments);
2062
+ }
2063
+ _createClass(CommandInternal, null, [{
2064
+ key: "getName",
2065
+ value: function getName() {
2066
+ return 'Core/CommandBases/CommandInternal';
2067
+ }
2068
+ }]);
2069
+ return CommandInternal;
2070
+ }(CommandBase);
2071
+
2072
+ /**
2073
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2074
+ */
2075
+
2076
+ var index$2 = /*#__PURE__*/Object.freeze({
2077
+ __proto__: null,
2078
+ CommandBase: CommandBase,
2079
+ CommandData: CommandData,
2080
+ CommandInternal: CommandInternal,
2081
+ CommandPublic: CommandPublic
2082
+ });
2083
+
2084
+ var Controller = /*#__PURE__*/function (_ObjectBase) {
2085
+ _inherits(Controller, _ObjectBase);
2086
+ var _super = _createSuper(Controller);
2087
+ function Controller() {
2088
+ var _this;
2089
+ _classCallCheck(this, Controller);
2090
+ _this = _super.call(this);
2091
+ _this.initialize();
2092
+ return _this;
2093
+ }
2094
+ _createClass(Controller, [{
2095
+ key: "initialize",
2096
+ value: function initialize() {
2097
+ this.register();
2098
+ this.setupHooks && this.setupHooks();
2099
+ }
2100
+ }, {
2101
+ key: "register",
2102
+ value: function register() {
2103
+ this.commands = commands.register(this.getCommands(), this);
2104
+ this.data = data.register(this.getData(), this);
2105
+ this.internal = internal.register(this.getInternal(), this);
2106
+ }
2107
+ }, {
2108
+ key: "getCommands",
2109
+ value: function getCommands() {
2110
+ return {};
2111
+ }
2112
+ }, {
2113
+ key: "getData",
2114
+ value: function getData() {
2115
+ return {};
2116
+ }
2117
+ }, {
2118
+ key: "getInternal",
2119
+ value: function getInternal() {
2120
+ return {};
2121
+ }
2122
+
2123
+ /**
2124
+ * Function setupHooks() : Override this method to setup hooks.
2125
+ */
2126
+ }], [{
2127
+ key: "getName",
2128
+ value: function getName() {
2129
+ return 'Core/Core/Controller';
2130
+ }
2131
+ }]);
2132
+ return Controller;
2133
+ }(ObjectBase);
2134
+
2135
+ var index$1 = /*#__PURE__*/Object.freeze({
2136
+ __proto__: null,
2137
+ Controller: Controller,
2138
+ ObjectBase: ObjectBase
2139
+ });
948
2140
 
949
2141
  /**
950
2142
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
@@ -964,121 +2156,43 @@ Internal: Internal
964
2156
 
965
2157
  var exported = /*#__PURE__*/Object.freeze({
966
2158
  __proto__: null,
967
- commandBases: index$4,
968
- core: index$3,
969
- errors: index$2,
2159
+ commandBases: index$2,
2160
+ core: index$1,
2161
+ errors: index$4,
970
2162
  managerBases: index,
971
- modules: index$1,
972
- utils: index$5
2163
+ managers: index$3,
2164
+ modules: index$5,
2165
+ utils: index$6
973
2166
  });
974
2167
 
975
- var name = "@zenflux/core";
976
- var version = "0.0.0-abc.1";
977
- var description = "ZenFlux core";
978
- var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
979
- var scripts = {
980
- test: "export flow_modules_logger=off && jest",
981
- build: "rollup --config rollup.config.ts --configPlugin typescript"
982
- };
983
- var repository = {
984
- type: "git",
985
- url: "git+https://github.com/zenflux/core.git"
986
- };
987
- var keywords = [
988
- "zenflux",
989
- "zen",
990
- "flux",
991
- "commands",
992
- "manager",
993
- "commands manager"
994
- ];
995
- var files = [
996
- "dist",
997
- "src",
998
- "types"
999
- ];
1000
- var license = "MIT";
1001
- var main = "dist/cjs/zenflux-core.js";
1002
- var unpkg = "dist/umd/zenflux-core.js";
1003
- var module = "dist/es/zenflux-core.js";
1004
- var types = "types/index.d.ts";
1005
- var devDependencies = {
1006
- "@babel/core": "^7.20.7",
1007
- "@babel/plugin-transform-runtime": "^7.19.6",
1008
- "@babel/preset-env": "^7.20.2",
1009
- "@babel/preset-typescript": "^7.18.6",
1010
- "@babel/runtime": "^7.20.7",
1011
- "@rollup/plugin-babel": "^6.0.3",
1012
- "@rollup/plugin-json": "^6.0.0",
1013
- "@rollup/plugin-node-resolve": "^15.0.1",
1014
- "@rollup/plugin-replace": "^5.0.2",
1015
- "@rollup/plugin-terser": "^0.2.1",
1016
- "@rollup/plugin-typescript": "^10.0.1",
1017
- "@types/jest": "^29.2.5",
1018
- "@typescript-eslint/eslint-plugin": "^5.48.0",
1019
- "@typescript-eslint/parser": "^5.48.0",
1020
- "babel-jest": "^29.3.1",
1021
- rollup: "^3.9.1",
1022
- "ts-jest": "^29.0.3",
1023
- tslib: "^2.4.1"
1024
- };
1025
- var dependencies = {
1026
- "@babel/runtime": "^7.19.0"
1027
- };
1028
- var pkg = {
1029
- name: name,
1030
- version: version,
1031
- description: description,
1032
- author: author,
1033
- scripts: scripts,
1034
- repository: repository,
1035
- keywords: keywords,
1036
- files: files,
1037
- license: license,
1038
- main: main,
1039
- unpkg: unpkg,
1040
- module: module,
1041
- types: types,
1042
- devDependencies: devDependencies,
1043
- dependencies: dependencies
1044
- };
1045
-
1046
- let isInitialized = false;
2168
+ var isInitialized = false;
1047
2169
  function errorInitTwice() {
1048
2170
  if (isInitialized) {
1049
2171
  throw new Error('ZenCore is already initialized.');
1050
2172
  }
1051
2173
  }
1052
2174
  errorInitTwice();
1053
- let config = {
2175
+ var config = {
1054
2176
  version: pkg.version
1055
2177
  };
1056
- const afterInitializeCallbacks = [];
1057
- const CoreAPI = {
1058
- initialize: configuration => {
2178
+ var CoreAPI = _objectSpread2({
2179
+ initialize: function initialize$1(configuration) {
1059
2180
  errorInitTwice();
1060
2181
  config = configuration || config;
1061
- managers.commands = new Commands();
1062
- managers.controllers = new Controllers();
1063
- managers.data = new Data(config);
1064
- managers.internal = new Internal();
2182
+ initialize(config);
1065
2183
  isInitialized = true;
1066
- afterInitializeCallbacks.forEach(callback => callback());
1067
2184
  },
1068
- destroy: () => {
2185
+ destroy: function destroy$1() {
2186
+ destroy();
1069
2187
  isInitialized = false;
1070
- managers.commands = {};
1071
- managers.controllers = {};
1072
- managers.data = {};
1073
- managers.internal = {};
1074
2188
  },
1075
- onAfterInitialize: callback => {
2189
+ onAfterInitialize: function onAfterInitialize(callback) {
1076
2190
  afterInitializeCallbacks.push(callback);
1077
2191
  },
1078
- config,
1079
- ...exported
1080
- };
2192
+ config: config
2193
+ }, exported);
2194
+
1081
2195
  // TODO: Make it available only for development.
1082
- if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
2196
+ if (!(globalThis !== null && globalThis !== void 0 && globalThis.ZenCore)) globalThis.ZenCore = CoreAPI;
1083
2197
 
1084
- export { index$4 as commandBases, index$3 as core, CoreAPI as default, index$2 as errors, index as managerBases, index$1 as modules, index$5 as utils };
2198
+ export { index$2 as commandBases, index$1 as core, CoreAPI as default, index$4 as errors, index as managerBases, index$3 as managers, index$5 as modules, index$6 as utils };