@legendapp/state 3.0.0-alpha.9 → 3.0.0-beta.0
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/configureLegendState.d.mts +13 -0
- package/config/configureLegendState.d.ts +13 -0
- package/config/configureLegendState.js +45 -0
- package/config/configureLegendState.mjs +43 -0
- 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/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +103 -79
- package/index.d.ts +103 -79
- package/index.js +326 -316
- package/index.mjs +323 -314
- package/package.json +36 -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 +8 -4
- package/persist-plugins/async-storage.mjs +8 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +35 -15
- package/persist-plugins/indexeddb.mjs +35 -16
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +10 -5
- package/persist-plugins/mmkv.mjs +10 -6
- package/react-reactive/enableReactComponents.d.mts +9 -0
- package/react-reactive/enableReactComponents.d.ts +9 -0
- package/react-reactive/enableReactComponents.js +19 -0
- package/react-reactive/enableReactComponents.mjs +17 -0
- package/react-reactive/enableReactNativeComponents.d.mts +22 -0
- package/react-reactive/enableReactNativeComponents.d.ts +22 -0
- package/react-reactive/enableReactNativeComponents.js +53 -0
- package/react-reactive/enableReactNativeComponents.mjs +51 -0
- package/react-reactive/enableReactive.d.mts +5 -0
- package/react-reactive/enableReactive.d.ts +5 -0
- package/react-reactive/enableReactive.js +24 -0
- package/react-reactive/enableReactive.mjs +22 -0
- package/react-reactive/enableReactive.native.d.mts +5 -0
- package/react-reactive/enableReactive.native.d.ts +5 -0
- package/react-reactive/enableReactive.native.js +58 -0
- package/react-reactive/enableReactive.native.mjs +56 -0
- package/react-reactive/enableReactive.web.d.mts +5 -0
- package/react-reactive/enableReactive.web.d.ts +5 -0
- package/react-reactive/enableReactive.web.js +58 -0
- package/react-reactive/enableReactive.web.mjs +56 -0
- package/react.d.mts +39 -34
- package/react.d.ts +39 -34
- package/react.js +39 -17
- package/react.mjs +39 -17
- package/sync-plugins/crud.d.mts +21 -23
- package/sync-plugins/crud.d.ts +21 -23
- package/sync-plugins/crud.js +224 -112
- package/sync-plugins/crud.mjs +226 -114
- package/sync-plugins/fetch.js +12 -8
- package/sync-plugins/fetch.mjs +13 -9
- package/sync-plugins/firebase.d.mts +27 -0
- package/sync-plugins/firebase.d.ts +27 -0
- package/sync-plugins/firebase.js +373 -0
- package/sync-plugins/firebase.mjs +368 -0
- package/sync-plugins/keel.d.mts +43 -26
- package/sync-plugins/keel.d.ts +43 -26
- package/sync-plugins/keel.js +145 -99
- package/sync-plugins/keel.mjs +147 -99
- package/sync-plugins/supabase.d.mts +19 -9
- package/sync-plugins/supabase.d.ts +19 -9
- package/sync-plugins/supabase.js +52 -21
- package/sync-plugins/supabase.mjs +53 -22
- package/sync-plugins/tanstack-query.d.mts +2 -2
- package/sync-plugins/tanstack-query.d.ts +2 -2
- package/sync-plugins/tanstack-query.js +22 -5
- package/sync-plugins/tanstack-query.mjs +22 -5
- package/sync-plugins/tanstack-react-query.d.mts +1 -1
- package/sync-plugins/tanstack-react-query.d.ts +1 -1
- package/sync-plugins/tanstack-react-query.js +8 -1
- package/sync-plugins/tanstack-react-query.mjs +8 -1
- package/sync.d.mts +74 -200
- package/sync.d.ts +74 -200
- package/sync.js +495 -281
- package/sync.mjs +500 -286
package/react.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var state = require('@legendapp/state');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var index_js = require('use-sync-external-store/shim/index.js');
|
|
6
|
+
var enableReactive = require('@legendapp/state/react-reactive/enableReactive');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
@@ -336,8 +337,27 @@ function For({
|
|
|
336
337
|
return out;
|
|
337
338
|
}
|
|
338
339
|
var Memo = React.memo(Computed, () => true);
|
|
340
|
+
|
|
341
|
+
// src/react/configureReactive.ts
|
|
339
342
|
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
340
343
|
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
344
|
+
function configureReactive({
|
|
345
|
+
components,
|
|
346
|
+
binders
|
|
347
|
+
}) {
|
|
348
|
+
if (components) {
|
|
349
|
+
for (const key in components) {
|
|
350
|
+
ReactiveFns.set(key, components[key]);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (binders) {
|
|
354
|
+
for (const key in binders) {
|
|
355
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/react/Reactive.tsx
|
|
341
361
|
var Reactive = new Proxy(
|
|
342
362
|
{},
|
|
343
363
|
{
|
|
@@ -357,26 +377,14 @@ var Reactive = new Proxy(
|
|
|
357
377
|
}
|
|
358
378
|
}
|
|
359
379
|
);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
binders
|
|
363
|
-
}) {
|
|
364
|
-
if (components) {
|
|
365
|
-
for (const key in components) {
|
|
366
|
-
ReactiveFns.set(key, components[key]);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (binders) {
|
|
370
|
-
for (const key in binders) {
|
|
371
|
-
ReactiveFnBinders.set(key, binders[key]);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
380
|
+
if (process.env.NODE_ENV !== "test") {
|
|
381
|
+
enableReactive.enableReactive(configureReactive);
|
|
374
382
|
}
|
|
375
|
-
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
383
|
+
function Show({ if: if_, ifReady, else: else_, $value, wrap, children }) {
|
|
376
384
|
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
377
385
|
const show = ifReady !== void 0 ? state.isObservableValueReady(value) : value;
|
|
378
386
|
const child = useSelector(
|
|
379
|
-
show ? state.isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
387
|
+
show ? state.isFunction(children) ? () => children($value ? $value.get() : value) : children : else_ != null ? else_ : null,
|
|
380
388
|
{ skipCheck: true }
|
|
381
389
|
);
|
|
382
390
|
return wrap ? React.createElement(wrap, void 0, child) : child;
|
|
@@ -495,8 +503,16 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
495
503
|
} else {
|
|
496
504
|
options = reactionOrOptions;
|
|
497
505
|
}
|
|
506
|
+
const deps = options == null ? void 0 : options.deps;
|
|
507
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
508
|
+
if (depsObs$) {
|
|
509
|
+
depsObs$.set(deps);
|
|
510
|
+
}
|
|
498
511
|
const ref = React.useRef({});
|
|
499
|
-
ref.current.selector =
|
|
512
|
+
ref.current.selector = deps ? () => {
|
|
513
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
514
|
+
return state.computeSelector(selector);
|
|
515
|
+
} : selector;
|
|
500
516
|
ref.current.reaction = reaction;
|
|
501
517
|
if (!ref.current.dispose) {
|
|
502
518
|
ref.current.dispose = state.observe(
|
|
@@ -521,12 +537,18 @@ function useObserveEffect(selector, reactionOrOptions, options) {
|
|
|
521
537
|
} else {
|
|
522
538
|
options = reactionOrOptions;
|
|
523
539
|
}
|
|
540
|
+
const deps = options == null ? void 0 : options.deps;
|
|
541
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
542
|
+
if (depsObs$) {
|
|
543
|
+
depsObs$.set(deps);
|
|
544
|
+
}
|
|
524
545
|
const ref = React.useRef({ selector });
|
|
525
546
|
ref.current = { selector, reaction };
|
|
526
547
|
useMountOnce(
|
|
527
548
|
() => state.observe(
|
|
528
549
|
(e) => {
|
|
529
550
|
const { selector: selector2 } = ref.current;
|
|
551
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
530
552
|
return state.isFunction(selector2) ? selector2(e) : selector2;
|
|
531
553
|
},
|
|
532
554
|
(e) => {
|
package/react.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isFunction, isEmpty, observable, isPromise, isObservable, when, computeSelector, isArray, isMap, isObservableValueReady, linked, observe, whenReady, internal, trackSelector, isPrimitive } 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
|
+
import { enableReactive } from '@legendapp/state/react-reactive/enableReactive';
|
|
4
5
|
|
|
5
6
|
// src/react/Computed.tsx
|
|
6
7
|
|
|
@@ -330,8 +331,27 @@ function For({
|
|
|
330
331
|
return out;
|
|
331
332
|
}
|
|
332
333
|
var Memo = memo(Computed, () => true);
|
|
334
|
+
|
|
335
|
+
// src/react/configureReactive.ts
|
|
333
336
|
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
334
337
|
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
338
|
+
function configureReactive({
|
|
339
|
+
components,
|
|
340
|
+
binders
|
|
341
|
+
}) {
|
|
342
|
+
if (components) {
|
|
343
|
+
for (const key in components) {
|
|
344
|
+
ReactiveFns.set(key, components[key]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (binders) {
|
|
348
|
+
for (const key in binders) {
|
|
349
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/react/Reactive.tsx
|
|
335
355
|
var Reactive = new Proxy(
|
|
336
356
|
{},
|
|
337
357
|
{
|
|
@@ -351,26 +371,14 @@ var Reactive = new Proxy(
|
|
|
351
371
|
}
|
|
352
372
|
}
|
|
353
373
|
);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
binders
|
|
357
|
-
}) {
|
|
358
|
-
if (components) {
|
|
359
|
-
for (const key in components) {
|
|
360
|
-
ReactiveFns.set(key, components[key]);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (binders) {
|
|
364
|
-
for (const key in binders) {
|
|
365
|
-
ReactiveFnBinders.set(key, binders[key]);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
374
|
+
if (process.env.NODE_ENV !== "test") {
|
|
375
|
+
enableReactive(configureReactive);
|
|
368
376
|
}
|
|
369
|
-
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
377
|
+
function Show({ if: if_, ifReady, else: else_, $value, wrap, children }) {
|
|
370
378
|
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
371
379
|
const show = ifReady !== void 0 ? isObservableValueReady(value) : value;
|
|
372
380
|
const child = useSelector(
|
|
373
|
-
show ? isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
381
|
+
show ? isFunction(children) ? () => children($value ? $value.get() : value) : children : else_ != null ? else_ : null,
|
|
374
382
|
{ skipCheck: true }
|
|
375
383
|
);
|
|
376
384
|
return wrap ? createElement(wrap, void 0, child) : child;
|
|
@@ -489,8 +497,16 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
489
497
|
} else {
|
|
490
498
|
options = reactionOrOptions;
|
|
491
499
|
}
|
|
500
|
+
const deps = options == null ? void 0 : options.deps;
|
|
501
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
502
|
+
if (depsObs$) {
|
|
503
|
+
depsObs$.set(deps);
|
|
504
|
+
}
|
|
492
505
|
const ref = useRef({});
|
|
493
|
-
ref.current.selector =
|
|
506
|
+
ref.current.selector = deps ? () => {
|
|
507
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
508
|
+
return computeSelector(selector);
|
|
509
|
+
} : selector;
|
|
494
510
|
ref.current.reaction = reaction;
|
|
495
511
|
if (!ref.current.dispose) {
|
|
496
512
|
ref.current.dispose = observe(
|
|
@@ -515,12 +531,18 @@ function useObserveEffect(selector, reactionOrOptions, options) {
|
|
|
515
531
|
} else {
|
|
516
532
|
options = reactionOrOptions;
|
|
517
533
|
}
|
|
534
|
+
const deps = options == null ? void 0 : options.deps;
|
|
535
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
536
|
+
if (depsObs$) {
|
|
537
|
+
depsObs$.set(deps);
|
|
538
|
+
}
|
|
518
539
|
const ref = useRef({ selector });
|
|
519
540
|
ref.current = { selector, reaction };
|
|
520
541
|
useMountOnce(
|
|
521
542
|
() => observe(
|
|
522
543
|
(e) => {
|
|
523
544
|
const { selector: selector2 } = ref.current;
|
|
545
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
524
546
|
return isFunction(selector2) ? selector2(e) : selector2;
|
|
525
547
|
},
|
|
526
548
|
(e) => {
|
package/sync-plugins/crud.d.mts
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
+
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
3
|
|
|
3
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
4
5
|
type CrudResult<T> = T;
|
|
5
|
-
interface SyncedCrudPropsSingle<TRemote, TLocal> {
|
|
6
|
-
get?: (params: SyncedGetParams) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
6
|
+
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
+
get?: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
7
8
|
initial?: InitialValue<TLocal, 'value'>;
|
|
8
9
|
as?: never | 'value';
|
|
9
10
|
}
|
|
10
|
-
interface SyncedCrudPropsMany<TRemote, TLocal, TAsOption extends CrudAsOption> {
|
|
11
|
-
list?: (params: SyncedGetParams) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
11
|
+
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
+
list?: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
12
13
|
as?: TAsOption;
|
|
13
14
|
initial?: InitialValue<TLocal, TAsOption>;
|
|
14
15
|
}
|
|
15
|
-
interface SyncedCrudOnSavedParams<TRemote extends {
|
|
16
|
-
id: string | number;
|
|
17
|
-
}, TLocal> {
|
|
16
|
+
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
18
17
|
saved: TLocal;
|
|
19
18
|
input: TRemote;
|
|
20
19
|
currentValue: TLocal;
|
|
21
20
|
isCreate: boolean;
|
|
22
21
|
props: SyncedCrudPropsBase<TRemote, TLocal>;
|
|
23
22
|
}
|
|
24
|
-
interface
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, params: SyncedSetParams<TRemote>): Promise<CrudResult<any>>;
|
|
23
|
+
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
|
+
type: 'create' | 'update' | 'delete';
|
|
25
|
+
}
|
|
26
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet'> {
|
|
27
|
+
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
|
+
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
|
+
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
32
30
|
onSaved?(params: SyncedCrudOnSavedParams<TRemote, TLocal>): Partial<TLocal> | void;
|
|
31
|
+
fieldId?: string;
|
|
33
32
|
fieldUpdatedAt?: string;
|
|
34
33
|
fieldCreatedAt?: string;
|
|
35
34
|
fieldDeleted?: string;
|
|
35
|
+
fieldDeletedList?: string;
|
|
36
36
|
updatePartial?: boolean;
|
|
37
37
|
changesSince?: 'all' | 'last-sync';
|
|
38
38
|
generateId?: () => string | number;
|
|
39
|
+
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
|
+
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
39
41
|
}
|
|
40
42
|
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[];
|
|
41
43
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -43,11 +45,7 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
43
45
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
44
46
|
id: number;
|
|
45
47
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
46
|
-
declare function syncedCrud<TRemote extends
|
|
47
|
-
|
|
48
|
-
}, TLocal = TRemote>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsSingle<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
49
|
-
declare function syncedCrud<TRemote extends {
|
|
50
|
-
id: string | number;
|
|
51
|
-
}, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsMany<TRemote, TLocal, TAsOption>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
48
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsSingle<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
49
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsMany<TRemote, TLocal, TAsOption>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
52
50
|
|
|
53
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, syncedCrud };
|
|
51
|
+
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
package/sync-plugins/crud.d.ts
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
+
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
3
|
|
|
3
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
4
5
|
type CrudResult<T> = T;
|
|
5
|
-
interface SyncedCrudPropsSingle<TRemote, TLocal> {
|
|
6
|
-
get?: (params: SyncedGetParams) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
6
|
+
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
+
get?: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
7
8
|
initial?: InitialValue<TLocal, 'value'>;
|
|
8
9
|
as?: never | 'value';
|
|
9
10
|
}
|
|
10
|
-
interface SyncedCrudPropsMany<TRemote, TLocal, TAsOption extends CrudAsOption> {
|
|
11
|
-
list?: (params: SyncedGetParams) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
11
|
+
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
+
list?: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
12
13
|
as?: TAsOption;
|
|
13
14
|
initial?: InitialValue<TLocal, TAsOption>;
|
|
14
15
|
}
|
|
15
|
-
interface SyncedCrudOnSavedParams<TRemote extends {
|
|
16
|
-
id: string | number;
|
|
17
|
-
}, TLocal> {
|
|
16
|
+
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
18
17
|
saved: TLocal;
|
|
19
18
|
input: TRemote;
|
|
20
19
|
currentValue: TLocal;
|
|
21
20
|
isCreate: boolean;
|
|
22
21
|
props: SyncedCrudPropsBase<TRemote, TLocal>;
|
|
23
22
|
}
|
|
24
|
-
interface
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, params: SyncedSetParams<TRemote>): Promise<CrudResult<any>>;
|
|
23
|
+
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
|
+
type: 'create' | 'update' | 'delete';
|
|
25
|
+
}
|
|
26
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet'> {
|
|
27
|
+
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
|
+
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
|
+
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
32
30
|
onSaved?(params: SyncedCrudOnSavedParams<TRemote, TLocal>): Partial<TLocal> | void;
|
|
31
|
+
fieldId?: string;
|
|
33
32
|
fieldUpdatedAt?: string;
|
|
34
33
|
fieldCreatedAt?: string;
|
|
35
34
|
fieldDeleted?: string;
|
|
35
|
+
fieldDeletedList?: string;
|
|
36
36
|
updatePartial?: boolean;
|
|
37
37
|
changesSince?: 'all' | 'last-sync';
|
|
38
38
|
generateId?: () => string | number;
|
|
39
|
+
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
|
+
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
39
41
|
}
|
|
40
42
|
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[];
|
|
41
43
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -43,11 +45,7 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
43
45
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
44
46
|
id: number;
|
|
45
47
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
46
|
-
declare function syncedCrud<TRemote extends
|
|
47
|
-
|
|
48
|
-
}, TLocal = TRemote>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsSingle<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
49
|
-
declare function syncedCrud<TRemote extends {
|
|
50
|
-
id: string | number;
|
|
51
|
-
}, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsMany<TRemote, TLocal, TAsOption>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
48
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsSingle<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
49
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsBase<TRemote, TLocal> & SyncedCrudPropsMany<TRemote, TLocal, TAsOption>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
52
50
|
|
|
53
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, syncedCrud };
|
|
51
|
+
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|