@go-avro/avro-js 0.0.2-beta.126 → 0.0.2-beta.128

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.
@@ -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 } 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 } 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';
@@ -105,6 +105,11 @@ declare module '../client/QueryClient' {
105
105
  useGetUserSessions(): UseQueryResult<Session[], StandardError>;
106
106
  useGetAvro(): UseQueryResult<Avro, StandardError>;
107
107
  useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
108
+ useCreateSkill(): ReturnType<typeof useMutation<{
109
+ id: string;
110
+ }, StandardError, {
111
+ skillData: Partial<Skill>;
112
+ }>>;
108
113
  useCreateEvent(): ReturnType<typeof useMutation<{
109
114
  id: string;
110
115
  }, StandardError, {
@@ -183,6 +188,12 @@ declare module '../client/QueryClient' {
183
188
  jobId: string;
184
189
  updates: Partial<Job>;
185
190
  }>>;
191
+ useUpdateSkill(): ReturnType<typeof useMutation<{
192
+ msg: string;
193
+ }, StandardError, {
194
+ skillId: string;
195
+ updates: Partial<Skill>;
196
+ }>>;
186
197
  useUpdateBill(): ReturnType<typeof useMutation<{
187
198
  msg: string;
188
199
  }, StandardError, {
@@ -241,7 +252,6 @@ declare module '../client/QueryClient' {
241
252
  useRemoveUserCompany(): ReturnType<typeof useMutation<{
242
253
  msg: string;
243
254
  }, StandardError, {
244
- companyId: string;
245
255
  userId: string;
246
256
  }>>;
247
257
  useDeleteEvent(): ReturnType<typeof useMutation<{
@@ -259,6 +269,11 @@ declare module '../client/QueryClient' {
259
269
  }, StandardError, {
260
270
  routeId: string;
261
271
  }>>;
272
+ useDeleteSkill(): ReturnType<typeof useMutation<{
273
+ msg: string;
274
+ }, StandardError, {
275
+ skillId: string;
276
+ }>>;
262
277
  useDeleteSelf(): ReturnType<typeof useMutation<{
263
278
  msg: string;
264
279
  }, StandardError, void>>;
@@ -81,13 +81,13 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
81
81
  AvroQueryClient.prototype.useRemoveUserCompany = function () {
82
82
  const queryClient = this.getQueryClient();
83
83
  return useMutation({
84
- mutationFn: async ({ companyId, userId }) => {
85
- return this.delete(`/company/${companyId}/user/${userId}`);
84
+ mutationFn: async ({ userId }) => {
85
+ return this.delete(`/company/${this.companyId}/user/${userId}`);
86
86
  },
87
- onMutate: async ({ companyId, userId }) => {
88
- await queryClient.cancelQueries({ queryKey: ['company', companyId] });
89
- const previousCompany = queryClient.getQueryData(['company', companyId]);
90
- queryClient.setQueryData(['company', companyId], (oldData) => {
87
+ onMutate: async ({ userId }) => {
88
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
89
+ const previousCompany = queryClient.getQueryData(['company', this.companyId]);
90
+ queryClient.setQueryData(['company', this.companyId], (oldData) => {
91
91
  if (!oldData)
92
92
  return oldData;
93
93
  return {
@@ -98,14 +98,12 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
98
98
  return { previousCompany };
99
99
  },
100
100
  onError: (err, variables, context) => {
101
- const { companyId } = variables;
102
101
  if (context?.previousCompany) {
103
- queryClient.setQueryData(['company', companyId], context.previousCompany);
102
+ queryClient.setQueryData(['company', this.companyId], context.previousCompany);
104
103
  }
105
104
  },
106
105
  onSettled: (_data, _error, variables) => {
107
- const { companyId } = variables;
108
- queryClient.invalidateQueries({ queryKey: ['company', companyId] });
106
+ queryClient.invalidateQueries({ queryKey: ['company', this.companyId] });
109
107
  },
110
108
  });
111
109
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ import { useMutation } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
+ AvroQueryClient.prototype.useCreateSkill = function () {
4
+ const queryClient = this.getQueryClient();
5
+ return useMutation({
6
+ mutationFn: async ({ skillData }) => {
7
+ return this.post(`/company/${this.companyId}/skill`, JSON.stringify(skillData), undefined, {
8
+ "Content-Type": "application/json",
9
+ });
10
+ },
11
+ onMutate: async ({ skillData }) => {
12
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
13
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId, 'skills'] });
14
+ const previousCompany = queryClient.getQueryData(['company', this.companyId]);
15
+ const previousSkills = queryClient.getQueryData(['company', this.companyId, 'skills']);
16
+ const tempSkill = {
17
+ id: `temp-${Date.now()}`,
18
+ name: skillData.name ?? 'New Skill',
19
+ };
20
+ if (previousCompany) {
21
+ queryClient.setQueryData(['company', this.companyId], {
22
+ ...previousCompany,
23
+ skills: [...(previousCompany.skills || []), tempSkill],
24
+ });
25
+ }
26
+ if (previousSkills) {
27
+ queryClient.setQueryData(['company', this.companyId, 'skills'], [...previousSkills, tempSkill]);
28
+ }
29
+ return { previousCompany, previousSkills };
30
+ },
31
+ onError: (_err, _vars, context) => {
32
+ const companyId = _vars?.companyId;
33
+ if (context?.previousCompany && companyId) {
34
+ queryClient.setQueryData(['company', companyId], context.previousCompany);
35
+ }
36
+ if (context?.previousSkills && companyId) {
37
+ queryClient.setQueryData(['company', companyId, 'skills'], context.previousSkills);
38
+ }
39
+ },
40
+ onSettled: (_data, _error, variables) => {
41
+ const { companyId } = variables;
42
+ queryClient.invalidateQueries({ queryKey: ['company', companyId] });
43
+ queryClient.invalidateQueries({ queryKey: ['company', companyId, 'skills'] });
44
+ },
45
+ });
46
+ };
47
+ AvroQueryClient.prototype.useUpdateSkill = function () {
48
+ const queryClient = this.getQueryClient();
49
+ return useMutation({
50
+ mutationFn: async ({ skillId, updates }) => {
51
+ return this.put(`/company/${this.companyId}/skill/${skillId}`, JSON.stringify(updates), undefined, {
52
+ "Content-Type": "application/json",
53
+ });
54
+ },
55
+ onMutate: async ({ skillId, updates }) => {
56
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
57
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId, 'skills'] });
58
+ const previousCompany = queryClient.getQueryData(['company', this.companyId]);
59
+ const previousSkills = queryClient.getQueryData(['company', this.companyId, 'skills']);
60
+ if (previousCompany) {
61
+ queryClient.setQueryData(['company', this.companyId], {
62
+ ...previousCompany,
63
+ skills: (previousCompany.skills || []).map((s) => (s.id === skillId ? { ...s, ...updates } : s)),
64
+ });
65
+ }
66
+ if (previousSkills) {
67
+ queryClient.setQueryData(['company', this.companyId, 'skills'], previousSkills.map((s) => (s.id === skillId ? { ...s, ...updates } : s)));
68
+ }
69
+ return { previousCompany, previousSkills };
70
+ },
71
+ onError: (_err, variables, context) => {
72
+ const { companyId } = variables;
73
+ if (context?.previousCompany && companyId) {
74
+ queryClient.setQueryData(['company', companyId], context.previousCompany);
75
+ }
76
+ if (context?.previousSkills && companyId) {
77
+ queryClient.setQueryData(['company', companyId, 'skills'], context.previousSkills);
78
+ }
79
+ },
80
+ onSettled: (_data, _error, variables) => {
81
+ const { companyId } = variables;
82
+ queryClient.invalidateQueries({ queryKey: ['company', companyId] });
83
+ queryClient.invalidateQueries({ queryKey: ['company', companyId, 'skills'] });
84
+ },
85
+ });
86
+ };
87
+ AvroQueryClient.prototype.useDeleteSkill = function () {
88
+ const queryClient = this.getQueryClient();
89
+ return useMutation({
90
+ mutationFn: async ({ skillId }) => {
91
+ return this.delete(`/company/${this.companyId}/skill/${skillId}`);
92
+ },
93
+ onMutate: async ({ skillId }) => {
94
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
95
+ await queryClient.cancelQueries({ queryKey: ['company', this.companyId, 'skills'] });
96
+ const previousCompany = queryClient.getQueryData(['company', this.companyId]);
97
+ const previousSkills = queryClient.getQueryData(['company', this.companyId, 'skills']);
98
+ if (previousCompany) {
99
+ queryClient.setQueryData(['company', this.companyId], {
100
+ ...previousCompany,
101
+ skills: (previousCompany.skills || []).filter((s) => s.id !== skillId),
102
+ });
103
+ }
104
+ if (previousSkills) {
105
+ queryClient.setQueryData(['company', this.companyId, 'skills'], previousSkills.filter((s) => s.id !== skillId));
106
+ }
107
+ return { previousCompany, previousSkills };
108
+ },
109
+ onError: (_err, variables, context) => {
110
+ const { companyId } = variables;
111
+ if (context?.previousCompany && companyId) {
112
+ queryClient.setQueryData(['company', companyId], context.previousCompany);
113
+ }
114
+ if (context?.previousSkills && companyId) {
115
+ queryClient.setQueryData(['company', companyId, 'skills'], context.previousSkills);
116
+ }
117
+ },
118
+ onSettled: (_data, _error, variables) => {
119
+ const { companyId } = variables;
120
+ queryClient.invalidateQueries({ queryKey: ['company', companyId] });
121
+ queryClient.invalidateQueries({ queryKey: ['company', companyId, 'skills'] });
122
+ },
123
+ });
124
+ };
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import './client/hooks/plans';
19
19
  import './client/hooks/analytics';
20
20
  import './client/hooks/avro';
21
21
  import './client/hooks/teams';
22
+ import './client/hooks/skills';
22
23
  export * from './types/api';
23
24
  export * from './types/auth';
24
25
  export * from './types/cache';
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ import './client/hooks/plans';
19
19
  import './client/hooks/analytics';
20
20
  import './client/hooks/avro';
21
21
  import './client/hooks/teams';
22
+ import './client/hooks/skills';
22
23
  export * from './types/api';
23
24
  export * from './types/auth';
24
25
  export * from './types/cache';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.126",
3
+ "version": "0.0.2-beta.128",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",