@sprucelabs/data-stores 18.1.97 → 18.1.98
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/.spruce/errors/dataStores/indexExists.schema.js +6 -0
- package/build/.spruce/errors/errors.types.d.ts +7 -0
- package/build/databases/MongoDatabase.js +5 -1
- package/build/databases/NeDbDatabase.js +8 -4
- package/build/errors/SpruceError.js +1 -1
- package/build/errors/indexExists.builder.d.ts +4 -0
- package/build/errors/indexExists.builder.js +4 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +7 -0
- package/build/esm/databases/MongoDatabase.js +5 -1
- package/build/esm/databases/NeDbDatabase.js +8 -4
- package/build/esm/errors/SpruceError.js +1 -1
- package/build/esm/errors/indexExists.builder.d.ts +4 -0
- package/build/esm/errors/indexExists.builder.js +4 -0
- package/package.json +1 -1
|
@@ -14,6 +14,12 @@ const indexExistsSchema = {
|
|
|
14
14
|
isArray: true,
|
|
15
15
|
options: undefined
|
|
16
16
|
},
|
|
17
|
+
/** . */
|
|
18
|
+
'collectionName': {
|
|
19
|
+
type: 'text',
|
|
20
|
+
isRequired: true,
|
|
21
|
+
options: undefined
|
|
22
|
+
},
|
|
17
23
|
}
|
|
18
24
|
};
|
|
19
25
|
schema_1.SchemaRegistry.getInstance().trackSchema(indexExistsSchema);
|
|
@@ -239,6 +239,7 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
239
239
|
interface IndexExists {
|
|
240
240
|
/** Index Exists. */
|
|
241
241
|
'index': string[];
|
|
242
|
+
'collectionName': string;
|
|
242
243
|
}
|
|
243
244
|
interface IndexExistsSchema extends SpruceSchema.Schema {
|
|
244
245
|
id: 'indexExists';
|
|
@@ -253,6 +254,12 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
253
254
|
isArray: true;
|
|
254
255
|
options: undefined;
|
|
255
256
|
};
|
|
257
|
+
/** . */
|
|
258
|
+
'collectionName': {
|
|
259
|
+
type: 'text';
|
|
260
|
+
isRequired: true;
|
|
261
|
+
options: undefined;
|
|
262
|
+
};
|
|
256
263
|
};
|
|
257
264
|
}
|
|
258
265
|
type IndexExistsEntity = SchemaEntity<SpruceErrors.DataStores.IndexExistsSchema>;
|
|
@@ -301,7 +301,11 @@ class MongoDatabase {
|
|
|
301
301
|
}
|
|
302
302
|
assertIndexDoesNotExist(currentIndexes, fields) {
|
|
303
303
|
if (this.doesIndexExist(currentIndexes, fields)) {
|
|
304
|
-
throw new SpruceError_1.default({
|
|
304
|
+
throw new SpruceError_1.default({
|
|
305
|
+
code: 'INDEX_EXISTS',
|
|
306
|
+
index: fields,
|
|
307
|
+
collectionName: this.dbName,
|
|
308
|
+
});
|
|
305
309
|
}
|
|
306
310
|
}
|
|
307
311
|
doesIndexExist(currentIndexes, fields) {
|
|
@@ -350,9 +350,13 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
350
350
|
}
|
|
351
351
|
throw new SpruceError_1.default({ code: 'INDEX_NOT_FOUND', missingIndex: fields });
|
|
352
352
|
}
|
|
353
|
-
assertIndexDoesNotExist(currentIndexes, fields) {
|
|
353
|
+
assertIndexDoesNotExist(currentIndexes, fields, collectionName) {
|
|
354
354
|
if (this.doesIndexExist(currentIndexes, fields)) {
|
|
355
|
-
throw new SpruceError_1.default({
|
|
355
|
+
throw new SpruceError_1.default({
|
|
356
|
+
code: 'INDEX_EXISTS',
|
|
357
|
+
index: fields,
|
|
358
|
+
collectionName,
|
|
359
|
+
});
|
|
356
360
|
}
|
|
357
361
|
}
|
|
358
362
|
doesIndexExist(currentIndexes, fields) {
|
|
@@ -369,7 +373,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
369
373
|
col._uniqueIndexes = [];
|
|
370
374
|
}
|
|
371
375
|
await this.randomDelay();
|
|
372
|
-
this.assertIndexDoesNotExist(col._uniqueIndexes, fields);
|
|
376
|
+
this.assertIndexDoesNotExist(col._uniqueIndexes, fields, collection);
|
|
373
377
|
if (col._uniqueIndexes) {
|
|
374
378
|
const tempUniqueIndexes = [...col._uniqueIndexes];
|
|
375
379
|
tempUniqueIndexes.push(fields);
|
|
@@ -400,7 +404,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
400
404
|
col._indexes = [];
|
|
401
405
|
}
|
|
402
406
|
await this.randomDelay();
|
|
403
|
-
this.assertIndexDoesNotExist(col._indexes, fields);
|
|
407
|
+
this.assertIndexDoesNotExist(col._indexes, fields, collection);
|
|
404
408
|
col._indexes.push(fields);
|
|
405
409
|
}
|
|
406
410
|
async syncUniqueIndexes(collectionName, indexes) {
|
|
@@ -85,7 +85,7 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
85
85
|
message = `The unique index ${options.missingIndex.join(', ')} you tried to remove does not exist!`;
|
|
86
86
|
break;
|
|
87
87
|
case 'INDEX_EXISTS':
|
|
88
|
-
message = `The unique index ${options.index.join(', ')} you attempted to create already exists!`;
|
|
88
|
+
message = `The unique index ${options.index.join(', ')} you attempted to create in '${options.collectionName}' already exists!`;
|
|
89
89
|
break;
|
|
90
90
|
case 'UNKNOWN_ERROR':
|
|
91
91
|
message = 'Unknown error!';
|
|
@@ -239,6 +239,7 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
239
239
|
interface IndexExists {
|
|
240
240
|
/** Index Exists. */
|
|
241
241
|
'index': string[];
|
|
242
|
+
'collectionName': string;
|
|
242
243
|
}
|
|
243
244
|
interface IndexExistsSchema extends SpruceSchema.Schema {
|
|
244
245
|
id: 'indexExists';
|
|
@@ -253,6 +254,12 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
253
254
|
isArray: true;
|
|
254
255
|
options: undefined;
|
|
255
256
|
};
|
|
257
|
+
/** . */
|
|
258
|
+
'collectionName': {
|
|
259
|
+
type: 'text';
|
|
260
|
+
isRequired: true;
|
|
261
|
+
options: undefined;
|
|
262
|
+
};
|
|
256
263
|
};
|
|
257
264
|
}
|
|
258
265
|
type IndexExistsEntity = SchemaEntity<SpruceErrors.DataStores.IndexExistsSchema>;
|
|
@@ -334,7 +334,11 @@ export default class MongoDatabase {
|
|
|
334
334
|
}
|
|
335
335
|
assertIndexDoesNotExist(currentIndexes, fields) {
|
|
336
336
|
if (this.doesIndexExist(currentIndexes, fields)) {
|
|
337
|
-
throw new SpruceError({
|
|
337
|
+
throw new SpruceError({
|
|
338
|
+
code: 'INDEX_EXISTS',
|
|
339
|
+
index: fields,
|
|
340
|
+
collectionName: this.dbName,
|
|
341
|
+
});
|
|
338
342
|
}
|
|
339
343
|
}
|
|
340
344
|
doesIndexExist(currentIndexes, fields) {
|
|
@@ -392,9 +392,13 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
392
392
|
throw new SpruceError({ code: 'INDEX_NOT_FOUND', missingIndex: fields });
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
-
assertIndexDoesNotExist(currentIndexes, fields) {
|
|
395
|
+
assertIndexDoesNotExist(currentIndexes, fields, collectionName) {
|
|
396
396
|
if (this.doesIndexExist(currentIndexes, fields)) {
|
|
397
|
-
throw new SpruceError({
|
|
397
|
+
throw new SpruceError({
|
|
398
|
+
code: 'INDEX_EXISTS',
|
|
399
|
+
index: fields,
|
|
400
|
+
collectionName,
|
|
401
|
+
});
|
|
398
402
|
}
|
|
399
403
|
}
|
|
400
404
|
doesIndexExist(currentIndexes, fields) {
|
|
@@ -412,7 +416,7 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
412
416
|
col._uniqueIndexes = [];
|
|
413
417
|
}
|
|
414
418
|
yield this.randomDelay();
|
|
415
|
-
this.assertIndexDoesNotExist(col._uniqueIndexes, fields);
|
|
419
|
+
this.assertIndexDoesNotExist(col._uniqueIndexes, fields, collection);
|
|
416
420
|
if (col._uniqueIndexes) {
|
|
417
421
|
const tempUniqueIndexes = [...col._uniqueIndexes];
|
|
418
422
|
tempUniqueIndexes.push(fields);
|
|
@@ -445,7 +449,7 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
445
449
|
col._indexes = [];
|
|
446
450
|
}
|
|
447
451
|
yield this.randomDelay();
|
|
448
|
-
this.assertIndexDoesNotExist(col._indexes, fields);
|
|
452
|
+
this.assertIndexDoesNotExist(col._indexes, fields, collection);
|
|
449
453
|
col._indexes.push(fields);
|
|
450
454
|
});
|
|
451
455
|
}
|
|
@@ -80,7 +80,7 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
80
80
|
message = `The unique index ${options.missingIndex.join(', ')} you tried to remove does not exist!`;
|
|
81
81
|
break;
|
|
82
82
|
case 'INDEX_EXISTS':
|
|
83
|
-
message = `The unique index ${options.index.join(', ')} you attempted to create already exists!`;
|
|
83
|
+
message = `The unique index ${options.index.join(', ')} you attempted to create in '${options.collectionName}' already exists!`;
|
|
84
84
|
break;
|
|
85
85
|
case 'UNKNOWN_ERROR':
|
|
86
86
|
message = 'Unknown error!';
|