@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,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// IMPORTANT: this file is only for exporting public API, please don't
|
|
6
|
-
// add "significant" logic in here (sort of a "Framework Header" in ObjC).
|
|
7
|
-
|
|
8
|
-
export * from './keep-alive'
|
|
9
|
-
export * from './observer'
|
|
10
|
-
|
|
11
|
-
export * from './essentials'
|
|
12
|
-
export * from './counter'
|
|
13
|
-
export * from './register'
|
|
14
|
-
export * from './attachment-token'
|
|
15
|
-
|
|
16
|
-
export * from './init'
|
|
17
|
-
export * from './logger'
|
|
18
|
-
export * from './document-id'
|
|
19
|
-
|
|
20
|
-
export * from './base-pending-cursor-operation'
|
|
21
|
-
export * from './base-pending-id-specific-operation'
|
|
22
|
-
export * from './connection-request'
|
|
23
|
-
export * from './authenticator'
|
|
24
|
-
export * from './identity'
|
|
25
|
-
export * from './ditto'
|
|
26
|
-
export * from './store-observer'
|
|
27
|
-
export * from './collection'
|
|
28
|
-
export * from './collection-interface'
|
|
29
|
-
export * from './collections-event'
|
|
30
|
-
export * from './document-path'
|
|
31
|
-
export * from './document'
|
|
32
|
-
export * from './sync'
|
|
33
|
-
export * from './sync-subscription'
|
|
34
|
-
export * from './error'
|
|
35
|
-
export * from './error-codes'
|
|
36
|
-
export * from './query-result-item'
|
|
37
|
-
export * from './query-result'
|
|
38
|
-
export * from './live-query-event'
|
|
39
|
-
export * from './live-query'
|
|
40
|
-
export * from './attachment'
|
|
41
|
-
export * from './attachment-fetcher'
|
|
42
|
-
export * from './attachment-fetch-event'
|
|
43
|
-
export * from './pending-cursor-operation'
|
|
44
|
-
export * from './pending-id-specific-operation'
|
|
45
|
-
export * from './pending-collections-operation'
|
|
46
|
-
export * from './small-peer-info'
|
|
47
|
-
export * from './store'
|
|
48
|
-
export * from './presence'
|
|
49
|
-
export * from './subscription'
|
|
50
|
-
export * from './test-helpers'
|
|
51
|
-
export * from './transport-config'
|
|
52
|
-
export * from './update-result'
|
|
53
|
-
export * from './update-results-map'
|
|
54
|
-
export * from './write-transaction'
|
|
55
|
-
export * from './write-transaction-collection'
|
|
56
|
-
export * from './write-transaction-pending-cursor-operation'
|
|
57
|
-
export * from './write-transaction-pending-id-specific-operation'
|
|
58
|
-
export * from './epilogue'
|
|
59
|
-
|
|
60
|
-
// TEMPORARY: exported to deal with non-canonical IDs.
|
|
61
|
-
export * from './cbor'
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { generateEphemeralToken } from './internal'
|
|
6
|
-
import { KeepAlive } from './keep-alive'
|
|
7
|
-
|
|
8
|
-
/** @internal */
|
|
9
|
-
export type ObserverToken = string
|
|
10
|
-
|
|
11
|
-
/** @internal */
|
|
12
|
-
export type ObserverManagerConstructorOptions = {
|
|
13
|
-
keepAlive?: KeepAlive
|
|
14
|
-
register?: (callback: (...args: any[]) => void) => void
|
|
15
|
-
unregister?: () => void
|
|
16
|
-
process?: (...args: any[]) => any[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
export class ObserverManager {
|
|
21
|
-
/** @internal */
|
|
22
|
-
readonly id: string
|
|
23
|
-
|
|
24
|
-
/** @internal */
|
|
25
|
-
readonly keepAlive: KeepAlive | null
|
|
26
|
-
|
|
27
|
-
/** @internal */
|
|
28
|
-
constructor(id: string, options: ObserverManagerConstructorOptions = {}) {
|
|
29
|
-
const keepAlive = options.keepAlive ?? null
|
|
30
|
-
const register = options.register ?? null
|
|
31
|
-
const unregister = options.unregister ?? null
|
|
32
|
-
const process = options.process ?? null
|
|
33
|
-
|
|
34
|
-
this.id = id
|
|
35
|
-
this.keepAlive = keepAlive
|
|
36
|
-
|
|
37
|
-
this.isClosed = false
|
|
38
|
-
this.isRegistered = false
|
|
39
|
-
this.callbacksByToken = {}
|
|
40
|
-
|
|
41
|
-
if (register !== null) {
|
|
42
|
-
this.register = register
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (unregister !== null) {
|
|
46
|
-
this.unregister = unregister
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (process !== null) {
|
|
50
|
-
this.process = process
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @internal */
|
|
55
|
-
addObserver(callback: any): ObserverToken {
|
|
56
|
-
if (this.isClosed) {
|
|
57
|
-
// REFACTOR: throw a catchable error here, such that calling code
|
|
58
|
-
// can be more specific when forwarding it to the user.
|
|
59
|
-
throw new Error(`Internal inconsistency, can't add '${this.id}' observer, observer mananger close()-ed.`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.registerIfNeeded()
|
|
63
|
-
|
|
64
|
-
const token = generateEphemeralToken()
|
|
65
|
-
this.callbacksByToken[token] = callback
|
|
66
|
-
|
|
67
|
-
this.keepAlive?.retain(`${this.id}.${token}`)
|
|
68
|
-
return token
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** @internal */
|
|
72
|
-
removeObserver(token: ObserverToken): void {
|
|
73
|
-
const callback = this.callbacksByToken[token]
|
|
74
|
-
|
|
75
|
-
if (typeof callback === 'undefined') {
|
|
76
|
-
throw new Error(`Can't remove '${this.id}' observer, token '${token}' has never been registered before.`)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (callback === null) {
|
|
80
|
-
// Observer has already been removed, no-op.
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// REFACTOR: not deleting the token here will keep eating up
|
|
85
|
-
// memory over long periods of time. We actually need to track
|
|
86
|
-
// the observer objects themselves and remove it from the table
|
|
87
|
-
// as soon as the observer object is garbage collected.
|
|
88
|
-
|
|
89
|
-
// The value is set to null to be able to discern between
|
|
90
|
-
// observers that have been removed and observers that have
|
|
91
|
-
// never been registered before.
|
|
92
|
-
this.callbacksByToken[token] = null
|
|
93
|
-
|
|
94
|
-
this.keepAlive?.release(`${this.id}.${token}`)
|
|
95
|
-
this.unregisterIfNeeded()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
hasObserver(token: ObserverToken): boolean {
|
|
99
|
-
return typeof this.callbacksByToken[token] != 'undefined'
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** @internal */
|
|
103
|
-
notify(...args: any[]) {
|
|
104
|
-
if (this.isClosed) {
|
|
105
|
-
// NOTE: we don't notify observers after closing and just swallow
|
|
106
|
-
// the event.
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const processedArgs = this.process(...args)
|
|
111
|
-
for (const token in this.callbacksByToken) {
|
|
112
|
-
const callback = this.callbacksByToken[token]
|
|
113
|
-
if (callback) callback(...processedArgs)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** @internal */
|
|
118
|
-
close() {
|
|
119
|
-
this.isClosed = true
|
|
120
|
-
for (const token in this.callbacksByToken) {
|
|
121
|
-
this.removeObserver(token)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Can be injected and replaced via constructor options.
|
|
127
|
-
*
|
|
128
|
-
* @abstract
|
|
129
|
-
*/
|
|
130
|
-
protected register(callback: (...args: any[]) => void) {
|
|
131
|
-
// No-op, subclasses may override and register.
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Can be injected and replaced via constructor options.
|
|
136
|
-
*
|
|
137
|
-
* @abstract
|
|
138
|
-
*/
|
|
139
|
-
protected unregister() {
|
|
140
|
-
// No-op, subclasses may override and unregister.
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Can be injected and replaced via constructor options.
|
|
145
|
-
*
|
|
146
|
-
* @abstract
|
|
147
|
-
*/
|
|
148
|
-
protected process(...args: any[]): any[] {
|
|
149
|
-
// No-op, subclasses may override and process/transform the callback parameters.
|
|
150
|
-
return args
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private isClosed: boolean
|
|
154
|
-
private isRegistered: boolean
|
|
155
|
-
private callbacksByToken: { [key: string]: ((...args: any[]) => void) | null }
|
|
156
|
-
private constructorOptions: ObserverManagerConstructorOptions
|
|
157
|
-
|
|
158
|
-
private hasObservers(): boolean {
|
|
159
|
-
return Object.keys(this.callbacksByToken).length > 0
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private registerIfNeeded() {
|
|
163
|
-
const needsToRegister = !this.isRegistered
|
|
164
|
-
if (needsToRegister) {
|
|
165
|
-
const weakThis = new WeakRef(this)
|
|
166
|
-
this.isRegistered = true
|
|
167
|
-
this.register(function (...args) {
|
|
168
|
-
const strongThis = weakThis.deref()
|
|
169
|
-
if (!strongThis) {
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
strongThis.notify(...args)
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private unregisterIfNeeded() {
|
|
179
|
-
const needsToUnregister = !this.hasObservers() && this.isRegistered
|
|
180
|
-
if (needsToUnregister) {
|
|
181
|
-
this.isRegistered = false
|
|
182
|
-
this.unregister()
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { ObserverToken } from './observer-manager'
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
interface ObserverManaging {
|
|
9
|
-
hasObserver(token: ObserverToken): boolean
|
|
10
|
-
removeObserver(token: ObserverToken): void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
14
|
-
export type ObserverOptions = {
|
|
15
|
-
stopsWhenFinalized?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Generic observer handle returned by various observation APIs. The observation
|
|
20
|
-
* remains active until the {@link stop | stop()} method is called explicitly or
|
|
21
|
-
* the observer instance is garbage collected. Therefore, to keep the observation
|
|
22
|
-
* alive, you have to keep a reference to the corresponding observer.
|
|
23
|
-
*/
|
|
24
|
-
export class Observer {
|
|
25
|
-
// NOTE: the core functionality of the observer manager is token-based. We use
|
|
26
|
-
// the `Observer` class merely as a public API wrapper around the token
|
|
27
|
-
// exposing a convenience `stop()` method plus life-cycle tracking.
|
|
28
|
-
|
|
29
|
-
/** @internal */
|
|
30
|
-
readonly observerManager: ObserverManaging
|
|
31
|
-
|
|
32
|
-
/** @internal */
|
|
33
|
-
get token(): ObserverToken | undefined {
|
|
34
|
-
return this._token
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @internal */
|
|
38
|
-
readonly options?: ObserverOptions
|
|
39
|
-
|
|
40
|
-
/** @internal */
|
|
41
|
-
constructor(observerManager: ObserverManaging, token: any, options: ObserverOptions = {}) {
|
|
42
|
-
this.observerManager = observerManager
|
|
43
|
-
this._token = token
|
|
44
|
-
this.options = options
|
|
45
|
-
|
|
46
|
-
if (options.stopsWhenFinalized) {
|
|
47
|
-
Observer.finalizationRegistry.register(this, { observerManager, token }, this)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Returns `true` if the observer has been explicitly stopped via the `stop()`
|
|
53
|
-
* method. Otherwise returns `false`.
|
|
54
|
-
*/
|
|
55
|
-
get isStopped(): boolean {
|
|
56
|
-
return this.token !== undefined && this.observerManager.hasObserver(this.token)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Stops the observation. Calling this method multiple times has no effect.
|
|
61
|
-
*/
|
|
62
|
-
stop() {
|
|
63
|
-
const token = this.token
|
|
64
|
-
if (token) {
|
|
65
|
-
delete this._token
|
|
66
|
-
Observer.finalizationRegistry.unregister(this)
|
|
67
|
-
this.observerManager.removeObserver(token)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private static finalizationRegistry = new FinalizationRegistry(Observer.finalize)
|
|
72
|
-
|
|
73
|
-
private _token?: ObserverToken
|
|
74
|
-
|
|
75
|
-
private static finalize(observerManagerAndToken: { observerManager: ObserverManaging; token: ObserverToken }) {
|
|
76
|
-
const { observerManager, token } = observerManagerAndToken
|
|
77
|
-
observerManager.removeObserver(token)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright (c) 2020 - 2021 DittoLive Inc. All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Collection } from './collection'
|
|
6
|
-
import { Document } from './document'
|
|
7
|
-
import { Subscription } from './subscription'
|
|
8
|
-
import { PendingCursorOperation } from './pending-cursor-operation'
|
|
9
|
-
|
|
10
|
-
import { CollectionsEvent } from './collections-event'
|
|
11
|
-
import { LiveQuery } from './live-query'
|
|
12
|
-
|
|
13
|
-
import type { QueryObservationHandler } from './pending-cursor-operation'
|
|
14
|
-
import type { SortDirection } from './essentials'
|
|
15
|
-
import type { Store } from './store'
|
|
16
|
-
// -----------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The closure that is called whenever the collections covered by a live query
|
|
20
|
-
* change.
|
|
21
|
-
*/
|
|
22
|
-
export type CollectionsObservationHandler = (event: CollectionsEvent, signalNext?: () => void) => void | Promise<void>
|
|
23
|
-
|
|
24
|
-
// -----------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* These objects are returned when calling
|
|
28
|
-
* {@link Store.collections | collections()} on {@link Store}.
|
|
29
|
-
*
|
|
30
|
-
* They allow chaining of further collections-related functions. You can either
|
|
31
|
-
* call {@link exec | exec()} on the object to get an array of
|
|
32
|
-
* {@link Collection}s as an immediate return value, or you can establish either
|
|
33
|
-
* a live query or a subscription, which both work over time.
|
|
34
|
-
*
|
|
35
|
-
* A live query, established by calling
|
|
36
|
-
* {@link PendingCollectionsOperation.observeLocal | observeLocal()}, will
|
|
37
|
-
* notify you every time there's a change in the collections that the device
|
|
38
|
-
* knows about.
|
|
39
|
-
*
|
|
40
|
-
* A subscription, established by calling {@link subscribe | subscribe()}, will
|
|
41
|
-
* act as a signal to other peers that the device connects to that you would
|
|
42
|
-
* like to receive updates from them about the collections that they know about.
|
|
43
|
-
*/
|
|
44
|
-
export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
|
|
45
|
-
/**
|
|
46
|
-
* Sort the collections based on a property of the collection.
|
|
47
|
-
*
|
|
48
|
-
* @param propertyPath The property path specifies the logic to be used when
|
|
49
|
-
* sorting the matching collections.
|
|
50
|
-
*
|
|
51
|
-
* @param direction Specify whether you want the sorting order to be
|
|
52
|
-
* `Ascending` or `Descending`.
|
|
53
|
-
*
|
|
54
|
-
* @return A {@link PendingCollectionsOperation} that you can chain further
|
|
55
|
-
* function calls to.
|
|
56
|
-
*/
|
|
57
|
-
sort(propertyPath: string, direction: SortDirection = 'ascending'): PendingCollectionsOperation {
|
|
58
|
-
// The return value is ignored here because we don't want to await the
|
|
59
|
-
// completion of the operation at this point.
|
|
60
|
-
void this.pendingCursorOperation.sort(propertyPath, direction)
|
|
61
|
-
return this
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Offset the resulting set of collections.
|
|
66
|
-
*
|
|
67
|
-
* This is useful if you aren't interested in the first N collections for one
|
|
68
|
-
* reason or another. For example, you might already have obtained the first
|
|
69
|
-
* 20 collections and so you might want to get the next 20 collections, and
|
|
70
|
-
* that is when you would use {@link offset | offset()}.
|
|
71
|
-
*
|
|
72
|
-
* @param offset The number of collections that you want the eventual
|
|
73
|
-
* resulting set of collections to be offset by (and thus not include).
|
|
74
|
-
*
|
|
75
|
-
* @return A {@link PendingCollectionsOperation} that you can chain further
|
|
76
|
-
* function calls to.
|
|
77
|
-
*/
|
|
78
|
-
offset(offset: number): PendingCollectionsOperation {
|
|
79
|
-
// The return value is ignored here because we don't want to await the
|
|
80
|
-
// completion of the operation at this point.
|
|
81
|
-
void this.pendingCursorOperation.offset(offset)
|
|
82
|
-
return this
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Limit the number of collections that get returned.
|
|
87
|
-
*
|
|
88
|
-
* @param limit The maximum number of collections that will be returned.
|
|
89
|
-
*
|
|
90
|
-
* @return A {@link PendingCollectionsOperation} that you can chain further
|
|
91
|
-
* function calls to.
|
|
92
|
-
*/
|
|
93
|
-
limit(limit: number): PendingCollectionsOperation {
|
|
94
|
-
// The return value is ignored here because we don't want to await the
|
|
95
|
-
// completion of the operation at this point.
|
|
96
|
-
void this.pendingCursorOperation.limit(limit)
|
|
97
|
-
return this
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Subscribes the device to updates about collections that other devices know
|
|
102
|
-
* about.
|
|
103
|
-
*
|
|
104
|
-
* The returned {@link Subscription} object must be kept in scope for as long
|
|
105
|
-
* as you want to keep receiving updates.
|
|
106
|
-
*
|
|
107
|
-
* @return A {@link Subscription} object that must be kept in scope for as
|
|
108
|
-
* long as you want to keep receiving updates from other devices about the
|
|
109
|
-
* collections that they know about.
|
|
110
|
-
*/
|
|
111
|
-
subscribe(): Subscription {
|
|
112
|
-
return this.pendingCursorOperation.subscribe()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Enables you to listen for changes that occur in relation to the collections
|
|
117
|
-
* that are known about locally.
|
|
118
|
-
*
|
|
119
|
-
* The returned {@link LiveQuery} object must be kept in scope for as long as
|
|
120
|
-
* you want the provided `handler` to be called when an update occurs.
|
|
121
|
-
*
|
|
122
|
-
* This won't subscribe to receive updates from other devices and so it will
|
|
123
|
-
* only fire when a local change to the known about collections occurs. If
|
|
124
|
-
* you want to receive remote updates as well, then create a subscription via
|
|
125
|
-
* {@link PendingCollectionsOperation.subscribe | subscribe()}.
|
|
126
|
-
*
|
|
127
|
-
* @param handler A closure that will be called every time there is an update
|
|
128
|
-
* about the list of known about collections.
|
|
129
|
-
*
|
|
130
|
-
* @return A {@link LiveQuery} object that must be kept in scope for as long
|
|
131
|
-
* as you want to keep receiving updates.
|
|
132
|
-
*/
|
|
133
|
-
observeLocal(handler: CollectionsObservationHandler): LiveQuery {
|
|
134
|
-
return this._observe(handler, false)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Enables you to listen for changes that occur in relation to the collections
|
|
139
|
-
* that are known about locally.
|
|
140
|
-
*
|
|
141
|
-
* The returned {@link LiveQuery} object must be kept in scope for as long as
|
|
142
|
-
* you want the provided `handler` to be called when an update occurs.
|
|
143
|
-
*
|
|
144
|
-
* This won't subscribe to receive updates from other devices and so it will
|
|
145
|
-
* only fire when a local change to the known about collections occurs. If
|
|
146
|
-
* you want to receive remote updates as well, then create a subscription via
|
|
147
|
-
* {@link PendingCollectionsOperation.subscribe | subscribe()}.
|
|
148
|
-
*
|
|
149
|
-
* @param handler A closure that will be called every time there is an update
|
|
150
|
-
* about the list of known about collections.
|
|
151
|
-
*
|
|
152
|
-
* @return A {@link LiveQuery} object that must be kept in scope for as long
|
|
153
|
-
* as you want to keep receiving updates.
|
|
154
|
-
*/
|
|
155
|
-
observeLocalWithNextSignal(handler: CollectionsObservationHandler): LiveQuery {
|
|
156
|
-
return this._observe(handler, true)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Return the list of collections requested based on the preceding function
|
|
161
|
-
* chaining.
|
|
162
|
-
*
|
|
163
|
-
* @return A list of {@link Collection}s based on the preceding function
|
|
164
|
-
* chaining.
|
|
165
|
-
*/
|
|
166
|
-
async exec(): Promise<Collection[]> {
|
|
167
|
-
const documents = await this.pendingCursorOperation.exec()
|
|
168
|
-
return collectionsFromDocuments(documents, this.store)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** @internal */
|
|
172
|
-
readonly store: Store
|
|
173
|
-
|
|
174
|
-
/** @internal */
|
|
175
|
-
constructor(store: Store) {
|
|
176
|
-
this.store = store
|
|
177
|
-
this.pendingCursorOperation = new PendingCursorOperation('true', null, new Collection('__collections', store))
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** @internal */
|
|
181
|
-
then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2> {
|
|
182
|
-
return this.exec().then(onfulfilled, onrejected)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ----------------------------------------------------------- Internal ------
|
|
186
|
-
|
|
187
|
-
/** @internal */
|
|
188
|
-
_observe(handler: CollectionsObservationHandler, waitForNextSignal: boolean): LiveQuery {
|
|
189
|
-
const weakStore = new WeakRef(this.store)
|
|
190
|
-
const collectionsObservationHandler: QueryObservationHandler = function (documents, event, nextSignal) {
|
|
191
|
-
const strongStore = weakStore.deref()
|
|
192
|
-
if (!strongStore) {
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const collections = collectionsFromDocuments(documents, strongStore)
|
|
197
|
-
let collEvent: CollectionsEvent
|
|
198
|
-
|
|
199
|
-
if (event.isInitial === true) {
|
|
200
|
-
collEvent = CollectionsEvent.initial(collections)
|
|
201
|
-
} else {
|
|
202
|
-
const oldCollections = collectionsFromDocuments(event.oldDocuments, strongStore)
|
|
203
|
-
collEvent = new CollectionsEvent({
|
|
204
|
-
isInitial: false,
|
|
205
|
-
collections,
|
|
206
|
-
oldCollections,
|
|
207
|
-
insertions: event.insertions,
|
|
208
|
-
deletions: event.deletions,
|
|
209
|
-
updates: event.updates,
|
|
210
|
-
moves: event.moves,
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// The handler return promises are ignored here because we are not
|
|
215
|
-
// handling errors during handler execution.
|
|
216
|
-
if (waitForNextSignal) {
|
|
217
|
-
void handler(collEvent, nextSignal)
|
|
218
|
-
} else {
|
|
219
|
-
void handler(collEvent)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return this.pendingCursorOperation._observe(collectionsObservationHandler, waitForNextSignal)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// ------------------------------------------------------------ Private ------
|
|
227
|
-
|
|
228
|
-
private readonly pendingCursorOperation: PendingCursorOperation
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** @private */
|
|
232
|
-
function collectionsFromDocuments(documents: Document[], store: Store): Collection[] {
|
|
233
|
-
const collections: Collection[] = []
|
|
234
|
-
for (const document of documents) {
|
|
235
|
-
const collectionName = document.at('name').value
|
|
236
|
-
if (collectionName !== undefined && typeof collectionName === 'string') {
|
|
237
|
-
collections.push(new Collection(collectionName, store))
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return collections
|
|
241
|
-
}
|