@sewdn/workflow-engine
v0.1.1
Published
A workflow engine core: a pure, deterministic command core over definitions, versions and instances. No UI, no storage, no clock of its own.
Readme
@sewdn/workflow-engine
The workflow engine core: the runtime model of definitions, versions and runs, as a pure, deterministic TypeScript package.
- Event-sourced. A command decides and does not mutate:
decide(world, command, env)gives its events or a refusal, and the world after it isevolve(world, events), the fold. The typed command functions (startRun(world, ctx, actor, input), …) are that pair in one call, returning{ ok, world, value, events }. Seesrc/events/README.md. - Pure. No clock, no randomness, no I/O: the instant, the actor, the rights and the directory answers come in the
env (
Ctxfor the command functions); ids are a function of the state. Every world handed out is deep-frozen; the states share their unchanged parts. - Projections. A run's history in words is a projection of its events (
src/projections/run-log.ts, worded by the history catalogs insrc/copy/); the other read models read the folded state and that log. - Streams. Snapshots (the state at a sequence) and rollback (an event of the stream) are in
src/events/stream.ts; idempotency keys are the caller's command log, not state.
Layout
| File | What |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| src/model.ts | Definitions, versions, instances, tokens, passes, executions, tasks, document versions, the world |
| src/context.ts | Ctx, the capabilities and the stock rights (rightsCan), refusals |
| src/roles.ts | the role map: who a seat, a fill or a rule names on a run (seatHolders, holdsRule, responsibleOf, canOn) |
| src/profile.ts | The one validator: Ajv 2020 under the workflow profile, the WF-D314 error filter, node data schemas |
| src/analyze.ts | Region paths, retour kinds and publish validation (04 §7.2) |
| src/conditions.ts | Three-valued evaluation with sources, the guarded schema leaf, staleness |
| src/runtime.ts | Tokens, splits, joins, the post-command fixpoint |
| src/commands.ts | Instance, task, recovery and notification commands; run, the wrapper every command goes through |
| src/decide.ts | decide, DecideEnv, ENGINE_COMMANDS: the pure decision of any command by name |
| src/events/ | The events, the live view a command reads through, the fold (evolve), the stream (snapshots, rollback); see its README |
| src/projections/ | run-log.ts: a run's log as a projection of its events |
| src/definition-content.ts | placeSchema, removeSchema (refused with the edit finding schema-in-use), placeSeat: an application's data types and seats on a definition's content |
| src/authoring.ts | Drafts, import, publish (JCS + SHA-256), retire, diffVersions |
| src/migration.ts | Plans, proefdraai, apply, the herstelstap fallback |
| src/projections.ts | lifecycle, whyBlocked, opTeVolgen, fieldView, history |
| src/invariants.ts | The 04 §3.6/§11 invariants and the append-only check |
| src/testing/sample-definitions.ts | The sample routes (routeversie 1–3 of the Spec route, Rechtstreeks Committee) and their builders, as data; exported as part of @sewdn/workflow-engine/testing |
| src/testing/ | Fixtures (the sample routes and personas), the scenario harness and the model-based generator; exported as @sewdn/workflow-engine/testing |
| src/scenarios/ | One file per <engine>/scenarios/… proof of the acceptance map (11), each test named with its row ID |
Gates
bun run typecheck
bun run lint
bun run test # scenarios + 600 model seeds
ENGINE_BASE=100000 ENGINE_SEEDS=20000 bun test src/model.test.ts # a sweep; stats in $TMPDIR/workflow-engine-model-stats.jsonA failing model seed is shrunk and printed with its trace. Replay it with ENGINE_BASE=<seed> ENGINE_SEEDS=1.
