@legendapp/state 3.0.0-beta.3 → 3.0.0-beta.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/.DS_Store +0 -0
- 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 +33 -4
- package/index.d.ts +33 -4
- package/index.js +191 -29
- package/index.mjs +191 -29
- 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/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 +6 -0
- package/react-web.d.ts +6 -0
- package/react-web.js +39 -0
- package/react-web.mjs +37 -0
- package/react.d.mts +41 -21
- package/react.d.ts +41 -21
- package/react.js +36 -23
- package/react.mjs +37 -25
- package/sync-plugins/crud.d.mts +24 -9
- package/sync-plugins/crud.d.ts +24 -9
- package/sync-plugins/crud.js +250 -116
- package/sync-plugins/crud.mjs +251 -117
- package/sync-plugins/firebase.d.mts +7 -3
- package/sync-plugins/firebase.d.ts +7 -3
- package/sync-plugins/firebase.js +4 -2
- package/sync-plugins/firebase.mjs +4 -2
- 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 +7 -3
- package/sync-plugins/supabase.d.ts +7 -3
- 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.d.mts +16 -8
- package/sync.d.ts +16 -8
- package/sync.js +324 -215
- package/sync.mjs +323 -215
- 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/react.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, isEmpty, observable,
|
|
1
|
+
import { isFunction, isEmpty, observable, computeSelector, isArray, isMap, isObservableValueReady, linked, isPromise, observe, when, whenReady, internal, trackSelector, isPrimitive, isObservable } from '@legendapp/state';
|
|
2
2
|
import React, { memo, forwardRef, createElement, useState, useContext, useMemo, useRef, useEffect, createContext, useCallback } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
4
4
|
import { enableReactive } from '@legendapp/state/react-reactive/enableReactive';
|
|
@@ -39,6 +39,7 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
39
39
|
} = trackSelector(
|
|
40
40
|
_selector,
|
|
41
41
|
_update,
|
|
42
|
+
options,
|
|
42
43
|
void 0,
|
|
43
44
|
void 0,
|
|
44
45
|
/*createResubscribe*/
|
|
@@ -94,12 +95,24 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
94
95
|
}
|
|
95
96
|
};
|
|
96
97
|
}
|
|
98
|
+
function doSuspense(selector) {
|
|
99
|
+
const vProm = when(selector);
|
|
100
|
+
if (React.use) {
|
|
101
|
+
React.use(vProm);
|
|
102
|
+
} else {
|
|
103
|
+
throw vProm;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
97
106
|
function useSelector(selector, options) {
|
|
98
107
|
var _a;
|
|
108
|
+
let value;
|
|
99
109
|
if (reactGlobals.inObserver && isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
100
|
-
|
|
110
|
+
value = computeSelector(selector, options);
|
|
111
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
112
|
+
doSuspense(selector);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
101
115
|
}
|
|
102
|
-
let value;
|
|
103
116
|
try {
|
|
104
117
|
const isPaused$ = useContext(getPauseContext());
|
|
105
118
|
const selectorFn = useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
@@ -114,16 +127,8 @@ function useSelector(selector, options) {
|
|
|
114
127
|
}
|
|
115
128
|
throw err;
|
|
116
129
|
}
|
|
117
|
-
if (options == null ? void 0 : options.suspense) {
|
|
118
|
-
|
|
119
|
-
if (isPromise(value) || !value && isObservable(selector)) {
|
|
120
|
-
const vProm = isProm ? value : when(selector);
|
|
121
|
-
if (React.use) {
|
|
122
|
-
React.use(vProm);
|
|
123
|
-
} else {
|
|
124
|
-
throw vProm;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
130
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
131
|
+
doSuspense(selector);
|
|
127
132
|
}
|
|
128
133
|
return value;
|
|
129
134
|
}
|
|
@@ -134,7 +139,7 @@ function Computed({ children }) {
|
|
|
134
139
|
}
|
|
135
140
|
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
136
141
|
var didWarnProps = false;
|
|
137
|
-
function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
142
|
+
function createReactiveComponent(component, observe3, reactive2, keysReactive, bindKeys) {
|
|
138
143
|
const ReactForwardRefSymbol = hasSymbol ? Symbol.for("react.forward_ref") : (
|
|
139
144
|
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
140
145
|
typeof forwardRef === "function" && forwardRef((props) => null)["$$typeof"]
|
|
@@ -159,6 +164,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
159
164
|
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
160
165
|
}
|
|
161
166
|
}
|
|
167
|
+
const keysReactiveSet = keysReactive ? new Set(keysReactive) : void 0;
|
|
162
168
|
const proxyHandler = {
|
|
163
169
|
apply(target, thisArg, argArray) {
|
|
164
170
|
if (reactive2) {
|
|
@@ -168,9 +174,10 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
168
174
|
for (let i = 0; i < keys.length; i++) {
|
|
169
175
|
const key = keys[i];
|
|
170
176
|
const p = props[key];
|
|
177
|
+
const isReactiveKey = keysReactiveSet && keysReactiveSet.has(key);
|
|
171
178
|
if (key === "children" && (isFunction(p) || isObservable(p))) {
|
|
172
179
|
props[key] = useSelector(p, { skipCheck: true });
|
|
173
|
-
} else if (key.startsWith("$") || key.endsWith("$")) {
|
|
180
|
+
} else if (isReactiveKey || key.startsWith("$") || key.endsWith("$")) {
|
|
174
181
|
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
175
182
|
didWarnProps = true;
|
|
176
183
|
console.warn(
|
|
@@ -180,7 +187,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
180
187
|
)}. See https://legendapp.com/open-source/state/migrating for more details.`
|
|
181
188
|
);
|
|
182
189
|
}
|
|
183
|
-
const k = key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
190
|
+
const k = isReactiveKey ? key : key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
184
191
|
const bind = bindKeys == null ? void 0 : bindKeys[k];
|
|
185
192
|
const shouldBind = bind && isObservable(p);
|
|
186
193
|
propsOut[k] = shouldBind && (bind == null ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
@@ -198,7 +205,9 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
198
205
|
process.env.NODE_ENV === "development" ? handlerFn : useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
|
-
|
|
208
|
+
if (!isReactiveKey) {
|
|
209
|
+
delete propsOut[key];
|
|
210
|
+
}
|
|
202
211
|
} else if (propsOut[key] === void 0) {
|
|
203
212
|
propsOut[key] = p;
|
|
204
213
|
}
|
|
@@ -235,11 +244,11 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
235
244
|
function observer(component) {
|
|
236
245
|
return createReactiveComponent(component, true);
|
|
237
246
|
}
|
|
238
|
-
function reactive(component, bindKeys) {
|
|
239
|
-
return createReactiveComponent(component, false, true, bindKeys);
|
|
247
|
+
function reactive(component, keys, bindKeys) {
|
|
248
|
+
return createReactiveComponent(component, false, true, keys, bindKeys);
|
|
240
249
|
}
|
|
241
|
-
function reactiveObserver(component, bindKeys) {
|
|
242
|
-
return createReactiveComponent(component, true, true, bindKeys);
|
|
250
|
+
function reactiveObserver(component, keys, bindKeys) {
|
|
251
|
+
return createReactiveComponent(component, true, true, keys, bindKeys);
|
|
243
252
|
}
|
|
244
253
|
function reactiveComponents(components) {
|
|
245
254
|
return new Proxy(
|
|
@@ -330,7 +339,10 @@ function For({
|
|
|
330
339
|
}
|
|
331
340
|
return out;
|
|
332
341
|
}
|
|
333
|
-
var Memo = memo(
|
|
342
|
+
var Memo = memo(
|
|
343
|
+
Computed,
|
|
344
|
+
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
345
|
+
);
|
|
334
346
|
|
|
335
347
|
// src/react/configureReactive.ts
|
|
336
348
|
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
@@ -365,7 +377,7 @@ var Reactive = new Proxy(
|
|
|
365
377
|
}
|
|
366
378
|
return createElement(Component, propsOut);
|
|
367
379
|
});
|
|
368
|
-
target[p] = reactive(render, ReactiveFnBinders.get(p));
|
|
380
|
+
target[p] = reactive(render, [], ReactiveFnBinders.get(p));
|
|
369
381
|
}
|
|
370
382
|
return target[p];
|
|
371
383
|
}
|
|
@@ -510,7 +522,7 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
510
522
|
ref.current.reaction = reaction;
|
|
511
523
|
if (!ref.current.dispose) {
|
|
512
524
|
ref.current.dispose = observe(
|
|
513
|
-
(e) => computeSelector(ref.current.selector, e),
|
|
525
|
+
(e) => computeSelector(ref.current.selector, void 0, e),
|
|
514
526
|
(e) => {
|
|
515
527
|
var _a, _b;
|
|
516
528
|
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
@@ -560,4 +572,4 @@ function useWhenReady(predicate, effect) {
|
|
|
560
572
|
return useMemo(() => whenReady(predicate, effect), []);
|
|
561
573
|
}
|
|
562
574
|
|
|
563
|
-
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
|
575
|
+
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useSelector as use$, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/sync-plugins/crud.d.mts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
-
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
|
+
import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
8
|
-
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
14
|
+
list?: never | undefined;
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
9
16
|
as?: never | 'value';
|
|
10
17
|
}
|
|
11
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
20
|
+
get?: never | undefined;
|
|
13
21
|
as?: TAsOption;
|
|
14
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
15
23
|
}
|
|
16
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
17
25
|
saved: TLocal;
|
|
@@ -23,7 +31,11 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
23
31
|
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
32
|
type: 'create' | 'update' | 'delete';
|
|
25
33
|
}
|
|
26
|
-
interface
|
|
34
|
+
interface CrudErrorParams extends Omit<SyncedErrorParams, 'source'> {
|
|
35
|
+
source: 'list' | 'get' | 'create' | 'update' | 'delete' | 'unknown';
|
|
36
|
+
}
|
|
37
|
+
type CrudOnErrorFn = (error: Error, params: CrudErrorParams) => void;
|
|
38
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet' | 'onError'> {
|
|
27
39
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
40
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
41
|
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
@@ -38,6 +50,7 @@ interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends
|
|
|
38
50
|
generateId?: () => string | number;
|
|
39
51
|
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
52
|
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
53
|
+
onError?: (error: Error, params: CrudErrorParams) => void;
|
|
41
54
|
}
|
|
42
55
|
type InitialValue<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<string | number, TLocal> : TAsOption extends 'object' ? Record<string | number, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
43
56
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -45,7 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
45
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
46
59
|
id: number;
|
|
47
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
48
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props:
|
|
49
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
62
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
63
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
64
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
50
65
|
|
|
51
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
package/sync-plugins/crud.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
-
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
|
+
import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
8
|
-
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
14
|
+
list?: never | undefined;
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
9
16
|
as?: never | 'value';
|
|
10
17
|
}
|
|
11
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
20
|
+
get?: never | undefined;
|
|
13
21
|
as?: TAsOption;
|
|
14
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
15
23
|
}
|
|
16
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
17
25
|
saved: TLocal;
|
|
@@ -23,7 +31,11 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
23
31
|
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
32
|
type: 'create' | 'update' | 'delete';
|
|
25
33
|
}
|
|
26
|
-
interface
|
|
34
|
+
interface CrudErrorParams extends Omit<SyncedErrorParams, 'source'> {
|
|
35
|
+
source: 'list' | 'get' | 'create' | 'update' | 'delete' | 'unknown';
|
|
36
|
+
}
|
|
37
|
+
type CrudOnErrorFn = (error: Error, params: CrudErrorParams) => void;
|
|
38
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet' | 'onError'> {
|
|
27
39
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
40
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
41
|
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
@@ -38,6 +50,7 @@ interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends
|
|
|
38
50
|
generateId?: () => string | number;
|
|
39
51
|
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
52
|
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
53
|
+
onError?: (error: Error, params: CrudErrorParams) => void;
|
|
41
54
|
}
|
|
42
55
|
type InitialValue<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<string | number, TLocal> : TAsOption extends 'object' ? Record<string | number, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
43
56
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -45,7 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
45
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
46
59
|
id: number;
|
|
47
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
48
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props:
|
|
49
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
62
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
63
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
64
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
50
65
|
|
|
51
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|