@legendapp/state 3.0.0-alpha.1 → 3.0.0-alpha.3
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/CHANGELOG.md +1 -831
- package/LICENSE +1 -21
- package/README.md +1 -141
- package/as/arrayAsRecord.d.mts +5 -0
- package/as/arrayAsRecord.d.ts +5 -0
- package/as/arrayAsRecord.js +28 -0
- package/as/arrayAsRecord.mjs +26 -0
- package/as/arrayAsSet.d.mts +5 -0
- package/as/arrayAsSet.d.ts +5 -0
- package/as/arrayAsSet.js +13 -0
- package/as/arrayAsSet.mjs +11 -0
- package/as/arrayAsString.d.mts +5 -0
- package/as/arrayAsString.d.ts +5 -0
- package/as/arrayAsString.js +13 -0
- package/as/arrayAsString.mjs +11 -0
- package/as/numberAsString.d.mts +5 -0
- package/as/numberAsString.d.ts +5 -0
- package/as/numberAsString.js +13 -0
- package/as/numberAsString.mjs +11 -0
- package/as/recordAsArray.d.mts +5 -0
- package/as/recordAsArray.d.ts +5 -0
- package/as/recordAsArray.js +25 -0
- package/as/recordAsArray.mjs +23 -0
- package/as/recordAsString.d.mts +5 -0
- package/as/recordAsString.d.ts +5 -0
- package/as/recordAsString.js +13 -0
- package/as/recordAsString.mjs +11 -0
- package/as/setAsArray.d.mts +5 -0
- package/as/setAsArray.d.ts +5 -0
- package/as/setAsArray.js +13 -0
- package/as/setAsArray.mjs +11 -0
- package/as/setAsString.d.mts +5 -0
- package/as/setAsString.d.ts +5 -0
- package/as/setAsString.js +13 -0
- package/as/setAsString.mjs +11 -0
- package/as/stringAsArray.d.mts +5 -0
- package/as/stringAsArray.d.ts +5 -0
- package/as/stringAsArray.js +13 -0
- package/as/stringAsArray.mjs +11 -0
- package/as/stringAsNumber.d.mts +5 -0
- package/as/stringAsNumber.d.ts +5 -0
- package/as/stringAsNumber.js +16 -0
- package/as/stringAsNumber.mjs +14 -0
- package/as/stringAsRecord.d.mts +5 -0
- package/as/stringAsRecord.d.ts +5 -0
- package/as/stringAsRecord.js +15 -0
- package/as/stringAsRecord.mjs +13 -0
- package/as/stringAsSet.d.mts +5 -0
- package/as/stringAsSet.d.ts +5 -0
- package/as/stringAsSet.js +13 -0
- package/as/stringAsSet.mjs +11 -0
- package/babel.d.mts +21 -0
- package/babel.d.ts +21 -2
- package/babel.js +57 -53
- package/babel.mjs +65 -0
- package/config/enable$GetSet.js +13 -14
- package/config/enable$GetSet.mjs +13 -14
- package/config/enableReactComponents.d.mts +9 -0
- package/config/enableReactComponents.d.ts +4 -2
- package/config/enableReactComponents.js +13 -10
- package/config/enableReactComponents.mjs +13 -10
- package/config/enableReactNativeComponents.d.mts +22 -0
- package/config/enableReactNativeComponents.d.ts +6 -4
- package/config/enableReactNativeComponents.js +43 -47
- package/config/enableReactNativeComponents.mjs +43 -47
- package/config/enableReactTracking.d.mts +7 -0
- package/config/enableReactTracking.d.ts +3 -2
- package/config/enableReactTracking.js +33 -38
- package/config/enableReactTracking.mjs +33 -38
- package/config/enableReactUse.d.mts +10 -0
- package/config/enableReactUse.d.ts +4 -1
- package/config/enableReactUse.js +15 -14
- package/config/enableReactUse.mjs +15 -14
- package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
- package/config/enable_GetSet.d.ts +10 -0
- package/config/enable_PeekAssign.d.mts +10 -0
- package/config/enable_PeekAssign.d.ts +4 -2
- package/config/enable_PeekAssign.js +13 -14
- package/config/enable_PeekAssign.mjs +13 -14
- package/helpers/pageHash.d.mts +9 -0
- package/helpers/pageHash.d.ts +2 -0
- package/helpers/pageHash.js +25 -30
- package/helpers/pageHash.mjs +25 -30
- package/helpers/pageHashParams.d.mts +9 -0
- package/helpers/pageHashParams.d.ts +2 -0
- package/helpers/pageHashParams.js +34 -37
- package/helpers/pageHashParams.mjs +34 -37
- package/helpers/time.d.mts +6 -0
- package/helpers/time.d.ts +6 -3
- package/helpers/time.js +17 -17
- package/helpers/time.mjs +17 -17
- package/helpers/trackHistory.d.mts +6 -0
- package/helpers/trackHistory.d.ts +4 -2
- package/helpers/trackHistory.js +13 -16
- package/helpers/trackHistory.mjs +13 -16
- package/helpers/undoRedo.d.mts +37 -0
- package/helpers/undoRedo.d.ts +5 -3
- package/helpers/undoRedo.js +59 -94
- package/helpers/undoRedo.mjs +59 -94
- package/index.d.mts +404 -0
- package/index.d.ts +371 -28
- package/index.js +2015 -2166
- package/index.mjs +2015 -2166
- package/package.json +254 -195
- package/persist-plugins/async-storage.d.mts +18 -0
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +79 -86
- package/persist-plugins/async-storage.mjs +79 -86
- package/persist-plugins/indexeddb.d.mts +29 -0
- package/persist-plugins/indexeddb.d.ts +6 -3
- package/persist-plugins/indexeddb.js +331 -352
- package/persist-plugins/indexeddb.mjs +331 -352
- package/persist-plugins/local-storage.d.mts +23 -0
- package/persist-plugins/local-storage.d.ts +8 -5
- package/persist-plugins/local-storage.js +74 -76
- package/persist-plugins/local-storage.mjs +74 -76
- package/persist-plugins/mmkv.d.mts +18 -0
- package/persist-plugins/mmkv.d.ts +6 -3
- package/persist-plugins/mmkv.js +82 -86
- package/persist-plugins/mmkv.mjs +82 -86
- package/react-hooks/createObservableHook.d.mts +5 -0
- package/react-hooks/createObservableHook.d.ts +4 -1
- package/react-hooks/createObservableHook.js +29 -30
- package/react-hooks/createObservableHook.mjs +25 -30
- package/react-hooks/useHover.d.mts +5 -0
- package/react-hooks/useHover.d.ts +5 -3
- package/react-hooks/useHover.js +29 -29
- package/react-hooks/useHover.mjs +29 -29
- package/react-hooks/useMeasure.d.mts +9 -0
- package/react-hooks/useMeasure.d.ts +5 -2
- package/react-hooks/useMeasure.js +30 -32
- package/react-hooks/useMeasure.mjs +30 -32
- package/react-hooks/useObservableNextRouter.d.mts +35 -0
- package/react-hooks/useObservableNextRouter.d.ts +9 -7
- package/react-hooks/useObservableNextRouter.js +64 -77
- package/react-hooks/useObservableNextRouter.mjs +60 -77
- package/react.d.mts +157 -0
- package/react.d.ts +157 -21
- package/react.js +458 -749
- package/react.mjs +457 -752
- package/sync-plugins/crud.d.mts +54 -0
- package/sync-plugins/crud.d.ts +12 -10
- package/sync-plugins/crud.js +253 -270
- package/sync-plugins/crud.mjs +253 -270
- package/sync-plugins/fetch.d.mts +21 -0
- package/sync-plugins/fetch.d.ts +7 -4
- package/sync-plugins/fetch.js +50 -37
- package/sync-plugins/fetch.mjs +50 -37
- package/sync-plugins/keel.d.mts +108 -0
- package/sync-plugins/keel.d.ts +17 -15
- package/sync-plugins/keel.js +229 -462
- package/sync-plugins/keel.mjs +227 -464
- package/sync-plugins/supabase.d.mts +39 -0
- package/sync-plugins/supabase.d.ts +16 -14
- package/sync-plugins/supabase.js +128 -128
- package/sync-plugins/supabase.mjs +128 -128
- package/sync-plugins/tanstack-query.d.mts +14 -0
- package/sync-plugins/tanstack-query.d.ts +7 -4
- package/sync-plugins/tanstack-query.js +51 -57
- package/sync-plugins/tanstack-query.mjs +51 -57
- package/sync-plugins/tanstack-react-query.d.mts +8 -0
- package/sync-plugins/tanstack-react-query.d.ts +6 -1
- package/sync-plugins/tanstack-react-query.js +2 -2
- package/sync-plugins/tanstack-react-query.mjs +2 -2
- package/sync.d.mts +351 -0
- package/sync.d.ts +349 -9
- package/sync.js +910 -964
- package/sync.mjs +920 -974
- package/trace.d.mts +9 -0
- package/trace.d.ts +9 -4
- package/trace.js +72 -62
- package/trace.mjs +72 -62
- package/types/babel.d.ts +1 -12
- package/babel.js.map +0 -1
- package/config/enable$GetSet.js.map +0 -1
- package/config/enable$GetSet.mjs.map +0 -1
- package/config/enableReactComponents.js.map +0 -1
- package/config/enableReactComponents.mjs.map +0 -1
- package/config/enableReactNativeComponents.js.map +0 -1
- package/config/enableReactNativeComponents.mjs.map +0 -1
- package/config/enableReactTracking.js.map +0 -1
- package/config/enableReactTracking.mjs.map +0 -1
- package/config/enableReactUse.js.map +0 -1
- package/config/enableReactUse.mjs.map +0 -1
- package/config/enable_PeekAssign.js.map +0 -1
- package/config/enable_PeekAssign.mjs.map +0 -1
- package/helpers/pageHash.js.map +0 -1
- package/helpers/pageHash.mjs.map +0 -1
- package/helpers/pageHashParams.js.map +0 -1
- package/helpers/pageHashParams.mjs.map +0 -1
- package/helpers/time.js.map +0 -1
- package/helpers/time.mjs.map +0 -1
- package/helpers/trackHistory.js.map +0 -1
- package/helpers/trackHistory.mjs.map +0 -1
- package/helpers/undoRedo.js.map +0 -1
- package/helpers/undoRedo.mjs.map +0 -1
- package/history.d.ts +0 -1
- package/history.js +0 -24
- package/history.js.map +0 -1
- package/history.mjs +0 -22
- package/history.mjs.map +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/persist-plugins/async-storage.js.map +0 -1
- package/persist-plugins/async-storage.mjs.map +0 -1
- package/persist-plugins/indexeddb.js.map +0 -1
- package/persist-plugins/indexeddb.mjs.map +0 -1
- package/persist-plugins/local-storage.js.map +0 -1
- package/persist-plugins/local-storage.mjs.map +0 -1
- package/persist-plugins/mmkv.js.map +0 -1
- package/persist-plugins/mmkv.mjs.map +0 -1
- package/react-hooks/createObservableHook.js.map +0 -1
- package/react-hooks/createObservableHook.mjs.map +0 -1
- package/react-hooks/useHover.js.map +0 -1
- package/react-hooks/useHover.mjs.map +0 -1
- package/react-hooks/useMeasure.js.map +0 -1
- package/react-hooks/useMeasure.mjs.map +0 -1
- package/react-hooks/useObservableNextRouter.js.map +0 -1
- package/react-hooks/useObservableNextRouter.mjs.map +0 -1
- package/react.js.map +0 -1
- package/react.mjs.map +0 -1
- package/src/ObservableObject.ts +0 -1350
- package/src/ObservablePrimitive.ts +0 -62
- package/src/babel/index.ts +0 -83
- package/src/batching.ts +0 -357
- package/src/computed.ts +0 -18
- package/src/config/enable$GetSet.ts +0 -30
- package/src/config/enableReactComponents.ts +0 -26
- package/src/config/enableReactNativeComponents.ts +0 -102
- package/src/config/enableReactTracking.ts +0 -62
- package/src/config/enableReactUse.ts +0 -32
- package/src/config/enable_PeekAssign.ts +0 -31
- package/src/config.ts +0 -47
- package/src/createObservable.ts +0 -47
- package/src/event.ts +0 -26
- package/src/globals.ts +0 -235
- package/src/helpers/pageHash.ts +0 -41
- package/src/helpers/pageHashParams.ts +0 -55
- package/src/helpers/time.ts +0 -30
- package/src/helpers/trackHistory.ts +0 -29
- package/src/helpers/undoRedo.ts +0 -111
- package/src/helpers.ts +0 -231
- package/src/is.ts +0 -63
- package/src/linked.ts +0 -17
- package/src/observable.ts +0 -32
- package/src/observableInterfaces.ts +0 -151
- package/src/observableTypes.ts +0 -232
- package/src/observe.ts +0 -89
- package/src/old-plugins/firebase.ts +0 -1053
- package/src/onChange.ts +0 -146
- package/src/persist/configureObservablePersistence.ts +0 -7
- package/src/persist/fieldTransformer.ts +0 -149
- package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
- package/src/persist/persistObservable.ts +0 -1034
- package/src/persist-plugins/async-storage.ts +0 -99
- package/src/persist-plugins/indexeddb.ts +0 -439
- package/src/persist-plugins/local-storage.ts +0 -86
- package/src/persist-plugins/mmkv.ts +0 -91
- package/src/proxy.ts +0 -28
- package/src/react/Computed.tsx +0 -8
- package/src/react/For.tsx +0 -116
- package/src/react/Memo.tsx +0 -4
- package/src/react/Reactive.tsx +0 -53
- package/src/react/Show.tsx +0 -33
- package/src/react/Switch.tsx +0 -43
- package/src/react/react-globals.ts +0 -3
- package/src/react/reactInterfaces.ts +0 -32
- package/src/react/reactive-observer.tsx +0 -210
- package/src/react/useComputed.ts +0 -36
- package/src/react/useEffectOnce.ts +0 -41
- package/src/react/useIsMounted.ts +0 -16
- package/src/react/useMount.ts +0 -15
- package/src/react/useObservable.ts +0 -24
- package/src/react/useObservableReducer.ts +0 -52
- package/src/react/useObservableState.ts +0 -30
- package/src/react/useObserve.ts +0 -54
- package/src/react/useObserveEffect.ts +0 -40
- package/src/react/usePauseProvider.tsx +0 -16
- package/src/react/useSelector.ts +0 -167
- package/src/react/useUnmount.ts +0 -8
- package/src/react/useWhen.ts +0 -9
- package/src/react-hooks/createObservableHook.ts +0 -53
- package/src/react-hooks/useHover.ts +0 -40
- package/src/react-hooks/useMeasure.ts +0 -48
- package/src/react-hooks/useObservableNextRouter.ts +0 -137
- package/src/retry.ts +0 -71
- package/src/setupTracking.ts +0 -26
- package/src/sync/activateSyncedNode.ts +0 -128
- package/src/sync/configureObservableSync.ts +0 -7
- package/src/sync/persistTypes.ts +0 -216
- package/src/sync/syncHelpers.ts +0 -180
- package/src/sync/syncObservable.ts +0 -1056
- package/src/sync/syncObservableAdapter.ts +0 -31
- package/src/sync/syncTypes.ts +0 -189
- package/src/sync/synced.ts +0 -21
- package/src/sync-plugins/crud.ts +0 -412
- package/src/sync-plugins/fetch.ts +0 -80
- package/src/sync-plugins/keel.ts +0 -495
- package/src/sync-plugins/supabase.ts +0 -249
- package/src/sync-plugins/tanstack-query.ts +0 -113
- package/src/sync-plugins/tanstack-react-query.ts +0 -12
- package/src/trace/traceHelpers.ts +0 -11
- package/src/trace/useTraceListeners.ts +0 -34
- package/src/trace/useTraceUpdates.ts +0 -24
- package/src/trace/useVerifyNotTracking.ts +0 -33
- package/src/trace/useVerifyOneRender.ts +0 -10
- package/src/trackSelector.ts +0 -52
- package/src/tracking.ts +0 -43
- package/src/types/babel.d.ts +0 -12
- package/src/when.ts +0 -75
- package/sync-plugins/crud.js.map +0 -1
- package/sync-plugins/crud.mjs.map +0 -1
- package/sync-plugins/fetch.js.map +0 -1
- package/sync-plugins/fetch.mjs.map +0 -1
- package/sync-plugins/keel.js.map +0 -1
- package/sync-plugins/keel.mjs.map +0 -1
- package/sync-plugins/supabase.js.map +0 -1
- package/sync-plugins/supabase.mjs.map +0 -1
- package/sync-plugins/tanstack-query.js.map +0 -1
- package/sync-plugins/tanstack-query.mjs.map +0 -1
- package/sync-plugins/tanstack-react-query.js.map +0 -1
- package/sync-plugins/tanstack-react-query.mjs.map +0 -1
- package/sync.js.map +0 -1
- package/sync.mjs.map +0 -1
- package/trace.js.map +0 -1
- package/trace.mjs.map +0 -1
package/sync-plugins/keel.mjs
CHANGED
|
@@ -1,491 +1,254 @@
|
|
|
1
|
-
import
|
|
2
|
-
import require$$1 from 'util';
|
|
1
|
+
import ksuid from 'ksuid';
|
|
3
2
|
import { observable, computeSelector, isFunction, isEmpty, when, internal } from '@legendapp/state';
|
|
4
3
|
import { removeNullUndefined } from '@legendapp/state/sync';
|
|
5
4
|
import { syncedCrud } from '@legendapp/state/sync-plugins/crud';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function baseConvertIntArray$1 (array, {from, to, fixedLength = null}) {
|
|
12
|
-
const length = fixedLength === null ? maxLength(array, from, to) : fixedLength;
|
|
13
|
-
const result = new Array(length);
|
|
14
|
-
|
|
15
|
-
// Each iteration prepends the resulting value, so start the offset at the end.
|
|
16
|
-
let offset = length;
|
|
17
|
-
let input = array;
|
|
18
|
-
while (input.length > 0) {
|
|
19
|
-
if (offset === 0) {
|
|
20
|
-
throw new RangeError(`Fixed length of ${fixedLength} is too small, expected at least ${maxLength(array, from, to)}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const quotients = [];
|
|
24
|
-
let remainder = 0;
|
|
25
|
-
|
|
26
|
-
for (const digit of input) {
|
|
27
|
-
const acc = digit + remainder * from;
|
|
28
|
-
const q = Math.floor(acc / to);
|
|
29
|
-
remainder = acc % to;
|
|
30
|
-
|
|
31
|
-
if (quotients.length > 0 || q > 0) {
|
|
32
|
-
quotients.push(q);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
result[--offset] = remainder;
|
|
37
|
-
input = quotients;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Trim leading padding, unless length is fixed.
|
|
41
|
-
if (fixedLength === null) {
|
|
42
|
-
return offset > 0 ? result.slice(offset) : result
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Fill in any holes in the result array.
|
|
46
|
-
while (offset > 0) {
|
|
47
|
-
result[--offset] = 0;
|
|
48
|
-
}
|
|
49
|
-
return result
|
|
50
|
-
}
|
|
51
|
-
var baseConvertIntArray_1 = baseConvertIntArray$1;
|
|
52
|
-
|
|
53
|
-
const baseConvertIntArray = baseConvertIntArray_1;
|
|
54
|
-
|
|
55
|
-
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
56
|
-
|
|
57
|
-
function encode (buffer, fixedLength) {
|
|
58
|
-
return baseConvertIntArray(buffer, { from: 256, to: 62, fixedLength })
|
|
59
|
-
.map(value => CHARS[value])
|
|
60
|
-
.join('')
|
|
61
|
-
}
|
|
62
|
-
base62$1.encode = encode;
|
|
63
|
-
|
|
64
|
-
function decode (string, fixedLength) {
|
|
65
|
-
// Optimization from https://github.com/andrew/base62.js/pull/31.
|
|
66
|
-
const input = Array.from(string, char => {
|
|
67
|
-
const charCode = char.charCodeAt(0);
|
|
68
|
-
if (charCode < 58) return charCode - 48
|
|
69
|
-
if (charCode < 91) return charCode - 55
|
|
70
|
-
return charCode - 61
|
|
71
|
-
});
|
|
72
|
-
return Buffer.from(baseConvertIntArray(input, { from: 62, to: 256, fixedLength }))
|
|
73
|
-
}
|
|
74
|
-
base62$1.decode = decode;
|
|
75
|
-
|
|
76
|
-
const { randomBytes } = require$$0;
|
|
77
|
-
const { inspect: { custom: customInspectSymbol }, promisify } = require$$1;
|
|
78
|
-
const base62 = base62$1;
|
|
79
|
-
|
|
80
|
-
const asyncRandomBytes = promisify(randomBytes);
|
|
81
|
-
|
|
82
|
-
// KSUID's epoch starts more recently so that the 32-bit number space gives a
|
|
83
|
-
// significantly higher useful lifetime of around 136 years from March 2014.
|
|
84
|
-
// This number (14e11) was picked to be easy to remember.
|
|
85
|
-
const EPOCH_IN_MS = 14e11;
|
|
86
|
-
|
|
87
|
-
const MAX_TIME_IN_MS = 1e3 * (2 ** 32 - 1) + EPOCH_IN_MS;
|
|
88
|
-
|
|
89
|
-
// Timestamp is a uint32
|
|
90
|
-
const TIMESTAMP_BYTE_LENGTH = 4;
|
|
91
|
-
|
|
92
|
-
// Payload is 16-bytes
|
|
93
|
-
const PAYLOAD_BYTE_LENGTH = 16;
|
|
94
|
-
|
|
95
|
-
// KSUIDs are 20 bytes when binary encoded
|
|
96
|
-
const BYTE_LENGTH = TIMESTAMP_BYTE_LENGTH + PAYLOAD_BYTE_LENGTH;
|
|
97
|
-
|
|
98
|
-
// The length of a KSUID when string (base62) encoded
|
|
99
|
-
const STRING_ENCODED_LENGTH = 27;
|
|
100
|
-
|
|
101
|
-
const TIME_IN_MS_ASSERTION = `Valid KSUID timestamps must be in milliseconds since ${new Date(0).toISOString()},
|
|
102
|
-
no earlier than ${new Date(EPOCH_IN_MS).toISOString()} and no later than ${new Date(MAX_TIME_IN_MS).toISOString()}
|
|
103
|
-
`.trim().replace(/(\n|\s)+/g, ' ').replace(/\.000Z/g, 'Z');
|
|
104
|
-
|
|
105
|
-
const VALID_ENCODING_ASSERTION = `Valid encoded KSUIDs are ${STRING_ENCODED_LENGTH} characters`;
|
|
106
|
-
|
|
107
|
-
const VALID_BUFFER_ASSERTION = `Valid KSUID buffers are ${BYTE_LENGTH} bytes`;
|
|
108
|
-
|
|
109
|
-
const VALID_PAYLOAD_ASSERTION = `Valid KSUID payloads are ${PAYLOAD_BYTE_LENGTH} bytes`;
|
|
110
|
-
|
|
111
|
-
function fromParts (timeInMs, payload) {
|
|
112
|
-
const timestamp = Math.floor((timeInMs - EPOCH_IN_MS) / 1e3);
|
|
113
|
-
const timestampBuffer = Buffer.allocUnsafe(TIMESTAMP_BYTE_LENGTH);
|
|
114
|
-
timestampBuffer.writeUInt32BE(timestamp, 0);
|
|
115
|
-
|
|
116
|
-
return Buffer.concat([timestampBuffer, payload], BYTE_LENGTH)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const bufferLookup = new WeakMap();
|
|
120
|
-
|
|
121
|
-
class KSUID {
|
|
122
|
-
constructor (buffer) {
|
|
123
|
-
if (!KSUID.isValid(buffer)) {
|
|
124
|
-
throw new TypeError(VALID_BUFFER_ASSERTION)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
bufferLookup.set(this, buffer);
|
|
128
|
-
Object.defineProperty(this, 'buffer', {
|
|
129
|
-
enumerable: true,
|
|
130
|
-
get () { return Buffer.from(buffer) }
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
get raw () {
|
|
135
|
-
return Buffer.from(bufferLookup.get(this).slice(0))
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
get date () {
|
|
139
|
-
return new Date(1e3 * this.timestamp + EPOCH_IN_MS)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
get timestamp () {
|
|
143
|
-
return bufferLookup.get(this).readUInt32BE(0)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
get payload () {
|
|
147
|
-
const payload = bufferLookup.get(this).slice(TIMESTAMP_BYTE_LENGTH, BYTE_LENGTH);
|
|
148
|
-
return Buffer.from(payload)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
get string () {
|
|
152
|
-
const encoded = base62.encode(bufferLookup.get(this), STRING_ENCODED_LENGTH);
|
|
153
|
-
return encoded.padStart(STRING_ENCODED_LENGTH, '0')
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
compare (other) {
|
|
157
|
-
if (!bufferLookup.has(other)) {
|
|
158
|
-
return 0
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return bufferLookup.get(this).compare(bufferLookup.get(other), 0, BYTE_LENGTH)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
equals (other) {
|
|
165
|
-
return this === other || (bufferLookup.has(other) && this.compare(other) === 0)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
toString () {
|
|
169
|
-
return `${this[Symbol.toStringTag]} { ${this.string} }`
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
toJSON () {
|
|
173
|
-
return this.string
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
[customInspectSymbol] () {
|
|
177
|
-
return this.toString()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
static async random (time = Date.now()) {
|
|
181
|
-
const payload = await asyncRandomBytes(PAYLOAD_BYTE_LENGTH);
|
|
182
|
-
return new KSUID(fromParts(Number(time), payload))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
static randomSync (time = Date.now()) {
|
|
186
|
-
const payload = randomBytes(PAYLOAD_BYTE_LENGTH);
|
|
187
|
-
return new KSUID(fromParts(Number(time), payload))
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
static fromParts (timeInMs, payload) {
|
|
191
|
-
if (!Number.isInteger(timeInMs) || timeInMs < EPOCH_IN_MS || timeInMs > MAX_TIME_IN_MS) {
|
|
192
|
-
throw new TypeError(TIME_IN_MS_ASSERTION)
|
|
193
|
-
}
|
|
194
|
-
if (!Buffer.isBuffer(payload) || payload.byteLength !== PAYLOAD_BYTE_LENGTH) {
|
|
195
|
-
throw new TypeError(VALID_PAYLOAD_ASSERTION)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return new KSUID(fromParts(timeInMs, payload))
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
static isValid (buffer) {
|
|
202
|
-
return Buffer.isBuffer(buffer) && buffer.byteLength === BYTE_LENGTH
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
static parse (string) {
|
|
206
|
-
if (string.length !== STRING_ENCODED_LENGTH) {
|
|
207
|
-
throw new TypeError(VALID_ENCODING_ASSERTION)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const decoded = base62.decode(string, BYTE_LENGTH);
|
|
211
|
-
if (decoded.byteLength === BYTE_LENGTH) {
|
|
212
|
-
return new KSUID(decoded)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const buffer = Buffer.allocUnsafe(BYTE_LENGTH);
|
|
216
|
-
const padEnd = BYTE_LENGTH - decoded.byteLength;
|
|
217
|
-
buffer.fill(0, 0, padEnd);
|
|
218
|
-
decoded.copy(buffer, padEnd);
|
|
219
|
-
return new KSUID(buffer)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
Object.defineProperty(KSUID.prototype, Symbol.toStringTag, { value: 'KSUID' });
|
|
223
|
-
// A string-encoded maximum value for a KSUID
|
|
224
|
-
Object.defineProperty(KSUID, 'MAX_STRING_ENCODED', { value: 'aWgEPTl1tmebfsQzFP4bxwgy80V' });
|
|
225
|
-
// A string-encoded minimum value for a KSUID
|
|
226
|
-
Object.defineProperty(KSUID, 'MIN_STRING_ENCODED', { value: '000000000000000000000000000' });
|
|
227
|
-
|
|
228
|
-
var ksuid = KSUID;
|
|
229
|
-
|
|
230
|
-
const { clone } = internal;
|
|
231
|
-
const KeelKeys = ['createdAt', 'updatedAt'];
|
|
6
|
+
// src/sync-plugins/keel.ts
|
|
7
|
+
var { clone } = internal;
|
|
8
|
+
var KeelKeys = ["createdAt", "updatedAt"];
|
|
232
9
|
function generateKeelId() {
|
|
233
|
-
|
|
10
|
+
return ksuid.randomSync().string;
|
|
234
11
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
12
|
+
var keelConfig = {};
|
|
13
|
+
var modifiedClients = /* @__PURE__ */ new WeakSet();
|
|
14
|
+
var isEnabled$ = observable(true);
|
|
238
15
|
async function ensureAuthToken() {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
16
|
+
await when(isEnabled$.get());
|
|
17
|
+
let isAuthed = await keelConfig.client.auth.isAuthenticated();
|
|
18
|
+
if (!isAuthed) {
|
|
19
|
+
isAuthed = await keelConfig.client.auth.refresh();
|
|
20
|
+
}
|
|
21
|
+
return isAuthed;
|
|
245
22
|
}
|
|
246
23
|
async function handleApiError(error, retry) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
retry === null || retry === void 0 ? void 0 : retry();
|
|
252
|
-
}
|
|
24
|
+
if (error.type === "unauthorized" || error.type === "forbidden") {
|
|
25
|
+
console.warn("Keel token expired, refreshing...");
|
|
26
|
+
await ensureAuthToken();
|
|
27
|
+
}
|
|
253
28
|
}
|
|
254
29
|
function convertObjectToCreate(item) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
30
|
+
const cloned = clone(item);
|
|
31
|
+
Object.keys(cloned).forEach((key) => {
|
|
32
|
+
if (key.endsWith("Id")) {
|
|
33
|
+
if (cloned[key]) {
|
|
34
|
+
cloned[key.slice(0, -2)] = { id: cloned[key] };
|
|
35
|
+
}
|
|
36
|
+
delete cloned[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
delete cloned.createdAt;
|
|
40
|
+
delete cloned.updatedAt;
|
|
41
|
+
return cloned;
|
|
267
42
|
}
|
|
268
43
|
function getSyncedKeelConfiguration() {
|
|
269
|
-
|
|
44
|
+
return keelConfig;
|
|
270
45
|
}
|
|
271
46
|
function configureSyncedKeel(config) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
return ret;
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
}
|
|
47
|
+
const { enabled, realtimePlugin, client, ...rest } = config;
|
|
48
|
+
Object.assign(keelConfig, removeNullUndefined(rest));
|
|
49
|
+
if (enabled !== void 0) {
|
|
50
|
+
isEnabled$.set(enabled);
|
|
51
|
+
}
|
|
52
|
+
if (realtimePlugin) {
|
|
53
|
+
keelConfig.realtimePlugin = realtimePlugin;
|
|
54
|
+
if (client && !modifiedClients.has(client)) {
|
|
55
|
+
modifiedClients.add(client);
|
|
56
|
+
const queries = client.api.queries;
|
|
57
|
+
Object.keys(queries).forEach((key) => {
|
|
58
|
+
if (key.startsWith("list")) {
|
|
59
|
+
const oldFn = queries[key];
|
|
60
|
+
queries[key] = (i) => {
|
|
61
|
+
const realtimeKey = [key, ...Object.values(i.where || {})].filter((value) => value && typeof value !== "object").join("/");
|
|
62
|
+
const subscribe = ({ refresh }) => {
|
|
63
|
+
if (realtimeKey) {
|
|
64
|
+
return realtimePlugin.subscribe(realtimeKey, refresh);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return oldFn(i).then((ret) => {
|
|
68
|
+
if (subscribe) {
|
|
69
|
+
ret.subscribe = subscribe;
|
|
70
|
+
ret.subscribeKey = realtimeKey;
|
|
71
|
+
}
|
|
72
|
+
return ret;
|
|
303
73
|
});
|
|
74
|
+
};
|
|
304
75
|
}
|
|
76
|
+
});
|
|
305
77
|
}
|
|
78
|
+
}
|
|
306
79
|
}
|
|
307
|
-
|
|
80
|
+
var NumPerPage = 200;
|
|
308
81
|
async function getAllPages(listFn, params) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
} while (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage);
|
|
342
|
-
return { results: allData, subscribe: subscribe_, subscribeKey: subscribeKey_ };
|
|
82
|
+
const allData = [];
|
|
83
|
+
let pageInfo = void 0;
|
|
84
|
+
let subscribe_;
|
|
85
|
+
let subscribeKey_;
|
|
86
|
+
const { first: firstParam } = params;
|
|
87
|
+
do {
|
|
88
|
+
const first = firstParam ? Math.min(firstParam - allData.length, NumPerPage) : NumPerPage;
|
|
89
|
+
if (first < 1) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
const pageEndCursor = pageInfo == null ? void 0 : pageInfo.endCursor;
|
|
93
|
+
const paramsWithCursor = pageEndCursor ? { first, ...params, after: pageEndCursor } : { first, ...params };
|
|
94
|
+
pageInfo = void 0;
|
|
95
|
+
const ret = await listFn(paramsWithCursor);
|
|
96
|
+
if (ret) {
|
|
97
|
+
const { data, error, subscribe, subscribeKey } = ret;
|
|
98
|
+
if (subscribe) {
|
|
99
|
+
subscribe_ = subscribe;
|
|
100
|
+
subscribeKey_ = subscribeKey;
|
|
101
|
+
}
|
|
102
|
+
if (error) {
|
|
103
|
+
await handleApiError(error);
|
|
104
|
+
throw new Error(error.message);
|
|
105
|
+
} else if (data) {
|
|
106
|
+
pageInfo = data.pageInfo;
|
|
107
|
+
allData.push(...data.results);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} while (pageInfo == null ? void 0 : pageInfo.hasNextPage);
|
|
111
|
+
return { results: allData, subscribe: subscribe_, subscribeKey: subscribeKey_ };
|
|
343
112
|
}
|
|
344
113
|
function syncedKeel(props) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const { retryNum, cancelRetry, update } = params;
|
|
401
|
-
if (isCreate &&
|
|
402
|
-
((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('for the unique')) &&
|
|
403
|
-
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('must be unique'))) {
|
|
404
|
-
if (__DEV__) {
|
|
405
|
-
console.log('Creating duplicate data already saved, just ignore.');
|
|
406
|
-
}
|
|
407
|
-
// This has already been saved but didn't update pending changes, so just update with {} to clear the pending state
|
|
408
|
-
update({
|
|
409
|
-
value: {},
|
|
410
|
-
mode: 'assign',
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
else if (error.type === 'bad_request') {
|
|
414
|
-
(_c = keelConfig.onError) === null || _c === void 0 ? void 0 : _c.call(keelConfig, error);
|
|
415
|
-
if (retryNum > 4) {
|
|
416
|
-
cancelRetry();
|
|
417
|
-
}
|
|
418
|
-
throw new Error(error.message);
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
await handleApiError(error);
|
|
422
|
-
throw new Error(error.message);
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
const create = createParam
|
|
426
|
-
? async (input, params) => {
|
|
427
|
-
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
428
|
-
if (error) {
|
|
429
|
-
handleSetError(error, params, true);
|
|
430
|
-
}
|
|
431
|
-
return data;
|
|
432
|
-
}
|
|
433
|
-
: undefined;
|
|
434
|
-
const update = updateParam
|
|
435
|
-
? async (input, params) => {
|
|
436
|
-
const id = input.id;
|
|
437
|
-
const values = convertObjectToCreate(input);
|
|
438
|
-
delete values.id;
|
|
439
|
-
delete values.createdAt;
|
|
440
|
-
delete values.updatedAt;
|
|
441
|
-
if (!isEmpty(values)) {
|
|
442
|
-
const { data, error } = await updateParam({ where: { id }, values });
|
|
443
|
-
if (error) {
|
|
444
|
-
handleSetError(error, params, false);
|
|
445
|
-
}
|
|
446
|
-
return data;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
: undefined;
|
|
450
|
-
const deleteFn = deleteParam
|
|
451
|
-
? async ({ id }, params) => {
|
|
452
|
-
const { data, error } = await deleteParam({ id });
|
|
453
|
-
if (error) {
|
|
454
|
-
handleSetError(error, params, false);
|
|
455
|
-
}
|
|
456
|
-
return data;
|
|
114
|
+
const { realtimePlugin } = keelConfig;
|
|
115
|
+
props = { ...keelConfig, ...props };
|
|
116
|
+
const {
|
|
117
|
+
get: getParam,
|
|
118
|
+
list: listParam,
|
|
119
|
+
create: createParam,
|
|
120
|
+
update: updateParam,
|
|
121
|
+
delete: deleteParam,
|
|
122
|
+
first,
|
|
123
|
+
where: whereParam,
|
|
124
|
+
waitFor,
|
|
125
|
+
fieldDeleted,
|
|
126
|
+
...rest
|
|
127
|
+
} = props;
|
|
128
|
+
const { changesSince } = props;
|
|
129
|
+
const asType = getParam ? "value" : props.as;
|
|
130
|
+
let subscribeFn;
|
|
131
|
+
const subscribeFnKey$ = observable("");
|
|
132
|
+
const fieldCreatedAt = "createdAt";
|
|
133
|
+
const fieldUpdatedAt = "updatedAt";
|
|
134
|
+
const list = listParam ? async (listParams) => {
|
|
135
|
+
const { lastSync, refresh } = listParams;
|
|
136
|
+
const queryBySync = !!lastSync && changesSince === "last-sync";
|
|
137
|
+
const where = Object.assign(
|
|
138
|
+
queryBySync ? { updatedAt: { after: new Date(lastSync + 1) } } : {},
|
|
139
|
+
isFunction(whereParam) ? whereParam() : whereParam
|
|
140
|
+
);
|
|
141
|
+
const params = { where, first };
|
|
142
|
+
const { results, subscribe: subscribe2, subscribeKey } = await getAllPages(listParam, params);
|
|
143
|
+
if (subscribe2) {
|
|
144
|
+
subscribeFn = () => subscribe2({ refresh });
|
|
145
|
+
subscribeFnKey$.set(subscribeKey);
|
|
146
|
+
}
|
|
147
|
+
return results;
|
|
148
|
+
} : void 0;
|
|
149
|
+
const get = getParam ? async (getParams) => {
|
|
150
|
+
const { refresh } = getParams;
|
|
151
|
+
const { data, error, subscribe: subscribe2, subscribeKey } = await getParam({ refresh });
|
|
152
|
+
if (subscribe2) {
|
|
153
|
+
subscribeFn = () => subscribe2({ refresh });
|
|
154
|
+
subscribeFnKey$.set(subscribeKey);
|
|
155
|
+
}
|
|
156
|
+
if (error) {
|
|
157
|
+
throw new Error(error.message);
|
|
158
|
+
} else {
|
|
159
|
+
return data;
|
|
160
|
+
}
|
|
161
|
+
} : void 0;
|
|
162
|
+
const onSaved = ({ saved }) => {
|
|
163
|
+
if (saved) {
|
|
164
|
+
const updatedAt = saved[fieldUpdatedAt];
|
|
165
|
+
if (updatedAt && realtimePlugin) {
|
|
166
|
+
const subscribeFnKey = subscribeFnKey$.get();
|
|
167
|
+
if (subscribeFnKey) {
|
|
168
|
+
realtimePlugin.setLatestChange(subscribeFnKey, updatedAt);
|
|
457
169
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const handleSetError = async (error, params, isCreate) => {
|
|
174
|
+
var _a, _b, _c;
|
|
175
|
+
const { retryNum, cancelRetry, update: update2 } = params;
|
|
176
|
+
if (isCreate && ((_a = error.message) == null ? void 0 : _a.includes("for the unique")) && ((_b = error.message) == null ? void 0 : _b.includes("must be unique"))) {
|
|
177
|
+
if (__DEV__) {
|
|
178
|
+
console.log("Creating duplicate data already saved, just ignore.");
|
|
179
|
+
}
|
|
180
|
+
update2({
|
|
181
|
+
value: {},
|
|
182
|
+
mode: "assign"
|
|
183
|
+
});
|
|
184
|
+
} else if (error.type === "bad_request") {
|
|
185
|
+
(_c = keelConfig.onError) == null ? void 0 : _c.call(keelConfig, error);
|
|
186
|
+
if (retryNum > 4) {
|
|
187
|
+
cancelRetry();
|
|
188
|
+
}
|
|
189
|
+
throw new Error(error.message);
|
|
190
|
+
} else {
|
|
191
|
+
await handleApiError(error);
|
|
192
|
+
throw new Error(error.message);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const create = createParam ? async (input, params) => {
|
|
196
|
+
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
197
|
+
if (error) {
|
|
198
|
+
handleSetError(error, params, true);
|
|
199
|
+
}
|
|
200
|
+
return data;
|
|
201
|
+
} : void 0;
|
|
202
|
+
const update = updateParam ? async (input, params) => {
|
|
203
|
+
const id = input.id;
|
|
204
|
+
const values = convertObjectToCreate(input);
|
|
205
|
+
delete values.id;
|
|
206
|
+
delete values.createdAt;
|
|
207
|
+
delete values.updatedAt;
|
|
208
|
+
if (!isEmpty(values)) {
|
|
209
|
+
const { data, error } = await updateParam({ where: { id }, values });
|
|
210
|
+
if (error) {
|
|
211
|
+
handleSetError(error, params, false);
|
|
212
|
+
}
|
|
213
|
+
return data;
|
|
214
|
+
}
|
|
215
|
+
} : void 0;
|
|
216
|
+
const deleteFn = deleteParam ? async ({ id }, params) => {
|
|
217
|
+
const { data, error } = await deleteParam({ id });
|
|
218
|
+
if (error) {
|
|
219
|
+
handleSetError(error, params, false);
|
|
220
|
+
}
|
|
221
|
+
return data;
|
|
222
|
+
} : void 0;
|
|
223
|
+
const subscribe = (params) => {
|
|
224
|
+
let unsubscribe = void 0;
|
|
225
|
+
when(subscribeFnKey$, () => {
|
|
226
|
+
unsubscribe = subscribeFn(params);
|
|
487
227
|
});
|
|
228
|
+
return () => {
|
|
229
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
return syncedCrud({
|
|
233
|
+
...rest,
|
|
234
|
+
as: asType,
|
|
235
|
+
list,
|
|
236
|
+
create,
|
|
237
|
+
update,
|
|
238
|
+
delete: deleteFn,
|
|
239
|
+
waitFor: () => isEnabled$.get() && (waitFor ? computeSelector(waitFor) : true),
|
|
240
|
+
onSaved,
|
|
241
|
+
onSavedUpdate: "createdUpdatedAt",
|
|
242
|
+
fieldCreatedAt,
|
|
243
|
+
fieldUpdatedAt,
|
|
244
|
+
fieldDeleted: fieldDeleted || "deleted",
|
|
245
|
+
changesSince,
|
|
246
|
+
updatePartial: true,
|
|
247
|
+
subscribe,
|
|
248
|
+
generateId: generateKeelId,
|
|
249
|
+
// @ts-expect-error This errors because of the get/list union type
|
|
250
|
+
get
|
|
251
|
+
});
|
|
488
252
|
}
|
|
489
253
|
|
|
490
254
|
export { KeelKeys, configureSyncedKeel, generateKeelId, getSyncedKeelConfiguration, syncedKeel };
|
|
491
|
-
//# sourceMappingURL=keel.mjs.map
|