@leyyo/common 1.3.7 → 1.3.9
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/dist/base/index.d.ts +3 -3
- package/dist/base/index.js +3 -20
- package/dist/base/index.types.d.ts +32 -18
- package/dist/base/index.types.js +1 -3
- package/dist/base/leyyo.d.ts +1 -1
- package/dist/base/leyyo.js +35 -26
- package/dist/base/leyyo.types.d.ts +3 -3
- package/dist/base/leyyo.types.js +1 -3
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +2 -19
- package/dist/class/index.types.d.ts +1 -1
- package/dist/class/index.types.js +1 -3
- package/dist/class/list.d.ts +1 -1
- package/dist/class/list.js +1 -6
- package/dist/class/logger.instance.d.ts +5 -5
- package/dist/class/logger.instance.js +8 -12
- package/dist/common/deploy.common.d.ts +2 -2
- package/dist/common/deploy.common.js +14 -16
- package/dist/common/enum.pool.d.ts +5 -3
- package/dist/common/enum.pool.js +36 -48
- package/dist/common/error.common.d.ts +4 -4
- package/dist/common/error.common.js +45 -85
- package/dist/common/error.pool.d.ts +5 -3
- package/dist/common/error.pool.js +12 -23
- package/dist/common/event.common.d.ts +2 -2
- package/dist/common/event.common.js +25 -28
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +11 -28
- package/dist/common/index.types.d.ts +42 -6
- package/dist/common/index.types.js +1 -3
- package/dist/common/inert.d.ts +4 -2
- package/dist/common/inert.js +97 -110
- package/dist/common/lifecycle.common.d.ts +2 -2
- package/dist/common/lifecycle.common.js +48 -61
- package/dist/common/literal.pool.d.ts +6 -3
- package/dist/common/literal.pool.js +37 -48
- package/dist/common/log.common.d.ts +4 -4
- package/dist/common/log.common.js +63 -60
- package/dist/common/repo.common.d.ts +3 -3
- package/dist/common/repo.common.js +50 -52
- package/dist/const/index.js +26 -30
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +1 -18
- package/dist/enum/log-level.js +1 -5
- package/dist/error/caused.error.d.ts +2 -2
- package/dist/error/caused.error.js +2 -7
- package/dist/error/developer.error.d.ts +3 -3
- package/dist/error/developer.error.js +9 -9
- package/dist/error/http.error.d.ts +2 -2
- package/dist/error/http.error.js +9 -15
- package/dist/error/index.d.ts +7 -7
- package/dist/error/index.js +7 -24
- package/dist/error/index.types.d.ts +3 -3
- package/dist/error/index.types.js +1 -3
- package/dist/error/invalid-value.error.d.ts +1 -1
- package/dist/error/invalid-value.error.js +6 -13
- package/dist/error/leyyo.error.d.ts +5 -5
- package/dist/error/leyyo.error.js +45 -34
- package/dist/error/multiple.error.d.ts +2 -2
- package/dist/error/multiple.error.js +6 -12
- package/dist/function/define-loader.d.ts +1 -1
- package/dist/function/define-loader.js +7 -10
- package/dist/function/delay.js +2 -6
- package/dist/function/delete-prop.js +9 -15
- package/dist/function/{empty.fn.js → empty-fn.js} +1 -5
- package/dist/function/extended-type.d.ts +1 -1
- package/dist/function/extended-type.js +8 -12
- package/dist/function/get-fqn.d.ts +1 -1
- package/dist/function/get-fqn.js +7 -12
- package/dist/function/get-prop.js +10 -16
- package/dist/function/has-fqn.d.ts +1 -1
- package/dist/function/has-fqn.js +7 -11
- package/dist/function/index.d.ts +38 -28
- package/dist/function/index.js +38 -45
- package/dist/function/index.types.d.ts +2 -2
- package/dist/function/index.types.js +1 -3
- package/dist/function/is-anonymous-name.js +3 -7
- package/dist/function/is-class.d.ts +7 -0
- package/dist/function/is-class.js +18 -0
- package/dist/function/is-empty.d.ts +12 -0
- package/dist/function/is-empty.js +18 -0
- package/dist/function/is-filled-arr.d.ts +10 -0
- package/dist/function/is-filled-arr.js +12 -0
- package/dist/function/is-filled-obj.d.ts +10 -0
- package/dist/function/is-filled-obj.js +13 -0
- package/dist/function/is-obj.d.ts +9 -0
- package/dist/function/is-obj.js +11 -0
- package/dist/function/is-test.js +2 -7
- package/dist/function/is-text.d.ts +11 -0
- package/dist/function/is-text.js +17 -0
- package/dist/function/jitter-interval.js +2 -6
- package/dist/function/leyyo-fn.d.ts +1 -1
- package/dist/function/leyyo-fn.js +2 -7
- package/dist/function/on-fqn-set.d.ts +1 -1
- package/dist/function/on-fqn-set.js +9 -13
- package/dist/function/one-or-more.d.ts +1 -1
- package/dist/function/one-or-more.js +1 -5
- package/dist/function/opt-add.d.ts +10 -0
- package/dist/function/opt-add.js +29 -0
- package/dist/function/opt-append.d.ts +9 -0
- package/dist/function/opt-append.js +24 -0
- package/dist/function/opt-check.d.ts +8 -0
- package/dist/function/opt-check.js +31 -0
- package/dist/function/opt-clone.d.ts +8 -0
- package/dist/function/opt-clone.js +12 -0
- package/dist/function/opt-field.d.ts +11 -0
- package/dist/function/opt-field.js +31 -0
- package/dist/function/opt-fn.d.ts +8 -0
- package/dist/function/opt-fn.js +11 -0
- package/dist/function/random-test-no.js +1 -5
- package/dist/function/remove-fqn.d.ts +1 -1
- package/dist/function/remove-fqn.js +10 -14
- package/dist/function/run-exporter.d.ts +1 -1
- package/dist/function/run-exporter.js +12 -27
- package/dist/function/secure-clone.d.ts +1 -1
- package/dist/function/secure-clone.js +2 -7
- package/dist/function/secure-json.js +6 -12
- package/dist/function/set-anonymous-fqn.d.ts +1 -1
- package/dist/function/set-anonymous-fqn.js +15 -19
- package/dist/function/set-anonymous-name.d.ts +1 -1
- package/dist/function/set-anonymous-name.js +23 -26
- package/dist/function/set-fqn.d.ts +1 -1
- package/dist/function/set-fqn.js +28 -31
- package/dist/function/set-prop.js +9 -15
- package/dist/function/stamp-loader.d.ts +1 -1
- package/dist/function/stamp-loader.js +4 -8
- package/dist/function/test-case.js +5 -9
- package/dist/function/test-name.js +4 -8
- package/dist/function/trigger-fqn.d.ts +1 -1
- package/dist/function/trigger-fqn.js +5 -9
- package/dist/index.d.ts +19 -19
- package/dist/index.foretell.js +10 -88
- package/dist/index.js +22 -40
- package/dist/index.loader.d.ts +1 -1
- package/dist/index.loader.js +6 -43
- package/dist/init/index.js +3 -7
- package/dist/internal.js +1 -5
- package/package.json +26 -16
- package/dist/assets/.gitkeep +0 -0
- package/dist/base/index.js.map +0 -1
- package/dist/base/index.types.js.map +0 -1
- package/dist/base/leyyo.js.map +0 -1
- package/dist/base/leyyo.types.js.map +0 -1
- package/dist/class/index.js.map +0 -1
- package/dist/class/index.types.js.map +0 -1
- package/dist/class/list.js.map +0 -1
- package/dist/class/logger.instance.js.map +0 -1
- package/dist/common/deploy.common.js.map +0 -1
- package/dist/common/enum.pool.js.map +0 -1
- package/dist/common/error.common.js.map +0 -1
- package/dist/common/error.pool.js.map +0 -1
- package/dist/common/event.common.js.map +0 -1
- package/dist/common/index.js.map +0 -1
- package/dist/common/index.types.js.map +0 -1
- package/dist/common/inert.js.map +0 -1
- package/dist/common/lifecycle.common.js.map +0 -1
- package/dist/common/literal.pool.js.map +0 -1
- package/dist/common/log.common.js.map +0 -1
- package/dist/common/repo.common.js.map +0 -1
- package/dist/const/index.js.map +0 -1
- package/dist/enum/index.js.map +0 -1
- package/dist/enum/log-level.js.map +0 -1
- package/dist/error/caused.error.js.map +0 -1
- package/dist/error/developer.error.js.map +0 -1
- package/dist/error/http.error.js.map +0 -1
- package/dist/error/index.js.map +0 -1
- package/dist/error/index.types.js.map +0 -1
- package/dist/error/invalid-value.error.js.map +0 -1
- package/dist/error/leyyo.error.js.map +0 -1
- package/dist/error/multiple.error.js.map +0 -1
- package/dist/function/define-loader.js.map +0 -1
- package/dist/function/delay.js.map +0 -1
- package/dist/function/delete-prop.js.map +0 -1
- package/dist/function/empty.fn.js.map +0 -1
- package/dist/function/extended-type.js.map +0 -1
- package/dist/function/get-fqn.js.map +0 -1
- package/dist/function/get-prop.js.map +0 -1
- package/dist/function/has-fqn.js.map +0 -1
- package/dist/function/index.js.map +0 -1
- package/dist/function/index.types.js.map +0 -1
- package/dist/function/is-anonymous-name.js.map +0 -1
- package/dist/function/is-test.js.map +0 -1
- package/dist/function/is.fn.d.ts +0 -59
- package/dist/function/is.fn.js +0 -93
- package/dist/function/is.fn.js.map +0 -1
- package/dist/function/jitter-interval.js.map +0 -1
- package/dist/function/leyyo-fn.js.map +0 -1
- package/dist/function/on-fqn-set.js.map +0 -1
- package/dist/function/one-or-more.js.map +0 -1
- package/dist/function/opt.fn.d.ts +0 -49
- package/dist/function/opt.fn.js +0 -142
- package/dist/function/opt.fn.js.map +0 -1
- package/dist/function/random-test-no.js.map +0 -1
- package/dist/function/remove-fqn.js.map +0 -1
- package/dist/function/run-exporter.js.map +0 -1
- package/dist/function/secure-clone.js.map +0 -1
- package/dist/function/secure-json.js.map +0 -1
- package/dist/function/set-anonymous-fqn.js.map +0 -1
- package/dist/function/set-anonymous-name.js.map +0 -1
- package/dist/function/set-fqn.js.map +0 -1
- package/dist/function/set-prop.js.map +0 -1
- package/dist/function/stamp-loader.js.map +0 -1
- package/dist/function/test-case.js.map +0 -1
- package/dist/function/test-name.js.map +0 -1
- package/dist/function/trigger-fqn.js.map +0 -1
- package/dist/index.foretell.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.loader.js.map +0 -1
- package/dist/init/index.js.map +0 -1
- package/dist/internal.js.map +0 -1
- /package/dist/function/{empty.fn.d.ts → empty-fn.d.ts} +0 -0
package/dist/common/inert.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.Inert = void 0;
|
|
13
|
-
const internal_1 = require("../internal");
|
|
14
|
-
const function_1 = require("../function");
|
|
15
|
-
const where = `${internal_1.FQN}.Inert`;
|
|
1
|
+
import { FQN } from "../internal.js";
|
|
2
|
+
import { getFqn, isFilledArr, isFilledObj, isObj, isText, onFqnSet, setAnonymousName, setFqn, testCase } from "../function/index.js";
|
|
3
|
+
const where = `${FQN}.Inert`;
|
|
16
4
|
// noinspection JSUnusedGlobalSymbols
|
|
17
|
-
class Inert {
|
|
5
|
+
export class Inert {
|
|
6
|
+
leyyo;
|
|
7
|
+
cluster;
|
|
8
|
+
options;
|
|
9
|
+
_repo;
|
|
10
|
+
static _pool;
|
|
18
11
|
/**
|
|
19
12
|
* Constructor
|
|
20
13
|
*
|
|
@@ -26,21 +19,21 @@ class Inert {
|
|
|
26
19
|
this.leyyo = leyyo;
|
|
27
20
|
this.cluster = cluster;
|
|
28
21
|
this.options = options;
|
|
29
|
-
if (!
|
|
30
|
-
throw new this.leyyo.developerError('Invalid cluster name',
|
|
22
|
+
if (!isText(this.cluster)) {
|
|
23
|
+
throw new this.leyyo.developerError('Invalid cluster name', testCase(FQN, 'XXX'), where);
|
|
31
24
|
}
|
|
32
|
-
if (
|
|
25
|
+
if (isObj(this.options)) {
|
|
33
26
|
this.options = {};
|
|
34
27
|
}
|
|
35
|
-
if (this.options.anonymousName && !
|
|
36
|
-
throw new this.leyyo.developerError('Invalid anonymous name',
|
|
28
|
+
if (this.options.anonymousName && !isText(this.options.anonymousName)) {
|
|
29
|
+
throw new this.leyyo.developerError('Invalid anonymous name', testCase(FQN, 'XXX'), where);
|
|
37
30
|
}
|
|
38
31
|
const repo = this.leyyo.repoCommon;
|
|
39
32
|
if (!Inert._pool) {
|
|
40
33
|
Inert._pool = repo.newMap(`${where}.pool`);
|
|
41
34
|
}
|
|
42
35
|
if (Inert._pool.has(this.cluster)) {
|
|
43
|
-
throw new this.leyyo.developerError(`Duplicated cluster [${this.cluster}]`,
|
|
36
|
+
throw new this.leyyo.developerError(`Duplicated cluster [${this.cluster}]`, testCase(FQN, 'XXX'), where);
|
|
44
37
|
}
|
|
45
38
|
this._repo = {
|
|
46
39
|
uniqueLoaded: repo.newSet(`${where}.${this.cluster}.uniqueLoaded`),
|
|
@@ -54,16 +47,16 @@ class Inert {
|
|
|
54
47
|
}
|
|
55
48
|
// region private
|
|
56
49
|
_inFqnStage(item) {
|
|
57
|
-
item.full =
|
|
50
|
+
item.full = getFqn(item.target);
|
|
58
51
|
if (!item.full || !item.full.includes('.')) {
|
|
59
|
-
if (
|
|
60
|
-
item.full =
|
|
52
|
+
if (isText(item.fqn)) {
|
|
53
|
+
item.full = setFqn(item.target, item.fqn);
|
|
61
54
|
}
|
|
62
55
|
else {
|
|
63
56
|
const { pendingFqn } = this._repo;
|
|
64
57
|
pendingFqn.set(item.name, item);
|
|
65
58
|
item.stage = 'fqn-waiting';
|
|
66
|
-
|
|
59
|
+
onFqnSet(item.target, f => this._afterFqnSet(f));
|
|
67
60
|
this._afterTargetFound(item);
|
|
68
61
|
return true;
|
|
69
62
|
}
|
|
@@ -71,7 +64,7 @@ class Inert {
|
|
|
71
64
|
return false;
|
|
72
65
|
}
|
|
73
66
|
_afterFqnSet(full) {
|
|
74
|
-
if (!
|
|
67
|
+
if (!isText(full)) {
|
|
75
68
|
return;
|
|
76
69
|
}
|
|
77
70
|
const { pendingFqn } = this._repo;
|
|
@@ -83,19 +76,19 @@ class Inert {
|
|
|
83
76
|
this._onFqnCompleted(item);
|
|
84
77
|
}
|
|
85
78
|
else {
|
|
86
|
-
new this.leyyo.developerError(`Inert could not be found after come back, [${full}]`,
|
|
79
|
+
new this.leyyo.developerError(`Inert could not be found after come back, [${full}]`, testCase(FQN, 'ZZZ'), where).log();
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
82
|
_onFqnCompleted(item) {
|
|
90
83
|
let ignore;
|
|
91
84
|
const { fullNames, basicNames, aliases } = this._repo;
|
|
92
|
-
if (
|
|
85
|
+
if (isText(item.full)) {
|
|
93
86
|
ignore = false;
|
|
94
87
|
if (fullNames.has(item.full)) {
|
|
95
88
|
const anotherItem = fullNames.get(item.full);
|
|
96
89
|
if (anotherItem.target !== item.target) {
|
|
97
90
|
ignore = true;
|
|
98
|
-
new this.leyyo.developerError(`Duplicated full name [${item.full}]`,
|
|
91
|
+
new this.leyyo.developerError(`Duplicated full name [${item.full}]`, testCase(FQN, 'ZZZ'), where).log();
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
if (!ignore) {
|
|
@@ -107,25 +100,24 @@ class Inert {
|
|
|
107
100
|
const anotherItem = basicNames.get(item.name);
|
|
108
101
|
if (anotherItem.target !== item.target) {
|
|
109
102
|
ignore = true;
|
|
110
|
-
new this.leyyo.developerError(`Duplicated basic name [${item.name}]`,
|
|
103
|
+
new this.leyyo.developerError(`Duplicated basic name [${item.name}]`, testCase(FQN, 'ZZZ'), where).log();
|
|
111
104
|
}
|
|
112
105
|
}
|
|
113
106
|
if (!ignore) {
|
|
114
107
|
basicNames.set(item.name, item);
|
|
115
108
|
}
|
|
116
|
-
if (
|
|
109
|
+
if (isFilledArr(item.aliases)) {
|
|
117
110
|
item.aliases.forEach(alias => {
|
|
118
|
-
var _a;
|
|
119
111
|
ignore = false;
|
|
120
112
|
if (aliases.has(alias)) {
|
|
121
113
|
const anotherName = aliases.get(alias);
|
|
122
114
|
if (![item.name, item.full].includes(anotherName)) {
|
|
123
115
|
ignore = true;
|
|
124
|
-
new this.leyyo.developerError(`Duplicated alias [${item.name}]`,
|
|
116
|
+
new this.leyyo.developerError(`Duplicated alias [${item.name}]`, testCase(FQN, 'ZZZ'), where).log();
|
|
125
117
|
}
|
|
126
118
|
}
|
|
127
119
|
if (!ignore) {
|
|
128
|
-
aliases.set(alias,
|
|
120
|
+
aliases.set(alias, item.full ?? item.name);
|
|
129
121
|
}
|
|
130
122
|
});
|
|
131
123
|
}
|
|
@@ -134,8 +126,8 @@ class Inert {
|
|
|
134
126
|
/** @inheritDoc */
|
|
135
127
|
register(options) {
|
|
136
128
|
const { uniqueLoaded } = this._repo;
|
|
137
|
-
if (!
|
|
138
|
-
throw new this.leyyo.developerError('Invalid inert options',
|
|
129
|
+
if (!isFilledObj(options)) {
|
|
130
|
+
throw new this.leyyo.developerError('Invalid inert options', testCase(FQN, 'XXX'), where);
|
|
139
131
|
}
|
|
140
132
|
// target
|
|
141
133
|
if (this._validate(options.target)) {
|
|
@@ -148,18 +140,18 @@ class Inert {
|
|
|
148
140
|
}
|
|
149
141
|
let basicName = this._getName(options.target);
|
|
150
142
|
if (!basicName) {
|
|
151
|
-
if (
|
|
143
|
+
if (isText(options.name)) {
|
|
152
144
|
basicName = options.name;
|
|
153
145
|
this._setName(options.target, options.name);
|
|
154
146
|
}
|
|
155
147
|
else if (this.options.anonymousName) {
|
|
156
|
-
basicName =
|
|
148
|
+
basicName = setAnonymousName(options.target, this.options.anonymousName);
|
|
157
149
|
}
|
|
158
150
|
}
|
|
159
151
|
if (!basicName) {
|
|
160
|
-
throw new this.leyyo.developerError('Empty name',
|
|
152
|
+
throw new this.leyyo.developerError('Empty name', testCase(FQN, 220), where);
|
|
161
153
|
}
|
|
162
|
-
const item =
|
|
154
|
+
const item = { ...options, name: basicName, stage: undefined, mode: 'eager' };
|
|
163
155
|
if (this._inFqnStage(item)) {
|
|
164
156
|
return;
|
|
165
157
|
}
|
|
@@ -169,45 +161,44 @@ class Inert {
|
|
|
169
161
|
}
|
|
170
162
|
// lazy target
|
|
171
163
|
else if (options.lazyTarget instanceof Promise) {
|
|
172
|
-
if (!
|
|
173
|
-
throw new this.leyyo.developerError('Invalid inert name',
|
|
164
|
+
if (!isText(options.name)) {
|
|
165
|
+
throw new this.leyyo.developerError('Invalid inert name', testCase(FQN, 'XXX'), where);
|
|
174
166
|
}
|
|
175
167
|
// it's already pending to be loaded
|
|
176
168
|
const { pendingLazy } = this._repo;
|
|
177
169
|
if (pendingLazy.has(options.name)) {
|
|
178
170
|
return;
|
|
179
171
|
}
|
|
180
|
-
const item =
|
|
172
|
+
const item = { ...options, stage: 'loading-waiting', mode: 'lazy' };
|
|
181
173
|
pendingLazy.set(options.name, item);
|
|
182
174
|
}
|
|
183
175
|
else {
|
|
184
|
-
throw new this.leyyo.developerError(`Invalid target or lazy target [${options.name}]`,
|
|
176
|
+
throw new this.leyyo.developerError(`Invalid target or lazy target [${options.name}]`, testCase(FQN, 224), where);
|
|
185
177
|
}
|
|
186
178
|
}
|
|
187
179
|
/** @inheritDoc */
|
|
180
|
+
lazy(fqn, name, lazyTarget, opt) {
|
|
181
|
+
this.register({ ...(opt ?? {}), fqn, name, lazyTarget });
|
|
182
|
+
}
|
|
183
|
+
/** @inheritDoc */
|
|
188
184
|
isLazy(name) {
|
|
189
|
-
|
|
190
|
-
return ((_a = this.get(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'lazy';
|
|
185
|
+
return this.get(name)?.mode === 'lazy';
|
|
191
186
|
}
|
|
192
187
|
/** @inheritDoc */
|
|
193
188
|
isInvalid(name) {
|
|
194
|
-
|
|
195
|
-
return ['failed', 'conflicted'].includes((_a = this.get(name)) === null || _a === void 0 ? void 0 : _a.mode);
|
|
189
|
+
return ['failed', 'conflicted'].includes(this.get(name)?.mode);
|
|
196
190
|
}
|
|
197
191
|
/** @inheritDoc */
|
|
198
192
|
isFailed(name) {
|
|
199
|
-
|
|
200
|
-
return ((_a = this.get(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'failed';
|
|
193
|
+
return this.get(name)?.mode === 'failed';
|
|
201
194
|
}
|
|
202
195
|
/** @inheritDoc */
|
|
203
196
|
isConflicted(name) {
|
|
204
|
-
|
|
205
|
-
return ((_a = this.get(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'conflicted';
|
|
197
|
+
return this.get(name)?.mode === 'conflicted';
|
|
206
198
|
}
|
|
207
199
|
/** @inheritDoc */
|
|
208
200
|
isEager(name) {
|
|
209
|
-
|
|
210
|
-
return ((_a = this.get(name)) === null || _a === void 0 ? void 0 : _a.mode) === 'eager';
|
|
201
|
+
return this.get(name)?.mode === 'eager';
|
|
211
202
|
}
|
|
212
203
|
/** @inheritDoc */
|
|
213
204
|
has(name) {
|
|
@@ -215,7 +206,7 @@ class Inert {
|
|
|
215
206
|
}
|
|
216
207
|
/** @inheritDoc */
|
|
217
208
|
get(name) {
|
|
218
|
-
if (!
|
|
209
|
+
if (!isText(name)) {
|
|
219
210
|
return undefined;
|
|
220
211
|
}
|
|
221
212
|
const { fullNames, basicNames, pendingFqn, pendingLazy, aliases } = this._repo;
|
|
@@ -238,65 +229,61 @@ class Inert {
|
|
|
238
229
|
return basicNames.get(name);
|
|
239
230
|
}
|
|
240
231
|
/** @inheritDoc */
|
|
241
|
-
load(name) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
pendingLazy.delete(name);
|
|
263
|
-
}
|
|
264
|
-
yield this._nextLoad(item);
|
|
265
|
-
// already loaded
|
|
266
|
-
if (uniqueLoaded.has(item.target)) {
|
|
267
|
-
return item;
|
|
268
|
-
}
|
|
232
|
+
async load(name) {
|
|
233
|
+
if (!isText(name)) {
|
|
234
|
+
throw new this.leyyo.developerError(`Invalid lazy name`, testCase(FQN, 'ZZZ'), where);
|
|
235
|
+
}
|
|
236
|
+
const { pendingLazy, uniqueLoaded } = this._repo;
|
|
237
|
+
const item = this.get(name);
|
|
238
|
+
if (!item) {
|
|
239
|
+
throw new this.leyyo.developerError(`Lazy was not defined [${name}]`, testCase(FQN, 'ZZZ'), where);
|
|
240
|
+
}
|
|
241
|
+
// It was already loaded
|
|
242
|
+
if (item.mode === 'eager') {
|
|
243
|
+
return item;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
item.target = await item.lazyTarget;
|
|
247
|
+
if (this._validate(item.target)) {
|
|
248
|
+
item.mode = 'eager';
|
|
249
|
+
delete item.lazyTarget;
|
|
250
|
+
// remove from pending
|
|
251
|
+
if (pendingLazy.has(name)) {
|
|
252
|
+
pendingLazy.delete(name);
|
|
269
253
|
}
|
|
270
|
-
|
|
271
|
-
|
|
254
|
+
await this._nextLoad(item);
|
|
255
|
+
// already loaded
|
|
256
|
+
if (uniqueLoaded.has(item.target)) {
|
|
257
|
+
return item;
|
|
272
258
|
}
|
|
273
259
|
}
|
|
274
|
-
|
|
275
|
-
item.mode = '
|
|
276
|
-
new this.leyyo.developerError(`Callback inert during loading lazy class [${name}]`, (0, function_1.testCase)(internal_1.FQN, 227), where).log(e);
|
|
277
|
-
}
|
|
278
|
-
// file could not be loaded
|
|
279
|
-
if (!item.target) {
|
|
280
|
-
return undefined;
|
|
260
|
+
else {
|
|
261
|
+
item.mode = 'conflicted';
|
|
281
262
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
263
|
+
}
|
|
264
|
+
catch (e) {
|
|
265
|
+
item.mode = 'failed';
|
|
266
|
+
new this.leyyo.developerError(`Callback inert during loading lazy class [${name}]`, testCase(FQN, 227), where).log(e);
|
|
267
|
+
}
|
|
268
|
+
// file could not be loaded
|
|
269
|
+
if (!item.target) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
let realName = this._getName(item.target);
|
|
273
|
+
if (item.name !== realName) {
|
|
274
|
+
if (!realName) {
|
|
275
|
+
realName = this._setName(item.target, item.name);
|
|
290
276
|
}
|
|
291
|
-
if (
|
|
292
|
-
|
|
277
|
+
if (!realName) {
|
|
278
|
+
new this.leyyo.developerError(`Conflict in names [${item.name} vs ${realName}]`, testCase(FQN, 'ZZZ'), where).log();
|
|
293
279
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
280
|
+
}
|
|
281
|
+
if (this._inFqnStage(item)) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
item.stage = 'persistent';
|
|
285
|
+
this._onFqnCompleted(item);
|
|
286
|
+
this._afterTargetFound(item);
|
|
287
|
+
return item;
|
|
299
288
|
}
|
|
300
289
|
}
|
|
301
|
-
exports.Inert = Inert;
|
|
302
|
-
//# sourceMappingURL=inert.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LifecycleCommonLike, LifecycleSortLambda, LifecycleStage } from "./index.types";
|
|
2
|
-
import { Fnc, LeyyoLike } from "../base";
|
|
1
|
+
import { LifecycleCommonLike, LifecycleSortLambda, LifecycleStage } from "./index.types.js";
|
|
2
|
+
import { Fnc, LeyyoLike } from "../base/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Lifecycle common interface
|
|
5
5
|
* */
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.LifecycleCommon = void 0;
|
|
13
|
-
const internal_1 = require("../internal");
|
|
14
|
-
const function_1 = require("../function");
|
|
15
|
-
const where = `${internal_1.FQN}.LifecycleFn`;
|
|
1
|
+
import { FQN } from "../internal.js";
|
|
2
|
+
import { isText, testCase } from "../function/index.js";
|
|
3
|
+
const where = `${FQN}.LifecycleFn`;
|
|
16
4
|
// noinspection JSUnusedGlobalSymbols
|
|
17
5
|
/**
|
|
18
6
|
* Lifecycle common interface
|
|
19
7
|
* */
|
|
20
|
-
class LifecycleCommon {
|
|
8
|
+
export class LifecycleCommon {
|
|
9
|
+
leyyo;
|
|
10
|
+
_stages;
|
|
11
|
+
_sortLambda;
|
|
21
12
|
/**
|
|
22
13
|
* Constructor
|
|
23
14
|
* */
|
|
@@ -45,17 +36,17 @@ class LifecycleCommon {
|
|
|
45
36
|
}
|
|
46
37
|
/** @inheritDoc */
|
|
47
38
|
addStage(stage, name, callback) {
|
|
48
|
-
if (!
|
|
49
|
-
throw new this.leyyo.developerError('Invalid lifecycle stage',
|
|
39
|
+
if (!isText(stage)) {
|
|
40
|
+
throw new this.leyyo.developerError('Invalid lifecycle stage', testCase(FQN, 100), where);
|
|
50
41
|
}
|
|
51
42
|
if (!this._stages.has(stage)) {
|
|
52
|
-
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`,
|
|
43
|
+
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 101), where);
|
|
53
44
|
}
|
|
54
|
-
if (!
|
|
55
|
-
throw new this.leyyo.developerError(`Invalid lifecycle name [${stage}]`,
|
|
45
|
+
if (!isText(name)) {
|
|
46
|
+
throw new this.leyyo.developerError(`Invalid lifecycle name [${stage}]`, testCase(FQN, 102), where);
|
|
56
47
|
}
|
|
57
48
|
if (typeof callback !== 'function') {
|
|
58
|
-
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}/${name}]`,
|
|
49
|
+
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}/${name}]`, testCase(FQN, 103), where);
|
|
59
50
|
}
|
|
60
51
|
const item = this._stages.get(stage);
|
|
61
52
|
if (!item.has(name)) {
|
|
@@ -64,61 +55,57 @@ class LifecycleCommon {
|
|
|
64
55
|
item.get(name).push(callback);
|
|
65
56
|
}
|
|
66
57
|
/** @inheritDoc */
|
|
67
|
-
runStage(stage, ...params) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
async runStage(stage, ...params) {
|
|
59
|
+
if (!isText(stage)) {
|
|
60
|
+
throw new this.leyyo.developerError('Invalid lifecycle stage', testCase(FQN, 104), where);
|
|
61
|
+
}
|
|
62
|
+
if (!this._stages.has(stage)) {
|
|
63
|
+
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 105), where);
|
|
64
|
+
}
|
|
65
|
+
let count = 0;
|
|
66
|
+
const item = this._stages.get(stage);
|
|
67
|
+
if (item.size < 1) {
|
|
68
|
+
return count;
|
|
69
|
+
}
|
|
70
|
+
let sorted;
|
|
71
|
+
if (this._sortLambda) {
|
|
72
|
+
try {
|
|
73
|
+
sorted = this._sortLambda(this._stages.get(stage));
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
catch (e) {
|
|
76
|
+
new this.leyyo.developerError(`Callback error during lifecycle order lambda [${stage}]`, testCase(FQN, 106), where).log(e);
|
|
74
77
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
}
|
|
79
|
+
if (!sorted) {
|
|
80
|
+
sorted = [];
|
|
81
|
+
for (const [name, callbacks] of item.entries()) {
|
|
82
|
+
sorted.push([name, callbacks]);
|
|
79
83
|
}
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
}
|
|
85
|
+
for (const [name, callbacks] of sorted) {
|
|
86
|
+
for (const callback of callbacks) {
|
|
82
87
|
try {
|
|
83
|
-
|
|
88
|
+
await callback(...params);
|
|
89
|
+
count++;
|
|
84
90
|
}
|
|
85
91
|
catch (e) {
|
|
86
|
-
new this.leyyo.developerError(`Callback error during lifecycle
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (!sorted) {
|
|
90
|
-
sorted = [];
|
|
91
|
-
for (const [name, callbacks] of item.entries()) {
|
|
92
|
-
sorted.push([name, callbacks]);
|
|
92
|
+
new this.leyyo.developerError(`Callback error during lifecycle callback [${stage}/${name}]`, testCase(FQN, 107), where).log(e);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
yield callback(...params);
|
|
99
|
-
count++;
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
new this.leyyo.developerError(`Callback error during lifecycle callback [${stage}/${name}]`, (0, function_1.testCase)(internal_1.FQN, 107), where).log(e);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return count;
|
|
107
|
-
});
|
|
95
|
+
}
|
|
96
|
+
return count;
|
|
108
97
|
}
|
|
109
98
|
/** @inheritDoc */
|
|
110
99
|
setOrderLambda(stage, lambda) {
|
|
111
|
-
if (!
|
|
112
|
-
throw new this.leyyo.developerError('Invalid lifecycle stage',
|
|
100
|
+
if (!isText(stage)) {
|
|
101
|
+
throw new this.leyyo.developerError('Invalid lifecycle stage', testCase(FQN, 108), where);
|
|
113
102
|
}
|
|
114
103
|
if (!this._stages.has(stage)) {
|
|
115
|
-
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`,
|
|
104
|
+
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 109), where);
|
|
116
105
|
}
|
|
117
106
|
if (typeof lambda !== 'function') {
|
|
118
|
-
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}]`,
|
|
107
|
+
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}]`, testCase(FQN, 110), where);
|
|
119
108
|
}
|
|
120
109
|
this._sortLambda = lambda;
|
|
121
110
|
}
|
|
122
111
|
}
|
|
123
|
-
exports.LifecycleCommon = LifecycleCommon;
|
|
124
|
-
//# sourceMappingURL=lifecycle.common.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Inert } from "./inert";
|
|
2
|
-
import { Literal, LiteralItemConfig, LiteralPoolItem, LiteralPoolLike, LiteralPoolOpt } from "./index.types";
|
|
3
|
-
import { LeyyoLike } from "../base";
|
|
1
|
+
import { Inert } from "./inert.js";
|
|
2
|
+
import { Literal, LiteralItemConfig, LiteralPoolItem, LiteralPoolLike, LiteralPoolOpt } from "./index.types.js";
|
|
3
|
+
import { LeyyoLike } from "../base/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Literal pool for call with name and lazy loading
|
|
6
6
|
* */
|
|
@@ -19,5 +19,8 @@ export declare class LiteralPool extends Inert<LiteralPoolItem, Literal, Literal
|
|
|
19
19
|
protected _validate(lit: Literal): boolean;
|
|
20
20
|
/** @inheritDoc */
|
|
21
21
|
setConfigItem(lit: Literal, conf: LiteralItemConfig): void;
|
|
22
|
+
/** @inheritDoc */
|
|
22
23
|
getConfigItem(lit: Literal): LiteralItemConfig;
|
|
24
|
+
/** @inheritDoc */
|
|
25
|
+
define(fqn: string, name: string, target: Literal, opt?: Omit<LiteralPoolOpt, 'name' | 'target' | 'lazyTarget' | 'fqn'>): void;
|
|
23
26
|
}
|