@koolbase/core 12.38.0 → 12.38.1

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.
@@ -875,6 +875,9 @@ class KoolbaseDatabase {
875
875
  await (0, cache_store_js_1.cacheRecord)(userId, base.collection, recordId, merged, base.revision);
876
876
  // And in the saved lists, so they show what the user just changed.
877
877
  await (0, cache_store_js_2.updateInCachedQueries)(userId, base.collection, recordId, data);
878
+ // What shows it hears of it, as after an online write (R125): a shown
879
+ // record reads its saved copy, which holds the change.
880
+ void (0, query_refresh_js_1.refreshCollectionQueries)(base.collection);
878
881
  // Optimistic: durable locally and queued to send, not yet accepted.
879
882
  return {
880
883
  id: recordId,
@@ -28,6 +28,7 @@ export declare class KoolbaseRecordController {
28
28
  private readonly live;
29
29
  private unlive;
30
30
  private liveTimer;
31
+ private unregister;
31
32
  constructor(db: RecordReader, collection: string, id: string, options?: {
32
33
  live?: boolean;
33
34
  });
@@ -40,6 +41,14 @@ export declare class KoolbaseRecordController {
40
41
  private showSaved;
41
42
  /** The record again, from the server. What is shown stays while it runs, and stays if it fails. */
42
43
  refresh(): Promise<void>;
44
+ /**
45
+ * After the app's own write to this collection (R125): the device's saved
46
+ * copy at once -- which already holds the change, made online or queued
47
+ * offline -- then the server's, SILENTLY (no `refreshing`). A read still in
48
+ * flight is superseded; if the server cannot be reached, the saved copy
49
+ * stays.
50
+ */
51
+ private refreshAfterWrite;
43
52
  /** Stops all updates. A result still in flight is dropped when it lands. */
44
53
  dispose(): void;
45
54
  /**
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.KoolbaseRecordController = exports.initialRecordState = void 0;
24
24
  const database_errors_js_1 = require("./database-errors.js");
25
25
  const live_source_js_1 = require("./live-source.js");
26
+ const query_refresh_js_1 = require("./query-refresh.js");
26
27
  exports.initialRecordState = Object.freeze({
27
28
  status: 'loading',
28
29
  record: null,
@@ -39,6 +40,9 @@ class KoolbaseRecordController {
39
40
  // The realtime subscription, and its pending debounced re-read.
40
41
  this.unlive = null;
41
42
  this.liveTimer = null;
43
+ // Registered for the app's own writes to this collection (R125), as a
44
+ // collection controller is.
45
+ this.unregister = null;
42
46
  this.db = db;
43
47
  this.collection = collection;
44
48
  this.id = id;
@@ -64,6 +68,8 @@ class KoolbaseRecordController {
64
68
  if (this.live && this.id) {
65
69
  this.unlive ?? (this.unlive = (0, live_source_js_1.liveSource)()?.subscribe(this.collection, (event) => this.onLive(event)) ?? null);
66
70
  }
71
+ if (this.id)
72
+ this.unregister ?? (this.unregister = (0, query_refresh_js_1.registerQueryRefresher)(this.collection, () => this.refreshAfterWrite()));
67
73
  await this.showSaved();
68
74
  await this.fetch();
69
75
  }
@@ -94,9 +100,37 @@ class KoolbaseRecordController {
94
100
  if (!this.isStale(gen))
95
101
  this.set({ refreshing: false });
96
102
  }
103
+ /**
104
+ * After the app's own write to this collection (R125): the device's saved
105
+ * copy at once -- which already holds the change, made online or queued
106
+ * offline -- then the server's, SILENTLY (no `refreshing`). A read still in
107
+ * flight is superseded; if the server cannot be reached, the saved copy
108
+ * stays.
109
+ */
110
+ async refreshAfterWrite() {
111
+ if (this.disposed || !this.id)
112
+ return;
113
+ const gen = ++this.generation;
114
+ if (this.db.getSaved) {
115
+ try {
116
+ const saved = await this.db.getSaved(this.id);
117
+ if (saved && !this.isStale(gen) && (saved.collection === undefined || saved.collection === this.collection)) {
118
+ this.set({ status: 'loaded', record: saved, error: null, isSaved: true });
119
+ }
120
+ }
121
+ catch {
122
+ // No saved copy to show: the server's answer decides.
123
+ }
124
+ }
125
+ if (this.isStale(gen))
126
+ return;
127
+ await this.fetch();
128
+ }
97
129
  /** Stops all updates. A result still in flight is dropped when it lands. */
98
130
  dispose() {
99
131
  this.disposed = true;
132
+ this.unregister?.();
133
+ this.unregister = null;
100
134
  this.unlive?.();
101
135
  this.unlive = null;
102
136
  if (this.liveTimer) {
@@ -872,6 +872,9 @@ export class KoolbaseDatabase {
872
872
  await cacheRecord(userId, base.collection, recordId, merged, base.revision);
873
873
  // And in the saved lists, so they show what the user just changed.
874
874
  await updateInCachedQueries(userId, base.collection, recordId, data);
875
+ // What shows it hears of it, as after an online write (R125): a shown
876
+ // record reads its saved copy, which holds the change.
877
+ void refreshCollectionQueries(base.collection);
875
878
  // Optimistic: durable locally and queued to send, not yet accepted.
876
879
  return {
877
880
  id: recordId,
@@ -28,6 +28,7 @@ export declare class KoolbaseRecordController {
28
28
  private readonly live;
29
29
  private unlive;
30
30
  private liveTimer;
31
+ private unregister;
31
32
  constructor(db: RecordReader, collection: string, id: string, options?: {
32
33
  live?: boolean;
33
34
  });
@@ -40,6 +41,14 @@ export declare class KoolbaseRecordController {
40
41
  private showSaved;
41
42
  /** The record again, from the server. What is shown stays while it runs, and stays if it fails. */
42
43
  refresh(): Promise<void>;
44
+ /**
45
+ * After the app's own write to this collection (R125): the device's saved
46
+ * copy at once -- which already holds the change, made online or queued
47
+ * offline -- then the server's, SILENTLY (no `refreshing`). A read still in
48
+ * flight is superseded; if the server cannot be reached, the saved copy
49
+ * stays.
50
+ */
51
+ private refreshAfterWrite;
43
52
  /** Stops all updates. A result still in flight is dropped when it lands. */
44
53
  dispose(): void;
45
54
  /**
@@ -20,6 +20,7 @@
20
20
  // found is notFound. No saved copy: the ordinary loading/error states.
21
21
  import { KoolbaseNotFoundError } from './database-errors.js';
22
22
  import { liveSource } from './live-source.js';
23
+ import { registerQueryRefresher } from './query-refresh.js';
23
24
  export const initialRecordState = Object.freeze({
24
25
  status: 'loading',
25
26
  record: null,
@@ -36,6 +37,9 @@ export class KoolbaseRecordController {
36
37
  // The realtime subscription, and its pending debounced re-read.
37
38
  this.unlive = null;
38
39
  this.liveTimer = null;
40
+ // Registered for the app's own writes to this collection (R125), as a
41
+ // collection controller is.
42
+ this.unregister = null;
39
43
  this.db = db;
40
44
  this.collection = collection;
41
45
  this.id = id;
@@ -61,6 +65,8 @@ export class KoolbaseRecordController {
61
65
  if (this.live && this.id) {
62
66
  this.unlive ?? (this.unlive = liveSource()?.subscribe(this.collection, (event) => this.onLive(event)) ?? null);
63
67
  }
68
+ if (this.id)
69
+ this.unregister ?? (this.unregister = registerQueryRefresher(this.collection, () => this.refreshAfterWrite()));
64
70
  await this.showSaved();
65
71
  await this.fetch();
66
72
  }
@@ -91,9 +97,37 @@ export class KoolbaseRecordController {
91
97
  if (!this.isStale(gen))
92
98
  this.set({ refreshing: false });
93
99
  }
100
+ /**
101
+ * After the app's own write to this collection (R125): the device's saved
102
+ * copy at once -- which already holds the change, made online or queued
103
+ * offline -- then the server's, SILENTLY (no `refreshing`). A read still in
104
+ * flight is superseded; if the server cannot be reached, the saved copy
105
+ * stays.
106
+ */
107
+ async refreshAfterWrite() {
108
+ if (this.disposed || !this.id)
109
+ return;
110
+ const gen = ++this.generation;
111
+ if (this.db.getSaved) {
112
+ try {
113
+ const saved = await this.db.getSaved(this.id);
114
+ if (saved && !this.isStale(gen) && (saved.collection === undefined || saved.collection === this.collection)) {
115
+ this.set({ status: 'loaded', record: saved, error: null, isSaved: true });
116
+ }
117
+ }
118
+ catch {
119
+ // No saved copy to show: the server's answer decides.
120
+ }
121
+ }
122
+ if (this.isStale(gen))
123
+ return;
124
+ await this.fetch();
125
+ }
94
126
  /** Stops all updates. A result still in flight is dropped when it lands. */
95
127
  dispose() {
96
128
  this.disposed = true;
129
+ this.unregister?.();
130
+ this.unregister = null;
97
131
  this.unlive?.();
98
132
  this.unlive = null;
99
133
  if (this.liveTimer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.38.0",
3
+ "version": "12.38.1",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",