@leyyo/common 1.3.16 → 1.3.17
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/common/repo.common.js +10 -8
- package/dist/{sys/sys-stat.d.ts → function/get-stat.d.ts} +18 -18
- package/dist/{sys/sys-stat.js → function/get-stat.js} +1 -1
- package/dist/function/index.d.ts +2 -0
- package/dist/function/index.js +2 -0
- package/dist/function/index.types.d.ts +3 -0
- package/dist/function/index.types.js +0 -1
- package/dist/function/load-config.d.ts +22 -0
- package/dist/function/load-config.js +242 -0
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +2 -2
- package/dist/sys/index.d.ts +1 -3
- package/dist/sys/index.js +1 -3
- package/dist/sys/leyyo-storage.d.ts +11 -0
- package/dist/sys/leyyo-storage.js +59 -0
- package/dist/sys/package-json.d.ts +6 -1
- package/dist/sys/package-json.js +14 -4
- package/package.json +3 -1
- package/dist/sys/index.types.d.ts +0 -13
- package/dist/sys/index.types.js +0 -1
- package/dist/sys/leyyo-config.d.ts +0 -2
- package/dist/sys/leyyo-config.js +0 -19
- package/dist/sys/sys-all.d.ts +0 -2
- package/dist/sys/sys-all.js +0 -8
|
@@ -2,10 +2,12 @@ import { FQN } from "../internal.js";
|
|
|
2
2
|
import { isText, testCase } from "../function/index.js";
|
|
3
3
|
import { DeveloperError } from "../error/index.js";
|
|
4
4
|
import { List } from "../class/index.js";
|
|
5
|
+
import { getRootStorage } from "../sys/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* Identifier of file
|
|
7
8
|
* */
|
|
8
9
|
const where = `${FQN}.Repo`;
|
|
10
|
+
const _NAME = '$$leyyo.repo';
|
|
9
11
|
// noinspection JSUnusedGlobalSymbols
|
|
10
12
|
export class RepoCommon {
|
|
11
13
|
leyyo;
|
|
@@ -14,35 +16,35 @@ export class RepoCommon {
|
|
|
14
16
|
/**
|
|
15
17
|
* Internal items which stores arrays
|
|
16
18
|
* */
|
|
17
|
-
_arrayItems = new Map();
|
|
19
|
+
_arrayItems = getRootStorage(_NAME, new Map());
|
|
18
20
|
/**
|
|
19
21
|
* Internal array volatile repo which could be cleared after lifecycle run
|
|
20
22
|
* */
|
|
21
|
-
_arrayVolatiles = new Set();
|
|
23
|
+
_arrayVolatiles = getRootStorage(_NAME, new Set());
|
|
22
24
|
/**
|
|
23
25
|
* Internal items which stores lists
|
|
24
26
|
* */
|
|
25
|
-
_listItems = new Map();
|
|
27
|
+
_listItems = getRootStorage(_NAME, new Map());
|
|
26
28
|
/**
|
|
27
29
|
* Internal list volatiles repo which could be cleared after lifecycle run
|
|
28
30
|
* */
|
|
29
|
-
_listVolatiles = new Set();
|
|
31
|
+
_listVolatiles = getRootStorage(_NAME, new Set());
|
|
30
32
|
/**
|
|
31
33
|
* Internal items which stores maps
|
|
32
34
|
* */
|
|
33
|
-
_mapItems = new Map();
|
|
35
|
+
_mapItems = getRootStorage(_NAME, new Map());
|
|
34
36
|
/**
|
|
35
37
|
* Internal map volatile repo which could be cleared after lifecycle run
|
|
36
38
|
* */
|
|
37
|
-
_mapVolatiles = new Set();
|
|
39
|
+
_mapVolatiles = getRootStorage(_NAME, new Set());
|
|
38
40
|
/**
|
|
39
41
|
* Internal items which stores sets
|
|
40
42
|
* */
|
|
41
|
-
_setItems = new Map();
|
|
43
|
+
_setItems = getRootStorage(_NAME, new Map());
|
|
42
44
|
/**
|
|
43
45
|
* Internal set volatiles repo which could be cleared after lifecycle run
|
|
44
46
|
* */
|
|
45
|
-
_setVolatiles = new Set();
|
|
47
|
+
_setVolatiles = getRootStorage(_NAME, new Set());
|
|
46
48
|
// endregion property
|
|
47
49
|
constructor(leyyo) {
|
|
48
50
|
this.leyyo = leyyo;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export interface
|
|
3
|
-
cpu:
|
|
4
|
-
memory:
|
|
5
|
-
time:
|
|
6
|
-
npm:
|
|
7
|
-
node:
|
|
8
|
-
project:
|
|
9
|
-
os:
|
|
1
|
+
export declare function getStat(): Statistics;
|
|
2
|
+
export interface Statistics {
|
|
3
|
+
cpu: StatisticsCpu;
|
|
4
|
+
memory: StatisticsMemory;
|
|
5
|
+
time: StatisticsTime;
|
|
6
|
+
npm: StatisticsNpm;
|
|
7
|
+
node: StatisticsNode;
|
|
8
|
+
project: StatisticsProject;
|
|
9
|
+
os: StatisticsOs;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
11
|
+
export interface StatisticsCpu {
|
|
12
12
|
user: number;
|
|
13
13
|
system: number;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
15
|
+
export interface StatisticsTime {
|
|
16
16
|
uptime: number;
|
|
17
17
|
startedAt: number;
|
|
18
18
|
}
|
|
19
|
-
export interface
|
|
19
|
+
export interface StatisticsNpm {
|
|
20
20
|
pwd: string;
|
|
21
21
|
version: string;
|
|
22
22
|
}
|
|
23
|
-
export interface
|
|
23
|
+
export interface StatisticsNode {
|
|
24
24
|
type: string;
|
|
25
25
|
version: string;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
27
|
+
export interface StatisticsProject {
|
|
28
28
|
name: string;
|
|
29
29
|
version: string;
|
|
30
30
|
environment: string;
|
|
31
31
|
log: string;
|
|
32
32
|
}
|
|
33
|
-
export interface
|
|
33
|
+
export interface StatisticsOs {
|
|
34
34
|
version: string;
|
|
35
35
|
arch: string;
|
|
36
36
|
platform: string;
|
|
37
37
|
machineType: string;
|
|
38
38
|
network: Record<string, unknown>;
|
|
39
|
-
cpu: Array<
|
|
39
|
+
cpu: Array<StatisticsCpuInfo>;
|
|
40
40
|
}
|
|
41
|
-
export interface
|
|
41
|
+
export interface StatisticsMemory {
|
|
42
42
|
/**
|
|
43
43
|
* Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the
|
|
44
44
|
* process, including all C++ and JavaScript objects and code.
|
|
@@ -60,7 +60,7 @@ export interface SysStatMemory {
|
|
|
60
60
|
*/
|
|
61
61
|
arrayBuffers: number;
|
|
62
62
|
}
|
|
63
|
-
export interface
|
|
63
|
+
export interface StatisticsCpuInfo {
|
|
64
64
|
model: string;
|
|
65
65
|
speed: number;
|
|
66
66
|
times: {
|
package/dist/function/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './delete-prop.js';
|
|
|
5
5
|
export * from './empty-fn.js';
|
|
6
6
|
export * from './extended-type.js';
|
|
7
7
|
export * from './get-fqn.js';
|
|
8
|
+
export * from './get-stat.js';
|
|
8
9
|
export * from './set-fqn.js';
|
|
9
10
|
export * from './remove-fqn.js';
|
|
10
11
|
export * from './on-fqn-set.js';
|
|
@@ -19,6 +20,7 @@ export * from './is-obj.js';
|
|
|
19
20
|
export * from './is-text.js';
|
|
20
21
|
export * from './is-anonymous-name.js';
|
|
21
22
|
export * from './jitter-interval.js';
|
|
23
|
+
export * from './load-config.js';
|
|
22
24
|
export * from './stamp-loader.js';
|
|
23
25
|
export * from './one-or-more.js';
|
|
24
26
|
export * from './opt-add.js';
|
package/dist/function/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './delete-prop.js';
|
|
|
5
5
|
export * from './empty-fn.js';
|
|
6
6
|
export * from './extended-type.js';
|
|
7
7
|
export * from './get-fqn.js';
|
|
8
|
+
export * from './get-stat.js';
|
|
8
9
|
export * from './set-fqn.js';
|
|
9
10
|
export * from './remove-fqn.js';
|
|
10
11
|
export * from './on-fqn-set.js';
|
|
@@ -19,6 +20,7 @@ export * from './is-obj.js';
|
|
|
19
20
|
export * from './is-text.js';
|
|
20
21
|
export * from './is-anonymous-name.js';
|
|
21
22
|
export * from './jitter-interval.js';
|
|
23
|
+
export * from './load-config.js';
|
|
22
24
|
export * from './stamp-loader.js';
|
|
23
25
|
export * from './one-or-more.js';
|
|
24
26
|
export * from './opt-add.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LeyyoConfig } from "./index.types.js";
|
|
2
|
+
export declare const leyyoConfig: LeyyoConfig;
|
|
3
|
+
/**
|
|
4
|
+
* Load config from `.leyyo.yaml` file
|
|
5
|
+
*
|
|
6
|
+
* `OBJECT` postfixes:
|
|
7
|
+
* - !: only override (`don't merge`)
|
|
8
|
+
* - ?: only merge (`don't override`)
|
|
9
|
+
* - <empty>: only set if key is absent
|
|
10
|
+
*
|
|
11
|
+
* `ARRAY` postfixes:
|
|
12
|
+
* - !: only override (`don't merge`)
|
|
13
|
+
* - ?: only merge (`don't override`)
|
|
14
|
+
* - <empty>: only set if key is absent
|
|
15
|
+
*
|
|
16
|
+
* Generics:
|
|
17
|
+
* - `C`- config model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @return {LeyyoConfig}
|
|
21
|
+
* */
|
|
22
|
+
export declare function loadConfig(url: string): LeyyoConfig;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import * as yaml from 'js-yaml';
|
|
6
|
+
import { isObj } from "./is-obj.js";
|
|
7
|
+
import { getRootStorage } from "../sys/index.js";
|
|
8
|
+
import { isText } from "./is-text.js";
|
|
9
|
+
import { isEmpty } from "./is-empty.js";
|
|
10
|
+
import { secureJson, secureObject } from "./secure-json.js";
|
|
11
|
+
const _NAME = '$$leyyo.config';
|
|
12
|
+
export const leyyoConfig = getRootStorage(_NAME, {});
|
|
13
|
+
/**
|
|
14
|
+
* Load config from `.leyyo.yaml` file
|
|
15
|
+
*
|
|
16
|
+
* `OBJECT` postfixes:
|
|
17
|
+
* - !: only override (`don't merge`)
|
|
18
|
+
* - ?: only merge (`don't override`)
|
|
19
|
+
* - <empty>: only set if key is absent
|
|
20
|
+
*
|
|
21
|
+
* `ARRAY` postfixes:
|
|
22
|
+
* - !: only override (`don't merge`)
|
|
23
|
+
* - ?: only merge (`don't override`)
|
|
24
|
+
* - <empty>: only set if key is absent
|
|
25
|
+
*
|
|
26
|
+
* Generics:
|
|
27
|
+
* - `C`- config model
|
|
28
|
+
*
|
|
29
|
+
* @param {string} url
|
|
30
|
+
* @return {LeyyoConfig}
|
|
31
|
+
* */
|
|
32
|
+
export function loadConfig(url) {
|
|
33
|
+
try {
|
|
34
|
+
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
35
|
+
const yamlPath = path.normalize(__dirname + '/.leyyo.yaml');
|
|
36
|
+
if (fs.existsSync(yamlPath)) {
|
|
37
|
+
const input = fs.readFileSync(yamlPath, 'utf8');
|
|
38
|
+
const data = yaml.load(input);
|
|
39
|
+
if (isObj(data)) {
|
|
40
|
+
for (const [k, v] of Object.entries(data)) {
|
|
41
|
+
_object(leyyoConfig, k, v);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return leyyoConfig;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error(`[leyyoConfig] ${e.name} => ${e.message}`);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get key behaviour
|
|
54
|
+
* @param {string} keyFull - key
|
|
55
|
+
* @return {Array} - tuple as `[behaviour, key]`
|
|
56
|
+
* */
|
|
57
|
+
function _behaviour(keyFull) {
|
|
58
|
+
if (!isText(keyFull)) {
|
|
59
|
+
return [undefined, undefined];
|
|
60
|
+
}
|
|
61
|
+
if (keyFull.endsWith('!')) {
|
|
62
|
+
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
63
|
+
if (!isText(keyFull)) {
|
|
64
|
+
return [undefined, undefined];
|
|
65
|
+
}
|
|
66
|
+
return ['override', keyFull];
|
|
67
|
+
}
|
|
68
|
+
else if (keyFull.endsWith('?')) {
|
|
69
|
+
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
70
|
+
if (!isText(keyFull)) {
|
|
71
|
+
return [undefined, undefined];
|
|
72
|
+
}
|
|
73
|
+
return ['merge', keyFull];
|
|
74
|
+
}
|
|
75
|
+
return [undefined, keyFull];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Merge array
|
|
79
|
+
*
|
|
80
|
+
* @param {Array} source
|
|
81
|
+
* @param {string} key
|
|
82
|
+
* @param {Array} value
|
|
83
|
+
* */
|
|
84
|
+
function _array(source, key, value) {
|
|
85
|
+
value.forEach((item, index) => {
|
|
86
|
+
if (isEmpty(item)) {
|
|
87
|
+
console.warn(`[leyyoConfig] value empty at (${key}#${index})`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const clonedSource = source.map(item => JSON.stringify(item));
|
|
91
|
+
switch (typeof item) {
|
|
92
|
+
case "string":
|
|
93
|
+
case "number":
|
|
94
|
+
case "boolean":
|
|
95
|
+
if (!clonedSource.includes(JSON.stringify(item))) {
|
|
96
|
+
source.push(item);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case "object":
|
|
100
|
+
if (!clonedSource.includes(secureJson(item))) {
|
|
101
|
+
source.push(secureObject(item));
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "undefined":
|
|
105
|
+
case "bigint":
|
|
106
|
+
case "symbol":
|
|
107
|
+
case "function":
|
|
108
|
+
console.warn(`[leyyoConfig] type is not allowed at (${key}#${index})`);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Merge object
|
|
115
|
+
*
|
|
116
|
+
* @param {object} source
|
|
117
|
+
* @param {string} keyFull - key
|
|
118
|
+
* @param {any} value
|
|
119
|
+
* */
|
|
120
|
+
function _object(source, keyFull, value) {
|
|
121
|
+
if (isEmpty(value)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const [behaviour, key] = _behaviour(keyFull);
|
|
125
|
+
if (!key) {
|
|
126
|
+
console.warn(`[leyyoConfig] key empty at (${keyFull})`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (!source) {
|
|
130
|
+
source = {};
|
|
131
|
+
}
|
|
132
|
+
// old is empty
|
|
133
|
+
if (isEmpty(source[key])) {
|
|
134
|
+
switch (typeof value) {
|
|
135
|
+
case "string":
|
|
136
|
+
case "number":
|
|
137
|
+
case "boolean":
|
|
138
|
+
source[key] = value;
|
|
139
|
+
break;
|
|
140
|
+
case "object":
|
|
141
|
+
source[key] = secureObject(value);
|
|
142
|
+
break;
|
|
143
|
+
case "function":
|
|
144
|
+
case "symbol":
|
|
145
|
+
case "bigint":
|
|
146
|
+
case "undefined":
|
|
147
|
+
console.warn(`[leyyoConfig] type is not allowed at (${key})`);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
switch (typeof value) {
|
|
153
|
+
case "string":
|
|
154
|
+
case "number":
|
|
155
|
+
case "boolean":
|
|
156
|
+
switch (behaviour) {
|
|
157
|
+
case "override":
|
|
158
|
+
source[key] = value;
|
|
159
|
+
break;
|
|
160
|
+
default: // merge
|
|
161
|
+
if (isEmpty(source[key])) {
|
|
162
|
+
source[key] = value;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
case "object":
|
|
168
|
+
// new is an array
|
|
169
|
+
if (Array.isArray(value)) {
|
|
170
|
+
// old is an array (BOTH)
|
|
171
|
+
if (Array.isArray(source[key])) {
|
|
172
|
+
switch (behaviour) {
|
|
173
|
+
case "override":
|
|
174
|
+
source[key] = secureObject(value);
|
|
175
|
+
break;
|
|
176
|
+
case "merge":
|
|
177
|
+
_array(source[key], key, value);
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
// old exists, ignore
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// CONFLICT: old is not array
|
|
185
|
+
else {
|
|
186
|
+
switch (behaviour) {
|
|
187
|
+
case "override":
|
|
188
|
+
source[key] = secureObject(value);
|
|
189
|
+
break;
|
|
190
|
+
case "merge":
|
|
191
|
+
// old is different, conflict
|
|
192
|
+
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
// old exists, ignore
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// new is an object
|
|
201
|
+
else {
|
|
202
|
+
// CONFLICT: old is not object
|
|
203
|
+
if (Array.isArray(source[key])) {
|
|
204
|
+
switch (behaviour) {
|
|
205
|
+
case "override":
|
|
206
|
+
source[key] = value;
|
|
207
|
+
break;
|
|
208
|
+
case "merge":
|
|
209
|
+
// old is different, conflict
|
|
210
|
+
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
211
|
+
break;
|
|
212
|
+
default:
|
|
213
|
+
// old exists, ignore
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// old is an object (BOTH)
|
|
218
|
+
else {
|
|
219
|
+
switch (behaviour) {
|
|
220
|
+
case "override":
|
|
221
|
+
source[key] = value;
|
|
222
|
+
break;
|
|
223
|
+
case "merge":
|
|
224
|
+
for (const [k, v] of Object.entries(value)) {
|
|
225
|
+
_object(source[key], k, v);
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
// old exists, ignore
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case "function":
|
|
236
|
+
case "symbol":
|
|
237
|
+
case "bigint":
|
|
238
|
+
case "undefined":
|
|
239
|
+
console.warn(`[leyyoConfig] type is not allowed at (${key})`);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const NME: string, FQN: string, VER: string
|
|
1
|
+
export declare const NME: string, FQN: string, VER: string;
|
package/dist/internal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const {
|
|
1
|
+
import { packageJson } from "./sys/index.js";
|
|
2
|
+
export const { name: NME, fqn: FQN, version: VER } = packageJson(import.meta.url);
|
package/dist/sys/index.d.ts
CHANGED
package/dist/sys/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type LeyyoStorage = Map<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* Local storage for leyyo platform
|
|
4
|
+
* */
|
|
5
|
+
export declare const leyyoStorage: LeyyoStorage;
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} name - name of storage
|
|
8
|
+
* @param {any} def - initial value
|
|
9
|
+
* */
|
|
10
|
+
export declare function getRootStorage<T>(name: string, def: T): T;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const _NAME = '$$leyyo.packages';
|
|
2
|
+
/**
|
|
3
|
+
* Create a standalone storage
|
|
4
|
+
*
|
|
5
|
+
* @return {LeyyoStorage}
|
|
6
|
+
* */
|
|
7
|
+
function _new() {
|
|
8
|
+
return new Map();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get a global storage
|
|
12
|
+
*
|
|
13
|
+
* @param {any} source - `global` or `globalThis`
|
|
14
|
+
* @return {LeyyoStorage}
|
|
15
|
+
* */
|
|
16
|
+
function _get(source) {
|
|
17
|
+
if (!source) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (source[_NAME] && source[_NAME] instanceof Map) {
|
|
21
|
+
return source[_NAME];
|
|
22
|
+
}
|
|
23
|
+
source[_NAME] = _new();
|
|
24
|
+
return source[_NAME];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build storage
|
|
28
|
+
*
|
|
29
|
+
* @return {LeyyoStorage}
|
|
30
|
+
* */
|
|
31
|
+
function _build() {
|
|
32
|
+
try {
|
|
33
|
+
return _get(globalThis) ?? _get(global) ?? _new();
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
return _new();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Local storage for leyyo platform
|
|
41
|
+
* */
|
|
42
|
+
export const leyyoStorage = _build();
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} name - name of storage
|
|
45
|
+
* @param {any} def - initial value
|
|
46
|
+
* */
|
|
47
|
+
export function getRootStorage(name, def) {
|
|
48
|
+
if (typeof name !== 'string') {
|
|
49
|
+
throw new Error('Invalid storage name', name);
|
|
50
|
+
}
|
|
51
|
+
if (leyyoStorage.has(name)) {
|
|
52
|
+
return leyyoStorage.get(name);
|
|
53
|
+
}
|
|
54
|
+
if (!def || typeof def !== 'object') {
|
|
55
|
+
throw new Error('Invalid storage value', def);
|
|
56
|
+
}
|
|
57
|
+
leyyoStorage.set(name, def);
|
|
58
|
+
return def;
|
|
59
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export interface PackageJson {
|
|
2
|
+
fqn: string;
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
[k: string]: unknown;
|
|
6
|
+
}
|
|
2
7
|
export declare function packageJson<P extends PackageJson = PackageJson>(url: string): P;
|
|
3
8
|
export declare function packageJson<P extends PackageJson = PackageJson>(url: string, full: true): P;
|
package/dist/sys/package-json.js
CHANGED
|
@@ -2,8 +2,10 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { dirname } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
+
import { getRootStorage } from "./leyyo-storage.js";
|
|
6
|
+
const _NAME = '$$leyyo.packages';
|
|
5
7
|
const _empty = { fqn: 'leyyo.unknown', name: '@leyyo/unknown', version: '0.0.0' };
|
|
6
|
-
const _map = new Map();
|
|
8
|
+
const _map = getRootStorage(_NAME, new Map());
|
|
7
9
|
export function packageJson(url, full) {
|
|
8
10
|
try {
|
|
9
11
|
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
@@ -17,9 +19,17 @@ export function packageJson(url, full) {
|
|
|
17
19
|
const name = jsonData.name;
|
|
18
20
|
const version = jsonData.version;
|
|
19
21
|
if (_map.has(name)) {
|
|
20
|
-
|
|
22
|
+
if (Array.isArray(_map.get(name))) {
|
|
23
|
+
console.warn(`Same package[${name}] duplicated, current: ${version}, previous versions: ${JSON.stringify(_map.get(name))}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
_map.set(name, []);
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
|
-
|
|
29
|
+
else {
|
|
30
|
+
_map.set(name, []);
|
|
31
|
+
}
|
|
32
|
+
_map.get(name).push(version);
|
|
23
33
|
const fqn = jsonData?.name.split('/').join('.').split('@').join('');
|
|
24
34
|
if (full) {
|
|
25
35
|
return { ...jsonData, fqn };
|
|
@@ -33,7 +43,7 @@ export function packageJson(url, full) {
|
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
45
|
catch (e) {
|
|
36
|
-
console.
|
|
46
|
+
console.error(`[packageJson] ${e.name} => ${e.message}`);
|
|
37
47
|
return _empty;
|
|
38
48
|
}
|
|
39
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leyyo/common",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.17",
|
|
4
4
|
"description": "Leyyo common library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@types/jest": "^30.0.0",
|
|
40
40
|
"@types/js-yaml": "^4.0.9",
|
|
41
41
|
"@types/node": "^24.2.1",
|
|
42
|
+
"@types/node-localstorage": "^1.3.3",
|
|
42
43
|
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
43
44
|
"@typescript-eslint/parser": "^8.39.1",
|
|
44
45
|
"eslint": "^9.33.0",
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
},
|
|
65
66
|
"dependencies": {
|
|
66
67
|
"js-yaml": "^4.1.1",
|
|
68
|
+
"node-localstorage": "^3.0.5",
|
|
67
69
|
"stacktrace-parser": "^0.1.11"
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface PackageJson {
|
|
2
|
-
fqn: string;
|
|
3
|
-
name: string;
|
|
4
|
-
version: string;
|
|
5
|
-
[k: string]: unknown;
|
|
6
|
-
}
|
|
7
|
-
export interface LeyyoConfig {
|
|
8
|
-
[fqn: string]: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
export interface LeyyoSysAll<C extends LeyyoConfig = LeyyoConfig, P extends PackageJson = PackageJson> {
|
|
11
|
-
config: C;
|
|
12
|
-
pck: P;
|
|
13
|
-
}
|
package/dist/sys/index.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/sys/leyyo-config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { dirname } from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
import * as yaml from 'js-yaml';
|
|
6
|
-
export function leyyoConfig(url) {
|
|
7
|
-
try {
|
|
8
|
-
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
9
|
-
const yamlPath = path.normalize(__dirname + '/.leyyo.yaml');
|
|
10
|
-
if (fs.existsSync(yamlPath)) {
|
|
11
|
-
const input = fs.readFileSync(yamlPath, 'utf8');
|
|
12
|
-
return yaml.load(input);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
console.log(`[leyyoConfig] ${e.name} => ${e.message}`);
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/sys/sys-all.d.ts
DELETED