@zenflux/core 0.0.0-alpha.0 → 0.0.0-alpha.2

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,84 +1,625 @@
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.20";
65
+ var version = "0.0.0-alpha.2";
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.3",
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
 
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);
441
+ }
442
+ }
443
+ function _asyncToGenerator(fn) {
444
+ return function () {
445
+ var self = this,
446
+ args = arguments;
447
+ return new Promise(function (resolve, reject) {
448
+ var gen = fn.apply(self, args);
449
+ function _next(value) {
450
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
451
+ }
452
+ function _throw(err) {
453
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
454
+ }
455
+ _next(undefined);
456
+ });
457
+ };
458
+ }
459
+
460
+ function _classCallCheck(instance, Constructor) {
461
+ if (!(instance instanceof Constructor)) {
462
+ throw new TypeError("Cannot call a class as a function");
463
+ }
464
+ }
465
+
466
+ function _defineProperties(target, props) {
467
+ for (var i = 0; i < props.length; i++) {
468
+ var descriptor = props[i];
469
+ descriptor.enumerable = descriptor.enumerable || false;
470
+ descriptor.configurable = true;
471
+ if ("value" in descriptor) descriptor.writable = true;
472
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
473
+ }
474
+ }
475
+ function _createClass(Constructor, protoProps, staticProps) {
476
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
477
+ if (staticProps) _defineProperties(Constructor, staticProps);
478
+ Object.defineProperty(Constructor, "prototype", {
479
+ writable: false
480
+ });
481
+ return Constructor;
482
+ }
483
+
484
+ function _assertThisInitialized(self) {
485
+ if (self === void 0) {
486
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
487
+ }
488
+ return self;
489
+ }
490
+
491
+ function _setPrototypeOf(o, p) {
492
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
493
+ o.__proto__ = p;
494
+ return o;
495
+ };
496
+ return _setPrototypeOf(o, p);
497
+ }
498
+
499
+ function _inherits(subClass, superClass) {
500
+ if (typeof superClass !== "function" && superClass !== null) {
501
+ throw new TypeError("Super expression must either be null or a function");
502
+ }
503
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
504
+ constructor: {
505
+ value: subClass,
506
+ writable: true,
507
+ configurable: true
508
+ }
509
+ });
510
+ Object.defineProperty(subClass, "prototype", {
511
+ writable: false
512
+ });
513
+ if (superClass) _setPrototypeOf(subClass, superClass);
514
+ }
515
+
516
+ function _getPrototypeOf(o) {
517
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
518
+ return o.__proto__ || Object.getPrototypeOf(o);
519
+ };
520
+ return _getPrototypeOf(o);
521
+ }
522
+
523
+ function _isNativeReflectConstruct() {
524
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
525
+ if (Reflect.construct.sham) return false;
526
+ if (typeof Proxy === "function") return true;
527
+ try {
528
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
529
+ return true;
530
+ } catch (e) {
531
+ return false;
532
+ }
533
+ }
534
+
535
+ function _possibleConstructorReturn(self, call) {
536
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
537
+ return call;
538
+ } else if (call !== void 0) {
539
+ throw new TypeError("Derived constructors may only return object or undefined");
540
+ }
541
+ return _assertThisInitialized(self);
542
+ }
543
+
544
+ function _createSuper(Derived) {
545
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
546
+ return function _createSuperInternal() {
547
+ var Super = _getPrototypeOf(Derived),
548
+ result;
549
+ if (hasNativeReflectConstruct) {
550
+ var NewTarget = _getPrototypeOf(this).constructor;
551
+ result = Reflect.construct(Super, arguments, NewTarget);
552
+ } else {
553
+ result = Super.apply(this, arguments);
554
+ }
555
+ return _possibleConstructorReturn(this, result);
556
+ };
557
+ }
558
+
559
+ function _arrayWithHoles(arr) {
560
+ if (Array.isArray(arr)) return arr;
561
+ }
562
+
563
+ function _iterableToArrayLimit(arr, i) {
564
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
565
+ if (null != _i) {
566
+ var _s,
567
+ _e,
568
+ _x,
569
+ _r,
570
+ _arr = [],
571
+ _n = !0,
572
+ _d = !1;
573
+ try {
574
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
575
+ if (Object(_i) !== _i) return;
576
+ _n = !1;
577
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
578
+ } catch (err) {
579
+ _d = !0, _e = err;
580
+ } finally {
581
+ try {
582
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
583
+ } finally {
584
+ if (_d) throw _e;
585
+ }
586
+ }
587
+ return _arr;
588
+ }
589
+ }
590
+
591
+ function _arrayLikeToArray(arr, len) {
592
+ if (len == null || len > arr.length) len = arr.length;
593
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
594
+ return arr2;
595
+ }
596
+
597
+ function _unsupportedIterableToArray(o, minLen) {
598
+ if (!o) return;
599
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
600
+ var n = Object.prototype.toString.call(o).slice(8, -1);
601
+ if (n === "Object" && o.constructor) n = o.constructor.name;
602
+ if (n === "Map" || n === "Set") return Array.from(o);
603
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
604
+ }
605
+
606
+ function _nonIterableRest() {
607
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
608
+ }
609
+
610
+ function _slicedToArray(arr, i) {
611
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
612
+ }
613
+
73
614
  /**
74
615
  * Function getCircularReplacer() : Reduce circular references.
75
616
  *
76
617
  * @copyright https://stackoverflow.com/a/53731154
77
618
  */
78
- const getCircularReplacer = () => {
79
- const seen = new WeakSet();
80
- return (key, value) => {
81
- 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) {
82
623
  if (seen.has(value)) {
83
624
  return;
84
625
  }
@@ -93,25 +634,31 @@ const getCircularReplacer = () => {
93
634
  *
94
635
  * @copyright http://jsfiddle.net/96sME/
95
636
  */
96
- const hexColorDelta = function (hex1, hex2) {
637
+ var hexColorDelta = function hexColorDelta(hex1, hex2) {
97
638
  hex1 = hex1.replace("#", "");
98
639
  hex2 = hex2.replace("#", "");
640
+
99
641
  // Get red/green/blue int values of hex1
100
- const r1 = parseInt(hex1.substring(0, 2), 16);
101
- const g1 = parseInt(hex1.substring(2, 4), 16);
102
- 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
+
103
646
  // Get red/green/blue int values of hex2
104
- const r2 = parseInt(hex2.substring(0, 2), 16);
105
- const g2 = parseInt(hex2.substring(2, 4), 16);
106
- 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
+
107
651
  // Calculate differences between reds, greens and blues
108
- let r = 255 - Math.abs(r1 - r2);
109
- let g = 255 - Math.abs(g1 - g2);
110
- 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
+
111
656
  // Limit differences between 0 and 1
657
+
112
658
  r /= 255;
113
659
  g /= 255;
114
660
  b /= 255;
661
+
115
662
  // 0 means opposite colors, 1 means same colors
116
663
  return (r + g + b) / 3;
117
664
  };
@@ -122,80 +669,20 @@ getCircularReplacer: getCircularReplacer,
122
669
  hexColorDelta: hexColorDelta
123
670
  });
124
671
 
125
- /**
126
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
127
- * @description: Module for logging instances.
128
- * @TODO:
129
- * - Remove `@ts-ignore`, requires a refactor.
130
- * - Add night/white mode.
131
- */
132
672
  // TODO: Should by dynamic/configure-able.
133
- const MAX_WRAPPING_RECURSIVE_DEPTH = 4;
134
- class Logger {
135
- static wrappers = {};
136
- static wrapperDepth = 0;
137
- static sharedData = {};
138
- static colorsInUse = [];
139
- defaultStyle;
140
- color;
141
- outputHandler;
142
- args = {};
143
- name;
144
- state = false;
145
- static getName() {
146
- return 'Core/Modules/Logger';
147
- }
148
- /**
149
- * Function reset() : Reset logger globals.
150
- */
151
- static reset() {
152
- Logger.wrappers = {};
153
- Logger.wrapperDepth = 0;
154
- Logger.colorsInUse = [];
155
- Logger.sharedData = {};
156
- }
157
- /**
158
- * Function createCustomWrapper() : Creates custom wrapper for log entities.
159
- */
160
- static createCustomWrapper(classType, callback) {
161
- // @ts-ignore
162
- if (!Logger.wrappers[classType]) {
163
- // @ts-ignore
164
- Logger.wrappers[classType.name] = [];
165
- }
166
- // @ts-ignore
167
- Logger.wrappers[classType.name].push({
168
- classType,
169
- callback
170
- });
171
- }
172
- /**
173
- * Function getCallerName() : Return caller name.
174
- */
175
- static getCallerName() {
176
- const error = new Error(),
177
- caller = error.stack ? error.stack.split("\n")[3].trim() : '_UNKNOWN_CALLER_NAME_';
178
- if (caller.startsWith("at new")) {
179
- return "constructor";
180
- }
181
- return caller.split(".")[1].split(" ")[0];
182
- }
183
- /**
184
- * Function functionView() : Return function preview.
185
- */
186
- static getFunctionView(fn) {
187
- let fReturn = "anonymous function()";
188
- // TODO: Check if works.
189
- if (typeof fn !== "string" && fn.name.length !== 0) {
190
- fReturn = fn.name.split(" ")[1] + "()";
191
- }
192
- return fReturn;
193
- }
673
+ var MAX_WRAPPING_RECURSIVE_DEPTH = 4;
674
+ var Logger = /*#__PURE__*/function () {
194
675
  /**
195
676
  * Function constructor() : Create logger class.
196
677
  */
197
- constructor(owner, isActive = false, args = {}) {
198
- 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'])) {
199
686
  return;
200
687
  }
201
688
  this.state = isActive;
@@ -210,256 +697,476 @@ class Logger {
210
697
  this.initialize();
211
698
  }
212
699
  }
700
+
213
701
  /**
214
702
  * Function initialize() : Initialize logger class.
215
703
  */
216
- initialize() {
217
- // @ts-ignore
218
- if (this.args.sameColor) {
219
- if (!Logger.sharedData[this.name]) {
220
- 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);
221
716
  }
222
- this.color = Logger.sharedData[this.name];
223
- } else {
224
- this.color = this.getRandomColor();
225
- 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"];
226
719
  }
227
- this.outputHandler = console.log;
228
- 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"];
229
- }
230
- /**
231
- * Function setOutputHandler() : Set custom output handler.
232
- */
233
- setOutputHandler(outputHandler) {
234
- this.outputHandler = outputHandler;
235
- }
236
- /**
237
- * Function useWrapper() : Search for customized log view, each instance,
238
- * that typeof the instance was registered wrapper will have unique output
239
- * according to the registered callback.
240
- */
241
- useWrapper(obj, shouldHandleChildren = true) {
242
- if (!obj || 'object' !== typeof obj || Array.isArray(obj)) {
243
- return obj;
244
- }
245
- Logger.wrapperDepth++;
246
- // Result will lose classType (instanceOf will not work), now based on obj.
247
- let result = {
248
- ...obj
249
- };
250
- // @ts-ignore
251
- Object.values(Logger.wrappers).forEach(([wrapper]) => {
252
- if (obj instanceof wrapper.classType) {
253
- 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
+ });
254
767
  }
255
- });
256
- if (Logger.wrapperDepth >= MAX_WRAPPING_RECURSIVE_DEPTH) {
257
768
  Logger.wrapperDepth--;
258
769
  return result;
259
770
  }
260
- if (shouldHandleChildren && result) {
261
- Object.entries(result).forEach(([key, value]) => {
262
- result[key] = this.useWrapper(value, true);
263
- });
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);
264
783
  }
265
- Logger.wrapperDepth--;
266
- return result;
267
- }
268
- /**
269
- * Function startEmpty() : Notify function start without args.
270
- *
271
- * @param {string} output
272
- */
273
- startEmpty(output = "") {
274
- if (!this.state) return;
275
- this.printFunctionNotify("se", Logger.getCallerName(), output);
276
- }
277
- /**
278
- * Function startWith() : Notify function start with args.
279
- *
280
- * TODO: Rename to startsWith
281
- */
282
- startWith(params) {
283
- if (!this.state) return;
284
- params = Object.assign({}, params);
285
- const type = "se";
286
- const source = Logger.getCallerName();
287
- if (typeof params == "string") {
288
- this.printInLineString(type, source, params);
289
- } else if (Object.keys(params).length === 1) {
290
- const key = Object.keys(params)[0];
291
- let value = Object.values(params)[0];
292
- // TODO: Check is repeated logic, handle it.
293
- if (typeof value === "object") {
294
- this.printNextLineObject(type, source, key, value || {});
295
- } else if (typeof value == "function") {
296
- 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
+ }
297
811
  } else {
298
- this.printInLineElement(type, source, key, value);
812
+ this.printMultiLineObject(type, source, params);
299
813
  }
300
- } else {
301
- this.printMultiLineObject(type, source, params);
302
814
  }
303
- }
304
- /**
305
- * Function object() : Prints object.
306
- **/
307
- object(params = {}, notice = "") {
308
- if (!this.state) return;
309
- const source = Logger.getCallerName();
310
- params = Object.create(params);
311
- for (let key in params) {
312
- if (typeof params[key] === "object") {
313
- 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));
314
832
  }
315
- this.out.apply(this, [`%c(ob)-> %c%c${this.name}%c::%c${source}%c() [${notice}] ->> ${key}: '${params[key]}'%c`].concat(this.defaultStyle));
316
833
  }
317
- }
318
- /**
319
- * Function debug() : Notify debug.
320
- */
321
- debug(output) {
322
- if (!this.state) return;
323
- this.printFunctionNotify("db", Logger.getCallerName(), output);
324
- }
325
- /**
326
- * Function drop : Preview as continue of log which drop ite.
327
- */
328
- drop(according, data) {
329
- if (!this.state) return;
330
- const source = Logger.getCallerName();
331
- for (let key in according) {
332
- 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);
333
843
  }
334
- this.out(data);
335
- }
336
- /**
337
- * Function throw() : Throws logged error.
338
- */
339
- throw(output, name = 'null', params = {}) {
340
- this.printFunctionNotify("tw", Logger.getCallerName(), output);
341
- if (params) this.printNextLineObject("tw", Logger.getCallerName(), name, params);
342
- throw new Error().stack;
343
- }
344
- /**
345
- * Function clone() : Create clone instance.
346
- */
347
- clone() {
348
- return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
349
- }
350
- /**
351
- * Function printFunctionNotify() : Print simple log for notify source (function).
352
- *
353
- */
354
- printFunctionNotify(type, source, output) {
355
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ${output}%c`].concat(this.defaultStyle));
356
- }
357
- /**
358
- * Function printInLineElement() : Print in line element.
359
- */
360
- printInLineElement(type, source, key, value) {
361
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ->> ${key}: '${value}'%c`].concat(this.defaultStyle));
362
- }
363
- /**
364
- * Function printInLineFunction() : Print in line function.
365
- */
366
- printInLineFunction(type, source, key, fn) {
367
- fn = Logger.getFunctionView(fn);
368
- this.printInLineElement(type, source, key, fn);
369
- }
370
- /**
371
- * Function printInLineString() : Print in line string.
372
- */
373
- printInLineString(type, source, string) {
374
- this.printInLineElement(type, source, "(string)", string);
375
- }
376
- /**
377
- * Function printNextLineObject() : Print object in next line.
378
- */
379
- printNextLineObject(type, source, key, obj) {
380
- obj = this.useWrapper(obj);
381
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c() ->> ${key} %c↓`].concat(this.defaultStyle));
382
- // print in next line
383
- this.out(obj);
384
- }
385
- /**
386
- * Function printMultiLineObject() : Print object in multiline format.
387
- */
388
- printMultiLineObject(type, source, obj) {
389
- this.out.apply(this, [`%c(${type})-> %c%c${this.name}%c::%c${source}%c(${Object.keys(obj).join(", ")}) %c↓`].concat(this.defaultStyle));
390
- for (let key in obj) {
391
- let value = obj[key];
392
- if (typeof value === "object") {
393
- value = JSON.stringify(this.useWrapper(value), getCircularReplacer());
394
- } else if (typeof obj[key] == "function") {
395
- 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));
855
+ }
856
+ this.out(data);
857
+ }
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;
870
+ }
871
+
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();
396
968
  }
397
- this.out.apply(this, ["%c" + key + ": `" + this.useWrapper(value) + "`", "color: #a3a3a3"]);
969
+ return color;
398
970
  }
399
- }
400
- /**
401
- * Function getRandomColor() : Return random color.
402
- */
403
- getRandomColor() {
404
- const letters = "0123456789ABCDEF";
405
- let color = "#";
406
- for (let i = 0; i < 6; i++) {
407
- color += letters[Math.floor(Math.random() * 16)];
408
- }
409
- let similar = Logger.colorsInUse.some(value => {
410
- // it returns the ratio of difference... closer to 1.0 is less difference.
411
- return hexColorDelta(color, value) >= 0.8;
412
- });
413
- // if the color is similar, try again.
414
- if (similar) {
415
- return this.getRandomColor();
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 = {};
416
999
  }
417
- return color;
418
- }
419
- /**
420
- * Function out() : Print console log with style
421
- */
422
- out(...args) {
423
- this.outputHandler.apply(this, args);
424
- }
425
- }
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", []);
426
1054
 
427
1055
  var index$5 = /*#__PURE__*/Object.freeze({
428
1056
  __proto__: null,
429
1057
  Logger: Logger
430
1058
  });
431
1059
 
432
- class CommandAlreadyRegistered extends Error {
433
- constructor(command) {
434
- super(`Command: '${command.getName()}' is already registered`);
1060
+ function _isNativeFunction(fn) {
1061
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
1062
+ }
1063
+
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
+ };
435
1076
  }
1077
+ return _construct.apply(null, arguments);
1078
+ }
1079
+
1080
+ function _wrapNativeSuper(Class) {
1081
+ var _cache = typeof Map === "function" ? new Map() : undefined;
1082
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
1083
+ if (Class === null || !_isNativeFunction(Class)) return Class;
1084
+ if (typeof Class !== "function") {
1085
+ throw new TypeError("Super expression must either be null or a function");
1086
+ }
1087
+ if (typeof _cache !== "undefined") {
1088
+ if (_cache.has(Class)) return _cache.get(Class);
1089
+ _cache.set(Class, Wrapper);
1090
+ }
1091
+ function Wrapper() {
1092
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
1093
+ }
1094
+ Wrapper.prototype = Object.create(Class.prototype, {
1095
+ constructor: {
1096
+ value: Wrapper,
1097
+ enumerable: false,
1098
+ writable: true,
1099
+ configurable: true
1100
+ }
1101
+ });
1102
+ return _setPrototypeOf(Wrapper, Class);
1103
+ };
1104
+ return _wrapNativeSuper(Class);
436
1105
  }
437
1106
 
438
1107
  /**
439
1108
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
440
1109
  */
441
- class CommandNotFound extends Error {
442
- constructor(command) {
443
- super(`Command: '${command}' is not found`);
444
- }
445
- }
446
1110
 
447
- class ControllerAlreadyRegistered extends Error {
448
- constructor(controller) {
449
- super(`Controller: '${controller.getName()}' is already registered`);
450
- }
451
- }
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));
452
1120
 
453
- class ForceMethodBase extends Error {
454
- constructor(className, methodName) {
455
- super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
456
- }
457
- }
458
- class ForceMethod extends Error {
459
- constructor(context, methodName) {
460
- super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
461
- }
462
- }
1121
+ /**
1122
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1123
+ */
1124
+ var CommandNotFound = /*#__PURE__*/function (_Error) {
1125
+ _inherits(CommandNotFound, _Error);
1126
+ var _super = _createSuper(CommandNotFound);
1127
+ function CommandNotFound(command) {
1128
+ _classCallCheck(this, CommandNotFound);
1129
+ return _super.call(this, "Command: '".concat(command, "' is not found"));
1130
+ }
1131
+ return _createClass(CommandNotFound);
1132
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
1133
+
1134
+ /**
1135
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1136
+ */
1137
+
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));
1147
+
1148
+ /**
1149
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1150
+ */
1151
+
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));
463
1170
 
464
1171
  var index$4 = /*#__PURE__*/Object.freeze({
465
1172
  __proto__: null,
@@ -469,241 +1176,456 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
469
1176
  ForceMethod: ForceMethod
470
1177
  });
471
1178
 
472
- /**
473
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
474
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
475
- */
476
- let IdCounter = 0;
1179
+ var IdCounter = 0;
1180
+
477
1181
  /**
478
1182
  * Base class 4 *
479
1183
  */
480
- class ObjectBase {
481
- virtualId = 0;
482
- static getName() {
483
- throw new ForceMethodBase("ObjectBase", "getName");
484
- }
485
- constructor() {
1184
+ var ObjectBase = /*#__PURE__*/function () {
1185
+ function ObjectBase() {
1186
+ _classCallCheck(this, ObjectBase);
1187
+ _defineProperty(this, "virtualId", 0);
486
1188
  this.virtualId = IdCounter;
487
1189
  APIIncreaseIdCounter();
488
1190
  }
489
- getName() {
490
- return this.constructor.getName();
491
- }
492
- }
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
+ }();
493
1204
  function APIIncreaseIdCounter() {
494
1205
  return IdCounter++;
495
1206
  }
496
1207
 
497
- /**
498
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
499
- * @description: Responsible for manging/running/hooking commands.
500
- */
501
- class Commands extends ObjectBase {
502
- static trace = [];
503
- current = {};
504
- currentArgs = {};
505
- trace = [];
506
- commands = {};
507
- onBeforeHooks = {};
508
- onBeforeUIHooks = {};
509
- onAfterHooks = {};
510
- onAfterOnceHooks = {};
511
- onAfterUIHooks = {};
512
- onAfterAffectHooks = {};
513
- logger;
514
- static getName() {
515
- return 'Core/Managers/Commands';
516
- }
517
- static async runCallbacks(callbacks, args = {}, options = {}) {
518
- const callbacksLength = callbacks?.length || 0;
519
- for (let i = 0; i < callbacksLength; ++i) {
520
- const callback = options.pop === true ? callbacks.pop() : callbacks[i];
521
- if (!callback) {
522
- throw new Error("Callback is not defined.");
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);
523
1260
  }
524
- 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;
525
1278
  }
526
- }
527
- static hookCommand(stack, hookCommand, context) {
528
- if (!stack[hookCommand]) {
529
- stack[hookCommand] = [];
1279
+ }, {
1280
+ key: "getAll",
1281
+ value: function getAll() {
1282
+ return this.commands;
530
1283
  }
531
- stack[hookCommand].push(context);
532
- }
533
- constructor() {
534
- super();
535
- this.logger = new Logger(this.getName(), true);
536
- this.logger.startEmpty();
537
- }
538
- async run(command, args = {}, options = {}) {
539
- if (typeof command === "string") {
540
- command = this.getCommandInstance(command, args, options);
541
- }
542
- this.attachCurrent(command, args);
543
- const result = await this.runInstance(command, args, options);
544
- this.detachCurrent(command);
545
- return result;
546
- }
547
- register(commands, controller) {
548
- const result = {};
549
- Object.values(commands).forEach(command => {
550
- const commandName = command.getName();
551
- if (this.commands[commandName]) {
552
- 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);
553
1302
  }
554
- this.commands[commandName] = command;
555
- result[commandName] = command;
556
- });
557
- return result;
558
- }
559
- getAll() {
560
- return this.commands;
561
- }
562
- getByName(name) {
563
- return this.commands[name];
564
- }
565
- getLogger() {
566
- return this.logger;
567
- }
568
- getCommandInstance(name, args = {}, options = {}) {
569
- const CommandClass = this.commands[name];
570
- if (!CommandClass) {
571
- throw new CommandNotFound(name);
1303
+
1304
+ // @ts-ignore
1305
+ return new CommandClass(args, options);
572
1306
  }
573
- // @ts-ignore
574
- return new CommandClass(args, options);
575
- }
576
- /**
577
- * Function onBefore() : Used to set hooks that effects only data and not UI.
578
- */
579
- onBefore(hookCommand, callback) {
580
- Commands.hookCommand(this.onBeforeHooks, hookCommand, callback);
581
- }
582
- /**
583
- * Function onBeforeUI() : Used to set hooks that effects only UI.
584
- */
585
- onBeforeUI(hookCommand, callback) {
586
- Commands.hookCommand(this.onBeforeUIHooks, hookCommand, callback);
587
- }
588
- /**
589
- * Function onAfter() : Used to set hooks that effects only data and not UI.
590
- */
591
- onAfter(hookCommand, callback) {
592
- Commands.hookCommand(this.onAfterHooks, hookCommand, callback);
593
- }
594
- /**
595
- * Function onAfterUI() : Used to set hooks that effects only UI.
596
- */
597
- onAfterUI(command, callback) {
598
- Commands.hookCommand(this.onAfterUIHooks, command, callback);
599
- }
600
- /**
601
- * Function onAfterOnce() : Used to set hooks that effects only data and not UI.
602
- */
603
- onAfterOnce(command, callback) {
604
- Commands.hookCommand(this.onAfterOnceHooks, command, callback);
605
- }
606
- /**
607
- * Function onAfterAffect() : Used to register a trigger that runs command after `hookCommand` run's.
608
- */
609
- onAfterAffect(hookCommand, affectCommand) {
610
- Commands.hookCommand(this.onAfterAffectHooks, hookCommand, affectCommand);
611
- }
612
- onBeforeRun(command, args = {}, options = {}) {
613
- if (this.onBeforeHooks[command.getName()]) {
614
- const callbacks = this.onBeforeHooks[command.getName()];
615
- 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);
616
1315
  }
617
- if (this.onBeforeUIHooks[command.getName()]) {
618
- const callbacks = this.onBeforeUIHooks[command.getName()];
619
- 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);
620
1324
  }
621
- }
622
- async runInstance(command, args = {}, options = {}) {
623
- let result = null;
624
- // TODO: Maybe a logger method to handle such cases.
625
- if (Object.keys(args).length) {
626
- this.logger.startWith({
627
- command: command.getName(),
628
- options,
629
- CommandArgs: "->"
630
- });
631
- this.logger.debug("CommandArgs:");
632
- this.logger.object(args);
633
- } else {
634
- this.logger.startWith({
635
- command: command.getName(),
636
- options,
637
- args
638
- });
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);
639
1333
  }
640
- this.onBeforeRun(command, args, options);
641
- result = await command.run();
642
- await this.onAfterRun(command, args, options, result);
643
- return result;
644
- }
645
- async onAfterRun(command, args, options, result) {
646
- options = Object.assign({}, options);
647
- if (this.onAfterAffectHooks[command.getName()]) {
648
- this.onAfterAffectHooks[command.getName()].forEach(command => {
649
- args.result = result;
650
- result = this.run(command.toString(), args, options);
651
- });
652
- 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);
653
1342
  }
654
- if (this.onAfterHooks) {
655
- args.result = result;
656
- await Commands.runCallbacks(Object.assign([], this.onAfterHooks[command.getName()]), args, options);
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);
657
1351
  }
658
- if (this.onAfterOnceHooks) {
659
- await Commands.runCallbacks(this.onAfterOnceHooks[command.getName()], args, {
660
- ...options,
661
- pop: true // Delete after run.
662
- });
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);
1360
+ }
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';
663
1503
  }
1504
+ }, {
1505
+ key: "runCallbacks",
1506
+ value: function () {
1507
+ var _runCallbacks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(callbacks) {
1508
+ var args,
1509
+ options,
1510
+ callbacksLength,
1511
+ i,
1512
+ callback,
1513
+ _args4 = arguments;
1514
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1515
+ while (1) switch (_context4.prev = _context4.next) {
1516
+ case 0:
1517
+ args = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
1518
+ options = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
1519
+ callbacksLength = (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length) || 0;
1520
+ i = 0;
1521
+ case 4:
1522
+ if (!(i < callbacksLength)) {
1523
+ _context4.next = 13;
1524
+ break;
1525
+ }
1526
+ callback = options.pop === true ? callbacks.pop() : callbacks[i];
1527
+ if (callback) {
1528
+ _context4.next = 8;
1529
+ break;
1530
+ }
1531
+ throw new Error("Callback is not defined.");
1532
+ case 8:
1533
+ _context4.next = 10;
1534
+ return callback(args, options);
1535
+ case 10:
1536
+ ++i;
1537
+ _context4.next = 4;
1538
+ break;
1539
+ case 13:
1540
+ case "end":
1541
+ return _context4.stop();
1542
+ }
1543
+ }, _callee4);
1544
+ }));
1545
+ function runCallbacks(_x7) {
1546
+ return _runCallbacks.apply(this, arguments);
1547
+ }
1548
+ return runCallbacks;
1549
+ }()
1550
+ }, {
1551
+ key: "hookCommand",
1552
+ value: function hookCommand(stack, _hookCommand, context) {
1553
+ if (!stack[_hookCommand]) {
1554
+ stack[_hookCommand] = [];
1555
+ }
1556
+ stack[_hookCommand].push(context);
1557
+ }
1558
+ }]);
1559
+ return Commands;
1560
+ }(ObjectBase);
1561
+ _defineProperty(Commands, "trace", []);
664
1562
 
665
- if (this.onAfterUIHooks) {
666
- 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];
667
1571
  }
668
- return result;
669
- }
670
- attachCurrent(command, args = {}) {
671
- this.current[command.getName()] = command;
672
- this.currentArgs[command.getName()] = args;
673
- this.trace.push(command.getName());
674
- Commands.trace.push(command.getName());
675
- }
676
- detachCurrent(command) {
677
- delete this.current[command.getName()];
678
- delete this.currentArgs[command.getName()];
679
- Commands.trace.pop();
680
- 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;
681
1610
  }
1611
+ return object;
682
1612
  }
683
1613
 
684
- /**
685
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
686
- * @description: Responsible for manging controllers, each controller is global singleton instance.
687
- */
688
- class Controllers extends ObjectBase {
689
- controllers = {};
690
- static getName() {
691
- return 'Core/Managers/Controllers';
692
- }
693
- get(name) {
694
- return this.controllers[name];
695
- }
696
- getAll() {
697
- return this.controllers;
698
- }
699
- register(controller) {
700
- if (this.controllers[controller.getName()]) {
701
- throw new ControllerAlreadyRegistered(controller);
702
- }
703
- // Register.
704
- this.controllers[controller.getName()] = controller;
705
- 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
+ };
706
1627
  }
1628
+ return _get.apply(this, arguments);
707
1629
  }
708
1630
 
709
1631
  /**
@@ -720,146 +1642,241 @@ var HTTPMethodEnum;
720
1642
  HTTPMethodEnum["__EMPTY__"] = "";
721
1643
  })(HTTPMethodEnum || (HTTPMethodEnum = {}));
722
1644
 
723
- /**
724
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
725
- * @description: Providing a simple wrapper for fetch API.
726
- */
727
- class Http extends ObjectBase {
728
- logger;
729
- apiBaseUrl;
730
- static getName() {
731
- return 'Core/Clients/Http';
732
- }
1645
+ var Http = /*#__PURE__*/function (_ObjectBase) {
1646
+ _inherits(Http, _ObjectBase);
1647
+ var _super = _createSuper(Http);
733
1648
  /**
734
1649
  * Function constructor() : Create the http.
735
1650
  */
736
- constructor(apiBaseUrl = 'http://localhost') {
737
- super();
738
- this.logger = new Logger(Http.getName(), true);
739
- this.logger.startWith({
740
- 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
741
1659
  });
742
- this.apiBaseUrl = apiBaseUrl + '/';
1660
+ _this.apiBaseUrl = apiBaseUrl + '/';
1661
+ return _this;
743
1662
  }
1663
+
744
1664
  /**
745
1665
  * Function fetch() : Fetch api.
746
1666
  */
747
- async fetch(path, method, body = null) {
748
- this.logger.startWith({
749
- path,
750
- method,
751
- body
752
- });
753
- const params = {
754
- 'credentials': 'include'
755
- },
756
- // Support cookies.
757
- headers = {};
758
- if ([HTTPMethodEnum.POST, HTTPMethodEnum.PUT, HTTPMethodEnum.PATCH].includes(method)) {
759
- Object.assign(headers, {
760
- 'Content-Type': 'application/json'
761
- });
762
- Object.assign(params, {
763
- method,
764
- headers: headers,
765
- body: JSON.stringify(body)
766
- });
767
- } else {
768
- Object.assign(params, {
769
- headers
770
- });
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';
771
1747
  }
772
- const response = await globalThis.fetch(this.apiBaseUrl + path, params);
773
- let data = undefined;
774
- try {
775
- data = await response.json();
776
- } catch (e) {
777
- console.error(e);
778
- return false;
779
- }
780
- // TODO: This is part should be modular and not hard coded.
781
- if (data?.error && data?.global && data?.message) {
782
- throw new Error(data.message);
783
- }
784
- this.logger.drop({
785
- path
786
- }, data);
787
- return data;
788
- }
789
- }
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);
790
1759
 
791
- /**
792
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
793
- * @description: Responsible for manging data commands which are wrappers for HTTP requests.
794
- */
795
- class Data extends Commands {
796
- static client;
797
- currentHttpMethod;
798
- static getName() {
799
- return 'Core/Managers/Data';
800
- }
801
- constructor(Config) {
802
- super();
803
1760
  // @ts-ignore
804
1761
  Data.client = new Http(Config.baseURL);
1762
+ return _this;
805
1763
  }
806
- getClient() {
807
- return Data.client;
808
- }
809
- get(command, args = {}, options = {}) {
810
- this.currentHttpMethod = HTTPMethodEnum.GET;
811
- return super.run(command, args, options);
812
- }
813
- update(command, args = {}, options = {}) {
814
- this.currentHttpMethod = HTTPMethodEnum.PATCH;
815
- return super.run(command, args, options);
816
- }
817
- delete(command, args = {}, options = {}) {
818
- this.currentHttpMethod = HTTPMethodEnum.DELETE;
819
- return super.run(command, args, options);
820
- }
821
- create(command, args = {}, options = {}) {
822
- this.currentHttpMethod = HTTPMethodEnum.POST;
823
- return super.run(command, args, options);
824
- }
825
- async runInstance(command, args = {}, options = {}) {
826
- if (!this.currentHttpMethod) {
827
- throw new Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');
828
- }
829
- // New args.
830
- const newArgs = {
831
- type: this.currentHttpMethod,
832
- args: {
833
- query: {},
834
- 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);
835
1848
  }
836
- };
837
- if (HTTPMethodEnum.GET === this.currentHttpMethod) {
838
- newArgs.args.query = args;
839
- } else {
840
- newArgs.args.data = args;
1849
+ return runInstance;
1850
+ }()
1851
+ }], [{
1852
+ key: "getName",
1853
+ value: function getName() {
1854
+ return 'Core/Managers/Data';
841
1855
  }
842
- args.result = await super.runInstance(command, newArgs, options);
843
- // Clear method type.
844
- this.currentHttpMethod = HTTPMethodEnum.__EMPTY__;
845
- return args.result;
846
- }
847
- }
1856
+ }]);
1857
+ return Data;
1858
+ }(Commands);
848
1859
 
849
- /**
850
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
851
- * @description: Responsible for manging internal commands, To serve commands that are not triggered by user.
852
- */
853
- class Internal extends Commands {
854
- static getName() {
855
- return 'Core/Managers/Internal';
856
- }
857
- }
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);
858
1875
 
859
1876
  /**
860
1877
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
861
1878
  */
862
- const afterInitializeCallbacks = [];
1879
+ var afterInitializeCallbacks = [];
863
1880
  function initialize(config) {
864
1881
  commands = new Commands();
865
1882
  controllers = new Controllers();
@@ -876,15 +1893,6 @@ var commands = {};
876
1893
  var controllers = {};
877
1894
  var data = {};
878
1895
  var internal = {};
879
- /*
880
- __ZEN_MANAGERS__.initialize = initialize;
881
- __ZEN_MANAGERS__.destroy = destroy;
882
-
883
- export var commands = __ZEN_MANAGERS__.commands;
884
- export var controllers = __ZEN_MANAGERS__.controllers;
885
- export var data = __ZEN_MANAGERS__.data;
886
- export var internal = __ZEN_MANAGERS__.internal;
887
- */
888
1896
 
889
1897
  var index$3 = /*#__PURE__*/Object.freeze({
890
1898
  __proto__: null,
@@ -897,107 +1905,169 @@ initialize: initialize,
897
1905
  get internal () { return internal; }
898
1906
  });
899
1907
 
900
- /**
901
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
902
- * @description: Base for all commands, they are all will be managed by the `Commands` managers.
903
- * @TODO
904
- * - Add validateArgs method or find something better.
905
- */
906
- class CommandBase extends ObjectBase {
907
- args = {};
908
- options = {};
909
- logger;
910
- constructor(args = {}, options = {}) {
911
- super();
912
- const name = this.constructor.getName();
913
- this.logger = new Logger(name, true, {
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, {
914
1921
  sameColor: true
915
1922
  });
916
- this.logger.startWith({
917
- args,
918
- options
1923
+ _this.logger.startWith({
1924
+ args: args,
1925
+ options: options
919
1926
  });
920
- this.initialize(args, options);
921
- }
922
- initialize(args, options) {
923
- this.args = args;
924
- this.options = options;
925
- }
926
- apply(args = this.args, options = this.options) {
927
- throw new ForceMethod(this, "apply");
928
- }
929
- async run() {
930
- this.onBeforeApply && this.onBeforeApply();
931
- const result = await this.apply(this.args, this.options);
932
- this.onAfterApply && this.onAfterApply();
933
- return result;
934
- }
935
- getArgs() {
936
- return this.args;
937
- }
938
- getOptions() {
939
- return this.options;
940
- }
941
- }
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);
942
1983
 
943
- /**
944
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
945
- * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
946
- * */
947
- class CommandPublic extends CommandBase {
948
- static getName() {
949
- return 'Core/CommandBases/CommandPublic';
950
- }
951
- }
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);
952
1999
 
953
- /**
954
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
955
- * @description: Each data command should represent a final REST endpoint.
956
- */
957
- class CommandData extends CommandBase {
958
- static getName() {
959
- return 'Core/CommandBases/CommandData';
960
- }
961
- /**
962
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
963
- * @example
964
- * ```
965
- * args = { query: { id: 1 } };
966
- * getEndpoint() = '/api/v1/users/{id}';
967
- * result = '/api/v1/users/1';
968
- * ```
969
- */
970
- getEndpoint() {
971
- throw new ForceMethod(this, 'getEndpoint');
972
- }
973
- apply(args = this.args, options = this.options) {
974
- const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
975
- return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
976
- }
977
- applyEndpointFormat(endpoint, data = {}) {
978
- // Replace query with `magic` placeholders.
979
- if (endpoint.includes('{')) {
980
- endpoint = endpoint.split('/').map(endpointPart => {
981
- const match = endpointPart.match('\\{(.*?)\\}');
982
- if (match?.length && 'undefined' !== typeof data[match[1]]) {
983
- return data[match[1]];
984
- }
985
- return endpointPart;
986
- }).join('/');
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');
987
2021
  }
988
- return endpoint;
989
- }
990
- }
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);
991
2055
 
992
- /**
993
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
994
- * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
995
- */
996
- class CommandInternal extends CommandBase {
997
- static getName() {
998
- return 'Core/CommandBases/CommandInternal';
999
- }
1000
- }
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);
1001
2071
 
1002
2072
  /**
1003
2073
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
@@ -1011,40 +2081,56 @@ CommandInternal: CommandInternal,
1011
2081
  CommandPublic: CommandPublic
1012
2082
  });
1013
2083
 
1014
- /**
1015
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1016
- * @description: Responsible for commands, Aka ( CommandsSpace ).
1017
- */
1018
- class Controller extends ObjectBase {
1019
- commands;
1020
- data;
1021
- internal;
1022
- static getName() {
1023
- return 'Core/Core/Controller';
1024
- }
1025
- constructor() {
1026
- super();
1027
- this.initialize();
1028
- }
1029
- initialize() {
1030
- this.register();
1031
- this.setupHooks && this.setupHooks();
1032
- }
1033
- register() {
1034
- this.commands = commands.register(this.getCommands(), this);
1035
- this.data = data.register(this.getData(), this);
1036
- this.internal = internal.register(this.getInternal(), this);
1037
- }
1038
- getCommands() {
1039
- return {};
1040
- }
1041
- getData() {
1042
- return {};
1043
- }
1044
- getInternal() {
1045
- return {};
1046
- }
1047
- }
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);
1048
2134
 
1049
2135
  var index$1 = /*#__PURE__*/Object.freeze({
1050
2136
  __proto__: null,
@@ -1079,34 +2165,34 @@ modules: index$5,
1079
2165
  utils: index$6
1080
2166
  });
1081
2167
 
1082
- let isInitialized = false;
2168
+ var isInitialized = false;
1083
2169
  function errorInitTwice() {
1084
2170
  if (isInitialized) {
1085
2171
  throw new Error('ZenCore is already initialized.');
1086
2172
  }
1087
2173
  }
1088
2174
  errorInitTwice();
1089
- let config = {
2175
+ var config = {
1090
2176
  version: pkg.version
1091
2177
  };
1092
- const CoreAPI = {
1093
- initialize: configuration => {
2178
+ var CoreAPI = _objectSpread2({
2179
+ initialize: function initialize$1(configuration) {
1094
2180
  errorInitTwice();
1095
2181
  config = configuration || config;
1096
2182
  initialize(config);
1097
2183
  isInitialized = true;
1098
2184
  },
1099
- destroy: () => {
2185
+ destroy: function destroy$1() {
1100
2186
  destroy();
1101
2187
  isInitialized = false;
1102
2188
  },
1103
- onAfterInitialize: callback => {
2189
+ onAfterInitialize: function onAfterInitialize(callback) {
1104
2190
  afterInitializeCallbacks.push(callback);
1105
2191
  },
1106
- config,
1107
- ...exported
1108
- };
2192
+ config: config
2193
+ }, exported);
2194
+
1109
2195
  // TODO: Make it available only for development.
1110
- if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
2196
+ if (!(globalThis !== null && globalThis !== void 0 && globalThis.ZenCore)) globalThis.ZenCore = CoreAPI;
1111
2197
 
1112
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 };