@fto-consult/expo-ui 8.20.3 → 8.20.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.20.3",
3
+ "version": "8.20.5",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "scripts": {
6
6
  "clear-npx-cache": "npx clear-npx-cache",
@@ -69,7 +69,7 @@
69
69
  "dependencies": {
70
70
  "@emotion/react": "^11.11.1",
71
71
  "@faker-js/faker": "^8.0.2",
72
- "@fto-consult/common": "^4.20.8",
72
+ "@fto-consult/common": "^4.21.0",
73
73
  "@fto-consult/node-utils": "^1.4.7",
74
74
  "apexcharts": "^3.45.2",
75
75
  "crypto-browserify": "^3.12.0",
@@ -0,0 +1,17 @@
1
+ // Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ import mobileNativePouchAdapter from "./native.adapter";
6
+ import 'react-native-get-random-values';
7
+ import PouchDB from "pouchdb";
8
+
9
+ const extra = {adapter : mobileNativePouchAdapter.adapter};
10
+ PouchDB
11
+ .plugin(mobileNativePouchAdapter)
12
+ export default {
13
+ PouchDB,
14
+ ...extra
15
+ }
16
+
17
+ export {PouchDB};
@@ -0,0 +1,48 @@
1
+ // Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ 'use strict'
6
+ import * as SQLite from 'expo-sqlite';
7
+ const WebSqlPouchCore = require('@craftzdog/pouchdb-adapter-websql-core').default
8
+ const adapter = 'mobile-native-sqlite';
9
+ function createOpenDBFunction (opts) {
10
+ return function (name, version, description, size) {
11
+ var openOpts = Object.assign({}, opts, {
12
+ name,
13
+ version: version,
14
+ description: description,
15
+ size: size
16
+ })
17
+ function onError (err) {
18
+ console.error(err)
19
+ if (typeof opts.onError === 'function') {
20
+ opts.onError(err)
21
+ }
22
+ }
23
+ return SQLite.openDatabase(openOpts.name, openOpts.version, openOpts.description, openOpts.size, null, onError)
24
+ }
25
+ }
26
+
27
+ function MobileNativeSQL (opts, callback) {
28
+ var websql = createOpenDBFunction(opts)
29
+ var _opts = Object.assign({
30
+ websql: websql
31
+ }, opts)
32
+ WebSqlPouchCore.call(this, _opts, callback)
33
+ }
34
+
35
+ MobileNativeSQL.valid = function () {
36
+ // if you're using ReactNative, we assume you know what you're doing because you control the environment
37
+ return true
38
+ }
39
+
40
+ // no need for a prefix in ReactNative (i.e. no need for `_pouch_` prefix
41
+ MobileNativeSQL.use_prefix = false
42
+
43
+ function mobileNativeQSLAdapter (PouchDB) {
44
+ PouchDB.adapter(adapter, MobileNativeSQL, true)
45
+ }
46
+
47
+ mobileNativeQSLAdapter.adapter = adapter;
48
+ export default mobileNativeQSLAdapter
@@ -34,23 +34,25 @@ export class SQLiteSession {
34
34
  }
35
35
  async init () {
36
36
  if (!this.db || !this.hasInit) {
37
- const dbName = this.getDBName();
38
- debug(`Opening sqlite database ${dbName} for session storage`);
39
37
  if(!this.openingPromise){
40
- this.openingPromise = SQLite.openDatabaseAsync(dbName).then((db)=>{
41
- return db.execAsync(`
42
- CREATE TABLE IF NOT EXISTS ${SESSION_TABLE} (id INTEGER PRIMARY KEY NOT NULL, key TEXT, value TEXT);
43
- `).then((d)=>{
44
- this.db = db;
45
- this.hasInit = true;
46
- this.getAll();
38
+ const dbName = this.getDBName();
39
+ debug(`Opening sqlite database ${dbName} for session storage`);
40
+ this.openingPromise = new Promise((resolve,reject)=>{
41
+ return SQLite.openDatabaseAsync(dbName).then((db)=>{
42
+ return db.execAsync(`CREATE TABLE IF NOT EXISTS ${SESSION_TABLE} (id INTEGER PRIMARY KEY NOT NULL, key TEXT, value TEXT);`).then((d)=>{
43
+ this.db = db;
44
+ this.hasInit = true;
45
+ return this.getAll().then((()=>{
46
+ resolve(db);
47
+ }));
48
+ })
47
49
  }).catch((e)=>{
48
- debug(e," error when initializing sqlite session");
49
- throw e;
50
- });
51
- }).finally(()=>{
52
- delete this.openingPromise;
53
- });;
50
+ debug(e," error when initializing sqlite session");
51
+ reject(e);
52
+ }).finally(()=>{
53
+ delete this.openingPromise;
54
+ });;
55
+ });
54
56
  }
55
57
  return this.openingPromise;
56
58
  }