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.cjs
CHANGED
|
@@ -1302,7 +1302,6 @@ var AppContextCore = class {
|
|
|
1302
1302
|
this.provideRecords = [];
|
|
1303
1303
|
this.registry = /* @__PURE__ */ new Map();
|
|
1304
1304
|
this.objectSteps = [];
|
|
1305
|
-
this.parentContexts = /* @__PURE__ */ new Set();
|
|
1306
1305
|
this.started = false;
|
|
1307
1306
|
this.starting = false;
|
|
1308
1307
|
this.startingEntries = null;
|
|
@@ -1344,43 +1343,6 @@ var AppContextCore = class {
|
|
|
1344
1343
|
this.loadingRecords.delete(record);
|
|
1345
1344
|
}
|
|
1346
1345
|
}
|
|
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
|
-
}
|
|
1384
1346
|
provide(cls, ...args) {
|
|
1385
1347
|
const last = args[args.length - 1];
|
|
1386
1348
|
const hasOptions = !!last && typeof last === "object" && ("provide" in last || "merge" in last || "useValue" in last || "useFactory" in last || "useClass" in last);
|
|
@@ -1471,14 +1433,27 @@ var AppContextCore = class {
|
|
|
1471
1433
|
use(...ctxes) {
|
|
1472
1434
|
for (const ctx of ctxes) {
|
|
1473
1435
|
const other = ctx;
|
|
1474
|
-
if (this.
|
|
1436
|
+
if (this.started && !other?.started) {
|
|
1475
1437
|
throw new Error(
|
|
1476
1438
|
"Cannot use an unstarted context into a started context."
|
|
1477
1439
|
);
|
|
1478
1440
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1441
|
+
if (Array.isArray(other?.provideRecords)) {
|
|
1442
|
+
this.provideRecords.push(...other.provideRecords);
|
|
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
|
+
}
|
|
1482
1457
|
}
|
|
1483
1458
|
return this;
|
|
1484
1459
|
}
|
|
@@ -1566,6 +1541,18 @@ var ConfigurerInstance = class {
|
|
|
1566
1541
|
const defaultBoolean = parseConfigBoolean(this.defaultConfig[key], false);
|
|
1567
1542
|
return convertBooleanArray(this.getString(key), defaultBoolean);
|
|
1568
1543
|
}
|
|
1544
|
+
getJSON(key) {
|
|
1545
|
+
const value = this.getString(key);
|
|
1546
|
+
const jsonString = typeof value === "string" && !value.trim() ? this.defaultConfig[key] : value;
|
|
1547
|
+
try {
|
|
1548
|
+
return JSON.parse(jsonString);
|
|
1549
|
+
} catch (error) {
|
|
1550
|
+
const message = error instanceof Error ? `: ${error.message}` : "";
|
|
1551
|
+
throw new Error(
|
|
1552
|
+
`Failed to parse JSON config "${String(key)}"${message}`
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1569
1556
|
};
|
|
1570
1557
|
var Configurer = class {
|
|
1571
1558
|
constructor(defaultConfig) {
|
|
@@ -1589,13 +1576,17 @@ var Configurer = class {
|
|
|
1589
1576
|
generateExampleObject() {
|
|
1590
1577
|
return Object.fromEntries(
|
|
1591
1578
|
Object.entries(this.defaultConfig).map(([key, value]) => {
|
|
1579
|
+
const typedValue = toTypedValue(value);
|
|
1580
|
+
if (typedValue && typeof typedValue === "object" && !Array.isArray(typedValue)) {
|
|
1581
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1582
|
+
}
|
|
1592
1583
|
if (value.includes(",")) {
|
|
1593
1584
|
return [
|
|
1594
1585
|
toCamelCaseKey(key),
|
|
1595
1586
|
value.split(",").map((v) => toTypedValue(v))
|
|
1596
1587
|
];
|
|
1597
1588
|
}
|
|
1598
|
-
return [toCamelCaseKey(key),
|
|
1589
|
+
return [toCamelCaseKey(key), typedValue];
|
|
1599
1590
|
})
|
|
1600
1591
|
);
|
|
1601
1592
|
}
|
|
@@ -1620,6 +1611,9 @@ function normalizeConfigValue(value) {
|
|
|
1620
1611
|
if (Array.isArray(value)) {
|
|
1621
1612
|
return value.map((item) => normalizeArrayItem(item)).join(",");
|
|
1622
1613
|
}
|
|
1614
|
+
if (typeof value === "object") {
|
|
1615
|
+
return JSON.stringify(value);
|
|
1616
|
+
}
|
|
1623
1617
|
return String(value);
|
|
1624
1618
|
}
|
|
1625
1619
|
function normalizeArrayItem(value) {
|
|
@@ -1683,8 +1677,26 @@ function toTypedValue(value) {
|
|
|
1683
1677
|
if (/^\d+$/.test(trimmed)) {
|
|
1684
1678
|
return Number.parseInt(trimmed, 10);
|
|
1685
1679
|
}
|
|
1680
|
+
const jsonObject = parseJsonObjectString(trimmed);
|
|
1681
|
+
if (jsonObject !== void 0) {
|
|
1682
|
+
return jsonObject;
|
|
1683
|
+
}
|
|
1686
1684
|
return trimmed;
|
|
1687
1685
|
}
|
|
1686
|
+
function parseJsonObjectString(value) {
|
|
1687
|
+
if (!value.startsWith("{") || !value.endsWith("}")) {
|
|
1688
|
+
return void 0;
|
|
1689
|
+
}
|
|
1690
|
+
try {
|
|
1691
|
+
const parsed = JSON.parse(value);
|
|
1692
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1693
|
+
return parsed;
|
|
1694
|
+
}
|
|
1695
|
+
} catch {
|
|
1696
|
+
return void 0;
|
|
1697
|
+
}
|
|
1698
|
+
return void 0;
|
|
1699
|
+
}
|
|
1688
1700
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1689
1701
|
0 && (module.exports = {
|
|
1690
1702
|
AbortedError,
|