@oxog/utils 1.0.1 → 1.1.0
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/CHANGELOG.md +34 -0
- package/README.md +56 -43
- package/dist/chunk-25WW2FCA.js +34 -0
- package/dist/chunk-25WW2FCA.js.map +1 -0
- package/dist/chunk-DEVWOLUI.cjs +112 -0
- package/dist/chunk-DEVWOLUI.cjs.map +1 -0
- package/dist/chunk-IUDFQZIP.js +99 -0
- package/dist/chunk-IUDFQZIP.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-SWG777R6.cjs +40 -0
- package/dist/chunk-SWG777R6.cjs.map +1 -0
- package/dist/index.cjs +210 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -11
- package/dist/index.d.ts +32 -11
- package/dist/index.js +156 -221
- package/dist/index.js.map +1 -1
- package/dist/plugins/async.cjs +90 -107
- package/dist/plugins/async.cjs.map +1 -1
- package/dist/plugins/async.d.cts +19 -6
- package/dist/plugins/async.d.ts +19 -6
- package/dist/plugins/async.js +89 -106
- package/dist/plugins/async.js.map +1 -1
- package/dist/plugins/deep.cjs +183 -59
- package/dist/plugins/deep.cjs.map +1 -1
- package/dist/plugins/deep.d.cts +25 -7
- package/dist/plugins/deep.d.ts +25 -7
- package/dist/plugins/deep.js +183 -59
- package/dist/plugins/deep.js.map +1 -1
- package/dist/plugins/guard.cjs +2 -0
- package/dist/plugins/guard.cjs.map +1 -1
- package/dist/plugins/guard.js +2 -0
- package/dist/plugins/guard.js.map +1 -1
- package/dist/plugins/transform.cjs +6 -3
- package/dist/plugins/transform.cjs.map +1 -1
- package/dist/plugins/transform.js +6 -3
- package/dist/plugins/transform.js.map +1 -1
- package/dist/{types-XmRC5wYO.d.cts → types-B-i5UbJo.d.cts} +24 -7
- package/dist/{types-XmRC5wYO.d.ts → types-B-i5UbJo.d.ts} +24 -7
- package/package.json +15 -10
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
-
};
|
|
3
|
+
var chunkDEVWOLUI_cjs = require('./chunk-DEVWOLUI.cjs');
|
|
4
|
+
var chunkSWG777R6_cjs = require('./chunk-SWG777R6.cjs');
|
|
5
|
+
var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
|
|
8
6
|
|
|
9
7
|
// src/plugins/core/object.ts
|
|
10
8
|
var object_exports = {};
|
|
11
|
-
__export(object_exports, {
|
|
9
|
+
chunkQ7SFCCGT_cjs.__export(object_exports, {
|
|
12
10
|
entries: () => entries,
|
|
13
11
|
fromEntries: () => fromEntries,
|
|
14
12
|
get: () => get,
|
|
@@ -25,12 +23,14 @@ function get(obj, path, defaultValue) {
|
|
|
25
23
|
if (obj == null) {
|
|
26
24
|
return defaultValue;
|
|
27
25
|
}
|
|
28
|
-
const keys2 = path.toString().split(/[\.\[]/g).map((k) => k.replace(/[\]']/g, "")).filter((k) => k !== "");
|
|
29
26
|
let result = obj;
|
|
30
|
-
for (const key of
|
|
27
|
+
for (const { key } of chunkSWG777R6_cjs.parsePath(path)) {
|
|
31
28
|
if (result == null) {
|
|
32
29
|
return defaultValue;
|
|
33
30
|
}
|
|
31
|
+
if (chunkSWG777R6_cjs.UNSAFE_KEYS.has(key) && !chunkSWG777R6_cjs.hasOwn(Object(result), key)) {
|
|
32
|
+
return defaultValue;
|
|
33
|
+
}
|
|
34
34
|
result = result[key];
|
|
35
35
|
}
|
|
36
36
|
if (typeof result === "function") {
|
|
@@ -42,35 +42,24 @@ function set(obj, path, value) {
|
|
|
42
42
|
if (obj == null || typeof obj !== "object") {
|
|
43
43
|
return obj;
|
|
44
44
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (Array.isArray(arrayValue)) {
|
|
59
|
-
return {
|
|
60
|
-
...current,
|
|
61
|
-
[arrayPath]: [
|
|
62
|
-
...arrayValue.slice(0, arrayIndex),
|
|
63
|
-
value,
|
|
64
|
-
...arrayValue.slice(arrayIndex + 1)
|
|
65
|
-
]
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return { ...current, [key]: value };
|
|
45
|
+
const segments = chunkSWG777R6_cjs.parsePath(path);
|
|
46
|
+
if (segments.length === 0) {
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
if (chunkSWG777R6_cjs.hasUnsafeSegment(segments)) {
|
|
50
|
+
throw new chunkDEVWOLUI_cjs.InvalidPathError(String(path));
|
|
51
|
+
}
|
|
52
|
+
const deepSet = (current, index) => {
|
|
53
|
+
const { key } = segments[index];
|
|
54
|
+
const copy = Array.isArray(current) ? current.slice() : { ...current };
|
|
55
|
+
if (index === segments.length - 1) {
|
|
56
|
+
copy[key] = value;
|
|
57
|
+
return copy;
|
|
70
58
|
}
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
59
|
+
const next = current[key];
|
|
60
|
+
const child = next != null && typeof next === "object" ? next : segments[index + 1].index ? [] : {};
|
|
61
|
+
copy[key] = deepSet(child, index + 1);
|
|
62
|
+
return copy;
|
|
74
63
|
};
|
|
75
64
|
return deepSet(obj, 0);
|
|
76
65
|
}
|
|
@@ -78,29 +67,31 @@ function setMut(obj, path, value) {
|
|
|
78
67
|
if (obj == null || typeof obj !== "object") {
|
|
79
68
|
return obj;
|
|
80
69
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
70
|
+
const segments = chunkSWG777R6_cjs.parsePath(path);
|
|
71
|
+
if (segments.length === 0) {
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
74
|
+
if (chunkSWG777R6_cjs.hasUnsafeSegment(segments)) {
|
|
75
|
+
throw new chunkDEVWOLUI_cjs.InvalidPathError(String(path));
|
|
76
|
+
}
|
|
77
|
+
let current = obj;
|
|
78
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
79
|
+
const { key } = segments[i];
|
|
80
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
81
|
+
current[key] = segments[i + 1].index ? [] : {};
|
|
87
82
|
}
|
|
88
|
-
|
|
83
|
+
current = current[key];
|
|
89
84
|
}
|
|
90
|
-
|
|
85
|
+
current[segments[segments.length - 1].key] = value;
|
|
91
86
|
return obj;
|
|
92
87
|
}
|
|
93
88
|
function has(obj, path) {
|
|
94
89
|
if (obj == null) {
|
|
95
90
|
return false;
|
|
96
91
|
}
|
|
97
|
-
const keys2 = path.toString().split(/[\.\[]/g).map((k) => k.replace(/[\]']/g, "")).filter((k) => k !== "");
|
|
98
92
|
let result = obj;
|
|
99
|
-
for (const key of
|
|
100
|
-
if (
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
if (result == null || !(key in result)) {
|
|
93
|
+
for (const { key } of chunkSWG777R6_cjs.parsePath(path)) {
|
|
94
|
+
if (result == null || !chunkSWG777R6_cjs.hasOwn(Object(result), key)) {
|
|
104
95
|
return false;
|
|
105
96
|
}
|
|
106
97
|
result = result[key];
|
|
@@ -111,7 +102,7 @@ function pick(obj, keys2) {
|
|
|
111
102
|
const result = {};
|
|
112
103
|
for (const key of keys2) {
|
|
113
104
|
if (key in obj) {
|
|
114
|
-
result
|
|
105
|
+
chunkSWG777R6_cjs.assignOwn(result, key, obj[key]);
|
|
115
106
|
}
|
|
116
107
|
}
|
|
117
108
|
return result;
|
|
@@ -124,11 +115,11 @@ function omit(obj, keys2) {
|
|
|
124
115
|
return result;
|
|
125
116
|
}
|
|
126
117
|
function merge(target, ...sources) {
|
|
127
|
-
const DANGEROUS_KEYS = ["__proto__", "constructor", "prototype"];
|
|
128
118
|
const result = { ...target };
|
|
129
119
|
for (const source of sources) {
|
|
120
|
+
if (source == null) continue;
|
|
130
121
|
for (const key of Object.keys(source)) {
|
|
131
|
-
if (
|
|
122
|
+
if (chunkSWG777R6_cjs.UNSAFE_KEYS.has(key)) continue;
|
|
132
123
|
result[key] = source[key];
|
|
133
124
|
}
|
|
134
125
|
}
|
|
@@ -149,7 +140,7 @@ function fromEntries(entries2) {
|
|
|
149
140
|
|
|
150
141
|
// src/plugins/core/array.ts
|
|
151
142
|
var array_exports = {};
|
|
152
|
-
__export(array_exports, {
|
|
143
|
+
chunkQ7SFCCGT_cjs.__export(array_exports, {
|
|
153
144
|
chunk: () => chunk,
|
|
154
145
|
compact: () => compact,
|
|
155
146
|
first: () => first,
|
|
@@ -165,10 +156,11 @@ function groupBy(arr, key) {
|
|
|
165
156
|
const result = {};
|
|
166
157
|
for (const item of arr) {
|
|
167
158
|
const groupKey = typeof key === "function" ? key(item) : String(item[key]);
|
|
168
|
-
if (
|
|
169
|
-
result[groupKey]
|
|
159
|
+
if (chunkSWG777R6_cjs.hasOwn(result, groupKey)) {
|
|
160
|
+
result[groupKey].push(item);
|
|
161
|
+
} else {
|
|
162
|
+
chunkSWG777R6_cjs.assignOwn(result, groupKey, [item]);
|
|
170
163
|
}
|
|
171
|
-
result[groupKey].push(item);
|
|
172
164
|
}
|
|
173
165
|
return result;
|
|
174
166
|
}
|
|
@@ -176,12 +168,16 @@ function keyBy(arr, key) {
|
|
|
176
168
|
const result = {};
|
|
177
169
|
for (const item of arr) {
|
|
178
170
|
const keyValue = typeof key === "function" ? key(item) : String(item[key]);
|
|
179
|
-
result
|
|
171
|
+
chunkSWG777R6_cjs.assignOwn(result, keyValue, item);
|
|
180
172
|
}
|
|
181
173
|
return result;
|
|
182
174
|
}
|
|
183
175
|
function chunk(arr, size) {
|
|
184
176
|
const result = [];
|
|
177
|
+
size = Math.trunc(size);
|
|
178
|
+
if (!(size >= 1)) {
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
185
181
|
for (let i = 0; i < arr.length; i += size) {
|
|
186
182
|
result.push(arr.slice(i, i + size));
|
|
187
183
|
}
|
|
@@ -217,18 +213,19 @@ function compact(arr) {
|
|
|
217
213
|
return arr.filter(Boolean);
|
|
218
214
|
}
|
|
219
215
|
function first(arr, n = 1) {
|
|
220
|
-
if (arr.length === 0) return void 0;
|
|
221
216
|
if (n === 1) return arr[0];
|
|
222
|
-
|
|
223
|
-
return
|
|
217
|
+
if (arr.length === 0) return void 0;
|
|
218
|
+
return arr.slice(0, Math.max(0, Math.trunc(n) || 0));
|
|
224
219
|
}
|
|
225
220
|
function last(arr, n = 1) {
|
|
226
|
-
if (arr.length === 0) return void 0;
|
|
227
221
|
if (n === 1) return arr[arr.length - 1];
|
|
228
|
-
|
|
222
|
+
if (arr.length === 0) return void 0;
|
|
223
|
+
const count = Math.max(0, Math.trunc(n) || 0);
|
|
224
|
+
return count === 0 ? [] : arr.slice(-count);
|
|
229
225
|
}
|
|
230
226
|
function sample(arr, n = 1) {
|
|
231
|
-
|
|
227
|
+
n = Math.max(0, Math.trunc(n) || 0);
|
|
228
|
+
if (arr.length === 0 || n === 0) return [];
|
|
232
229
|
if (n >= arr.length) return [...arr];
|
|
233
230
|
const shuffled = [...arr];
|
|
234
231
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
|
@@ -240,7 +237,7 @@ function sample(arr, n = 1) {
|
|
|
240
237
|
|
|
241
238
|
// src/plugins/core/string.ts
|
|
242
239
|
var string_exports = {};
|
|
243
|
-
__export(string_exports, {
|
|
240
|
+
chunkQ7SFCCGT_cjs.__export(string_exports, {
|
|
244
241
|
camelCase: () => camelCase,
|
|
245
242
|
capitalize: () => capitalize,
|
|
246
243
|
kebabCase: () => kebabCase,
|
|
@@ -270,91 +267,99 @@ function capitalize(str) {
|
|
|
270
267
|
}
|
|
271
268
|
function truncate(str, length, suffix = "...") {
|
|
272
269
|
if (str.length <= length) return str;
|
|
273
|
-
|
|
270
|
+
let end = Math.max(0, Math.trunc(length) || 0);
|
|
271
|
+
if (end > 0 && isHighSurrogate(str.charCodeAt(end - 1)) && isLowSurrogate(str.charCodeAt(end))) {
|
|
272
|
+
end--;
|
|
273
|
+
}
|
|
274
|
+
return str.slice(0, end) + suffix;
|
|
274
275
|
}
|
|
276
|
+
var isHighSurrogate = (code) => code >= 55296 && code <= 56319;
|
|
277
|
+
var isLowSurrogate = (code) => code >= 56320 && code <= 57343;
|
|
275
278
|
function slugify(str) {
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
"\u011F": "g",
|
|
283
|
-
"\u011E": "g",
|
|
284
|
-
"\xFC": "u",
|
|
285
|
-
"\xDC": "u",
|
|
286
|
-
"\xF6": "o",
|
|
287
|
-
"\xD6": "o",
|
|
288
|
-
"\xE7": "c",
|
|
289
|
-
"\xC7": "c",
|
|
290
|
-
// Russian (Cyrillic to Latin - basic transliteration)
|
|
291
|
-
"\u0430": "a",
|
|
292
|
-
"\u0431": "b",
|
|
293
|
-
"\u0432": "v",
|
|
294
|
-
"\u0433": "g",
|
|
295
|
-
"\u0434": "d",
|
|
296
|
-
"\u0435": "e",
|
|
297
|
-
"\u0451": "yo",
|
|
298
|
-
"\u0436": "zh",
|
|
299
|
-
"\u0437": "z",
|
|
300
|
-
"\u0438": "i",
|
|
301
|
-
"\u0439": "y",
|
|
302
|
-
"\u043A": "k",
|
|
303
|
-
"\u043B": "l",
|
|
304
|
-
"\u043C": "m",
|
|
305
|
-
"\u043D": "n",
|
|
306
|
-
"\u043E": "o",
|
|
307
|
-
"\u043F": "p",
|
|
308
|
-
"\u0440": "r",
|
|
309
|
-
"\u0441": "s",
|
|
310
|
-
"\u0442": "t",
|
|
311
|
-
"\u0443": "u",
|
|
312
|
-
"\u0444": "f",
|
|
313
|
-
"\u0445": "h",
|
|
314
|
-
"\u0446": "ts",
|
|
315
|
-
"\u0447": "ch",
|
|
316
|
-
"\u0448": "sh",
|
|
317
|
-
"\u0449": "shch",
|
|
318
|
-
"\u044A": "",
|
|
319
|
-
"\u044B": "y",
|
|
320
|
-
"\u044C": "",
|
|
321
|
-
"\u044D": "e",
|
|
322
|
-
"\u044E": "yu",
|
|
323
|
-
"\u044F": "ya",
|
|
324
|
-
// Greek (basic)
|
|
325
|
-
"\u03B1": "a",
|
|
326
|
-
"\u03B2": "b",
|
|
327
|
-
"\u03B3": "g",
|
|
328
|
-
"\u03B4": "d",
|
|
329
|
-
"\u03B5": "e",
|
|
330
|
-
"\u03B6": "z",
|
|
331
|
-
"\u03B7": "i",
|
|
332
|
-
"\u03B8": "th",
|
|
333
|
-
"\u03B9": "i",
|
|
334
|
-
"\u03BA": "k",
|
|
335
|
-
"\u03BB": "l",
|
|
336
|
-
"\u03BC": "m",
|
|
337
|
-
"\u03BD": "n",
|
|
338
|
-
"\u03BE": "x",
|
|
339
|
-
"\u03BF": "o",
|
|
340
|
-
"\u03C0": "p",
|
|
341
|
-
"\u03C1": "r",
|
|
342
|
-
"\u03C3": "s",
|
|
343
|
-
"\u03C4": "t",
|
|
344
|
-
"\u03C5": "y",
|
|
345
|
-
"\u03C6": "f",
|
|
346
|
-
"\u03C7": "ch",
|
|
347
|
-
"\u03C8": "ps",
|
|
348
|
-
"\u03C9": "o"
|
|
279
|
+
const transliterate = (input) => {
|
|
280
|
+
let out = "";
|
|
281
|
+
for (const char of input) {
|
|
282
|
+
out += chunkSWG777R6_cjs.hasOwn(SLUG_CHAR_MAP, char) ? SLUG_CHAR_MAP[char] : char;
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
349
285
|
};
|
|
350
|
-
return
|
|
286
|
+
return transliterate(transliterate(str.toLowerCase()).normalize("NFD").replace(/[\u0300-\u036f]/g, "")).replace(/[\s\-_]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
351
287
|
}
|
|
288
|
+
var SLUG_CHAR_MAP = {
|
|
289
|
+
// Turkish
|
|
290
|
+
"\u015F": "s",
|
|
291
|
+
"\u0131": "i",
|
|
292
|
+
"\u011F": "g",
|
|
293
|
+
"\xFC": "u",
|
|
294
|
+
"\xF6": "o",
|
|
295
|
+
"\xE7": "c",
|
|
296
|
+
// Russian (Cyrillic to Latin - basic transliteration)
|
|
297
|
+
"\u0430": "a",
|
|
298
|
+
"\u0431": "b",
|
|
299
|
+
"\u0432": "v",
|
|
300
|
+
"\u0433": "g",
|
|
301
|
+
"\u0434": "d",
|
|
302
|
+
"\u0435": "e",
|
|
303
|
+
"\u0451": "yo",
|
|
304
|
+
"\u0436": "zh",
|
|
305
|
+
"\u0437": "z",
|
|
306
|
+
"\u0438": "i",
|
|
307
|
+
"\u0439": "y",
|
|
308
|
+
"\u043A": "k",
|
|
309
|
+
"\u043B": "l",
|
|
310
|
+
"\u043C": "m",
|
|
311
|
+
"\u043D": "n",
|
|
312
|
+
"\u043E": "o",
|
|
313
|
+
"\u043F": "p",
|
|
314
|
+
"\u0440": "r",
|
|
315
|
+
"\u0441": "s",
|
|
316
|
+
"\u0442": "t",
|
|
317
|
+
"\u0443": "u",
|
|
318
|
+
"\u0444": "f",
|
|
319
|
+
"\u0445": "h",
|
|
320
|
+
"\u0446": "ts",
|
|
321
|
+
"\u0447": "ch",
|
|
322
|
+
"\u0448": "sh",
|
|
323
|
+
"\u0449": "shch",
|
|
324
|
+
"\u044A": "",
|
|
325
|
+
"\u044B": "y",
|
|
326
|
+
"\u044C": "",
|
|
327
|
+
"\u044D": "e",
|
|
328
|
+
"\u044E": "yu",
|
|
329
|
+
"\u044F": "ya",
|
|
330
|
+
// Greek (basic)
|
|
331
|
+
"\u03B1": "a",
|
|
332
|
+
"\u03B2": "b",
|
|
333
|
+
"\u03B3": "g",
|
|
334
|
+
"\u03B4": "d",
|
|
335
|
+
"\u03B5": "e",
|
|
336
|
+
"\u03B6": "z",
|
|
337
|
+
"\u03B7": "i",
|
|
338
|
+
"\u03B8": "th",
|
|
339
|
+
"\u03B9": "i",
|
|
340
|
+
"\u03BA": "k",
|
|
341
|
+
"\u03BB": "l",
|
|
342
|
+
"\u03BC": "m",
|
|
343
|
+
"\u03BD": "n",
|
|
344
|
+
"\u03BE": "x",
|
|
345
|
+
"\u03BF": "o",
|
|
346
|
+
"\u03C0": "p",
|
|
347
|
+
"\u03C1": "r",
|
|
348
|
+
"\u03C3": "s",
|
|
349
|
+
"\u03C2": "s",
|
|
350
|
+
"\u03C4": "t",
|
|
351
|
+
"\u03C5": "y",
|
|
352
|
+
"\u03C6": "f",
|
|
353
|
+
"\u03C7": "ch",
|
|
354
|
+
"\u03C8": "ps",
|
|
355
|
+
"\u03C9": "o"
|
|
356
|
+
};
|
|
352
357
|
function template(str, data) {
|
|
353
358
|
return str.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
|
|
354
359
|
const keys2 = path.trim().split(".");
|
|
355
360
|
let value = data;
|
|
356
361
|
for (const key of keys2) {
|
|
357
|
-
if (value == null) {
|
|
362
|
+
if (value == null || !chunkSWG777R6_cjs.hasOwn(Object(value), key)) {
|
|
358
363
|
return "";
|
|
359
364
|
}
|
|
360
365
|
value = value[key];
|
|
@@ -509,87 +514,6 @@ var ScopedEventBus = class {
|
|
|
509
514
|
}
|
|
510
515
|
};
|
|
511
516
|
|
|
512
|
-
// src/errors.ts
|
|
513
|
-
var UtilsError = class extends Error {
|
|
514
|
-
code;
|
|
515
|
-
constructor(message, code) {
|
|
516
|
-
super(message);
|
|
517
|
-
this.name = "UtilsError";
|
|
518
|
-
this.code = code;
|
|
519
|
-
Error.captureStackTrace(this, this.constructor);
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
var InvalidPathError = class extends UtilsError {
|
|
523
|
-
constructor(path) {
|
|
524
|
-
super(`Invalid path: ${path}`, "INVALID_PATH");
|
|
525
|
-
this.name = "InvalidPathError";
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
var CircularReferenceError = class extends UtilsError {
|
|
529
|
-
constructor() {
|
|
530
|
-
super("Circular reference detected", "CIRCULAR_REF");
|
|
531
|
-
this.name = "CircularReferenceError";
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
var TimeoutError = class extends UtilsError {
|
|
535
|
-
constructor(ms) {
|
|
536
|
-
super(`Operation timed out after ${ms}ms`, "TIMEOUT");
|
|
537
|
-
this.name = "TimeoutError";
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
var PluginAlreadyRegisteredError = class extends UtilsError {
|
|
541
|
-
constructor(name) {
|
|
542
|
-
super(`Plugin "${name}" already registered`, "PLUGIN_ALREADY_REGISTERED");
|
|
543
|
-
this.name = "PluginAlreadyRegisteredError";
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
var PluginNotFoundError = class extends UtilsError {
|
|
547
|
-
constructor(name) {
|
|
548
|
-
super(`Plugin "${name}" not found`, "PLUGIN_NOT_FOUND");
|
|
549
|
-
this.name = "PluginNotFoundError";
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
var PluginDependencyMissingError = class extends UtilsError {
|
|
553
|
-
constructor(plugin, dependency) {
|
|
554
|
-
super(`Plugin "${plugin}" requires "${dependency}" to be registered first`, "PLUGIN_DEPENDENCY_MISSING");
|
|
555
|
-
this.name = "PluginDependencyMissingError";
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
var MaxRetriesExceededError = class extends UtilsError {
|
|
559
|
-
constructor(attempts) {
|
|
560
|
-
super(`Maximum retry attempts (${attempts}) exceeded`, "MAX_RETRIES_EXCEEDED");
|
|
561
|
-
this.name = "MaxRetriesExceededError";
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
var CircularDependencyError = class extends UtilsError {
|
|
565
|
-
constructor(cycle) {
|
|
566
|
-
super(`Circular dependency detected: ${cycle.join(" -> ")}`, "CIRCULAR_DEPENDENCY");
|
|
567
|
-
this.name = "CircularDependencyError";
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
var PluginInitializationError = class extends UtilsError {
|
|
571
|
-
pluginName;
|
|
572
|
-
cause;
|
|
573
|
-
constructor(pluginName, cause) {
|
|
574
|
-
super(`Plugin "${pluginName}" failed to initialize: ${cause.message}`, "PLUGIN_INIT_FAILED");
|
|
575
|
-
this.name = "PluginInitializationError";
|
|
576
|
-
this.pluginName = pluginName;
|
|
577
|
-
this.cause = cause;
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
var KernelAlreadyInitializedError = class extends UtilsError {
|
|
581
|
-
constructor() {
|
|
582
|
-
super("Kernel is already initialized", "KERNEL_ALREADY_INITIALIZED");
|
|
583
|
-
this.name = "KernelAlreadyInitializedError";
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
var KernelInitializingError = class extends UtilsError {
|
|
587
|
-
constructor() {
|
|
588
|
-
super("Kernel is currently initializing", "KERNEL_INITIALIZING");
|
|
589
|
-
this.name = "KernelInitializingError";
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
|
|
593
517
|
// src/kernel.ts
|
|
594
518
|
var Kernel = class {
|
|
595
519
|
plugins = /* @__PURE__ */ new Map();
|
|
@@ -612,12 +536,12 @@ var Kernel = class {
|
|
|
612
536
|
*/
|
|
613
537
|
register(plugin) {
|
|
614
538
|
if (this.plugins.has(plugin.name)) {
|
|
615
|
-
throw new PluginAlreadyRegisteredError(plugin.name);
|
|
539
|
+
throw new chunkDEVWOLUI_cjs.PluginAlreadyRegisteredError(plugin.name);
|
|
616
540
|
}
|
|
617
541
|
if (plugin.dependencies) {
|
|
618
542
|
for (const dep of plugin.dependencies) {
|
|
619
543
|
if (!this.plugins.has(dep)) {
|
|
620
|
-
throw new PluginDependencyMissingError(plugin.name, dep);
|
|
544
|
+
throw new chunkDEVWOLUI_cjs.PluginDependencyMissingError(plugin.name, dep);
|
|
621
545
|
}
|
|
622
546
|
}
|
|
623
547
|
}
|
|
@@ -666,6 +590,11 @@ var Kernel = class {
|
|
|
666
590
|
this.initPromise = this.doInit();
|
|
667
591
|
try {
|
|
668
592
|
await this.initPromise;
|
|
593
|
+
} catch (error) {
|
|
594
|
+
if (this.state === "initializing") {
|
|
595
|
+
this.state = "idle";
|
|
596
|
+
}
|
|
597
|
+
throw error;
|
|
669
598
|
} finally {
|
|
670
599
|
this.initPromise = null;
|
|
671
600
|
}
|
|
@@ -673,6 +602,11 @@ var Kernel = class {
|
|
|
673
602
|
async doInit() {
|
|
674
603
|
const sortedEntries = this.topologicalSort();
|
|
675
604
|
const initializedStack = [];
|
|
605
|
+
for (const entry of sortedEntries) {
|
|
606
|
+
if (entry.state === "error" || entry.state === "destroyed") {
|
|
607
|
+
entry.state = "registered";
|
|
608
|
+
}
|
|
609
|
+
}
|
|
676
610
|
for (const entry of sortedEntries) {
|
|
677
611
|
try {
|
|
678
612
|
await this.initPlugin(entry);
|
|
@@ -690,7 +624,7 @@ var Kernel = class {
|
|
|
690
624
|
}
|
|
691
625
|
}
|
|
692
626
|
this.state = "idle";
|
|
693
|
-
throw new PluginInitializationError(
|
|
627
|
+
throw new chunkDEVWOLUI_cjs.PluginInitializationError(
|
|
694
628
|
entry.plugin.name,
|
|
695
629
|
error instanceof Error ? error : new Error(String(error))
|
|
696
630
|
);
|
|
@@ -750,7 +684,7 @@ var Kernel = class {
|
|
|
750
684
|
if (visiting.has(name)) {
|
|
751
685
|
const cycleStart = path.indexOf(name);
|
|
752
686
|
const cycle = [...path.slice(cycleStart), name];
|
|
753
|
-
throw new CircularDependencyError(cycle);
|
|
687
|
+
throw new chunkDEVWOLUI_cjs.CircularDependencyError(cycle);
|
|
754
688
|
}
|
|
755
689
|
const entry = this.plugins.get(name);
|
|
756
690
|
if (!entry) return;
|
|
@@ -781,7 +715,7 @@ var Kernel = class {
|
|
|
781
715
|
async unregister(name) {
|
|
782
716
|
const entry = this.plugins.get(name);
|
|
783
717
|
if (!entry) {
|
|
784
|
-
throw new PluginNotFoundError(name);
|
|
718
|
+
throw new chunkDEVWOLUI_cjs.PluginNotFoundError(name);
|
|
785
719
|
}
|
|
786
720
|
for (const [otherName, otherEntry] of this.plugins) {
|
|
787
721
|
if (otherName !== name && otherEntry.plugin.dependencies?.includes(name)) {
|
|
@@ -909,27 +843,63 @@ var Kernel = class {
|
|
|
909
843
|
}
|
|
910
844
|
}
|
|
911
845
|
this.plugins.clear();
|
|
912
|
-
this.eventBus.removeAllListeners();
|
|
913
846
|
this.state = "destroyed";
|
|
914
847
|
this.eventBus.emit("kernel:destroyed");
|
|
848
|
+
this.eventBus.removeAllListeners();
|
|
915
849
|
}
|
|
916
850
|
};
|
|
917
851
|
|
|
918
|
-
exports
|
|
919
|
-
|
|
852
|
+
Object.defineProperty(exports, "CircularDependencyError", {
|
|
853
|
+
enumerable: true,
|
|
854
|
+
get: function () { return chunkDEVWOLUI_cjs.CircularDependencyError; }
|
|
855
|
+
});
|
|
856
|
+
Object.defineProperty(exports, "CircularReferenceError", {
|
|
857
|
+
enumerable: true,
|
|
858
|
+
get: function () { return chunkDEVWOLUI_cjs.CircularReferenceError; }
|
|
859
|
+
});
|
|
860
|
+
Object.defineProperty(exports, "InvalidPathError", {
|
|
861
|
+
enumerable: true,
|
|
862
|
+
get: function () { return chunkDEVWOLUI_cjs.InvalidPathError; }
|
|
863
|
+
});
|
|
864
|
+
Object.defineProperty(exports, "KernelAlreadyInitializedError", {
|
|
865
|
+
enumerable: true,
|
|
866
|
+
get: function () { return chunkDEVWOLUI_cjs.KernelAlreadyInitializedError; }
|
|
867
|
+
});
|
|
868
|
+
Object.defineProperty(exports, "KernelInitializingError", {
|
|
869
|
+
enumerable: true,
|
|
870
|
+
get: function () { return chunkDEVWOLUI_cjs.KernelInitializingError; }
|
|
871
|
+
});
|
|
872
|
+
Object.defineProperty(exports, "MaxRetriesExceededError", {
|
|
873
|
+
enumerable: true,
|
|
874
|
+
get: function () { return chunkDEVWOLUI_cjs.MaxRetriesExceededError; }
|
|
875
|
+
});
|
|
876
|
+
Object.defineProperty(exports, "PluginAlreadyRegisteredError", {
|
|
877
|
+
enumerable: true,
|
|
878
|
+
get: function () { return chunkDEVWOLUI_cjs.PluginAlreadyRegisteredError; }
|
|
879
|
+
});
|
|
880
|
+
Object.defineProperty(exports, "PluginDependencyMissingError", {
|
|
881
|
+
enumerable: true,
|
|
882
|
+
get: function () { return chunkDEVWOLUI_cjs.PluginDependencyMissingError; }
|
|
883
|
+
});
|
|
884
|
+
Object.defineProperty(exports, "PluginInitializationError", {
|
|
885
|
+
enumerable: true,
|
|
886
|
+
get: function () { return chunkDEVWOLUI_cjs.PluginInitializationError; }
|
|
887
|
+
});
|
|
888
|
+
Object.defineProperty(exports, "PluginNotFoundError", {
|
|
889
|
+
enumerable: true,
|
|
890
|
+
get: function () { return chunkDEVWOLUI_cjs.PluginNotFoundError; }
|
|
891
|
+
});
|
|
892
|
+
Object.defineProperty(exports, "TimeoutError", {
|
|
893
|
+
enumerable: true,
|
|
894
|
+
get: function () { return chunkDEVWOLUI_cjs.TimeoutError; }
|
|
895
|
+
});
|
|
896
|
+
Object.defineProperty(exports, "UtilsError", {
|
|
897
|
+
enumerable: true,
|
|
898
|
+
get: function () { return chunkDEVWOLUI_cjs.UtilsError; }
|
|
899
|
+
});
|
|
920
900
|
exports.EventBus = EventBus;
|
|
921
|
-
exports.InvalidPathError = InvalidPathError;
|
|
922
901
|
exports.Kernel = Kernel;
|
|
923
|
-
exports.KernelAlreadyInitializedError = KernelAlreadyInitializedError;
|
|
924
|
-
exports.KernelInitializingError = KernelInitializingError;
|
|
925
|
-
exports.MaxRetriesExceededError = MaxRetriesExceededError;
|
|
926
|
-
exports.PluginAlreadyRegisteredError = PluginAlreadyRegisteredError;
|
|
927
|
-
exports.PluginDependencyMissingError = PluginDependencyMissingError;
|
|
928
|
-
exports.PluginInitializationError = PluginInitializationError;
|
|
929
|
-
exports.PluginNotFoundError = PluginNotFoundError;
|
|
930
902
|
exports.ScopedEventBus = ScopedEventBus;
|
|
931
|
-
exports.TimeoutError = TimeoutError;
|
|
932
|
-
exports.UtilsError = UtilsError;
|
|
933
903
|
exports.array = array_exports;
|
|
934
904
|
exports.camelCase = camelCase;
|
|
935
905
|
exports.capitalize = capitalize;
|