@go-avro/avro-js 0.0.2-beta.121 → 0.0.2-beta.123

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.
@@ -2,12 +2,7 @@ import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.getJobsFromCache = function () {
4
4
  const queryClient = this.getQueryClient();
5
- const cachedJobsData = queryClient.getQueryData(['jobs', this.companyId, this.company?.num_jobs]);
6
- if (cachedJobsData && cachedJobsData.pages) {
7
- return cachedJobsData.pages.flat();
8
- }
9
- const cachedJobs = queryClient.getQueryData(['jobs', this.companyId]);
10
- return cachedJobs || [];
5
+ return (queryClient.getQueryData(['jobs', this.companyId, this.company?.num_jobs]) ?? []);
11
6
  };
12
7
  AvroQueryClient.prototype.useGetJobs = function (onProgress) {
13
8
  const queryClient = this.getQueryClient();
@@ -22,7 +17,7 @@ AvroQueryClient.prototype.useGetJobs = function (onProgress) {
22
17
  onProgress?.(0);
23
18
  const pageCount = amt ? Math.ceil((this.company?.num_jobs ?? 0) / amt) : 0;
24
19
  let completed = 0;
25
- const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * amt }));
20
+ const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * amt, amt }));
26
21
  const trackedPromises = promises.map((promise) => promise.then((result) => {
27
22
  completed++;
28
23
  const fraction = completed / pageCount;
@@ -31,7 +26,12 @@ AvroQueryClient.prototype.useGetJobs = function (onProgress) {
31
26
  }));
32
27
  const pages = await Promise.all(trackedPromises);
33
28
  const jobs = pages.flat();
29
+ const uniqueJobsMap = {};
34
30
  jobs.forEach((job) => {
31
+ uniqueJobsMap[job.id] = job;
32
+ });
33
+ const uniqueJobs = Object.values(uniqueJobsMap);
34
+ uniqueJobs.forEach((job) => {
35
35
  job.current_event = job.tasks.reduce((latest, task) => {
36
36
  return task.current_event && (!latest || task.current_event.time_started > latest.time_started) ? task.current_event : latest;
37
37
  }, null);
@@ -50,7 +50,7 @@ AvroQueryClient.prototype.useGetJobs = function (onProgress) {
50
50
  AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
51
51
  const queryClient = this.getQueryClient();
52
52
  const result = useInfiniteQuery({
53
- queryKey: ['jobs', this.companyId, body.amt ?? 50, body.query ?? "", body.routeId ?? ""],
53
+ queryKey: ['infinite', 'jobs', this.companyId, body.amt ?? 50, body.query ?? "", body.routeId ?? ""],
54
54
  initialPageParam: 0,
55
55
  getNextPageParam: (lastPage, allPages) => {
56
56
  if (lastPage.length < (body.amt ?? 50))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.121",
3
+ "version": "0.0.2-beta.123",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",