@orion-js/mongodb 4.2.0 → 4.2.1
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 +53 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +49 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,17 @@ __export(index_exports, {
|
|
|
36
36
|
MongoDB: () => MongoDB,
|
|
37
37
|
Repository: () => Repository,
|
|
38
38
|
allConnectionPromises: () => allConnectionPromises,
|
|
39
|
+
collectionsRegistry: () => collectionsRegistry,
|
|
39
40
|
configureConnection: () => configureConnection,
|
|
40
41
|
connections: () => connections,
|
|
41
42
|
createCollection: () => createCollection,
|
|
42
43
|
createIndexesPromises: () => createIndexesPromises,
|
|
44
|
+
deleteAllUnusedIndexes: () => deleteAllUnusedIndexes,
|
|
43
45
|
getDBName: () => getDBName,
|
|
44
46
|
getMongoConnection: () => getMongoConnection,
|
|
45
47
|
getOrCreateEncryptionKey: () => getOrCreateEncryptionKey,
|
|
48
|
+
getRegisteredCollections: () => getRegisteredCollections,
|
|
49
|
+
registerCollection: () => registerCollection,
|
|
46
50
|
typedId: () => typedId
|
|
47
51
|
});
|
|
48
52
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1327,6 +1331,43 @@ async function loadIndexes(collection) {
|
|
|
1327
1331
|
return results;
|
|
1328
1332
|
}
|
|
1329
1333
|
|
|
1334
|
+
// src/createCollection/collectionsRegistry.ts
|
|
1335
|
+
var import_logger4 = require("@orion-js/logger");
|
|
1336
|
+
var collectionsRegistry = /* @__PURE__ */ new Map();
|
|
1337
|
+
function registerCollection(connectionName, collection) {
|
|
1338
|
+
if (!collectionsRegistry.has(connectionName)) {
|
|
1339
|
+
collectionsRegistry.set(connectionName, /* @__PURE__ */ new Map());
|
|
1340
|
+
}
|
|
1341
|
+
collectionsRegistry.get(connectionName).set(collection.name, collection);
|
|
1342
|
+
}
|
|
1343
|
+
function getRegisteredCollections(connectionName = "main") {
|
|
1344
|
+
const connectionCollections = collectionsRegistry.get(connectionName);
|
|
1345
|
+
if (!connectionCollections) {
|
|
1346
|
+
return [];
|
|
1347
|
+
}
|
|
1348
|
+
return Array.from(connectionCollections.values());
|
|
1349
|
+
}
|
|
1350
|
+
async function deleteAllUnusedIndexes(connectionName = "main") {
|
|
1351
|
+
const collections = getRegisteredCollections(connectionName);
|
|
1352
|
+
if (collections.length === 0) {
|
|
1353
|
+
import_logger4.logger.warn(`No collections registered for connection "${connectionName}"`);
|
|
1354
|
+
return [];
|
|
1355
|
+
}
|
|
1356
|
+
import_logger4.logger.info(
|
|
1357
|
+
`Deleting unused indexes from ${collections.length} collections on connection "${connectionName}"`
|
|
1358
|
+
);
|
|
1359
|
+
const results = [];
|
|
1360
|
+
for (const collection of collections) {
|
|
1361
|
+
const result = await collection.deleteUnusedIndexes();
|
|
1362
|
+
if (result.deletedIndexes.length > 0) {
|
|
1363
|
+
results.push(result);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
const totalDeleted = results.reduce((sum, r) => sum + r.deletedIndexes.length, 0);
|
|
1367
|
+
import_logger4.logger.info(`Deleted ${totalDeleted} unused indexes from ${results.length} collections`);
|
|
1368
|
+
return results;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1330
1371
|
// src/createCollection/getSchemaAndModel.ts
|
|
1331
1372
|
var import_helpers7 = require("@orion-js/helpers");
|
|
1332
1373
|
Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
|
|
@@ -1359,7 +1400,7 @@ function getSchema(options) {
|
|
|
1359
1400
|
}
|
|
1360
1401
|
|
|
1361
1402
|
// src/createCollection/wrapMethods.ts
|
|
1362
|
-
var
|
|
1403
|
+
var import_logger5 = require("@orion-js/logger");
|
|
1363
1404
|
function wrapMethods(collection) {
|
|
1364
1405
|
const methodsWithPromises = [
|
|
1365
1406
|
"findOne",
|
|
@@ -1395,7 +1436,7 @@ function wrapMethods(collection) {
|
|
|
1395
1436
|
collection[methodName2] = (...args) => {
|
|
1396
1437
|
collection.startConnection();
|
|
1397
1438
|
if (!collection.rawCollection) {
|
|
1398
|
-
|
|
1439
|
+
import_logger5.logger.error("Method called before connection was initialized", {
|
|
1399
1440
|
collectionName: collection.name,
|
|
1400
1441
|
connectionName: collection.connectionName,
|
|
1401
1442
|
methodName: methodName2
|
|
@@ -1505,6 +1546,7 @@ function createCollection(options) {
|
|
|
1505
1546
|
}
|
|
1506
1547
|
wrapMethods(mainCollection);
|
|
1507
1548
|
wrapMethods(encryptedCollection);
|
|
1549
|
+
registerCollection(connectionName, mainCollection);
|
|
1508
1550
|
return mainCollection;
|
|
1509
1551
|
}
|
|
1510
1552
|
|
|
@@ -1535,7 +1577,7 @@ function MongoCollection(options) {
|
|
|
1535
1577
|
}
|
|
1536
1578
|
|
|
1537
1579
|
// src/encrypted/getOrCreateEncryptionKey.ts
|
|
1538
|
-
var
|
|
1580
|
+
var import_logger6 = require("@orion-js/logger");
|
|
1539
1581
|
var import_mongodb3 = require("mongodb");
|
|
1540
1582
|
async function getOrCreateEncryptionKey({
|
|
1541
1583
|
keyAltName,
|
|
@@ -1547,7 +1589,7 @@ async function getOrCreateEncryptionKey({
|
|
|
1547
1589
|
kmsProviders
|
|
1548
1590
|
}) {
|
|
1549
1591
|
const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`;
|
|
1550
|
-
|
|
1592
|
+
import_logger6.logger.info("Connecting to database to get or create the encryption key", {
|
|
1551
1593
|
keyVaultNamespace,
|
|
1552
1594
|
keyAltName
|
|
1553
1595
|
});
|
|
@@ -1565,14 +1607,14 @@ async function getOrCreateEncryptionKey({
|
|
|
1565
1607
|
});
|
|
1566
1608
|
const key = await clientEncryption.getKeyByAltName(keyAltName);
|
|
1567
1609
|
if (key) {
|
|
1568
|
-
|
|
1610
|
+
import_logger6.logger.info("Key found on the key vault", {
|
|
1569
1611
|
keyVaultNamespace,
|
|
1570
1612
|
keyAltName,
|
|
1571
1613
|
UUID: key._id
|
|
1572
1614
|
});
|
|
1573
1615
|
return { key: key._id, keyVaultNamespace };
|
|
1574
1616
|
}
|
|
1575
|
-
|
|
1617
|
+
import_logger6.logger.info("Key not found on the key vault, creating a new one", {
|
|
1576
1618
|
keyVaultNamespace,
|
|
1577
1619
|
keyAltName
|
|
1578
1620
|
});
|
|
@@ -1580,7 +1622,7 @@ async function getOrCreateEncryptionKey({
|
|
|
1580
1622
|
keyAltNames: [keyAltName],
|
|
1581
1623
|
...masterKey ? { masterKey } : {}
|
|
1582
1624
|
});
|
|
1583
|
-
|
|
1625
|
+
import_logger6.logger.info("New encryption key created", {
|
|
1584
1626
|
keyVaultNamespace,
|
|
1585
1627
|
keyAltName,
|
|
1586
1628
|
UUID: newKey
|
|
@@ -1600,13 +1642,17 @@ var ENCRYPTION_ALGORITHMS = {
|
|
|
1600
1642
|
MongoDB,
|
|
1601
1643
|
Repository,
|
|
1602
1644
|
allConnectionPromises,
|
|
1645
|
+
collectionsRegistry,
|
|
1603
1646
|
configureConnection,
|
|
1604
1647
|
connections,
|
|
1605
1648
|
createCollection,
|
|
1606
1649
|
createIndexesPromises,
|
|
1650
|
+
deleteAllUnusedIndexes,
|
|
1607
1651
|
getDBName,
|
|
1608
1652
|
getMongoConnection,
|
|
1609
1653
|
getOrCreateEncryptionKey,
|
|
1654
|
+
getRegisteredCollections,
|
|
1655
|
+
registerCollection,
|
|
1610
1656
|
typedId
|
|
1611
1657
|
});
|
|
1612
1658
|
//# sourceMappingURL=index.cjs.map
|