@zenflux/core 0.0.0-abc.9 → 0.0.0-alpha.1

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