@sprucelabs/data-stores 28.2.0 → 28.3.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/build/databases/MongoDatabase.js +3 -3
- package/build/esm/databases/MongoDatabase.js +3 -3
- package/build/esm/tests/databaseAssertUtil.d.ts +3 -1
- package/build/esm/tests/databaseAssertUtil.js +16 -4
- package/build/tests/databaseAssertUtil.d.ts +3 -1
- package/build/tests/databaseAssertUtil.js +15 -3
- package/package.json +1 -1
@@ -342,6 +342,9 @@ class MongoDatabase {
|
|
342
342
|
var _a;
|
343
343
|
const currentIndexes = await this.getIndexes(collectionName, shouldIncludeUnique);
|
344
344
|
const indexesToDelete = (0, database_utilities_1.pluckMissingIndexes)(currentIndexes, indexes);
|
345
|
+
for (const extra of indexesToDelete) {
|
346
|
+
await this.dropIndex(collectionName, extra);
|
347
|
+
}
|
345
348
|
for (const index of indexes) {
|
346
349
|
if (!this.doesInclude(currentIndexes, this.normalizeIndex(index))) {
|
347
350
|
try {
|
@@ -354,9 +357,6 @@ class MongoDatabase {
|
|
354
357
|
}
|
355
358
|
}
|
356
359
|
}
|
357
|
-
for (const extra of indexesToDelete) {
|
358
|
-
await this.dropIndex(collectionName, extra);
|
359
|
-
}
|
360
360
|
}
|
361
361
|
async createUniqueIndex(collection, index) {
|
362
362
|
const currentIndexes = await this.getUniqueIndexes(collection);
|
@@ -378,6 +378,9 @@ export default class MongoDatabase {
|
|
378
378
|
var _a;
|
379
379
|
const currentIndexes = yield this.getIndexes(collectionName, shouldIncludeUnique);
|
380
380
|
const indexesToDelete = pluckMissingIndexes(currentIndexes, indexes);
|
381
|
+
for (const extra of indexesToDelete) {
|
382
|
+
yield this.dropIndex(collectionName, extra);
|
383
|
+
}
|
381
384
|
for (const index of indexes) {
|
382
385
|
if (!this.doesInclude(currentIndexes, this.normalizeIndex(index))) {
|
383
386
|
try {
|
@@ -390,9 +393,6 @@ export default class MongoDatabase {
|
|
390
393
|
}
|
391
394
|
}
|
392
395
|
}
|
393
|
-
for (const extra of indexesToDelete) {
|
394
|
-
yield this.dropIndex(collectionName, extra);
|
395
|
-
}
|
396
396
|
});
|
397
397
|
}
|
398
398
|
createUniqueIndex(collection, index) {
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Database, IndexWithFilter, TestConnect } from '../types/database.types';
|
2
2
|
import { DataStore } from '../types/stores.types';
|
3
3
|
declare const methods: readonly ["assertThrowsWithInvalidConnectionString", "assertThrowsWhenCantConnect", "assertThrowsWithBadDatabaseName", "assertKnowsIfConnectionClosed", "assertCanSortDesc", "assertCanSortAsc", "assertCanSortById", "assertCanQueryWithOr", "assertGeneratesIdDifferentEachTime", "assertInsertingGeneratesId", "assertCanCreateMany", "assertCanCreateWithObjectField", "assertCanCountOnId", "assertCanCount", "assertThrowsWhenUpdatingRecordNotFound", "assertCanUpdate", "assertCanUpdateMany", "assertCanPushOntoArrayValue", "assertCanUpdateWithObjectField", "assertCanUpdateFieldInObjectFieldWithTargettedWhere", "assertCanSaveAndGetNullAndUndefined", "assertCanUpsertOne", "assertCanUpsertNull", "assertCanPushToArrayOnUpsert", "assertCanSyncUniqueIndexesWithFilterExpression", "assertEmptyDatabaseReturnsEmptyArray", "assertFindOneOnEmptyDatabaseReturnsNull", "assertCanLimitResults", "assertCanLimitResultsToZero", "assertCanFindWithBooleanField", "assertCanQueryByGtLtGteLteNe", "assertCanQueryPathWithDotSyntax", "assertCanReturnOnlySelectFields", "assertCanSearchByRegex", "assertCanFindWithNe", "assertCanFindWithIn", "assertCanDeleteRecord", "assertCanDeleteOne", "assertHasNoUniqueIndexToStart", "assertCanCreateUniqueIndex", "assertCanCreateMultiFieldUniqueIndex", "assertCantCreateUniqueIndexTwice", "assertCanDropUniqueIndex", "assertCanDropCompoundUniqueIndex", "assertCantDropUniqueIndexThatDoesntExist", "assertCantDropIndexWhenNoIndexExists", "assertCantDropCompoundUniqueIndexThatDoesntExist", "assertSyncingUniqueIndexsAddsMissingIndexes", "assertSyncingUniqueIndexsSkipsExistingIndexs", "assertSyncingUniqueIndexesRemovesExtraIndexes", "assertSyncingUniqueIndexesIsRaceProof", "assertSyncingIndexesDoesNotAddAndRemove", "assertUniqueIndexBlocksDuplicates", "assertDuplicateKeyThrowsOnInsert", "assertSettingUniqueIndexViolationThrowsSpruceError", "assertCanCreateUniqueIndexOnNestedField", "assertUpsertWithUniqueIndex", "assertNestedFieldIndexUpdates", "assertHasNoIndexToStart", "assertCanCreateIndex", "assertCantCreateSameIndexTwice", "assertCanCreateMultiFieldIndex", "assertCanDropIndex", "assertCanDropCompoundIndex", "assertCantDropCompoundIndexThatDoesNotExist", "assertSyncIndexesSkipsExisting", "assertSyncIndexesRemovesExtraIndexes", "assertSyncIndexesHandlesRaceConditions", "assertSyncIndexesDoesNotRemoveExisting", "assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected", "assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates"];
|
4
|
-
|
4
|
+
type OriginalMethods = (typeof methods)[number];
|
5
|
+
type BangMethods = `!${OriginalMethods}`;
|
6
|
+
export type DatabaseAssertionName = OriginalMethods | BangMethods;
|
5
7
|
declare const databaseAssertUtil: {
|
6
8
|
collectionName: string;
|
7
9
|
runSuite(connect: TestConnect, tests?: DatabaseAssertionName[]): Promise<void>;
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
8
|
});
|
9
9
|
};
|
10
|
-
import { assertOptions } from '@sprucelabs/schema';
|
10
|
+
import { assertOptions, SchemaError } from '@sprucelabs/schema';
|
11
11
|
import { assert } from '@sprucelabs/test-utils';
|
12
12
|
import { errorAssert } from '@sprucelabs/test-utils';
|
13
13
|
import generateId from '../utilities/generateId.js';
|
@@ -100,9 +100,21 @@ const databaseAssertUtil = {
|
|
100
100
|
const db = yield connectToDabatase(connect);
|
101
101
|
yield db.dropDatabase();
|
102
102
|
yield this.shutdown(db);
|
103
|
-
|
104
|
-
|
105
|
-
tests
|
103
|
+
const hasIgnore = tests === null || tests === void 0 ? void 0 : tests.find((t) => t.startsWith('!'));
|
104
|
+
if (hasIgnore && tests) {
|
105
|
+
for (const method of tests) {
|
106
|
+
if (!method.startsWith('!')) {
|
107
|
+
throw new SchemaError({
|
108
|
+
code: 'INVALID_PARAMETERS',
|
109
|
+
parameters: ['tests'],
|
110
|
+
});
|
111
|
+
}
|
112
|
+
}
|
113
|
+
const doesMatch = (m) => {
|
114
|
+
return !!tests.find((t) => t.substring(1) === m);
|
115
|
+
};
|
116
|
+
const filtered = methods.filter((m) => !doesMatch(m));
|
117
|
+
tests = filtered;
|
106
118
|
}
|
107
119
|
const toRun = tests !== null && tests !== void 0 ? tests : methods;
|
108
120
|
for (const method of toRun) {
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Database, IndexWithFilter, TestConnect } from '../types/database.types';
|
2
2
|
import { DataStore } from '../types/stores.types';
|
3
3
|
declare const methods: readonly ["assertThrowsWithInvalidConnectionString", "assertThrowsWhenCantConnect", "assertThrowsWithBadDatabaseName", "assertKnowsIfConnectionClosed", "assertCanSortDesc", "assertCanSortAsc", "assertCanSortById", "assertCanQueryWithOr", "assertGeneratesIdDifferentEachTime", "assertInsertingGeneratesId", "assertCanCreateMany", "assertCanCreateWithObjectField", "assertCanCountOnId", "assertCanCount", "assertThrowsWhenUpdatingRecordNotFound", "assertCanUpdate", "assertCanUpdateMany", "assertCanPushOntoArrayValue", "assertCanUpdateWithObjectField", "assertCanUpdateFieldInObjectFieldWithTargettedWhere", "assertCanSaveAndGetNullAndUndefined", "assertCanUpsertOne", "assertCanUpsertNull", "assertCanPushToArrayOnUpsert", "assertCanSyncUniqueIndexesWithFilterExpression", "assertEmptyDatabaseReturnsEmptyArray", "assertFindOneOnEmptyDatabaseReturnsNull", "assertCanLimitResults", "assertCanLimitResultsToZero", "assertCanFindWithBooleanField", "assertCanQueryByGtLtGteLteNe", "assertCanQueryPathWithDotSyntax", "assertCanReturnOnlySelectFields", "assertCanSearchByRegex", "assertCanFindWithNe", "assertCanFindWithIn", "assertCanDeleteRecord", "assertCanDeleteOne", "assertHasNoUniqueIndexToStart", "assertCanCreateUniqueIndex", "assertCanCreateMultiFieldUniqueIndex", "assertCantCreateUniqueIndexTwice", "assertCanDropUniqueIndex", "assertCanDropCompoundUniqueIndex", "assertCantDropUniqueIndexThatDoesntExist", "assertCantDropIndexWhenNoIndexExists", "assertCantDropCompoundUniqueIndexThatDoesntExist", "assertSyncingUniqueIndexsAddsMissingIndexes", "assertSyncingUniqueIndexsSkipsExistingIndexs", "assertSyncingUniqueIndexesRemovesExtraIndexes", "assertSyncingUniqueIndexesIsRaceProof", "assertSyncingIndexesDoesNotAddAndRemove", "assertUniqueIndexBlocksDuplicates", "assertDuplicateKeyThrowsOnInsert", "assertSettingUniqueIndexViolationThrowsSpruceError", "assertCanCreateUniqueIndexOnNestedField", "assertUpsertWithUniqueIndex", "assertNestedFieldIndexUpdates", "assertHasNoIndexToStart", "assertCanCreateIndex", "assertCantCreateSameIndexTwice", "assertCanCreateMultiFieldIndex", "assertCanDropIndex", "assertCanDropCompoundIndex", "assertCantDropCompoundIndexThatDoesNotExist", "assertSyncIndexesSkipsExisting", "assertSyncIndexesRemovesExtraIndexes", "assertSyncIndexesHandlesRaceConditions", "assertSyncIndexesDoesNotRemoveExisting", "assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected", "assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates"];
|
4
|
-
|
4
|
+
type OriginalMethods = (typeof methods)[number];
|
5
|
+
type BangMethods = `!${OriginalMethods}`;
|
6
|
+
export type DatabaseAssertionName = OriginalMethods | BangMethods;
|
5
7
|
declare const databaseAssertUtil: {
|
6
8
|
collectionName: string;
|
7
9
|
runSuite(connect: TestConnect, tests?: DatabaseAssertionName[]): Promise<void>;
|
@@ -95,9 +95,21 @@ const databaseAssertUtil = {
|
|
95
95
|
const db = await connectToDabatase(connect);
|
96
96
|
await db.dropDatabase();
|
97
97
|
await this.shutdown(db);
|
98
|
-
|
99
|
-
|
100
|
-
tests
|
98
|
+
const hasIgnore = tests === null || tests === void 0 ? void 0 : tests.find((t) => t.startsWith('!'));
|
99
|
+
if (hasIgnore && tests) {
|
100
|
+
for (const method of tests) {
|
101
|
+
if (!method.startsWith('!')) {
|
102
|
+
throw new schema_1.SchemaError({
|
103
|
+
code: 'INVALID_PARAMETERS',
|
104
|
+
parameters: ['tests'],
|
105
|
+
});
|
106
|
+
}
|
107
|
+
}
|
108
|
+
const doesMatch = (m) => {
|
109
|
+
return !!tests.find((t) => t.substring(1) === m);
|
110
|
+
};
|
111
|
+
const filtered = methods.filter((m) => !doesMatch(m));
|
112
|
+
tests = filtered;
|
101
113
|
}
|
102
114
|
const toRun = tests !== null && tests !== void 0 ? tests : methods;
|
103
115
|
for (const method of toRun) {
|