@tursodatabase/sync-react-native 0.5.0-pre.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/README.md +117 -0
- package/android/CMakeLists.txt +53 -0
- package/android/build.gradle +84 -0
- package/android/cpp-adapter.cpp +49 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoBridge.java +44 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoModule.java +82 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoPackage.java +29 -0
- package/cpp/TursoConnectionHostObject.cpp +179 -0
- package/cpp/TursoConnectionHostObject.h +52 -0
- package/cpp/TursoDatabaseHostObject.cpp +98 -0
- package/cpp/TursoDatabaseHostObject.h +49 -0
- package/cpp/TursoHostObject.cpp +561 -0
- package/cpp/TursoHostObject.h +24 -0
- package/cpp/TursoStatementHostObject.cpp +414 -0
- package/cpp/TursoStatementHostObject.h +65 -0
- package/cpp/TursoSyncChangesHostObject.cpp +41 -0
- package/cpp/TursoSyncChangesHostObject.h +52 -0
- package/cpp/TursoSyncDatabaseHostObject.cpp +328 -0
- package/cpp/TursoSyncDatabaseHostObject.h +61 -0
- package/cpp/TursoSyncIoItemHostObject.cpp +304 -0
- package/cpp/TursoSyncIoItemHostObject.h +52 -0
- package/cpp/TursoSyncOperationHostObject.cpp +168 -0
- package/cpp/TursoSyncOperationHostObject.h +53 -0
- package/ios/TursoModule.h +8 -0
- package/ios/TursoModule.mm +95 -0
- package/lib/commonjs/Database.js +445 -0
- package/lib/commonjs/Database.js.map +1 -0
- package/lib/commonjs/Statement.js +339 -0
- package/lib/commonjs/Statement.js.map +1 -0
- package/lib/commonjs/index.js +229 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/asyncOperation.js +124 -0
- package/lib/commonjs/internal/asyncOperation.js.map +1 -0
- package/lib/commonjs/internal/ioProcessor.js +315 -0
- package/lib/commonjs/internal/ioProcessor.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +133 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/Database.js +441 -0
- package/lib/module/Database.js.map +1 -0
- package/lib/module/Statement.js +335 -0
- package/lib/module/Statement.js.map +1 -0
- package/lib/module/index.js +205 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/asyncOperation.js +116 -0
- package/lib/module/internal/asyncOperation.js.map +1 -0
- package/lib/module/internal/ioProcessor.js +309 -0
- package/lib/module/internal/ioProcessor.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +163 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/Database.d.ts +140 -0
- package/lib/typescript/Database.d.ts.map +1 -0
- package/lib/typescript/Statement.d.ts +105 -0
- package/lib/typescript/Statement.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +175 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/internal/asyncOperation.d.ts +39 -0
- package/lib/typescript/internal/asyncOperation.d.ts.map +1 -0
- package/lib/typescript/internal/ioProcessor.d.ts +48 -0
- package/lib/typescript/internal/ioProcessor.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +316 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +97 -0
- package/src/Database.ts +480 -0
- package/src/Statement.ts +372 -0
- package/src/index.ts +240 -0
- package/src/internal/asyncOperation.ts +147 -0
- package/src/internal/ioProcessor.ts +328 -0
- package/src/types.ts +391 -0
- package/turso-sync-react-native.podspec +56 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#include "TursoDatabaseHostObject.h"
|
|
2
|
+
#include "TursoConnectionHostObject.h"
|
|
3
|
+
|
|
4
|
+
extern "C" {
|
|
5
|
+
#include <turso.h>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
namespace turso {
|
|
9
|
+
|
|
10
|
+
TursoDatabaseHostObject::~TursoDatabaseHostObject() {
|
|
11
|
+
if (db_) {
|
|
12
|
+
turso_database_deinit(db_);
|
|
13
|
+
db_ = nullptr;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void TursoDatabaseHostObject::throwError(jsi::Runtime &rt, const char *error) {
|
|
18
|
+
throw jsi::JSError(rt, error ? error : "Unknown error");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
jsi::Value TursoDatabaseHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
|
|
22
|
+
auto propName = name.utf8(rt);
|
|
23
|
+
|
|
24
|
+
if (propName == "open") {
|
|
25
|
+
return jsi::Function::createFromHostFunction(
|
|
26
|
+
rt, name, 0,
|
|
27
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
28
|
+
return this->open(rt);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (propName == "connect") {
|
|
34
|
+
return jsi::Function::createFromHostFunction(
|
|
35
|
+
rt, name, 0,
|
|
36
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
37
|
+
return this->connect(rt);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (propName == "close") {
|
|
43
|
+
return jsi::Function::createFromHostFunction(
|
|
44
|
+
rt, name, 0,
|
|
45
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
46
|
+
return this->close(rt);
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return jsi::Value::undefined();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void TursoDatabaseHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) {
|
|
55
|
+
// Read-only object
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
std::vector<jsi::PropNameID> TursoDatabaseHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
59
|
+
std::vector<jsi::PropNameID> props;
|
|
60
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "open"));
|
|
61
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "connect"));
|
|
62
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "close"));
|
|
63
|
+
return props;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 1:1 C API mapping - NO logic, just calls through to C API
|
|
67
|
+
jsi::Value TursoDatabaseHostObject::open(jsi::Runtime &rt) {
|
|
68
|
+
const char* error = nullptr;
|
|
69
|
+
turso_status_code_t status = turso_database_open(db_, &error);
|
|
70
|
+
|
|
71
|
+
if (status != TURSO_OK) {
|
|
72
|
+
throwError(rt, error);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return jsi::Value::undefined();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
jsi::Value TursoDatabaseHostObject::connect(jsi::Runtime &rt) {
|
|
79
|
+
turso_connection_t* connection = nullptr;
|
|
80
|
+
const char* error = nullptr;
|
|
81
|
+
turso_status_code_t status = turso_database_connect(db_, &connection, &error);
|
|
82
|
+
|
|
83
|
+
if (status != TURSO_OK) {
|
|
84
|
+
throwError(rt, error);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Wrap connection in TursoConnectionHostObject
|
|
88
|
+
auto connectionObj = std::make_shared<TursoConnectionHostObject>(connection);
|
|
89
|
+
return jsi::Object::createFromHostObject(rt, connectionObj);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
jsi::Value TursoDatabaseHostObject::close(jsi::Runtime &rt) {
|
|
93
|
+
// turso_database_close doesn't exist in the C API
|
|
94
|
+
// Closing happens in destructor via turso_database_deinit
|
|
95
|
+
return jsi::Value::undefined();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
} // namespace turso
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
// Forward declarations for Turso C API types
|
|
8
|
+
extern "C" {
|
|
9
|
+
struct turso_database;
|
|
10
|
+
struct turso_connection;
|
|
11
|
+
typedef struct turso_database turso_database_t;
|
|
12
|
+
typedef struct turso_connection turso_connection_t;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
namespace turso {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* TursoDatabaseHostObject wraps turso_database_t* (core SDK-KIT type for local database).
|
|
21
|
+
* This is a THIN wrapper - 1:1 mapping of SDK-KIT C API with NO logic.
|
|
22
|
+
* All logic belongs in TypeScript or Rust, not here.
|
|
23
|
+
*/
|
|
24
|
+
class TursoDatabaseHostObject : public jsi::HostObject {
|
|
25
|
+
public:
|
|
26
|
+
TursoDatabaseHostObject(turso_database_t* db) : db_(db) {}
|
|
27
|
+
~TursoDatabaseHostObject();
|
|
28
|
+
|
|
29
|
+
// JSI HostObject interface
|
|
30
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name) override;
|
|
31
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) override;
|
|
32
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
33
|
+
|
|
34
|
+
// Direct access to wrapped pointer (for internal use)
|
|
35
|
+
turso_database_t* getDatabase() const { return db_; }
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
turso_database_t* db_ = nullptr;
|
|
39
|
+
|
|
40
|
+
// Helper to throw JS errors
|
|
41
|
+
void throwError(jsi::Runtime &rt, const char *error);
|
|
42
|
+
|
|
43
|
+
// 1:1 C API mapping methods (NO logic - just calls through to C API)
|
|
44
|
+
jsi::Value open(jsi::Runtime &rt);
|
|
45
|
+
jsi::Value connect(jsi::Runtime &rt);
|
|
46
|
+
jsi::Value close(jsi::Runtime &rt);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
} // namespace turso
|