@unvired/react-native-unvired-sdk 0.0.21 → 0.0.23
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 +1 -1
- package/dist/database/Database.d.ts +2 -53
- package/dist/database/Database.js +6 -128
- package/dist/database/DatabaseManager.d.ts +1 -1
- package/dist/database/DatabaseManager.js +2 -4
- package/dist/database/services/DatabaseNative.js +83 -22
- package/package.json +16 -18
- package/ts-core/ReactNativePlatformAdapter.ts +39 -68
- package/dist/database/services/DatabaseWeb.d.ts +0 -13
- package/dist/database/services/DatabaseWeb.js +0 -138
package/BuildNo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
R-0.000.
|
|
1
|
+
R-0.000.0023
|
|
@@ -10,60 +10,9 @@ export declare class Database {
|
|
|
10
10
|
*/
|
|
11
11
|
executeSql(query: string, params?: any[]): Promise<any[]>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Delete a database
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Drop a table
|
|
18
|
-
*/
|
|
19
|
-
dropTable(tableName: string): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Insert a record
|
|
22
|
-
*/
|
|
23
|
-
insert(tableName: string, data: Record<string, any>): Promise<number>;
|
|
24
|
-
/**
|
|
25
|
-
* Insert multiple records in a transaction
|
|
26
|
-
*/
|
|
27
|
-
insertBatch(tableName: string, records: Record<string, any>[]): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Update records
|
|
30
|
-
*/
|
|
31
|
-
update(tableName: string, data: Record<string, any>, where: string, whereParams?: any[]): Promise<number>;
|
|
32
|
-
/**
|
|
33
|
-
* Delete records
|
|
34
|
-
*/
|
|
35
|
-
delete(tableName: string, where: string, whereParams?: any[]): Promise<number>;
|
|
36
|
-
/**
|
|
37
|
-
* Select records
|
|
38
|
-
*/
|
|
39
|
-
select(tableName: string, columns?: string[], where?: string, whereParams?: any[], orderBy?: string, limit?: number): Promise<any[]>;
|
|
40
|
-
/**
|
|
41
|
-
* Select a single record
|
|
42
|
-
*/
|
|
43
|
-
selectOne(tableName: string, columns?: string[], where?: string, whereParams?: any[]): Promise<any | null>;
|
|
44
|
-
/**
|
|
45
|
-
* Count records
|
|
46
|
-
*/
|
|
47
|
-
count(tableName: string, where?: string, whereParams?: any[]): Promise<number>;
|
|
48
|
-
/**
|
|
49
|
-
* Check if a table exists
|
|
50
|
-
*/
|
|
51
|
-
tableExists(tableName: string): Promise<boolean>;
|
|
52
|
-
/**
|
|
53
|
-
* Get all table names
|
|
54
|
-
*/
|
|
55
|
-
getAllTables(): Promise<string[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Clear all data from a table
|
|
58
|
-
*/
|
|
59
|
-
truncate(tableName: string): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Execute multiple SQL statements in a transaction
|
|
62
|
-
*/
|
|
63
|
-
transaction(queries: Array<{
|
|
64
|
-
query: string;
|
|
65
|
-
params?: any[];
|
|
66
|
-
}>): Promise<void>;
|
|
15
|
+
deleteDB(): Promise<void>;
|
|
67
16
|
}
|
|
68
17
|
/**
|
|
69
18
|
* Create a new database instance
|
|
@@ -17,135 +17,13 @@ export class Database {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Delete a database
|
|
21
21
|
*/
|
|
22
|
-
async
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
await this.executeSql(query);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Drop a table
|
|
31
|
-
*/
|
|
32
|
-
async dropTable(tableName) {
|
|
33
|
-
const query = `DROP TABLE IF EXISTS ${tableName}`;
|
|
34
|
-
await this.executeSql(query);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Insert a record
|
|
38
|
-
*/
|
|
39
|
-
async insert(tableName, data) {
|
|
40
|
-
var _a;
|
|
41
|
-
const columns = Object.keys(data).join(', ');
|
|
42
|
-
const placeholders = Object.keys(data).map(() => '?').join(', ');
|
|
43
|
-
const values = Object.values(data);
|
|
44
|
-
const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`;
|
|
45
|
-
const result = await this.executeSql(query, values);
|
|
46
|
-
// Return the insert ID if available
|
|
47
|
-
return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.insertId) || 0;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Insert multiple records in a transaction
|
|
51
|
-
*/
|
|
52
|
-
async insertBatch(tableName, records) {
|
|
53
|
-
if (records.length === 0)
|
|
54
|
-
return;
|
|
55
|
-
const columns = Object.keys(records[0]).join(', ');
|
|
56
|
-
const placeholders = Object.keys(records[0]).map(() => '?').join(', ');
|
|
57
|
-
const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`;
|
|
58
|
-
for (const record of records) {
|
|
59
|
-
const values = Object.values(record);
|
|
60
|
-
await this.executeSql(query, values);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Update records
|
|
65
|
-
*/
|
|
66
|
-
async update(tableName, data, where, whereParams = []) {
|
|
67
|
-
var _a;
|
|
68
|
-
const setClause = Object.keys(data)
|
|
69
|
-
.map(key => `${key} = ?`)
|
|
70
|
-
.join(', ');
|
|
71
|
-
const values = [...Object.values(data), ...whereParams];
|
|
72
|
-
const query = `UPDATE ${tableName} SET ${setClause} WHERE ${where}`;
|
|
73
|
-
const result = await this.executeSql(query, values);
|
|
74
|
-
return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.rowsAffected) || 0;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Delete records
|
|
78
|
-
*/
|
|
79
|
-
async delete(tableName, where, whereParams = []) {
|
|
80
|
-
var _a;
|
|
81
|
-
const query = `DELETE FROM ${tableName} WHERE ${where}`;
|
|
82
|
-
const result = await this.executeSql(query, whereParams);
|
|
83
|
-
return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.rowsAffected) || 0;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Select records
|
|
87
|
-
*/
|
|
88
|
-
async select(tableName, columns = ['*'], where, whereParams = [], orderBy, limit) {
|
|
89
|
-
let query = `SELECT ${columns.join(', ')} FROM ${tableName}`;
|
|
90
|
-
if (where) {
|
|
91
|
-
query += ` WHERE ${where}`;
|
|
92
|
-
}
|
|
93
|
-
if (orderBy) {
|
|
94
|
-
query += ` ORDER BY ${orderBy}`;
|
|
95
|
-
}
|
|
96
|
-
if (limit) {
|
|
97
|
-
query += ` LIMIT ${limit}`;
|
|
98
|
-
}
|
|
99
|
-
return this.executeSql(query, whereParams);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Select a single record
|
|
103
|
-
*/
|
|
104
|
-
async selectOne(tableName, columns = ['*'], where, whereParams = []) {
|
|
105
|
-
const results = await this.select(tableName, columns, where, whereParams, undefined, 1);
|
|
106
|
-
return results.length > 0 ? results[0] : null;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Count records
|
|
110
|
-
*/
|
|
111
|
-
async count(tableName, where, whereParams = []) {
|
|
112
|
-
var _a;
|
|
113
|
-
let query = `SELECT COUNT(*) as count FROM ${tableName}`;
|
|
114
|
-
if (where) {
|
|
115
|
-
query += ` WHERE ${where}`;
|
|
116
|
-
}
|
|
117
|
-
const result = await this.executeSql(query, whereParams);
|
|
118
|
-
return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) || 0;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Check if a table exists
|
|
122
|
-
*/
|
|
123
|
-
async tableExists(tableName) {
|
|
124
|
-
const query = `SELECT name FROM sqlite_master WHERE type='table' AND name=?`;
|
|
125
|
-
const result = await this.executeSql(query, [tableName]);
|
|
126
|
-
return result.length > 0;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get all table names
|
|
130
|
-
*/
|
|
131
|
-
async getAllTables() {
|
|
132
|
-
const query = `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`;
|
|
133
|
-
const result = await this.executeSql(query);
|
|
134
|
-
return result.map(row => row.name);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Clear all data from a table
|
|
138
|
-
*/
|
|
139
|
-
async truncate(tableName) {
|
|
140
|
-
await this.executeSql(`DELETE FROM ${tableName}`);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Execute multiple SQL statements in a transaction
|
|
144
|
-
*/
|
|
145
|
-
async transaction(queries) {
|
|
146
|
-
for (const { query, params } of queries) {
|
|
147
|
-
await this.executeSql(query, params || []);
|
|
148
|
-
}
|
|
22
|
+
async deleteDB() {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const adapter = DatabaseManager.getDatabaseAdapter();
|
|
25
|
+
adapter.deleteUserData({ dbName: this.dbName }, () => resolve(), (error) => reject(new Error(String(error))));
|
|
26
|
+
});
|
|
149
27
|
}
|
|
150
28
|
}
|
|
151
29
|
/**
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DatabaseNative } from './services/DatabaseNative';
|
|
3
|
-
import { DatabaseWeb } from './services/DatabaseWeb';
|
|
1
|
+
import { DatabaseNative } from "./services/DatabaseNative";
|
|
4
2
|
// Select database implementation based on platform
|
|
5
|
-
const dbImpl =
|
|
3
|
+
const dbImpl = new DatabaseNative();
|
|
6
4
|
/**
|
|
7
5
|
* DatabaseManager - Manages database operations across platforms
|
|
8
6
|
* - iOS/Android/Windows: Uses @op-engineering/op-sqlite
|
|
@@ -9,10 +9,9 @@ export class DatabaseNative {
|
|
|
9
9
|
if (this.databases.has(dbKey)) {
|
|
10
10
|
return this.databases.get(dbKey);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// For now, we rely on the name.
|
|
12
|
+
if (!name) {
|
|
13
|
+
throw new Error("Database name is required");
|
|
14
|
+
}
|
|
16
15
|
const db = open({ name });
|
|
17
16
|
this.databases.set(dbKey, db);
|
|
18
17
|
return db;
|
|
@@ -29,43 +28,105 @@ export class DatabaseNative {
|
|
|
29
28
|
}
|
|
30
29
|
},
|
|
31
30
|
execute: async (options, successCallback, errorCallback) => {
|
|
32
|
-
var _a;
|
|
33
31
|
try {
|
|
34
32
|
const db = this.getDatabase(options.dbName);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
const
|
|
40
|
-
|
|
33
|
+
// FIX: Await the result properly
|
|
34
|
+
const res = await db.execute(options.query, options.params);
|
|
35
|
+
let resultToReturn = [];
|
|
36
|
+
// Cast to any to avoid TS error "Property '_array' does not exist on type 'never'"
|
|
37
|
+
const rawRes = res;
|
|
38
|
+
if (rawRes) {
|
|
39
|
+
if (rawRes.rows) {
|
|
40
|
+
const rawRows = rawRes.rows;
|
|
41
|
+
if (Array.isArray(rawRows)) {
|
|
42
|
+
resultToReturn = rawRows;
|
|
43
|
+
}
|
|
44
|
+
else if (rawRows._array && Array.isArray(rawRows._array)) {
|
|
45
|
+
resultToReturn = rawRows._array;
|
|
46
|
+
}
|
|
47
|
+
else if (typeof rawRows.length === 'number') {
|
|
48
|
+
// JSI iterator
|
|
49
|
+
for (let i = 0; i < rawRows.length; i++) {
|
|
50
|
+
// Use item() if available, otherwise index access
|
|
51
|
+
const r = rawRows.item ? rawRows.item(i) : rawRows[i];
|
|
52
|
+
resultToReturn.push(r);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (Array.isArray(rawRes)) {
|
|
57
|
+
resultToReturn = rawRes;
|
|
58
|
+
}
|
|
59
|
+
// Attach insertId if present (though interface usually expects strict array,
|
|
60
|
+
// JS runtime allows attaching props to array)
|
|
61
|
+
if (rawRes.insertId !== undefined) {
|
|
62
|
+
resultToReturn.insertId = rawRes.insertId;
|
|
63
|
+
resultToReturn.rowsAffected = rawRes.rowsAffected;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
successCallback(resultToReturn);
|
|
41
67
|
}
|
|
42
68
|
catch (error) {
|
|
43
69
|
errorCallback(error instanceof Error ? error.message : String(error));
|
|
44
70
|
}
|
|
45
71
|
},
|
|
46
72
|
executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
|
|
47
|
-
var _a
|
|
73
|
+
var _a;
|
|
48
74
|
try {
|
|
49
75
|
const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
|
|
50
76
|
const db = this.getDatabase(dbName);
|
|
51
|
-
const res = db.execute(sqlQuery);
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
77
|
+
const res = await db.execute(sqlQuery);
|
|
78
|
+
let resultToReturn = [];
|
|
79
|
+
const rawRes = res;
|
|
80
|
+
if (rawRes && rawRes.rows) {
|
|
81
|
+
const rawRows = rawRes.rows;
|
|
82
|
+
if (typeof rawRows.length === 'number') {
|
|
83
|
+
for (let i = 0; i < rawRows.length; i++) {
|
|
84
|
+
const r = rawRows.item ? rawRows.item(i) : rawRows[i];
|
|
85
|
+
resultToReturn.push(r);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (Array.isArray(rawRows)) {
|
|
89
|
+
resultToReturn = rawRows;
|
|
90
|
+
}
|
|
91
|
+
else if (rawRows._array) {
|
|
92
|
+
resultToReturn = rawRows._array;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Attach insertId if present
|
|
96
|
+
if (rawRes && rawRes.insertId !== undefined) {
|
|
97
|
+
resultToReturn.insertId = rawRes.insertId;
|
|
98
|
+
resultToReturn.rowsAffected = rawRes.rowsAffected;
|
|
99
|
+
}
|
|
100
|
+
callback(resultToReturn);
|
|
55
101
|
}
|
|
56
102
|
catch (error) {
|
|
57
103
|
callback([]);
|
|
58
104
|
}
|
|
59
105
|
},
|
|
60
106
|
selectFromPath: async (dbPath, sqlQuery, callback) => {
|
|
61
|
-
var _a
|
|
107
|
+
var _a;
|
|
62
108
|
try {
|
|
63
109
|
const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
|
|
64
110
|
const db = this.getDatabase(dbName);
|
|
65
|
-
const res = db.execute(sqlQuery);
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
111
|
+
const res = await db.execute(sqlQuery);
|
|
112
|
+
let resultToReturn = [];
|
|
113
|
+
const rawRes = res;
|
|
114
|
+
if (rawRes && rawRes.rows) {
|
|
115
|
+
const rawRows = rawRes.rows;
|
|
116
|
+
if (typeof rawRows.length === 'number') {
|
|
117
|
+
for (let i = 0; i < rawRows.length; i++) {
|
|
118
|
+
const r = rawRows.item ? rawRows.item(i) : rawRows[i];
|
|
119
|
+
resultToReturn.push(r);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (Array.isArray(rawRows)) {
|
|
123
|
+
resultToReturn = rawRows;
|
|
124
|
+
}
|
|
125
|
+
else if (rawRows._array) {
|
|
126
|
+
resultToReturn = rawRows._array;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
callback(resultToReturn);
|
|
69
130
|
}
|
|
70
131
|
catch (error) {
|
|
71
132
|
callback([]);
|
|
@@ -106,7 +167,7 @@ export class DatabaseNative {
|
|
|
106
167
|
? "DELETE FROM user_data WHERE user_id = ?"
|
|
107
168
|
: "DELETE FROM user_data";
|
|
108
169
|
const params = options.userId ? [options.userId] : [];
|
|
109
|
-
db.execute(query, params);
|
|
170
|
+
await db.execute(query, params);
|
|
110
171
|
callback();
|
|
111
172
|
}
|
|
112
173
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvired/react-native-unvired-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Unvired SDK for React Native with logging, database, notifications, and file system support",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
+
"@op-engineering/op-sqlite": "^15.2.5",
|
|
16
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
17
|
+
"@react-native-firebase/messaging": "^21.8.1",
|
|
15
18
|
"react": ">=18",
|
|
16
19
|
"react-native": ">=0.73",
|
|
17
|
-
"react-native-fs": "^2.20.0",
|
|
18
20
|
"react-native-device-info": "^15.0.1",
|
|
19
|
-
"
|
|
20
|
-
"react-native-zip-archive": "^7.0.2"
|
|
21
|
-
"@react-native-firebase/messaging": "^21.8.1",
|
|
22
|
-
"@react-native-async-storage/async-storage": "^2.2.0"
|
|
21
|
+
"react-native-fs": "^2.20.0",
|
|
22
|
+
"react-native-zip-archive": "^7.0.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependenciesMeta": {
|
|
25
25
|
"@react-native-firebase/messaging": {
|
|
@@ -42,25 +42,23 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"pako": "^2.1.0"
|
|
46
|
-
"sql.js": "^1.10.3"
|
|
45
|
+
"pako": "^2.1.0"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"
|
|
48
|
+
"@op-engineering/op-sqlite": "^15.2.5",
|
|
49
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
50
|
+
"@react-native-firebase/messaging": "^21.8.1",
|
|
51
|
+
"@types/pako": "^2.0.4",
|
|
52
|
+
"@types/react": ">=18",
|
|
53
|
+
"@types/react-native": "^0.73.0",
|
|
50
54
|
"eslint": "^8.0.0",
|
|
51
55
|
"jest": "^29.0.0",
|
|
52
56
|
"prettier": "^3.0.0",
|
|
53
|
-
"@types/react": ">=18",
|
|
54
|
-
"@types/react-native": "^0.73.0",
|
|
55
57
|
"react": "19.2.0",
|
|
56
58
|
"react-native": "0.83.1",
|
|
57
|
-
"react-native-fs": "^2.20.0",
|
|
58
59
|
"react-native-device-info": "^15.0.1",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
62
|
-
"@types/pako": "^2.0.4",
|
|
63
|
-
"@types/sql.js": "^1.4.9"
|
|
60
|
+
"react-native-fs": "^2.20.0",
|
|
61
|
+
"typescript": "^5.0.0"
|
|
64
62
|
},
|
|
65
63
|
"engines": {
|
|
66
64
|
"node": ">=18"
|
|
@@ -68,4 +66,4 @@
|
|
|
68
66
|
"publishConfig": {
|
|
69
67
|
"access": "public"
|
|
70
68
|
}
|
|
71
|
-
}
|
|
69
|
+
}
|
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { FileSystem } from '../src/file-system/FileSystem';
|
|
1
|
+
import { DeviceInfo, DatabaseManager, LocalStorage, logger, LogLevel, PushNotification, FileSystem } from '@unvired/react-native-unvired-sdk';
|
|
2
|
+
import { PlatformInterface, IDeviceInfo, IFileEntry, IDatabaseAdapter, IPushNotificationAdapter, ILoggerAdapter, IStorageAdapter } from './PlatformInterface';
|
|
3
|
+
|
|
5
4
|
export class ReactNativePlatformAdapter implements PlatformInterface {
|
|
6
5
|
|
|
7
|
-
getDeviceInfo(): IDeviceInfo {
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
platform: 'unknown',
|
|
11
|
-
model: '',
|
|
12
|
-
version: '',
|
|
13
|
-
isMobile: true
|
|
14
|
-
};
|
|
6
|
+
async getDeviceInfo(): Promise<IDeviceInfo> {
|
|
7
|
+
return await DeviceInfo.getDeviceInfo();
|
|
15
8
|
}
|
|
16
9
|
|
|
17
10
|
getPlatform(): string {
|
|
18
|
-
|
|
19
|
-
return "";
|
|
11
|
+
return DeviceInfo.getPlatform();
|
|
20
12
|
}
|
|
21
13
|
|
|
22
14
|
getFrontendType(): string {
|
|
23
|
-
|
|
24
|
-
// Refer CordovaPlatformAdapter.ts for reference to return values
|
|
25
|
-
return "";
|
|
15
|
+
return DeviceInfo.getFrontendType();
|
|
26
16
|
}
|
|
27
17
|
|
|
28
18
|
getDocumentDirectory(): string {
|
|
29
|
-
// Return the document directory path for React Native
|
|
30
19
|
return FileSystem.getDocumentDirectory();
|
|
31
20
|
}
|
|
32
21
|
|
|
@@ -35,71 +24,66 @@ export class ReactNativePlatformAdapter implements PlatformInterface {
|
|
|
35
24
|
}
|
|
36
25
|
|
|
37
26
|
async getFolderBasedOnUserId(userId: string): Promise<string> {
|
|
38
|
-
return FileSystem.getFolderBasedOnUserId(userId);
|
|
27
|
+
return await FileSystem.getFolderBasedOnUserId(userId);
|
|
39
28
|
}
|
|
40
29
|
|
|
41
30
|
async deleteUserFolder(userId: string): Promise<void> {
|
|
42
|
-
|
|
31
|
+
await FileSystem.deleteUserFolder(userId);
|
|
43
32
|
}
|
|
44
33
|
|
|
45
34
|
getDatabaseAdapter(): IDatabaseAdapter {
|
|
46
|
-
// TODO: Implement database adapter
|
|
47
35
|
return {
|
|
48
|
-
create: (options, successCallback, errorCallback) => {
|
|
49
|
-
//
|
|
36
|
+
create: (options: { userId: string }, successCallback, errorCallback) => {
|
|
37
|
+
// Map userId to dbName or pass appropriate options
|
|
38
|
+
DatabaseManager.getDatabaseAdapter().create({ name: options.userId }, successCallback, errorCallback);
|
|
50
39
|
},
|
|
51
|
-
execute: (options, successCallback, errorCallback) => {
|
|
52
|
-
|
|
40
|
+
execute: (options: any, successCallback, errorCallback) => {
|
|
41
|
+
DatabaseManager.getDatabaseAdapter().execute(options, successCallback, errorCallback);
|
|
53
42
|
},
|
|
54
43
|
executeStatementOnPath: (dbPath, sqlQuery, callback) => {
|
|
55
|
-
|
|
56
|
-
callback([]);
|
|
44
|
+
DatabaseManager.getDatabaseAdapter().executeStatementOnPath(dbPath, sqlQuery, callback);
|
|
57
45
|
},
|
|
58
46
|
selectFromPath: (dbPath, sqlQuery, callback) => {
|
|
59
|
-
|
|
60
|
-
callback([]);
|
|
47
|
+
DatabaseManager.getDatabaseAdapter().selectFromPath(dbPath, sqlQuery, callback);
|
|
61
48
|
},
|
|
62
49
|
createDatabase: (dbPath, callback) => {
|
|
63
|
-
|
|
64
|
-
callback();
|
|
50
|
+
DatabaseManager.getDatabaseAdapter().createDatabase(dbPath, callback);
|
|
65
51
|
},
|
|
66
|
-
getDBFilePath: (options, callback) => {
|
|
67
|
-
|
|
68
|
-
callback("");
|
|
52
|
+
getDBFilePath: (options: { dbType: string }, callback) => {
|
|
53
|
+
DatabaseManager.getDatabaseAdapter().getDBFilePath({ name: options.dbType }, callback);
|
|
69
54
|
},
|
|
70
|
-
saveWebDB: (options, callback, errorCallback) => {
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
saveWebDB: (options: { userId: string }, callback, errorCallback) => {
|
|
56
|
+
const dbName = options.userId;
|
|
57
|
+
const data = (options as any).data || {};
|
|
58
|
+
DatabaseManager.getDatabaseAdapter().saveWebDB({ dbName, data }, callback, errorCallback);
|
|
73
59
|
},
|
|
74
|
-
exportWebDB: (options, callback, errorCallback) => {
|
|
75
|
-
|
|
76
|
-
callback({});
|
|
60
|
+
exportWebDB: (options: { userId: string }, callback, errorCallback) => {
|
|
61
|
+
DatabaseManager.getDatabaseAdapter().exportWebDB({ dbName: options.userId }, callback, errorCallback);
|
|
77
62
|
},
|
|
78
|
-
deleteUserData: (options, callback, errorCallback) => {
|
|
79
|
-
|
|
80
|
-
callback();
|
|
63
|
+
deleteUserData: (options: { userId: string }, callback, errorCallback) => {
|
|
64
|
+
DatabaseManager.getDatabaseAdapter().deleteUserData({ dbName: options.userId, userId: options.userId }, callback, errorCallback);
|
|
81
65
|
}
|
|
82
66
|
};
|
|
83
67
|
}
|
|
84
68
|
|
|
85
69
|
getPushNotificationAdapter(): IPushNotificationAdapter | null {
|
|
86
70
|
try {
|
|
71
|
+
const pushNotification = new PushNotification();
|
|
87
72
|
return {
|
|
88
73
|
requestPermission: async (options = { forceShow: false }) => {
|
|
89
|
-
|
|
74
|
+
await pushNotification.requestPermission(options);
|
|
90
75
|
},
|
|
91
76
|
getToken: async () => {
|
|
92
|
-
|
|
93
|
-
return "";
|
|
77
|
+
return await pushNotification.getToken();
|
|
94
78
|
},
|
|
95
79
|
onTokenRefresh: (callback) => {
|
|
96
|
-
|
|
80
|
+
pushNotification.onTokenRefresh(callback);
|
|
97
81
|
},
|
|
98
82
|
onMessage: (callback) => {
|
|
99
|
-
|
|
83
|
+
pushNotification.onMessage(callback);
|
|
100
84
|
},
|
|
101
85
|
onBackgroundMessage: (callback) => {
|
|
102
|
-
|
|
86
|
+
pushNotification.onBackgroundMessage(callback);
|
|
103
87
|
}
|
|
104
88
|
};
|
|
105
89
|
} catch (error) {
|
|
@@ -110,58 +94,45 @@ export class ReactNativePlatformAdapter implements PlatformInterface {
|
|
|
110
94
|
getLoggerAdapter(): ILoggerAdapter {
|
|
111
95
|
return {
|
|
112
96
|
logDebug: (sourceClass, method, message) => {
|
|
113
|
-
console.log(`[DEBUG] ${sourceClass}.${method}: ${message}`);
|
|
114
97
|
logger.logDebug(sourceClass, method, message);
|
|
115
|
-
// TODO: Implement log file writing
|
|
116
98
|
},
|
|
117
99
|
logError: (sourceClass, method, message) => {
|
|
118
|
-
console.error(`[ERROR] ${sourceClass}.${method}: ${message}`);
|
|
119
100
|
logger.logError(sourceClass, method, message);
|
|
120
|
-
// TODO: Implement log file writing
|
|
121
101
|
},
|
|
122
102
|
logInfo: (sourceClass, method, message) => {
|
|
123
|
-
console.info(`[INFO] ${sourceClass}.${method}: ${message}`);
|
|
124
103
|
logger.logInfo(sourceClass, method, message);
|
|
125
|
-
// TODO: Implement log file writing
|
|
126
104
|
},
|
|
127
105
|
setLogLevel: (logLevel: LogLevel) => {
|
|
128
|
-
// TODO: Implement log level setting
|
|
129
|
-
console.log(`Setting log level to: ${logLevel}`);
|
|
130
106
|
logger.setLogLevel(logLevel);
|
|
131
107
|
},
|
|
132
108
|
getLogFileURL: async () => {
|
|
133
|
-
// TODO: Implement log file URL retrieval
|
|
134
109
|
return logger.getLogFileURL();
|
|
135
110
|
},
|
|
136
111
|
getLogFileContent: async () => {
|
|
137
|
-
// TODO: Implement log file content retrieval
|
|
138
112
|
return logger.getLogFileContent();
|
|
139
113
|
},
|
|
140
114
|
getBackupLogFileContent: async () => {
|
|
141
|
-
|
|
142
|
-
const content = await logger.getBackupLogFileContent();
|
|
143
|
-
return content || '';
|
|
115
|
+
return logger.getBackupLogFileContent();
|
|
144
116
|
},
|
|
145
117
|
clearLogFile: async () => {
|
|
146
|
-
// TODO: Implement log file clearing
|
|
147
118
|
logger.clearLogFile();
|
|
148
119
|
}
|
|
149
120
|
};
|
|
150
121
|
}
|
|
151
122
|
|
|
152
|
-
getStorageAdapter() {
|
|
123
|
+
getStorageAdapter(): IStorageAdapter {
|
|
153
124
|
return {
|
|
154
125
|
getItem: (key: string) => {
|
|
155
|
-
return
|
|
126
|
+
return LocalStorage.getItem(key);
|
|
156
127
|
},
|
|
157
128
|
setItem: (key: string, value: string) => {
|
|
158
|
-
|
|
129
|
+
return LocalStorage.setItem(key, value);
|
|
159
130
|
},
|
|
160
131
|
removeItem: (key: string) => {
|
|
161
|
-
|
|
132
|
+
return LocalStorage.removeItem(key);
|
|
162
133
|
},
|
|
163
134
|
clear: () => {
|
|
164
|
-
|
|
135
|
+
return LocalStorage.clear();
|
|
165
136
|
}
|
|
166
137
|
};
|
|
167
138
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IDatabaseAdapter } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* DatabaseWeb - Web database implementation using sql.js
|
|
4
|
-
* Uses SQLite compiled to WebAssembly for full SQLite compatibility in browsers
|
|
5
|
-
*/
|
|
6
|
-
export declare class DatabaseWeb {
|
|
7
|
-
private databases;
|
|
8
|
-
private SQL;
|
|
9
|
-
private initSQL;
|
|
10
|
-
private getDatabase;
|
|
11
|
-
private executeQuery;
|
|
12
|
-
getAdapter(): IDatabaseAdapter;
|
|
13
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import initSqlJs from 'sql.js';
|
|
2
|
-
/**
|
|
3
|
-
* DatabaseWeb - Web database implementation using sql.js
|
|
4
|
-
* Uses SQLite compiled to WebAssembly for full SQLite compatibility in browsers
|
|
5
|
-
*/
|
|
6
|
-
export class DatabaseWeb {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.databases = new Map();
|
|
9
|
-
this.SQL = null;
|
|
10
|
-
}
|
|
11
|
-
async initSQL() {
|
|
12
|
-
if (!this.SQL) {
|
|
13
|
-
this.SQL = await initSqlJs({
|
|
14
|
-
locateFile: (file) => `https://sql.js.org/dist/${file}`
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return this.SQL;
|
|
18
|
-
}
|
|
19
|
-
async getDatabase(name) {
|
|
20
|
-
if (this.databases.has(name)) {
|
|
21
|
-
return this.databases.get(name);
|
|
22
|
-
}
|
|
23
|
-
const SQL = await this.initSQL();
|
|
24
|
-
const db = new SQL.Database();
|
|
25
|
-
this.databases.set(name, db);
|
|
26
|
-
return db;
|
|
27
|
-
}
|
|
28
|
-
executeQuery(db, query, params = []) {
|
|
29
|
-
const results = [];
|
|
30
|
-
const stmt = db.prepare(query);
|
|
31
|
-
stmt.bind(params);
|
|
32
|
-
while (stmt.step()) {
|
|
33
|
-
const row = stmt.getAsObject();
|
|
34
|
-
results.push(row);
|
|
35
|
-
}
|
|
36
|
-
stmt.free();
|
|
37
|
-
return results;
|
|
38
|
-
}
|
|
39
|
-
getAdapter() {
|
|
40
|
-
return {
|
|
41
|
-
create: async (options, successCallback, errorCallback) => {
|
|
42
|
-
try {
|
|
43
|
-
await this.getDatabase(options.name);
|
|
44
|
-
successCallback({ success: true, database: options.name });
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
errorCallback(error instanceof Error ? error.message : String(error));
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
execute: async (options, successCallback, errorCallback) => {
|
|
51
|
-
try {
|
|
52
|
-
const db = await this.getDatabase(options.dbName);
|
|
53
|
-
const results = this.executeQuery(db, options.query, options.params);
|
|
54
|
-
successCallback(results);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
errorCallback(error instanceof Error ? error.message : String(error));
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
|
|
61
|
-
var _a;
|
|
62
|
-
try {
|
|
63
|
-
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
64
|
-
const db = await this.getDatabase(dbName);
|
|
65
|
-
const results = this.executeQuery(db, sqlQuery);
|
|
66
|
-
callback(results);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
callback([]);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
selectFromPath: async (dbPath, sqlQuery, callback) => {
|
|
73
|
-
var _a;
|
|
74
|
-
try {
|
|
75
|
-
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
76
|
-
const db = await this.getDatabase(dbName);
|
|
77
|
-
const results = this.executeQuery(db, sqlQuery);
|
|
78
|
-
callback(results);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
callback([]);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
createDatabase: async (dbPath, callback) => {
|
|
85
|
-
var _a;
|
|
86
|
-
try {
|
|
87
|
-
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
88
|
-
await this.getDatabase(dbName);
|
|
89
|
-
callback();
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
callback();
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
getDBFilePath: async (options, callback) => {
|
|
96
|
-
callback(`sqljs://${options.name}`);
|
|
97
|
-
},
|
|
98
|
-
saveWebDB: async (options, callback, errorCallback) => {
|
|
99
|
-
try {
|
|
100
|
-
const db = await this.getDatabase(options.dbName);
|
|
101
|
-
if (Array.isArray(options.data)) {
|
|
102
|
-
for (const item of options.data) {
|
|
103
|
-
if (item.query && item.params) {
|
|
104
|
-
db.run(item.query, item.params);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
callback({ success: true });
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
errorCallback(error instanceof Error ? error.message : String(error));
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
exportWebDB: async (options, callback, errorCallback) => {
|
|
115
|
-
try {
|
|
116
|
-
const db = await this.getDatabase(options.dbName);
|
|
117
|
-
const tables = this.executeQuery(db, "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'");
|
|
118
|
-
callback({ success: true, tables: tables.map(t => t.name) });
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
errorCallback(error instanceof Error ? error.message : String(error));
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
deleteUserData: async (options, callback, errorCallback) => {
|
|
125
|
-
try {
|
|
126
|
-
const db = await this.getDatabase(options.dbName);
|
|
127
|
-
const query = options.userId ? 'DELETE FROM user_data WHERE user_id = ?' : 'DELETE FROM user_data';
|
|
128
|
-
const params = options.userId ? [options.userId] : [];
|
|
129
|
-
db.run(query, params);
|
|
130
|
-
callback();
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
errorCallback(error instanceof Error ? error.message : String(error));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|