@sprucelabs/data-stores 26.4.35 → 26.4.37
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/esm/cursors/BatchArrayCursor.js +1 -1
- package/build/esm/cursors/BatchCursor.js +1 -1
- package/build/esm/databases/MongoDatabase.js +4 -4
- package/build/esm/databases/NeDbDatabase.js +9 -9
- package/build/esm/factories/StoreFactory.js +1 -1
- package/build/esm/loaders/StoreLoader.js +1 -1
- package/build/esm/stores/AbstractStore.js +26 -26
- package/build/esm/tests/databaseAssertUtil.js +4 -4
- package/package.json +8 -8
|
@@ -24,8 +24,8 @@ export default class BatchArrayCursor {
|
|
|
24
24
|
this.onNextResultsHandler = cb;
|
|
25
25
|
}
|
|
26
26
|
next() {
|
|
27
|
-
var _a, _b;
|
|
28
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b;
|
|
29
29
|
const { batchSize = 10 } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
30
30
|
const i = this.items.slice(this.currenIndex, this.currenIndex + batchSize);
|
|
31
31
|
this.currenIndex += batchSize;
|
|
@@ -47,8 +47,8 @@ export default class BatchCursorImpl {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
next() {
|
|
50
|
-
var _a, _b;
|
|
51
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
var _a, _b;
|
|
52
52
|
const _c = (_a = this.options) !== null && _a !== void 0 ? _a : {}, { batchSize = 10 } = _c, rest = __rest(_c, ["batchSize"]);
|
|
53
53
|
let query = Object.assign({}, this.query);
|
|
54
54
|
if (this.lastId) {
|
|
@@ -60,8 +60,8 @@ export default class MongoDatabase {
|
|
|
60
60
|
return generateId();
|
|
61
61
|
}
|
|
62
62
|
delete(collection, query) {
|
|
63
|
-
var _a;
|
|
64
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
65
|
const results = yield this.assertDbWhileAttempingTo('delete many records', collection)
|
|
66
66
|
.collection(collection)
|
|
67
67
|
.deleteMany(this.toMongoIdAndNull(collection, query));
|
|
@@ -69,8 +69,8 @@ export default class MongoDatabase {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
deleteOne(collection, query) {
|
|
72
|
-
var _a;
|
|
73
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
var _a;
|
|
74
74
|
const results = yield this.assertDbWhileAttempingTo('delete one record', collection)
|
|
75
75
|
.collection(collection)
|
|
76
76
|
.deleteOne(this.toMongoIdAndNull(collection, query));
|
|
@@ -295,8 +295,8 @@ export default class MongoDatabase {
|
|
|
295
295
|
}
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
|
-
getIndexes(
|
|
299
|
-
return __awaiter(this,
|
|
298
|
+
getIndexes(collection_1) {
|
|
299
|
+
return __awaiter(this, arguments, void 0, function* (collection, shouldIncludeUnique = false) {
|
|
300
300
|
try {
|
|
301
301
|
const indexes = yield this.listIndexes(collection);
|
|
302
302
|
if (shouldIncludeUnique) {
|
|
@@ -248,8 +248,8 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
248
248
|
return results;
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
|
-
updateOne(
|
|
252
|
-
return __awaiter(this,
|
|
251
|
+
updateOne(collection_1, query_1, updates_1, neDbOptions_1) {
|
|
252
|
+
return __awaiter(this, arguments, void 0, function* (collection, query, updates, neDbOptions, action = 'updateOne') {
|
|
253
253
|
const preppedQuery = this.prepQuery(query);
|
|
254
254
|
const mutexKey = 'updateMutex';
|
|
255
255
|
yield this.lock(mutexKey);
|
|
@@ -348,16 +348,16 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
getUniqueIndexes(collection) {
|
|
351
|
-
var _a;
|
|
352
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
352
|
+
var _a;
|
|
353
353
|
const col = this.loadCollection(collection);
|
|
354
354
|
yield this.randomDelay();
|
|
355
355
|
return (_a = col._uniqueIndexes) !== null && _a !== void 0 ? _a : [];
|
|
356
356
|
});
|
|
357
357
|
}
|
|
358
|
-
getIndexes(
|
|
359
|
-
|
|
360
|
-
|
|
358
|
+
getIndexes(collection_1) {
|
|
359
|
+
return __awaiter(this, arguments, void 0, function* (collection, shouldIncludeUnique = false) {
|
|
360
|
+
var _a, _b, _c;
|
|
361
361
|
const col = this.loadCollection(collection);
|
|
362
362
|
yield this.randomDelay();
|
|
363
363
|
if (shouldIncludeUnique) {
|
|
@@ -368,8 +368,8 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
370
|
dropIndex(collection, fields) {
|
|
371
|
-
var _a, _b;
|
|
372
371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
var _a, _b;
|
|
373
373
|
const col = this.loadCollection(collection);
|
|
374
374
|
yield this.randomDelay();
|
|
375
375
|
let found = false;
|
|
@@ -470,8 +470,8 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
470
470
|
});
|
|
471
471
|
}
|
|
472
472
|
syncUniqueIndexes(collectionName, indexes) {
|
|
473
|
-
var _a;
|
|
474
473
|
return __awaiter(this, void 0, void 0, function* () {
|
|
474
|
+
var _a;
|
|
475
475
|
const currentIndexes = yield this.getUniqueIndexes(collectionName);
|
|
476
476
|
const extraIndexes = differenceWith(currentIndexes, indexes, isEqual);
|
|
477
477
|
for (const index of indexes) {
|
|
@@ -492,8 +492,8 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
syncIndexes(collectionName, indexes) {
|
|
495
|
-
var _a;
|
|
496
495
|
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
var _a;
|
|
497
497
|
const currentIndexes = yield this.getIndexes(collectionName);
|
|
498
498
|
const extraIndexes = differenceWith(currentIndexes, indexes, isEqual);
|
|
499
499
|
for (const index of indexes) {
|
|
@@ -83,8 +83,8 @@ class StoreLoader {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
loadStoreClassesWithErrors() {
|
|
86
|
-
var _a, _b;
|
|
87
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b;
|
|
88
88
|
const combinedFile = diskUtil.resolveFile(this.activeDir, HASH_SPRUCE_DIR_NAME, 'stores', 'stores');
|
|
89
89
|
if (!combinedFile) {
|
|
90
90
|
return { stores: [], errors: [] };
|
|
@@ -45,9 +45,9 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
45
45
|
getCollectionName() {
|
|
46
46
|
return this.collectionName;
|
|
47
47
|
}
|
|
48
|
-
prepareAndNormalizeRecord(
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
prepareAndNormalizeRecord(record_1) {
|
|
49
|
+
return __awaiter(this, arguments, void 0, function* (record, options = {}) {
|
|
50
|
+
var _a, _b, _c;
|
|
51
51
|
let preparedRecord = this.prepareRecord
|
|
52
52
|
? yield this.prepareRecord(record, options)
|
|
53
53
|
: record;
|
|
@@ -98,8 +98,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
createOne(values, options) {
|
|
101
|
-
var _a;
|
|
102
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a;
|
|
103
103
|
try {
|
|
104
104
|
//@ts-ignore
|
|
105
105
|
validateSchemaValues(this.createSchema, values);
|
|
@@ -151,8 +151,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
151
151
|
return toSave;
|
|
152
152
|
}
|
|
153
153
|
handleWillCreatePlugins(values) {
|
|
154
|
-
var _a;
|
|
155
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
var _a;
|
|
156
156
|
let valuesToMixinBeforeCreate = {};
|
|
157
157
|
let newValues = values;
|
|
158
158
|
for (const plugin of this.plugins) {
|
|
@@ -169,8 +169,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
handleDidCreateForPlugins(record) {
|
|
172
|
-
var _a;
|
|
173
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
var _a;
|
|
174
174
|
let mixinValuesOnReturn = {};
|
|
175
175
|
for (const plugin of this.plugins) {
|
|
176
176
|
const r = yield ((_a = plugin.didCreateOne) === null || _a === void 0 ? void 0 : _a.call(plugin, record));
|
|
@@ -182,15 +182,15 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
182
182
|
get primaryFieldName() {
|
|
183
183
|
return this.primaryFieldNames[0];
|
|
184
184
|
}
|
|
185
|
-
findOne(
|
|
186
|
-
return __awaiter(this,
|
|
185
|
+
findOne(query_1) {
|
|
186
|
+
return __awaiter(this, arguments, void 0, function* (query, options = {}) {
|
|
187
187
|
return this._findOne(query, options);
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
_findOne(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
190
|
+
_findOne(query_1) {
|
|
191
|
+
return __awaiter(this, arguments, void 0, function* (query, options = {}, internalOptions = {
|
|
192
|
+
shouldTriggerWillQuery: true,
|
|
193
|
+
}) {
|
|
194
194
|
const results = yield this._find(query, { limit: 1 }, options, internalOptions);
|
|
195
195
|
let match = results[0];
|
|
196
196
|
if (match) {
|
|
@@ -201,8 +201,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
handleDidFindForPlugins(query, match) {
|
|
204
|
-
var _a, _b;
|
|
205
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
var _a, _b;
|
|
206
206
|
for (const plugin of this.plugins) {
|
|
207
207
|
const { valuesToMixinBeforeReturning: values } = (_b = (yield ((_a = plugin.didFindOne) === null || _a === void 0 ? void 0 : _a.call(plugin, query, match)))) !== null && _b !== void 0 ? _b : {};
|
|
208
208
|
if (values) {
|
|
@@ -223,11 +223,11 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
223
223
|
return this._find(query, queryOptions, options);
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
_find(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
_find(query_1, queryOptions_1, options_1) {
|
|
227
|
+
return __awaiter(this, arguments, void 0, function* (query, queryOptions, options, internalOptions = {
|
|
228
|
+
shouldTriggerWillQuery: true,
|
|
229
|
+
}) {
|
|
230
|
+
var _a, _b;
|
|
231
231
|
let resolvedQuery = query;
|
|
232
232
|
let resolvedOptions = queryOptions;
|
|
233
233
|
const { shouldTriggerWillQuery } = internalOptions;
|
|
@@ -252,8 +252,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
254
|
handleWillFindPlugins(query, queryOptions) {
|
|
255
|
-
var _a, _b;
|
|
256
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
var _a, _b;
|
|
257
257
|
const plugin = this.plugins[0];
|
|
258
258
|
const { query: pluginQuery, options: pluginOptions } = (_b = (yield ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.willFind) === null || _a === void 0 ? void 0 : _a.call(plugin, query, queryOptions)))) !== null && _b !== void 0 ? _b : {};
|
|
259
259
|
query = pluginQuery !== null && pluginQuery !== void 0 ? pluginQuery : query;
|
|
@@ -314,9 +314,9 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
314
314
|
return this.db.update(this.collectionName, query, updates);
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
|
-
findOneAndUpdate(
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
findOneAndUpdate(query_1, updates_1, notFoundHandler_1) {
|
|
318
|
+
return __awaiter(this, arguments, void 0, function* (query, updates, notFoundHandler, options = {}) {
|
|
319
|
+
var _a, _b, _c;
|
|
320
320
|
let { ops, updates: initialUpdates } = this.pluckOperations(updates);
|
|
321
321
|
let q = (_b = (yield ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, Object.assign({}, query))))) !== null && _b !== void 0 ? _b : query;
|
|
322
322
|
try {
|
|
@@ -372,8 +372,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
handleWillUpdateOnePlugins(query, updates) {
|
|
375
|
-
var _a;
|
|
376
375
|
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
var _a;
|
|
377
377
|
let shouldUpdate = true;
|
|
378
378
|
let resolvedQuery = query;
|
|
379
379
|
let resolvedUpdates = updates;
|
|
@@ -425,8 +425,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
425
425
|
return !!preparedRecord._isScrambled;
|
|
426
426
|
}
|
|
427
427
|
generateScrambledRecord() {
|
|
428
|
-
var _a;
|
|
429
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
|
+
var _a;
|
|
430
430
|
if (!this.scrambleFields) {
|
|
431
431
|
throw new SpruceError({ code: 'SCRAMBLE_NOT_CONFIGURED' });
|
|
432
432
|
}
|
|
@@ -442,8 +442,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
deleteOne(query) {
|
|
445
|
-
var _a, _b, _c, _d;
|
|
446
445
|
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
var _a, _b, _c, _d;
|
|
447
447
|
let q = (_b = (yield ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, Object.assign({}, query))))) !== null && _b !== void 0 ? _b : Object.assign({}, query);
|
|
448
448
|
for (const plugin of this.plugins) {
|
|
449
449
|
const { query } = (_d = (yield ((_c = plugin.willDeleteOne) === null || _c === void 0 ? void 0 : _c.call(plugin, q)))) !== null && _d !== void 0 ? _d : {};
|
|
@@ -455,8 +455,8 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
delete(query) {
|
|
458
|
-
var _a, _b;
|
|
459
458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
459
|
+
var _a, _b;
|
|
460
460
|
const q = (_b = (yield ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, Object.assign({}, query))))) !== null && _b !== void 0 ? _b : Object.assign({}, query);
|
|
461
461
|
return yield this.db.delete(this.collectionName, q);
|
|
462
462
|
});
|
|
@@ -954,8 +954,8 @@ const databaseAssertUtil = {
|
|
|
954
954
|
});
|
|
955
955
|
},
|
|
956
956
|
assertCanCreateUniqueIndexOnNestedField(connect) {
|
|
957
|
-
var _a;
|
|
958
957
|
return __awaiter(this, void 0, void 0, function* () {
|
|
958
|
+
var _a;
|
|
959
959
|
const db = yield connectToDabatase(connect);
|
|
960
960
|
try {
|
|
961
961
|
yield db.createUniqueIndex(this.collectionName, [
|
|
@@ -1340,8 +1340,8 @@ const databaseAssertUtil = {
|
|
|
1340
1340
|
});
|
|
1341
1341
|
},
|
|
1342
1342
|
assertCanUpsertNull(connect) {
|
|
1343
|
-
var _a, _b;
|
|
1344
1343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1344
|
+
var _a, _b;
|
|
1345
1345
|
const db = yield connectToDabatase(connect);
|
|
1346
1346
|
const createdUndefined = yield db.upsertOne(this.collectionName, {
|
|
1347
1347
|
undefinedField: undefined,
|
|
@@ -1378,8 +1378,8 @@ const databaseAssertUtil = {
|
|
|
1378
1378
|
});
|
|
1379
1379
|
},
|
|
1380
1380
|
assertCanSaveAndGetNullAndUndefined(connect) {
|
|
1381
|
-
var _a, _b;
|
|
1382
1381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1382
|
+
var _a, _b;
|
|
1383
1383
|
const db = yield connectToDabatase(connect);
|
|
1384
1384
|
const created = yield db.createOne(this.collectionName, {
|
|
1385
1385
|
undefinedField: undefined,
|
|
@@ -1562,8 +1562,8 @@ const databaseAssertUtil = {
|
|
|
1562
1562
|
});
|
|
1563
1563
|
},
|
|
1564
1564
|
assertNestedFieldIndexUpdates(connect) {
|
|
1565
|
-
var _a;
|
|
1566
1565
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1566
|
+
var _a;
|
|
1567
1567
|
const db = yield connectToDabatase(connect);
|
|
1568
1568
|
yield db.createUniqueIndex(this.collectionName, [
|
|
1569
1569
|
'target.organizationId',
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "26.4.
|
|
6
|
+
"version": "26.4.37",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/**/*",
|
|
9
9
|
"!build/__tests__",
|
|
@@ -69,25 +69,25 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@sprucelabs/error": "^5.1.65",
|
|
72
|
-
"@sprucelabs/globby": "^1.0.
|
|
73
|
-
"@sprucelabs/schema": "^29.4.
|
|
74
|
-
"@sprucelabs/spruce-skill-utils": "^30.2
|
|
72
|
+
"@sprucelabs/globby": "^1.0.16",
|
|
73
|
+
"@sprucelabs/schema": "^29.4.11",
|
|
74
|
+
"@sprucelabs/spruce-skill-utils": "^30.3.2",
|
|
75
75
|
"just-clone": "^6.2.0",
|
|
76
76
|
"lodash": "^4.17.21",
|
|
77
77
|
"mongodb": "^6.4.0",
|
|
78
78
|
"nedb": "^1.8.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@sprucelabs/esm-postbuild": "^5.0.
|
|
82
|
-
"@sprucelabs/jest-json-reporter": "^7.0.
|
|
81
|
+
"@sprucelabs/esm-postbuild": "^5.0.162",
|
|
82
|
+
"@sprucelabs/jest-json-reporter": "^7.0.174",
|
|
83
83
|
"@sprucelabs/jest-sheets-reporter": "^3.0.26",
|
|
84
84
|
"@sprucelabs/resolve-path-aliases": "^1.1.283",
|
|
85
85
|
"@sprucelabs/semantic-release": "^4.0.8",
|
|
86
86
|
"@sprucelabs/test": "^8.0.41",
|
|
87
|
-
"@sprucelabs/test-utils": "^4.0.
|
|
87
|
+
"@sprucelabs/test-utils": "^4.0.109",
|
|
88
88
|
"@types/lodash": "^4.14.202",
|
|
89
89
|
"@types/nedb": "^1.8.16",
|
|
90
|
-
"@types/node": "^20.11.
|
|
90
|
+
"@types/node": "^20.11.25",
|
|
91
91
|
"chokidar-cli": "^3.0.0",
|
|
92
92
|
"concurrently": "^8.2.2",
|
|
93
93
|
"dotenv": "^16.4.5",
|