@digigov/text-search 0.1.0-a131264d → 0.1.0-b0737a96

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.
@@ -1,6 +1,17 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { useCallback, useMemo, useState } from 'react';
3
- import SearchIndex from "./search";
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = useSearch;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _search = _interopRequireDefault(require("./search"));
4
15
 
5
16
  /**
6
17
  * Hook for searching through a list of documents
@@ -14,22 +25,22 @@ import SearchIndex from "./search";
14
25
  *
15
26
  * @typeParam T - The type of the data in the documents list
16
27
  */
17
- export default function useSearch(documents, query, options) {
18
- var _useState = useState(false),
19
- _useState2 = _slicedToArray(_useState, 2),
28
+ function useSearch(documents, query, options) {
29
+ var _useState = (0, _react.useState)(false),
30
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
20
31
  loading = _useState2[0],
21
32
  setLoading = _useState2[1];
22
33
 
23
- var _useState3 = useState(documents),
24
- _useState4 = _slicedToArray(_useState3, 2),
34
+ var _useState3 = (0, _react.useState)(documents),
35
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
25
36
  data = _useState4[0],
26
37
  setData = _useState4[1];
27
38
 
28
39
  var indexing = options === null || options === void 0 ? void 0 : options.indexing;
29
- var index = useMemo(function () {
30
- return new SearchIndex(documents, indexing);
40
+ var index = (0, _react.useMemo)(function () {
41
+ return new _search["default"](documents, indexing);
31
42
  }, [documents, indexing]);
32
- var search = useCallback(function () {
43
+ var search = (0, _react.useCallback)(function () {
33
44
  if (query) {
34
45
  setLoading(true);
35
46
  index.searchAsync(documents, query).then(function (data) {
@@ -41,7 +52,7 @@ export default function useSearch(documents, query, options) {
41
52
  setData(documents);
42
53
  }
43
54
  }, [query, index, documents]);
44
- var reset = useCallback(function () {
55
+ var reset = (0, _react.useCallback)(function () {
45
56
  setData(documents);
46
57
  setLoading(false);
47
58
  }, [documents]);
@@ -1,24 +1,32 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
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"));
3
14
 
4
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; }
5
16
 
6
- import { act, renderHook } from '@testing-library/react-hooks';
7
- import useSearch from "./hook";
8
- import documents from "./test-utils/data.json";
9
17
  describe('loading', function () {
10
- it('should start when searching', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
18
+ it('should start when searching', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
11
19
  var _renderHook, result;
12
20
 
13
21
  return _regeneratorRuntime().wrap(function _callee$(_context) {
14
22
  while (1) {
15
23
  switch (_context.prev = _context.next) {
16
24
  case 0:
17
- _renderHook = renderHook(function () {
18
- return useSearch(documents, 'Anastasia');
25
+ _renderHook = (0, _reactHooks.renderHook)(function () {
26
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
19
27
  }), result = _renderHook.result;
20
28
  expect(result.current.loading).toBe(false);
21
- act(function () {
29
+ (0, _reactHooks.act)(function () {
22
30
  return result.current.search();
23
31
  });
24
32
  expect(result.current.loading).toBe(true);
@@ -30,18 +38,18 @@ describe('loading', function () {
30
38
  }
31
39
  }, _callee);
32
40
  })));
33
- it('should stop after search is completed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
41
+ it('should stop after search is completed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
34
42
  var _renderHook2, result, waitForNextUpdate;
35
43
 
36
44
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
37
45
  while (1) {
38
46
  switch (_context2.prev = _context2.next) {
39
47
  case 0:
40
- _renderHook2 = renderHook(function () {
41
- return useSearch(documents, 'Anastasia');
48
+ _renderHook2 = (0, _reactHooks.renderHook)(function () {
49
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
42
50
  }), result = _renderHook2.result, waitForNextUpdate = _renderHook2.waitForNextUpdate;
43
51
  expect(result.current.loading).toBe(false);
44
- act(function () {
52
+ (0, _reactHooks.act)(function () {
45
53
  return result.current.search();
46
54
  });
47
55
  expect(result.current.loading).toBe(true);
@@ -60,32 +68,32 @@ describe('loading', function () {
60
68
  })));
61
69
  });
62
70
  describe('reset', function () {
63
- it('should change the returned result back to the initial data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
71
+ it('should change the returned result back to the initial data', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
64
72
  var _renderHook3, result, waitForNextUpdate;
65
73
 
66
74
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
67
75
  while (1) {
68
76
  switch (_context3.prev = _context3.next) {
69
77
  case 0:
70
- _renderHook3 = renderHook(function () {
71
- return useSearch(documents, 'Anastasia');
78
+ _renderHook3 = (0, _reactHooks.renderHook)(function () {
79
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
72
80
  }), result = _renderHook3.result, waitForNextUpdate = _renderHook3.waitForNextUpdate;
73
81
  expect(result.current.loading).toBe(false);
74
- act(function () {
82
+ (0, _reactHooks.act)(function () {
75
83
  return result.current.search();
76
84
  });
77
85
  expect(result.current.loading).toBe(true);
78
- expect(result.current.data).toEqual(documents);
86
+ expect(result.current.data).toEqual(_data["default"]);
79
87
  _context3.next = 7;
80
88
  return waitForNextUpdate();
81
89
 
82
90
  case 7:
83
91
  expect(result.current.loading).toBe(false);
84
92
  expect(result.current.data.length).toBe(1);
85
- act(function () {
93
+ (0, _reactHooks.act)(function () {
86
94
  return result.current.reset();
87
95
  });
88
- expect(result.current.data).toEqual(documents);
96
+ expect(result.current.data).toEqual(_data["default"]);
89
97
  expect(result.current.loading).toBe(false);
90
98
 
91
99
  case 12:
@@ -97,22 +105,22 @@ describe('reset', function () {
97
105
  })));
98
106
  });
99
107
  describe('search', function () {
100
- it('should return the initial data when no query is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
108
+ it('should return the initial data when no query is passed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
101
109
  var _renderHook4, result;
102
110
 
103
111
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
104
112
  while (1) {
105
113
  switch (_context4.prev = _context4.next) {
106
114
  case 0:
107
- _renderHook4 = renderHook(function () {
108
- return useSearch(documents);
115
+ _renderHook4 = (0, _reactHooks.renderHook)(function () {
116
+ return (0, _hook["default"])(_data["default"]);
109
117
  }), result = _renderHook4.result;
110
118
  expect(result.current.loading).toBe(false);
111
- act(function () {
119
+ (0, _reactHooks.act)(function () {
112
120
  return result.current.search();
113
121
  });
114
122
  expect(result.current.loading).toBe(false);
115
- expect(result.current.data).toEqual(documents);
123
+ expect(result.current.data).toEqual(_data["default"]);
116
124
 
117
125
  case 5:
118
126
  case "end":
@@ -121,22 +129,22 @@ describe('search', function () {
121
129
  }
122
130
  }, _callee4);
123
131
  })));
124
- it('should return an empty array when there are no relevant items', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
132
+ it('should return an empty array when there are no relevant items', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
125
133
  var _renderHook5, result, waitForNextUpdate;
126
134
 
127
135
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
128
136
  while (1) {
129
137
  switch (_context5.prev = _context5.next) {
130
138
  case 0:
131
- _renderHook5 = renderHook(function () {
132
- return useSearch(documents, 'fajsgsdgsdgsd');
139
+ _renderHook5 = (0, _reactHooks.renderHook)(function () {
140
+ return (0, _hook["default"])(_data["default"], 'fajsgsdgsdgsd');
133
141
  }), result = _renderHook5.result, waitForNextUpdate = _renderHook5.waitForNextUpdate;
134
142
  expect(result.current.loading).toBe(false);
135
- act(function () {
143
+ (0, _reactHooks.act)(function () {
136
144
  return result.current.search();
137
145
  });
138
146
  expect(result.current.loading).toBe(true);
139
- expect(result.current.data).toEqual(documents);
147
+ expect(result.current.data).toEqual(_data["default"]);
140
148
  _context5.next = 7;
141
149
  return waitForNextUpdate();
142
150
 
@@ -151,15 +159,15 @@ describe('search', function () {
151
159
  }
152
160
  }, _callee5);
153
161
  })));
154
- it('should return an empty array when relevant field is not indexed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
162
+ it('should return an empty array when relevant field is not indexed', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
155
163
  var _renderHook6, result, waitForNextUpdate;
156
164
 
157
165
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
158
166
  while (1) {
159
167
  switch (_context6.prev = _context6.next) {
160
168
  case 0:
161
- _renderHook6 = renderHook(function () {
162
- return useSearch(documents, 'Anastasia', {
169
+ _renderHook6 = (0, _reactHooks.renderHook)(function () {
170
+ return (0, _hook["default"])(_data["default"], 'Anastasia', {
163
171
  indexing: {
164
172
  fields: ['lastName'] // missing 'firstName'
165
173
 
@@ -167,11 +175,11 @@ describe('search', function () {
167
175
  });
168
176
  }), result = _renderHook6.result, waitForNextUpdate = _renderHook6.waitForNextUpdate;
169
177
  expect(result.current.loading).toBe(false);
170
- act(function () {
178
+ (0, _reactHooks.act)(function () {
171
179
  return result.current.search();
172
180
  });
173
181
  expect(result.current.loading).toBe(true);
174
- expect(result.current.data).toEqual(documents);
182
+ expect(result.current.data).toEqual(_data["default"]);
175
183
  _context6.next = 7;
176
184
  return waitForNextUpdate();
177
185
 
@@ -186,22 +194,22 @@ describe('search', function () {
186
194
  }
187
195
  }, _callee6);
188
196
  })));
189
- it('should return a single result when there is only one relevant item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
197
+ it('should return a single result when there is only one relevant item', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
190
198
  var _renderHook7, result, waitForNextUpdate, firstResult;
191
199
 
192
200
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
193
201
  while (1) {
194
202
  switch (_context7.prev = _context7.next) {
195
203
  case 0:
196
- _renderHook7 = renderHook(function () {
197
- return useSearch(documents, 'Anastasia');
204
+ _renderHook7 = (0, _reactHooks.renderHook)(function () {
205
+ return (0, _hook["default"])(_data["default"], 'Anastasia');
198
206
  }), result = _renderHook7.result, waitForNextUpdate = _renderHook7.waitForNextUpdate;
199
207
  expect(result.current.loading).toBe(false);
200
- act(function () {
208
+ (0, _reactHooks.act)(function () {
201
209
  return result.current.search();
202
210
  });
203
211
  expect(result.current.loading).toBe(true);
204
- expect(result.current.data).toEqual(documents);
212
+ expect(result.current.data).toEqual(_data["default"]);
205
213
  _context7.next = 7;
206
214
  return waitForNextUpdate();
207
215
 
@@ -219,22 +227,22 @@ describe('search', function () {
219
227
  }
220
228
  }, _callee7);
221
229
  })));
222
- it('should return multiple results when there are multiple relevant items', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
230
+ it('should return multiple results when there are multiple relevant items', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
223
231
  var _renderHook8, result, waitForNextUpdate;
224
232
 
225
233
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
226
234
  while (1) {
227
235
  switch (_context8.prev = _context8.next) {
228
236
  case 0:
229
- _renderHook8 = renderHook(function () {
230
- return useSearch(documents, 'Kari');
237
+ _renderHook8 = (0, _reactHooks.renderHook)(function () {
238
+ return (0, _hook["default"])(_data["default"], 'Kari');
231
239
  }), result = _renderHook8.result, waitForNextUpdate = _renderHook8.waitForNextUpdate;
232
240
  expect(result.current.loading).toBe(false);
233
- act(function () {
241
+ (0, _reactHooks.act)(function () {
234
242
  return result.current.search();
235
243
  });
236
244
  expect(result.current.loading).toBe(true);
237
- expect(result.current.data).toEqual(documents);
245
+ expect(result.current.data).toEqual(_data["default"]);
238
246
  _context8.next = 7;
239
247
  return waitForNextUpdate();
240
248
 
@@ -253,22 +261,22 @@ describe('search', function () {
253
261
  }
254
262
  }, _callee8);
255
263
  })));
256
- it('should work with a partial query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
264
+ it('should work with a partial query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
257
265
  var _renderHook9, result, waitForNextUpdate, firstResult;
258
266
 
259
267
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
260
268
  while (1) {
261
269
  switch (_context9.prev = _context9.next) {
262
270
  case 0:
263
- _renderHook9 = renderHook(function () {
264
- return useSearch(documents, 'anast');
271
+ _renderHook9 = (0, _reactHooks.renderHook)(function () {
272
+ return (0, _hook["default"])(_data["default"], 'anast');
265
273
  }), result = _renderHook9.result, waitForNextUpdate = _renderHook9.waitForNextUpdate;
266
274
  expect(result.current.loading).toBe(false);
267
- act(function () {
275
+ (0, _reactHooks.act)(function () {
268
276
  return result.current.search();
269
277
  });
270
278
  expect(result.current.loading).toBe(true);
271
- expect(result.current.data).toEqual(documents);
279
+ expect(result.current.data).toEqual(_data["default"]);
272
280
  _context9.next = 7;
273
281
  return waitForNextUpdate();
274
282
 
@@ -286,22 +294,22 @@ describe('search', function () {
286
294
  }
287
295
  }, _callee9);
288
296
  })));
289
- it('should work with nested field if not explicitly stated', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
297
+ it('should work with nested field if not explicitly stated', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
290
298
  var _renderHook10, result, waitForNextUpdate, firstResult;
291
299
 
292
300
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
293
301
  while (1) {
294
302
  switch (_context10.prev = _context10.next) {
295
303
  case 0:
296
- _renderHook10 = renderHook(function () {
297
- return useSearch(documents, 'Titanic');
304
+ _renderHook10 = (0, _reactHooks.renderHook)(function () {
305
+ return (0, _hook["default"])(_data["default"], 'Titanic');
298
306
  }), result = _renderHook10.result, waitForNextUpdate = _renderHook10.waitForNextUpdate;
299
307
  expect(result.current.loading).toBe(false);
300
- act(function () {
308
+ (0, _reactHooks.act)(function () {
301
309
  return result.current.search();
302
310
  });
303
311
  expect(result.current.loading).toBe(true);
304
- expect(result.current.data).toEqual(documents);
312
+ expect(result.current.data).toEqual(_data["default"]);
305
313
  _context10.next = 7;
306
314
  return waitForNextUpdate();
307
315
 
@@ -319,26 +327,26 @@ describe('search', function () {
319
327
  }
320
328
  }, _callee10);
321
329
  })));
322
- it('should work with nested field if explicitly stated', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
330
+ it('should work with nested field if explicitly stated', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
323
331
  var _renderHook11, result, waitForNextUpdate, firstResult;
324
332
 
325
333
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
326
334
  while (1) {
327
335
  switch (_context11.prev = _context11.next) {
328
336
  case 0:
329
- _renderHook11 = renderHook(function () {
330
- return useSearch(documents, 'Titanic', {
337
+ _renderHook11 = (0, _reactHooks.renderHook)(function () {
338
+ return (0, _hook["default"])(_data["default"], 'Titanic', {
331
339
  indexing: {
332
340
  fields: ['address.city']
333
341
  }
334
342
  });
335
343
  }), result = _renderHook11.result, waitForNextUpdate = _renderHook11.waitForNextUpdate;
336
344
  expect(result.current.loading).toBe(false);
337
- act(function () {
345
+ (0, _reactHooks.act)(function () {
338
346
  return result.current.search();
339
347
  });
340
348
  expect(result.current.loading).toBe(true);
341
- expect(result.current.data).toEqual(documents);
349
+ expect(result.current.data).toEqual(_data["default"]);
342
350
  _context11.next = 7;
343
351
  return waitForNextUpdate();
344
352
 
@@ -356,26 +364,26 @@ describe('search', function () {
356
364
  }
357
365
  }, _callee11);
358
366
  })));
359
- it('should work with nested ID', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
367
+ it('should work with nested ID', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
360
368
  var _renderHook12, result, waitForNextUpdate, firstResult;
361
369
 
362
370
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
363
371
  while (1) {
364
372
  switch (_context12.prev = _context12.next) {
365
373
  case 0:
366
- _renderHook12 = renderHook(function () {
367
- return useSearch(documents, 'Titanic', {
374
+ _renderHook12 = (0, _reactHooks.renderHook)(function () {
375
+ return (0, _hook["default"])(_data["default"], 'Titanic', {
368
376
  indexing: {
369
377
  idKey: 'address.street'
370
378
  }
371
379
  });
372
380
  }), result = _renderHook12.result, waitForNextUpdate = _renderHook12.waitForNextUpdate;
373
381
  expect(result.current.loading).toBe(false);
374
- act(function () {
382
+ (0, _reactHooks.act)(function () {
375
383
  return result.current.search();
376
384
  });
377
385
  expect(result.current.loading).toBe(true);
378
- expect(result.current.data).toEqual(documents);
386
+ expect(result.current.data).toEqual(_data["default"]);
379
387
  _context12.next = 7;
380
388
  return waitForNextUpdate();
381
389
 
@@ -393,22 +401,22 @@ describe('search', function () {
393
401
  }
394
402
  }, _callee12);
395
403
  })));
396
- it('should work with indexed Greek characters and Latin query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
404
+ it('should work with indexed Greek characters and Latin query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
397
405
  var _renderHook13, result, waitForNextUpdate, firstResult;
398
406
 
399
407
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
400
408
  while (1) {
401
409
  switch (_context13.prev = _context13.next) {
402
410
  case 0:
403
- _renderHook13 = renderHook(function () {
404
- return useSearch(documents, 'Markos');
411
+ _renderHook13 = (0, _reactHooks.renderHook)(function () {
412
+ return (0, _hook["default"])(_data["default"], 'Markos');
405
413
  }), result = _renderHook13.result, waitForNextUpdate = _renderHook13.waitForNextUpdate;
406
414
  expect(result.current.loading).toBe(false);
407
- act(function () {
415
+ (0, _reactHooks.act)(function () {
408
416
  return result.current.search();
409
417
  });
410
418
  expect(result.current.loading).toBe(true);
411
- expect(result.current.data).toEqual(documents);
419
+ expect(result.current.data).toEqual(_data["default"]);
412
420
  _context13.next = 7;
413
421
  return waitForNextUpdate();
414
422
 
@@ -426,22 +434,22 @@ describe('search', function () {
426
434
  }
427
435
  }, _callee13);
428
436
  })));
429
- it('should work with indexed Greek characters and Greek query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
437
+ it('should work with indexed Greek characters and Greek query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
430
438
  var _renderHook14, result, waitForNextUpdate, firstResult;
431
439
 
432
440
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
433
441
  while (1) {
434
442
  switch (_context14.prev = _context14.next) {
435
443
  case 0:
436
- _renderHook14 = renderHook(function () {
437
- return useSearch(documents, 'Μάρκος');
444
+ _renderHook14 = (0, _reactHooks.renderHook)(function () {
445
+ return (0, _hook["default"])(_data["default"], 'Μάρκος');
438
446
  }), result = _renderHook14.result, waitForNextUpdate = _renderHook14.waitForNextUpdate;
439
447
  expect(result.current.loading).toBe(false);
440
- act(function () {
448
+ (0, _reactHooks.act)(function () {
441
449
  return result.current.search();
442
450
  });
443
451
  expect(result.current.loading).toBe(true);
444
- expect(result.current.data).toEqual(documents);
452
+ expect(result.current.data).toEqual(_data["default"]);
445
453
  _context14.next = 7;
446
454
  return waitForNextUpdate();
447
455
 
@@ -459,7 +467,7 @@ describe('search', function () {
459
467
  }
460
468
  }, _callee14);
461
469
  })));
462
- it('should react to changes in the documents list', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
470
+ it('should react to changes in the documents list', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
463
471
  var emptyDocuments, _renderHook15, result, rerender, waitForNextUpdate, firstResult;
464
472
 
465
473
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
@@ -467,16 +475,16 @@ describe('search', function () {
467
475
  switch (_context15.prev = _context15.next) {
468
476
  case 0:
469
477
  emptyDocuments = [];
470
- _renderHook15 = renderHook(function (_ref16) {
478
+ _renderHook15 = (0, _reactHooks.renderHook)(function (_ref16) {
471
479
  var documents = _ref16.documents;
472
- return useSearch(documents, 'Anastasia');
480
+ return (0, _hook["default"])(documents, 'Anastasia');
473
481
  }, {
474
482
  initialProps: {
475
483
  documents: emptyDocuments
476
484
  }
477
485
  }), result = _renderHook15.result, rerender = _renderHook15.rerender, waitForNextUpdate = _renderHook15.waitForNextUpdate;
478
486
  expect(result.current.loading).toBe(false);
479
- act(function () {
487
+ (0, _reactHooks.act)(function () {
480
488
  return result.current.search();
481
489
  });
482
490
  expect(result.current.loading).toBe(true);
@@ -487,11 +495,11 @@ describe('search', function () {
487
495
  expect(result.current.loading).toBe(false);
488
496
  expect(result.current.data).toEqual([]);
489
497
  rerender({
490
- documents: documents
498
+ documents: _data["default"]
491
499
  });
492
500
  expect(result.current.loading).toBe(false);
493
501
  expect(result.current.data).toEqual([]);
494
- act(function () {
502
+ (0, _reactHooks.act)(function () {
495
503
  return result.current.search();
496
504
  });
497
505
  expect(result.current.loading).toBe(true);
@@ -513,33 +521,33 @@ describe('search', function () {
513
521
  }
514
522
  }, _callee15);
515
523
  })));
516
- it('should react to changes in the search query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
524
+ it('should react to changes in the search query', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
517
525
  var _renderHook16, result, rerender, waitForNextUpdate, firstResult;
518
526
 
519
527
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
520
528
  while (1) {
521
529
  switch (_context16.prev = _context16.next) {
522
530
  case 0:
523
- _renderHook16 = renderHook(function (_ref18) {
531
+ _renderHook16 = (0, _reactHooks.renderHook)(function (_ref18) {
524
532
  var query = _ref18.query;
525
- return useSearch(documents, query);
533
+ return (0, _hook["default"])(_data["default"], query);
526
534
  }, {
527
535
  initialProps: {
528
536
  query: ''
529
537
  }
530
538
  }), result = _renderHook16.result, rerender = _renderHook16.rerender, waitForNextUpdate = _renderHook16.waitForNextUpdate;
531
539
  expect(result.current.loading).toBe(false);
532
- expect(result.current.data).toEqual(documents);
540
+ expect(result.current.data).toEqual(_data["default"]);
533
541
  rerender({
534
542
  query: 'Anastasia'
535
543
  });
536
544
  expect(result.current.loading).toBe(false);
537
- expect(result.current.data).toEqual(documents);
538
- act(function () {
545
+ expect(result.current.data).toEqual(_data["default"]);
546
+ (0, _reactHooks.act)(function () {
539
547
  return result.current.search();
540
548
  });
541
549
  expect(result.current.loading).toBe(true);
542
- expect(result.current.data).toEqual(documents);
550
+ expect(result.current.data).toEqual(_data["default"]);
543
551
  _context16.next = 11;
544
552
  return waitForNextUpdate();
545
553
 
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;