@erdoai/cli 0.222.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 +74 -4
- 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
|
|
@@ -192,6 +210,16 @@ function parseCSV(text) {
|
|
|
192
210
|
return rows;
|
|
193
211
|
}
|
|
194
212
|
|
|
213
|
+
// src/order-by.ts
|
|
214
|
+
function parseOrderByOption(value) {
|
|
215
|
+
const match = /^(.*):(asc|desc)$/i.exec(value);
|
|
216
|
+
const column = (match ? match[1] : value).trim();
|
|
217
|
+
if (!column) {
|
|
218
|
+
throw new Error(`--order-by needs a column name, got "${value}"`);
|
|
219
|
+
}
|
|
220
|
+
return match ? { column, direction: match[2].toLowerCase() } : { column };
|
|
221
|
+
}
|
|
222
|
+
|
|
195
223
|
// src/knowledge-freshness.ts
|
|
196
224
|
function knowledgeFreshnessFromOptions(opts) {
|
|
197
225
|
const out = {};
|
|
@@ -1811,6 +1839,10 @@ var ErdoClient = class {
|
|
|
1811
1839
|
//
|
|
1812
1840
|
// revision_id runs the same read against a superseded storage revision instead
|
|
1813
1841
|
// of the dataset's live contents — the ids come from listDatasetRevisions.
|
|
1842
|
+
//
|
|
1843
|
+
// order_by, offset and include_total_rows page a read without SQL: the storage
|
|
1844
|
+
// engine sorts and slices, and total_rows is the matched-row count when counted
|
|
1845
|
+
// or proven by a short last page. They do not combine with sql_query.
|
|
1814
1846
|
fetchDatasetContents(slug, opts) {
|
|
1815
1847
|
return this.request(
|
|
1816
1848
|
"POST",
|
|
@@ -1819,7 +1851,10 @@ var ErdoClient = class {
|
|
|
1819
1851
|
sql_query: opts.sql_query,
|
|
1820
1852
|
limit: opts.limit,
|
|
1821
1853
|
filter_names: opts.filter_names,
|
|
1822
|
-
revision_id: opts.revision_id
|
|
1854
|
+
revision_id: opts.revision_id,
|
|
1855
|
+
order_by: opts.order_by,
|
|
1856
|
+
offset: opts.offset,
|
|
1857
|
+
include_total_rows: opts.include_total_rows
|
|
1823
1858
|
}
|
|
1824
1859
|
);
|
|
1825
1860
|
}
|
|
@@ -9102,7 +9137,12 @@ datasetsCmd.command("fetch <slug>").description(
|
|
|
9102
9137
|
).option(
|
|
9103
9138
|
"--revision <id>",
|
|
9104
9139
|
"read a superseded storage revision instead of the live table \u2014 the same SQL runs against the contents this id names, so a version that was overwritten is still queryable (see: erdo datasets revisions <slug> for the ids)"
|
|
9105
|
-
).
|
|
9140
|
+
).option(
|
|
9141
|
+
"--order-by <column[:desc]>",
|
|
9142
|
+
"sort without SQL by a column of the dataset, ascending unless suffixed :desc (repeatable; later keys break ties). Not with --sql.",
|
|
9143
|
+
(v, acc) => acc.concat(v),
|
|
9144
|
+
[]
|
|
9145
|
+
).option("--offset <n>", "skip this many sorted rows; with --limit it is a page. Not with --sql.", (v) => parseInt(v, 10)).option("--total", "also return total_rows, the count of every row the read matches. Not with --sql.").action(
|
|
9106
9146
|
async (slug, opts) => {
|
|
9107
9147
|
try {
|
|
9108
9148
|
print(
|
|
@@ -9110,7 +9150,10 @@ datasetsCmd.command("fetch <slug>").description(
|
|
|
9110
9150
|
sql_query: opts.sql,
|
|
9111
9151
|
limit: opts.limit,
|
|
9112
9152
|
filter_names: opts.filter.length ? opts.filter : void 0,
|
|
9113
|
-
revision_id: opts.revision
|
|
9153
|
+
revision_id: opts.revision,
|
|
9154
|
+
order_by: opts.orderBy.length ? opts.orderBy.map(parseOrderByOption) : void 0,
|
|
9155
|
+
offset: opts.offset,
|
|
9156
|
+
include_total_rows: opts.total || void 0
|
|
9114
9157
|
})
|
|
9115
9158
|
);
|
|
9116
9159
|
} catch (e) {
|
|
@@ -9315,7 +9358,7 @@ datasetsCmd.command("configure-integration <dataset-id>").description(
|
|
|
9315
9358
|
}
|
|
9316
9359
|
);
|
|
9317
9360
|
var refreshCmd = datasetsCmd.command("refresh").description(
|
|
9318
|
-
"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`"
|
|
9319
9362
|
);
|
|
9320
9363
|
var REFRESH_STRATEGIES = ["script", "script_js", "agent_run", "live_webhook"];
|
|
9321
9364
|
function readRefreshJSONFile(value, label) {
|
|
@@ -9620,6 +9663,33 @@ refreshCmd.command("set <slug>").description(
|
|
|
9620
9663
|
}
|
|
9621
9664
|
}
|
|
9622
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
|
+
});
|
|
9623
9693
|
refreshCmd.command("run <slug>").description(
|
|
9624
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."
|
|
9625
9695
|
).option("--json", "print the raw JSON result instead of a summary").action(async (slug, opts) => {
|