mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(chord): add JSON delta tracking
This commit is contained in:
parent
9e1aa8b445
commit
f7079d5628
5 changed files with 2155 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
1080
packages/chord/src/delta/index.ts
Normal file
1080
packages/chord/src/delta/index.ts
Normal file
File diff suppressed because it is too large
Load diff
1045
packages/chord/test/delta.test.ts
Normal file
1045
packages/chord/test/delta.test.ts
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue