@erdoai/cli 0.223.0 → 0.224.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.
- package/dist/index.js +46 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,6 +126,24 @@ function describeFreshnessTarget(state) {
|
|
|
126
126
|
|
|
127
127
|
// src/index.ts
|
|
128
128
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
129
|
+
|
|
130
|
+
// src/script-edits.ts
|
|
131
|
+
function parseScriptEdits(text) {
|
|
132
|
+
const parsed = JSON.parse(text);
|
|
133
|
+
const list = Array.isArray(parsed) ? parsed : parsed && typeof parsed === "object" && Array.isArray(parsed.edits) ? parsed.edits : null;
|
|
134
|
+
if (!list || list.length === 0) {
|
|
135
|
+
throw new Error('--edits must be a JSON array of {"old_string", "new_string"} (or {"edits": [...]}) with at least one edit');
|
|
136
|
+
}
|
|
137
|
+
return list.map((edit, i) => {
|
|
138
|
+
const e = edit;
|
|
139
|
+
if (typeof e?.old_string !== "string" || e.old_string === "" || typeof e.new_string !== "string") {
|
|
140
|
+
throw new Error(`edit ${i}: needs a non-empty string old_string and a string new_string`);
|
|
141
|
+
}
|
|
142
|
+
return { old_string: e.old_string, new_string: e.new_string };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/index.ts
|
|
129
147
|
import { basename as basename2 } from "path";
|
|
130
148
|
|
|
131
149
|
// src/csv.ts
|
|
@@ -9340,7 +9358,7 @@ datasetsCmd.command("configure-integration <dataset-id>").description(
|
|
|
9340
9358
|
}
|
|
9341
9359
|
);
|
|
9342
9360
|
var refreshCmd = datasetsCmd.command("refresh").description(
|
|
9343
|
-
"The recipe that keeps a dataset current, and the triggers that run it \u2014 read it with `show`, install or replace it with `set`, and run it once now with `run`"
|
|
9361
|
+
"The recipe that keeps a dataset current, and the triggers that run it \u2014 read it with `show`, install or replace it with `set`, change part of its script with `edit`, and run it once now with `run`"
|
|
9344
9362
|
);
|
|
9345
9363
|
var REFRESH_STRATEGIES = ["script", "script_js", "agent_run", "live_webhook"];
|
|
9346
9364
|
function readRefreshJSONFile(value, label) {
|
|
@@ -9645,6 +9663,33 @@ refreshCmd.command("set <slug>").description(
|
|
|
9645
9663
|
}
|
|
9646
9664
|
}
|
|
9647
9665
|
);
|
|
9666
|
+
refreshCmd.command("edit <slug>").description(
|
|
9667
|
+
"Change part of a dataset's saved script or transform_js without resending it: each old_string must match the saved source exactly once. Only the source changes; the schedule and every other setting stay as saved. The edited recipe is compile-checked and test-run like `set`"
|
|
9668
|
+
).requiredOption("--edits <@file>", 'JSON file: [{"old_string": "...", "new_string": "..."}, ...], applied in order').action(async (slug, opts) => {
|
|
9669
|
+
try {
|
|
9670
|
+
const path = opts.edits.startsWith("@") ? opts.edits.slice(1) : opts.edits;
|
|
9671
|
+
const edits = parseScriptEdits(readFileSync5(path, "utf8"));
|
|
9672
|
+
const client = new ErdoClient();
|
|
9673
|
+
const current = await client.getDatasetRefresh(slug);
|
|
9674
|
+
if (!current.configured || !current.strategy) {
|
|
9675
|
+
fail(new Error(`${slug} has no saved refresh to edit; install one with: erdo datasets refresh set ${slug}`));
|
|
9676
|
+
return;
|
|
9677
|
+
}
|
|
9678
|
+
const res = await client.setDatasetRefresh(slug, { strategy: current.strategy, script_edits: edits });
|
|
9679
|
+
console.log(`Edited the ${res.strategy} source of ${res.dataset_slug} (${edits.length} ${edits.length === 1 ? "edit" : "edits"}); every other setting is unchanged`);
|
|
9680
|
+
if (res.test_run) {
|
|
9681
|
+
if (res.test_run.success) {
|
|
9682
|
+
console.log(`test run: passed in ${res.test_run.duration_ms} ms`);
|
|
9683
|
+
} else {
|
|
9684
|
+
console.error(`test run: FAILED after ${res.test_run.duration_ms} ms \u2014 ${res.test_run.error || "no error reported"}`);
|
|
9685
|
+
console.error("The edit is saved but the recipe does not run. Fix it with another edit.");
|
|
9686
|
+
process.exitCode = 1;
|
|
9687
|
+
}
|
|
9688
|
+
}
|
|
9689
|
+
} catch (e) {
|
|
9690
|
+
fail(e);
|
|
9691
|
+
}
|
|
9692
|
+
});
|
|
9648
9693
|
refreshCmd.command("run <slug>").description(
|
|
9649
9694
|
"Run a dataset's configured refresh once, now \u2014 the same recipe a cron or a page view would run, without waiting for either. It is asynchronous: this answers with the execution it started, and `datasets refresh show <slug>` carries the outcome once it finishes."
|
|
9650
9695
|
).option("--json", "print the raw JSON result instead of a summary").action(async (slug, opts) => {
|