@sprucelabs/data-stores 28.3.239 → 28.3.240

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.
@@ -403,10 +403,11 @@ class MongoDatabase {
403
403
  async update(collection, query, updates) {
404
404
  const q = this.toMongoIdAndNull(collection, query);
405
405
  const values = mongo_utility_1.default.prepareUpdates(updates);
406
- const { modifiedCount } = await this.assertDbWhileAttempingTo('update many records.', collection)
406
+ const results = await this.assertDbWhileAttempingTo('update many records.', collection)
407
407
  .collection(collection)
408
408
  .updateMany(q, values);
409
- return modifiedCount;
409
+ const { matchedCount } = results;
410
+ return matchedCount;
410
411
  }
411
412
  async updateOne(collection, query, updates) {
412
413
  const q = this.toMongoIdAndNull(collection, query);
@@ -219,7 +219,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
219
219
  });
220
220
  }
221
221
  async update(collection, query, updates, neDbOptions) {
222
- const results = this.updateOne(collection, query, updates, Object.assign(Object.assign({}, neDbOptions), { multi: true, returnUpdatedDocs: false }), 'update');
222
+ const results = await this.updateOne(collection, query, updates, Object.assign(Object.assign({}, neDbOptions), { multi: true, returnUpdatedDocs: false }), 'update');
223
223
  return results;
224
224
  }
225
225
  async updateOne(collection, query, updates, neDbOptions, action = 'updateOne') {
@@ -445,10 +445,11 @@ export default class MongoDatabase {
445
445
  return __awaiter(this, void 0, void 0, function* () {
446
446
  const q = this.toMongoIdAndNull(collection, query);
447
447
  const values = mongoUtil.prepareUpdates(updates);
448
- const { modifiedCount } = yield this.assertDbWhileAttempingTo('update many records.', collection)
448
+ const results = yield this.assertDbWhileAttempingTo('update many records.', collection)
449
449
  .collection(collection)
450
450
  .updateMany(q, values);
451
- return modifiedCount;
451
+ const { matchedCount } = results;
452
+ return matchedCount;
452
453
  });
453
454
  }
454
455
  updateOne(collection, query, updates) {
@@ -246,7 +246,7 @@ export default class NeDbDatabase extends AbstractMutexer {
246
246
  }
247
247
  update(collection, query, updates, neDbOptions) {
248
248
  return __awaiter(this, void 0, void 0, function* () {
249
- const results = this.updateOne(collection, query, updates, Object.assign(Object.assign({}, neDbOptions), { multi: true, returnUpdatedDocs: false }), 'update');
249
+ const results = yield this.updateOne(collection, query, updates, Object.assign(Object.assign({}, neDbOptions), { multi: true, returnUpdatedDocs: false }), 'update');
250
250
  return results;
251
251
  });
252
252
  }
@@ -1,6 +1,6 @@
1
1
  import { Database, IndexWithFilter, TestConnect } from '../types/database.types';
2
2
  import { DataStore } from '../types/stores.types';
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"];
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", "assertUpdateReturnsMatchedAndUpdatedCounts", "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
5
  type BangMethods = `!${OriginalMethods}`;
6
6
  export type DatabaseAssertionName = OriginalMethods | BangMethods;
@@ -87,6 +87,7 @@ declare const databaseAssertUtil: {
87
87
  _assertCanCreateMultiFieldIndex(connect: TestConnect, fields: string[]): Promise<void>;
88
88
  canUpdateNestedField(connect: TestConnect): Promise<void>;
89
89
  canUpsertNestedField(connect: TestConnect): Promise<void>;
90
+ assertUpdateReturnsMatchedAndUpdatedCounts(connect: TestConnect): Promise<void>;
90
91
  assertHasLowerCaseToCamelCaseMappingEnabled(store: DataStore): void;
91
92
  };
92
93
  export default databaseAssertUtil;
@@ -37,6 +37,7 @@ const methods = [
37
37
  'assertCanUpdateWithObjectField',
38
38
  'assertCanUpdateFieldInObjectFieldWithTargettedWhere',
39
39
  'assertCanSaveAndGetNullAndUndefined',
40
+ 'assertUpdateReturnsMatchedAndUpdatedCounts',
40
41
  //upserting
41
42
  'assertCanUpsertOne',
42
43
  'assertCanUpsertNull',
@@ -141,8 +142,8 @@ const databaseAssertUtil = {
141
142
  },
142
143
  _assertUpdateUpdatedRightNumberOfRecords(db, search, updates, expectedUpdateCount) {
143
144
  return __awaiter(this, void 0, void 0, function* () {
144
- const updatedCount = yield db.update(this.collectionName, search, updates);
145
- assert.isEqual(updatedCount, expectedUpdateCount, 'db.update() did not update the expected amount of records! Make sure it returns an integer of the number of records updated.');
145
+ const updated = yield db.update(this.collectionName, search, updates);
146
+ assert.isEqual(updated, expectedUpdateCount, 'db.update() did not update the expected amount of records! Make sure it returns an integer of the number of records updated.');
146
147
  const count = yield db.count(this.collectionName, updates);
147
148
  assert.isEqual(count, expectedUpdateCount);
148
149
  });
@@ -2005,6 +2006,27 @@ const databaseAssertUtil = {
2005
2006
  yield this.shutdown(db);
2006
2007
  });
2007
2008
  },
2009
+ assertUpdateReturnsMatchedAndUpdatedCounts(connect) {
2010
+ return __awaiter(this, void 0, void 0, function* () {
2011
+ const db = yield connectToDabatase(connect);
2012
+ const record = yield db.createOne(this.collectionName, {
2013
+ name: 'first',
2014
+ });
2015
+ let updated = yield db.update(this.collectionName, { id: record.id }, {
2016
+ name: 'second',
2017
+ });
2018
+ assert.isEqual(updated, 1, 'update() should return the number of matched records (in this case 1)');
2019
+ updated = yield db.update(this.collectionName, { id: record.id }, {
2020
+ name: 'second',
2021
+ });
2022
+ assert.isEqual(updated, 1, 'update() did not return the correct number of matched records (in this case 1)');
2023
+ updated = yield db.update(this.collectionName, { id: generateId() }, {
2024
+ name: 'second',
2025
+ });
2026
+ assert.isEqual(updated, 0, 'update() did not return the correct number of matched records on an update (in this case 0).');
2027
+ yield this.shutdown(db);
2028
+ });
2029
+ },
2008
2030
  assertHasLowerCaseToCamelCaseMappingEnabled(store) {
2009
2031
  assert.isTrue(
2010
2032
  //@ts-ignore
@@ -1,6 +1,6 @@
1
1
  import { Database, IndexWithFilter, TestConnect } from '../types/database.types';
2
2
  import { DataStore } from '../types/stores.types';
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"];
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", "assertUpdateReturnsMatchedAndUpdatedCounts", "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
5
  type BangMethods = `!${OriginalMethods}`;
6
6
  export type DatabaseAssertionName = OriginalMethods | BangMethods;
@@ -87,6 +87,7 @@ declare const databaseAssertUtil: {
87
87
  _assertCanCreateMultiFieldIndex(connect: TestConnect, fields: string[]): Promise<void>;
88
88
  canUpdateNestedField(connect: TestConnect): Promise<void>;
89
89
  canUpsertNestedField(connect: TestConnect): Promise<void>;
90
+ assertUpdateReturnsMatchedAndUpdatedCounts(connect: TestConnect): Promise<void>;
90
91
  assertHasLowerCaseToCamelCaseMappingEnabled(store: DataStore): void;
91
92
  };
92
93
  export default databaseAssertUtil;
@@ -33,6 +33,7 @@ const methods = [
33
33
  'assertCanUpdateWithObjectField',
34
34
  'assertCanUpdateFieldInObjectFieldWithTargettedWhere',
35
35
  'assertCanSaveAndGetNullAndUndefined',
36
+ 'assertUpdateReturnsMatchedAndUpdatedCounts',
36
37
  //upserting
37
38
  'assertCanUpsertOne',
38
39
  'assertCanUpsertNull',
@@ -132,8 +133,8 @@ const databaseAssertUtil = {
132
133
  return allIndexes.filter((i) => i.fields[0] !== '_id');
133
134
  },
134
135
  async _assertUpdateUpdatedRightNumberOfRecords(db, search, updates, expectedUpdateCount) {
135
- const updatedCount = await db.update(this.collectionName, search, updates);
136
- test_utils_1.assert.isEqual(updatedCount, expectedUpdateCount, 'db.update() did not update the expected amount of records! Make sure it returns an integer of the number of records updated.');
136
+ const updated = await db.update(this.collectionName, search, updates);
137
+ test_utils_1.assert.isEqual(updated, expectedUpdateCount, 'db.update() did not update the expected amount of records! Make sure it returns an integer of the number of records updated.');
137
138
  const count = await db.count(this.collectionName, updates);
138
139
  test_utils_1.assert.isEqual(count, expectedUpdateCount);
139
140
  },
@@ -1841,6 +1842,25 @@ const databaseAssertUtil = {
1841
1842
  test_utils_1.assert.isEqual(match.target.locationId, locationId, `Upserting lost existing key 'target.locationId'`);
1842
1843
  await this.shutdown(db);
1843
1844
  },
1845
+ async assertUpdateReturnsMatchedAndUpdatedCounts(connect) {
1846
+ const db = await connectToDabatase(connect);
1847
+ const record = await db.createOne(this.collectionName, {
1848
+ name: 'first',
1849
+ });
1850
+ let updated = await db.update(this.collectionName, { id: record.id }, {
1851
+ name: 'second',
1852
+ });
1853
+ test_utils_1.assert.isEqual(updated, 1, 'update() should return the number of matched records (in this case 1)');
1854
+ updated = await db.update(this.collectionName, { id: record.id }, {
1855
+ name: 'second',
1856
+ });
1857
+ test_utils_1.assert.isEqual(updated, 1, 'update() did not return the correct number of matched records (in this case 1)');
1858
+ updated = await db.update(this.collectionName, { id: (0, generateId_1.default)() }, {
1859
+ name: 'second',
1860
+ });
1861
+ test_utils_1.assert.isEqual(updated, 0, 'update() did not return the correct number of matched records on an update (in this case 0).');
1862
+ await this.shutdown(db);
1863
+ },
1844
1864
  assertHasLowerCaseToCamelCaseMappingEnabled(store) {
1845
1865
  test_utils_1.assert.isTrue(
1846
1866
  //@ts-ignore
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "28.3.239",
6
+ "version": "28.3.240",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",