@inseefr/lunatic 2.6.9 → 2.6.10
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/lib/use-lunatic/use-suggesters.js +40 -31
- package/lib/utils/store-tools/initStore.js +4 -3
- package/lib/utils/store-tools/open-or-create-store.js +3 -3
- package/lib/utils/suggester-workers/searching/searching.js +20 -10
- package/package.json +1 -1
- package/workers-release/lunatic-append-worker-0.3.0-experimental.js +1 -1
- package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +1 -1
|
@@ -80,28 +80,32 @@ function useSuggesters(_ref) {
|
|
|
80
80
|
}
|
|
81
81
|
}, [suggesters, status]);
|
|
82
82
|
(0, _react.useEffect)(function () {
|
|
83
|
-
var aborts =
|
|
83
|
+
var aborts = {
|
|
84
|
+
current: []
|
|
85
|
+
};
|
|
84
86
|
if (typeof getReferentiel === 'function' && Array.isArray(suggesters) && auto) {
|
|
85
|
-
suggesters.
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
89
|
-
var isClean, data, _createAppendTask, _createAppendTask2, append, abort, result;
|
|
87
|
+
var suggesterWorkers = suggesters.map( /*#__PURE__*/function () {
|
|
88
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(store) {
|
|
89
|
+
var name, current, isClean, data, _createAppendTask, _createAppendTask2, append, abort, result;
|
|
90
90
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
91
91
|
while (1) switch (_context.prev = _context.next) {
|
|
92
92
|
case 0:
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
name = store.name;
|
|
94
|
+
current = status.current;
|
|
95
|
+
if (current) {
|
|
96
|
+
_context.next = 4;
|
|
95
97
|
break;
|
|
96
98
|
}
|
|
97
|
-
_context.
|
|
99
|
+
return _context.abrupt("return");
|
|
100
|
+
case 4:
|
|
101
|
+
_context.prev = 4;
|
|
98
102
|
if (!(current[name] === SuggesterStatus.idle)) {
|
|
99
|
-
_context.next =
|
|
103
|
+
_context.next = 10;
|
|
100
104
|
break;
|
|
101
105
|
}
|
|
102
|
-
_context.next =
|
|
106
|
+
_context.next = 8;
|
|
103
107
|
return (0, _initStore.initStore)(store);
|
|
104
|
-
case
|
|
108
|
+
case 8:
|
|
105
109
|
isClean = _context.sent;
|
|
106
110
|
if (!isClean) {
|
|
107
111
|
setStatus(status, name, SuggesterStatus.error);
|
|
@@ -110,20 +114,20 @@ function useSuggesters(_ref) {
|
|
|
110
114
|
setStatus(status, name, SuggesterStatus.pending);
|
|
111
115
|
setTimestamp(Date.now());
|
|
112
116
|
}
|
|
113
|
-
case
|
|
117
|
+
case 10:
|
|
114
118
|
if (!(current[name] === SuggesterStatus.pending)) {
|
|
115
|
-
_context.next =
|
|
119
|
+
_context.next = 20;
|
|
116
120
|
break;
|
|
117
121
|
}
|
|
118
|
-
_context.next =
|
|
122
|
+
_context.next = 13;
|
|
119
123
|
return getReferentiel(name);
|
|
120
|
-
case
|
|
124
|
+
case 13:
|
|
121
125
|
data = _context.sent;
|
|
122
126
|
_createAppendTask = (0, _createAppendTask3.createAppendTask)(store, 1, nothing, workersBasePath), _createAppendTask2 = _slicedToArray(_createAppendTask, 2), append = _createAppendTask2[0], abort = _createAppendTask2[1];
|
|
123
|
-
aborts.push(abort);
|
|
124
|
-
_context.next =
|
|
127
|
+
aborts.current.push(abort);
|
|
128
|
+
_context.next = 18;
|
|
125
129
|
return append(data);
|
|
126
|
-
case
|
|
130
|
+
case 18:
|
|
127
131
|
result = _context.sent;
|
|
128
132
|
if (result) {
|
|
129
133
|
setStatus(status, name, SuggesterStatus.success);
|
|
@@ -132,27 +136,32 @@ function useSuggesters(_ref) {
|
|
|
132
136
|
setStatus(status, name, SuggesterStatus.error);
|
|
133
137
|
setTimestamp(Date.now());
|
|
134
138
|
}
|
|
135
|
-
case
|
|
136
|
-
_context.next =
|
|
139
|
+
case 20:
|
|
140
|
+
_context.next = 27;
|
|
137
141
|
break;
|
|
138
|
-
case
|
|
139
|
-
_context.prev =
|
|
140
|
-
_context.t0 = _context["catch"](
|
|
142
|
+
case 22:
|
|
143
|
+
_context.prev = 22;
|
|
144
|
+
_context.t0 = _context["catch"](4);
|
|
141
145
|
console.error(_context.t0);
|
|
142
146
|
setStatus(status, name, SuggesterStatus.error);
|
|
143
147
|
setTimestamp(Date.now());
|
|
144
|
-
case
|
|
148
|
+
case 27:
|
|
145
149
|
case "end":
|
|
146
150
|
return _context.stop();
|
|
147
151
|
}
|
|
148
|
-
}, _callee, null, [[
|
|
149
|
-
}))
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
}, _callee, null, [[4, 22]]);
|
|
153
|
+
}));
|
|
154
|
+
return function (_x2) {
|
|
155
|
+
return _ref3.apply(this, arguments);
|
|
156
|
+
};
|
|
157
|
+
}());
|
|
158
|
+
var clearWorkers = function clearWorkers() {
|
|
159
|
+
return aborts.current.forEach(function (a) {
|
|
160
|
+
return a();
|
|
154
161
|
});
|
|
155
162
|
};
|
|
163
|
+
Promise.all(suggesterWorkers)["finally"](clearWorkers);
|
|
164
|
+
return clearWorkers;
|
|
156
165
|
}
|
|
157
166
|
}, [suggesters, auto, getReferentiel, status, workersBasePath]);
|
|
158
167
|
return getSuggesterStatus;
|
|
@@ -28,7 +28,7 @@ function _initStore() {
|
|
|
28
28
|
case 3:
|
|
29
29
|
db = _context.sent;
|
|
30
30
|
if (!db) {
|
|
31
|
-
_context.next =
|
|
31
|
+
_context.next = 16;
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
34
|
_context.next = 7;
|
|
@@ -43,10 +43,11 @@ function _initStore() {
|
|
|
43
43
|
return (0, _insertEntity["default"])(db, _constantes["default"].STORE_INFO_NAME, storeInfo);
|
|
44
44
|
case 13:
|
|
45
45
|
c = _context.sent;
|
|
46
|
+
db.close();
|
|
46
47
|
return _context.abrupt("return", a && b && c);
|
|
47
|
-
case 15:
|
|
48
|
-
return _context.abrupt("return", false);
|
|
49
48
|
case 16:
|
|
49
|
+
return _context.abrupt("return", false);
|
|
50
|
+
case 17:
|
|
50
51
|
case "end":
|
|
51
52
|
return _context.stop();
|
|
52
53
|
}
|
|
@@ -9,14 +9,14 @@ var _getIdb = _interopRequireDefault(require("../idb-tools/get-idb"));
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
10
|
/* eslint-disable no-restricted-globals */
|
|
11
11
|
|
|
12
|
-
var IDB_REF = (0, _getIdb["default"])();
|
|
13
12
|
function openStorage(name) {
|
|
14
13
|
var idbVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
15
14
|
return new Promise(function (resolve, reject) {
|
|
16
|
-
|
|
15
|
+
var idb = (0, _getIdb["default"])();
|
|
16
|
+
if (!idb) {
|
|
17
17
|
reject('indexedDb not supported !');
|
|
18
18
|
}
|
|
19
|
-
var request =
|
|
19
|
+
var request = idb.open(name, idbVersion);
|
|
20
20
|
var db;
|
|
21
21
|
var doIt = true;
|
|
22
22
|
request.onupgradeneeded = function (e) {
|
|
@@ -83,14 +83,14 @@ function searching(_x3, _x4) {
|
|
|
83
83
|
}
|
|
84
84
|
function _searching() {
|
|
85
85
|
_searching = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(search, _ref2) {
|
|
86
|
-
var name, _ref2$version, version, _ref2$meloto, meloto, db, info, queryParser, max, order, parser, transaction, store, index,
|
|
86
|
+
var name, _ref2$version, version, _ref2$meloto, meloto, db, info, queryParser, max, order, parser, tokens, transaction, store, index, documents;
|
|
87
87
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
88
88
|
while (1) switch (_context2.prev = _context2.next) {
|
|
89
89
|
case 0:
|
|
90
90
|
name = _ref2.name, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1' : _ref2$version, _ref2$meloto = _ref2.meloto, meloto = _ref2$meloto === void 0 ? true : _ref2$meloto;
|
|
91
91
|
_context2.prev = 1;
|
|
92
92
|
if (!isValideSearch(search)) {
|
|
93
|
-
_context2.next =
|
|
93
|
+
_context2.next = 23;
|
|
94
94
|
break;
|
|
95
95
|
}
|
|
96
96
|
_context2.next = 5;
|
|
@@ -106,34 +106,44 @@ function _searching() {
|
|
|
106
106
|
return (0, _resolveQueryParser["default"])(queryParser);
|
|
107
107
|
case 12:
|
|
108
108
|
parser = _context2.sent;
|
|
109
|
+
tokens = parser(search); // Do not start a transaction if we have nothing to search
|
|
110
|
+
if (!(tokens.length === 0)) {
|
|
111
|
+
_context2.next = 16;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return _context2.abrupt("return", {
|
|
115
|
+
results: [],
|
|
116
|
+
search: search,
|
|
117
|
+
tokens: tokens
|
|
118
|
+
});
|
|
119
|
+
case 16:
|
|
109
120
|
transaction = db.transaction(_storeTools.CONSTANTES.STORE_DATA_NAME, 'readonly');
|
|
110
121
|
store = transaction.objectStore(_storeTools.CONSTANTES.STORE_DATA_NAME);
|
|
111
122
|
index = store.index(_storeTools.CONSTANTES.STORE_INDEX_NAME);
|
|
112
|
-
|
|
113
|
-
_context2.next = 19;
|
|
123
|
+
_context2.next = 21;
|
|
114
124
|
return searchTokens(tokens, index);
|
|
115
|
-
case
|
|
125
|
+
case 21:
|
|
116
126
|
documents = _context2.sent;
|
|
117
127
|
return _context2.abrupt("return", {
|
|
118
128
|
results: prepare((0, _order["default"])(order)(filterSize((0, _computeScore["default"])(documents, tokens, meloto), max), order)),
|
|
119
129
|
search: search,
|
|
120
130
|
tokens: tokens
|
|
121
131
|
});
|
|
122
|
-
case
|
|
132
|
+
case 23:
|
|
123
133
|
return _context2.abrupt("return", {
|
|
124
134
|
results: [],
|
|
125
135
|
search: search
|
|
126
136
|
});
|
|
127
|
-
case
|
|
128
|
-
_context2.prev =
|
|
137
|
+
case 26:
|
|
138
|
+
_context2.prev = 26;
|
|
129
139
|
_context2.t0 = _context2["catch"](1);
|
|
130
140
|
console.error(_context2.t0);
|
|
131
141
|
throw _context2.t0;
|
|
132
|
-
case
|
|
142
|
+
case 30:
|
|
133
143
|
case "end":
|
|
134
144
|
return _context2.stop();
|
|
135
145
|
}
|
|
136
|
-
}, _callee2, null, [[1,
|
|
146
|
+
}, _callee2, null, [[1, 26]]);
|
|
137
147
|
}));
|
|
138
148
|
return _searching.apply(this, arguments);
|
|
139
149
|
}
|