anbaric-tsapi 1.0.0 → 1.0.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.
- package/README.md +67 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# anbaric-tsapi
|
|
2
|
+
|
|
3
|
+
The contracts and value classes shared by every Anbaric package. Nothing
|
|
4
|
+
here depends on any other Anbaric package. App developers usually install
|
|
5
|
+
[`anbaric`](https://npmjs.com/package/anbaric) instead, which re-exports all
|
|
6
|
+
of this.
|
|
7
|
+
|
|
8
|
+
Interfaces whose implementations may cross a process boundary are async:
|
|
9
|
+
their methods return `Promise` even when an implementation is trivially
|
|
10
|
+
synchronous.
|
|
11
|
+
|
|
12
|
+
## Value classes
|
|
13
|
+
|
|
14
|
+
**`Job`** — a unit of work moving through a workflow.
|
|
15
|
+
`new Job(id, properties = new Map(), initialState, workflowId?, startedBy = "system", startedAt = new Date(), lastUpdated = startedAt, transitions = [])`.
|
|
16
|
+
`stateId` is a getter; state only changes through
|
|
17
|
+
`transition(transition, actor = workflowId ?? "state-machine")`, which
|
|
18
|
+
records `{from, to, actor}` into `transitions` and bumps `lastUpdated` when
|
|
19
|
+
the transition's predicate accepts the job.
|
|
20
|
+
|
|
21
|
+
**`State`** — `new State(id, actions = [], transitions = [])`, plus
|
|
22
|
+
`subscribe(action)` to add an action later.
|
|
23
|
+
|
|
24
|
+
**`Action`** — `new Action(name, actor, description = "", id = crypto.randomUUID())`.
|
|
25
|
+
Two replaceable function fields: `predicate : (job) => boolean` (defaults to
|
|
26
|
+
accept) gates whether the action runs, and
|
|
27
|
+
`run : (job) => Promise<Map<string, any>>` (defaults to an empty map)
|
|
28
|
+
returns the property changes the action wants. `run` never mutates the job.
|
|
29
|
+
|
|
30
|
+
**`Actor`** — an interface, pure identity: `{ type : "HUMAN" | "CODE" | "AGENT", id : string, role : string }`.
|
|
31
|
+
Concrete `Human`, `Code`, `Agent` classes live in `anbaric-state-machine`.
|
|
32
|
+
|
|
33
|
+
**`Transition`** — `new Transition(to, predicate)`; the first accepting
|
|
34
|
+
transition in a state wins.
|
|
35
|
+
|
|
36
|
+
**`PropertyDefinition`** — `new PropertyDefinition(id)` with mutable
|
|
37
|
+
`required : boolean` (default false) and `validation : (value) => boolean`
|
|
38
|
+
(default accept).
|
|
39
|
+
|
|
40
|
+
**`JobTransition`** — `{ from : string, to : string, actor : string }`.
|
|
41
|
+
|
|
42
|
+
**Serialization** — `serializeJob(job) : SerializedJob` and
|
|
43
|
+
`deserializeJob(serialized) : Job` define the wire shape used by the cloud
|
|
44
|
+
clients and platform (dates as ISO strings, properties as a plain object).
|
|
45
|
+
|
|
46
|
+
## Contracts
|
|
47
|
+
|
|
48
|
+
**`JobPersistence`** — `save(job)`, `retrieve(id)` (throws
|
|
49
|
+
`No job found with id "x"`), `delete(id)`, `list(pageSize = 100, page = 0)`,
|
|
50
|
+
`updateProperties(id, properties)` (merge; implementations stamp
|
|
51
|
+
`lastUpdated`).
|
|
52
|
+
|
|
53
|
+
**`Queue`** — `enqueue(jobId, workflowId)`, `schedule(jobId, workflowId, due)`.
|
|
54
|
+
**`Dequeue extends Queue`** adds `dequeueSome() : Promise<Array<QueueMessage>>`;
|
|
55
|
+
the exported `Dequeue.supports(queue)` type guard tests for it structurally.
|
|
56
|
+
Delivery is at-least-once: consumers must tolerate redelivery.
|
|
57
|
+
|
|
58
|
+
**`Consumer`** — `subscribe(workflowId, processJob)` routes deliveries for
|
|
59
|
+
one workflow to a callback; `cleanUp()` releases resources.
|
|
60
|
+
|
|
61
|
+
**`JsonStore`** — `save(id, document)`, `retrieve(id)`, `delete(id)`,
|
|
62
|
+
`list()`; implementations validate against a `JsonSchema` when one is given.
|
|
63
|
+
|
|
64
|
+
**`SecretStore`** — `save(name, value)`, `retrieve(name)`, `list()`.
|
|
65
|
+
|
|
66
|
+
**`QueueMessage`** — `{ jobId, workflowId }`; part of the platform's private
|
|
67
|
+
wire protocol (in `api/cloud/`), exported because `Dequeue` returns it.
|
package/package.json
CHANGED