@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
@@ -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,55 @@ 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
|
+
await this.shutdown(db);
|
1522
|
+
},
|
1473
1523
|
async assertSyncIndexesRemovesExtraIndexes(connect) {
|
1474
1524
|
const db = await connectToDabatase(connect);
|
1475
1525
|
await db.syncIndexes(this.collectionName, [
|
@@ -1477,26 +1527,27 @@ const databaseAssertUtil = {
|
|
1477
1527
|
['someField'],
|
1478
1528
|
['otherField', 'otherField2'],
|
1479
1529
|
]);
|
1480
|
-
let indexes = await this.
|
1530
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1481
1531
|
test_utils_1.assert.isLength(indexes, 3);
|
1482
1532
|
await db.syncIndexes(this.collectionName, [['name']]);
|
1483
|
-
indexes = await this.
|
1533
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1484
1534
|
test_utils_1.assert.isLength(indexes, 1);
|
1485
|
-
test_utils_1.assert.isEqual(indexes[0][0], 'name');
|
1535
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0], 'name');
|
1486
1536
|
await this.shutdown(db);
|
1487
1537
|
},
|
1488
1538
|
async assertSyncIndexesSkipsExisting(connect) {
|
1489
1539
|
const db = await connectToDabatase(connect);
|
1490
1540
|
await db.syncIndexes(this.collectionName, [['name']]);
|
1491
|
-
let indexes = await this.
|
1541
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1492
1542
|
test_utils_1.assert.isLength(indexes, 1);
|
1543
|
+
test_utils_1.assert.isLength(indexes[0].fields, 1);
|
1493
1544
|
await db.syncIndexes(this.collectionName, [
|
1494
1545
|
['name'],
|
1495
1546
|
['someField'],
|
1496
1547
|
['otherField', 'otherField2'],
|
1497
1548
|
]);
|
1498
|
-
indexes = await this.
|
1499
|
-
test_utils_1.assert.isLength(indexes, 3);
|
1549
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1550
|
+
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
1551
|
await this.shutdown(db);
|
1501
1552
|
},
|
1502
1553
|
async assertCantDropCompoundIndexThatDoesNotExist(connect) {
|
@@ -1508,7 +1559,7 @@ const databaseAssertUtil = {
|
|
1508
1559
|
const err = await test_utils_1.assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['uniqueField', 'someOtherField']));
|
1509
1560
|
test_utils_2.errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
1510
1561
|
collectionName: this.collectionName,
|
1511
|
-
missingIndex: ['
|
1562
|
+
missingIndex: ['someOtherField', 'uniqueField'],
|
1512
1563
|
});
|
1513
1564
|
await this.shutdown(db);
|
1514
1565
|
},
|
@@ -1516,25 +1567,25 @@ const databaseAssertUtil = {
|
|
1516
1567
|
const db = await connectToDabatase(connect);
|
1517
1568
|
await db.createIndex(this.collectionName, ['someField', 'otherField']);
|
1518
1569
|
await db.dropIndex(this.collectionName, ['someField', 'otherField']);
|
1519
|
-
let indexes = await this.
|
1520
|
-
test_utils_1.assert.isLength(indexes, 0);
|
1570
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1571
|
+
test_utils_1.assert.isLength(indexes, 0, `The one index I created should have been dropped`);
|
1521
1572
|
await db.createIndex(this.collectionName, ['someField', 'someField2']);
|
1522
1573
|
await db.createIndex(this.collectionName, ['someField', 'someField3']);
|
1523
1574
|
await db.dropIndex(this.collectionName, ['someField', 'someField3']);
|
1524
|
-
indexes = await this.
|
1525
|
-
test_utils_1.assert.isLength(indexes, 1);
|
1575
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1576
|
+
test_utils_1.assert.isLength(indexes, 1, `I created 2 compound indexes, then dropped one, and expected 1 to remain.`);
|
1526
1577
|
await this.shutdown(db);
|
1527
1578
|
},
|
1528
1579
|
async assertCanDropIndex(connect) {
|
1529
1580
|
const db = await connectToDabatase(connect);
|
1530
1581
|
await db.createIndex(this.collectionName, ['someField']);
|
1531
1582
|
await db.dropIndex(this.collectionName, ['someField']);
|
1532
|
-
let indexes = await this.
|
1583
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1533
1584
|
test_utils_1.assert.isLength(indexes, 0);
|
1534
1585
|
await db.createIndex(this.collectionName, ['someField2']);
|
1535
1586
|
await db.createIndex(this.collectionName, ['someField3']);
|
1536
1587
|
await db.dropIndex(this.collectionName, ['someField3']);
|
1537
|
-
indexes = await this.
|
1588
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1538
1589
|
test_utils_1.assert.isLength(indexes, 1);
|
1539
1590
|
await this.shutdown(db);
|
1540
1591
|
},
|
@@ -1559,7 +1610,7 @@ const databaseAssertUtil = {
|
|
1559
1610
|
async assertCantCreateSameIndexTwice(connect) {
|
1560
1611
|
const db = await connectToDabatase(connect);
|
1561
1612
|
await db.createIndex(this.collectionName, ['name']);
|
1562
|
-
let indexes = await this.
|
1613
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1563
1614
|
test_utils_1.assert.isLength(indexes, 1);
|
1564
1615
|
const err = await test_utils_1.assert.doesThrowAsync(() => db.createIndex(this.collectionName, ['name']));
|
1565
1616
|
test_utils_2.errorAssert.assertError(err, 'INDEX_EXISTS');
|
@@ -1568,23 +1619,23 @@ const databaseAssertUtil = {
|
|
1568
1619
|
async assertCanCreateIndex(connect) {
|
1569
1620
|
const db = await connectToDabatase(connect);
|
1570
1621
|
await db.createIndex(this.collectionName, ['uniqueField']);
|
1571
|
-
let indexes = await this.
|
1622
|
+
let indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1572
1623
|
test_utils_1.assert.isArray(indexes, 'getIndexes() should return an array!');
|
1573
1624
|
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());
|
1625
|
+
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!');
|
1626
|
+
test_utils_1.assert.isEqual(indexes[0].fields[0].toLowerCase(), 'uniqueField'.toLowerCase());
|
1576
1627
|
await db.createIndex(this.collectionName, ['uniqueField2']);
|
1577
|
-
indexes = await this.
|
1628
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1578
1629
|
test_utils_1.assert.isLength(indexes, 2);
|
1579
|
-
test_utils_1.assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1630
|
+
test_utils_1.assert.isEqual(indexes[1].fields[0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
1580
1631
|
await db.createIndex(this.collectionName, [
|
1581
1632
|
'uniqueField3',
|
1582
1633
|
'uniqueField4',
|
1583
1634
|
]);
|
1584
|
-
indexes = await this.
|
1635
|
+
indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1585
1636
|
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());
|
1637
|
+
test_utils_1.assert.isEqual(indexes[2].fields[0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
1638
|
+
test_utils_1.assert.isEqual(indexes[2].fields[1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
1588
1639
|
await this.shutdown(db);
|
1589
1640
|
},
|
1590
1641
|
async assertHasNoIndexToStart(connect) {
|
@@ -1729,9 +1780,9 @@ const databaseAssertUtil = {
|
|
1729
1780
|
async _assertCanCreateMultiFieldIndex(connect, fields) {
|
1730
1781
|
const db = await connectToDabatase(connect);
|
1731
1782
|
await db.createIndex(this.collectionName, fields);
|
1732
|
-
const indexes = await this.
|
1783
|
+
const indexes = await this._getIndexesWith_IdFilteredOut(db);
|
1733
1784
|
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()));
|
1785
|
+
test_utils_1.assert.isEqualDeep(indexes[0].fields.map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
1735
1786
|
await this.shutdown(db);
|
1736
1787
|
},
|
1737
1788
|
assertHasLowerCaseToCamelCaseMappingEnabled(store) {
|
@@ -1744,11 +1795,11 @@ exports.default = databaseAssertUtil;
|
|
1744
1795
|
async function assertCantCreateUniqueIndexTwice(db, collectionName, fields, expectedTotalUniqueIndexes) {
|
1745
1796
|
await db.createUniqueIndex(collectionName, fields);
|
1746
1797
|
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,
|
1798
|
+
test_utils_1.assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return all unique indexes');
|
1799
|
+
const err = await test_utils_1.assert.doesThrowAsync(() => db.createUniqueIndex(collectionName, fields), undefined, 'createUniqueIndex() should throw a DataStoreError({code: "INDEX_EXISTS"}) error.');
|
1749
1800
|
test_utils_2.errorAssert.assertError(err, 'INDEX_EXISTS', {
|
1750
1801
|
collectionName,
|
1751
|
-
index:
|
1802
|
+
index: fields,
|
1752
1803
|
});
|
1753
1804
|
}
|
1754
1805
|
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
@@ -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
|
-
}
|