@sprucelabs/data-stores 25.6.0 → 25.7.1

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.
@@ -8,6 +8,7 @@ export default class BatchArrayCursor<T> implements BatchCursor<T> {
8
8
  getTotalRecords(): Promise<number>;
9
9
  setOnNextResults(cb: OnNextResultsHandler<T>): void;
10
10
  next(): Promise<T[] | null>;
11
+ [Symbol.asyncIterator](): AsyncIterator<T, T, undefined>;
11
12
  }
12
13
  export type BatchArrayCursorOptions = {
13
14
  batchSize?: number;
@@ -24,5 +24,13 @@ class BatchArrayCursor {
24
24
  }
25
25
  return i.length ? i : null;
26
26
  }
27
+ [Symbol.asyncIterator]() {
28
+ return {
29
+ next: async () => {
30
+ const value = await this.next();
31
+ return { value, done: value === null };
32
+ },
33
+ };
34
+ }
27
35
  }
28
36
  exports.default = BatchArrayCursor;
@@ -8,6 +8,7 @@ export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<Resp
8
8
  private query?;
9
9
  private nextHandler?;
10
10
  private constructor();
11
+ [Symbol.asyncIterator](): AsyncIterator<ResponseRecord, any, undefined>;
11
12
  static Cursor<Response>(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions): BatchCursor<Response>;
12
13
  setOnNextResults(cb: (results: ResponseRecord[]) => never[]): void;
13
14
  getTotalRecords(): Promise<number>;
@@ -18,7 +19,7 @@ export interface FindBatchOptions<IncludePrivateFields extends boolean = true, F
18
19
  batchSize?: number;
19
20
  }
20
21
  export type OnNextResultsHandler<ResponseRecord> = (results: ResponseRecord[]) => Record<string, any>[] | Promise<Record<string, any>[]>;
21
- export interface BatchCursor<ResponseRecord> {
22
+ export interface BatchCursor<ResponseRecord> extends AsyncIterable<ResponseRecord> {
22
23
  getTotalRecords(): Promise<number>;
23
24
  setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
24
25
  next(): Promise<ResponseRecord[] | null>;
@@ -17,6 +17,14 @@ class BatchCursorImpl {
17
17
  this.query = query;
18
18
  this.options = options;
19
19
  }
20
+ [Symbol.asyncIterator]() {
21
+ return {
22
+ next: async () => {
23
+ const value = await this.next();
24
+ return { value, done: value === null };
25
+ },
26
+ };
27
+ }
20
28
  static Cursor(store, query, options) {
21
29
  return new this(store, query, options);
22
30
  }
@@ -8,6 +8,7 @@ export default class BatchArrayCursor<T> implements BatchCursor<T> {
8
8
  getTotalRecords(): Promise<number>;
9
9
  setOnNextResults(cb: OnNextResultsHandler<T>): void;
10
10
  next(): Promise<T[] | null>;
11
+ [Symbol.asyncIterator](): AsyncIterator<T, T, undefined>;
11
12
  }
12
13
  export type BatchArrayCursorOptions = {
13
14
  batchSize?: number;
@@ -35,4 +35,12 @@ export default class BatchArrayCursor {
35
35
  return i.length ? i : null;
36
36
  });
37
37
  }
38
+ [Symbol.asyncIterator]() {
39
+ return {
40
+ next: () => __awaiter(this, void 0, void 0, function* () {
41
+ const value = yield this.next();
42
+ return { value, done: value === null };
43
+ }),
44
+ };
45
+ }
38
46
  }
@@ -8,6 +8,7 @@ export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<Resp
8
8
  private query?;
9
9
  private nextHandler?;
10
10
  private constructor();
11
+ [Symbol.asyncIterator](): AsyncIterator<ResponseRecord, any, undefined>;
11
12
  static Cursor<Response>(store: AbstractStore<Schema>, query?: Record<string, any>, options?: FindBatchOptions): BatchCursor<Response>;
12
13
  setOnNextResults(cb: (results: ResponseRecord[]) => never[]): void;
13
14
  getTotalRecords(): Promise<number>;
@@ -18,7 +19,7 @@ export interface FindBatchOptions<IncludePrivateFields extends boolean = true, F
18
19
  batchSize?: number;
19
20
  }
20
21
  export type OnNextResultsHandler<ResponseRecord> = (results: ResponseRecord[]) => Record<string, any>[] | Promise<Record<string, any>[]>;
21
- export interface BatchCursor<ResponseRecord> {
22
+ export interface BatchCursor<ResponseRecord> extends AsyncIterable<ResponseRecord> {
22
23
  getTotalRecords(): Promise<number>;
23
24
  setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
24
25
  next(): Promise<ResponseRecord[] | null>;
@@ -24,6 +24,14 @@ export default class BatchCursorImpl {
24
24
  this.query = query;
25
25
  this.options = options;
26
26
  }
27
+ [Symbol.asyncIterator]() {
28
+ return {
29
+ next: () => __awaiter(this, void 0, void 0, function* () {
30
+ const value = yield this.next();
31
+ return { value, done: value === null };
32
+ }),
33
+ };
34
+ }
27
35
  static Cursor(store, query, options) {
28
36
  return new this(store, query, options);
29
37
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "25.6.0",
6
+ "version": "25.7.1",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -68,23 +68,23 @@
68
68
  "upgrade.packages.test": "yarn upgrade.packages.all && yarn lint && yarn build.dev && yarn test"
69
69
  },
70
70
  "dependencies": {
71
- "@sprucelabs/error": "^5.1.37",
71
+ "@sprucelabs/error": "^5.1.38",
72
72
  "@sprucelabs/globby": "^1.0.3",
73
- "@sprucelabs/schema": "^29.0.73",
74
- "@sprucelabs/spruce-skill-utils": "^30.1.6",
73
+ "@sprucelabs/schema": "^29.0.74",
74
+ "@sprucelabs/spruce-skill-utils": "^30.1.7",
75
75
  "just-clone": "^6.2.0",
76
76
  "lodash": "^4.17.21",
77
77
  "mongodb": "^6.2.0",
78
78
  "nedb": "^1.8.0"
79
79
  },
80
80
  "devDependencies": {
81
- "@sprucelabs/esm-postbuild": "^5.0.85",
82
- "@sprucelabs/jest-json-reporter": "^7.0.112",
81
+ "@sprucelabs/esm-postbuild": "^5.0.86",
82
+ "@sprucelabs/jest-json-reporter": "^7.0.113",
83
83
  "@sprucelabs/jest-sheets-reporter": "^3.0.26",
84
- "@sprucelabs/resolve-path-aliases": "^1.1.254",
84
+ "@sprucelabs/resolve-path-aliases": "^1.1.255",
85
85
  "@sprucelabs/semantic-release": "^4.0.8",
86
- "@sprucelabs/test": "^8.0.22",
87
- "@sprucelabs/test-utils": "^4.0.62",
86
+ "@sprucelabs/test": "^8.0.23",
87
+ "@sprucelabs/test-utils": "^4.0.63",
88
88
  "@types/lodash": "^4.14.200",
89
89
  "@types/nedb": "^1.8.15",
90
90
  "@types/node": "^20.8.9",