@dittolive/ditto 4.7.0 → 4.7.1-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +2 -2
  2. package/node/ditto.cjs.js +70 -56
  3. package/node/ditto.darwin-arm64.node +0 -0
  4. package/node/ditto.darwin-x64.node +0 -0
  5. package/node/ditto.linux-arm.node +0 -0
  6. package/node/ditto.linux-arm64.node +0 -0
  7. package/node/ditto.linux-x64.node +0 -0
  8. package/node/ditto.win32-x64.node +0 -0
  9. package/node/transports.darwin-arm64.node +0 -0
  10. package/node/transports.darwin-x64.node +0 -0
  11. package/package.json +1 -1
  12. package/react-native/android/build.gradle +1 -1
  13. package/react-native/src/sources/@ditto.core.ts +1 -1
  14. package/react-native/src/sources/@environment.ts +1 -1
  15. package/react-native/src/sources/attachment-fetcher-manager.ts +1 -1
  16. package/react-native/src/sources/attachment-fetcher.ts +2 -2
  17. package/react-native/src/sources/bridge.ts +1 -1
  18. package/react-native/src/sources/ditto.ts +7 -3
  19. package/react-native/src/sources/ffi.ts +16 -11
  20. package/react-native/src/sources/live-query-manager.ts +3 -4
  21. package/react-native/src/sources/live-query.ts +2 -1
  22. package/react-native/src/sources/pending-collections-operation.ts +15 -6
  23. package/react-native/src/sources/pending-cursor-operation.ts +2 -2
  24. package/react-native/src/sources/pending-id-specific-operation.ts +3 -3
  25. package/react-native/src/sources/presence-manager.ts +8 -9
  26. package/react-native/src/sources/presence.ts +6 -6
  27. package/react-native/src/sources/small-peer-info.ts +2 -2
  28. package/react-native/src/sources/store-observer.ts +1 -1
  29. package/react-native/src/sources/store.ts +5 -2
  30. package/react-native/src/sources/subscription-manager.ts +12 -12
  31. package/react-native/src/sources/subscription.ts +2 -2
  32. package/types/ditto.d.ts +8 -4
  33. package/web/ditto.es6.js +1 -1
  34. package/web/ditto.umd.js +1 -1
  35. package/web/ditto.wasm +0 -0
  36. package/react-native/android/.project +0 -34
  37. package/react-native/android/bin/.project +0 -34
  38. package/react-native/android/bin/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.class +0 -0
  39. package/react-native/android/bin/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.class +0 -0
  40. package/react-native/android/build/intermediates/cxx/abi_configuration_4i3a4k2a.json +0 -14
  41. package/react-native/android/build/intermediates/cxx/abi_configuration_4i3a4k2a.log +0 -1
  42. package/react-native/android/build/intermediates/cxx/abi_configuration_4i3a4k2a_key.json +0 -23
  43. package/react-native/android/build/intermediates/cxx/create_cxx_tasks_371_timing.txt +0 -5
  44. package/react-native/android/build/intermediates/cxx/ndk_locator_record_4q2c3f1f.json +0 -11
  45. package/react-native/android/build/intermediates/cxx/ndk_locator_record_4q2c3f1f.log +0 -72
  46. package/react-native/android/build/intermediates/cxx/ndk_locator_record_4q2c3f1f_key.json +0 -10
@@ -136,7 +136,8 @@ export class LiveQuery {
136
136
  })
137
137
  }
138
138
 
139
- handler(documents, event, signalNext)
139
+ // We discard the return promise because error-handling is not supported.
140
+ void handler(documents, event, signalNext)
140
141
  })
141
142
  })
142
143
 
@@ -10,6 +10,7 @@ import { PendingCursorOperation } from './pending-cursor-operation'
10
10
  import { CollectionsEvent } from './collections-event'
11
11
  import { LiveQuery } from './live-query'
12
12
 
13
+ import type { QueryObservationHandler } from './pending-cursor-operation'
13
14
  import type { SortDirection } from './essentials'
14
15
  import type { Store } from './store'
15
16
  // -----------------------------------------------------------------------------
@@ -54,7 +55,9 @@ export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
54
55
  * function calls to.
55
56
  */
56
57
  sort(propertyPath: string, direction: SortDirection = 'ascending'): PendingCollectionsOperation {
57
- this.pendingCursorOperation.sort(propertyPath, direction)
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)
58
61
  return this
59
62
  }
60
63
 
@@ -73,7 +76,9 @@ export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
73
76
  * function calls to.
74
77
  */
75
78
  offset(offset: number): PendingCollectionsOperation {
76
- this.pendingCursorOperation.offset(offset)
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)
77
82
  return this
78
83
  }
79
84
 
@@ -86,7 +91,9 @@ export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
86
91
  * function calls to.
87
92
  */
88
93
  limit(limit: number): PendingCollectionsOperation {
89
- this.pendingCursorOperation.limit(limit)
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)
90
97
  return this
91
98
  }
92
99
 
@@ -180,7 +187,7 @@ export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
180
187
  /** @internal */
181
188
  _observe(handler: CollectionsObservationHandler, waitForNextSignal: boolean): LiveQuery {
182
189
  const weakStore = new WeakRef(this.store)
183
- const collectionsObservationHandler = function (documents, event, nextSignal) {
190
+ const collectionsObservationHandler: QueryObservationHandler = function (documents, event, nextSignal) {
184
191
  const strongStore = weakStore.deref()
185
192
  if (!strongStore) {
186
193
  return
@@ -204,10 +211,12 @@ export class PendingCollectionsOperation implements PromiseLike<Collection[]> {
204
211
  })
205
212
  }
206
213
 
214
+ // The handler return promises are ignored here because we are not
215
+ // handling errors during handler execution.
207
216
  if (waitForNextSignal) {
208
- handler(collEvent, nextSignal)
217
+ void handler(collEvent, nextSignal)
209
218
  } else {
210
- handler(collEvent)
219
+ void handler(collEvent)
211
220
  }
212
221
  }
213
222
 
@@ -202,9 +202,9 @@ export class PendingCursorOperation extends BasePendingCursorOperation {
202
202
 
203
203
  /** @internal */
204
204
  _observe(handler: QueryObservationHandler, waitForNextSignal: boolean): LiveQuery {
205
- function wrappedHandler(documents, event, nextSignal) {
205
+ async function wrappedHandler(documents, event, nextSignal) {
206
206
  try {
207
- return handler.call(this, documents, event)
207
+ return await handler.call(this, documents, event)
208
208
  } finally {
209
209
  nextSignal()
210
210
  }
@@ -181,7 +181,7 @@ export class PendingIDSpecificOperation extends BasePendingIDSpecificOperation {
181
181
 
182
182
  /** @internal */
183
183
  _observe(handler: SingleObservationHandler, waitForNextSignal: boolean): LiveQuery {
184
- const liveQuery = new LiveQuery(this.query, null, null, [], -1, 0, this.collection as Collection, (documents, event, signalNext) => {
184
+ const liveQuery = new LiveQuery(this.query, null, null, [], -1, 0, this.collection as Collection, async (documents, event, signalNext) => {
185
185
  if (documents.length > 1) {
186
186
  throw new Error(`Internal inconsistency, single document live query returned more than one document. Query: ${this.query}}.`)
187
187
  }
@@ -202,10 +202,10 @@ export class PendingIDSpecificOperation extends BasePendingIDSpecificOperation {
202
202
 
203
203
  const singleDocumentEvent = new SingleDocumentLiveQueryEvent(event.isInitial, oldDocument)
204
204
  if (waitForNextSignal) {
205
- handler(document, singleDocumentEvent, signalNext)
205
+ void handler(document, singleDocumentEvent, signalNext)
206
206
  } else {
207
207
  try {
208
- handler(document, singleDocumentEvent)
208
+ await handler(document, singleDocumentEvent)
209
209
  } finally {
210
210
  signalNext()
211
211
  }
@@ -52,7 +52,7 @@ export class PresenceManager {
52
52
  }
53
53
 
54
54
  /** @internal */
55
- removeObserver(token: PresenceToken) {
55
+ async removeObserver(token: PresenceToken): Promise<void> {
56
56
  const callback = this.callbacksByPresenceToken[token]
57
57
 
58
58
  if (typeof callback === 'undefined') {
@@ -71,7 +71,7 @@ export class PresenceManager {
71
71
  // the observer objects themselves and remove it from the table
72
72
  // as soon as the observer object is garbage collected.
73
73
  this.callbacksByPresenceToken[token] = null
74
- this.unregisterIfNeeded()
74
+ return this.unregisterIfNeeded()
75
75
  }
76
76
  }
77
77
 
@@ -81,11 +81,10 @@ export class PresenceManager {
81
81
  }
82
82
 
83
83
  /** @internal */
84
- close() {
84
+ async close() {
85
85
  this.isClosed = true
86
- for (const token in this.callbacksByPresenceToken) {
87
- this.removeObserver(token)
88
- }
86
+ const tokens = Object.keys(this.callbacksByPresenceToken)
87
+ return Promise.all(tokens.map((token) => this.removeObserver(token)))
89
88
  }
90
89
 
91
90
  // ------------------------------------------------------------ Private ------
@@ -113,14 +112,14 @@ export class PresenceManager {
113
112
  })
114
113
  }
115
114
 
116
- private unregisterIfNeeded() {
115
+ private unregisterIfNeeded(): Promise<void> {
117
116
  const ditto = this.ditto
118
117
  const dittoHandle = Bridge.ditto.handleFor(ditto)
119
- ditto.deferClose(() => {
118
+ return this.ditto.deferCloseAsync(async () => {
120
119
  const needsToUnregister = !this.hasObservers() && this.isRegistered
121
120
  if (needsToUnregister) {
122
121
  this.isRegistered = false
123
- FFI.dittoClearPresenceCallback(dittoHandle.deref())
122
+ await FFI.dittoClearPresenceCallback(dittoHandle.deref())
124
123
  this.currentRemotePeers = []
125
124
  }
126
125
  })
@@ -322,11 +322,11 @@ export class Presence {
322
322
  * @see {@link peerMetadataJSONString | peerMetadataJSONString()} for details
323
323
  * on usage of metadata.
324
324
  */
325
- async setPeerMetadataJSONString(jsonString: string) {
325
+ async setPeerMetadataJSONString(jsonString: string): Promise<void> {
326
326
  const dittoHandle = Bridge.ditto.handleFor(this.ditto)
327
- await this.ditto.deferClose(() => {
327
+ await this.ditto.deferCloseAsync(async () => {
328
328
  return mapFFIErrorsAsync(async () => {
329
- await FFI.presenceTrySetPeerMetadataJSON(dittoHandle.deref(), jsonString)
329
+ return FFI.presenceTrySetPeerMetadataJSON(dittoHandle.deref(), jsonString)
330
330
  })
331
331
  })
332
332
  }
@@ -357,7 +357,7 @@ export class Presence {
357
357
  * @see {@link setPeerMetadataJSONString | setPeerMetadataJSONString()} for
358
358
  * details.
359
359
  */
360
- async setPeerMetadata(peerMetadata: Record<string, any>) {
360
+ async setPeerMetadata(peerMetadata: Record<string, any>): Promise<void> {
361
361
  let jsonString: string
362
362
  try {
363
363
  jsonString = JSON.stringify(peerMetadata)
@@ -405,8 +405,8 @@ export class Presence {
405
405
  unregister: () => {
406
406
  const ditto = this.ditto
407
407
  const dittoHandle = Bridge.ditto.handleFor(ditto)
408
- ditto.deferClose(() => {
409
- FFI.dittoClearPresenceV3Callback(dittoHandle.deref())
408
+ void ditto.deferCloseAsync(async () => {
409
+ return FFI.dittoClearPresenceV3Callback(dittoHandle.deref())
410
410
  })
411
411
  },
412
412
 
@@ -56,8 +56,8 @@ export class SmallPeerInfo {
56
56
  }
57
57
 
58
58
  const dittoHandle = Bridge.ditto.handleFor(this.ditto)
59
- this.ditto.deferClose(() => {
60
- FFI.dittoSmallPeerInfoSetEnabled(dittoHandle.deref(), newValue)
59
+ void this.ditto.deferCloseAsync(async () => {
60
+ return FFI.dittoSmallPeerInfoSetEnabled(dittoHandle.deref(), newValue)
61
61
  })
62
62
  }
63
63
 
@@ -115,7 +115,7 @@ export class StoreObserver {
115
115
 
116
116
  Logger.debug(`Invoking user event handler with new event for store observer ${storeObserverID}`)
117
117
  observationHandler(result, () => {
118
- strongThis.signalNext()
118
+ return strongThis.signalNext()
119
119
  })
120
120
  }
121
121
 
@@ -152,9 +152,9 @@ export class Store {
152
152
  // the method call that started the observer.
153
153
 
154
154
  const dittoHandle = Bridge.ditto.handleFor(this.ditto)
155
- this.ditto.deferCloseAsync(async () => {
155
+ void this.ditto.deferCloseAsync(async () => {
156
156
  return new Promise<void>((resolve) => {
157
- step(async () => {
157
+ void step(async () => {
158
158
  try {
159
159
  // prettier-ignore
160
160
  await mapFFIErrorsAsync(
@@ -464,6 +464,7 @@ export class Store {
464
464
  const attachmentFetcher = new AttachmentFetcher(ditto, attachmentToken, null, eventHandler)
465
465
 
466
466
  // @ts-expect-error modifying readonly property
467
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
467
468
  this.attachmentFetchers = Object.freeze([...this.attachmentFetchers, attachmentFetcher])
468
469
 
469
470
  return attachmentFetcher
@@ -590,8 +591,10 @@ export class Store {
590
591
  }
591
592
 
592
593
  const newAttachmentFetchers = [...this.attachmentFetchers]
594
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
593
595
  newAttachmentFetchers.splice(indexToDelete, 1)
594
596
  // @ts-expect-error modifying readonly property
597
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
595
598
  this.attachmentFetchers = Object.freeze(newAttachmentFetchers)
596
599
 
597
600
  return true
@@ -36,12 +36,13 @@ export class SubscriptionManager {
36
36
  /**
37
37
  * Begin tracking a subscription instance and start it.
38
38
  *
39
- * @internal */
39
+ * @internal
40
+ */
40
41
  add(subscription: Subscription) {
41
42
  const ditto = this.ditto
42
43
  const dittoHandle = Bridge.ditto.handleFor(ditto)
43
44
  const contextInfo = subscription.contextInfo
44
- ditto.deferClose(async () => {
45
+ ditto.deferClose(() => {
45
46
  this.subscriptions[contextInfo.id] = new WeakRef(subscription)
46
47
  this.finalizationRegistry.register(subscription, subscription.contextInfo, subscription)
47
48
  FFI.addSubscription(dittoHandle.deref(), contextInfo.collectionName, contextInfo.query, contextInfo.queryArgsCBOR, contextInfo.orderBys, contextInfo.limit, contextInfo.offset)
@@ -51,8 +52,9 @@ export class SubscriptionManager {
51
52
  /**
52
53
  * Stop tracking a subscription instance and cancel it.
53
54
  *
54
- * @internal */
55
- remove(subscription: Subscription) {
55
+ * @internal
56
+ */
57
+ remove(subscription: Subscription): void {
56
58
  if (this.subscriptions[subscription.contextInfo.id] == null) {
57
59
  throw new Error(`Internal inconsistency, tried to remove a subscription that is not tracked: ${subscription.contextInfo.id}`)
58
60
  }
@@ -63,16 +65,13 @@ export class SubscriptionManager {
63
65
  /**
64
66
  * Stop tracking all subscriptions and cancel them.
65
67
  *
66
- * @internal */
68
+ * @internal
69
+ */
67
70
  close() {
68
- this.ditto.deferClose(async () => {
71
+ this.ditto.deferClose(() => {
69
72
  for (const subscriptionID in this.subscriptions) {
70
73
  const subscription = this.subscriptions[subscriptionID].deref()
71
- if (subscription != null) {
72
- // This doesn't call `Subscription.cancel()` because that is not
73
- // async and we want to wait for all subscriptions to be removed.
74
- this.remove(subscription)
75
- }
74
+ subscription?.cancel()
76
75
  }
77
76
  })
78
77
  }
@@ -87,7 +86,8 @@ export class SubscriptionManager {
87
86
  * Remove tracked subscription without unregistering from finalization
88
87
  * registry.
89
88
  *
90
- * @internal */
89
+ * @internal
90
+ */
91
91
  private removeWithContextInfo(contextInfo: SubscriptionContextInfo) {
92
92
  const ditto = this.ditto
93
93
  const dittoHandle = Bridge.ditto.handleFor(ditto)
@@ -33,14 +33,14 @@ export class Subscription {
33
33
  /**
34
34
  * The name of the collection that the subscription is based on.
35
35
  */
36
- get collectionName() {
36
+ get collectionName(): string {
37
37
  return this.collection.name
38
38
  }
39
39
 
40
40
  /**
41
41
  * Cancels a subscription and releases all associated resources.
42
42
  */
43
- cancel() {
43
+ cancel(): void {
44
44
  if (!this.isCancelled) {
45
45
  this._isCancelled = true
46
46
  this.manager.remove(this)
package/types/ditto.d.ts CHANGED
@@ -756,17 +756,20 @@ declare class SubscriptionManager {
756
756
  /**
757
757
  * Begin tracking a subscription instance and start it.
758
758
  *
759
- * @internal */
759
+ * @internal
760
+ */
760
761
  add(subscription: Subscription): void;
761
762
  /**
762
763
  * Stop tracking a subscription instance and cancel it.
763
764
  *
764
- * @internal */
765
+ * @internal
766
+ */
765
767
  remove(subscription: Subscription): void;
766
768
  /**
767
769
  * Stop tracking all subscriptions and cancel them.
768
770
  *
769
- * @internal */
771
+ * @internal
772
+ */
770
773
  close(): void;
771
774
  private ditto;
772
775
  private subscriptions;
@@ -775,7 +778,8 @@ declare class SubscriptionManager {
775
778
  * Remove tracked subscription without unregistering from finalization
776
779
  * registry.
777
780
  *
778
- * @internal */
781
+ * @internal
782
+ */
779
783
  private removeWithContextInfo;
780
784
  }
781
785