@legendapp/state 3.0.0-alpha.16 → 3.0.0-alpha.18
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/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/sync-plugins/crud.js +4 -1
- package/sync-plugins/crud.mjs +4 -1
- package/sync-plugins/keel.d.mts +8 -2
- package/sync-plugins/keel.d.ts +8 -2
- package/sync-plugins/keel.js +7 -5
- package/sync-plugins/keel.mjs +7 -5
package/index.d.mts
CHANGED
|
@@ -394,8 +394,8 @@ declare const internal: {
|
|
|
394
394
|
};
|
|
395
395
|
pendingNodes: Map<NodeValue, () => void>;
|
|
396
396
|
dirtyNodes: Set<NodeValue>;
|
|
397
|
-
replacer: ((this: any, key: string, value: any) => any)
|
|
398
|
-
reviver: ((this: any, key: string, value: any) => any)
|
|
397
|
+
replacer: undefined | ((this: any, key: string, value: any) => any);
|
|
398
|
+
reviver: undefined | ((this: any, key: string, value: any) => any);
|
|
399
399
|
};
|
|
400
400
|
initializePathType: typeof initializePathType;
|
|
401
401
|
observableFns: Map<string, (node: NodeValue, ...args: any[]) => any>;
|
package/index.d.ts
CHANGED
|
@@ -394,8 +394,8 @@ declare const internal: {
|
|
|
394
394
|
};
|
|
395
395
|
pendingNodes: Map<NodeValue, () => void>;
|
|
396
396
|
dirtyNodes: Set<NodeValue>;
|
|
397
|
-
replacer: ((this: any, key: string, value: any) => any)
|
|
398
|
-
reviver: ((this: any, key: string, value: any) => any)
|
|
397
|
+
replacer: undefined | ((this: any, key: string, value: any) => any);
|
|
398
|
+
reviver: undefined | ((this: any, key: string, value: any) => any);
|
|
399
399
|
};
|
|
400
400
|
initializePathType: typeof initializePathType;
|
|
401
401
|
observableFns: Map<string, (node: NodeValue, ...args: any[]) => any>;
|
package/index.js
CHANGED
package/index.mjs
CHANGED
package/package.json
CHANGED
package/sync-plugins/crud.js
CHANGED
|
@@ -216,7 +216,10 @@ function syncedCrud(props) {
|
|
|
216
216
|
}
|
|
217
217
|
} else {
|
|
218
218
|
if (updateFn) {
|
|
219
|
-
updates.set(
|
|
219
|
+
updates.set(
|
|
220
|
+
item.id,
|
|
221
|
+
updates.has(item.id) ? Object.assign(updates.get(item.id), item) : item
|
|
222
|
+
);
|
|
220
223
|
} else {
|
|
221
224
|
console.log("[legend-state] missing update function");
|
|
222
225
|
}
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -214,7 +214,10 @@ function syncedCrud(props) {
|
|
|
214
214
|
}
|
|
215
215
|
} else {
|
|
216
216
|
if (updateFn) {
|
|
217
|
-
updates.set(
|
|
217
|
+
updates.set(
|
|
218
|
+
item.id,
|
|
219
|
+
updates.has(item.id) ? Object.assign(updates.get(item.id), item) : item
|
|
220
|
+
);
|
|
218
221
|
} else {
|
|
219
222
|
console.log("[legend-state] missing update function");
|
|
220
223
|
}
|
package/sync-plugins/keel.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SyncedGetSetSubscribeBaseParams, SyncedOptions } from '@legendapp/state/sync';
|
|
1
|
+
import { SyncedGetSetSubscribeBaseParams, SyncedOptions, SyncedSetParams } from '@legendapp/state/sync';
|
|
2
2
|
import { SyncedCrudPropsBase, CrudAsOption, SyncedCrudReturnType, SyncedCrudPropsSingle, CrudResult, SyncedCrudPropsMany } from '@legendapp/state/sync-plugins/crud';
|
|
3
3
|
|
|
4
4
|
interface KeelObjectBase {
|
|
@@ -55,7 +55,13 @@ interface SyncedKeelConfiguration extends Omit<SyncedCrudPropsBase<any>, keyof S
|
|
|
55
55
|
realtimePlugin?: KeelRealtimePlugin;
|
|
56
56
|
as?: Exclude<CrudAsOption, 'value'>;
|
|
57
57
|
enabled?: boolean;
|
|
58
|
-
onError?: (params:
|
|
58
|
+
onError?: (params: {
|
|
59
|
+
type: 'create' | 'update' | 'delete';
|
|
60
|
+
params: SyncedSetParams<any>;
|
|
61
|
+
input: any;
|
|
62
|
+
action: string;
|
|
63
|
+
error: APIResult<any>['error'];
|
|
64
|
+
}) => void;
|
|
59
65
|
}
|
|
60
66
|
interface SyncedKeelPropsManyBase<TRemote extends {
|
|
61
67
|
id: string;
|
package/sync-plugins/keel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SyncedGetSetSubscribeBaseParams, SyncedOptions } from '@legendapp/state/sync';
|
|
1
|
+
import { SyncedGetSetSubscribeBaseParams, SyncedOptions, SyncedSetParams } from '@legendapp/state/sync';
|
|
2
2
|
import { SyncedCrudPropsBase, CrudAsOption, SyncedCrudReturnType, SyncedCrudPropsSingle, CrudResult, SyncedCrudPropsMany } from '@legendapp/state/sync-plugins/crud';
|
|
3
3
|
|
|
4
4
|
interface KeelObjectBase {
|
|
@@ -55,7 +55,13 @@ interface SyncedKeelConfiguration extends Omit<SyncedCrudPropsBase<any>, keyof S
|
|
|
55
55
|
realtimePlugin?: KeelRealtimePlugin;
|
|
56
56
|
as?: Exclude<CrudAsOption, 'value'>;
|
|
57
57
|
enabled?: boolean;
|
|
58
|
-
onError?: (params:
|
|
58
|
+
onError?: (params: {
|
|
59
|
+
type: 'create' | 'update' | 'delete';
|
|
60
|
+
params: SyncedSetParams<any>;
|
|
61
|
+
input: any;
|
|
62
|
+
action: string;
|
|
63
|
+
error: APIResult<any>['error'];
|
|
64
|
+
}) => void;
|
|
59
65
|
}
|
|
60
66
|
interface SyncedKeelPropsManyBase<TRemote extends {
|
|
61
67
|
id: string;
|
package/sync-plugins/keel.js
CHANGED
|
@@ -183,7 +183,7 @@ function syncedKeel(props) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
|
-
const handleSetError = async (error, params, from) => {
|
|
186
|
+
const handleSetError = async (error, params, input, fn, from) => {
|
|
187
187
|
var _a, _b, _c;
|
|
188
188
|
const { retryNum, cancelRetry, update: update2 } = params;
|
|
189
189
|
if (from === "create" && ((_a = error.message) == null ? void 0 : _a.includes("for the unique")) && ((_b = error.message) == null ? void 0 : _b.includes("must be unique"))) {
|
|
@@ -203,7 +203,7 @@ function syncedKeel(props) {
|
|
|
203
203
|
cancelRetry();
|
|
204
204
|
}
|
|
205
205
|
} else if (error.type === "bad_request") {
|
|
206
|
-
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, error);
|
|
206
|
+
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, { error, params, input, type: from, action: fn.name || fn.toString() });
|
|
207
207
|
if (retryNum > 4) {
|
|
208
208
|
cancelRetry();
|
|
209
209
|
}
|
|
@@ -214,13 +214,15 @@ function syncedKeel(props) {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
const create = createParam ? async (input, params) => {
|
|
217
|
+
console.log(createParam.toString());
|
|
217
218
|
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
218
219
|
if (error) {
|
|
219
|
-
await handleSetError(error, params, "create");
|
|
220
|
+
await handleSetError(error, params, input, createParam, "create");
|
|
220
221
|
}
|
|
221
222
|
return data;
|
|
222
223
|
} : void 0;
|
|
223
224
|
const update = updateParam ? async (input, params) => {
|
|
225
|
+
console.log(updateParam.toString());
|
|
224
226
|
const id = input.id;
|
|
225
227
|
const values = convertObjectToCreate(input);
|
|
226
228
|
delete values.id;
|
|
@@ -229,7 +231,7 @@ function syncedKeel(props) {
|
|
|
229
231
|
if (!state.isEmpty(values)) {
|
|
230
232
|
const { data, error } = await updateParam({ where: { id }, values });
|
|
231
233
|
if (error) {
|
|
232
|
-
await handleSetError(error, params, "update");
|
|
234
|
+
await handleSetError(error, params, input, updateParam, "update");
|
|
233
235
|
}
|
|
234
236
|
return data;
|
|
235
237
|
}
|
|
@@ -237,7 +239,7 @@ function syncedKeel(props) {
|
|
|
237
239
|
const deleteFn = deleteParam ? async (value, params) => {
|
|
238
240
|
const { data, error } = await deleteParam({ id: value.id });
|
|
239
241
|
if (error) {
|
|
240
|
-
await handleSetError(error, params, "delete");
|
|
242
|
+
await handleSetError(error, params, value, deleteParam, "delete");
|
|
241
243
|
}
|
|
242
244
|
return data;
|
|
243
245
|
} : void 0;
|
package/sync-plugins/keel.mjs
CHANGED
|
@@ -177,7 +177,7 @@ function syncedKeel(props) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
-
const handleSetError = async (error, params, from) => {
|
|
180
|
+
const handleSetError = async (error, params, input, fn, from) => {
|
|
181
181
|
var _a, _b, _c;
|
|
182
182
|
const { retryNum, cancelRetry, update: update2 } = params;
|
|
183
183
|
if (from === "create" && ((_a = error.message) == null ? void 0 : _a.includes("for the unique")) && ((_b = error.message) == null ? void 0 : _b.includes("must be unique"))) {
|
|
@@ -197,7 +197,7 @@ function syncedKeel(props) {
|
|
|
197
197
|
cancelRetry();
|
|
198
198
|
}
|
|
199
199
|
} else if (error.type === "bad_request") {
|
|
200
|
-
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, error);
|
|
200
|
+
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, { error, params, input, type: from, action: fn.name || fn.toString() });
|
|
201
201
|
if (retryNum > 4) {
|
|
202
202
|
cancelRetry();
|
|
203
203
|
}
|
|
@@ -208,13 +208,15 @@ function syncedKeel(props) {
|
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
const create = createParam ? async (input, params) => {
|
|
211
|
+
console.log(createParam.toString());
|
|
211
212
|
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
212
213
|
if (error) {
|
|
213
|
-
await handleSetError(error, params, "create");
|
|
214
|
+
await handleSetError(error, params, input, createParam, "create");
|
|
214
215
|
}
|
|
215
216
|
return data;
|
|
216
217
|
} : void 0;
|
|
217
218
|
const update = updateParam ? async (input, params) => {
|
|
219
|
+
console.log(updateParam.toString());
|
|
218
220
|
const id = input.id;
|
|
219
221
|
const values = convertObjectToCreate(input);
|
|
220
222
|
delete values.id;
|
|
@@ -223,7 +225,7 @@ function syncedKeel(props) {
|
|
|
223
225
|
if (!isEmpty(values)) {
|
|
224
226
|
const { data, error } = await updateParam({ where: { id }, values });
|
|
225
227
|
if (error) {
|
|
226
|
-
await handleSetError(error, params, "update");
|
|
228
|
+
await handleSetError(error, params, input, updateParam, "update");
|
|
227
229
|
}
|
|
228
230
|
return data;
|
|
229
231
|
}
|
|
@@ -231,7 +233,7 @@ function syncedKeel(props) {
|
|
|
231
233
|
const deleteFn = deleteParam ? async (value, params) => {
|
|
232
234
|
const { data, error } = await deleteParam({ id: value.id });
|
|
233
235
|
if (error) {
|
|
234
|
-
await handleSetError(error, params, "delete");
|
|
236
|
+
await handleSetError(error, params, value, deleteParam, "delete");
|
|
235
237
|
}
|
|
236
238
|
return data;
|
|
237
239
|
} : void 0;
|