@leyyo/common 1.3.18 → 1.3.19
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 -3
- package/dist/base/index.types.d.ts +3 -70
- package/dist/base/index.types.js +0 -32
- package/dist/base/leyyo.d.ts +0 -3
- package/dist/base/leyyo.js +8 -19
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +2 -2
- package/dist/class/index.types.d.ts +0 -20
- package/dist/class/list.d.ts +0 -6
- package/dist/class/list.js +0 -6
- package/dist/class/logger.instance.d.ts +6 -11
- package/dist/class/logger.instance.js +11 -25
- package/dist/common/deploy.common.d.ts +0 -16
- package/dist/common/deploy.common.js +4 -21
- package/dist/common/enum.pool.d.ts +5 -13
- package/dist/common/enum.pool.js +16 -17
- package/dist/common/error.common.d.ts +0 -30
- package/dist/common/error.common.js +33 -69
- package/dist/common/error.pool.d.ts +1 -10
- package/dist/common/error.pool.js +2 -13
- package/dist/common/event.common.d.ts +0 -8
- package/dist/common/event.common.js +15 -25
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +11 -11
- package/dist/common/index.types.d.ts +12 -435
- package/dist/common/index.types.js +0 -1
- package/dist/common/inert.d.ts +1 -49
- package/dist/common/inert.js +35 -64
- package/dist/common/lifecycle.common.d.ts +0 -14
- package/dist/common/lifecycle.common.js +13 -29
- package/dist/common/literal.pool.d.ts +1 -12
- package/dist/common/literal.pool.js +3 -18
- package/dist/common/log.common.d.ts +0 -54
- package/dist/common/log.common.js +62 -147
- package/dist/common/repo.common.d.ts +0 -188
- package/dist/common/repo.common.js +23 -239
- package/dist/const/index.d.ts +0 -7
- package/dist/const/index.js +28 -36
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +1 -1
- package/dist/enum/log-level.d.ts +1 -4
- package/dist/enum/log-level.js +1 -1
- package/dist/error/caused.error.d.ts +0 -10
- package/dist/error/caused.error.js +0 -10
- package/dist/error/developer.error.d.ts +1 -10
- package/dist/error/developer.error.js +6 -25
- package/dist/error/http.error.d.ts +0 -13
- package/dist/error/http.error.js +1 -8
- package/dist/error/index.d.ts +7 -7
- package/dist/error/index.js +7 -7
- package/dist/error/index.types.d.ts +1 -150
- package/dist/error/invalid-value.error.d.ts +0 -3
- package/dist/error/invalid-value.error.js +1 -4
- package/dist/error/leyyo.error.d.ts +0 -33
- package/dist/error/leyyo.error.js +25 -57
- package/dist/error/multiple.error.d.ts +0 -6
- package/dist/error/multiple.error.js +2 -9
- package/dist/function/define-loader.d.ts +0 -6
- package/dist/function/define-loader.js +0 -6
- package/dist/function/delay.d.ts +0 -8
- package/dist/function/delay.js +0 -9
- package/dist/function/delete-prop.d.ts +0 -21
- package/dist/function/delete-prop.js +6 -28
- package/dist/function/empty-fn.d.ts +0 -6
- package/dist/function/empty-fn.js +1 -9
- package/dist/function/extended-type.d.ts +0 -6
- package/dist/function/extended-type.js +18 -24
- package/dist/function/get-fqn.d.ts +0 -6
- package/dist/function/get-fqn.js +2 -8
- package/dist/function/get-prop.d.ts +0 -21
- package/dist/function/get-prop.js +5 -26
- package/dist/function/get-stat.d.ts +0 -20
- package/dist/function/get-stat.js +7 -2
- package/dist/function/has-fqn.d.ts +0 -6
- package/dist/function/has-fqn.js +2 -8
- package/dist/function/index.d.ts +40 -40
- package/dist/function/index.js +40 -40
- package/dist/function/index.types.d.ts +1 -1
- package/dist/function/is-anonymous-name.js +1 -1
- package/dist/function/is-class.d.ts +0 -6
- package/dist/function/is-class.js +2 -20
- package/dist/function/is-empty.d.ts +0 -11
- package/dist/function/is-empty.js +1 -12
- package/dist/function/is-filled-arr.d.ts +0 -9
- package/dist/function/is-filled-arr.js +0 -9
- package/dist/function/is-filled-obj.d.ts +0 -9
- package/dist/function/is-filled-obj.js +0 -9
- package/dist/function/is-obj.d.ts +0 -8
- package/dist/function/is-obj.js +1 -9
- package/dist/function/is-test.d.ts +0 -8
- package/dist/function/is-test.js +3 -19
- package/dist/function/is-text.d.ts +0 -10
- package/dist/function/is-text.js +1 -11
- package/dist/function/jitter-interval.d.ts +0 -9
- package/dist/function/jitter-interval.js +2 -18
- package/dist/function/load-config.d.ts +0 -19
- package/dist/function/load-config.js +10 -61
- package/dist/function/on-fqn-set.js +3 -3
- package/dist/function/one-or-more.d.ts +0 -6
- package/dist/function/one-or-more.js +0 -7
- package/dist/function/opt-add.d.ts +0 -8
- package/dist/function/opt-add.js +2 -10
- package/dist/function/opt-append.d.ts +0 -7
- package/dist/function/opt-append.js +0 -7
- package/dist/function/opt-check.d.ts +0 -6
- package/dist/function/opt-check.js +2 -9
- package/dist/function/opt-clone.d.ts +0 -6
- package/dist/function/opt-clone.js +0 -7
- package/dist/function/opt-field.d.ts +0 -8
- package/dist/function/opt-field.js +6 -14
- package/dist/function/opt-fn.d.ts +0 -6
- package/dist/function/opt-fn.js +0 -7
- package/dist/function/random-test-no.d.ts +0 -5
- package/dist/function/random-test-no.js +0 -5
- package/dist/function/remove-fqn.d.ts +0 -8
- package/dist/function/remove-fqn.js +3 -12
- package/dist/function/run-exporter.d.ts +0 -5
- package/dist/function/run-exporter.js +3 -17
- package/dist/function/secure-clone.js +3 -3
- package/dist/function/secure-json.d.ts +0 -35
- package/dist/function/secure-json.js +12 -54
- package/dist/function/set-anonymous-fqn.js +4 -5
- package/dist/function/set-anonymous-name.js +14 -14
- package/dist/function/set-fqn.d.ts +0 -7
- package/dist/function/set-fqn.js +8 -15
- package/dist/function/set-prop.d.ts +0 -24
- package/dist/function/set-prop.js +6 -30
- package/dist/function/stamp-loader.d.ts +0 -6
- package/dist/function/stamp-loader.js +1 -7
- package/dist/function/test-case.d.ts +0 -7
- package/dist/function/test-case.js +3 -10
- package/dist/function/test-name.d.ts +0 -7
- package/dist/function/test-name.js +2 -9
- package/dist/function/trigger-fqn.js +2 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.foretell.js +7 -10
- package/dist/index.js +10 -11
- package/dist/index.loader.js +1 -8
- package/dist/init/index.js +5 -7
- package/dist/sys/index.d.ts +2 -2
- package/dist/sys/index.js +2 -2
- package/dist/sys/leyyo-storage.d.ts +0 -7
- package/dist/sys/leyyo-storage.js +5 -28
- package/dist/sys/package-json.js +5 -5
- package/package.json +16 -31
package/dist/common/inert.js
CHANGED
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
import { FQN } from "../internal.js";
|
|
2
|
-
import { getFqn, isFilledArr, isFilledObj, isObj, isText, onFqnSet, setAnonymousName, setFqn, testCase } from "../function/index.js";
|
|
2
|
+
import { getFqn, isFilledArr, isFilledObj, isObj, isText, onFqnSet, setAnonymousName, setFqn, testCase, } from "../function/index.js";
|
|
3
3
|
const where = `${FQN}.Inert`;
|
|
4
|
-
// noinspection JSUnusedGlobalSymbols
|
|
5
4
|
export class Inert {
|
|
6
5
|
leyyo;
|
|
7
6
|
cluster;
|
|
8
7
|
options;
|
|
9
8
|
_repo;
|
|
10
9
|
static _pool;
|
|
11
|
-
/**
|
|
12
|
-
* Constructor
|
|
13
|
-
*
|
|
14
|
-
* @param {LeyyoLike} leyyo
|
|
15
|
-
* @param {string} cluster
|
|
16
|
-
* @param {InertBuildOpt} options
|
|
17
|
-
* */
|
|
18
10
|
constructor(leyyo, cluster, options) {
|
|
19
11
|
this.leyyo = leyyo;
|
|
20
12
|
this.cluster = cluster;
|
|
21
13
|
this.options = options;
|
|
22
14
|
if (!isText(this.cluster)) {
|
|
23
|
-
throw new this.leyyo.developerError(
|
|
15
|
+
throw new this.leyyo.developerError("Invalid cluster name", testCase(FQN, "XXX"), where);
|
|
24
16
|
}
|
|
25
17
|
if (isObj(this.options)) {
|
|
26
18
|
this.options = {};
|
|
27
19
|
}
|
|
28
20
|
if (this.options.anonymousName && !isText(this.options.anonymousName)) {
|
|
29
|
-
throw new this.leyyo.developerError(
|
|
21
|
+
throw new this.leyyo.developerError("Invalid anonymous name", testCase(FQN, "XXX"), where);
|
|
30
22
|
}
|
|
31
23
|
const repo = this.leyyo.repoCommon;
|
|
32
24
|
if (!Inert._pool) {
|
|
33
25
|
Inert._pool = repo.newMap(`${where}.pool`);
|
|
34
26
|
}
|
|
35
27
|
if (Inert._pool.has(this.cluster)) {
|
|
36
|
-
throw new this.leyyo.developerError(`Duplicated cluster [${this.cluster}]`, testCase(FQN,
|
|
28
|
+
throw new this.leyyo.developerError(`Duplicated cluster [${this.cluster}]`, testCase(FQN, "XXX"), where);
|
|
37
29
|
}
|
|
38
30
|
this._repo = {
|
|
39
31
|
uniqueLoaded: repo.newSet(`${where}.${this.cluster}.uniqueLoaded`),
|
|
@@ -45,18 +37,17 @@ export class Inert {
|
|
|
45
37
|
};
|
|
46
38
|
Inert._pool.set(this.cluster, this._repo);
|
|
47
39
|
}
|
|
48
|
-
// region private
|
|
49
40
|
_inFqnStage(item) {
|
|
50
41
|
item.full = getFqn(item.target);
|
|
51
|
-
if (!item.full || !item.full.includes(
|
|
42
|
+
if (!item.full || !item.full.includes(".")) {
|
|
52
43
|
if (isText(item.fqn)) {
|
|
53
44
|
item.full = setFqn(item.target, item.fqn);
|
|
54
45
|
}
|
|
55
46
|
else {
|
|
56
47
|
const { pendingFqn } = this._repo;
|
|
57
48
|
pendingFqn.set(item.name, item);
|
|
58
|
-
item.stage =
|
|
59
|
-
onFqnSet(item.target, f => this._afterFqnSet(f));
|
|
49
|
+
item.stage = "fqn-waiting";
|
|
50
|
+
onFqnSet(item.target, (f) => this._afterFqnSet(f));
|
|
60
51
|
this._afterTargetFound(item);
|
|
61
52
|
return true;
|
|
62
53
|
}
|
|
@@ -68,15 +59,15 @@ export class Inert {
|
|
|
68
59
|
return;
|
|
69
60
|
}
|
|
70
61
|
const { pendingFqn } = this._repo;
|
|
71
|
-
const item = pendingFqn.get(full.split(
|
|
62
|
+
const item = pendingFqn.get(full.split(".").pop());
|
|
72
63
|
if (item) {
|
|
73
64
|
pendingFqn.delete(item.name);
|
|
74
65
|
item.full = full;
|
|
75
|
-
item.stage =
|
|
66
|
+
item.stage = "persistent";
|
|
76
67
|
this._onFqnCompleted(item);
|
|
77
68
|
}
|
|
78
69
|
else {
|
|
79
|
-
new this.leyyo.developerError(`Inert could not be found after come back, [${full}]`, testCase(FQN,
|
|
70
|
+
new this.leyyo.developerError(`Inert could not be found after come back, [${full}]`, testCase(FQN, "ZZZ"), where).log();
|
|
80
71
|
}
|
|
81
72
|
}
|
|
82
73
|
_onFqnCompleted(item) {
|
|
@@ -88,7 +79,7 @@ export class Inert {
|
|
|
88
79
|
const anotherItem = fullNames.get(item.full);
|
|
89
80
|
if (anotherItem.target !== item.target) {
|
|
90
81
|
ignore = true;
|
|
91
|
-
new this.leyyo.developerError(`Duplicated full name [${item.full}]`, testCase(FQN,
|
|
82
|
+
new this.leyyo.developerError(`Duplicated full name [${item.full}]`, testCase(FQN, "ZZZ"), where).log();
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
85
|
if (!ignore) {
|
|
@@ -100,20 +91,20 @@ export class Inert {
|
|
|
100
91
|
const anotherItem = basicNames.get(item.name);
|
|
101
92
|
if (anotherItem.target !== item.target) {
|
|
102
93
|
ignore = true;
|
|
103
|
-
new this.leyyo.developerError(`Duplicated basic name [${item.name}]`, testCase(FQN,
|
|
94
|
+
new this.leyyo.developerError(`Duplicated basic name [${item.name}]`, testCase(FQN, "ZZZ"), where).log();
|
|
104
95
|
}
|
|
105
96
|
}
|
|
106
97
|
if (!ignore) {
|
|
107
98
|
basicNames.set(item.name, item);
|
|
108
99
|
}
|
|
109
100
|
if (isFilledArr(item.aliases)) {
|
|
110
|
-
item.aliases.forEach(alias => {
|
|
101
|
+
item.aliases.forEach((alias) => {
|
|
111
102
|
ignore = false;
|
|
112
103
|
if (aliases.has(alias)) {
|
|
113
104
|
const anotherName = aliases.get(alias);
|
|
114
105
|
if (![item.name, item.full].includes(anotherName)) {
|
|
115
106
|
ignore = true;
|
|
116
|
-
new this.leyyo.developerError(`Duplicated alias [${item.name}]`, testCase(FQN,
|
|
107
|
+
new this.leyyo.developerError(`Duplicated alias [${item.name}]`, testCase(FQN, "ZZZ"), where).log();
|
|
117
108
|
}
|
|
118
109
|
}
|
|
119
110
|
if (!ignore) {
|
|
@@ -122,19 +113,15 @@ export class Inert {
|
|
|
122
113
|
});
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
|
-
// endregion private
|
|
126
|
-
/** @inheritDoc */
|
|
127
116
|
register(options) {
|
|
128
117
|
const { uniqueLoaded } = this._repo;
|
|
129
118
|
if (!isFilledObj(options)) {
|
|
130
|
-
throw new this.leyyo.developerError(
|
|
119
|
+
throw new this.leyyo.developerError("Invalid inert options", testCase(FQN, "XXX"), where);
|
|
131
120
|
}
|
|
132
|
-
// target
|
|
133
121
|
if (this._validate(options.target)) {
|
|
134
122
|
if (options.lazyTarget) {
|
|
135
123
|
delete options.lazyTarget;
|
|
136
124
|
}
|
|
137
|
-
// already defined
|
|
138
125
|
if (uniqueLoaded.has(options.target)) {
|
|
139
126
|
return;
|
|
140
127
|
}
|
|
@@ -149,74 +136,63 @@ export class Inert {
|
|
|
149
136
|
}
|
|
150
137
|
}
|
|
151
138
|
if (!basicName) {
|
|
152
|
-
throw new this.leyyo.developerError(
|
|
139
|
+
throw new this.leyyo.developerError("Empty name", testCase(FQN, 220), where);
|
|
153
140
|
}
|
|
154
|
-
const item = { ...options, name: basicName, stage: undefined, mode:
|
|
141
|
+
const item = { ...options, name: basicName, stage: undefined, mode: "eager" };
|
|
155
142
|
if (this._inFqnStage(item)) {
|
|
156
143
|
return;
|
|
157
144
|
}
|
|
158
|
-
item.stage =
|
|
145
|
+
item.stage = "persistent";
|
|
159
146
|
this._onFqnCompleted(item);
|
|
160
147
|
this._afterTargetFound(item);
|
|
161
148
|
}
|
|
162
|
-
// lazy target
|
|
163
149
|
else if (options.lazyTarget instanceof Promise) {
|
|
164
150
|
if (!isText(options.name)) {
|
|
165
|
-
throw new this.leyyo.developerError(
|
|
151
|
+
throw new this.leyyo.developerError("Invalid inert name", testCase(FQN, "XXX"), where);
|
|
166
152
|
}
|
|
167
|
-
// it's already pending to be loaded
|
|
168
153
|
const { pendingLazy } = this._repo;
|
|
169
154
|
if (pendingLazy.has(options.name)) {
|
|
170
155
|
return;
|
|
171
156
|
}
|
|
172
|
-
const item = { ...options, stage:
|
|
157
|
+
const item = { ...options, stage: "loading-waiting", mode: "lazy" };
|
|
173
158
|
pendingLazy.set(options.name, item);
|
|
174
159
|
}
|
|
175
160
|
else {
|
|
176
161
|
throw new this.leyyo.developerError(`Invalid target or lazy target [${options.name}]`, testCase(FQN, 224), where);
|
|
177
162
|
}
|
|
178
163
|
}
|
|
179
|
-
/** @inheritDoc */
|
|
180
164
|
lazy(fqn, name, lazyTarget, opt) {
|
|
181
165
|
this.register({ ...(opt ?? {}), fqn, name, lazyTarget });
|
|
182
166
|
}
|
|
183
|
-
/** @inheritDoc */
|
|
184
167
|
isLazy(name) {
|
|
185
|
-
return this.get(name)?.mode ===
|
|
168
|
+
return this.get(name)?.mode === "lazy";
|
|
186
169
|
}
|
|
187
|
-
/** @inheritDoc */
|
|
188
170
|
isInvalid(name) {
|
|
189
|
-
return [
|
|
171
|
+
return ["failed", "conflicted"].includes(this.get(name)?.mode);
|
|
190
172
|
}
|
|
191
|
-
/** @inheritDoc */
|
|
192
173
|
isFailed(name) {
|
|
193
|
-
return this.get(name)?.mode ===
|
|
174
|
+
return this.get(name)?.mode === "failed";
|
|
194
175
|
}
|
|
195
|
-
/** @inheritDoc */
|
|
196
176
|
isConflicted(name) {
|
|
197
|
-
return this.get(name)?.mode ===
|
|
177
|
+
return this.get(name)?.mode === "conflicted";
|
|
198
178
|
}
|
|
199
|
-
/** @inheritDoc */
|
|
200
179
|
isEager(name) {
|
|
201
|
-
return this.get(name)?.mode ===
|
|
180
|
+
return this.get(name)?.mode === "eager";
|
|
202
181
|
}
|
|
203
|
-
/** @inheritDoc */
|
|
204
182
|
has(name) {
|
|
205
183
|
return !!this.get(name);
|
|
206
184
|
}
|
|
207
|
-
/** @inheritDoc */
|
|
208
185
|
get(name) {
|
|
209
186
|
if (!isText(name)) {
|
|
210
187
|
return undefined;
|
|
211
188
|
}
|
|
212
189
|
const { fullNames, basicNames, pendingFqn, pendingLazy, aliases } = this._repo;
|
|
213
|
-
if (name.includes(
|
|
190
|
+
if (name.includes(".")) {
|
|
214
191
|
if (fullNames.has(name)) {
|
|
215
192
|
return fullNames.get(name);
|
|
216
193
|
}
|
|
217
|
-
return this.get(name.split(
|
|
194
|
+
return this.get(name.split(".").pop());
|
|
218
195
|
}
|
|
219
|
-
// no dot
|
|
220
196
|
if (pendingFqn.has(name)) {
|
|
221
197
|
return pendingFqn.get(name);
|
|
222
198
|
}
|
|
@@ -228,44 +204,39 @@ export class Inert {
|
|
|
228
204
|
}
|
|
229
205
|
return basicNames.get(name);
|
|
230
206
|
}
|
|
231
|
-
/** @inheritDoc */
|
|
232
207
|
async load(name) {
|
|
233
208
|
if (!isText(name)) {
|
|
234
|
-
throw new this.leyyo.developerError(`Invalid lazy name`, testCase(FQN,
|
|
209
|
+
throw new this.leyyo.developerError(`Invalid lazy name`, testCase(FQN, "ZZZ"), where);
|
|
235
210
|
}
|
|
236
211
|
const { pendingLazy, uniqueLoaded } = this._repo;
|
|
237
212
|
const item = this.get(name);
|
|
238
213
|
if (!item) {
|
|
239
|
-
throw new this.leyyo.developerError(`Lazy was not defined [${name}]`, testCase(FQN,
|
|
214
|
+
throw new this.leyyo.developerError(`Lazy was not defined [${name}]`, testCase(FQN, "ZZZ"), where);
|
|
240
215
|
}
|
|
241
|
-
|
|
242
|
-
if (item.mode === 'eager') {
|
|
216
|
+
if (item.mode === "eager") {
|
|
243
217
|
return item;
|
|
244
218
|
}
|
|
245
219
|
try {
|
|
246
220
|
item.target = await item.lazyTarget;
|
|
247
221
|
if (this._validate(item.target)) {
|
|
248
|
-
item.mode =
|
|
222
|
+
item.mode = "eager";
|
|
249
223
|
delete item.lazyTarget;
|
|
250
|
-
// remove from pending
|
|
251
224
|
if (pendingLazy.has(name)) {
|
|
252
225
|
pendingLazy.delete(name);
|
|
253
226
|
}
|
|
254
227
|
await this._nextLoad(item);
|
|
255
|
-
// already loaded
|
|
256
228
|
if (uniqueLoaded.has(item.target)) {
|
|
257
229
|
return item;
|
|
258
230
|
}
|
|
259
231
|
}
|
|
260
232
|
else {
|
|
261
|
-
item.mode =
|
|
233
|
+
item.mode = "conflicted";
|
|
262
234
|
}
|
|
263
235
|
}
|
|
264
236
|
catch (e) {
|
|
265
|
-
item.mode =
|
|
237
|
+
item.mode = "failed";
|
|
266
238
|
new this.leyyo.developerError(`Callback inert during loading lazy class [${name}]`, testCase(FQN, 227), where).log(e);
|
|
267
239
|
}
|
|
268
|
-
// file could not be loaded
|
|
269
240
|
if (!item.target) {
|
|
270
241
|
return undefined;
|
|
271
242
|
}
|
|
@@ -275,13 +246,13 @@ export class Inert {
|
|
|
275
246
|
realName = this._setName(item.target, item.name);
|
|
276
247
|
}
|
|
277
248
|
if (!realName) {
|
|
278
|
-
new this.leyyo.developerError(`Conflict in names [${item.name} vs ${realName}]`, testCase(FQN,
|
|
249
|
+
new this.leyyo.developerError(`Conflict in names [${item.name} vs ${realName}]`, testCase(FQN, "ZZZ"), where).log();
|
|
279
250
|
}
|
|
280
251
|
}
|
|
281
252
|
if (this._inFqnStage(item)) {
|
|
282
253
|
return;
|
|
283
254
|
}
|
|
284
|
-
item.stage =
|
|
255
|
+
item.stage = "persistent";
|
|
285
256
|
this._onFqnCompleted(item);
|
|
286
257
|
this._afterTargetFound(item);
|
|
287
258
|
return item;
|
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import { LifecycleCommonLike, LifecycleSortLambda, LifecycleStage } from "./index.types.js";
|
|
2
2
|
import { Fnc, LeyyoLike } from "../base/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Lifecycle common interface
|
|
5
|
-
* */
|
|
6
3
|
export declare class LifecycleCommon implements LifecycleCommonLike {
|
|
7
4
|
private leyyo;
|
|
8
5
|
private _stages;
|
|
9
6
|
private _sortLambda;
|
|
10
|
-
/**
|
|
11
|
-
* Constructor
|
|
12
|
-
* */
|
|
13
7
|
constructor(leyyo: LeyyoLike);
|
|
14
|
-
/**
|
|
15
|
-
* Init lifecycle by stage
|
|
16
|
-
*
|
|
17
|
-
* @param {LifecycleStage} stage - stage
|
|
18
|
-
* */
|
|
19
8
|
private _init;
|
|
20
|
-
/** @inheritDoc */
|
|
21
9
|
addStage(stage: LifecycleStage, name: string, callback: Fnc): void;
|
|
22
|
-
/** @inheritDoc */
|
|
23
10
|
runStage(stage: LifecycleStage, ...params: Array<unknown>): Promise<number>;
|
|
24
|
-
/** @inheritDoc */
|
|
25
11
|
setOrderLambda(stage: LifecycleStage, lambda: LifecycleSortLambda): void;
|
|
26
12
|
}
|
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
import { FQN } from "../internal.js";
|
|
2
2
|
import { isText, testCase } from "../function/index.js";
|
|
3
3
|
const where = `${FQN}.LifecycleFn`;
|
|
4
|
-
// noinspection JSUnusedGlobalSymbols
|
|
5
|
-
/**
|
|
6
|
-
* Lifecycle common interface
|
|
7
|
-
* */
|
|
8
4
|
export class LifecycleCommon {
|
|
9
5
|
leyyo;
|
|
10
6
|
_stages;
|
|
11
7
|
_sortLambda;
|
|
12
|
-
/**
|
|
13
|
-
* Constructor
|
|
14
|
-
* */
|
|
15
8
|
constructor(leyyo) {
|
|
16
9
|
this.leyyo = leyyo;
|
|
17
10
|
this._stages = this.leyyo.repoCommon.newMap(`${where}.stages`);
|
|
18
|
-
|
|
19
|
-
this._init(
|
|
20
|
-
this._init(
|
|
21
|
-
this._init(
|
|
22
|
-
this._init(
|
|
23
|
-
this._init(
|
|
24
|
-
this._init(
|
|
25
|
-
this._init(
|
|
26
|
-
this._init('kill');
|
|
11
|
+
this._init("initialize");
|
|
12
|
+
this._init("print");
|
|
13
|
+
this._init("validate");
|
|
14
|
+
this._init("process");
|
|
15
|
+
this._init("clear");
|
|
16
|
+
this._init("ota-before");
|
|
17
|
+
this._init("ota-after");
|
|
18
|
+
this._init("kill");
|
|
27
19
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Init lifecycle by stage
|
|
30
|
-
*
|
|
31
|
-
* @param {LifecycleStage} stage - stage
|
|
32
|
-
* */
|
|
33
20
|
_init(stage) {
|
|
34
21
|
const newMap = this.leyyo.repoCommon.newMap(`${where}.${stage}`);
|
|
35
22
|
this._stages.set(stage, newMap);
|
|
36
23
|
}
|
|
37
|
-
/** @inheritDoc */
|
|
38
24
|
addStage(stage, name, callback) {
|
|
39
25
|
if (!isText(stage)) {
|
|
40
|
-
throw new this.leyyo.developerError(
|
|
26
|
+
throw new this.leyyo.developerError("Invalid lifecycle stage", testCase(FQN, 100), where);
|
|
41
27
|
}
|
|
42
28
|
if (!this._stages.has(stage)) {
|
|
43
29
|
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 101), where);
|
|
@@ -45,7 +31,7 @@ export class LifecycleCommon {
|
|
|
45
31
|
if (!isText(name)) {
|
|
46
32
|
throw new this.leyyo.developerError(`Invalid lifecycle name [${stage}]`, testCase(FQN, 102), where);
|
|
47
33
|
}
|
|
48
|
-
if (typeof callback !==
|
|
34
|
+
if (typeof callback !== "function") {
|
|
49
35
|
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}/${name}]`, testCase(FQN, 103), where);
|
|
50
36
|
}
|
|
51
37
|
const item = this._stages.get(stage);
|
|
@@ -54,10 +40,9 @@ export class LifecycleCommon {
|
|
|
54
40
|
}
|
|
55
41
|
item.get(name).push(callback);
|
|
56
42
|
}
|
|
57
|
-
/** @inheritDoc */
|
|
58
43
|
async runStage(stage, ...params) {
|
|
59
44
|
if (!isText(stage)) {
|
|
60
|
-
throw new this.leyyo.developerError(
|
|
45
|
+
throw new this.leyyo.developerError("Invalid lifecycle stage", testCase(FQN, 104), where);
|
|
61
46
|
}
|
|
62
47
|
if (!this._stages.has(stage)) {
|
|
63
48
|
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 105), where);
|
|
@@ -95,15 +80,14 @@ export class LifecycleCommon {
|
|
|
95
80
|
}
|
|
96
81
|
return count;
|
|
97
82
|
}
|
|
98
|
-
/** @inheritDoc */
|
|
99
83
|
setOrderLambda(stage, lambda) {
|
|
100
84
|
if (!isText(stage)) {
|
|
101
|
-
throw new this.leyyo.developerError(
|
|
85
|
+
throw new this.leyyo.developerError("Invalid lifecycle stage", testCase(FQN, 108), where);
|
|
102
86
|
}
|
|
103
87
|
if (!this._stages.has(stage)) {
|
|
104
88
|
throw new this.leyyo.developerError(`Lifecycle stage could not be found [${stage}]`, testCase(FQN, 109), where);
|
|
105
89
|
}
|
|
106
|
-
if (typeof lambda !==
|
|
90
|
+
if (typeof lambda !== "function") {
|
|
107
91
|
throw new this.leyyo.developerError(`Invalid lifecycle callback [${stage}]`, testCase(FQN, 110), where);
|
|
108
92
|
}
|
|
109
93
|
this._sortLambda = lambda;
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
2
|
import { Literal, LiteralItemConfig, LiteralPoolItem, LiteralPoolLike, LiteralPoolOpt } from "./index.types.js";
|
|
3
3
|
import { LeyyoLike } from "../base/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Literal pool for call with name and lazy loading
|
|
6
|
-
* */
|
|
7
4
|
export declare class LiteralPool extends Inert<LiteralPoolItem, Literal, LiteralPoolOpt> implements LiteralPoolLike {
|
|
8
5
|
protected leyyo: LeyyoLike;
|
|
9
6
|
constructor(leyyo: LeyyoLike);
|
|
10
|
-
/** @inheritDoc */
|
|
11
7
|
protected _getName(lit: Literal): string;
|
|
12
|
-
/** @inheritDoc */
|
|
13
8
|
protected _nextLoad(item: LiteralPoolItem): Promise<void>;
|
|
14
|
-
/** @inheritDoc */
|
|
15
9
|
protected _setName(lit: Literal, name: string): string;
|
|
16
|
-
/** @inheritDoc */
|
|
17
10
|
protected _afterTargetFound(item: LiteralPoolItem): void;
|
|
18
|
-
/** @inheritDoc */
|
|
19
11
|
protected _validate(lit: Literal): boolean;
|
|
20
|
-
/** @inheritDoc */
|
|
21
12
|
setConfigItem(lit: Literal, conf: LiteralItemConfig): void;
|
|
22
|
-
/** @inheritDoc */
|
|
23
13
|
getConfigItem(lit: Literal): LiteralItemConfig;
|
|
24
|
-
|
|
25
|
-
define(fqn: string, name: string, target: Literal, opt?: Omit<LiteralPoolOpt, 'name' | 'target' | 'lazyTarget' | 'fqn'>): void;
|
|
14
|
+
define(fqn: string, name: string, target: Literal, opt?: Omit<LiteralPoolOpt, "name" | "target" | "lazyTarget" | "fqn">): void;
|
|
26
15
|
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
|
-
import { getSymbol, isEmpty, isFilledArr, isFilledObj, isObj, isText, setSymbol, testCase } from "../function/index.js";
|
|
2
|
+
import { getSymbol, isEmpty, isFilledArr, isFilledObj, isObj, isText, setSymbol, testCase, } from "../function/index.js";
|
|
3
3
|
import { FQN } from "../internal.js";
|
|
4
4
|
import { KEY_LITERAL_ALT, KEY_LITERAL_I18N, KEY_LITERAL_NAME } from "../const/index.js";
|
|
5
5
|
const where = `${FQN}.LiteralPool`;
|
|
6
|
-
// noinspection JSUnusedGlobalSymbols
|
|
7
|
-
/**
|
|
8
|
-
* Literal pool for call with name and lazy loading
|
|
9
|
-
* */
|
|
10
6
|
export class LiteralPool extends Inert {
|
|
11
7
|
leyyo;
|
|
12
8
|
constructor(leyyo) {
|
|
13
|
-
super(leyyo,
|
|
9
|
+
super(leyyo, "literal", {});
|
|
14
10
|
this.leyyo = leyyo;
|
|
15
11
|
}
|
|
16
|
-
// region protected
|
|
17
|
-
/** @inheritDoc */
|
|
18
12
|
_getName(lit) {
|
|
19
13
|
return this.getConfigItem(lit)?.name;
|
|
20
14
|
}
|
|
21
|
-
/** @inheritDoc */
|
|
22
15
|
async _nextLoad(item) {
|
|
23
16
|
if (item.target && item.lazyAlt) {
|
|
24
17
|
try {
|
|
@@ -27,12 +20,11 @@ export class LiteralPool extends Inert {
|
|
|
27
20
|
this.setConfigItem(item.target, item);
|
|
28
21
|
}
|
|
29
22
|
catch (e) {
|
|
30
|
-
new this.leyyo.developerError(
|
|
23
|
+
new this.leyyo.developerError("Callback error during loading literal alternate data", testCase(FQN, 186), where).log(e);
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
26
|
delete item.lazyAlt;
|
|
34
27
|
}
|
|
35
|
-
/** @inheritDoc */
|
|
36
28
|
_setName(lit, name) {
|
|
37
29
|
if (isText(name)) {
|
|
38
30
|
setSymbol(lit, KEY_LITERAL_NAME, name);
|
|
@@ -40,7 +32,6 @@ export class LiteralPool extends Inert {
|
|
|
40
32
|
}
|
|
41
33
|
return undefined;
|
|
42
34
|
}
|
|
43
|
-
/** @inheritDoc */
|
|
44
35
|
_afterTargetFound(item) {
|
|
45
36
|
if (item.lazyTarget) {
|
|
46
37
|
delete item.lazyTarget;
|
|
@@ -50,13 +41,9 @@ export class LiteralPool extends Inert {
|
|
|
50
41
|
}
|
|
51
42
|
this.setConfigItem(item.target, item);
|
|
52
43
|
}
|
|
53
|
-
/** @inheritDoc */
|
|
54
44
|
_validate(lit) {
|
|
55
45
|
return isFilledArr(lit);
|
|
56
46
|
}
|
|
57
|
-
// endregion protected
|
|
58
|
-
// region public
|
|
59
|
-
/** @inheritDoc */
|
|
60
47
|
setConfigItem(lit, conf) {
|
|
61
48
|
if (!isObj(conf)) {
|
|
62
49
|
return;
|
|
@@ -71,7 +58,6 @@ export class LiteralPool extends Inert {
|
|
|
71
58
|
setSymbol(lit, KEY_LITERAL_ALT, conf.alt);
|
|
72
59
|
}
|
|
73
60
|
}
|
|
74
|
-
/** @inheritDoc */
|
|
75
61
|
getConfigItem(lit) {
|
|
76
62
|
if (!this._validate(lit)) {
|
|
77
63
|
return undefined;
|
|
@@ -82,7 +68,6 @@ export class LiteralPool extends Inert {
|
|
|
82
68
|
alt: getSymbol(lit, KEY_LITERAL_ALT),
|
|
83
69
|
};
|
|
84
70
|
}
|
|
85
|
-
/** @inheritDoc */
|
|
86
71
|
define(fqn, name, target, opt) {
|
|
87
72
|
this.register({ ...(opt ?? {}), fqn, name, target });
|
|
88
73
|
}
|
|
@@ -4,15 +4,7 @@ import { Opt } from "../function/index.js";
|
|
|
4
4
|
import { ContextFinderLambda, LogCommonLike, LogFormatterLambda, Logger, LogStylerLambda } from "./index.types.js";
|
|
5
5
|
export declare class LogCommon implements LogCommonLike {
|
|
6
6
|
private leyyo;
|
|
7
|
-
/**
|
|
8
|
-
* Loggers
|
|
9
|
-
* */
|
|
10
7
|
private _loggers;
|
|
11
|
-
/**
|
|
12
|
-
* Local console colors
|
|
13
|
-
*
|
|
14
|
-
* @type {LocalColorLike}
|
|
15
|
-
* */
|
|
16
8
|
private _localColor;
|
|
17
9
|
private _logFormatter;
|
|
18
10
|
private _logDeploymentStyler;
|
|
@@ -20,62 +12,16 @@ export declare class LogCommon implements LogCommonLike {
|
|
|
20
12
|
private _logStyler;
|
|
21
13
|
private _contextFinder;
|
|
22
14
|
constructor(leyyo: LeyyoLike);
|
|
23
|
-
/**
|
|
24
|
-
* Set formatter
|
|
25
|
-
*
|
|
26
|
-
* @param {function} fn - lambda for formatter
|
|
27
|
-
* */
|
|
28
15
|
setLogFormatter(fn: LogFormatterLambda): void;
|
|
29
|
-
/**
|
|
30
|
-
* Set deployment styler
|
|
31
|
-
*
|
|
32
|
-
* @param {function} fn - lambda for styler
|
|
33
|
-
* */
|
|
34
16
|
setLogDeploymentStyler(fn: LogStylerLambda): void;
|
|
35
|
-
/**
|
|
36
|
-
* Set local style
|
|
37
|
-
*
|
|
38
|
-
* @param {function} fn - lambda for styler
|
|
39
|
-
* */
|
|
40
17
|
setLogLocalStyler(fn: LogStylerLambda): void;
|
|
41
|
-
/**
|
|
42
|
-
* Set local style
|
|
43
|
-
*
|
|
44
|
-
* @param {function} fn - lambda for styler
|
|
45
|
-
* */
|
|
46
18
|
setContextFinder(fn: ContextFinderLambda): void;
|
|
47
19
|
private _defaults;
|
|
48
|
-
/**
|
|
49
|
-
* Build short style of logger name
|
|
50
|
-
*
|
|
51
|
-
* @param {string} where - original logger name
|
|
52
|
-
* @param {string} - short style
|
|
53
|
-
* */
|
|
54
20
|
private _shortenWhere;
|
|
55
|
-
/**
|
|
56
|
-
* Log consumer
|
|
57
|
-
*
|
|
58
|
-
* @param {LogItem} item
|
|
59
|
-
* */
|
|
60
21
|
private _consumeLog;
|
|
61
|
-
/**
|
|
62
|
-
* Generate random logger name
|
|
63
|
-
*
|
|
64
|
-
* @return {string}
|
|
65
|
-
* */
|
|
66
22
|
private _randomLoggerName;
|
|
67
|
-
/**
|
|
68
|
-
* Check logger name's uniqueness, and loop till unique name
|
|
69
|
-
*
|
|
70
|
-
* @param {string} name - base name
|
|
71
|
-
* @param {number} index - try count
|
|
72
|
-
* @return {string}
|
|
73
|
-
* */
|
|
74
23
|
private _checkLoggerName;
|
|
75
|
-
/** @inheritDoc */
|
|
76
24
|
of(value: ClassLike | Fnc | Obj | string): Logger;
|
|
77
|
-
/** @inheritDoc */
|
|
78
25
|
initConsume(): void;
|
|
79
|
-
/** @inheritDoc */
|
|
80
26
|
emitLog(level: LogLevel, where: string, message: any, params?: any | Opt): void;
|
|
81
27
|
}
|