keyv 6.0.0-beta.1 → 6.0.0-beta.3
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 +99 -98
- package/dist/index.mjs +99 -98
- package/package.json +12 -9
package/dist/index.cjs
CHANGED
|
@@ -406,26 +406,26 @@ async function deleteExpiredKeys(keys, data, keyv) {
|
|
|
406
406
|
* Maps new hook names to their deprecated equivalents so both fire during migration.
|
|
407
407
|
*/
|
|
408
408
|
const deprecatedHookAliases = new Map([
|
|
409
|
-
[
|
|
410
|
-
[
|
|
411
|
-
[
|
|
412
|
-
[
|
|
413
|
-
[
|
|
414
|
-
[
|
|
415
|
-
[
|
|
416
|
-
[
|
|
417
|
-
[
|
|
418
|
-
[
|
|
419
|
-
[
|
|
420
|
-
[
|
|
421
|
-
[
|
|
422
|
-
[
|
|
423
|
-
[
|
|
424
|
-
[
|
|
425
|
-
[
|
|
426
|
-
[
|
|
427
|
-
[
|
|
428
|
-
[
|
|
409
|
+
["before:set", "preSet"],
|
|
410
|
+
["after:set", "postSet"],
|
|
411
|
+
["before:get", "preGet"],
|
|
412
|
+
["after:get", "postGet"],
|
|
413
|
+
["before:getMany", "preGetMany"],
|
|
414
|
+
["after:getMany", "postGetMany"],
|
|
415
|
+
["before:getRaw", "preGetRaw"],
|
|
416
|
+
["after:getRaw", "postGetRaw"],
|
|
417
|
+
["before:getManyRaw", "preGetManyRaw"],
|
|
418
|
+
["after:getManyRaw", "postGetManyRaw"],
|
|
419
|
+
["before:setRaw", "preSetRaw"],
|
|
420
|
+
["after:setRaw", "postSetRaw"],
|
|
421
|
+
["before:setMany", "preSetMany"],
|
|
422
|
+
["after:setMany", "postSetMany"],
|
|
423
|
+
["before:setManyRaw", "preSetManyRaw"],
|
|
424
|
+
["after:setManyRaw", "postSetManyRaw"],
|
|
425
|
+
["before:delete", "preDelete"],
|
|
426
|
+
["after:delete", "postDelete"],
|
|
427
|
+
["before:deleteMany", "preDeleteMany"],
|
|
428
|
+
["after:deleteMany", "postDeleteMany"]
|
|
429
429
|
]);
|
|
430
430
|
/**
|
|
431
431
|
* Build the deprecated-hooks map used by Hookified to warn when old PRE_/POST_ hook names are registered.
|
|
@@ -489,7 +489,7 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
|
|
|
489
489
|
if (options?.keySeparator) this._keySeparator = options.keySeparator;
|
|
490
490
|
if (options?.namespace) this._namespace = options.namespace;
|
|
491
491
|
this._capabilities = detectKeyvStorage(store);
|
|
492
|
-
if (typeof store.on === "function") store.on(
|
|
492
|
+
if (typeof store.on === "function") store.on("error", (error) => this.emit("error", error));
|
|
493
493
|
}
|
|
494
494
|
/**
|
|
495
495
|
* Gets the underlying store instance.
|
|
@@ -696,7 +696,7 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
|
|
|
696
696
|
const result = await this._store.delete(keyPrefix);
|
|
697
697
|
results.push(result);
|
|
698
698
|
} catch (error) {
|
|
699
|
-
this.emit(
|
|
699
|
+
this.emit("error", error);
|
|
700
700
|
results.push(false);
|
|
701
701
|
}
|
|
702
702
|
return results;
|
|
@@ -1389,7 +1389,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1389
1389
|
if (cap.store === "keyvStorage") return store;
|
|
1390
1390
|
if (cap.store === "mapLike") return new KeyvMemoryAdapter(store);
|
|
1391
1391
|
if (cap.store === "asyncMap") return new KeyvBridgeAdapter(store);
|
|
1392
|
-
this.emit(
|
|
1392
|
+
this.emit("error", /* @__PURE__ */ new Error("Could not use the provided storage adapter, falling back to KeyvMemoryAdapter with Map"));
|
|
1393
1393
|
return new KeyvMemoryAdapter(/* @__PURE__ */ new Map());
|
|
1394
1394
|
}
|
|
1395
1395
|
/**
|
|
@@ -1399,7 +1399,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1399
1399
|
*/
|
|
1400
1400
|
setStore(store) {
|
|
1401
1401
|
this._store = this.resolveStore(store);
|
|
1402
|
-
if (typeof this._store.on === "function") this._store.on(
|
|
1402
|
+
if (typeof this._store.on === "function") this._store.on("error", (error) => this.emit("error", error));
|
|
1403
1403
|
this._store.namespace = this._namespace;
|
|
1404
1404
|
}
|
|
1405
1405
|
/**
|
|
@@ -1417,30 +1417,30 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1417
1417
|
if (Array.isArray(key)) return this.getMany(key);
|
|
1418
1418
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1419
1419
|
if (key === "") return;
|
|
1420
|
-
await this.hookWithDeprecated(
|
|
1420
|
+
await this.hookWithDeprecated("before:get", { key });
|
|
1421
1421
|
let rawData;
|
|
1422
1422
|
try {
|
|
1423
1423
|
rawData = await this._store.get(key);
|
|
1424
1424
|
} catch (error) {
|
|
1425
|
-
this.emit(
|
|
1426
|
-
this.emitTelemetry(
|
|
1425
|
+
this.emit("error", error);
|
|
1426
|
+
this.emitTelemetry("stat:error", key);
|
|
1427
1427
|
}
|
|
1428
1428
|
let data;
|
|
1429
1429
|
if (this._checkExpired) [data] = await this.decodeWithExpire(key, rawData);
|
|
1430
1430
|
else data = rawData === void 0 || rawData === null ? void 0 : typeof rawData === "string" ? await this.decode(rawData) : rawData;
|
|
1431
1431
|
if (data === void 0) {
|
|
1432
|
-
await this.hookWithDeprecated(
|
|
1432
|
+
await this.hookWithDeprecated("after:get", {
|
|
1433
1433
|
key,
|
|
1434
1434
|
value: void 0
|
|
1435
1435
|
});
|
|
1436
|
-
this.emitTelemetry(
|
|
1436
|
+
this.emitTelemetry("stat:miss", key);
|
|
1437
1437
|
return;
|
|
1438
1438
|
}
|
|
1439
|
-
await this.hookWithDeprecated(
|
|
1439
|
+
await this.hookWithDeprecated("after:get", {
|
|
1440
1440
|
key,
|
|
1441
1441
|
value: data
|
|
1442
1442
|
});
|
|
1443
|
-
this.emitTelemetry(
|
|
1443
|
+
this.emitTelemetry("stat:hit", key);
|
|
1444
1444
|
return data.value;
|
|
1445
1445
|
}
|
|
1446
1446
|
/**
|
|
@@ -1449,7 +1449,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1449
1449
|
*/
|
|
1450
1450
|
async getMany(keys) {
|
|
1451
1451
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1452
|
-
await this.hookWithDeprecated(
|
|
1452
|
+
await this.hookWithDeprecated("before:getMany", { keys });
|
|
1453
1453
|
const rawData = await this._store.getMany(keys);
|
|
1454
1454
|
let deserialized;
|
|
1455
1455
|
if (this._checkExpired) deserialized = await this.decodeWithExpire(keys, rawData);
|
|
@@ -1458,9 +1458,9 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1458
1458
|
return typeof row === "string" ? this.decode(row) : row;
|
|
1459
1459
|
}));
|
|
1460
1460
|
const result = deserialized.map((row) => row !== void 0 ? row.value : void 0);
|
|
1461
|
-
await this.hookWithDeprecated(
|
|
1462
|
-
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry(
|
|
1463
|
-
else this.emitTelemetry(
|
|
1461
|
+
await this.hookWithDeprecated("after:getMany", result);
|
|
1462
|
+
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry("stat:miss", keys[i]);
|
|
1463
|
+
else this.emitTelemetry("stat:hit", keys[i]);
|
|
1464
1464
|
return result;
|
|
1465
1465
|
}
|
|
1466
1466
|
/**
|
|
@@ -1472,21 +1472,21 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1472
1472
|
async getRaw(key) {
|
|
1473
1473
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1474
1474
|
if (key === "") return;
|
|
1475
|
-
await this.hookWithDeprecated(
|
|
1475
|
+
await this.hookWithDeprecated("before:getRaw", { key });
|
|
1476
1476
|
const rawData = await this._store.get(key);
|
|
1477
1477
|
let data;
|
|
1478
1478
|
if (this._checkExpired) [data] = await this.decodeWithExpire(key, rawData);
|
|
1479
1479
|
else data = rawData === void 0 || rawData === null ? void 0 : typeof rawData === "string" ? await this.decode(rawData) : rawData;
|
|
1480
1480
|
if (data === void 0) {
|
|
1481
|
-
await this.hookWithDeprecated(
|
|
1481
|
+
await this.hookWithDeprecated("after:getRaw", {
|
|
1482
1482
|
key,
|
|
1483
1483
|
value: void 0
|
|
1484
1484
|
});
|
|
1485
|
-
this.emitTelemetry(
|
|
1485
|
+
this.emitTelemetry("stat:miss", key);
|
|
1486
1486
|
return;
|
|
1487
1487
|
}
|
|
1488
|
-
this.emitTelemetry(
|
|
1489
|
-
await this.hookWithDeprecated(
|
|
1488
|
+
this.emitTelemetry("stat:hit", key);
|
|
1489
|
+
await this.hookWithDeprecated("after:getRaw", {
|
|
1490
1490
|
key,
|
|
1491
1491
|
value: data
|
|
1492
1492
|
});
|
|
@@ -1500,10 +1500,10 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1500
1500
|
async getManyRaw(keys) {
|
|
1501
1501
|
/* v8 ignore next -- @preserve */
|
|
1502
1502
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1503
|
-
await this.hookWithDeprecated(
|
|
1503
|
+
await this.hookWithDeprecated("before:getManyRaw", { keys });
|
|
1504
1504
|
if (keys.length === 0) {
|
|
1505
1505
|
const result = [];
|
|
1506
|
-
await this.hookWithDeprecated(
|
|
1506
|
+
await this.hookWithDeprecated("after:getManyRaw", {
|
|
1507
1507
|
keys,
|
|
1508
1508
|
values: result
|
|
1509
1509
|
});
|
|
@@ -1516,9 +1516,9 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1516
1516
|
if (row === void 0 || row === null) return;
|
|
1517
1517
|
return typeof row === "string" ? this.decode(row) : row;
|
|
1518
1518
|
}));
|
|
1519
|
-
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry(
|
|
1520
|
-
else this.emitTelemetry(
|
|
1521
|
-
await this.hookWithDeprecated(
|
|
1519
|
+
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry("stat:miss", keys[i]);
|
|
1520
|
+
else this.emitTelemetry("stat:hit", keys[i]);
|
|
1521
|
+
await this.hookWithDeprecated("after:getManyRaw", {
|
|
1522
1522
|
keys,
|
|
1523
1523
|
values: result
|
|
1524
1524
|
});
|
|
@@ -1539,12 +1539,12 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1539
1539
|
value,
|
|
1540
1540
|
ttl
|
|
1541
1541
|
};
|
|
1542
|
-
await this.hookWithDeprecated(
|
|
1542
|
+
await this.hookWithDeprecated("before:set", data);
|
|
1543
1543
|
data.ttl = resolveTtl(data.ttl, this._ttl);
|
|
1544
1544
|
const expires = calculateExpires(data.ttl);
|
|
1545
1545
|
if (typeof data.value === "symbol") {
|
|
1546
|
-
this.emit(
|
|
1547
|
-
this.emitTelemetry(
|
|
1546
|
+
this.emit("error", "symbol cannot be serialized");
|
|
1547
|
+
this.emitTelemetry("stat:error", key);
|
|
1548
1548
|
return false;
|
|
1549
1549
|
}
|
|
1550
1550
|
const formattedValue = {
|
|
@@ -1558,15 +1558,15 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1558
1558
|
result = await this._store.set(data.key, encodedValue, data.ttl);
|
|
1559
1559
|
} catch (error) {
|
|
1560
1560
|
result = false;
|
|
1561
|
-
this.emit(
|
|
1562
|
-
this.emitTelemetry(
|
|
1561
|
+
this.emit("error", error);
|
|
1562
|
+
this.emitTelemetry("stat:error", key);
|
|
1563
1563
|
}
|
|
1564
|
-
await this.hookWithDeprecated(
|
|
1564
|
+
await this.hookWithDeprecated("after:set", {
|
|
1565
1565
|
key,
|
|
1566
1566
|
value: encodedValue,
|
|
1567
1567
|
ttl
|
|
1568
1568
|
});
|
|
1569
|
-
if (result) this.emitTelemetry(
|
|
1569
|
+
if (result) this.emitTelemetry("stat:set", key);
|
|
1570
1570
|
return result;
|
|
1571
1571
|
}
|
|
1572
1572
|
/**
|
|
@@ -1580,7 +1580,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1580
1580
|
key: this._sanitize.enabled ? this._sanitize.cleanKey(e.key) : e.key
|
|
1581
1581
|
}));
|
|
1582
1582
|
const data = { entries };
|
|
1583
|
-
await this.hookWithDeprecated(
|
|
1583
|
+
await this.hookWithDeprecated("before:setMany", data);
|
|
1584
1584
|
entries = data.entries;
|
|
1585
1585
|
let results = [];
|
|
1586
1586
|
try {
|
|
@@ -1590,8 +1590,8 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1590
1590
|
const expires = calculateExpires(ttl);
|
|
1591
1591
|
/* v8 ignore next -- @preserve */
|
|
1592
1592
|
if (typeof value === "symbol") {
|
|
1593
|
-
this.emit(
|
|
1594
|
-
this.emitTelemetry(
|
|
1593
|
+
this.emit("error", "symbol cannot be serialized");
|
|
1594
|
+
this.emitTelemetry("stat:error", key);
|
|
1595
1595
|
throw new Error("symbol cannot be serialized");
|
|
1596
1596
|
}
|
|
1597
1597
|
const formattedValue = {
|
|
@@ -1607,13 +1607,13 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1607
1607
|
const storeResult = await this._store.setMany(serializedEntries);
|
|
1608
1608
|
/* v8 ignore next -- @preserve */
|
|
1609
1609
|
results = Array.isArray(storeResult) ? storeResult : entries.map(() => true);
|
|
1610
|
-
this.emitTelemetry(
|
|
1610
|
+
this.emitTelemetry("stat:set", entries.map((e) => e.key));
|
|
1611
1611
|
} catch (error) {
|
|
1612
|
-
this.emit(
|
|
1613
|
-
this.emitTelemetry(
|
|
1612
|
+
this.emit("error", error);
|
|
1613
|
+
this.emitTelemetry("stat:error", entries.map((e) => e.key));
|
|
1614
1614
|
results = entries.map(() => false);
|
|
1615
1615
|
}
|
|
1616
|
-
await this.hookWithDeprecated(
|
|
1616
|
+
await this.hookWithDeprecated("after:setMany", {
|
|
1617
1617
|
entries,
|
|
1618
1618
|
values: results
|
|
1619
1619
|
});
|
|
@@ -1635,7 +1635,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1635
1635
|
key,
|
|
1636
1636
|
value
|
|
1637
1637
|
};
|
|
1638
|
-
await this.hookWithDeprecated(
|
|
1638
|
+
await this.hookWithDeprecated("before:setRaw", data);
|
|
1639
1639
|
const ttl = ttlFromExpires(data.value.expires);
|
|
1640
1640
|
let result = true;
|
|
1641
1641
|
try {
|
|
@@ -1644,15 +1644,15 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1644
1644
|
if (typeof storeResult === "boolean") result = storeResult;
|
|
1645
1645
|
} catch (error) {
|
|
1646
1646
|
result = false;
|
|
1647
|
-
this.emit(
|
|
1648
|
-
this.emitTelemetry(
|
|
1647
|
+
this.emit("error", error);
|
|
1648
|
+
this.emitTelemetry("stat:error", key);
|
|
1649
1649
|
}
|
|
1650
|
-
await this.hookWithDeprecated(
|
|
1650
|
+
await this.hookWithDeprecated("after:setRaw", {
|
|
1651
1651
|
key,
|
|
1652
1652
|
value: data.value,
|
|
1653
1653
|
ttl
|
|
1654
1654
|
});
|
|
1655
|
-
if (result) this.emitTelemetry(
|
|
1655
|
+
if (result) this.emitTelemetry("stat:set", key);
|
|
1656
1656
|
return result;
|
|
1657
1657
|
}
|
|
1658
1658
|
/**
|
|
@@ -1665,10 +1665,11 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1665
1665
|
async setManyRaw(entries) {
|
|
1666
1666
|
entries = entries.map((e) => ({
|
|
1667
1667
|
...e,
|
|
1668
|
+
/* v8 ignore next -- @preserve */
|
|
1668
1669
|
key: this._sanitize.enabled ? this._sanitize.cleanKey(e.key) : e.key
|
|
1669
1670
|
}));
|
|
1670
1671
|
let results = [];
|
|
1671
|
-
await this.hookWithDeprecated(
|
|
1672
|
+
await this.hookWithDeprecated("before:setManyRaw", { entries });
|
|
1672
1673
|
try {
|
|
1673
1674
|
const rawEntries = await Promise.all(entries.map(async ({ key, value }) => {
|
|
1674
1675
|
const ttl = ttlFromExpires(value.expires);
|
|
@@ -1680,13 +1681,13 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1680
1681
|
}));
|
|
1681
1682
|
const storeResult = await this._store.setMany(rawEntries);
|
|
1682
1683
|
results = Array.isArray(storeResult) ? storeResult : entries.map(() => true);
|
|
1683
|
-
this.emitTelemetry(
|
|
1684
|
+
this.emitTelemetry("stat:set", entries.map((e) => e.key));
|
|
1684
1685
|
} catch (error) {
|
|
1685
|
-
this.emit(
|
|
1686
|
-
this.emitTelemetry(
|
|
1686
|
+
this.emit("error", error);
|
|
1687
|
+
this.emitTelemetry("stat:error", entries.map((e) => e.key));
|
|
1687
1688
|
results = entries.map(() => false);
|
|
1688
1689
|
}
|
|
1689
|
-
await this.hookWithDeprecated(
|
|
1690
|
+
await this.hookWithDeprecated("after:setManyRaw", {
|
|
1690
1691
|
entries,
|
|
1691
1692
|
results
|
|
1692
1693
|
});
|
|
@@ -1696,20 +1697,20 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1696
1697
|
if (Array.isArray(key)) return this.deleteMany(key);
|
|
1697
1698
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1698
1699
|
if (key === "") return false;
|
|
1699
|
-
await this.hookWithDeprecated(
|
|
1700
|
+
await this.hookWithDeprecated("before:delete", { key });
|
|
1700
1701
|
let result = true;
|
|
1701
1702
|
try {
|
|
1702
1703
|
result = await this._store.delete(key);
|
|
1703
1704
|
} catch (error) {
|
|
1704
1705
|
result = false;
|
|
1705
|
-
this.emit(
|
|
1706
|
-
this.emitTelemetry(
|
|
1706
|
+
this.emit("error", error);
|
|
1707
|
+
this.emitTelemetry("stat:error", key);
|
|
1707
1708
|
}
|
|
1708
|
-
await this.hookWithDeprecated(
|
|
1709
|
+
await this.hookWithDeprecated("after:delete", {
|
|
1709
1710
|
key,
|
|
1710
1711
|
value: result
|
|
1711
1712
|
});
|
|
1712
|
-
this.emitTelemetry(
|
|
1713
|
+
this.emitTelemetry("stat:delete", key);
|
|
1713
1714
|
return result;
|
|
1714
1715
|
}
|
|
1715
1716
|
/**
|
|
@@ -1720,22 +1721,22 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1720
1721
|
async deleteMany(keys) {
|
|
1721
1722
|
/* v8 ignore next -- @preserve */
|
|
1722
1723
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1723
|
-
await this.hookWithDeprecated(
|
|
1724
|
-
await this.hookWithDeprecated(
|
|
1724
|
+
await this.hookWithDeprecated("before:deleteMany", { keys });
|
|
1725
|
+
await this.hookWithDeprecated("before:delete", { key: keys });
|
|
1725
1726
|
let results;
|
|
1726
1727
|
try {
|
|
1727
1728
|
results = await this._store.deleteMany(keys);
|
|
1728
|
-
this.emitTelemetry(
|
|
1729
|
+
this.emitTelemetry("stat:delete", keys);
|
|
1729
1730
|
} catch (error) {
|
|
1730
|
-
this.emit(
|
|
1731
|
-
this.emitTelemetry(
|
|
1731
|
+
this.emit("error", error);
|
|
1732
|
+
this.emitTelemetry("stat:error", keys);
|
|
1732
1733
|
results = keys.map(() => false);
|
|
1733
1734
|
}
|
|
1734
|
-
await this.hookWithDeprecated(
|
|
1735
|
+
await this.hookWithDeprecated("after:deleteMany", {
|
|
1735
1736
|
keys,
|
|
1736
1737
|
values: results
|
|
1737
1738
|
});
|
|
1738
|
-
await this.hookWithDeprecated(
|
|
1739
|
+
await this.hookWithDeprecated("after:delete", {
|
|
1739
1740
|
key: keys,
|
|
1740
1741
|
value: results
|
|
1741
1742
|
});
|
|
@@ -1745,7 +1746,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1745
1746
|
if (Array.isArray(key)) return this.hasMany(key);
|
|
1746
1747
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1747
1748
|
if (key === "") return false;
|
|
1748
|
-
await this.hookWithDeprecated(
|
|
1749
|
+
await this.hookWithDeprecated("before:has", { key });
|
|
1749
1750
|
let result = false;
|
|
1750
1751
|
try {
|
|
1751
1752
|
if (this._checkExpired) {
|
|
@@ -1756,10 +1757,10 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1756
1757
|
}
|
|
1757
1758
|
} else result = await this._store.has(key);
|
|
1758
1759
|
} catch (error) {
|
|
1759
|
-
this.emit(
|
|
1760
|
-
this.emitTelemetry(
|
|
1760
|
+
this.emit("error", error);
|
|
1761
|
+
this.emitTelemetry("stat:error", key);
|
|
1761
1762
|
}
|
|
1762
|
-
await this.hookWithDeprecated(
|
|
1763
|
+
await this.hookWithDeprecated("after:has", {
|
|
1763
1764
|
key,
|
|
1764
1765
|
value: result
|
|
1765
1766
|
});
|
|
@@ -1772,7 +1773,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1772
1773
|
*/
|
|
1773
1774
|
async hasMany(keys) {
|
|
1774
1775
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1775
|
-
await this.hookWithDeprecated(
|
|
1776
|
+
await this.hookWithDeprecated("before:hasMany", { keys });
|
|
1776
1777
|
let results = [];
|
|
1777
1778
|
try {
|
|
1778
1779
|
if (this._checkExpired) {
|
|
@@ -1780,11 +1781,11 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1780
1781
|
results = (await this.decodeWithExpire(keys, rawData)).map((row) => row !== void 0);
|
|
1781
1782
|
} else results = await this._store.hasMany(keys);
|
|
1782
1783
|
} catch (error) {
|
|
1783
|
-
this.emit(
|
|
1784
|
-
this.emitTelemetry(
|
|
1784
|
+
this.emit("error", error);
|
|
1785
|
+
this.emitTelemetry("stat:error", keys);
|
|
1785
1786
|
results = keys.map(() => false);
|
|
1786
1787
|
}
|
|
1787
|
-
await this.hookWithDeprecated(
|
|
1788
|
+
await this.hookWithDeprecated("after:hasMany", {
|
|
1788
1789
|
keys,
|
|
1789
1790
|
values: results
|
|
1790
1791
|
});
|
|
@@ -1796,14 +1797,14 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1796
1797
|
*/
|
|
1797
1798
|
async clear() {
|
|
1798
1799
|
this.emit("clear");
|
|
1799
|
-
await this.hook(
|
|
1800
|
+
await this.hook("before:clear", { namespace: this._namespace });
|
|
1800
1801
|
try {
|
|
1801
1802
|
await this._store.clear();
|
|
1802
1803
|
} catch (error) {
|
|
1803
|
-
this.emit(
|
|
1804
|
-
this.emitTelemetry(
|
|
1804
|
+
this.emit("error", error);
|
|
1805
|
+
this.emitTelemetry("stat:error");
|
|
1805
1806
|
}
|
|
1806
|
-
await this.hook(
|
|
1807
|
+
await this.hook("after:clear", { namespace: this._namespace });
|
|
1807
1808
|
}
|
|
1808
1809
|
/**
|
|
1809
1810
|
* Will disconnect the store. This is only available if the store has a disconnect method
|
|
@@ -1811,13 +1812,13 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1811
1812
|
*/
|
|
1812
1813
|
async disconnect() {
|
|
1813
1814
|
this.emit("disconnect");
|
|
1814
|
-
await this.hook(
|
|
1815
|
+
await this.hook("before:disconnect", { namespace: this._namespace });
|
|
1815
1816
|
try {
|
|
1816
1817
|
if (this._store.disconnect) await this._store.disconnect();
|
|
1817
1818
|
} catch (error) {
|
|
1818
|
-
this.emit(
|
|
1819
|
+
this.emit("error", error);
|
|
1819
1820
|
}
|
|
1820
|
-
await this.hook(
|
|
1821
|
+
await this.hook("after:disconnect", { namespace: this._namespace });
|
|
1821
1822
|
}
|
|
1822
1823
|
/**
|
|
1823
1824
|
* Iterate over all key-value pairs in the store. Automatically deserializes values,
|
|
@@ -1865,7 +1866,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1865
1866
|
if (typeof result === "string") return await this._serialization.parse(result);
|
|
1866
1867
|
return result;
|
|
1867
1868
|
} catch (error) {
|
|
1868
|
-
this.emit(
|
|
1869
|
+
this.emit("error", error);
|
|
1869
1870
|
return;
|
|
1870
1871
|
}
|
|
1871
1872
|
}
|
|
@@ -2205,7 +2206,7 @@ var KeyvMemoryAdapter = class extends hookified.Hookified {
|
|
|
2205
2206
|
this._store.delete(keyPrefix);
|
|
2206
2207
|
results.push(existed);
|
|
2207
2208
|
} catch (error) {
|
|
2208
|
-
this.emit(
|
|
2209
|
+
this.emit("error", error);
|
|
2209
2210
|
results.push(false);
|
|
2210
2211
|
}
|
|
2211
2212
|
return results;
|
package/dist/index.mjs
CHANGED
|
@@ -402,26 +402,26 @@ async function deleteExpiredKeys(keys, data, keyv) {
|
|
|
402
402
|
* Maps new hook names to their deprecated equivalents so both fire during migration.
|
|
403
403
|
*/
|
|
404
404
|
const deprecatedHookAliases = new Map([
|
|
405
|
-
[
|
|
406
|
-
[
|
|
407
|
-
[
|
|
408
|
-
[
|
|
409
|
-
[
|
|
410
|
-
[
|
|
411
|
-
[
|
|
412
|
-
[
|
|
413
|
-
[
|
|
414
|
-
[
|
|
415
|
-
[
|
|
416
|
-
[
|
|
417
|
-
[
|
|
418
|
-
[
|
|
419
|
-
[
|
|
420
|
-
[
|
|
421
|
-
[
|
|
422
|
-
[
|
|
423
|
-
[
|
|
424
|
-
[
|
|
405
|
+
["before:set", "preSet"],
|
|
406
|
+
["after:set", "postSet"],
|
|
407
|
+
["before:get", "preGet"],
|
|
408
|
+
["after:get", "postGet"],
|
|
409
|
+
["before:getMany", "preGetMany"],
|
|
410
|
+
["after:getMany", "postGetMany"],
|
|
411
|
+
["before:getRaw", "preGetRaw"],
|
|
412
|
+
["after:getRaw", "postGetRaw"],
|
|
413
|
+
["before:getManyRaw", "preGetManyRaw"],
|
|
414
|
+
["after:getManyRaw", "postGetManyRaw"],
|
|
415
|
+
["before:setRaw", "preSetRaw"],
|
|
416
|
+
["after:setRaw", "postSetRaw"],
|
|
417
|
+
["before:setMany", "preSetMany"],
|
|
418
|
+
["after:setMany", "postSetMany"],
|
|
419
|
+
["before:setManyRaw", "preSetManyRaw"],
|
|
420
|
+
["after:setManyRaw", "postSetManyRaw"],
|
|
421
|
+
["before:delete", "preDelete"],
|
|
422
|
+
["after:delete", "postDelete"],
|
|
423
|
+
["before:deleteMany", "preDeleteMany"],
|
|
424
|
+
["after:deleteMany", "postDeleteMany"]
|
|
425
425
|
]);
|
|
426
426
|
/**
|
|
427
427
|
* Build the deprecated-hooks map used by Hookified to warn when old PRE_/POST_ hook names are registered.
|
|
@@ -485,7 +485,7 @@ var KeyvBridgeAdapter = class extends Hookified {
|
|
|
485
485
|
if (options?.keySeparator) this._keySeparator = options.keySeparator;
|
|
486
486
|
if (options?.namespace) this._namespace = options.namespace;
|
|
487
487
|
this._capabilities = detectKeyvStorage(store);
|
|
488
|
-
if (typeof store.on === "function") store.on(
|
|
488
|
+
if (typeof store.on === "function") store.on("error", (error) => this.emit("error", error));
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
491
491
|
* Gets the underlying store instance.
|
|
@@ -692,7 +692,7 @@ var KeyvBridgeAdapter = class extends Hookified {
|
|
|
692
692
|
const result = await this._store.delete(keyPrefix);
|
|
693
693
|
results.push(result);
|
|
694
694
|
} catch (error) {
|
|
695
|
-
this.emit(
|
|
695
|
+
this.emit("error", error);
|
|
696
696
|
results.push(false);
|
|
697
697
|
}
|
|
698
698
|
return results;
|
|
@@ -1385,7 +1385,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1385
1385
|
if (cap.store === "keyvStorage") return store;
|
|
1386
1386
|
if (cap.store === "mapLike") return new KeyvMemoryAdapter(store);
|
|
1387
1387
|
if (cap.store === "asyncMap") return new KeyvBridgeAdapter(store);
|
|
1388
|
-
this.emit(
|
|
1388
|
+
this.emit("error", /* @__PURE__ */ new Error("Could not use the provided storage adapter, falling back to KeyvMemoryAdapter with Map"));
|
|
1389
1389
|
return new KeyvMemoryAdapter(/* @__PURE__ */ new Map());
|
|
1390
1390
|
}
|
|
1391
1391
|
/**
|
|
@@ -1395,7 +1395,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1395
1395
|
*/
|
|
1396
1396
|
setStore(store) {
|
|
1397
1397
|
this._store = this.resolveStore(store);
|
|
1398
|
-
if (typeof this._store.on === "function") this._store.on(
|
|
1398
|
+
if (typeof this._store.on === "function") this._store.on("error", (error) => this.emit("error", error));
|
|
1399
1399
|
this._store.namespace = this._namespace;
|
|
1400
1400
|
}
|
|
1401
1401
|
/**
|
|
@@ -1413,30 +1413,30 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1413
1413
|
if (Array.isArray(key)) return this.getMany(key);
|
|
1414
1414
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1415
1415
|
if (key === "") return;
|
|
1416
|
-
await this.hookWithDeprecated(
|
|
1416
|
+
await this.hookWithDeprecated("before:get", { key });
|
|
1417
1417
|
let rawData;
|
|
1418
1418
|
try {
|
|
1419
1419
|
rawData = await this._store.get(key);
|
|
1420
1420
|
} catch (error) {
|
|
1421
|
-
this.emit(
|
|
1422
|
-
this.emitTelemetry(
|
|
1421
|
+
this.emit("error", error);
|
|
1422
|
+
this.emitTelemetry("stat:error", key);
|
|
1423
1423
|
}
|
|
1424
1424
|
let data;
|
|
1425
1425
|
if (this._checkExpired) [data] = await this.decodeWithExpire(key, rawData);
|
|
1426
1426
|
else data = rawData === void 0 || rawData === null ? void 0 : typeof rawData === "string" ? await this.decode(rawData) : rawData;
|
|
1427
1427
|
if (data === void 0) {
|
|
1428
|
-
await this.hookWithDeprecated(
|
|
1428
|
+
await this.hookWithDeprecated("after:get", {
|
|
1429
1429
|
key,
|
|
1430
1430
|
value: void 0
|
|
1431
1431
|
});
|
|
1432
|
-
this.emitTelemetry(
|
|
1432
|
+
this.emitTelemetry("stat:miss", key);
|
|
1433
1433
|
return;
|
|
1434
1434
|
}
|
|
1435
|
-
await this.hookWithDeprecated(
|
|
1435
|
+
await this.hookWithDeprecated("after:get", {
|
|
1436
1436
|
key,
|
|
1437
1437
|
value: data
|
|
1438
1438
|
});
|
|
1439
|
-
this.emitTelemetry(
|
|
1439
|
+
this.emitTelemetry("stat:hit", key);
|
|
1440
1440
|
return data.value;
|
|
1441
1441
|
}
|
|
1442
1442
|
/**
|
|
@@ -1445,7 +1445,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1445
1445
|
*/
|
|
1446
1446
|
async getMany(keys) {
|
|
1447
1447
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1448
|
-
await this.hookWithDeprecated(
|
|
1448
|
+
await this.hookWithDeprecated("before:getMany", { keys });
|
|
1449
1449
|
const rawData = await this._store.getMany(keys);
|
|
1450
1450
|
let deserialized;
|
|
1451
1451
|
if (this._checkExpired) deserialized = await this.decodeWithExpire(keys, rawData);
|
|
@@ -1454,9 +1454,9 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1454
1454
|
return typeof row === "string" ? this.decode(row) : row;
|
|
1455
1455
|
}));
|
|
1456
1456
|
const result = deserialized.map((row) => row !== void 0 ? row.value : void 0);
|
|
1457
|
-
await this.hookWithDeprecated(
|
|
1458
|
-
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry(
|
|
1459
|
-
else this.emitTelemetry(
|
|
1457
|
+
await this.hookWithDeprecated("after:getMany", result);
|
|
1458
|
+
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry("stat:miss", keys[i]);
|
|
1459
|
+
else this.emitTelemetry("stat:hit", keys[i]);
|
|
1460
1460
|
return result;
|
|
1461
1461
|
}
|
|
1462
1462
|
/**
|
|
@@ -1468,21 +1468,21 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1468
1468
|
async getRaw(key) {
|
|
1469
1469
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1470
1470
|
if (key === "") return;
|
|
1471
|
-
await this.hookWithDeprecated(
|
|
1471
|
+
await this.hookWithDeprecated("before:getRaw", { key });
|
|
1472
1472
|
const rawData = await this._store.get(key);
|
|
1473
1473
|
let data;
|
|
1474
1474
|
if (this._checkExpired) [data] = await this.decodeWithExpire(key, rawData);
|
|
1475
1475
|
else data = rawData === void 0 || rawData === null ? void 0 : typeof rawData === "string" ? await this.decode(rawData) : rawData;
|
|
1476
1476
|
if (data === void 0) {
|
|
1477
|
-
await this.hookWithDeprecated(
|
|
1477
|
+
await this.hookWithDeprecated("after:getRaw", {
|
|
1478
1478
|
key,
|
|
1479
1479
|
value: void 0
|
|
1480
1480
|
});
|
|
1481
|
-
this.emitTelemetry(
|
|
1481
|
+
this.emitTelemetry("stat:miss", key);
|
|
1482
1482
|
return;
|
|
1483
1483
|
}
|
|
1484
|
-
this.emitTelemetry(
|
|
1485
|
-
await this.hookWithDeprecated(
|
|
1484
|
+
this.emitTelemetry("stat:hit", key);
|
|
1485
|
+
await this.hookWithDeprecated("after:getRaw", {
|
|
1486
1486
|
key,
|
|
1487
1487
|
value: data
|
|
1488
1488
|
});
|
|
@@ -1496,10 +1496,10 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1496
1496
|
async getManyRaw(keys) {
|
|
1497
1497
|
/* v8 ignore next -- @preserve */
|
|
1498
1498
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1499
|
-
await this.hookWithDeprecated(
|
|
1499
|
+
await this.hookWithDeprecated("before:getManyRaw", { keys });
|
|
1500
1500
|
if (keys.length === 0) {
|
|
1501
1501
|
const result = [];
|
|
1502
|
-
await this.hookWithDeprecated(
|
|
1502
|
+
await this.hookWithDeprecated("after:getManyRaw", {
|
|
1503
1503
|
keys,
|
|
1504
1504
|
values: result
|
|
1505
1505
|
});
|
|
@@ -1512,9 +1512,9 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1512
1512
|
if (row === void 0 || row === null) return;
|
|
1513
1513
|
return typeof row === "string" ? this.decode(row) : row;
|
|
1514
1514
|
}));
|
|
1515
|
-
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry(
|
|
1516
|
-
else this.emitTelemetry(
|
|
1517
|
-
await this.hookWithDeprecated(
|
|
1515
|
+
for (let i = 0; i < result.length; i++) if (result[i] === void 0) this.emitTelemetry("stat:miss", keys[i]);
|
|
1516
|
+
else this.emitTelemetry("stat:hit", keys[i]);
|
|
1517
|
+
await this.hookWithDeprecated("after:getManyRaw", {
|
|
1518
1518
|
keys,
|
|
1519
1519
|
values: result
|
|
1520
1520
|
});
|
|
@@ -1535,12 +1535,12 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1535
1535
|
value,
|
|
1536
1536
|
ttl
|
|
1537
1537
|
};
|
|
1538
|
-
await this.hookWithDeprecated(
|
|
1538
|
+
await this.hookWithDeprecated("before:set", data);
|
|
1539
1539
|
data.ttl = resolveTtl(data.ttl, this._ttl);
|
|
1540
1540
|
const expires = calculateExpires(data.ttl);
|
|
1541
1541
|
if (typeof data.value === "symbol") {
|
|
1542
|
-
this.emit(
|
|
1543
|
-
this.emitTelemetry(
|
|
1542
|
+
this.emit("error", "symbol cannot be serialized");
|
|
1543
|
+
this.emitTelemetry("stat:error", key);
|
|
1544
1544
|
return false;
|
|
1545
1545
|
}
|
|
1546
1546
|
const formattedValue = {
|
|
@@ -1554,15 +1554,15 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1554
1554
|
result = await this._store.set(data.key, encodedValue, data.ttl);
|
|
1555
1555
|
} catch (error) {
|
|
1556
1556
|
result = false;
|
|
1557
|
-
this.emit(
|
|
1558
|
-
this.emitTelemetry(
|
|
1557
|
+
this.emit("error", error);
|
|
1558
|
+
this.emitTelemetry("stat:error", key);
|
|
1559
1559
|
}
|
|
1560
|
-
await this.hookWithDeprecated(
|
|
1560
|
+
await this.hookWithDeprecated("after:set", {
|
|
1561
1561
|
key,
|
|
1562
1562
|
value: encodedValue,
|
|
1563
1563
|
ttl
|
|
1564
1564
|
});
|
|
1565
|
-
if (result) this.emitTelemetry(
|
|
1565
|
+
if (result) this.emitTelemetry("stat:set", key);
|
|
1566
1566
|
return result;
|
|
1567
1567
|
}
|
|
1568
1568
|
/**
|
|
@@ -1576,7 +1576,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1576
1576
|
key: this._sanitize.enabled ? this._sanitize.cleanKey(e.key) : e.key
|
|
1577
1577
|
}));
|
|
1578
1578
|
const data = { entries };
|
|
1579
|
-
await this.hookWithDeprecated(
|
|
1579
|
+
await this.hookWithDeprecated("before:setMany", data);
|
|
1580
1580
|
entries = data.entries;
|
|
1581
1581
|
let results = [];
|
|
1582
1582
|
try {
|
|
@@ -1586,8 +1586,8 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1586
1586
|
const expires = calculateExpires(ttl);
|
|
1587
1587
|
/* v8 ignore next -- @preserve */
|
|
1588
1588
|
if (typeof value === "symbol") {
|
|
1589
|
-
this.emit(
|
|
1590
|
-
this.emitTelemetry(
|
|
1589
|
+
this.emit("error", "symbol cannot be serialized");
|
|
1590
|
+
this.emitTelemetry("stat:error", key);
|
|
1591
1591
|
throw new Error("symbol cannot be serialized");
|
|
1592
1592
|
}
|
|
1593
1593
|
const formattedValue = {
|
|
@@ -1603,13 +1603,13 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1603
1603
|
const storeResult = await this._store.setMany(serializedEntries);
|
|
1604
1604
|
/* v8 ignore next -- @preserve */
|
|
1605
1605
|
results = Array.isArray(storeResult) ? storeResult : entries.map(() => true);
|
|
1606
|
-
this.emitTelemetry(
|
|
1606
|
+
this.emitTelemetry("stat:set", entries.map((e) => e.key));
|
|
1607
1607
|
} catch (error) {
|
|
1608
|
-
this.emit(
|
|
1609
|
-
this.emitTelemetry(
|
|
1608
|
+
this.emit("error", error);
|
|
1609
|
+
this.emitTelemetry("stat:error", entries.map((e) => e.key));
|
|
1610
1610
|
results = entries.map(() => false);
|
|
1611
1611
|
}
|
|
1612
|
-
await this.hookWithDeprecated(
|
|
1612
|
+
await this.hookWithDeprecated("after:setMany", {
|
|
1613
1613
|
entries,
|
|
1614
1614
|
values: results
|
|
1615
1615
|
});
|
|
@@ -1631,7 +1631,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1631
1631
|
key,
|
|
1632
1632
|
value
|
|
1633
1633
|
};
|
|
1634
|
-
await this.hookWithDeprecated(
|
|
1634
|
+
await this.hookWithDeprecated("before:setRaw", data);
|
|
1635
1635
|
const ttl = ttlFromExpires(data.value.expires);
|
|
1636
1636
|
let result = true;
|
|
1637
1637
|
try {
|
|
@@ -1640,15 +1640,15 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1640
1640
|
if (typeof storeResult === "boolean") result = storeResult;
|
|
1641
1641
|
} catch (error) {
|
|
1642
1642
|
result = false;
|
|
1643
|
-
this.emit(
|
|
1644
|
-
this.emitTelemetry(
|
|
1643
|
+
this.emit("error", error);
|
|
1644
|
+
this.emitTelemetry("stat:error", key);
|
|
1645
1645
|
}
|
|
1646
|
-
await this.hookWithDeprecated(
|
|
1646
|
+
await this.hookWithDeprecated("after:setRaw", {
|
|
1647
1647
|
key,
|
|
1648
1648
|
value: data.value,
|
|
1649
1649
|
ttl
|
|
1650
1650
|
});
|
|
1651
|
-
if (result) this.emitTelemetry(
|
|
1651
|
+
if (result) this.emitTelemetry("stat:set", key);
|
|
1652
1652
|
return result;
|
|
1653
1653
|
}
|
|
1654
1654
|
/**
|
|
@@ -1661,10 +1661,11 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1661
1661
|
async setManyRaw(entries) {
|
|
1662
1662
|
entries = entries.map((e) => ({
|
|
1663
1663
|
...e,
|
|
1664
|
+
/* v8 ignore next -- @preserve */
|
|
1664
1665
|
key: this._sanitize.enabled ? this._sanitize.cleanKey(e.key) : e.key
|
|
1665
1666
|
}));
|
|
1666
1667
|
let results = [];
|
|
1667
|
-
await this.hookWithDeprecated(
|
|
1668
|
+
await this.hookWithDeprecated("before:setManyRaw", { entries });
|
|
1668
1669
|
try {
|
|
1669
1670
|
const rawEntries = await Promise.all(entries.map(async ({ key, value }) => {
|
|
1670
1671
|
const ttl = ttlFromExpires(value.expires);
|
|
@@ -1676,13 +1677,13 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1676
1677
|
}));
|
|
1677
1678
|
const storeResult = await this._store.setMany(rawEntries);
|
|
1678
1679
|
results = Array.isArray(storeResult) ? storeResult : entries.map(() => true);
|
|
1679
|
-
this.emitTelemetry(
|
|
1680
|
+
this.emitTelemetry("stat:set", entries.map((e) => e.key));
|
|
1680
1681
|
} catch (error) {
|
|
1681
|
-
this.emit(
|
|
1682
|
-
this.emitTelemetry(
|
|
1682
|
+
this.emit("error", error);
|
|
1683
|
+
this.emitTelemetry("stat:error", entries.map((e) => e.key));
|
|
1683
1684
|
results = entries.map(() => false);
|
|
1684
1685
|
}
|
|
1685
|
-
await this.hookWithDeprecated(
|
|
1686
|
+
await this.hookWithDeprecated("after:setManyRaw", {
|
|
1686
1687
|
entries,
|
|
1687
1688
|
results
|
|
1688
1689
|
});
|
|
@@ -1692,20 +1693,20 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1692
1693
|
if (Array.isArray(key)) return this.deleteMany(key);
|
|
1693
1694
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1694
1695
|
if (key === "") return false;
|
|
1695
|
-
await this.hookWithDeprecated(
|
|
1696
|
+
await this.hookWithDeprecated("before:delete", { key });
|
|
1696
1697
|
let result = true;
|
|
1697
1698
|
try {
|
|
1698
1699
|
result = await this._store.delete(key);
|
|
1699
1700
|
} catch (error) {
|
|
1700
1701
|
result = false;
|
|
1701
|
-
this.emit(
|
|
1702
|
-
this.emitTelemetry(
|
|
1702
|
+
this.emit("error", error);
|
|
1703
|
+
this.emitTelemetry("stat:error", key);
|
|
1703
1704
|
}
|
|
1704
|
-
await this.hookWithDeprecated(
|
|
1705
|
+
await this.hookWithDeprecated("after:delete", {
|
|
1705
1706
|
key,
|
|
1706
1707
|
value: result
|
|
1707
1708
|
});
|
|
1708
|
-
this.emitTelemetry(
|
|
1709
|
+
this.emitTelemetry("stat:delete", key);
|
|
1709
1710
|
return result;
|
|
1710
1711
|
}
|
|
1711
1712
|
/**
|
|
@@ -1716,22 +1717,22 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1716
1717
|
async deleteMany(keys) {
|
|
1717
1718
|
/* v8 ignore next -- @preserve */
|
|
1718
1719
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1719
|
-
await this.hookWithDeprecated(
|
|
1720
|
-
await this.hookWithDeprecated(
|
|
1720
|
+
await this.hookWithDeprecated("before:deleteMany", { keys });
|
|
1721
|
+
await this.hookWithDeprecated("before:delete", { key: keys });
|
|
1721
1722
|
let results;
|
|
1722
1723
|
try {
|
|
1723
1724
|
results = await this._store.deleteMany(keys);
|
|
1724
|
-
this.emitTelemetry(
|
|
1725
|
+
this.emitTelemetry("stat:delete", keys);
|
|
1725
1726
|
} catch (error) {
|
|
1726
|
-
this.emit(
|
|
1727
|
-
this.emitTelemetry(
|
|
1727
|
+
this.emit("error", error);
|
|
1728
|
+
this.emitTelemetry("stat:error", keys);
|
|
1728
1729
|
results = keys.map(() => false);
|
|
1729
1730
|
}
|
|
1730
|
-
await this.hookWithDeprecated(
|
|
1731
|
+
await this.hookWithDeprecated("after:deleteMany", {
|
|
1731
1732
|
keys,
|
|
1732
1733
|
values: results
|
|
1733
1734
|
});
|
|
1734
|
-
await this.hookWithDeprecated(
|
|
1735
|
+
await this.hookWithDeprecated("after:delete", {
|
|
1735
1736
|
key: keys,
|
|
1736
1737
|
value: results
|
|
1737
1738
|
});
|
|
@@ -1741,7 +1742,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1741
1742
|
if (Array.isArray(key)) return this.hasMany(key);
|
|
1742
1743
|
key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
|
|
1743
1744
|
if (key === "") return false;
|
|
1744
|
-
await this.hookWithDeprecated(
|
|
1745
|
+
await this.hookWithDeprecated("before:has", { key });
|
|
1745
1746
|
let result = false;
|
|
1746
1747
|
try {
|
|
1747
1748
|
if (this._checkExpired) {
|
|
@@ -1752,10 +1753,10 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1752
1753
|
}
|
|
1753
1754
|
} else result = await this._store.has(key);
|
|
1754
1755
|
} catch (error) {
|
|
1755
|
-
this.emit(
|
|
1756
|
-
this.emitTelemetry(
|
|
1756
|
+
this.emit("error", error);
|
|
1757
|
+
this.emitTelemetry("stat:error", key);
|
|
1757
1758
|
}
|
|
1758
|
-
await this.hookWithDeprecated(
|
|
1759
|
+
await this.hookWithDeprecated("after:has", {
|
|
1759
1760
|
key,
|
|
1760
1761
|
value: result
|
|
1761
1762
|
});
|
|
@@ -1768,7 +1769,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1768
1769
|
*/
|
|
1769
1770
|
async hasMany(keys) {
|
|
1770
1771
|
keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
|
|
1771
|
-
await this.hookWithDeprecated(
|
|
1772
|
+
await this.hookWithDeprecated("before:hasMany", { keys });
|
|
1772
1773
|
let results = [];
|
|
1773
1774
|
try {
|
|
1774
1775
|
if (this._checkExpired) {
|
|
@@ -1776,11 +1777,11 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1776
1777
|
results = (await this.decodeWithExpire(keys, rawData)).map((row) => row !== void 0);
|
|
1777
1778
|
} else results = await this._store.hasMany(keys);
|
|
1778
1779
|
} catch (error) {
|
|
1779
|
-
this.emit(
|
|
1780
|
-
this.emitTelemetry(
|
|
1780
|
+
this.emit("error", error);
|
|
1781
|
+
this.emitTelemetry("stat:error", keys);
|
|
1781
1782
|
results = keys.map(() => false);
|
|
1782
1783
|
}
|
|
1783
|
-
await this.hookWithDeprecated(
|
|
1784
|
+
await this.hookWithDeprecated("after:hasMany", {
|
|
1784
1785
|
keys,
|
|
1785
1786
|
values: results
|
|
1786
1787
|
});
|
|
@@ -1792,14 +1793,14 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1792
1793
|
*/
|
|
1793
1794
|
async clear() {
|
|
1794
1795
|
this.emit("clear");
|
|
1795
|
-
await this.hook(
|
|
1796
|
+
await this.hook("before:clear", { namespace: this._namespace });
|
|
1796
1797
|
try {
|
|
1797
1798
|
await this._store.clear();
|
|
1798
1799
|
} catch (error) {
|
|
1799
|
-
this.emit(
|
|
1800
|
-
this.emitTelemetry(
|
|
1800
|
+
this.emit("error", error);
|
|
1801
|
+
this.emitTelemetry("stat:error");
|
|
1801
1802
|
}
|
|
1802
|
-
await this.hook(
|
|
1803
|
+
await this.hook("after:clear", { namespace: this._namespace });
|
|
1803
1804
|
}
|
|
1804
1805
|
/**
|
|
1805
1806
|
* Will disconnect the store. This is only available if the store has a disconnect method
|
|
@@ -1807,13 +1808,13 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1807
1808
|
*/
|
|
1808
1809
|
async disconnect() {
|
|
1809
1810
|
this.emit("disconnect");
|
|
1810
|
-
await this.hook(
|
|
1811
|
+
await this.hook("before:disconnect", { namespace: this._namespace });
|
|
1811
1812
|
try {
|
|
1812
1813
|
if (this._store.disconnect) await this._store.disconnect();
|
|
1813
1814
|
} catch (error) {
|
|
1814
|
-
this.emit(
|
|
1815
|
+
this.emit("error", error);
|
|
1815
1816
|
}
|
|
1816
|
-
await this.hook(
|
|
1817
|
+
await this.hook("after:disconnect", { namespace: this._namespace });
|
|
1817
1818
|
}
|
|
1818
1819
|
/**
|
|
1819
1820
|
* Iterate over all key-value pairs in the store. Automatically deserializes values,
|
|
@@ -1861,7 +1862,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1861
1862
|
if (typeof result === "string") return await this._serialization.parse(result);
|
|
1862
1863
|
return result;
|
|
1863
1864
|
} catch (error) {
|
|
1864
|
-
this.emit(
|
|
1865
|
+
this.emit("error", error);
|
|
1865
1866
|
return;
|
|
1866
1867
|
}
|
|
1867
1868
|
}
|
|
@@ -2201,7 +2202,7 @@ var KeyvMemoryAdapter = class extends Hookified {
|
|
|
2201
2202
|
this._store.delete(keyPrefix);
|
|
2202
2203
|
results.push(existed);
|
|
2203
2204
|
} catch (error) {
|
|
2204
|
-
this.emit(
|
|
2205
|
+
this.emit("error", error);
|
|
2205
2206
|
results.push(false);
|
|
2206
2207
|
}
|
|
2207
2208
|
return results;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.3",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -50,25 +50,28 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"hookified": "^
|
|
53
|
+
"hookified": "^3.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@biomejs/biome": "^2.
|
|
57
|
-
"@faker-js/faker": "^10.
|
|
58
|
-
"@vitest/coverage-v8": "^4.
|
|
59
|
-
"happy-dom": "^20.
|
|
56
|
+
"@biomejs/biome": "^2.4.16",
|
|
57
|
+
"@faker-js/faker": "^10.4.0",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
59
|
+
"happy-dom": "^20.10.2",
|
|
60
60
|
"keyv-anyredis": "^3.3.0",
|
|
61
61
|
"keyv-file": "^5.3.3",
|
|
62
|
-
"lru.min": "^1.1.
|
|
62
|
+
"lru.min": "^1.1.4",
|
|
63
63
|
"quick-lru": "^7.0.0",
|
|
64
|
-
"rimraf": "^6.1.
|
|
64
|
+
"rimraf": "^6.1.3",
|
|
65
65
|
"timekeeper": "^2.3.1",
|
|
66
66
|
"tsd": "^0.33.0",
|
|
67
|
-
"vitest": "^4.
|
|
67
|
+
"vitest": "^4.1.8"
|
|
68
68
|
},
|
|
69
69
|
"tsd": {
|
|
70
70
|
"directory": "test"
|
|
71
71
|
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">= 22.18.0"
|
|
74
|
+
},
|
|
72
75
|
"files": [
|
|
73
76
|
"dist",
|
|
74
77
|
"LICENSE"
|