nfkit 1.0.31 → 1.0.33
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/index.cjs +55 -43
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +55 -43
- package/dist/index.mjs.map +2 -2
- package/dist/src/app-context/app-context.d.ts +0 -4
- package/dist/src/configurer/configurer.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1254,7 +1254,6 @@ var AppContextCore = class {
|
|
|
1254
1254
|
this.provideRecords = [];
|
|
1255
1255
|
this.registry = /* @__PURE__ */ new Map();
|
|
1256
1256
|
this.objectSteps = [];
|
|
1257
|
-
this.parentContexts = /* @__PURE__ */ new Set();
|
|
1258
1257
|
this.started = false;
|
|
1259
1258
|
this.starting = false;
|
|
1260
1259
|
this.startingEntries = null;
|
|
@@ -1296,43 +1295,6 @@ var AppContextCore = class {
|
|
|
1296
1295
|
this.loadingRecords.delete(record);
|
|
1297
1296
|
}
|
|
1298
1297
|
}
|
|
1299
|
-
applyUsedContext(other) {
|
|
1300
|
-
if (Array.isArray(other?.provideRecords)) {
|
|
1301
|
-
this.provideRecords.push(...other.provideRecords);
|
|
1302
|
-
}
|
|
1303
|
-
if (Array.isArray(other?.objectSteps)) {
|
|
1304
|
-
this.objectSteps.push(...other.objectSteps);
|
|
1305
|
-
for (const step of other.objectSteps) {
|
|
1306
|
-
step(this);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
if (other?.started) {
|
|
1310
|
-
if (other?.registry instanceof Map) {
|
|
1311
|
-
for (const [key, value] of other.registry.entries()) {
|
|
1312
|
-
this.registry.set(key, value);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
hasStartedInParentChain(visited = /* @__PURE__ */ new Set()) {
|
|
1318
|
-
if (visited.has(this)) return false;
|
|
1319
|
-
visited.add(this);
|
|
1320
|
-
if (this.started) return true;
|
|
1321
|
-
for (const parent of this.parentContexts) {
|
|
1322
|
-
if (parent.hasStartedInParentChain(visited)) {
|
|
1323
|
-
return true;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
return false;
|
|
1327
|
-
}
|
|
1328
|
-
propagateUsedContextToParents(other, visited = /* @__PURE__ */ new Set()) {
|
|
1329
|
-
if (visited.has(this)) return;
|
|
1330
|
-
visited.add(this);
|
|
1331
|
-
for (const parent of this.parentContexts) {
|
|
1332
|
-
parent.applyUsedContext(other);
|
|
1333
|
-
parent.propagateUsedContextToParents(other, visited);
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
1298
|
provide(cls, ...args) {
|
|
1337
1299
|
const last = args[args.length - 1];
|
|
1338
1300
|
const hasOptions = !!last && typeof last === "object" && ("provide" in last || "merge" in last || "useValue" in last || "useFactory" in last || "useClass" in last);
|
|
@@ -1423,14 +1385,27 @@ var AppContextCore = class {
|
|
|
1423
1385
|
use(...ctxes) {
|
|
1424
1386
|
for (const ctx of ctxes) {
|
|
1425
1387
|
const other = ctx;
|
|
1426
|
-
if (this.
|
|
1388
|
+
if (this.started && !other?.started) {
|
|
1427
1389
|
throw new Error(
|
|
1428
1390
|
"Cannot use an unstarted context into a started context."
|
|
1429
1391
|
);
|
|
1430
1392
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1393
|
+
if (Array.isArray(other?.provideRecords)) {
|
|
1394
|
+
this.provideRecords.push(...other.provideRecords);
|
|
1395
|
+
}
|
|
1396
|
+
if (Array.isArray(other?.objectSteps)) {
|
|
1397
|
+
this.objectSteps.push(...other.objectSteps);
|
|
1398
|
+
for (const step of other.objectSteps) {
|
|
1399
|
+
step(this);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (other?.started) {
|
|
1403
|
+
if (other?.registry instanceof Map) {
|
|
1404
|
+
for (const [key, value] of other.registry.entries()) {
|
|
1405
|
+
this.registry.set(key, value);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1434
1409
|
}
|
|
1435
1410
|
return this;
|
|
1436
1411
|
}
|
|
@@ -1518,6 +1493,18 @@ var ConfigurerInstance = class {
|
|
|
1518
1493
|
const defaultBoolean = parseConfigBoolean(this.defaultConfig[key], false);
|
|
1519
1494
|
return convertBooleanArray(this.getString(key), defaultBoolean);
|
|
1520
1495
|
}
|
|
1496
|
+
getJSON(key) {
|
|
1497
|
+
const value = this.getString(key);
|
|
1498
|
+
const jsonString = typeof value === "string" && !value.trim() ? this.defaultConfig[key] : value;
|
|
1499
|
+
try {
|
|
1500
|
+
return JSON.parse(jsonString);
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
const message = error instanceof Error ? `: ${error.message}` : "";
|
|
1503
|
+
throw new Error(
|
|
1504
|
+
`Failed to parse JSON config "${String(key)}"${message}`
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1521
1508
|
};
|
|
1522
1509
|
var Configurer = class {
|
|
1523
1510
|
constructor(defaultConfig) {
|
|
@@ -1541,13 +1528,17 @@ var Configurer = class {
|
|
|
1541
1528
|
generateExampleObject() {
|
|
1542
1529
|
return Object.fromEntries(
|
|
1543
1530
|
Object.entries(this.defaultConfig).map(([key, value]) => {
|
|
1531
|
+
const typedValue = toTypedValue(value);
|
|
1532
|
+
if (typedValue && typeof typedValue === "object" && !Array.isArray(typedValue)) {
|
|
1533
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1534
|
+
}
|
|
1544
1535
|
if (value.includes(",")) {
|
|
1545
1536
|
return [
|
|
1546
1537
|
toCamelCaseKey(key),
|
|
1547
1538
|
value.split(",").map((v) => toTypedValue(v))
|
|
1548
1539
|
];
|
|
1549
1540
|
}
|
|
1550
|
-
return [toCamelCaseKey(key),
|
|
1541
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1551
1542
|
})
|
|
1552
1543
|
);
|
|
1553
1544
|
}
|
|
@@ -1572,6 +1563,9 @@ function normalizeConfigValue(value) {
|
|
|
1572
1563
|
if (Array.isArray(value)) {
|
|
1573
1564
|
return value.map((item) => normalizeArrayItem(item)).join(",");
|
|
1574
1565
|
}
|
|
1566
|
+
if (typeof value === "object") {
|
|
1567
|
+
return JSON.stringify(value);
|
|
1568
|
+
}
|
|
1575
1569
|
return String(value);
|
|
1576
1570
|
}
|
|
1577
1571
|
function normalizeArrayItem(value) {
|
|
@@ -1635,8 +1629,26 @@ function toTypedValue(value) {
|
|
|
1635
1629
|
if (/^\d+$/.test(trimmed)) {
|
|
1636
1630
|
return Number.parseInt(trimmed, 10);
|
|
1637
1631
|
}
|
|
1632
|
+
const jsonObject = parseJsonObjectString(trimmed);
|
|
1633
|
+
if (jsonObject !== void 0) {
|
|
1634
|
+
return jsonObject;
|
|
1635
|
+
}
|
|
1638
1636
|
return trimmed;
|
|
1639
1637
|
}
|
|
1638
|
+
function parseJsonObjectString(value) {
|
|
1639
|
+
if (!value.startsWith("{") || !value.endsWith("}")) {
|
|
1640
|
+
return void 0;
|
|
1641
|
+
}
|
|
1642
|
+
try {
|
|
1643
|
+
const parsed = JSON.parse(value);
|
|
1644
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1645
|
+
return parsed;
|
|
1646
|
+
}
|
|
1647
|
+
} catch {
|
|
1648
|
+
return void 0;
|
|
1649
|
+
}
|
|
1650
|
+
return void 0;
|
|
1651
|
+
}
|
|
1640
1652
|
export {
|
|
1641
1653
|
AbortedError,
|
|
1642
1654
|
AppContextCore,
|