tsense 0.0.11 → 0.0.13

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 (2) hide show
  1. package/dist/tsense.js +4 -9
  2. package/package.json +1 -1
package/dist/tsense.js CHANGED
@@ -382,17 +382,15 @@ export class TSense {
382
382
  yield this.ensureSynced();
383
383
  const limit = Math.min((_a = options.limit) !== null && _a !== void 0 ? _a : 20, 100);
384
384
  const field = options.sort.field;
385
+ const page = options.cursor ? Number(options.cursor) : 1;
385
386
  const params = {
386
387
  q: (_b = options.query) !== null && _b !== void 0 ? _b : "",
387
388
  query_by: ((_c = options.queryBy) !== null && _c !== void 0 ? _c : [this.options.defaultSearchField]).join(","),
388
389
  per_page: limit,
390
+ page,
389
391
  sort_by: `${field}:${options.sort.direction}`,
390
392
  };
391
393
  const filterParts = this.buildFilter(options.filter);
392
- if (options.cursor) {
393
- const op = options.sort.direction === "asc" ? ">" : "<";
394
- filterParts.push(`${field}:${op}${options.cursor}`);
395
- }
396
394
  const filterBy = filterParts.join("&&");
397
395
  if (filterBy)
398
396
  params.filter_by = filterBy;
@@ -403,15 +401,12 @@ export class TSense {
403
401
  });
404
402
  const hits = (_d = res.hits) !== null && _d !== void 0 ? _d : [];
405
403
  const data = [];
406
- const lastHit = hits[hits.length - 1].document;
407
- const nextCursor = String(lastHit[field]);
408
404
  for (const hit of hits) {
409
405
  const doc = this.deserializeDoc(hit.document);
410
406
  data.push(doc);
411
407
  }
412
- if (data.length < limit) {
413
- return { data, nextCursor: null, total: res.found };
414
- }
408
+ const hasMore = page * limit < res.found;
409
+ const nextCursor = hasMore ? String(page + 1) : null;
415
410
  return { data, nextCursor, total: res.found };
416
411
  });
417
412
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsense",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "private": false,
5
5
  "description": "Opinionated, fully typed typesense client",
6
6
  "keywords": [