@eide/foir-cli 0.19.0 → 0.20.1

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/cli.js +58 -4
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4945,13 +4945,37 @@ var PushConflictError = class extends Error {
4945
4945
  this.conflicts = conflicts;
4946
4946
  }
4947
4947
  };
4948
+ function normalizeForDiff(v) {
4949
+ if (v === null || v === void 0) return void 0;
4950
+ if (Array.isArray(v)) {
4951
+ const items = v.map(normalizeForDiff).filter((x) => x !== void 0);
4952
+ return items.length ? items : void 0;
4953
+ }
4954
+ if (typeof v !== "object") {
4955
+ if (v === false || v === "" || v === 0) return void 0;
4956
+ return v;
4957
+ }
4958
+ const obj = v;
4959
+ const out = {};
4960
+ for (const [k, val] of Object.entries(obj)) {
4961
+ if (k === "$typeName") continue;
4962
+ if (k === "id") continue;
4963
+ const norm = normalizeForDiff(val);
4964
+ if (norm === void 0) continue;
4965
+ out[k] = norm;
4966
+ }
4967
+ return Object.keys(out).length ? out : void 0;
4968
+ }
4948
4969
  function canonicalize(v) {
4970
+ return canonicalJson(normalizeForDiff(v));
4971
+ }
4972
+ function canonicalJson(v) {
4949
4973
  if (v === void 0) return "undefined";
4950
4974
  if (v === null || typeof v !== "object") return JSON.stringify(v);
4951
- if (Array.isArray(v)) return "[" + v.map(canonicalize).join(",") + "]";
4975
+ if (Array.isArray(v)) return "[" + v.map(canonicalJson).join(",") + "]";
4952
4976
  const obj = v;
4953
4977
  const keys = Object.keys(obj).sort();
4954
- return "{" + keys.map((k) => JSON.stringify(k) + ":" + canonicalize(obj[k])).join(",") + "}";
4978
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + canonicalJson(obj[k])).join(",") + "}";
4955
4979
  }
4956
4980
  function deepEqual(a, b) {
4957
4981
  return canonicalize(a) === canonicalize(b);
@@ -6625,7 +6649,9 @@ function registerRecordsCommands(program2, globalOpts) {
6625
6649
  }
6626
6650
  )
6627
6651
  );
6628
- records.command("update <modelKey> <id>").description("Update a record").option("-d, --data <json>", "Record data as JSON").option("-f, --file <path>", "Read data from file").action(
6652
+ records.command("update <modelKey> <id>").description(
6653
+ "Update a record's data column directly. Bypasses versioning \u2014 no version row is created and currentVersionId is unchanged. For the admin-equivalent atomic save (data + new version + currentVersionId bump), use `records save`."
6654
+ ).option("-d, --data <json>", "Record data as JSON").option("-f, --file <path>", "Read data from file").action(
6629
6655
  withErrorHandler(
6630
6656
  globalOpts,
6631
6657
  async (_modelKey, id, cmdOpts) => {
@@ -6641,6 +6667,34 @@ function registerRecordsCommands(program2, globalOpts) {
6641
6667
  }
6642
6668
  )
6643
6669
  );
6670
+ records.command("save <modelKey> <id>").description(
6671
+ "Save record content (admin Save Draft equivalent). Atomically replaces data, creates an immutable version row, and advances currentVersionId \u2014 preview and storefront see the new content without a separate publish step."
6672
+ ).option("-d, --data <json>", "Record data as JSON").option("-f, --file <path>", "Read data from file").option("-m, --message <msg>", "Change description").option("--variant <key>", "Save into a specific variant").action(
6673
+ withErrorHandler(
6674
+ globalOpts,
6675
+ async (_modelKey, id, cmdOpts) => {
6676
+ const opts = globalOpts();
6677
+ const client = await createPlatformClient(opts);
6678
+ const inputData = await parseInputData(cmdOpts);
6679
+ const result = await client.records.saveContent({
6680
+ recordId: id,
6681
+ data: inputData,
6682
+ variantKey: cmdOpts.variant,
6683
+ changeDescription: cmdOpts.message
6684
+ });
6685
+ formatOutput(
6686
+ {
6687
+ record: result.record ? toJson3(RecordSchema, result.record) : null,
6688
+ version: result.version ? toJson3(RecordSchema, result.version) : null
6689
+ },
6690
+ opts
6691
+ );
6692
+ if (!(opts.json || opts.jsonl || opts.quiet)) {
6693
+ success(`Saved record ${id} \u2192 version ${result.version?.id}`);
6694
+ }
6695
+ }
6696
+ )
6697
+ );
6644
6698
  records.command("delete <modelKey> <id>").description("Delete a record").option("--confirm", "Skip confirmation prompt").action(
6645
6699
  withErrorHandler(
6646
6700
  globalOpts,
@@ -6748,7 +6802,7 @@ function registerRecordsCommands(program2, globalOpts) {
6748
6802
  })
6749
6803
  );
6750
6804
  records.command("create-version <parentId>").description(
6751
- "Create a new version on a versioned record (or variant). parentId is the record or variant ID."
6805
+ "Low-level: create a version row without touching the parent record's data column or currentVersionId. The new version is orphaned from preview/storefront resolution until published. For the admin-equivalent atomic save (data + version + currentVersionId), use `records save`."
6752
6806
  ).option("-d, --data <json>", "Version content as JSON").option("-f, --file <path>", "Read content from file").option("-m, --message <msg>", "Change description").option("--source-version <id>", "Source version ID to base off").action(
6753
6807
  withErrorHandler(
6754
6808
  globalOpts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eide/foir-cli",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "description": "Universal platform CLI for Foir platform",
5
5
  "type": "module",
6
6
  "publishConfig": {