@sprucelabs/data-stores 28.1.333 → 28.1.335
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/build/databases/MongoDatabase.d.ts +13 -8
- package/build/databases/MongoDatabase.js +56 -64
- package/build/databases/NeDbDatabase.d.ts +8 -7
- package/build/databases/NeDbDatabase.js +26 -33
- package/build/databases/database.utilities.d.ts +6 -0
- package/build/databases/database.utilities.js +40 -0
- package/build/esm/databases/MongoDatabase.d.ts +13 -8
- package/build/esm/databases/MongoDatabase.js +56 -62
- package/build/esm/databases/NeDbDatabase.d.ts +8 -7
- package/build/esm/databases/NeDbDatabase.js +23 -30
- package/build/esm/databases/database.utilities.d.ts +6 -0
- package/build/esm/databases/database.utilities.js +30 -0
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/tests/databaseAssertUtil.d.ts +4 -3
- package/build/esm/tests/databaseAssertUtil.js +101 -49
- package/build/esm/types/database.types.d.ts +8 -9
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -3
- package/build/tests/databaseAssertUtil.d.ts +4 -3
- package/build/tests/databaseAssertUtil.js +99 -49
- package/build/types/database.types.d.ts +8 -9
- package/package.json +9 -9
- package/build/databases/normalizeIndex.d.ts +0 -5
- package/build/databases/normalizeIndex.js +0 -8
- package/build/esm/databases/normalizeIndex.d.ts +0 -5
- package/build/esm/databases/normalizeIndex.js +0 -5
@@ -93,6 +93,7 @@ const databaseAssertUtil = {
|
|
93
93
|
'assertSyncIndexesHandlesRaceConditions',
|
94
94
|
'assertSyncIndexesDoesNotRemoveExisting',
|
95
95
|
'assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected',
|
96
|
+
'assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates',
|
96
97
|
];
|
97
98
|
const db = await connectToDabatase(connect);
|
98
99
|
await db.dropDatabase();
|
@@ -111,12 +112,11 @@ const databaseAssertUtil = {
|
|
111
112
|
}
|
112
113
|
}
|
113
114
|
},
|
114
|
-
async
|
115
|
-
return this.
|
115
|
+
async _getIndexesWith_IdFilteredOut(db) {
|
116
|
+
return this._filterOut_Id(await db.getIndexes(this.collectionName));
|
116
117
|
},
|
117
|
-
|
118
|
-
|
119
|
-
return allIndexes.filter((i) => i[0] !== '_id');
|
118
|
+
_filterOut_Id(allIndexes) {
|
119
|
+
return allIndexes.filter((i) => i.fields[0] !== '_id');
|
120
120
|
},
|
121
121
|
async _assertUpdateUpdatedRightNumberOfRecords(db, search, updates, expectedUpdateCount) {
|
122
122
|
const updatedCount = await db.update(this.collectionName, search, updates);
|
@@ -224,20 +224,20 @@ const databaseAssertUtil = {
|
|
224
224
|
await db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
225
225
|
let indexes = (await db.getUniqueIndexes(this.collectionName));
|
226
226
|
test_utils_1.assert.isLength(indexes, 1, 'getUniqueIndexes() did not return the unique index I tried to create!');
|
227
|
-
test_utils_1.assert.isLength(indexes[0], 1, 'getUniqueIndexes() needs to return an array of
|
228
|
-
test_utils_1.assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase(), 'getUniqueIndexes() did not add the expected field to the first unique index.');
|
227
|
+
test_utils_1.assert.isLength(indexes[0].fields, 1, 'getUniqueIndexes() needs to return an array of IndexWithFilters. Each item in the array should be an array of fields that make up the unique index.');
|
228
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniqueField'.toLowerCase(), 'getUniqueIndexes() did not add the expected field to the first unique index.');
|
229
229
|
await db.createUniqueIndex(this.collectionName, ['uniqueField2']);
|
230
|
-
indexes =
|
230
|
+
indexes = await db.getUniqueIndexes(this.collectionName);
|
231
231
|
test_utils_1.assert.isLength(indexes, 2);
|
232
|
-
test_utils_1.assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
232
|
+
test_utils_1.assert.isEqual(indexes[1].fields[0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
233
233
|
await db.createUniqueIndex(this.collectionName, [
|
234
234
|
'uniqueField3',
|
235
235
|
'uniqueField4',
|
236
236
|
]);
|
237
|
-
indexes =
|
237
|
+
indexes = await db.getUniqueIndexes(this.collectionName);
|
238
238
|
test_utils_1.assert.isLength(indexes, 3);
|
239
|
-
test_utils_1.assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
240
|
-
test_utils_1.assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
239
|
+
test_utils_1.assert.isEqual(indexes[2].fields[0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
240
|
+
test_utils_1.assert.isEqual(indexes[2].fields[1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
241
241
|
await this.shutdown(db);
|
242
242
|
},
|
243
243
|
async assertHasNoUniqueIndexToStart(connect) {
|
@@ -681,12 +681,12 @@ const databaseAssertUtil = {
|
|
681
681
|
['someField'],
|
682
682
|
['otherField', 'otherField2'],
|
683
683
|
]);
|
684
|
-
let indexes =
|
684
|
+
let indexes = await db.getUniqueIndexes(this.collectionName);
|
685
685
|
test_utils_1.assert.isLength(indexes, 3, 'syncUniqueIndexes() should have created 3 indexes.');
|
686
686
|
await db.syncUniqueIndexes(this.collectionName, [['uniqueField']]);
|
687
|
-
indexes =
|
687
|
+
indexes = await db.getUniqueIndexes(this.collectionName);
|
688
688
|
test_utils_1.assert.isLength(indexes, 1);
|
689
|
-
test_utils_1.assert.isEqual(indexes[0][0].toLowerCase(), 'uniquefield');
|
689
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniquefield');
|
690
690
|
await db.syncUniqueIndexes(this.collectionName, [
|
691
691
|
{
|
692
692
|
fields: ['uniqueField'],
|
@@ -703,7 +703,7 @@ const databaseAssertUtil = {
|
|
703
703
|
filter: { isActive: true },
|
704
704
|
},
|
705
705
|
]);
|
706
|
-
indexes =
|
706
|
+
indexes = await db.getUniqueIndexes(this.collectionName);
|
707
707
|
test_utils_1.assert.isLength(indexes, 2, `Syncing unique indexs with filter is not removing extra indexes.`);
|
708
708
|
await this.shutdown(db);
|
709
709
|
},
|
@@ -728,7 +728,7 @@ const databaseAssertUtil = {
|
|
728
728
|
test_utils_1.assert.isLength(indexes, 1, 'There should be 1 index after syncing.');
|
729
729
|
await db.syncUniqueIndexes(this.collectionName, [['someField']]);
|
730
730
|
indexes = await db.getUniqueIndexes(this.collectionName);
|
731
|
-
test_utils_1.assert.isLength(indexes, 1, '
|
731
|
+
test_utils_1.assert.isLength(indexes, 1, 'syncUniqueIndexes() should have removed the index that was set before it that was different.');
|
732
732
|
await db.syncUniqueIndexes(this.collectionName, [
|
733
733
|
['uniqueField'],
|
734
734
|
['someField'],
|
@@ -743,11 +743,11 @@ const databaseAssertUtil = {
|
|
743
743
|
'someField',
|
744
744
|
'someOtherField',
|
745
745
|
]);
|
746
|
-
const err = await test_utils_1.assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['
|
746
|
+
const err = await test_utils_1.assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['someOtherField', 'uniqueField']));
|
747
747
|
lowerCaseMissingIndexValues(err);
|
748
748
|
test_utils_2.errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
749
749
|
collectionName: this.collectionName,
|
750
|
-
missingIndex: ['
|
750
|
+
missingIndex: ['someotherfield', 'uniquefield'],
|
751
751
|
});
|
752
752
|
await this.shutdown(db);
|
753
753
|
},
|
@@ -810,6 +810,7 @@ const databaseAssertUtil = {
|
|
810
810
|
async assertCantCreateUniqueIndexTwice(connect) {
|
811
811
|
const db = await connectToDabatase(connect);
|
812
812
|
await assertCantCreateUniqueIndexTwice(db, this.collectionName, ['uniqueField'], 1);
|
813
|
+
await assertCantCreateUniqueIndexTwice(db, this.collectionName, ['uniqueField', 'anotherField'], 2);
|
813
814
|
await this.shutdown(db);
|
814
815
|
},
|
815
816
|
async assertSyncingUniqueIndexesIsRaceProof(connect) {
|
@@ -934,8 +935,8 @@ const databaseAssertUtil = {
|
|
934
935
|
}));
|
935
936
|
test_utils_2.errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
936
937
|
collectionName: this.collectionName,
|
937
|
-
duplicateFields: ['
|
938
|
-
duplicateValues: ['
|
938
|
+
duplicateFields: ['slug', 'target.organizationId'],
|
939
|
+
duplicateValues: ['a slug', 'go!'],
|
939
940
|
action: 'create',
|
940
941
|
});
|
941
942
|
await db.upsertOne(this.collectionName, {
|
@@ -1377,7 +1378,7 @@ const databaseAssertUtil = {
|
|
1377
1378
|
uniqueField: 'test',
|
1378
1379
|
slug: null,
|
1379
1380
|
someField3: 'test',
|
1380
|
-
}), undefined, `Creating a duplicate record with should throw an error.`);
|
1381
|
+
}), undefined, `Creating a duplicate record with should throw an error with a uniqueIndex with filter. Make sure syncUniqueIndexes() is actually created the index honoring the filter.`);
|
1381
1382
|
await db.createOne(this.collectionName, {
|
1382
1383
|
name: (0, generateId_1.default)(),
|
1383
1384
|
slug: '555-000-0000',
|
@@ -1470,6 +1471,54 @@ const databaseAssertUtil = {
|
|
1470
1471
|
});
|
1471
1472
|
await this.shutdown(db);
|
1472
1473
|
},
|
1474
|
+
async assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates(connect) {
|
1475
|
+
const db = await connectToDabatase(connect);
|
1476
|
+
await db.syncUniqueIndexes(this.collectionName, [
|
1477
|
+
['uniqueField', 'someField3'],
|
1478
|
+
]);
|
1479
|
+
await db.syncUniqueIndexes(this.collectionName, [
|
1480
|
+
{
|
1481
|
+
fields: ['uniqueField', 'someField3'],
|
1482
|
+
filter: {
|
1483
|
+
uniqueField: { $type: 'string' },
|
1484
|
+
},
|
1485
|
+
},
|
1486
|
+
]);
|
1487
|
+
await db.createOne(this.collectionName, {
|
1488
|
+
name: (0, generateId_1.default)(),
|
1489
|
+
uniqueField: 1,
|
1490
|
+
slug: null,
|
1491
|
+
someField3: 'test',
|
1492
|
+
});
|
1493
|
+
try {
|
1494
|
+
await db.createOne(this.collectionName, {
|
1495
|
+
name: (0, generateId_1.default)(),
|
1496
|
+
uniqueField: 1,
|
1497
|
+
slug: null,
|
1498
|
+
someField3: 'test',
|
1499
|
+
});
|
1500
|
+
}
|
1501
|
+
catch (_a) {
|
1502
|
+
test_utils_1.assert.fail(`An error was thrown trying to create a record that should not have matched on a unique index with a filter. Make sure your database adapter is properly syncing indexes. In this case, it should remove an index without a filter with an index with a filter.`);
|
1503
|
+
}
|
1504
|
+
await db.createOne(this.collectionName, {
|
1505
|
+
name: (0, generateId_1.default)(),
|
1506
|
+
uniqueField: 'hey there',
|
1507
|
+
slug: null,
|
1508
|
+
someField3: 'how are you?',
|
1509
|
+
});
|
1510
|
+
try {
|
1511
|
+
await test_utils_1.assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
1512
|
+
name: (0, generateId_1.default)(),
|
1513
|
+
uniqueField: 'hey there',
|
1514
|
+
slug: null,
|
1515
|
+
someField3: 'how are you?',
|
1516
|
+
}));
|
1517
|
+
}
|
1518
|
+
catch (_b) {
|
1519
|
+
test_utils_1.assert.fail(`A record was created that should have been blocked by a unique index with a filter`);
|
1520
|
+
}
|
1521
|
+
},
|
1473
1522
|
async assertSyncIndexesRemovesExtraIndexes(connect) {
|
1474
1523
|
const db = await connectToDabatase(connect);
|
1475
1524
|
await db.syncIndexes(this.collectionName, [
|
@@ -1477,26 +1526,27 @@ const databaseAssertUtil = {
|
|
1477
1526
|
['someField'],
|
1478
1527
|
['otherField', 'otherField2'],
|
1479
1528
|
]);
|
1480
|
-
let indexes = await this.
|
1529
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1481
1530
|
test_utils_1.assert.isLength(indexes, 3);
|
1482
1531
|
await db.syncIndexes(this.collectionName, [['name']]);
|
1483
|
-
indexes = await this.
|
1532
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1484
1533
|
test_utils_1.assert.isLength(indexes, 1);
|
1485
|
-
test_utils_1.assert.isEqual(indexes[0][0], 'name');
|
1534
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0], 'name');
|
1486
1535
|
await this.shutdown(db);
|
1487
1536
|
},
|
1488
1537
|
async assertSyncIndexesSkipsExisting(connect) {
|
1489
1538
|
const db = await connectToDabatase(connect);
|
1490
1539
|
await db.syncIndexes(this.collectionName, [['name']]);
|
1491
|
-
let indexes = await this.
|
1540
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1492
1541
|
test_utils_1.assert.isLength(indexes, 1);
|
1542
|
+
test_utils_1.assert.isLength(indexes[0].fields, 1);
|
1493
1543
|
await db.syncIndexes(this.collectionName, [
|
1494
1544
|
['name'],
|
1495
1545
|
['someField'],
|
1496
1546
|
['otherField', 'otherField2'],
|
1497
1547
|
]);
|
1498
|
-
indexes = await this.
|
1499
|
-
test_utils_1.assert.isLength(indexes, 3);
|
1548
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1549
|
+
test_utils_1.assert.isLength(indexes, 3, 'There should be 3 indexes after the last sync. 1 would have been skipped, the other 2 should have been added');
|
1500
1550
|
await this.shutdown(db);
|
1501
1551
|
},
|
1502
1552
|
async assertCantDropCompoundIndexThatDoesNotExist(connect) {
|
@@ -1508,7 +1558,7 @@ const databaseAssertUtil = {
|
|
1508
1558
|
const err = await test_utils_1.assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['uniqueField', 'someOtherField']));
|
1509
1559
|
test_utils_2.errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
1510
1560
|
collectionName: this.collectionName,
|
1511
|
-
missingIndex: ['
|
1561
|
+
missingIndex: ['someOtherField', 'uniqueField'],
|
1512
1562
|
});
|
1513
1563
|
await this.shutdown(db);
|
1514
1564
|
},
|
@@ -1516,25 +1566,25 @@ const databaseAssertUtil = {
|
|
1516
1566
|
const db = await connectToDabatase(connect);
|
1517
1567
|
await db.createIndex(this.collectionName, ['someField', 'otherField']);
|
1518
1568
|
await db.dropIndex(this.collectionName, ['someField', 'otherField']);
|
1519
|
-
let indexes = await this.
|
1520
|
-
test_utils_1.assert.isLength(indexes, 0);
|
1569
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1570
|
+
test_utils_1.assert.isLength(indexes, 0, `The one index I created should have been dropped`);
|
1521
1571
|
await db.createIndex(this.collectionName, ['someField', 'someField2']);
|
1522
1572
|
await db.createIndex(this.collectionName, ['someField', 'someField3']);
|
1523
1573
|
await db.dropIndex(this.collectionName, ['someField', 'someField3']);
|
1524
|
-
indexes = await this.
|
1525
|
-
test_utils_1.assert.isLength(indexes, 1);
|
1574
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1575
|
+
test_utils_1.assert.isLength(indexes, 1, `I created 2 compound indexes, then dropped one, and expected 1 to remain.`);
|
1526
1576
|
await this.shutdown(db);
|
1527
1577
|
},
|
1528
1578
|
async assertCanDropIndex(connect) {
|
1529
1579
|
const db = await connectToDabatase(connect);
|
1530
1580
|
await db.createIndex(this.collectionName, ['someField']);
|
1531
1581
|
await db.dropIndex(this.collectionName, ['someField']);
|
1532
|
-
let indexes = await this.
|
1582
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1533
1583
|
test_utils_1.assert.isLength(indexes, 0);
|
1534
1584
|
await db.createIndex(this.collectionName, ['someField2']);
|
1535
1585
|
await db.createIndex(this.collectionName, ['someField3']);
|
1536
1586
|
await db.dropIndex(this.collectionName, ['someField3']);
|
1537
|
-
indexes = await this.
|
1587
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1538
1588
|
test_utils_1.assert.isLength(indexes, 1);
|
1539
1589
|
await this.shutdown(db);
|
1540
1590
|
},
|
@@ -1559,7 +1609,7 @@ const databaseAssertUtil = {
|
|
1559
1609
|
async assertCantCreateSameIndexTwice(connect) {
|
1560
1610
|
const db = await connectToDabatase(connect);
|
1561
1611
|
await db.createIndex(this.collectionName, ['name']);
|
1562
|
-
let indexes = await this.
|
1612
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1563
1613
|
test_utils_1.assert.isLength(indexes, 1);
|
1564
1614
|
const err = await test_utils_1.assert.doesThrowAsync(() => db.createIndex(this.collectionName, ['name']));
|
1565
1615
|
test_utils_2.errorAssert.assertError(err, 'INDEX_EXISTS');
|
@@ -1568,23 +1618,23 @@ const databaseAssertUtil = {
|
|
1568
1618
|
async assertCanCreateIndex(connect) {
|
1569
1619
|
const db = await connectToDabatase(connect);
|
1570
1620
|
await db.createIndex(this.collectionName, ['uniqueField']);
|
1571
|
-
let indexes = await this.
|
1621
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1572
1622
|
test_utils_1.assert.isArray(indexes, 'getIndexes() should return an array!');
|
1573
1623
|
test_utils_1.assert.isLength(indexes, 1, 'getIndexes() should return the one index that was created!');
|
1574
|
-
test_utils_1.assert.isLength(indexes[0], 1, 'getIndexes() should return an array of
|
1575
|
-
test_utils_1.assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase());
|
1624
|
+
test_utils_1.assert.isLength(indexes[0].fields, 1, 'getIndexes() should return an array of IndexWithFilter! It should be returing the first index I created with the first field!');
|
1625
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniqueField'.toLowerCase());
|
1576
1626
|
await db.createIndex(this.collectionName, ['uniqueField2']);
|
1577
|
-
indexes = await this.
|
1627
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1578
1628
|
test_utils_1.assert.isLength(indexes, 2);
|
1579
|
-
test_utils_1.assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1629
|
+
test_utils_1.assert.isEqual(indexes[1].fields[0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1580
1630
|
await db.createIndex(this.collectionName, [
|
1581
1631
|
'uniqueField3',
|
1582
1632
|
'uniqueField4',
|
1583
1633
|
]);
|
1584
|
-
indexes = await this.
|
1634
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1585
1635
|
test_utils_1.assert.isLength(indexes, 3);
|
1586
|
-
test_utils_1.assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
1587
|
-
test_utils_1.assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
1636
|
+
test_utils_1.assert.isEqual(indexes[2].fields[0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
1637
|
+
test_utils_1.assert.isEqual(indexes[2].fields[1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
1588
1638
|
await this.shutdown(db);
|
1589
1639
|
},
|
1590
1640
|
async assertHasNoIndexToStart(connect) {
|
@@ -1729,9 +1779,9 @@ const databaseAssertUtil = {
|
|
1729
1779
|
async _assertCanCreateMultiFieldIndex(connect, fields) {
|
1730
1780
|
const db = await connectToDabatase(connect);
|
1731
1781
|
await db.createIndex(this.collectionName, fields);
|
1732
|
-
const indexes = await this.
|
1782
|
+
const indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1733
1783
|
test_utils_1.assert.isLength(indexes, 1, `getIndexes() should return the index it created. I expected 1 but got ${indexes.length}. Also, make sure you clear the indexes when resetting the database!`);
|
1734
|
-
test_utils_1.assert.isEqualDeep(indexes[0].map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
1784
|
+
test_utils_1.assert.isEqualDeep(indexes[0].fields.map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
1735
1785
|
await this.shutdown(db);
|
1736
1786
|
},
|
1737
1787
|
assertHasLowerCaseToCamelCaseMappingEnabled(store) {
|
@@ -1744,11 +1794,11 @@ exports.default = databaseAssertUtil;
|
|
1744
1794
|
async function assertCantCreateUniqueIndexTwice(db, collectionName, fields, expectedTotalUniqueIndexes) {
|
1745
1795
|
await db.createUniqueIndex(collectionName, fields);
|
1746
1796
|
let indexes = await db.getUniqueIndexes(collectionName);
|
1747
|
-
test_utils_1.assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return
|
1748
|
-
const err = await test_utils_1.assert.doesThrowAsync(() => db.createUniqueIndex(collectionName,
|
1797
|
+
test_utils_1.assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return all unique indexes');
|
1798
|
+
const err = await test_utils_1.assert.doesThrowAsync(() => db.createUniqueIndex(collectionName, fields), undefined, 'createUniqueIndex() should throw a DataStoreError({code: "INDEX_EXISTS"}) error.');
|
1749
1799
|
test_utils_2.errorAssert.assertError(err, 'INDEX_EXISTS', {
|
1750
1800
|
collectionName,
|
1751
|
-
index:
|
1801
|
+
index: fields,
|
1752
1802
|
});
|
1753
1803
|
}
|
1754
1804
|
function lowerCaseErrorDuplicateFields(err) {
|
@@ -2,11 +2,11 @@ import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
2
2
|
import { QueryOptions } from './query.types';
|
3
3
|
export interface Database {
|
4
4
|
[x: string]: any;
|
5
|
-
syncUniqueIndexes(collectionName: string, indexes:
|
5
|
+
syncUniqueIndexes(collectionName: string, indexes: Index[]): Promise<void>;
|
6
6
|
syncIndexes(collectionName: string, indexes: Index[]): Promise<void>;
|
7
|
-
dropIndex(collectionName: string,
|
8
|
-
getUniqueIndexes(collectionName: string): Promise<
|
9
|
-
getIndexes(collectionName: string): Promise<
|
7
|
+
dropIndex(collectionName: string, index: Index): Promise<void>;
|
8
|
+
getUniqueIndexes(collectionName: string): Promise<IndexWithFilter[]>;
|
9
|
+
getIndexes(collectionName: string): Promise<IndexWithFilter[]>;
|
10
10
|
isConnected(): boolean;
|
11
11
|
generateId(): string;
|
12
12
|
connect(): Promise<void>;
|
@@ -24,8 +24,8 @@ export interface Database {
|
|
24
24
|
delete(collection: string, query: Record<string, any>): Promise<number>;
|
25
25
|
deleteOne(collection: string, query: Record<string, any>): Promise<number>;
|
26
26
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
27
|
-
createUniqueIndex(collection: string,
|
28
|
-
createIndex(collection: string,
|
27
|
+
createUniqueIndex(collection: string, index: Index): Promise<void>;
|
28
|
+
createIndex(collection: string, index: Index): Promise<void>;
|
29
29
|
query<T>(query: string, params?: any[]): Promise<T[]>;
|
30
30
|
}
|
31
31
|
export interface DatabaseOptions {
|
@@ -40,10 +40,9 @@ export type TestConnect = (connectionString?: string, dbName?: string) => Promis
|
|
40
40
|
}>;
|
41
41
|
export interface IndexWithFilter {
|
42
42
|
fields: string[];
|
43
|
-
filter
|
43
|
+
filter?: Record<string, any>;
|
44
44
|
}
|
45
|
-
export type
|
46
|
-
export type Index = string[];
|
45
|
+
export type Index = string[] | IndexWithFilter;
|
47
46
|
export interface CreateOptions extends DatabaseInternalOptions {
|
48
47
|
}
|
49
48
|
export interface DatabaseInternalOptions {
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"publishConfig": {
|
4
4
|
"access": "public"
|
5
5
|
},
|
6
|
-
"version": "28.1.
|
6
|
+
"version": "28.1.335",
|
7
7
|
"files": [
|
8
8
|
"build/**/*",
|
9
9
|
"!build/__tests__",
|
@@ -64,22 +64,22 @@
|
|
64
64
|
"watch.tsc": "tsc -w"
|
65
65
|
},
|
66
66
|
"dependencies": {
|
67
|
-
"@sprucelabs/error": "^6.0.
|
68
|
-
"@sprucelabs/globby": "^2.0.
|
69
|
-
"@sprucelabs/schema": "^30.0.
|
70
|
-
"@sprucelabs/spruce-skill-utils": "^31.0.
|
67
|
+
"@sprucelabs/error": "^6.0.336",
|
68
|
+
"@sprucelabs/globby": "^2.0.297",
|
69
|
+
"@sprucelabs/schema": "^30.0.384",
|
70
|
+
"@sprucelabs/spruce-skill-utils": "^31.0.403",
|
71
71
|
"just-clone": "^6.2.0",
|
72
72
|
"lodash": "^4.17.21",
|
73
73
|
"mongodb": "^6.8.1",
|
74
74
|
"nedb": "^1.8.0"
|
75
75
|
},
|
76
76
|
"devDependencies": {
|
77
|
-
"@sprucelabs/esm-postbuild": "^6.0.
|
78
|
-
"@sprucelabs/jest-json-reporter": "^8.0.
|
79
|
-
"@sprucelabs/resolve-path-aliases": "^2.0.
|
77
|
+
"@sprucelabs/esm-postbuild": "^6.0.320",
|
78
|
+
"@sprucelabs/jest-json-reporter": "^8.0.337",
|
79
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.315",
|
80
80
|
"@sprucelabs/semantic-release": "^5.0.2",
|
81
81
|
"@sprucelabs/test": "^9.0.44",
|
82
|
-
"@sprucelabs/test-utils": "^5.1.
|
82
|
+
"@sprucelabs/test-utils": "^5.1.282",
|
83
83
|
"@types/lodash": "^4.17.7",
|
84
84
|
"@types/nedb": "^1.8.16",
|
85
85
|
"@types/node": "^22.5.4",
|
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.default = normalizeIndex;
|
4
|
-
function normalizeIndex(index) {
|
5
|
-
const fields = Array.isArray(index) ? index : index.fields;
|
6
|
-
const filter = Array.isArray(index) ? undefined : index.filter;
|
7
|
-
return { fields, filter };
|
8
|
-
}
|