@sprucelabs/data-stores 26.3.10 → 26.4.0
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.
|
@@ -41,6 +41,7 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
41
41
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
42
42
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
43
43
|
query<T>(query: string, params?: any[]): Promise<T[]>;
|
|
44
|
+
private queryToKey;
|
|
44
45
|
private assertValidFakedQueryResponse;
|
|
45
46
|
fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
|
|
46
47
|
}
|
|
@@ -460,7 +460,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
async query(query, params) {
|
|
463
|
-
const cb = this.fakedQueries[query];
|
|
463
|
+
const cb = this.fakedQueries[this.queryToKey(query)];
|
|
464
464
|
if (cb) {
|
|
465
465
|
const results = await cb(params);
|
|
466
466
|
this.assertValidFakedQueryResponse(results, query);
|
|
@@ -471,6 +471,9 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
471
471
|
query,
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
|
+
queryToKey(query) {
|
|
475
|
+
return query.toLowerCase().replace(/\s/g, '').replace(/\n/g, '');
|
|
476
|
+
}
|
|
474
477
|
assertValidFakedQueryResponse(results, query) {
|
|
475
478
|
if (!Array.isArray(results)) {
|
|
476
479
|
throw new SpruceError_1.default({
|
|
@@ -481,7 +484,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
481
484
|
}
|
|
482
485
|
}
|
|
483
486
|
fakeQuery(query, cb) {
|
|
484
|
-
this.fakedQueries[query] = cb;
|
|
487
|
+
this.fakedQueries[this.queryToKey(query)] = cb;
|
|
485
488
|
}
|
|
486
489
|
}
|
|
487
490
|
exports.default = NeDbDatabase;
|
|
@@ -41,6 +41,7 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
41
41
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
42
42
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
43
43
|
query<T>(query: string, params?: any[]): Promise<T[]>;
|
|
44
|
+
private queryToKey;
|
|
44
45
|
private assertValidFakedQueryResponse;
|
|
45
46
|
fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
|
|
46
47
|
}
|
|
@@ -511,7 +511,7 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
511
511
|
}
|
|
512
512
|
query(query, params) {
|
|
513
513
|
return __awaiter(this, void 0, void 0, function* () {
|
|
514
|
-
const cb = this.fakedQueries[query];
|
|
514
|
+
const cb = this.fakedQueries[this.queryToKey(query)];
|
|
515
515
|
if (cb) {
|
|
516
516
|
const results = yield cb(params);
|
|
517
517
|
this.assertValidFakedQueryResponse(results, query);
|
|
@@ -523,6 +523,9 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
523
523
|
});
|
|
524
524
|
});
|
|
525
525
|
}
|
|
526
|
+
queryToKey(query) {
|
|
527
|
+
return query.toLowerCase().replace(/\s/g, '').replace(/\n/g, '');
|
|
528
|
+
}
|
|
526
529
|
assertValidFakedQueryResponse(results, query) {
|
|
527
530
|
if (!Array.isArray(results)) {
|
|
528
531
|
throw new SpruceError({
|
|
@@ -533,6 +536,6 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
533
536
|
}
|
|
534
537
|
}
|
|
535
538
|
fakeQuery(query, cb) {
|
|
536
|
-
this.fakedQueries[query] = cb;
|
|
539
|
+
this.fakedQueries[this.queryToKey(query)] = cb;
|
|
537
540
|
}
|
|
538
541
|
}
|