Socket
Socket
Sign inDemoInstall

react-sqlite-hook

Package Overview
Dependencies
24
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.0.1

12

CHANGELOG.md

@@ -1,3 +0,11 @@

## 2.0.0 (2021-03-20) REFACTOR
## 2.0.1 (2021-04-26) NEXT
### Added Features
- add `checkConnectionsConsistency` method
- add `import` & `export` JSON Listeners
- update README.md & APIHook.md
## 2.0.0 (2021-03-20) NEXT
## Chore

@@ -8,3 +16,3 @@

## 2.0.0-alpha.1 (2021-01-26) REFACTOR
## 2.0.0-alpha.1 (2021-01-26) NEXT

@@ -11,0 +19,0 @@ ## Chore

10

dist/package.json
{
"name": "react-sqlite-hook",
"version": "2.0.0-alpha.1",
"version": "2.0.0",
"description": "React Hook for @Capacitor-community/sqlite plugin",

@@ -46,8 +46,8 @@ "repository": {

"peerDependencies": {
"react": "^17.0.1",
"@capacitor-community/sqlite": "^3.0.0-beta.12",
"@capacitor/core": "^3.0.0-rc.0",
"@capacitor-community/sqlite": "^3.0.0-beta.7"
"react": "^17.0.1"
},
"devDependencies": {
"@capacitor-community/sqlite": "^3.0.0-beta.7",
"@capacitor-community/sqlite": "3.0.0-beta.12",
"@capacitor/core": "^3.0.0-rc.0",

@@ -70,3 +70,3 @@ "@capacitor/docgen": "0.0.14",

"tslint-ionic-rules": "0.0.21",
"typedoc": "^0.18.0",
"typedoc": "^0.20.36",
"typescript": "^4.0.5",

@@ -73,0 +73,0 @@ "uglify-js": "^3.2.0"

import { AvailableResult } from './util/models';
import { SQLiteDBConnection, capSQLiteChanges, capSQLiteValues } from '@capacitor-community/sqlite';
export { SQLiteDBConnection };
export declare type SQLiteProps = {
onProgressImport?: (progress: string) => void;
onProgressExport?: (progress: string) => void;
};
/**

@@ -123,2 +127,10 @@ * SQLite Hook Interface

copyFromAssets(): Promise<void>;
/**
* Check the consistency between Js Connections
* and Native Connections
* if inconsistency all connections are removed
* @returns Promise<Result>
* @since 2.0.1
*/
checkConnectionsConsistency(): Promise<Result>;
}

@@ -142,2 +154,2 @@ export interface MySet {

*/
export declare const useSQLite: () => SQLiteHook;
export declare const useSQLite: ({ onProgressImport, onProgressExport }: SQLiteProps) => SQLiteHook;

@@ -1,2 +0,2 @@

import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useEffect } from 'react';
import { Capacitor } from '@capacitor/core';

@@ -10,3 +10,3 @@ import { notAvailable } from './util/models';

*/
export const useSQLite = () => {
export const useSQLite = ({ onProgressImport, onProgressExport }) => {
const platform = Capacitor.getPlatform();

@@ -17,2 +17,23 @@ const sqlitePlugin = CapacitorSQLite;

}, [sqlitePlugin]);
useEffect(() => {
// init Listeners
let importListener = null;
let exportListener = null;
if (onProgressImport && sqlitePlugin)
importListener =
sqlitePlugin.addListener('sqliteImportProgressEvent', (e) => {
onProgressImport(e.progress);
});
if (onProgressExport && sqlitePlugin)
exportListener =
sqlitePlugin.addListener('sqliteExportProgressEvent', (e) => {
onProgressExport(e.progress);
});
return () => {
if (importListener)
importListener.remove();
if (exportListener)
exportListener.remove();
};
}, []);
const availableFeaturesN = {

@@ -309,4 +330,23 @@ useSQLite: isFeatureAvailable('CapacitorSQLite', 'useSQLite')

}, [mSQLite]);
/**
* Check the consistency between Js Connections
* and Native Connections
* if inconsistency all connections are removed
*/
const checkConnectionsConsistency = useCallback(async () => {
try {
const r = await mSQLite.checkConnectionsConsistency();
if (r) {
return Promise.resolve(r);
}
else {
return Promise.reject('Error Json Object not valid');
}
}
catch (err) {
return Promise.reject(err);
}
}, [mSQLite]);
if (!availableFeaturesN.useSQLite) {
return Object.assign({ echo: featureNotAvailableError, getPlatform: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError }, notAvailable);
return Object.assign({ echo: featureNotAvailableError, getPlatform: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError, checkConnectionsConsistency: featureNotAvailableError }, notAvailable);
}

@@ -318,5 +358,5 @@ else {

isConnection, isDatabase, getDatabaseList, addSQLiteSuffix,
deleteOldDatabases, isAvailable: true };
deleteOldDatabases, checkConnectionsConsistency, isAvailable: true };
}
};
//# sourceMappingURL=useSQLite.js.map

@@ -28,2 +28,3 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>

* [`copyFromAssets()`](#copyfromassets)
* [`checkConnectionsConsistency()`](#checkconnectionsconsistency)
* [Interfaces](#interfaces)

@@ -33,2 +34,4 @@

* [Listeners](#listeners)
## API Hook

@@ -317,2 +320,19 @@

### checkConnectionsConsistency()
```typescript
checkConnectionsConsistency() => Promise<Result>
```
Check the consistency between Js Connections
and Native Connections
if inconsistency all connections are removed
**Returns:** <code>Promise&lt;<a href="#result">Result</a>&gt;</code>
**Since:** 2.0.1
--------------------
### Interfaces

@@ -385,1 +405,13 @@

</docgen-api>
### Listeners
`Available since 2.0.1`
The listeners are attached to the plugin.
| Listener | Type | Description |
| -------------------- | ------------------ | ---------------------------------------------------------- |
| **onProgressImport** | {progress: string} | Emitted at different steps of the `importFromJson` process |
| **onProgressExport** | {progress: string} | Emitted at different steps of the `exportToJson` process |
{
"name": "react-sqlite-hook",
"version": "2.0.0",
"version": "2.0.1",
"description": "React Hook for @Capacitor-community/sqlite plugin",

@@ -46,8 +46,8 @@ "repository": {

"peerDependencies": {
"react": "^17.0.1",
"@capacitor-community/sqlite": "^3.0.0-beta.12",
"@capacitor/core": "^3.0.0-rc.0",
"@capacitor-community/sqlite": "^3.0.0-beta.7"
"react": "^17.0.1"
},
"devDependencies": {
"@capacitor-community/sqlite": "^3.0.0-beta.7",
"@capacitor-community/sqlite": "3.0.0-beta.12",
"@capacitor/core": "^3.0.0-rc.0",

@@ -70,3 +70,3 @@ "@capacitor/docgen": "0.0.14",

"tslint-ionic-rules": "0.0.21",
"typedoc": "^0.18.0",
"typedoc": "^0.20.36",
"typescript": "^4.0.5",

@@ -73,0 +73,0 @@ "uglify-js": "^3.2.0"

@@ -51,3 +51,33 @@ <p align="center"><br><img src="https://avatars3.githubusercontent.com/u/16580653?v=4" width="128" height="128" /></p>

```
## Supported methods
| Name | Android | iOS | Electron | Web |
| :-------------------------- | :------ | :-- | :------- | :-- |
| echo | ✅ | ✅ | 🚧 | ❌ |
| getPlatform | ✅ | ✅ | 🚧 | ❌ |
| addUpgradeStatement | ✅ | ✅ | 🚧 | ❌ |
| createConnection | ✅ | ✅ | 🚧 | ❌ |
| retrieveConnection | ✅ | ✅ | 🚧 | ❌ |
| retrieveAllConnections | ✅ | ✅ | 🚧 | ❌ |
| closeConnection | ✅ | ✅ | 🚧 | ❌ |
| closeAllConnections | ✅ | ✅ | 🚧 | ❌ |
| isConnection | ✅ | ✅ | 🚧 | ❌ |
| isDatabase | ✅ | ✅ | 🚧 | ❌ |
| getDatabaseList | ✅ | ✅ | 🚧 | ❌ |
| addSQLiteSuffix | ✅ | ✅ | 🚧 | ❌ |
| deleteOldDatabases | ✅ | ✅ | 🚧 | ❌ |
| importFromJson | ✅ | ✅ | 🚧 | ❌ |
| isJsonValid | ✅ | ✅ | 🚧 | ❌ |
| copyFromAssets | ✅ | ✅ | 🚧 | ❌ |
| checkConnectionsConsistency | ✅ | ✅ | 🚧 | ❌ |
## Supported listeners
| Name | Android | iOS | Electron | Web |
| :--------------- | :------ | :-- | :------- | :-- |
| onProgressImport | ✅ | ✅ | 🚧 | ❌ |
| onProgressExport | ✅ | ✅ | 🚧 | ❌ |
## Documentation

@@ -54,0 +84,0 @@

@@ -148,3 +148,3 @@

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -163,3 +163,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -177,3 +177,3 @@ await act(async () => {

});
const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -191,3 +191,3 @@ await act(async () => {

});
const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));
await act(async () => {

@@ -208,3 +208,3 @@ });

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -225,3 +225,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -242,3 +242,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -262,3 +262,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -289,3 +289,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -314,3 +314,3 @@ await act(async () => {

const r = renderHook(() => useSQLite());
const r = renderHook(() => useSQLite({}));

@@ -317,0 +317,0 @@ await act(async () => {

@@ -1,2 +0,2 @@

import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useEffect } from 'react';
import { Capacitor } from '@capacitor/core';

@@ -11,2 +11,6 @@ import { AvailableResult, notAvailable } from './util/models';

export type SQLiteProps = {
onProgressImport?: (progress: string) => void;
onProgressExport?: (progress: string) => void;
}
/**

@@ -134,3 +138,12 @@ * SQLite Hook Interface

copyFromAssets(): Promise<void>;
/**
* Check the consistency between Js Connections
* and Native Connections
* if inconsistency all connections are removed
* @returns Promise<Result>
* @since 2.0.1
*/
checkConnectionsConsistency(): Promise<Result>;
}

@@ -159,4 +172,6 @@

*/
export const useSQLite = (): SQLiteHook => {
export const useSQLite = ({
onProgressImport,
onProgressExport
}: SQLiteProps): SQLiteHook => {
const platform = Capacitor.getPlatform();

@@ -168,2 +183,21 @@ const sqlitePlugin: any = CapacitorSQLite;

useEffect(() => {
// init Listeners
let importListener: any = null;
let exportListener: any = null;
if(onProgressImport && sqlitePlugin) importListener =
sqlitePlugin.addListener('sqliteImportProgressEvent',
(e: any) => {
onProgressImport(e.progress);
});
if(onProgressExport && sqlitePlugin) exportListener =
sqlitePlugin.addListener('sqliteExportProgressEvent',
(e: any) => {
onProgressExport(e.progress);
});
return () => {
if(importListener) importListener.remove();
if(exportListener) exportListener.remove();
}
}, []);

@@ -454,3 +488,21 @@ const availableFeaturesN = {

}, [mSQLite]);
/**
* Check the consistency between Js Connections
* and Native Connections
* if inconsistency all connections are removed
*/
const checkConnectionsConsistency = useCallback(async () : Promise<Result> => {
try {
const r = await mSQLite.checkConnectionsConsistency();
if(r) {
return Promise.resolve(r);
} else {
return Promise.reject('Error Json Object not valid');
}
} catch (err) {
return Promise.reject(err);
}
}, [mSQLite]);
if (!availableFeaturesN.useSQLite) {

@@ -474,2 +526,3 @@ return {

deleteOldDatabases: featureNotAvailableError,
checkConnectionsConsistency: featureNotAvailableError,
...notAvailable

@@ -482,5 +535,5 @@ };

isConnection, isDatabase, getDatabaseList, addSQLiteSuffix,
deleteOldDatabases, isAvailable: true};
deleteOldDatabases, checkConnectionsConsistency, isAvailable: true};
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc