@sprucelabs/data-stores 28.1.334 → 28.1.336
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 +102 -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 +100 -49
- package/build/types/database.types.d.ts +8 -9
- package/package.json +1 -1
- 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
@@ -98,6 +98,7 @@ const databaseAssertUtil = {
|
|
98
98
|
'assertSyncIndexesHandlesRaceConditions',
|
99
99
|
'assertSyncIndexesDoesNotRemoveExisting',
|
100
100
|
'assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected',
|
101
|
+
'assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates',
|
101
102
|
];
|
102
103
|
const db = yield connectToDabatase(connect);
|
103
104
|
yield db.dropDatabase();
|
@@ -117,14 +118,13 @@ const databaseAssertUtil = {
|
|
117
118
|
}
|
118
119
|
});
|
119
120
|
},
|
120
|
-
|
121
|
+
_getIndexesWith_IdFilteredOut(db) {
|
121
122
|
return __awaiter(this, void 0, void 0, function* () {
|
122
|
-
return this.
|
123
|
+
return this._filterOut_Id(yield db.getIndexes(this.collectionName));
|
123
124
|
});
|
124
125
|
},
|
125
|
-
|
126
|
-
|
127
|
-
return allIndexes.filter((i) => i[0] !== '_id');
|
126
|
+
_filterOut_Id(allIndexes) {
|
127
|
+
return allIndexes.filter((i) => i.fields[0] !== '_id');
|
128
128
|
},
|
129
129
|
_assertUpdateUpdatedRightNumberOfRecords(db, search, updates, expectedUpdateCount) {
|
130
130
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -247,20 +247,20 @@ const databaseAssertUtil = {
|
|
247
247
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
248
248
|
let indexes = (yield db.getUniqueIndexes(this.collectionName));
|
249
249
|
assert.isLength(indexes, 1, 'getUniqueIndexes() did not return the unique index I tried to create!');
|
250
|
-
assert.isLength(indexes[0], 1, 'getUniqueIndexes() needs to return an array of
|
251
|
-
assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase(), 'getUniqueIndexes() did not add the expected field to the first unique index.');
|
250
|
+
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.');
|
251
|
+
assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniqueField'.toLowerCase(), 'getUniqueIndexes() did not add the expected field to the first unique index.');
|
252
252
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField2']);
|
253
|
-
indexes =
|
253
|
+
indexes = yield db.getUniqueIndexes(this.collectionName);
|
254
254
|
assert.isLength(indexes, 2);
|
255
|
-
assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
255
|
+
assert.isEqual(indexes[1].fields[0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
256
256
|
yield db.createUniqueIndex(this.collectionName, [
|
257
257
|
'uniqueField3',
|
258
258
|
'uniqueField4',
|
259
259
|
]);
|
260
|
-
indexes =
|
260
|
+
indexes = yield db.getUniqueIndexes(this.collectionName);
|
261
261
|
assert.isLength(indexes, 3);
|
262
|
-
assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
263
|
-
assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
262
|
+
assert.isEqual(indexes[2].fields[0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
263
|
+
assert.isEqual(indexes[2].fields[1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
264
264
|
yield this.shutdown(db);
|
265
265
|
});
|
266
266
|
},
|
@@ -748,12 +748,12 @@ const databaseAssertUtil = {
|
|
748
748
|
['someField'],
|
749
749
|
['otherField', 'otherField2'],
|
750
750
|
]);
|
751
|
-
let indexes =
|
751
|
+
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
752
752
|
assert.isLength(indexes, 3, 'syncUniqueIndexes() should have created 3 indexes.');
|
753
753
|
yield db.syncUniqueIndexes(this.collectionName, [['uniqueField']]);
|
754
|
-
indexes =
|
754
|
+
indexes = yield db.getUniqueIndexes(this.collectionName);
|
755
755
|
assert.isLength(indexes, 1);
|
756
|
-
assert.isEqual(indexes[0][0].toLowerCase(), 'uniquefield');
|
756
|
+
assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniquefield');
|
757
757
|
yield db.syncUniqueIndexes(this.collectionName, [
|
758
758
|
{
|
759
759
|
fields: ['uniqueField'],
|
@@ -770,7 +770,7 @@ const databaseAssertUtil = {
|
|
770
770
|
filter: { isActive: true },
|
771
771
|
},
|
772
772
|
]);
|
773
|
-
indexes =
|
773
|
+
indexes = yield db.getUniqueIndexes(this.collectionName);
|
774
774
|
assert.isLength(indexes, 2, `Syncing unique indexs with filter is not removing extra indexes.`);
|
775
775
|
yield this.shutdown(db);
|
776
776
|
});
|
@@ -799,7 +799,7 @@ const databaseAssertUtil = {
|
|
799
799
|
assert.isLength(indexes, 1, 'There should be 1 index after syncing.');
|
800
800
|
yield db.syncUniqueIndexes(this.collectionName, [['someField']]);
|
801
801
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
802
|
-
assert.isLength(indexes, 1, '
|
802
|
+
assert.isLength(indexes, 1, 'syncUniqueIndexes() should have removed the index that was set before it that was different.');
|
803
803
|
yield db.syncUniqueIndexes(this.collectionName, [
|
804
804
|
['uniqueField'],
|
805
805
|
['someField'],
|
@@ -816,11 +816,11 @@ const databaseAssertUtil = {
|
|
816
816
|
'someField',
|
817
817
|
'someOtherField',
|
818
818
|
]);
|
819
|
-
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['
|
819
|
+
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['someOtherField', 'uniqueField']));
|
820
820
|
lowerCaseMissingIndexValues(err);
|
821
821
|
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
822
822
|
collectionName: this.collectionName,
|
823
|
-
missingIndex: ['
|
823
|
+
missingIndex: ['someotherfield', 'uniquefield'],
|
824
824
|
});
|
825
825
|
yield this.shutdown(db);
|
826
826
|
});
|
@@ -893,6 +893,7 @@ const databaseAssertUtil = {
|
|
893
893
|
return __awaiter(this, void 0, void 0, function* () {
|
894
894
|
const db = yield connectToDabatase(connect);
|
895
895
|
yield assertCantCreateUniqueIndexTwice(db, this.collectionName, ['uniqueField'], 1);
|
896
|
+
yield assertCantCreateUniqueIndexTwice(db, this.collectionName, ['uniqueField', 'anotherField'], 2);
|
896
897
|
yield this.shutdown(db);
|
897
898
|
});
|
898
899
|
},
|
@@ -1023,8 +1024,8 @@ const databaseAssertUtil = {
|
|
1023
1024
|
}));
|
1024
1025
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
1025
1026
|
collectionName: this.collectionName,
|
1026
|
-
duplicateFields: ['
|
1027
|
-
duplicateValues: ['
|
1027
|
+
duplicateFields: ['slug', 'target.organizationId'],
|
1028
|
+
duplicateValues: ['a slug', 'go!'],
|
1028
1029
|
action: 'create',
|
1029
1030
|
});
|
1030
1031
|
yield db.upsertOne(this.collectionName, {
|
@@ -1502,7 +1503,7 @@ const databaseAssertUtil = {
|
|
1502
1503
|
uniqueField: 'test',
|
1503
1504
|
slug: null,
|
1504
1505
|
someField3: 'test',
|
1505
|
-
}), undefined, `Creating a duplicate record with should throw an error.`);
|
1506
|
+
}), 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.`);
|
1506
1507
|
yield db.createOne(this.collectionName, {
|
1507
1508
|
name: generateId(),
|
1508
1509
|
slug: '555-000-0000',
|
@@ -1596,6 +1597,57 @@ const databaseAssertUtil = {
|
|
1596
1597
|
yield this.shutdown(db);
|
1597
1598
|
});
|
1598
1599
|
},
|
1600
|
+
assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates(connect) {
|
1601
|
+
return __awaiter(this, void 0, void 0, function* () {
|
1602
|
+
const db = yield connectToDabatase(connect);
|
1603
|
+
yield db.syncUniqueIndexes(this.collectionName, [
|
1604
|
+
['uniqueField', 'someField3'],
|
1605
|
+
]);
|
1606
|
+
yield db.syncUniqueIndexes(this.collectionName, [
|
1607
|
+
{
|
1608
|
+
fields: ['uniqueField', 'someField3'],
|
1609
|
+
filter: {
|
1610
|
+
uniqueField: { $type: 'string' },
|
1611
|
+
},
|
1612
|
+
},
|
1613
|
+
]);
|
1614
|
+
yield db.createOne(this.collectionName, {
|
1615
|
+
name: generateId(),
|
1616
|
+
uniqueField: 1,
|
1617
|
+
slug: null,
|
1618
|
+
someField3: 'test',
|
1619
|
+
});
|
1620
|
+
try {
|
1621
|
+
yield db.createOne(this.collectionName, {
|
1622
|
+
name: generateId(),
|
1623
|
+
uniqueField: 1,
|
1624
|
+
slug: null,
|
1625
|
+
someField3: 'test',
|
1626
|
+
});
|
1627
|
+
}
|
1628
|
+
catch (_a) {
|
1629
|
+
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.`);
|
1630
|
+
}
|
1631
|
+
yield db.createOne(this.collectionName, {
|
1632
|
+
name: generateId(),
|
1633
|
+
uniqueField: 'hey there',
|
1634
|
+
slug: null,
|
1635
|
+
someField3: 'how are you?',
|
1636
|
+
});
|
1637
|
+
try {
|
1638
|
+
yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
1639
|
+
name: generateId(),
|
1640
|
+
uniqueField: 'hey there',
|
1641
|
+
slug: null,
|
1642
|
+
someField3: 'how are you?',
|
1643
|
+
}));
|
1644
|
+
}
|
1645
|
+
catch (_b) {
|
1646
|
+
assert.fail(`A record was created that should have been blocked by a unique index with a filter`);
|
1647
|
+
}
|
1648
|
+
yield this.shutdown(db);
|
1649
|
+
});
|
1650
|
+
},
|
1599
1651
|
assertSyncIndexesRemovesExtraIndexes(connect) {
|
1600
1652
|
return __awaiter(this, void 0, void 0, function* () {
|
1601
1653
|
const db = yield connectToDabatase(connect);
|
@@ -1604,12 +1656,12 @@ const databaseAssertUtil = {
|
|
1604
1656
|
['someField'],
|
1605
1657
|
['otherField', 'otherField2'],
|
1606
1658
|
]);
|
1607
|
-
let indexes = yield this.
|
1659
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1608
1660
|
assert.isLength(indexes, 3);
|
1609
1661
|
yield db.syncIndexes(this.collectionName, [['name']]);
|
1610
|
-
indexes = yield this.
|
1662
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1611
1663
|
assert.isLength(indexes, 1);
|
1612
|
-
assert.isEqual(indexes[0][0], 'name');
|
1664
|
+
assert.isEqual(indexes[0].fields[0], 'name');
|
1613
1665
|
yield this.shutdown(db);
|
1614
1666
|
});
|
1615
1667
|
},
|
@@ -1617,15 +1669,16 @@ const databaseAssertUtil = {
|
|
1617
1669
|
return __awaiter(this, void 0, void 0, function* () {
|
1618
1670
|
const db = yield connectToDabatase(connect);
|
1619
1671
|
yield db.syncIndexes(this.collectionName, [['name']]);
|
1620
|
-
let indexes = yield this.
|
1672
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1621
1673
|
assert.isLength(indexes, 1);
|
1674
|
+
assert.isLength(indexes[0].fields, 1);
|
1622
1675
|
yield db.syncIndexes(this.collectionName, [
|
1623
1676
|
['name'],
|
1624
1677
|
['someField'],
|
1625
1678
|
['otherField', 'otherField2'],
|
1626
1679
|
]);
|
1627
|
-
indexes = yield this.
|
1628
|
-
assert.isLength(indexes, 3);
|
1680
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1681
|
+
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');
|
1629
1682
|
yield this.shutdown(db);
|
1630
1683
|
});
|
1631
1684
|
},
|
@@ -1639,7 +1692,7 @@ const databaseAssertUtil = {
|
|
1639
1692
|
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['uniqueField', 'someOtherField']));
|
1640
1693
|
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
1641
1694
|
collectionName: this.collectionName,
|
1642
|
-
missingIndex: ['
|
1695
|
+
missingIndex: ['someOtherField', 'uniqueField'],
|
1643
1696
|
});
|
1644
1697
|
yield this.shutdown(db);
|
1645
1698
|
});
|
@@ -1649,13 +1702,13 @@ const databaseAssertUtil = {
|
|
1649
1702
|
const db = yield connectToDabatase(connect);
|
1650
1703
|
yield db.createIndex(this.collectionName, ['someField', 'otherField']);
|
1651
1704
|
yield db.dropIndex(this.collectionName, ['someField', 'otherField']);
|
1652
|
-
let indexes = yield this.
|
1653
|
-
assert.isLength(indexes, 0);
|
1705
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1706
|
+
assert.isLength(indexes, 0, `The one index I created should have been dropped`);
|
1654
1707
|
yield db.createIndex(this.collectionName, ['someField', 'someField2']);
|
1655
1708
|
yield db.createIndex(this.collectionName, ['someField', 'someField3']);
|
1656
1709
|
yield db.dropIndex(this.collectionName, ['someField', 'someField3']);
|
1657
|
-
indexes = yield this.
|
1658
|
-
assert.isLength(indexes, 1);
|
1710
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1711
|
+
assert.isLength(indexes, 1, `I created 2 compound indexes, then dropped one, and expected 1 to remain.`);
|
1659
1712
|
yield this.shutdown(db);
|
1660
1713
|
});
|
1661
1714
|
},
|
@@ -1664,12 +1717,12 @@ const databaseAssertUtil = {
|
|
1664
1717
|
const db = yield connectToDabatase(connect);
|
1665
1718
|
yield db.createIndex(this.collectionName, ['someField']);
|
1666
1719
|
yield db.dropIndex(this.collectionName, ['someField']);
|
1667
|
-
let indexes = yield this.
|
1720
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1668
1721
|
assert.isLength(indexes, 0);
|
1669
1722
|
yield db.createIndex(this.collectionName, ['someField2']);
|
1670
1723
|
yield db.createIndex(this.collectionName, ['someField3']);
|
1671
1724
|
yield db.dropIndex(this.collectionName, ['someField3']);
|
1672
|
-
indexes = yield this.
|
1725
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1673
1726
|
assert.isLength(indexes, 1);
|
1674
1727
|
yield this.shutdown(db);
|
1675
1728
|
});
|
@@ -1698,7 +1751,7 @@ const databaseAssertUtil = {
|
|
1698
1751
|
return __awaiter(this, void 0, void 0, function* () {
|
1699
1752
|
const db = yield connectToDabatase(connect);
|
1700
1753
|
yield db.createIndex(this.collectionName, ['name']);
|
1701
|
-
let indexes = yield this.
|
1754
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1702
1755
|
assert.isLength(indexes, 1);
|
1703
1756
|
const err = yield assert.doesThrowAsync(() => db.createIndex(this.collectionName, ['name']));
|
1704
1757
|
errorAssert.assertError(err, 'INDEX_EXISTS');
|
@@ -1709,23 +1762,23 @@ const databaseAssertUtil = {
|
|
1709
1762
|
return __awaiter(this, void 0, void 0, function* () {
|
1710
1763
|
const db = yield connectToDabatase(connect);
|
1711
1764
|
yield db.createIndex(this.collectionName, ['uniqueField']);
|
1712
|
-
let indexes = yield this.
|
1765
|
+
let indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1713
1766
|
assert.isArray(indexes, 'getIndexes() should return an array!');
|
1714
1767
|
assert.isLength(indexes, 1, 'getIndexes() should return the one index that was created!');
|
1715
|
-
assert.isLength(indexes[0], 1, 'getIndexes() should return an array of
|
1716
|
-
assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase());
|
1768
|
+
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!');
|
1769
|
+
assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniqueField'.toLowerCase());
|
1717
1770
|
yield db.createIndex(this.collectionName, ['uniqueField2']);
|
1718
|
-
indexes = yield this.
|
1771
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1719
1772
|
assert.isLength(indexes, 2);
|
1720
|
-
assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1773
|
+
assert.isEqual(indexes[1].fields[0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1721
1774
|
yield db.createIndex(this.collectionName, [
|
1722
1775
|
'uniqueField3',
|
1723
1776
|
'uniqueField4',
|
1724
1777
|
]);
|
1725
|
-
indexes = yield this.
|
1778
|
+
indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1726
1779
|
assert.isLength(indexes, 3);
|
1727
|
-
assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
1728
|
-
assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
1780
|
+
assert.isEqual(indexes[2].fields[0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
1781
|
+
assert.isEqual(indexes[2].fields[1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
1729
1782
|
yield this.shutdown(db);
|
1730
1783
|
});
|
1731
1784
|
},
|
@@ -1886,9 +1939,9 @@ const databaseAssertUtil = {
|
|
1886
1939
|
return __awaiter(this, void 0, void 0, function* () {
|
1887
1940
|
const db = yield connectToDabatase(connect);
|
1888
1941
|
yield db.createIndex(this.collectionName, fields);
|
1889
|
-
const indexes = yield this.
|
1942
|
+
const indexes = yield this._getIndexesWith_IdFilteredOut(db);
|
1890
1943
|
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!`);
|
1891
|
-
assert.isEqualDeep(indexes[0].map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
1944
|
+
assert.isEqualDeep(indexes[0].fields.map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
1892
1945
|
yield this.shutdown(db);
|
1893
1946
|
});
|
1894
1947
|
},
|
@@ -1903,11 +1956,11 @@ function assertCantCreateUniqueIndexTwice(db, collectionName, fields, expectedTo
|
|
1903
1956
|
return __awaiter(this, void 0, void 0, function* () {
|
1904
1957
|
yield db.createUniqueIndex(collectionName, fields);
|
1905
1958
|
let indexes = yield db.getUniqueIndexes(collectionName);
|
1906
|
-
assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return
|
1907
|
-
const err = yield assert.doesThrowAsync(() => db.createUniqueIndex(collectionName,
|
1959
|
+
assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return all unique indexes');
|
1960
|
+
const err = yield assert.doesThrowAsync(() => db.createUniqueIndex(collectionName, fields), undefined, 'createUniqueIndex() should throw a DataStoreError({code: "INDEX_EXISTS"}) error.');
|
1908
1961
|
errorAssert.assertError(err, 'INDEX_EXISTS', {
|
1909
1962
|
collectionName,
|
1910
|
-
index:
|
1963
|
+
index: fields,
|
1911
1964
|
});
|
1912
1965
|
});
|
1913
1966
|
}
|
@@ -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/build/index.d.ts
CHANGED
@@ -21,7 +21,7 @@ export * from './cursors/CursorPager';
|
|
21
21
|
export { default as CursorPagerFaker } from './cursors/CursorPagerFaker';
|
22
22
|
export * from './cursors/CursorPager';
|
23
23
|
export { default as DatabaseFieldMapperPlugin } from './plugins/DatabaseFieldMapperPlugin';
|
24
|
-
export
|
24
|
+
export * from './databases/database.utilities';
|
25
25
|
/**
|
26
26
|
* @deprecated databaseAssertUtil -> databaseAssert
|
27
27
|
*/
|
package/build/index.js
CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
18
|
};
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
-
exports.BatchArrayCursor = exports.BatchCursorImpl = exports.storePluginAssert = exports.databaseAssert = exports.databaseAssertUtil = exports.
|
20
|
+
exports.BatchArrayCursor = exports.BatchCursorImpl = exports.storePluginAssert = exports.databaseAssert = exports.databaseAssertUtil = exports.DatabaseFieldMapperPlugin = exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.DataStoresError = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
|
21
21
|
var AbstractDatabaseTest_1 = require("./tests/AbstractDatabaseTest");
|
22
22
|
Object.defineProperty(exports, "AbstractDatabaseTest", { enumerable: true, get: function () { return __importDefault(AbstractDatabaseTest_1).default; } });
|
23
23
|
var DatabaseFixture_1 = require("./fixtures/DatabaseFixture");
|
@@ -55,8 +55,7 @@ Object.defineProperty(exports, "CursorPagerFaker", { enumerable: true, get: func
|
|
55
55
|
__exportStar(require("./cursors/CursorPager"), exports);
|
56
56
|
var DatabaseFieldMapperPlugin_1 = require("./plugins/DatabaseFieldMapperPlugin");
|
57
57
|
Object.defineProperty(exports, "DatabaseFieldMapperPlugin", { enumerable: true, get: function () { return __importDefault(DatabaseFieldMapperPlugin_1).default; } });
|
58
|
-
|
59
|
-
Object.defineProperty(exports, "normalizeIndex", { enumerable: true, get: function () { return __importDefault(normalizeIndex_1).default; } });
|
58
|
+
__exportStar(require("./databases/database.utilities"), exports);
|
60
59
|
/**
|
61
60
|
* @deprecated databaseAssertUtil -> databaseAssert
|
62
61
|
*/
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { Database,
|
1
|
+
import { Database, IndexWithFilter, TestConnect } from '../types/database.types';
|
2
2
|
import { DataStore } from '../types/stores.types';
|
3
3
|
declare const databaseAssertUtil: {
|
4
4
|
collectionName: string;
|
5
5
|
runSuite(connect: TestConnect, tests?: string[]): Promise<void>;
|
6
|
-
|
7
|
-
|
6
|
+
_getIndexesWith_IdFilteredOut(db: Database): Promise<IndexWithFilter[]>;
|
7
|
+
_filterOut_Id(allIndexes: IndexWithFilter[]): IndexWithFilter[];
|
8
8
|
_assertUpdateUpdatedRightNumberOfRecords(db: Database, search: Record<string, any>, updates: Record<string, any>, expectedUpdateCount: number): Promise<void>;
|
9
9
|
generateIdDifferentEachTime(connect: TestConnect): Promise<void>;
|
10
10
|
assertCanSortDesc(connect: TestConnect): Promise<void>;
|
@@ -64,6 +64,7 @@ declare const databaseAssertUtil: {
|
|
64
64
|
assertCanSaveAndGetNullAndUndefined(connect: TestConnect): Promise<void>;
|
65
65
|
assertSyncIndexesDoesNotRemoveExisting(connect: TestConnect): Promise<void>;
|
66
66
|
assertCanSyncUniqueIndexesWithFilterExpression(connect: TestConnect): Promise<void>;
|
67
|
+
assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates(connect: TestConnect): Promise<void>;
|
67
68
|
assertSyncIndexesRemovesExtraIndexes(connect: TestConnect): Promise<void>;
|
68
69
|
assertSyncIndexesSkipsExisting(connect: TestConnect): Promise<void>;
|
69
70
|
assertCantDropCompoundIndexThatDoesNotExist(connect: TestConnect): Promise<void>;
|