nfkit 1.0.32 → 1.0.34
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 +80 -18
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +80 -18
- package/dist/index.mjs.map +2 -2
- package/dist/src/app-context/app-context.d.ts +4 -0
- package/dist/src/configurer/configurer.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1302,6 +1302,7 @@ var AppContextCore = class {
|
|
|
1302
1302
|
this.provideRecords = [];
|
|
1303
1303
|
this.registry = /* @__PURE__ */ new Map();
|
|
1304
1304
|
this.objectSteps = [];
|
|
1305
|
+
this.parentContexts = /* @__PURE__ */ new Set();
|
|
1305
1306
|
this.started = false;
|
|
1306
1307
|
this.starting = false;
|
|
1307
1308
|
this.startingEntries = null;
|
|
@@ -1343,6 +1344,43 @@ var AppContextCore = class {
|
|
|
1343
1344
|
this.loadingRecords.delete(record);
|
|
1344
1345
|
}
|
|
1345
1346
|
}
|
|
1347
|
+
applyUsedContext(other) {
|
|
1348
|
+
if (Array.isArray(other?.provideRecords)) {
|
|
1349
|
+
this.provideRecords.push(...other.provideRecords);
|
|
1350
|
+
}
|
|
1351
|
+
if (Array.isArray(other?.objectSteps)) {
|
|
1352
|
+
this.objectSteps.push(...other.objectSteps);
|
|
1353
|
+
for (const step of other.objectSteps) {
|
|
1354
|
+
step(this);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (other?.started) {
|
|
1358
|
+
if (other?.registry instanceof Map) {
|
|
1359
|
+
for (const [key, value] of other.registry.entries()) {
|
|
1360
|
+
this.registry.set(key, value);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
hasStartedInParentChain(visited = /* @__PURE__ */ new Set()) {
|
|
1366
|
+
if (visited.has(this)) return false;
|
|
1367
|
+
visited.add(this);
|
|
1368
|
+
if (this.started) return true;
|
|
1369
|
+
for (const parent of this.parentContexts) {
|
|
1370
|
+
if (parent.hasStartedInParentChain(visited)) {
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
propagateUsedContextToParents(other, visited = /* @__PURE__ */ new Set()) {
|
|
1377
|
+
if (visited.has(this)) return;
|
|
1378
|
+
visited.add(this);
|
|
1379
|
+
for (const parent of this.parentContexts) {
|
|
1380
|
+
parent.applyUsedContext(other);
|
|
1381
|
+
parent.propagateUsedContextToParents(other, visited);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1346
1384
|
provide(cls, ...args) {
|
|
1347
1385
|
const last = args[args.length - 1];
|
|
1348
1386
|
const hasOptions = !!last && typeof last === "object" && ("provide" in last || "merge" in last || "useValue" in last || "useFactory" in last || "useClass" in last);
|
|
@@ -1433,27 +1471,14 @@ var AppContextCore = class {
|
|
|
1433
1471
|
use(...ctxes) {
|
|
1434
1472
|
for (const ctx of ctxes) {
|
|
1435
1473
|
const other = ctx;
|
|
1436
|
-
if (this.
|
|
1474
|
+
if (this.hasStartedInParentChain() && !other?.started) {
|
|
1437
1475
|
throw new Error(
|
|
1438
1476
|
"Cannot use an unstarted context into a started context."
|
|
1439
1477
|
);
|
|
1440
1478
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (Array.isArray(other?.objectSteps)) {
|
|
1445
|
-
this.objectSteps.push(...other.objectSteps);
|
|
1446
|
-
for (const step of other.objectSteps) {
|
|
1447
|
-
step(this);
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
if (other?.started) {
|
|
1451
|
-
if (other?.registry instanceof Map) {
|
|
1452
|
-
for (const [key, value] of other.registry.entries()) {
|
|
1453
|
-
this.registry.set(key, value);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1479
|
+
this.applyUsedContext(other);
|
|
1480
|
+
other.parentContexts.add(this);
|
|
1481
|
+
this.propagateUsedContextToParents(other);
|
|
1457
1482
|
}
|
|
1458
1483
|
return this;
|
|
1459
1484
|
}
|
|
@@ -1541,6 +1566,18 @@ var ConfigurerInstance = class {
|
|
|
1541
1566
|
const defaultBoolean = parseConfigBoolean(this.defaultConfig[key], false);
|
|
1542
1567
|
return convertBooleanArray(this.getString(key), defaultBoolean);
|
|
1543
1568
|
}
|
|
1569
|
+
getJSON(key) {
|
|
1570
|
+
const value = this.getString(key);
|
|
1571
|
+
const jsonString = typeof value === "string" && !value.trim() ? this.defaultConfig[key] : value;
|
|
1572
|
+
try {
|
|
1573
|
+
return JSON.parse(jsonString);
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
const message = error instanceof Error ? `: ${error.message}` : "";
|
|
1576
|
+
throw new Error(
|
|
1577
|
+
`Failed to parse JSON config "${String(key)}"${message}`
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1544
1581
|
};
|
|
1545
1582
|
var Configurer = class {
|
|
1546
1583
|
constructor(defaultConfig) {
|
|
@@ -1564,13 +1601,17 @@ var Configurer = class {
|
|
|
1564
1601
|
generateExampleObject() {
|
|
1565
1602
|
return Object.fromEntries(
|
|
1566
1603
|
Object.entries(this.defaultConfig).map(([key, value]) => {
|
|
1604
|
+
const typedValue = toTypedValue(value);
|
|
1605
|
+
if (typedValue && typeof typedValue === "object" && !Array.isArray(typedValue)) {
|
|
1606
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1607
|
+
}
|
|
1567
1608
|
if (value.includes(",")) {
|
|
1568
1609
|
return [
|
|
1569
1610
|
toCamelCaseKey(key),
|
|
1570
1611
|
value.split(",").map((v) => toTypedValue(v))
|
|
1571
1612
|
];
|
|
1572
1613
|
}
|
|
1573
|
-
return [toCamelCaseKey(key),
|
|
1614
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1574
1615
|
})
|
|
1575
1616
|
);
|
|
1576
1617
|
}
|
|
@@ -1595,6 +1636,9 @@ function normalizeConfigValue(value) {
|
|
|
1595
1636
|
if (Array.isArray(value)) {
|
|
1596
1637
|
return value.map((item) => normalizeArrayItem(item)).join(",");
|
|
1597
1638
|
}
|
|
1639
|
+
if (typeof value === "object") {
|
|
1640
|
+
return JSON.stringify(value);
|
|
1641
|
+
}
|
|
1598
1642
|
return String(value);
|
|
1599
1643
|
}
|
|
1600
1644
|
function normalizeArrayItem(value) {
|
|
@@ -1658,8 +1702,26 @@ function toTypedValue(value) {
|
|
|
1658
1702
|
if (/^\d+$/.test(trimmed)) {
|
|
1659
1703
|
return Number.parseInt(trimmed, 10);
|
|
1660
1704
|
}
|
|
1705
|
+
const jsonObject = parseJsonObjectString(trimmed);
|
|
1706
|
+
if (jsonObject !== void 0) {
|
|
1707
|
+
return jsonObject;
|
|
1708
|
+
}
|
|
1661
1709
|
return trimmed;
|
|
1662
1710
|
}
|
|
1711
|
+
function parseJsonObjectString(value) {
|
|
1712
|
+
if (!value.startsWith("{") || !value.endsWith("}")) {
|
|
1713
|
+
return void 0;
|
|
1714
|
+
}
|
|
1715
|
+
try {
|
|
1716
|
+
const parsed = JSON.parse(value);
|
|
1717
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1718
|
+
return parsed;
|
|
1719
|
+
}
|
|
1720
|
+
} catch {
|
|
1721
|
+
return void 0;
|
|
1722
|
+
}
|
|
1723
|
+
return void 0;
|
|
1724
|
+
}
|
|
1663
1725
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1664
1726
|
0 && (module.exports = {
|
|
1665
1727
|
AbortedError,
|