@letarette/client 0.1.5 → 0.1.7

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/agent.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from "events";
3
2
  import { NATSOptions } from "./natshelper";
4
3
  import { SearchResponse } from "./protocol";
package/lib/agent.js CHANGED
@@ -9,10 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.mergeResponses = exports.SearchAgent = void 0;
12
+ exports.SearchAgent = void 0;
13
+ exports.mergeResponses = mergeResponses;
13
14
  const events_1 = require("events");
14
15
  const monitor_1 = require("./monitor");
15
16
  const natshelper_1 = require("./natshelper");
17
+ const protocol_1 = require("./protocol");
16
18
  // A Letarette Search Agent
17
19
  class SearchAgent extends events_1.EventEmitter {
18
20
  constructor(URLs, options = { topic: "leta" }) {
@@ -39,10 +41,12 @@ class SearchAgent extends events_1.EventEmitter {
39
41
  if (this.client === null) {
40
42
  throw new Error("Must be connected");
41
43
  }
44
+ const numShards = yield this.getNumShards();
45
+ const shardedLimit = Math.max(1, Math.trunc(pageLimit / numShards));
42
46
  const req = {
43
47
  Query: query,
44
48
  Spaces: spaces,
45
- PageLimit: pageLimit,
49
+ PageLimit: shardedLimit,
46
50
  PageOffset: pageOffset,
47
51
  Autocorrect: false,
48
52
  };
@@ -54,7 +58,6 @@ class SearchAgent extends events_1.EventEmitter {
54
58
  }
55
59
  reject("Timeout waiting for search response");
56
60
  }, 2000);
57
- const shards = yield this.getNumShards();
58
61
  const inbox = this.client.createInbox();
59
62
  const responses = [];
60
63
  subscription = yield this.client.subscribe(inbox, (err, msg) => {
@@ -63,12 +66,12 @@ class SearchAgent extends events_1.EventEmitter {
63
66
  }
64
67
  const res = msg.data;
65
68
  responses.push(res);
66
- if (responses.length === shards) {
69
+ if (responses.length === numShards) {
67
70
  clearTimeout(timeout);
68
71
  resolve(responses);
69
72
  }
70
- }, { max: shards });
71
- subscription.unsubscribe(shards);
73
+ }, { max: numShards });
74
+ subscription.unsubscribe(numShards);
72
75
  this.client.publish(this.options.topic + ".q", req, inbox);
73
76
  }));
74
77
  const result = yield request;
@@ -107,7 +110,7 @@ function mergeResponses(responses) {
107
110
  Respelt: "",
108
111
  RespeltDistance: 0.0,
109
112
  },
110
- Status: 0,
113
+ Status: protocol_1.SearchStatusCode.NoHit,
111
114
  Duration: 0,
112
115
  };
113
116
  for (const response of responses) {
@@ -133,4 +136,3 @@ function mergeResponses(responses) {
133
136
  });
134
137
  return merged;
135
138
  }
136
- exports.mergeResponses = mergeResponses;
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from "events";
3
2
  import { NATSOptions } from "./natshelper";
4
3
  import { DocumentRequest, DocumentUpdate, IndexUpdate, IndexUpdateRequest } from "./protocol";
5
- export declare type IndexRequestHandler = (req: IndexUpdateRequest) => IndexUpdate;
6
- export declare type DocumentRequestHandler = (req: DocumentRequest) => DocumentUpdate;
4
+ export type IndexRequestHandler = (req: IndexUpdateRequest) => IndexUpdate;
5
+ export type DocumentRequestHandler = (req: DocumentRequest) => DocumentUpdate;
7
6
  export declare class DocumentManager extends EventEmitter {
8
7
  private client;
9
8
  private readonly URLs;
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/lib/monitor.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from "events";
3
2
  import { NATSOptions } from "./natshelper";
4
3
  export declare class Monitor extends EventEmitter {
package/lib/natshelper.js CHANGED
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getMaxPayload = exports.connect = void 0;
12
+ exports.connect = connect;
13
+ exports.getMaxPayload = getMaxPayload;
13
14
  const fs_1 = require("fs");
14
15
  const util_1 = require("util");
15
16
  const ts_nats_1 = require("ts-nats");
@@ -39,9 +40,7 @@ function connect(URLs, options) {
39
40
  return client;
40
41
  });
41
42
  }
42
- exports.connect = connect;
43
43
  function getMaxPayload(client) {
44
44
  const cAsAny = client;
45
45
  return cAsAny.maxPayload || 0;
46
46
  }
47
- exports.getMaxPayload = getMaxPayload;
package/lib/protocol.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type DocumentID = string;
1
+ export type DocumentID = string;
2
2
  export declare const version = "0.5.0";
3
3
  export declare enum IndexStatusCode {
4
4
  InSync = 72,
package/lib/protocol.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchStatusCodeToString = exports.SearchStatusCode = exports.indexStatusCodeToString = exports.IndexStatusCode = exports.version = void 0;
3
+ exports.SearchStatusCode = exports.IndexStatusCode = exports.version = void 0;
4
+ exports.indexStatusCodeToString = indexStatusCodeToString;
5
+ exports.searchStatusCodeToString = searchStatusCodeToString;
4
6
  exports.version = "0.5.0";
5
7
  // Codes returned in index status updates
6
8
  var IndexStatusCode;
@@ -10,7 +12,7 @@ var IndexStatusCode;
10
12
  IndexStatusCode[IndexStatusCode["Syncing"] = 74] = "Syncing";
11
13
  IndexStatusCode[IndexStatusCode["IncompleteShardgroup"] = 75] = "IncompleteShardgroup";
12
14
  IndexStatusCode[IndexStatusCode["IndexStatusIncompatible"] = 76] = "IndexStatusIncompatible";
13
- })(IndexStatusCode = exports.IndexStatusCode || (exports.IndexStatusCode = {}));
15
+ })(IndexStatusCode || (exports.IndexStatusCode = IndexStatusCode = {}));
14
16
  function indexStatusCodeToString(code) {
15
17
  switch (code) {
16
18
  case IndexStatusCode.InSync:
@@ -27,7 +29,6 @@ function indexStatusCodeToString(code) {
27
29
  return `unknown (${code})`;
28
30
  }
29
31
  }
30
- exports.indexStatusCodeToString = indexStatusCodeToString;
31
32
  // Codes returned in search responses
32
33
  var SearchStatusCode;
33
34
  (function (SearchStatusCode) {
@@ -37,7 +38,7 @@ var SearchStatusCode;
37
38
  SearchStatusCode[SearchStatusCode["Timeout"] = 45] = "Timeout";
38
39
  SearchStatusCode[SearchStatusCode["QueryError"] = 46] = "QueryError";
39
40
  SearchStatusCode[SearchStatusCode["ServerError"] = 47] = "ServerError";
40
- })(SearchStatusCode = exports.SearchStatusCode || (exports.SearchStatusCode = {}));
41
+ })(SearchStatusCode || (exports.SearchStatusCode = SearchStatusCode = {}));
41
42
  function searchStatusCodeToString(code) {
42
43
  switch (code) {
43
44
  case SearchStatusCode.NoHit:
@@ -56,4 +57,3 @@ function searchStatusCodeToString(code) {
56
57
  return `unknown (${code})`;
57
58
  }
58
59
  }
59
- exports.searchStatusCodeToString = searchStatusCodeToString;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@letarette/client",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "repository": {
5
5
  "type": "git",
6
- "url": "https://github.com/erkkah/letarette.js"
6
+ "url": "git+https://github.com/erkkah/letarette.js.git"
7
7
  },
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -29,14 +29,13 @@
29
29
  "lint": "tslint -p tsconfig.json"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/jest": "^24.0.23",
33
- "@types/node": "^16.7.10",
34
- "jest": "^26.4.2",
32
+ "@types/jest": "^30.0.0",
33
+ "@types/node": "^25.3.0",
34
+ "jest": "^30.2.0",
35
35
  "minimist": ">=1.2.2",
36
- "ts-jest": "^26.3.0",
36
+ "ts-jest": "^29.4.6",
37
37
  "ts-node": "^10.2.1",
38
- "tslint": "^6.1.3",
39
- "typescript": "^4.4.2"
38
+ "typescript": "^5.9.3"
40
39
  },
41
40
  "dependencies": {
42
41
  "ts-nats": "^1.2.15"