@go-avro/avro-js 1.6.0 → 1.6.1
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 +12 -1
- package/dist/client/QueryClient.js +39 -16
- package/dist/client/hooks/events.js +10 -14
- package/dist/client/hooks/messages.js +18 -16
- package/dist/client/hooks/sessions.js +12 -6
- package/dist/client/realtime.js +4 -2
- package/dist/types/api/Bill.js +2 -1
- package/dist/types/api/Job.js +2 -1
- package/dist/types/api/LineItem.js +2 -1
- package/dist/types/api/Prepayment.js +2 -1
- package/dist/types/api/Route.js +2 -1
- package/dist/types/api/RouteJob.js +2 -1
- package/dist/types/api/Session.js +2 -1
- package/dist/types/api/Task.js +2 -1
- package/dist/types/api/_Event.js +2 -1
- package/dist/types/api/assignData.d.ts +9 -0
- package/dist/types/api/assignData.js +17 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -290,10 +290,12 @@ declare module './QueryClient.js' {
|
|
|
290
290
|
pay_in_cash?: boolean;
|
|
291
291
|
}>>;
|
|
292
292
|
useCreateMessage(chatId: string): ReturnType<typeof useMutation<{
|
|
293
|
+
msg?: string;
|
|
293
294
|
id: string;
|
|
294
295
|
}, StandardError, {
|
|
295
296
|
content: string;
|
|
296
297
|
time_sent?: number;
|
|
298
|
+
id?: string;
|
|
297
299
|
}>>;
|
|
298
300
|
useCreateProposal(): ReturnType<typeof useMutation<{
|
|
299
301
|
id: string;
|
|
@@ -721,6 +723,8 @@ export declare class AvroQueryClient {
|
|
|
721
723
|
private _persister;
|
|
722
724
|
private _presencePending;
|
|
723
725
|
private _presenceTimer;
|
|
726
|
+
/** Chat rooms to (re)join on every connect; socket rooms don't survive reconnects. */
|
|
727
|
+
private _joinedChats;
|
|
724
728
|
private _restored;
|
|
725
729
|
private _emailTracking;
|
|
726
730
|
private _emailListenersInit;
|
|
@@ -759,6 +763,13 @@ export declare class AvroQueryClient {
|
|
|
759
763
|
/** Tell the server which install this live socket belongs to. */
|
|
760
764
|
private registerDevice;
|
|
761
765
|
emit(eventName: string, data: unknown): void;
|
|
766
|
+
/**
|
|
767
|
+
* Join a chat's socket room so `new_message` and presence events for it
|
|
768
|
+
* arrive. The room is rejoined after reconnects until `leaveChat`.
|
|
769
|
+
*/
|
|
770
|
+
joinChat(chatId: string): void;
|
|
771
|
+
/** Leave a chat's socket room joined with `joinChat`. */
|
|
772
|
+
leaveChat(chatId: string): void;
|
|
762
773
|
on<T>(eventName: string, callback: (data: T) => void): void;
|
|
763
774
|
off(eventName: string, callback?: Function): void;
|
|
764
775
|
/** Wire the socket to the cache (called once from the provider). */
|
|
@@ -1050,7 +1061,7 @@ export declare class AvroQueryClient {
|
|
|
1050
1061
|
unknown_ids?: string[];
|
|
1051
1062
|
active?: boolean;
|
|
1052
1063
|
user_id?: string;
|
|
1053
|
-
}, cancelToken?: CancelToken, headers?: Record<string, string
|
|
1064
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>, companyId?: string | undefined): Promise<any>;
|
|
1054
1065
|
private _initEmailListeners;
|
|
1055
1066
|
trackEmail(options?: TrackEmailOptions): string;
|
|
1056
1067
|
sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
|
|
@@ -58,6 +58,8 @@ export class AvroQueryClient {
|
|
|
58
58
|
this._persister = null;
|
|
59
59
|
this._presencePending = new Set();
|
|
60
60
|
this._presenceTimer = null;
|
|
61
|
+
/** Chat rooms to (re)join on every connect; socket rooms don't survive reconnects. */
|
|
62
|
+
this._joinedChats = new Set();
|
|
61
63
|
this._restored = null;
|
|
62
64
|
this._emailTracking = new Map();
|
|
63
65
|
this._emailListenersInit = false;
|
|
@@ -268,6 +270,25 @@ export class AvroQueryClient {
|
|
|
268
270
|
}
|
|
269
271
|
this.socket.emit(eventName, data);
|
|
270
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Join a chat's socket room so `new_message` and presence events for it
|
|
275
|
+
* arrive. The room is rejoined after reconnects until `leaveChat`.
|
|
276
|
+
*/
|
|
277
|
+
joinChat(chatId) {
|
|
278
|
+
if (!chatId)
|
|
279
|
+
return;
|
|
280
|
+
this._joinedChats.add(chatId);
|
|
281
|
+
if (this.socket?.connected)
|
|
282
|
+
this.socket.emit('join_chat', { chat_id: chatId });
|
|
283
|
+
}
|
|
284
|
+
/** Leave a chat's socket room joined with `joinChat`. */
|
|
285
|
+
leaveChat(chatId) {
|
|
286
|
+
if (!chatId)
|
|
287
|
+
return;
|
|
288
|
+
this._joinedChats.delete(chatId);
|
|
289
|
+
if (this.socket?.connected)
|
|
290
|
+
this.socket.emit('leave_chat', { chat_id: chatId });
|
|
291
|
+
}
|
|
271
292
|
on(eventName, callback) {
|
|
272
293
|
this.socket?.on(eventName, callback);
|
|
273
294
|
}
|
|
@@ -297,6 +318,13 @@ export class AvroQueryClient {
|
|
|
297
318
|
if (data?.company_id && data.company_id === this.companyId)
|
|
298
319
|
this.joinCompanyRoom();
|
|
299
320
|
});
|
|
321
|
+
// Sent before a chat room is closed after a membership change;
|
|
322
|
+
// the server re-checks membership, so removed members stay out.
|
|
323
|
+
on('rejoin_chat', (data) => {
|
|
324
|
+
if (data?.chat_id && this._joinedChats.has(data.chat_id)) {
|
|
325
|
+
this.socket?.emit('join_chat', { chat_id: data.chat_id });
|
|
326
|
+
}
|
|
327
|
+
});
|
|
300
328
|
// Presence names the member that changed; coalesce a burst of
|
|
301
329
|
// flips (mobile sockets cycle constantly) into one bulk fetch
|
|
302
330
|
// and patch those members instead of re-downloading every
|
|
@@ -370,7 +398,12 @@ export class AvroQueryClient {
|
|
|
370
398
|
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
371
399
|
queryClient.invalidateQueries({ queryKey: ['messages'] });
|
|
372
400
|
});
|
|
373
|
-
on('connect', () =>
|
|
401
|
+
on('connect', () => {
|
|
402
|
+
this.joinCompanyRoom();
|
|
403
|
+
for (const chatId of this._joinedChats) {
|
|
404
|
+
this.socket.emit('join_chat', { chat_id: chatId });
|
|
405
|
+
}
|
|
406
|
+
});
|
|
374
407
|
if (this.socket.connected && this.companyId)
|
|
375
408
|
this.joinCompanyRoom();
|
|
376
409
|
this._socketInvalidationCleanup = () => {
|
|
@@ -545,12 +578,7 @@ export class AvroQueryClient {
|
|
|
545
578
|
}
|
|
546
579
|
throw new StandardError(401, 'Invalid Google login response');
|
|
547
580
|
}
|
|
548
|
-
this.
|
|
549
|
-
this.socket.auth = this.socketAuth(resp.access_token);
|
|
550
|
-
if (!this.socket.connected) {
|
|
551
|
-
this.ensureSocketConnected();
|
|
552
|
-
}
|
|
553
|
-
await this.config.authManager.setTokens({
|
|
581
|
+
await this.loginSuccess({
|
|
554
582
|
access_token: resp.access_token,
|
|
555
583
|
refresh_token: resp.refresh_token,
|
|
556
584
|
});
|
|
@@ -576,12 +604,7 @@ export class AvroQueryClient {
|
|
|
576
604
|
}
|
|
577
605
|
throw new StandardError(401, 'Invalid Apple login response');
|
|
578
606
|
}
|
|
579
|
-
this.
|
|
580
|
-
this.socket.auth = this.socketAuth(resp.access_token);
|
|
581
|
-
if (!this.socket.connected) {
|
|
582
|
-
this.ensureSocketConnected();
|
|
583
|
-
}
|
|
584
|
-
await this.config.authManager.setTokens({
|
|
607
|
+
await this.loginSuccess({
|
|
585
608
|
access_token: resp.access_token,
|
|
586
609
|
refresh_token: resp.refresh_token,
|
|
587
610
|
});
|
|
@@ -1088,12 +1111,12 @@ export class AvroQueryClient {
|
|
|
1088
1111
|
throw fetchError(err, 'Failed to fetch skills');
|
|
1089
1112
|
});
|
|
1090
1113
|
}
|
|
1091
|
-
fetchSessions(body = {}, cancelToken, headers = {}) {
|
|
1092
|
-
if (!
|
|
1114
|
+
fetchSessions(body = {}, cancelToken, headers = {}, companyId = this.companyId) {
|
|
1115
|
+
if (!companyId || companyId.trim() === '') {
|
|
1093
1116
|
throw new StandardError(400, 'Company ID is required');
|
|
1094
1117
|
}
|
|
1095
1118
|
const amount = body.amt ?? Math.max(body.unknown_ids?.length ?? 0, 50);
|
|
1096
|
-
return this._fetch('POST', `/company/${
|
|
1119
|
+
return this._fetch('POST', `/company/${companyId}/sessions?amount=${amount}`, JSON.stringify({ ...body, amt: amount }), cancelToken, {
|
|
1097
1120
|
...headers,
|
|
1098
1121
|
'Content-Type': 'application/json',
|
|
1099
1122
|
}, true)
|
|
@@ -2,7 +2,7 @@ import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
3
|
import { restoreNs, snapshotNs, seedDetails, removeOptimisticRow } from '../cache.js';
|
|
4
4
|
import { keys, matchesList } from '../realtime.js';
|
|
5
|
-
import { constructEvent, DelayEvent, Job, LineItemStatus, } from '../../types/api.js';
|
|
5
|
+
import { constructEvent, DelayEvent, Job, LineItemStatus, Task, } from '../../types/api.js';
|
|
6
6
|
const isJobsQuery = (q) => q.queryKey[0] === 'jobs';
|
|
7
7
|
const isEventsQuery = (q) => q.queryKey[0] === 'events';
|
|
8
8
|
const isEventsQueryFor = (item) => (q) => q.queryKey[0] === 'events' && matchesList('event', q.queryKey, item) === 'match';
|
|
@@ -179,13 +179,13 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
|
|
|
179
179
|
const delayUntil = Math.max(task.delay_until != null && task.delay_until > now
|
|
180
180
|
? task.delay_until
|
|
181
181
|
: 0, now + delayData.delay_seconds);
|
|
182
|
-
return {
|
|
182
|
+
return new Task({
|
|
183
183
|
...task,
|
|
184
184
|
delay_until: delayUntil,
|
|
185
185
|
overdue_time: task.overdue_time != null
|
|
186
186
|
? Math.min(task.overdue_time, now - delayUntil)
|
|
187
187
|
: task.overdue_time,
|
|
188
|
-
};
|
|
188
|
+
});
|
|
189
189
|
}
|
|
190
190
|
return task;
|
|
191
191
|
}),
|
|
@@ -283,24 +283,20 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
283
283
|
last_completed_event: isEnding && mergedEvent ? mergedEvent : previousJob.last_completed_event,
|
|
284
284
|
tasks: previousJob.tasks.map((task) => {
|
|
285
285
|
if (updates.tasks?.includes(task.id ?? '')) {
|
|
286
|
-
return {
|
|
286
|
+
return new Task({
|
|
287
287
|
...task,
|
|
288
288
|
current_event: isEnding
|
|
289
289
|
? null
|
|
290
|
-
:
|
|
291
|
-
? { ...previousEvent, ...updates }
|
|
292
|
-
: task.current_event,
|
|
290
|
+
: (mergedEvent ?? task.current_event),
|
|
293
291
|
last_completed_event: isEnding
|
|
294
|
-
?
|
|
295
|
-
? { ...previousEvent, ...updates }
|
|
296
|
-
: task.last_completed_event
|
|
292
|
+
? (mergedEvent ?? task.last_completed_event)
|
|
297
293
|
: task.last_completed_event,
|
|
298
294
|
// Next due a period out, or when an active
|
|
299
295
|
// delay ends if that's later.
|
|
300
296
|
overdue_time: isEnding
|
|
301
297
|
? -Math.max(task.frequency ?? 0, (task.delay_until ?? 0) - Date.now() / 1000)
|
|
302
298
|
: task.overdue_time,
|
|
303
|
-
};
|
|
299
|
+
});
|
|
304
300
|
}
|
|
305
301
|
return task;
|
|
306
302
|
}),
|
|
@@ -315,16 +311,16 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
315
311
|
return old;
|
|
316
312
|
});
|
|
317
313
|
}
|
|
318
|
-
queryClient.setQueryData(['events', eventId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
314
|
+
queryClient.setQueryData(['events', eventId], (oldData) => oldData ? constructEvent({ ...oldData, ...updates }) : undefined);
|
|
319
315
|
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
320
316
|
if (!oldData)
|
|
321
317
|
return oldData;
|
|
322
318
|
if (oldData.pages) {
|
|
323
|
-
const updatedPages = oldData.pages.map((page) => page.map((event) => event.id === eventId ? { ...event, ...updates } : event));
|
|
319
|
+
const updatedPages = oldData.pages.map((page) => page.map((event) => event.id === eventId ? constructEvent({ ...event, ...updates }) : event));
|
|
324
320
|
return { ...oldData, pages: updatedPages };
|
|
325
321
|
}
|
|
326
322
|
if (Array.isArray(oldData)) {
|
|
327
|
-
return oldData.map((event) => event.id === eventId ? { ...event, ...updates } : event);
|
|
323
|
+
return oldData.map((event) => event.id === eventId ? constructEvent({ ...event, ...updates }) : event);
|
|
328
324
|
}
|
|
329
325
|
return oldData;
|
|
330
326
|
});
|
|
@@ -28,22 +28,24 @@ AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
|
|
|
28
28
|
AvroQueryClient.prototype.useCreateMessage = function (chatId) {
|
|
29
29
|
const queryClient = this.getQueryClient();
|
|
30
30
|
return useMutation({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
// The backend replies `{ msg, id }`, not a full Message, so the
|
|
32
|
+
// reply is never cached as one; the list refetches instead.
|
|
33
|
+
mutationFn: ({ content, time_sent, id }) => this.post({
|
|
34
|
+
path: `/chat/${chatId}/message`,
|
|
35
|
+
data: JSON.stringify({
|
|
36
|
+
message: {
|
|
37
|
+
content,
|
|
38
|
+
time_sent: time_sent ?? Math.floor(Date.now() / 1000),
|
|
39
|
+
id,
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
|
+
}),
|
|
44
|
+
onSettled: () => {
|
|
45
|
+
// `new_message` only reaches sockets in the chat room, so the
|
|
46
|
+
// sender can't rely on it to see their own message.
|
|
47
|
+
queryClient.invalidateQueries({ queryKey: ['messages', 'infinite', chatId] });
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
47
49
|
},
|
|
48
50
|
});
|
|
49
51
|
};
|
|
@@ -69,7 +69,7 @@ AvroQueryClient.prototype.useGetCompanySessionsByIds = function (sessionIds, par
|
|
|
69
69
|
const sortedIds = [...sessionIds].sort();
|
|
70
70
|
const result = useQuery({
|
|
71
71
|
queryKey: keys.list(NS, companyId, listFilters({ unknown_ids: sortedIds })),
|
|
72
|
-
queryFn: () => this.fetchSessions({ unknown_ids: sortedIds, amt: sortedIds.length }).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
72
|
+
queryFn: () => this.fetchSessions({ unknown_ids: sortedIds, amt: sortedIds.length }, undefined, {}, companyId).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
73
73
|
enabled: Boolean(companyId) && sortedIds.length > 0 && (params.enabled ?? true),
|
|
74
74
|
});
|
|
75
75
|
return result;
|
|
@@ -80,7 +80,7 @@ AvroQueryClient.prototype.useGetActiveCompanySessions = function (params = {}) {
|
|
|
80
80
|
const companyId = params.companyId ?? this.companyId;
|
|
81
81
|
const result = useQuery({
|
|
82
82
|
queryKey: keys.list(NS, companyId, listFilters({ active: true })),
|
|
83
|
-
queryFn: () => this.fetchSessions({ active: true, amt: 500 }).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
83
|
+
queryFn: () => this.fetchSessions({ active: true, amt: 500 }, undefined, {}, companyId).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
84
84
|
enabled: Boolean(companyId) && (params.enabled ?? true),
|
|
85
85
|
});
|
|
86
86
|
return result;
|
|
@@ -174,13 +174,16 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
174
174
|
onMutate: async ({ sessionId, updates, }) => {
|
|
175
175
|
await queryClient.cancelQueries({ queryKey: [NS] });
|
|
176
176
|
const previous = snapshotSessionLists(queryClient);
|
|
177
|
+
const previousDetail = queryClient.getQueryData(keys.detail(NS, sessionId));
|
|
177
178
|
patchSessionLists(queryClient, (items) => items.map((session) => session.id === sessionId ? new Session({ ...session, ...updates }) : session));
|
|
178
179
|
queryClient.setQueryData(keys.detail(NS, sessionId), (old) => old ? new Session({ ...old, ...updates }) : old);
|
|
179
|
-
return { previous };
|
|
180
|
+
return { previous, previousDetail };
|
|
180
181
|
},
|
|
181
|
-
onError: (_err,
|
|
182
|
+
onError: (_err, { sessionId }, context) => {
|
|
182
183
|
if (context?.previous)
|
|
183
184
|
restoreSessionLists(queryClient, context.previous);
|
|
185
|
+
if (context?.previousDetail)
|
|
186
|
+
queryClient.setQueryData(keys.detail(NS, sessionId), context.previousDetail);
|
|
184
187
|
},
|
|
185
188
|
onSettled: () => {
|
|
186
189
|
this.syncAfterMutation('session', 'timecard');
|
|
@@ -229,13 +232,16 @@ AvroQueryClient.prototype.useUpdateCompanySession = function () {
|
|
|
229
232
|
onMutate: async ({ sessionId, updates }) => {
|
|
230
233
|
await queryClient.cancelQueries({ queryKey: [NS] });
|
|
231
234
|
const previous = snapshotSessionLists(queryClient);
|
|
235
|
+
const previousDetail = queryClient.getQueryData(keys.detail(NS, sessionId));
|
|
232
236
|
patchSessionLists(queryClient, (items) => items.map((session) => session.id === sessionId ? new Session({ ...session, ...updates }) : session));
|
|
233
237
|
queryClient.setQueryData(keys.detail(NS, sessionId), (old) => old ? new Session({ ...old, ...updates }) : old);
|
|
234
|
-
return { previous };
|
|
238
|
+
return { previous, previousDetail };
|
|
235
239
|
},
|
|
236
|
-
onError: (_err,
|
|
240
|
+
onError: (_err, { sessionId }, context) => {
|
|
237
241
|
if (context?.previous)
|
|
238
242
|
restoreSessionLists(queryClient, context.previous);
|
|
243
|
+
if (context?.previousDetail)
|
|
244
|
+
queryClient.setQueryData(keys.detail(NS, sessionId), context.previousDetail);
|
|
239
245
|
},
|
|
240
246
|
onSettled: () => {
|
|
241
247
|
this.syncAfterMutation('session', 'timecard');
|
package/dist/client/realtime.js
CHANGED
|
@@ -152,8 +152,10 @@ function matchTimecards(filters, item) {
|
|
|
152
152
|
return 'nomatch';
|
|
153
153
|
if (filters.status && item.status !== filters.status)
|
|
154
154
|
return 'nomatch';
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
// The backend snaps period_start to the enclosing pay period, so the
|
|
156
|
+
// requested instant can't be compared to item.start client-side.
|
|
157
|
+
if (filters.periodStart)
|
|
158
|
+
return 'unknown';
|
|
157
159
|
return 'match';
|
|
158
160
|
}
|
|
159
161
|
function matchPayouts(filters, item) {
|
package/dist/types/api/Bill.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { LineItem } from './LineItem.js';
|
|
2
3
|
export const BillStatus = {
|
|
3
4
|
SENT: 'SENT',
|
|
@@ -17,7 +18,7 @@ export class Bill {
|
|
|
17
18
|
this.customItems = () => (this.line_items ?? []).filter((item) => item.line_item_type === 'CUSTOM' || item.line_item_type === 'PROCESSING_FEE');
|
|
18
19
|
this.topLevelItems = () => (this.line_items ?? []).filter((item) => !item.parent_id);
|
|
19
20
|
this.childItems = (parentId) => (this.line_items ?? []).filter((item) => item.parent_id === parentId);
|
|
20
|
-
|
|
21
|
+
assignData(this, init);
|
|
21
22
|
if (init?.line_items) {
|
|
22
23
|
this.line_items = init.line_items.map((item) => new LineItem(item));
|
|
23
24
|
}
|
package/dist/types/api/Job.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { Task, TaskStatus } from './Task.js';
|
|
2
3
|
import { RouteJob } from './RouteJob.js';
|
|
3
4
|
export class Job {
|
|
@@ -59,7 +60,7 @@ export class Job {
|
|
|
59
60
|
this.isDone = (route) => {
|
|
60
61
|
return this.portionDone(route) === 1;
|
|
61
62
|
};
|
|
62
|
-
|
|
63
|
+
assignData(this, init);
|
|
63
64
|
if (init?.tasks) {
|
|
64
65
|
this.tasks = init.tasks.map((t) => new Task(t));
|
|
65
66
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
export const LineItemStatus = {
|
|
2
3
|
CREATED: 'CREATED',
|
|
3
4
|
PENDING_AUTOBILL: 'PENDING_AUTOBILL',
|
|
@@ -37,6 +38,6 @@ export class LineItem {
|
|
|
37
38
|
return (this.status === LineItemStatus.PENDING_AUTOBILL ||
|
|
38
39
|
this.status === LineItemStatus.PROCESSING);
|
|
39
40
|
};
|
|
40
|
-
|
|
41
|
+
assignData(this, init);
|
|
41
42
|
}
|
|
42
43
|
}
|
package/dist/types/api/Route.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { RouteJob } from './RouteJob.js';
|
|
2
3
|
export const FrequencyType = {
|
|
3
4
|
ONCE: 'ONCE',
|
|
@@ -84,7 +85,7 @@ export class Route {
|
|
|
84
85
|
}
|
|
85
86
|
return offset;
|
|
86
87
|
};
|
|
87
|
-
|
|
88
|
+
assignData(this, init);
|
|
88
89
|
if (init?.jobs) {
|
|
89
90
|
this.jobs = init.jobs.map((j) => new RouteJob(j));
|
|
90
91
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
export class RouteJob {
|
|
2
3
|
constructor(init) {
|
|
3
4
|
this.getPredictedArrival = () => {
|
|
@@ -5,7 +6,7 @@ export class RouteJob {
|
|
|
5
6
|
? this.estimated_arrival_time
|
|
6
7
|
: this.scheduled_arrival_time;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
assignData(this, init);
|
|
9
10
|
this.tasks = (init?.tasks ?? []).map((t) => typeof t === 'string'
|
|
10
11
|
? { id: t, depends_on: [] }
|
|
11
12
|
: { ...t, depends_on: t.depends_on ?? [] });
|
package/dist/types/api/Task.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { Prepayment } from './Prepayment.js';
|
|
2
3
|
export const TaskStatus = {
|
|
3
4
|
PENDING_CUSTOMER: 'PENDING_CUSTOMER',
|
|
@@ -153,7 +154,7 @@ export class Task {
|
|
|
153
154
|
const cutoff = Math.floor(routeDay.getTime() / 1000);
|
|
154
155
|
return (this.last_completed_event?.time_ended ?? 0) >= cutoff;
|
|
155
156
|
};
|
|
156
|
-
|
|
157
|
+
assignData(this, init);
|
|
157
158
|
if (init?.prepayments) {
|
|
158
159
|
this.prepayments = init.prepayments.map((p) => new Prepayment(p));
|
|
159
160
|
}
|
package/dist/types/api/_Event.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { LineItem } from './LineItem.js';
|
|
2
3
|
export class _Event extends LineItem {
|
|
3
4
|
constructor(init) {
|
|
@@ -6,7 +7,7 @@ export class _Event extends LineItem {
|
|
|
6
7
|
const additionalChargesCost = this.additional_charges.reduce((acc, charge) => acc + (charge.cost ?? 0) * (charge.amount ?? 0), 0);
|
|
7
8
|
return this.cost * this.amount + additionalChargesCost;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
assignData(this, init);
|
|
10
11
|
this.breaks = init?.breaks ?? [];
|
|
11
12
|
this.images = init?.images ?? [];
|
|
12
13
|
this.tasks = init?.tasks ?? [];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy an init object's data onto a model instance.
|
|
3
|
+
*
|
|
4
|
+
* Model methods are arrow-function class fields bound to their own
|
|
5
|
+
* instance. Rebuilding a model from a spread of another instance
|
|
6
|
+
* (`new Job({ ...job, ...updates })`) would otherwise copy the old
|
|
7
|
+
* instance's methods, which keep reading the old object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assignData<T extends object>(target: T, init?: Partial<T>): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy an init object's data onto a model instance.
|
|
3
|
+
*
|
|
4
|
+
* Model methods are arrow-function class fields bound to their own
|
|
5
|
+
* instance. Rebuilding a model from a spread of another instance
|
|
6
|
+
* (`new Job({ ...job, ...updates })`) would otherwise copy the old
|
|
7
|
+
* instance's methods, which keep reading the old object.
|
|
8
|
+
*/
|
|
9
|
+
export function assignData(target, init) {
|
|
10
|
+
if (!init)
|
|
11
|
+
return;
|
|
12
|
+
for (const [key, value] of Object.entries(init)) {
|
|
13
|
+
if (typeof value === 'function')
|
|
14
|
+
continue;
|
|
15
|
+
target[key] = value;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "1.6.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "1.6.1";
|
package/dist/version.js
CHANGED