@legendapp/state 3.0.0-alpha.33 → 3.0.0-alpha.35
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/config.d.mts +1 -1
- package/config.d.ts +1 -1
- package/config.js +18 -12
- package/config.mjs +18 -12
- package/index.d.mts +10 -3
- package/index.d.ts +10 -3
- package/index.js +79 -42
- package/index.mjs +76 -42
- package/{observableInterfaces-CZR3_8mM.d.mts → observableInterfaces-CgBddSU6.d.mts} +6 -2
- package/{observableInterfaces-CZR3_8mM.d.ts → observableInterfaces-CgBddSU6.d.ts} +6 -2
- package/package.json +1 -1
- package/persist-plugins/async-storage.d.mts +2 -2
- package/persist-plugins/async-storage.d.ts +2 -2
- package/persist-plugins/async-storage.js +3 -7
- package/persist-plugins/async-storage.mjs +3 -7
- package/persist-plugins/indexeddb.d.mts +2 -2
- package/persist-plugins/indexeddb.d.ts +2 -2
- package/persist-plugins/indexeddb.js +3 -7
- package/persist-plugins/indexeddb.mjs +3 -7
- package/persist-plugins/mmkv.d.mts +2 -2
- package/persist-plugins/mmkv.d.ts +2 -2
- package/persist-plugins/mmkv.js +3 -7
- package/persist-plugins/mmkv.mjs +3 -7
- package/sync-plugins/crud.js +6 -7
- package/sync-plugins/crud.mjs +7 -8
- package/sync-plugins/keel.d.mts +28 -28
- package/sync-plugins/keel.d.ts +28 -28
- package/sync-plugins/keel.js +106 -82
- package/sync-plugins/keel.mjs +108 -82
- package/sync-plugins/supabase.d.mts +2 -2
- package/sync-plugins/supabase.d.ts +2 -2
- package/sync.d.mts +11 -13
- package/sync.d.ts +11 -13
- package/sync.js +149 -130
- package/sync.mjs +150 -131
package/sync-plugins/keel.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { observable,
|
|
2
|
-
import { removeNullUndefined } from '@legendapp/state/sync';
|
|
1
|
+
import { observable, isFunction, when, batch, isEmpty } from '@legendapp/state';
|
|
3
2
|
import { syncedCrud } from '@legendapp/state/sync-plugins/crud';
|
|
4
3
|
import ksuid from 'ksuid';
|
|
5
4
|
|
|
@@ -8,24 +7,50 @@ var KeelKeys = ["createdAt", "updatedAt"];
|
|
|
8
7
|
function generateKeelId() {
|
|
9
8
|
return ksuid.randomSync().string;
|
|
10
9
|
}
|
|
11
|
-
var keelConfig = {};
|
|
12
10
|
var modifiedClients = /* @__PURE__ */ new WeakSet();
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
11
|
+
var isAuthed$ = observable(false);
|
|
12
|
+
var isAuthing$ = observable(false);
|
|
13
|
+
async function ensureAuthToken(props, force) {
|
|
14
|
+
if (!force && isAuthed$.get()) {
|
|
15
|
+
return true;
|
|
18
16
|
}
|
|
19
|
-
|
|
17
|
+
const { client, refreshAuth } = props;
|
|
18
|
+
let isAuthed = await client.auth.isAuthenticated().then(({ data }) => data);
|
|
20
19
|
if (!isAuthed) {
|
|
21
|
-
|
|
20
|
+
if (!force && isAuthing$.get()) {
|
|
21
|
+
return when(
|
|
22
|
+
() => !isAuthing$.get(),
|
|
23
|
+
() => isAuthed$.get()
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
isAuthing$.set(true);
|
|
27
|
+
if (refreshAuth) {
|
|
28
|
+
await refreshAuth();
|
|
29
|
+
}
|
|
30
|
+
isAuthed = await client.auth.isAuthenticated().then(({ data }) => data);
|
|
31
|
+
if (!isAuthed) {
|
|
32
|
+
isAuthed = await client.auth.refresh().then(({ data }) => data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (isAuthed) {
|
|
36
|
+
batch(() => {
|
|
37
|
+
isAuthed$.set(true);
|
|
38
|
+
isAuthing$.set(false);
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
setTimeout(() => ensureAuthToken(
|
|
42
|
+
props,
|
|
43
|
+
/*force*/
|
|
44
|
+
true
|
|
45
|
+
), 1e3);
|
|
22
46
|
}
|
|
23
47
|
return isAuthed;
|
|
24
48
|
}
|
|
25
|
-
async function handleApiError(error, retry) {
|
|
49
|
+
async function handleApiError(props, error, retry) {
|
|
26
50
|
if (error.type === "unauthorized" || error.type === "forbidden") {
|
|
27
51
|
console.warn("Keel token expired, refreshing...");
|
|
28
|
-
|
|
52
|
+
isAuthed$.set(false);
|
|
53
|
+
await ensureAuthToken(props);
|
|
29
54
|
}
|
|
30
55
|
}
|
|
31
56
|
function convertObjectToCreate(item) {
|
|
@@ -45,49 +70,30 @@ function convertObjectToCreate(item) {
|
|
|
45
70
|
});
|
|
46
71
|
return cloned;
|
|
47
72
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const queries = client.api.queries;
|
|
62
|
-
Object.keys(queries).forEach((key) => {
|
|
63
|
-
if (key.startsWith("list")) {
|
|
64
|
-
const oldFn = queries[key];
|
|
65
|
-
queries[key] = (i) => {
|
|
66
|
-
const realtimeKey = [key, ...Object.values(i.where || {})].filter((value) => value && typeof value !== "object").join("/");
|
|
67
|
-
const subscribe = (params) => {
|
|
68
|
-
if (realtimeKey) {
|
|
69
|
-
return realtimePlugin.subscribe(realtimeKey, params);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return oldFn(i).then((ret) => {
|
|
73
|
-
if (subscribe) {
|
|
74
|
-
ret.subscribe = subscribe;
|
|
75
|
-
ret.subscribeKey = realtimeKey;
|
|
76
|
-
}
|
|
77
|
-
return ret;
|
|
78
|
-
});
|
|
73
|
+
var realtimeState = { current: {} };
|
|
74
|
+
function setupRealtime(props) {
|
|
75
|
+
const { client } = props;
|
|
76
|
+
if (client && !modifiedClients.has(client)) {
|
|
77
|
+
modifiedClients.add(client);
|
|
78
|
+
const queries = client.api.queries;
|
|
79
|
+
Object.keys(queries).forEach((key) => {
|
|
80
|
+
if (key.startsWith("list")) {
|
|
81
|
+
const origFn = queries[key];
|
|
82
|
+
queries[key] = (i) => {
|
|
83
|
+
realtimeState.current = {
|
|
84
|
+
lastAction: key,
|
|
85
|
+
lastParams: i
|
|
79
86
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
return origFn(i);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
});
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
var NumPerPage = 200;
|
|
86
|
-
async function getAllPages(listFn, params) {
|
|
94
|
+
async function getAllPages(props, listFn, params) {
|
|
87
95
|
const allData = [];
|
|
88
96
|
let pageInfo = void 0;
|
|
89
|
-
let subscribe_;
|
|
90
|
-
let subscribeKey_;
|
|
91
97
|
const { first: firstParam } = params;
|
|
92
98
|
do {
|
|
93
99
|
const first = firstParam ? Math.min(firstParam - allData.length, NumPerPage) : NumPerPage;
|
|
@@ -99,13 +105,9 @@ async function getAllPages(listFn, params) {
|
|
|
99
105
|
pageInfo = void 0;
|
|
100
106
|
const ret = await listFn(paramsWithCursor);
|
|
101
107
|
if (ret) {
|
|
102
|
-
const { data, error
|
|
103
|
-
if (subscribe) {
|
|
104
|
-
subscribe_ = subscribe;
|
|
105
|
-
subscribeKey_ = subscribeKey;
|
|
106
|
-
}
|
|
108
|
+
const { data, error } = ret;
|
|
107
109
|
if (error) {
|
|
108
|
-
await handleApiError(error);
|
|
110
|
+
await handleApiError(props, error);
|
|
109
111
|
throw new Error(error.message);
|
|
110
112
|
} else if (data) {
|
|
111
113
|
pageInfo = data.pageInfo;
|
|
@@ -113,23 +115,25 @@ async function getAllPages(listFn, params) {
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
} while (pageInfo == null ? void 0 : pageInfo.hasNextPage);
|
|
116
|
-
return
|
|
118
|
+
return allData;
|
|
117
119
|
}
|
|
118
120
|
function syncedKeel(props) {
|
|
119
|
-
const { realtimePlugin } = keelConfig;
|
|
120
|
-
props = { ...keelConfig, ...props };
|
|
121
121
|
const {
|
|
122
122
|
get: getParam,
|
|
123
123
|
list: listParam,
|
|
124
124
|
create: createParam,
|
|
125
125
|
update: updateParam,
|
|
126
126
|
delete: deleteParam,
|
|
127
|
+
subscribe: subscribeParam,
|
|
127
128
|
first,
|
|
128
129
|
where: whereParam,
|
|
129
130
|
waitFor,
|
|
130
131
|
waitForSet,
|
|
131
132
|
fieldDeleted,
|
|
133
|
+
realtime,
|
|
132
134
|
mode,
|
|
135
|
+
onError,
|
|
136
|
+
requireAuth = true,
|
|
133
137
|
...rest
|
|
134
138
|
} = props;
|
|
135
139
|
const { changesSince } = props;
|
|
@@ -138,13 +142,15 @@ function syncedKeel(props) {
|
|
|
138
142
|
const subscribeFnKey$ = observable("");
|
|
139
143
|
const fieldCreatedAt = "createdAt";
|
|
140
144
|
const fieldUpdatedAt = "updatedAt";
|
|
141
|
-
const setupSubscribe =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
145
|
+
const setupSubscribe = realtime ? async (getParams) => {
|
|
146
|
+
const { lastAction, lastParams } = realtimeState.current;
|
|
147
|
+
const { path, plugin } = realtime;
|
|
148
|
+
if (lastAction && path && plugin) {
|
|
149
|
+
const key = await path(lastAction, lastParams);
|
|
150
|
+
subscribeFn = () => realtime.plugin.subscribe(key, getParams);
|
|
151
|
+
subscribeFnKey$.set(key);
|
|
146
152
|
}
|
|
147
|
-
};
|
|
153
|
+
} : void 0;
|
|
148
154
|
const list = listParam ? async (listParams) => {
|
|
149
155
|
const { lastSync } = listParams;
|
|
150
156
|
const queryBySync = !!lastSync && changesSince === "last-sync";
|
|
@@ -153,18 +159,21 @@ function syncedKeel(props) {
|
|
|
153
159
|
isFunction(whereParam) ? whereParam() : whereParam
|
|
154
160
|
);
|
|
155
161
|
const params = { where, first };
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
realtimeState.current = {};
|
|
163
|
+
const promise = getAllPages(props, listParam, params);
|
|
164
|
+
if (realtime) {
|
|
165
|
+
setupSubscribe(listParams);
|
|
159
166
|
}
|
|
160
|
-
return
|
|
167
|
+
return promise;
|
|
161
168
|
} : void 0;
|
|
162
169
|
const get = getParam ? async (getParams) => {
|
|
163
170
|
const { refresh } = getParams;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
realtimeState.current = {};
|
|
172
|
+
const promise = getParam({ refresh });
|
|
173
|
+
if (realtime) {
|
|
174
|
+
setupSubscribe(getParams);
|
|
167
175
|
}
|
|
176
|
+
const { data, error } = await promise;
|
|
168
177
|
if (error) {
|
|
169
178
|
throw new Error(error.message);
|
|
170
179
|
} else {
|
|
@@ -173,17 +182,16 @@ function syncedKeel(props) {
|
|
|
173
182
|
} : void 0;
|
|
174
183
|
const onSaved = ({ saved }) => {
|
|
175
184
|
if (saved) {
|
|
176
|
-
|
|
177
|
-
if (updatedAt && realtimePlugin) {
|
|
185
|
+
if (realtime == null ? void 0 : realtime.plugin) {
|
|
178
186
|
const subscribeFnKey = subscribeFnKey$.get();
|
|
179
187
|
if (subscribeFnKey) {
|
|
180
|
-
|
|
188
|
+
realtime == null ? void 0 : realtime.plugin.setSaved(subscribeFnKey);
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
}
|
|
184
192
|
};
|
|
185
193
|
const handleSetError = async (error, params, input, fn, from) => {
|
|
186
|
-
var _a, _b
|
|
194
|
+
var _a, _b;
|
|
187
195
|
const { retryNum, update: update2 } = params;
|
|
188
196
|
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"))) {
|
|
189
197
|
if (__DEV__) {
|
|
@@ -202,13 +210,19 @@ function syncedKeel(props) {
|
|
|
202
210
|
params.cancelRetry = true;
|
|
203
211
|
}
|
|
204
212
|
} else if (error.type === "bad_request") {
|
|
205
|
-
|
|
213
|
+
onError == null ? void 0 : onError(new Error(error.message), params, {
|
|
214
|
+
error,
|
|
215
|
+
params,
|
|
216
|
+
input,
|
|
217
|
+
type: from,
|
|
218
|
+
action: fn.name || fn.toString()
|
|
219
|
+
});
|
|
206
220
|
if (retryNum > 4) {
|
|
207
221
|
params.cancelRetry = true;
|
|
208
222
|
}
|
|
209
223
|
throw new Error(error.message, { cause: { input } });
|
|
210
224
|
} else {
|
|
211
|
-
await handleApiError(error);
|
|
225
|
+
await handleApiError(props, error);
|
|
212
226
|
throw new Error(error.message, { cause: { input } });
|
|
213
227
|
}
|
|
214
228
|
};
|
|
@@ -238,7 +252,10 @@ function syncedKeel(props) {
|
|
|
238
252
|
}
|
|
239
253
|
return data;
|
|
240
254
|
} : void 0;
|
|
241
|
-
|
|
255
|
+
if (realtime) {
|
|
256
|
+
setupRealtime(props);
|
|
257
|
+
}
|
|
258
|
+
const subscribe = subscribeParam || (realtime ? (params) => {
|
|
242
259
|
let unsubscribe = void 0;
|
|
243
260
|
when(subscribeFnKey$, () => {
|
|
244
261
|
unsubscribe = subscribeFn(params);
|
|
@@ -246,7 +263,7 @@ function syncedKeel(props) {
|
|
|
246
263
|
return () => {
|
|
247
264
|
unsubscribe == null ? void 0 : unsubscribe();
|
|
248
265
|
};
|
|
249
|
-
};
|
|
266
|
+
} : void 0);
|
|
250
267
|
return syncedCrud({
|
|
251
268
|
...rest,
|
|
252
269
|
as: asType,
|
|
@@ -255,8 +272,17 @@ function syncedKeel(props) {
|
|
|
255
272
|
create,
|
|
256
273
|
update,
|
|
257
274
|
delete: deleteFn,
|
|
258
|
-
waitFor: () =>
|
|
259
|
-
|
|
275
|
+
waitFor: () => {
|
|
276
|
+
ensureAuthToken(props);
|
|
277
|
+
return [requireAuth ? isAuthed$ : true, waitFor || true];
|
|
278
|
+
},
|
|
279
|
+
waitForSet: (params) => {
|
|
280
|
+
ensureAuthToken(props);
|
|
281
|
+
return [
|
|
282
|
+
requireAuth ? isAuthed$ : true,
|
|
283
|
+
() => waitForSet ? isFunction(waitForSet) ? waitForSet(params) : waitForSet : true
|
|
284
|
+
];
|
|
285
|
+
},
|
|
260
286
|
onSaved,
|
|
261
287
|
fieldCreatedAt,
|
|
262
288
|
fieldUpdatedAt,
|
|
@@ -270,4 +296,4 @@ function syncedKeel(props) {
|
|
|
270
296
|
});
|
|
271
297
|
}
|
|
272
298
|
|
|
273
|
-
export { KeelKeys,
|
|
299
|
+
export { KeelKeys, generateKeelId, syncedKeel };
|
|
@@ -25,7 +25,7 @@ interface SyncedSupabaseConfiguration extends Omit<SyncedSupabaseConfig<{
|
|
|
25
25
|
enabled?: Observable<boolean>;
|
|
26
26
|
as?: Exclude<CrudAsOption, 'value'>;
|
|
27
27
|
}
|
|
28
|
-
interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client
|
|
28
|
+
interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client> = 'public', TOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote> extends SyncedSupabaseConfig<TRemote, TLocal>, Omit<SyncedCrudPropsMany<TRemote, TRemote, TOption>, 'list'> {
|
|
29
29
|
supabase: Client;
|
|
30
30
|
collection: Collection;
|
|
31
31
|
schema?: SchemaName;
|
|
@@ -44,6 +44,6 @@ interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collectio
|
|
|
44
44
|
}
|
|
45
45
|
declare function getSyncedSupabaseConfiguration(): SyncedSupabaseConfiguration;
|
|
46
46
|
declare function configureSyncedSupabase(config: SyncedSupabaseConfiguration): void;
|
|
47
|
-
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client
|
|
47
|
+
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabaseProps<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
48
48
|
|
|
49
49
|
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|
|
@@ -25,7 +25,7 @@ interface SyncedSupabaseConfiguration extends Omit<SyncedSupabaseConfig<{
|
|
|
25
25
|
enabled?: Observable<boolean>;
|
|
26
26
|
as?: Exclude<CrudAsOption, 'value'>;
|
|
27
27
|
}
|
|
28
|
-
interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client
|
|
28
|
+
interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client> = 'public', TOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote> extends SyncedSupabaseConfig<TRemote, TLocal>, Omit<SyncedCrudPropsMany<TRemote, TRemote, TOption>, 'list'> {
|
|
29
29
|
supabase: Client;
|
|
30
30
|
collection: Collection;
|
|
31
31
|
schema?: SchemaName;
|
|
@@ -44,6 +44,6 @@ interface SyncedSupabaseProps<Client extends SupabaseClient<any, any>, Collectio
|
|
|
44
44
|
}
|
|
45
45
|
declare function getSyncedSupabaseConfiguration(): SyncedSupabaseConfiguration;
|
|
46
46
|
declare function configureSyncedSupabase(config: SyncedSupabaseConfiguration): void;
|
|
47
|
-
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client
|
|
47
|
+
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabaseProps<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
48
48
|
|
|
49
49
|
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|
package/sync.d.mts
CHANGED
|
@@ -4,8 +4,8 @@ import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, Update
|
|
|
4
4
|
import { SyncedOptionsGlobal as SyncedOptionsGlobal$1 } from '@legendapp/state/sync';
|
|
5
5
|
|
|
6
6
|
interface PersistOptions<T = any> {
|
|
7
|
-
name
|
|
8
|
-
plugin?: ClassConstructor<ObservablePersistPlugin, T[]
|
|
7
|
+
name?: string;
|
|
8
|
+
plugin?: ClassConstructor<ObservablePersistPlugin, T[]> | ObservablePersistPlugin;
|
|
9
9
|
retrySync?: boolean;
|
|
10
10
|
transform?: SyncTransform<T>;
|
|
11
11
|
readonly?: boolean;
|
|
@@ -50,6 +50,7 @@ interface SyncedErrorParams {
|
|
|
50
50
|
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
51
|
source: 'get' | 'set' | 'subscribe';
|
|
52
52
|
value$: ObservableParam<any>;
|
|
53
|
+
retryParams?: OnErrorRetryParams;
|
|
53
54
|
}
|
|
54
55
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
55
56
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
@@ -61,18 +62,19 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
61
62
|
syncMode?: 'auto' | 'manual';
|
|
62
63
|
mode?: GetMode;
|
|
63
64
|
transform?: SyncTransform<TLocal, TRemote>;
|
|
64
|
-
onGetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
65
|
-
onSetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
66
65
|
onBeforeGet?: (params: {
|
|
67
66
|
value: TRemote;
|
|
68
67
|
lastSync: number | undefined;
|
|
69
68
|
pendingChanges: PendingChanges | undefined;
|
|
69
|
+
cancel: boolean;
|
|
70
70
|
clearPendingChanges: () => Promise<void>;
|
|
71
71
|
resetCache: () => Promise<void>;
|
|
72
72
|
}) => void;
|
|
73
|
-
onBeforeSet?: (
|
|
73
|
+
onBeforeSet?: (params: {
|
|
74
|
+
cancel: boolean;
|
|
75
|
+
}) => void;
|
|
74
76
|
onAfterSet?: () => void;
|
|
75
|
-
|
|
77
|
+
onError?: (error: Error, params: SyncedErrorParams) => void;
|
|
76
78
|
}
|
|
77
79
|
interface SyncedOptionsGlobal<T = any> extends Omit<SyncedOptions<T>, 'get' | 'set' | 'persist' | 'initial' | 'waitForSet' | 'waitFor' | 'transform' | 'subscribe'> {
|
|
78
80
|
persist?: ObservablePersistPluginOptions & Omit<PersistOptions, 'name' | 'transform' | 'options'>;
|
|
@@ -198,7 +200,7 @@ declare function transformStringifyDates<TRemote extends Record<string, any>, TL
|
|
|
198
200
|
declare function transformStringifyDates<TRemote extends Record<string, any>, Keys extends keyof TRemote = keyof TRemote>(...args: Keys[]): SyncTransform<TransformStringsToDates<TRemote, Keys>, TRemote>;
|
|
199
201
|
declare function transformStringifyDates<TRemote extends Record<string, any>, TLocal extends Record<string, any> = TRemote>(...args: (keyof TRemote)[]): SyncTransform<TRemote, TLocal>;
|
|
200
202
|
|
|
201
|
-
declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin
|
|
203
|
+
declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin> | ObservablePersistPlugin, {
|
|
202
204
|
plugin: ObservablePersistPlugin;
|
|
203
205
|
initialized: Observable<boolean>;
|
|
204
206
|
}>;
|
|
@@ -208,12 +210,8 @@ declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced
|
|
|
208
210
|
|
|
209
211
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
type RetType = typeof synced;
|
|
215
|
-
declare function configureSynced<T extends typeof synced>(fn: T, origOptions: SyncedOptionsConfigure): T;
|
|
216
|
-
declare function configureSynced(origOptions: SyncedOptionsConfigure): RetType;
|
|
213
|
+
declare function configureSynced<T extends (...args: any[]) => any>(fn: T, origOptions: Partial<Parameters<T>[0]>): T;
|
|
214
|
+
declare function configureSynced(origOptions: SyncedOptions): typeof synced;
|
|
217
215
|
|
|
218
216
|
declare function waitForSet(waitForSet: WaitForSet<any>, changes: Change[], value: any, params?: Record<string, any>): Promise<void>;
|
|
219
217
|
|
package/sync.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { ClassConstructor, NodeInfo, ObservableParam, GetMode, SetParams, Update
|
|
|
4
4
|
import { SyncedOptionsGlobal as SyncedOptionsGlobal$1 } from '@legendapp/state/sync';
|
|
5
5
|
|
|
6
6
|
interface PersistOptions<T = any> {
|
|
7
|
-
name
|
|
8
|
-
plugin?: ClassConstructor<ObservablePersistPlugin, T[]
|
|
7
|
+
name?: string;
|
|
8
|
+
plugin?: ClassConstructor<ObservablePersistPlugin, T[]> | ObservablePersistPlugin;
|
|
9
9
|
retrySync?: boolean;
|
|
10
10
|
transform?: SyncTransform<T>;
|
|
11
11
|
readonly?: boolean;
|
|
@@ -50,6 +50,7 @@ interface SyncedErrorParams {
|
|
|
50
50
|
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
51
|
source: 'get' | 'set' | 'subscribe';
|
|
52
52
|
value$: ObservableParam<any>;
|
|
53
|
+
retryParams?: OnErrorRetryParams;
|
|
53
54
|
}
|
|
54
55
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
55
56
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
@@ -61,18 +62,19 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
61
62
|
syncMode?: 'auto' | 'manual';
|
|
62
63
|
mode?: GetMode;
|
|
63
64
|
transform?: SyncTransform<TLocal, TRemote>;
|
|
64
|
-
onGetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
65
|
-
onSetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
66
65
|
onBeforeGet?: (params: {
|
|
67
66
|
value: TRemote;
|
|
68
67
|
lastSync: number | undefined;
|
|
69
68
|
pendingChanges: PendingChanges | undefined;
|
|
69
|
+
cancel: boolean;
|
|
70
70
|
clearPendingChanges: () => Promise<void>;
|
|
71
71
|
resetCache: () => Promise<void>;
|
|
72
72
|
}) => void;
|
|
73
|
-
onBeforeSet?: (
|
|
73
|
+
onBeforeSet?: (params: {
|
|
74
|
+
cancel: boolean;
|
|
75
|
+
}) => void;
|
|
74
76
|
onAfterSet?: () => void;
|
|
75
|
-
|
|
77
|
+
onError?: (error: Error, params: SyncedErrorParams) => void;
|
|
76
78
|
}
|
|
77
79
|
interface SyncedOptionsGlobal<T = any> extends Omit<SyncedOptions<T>, 'get' | 'set' | 'persist' | 'initial' | 'waitForSet' | 'waitFor' | 'transform' | 'subscribe'> {
|
|
78
80
|
persist?: ObservablePersistPluginOptions & Omit<PersistOptions, 'name' | 'transform' | 'options'>;
|
|
@@ -198,7 +200,7 @@ declare function transformStringifyDates<TRemote extends Record<string, any>, TL
|
|
|
198
200
|
declare function transformStringifyDates<TRemote extends Record<string, any>, Keys extends keyof TRemote = keyof TRemote>(...args: Keys[]): SyncTransform<TransformStringsToDates<TRemote, Keys>, TRemote>;
|
|
199
201
|
declare function transformStringifyDates<TRemote extends Record<string, any>, TLocal extends Record<string, any> = TRemote>(...args: (keyof TRemote)[]): SyncTransform<TRemote, TLocal>;
|
|
200
202
|
|
|
201
|
-
declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin
|
|
203
|
+
declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin> | ObservablePersistPlugin, {
|
|
202
204
|
plugin: ObservablePersistPlugin;
|
|
203
205
|
initialized: Observable<boolean>;
|
|
204
206
|
}>;
|
|
@@ -208,12 +210,8 @@ declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced
|
|
|
208
210
|
|
|
209
211
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
type RetType = typeof synced;
|
|
215
|
-
declare function configureSynced<T extends typeof synced>(fn: T, origOptions: SyncedOptionsConfigure): T;
|
|
216
|
-
declare function configureSynced(origOptions: SyncedOptionsConfigure): RetType;
|
|
213
|
+
declare function configureSynced<T extends (...args: any[]) => any>(fn: T, origOptions: Partial<Parameters<T>[0]>): T;
|
|
214
|
+
declare function configureSynced(origOptions: SyncedOptions): typeof synced;
|
|
217
215
|
|
|
218
216
|
declare function waitForSet(waitForSet: WaitForSet<any>, changes: Change[], value: any, params?: Record<string, any>): Promise<void>;
|
|
219
217
|
|