@istar-ts/actions 0.0.0-stage → 0.15.0-beta.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/LICENSE +44 -0
- package/README.md +103 -2
- package/dist/index.cjs +1118 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +741 -0
- package/dist/index.d.ts +741 -0
- package/dist/index.js +1103 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vieira Neto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Portions of this software are derived from piStar (https://github.com/jhcp/piStar),
|
|
26
|
+
© João Pimentel and contributors, MIT License:
|
|
27
|
+
|
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
30
|
+
in the Software without restriction, including without limitation the rights
|
|
31
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
33
|
+
furnished to do so, subject to the following conditions:
|
|
34
|
+
|
|
35
|
+
The above copyright notice and this permission notice shall be included in all
|
|
36
|
+
copies or substantial portions of the Software.
|
|
37
|
+
|
|
38
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
42
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
43
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
44
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @istar-ts/actions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A typed, checked, undoable way to edit an istar-ts model from anywhere: the canvas, a language
|
|
4
|
+
server's quick fix, a CLI, an LLM agent. A subset of the
|
|
5
|
+
[GLSP action protocol](https://eclipse.dev/glsp/documentation/protocol/) over a `ModelStore`,
|
|
6
|
+
framework-free, depending only on `@istar-ts/core`.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createModelStore } from '@istar-ts/core';
|
|
10
|
+
import { createActionDispatcher } from '@istar-ts/actions';
|
|
11
|
+
|
|
12
|
+
const store = createModelStore(model);
|
|
13
|
+
const dispatcher = createActionDispatcher(store, {
|
|
14
|
+
guards: [(operation, model) => /* host rules */ []],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const result = await dispatcher.dispatch({
|
|
18
|
+
kind: 'createNode',
|
|
19
|
+
elementTypeId: 'istar.Goal',
|
|
20
|
+
containerId: actorId,
|
|
21
|
+
location: { x: 120, y: 80 },
|
|
22
|
+
});
|
|
23
|
+
if (result.ok) console.log(result.createdIds);
|
|
24
|
+
else console.log(result.diagnostics); // GoalDiagnostic[]; the model is untouched
|
|
25
|
+
|
|
26
|
+
dispatcher.subscribe((action) => {
|
|
27
|
+
if (action.kind === 'sourceModelChanged') refresh();
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- **Operations** (one undo step each): `createNode`, `createEdge` (a dependency creates its
|
|
32
|
+
dependum and two links), `deleteElement`, `changeBounds`, `changeContainer`, `reconnectEdge`,
|
|
33
|
+
`applyLabelEdit` (`"<id>"` for a name, `"<id>#<key>"` for a custom property; an empty name on a
|
|
34
|
+
link removes it), `compound`, and `istar.addLeg`, `istar.removeLeg`, `istar.setCollapsed`,
|
|
35
|
+
`istar.updateDiagram`, `istar.updateProperties`, `istar.updateDisplay` (an element's `display`
|
|
36
|
+
patch), `istar.setLinkValue` (an existing link's contribution value).
|
|
37
|
+
- **Requests**: `requestModel` (the piStar file), `requestTypeHints` (from the metamodel),
|
|
38
|
+
`requestCheckEdge` (`canLink`), `requestContextActions` (the palette, `DEFAULT_PALETTE` unless
|
|
39
|
+
the `palette` option says otherwise), `requestMarkers` (link and property issues, and the host's
|
|
40
|
+
diagnostics, as GLSP markers).
|
|
41
|
+
- `glspUndo`, `glspRedo`, `saveModel` (through the `save` option), and the notifications
|
|
42
|
+
`sourceModelChanged` and `setDirtyState` sent to subscribers.
|
|
43
|
+
|
|
44
|
+
Every action and result is plain JSON, so an `ActionDispatcher` can live across a
|
|
45
|
+
`postMessage`.
|
|
46
|
+
|
|
47
|
+
## Transport
|
|
48
|
+
|
|
49
|
+
`connectDispatcher`/`createRemoteDispatcher` carry an `ActionDispatcher` over a
|
|
50
|
+
`MessagePort`-like object (`{ postMessage, onmessage }` — a DOM `MessagePort` or a worker fits),
|
|
51
|
+
framed as JSON-RPC 2.0: a dispatch is a request (`method` = the action's `kind`, `params` = the
|
|
52
|
+
action), answered with the `ActionResult` as `result`; `subscribe` events go server to client as
|
|
53
|
+
notifications. A rejection (`ok: false`) is a normal result, not a JSON-RPC error — only a
|
|
54
|
+
malformed frame or an unhandled exception is (`-32600`/`-32601`/`-32603`).
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { connectDispatcher, createRemoteDispatcher } from '@istar-ts/actions';
|
|
58
|
+
|
|
59
|
+
const dispose = connectDispatcher(serverPort, dispatcher); // server side
|
|
60
|
+
const remote = createRemoteDispatcher(clientPort); // client side, same ActionDispatcher interface
|
|
61
|
+
await remote.dispatch({ kind: 'createNode', elementTypeId: 'istar.Goal' });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This frames one JSON-RPC method per action kind, not yet GLSP's own five-method lifecycle
|
|
65
|
+
(`initialize`/`initializeClientSession`/`process`/`disposeClientSession`/`shutdown`); see
|
|
66
|
+
[`docs/action-protocol.md`](https://github.com/vieirin/istar-ts/blob/main/docs/action-protocol.md)
|
|
67
|
+
for the GLSP mapping, the gap, and [#44](https://github.com/vieirin/istar-ts/issues/44).
|
|
68
|
+
|
|
69
|
+
## Mirror store
|
|
70
|
+
|
|
71
|
+
`createMirrorStore(remote)` is a read-only `ModelStore` whose model follows a dispatcher that
|
|
72
|
+
lives elsewhere (a worker, a server, a `createRemoteDispatcher` port), so anything that renders a
|
|
73
|
+
`ModelStore` (`<IstarCanvas>`, the inspector) can show it:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { createActionDispatcher, createMirrorStore } from '@istar-ts/actions';
|
|
77
|
+
|
|
78
|
+
// Where the model lives: push the model with each change (`sendModel`), then serve it.
|
|
79
|
+
connectDispatcher(port, createActionDispatcher(store, { sendModel: true }));
|
|
80
|
+
|
|
81
|
+
// In the page:
|
|
82
|
+
const mirror = createMirrorStore(createRemoteDispatcher(otherPort), { metamodel });
|
|
83
|
+
await mirror.ready; // the first `requestModel` answered
|
|
84
|
+
await mirror.dispatcher.dispatch(action); // resolves once the mirror shows the change
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **Updates.** It asks for the model once (`requestModel`), then follows `sourceModelChanged`.
|
|
88
|
+
With `sendModel`, the notification carries the new model as `newRoot` (piStar JSON) and the
|
|
89
|
+
mirror applies it as it arrives; without it, the mirror answers each notification with a
|
|
90
|
+
`requestModel`. The update is the whole file, re-parsed: on the largest fixture (smartHome, 237
|
|
91
|
+
ids, 48 KB of JSON) a pushed update costs about 3 ms (`toPistarObject` 0.3 ms, the structured
|
|
92
|
+
clone 0.5 ms, `parsePistar` 2.2 ms), a re-requested one about 7 ms over a `MessageChannel`. An
|
|
93
|
+
element, link or diagram equal to the one it replaces keeps its old object, and so does the
|
|
94
|
+
metamodel while the file's `"metamodel"` block is unchanged.
|
|
95
|
+
- **Order.** Changes apply in the order the remote sends them, whoever made them.
|
|
96
|
+
`mirror.dispatcher` is the remote with one guarantee added: `dispatch` resolves after the mirror
|
|
97
|
+
shows what the action did, so code that selects a created id, or rolls back a rejected one,
|
|
98
|
+
sees the model it expects. With a `sendModel` remote the plain remote already has that order (a
|
|
99
|
+
change's notification arrives before its result). A rejected action changes nothing, mirror
|
|
100
|
+
included.
|
|
101
|
+
- **Writes.** Every mutation (`addElement` … `replace`, `load`, `transaction`, `clearHistory`)
|
|
102
|
+
throws a `ModelOperationError`: dispatch to the remote. `undo`/`redo` dispatch `glspUndo` /
|
|
103
|
+
`glspRedo`, so there is one undo stack, the remote's. `canUndo`/`canRedo` are counted from the
|
|
104
|
+
notifications heard since the mirror connected; earlier edits aren't counted.
|