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

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.
@@ -21,7 +21,7 @@ declare module '../client/QueryClient' {
21
21
  getDelay(strategy: RetryStrategy, attempt: number): number;
22
22
  sleep(ms: number): Promise<void>;
23
23
  useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
24
- useGetJobs(total: number, onProgress?: (fraction: number) => void): UseQueryResult<Job[], StandardError>;
24
+ useGetJobs(onProgress?: (fraction: number) => void): UseQueryResult<Job[], StandardError>;
25
25
  getJobsFromCache(): Job[];
26
26
  useGetInfiniteJobs(body: {
27
27
  amt?: number;
@@ -282,6 +282,7 @@ export declare class AvroQueryClient {
282
282
  readonly socket: Socket;
283
283
  _isAuthenticated: boolean;
284
284
  companyId: string | null;
285
+ company: Company | null;
285
286
  constructor(config: AvroQueryClientConfig);
286
287
  emit(eventName: string, data: unknown): void;
287
288
  on<T>(eventName: string, callback: (data: T) => void): void;
@@ -6,6 +6,7 @@ export class AvroQueryClient {
6
6
  constructor(config) {
7
7
  this._isAuthenticated = false;
8
8
  this.companyId = null;
9
+ this.company = null;
9
10
  this.config = {
10
11
  baseUrl: config.baseUrl,
11
12
  authManager: config.authManager,
@@ -27,7 +27,8 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
27
27
  throw new Error("No company ID set and no companies available");
28
28
  }
29
29
  }
30
- return this.get(`/company/${this.companyId}`);
30
+ this.company = await this.get(`/company/${this.companyId}`);
31
+ return this.company;
31
32
  },
32
33
  });
33
34
  };
@@ -1,26 +1,26 @@
1
1
  import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
- AvroQueryClient.prototype.getJobsFromCache = function (total = 0) {
3
+ AvroQueryClient.prototype.getJobsFromCache = function () {
4
4
  const queryClient = this.getQueryClient();
5
- const cachedJobsData = queryClient.getQueryData(['jobs', this.companyId, total]);
5
+ const cachedJobsData = queryClient.getQueryData(['jobs', this.companyId, this.company?.num_jobs]);
6
6
  if (cachedJobsData && cachedJobsData.pages) {
7
7
  return cachedJobsData.pages.flat();
8
8
  }
9
9
  const cachedJobs = queryClient.getQueryData(['jobs', this.companyId]);
10
10
  return cachedJobs || [];
11
11
  };
12
- AvroQueryClient.prototype.useGetJobs = function (total = 0, onProgress) {
12
+ AvroQueryClient.prototype.useGetJobs = function (onProgress) {
13
13
  const queryClient = this.getQueryClient();
14
14
  const amt = 50;
15
15
  return useQuery({
16
- queryKey: ['jobs', this.companyId, total],
16
+ queryKey: ['jobs', this.companyId, this.company?.num_jobs],
17
17
  queryFn: async () => {
18
- if (total === 0) {
18
+ if (this.company?.num_jobs === 0) {
19
19
  onProgress?.(1);
20
20
  return [];
21
21
  }
22
22
  onProgress?.(0);
23
- const pageCount = amt ? Math.ceil(total / amt) : 0;
23
+ const pageCount = amt ? Math.ceil((this.company?.num_jobs ?? 0) / amt) : 0;
24
24
  let completed = 0;
25
25
  const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * amt }));
26
26
  const trackedPromises = promises.map((promise) => promise.then((result) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.120",
3
+ "version": "0.0.2-beta.121",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",