@unvired/react-native-unvired-sdk 0.0.14 → 0.0.16

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/BuildNo.txt CHANGED
@@ -1 +1 @@
1
- R-0.000.0014
1
+ R-0.000.0016
@@ -1,7 +1,7 @@
1
1
  import { IDatabaseAdapter } from './types';
2
2
  /**
3
3
  * DatabaseManager - Manages database operations across platforms
4
- * - iOS/Android/Windows: Uses react-native-sqlite-storage
4
+ * - iOS/Android/Windows: Uses @op-engineering/op-sqlite
5
5
  * - Web: Uses WebSQL
6
6
  */
7
7
  export declare class DatabaseManager {
@@ -5,7 +5,7 @@ import { DatabaseWeb } from './services/DatabaseWeb';
5
5
  const dbImpl = Platform.OS === 'web' ? new DatabaseWeb() : new DatabaseNative();
6
6
  /**
7
7
  * DatabaseManager - Manages database operations across platforms
8
- * - iOS/Android/Windows: Uses react-native-sqlite-storage
8
+ * - iOS/Android/Windows: Uses @op-engineering/op-sqlite
9
9
  * - Web: Uses WebSQL
10
10
  */
11
11
  export class DatabaseManager {
@@ -3,6 +3,5 @@ export declare class DatabaseNative {
3
3
  private databases;
4
4
  private defaultLocation;
5
5
  private getDatabase;
6
- private resultSetToArray;
7
6
  getAdapter(): IDatabaseAdapter;
8
7
  }
@@ -1,33 +1,27 @@
1
- import SQLite from "react-native-sqlite-storage";
2
- SQLite.enablePromise(true);
3
- SQLite.DEBUG(false);
1
+ import { open } from '@op-engineering/op-sqlite';
4
2
  export class DatabaseNative {
5
3
  constructor() {
6
4
  this.databases = new Map();
7
5
  this.defaultLocation = "default";
8
6
  }
9
- async getDatabase(name, location) {
7
+ getDatabase(name, location) {
10
8
  const dbKey = `${name}_${location || this.defaultLocation}`;
11
9
  if (this.databases.has(dbKey)) {
12
10
  return this.databases.get(dbKey);
13
11
  }
14
- const dbLocation = (location || this.defaultLocation);
15
- const db = await SQLite.openDatabase({ name, location: dbLocation });
12
+ // @op-engineering/op-sqlite open function
13
+ // We treat location as mainly advisory since op-sqlite defaults to valid paths.
14
+ // If strict paths are needed, we would need to construct absolute path using FS.
15
+ // For now, we rely on the name.
16
+ const db = open({ name });
16
17
  this.databases.set(dbKey, db);
17
18
  return db;
18
19
  }
19
- resultSetToArray(resultSet) {
20
- const results = [];
21
- for (let i = 0; i < resultSet.rows.length; i++) {
22
- results.push(resultSet.rows.item(i));
23
- }
24
- return results;
25
- }
26
20
  getAdapter() {
27
21
  return {
28
22
  create: async (options, successCallback, errorCallback) => {
29
23
  try {
30
- await this.getDatabase(options.name, options.location);
24
+ this.getDatabase(options.name, options.location);
31
25
  successCallback({ success: true, database: options.name });
32
26
  }
33
27
  catch (error) {
@@ -35,61 +29,43 @@ export class DatabaseNative {
35
29
  }
36
30
  },
37
31
  execute: async (options, successCallback, errorCallback) => {
32
+ var _a;
38
33
  try {
39
- const db = await this.getDatabase(options.dbName);
40
- const results = await new Promise((resolve, reject) => {
41
- db.transaction((tx) => {
42
- tx.executeSql(options.query, options.params || [], (_, resultSet) => {
43
- resolve(this.resultSetToArray(resultSet));
44
- }, (_, error) => {
45
- reject(error);
46
- return false;
47
- });
48
- });
49
- });
50
- successCallback(results);
34
+ const db = this.getDatabase(options.dbName);
35
+ const res = db.execute(options.query, options.params);
36
+ // op-sqlite v15+ returns rows as an array natively in most configurations
37
+ // Check for _array for backward compatibility with some bridges or older habits
38
+ // @ts-ignore
39
+ const rows = ((_a = res.rows) === null || _a === void 0 ? void 0 : _a._array) || res.rows || [];
40
+ successCallback(rows);
51
41
  }
52
42
  catch (error) {
53
43
  errorCallback(error instanceof Error ? error.message : String(error));
54
44
  }
55
45
  },
56
46
  executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
57
- var _a;
47
+ var _a, _b;
58
48
  try {
59
49
  const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
60
- const db = await this.getDatabase(dbName);
61
- const results = await new Promise((resolve) => {
62
- db.transaction((tx) => {
63
- tx.executeSql(sqlQuery, [], (_, resultSet) => {
64
- resolve(this.resultSetToArray(resultSet));
65
- }, () => {
66
- resolve([]);
67
- return false;
68
- });
69
- });
70
- });
71
- callback(results);
50
+ const db = this.getDatabase(dbName);
51
+ const res = db.execute(sqlQuery);
52
+ // @ts-ignore
53
+ const rows = ((_b = res.rows) === null || _b === void 0 ? void 0 : _b._array) || res.rows || [];
54
+ callback(rows);
72
55
  }
73
56
  catch (error) {
74
57
  callback([]);
75
58
  }
76
59
  },
77
60
  selectFromPath: async (dbPath, sqlQuery, callback) => {
78
- var _a;
61
+ var _a, _b;
79
62
  try {
80
63
  const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
81
- const db = await this.getDatabase(dbName);
82
- const results = await new Promise((resolve) => {
83
- db.readTransaction((tx) => {
84
- tx.executeSql(sqlQuery, [], (_, resultSet) => {
85
- resolve(this.resultSetToArray(resultSet));
86
- }, () => {
87
- resolve([]);
88
- return false;
89
- });
90
- });
91
- });
92
- callback(results);
64
+ const db = this.getDatabase(dbName);
65
+ const res = db.execute(sqlQuery);
66
+ // @ts-ignore
67
+ const rows = ((_b = res.rows) === null || _b === void 0 ? void 0 : _b._array) || res.rows || [];
68
+ callback(rows);
93
69
  }
94
70
  catch (error) {
95
71
  callback([]);
@@ -99,7 +75,7 @@ export class DatabaseNative {
99
75
  var _a;
100
76
  try {
101
77
  const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
102
- await this.getDatabase(dbName);
78
+ this.getDatabase(dbName);
103
79
  callback();
104
80
  }
105
81
  catch (error) {
@@ -125,19 +101,12 @@ export class DatabaseNative {
125
101
  },
126
102
  deleteUserData: async (options, callback, errorCallback) => {
127
103
  try {
128
- const db = await this.getDatabase(options.dbName);
129
- await new Promise((resolve, reject) => {
130
- db.transaction((tx) => {
131
- const query = options.userId
132
- ? "DELETE FROM user_data WHERE user_id = ?"
133
- : "DELETE FROM user_data";
134
- const params = options.userId ? [options.userId] : [];
135
- tx.executeSql(query, params, () => resolve(), (_, error) => {
136
- reject(error);
137
- return false;
138
- });
139
- });
140
- });
104
+ const db = this.getDatabase(options.dbName);
105
+ const query = options.userId
106
+ ? "DELETE FROM user_data WHERE user_id = ?"
107
+ : "DELETE FROM user_data";
108
+ const params = options.userId ? [options.userId] : [];
109
+ db.execute(query, params);
141
110
  callback();
142
111
  }
143
112
  catch (error) {
@@ -1,9 +1,63 @@
1
- import { BaseFileSystem } from './BaseFileSystem';
1
+ import { IFileEntry, FileSystemEncoding } from './FileSystem.types';
2
2
  /**
3
3
  * FileSystem class
4
- * Extends BaseFileSystem
4
+ * Handles file system operations for React Native
5
+ * - iOS/Android/Windows: Uses react-native-fs
6
+ * - Web: Limited functionality (not supported)
5
7
  */
6
- export declare class FileSystem extends BaseFileSystem {
8
+ export declare class FileSystem {
9
+ /**
10
+ * Get document directory path
11
+ */
12
+ static getDocumentDirectory(): string;
13
+ /**
14
+ * Resolve local file system URL
15
+ */
16
+ static resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
17
+ /**
18
+ * Get folder based on user ID
19
+ */
20
+ static getFolderBasedOnUserId(userId: string): Promise<string>;
21
+ /**
22
+ * Delete user folder
23
+ */
24
+ static deleteUserFolder(userId: string): Promise<void>;
25
+ /**
26
+ * Create directory
27
+ */
28
+ static createDirectory(path: string): Promise<void>;
29
+ /**
30
+ * Read file content
31
+ */
32
+ static readFile(path: string, encoding?: FileSystemEncoding): Promise<string>;
33
+ /**
34
+ * Write file content
35
+ */
36
+ static writeFile(path: string, content: string, encoding?: FileSystemEncoding): Promise<void>;
37
+ /**
38
+ * Delete file
39
+ */
40
+ static deleteFile(path: string): Promise<void>;
41
+ /**
42
+ * Check if file exists
43
+ */
44
+ static exists(path: string): Promise<boolean>;
45
+ /**
46
+ * Get file info
47
+ */
48
+ static stat(path: string): Promise<any>;
49
+ /**
50
+ * List directory contents
51
+ */
52
+ static readDir(path: string): Promise<any[]>;
53
+ /**
54
+ * Copy file
55
+ */
56
+ static copyFile(source: string, destination: string): Promise<void>;
57
+ /**
58
+ * Move file
59
+ */
60
+ static moveFile(source: string, destination: string): Promise<void>;
7
61
  }
8
62
  export type { IFileEntry } from './FileSystem.types';
9
63
  export default FileSystem;
@@ -1,11 +1,164 @@
1
- // FileSystem.ts
2
- // Main file system export
3
- import { BaseFileSystem } from './BaseFileSystem';
1
+ import { Platform } from 'react-native';
2
+ import { FileSystemNative } from './services/FileSystemNative';
3
+ import { FileSystemWeb } from './services/FileSystemWeb';
4
+ // Select file system implementation based on platform
5
+ const fsImpl = Platform.OS === 'web' ? new FileSystemWeb() : new FileSystemNative();
4
6
  /**
5
7
  * FileSystem class
6
- * Extends BaseFileSystem
8
+ * Handles file system operations for React Native
9
+ * - iOS/Android/Windows: Uses react-native-fs
10
+ * - Web: Limited functionality (not supported)
7
11
  */
8
- export class FileSystem extends BaseFileSystem {
12
+ export class FileSystem {
13
+ /**
14
+ * Get document directory path
15
+ */
16
+ static getDocumentDirectory() {
17
+ return fsImpl.getDocumentDirectory();
18
+ }
19
+ /**
20
+ * Resolve local file system URL
21
+ */
22
+ static async resolveLocalFileSystemURL(url) {
23
+ try {
24
+ return await fsImpl.resolveLocalFileSystemURL(url);
25
+ }
26
+ catch (error) {
27
+ console.error('Error resolving file system URL:', error);
28
+ throw error;
29
+ }
30
+ }
31
+ /**
32
+ * Get folder based on user ID
33
+ */
34
+ static async getFolderBasedOnUserId(userId) {
35
+ try {
36
+ return await fsImpl.getFolderBasedOnUserId(userId);
37
+ }
38
+ catch (error) {
39
+ console.error('Error getting user folder:', error);
40
+ throw error;
41
+ }
42
+ }
43
+ /**
44
+ * Delete user folder
45
+ */
46
+ static async deleteUserFolder(userId) {
47
+ try {
48
+ await fsImpl.deleteUserFolder(userId);
49
+ }
50
+ catch (error) {
51
+ console.error('Error deleting user folder:', error);
52
+ throw error;
53
+ }
54
+ }
55
+ /**
56
+ * Create directory
57
+ */
58
+ static async createDirectory(path) {
59
+ try {
60
+ await fsImpl.createDirectory(path);
61
+ }
62
+ catch (error) {
63
+ console.error('Error creating directory:', error);
64
+ throw error;
65
+ }
66
+ }
67
+ /**
68
+ * Read file content
69
+ */
70
+ static async readFile(path, encoding = 'utf8') {
71
+ try {
72
+ return await fsImpl.readFile(path, encoding);
73
+ }
74
+ catch (error) {
75
+ console.error('Error reading file:', error);
76
+ throw error;
77
+ }
78
+ }
79
+ /**
80
+ * Write file content
81
+ */
82
+ static async writeFile(path, content, encoding = 'utf8') {
83
+ try {
84
+ await fsImpl.writeFile(path, content, encoding);
85
+ }
86
+ catch (error) {
87
+ console.error('Error writing file:', error);
88
+ throw error;
89
+ }
90
+ }
91
+ /**
92
+ * Delete file
93
+ */
94
+ static async deleteFile(path) {
95
+ try {
96
+ await fsImpl.deleteFile(path);
97
+ }
98
+ catch (error) {
99
+ console.error('Error deleting file:', error);
100
+ throw error;
101
+ }
102
+ }
103
+ /**
104
+ * Check if file exists
105
+ */
106
+ static async exists(path) {
107
+ try {
108
+ return await fsImpl.exists(path);
109
+ }
110
+ catch (error) {
111
+ return false;
112
+ }
113
+ }
114
+ /**
115
+ * Get file info
116
+ */
117
+ static async stat(path) {
118
+ try {
119
+ return await fsImpl.stat(path);
120
+ }
121
+ catch (error) {
122
+ console.error('Error getting file stats:', error);
123
+ throw error;
124
+ }
125
+ }
126
+ /**
127
+ * List directory contents
128
+ */
129
+ static async readDir(path) {
130
+ try {
131
+ return await fsImpl.readDir(path);
132
+ }
133
+ catch (error) {
134
+ console.error('Error reading directory:', error);
135
+ throw error;
136
+ }
137
+ }
138
+ /**
139
+ * Copy file
140
+ */
141
+ static async copyFile(source, destination) {
142
+ try {
143
+ await fsImpl.copyFile(source, destination);
144
+ }
145
+ catch (error) {
146
+ console.error('Error copying file:', error);
147
+ throw error;
148
+ }
149
+ }
150
+ /**
151
+ * Move file
152
+ */
153
+ static async moveFile(source, destination) {
154
+ try {
155
+ await fsImpl.moveFile(source, destination);
156
+ }
157
+ catch (error) {
158
+ console.error('Error moving file:', error);
159
+ throw error;
160
+ }
161
+ }
9
162
  }
10
163
  // Default export
11
164
  export default FileSystem;
@@ -1,11 +1,41 @@
1
1
  /**
2
2
  * File entry interface
3
3
  */
4
+ export interface IDirectoryReader {
5
+ readEntries(successCallback: (entries: IFileEntry[]) => void, errorCallback: (error: any) => void): void;
6
+ }
4
7
  export interface IFileEntry {
5
8
  isFile: boolean;
6
9
  isDirectory: boolean;
7
10
  name: string;
8
11
  fullPath: string;
9
12
  filesystem?: any;
10
- nativeURL?: string;
13
+ nativeURL: string;
14
+ remove(callback: () => void, errorCallback: (error: any) => void): void;
15
+ removeRecursively(callback: () => void, errorCallback: (error: any) => void): void;
16
+ createReader(): IDirectoryReader;
17
+ getDirectory?(path: string, options: {
18
+ create: boolean;
19
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
20
+ getFile?(path: string, options: {
21
+ create: boolean;
22
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
23
+ file?(callback: (file: any) => void, errorCallback: (error: any) => void): void;
24
+ createWriter?(callback: (writer: any) => void, errorCallback: (error: any) => void): void;
25
+ }
26
+ export type FileSystemEncoding = 'utf8' | 'ascii' | 'base64';
27
+ export interface IFileSystem {
28
+ getDocumentDirectory(): string;
29
+ resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
30
+ getFolderBasedOnUserId(userId: string): Promise<string>;
31
+ deleteUserFolder(userId: string): Promise<void>;
32
+ createDirectory(path: string): Promise<void>;
33
+ readFile(path: string, encoding?: FileSystemEncoding): Promise<string>;
34
+ writeFile(path: string, content: string, encoding?: FileSystemEncoding): Promise<void>;
35
+ deleteFile(path: string): Promise<void>;
36
+ exists(path: string): Promise<boolean>;
37
+ stat(path: string): Promise<any>;
38
+ readDir(path: string): Promise<any[]>;
39
+ copyFile(source: string, destination: string): Promise<void>;
40
+ moveFile(source: string, destination: string): Promise<void>;
11
41
  }
@@ -0,0 +1,55 @@
1
+ import { IFileEntry, IDirectoryReader } from './FileSystem.types';
2
+ /**
3
+ * DirectoryReader implementation for React Native
4
+ * Wraps RNFS.readDir to match the Cordova DirectoryReader interface
5
+ */
6
+ export declare class RNDirectoryReader implements IDirectoryReader {
7
+ private dirPath;
8
+ constructor(dirPath: string);
9
+ readEntries(callback: (entries: IFileEntry[]) => void, errorCallback: (error: any) => void): void;
10
+ }
11
+ /**
12
+ * FileEntry implementation for React Native
13
+ * Wraps react-native-fs to match the Cordova FileEntry interface
14
+ */
15
+ export declare class RNFileEntry implements IFileEntry {
16
+ isFile: boolean;
17
+ isDirectory: boolean;
18
+ name: string;
19
+ fullPath: string;
20
+ nativeURL: string;
21
+ filesystem: any;
22
+ constructor(path: string, isDirectory?: boolean);
23
+ /**
24
+ * Remove a file or empty directory
25
+ */
26
+ remove(callback: () => void, errorCallback: (error: any) => void): void;
27
+ /**
28
+ * Remove a directory and all its contents recursively
29
+ */
30
+ removeRecursively(callback: () => void, errorCallback: (error: any) => void): void;
31
+ /**
32
+ * Create a directory reader for reading directory contents
33
+ */
34
+ createReader(): IDirectoryReader;
35
+ /**
36
+ * Get or create a subdirectory
37
+ */
38
+ getDirectory(path: string, options: {
39
+ create: boolean;
40
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
41
+ /**
42
+ * Get or create a file
43
+ */
44
+ getFile(path: string, options: {
45
+ create: boolean;
46
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
47
+ /**
48
+ * Get file metadata
49
+ */
50
+ file(callback: (file: any) => void, errorCallback: (error: any) => void): void;
51
+ /**
52
+ * Create a file writer for writing to the file
53
+ */
54
+ createWriter(callback: (writer: any) => void, errorCallback: (error: any) => void): void;
55
+ }