@dittolive/ditto 4.5.0 → 4.5.1-experimental.aarch64-linux.1.aarch64

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 (289) hide show
  1. package/README.md +2 -2
  2. package/node/ditto.cjs.js +2 -9620
  3. package/node/{ditto.linux-x64.node → ditto.linux-arm64.node} +0 -0
  4. package/package.json +38 -34
  5. package/types/ditto.d.ts +0 -2
  6. package/web/ditto.es6.js +1 -1
  7. package/web/ditto.umd.js +1 -1
  8. package/web/ditto.wasm +0 -0
  9. package/DittoReactNative.podspec +0 -27
  10. package/node/ditto.darwin-arm64.node +0 -0
  11. package/node/ditto.darwin-x64.node +0 -0
  12. package/node/ditto.linux-arm.node +0 -0
  13. package/node/ditto.win32-x64.node +0 -0
  14. package/node/transports.darwin-arm64.node +0 -0
  15. package/node/transports.darwin-x64.node +0 -0
  16. package/react-native/android/CMakeLists.txt +0 -37
  17. package/react-native/android/build.gradle +0 -203
  18. package/react-native/android/cpp-adapter.cpp +0 -254
  19. package/react-native/android/gradle.properties +0 -5
  20. package/react-native/android/src/main/AndroidManifest.xml +0 -4
  21. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +0 -85
  22. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +0 -28
  23. package/react-native/boost/boost/assert.hpp +0 -85
  24. package/react-native/boost/boost/config/abi/borland_prefix.hpp +0 -27
  25. package/react-native/boost/boost/config/abi/borland_suffix.hpp +0 -12
  26. package/react-native/boost/boost/config/abi/msvc_prefix.hpp +0 -22
  27. package/react-native/boost/boost/config/abi/msvc_suffix.hpp +0 -8
  28. package/react-native/boost/boost/config/abi_prefix.hpp +0 -25
  29. package/react-native/boost/boost/config/abi_suffix.hpp +0 -25
  30. package/react-native/boost/boost/config/assert_cxx03.hpp +0 -211
  31. package/react-native/boost/boost/config/assert_cxx11.hpp +0 -209
  32. package/react-native/boost/boost/config/assert_cxx14.hpp +0 -47
  33. package/react-native/boost/boost/config/assert_cxx17.hpp +0 -62
  34. package/react-native/boost/boost/config/assert_cxx20.hpp +0 -59
  35. package/react-native/boost/boost/config/assert_cxx98.hpp +0 -23
  36. package/react-native/boost/boost/config/auto_link.hpp +0 -525
  37. package/react-native/boost/boost/config/compiler/borland.hpp +0 -339
  38. package/react-native/boost/boost/config/compiler/clang.hpp +0 -366
  39. package/react-native/boost/boost/config/compiler/clang_version.hpp +0 -83
  40. package/react-native/boost/boost/config/compiler/codegear.hpp +0 -385
  41. package/react-native/boost/boost/config/compiler/comeau.hpp +0 -59
  42. package/react-native/boost/boost/config/compiler/common_edg.hpp +0 -183
  43. package/react-native/boost/boost/config/compiler/compaq_cxx.hpp +0 -19
  44. package/react-native/boost/boost/config/compiler/cray.hpp +0 -446
  45. package/react-native/boost/boost/config/compiler/diab.hpp +0 -26
  46. package/react-native/boost/boost/config/compiler/digitalmars.hpp +0 -143
  47. package/react-native/boost/boost/config/compiler/gcc.hpp +0 -383
  48. package/react-native/boost/boost/config/compiler/gcc_xml.hpp +0 -114
  49. package/react-native/boost/boost/config/compiler/greenhills.hpp +0 -28
  50. package/react-native/boost/boost/config/compiler/hp_acc.hpp +0 -149
  51. package/react-native/boost/boost/config/compiler/intel.hpp +0 -577
  52. package/react-native/boost/boost/config/compiler/kai.hpp +0 -33
  53. package/react-native/boost/boost/config/compiler/metrowerks.hpp +0 -198
  54. package/react-native/boost/boost/config/compiler/mpw.hpp +0 -140
  55. package/react-native/boost/boost/config/compiler/nvcc.hpp +0 -61
  56. package/react-native/boost/boost/config/compiler/pathscale.hpp +0 -138
  57. package/react-native/boost/boost/config/compiler/pgi.hpp +0 -23
  58. package/react-native/boost/boost/config/compiler/sgi_mipspro.hpp +0 -29
  59. package/react-native/boost/boost/config/compiler/sunpro_cc.hpp +0 -222
  60. package/react-native/boost/boost/config/compiler/vacpp.hpp +0 -186
  61. package/react-native/boost/boost/config/compiler/visualc.hpp +0 -391
  62. package/react-native/boost/boost/config/compiler/xlcpp.hpp +0 -299
  63. package/react-native/boost/boost/config/compiler/xlcpp_zos.hpp +0 -173
  64. package/react-native/boost/boost/config/detail/cxx_composite.hpp +0 -203
  65. package/react-native/boost/boost/config/detail/posix_features.hpp +0 -95
  66. package/react-native/boost/boost/config/detail/select_compiler_config.hpp +0 -157
  67. package/react-native/boost/boost/config/detail/select_platform_config.hpp +0 -147
  68. package/react-native/boost/boost/config/detail/select_stdlib_config.hpp +0 -121
  69. package/react-native/boost/boost/config/detail/suffix.hpp +0 -1294
  70. package/react-native/boost/boost/config/header_deprecated.hpp +0 -26
  71. package/react-native/boost/boost/config/helper_macros.hpp +0 -37
  72. package/react-native/boost/boost/config/no_tr1/cmath.hpp +0 -28
  73. package/react-native/boost/boost/config/no_tr1/complex.hpp +0 -28
  74. package/react-native/boost/boost/config/no_tr1/functional.hpp +0 -28
  75. package/react-native/boost/boost/config/no_tr1/memory.hpp +0 -28
  76. package/react-native/boost/boost/config/no_tr1/utility.hpp +0 -28
  77. package/react-native/boost/boost/config/platform/aix.hpp +0 -33
  78. package/react-native/boost/boost/config/platform/amigaos.hpp +0 -15
  79. package/react-native/boost/boost/config/platform/beos.hpp +0 -26
  80. package/react-native/boost/boost/config/platform/bsd.hpp +0 -83
  81. package/react-native/boost/boost/config/platform/cloudabi.hpp +0 -18
  82. package/react-native/boost/boost/config/platform/cray.hpp +0 -18
  83. package/react-native/boost/boost/config/platform/cygwin.hpp +0 -71
  84. package/react-native/boost/boost/config/platform/haiku.hpp +0 -31
  85. package/react-native/boost/boost/config/platform/hpux.hpp +0 -87
  86. package/react-native/boost/boost/config/platform/irix.hpp +0 -31
  87. package/react-native/boost/boost/config/platform/linux.hpp +0 -106
  88. package/react-native/boost/boost/config/platform/macos.hpp +0 -87
  89. package/react-native/boost/boost/config/platform/qnxnto.hpp +0 -31
  90. package/react-native/boost/boost/config/platform/solaris.hpp +0 -31
  91. package/react-native/boost/boost/config/platform/symbian.hpp +0 -97
  92. package/react-native/boost/boost/config/platform/vms.hpp +0 -25
  93. package/react-native/boost/boost/config/platform/vxworks.hpp +0 -422
  94. package/react-native/boost/boost/config/platform/wasm.hpp +0 -23
  95. package/react-native/boost/boost/config/platform/win32.hpp +0 -90
  96. package/react-native/boost/boost/config/platform/zos.hpp +0 -32
  97. package/react-native/boost/boost/config/pragma_message.hpp +0 -31
  98. package/react-native/boost/boost/config/requires_threads.hpp +0 -92
  99. package/react-native/boost/boost/config/stdlib/dinkumware.hpp +0 -324
  100. package/react-native/boost/boost/config/stdlib/libcomo.hpp +0 -93
  101. package/react-native/boost/boost/config/stdlib/libcpp.hpp +0 -180
  102. package/react-native/boost/boost/config/stdlib/libstdcpp3.hpp +0 -482
  103. package/react-native/boost/boost/config/stdlib/modena.hpp +0 -79
  104. package/react-native/boost/boost/config/stdlib/msl.hpp +0 -98
  105. package/react-native/boost/boost/config/stdlib/roguewave.hpp +0 -208
  106. package/react-native/boost/boost/config/stdlib/sgi.hpp +0 -168
  107. package/react-native/boost/boost/config/stdlib/stlport.hpp +0 -258
  108. package/react-native/boost/boost/config/stdlib/vacpp.hpp +0 -74
  109. package/react-native/boost/boost/config/stdlib/xlcpp_zos.hpp +0 -61
  110. package/react-native/boost/boost/config/user.hpp +0 -133
  111. package/react-native/boost/boost/config/warning_disable.hpp +0 -47
  112. package/react-native/boost/boost/config/workaround.hpp +0 -305
  113. package/react-native/boost/boost/config.hpp +0 -67
  114. package/react-native/boost/boost/cstdint.hpp +0 -556
  115. package/react-native/boost/boost/intrusive_ptr.hpp +0 -18
  116. package/react-native/boost/boost/smart_ptr/detail/atomic_count.hpp +0 -103
  117. package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc.hpp +0 -79
  118. package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_atomic.hpp +0 -63
  119. package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_x86.hpp +0 -88
  120. package/react-native/boost/boost/smart_ptr/detail/atomic_count_nt.hpp +0 -66
  121. package/react-native/boost/boost/smart_ptr/detail/atomic_count_pt.hpp +0 -104
  122. package/react-native/boost/boost/smart_ptr/detail/atomic_count_spin.hpp +0 -69
  123. package/react-native/boost/boost/smart_ptr/detail/atomic_count_std_atomic.hpp +0 -67
  124. package/react-native/boost/boost/smart_ptr/detail/atomic_count_sync.hpp +0 -72
  125. package/react-native/boost/boost/smart_ptr/detail/atomic_count_win32.hpp +0 -70
  126. package/react-native/boost/boost/smart_ptr/detail/local_counted_base.hpp +0 -148
  127. package/react-native/boost/boost/smart_ptr/detail/local_sp_deleter.hpp +0 -91
  128. package/react-native/boost/boost/smart_ptr/detail/operator_bool.hpp +0 -64
  129. package/react-native/boost/boost/smart_ptr/detail/requires_cxx11.hpp +0 -23
  130. package/react-native/boost/boost/smart_ptr/detail/shared_count.hpp +0 -707
  131. package/react-native/boost/boost/smart_ptr/detail/sp_convertible.hpp +0 -92
  132. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base.hpp +0 -92
  133. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp +0 -163
  134. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_aix.hpp +0 -152
  135. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp +0 -185
  136. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp +0 -148
  137. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp +0 -170
  138. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp +0 -200
  139. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp +0 -194
  140. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp +0 -179
  141. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp +0 -186
  142. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp +0 -119
  143. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_pt.hpp +0 -147
  144. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp +0 -174
  145. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_spin.hpp +0 -141
  146. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp +0 -147
  147. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_sync.hpp +0 -165
  148. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp +0 -163
  149. package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_w32.hpp +0 -140
  150. package/react-native/boost/boost/smart_ptr/detail/sp_counted_impl.hpp +0 -309
  151. package/react-native/boost/boost/smart_ptr/detail/sp_disable_deprecated.hpp +0 -40
  152. package/react-native/boost/boost/smart_ptr/detail/sp_forward.hpp +0 -52
  153. package/react-native/boost/boost/smart_ptr/detail/sp_has_gcc_intrinsics.hpp +0 -27
  154. package/react-native/boost/boost/smart_ptr/detail/sp_has_sync_intrinsics.hpp +0 -69
  155. package/react-native/boost/boost/smart_ptr/detail/sp_interlocked.hpp +0 -173
  156. package/react-native/boost/boost/smart_ptr/detail/sp_noexcept.hpp +0 -48
  157. package/react-native/boost/boost/smart_ptr/detail/sp_nullptr_t.hpp +0 -45
  158. package/react-native/boost/boost/smart_ptr/detail/sp_obsolete.hpp +0 -32
  159. package/react-native/boost/boost/smart_ptr/detail/sp_thread_pause.hpp +0 -51
  160. package/react-native/boost/boost/smart_ptr/detail/sp_thread_sleep.hpp +0 -104
  161. package/react-native/boost/boost/smart_ptr/detail/sp_thread_yield.hpp +0 -100
  162. package/react-native/boost/boost/smart_ptr/detail/sp_typeinfo_.hpp +0 -58
  163. package/react-native/boost/boost/smart_ptr/detail/sp_win32_sleep.hpp +0 -49
  164. package/react-native/boost/boost/smart_ptr/intrusive_ptr.hpp +0 -409
  165. package/react-native/boost/boost/smart_ptr/intrusive_ref_counter.hpp +0 -188
  166. package/react-native/cpp/include/Attachment.h +0 -16
  167. package/react-native/cpp/include/Authentication.h +0 -23
  168. package/react-native/cpp/include/Collection.h +0 -13
  169. package/react-native/cpp/include/DQL.h +0 -21
  170. package/react-native/cpp/include/Document.h +0 -17
  171. package/react-native/cpp/include/Identity.h +0 -17
  172. package/react-native/cpp/include/Lifecycle.h +0 -16
  173. package/react-native/cpp/include/LiveQuery.h +0 -17
  174. package/react-native/cpp/include/Logger.h +0 -22
  175. package/react-native/cpp/include/Misc.h +0 -26
  176. package/react-native/cpp/include/Presence.h +0 -14
  177. package/react-native/cpp/include/RetainableState.h +0 -24
  178. package/react-native/cpp/include/SmallPeerInfo.h +0 -17
  179. package/react-native/cpp/include/Transports.h +0 -25
  180. package/react-native/cpp/include/TypedArray.hpp +0 -167
  181. package/react-native/cpp/include/Utils.h +0 -61
  182. package/react-native/cpp/include/main.h +0 -10
  183. package/react-native/cpp/src/Attachment.cpp +0 -86
  184. package/react-native/cpp/src/Authentication.cpp +0 -224
  185. package/react-native/cpp/src/Collection.cpp +0 -54
  186. package/react-native/cpp/src/DQL.cpp +0 -254
  187. package/react-native/cpp/src/Document.cpp +0 -146
  188. package/react-native/cpp/src/Identity.cpp +0 -123
  189. package/react-native/cpp/src/Lifecycle.cpp +0 -75
  190. package/react-native/cpp/src/LiveQuery.cpp +0 -64
  191. package/react-native/cpp/src/Logger.cpp +0 -200
  192. package/react-native/cpp/src/Misc.cpp +0 -271
  193. package/react-native/cpp/src/Presence.cpp +0 -77
  194. package/react-native/cpp/src/RetainableState.cpp +0 -15
  195. package/react-native/cpp/src/SmallPeerInfo.cpp +0 -108
  196. package/react-native/cpp/src/Transports.cpp +0 -270
  197. package/react-native/cpp/src/TypedArray.cpp +0 -303
  198. package/react-native/cpp/src/Utils.cpp +0 -138
  199. package/react-native/cpp/src/main.cpp +0 -149
  200. package/react-native/dittoffi/dittoffi.h +0 -4698
  201. package/react-native/dittoffi/ifaddrs.cpp +0 -385
  202. package/react-native/dittoffi/ifaddrs.h +0 -206
  203. package/react-native/ios/DittoRNSDK.h +0 -7
  204. package/react-native/ios/DittoRNSDK.mm +0 -107
  205. package/react-native/ios/YeetJSIUtils.h +0 -60
  206. package/react-native/ios/YeetJSIUtils.mm +0 -196
  207. package/react-native/lib/commonjs/ditto.rn.js +0 -93
  208. package/react-native/lib/commonjs/ditto.rn.js.map +0 -1
  209. package/react-native/lib/commonjs/index.js +0 -14
  210. package/react-native/lib/commonjs/index.js.map +0 -1
  211. package/react-native/lib/module/ditto.rn.js +0 -83
  212. package/react-native/lib/module/ditto.rn.js.map +0 -1
  213. package/react-native/lib/module/index.js +0 -13
  214. package/react-native/lib/module/index.js.map +0 -1
  215. package/react-native/lib/typescript/ditto.rn.d.ts +0 -15
  216. package/react-native/lib/typescript/ditto.rn.d.ts.map +0 -1
  217. package/react-native/lib/typescript/index.d.ts +0 -1
  218. package/react-native/lib/typescript/index.d.ts.map +0 -1
  219. package/react-native/scripts/ruby/include_local_boost.rb +0 -78
  220. package/react-native/src/ditto.rn.ts +0 -91
  221. package/react-native/src/environment/environment.fallback.ts +0 -4
  222. package/react-native/src/index.ts +0 -26
  223. package/react-native/src/sources/@cbor-redux.ts +0 -2
  224. package/react-native/src/sources/@ditto.core.ts +0 -1
  225. package/react-native/src/sources/@environment.ts +0 -2
  226. package/react-native/src/sources/attachment-fetch-event.ts +0 -54
  227. package/react-native/src/sources/attachment-fetcher-manager.ts +0 -129
  228. package/react-native/src/sources/attachment-fetcher.ts +0 -124
  229. package/react-native/src/sources/attachment-token.ts +0 -48
  230. package/react-native/src/sources/attachment.ts +0 -59
  231. package/react-native/src/sources/augment.ts +0 -89
  232. package/react-native/src/sources/authenticator.ts +0 -314
  233. package/react-native/src/sources/base-pending-cursor-operation.ts +0 -237
  234. package/react-native/src/sources/base-pending-id-specific-operation.ts +0 -109
  235. package/react-native/src/sources/bridge.ts +0 -549
  236. package/react-native/src/sources/build-time-constants.ts +0 -4
  237. package/react-native/src/sources/cbor.ts +0 -35
  238. package/react-native/src/sources/collection-interface.ts +0 -67
  239. package/react-native/src/sources/collection.ts +0 -212
  240. package/react-native/src/sources/collections-event.ts +0 -99
  241. package/react-native/src/sources/counter.ts +0 -77
  242. package/react-native/src/sources/ditto.ts +0 -945
  243. package/react-native/src/sources/document-id.ts +0 -159
  244. package/react-native/src/sources/document-path.ts +0 -303
  245. package/react-native/src/sources/document.ts +0 -192
  246. package/react-native/src/sources/epilogue.ts +0 -24
  247. package/react-native/src/sources/error-codes.ts +0 -52
  248. package/react-native/src/sources/error.ts +0 -203
  249. package/react-native/src/sources/essentials.ts +0 -53
  250. package/react-native/src/sources/ffi-error.ts +0 -117
  251. package/react-native/src/sources/ffi.ts +0 -1972
  252. package/react-native/src/sources/identity.ts +0 -163
  253. package/react-native/src/sources/init.ts +0 -70
  254. package/react-native/src/sources/internal.ts +0 -113
  255. package/react-native/src/sources/keep-alive.ts +0 -69
  256. package/react-native/src/sources/key-path.ts +0 -195
  257. package/react-native/src/sources/live-query-event.ts +0 -208
  258. package/react-native/src/sources/live-query-manager.ts +0 -101
  259. package/react-native/src/sources/live-query.ts +0 -164
  260. package/react-native/src/sources/logger.ts +0 -196
  261. package/react-native/src/sources/observer-manager.ts +0 -175
  262. package/react-native/src/sources/observer.ts +0 -77
  263. package/react-native/src/sources/pending-collections-operation.ts +0 -232
  264. package/react-native/src/sources/pending-cursor-operation.ts +0 -218
  265. package/react-native/src/sources/pending-id-specific-operation.ts +0 -216
  266. package/react-native/src/sources/presence-manager.ts +0 -160
  267. package/react-native/src/sources/presence.ts +0 -238
  268. package/react-native/src/sources/query-result-item.ts +0 -116
  269. package/react-native/src/sources/query-result.ts +0 -55
  270. package/react-native/src/sources/register.ts +0 -92
  271. package/react-native/src/sources/small-peer-info.ts +0 -176
  272. package/react-native/src/sources/static-tcp-client.ts +0 -6
  273. package/react-native/src/sources/store-observer.ts +0 -176
  274. package/react-native/src/sources/store.ts +0 -365
  275. package/react-native/src/sources/subscription-manager.ts +0 -98
  276. package/react-native/src/sources/subscription.ts +0 -88
  277. package/react-native/src/sources/sync-subscription.ts +0 -90
  278. package/react-native/src/sources/sync.ts +0 -495
  279. package/react-native/src/sources/test-helpers.ts +0 -24
  280. package/react-native/src/sources/transport-conditions-manager.ts +0 -104
  281. package/react-native/src/sources/transport-config.ts +0 -428
  282. package/react-native/src/sources/update-result.ts +0 -66
  283. package/react-native/src/sources/update-results-map.ts +0 -57
  284. package/react-native/src/sources/websocket-client.ts +0 -6
  285. package/react-native/src/sources/write-transaction-collection.ts +0 -122
  286. package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +0 -101
  287. package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +0 -72
  288. package/react-native/src/sources/write-transaction.ts +0 -119
  289. package/react-native.config.js +0 -9
@@ -1,945 +0,0 @@
1
- //
2
- // Copyright © 2021 DittoLive Incorporated. All rights reserved.
3
- //
4
-
5
- import * as FFI from './ffi'
6
- import * as Environment from './@environment'
7
-
8
- import { TransportConfig, transportConfigToSerializable } from './transport-config'
9
-
10
- import { Authenticator, OnlineAuthenticator, NotAvailableAuthenticator } from './authenticator'
11
- import { IdentityTypesRequiringOfflineLicenseToken } from './identity'
12
- import { Bridge } from './bridge'
13
- import { CBOR } from './cbor'
14
- import { Store } from './store'
15
- import { Logger } from './logger'
16
- import { KeepAlive } from './keep-alive'
17
-
18
- import { Observer } from './observer'
19
- import { ObserverManager } from './observer-manager'
20
-
21
- import { Presence } from './presence'
22
- import { LiveQueryManager } from './live-query-manager'
23
- import { PresenceManager } from './presence-manager'
24
- import { TransportConditionsManager } from './transport-conditions-manager'
25
- import { Sync } from './sync'
26
-
27
- import { defaultAuthURL } from './internal'
28
- import { SubscriptionManager } from './subscription-manager'
29
- import { AttachmentFetcherManager } from './attachment-fetcher-manager'
30
- import { SmallPeerInfo } from './small-peer-info'
31
-
32
- import type { Identity } from './identity'
33
- // -----------------------------------------------------------------------------
34
-
35
- /** Types of connections that can be established between two peers. */
36
- export type TransportCondition = 'Unknown' | 'OK' | 'GenericFailure' | 'AppInBackground' | 'MDNSFailure' | 'TCPListenFailure' | 'NoBLECentralPermission' | 'NoBLEPeripheralPermission' | 'CannotEstablishConnection' | 'BLEDisabled' | 'NoBLEHardware' | 'WiFiDisabled' | 'TemporarilyUnavailable'
37
-
38
- /** The source for a transport condition. */
39
- export type ConditionSource = 'BLE' | 'TCP' | 'AWDL' | 'MDNS'
40
-
41
- // -----------------------------------------------------------------------------
42
-
43
- /**
44
- * Types of connections that can be established between two peers.
45
- * @deprecated replaced by {@link ConnectionType}.
46
- */
47
- export type PresenceConnectionType = 'WiFi' | 'WebSocket' | 'AWDL' | 'BLE'
48
-
49
- /**
50
- * A peer object with information about an observed peer.
51
- * @deprecated replaced by {@link Peer}.
52
- */
53
- export type RemotePeer = {
54
- networkID: string
55
- deviceName: string
56
- rssi?: number
57
- approximateDistanceInMeters?: number
58
- connections: PresenceConnectionType[]
59
- }
60
-
61
- // -----------------------------------------------------------------------------
62
-
63
- const DEFAULT_PERSISTENCE_DIRECTORY = 'ditto'
64
-
65
- /**
66
- * Ditto is the entry point for accessing Ditto-related functionality.
67
- */
68
- export class Ditto {
69
- /**
70
- * A string containing the semantic version of the Ditto SDK. Example: 4.4.3
71
- */
72
- static get VERSION(): string {
73
- return FFI.dittoGetSDKSemver()
74
- }
75
-
76
- /**
77
- * Configure a custom identifier for the current device.
78
- *
79
- * When using {@link Presence.observe | presence.observe()}, each remote peer is
80
- * represented by a short UTF-8 "device name". By default this will be a
81
- * truncated version of the device's hostname. It does not need to be unique
82
- * among peers. Configure the device name before calling
83
- * {@link startSync | startSync()}. If it is too long it may be truncated.
84
- */
85
- deviceName: string
86
-
87
- /** Returns a string identifying the version of the Ditto SDK. */
88
- get sdkVersion() {
89
- const dittoHandle = Bridge.ditto.handleFor(this)
90
- return this.deferClose(() => {
91
- return FFI.dittoGetSDKVersion(dittoHandle.deref())
92
- })
93
- }
94
-
95
- /**
96
- * The (validated) identity this Ditto instance was initialized with.
97
- */
98
- readonly identity: Identity
99
-
100
- /**
101
- * The path this Ditto instance was initialized with, if no path was given at
102
- * construction time, the default value is returned (see constructor).
103
- *
104
- * @deprecated `Ditto.path` is deprecated. Please update your code to use the
105
- * new 'Ditto.persistenceDirectory' property instead.
106
- */
107
- get path(): string {
108
- Logger.warning("⚠️ Deprecation Warning: The 'Ditto.path' property is deprecated. Please update your code to use the new 'Ditto.persistenceDirectory' property instead.")
109
- return this.persistenceDirectory
110
- }
111
-
112
- /**
113
- * Path to the local directory used for persistent data storage.
114
- *
115
- * Defaults to 'ditto'. In environments without file system access, such as
116
- * browsers, this is used as a namespace for the internal data store.
117
- */
118
- readonly persistenceDirectory: string
119
-
120
- /**
121
- * Provides access to the SDK's store functionality.
122
- */
123
- readonly store: Store
124
-
125
- /**
126
- * Provides access to the SDK's sync functionality.
127
- */
128
- readonly sync: Sync
129
-
130
- /**
131
- * Provides access to the SDK's presence functionality.
132
- */
133
- readonly presence: Presence
134
-
135
- /**
136
- * Provides access to authentication methods for logging on to Ditto Cloud.
137
- */
138
- readonly auth: Authenticator
139
-
140
- /**
141
- * The site ID that the instance of `Ditto` is using as part of its identity.
142
- */
143
- readonly siteID: number | BigInt
144
-
145
- /**
146
- * Provides access to the SDK's small peer info functionality.
147
- */
148
- readonly smallPeerInfo: SmallPeerInfo
149
-
150
- /**
151
- * Returns `true` if an offline license token has been set, otherwise returns `false`.
152
- *
153
- * @see {@link setOfflineOnlyLicenseToken | setOfflineOnlyLicenseToken()}
154
- */
155
- get isActivated() {
156
- return this._isActivated ?? false
157
- }
158
-
159
- /**
160
- * `true` once {@link close | Ditto.close()} has been called, otherwise
161
- * `false`.
162
- */
163
- get isClosed() {
164
- return this._isClosed ?? false
165
- }
166
-
167
- /**
168
- * Returns `true` if sync is active, otherwise returns `false`. Use
169
- * {@link startSync | startSync()} to activate and
170
- * {@link stopSync | stopSync()} to deactivate sync.
171
- */
172
- get isSyncActive() {
173
- return this._isSyncActive ?? false
174
- }
175
-
176
- /**
177
- * Application ID associated with the {@link Identity | identity} used by this
178
- * Ditto instance.
179
- * */
180
- readonly appID: string
181
-
182
- /**
183
- * Initializes a new `Ditto` instance.
184
- *
185
- * **NOTE**: The `sharedKey` identity is only supported for Node environments,
186
- * using this to create a Ditto instance in the web browser will throw an
187
- * exception.
188
- *
189
- * @param identity - Identity for the new Ditto instance, defaults to
190
- * `offlinePlayground` with `appID` being the empty string `''`.
191
- *
192
- * @param persistenceDirectory optional string containing a directory path
193
- * that Ditto will use for persistence. Defaults to `"ditto"`. On Windows,
194
- * the path will be automatically normalized.
195
- *
196
- * @see {@link Ditto.identity}
197
- * @see {@link Ditto.persistenceDirectory}
198
- * @throws {Error} when the current environment is not supported by this SDK.
199
- * @throws {Error} for other failures during initialization of Ditto and
200
- * validation of the provided identity.
201
- */
202
- constructor(identity?: Identity, persistenceDirectory?: string) {
203
- if (!Ditto.isEnvironmentSupported()) {
204
- throw new Error('Ditto does not support this JavaScript environment. Please consult the Ditto JavaScript documentation for a list of supported environments and browsers. You can use `Ditto.isEnvironmentSupported()` to run this check anytime.')
205
- }
206
-
207
- this.persistenceDirectory = Ditto.initPersistenceDirectory(persistenceDirectory)
208
-
209
- const identityOrDefault = identity ?? { type: 'offlinePlayground', appID: '' }
210
-
211
- const validIdentity = Object.freeze(this.validateIdentity(identityOrDefault))
212
-
213
- this.identity = Object.freeze(validIdentity)
214
-
215
- if (Environment.isReactNativeBuild) {
216
- this.deviceName = FFI.getDeviceName() as string
217
- }
218
-
219
- this.keepAlive = new KeepAlive()
220
-
221
- const uninitializedDittoX = FFI.uninitializedDittoMake(this.persistenceDirectory)
222
-
223
- let secondsRemainingUntilAuthenticationExpires: number | null = null
224
-
225
- const weakThis = new WeakRef(this)
226
- const identityConfig = (() => {
227
- if (validIdentity.type === 'offlinePlayground') {
228
- if (Environment.isReactNativeBuild) {
229
- throw new Error('OfflinePlayground Identity is currently not implemented for React Native.')
230
- }
231
- return FFI.dittoIdentityConfigMakeOfflinePlayground(validIdentity.appID, validIdentity.siteID ?? 0)
232
- }
233
-
234
- if (validIdentity.type === 'manual') {
235
- if (Environment.isReactNativeBuild) {
236
- throw new Error('Manual Identify is currently not implemented for React Native.')
237
- }
238
- return FFI.dittoIdentityConfigMakeManual(validIdentity.certificate)
239
- }
240
-
241
- if (validIdentity.type === 'sharedKey') {
242
- if (Environment.isReactNativeBuild) {
243
- throw new Error('Shared Key Identity is currently not implemented for React Native.')
244
- }
245
- return FFI.dittoIdentityConfigMakeSharedKey(validIdentity.appID, validIdentity.sharedKey, validIdentity.siteID)
246
- }
247
-
248
- if (validIdentity.type === 'onlinePlayground') {
249
- const authURL = validIdentity.customAuthURL ?? defaultAuthURL(validIdentity.appID)
250
- return FFI.dittoIdentityConfigMakeOnlinePlayground(validIdentity.appID, validIdentity.token, authURL)
251
- }
252
-
253
- if (validIdentity.type === 'onlineWithAuthentication') {
254
- const authURL = validIdentity.customAuthURL ?? defaultAuthURL(validIdentity.appID)
255
- return FFI.dittoIdentityConfigMakeOnlineWithAuthentication(validIdentity.appID, authURL)
256
- }
257
-
258
- throw new Error(`Can't create Ditto, unsupported identity type: ${validIdentity}`)
259
- })()
260
-
261
- const dittoPointer = FFI.dittoMake(uninitializedDittoX, identityConfig)
262
-
263
- FFI.dittoAuthClientSetValidityListener(dittoPointer, function (...args) {
264
- const ditto = weakThis.deref()
265
- if (ditto == null || ditto.isClosed) {
266
- Logger.info('Ditto is closed, ignoring auth client validity change')
267
- } else {
268
- ditto.authClientValidityChanged(...args)
269
- }
270
- })
271
-
272
- const isWebValid = FFI.dittoAuthClientIsWebValid(dittoPointer)
273
- const isX509Valid = FFI.dittoAuthClientIsX509Valid(dittoPointer)
274
-
275
- const appID = FFI.dittoAuthClientGetAppID(dittoPointer)
276
- const siteID = FFI.dittoAuthClientGetSiteID(dittoPointer)
277
-
278
- Bridge.ditto.bridge(dittoPointer, this)
279
-
280
- if (validIdentity.type === 'onlineWithAuthentication') {
281
- this.auth = new OnlineAuthenticator(this.keepAlive, this, validIdentity.authHandler)
282
-
283
- const loginProviderX = FFI.dittoAuthClientMakeLoginProvider(function (secondsRemaining) {
284
- const strongThis = weakThis.deref()
285
- if (!strongThis) {
286
- Logger.warning(`Internal inconsistency, LoginProvider callback fired after the corresponding Ditto instance has been deallocated.`)
287
- return
288
- }
289
-
290
- if (strongThis.auth) {
291
- strongThis.auth['@ditto.authenticationExpiring'](secondsRemaining)
292
- } else {
293
-
294
- secondsRemainingUntilAuthenticationExpires = secondsRemaining
295
- }
296
- })
297
-
298
- FFI.dittoAuthSetLoginProvider(dittoPointer, loginProviderX)
299
- } else if (validIdentity.type === 'onlinePlayground') {
300
- this.auth = new OnlineAuthenticator(this.keepAlive, this, {
301
- authenticationRequired: function (authenticator: Authenticator) {
302
- // No-op.
303
- },
304
-
305
- authenticationExpiringSoon: function (authenticator: Authenticator, secondsRemaining: number) {
306
- // No-op.
307
- },
308
- })
309
- } else {
310
- this.auth = new NotAvailableAuthenticator(this.keepAlive)
311
- }
312
-
313
- const transportConfig = this.makeDefaultTransportConfig()
314
-
315
-
316
- this.appID = appID
317
- this.siteID = siteID
318
- this._transportConfig = transportConfig.copy().freeze()
319
-
320
- this.isX509Valid = isX509Valid
321
- this.isWebValid = isWebValid
322
-
323
- this.sync = new Sync(this)
324
- this.sync.update({ isSyncActive: false, isX509Valid, isWebValid, identity: validIdentity, ditto: this, transportConfig })
325
-
326
-
327
- this._isActivated = Environment.isWebBuild || !IdentityTypesRequiringOfflineLicenseToken.includes(validIdentity.type)
328
-
329
- this.store = new Store(this)
330
- this.smallPeerInfo = new SmallPeerInfo(this)
331
- this.presence = new Presence(this)
332
- this.presenceManager = new PresenceManager(this)
333
- this.liveQueryManager = new LiveQueryManager(this, this.keepAlive)
334
- this.attachmentFetcherManager = new AttachmentFetcherManager(this)
335
- this.transportConditionsManager = new TransportConditionsManager(this)
336
- this.subscriptionManager = new SubscriptionManager(this)
337
-
338
- disableDeadlockTimeoutWhenDebugging()
339
-
340
- if (secondsRemainingUntilAuthenticationExpires != null) {
341
- this.auth['@ditto.authenticationExpiring'](secondsRemainingUntilAuthenticationExpires)
342
- }
343
- }
344
-
345
- /**
346
- * Don't terminate the process when callbacks are pending for a long time.
347
- *
348
- * Some methods in the Ditto library accept asynchronous functions as callback
349
- * parameters. If these asynchronous functions do not resolve within a certain
350
- * period of time after having been invoked by Ditto, deadlock detection gets
351
- * triggered, resulting in the termination of the process.
352
- *
353
- * When Ditto is executed in a Node.js environment with an interactive
354
- * debugger attached, this deadlock detection might get activated upon
355
- * encountering a breakpoint. Calling `Ditto.disableDeadlockDetection()`
356
- * disables this behavior, thus allowing the use of an interactive debugger
357
- * without triggering the deadlock detection.
358
- *
359
- * This feature is not available in the browser.
360
- */
361
- static disableDeadlockDetection(): void {
362
- if (Environment.isNodeBuild) {
363
- const current = FFI.getDeadlockTimeout()
364
- if (current !== 0) {
365
- try {
366
- FFI.setDeadlockTimeout(0)
367
- } catch (e: any) {
368
- throw new Error(`Failed to disable deadlock detection: ${e?.message}`)
369
- }
370
- }
371
- }
372
- }
373
-
374
- /**
375
- * Returns `true` if deadlock detection is enabled.
376
- *
377
- * See
378
- * {@link Ditto.disableDeadlockDetection | Ditto.disableDeadlockDetection()}
379
- * for more information.
380
- *
381
- * This method always returns `false` in the browser where deadlock detection
382
- * is not available.
383
- *
384
- * @returns `true` if deadlock detection is enabled
385
- */
386
- static hasDeadlockDetection(): boolean {
387
- if (Environment.isNodeBuild) {
388
- return FFI.getDeadlockTimeout() !== 0
389
- }
390
- return false
391
- }
392
-
393
- /**
394
- * Check if the current environment supports running Ditto.
395
- *
396
- * Required APIs include:
397
- *
398
- * - `BigInt`
399
- * - `FinalizationRegistry`
400
- * - `WeakRef`
401
- *
402
- * Internet Explorer is not supported.
403
- *
404
- * @returns `true` if the environment is supported
405
- */
406
- static isEnvironmentSupported(): boolean {
407
- let isIE = false
408
- if (typeof window !== 'undefined' && window.navigator && window.navigator.userAgent && window.navigator.appVersion) {
409
- isIE = window.navigator.userAgent.indexOf('MSIE') !== -1 || window.navigator.appVersion.indexOf('Trident/') > -1
410
- }
411
-
412
- let hasRequiredAPIs: boolean
413
- try {
414
- hasRequiredAPIs = checkAPIs()
415
- } catch (error) {
416
- throw new Error(`Error checking environment support: ${error}`)
417
- }
418
-
419
- return !isIE && hasRequiredAPIs
420
- }
421
-
422
- /**
423
- * Validates and creates the given directory and returns its path.
424
- *
425
- * Any string containing non-whitespace characters is considered valid.
426
- * Defaults to `ditto` if no path or an invalid path is given. In web
427
- * environments, the given path is returned as-is if it is valid.
428
- *
429
- * @param path optional string containing a writable directory path
430
- * @returns validated path
431
- * @internal
432
- */
433
- static initPersistenceDirectory(path?: string): string {
434
- let validatedPath: string
435
- if (path == null) {
436
- validatedPath = DEFAULT_PERSISTENCE_DIRECTORY
437
- } else if (path.trim().length === 0) {
438
- throw new Error(`Invalid argument for path parameter: '${path}'`)
439
- } else {
440
- validatedPath = path
441
- }
442
-
443
- if (Environment.isReactNativeBuild) {
444
- validatedPath = FFI.createDirectory(validatedPath) as string
445
- }
446
- return validatedPath
447
- }
448
-
449
- /**
450
- * Activate a `Ditto` instance by setting an offline only license token. You
451
- * cannot initiate sync with `Ditto` before you have activated it. The offline
452
- * license token is only valid for identities of type `development`, `manual`,
453
- * `offlinePlayground`, and `sharedKey`.
454
- *
455
- * @param licenseToken the license token to activate the `Ditto` instance
456
- * with. You can find yours on the [Ditto portal](https://portal.ditto.live).
457
- *
458
- * @throws {Error} if called in a React Native environment.
459
- */
460
- setOfflineOnlyLicenseToken(licenseToken: string) {
461
- if (Environment.isWebBuild) {
462
-
463
- Logger.info('Offline license token are ignored on web builds. Token validation will be skipped.')
464
- }
465
- if (Environment.isReactNativeBuild) {
466
- throw new Error('Offline license tokens are currently not implemented for the React Native SDK.')
467
- } else {
468
- if (IdentityTypesRequiringOfflineLicenseToken.includes(this.identity.type)) {
469
- const { result, errorMessage } = FFI.verifyLicense(licenseToken)
470
- if (result !== 'LicenseOk') {
471
- this._isActivated = false
472
- throw new Error(errorMessage)
473
- } else {
474
- this._isActivated = true
475
- }
476
- } else {
477
- throw new Error('Offline license tokens should only be used for manual, sharedKey or offlinePlayground identities')
478
- }
479
- }
480
- }
481
-
482
- /**
483
- * Returns the current transport configuration, frozen. If you want to modify
484
- * the transport config, make a {@link TransportConfig.copy | copy} first. Or
485
- * use the {@link updateTransportConfig | updateTransportConfig()}
486
- * convenience method. By default peer-to-peer transports (Bluetooth, WiFi,
487
- * and AWDL) are enabled if available in the current environment
488
- * (Web, Node, OS, etc.).
489
- *
490
- * @see {@link setTransportConfig | setTransportConfig()}
491
- * @see {@link updateTransportConfig | updateTransportConfig()}
492
- */
493
- get transportConfig(): TransportConfig {
494
- return this._transportConfig
495
- }
496
-
497
- /**
498
- * Assigns a new transports configuration. By default peer-to-peer transports
499
- * (Bluetooth, WiFi, and AWDL) are enabled. You may use this method to alter
500
- * the configuration at any time, however sync will not begin until
501
- * {@link startSync | startSync()} is called.
502
- *
503
- * @see {@link transportConfig}
504
- * @see {@link updateTransportConfig | updateTransportConfig()}
505
- */
506
- setTransportConfig(transportConfig: TransportConfig) {
507
- this._transportConfig = transportConfig.copy().freeze()
508
- const transportConfigNew = this.transportConfig
509
-
510
- const identity = this.identity
511
- const isWebValid = this.isWebValid
512
- const isX509Valid = this.isX509Valid
513
-
514
- this.sync.update({ transportConfig: transportConfigNew, identity, isWebValid, isX509Valid, isSyncActive: this.isSyncActive, ditto: this })
515
-
516
- const configSerializeReady = transportConfigToSerializable(transportConfigNew)
517
- const configCBOR = CBOR.encode(configSerializeReady)
518
- const dittoHandle = Bridge.ditto.handleFor(this)
519
- this.deferClose(() => {
520
- FFI.dittoSmallPeerInfoCollectionSetTransportConfigData(dittoHandle.deref(), configCBOR)
521
- })
522
- }
523
-
524
- /**
525
- * Convenience method for updating the transport config. Creates a copy of the
526
- * current transport config, passes that copy to the `update` closure,
527
- * allowing it to mutate as needed, and sets that updated copy afterwards.
528
- */
529
- updateTransportConfig(update: (transportConfig: TransportConfig) => void): Ditto {
530
- const transportConfig = this.transportConfig.copy()
531
- update(transportConfig)
532
- this.setTransportConfig(transportConfig)
533
- return this
534
- }
535
-
536
- /**
537
- * Starts the network transports. Ditto will connect to other devices.
538
- *
539
- * By default Ditto will enable all peer-to-peer transport types. On **Node**,
540
- * this means BluetoothLE, WiFi/LAN, and AWDL. On the **Web**, only connecting
541
- * via Websockets is supported. The network configuration can be
542
- * customized with {@link updateTransportConfig | updateTransportConfig()}
543
- * or replaced entirely with {@link setTransportConfig | setTransportConfig()}.
544
- *
545
- *
546
- * Ditto will prevent the process from exiting until sync is stopped (not
547
- * relevant when running in the browser).
548
- *
549
- * **NOTE**: the BluetoothLE transport on Linux is experimental, this
550
- * method panics if no BluetoothLE hardware is available. Therefore, contrary
551
- * to the above, the BluetoothLE transport is temporarily disabled by default
552
- * on Linux.
553
- *
554
- * @see {@link isSyncActive}
555
- * @see {@link stopSync | stopSync()}
556
- */
557
- startSync() {
558
- this.setSyncActive(true)
559
- }
560
-
561
- /**
562
- * Stops all network transports.
563
- *
564
- * You may continue to use the database locally but no data will sync to or
565
- * from other devices.
566
- *
567
- * @see {@link isSyncActive}
568
- * @see {@link startSync | startSync()}
569
- */
570
- stopSync() {
571
- this.setSyncActive(false)
572
- }
573
-
574
- /**
575
- * Registers an observer for info about Ditto peers in range of this device.
576
- *
577
- * Ditto will prevent the process from exiting as long as there are active
578
- * peers observers (not relevant when running in the browser).
579
- *
580
- * @param callback called immediately with the current state of peers
581
- * in range and whenever that state changes. Then it will be invoked
582
- * repeatedly when Ditto devices come and go, or the active connections to
583
- * them change.
584
- *
585
- * @deprecated please use {@link Presence.observe | presence.observe()} instead.
586
- */
587
- observePeers(callback: (peersData: RemotePeer[]) => void): Observer {
588
- Logger.warning('`ditto.observePeers()` is deprecated, please use `ditto.presence.observe()` instead.')
589
- const token = this.presenceManager.addObserver(callback)
590
- return new Observer(this.presenceManager, token, { stopsWhenFinalized: true })
591
- }
592
-
593
- /**
594
- * Register observer for changes of underlying transport conditions.
595
- *
596
- * Ditto will prevent the process from exiting as long as there are active
597
- * transport conditions observers (not relevant when running in the browser).
598
- *
599
- * @param callback called when underlying transport conditions change with
600
- * the changed `condition` and its `source`.
601
- */
602
- observeTransportConditions(callback: (condition: TransportCondition, source: ConditionSource) => void): Observer {
603
- const token = this.transportConditionsManager.addObserver(callback)
604
- return new Observer(this.transportConditionsManager, token, { stopsWhenFinalized: true })
605
- }
606
-
607
- /**
608
- * Removes all sync metadata for any remote peers which aren't currently
609
- * connected. This method shouldn't usually be called. Manually running
610
- * garbage collection often will result in slower sync times. Ditto
611
- * automatically runs a garbage a collection process in the background at
612
- * optimal times.
613
- *
614
- * Manually running garbage collection is typically only useful during testing
615
- * if large amounts of data are being generated. Alternatively, if an entire
616
- * data set is to be evicted and it's clear that maintaining this metadata
617
- * isn't necessary, then garbage collection could be run after evicting the
618
- * old data.
619
- *
620
- * Only available in Node environments at the moment, no-op in the browser.
621
- */
622
- runGarbageCollection() {
623
- const dittoHandle = Bridge.ditto.handleFor(this)
624
- return this.deferClose(() => {
625
- FFI.dittoRunGarbageCollection(dittoHandle.deref())
626
- })
627
- }
628
-
629
- /**
630
- * Explicitly opt-in to disabling the ability to sync with Ditto peers running
631
- * any version of the SDK in the v3 (or lower) series of releases.
632
- *
633
- * Assuming this succeeds then this peer will only be able to sync with other
634
- * peers using SDKs in the v4 (or higher) series of releases. Note that this
635
- * disabling of sync spreads to peers that sync with a peer that has disabled,
636
- * or has (transitively) had disabled, syncing with v3 SDK peers.
637
- *
638
- * @throws {Error} if called in a React Native environment.
639
- */
640
- disableSyncWithV3() {
641
- if (Environment.isReactNativeBuild) {
642
- throw new Error('Disabling sync with V3 is not supported in a React Native environment.')
643
- }
644
- const dittoHandle = Bridge.ditto.handleFor(this)
645
- return this.deferClose(() => {
646
- FFI.dittoDisableSyncWithV3(dittoHandle.deref())
647
- })
648
- }
649
-
650
- /**
651
- * Shut down Ditto and release all resources.
652
- *
653
- * Must be called before recreating a Ditto instance that uses the same
654
- * persistence directory.
655
- */
656
- async close() {
657
- if (this.isClosed) {
658
- return
659
- }
660
-
661
- this._isClosed = true
662
-
663
- this.stopSync()
664
-
665
- this.store.close()
666
- this.presence.close()
667
- this.auth.close()
668
- this.sync.close()
669
- this.presenceManager.close()
670
- this.liveQueryManager.close()
671
- this.attachmentFetcherManager.close()
672
- this.transportConditionsManager.close()
673
- this.subscriptionManager.close()
674
-
675
- if (this.keepAlive.isActive) {
676
- throw new Error('Internal inconsistency, still kept alive after the Ditto object has been close()-ed. ')
677
- }
678
-
679
-
680
- do {
681
- await Promise.allSettled(this.pendingOperations)
682
-
683
- } while (this.pendingOperations.size > 0)
684
- this.deferCloseAllowed = false
685
-
686
- await Bridge.ditto.close(this)
687
- }
688
-
689
- // ------------------------------------------------------------ Internal -----
690
-
691
- /** @internal */
692
- keepAlive: KeepAlive
693
-
694
- /** @internal */
695
- liveQueryManager: LiveQueryManager
696
-
697
- /** @internal */
698
- subscriptionManager: SubscriptionManager
699
-
700
- /** @internal */
701
- attachmentFetcherManager: AttachmentFetcherManager
702
-
703
- /**
704
- * The number of operations pending before the Ditto instance can be closed.
705
- *
706
- * For testing purposes only.
707
- * @internal */
708
- get numPendingOperations(): number {
709
- return this.pendingOperations.size
710
- }
711
-
712
- /**
713
- * Makes sure that the closure is executed only if the Ditto instance hasn't
714
- * been closed yet.
715
- *
716
- * @param closure the synchronous closure to execute.
717
- * @returns the result of the closure.
718
- * @throws if the Ditto instance was closed before calling this method.
719
- * @internal */
720
- deferClose<T>(closure: () => T): T {
721
- if (!this.deferCloseAllowed) {
722
- throw new Error(`Can't perform operation using a Ditto instance that has been closed.`)
723
- }
724
-
725
- return closure()
726
- }
727
-
728
- /**
729
- * Makes sure that the closure is executed to completion before the Ditto
730
- * instance is closed.
731
- *
732
- * Any calls to {@link close | `Ditto.close()`} will wait until the closure
733
- * has completed before closing the Ditto instance.
734
- *
735
- * @param closure the asynchronous closure to execute.
736
- * @returns the result of the closure.
737
- * @throws if the Ditto instance was closed before calling this method.
738
- * @internal */
739
- async deferCloseAsync<T>(closure: () => Promise<T>): Promise<T> {
740
- if (!this.deferCloseAllowed) {
741
- throw new Error(`Can't perform operation using a Ditto instance that has been closed.`)
742
- }
743
-
744
- const pendingOperation = closure()
745
- this.pendingOperations.add(pendingOperation)
746
-
747
- let result: T
748
- try {
749
- result = await pendingOperation
750
- } finally {
751
-
752
- this.pendingOperations.delete(pendingOperation)
753
- }
754
-
755
- return result
756
- }
757
-
758
- // ------------------------------------------------------------ Private ------
759
-
760
- private deferCloseAllowed: boolean = true
761
- private isWebValid: boolean = false
762
- private isX509Valid: boolean = false
763
-
764
- private presenceManager: PresenceManager
765
- private transportConditionsManager: ObserverManager
766
-
767
- private _isActivated: boolean
768
- private _isSyncActive: boolean = false
769
- private _isClosed: boolean = false
770
- private _transportConfig: TransportConfig
771
-
772
- /** Set of pending operations that need to complete before the Ditto instance can be closed in a safe manner. */
773
- private pendingOperations = new Set<Promise<any>>()
774
-
775
- private authClientValidityChanged(isWebValid: boolean, isX509Valid: boolean) {
776
- const transportConfig = this.transportConfig
777
- const identity = this.identity
778
-
779
- const isSyncActive = this.isSyncActive
780
- const wasX509Valid = this.isX509Valid
781
- const wasWebValid = this.isWebValid
782
-
783
- this.isX509Valid = isX509Valid
784
- this.isWebValid = isWebValid
785
-
786
- this.auth['@ditto.authClientValidityChanged'](isWebValid, isX509Valid)
787
- this.sync.update({ transportConfig, identity, isWebValid, isX509Valid, isSyncActive, ditto: this })
788
- }
789
-
790
- private validateIdentity(identity: Identity): Identity {
791
- const validIdentity = { ...identity }
792
-
793
- const appID = identity.appID
794
-
795
- if (!['offlinePlayground', 'sharedKey', 'manual', 'onlinePlayground', 'onlineWithAuthentication'].includes(identity.type)) {
796
- throw new Error(`Can't create Ditto instance, unknown identity type: ${identity.type}`)
797
- }
798
-
799
- if ((identity.type === 'offlinePlayground' || identity.type === 'sharedKey' || identity.type === 'onlinePlayground' || identity.type === 'onlineWithAuthentication') && typeof appID === 'undefined') {
800
- throw new Error(`Property .appID must be given for identity, but isn't.`)
801
- }
802
-
803
- if (typeof appID !== 'undefined' && typeof appID !== 'string') {
804
- throw new Error(`Property .appID must be be of type string, but is of type '${typeof appID}': ${appID}`)
805
- }
806
-
807
- if ((identity.type === 'offlinePlayground' || identity.type === 'sharedKey') && typeof identity.siteID !== 'undefined') {
808
- const siteID = identity.siteID
809
- const isSiteIDNumberOrBigInt = typeof siteID === 'number' || typeof siteID === 'bigint'
810
-
811
- if (!isSiteIDNumberOrBigInt) throw new Error("Can't create Ditto instance, siteID must be a number or BigInt")
812
- if (siteID < 0) throw new Error("Can't create Ditto instance, siteID must be >= 0")
813
- if (siteID > BigInt('0xffffffffffffffff')) throw new Error("Can't create Ditto instance, siteID must be < 2^64")
814
- }
815
-
816
- if (identity.type === 'sharedKey') {
817
- }
818
-
819
- if (identity.type === 'manual') {
820
- }
821
-
822
- if (identity.type === 'onlinePlayground') {
823
- const token = identity.token
824
-
825
- if (typeof token === 'undefined') {
826
- throw new Error(`Property .token must be given for identity but isn't. You can find the corresponding token on the Ditto Portal.`)
827
- }
828
-
829
- if (typeof token !== 'undefined' && typeof token !== 'string') {
830
- throw new Error(`Property .token of identity must be be of type string, but is of type '${typeof token}': ${token}`)
831
- }
832
- }
833
-
834
- if (identity.type === 'onlineWithAuthentication') {
835
- }
836
-
837
- return validIdentity
838
- }
839
-
840
- private setSyncActive(flag: boolean) {
841
- const dittoHandle = Bridge.ditto.handleFor(this)
842
- this.deferClose(() => {
843
- if (flag && IdentityTypesRequiringOfflineLicenseToken.includes(this.identity.type) && !this.isActivated) {
844
- throw new Error('Sync could not be started because Ditto has not yet been activated. This can be achieved with a successful call to `setOfflineOnlyLicenseToken`. If you need to obtain a license token then please visit https://portal.ditto.live.')
845
- }
846
-
847
- if (!this.isSyncActive && flag) {
848
- this.keepAlive.retain('sync')
849
- }
850
-
851
- if (this.isSyncActive && !flag) {
852
- this.keepAlive.release('sync')
853
- }
854
-
855
- this._isSyncActive = flag
856
-
857
- const isWebValid = this.isWebValid
858
- const isX509Valid = this.isX509Valid
859
-
860
- const identity = this.identity
861
- const transportConfig = this.transportConfig
862
-
863
- FFI.dittoSetDeviceName(dittoHandle.deref(), this.deviceName)
864
- this.sync.update({ identity, transportConfig, isWebValid, isX509Valid, isSyncActive: !!flag, ditto: this })
865
- })
866
- }
867
-
868
- private makeDefaultTransportConfig(): TransportConfig {
869
- const dittoHandle = Bridge.ditto.handleFor(this)
870
- return this.deferClose(() => {
871
- const transportConfig = new TransportConfig()
872
-
873
- if (FFI.transportsBLEIsAvailable(dittoHandle.deref())) {
874
- transportConfig.peerToPeer.bluetoothLE.isEnabled = true
875
- }
876
-
877
- if (FFI.transportsAWDLIsAvailable(dittoHandle.deref())) {
878
- transportConfig.peerToPeer.awdl.isEnabled = true
879
- }
880
-
881
- if (FFI.transportsLANIsAvailable(dittoHandle.deref())) {
882
- transportConfig.peerToPeer.lan.isEnabled = true
883
- }
884
-
885
- return transportConfig.freeze()
886
- })
887
- }
888
- }
889
-
890
- /**
891
- * Returns true if the current JS environment supports all required APIs.
892
- *
893
- * @param _globalObject optional global object to test this function without
894
- * having to mock `global`.
895
- * @returns `true` iff all required APIs exist on `global`.
896
- * @internal
897
- */
898
- export const checkAPIs = (_globalObject?: typeof globalThis): boolean => {
899
- const requiredBrowserAPIs = ['BigInt', 'WeakRef', 'FinalizationRegistry'] as const
900
- const globalObject = _globalObject || globalThis || global || window
901
- return requiredBrowserAPIs.every((apiName) => !!globalObject[apiName])
902
- }
903
-
904
- /**
905
- * Disable deadlock timeout when Node.js is running with `--inspect` parameter.
906
- *
907
- * This heuristic is not failsafe as debugging mode can also be enabled by
908
- * sending a `SIGUSR1` signal to the process.
909
- *
910
- * @internal
911
- */
912
- export const disableDeadlockTimeoutWhenDebugging = () => {
913
- if (Environment.isNodeBuild) {
914
- const hasInspector = process && process?.execArgv?.some((arg) => arg.includes('--inspect') || arg.includes('--debug'))
915
-
916
- const hasLegacyDebugMode = (process && process?.execArgv?.some((arg) => arg.includes('--debug'))) || typeof v8debug === 'object'
917
-
918
- if (hasInspector || hasLegacyDebugMode) {
919
- try {
920
- FFI.setDeadlockTimeout(0)
921
- Logger.warning('Detected Node running with inspector enabled, disabling deadlock timeout.')
922
- } catch (e: any) {
923
- Logger.error(`Detected Node running with inspector enabled but failed to disable deadlock timeout: ${e?.message}`)
924
- }
925
- }
926
- }
927
- }
928
-
929
- /**
930
- * Return true if we have read and write permissions for the given directory.
931
- *
932
- * Always returns `true` in the browser.
933
- *
934
- * Uses `fs.accessSync()` on all platforms except Windows, where ACLs are not
935
- * checked by that method [1]. On Windows, we try writing and removing a temp
936
- * file to the given path instead.
937
- *
938
- * [1]:
939
- * https://nodejs.org/docs/latest-v18.x/api/fs.html#fsaccesspath-mode-callback
940
- *
941
- * @internal
942
- */
943
- const isDirectoryWritable = (directoryPath: string): boolean => {
944
- return true
945
- }