@erdoai/cli 0.231.1 → 0.232.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 +80 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1748,6 +1748,24 @@ var ErdoClient = class {
1748
1748
  deleteDataset(slug) {
1749
1749
  return this.request("DELETE", `/v1/datasets/${encodeURIComponent(slug)}`);
1750
1750
  }
1751
+ // The /v1 endpoint is a DELETE, whose parameters Encore reads from the query
1752
+ // string, so the keys travel there and never in a body. Not replayed after a
1753
+ // network failure, so rows_affected reports this call's deletions.
1754
+ deleteDatasetRows(slug, input) {
1755
+ const query = new URLSearchParams();
1756
+ if ("delete_all" in input) {
1757
+ query.set("delete_all", "true");
1758
+ } else {
1759
+ query.set("key_column", input.key_column);
1760
+ for (const key of input.keys) query.append("keys", key);
1761
+ }
1762
+ return this.request(
1763
+ "DELETE",
1764
+ `/v1/datasets/${encodeURIComponent(slug)}/rows?${query.toString()}`,
1765
+ void 0,
1766
+ false
1767
+ );
1768
+ }
1751
1769
  setDatasetPurpose(slug, input) {
1752
1770
  return this.updateDatasetSchema(slug, input);
1753
1771
  }
@@ -8757,6 +8775,68 @@ datasetsCmd.command("write <slug>").description(
8757
8775
  }
8758
8776
  }
8759
8777
  );
8778
+ var DELETE_ROWS_BATCH = 100;
8779
+ function parseDeleteKeys(raw) {
8780
+ const text = (readMaybeFile(raw) ?? "").trim();
8781
+ let keys;
8782
+ if (text.startsWith("[")) {
8783
+ try {
8784
+ keys = JSON.parse(text);
8785
+ } catch (error) {
8786
+ throw new Error(`--keys JSON must be valid: ${error instanceof Error ? error.message : String(error)}`);
8787
+ }
8788
+ if (!Array.isArray(keys) || keys.some((key) => typeof key !== "string" && typeof key !== "number")) {
8789
+ throw new Error("--keys JSON must be an array of strings");
8790
+ }
8791
+ keys = keys.map(String);
8792
+ } else {
8793
+ keys = text.split("\n");
8794
+ }
8795
+ const cleaned = [...new Set(keys.map((key) => key.trim()).filter(Boolean))];
8796
+ if (cleaned.length === 0) {
8797
+ throw new Error("--keys names no keys");
8798
+ }
8799
+ return cleaned;
8800
+ }
8801
+ datasetsCmd.command("delete-rows <slug>").description(
8802
+ "Permanently delete rows from a dataset (the erdo_delete_dataset_rows MCP tool): every row whose --key-column equals one of --keys, or with --all every row. Deleted rows also leave the change history, so restore-row cannot bring them back: fetch them first if you may want them. Nothing is deleted without --yes"
8803
+ ).option("--key-column <column>", "the column to match --keys against").option("--keys <keys-or-@file>", "keys to delete: a JSON array, or one key per line; @path reads a file").option("--all", "delete every row instead of named keys").option("--yes", "confirm the permanent deletion").action(async (slug, opts) => {
8804
+ try {
8805
+ const keyColumn = opts.keyColumn?.trim();
8806
+ if (opts.all && (keyColumn || opts.keys !== void 0)) {
8807
+ throw new Error("--all cannot be combined with --key-column or --keys");
8808
+ }
8809
+ if (!opts.all && (!keyColumn || opts.keys === void 0)) {
8810
+ throw new Error("name the rows to delete with --key-column and --keys, or pass --all to delete every row");
8811
+ }
8812
+ const keys = opts.all ? [] : parseDeleteKeys(opts.keys);
8813
+ if (!opts.yes) {
8814
+ throw new Error(
8815
+ opts.all ? `deleting every row of ${slug} is permanent; rerun with --yes to delete them` : `deleting up to ${keys.length} key(s) from ${slug} is permanent; rerun with --yes to delete them`
8816
+ );
8817
+ }
8818
+ const client = new ErdoClient();
8819
+ if (opts.all) {
8820
+ print(await client.deleteDatasetRows(slug, { delete_all: true }));
8821
+ return;
8822
+ }
8823
+ let rowsAffected = 0;
8824
+ for (let start = 0; start < keys.length; start += DELETE_ROWS_BATCH) {
8825
+ const batch = keys.slice(start, start + DELETE_ROWS_BATCH);
8826
+ try {
8827
+ rowsAffected += (await client.deleteDatasetRows(slug, { key_column: keyColumn, keys: batch })).rows_affected;
8828
+ } catch (error) {
8829
+ if (start > 0) {
8830
+ console.error(`deleted ${rowsAffected} row(s) for the first ${start} of ${keys.length} keys before this failure`);
8831
+ }
8832
+ throw error;
8833
+ }
8834
+ }
8835
+ print({ rows_affected: rowsAffected, keys_requested: keys.length });
8836
+ } catch (e) {
8837
+ fail(e);
8838
+ }
8839
+ });
8760
8840
  function readSchemaFile(path) {
8761
8841
  const parsed = JSON.parse(readFileSync5(path, "utf8"));
8762
8842
  const schema = Array.isArray(parsed) ? { columns: parsed } : parsed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.231.1",
3
+ "version": "0.232.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {