@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.cjs
CHANGED
|
@@ -521,7 +521,18 @@ var QueryResults = class extends Array {
|
|
|
521
521
|
* ```
|
|
522
522
|
*/
|
|
523
523
|
constructor(records, nextPage, fetcher) {
|
|
524
|
-
|
|
524
|
+
const items = (() => {
|
|
525
|
+
if (records == null) return [];
|
|
526
|
+
if (Array.isArray(records)) return records;
|
|
527
|
+
if (typeof records[Symbol.iterator] === "function") {
|
|
528
|
+
return Array.from(records);
|
|
529
|
+
}
|
|
530
|
+
if (typeof records.length === "number") {
|
|
531
|
+
return Array.from(records);
|
|
532
|
+
}
|
|
533
|
+
return [records];
|
|
534
|
+
})();
|
|
535
|
+
super(...items);
|
|
525
536
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
526
537
|
this.nextPage = nextPage;
|
|
527
538
|
this.fetcher = fetcher;
|
|
@@ -571,13 +582,36 @@ var QueryResults = class extends Array {
|
|
|
571
582
|
/**
|
|
572
583
|
* Iterates over each record on the current page only.
|
|
573
584
|
* @param action - Function to invoke for each record.
|
|
585
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
574
586
|
* @example
|
|
575
587
|
* ```ts
|
|
576
588
|
* results.forEachOnPage(u => console.log(u.id));
|
|
577
589
|
* ```
|
|
578
590
|
*/
|
|
579
|
-
forEachOnPage(action) {
|
|
580
|
-
|
|
591
|
+
forEachOnPage(action, thisArg) {
|
|
592
|
+
super.forEach((value, index) => {
|
|
593
|
+
action.call(thisArg, value, index, this);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Iterates over every record across all pages sequentially.
|
|
598
|
+
* @param action - Function executed for each record. Returning `false`
|
|
599
|
+
* stops iteration early.
|
|
600
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
601
|
+
* @example
|
|
602
|
+
* ```ts
|
|
603
|
+
* await results.forEach(u => {
|
|
604
|
+
* console.log(u.id);
|
|
605
|
+
* });
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
forEach(action, thisArg) {
|
|
609
|
+
let index = 0;
|
|
610
|
+
return this.forEachAll(async (item) => {
|
|
611
|
+
const result = await action.call(thisArg, item, index, this);
|
|
612
|
+
index += 1;
|
|
613
|
+
return result;
|
|
614
|
+
});
|
|
581
615
|
}
|
|
582
616
|
/**
|
|
583
617
|
* Iterates over every record across all pages sequentially.
|