@flumens/models 0.3.1 → 0.4.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.
@@ -21,6 +21,7 @@ export default class SQLiteDatabase {
21
21
  constructor({ name, debug, web }: SQLiteDatabaseOptions);
22
22
  init(): Promise<void>;
23
23
  query<T>({ sql, params }: Query): Promise<T[]>;
24
- getUrl(): Promise<string | undefined>;
24
+ export(): Promise<Blob>;
25
+ import(blob: Blob): Promise<void>;
25
26
  }
26
27
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("jeep-sqlite/loader"),n=require("@capacitor-community/sqlite");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=i(require("@flumens/utils/dist/deferred")),s=function(){function i(e){var t=e.name,i=e.debug,s=e.web;this.sqliteConnection=new n.SQLiteConnection(n.CapacitorSQLite),this.name="main",this.debug=!1,this.isWeb=!1,this.ready=new r.default,this.name=t||this.name,this.debug=i||this.debug,this.isWeb=s||this.isWeb}return i.migrateCordova=function(t){var i;return e.__awaiter(this,void 0,void 0,(function(){var r,s,o;return e.__generator(this,(function(e){switch(e.label){case 0:console.log("SQLite: Cordova db migration"),r=new n.SQLiteConnection(n.CapacitorSQLite),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,r.getMigratableDbList(t?"Library/LocalDatabase":void 0)];case 2:return s=e.sent(),(null===(i=s.values)||void 0===i?void 0:i.length)?(console.log("SQLite: migrating",s.values),[4,r.addSQLiteSuffix(t?"Library/LocalDatabase":void 0,s.values)]):(console.log("SQLite: no Cordova db to migrate"),[2]);case 3:return e.sent(),[4,r.deleteOldDatabases(t?"Library/LocalDatabase":void 0,s.values)];case 4:return e.sent(),console.log("SQLite: migrating done",s.values),[3,6];case 5:return o=e.sent(),console.error(o),[3,6];case 6:return[4,r.checkConnectionsConsistency()];case 7:return e.sent(),[4,r.closeAllConnections()];case 8:return e.sent(),[2]}}))}))},Object.defineProperty(i.prototype,"db",{get:function(){return this.connection},enumerable:!1,configurable:!0}),i.prototype.init=function(){return e.__awaiter(this,void 0,void 0,(function(){var n,i;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isWeb?(t.defineCustomElements(window),(n=document.createElement("jeep-sqlite")).setAttribute("autoSave","true"),document.body.appendChild(n),[4,customElements.whenDefined("jeep-sqlite")]):[3,3];case 1:return e.sent(),[4,this.sqliteConnection.initWebStore()];case 2:e.sent(),e.label=3;case 3:return[4,this.sqliteConnection.checkConnectionsConsistency()];case 4:return e.sent(),[4,this.sqliteConnection.closeAllConnections()];case 5:return e.sent(),i=this,[4,this.sqliteConnection.createConnection(this.name,!1,"no-encryption",1,!1)];case 6:return i.connection=e.sent(),[4,this.connection.open()];case 7:return e.sent(),this.ready.resolve(!0),[2]}}))}))},i.prototype.query=function(t){var n,i=t.sql,r=t.params;return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.db.query(i,r).then((function(e){return e.values||[]}))];case 2:return t=e.sent(),this.debug?(console.groupCollapsed("💾 SQL: ".concat(i.trimStart().replaceAll(/\n/g," ").replaceAll(/\s+/g," ").substring(0,30),"...")),console.debug(i,r,t),console.groupEnd(),[4,null===(n=this.sqliteConnection)||void 0===n?void 0:n.saveToStore(this.name)]):[3,4];case 3:e.sent(),e.label=4;case 4:return[2,t]}}))}))},i.prototype.getUrl=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return this.isWeb?[2,""]:[4,this.db.getUrl()];case 1:return[2,e.sent().url]}}))}))},i}();exports.default=s;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("jeep-sqlite/loader"),n=require("@capacitor-community/sqlite"),r=require("@capacitor/core"),i=require("@capacitor/filesystem");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(require("@flumens/utils/dist/deferred")),a=function(){function s(e){var t=e.name,r=e.debug,i=e.web;this.sqliteConnection=new n.SQLiteConnection(n.CapacitorSQLite),this.name="main",this.debug=!1,this.isWeb=!1,this.ready=new o.default,this.name=t||this.name,this.debug=r||this.debug,this.isWeb=i||this.isWeb}return s.migrateCordova=function(t){var r;return e.__awaiter(this,void 0,void 0,(function(){var i,s,o;return e.__generator(this,(function(e){switch(e.label){case 0:console.log("SQLite: Cordova db migration"),i=new n.SQLiteConnection(n.CapacitorSQLite),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,i.getMigratableDbList(t?"Library/LocalDatabase":void 0)];case 2:return s=e.sent(),(null===(r=s.values)||void 0===r?void 0:r.length)?(console.log("SQLite: migrating",s.values),[4,i.addSQLiteSuffix(t?"Library/LocalDatabase":void 0,s.values)]):(console.log("SQLite: no Cordova db to migrate"),[2]);case 3:return e.sent(),[4,i.deleteOldDatabases(t?"Library/LocalDatabase":void 0,s.values)];case 4:return e.sent(),console.log("SQLite: migrating done",s.values),[3,6];case 5:return o=e.sent(),console.error(o),[3,6];case 6:return[4,i.checkConnectionsConsistency()];case 7:return e.sent(),[4,i.closeAllConnections()];case 8:return e.sent(),[2]}}))}))},Object.defineProperty(s.prototype,"db",{get:function(){return this.connection},enumerable:!1,configurable:!0}),s.prototype.init=function(){return e.__awaiter(this,void 0,void 0,(function(){var n,r;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isWeb?(t.defineCustomElements(window),(n=document.createElement("jeep-sqlite")).setAttribute("autoSave","true"),document.body.appendChild(n),[4,customElements.whenDefined("jeep-sqlite")]):[3,3];case 1:return e.sent(),[4,this.sqliteConnection.initWebStore()];case 2:e.sent(),e.label=3;case 3:return[4,this.sqliteConnection.checkConnectionsConsistency()];case 4:return e.sent(),[4,this.sqliteConnection.closeAllConnections()];case 5:return e.sent(),r=this,[4,this.sqliteConnection.createConnection(this.name,!1,"no-encryption",1,!1)];case 6:return r.connection=e.sent(),[4,this.connection.open()];case 7:return e.sent(),this.ready.resolve(!0),[2]}}))}))},s.prototype.query=function(t){var n,r=t.sql,i=t.params;return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.db.query(r,i).then((function(e){return e.values||[]}))];case 2:return t=e.sent(),this.debug?(console.groupCollapsed("💾 SQL: ".concat(r.trimStart().replaceAll(/\n/g," ").replaceAll(/\s+/g," ").substring(0,30),"...")),console.debug(r,i,t),console.groupEnd(),[4,null===(n=this.sqliteConnection)||void 0===n?void 0:n.saveToStore(this.name)]):[3,4];case 3:e.sent(),e.label=4;case 4:return[2,t]}}))}))},s.prototype.export=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,n;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isWeb?(t=this.name,[2,new Promise((function(e){indexedDB.open("jeepSqliteStore").onsuccess=function(n){n.target.result.transaction(["databases"],"readwrite").objectStore("databases").get("".concat(t,"SQLite.db")).onsuccess=function(t){var n=new Blob([t.target.result],{type:"application/vnd.sqlite3"});e(n)}}}))]):[4,this.db.getUrl()];case 1:return n=e.sent().url,[4,fetch(r.Capacitor.convertFileSrc(n))];case 2:return[2,e.sent().blob()]}}))}))},s.prototype.import=function(t){return e.__awaiter(this,void 0,void 0,(function(){var n,r,s,o,a;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isWeb?(r=Uint8Array.bind,[4,t.arrayBuffer()]):[3,2];case 1:return n=new(r.apply(Uint8Array,[void 0,e.sent()])),s=this.name,new Promise((function(e){indexedDB.open("jeepSqliteStore").onsuccess=function(t){t.target.result.transaction(["databases"],"readwrite").objectStore("databases").put(n,"".concat(s,"SQLite.db"),0).onsuccess=function(){return e()}}})),[2];case 2:return[4,this.db.getUrl()];case 3:return o=e.sent().url,[4,new Promise((function(e){var n=new FileReader;n.onload=e,n.readAsDataURL(t)})).then((function(e){return e.target.result}))];case 4:return a=e.sent(),[4,i.Filesystem.writeFile({path:o,data:a})];case 5:return e.sent(),[2]}}))}))},s}();exports.default=a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flumens/models",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "scripts": {
@@ -34,7 +34,9 @@
34
34
  "@flumens/utils": "*"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@capacitor-community/sqlite": "^6.0.2",
37
+ "@capacitor/core": "^6",
38
+ "@capacitor/filesystem": "^6",
39
+ "@capacitor-community/sqlite": "^6",
38
40
  "deep-diff": "^1",
39
41
  "drizzle-orm": "^0.34.1",
40
42
  "jeep-sqlite": "^2.8.0",