@dittolive/ditto 4.7.4 → 4.7.5-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 +2 -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/.gradle/8.9/checksums/checksums.lock +0 -0
- package/react-native/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/react-native/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/react-native/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/react-native/android/.gradle/8.9/gc.properties +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/react-native/android/.gradle/vcs-1/gc.properties +0 -0
- 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,430 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Restore a `TransportConfig` from its serializable representation.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export function transportConfigFromDeserializable(serialized: any): TransportConfig {
|
|
11
|
-
const peerToPeerJSON = serialized['peer_to_peer']
|
|
12
|
-
const bluetoothLEJSON = peerToPeerJSON['bluetooth_le']
|
|
13
|
-
const bluetoothLEEnabled = bluetoothLEJSON['enabled']
|
|
14
|
-
const awdlJSON = peerToPeerJSON['awdl']
|
|
15
|
-
const awdlEnabled = awdlJSON['enabled']
|
|
16
|
-
const lanJSON = peerToPeerJSON['lan']
|
|
17
|
-
const lanEnabled = lanJSON['enabled']
|
|
18
|
-
const lanMdnsEnabled = lanJSON['mdns_enabled']
|
|
19
|
-
const lanMulticastEnabled = lanJSON['multicast_enabled']
|
|
20
|
-
|
|
21
|
-
const connectJSON = serialized['connect']
|
|
22
|
-
const connectTcpServers = connectJSON['tcp_servers']
|
|
23
|
-
const connectWebsocketURLs = connectJSON['websocket_urls']
|
|
24
|
-
const connectRetryInterval = connectJSON['retry_interval']
|
|
25
|
-
|
|
26
|
-
const listenJSON = serialized['listen']
|
|
27
|
-
const tcpJSON = listenJSON['tcp']
|
|
28
|
-
const tcpEnabled = tcpJSON['enabled']
|
|
29
|
-
const tcpInterfaceIP = tcpJSON['interface_ip']
|
|
30
|
-
const tcpPort = tcpJSON['port']
|
|
31
|
-
const httpJSON = listenJSON['http']
|
|
32
|
-
const httpEnabled = httpJSON['enabled']
|
|
33
|
-
const httpInterfaceIP = httpJSON['interface_ip']
|
|
34
|
-
const httpPort = httpJSON['port']
|
|
35
|
-
const httpStaticContentPath = httpJSON['static_content_path']
|
|
36
|
-
const httpWebsocketSync = httpJSON['websocket_sync']
|
|
37
|
-
const httpTLSKeyPath = httpJSON['tls_key_path']
|
|
38
|
-
const httpTLSCertificatePath = httpJSON['tls_certificate_path']
|
|
39
|
-
|
|
40
|
-
const globalJSON = serialized['global']
|
|
41
|
-
const globalSyncGroup = globalJSON['sync_group']
|
|
42
|
-
const globalRoutingHint = globalJSON['routing_hint']
|
|
43
|
-
|
|
44
|
-
const config = new TransportConfig()
|
|
45
|
-
|
|
46
|
-
config.peerToPeer.bluetoothLE.isEnabled = bluetoothLEEnabled
|
|
47
|
-
config.peerToPeer.awdl.isEnabled = awdlEnabled
|
|
48
|
-
config.peerToPeer.lan.isEnabled = lanEnabled
|
|
49
|
-
config.peerToPeer.lan.isMdnsEnabled = lanMdnsEnabled
|
|
50
|
-
config.peerToPeer.lan.isMulticastEnabled = lanMulticastEnabled
|
|
51
|
-
|
|
52
|
-
config.connect.tcpServers = connectTcpServers
|
|
53
|
-
config.connect.websocketURLs = connectWebsocketURLs
|
|
54
|
-
config.connect.retryInterval = connectRetryInterval
|
|
55
|
-
|
|
56
|
-
config.listen.tcp.isEnabled = tcpEnabled
|
|
57
|
-
config.listen.tcp.interfaceIP = tcpInterfaceIP
|
|
58
|
-
config.listen.tcp.port = tcpPort
|
|
59
|
-
config.listen.http.isEnabled = httpEnabled
|
|
60
|
-
config.listen.http.interfaceIP = httpInterfaceIP
|
|
61
|
-
config.listen.http.port = httpPort
|
|
62
|
-
config.listen.http.staticContentPath = httpStaticContentPath
|
|
63
|
-
config.listen.http.websocketSync = httpWebsocketSync
|
|
64
|
-
config.listen.http.tlsKeyPath = httpTLSKeyPath
|
|
65
|
-
config.listen.http.tlsCertificatePath = httpTLSCertificatePath
|
|
66
|
-
|
|
67
|
-
config.global.syncGroup = globalSyncGroup
|
|
68
|
-
config.global.routingHint = globalRoutingHint
|
|
69
|
-
|
|
70
|
-
return config
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Convert a `TransportConfig` to a serializable representation.
|
|
75
|
-
*
|
|
76
|
-
* This mainly involves converting the `TransportConfig`'s properties to have the expected key names
|
|
77
|
-
* and casing.
|
|
78
|
-
*
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
export function transportConfigToSerializable(config: TransportConfig): any {
|
|
82
|
-
const peerToPeer = config.peerToPeer
|
|
83
|
-
const connect = config.connect
|
|
84
|
-
const listen = config.listen
|
|
85
|
-
const global = config.global
|
|
86
|
-
|
|
87
|
-
const serialized = {
|
|
88
|
-
peer_to_peer: {
|
|
89
|
-
bluetooth_le: {
|
|
90
|
-
enabled: peerToPeer.bluetoothLE.isEnabled,
|
|
91
|
-
},
|
|
92
|
-
awdl: {
|
|
93
|
-
enabled: peerToPeer.awdl.isEnabled,
|
|
94
|
-
},
|
|
95
|
-
lan: {
|
|
96
|
-
enabled: peerToPeer.lan.isEnabled,
|
|
97
|
-
mdns_enabled: peerToPeer.lan.isMdnsEnabled,
|
|
98
|
-
multicast_enabled: peerToPeer.lan.isMulticastEnabled,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
connect: {
|
|
102
|
-
tcp_servers: connect.tcpServers,
|
|
103
|
-
websocket_urls: connect.websocketURLs,
|
|
104
|
-
retry_interval: connect.retryInterval,
|
|
105
|
-
},
|
|
106
|
-
listen: {
|
|
107
|
-
tcp: {
|
|
108
|
-
enabled: listen.tcp.isEnabled,
|
|
109
|
-
interface_ip: listen.tcp.interfaceIP,
|
|
110
|
-
port: listen.tcp.port,
|
|
111
|
-
},
|
|
112
|
-
http: {
|
|
113
|
-
enabled: listen.http.isEnabled,
|
|
114
|
-
interface_ip: listen.http.interfaceIP,
|
|
115
|
-
port: listen.http.port,
|
|
116
|
-
websocket_sync: listen.http.websocketSync,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
global: {
|
|
120
|
-
sync_group: global.syncGroup,
|
|
121
|
-
routing_hint: global.routingHint,
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Only set the optional properties if they are not undefined
|
|
126
|
-
if (listen.http.staticContentPath) {
|
|
127
|
-
serialized.listen.http['static_content_path'] = listen.http.staticContentPath
|
|
128
|
-
}
|
|
129
|
-
if (listen.http.tlsKeyPath) {
|
|
130
|
-
serialized.listen.http['tls_key_path'] = listen.http.tlsKeyPath
|
|
131
|
-
}
|
|
132
|
-
if (listen.http.tlsCertificatePath) {
|
|
133
|
-
serialized.listen.http['tls_certificate_path'] = listen.http.tlsCertificatePath
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return serialized
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Part of {@link TransportConfig} type, configuration for listening for TCP
|
|
141
|
-
* connections.
|
|
142
|
-
*/
|
|
143
|
-
export interface TransportConfigListenTCP {
|
|
144
|
-
isEnabled: boolean
|
|
145
|
-
interfaceIP: string
|
|
146
|
-
port: number
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Part of {@link TransportConfig} type, configuration for listening for HTTP,
|
|
151
|
-
* including Websocket, connections.
|
|
152
|
-
*/
|
|
153
|
-
export interface TransportConfigListenHTTP {
|
|
154
|
-
isEnabled: boolean
|
|
155
|
-
interfaceIP: string
|
|
156
|
-
port: number
|
|
157
|
-
staticContentPath?: string
|
|
158
|
-
websocketSync: boolean
|
|
159
|
-
tlsKeyPath?: string
|
|
160
|
-
tlsCertificatePath?: string
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Part of {@link TransportConfig} type, configuration for all P2P transports.
|
|
165
|
-
*/
|
|
166
|
-
export interface TransportConfigPeerToPeer {
|
|
167
|
-
bluetoothLE: { isEnabled: boolean }
|
|
168
|
-
awdl: { isEnabled: boolean }
|
|
169
|
-
lan: TransportConfigLan
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Part of {@link TransportConfig} type, configuration for discovering and syncing with peers on LAN.
|
|
174
|
-
*/
|
|
175
|
-
export interface TransportConfigLan {
|
|
176
|
-
isEnabled: boolean
|
|
177
|
-
isMdnsEnabled: boolean
|
|
178
|
-
/**
|
|
179
|
-
* @deprecated Multicast is deprecated. Please use mDNS instead.
|
|
180
|
-
*/
|
|
181
|
-
isMulticastEnabled: boolean
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Part of {@link TransportConfig} type, configuration for connecting to TCP
|
|
186
|
-
* and Websocket servers.
|
|
187
|
-
*/
|
|
188
|
-
export interface TransportConfigConnect {
|
|
189
|
-
tcpServers: string[]
|
|
190
|
-
websocketURLs: string[]
|
|
191
|
-
/**
|
|
192
|
-
* The retry interval in milliseconds between failed connection attempts. For cross-compatibility, this must be less than 2^32 - 1.
|
|
193
|
-
*/
|
|
194
|
-
retryInterval: number
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Part of {@link TransportConfig} type, configuration for listening for
|
|
199
|
-
* incoming TCP and HTTP connections.
|
|
200
|
-
*/
|
|
201
|
-
export interface TransportConfigListen {
|
|
202
|
-
tcp: TransportConfigListenTCP
|
|
203
|
-
http: TransportConfigListenHTTP
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const NO_PREFERRED_ROUTE_HINT = 0
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Part of {@link TransportConfig} type, settings not associated with any specific type of transport.
|
|
210
|
-
*/
|
|
211
|
-
export interface TransportConfigGlobal {
|
|
212
|
-
/**
|
|
213
|
-
* The sync group for this device.
|
|
214
|
-
*
|
|
215
|
-
* When peer-to-peer transports are enabled, all devices with the same App ID will
|
|
216
|
-
* normally form an interconnected mesh network. In some situations it may be
|
|
217
|
-
* desirable to have distinct groups of devices within the same app, so that
|
|
218
|
-
* connections will only be formed within each group. The `syncGroup` parameter
|
|
219
|
-
* changes that group membership. A device can only ever be in one sync group, which
|
|
220
|
-
* by default is group 0. Up to 2^32 distinct group numbers can be used in an app.
|
|
221
|
-
*
|
|
222
|
-
* This is an optimization, not a security control. If a connection is created
|
|
223
|
-
* manually, such as by specifying a `connect` transport, then devices from
|
|
224
|
-
* different sync groups will still sync as normal. If two groups of devices are
|
|
225
|
-
* intended to have access to different data sets, this must be enforced using
|
|
226
|
-
* Ditto's permissions system.
|
|
227
|
-
*/
|
|
228
|
-
syncGroup: number
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* The routing hint for this device.
|
|
232
|
-
*
|
|
233
|
-
* A routing hint is a performance tuning option which can improve the performance of
|
|
234
|
-
* applications that use large collections. Ditto will make a best effort to co-locate data for
|
|
235
|
-
* the same routing key. In most circumstances, this should substantially improve responsiveness
|
|
236
|
-
* of the Ditto Cloud.
|
|
237
|
-
*
|
|
238
|
-
* The value of the routing hint is application specific - you are free to chose any value.
|
|
239
|
-
* Devices which you expect to operate on much the same data should be configured to
|
|
240
|
-
* use the same value.
|
|
241
|
-
*
|
|
242
|
-
* A routing hint does not partition data. The value of the routing hint will not affect the data
|
|
243
|
-
* returned for a query. The routing hint only improves the efficiency of the Cloud's
|
|
244
|
-
* ability to satisfy the query.
|
|
245
|
-
*/
|
|
246
|
-
routingHint: number
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* A configuration object specifying which network transports Ditto should
|
|
251
|
-
* use to sync data.
|
|
252
|
-
*
|
|
253
|
-
* A Ditto object comes with a default transport configuration where all
|
|
254
|
-
* available peer-to-peer transports are enabled. You can customize this by
|
|
255
|
-
* copying that or initializing a new `TransportConfig`, adjusting its
|
|
256
|
-
* properties, and supplying it to `setTransportConfig()` on `Ditto`.
|
|
257
|
-
*
|
|
258
|
-
* When you initialize a new `TransportConfig` instance, all transports are
|
|
259
|
-
* disabled. You must enable each one explicitly.
|
|
260
|
-
*
|
|
261
|
-
* Peer-to-peer transports will automatically discover peers in the vicinity
|
|
262
|
-
* and create connections without any configuration. These are configured via
|
|
263
|
-
* the `peerToPeer` property. To turn each one on, set its `isEnabled` property
|
|
264
|
-
* to `true`.
|
|
265
|
-
*
|
|
266
|
-
* To connect to a peer at a known location, such as a Ditto Big Peer, add its
|
|
267
|
-
* address inside the connect configuration. These are either "host:port"
|
|
268
|
-
* strings for raw TCP sync, or a "wss://…" URL for websockets.
|
|
269
|
-
*
|
|
270
|
-
* The listen configurations are for specific less common data sync scenarios.
|
|
271
|
-
* Please read the documentation on the Ditto website for examples. Incorrect
|
|
272
|
-
* use of listen can result in insecure configurations.
|
|
273
|
-
*
|
|
274
|
-
* **IMPORTANT**: when running in the browser, only the `connect.websocketURLs`
|
|
275
|
-
* part is considered, the rest of the configuration is ignored.
|
|
276
|
-
*/
|
|
277
|
-
export class TransportConfig {
|
|
278
|
-
/** Configuration for peer-to-peer connections. */
|
|
279
|
-
readonly peerToPeer: TransportConfigPeerToPeer
|
|
280
|
-
|
|
281
|
-
/** Configuration for connecting to servers. */
|
|
282
|
-
readonly connect: TransportConfigConnect
|
|
283
|
-
|
|
284
|
-
/** Configuration for listening for incomping connections. */
|
|
285
|
-
readonly listen: TransportConfigListen
|
|
286
|
-
|
|
287
|
-
/** Settings not associated with any specific type of transport. */
|
|
288
|
-
readonly global: TransportConfigGlobal
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Create a new transport config initialized with the default settings.
|
|
292
|
-
*/
|
|
293
|
-
constructor() {
|
|
294
|
-
this.peerToPeer = {
|
|
295
|
-
bluetoothLE: { isEnabled: false },
|
|
296
|
-
awdl: { isEnabled: false },
|
|
297
|
-
lan: { isEnabled: false, isMdnsEnabled: true, isMulticastEnabled: true },
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
this.connect = {
|
|
301
|
-
tcpServers: [],
|
|
302
|
-
websocketURLs: [],
|
|
303
|
-
retryInterval: 5000,
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
this.listen = {
|
|
307
|
-
tcp: {
|
|
308
|
-
isEnabled: false,
|
|
309
|
-
interfaceIP: '[::]',
|
|
310
|
-
port: 4040,
|
|
311
|
-
},
|
|
312
|
-
|
|
313
|
-
http: {
|
|
314
|
-
isEnabled: false,
|
|
315
|
-
interfaceIP: '[::]',
|
|
316
|
-
port: 80,
|
|
317
|
-
websocketSync: true,
|
|
318
|
-
},
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
this.global = {
|
|
322
|
-
syncGroup: 0,
|
|
323
|
-
routingHint: NO_PREFERRED_ROUTE_HINT,
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Enables all peer-to-peer transports. Throws if receiver is frozen.
|
|
329
|
-
*/
|
|
330
|
-
setAllPeerToPeerEnabled(enabled: boolean) {
|
|
331
|
-
this.peerToPeer.bluetoothLE.isEnabled = enabled
|
|
332
|
-
this.peerToPeer.lan.isEnabled = enabled
|
|
333
|
-
this.peerToPeer.awdl.isEnabled = enabled
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Returns `true` if the transport configuration is frozen, otherwise
|
|
338
|
-
* returns `false`.
|
|
339
|
-
*/
|
|
340
|
-
get isFrozen(): boolean {
|
|
341
|
-
return this._isFrozen
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* (Deep) freezes the receiver such that it can't be modified anymore.
|
|
346
|
-
*/
|
|
347
|
-
freeze(): TransportConfig {
|
|
348
|
-
if (this.isFrozen) return this
|
|
349
|
-
this._isFrozen = true
|
|
350
|
-
|
|
351
|
-
Object.freeze(this.peerToPeer.bluetoothLE)
|
|
352
|
-
Object.freeze(this.peerToPeer.awdl)
|
|
353
|
-
Object.freeze(this.peerToPeer.lan)
|
|
354
|
-
Object.freeze(this.peerToPeer)
|
|
355
|
-
|
|
356
|
-
Object.freeze(this.connect.tcpServers)
|
|
357
|
-
Object.freeze(this.connect.websocketURLs)
|
|
358
|
-
Object.freeze(this.connect)
|
|
359
|
-
|
|
360
|
-
Object.freeze(this.listen.tcp)
|
|
361
|
-
Object.freeze(this.listen.http)
|
|
362
|
-
Object.freeze(this.listen)
|
|
363
|
-
|
|
364
|
-
Object.freeze(this.global)
|
|
365
|
-
|
|
366
|
-
return this
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Returns a (deep) copy of the receiver.
|
|
371
|
-
*/
|
|
372
|
-
copy(): TransportConfig {
|
|
373
|
-
const copy = new TransportConfig()
|
|
374
|
-
|
|
375
|
-
copy.peerToPeer.bluetoothLE.isEnabled = this.peerToPeer.bluetoothLE.isEnabled
|
|
376
|
-
copy.peerToPeer.awdl.isEnabled = this.peerToPeer.awdl.isEnabled
|
|
377
|
-
copy.peerToPeer.lan.isEnabled = this.peerToPeer.lan.isEnabled
|
|
378
|
-
copy.peerToPeer.lan.isMdnsEnabled = this.peerToPeer.lan.isMdnsEnabled
|
|
379
|
-
copy.peerToPeer.lan.isMulticastEnabled = this.peerToPeer.lan.isMulticastEnabled
|
|
380
|
-
|
|
381
|
-
copy.connect.tcpServers = this.connect.tcpServers.slice()
|
|
382
|
-
copy.connect.websocketURLs = this.connect.websocketURLs.slice()
|
|
383
|
-
copy.connect.retryInterval = this.connect.retryInterval
|
|
384
|
-
|
|
385
|
-
copy.listen.tcp = { ...this.listen.tcp }
|
|
386
|
-
copy.listen.http = { ...this.listen.http }
|
|
387
|
-
|
|
388
|
-
copy.global.syncGroup = this.global.syncGroup
|
|
389
|
-
copy.global.routingHint = this.global.routingHint
|
|
390
|
-
|
|
391
|
-
return copy
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Returns `true` if passed in TCP configurations are equal, otherwise
|
|
396
|
-
* returns `false`.
|
|
397
|
-
*/
|
|
398
|
-
static areListenTCPsEqual(left: TransportConfigListenTCP, right: TransportConfigListenTCP): boolean {
|
|
399
|
-
/* eslint-disable */
|
|
400
|
-
// prettier-ignore
|
|
401
|
-
return (
|
|
402
|
-
left.isEnabled === right.isEnabled &&
|
|
403
|
-
left.interfaceIP === right.interfaceIP &&
|
|
404
|
-
left.port === right.port
|
|
405
|
-
)
|
|
406
|
-
/* eslint-enable */
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Returns `true` if passed in HTTP configurations are equal, otherwise
|
|
411
|
-
* returns `false`.
|
|
412
|
-
*/
|
|
413
|
-
static areListenHTTPsEqual(left: TransportConfigListenHTTP, right: TransportConfigListenHTTP): boolean {
|
|
414
|
-
/* eslint-disable */
|
|
415
|
-
// prettier-ignore
|
|
416
|
-
return (
|
|
417
|
-
left.isEnabled === right.isEnabled &&
|
|
418
|
-
left.interfaceIP === right.interfaceIP &&
|
|
419
|
-
left.port === right.port &&
|
|
420
|
-
|
|
421
|
-
left.staticContentPath === right.staticContentPath &&
|
|
422
|
-
left.websocketSync === right.websocketSync &&
|
|
423
|
-
left.tlsKeyPath === right.tlsKeyPath &&
|
|
424
|
-
left.tlsCertificatePath === right.tlsCertificatePath
|
|
425
|
-
)
|
|
426
|
-
/* eslint-enable */
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
private _isFrozen: boolean = false
|
|
430
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { DocumentID } from './document-id'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The types of an {@link UpdateResult}.
|
|
9
|
-
*/
|
|
10
|
-
export type UpdateResultType = 'set' | 'incremented' | 'removed'
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Provides information about a successful update operation on a document.
|
|
14
|
-
*
|
|
15
|
-
* The update result can be one of the following types:
|
|
16
|
-
* - `set`
|
|
17
|
-
* - `removed`
|
|
18
|
-
* - `incremented`
|
|
19
|
-
*/
|
|
20
|
-
export class UpdateResult {
|
|
21
|
-
/** The update result's type. */
|
|
22
|
-
readonly type: UpdateResultType
|
|
23
|
-
|
|
24
|
-
/** The ID of the document that was updated. */
|
|
25
|
-
readonly docID: DocumentID
|
|
26
|
-
|
|
27
|
-
/** The path to the key in the document that was updated. */
|
|
28
|
-
readonly path: string
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The associated value for `set` operations. The value will be the new value
|
|
32
|
-
* at the key path.
|
|
33
|
-
*
|
|
34
|
-
* All other types of update results do not have this property set.
|
|
35
|
-
*/
|
|
36
|
-
readonly value?: any
|
|
37
|
-
|
|
38
|
-
/** The associated amount, only set if {@link type} is `incremented`. */
|
|
39
|
-
readonly amount?: number
|
|
40
|
-
|
|
41
|
-
// ----------------------------------------------------------- Internal ------
|
|
42
|
-
|
|
43
|
-
/** @internal */
|
|
44
|
-
static set(docID: DocumentID, path: string, value?: any): UpdateResult {
|
|
45
|
-
return new UpdateResult('set', docID, path, value, undefined)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** @internal */
|
|
49
|
-
static incremented(docID: DocumentID, path: string, amount: number): UpdateResult {
|
|
50
|
-
return new UpdateResult('incremented', docID, path, undefined, amount)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** @internal */
|
|
54
|
-
static removed(docID: DocumentID, path: string): UpdateResult {
|
|
55
|
-
return new UpdateResult('removed', docID, path, undefined, undefined)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @internal */
|
|
59
|
-
private constructor(type: UpdateResultType, docID: DocumentID, path: string, value?: any, amount?: number) {
|
|
60
|
-
this.type = type
|
|
61
|
-
this.docID = docID
|
|
62
|
-
this.path = path
|
|
63
|
-
if (value !== undefined) this.value = value
|
|
64
|
-
if (amount !== undefined) this.amount = amount
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { DocumentID } from './document-id'
|
|
6
|
-
import { UpdateResult } from './update-result'
|
|
7
|
-
|
|
8
|
-
import type { DocumentIDValue } from './document-id'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Maps a {@link DocumentID} to an array of
|
|
12
|
-
* {@link UpdateResult | update results}. This is the data structure you get
|
|
13
|
-
* when {@link PendingCursorOperation.update | updating} a set of documents
|
|
14
|
-
* with detailed info about the performed updates.
|
|
15
|
-
*/
|
|
16
|
-
export class UpdateResultsMap {
|
|
17
|
-
/**
|
|
18
|
-
* Returns an array of {@link UpdateResult | update results} associated with
|
|
19
|
-
* the `documentID` or undefined if not found.
|
|
20
|
-
*/
|
|
21
|
-
get(documentIDOrValue: DocumentID | DocumentIDValue): UpdateResult[] | undefined {
|
|
22
|
-
const documentID: DocumentID = documentIDOrValue instanceof DocumentID ? documentIDOrValue : new DocumentID(documentIDOrValue)
|
|
23
|
-
const documentIDString = documentID.toString()
|
|
24
|
-
return this.updateResultsByDocumentIDString[documentIDString]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns all contained keys, i.e. {@link DocumentID | document IDs}
|
|
29
|
-
* contained in this map.
|
|
30
|
-
*/
|
|
31
|
-
keys(): DocumentID[] {
|
|
32
|
-
return this.documentIDs.slice()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ----------------------------------------------------------- Internal ------
|
|
36
|
-
|
|
37
|
-
/** @internal */
|
|
38
|
-
constructor(documentIDs: DocumentID[], updateResultsByDocumentIDString: object) {
|
|
39
|
-
// REFACTOR: this quick & dirty implementation assumes Document.toString()
|
|
40
|
-
// to be isomorphic, i.e. id1.equals(id2) <==> id1.toString() == id2.toString(),
|
|
41
|
-
// which isn't the case in certain edge cases. Fix by implementing a proper
|
|
42
|
-
// data structure ensuring correctness. One idea would be to use toString()
|
|
43
|
-
// as a hash value and add a check plus conflict resolution after lookup.
|
|
44
|
-
// Another idea would be to check for isomorphism for the particular subset
|
|
45
|
-
// that is passed in and fallback to O(n) linear array search if not.
|
|
46
|
-
|
|
47
|
-
const documentIDStrings = documentIDs
|
|
48
|
-
.map((documentID) => documentID.toString())
|
|
49
|
-
.sort()
|
|
50
|
-
.join(', ')
|
|
51
|
-
const updateResultsKeys = Object.keys(updateResultsByDocumentIDString).sort().join(', ')
|
|
52
|
-
|
|
53
|
-
if (documentIDStrings !== updateResultsKeys) {
|
|
54
|
-
throw new Error("Internal inconsistency, can't construct update results map, documentIDs must all be keys in update results (by document ID string)")
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.documentIDs = documentIDs.slice()
|
|
58
|
-
this.updateResultsByDocumentIDString = { ...updateResultsByDocumentIDString }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ------------------------------------------------------------ Private ------
|
|
62
|
-
|
|
63
|
-
private documentIDs: DocumentID[]
|
|
64
|
-
private updateResultsByDocumentIDString: object
|
|
65
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2023 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as FFI from './ffi'
|
|
6
|
-
|
|
7
|
-
import { Bridge } from './bridge'
|
|
8
|
-
import { CBOR } from './cbor'
|
|
9
|
-
import { desugarJSObject } from './augment'
|
|
10
|
-
import { DocumentID } from './document-id'
|
|
11
|
-
import { performAsyncToWorkaroundNonAsyncFFIAPI } from './internal'
|
|
12
|
-
import { WriteTransactionPendingCursorOperation } from './write-transaction-pending-cursor-operation'
|
|
13
|
-
import { WriteTransactionPendingIDSpecificOperation } from './write-transaction-pending-id-specific-operation'
|
|
14
|
-
|
|
15
|
-
import type { Store } from './store'
|
|
16
|
-
import type { QueryArguments } from './essentials'
|
|
17
|
-
import type { DocumentValue } from './document'
|
|
18
|
-
import type { CollectionInterface, UpsertOptions } from './collection-interface'
|
|
19
|
-
import type { WriteTransaction } from './write-transaction'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Represents a collection of a Ditto store that is used in the context of a
|
|
23
|
-
* write transaction.
|
|
24
|
-
*
|
|
25
|
-
* Supports most of a regular {@link Collection | collection}'s functionality
|
|
26
|
-
* but cannot be subscribed or live queried and can not be used to create
|
|
27
|
-
* attachments.
|
|
28
|
-
*
|
|
29
|
-
* Create a `WriteTransactionCollection` by starting a {@link WriteTransaction}
|
|
30
|
-
* and using its `scoped` method.
|
|
31
|
-
*/
|
|
32
|
-
export class WriteTransactionCollection implements CollectionInterface {
|
|
33
|
-
/** The name of the collection. */
|
|
34
|
-
readonly name: string
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The store this collection belongs to.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
readonly store: Store
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The write transaction within which this collection instance is used.
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
readonly writeTransaction: WriteTransaction
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Search for documents in this collection using the provided query string.
|
|
50
|
-
*
|
|
51
|
-
* The returned cursor operation can be used to chain operations on the
|
|
52
|
-
* resulting document set.
|
|
53
|
-
*
|
|
54
|
-
* @param query The query to run against the collection.
|
|
55
|
-
* @param queryArgs These arguments replace placeholders in the provided
|
|
56
|
-
* query.
|
|
57
|
-
*/
|
|
58
|
-
find(query: string, queryArgs?: QueryArguments | undefined): WriteTransactionPendingCursorOperation {
|
|
59
|
-
return new WriteTransactionPendingCursorOperation(query, queryArgs ?? null, this)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Convenience method, equivalent to calling {@link find | find()} and passing
|
|
64
|
-
* the query `"true"`.
|
|
65
|
-
*/
|
|
66
|
-
findAll(): WriteTransactionPendingCursorOperation {
|
|
67
|
-
return this.find('true')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Generates a {@link WriteTransactionPendingIDSpecificOperation} with the
|
|
72
|
-
* provided document ID.
|
|
73
|
-
*
|
|
74
|
-
* The returned object can be used to find and return the document. It can also be used to update, remove or evict the document.
|
|
75
|
-
*
|
|
76
|
-
* @param id The ID of the document to find.
|
|
77
|
-
*/
|
|
78
|
-
findByID(id: any): WriteTransactionPendingIDSpecificOperation {
|
|
79
|
-
const documentID: DocumentID = id instanceof DocumentID ? id : new DocumentID(id)
|
|
80
|
-
return new WriteTransactionPendingIDSpecificOperation(documentID, this)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async upsert(value: DocumentValue, options: UpsertOptions = {}): Promise<DocumentID> {
|
|
84
|
-
const ditto = this.store.ditto
|
|
85
|
-
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
86
|
-
return ditto.deferCloseAsync(async () => {
|
|
87
|
-
const writeStrategy = options.writeStrategy ?? 'merge'
|
|
88
|
-
|
|
89
|
-
const documentValueJSON = desugarJSObject(value)
|
|
90
|
-
const documentValueCBOR = CBOR.encode(documentValueJSON)
|
|
91
|
-
|
|
92
|
-
const idCBOR = await performAsyncToWorkaroundNonAsyncFFIAPI(async () => {
|
|
93
|
-
return await FFI.collectionInsertValue(dittoHandle.deref(), this.name, documentValueCBOR, writeStrategy, this.writeTransaction.writeTransactionPointer)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const insertedDocumentId = new DocumentID(idCBOR, true)
|
|
97
|
-
this.writeTransaction.addResult('inserted', insertedDocumentId, this.name)
|
|
98
|
-
|
|
99
|
-
return new DocumentID(idCBOR, true)
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* See comment in {@link CollectionInterface.findByIDCBOR()}
|
|
105
|
-
*
|
|
106
|
-
* @internal */
|
|
107
|
-
findByIDCBOR(idCBOR: Uint8Array): WriteTransactionPendingIDSpecificOperation {
|
|
108
|
-
const documentID = new DocumentID(idCBOR, true, true)
|
|
109
|
-
return new WriteTransactionPendingIDSpecificOperation(documentID, this)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* This constructor is marked internal because write transaction collections
|
|
114
|
-
* should be created from a {@link WriteTransaction} instance.
|
|
115
|
-
*
|
|
116
|
-
* @internal */
|
|
117
|
-
constructor(name: string, store: Store, writeTransaction: WriteTransaction) {
|
|
118
|
-
this.name = name
|
|
119
|
-
this.store = store
|
|
120
|
-
this.writeTransaction = writeTransaction
|
|
121
|
-
}
|
|
122
|
-
}
|