@erdoai/cli 0.202.0 → 0.203.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 (2) hide show
  1. package/dist/index.js +57 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -79,6 +79,50 @@ function formatRefreshJobRow(r) {
79
79
  if (r.keep_running) notes.push("keep-running");
80
80
  return `${r.id} ${r.state} ${r.name} refresh${notes.length ? ` ${notes.join("; ")}` : ""}`;
81
81
  }
82
+ var FRESHNESS_TARGET_MIN_SECONDS = 5 * 60;
83
+ var FRESHNESS_TARGET_MAX_SECONDS = 366 * 24 * 60 * 60;
84
+ var FRESHNESS_UNITS = { s: 1, m: 60, h: 60 * 60, d: 24 * 60 * 60, w: 7 * 24 * 60 * 60 };
85
+ function parseFreshnessTarget(value) {
86
+ const text = value.trim().toLowerCase();
87
+ if (text === "off" || text === "none" || text === "0") return 0;
88
+ let seconds;
89
+ if (/^\d+$/.test(text)) {
90
+ seconds = Number(text);
91
+ } else {
92
+ const parts = text.match(/^(?:\d+[smhdw])+$/) ? text.match(/\d+[smhdw]/g) : null;
93
+ if (!parts) {
94
+ throw new Error(`--freshness-target must be a duration like 30m, 2h, 1d or 1h30m, a number of seconds, or off (got ${JSON.stringify(value)})`);
95
+ }
96
+ seconds = parts.reduce((total, part) => total + Number(part.slice(0, -1)) * FRESHNESS_UNITS[part.slice(-1)], 0);
97
+ }
98
+ if (seconds === 0) return 0;
99
+ if (seconds < FRESHNESS_TARGET_MIN_SECONDS || seconds > FRESHNESS_TARGET_MAX_SECONDS) {
100
+ throw new Error("--freshness-target must be between 5m and 366d, or off to clear it");
101
+ }
102
+ return seconds;
103
+ }
104
+ function formatFreshnessTarget(seconds) {
105
+ const units = [[24 * 60 * 60, "day"], [60 * 60, "hour"], [60, "minute"]];
106
+ const plural = (n, unit) => `${n} ${unit}${n === 1 ? "" : "s"}`;
107
+ for (let i = 0; i < units.length; i++) {
108
+ const [size, name] = units[i];
109
+ if (seconds < size) continue;
110
+ let text = plural(Math.floor(seconds / size), name);
111
+ if (i + 1 < units.length) {
112
+ const minor = Math.floor(seconds % size / units[i + 1][0]);
113
+ if (minor > 0) text += ` ${plural(minor, units[i + 1][1])}`;
114
+ }
115
+ return text;
116
+ }
117
+ return plural(seconds, "second");
118
+ }
119
+ function describeFreshnessTarget(state) {
120
+ if (!state.freshness_target_seconds) return void 0;
121
+ const target = `data no older than ${formatFreshnessTarget(state.freshness_target_seconds)} \u2014 its owner is alerted when it falls behind, and it is never paused for being unread`;
122
+ if (!state.freshness_alert) return target;
123
+ const since = state.freshness_alert_raised_at ? ` since ${state.freshness_alert_raised_at}` : "";
124
+ return `${target}. ALERTING${since}: ${state.freshness_alert}`;
125
+ }
82
126
 
83
127
  // src/index.ts
84
128
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
@@ -9128,6 +9172,8 @@ refreshCmd.command("show <slug>").description(
9128
9172
  const pendingPause = describePendingPause(res);
9129
9173
  if (pendingPause) rows.push(["pause warning", pendingPause]);
9130
9174
  if (res.keep_running) rows.push(["keep running", "yes \u2014 never paused for being unread"]);
9175
+ const freshness = describeFreshnessTarget(res);
9176
+ if (freshness) rows.push(["freshness target", freshness]);
9131
9177
  const eventTriggers = describeEventTriggers(res);
9132
9178
  if (eventTriggers) rows.push(["event triggers", eventTriggers]);
9133
9179
  if (res.schedule) {
@@ -9231,6 +9277,9 @@ refreshCmd.command("set <slug>").description(
9231
9277
  "--debounce <seconds>",
9232
9278
  "minimum gap between two view-triggered refreshes",
9233
9279
  (v) => parseInt(v, 10)
9280
+ ).option(
9281
+ "--freshness-target <duration>",
9282
+ "for a durable dataset people or systems rely on: the longest its data may go without a successful refresh or a write, e.g. 2h, 1d or 1h30m (5m to 366d). If it goes stale, or its refresh is paused or failing, the refresh's owner gets one attention item that resolves itself once the data is fresh again, and the refresh is never paused for being unread. Omit to keep the saved target; pass off to clear it"
9234
9283
  ).option(
9235
9284
  "--live-write-mode <append|replace>",
9236
9285
  "for the live strategies: append for a time-series that accumulates, replace for current state that overwrites on each event"
@@ -9340,6 +9389,9 @@ refreshCmd.command("set <slug>").description(
9340
9389
  body.refresh_on_view_stale_after_seconds = opts.staleAfter;
9341
9390
  }
9342
9391
  if (opts.debounce !== void 0) body.refresh_on_view_debounce_seconds = opts.debounce;
9392
+ if (opts.freshnessTarget !== void 0) {
9393
+ body.freshness_target_seconds = parseFreshnessTarget(opts.freshnessTarget);
9394
+ }
9343
9395
  if (opts.liveWriteMode) body.live_write_mode = opts.liveWriteMode;
9344
9396
  if (opts.payloadSchema) {
9345
9397
  body.payload_schema = readRefreshJSONFile(opts.payloadSchema, "--payload-schema");
@@ -9365,6 +9417,11 @@ refreshCmd.command("set <slug>").description(
9365
9417
  job_enabled: body.job_enabled,
9366
9418
  schedule_enabled: body.schedule_enabled
9367
9419
  }));
9420
+ if (res.freshness_target_seconds) {
9421
+ console.log(`freshness target: ${formatFreshnessTarget(res.freshness_target_seconds)} \u2014 its owner is alerted when the data falls behind`);
9422
+ } else if (body.freshness_target_seconds === 0) {
9423
+ console.log("freshness target: cleared");
9424
+ }
9368
9425
  if (res.job_id) console.log(`job: ${res.job_id}`);
9369
9426
  if (res.webhook_url) {
9370
9427
  console.log(`webhook url: ${res.webhook_url}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.202.0",
3
+ "version": "0.203.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {