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