@go-avro/avro-js 0.1.14 → 0.1.15

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.
@@ -632,12 +632,15 @@ export class AvroQueryClient {
632
632
  }
633
633
  const features = pelias.value?.features ?? [];
634
634
  const knownLabels = new Set(features.map((feature) => feature.properties.label.toLowerCase()));
635
+ // Census only answers with exact geocodes of a complete address, so
636
+ // its matches lead; Pelias can fill the list with same-named streets
637
+ // elsewhere and bury the address the user actually typed.
635
638
  return {
636
639
  ...pelias.value,
637
640
  type: 'FeatureCollection',
638
641
  features: [
639
- ...features,
640
642
  ...census.filter((feature) => !knownLabels.has(feature.properties.label.toLowerCase())),
643
+ ...features,
641
644
  ],
642
645
  };
643
646
  }
@@ -154,8 +154,8 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
154
154
  cost: 0,
155
155
  amount: 1,
156
156
  });
157
- // The server bumps task.delay atomically with the delay
158
- // event; mirror that into the cached job.
157
+ // Mirror the server: each delayed task isn't due until the
158
+ // later of its own delay ends and this one does.
159
159
  const previousJob = queryClient.getQueryData([
160
160
  'jobs',
161
161
  delayData.job_id,
@@ -165,11 +165,14 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
165
165
  ...previousJob,
166
166
  tasks: previousJob.tasks.map((task) => {
167
167
  if (delayData.tasks.includes(task.id ?? '')) {
168
+ const delayUntil = Math.max(task.delay_until != null && task.delay_until > now
169
+ ? task.delay_until
170
+ : 0, now + delayData.delay_seconds);
168
171
  return {
169
172
  ...task,
170
- delay: (task.delay ?? 0) + delayData.delay_seconds,
173
+ delay_until: delayUntil,
171
174
  overdue_time: task.overdue_time != null
172
- ? task.overdue_time - delayData.delay_seconds
175
+ ? Math.min(task.overdue_time, now - delayUntil)
173
176
  : task.overdue_time,
174
177
  };
175
178
  }
@@ -279,8 +282,10 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
279
282
  ? { ...previousEvent, ...updates }
280
283
  : task.last_completed_event
281
284
  : task.last_completed_event,
285
+ // Next due a period out, or when an active
286
+ // delay ends if that's later.
282
287
  overdue_time: isEnding
283
- ? -(task.frequency ?? 0) - (task.delay ?? 0)
288
+ ? -Math.max(task.frequency ?? 0, (task.delay_until ?? 0) - Date.now() / 1000)
284
289
  : task.overdue_time,
285
290
  };
286
291
  }
@@ -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
  }
@@ -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 = "0.1.15";
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 = '0.1.15';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",