@sprucelabs/data-stores 26.2.9 → 26.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/build/.spruce/errors/dataStores/queryNotFaked.schema.d.ts +3 -0
- package/build/.spruce/errors/dataStores/queryNotFaked.schema.js +23 -0
- package/build/.spruce/errors/errors.types.d.ts +27 -0
- package/build/.spruce/errors/options.types.d.ts +4 -1
- package/build/databases/MongoDatabase.js +1 -0
- package/build/databases/NeDbDatabase.d.ts +4 -1
- package/build/databases/NeDbDatabase.js +11 -2
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/queryNotFaked.builder.d.ts +17 -0
- package/build/errors/queryNotFaked.builder.js +17 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +27 -0
- package/build/esm/.spruce/errors/options.types.d.ts +4 -1
- package/build/esm/databases/MongoDatabase.js +1 -0
- package/build/esm/databases/NeDbDatabase.d.ts +4 -1
- package/build/esm/databases/NeDbDatabase.js +11 -2
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/errors/queryNotFaked.builder.d.ts +17 -0
- package/build/esm/errors/queryNotFaked.builder.js +15 -0
- package/build/esm/types/database.types.d.ts +1 -1
- package/build/types/database.types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const queryNotFakedSchema = {
|
|
5
|
+
id: 'queryNotFaked',
|
|
6
|
+
namespace: 'DataStores',
|
|
7
|
+
name: 'Query not faked',
|
|
8
|
+
fields: {
|
|
9
|
+
/** . */
|
|
10
|
+
'query': {
|
|
11
|
+
type: 'text',
|
|
12
|
+
isRequired: true,
|
|
13
|
+
options: undefined
|
|
14
|
+
},
|
|
15
|
+
/** . */
|
|
16
|
+
'params': {
|
|
17
|
+
type: 'raw',
|
|
18
|
+
options: { valueType: `Record<string, any>`, }
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(queryNotFakedSchema);
|
|
23
|
+
exports.default = queryNotFakedSchema;
|
|
@@ -134,6 +134,33 @@ 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 QueryNotFaked {
|
|
139
|
+
'query': string;
|
|
140
|
+
'params'?: (Record<string, any>) | undefined | null;
|
|
141
|
+
}
|
|
142
|
+
interface QueryNotFakedSchema extends SpruceSchema.Schema {
|
|
143
|
+
id: 'queryNotFaked';
|
|
144
|
+
namespace: 'DataStores';
|
|
145
|
+
name: 'Query not faked';
|
|
146
|
+
fields: {
|
|
147
|
+
/** . */
|
|
148
|
+
'query': {
|
|
149
|
+
type: 'text';
|
|
150
|
+
isRequired: true;
|
|
151
|
+
options: undefined;
|
|
152
|
+
};
|
|
153
|
+
/** . */
|
|
154
|
+
'params': {
|
|
155
|
+
type: 'raw';
|
|
156
|
+
options: {
|
|
157
|
+
valueType: `Record<string, any>`;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
type QueryNotFakedEntity = SchemaEntity<SpruceErrors.DataStores.QueryNotFakedSchema>;
|
|
163
|
+
}
|
|
137
164
|
export declare namespace SpruceErrors.DataStores {
|
|
138
165
|
interface NotImplemented {
|
|
139
166
|
}
|
|
@@ -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 QueryNotFakedErrorOptions extends SpruceErrors.DataStores.QueryNotFaked, ISpruceErrorOptions {
|
|
22
|
+
code: 'QUERY_NOT_FAKED';
|
|
23
|
+
}
|
|
21
24
|
export interface NotImplementedErrorOptions extends SpruceErrors.DataStores.NotImplemented, ISpruceErrorOptions {
|
|
22
25
|
code: 'NOT_IMPLEMENTED';
|
|
23
26
|
}
|
|
@@ -60,5 +63,5 @@ export interface DuplicateKeyErrorOptions extends SpruceErrors.DataStores.Duplic
|
|
|
60
63
|
export interface DatabaseNotConnectedErrorOptions extends SpruceErrors.DataStores.DatabaseNotConnected, ISpruceErrorOptions {
|
|
61
64
|
code: 'DATABASE_NOT_CONNECTED';
|
|
62
65
|
}
|
|
63
|
-
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
66
|
+
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | QueryNotFakedErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
64
67
|
export default ErrorOptions;
|
|
@@ -4,6 +4,7 @@ import { QueryOptions } from '../types/query.types';
|
|
|
4
4
|
export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
5
5
|
private collections;
|
|
6
6
|
private _isConnected;
|
|
7
|
+
private fakedQueries;
|
|
7
8
|
generateId(): string;
|
|
8
9
|
connect(): Promise<void>;
|
|
9
10
|
close(): Promise<void>;
|
|
@@ -39,5 +40,7 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
39
40
|
createIndex(collection: string, fields: string[]): Promise<void>;
|
|
40
41
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
41
42
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
42
|
-
query<T>(): Promise<T>;
|
|
43
|
+
query<T>(query: string, params?: Record<string, any>): Promise<T>;
|
|
44
|
+
fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
|
|
43
45
|
}
|
|
46
|
+
export type FakeQueryHandler<T> = (params?: Record<string, any>) => Promise<T> | T;
|
|
@@ -36,6 +36,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
36
36
|
super(...arguments);
|
|
37
37
|
this.collections = {};
|
|
38
38
|
this._isConnected = false;
|
|
39
|
+
this.fakedQueries = {};
|
|
39
40
|
}
|
|
40
41
|
generateId() {
|
|
41
42
|
return (0, generateId_1.default)();
|
|
@@ -458,10 +459,18 @@ class NeDbDatabase extends AbstractMutexer_1.default {
|
|
|
458
459
|
await this.dropIndex(collectionName, extra);
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
|
-
async query() {
|
|
462
|
+
async query(query, params) {
|
|
463
|
+
const cb = this.fakedQueries[query];
|
|
464
|
+
if (cb) {
|
|
465
|
+
return cb(params);
|
|
466
|
+
}
|
|
462
467
|
throw new SpruceError_1.default({
|
|
463
|
-
code: '
|
|
468
|
+
code: 'QUERY_NOT_FAKED',
|
|
469
|
+
query,
|
|
464
470
|
});
|
|
465
471
|
}
|
|
472
|
+
fakeQuery(query, cb) {
|
|
473
|
+
this.fakedQueries[query] = cb;
|
|
474
|
+
}
|
|
466
475
|
}
|
|
467
476
|
exports.default = NeDbDatabase;
|
|
@@ -102,6 +102,9 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
102
102
|
case 'NOT_IMPLEMENTED':
|
|
103
103
|
message = 'A Not implemented just happened!';
|
|
104
104
|
break;
|
|
105
|
+
case 'QUERY_NOT_FAKED':
|
|
106
|
+
message = `The query '${options.query}' was not faked. Try this.stores.fakeQuery(...).`;
|
|
107
|
+
break;
|
|
105
108
|
default:
|
|
106
109
|
message = super.friendlyMessage();
|
|
107
110
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
exports.default = (0, schema_1.buildErrorSchema)({
|
|
5
|
+
id: 'queryNotFaked',
|
|
6
|
+
name: 'Query not faked',
|
|
7
|
+
fields: {
|
|
8
|
+
query: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
isRequired: true,
|
|
11
|
+
},
|
|
12
|
+
params: {
|
|
13
|
+
type: 'raw',
|
|
14
|
+
options: { valueType: 'Record<string, any>' },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -134,6 +134,33 @@ 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 QueryNotFaked {
|
|
139
|
+
'query': string;
|
|
140
|
+
'params'?: (Record<string, any>) | undefined | null;
|
|
141
|
+
}
|
|
142
|
+
interface QueryNotFakedSchema extends SpruceSchema.Schema {
|
|
143
|
+
id: 'queryNotFaked';
|
|
144
|
+
namespace: 'DataStores';
|
|
145
|
+
name: 'Query not faked';
|
|
146
|
+
fields: {
|
|
147
|
+
/** . */
|
|
148
|
+
'query': {
|
|
149
|
+
type: 'text';
|
|
150
|
+
isRequired: true;
|
|
151
|
+
options: undefined;
|
|
152
|
+
};
|
|
153
|
+
/** . */
|
|
154
|
+
'params': {
|
|
155
|
+
type: 'raw';
|
|
156
|
+
options: {
|
|
157
|
+
valueType: `Record<string, any>`;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
type QueryNotFakedEntity = SchemaEntity<SpruceErrors.DataStores.QueryNotFakedSchema>;
|
|
163
|
+
}
|
|
137
164
|
export declare namespace SpruceErrors.DataStores {
|
|
138
165
|
interface NotImplemented {
|
|
139
166
|
}
|
|
@@ -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 QueryNotFakedErrorOptions extends SpruceErrors.DataStores.QueryNotFaked, ISpruceErrorOptions {
|
|
22
|
+
code: 'QUERY_NOT_FAKED';
|
|
23
|
+
}
|
|
21
24
|
export interface NotImplementedErrorOptions extends SpruceErrors.DataStores.NotImplemented, ISpruceErrorOptions {
|
|
22
25
|
code: 'NOT_IMPLEMENTED';
|
|
23
26
|
}
|
|
@@ -60,5 +63,5 @@ export interface DuplicateKeyErrorOptions extends SpruceErrors.DataStores.Duplic
|
|
|
60
63
|
export interface DatabaseNotConnectedErrorOptions extends SpruceErrors.DataStores.DatabaseNotConnected, ISpruceErrorOptions {
|
|
61
64
|
code: 'DATABASE_NOT_CONNECTED';
|
|
62
65
|
}
|
|
63
|
-
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
66
|
+
type ErrorOptions = UnknownStoreErrorErrorOptions | UnknownErrorErrorOptions | UnknownDatabaseErrorErrorOptions | UnableToConnectToDbErrorOptions | ScrambleNotConfiguredErrorOptions | RecordNotFoundErrorOptions | QueryNotFakedErrorOptions | NotImplementedErrorOptions | MongoIdMappingErrorErrorOptions | InvalidStoreNameErrorOptions | InvalidStoreErrorOptions | InvalidDbConnectionStringErrorOptions | InvalidDatabaseNameErrorOptions | InvalidConnectionStringSchemeErrorOptions | IndexNotFoundErrorOptions | IndexExistsErrorOptions | FailedToLoadStoresErrorOptions | FailedToLoadStoreErrorOptions | DuplicateRecordErrorOptions | DuplicateKeyErrorOptions | DatabaseNotConnectedErrorOptions;
|
|
64
67
|
export default ErrorOptions;
|
|
@@ -490,6 +490,7 @@ export default class MongoDatabase {
|
|
|
490
490
|
return __awaiter(this, void 0, void 0, function* () {
|
|
491
491
|
throw new SpruceError({
|
|
492
492
|
code: 'NOT_IMPLEMENTED',
|
|
493
|
+
friendlyMessage: `You cannot run a query using mongodb. Try a different database adapter!`,
|
|
493
494
|
});
|
|
494
495
|
});
|
|
495
496
|
}
|
|
@@ -4,6 +4,7 @@ import { QueryOptions } from '../types/query.types';
|
|
|
4
4
|
export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
5
5
|
private collections;
|
|
6
6
|
private _isConnected;
|
|
7
|
+
private fakedQueries;
|
|
7
8
|
generateId(): string;
|
|
8
9
|
connect(): Promise<void>;
|
|
9
10
|
close(): Promise<void>;
|
|
@@ -39,5 +40,7 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
|
|
|
39
40
|
createIndex(collection: string, fields: string[]): Promise<void>;
|
|
40
41
|
syncUniqueIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
41
42
|
syncIndexes(collectionName: string, indexes: string[][]): Promise<void>;
|
|
42
|
-
query<T>(): Promise<T>;
|
|
43
|
+
query<T>(query: string, params?: Record<string, any>): Promise<T>;
|
|
44
|
+
fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
|
|
43
45
|
}
|
|
46
|
+
export type FakeQueryHandler<T> = (params?: Record<string, any>) => Promise<T> | T;
|
|
@@ -40,6 +40,7 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
40
40
|
super(...arguments);
|
|
41
41
|
this.collections = {};
|
|
42
42
|
this._isConnected = false;
|
|
43
|
+
this.fakedQueries = {};
|
|
43
44
|
}
|
|
44
45
|
generateId() {
|
|
45
46
|
return generateId();
|
|
@@ -508,11 +509,19 @@ export default class NeDbDatabase extends AbstractMutexer {
|
|
|
508
509
|
}
|
|
509
510
|
});
|
|
510
511
|
}
|
|
511
|
-
query() {
|
|
512
|
+
query(query, params) {
|
|
512
513
|
return __awaiter(this, void 0, void 0, function* () {
|
|
514
|
+
const cb = this.fakedQueries[query];
|
|
515
|
+
if (cb) {
|
|
516
|
+
return cb(params);
|
|
517
|
+
}
|
|
513
518
|
throw new SpruceError({
|
|
514
|
-
code: '
|
|
519
|
+
code: 'QUERY_NOT_FAKED',
|
|
520
|
+
query,
|
|
515
521
|
});
|
|
516
522
|
});
|
|
517
523
|
}
|
|
524
|
+
fakeQuery(query, cb) {
|
|
525
|
+
this.fakedQueries[query] = cb;
|
|
526
|
+
}
|
|
518
527
|
}
|
|
@@ -97,6 +97,9 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
|
|
|
97
97
|
case 'NOT_IMPLEMENTED':
|
|
98
98
|
message = 'A Not implemented just happened!';
|
|
99
99
|
break;
|
|
100
|
+
case 'QUERY_NOT_FAKED':
|
|
101
|
+
message = `The query '${options.query}' was not faked. Try this.stores.fakeQuery(...).`;
|
|
102
|
+
break;
|
|
100
103
|
default:
|
|
101
104
|
message = super.friendlyMessage();
|
|
102
105
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { buildErrorSchema } from '@sprucelabs/schema';
|
|
2
|
+
export default buildErrorSchema({
|
|
3
|
+
id: 'queryNotFaked',
|
|
4
|
+
name: 'Query not faked',
|
|
5
|
+
fields: {
|
|
6
|
+
query: {
|
|
7
|
+
type: 'text',
|
|
8
|
+
isRequired: true,
|
|
9
|
+
},
|
|
10
|
+
params: {
|
|
11
|
+
type: 'raw',
|
|
12
|
+
options: { valueType: 'Record<string, any>' },
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -26,7 +26,7 @@ export interface Database {
|
|
|
26
26
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
27
27
|
createUniqueIndex(collection: string, fields: UniqueIndex): Promise<void>;
|
|
28
28
|
createIndex(collection: string, fields: Index): Promise<void>;
|
|
29
|
-
query<T>(query: string): Promise<T>;
|
|
29
|
+
query<T>(query: string, params?: Record<string, any>): Promise<T>;
|
|
30
30
|
}
|
|
31
31
|
export interface DatabaseOptions {
|
|
32
32
|
dbName?: string;
|
|
@@ -26,7 +26,7 @@ export interface Database {
|
|
|
26
26
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
27
27
|
createUniqueIndex(collection: string, fields: UniqueIndex): Promise<void>;
|
|
28
28
|
createIndex(collection: string, fields: Index): Promise<void>;
|
|
29
|
-
query<T>(query: string): Promise<T>;
|
|
29
|
+
query<T>(query: string, params?: Record<string, any>): Promise<T>;
|
|
30
30
|
}
|
|
31
31
|
export interface DatabaseOptions {
|
|
32
32
|
dbName?: string;
|