@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.
- package/DittoReactNative.podspec +27 -0
- package/README.md +2 -2
- package/node/ditto.cjs.js +1 -1
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-arm64.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +5 -2
- package/react-native/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/react-native/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/react-native/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/react-native/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/react-native/android/.gradle/8.9/gc.properties +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/react-native/android/.gradle/vcs-1/gc.properties +0 -0
- package/react-native/android/CMakeLists.txt +36 -0
- package/react-native/android/build.gradle +190 -0
- package/react-native/android/cpp-adapter.cpp +259 -0
- package/react-native/android/gradle.properties +5 -0
- package/react-native/android/src/main/AndroidManifest.xml +4 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +120 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/cpp/include/Arc.hpp +159 -0
- package/react-native/cpp/include/Attachment.h +20 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/ConnectionRequest.h +18 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/FFIUtils.h +16 -0
- package/react-native/cpp/include/IO.h +13 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +16 -0
- package/react-native/cpp/include/LiveQuery.h +17 -0
- package/react-native/cpp/include/Logger.h +22 -0
- package/react-native/cpp/include/Misc.h +30 -0
- package/react-native/cpp/include/Presence.h +18 -0
- package/react-native/cpp/include/SmallPeerInfo.h +19 -0
- package/react-native/cpp/include/Transports.h +25 -0
- package/react-native/cpp/include/TypedArray.hpp +167 -0
- package/react-native/cpp/include/Utils.h +70 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +272 -0
- package/react-native/cpp/src/Authentication.cpp +227 -0
- package/react-native/cpp/src/Collection.cpp +56 -0
- package/react-native/cpp/src/ConnectionRequest.cpp +123 -0
- package/react-native/cpp/src/DQL.cpp +256 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/FFIUtils.cpp +122 -0
- package/react-native/cpp/src/IO.cpp +35 -0
- package/react-native/cpp/src/Identity.cpp +122 -0
- package/react-native/cpp/src/Lifecycle.cpp +93 -0
- package/react-native/cpp/src/LiveQuery.cpp +63 -0
- package/react-native/cpp/src/Logger.cpp +199 -0
- package/react-native/cpp/src/Misc.cpp +322 -0
- package/react-native/cpp/src/Presence.cpp +166 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
- package/react-native/cpp/src/Transports.cpp +275 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +139 -0
- package/react-native/cpp/src/main.cpp +178 -0
- package/react-native/dittoffi/dittoffi.h +4873 -0
- package/react-native/dittoffi/ifaddrs.cpp +385 -0
- package/react-native/dittoffi/ifaddrs.h +206 -0
- package/react-native/ios/DittoRNSDK.h +7 -0
- package/react-native/ios/DittoRNSDK.mm +159 -0
- package/react-native/ios/YeetJSIUtils.h +60 -0
- package/react-native/ios/YeetJSIUtils.mm +196 -0
- package/react-native/lib/commonjs/ditto.rn.js +93 -0
- package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
- package/react-native/lib/commonjs/index.js +61 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +89 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +27 -0
- package/react-native/lib/module/index.js.map +1 -0
- package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
- package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
- package/react-native/lib/typescript/index.d.ts +1 -0
- package/react-native/lib/typescript/index.d.ts.map +1 -0
- package/react-native/src/ditto.rn.ts +123 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +29 -0
- package/react-native/src/sources/@cbor-redux.ts +2 -0
- package/react-native/src/sources/@ditto.core.ts +1 -0
- package/react-native/src/sources/@environment.ts +1 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +145 -0
- package/react-native/src/sources/attachment-fetcher.ts +265 -0
- package/react-native/src/sources/attachment-token.ts +129 -0
- package/react-native/src/sources/attachment.ts +121 -0
- package/react-native/src/sources/augment.ts +108 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +255 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +112 -0
- package/react-native/src/sources/bridge.ts +557 -0
- package/react-native/src/sources/build-time-constants.ts +8 -0
- package/react-native/src/sources/cbor.ts +20 -0
- package/react-native/src/sources/collection-interface.ts +73 -0
- package/react-native/src/sources/collection.ts +219 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/connection-request.ts +142 -0
- package/react-native/src/sources/counter.ts +82 -0
- package/react-native/src/sources/ditto.ts +991 -0
- package/react-native/src/sources/document-id.ts +163 -0
- package/react-native/src/sources/document-path.ts +308 -0
- package/react-native/src/sources/document.ts +237 -0
- package/react-native/src/sources/epilogue.ts +32 -0
- package/react-native/src/sources/error-codes.ts +114 -0
- package/react-native/src/sources/error.ts +256 -0
- package/react-native/src/sources/essentials.ts +81 -0
- package/react-native/src/sources/ffi-error.ts +134 -0
- package/react-native/src/sources/ffi.ts +2190 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +71 -0
- package/react-native/src/sources/internal.ts +143 -0
- package/react-native/src/sources/keep-alive.ts +73 -0
- package/react-native/src/sources/key-path.ts +198 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +110 -0
- package/react-native/src/sources/live-query.ts +167 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/main.ts +61 -0
- package/react-native/src/sources/observer-manager.ts +185 -0
- package/react-native/src/sources/observer.ts +79 -0
- package/react-native/src/sources/pending-collections-operation.ts +241 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +218 -0
- package/react-native/src/sources/presence-manager.ts +170 -0
- package/react-native/src/sources/presence.ts +427 -0
- package/react-native/src/sources/query-result-item.ts +131 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +95 -0
- package/react-native/src/sources/small-peer-info.ts +166 -0
- package/react-native/src/sources/static-tcp-client.ts +8 -0
- package/react-native/src/sources/store-observer.ts +170 -0
- package/react-native/src/sources/store.ts +630 -0
- package/react-native/src/sources/subscription-manager.ts +99 -0
- package/react-native/src/sources/subscription.ts +89 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +561 -0
- package/react-native/src/sources/test-helpers.ts +24 -0
- package/react-native/src/sources/transport-conditions-manager.ts +104 -0
- package/react-native/src/sources/transport-config.ts +430 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +65 -0
- package/react-native/src/sources/websocket-client.ts +7 -0
- package/react-native/src/sources/write-transaction-collection.ts +122 -0
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +74 -0
- package/react-native/src/sources/write-transaction.ts +121 -0
- package/react-native.config.js +9 -0
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","FinalizationGroup","dittoCore","global","isLoaded","ditto_sdk_transports_init","_NativeModules$DittoR","result","DittoRNSDK","install","Error","setInterval","ditto_tick","FinalizationRegistry","platformName","select","ios","android","default","ditto_init_sdk_version","Object","keys","filter","key","forEach","exports","transportsErrorPointer","OS","res","ditto_sdk_transports_set_android_context","getMissingAndroidPermissions","ditto_sdk_transports_android_missing_permissions","boxCStringIntoString","something","boxCBytesIntoBuffer","cborBytes","bytes","sliceBoxedToUInt8Array","Uint8Array","getDeadlockTimeout","setDeadlockTimeout"],"sourceRoot":"../../src","sources":["ditto.rn.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAyB,cAAc;AACvE;;AAEA;AACA;AACA;AACA,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,OAAO,mCAAmC;;AAE1C;;AAEA;AACA;AACA;AAoBA,MAAMC,SAAS,GAAGC,MAAkC;AAEpD,MAAMC,QAAQ,GAAG,OAAOF,SAAS,CAACG,yBAAyB,KAAK,UAAU;AAC1E,IAAI,CAACD,QAAQ,EAAE;EAAA,IAAAE,qBAAA;EACb,MAAMC,MAAM,IAAAD,qBAAA,GAAGP,aAAa,CAACS,UAAU,cAAAF,qBAAA,uBAAxBA,qBAAA,CAA0BG,OAAO,CAAC,CAAC;EAElD,IAAI,CAACF,MAAM,EAAE;IACX,MAAM,IAAIG,KAAK,CAAC,wDAAwD,CAAC;EAC3E;;EAEA;EACA;EACA;EACAC,WAAW,CAAC,MAAM;IAChBT,SAAS,CAACU,UAAU,CAAC,CAAC;EACxB,CAAC,EAAE,EAAE,CAAC;;EAEN;EACA;EACA,IACE,OAAOT,MAAM,CAACU,oBAAoB,KAAK,WAAW,IAClD,OAAOZ,iBAAiB,KAAK,WAAW,EACxC;IACAE,MAAM,CAACU,oBAAoB,GAAGZ,iBAAiB;EACjD;EAEA,MAAMa,YAAiB,GAAGd,QAAQ,CAACe,MAAM,CAAC;IACxCC,GAAG,EAAE,KAAK;IACVC,OAAO,EAAE,SAAS;IAClBC,OAAO,EAAE;EACX,CAAC,CAAC;EAEFhB,SAAS,CAACiB,sBAAsB,CAACL,YAAY,EAAE,YAAY,EAAE,OAAO,CAAC;AACvE;;AAEA;AACAM,MAAM,CAACC,IAAI,CAACnB,SAAS;AACnB;AAAA,CACCoB,MAAM,CAAEC,GAAG,IAAKA,GAAG,KAAK,2BAA2B,CAAC,CACpDC,OAAO,CAAED,GAAG,IAAK;EAChBE,OAAO,CAACF,GAAG,CAAC,GAAGrB,SAAS,CAACqB,GAAG,CAAwB;AACtD,CAAC,CAAC;;AAEJ;AACA;AACA,OAAO,SAASlB,yBAAyBA,CACvCqB,sBAA2B,EAClB;EACT,IAAI1B,QAAQ,CAAC2B,EAAE,KAAK,SAAS,EAAE;IAC7B,MAAMC,GAAG,GAAG1B,SAAS,CAAC2B,wCAAwC,CAAC,CAAC;IAChE,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIlB,KAAK,CACb,0FACF,CAAC;IACH;EACF;EACA,OAAOR,SAAS,CAACG,yBAAyB,CAACqB,sBAAsB,CAAC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,4BAA4BA,CAAA,EAAiB;EAC3D,IAAI9B,QAAQ,CAAC2B,EAAE,KAAK,SAAS,EAAE;IAC7B,OAAO,EAAE;EACX;EACA,OAAOzB,SAAS,CAAC6B,gDAAgD,CAAC,CAAC;AACrE;;AAEA;AACA;AACA;;AAEA,OAAO,SAASC,oBAAoBA,CAACC,SAAc,EAAE;EACnD,OAAOA,SAAS;AAClB;AAEA,OAAO,SAASC,mBAAmBA,CAACC,SAAc,EAAE;EAClD,MAAMC,KAAK,GAAGlC,SAAS,CAACmC,sBAAsB,CAACF,SAAS,CAAC;EACzD,OAAOC,KAAK,GAAG,IAAIE,UAAU,CAACF,KAAK,CAAC,GAAG,IAAI;AAC7C;AAEA,OAAO,SAASG,kBAAkBA,CAAA,EAAW;EAC3C,OAAO,CAAC;AACV;AAEA,OAAO,SAASC,kBAAkBA,CAACP,SAAc,EAAE;EACjD,OAAOA,SAAS;AAClB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// RN API
|
|
2
|
+
|
|
3
|
+
export { getMissingAndroidPermissions } from './ditto.rn';
|
|
4
|
+
|
|
5
|
+
// JS API
|
|
6
|
+
|
|
7
|
+
export * from '../../sources/essentials';
|
|
8
|
+
export * from '../../sources/logger';
|
|
9
|
+
export * from '../../sources/document-id';
|
|
10
|
+
export * from '../../sources/observer';
|
|
11
|
+
export * from '../../sources/authenticator';
|
|
12
|
+
export * from '../../sources/identity';
|
|
13
|
+
export * from '../../sources/ditto';
|
|
14
|
+
export * from '../../sources/store-observer';
|
|
15
|
+
export * from '../../sources/sync';
|
|
16
|
+
export * from '../../sources/sync-subscription';
|
|
17
|
+
export * from '../../sources/error';
|
|
18
|
+
export * from '../../sources/error-codes';
|
|
19
|
+
export * from '../../sources/query-result-item';
|
|
20
|
+
export * from '../../sources/query-result';
|
|
21
|
+
export * from '../../sources/small-peer-info';
|
|
22
|
+
export * from '../../sources/store';
|
|
23
|
+
export * from '../../sources/presence';
|
|
24
|
+
export * from '../../sources/transport-config';
|
|
25
|
+
export * from '../../sources/epilogue';
|
|
26
|
+
|
|
27
|
+
# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Permission } from 'react-native';
|
|
2
|
+
import 'fastestsmallesttextencoderdecoder';
|
|
3
|
+
export declare function ditto_sdk_transports_init(transportsErrorPointer: any): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Get the list of missing Android permissions for syncing. The returned value
|
|
6
|
+
* can be passed directly to `PermissionsAndroid.requestMultiple()`.
|
|
7
|
+
*
|
|
8
|
+
* Returns an empty array on other platforms.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getMissingAndroidPermissions(): Permission[];
|
|
11
|
+
export declare function boxCStringIntoString(something: any): any;
|
|
12
|
+
export declare function boxCBytesIntoBuffer(cborBytes: any): Uint8Array | null;
|
|
13
|
+
export declare function getDeadlockTimeout(): number;
|
|
14
|
+
export declare function setDeadlockTimeout(something: any): any;
|
|
15
|
+
//# sourceMappingURL=ditto.rn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ditto.rn.d.ts","sourceRoot":"","sources":["../../src/ditto.rn.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAOxE,OAAO,mCAAmC,CAAC;AAuE3C,wBAAgB,yBAAyB,CACvC,sBAAsB,EAAE,GAAG,GAC1B,OAAO,CAUT;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,IAAI,UAAU,EAAE,CAK3D;AAMD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,GAAG,OAElD;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,GAAG,qBAGjD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,GAAG,OAEhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { NativeModules, Platform, type Permission } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { FinalizationGroup } from '@ungap/weakrefs';
|
|
4
|
+
import 'fastestsmallesttextencoderdecoder';
|
|
5
|
+
|
|
6
|
+
import { type Language, type Platform as SDKPlatform } from './sources/ffi';
|
|
7
|
+
|
|
8
|
+
interface JSSDKAPI {
|
|
9
|
+
/* C++ methods */
|
|
10
|
+
ditto_sdk_transports_init(transportsErrorPointer: any): boolean;
|
|
11
|
+
ditto_init_sdk_version(
|
|
12
|
+
platform: SDKPlatform,
|
|
13
|
+
language: Language,
|
|
14
|
+
semVer: string
|
|
15
|
+
): number;
|
|
16
|
+
sliceBoxedToUInt8Array(cborBytes: any): Uint8Array | null;
|
|
17
|
+
sliceRefToUInt8Array(cborBytes: any): Uint8Array | null;
|
|
18
|
+
}
|
|
19
|
+
interface PlatformSpecificAPI {
|
|
20
|
+
getRandomValues<T extends ArrayBufferView>(array: T): T;
|
|
21
|
+
ditto_tick(): void;
|
|
22
|
+
createDirectory(path: string): string;
|
|
23
|
+
readFile(path: string): string;
|
|
24
|
+
copyFile(source: string, destination: string, dittoPath: string): string;
|
|
25
|
+
checkDirectoryExists(path: string): string;
|
|
26
|
+
defaultDeviceName(): string;
|
|
27
|
+
|
|
28
|
+
// Android only
|
|
29
|
+
ditto_sdk_transports_set_android_context(): boolean;
|
|
30
|
+
ditto_sdk_transports_android_missing_permissions(): string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DittoCoreType = JSSDKAPI & PlatformSpecificAPI;
|
|
34
|
+
const dittoCore = global as unknown as DittoCoreType;
|
|
35
|
+
|
|
36
|
+
const isLoaded = typeof dittoCore.ditto_sdk_transports_init === 'function';
|
|
37
|
+
if (!isLoaded) {
|
|
38
|
+
const result = NativeModules.DittoRNSDK?.install();
|
|
39
|
+
|
|
40
|
+
if (!result) {
|
|
41
|
+
throw new Error('JSI bindings were not installed for: DittoRNSDK Module');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setInterval(() => {
|
|
45
|
+
dittoCore.ditto_tick();
|
|
46
|
+
}, 50);
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
typeof global.FinalizationRegistry === 'undefined' &&
|
|
50
|
+
typeof FinalizationGroup !== 'undefined'
|
|
51
|
+
) {
|
|
52
|
+
global.FinalizationRegistry = FinalizationGroup;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const platformName: SDKPlatform = Platform.select({
|
|
56
|
+
ios: 'Ios',
|
|
57
|
+
android: 'Android',
|
|
58
|
+
default: 'Unknown',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
dittoCore.ditto_init_sdk_version(
|
|
62
|
+
platformName,
|
|
63
|
+
'JavaScript',
|
|
64
|
+
'4.7.0-rc.1'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Export JSI methods.
|
|
69
|
+
Object.keys(dittoCore)
|
|
70
|
+
// we will provide our own decorated implementation.
|
|
71
|
+
.filter((key) => key !== 'ditto_sdk_transports_init')
|
|
72
|
+
.forEach((key) => {
|
|
73
|
+
exports[key] = dittoCore[key as keyof DittoCoreType];
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export function ditto_sdk_transports_init(
|
|
77
|
+
transportsErrorPointer: any
|
|
78
|
+
): boolean {
|
|
79
|
+
if (Platform.OS === 'android') {
|
|
80
|
+
const res = dittoCore.ditto_sdk_transports_set_android_context();
|
|
81
|
+
if (!res) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Couldn't manage to set Android context with `ditto_sdk_transports_set_android_context()`"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return dittoCore.ditto_sdk_transports_init(transportsErrorPointer);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the list of missing Android permissions for syncing. The returned value
|
|
92
|
+
* can be passed directly to `PermissionsAndroid.requestMultiple()`.
|
|
93
|
+
*
|
|
94
|
+
* Returns an empty array on other platforms.
|
|
95
|
+
*/
|
|
96
|
+
export function getMissingAndroidPermissions(): Permission[] {
|
|
97
|
+
if (Platform.OS !== 'android') {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
return dittoCore.ditto_sdk_transports_android_missing_permissions() as Permission[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//
|
|
104
|
+
// Needed as for JS SDK API's.
|
|
105
|
+
//
|
|
106
|
+
|
|
107
|
+
export function boxCBytesIntoBuffer(cborBytes: any): Uint8Array | null {
|
|
108
|
+
const bytes = dittoCore.sliceBoxedToUInt8Array(cborBytes);
|
|
109
|
+
return bytes ? new Uint8Array(bytes) : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function refCBytesIntoBuffer(cborBytes: any): Uint8Array | null {
|
|
113
|
+
const bytes = dittoCore.sliceRefToUInt8Array(cborBytes);
|
|
114
|
+
return bytes ? new Uint8Array(bytes) : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getDeadlockTimeout(): number {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function setDeadlockTimeout(something: any) {
|
|
122
|
+
return something;
|
|
123
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { getMissingAndroidPermissions } from './ditto.rn';
|
|
2
|
+
|
|
3
|
+
export * from './sources/essentials';
|
|
4
|
+
|
|
5
|
+
export * from './sources/attachment-token';
|
|
6
|
+
export * from './sources/attachment';
|
|
7
|
+
export * from './sources/attachment-fetcher';
|
|
8
|
+
export * from './sources/attachment-fetch-event';
|
|
9
|
+
export * from './sources/init';
|
|
10
|
+
export * from './sources/logger';
|
|
11
|
+
export * from './sources/document-id';
|
|
12
|
+
export * from './sources/observer';
|
|
13
|
+
|
|
14
|
+
export * from './sources/authenticator';
|
|
15
|
+
export * from './sources/identity';
|
|
16
|
+
export * from './sources/ditto';
|
|
17
|
+
export * from './sources/store-observer';
|
|
18
|
+
export * from './sources/sync';
|
|
19
|
+
export * from './sources/sync-subscription';
|
|
20
|
+
export * from './sources/error';
|
|
21
|
+
export * from './sources/error-codes';
|
|
22
|
+
export * from './sources/query-result-item';
|
|
23
|
+
export * from './sources/query-result';
|
|
24
|
+
export * from './sources/small-peer-info';
|
|
25
|
+
export * from './sources/store';
|
|
26
|
+
export * from './sources/presence';
|
|
27
|
+
export * from './sources/transport-config';
|
|
28
|
+
export * from './sources/epilogue';
|
|
29
|
+
export * from './sources/connection-request';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@dittolive/ditto/react-native/src/ditto.rn';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@dittolive/ditto/react-native/src/environment/environment.fallback';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { Attachment } from './attachment'
|
|
6
|
+
import type { Store } from './store'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The types of attachment fetch events that can be delivered to an attachment
|
|
10
|
+
* fetcher's `callback`.
|
|
11
|
+
*/
|
|
12
|
+
export type AttachmentFetchEventType = 'Completed' | 'Progress' | 'Deleted'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An attachment fetch event used when the attachment's download has completed.
|
|
16
|
+
*/
|
|
17
|
+
export type AttachmentFetchEventCompleted = {
|
|
18
|
+
type: 'Completed'
|
|
19
|
+
attachment: Attachment
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An attachment fetch event used when the attachment's download progressed but
|
|
24
|
+
* is not yet complete.
|
|
25
|
+
*/
|
|
26
|
+
export type AttachmentFetchEventProgress = {
|
|
27
|
+
type: 'Progress'
|
|
28
|
+
totalBytes: number | BigInt
|
|
29
|
+
downloadedBytes: number | BigInt
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An attachment fetch event used when the attachment is deleted.
|
|
34
|
+
*/
|
|
35
|
+
export type AttachmentFetchEventDeleted = {
|
|
36
|
+
type: 'Deleted'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A representation of the events that can occur in relation to an attachment
|
|
41
|
+
* fetch.
|
|
42
|
+
*
|
|
43
|
+
* There are three different attachment fetch events: `Completed`, `Progress`,
|
|
44
|
+
* or `Deleted`.
|
|
45
|
+
*
|
|
46
|
+
* There will be at most one `Completed` or `Deleted` event per attachment
|
|
47
|
+
* fetch. There can be many `Progress` events delivered for each attachment
|
|
48
|
+
* fetch.
|
|
49
|
+
*
|
|
50
|
+
* Updates relating to an attachment fetch are delivered by registering an
|
|
51
|
+
* {@link AttachmentFetcher} through a call to
|
|
52
|
+
* {@link Store["fetchAttachment"] | ditto.store.fetchAttachment()}.
|
|
53
|
+
*/
|
|
54
|
+
export type AttachmentFetchEvent = AttachmentFetchEventCompleted | AttachmentFetchEventProgress | AttachmentFetchEventDeleted
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2023 DittoLive Incorporated. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as FFI from './ffi'
|
|
6
|
+
|
|
7
|
+
import { AttachmentFetcher } from './attachment-fetcher'
|
|
8
|
+
import { AttachmentToken } from './attachment-token'
|
|
9
|
+
import { Bridge } from './bridge'
|
|
10
|
+
|
|
11
|
+
import type { AttachmentFetchEvent } from './attachment-fetch-event'
|
|
12
|
+
import type { Ditto } from './ditto'
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
type AttachmentFetcherContextInfo = {
|
|
16
|
+
attachmentFetcher: WeakRef<AttachmentFetcher>
|
|
17
|
+
// Attachment token is unique per attachment.
|
|
18
|
+
attachmentTokenID: Uint8Array
|
|
19
|
+
// This id is unique per attachment fetcher.
|
|
20
|
+
id: string
|
|
21
|
+
// Promise for a token that can be used to cancel the fetch. If `null`, the
|
|
22
|
+
// fetch has already completed, errored, or been canceled.
|
|
23
|
+
cancelTokenPromise: Promise<number | BigInt | null> | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Manages attachment fetchers to make sure we free all resources when the
|
|
28
|
+
* fetcher is garbage collected and to allow us to wait for freeing of
|
|
29
|
+
* ressources to be finished before the ditto instance is closed.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export class AttachmentFetcherManager {
|
|
34
|
+
readonly ditto: Ditto
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
constructor(ditto: Ditto) {
|
|
38
|
+
this.ditto = ditto
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Start an attachment fetcher.
|
|
43
|
+
*
|
|
44
|
+
* @internal */
|
|
45
|
+
startAttachmentFetcher(token: AttachmentToken, eventHandler?: (attachmentFetchEvent: AttachmentFetchEvent) => void): AttachmentFetcher {
|
|
46
|
+
return this.ditto.deferClose(() => {
|
|
47
|
+
const attachmentFetcher = new AttachmentFetcher(this.ditto, token, this, eventHandler)
|
|
48
|
+
|
|
49
|
+
// Register in finalization registry.
|
|
50
|
+
const contextInfo: AttachmentFetcherContextInfo = {
|
|
51
|
+
id: attachmentFetcher.id,
|
|
52
|
+
attachmentTokenID: token.idBytes,
|
|
53
|
+
cancelTokenPromise: attachmentFetcher.cancelTokenPromise,
|
|
54
|
+
attachmentFetcher: new WeakRef(attachmentFetcher),
|
|
55
|
+
}
|
|
56
|
+
this.finalizationRegistry.register(attachmentFetcher, contextInfo, attachmentFetcher)
|
|
57
|
+
|
|
58
|
+
// Keep a reference to the context info so that we can stop the fetcher.
|
|
59
|
+
this.contextInfoByID[attachmentFetcher.id] = contextInfo
|
|
60
|
+
|
|
61
|
+
// Prevent cancellation of the fetch once it was fulfilled or rejected.
|
|
62
|
+
const resetCancelToken = () => {
|
|
63
|
+
if (this.contextInfoByID[attachmentFetcher.id] != null) {
|
|
64
|
+
this.contextInfoByID[attachmentFetcher.id].cancelTokenPromise = null
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
attachmentFetcher.attachment.then(
|
|
68
|
+
(value) => {
|
|
69
|
+
resetCancelToken()
|
|
70
|
+
return value
|
|
71
|
+
},
|
|
72
|
+
(reason) => {
|
|
73
|
+
resetCancelToken()
|
|
74
|
+
return reason
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
// Keep the attachment fetcher alive until it is stopped.
|
|
79
|
+
this.ditto.keepAlive.retain(`AttachmentFetcher.${attachmentFetcher.id})`)
|
|
80
|
+
|
|
81
|
+
return attachmentFetcher
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stop an attachment fetcher and wait for it to be stopped.
|
|
87
|
+
*
|
|
88
|
+
* @internal */
|
|
89
|
+
async stopAttachmentFetcher(attachmentFetcher: AttachmentFetcher): Promise<void> {
|
|
90
|
+
this.finalizationRegistry.unregister(attachmentFetcher)
|
|
91
|
+
const contextInfo = this.contextInfoByID[attachmentFetcher.id]
|
|
92
|
+
if (contextInfo == null) {
|
|
93
|
+
throw new Error(`Internal inconsistency: cannot stop attachment fetcher ${attachmentFetcher.id}, which is not registered.`)
|
|
94
|
+
}
|
|
95
|
+
await this.stopWithContextInfo(contextInfo)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Closing the manager will cancel all attachment fetchers.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
close() {
|
|
104
|
+
void this.ditto.deferCloseAsync(async () => {
|
|
105
|
+
const contextInfos = Object.values(this.contextInfoByID)
|
|
106
|
+
const stopped = contextInfos.map(async (contextInfo) => {
|
|
107
|
+
const attachmentFetcher = contextInfo.attachmentFetcher.deref()
|
|
108
|
+
if (attachmentFetcher != null) {
|
|
109
|
+
await this.stopAttachmentFetcher(attachmentFetcher)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
await Promise.all(stopped)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// --- Private ---
|
|
117
|
+
|
|
118
|
+
private contextInfoByID: { [attachmentFetcherID: string]: AttachmentFetcherContextInfo } = {}
|
|
119
|
+
|
|
120
|
+
private finalizationRegistry: FinalizationRegistry<AttachmentFetcherContextInfo> = new FinalizationRegistry(this.stopWithContextInfo)
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Stop the attachment fetcher without unregistering it from the finalization
|
|
124
|
+
* registry.
|
|
125
|
+
*/
|
|
126
|
+
private stopWithContextInfo(contextInfo: AttachmentFetcherContextInfo): Promise<void> {
|
|
127
|
+
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
128
|
+
return this.ditto.deferCloseAsync(async () => {
|
|
129
|
+
// Remove the manager's own record of the context info.
|
|
130
|
+
if (this.contextInfoByID[contextInfo.id] == null) {
|
|
131
|
+
throw new Error(`Internal inconsistency: attachment fetcher ${contextInfo.id} not found in active attachment fetchers.`)
|
|
132
|
+
}
|
|
133
|
+
delete this.contextInfoByID[contextInfo.id]
|
|
134
|
+
|
|
135
|
+
// Release the keep-alive.
|
|
136
|
+
this.ditto.keepAlive.release(`AttachmentFetcher.${contextInfo.id})`)
|
|
137
|
+
|
|
138
|
+
// Cancel the fetcher if it is still running.
|
|
139
|
+
const cancelToken = await contextInfo.cancelTokenPromise
|
|
140
|
+
if (cancelToken) {
|
|
141
|
+
FFI.dittoCancelResolveAttachment(dittoHandle.deref(), contextInfo.attachmentTokenID, cancelToken)
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
}
|