@legendapp/state 3.0.0-beta.27 → 3.0.0-beta.29
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/package.json +1 -1
- package/sync-plugins/crud.js +13 -4
- package/sync-plugins/crud.mjs +13 -4
- package/sync-plugins/keel.d.mts +3 -0
- package/sync-plugins/keel.d.ts +3 -0
- package/sync-plugins/keel.js +8 -11
- package/sync-plugins/keel.mjs +8 -11
package/package.json
CHANGED
package/sync-plugins/crud.js
CHANGED
|
@@ -36,7 +36,7 @@ function arrayToRecord(arr, keyField) {
|
|
|
36
36
|
}
|
|
37
37
|
return record;
|
|
38
38
|
}
|
|
39
|
-
function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, actionFn, saveResult) {
|
|
39
|
+
function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, itemValueFull, actionFn, saveResult) {
|
|
40
40
|
if (action === "delete") {
|
|
41
41
|
if (queuedRetries.create.has(itemKey)) {
|
|
42
42
|
queuedRetries.create.delete(itemKey);
|
|
@@ -54,7 +54,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
54
54
|
itemValue = Object.assign(queuedRetry, itemValue);
|
|
55
55
|
}
|
|
56
56
|
queuedRetries[action].set(itemKey, itemValue);
|
|
57
|
-
const clonedValue = clone(
|
|
57
|
+
const clonedValue = clone(itemValueFull);
|
|
58
58
|
const paramsWithChanges = { ...params, changes: [change] };
|
|
59
59
|
return runWithRetry(
|
|
60
60
|
paramsWithChanges,
|
|
@@ -401,6 +401,7 @@ function syncedCrud(props) {
|
|
|
401
401
|
createObj,
|
|
402
402
|
changesById.get(itemKey),
|
|
403
403
|
queuedRetries,
|
|
404
|
+
createObj,
|
|
404
405
|
createFn,
|
|
405
406
|
saveResult
|
|
406
407
|
).then(() => {
|
|
@@ -409,11 +410,15 @@ function syncedCrud(props) {
|
|
|
409
410
|
}),
|
|
410
411
|
// Handle updates
|
|
411
412
|
...Array.from(updates).map(async ([itemKey, itemValue]) => {
|
|
413
|
+
const fullValue = updateFullValues.get(itemKey);
|
|
412
414
|
if (waitForSetParam) {
|
|
413
|
-
const fullValue = updateFullValues.get(itemKey);
|
|
414
415
|
await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
|
|
415
416
|
}
|
|
416
417
|
const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
|
|
418
|
+
const fullValueTransformed = await transformOut(
|
|
419
|
+
fullValue,
|
|
420
|
+
transform == null ? void 0 : transform.save
|
|
421
|
+
);
|
|
417
422
|
if (Object.keys(changed).length > 0) {
|
|
418
423
|
return retrySet(
|
|
419
424
|
params,
|
|
@@ -423,6 +428,7 @@ function syncedCrud(props) {
|
|
|
423
428
|
changed,
|
|
424
429
|
changesById.get(itemKey),
|
|
425
430
|
queuedRetries,
|
|
431
|
+
fullValueTransformed,
|
|
426
432
|
updateFn,
|
|
427
433
|
saveResult
|
|
428
434
|
);
|
|
@@ -447,19 +453,22 @@ function syncedCrud(props) {
|
|
|
447
453
|
valuePrevious,
|
|
448
454
|
changesById.get(itemKey),
|
|
449
455
|
queuedRetries,
|
|
456
|
+
valuePrevious,
|
|
450
457
|
deleteFn,
|
|
451
458
|
saveResult
|
|
452
459
|
);
|
|
453
460
|
}
|
|
454
461
|
if (fieldDeleted && updateFn) {
|
|
462
|
+
const value2 = { [fieldId]: itemKey, [fieldDeleted]: true };
|
|
455
463
|
return retrySet(
|
|
456
464
|
params,
|
|
457
465
|
retry,
|
|
458
466
|
"delete",
|
|
459
467
|
itemKey,
|
|
460
|
-
|
|
468
|
+
value2,
|
|
461
469
|
changesById.get(itemKey),
|
|
462
470
|
queuedRetries,
|
|
471
|
+
value2,
|
|
463
472
|
updateFn,
|
|
464
473
|
saveResult
|
|
465
474
|
);
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -34,7 +34,7 @@ function arrayToRecord(arr, keyField) {
|
|
|
34
34
|
}
|
|
35
35
|
return record;
|
|
36
36
|
}
|
|
37
|
-
function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, actionFn, saveResult) {
|
|
37
|
+
function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, itemValueFull, actionFn, saveResult) {
|
|
38
38
|
if (action === "delete") {
|
|
39
39
|
if (queuedRetries.create.has(itemKey)) {
|
|
40
40
|
queuedRetries.create.delete(itemKey);
|
|
@@ -52,7 +52,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
52
52
|
itemValue = Object.assign(queuedRetry, itemValue);
|
|
53
53
|
}
|
|
54
54
|
queuedRetries[action].set(itemKey, itemValue);
|
|
55
|
-
const clonedValue = clone(
|
|
55
|
+
const clonedValue = clone(itemValueFull);
|
|
56
56
|
const paramsWithChanges = { ...params, changes: [change] };
|
|
57
57
|
return runWithRetry(
|
|
58
58
|
paramsWithChanges,
|
|
@@ -399,6 +399,7 @@ function syncedCrud(props) {
|
|
|
399
399
|
createObj,
|
|
400
400
|
changesById.get(itemKey),
|
|
401
401
|
queuedRetries,
|
|
402
|
+
createObj,
|
|
402
403
|
createFn,
|
|
403
404
|
saveResult
|
|
404
405
|
).then(() => {
|
|
@@ -407,11 +408,15 @@ function syncedCrud(props) {
|
|
|
407
408
|
}),
|
|
408
409
|
// Handle updates
|
|
409
410
|
...Array.from(updates).map(async ([itemKey, itemValue]) => {
|
|
411
|
+
const fullValue = updateFullValues.get(itemKey);
|
|
410
412
|
if (waitForSetParam) {
|
|
411
|
-
const fullValue = updateFullValues.get(itemKey);
|
|
412
413
|
await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
|
|
413
414
|
}
|
|
414
415
|
const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
|
|
416
|
+
const fullValueTransformed = await transformOut(
|
|
417
|
+
fullValue,
|
|
418
|
+
transform == null ? void 0 : transform.save
|
|
419
|
+
);
|
|
415
420
|
if (Object.keys(changed).length > 0) {
|
|
416
421
|
return retrySet(
|
|
417
422
|
params,
|
|
@@ -421,6 +426,7 @@ function syncedCrud(props) {
|
|
|
421
426
|
changed,
|
|
422
427
|
changesById.get(itemKey),
|
|
423
428
|
queuedRetries,
|
|
429
|
+
fullValueTransformed,
|
|
424
430
|
updateFn,
|
|
425
431
|
saveResult
|
|
426
432
|
);
|
|
@@ -445,19 +451,22 @@ function syncedCrud(props) {
|
|
|
445
451
|
valuePrevious,
|
|
446
452
|
changesById.get(itemKey),
|
|
447
453
|
queuedRetries,
|
|
454
|
+
valuePrevious,
|
|
448
455
|
deleteFn,
|
|
449
456
|
saveResult
|
|
450
457
|
);
|
|
451
458
|
}
|
|
452
459
|
if (fieldDeleted && updateFn) {
|
|
460
|
+
const value2 = { [fieldId]: itemKey, [fieldDeleted]: true };
|
|
453
461
|
return retrySet(
|
|
454
462
|
params,
|
|
455
463
|
retry,
|
|
456
464
|
"delete",
|
|
457
465
|
itemKey,
|
|
458
|
-
|
|
466
|
+
value2,
|
|
459
467
|
changesById.get(itemKey),
|
|
460
468
|
queuedRetries,
|
|
469
|
+
value2,
|
|
461
470
|
updateFn,
|
|
462
471
|
saveResult
|
|
463
472
|
);
|
package/sync-plugins/keel.d.mts
CHANGED
|
@@ -50,6 +50,9 @@ interface KeelClient {
|
|
|
50
50
|
api: {
|
|
51
51
|
queries: Record<string, (i: any) => Promise<any>>;
|
|
52
52
|
};
|
|
53
|
+
client: {
|
|
54
|
+
rawRequest: <T>(action: string, body: any) => Promise<APIResult<T>>;
|
|
55
|
+
};
|
|
53
56
|
}
|
|
54
57
|
interface SyncedKeelPropsManyBase<TRemote extends {
|
|
55
58
|
id: string;
|
package/sync-plugins/keel.d.ts
CHANGED
|
@@ -50,6 +50,9 @@ interface KeelClient {
|
|
|
50
50
|
api: {
|
|
51
51
|
queries: Record<string, (i: any) => Promise<any>>;
|
|
52
52
|
};
|
|
53
|
+
client: {
|
|
54
|
+
rawRequest: <T>(action: string, body: any) => Promise<APIResult<T>>;
|
|
55
|
+
};
|
|
53
56
|
}
|
|
54
57
|
interface SyncedKeelPropsManyBase<TRemote extends {
|
|
55
58
|
id: string;
|
package/sync-plugins/keel.js
CHANGED
|
@@ -79,19 +79,16 @@ function setupRealtime(props) {
|
|
|
79
79
|
const { client } = props;
|
|
80
80
|
if (client && !modifiedClients.has(client)) {
|
|
81
81
|
modifiedClients.add(client);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
lastAction: key,
|
|
89
|
-
lastParams: i
|
|
90
|
-
};
|
|
91
|
-
return origFn(i);
|
|
82
|
+
const originalRawRequest = client.client.rawRequest;
|
|
83
|
+
client.client.rawRequest = (action, body) => {
|
|
84
|
+
if (action.startsWith("list")) {
|
|
85
|
+
realtimeState.current = {
|
|
86
|
+
lastAction: action,
|
|
87
|
+
lastParams: body
|
|
92
88
|
};
|
|
93
89
|
}
|
|
94
|
-
|
|
90
|
+
return originalRawRequest(action, body);
|
|
91
|
+
};
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
var NumPerPage = 200;
|
package/sync-plugins/keel.mjs
CHANGED
|
@@ -77,19 +77,16 @@ function setupRealtime(props) {
|
|
|
77
77
|
const { client } = props;
|
|
78
78
|
if (client && !modifiedClients.has(client)) {
|
|
79
79
|
modifiedClients.add(client);
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
lastAction: key,
|
|
87
|
-
lastParams: i
|
|
88
|
-
};
|
|
89
|
-
return origFn(i);
|
|
80
|
+
const originalRawRequest = client.client.rawRequest;
|
|
81
|
+
client.client.rawRequest = (action, body) => {
|
|
82
|
+
if (action.startsWith("list")) {
|
|
83
|
+
realtimeState.current = {
|
|
84
|
+
lastAction: action,
|
|
85
|
+
lastParams: body
|
|
90
86
|
};
|
|
91
87
|
}
|
|
92
|
-
|
|
88
|
+
return originalRawRequest(action, body);
|
|
89
|
+
};
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
var NumPerPage = 200;
|