react-sqlite-hook
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -0,1 +1,13 @@ | ||
## 3.2.0 (2023-03-09) | ||
### Chore | ||
- update to @capacitor/core@4.6.3 | ||
- update to @capacitor-community/sqlite@4.6.3-1 | ||
### Added Features | ||
- checkEncryptionSecret, moveDatabasesAndAddSuffix | ||
- isDatabaseEncrypted, isInConfigEncryption, isInConfigBiometricAuth | ||
## 3.1.1 (2022-09-25) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -49,8 +49,8 @@ "repository": { | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "^4.1.1", | ||
"@capacitor/core": "^4.1.0", | ||
"@capacitor-community/sqlite": "^4.6.3-1", | ||
"@capacitor/core": "^4.6.3", | ||
"@capacitor/docgen": "0.0.17", | ||
"@testing-library/react-hooks": "^7.0.2", | ||
"@types/jest": "^27.4.1", | ||
"@types/react-test-renderer": "^17.0.1", | ||
"@types/react-test-renderer": "^18.0.0", | ||
"conventional-changelog": "^3.1.25", | ||
@@ -57,0 +57,0 @@ "jest": "^27.5.1", |
@@ -113,2 +113,21 @@ import { AvailableResult } from './util/models'; | ||
/** | ||
* Check if a SQLite database is encrypted | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isDatabaseEncrypted(database: string): Promise<Result>; | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isInConfigEncryption(): Promise<Result>; | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isInConfigBiometricAuth(): Promise<Result>; | ||
/** | ||
* Get a Non-Conformed database path | ||
@@ -253,2 +272,17 @@ * @param databasePath | ||
clearEncryptionSecret(): Promise<void>; | ||
/** | ||
* Check encryption passphrase | ||
* | ||
* @param passphrase | ||
* @return Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
checkEncryptionSecret(passphrase: string): Promise<Result>; | ||
/** | ||
* Moves databases to the location the plugin can read them, and adds sqlite suffix | ||
* This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files | ||
* @param folderPath the origin from where to move the databases | ||
* @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension. | ||
*/ | ||
moveDatabasesAndAddSuffix(folderPath?: string, dbNameList?: string[]): Promise<void>; | ||
} | ||
@@ -255,0 +289,0 @@ export interface MySet { |
@@ -209,2 +209,65 @@ import { useCallback, useMemo, useEffect, useRef } from 'react'; | ||
/** | ||
* Check if a SQLite database is encrypted | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isDatabaseEncrypted = useCallback(async (dbName) => { | ||
if (dbName.length > 0) { | ||
try { | ||
const r = await mSQLite.isDatabaseEncrypted(dbName); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("Error in isDatabaseEncrypted"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Must provide a database name'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isInConfigEncryption = useCallback(async () => { | ||
try { | ||
const r = await mSQLite.isInConfigEncryption(); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("Error in isInConfigEncryption"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isInConfigBiometricAuth = useCallback(async () => { | ||
try { | ||
const r = await mSQLite.isInConfigBiometricAuth(); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("Error in isInConfigBiometricAuth"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Get the database list | ||
@@ -523,2 +586,23 @@ * @returns Promise<capSQLiteValues> | ||
/** | ||
* Check Encryption Secret | ||
* | ||
* @param passphrase | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const checkEncryptionSecret = useCallback(async (passphrase) => { | ||
try { | ||
const r = await mSQLite.checkEncryptionSecret(passphrase); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject('Error in checkEncryptionSecret'); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Get a Non-Conformed database path | ||
@@ -668,4 +752,21 @@ * @param databasePath | ||
}, [mSQLite]); | ||
/** | ||
* Moves databases to the location the plugin can read them, and adds sqlite suffix | ||
* This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files | ||
* @param folderPath the origin from where to move the databases | ||
* @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension. | ||
*/ | ||
const moveDatabasesAndAddSuffix = useCallback(async (folderPath, dbNameList) => { | ||
const path = folderPath ? folderPath : 'default'; | ||
const dbList = dbNameList ? dbNameList : []; | ||
try { | ||
await mSQLite.moveDatabasesAndAddSuffix(path, dbList); | ||
return Promise.resolve(); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
if (!availableFeaturesN.useSQLite) { | ||
return Object.assign({ initWebStore: featureNotAvailableError, saveToStore: featureNotAvailableError, echo: featureNotAvailableError, getPlatform: featureNotAvailableError, getCapacitorSQLite: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, getFromHTTPRequest: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getNCDatabasePath: featureNotAvailableError, createNCConnection: featureNotAvailableError, closeNCConnection: featureNotAvailableError, retrieveNCConnection: featureNotAvailableError, isNCConnection: featureNotAvailableError, isNCDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, getMigratableDbList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError, checkConnectionsConsistency: featureNotAvailableError, isSecretStored: featureNotAvailableError, setEncryptionSecret: featureNotAvailableError, changeEncryptionSecret: featureNotAvailableError, clearEncryptionSecret: featureNotAvailableError }, notAvailable); | ||
return Object.assign({ initWebStore: featureNotAvailableError, saveToStore: featureNotAvailableError, echo: featureNotAvailableError, getPlatform: featureNotAvailableError, getCapacitorSQLite: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, getFromHTTPRequest: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getNCDatabasePath: featureNotAvailableError, createNCConnection: featureNotAvailableError, closeNCConnection: featureNotAvailableError, retrieveNCConnection: featureNotAvailableError, isNCConnection: featureNotAvailableError, isNCDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, getMigratableDbList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError, checkConnectionsConsistency: featureNotAvailableError, isSecretStored: featureNotAvailableError, setEncryptionSecret: featureNotAvailableError, changeEncryptionSecret: featureNotAvailableError, clearEncryptionSecret: featureNotAvailableError, checkEncryptionSecret: featureNotAvailableError, moveDatabasesAndAddSuffix: featureNotAvailableError, isInConfigEncryption: featureNotAvailableError, isInConfigBiometricAuth: featureNotAvailableError, isDatabaseEncrypted: featureNotAvailableError }, notAvailable); | ||
} | ||
@@ -678,7 +779,9 @@ else { | ||
deleteOldDatabases, checkConnectionsConsistency, | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, clearEncryptionSecret, | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, | ||
clearEncryptionSecret, checkEncryptionSecret, moveDatabasesAndAddSuffix, | ||
initWebStore, saveToStore, getNCDatabasePath, createNCConnection, | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, isAvailable: true }; | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, | ||
isInConfigEncryption, isInConfigBiometricAuth, isDatabaseEncrypted, isAvailable: true }; | ||
} | ||
}; | ||
//# sourceMappingURL=useSQLite.js.map |
@@ -25,2 +25,5 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> | ||
* [`isDatabase(...)`](#isdatabase) | ||
* [`isDatabaseEncrypted(...)`](#isdatabaseencrypted) | ||
* [`isInConfigEncryption()`](#isinconfigencryption) | ||
* [`isInConfigBiometricAuth()`](#isinconfigbiometricauth) | ||
* [`getNCDatabasePath(...)`](#getncdatabasepath) | ||
@@ -39,2 +42,3 @@ * [`createNCConnection(...)`](#createncconnection) | ||
* [`copyFromAssets(...)`](#copyfromassets) | ||
* [`getFromHTTPRequest(...)`](#getfromhttprequest) | ||
* [`checkConnectionsConsistency()`](#checkconnectionsconsistency) | ||
@@ -44,2 +48,5 @@ * [`isSecretStored()`](#issecretstored) | ||
* [`changeEncryptionSecret(...)`](#changeencryptionsecret) | ||
* [`clearEncryptionSecret()`](#clearencryptionsecret) | ||
* [`checkEncryptionSecret(...)`](#checkencryptionsecret) | ||
* [`moveDatabasesAndAddSuffix(...)`](#movedatabasesandaddsuffix) | ||
* [Interfaces](#interfaces) | ||
@@ -145,6 +152,6 @@ | ||
| Param | Type | Description | | ||
| ------------- | --------------------------------------------------------- | ----------------- | | ||
| **`dbName`** | <code>string</code> | database name | | ||
| **`upgrade`** | <code><a href="#versionupgrade">VersionUpgrade</a></code> | upgrade statement | | ||
| Param | Type | Description | | ||
| ------------- | --------------------------------------------------------- | -------------------------------------- | | ||
| **`dbName`** | <code>string</code> | database name | | ||
| **`upgrade`** | <code><a href="#versionupgrade">VersionUpgrade</a></code> | upgrade statement modified since 3.0.1 | | ||
@@ -159,3 +166,3 @@ **Since:** 2.0.0 | ||
```typescript | ||
createConnection(database: string, encrypted?: boolean | undefined, mode?: string | undefined, version?: number | undefined) => Promise<SQLiteDBConnection> | ||
createConnection(database: string, encrypted?: boolean | undefined, mode?: string | undefined, version?: number | undefined, readonly?: boolean | undefined) => Promise<SQLiteDBConnection> | ||
``` | ||
@@ -165,8 +172,9 @@ | ||
| Param | Type | | ||
| --------------- | -------------------- | | ||
| **`database`** | <code>string</code> | | ||
| **`encrypted`** | <code>boolean</code> | | ||
| **`mode`** | <code>string</code> | | ||
| **`version`** | <code>number</code> | | ||
| Param | Type | Description | | ||
| --------------- | -------------------- | ----------- | | ||
| **`database`** | <code>string</code> | | | ||
| **`encrypted`** | <code>boolean</code> | | | ||
| **`mode`** | <code>string</code> | | | ||
| **`version`** | <code>number</code> | | | ||
| **`readonly`** | <code>boolean</code> | since 3.0.1 | | ||
@@ -183,3 +191,3 @@ **Returns:** <code>Promise<SQLiteDBConnection></code> | ||
```typescript | ||
retrieveConnection(database: string) => Promise<SQLiteDBConnection> | ||
retrieveConnection(database: string, readonly?: boolean | undefined) => Promise<SQLiteDBConnection> | ||
``` | ||
@@ -189,5 +197,6 @@ | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
| Param | Type | Description | | ||
| -------------- | -------------------- | ----------- | | ||
| **`database`** | <code>string</code> | | | ||
| **`readonly`** | <code>boolean</code> | since 3.0.1 | | ||
@@ -219,3 +228,3 @@ **Returns:** <code>Promise<SQLiteDBConnection></code> | ||
```typescript | ||
closeConnection(database: string) => Promise<void> | ||
closeConnection(database: string, readonly?: boolean | undefined) => Promise<void> | ||
``` | ||
@@ -225,5 +234,6 @@ | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
| Param | Type | Description | | ||
| -------------- | -------------------- | ----------- | | ||
| **`database`** | <code>string</code> | | | ||
| **`readonly`** | <code>boolean</code> | since 3.0.1 | | ||
@@ -251,3 +261,3 @@ **Since:** 2.0.0 | ||
```typescript | ||
isConnection(database: string) => Promise<Result> | ||
isConnection(database: string, readonly?: boolean | undefined) => Promise<Result> | ||
``` | ||
@@ -257,5 +267,6 @@ | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
| Param | Type | Description | | ||
| -------------- | -------------------- | ----------- | | ||
| **`database`** | <code>string</code> | | | ||
| **`readonly`** | <code>boolean</code> | since 3.0.1 | | ||
@@ -288,2 +299,51 @@ **Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
### isDatabaseEncrypted(...) | ||
```typescript | ||
isDatabaseEncrypted(database: string) => Promise<Result> | ||
``` | ||
Check if a SQLite database is encrypted | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.2.0 | ||
-------------------- | ||
### isInConfigEncryption() | ||
```typescript | ||
isInConfigEncryption() => Promise<Result> | ||
``` | ||
Check encryption value in capacitor.config | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.2.0 | ||
-------------------- | ||
### isInConfigBiometricAuth() | ||
```typescript | ||
isInConfigBiometricAuth() => Promise<Result> | ||
``` | ||
Check encryption value in capacitor.config | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.2.0 | ||
-------------------- | ||
### getNCDatabasePath(...) | ||
@@ -304,3 +364,3 @@ | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -325,3 +385,3 @@ -------------------- | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -345,3 +405,3 @@ -------------------- | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -363,3 +423,3 @@ -------------------- | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -383,3 +443,3 @@ -------------------- | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -403,3 +463,3 @@ -------------------- | ||
**Since:** 3.3.3-1 | ||
**Since:** 2.1.4 | ||
@@ -525,5 +585,5 @@ -------------------- | ||
| Param | Type | | ||
| --------------- | -------------------- | | ||
| **`overwrite`** | <code>boolean</code> | | ||
| Param | Type | Description | | ||
| --------------- | -------------------- | ----------- | | ||
| **`overwrite`** | <code>boolean</code> | boolean | | ||
@@ -535,2 +595,20 @@ **Since:** 2.0.0 | ||
### getFromHTTPRequest(...) | ||
```typescript | ||
getFromHTTPRequest(url: string, overwrite?: boolean | undefined) => Promise<void> | ||
``` | ||
Get databases from HTTP request to application database folder | ||
| Param | Type | Description | | ||
| --------------- | -------------------- | ----------- | | ||
| **`url`** | <code>string</code> | string | | ||
| **`overwrite`** | <code>boolean</code> | boolean | | ||
**Since:** 3.0.2 | ||
-------------------- | ||
### checkConnectionsConsistency() | ||
@@ -606,23 +684,62 @@ | ||
### Interfaces | ||
### clearEncryptionSecret() | ||
```typescript | ||
clearEncryptionSecret() => Promise<void> | ||
``` | ||
#### VersionUpgrade | ||
Clear the encrypted secret from secure storage | ||
| Prop | Type | | ||
| ----------------- | -------------------- | | ||
| **`fromVersion`** | <code>number</code> | | ||
| **`toVersion`** | <code>number</code> | | ||
| **`statement`** | <code>string</code> | | ||
| **`set`** | <code>MySet[]</code> | | ||
**Since:** 3.0.0 | ||
-------------------- | ||
#### MySet | ||
| Prop | Type | | ||
| --------------- | ------------------- | | ||
| **`statement`** | <code>string</code> | | ||
| **`values`** | <code>any[]</code> | | ||
### checkEncryptionSecret(...) | ||
```typescript | ||
checkEncryptionSecret(passphrase: string) => Promise<Result> | ||
``` | ||
Check encryption passphrase | ||
| Param | Type | | ||
| ---------------- | ------------------- | | ||
| **`passphrase`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.2.0 | ||
-------------------- | ||
### moveDatabasesAndAddSuffix(...) | ||
```typescript | ||
moveDatabasesAndAddSuffix(folderPath?: string | undefined, dbNameList?: string[] | undefined) => Promise<void> | ||
``` | ||
Moves databases to the location the plugin can read them, and adds sqlite suffix | ||
This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files | ||
| Param | Type | Description | | ||
| ---------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| **`folderPath`** | <code>string</code> | the origin from where to move the databases | | ||
| **`dbNameList`** | <code>string[]</code> | the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension. | | ||
-------------------- | ||
### Interfaces | ||
#### VersionUpgrade | ||
| Prop | Type | | ||
| ---------------- | --------------------- | | ||
| **`toVersion`** | <code>number</code> | | ||
| **`statements`** | <code>string[]</code> | | ||
#### Map | ||
@@ -661,5 +778,5 @@ | ||
| Prop | Type | Description | | ||
| ------------ | ------------------ | -------------------------------- | | ||
| **`values`** | <code>any[]</code> | the data values list as an Array | | ||
| Prop | Type | Description | | ||
| ------------ | ------------------ | ---------------------------------------------------------------------------------------- | | ||
| **`values`** | <code>any[]</code> | the data values list as an Array iOS the first row is the returned ios_columns name list | | ||
@@ -666,0 +783,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -49,8 +49,8 @@ "repository": { | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "^4.1.1", | ||
"@capacitor/core": "^4.1.0", | ||
"@capacitor-community/sqlite": "^4.6.3-1", | ||
"@capacitor/core": "^4.6.3", | ||
"@capacitor/docgen": "0.0.17", | ||
"@testing-library/react-hooks": "^7.0.2", | ||
"@types/jest": "^27.4.1", | ||
"@types/react-test-renderer": "^17.0.1", | ||
"@types/react-test-renderer": "^18.0.0", | ||
"conventional-changelog": "^3.1.25", | ||
@@ -57,0 +57,0 @@ "jest": "^27.5.1", |
@@ -122,2 +122,22 @@ import { useCallback, useMemo, useEffect, useRef } from 'react'; | ||
/** | ||
* Check if a SQLite database is encrypted | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isDatabaseEncrypted(database: string): Promise<Result>; | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isInConfigEncryption(): Promise<Result>; | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
isInConfigBiometricAuth(): Promise<Result>; | ||
/** | ||
* Get a Non-Conformed database path | ||
@@ -263,2 +283,17 @@ * @param databasePath | ||
clearEncryptionSecret(): Promise<void>; | ||
/** | ||
* Check encryption passphrase | ||
* | ||
* @param passphrase | ||
* @return Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
checkEncryptionSecret(passphrase: string): Promise<Result>; | ||
/** | ||
* Moves databases to the location the plugin can read them, and adds sqlite suffix | ||
* This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files | ||
* @param folderPath the origin from where to move the databases | ||
* @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension. | ||
*/ | ||
moveDatabasesAndAddSuffix(folderPath?: string, dbNameList?: string[],): Promise<void>; | ||
@@ -489,2 +524,62 @@ } | ||
/** | ||
* Check if a SQLite database is encrypted | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isDatabaseEncrypted = useCallback(async (dbName: string): Promise<Result> => { | ||
if(dbName.length > 0) { | ||
try { | ||
const r = await mSQLite.isDatabaseEncrypted(dbName); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("Error in isDatabaseEncrypted"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else { | ||
return Promise.reject('Must provide a database name'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isInConfigEncryption = useCallback(async (): Promise<Result> => { | ||
try { | ||
const r = await mSQLite.isInConfigEncryption(); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("Error in isInConfigEncryption"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check encryption value in capacitor.config | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const isInConfigBiometricAuth = useCallback(async (): Promise<Result> => { | ||
try { | ||
const r = await mSQLite.isInConfigBiometricAuth(); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("Error in isInConfigBiometricAuth"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Get the database list | ||
@@ -793,2 +888,22 @@ * @returns Promise<capSQLiteValues> | ||
/** | ||
* Check Encryption Secret | ||
* | ||
* @param passphrase | ||
* @returns Promise<Result> | ||
* @since 3.2.0 | ||
*/ | ||
const checkEncryptionSecret = useCallback( async(passphrase: string): Promise<Result> => { | ||
try { | ||
const r = await mSQLite.checkEncryptionSecret(passphrase); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject('Error in checkEncryptionSecret'); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Get a Non-Conformed database path | ||
@@ -931,2 +1046,20 @@ * @param databasePath | ||
}, [mSQLite]); | ||
/** | ||
* Moves databases to the location the plugin can read them, and adds sqlite suffix | ||
* This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files | ||
* @param folderPath the origin from where to move the databases | ||
* @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension. | ||
*/ | ||
const moveDatabasesAndAddSuffix = useCallback(async (folderPath?: string, dbNameList?: string[],): Promise<void> => { | ||
const path: string = folderPath ? folderPath : 'default'; | ||
const dbList: string[] = dbNameList ? dbNameList : []; | ||
try { | ||
await mSQLite.moveDatabasesAndAddSuffix(path, dbList); | ||
return Promise.resolve(); | ||
} catch(err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
if (!availableFeaturesN.useSQLite) { | ||
@@ -961,7 +1094,12 @@ return { | ||
deleteOldDatabases: featureNotAvailableError, | ||
checkConnectionsConsistency: featureNotAvailableError, | ||
checkConnectionsConsistency: featureNotAvailableError, | ||
isSecretStored: featureNotAvailableError, | ||
setEncryptionSecret: featureNotAvailableError, | ||
changeEncryptionSecret: featureNotAvailableError, | ||
clearEncryptionSecret: featureNotAvailableError, | ||
clearEncryptionSecret: featureNotAvailableError, | ||
checkEncryptionSecret: featureNotAvailableError, | ||
moveDatabasesAndAddSuffix: featureNotAvailableError, | ||
isInConfigEncryption: featureNotAvailableError, | ||
isInConfigBiometricAuth: featureNotAvailableError, | ||
isDatabaseEncrypted: featureNotAvailableError, | ||
...notAvailable | ||
@@ -975,7 +1113,9 @@ }; | ||
deleteOldDatabases, checkConnectionsConsistency, | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, clearEncryptionSecret, | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, | ||
clearEncryptionSecret, checkEncryptionSecret, moveDatabasesAndAddSuffix, | ||
initWebStore, saveToStore, getNCDatabasePath, createNCConnection, | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, isAvailable: true}; | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, | ||
isInConfigEncryption, isInConfigBiometricAuth, isDatabaseEncrypted, isAvailable: true}; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
150144
2608