@go-avro/avro-js 0.0.2-beta.135 → 0.0.2-beta.137
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/dist/client/QueryClient.d.ts +31 -1
- package/dist/client/QueryClient.js +19 -0
- package/dist/client/hooks/groups.d.ts +1 -0
- package/dist/client/hooks/groups.js +130 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
2
|
import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { AuthManager } from '../auth/AuthManager';
|
|
4
|
-
import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill } from '../types/api';
|
|
4
|
+
import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group } from '../types/api';
|
|
5
5
|
import { Tokens } from '../types/auth';
|
|
6
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
@@ -86,6 +86,13 @@ declare module '../client/QueryClient' {
|
|
|
86
86
|
query?: string;
|
|
87
87
|
paid?: boolean;
|
|
88
88
|
}): UseInfiniteQueryResult<InfiniteData<Bill[], unknown>, StandardError>;
|
|
89
|
+
useGetGroups(body: {
|
|
90
|
+
amt?: number;
|
|
91
|
+
known_ids?: string[];
|
|
92
|
+
unknown_ids?: string[];
|
|
93
|
+
query?: string;
|
|
94
|
+
offset?: number;
|
|
95
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Group[], StandardError>;
|
|
89
96
|
useGetPlans(code: string): UseQueryResult<Plan[], StandardError>;
|
|
90
97
|
useGetCompanies(options?: {}): UseQueryResult<Company[], StandardError>;
|
|
91
98
|
useGetAnalytics(): UseQueryResult<any, StandardError>;
|
|
@@ -108,6 +115,11 @@ declare module '../client/QueryClient' {
|
|
|
108
115
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
109
116
|
useGetAvro(): UseQueryResult<Avro, StandardError>;
|
|
110
117
|
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
118
|
+
useCreateGroup(): ReturnType<typeof useMutation<{
|
|
119
|
+
id: string;
|
|
120
|
+
}, StandardError, {
|
|
121
|
+
groupData: Partial<Group>;
|
|
122
|
+
}>>;
|
|
111
123
|
useCreateSkill(): ReturnType<typeof useMutation<{
|
|
112
124
|
id: string;
|
|
113
125
|
}, StandardError, {
|
|
@@ -185,6 +197,12 @@ declare module '../client/QueryClient' {
|
|
|
185
197
|
sessionId: string;
|
|
186
198
|
updates: Partial<Session>;
|
|
187
199
|
}>>;
|
|
200
|
+
useUpdateGroup(): ReturnType<typeof useMutation<{
|
|
201
|
+
msg: string;
|
|
202
|
+
}, StandardError, {
|
|
203
|
+
groupId: string;
|
|
204
|
+
groupData: Partial<Group>;
|
|
205
|
+
}>>;
|
|
188
206
|
useUpdateJob(): ReturnType<typeof useMutation<{
|
|
189
207
|
msg: string;
|
|
190
208
|
}, StandardError, {
|
|
@@ -257,6 +275,11 @@ declare module '../client/QueryClient' {
|
|
|
257
275
|
}, StandardError, {
|
|
258
276
|
userId: string;
|
|
259
277
|
}>>;
|
|
278
|
+
useDeleteGroup(): ReturnType<typeof useMutation<{
|
|
279
|
+
msg: string;
|
|
280
|
+
}, StandardError, {
|
|
281
|
+
groupId: string;
|
|
282
|
+
}>>;
|
|
260
283
|
useDeleteEvent(): ReturnType<typeof useMutation<{
|
|
261
284
|
msg: string;
|
|
262
285
|
}, StandardError, {
|
|
@@ -413,6 +436,13 @@ export declare class AvroQueryClient {
|
|
|
413
436
|
query?: string;
|
|
414
437
|
offset?: number;
|
|
415
438
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
439
|
+
fetchGroups(body?: {
|
|
440
|
+
amt?: number;
|
|
441
|
+
known_ids?: string[];
|
|
442
|
+
unknown_ids?: string[];
|
|
443
|
+
query?: string;
|
|
444
|
+
offset?: number;
|
|
445
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
416
446
|
fetchSkills(body?: {
|
|
417
447
|
amt?: number;
|
|
418
448
|
known_ids?: string[];
|
|
@@ -408,6 +408,25 @@ export class AvroQueryClient {
|
|
|
408
408
|
throw new StandardError(500, 'Failed to fetch teams');
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
|
+
fetchGroups(body = {}, cancelToken, headers = {}) {
|
|
412
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
413
|
+
throw new StandardError(400, 'Company ID is required');
|
|
414
|
+
}
|
|
415
|
+
return this._fetch('POST', `/company/${this.companyId}/groups`, JSON.stringify(body), cancelToken, {
|
|
416
|
+
...headers,
|
|
417
|
+
'Content-Type': 'application/json',
|
|
418
|
+
})
|
|
419
|
+
.then(response => {
|
|
420
|
+
if (!response || !Array.isArray(response)) {
|
|
421
|
+
throw new StandardError(400, 'Invalid groups response');
|
|
422
|
+
}
|
|
423
|
+
return response;
|
|
424
|
+
})
|
|
425
|
+
.catch(err => {
|
|
426
|
+
console.error('Failed to fetch groups:', err);
|
|
427
|
+
throw new StandardError(500, 'Failed to fetch groups');
|
|
428
|
+
});
|
|
429
|
+
}
|
|
411
430
|
fetchSkills(body = {}, cancelToken, headers = {}) {
|
|
412
431
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
413
432
|
throw new StandardError(400, 'Company ID is required');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
AvroQueryClient.prototype.useGetGroups = function (body, total, onProgress) {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: ['groups', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
6
|
+
queryFn: async () => {
|
|
7
|
+
if (typeof total !== "number") {
|
|
8
|
+
return this.fetchGroups({ ...body, offset: 0 });
|
|
9
|
+
}
|
|
10
|
+
onProgress?.(0);
|
|
11
|
+
const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
|
|
12
|
+
let completed = 0;
|
|
13
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchGroups({
|
|
14
|
+
...body,
|
|
15
|
+
offset: i * (body.amt ?? 1),
|
|
16
|
+
}));
|
|
17
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
18
|
+
completed++;
|
|
19
|
+
const fraction = completed / pageCount;
|
|
20
|
+
onProgress?.(fraction);
|
|
21
|
+
return result;
|
|
22
|
+
}));
|
|
23
|
+
const pages = await Promise.all(trackedPromises);
|
|
24
|
+
const groups = pages.flat();
|
|
25
|
+
return groups;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
AvroQueryClient.prototype.useCreateGroup = function () {
|
|
30
|
+
const queryClient = this.getQueryClient();
|
|
31
|
+
return useMutation({
|
|
32
|
+
mutationFn: async ({ groupData }) => {
|
|
33
|
+
return this.post(`/company/${this.companyId}/group`, JSON.stringify(groupData), undefined, { "Content-Type": "application/json" });
|
|
34
|
+
},
|
|
35
|
+
onSettled: () => {
|
|
36
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
37
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
42
|
+
const queryClient = this.getQueryClient();
|
|
43
|
+
return useMutation({
|
|
44
|
+
mutationFn: async ({ groupId, groupData }) => {
|
|
45
|
+
return this.put(`/group/${groupId}`, JSON.stringify(groupData), undefined, { "Content-Type": "application/json" });
|
|
46
|
+
},
|
|
47
|
+
onMutate: async ({ groupId, groupData }) => {
|
|
48
|
+
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
49
|
+
await queryClient.cancelQueries({ queryKey: ['group', groupId] });
|
|
50
|
+
const previousGroups = queryClient.getQueryData(['groups']);
|
|
51
|
+
const previousGroup = queryClient.getQueryData(['group', groupId]);
|
|
52
|
+
queryClient.setQueryData(['group', groupId], (oldData) => {
|
|
53
|
+
if (!oldData)
|
|
54
|
+
return oldData;
|
|
55
|
+
return { ...oldData, ...groupData };
|
|
56
|
+
});
|
|
57
|
+
queryClient.setQueriesData({ queryKey: ['groups'] }, (oldData) => {
|
|
58
|
+
if (!oldData)
|
|
59
|
+
return oldData;
|
|
60
|
+
if (oldData.pages) {
|
|
61
|
+
const updatedPages = oldData.pages.map((page) => page.map((group) => group.id === groupId ? { ...group, ...groupData } : group));
|
|
62
|
+
return { ...oldData, pages: updatedPages };
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(oldData)) {
|
|
65
|
+
return oldData.map((group) => group.id === groupId ? { ...group, ...groupData } : group);
|
|
66
|
+
}
|
|
67
|
+
return oldData;
|
|
68
|
+
});
|
|
69
|
+
return { previousGroups, previousGroup };
|
|
70
|
+
},
|
|
71
|
+
onError: (_err, variables, context) => {
|
|
72
|
+
const { groupId } = variables;
|
|
73
|
+
if (context?.previousGroups) {
|
|
74
|
+
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
75
|
+
}
|
|
76
|
+
if (context?.previousGroup) {
|
|
77
|
+
queryClient.setQueryData(['group', groupId], context.previousGroup);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
onSettled: (_data, _error, variables) => {
|
|
81
|
+
const { groupId } = variables;
|
|
82
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
83
|
+
queryClient.invalidateQueries({ queryKey: ['group', groupId] });
|
|
84
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
89
|
+
const queryClient = this.getQueryClient();
|
|
90
|
+
return useMutation({
|
|
91
|
+
mutationFn: async ({ groupId, }) => {
|
|
92
|
+
return this.delete(`/group/${groupId}`);
|
|
93
|
+
},
|
|
94
|
+
onMutate: async ({ groupId }) => {
|
|
95
|
+
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
96
|
+
await queryClient.cancelQueries({ queryKey: ['group', groupId] });
|
|
97
|
+
const previousGroups = queryClient.getQueryData(['groups']);
|
|
98
|
+
const previousGroup = queryClient.getQueryData(['group', groupId]);
|
|
99
|
+
queryClient.setQueryData(['group', groupId], undefined);
|
|
100
|
+
queryClient.setQueriesData({ queryKey: ['groups'] }, (oldData) => {
|
|
101
|
+
if (!oldData)
|
|
102
|
+
return oldData;
|
|
103
|
+
if (oldData.pages) {
|
|
104
|
+
const updatedPages = oldData.pages.map((page) => page.filter((group) => group.id !== groupId));
|
|
105
|
+
return { ...oldData, pages: updatedPages };
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(oldData)) {
|
|
108
|
+
return oldData.filter((group) => group.id !== groupId);
|
|
109
|
+
}
|
|
110
|
+
return oldData;
|
|
111
|
+
});
|
|
112
|
+
return { previousGroups, previousGroup };
|
|
113
|
+
},
|
|
114
|
+
onError: (_err, variables, context) => {
|
|
115
|
+
const { groupId } = variables;
|
|
116
|
+
if (context?.previousGroups) {
|
|
117
|
+
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
118
|
+
}
|
|
119
|
+
if (context?.previousGroup) {
|
|
120
|
+
queryClient.setQueryData(['group', groupId], context.previousGroup);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onSettled: (_data, _error, variables) => {
|
|
124
|
+
const { groupId } = variables;
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
126
|
+
queryClient.invalidateQueries({ queryKey: ['group', groupId] });
|
|
127
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClientConfig, AvroQueryClient } from './client/QueryClient';
|
|
2
|
-
export { AvroQueryClientProvider } from './client/AvroQueryClientProvider';
|
|
2
|
+
export { AvroQueryClientProvider, useAvroQueryClient } from './client/AvroQueryClientProvider';
|
|
3
3
|
export { AuthManager } from './auth/AuthManager';
|
|
4
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
5
5
|
import './client/core/xhr';
|
|
@@ -20,6 +20,7 @@ import './client/hooks/plans';
|
|
|
20
20
|
import './client/hooks/analytics';
|
|
21
21
|
import './client/hooks/avro';
|
|
22
22
|
import './client/hooks/teams';
|
|
23
|
+
import './client/hooks/groups';
|
|
23
24
|
import './client/hooks/skills';
|
|
24
25
|
export * from './types/api';
|
|
25
26
|
export * from './types/auth';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClient } from './client/QueryClient';
|
|
2
|
-
export { AvroQueryClientProvider } from './client/AvroQueryClientProvider';
|
|
2
|
+
export { AvroQueryClientProvider, useAvroQueryClient } from './client/AvroQueryClientProvider';
|
|
3
3
|
export { AuthManager } from './auth/AuthManager';
|
|
4
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
5
5
|
import './client/core/xhr';
|
|
@@ -20,6 +20,7 @@ import './client/hooks/plans';
|
|
|
20
20
|
import './client/hooks/analytics';
|
|
21
21
|
import './client/hooks/avro';
|
|
22
22
|
import './client/hooks/teams';
|
|
23
|
+
import './client/hooks/groups';
|
|
23
24
|
import './client/hooks/skills';
|
|
24
25
|
export * from './types/api';
|
|
25
26
|
export * from './types/auth';
|