Add project command API

This commit is contained in:
2026-07-23 21:56:13 +02:00
parent 1e4dd26bb8
commit e4c7cf06e9
19 changed files with 781 additions and 21 deletions
+38 -4
View File
@@ -6,15 +6,49 @@ The circuit-first editor uses tree, circuit, row and project-device endpoints.
All paths below are mounted below `/api`. There is no Consumer application API.
Project responses from `GET /projects` and `GET /projects/:projectId` include
`currentRevision`. It currently exposes the persisted revision foundation only;
no public undo or redo command exists yet.
`currentRevision`. Versioned project commands use this value for optimistic
concurrency checks.
### Project History State
### Project Commands and History
- `GET /projects/:projectId/history`
- returns `currentRevision`, `undoDepth`, `redoDepth` and the current top
change-set id for both persistent stacks
- is read-only; the editor does not consume it yet
- `POST /projects/:projectId/commands`
- executes a supported versioned command as a new user revision
- body: `{ "expectedRevision": 0, "command": { ... } }`
- `POST /projects/:projectId/history/undo`
- `POST /projects/:projectId/history/redo`
- body: `{ "expectedRevision": 1 }`
- executes the eligible inverse or forward command as a new auditable
revision
The public dispatcher currently supports `circuit.update` and
`circuit-device-row.update`, both with schema version `1`. Other command types
are rejected. The editor does not consume these endpoints yet.
Example:
```json
{
"expectedRevision": 0,
"description": "Rename circuit",
"command": {
"schemaVersion": 1,
"type": "circuit.update",
"payload": {
"circuitId": "cir_1",
"changes": [
{ "field": "displayName", "value": "Sockets East" }
]
}
}
}
```
A stale `expectedRevision` returns HTTP `409` with
`PROJECT_REVISION_CONFLICT`. Undo or redo without an eligible stack entry
returns HTTP `409` with `PROJECT_HISTORY_OPERATION_UNAVAILABLE`.
## Circuit-First Endpoints
+6 -3
View File
@@ -76,9 +76,12 @@ Gerätezeilen-Kommandos bewahren dabei auch lokale ProjectDevice-Overrides und
prüfen Projektzugehörigkeit von Verknüpfungen und Räumen. Projektweite,
persistente Undo-/Redo-Stacks verwalten die zulässige LIFO-Reihenfolge und
verwerfen den Redo-Zweig bei einem neuen Benutzerkommando. Ihr Status ist über
`GET /api/projects/:projectId/history` lesbar. Die schreibenden Command-Stores
sind noch nicht über die API oder das Grid aktiviert; serverseitiges Undo/Redo
ist daher noch nicht verfügbar.
`GET /api/projects/:projectId/history` lesbar. Ein zentraler Dispatcher führt
die unterstützten Typen `circuit.update` und `circuit-device-row.update` über
öffentliche Command-, Undo- und Redo-Endpunkte aus. Das Grid verwendet diese
Endpunkte noch nicht; seine sichtbare Historie bleibt daher sitzungslokal.
Struktur-, Synchronisierungs- und Löschoperationen müssen vor der
Frontend-Umstellung ebenfalls als persistente Commands modelliert werden.
## Projektgeräte
@@ -167,7 +167,12 @@ Completed foundation:
- domain writes, audit revisions and stack transitions share one transaction;
a forced stack failure rolls all of them back
- `GET /api/projects/:projectId/history` exposes current revision, stack depths
and top change-set ids without enabling mutation endpoints
and top change-set ids
- a central application dispatcher executes the supported `circuit.update`
and `circuit-device-row.update` envelopes without coupling the domain service
to SQLite
- public command, undo and redo endpoints require an expected revision; undo
and redo reconstruct the eligible persisted inverse or forward command
Remaining constraints before completing persistent history:
@@ -176,10 +181,9 @@ Remaining constraints before completing persistent history:
command envelope is complete
- route the remaining structural, synchronization and destructive domain
writes through the shared command, revision and stack transaction boundary
- add public command execution plus undo/redo endpoints; read-only revision and
stack eligibility state is already exposed
- replace the session-local frontend command stack only after server-side
command execution and inverse application are complete
command coverage is complete for structural, destructive and synchronization
operations
- do not model IFCGUID as an overloaded circuit equipment identifier
- keep database backup/restore checks separate from project history tests
@@ -362,6 +362,8 @@ Tasks:
- define concrete serializable domain command descriptions and executors
outside React
- [x] persist undo/redo eligibility on the server
- [x] expose public command, undo and redo endpoints for the first supported
update command types
- add named and periodic logical project snapshots
- restore a historical snapshot as a new revision
- keep database backups separate from logical history
@@ -385,6 +387,9 @@ Implemented foundation:
late-failure rollback coverage
- a read-only project history endpoint exposes revision, stack depths and top
change-set ids
- a central application dispatcher reconstructs persisted commands and exposes
optimistic command, undo and redo endpoints for Circuit and CircuitDeviceRow
field updates
- revision metadata, change-set payloads and the project counter are committed
in one SQLite transaction
- a stale expected revision produces no history writes