@koolbase/core 12.38.0 → 12.38.2
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/cjs/database.d.ts +7 -0
- package/dist/cjs/database.js +20 -0
- package/dist/cjs/record-controller.d.ts +9 -0
- package/dist/cjs/record-controller.js +34 -0
- package/dist/esm/database.d.ts +7 -0
- package/dist/esm/database.js +20 -0
- package/dist/esm/record-controller.d.ts +9 -0
- package/dist/esm/record-controller.js +34 -0
- package/package.json +1 -1
package/dist/cjs/database.d.ts
CHANGED
|
@@ -215,6 +215,13 @@ export declare class KoolbaseDatabase {
|
|
|
215
215
|
* rebase onto: the conflict is removed and the held writes stay as they are.
|
|
216
216
|
*/
|
|
217
217
|
private settleConflict;
|
|
218
|
+
/**
|
|
219
|
+
* The server's version stands (keep theirs, abandon): the device's saved
|
|
220
|
+
* copy takes it -- it still held the refused change -- and what shows the
|
|
221
|
+
* collection hears of it (R125), so the screen stops showing what was
|
|
222
|
+
* discarded, offline too.
|
|
223
|
+
*/
|
|
224
|
+
private showServerVersion;
|
|
218
225
|
private dropConflict;
|
|
219
226
|
/**
|
|
220
227
|
* Issues the resolving write, conditional on the revision the refusal
|
package/dist/cjs/database.js
CHANGED
|
@@ -72,12 +72,14 @@ class KoolbaseDatabase {
|
|
|
72
72
|
// conflict, rather than the change quietly disappearing -- and what
|
|
73
73
|
// stands is what the writes held behind it now build on.
|
|
74
74
|
await this.settleConflict(c, c.server, c.serverRevision);
|
|
75
|
+
await this.showServerVersion(c);
|
|
75
76
|
},
|
|
76
77
|
abandon: async (id) => {
|
|
77
78
|
const c = await this.requireConflict(id);
|
|
78
79
|
// Neither version claimed to win, so the record stands as the server
|
|
79
80
|
// has it: what anything still queued must build on.
|
|
80
81
|
await this.settleConflict(c, c.server, c.serverRevision);
|
|
82
|
+
await this.showServerVersion(c);
|
|
81
83
|
},
|
|
82
84
|
};
|
|
83
85
|
this.config = config;
|
|
@@ -695,6 +697,21 @@ class KoolbaseDatabase {
|
|
|
695
697
|
(0, offline_state_js_1.rebaseHeldWrites)(s, c.recordId, resolved, revision);
|
|
696
698
|
});
|
|
697
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* The server's version stands (keep theirs, abandon): the device's saved
|
|
702
|
+
* copy takes it -- it still held the refused change -- and what shows the
|
|
703
|
+
* collection hears of it (R125), so the screen stops showing what was
|
|
704
|
+
* discarded, offline too.
|
|
705
|
+
*/
|
|
706
|
+
async showServerVersion(c) {
|
|
707
|
+
const userId = this.getUserId();
|
|
708
|
+
if (userId && c.recordId && c.server) {
|
|
709
|
+
const fields = Object.fromEntries(Object.entries(c.server).filter(([k]) => !k.startsWith('$')));
|
|
710
|
+
await (0, cache_store_js_1.cacheRecord)(userId, c.collection, c.recordId, fields, c.serverRevision);
|
|
711
|
+
await (0, cache_store_js_2.updateInCachedQueries)(userId, c.collection, c.recordId, fields);
|
|
712
|
+
}
|
|
713
|
+
void (0, query_refresh_js_1.refreshCollectionQueries)(c.collection);
|
|
714
|
+
}
|
|
698
715
|
async dropConflict(id) {
|
|
699
716
|
const userId = this.requireUserId('conflict resolution');
|
|
700
717
|
await (0, offline_state_js_1.mutateOfflineState)(userId, (s) => {
|
|
@@ -875,6 +892,9 @@ class KoolbaseDatabase {
|
|
|
875
892
|
await (0, cache_store_js_1.cacheRecord)(userId, base.collection, recordId, merged, base.revision);
|
|
876
893
|
// And in the saved lists, so they show what the user just changed.
|
|
877
894
|
await (0, cache_store_js_2.updateInCachedQueries)(userId, base.collection, recordId, data);
|
|
895
|
+
// What shows it hears of it, as after an online write (R125): a shown
|
|
896
|
+
// record reads its saved copy, which holds the change.
|
|
897
|
+
void (0, query_refresh_js_1.refreshCollectionQueries)(base.collection);
|
|
878
898
|
// Optimistic: durable locally and queued to send, not yet accepted.
|
|
879
899
|
return {
|
|
880
900
|
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) {
|
package/dist/esm/database.d.ts
CHANGED
|
@@ -215,6 +215,13 @@ export declare class KoolbaseDatabase {
|
|
|
215
215
|
* rebase onto: the conflict is removed and the held writes stay as they are.
|
|
216
216
|
*/
|
|
217
217
|
private settleConflict;
|
|
218
|
+
/**
|
|
219
|
+
* The server's version stands (keep theirs, abandon): the device's saved
|
|
220
|
+
* copy takes it -- it still held the refused change -- and what shows the
|
|
221
|
+
* collection hears of it (R125), so the screen stops showing what was
|
|
222
|
+
* discarded, offline too.
|
|
223
|
+
*/
|
|
224
|
+
private showServerVersion;
|
|
218
225
|
private dropConflict;
|
|
219
226
|
/**
|
|
220
227
|
* Issues the resolving write, conditional on the revision the refusal
|
package/dist/esm/database.js
CHANGED
|
@@ -69,12 +69,14 @@ export class KoolbaseDatabase {
|
|
|
69
69
|
// conflict, rather than the change quietly disappearing -- and what
|
|
70
70
|
// stands is what the writes held behind it now build on.
|
|
71
71
|
await this.settleConflict(c, c.server, c.serverRevision);
|
|
72
|
+
await this.showServerVersion(c);
|
|
72
73
|
},
|
|
73
74
|
abandon: async (id) => {
|
|
74
75
|
const c = await this.requireConflict(id);
|
|
75
76
|
// Neither version claimed to win, so the record stands as the server
|
|
76
77
|
// has it: what anything still queued must build on.
|
|
77
78
|
await this.settleConflict(c, c.server, c.serverRevision);
|
|
79
|
+
await this.showServerVersion(c);
|
|
78
80
|
},
|
|
79
81
|
};
|
|
80
82
|
this.config = config;
|
|
@@ -692,6 +694,21 @@ export class KoolbaseDatabase {
|
|
|
692
694
|
rebaseHeldWrites(s, c.recordId, resolved, revision);
|
|
693
695
|
});
|
|
694
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* The server's version stands (keep theirs, abandon): the device's saved
|
|
699
|
+
* copy takes it -- it still held the refused change -- and what shows the
|
|
700
|
+
* collection hears of it (R125), so the screen stops showing what was
|
|
701
|
+
* discarded, offline too.
|
|
702
|
+
*/
|
|
703
|
+
async showServerVersion(c) {
|
|
704
|
+
const userId = this.getUserId();
|
|
705
|
+
if (userId && c.recordId && c.server) {
|
|
706
|
+
const fields = Object.fromEntries(Object.entries(c.server).filter(([k]) => !k.startsWith('$')));
|
|
707
|
+
await cacheRecord(userId, c.collection, c.recordId, fields, c.serverRevision);
|
|
708
|
+
await updateInCachedQueries(userId, c.collection, c.recordId, fields);
|
|
709
|
+
}
|
|
710
|
+
void refreshCollectionQueries(c.collection);
|
|
711
|
+
}
|
|
695
712
|
async dropConflict(id) {
|
|
696
713
|
const userId = this.requireUserId('conflict resolution');
|
|
697
714
|
await mutateOfflineState(userId, (s) => {
|
|
@@ -872,6 +889,9 @@ export class KoolbaseDatabase {
|
|
|
872
889
|
await cacheRecord(userId, base.collection, recordId, merged, base.revision);
|
|
873
890
|
// And in the saved lists, so they show what the user just changed.
|
|
874
891
|
await updateInCachedQueries(userId, base.collection, recordId, data);
|
|
892
|
+
// What shows it hears of it, as after an online write (R125): a shown
|
|
893
|
+
// record reads its saved copy, which holds the change.
|
|
894
|
+
void refreshCollectionQueries(base.collection);
|
|
875
895
|
// Optimistic: durable locally and queued to send, not yet accepted.
|
|
876
896
|
return {
|
|
877
897
|
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.
|
|
3
|
+
"version": "12.38.2",
|
|
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",
|