@onyx.dev/onyx-database 0.1.5 → 0.1.7
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/dist/index.cjs +37 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -202,7 +202,7 @@ declare class QueryResults<T> extends Array<T> {
|
|
|
202
202
|
* const results = new QueryResults(users, token, t => fetchMore(t));
|
|
203
203
|
* ```
|
|
204
204
|
*/
|
|
205
|
-
constructor(records: T
|
|
205
|
+
constructor(records: Iterable<T> | ArrayLike<T> | T | null | undefined, nextPage: string | null, fetcher?: (token: string) => Promise<QueryResults<T>>);
|
|
206
206
|
/**
|
|
207
207
|
* Returns the first record in the result set.
|
|
208
208
|
* @throws Error if the result set is empty.
|
|
@@ -239,12 +239,26 @@ declare class QueryResults<T> extends Array<T> {
|
|
|
239
239
|
/**
|
|
240
240
|
* Iterates over each record on the current page only.
|
|
241
241
|
* @param action - Function to invoke for each record.
|
|
242
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
242
243
|
* @example
|
|
243
244
|
* ```ts
|
|
244
245
|
* results.forEachOnPage(u => console.log(u.id));
|
|
245
246
|
* ```
|
|
246
247
|
*/
|
|
247
|
-
forEachOnPage(action: (item: T) => void): void;
|
|
248
|
+
forEachOnPage(action: (item: T, index: number, array: QueryResults<T>) => void, thisArg?: unknown): void;
|
|
249
|
+
/**
|
|
250
|
+
* Iterates over every record across all pages sequentially.
|
|
251
|
+
* @param action - Function executed for each record. Returning `false`
|
|
252
|
+
* stops iteration early.
|
|
253
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* await results.forEach(u => {
|
|
257
|
+
* console.log(u.id);
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
forEach(action: (item: T, index: number, array: T[]) => void, thisArg?: unknown): Promise<void>;
|
|
248
262
|
/**
|
|
249
263
|
* Iterates over every record across all pages sequentially.
|
|
250
264
|
* @param action - Function executed for each record. Returning `false`
|
package/dist/index.d.ts
CHANGED
|
@@ -202,7 +202,7 @@ declare class QueryResults<T> extends Array<T> {
|
|
|
202
202
|
* const results = new QueryResults(users, token, t => fetchMore(t));
|
|
203
203
|
* ```
|
|
204
204
|
*/
|
|
205
|
-
constructor(records: T
|
|
205
|
+
constructor(records: Iterable<T> | ArrayLike<T> | T | null | undefined, nextPage: string | null, fetcher?: (token: string) => Promise<QueryResults<T>>);
|
|
206
206
|
/**
|
|
207
207
|
* Returns the first record in the result set.
|
|
208
208
|
* @throws Error if the result set is empty.
|
|
@@ -239,12 +239,26 @@ declare class QueryResults<T> extends Array<T> {
|
|
|
239
239
|
/**
|
|
240
240
|
* Iterates over each record on the current page only.
|
|
241
241
|
* @param action - Function to invoke for each record.
|
|
242
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
242
243
|
* @example
|
|
243
244
|
* ```ts
|
|
244
245
|
* results.forEachOnPage(u => console.log(u.id));
|
|
245
246
|
* ```
|
|
246
247
|
*/
|
|
247
|
-
forEachOnPage(action: (item: T) => void): void;
|
|
248
|
+
forEachOnPage(action: (item: T, index: number, array: QueryResults<T>) => void, thisArg?: unknown): void;
|
|
249
|
+
/**
|
|
250
|
+
* Iterates over every record across all pages sequentially.
|
|
251
|
+
* @param action - Function executed for each record. Returning `false`
|
|
252
|
+
* stops iteration early.
|
|
253
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* await results.forEach(u => {
|
|
257
|
+
* console.log(u.id);
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
forEach(action: (item: T, index: number, array: T[]) => void, thisArg?: unknown): Promise<void>;
|
|
248
262
|
/**
|
|
249
263
|
* Iterates over every record across all pages sequentially.
|
|
250
264
|
* @param action - Function executed for each record. Returning `false`
|
package/dist/index.js
CHANGED
|
@@ -519,7 +519,18 @@ var QueryResults = class extends Array {
|
|
|
519
519
|
* ```
|
|
520
520
|
*/
|
|
521
521
|
constructor(records, nextPage, fetcher) {
|
|
522
|
-
|
|
522
|
+
const items = (() => {
|
|
523
|
+
if (records == null) return [];
|
|
524
|
+
if (Array.isArray(records)) return records;
|
|
525
|
+
if (typeof records[Symbol.iterator] === "function") {
|
|
526
|
+
return Array.from(records);
|
|
527
|
+
}
|
|
528
|
+
if (typeof records.length === "number") {
|
|
529
|
+
return Array.from(records);
|
|
530
|
+
}
|
|
531
|
+
return [records];
|
|
532
|
+
})();
|
|
533
|
+
super(...items);
|
|
523
534
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
524
535
|
this.nextPage = nextPage;
|
|
525
536
|
this.fetcher = fetcher;
|
|
@@ -569,13 +580,36 @@ var QueryResults = class extends Array {
|
|
|
569
580
|
/**
|
|
570
581
|
* Iterates over each record on the current page only.
|
|
571
582
|
* @param action - Function to invoke for each record.
|
|
583
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
572
584
|
* @example
|
|
573
585
|
* ```ts
|
|
574
586
|
* results.forEachOnPage(u => console.log(u.id));
|
|
575
587
|
* ```
|
|
576
588
|
*/
|
|
577
|
-
forEachOnPage(action) {
|
|
578
|
-
|
|
589
|
+
forEachOnPage(action, thisArg) {
|
|
590
|
+
super.forEach((value, index) => {
|
|
591
|
+
action.call(thisArg, value, index, this);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Iterates over every record across all pages sequentially.
|
|
596
|
+
* @param action - Function executed for each record. Returning `false`
|
|
597
|
+
* stops iteration early.
|
|
598
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
599
|
+
* @example
|
|
600
|
+
* ```ts
|
|
601
|
+
* await results.forEach(u => {
|
|
602
|
+
* console.log(u.id);
|
|
603
|
+
* });
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
forEach(action, thisArg) {
|
|
607
|
+
let index = 0;
|
|
608
|
+
return this.forEachAll(async (item) => {
|
|
609
|
+
const result = await action.call(thisArg, item, index, this);
|
|
610
|
+
index += 1;
|
|
611
|
+
return result;
|
|
612
|
+
});
|
|
579
613
|
}
|
|
580
614
|
/**
|
|
581
615
|
* Iterates over every record across all pages sequentially.
|