@legendapp/state 3.0.0-alpha.29 → 3.0.0-alpha.30
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/enable$GetSet.js +2 -1
- package/config/enable$GetSet.mjs +2 -1
- package/config/enableReactTracking.js +2 -1
- package/config/enableReactTracking.mjs +2 -1
- package/config/enableReactUse.js +2 -1
- package/config/enableReactUse.mjs +2 -1
- package/config/enable_PeekAssign.js +2 -1
- package/config/enable_PeekAssign.mjs +2 -1
- package/config.d.mts +13 -0
- package/config.d.ts +13 -0
- package/config.js +2052 -0
- package/config.mjs +2050 -0
- package/index.d.mts +5 -302
- package/index.d.ts +5 -302
- package/index.js +27 -142
- package/index.mjs +28 -141
- package/observableInterfaces-Dilj6F92.d.mts +282 -0
- package/observableInterfaces-Dilj6F92.d.ts +282 -0
- package/package.json +6 -1
- package/persist-plugins/async-storage.d.mts +6 -3
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +12 -4
- package/persist-plugins/async-storage.mjs +12 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +15 -5
- package/persist-plugins/indexeddb.mjs +15 -6
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +14 -5
- package/persist-plugins/mmkv.mjs +14 -6
- package/react.d.mts +1 -0
- package/react.d.ts +1 -0
- package/react.js +2 -2
- package/react.mjs +2 -2
- package/sync-plugins/crud.d.mts +1 -1
- package/sync-plugins/crud.d.ts +1 -1
- package/sync-plugins/fetch.js +12 -8
- package/sync-plugins/fetch.mjs +13 -9
- package/sync-plugins/keel.d.mts +2 -2
- package/sync-plugins/keel.d.ts +2 -2
- package/sync-plugins/keel.js +6 -6
- package/sync-plugins/keel.mjs +6 -6
- package/sync.d.mts +37 -19
- package/sync.d.ts +37 -19
- package/sync.js +143 -41
- package/sync.mjs +151 -50
package/persist-plugins/mmkv.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var symbolDefault = Symbol();
|
|
|
6
6
|
var MetadataSuffix = "__m";
|
|
7
7
|
var { safeParse, safeStringify } = internal;
|
|
8
8
|
var ObservablePersistMMKV = class {
|
|
9
|
-
constructor() {
|
|
9
|
+
constructor(configuration) {
|
|
10
10
|
this.data = {};
|
|
11
11
|
this.storages = /* @__PURE__ */ new Map([
|
|
12
12
|
[
|
|
@@ -16,6 +16,7 @@ var ObservablePersistMMKV = class {
|
|
|
16
16
|
})
|
|
17
17
|
]
|
|
18
18
|
]);
|
|
19
|
+
this.configuration = configuration;
|
|
19
20
|
}
|
|
20
21
|
// Gets
|
|
21
22
|
getTable(table, init, config) {
|
|
@@ -57,12 +58,12 @@ var ObservablePersistMMKV = class {
|
|
|
57
58
|
}
|
|
58
59
|
// Private
|
|
59
60
|
getStorage(config) {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
const key = JSON.stringify(
|
|
61
|
+
const configuration = config.mmkv || this.configuration;
|
|
62
|
+
if (configuration) {
|
|
63
|
+
const key = JSON.stringify(configuration);
|
|
63
64
|
let storage = this.storages.get(key);
|
|
64
65
|
if (!storage) {
|
|
65
|
-
storage = new MMKV(
|
|
66
|
+
storage = new MMKV(configuration);
|
|
66
67
|
this.storages.set(key, storage);
|
|
67
68
|
}
|
|
68
69
|
return storage;
|
|
@@ -88,5 +89,12 @@ var ObservablePersistMMKV = class {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
};
|
|
92
|
+
function configureObservablePersistMMKV(configuration) {
|
|
93
|
+
return class ObservablePersistMMKVConfigured extends ObservablePersistMMKV {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(configuration);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
|
|
92
|
-
export { ObservablePersistMMKV };
|
|
100
|
+
export { ObservablePersistMMKV, configureObservablePersistMMKV };
|
package/react.d.mts
CHANGED
package/react.d.ts
CHANGED
package/react.js
CHANGED
|
@@ -372,11 +372,11 @@ function configureReactive({
|
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
375
|
+
function Show({ if: if_, ifReady, else: else_, $value, wrap, children }) {
|
|
376
376
|
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
377
377
|
const show = ifReady !== void 0 ? state.isObservableValueReady(value) : value;
|
|
378
378
|
const child = useSelector(
|
|
379
|
-
show ? state.isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
379
|
+
show ? state.isFunction(children) ? () => children($value ? $value.get() : value) : children : else_ != null ? else_ : null,
|
|
380
380
|
{ skipCheck: true }
|
|
381
381
|
);
|
|
382
382
|
return wrap ? React.createElement(wrap, void 0, child) : child;
|
package/react.mjs
CHANGED
|
@@ -366,11 +366,11 @@ function configureReactive({
|
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
-
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
369
|
+
function Show({ if: if_, ifReady, else: else_, $value, wrap, children }) {
|
|
370
370
|
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
371
371
|
const show = ifReady !== void 0 ? isObservableValueReady(value) : value;
|
|
372
372
|
const child = useSelector(
|
|
373
|
-
show ? isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
373
|
+
show ? isFunction(children) ? () => children($value ? $value.get() : value) : children : else_ != null ? else_ : null,
|
|
374
374
|
{ skipCheck: true }
|
|
375
375
|
);
|
|
376
376
|
return wrap ? createElement(wrap, void 0, child) : child;
|
package/sync-plugins/crud.d.mts
CHANGED
|
@@ -22,7 +22,7 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
22
22
|
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe'> {
|
|
23
23
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
24
24
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
25
|
-
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<
|
|
25
|
+
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
26
26
|
onSaved?(params: SyncedCrudOnSavedParams<TRemote, TLocal>): Partial<TLocal> | void;
|
|
27
27
|
fieldId?: string;
|
|
28
28
|
fieldUpdatedAt?: string;
|
package/sync-plugins/crud.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
22
22
|
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe'> {
|
|
23
23
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
24
24
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
25
|
-
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<
|
|
25
|
+
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
26
26
|
onSaved?(params: SyncedCrudOnSavedParams<TRemote, TLocal>): Partial<TLocal> | void;
|
|
27
27
|
fieldId?: string;
|
|
28
28
|
fieldUpdatedAt?: string;
|
package/sync-plugins/fetch.js
CHANGED
|
@@ -18,15 +18,19 @@ function syncedFetch(props) {
|
|
|
18
18
|
} = props;
|
|
19
19
|
const get = async () => {
|
|
20
20
|
const url = state.computeSelector(getParam);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (url && state.isString(url)) {
|
|
22
|
+
const response = await fetch(url, getInit);
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(response.statusText);
|
|
25
|
+
}
|
|
26
|
+
let value = await response[valueType || "json"]();
|
|
27
|
+
if (transform == null ? void 0 : transform.load) {
|
|
28
|
+
value = transform == null ? void 0 : transform.load(value, "get");
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
} else {
|
|
32
|
+
return null;
|
|
28
33
|
}
|
|
29
|
-
return value;
|
|
30
34
|
};
|
|
31
35
|
let set = void 0;
|
|
32
36
|
if (setParam) {
|
package/sync-plugins/fetch.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computeSelector, getNodeValue } from '@legendapp/state';
|
|
1
|
+
import { computeSelector, isString, getNodeValue } from '@legendapp/state';
|
|
2
2
|
import { synced } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
// src/sync-plugins/fetch.ts
|
|
@@ -16,15 +16,19 @@ function syncedFetch(props) {
|
|
|
16
16
|
} = props;
|
|
17
17
|
const get = async () => {
|
|
18
18
|
const url = computeSelector(getParam);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (url && isString(url)) {
|
|
20
|
+
const response = await fetch(url, getInit);
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(response.statusText);
|
|
23
|
+
}
|
|
24
|
+
let value = await response[valueType || "json"]();
|
|
25
|
+
if (transform == null ? void 0 : transform.load) {
|
|
26
|
+
value = transform == null ? void 0 : transform.load(value, "get");
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
} else {
|
|
30
|
+
return null;
|
|
26
31
|
}
|
|
27
|
-
return value;
|
|
28
32
|
};
|
|
29
33
|
let set = void 0;
|
|
30
34
|
if (setParam) {
|
package/sync-plugins/keel.d.mts
CHANGED
|
@@ -45,8 +45,8 @@ interface KeelRealtimePlugin {
|
|
|
45
45
|
interface SyncedKeelConfiguration extends Omit<SyncedCrudPropsBase<any>, keyof SyncedOptions | 'create' | 'update' | 'delete' | 'onSaved' | 'updatePartial' | 'fieldCreatedAt' | 'fieldUpdatedAt' | 'generateId'> {
|
|
46
46
|
client: {
|
|
47
47
|
auth: {
|
|
48
|
-
refresh: () => Promise<boolean
|
|
49
|
-
isAuthenticated: () => Promise<boolean
|
|
48
|
+
refresh: () => Promise<APIResult<boolean>>;
|
|
49
|
+
isAuthenticated: () => Promise<APIResult<boolean>>;
|
|
50
50
|
};
|
|
51
51
|
api: {
|
|
52
52
|
queries: Record<string, (i: any) => Promise<any>>;
|
package/sync-plugins/keel.d.ts
CHANGED
|
@@ -45,8 +45,8 @@ interface KeelRealtimePlugin {
|
|
|
45
45
|
interface SyncedKeelConfiguration extends Omit<SyncedCrudPropsBase<any>, keyof SyncedOptions | 'create' | 'update' | 'delete' | 'onSaved' | 'updatePartial' | 'fieldCreatedAt' | 'fieldUpdatedAt' | 'generateId'> {
|
|
46
46
|
client: {
|
|
47
47
|
auth: {
|
|
48
|
-
refresh: () => Promise<boolean
|
|
49
|
-
isAuthenticated: () => Promise<boolean
|
|
48
|
+
refresh: () => Promise<APIResult<boolean>>;
|
|
49
|
+
isAuthenticated: () => Promise<APIResult<boolean>>;
|
|
50
50
|
};
|
|
51
51
|
api: {
|
|
52
52
|
queries: Record<string, (i: any) => Promise<any>>;
|
package/sync-plugins/keel.js
CHANGED
|
@@ -188,12 +188,12 @@ function syncedKeel(props) {
|
|
|
188
188
|
};
|
|
189
189
|
const handleSetError = async (error, params, input, fn, from) => {
|
|
190
190
|
var _a, _b, _c;
|
|
191
|
-
const { retryNum,
|
|
191
|
+
const { retryNum, update: update2 } = params;
|
|
192
192
|
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"))) {
|
|
193
193
|
if (__DEV__) {
|
|
194
194
|
console.log("Creating duplicate data already saved, just ignore.");
|
|
195
195
|
}
|
|
196
|
-
cancelRetry
|
|
196
|
+
params.cancelRetry = true;
|
|
197
197
|
update2({
|
|
198
198
|
value: {},
|
|
199
199
|
mode: "assign"
|
|
@@ -203,17 +203,17 @@ function syncedKeel(props) {
|
|
|
203
203
|
if (__DEV__) {
|
|
204
204
|
console.log("Deleting non-existing data, just ignore.");
|
|
205
205
|
}
|
|
206
|
-
cancelRetry
|
|
206
|
+
params.cancelRetry = true;
|
|
207
207
|
}
|
|
208
208
|
} else if (error.type === "bad_request") {
|
|
209
209
|
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, { error, params, input, type: from, action: fn.name || fn.toString() });
|
|
210
210
|
if (retryNum > 4) {
|
|
211
|
-
cancelRetry
|
|
211
|
+
params.cancelRetry = true;
|
|
212
212
|
}
|
|
213
|
-
throw new Error(error.message);
|
|
213
|
+
throw new Error(error.message, { cause: { input } });
|
|
214
214
|
} else {
|
|
215
215
|
await handleApiError(error);
|
|
216
|
-
throw new Error(error.message);
|
|
216
|
+
throw new Error(error.message, { cause: { input } });
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
const create = createParam ? async (input, params) => {
|
package/sync-plugins/keel.mjs
CHANGED
|
@@ -182,12 +182,12 @@ function syncedKeel(props) {
|
|
|
182
182
|
};
|
|
183
183
|
const handleSetError = async (error, params, input, fn, from) => {
|
|
184
184
|
var _a, _b, _c;
|
|
185
|
-
const { retryNum,
|
|
185
|
+
const { retryNum, update: update2 } = params;
|
|
186
186
|
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"))) {
|
|
187
187
|
if (__DEV__) {
|
|
188
188
|
console.log("Creating duplicate data already saved, just ignore.");
|
|
189
189
|
}
|
|
190
|
-
cancelRetry
|
|
190
|
+
params.cancelRetry = true;
|
|
191
191
|
update2({
|
|
192
192
|
value: {},
|
|
193
193
|
mode: "assign"
|
|
@@ -197,17 +197,17 @@ function syncedKeel(props) {
|
|
|
197
197
|
if (__DEV__) {
|
|
198
198
|
console.log("Deleting non-existing data, just ignore.");
|
|
199
199
|
}
|
|
200
|
-
cancelRetry
|
|
200
|
+
params.cancelRetry = true;
|
|
201
201
|
}
|
|
202
202
|
} else if (error.type === "bad_request") {
|
|
203
203
|
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, { error, params, input, type: from, action: fn.name || fn.toString() });
|
|
204
204
|
if (retryNum > 4) {
|
|
205
|
-
cancelRetry
|
|
205
|
+
params.cancelRetry = true;
|
|
206
206
|
}
|
|
207
|
-
throw new Error(error.message);
|
|
207
|
+
throw new Error(error.message, { cause: { input } });
|
|
208
208
|
} else {
|
|
209
209
|
await handleApiError(error);
|
|
210
|
-
throw new Error(error.message);
|
|
210
|
+
throw new Error(error.message, { cause: { input } });
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
213
|
const create = createParam ? async (input, params) => {
|
package/sync.d.mts
CHANGED
|
@@ -21,27 +21,36 @@ interface SyncedGetSetSubscribeBaseParams<T = any> {
|
|
|
21
21
|
value$: ObservableParam<T>;
|
|
22
22
|
refresh: () => void;
|
|
23
23
|
}
|
|
24
|
-
interface
|
|
24
|
+
interface SyncedGetSetBaseParams<T = any> extends SyncedGetSetSubscribeBaseParams<T>, OnErrorRetryParams {
|
|
25
|
+
}
|
|
26
|
+
interface OnErrorRetryParams {
|
|
27
|
+
retryNum: number;
|
|
28
|
+
cancelRetry: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SyncedGetParams<T> extends SyncedGetSetBaseParams<T> {
|
|
25
31
|
value: any;
|
|
26
32
|
lastSync: number | undefined;
|
|
27
33
|
updateLastSync: (lastSync: number) => void;
|
|
28
34
|
mode: GetMode;
|
|
29
|
-
retryNum: number;
|
|
30
|
-
cancelRetry: () => void;
|
|
31
35
|
onError: (error: Error) => void;
|
|
32
36
|
options: SyncedOptions;
|
|
33
37
|
}
|
|
34
|
-
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>,
|
|
38
|
+
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>, SyncedGetSetBaseParams<T> {
|
|
35
39
|
update: UpdateFn<T>;
|
|
36
|
-
|
|
37
|
-
retryNum: number;
|
|
38
|
-
onError: (error: Error) => void;
|
|
40
|
+
onError: (error: Error, retryParams: OnErrorRetryParams) => void;
|
|
39
41
|
}
|
|
40
42
|
interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams<T> {
|
|
41
43
|
lastSync: number | undefined;
|
|
42
44
|
update: UpdateFn<T>;
|
|
43
45
|
onError: (error: Error) => void;
|
|
44
46
|
}
|
|
47
|
+
interface SyncedErrorParams {
|
|
48
|
+
getParams?: SyncedGetParams<any>;
|
|
49
|
+
setParams?: SyncedSetParams<any>;
|
|
50
|
+
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
|
+
source: 'get' | 'set' | 'subscribe';
|
|
52
|
+
value$: ObservableParam<any>;
|
|
53
|
+
}
|
|
45
54
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
46
55
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
47
56
|
set?: (params: SyncedSetParams<TRemote>) => void | Promise<any>;
|
|
@@ -52,8 +61,8 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
52
61
|
syncMode?: 'auto' | 'manual';
|
|
53
62
|
mode?: GetMode;
|
|
54
63
|
transform?: SyncTransform<TLocal, TRemote>;
|
|
55
|
-
onGetError?: (error: Error,
|
|
56
|
-
onSetError?: (error: Error,
|
|
64
|
+
onGetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
65
|
+
onSetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
57
66
|
onBeforeGet?: (params: {
|
|
58
67
|
value: TRemote;
|
|
59
68
|
lastSync: number | undefined;
|
|
@@ -68,18 +77,20 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
68
77
|
interface SyncedOptionsGlobal<T = any> extends Omit<SyncedOptions<T>, 'get' | 'set' | 'persist' | 'initial' | 'waitForSet' | 'waitFor' | 'transform' | 'subscribe'> {
|
|
69
78
|
persist?: ObservablePersistPluginOptions & Omit<PersistOptions, 'name' | 'transform' | 'options'>;
|
|
70
79
|
}
|
|
80
|
+
interface ObservablePersistIndexedDBPluginOptions {
|
|
81
|
+
databaseName: string;
|
|
82
|
+
version: number;
|
|
83
|
+
tableNames: string[];
|
|
84
|
+
}
|
|
85
|
+
interface ObservablePersistAsyncStoragePluginOptions {
|
|
86
|
+
AsyncStorage: AsyncStorageStatic;
|
|
87
|
+
preload?: boolean | string[];
|
|
88
|
+
}
|
|
71
89
|
interface ObservablePersistPluginOptions {
|
|
72
90
|
onGetError?: (error: Error) => void;
|
|
73
91
|
onSetError?: (error: Error) => void;
|
|
74
|
-
indexedDB?:
|
|
75
|
-
|
|
76
|
-
version: number;
|
|
77
|
-
tableNames: string[];
|
|
78
|
-
};
|
|
79
|
-
asyncStorage?: {
|
|
80
|
-
AsyncStorage: AsyncStorageStatic;
|
|
81
|
-
preload?: boolean | string[];
|
|
82
|
-
};
|
|
92
|
+
indexedDB?: ObservablePersistIndexedDBPluginOptions;
|
|
93
|
+
asyncStorage?: ObservablePersistAsyncStoragePluginOptions;
|
|
83
94
|
}
|
|
84
95
|
interface ObservablePersistPlugin {
|
|
85
96
|
initialize?(config: ObservablePersistPluginOptions): void | Promise<void>;
|
|
@@ -197,8 +208,15 @@ declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced
|
|
|
197
208
|
|
|
198
209
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
199
210
|
|
|
211
|
+
interface SyncedOptionsConfigure extends Omit<SyncedOptions, 'persist'> {
|
|
212
|
+
persist?: Partial<PersistOptions<any>>;
|
|
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;
|
|
217
|
+
|
|
200
218
|
declare const internal: {
|
|
201
219
|
observableSyncConfiguration: SyncedOptionsGlobal;
|
|
202
220
|
};
|
|
203
221
|
|
|
204
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedGetParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
222
|
+
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 };
|
package/sync.d.ts
CHANGED
|
@@ -21,27 +21,36 @@ interface SyncedGetSetSubscribeBaseParams<T = any> {
|
|
|
21
21
|
value$: ObservableParam<T>;
|
|
22
22
|
refresh: () => void;
|
|
23
23
|
}
|
|
24
|
-
interface
|
|
24
|
+
interface SyncedGetSetBaseParams<T = any> extends SyncedGetSetSubscribeBaseParams<T>, OnErrorRetryParams {
|
|
25
|
+
}
|
|
26
|
+
interface OnErrorRetryParams {
|
|
27
|
+
retryNum: number;
|
|
28
|
+
cancelRetry: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SyncedGetParams<T> extends SyncedGetSetBaseParams<T> {
|
|
25
31
|
value: any;
|
|
26
32
|
lastSync: number | undefined;
|
|
27
33
|
updateLastSync: (lastSync: number) => void;
|
|
28
34
|
mode: GetMode;
|
|
29
|
-
retryNum: number;
|
|
30
|
-
cancelRetry: () => void;
|
|
31
35
|
onError: (error: Error) => void;
|
|
32
36
|
options: SyncedOptions;
|
|
33
37
|
}
|
|
34
|
-
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>,
|
|
38
|
+
interface SyncedSetParams<T> extends Pick<SetParams<T>, 'changes' | 'value'>, SyncedGetSetBaseParams<T> {
|
|
35
39
|
update: UpdateFn<T>;
|
|
36
|
-
|
|
37
|
-
retryNum: number;
|
|
38
|
-
onError: (error: Error) => void;
|
|
40
|
+
onError: (error: Error, retryParams: OnErrorRetryParams) => void;
|
|
39
41
|
}
|
|
40
42
|
interface SyncedSubscribeParams<T = any> extends SyncedGetSetSubscribeBaseParams<T> {
|
|
41
43
|
lastSync: number | undefined;
|
|
42
44
|
update: UpdateFn<T>;
|
|
43
45
|
onError: (error: Error) => void;
|
|
44
46
|
}
|
|
47
|
+
interface SyncedErrorParams {
|
|
48
|
+
getParams?: SyncedGetParams<any>;
|
|
49
|
+
setParams?: SyncedSetParams<any>;
|
|
50
|
+
subscribeParams?: SyncedSubscribeParams<any>;
|
|
51
|
+
source: 'get' | 'set' | 'subscribe';
|
|
52
|
+
value$: ObservableParam<any>;
|
|
53
|
+
}
|
|
45
54
|
interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOptions<TRemote>, 'get' | 'set'> {
|
|
46
55
|
get?: (params: SyncedGetParams<TRemote>) => Promise<TRemote> | TRemote;
|
|
47
56
|
set?: (params: SyncedSetParams<TRemote>) => void | Promise<any>;
|
|
@@ -52,8 +61,8 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
52
61
|
syncMode?: 'auto' | 'manual';
|
|
53
62
|
mode?: GetMode;
|
|
54
63
|
transform?: SyncTransform<TLocal, TRemote>;
|
|
55
|
-
onGetError?: (error: Error,
|
|
56
|
-
onSetError?: (error: Error,
|
|
64
|
+
onGetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
65
|
+
onSetError?: (error: Error, params: SyncedErrorParams) => void;
|
|
57
66
|
onBeforeGet?: (params: {
|
|
58
67
|
value: TRemote;
|
|
59
68
|
lastSync: number | undefined;
|
|
@@ -68,18 +77,20 @@ interface SyncedOptions<TRemote = any, TLocal = TRemote> extends Omit<LinkedOpti
|
|
|
68
77
|
interface SyncedOptionsGlobal<T = any> extends Omit<SyncedOptions<T>, 'get' | 'set' | 'persist' | 'initial' | 'waitForSet' | 'waitFor' | 'transform' | 'subscribe'> {
|
|
69
78
|
persist?: ObservablePersistPluginOptions & Omit<PersistOptions, 'name' | 'transform' | 'options'>;
|
|
70
79
|
}
|
|
80
|
+
interface ObservablePersistIndexedDBPluginOptions {
|
|
81
|
+
databaseName: string;
|
|
82
|
+
version: number;
|
|
83
|
+
tableNames: string[];
|
|
84
|
+
}
|
|
85
|
+
interface ObservablePersistAsyncStoragePluginOptions {
|
|
86
|
+
AsyncStorage: AsyncStorageStatic;
|
|
87
|
+
preload?: boolean | string[];
|
|
88
|
+
}
|
|
71
89
|
interface ObservablePersistPluginOptions {
|
|
72
90
|
onGetError?: (error: Error) => void;
|
|
73
91
|
onSetError?: (error: Error) => void;
|
|
74
|
-
indexedDB?:
|
|
75
|
-
|
|
76
|
-
version: number;
|
|
77
|
-
tableNames: string[];
|
|
78
|
-
};
|
|
79
|
-
asyncStorage?: {
|
|
80
|
-
AsyncStorage: AsyncStorageStatic;
|
|
81
|
-
preload?: boolean | string[];
|
|
82
|
-
};
|
|
92
|
+
indexedDB?: ObservablePersistIndexedDBPluginOptions;
|
|
93
|
+
asyncStorage?: ObservablePersistAsyncStoragePluginOptions;
|
|
83
94
|
}
|
|
84
95
|
interface ObservablePersistPlugin {
|
|
85
96
|
initialize?(config: ObservablePersistPluginOptions): void | Promise<void>;
|
|
@@ -197,8 +208,15 @@ declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced
|
|
|
197
208
|
|
|
198
209
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
199
210
|
|
|
211
|
+
interface SyncedOptionsConfigure extends Omit<SyncedOptions, 'persist'> {
|
|
212
|
+
persist?: Partial<PersistOptions<any>>;
|
|
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;
|
|
217
|
+
|
|
200
218
|
declare const internal: {
|
|
201
219
|
observableSyncConfiguration: SyncedOptionsGlobal;
|
|
202
220
|
};
|
|
203
221
|
|
|
204
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedGetParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
222
|
+
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 };
|