@op-engineering/op-sqlite 0.0.0-resolution-test

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 (99) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +31 -0
  3. package/android/.project +17 -0
  4. package/android/.settings/org.eclipse.buildship.core.prefs +13 -0
  5. package/android/CMakeLists.txt +141 -0
  6. package/android/build.gradle +266 -0
  7. package/android/c_sources/tokenizers.cpp +88 -0
  8. package/android/c_sources/tokenizers.h +15 -0
  9. package/android/cpp-adapter.cpp +46 -0
  10. package/android/gradle.properties +1 -0
  11. package/android/jniLibs/arm64-v8a/libsql_experimental.a +0 -0
  12. package/android/jniLibs/armeabi-v7a/libsql_experimental.a +0 -0
  13. package/android/jniLibs/x86/libsql_experimental.a +0 -0
  14. package/android/jniLibs/x86_64/libsql_experimental.a +0 -0
  15. package/android/src/main/AndroidManifest.xml +1 -0
  16. package/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt +37 -0
  17. package/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +119 -0
  18. package/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt +18 -0
  19. package/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so +0 -0
  20. package/android/src/main/jniLibs/arm64-v8a/libsqlite_vec.so +0 -0
  21. package/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so +0 -0
  22. package/android/src/main/jniLibs/armeabi-v7a/libsqlite_vec.so +0 -0
  23. package/android/src/main/jniLibs/x86/libcrsqlite.so +0 -0
  24. package/android/src/main/jniLibs/x86/libsqlite_vec.so +0 -0
  25. package/android/src/main/jniLibs/x86_64/libcrsqlite.so +0 -0
  26. package/android/src/main/jniLibs/x86_64/libsqlite_vec.so +0 -0
  27. package/android/src/paper/java/com/op/sqlite/NativeOPSQLiteSpec.java +77 -0
  28. package/cpp/DBHostObject.cpp +852 -0
  29. package/cpp/DBHostObject.h +99 -0
  30. package/cpp/DumbHostObject.cpp +72 -0
  31. package/cpp/DumbHostObject.h +36 -0
  32. package/cpp/OPThreadPool.cpp +120 -0
  33. package/cpp/OPThreadPool.h +44 -0
  34. package/cpp/PreparedStatementHostObject.cpp +151 -0
  35. package/cpp/PreparedStatementHostObject.h +59 -0
  36. package/cpp/SmartHostObject.cpp +34 -0
  37. package/cpp/SmartHostObject.h +24 -0
  38. package/cpp/bindings.cpp +182 -0
  39. package/cpp/bindings.h +19 -0
  40. package/cpp/bridge.cpp +873 -0
  41. package/cpp/bridge.h +80 -0
  42. package/cpp/libsql/bridge.cpp +738 -0
  43. package/cpp/libsql/bridge.h +85 -0
  44. package/cpp/libsql/libsql.h +172 -0
  45. package/cpp/logs.h +40 -0
  46. package/cpp/macros.h +15 -0
  47. package/cpp/sqlcipher/sqlite3.c +262970 -0
  48. package/cpp/sqlcipher/sqlite3.h +13485 -0
  49. package/cpp/sqlite3.c +261454 -0
  50. package/cpp/sqlite3.h +13715 -0
  51. package/cpp/types.h +33 -0
  52. package/cpp/utils.cpp +327 -0
  53. package/cpp/utils.h +47 -0
  54. package/generate_tokenizers_header_file.rb +29 -0
  55. package/ios/OPSQLite.h +7 -0
  56. package/ios/OPSQLite.mm +157 -0
  57. package/ios/OPSQLite.xcodeproj/project.pbxproj +275 -0
  58. package/ios/crsqlite.xcframework/Info.plist +46 -0
  59. package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/Info.plist +24 -0
  60. package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/crsqlite +0 -0
  61. package/ios/crsqlite.xcframework/ios-arm64_x86_64-simulator/crsqlite.framework/Info.plist +24 -0
  62. package/ios/crsqlite.xcframework/ios-arm64_x86_64-simulator/crsqlite.framework/crsqlite +0 -0
  63. package/ios/libsql.xcframework/Info.plist +48 -0
  64. package/ios/libsql.xcframework/ios-arm64/Headers/libsql.h +172 -0
  65. package/ios/libsql.xcframework/ios-arm64/libsql_experimental.a +0 -0
  66. package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h +172 -0
  67. package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a +0 -0
  68. package/ios/sqlitevec.xcframework/Info.plist +71 -0
  69. package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/Info.plist +24 -0
  70. package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/sqlitevec +0 -0
  71. package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/Info.plist +24 -0
  72. package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec +0 -0
  73. package/ios/sqlitevec.xcframework/tvos-arm64/sqlitevec.framework/Info.plist +24 -0
  74. package/ios/sqlitevec.xcframework/tvos-arm64/sqlitevec.framework/sqlitevec +0 -0
  75. package/ios/sqlitevec.xcframework/tvos-arm64_x86_64-simulator/sqlitevec.framework/Info.plist +24 -0
  76. package/ios/sqlitevec.xcframework/tvos-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec +0 -0
  77. package/lib/commonjs/NativeOPSQLite.js +9 -0
  78. package/lib/commonjs/NativeOPSQLite.js.map +1 -0
  79. package/lib/commonjs/Storage.js +60 -0
  80. package/lib/commonjs/Storage.js.map +1 -0
  81. package/lib/commonjs/index.js +365 -0
  82. package/lib/commonjs/index.js.map +1 -0
  83. package/lib/module/NativeOPSQLite.js +3 -0
  84. package/lib/module/NativeOPSQLite.js.map +1 -0
  85. package/lib/module/Storage.js +53 -0
  86. package/lib/module/Storage.js.map +1 -0
  87. package/lib/module/index.js +340 -0
  88. package/lib/module/index.js.map +1 -0
  89. package/lib/typescript/src/NativeOPSQLite.d.ts +15 -0
  90. package/lib/typescript/src/NativeOPSQLite.d.ts.map +1 -0
  91. package/lib/typescript/src/Storage.d.ts +23 -0
  92. package/lib/typescript/src/Storage.d.ts.map +1 -0
  93. package/lib/typescript/src/index.d.ts +319 -0
  94. package/lib/typescript/src/index.d.ts.map +1 -0
  95. package/op-sqlite.podspec +212 -0
  96. package/package.json +85 -0
  97. package/src/NativeOPSQLite.ts +17 -0
  98. package/src/Storage.ts +85 -0
  99. package/src/index.ts +722 -0
@@ -0,0 +1,182 @@
1
+ #include "bindings.h"
2
+ #include "DBHostObject.h"
3
+ #include "DumbHostObject.h"
4
+ #include "OPThreadPool.h"
5
+ #ifdef OP_SQLITE_USE_LIBSQL
6
+ #include "libsql/bridge.h"
7
+ #else
8
+ #include "bridge.h"
9
+ #endif
10
+ #include "logs.h"
11
+ #include "macros.h"
12
+ #include "utils.h"
13
+ #include <iostream>
14
+ #include <string>
15
+ #include <unordered_map>
16
+ #include <vector>
17
+
18
+ namespace opsqlite {
19
+
20
+ namespace jsi = facebook::jsi;
21
+
22
+ std::string _base_path;
23
+ std::string _crsqlite_path;
24
+ std::string _sqlite_vec_path;
25
+ std::vector<std::shared_ptr<DBHostObject>> dbs;
26
+
27
+ // React native will try to clean the module on JS context invalidation
28
+ // (CodePush/Hot Reload) The clearState function is called
29
+ void invalidate() {
30
+ for (const auto &db : dbs) {
31
+ db->invalidate();
32
+ }
33
+
34
+ // Clear our existing vector of shared pointers so they can be garbage
35
+ // collected
36
+ dbs.clear();
37
+ }
38
+
39
+ void install(jsi::Runtime &rt,
40
+ const std::shared_ptr<react::CallInvoker> &invoker,
41
+ const char *base_path, const char *crsqlite_path,
42
+ const char *sqlite_vec_path) {
43
+ _base_path = std::string(base_path);
44
+ _crsqlite_path = std::string(crsqlite_path);
45
+ _sqlite_vec_path = std::string(sqlite_vec_path);
46
+
47
+ auto open = HOST_STATIC_FN("open") {
48
+ jsi::Object options = args[0].asObject(rt);
49
+ std::string name =
50
+ options.getProperty(rt, "name").asString(rt).utf8(rt);
51
+ std::string path = std::string(_base_path);
52
+ std::string location;
53
+ std::string encryption_key;
54
+
55
+ if (options.hasProperty(rt, "location")) {
56
+ location =
57
+ options.getProperty(rt, "location").asString(rt).utf8(rt);
58
+ }
59
+
60
+ if (options.hasProperty(rt, "encryptionKey")) {
61
+ encryption_key =
62
+ options.getProperty(rt, "encryptionKey").asString(rt).utf8(rt);
63
+ }
64
+
65
+ #ifdef OP_SQLITE_USE_SQLCIPHER
66
+ if (encryption_key.empty()) {
67
+ log_to_console(rt, "Encryption key is missing for SQLCipher");
68
+ }
69
+ #endif
70
+
71
+ if (!location.empty()) {
72
+ if (location == ":memory:") {
73
+ path = ":memory:";
74
+ } else if (location.rfind('/', 0) == 0) {
75
+ path = location;
76
+ } else {
77
+ path = path + "/" + location;
78
+ }
79
+ }
80
+
81
+ std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
82
+ rt, path, invoker, name, path, _crsqlite_path, _sqlite_vec_path,
83
+ encryption_key);
84
+ dbs.emplace_back(db);
85
+ return jsi::Object::createFromHostObject(rt, db);
86
+ });
87
+
88
+ auto is_sqlcipher = HOST_STATIC_FN("isSQLCipher") {
89
+ #ifdef OP_SQLITE_USE_SQLCIPHER
90
+ return true;
91
+ #else
92
+ return false;
93
+ #endif
94
+ });
95
+
96
+ auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
97
+ #ifdef OP_SQLITE_USE_PHONE_VERSION
98
+ return true;
99
+ #else
100
+ return false;
101
+ #endif
102
+ });
103
+
104
+ auto is_libsql = HOST_STATIC_FN("isLibsql") {
105
+ #ifdef OP_SQLITE_USE_LIBSQL
106
+ return true;
107
+ #else
108
+ return false;
109
+ #endif
110
+ });
111
+
112
+ #ifdef OP_SQLITE_USE_LIBSQL
113
+ auto open_remote = HOST_STATIC_FN("openRemote") {
114
+ jsi::Object options = args[0].asObject(rt);
115
+ std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt);
116
+ std::string auth_token =
117
+ options.getProperty(rt, "authToken").asString(rt).utf8(rt);
118
+
119
+ std::shared_ptr<DBHostObject> db =
120
+ std::make_shared<DBHostObject>(rt, url, auth_token, invoker);
121
+ return jsi::Object::createFromHostObject(rt, db);
122
+ });
123
+
124
+ auto open_sync = HOST_STATIC_FN("openSync") {
125
+ jsi::Object options = args[0].asObject(rt);
126
+ std::string name =
127
+ options.getProperty(rt, "name").asString(rt).utf8(rt);
128
+ std::string path = std::string(_base_path);
129
+ std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt);
130
+ std::string auth_token =
131
+ options.getProperty(rt, "authToken").asString(rt).utf8(rt);
132
+ int sync_interval = 0;
133
+ if (options.hasProperty(rt, "syncInterval")) {
134
+ sync_interval = static_cast<int>(
135
+ options.getProperty(rt, "syncInterval").asNumber());
136
+ }
137
+ std::string location;
138
+
139
+ if (options.hasProperty(rt, "location")) {
140
+ location =
141
+ options.getProperty(rt, "location").asString(rt).utf8(rt);
142
+ }
143
+
144
+ if (!location.empty()) {
145
+ if (location == ":memory:") {
146
+ path = ":memory:";
147
+ } else if (location.rfind("/", 0) == 0) {
148
+ path = location;
149
+ } else {
150
+ path = path + "/" + location;
151
+ }
152
+ }
153
+
154
+ std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
155
+ rt, invoker, name, path, url, auth_token, sync_interval);
156
+ return jsi::Object::createFromHostObject(rt, db);
157
+ });
158
+ #endif
159
+
160
+ jsi::Object module = jsi::Object(rt);
161
+ module.setProperty(rt, "open", std::move(open));
162
+ module.setProperty(rt, "isSQLCipher", std::move(is_sqlcipher));
163
+ module.setProperty(rt, "isLibsql", std::move(is_libsql));
164
+ module.setProperty(rt, "isIOSEmbedded", std::move(is_ios_embedded));
165
+ #ifdef OP_SQLITE_USE_LIBSQL
166
+ module.setProperty(rt, "openRemote", std::move(open_remote));
167
+ module.setProperty(rt, "openSync", std::move(open_sync));
168
+ #endif
169
+
170
+ rt.global().setProperty(rt, "__OPSQLiteProxy", std::move(module));
171
+ }
172
+
173
+ void expoUpdatesWorkaround(const char *base_path) {
174
+ #ifdef OP_SQLITE_USE_LIBSQL
175
+ std::string path = std::string(base_path);
176
+ // Open a DB before anything else so that expo-updates does not mess up the
177
+ // configuration
178
+ opsqlite_libsql_open("__dummy", path, "");
179
+ #endif
180
+ }
181
+
182
+ } // namespace opsqlite
package/cpp/bindings.h ADDED
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvoker.h>
4
+ #include <jsi/jsi.h>
5
+ #include <jsi/jsilib.h>
6
+
7
+ namespace opsqlite {
8
+
9
+ namespace jsi = facebook::jsi;
10
+ namespace react = facebook::react;
11
+
12
+ void install(jsi::Runtime &rt,
13
+ const std::shared_ptr<react::CallInvoker> &invoker,
14
+ const char *base_path, const char *crsqlite_path,
15
+ const char *sqlite_vec_path);
16
+ void invalidate();
17
+ void expoUpdatesWorkaround(const char *base_path);
18
+
19
+ } // namespace opsqlite