@istar-ts/actions 0.15.0-beta.3 → 0.15.0-beta.4

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.cjs CHANGED
@@ -19,7 +19,9 @@ const OPERATION_KIND_LIST = [
19
19
  "istar.setLinkValue",
20
20
  "istar.updateLinkDisplay",
21
21
  "istar.changeLinkKind",
22
- "istar.setFileMetamodel"
22
+ "istar.setFileMetamodel",
23
+ "istar.updateModelExtra",
24
+ "istar.replaceModel"
23
25
  ];
24
26
  const REQUEST_KIND_LIST = [
25
27
  "requestModel",
@@ -276,6 +278,11 @@ function rejectCheck(check, endpoints) {
276
278
  function metaOf(model) {
277
279
  return (0, _istar_ts_core.metamodelOf)(model);
278
280
  }
281
+ /**
282
+ * Keys `istar.updateModelExtra`'s `set`/`remove` must not touch: every key core models itself
283
+ * (`TOP_LEVEL_KEYS`, which includes `tool`), and `"metamodel"` (`istar.setFileMetamodel`'s own).
284
+ */
285
+ const RESERVED_EXTRA_KEYS = /* @__PURE__ */ new Set([..._istar_ts_core.TOP_LEVEL_KEYS, _istar_ts_core.FILE_METAMODEL_KEY]);
279
286
  /** A model with `links` changed, as the core operations derive one. */
280
287
  function withLinks(model, links) {
281
288
  return (0, _istar_ts_core.inheritMetamodel)(model, (0, _istar_ts_core.inheritSourceLayout)(model, {
@@ -582,6 +589,48 @@ function createActionDispatcher(store, options = {}) {
582
589
  s.replace(next);
583
590
  return;
584
591
  }
592
+ case "istar.updateModelExtra": {
593
+ const { set, remove, tool } = operation;
594
+ for (const key of [...Object.keys(set ?? {}), ...remove ?? []]) {
595
+ if (!RESERVED_EXTRA_KEYS.has(key)) continue;
596
+ if (key === "tool") reject(`"tool" is a modelled field: set it with this operation's own "tool"`, "", "reserved-key");
597
+ if (key === _istar_ts_core.FILE_METAMODEL_KEY) reject(`"${key}" is set with istar.setFileMetamodel, not updateModelExtra`, "", "reserved-key");
598
+ reject(`"${key}" is modelled by the file itself and cannot be an extra key`, "", "reserved-key");
599
+ }
600
+ let withTool = model;
601
+ if (tool === null) {
602
+ const { tool: _tool, ...rest } = withTool;
603
+ withTool = rest;
604
+ } else if (tool !== void 0) withTool = {
605
+ ...withTool,
606
+ tool
607
+ };
608
+ const extra = { ...withTool.extra };
609
+ if (set) for (const [key, value] of Object.entries(set)) extra[key] = value;
610
+ if (remove) for (const key of remove) delete extra[key];
611
+ const { extra: _extra, ...rest } = withTool;
612
+ const next = {
613
+ ...rest,
614
+ ...Object.keys(extra).length > 0 ? { extra } : {}
615
+ };
616
+ s.replace((0, _istar_ts_core.inheritMetamodel)(model, (0, _istar_ts_core.inheritSourceLayout)(model, next)));
617
+ return;
618
+ }
619
+ case "istar.replaceModel": {
620
+ const host = (0, _istar_ts_core.hostMetamodelOf)(model) ?? meta;
621
+ let next;
622
+ try {
623
+ next = (0, _istar_ts_core.parsePistar)(operation.model, {
624
+ metamodel: host,
625
+ fileMetamodel: operation.fileMetamodel ?? false
626
+ });
627
+ } catch (error) {
628
+ if (error instanceof _istar_ts_core.PistarParseError) reject(error.message, "", "parse-error");
629
+ throw error;
630
+ }
631
+ s.replace(next);
632
+ return;
633
+ }
585
634
  default: reject(`unknown operation "${operation.kind}"`, "", "unknown-action");
586
635
  }
587
636
  };
@@ -594,7 +643,8 @@ function createActionDispatcher(store, options = {}) {
594
643
  for (const [key, value] of Object.entries(properties)) if (value === null) delete next[key];
595
644
  else if (typeof value === "string") next[key] = value;
596
645
  else reject(`the value of "${key}" must be a string or null`, id, "invalid-value");
597
- const customProperties = Object.keys(next).length > 0 ? next : null;
646
+ if (Object.keys(next).length === 0 && owner.customProperties === void 0) return;
647
+ const customProperties = next;
598
648
  if (model.elements.has(id)) s.updateElement(id, { customProperties });
599
649
  else s.updateLink(id, { customProperties });
600
650
  };