@onyx.dev/onyx-database 0.1.6 → 0.1.9

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.d.cts CHANGED
@@ -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`
@@ -444,10 +458,10 @@ interface IQueryBuilder<T = unknown> {
444
458
  * Selects a subset of fields to return.
445
459
  * @example
446
460
  * ```ts
447
- * const emails = await db.from('User').selectFields('email').list();
461
+ * const emails = await db.from('User').select('email').list();
448
462
  * ```
449
463
  */
450
- selectFields(...fields: Array<string | string[]>): IQueryBuilder<T>;
464
+ select(...fields: Array<string | string[]>): IQueryBuilder<T>;
451
465
  /**
452
466
  * Resolves related values by name.
453
467
  * @example
@@ -503,7 +517,7 @@ interface IQueryBuilder<T = unknown> {
503
517
  * Ensures only distinct records are returned.
504
518
  * @example
505
519
  * ```ts
506
- * const roles = await db.from('User').selectFields('role').distinct().list();
520
+ * const roles = await db.from('User').select('role').distinct().list();
507
521
  * ```
508
522
  */
509
523
  distinct(): IQueryBuilder<T>;
package/dist/index.d.ts CHANGED
@@ -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`
@@ -444,10 +458,10 @@ interface IQueryBuilder<T = unknown> {
444
458
  * Selects a subset of fields to return.
445
459
  * @example
446
460
  * ```ts
447
- * const emails = await db.from('User').selectFields('email').list();
461
+ * const emails = await db.from('User').select('email').list();
448
462
  * ```
449
463
  */
450
- selectFields(...fields: Array<string | string[]>): IQueryBuilder<T>;
464
+ select(...fields: Array<string | string[]>): IQueryBuilder<T>;
451
465
  /**
452
466
  * Resolves related values by name.
453
467
  * @example
@@ -503,7 +517,7 @@ interface IQueryBuilder<T = unknown> {
503
517
  * Ensures only distinct records are returned.
504
518
  * @example
505
519
  * ```ts
506
- * const roles = await db.from('User').selectFields('role').distinct().list();
520
+ * const roles = await db.from('User').select('role').distinct().list();
507
521
  * ```
508
522
  */
509
523
  distinct(): IQueryBuilder<T>;
package/dist/index.js CHANGED
@@ -580,13 +580,36 @@ var QueryResults = class extends Array {
580
580
  /**
581
581
  * Iterates over each record on the current page only.
582
582
  * @param action - Function to invoke for each record.
583
+ * @param thisArg - Optional `this` binding for the callback.
583
584
  * @example
584
585
  * ```ts
585
586
  * results.forEachOnPage(u => console.log(u.id));
586
587
  * ```
587
588
  */
588
- forEachOnPage(action) {
589
- this.forEach(action);
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
+ });
590
613
  }
591
614
  /**
592
615
  * Iterates over every record across all pages sequentially.
@@ -980,7 +1003,7 @@ var OnyxDatabaseImpl = class {
980
1003
  null,
981
1004
  this.defaultPartition
982
1005
  );
983
- qb.selectFields(...fields);
1006
+ qb.select(...fields);
984
1007
  return qb;
985
1008
  }
986
1009
  cascade(...relationships) {
@@ -1187,7 +1210,7 @@ var QueryBuilderImpl = class {
1187
1210
  this.table = table;
1188
1211
  return this;
1189
1212
  }
1190
- selectFields(...fields) {
1213
+ select(...fields) {
1191
1214
  const flat = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
1192
1215
  this.fields = flat.length > 0 ? flat : null;
1193
1216
  return this;