pubo-web 1.0.78 → 1.0.80

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.
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+
3
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) {
11
+ try {
12
+ step(generator.next(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ }
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function step(result) {
25
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
26
+ }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = this && this.__generator || function (thisArg, body) {
31
+ var _ = {
32
+ label: 0,
33
+ sent: function sent() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ },
40
+ f,
41
+ y,
42
+ t,
43
+ g;
44
+ return g = {
45
+ next: verb(0),
46
+ "throw": verb(1),
47
+ "return": verb(2)
48
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
49
+ return this;
50
+ }), g;
51
+ function verb(n) {
52
+ return function (v) {
53
+ return step([n, v]);
54
+ };
55
+ }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
59
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
60
+ if (y = 0, t) op = [op[0] & 2, t.value];
61
+ switch (op[0]) {
62
+ case 0:
63
+ case 1:
64
+ t = op;
65
+ break;
66
+ case 4:
67
+ _.label++;
68
+ return {
69
+ value: op[1],
70
+ done: false
71
+ };
72
+ case 5:
73
+ _.label++;
74
+ y = op[1];
75
+ op = [0];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [6, e];
107
+ y = 0;
108
+ } finally {
109
+ f = t = 0;
110
+ }
111
+ if (op[0] & 5) throw op[1];
112
+ return {
113
+ value: op[0] ? op[1] : void 0,
114
+ done: true
115
+ };
116
+ }
117
+ };
118
+ var __values = this && this.__values || function (o) {
119
+ var s = typeof Symbol === "function" && Symbol.iterator,
120
+ m = s && o[s],
121
+ i = 0;
122
+ if (m) return m.call(o);
123
+ if (o && typeof o.length === "number") return {
124
+ next: function next() {
125
+ if (o && i >= o.length) o = void 0;
126
+ return {
127
+ value: o && o[i++],
128
+ done: !o
129
+ };
130
+ }
131
+ };
132
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
133
+ };
134
+ var __read = this && this.__read || function (o, n) {
135
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
136
+ if (!m) return o;
137
+ var i = m.call(o),
138
+ r,
139
+ ar = [],
140
+ e;
141
+ try {
142
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
143
+ } catch (error) {
144
+ e = {
145
+ error: error
146
+ };
147
+ } finally {
148
+ try {
149
+ if (r && !r.done && (m = i["return"])) m.call(i);
150
+ } finally {
151
+ if (e) throw e.error;
152
+ }
153
+ }
154
+ return ar;
155
+ };
156
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
157
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
158
+ if (ar || !(i in from)) {
159
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
160
+ ar[i] = from[i];
161
+ }
162
+ }
163
+ return to.concat(ar || Array.prototype.slice.call(from));
164
+ };
165
+ Object.defineProperty(exports, "__esModule", {
166
+ value: true
167
+ });
168
+ exports.IndexedDBUtils = void 0;
169
+ var IndexedDBUtils = /** @class */function () {
170
+ function IndexedDBUtils(name, version, tables) {
171
+ this.indexedDB = self.indexedDB;
172
+ this.get = this.createTransaction(function (objectStore, key) {
173
+ return objectStore.get(key);
174
+ });
175
+ this.getAll = this.createTransaction(function (objectStore) {
176
+ return objectStore.getAll();
177
+ });
178
+ this["delete"] = this.createTransaction(function (objectStore, key) {
179
+ return objectStore["delete"](key);
180
+ });
181
+ this.put = this.createTransaction(function (objectStore, values) {
182
+ return objectStore.put(values);
183
+ });
184
+ this.name = name;
185
+ this.version = version;
186
+ this.tables = tables;
187
+ }
188
+ IndexedDBUtils.prototype.open = function () {
189
+ var _this = this;
190
+ return new Promise(function (resolve, reject) {
191
+ var _a;
192
+ var request = (_a = _this.indexedDB) === null || _a === void 0 ? void 0 : _a.open(_this.name, _this.version);
193
+ request.onupgradeneeded = function (event) {
194
+ return __awaiter(_this, void 0, void 0, function () {
195
+ var _a, _b, table;
196
+ var e_1, _c;
197
+ var _this = this;
198
+ return __generator(this, function (_d) {
199
+ // @ts-ignore
200
+ this.db = event.target.result;
201
+ // @ts-ignore
202
+ this.transaction = event.target.transaction;
203
+ this.transaction.oncomplete = function () {
204
+ return __awaiter(_this, void 0, void 0, function () {
205
+ var _a, _b, table, e_2_1;
206
+ var e_2, _c;
207
+ return __generator(this, function (_d) {
208
+ switch (_d.label) {
209
+ case 0:
210
+ this.transaction = null;
211
+ _d.label = 1;
212
+ case 1:
213
+ _d.trys.push([1, 6, 7, 8]);
214
+ _a = __values(this.tables), _b = _a.next();
215
+ _d.label = 2;
216
+ case 2:
217
+ if (!!_b.done) return [3 /*break*/, 5];
218
+ table = _b.value;
219
+ if (!table["default"]) return [3 /*break*/, 4];
220
+ return [4 /*yield*/, this.put(table.name, table["default"])];
221
+ case 3:
222
+ _d.sent();
223
+ _d.label = 4;
224
+ case 4:
225
+ _b = _a.next();
226
+ return [3 /*break*/, 2];
227
+ case 5:
228
+ return [3 /*break*/, 8];
229
+ case 6:
230
+ e_2_1 = _d.sent();
231
+ e_2 = {
232
+ error: e_2_1
233
+ };
234
+ return [3 /*break*/, 8];
235
+ case 7:
236
+ try {
237
+ if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
238
+ } finally {
239
+ if (e_2) throw e_2.error;
240
+ }
241
+ return [7 /*endfinally*/];
242
+ case 8:
243
+ return [2 /*return*/];
244
+ }
245
+ });
246
+ });
247
+ };
248
+
249
+ try {
250
+ for (_a = __values(this.tables), _b = _a.next(); !_b.done; _b = _a.next()) {
251
+ table = _b.value;
252
+ this.createTable(table);
253
+ }
254
+ } catch (e_1_1) {
255
+ e_1 = {
256
+ error: e_1_1
257
+ };
258
+ } finally {
259
+ try {
260
+ if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
261
+ } finally {
262
+ if (e_1) throw e_1.error;
263
+ }
264
+ }
265
+ resolve('success');
266
+ return [2 /*return*/];
267
+ });
268
+ });
269
+ };
270
+
271
+ request.onsuccess = function () {
272
+ _this.db = request.result;
273
+ resolve('success');
274
+ };
275
+ request.onerror = function (error) {
276
+ console.error('indexed db connect error: ', error);
277
+ reject(error);
278
+ };
279
+ });
280
+ };
281
+ IndexedDBUtils.prototype.createTable = function (table) {
282
+ if (!this.db.objectStoreNames.contains(table.name)) {
283
+ this.db.createObjectStore(table.name, table.options || {
284
+ keyPath: '_id',
285
+ autoIncrement: true
286
+ });
287
+ }
288
+ };
289
+ IndexedDBUtils.prototype.createTransaction = function (getRequest) {
290
+ var _this = this;
291
+ return function (store) {
292
+ var args = [];
293
+ for (var _i = 1; _i < arguments.length; _i++) {
294
+ args[_i - 1] = arguments[_i];
295
+ }
296
+ return new Promise(function (resolve, reject) {
297
+ if (!_this.db) {
298
+ reject('not connect');
299
+ return;
300
+ }
301
+ var transaction = _this.db.transaction([store], 'readwrite');
302
+ var objectStore = transaction.objectStore(store);
303
+ var request = getRequest.apply(void 0, __spreadArray([objectStore], __read(args), false));
304
+ request.onerror = function (event) {
305
+ reject(event);
306
+ };
307
+ request.onsuccess = function () {
308
+ resolve(request.result);
309
+ };
310
+ });
311
+ };
312
+ };
313
+ return IndexedDBUtils;
314
+ }();
315
+ exports.IndexedDBUtils = IndexedDBUtils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.78",
3
+ "version": "1.0.80",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.78"
22
+ "pubo-utils": "^1.0.80"
23
23
  },
24
- "gitHead": "fcecf50aa7224cbb792821a0cc951c0aa6626444"
24
+ "gitHead": "29c92b8f53b85afb98d47d6557a99e4ce236615e"
25
25
  }