sliftutils 1.4.45 → 1.4.46

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/index.d.ts CHANGED
@@ -845,6 +845,14 @@ declare module "sliftutils/storage/BulkDatabase2/BulkDatabase2" {
845
845
  value: T[Column];
846
846
  time: number;
847
847
  }[] | undefined;
848
+ /**
849
+ * Reactive: whether (key, column) is loaded yet — true once we know the answer (value, absent, or
850
+ * deleted), false while it's still loading. getSingleFieldObjSync returns undefined for BOTH "loading"
851
+ * and "absent", so use this to tell them apart (e.g. show a spinner only when this is false).
852
+ */
853
+ isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean;
854
+ /** Reactive: whether a whole column is loaded yet (see isFieldLoadedSync). */
855
+ isColumnLoadedSync<Column extends keyof T>(column: Column): boolean;
848
856
  /** The columns present on disk and their byte sizes (no row data read). */
849
857
  getColumnInfo(): Promise<BulkColumnInfo[]>;
850
858
  /** A cheap snapshot of the collection's shape (row/key counts, total bytes, columns) — no row data. */
@@ -1058,6 +1066,8 @@ declare module "sliftutils/storage/BulkDatabase2/BulkDatabaseBase" {
1058
1066
  value: T[Column];
1059
1067
  time: number;
1060
1068
  }[] | undefined;
1069
+ isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean;
1070
+ isColumnLoadedSync<Column extends keyof T>(column: Column): boolean;
1061
1071
  getColumnInfo(): Promise<{
1062
1072
  column: string;
1063
1073
  byteSize: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.4.45",
3
+ "version": "1.4.46",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -80,6 +80,14 @@ export interface IBulkDatabase2<T extends {
80
80
  value: T[Column];
81
81
  time: number;
82
82
  }[] | undefined;
83
+ /**
84
+ * Reactive: whether (key, column) is loaded yet — true once we know the answer (value, absent, or
85
+ * deleted), false while it's still loading. getSingleFieldObjSync returns undefined for BOTH "loading"
86
+ * and "absent", so use this to tell them apart (e.g. show a spinner only when this is false).
87
+ */
88
+ isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean;
89
+ /** Reactive: whether a whole column is loaded yet (see isFieldLoadedSync). */
90
+ isColumnLoadedSync<Column extends keyof T>(column: Column): boolean;
83
91
  /** The columns present on disk and their byte sizes (no row data read). */
84
92
  getColumnInfo(): Promise<BulkColumnInfo[]>;
85
93
  /** A cheap snapshot of the collection's shape (row/key counts, total bytes, columns) — no row data. */
@@ -65,6 +65,15 @@ export interface IBulkDatabase2<T extends { key: string }> {
65
65
  /** Synchronous, reactive read of a whole column ({ key, value, time }). undefined while still loading. */
66
66
  getColumnSync<Column extends keyof T>(column: Column): { key: string; value: T[Column]; time: number }[] | undefined;
67
67
 
68
+ /**
69
+ * Reactive: whether (key, column) is loaded yet — true once we know the answer (value, absent, or
70
+ * deleted), false while it's still loading. getSingleFieldObjSync returns undefined for BOTH "loading"
71
+ * and "absent", so use this to tell them apart (e.g. show a spinner only when this is false).
72
+ */
73
+ isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean;
74
+ /** Reactive: whether a whole column is loaded yet (see isFieldLoadedSync). */
75
+ isColumnLoadedSync<Column extends keyof T>(column: Column): boolean;
76
+
68
77
  /** The columns present on disk and their byte sizes (no row data read). */
69
78
  getColumnInfo(): Promise<BulkColumnInfo[]>;
70
79
  /** A cheap snapshot of the collection's shape (row/key counts, total bytes, columns) — no row data. */
@@ -154,6 +154,8 @@ export declare class BulkDatabaseBase<T extends {
154
154
  value: T[Column];
155
155
  time: number;
156
156
  }[] | undefined;
157
+ isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean;
158
+ isColumnLoadedSync<Column extends keyof T>(column: Column): boolean;
157
159
  getColumnInfo(): Promise<{
158
160
  column: string;
159
161
  byteSize: number;
@@ -1604,6 +1604,38 @@ export class BulkDatabaseBase<T extends { key: string }> {
1604
1604
  return result;
1605
1605
  }
1606
1606
 
1607
+ // Reactive: whether (key, column) is available to read synchronously yet. true once it's loaded — we
1608
+ // know the answer, whether that's a value, absent, or deleted; false while it's still loading from disk.
1609
+ // Pairs with getSingleFieldObjSync, which returns undefined for BOTH "loading" and "absent" — use this
1610
+ // to tell them apart (e.g. show a spinner only when this is false). Triggers the load if not started,
1611
+ // and (like the sync reads) counts the last-known value served during a reload as loaded.
1612
+ public isFieldLoadedSync<Column extends keyof T>(key: string, column: Column): boolean {
1613
+ void this.syncSetup();
1614
+ this.deps.observe(LOAD_SIGNAL);
1615
+ this.deps.observe(key);
1616
+ const entry = this.overlay.get(key);
1617
+ if (entry !== undefined) {
1618
+ if (entry.value === DELETED) return true; // known: deleted
1619
+ if (String(column) in entry.value) return true; // known: overlay holds this column
1620
+ // else: this column falls through to disk — check the base caches below
1621
+ }
1622
+ const cacheKey = nullJoin(String(column), key);
1623
+ if (this.baseFields.has(cacheKey) || this.staleBaseFields.has(cacheKey)) return true;
1624
+ this.ensureBaseField(key, String(column));
1625
+ return false;
1626
+ }
1627
+
1628
+ // Reactive: whether a whole column is available to read synchronously yet (see isFieldLoadedSync).
1629
+ public isColumnLoadedSync<Column extends keyof T>(column: Column): boolean {
1630
+ void this.syncSetup();
1631
+ this.deps.observe(LOAD_SIGNAL);
1632
+ this.deps.observe(OVERLAY_SIGNAL);
1633
+ const col = String(column);
1634
+ if (this.columnCache.has(col) || this.baseColumns.has(col) || this.staleBaseColumns.has(col)) return true;
1635
+ this.ensureBaseColumn(col);
1636
+ return false;
1637
+ }
1638
+
1607
1639
  public async getColumnInfo() {
1608
1640
  let reader = await this.reader();
1609
1641
  return reader.columns;