@sprucelabs/data-stores 26.2.2 → 26.2.3

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.
@@ -1,5 +1,5 @@
1
1
  import AbstractMutexer from '../mutexers/AbstractMutexer';
2
- import { CreateOptions, Database } from '../types/database.types';
2
+ import { CreateOptions, Database, DatabaseInternalOptions } from '../types/database.types';
3
3
  import { QueryOptions } from '../types/query.types';
4
4
  export default class NeDbDatabase extends AbstractMutexer implements Database {
5
5
  private collections;
@@ -22,8 +22,8 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
22
22
  private loadCollection;
23
23
  dropCollection(name: string): Promise<void>;
24
24
  dropDatabase(): Promise<void>;
25
- findOne(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any> | null>;
26
- find(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any>[]>;
25
+ findOne(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any> | null>;
26
+ find(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>[]>;
27
27
  update(collection: string, query: Record<string, any>, updates: Record<string, any>, neDbOptions?: Record<string, any>): Promise<number>;
28
28
  updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>, neDbOptions?: Record<string, any>, action?: string): Promise<Record<string, any>>;
29
29
  upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
@@ -177,11 +177,12 @@ class NeDbDatabase extends AbstractMutexer_1.default {
177
177
  this.collections = {};
178
178
  return Promise.resolve();
179
179
  }
180
- async findOne(collection, query, options) {
181
- const results = await this.find(collection, this.prepQuery(query !== null && query !== void 0 ? query : {}), Object.assign({ limit: 1 }, (options || {})));
182
- return results[0];
180
+ async findOne(collection, query, options, dbOptions) {
181
+ const results = await this.find(collection, query !== null && query !== void 0 ? query : {}, Object.assign({ limit: 1 }, (options || {})), dbOptions);
182
+ const match = results[0];
183
+ return match;
183
184
  }
184
- async find(collection, query, options) {
185
+ async find(collection, query, options, dbOptions) {
185
186
  await this.randomDelay();
186
187
  if ((options === null || options === void 0 ? void 0 : options.limit) === 0) {
187
188
  return [];
@@ -205,7 +206,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
205
206
  reject(err);
206
207
  }
207
208
  else {
208
- resolve(results.map((r) => this.normalizeRecord(r)));
209
+ resolve(results.map((r) => this.normalizeRecord(r, dbOptions)));
209
210
  }
210
211
  });
211
212
  });
@@ -242,7 +243,7 @@ class NeDbDatabase extends AbstractMutexer_1.default {
242
243
  }));
243
244
  }
244
245
  else {
245
- resolve(docs ? this.normalizeRecord(docs) : numUpdated);
246
+ resolve(docs ? this.normalizeRecord(docs, neDbOptions) : numUpdated);
246
247
  }
247
248
  });
248
249
  });
@@ -1,5 +1,5 @@
1
1
  import AbstractMutexer from '../mutexers/AbstractMutexer';
2
- import { CreateOptions, Database } from '../types/database.types';
2
+ import { CreateOptions, Database, DatabaseInternalOptions } from '../types/database.types';
3
3
  import { QueryOptions } from '../types/query.types';
4
4
  export default class NeDbDatabase extends AbstractMutexer implements Database {
5
5
  private collections;
@@ -22,8 +22,8 @@ export default class NeDbDatabase extends AbstractMutexer implements Database {
22
22
  private loadCollection;
23
23
  dropCollection(name: string): Promise<void>;
24
24
  dropDatabase(): Promise<void>;
25
- findOne(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any> | null>;
26
- find(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any>[]>;
25
+ findOne(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any> | null>;
26
+ find(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>[]>;
27
27
  update(collection: string, query: Record<string, any>, updates: Record<string, any>, neDbOptions?: Record<string, any>): Promise<number>;
28
28
  updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>, neDbOptions?: Record<string, any>, action?: string): Promise<Record<string, any>>;
29
29
  upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
@@ -199,13 +199,14 @@ export default class NeDbDatabase extends AbstractMutexer {
199
199
  return Promise.resolve();
200
200
  });
201
201
  }
202
- findOne(collection, query, options) {
202
+ findOne(collection, query, options, dbOptions) {
203
203
  return __awaiter(this, void 0, void 0, function* () {
204
- const results = yield this.find(collection, this.prepQuery(query !== null && query !== void 0 ? query : {}), Object.assign({ limit: 1 }, (options || {})));
205
- return results[0];
204
+ const results = yield this.find(collection, query !== null && query !== void 0 ? query : {}, Object.assign({ limit: 1 }, (options || {})), dbOptions);
205
+ const match = results[0];
206
+ return match;
206
207
  });
207
208
  }
208
- find(collection, query, options) {
209
+ find(collection, query, options, dbOptions) {
209
210
  return __awaiter(this, void 0, void 0, function* () {
210
211
  yield this.randomDelay();
211
212
  if ((options === null || options === void 0 ? void 0 : options.limit) === 0) {
@@ -230,7 +231,7 @@ export default class NeDbDatabase extends AbstractMutexer {
230
231
  reject(err);
231
232
  }
232
233
  else {
233
- resolve(results.map((r) => this.normalizeRecord(r)));
234
+ resolve(results.map((r) => this.normalizeRecord(r, dbOptions)));
234
235
  }
235
236
  });
236
237
  });
@@ -271,7 +272,7 @@ export default class NeDbDatabase extends AbstractMutexer {
271
272
  }));
272
273
  }
273
274
  else {
274
- resolve(docs ? this.normalizeRecord(docs) : numUpdated);
275
+ resolve(docs ? this.normalizeRecord(docs, neDbOptions) : numUpdated);
275
276
  }
276
277
  }));
277
278
  });
@@ -226,14 +226,17 @@ export default class AbstractStore extends AbstractMutexer {
226
226
  var _a, _b;
227
227
  return __awaiter(this, void 0, void 0, function* () {
228
228
  let resolvedQuery = query;
229
+ let resolvedOptions = queryOptions;
229
230
  const { shouldTriggerWillQuery } = internalOptions;
230
231
  if (shouldTriggerWillQuery) {
231
232
  resolvedQuery = ((_b = (yield ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, query)))) !== null && _b !== void 0 ? _b : query);
233
+ const { query: q, options: o } = yield this.handleWillFindPlugins(resolvedQuery, queryOptions);
234
+ resolvedQuery = q;
235
+ resolvedOptions = o;
232
236
  }
233
- const { query: q, options: o } = yield this.handleWillFindPlugins(resolvedQuery, queryOptions);
234
- resolvedQuery = q;
235
- const resolvedOptions = o !== null && o !== void 0 ? o : queryOptions;
236
- const results = yield this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: options === null || options === void 0 ? void 0 : options.includeFields }));
237
+ const results = yield this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: options === null || options === void 0 ? void 0 : options.includeFields }), {
238
+ primaryFieldNames: this.primaryFieldNames,
239
+ });
237
240
  if (results) {
238
241
  const all = results.map((result) => this.prepareAndNormalizeRecord(result, Object.assign(Object.assign({}, options), { shouldStripUndefinedAndNullValues: true })));
239
242
  const records = yield Promise.all(all);
@@ -345,7 +348,9 @@ export default class AbstractStore extends AbstractMutexer {
345
348
  for (const { name, value } of ops) {
346
349
  normalizedValues[name] = value;
347
350
  }
348
- const results = yield this.db.updateOne(this.collectionName, q, normalizedValues);
351
+ const results = yield this.db.updateOne(this.collectionName, q, normalizedValues, {
352
+ primaryFieldNames: this.primaryFieldNames,
353
+ });
349
354
  yield ((_c = this.didUpdate) === null || _c === void 0 ? void 0 : _c.call(this, current, results));
350
355
  return this.prepareAndNormalizeRecord(results, options);
351
356
  }
@@ -16,9 +16,9 @@ export interface Database {
16
16
  create(collection: string, values: Record<string, any>[]): Promise<Record<string, any>[]>;
17
17
  dropCollection(name: string): Promise<void>;
18
18
  dropDatabase(): Promise<void>;
19
- findOne(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any> | null>;
20
- find(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any>[]>;
21
- updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
19
+ findOne(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any> | null>;
20
+ find(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>[]>;
21
+ updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>>;
22
22
  update(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<number>;
23
23
  upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
24
24
  delete(collection: string, query: Record<string, any>): Promise<number>;
@@ -40,6 +40,8 @@ export type TestConnect = (connectionString?: string, dbName?: string) => Promis
40
40
  }>;
41
41
  export type UniqueIndex = string[];
42
42
  export type Index = string[];
43
- export interface CreateOptions {
43
+ export interface CreateOptions extends DatabaseInternalOptions {
44
+ }
45
+ export interface DatabaseInternalOptions {
44
46
  primaryFieldNames?: string[];
45
47
  }
@@ -224,14 +224,17 @@ class AbstractStore extends AbstractMutexer_1.default {
224
224
  }) {
225
225
  var _a, _b;
226
226
  let resolvedQuery = query;
227
+ let resolvedOptions = queryOptions;
227
228
  const { shouldTriggerWillQuery } = internalOptions;
228
229
  if (shouldTriggerWillQuery) {
229
230
  resolvedQuery = ((_b = (await ((_a = this.willFind) === null || _a === void 0 ? void 0 : _a.call(this, query)))) !== null && _b !== void 0 ? _b : query);
231
+ const { query: q, options: o } = await this.handleWillFindPlugins(resolvedQuery, queryOptions);
232
+ resolvedQuery = q;
233
+ resolvedOptions = o;
230
234
  }
231
- const { query: q, options: o } = await this.handleWillFindPlugins(resolvedQuery, queryOptions);
232
- resolvedQuery = q;
233
- const resolvedOptions = o !== null && o !== void 0 ? o : queryOptions;
234
- const results = await this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: options === null || options === void 0 ? void 0 : options.includeFields }));
235
+ const results = await this.db.find(this.collectionName, resolvedQuery, Object.assign(Object.assign({}, resolvedOptions), { includeFields: options === null || options === void 0 ? void 0 : options.includeFields }), {
236
+ primaryFieldNames: this.primaryFieldNames,
237
+ });
235
238
  if (results) {
236
239
  const all = results.map((result) => this.prepareAndNormalizeRecord(result, Object.assign(Object.assign({}, options), { shouldStripUndefinedAndNullValues: true })));
237
240
  const records = await Promise.all(all);
@@ -331,7 +334,9 @@ class AbstractStore extends AbstractMutexer_1.default {
331
334
  for (const { name, value } of ops) {
332
335
  normalizedValues[name] = value;
333
336
  }
334
- const results = await this.db.updateOne(this.collectionName, q, normalizedValues);
337
+ const results = await this.db.updateOne(this.collectionName, q, normalizedValues, {
338
+ primaryFieldNames: this.primaryFieldNames,
339
+ });
335
340
  await ((_c = this.didUpdate) === null || _c === void 0 ? void 0 : _c.call(this, current, results));
336
341
  return this.prepareAndNormalizeRecord(results, options);
337
342
  }
@@ -16,9 +16,9 @@ export interface Database {
16
16
  create(collection: string, values: Record<string, any>[]): Promise<Record<string, any>[]>;
17
17
  dropCollection(name: string): Promise<void>;
18
18
  dropDatabase(): Promise<void>;
19
- findOne(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any> | null>;
20
- find(collection: string, query?: Record<string, any>, options?: QueryOptions): Promise<Record<string, any>[]>;
21
- updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
19
+ findOne(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any> | null>;
20
+ find(collection: string, query?: Record<string, any>, options?: QueryOptions, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>[]>;
21
+ updateOne(collection: string, query: Record<string, any>, updates: Record<string, any>, dbOptions?: DatabaseInternalOptions): Promise<Record<string, any>>;
22
22
  update(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<number>;
23
23
  upsertOne(collection: string, query: Record<string, any>, updates: Record<string, any>): Promise<Record<string, any>>;
24
24
  delete(collection: string, query: Record<string, any>): Promise<number>;
@@ -40,6 +40,8 @@ export type TestConnect = (connectionString?: string, dbName?: string) => Promis
40
40
  }>;
41
41
  export type UniqueIndex = string[];
42
42
  export type Index = string[];
43
- export interface CreateOptions {
43
+ export interface CreateOptions extends DatabaseInternalOptions {
44
+ }
45
+ export interface DatabaseInternalOptions {
44
46
  primaryFieldNames?: string[];
45
47
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "26.2.2",
6
+ "version": "26.2.3",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",