@capacitor-community/sqlite 4.8.0-0 → 4.8.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/README.md +11 -11
- package/electron/dist/plugin.js +229 -129
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
17
17
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
18
18
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
19
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
19
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-34-orange?style=flat-square" /></a>
|
|
20
20
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
21
21
|
</p>
|
|
22
22
|
|
|
@@ -157,10 +157,9 @@ You'll need the usual capacitor/android/react npm script to build and copy the a
|
|
|
157
157
|
|
|
158
158
|
```bash
|
|
159
159
|
cd electron
|
|
160
|
-
npm install --save
|
|
160
|
+
npm install --save @journeyapps/sqlcipher
|
|
161
161
|
npm install --save jszip
|
|
162
162
|
npm install --save node-fetch@2.6.7
|
|
163
|
-
npm install --save-dev @types/sqlite3
|
|
164
163
|
```
|
|
165
164
|
- **Important**: `node-fetch` version must be `<=2.6.7`; otherwise [you'll get an error](https://github.com/capacitor-community/sqlite/issues/349 "you'll get an error ERR_REQUIRE_ESM") running the app.
|
|
166
165
|
|
|
@@ -180,7 +179,7 @@ npm install --save-dev @types/sqlite3
|
|
|
180
179
|
| isConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
|
|
181
180
|
| isConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7
|
|
182
181
|
| open (non-encrypted DB) | ✅ | ✅ | ✅ | ✅ |
|
|
183
|
-
| open (encrypted DB) | ✅ | ✅ |
|
|
182
|
+
| open (encrypted DB) | ✅ | ✅ | ✅ | ❌ |
|
|
184
183
|
| close | ✅ | ✅ | ✅ | ✅ |
|
|
185
184
|
| getUrl | ✅ | ✅ | ❌ | ❌ |
|
|
186
185
|
| getVersion | ✅ | ✅ | ✅ | ✅ |
|
|
@@ -209,10 +208,10 @@ npm install --save-dev @types/sqlite3
|
|
|
209
208
|
| deleteOldDatabases | ✅ | ✅ | ❌ | ❌ |
|
|
210
209
|
| moveDatabasesAndAddSuffix | ✅ | ✅ | ❌ | ❌ |
|
|
211
210
|
| checkConnectionsConsistency | ✅ | ✅ | ✅ | ✅ |
|
|
212
|
-
| isSecretStored | ✅ | ✅ |
|
|
213
|
-
| setEncryptionSecret | ✅ | ✅ |
|
|
214
|
-
| changeEncryptionSecret | ✅ | ✅ |
|
|
215
|
-
| clearEncryptionSecret | ✅ | ✅ |
|
|
211
|
+
| isSecretStored | ✅ | ✅ | ✅ | ❌ |
|
|
212
|
+
| setEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
|
|
213
|
+
| changeEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
|
|
214
|
+
| clearEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
|
|
216
215
|
| checkEncryptionSecret | ✅ | ✅ | ❌ | ❌ |
|
|
217
216
|
| initWebStore | ❌ | ❌ | ❌ | ✅ |
|
|
218
217
|
| saveToStore | ❌ | ❌ | ❌ | ✅ |
|
|
@@ -305,9 +304,9 @@ npm install --save-dev @types/sqlite3
|
|
|
305
304
|
## Dependencies
|
|
306
305
|
|
|
307
306
|
The iOS and Android codes are using `SQLCipher` allowing for database encryption.
|
|
308
|
-
The iOS codes is using `ZIPFoundation` for unzipping assets files
|
|
309
|
-
The Electron code is using `
|
|
310
|
-
The Web code is using the Stencil component `jeep-sqlite` based on `sql.js`, `localforage
|
|
307
|
+
The iOS codes is using `ZIPFoundation` for unzipping assets files
|
|
308
|
+
The Electron code is using `@journeyapps/sqlcipher` and `node-fetch` from 4.2.0.
|
|
309
|
+
The Web code is using the Stencil component `jeep-sqlite` based on `sql.js`, `localforage`. and `jszip`
|
|
311
310
|
|
|
312
311
|
## Contributors ✨
|
|
313
312
|
|
|
@@ -351,6 +350,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
351
350
|
<a href="https://github.com/patdx" title="patdx"><img src="https://github.com/patdx.png?size=100" width="50" height="50" /></a>
|
|
352
351
|
<a href="https://github.com/folsze" title="folsze"><img src="https://github.com/folsze.png?size=100" width="50" height="50" /></a>
|
|
353
352
|
<a href="https://github.com/pranav-singhal" title="pranav-singhal"><img src="https://github.com/pranav-singhal.png?size=100" width="50" height="50" /></a>
|
|
353
|
+
<a href="https://github.com/beligatclement" title="beligatclement"><img src="https://github.com/beligatclement.png?size=100" width="50" height="50" /></a>
|
|
354
354
|
</p>
|
|
355
355
|
|
|
356
356
|
|
package/electron/dist/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var require$$0 = require('
|
|
5
|
+
var require$$0 = require('@journeyapps/sqlcipher');
|
|
6
6
|
var require$$0$1 = require('node:fs/promises');
|
|
7
7
|
var require$$1 = require('path');
|
|
8
8
|
var require$$2 = require('fs');
|
|
@@ -24,6 +24,18 @@ var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
|
24
24
|
|
|
25
25
|
var src = {};
|
|
26
26
|
|
|
27
|
+
var GlobalSQLite$1 = {};
|
|
28
|
+
|
|
29
|
+
Object.defineProperty(GlobalSQLite$1, "__esModule", { value: true });
|
|
30
|
+
GlobalSQLite$1.GlobalSQLite = void 0;
|
|
31
|
+
class GlobalSQLite {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.secret = 'sqlite secret';
|
|
34
|
+
this.newsecret = 'sqlite new secret';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
GlobalSQLite$1.GlobalSQLite = GlobalSQLite;
|
|
38
|
+
|
|
27
39
|
var Database$1 = {};
|
|
28
40
|
|
|
29
41
|
var exportToJson = {};
|
|
@@ -34,28 +46,28 @@ Object.defineProperty(utilsSQLite, "__esModule", { value: true });
|
|
|
34
46
|
utilsSQLite.UtilsSQLite = void 0;
|
|
35
47
|
const SQLITE_OPEN_READONLY = 1;
|
|
36
48
|
class UtilsSQLite {
|
|
49
|
+
// public SQLite3: any;
|
|
37
50
|
constructor() {
|
|
38
51
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
39
|
-
|
|
40
|
-
this.SQLite3 = require
|
|
52
|
+
this.JSQlite = require$$0__default["default"].verbose();
|
|
53
|
+
// this.SQLite3 = require('sqlite3');
|
|
41
54
|
}
|
|
42
55
|
/**
|
|
43
56
|
* OpenOrCreateDatabase
|
|
44
57
|
* @param pathDB
|
|
45
58
|
* @param password
|
|
46
59
|
*/
|
|
47
|
-
async openOrCreateDatabase(pathDB
|
|
48
|
-
password: string,*/, readonly) {
|
|
60
|
+
async openOrCreateDatabase(pathDB, password, readonly) {
|
|
49
61
|
const msg = 'OpenOrCreateDatabase: ';
|
|
50
62
|
// open sqlite3 database
|
|
51
63
|
let mDB;
|
|
52
64
|
if (!readonly) {
|
|
53
|
-
mDB = new this.
|
|
65
|
+
mDB = new this.JSQlite.Database(pathDB, {
|
|
54
66
|
verbose: console.log,
|
|
55
67
|
});
|
|
56
68
|
}
|
|
57
69
|
else {
|
|
58
|
-
mDB = new this.
|
|
70
|
+
mDB = new this.JSQlite.Database(pathDB, SQLITE_OPEN_READONLY, {
|
|
59
71
|
verbose: console.log,
|
|
60
72
|
});
|
|
61
73
|
}
|
|
@@ -67,11 +79,10 @@ class UtilsSQLite {
|
|
|
67
79
|
return Promise.reject(msg + `dbChanges ${err}`);
|
|
68
80
|
}
|
|
69
81
|
try {
|
|
70
|
-
|
|
82
|
+
// set the password
|
|
71
83
|
if (password.length > 0) {
|
|
72
|
-
|
|
84
|
+
await this.setCipherPragma(mDB, password);
|
|
73
85
|
}
|
|
74
|
-
*/
|
|
75
86
|
// set Foreign Keys On
|
|
76
87
|
await this.setForeignKeyConstraintsEnabled(mDB, true);
|
|
77
88
|
}
|
|
@@ -89,21 +100,20 @@ class UtilsSQLite {
|
|
|
89
100
|
* @param mDB
|
|
90
101
|
* @param password
|
|
91
102
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
async setCipherPragma(mDB, password) {
|
|
104
|
+
console.log("setCipherPragma");
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
mDB.serialize(() => {
|
|
107
|
+
mDB.run('PRAGMA cipher_compatibility = 4');
|
|
108
|
+
mDB.run(`PRAGMA key = '${password}'`, (err) => {
|
|
109
|
+
if (err) {
|
|
110
|
+
reject(new Error('SetForeignKey: ' + `${err.message}`));
|
|
111
|
+
}
|
|
112
|
+
resolve();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
103
115
|
});
|
|
104
|
-
});
|
|
105
116
|
}
|
|
106
|
-
*/
|
|
107
117
|
/**
|
|
108
118
|
* SetForeignKeyConstraintsEnabled
|
|
109
119
|
* @param mDB
|
|
@@ -170,50 +180,39 @@ class UtilsSQLite {
|
|
|
170
180
|
* @param password
|
|
171
181
|
* @param newpassword
|
|
172
182
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return Promise.reject(err);
|
|
186
|
-
} finally {
|
|
187
|
-
mDB.close();
|
|
188
|
-
}
|
|
183
|
+
async changePassword(pathDB, password, newpassword) {
|
|
184
|
+
let mDB;
|
|
185
|
+
try {
|
|
186
|
+
mDB = await this.openOrCreateDatabase(pathDB, password, false);
|
|
187
|
+
await this.pragmaReKey(mDB, password, newpassword);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
return Promise.reject(err);
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
mDB.close();
|
|
194
|
+
}
|
|
189
195
|
}
|
|
190
|
-
*/
|
|
191
196
|
/**
|
|
192
197
|
* PragmaReKey
|
|
193
198
|
* @param mDB
|
|
194
199
|
* @param password
|
|
195
200
|
* @param newpassword
|
|
196
201
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
reject(new Error('ChangePassword: ' + `${err.message}`));
|
|
210
|
-
}
|
|
211
|
-
resolve();
|
|
212
|
-
});
|
|
202
|
+
async pragmaReKey(mDB, password, newpassword) {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
mDB.serialize(() => {
|
|
205
|
+
mDB.run('PRAGMA cipher_compatibility = 4');
|
|
206
|
+
mDB.run(`PRAGMA key = '${password}'`);
|
|
207
|
+
mDB.run(`PRAGMA rekey = '${newpassword}'`, (err) => {
|
|
208
|
+
if (err) {
|
|
209
|
+
reject(new Error('ChangePassword: ' + `${err.message}`));
|
|
210
|
+
}
|
|
211
|
+
resolve();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
213
214
|
});
|
|
214
|
-
});
|
|
215
215
|
}
|
|
216
|
-
*/
|
|
217
216
|
/**
|
|
218
217
|
* BeginTransaction
|
|
219
218
|
* @param db
|
|
@@ -872,10 +871,10 @@ var utilsJson = {};
|
|
|
872
871
|
|
|
873
872
|
Object.defineProperty(utilsJson, "__esModule", { value: true });
|
|
874
873
|
utilsJson.UtilsJson = void 0;
|
|
875
|
-
const utilsSQLite_1$
|
|
874
|
+
const utilsSQLite_1$6 = utilsSQLite;
|
|
876
875
|
class UtilsJson {
|
|
877
876
|
constructor() {
|
|
878
|
-
this.sqliteUtil = new utilsSQLite_1$
|
|
877
|
+
this.sqliteUtil = new utilsSQLite_1$6.UtilsSQLite();
|
|
879
878
|
}
|
|
880
879
|
/**
|
|
881
880
|
* IsTableExists
|
|
@@ -1717,11 +1716,11 @@ utilsJson.UtilsJson = UtilsJson;
|
|
|
1717
1716
|
|
|
1718
1717
|
Object.defineProperty(exportToJson, "__esModule", { value: true });
|
|
1719
1718
|
exportToJson.ExportToJson = void 0;
|
|
1720
|
-
const utilsSQLite_1$
|
|
1719
|
+
const utilsSQLite_1$5 = utilsSQLite;
|
|
1721
1720
|
const utilsJson_1$3 = utilsJson;
|
|
1722
1721
|
class ExportToJson {
|
|
1723
1722
|
constructor() {
|
|
1724
|
-
this.sqliteUtil = new utilsSQLite_1$
|
|
1723
|
+
this.sqliteUtil = new utilsSQLite_1$5.UtilsSQLite();
|
|
1725
1724
|
this.jsonUtil = new utilsJson_1$3.UtilsJson();
|
|
1726
1725
|
}
|
|
1727
1726
|
/**
|
|
@@ -2432,10 +2431,10 @@ var utilsDrop = {};
|
|
|
2432
2431
|
|
|
2433
2432
|
Object.defineProperty(utilsDrop, "__esModule", { value: true });
|
|
2434
2433
|
utilsDrop.UtilsDrop = void 0;
|
|
2435
|
-
const utilsSQLite_1$
|
|
2434
|
+
const utilsSQLite_1$4 = utilsSQLite;
|
|
2436
2435
|
class UtilsDrop {
|
|
2437
2436
|
constructor() {
|
|
2438
|
-
this.sqliteUtil = new utilsSQLite_1$
|
|
2437
|
+
this.sqliteUtil = new utilsSQLite_1$4.UtilsSQLite();
|
|
2439
2438
|
}
|
|
2440
2439
|
/**
|
|
2441
2440
|
* DropElements
|
|
@@ -2541,12 +2540,12 @@ utilsDrop.UtilsDrop = UtilsDrop;
|
|
|
2541
2540
|
Object.defineProperty(importFromJson, "__esModule", { value: true });
|
|
2542
2541
|
importFromJson.ImportFromJson = void 0;
|
|
2543
2542
|
const utilsDrop_1 = utilsDrop;
|
|
2544
|
-
const utilsSQLite_1$
|
|
2543
|
+
const utilsSQLite_1$3 = utilsSQLite;
|
|
2545
2544
|
const utilsJson_1$2 = utilsJson;
|
|
2546
2545
|
class ImportFromJson {
|
|
2547
2546
|
constructor() {
|
|
2548
2547
|
this.jsonUtil = new utilsJson_1$2.UtilsJson();
|
|
2549
|
-
this.sqliteUtil = new utilsSQLite_1$
|
|
2548
|
+
this.sqliteUtil = new utilsSQLite_1$3.UtilsSQLite();
|
|
2550
2549
|
this.dropUtil = new utilsDrop_1.UtilsDrop();
|
|
2551
2550
|
}
|
|
2552
2551
|
/**
|
|
@@ -2689,6 +2688,8 @@ class ImportFromJson {
|
|
|
2689
2688
|
}
|
|
2690
2689
|
importFromJson.ImportFromJson = ImportFromJson;
|
|
2691
2690
|
|
|
2691
|
+
var utilsEncryption = {};
|
|
2692
|
+
|
|
2692
2693
|
var utilsFile = {};
|
|
2693
2694
|
|
|
2694
2695
|
Object.defineProperty(utilsFile, "__esModule", { value: true });
|
|
@@ -3262,6 +3263,66 @@ class UtilsFile {
|
|
|
3262
3263
|
}
|
|
3263
3264
|
utilsFile.UtilsFile = UtilsFile;
|
|
3264
3265
|
|
|
3266
|
+
Object.defineProperty(utilsEncryption, "__esModule", { value: true });
|
|
3267
|
+
utilsEncryption.UtilsEncryption = void 0;
|
|
3268
|
+
const utilsFile_1$2 = utilsFile;
|
|
3269
|
+
const utilsSQLite_1$2 = utilsSQLite;
|
|
3270
|
+
class UtilsEncryption {
|
|
3271
|
+
constructor() {
|
|
3272
|
+
this.fileUtil = new utilsFile_1$2.UtilsFile();
|
|
3273
|
+
this.sqliteUtil = new utilsSQLite_1$2.UtilsSQLite();
|
|
3274
|
+
}
|
|
3275
|
+
/**
|
|
3276
|
+
* EncryptDatabase
|
|
3277
|
+
* @param pathDB
|
|
3278
|
+
* @param password
|
|
3279
|
+
*/
|
|
3280
|
+
encryptDatabase(pathDB, password) {
|
|
3281
|
+
return new Promise(async (resolve, reject) => {
|
|
3282
|
+
const msg = 'EncryptDatabase: ';
|
|
3283
|
+
let retB = this.fileUtil.isPathExists(pathDB);
|
|
3284
|
+
if (retB) {
|
|
3285
|
+
let tempPath = this.fileUtil.getFilePath('temp.db');
|
|
3286
|
+
try {
|
|
3287
|
+
await this.fileUtil.renameFilePath(pathDB, tempPath);
|
|
3288
|
+
const oDB = await this.sqliteUtil.openOrCreateDatabase(tempPath, '', false);
|
|
3289
|
+
const mDB = await this.sqliteUtil.openOrCreateDatabase(pathDB, password, false);
|
|
3290
|
+
await this.sqlcipherEncrypt(oDB, pathDB, password);
|
|
3291
|
+
oDB.close();
|
|
3292
|
+
this.fileUtil.deleteFilePath(tempPath);
|
|
3293
|
+
mDB.close();
|
|
3294
|
+
resolve();
|
|
3295
|
+
}
|
|
3296
|
+
catch (err) {
|
|
3297
|
+
reject(new Error(`${msg} ${err.message} `));
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
else {
|
|
3301
|
+
reject(new Error(`${msg}file path ${pathDB} ` + 'does not exist'));
|
|
3302
|
+
}
|
|
3303
|
+
});
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* SqlcipherEncrypt
|
|
3307
|
+
* @param oDB
|
|
3308
|
+
* @param pathDB
|
|
3309
|
+
* @param password
|
|
3310
|
+
*/
|
|
3311
|
+
sqlcipherEncrypt(oDB, pathDB, password) {
|
|
3312
|
+
return new Promise(async (resolve) => {
|
|
3313
|
+
oDB.serialize(() => {
|
|
3314
|
+
let stmt = `ATTACH DATABASE '${pathDB}' `;
|
|
3315
|
+
stmt += `AS encrypted KEY '${password}';`;
|
|
3316
|
+
oDB.run(stmt);
|
|
3317
|
+
oDB.run("SELECT sqlcipher_export('encrypted');");
|
|
3318
|
+
oDB.run('DETACH DATABASE encrypted;');
|
|
3319
|
+
});
|
|
3320
|
+
resolve();
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
utilsEncryption.UtilsEncryption = UtilsEncryption;
|
|
3325
|
+
|
|
3265
3326
|
var utilsUpgrade = {};
|
|
3266
3327
|
|
|
3267
3328
|
Object.defineProperty(utilsUpgrade, "__esModule", { value: true });
|
|
@@ -3333,35 +3394,34 @@ utilsUpgrade.UtilsUpgrade = UtilsUpgrade;
|
|
|
3333
3394
|
|
|
3334
3395
|
Object.defineProperty(Database$1, "__esModule", { value: true });
|
|
3335
3396
|
Database$1.Database = void 0;
|
|
3397
|
+
const GlobalSQLite_1$1 = GlobalSQLite$1;
|
|
3336
3398
|
const exportToJson_1 = exportToJson;
|
|
3337
3399
|
const importFromJson_1 = importFromJson;
|
|
3338
3400
|
const utilsJson_1$1 = utilsJson;
|
|
3339
|
-
|
|
3401
|
+
const utilsEncryption_1 = utilsEncryption;
|
|
3340
3402
|
const utilsFile_1$1 = utilsFile;
|
|
3341
3403
|
const utilsSQLite_1 = utilsSQLite;
|
|
3342
3404
|
const utilsUpgrade_1 = utilsUpgrade;
|
|
3343
3405
|
class Database {
|
|
3344
|
-
constructor(dbName,
|
|
3345
|
-
// encrypted: boolean,
|
|
3346
|
-
// mode: string,
|
|
3347
|
-
version, readonly, upgDict) {
|
|
3406
|
+
constructor(dbName, encrypted, mode, version, readonly, upgDict, globalUtil) {
|
|
3348
3407
|
this.fileUtil = new utilsFile_1$1.UtilsFile();
|
|
3349
3408
|
this.sqliteUtil = new utilsSQLite_1.UtilsSQLite();
|
|
3350
3409
|
this.jsonUtil = new utilsJson_1$1.UtilsJson();
|
|
3351
|
-
|
|
3352
|
-
|
|
3410
|
+
this.globalUtil = new GlobalSQLite_1$1.GlobalSQLite();
|
|
3411
|
+
this.encryptionUtil = new utilsEncryption_1.UtilsEncryption();
|
|
3353
3412
|
this.upgradeUtil = new utilsUpgrade_1.UtilsUpgrade();
|
|
3354
3413
|
this.importFromJsonUtil = new importFromJson_1.ImportFromJson();
|
|
3355
3414
|
this.exportToJsonUtil = new exportToJson_1.ExportToJson();
|
|
3356
3415
|
this.upgradeVersionDict = {};
|
|
3357
3416
|
this.dbName = dbName;
|
|
3358
|
-
|
|
3359
|
-
|
|
3417
|
+
this._encrypted = encrypted;
|
|
3418
|
+
this._mode = mode;
|
|
3360
3419
|
this.version = version;
|
|
3361
3420
|
this.readonly = readonly;
|
|
3362
3421
|
this.upgradeVersionDict = upgDict;
|
|
3363
3422
|
this.pathDB = this.fileUtil.getFilePath(dbName);
|
|
3364
3423
|
this._isDbOpen = false;
|
|
3424
|
+
this.globalUtil = globalUtil ? globalUtil : new GlobalSQLite_1$1.GlobalSQLite();
|
|
3365
3425
|
if (this.pathDB.length === 0)
|
|
3366
3426
|
throw new Error('Could not generate a path to ' + dbName);
|
|
3367
3427
|
}
|
|
@@ -3382,29 +3442,23 @@ class Database {
|
|
|
3382
3442
|
*/
|
|
3383
3443
|
async open() {
|
|
3384
3444
|
this._isDbOpen = false;
|
|
3385
|
-
|
|
3445
|
+
let password = '';
|
|
3386
3446
|
try {
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
(this._mode === 'secret' || this._mode === 'encryption')
|
|
3391
|
-
) {
|
|
3392
|
-
password = this._uGlobal.secret;
|
|
3447
|
+
if (this._encrypted &&
|
|
3448
|
+
(this._mode === 'secret' || this._mode === 'encryption')) {
|
|
3449
|
+
password = this.globalUtil.secret;
|
|
3393
3450
|
}
|
|
3394
3451
|
if (this._mode === 'newsecret') {
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3452
|
+
// change the password
|
|
3453
|
+
const oPassword = this.globalUtil.secret;
|
|
3454
|
+
const nPassword = this.globalUtil.newsecret;
|
|
3455
|
+
await this.sqliteUtil.changePassword(this.pathDB, oPassword, nPassword);
|
|
3456
|
+
password = nPassword;
|
|
3400
3457
|
}
|
|
3401
|
-
|
|
3402
3458
|
if (this._mode === 'encryption') {
|
|
3403
|
-
|
|
3459
|
+
await this.encryptionUtil.encryptDatabase(this.pathDB, password);
|
|
3404
3460
|
}
|
|
3405
|
-
|
|
3406
|
-
this.database = await this.sqliteUtil.openOrCreateDatabase(this.pathDB /*,
|
|
3407
|
-
password,*/, this.readonly);
|
|
3461
|
+
this.database = await this.sqliteUtil.openOrCreateDatabase(this.pathDB, password, this.readonly);
|
|
3408
3462
|
this._isDbOpen = true;
|
|
3409
3463
|
if (!this.readonly) {
|
|
3410
3464
|
const curVersion = await this.sqliteUtil.getVersion(this.database);
|
|
@@ -3456,6 +3510,25 @@ class Database {
|
|
|
3456
3510
|
});
|
|
3457
3511
|
});
|
|
3458
3512
|
}
|
|
3513
|
+
/**
|
|
3514
|
+
* ChangeSecret
|
|
3515
|
+
* open the @journeyapps/sqlcipher sqlite3 database
|
|
3516
|
+
* @returns Promise<void>
|
|
3517
|
+
*/
|
|
3518
|
+
async changeSecret() {
|
|
3519
|
+
try {
|
|
3520
|
+
if (this._mode === 'encryption') {
|
|
3521
|
+
// change the password
|
|
3522
|
+
const oPassword = this.globalUtil.secret;
|
|
3523
|
+
const nPassword = this.globalUtil.newsecret;
|
|
3524
|
+
await this.sqliteUtil.changePassword(this.pathDB, oPassword, nPassword);
|
|
3525
|
+
}
|
|
3526
|
+
return;
|
|
3527
|
+
}
|
|
3528
|
+
catch (err) {
|
|
3529
|
+
throw new Error(`Change secret: ${err}`);
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3459
3532
|
/**
|
|
3460
3533
|
* GetVersion
|
|
3461
3534
|
* get the database version
|
|
@@ -3855,6 +3928,7 @@ Database$1.Database = Database;
|
|
|
3855
3928
|
|
|
3856
3929
|
Object.defineProperty(src, "__esModule", { value: true });
|
|
3857
3930
|
exports.CapacitorSQLite = src.CapacitorSQLite = void 0;
|
|
3931
|
+
const GlobalSQLite_1 = GlobalSQLite$1;
|
|
3858
3932
|
const Database_1 = Database$1;
|
|
3859
3933
|
const utilsJson_1 = utilsJson;
|
|
3860
3934
|
const utilsFile_1 = utilsFile;
|
|
@@ -3864,6 +3938,7 @@ class CapacitorSQLite {
|
|
|
3864
3938
|
this.databases = {};
|
|
3865
3939
|
this.fileUtil = new utilsFile_1.UtilsFile();
|
|
3866
3940
|
this.jsonUtil = new utilsJson_1.UtilsJson();
|
|
3941
|
+
this.globalUtil = new GlobalSQLite_1.GlobalSQLite();
|
|
3867
3942
|
}
|
|
3868
3943
|
async createConnection(options) {
|
|
3869
3944
|
const optionKeys = Object.keys(options);
|
|
@@ -3872,18 +3947,16 @@ class CapacitorSQLite {
|
|
|
3872
3947
|
}
|
|
3873
3948
|
const dbName = options.database;
|
|
3874
3949
|
const version = options.version ? options.version : 1;
|
|
3875
|
-
|
|
3876
|
-
const inMode = "no-encryption";
|
|
3877
|
-
|
|
3878
|
-
const encrypted: boolean =
|
|
3879
|
-
options.encrypted && this._osType === 'Darwin'
|
|
3950
|
+
// const encrypted = false;
|
|
3951
|
+
// const inMode = "no-encryption";
|
|
3952
|
+
const encrypted = options.encrypted
|
|
3880
3953
|
? options.encrypted
|
|
3881
3954
|
: false;
|
|
3882
|
-
const inMode
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3955
|
+
const inMode = options.mode === "secret"
|
|
3956
|
+
? "secret"
|
|
3957
|
+
: options.mode === "encryption"
|
|
3958
|
+
? "encryption"
|
|
3959
|
+
: 'no-encryption';
|
|
3887
3960
|
const readonly = options.readonly ? options.readonly : false;
|
|
3888
3961
|
let upgrades = {};
|
|
3889
3962
|
const versionUpgradeKeys = Object.keys(this.versionUpgrades);
|
|
@@ -3892,11 +3965,7 @@ class CapacitorSQLite {
|
|
|
3892
3965
|
upgrades = this.versionUpgrades[dbName];
|
|
3893
3966
|
}
|
|
3894
3967
|
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3895
|
-
const databaseConnection = new Database_1.Database(dbName + 'SQLite.db',
|
|
3896
|
-
/* encrypted,
|
|
3897
|
-
inMode,
|
|
3898
|
-
*/
|
|
3899
|
-
version, readonly, upgrades);
|
|
3968
|
+
const databaseConnection = new Database_1.Database(dbName + 'SQLite.db', encrypted, inMode, version, readonly, upgrades, this.globalUtil);
|
|
3900
3969
|
this.databases[connName] = databaseConnection;
|
|
3901
3970
|
return;
|
|
3902
3971
|
}
|
|
@@ -4187,7 +4256,7 @@ class CapacitorSQLite {
|
|
|
4187
4256
|
}
|
|
4188
4257
|
}
|
|
4189
4258
|
async importFromJson(options) {
|
|
4190
|
-
var _a, _b;
|
|
4259
|
+
var _a, _b, _c, _d;
|
|
4191
4260
|
const jsonString = this.getOptionValue(options, 'jsonstring');
|
|
4192
4261
|
const jsonObj = JSON.parse(jsonString);
|
|
4193
4262
|
const isValid = this.jsonUtil.isJsonSQLite(jsonObj);
|
|
@@ -4197,14 +4266,11 @@ class CapacitorSQLite {
|
|
|
4197
4266
|
const vJsonObj = jsonObj;
|
|
4198
4267
|
const dbName = `${vJsonObj.database}SQLite.db`;
|
|
4199
4268
|
const targetDbVersion = (_a = vJsonObj.version) !== null && _a !== void 0 ? _a : 1;
|
|
4200
|
-
const mode = vJsonObj.mode;
|
|
4201
4269
|
const overwrite = (_b = vJsonObj.overwrite) !== null && _b !== void 0 ? _b : false;
|
|
4202
|
-
|
|
4203
|
-
|
|
4270
|
+
const encrypted = (_c = vJsonObj.encrypted) !== null && _c !== void 0 ? _c : false;
|
|
4271
|
+
const mode = (_d = vJsonObj.mode) !== null && _d !== void 0 ? _d : 'no-encryption';
|
|
4204
4272
|
// Create the database
|
|
4205
|
-
const database = new Database_1.Database(dbName,
|
|
4206
|
-
/*encrypted, mode, */
|
|
4207
|
-
targetDbVersion, false, {});
|
|
4273
|
+
const database = new Database_1.Database(dbName, encrypted, mode, targetDbVersion, false, {}, this.globalUtil);
|
|
4208
4274
|
try {
|
|
4209
4275
|
if (overwrite && mode === 'full') {
|
|
4210
4276
|
const isExists = this.fileUtil.isFileExists(dbName);
|
|
@@ -4551,6 +4617,55 @@ class CapacitorSQLite {
|
|
|
4551
4617
|
}
|
|
4552
4618
|
return options[optionKey];
|
|
4553
4619
|
}
|
|
4620
|
+
async isSecretStored() {
|
|
4621
|
+
var _a;
|
|
4622
|
+
if (this.globalUtil != null) {
|
|
4623
|
+
let capSQLiteResult = { result: false };
|
|
4624
|
+
if (((_a = this.globalUtil) === null || _a === void 0 ? void 0 : _a.secret) != null && this.globalUtil.secret !== 'sqlite secret') {
|
|
4625
|
+
capSQLiteResult = { result: true };
|
|
4626
|
+
}
|
|
4627
|
+
return Promise.resolve(capSQLiteResult);
|
|
4628
|
+
}
|
|
4629
|
+
else {
|
|
4630
|
+
return Promise.reject(`isSecretStored: Failed check Secret.`);
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
4633
|
+
async setEncryptionSecret(options) {
|
|
4634
|
+
if (this.globalUtil != null) {
|
|
4635
|
+
this.globalUtil.secret = options.passphrase;
|
|
4636
|
+
Promise.resolve();
|
|
4637
|
+
}
|
|
4638
|
+
else {
|
|
4639
|
+
return Promise.reject(`setEncryptionSecret: Failed to set Secret.`);
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
async changeEncryptionSecret(options) {
|
|
4643
|
+
if (this.globalUtil != null) {
|
|
4644
|
+
this.globalUtil.secret = options.oldpassphrase;
|
|
4645
|
+
this.globalUtil.newsecret = options.passphrase;
|
|
4646
|
+
// get the database folder
|
|
4647
|
+
const pathDatabase = this.fileUtil.getDatabasesPath();
|
|
4648
|
+
// get the list of databases
|
|
4649
|
+
const files = await this.fileUtil.getFileList(pathDatabase);
|
|
4650
|
+
files.forEach((dbName) => {
|
|
4651
|
+
const connName = 'RW_' + dbName;
|
|
4652
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4653
|
+
database.changeSecret();
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
else {
|
|
4657
|
+
return Promise.reject(`changeEncryptionSecret: Failed to change Secret.`);
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
async clearEncryptionSecret() {
|
|
4661
|
+
if (this.globalUtil != null) {
|
|
4662
|
+
this.globalUtil.secret = '';
|
|
4663
|
+
Promise.resolve();
|
|
4664
|
+
}
|
|
4665
|
+
else {
|
|
4666
|
+
return Promise.reject(`clearEncryptionSecret: Failed to clear Secret.`);
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4554
4669
|
////////////////////////////////
|
|
4555
4670
|
//// UNIMPLEMENTED METHODS
|
|
4556
4671
|
////////////////////////////////
|
|
@@ -4588,21 +4703,6 @@ class CapacitorSQLite {
|
|
|
4588
4703
|
console.log(`${JSON.stringify(options)}`);
|
|
4589
4704
|
throw new Error('Method not implemented.');
|
|
4590
4705
|
}
|
|
4591
|
-
async isSecretStored() {
|
|
4592
|
-
throw new Error('Method not implemented.');
|
|
4593
|
-
}
|
|
4594
|
-
async setEncryptionSecret(options) {
|
|
4595
|
-
console.log(`${JSON.stringify(options)}`);
|
|
4596
|
-
throw new Error('Method not implemented.');
|
|
4597
|
-
}
|
|
4598
|
-
async changeEncryptionSecret(options) {
|
|
4599
|
-
console.log(`${JSON.stringify(options)}`);
|
|
4600
|
-
throw new Error('Method not implemented.');
|
|
4601
|
-
}
|
|
4602
|
-
async clearEncryptionSecret() {
|
|
4603
|
-
console.log('clearEncryptionSecret');
|
|
4604
|
-
throw new Error('Method not implemented.');
|
|
4605
|
-
}
|
|
4606
4706
|
async checkEncryptionSecret(options) {
|
|
4607
4707
|
console.log('checkEncryptionSecret', options);
|
|
4608
4708
|
throw new Error('Method not implemented.');
|