@dittolive/ditto 4.7.4-rc.2 → 4.7.4

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 (160) hide show
  1. package/DittoReactNative.podspec +27 -0
  2. package/README.md +2 -2
  3. package/node/ditto.cjs.js +1 -1
  4. package/node/ditto.darwin-arm64.node +0 -0
  5. package/node/ditto.darwin-x64.node +0 -0
  6. package/node/ditto.linux-arm.node +0 -0
  7. package/node/ditto.linux-arm64.node +0 -0
  8. package/node/ditto.linux-x64.node +0 -0
  9. package/node/ditto.win32-x64.node +0 -0
  10. package/node/transports.darwin-arm64.node +0 -0
  11. package/node/transports.darwin-x64.node +0 -0
  12. package/package.json +5 -2
  13. package/react-native/android/.gradle/8.9/checksums/checksums.lock +0 -0
  14. package/react-native/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  15. package/react-native/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  16. package/react-native/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  17. package/react-native/android/.gradle/8.9/gc.properties +0 -0
  18. package/react-native/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  19. package/react-native/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  20. package/react-native/android/.gradle/vcs-1/gc.properties +0 -0
  21. package/react-native/android/CMakeLists.txt +36 -0
  22. package/react-native/android/build.gradle +190 -0
  23. package/react-native/android/cpp-adapter.cpp +259 -0
  24. package/react-native/android/gradle.properties +5 -0
  25. package/react-native/android/src/main/AndroidManifest.xml +4 -0
  26. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +120 -0
  27. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
  28. package/react-native/cpp/include/Arc.hpp +159 -0
  29. package/react-native/cpp/include/Attachment.h +20 -0
  30. package/react-native/cpp/include/Authentication.h +23 -0
  31. package/react-native/cpp/include/Collection.h +13 -0
  32. package/react-native/cpp/include/ConnectionRequest.h +18 -0
  33. package/react-native/cpp/include/DQL.h +21 -0
  34. package/react-native/cpp/include/Document.h +17 -0
  35. package/react-native/cpp/include/FFIUtils.h +16 -0
  36. package/react-native/cpp/include/IO.h +13 -0
  37. package/react-native/cpp/include/Identity.h +17 -0
  38. package/react-native/cpp/include/Lifecycle.h +16 -0
  39. package/react-native/cpp/include/LiveQuery.h +17 -0
  40. package/react-native/cpp/include/Logger.h +22 -0
  41. package/react-native/cpp/include/Misc.h +30 -0
  42. package/react-native/cpp/include/Presence.h +18 -0
  43. package/react-native/cpp/include/SmallPeerInfo.h +19 -0
  44. package/react-native/cpp/include/Transports.h +25 -0
  45. package/react-native/cpp/include/TypedArray.hpp +167 -0
  46. package/react-native/cpp/include/Utils.h +70 -0
  47. package/react-native/cpp/include/main.h +10 -0
  48. package/react-native/cpp/src/Attachment.cpp +272 -0
  49. package/react-native/cpp/src/Authentication.cpp +227 -0
  50. package/react-native/cpp/src/Collection.cpp +56 -0
  51. package/react-native/cpp/src/ConnectionRequest.cpp +123 -0
  52. package/react-native/cpp/src/DQL.cpp +256 -0
  53. package/react-native/cpp/src/Document.cpp +146 -0
  54. package/react-native/cpp/src/FFIUtils.cpp +122 -0
  55. package/react-native/cpp/src/IO.cpp +35 -0
  56. package/react-native/cpp/src/Identity.cpp +122 -0
  57. package/react-native/cpp/src/Lifecycle.cpp +93 -0
  58. package/react-native/cpp/src/LiveQuery.cpp +63 -0
  59. package/react-native/cpp/src/Logger.cpp +199 -0
  60. package/react-native/cpp/src/Misc.cpp +322 -0
  61. package/react-native/cpp/src/Presence.cpp +166 -0
  62. package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
  63. package/react-native/cpp/src/Transports.cpp +275 -0
  64. package/react-native/cpp/src/TypedArray.cpp +303 -0
  65. package/react-native/cpp/src/Utils.cpp +139 -0
  66. package/react-native/cpp/src/main.cpp +178 -0
  67. package/react-native/dittoffi/dittoffi.h +4873 -0
  68. package/react-native/dittoffi/ifaddrs.cpp +385 -0
  69. package/react-native/dittoffi/ifaddrs.h +206 -0
  70. package/react-native/ios/DittoRNSDK.h +7 -0
  71. package/react-native/ios/DittoRNSDK.mm +159 -0
  72. package/react-native/ios/YeetJSIUtils.h +60 -0
  73. package/react-native/ios/YeetJSIUtils.mm +196 -0
  74. package/react-native/lib/commonjs/ditto.rn.js +93 -0
  75. package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
  76. package/react-native/lib/commonjs/index.js +61 -0
  77. package/react-native/lib/commonjs/index.js.map +1 -0
  78. package/react-native/lib/module/ditto.rn.js +89 -0
  79. package/react-native/lib/module/ditto.rn.js.map +1 -0
  80. package/react-native/lib/module/index.js +27 -0
  81. package/react-native/lib/module/index.js.map +1 -0
  82. package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
  83. package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
  84. package/react-native/lib/typescript/index.d.ts +1 -0
  85. package/react-native/lib/typescript/index.d.ts.map +1 -0
  86. package/react-native/src/ditto.rn.ts +123 -0
  87. package/react-native/src/environment/environment.fallback.ts +4 -0
  88. package/react-native/src/index.ts +29 -0
  89. package/react-native/src/sources/@cbor-redux.ts +2 -0
  90. package/react-native/src/sources/@ditto.core.ts +1 -0
  91. package/react-native/src/sources/@environment.ts +1 -0
  92. package/react-native/src/sources/attachment-fetch-event.ts +54 -0
  93. package/react-native/src/sources/attachment-fetcher-manager.ts +145 -0
  94. package/react-native/src/sources/attachment-fetcher.ts +265 -0
  95. package/react-native/src/sources/attachment-token.ts +129 -0
  96. package/react-native/src/sources/attachment.ts +121 -0
  97. package/react-native/src/sources/augment.ts +108 -0
  98. package/react-native/src/sources/authenticator.ts +314 -0
  99. package/react-native/src/sources/base-pending-cursor-operation.ts +255 -0
  100. package/react-native/src/sources/base-pending-id-specific-operation.ts +112 -0
  101. package/react-native/src/sources/bridge.ts +557 -0
  102. package/react-native/src/sources/build-time-constants.ts +8 -0
  103. package/react-native/src/sources/cbor.ts +20 -0
  104. package/react-native/src/sources/collection-interface.ts +73 -0
  105. package/react-native/src/sources/collection.ts +219 -0
  106. package/react-native/src/sources/collections-event.ts +99 -0
  107. package/react-native/src/sources/connection-request.ts +142 -0
  108. package/react-native/src/sources/counter.ts +82 -0
  109. package/react-native/src/sources/ditto.ts +991 -0
  110. package/react-native/src/sources/document-id.ts +163 -0
  111. package/react-native/src/sources/document-path.ts +308 -0
  112. package/react-native/src/sources/document.ts +237 -0
  113. package/react-native/src/sources/epilogue.ts +32 -0
  114. package/react-native/src/sources/error-codes.ts +114 -0
  115. package/react-native/src/sources/error.ts +256 -0
  116. package/react-native/src/sources/essentials.ts +81 -0
  117. package/react-native/src/sources/ffi-error.ts +134 -0
  118. package/react-native/src/sources/ffi.ts +2190 -0
  119. package/react-native/src/sources/identity.ts +163 -0
  120. package/react-native/src/sources/init.ts +71 -0
  121. package/react-native/src/sources/internal.ts +143 -0
  122. package/react-native/src/sources/keep-alive.ts +73 -0
  123. package/react-native/src/sources/key-path.ts +198 -0
  124. package/react-native/src/sources/live-query-event.ts +208 -0
  125. package/react-native/src/sources/live-query-manager.ts +110 -0
  126. package/react-native/src/sources/live-query.ts +167 -0
  127. package/react-native/src/sources/logger.ts +196 -0
  128. package/react-native/src/sources/main.ts +61 -0
  129. package/react-native/src/sources/observer-manager.ts +185 -0
  130. package/react-native/src/sources/observer.ts +79 -0
  131. package/react-native/src/sources/pending-collections-operation.ts +241 -0
  132. package/react-native/src/sources/pending-cursor-operation.ts +218 -0
  133. package/react-native/src/sources/pending-id-specific-operation.ts +218 -0
  134. package/react-native/src/sources/presence-manager.ts +170 -0
  135. package/react-native/src/sources/presence.ts +427 -0
  136. package/react-native/src/sources/query-result-item.ts +131 -0
  137. package/react-native/src/sources/query-result.ts +55 -0
  138. package/react-native/src/sources/register.ts +95 -0
  139. package/react-native/src/sources/small-peer-info.ts +166 -0
  140. package/react-native/src/sources/static-tcp-client.ts +8 -0
  141. package/react-native/src/sources/store-observer.ts +170 -0
  142. package/react-native/src/sources/store.ts +630 -0
  143. package/react-native/src/sources/subscription-manager.ts +99 -0
  144. package/react-native/src/sources/subscription.ts +89 -0
  145. package/react-native/src/sources/sync-subscription.ts +90 -0
  146. package/react-native/src/sources/sync.ts +561 -0
  147. package/react-native/src/sources/test-helpers.ts +24 -0
  148. package/react-native/src/sources/transport-conditions-manager.ts +104 -0
  149. package/react-native/src/sources/transport-config.ts +430 -0
  150. package/react-native/src/sources/update-result.ts +66 -0
  151. package/react-native/src/sources/update-results-map.ts +65 -0
  152. package/react-native/src/sources/websocket-client.ts +7 -0
  153. package/react-native/src/sources/write-transaction-collection.ts +122 -0
  154. package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
  155. package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +74 -0
  156. package/react-native/src/sources/write-transaction.ts +121 -0
  157. package/react-native.config.js +9 -0
  158. package/web/ditto.es6.js +1 -1
  159. package/web/ditto.umd.js +1 -1
  160. package/web/ditto.wasm +0 -0
@@ -0,0 +1,101 @@
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 { DocumentID } from './document-id'
9
+ import { performAsyncToWorkaroundNonAsyncFFIAPI } from './internal'
10
+ import { BasePendingCursorOperation } from './base-pending-cursor-operation'
11
+
12
+ import type { QueryArguments, SortDirection } from './essentials'
13
+ import type { Document, MutableDocument } from './document'
14
+ import type { UpdateResultsMap } from './update-results-map'
15
+ import type { Collection } from './collection'
16
+ import type { WriteTransactionCollection } from './write-transaction-collection'
17
+
18
+ /**
19
+ * These objects are returned when using `find`-like functionality on
20
+ * {@link Collection}.
21
+ *
22
+ * They allow chaining of further query-related functions to do things like add
23
+ * a limit to the number of documents you want returned or specify how you want
24
+ * the documents to be sorted and ordered.
25
+ *
26
+ * You can call {@link exec | exec()} on the cursor to get an array of
27
+ * {@link Document | documents} or you can use methods for updating, removing
28
+ * or evicting any matching documents.
29
+ *
30
+ * Live queries and subscriptions are only available outside of transactions.
31
+ */
32
+ export class WriteTransactionPendingCursorOperation extends BasePendingCursorOperation {
33
+ sort(propertyPath: string, direction: SortDirection = 'ascending'): WriteTransactionPendingCursorOperation {
34
+ return super.sort(propertyPath, direction) as WriteTransactionPendingCursorOperation
35
+ }
36
+
37
+ offset(offset: number): WriteTransactionPendingCursorOperation {
38
+ return super.offset(offset) as WriteTransactionPendingCursorOperation
39
+ }
40
+
41
+ limit(limit: number): WriteTransactionPendingCursorOperation {
42
+ return super.limit(limit) as WriteTransactionPendingCursorOperation
43
+ }
44
+
45
+ async remove(): Promise<DocumentID[]> {
46
+ const ditto = this.collection.store.ditto
47
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
48
+ return ditto.deferCloseAsync(async () => {
49
+ const query = this.query
50
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
51
+
52
+ const documentsX = await performAsyncToWorkaroundNonAsyncFFIAPI(async () => FFI.collectionRemoveQueryStr(dittoHandle.deref(), this.collection.name, transaction.writeTransactionPointer, query, this.queryArgsCBOR, this.orderBys, this.currentLimit, this.currentOffset))
53
+ const results: DocumentID[] = documentsX.map((idCBOR: Uint8Array) => {
54
+ return new DocumentID(idCBOR, true)
55
+ })
56
+
57
+ results.forEach((documentId) => {
58
+ transaction.addResult('removed', documentId, this.collection.name)
59
+ })
60
+
61
+ return results
62
+ })
63
+ }
64
+
65
+ async evict(): Promise<DocumentID[]> {
66
+ const ditto = this.collection.store.ditto
67
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
68
+ return ditto.deferCloseAsync(async () => {
69
+ const query = this.query
70
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
71
+
72
+ const documentsX = await performAsyncToWorkaroundNonAsyncFFIAPI(async () => FFI.collectionEvictQueryStr(dittoHandle.deref(), this.collection.name, transaction.writeTransactionPointer, query, this.queryArgsCBOR, this.orderBys, this.currentLimit, this.currentOffset))
73
+
74
+ const results: DocumentID[] = documentsX.map((idCBOR: Uint8Array) => {
75
+ return new DocumentID(idCBOR, true)
76
+ })
77
+
78
+ results.forEach((documentId) => {
79
+ transaction.addResult('evicted', documentId, this.collection.name)
80
+ })
81
+
82
+ return results
83
+ })
84
+ }
85
+
86
+ async update(closure: (documents: MutableDocument[]) => void): Promise<UpdateResultsMap> {
87
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
88
+ const results = await super.updateWithTransaction(closure, transaction.writeTransactionPointer)
89
+ results.keys().forEach((documentId) => {
90
+ transaction.addResult('updated', documentId, this.collection.name)
91
+ })
92
+ return results
93
+ }
94
+
95
+ // ----------------------------------------------------------- Internal ------
96
+
97
+ /** @internal */
98
+ constructor(query: string, queryArgs: QueryArguments | null, collection: WriteTransactionCollection) {
99
+ super(query, queryArgs, collection)
100
+ }
101
+ }
@@ -0,0 +1,74 @@
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 { MutableDocument } from './document'
9
+ import { performAsyncToWorkaroundNonAsyncFFIAPI } from './internal'
10
+ import { BasePendingIDSpecificOperation } from './base-pending-id-specific-operation'
11
+
12
+ import type { UpdateResult } from './update-result'
13
+ import type { DocumentID } from './document-id'
14
+ import type { WriteTransactionCollection } from './write-transaction-collection'
15
+
16
+ export class WriteTransactionPendingIDSpecificOperation extends BasePendingIDSpecificOperation {
17
+ async remove(): Promise<boolean> {
18
+ const ditto = this.collection.store.ditto
19
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
20
+ return ditto.deferCloseAsync(async () => {
21
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
22
+ const result = await performAsyncToWorkaroundNonAsyncFFIAPI(async () => FFI.collectionRemove(dittoHandle.deref(), this.collection.name, transaction.writeTransactionPointer, this.documentIDCBOR))
23
+
24
+ transaction.addResult('removed', this.documentID, this.collection.name)
25
+ return result
26
+ })
27
+ }
28
+
29
+ async evict(): Promise<boolean> {
30
+ const ditto = this.collection.store.ditto
31
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
32
+ return ditto.deferCloseAsync(async () => {
33
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
34
+ const result = await performAsyncToWorkaroundNonAsyncFFIAPI(async () => await FFI.collectionEvict(dittoHandle.deref(), this.collection.name, transaction.writeTransactionPointer, this.documentIDCBOR))
35
+
36
+ transaction.addResult('evicted', this.documentID, this.collection.name)
37
+ return result
38
+ })
39
+ }
40
+
41
+ async update(closure: (document: MutableDocument) => void): Promise<UpdateResult[]> {
42
+ const ditto = this.collection.store.ditto
43
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
44
+ return ditto.deferCloseAsync(async () => {
45
+ const transaction = (this.collection as WriteTransactionCollection).writeTransaction
46
+
47
+ const readTransactionX = await FFI.readTransaction(dittoHandle.deref())
48
+ const documentX = await FFI.collectionGet(dittoHandle.deref(), this.collection.name, this.documentIDCBOR, readTransactionX)
49
+ FFI.readTransactionFree(readTransactionX)
50
+
51
+ if (!documentX) throw new Error(`Can't update, document with ID '${this.documentID.toString()}' not found in collection named '${this.collection.name}'`)
52
+
53
+ const mutableDocument = Bridge.mutableDocument.bridge(documentX, () => new MutableDocument())
54
+ closure(mutableDocument)
55
+
56
+ // Ownership is transferred back to the FFI layer via collectionUpdate(),
57
+ // we therefore need to explicitly unregister the instance.
58
+ Bridge.mutableDocument.unregister(mutableDocument)
59
+
60
+ await FFI.collectionUpdate(dittoHandle.deref(), this.collection.name, transaction.writeTransactionPointer, documentX)
61
+
62
+ transaction.addResult('updated', this.documentID, this.collection.name)
63
+
64
+ return mutableDocument['@ditto.updateResults'].slice()
65
+ })
66
+ }
67
+
68
+ // ----------------------------------------------------------- Internal ------
69
+
70
+ /** @internal */
71
+ constructor(documentID: DocumentID, collection: WriteTransactionCollection) {
72
+ super(documentID, collection)
73
+ }
74
+ }
@@ -0,0 +1,121 @@
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 { WriteTransactionCollection } from './write-transaction-collection'
9
+
10
+ import type { Ditto } from './ditto'
11
+ import type { DocumentID } from './document-id'
12
+ import type { Store } from './store'
13
+
14
+ /**
15
+ * Provides information about the result of an operation on a document that was
16
+ * part of a write transaction.
17
+ *
18
+ * The write transaction result can be one of the following types:
19
+ *
20
+ * - `inserted`
21
+ * - `removed`
22
+ * - `evicted`
23
+ * - `updated`
24
+ *
25
+ * Please note that an `upsert` operation always results in the result type
26
+ * `inserted`, regardless of whether it resulted in an update or insert.
27
+ */
28
+ export interface WriteTransactionResult {
29
+ type: 'inserted' | 'removed' | 'evicted' | 'updated'
30
+ docID: DocumentID
31
+ collectionName: string
32
+ }
33
+
34
+ /**
35
+ * Perform writes in a transaction.
36
+ *
37
+ * Create a write transaction using {@link Store.write | ditto.store.write}.
38
+ */
39
+ export class WriteTransaction {
40
+ // Pointer to internal C transaction through FFI.
41
+ /** @internal */
42
+ readonly writeTransactionPointer: FFI.Pointer<FFI.FFIWriteTransaction>
43
+
44
+ /** @internal */
45
+ readonly ditto: Ditto
46
+
47
+ // All documents affected by writes in this transaction are collected here.
48
+ readonly results: WriteTransactionResult[]
49
+
50
+ /**
51
+ * Initialise a write transaction given a Ditto instance.
52
+ *
53
+ * This is not implemented as a constructor in order to be able to use FFI
54
+ * async functions. Users start transactions through {@link Store.write}.
55
+ *
56
+ * @param ditto an instance of Ditto
57
+ * @internal
58
+ */
59
+ static async init(ditto: Ditto) {
60
+ return ditto.deferCloseAsync(async () => {
61
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
62
+ const writeTransactionPointer = await FFI.writeTransaction(dittoHandle.deref())
63
+ return new WriteTransaction(ditto, writeTransactionPointer)
64
+ })
65
+ }
66
+
67
+ /**
68
+ * Creates a transaction-specific
69
+ * {@link WriteTransactionCollection | collection} object that will ensure
70
+ * that operations called on it are all in the context of the collection name
71
+ * provided to this function. You can create many
72
+ * {@link WriteTransactionCollection | collection} objects per
73
+ * {@link WriteTransaction} object.
74
+ * */
75
+ scoped(toCollectionNamed: string): WriteTransactionCollection {
76
+ if (typeof toCollectionNamed !== 'string') {
77
+ throw new Error('Collection name must be a string')
78
+ }
79
+ return new WriteTransactionCollection(toCollectionNamed, this.ditto.store, this)
80
+ }
81
+
82
+ // ----------------------------------------------------------- Internal ------
83
+
84
+ /** @internal */
85
+ async commit(): Promise<void> {
86
+ const ditto = this.ditto
87
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
88
+ return ditto.deferCloseAsync(async () => {
89
+ return FFI.writeTransactionCommit(dittoHandle.deref(), this.writeTransactionPointer)
90
+ })
91
+ }
92
+
93
+ /** @internal */
94
+ async rollback(): Promise<void> {
95
+ const ditto = this.ditto
96
+ const dittoHandle = Bridge.ditto.handleFor(ditto)
97
+ return ditto.deferCloseAsync(async () => {
98
+ return FFI.writeTransactionRollback(dittoHandle.deref(), this.writeTransactionPointer)
99
+ })
100
+ }
101
+
102
+ /**
103
+ * Adds an entry to the list of results that is returned at the end of a
104
+ * transaction.
105
+ *
106
+ * @internal */
107
+ addResult(type: WriteTransactionResult['type'], docID: DocumentID, collectionName: string) {
108
+ this.results.push({
109
+ type,
110
+ docID,
111
+ collectionName,
112
+ })
113
+ }
114
+
115
+ /** @internal */
116
+ constructor(ditto: Ditto, cTransaction: FFI.Pointer<FFI.FFIWriteTransaction>) {
117
+ this.writeTransactionPointer = cTransaction
118
+ this.ditto = ditto
119
+ this.results = []
120
+ }
121
+ }
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ android: {
5
+ sourceDir: './react-native/android',
6
+ },
7
+ },
8
+ },
9
+ };