@bbn/bbn 1.0.437 → 1.0.439
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/_.js +7 -11
- package/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/date.d.ts +39 -0
- package/dist/date.js +339 -0
- package/dist/db.js +107 -124
- package/dist/fn/ajax/_addLoader.js +6 -6
- package/dist/fn/ajax/_deleteLoader.js +11 -13
- package/dist/fn/ajax/abort.js +1 -1
- package/dist/fn/ajax/abortURL.js +1 -1
- package/dist/fn/ajax/ajax.js +25 -30
- package/dist/fn/ajax/callback.js +10 -14
- package/dist/fn/ajax/download.js +7 -9
- package/dist/fn/ajax/downloadContent.js +5 -6
- package/dist/fn/ajax/getLoader.js +1 -1
- package/dist/fn/ajax/getRequestId.js +2 -2
- package/dist/fn/ajax/link.js +9 -13
- package/dist/fn/ajax/post.js +3 -7
- package/dist/fn/ajax/postOut.js +2 -4
- package/dist/fn/ajax/setNavigationVars.js +5 -7
- package/dist/fn/ajax/stream.js +21 -22
- package/dist/fn/ajax/treatAjaxArguments.js +3 -3
- package/dist/fn/ajax/upload.js +6 -9
- package/dist/fn/browser/copy.js +9 -12
- package/dist/fn/browser/error.js +2 -2
- package/dist/fn/browser/executeSlowly.js +11 -55
- package/dist/fn/browser/getBrowserName.js +1 -1
- package/dist/fn/browser/getBrowserVersion.js +1 -1
- package/dist/fn/browser/getCookie.js +5 -5
- package/dist/fn/browser/getDeviceType.js +1 -1
- package/dist/fn/browser/getEventData.js +30 -30
- package/dist/fn/browser/happy.js +1 -5
- package/dist/fn/browser/info.js +1 -5
- package/dist/fn/browser/isActiveInterface.js +2 -3
- package/dist/fn/browser/isFocused.js +1 -2
- package/dist/fn/browser/log.js +8 -12
- package/dist/fn/browser/replaceSelection.js +5 -5
- package/dist/fn/browser/selectElementText.js +4 -5
- package/dist/fn/browser/setCookie.js +3 -3
- package/dist/fn/browser/warning.js +2 -2
- package/dist/fn/browser/yieldToBrowser.js +7 -43
- package/dist/fn/convert/arrayBuffer2String.js +1 -1
- package/dist/fn/convert/canvasToImage.js +1 -1
- package/dist/fn/convert/colorToHex.js +1 -1
- package/dist/fn/convert/fromXml.js +7 -13
- package/dist/fn/convert/hex2rgb.js +1 -1
- package/dist/fn/convert/imageToCanvas.js +1 -1
- package/dist/fn/convert/imgToBase64.js +2 -3
- package/dist/fn/convert/toCSV.js +7 -10
- package/dist/fn/datetime/calendar.js +4 -5
- package/dist/fn/datetime/date.js +1 -1
- package/dist/fn/datetime/dateSQL.js +1 -1
- package/dist/fn/datetime/daysInMonth.js +1 -1
- package/dist/fn/datetime/fdate.js +2 -3
- package/dist/fn/datetime/fdatetime.js +2 -3
- package/dist/fn/datetime/ftime.js +1 -1
- package/dist/fn/datetime/getChrono.js +2 -3
- package/dist/fn/datetime/getDay.js +3 -3
- package/dist/fn/datetime/startChrono.js +1 -1
- package/dist/fn/datetime/stopChrono.js +2 -2
- package/dist/fn/datetime/timestamp.js +2 -3
- package/dist/fn/default/defaultAjaxAbortFunction.js +1 -2
- package/dist/fn/default/defaultAjaxErrorFunction.js +1 -3
- package/dist/fn/default/defaultAlertFunction.js +1 -2
- package/dist/fn/default/defaultConfirmFunction.js +2 -3
- package/dist/fn/default/defaultEndLoadingFunction.js +1 -3
- package/dist/fn/default/defaultPostLinkFunction.js +1 -2
- package/dist/fn/default/defaultPreLinkFunction.js +1 -3
- package/dist/fn/form/addInputs.js +10 -12
- package/dist/fn/form/fieldValue.js +1 -1
- package/dist/fn/form/formdata.js +24 -24
- package/dist/fn/form/objectToFormData.js +5 -8
- package/dist/fn/form/submit.js +4 -4
- package/dist/fn/html/adjustHeight.js +1 -1
- package/dist/fn/html/adjustSize.js +5 -5
- package/dist/fn/html/adjustWidth.js +1 -1
- package/dist/fn/html/getAllTags.js +1 -1
- package/dist/fn/html/getAncestors.js +2 -3
- package/dist/fn/html/getAttributes.js +2 -2
- package/dist/fn/html/getHTMLOfSelection.js +4 -4
- package/dist/fn/html/getHtml.js +2 -3
- package/dist/fn/html/getIndex.js +3 -4
- package/dist/fn/html/getPath.js +12 -17
- package/dist/fn/html/html2text.js +1 -1
- package/dist/fn/html/isInViewport.js +4 -5
- package/dist/fn/html/isInside.js +5 -5
- package/dist/fn/html/makeReactive.js +22 -26
- package/dist/fn/init.js +18 -18
- package/dist/fn/loop/each.js +2 -2
- package/dist/fn/loop/fori.js +3 -5
- package/dist/fn/loop/forir.js +3 -5
- package/dist/fn/loop/iterate.js +3 -6
- package/dist/fn/loop/riterate.js +1 -2
- package/dist/fn/misc/analyzeFunction.js +36 -36
- package/dist/fn/misc/money.js +4 -4
- package/dist/fn/misc/translate.js +2 -2
- package/dist/fn/object/_compareValues.js +2 -3
- package/dist/fn/object/_filter.js +7 -10
- package/dist/fn/object/arrayFromProp.js +2 -2
- package/dist/fn/object/checkProps.js +1 -2
- package/dist/fn/object/checkPropsDetails.js +8 -9
- package/dist/fn/object/checkPropsOrDie.js +2 -3
- package/dist/fn/object/circularReplacer.js +2 -2
- package/dist/fn/object/clone.js +2 -2
- package/dist/fn/object/compareConditions.js +6 -6
- package/dist/fn/object/count.js +1 -3
- package/dist/fn/object/createObject.js +3 -16
- package/dist/fn/object/deepPath.js +6 -7
- package/dist/fn/object/diffObj.js +11 -13
- package/dist/fn/object/extend.js +10 -14
- package/dist/fn/object/extendOut.js +4 -9
- package/dist/fn/object/filter.js +6 -8
- package/dist/fn/object/filterToConditions.js +6 -7
- package/dist/fn/object/findAll.js +4 -5
- package/dist/fn/object/getField.js +2 -8
- package/dist/fn/object/getFieldValues.js +2 -2
- package/dist/fn/object/getProperty.js +5 -9
- package/dist/fn/object/getRow.js +2 -7
- package/dist/fn/object/getSortingMoves.js +28 -28
- package/dist/fn/object/isWritable.js +1 -1
- package/dist/fn/object/map.js +2 -3
- package/dist/fn/object/move.js +1 -1
- package/dist/fn/object/multiorder.js +5 -6
- package/dist/fn/object/mutateArray.js +8 -9
- package/dist/fn/object/mutateObject.js +3 -3
- package/dist/fn/object/order.js +1 -2
- package/dist/fn/object/removeEmpty.js +2 -2
- package/dist/fn/object/removePrivateProp.js +2 -3
- package/dist/fn/object/search.js +13 -17
- package/dist/fn/object/setProp.js +1 -3
- package/dist/fn/object/setProperty.js +8 -8
- package/dist/fn/object/shortenObj.js +3 -4
- package/dist/fn/object/shuffle.js +2 -3
- package/dist/fn/object/sum.js +3 -3
- package/dist/fn/object/unique.js +1 -1
- package/dist/fn/phone/fphone.js +22 -22
- package/dist/fn/string/baseName.js +3 -3
- package/dist/fn/string/correctCase.js +1 -1
- package/dist/fn/string/crc32.js +7 -7
- package/dist/fn/string/data2Html.js +4 -5
- package/dist/fn/string/dirName.js +1 -1
- package/dist/fn/string/escapeUrl.js +6 -6
- package/dist/fn/string/fileExt.js +1 -1
- package/dist/fn/string/firstVarElement.js +2 -2
- package/dist/fn/string/format.js +4 -4
- package/dist/fn/string/formatBytes.js +2 -3
- package/dist/fn/string/hash.js +4 -8
- package/dist/fn/string/randomString.js +5 -5
- package/dist/fn/string/replaceAll.js +1 -2
- package/dist/fn/string/sanitize.js +6 -7
- package/dist/fn/string/simpleHash.js +2 -2
- package/dist/fn/string/simpleHash1.js +3 -3
- package/dist/fn/string/simpleHash2.js +3 -3
- package/dist/fn/string/treatForHash.js +6 -10
- package/dist/fn/string/trim.js +1 -2
- package/dist/fn/string/uniqString.js +7 -14
- package/dist/fn/style/addColors.js +14 -14
- package/dist/fn/style/addStyle.js +1 -1
- package/dist/fn/style/animateCss.js +1 -1
- package/dist/fn/style/center.js +1 -1
- package/dist/fn/style/cssExists.js +5 -5
- package/dist/fn/style/getCssVar.js +1 -1
- package/dist/fn/style/getScrollBarSize.js +5 -5
- package/dist/fn/style/lightenDarkenHex.js +2 -2
- package/dist/fn/style/outerHeight.js +2 -2
- package/dist/fn/style/outerWidth.js +2 -2
- package/dist/fn/style/resize.js +14 -14
- package/dist/fn/type/checkType.js +5 -9
- package/dist/fn/type/isArray.js +2 -7
- package/dist/fn/type/isBlob.js +2 -7
- package/dist/fn/type/isBoolean.js +2 -7
- package/dist/fn/type/isCanvas.js +2 -7
- package/dist/fn/type/isColor.js +2 -7
- package/dist/fn/type/isComment.js +2 -7
- package/dist/fn/type/isCp.js +3 -8
- package/dist/fn/type/isDataURL.js +2 -7
- package/dist/fn/type/isDate.js +2 -7
- package/dist/fn/type/isDimension.js +2 -7
- package/dist/fn/type/isDom.js +2 -7
- package/dist/fn/type/isEmail.js +3 -8
- package/dist/fn/type/isEvent.js +2 -7
- package/dist/fn/type/isFunction.js +2 -7
- package/dist/fn/type/isHostname.js +2 -7
- package/dist/fn/type/isIP.js +2 -7
- package/dist/fn/type/isInt.js +2 -7
- package/dist/fn/type/isIterable.js +2 -7
- package/dist/fn/type/isNotObject.js +2 -7
- package/dist/fn/type/isNull.js +2 -7
- package/dist/fn/type/isNumber.js +2 -7
- package/dist/fn/type/isObject.js +2 -7
- package/dist/fn/type/isPercent.js +2 -7
- package/dist/fn/type/isPrimitive.js +2 -7
- package/dist/fn/type/isPromise.js +2 -7
- package/dist/fn/type/isPropSize.js +2 -2
- package/dist/fn/type/isSQLDate.js +2 -7
- package/dist/fn/type/isSame.js +12 -12
- package/dist/fn/type/isString.js +2 -7
- package/dist/fn/type/isSymbol.js +2 -7
- package/dist/fn/type/isURL.js +2 -7
- package/dist/fn/type/isUid.js +2 -7
- package/dist/fn/type/isValidDimension.js +2 -2
- package/dist/fn/type/isValidName.js +2 -7
- package/dist/fn/type/isVue.js +4 -11
- package/dist/fn.js +247 -247
- package/dist/index.js +9 -7
- package/package.json +1 -1
package/dist/db.js
CHANGED
|
@@ -5,24 +5,23 @@ import log from './fn/browser/log.js';
|
|
|
5
5
|
import isObject from './fn/type/isObject.js';
|
|
6
6
|
import isArray from './fn/type/isArray.js';
|
|
7
7
|
import extend from './fn/object/extend.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const idb = window['indexedDB'] || window['webkitIndexedDB'] || window['mozIndexedDB'] || window['OIndexedDB'] || window['msIndexedDB'];
|
|
9
|
+
const transformResult = (obj, fields) => {
|
|
10
10
|
if (fields === null || fields === void 0 ? void 0 : fields.length) {
|
|
11
|
-
|
|
12
|
-
iterate(obj,
|
|
11
|
+
let res = {};
|
|
12
|
+
iterate(obj, (v, n) => {
|
|
13
13
|
if (fields.indexOf(n) > -1) {
|
|
14
|
-
|
|
14
|
+
res[n] = v;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
return
|
|
17
|
+
return res;
|
|
18
18
|
}
|
|
19
19
|
return obj;
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const fieldsFromFilter = (filter, fields = []) => {
|
|
22
22
|
var _a;
|
|
23
|
-
if (fields === void 0) { fields = []; }
|
|
24
23
|
if ((_a = filter === null || filter === void 0 ? void 0 : filter.conditions) === null || _a === void 0 ? void 0 : _a.length) {
|
|
25
|
-
filter.conditions.forEach(
|
|
24
|
+
filter.conditions.forEach(cond => {
|
|
26
25
|
if (cond.field && !fields.includes(cond.field)) {
|
|
27
26
|
fields.push(cond.field);
|
|
28
27
|
}
|
|
@@ -32,14 +31,14 @@ var fieldsFromFilter = function (filter, fields) {
|
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
else if (isObject(filter)) {
|
|
35
|
-
iterate(filter,
|
|
34
|
+
iterate(filter, (v, n) => {
|
|
36
35
|
if (!fields.includes(n)) {
|
|
37
36
|
fields.push(n);
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
else if (isArray(filter)) {
|
|
42
|
-
filter.forEach(
|
|
41
|
+
filter.forEach(cond => {
|
|
43
42
|
if (cond.field && !fields.includes(cond.field)) {
|
|
44
43
|
fields.push(cond.field);
|
|
45
44
|
}
|
|
@@ -50,162 +49,152 @@ var fieldsFromFilter = function (filter, fields) {
|
|
|
50
49
|
}
|
|
51
50
|
return fields;
|
|
52
51
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
req.onerror = function () {
|
|
52
|
+
const dbObject = function (dbName) {
|
|
53
|
+
const conn = db._connections[dbName];
|
|
54
|
+
const structure = db._structures[dbName];
|
|
55
|
+
let lastError = null;
|
|
56
|
+
const onError = (req, resolve) => {
|
|
57
|
+
req.onerror = () => {
|
|
60
58
|
lastError = req.error;
|
|
61
59
|
log(req.error);
|
|
62
60
|
resolve(req.error);
|
|
63
61
|
};
|
|
64
62
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
tx.onabort =
|
|
63
|
+
const getStore = (table, mode) => {
|
|
64
|
+
const tx = conn.transaction([table], mode.toLowerCase().indexOf('r') === 0 ? "readonly" : "readwrite");
|
|
65
|
+
tx.onabort = () => {
|
|
68
66
|
lastError = tx.error;
|
|
69
67
|
throw new Error(tx.error);
|
|
70
68
|
};
|
|
71
69
|
return [tx, tx.objectStore(table)];
|
|
72
70
|
};
|
|
73
|
-
this.lastError =
|
|
74
|
-
this.insert =
|
|
71
|
+
this.lastError = () => lastError;
|
|
72
|
+
this.insert = (table, data) => {
|
|
75
73
|
if (!Array.isArray(data)) {
|
|
76
74
|
data = [data];
|
|
77
75
|
}
|
|
78
|
-
return new Promise(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
each(data,
|
|
82
|
-
|
|
83
|
-
request.onerror =
|
|
76
|
+
return new Promise(resolve => {
|
|
77
|
+
const [tx, store] = getStore(table, 'w');
|
|
78
|
+
let res = data.length;
|
|
79
|
+
each(data, a => {
|
|
80
|
+
const request = store.put(a);
|
|
81
|
+
request.onerror = () => {
|
|
84
82
|
log(request.error);
|
|
85
83
|
res--;
|
|
86
84
|
};
|
|
87
85
|
});
|
|
88
|
-
tx.oncomplete =
|
|
86
|
+
tx.oncomplete = () => {
|
|
89
87
|
resolve(res);
|
|
90
88
|
};
|
|
91
89
|
});
|
|
92
90
|
};
|
|
93
|
-
this.update =
|
|
94
|
-
return new Promise(
|
|
95
|
-
|
|
96
|
-
var _a;
|
|
91
|
+
this.update = (table, data, where, replace) => {
|
|
92
|
+
return new Promise(resolve => {
|
|
93
|
+
this.selectAll(table, [], where).then(rows => {
|
|
97
94
|
if (!rows.length) {
|
|
98
95
|
resolve(0);
|
|
99
96
|
return;
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
for (
|
|
106
|
-
|
|
98
|
+
const [tx, store] = getStore(table, 'w');
|
|
99
|
+
const arch = structure[table];
|
|
100
|
+
const primary = arch.keys.PRIMARY.columns.length > 1 ? arch.keys.PRIMARY.columns : arch.keys.PRIMARY.columns[0];
|
|
101
|
+
let res = 0;
|
|
102
|
+
for (let i = 0; i < rows.length; i++) {
|
|
103
|
+
const newData = extend({}, replace ? { [primary]: rows[i][primary] } : rows[i], data);
|
|
107
104
|
if (!newData[primary]) {
|
|
108
105
|
throw new Error(_("No primary key in the data"));
|
|
109
106
|
}
|
|
110
|
-
|
|
107
|
+
const req = store.put(newData);
|
|
111
108
|
onError(req, resolve);
|
|
112
|
-
req.onsuccess =
|
|
109
|
+
req.onsuccess = () => {
|
|
113
110
|
res++;
|
|
114
111
|
};
|
|
115
112
|
}
|
|
116
|
-
tx.oncomplete =
|
|
113
|
+
tx.oncomplete = () => {
|
|
117
114
|
resolve(res);
|
|
118
115
|
};
|
|
119
116
|
});
|
|
120
117
|
});
|
|
121
118
|
};
|
|
122
|
-
this.delete =
|
|
123
|
-
return new Promise(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
this.delete = (table, where) => {
|
|
120
|
+
return new Promise(resolve => {
|
|
121
|
+
const [tx, store] = getStore(table, 'w');
|
|
122
|
+
const arch = structure[table];
|
|
123
|
+
const primary = arch.keys.PRIMARY.columns.length > 1 ? arch.keys.PRIMARY.columns : arch.keys.PRIMARY.columns[0];
|
|
127
124
|
if (!where[primary]) {
|
|
128
125
|
throw new Error(_("No "));
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
let res = 1;
|
|
128
|
+
const req = store.delete(where[primary]);
|
|
132
129
|
onError(req, resolve);
|
|
133
|
-
tx.oncomplete =
|
|
130
|
+
tx.oncomplete = () => {
|
|
134
131
|
resolve(res);
|
|
135
132
|
};
|
|
136
133
|
});
|
|
137
134
|
};
|
|
138
|
-
this.selectOne =
|
|
139
|
-
return new Promise(
|
|
140
|
-
|
|
135
|
+
this.selectOne = (table, field, where, order, start, limit) => {
|
|
136
|
+
return new Promise(resolve => {
|
|
137
|
+
this.selectAll(table, [field], where, order, start, 1).then(d => {
|
|
141
138
|
var _a, _b;
|
|
142
139
|
resolve((_b = (_a = d === null || d === void 0 ? void 0 : d[0]) === null || _a === void 0 ? void 0 : _a[field]) !== null && _b !== void 0 ? _b : undefined);
|
|
143
140
|
});
|
|
144
141
|
});
|
|
145
142
|
};
|
|
146
|
-
this.select =
|
|
147
|
-
return new Promise(
|
|
148
|
-
|
|
143
|
+
this.select = (table, fields, where, order, start) => {
|
|
144
|
+
return new Promise(resolve => {
|
|
145
|
+
this.selectAll(table, fields, where, order, start, 1).then(d => {
|
|
149
146
|
resolve(d.length ? d[0] : null);
|
|
150
147
|
});
|
|
151
148
|
});
|
|
152
149
|
};
|
|
153
|
-
this.selectAll =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var _a = getStore(table, 'r'), tx = _a[0], store = _a[1];
|
|
161
|
-
var arch = structure[table];
|
|
162
|
-
var primary = arch.keys.PRIMARY.columns.length > 1 ? arch.keys.PRIMARY.columns : arch.keys.PRIMARY.columns[0];
|
|
163
|
-
var search = isObject(where) ? Object.keys(where)[0] : (!where || isArray(where) ? null : primary);
|
|
164
|
-
var results = [];
|
|
150
|
+
this.selectAll = (table, fields = [], where = null, order = null, start = 0, limit = null) => {
|
|
151
|
+
return new Promise(resolve => {
|
|
152
|
+
const [tx, store] = getStore(table, 'r');
|
|
153
|
+
const arch = structure[table];
|
|
154
|
+
const primary = arch.keys.PRIMARY.columns.length > 1 ? arch.keys.PRIMARY.columns : arch.keys.PRIMARY.columns[0];
|
|
155
|
+
const search = isObject(where) ? Object.keys(where)[0] : (!where || isArray(where) ? null : primary);
|
|
156
|
+
const results = [];
|
|
165
157
|
if (search === primary) {
|
|
166
158
|
if (bbn.fn.isArray(where === null || where === void 0 ? void 0 : where[primary])) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
getter.onsuccess =
|
|
172
|
-
|
|
159
|
+
let req = [];
|
|
160
|
+
const max = Math.min(where[primary].length, limit || 9999999);
|
|
161
|
+
for (let i = start || 0; i < max; i++) {
|
|
162
|
+
let getter = store.get(where[primary][i]);
|
|
163
|
+
getter.onsuccess = () => {
|
|
164
|
+
let obj = getter.result;
|
|
173
165
|
results.push(transformResult(obj, fields));
|
|
174
|
-
if (results.length ===
|
|
166
|
+
if (results.length === max) {
|
|
175
167
|
resolve(results);
|
|
176
168
|
}
|
|
177
169
|
};
|
|
178
170
|
onError(getter, resolve);
|
|
179
171
|
req.push(getter);
|
|
180
|
-
};
|
|
181
|
-
for (var i = start || 0; i < max_1; i++) {
|
|
182
|
-
_loop_1(i);
|
|
183
172
|
}
|
|
184
173
|
}
|
|
185
174
|
else {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
let req = store.get((where === null || where === void 0 ? void 0 : where[primary]) || where);
|
|
176
|
+
req.onsuccess = () => {
|
|
177
|
+
let obj = req.result;
|
|
189
178
|
results.push(transformResult(obj, fields));
|
|
190
179
|
resolve(results);
|
|
191
180
|
};
|
|
192
|
-
onError(
|
|
181
|
+
onError(req, resolve);
|
|
193
182
|
}
|
|
194
183
|
}
|
|
195
184
|
else {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
req.onsuccess =
|
|
199
|
-
|
|
185
|
+
const req = store.openCursor();
|
|
186
|
+
let i = 0;
|
|
187
|
+
req.onsuccess = (e) => {
|
|
188
|
+
const cursor = e.target.result;
|
|
200
189
|
if (cursor) {
|
|
201
190
|
if (!where || !bbn.fn.search([cursor.value], where)) {
|
|
202
|
-
if (
|
|
191
|
+
if (i >= start) {
|
|
203
192
|
results.push(transformResult(cursor.value, fields));
|
|
204
193
|
if (results.length === limit) {
|
|
205
194
|
resolve(results);
|
|
206
195
|
}
|
|
207
196
|
}
|
|
208
|
-
|
|
197
|
+
i++;
|
|
209
198
|
}
|
|
210
199
|
cursor.continue();
|
|
211
200
|
}
|
|
@@ -217,19 +206,14 @@ var dbObject = function (dbName) {
|
|
|
217
206
|
}
|
|
218
207
|
});
|
|
219
208
|
};
|
|
220
|
-
this.getColumnValues =
|
|
221
|
-
return new Promise(
|
|
222
|
-
|
|
223
|
-
|
|
209
|
+
this.getColumnValues = (table, field, where, order, start, limit) => {
|
|
210
|
+
return new Promise(resolve => {
|
|
211
|
+
const tx = conn.transaction([table], "read");
|
|
212
|
+
const store = tx.objectStore(table);
|
|
224
213
|
});
|
|
225
214
|
};
|
|
226
|
-
this.copyTable =
|
|
227
|
-
|
|
228
|
-
if (where === void 0) { where = null; }
|
|
229
|
-
if (order === void 0) { order = null; }
|
|
230
|
-
if (start === void 0) { start = 0; }
|
|
231
|
-
if (limit === void 0) { limit = null; }
|
|
232
|
-
return new Promise(function (resolve) {
|
|
215
|
+
this.copyTable = (target, table, fields = [], where = null, order = null, start = 0, limit = null) => {
|
|
216
|
+
return new Promise(resolve => {
|
|
233
217
|
if (!conn.objectStoreNames.contains(target)) {
|
|
234
218
|
db.add(dbName, target, structure[table]);
|
|
235
219
|
}
|
|
@@ -237,9 +221,9 @@ var dbObject = function (dbName) {
|
|
|
237
221
|
resolve(0);
|
|
238
222
|
throw new Error(_("The target table %s does not exist", target));
|
|
239
223
|
}
|
|
240
|
-
|
|
224
|
+
this.selectAll(table, fields, where, order, start, limit).then(d => {
|
|
241
225
|
if (d.length) {
|
|
242
|
-
|
|
226
|
+
this.insert(target, d).then(res => {
|
|
243
227
|
resolve(res);
|
|
244
228
|
});
|
|
245
229
|
}
|
|
@@ -249,28 +233,28 @@ var dbObject = function (dbName) {
|
|
|
249
233
|
});
|
|
250
234
|
});
|
|
251
235
|
};
|
|
252
|
-
this.deleteTable =
|
|
253
|
-
return new Promise(
|
|
236
|
+
this.deleteTable = table => {
|
|
237
|
+
return new Promise(resolve => {
|
|
254
238
|
conn.deleteObjectStore(table);
|
|
255
239
|
resolve(true);
|
|
256
240
|
});
|
|
257
241
|
};
|
|
258
242
|
};
|
|
259
|
-
|
|
243
|
+
const db = {
|
|
260
244
|
_structures: {},
|
|
261
245
|
/* This variable should be set to true in debugging mode only */
|
|
262
246
|
_connections: {},
|
|
263
247
|
/* Address of the CDN (where this file should be hosted) */
|
|
264
248
|
_stores: {},
|
|
265
249
|
ok: idb !== undefined,
|
|
266
|
-
updateStructure
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
updateStructure(storeName, structure, req) {
|
|
251
|
+
const primary = structure.keys.PRIMARY.columns.length > 1 ? structure.keys.PRIMARY.columns : structure.keys.PRIMARY.columns[0];
|
|
252
|
+
const stores = req.objectStoreNames;
|
|
269
253
|
if (!stores.contains(storeName)) {
|
|
270
|
-
|
|
271
|
-
iterate(structure.keys,
|
|
254
|
+
const store = req.createObjectStore(storeName, { keyPath: primary });
|
|
255
|
+
iterate(structure.keys, (a, n) => {
|
|
272
256
|
if (n !== 'PRIMARY') {
|
|
273
|
-
|
|
257
|
+
store.createIndex(n, a.columns.length > 1 ? a.columns : a.columns[0], {
|
|
274
258
|
unique: !!a.unique
|
|
275
259
|
});
|
|
276
260
|
}
|
|
@@ -279,24 +263,23 @@ var db = {
|
|
|
279
263
|
else {
|
|
280
264
|
}
|
|
281
265
|
},
|
|
282
|
-
open
|
|
283
|
-
|
|
284
|
-
return new Promise(function (resolve) {
|
|
266
|
+
open(name) {
|
|
267
|
+
return new Promise((resolve) => {
|
|
285
268
|
if (!db._connections[name]) {
|
|
286
269
|
if (!db._structures[name]) {
|
|
287
270
|
throw new Error(_("Impossible to find a structure for the database %s", name));
|
|
288
271
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
iterate(db._structures[name],
|
|
294
|
-
|
|
272
|
+
let num = Math.max.apply(this, [1].concat(Object.keys(db._structures[name]).map(a => db._structures[name][a].num || 1)));
|
|
273
|
+
const conn = idb.open(name, num);
|
|
274
|
+
conn.onupgradeneeded = () => {
|
|
275
|
+
const req = conn.result;
|
|
276
|
+
iterate(db._structures[name], (structure, storeName) => {
|
|
277
|
+
this.updateStructure(storeName, structure, req);
|
|
295
278
|
});
|
|
296
279
|
};
|
|
297
|
-
|
|
298
|
-
db._connections[name] =
|
|
299
|
-
|
|
280
|
+
conn.onsuccess = () => {
|
|
281
|
+
db._connections[name] = conn.result;
|
|
282
|
+
let obj = new dbObject(name);
|
|
300
283
|
resolve(obj);
|
|
301
284
|
};
|
|
302
285
|
}
|
|
@@ -305,7 +288,7 @@ var db = {
|
|
|
305
288
|
}
|
|
306
289
|
});
|
|
307
290
|
},
|
|
308
|
-
add
|
|
291
|
+
add(database, name, structure) {
|
|
309
292
|
var _a;
|
|
310
293
|
if (((_a = structure === null || structure === void 0 ? void 0 : structure.keys) === null || _a === void 0 ? void 0 : _a.PRIMARY) && (structure === null || structure === void 0 ? void 0 : structure.fields)) {
|
|
311
294
|
if (!db._structures[database]) {
|
|
@@ -15,15 +15,15 @@ import substr from '../string/substr.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export default function _addLoader(requestId, prom, aborter) {
|
|
17
17
|
/** @var {Number} tst Current timestamp */
|
|
18
|
-
|
|
18
|
+
let tst = new Date().getTime();
|
|
19
19
|
/** @var {String} url The original URL (part of requestId before : and md5) */
|
|
20
|
-
|
|
20
|
+
let url = substr(requestId, 0, requestId.length - 33);
|
|
21
21
|
/** @var {Object} loader The loader object */
|
|
22
|
-
|
|
22
|
+
let loader = {
|
|
23
23
|
key: requestId,
|
|
24
|
-
url
|
|
24
|
+
url,
|
|
25
25
|
loader: prom,
|
|
26
|
-
aborter
|
|
26
|
+
aborter,
|
|
27
27
|
loading: true,
|
|
28
28
|
error: false,
|
|
29
29
|
abort: false,
|
|
@@ -36,7 +36,7 @@ export default function _addLoader(requestId, prom, aborter) {
|
|
|
36
36
|
// Adding an object with this loader info in bbn.env.loadersHistory
|
|
37
37
|
bbn.env.loadersHistory.unshift(loader);
|
|
38
38
|
/** @var {Number} idx A pointer starting at the end of array loadersHistory */
|
|
39
|
-
|
|
39
|
+
let idx = bbn.env.loadersHistory.length;
|
|
40
40
|
// Removing elements from the loadersHistory object if their number is higher
|
|
41
41
|
// than bbn.env.maxLoadersHistory
|
|
42
42
|
while (idx && bbn.env.loadersHistory.length > bbn.env.maxLoadersHistory) {
|
|
@@ -15,23 +15,21 @@ import isObject from '../type/isObject.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @returns {Boolean} True if the loader was found
|
|
17
17
|
*/
|
|
18
|
-
export default function _deleteLoader(requestId, res, isAbort) {
|
|
19
|
-
|
|
20
|
-
if (isAbort === void 0) { isAbort = false; }
|
|
21
|
-
var idx = search(bbn.env.loaders, { key: requestId });
|
|
18
|
+
export default function _deleteLoader(requestId, res = null, isAbort = false) {
|
|
19
|
+
let idx = search(bbn.env.loaders, { key: requestId });
|
|
22
20
|
if (idx > -1) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
let loader = bbn.env.loaders.splice(idx, 1)[0];
|
|
22
|
+
let history = getRow(bbn.env.loadersHistory, { key: requestId, start: loader.start });
|
|
23
|
+
if (history) {
|
|
24
|
+
history.loading = false;
|
|
25
|
+
history.duration = new Date().getTime() - loader.start;
|
|
28
26
|
if (typeof res === 'string') {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
history.errorMessage = res;
|
|
28
|
+
history.error = !isAbort;
|
|
29
|
+
history.abort = isAbort;
|
|
32
30
|
}
|
|
33
31
|
else if (isObject(res)) {
|
|
34
|
-
|
|
32
|
+
history.success = true;
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
return true;
|
package/dist/fn/ajax/abort.js
CHANGED
|
@@ -22,7 +22,7 @@ import getLoader from './getLoader.js';
|
|
|
22
22
|
* @returns {undefined}
|
|
23
23
|
*/
|
|
24
24
|
export default function abort(requestId) {
|
|
25
|
-
|
|
25
|
+
let loader = getLoader(requestId);
|
|
26
26
|
if (loader === null || loader === void 0 ? void 0 : loader.aborter) {
|
|
27
27
|
loader.aborter.abort('Operation canceled by the user.');
|
|
28
28
|
}
|
package/dist/fn/ajax/abortURL.js
CHANGED
|
@@ -21,7 +21,7 @@ import _filter from '../object/_filter.js';
|
|
|
21
21
|
* @returns {undefined}
|
|
22
22
|
*/
|
|
23
23
|
export default function abortURL(url) {
|
|
24
|
-
each(_filter(bbn.env.loaders, { url: url }),
|
|
24
|
+
each(_filter(bbn.env.loaders, { url: url }), (a) => {
|
|
25
25
|
if (a && a.source) {
|
|
26
26
|
a.source.cancel('Operation canceled by the user.');
|
|
27
27
|
}
|
package/dist/fn/ajax/ajax.js
CHANGED
|
@@ -62,12 +62,7 @@ import _addLoader from './_addLoader.js';
|
|
|
62
62
|
*
|
|
63
63
|
* @returns {Promise} The Promise created by the generated XHR.
|
|
64
64
|
*/
|
|
65
|
-
export default function ajax(url, datatype, data, success, failure, abort) {
|
|
66
|
-
if (datatype === void 0) { datatype = null; }
|
|
67
|
-
if (data === void 0) { data = null; }
|
|
68
|
-
if (success === void 0) { success = null; }
|
|
69
|
-
if (failure === void 0) { failure = null; }
|
|
70
|
-
if (abort === void 0) { abort = null; }
|
|
65
|
+
export default function ajax(url, datatype = null, data = null, success = null, failure = null, abort = null) {
|
|
71
66
|
if ((datatype === null) && url && (typeof url === "object") && url.url) {
|
|
72
67
|
if (url.abort) {
|
|
73
68
|
abort = url.abort;
|
|
@@ -97,16 +92,16 @@ export default function ajax(url, datatype, data, success, failure, abort) {
|
|
|
97
92
|
if (!datatype) {
|
|
98
93
|
datatype = "json";
|
|
99
94
|
}
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
let requestId = getRequestId(url, data, datatype);
|
|
96
|
+
let loaderObj = getLoader(requestId);
|
|
102
97
|
if (loaderObj === null || loaderObj === void 0 ? void 0 : loaderObj.loader) {
|
|
103
98
|
return loaderObj.loader;
|
|
104
99
|
}
|
|
105
100
|
if (bbn.env.token) {
|
|
106
101
|
extend(data || {}, { _bbn_token: bbn.env.token });
|
|
107
102
|
}
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
const aborter = new AbortController();
|
|
104
|
+
let options = {
|
|
110
105
|
responseType: datatype,
|
|
111
106
|
signal: aborter.signal
|
|
112
107
|
};
|
|
@@ -116,17 +111,17 @@ export default function ajax(url, datatype, data, success, failure, abort) {
|
|
|
116
111
|
"Content-Type": "text/javascript",
|
|
117
112
|
};
|
|
118
113
|
}
|
|
119
|
-
|
|
114
|
+
let args = [url];
|
|
120
115
|
if (isObject(data)) {
|
|
121
116
|
args.push(data);
|
|
122
117
|
}
|
|
123
118
|
args.push(options);
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
const axiosMethod = args.length === 2 ? "get" : "post";
|
|
120
|
+
let loader = axios[axiosMethod]
|
|
126
121
|
.apply(null, args)
|
|
127
|
-
.then(
|
|
128
|
-
_deleteLoader(
|
|
129
|
-
bbn.fn.defaultEndLoadingFunction(url,
|
|
122
|
+
.then(res => {
|
|
123
|
+
_deleteLoader(requestId, res);
|
|
124
|
+
bbn.fn.defaultEndLoadingFunction(url, tst, data, res);
|
|
130
125
|
switch (res.status) {
|
|
131
126
|
case 200:
|
|
132
127
|
if (isFunction(success)) {
|
|
@@ -135,22 +130,22 @@ export default function ajax(url, datatype, data, success, failure, abort) {
|
|
|
135
130
|
}
|
|
136
131
|
break;
|
|
137
132
|
default:
|
|
138
|
-
|
|
133
|
+
let ok = 1;
|
|
139
134
|
if (isFunction(failure)) {
|
|
140
|
-
ok = failure(
|
|
135
|
+
ok = failure(loader, res.message, res);
|
|
141
136
|
}
|
|
142
137
|
if (ok) {
|
|
143
|
-
bbn.fn.defaultAjaxErrorFunction(
|
|
138
|
+
bbn.fn.defaultAjaxErrorFunction(loader, res.message, res);
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
141
|
return res;
|
|
147
142
|
})
|
|
148
|
-
.catch(
|
|
149
|
-
|
|
150
|
-
_deleteLoader(
|
|
151
|
-
bbn.fn.defaultEndLoadingFunction(url,
|
|
143
|
+
.catch((err) => {
|
|
144
|
+
let isAbort = axios.isCancel(err);
|
|
145
|
+
_deleteLoader(requestId, err.message || err.response.data, isAbort);
|
|
146
|
+
bbn.fn.defaultEndLoadingFunction(url, tst, data, err);
|
|
152
147
|
if (isAbort) {
|
|
153
|
-
|
|
148
|
+
let ok = 1;
|
|
154
149
|
if (isFunction(abort)) {
|
|
155
150
|
ok = abort(err.message, url);
|
|
156
151
|
}
|
|
@@ -159,19 +154,19 @@ export default function ajax(url, datatype, data, success, failure, abort) {
|
|
|
159
154
|
}
|
|
160
155
|
}
|
|
161
156
|
else {
|
|
162
|
-
|
|
157
|
+
let ok = 1;
|
|
163
158
|
if (isFunction(failure)) {
|
|
164
|
-
ok = failure(
|
|
159
|
+
ok = failure(loader, err.message, err);
|
|
165
160
|
}
|
|
166
161
|
if (ok) {
|
|
167
|
-
bbn.fn.defaultAjaxErrorFunction(
|
|
162
|
+
bbn.fn.defaultAjaxErrorFunction(loader, err.message, err.response);
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
165
|
return err.response;
|
|
171
166
|
});
|
|
172
|
-
|
|
173
|
-
bbn.fn.defaultStartLoadingFunction(url,
|
|
174
|
-
return
|
|
167
|
+
let tst = _addLoader(requestId, loader, aborter);
|
|
168
|
+
bbn.fn.defaultStartLoadingFunction(url, tst, data, requestId);
|
|
169
|
+
return loader;
|
|
175
170
|
}
|
|
176
171
|
}
|
|
177
172
|
;
|
package/dist/fn/ajax/callback.js
CHANGED
|
@@ -36,21 +36,17 @@ import log from '../browser/log.js';
|
|
|
36
36
|
*
|
|
37
37
|
* @returns {*} The result of the main callback function: res.script, fn, or bbn.fn.defaultLinkFunction
|
|
38
38
|
*/
|
|
39
|
-
export default function callback(url, res, fn, fn2, ele) {
|
|
40
|
-
|
|
41
|
-
if (fn === void 0) { fn = null; }
|
|
42
|
-
if (fn2 === void 0) { fn2 = null; }
|
|
43
|
-
if (ele === void 0) { ele = null; }
|
|
44
|
-
var tmp = false;
|
|
39
|
+
export default function callback(url, res = null, fn = null, fn2 = null, ele = null) {
|
|
40
|
+
let tmp = false;
|
|
45
41
|
if (res) {
|
|
46
42
|
tmp = true;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
let t = typeof res;
|
|
44
|
+
let isObj = t.toLowerCase() === 'object';
|
|
45
|
+
let errTitle;
|
|
50
46
|
if (isObj && res.prescript) {
|
|
51
47
|
/* var ok can be changed to false in prescript execution */
|
|
52
48
|
try {
|
|
53
|
-
|
|
49
|
+
const preFn = new Function(res.prescript);
|
|
54
50
|
preFn();
|
|
55
51
|
}
|
|
56
52
|
catch (e) {
|
|
@@ -80,10 +76,10 @@ export default function callback(url, res, fn, fn2, ele) {
|
|
|
80
76
|
tmp = res.script(res.data ? res.data : {}, ele || null);
|
|
81
77
|
}
|
|
82
78
|
else {
|
|
83
|
-
tmp = (
|
|
84
|
-
|
|
79
|
+
tmp = ((data, ele) => {
|
|
80
|
+
let r = null;
|
|
85
81
|
try {
|
|
86
|
-
|
|
82
|
+
let fnScript = new Function(res.script);
|
|
87
83
|
r = fnScript();
|
|
88
84
|
if (isFunction(r)) {
|
|
89
85
|
r = r(data, ele);
|
|
@@ -105,7 +101,7 @@ export default function callback(url, res, fn, fn2, ele) {
|
|
|
105
101
|
bbn.fn.defaultPostLinkFunction(res, ele);
|
|
106
102
|
}
|
|
107
103
|
if (tmp && isObj && res.postscript) {
|
|
108
|
-
|
|
104
|
+
let fnPost = new Function(res.postscript);
|
|
109
105
|
fnPost(res.postscript);
|
|
110
106
|
}
|
|
111
107
|
if (isObj && res.error) {
|