@legendapp/state 3.0.0-beta.4 → 3.0.0-beta.41
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/.DS_Store +0 -0
- package/README.md +2 -2
- package/config/enableReactComponents.js +3 -1
- package/config/enableReactComponents.mjs +3 -1
- package/config/enableReactTracking.d.mts +2 -1
- package/config/enableReactTracking.d.ts +2 -1
- package/config/enableReactTracking.js +32 -13
- package/config/enableReactTracking.mjs +32 -13
- package/index.d.mts +46 -8
- package/index.d.ts +46 -8
- package/index.js +267 -75
- package/index.mjs +267 -75
- package/package.json +35 -1
- package/persist-plugins/async-storage.js +17 -9
- package/persist-plugins/async-storage.mjs +17 -9
- package/persist-plugins/expo-sqlite.d.mts +19 -0
- package/persist-plugins/expo-sqlite.d.ts +19 -0
- package/persist-plugins/expo-sqlite.js +72 -0
- package/persist-plugins/expo-sqlite.mjs +69 -0
- package/persist-plugins/indexeddb.js +13 -3
- package/persist-plugins/indexeddb.mjs +13 -3
- package/react-native.d.mts +4 -0
- package/react-native.d.ts +4 -0
- package/react-native.js +53 -0
- package/react-native.mjs +40 -0
- package/react-reactive/Components.d.mts +19 -0
- package/react-reactive/Components.d.ts +19 -0
- package/react-reactive/Components.js +53 -0
- package/react-reactive/Components.mjs +40 -0
- package/react-reactive/enableReactComponents.d.mts +3 -2
- package/react-reactive/enableReactComponents.d.ts +3 -2
- package/react-reactive/enableReactComponents.js +10 -3
- package/react-reactive/enableReactComponents.mjs +10 -3
- package/react-reactive/enableReactNativeComponents.d.mts +3 -20
- package/react-reactive/enableReactNativeComponents.d.ts +3 -20
- package/react-reactive/enableReactNativeComponents.js +8 -3
- package/react-reactive/enableReactNativeComponents.mjs +8 -3
- package/react-reactive/enableReactive.js +10 -3
- package/react-reactive/enableReactive.mjs +10 -3
- package/react-reactive/enableReactive.native.js +8 -3
- package/react-reactive/enableReactive.native.mjs +8 -3
- package/react-reactive/enableReactive.web.js +8 -3
- package/react-reactive/enableReactive.web.mjs +8 -3
- package/react-web.d.mts +7 -0
- package/react-web.d.ts +7 -0
- package/react-web.js +39 -0
- package/react-web.mjs +37 -0
- package/react.d.mts +59 -26
- package/react.d.ts +59 -26
- package/react.js +136 -87
- package/react.mjs +135 -89
- package/sync-plugins/crud.d.mts +24 -9
- package/sync-plugins/crud.d.ts +24 -9
- package/sync-plugins/crud.js +267 -123
- package/sync-plugins/crud.mjs +268 -124
- package/sync-plugins/firebase.d.mts +7 -3
- package/sync-plugins/firebase.d.ts +7 -3
- package/sync-plugins/firebase.js +214 -64
- package/sync-plugins/firebase.mjs +215 -65
- package/sync-plugins/keel.d.mts +12 -13
- package/sync-plugins/keel.d.ts +12 -13
- package/sync-plugins/keel.js +60 -52
- package/sync-plugins/keel.mjs +61 -48
- package/sync-plugins/supabase.d.mts +10 -5
- package/sync-plugins/supabase.d.ts +10 -5
- package/sync-plugins/supabase.js +90 -33
- package/sync-plugins/supabase.mjs +91 -34
- package/sync-plugins/tanstack-query.d.mts +3 -3
- package/sync-plugins/tanstack-query.d.ts +3 -3
- package/sync-plugins/tanstack-query.js +1 -1
- package/sync-plugins/tanstack-query.mjs +1 -1
- package/sync.d.mts +17 -8
- package/sync.d.ts +17 -8
- package/sync.js +448 -307
- package/sync.mjs +446 -307
- package/trace.js +5 -6
- package/trace.mjs +5 -6
- package/types/reactive-native.d.ts +19 -0
- package/types/reactive-web.d.ts +7 -0
package/sync-plugins/supabase.js
CHANGED
|
@@ -18,15 +18,29 @@ function configureSyncedSupabase(config) {
|
|
|
18
18
|
}
|
|
19
19
|
Object.assign(supabaseConfig, sync.removeNullUndefined(rest));
|
|
20
20
|
}
|
|
21
|
-
function wrapSupabaseFn(fn) {
|
|
22
|
-
return async (...args) => {
|
|
23
|
-
const {
|
|
21
|
+
function wrapSupabaseFn(fn, source) {
|
|
22
|
+
return async (params, ...args) => {
|
|
23
|
+
const { onError } = params;
|
|
24
|
+
const { data, error } = await fn(params, ...args);
|
|
24
25
|
if (error) {
|
|
25
|
-
|
|
26
|
+
onError(new Error(error.message), {
|
|
27
|
+
getParams: params,
|
|
28
|
+
source,
|
|
29
|
+
type: "get",
|
|
30
|
+
retry: params
|
|
31
|
+
});
|
|
26
32
|
}
|
|
27
33
|
return data;
|
|
28
34
|
};
|
|
29
35
|
}
|
|
36
|
+
function handleSupabaseError(error, onError, params) {
|
|
37
|
+
var _a;
|
|
38
|
+
if ((_a = error.message) == null ? void 0 : _a.includes("Failed to fetch")) {
|
|
39
|
+
throw error;
|
|
40
|
+
} else {
|
|
41
|
+
onError(new Error(error.message), params);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
30
44
|
function syncedSupabase(props) {
|
|
31
45
|
props = { ...supabaseConfig, ...props };
|
|
32
46
|
const {
|
|
@@ -36,10 +50,11 @@ function syncedSupabase(props) {
|
|
|
36
50
|
schema,
|
|
37
51
|
filter,
|
|
38
52
|
actions,
|
|
39
|
-
fieldCreatedAt
|
|
40
|
-
fieldUpdatedAt
|
|
41
|
-
fieldDeleted
|
|
53
|
+
fieldCreatedAt,
|
|
54
|
+
fieldUpdatedAt,
|
|
55
|
+
fieldDeleted,
|
|
42
56
|
realtime,
|
|
57
|
+
fieldId = "id",
|
|
43
58
|
changesSince,
|
|
44
59
|
transform: transformParam,
|
|
45
60
|
stringifyDates,
|
|
@@ -54,11 +69,19 @@ function syncedSupabase(props) {
|
|
|
54
69
|
...rest
|
|
55
70
|
} = props;
|
|
56
71
|
const client = supabase;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
if (process.env.NODE_ENV === "development" && changesSince === "last-sync") {
|
|
73
|
+
if (!fieldCreatedAt) {
|
|
74
|
+
console.warn("[legend-state] fieldCreatedAt is required when using last-sync mode");
|
|
75
|
+
}
|
|
76
|
+
if (!fieldUpdatedAt) {
|
|
77
|
+
console.warn("[legend-state] fieldUpdatedAt is required when using last-sync mode");
|
|
78
|
+
}
|
|
79
|
+
if (!fieldDeleted) {
|
|
80
|
+
console.warn("[legend-state] fieldDeleted is required when using last-sync mode");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const list = !actions || actions.includes("read") ? listParam ? wrapSupabaseFn(listParam, "list") : async (params) => {
|
|
84
|
+
const { lastSync, onError } = params;
|
|
62
85
|
const clientSchema = schema ? client.schema(schema) : client;
|
|
63
86
|
const from = clientSchema.from(collection);
|
|
64
87
|
let select = selectFn ? selectFn(from) : from.select();
|
|
@@ -70,42 +93,75 @@ function syncedSupabase(props) {
|
|
|
70
93
|
select = filter(select, params);
|
|
71
94
|
}
|
|
72
95
|
const { data, error } = await select;
|
|
73
|
-
if (
|
|
74
|
-
|
|
96
|
+
if (data) {
|
|
97
|
+
return data || [];
|
|
98
|
+
} else if (error) {
|
|
99
|
+
handleSupabaseError(error, onError, {
|
|
100
|
+
getParams: params,
|
|
101
|
+
source: "list",
|
|
102
|
+
type: "get",
|
|
103
|
+
retry: params
|
|
104
|
+
});
|
|
75
105
|
}
|
|
76
|
-
return
|
|
106
|
+
return null;
|
|
77
107
|
} : void 0;
|
|
78
|
-
const create = createParam ? wrapSupabaseFn(createParam) : !actions || actions.includes("create") ? async (input) => {
|
|
108
|
+
const create = createParam ? wrapSupabaseFn(createParam, "create") : !actions || actions.includes("create") ? async (input, params) => {
|
|
109
|
+
const { onError } = params;
|
|
79
110
|
const res = await client.from(collection).insert(input).select();
|
|
80
111
|
const { data, error } = res;
|
|
81
112
|
if (data) {
|
|
82
113
|
const created = data[0];
|
|
83
114
|
return created;
|
|
84
|
-
} else {
|
|
85
|
-
|
|
115
|
+
} else if (error) {
|
|
116
|
+
handleSupabaseError(error, onError, {
|
|
117
|
+
setParams: params,
|
|
118
|
+
source: "create",
|
|
119
|
+
type: "set",
|
|
120
|
+
retry: params,
|
|
121
|
+
input,
|
|
122
|
+
revert: sync.createRevertChanges(params.value$, params.changes)
|
|
123
|
+
});
|
|
86
124
|
}
|
|
87
125
|
} : void 0;
|
|
88
|
-
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam) : async (input) => {
|
|
89
|
-
const
|
|
126
|
+
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam, "update") : async (input, params) => {
|
|
127
|
+
const { onError } = params;
|
|
128
|
+
const res = await client.from(collection).update(input).eq(fieldId, input[fieldId]).select();
|
|
90
129
|
const { data, error } = res;
|
|
91
130
|
if (data) {
|
|
92
131
|
const created = data[0];
|
|
93
132
|
return created;
|
|
94
|
-
} else {
|
|
95
|
-
|
|
133
|
+
} else if (error) {
|
|
134
|
+
handleSupabaseError(error, onError, {
|
|
135
|
+
setParams: params,
|
|
136
|
+
source: "update",
|
|
137
|
+
type: "set",
|
|
138
|
+
retry: params,
|
|
139
|
+
input,
|
|
140
|
+
revert: sync.createRevertChanges(params.value$, params.changes)
|
|
141
|
+
});
|
|
96
142
|
}
|
|
97
143
|
} : void 0;
|
|
98
|
-
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ?
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
144
|
+
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ? (
|
|
145
|
+
// prettier-ignore
|
|
146
|
+
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
147
|
+
const { onError } = params;
|
|
148
|
+
const res = await client.from(collection).delete().eq(fieldId, input[fieldId]).select();
|
|
149
|
+
const { data, error } = res;
|
|
150
|
+
if (data) {
|
|
151
|
+
const created = data[0];
|
|
152
|
+
return created;
|
|
153
|
+
} else if (error) {
|
|
154
|
+
handleSupabaseError(error, onError, {
|
|
155
|
+
setParams: params,
|
|
156
|
+
source: "delete",
|
|
157
|
+
type: "set",
|
|
158
|
+
retry: params,
|
|
159
|
+
input,
|
|
160
|
+
revert: sync.createRevertChanges(params.value$, params.changes)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
107
163
|
}
|
|
108
|
-
|
|
164
|
+
) : void 0;
|
|
109
165
|
const subscribe = realtime ? ({ node, value$, update: update2 }) => {
|
|
110
166
|
const { filter: filter2, schema: schema2 } = state.isObject(realtime) ? realtime : {};
|
|
111
167
|
const channel = client.channel(`LS_${node.key || ""}${channelNum++}`).on(
|
|
@@ -120,7 +176,7 @@ function syncedSupabase(props) {
|
|
|
120
176
|
var _a;
|
|
121
177
|
const { eventType, new: value, old } = payload;
|
|
122
178
|
if (eventType === "INSERT" || eventType === "UPDATE") {
|
|
123
|
-
const cur = (_a = value$.peek()) == null ? void 0 : _a[value
|
|
179
|
+
const cur = (_a = value$.peek()) == null ? void 0 : _a[value[fieldId]];
|
|
124
180
|
let isOk = !fieldUpdatedAt;
|
|
125
181
|
let lastSync = void 0;
|
|
126
182
|
if (!isOk) {
|
|
@@ -163,6 +219,7 @@ function syncedSupabase(props) {
|
|
|
163
219
|
fieldUpdatedAt,
|
|
164
220
|
fieldDeleted,
|
|
165
221
|
updatePartial: false,
|
|
222
|
+
fieldId,
|
|
166
223
|
transform,
|
|
167
224
|
generateId,
|
|
168
225
|
waitFor: () => isEnabled$.get() && (waitFor ? state.computeSelector(waitFor) : true),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { observable, computeSelector, isFunction, isObject, symbolDelete } from '@legendapp/state';
|
|
2
|
-
import { removeNullUndefined, transformStringifyDates, combineTransforms } from '@legendapp/state/sync';
|
|
2
|
+
import { removeNullUndefined, createRevertChanges, transformStringifyDates, combineTransforms } from '@legendapp/state/sync';
|
|
3
3
|
import { syncedCrud } from '@legendapp/state/sync-plugins/crud';
|
|
4
4
|
|
|
5
5
|
// src/sync-plugins/supabase.ts
|
|
@@ -16,15 +16,29 @@ function configureSyncedSupabase(config) {
|
|
|
16
16
|
}
|
|
17
17
|
Object.assign(supabaseConfig, removeNullUndefined(rest));
|
|
18
18
|
}
|
|
19
|
-
function wrapSupabaseFn(fn) {
|
|
20
|
-
return async (...args) => {
|
|
21
|
-
const {
|
|
19
|
+
function wrapSupabaseFn(fn, source) {
|
|
20
|
+
return async (params, ...args) => {
|
|
21
|
+
const { onError } = params;
|
|
22
|
+
const { data, error } = await fn(params, ...args);
|
|
22
23
|
if (error) {
|
|
23
|
-
|
|
24
|
+
onError(new Error(error.message), {
|
|
25
|
+
getParams: params,
|
|
26
|
+
source,
|
|
27
|
+
type: "get",
|
|
28
|
+
retry: params
|
|
29
|
+
});
|
|
24
30
|
}
|
|
25
31
|
return data;
|
|
26
32
|
};
|
|
27
33
|
}
|
|
34
|
+
function handleSupabaseError(error, onError, params) {
|
|
35
|
+
var _a;
|
|
36
|
+
if ((_a = error.message) == null ? void 0 : _a.includes("Failed to fetch")) {
|
|
37
|
+
throw error;
|
|
38
|
+
} else {
|
|
39
|
+
onError(new Error(error.message), params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
28
42
|
function syncedSupabase(props) {
|
|
29
43
|
props = { ...supabaseConfig, ...props };
|
|
30
44
|
const {
|
|
@@ -34,10 +48,11 @@ function syncedSupabase(props) {
|
|
|
34
48
|
schema,
|
|
35
49
|
filter,
|
|
36
50
|
actions,
|
|
37
|
-
fieldCreatedAt
|
|
38
|
-
fieldUpdatedAt
|
|
39
|
-
fieldDeleted
|
|
51
|
+
fieldCreatedAt,
|
|
52
|
+
fieldUpdatedAt,
|
|
53
|
+
fieldDeleted,
|
|
40
54
|
realtime,
|
|
55
|
+
fieldId = "id",
|
|
41
56
|
changesSince,
|
|
42
57
|
transform: transformParam,
|
|
43
58
|
stringifyDates,
|
|
@@ -52,11 +67,19 @@ function syncedSupabase(props) {
|
|
|
52
67
|
...rest
|
|
53
68
|
} = props;
|
|
54
69
|
const client = supabase;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
if (process.env.NODE_ENV === "development" && changesSince === "last-sync") {
|
|
71
|
+
if (!fieldCreatedAt) {
|
|
72
|
+
console.warn("[legend-state] fieldCreatedAt is required when using last-sync mode");
|
|
73
|
+
}
|
|
74
|
+
if (!fieldUpdatedAt) {
|
|
75
|
+
console.warn("[legend-state] fieldUpdatedAt is required when using last-sync mode");
|
|
76
|
+
}
|
|
77
|
+
if (!fieldDeleted) {
|
|
78
|
+
console.warn("[legend-state] fieldDeleted is required when using last-sync mode");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const list = !actions || actions.includes("read") ? listParam ? wrapSupabaseFn(listParam, "list") : async (params) => {
|
|
82
|
+
const { lastSync, onError } = params;
|
|
60
83
|
const clientSchema = schema ? client.schema(schema) : client;
|
|
61
84
|
const from = clientSchema.from(collection);
|
|
62
85
|
let select = selectFn ? selectFn(from) : from.select();
|
|
@@ -68,42 +91,75 @@ function syncedSupabase(props) {
|
|
|
68
91
|
select = filter(select, params);
|
|
69
92
|
}
|
|
70
93
|
const { data, error } = await select;
|
|
71
|
-
if (
|
|
72
|
-
|
|
94
|
+
if (data) {
|
|
95
|
+
return data || [];
|
|
96
|
+
} else if (error) {
|
|
97
|
+
handleSupabaseError(error, onError, {
|
|
98
|
+
getParams: params,
|
|
99
|
+
source: "list",
|
|
100
|
+
type: "get",
|
|
101
|
+
retry: params
|
|
102
|
+
});
|
|
73
103
|
}
|
|
74
|
-
return
|
|
104
|
+
return null;
|
|
75
105
|
} : void 0;
|
|
76
|
-
const create = createParam ? wrapSupabaseFn(createParam) : !actions || actions.includes("create") ? async (input) => {
|
|
106
|
+
const create = createParam ? wrapSupabaseFn(createParam, "create") : !actions || actions.includes("create") ? async (input, params) => {
|
|
107
|
+
const { onError } = params;
|
|
77
108
|
const res = await client.from(collection).insert(input).select();
|
|
78
109
|
const { data, error } = res;
|
|
79
110
|
if (data) {
|
|
80
111
|
const created = data[0];
|
|
81
112
|
return created;
|
|
82
|
-
} else {
|
|
83
|
-
|
|
113
|
+
} else if (error) {
|
|
114
|
+
handleSupabaseError(error, onError, {
|
|
115
|
+
setParams: params,
|
|
116
|
+
source: "create",
|
|
117
|
+
type: "set",
|
|
118
|
+
retry: params,
|
|
119
|
+
input,
|
|
120
|
+
revert: createRevertChanges(params.value$, params.changes)
|
|
121
|
+
});
|
|
84
122
|
}
|
|
85
123
|
} : void 0;
|
|
86
|
-
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam) : async (input) => {
|
|
87
|
-
const
|
|
124
|
+
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam, "update") : async (input, params) => {
|
|
125
|
+
const { onError } = params;
|
|
126
|
+
const res = await client.from(collection).update(input).eq(fieldId, input[fieldId]).select();
|
|
88
127
|
const { data, error } = res;
|
|
89
128
|
if (data) {
|
|
90
129
|
const created = data[0];
|
|
91
130
|
return created;
|
|
92
|
-
} else {
|
|
93
|
-
|
|
131
|
+
} else if (error) {
|
|
132
|
+
handleSupabaseError(error, onError, {
|
|
133
|
+
setParams: params,
|
|
134
|
+
source: "update",
|
|
135
|
+
type: "set",
|
|
136
|
+
retry: params,
|
|
137
|
+
input,
|
|
138
|
+
revert: createRevertChanges(params.value$, params.changes)
|
|
139
|
+
});
|
|
94
140
|
}
|
|
95
141
|
} : void 0;
|
|
96
|
-
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ?
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
142
|
+
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ? (
|
|
143
|
+
// prettier-ignore
|
|
144
|
+
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
145
|
+
const { onError } = params;
|
|
146
|
+
const res = await client.from(collection).delete().eq(fieldId, input[fieldId]).select();
|
|
147
|
+
const { data, error } = res;
|
|
148
|
+
if (data) {
|
|
149
|
+
const created = data[0];
|
|
150
|
+
return created;
|
|
151
|
+
} else if (error) {
|
|
152
|
+
handleSupabaseError(error, onError, {
|
|
153
|
+
setParams: params,
|
|
154
|
+
source: "delete",
|
|
155
|
+
type: "set",
|
|
156
|
+
retry: params,
|
|
157
|
+
input,
|
|
158
|
+
revert: createRevertChanges(params.value$, params.changes)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
105
161
|
}
|
|
106
|
-
|
|
162
|
+
) : void 0;
|
|
107
163
|
const subscribe = realtime ? ({ node, value$, update: update2 }) => {
|
|
108
164
|
const { filter: filter2, schema: schema2 } = isObject(realtime) ? realtime : {};
|
|
109
165
|
const channel = client.channel(`LS_${node.key || ""}${channelNum++}`).on(
|
|
@@ -118,7 +174,7 @@ function syncedSupabase(props) {
|
|
|
118
174
|
var _a;
|
|
119
175
|
const { eventType, new: value, old } = payload;
|
|
120
176
|
if (eventType === "INSERT" || eventType === "UPDATE") {
|
|
121
|
-
const cur = (_a = value$.peek()) == null ? void 0 : _a[value
|
|
177
|
+
const cur = (_a = value$.peek()) == null ? void 0 : _a[value[fieldId]];
|
|
122
178
|
let isOk = !fieldUpdatedAt;
|
|
123
179
|
let lastSync = void 0;
|
|
124
180
|
if (!isOk) {
|
|
@@ -161,6 +217,7 @@ function syncedSupabase(props) {
|
|
|
161
217
|
fieldUpdatedAt,
|
|
162
218
|
fieldDeleted,
|
|
163
219
|
updatePartial: false,
|
|
220
|
+
fieldId,
|
|
164
221
|
transform,
|
|
165
222
|
generateId,
|
|
166
223
|
waitFor: () => isEnabled$.get() && (waitFor ? computeSelector(waitFor) : true),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SyncedOptions } from '@legendapp/state/sync';
|
|
1
|
+
import { SyncedOptions, Synced } from '@legendapp/state/sync';
|
|
2
2
|
import { QueryKey, QueryObserverOptions, QueryClient, MutationObserverOptions, DefaultError } from '@tanstack/query-core';
|
|
3
3
|
|
|
4
4
|
interface ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey extends QueryKey> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TData, TQueryKey>, 'queryKey'> {
|
|
@@ -7,8 +7,8 @@ interface ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey extends
|
|
|
7
7
|
interface SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey extends QueryKey> extends Omit<SyncedOptions<TData>, 'get' | 'set' | 'retry'> {
|
|
8
8
|
queryClient: QueryClient;
|
|
9
9
|
query: ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
10
|
-
mutation?: MutationObserverOptions<
|
|
10
|
+
mutation?: MutationObserverOptions<TQueryFnData, TError, TData>;
|
|
11
11
|
}
|
|
12
|
-
declare function syncedQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(params: SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey>): TData
|
|
12
|
+
declare function syncedQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(params: SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey>): Synced<TData>;
|
|
13
13
|
|
|
14
14
|
export { type ObservableQueryOptions, type SyncedQueryParams, syncedQuery };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SyncedOptions } from '@legendapp/state/sync';
|
|
1
|
+
import { SyncedOptions, Synced } from '@legendapp/state/sync';
|
|
2
2
|
import { QueryKey, QueryObserverOptions, QueryClient, MutationObserverOptions, DefaultError } from '@tanstack/query-core';
|
|
3
3
|
|
|
4
4
|
interface ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey extends QueryKey> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TData, TQueryKey>, 'queryKey'> {
|
|
@@ -7,8 +7,8 @@ interface ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey extends
|
|
|
7
7
|
interface SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey extends QueryKey> extends Omit<SyncedOptions<TData>, 'get' | 'set' | 'retry'> {
|
|
8
8
|
queryClient: QueryClient;
|
|
9
9
|
query: ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
10
|
-
mutation?: MutationObserverOptions<
|
|
10
|
+
mutation?: MutationObserverOptions<TQueryFnData, TError, TData>;
|
|
11
11
|
}
|
|
12
|
-
declare function syncedQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(params: SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey>): TData
|
|
12
|
+
declare function syncedQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(params: SyncedQueryParams<TQueryFnData, TError, TData, TQueryKey>): Synced<TData>;
|
|
13
13
|
|
|
14
14
|
export { type ObservableQueryOptions, type SyncedQueryParams, syncedQuery };
|
package/sync.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MMKVConfiguration } from 'react-native-mmkv';
|
|
2
2
|
import { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
|
|
3
|
-
import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, UpdateFn, LinkedOptions, RetryOptions, Change, Observable, ObservableSyncState, TypeAtPath, RecordValue, ArrayValue, WaitForSet } from '@legendapp/state';
|
|
3
|
+
import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, UpdateSetFn, UpdateFn, LinkedOptions, RetryOptions, Change, Observable, ObservableSyncState, TypeAtPath, RecordValue, ArrayValue, WaitForSet } from '@legendapp/state';
|
|
4
4
|
import { SyncedOptionsGlobal as SyncedOptionsGlobal$1 } from '@legendapp/state/sync';
|
|
5
5
|
|
|
6
6
|
interface PersistOptions<T = any> {
|
|
@@ -32,12 +32,12 @@ interface SyncedGetParams<T> extends SyncedGetSetBaseParams<T> {
|
|
|
32
32
|
lastSync: number | undefined;
|
|
33
33
|
updateLastSync: (lastSync: number) => void;
|
|
34
34
|
mode: GetMode;
|
|
35
|
-
onError: (error: Error) => void;
|
|
35
|
+
onError: (error: Error, params: SyncedErrorParams) => void;
|
|
36
36
|
options: SyncedOptions;
|
|
37
37
|
}
|
|
38
38
|
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>, SyncedGetSetBaseParams<T> {
|
|
39
|
-
update:
|
|
40
|
-
onError: (error: Error,
|
|
39
|
+
update: UpdateSetFn<T>;
|
|
40
|
+
onError: (error: Error, params: SyncedErrorParams) => void;
|
|
41
41
|
}
|
|
42
42
|
interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams<T> {
|
|
43
43
|
lastSync: number | undefined;
|
|
@@ -45,12 +45,14 @@ interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams
|
|
|
45
45
|
onError: (error: Error) => void;
|
|
46
46
|
}
|
|
47
47
|
interface SyncedErrorParams {
|
|
48
|
+
source: 'get' | 'set' | 'subscribe';
|
|
49
|
+
type: 'get' | 'set';
|
|
50
|
+
retry: OnErrorRetryParams;
|
|
48
51
|
getParams?: SyncedGetParams<any>;
|
|
49
52
|
setParams?: SyncedSetParams<any>;
|
|
50
53
|
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
retryParams?: OnErrorRetryParams;
|
|
54
|
+
input?: any;
|
|
55
|
+
revert?: () => void;
|
|
54
56
|
}
|
|
55
57
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
56
58
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
@@ -209,17 +211,24 @@ declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin>
|
|
|
209
211
|
declare function onChangeRemote(cb: () => void): void;
|
|
210
212
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: SyncedOptions<T>): Observable<ObservableSyncState>;
|
|
211
213
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced<T>): Observable<ObservableSyncState>;
|
|
214
|
+
declare function getAllSyncStates(): readonly [Observable<ObservableSyncState>, NodeInfo][];
|
|
212
215
|
|
|
213
216
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
214
217
|
|
|
215
218
|
declare function configureSynced<T extends (...args: any[]) => any>(fn: T, origOptions: Partial<Parameters<T>[0]>): T;
|
|
216
219
|
declare function configureSynced(origOptions: SyncedOptions): typeof synced;
|
|
217
220
|
|
|
221
|
+
declare function createRevertChanges(obs$: ObservableParam<any>, changes: Change[]): () => void;
|
|
222
|
+
|
|
218
223
|
declare function waitForSet(waitForSet: WaitForSet<any>, changes: Change[], value: any, params?: Record<string, any>): Promise<void>;
|
|
219
224
|
|
|
225
|
+
declare function runWithRetry<T>(state: SyncedGetSetBaseParams<any>, retryOptions: RetryOptions | undefined, retryId: any, fn: (params: OnErrorRetryParams) => Promise<T>): Promise<T>;
|
|
226
|
+
declare function runWithRetry<T>(state: SyncedGetSetBaseParams<any>, retryOptions: RetryOptions | undefined, retryId: any, fn: (params: OnErrorRetryParams) => T): T;
|
|
227
|
+
|
|
220
228
|
declare const internal: {
|
|
221
229
|
observableSyncConfiguration: SyncedOptionsGlobal;
|
|
222
230
|
waitForSet: typeof waitForSet;
|
|
231
|
+
runWithRetry: typeof runWithRetry;
|
|
223
232
|
};
|
|
224
233
|
|
|
225
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
234
|
+
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, getAllSyncStates, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
package/sync.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MMKVConfiguration } from 'react-native-mmkv';
|
|
2
2
|
import { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
|
|
3
|
-
import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, UpdateFn, LinkedOptions, RetryOptions, Change, Observable, ObservableSyncState, TypeAtPath, RecordValue, ArrayValue, WaitForSet } from '@legendapp/state';
|
|
3
|
+
import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, UpdateSetFn, UpdateFn, LinkedOptions, RetryOptions, Change, Observable, ObservableSyncState, TypeAtPath, RecordValue, ArrayValue, WaitForSet } from '@legendapp/state';
|
|
4
4
|
import { SyncedOptionsGlobal as SyncedOptionsGlobal$1 } from '@legendapp/state/sync';
|
|
5
5
|
|
|
6
6
|
interface PersistOptions<T = any> {
|
|
@@ -32,12 +32,12 @@ interface SyncedGetParams<T> extends SyncedGetSetBaseParams<T> {
|
|
|
32
32
|
lastSync: number | undefined;
|
|
33
33
|
updateLastSync: (lastSync: number) => void;
|
|
34
34
|
mode: GetMode;
|
|
35
|
-
onError: (error: Error) => void;
|
|
35
|
+
onError: (error: Error, params: SyncedErrorParams) => void;
|
|
36
36
|
options: SyncedOptions;
|
|
37
37
|
}
|
|
38
38
|
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>, SyncedGetSetBaseParams<T> {
|
|
39
|
-
update:
|
|
40
|
-
onError: (error: Error,
|
|
39
|
+
update: UpdateSetFn<T>;
|
|
40
|
+
onError: (error: Error, params: SyncedErrorParams) => void;
|
|
41
41
|
}
|
|
42
42
|
interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams<T> {
|
|
43
43
|
lastSync: number | undefined;
|
|
@@ -45,12 +45,14 @@ interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams
|
|
|
45
45
|
onError: (error: Error) => void;
|
|
46
46
|
}
|
|
47
47
|
interface SyncedErrorParams {
|
|
48
|
+
source: 'get' | 'set' | 'subscribe';
|
|
49
|
+
type: 'get' | 'set';
|
|
50
|
+
retry: OnErrorRetryParams;
|
|
48
51
|
getParams?: SyncedGetParams<any>;
|
|
49
52
|
setParams?: SyncedSetParams<any>;
|
|
50
53
|
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
retryParams?: OnErrorRetryParams;
|
|
54
|
+
input?: any;
|
|
55
|
+
revert?: () => void;
|
|
54
56
|
}
|
|
55
57
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
56
58
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
@@ -209,17 +211,24 @@ declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin>
|
|
|
209
211
|
declare function onChangeRemote(cb: () => void): void;
|
|
210
212
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: SyncedOptions<T>): Observable<ObservableSyncState>;
|
|
211
213
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced<T>): Observable<ObservableSyncState>;
|
|
214
|
+
declare function getAllSyncStates(): readonly [Observable<ObservableSyncState>, NodeInfo][];
|
|
212
215
|
|
|
213
216
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
214
217
|
|
|
215
218
|
declare function configureSynced<T extends (...args: any[]) => any>(fn: T, origOptions: Partial<Parameters<T>[0]>): T;
|
|
216
219
|
declare function configureSynced(origOptions: SyncedOptions): typeof synced;
|
|
217
220
|
|
|
221
|
+
declare function createRevertChanges(obs$: ObservableParam<any>, changes: Change[]): () => void;
|
|
222
|
+
|
|
218
223
|
declare function waitForSet(waitForSet: WaitForSet<any>, changes: Change[], value: any, params?: Record<string, any>): Promise<void>;
|
|
219
224
|
|
|
225
|
+
declare function runWithRetry<T>(state: SyncedGetSetBaseParams<any>, retryOptions: RetryOptions | undefined, retryId: any, fn: (params: OnErrorRetryParams) => Promise<T>): Promise<T>;
|
|
226
|
+
declare function runWithRetry<T>(state: SyncedGetSetBaseParams<any>, retryOptions: RetryOptions | undefined, retryId: any, fn: (params: OnErrorRetryParams) => T): T;
|
|
227
|
+
|
|
220
228
|
declare const internal: {
|
|
221
229
|
observableSyncConfiguration: SyncedOptionsGlobal;
|
|
222
230
|
waitForSet: typeof waitForSet;
|
|
231
|
+
runWithRetry: typeof runWithRetry;
|
|
223
232
|
};
|
|
224
233
|
|
|
225
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
234
|
+
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, getAllSyncStates, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|