@go-avro/avro-js 0.1.14 → 1.6.0

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.
Files changed (42) hide show
  1. package/dist/auth/AuthManager.d.ts +28 -0
  2. package/dist/auth/AuthManager.js +119 -43
  3. package/dist/client/QueryClient.d.ts +56 -1
  4. package/dist/client/QueryClient.js +264 -80
  5. package/dist/client/cache.d.ts +24 -0
  6. package/dist/client/cache.js +51 -0
  7. package/dist/client/core/fetch.js +58 -49
  8. package/dist/client/core/policy.d.ts +17 -0
  9. package/dist/client/core/policy.js +35 -0
  10. package/dist/client/core/xhr.js +16 -14
  11. package/dist/client/hooks/bills.js +10 -14
  12. package/dist/client/hooks/catalog_items.js +18 -8
  13. package/dist/client/hooks/chats.js +2 -8
  14. package/dist/client/hooks/companies.js +11 -5
  15. package/dist/client/hooks/events.js +46 -35
  16. package/dist/client/hooks/groups.js +11 -26
  17. package/dist/client/hooks/jobs.js +3 -8
  18. package/dist/client/hooks/labels.js +11 -26
  19. package/dist/client/hooks/messages.js +3 -8
  20. package/dist/client/hooks/months.js +28 -22
  21. package/dist/client/hooks/payouts.js +3 -8
  22. package/dist/client/hooks/prepayments.js +28 -22
  23. package/dist/client/hooks/proposal.js +1 -0
  24. package/dist/client/hooks/routes.js +8 -6
  25. package/dist/client/hooks/sessions.js +11 -27
  26. package/dist/client/hooks/skills.js +6 -4
  27. package/dist/client/hooks/teams.js +6 -4
  28. package/dist/client/hooks/timecards.js +7 -7
  29. package/dist/client/hooks/waivers.js +6 -4
  30. package/dist/client/persist.js +21 -2
  31. package/dist/client/realtime.d.ts +12 -0
  32. package/dist/client/realtime.js +160 -46
  33. package/dist/types/api/Company.d.ts +2 -0
  34. package/dist/types/api/DelayEvent.d.ts +1 -1
  35. package/dist/types/api/LineItem.d.ts +4 -0
  36. package/dist/types/api/LineItem.js +8 -1
  37. package/dist/types/api/Task.d.ts +20 -0
  38. package/dist/types/api/Task.js +11 -1
  39. package/dist/types/api.d.ts +3 -3
  40. package/dist/version.d.ts +1 -1
  41. package/dist/version.js +1 -1
  42. package/package.json +7 -2
@@ -27,12 +27,17 @@ function searchAware(filters) {
27
27
  const q = filters.query;
28
28
  return typeof q === 'string' && q.length > 0 ? 'unknown' : 'match';
29
29
  }
30
+ /**
31
+ * Backend id filters: non-empty `unknown_ids` means "only these ids";
32
+ * otherwise `known_ids` means "exclude these ids".
33
+ */
30
34
  function withIds(filters, item) {
31
35
  const known = filters.known_ids;
32
36
  const unknown = filters.unknown_ids;
33
- if (Array.isArray(known) && known.length > 0 && !known.includes(item.id))
34
- return 'nomatch';
35
- if (Array.isArray(unknown) && unknown.length > 0 && unknown.includes(item.id))
37
+ if (Array.isArray(unknown) && unknown.length > 0) {
38
+ return unknown.includes(item.id) ? null : 'nomatch';
39
+ }
40
+ if (Array.isArray(known) && known.length > 0 && known.includes(item.id))
36
41
  return 'nomatch';
37
42
  return null;
38
43
  }
@@ -67,13 +72,18 @@ function isPaidStatus(status) {
67
72
  function isBilledStatus(status) {
68
73
  return status === 'BILLED' || status === 'EXTERNALLY_BILLED';
69
74
  }
70
- /** Shared by events / months / prepayments (line-item lists). */
75
+ /**
76
+ * Shared by events / months / prepayments (line-item lists). Mirrors the
77
+ * backend: the `unbilled`/`billed`/`paid` flags are OR-combined status
78
+ * buckets defaulting to `true`/`false`/`false`; "unbilled" is `CREATED`
79
+ * only, and in-flight statuses (`PROCESSING`, `PENDING_AUTOBILL`) are in
80
+ * no bucket, so no list returns them.
81
+ */
71
82
  function matchLineItems(filters, item) {
72
83
  const byIds = withIds(filters, item);
73
84
  if (byIds)
74
85
  return byIds;
75
- const parentKey = typeof filters.jobId === 'string' ? 'job_id' : null;
76
- if (parentKey && filters.jobId && item[parentKey] !== filters.jobId)
86
+ if (typeof filters.jobId === 'string' && filters.jobId && item.job_id !== filters.jobId)
77
87
  return 'nomatch';
78
88
  if (typeof filters.taskId === 'string' && filters.taskId && item.task_id !== filters.taskId)
79
89
  return 'nomatch';
@@ -85,26 +95,26 @@ function matchLineItems(filters, item) {
85
95
  return 'nomatch';
86
96
  const status = item.status;
87
97
  if (status !== undefined) {
88
- const paid = isPaidStatus(status);
89
- const billed = isBilledStatus(status);
90
- const unbilled = !paid && !billed;
91
- if (filters.paid === false && paid)
92
- return 'nomatch';
93
- if (filters.billed === false && billed)
94
- return 'nomatch';
95
- if (filters.unbilled === false && unbilled)
98
+ const wantUnbilled = filters.unbilled === undefined ? true : filters.unbilled === true;
99
+ const wantBilled = filters.billed === true;
100
+ const wantPaid = filters.paid === true;
101
+ const inBucket = (isPaidStatus(status) && wantPaid) ||
102
+ (isBilledStatus(status) && wantBilled) ||
103
+ (status === 'CREATED' && wantUnbilled);
104
+ if (!inBucket)
96
105
  return 'nomatch';
97
106
  }
98
107
  return searchAware(filters);
99
108
  }
109
+ /** Backend: `paid: true` = fully-paid only; `paid: false` = no paid filter. */
100
110
  function matchBills(filters, item) {
101
111
  const byIds = withIds(filters, item);
102
112
  if (byIds)
103
113
  return byIds;
104
114
  const status = item.status;
105
- if (typeof filters.paid === 'boolean' && status !== undefined) {
115
+ if (filters.paid === true && status !== undefined) {
106
116
  const paid = status === 'PAID' || status === 'MANUALLY_PAID';
107
- if (filters.paid !== paid)
117
+ if (!paid)
108
118
  return 'nomatch';
109
119
  }
110
120
  const hard = ['created_from', 'created_to', 'paid_from', 'paid_to', 'amount_min', 'amount_max'];
@@ -164,7 +174,12 @@ function matchPayouts(filters, item) {
164
174
  return 'unknown';
165
175
  return searchAware(filters);
166
176
  }
167
- const bulk = (method) => (client, ids) => client[method]({ unknown_ids: ids, amt: ids.length });
177
+ const bulk = (method, extra = {}) => (client, ids) => client[method]({ ...extra, unknown_ids: ids, amt: ids.length });
178
+ /** Line-item list endpoints default to unbilled-only: ask for every bucket. */
179
+ const ALL_LINE_ITEM_STATUSES = { unbilled: true, billed: true, paid: true };
180
+ /** Single-entity GET (404/403 is treated as gone by the applier). */
181
+ const getOne = (path) => (client, id) => client.get({ path: path(id) });
182
+ const COMPANY_EMBEDS = [['companies'], ['/company/list']];
168
183
  export const REGISTRY = {
169
184
  job: {
170
185
  ns: 'jobs',
@@ -175,7 +190,7 @@ export const REGISTRY = {
175
190
  event: {
176
191
  ns: 'events',
177
192
  construct: constructEvent,
178
- fetchMany: bulk('fetchEvents'),
193
+ fetchMany: bulk('fetchEvents', ALL_LINE_ITEM_STATUSES),
179
194
  listMatch: matchLineItems,
180
195
  },
181
196
  route: {
@@ -185,13 +200,31 @@ export const REGISTRY = {
185
200
  listMatch: searchAware,
186
201
  },
187
202
  team: { ns: 'teams', fetchMany: bulk('fetchTeams'), listMatch: searchAware },
188
- group: { ns: 'groups', fetchMany: bulk('fetchGroups'), listMatch: searchAware },
189
- label: { ns: 'labels', fetchMany: bulk('fetchLabels'), listMatch: searchAware },
190
- skill: { ns: 'skills', fetchMany: bulk('fetchSkills'), listMatch: searchAware },
203
+ // Labels, groups, skills and catalog items are also embedded in the
204
+ // company payload, so their changes must refresh it too.
205
+ group: {
206
+ ns: 'groups',
207
+ fetchOne: getOne((id) => `/group/${id}`),
208
+ listMatch: searchAware,
209
+ alsoInvalidate: COMPANY_EMBEDS,
210
+ },
211
+ label: {
212
+ ns: 'labels',
213
+ fetchOne: getOne((id) => `/label/${id}`),
214
+ listMatch: searchAware,
215
+ alsoInvalidate: COMPANY_EMBEDS,
216
+ },
217
+ skill: {
218
+ ns: 'skills',
219
+ fetchMany: bulk('fetchSkills'),
220
+ listMatch: searchAware,
221
+ alsoInvalidate: COMPANY_EMBEDS,
222
+ },
223
+ // No single-item GET exists: catalog items only live on the company.
191
224
  catalog_item: {
192
225
  ns: 'catalog_items',
193
- fetchOne: (client, id) => client.get({ path: `/catalog_item/${id}` }),
194
- listMatch: searchAware,
226
+ invalidateOnly: true,
227
+ alsoInvalidate: COMPANY_EMBEDS,
195
228
  },
196
229
  proposal: {
197
230
  ns: 'proposals',
@@ -203,10 +236,14 @@ export const REGISTRY = {
203
236
  ns: 'proposal_terms',
204
237
  fetchOne: (client, id) => client.get({ path: `/proposal_terms/${id}` }),
205
238
  },
206
- month: { ns: 'months', fetchMany: bulk('fetchMonths'), listMatch: matchLineItems },
239
+ month: {
240
+ ns: 'months',
241
+ fetchMany: bulk('fetchMonths', ALL_LINE_ITEM_STATUSES),
242
+ listMatch: matchLineItems,
243
+ },
207
244
  prepayment: {
208
245
  ns: 'prepayments',
209
- fetchMany: bulk('fetchPrepayments'),
246
+ fetchMany: bulk('fetchPrepayments', ALL_LINE_ITEM_STATUSES),
210
247
  listMatch: matchLineItems,
211
248
  },
212
249
  bill: {
@@ -300,12 +337,6 @@ export function upsertEntity(qc, spec, item) {
300
337
  return mapList(old, (items) => items.map((x) => (x?.id === id ? item : x)));
301
338
  return insertInto(old, item);
302
339
  });
303
- // A fresh insert into a server-ordered paged list: settle order.
304
- if (verdict === 'match' &&
305
- key[1] === 'infinite' &&
306
- !listHas(query.state.data, id)) {
307
- qc.invalidateQueries({ queryKey: key, exact: true });
308
- }
309
340
  }
310
341
  }
311
342
  export function matchesList(type, key, item) {
@@ -323,12 +354,43 @@ export function invalidateType(qc, spec) {
323
354
  // ─── Applying batches ───────────────────────────────────────────────
324
355
  const FETCH_COALESCE_MS = 50;
325
356
  const FETCH_CHUNK = 100;
357
+ /** A fetch failure that means "this entity is gone or no longer visible". */
358
+ function isGoneError(err) {
359
+ const status = err?.status;
360
+ return status === 404 || status === 403;
361
+ }
362
+ /** Drop an id from every list in `ns`; mark (don't drop) its detail stale. */
363
+ function dropFromLists(qc, ns, id) {
364
+ qc.setQueriesData({ predicate: (q) => q.queryKey[0] === ns && isListKey(q.queryKey) }, (old) => (old ? mapList(old, (items) => items.filter((x) => x?.id !== id)) : old));
365
+ qc.invalidateQueries({ queryKey: keys.detail(ns, id), exact: true });
366
+ }
326
367
  export class ChangeApplier {
327
368
  constructor(client, qc) {
328
369
  this.client = client;
329
370
  this.qc = qc;
330
371
  this.pending = new Map();
331
372
  this.timer = null;
373
+ /**
374
+ * Latest change sequence per `type:id`. Every change (enqueue, inline
375
+ * data, delete) takes a fresh number; a fetch only applies results for
376
+ * ids whose number is unchanged since it started, so an in-flight
377
+ * fetch can't resurrect a deleted entity or overwrite a newer one.
378
+ */
379
+ this.seq = 0;
380
+ this.latest = new Map();
381
+ this.inflight = new Map();
382
+ }
383
+ mark(type, id) {
384
+ this.latest.set(`${type}:${id}`, ++this.seq);
385
+ }
386
+ /** Settle a change applied inline: only an in-flight fetch needs the mark. */
387
+ markApplied(type, id) {
388
+ this.pending.get(type)?.delete(id);
389
+ const key = `${type}:${id}`;
390
+ if ((this.inflight.get(key) ?? 0) > 0)
391
+ this.mark(type, id);
392
+ else
393
+ this.latest.delete(key);
332
394
  }
333
395
  apply(payload) {
334
396
  const entries = Array.isArray(payload?.changes) ? payload.changes : [];
@@ -346,11 +408,13 @@ export class ChangeApplier {
346
408
  if (!entry.id)
347
409
  continue;
348
410
  if (entry.op === 'delete') {
411
+ this.markApplied(entry.type, entry.id);
349
412
  removeEntity(this.qc, spec.ns, entry.id);
350
413
  spec.alsoInvalidate?.forEach((k) => this.qc.invalidateQueries({ queryKey: [...k] }));
351
414
  continue;
352
415
  }
353
416
  if (entry.data !== undefined && entry.data !== null) {
417
+ this.markApplied(entry.type, entry.id);
354
418
  upsertEntity(this.qc, spec, spec.construct ? spec.construct(entry.data) : entry.data);
355
419
  spec.alsoInvalidate?.forEach((k) => this.qc.invalidateQueries({ queryKey: [...k] }));
356
420
  continue;
@@ -359,6 +423,7 @@ export class ChangeApplier {
359
423
  }
360
424
  }
361
425
  enqueue(type, id) {
426
+ this.mark(type, id);
362
427
  let set = this.pending.get(type);
363
428
  if (!set) {
364
429
  set = new Set();
@@ -375,7 +440,9 @@ export class ChangeApplier {
375
440
  async flush() {
376
441
  const batches = Array.from(this.pending.entries());
377
442
  this.pending.clear();
378
- await Promise.all(batches.map(([type, ids]) => this.fetchAndApply(type, [...ids])));
443
+ await Promise.all(batches
444
+ .filter(([, ids]) => ids.size > 0)
445
+ .map(([type, ids]) => this.fetchAndApply(type, [...ids])));
379
446
  }
380
447
  /** True when some mounted hook is currently observing this namespace. */
381
448
  isObserved(ns) {
@@ -395,40 +462,85 @@ export class ChangeApplier {
395
462
  invalidateType(this.qc, spec);
396
463
  return;
397
464
  }
465
+ const started = new Map(ids.map((id) => [id, this.latest.get(`${type}:${id}`)]));
466
+ // Only ids with no newer change since this fetch began may be applied.
467
+ const current = (id) => this.latest.get(`${type}:${id}`) === started.get(id);
468
+ const settle = (id) => {
469
+ const key = `${type}:${id}`;
470
+ const left = (this.inflight.get(key) ?? 1) - 1;
471
+ if (left > 0) {
472
+ this.inflight.set(key, left);
473
+ return;
474
+ }
475
+ this.inflight.delete(key);
476
+ if (current(id))
477
+ this.latest.delete(key);
478
+ };
479
+ ids.forEach((id) => {
480
+ const key = `${type}:${id}`;
481
+ this.inflight.set(key, (this.inflight.get(key) ?? 0) + 1);
482
+ });
398
483
  try {
399
- let raws = [];
484
+ const found = new Map();
485
+ const gone = new Set();
486
+ let failed = false;
400
487
  if (spec.fetchMany) {
401
488
  for (let i = 0; i < ids.length; i += FETCH_CHUNK) {
402
489
  const chunk = ids.slice(i, i + FETCH_CHUNK);
403
490
  const got = await spec.fetchMany(this.client, chunk);
404
- raws = raws.concat(Array.isArray(got) ? got : []);
491
+ for (const raw of Array.isArray(got) ? got : []) {
492
+ if (raw?.id)
493
+ found.set(raw.id, raw);
494
+ }
405
495
  }
496
+ // The bulk endpoint is authoritative for the ids it was asked for.
497
+ for (const id of ids)
498
+ if (!found.has(id))
499
+ gone.add(id);
406
500
  }
407
501
  else if (spec.fetchOne) {
408
502
  const results = await Promise.allSettled(ids.map((id) => spec.fetchOne(this.client, id)));
409
- raws = results
410
- .filter((r) => r.status === 'fulfilled')
411
- .map((r) => r.value)
412
- .filter(Boolean);
503
+ results.forEach((r, i) => {
504
+ const id = ids[i];
505
+ if (r.status === 'fulfilled') {
506
+ if (r.value?.id)
507
+ found.set(r.value.id, r.value);
508
+ else
509
+ gone.add(id);
510
+ }
511
+ else if (isGoneError(r.reason)) {
512
+ gone.add(id);
513
+ }
514
+ else {
515
+ // Transient failure: not evidence of deletion.
516
+ failed = true;
517
+ console.error(`[realtime] fetch ${type} ${id} failed:`, r.reason);
518
+ }
519
+ });
413
520
  }
414
521
  else {
522
+ ids.forEach(settle);
415
523
  invalidateType(this.qc, spec);
416
524
  return;
417
525
  }
418
- const seen = new Set();
419
- for (const raw of raws) {
420
- if (!raw?.id)
526
+ for (const [id, raw] of found) {
527
+ if (!current(id))
421
528
  continue;
422
- seen.add(raw.id);
423
529
  upsertEntity(this.qc, spec, spec.construct ? spec.construct(raw) : raw);
424
530
  }
425
- for (const id of ids)
426
- if (!seen.has(id))
427
- removeEntity(this.qc, spec.ns, id);
428
- spec.alsoInvalidate?.forEach((k) => this.qc.invalidateQueries({ queryKey: [...k] }));
531
+ for (const id of gone) {
532
+ if (current(id))
533
+ dropFromLists(this.qc, spec.ns, id);
534
+ }
535
+ ids.forEach(settle);
536
+ if (failed)
537
+ invalidateType(this.qc, spec);
538
+ else
539
+ spec.alsoInvalidate?.forEach((k) => this.qc.invalidateQueries({ queryKey: [...k] }));
429
540
  }
430
541
  catch (err) {
431
542
  console.error(`[realtime] bulk fetch for ${type} failed:`, err);
543
+ ids.forEach(settle);
432
544
  invalidateType(this.qc, spec);
433
545
  }
434
546
  }
@@ -437,6 +549,8 @@ export class ChangeApplier {
437
549
  clearTimeout(this.timer);
438
550
  this.timer = null;
439
551
  this.pending.clear();
552
+ this.latest.clear();
553
+ this.inflight.clear();
440
554
  }
441
555
  }
442
556
  /** Namespaces a mutation should refetch when no socket can deliver the change. */
@@ -61,4 +61,6 @@ export interface Company {
61
61
  default_pass_on_fees: boolean;
62
62
  require_team_for_clock_in: boolean;
63
63
  accepts_cash_payments: boolean;
64
+ /** IANA zone (e.g. `America/Chicago`) for route recurrence and bill days. */
65
+ timezone: string;
64
66
  }
@@ -2,7 +2,7 @@ import { _Event } from './_Event.js';
2
2
  declare module './DelayEvent.js' {
3
3
  interface DelayEvent extends _Event {
4
4
  line_item_type: 'DELAY';
5
- /** Seconds this delay added to each linked task's delay. */
5
+ /** Seconds after it was logged that this delay holds its tasks off. */
6
6
  delay_seconds: number;
7
7
  }
8
8
  }
@@ -1,5 +1,6 @@
1
1
  export declare const LineItemStatus: {
2
2
  readonly CREATED: "CREATED";
3
+ readonly PENDING_AUTOBILL: "PENDING_AUTOBILL";
3
4
  readonly EXTERNALLY_BILLED: "EXTERNALLY_BILLED";
4
5
  readonly BILLED: "BILLED";
5
6
  readonly PROCESSING: "PROCESSING";
@@ -38,5 +39,8 @@ export declare class LineItem {
38
39
  constructor(init?: Partial<LineItem>);
39
40
  isPaid: () => boolean;
40
41
  isBilled: () => boolean;
42
+ /** Matches the backend's "unbilled" bucket: `CREATED` only. */
41
43
  isUnbilled: () => boolean;
44
+ /** In flight: being auto-billed or a payment is processing (in no list bucket). */
45
+ isPending: () => boolean;
42
46
  }
@@ -1,5 +1,6 @@
1
1
  export const LineItemStatus = {
2
2
  CREATED: 'CREATED',
3
+ PENDING_AUTOBILL: 'PENDING_AUTOBILL',
3
4
  EXTERNALLY_BILLED: 'EXTERNALLY_BILLED',
4
5
  BILLED: 'BILLED',
5
6
  PROCESSING: 'PROCESSING',
@@ -27,8 +28,14 @@ export class LineItem {
27
28
  return (this.status === LineItemStatus.BILLED ||
28
29
  this.status === LineItemStatus.EXTERNALLY_BILLED);
29
30
  };
31
+ /** Matches the backend's "unbilled" bucket: `CREATED` only. */
30
32
  this.isUnbilled = () => {
31
- return !this.isBilled() && !this.isPaid();
33
+ return this.status === LineItemStatus.CREATED;
34
+ };
35
+ /** In flight: being auto-billed or a payment is processing (in no list bucket). */
36
+ this.isPending = () => {
37
+ return (this.status === LineItemStatus.PENDING_AUTOBILL ||
38
+ this.status === LineItemStatus.PROCESSING);
32
39
  };
33
40
  Object.assign(this, init);
34
41
  }
@@ -49,7 +49,17 @@ declare module './Task.js' {
49
49
  overdue_time: number;
50
50
  last_completed_event: _Event | null;
51
51
  current_event: _Event | null;
52
+ /**
53
+ * Seconds the due date was pushed back when the server serialized
54
+ * this task. Goes stale in cached responses; prefer `getDelayUntil()`.
55
+ */
52
56
  delay: number;
57
+ /**
58
+ * When (epoch seconds) the latest delay on this task ends, or null.
59
+ * A delay only holds until then; compare against the clock with
60
+ * `getDelayUntil()`.
61
+ */
62
+ delay_until: number | null;
53
63
  skills: string[];
54
64
  service: number;
55
65
  bill_mode: 'MONTH' | 'SERVICE' | 'NONE';
@@ -67,12 +77,22 @@ declare module './Task.js' {
67
77
  route_ids: string[];
68
78
  }
69
79
  }
80
+ /**
81
+ * End (epoch seconds) of a task's delay if it's still in effect, else null.
82
+ * A plain function so it works on spread copies of a Task too.
83
+ */
84
+ export declare const getTaskDelayUntil: (task: {
85
+ delay_until?: number | null;
86
+ }, now?: number) => number | null;
70
87
  export declare class Task {
71
88
  constructor(init?: Partial<Task>);
72
89
  getStatusLabel: () => "Active" | "Archived" | "Pending Activation" | "Draft" | "Pending Customer Approval" | "Pending Company Approval" | "Pending Payment";
73
90
  getUnroutedReasonLabel: () => string | null;
74
91
  isOverdue: () => boolean;
75
92
  getOverdueLabel: () => string;
93
+ /** End (epoch seconds) of this task's delay if it's still in effect. */
94
+ getDelayUntil: (now?: number) => number | null;
95
+ isDelayed: (now?: number) => boolean;
76
96
  getNextDue: () => number | null;
77
97
  computeNextTaskState: (isCustomer: boolean, action: "accept" | "modify" | "reject") => TaskStatus;
78
98
  getPrepaidEventsRemaining: () => number;
@@ -34,6 +34,11 @@ export const UNROUTED_REASON_LABELS = {
34
34
  MANDATORY_UNSERVED: 'Far past due and forced onto the day, but the day could not hold it',
35
35
  DID_NOT_FIT: 'Did not fit any schedule',
36
36
  };
37
+ /**
38
+ * End (epoch seconds) of a task's delay if it's still in effect, else null.
39
+ * A plain function so it works on spread copies of a Task too.
40
+ */
41
+ export const getTaskDelayUntil = (task, now = Date.now() / 1000) => (task.delay_until != null && task.delay_until > now ? task.delay_until : null);
37
42
  export class Task {
38
43
  constructor(init) {
39
44
  this.getStatusLabel = () => {
@@ -80,10 +85,15 @@ export class Task {
80
85
  return `${Math.floor(this.overdue_time / 86400)}d overdue`;
81
86
  }
82
87
  };
88
+ /** End (epoch seconds) of this task's delay if it's still in effect. */
89
+ this.getDelayUntil = (now) => getTaskDelayUntil(this, now);
90
+ this.isDelayed = (now) => this.getDelayUntil(now) !== null;
83
91
  this.getNextDue = () => {
84
92
  if (this.frequency > 0 && this.status === TaskStatus.ACTIVE) {
85
93
  const lastEventTime = this.last_completed_event?.time_ended ?? this.activate_on ?? this.time_created;
86
- return lastEventTime + this.delay + this.frequency;
94
+ const due = lastEventTime + this.frequency;
95
+ // A delay holds the task off until it ends, then lapses.
96
+ return Math.max(due, this.getDelayUntil() ?? due);
87
97
  }
88
98
  return null;
89
99
  };
@@ -225,9 +225,9 @@ export type EventUpdatePayload = Partial<Omit<_Event, 'users'>> & {
225
225
  /**
226
226
  * Wire payload for logging a delay (POST /job/{job_id}/delay).
227
227
  *
228
- * The backend applies `delay_seconds` to each task in `tasks`
229
- * atomically with the DelayEvent row — callers must NOT also bump
230
- * `task.delay` through a job update.
228
+ * Each task in `tasks` (and only those) isn't due until
229
+ * `delay_seconds` from now; after that the delay lapses on its own.
230
+ * Overlapping delays don't add up — the latest end wins.
231
231
  */
232
232
  export interface DelayEventCreatePayload {
233
233
  job_id: string;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.1.14";
1
+ export declare const AVRO_JS_VERSION = "1.6.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.1.14';
3
+ export const AVRO_JS_VERSION = '1.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.1.14",
3
+ "version": "1.6.0",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,6 +36,7 @@
36
36
  "license": "CC-BY-SA-4.0",
37
37
  "devDependencies": {
38
38
  "@eslint/js": "^9.39.4",
39
+ "@tanstack/react-query": "^5.90.2",
39
40
  "@types/react": "^19.2.2",
40
41
  "@types/uuid": "^10.0.0",
41
42
  "@typescript-eslint/eslint-plugin": "^8.38.0",
@@ -46,10 +47,15 @@
46
47
  "eslint-plugin-react": "^7.37.5",
47
48
  "globals": "^17.6.0",
48
49
  "prettier": "^3.8.3",
50
+ "react": "^19.0.0",
49
51
  "tsc-alias": "^1.8.17",
50
52
  "typescript": "^5.8.3",
51
53
  "typescript-eslint": "^8.38.0"
52
54
  },
55
+ "peerDependencies": {
56
+ "@tanstack/react-query": "^5.90.2",
57
+ "react": "^18.0.0 || ^19.0.0"
58
+ },
53
59
  "files": [
54
60
  "dist"
55
61
  ],
@@ -57,7 +63,6 @@
57
63
  "access": "public"
58
64
  },
59
65
  "dependencies": {
60
- "@tanstack/react-query": "^5.90.2",
61
66
  "socket.io-client": "^4.8.1",
62
67
  "uuid": "^14.0.0"
63
68
  }