@op-engineering/op-sqlite 11.3.0 → 11.4.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/cpp/bindings.cpp CHANGED
@@ -170,4 +170,13 @@ void install(jsi::Runtime &rt,
170
170
  rt.global().setProperty(rt, "__OPSQLiteProxy", std::move(module));
171
171
  }
172
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
+
173
182
  } // namespace opsqlite
package/cpp/bindings.h CHANGED
@@ -14,5 +14,6 @@ void install(jsi::Runtime &rt,
14
14
  const char *base_path, const char *crsqlite_path,
15
15
  const char *sqlite_vec_path);
16
16
  void invalidate();
17
+ void expoUpdatesWorkaround(const char *base_path);
17
18
 
18
19
  } // namespace opsqlite
package/ios/OPSQLite.h CHANGED
@@ -1,16 +1,7 @@
1
- // #ifdef RCT_NEW_ARCH_ENABLED
2
- // #import <OPSQLiteSpec/OPSQLiteSpec.h>
3
- // #else
4
1
  #import <React/RCTBridge.h>
5
- // #endif
6
2
 
7
- @interface OPSQLite : NSObject
8
- // #ifdef RCT_NEW_ARCH_ENABLED
9
- // <NativeOPSQLiteSpec>
10
- // #else
11
- <RCTBridgeModule>
12
- // #endif
3
+ @interface OPSQLite : NSObject <RCTBridgeModule>
13
4
 
14
5
  @property(nonatomic, assign) BOOL setBridgeOnMainQueue;
15
-
6
+ + (void)expoUpdatesWorkaround;
16
7
  @end
package/ios/OPSQLite.mm CHANGED
@@ -13,143 +13,145 @@
13
13
  RCT_EXPORT_MODULE()
14
14
 
15
15
  + (BOOL)requiresMainQueueSetup {
16
- return YES;
16
+ return YES;
17
17
  }
18
18
 
19
19
  - (NSDictionary *)constantsToExport {
20
- NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(
21
- NSLibraryDirectory, NSUserDomainMask, true);
22
- NSString *libraryPath = [libraryPaths objectAtIndex:0];
23
-
24
- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(
25
- NSDocumentDirectory, NSUserDomainMask, true);
26
- NSString *documentPath = [documentPaths objectAtIndex:0];
27
- return
28
- @{@"IOS_DOCUMENT_PATH" : documentPath, @"IOS_LIBRARY_PATH" : libraryPath};
20
+ NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(
21
+ NSLibraryDirectory, NSUserDomainMask, true);
22
+ NSString *libraryPath = [libraryPaths objectAtIndex:0];
23
+
24
+ NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(
25
+ NSDocumentDirectory, NSUserDomainMask, true);
26
+ NSString *documentPath = [documentPaths objectAtIndex:0];
27
+ return @{
28
+ @"IOS_DOCUMENT_PATH" : documentPath,
29
+ @"IOS_LIBRARY_PATH" : libraryPath
30
+ };
29
31
  }
30
32
 
31
33
  - (NSDictionary *)getConstants {
32
- return [self constantsToExport];
34
+ return [self constantsToExport];
33
35
  }
34
36
 
35
37
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
36
- RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;
37
- if (cxxBridge == nil) {
38
- return @false;
39
- }
40
-
41
- auto jsiRuntime = (facebook::jsi::Runtime *)cxxBridge.runtime;
42
- if (jsiRuntime == nil) {
43
- return @false;
44
- }
45
-
46
- auto &runtime = *jsiRuntime;
47
- auto callInvoker = _bridge.jsCallInvoker;
48
-
49
- // Get appGroupID value from Info.plist using key "AppGroup"
50
- NSString *appGroupID =
51
- [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OPSQLite_AppGroup"];
52
- NSString *documentPath;
53
-
54
- if (appGroupID != nil) {
55
- // Get the app groups container storage url
56
- NSFileManager *fileManager = [NSFileManager defaultManager];
57
- NSURL *storeUrl = [fileManager
58
- containerURLForSecurityApplicationGroupIdentifier:appGroupID];
59
-
60
- if (storeUrl == nil) {
61
- NSLog(@"OP-SQLite: Invalid AppGroup ID provided (%@). Check the value of "
62
- @"\"AppGroup\" in your Info.plist file",
63
- appGroupID);
64
- return @false;
38
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;
39
+ if (cxxBridge == nil) {
40
+ return @false;
65
41
  }
66
42
 
67
- documentPath = [storeUrl path];
68
- } else {
69
- NSArray *paths = NSSearchPathForDirectoriesInDomains(
70
- NSLibraryDirectory, NSUserDomainMask, true);
71
- documentPath = [paths objectAtIndex:0];
72
- }
73
-
74
- NSBundle *crsqlite_bundle =
75
- [NSBundle bundleWithIdentifier:@"io.vlcn.crsqlite"];
76
- NSString *crsqlite_path = [crsqlite_bundle pathForResource:@"crsqlite"
77
- ofType:@""];
78
- NSBundle *libsqlitevec_bundle =
79
- [NSBundle bundleWithIdentifier:@"com.ospfranco.sqlitevec"];
80
- NSString *sqlite_vec_path = [libsqlitevec_bundle pathForResource:@"sqlitevec"
81
- ofType:@""];
82
-
83
- if (crsqlite_path == nil) {
84
- crsqlite_path = @"";
85
- }
86
-
87
- if (sqlite_vec_path == nil) {
88
- sqlite_vec_path = @"";
89
- }
90
-
91
- opsqlite::install(runtime, callInvoker, [documentPath UTF8String],
92
- [crsqlite_path UTF8String], [sqlite_vec_path UTF8String]);
93
- return @true;
43
+ auto jsiRuntime = (facebook::jsi::Runtime *)cxxBridge.runtime;
44
+ if (jsiRuntime == nil) {
45
+ return @false;
46
+ }
47
+
48
+ auto &runtime = *jsiRuntime;
49
+ auto callInvoker = _bridge.jsCallInvoker;
50
+
51
+ // Get appGroupID value from Info.plist using key "AppGroup"
52
+ NSString *appGroupID =
53
+ [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OPSQLite_AppGroup"];
54
+ NSString *documentPath;
55
+
56
+ if (appGroupID != nil) {
57
+ // Get the app groups container storage url
58
+ NSFileManager *fileManager = [NSFileManager defaultManager];
59
+ NSURL *storeUrl = [fileManager
60
+ containerURLForSecurityApplicationGroupIdentifier:appGroupID];
61
+
62
+ if (storeUrl == nil) {
63
+ NSLog(@"OP-SQLite: Invalid AppGroup ID provided (%@). Check the "
64
+ @"value of "
65
+ @"\"AppGroup\" in your Info.plist file",
66
+ appGroupID);
67
+ return @false;
68
+ }
69
+
70
+ documentPath = [storeUrl path];
71
+ } else {
72
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(
73
+ NSLibraryDirectory, NSUserDomainMask, true);
74
+ documentPath = [paths objectAtIndex:0];
75
+ }
76
+
77
+ NSBundle *crsqlite_bundle =
78
+ [NSBundle bundleWithIdentifier:@"io.vlcn.crsqlite"];
79
+ NSString *crsqlite_path = [crsqlite_bundle pathForResource:@"crsqlite"
80
+ ofType:@""];
81
+ NSBundle *libsqlitevec_bundle =
82
+ [NSBundle bundleWithIdentifier:@"com.ospfranco.sqlitevec"];
83
+ NSString *sqlite_vec_path =
84
+ [libsqlitevec_bundle pathForResource:@"sqlitevec" ofType:@""];
85
+
86
+ if (crsqlite_path == nil) {
87
+ crsqlite_path = @"";
88
+ }
89
+
90
+ if (sqlite_vec_path == nil) {
91
+ sqlite_vec_path = @"";
92
+ }
93
+
94
+ opsqlite::install(runtime, callInvoker, [documentPath UTF8String],
95
+ [crsqlite_path UTF8String], [sqlite_vec_path UTF8String]);
96
+ return @true;
94
97
  }
95
98
 
96
99
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getDylibPath : (
97
100
  NSString *)bundleId andResource : (NSString *)resourceName) {
98
- NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleId];
99
- NSString *path = [bundle pathForResource:resourceName ofType:@""];
100
- return path;
101
+ NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleId];
102
+ NSString *path = [bundle pathForResource:resourceName ofType:@""];
103
+ return path;
101
104
  }
102
105
 
103
106
  RCT_EXPORT_METHOD(moveAssetsDatabase : (NSDictionary *)args resolve : (
104
107
  RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject) {
105
- NSString *documentPath = [NSSearchPathForDirectoriesInDomains(
106
- NSLibraryDirectory, NSUserDomainMask, true) objectAtIndex:0];
108
+ NSString *documentPath = [NSSearchPathForDirectoriesInDomains(
109
+ NSLibraryDirectory, NSUserDomainMask, true) objectAtIndex:0];
110
+
111
+ NSString *filename = args[@"filename"];
112
+ BOOL overwrite = args[@"overwrite"];
107
113
 
108
- NSString *filename = args[@"filename"];
109
- BOOL overwrite = args[@"overwrite"];
114
+ NSString *sourcePath = [[NSBundle mainBundle] pathForResource:filename
115
+ ofType:nil];
110
116
 
111
- NSString *sourcePath = [[NSBundle mainBundle] pathForResource:filename
112
- ofType:nil];
117
+ NSString *destinationPath =
118
+ [documentPath stringByAppendingPathComponent:filename];
113
119
 
114
- NSString *destinationPath =
115
- [documentPath stringByAppendingPathComponent:filename];
120
+ NSError *error;
121
+ NSFileManager *fileManager = [NSFileManager defaultManager];
122
+ if ([fileManager fileExistsAtPath:destinationPath]) {
123
+ if (overwrite) {
124
+ [fileManager removeItemAtPath:destinationPath error:&error];
125
+ if (error) {
126
+ NSLog(@"Error: %@", error);
127
+ resolve(@false);
128
+ return;
129
+ }
130
+ } else {
131
+ resolve(@true);
132
+ return;
133
+ }
134
+ }
116
135
 
117
- NSError *error;
118
- NSFileManager *fileManager = [NSFileManager defaultManager];
119
- if ([fileManager fileExistsAtPath:destinationPath]) {
120
- if (overwrite) {
121
- [fileManager removeItemAtPath:destinationPath error:&error];
122
- if (error) {
136
+ [fileManager copyItemAtPath:sourcePath toPath:destinationPath error:&error];
137
+ if (error) {
123
138
  NSLog(@"Error: %@", error);
124
139
  resolve(@false);
125
140
  return;
126
- }
127
- } else {
128
- resolve(@true);
129
- return;
130
141
  }
131
- }
132
-
133
- [fileManager copyItemAtPath:sourcePath toPath:destinationPath error:&error];
134
- if (error) {
135
- NSLog(@"Error: %@", error);
136
- resolve(@false);
142
+ resolve(@true);
137
143
  return;
138
- }
139
- resolve(@true);
140
- return;
141
144
  }
142
145
 
143
- // #if RCT_NEW_ARCH_ENABLED
144
- // - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
145
- // (const facebook::react::ObjCTurboModule::InitParams &)params
146
- // {
147
- // return std::make_shared<facebook::react::NativeOPSQLiteSpecJSI>(params);
148
- // }
149
- // #endif
150
-
151
146
  - (void)invalidate {
152
- opsqlite::invalidate();
147
+ opsqlite::invalidate();
148
+ }
149
+
150
+ + (void)expoUpdatesWorkaround {
151
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(
152
+ NSLibraryDirectory, NSUserDomainMask, true);
153
+ NSString *documentPath = [paths objectAtIndex:0];
154
+ opsqlite::expoUpdatesWorkaround([documentPath UTF8String]);
153
155
  }
154
156
 
155
157
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "11.3.0",
3
+ "version": "11.4.0",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",