@delali/narsil 0.3.1-next.88 → 0.3.1-next.89

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.
@@ -138,6 +138,8 @@ function toCredentialBuffer(material) {
138
138
  }
139
139
 
140
140
  // src/distribution/transport/grpc/client.ts
141
+ var CONNECT_PROBE_PATH = "/narsil.transport.v1.ConnectProbe/LastError";
142
+ var LAST_ERROR_PATTERN = /Last error: (?:Error: )?(.*?)\. Resolution note:/s;
141
143
  var GrpcClientPool = class {
142
144
  grpc;
143
145
  config;
@@ -276,19 +278,55 @@ var GrpcClientPool = class {
276
278
  }
277
279
  connect(target) {
278
280
  const client = new this.grpc.Client(target, this.credentials(), channelOptions());
281
+ const channel = client.getChannel();
282
+ const { READY, SHUTDOWN, TRANSIENT_FAILURE } = this.grpc.connectivityState;
283
+ const deadline = Date.now() + this.config.connectTimeout;
279
284
  return new Promise((resolve, reject) => {
280
- client.waitForReady(Date.now() + this.config.connectTimeout, (err) => {
281
- if (err === void 0) {
282
- resolve(client);
283
- return;
284
- }
285
+ const fail = (reason) => {
285
286
  client.close();
286
287
  reject(
287
- new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${err.message}`, {
288
+ new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${reason}`, {
288
289
  target
289
290
  })
290
291
  );
291
- });
292
+ };
293
+ const check = (deadlinePassed) => {
294
+ if (deadlinePassed !== void 0) {
295
+ fail(`no connection was ready within ${this.config.connectTimeout}ms`);
296
+ return;
297
+ }
298
+ try {
299
+ const state = channel.getConnectivityState(true);
300
+ if (state === READY) {
301
+ resolve(client);
302
+ } else if (state === TRANSIENT_FAILURE) {
303
+ void this.lastConnectError(client, deadline).then(fail);
304
+ } else if (state === SHUTDOWN) {
305
+ fail("the channel shut down");
306
+ } else {
307
+ channel.watchConnectivityState(state, deadline, check);
308
+ }
309
+ } catch {
310
+ fail("the channel closed");
311
+ }
312
+ };
313
+ check();
314
+ });
315
+ }
316
+ lastConnectError(client, deadline) {
317
+ return new Promise((resolve) => {
318
+ client.makeUnaryRequest(
319
+ CONNECT_PROBE_PATH,
320
+ sendMethod.requestSerialize,
321
+ sendMethod.responseDeserialize,
322
+ new Uint8Array(0),
323
+ this.metadata(),
324
+ { deadline },
325
+ (err) => {
326
+ const details = err?.details ?? "";
327
+ resolve(LAST_ERROR_PATTERN.exec(details)?.[1] ?? (details === "" ? "the channel failed to connect" : details));
328
+ }
329
+ );
292
330
  });
293
331
  }
294
332
  credentials() {
package/dist/react.mjs CHANGED
@@ -729,7 +729,7 @@ function useImport(indexName, options) {
729
729
  inFlight.current = true;
730
730
  client.getTask(taskId, { ...request.current, signal: controller.signal }).then((next) => {
731
731
  setProgress((prev) => {
732
- if (prev.task?.id !== taskId) return prev;
732
+ if (prev.task?.id !== taskId || isTerminalTask(prev.task)) return prev;
733
733
  if (next === null) {
734
734
  return {
735
735
  ...prev,
@@ -744,7 +744,9 @@ function useImport(indexName, options) {
744
744
  });
745
745
  }).catch((err) => {
746
746
  if (controller.signal.aborted) return;
747
- setProgress((prev) => prev.task?.id === taskId ? { ...prev, error: asNarsilError(err, "The import") } : prev);
747
+ setProgress(
748
+ (prev) => prev.task?.id === taskId && !isTerminalTask(prev.task) ? { ...prev, error: asNarsilError(err, "The import") } : prev
749
+ );
748
750
  }).finally(() => {
749
751
  inFlight.current = false;
750
752
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil",
3
- "version": "0.3.1-next.88",
3
+ "version": "0.3.1-next.89",
4
4
  "type": "module",
5
5
  "description": "Distributed search engine with full-text, vector, hybrid, and geosearch. One engine, embedded or on a server, with a cross-language .nrsl format.",
6
6
  "author": "Delali (https://sondelali.com)",
@@ -255,11 +255,11 @@
255
255
  }
256
256
  },
257
257
  "optionalDependencies": {
258
- "@delali/narsil-native-darwin-arm64": "0.3.1-next.88",
259
- "@delali/narsil-native-darwin-x64": "0.3.1-next.88",
260
- "@delali/narsil-native-linux-arm64": "0.3.1-next.88",
261
- "@delali/narsil-native-linux-x64": "0.3.1-next.88",
262
- "@delali/narsil-native-win32-arm64": "0.3.1-next.88",
263
- "@delali/narsil-native-win32-x64": "0.3.1-next.88"
258
+ "@delali/narsil-native-darwin-arm64": "0.3.1-next.89",
259
+ "@delali/narsil-native-darwin-x64": "0.3.1-next.89",
260
+ "@delali/narsil-native-linux-arm64": "0.3.1-next.89",
261
+ "@delali/narsil-native-linux-x64": "0.3.1-next.89",
262
+ "@delali/narsil-native-win32-arm64": "0.3.1-next.89",
263
+ "@delali/narsil-native-win32-x64": "0.3.1-next.89"
264
264
  }
265
265
  }