@sprucelabs/data-stores 22.1.0 → 22.3.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.
- package/README.md +1 -0
- package/build/.spruce/errors/dataStores/notImplemented.schema.d.ts +3 -0
- package/build/.spruce/errors/dataStores/notImplemented.schema.js +11 -0
- package/build/.spruce/errors/errors.types.d.ts +11 -0
- package/build/.spruce/errors/options.types.d.ts +4 -1
- package/build/databases/MongoDatabase.d.ts +1 -0
- package/build/databases/MongoDatabase.js +5 -0
- package/build/databases/NeDbDatabase.d.ts +1 -0
- package/build/databases/NeDbDatabase.js +5 -0
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/notImplemented.builder.d.ts +6 -0
- package/build/errors/notImplemented.builder.js +8 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +11 -0
- package/build/esm/.spruce/errors/options.types.d.ts +4 -1
- package/build/esm/databases/MongoDatabase.d.ts +1 -0
- package/build/esm/databases/MongoDatabase.js +7 -0
- package/build/esm/databases/NeDbDatabase.d.ts +1 -0
- package/build/esm/databases/NeDbDatabase.js +7 -0
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/errors/notImplemented.builder.d.ts +6 -0
- package/build/esm/errors/notImplemented.builder.js +6 -0
- package/build/esm/tests/databaseAssertUtil.d.ts +1 -1
- package/build/esm/tests/databaseAssertUtil.js +19 -2
- package/build/esm/tests/pluckAssertionMethods.d.ts +1 -1
- package/build/esm/types/database.types.d.ts +1 -0
- package/build/tests/databaseAssertUtil.d.ts +1 -1
- package/build/tests/databaseAssertUtil.js +19 -2
- package/build/tests/pluckAssertionMethods.d.ts +1 -1
- package/build/types/database.types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const notImplementedSchema = {
|
|
5
|
+
id: 'notImplemented',
|
|
6
|
+
namespace: 'DataStores',
|
|
7
|
+
name: 'Not implemented',
|
|
8
|
+
fields: {}
|
|
9
|
+
};
|
|
10
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(notImplementedSchema);
|
|
11
|
+
exports.default = notImplementedSchema;
|
|
@@ -134,6 +134,17 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
134
134
|
}
|
|
135
135
|
type RecordNotFoundEntity = SchemaEntity<SpruceErrors.DataStores.RecordNotFoundSchema>;
|
|
136
136
|
}
|
|
137
|
+
export declare namespace SpruceErrors.DataStores {
|
|
138
|
+
interface NotImplemented {
|
|
139
|
+
}
|
|
140
|
+
interface NotImplementedSchema extends SpruceSchema.Schema {
|
|
141
|
+
id: 'notImplemented';
|
|
142
|
+
namespace: 'DataStores';
|
|
143
|
+
name: 'Not implemented';
|
|
144
|
+
fields: {};
|
|
145
|
+
}
|
|
146
|
+
type NotImplementedEntity = SchemaEntity<SpruceErrors.DataStores.NotImplementedSchema>;
|
|
147
|
+
}
|
|
137
148
|
export declare namespace SpruceErrors.DataStores {
|
|
138
149
|
interface MongoIdMappingError {
|
|
139
150
|
}
|
|
@@ -18,6 +18,9 @@ export interface ScrambleNotConfiguredErrorOptions extends SpruceErrors.DataStor
|
|
|
18
18
|
export interface RecordNotFoundErrorOptions extends SpruceErrors.DataStores.RecordNotFound, ISpruceErrorOptions {
|
|
19
19
|
code: 'RECORD_NOT_FOUND';
|
|
20
20
|
}
|
|
21
|
+
export interface NotImplementedErrorOptions extends SpruceErrors.DataStores.NotImplemented, ISpruceErrorOptions {
|
|
22
|
+
code: 'NOT_IMPLEMENTED';
|
|
23
|
+
}
|
|
21
24
|
export interface MongoIdMappingErrorErrorOptions extends SpruceErrors.DataStores.MongoIdMappingError, ISpruceErrorOptions {
|
|
22
25
|
code: 'MONGO_ID_MAPPING_ERROR';
|
|
23
26
|
}
|
|
@@ -57,5 +60,5 @@ export interface DuplicateKeyErrorOptions extends SpruceErrors.DataStores.Duplic
|
|
|
57
60
|
export interface DatabaseNotConnectedErrorOptions extends SpruceErrors.DataStores.DatabaseNotConnected, ISpruceErrorOptions {
|
|
58
61
|
code: 'DATABASE_NOT_CONNECTED';
|
|
59
62
|
}
|
|
60
|
-
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
63
|
+
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
61
64
|
export default ErrorOptions;
|
|
@@ -39,4 +39,5 @@ export default class MongoDatabase implements Database {
|
|
|
39
39
|
updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
|
|
40
40
|
upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
|
|
41
41
|
private generateDuplicateFieldsForError;
|
|
42
|
+
query<T>(): Promise<T>;
|
|
42
43
|
}
|
|
@@ -38,4 +38,5 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
38
38
|
createIndex(collection: string, fields: string[]): Promise<void>;
|
|
39
39
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
40
40
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
41
|
+
query<T>(): Promise<T>;
|
|
41
42
|
}
|
|
@@ -451,5 +451,10 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
451
451
|
await this.dropIndex(collectionName, extra);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
|
+
async query() {
|
|
455
|
+
throw new SpruceError_1.default({
|
|
456
|
+
code: 'NOT_IMPLEMENTED',
|
|
457
|
+
});
|
|
458
|
+
}
|
|
454
459
|
}
|
|
455
460
|
exports.default = NeDbDatabase;
|
|
@@ -99,6 +99,9 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
99
99
|
case 'INVALID_CONNECTION_STRING_SCHEME':
|
|
100
100
|
message = `There is no database adapter setup for: ${options.connectionString.split('://')[0]}`;
|
|
101
101
|
break;
|
|
102
|
+
case 'NOT_IMPLEMENTED':
|
|
103
|
+
message = 'A Not implemented just happened!';
|
|
104
|
+
break;
|
|
102
105
|
default:
|
|
103
106
|
message = super.friendlyMessage();
|
|
104
107
|
}
|
|
@@ -134,6 +134,17 @@ export declare namespace SpruceErrors.DataStores {
|
|
|
134
134
|
}
|
|
135
135
|
type RecordNotFoundEntity = SchemaEntity<SpruceErrors.DataStores.RecordNotFoundSchema>;
|
|
136
136
|
}
|
|
137
|
+
export declare namespace SpruceErrors.DataStores {
|
|
138
|
+
interface NotImplemented {
|
|
139
|
+
}
|
|
140
|
+
interface NotImplementedSchema extends SpruceSchema.Schema {
|
|
141
|
+
id: 'notImplemented';
|
|
142
|
+
namespace: 'DataStores';
|
|
143
|
+
name: 'Not implemented';
|
|
144
|
+
fields: {};
|
|
145
|
+
}
|
|
146
|
+
type NotImplementedEntity = SchemaEntity<SpruceErrors.DataStores.NotImplementedSchema>;
|
|
147
|
+
}
|
|
137
148
|
export declare namespace SpruceErrors.DataStores {
|
|
138
149
|
interface MongoIdMappingError {
|
|
139
150
|
}
|
|
@@ -18,6 +18,9 @@ export interface ScrambleNotConfiguredErrorOptions extends SpruceErrors.DataStor
|
|
|
18
18
|
export interface RecordNotFoundErrorOptions extends SpruceErrors.DataStores.RecordNotFound, ISpruceErrorOptions {
|
|
19
19
|
code: 'RECORD_NOT_FOUND';
|
|
20
20
|
}
|
|
21
|
+
export interface NotImplementedErrorOptions extends SpruceErrors.DataStores.NotImplemented, ISpruceErrorOptions {
|
|
22
|
+
code: 'NOT_IMPLEMENTED';
|
|
23
|
+
}
|
|
21
24
|
export interface MongoIdMappingErrorErrorOptions extends SpruceErrors.DataStores.MongoIdMappingError, ISpruceErrorOptions {
|
|
22
25
|
code: 'MONGO_ID_MAPPING_ERROR';
|
|
23
26
|
}
|
|
@@ -57,5 +60,5 @@ export interface DuplicateKeyErrorOptions extends SpruceErrors.DataStores.Duplic
|
|
|
57
60
|
export interface DatabaseNotConnectedErrorOptions extends SpruceErrors.DataStores.DatabaseNotConnected, ISpruceErrorOptions {
|
|
58
61
|
code: 'DATABASE_NOT_CONNECTED';
|
|
59
62
|
}
|
|
60
|
-
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
63
|
+
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
61
64
|
export default ErrorOptions;
|
|
@@ -39,4 +39,5 @@ export default class MongoDatabase implements Database {
|
|
|
39
39
|
updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
|
|
40
40
|
upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
|
|
41
41
|
private generateDuplicateFieldsForError;
|
|
42
|
+
query<T>(): Promise<T>;
|
|
42
43
|
}
|
|
@@ -38,4 +38,5 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
38
38
|
createIndex(collection: string, fields: string[]): Promise<void>;
|
|
39
39
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
40
40
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
41
|
+
query<T>(): Promise<T>;
|
|
41
42
|
}
|
|
@@ -94,6 +94,9 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
94
94
|
case 'INVALID_CONNECTION_STRING_SCHEME':
|
|
95
95
|
message = `There is no database adapter setup for: ${options.connectionString.split('://')[0]}`;
|
|
96
96
|
break;
|
|
97
|
+
case 'NOT_IMPLEMENTED':
|
|
98
|
+
message = 'A Not implemented just happened!';
|
|
99
|
+
break;
|
|
97
100
|
default:
|
|
98
101
|
message = super.friendlyMessage();
|
|
99
102
|
}
|
|
@@ -53,7 +53,7 @@ declare const databaseAssertUtil: {
|
|
|
53
53
|
assertThrowsWithInvalidConnectionString(connect: TestConnect): Promise<void>;
|
|
54
54
|
assertKnowsIfConnectionClosed(connect: TestConnect): Promise<void>;
|
|
55
55
|
assertCanQueryPathWithDotSyntax(connect: TestConnect): Promise<void>;
|
|
56
|
-
|
|
56
|
+
assertCanQueryByGtLtGteLteNe(connect: TestConnect): Promise<void>;
|
|
57
57
|
assertCanFindWithNe(connect: TestConnect): Promise<void>;
|
|
58
58
|
assertCanFindWithIn(connect: TestConnect): Promise<void>;
|
|
59
59
|
assertCanFindWithBooleanField(connect: TestConnect): Promise<void>;
|
|
@@ -55,7 +55,7 @@ const databaseAssertUtil = {
|
|
|
55
55
|
'assertCanLimitResults',
|
|
56
56
|
'assertCanLimitResultsToZero',
|
|
57
57
|
'assertCanFindWithBooleanField',
|
|
58
|
-
'
|
|
58
|
+
'assertCanQueryByGtLtGteLteNe',
|
|
59
59
|
'assertCanQueryPathWithDotSyntax',
|
|
60
60
|
'assertCanReturnOnlySelectFields',
|
|
61
61
|
'assertCanSearchByRegex',
|
|
@@ -1162,25 +1162,29 @@ const databaseAssertUtil = {
|
|
|
1162
1162
|
yield this.shutdown(db);
|
|
1163
1163
|
});
|
|
1164
1164
|
},
|
|
1165
|
-
|
|
1165
|
+
assertCanQueryByGtLtGteLteNe(connect) {
|
|
1166
1166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1167
1167
|
const db = yield connectToDabatase(connect);
|
|
1168
1168
|
const created = yield db.create(this.collectionName, [
|
|
1169
1169
|
{
|
|
1170
1170
|
number: 1,
|
|
1171
1171
|
name: generateId(),
|
|
1172
|
+
someField: null,
|
|
1172
1173
|
},
|
|
1173
1174
|
{
|
|
1174
1175
|
number: 2,
|
|
1175
1176
|
name: generateId(),
|
|
1177
|
+
someField: 'test',
|
|
1176
1178
|
},
|
|
1177
1179
|
{
|
|
1178
1180
|
number: 3,
|
|
1179
1181
|
name: generateId(),
|
|
1182
|
+
someField: 'test',
|
|
1180
1183
|
},
|
|
1181
1184
|
{
|
|
1182
1185
|
number: 4,
|
|
1183
1186
|
name: generateId(),
|
|
1187
|
+
someField: 'test',
|
|
1184
1188
|
},
|
|
1185
1189
|
]);
|
|
1186
1190
|
const gtMatches = yield db.find(this.collectionName, {
|
|
@@ -1207,6 +1211,19 @@ const databaseAssertUtil = {
|
|
|
1207
1211
|
assert.isEqual(lteMatches[0].number, 1);
|
|
1208
1212
|
assert.isEqual(lteMatches[1].number, 2);
|
|
1209
1213
|
assert.isEqual(lteMatches[2].number, 3);
|
|
1214
|
+
const notMatches = yield db.find(this.collectionName, {
|
|
1215
|
+
id: {
|
|
1216
|
+
$ne: created[0].id,
|
|
1217
|
+
},
|
|
1218
|
+
});
|
|
1219
|
+
assert.isNotEqual(notMatches[0].id, created[0].id);
|
|
1220
|
+
assert.isLength(notMatches, created.length - 1);
|
|
1221
|
+
const notNull = yield db.find(this.collectionName, {
|
|
1222
|
+
someField: {
|
|
1223
|
+
$ne: null,
|
|
1224
|
+
},
|
|
1225
|
+
});
|
|
1226
|
+
assert.isLength(notNull, created.length - 1);
|
|
1210
1227
|
yield this.shutdown(db);
|
|
1211
1228
|
});
|
|
1212
1229
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import databaseAssertUtil from './databaseAssertUtil';
|
|
2
|
-
export default function pluckAssertionMethods(util: typeof databaseAssertUtil): ("collectionName" | "assertThrowsWithInvalidConnectionString" | "assertThrowsWhenCantConnect" | "assertThrowsWithBadDatabaseName" | "assertEmptyDatabaseReturnsEmptyArray" | "assertKnowsIfConnectionClosed" | "assertFindOneOnEmptyDatabaseReturnsNull" | "assertCanSortDesc" | "assertCanSortAsc" | "assertCanSortById" | "assertCanQueryWithOr" | "generateIdDifferentEachTime" | "assertInsertingGeneratesId" | "assertCanCreateMany" | "assertCanLimitResults" | "assertCanCreateWithObjectField" | "assertCanCountOnId" | "assertCanCount" | "assertThrowsWhenUpdatingRecordNotFound" | "assertCanUpdate" | "assertCanUpdateMany" | "assertCanPushOntoArrayValue" | "canUpdateWithObjectField" | "canUpdateFieldInObjectFieldWithTargettedWhere" | "assertCanSaveAndGetNullAndUndefined" | "assertCanUpsertOne" | "assertCanUpsertNull" | "assertCanPushToArrayOnUpsert" | "assertCanLimitResultsToZero" | "assertCanFindWithBooleanField" | "
|
|
2
|
+
export default function pluckAssertionMethods(util: typeof databaseAssertUtil): ("collectionName" | "assertThrowsWithInvalidConnectionString" | "assertThrowsWhenCantConnect" | "assertThrowsWithBadDatabaseName" | "assertEmptyDatabaseReturnsEmptyArray" | "assertKnowsIfConnectionClosed" | "assertFindOneOnEmptyDatabaseReturnsNull" | "assertCanSortDesc" | "assertCanSortAsc" | "assertCanSortById" | "assertCanQueryWithOr" | "generateIdDifferentEachTime" | "assertInsertingGeneratesId" | "assertCanCreateMany" | "assertCanLimitResults" | "assertCanCreateWithObjectField" | "assertCanCountOnId" | "assertCanCount" | "assertThrowsWhenUpdatingRecordNotFound" | "assertCanUpdate" | "assertCanUpdateMany" | "assertCanPushOntoArrayValue" | "canUpdateWithObjectField" | "canUpdateFieldInObjectFieldWithTargettedWhere" | "assertCanSaveAndGetNullAndUndefined" | "assertCanUpsertOne" | "assertCanUpsertNull" | "assertCanPushToArrayOnUpsert" | "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" | "runSuite" | "_getFilteredIndexes" | "_filterIdIndex" | "_assertUpdateUpdatedRightNumberOfRecords" | "shutdown" | "_assertThrowsExpectedNotFoundOnUpdateOne" | "_assert$orReturnsExpectedTotalRecords" | "_assertCanCreateMultiFieldIndex")[];
|
|
@@ -27,6 +27,7 @@ export interface Database {
|
|
|
27
27
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
28
28
|
createUniqueIndex(collection: string, fields: UniqueIndex): Promise<void>;
|
|
29
29
|
createIndex(collection: string, fields: Index): Promise<void>;
|
|
30
|
+
query<T>(query: string): Promise<T>;
|
|
30
31
|
}
|
|
31
32
|
export interface DatabaseOptions {
|
|
32
33
|
dbName?: string;
|
|
@@ -53,7 +53,7 @@ declare const databaseAssertUtil: {
|
|
|
53
53
|
assertThrowsWithInvalidConnectionString(connect: TestConnect): Promise<void>;
|
|
54
54
|
assertKnowsIfConnectionClosed(connect: TestConnect): Promise<void>;
|
|
55
55
|
assertCanQueryPathWithDotSyntax(connect: TestConnect): Promise<void>;
|
|
56
|
-
|
|
56
|
+
assertCanQueryByGtLtGteLteNe(connect: TestConnect): Promise<void>;
|
|
57
57
|
assertCanFindWithNe(connect: TestConnect): Promise<void>;
|
|
58
58
|
assertCanFindWithIn(connect: TestConnect): Promise<void>;
|
|
59
59
|
assertCanFindWithBooleanField(connect: TestConnect): Promise<void>;
|
|
@@ -50,7 +50,7 @@ const databaseAssertUtil = {
|
|
|
50
50
|
'assertCanLimitResults',
|
|
51
51
|
'assertCanLimitResultsToZero',
|
|
52
52
|
'assertCanFindWithBooleanField',
|
|
53
|
-
'
|
|
53
|
+
'assertCanQueryByGtLtGteLteNe',
|
|
54
54
|
'assertCanQueryPathWithDotSyntax',
|
|
55
55
|
'assertCanReturnOnlySelectFields',
|
|
56
56
|
'assertCanSearchByRegex',
|
|
@@ -1056,24 +1056,28 @@ const databaseAssertUtil = {
|
|
|
1056
1056
|
test_utils_1.assert.isEqual(secondMatch.name, 'second');
|
|
1057
1057
|
await this.shutdown(db);
|
|
1058
1058
|
},
|
|
1059
|
-
async
|
|
1059
|
+
async assertCanQueryByGtLtGteLteNe(connect) {
|
|
1060
1060
|
const db = await connectToDabatase(connect);
|
|
1061
1061
|
const created = await db.create(this.collectionName, [
|
|
1062
1062
|
{
|
|
1063
1063
|
number: 1,
|
|
1064
1064
|
name: (0, generateId_1.default)(),
|
|
1065
|
+
someField: null,
|
|
1065
1066
|
},
|
|
1066
1067
|
{
|
|
1067
1068
|
number: 2,
|
|
1068
1069
|
name: (0, generateId_1.default)(),
|
|
1070
|
+
someField: 'test',
|
|
1069
1071
|
},
|
|
1070
1072
|
{
|
|
1071
1073
|
number: 3,
|
|
1072
1074
|
name: (0, generateId_1.default)(),
|
|
1075
|
+
someField: 'test',
|
|
1073
1076
|
},
|
|
1074
1077
|
{
|
|
1075
1078
|
number: 4,
|
|
1076
1079
|
name: (0, generateId_1.default)(),
|
|
1080
|
+
someField: 'test',
|
|
1077
1081
|
},
|
|
1078
1082
|
]);
|
|
1079
1083
|
const gtMatches = await db.find(this.collectionName, {
|
|
@@ -1100,6 +1104,19 @@ const databaseAssertUtil = {
|
|
|
1100
1104
|
test_utils_1.assert.isEqual(lteMatches[0].number, 1);
|
|
1101
1105
|
test_utils_1.assert.isEqual(lteMatches[1].number, 2);
|
|
1102
1106
|
test_utils_1.assert.isEqual(lteMatches[2].number, 3);
|
|
1107
|
+
const notMatches = await db.find(this.collectionName, {
|
|
1108
|
+
id: {
|
|
1109
|
+
$ne: created[0].id,
|
|
1110
|
+
},
|
|
1111
|
+
});
|
|
1112
|
+
test_utils_1.assert.isNotEqual(notMatches[0].id, created[0].id);
|
|
1113
|
+
test_utils_1.assert.isLength(notMatches, created.length - 1);
|
|
1114
|
+
const notNull = await db.find(this.collectionName, {
|
|
1115
|
+
someField: {
|
|
1116
|
+
$ne: null,
|
|
1117
|
+
},
|
|
1118
|
+
});
|
|
1119
|
+
test_utils_1.assert.isLength(notNull, created.length - 1);
|
|
1103
1120
|
await this.shutdown(db);
|
|
1104
1121
|
},
|
|
1105
1122
|
async assertCanFindWithNe(connect) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import databaseAssertUtil from './databaseAssertUtil';
|
|
2
|
-
export default function pluckAssertionMethods(util: typeof databaseAssertUtil): ("collectionName" | "assertThrowsWithInvalidConnectionString" | "assertThrowsWhenCantConnect" | "assertThrowsWithBadDatabaseName" | "assertEmptyDatabaseReturnsEmptyArray" | "assertKnowsIfConnectionClosed" | "assertFindOneOnEmptyDatabaseReturnsNull" | "assertCanSortDesc" | "assertCanSortAsc" | "assertCanSortById" | "assertCanQueryWithOr" | "generateIdDifferentEachTime" | "assertInsertingGeneratesId" | "assertCanCreateMany" | "assertCanLimitResults" | "assertCanCreateWithObjectField" | "assertCanCountOnId" | "assertCanCount" | "assertThrowsWhenUpdatingRecordNotFound" | "assertCanUpdate" | "assertCanUpdateMany" | "assertCanPushOntoArrayValue" | "canUpdateWithObjectField" | "canUpdateFieldInObjectFieldWithTargettedWhere" | "assertCanSaveAndGetNullAndUndefined" | "assertCanUpsertOne" | "assertCanUpsertNull" | "assertCanPushToArrayOnUpsert" | "assertCanLimitResultsToZero" | "assertCanFindWithBooleanField" | "
|
|
2
|
+
export default function pluckAssertionMethods(util: typeof databaseAssertUtil): ("collectionName" | "assertThrowsWithInvalidConnectionString" | "assertThrowsWhenCantConnect" | "assertThrowsWithBadDatabaseName" | "assertEmptyDatabaseReturnsEmptyArray" | "assertKnowsIfConnectionClosed" | "assertFindOneOnEmptyDatabaseReturnsNull" | "assertCanSortDesc" | "assertCanSortAsc" | "assertCanSortById" | "assertCanQueryWithOr" | "generateIdDifferentEachTime" | "assertInsertingGeneratesId" | "assertCanCreateMany" | "assertCanLimitResults" | "assertCanCreateWithObjectField" | "assertCanCountOnId" | "assertCanCount" | "assertThrowsWhenUpdatingRecordNotFound" | "assertCanUpdate" | "assertCanUpdateMany" | "assertCanPushOntoArrayValue" | "canUpdateWithObjectField" | "canUpdateFieldInObjectFieldWithTargettedWhere" | "assertCanSaveAndGetNullAndUndefined" | "assertCanUpsertOne" | "assertCanUpsertNull" | "assertCanPushToArrayOnUpsert" | "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" | "runSuite" | "_getFilteredIndexes" | "_filterIdIndex" | "_assertUpdateUpdatedRightNumberOfRecords" | "shutdown" | "_assertThrowsExpectedNotFoundOnUpdateOne" | "_assert$orReturnsExpectedTotalRecords" | "_assertCanCreateMultiFieldIndex")[];
|
|
@@ -27,6 +27,7 @@ export interface Database {
|
|
|
27
27
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
28
28
|
createUniqueIndex(collection: string, fields: UniqueIndex): Promise<void>;
|
|
29
29
|
createIndex(collection: string, fields: Index): Promise<void>;
|
|
30
|
+
query<T>(query: string): Promise<T>;
|
|
30
31
|
}
|
|
31
32
|
export interface DatabaseOptions {
|
|
32
33
|
dbName?: string;
|