@digigov/text-search 0.1.0-8b33e4c8

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.
Files changed (47) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +70 -0
  3. package/cjs/hook.js +65 -0
  4. package/cjs/hook.spec.js +568 -0
  5. package/cjs/index.js +27 -0
  6. package/cjs/search/__tests__/utils.spec.js +84 -0
  7. package/cjs/search/index.js +11 -0
  8. package/cjs/search/lang/gr/encoder.js +28 -0
  9. package/cjs/search/lang/gr/normalization-map.js +107 -0
  10. package/cjs/search/search-index.js +165 -0
  11. package/cjs/search/utils.js +100 -0
  12. package/cjs/test-utils/data.json +552 -0
  13. package/cjs/types.js +5 -0
  14. package/hook.d.ts +19 -0
  15. package/hook.js +54 -0
  16. package/hook.spec.d.ts +1 -0
  17. package/hook.spec.js +560 -0
  18. package/index.d.ts +3 -0
  19. package/index.js +3 -0
  20. package/package.json +22 -0
  21. package/search/__tests__/utils.spec.d.ts +1 -0
  22. package/search/__tests__/utils.spec.js +81 -0
  23. package/search/index.d.ts +2 -0
  24. package/search/index.js +2 -0
  25. package/search/lang/gr/encoder.d.ts +11 -0
  26. package/search/lang/gr/encoder.js +20 -0
  27. package/search/lang/gr/normalization-map.d.ts +100 -0
  28. package/search/lang/gr/normalization-map.js +100 -0
  29. package/search/package.json +6 -0
  30. package/search/search-index.d.ts +42 -0
  31. package/search/search-index.js +150 -0
  32. package/search/utils.d.ts +25 -0
  33. package/search/utils.js +88 -0
  34. package/src/hook.spec.ts +289 -0
  35. package/src/hook.ts +50 -0
  36. package/src/index.ts +4 -0
  37. package/src/search/__tests__/utils.spec.ts +73 -0
  38. package/src/search/index.ts +3 -0
  39. package/src/search/lang/gr/encoder.ts +27 -0
  40. package/src/search/lang/gr/normalization-map.ts +100 -0
  41. package/src/search/search-index.ts +103 -0
  42. package/src/search/utils.ts +72 -0
  43. package/src/test-utils/data.json +552 -0
  44. package/src/types.ts +65 -0
  45. package/test-utils/data.json +552 -0
  46. package/types.d.ts +56 -0
  47. package/types.js +1 -0
@@ -0,0 +1,568 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
+
9
+ var _reactHooks = require("@testing-library/react-hooks");
10
+
11
+ var _hook = _interopRequireDefault(require("./hook"));
12
+
13
+ var _data = _interopRequireDefault(require("./test-utils/data.json"));
14
+
15
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
16
+
17
+ describe('loading', function () {
18
+ it('should start when searching', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
19
+ var _renderHook, result;
20
+
21
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
22
+ while (1) {
23
+ switch (_context.prev = _context.next) {
24
+ case 0:
25
+ _renderHook = (0, _reactHooks.renderHook)(function () {
26
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
27
+ }), result = _renderHook.result;
28
+ expect(result.current.loading).toBe(false);
29
+ (0, _reactHooks.act)(function () {
30
+ return result.current.search();
31
+ });
32
+ expect(result.current.loading).toBe(true);
33
+
34
+ case 4:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }
39
+ }, _callee);
40
+ })));
41
+ it('should stop after search is completed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
42
+ var _renderHook2, result, waitForNextUpdate;
43
+
44
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
45
+ while (1) {
46
+ switch (_context2.prev = _context2.next) {
47
+ case 0:
48
+ _renderHook2 = (0, _reactHooks.renderHook)(function () {
49
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
50
+ }), result = _renderHook2.result, waitForNextUpdate = _renderHook2.waitForNextUpdate;
51
+ expect(result.current.loading).toBe(false);
52
+ (0, _reactHooks.act)(function () {
53
+ return result.current.search();
54
+ });
55
+ expect(result.current.loading).toBe(true);
56
+ _context2.next = 6;
57
+ return waitForNextUpdate();
58
+
59
+ case 6:
60
+ expect(result.current.loading).toBe(false);
61
+
62
+ case 7:
63
+ case "end":
64
+ return _context2.stop();
65
+ }
66
+ }
67
+ }, _callee2);
68
+ })));
69
+ });
70
+ describe('reset', function () {
71
+ it('should change the returned result back to the initial data', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
72
+ var _renderHook3, result, waitForNextUpdate;
73
+
74
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
75
+ while (1) {
76
+ switch (_context3.prev = _context3.next) {
77
+ case 0:
78
+ _renderHook3 = (0, _reactHooks.renderHook)(function () {
79
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
80
+ }), result = _renderHook3.result, waitForNextUpdate = _renderHook3.waitForNextUpdate;
81
+ expect(result.current.loading).toBe(false);
82
+ (0, _reactHooks.act)(function () {
83
+ return result.current.search();
84
+ });
85
+ expect(result.current.loading).toBe(true);
86
+ expect(result.current.data).toEqual(_data["default"]);
87
+ _context3.next = 7;
88
+ return waitForNextUpdate();
89
+
90
+ case 7:
91
+ expect(result.current.loading).toBe(false);
92
+ expect(result.current.data.length).toBe(1);
93
+ (0, _reactHooks.act)(function () {
94
+ return result.current.reset();
95
+ });
96
+ expect(result.current.data).toEqual(_data["default"]);
97
+ expect(result.current.loading).toBe(false);
98
+
99
+ case 12:
100
+ case "end":
101
+ return _context3.stop();
102
+ }
103
+ }
104
+ }, _callee3);
105
+ })));
106
+ });
107
+ describe('search', function () {
108
+ it('should return the initial data when no query is passed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
109
+ var _renderHook4, result;
110
+
111
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
112
+ while (1) {
113
+ switch (_context4.prev = _context4.next) {
114
+ case 0:
115
+ _renderHook4 = (0, _reactHooks.renderHook)(function () {
116
+ return (0, _hook["default"])(_data["default"]);
117
+ }), result = _renderHook4.result;
118
+ expect(result.current.loading).toBe(false);
119
+ (0, _reactHooks.act)(function () {
120
+ return result.current.search();
121
+ });
122
+ expect(result.current.loading).toBe(false);
123
+ expect(result.current.data).toEqual(_data["default"]);
124
+
125
+ case 5:
126
+ case "end":
127
+ return _context4.stop();
128
+ }
129
+ }
130
+ }, _callee4);
131
+ })));
132
+ it('should return an empty array when there are no relevant items', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
133
+ var _renderHook5, result, waitForNextUpdate;
134
+
135
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
136
+ while (1) {
137
+ switch (_context5.prev = _context5.next) {
138
+ case 0:
139
+ _renderHook5 = (0, _reactHooks.renderHook)(function () {
140
+ return (0, _hook["default"])(_data["default"], 'fajsgsdgsdgsd');
141
+ }), result = _renderHook5.result, waitForNextUpdate = _renderHook5.waitForNextUpdate;
142
+ expect(result.current.loading).toBe(false);
143
+ (0, _reactHooks.act)(function () {
144
+ return result.current.search();
145
+ });
146
+ expect(result.current.loading).toBe(true);
147
+ expect(result.current.data).toEqual(_data["default"]);
148
+ _context5.next = 7;
149
+ return waitForNextUpdate();
150
+
151
+ case 7:
152
+ expect(result.current.loading).toBe(false);
153
+ expect(result.current.data).toEqual([]);
154
+
155
+ case 9:
156
+ case "end":
157
+ return _context5.stop();
158
+ }
159
+ }
160
+ }, _callee5);
161
+ })));
162
+ it('should return an empty array when relevant field is not indexed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
163
+ var _renderHook6, result, waitForNextUpdate;
164
+
165
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
166
+ while (1) {
167
+ switch (_context6.prev = _context6.next) {
168
+ case 0:
169
+ _renderHook6 = (0, _reactHooks.renderHook)(function () {
170
+ return (0, _hook["default"])(_data["default"], 'Anastasia', {
171
+ indexing: {
172
+ fields: ['lastName'] // missing 'firstName'
173
+
174
+ }
175
+ });
176
+ }), result = _renderHook6.result, waitForNextUpdate = _renderHook6.waitForNextUpdate;
177
+ expect(result.current.loading).toBe(false);
178
+ (0, _reactHooks.act)(function () {
179
+ return result.current.search();
180
+ });
181
+ expect(result.current.loading).toBe(true);
182
+ expect(result.current.data).toEqual(_data["default"]);
183
+ _context6.next = 7;
184
+ return waitForNextUpdate();
185
+
186
+ case 7:
187
+ expect(result.current.loading).toBe(false);
188
+ expect(result.current.data).toEqual([]);
189
+
190
+ case 9:
191
+ case "end":
192
+ return _context6.stop();
193
+ }
194
+ }
195
+ }, _callee6);
196
+ })));
197
+ it('should return a single result when there is only one relevant item', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
198
+ var _renderHook7, result, waitForNextUpdate, firstResult;
199
+
200
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
201
+ while (1) {
202
+ switch (_context7.prev = _context7.next) {
203
+ case 0:
204
+ _renderHook7 = (0, _reactHooks.renderHook)(function () {
205
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
206
+ }), result = _renderHook7.result, waitForNextUpdate = _renderHook7.waitForNextUpdate;
207
+ expect(result.current.loading).toBe(false);
208
+ (0, _reactHooks.act)(function () {
209
+ return result.current.search();
210
+ });
211
+ expect(result.current.loading).toBe(true);
212
+ expect(result.current.data).toEqual(_data["default"]);
213
+ _context7.next = 7;
214
+ return waitForNextUpdate();
215
+
216
+ case 7:
217
+ expect(result.current.loading).toBe(false);
218
+ expect(result.current.data.length).toBe(1);
219
+ firstResult = result.current.data[0];
220
+ expect(firstResult).toBeDefined();
221
+ expect(Object.values(firstResult).values()).toContain('Anastasia');
222
+
223
+ case 12:
224
+ case "end":
225
+ return _context7.stop();
226
+ }
227
+ }
228
+ }, _callee7);
229
+ })));
230
+ it('should return multiple results when there are multiple relevant items', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
231
+ var _renderHook8, result, waitForNextUpdate;
232
+
233
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
234
+ while (1) {
235
+ switch (_context8.prev = _context8.next) {
236
+ case 0:
237
+ _renderHook8 = (0, _reactHooks.renderHook)(function () {
238
+ return (0, _hook["default"])(_data["default"], 'Kari');
239
+ }), result = _renderHook8.result, waitForNextUpdate = _renderHook8.waitForNextUpdate;
240
+ expect(result.current.loading).toBe(false);
241
+ (0, _reactHooks.act)(function () {
242
+ return result.current.search();
243
+ });
244
+ expect(result.current.loading).toBe(true);
245
+ expect(result.current.data).toEqual(_data["default"]);
246
+ _context8.next = 7;
247
+ return waitForNextUpdate();
248
+
249
+ case 7:
250
+ expect(result.current.loading).toBe(false);
251
+ expect(result.current.data.length).toBeGreaterThanOrEqual(2);
252
+ result.current.data.forEach(function (item) {
253
+ expect(item).toBeDefined();
254
+ expect(Object.values(item).values()).toContain('Kari');
255
+ });
256
+
257
+ case 10:
258
+ case "end":
259
+ return _context8.stop();
260
+ }
261
+ }
262
+ }, _callee8);
263
+ })));
264
+ it('should work with a partial query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
265
+ var _renderHook9, result, waitForNextUpdate, firstResult;
266
+
267
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
268
+ while (1) {
269
+ switch (_context9.prev = _context9.next) {
270
+ case 0:
271
+ _renderHook9 = (0, _reactHooks.renderHook)(function () {
272
+ return (0, _hook["default"])(_data["default"], 'anast');
273
+ }), result = _renderHook9.result, waitForNextUpdate = _renderHook9.waitForNextUpdate;
274
+ expect(result.current.loading).toBe(false);
275
+ (0, _reactHooks.act)(function () {
276
+ return result.current.search();
277
+ });
278
+ expect(result.current.loading).toBe(true);
279
+ expect(result.current.data).toEqual(_data["default"]);
280
+ _context9.next = 7;
281
+ return waitForNextUpdate();
282
+
283
+ case 7:
284
+ expect(result.current.loading).toBe(false);
285
+ expect(result.current.data.length).toBe(1);
286
+ firstResult = result.current.data[0];
287
+ expect(firstResult).toBeDefined();
288
+ expect(Object.values(firstResult).values()).toContain('Anastasia');
289
+
290
+ case 12:
291
+ case "end":
292
+ return _context9.stop();
293
+ }
294
+ }
295
+ }, _callee9);
296
+ })));
297
+ it('should work with nested field if not explicitly stated', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
298
+ var _renderHook10, result, waitForNextUpdate, firstResult;
299
+
300
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
301
+ while (1) {
302
+ switch (_context10.prev = _context10.next) {
303
+ case 0:
304
+ _renderHook10 = (0, _reactHooks.renderHook)(function () {
305
+ return (0, _hook["default"])(_data["default"], 'Titanic');
306
+ }), result = _renderHook10.result, waitForNextUpdate = _renderHook10.waitForNextUpdate;
307
+ expect(result.current.loading).toBe(false);
308
+ (0, _reactHooks.act)(function () {
309
+ return result.current.search();
310
+ });
311
+ expect(result.current.loading).toBe(true);
312
+ expect(result.current.data).toEqual(_data["default"]);
313
+ _context10.next = 7;
314
+ return waitForNextUpdate();
315
+
316
+ case 7:
317
+ expect(result.current.loading).toBe(false);
318
+ expect(result.current.data.length).toBe(1);
319
+ firstResult = result.current.data[0];
320
+ expect(firstResult).toBeDefined();
321
+ expect(Object.values(firstResult.address).values()).toContain('Titanic');
322
+
323
+ case 12:
324
+ case "end":
325
+ return _context10.stop();
326
+ }
327
+ }
328
+ }, _callee10);
329
+ })));
330
+ it('should work with nested field if explicitly stated', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
331
+ var _renderHook11, result, waitForNextUpdate, firstResult;
332
+
333
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
334
+ while (1) {
335
+ switch (_context11.prev = _context11.next) {
336
+ case 0:
337
+ _renderHook11 = (0, _reactHooks.renderHook)(function () {
338
+ return (0, _hook["default"])(_data["default"], 'Titanic', {
339
+ indexing: {
340
+ fields: ['address.city']
341
+ }
342
+ });
343
+ }), result = _renderHook11.result, waitForNextUpdate = _renderHook11.waitForNextUpdate;
344
+ expect(result.current.loading).toBe(false);
345
+ (0, _reactHooks.act)(function () {
346
+ return result.current.search();
347
+ });
348
+ expect(result.current.loading).toBe(true);
349
+ expect(result.current.data).toEqual(_data["default"]);
350
+ _context11.next = 7;
351
+ return waitForNextUpdate();
352
+
353
+ case 7:
354
+ expect(result.current.loading).toBe(false);
355
+ expect(result.current.data.length).toBe(1);
356
+ firstResult = result.current.data[0];
357
+ expect(firstResult).toBeDefined();
358
+ expect(Object.values(firstResult.address).values()).toContain('Titanic');
359
+
360
+ case 12:
361
+ case "end":
362
+ return _context11.stop();
363
+ }
364
+ }
365
+ }, _callee11);
366
+ })));
367
+ it('should work with nested ID', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
368
+ var _renderHook12, result, waitForNextUpdate, firstResult;
369
+
370
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
371
+ while (1) {
372
+ switch (_context12.prev = _context12.next) {
373
+ case 0:
374
+ _renderHook12 = (0, _reactHooks.renderHook)(function () {
375
+ return (0, _hook["default"])(_data["default"], 'Titanic', {
376
+ indexing: {
377
+ idKey: 'address.street'
378
+ }
379
+ });
380
+ }), result = _renderHook12.result, waitForNextUpdate = _renderHook12.waitForNextUpdate;
381
+ expect(result.current.loading).toBe(false);
382
+ (0, _reactHooks.act)(function () {
383
+ return result.current.search();
384
+ });
385
+ expect(result.current.loading).toBe(true);
386
+ expect(result.current.data).toEqual(_data["default"]);
387
+ _context12.next = 7;
388
+ return waitForNextUpdate();
389
+
390
+ case 7:
391
+ expect(result.current.loading).toBe(false);
392
+ expect(result.current.data.length).toBe(1);
393
+ firstResult = result.current.data[0];
394
+ expect(firstResult).toBeDefined();
395
+ expect(Object.values(firstResult.address).values()).toContain('Titanic');
396
+
397
+ case 12:
398
+ case "end":
399
+ return _context12.stop();
400
+ }
401
+ }
402
+ }, _callee12);
403
+ })));
404
+ it('should work with indexed Greek characters and Latin query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
405
+ var _renderHook13, result, waitForNextUpdate, firstResult;
406
+
407
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
408
+ while (1) {
409
+ switch (_context13.prev = _context13.next) {
410
+ case 0:
411
+ _renderHook13 = (0, _reactHooks.renderHook)(function () {
412
+ return (0, _hook["default"])(_data["default"], 'Markos');
413
+ }), result = _renderHook13.result, waitForNextUpdate = _renderHook13.waitForNextUpdate;
414
+ expect(result.current.loading).toBe(false);
415
+ (0, _reactHooks.act)(function () {
416
+ return result.current.search();
417
+ });
418
+ expect(result.current.loading).toBe(true);
419
+ expect(result.current.data).toEqual(_data["default"]);
420
+ _context13.next = 7;
421
+ return waitForNextUpdate();
422
+
423
+ case 7:
424
+ expect(result.current.loading).toBe(false);
425
+ expect(result.current.data.length).toBe(1);
426
+ firstResult = result.current.data[0];
427
+ expect(firstResult).toBeDefined();
428
+ expect(Object.values(firstResult).values()).toContain('Μάρκος');
429
+
430
+ case 12:
431
+ case "end":
432
+ return _context13.stop();
433
+ }
434
+ }
435
+ }, _callee13);
436
+ })));
437
+ it('should work with indexed Greek characters and Greek query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
438
+ var _renderHook14, result, waitForNextUpdate, firstResult;
439
+
440
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
441
+ while (1) {
442
+ switch (_context14.prev = _context14.next) {
443
+ case 0:
444
+ _renderHook14 = (0, _reactHooks.renderHook)(function () {
445
+ return (0, _hook["default"])(_data["default"], 'Μάρκος');
446
+ }), result = _renderHook14.result, waitForNextUpdate = _renderHook14.waitForNextUpdate;
447
+ expect(result.current.loading).toBe(false);
448
+ (0, _reactHooks.act)(function () {
449
+ return result.current.search();
450
+ });
451
+ expect(result.current.loading).toBe(true);
452
+ expect(result.current.data).toEqual(_data["default"]);
453
+ _context14.next = 7;
454
+ return waitForNextUpdate();
455
+
456
+ case 7:
457
+ expect(result.current.loading).toBe(false);
458
+ expect(result.current.data.length).toBe(1);
459
+ firstResult = result.current.data[0];
460
+ expect(firstResult).toBeDefined();
461
+ expect(Object.values(firstResult).values()).toContain('Μάρκος');
462
+
463
+ case 12:
464
+ case "end":
465
+ return _context14.stop();
466
+ }
467
+ }
468
+ }, _callee14);
469
+ })));
470
+ it('should react to changes in the documents list', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
471
+ var emptyDocuments, _renderHook15, result, rerender, waitForNextUpdate, firstResult;
472
+
473
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
474
+ while (1) {
475
+ switch (_context15.prev = _context15.next) {
476
+ case 0:
477
+ emptyDocuments = [];
478
+ _renderHook15 = (0, _reactHooks.renderHook)(function (_ref16) {
479
+ var documents = _ref16.documents;
480
+ return (0, _hook["default"])(documents, 'Anastasia');
481
+ }, {
482
+ initialProps: {
483
+ documents: emptyDocuments
484
+ }
485
+ }), result = _renderHook15.result, rerender = _renderHook15.rerender, waitForNextUpdate = _renderHook15.waitForNextUpdate;
486
+ expect(result.current.loading).toBe(false);
487
+ (0, _reactHooks.act)(function () {
488
+ return result.current.search();
489
+ });
490
+ expect(result.current.loading).toBe(true);
491
+ _context15.next = 7;
492
+ return waitForNextUpdate();
493
+
494
+ case 7:
495
+ expect(result.current.loading).toBe(false);
496
+ expect(result.current.data).toEqual([]);
497
+ rerender({
498
+ documents: _data["default"]
499
+ });
500
+ expect(result.current.loading).toBe(false);
501
+ expect(result.current.data).toEqual([]);
502
+ (0, _reactHooks.act)(function () {
503
+ return result.current.search();
504
+ });
505
+ expect(result.current.loading).toBe(true);
506
+ expect(result.current.data).toEqual([]);
507
+ _context15.next = 17;
508
+ return waitForNextUpdate();
509
+
510
+ case 17:
511
+ expect(result.current.loading).toBe(false);
512
+ expect(result.current.data.length).toBe(1);
513
+ firstResult = result.current.data[0];
514
+ expect(firstResult).toBeDefined();
515
+ expect(Object.values(firstResult).values()).toContain('Anastasia');
516
+
517
+ case 22:
518
+ case "end":
519
+ return _context15.stop();
520
+ }
521
+ }
522
+ }, _callee15);
523
+ })));
524
+ it('should react to changes in the search query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
525
+ var _renderHook16, result, rerender, waitForNextUpdate, firstResult;
526
+
527
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
528
+ while (1) {
529
+ switch (_context16.prev = _context16.next) {
530
+ case 0:
531
+ _renderHook16 = (0, _reactHooks.renderHook)(function (_ref18) {
532
+ var query = _ref18.query;
533
+ return (0, _hook["default"])(_data["default"], query);
534
+ }, {
535
+ initialProps: {
536
+ query: ''
537
+ }
538
+ }), result = _renderHook16.result, rerender = _renderHook16.rerender, waitForNextUpdate = _renderHook16.waitForNextUpdate;
539
+ expect(result.current.loading).toBe(false);
540
+ expect(result.current.data).toEqual(_data["default"]);
541
+ rerender({
542
+ query: 'Anastasia'
543
+ });
544
+ expect(result.current.loading).toBe(false);
545
+ expect(result.current.data).toEqual(_data["default"]);
546
+ (0, _reactHooks.act)(function () {
547
+ return result.current.search();
548
+ });
549
+ expect(result.current.loading).toBe(true);
550
+ expect(result.current.data).toEqual(_data["default"]);
551
+ _context16.next = 11;
552
+ return waitForNextUpdate();
553
+
554
+ case 11:
555
+ expect(result.current.loading).toBe(false);
556
+ expect(result.current.data.length).toBe(1);
557
+ firstResult = result.current.data[0];
558
+ expect(firstResult).toBeDefined();
559
+ expect(Object.values(firstResult).values()).toContain('Anastasia');
560
+
561
+ case 16:
562
+ case "end":
563
+ return _context16.stop();
564
+ }
565
+ }
566
+ }, _callee16);
567
+ })));
568
+ });
package/cjs/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ var _exportNames = {};
9
+ exports["default"] = void 0;
10
+
11
+ var _hook = _interopRequireDefault(require("./hook"));
12
+
13
+ var _search = require("./search");
14
+
15
+ Object.keys(_search).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
18
+ if (key in exports && exports[key] === _search[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function get() {
22
+ return _search[key];
23
+ }
24
+ });
25
+ });
26
+ var _default = _hook["default"];
27
+ exports["default"] = _default;