@go-avro/avro-js 0.0.78 → 0.0.79

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.
@@ -659,12 +659,13 @@ export declare class AvroQueryClient {
659
659
  headers?: Record<string, string>;
660
660
  progressUpdateCallback?: (loaded: number, total: number) => void;
661
661
  }): Promise<T>;
662
- post<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
662
+ post<T>({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }: {
663
663
  path: string;
664
664
  data?: any;
665
665
  cancelToken?: CancelToken;
666
666
  headers?: Record<string, string>;
667
667
  progressUpdateCallback?: (loaded: number, total: number) => void;
668
+ maxRetries?: number;
668
669
  }): Promise<T>;
669
670
  put<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
670
671
  path: string;
@@ -565,8 +565,8 @@ export class AvroQueryClient {
565
565
  get({ path, cancelToken, headers, progressUpdateCallback, }) {
566
566
  return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
567
567
  }
568
- post({ path, data, cancelToken, headers, progressUpdateCallback, }) {
569
- return this._xhr('POST', path, data, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
568
+ post({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }) {
569
+ return this._xhr('POST', path, data, cancelToken, headers, false, maxRetries ?? this.config.maxRetries, progressUpdateCallback);
570
570
  }
571
571
  put({ path, data, cancelToken, headers, progressUpdateCallback, }) {
572
572
  return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
@@ -930,6 +930,9 @@ export class AvroQueryClient {
930
930
  ...headers,
931
931
  'Content-Type': 'application/json',
932
932
  },
933
+ // Autocomplete is per-keystroke; retrying a down backend just
934
+ // multiplies the load. The next keystroke is the retry.
935
+ maxRetries: 0,
933
936
  });
934
937
  if (!include_census) {
935
938
  return peliasPromise;
@@ -967,6 +970,7 @@ export class AvroQueryClient {
967
970
  ...headers,
968
971
  'Content-Type': 'application/json',
969
972
  },
973
+ maxRetries: 0,
970
974
  });
971
975
  }
972
976
  fetchChats(body = {}, cancelToken, headers = {}) {
@@ -2,13 +2,14 @@ import { AvroQueryClient } from '../../client/QueryClient';
2
2
  import { StandardError } from '../../types/error';
3
3
  import { AuthState } from '../../types/auth';
4
4
  import { AVRO_JS_VERSION } from '../../version';
5
- AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0, progressUpdateCallback) {
5
+ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount, progressUpdateCallback) {
6
+ const maxRetries = retryCount ?? this.config.maxRetries;
6
7
  const checkCancelled = () => {
7
8
  if (cancelToken?.isCancelled()) {
8
9
  throw new StandardError(0, 'Request cancelled');
9
10
  }
10
11
  };
11
- for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
12
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
12
13
  try {
13
14
  checkCancelled();
14
15
  const token = this.getAuthState() === AuthState.AUTHENTICATED
@@ -102,7 +103,7 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
102
103
  throw new StandardError(401, 'Unauthorized (refresh failed)');
103
104
  }
104
105
  }
105
- if (error.status === 401 || attempt >= this.config.maxRetries) {
106
+ if (error.status === 401 || attempt >= maxRetries) {
106
107
  console.error('Not retrying request, throwing error.');
107
108
  throw error;
108
109
  }
@@ -24,6 +24,7 @@ AvroQueryClient.prototype.useAutocompleteAddress = function (address, { size = 1
24
24
  enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
25
25
  placeholderData: keepPreviousData,
26
26
  staleTime: 5 * 60 * 1000,
27
+ retry: false,
27
28
  });
28
29
  };
29
30
  AvroQueryClient.prototype.useSearchAddress = function (address, { focusPointLatitude, focusPointLongitude, minLength = 3, debounceMs = 500, } = {}) {
@@ -39,5 +40,6 @@ AvroQueryClient.prototype.useSearchAddress = function (address, { focusPointLati
39
40
  enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
40
41
  placeholderData: keepPreviousData,
41
42
  staleTime: 5 * 60 * 1000,
43
+ retry: false,
42
44
  });
43
45
  };
@@ -4,7 +4,12 @@ import { Route } from '../../types/api';
4
4
  const dedupeJobTasks = (payload) => payload.jobs
5
5
  ? {
6
6
  ...payload,
7
- jobs: payload.jobs.map((job) => job.tasks ? { ...job, tasks: [...new Set(job.tasks)] } : job),
7
+ jobs: payload.jobs.map((job) => job.tasks
8
+ ? {
9
+ ...job,
10
+ tasks: job.tasks.filter((task, index, all) => all.findIndex((t) => t.id === task.id) === index),
11
+ }
12
+ : job),
8
13
  }
9
14
  : payload;
10
15
  AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
@@ -28,7 +28,7 @@ export class Job {
28
28
  */
29
29
  this.getServiceDuration = (routeJob) => {
30
30
  return routeJob.tasks
31
- .map((tid) => this.tasks.find((t) => t.id === tid)?.service ?? 0)
31
+ .map((rt) => this.tasks.find((t) => t.id === rt.id)?.service ?? 0)
32
32
  .reduce((a, b) => a + b, 0);
33
33
  };
34
34
  /**
@@ -50,7 +50,7 @@ export class Job {
50
50
  if (!routeJob) {
51
51
  return 0;
52
52
  }
53
- const contextTasks = this.tasks.filter((t) => !t.id || routeJob.tasks.includes(t.id));
53
+ const contextTasks = this.tasks.filter((t) => !t.id || routeJob.tasks.some((rt) => rt.id === t.id));
54
54
  if (contextTasks.length === 0) {
55
55
  return 0;
56
56
  }
@@ -7,16 +7,14 @@ declare module '../../types/api/RouteJob' {
7
7
  order: number;
8
8
  estimated_arrival_time: number;
9
9
  scheduled_arrival_time: number;
10
- tasks: string[];
10
+ tasks: RouteJobTask[];
11
11
  }
12
12
  }
13
+ export interface RouteJobTask {
14
+ id: string;
15
+ depends_on: string[];
16
+ }
13
17
  export declare class RouteJob {
14
18
  constructor(init?: Partial<RouteJob>);
15
- /**
16
- * Returns the arrival time the UI should show for this stop:
17
- * `scheduled_arrival_time` if set (>= 0), otherwise the optimizer's
18
- * `estimated_arrival_time`. The sentinel value -1 means "no manual
19
- * schedule, fall back to the optimizer estimate".
20
- */
21
19
  getPredictedArrival: () => number;
22
20
  }
@@ -1,16 +1,13 @@
1
1
  export class RouteJob {
2
2
  constructor(init) {
3
- /**
4
- * Returns the arrival time the UI should show for this stop:
5
- * `scheduled_arrival_time` if set (>= 0), otherwise the optimizer's
6
- * `estimated_arrival_time`. The sentinel value -1 means "no manual
7
- * schedule, fall back to the optimizer estimate".
8
- */
9
3
  this.getPredictedArrival = () => {
10
4
  return this.scheduled_arrival_time === -1
11
5
  ? this.estimated_arrival_time
12
6
  : this.scheduled_arrival_time;
13
7
  };
14
8
  Object.assign(this, init);
9
+ this.tasks = (init?.tasks ?? []).map((t) => typeof t === 'string'
10
+ ? { id: t, depends_on: [] }
11
+ : { ...t, depends_on: t.depends_on ?? [] });
15
12
  }
16
13
  }
@@ -87,7 +87,10 @@ export type RouteScheduleConfig = {
87
87
  schedules: TeamSchedule[];
88
88
  whitelist: string[];
89
89
  blacklist: string[];
90
- tasks: string[];
90
+ tasks: {
91
+ task: string;
92
+ depends_on: string[];
93
+ }[];
91
94
  };
92
95
  export interface Location {
93
96
  accuracy: number;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.78";
1
+ export declare const AVRO_JS_VERSION = "0.0.79";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.0.78';
3
+ export const AVRO_JS_VERSION = '0.0.79';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",