nexabase-console 2.0.9 → 2.1.0

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.
@@ -57,6 +57,8 @@ export declare class NexaApp {
57
57
  action: 'set' | 'patch' | 'delete';
58
58
  serverDocument?: any;
59
59
  updateTime?: string;
60
+ mutationData?: any;
61
+ merge?: boolean;
60
62
  }): Promise<{
61
63
  data: any | null;
62
64
  hasPendingWrites: boolean;
@@ -166,14 +166,31 @@ class NexaApp {
166
166
  const db = this.indexedDB.getRawDB();
167
167
  const queue = this.mutationQueue.inMemoryQueue;
168
168
  const jobIndex = queue.findIndex((j) => j.id === mutationId);
169
- if (jobIndex !== -1)
169
+ let jobData = null;
170
+ if (jobIndex !== -1) {
171
+ jobData = queue[jobIndex];
170
172
  queue.splice(jobIndex, 1);
173
+ }
171
174
  if (options.action === 'delete') {
172
175
  this.localStore.getServerBaseCache()[path] = null;
173
176
  }
174
177
  else if (serverDocument && serverDocument.fields) {
175
178
  this.localStore.getServerBaseCache()[path] = (0, QueryUtils_1.reviveNexaData)(serverDocument.fields);
176
179
  }
180
+ else {
181
+ // PROMOTION: If server returned success: true without serverDocument.fields (lightweight ACK),
182
+ // promote the local mutation payload to Server Base Cache so the document does not revert to null!
183
+ const rawData = (jobData ? jobData.data : options.mutationData) || {};
184
+ const isMerge = jobData ? jobData.merge : options.merge;
185
+ let currentBase = this.localStore.getServerBaseCache()[path];
186
+ currentBase = currentBase !== undefined && currentBase !== null ? (0, QueryUtils_1.cloneNexaData)(currentBase) : currentBase;
187
+ if (options.action === 'set' && !isMerge) {
188
+ this.localStore.getServerBaseCache()[path] = (0, QueryUtils_1.reviveNexaData)((0, helpers_1.applyDataTransforms)({}, rawData));
189
+ }
190
+ else {
191
+ this.localStore.getServerBaseCache()[path] = (0, QueryUtils_1.reviveNexaData)((0, helpers_1.applyDataTransforms)(currentBase || {}, rawData));
192
+ }
193
+ }
177
194
  const view = this._calculateLocalView(path);
178
195
  const rebasedData = view.data;
179
196
  if (rebasedData === null) {
@@ -173,7 +173,9 @@ const executeWriteMutation = async (docRef, action, data, options) => {
173
173
  path: docRef.path,
174
174
  action,
175
175
  serverDocument: res.document,
176
- updateTime: res.document?.updateTime
176
+ updateTime: res.document?.updateTime,
177
+ mutationData: data,
178
+ merge: options?.merge
177
179
  });
178
180
  }
179
181
  catch (ackError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexabase-console",
3
- "version": "2.0.9",
3
+ "version": "2.1.0",
4
4
  "description": "SDK Client resmi untuk NexaBase: Platform Sinkronisasi NoSQL, Realtime, File Storage, & Autentikasi Offline-First.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",