feat(chord): add JSON delta tracking

This commit is contained in:
Mario Zechner 2026-08-31 02:04:17 +02:00
parent 9e1aa8b445
commit f7079d5628
5 changed files with 2155 additions and 1 deletions

View file

@ -404,7 +404,7 @@ Explicit non-goals:
- automatic unchanged-value suppression; and
- high-frequency stream transport.
A later delta primitive requires a concrete feature and a separate snapshot/delta/gap-recovery design.
Chord now exposes a standalone intent-preserving JSON delta primitive for durable output and other explicit consumers. Replicated service state still uses complete snapshots and ordered latest-value updates; adopting deltas there requires a separate snapshot/delta/gap-recovery design.
## 9. Symmetric RPC plumbing

View file

@ -36,6 +36,10 @@ The design has a few connected pieces:
ordered updates, and become unready on disconnect or replacement until they
are rehydrated.
- **Delta tracking** records mutations to plain JSON as compact operations. It
preserves append, front-truncation, and array-splice intent, supports durable
base batches, and validates untrusted operations before applying them.
- **Remote service sources** advertise services available outside a facet host
and open bindings for the services its facets require. Bindings carry logical
calls and subscriptions through an application-supplied adapter. Chord
@ -57,6 +61,26 @@ the root API.
Chord-owned identifiers use the `chord.*` namespace and its reserved service
prefix is `$chord.*`.
## Tracking JSON deltas
Import the standalone delta primitive from `@earendil-works/chord/delta`:
```ts
import { apply, track } from "@earendil-works/chord/delta";
const changes = track({ output: "", count: 0 });
changes.flush(); // opening base batch
changes.state.output += "done\n";
changes.state.count += 1;
const ops = changes.flush();
const replica = apply({ output: "", count: 0 }, ops);
```
The first flush is always a complete base batch. Later flushes contain path-based
changes. String assignments preserve pure appends and rolling-window movement as
append and front-truncate operations; unrelated rewrites fall back to a set.
## Bundling and loading facets
`@earendil-works/chord/bundler` uses esbuild to turn ESM or TypeScript application

View file

@ -16,6 +16,11 @@
"types": "./dist/context/index.d.ts",
"import": "./dist/context/index.js"
},
"./delta": {
"source": "./src/delta/index.ts",
"types": "./dist/delta/index.d.ts",
"import": "./dist/delta/index.js"
},
"./bundler": {
"source": "./src/bundler.ts",
"types": "./dist/bundler.d.ts",

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff