@trainstar/synchro-react-native 0.1.0
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/LICENSE +20 -0
- package/README.md +122 -0
- package/SynchroReactNative.podspec +22 -0
- package/android/build.gradle +81 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/kotlin/com/trainstar/synchro/rn/SynchroModule.kt +808 -0
- package/android/src/main/kotlin/com/trainstar/synchro/rn/SynchroPackage.kt +32 -0
- package/ios/SynchroModule.mm +368 -0
- package/ios/SynchroModule.swift +970 -0
- package/lib/module/NativeSynchro.js +5 -0
- package/lib/module/NativeSynchro.js.map +1 -0
- package/lib/module/SynchroClient.js +295 -0
- package/lib/module/SynchroClient.js.map +1 -0
- package/lib/module/errors.js +150 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/hooks/index.js +6 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/usePendingChanges.js +25 -0
- package/lib/module/hooks/usePendingChanges.js.map +1 -0
- package/lib/module/hooks/useQuery.js +74 -0
- package/lib/module/hooks/useQuery.js.map +1 -0
- package/lib/module/hooks/useSyncStatus.js +15 -0
- package/lib/module/hooks/useSyncStatus.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSynchro.d.ts +84 -0
- package/lib/typescript/src/NativeSynchro.d.ts.map +1 -0
- package/lib/typescript/src/SynchroClient.d.ts +30 -0
- package/lib/typescript/src/SynchroClient.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +61 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +4 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePendingChanges.d.ts +3 -0
- package/lib/typescript/src/hooks/usePendingChanges.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useQuery.d.ts +12 -0
- package/lib/typescript/src/hooks/useQuery.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSyncStatus.d.ts +4 -0
- package/lib/typescript/src/hooks/useSyncStatus.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +55 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +146 -0
- package/src/NativeSynchro.ts +114 -0
- package/src/SynchroClient.ts +424 -0
- package/src/errors.ts +205 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/usePendingChanges.ts +32 -0
- package/src/hooks/useQuery.ts +93 -0
- package/src/hooks/useSyncStatus.ts +17 -0
- package/src/index.ts +41 -0
- package/src/types.ts +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Trainstar
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# `@trainstar/synchro-react-native`
|
|
2
|
+
|
|
3
|
+
React Native TurboModule bridge for Synchro. The package wraps the native Swift and Kotlin SDKs; it does not implement a separate sync engine in JavaScript.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- React Native `0.83.x`
|
|
8
|
+
- iOS `16.0+`
|
|
9
|
+
- Android `minSdk 24`
|
|
10
|
+
- Node `20+`
|
|
11
|
+
- Android development and CI should use JDK `17`
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @trainstar/synchro-react-native
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
iOS:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
cd ios
|
|
23
|
+
pod install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Android autolinks through the React Native Gradle plugin. No manual `MainApplication` edits are required.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { SynchroClient } from '@trainstar/synchro-react-native';
|
|
32
|
+
|
|
33
|
+
const client = new SynchroClient({
|
|
34
|
+
dbPath: 'synchro.db',
|
|
35
|
+
serverURL: 'https://api.example.com',
|
|
36
|
+
authProvider: async () => '<jwt>',
|
|
37
|
+
clientID: 'device-1',
|
|
38
|
+
appVersion: '1.0.0',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await client.initialize();
|
|
42
|
+
await client.start();
|
|
43
|
+
|
|
44
|
+
const rows = await client.query('SELECT * FROM tasks WHERE done = ?', [0]);
|
|
45
|
+
await client.execute('UPDATE tasks SET done = ? WHERE id = ?', [1, rows[0].id]);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Public API
|
|
49
|
+
|
|
50
|
+
Core methods:
|
|
51
|
+
|
|
52
|
+
- `initialize()`
|
|
53
|
+
- `query(sql, params?)`
|
|
54
|
+
- `queryOne(sql, params?)`
|
|
55
|
+
- `execute(sql, params?)`
|
|
56
|
+
- `executeBatch(statements)`
|
|
57
|
+
- `createTable(...)`
|
|
58
|
+
- `alterTable(...)`
|
|
59
|
+
- `createIndex(...)`
|
|
60
|
+
- `pendingChangeCount()`
|
|
61
|
+
- `start()`
|
|
62
|
+
- `stop()`
|
|
63
|
+
- `syncNow()`
|
|
64
|
+
- `close()`
|
|
65
|
+
|
|
66
|
+
Events and hooks:
|
|
67
|
+
|
|
68
|
+
- `onStatusChange(callback)`
|
|
69
|
+
- `onConflict(callback)`
|
|
70
|
+
- `onSnapshotRequired(handler)`
|
|
71
|
+
- `useQuery(client, sql, params?, tables?)`
|
|
72
|
+
- `useSyncStatus(client)`
|
|
73
|
+
- `usePendingChanges(client, pollInterval?)`
|
|
74
|
+
|
|
75
|
+
## Transactions
|
|
76
|
+
|
|
77
|
+
`writeTransaction()` and `readTransaction()` mirror the native SDKs through a bridge-held transaction session.
|
|
78
|
+
|
|
79
|
+
Contract:
|
|
80
|
+
|
|
81
|
+
- The callback must only perform database work.
|
|
82
|
+
- Do not perform network I/O or long-running waits inside the callback.
|
|
83
|
+
- Transactions time out after 5 seconds of inactivity and reject with `TransactionTimeoutError`.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
await client.writeTransaction(async (tx) => {
|
|
87
|
+
await tx.execute(
|
|
88
|
+
'INSERT INTO tasks (id, title, done) VALUES (?, ?, ?)',
|
|
89
|
+
['task-1', 'Ship RN SDK', 0]
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Errors
|
|
95
|
+
|
|
96
|
+
Native errors are normalized to typed JS errors, including:
|
|
97
|
+
|
|
98
|
+
- `NotConnectedError`
|
|
99
|
+
- `SchemaNotLoadedError`
|
|
100
|
+
- `TableNotSyncedError`
|
|
101
|
+
- `UpgradeRequiredError`
|
|
102
|
+
- `SchemaMismatchError`
|
|
103
|
+
- `SnapshotRequiredError`
|
|
104
|
+
- `PushRejectedError`
|
|
105
|
+
- `NetworkError`
|
|
106
|
+
- `ServerError`
|
|
107
|
+
- `DatabaseError`
|
|
108
|
+
- `InvalidResponseError`
|
|
109
|
+
- `AlreadyStartedError`
|
|
110
|
+
- `NotStartedError`
|
|
111
|
+
- `TransactionTimeoutError`
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npm run typecheck
|
|
117
|
+
npm run test:unit
|
|
118
|
+
npm run prepare
|
|
119
|
+
npm run pack:dry-run
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The example app in [`example/`](./example) is the end-to-end harness used for RN bridge verification on iOS and Android.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "SynchroReactNative"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => "16.0" }
|
|
14
|
+
s.source = { :git => "https://github.com/trainstar/synchro.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
s.dependency "Synchro", "~> 0.1"
|
|
20
|
+
|
|
21
|
+
install_modules_dependencies(s)
|
|
22
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.SynchroReactNative = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return SynchroReactNative[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
mavenLocal()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
dependencies {
|
|
24
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
25
|
+
// noinspection DifferentKotlinGradleVersion
|
|
26
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
apply plugin: "com.android.library"
|
|
32
|
+
apply plugin: "kotlin-android"
|
|
33
|
+
|
|
34
|
+
apply plugin: "com.facebook.react"
|
|
35
|
+
|
|
36
|
+
android {
|
|
37
|
+
namespace "com.trainstar.synchro.rn"
|
|
38
|
+
|
|
39
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
40
|
+
|
|
41
|
+
defaultConfig {
|
|
42
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
43
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
sourceSets {
|
|
47
|
+
main {
|
|
48
|
+
kotlin.srcDirs = ['src/main/kotlin']
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
buildFeatures {
|
|
53
|
+
buildConfig true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
buildTypes {
|
|
57
|
+
release {
|
|
58
|
+
minifyEnabled false
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
lint {
|
|
63
|
+
disable "GradleCompatible"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
compileOptions {
|
|
67
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
68
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
repositories {
|
|
73
|
+
mavenLocal()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
dependencies {
|
|
77
|
+
implementation "com.facebook.react:react-android"
|
|
78
|
+
implementation "com.trainstar:synchro:0.1.0"
|
|
79
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"
|
|
80
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0"
|
|
81
|
+
}
|