@flumens/models 0.6.0 → 0.7.1
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/dist/Collection.js +1 -108
- package/dist/Drupal/User.d.ts +6 -6
- package/dist/Drupal/User.js +1 -433
- package/dist/Indicia/ElasticOccurrence.d.ts +5 -0
- package/dist/Indicia/ElasticOccurrence.js +1 -0
- package/dist/Indicia/ElasticSample.d.ts +11 -0
- package/dist/Indicia/ElasticSample.js +1 -0
- package/dist/Indicia/Media.d.ts +5 -7
- package/dist/Indicia/Media.js +1 -369
- package/dist/Indicia/Occurrence.d.ts +30 -8
- package/dist/Indicia/Occurrence.js +1 -220
- package/dist/Indicia/Sample.d.ts +54 -11
- package/dist/Indicia/Sample.js +1 -687
- package/dist/Indicia/SampleCollection.d.ts +12 -4
- package/dist/Indicia/SampleCollection.js +1 -77
- package/dist/Indicia/helpers.d.ts +9 -0
- package/dist/Indicia/helpers.js +1 -120
- package/dist/Model.d.ts +10 -9
- package/dist/Model.js +1 -191
- package/dist/Stores/LocalForageStore.js +1 -228
- package/dist/Stores/SQLiteDatabase.js +1 -221
- package/dist/Stores/SQLiteStore.js +1 -310
- package/dist/Stores/Store.js +1 -11
- package/dist/Stores/utils.js +1 -60
- package/dist/index.js +1 -29
- package/package.json +5 -2
|
@@ -1,228 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tslib = require('tslib');
|
|
6
|
-
var LocalForage = require('localforage');
|
|
7
|
-
var CordovaSQLiteDriver = require('localforage-cordovasqlitedriver');
|
|
8
|
-
var utils = require('@flumens/utils');
|
|
9
|
-
var utils$1 = require('./utils.js');
|
|
10
|
-
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var LocalForage__default = /*#__PURE__*/_interopDefaultLegacy(LocalForage);
|
|
14
|
-
var CordovaSQLiteDriver__default = /*#__PURE__*/_interopDefaultLegacy(CordovaSQLiteDriver);
|
|
15
|
-
|
|
16
|
-
var defaultDriverOrder = ['indexeddb', 'websql', 'localstorage'];
|
|
17
|
-
if (utils.isPlatform('hybrid')) {
|
|
18
|
-
if (!window.sqlitePlugin) {
|
|
19
|
-
throw new Error('cordova-sql-storage plugin is missing. Please install it.');
|
|
20
|
-
}
|
|
21
|
-
defaultDriverOrder = tslib.__spreadArray([CordovaSQLiteDriver__default["default"]], defaultDriverOrder, true);
|
|
22
|
-
}
|
|
23
|
-
// create local store
|
|
24
|
-
var defaultConfig = {
|
|
25
|
-
driverOrder: defaultDriverOrder,
|
|
26
|
-
};
|
|
27
|
-
var LocalForageStore = /** @class */ (function () {
|
|
28
|
-
function LocalForageStore(options) {
|
|
29
|
-
var _this = this;
|
|
30
|
-
var config = tslib.__assign(tslib.__assign({}, defaultConfig), options);
|
|
31
|
-
this.debugging = config.debugging;
|
|
32
|
-
// initialize db
|
|
33
|
-
this.localForage = null;
|
|
34
|
-
this.ready = new Promise(function (resolve, reject) {
|
|
35
|
-
// check custom drivers (eg. SQLite)
|
|
36
|
-
var customDriversPromise = new Promise(function (_resolve) {
|
|
37
|
-
if (config.driverOrder && typeof config.driverOrder[0] === 'object') {
|
|
38
|
-
LocalForage__default["default"].defineDriver(config.driverOrder[0]).then(_resolve);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
_resolve(undefined);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
if (!config.storeName) {
|
|
45
|
-
throw new Error('storeName prop is missing');
|
|
46
|
-
}
|
|
47
|
-
_this.storeName = config.storeName;
|
|
48
|
-
// config
|
|
49
|
-
customDriversPromise.then(function () {
|
|
50
|
-
var dbConfig = {
|
|
51
|
-
name: config.name || 'indicia',
|
|
52
|
-
storeName: config.storeName,
|
|
53
|
-
};
|
|
54
|
-
if (config.version) {
|
|
55
|
-
dbConfig.version = config.version;
|
|
56
|
-
}
|
|
57
|
-
var drivers = LocalForageStore._getDriverOrder(config.driverOrder);
|
|
58
|
-
var DB = config.LocalForage || LocalForage__default["default"];
|
|
59
|
-
// init
|
|
60
|
-
_this.localForage = DB.createInstance(dbConfig);
|
|
61
|
-
_this.localForage.setDriver(drivers).then(resolve).catch(reject);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
LocalForageStore._getDriverOrder = function (driverOrder) {
|
|
66
|
-
return driverOrder.map(function (driver) {
|
|
67
|
-
switch (driver) {
|
|
68
|
-
case 'indexeddb':
|
|
69
|
-
return LocalForage__default["default"].INDEXEDDB;
|
|
70
|
-
case 'websql':
|
|
71
|
-
return LocalForage__default["default"].WEBSQL;
|
|
72
|
-
case 'localstorage':
|
|
73
|
-
return LocalForage__default["default"].LOCALSTORAGE;
|
|
74
|
-
default:
|
|
75
|
-
// custom
|
|
76
|
-
if (typeof driver === 'object' && driver._driver) {
|
|
77
|
-
return driver._driver;
|
|
78
|
-
}
|
|
79
|
-
return console.error('No such db driver!');
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
LocalForageStore.prototype.save = function (val) {
|
|
84
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var currentVal;
|
|
86
|
-
return tslib.__generator(this, function (_a) {
|
|
87
|
-
switch (_a.label) {
|
|
88
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.sent();
|
|
91
|
-
if (!val.cid) {
|
|
92
|
-
throw new Error('Invalid key passed to store');
|
|
93
|
-
}
|
|
94
|
-
if (!this.debugging) return [3 /*break*/, 3];
|
|
95
|
-
return [4 /*yield*/, this.find(val.cid)];
|
|
96
|
-
case 2:
|
|
97
|
-
currentVal = _a.sent();
|
|
98
|
-
utils$1.printDiff(currentVal, val, val.cid, this.storeName);
|
|
99
|
-
_a.label = 3;
|
|
100
|
-
case 3: return [2 /*return*/, this.localForage.setItem(val.cid, val)];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
LocalForageStore.prototype.find = function (key) {
|
|
106
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
107
|
-
return tslib.__generator(this, function (_a) {
|
|
108
|
-
switch (_a.label) {
|
|
109
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
110
|
-
case 1:
|
|
111
|
-
_a.sent();
|
|
112
|
-
if (!key) {
|
|
113
|
-
throw new Error('Invalid key passed to store');
|
|
114
|
-
}
|
|
115
|
-
return [2 /*return*/, this.localForage.getItem(key)];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
LocalForageStore.prototype.findAll = function () {
|
|
121
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
122
|
-
var models;
|
|
123
|
-
return tslib.__generator(this, function (_a) {
|
|
124
|
-
switch (_a.label) {
|
|
125
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
126
|
-
case 1:
|
|
127
|
-
_a.sent();
|
|
128
|
-
models = [];
|
|
129
|
-
return [4 /*yield*/, this.localForage.iterate(function (value) {
|
|
130
|
-
models.push(value);
|
|
131
|
-
})];
|
|
132
|
-
case 2:
|
|
133
|
-
_a.sent();
|
|
134
|
-
return [2 /*return*/, models];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
LocalForageStore.prototype.delete = function (key) {
|
|
140
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
141
|
-
return tslib.__generator(this, function (_a) {
|
|
142
|
-
switch (_a.label) {
|
|
143
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
144
|
-
case 1:
|
|
145
|
-
_a.sent();
|
|
146
|
-
if (!key) {
|
|
147
|
-
throw new Error('Invalid key passed to store');
|
|
148
|
-
}
|
|
149
|
-
return [2 /*return*/, this.localForage.removeItem(key)];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
LocalForageStore.prototype.deleteAll = function () {
|
|
155
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
156
|
-
var models;
|
|
157
|
-
var _this = this;
|
|
158
|
-
return tslib.__generator(this, function (_a) {
|
|
159
|
-
switch (_a.label) {
|
|
160
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
161
|
-
case 1:
|
|
162
|
-
_a.sent();
|
|
163
|
-
return [4 /*yield*/, this.findAll()];
|
|
164
|
-
case 2:
|
|
165
|
-
models = _a.sent();
|
|
166
|
-
return [4 /*yield*/, Promise.all(models.map(function (model) { return _this.delete(model); }))];
|
|
167
|
-
case 3:
|
|
168
|
-
_a.sent();
|
|
169
|
-
return [2 /*return*/];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Exports all objects from the store.
|
|
176
|
-
*/
|
|
177
|
-
LocalForageStore.prototype.export = function () {
|
|
178
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
179
|
-
var addCIDs;
|
|
180
|
-
return tslib.__generator(this, function (_a) {
|
|
181
|
-
switch (_a.label) {
|
|
182
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
183
|
-
case 1:
|
|
184
|
-
_a.sent();
|
|
185
|
-
addCIDs = function (agg, val) {
|
|
186
|
-
var _a;
|
|
187
|
-
return (tslib.__assign(tslib.__assign({}, agg), (_a = {}, _a[val.cid] = val, _a)));
|
|
188
|
-
};
|
|
189
|
-
return [4 /*yield*/, this.findAll()];
|
|
190
|
-
case 2: return [2 /*return*/, (_a.sent()).reduce(addCIDs, {})];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Imports objects to store.
|
|
197
|
-
*/
|
|
198
|
-
LocalForageStore.prototype.import = function (obj) {
|
|
199
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
200
|
-
var savingAll;
|
|
201
|
-
var _this = this;
|
|
202
|
-
return tslib.__generator(this, function (_a) {
|
|
203
|
-
switch (_a.label) {
|
|
204
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
205
|
-
case 1:
|
|
206
|
-
_a.sent();
|
|
207
|
-
return [4 /*yield*/, this.deleteAll()];
|
|
208
|
-
case 2:
|
|
209
|
-
_a.sent();
|
|
210
|
-
if (typeof obj !== 'object') {
|
|
211
|
-
throw new Error('Invalid obj passed to store');
|
|
212
|
-
}
|
|
213
|
-
savingAll = Object.entries(obj).map(function (_a) {
|
|
214
|
-
var val = _a[1];
|
|
215
|
-
return _this.save(val);
|
|
216
|
-
});
|
|
217
|
-
return [4 /*yield*/, Promise.all(savingAll)];
|
|
218
|
-
case 3:
|
|
219
|
-
_a.sent();
|
|
220
|
-
return [2 /*return*/];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
return LocalForageStore;
|
|
226
|
-
}());
|
|
227
|
-
|
|
228
|
-
exports["default"] = LocalForageStore;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("localforage"),t=require("localforage-cordovasqlitedriver"),i=require("@flumens/utils"),n=require("./utils.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(r),a=o(t),u=["indexeddb","websql","localstorage"];if(i.isPlatform("hybrid")){if(!window.sqlitePlugin)throw new Error("cordova-sql-storage plugin is missing. Please install it.");u=e.__spreadArray([a.default],u,!0)}var c={driverOrder:u},d=function(){function r(t){var i=this,n=e.__assign(e.__assign({},c),t);this.debugging=n.debugging,this.localForage=null,this.ready=new Promise((function(e,t){var o=new Promise((function(e){n.driverOrder&&"object"==typeof n.driverOrder[0]?s.default.defineDriver(n.driverOrder[0]).then(e):e(void 0)}));if(!n.storeName)throw new Error("storeName prop is missing");i.storeName=n.storeName,o.then((function(){var o={name:n.name||"indicia",storeName:n.storeName};n.version&&(o.version=n.version);var a=r._getDriverOrder(n.driverOrder),u=n.LocalForage||s.default;i.localForage=u.createInstance(o),i.localForage.setDriver(a).then(e).catch(t)}))}))}return r._getDriverOrder=function(e){return e.map((function(e){switch(e){case"indexeddb":return s.default.INDEXEDDB;case"websql":return s.default.WEBSQL;case"localstorage":return s.default.LOCALSTORAGE;default:return"object"==typeof e&&e._driver?e._driver:console.error("No such db driver!")}}))},r.prototype.save=function(r){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:if(e.sent(),!r.cid)throw new Error("Invalid key passed to store");return this.debugging?[4,this.find(r.cid)]:[3,3];case 2:t=e.sent(),n.printDiff(t,r,r.cid,this.storeName),e.label=3;case 3:return[2,this.localForage.setItem(r.cid,r)]}}))}))},r.prototype.find=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.getItem(r)]}}))}))},r.prototype.findAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),r=[],[4,this.localForage.iterate((function(e){r.push(e)}))];case 2:return e.sent(),[2,r]}}))}))},r.prototype.delete=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.removeItem(r)]}}))}))},r.prototype.deleteAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r,t=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.findAll()];case 2:return r=e.sent(),[4,Promise.all(r.map((function(e){return t.delete(e)})))];case 3:return e.sent(),[2]}}))}))},r.prototype.export=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.ready];case 1:return t.sent(),r=function(r,t){var i;return e.__assign(e.__assign({},r),((i={})[t.cid]=t,i))},[4,this.findAll()];case 2:return[2,t.sent().reduce(r,{})]}}))}))},r.prototype.import=function(r){return e.__awaiter(this,void 0,void 0,(function(){var t,i=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.deleteAll()];case 2:if(e.sent(),"object"!=typeof r)throw new Error("Invalid obj passed to store");return t=Object.entries(r).map((function(e){var r=e[1];return i.save(r)})),[4,Promise.all(t)];case 3:return e.sent(),[2]}}))}))},r}();exports.default=d;
|
|
@@ -1,221 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tslib = require('tslib');
|
|
6
|
-
var loader = require('jeep-sqlite/loader');
|
|
7
|
-
var sqlite = require('@capacitor-community/sqlite');
|
|
8
|
-
var core = require('@capacitor/core');
|
|
9
|
-
var filesystem = require('@capacitor/filesystem');
|
|
10
|
-
var utils = require('@flumens/utils');
|
|
11
|
-
|
|
12
|
-
var SQLiteDatabase = /** @class */ (function () {
|
|
13
|
-
function SQLiteDatabase(_a) {
|
|
14
|
-
var name = _a.name, debug = _a.debug, web = _a.web;
|
|
15
|
-
this.sqliteConnection = new sqlite.SQLiteConnection(sqlite.CapacitorSQLite);
|
|
16
|
-
this.name = 'main';
|
|
17
|
-
this.debug = false;
|
|
18
|
-
this.isWeb = false;
|
|
19
|
-
this.ready = new utils.Deferred();
|
|
20
|
-
this.name = name || this.name;
|
|
21
|
-
this.debug = debug || this.debug;
|
|
22
|
-
this.isWeb = web || this.isWeb;
|
|
23
|
-
}
|
|
24
|
-
SQLiteDatabase.migrateCordova = function (isIOS) {
|
|
25
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
26
|
-
var sqliteConnection, res, error_1;
|
|
27
|
-
var _a;
|
|
28
|
-
return tslib.__generator(this, function (_b) {
|
|
29
|
-
switch (_b.label) {
|
|
30
|
-
case 0:
|
|
31
|
-
console.log('SQLite: Cordova db migration');
|
|
32
|
-
sqliteConnection = new sqlite.SQLiteConnection(sqlite.CapacitorSQLite);
|
|
33
|
-
_b.label = 1;
|
|
34
|
-
case 1:
|
|
35
|
-
_b.trys.push([1, 5, , 6]);
|
|
36
|
-
return [4 /*yield*/, sqliteConnection.getMigratableDbList(isIOS ? 'Library/LocalDatabase' : undefined)];
|
|
37
|
-
case 2:
|
|
38
|
-
res = _b.sent();
|
|
39
|
-
if (!((_a = res.values) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
40
|
-
console.log('SQLite: no Cordova db to migrate');
|
|
41
|
-
return [2 /*return*/];
|
|
42
|
-
}
|
|
43
|
-
console.log('SQLite: migrating', res.values);
|
|
44
|
-
return [4 /*yield*/, sqliteConnection.addSQLiteSuffix(isIOS ? 'Library/LocalDatabase' : undefined, res.values)];
|
|
45
|
-
case 3:
|
|
46
|
-
_b.sent();
|
|
47
|
-
return [4 /*yield*/, sqliteConnection.deleteOldDatabases(isIOS ? 'Library/LocalDatabase' : undefined, res.values)];
|
|
48
|
-
case 4:
|
|
49
|
-
_b.sent();
|
|
50
|
-
console.log('SQLite: migrating done', res.values);
|
|
51
|
-
return [3 /*break*/, 6];
|
|
52
|
-
case 5:
|
|
53
|
-
error_1 = _b.sent();
|
|
54
|
-
console.error(error_1);
|
|
55
|
-
return [3 /*break*/, 6];
|
|
56
|
-
case 6: return [4 /*yield*/, sqliteConnection.checkConnectionsConsistency()];
|
|
57
|
-
case 7:
|
|
58
|
-
_b.sent();
|
|
59
|
-
return [4 /*yield*/, sqliteConnection.closeAllConnections()];
|
|
60
|
-
case 8:
|
|
61
|
-
_b.sent();
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
Object.defineProperty(SQLiteDatabase.prototype, "db", {
|
|
68
|
-
get: function () {
|
|
69
|
-
return this.connection;
|
|
70
|
-
},
|
|
71
|
-
enumerable: false,
|
|
72
|
-
configurable: true
|
|
73
|
-
});
|
|
74
|
-
SQLiteDatabase.prototype.init = function () {
|
|
75
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var jeepSqlite, _a;
|
|
77
|
-
return tslib.__generator(this, function (_b) {
|
|
78
|
-
switch (_b.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
if (!this.isWeb) return [3 /*break*/, 3];
|
|
81
|
-
loader.defineCustomElements(window);
|
|
82
|
-
jeepSqlite = document.createElement('jeep-sqlite');
|
|
83
|
-
jeepSqlite.setAttribute('autoSave', 'true');
|
|
84
|
-
document.body.appendChild(jeepSqlite);
|
|
85
|
-
return [4 /*yield*/, customElements.whenDefined('jeep-sqlite')];
|
|
86
|
-
case 1:
|
|
87
|
-
_b.sent();
|
|
88
|
-
return [4 /*yield*/, this.sqliteConnection.initWebStore()];
|
|
89
|
-
case 2:
|
|
90
|
-
_b.sent();
|
|
91
|
-
_b.label = 3;
|
|
92
|
-
case 3: return [4 /*yield*/, this.sqliteConnection.checkConnectionsConsistency()];
|
|
93
|
-
case 4:
|
|
94
|
-
_b.sent();
|
|
95
|
-
return [4 /*yield*/, this.sqliteConnection.closeAllConnections()];
|
|
96
|
-
case 5:
|
|
97
|
-
_b.sent();
|
|
98
|
-
_a = this;
|
|
99
|
-
return [4 /*yield*/, this.sqliteConnection.createConnection(this.name, false, 'no-encryption', 1, false)];
|
|
100
|
-
case 6:
|
|
101
|
-
_a.connection = _b.sent();
|
|
102
|
-
return [4 /*yield*/, this.connection.open()];
|
|
103
|
-
case 7:
|
|
104
|
-
_b.sent();
|
|
105
|
-
this.ready.resolve(true);
|
|
106
|
-
return [2 /*return*/];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
SQLiteDatabase.prototype.query = function (_a) {
|
|
112
|
-
return tslib.__awaiter(this, arguments, void 0, function (_b) {
|
|
113
|
-
var res;
|
|
114
|
-
var _c;
|
|
115
|
-
var sql = _b.sql, params = _b.params;
|
|
116
|
-
return tslib.__generator(this, function (_d) {
|
|
117
|
-
switch (_d.label) {
|
|
118
|
-
case 0: return [4 /*yield*/, this.ready];
|
|
119
|
-
case 1:
|
|
120
|
-
_d.sent();
|
|
121
|
-
return [4 /*yield*/, this.db.query(sql, params).then(function (r) { return r.values || []; })];
|
|
122
|
-
case 2:
|
|
123
|
-
res = _d.sent();
|
|
124
|
-
if (!this.debug) return [3 /*break*/, 4];
|
|
125
|
-
console.groupCollapsed("\uD83D\uDCBE SQL: ".concat(sql
|
|
126
|
-
.trimStart()
|
|
127
|
-
.replaceAll(/\n/g, ' ')
|
|
128
|
-
.replaceAll(/\s+/g, ' ')
|
|
129
|
-
.substring(0, 30), "..."));
|
|
130
|
-
console.debug(sql, params, res);
|
|
131
|
-
console.groupEnd();
|
|
132
|
-
return [4 /*yield*/, ((_c = this.sqliteConnection) === null || _c === void 0 ? void 0 : _c.saveToStore(this.name))];
|
|
133
|
-
case 3:
|
|
134
|
-
_d.sent();
|
|
135
|
-
_d.label = 4;
|
|
136
|
-
case 4: return [2 /*return*/, res];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
SQLiteDatabase.prototype.export = function () {
|
|
142
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var name_1, url, res;
|
|
144
|
-
return tslib.__generator(this, function (_a) {
|
|
145
|
-
switch (_a.label) {
|
|
146
|
-
case 0:
|
|
147
|
-
if (this.isWeb) {
|
|
148
|
-
name_1 = this.name;
|
|
149
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
150
|
-
var request = indexedDB.open('jeepSqliteStore');
|
|
151
|
-
request.onsuccess = function (event) {
|
|
152
|
-
var getRequest = event.target.result
|
|
153
|
-
.transaction(['databases'], 'readwrite')
|
|
154
|
-
.objectStore('databases')
|
|
155
|
-
.get("".concat(name_1, "SQLite.db"));
|
|
156
|
-
getRequest.onsuccess = function (e) {
|
|
157
|
-
var blob = new Blob([e.target.result], {
|
|
158
|
-
type: 'application/vnd.sqlite3',
|
|
159
|
-
});
|
|
160
|
-
resolve(blob);
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
})];
|
|
164
|
-
}
|
|
165
|
-
return [4 /*yield*/, this.db.getUrl()];
|
|
166
|
-
case 1:
|
|
167
|
-
url = (_a.sent()).url;
|
|
168
|
-
return [4 /*yield*/, fetch(core.Capacitor.convertFileSrc(url))];
|
|
169
|
-
case 2:
|
|
170
|
-
res = _a.sent();
|
|
171
|
-
return [2 /*return*/, res.blob()];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
SQLiteDatabase.prototype.import = function (blob) {
|
|
177
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
178
|
-
var arr_1, _a, name_2, url, dataURI;
|
|
179
|
-
return tslib.__generator(this, function (_b) {
|
|
180
|
-
switch (_b.label) {
|
|
181
|
-
case 0:
|
|
182
|
-
if (!this.isWeb) return [3 /*break*/, 2];
|
|
183
|
-
_a = Uint8Array.bind;
|
|
184
|
-
return [4 /*yield*/, blob.arrayBuffer()];
|
|
185
|
-
case 1:
|
|
186
|
-
arr_1 = new (_a.apply(Uint8Array, [void 0, _b.sent()]))();
|
|
187
|
-
name_2 = this.name;
|
|
188
|
-
// eslint-disable-next-line no-new
|
|
189
|
-
new Promise(function (resolve) {
|
|
190
|
-
var request = indexedDB.open('jeepSqliteStore');
|
|
191
|
-
request.onsuccess = function (event) {
|
|
192
|
-
var getRequest = event.target.result
|
|
193
|
-
.transaction(['databases'], 'readwrite')
|
|
194
|
-
.objectStore('databases')
|
|
195
|
-
.put(arr_1, "".concat(name_2, "SQLite.db"), 0);
|
|
196
|
-
getRequest.onsuccess = function () { return resolve(); };
|
|
197
|
-
};
|
|
198
|
-
});
|
|
199
|
-
return [2 /*return*/];
|
|
200
|
-
case 2: return [4 /*yield*/, this.db.getUrl()];
|
|
201
|
-
case 3:
|
|
202
|
-
url = (_b.sent()).url;
|
|
203
|
-
return [4 /*yield*/, new Promise(function (r) {
|
|
204
|
-
var a = new FileReader();
|
|
205
|
-
a.onload = r;
|
|
206
|
-
a.readAsDataURL(blob);
|
|
207
|
-
}).then(function (e) { return e.target.result; })];
|
|
208
|
-
case 4:
|
|
209
|
-
dataURI = _b.sent();
|
|
210
|
-
return [4 /*yield*/, filesystem.Filesystem.writeFile({ path: url, data: dataURI })];
|
|
211
|
-
case 5:
|
|
212
|
-
_b.sent();
|
|
213
|
-
return [2 /*return*/];
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
return SQLiteDatabase;
|
|
219
|
-
}());
|
|
220
|
-
|
|
221
|
-
exports["default"] = SQLiteDatabase;
|
|
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"),s=require("@flumens/utils"),o=function(){function o(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 s.Deferred,this.name=t||this.name,this.debug=r||this.debug,this.isWeb=i||this.isWeb}return o.migrateCordova=function(t){return e.__awaiter(this,void 0,void 0,(function(){var r,i,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 i=e.sent(),(null===(o=i.values)||void 0===o?void 0:o.length)?(console.log("SQLite: migrating",i.values),[4,r.addSQLiteSuffix(t?"Library/LocalDatabase":void 0,i.values)]):(console.log("SQLite: no Cordova db to migrate"),[2]);case 3:return e.sent(),[4,r.deleteOldDatabases(t?"Library/LocalDatabase":void 0,i.values)];case 4:return e.sent(),console.log("SQLite: migrating done",i.values),[3,6];case 5:return s=e.sent(),console.error(s),[3,6];case 6:return[4,r.checkConnectionsConsistency()];case 7:return e.sent(),[4,r.closeAllConnections()];case 8:return e.sent(),[2]}}))}))},Object.defineProperty(o.prototype,"db",{get:function(){return this.connection},enumerable:!1,configurable:!0}),o.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]}}))}))},o.prototype.query=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var n,r,i=t.sql,s=t.params;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,s).then((function(e){return e.values||[]}))];case 2:return n=e.sent(),this.debug?(console.groupCollapsed("💾 SQL: ".concat(i.trimStart().replaceAll(/\n/g," ").replaceAll(/\s+/g," ").substring(0,30),"...")),console.debug(i,s,n),console.groupEnd(),[4,null===(r=this.sqliteConnection)||void 0===r?void 0:r.saveToStore(this.name)]):[3,4];case 3:e.sent(),e.label=4;case 4:return[2,n]}}))}))},o.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()]}}))}))},o.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]}}))}))},o}();exports.default=o;
|