@op-engineering/op-sqlite 15.1.2 → 15.1.3

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.
@@ -20,7 +20,7 @@ namespace react = facebook::react;
20
20
  void DBHostObject::flush_pending_reactive_queries(
21
21
  const std::shared_ptr<jsi::Value> &resolve) {
22
22
  invoker->invokeAsync(
23
- [this, resolve]() { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
23
+ [resolve](jsi::Runtime &rt) { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
24
24
  }
25
25
  #else
26
26
  void DBHostObject::flush_pending_reactive_queries(
@@ -36,8 +36,8 @@ void DBHostObject::flush_pending_reactive_queries(
36
36
  metadata);
37
37
 
38
38
  invoker->invokeAsync(
39
- [this, results = std::make_shared<std::vector<DumbHostObject>>(results),
40
- callback = query->callback, metadata, status = std::move(status)] {
39
+ [results = std::make_shared<std::vector<DumbHostObject>>(results),
40
+ callback = query->callback, metadata, status = std::move(status)](jsi::Runtime &rt) {
41
41
  auto jsiResult = create_result(rt, status, results.get(), metadata);
42
42
  callback->asObject(rt).asFunction(rt).call(rt, jsiResult);
43
43
  });
@@ -46,24 +46,24 @@ void DBHostObject::flush_pending_reactive_queries(
46
46
  pending_reactive_queries.clear();
47
47
 
48
48
  invoker->invokeAsync(
49
- [this, resolve]() { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
49
+ [resolve](jsi::Runtime &rt) { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
50
50
  }
51
51
 
52
52
  void DBHostObject::on_commit() {
53
53
  invoker->invokeAsync(
54
- [this] { commit_hook_callback->asObject(rt).asFunction(rt).call(rt); });
54
+ [this](jsi::Runtime &rt) { commit_hook_callback->asObject(rt).asFunction(rt).call(rt); });
55
55
  }
56
56
 
57
57
  void DBHostObject::on_rollback() {
58
58
  invoker->invokeAsync(
59
- [this] { rollback_hook_callback->asObject(rt).asFunction(rt).call(rt); });
59
+ [this](jsi::Runtime &rt) { rollback_hook_callback->asObject(rt).asFunction(rt).call(rt); });
60
60
  }
61
61
 
62
62
  void DBHostObject::on_update(const std::string &table,
63
63
  const std::string &operation, long long row_id) {
64
64
  if (update_hook_callback != nullptr) {
65
65
  invoker->invokeAsync(
66
- [this, callback = update_hook_callback, table, operation, row_id] {
66
+ [callback = update_hook_callback, table, operation, row_id](jsi::Runtime &rt) {
67
67
  auto res = jsi::Object(rt);
68
68
  res.setProperty(rt, "table", jsi::String::createFromUtf8(rt, table));
69
69
  res.setProperty(rt, "operation",
@@ -142,24 +142,21 @@ void DBHostObject::auto_register_update_hook() {
142
142
  #ifdef OP_SQLITE_USE_LIBSQL
143
143
  // Remote connection constructor
144
144
  DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &url,
145
- std::string &auth_token,
146
- std::shared_ptr<react::CallInvoker> invoker)
147
- : db_name(url), invoker(std::move(invoker)), rt(rt) {
145
+ std::string &auth_token)
146
+ : db_name(url) {
148
147
  _thread_pool = std::make_shared<ThreadPool>();
149
148
  db = opsqlite_libsql_open_remote(url, auth_token);
150
149
 
151
- create_jsi_functions();
150
+ create_jsi_functions(rt);
152
151
  }
153
152
 
154
153
  // Sync connection constructor
155
- DBHostObject::DBHostObject(jsi::Runtime &rt,
156
- std::shared_ptr<react::CallInvoker> invoker,
157
- std::string &db_name, std::string &path,
158
- std::string &url, std::string &auth_token,
159
- int sync_interval, bool offline,
160
- std::string &encryption_key,
154
+ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &db_name,
155
+ std::string &path, std::string &url,
156
+ std::string &auth_token, int sync_interval,
157
+ bool offline, std::string &encryption_key,
161
158
  std::string &remote_encryption_key)
162
- : db_name(db_name), invoker(std::move(invoker)), rt(rt) {
159
+ : db_name(db_name) {
163
160
 
164
161
  _thread_pool = std::make_shared<ThreadPool>();
165
162
 
@@ -167,19 +164,17 @@ DBHostObject::DBHostObject(jsi::Runtime &rt,
167
164
  opsqlite_libsql_open_sync(db_name, path, url, auth_token, sync_interval,
168
165
  offline, encryption_key, remote_encryption_key);
169
166
 
170
- create_jsi_functions();
167
+ create_jsi_functions(rt);
171
168
  }
172
169
 
173
170
  #endif
174
171
 
175
172
  DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
176
- std::shared_ptr<react::CallInvoker> invoker,
177
173
  std::string &db_name, std::string &path,
178
174
  std::string &crsqlite_path,
179
175
  std::string &sqlite_vec_path,
180
176
  std::string &encryption_key)
181
- : base_path(base_path), invoker(std::move(invoker)), db_name(db_name),
182
- rt(rt) {
177
+ : base_path(base_path), db_name(db_name) {
183
178
  _thread_pool = std::make_shared<ThreadPool>();
184
179
 
185
180
  #ifdef OP_SQLITE_USE_SQLCIPHER
@@ -190,10 +185,10 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
190
185
  #else
191
186
  db = opsqlite_open(db_name, path, crsqlite_path, sqlite_vec_path);
192
187
  #endif
193
- create_jsi_functions();
188
+ create_jsi_functions(rt);
194
189
  };
195
190
 
196
- void DBHostObject::create_jsi_functions() {
191
+ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
197
192
  function_map["attach"] = HFN(this) {
198
193
  std::string secondary_db_path = std::string(base_path);
199
194
 
@@ -432,19 +427,19 @@ void DBHostObject::create_jsi_functions() {
432
427
  });
433
428
 
434
429
  #ifdef OP_SQLITE_USE_LIBSQL
435
- function_map["sync"] = HOSTFN("sync") {
430
+ function_map["sync"] = HFN(this) {
436
431
  opsqlite_libsql_sync(db);
437
432
  return {};
438
433
  });
439
434
 
440
- function_map["setReservedBytes"] = HOSTFN("setReservedBytes") {
441
- int32_t reserved_bytes = static_cast<int32_t>(args[0].asNumber());
435
+ function_map["setReservedBytes"] =HFN(this) {
436
+ auto reserved_bytes = static_cast<int32_t>(args[0].asNumber());
442
437
  opsqlite_libsql_set_reserved_bytes(db, reserved_bytes);
443
438
  return {};
444
439
  });
445
440
 
446
- function_map["getReservedBytes"] = HOSTFN("getReservedBytes") {
447
- return jsi::Value(opsqlite_libsql_get_reserved_bytes(db));
441
+ function_map["getReservedBytes"] = HFN(this) {
442
+ return {opsqlite_libsql_get_reserved_bytes(db)};
448
443
  });
449
444
  #else
450
445
  function_map["loadFile"] = HFN(this) {
@@ -466,7 +461,7 @@ void DBHostObject::create_jsi_functions() {
466
461
  });
467
462
  });
468
463
 
469
- function_map["updateHook"] = HOSTFN("updateHook") {
464
+ function_map["updateHook"] = HFN(this) {
470
465
  auto callback = std::make_shared<jsi::Value>(rt, args[0]);
471
466
 
472
467
  if (callback->isUndefined() || callback->isNull()) {
@@ -479,7 +474,7 @@ void DBHostObject::create_jsi_functions() {
479
474
  return {};
480
475
  });
481
476
 
482
- function_map["commitHook"] = HOSTFN("commitHook") {
477
+ function_map["commitHook"] = HFN(this) {
483
478
  if (count < 1) {
484
479
  throw std::runtime_error("[op-sqlite][commitHook] callback needed");
485
480
  }
@@ -495,7 +490,7 @@ void DBHostObject::create_jsi_functions() {
495
490
  return {};
496
491
  });
497
492
 
498
- function_map["rollbackHook"] = HOSTFN("rollbackHook") {
493
+ function_map["rollbackHook"] = HFN(this) {
499
494
  if (count < 1) {
500
495
  throw std::runtime_error("[op-sqlite][rollbackHook] callback needed");
501
496
  }
@@ -512,7 +507,7 @@ void DBHostObject::create_jsi_functions() {
512
507
  return {};
513
508
  });
514
509
 
515
- function_map["loadExtension"] = HOSTFN("loadExtension") {
510
+ function_map["loadExtension"] = HFN(this) {
516
511
  auto path = args[0].asString(rt).utf8(rt);
517
512
  std::string entry_point;
518
513
  if (count > 1 && args[1].isString()) {
@@ -523,7 +518,7 @@ void DBHostObject::create_jsi_functions() {
523
518
  return {};
524
519
  });
525
520
 
526
- function_map["reactiveExecute"] = HOSTFN("reactiveExecute") {
521
+ function_map["reactiveExecute"] = HFN(this) {
527
522
  auto query = args[0].asObject(rt);
528
523
 
529
524
  const std::string query_str =
@@ -566,7 +561,7 @@ void DBHostObject::create_jsi_functions() {
566
561
 
567
562
  auto_register_update_hook();
568
563
 
569
- auto unsubscribe = HOSTFN("unsubscribe") {
564
+ auto unsubscribe = HFN2(this, reactiveQuery) {
570
565
  auto it = std::find(reactive_queries.begin(), reactive_queries.end(),
571
566
  reactiveQuery);
572
567
  if (it != reactive_queries.end()) {
@@ -580,7 +575,7 @@ void DBHostObject::create_jsi_functions() {
580
575
  });
581
576
  #endif
582
577
 
583
- function_map["prepareStatement"] = HOSTFN("prepareStatement") {
578
+ function_map["prepareStatement"] = HFN(this) {
584
579
  auto query = args[0].asString(rt).utf8(rt);
585
580
  #ifdef OP_SQLITE_USE_LIBSQL
586
581
  libsql_stmt_t statement = opsqlite_libsql_prepare_statement(db, query);
@@ -593,7 +588,7 @@ void DBHostObject::create_jsi_functions() {
593
588
  return jsi::Object::createFromHostObject(rt, preparedStatementHostObject);
594
589
  });
595
590
 
596
- function_map["getDbPath"] = HOSTFN("getDbPath") {
591
+ function_map["getDbPath"] = HFN(this) {
597
592
  std::string path = std::string(base_path);
598
593
 
599
594
  if (count == 1) {
@@ -617,13 +612,12 @@ void DBHostObject::create_jsi_functions() {
617
612
  return jsi::String::createFromUtf8(rt, result);
618
613
  });
619
614
 
620
- function_map["flushPendingReactiveQueries"] =
621
- HOSTFN("flushPendingReactiveQueries") {
615
+ function_map["flushPendingReactiveQueries"] = HFN(this) {
622
616
  auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
623
- auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
617
+ auto promise = promiseCtr.callAsConstructor(rt, HFN(this) {
624
618
  auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
625
619
 
626
- auto task = [&rt, this, resolve]() {
620
+ auto task = [this, resolve]() {
627
621
  flush_pending_reactive_queries(resolve);
628
622
  };
629
623
 
@@ -645,11 +639,11 @@ std::vector<jsi::PropNameID> DBHostObject::getPropertyNames(jsi::Runtime &_rt) {
645
639
  return keys;
646
640
  }
647
641
 
648
- jsi::Value DBHostObject::get(jsi::Runtime &_rt,
642
+ jsi::Value DBHostObject::get(jsi::Runtime &rt,
649
643
  const jsi::PropNameID &propNameID) {
650
644
  auto name = propNameID.utf8(rt);
651
645
  if (function_map.count(name) != 1) {
652
- return HOST_STATIC_FN(name.c_str()) {
646
+ return HFN(name) {
653
647
  throw std::runtime_error(
654
648
  "[op-sqlite] Function " + name +
655
649
  " not implemented for current backend (libsql or sqlcipher)");
@@ -44,22 +44,19 @@ struct ReactiveQuery {
44
44
  class JSI_EXPORT DBHostObject : public jsi::HostObject {
45
45
  public:
46
46
  // Normal constructor shared between all backends
47
- DBHostObject(jsi::Runtime &rt, std::string &base_path,
48
- std::shared_ptr<react::CallInvoker> invoker,
49
- std::string &db_name, std::string &path,
50
- std::string &crsqlite_path, std::string &sqlite_vec_path,
51
- std::string &encryption_key);
47
+ DBHostObject(jsi::Runtime &rt, std::string &base_path, std::string &db_name,
48
+ std::string &path, std::string &crsqlite_path,
49
+ std::string &sqlite_vec_path, std::string &encryption_key);
52
50
 
53
51
  #ifdef OP_SQLITE_USE_LIBSQL
54
52
  // Constructor for remoteOpen, purely for remote databases
55
- DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
56
- std::shared_ptr<react::CallInvoker> invoker);
53
+ DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token);
57
54
 
58
55
  // Constructor for a local database with remote sync
59
- DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
60
- std::string &db_name, std::string &path, std::string &url,
61
- std::string &auth_token, int sync_interval, bool offline,
62
- std::string &encryption_key, std::string &remote_encryption_key);
56
+ DBHostObject(jsi::Runtime &rt, std::string &db_name, std::string &path,
57
+ std::string &url, std::string &auth_token, int sync_interval,
58
+ bool offline, std::string &encryption_key,
59
+ std::string &remote_encryption_key);
63
60
  #endif
64
61
 
65
62
  std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
@@ -76,19 +73,16 @@ public:
76
73
  private:
77
74
  std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
78
75
  void auto_register_update_hook();
79
- void create_jsi_functions();
80
- void
81
- flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
76
+ void create_jsi_functions(jsi::Runtime &rt);
77
+ void flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
82
78
 
83
79
  std::unordered_map<std::string, jsi::Value> function_map;
84
80
  std::string base_path;
85
- std::shared_ptr<react::CallInvoker> invoker;
86
81
  std::shared_ptr<ThreadPool> _thread_pool;
87
82
  std::string db_name;
88
83
  std::shared_ptr<jsi::Value> update_hook_callback;
89
84
  std::shared_ptr<jsi::Value> commit_hook_callback;
90
85
  std::shared_ptr<jsi::Value> rollback_hook_callback;
91
- jsi::Runtime &rt;
92
86
  std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
93
87
  std::vector<PendingReactiveInvocation> pending_reactive_invocations;
94
88
  bool is_update_hook_registered = false;
package/cpp/OPSqlite.cpp CHANGED
@@ -43,14 +43,14 @@ void invalidate() {
43
43
  }
44
44
 
45
45
  void install(jsi::Runtime &rt,
46
- const std::shared_ptr<react::CallInvoker> &invoker,
46
+ const std::shared_ptr<react::CallInvoker> &_invoker,
47
47
  const char *base_path, const char *crsqlite_path,
48
48
  const char *sqlite_vec_path) {
49
49
 
50
50
  _base_path = std::string(base_path);
51
51
  _crsqlite_path = std::string(crsqlite_path);
52
52
  _sqlite_vec_path = std::string(sqlite_vec_path);
53
- opsqlite::invoker = invoker;
53
+ opsqlite::invoker = _invoker;
54
54
  opsqlite::invalidated = false;
55
55
 
56
56
  auto open = HFN0 {
@@ -69,12 +69,6 @@ void install(jsi::Runtime &rt,
69
69
  options.getProperty(rt, "encryptionKey").asString(rt).utf8(rt);
70
70
  }
71
71
 
72
- #ifdef OP_SQLITE_USE_SQLCIPHER
73
- if (encryption_key.empty()) {
74
- log_to_console(rt, "Encryption key is missing for SQLCipher");
75
- }
76
- #endif
77
-
78
72
  if (!location.empty()) {
79
73
  if (location == ":memory:") {
80
74
  path = ":memory:";
@@ -86,13 +80,12 @@ void install(jsi::Runtime &rt,
86
80
  }
87
81
 
88
82
  std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
89
- rt, path, opsqlite::invoker, name, path, _crsqlite_path,
90
- _sqlite_vec_path, encryption_key);
83
+ rt, path, name, path, _crsqlite_path, _sqlite_vec_path, encryption_key);
91
84
  dbs.emplace_back(db);
92
85
  return jsi::Object::createFromHostObject(rt, db);
93
86
  });
94
87
 
95
- auto is_sqlcipher = HOST_STATIC_FN("isSQLCipher") {
88
+ auto is_sqlcipher = HFN(=) {
96
89
  #ifdef OP_SQLITE_USE_SQLCIPHER
97
90
  return true;
98
91
  #else
@@ -100,7 +93,7 @@ void install(jsi::Runtime &rt,
100
93
  #endif
101
94
  });
102
95
 
103
- auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
96
+ auto is_ios_embedded = HFN(=) {
104
97
  #ifdef OP_SQLITE_USE_PHONE_VERSION
105
98
  return true;
106
99
  #else
@@ -108,7 +101,7 @@ void install(jsi::Runtime &rt,
108
101
  #endif
109
102
  });
110
103
 
111
- auto is_libsql = HOST_STATIC_FN("isLibsql") {
104
+ auto is_libsql = HFN(=) {
112
105
  #ifdef OP_SQLITE_USE_LIBSQL
113
106
  return true;
114
107
  #else
@@ -117,7 +110,7 @@ void install(jsi::Runtime &rt,
117
110
  });
118
111
 
119
112
  #ifdef OP_SQLITE_USE_LIBSQL
120
- auto open_remote = HOST_STATIC_FN("openRemote") {
113
+ auto open_remote = HFN(=) {
121
114
  jsi::Object options = args[0].asObject(rt);
122
115
 
123
116
  std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt);
@@ -126,12 +119,12 @@ void install(jsi::Runtime &rt,
126
119
  options.getProperty(rt, "authToken").asString(rt).utf8(rt);
127
120
 
128
121
  std::shared_ptr<DBHostObject> db =
129
- std::make_shared<DBHostObject>(rt, url, auth_token, invoker);
122
+ std::make_shared<DBHostObject>(rt, url, auth_token);
130
123
 
131
124
  return jsi::Object::createFromHostObject(rt, db);
132
125
  });
133
126
 
134
- auto open_sync = HOST_STATIC_FN("openSync") {
127
+ auto open_sync = HFN(=) {
135
128
  jsi::Object options = args[0].asObject(rt);
136
129
  std::string name = options.getProperty(rt, "name").asString(rt).utf8(rt);
137
130
  std::string path = std::string(_base_path);
@@ -169,7 +162,7 @@ void install(jsi::Runtime &rt,
169
162
  if (!location.empty()) {
170
163
  if (location == ":memory:") {
171
164
  path = ":memory:";
172
- } else if (location.rfind("/", 0) == 0) {
165
+ } else if (location.rfind('/', 0) == 0) {
173
166
  path = location;
174
167
  } else {
175
168
  path = path + "/" + location;
@@ -177,8 +170,8 @@ void install(jsi::Runtime &rt,
177
170
  }
178
171
 
179
172
  std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
180
- rt, invoker, name, path, url, auth_token, sync_interval, offline,
181
- encryption_key, remote_encryption_key);
173
+ rt, name, path, url, auth_token, sync_interval, offline, encryption_key,
174
+ remote_encryption_key);
182
175
  return jsi::Object::createFromHostObject(rt, db);
183
176
  });
184
177
  #endif
@@ -48,7 +48,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
48
48
  }
49
49
 
50
50
  if (name == "bindSync") {
51
- return HOSTFN("bindSync") {
51
+ return HFN(this) {
52
52
  if (_stmt == nullptr) {
53
53
  throw std::runtime_error("statement has been freed");
54
54
  }
@@ -71,7 +71,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
71
71
  }
72
72
 
73
73
  if (name == "execute") {
74
- return HOSTFN("execute") {
74
+ return HFN(this) {
75
75
  if (_stmt == nullptr) {
76
76
  throw std::runtime_error("statement has been freed");
77
77
  }
package/cpp/macros.hpp CHANGED
@@ -1,19 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #define HOSTFN(name) \
4
- jsi::Function::createFromHostFunction( \
5
- rt, \
6
- jsi::PropNameID::forAscii(rt, name), \
7
- 0, \
8
- [=, this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
9
-
10
- #define HOST_STATIC_FN(name) \
11
- jsi::Function::createFromHostFunction( \
12
- rt, \
13
- jsi::PropNameID::forAscii(rt, name), \
14
- 0, \
15
- [=](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
16
-
17
3
  // Do not unroll into multi lines to avoid Xcode reporting the wrong lines
18
4
  #define HFN0 jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
19
5
  #define HFN(c1) jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [c1](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
package/op-sqlite.podspec CHANGED
@@ -33,8 +33,8 @@ if is_user_app
33
33
  raise "package.json not found" if package_json_path.nil?
34
34
 
35
35
  app_package = JSON.parse(File.read(package_json_path))
36
- # When running on the example app
37
36
  else
37
+ # When running on the example app
38
38
  package_json_path = File.join(__dir__, "example", "package.json")
39
39
  app_package = JSON.parse(File.read(File.join(__dir__, "example", "package.json")))
40
40
  end
@@ -90,7 +90,7 @@ Pod::Spec.new do |s|
90
90
  s.license = package["license"]
91
91
  s.authors = package["author"]
92
92
 
93
- s.platforms = { :ios => "13.0", :tvos => "13.0", :osx => "10.15", :visionos => "1.0" }
93
+ s.platforms = { :ios => min_ios_version_supported, :tvos => "13.0", :osx => "10.15", :visionos => "1.0" }
94
94
  s.source = { :git => "https://github.com/op-engineering/op-sqlite.git", :tag => "#{s.version}" }
95
95
 
96
96
  install_modules_dependencies(s)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "15.1.2",
3
+ "version": "15.1.3",
4
4
  "description": "Fastest SQLite for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",