@anfenn/dync 1.0.1 → 1.0.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/{chunk-LGHOZECP.js → chunk-66PSQW4D.js} +120 -120
- package/dist/chunk-66PSQW4D.js.map +1 -0
- package/dist/index.cjs +119 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.shared-YSn6c01d.d.cts → index.shared-BGwvMH8f.d.cts} +3 -3
- package/dist/{index.shared-CPIge2ZM.d.ts → index.shared-CkYsQYyn.d.ts} +3 -3
- package/dist/react/index.cjs +119 -119
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -4
- package/src/core/StateManager.ts +15 -15
- package/src/core/firstLoad.ts +27 -27
- package/src/core/pullOperations.ts +28 -28
- package/src/core/pushOperations.ts +41 -41
- package/src/core/tableEnhancers.ts +9 -9
- package/src/index.shared.ts +3 -3
- package/src/types.ts +3 -3
- package/dist/chunk-LGHOZECP.js.map +0 -1
|
@@ -140,7 +140,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
140
140
|
|
|
141
141
|
await state.addPendingChange({
|
|
142
142
|
action: SyncAction.Create,
|
|
143
|
-
|
|
143
|
+
tableName,
|
|
144
144
|
localId,
|
|
145
145
|
changes: syncedItem,
|
|
146
146
|
before: null,
|
|
@@ -175,7 +175,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
175
175
|
|
|
176
176
|
await state.addPendingChange({
|
|
177
177
|
action: isUpdate ? SyncAction.Update : SyncAction.Create,
|
|
178
|
-
|
|
178
|
+
tableName,
|
|
179
179
|
localId,
|
|
180
180
|
id: existingRecord?.id,
|
|
181
181
|
changes: syncedItem,
|
|
@@ -206,7 +206,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
206
206
|
if (result > 0) {
|
|
207
207
|
await state.addPendingChange({
|
|
208
208
|
action: SyncAction.Update,
|
|
209
|
-
|
|
209
|
+
tableName,
|
|
210
210
|
localId: key,
|
|
211
211
|
id: record.id,
|
|
212
212
|
changes: updatedChanges,
|
|
@@ -234,7 +234,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
234
234
|
deletedLocalId = record._localId;
|
|
235
235
|
await state.addPendingChange({
|
|
236
236
|
action: SyncAction.Remove,
|
|
237
|
-
|
|
237
|
+
tableName,
|
|
238
238
|
localId: record._localId,
|
|
239
239
|
id: record.id,
|
|
240
240
|
changes: null,
|
|
@@ -268,7 +268,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
268
268
|
for (const syncedItem of syncedItems) {
|
|
269
269
|
await state.addPendingChange({
|
|
270
270
|
action: SyncAction.Create,
|
|
271
|
-
|
|
271
|
+
tableName,
|
|
272
272
|
localId: syncedItem._localId,
|
|
273
273
|
changes: syncedItem,
|
|
274
274
|
before: null,
|
|
@@ -314,7 +314,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
314
314
|
const existing = existingMap.get(syncedItem._localId);
|
|
315
315
|
await state.addPendingChange({
|
|
316
316
|
action: existing ? SyncAction.Update : SyncAction.Create,
|
|
317
|
-
|
|
317
|
+
tableName,
|
|
318
318
|
localId: syncedItem._localId,
|
|
319
319
|
id: existing?.id,
|
|
320
320
|
changes: syncedItem,
|
|
@@ -364,7 +364,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
364
364
|
updatedKeys.push(record._localId);
|
|
365
365
|
await state.addPendingChange({
|
|
366
366
|
action: SyncAction.Update,
|
|
367
|
-
|
|
367
|
+
tableName,
|
|
368
368
|
localId: record._localId,
|
|
369
369
|
id: record.id,
|
|
370
370
|
changes,
|
|
@@ -398,7 +398,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
398
398
|
deletedLocalIds.push(record._localId);
|
|
399
399
|
await state.addPendingChange({
|
|
400
400
|
action: SyncAction.Remove,
|
|
401
|
-
|
|
401
|
+
tableName,
|
|
402
402
|
localId: record._localId,
|
|
403
403
|
id: record.id,
|
|
404
404
|
changes: null,
|
|
@@ -428,7 +428,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
|
|
|
428
428
|
deletedLocalIds.push(record._localId);
|
|
429
429
|
await state.addPendingChange({
|
|
430
430
|
action: SyncAction.Remove,
|
|
431
|
-
|
|
431
|
+
tableName,
|
|
432
432
|
localId: record._localId,
|
|
433
433
|
id: record.id,
|
|
434
434
|
changes: null,
|
package/src/index.shared.ts
CHANGED
|
@@ -492,8 +492,8 @@ class DyncBase<_TStoreMap = Record<string, any>> {
|
|
|
492
492
|
return;
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
await this.withTransaction('rw', [conflict.
|
|
496
|
-
const txTable = tables[conflict.
|
|
495
|
+
await this.withTransaction('rw', [conflict.tableName, DYNC_STATE_TABLE], async (tables) => {
|
|
496
|
+
const txTable = tables[conflict.tableName]!;
|
|
497
497
|
if (!keepLocal) {
|
|
498
498
|
const item = await txTable.get(localId);
|
|
499
499
|
if (item) {
|
|
@@ -509,7 +509,7 @@ class DyncBase<_TStoreMap = Record<string, any>> {
|
|
|
509
509
|
|
|
510
510
|
await this.state.setState((syncState) => ({
|
|
511
511
|
...syncState,
|
|
512
|
-
pendingChanges: syncState.pendingChanges.filter((p) => !(p.localId === localId && p.
|
|
512
|
+
pendingChanges: syncState.pendingChanges.filter((p) => !(p.localId === localId && p.tableName === conflict.tableName)),
|
|
513
513
|
}));
|
|
514
514
|
}
|
|
515
515
|
|
package/src/types.ts
CHANGED
|
@@ -97,7 +97,7 @@ export interface BatchSync {
|
|
|
97
97
|
export type MissingRemoteRecordStrategy = 'ignore' | 'delete-local-record' | 'insert-remote-record';
|
|
98
98
|
export type ConflictResolutionStrategy = 'local-wins' | 'remote-wins' | 'try-shallow-merge';
|
|
99
99
|
|
|
100
|
-
export type AfterRemoteAddCallback = (
|
|
100
|
+
export type AfterRemoteAddCallback = (tableName: string, item: SyncedRecord) => void;
|
|
101
101
|
export type MissingRemoteRecordDuringUpdateCallback = (strategy: MissingRemoteRecordStrategy, item: SyncedRecord) => void;
|
|
102
102
|
|
|
103
103
|
export interface SyncOptions {
|
|
@@ -157,7 +157,7 @@ export enum SyncAction {
|
|
|
157
157
|
|
|
158
158
|
export interface PendingChange {
|
|
159
159
|
action: SyncAction;
|
|
160
|
-
|
|
160
|
+
tableName: string;
|
|
161
161
|
localId: string;
|
|
162
162
|
id?: any;
|
|
163
163
|
version: number;
|
|
@@ -167,7 +167,7 @@ export interface PendingChange {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
export interface Conflict {
|
|
170
|
-
|
|
170
|
+
tableName: string;
|
|
171
171
|
fields: FieldConflict[];
|
|
172
172
|
}
|
|
173
173
|
|