@dittolive/ditto 4.7.3 → 4.7.4-rc.2
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/README.md +2 -2
- package/node/ditto.cjs.js +1 -1
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-arm64.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +10 -5
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
- package/DittoReactNative.podspec +0 -27
- package/react-native/android/CMakeLists.txt +0 -36
- package/react-native/android/build.gradle +0 -190
- package/react-native/android/cpp-adapter.cpp +0 -259
- package/react-native/android/gradle.properties +0 -5
- package/react-native/android/src/main/AndroidManifest.xml +0 -4
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +0 -120
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +0 -28
- package/react-native/cpp/include/Arc.hpp +0 -159
- package/react-native/cpp/include/Attachment.h +0 -20
- package/react-native/cpp/include/Authentication.h +0 -23
- package/react-native/cpp/include/Collection.h +0 -13
- package/react-native/cpp/include/ConnectionRequest.h +0 -18
- package/react-native/cpp/include/DQL.h +0 -21
- package/react-native/cpp/include/Document.h +0 -17
- package/react-native/cpp/include/FFIUtils.h +0 -16
- package/react-native/cpp/include/IO.h +0 -13
- package/react-native/cpp/include/Identity.h +0 -17
- package/react-native/cpp/include/Lifecycle.h +0 -16
- package/react-native/cpp/include/LiveQuery.h +0 -17
- package/react-native/cpp/include/Logger.h +0 -22
- package/react-native/cpp/include/Misc.h +0 -30
- package/react-native/cpp/include/Presence.h +0 -18
- package/react-native/cpp/include/SmallPeerInfo.h +0 -19
- package/react-native/cpp/include/Transports.h +0 -25
- package/react-native/cpp/include/TypedArray.hpp +0 -167
- package/react-native/cpp/include/Utils.h +0 -70
- package/react-native/cpp/include/main.h +0 -10
- package/react-native/cpp/src/Attachment.cpp +0 -272
- package/react-native/cpp/src/Authentication.cpp +0 -227
- package/react-native/cpp/src/Collection.cpp +0 -56
- package/react-native/cpp/src/ConnectionRequest.cpp +0 -123
- package/react-native/cpp/src/DQL.cpp +0 -256
- package/react-native/cpp/src/Document.cpp +0 -146
- package/react-native/cpp/src/FFIUtils.cpp +0 -122
- package/react-native/cpp/src/IO.cpp +0 -35
- package/react-native/cpp/src/Identity.cpp +0 -122
- package/react-native/cpp/src/Lifecycle.cpp +0 -93
- package/react-native/cpp/src/LiveQuery.cpp +0 -63
- package/react-native/cpp/src/Logger.cpp +0 -199
- package/react-native/cpp/src/Misc.cpp +0 -322
- package/react-native/cpp/src/Presence.cpp +0 -166
- package/react-native/cpp/src/SmallPeerInfo.cpp +0 -142
- package/react-native/cpp/src/Transports.cpp +0 -275
- package/react-native/cpp/src/TypedArray.cpp +0 -303
- package/react-native/cpp/src/Utils.cpp +0 -139
- package/react-native/cpp/src/main.cpp +0 -178
- package/react-native/dittoffi/dittoffi.h +0 -4873
- package/react-native/dittoffi/ifaddrs.cpp +0 -385
- package/react-native/dittoffi/ifaddrs.h +0 -206
- package/react-native/ios/DittoRNSDK.h +0 -7
- package/react-native/ios/DittoRNSDK.mm +0 -159
- package/react-native/ios/YeetJSIUtils.h +0 -60
- package/react-native/ios/YeetJSIUtils.mm +0 -196
- package/react-native/lib/commonjs/ditto.rn.js +0 -93
- package/react-native/lib/commonjs/ditto.rn.js.map +0 -1
- package/react-native/lib/commonjs/index.js +0 -61
- package/react-native/lib/commonjs/index.js.map +0 -1
- package/react-native/lib/module/ditto.rn.js +0 -89
- package/react-native/lib/module/ditto.rn.js.map +0 -1
- package/react-native/lib/module/index.js +0 -27
- package/react-native/lib/module/index.js.map +0 -1
- package/react-native/lib/typescript/ditto.rn.d.ts +0 -15
- package/react-native/lib/typescript/ditto.rn.d.ts.map +0 -1
- package/react-native/lib/typescript/index.d.ts +0 -1
- package/react-native/lib/typescript/index.d.ts.map +0 -1
- package/react-native/src/ditto.rn.ts +0 -123
- package/react-native/src/environment/environment.fallback.ts +0 -4
- package/react-native/src/index.ts +0 -29
- package/react-native/src/sources/@cbor-redux.ts +0 -2
- package/react-native/src/sources/@ditto.core.ts +0 -1
- package/react-native/src/sources/@environment.ts +0 -1
- package/react-native/src/sources/attachment-fetch-event.ts +0 -54
- package/react-native/src/sources/attachment-fetcher-manager.ts +0 -145
- package/react-native/src/sources/attachment-fetcher.ts +0 -265
- package/react-native/src/sources/attachment-token.ts +0 -129
- package/react-native/src/sources/attachment.ts +0 -121
- package/react-native/src/sources/augment.ts +0 -108
- package/react-native/src/sources/authenticator.ts +0 -314
- package/react-native/src/sources/base-pending-cursor-operation.ts +0 -255
- package/react-native/src/sources/base-pending-id-specific-operation.ts +0 -112
- package/react-native/src/sources/bridge.ts +0 -557
- package/react-native/src/sources/build-time-constants.ts +0 -8
- package/react-native/src/sources/cbor.ts +0 -20
- package/react-native/src/sources/collection-interface.ts +0 -73
- package/react-native/src/sources/collection.ts +0 -219
- package/react-native/src/sources/collections-event.ts +0 -99
- package/react-native/src/sources/connection-request.ts +0 -142
- package/react-native/src/sources/counter.ts +0 -82
- package/react-native/src/sources/ditto.ts +0 -991
- package/react-native/src/sources/document-id.ts +0 -163
- package/react-native/src/sources/document-path.ts +0 -308
- package/react-native/src/sources/document.ts +0 -237
- package/react-native/src/sources/epilogue.ts +0 -32
- package/react-native/src/sources/error-codes.ts +0 -114
- package/react-native/src/sources/error.ts +0 -256
- package/react-native/src/sources/essentials.ts +0 -81
- package/react-native/src/sources/ffi-error.ts +0 -134
- package/react-native/src/sources/ffi.ts +0 -2190
- package/react-native/src/sources/identity.ts +0 -163
- package/react-native/src/sources/init.ts +0 -71
- package/react-native/src/sources/internal.ts +0 -143
- package/react-native/src/sources/keep-alive.ts +0 -73
- package/react-native/src/sources/key-path.ts +0 -198
- package/react-native/src/sources/live-query-event.ts +0 -208
- package/react-native/src/sources/live-query-manager.ts +0 -110
- package/react-native/src/sources/live-query.ts +0 -167
- package/react-native/src/sources/logger.ts +0 -196
- package/react-native/src/sources/main.ts +0 -61
- package/react-native/src/sources/observer-manager.ts +0 -185
- package/react-native/src/sources/observer.ts +0 -79
- package/react-native/src/sources/pending-collections-operation.ts +0 -241
- package/react-native/src/sources/pending-cursor-operation.ts +0 -218
- package/react-native/src/sources/pending-id-specific-operation.ts +0 -218
- package/react-native/src/sources/presence-manager.ts +0 -170
- package/react-native/src/sources/presence.ts +0 -427
- package/react-native/src/sources/query-result-item.ts +0 -131
- package/react-native/src/sources/query-result.ts +0 -55
- package/react-native/src/sources/register.ts +0 -95
- package/react-native/src/sources/small-peer-info.ts +0 -166
- package/react-native/src/sources/static-tcp-client.ts +0 -8
- package/react-native/src/sources/store-observer.ts +0 -170
- package/react-native/src/sources/store.ts +0 -630
- package/react-native/src/sources/subscription-manager.ts +0 -99
- package/react-native/src/sources/subscription.ts +0 -89
- package/react-native/src/sources/sync-subscription.ts +0 -90
- package/react-native/src/sources/sync.ts +0 -561
- package/react-native/src/sources/test-helpers.ts +0 -24
- package/react-native/src/sources/transport-conditions-manager.ts +0 -104
- package/react-native/src/sources/transport-config.ts +0 -430
- package/react-native/src/sources/update-result.ts +0 -66
- package/react-native/src/sources/update-results-map.ts +0 -65
- package/react-native/src/sources/websocket-client.ts +0 -7
- package/react-native/src/sources/write-transaction-collection.ts +0 -122
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +0 -101
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +0 -74
- package/react-native/src/sources/write-transaction.ts +0 -121
- package/react-native.config.js +0 -9
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2023 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as FFI from './ffi'
|
|
6
|
-
import { Bridge } from './bridge'
|
|
7
|
-
|
|
8
|
-
import type { Ditto } from './ditto'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Specifies which peers to replicate the small peer info to when enabled.
|
|
12
|
-
*
|
|
13
|
-
* Possible values are:
|
|
14
|
-
*
|
|
15
|
-
* - `LocalPeerOnly`: no replication (default)
|
|
16
|
-
* - `BigPeerOnly`: replicate to the Big Peer
|
|
17
|
-
*/
|
|
18
|
-
export type SmallPeerInfoSyncScope = 'LocalPeerOnly' | 'BigPeerOnly'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The entrypoint for small peer user info collection. Small peer info consists
|
|
22
|
-
* of information gathered into a system collection on a regular interval and
|
|
23
|
-
* optionally synced to the Big Peer for device dashboard and debugging
|
|
24
|
-
* purposes.
|
|
25
|
-
*
|
|
26
|
-
* An instance of this class is available on each `Ditto` instance via its
|
|
27
|
-
* {@link Ditto.smallPeerInfo | `smallPeerInfo`} property. Instantiating this
|
|
28
|
-
* class directly is not supported.
|
|
29
|
-
*/
|
|
30
|
-
export class SmallPeerInfo {
|
|
31
|
-
/**
|
|
32
|
-
* Indicates whether small peer info collection is currently enabled, defaults
|
|
33
|
-
* to `false`.
|
|
34
|
-
*
|
|
35
|
-
* **Note**: whether the background ingestion process is enabled or not is a
|
|
36
|
-
* separate decision to whether this information is allowed to sync to other
|
|
37
|
-
* peers (including the big peer). This is controlled by
|
|
38
|
-
* {@link getSyncScope | getSyncScope()} and
|
|
39
|
-
* {@link setSyncScope | setSyncScope()}.
|
|
40
|
-
*/
|
|
41
|
-
get isEnabled(): boolean {
|
|
42
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
43
|
-
return this.ditto.deferClose(() => {
|
|
44
|
-
return FFI.dittoSmallPeerInfoGetIsEnabled(dittoHandle.deref())
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set whether small peer info collection is enabled.
|
|
50
|
-
*
|
|
51
|
-
* @throws when set to a non-boolean value.
|
|
52
|
-
*/
|
|
53
|
-
set isEnabled(newValue: boolean) {
|
|
54
|
-
if (typeof newValue !== 'boolean') {
|
|
55
|
-
throw new TypeError(`Expected boolean, got ${typeof newValue}`)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
59
|
-
void this.ditto.deferCloseAsync(async () => {
|
|
60
|
-
return FFI.dittoSmallPeerInfoSetEnabled(dittoHandle.deref(), newValue)
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The metadata associated with the small peer info.
|
|
66
|
-
*
|
|
67
|
-
* Small peer info metadata is a free-form, user-provided JSON object that
|
|
68
|
-
* is inserted into the small peer info system document at each collection
|
|
69
|
-
* interval.
|
|
70
|
-
*/
|
|
71
|
-
get metadata(): Record<string, any> {
|
|
72
|
-
return JSON.parse(this.metadataJSONString)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Set the metadata associated with the small peer info.
|
|
77
|
-
*
|
|
78
|
-
* The metadata must be a JSON-serializable object that conforms to the
|
|
79
|
-
* following constraints:
|
|
80
|
-
*
|
|
81
|
-
* - Must be a JSON object (not an array, string, number, etc.)
|
|
82
|
-
* - The size when encoded as JSON must be less than 128 KB
|
|
83
|
-
* - May only be nested up to 64 levels deep
|
|
84
|
-
*
|
|
85
|
-
* @example <caption>Valid metadata</caption>
|
|
86
|
-
* ditto.smallPeerInfo.metadata = {
|
|
87
|
-
* "foo": "bar",
|
|
88
|
-
* "nested": {
|
|
89
|
-
* "inner": "value"
|
|
90
|
-
* }
|
|
91
|
-
* }
|
|
92
|
-
*
|
|
93
|
-
* @throws when set to a value that violates any of the constraints listed
|
|
94
|
-
* above.
|
|
95
|
-
*/
|
|
96
|
-
set metadata(metadata: Record<string, any>) {
|
|
97
|
-
this.metadataJSONString = JSON.stringify(metadata)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The metadata associated with the small peer info, as a JSON string.
|
|
102
|
-
*/
|
|
103
|
-
get metadataJSONString(): string {
|
|
104
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
105
|
-
return this.ditto.deferClose(() => {
|
|
106
|
-
return FFI.dittoSmallPeerInfoGetMetadata(dittoHandle.deref())
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Set the metadata associated with the small peer info, as a JSON string.
|
|
112
|
-
*
|
|
113
|
-
* @see {@link SmallPeerInfo.metadata | `metadata`} for more information on
|
|
114
|
-
* valid values.
|
|
115
|
-
* @throws when set to a value that violates any of the constraints listed in
|
|
116
|
-
* {@link SmallPeerInfo.metadata | `metadata`}.
|
|
117
|
-
*/
|
|
118
|
-
set metadataJSONString(metadata: string) {
|
|
119
|
-
if (typeof metadata !== 'string') {
|
|
120
|
-
throw new TypeError(`Expected string, got ${typeof metadata}`)
|
|
121
|
-
}
|
|
122
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
123
|
-
this.ditto.deferClose(() => {
|
|
124
|
-
// throws if any validation errors occur
|
|
125
|
-
FFI.dittoSmallPeerInfoSetMetadata(dittoHandle.deref(), metadata)
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Determines which "kind" of peers the small peer info will be
|
|
131
|
-
* replicated to.
|
|
132
|
-
*
|
|
133
|
-
* Defaults to `LocalPeerOnly`, which means no replication. Set this to
|
|
134
|
-
* `BigPeerOnly` to replicate collected info to the Big Peer.
|
|
135
|
-
*/
|
|
136
|
-
async getSyncScope(): Promise<SmallPeerInfoSyncScope> {
|
|
137
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
138
|
-
return this.ditto.deferCloseAsync(async () => {
|
|
139
|
-
return FFI.dittoSmallPeerInfoGetSyncScope(dittoHandle.deref())
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Set the sync scope.
|
|
145
|
-
*
|
|
146
|
-
* See {@link getSyncScope} for more information.
|
|
147
|
-
*
|
|
148
|
-
* @param syncScope the new sync scope.
|
|
149
|
-
* @throws when set to a value other than `BigPeerOnly` or `LocalPeerOnly`.
|
|
150
|
-
*/
|
|
151
|
-
async setSyncScope(syncScope: SmallPeerInfoSyncScope): Promise<void> {
|
|
152
|
-
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
153
|
-
return this.ditto.deferCloseAsync(async () => {
|
|
154
|
-
return FFI.dittoSmallPeerInfoSetSyncScope(dittoHandle.deref(), syncScope as any)
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ----------------------------------------------------------- Internal ------
|
|
159
|
-
|
|
160
|
-
private ditto: Ditto
|
|
161
|
-
|
|
162
|
-
/** @internal */
|
|
163
|
-
constructor(ditto: Ditto) {
|
|
164
|
-
this.ditto = ditto
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2023 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as FFI from './ffi'
|
|
6
|
-
|
|
7
|
-
import { desugarJSObject } from './augment'
|
|
8
|
-
import { Bridge } from './bridge'
|
|
9
|
-
import { CBOR } from './cbor'
|
|
10
|
-
import { DittoError, mapFFIErrors } from './error'
|
|
11
|
-
import { Logger } from './logger'
|
|
12
|
-
import { QueryResult } from './query-result'
|
|
13
|
-
|
|
14
|
-
import type { Ditto } from './ditto'
|
|
15
|
-
import type { DQLQueryArguments } from './essentials'
|
|
16
|
-
import type { Store } from './store'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A store observation handler is called whenever an active store observer
|
|
20
|
-
* receives new results.
|
|
21
|
-
*/
|
|
22
|
-
export type StoreObservationHandler = (queryResult: QueryResult) => void
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A store observation handler is called whenever an active store observer
|
|
26
|
-
* receives new results.
|
|
27
|
-
*
|
|
28
|
-
* Call `signalNext()` to signal that the handler is ready to receive the next
|
|
29
|
-
* callback from the store observer.
|
|
30
|
-
*/
|
|
31
|
-
export type StoreObservationHandlerWithSignalNext = (queryResult: QueryResult, signalNext: () => void) => void
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A store observer invokes a given handler whenever results for its query
|
|
35
|
-
* change.
|
|
36
|
-
*
|
|
37
|
-
* The store observer will remain active until it is {@link cancel | cancelled},
|
|
38
|
-
* or the Ditto instance managing the observer has been
|
|
39
|
-
* {@link Ditto.close | closed}.
|
|
40
|
-
*
|
|
41
|
-
* Create a store observer by calling
|
|
42
|
-
* {@link Store.registerObserver | `ditto.store.registerObserver()`}.
|
|
43
|
-
*/
|
|
44
|
-
export class StoreObserver {
|
|
45
|
-
/**
|
|
46
|
-
* The Ditto instance this store observer is registered with.
|
|
47
|
-
*/
|
|
48
|
-
readonly ditto: Ditto
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The query string of the store observer (as passed when registering it).
|
|
52
|
-
*/
|
|
53
|
-
readonly queryString: string
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The query arguments of the store observer (as passed when registering it).
|
|
57
|
-
*/
|
|
58
|
-
readonly queryArguments?: Readonly<DQLQueryArguments>
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Convenience property, returns `true` once the store observer has been
|
|
62
|
-
* cancelled.
|
|
63
|
-
*/
|
|
64
|
-
get isCancelled(): boolean {
|
|
65
|
-
return this._isCancelled
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Cancels the store observer and unregisters it. No-op if the
|
|
70
|
-
* store observer has already been cancelled.
|
|
71
|
-
*/
|
|
72
|
-
cancel() {
|
|
73
|
-
if (this._isCancelled) return
|
|
74
|
-
this._isCancelled = true
|
|
75
|
-
this.ditto.store.unregisterObserver(this)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// --------------------------- Internal -------------------------------------
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The ID of this observer's live query.
|
|
82
|
-
*
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
readonly liveQueryID: number
|
|
86
|
-
|
|
87
|
-
/** @internal */
|
|
88
|
-
constructor(ditto: Ditto, query: string, queryArguments: DQLQueryArguments | null, observationHandler: StoreObservationHandlerWithSignalNext) {
|
|
89
|
-
this.queryString = query
|
|
90
|
-
this.queryArguments = queryArguments ? Object.freeze({ ...queryArguments }) : undefined
|
|
91
|
-
this.ditto = ditto
|
|
92
|
-
|
|
93
|
-
let queryArgumentsCBOR: Uint8Array | null = null
|
|
94
|
-
if (queryArguments != null) {
|
|
95
|
-
try {
|
|
96
|
-
const queryArgumentsJSON = desugarJSObject(queryArguments)
|
|
97
|
-
queryArgumentsCBOR = CBOR.encode(queryArgumentsJSON)
|
|
98
|
-
} catch (error: any) {
|
|
99
|
-
throw new DittoError('query/arguments-invalid')
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
let storeObserverID: number | undefined
|
|
103
|
-
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
104
|
-
this.ditto.deferClose(() => {
|
|
105
|
-
const weakThis = new WeakRef(this)
|
|
106
|
-
|
|
107
|
-
function wrappedObservationHandler(cCBParams: CCallbackParams): void {
|
|
108
|
-
const strongThis = weakThis.deref()
|
|
109
|
-
if (strongThis == null) {
|
|
110
|
-
Logger.debug(`Ignoring change event received by store observer ${storeObserverID} after it was cancelled`)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const result = Bridge.queryResult.bridge(cCBParams.query_result, () => new QueryResult(cCBParams.query_result))
|
|
115
|
-
|
|
116
|
-
Logger.debug(`Invoking user event handler with new event for store observer ${storeObserverID}`)
|
|
117
|
-
observationHandler(result, () => {
|
|
118
|
-
return strongThis.signalNext()
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
mapFFIErrors(() => {
|
|
123
|
-
storeObserverID = FFI.tryExperimentalRegisterChangeObserver(dittoHandle.deref(), query, queryArgumentsCBOR, wrappedObservationHandler)
|
|
124
|
-
})
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
if (storeObserverID == null) {
|
|
128
|
-
throw new DittoError('internal', 'Internal inconsistency, store observer ID is undefined after registering')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this.liveQueryID = storeObserverID
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// --------------------------- Private --------------------------------------
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* `true` when the store observer has been cancelled.
|
|
138
|
-
*
|
|
139
|
-
* We mark the store observer as cancelled here as an optimization to avoid a
|
|
140
|
-
* scan of all store observers in the store whenever the `isCancelled`
|
|
141
|
-
* property is checked.
|
|
142
|
-
*/
|
|
143
|
-
private _isCancelled = false
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Signals to Ditto Core that the observer is ready for the next event.
|
|
147
|
-
*/
|
|
148
|
-
private signalNext() {
|
|
149
|
-
const ditto = this.ditto
|
|
150
|
-
if (!ditto || ditto.isClosed) return
|
|
151
|
-
|
|
152
|
-
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
153
|
-
const dittoPointer = dittoHandle.derefOrNull()
|
|
154
|
-
if (!dittoPointer) return
|
|
155
|
-
|
|
156
|
-
if (this.liveQueryID == null) {
|
|
157
|
-
throw new Error('live query ID is null while signaling ready for next event')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return ditto.deferCloseAsync(async () => {
|
|
161
|
-
Logger.debug(`Signaling availability for live query ${this.liveQueryID}`)
|
|
162
|
-
await FFI.liveQuerySignalAvailableNext(dittoPointer, this.liveQueryID)
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// c.f. struct c_cb_params
|
|
168
|
-
type CCallbackParams = {
|
|
169
|
-
query_result: FFI.Pointer<FFI.FFIQueryResult>
|
|
170
|
-
}
|