@sprucelabs/data-stores 28.5.115 → 28.6.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/esm/plugins/DatabaseFieldMapperPlugin.d.ts +2 -2
- package/build/esm/stores/AbstractStore.d.ts +2 -1
- package/build/esm/stores/AbstractStore.js +10 -8
- package/build/esm/types/stores.types.d.ts +3 -3
- package/build/plugins/DatabaseFieldMapperPlugin.d.ts +2 -2
- package/build/stores/AbstractStore.d.ts +2 -1
- package/build/stores/AbstractStore.js +9 -7
- package/build/types/stores.types.d.ts +3 -3
- package/package.json +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FullQueryOptions } from '../stores/AbstractStore';
|
2
2
|
import { DataStorePlugin, DataStorePluginPrepareResponse, DataStorePluginWillCreateOneResponse, DataStorePluginWillFindResponse, DataStorePluginWillUpdateOneResponse } from '../types/stores.types';
|
3
3
|
export default class DatabaseFieldMapperPlugin implements DataStorePlugin {
|
4
4
|
private mapper;
|
@@ -7,5 +7,5 @@ export default class DatabaseFieldMapperPlugin implements DataStorePlugin {
|
|
7
7
|
willCreateOne(values: Record<string, any>): Promise<void | DataStorePluginWillCreateOneResponse>;
|
8
8
|
prepareRecord(record: Record<string, any>): Promise<void | DataStorePluginPrepareResponse>;
|
9
9
|
willUpdateOne(query: Record<string, any>, updates: Record<string, any>): Promise<void | DataStorePluginWillUpdateOneResponse>;
|
10
|
-
willFind(query: Record<string, any>, options?:
|
10
|
+
willFind(query: Record<string, any>, options?: FullQueryOptions): Promise<void | DataStorePluginWillFindResponse>;
|
11
11
|
}
|
@@ -42,7 +42,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
42
42
|
private _findOne;
|
43
43
|
private handleDidFindForPlugins;
|
44
44
|
count(query?: QueryBuilder<QueryRecord>): Promise<number>;
|
45
|
-
find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>,
|
45
|
+
find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: FullQueryOptions<CreateEntityInstances, FullSchema, F>, legacyOptions?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<SchemaValues<FullSchema, false, CreateEntityInstances, false, F, SchemaPublicFieldNames<FullSchema>>>[]>;
|
46
46
|
private _find;
|
47
47
|
private handleWillFindPlugins;
|
48
48
|
findBatch<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query?: QueryBuilder<QueryRecord>, options?: FindBatchOptions<IncludePrivateFields, FullSchema, F>): Promise<import("../cursors/BatchCursor").BatchCursor<SchemaValues<FullSchema, CreateEntityInstances, IncludePrivateFields, false, F, PF>>>;
|
@@ -61,4 +61,5 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
61
61
|
delete(query: QueryBuilder<QueryRecord>): Promise<number>;
|
62
62
|
}
|
63
63
|
type Response<FullSchema extends Schema, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, PF extends SchemaPublicFieldNames<FullSchema>, F extends SchemaFieldNames<FullSchema>> = SchemaValues<FullSchema, CreateEntityInstances, IncludePrivateFields, false, F, PF>;
|
64
|
+
export type FullQueryOptions<CreateEntityInstances extends boolean = boolean, FullSchema extends Schema = Schema, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>> = Omit<QueryOptions, 'includeFields'> & PrepareOptions<CreateEntityInstances, FullSchema, F>;
|
64
65
|
export {};
|
@@ -193,7 +193,7 @@ export default class AbstractStore extends AbstractMutexer {
|
|
193
193
|
return __awaiter(this, arguments, void 0, function* (query, options = {}, internalOptions = {
|
194
194
|
shouldTriggerWillQuery: true,
|
195
195
|
}) {
|
196
|
-
const results = yield this._find(query, { limit: 1 }, options, internalOptions);
|
196
|
+
const results = yield this._find(query, Object.assign({ limit: 1 }, options), internalOptions);
|
197
197
|
let match = results[0];
|
198
198
|
if (match) {
|
199
199
|
match = (yield this.handleDidFindForPlugins(query, match));
|
@@ -220,26 +220,28 @@ export default class AbstractStore extends AbstractMutexer {
|
|
220
220
|
return count;
|
221
221
|
});
|
222
222
|
}
|
223
|
-
find(query,
|
223
|
+
find(query, options,
|
224
|
+
// @deprecated - use parameter before this instead
|
225
|
+
legacyOptions) {
|
224
226
|
return __awaiter(this, void 0, void 0, function* () {
|
225
|
-
return this._find(query,
|
227
|
+
return this._find(query, Object.assign(Object.assign({}, options), legacyOptions));
|
226
228
|
});
|
227
229
|
}
|
228
|
-
_find(query_1,
|
229
|
-
return __awaiter(this, arguments, void 0, function* (query,
|
230
|
+
_find(query_1, options_1) {
|
231
|
+
return __awaiter(this, arguments, void 0, function* (query, options, internalOptions = {
|
230
232
|
shouldTriggerWillQuery: true,
|
231
233
|
}) {
|
232
234
|
var _a, _b;
|
233
235
|
let resolvedQuery = query;
|
234
|
-
let resolvedOptions =
|
236
|
+
let resolvedOptions = options;
|
235
237
|
const { shouldTriggerWillQuery } = internalOptions;
|
236
238
|
if (shouldTriggerWillQuery) {
|
237
239
|
resolvedQuery = ((_b = (yield ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, query)))) !== null && _b !== void 0 ? _b : query);
|
238
|
-
const { query: q, options: o } = yield this.handleWillFindPlugins(resolvedQuery,
|
240
|
+
const { query: q, options: o } = yield this.handleWillFindPlugins(resolvedQuery, resolvedOptions);
|
239
241
|
resolvedQuery = q;
|
240
242
|
resolvedOptions = o;
|
241
243
|
}
|
242
|
-
const results = yield this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields:
|
244
|
+
const results = yield this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: resolvedOptions === null || resolvedOptions === void 0 ? void 0 : resolvedOptions.includeFields }), {
|
243
245
|
primaryFieldNames: this.primaryFieldNames,
|
244
246
|
});
|
245
247
|
if (results) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema, SchemaFieldNames, SchemaPublicValues, SchemaValues } from '@sprucelabs/schema';
|
2
2
|
import StoreFactory from '../factories/StoreFactory';
|
3
|
+
import { FullQueryOptions } from '../stores/AbstractStore';
|
3
4
|
import { Database } from './database.types';
|
4
|
-
import { QueryOptions } from './query.types';
|
5
5
|
export declare const saveOperations: readonly ["$push", "$inc", "$min", "$max", "$mul", "$push", "$pull", "$pop"];
|
6
6
|
export type SaveOperation = (typeof saveOperations)[number];
|
7
7
|
export type SaveOperations = Partial<Record<SaveOperation, Record<string, any>>>;
|
@@ -39,7 +39,7 @@ export interface DataStorePlugin {
|
|
39
39
|
didFindOne?: (query: Record<string, any>, record: Record<string, any>) => Promise<void | DataStorePluginDidFindOneResponse>;
|
40
40
|
getName(): string;
|
41
41
|
prepareRecord?: (record: Record<string, any>) => Promise<void | DataStorePluginPrepareResponse>;
|
42
|
-
willFind?: (query: Record<string, any>, options?:
|
42
|
+
willFind?: (query: Record<string, any>, options?: FullQueryOptions) => Promise<void | DataStorePluginWillFindResponse>;
|
43
43
|
}
|
44
44
|
export interface DataStorePluginPrepareResponse {
|
45
45
|
newValues?: Record<string, any>;
|
@@ -64,5 +64,5 @@ export interface DataStorePluginDidFindOneResponse {
|
|
64
64
|
}
|
65
65
|
export interface DataStorePluginWillFindResponse {
|
66
66
|
query?: Record<string, any>;
|
67
|
-
options?:
|
67
|
+
options?: FullQueryOptions;
|
68
68
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FullQueryOptions } from '../stores/AbstractStore';
|
2
2
|
import { DataStorePlugin, DataStorePluginPrepareResponse, DataStorePluginWillCreateOneResponse, DataStorePluginWillFindResponse, DataStorePluginWillUpdateOneResponse } from '../types/stores.types';
|
3
3
|
export default class DatabaseFieldMapperPlugin implements DataStorePlugin {
|
4
4
|
private mapper;
|
@@ -7,5 +7,5 @@ export default class DatabaseFieldMapperPlugin implements DataStorePlugin {
|
|
7
7
|
willCreateOne(values: Record<string, any>): Promise<void | DataStorePluginWillCreateOneResponse>;
|
8
8
|
prepareRecord(record: Record<string, any>): Promise<void | DataStorePluginPrepareResponse>;
|
9
9
|
willUpdateOne(query: Record<string, any>, updates: Record<string, any>): Promise<void | DataStorePluginWillUpdateOneResponse>;
|
10
|
-
willFind(query: Record<string, any>, options?:
|
10
|
+
willFind(query: Record<string, any>, options?: FullQueryOptions): Promise<void | DataStorePluginWillFindResponse>;
|
11
11
|
}
|
@@ -42,7 +42,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
42
42
|
private _findOne;
|
43
43
|
private handleDidFindForPlugins;
|
44
44
|
count(query?: QueryBuilder<QueryRecord>): Promise<number>;
|
45
|
-
find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>,
|
45
|
+
find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: FullQueryOptions<CreateEntityInstances, FullSchema, F>, legacyOptions?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<SchemaValues<FullSchema, false, CreateEntityInstances, false, F, SchemaPublicFieldNames<FullSchema>>>[]>;
|
46
46
|
private _find;
|
47
47
|
private handleWillFindPlugins;
|
48
48
|
findBatch<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query?: QueryBuilder<QueryRecord>, options?: FindBatchOptions<IncludePrivateFields, FullSchema, F>): Promise<import("../cursors/BatchCursor").BatchCursor<SchemaValues<FullSchema, CreateEntityInstances, IncludePrivateFields, false, F, PF>>>;
|
@@ -61,4 +61,5 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
61
61
|
delete(query: QueryBuilder<QueryRecord>): Promise<number>;
|
62
62
|
}
|
63
63
|
type Response<FullSchema extends Schema, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, PF extends SchemaPublicFieldNames<FullSchema>, F extends SchemaFieldNames<FullSchema>> = SchemaValues<FullSchema, CreateEntityInstances, IncludePrivateFields, false, F, PF>;
|
64
|
+
export type FullQueryOptions<CreateEntityInstances extends boolean = boolean, FullSchema extends Schema = Schema, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>> = Omit<QueryOptions, 'includeFields'> & PrepareOptions<CreateEntityInstances, FullSchema, F>;
|
64
65
|
export {};
|
@@ -209,7 +209,7 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
209
209
|
async _findOne(query, options = {}, internalOptions = {
|
210
210
|
shouldTriggerWillQuery: true,
|
211
211
|
}) {
|
212
|
-
const results = await this._find(query, { limit: 1 }, options, internalOptions);
|
212
|
+
const results = await this._find(query, Object.assign({ limit: 1 }, options), internalOptions);
|
213
213
|
let match = results[0];
|
214
214
|
if (match) {
|
215
215
|
match = (await this.handleDidFindForPlugins(query, match));
|
@@ -231,23 +231,25 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
231
231
|
const count = await this.db.count(this.collectionName, query);
|
232
232
|
return count;
|
233
233
|
}
|
234
|
-
async find(query,
|
235
|
-
|
234
|
+
async find(query, options,
|
235
|
+
// @deprecated - use parameter before this instead
|
236
|
+
legacyOptions) {
|
237
|
+
return this._find(query, Object.assign(Object.assign({}, options), legacyOptions));
|
236
238
|
}
|
237
|
-
async _find(query,
|
239
|
+
async _find(query, options, internalOptions = {
|
238
240
|
shouldTriggerWillQuery: true,
|
239
241
|
}) {
|
240
242
|
var _a, _b;
|
241
243
|
let resolvedQuery = query;
|
242
|
-
let resolvedOptions =
|
244
|
+
let resolvedOptions = options;
|
243
245
|
const { shouldTriggerWillQuery } = internalOptions;
|
244
246
|
if (shouldTriggerWillQuery) {
|
245
247
|
resolvedQuery = ((_b = (await ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, query)))) !== null && _b !== void 0 ? _b : query);
|
246
|
-
const { query: q, options: o } = await this.handleWillFindPlugins(resolvedQuery,
|
248
|
+
const { query: q, options: o } = await this.handleWillFindPlugins(resolvedQuery, resolvedOptions);
|
247
249
|
resolvedQuery = q;
|
248
250
|
resolvedOptions = o;
|
249
251
|
}
|
250
|
-
const results = await this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields:
|
252
|
+
const results = await this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: resolvedOptions === null || resolvedOptions === void 0 ? void 0 : resolvedOptions.includeFields }), {
|
251
253
|
primaryFieldNames: this.primaryFieldNames,
|
252
254
|
});
|
253
255
|
if (results) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema, SchemaFieldNames, SchemaPublicValues, SchemaValues } from '@sprucelabs/schema';
|
2
2
|
import StoreFactory from '../factories/StoreFactory';
|
3
|
+
import { FullQueryOptions } from '../stores/AbstractStore';
|
3
4
|
import { Database } from './database.types';
|
4
|
-
import { QueryOptions } from './query.types';
|
5
5
|
export declare const saveOperations: readonly ["$push", "$inc", "$min", "$max", "$mul", "$push", "$pull", "$pop"];
|
6
6
|
export type SaveOperation = (typeof saveOperations)[number];
|
7
7
|
export type SaveOperations = Partial<Record<SaveOperation, Record<string, any>>>;
|
@@ -39,7 +39,7 @@ export interface DataStorePlugin {
|
|
39
39
|
didFindOne?: (query: Record<string, any>, record: Record<string, any>) => Promise<void | DataStorePluginDidFindOneResponse>;
|
40
40
|
getName(): string;
|
41
41
|
prepareRecord?: (record: Record<string, any>) => Promise<void | DataStorePluginPrepareResponse>;
|
42
|
-
willFind?: (query: Record<string, any>, options?:
|
42
|
+
willFind?: (query: Record<string, any>, options?: FullQueryOptions) => Promise<void | DataStorePluginWillFindResponse>;
|
43
43
|
}
|
44
44
|
export interface DataStorePluginPrepareResponse {
|
45
45
|
newValues?: Record<string, any>;
|
@@ -64,5 +64,5 @@ export interface DataStorePluginDidFindOneResponse {
|
|
64
64
|
}
|
65
65
|
export interface DataStorePluginWillFindResponse {
|
66
66
|
query?: Record<string, any>;
|
67
|
-
options?:
|
67
|
+
options?: FullQueryOptions;
|
68
68
|
}
|