@sprucelabs/data-stores 25.5.0 → 25.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/cursors/BatchArrayCursor.d.ts +14 -0
- package/build/cursors/BatchArrayCursor.js +28 -0
- package/build/cursors/BatchCursor.d.ts +2 -1
- package/build/esm/cursors/BatchArrayCursor.d.ts +14 -0
- package/build/esm/cursors/BatchArrayCursor.js +38 -0
- package/build/esm/cursors/BatchCursor.d.ts +2 -1
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.js +2 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BatchCursor, OnNextResultsHandler } from './BatchCursor';
|
|
2
|
+
export default class BatchArrayCursor<T> implements BatchCursor<T> {
|
|
3
|
+
private items;
|
|
4
|
+
private options?;
|
|
5
|
+
private currenIndex;
|
|
6
|
+
private onNextResultsHandler?;
|
|
7
|
+
constructor(items: T[], options?: BatchArrayCursorOptions);
|
|
8
|
+
getTotalRecords(): Promise<number>;
|
|
9
|
+
setOnNextResults(cb: OnNextResultsHandler<T>): void;
|
|
10
|
+
next(): Promise<T[] | null>;
|
|
11
|
+
}
|
|
12
|
+
export type BatchArrayCursorOptions = {
|
|
13
|
+
batchSize?: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
class BatchArrayCursor {
|
|
5
|
+
constructor(items, options) {
|
|
6
|
+
this.currenIndex = 0;
|
|
7
|
+
(0, schema_1.assertOptions)({ items }, ['items']);
|
|
8
|
+
this.items = items;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
async getTotalRecords() {
|
|
12
|
+
return this.items.length;
|
|
13
|
+
}
|
|
14
|
+
setOnNextResults(cb) {
|
|
15
|
+
this.onNextResultsHandler = cb;
|
|
16
|
+
}
|
|
17
|
+
async next() {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const { batchSize = 10 } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
20
|
+
const i = this.items.slice(this.currenIndex, this.currenIndex + batchSize);
|
|
21
|
+
this.currenIndex += batchSize;
|
|
22
|
+
if (this.onNextResultsHandler) {
|
|
23
|
+
return (_b = this.onNextResultsHandler) === null || _b === void 0 ? void 0 : _b.call(this, i);
|
|
24
|
+
}
|
|
25
|
+
return i.length ? i : null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = BatchArrayCursor;
|
|
@@ -17,8 +17,9 @@ export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<Resp
|
|
|
17
17
|
export interface FindBatchOptions<IncludePrivateFields extends boolean = true, FullSchema extends Schema = Schema, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>> extends Omit<QueryOptions, 'includeFields'>, PrepareOptions<IncludePrivateFields, FullSchema, F> {
|
|
18
18
|
batchSize?: number;
|
|
19
19
|
}
|
|
20
|
+
export type OnNextResultsHandler<ResponseRecord> = (results: ResponseRecord[]) => Record<string, any>[] | Promise<Record<string, any>[]>;
|
|
20
21
|
export interface BatchCursor<ResponseRecord> {
|
|
21
22
|
getTotalRecords(): Promise<number>;
|
|
22
|
-
setOnNextResults(cb:
|
|
23
|
+
setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
|
|
23
24
|
next(): Promise<ResponseRecord[] | null>;
|
|
24
25
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BatchCursor, OnNextResultsHandler } from './BatchCursor';
|
|
2
|
+
export default class BatchArrayCursor<T> implements BatchCursor<T> {
|
|
3
|
+
private items;
|
|
4
|
+
private options?;
|
|
5
|
+
private currenIndex;
|
|
6
|
+
private onNextResultsHandler?;
|
|
7
|
+
constructor(items: T[], options?: BatchArrayCursorOptions);
|
|
8
|
+
getTotalRecords(): Promise<number>;
|
|
9
|
+
setOnNextResults(cb: OnNextResultsHandler<T>): void;
|
|
10
|
+
next(): Promise<T[] | null>;
|
|
11
|
+
}
|
|
12
|
+
export type BatchArrayCursorOptions = {
|
|
13
|
+
batchSize?: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
11
|
+
export default class BatchArrayCursor {
|
|
12
|
+
constructor(items, options) {
|
|
13
|
+
this.currenIndex = 0;
|
|
14
|
+
assertOptions({ items }, ['items']);
|
|
15
|
+
this.items = items;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
getTotalRecords() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return this.items.length;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
setOnNextResults(cb) {
|
|
24
|
+
this.onNextResultsHandler = cb;
|
|
25
|
+
}
|
|
26
|
+
next() {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const { batchSize = 10 } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
30
|
+
const i = this.items.slice(this.currenIndex, this.currenIndex + batchSize);
|
|
31
|
+
this.currenIndex += batchSize;
|
|
32
|
+
if (this.onNextResultsHandler) {
|
|
33
|
+
return (_b = this.onNextResultsHandler) === null || _b === void 0 ? void 0 : _b.call(this, i);
|
|
34
|
+
}
|
|
35
|
+
return i.length ? i : null;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -17,8 +17,9 @@ export default class BatchCursorImpl<ResponseRecord> implements BatchCursor<Resp
|
|
|
17
17
|
export interface FindBatchOptions<IncludePrivateFields extends boolean = true, FullSchema extends Schema = Schema, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>> extends Omit<QueryOptions, 'includeFields'>, PrepareOptions<IncludePrivateFields, FullSchema, F> {
|
|
18
18
|
batchSize?: number;
|
|
19
19
|
}
|
|
20
|
+
export type OnNextResultsHandler<ResponseRecord> = (results: ResponseRecord[]) => Record<string, any>[] | Promise<Record<string, any>[]>;
|
|
20
21
|
export interface BatchCursor<ResponseRecord> {
|
|
21
22
|
getTotalRecords(): Promise<number>;
|
|
22
|
-
setOnNextResults(cb:
|
|
23
|
+
setOnNextResults(cb: OnNextResultsHandler<ResponseRecord>): void;
|
|
23
24
|
next(): Promise<ResponseRecord[] | null>;
|
|
24
25
|
}
|
package/build/esm/index.d.ts
CHANGED
|
@@ -27,3 +27,5 @@ export { default as databaseAssertUtil } from './tests/databaseAssertUtil';
|
|
|
27
27
|
export { default as databaseAssert } from './tests/databaseAssertUtil';
|
|
28
28
|
export { default as BatchCursorImpl } from './cursors/BatchCursor';
|
|
29
29
|
export * from './cursors/BatchCursor';
|
|
30
|
+
export { default as BatchArrayCursor } from './cursors/BatchArrayCursor';
|
|
31
|
+
export * from './cursors/BatchArrayCursor';
|
package/build/esm/index.js
CHANGED
|
@@ -27,3 +27,5 @@ export { default as databaseAssertUtil } from './tests/databaseAssertUtil.js';
|
|
|
27
27
|
export { default as databaseAssert } from './tests/databaseAssertUtil.js';
|
|
28
28
|
export { default as BatchCursorImpl } from './cursors/BatchCursor.js';
|
|
29
29
|
export * from './cursors/BatchCursor.js';
|
|
30
|
+
export { default as BatchArrayCursor } from './cursors/BatchArrayCursor.js';
|
|
31
|
+
export * from './cursors/BatchArrayCursor.js';
|
package/build/index.d.ts
CHANGED
|
@@ -27,3 +27,5 @@ export { default as databaseAssertUtil } from './tests/databaseAssertUtil';
|
|
|
27
27
|
export { default as databaseAssert } from './tests/databaseAssertUtil';
|
|
28
28
|
export { default as BatchCursorImpl } from './cursors/BatchCursor';
|
|
29
29
|
export * from './cursors/BatchCursor';
|
|
30
|
+
export { default as BatchArrayCursor } from './cursors/BatchArrayCursor';
|
|
31
|
+
export * from './cursors/BatchArrayCursor';
|
package/build/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.BatchCursorImpl = exports.databaseAssert = exports.databaseAssertUtil = exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.DataStoresError = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
|
|
20
|
+
exports.BatchArrayCursor = exports.BatchCursorImpl = exports.databaseAssert = exports.databaseAssertUtil = exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.DataStoresError = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
|
|
21
21
|
var AbstractDatabaseTest_1 = require("./tests/AbstractDatabaseTest");
|
|
22
22
|
Object.defineProperty(exports, "AbstractDatabaseTest", { enumerable: true, get: function () { return __importDefault(AbstractDatabaseTest_1).default; } });
|
|
23
23
|
var DatabaseFixture_1 = require("./fixtures/DatabaseFixture");
|
|
@@ -63,3 +63,6 @@ Object.defineProperty(exports, "databaseAssert", { enumerable: true, get: functi
|
|
|
63
63
|
var BatchCursor_1 = require("./cursors/BatchCursor");
|
|
64
64
|
Object.defineProperty(exports, "BatchCursorImpl", { enumerable: true, get: function () { return __importDefault(BatchCursor_1).default; } });
|
|
65
65
|
__exportStar(require("./cursors/BatchCursor"), exports);
|
|
66
|
+
var BatchArrayCursor_1 = require("./cursors/BatchArrayCursor");
|
|
67
|
+
Object.defineProperty(exports, "BatchArrayCursor", { enumerable: true, get: function () { return __importDefault(BatchArrayCursor_1).default; } });
|
|
68
|
+
__exportStar(require("./cursors/BatchArrayCursor"), exports);
|