@sprucelabs/data-stores 25.7.7 → 25.7.8

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.
@@ -3,14 +3,16 @@ import AbstractStore from '../stores/AbstractStore';
3
3
  import { QueryOptions } from '../types/query.types';
4
4
  import { PrepareOptions } from '../types/stores.types';
5
5
  export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<ResponseRecord> {
6
+ static Class?: new (...args: any[]) => BatchCursor<any>;
6
7
  private store;
7
8
  private options?;
8
- private query?;
9
+ protected query?: Record<string, any>;
9
10
  private nextHandler?;
10
- private constructor();
11
+ private lastId?;
12
+ protected constructor(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions);
11
13
  [Symbol.asyncIterator](): AsyncIterator<ResponseRecord, any, undefined>;
12
14
  static Cursor<Response>(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions): BatchCursor<Response>;
13
- setOnNextResults(cb: (results: ResponseRecord[]) => never[]): void;
15
+ setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
14
16
  getTotalRecords(): Promise<number>;
15
17
  next(): Promise<ResponseRecord[] | null>;
16
18
  private bumpCursorPosition;
@@ -27,8 +27,9 @@ class BatchCursorImpl {
27
27
  };
28
28
  }
29
29
  static Cursor(store, query, options) {
30
+ var _a;
30
31
  (0, schema_1.assertOptions)({ store }, ['store'], 'You need to pass a store to BatchCursor.Cursor()');
31
- return new this(store, query, options);
32
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(store, query, options);
32
33
  }
33
34
  setOnNextResults(cb) {
34
35
  this.nextHandler = cb;
@@ -37,9 +38,15 @@ class BatchCursorImpl {
37
38
  return this.store.count(Object.assign({}, this.query));
38
39
  }
39
40
  async next() {
40
- var _a;
41
- const _b = (_a = this.options) !== null && _a !== void 0 ? _a : {}, { batchSize = 10 } = _b, rest = __rest(_b, ["batchSize"]);
42
- const matches = await this.store.find(Object.assign({}, this.query), {
41
+ var _a, _b;
42
+ const _c = (_a = this.options) !== null && _a !== void 0 ? _a : {}, { batchSize = 10 } = _c, rest = __rest(_c, ["batchSize"]);
43
+ let query = Object.assign({}, this.query);
44
+ if (this.lastId) {
45
+ query = {
46
+ $and: [(_b = this.query) !== null && _b !== void 0 ? _b : {}, { id: { $gt: this.lastId } }],
47
+ };
48
+ }
49
+ const matches = await this.store.find(query, {
43
50
  limit: batchSize,
44
51
  }, Object.assign({}, rest));
45
52
  if (matches.length === 0) {
@@ -57,9 +64,7 @@ class BatchCursorImpl {
57
64
  if (!this.query) {
58
65
  this.query = {};
59
66
  }
60
- this.query = {
61
- $and: [{ id: { $gt: last.id } }, Object.assign({}, this.query)],
62
- };
67
+ this.lastId = last.id;
63
68
  }
64
69
  }
65
70
  }
@@ -3,14 +3,16 @@ import AbstractStore from '../stores/AbstractStore';
3
3
  import { QueryOptions } from '../types/query.types';
4
4
  import { PrepareOptions } from '../types/stores.types';
5
5
  export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<ResponseRecord> {
6
+ static Class?: new (...args: any[]) => BatchCursor<any>;
6
7
  private store;
7
8
  private options?;
8
- private query?;
9
+ protected query?: Record<string, any>;
9
10
  private nextHandler?;
10
- private constructor();
11
+ private lastId?;
12
+ protected constructor(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions);
11
13
  [Symbol.asyncIterator](): AsyncIterator<ResponseRecord, any, undefined>;
12
14
  static Cursor<Response>(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions): BatchCursor<Response>;
13
- setOnNextResults(cb: (results: ResponseRecord[]) => never[]): void;
15
+ setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
14
16
  getTotalRecords(): Promise<number>;
15
17
  next(): Promise<ResponseRecord[] | null>;
16
18
  private bumpCursorPosition;
@@ -34,8 +34,9 @@ export default class BatchCursorImpl {
34
34
  };
35
35
  }
36
36
  static Cursor(store, query, options) {
37
+ var _a;
37
38
  assertOptions({ store }, ['store'], 'You need to pass a store to BatchCursor.Cursor()');
38
- return new this(store, query, options);
39
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(store, query, options);
39
40
  }
40
41
  setOnNextResults(cb) {
41
42
  this.nextHandler = cb;
@@ -46,10 +47,16 @@ export default class BatchCursorImpl {
46
47
  });
47
48
  }
48
49
  next() {
49
- var _a;
50
+ var _a, _b;
50
51
  return __awaiter(this, void 0, void 0, function* () {
51
- const _b = (_a = this.options) !== null && _a !== void 0 ? _a : {}, { batchSize = 10 } = _b, rest = __rest(_b, ["batchSize"]);
52
- const matches = yield this.store.find(Object.assign({}, this.query), {
52
+ const _c = (_a = this.options) !== null && _a !== void 0 ? _a : {}, { batchSize = 10 } = _c, rest = __rest(_c, ["batchSize"]);
53
+ let query = Object.assign({}, this.query);
54
+ if (this.lastId) {
55
+ query = {
56
+ $and: [(_b = this.query) !== null && _b !== void 0 ? _b : {}, { id: { $gt: this.lastId } }],
57
+ };
58
+ }
59
+ const matches = yield this.store.find(query, {
53
60
  limit: batchSize,
54
61
  }, Object.assign({}, rest));
55
62
  if (matches.length === 0) {
@@ -68,9 +75,7 @@ export default class BatchCursorImpl {
68
75
  if (!this.query) {
69
76
  this.query = {};
70
77
  }
71
- this.query = {
72
- $and: [{ id: { $gt: last.id } }, Object.assign({}, this.query)],
73
- };
78
+ this.lastId = last.id;
74
79
  }
75
80
  }
76
81
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "25.7.7",
6
+ "version": "25.7.8",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",