@leyyo/common 1.2.6 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +395 -3
- package/dist/class/index.d.ts +2 -0
- package/dist/{opt → class}/index.js +2 -1
- package/dist/class/index.js.map +1 -0
- package/dist/class/list.d.ts +13 -0
- package/dist/class/list.js +37 -0
- package/dist/class/list.js.map +1 -0
- package/dist/{log → class}/logger.instance.d.ts +10 -12
- package/dist/class/logger.instance.js +150 -0
- package/dist/class/logger.instance.js.map +1 -0
- package/dist/common/array.fn.d.ts +46 -0
- package/dist/common/array.fn.js +123 -0
- package/dist/common/array.fn.js.map +1 -0
- package/dist/common/deploy.fn.d.ts +18 -0
- package/dist/common/deploy.fn.js +73 -0
- package/dist/common/deploy.fn.js.map +1 -0
- package/dist/common/enum.fn.d.ts +63 -0
- package/dist/common/enum.fn.js +191 -0
- package/dist/common/enum.fn.js.map +1 -0
- package/dist/common/error.fn.d.ts +91 -0
- package/dist/common/error.fn.js +400 -0
- package/dist/common/error.fn.js.map +1 -0
- package/dist/common/event.fn.d.ts +45 -0
- package/dist/common/event.fn.js +160 -0
- package/dist/common/event.fn.js.map +1 -0
- package/dist/common/exporter.fn.d.ts +7 -0
- package/dist/common/exporter.fn.js +49 -0
- package/dist/common/exporter.fn.js.map +1 -0
- package/dist/common/fqn.fn.d.ts +27 -0
- package/dist/common/fqn.fn.js +104 -0
- package/dist/common/fqn.fn.js.map +1 -0
- package/dist/common/index.d.ts +14 -0
- package/dist/{hub → common}/index.js +14 -1
- package/dist/common/index.js.map +1 -0
- package/dist/common/lifecycle.fn.d.ts +24 -0
- package/dist/common/lifecycle.fn.js +135 -0
- package/dist/common/lifecycle.fn.js.map +1 -0
- package/dist/common/list.fn.d.ts +47 -0
- package/dist/common/list.fn.js +122 -0
- package/dist/common/list.fn.js.map +1 -0
- package/dist/common/loader.fn.d.ts +15 -0
- package/dist/common/loader.fn.js +38 -0
- package/dist/common/loader.fn.js.map +1 -0
- package/dist/common/log.fn.d.ts +21 -0
- package/dist/common/log.fn.js +321 -0
- package/dist/common/log.fn.js.map +1 -0
- package/dist/common/map.fn.d.ts +46 -0
- package/dist/common/map.fn.js +123 -0
- package/dist/common/map.fn.js.map +1 -0
- package/dist/common/opt.fn.d.ts +48 -0
- package/dist/common/opt.fn.js +137 -0
- package/dist/common/opt.fn.js.map +1 -0
- package/dist/common/set.fn.d.ts +46 -0
- package/dist/common/set.fn.js +123 -0
- package/dist/common/set.fn.js.map +1 -0
- package/dist/common/test.fn.d.ts +26 -0
- package/dist/common/test.fn.js +81 -0
- package/dist/common/test.fn.js.map +1 -0
- package/dist/const/index.d.ts +23 -0
- package/dist/const/index.js +28 -0
- package/dist/const/index.js.map +1 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/{deploy → enum}/index.js +1 -1
- package/dist/enum/index.js.map +1 -0
- package/dist/{log → enum}/log-level.js +2 -2
- package/dist/enum/log-level.js.map +1 -0
- package/dist/error/caused.error.d.ts +15 -0
- package/dist/error/caused.error.js +24 -0
- package/dist/error/caused.error.js.map +1 -0
- package/dist/error/developer.error.d.ts +24 -0
- package/dist/error/developer.error.js +69 -0
- package/dist/error/developer.error.js.map +1 -0
- package/dist/error/{items/http.error.d.ts → http.error.d.ts} +1 -1
- package/dist/error/http.error.js +31 -0
- package/dist/error/http.error.js.map +1 -0
- package/dist/error/index.d.ts +6 -3
- package/dist/error/index.js +6 -3
- package/dist/error/index.js.map +1 -1
- package/dist/error/{items/invalid-value.error.js → invalid-value.error.js} +6 -2
- package/dist/error/invalid-value.error.js.map +1 -0
- package/dist/error/leyyo.error.d.ts +87 -0
- package/dist/error/leyyo.error.js +259 -0
- package/dist/error/leyyo.error.js.map +1 -0
- package/dist/error/{items/multiple.error.d.ts → multiple.error.d.ts} +1 -1
- package/dist/error/{items/multiple.error.js → multiple.error.js} +5 -4
- package/dist/error/multiple.error.js.map +1 -0
- package/dist/{util → function}/delay.js +1 -0
- package/dist/function/delay.js.map +1 -0
- package/dist/function/empty.fn.d.ts +8 -0
- package/dist/{util → function}/empty.fn.js +3 -2
- package/dist/function/empty.fn.js.map +1 -0
- package/dist/function/error-obj.d.ts +8 -0
- package/dist/function/error-obj.js +25 -0
- package/dist/function/error-obj.js.map +1 -0
- package/dist/function/error-text.d.ts +7 -0
- package/dist/function/error-text.js +18 -0
- package/dist/function/error-text.js.map +1 -0
- package/dist/function/extended-type.d.ts +8 -0
- package/dist/function/extended-type.js +56 -0
- package/dist/function/extended-type.js.map +1 -0
- package/dist/{util → function}/index.d.ts +4 -4
- package/dist/{util → function}/index.js +4 -4
- package/dist/function/index.js.map +1 -0
- package/dist/{util → function}/is.d.ts +12 -13
- package/dist/function/is.js +89 -0
- package/dist/function/is.js.map +1 -0
- package/dist/{util → function}/jitter-interval.js +1 -0
- package/dist/function/jitter-interval.js.map +1 -0
- package/dist/{util → function}/one-or-more.d.ts +1 -1
- package/dist/{util → function}/one-or-more.js +1 -0
- package/dist/function/one-or-more.js.map +1 -0
- package/dist/{util → function}/secure-clone.d.ts +1 -1
- package/dist/function/secure-clone.js.map +1 -0
- package/dist/function/secure-json.js.map +1 -0
- package/dist/index.d.ts +7 -19
- package/dist/index.js +7 -21
- package/dist/index.js.map +1 -1
- package/dist/index.types.d.ts +510 -0
- package/dist/{shared/index.types.js → index.types.js} +1 -1
- package/dist/index.types.js.map +1 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +98 -0
- package/dist/loader.js.map +1 -0
- package/package.json +5 -3
- package/dist/$$leyyo-loader.d.ts +0 -1
- package/dist/$$leyyo-loader.js +0 -40
- package/dist/$$leyyo-loader.js.map +0 -1
- package/dist/deploy/deploy.common.d.ts +0 -34
- package/dist/deploy/deploy.common.js +0 -125
- package/dist/deploy/deploy.common.js.map +0 -1
- package/dist/deploy/index.d.ts +0 -1
- package/dist/deploy/index.js.map +0 -1
- package/dist/deploy/index.types.d.ts +0 -29
- package/dist/deploy/index.types.js +0 -3
- package/dist/deploy/index.types.js.map +0 -1
- package/dist/error/error.common.d.ts +0 -34
- package/dist/error/error.common.js +0 -220
- package/dist/error/error.common.js.map +0 -1
- package/dist/error/index.const.d.ts +0 -4
- package/dist/error/index.const.js +0 -8
- package/dist/error/index.const.js.map +0 -1
- package/dist/error/index.types.d.ts +0 -109
- package/dist/error/index.types.js +0 -3
- package/dist/error/index.types.js.map +0 -1
- package/dist/error/items/caused.error.d.ts +0 -6
- package/dist/error/items/caused.error.js +0 -11
- package/dist/error/items/caused.error.js.map +0 -1
- package/dist/error/items/developer.error.d.ts +0 -4
- package/dist/error/items/developer.error.js +0 -11
- package/dist/error/items/developer.error.js.map +0 -1
- package/dist/error/items/http.error.js +0 -37
- package/dist/error/items/http.error.js.map +0 -1
- package/dist/error/items/index.d.ts +0 -6
- package/dist/error/items/index.js +0 -23
- package/dist/error/items/index.js.map +0 -1
- package/dist/error/items/invalid-value.error.js.map +0 -1
- package/dist/error/items/leyyo.error.d.ts +0 -60
- package/dist/error/items/leyyo.error.js +0 -144
- package/dist/error/items/leyyo.error.js.map +0 -1
- package/dist/error/items/multiple.error.js.map +0 -1
- package/dist/event/event.common.d.ts +0 -80
- package/dist/event/event.common.js +0 -308
- package/dist/event/event.common.js.map +0 -1
- package/dist/event/event.error.d.ts +0 -3
- package/dist/event/event.error.js +0 -9
- package/dist/event/event.error.js.map +0 -1
- package/dist/event/index.d.ts +0 -2
- package/dist/event/index.js +0 -19
- package/dist/event/index.js.map +0 -1
- package/dist/event/index.types.d.ts +0 -265
- package/dist/event/index.types.js +0 -3
- package/dist/event/index.types.js.map +0 -1
- package/dist/hub/hub.channel.d.ts +0 -27
- package/dist/hub/hub.channel.js +0 -83
- package/dist/hub/hub.channel.js.map +0 -1
- package/dist/hub/hub.common.d.ts +0 -27
- package/dist/hub/hub.common.js +0 -92
- package/dist/hub/hub.common.js.map +0 -1
- package/dist/hub/index.d.ts +0 -1
- package/dist/hub/index.js.map +0 -1
- package/dist/hub/index.types.d.ts +0 -105
- package/dist/hub/index.types.js +0 -3
- package/dist/hub/index.types.js.map +0 -1
- package/dist/leyyo/index.d.ts +0 -1
- package/dist/leyyo/index.js +0 -18
- package/dist/leyyo/index.js.map +0 -1
- package/dist/leyyo/index.types.d.ts +0 -21
- package/dist/leyyo/index.types.js +0 -3
- package/dist/leyyo/index.types.js.map +0 -1
- package/dist/leyyo/leyyo.d.ts +0 -25
- package/dist/leyyo/leyyo.js +0 -62
- package/dist/leyyo/leyyo.js.map +0 -1
- package/dist/log/index.d.ts +0 -4
- package/dist/log/index.js +0 -21
- package/dist/log/index.js.map +0 -1
- package/dist/log/index.types.d.ts +0 -47
- package/dist/log/index.types.js +0 -3
- package/dist/log/index.types.js.map +0 -1
- package/dist/log/log-level.js.map +0 -1
- package/dist/log/log.common.d.ts +0 -15
- package/dist/log/log.common.js +0 -135
- package/dist/log/log.common.js.map +0 -1
- package/dist/log/logger.error.d.ts +0 -3
- package/dist/log/logger.error.js +0 -9
- package/dist/log/logger.error.js.map +0 -1
- package/dist/log/logger.instance.js +0 -139
- package/dist/log/logger.instance.js.map +0 -1
- package/dist/name/index.d.ts +0 -2
- package/dist/name/index.js +0 -19
- package/dist/name/index.js.map +0 -1
- package/dist/name/index.types.d.ts +0 -21
- package/dist/name/index.types.js +0 -3
- package/dist/name/index.types.js.map +0 -1
- package/dist/name/name.common.d.ts +0 -16
- package/dist/name/name.common.js +0 -109
- package/dist/name/name.common.js.map +0 -1
- package/dist/name/name.error.d.ts +0 -3
- package/dist/name/name.error.js +0 -9
- package/dist/name/name.error.js.map +0 -1
- package/dist/opt/index.d.ts +0 -1
- package/dist/opt/index.js.map +0 -1
- package/dist/opt/index.types.d.ts +0 -33
- package/dist/opt/index.types.js +0 -3
- package/dist/opt/index.types.js.map +0 -1
- package/dist/opt/opt.common.d.ts +0 -15
- package/dist/opt/opt.common.js +0 -93
- package/dist/opt/opt.common.js.map +0 -1
- package/dist/repo/index.d.ts +0 -1
- package/dist/repo/index.js +0 -18
- package/dist/repo/index.js.map +0 -1
- package/dist/repo/index.types.d.ts +0 -104
- package/dist/repo/index.types.js +0 -3
- package/dist/repo/index.types.js.map +0 -1
- package/dist/repo/repo.common.d.ts +0 -41
- package/dist/repo/repo.common.js +0 -146
- package/dist/repo/repo.common.js.map +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -5
- package/dist/server.js.map +0 -1
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.enum.d.ts +0 -7
- package/dist/shared/index.enum.js +0 -3
- package/dist/shared/index.enum.js.map +0 -1
- package/dist/shared/index.fqn.d.ts +0 -3
- package/dist/shared/index.fqn.js +0 -3
- package/dist/shared/index.fqn.js.map +0 -1
- package/dist/shared/index.js +0 -22
- package/dist/shared/index.js.map +0 -1
- package/dist/shared/index.json.d.ts +0 -33
- package/dist/shared/index.json.js +0 -3
- package/dist/shared/index.json.js.map +0 -1
- package/dist/shared/index.loader.d.ts +0 -5
- package/dist/shared/index.loader.js +0 -3
- package/dist/shared/index.loader.js.map +0 -1
- package/dist/shared/index.types.d.ts +0 -168
- package/dist/shared/index.types.js.map +0 -1
- package/dist/util/$define-error.d.ts +0 -9
- package/dist/util/$define-error.js +0 -25
- package/dist/util/$define-error.js.map +0 -1
- package/dist/util/$enum-name.d.ts +0 -16
- package/dist/util/$enum-name.js +0 -18
- package/dist/util/$enum-name.js.map +0 -1
- package/dist/util/$loader.d.ts +0 -18
- package/dist/util/$loader.js +0 -40
- package/dist/util/$loader.js.map +0 -1
- package/dist/util/delay.js.map +0 -1
- package/dist/util/empty.fn.d.ts +0 -8
- package/dist/util/empty.fn.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/is.js +0 -68
- package/dist/util/is.js.map +0 -1
- package/dist/util/jitter-interval.js.map +0 -1
- package/dist/util/one-or-more.js.map +0 -1
- package/dist/util/secure-clone.js.map +0 -1
- package/dist/util/secure-json.js.map +0 -1
- /package/dist/{log → enum}/log-level.d.ts +0 -0
- /package/dist/error/{items/invalid-value.error.d.ts → invalid-value.error.d.ts} +0 -0
- /package/dist/{util → function}/delay.d.ts +0 -0
- /package/dist/{util → function}/jitter-interval.d.ts +0 -0
- /package/dist/{util → function}/secure-clone.js +0 -0
- /package/dist/{util → function}/secure-json.d.ts +0 -0
- /package/dist/{util → function}/secure-json.js +0 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.defineError = defineError;
|
|
47
|
+
exports.defineLazyError = defineLazyError;
|
|
48
|
+
exports.isErrorLazy = isErrorLazy;
|
|
49
|
+
exports.isErrorEager = isErrorEager;
|
|
50
|
+
exports.isErrorDefined = isErrorDefined;
|
|
51
|
+
exports.getError = getError;
|
|
52
|
+
exports.getLazyError = getLazyError;
|
|
53
|
+
exports.emitError = emitError;
|
|
54
|
+
exports.errorStack = errorStack;
|
|
55
|
+
exports.toErrorJsonBasic = toErrorJsonBasic;
|
|
56
|
+
exports.toErrorJsonFull = toErrorJsonFull;
|
|
57
|
+
exports.errorCast = errorCast;
|
|
58
|
+
const function_1 = require("../function");
|
|
59
|
+
const const_1 = require("../const");
|
|
60
|
+
const internal_1 = require("../internal");
|
|
61
|
+
const event_fn_1 = require("./event.fn");
|
|
62
|
+
const error_1 = require("../error");
|
|
63
|
+
const set_fn_1 = require("./set.fn");
|
|
64
|
+
const map_fn_1 = require("./map.fn");
|
|
65
|
+
const stackTraceParser = __importStar(require("stacktrace-parser"));
|
|
66
|
+
// region properties
|
|
67
|
+
const where = `${internal_1.FQN}.ErrorFn`;
|
|
68
|
+
const _items = (0, set_fn_1.newRepoSet)(`${where}.items`);
|
|
69
|
+
const _names = (0, map_fn_1.newRepoMap)(`${where}.names`);
|
|
70
|
+
const _knownPackages = (0, map_fn_1.newRepoMap)(`${where}.knownPackages`);
|
|
71
|
+
// endregion properties
|
|
72
|
+
// noinspection JSUnusedGlobalSymbols
|
|
73
|
+
/**
|
|
74
|
+
* Define an error
|
|
75
|
+
*
|
|
76
|
+
* @param {ClassLike} clazz - error class
|
|
77
|
+
* @param {ErrorDefineEagerOpt} options - options
|
|
78
|
+
* */
|
|
79
|
+
function defineError(clazz, options) {
|
|
80
|
+
if (!(0, function_1.isClass)(clazz)) {
|
|
81
|
+
throw new error_1.DeveloperError('Invalid error class', 'defineError#01', where);
|
|
82
|
+
}
|
|
83
|
+
if (!(0, function_1.isFilledObj)(options)) {
|
|
84
|
+
throw new error_1.DeveloperError('Invalid error options', 'defineError#02', where);
|
|
85
|
+
}
|
|
86
|
+
_items.add(clazz);
|
|
87
|
+
_names.set(clazz.name, Object.assign(Object.assign({}, options), { name: clazz.name, mode: 'eager', clazz }));
|
|
88
|
+
if ((0, function_1.isText)(options.message)) {
|
|
89
|
+
clazz[const_1.LY_ERROR_DEFAULT_MESSAGE] = options.message;
|
|
90
|
+
}
|
|
91
|
+
if (!(0, function_1.isEmpty)(options.emit)) {
|
|
92
|
+
clazz[const_1.LY_ERROR_EMIT] = options.emit;
|
|
93
|
+
}
|
|
94
|
+
if (!(0, function_1.isEmpty)(options.i18n)) {
|
|
95
|
+
clazz[const_1.LY_ERROR_DECORATE_I18N] = options.i18n;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check conflict case
|
|
100
|
+
*
|
|
101
|
+
* @param {string} name - error name
|
|
102
|
+
* @param {EnumData} clazz - error class
|
|
103
|
+
* @return {boolean} - if yes: it was already defined
|
|
104
|
+
* */
|
|
105
|
+
function isAlreadyDefined(name, clazz) {
|
|
106
|
+
return _items.has(clazz) && _names.has(name);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Define an error as lazy (with path)
|
|
110
|
+
*
|
|
111
|
+
* @param {ErrorDefineLazyOpt} opt - error options
|
|
112
|
+
* */
|
|
113
|
+
function defineLazyError(opt) {
|
|
114
|
+
if (!(0, function_1.isFilledObj)(opt)) {
|
|
115
|
+
throw new error_1.DeveloperError('Invalid error options', 'onDeployed#01', where);
|
|
116
|
+
}
|
|
117
|
+
if (!(opt.lazyClass instanceof Promise)) {
|
|
118
|
+
throw new error_1.DeveloperError('Invalid error class path', 'onDeployed#01', where);
|
|
119
|
+
}
|
|
120
|
+
_names.set(opt.name, Object.assign(Object.assign({}, opt), { mode: 'lazy' }));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check error defined as lazy, by name
|
|
124
|
+
* Note:
|
|
125
|
+
* - Error's mode will be shifted lazy to eager after loaded
|
|
126
|
+
*
|
|
127
|
+
* @param {string} name - error name
|
|
128
|
+
* @return {boolean}
|
|
129
|
+
* */
|
|
130
|
+
function isErrorLazy(name) {
|
|
131
|
+
var _a;
|
|
132
|
+
return ((_a = getError(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'lazy';
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check error defined as eager, by name
|
|
136
|
+
*
|
|
137
|
+
* @param {string} name - error name
|
|
138
|
+
* @return {boolean}
|
|
139
|
+
* */
|
|
140
|
+
function isErrorEager(name) {
|
|
141
|
+
var _a;
|
|
142
|
+
return ((_a = getError(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'eager';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check error defined or not, by name
|
|
146
|
+
*
|
|
147
|
+
* @param {string} name - error name
|
|
148
|
+
* @return {boolean}
|
|
149
|
+
* */
|
|
150
|
+
function isErrorDefined(name) {
|
|
151
|
+
return !!getError(name);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get error by name
|
|
155
|
+
* Note:
|
|
156
|
+
* - Enum may be lazy mode, so it has lazy paths without class
|
|
157
|
+
*
|
|
158
|
+
* @param {string} name - error name
|
|
159
|
+
* @return {EnumItem}
|
|
160
|
+
* */
|
|
161
|
+
function getError(name) {
|
|
162
|
+
if (!(0, function_1.isText)(name)) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
if (!_names.has(name)) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return _names.get(name);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Load lazy error by name
|
|
172
|
+
* Note:
|
|
173
|
+
* - Error must be exported as `foretell`
|
|
174
|
+
*
|
|
175
|
+
* @param {string} name - name of error
|
|
176
|
+
* @return {Promise<EnumItem>}
|
|
177
|
+
* */
|
|
178
|
+
function getLazyError(name) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
if (!(0, function_1.isText)(name)) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
if (!_names.has(name)) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
const item = _names.get(name);
|
|
187
|
+
if (item.mode === 'eager') {
|
|
188
|
+
return item;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
item.clazz = yield item.lazyClass;
|
|
192
|
+
if ((0, function_1.isClass)(item.clazz)) {
|
|
193
|
+
if (isAlreadyDefined(name, item.clazz)) {
|
|
194
|
+
delete item.lazyClass;
|
|
195
|
+
return item;
|
|
196
|
+
}
|
|
197
|
+
item.mode = 'eager';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
new error_1.DeveloperError('Raised callback run', 'optCheck#01', where).log(e);
|
|
202
|
+
}
|
|
203
|
+
delete item.lazyClass;
|
|
204
|
+
return item;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* It will be called when an error raised
|
|
209
|
+
* */
|
|
210
|
+
function emitError(err) {
|
|
211
|
+
if (!(err instanceof Error)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// already emitted
|
|
215
|
+
if (err[const_1.LY_ERROR_EMITTED]) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const clazz = err.constructor;
|
|
219
|
+
// error does not support to emit
|
|
220
|
+
if (!clazz[const_1.LY_ERROR_EMIT]) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// prevent duplicated emits
|
|
224
|
+
err[const_1.LY_ERROR_EMITTED] = true;
|
|
225
|
+
(0, event_fn_1.emitEvent)('error:emit', err);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Build error stack
|
|
229
|
+
*
|
|
230
|
+
* @param {Error} source
|
|
231
|
+
* @param {boolean?} force
|
|
232
|
+
* */
|
|
233
|
+
function errorStack(source, force) {
|
|
234
|
+
var _a;
|
|
235
|
+
if (!force && Array.isArray(source.stackTrace)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
source.stackTrace = [];
|
|
239
|
+
try {
|
|
240
|
+
let causedBy;
|
|
241
|
+
const leyyoError = source;
|
|
242
|
+
if (leyyoError.causedBy) {
|
|
243
|
+
if (Array.isArray(leyyoError.causedBy) && leyyoError.causedBy.length > 0) {
|
|
244
|
+
causedBy = leyyoError.causedBy[0];
|
|
245
|
+
}
|
|
246
|
+
else if (leyyoError.causedBy instanceof Error) {
|
|
247
|
+
causedBy = leyyoError.causedBy;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const original = (_a = causedBy === null || causedBy === void 0 ? void 0 : causedBy.stack) !== null && _a !== void 0 ? _a : source.stack;
|
|
251
|
+
if (original) {
|
|
252
|
+
const frames = stackTraceParser.parse(original);
|
|
253
|
+
if (Array.isArray(frames)) {
|
|
254
|
+
frames.forEach(frame => {
|
|
255
|
+
var _a, _b;
|
|
256
|
+
if (['<unknown>', 'Object.<anonymous>'].includes(frame.methodName)) {
|
|
257
|
+
frame.methodName = undefined;
|
|
258
|
+
}
|
|
259
|
+
if (frame.file) {
|
|
260
|
+
if (frame.file.startsWith('node:')) {
|
|
261
|
+
frame.file = `@ ` + frame.file.substring(5);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
for (const [pck, short] of _knownPackages.entries()) {
|
|
265
|
+
const index = frame.file.indexOf(pck);
|
|
266
|
+
if (index >= 0) {
|
|
267
|
+
let part = frame.file.substring(index + pck.length);
|
|
268
|
+
if (part.startsWith('/')) {
|
|
269
|
+
part = part.substring(1);
|
|
270
|
+
}
|
|
271
|
+
if (part.startsWith('dist/')) {
|
|
272
|
+
part = part.substring(5);
|
|
273
|
+
}
|
|
274
|
+
frame.file = `#${short} ` + part;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (frame.file.endsWith('.js') || frame.file.endsWith('.ts')) {
|
|
280
|
+
frame.file.substring(0, frame.file.length - 3);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const line = {};
|
|
284
|
+
if (frame.file) {
|
|
285
|
+
line.file = frame.file;
|
|
286
|
+
}
|
|
287
|
+
if (frame.methodName) {
|
|
288
|
+
line.method = frame.methodName;
|
|
289
|
+
}
|
|
290
|
+
if (frame.lineNumber !== undefined && frame.column !== undefined) {
|
|
291
|
+
line.pos = `${(_a = frame.lineNumber) !== null && _a !== void 0 ? _a : ''}:${(_b = frame.column) !== null && _b !== void 0 ? _b : ''}`;
|
|
292
|
+
}
|
|
293
|
+
source.stackTrace.push(line);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
// none
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Transform error as a bare object without name and message
|
|
304
|
+
*
|
|
305
|
+
* @param {Error} err - error instance
|
|
306
|
+
* @param {Opt} existing - existing parameters
|
|
307
|
+
* @return {Opt?} - bare error object
|
|
308
|
+
* */
|
|
309
|
+
function toErrorJsonBasic(err, existing) {
|
|
310
|
+
return _toErrorJson(err, existing, true, new WeakSet());
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Transform error as a bare object with name and message
|
|
314
|
+
*
|
|
315
|
+
* @param {Error} err - error instance
|
|
316
|
+
* @param {Opt} existing - existing parameters
|
|
317
|
+
* @return {Opt?} - bare error object
|
|
318
|
+
* */
|
|
319
|
+
function toErrorJsonFull(err, existing) {
|
|
320
|
+
return _toErrorJson(err, existing, false, new WeakSet());
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Transform error as a bare object
|
|
324
|
+
*
|
|
325
|
+
* @param {Error} err - error instance
|
|
326
|
+
* @param {Opt} existing - existing parameters
|
|
327
|
+
* @param {boolean} ignoreNameMessage - ignore name & message?
|
|
328
|
+
* @param {WeakSet} weakSet - weak set to prevent duplicates
|
|
329
|
+
* @return {Opt?} - bare error object
|
|
330
|
+
* */
|
|
331
|
+
function _toErrorJson(err, existing, ignoreNameMessage, weakSet) {
|
|
332
|
+
if (!(err instanceof Error)) {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
if (weakSet.has(err)) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
weakSet.add(err);
|
|
339
|
+
let result = (0, function_1.isObj)(existing) ? existing : {};
|
|
340
|
+
const leyyoError = err;
|
|
341
|
+
if ((0, function_1.isFilledObj)(leyyoError.params)) {
|
|
342
|
+
result = Object.assign(Object.assign({}, result), leyyoError.params);
|
|
343
|
+
}
|
|
344
|
+
for (const [k, v] of Object.entries(err)) {
|
|
345
|
+
if (typeof k !== 'string' || ['undefined', 'symbol', 'function'].includes(typeof v) || v === null) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
switch (k) {
|
|
349
|
+
case 'name':
|
|
350
|
+
case 'message':
|
|
351
|
+
if (!ignoreNameMessage) {
|
|
352
|
+
result[k] = v;
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
case 'stack':
|
|
356
|
+
case 'params':
|
|
357
|
+
break;
|
|
358
|
+
case 'causedBy':
|
|
359
|
+
if (v instanceof Error) {
|
|
360
|
+
const causedBy = _toErrorJson(v, {}, false, weakSet);
|
|
361
|
+
if (causedBy) {
|
|
362
|
+
result[k] = v;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if ((0, function_1.isFilledArr)(v)) {
|
|
366
|
+
const errors = v;
|
|
367
|
+
const causedErrors = [];
|
|
368
|
+
errors.forEach(e => {
|
|
369
|
+
const causedError = _toErrorJson(e, {}, false, weakSet);
|
|
370
|
+
if (causedError) {
|
|
371
|
+
causedErrors.push(causedError);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
if (causedErrors.length > 0) {
|
|
375
|
+
result[k] = causedErrors;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
default:
|
|
380
|
+
result[k] = v;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Cast a native error to given error class
|
|
387
|
+
*
|
|
388
|
+
* @param {function} clazz - new error class
|
|
389
|
+
* @param {Error} e - native error instance
|
|
390
|
+
* @param {Opt?} params - params for error
|
|
391
|
+
* @return {LeyyoErrorLike} - new error instance
|
|
392
|
+
* */
|
|
393
|
+
function errorCast(clazz, e, params) {
|
|
394
|
+
const err = new clazz(e.message, params);
|
|
395
|
+
err.$copyProperties(e);
|
|
396
|
+
err.causedBy = e;
|
|
397
|
+
return err;
|
|
398
|
+
}
|
|
399
|
+
error_1.DeveloperError.stackBuilder(errorStack);
|
|
400
|
+
//# sourceMappingURL=error.fn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.fn.js","sourceRoot":"","sources":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CAAC;gBACd,MAAM;QACd,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;;;KAOK;AACL,SAAgB,SAAS,CAA2B,KAAgB,EAAE,CAAQ,EAAE,MAAY;IACxF,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAM,CAAC;IAC7C,GAAmC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACxD,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjB,OAAO,GAAG,CAAC;AACf,CAAC;AAED,sBAAc,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventType, Fnc } from "../index.types";
|
|
2
|
+
/**
|
|
3
|
+
* Emit (fire) an event
|
|
4
|
+
*
|
|
5
|
+
* @param {string} name - event name
|
|
6
|
+
* @param {...Array} values - They will be used for callback of listener
|
|
7
|
+
* @return {boolean} - message is emitted correctly
|
|
8
|
+
*
|
|
9
|
+
* Note:
|
|
10
|
+
* - If there is not any listener for this event yet, events will be collected
|
|
11
|
+
* */
|
|
12
|
+
export declare function emitEvent<T extends string = string>(name: EventType | T, ...values: Array<unknown>): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Listen an event
|
|
15
|
+
*
|
|
16
|
+
* @param {string} name - event name
|
|
17
|
+
* @param {function} callback - callback for emitted event
|
|
18
|
+
*
|
|
19
|
+
* Note:
|
|
20
|
+
* - If there are previous emitted events, it will listen them immediately (lazy event driven)
|
|
21
|
+
* */
|
|
22
|
+
export declare function listenEvent<T extends string = string>(name: EventType | T, callback: Fnc): void;
|
|
23
|
+
/**
|
|
24
|
+
* Deactivate an event
|
|
25
|
+
*
|
|
26
|
+
* Means:
|
|
27
|
+
* - If there is no any listener then;
|
|
28
|
+
* - - emitted messages will be ignored
|
|
29
|
+
* - - collected message will be cleared
|
|
30
|
+
*
|
|
31
|
+
* @param {string} name - event name
|
|
32
|
+
* @return {boolean} - if it is previously activated (default) then true
|
|
33
|
+
* */
|
|
34
|
+
export declare function deactivateEvent(name: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Activate an event
|
|
37
|
+
*
|
|
38
|
+
* Means:
|
|
39
|
+
* - If there is no any listener then;
|
|
40
|
+
* - - emitted messages will be collected till listener comes in
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name - event name
|
|
43
|
+
* @return {boolean} - if it is previously deactivated then true
|
|
44
|
+
* */
|
|
45
|
+
export declare function activateEvent(name: string): boolean;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.emitEvent = emitEvent;
|
|
7
|
+
exports.listenEvent = listenEvent;
|
|
8
|
+
exports.deactivateEvent = deactivateEvent;
|
|
9
|
+
exports.activateEvent = activateEvent;
|
|
10
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
11
|
+
const function_1 = require("../function");
|
|
12
|
+
const error_1 = require("../error");
|
|
13
|
+
const internal_1 = require("../internal");
|
|
14
|
+
const class_1 = require("../class");
|
|
15
|
+
const set_fn_1 = require("./set.fn");
|
|
16
|
+
const map_fn_1 = require("./map.fn");
|
|
17
|
+
// region properties
|
|
18
|
+
const where = `${internal_1.FQN}.EventFn`;
|
|
19
|
+
const emitter = new node_events_1.default();
|
|
20
|
+
const listenedEvents = (0, map_fn_1.newRepoMap)(`${where}.listened`);
|
|
21
|
+
const waitingEvents = (0, map_fn_1.newRepoMap)(`${where}.waiting`);
|
|
22
|
+
const removedEvents = (0, map_fn_1.newRepoMap)(`${where}.removed`); // stored, emitted
|
|
23
|
+
const deactivatedEvents = (0, set_fn_1.newRepoSet)(`${where}.deactivated`);
|
|
24
|
+
// endregion properties
|
|
25
|
+
/**
|
|
26
|
+
* Emit (fire) an event
|
|
27
|
+
*
|
|
28
|
+
* @param {string} name - event name
|
|
29
|
+
* @param {...Array} values - They will be used for callback of listener
|
|
30
|
+
* @return {boolean} - message is emitted correctly
|
|
31
|
+
*
|
|
32
|
+
* Note:
|
|
33
|
+
* - If there is not any listener for this event yet, events will be collected
|
|
34
|
+
* */
|
|
35
|
+
function emitEvent(name, ...values) {
|
|
36
|
+
if (typeof name !== 'string') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (!emitter.emit(name, ...values)) {
|
|
40
|
+
// It is deactivated, no collect it anymore
|
|
41
|
+
if (deactivatedEvents.has(name)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
let item = waitingEvents.get(name);
|
|
45
|
+
if (!item) {
|
|
46
|
+
item = [];
|
|
47
|
+
waitingEvents.set(name, item);
|
|
48
|
+
}
|
|
49
|
+
else if (item.length > 10000) {
|
|
50
|
+
let parts = removedEvents.get(name);
|
|
51
|
+
if (parts === undefined) {
|
|
52
|
+
parts = [item.length, item.length + 1];
|
|
53
|
+
class_1.defLogger.warn(`Removed message. name: ${name}, times: ${parts[1]}`, { where, eventName: name });
|
|
54
|
+
item.shift();
|
|
55
|
+
removedEvents.set(name, parts);
|
|
56
|
+
}
|
|
57
|
+
else if (parts[0] >= 10000) {
|
|
58
|
+
// there are too many events, and there is no any listener, close it
|
|
59
|
+
if (parts[1] > 50000) {
|
|
60
|
+
deactivateEvent(name);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
// clear half of it
|
|
64
|
+
parts[0] = 5000;
|
|
65
|
+
item.splice(0, 5000);
|
|
66
|
+
parts[1]++; // increment emitted
|
|
67
|
+
class_1.defLogger.warn(`Removed all messages. name: ${name}, times: ${parts[1]}`, { where, eventName: name });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
parts[1]++; // increment emitted
|
|
71
|
+
item.shift();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
item.push(values);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Listen an event
|
|
81
|
+
*
|
|
82
|
+
* @param {string} name - event name
|
|
83
|
+
* @param {function} callback - callback for emitted event
|
|
84
|
+
*
|
|
85
|
+
* Note:
|
|
86
|
+
* - If there are previous emitted events, it will listen them immediately (lazy event driven)
|
|
87
|
+
* */
|
|
88
|
+
function listenEvent(name, callback) {
|
|
89
|
+
if (!(0, function_1.isText)(name)) {
|
|
90
|
+
throw new error_1.DeveloperError('Invalid event name', 'listenEvent#01', where);
|
|
91
|
+
}
|
|
92
|
+
if (typeof callback !== 'function') {
|
|
93
|
+
throw new error_1.DeveloperError('Invalid event callback', 'listenEvent#02', where);
|
|
94
|
+
}
|
|
95
|
+
const exists = listenedEvents.has(name);
|
|
96
|
+
if (exists) {
|
|
97
|
+
emitter.removeAllListeners(name);
|
|
98
|
+
}
|
|
99
|
+
emitter.on(name, callback);
|
|
100
|
+
// if there is a listener, event will be activated automatically
|
|
101
|
+
activateEvent(name);
|
|
102
|
+
listenedEvents.set(name, callback);
|
|
103
|
+
if (!exists) {
|
|
104
|
+
if (waitingEvents.has(name)) {
|
|
105
|
+
waitingEvents.get(name).forEach(values => {
|
|
106
|
+
emitter.emit(name, ...values);
|
|
107
|
+
});
|
|
108
|
+
waitingEvents.delete(name);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Deactivate an event
|
|
114
|
+
*
|
|
115
|
+
* Means:
|
|
116
|
+
* - If there is no any listener then;
|
|
117
|
+
* - - emitted messages will be ignored
|
|
118
|
+
* - - collected message will be cleared
|
|
119
|
+
*
|
|
120
|
+
* @param {string} name - event name
|
|
121
|
+
* @return {boolean} - if it is previously activated (default) then true
|
|
122
|
+
* */
|
|
123
|
+
function deactivateEvent(name) {
|
|
124
|
+
if (!(0, function_1.isText)(name)) {
|
|
125
|
+
throw new error_1.DeveloperError('Invalid event name', 'listenEvent#01', where);
|
|
126
|
+
}
|
|
127
|
+
if (waitingEvents.has(name)) {
|
|
128
|
+
class_1.defLogger.warn(`Deactivated and cleared all messages. name: ${name}`, { where, eventName: name });
|
|
129
|
+
waitingEvents.delete(name);
|
|
130
|
+
}
|
|
131
|
+
if (removedEvents.has(name)) {
|
|
132
|
+
removedEvents.delete(name);
|
|
133
|
+
}
|
|
134
|
+
if (!deactivatedEvents.has(name)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
deactivatedEvents.add(name);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Activate an event
|
|
142
|
+
*
|
|
143
|
+
* Means:
|
|
144
|
+
* - If there is no any listener then;
|
|
145
|
+
* - - emitted messages will be collected till listener comes in
|
|
146
|
+
*
|
|
147
|
+
* @param {string} name - event name
|
|
148
|
+
* @return {boolean} - if it is previously deactivated then true
|
|
149
|
+
* */
|
|
150
|
+
function activateEvent(name) {
|
|
151
|
+
if (!(0, function_1.isText)(name)) {
|
|
152
|
+
throw new error_1.DeveloperError('Invalid event name', 'listenEvent#01', where);
|
|
153
|
+
}
|
|
154
|
+
if (deactivatedEvents.has(name)) {
|
|
155
|
+
deactivatedEvents.delete(name);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=event.fn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.fn.js","sourceRoot":"","sources":["../../src/common/event.fn.ts"],"names":[],"mappings":";;;;;AA4BA,8BAgDC;AAWD,kCA0BC;AAaD,0CAgBC;AAYD,sCASC;AAnKD,8DAAuC;AAEvC,0CAAmC;AACnC,oCAAwC;AACxC,0CAAgC;AAChC,oCAAmC;AACnC,qCAAoC;AACpC,qCAAoC;AAEpC,oBAAoB;AACpB,MAAM,KAAK,GAAG,GAAG,cAAG,UAAU,CAAC;AAC/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C,CAAC;IAC/B,CAAC;IACD,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;;;;;;KASK;AACL,SAAgB,aAAa,CAAC,IAAY;IACtC,IAAI,CAAC,IAAA,iBAAM,EAAC,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,sBAAc,CAAC,oBAAoB,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runExporter = runExporter;
|
|
13
|
+
const lifecycle_fn_1 = require("./lifecycle.fn");
|
|
14
|
+
// noinspection JSUnusedGlobalSymbols
|
|
15
|
+
/**
|
|
16
|
+
* Run exporter
|
|
17
|
+
*
|
|
18
|
+
* @return {Promise<ExporterData>}
|
|
19
|
+
* */
|
|
20
|
+
function runExporter() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const data = {};
|
|
23
|
+
const depot = {
|
|
24
|
+
add(name, value) {
|
|
25
|
+
append(data, name, value, 0);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
yield (0, lifecycle_fn_1.runLifecycleStage)('print', depot);
|
|
29
|
+
return data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Append to exporter with preventing overridden keys
|
|
34
|
+
*
|
|
35
|
+
* @param {ExporterData} data
|
|
36
|
+
* @param {string} name
|
|
37
|
+
* @param {ExporterValue} value
|
|
38
|
+
* @param {number} duplicated
|
|
39
|
+
* */
|
|
40
|
+
const append = (data, name, value, duplicated) => {
|
|
41
|
+
const postfix = (duplicated === 0) ? '' : '#' + duplicated;
|
|
42
|
+
if (data[name + postfix] !== undefined) {
|
|
43
|
+
data[name + postfix] = value;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
append(data, name, value, duplicated + 1);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=exporter.fn.js.map
|