@homeostate/tool-simulator 0.1.0 → 0.3.0
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/CHANGELOG.md +154 -0
- package/README.md +14 -3
- package/dist/compare.d.ts +0 -5
- package/dist/compare.d.ts.map +1 -1
- package/dist/compare.js +0 -13
- package/dist/compare.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lost-keys.d.ts +35 -0
- package/dist/lost-keys.d.ts.map +1 -0
- package/dist/lost-keys.js +139 -0
- package/dist/lost-keys.js.map +1 -0
- package/dist/network.d.ts +35 -5
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +47 -12
- package/dist/network.js.map +1 -1
- package/dist/randomized.d.ts +10 -4
- package/dist/randomized.d.ts.map +1 -1
- package/dist/randomized.js +27 -6
- package/dist/randomized.js.map +1 -1
- package/package.json +7 -7
- package/src/compare.ts +0 -18
- package/src/index.ts +1 -0
- package/src/lost-keys.ts +164 -0
- package/src/network.ts +83 -26
- package/src/randomized.ts +29 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,159 @@
|
|
|
1
1
|
# @homeostate/tool-simulator
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f3f22e8: `advance` and `settle` now check, after every delivery, that no peer's store and document both lose a synced top-level key that no peer deleted, and reject with a `LostKeyError` naming the peer, the key, the virtual time and the seed. `runRandomized` runs the check too, so its error names the step in which a key was lost. Before, a store that dropped a key for a while and got it back once a late update arrived still converged, so the run passed. Runs that passed before can now fail. A key deleted during a delivery, such as by a store subscriber or a timer, is reported as lost: pass `checkLostKeys: false` to `createNetwork`, or in `runRandomized`'s `network`, to turn the check off.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- e98195d: **Breaking:** a smaller sync engine API, with one way to do each thing. Migrate as follows:
|
|
12
|
+
|
|
13
|
+
- `SyncEngine` drops `isConnected()`, which returned what `getStatus()` holds. Replace
|
|
14
|
+
`engine.isConnected()` with `engine.getStatus().connected`. This also applies to the engine that
|
|
15
|
+
Zustand's and Redux's `store.homeostate`, `syncMobxStore` and `syncStateTree` return. An object
|
|
16
|
+
that implements `SyncEngine` by hand can drop the method.
|
|
17
|
+
- `SyncEvent` gains `"error"`, sent when the engine records a failure, which
|
|
18
|
+
`getStatus().failure` then holds. Work that throws, which used to send no event, now sends
|
|
19
|
+
`"error"`, before `onError` runs or the error propagates. A write loop sends it after the
|
|
20
|
+
`"remote"` of the apply that stopped it. A `switch` over `SyncEvent` must handle it.
|
|
21
|
+
- `SyncEngine` drops `subscribeStatus()`: every change of the status comes with a sync event, so
|
|
22
|
+
`subscribe` tells when to read it. Replace `engine.subscribeStatus(listener)` with
|
|
23
|
+
`engine.subscribe(() => listener())`, and read `engine.getStatus()` in it as before; it returns
|
|
24
|
+
the same object while the status is unchanged, so compare by identity to skip the events that
|
|
25
|
+
change nothing. An object that implements `SyncEngine` by hand can drop the method.
|
|
26
|
+
- `SyncEngineConfig.seed` is a boolean, `true` by default, and the `SeedStrategy` type is gone.
|
|
27
|
+
`"if-empty"` seeded each synced key the backend lacks, not only an empty backend. Replace
|
|
28
|
+
`seed: "if-empty"` with `seed: true`, or leave it out, and `seed: "never"` with `seed: false`.
|
|
29
|
+
This also applies to the options of Zustand's and Redux's `homeostate`, `syncMobxStore`,
|
|
30
|
+
`syncStateTree` and `atomWithSync`. Remove imports of `SeedStrategy`; type a variable that holds
|
|
31
|
+
the option as `boolean`. In plain JavaScript, a leftover `seed: "never"` is truthy and now
|
|
32
|
+
seeds, so replace it.
|
|
33
|
+
- The `ChangeType` object and type are removed; compare a step's `type` with its string literal.
|
|
34
|
+
Replace `ChangeType.INSERT`, `ChangeType.UPDATE` and `ChangeType.DELETE` with `"insert"`,
|
|
35
|
+
`"update"` and `"delete"`, and type a variable that holds a step type as `Change["type"]`.
|
|
36
|
+
- The `"pending"` step type is renamed `"edit"`: a step that edits the container at its key in
|
|
37
|
+
place by its nested script `changes`, as before. `getChanges` returns `"edit"` steps where it
|
|
38
|
+
returned `"pending"` ones. Replace `ChangeType.PENDING` and `"pending"` with `"edit"` wherever
|
|
39
|
+
you build a script or switch on a step's `type`; a `switch` left on `"pending"` no longer
|
|
40
|
+
matches, and TypeScript reports the comparison.
|
|
41
|
+
- `applyStringChanges`, `EditScript` and `Diffable` are no longer exported. `applyStringChanges`
|
|
42
|
+
returned the string a text script leads to, which is the second string given to `getChanges`,
|
|
43
|
+
so use that string; to edit a text in place, use `applyChanges` with `ApplyOps.editText`.
|
|
44
|
+
Replace `EditScript` with the script type of the kind diffed, `RecordChange[]`, `ListChange[]`
|
|
45
|
+
or `TextChange[]`, as `getChanges` returns it, and `Diffable` with
|
|
46
|
+
`JsonObject | unknown[] | string`; `getChanges` still needs both values narrowed to one kind.
|
|
47
|
+
- `count` is required on an array or string delete step: `ListChange` and `TextChange` declare
|
|
48
|
+
`count: number`, no longer `count?: number`. `getChanges` already set it on every such delete,
|
|
49
|
+
so only a script built by hand changes: add `count: 1` to an array or string delete that left
|
|
50
|
+
it out before passing the script to `applyChanges`. In plain JavaScript, such a delete no
|
|
51
|
+
longer removes one item, so add the `count` there too. A record delete still has no `count`.
|
|
52
|
+
- `getChanges` replaces a changed nested string whole by default, as `createCrdtBackend` and
|
|
53
|
+
`mergeConcurrent` already did: without `options.text`, a string in a record or an array that
|
|
54
|
+
changed is one `"update"` step instead of an `"edit"` step with a character-level script, and
|
|
55
|
+
so is what `applyChanges` writes. Two strings passed directly are still diffed character by
|
|
56
|
+
character. Pass `text: () => true` to keep character-level scripts for every nested string, or
|
|
57
|
+
a `TextPolicy` for some. The CRDT backends pass their `text` option, so they are unchanged.
|
|
58
|
+
- `createCrdtBackend` takes the parts as one object, `text` among them, and
|
|
59
|
+
`CrdtBackendOptions` is removed. Replace
|
|
60
|
+
`createCrdtBackend((text) => ({ read, transact, watch, revision }), { text })` with
|
|
61
|
+
`createCrdtBackend({ read, transact, watch, revision, text })`, and build the `ApplyOps` that
|
|
62
|
+
`transact` hands over from the same `text`, which is `undefined` when no string is text: core
|
|
63
|
+
no longer passes a policy with its default applied. `CrdtBackendParts` gains the optional
|
|
64
|
+
`text`. The Yjs, Loro and Automerge backends take their `text` option as before.
|
|
65
|
+
- `CrdtBackend.revision` and `CrdtBackendParts.revision` are required. A backend written by hand,
|
|
66
|
+
or parts passed to `createCrdtBackend`, must implement `revision`; return `undefined` when it
|
|
67
|
+
cannot tell, which keeps the read before every local change that a backend without `revision`
|
|
68
|
+
had. Such a backend now also gets no `previous` when the engine writes back what the store
|
|
69
|
+
changed during a remote apply, or a local change merged into one, since the engine cannot tell
|
|
70
|
+
whether the document changed during `setState`; the backend diffs against its document then.
|
|
71
|
+
The Yjs, Loro, Automerge and memory backends already implement it.
|
|
72
|
+
- `createSyncEngine` takes one options object, as the setup helpers do: the `backend`, the
|
|
73
|
+
`adapter` and the `SyncEngineConfig` options, flat. Replace
|
|
74
|
+
`createSyncEngine(backend, adapter, config)` with
|
|
75
|
+
`createSyncEngine({ backend, adapter, ...config })`, or list the options inline, such as
|
|
76
|
+
`createSyncEngine({ backend, adapter, omit: ["draft"] })`, and
|
|
77
|
+
`createSyncEngine(backend, adapter)` with `createSyncEngine({ backend, adapter })`. The state
|
|
78
|
+
type is still taken from `adapter`. The new `SyncEngineOptions<S>` type names the object. The
|
|
79
|
+
setup helpers' options are unchanged.
|
|
80
|
+
- `filter` takes the key alone, `(key: keyof S & string) => boolean`, and a key the store holds as
|
|
81
|
+
a function is never synced, whatever `filter` returns: the engine neither writes it nor reads the
|
|
82
|
+
backend's value into it. A store that makes a synced key a function deletes it from the backend
|
|
83
|
+
with its next write, as before, and syncs it again once it holds a JSON value. A backend value is
|
|
84
|
+
no longer judged: a synced key always takes it. `defaultSyncFilter` is removed. Drop
|
|
85
|
+
`filter: defaultSyncFilter`; replace `(key, value) => defaultSyncFilter(key, value) && key !==
|
|
86
|
+
"draft"` with `(key) => key !== "draft"`, or with `omit: ["draft"]`; elsewhere, replace
|
|
87
|
+
`defaultSyncFilter(key, value)` with `typeof value !== "function"`. A custom filter no longer
|
|
88
|
+
syncs functions it keeps, so it need not exclude them. A rule on any other value has no
|
|
89
|
+
replacement: choose the keys by name, or sync a slice without them with `scopeAdapter`. A filter
|
|
90
|
+
that takes a second parameter fails to compile; in plain JavaScript, it gets `undefined` there.
|
|
91
|
+
|
|
92
|
+
- 1bfdf95: `runRandomized` no longer reports peers that converge as diverged when updates written after
|
|
93
|
+
its final heal are dropped. With a `dropRate`, a store that writes in answer to remote changes,
|
|
94
|
+
such as a subscriber that keeps a derived key in synced state, writes new updates as the
|
|
95
|
+
documents `heal()` exchanges arrive, and the network can drop those too. The run healed once,
|
|
96
|
+
so a dropped update stayed lost and the run failed with a `ConvergenceError`. It now heals and
|
|
97
|
+
settles again until a round drops nothing, at most 10 rounds, as a provider that resyncs would.
|
|
98
|
+
The steps make the same random choices, so a seed replays the same steps. When the tenth round
|
|
99
|
+
still dropped updates and the peers did not converge, the error says so. `expectConverged()`
|
|
100
|
+
now also says how many updates were dropped since the last `heal()`, so tests that heal by hand
|
|
101
|
+
get the same hint: repeat `heal()` and `settle()` until `stats().dropped` stops growing.
|
|
102
|
+
- Updated dependencies [e98195d]
|
|
103
|
+
- Updated dependencies [e4e66f6]
|
|
104
|
+
- Updated dependencies [d17efad]
|
|
105
|
+
- Updated dependencies [7172cf4]
|
|
106
|
+
- Updated dependencies [3edede4]
|
|
107
|
+
- Updated dependencies [ea86a91]
|
|
108
|
+
- Updated dependencies [b2c1521]
|
|
109
|
+
- Updated dependencies [038c0e1]
|
|
110
|
+
- Updated dependencies [988dec0]
|
|
111
|
+
- Updated dependencies [48b0532]
|
|
112
|
+
- Updated dependencies [bf8324b]
|
|
113
|
+
- Updated dependencies [e97b920]
|
|
114
|
+
- Updated dependencies [2756e79]
|
|
115
|
+
- Updated dependencies [44a47f2]
|
|
116
|
+
- Updated dependencies [fab156f]
|
|
117
|
+
- Updated dependencies [e51dad7]
|
|
118
|
+
- Updated dependencies [1a6cfb8]
|
|
119
|
+
- Updated dependencies [4008d1e]
|
|
120
|
+
- Updated dependencies [76ec475]
|
|
121
|
+
- Updated dependencies [106f2a4]
|
|
122
|
+
- Updated dependencies [b296a2f]
|
|
123
|
+
- Updated dependencies [987d676]
|
|
124
|
+
- Updated dependencies [3e8a239]
|
|
125
|
+
- @homeostate/core@0.5.0
|
|
126
|
+
|
|
127
|
+
## 0.2.0
|
|
128
|
+
|
|
129
|
+
### Minor Changes
|
|
130
|
+
|
|
131
|
+
- 7e7171a: `PeerSetup.config` is typed by the adapter's state, `SyncEngineConfig<S>`, so a peer can take the
|
|
132
|
+
engine's `keys` and `omit` with checked key names. Like `filter`, they also decide what
|
|
133
|
+
convergence compares.
|
|
134
|
+
|
|
135
|
+
### Patch Changes
|
|
136
|
+
|
|
137
|
+
- cde0b51: A peer's `syncedState()` reads the engine's `getSyncedState()` instead of applying the filter
|
|
138
|
+
again, so convergence compares exactly what the engine syncs.
|
|
139
|
+
- Updated dependencies [39809d7]
|
|
140
|
+
- Updated dependencies [a80be3b]
|
|
141
|
+
- Updated dependencies [60331b4]
|
|
142
|
+
- Updated dependencies [567932b]
|
|
143
|
+
- Updated dependencies [55812ce]
|
|
144
|
+
- Updated dependencies [d2a66d8]
|
|
145
|
+
- Updated dependencies [8ed9541]
|
|
146
|
+
- Updated dependencies [ceca144]
|
|
147
|
+
- Updated dependencies [3bdd635]
|
|
148
|
+
- Updated dependencies [9a6e0c6]
|
|
149
|
+
- Updated dependencies [aa7cbc1]
|
|
150
|
+
- Updated dependencies [3b9d6dc]
|
|
151
|
+
- Updated dependencies [9ce5ff0]
|
|
152
|
+
- Updated dependencies [cde0b51]
|
|
153
|
+
- Updated dependencies [074eadc]
|
|
154
|
+
- Updated dependencies [7e7171a]
|
|
155
|
+
- @homeostate/core@0.4.0
|
|
156
|
+
|
|
3
157
|
## 0.1.0
|
|
4
158
|
|
|
5
159
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# @homeostate/tool-simulator
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@homeostate/tool-simulator)
|
|
4
|
+
[](https://bundlejs.com/?q=%40homeostate%2Ftool-simulator&config=%7B%22esbuild%22%3A%7B%22external%22%3A%5B%22%40homeostate%2Fcore%22%5D%7D%7D)
|
|
5
|
+
[](https://www.npmjs.com/package/@homeostate/tool-simulator)
|
|
6
|
+
[](https://github.com/mixedrays/homeostate/blob/main/packages/tool-simulator/LICENSE)
|
|
7
|
+
|
|
3
8
|
Test that peers synced by [`@homeostate/core`](https://github.com/mixedrays/homeostate/tree/main/packages/core)
|
|
4
9
|
converge. It runs several peers, each a store, a backend and a sync engine, on a simulated
|
|
5
10
|
network with latency, dropped and reordered messages and partitions, on virtual time, and
|
|
@@ -47,10 +52,16 @@ network.expectConverged();
|
|
|
47
52
|
|
|
48
53
|
Each peer's `doc` is its backend's document as binary updates, from the CRDT package's
|
|
49
54
|
`create*Persistable`: that is what the network carries. `settle()` delivers every message on
|
|
50
|
-
its way, and
|
|
55
|
+
its way, and rejects if a peer's store and document both lose a synced key that no peer
|
|
56
|
+
deleted. `expectConverged()` throws unless every peer's store and document agree.
|
|
57
|
+
|
|
58
|
+
With a `dropRate`, the updates stores write in answer to the exchange `heal()` starts, such as a
|
|
59
|
+
key derived from synced state, can be dropped too. Repeat `heal()` and `settle()` until
|
|
60
|
+
`stats().dropped` stops growing before you check convergence.
|
|
51
61
|
|
|
52
|
-
`runRandomized` drives random edits, link cuts and reconnections across a fresh network,
|
|
53
|
-
|
|
62
|
+
`runRandomized` drives random edits, link cuts and reconnections across a fresh network, checks
|
|
63
|
+
after every delivery that no peer's store loses a synced key, then heals and settles until
|
|
64
|
+
nothing more is dropped and checks convergence, and names the seed of a run that fails:
|
|
54
65
|
|
|
55
66
|
```ts
|
|
56
67
|
await runRandomized({
|
package/dist/compare.d.ts
CHANGED
|
@@ -8,11 +8,6 @@ export interface Difference {
|
|
|
8
8
|
}
|
|
9
9
|
/** `value` as JSON stores it: functions and `undefined` dropped, a Date as a string. */
|
|
10
10
|
export declare const asJson: (value: unknown) => unknown;
|
|
11
|
-
/**
|
|
12
|
-
* The keys of a store's state the engine syncs, as JSON: the keys `filter` keeps, without
|
|
13
|
-
* `__proto__`, which the engine never syncs.
|
|
14
|
-
*/
|
|
15
|
-
export declare const syncedJson: (state: unknown, filter?: (key: string, value: unknown) => boolean) => unknown;
|
|
16
11
|
/** The first place where two JSON values differ, or `null` when they are equal. */
|
|
17
12
|
export declare const firstDifference: (left: unknown, right: unknown, path?: Path) => Difference | null;
|
|
18
13
|
/** `todos[0].title`, the way a path reads in code. */
|
package/dist/compare.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAEvC,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CAChB;AAUD,wFAAwF;AACxF,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,KAAG,OACgB,CAAC;AAEzD,mFAAmF;AACnF,eAAO,MAAM,eAAe,GAC1B,MAAM,OAAO,EACb,OAAO,OAAO,EACd,OAAM,IAAS,KACd,UAAU,GAAG,IAgCf,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,MAQvC,CAAC;AAIF,iEAAiE;AACjE,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,MAI5C,CAAC"}
|
package/dist/compare.js
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import { defaultSyncFilter } from "@homeostate/core";
|
|
2
1
|
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3
2
|
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
4
3
|
/** `value` as JSON stores it: functions and `undefined` dropped, a Date as a string. */
|
|
5
4
|
export const asJson = (value) => JSON.parse(JSON.stringify(value) ?? "null");
|
|
6
|
-
/**
|
|
7
|
-
* The keys of a store's state the engine syncs, as JSON: the keys `filter` keeps, without
|
|
8
|
-
* `__proto__`, which the engine never syncs.
|
|
9
|
-
*/
|
|
10
|
-
export const syncedJson = (state, filter = defaultSyncFilter) => {
|
|
11
|
-
const synced = {};
|
|
12
|
-
if (isRecord(state))
|
|
13
|
-
for (const key of Object.keys(state))
|
|
14
|
-
if (key !== "__proto__" && filter(key, state[key]))
|
|
15
|
-
synced[key] = state[key];
|
|
16
|
-
return asJson(synced);
|
|
17
|
-
};
|
|
18
5
|
/** The first place where two JSON values differ, or `null` when they are equal. */
|
|
19
6
|
export const firstDifference = (left, right, path = []) => {
|
|
20
7
|
if (Object.is(left, right))
|
package/dist/compare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAYA,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAkB,EAAE,CAClD,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,GAAW,EAAW,EAAE,CACtD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C,IAAI,EAAE,GAAG,EAAE,EAAE;QACvC,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,IAAI,IAAI,GAAG,GAAG,CAAC;QACtD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC;YACjC,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;QAC3C,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;IAC9C,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,iEAAiE;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAU,EAAE;IACpD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { ConvergenceError, createNetwork } from "./network.js";
|
|
2
|
+
export { LostKeyError } from "./lost-keys.js";
|
|
2
3
|
export type { Network, NetworkOptions, NetworkStats, Peer, PeerSetup, } from "./network.js";
|
|
3
4
|
export { randomEdit, runRandomized } from "./randomized.js";
|
|
4
5
|
export type { RandomAction, RandomizedOptions } from "./randomized.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,YAAY,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQ9C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Peer } from "./network.js";
|
|
2
|
+
/** Thrown by `advance` and `settle` when a peer lost a synced key; see `checkLostKeys`. */
|
|
3
|
+
export declare class LostKeyError extends Error {
|
|
4
|
+
readonly seed: number;
|
|
5
|
+
/** The peer's name. */
|
|
6
|
+
readonly peer: string;
|
|
7
|
+
readonly key: string;
|
|
8
|
+
/** Virtual time of the checkpoint that found the loss, in milliseconds. */
|
|
9
|
+
readonly at: number;
|
|
10
|
+
constructor(message: string, details: {
|
|
11
|
+
seed: number;
|
|
12
|
+
peer: string;
|
|
13
|
+
key: string;
|
|
14
|
+
at: number;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks that no peer's store and document both lose a synced top-level key that no peer
|
|
19
|
+
* deleted. The network calls it as its documents change and around its deliveries.
|
|
20
|
+
*/
|
|
21
|
+
export interface LostKeyCheck {
|
|
22
|
+
/** Start tracking a peer, before it links and connects. */
|
|
23
|
+
addPeer: (peer: Peer) => void;
|
|
24
|
+
/** The peer's document changed; `outside` when no delivery is running. */
|
|
25
|
+
changed: (peer: Peer, outside: boolean) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Before deliveries: what changed since the last checkpoint was done by the test, so a key
|
|
28
|
+
* that left a store or document is deleted.
|
|
29
|
+
*/
|
|
30
|
+
beforeDeliveries: (peers: readonly Peer[]) => void;
|
|
31
|
+
/** After a delivery to `peer` from `from`, or after the last one; throws a `LostKeyError`. */
|
|
32
|
+
afterDelivery: (peer: Peer, at: number, from?: Peer) => void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createLostKeyCheck(seed: number): LostKeyCheck;
|
|
35
|
+
//# sourceMappingURL=lost-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lost-keys.d.ts","sourceRoot":"","sources":["../src/lost-keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,2FAA2F;AAC3F,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAGlB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE;CASnE;AAgBD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9B,0EAA0E;IAC1E,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD;;;OAGG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,KAAK,IAAI,CAAC;IACnD,8FAA8F;IAC9F,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,IAAI,CAAC;CAC9D;AAiBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CA2F7D"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { formatPath } from "./compare.js";
|
|
2
|
+
/** Thrown by `advance` and `settle` when a peer lost a synced key; see `checkLostKeys`. */
|
|
3
|
+
export class LostKeyError extends Error {
|
|
4
|
+
constructor(message, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
Object.defineProperty(this, "seed", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
/** The peer's name. */
|
|
13
|
+
Object.defineProperty(this, "peer", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "key", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
/** Virtual time of the checkpoint that found the loss, in milliseconds. */
|
|
26
|
+
Object.defineProperty(this, "at", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
this.name = "LostKeyError";
|
|
33
|
+
this.seed = details.seed;
|
|
34
|
+
this.peer = details.peer;
|
|
35
|
+
this.key = details.key;
|
|
36
|
+
this.at = details.at;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The keys of `state` that JSON keeps, as `peer.syncedState()` has them. */
|
|
40
|
+
const jsonKeys = (state) => {
|
|
41
|
+
const keys = new Set();
|
|
42
|
+
for (const [key, value] of Object.entries(state))
|
|
43
|
+
if (value !== undefined &&
|
|
44
|
+
typeof value !== "function" &&
|
|
45
|
+
typeof value !== "symbol")
|
|
46
|
+
keys.add(key);
|
|
47
|
+
return keys;
|
|
48
|
+
};
|
|
49
|
+
const formatTime = (ms) => String(Number(ms.toFixed(2)));
|
|
50
|
+
export function createLostKeyCheck(seed) {
|
|
51
|
+
const tracked = new Map();
|
|
52
|
+
/** Keys a checkpoint outside a delivery saw leave a store or document; never cleared. */
|
|
53
|
+
const deleted = new Set();
|
|
54
|
+
const storeKeys = (peer) => jsonKeys(peer.engine.getSyncedState());
|
|
55
|
+
const docKeys = (peer, state) => {
|
|
56
|
+
if (!state.doc) {
|
|
57
|
+
state.doc = jsonKeys(peer.backend.read());
|
|
58
|
+
// Only the test's own changes delete; a delivery that removes a key may be a loss.
|
|
59
|
+
if (state.changedOutside && state.lastDoc)
|
|
60
|
+
for (const key of state.lastDoc)
|
|
61
|
+
if (!state.doc.has(key))
|
|
62
|
+
deleted.add(key);
|
|
63
|
+
state.lastDoc = state.doc;
|
|
64
|
+
state.changedOutside = false;
|
|
65
|
+
}
|
|
66
|
+
return state.doc;
|
|
67
|
+
};
|
|
68
|
+
/** Mark the keys that left the store since its last checkpoint as deleted. */
|
|
69
|
+
const noteRemovals = (state, store) => {
|
|
70
|
+
for (const key of state.store)
|
|
71
|
+
if (!store.has(key))
|
|
72
|
+
deleted.add(key);
|
|
73
|
+
state.store = store;
|
|
74
|
+
};
|
|
75
|
+
const hold = (peer, state, keys) => {
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
if (state.held.has(key) || deleted.has(key))
|
|
78
|
+
continue;
|
|
79
|
+
if (docKeys(peer, state).has(key))
|
|
80
|
+
state.held.add(key);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const track = (peer) => {
|
|
84
|
+
const state = tracked.get(peer);
|
|
85
|
+
if (!state)
|
|
86
|
+
throw new Error(`${peer.name} is not on the network.`);
|
|
87
|
+
return state;
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
addPeer: (peer) => {
|
|
91
|
+
tracked.set(peer, {
|
|
92
|
+
store: storeKeys(peer),
|
|
93
|
+
doc: undefined,
|
|
94
|
+
lastDoc: undefined,
|
|
95
|
+
changedOutside: false,
|
|
96
|
+
held: new Set(),
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
changed: (peer, outside) => {
|
|
100
|
+
const state = track(peer);
|
|
101
|
+
state.doc = undefined;
|
|
102
|
+
if (!outside)
|
|
103
|
+
return;
|
|
104
|
+
state.changedOutside = true;
|
|
105
|
+
// A key added and removed again before the next delivery still counts as deleted.
|
|
106
|
+
noteRemovals(state, storeKeys(peer));
|
|
107
|
+
},
|
|
108
|
+
beforeDeliveries: (peers) => {
|
|
109
|
+
for (const peer of peers) {
|
|
110
|
+
const state = track(peer);
|
|
111
|
+
const store = storeKeys(peer);
|
|
112
|
+
noteRemovals(state, store);
|
|
113
|
+
if (state.changedOutside)
|
|
114
|
+
docKeys(peer, state);
|
|
115
|
+
hold(peer, state, store);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
afterDelivery: (peer, at, from) => {
|
|
119
|
+
const state = track(peer);
|
|
120
|
+
const store = storeKeys(peer);
|
|
121
|
+
for (const key of state.held) {
|
|
122
|
+
if (store.has(key))
|
|
123
|
+
continue;
|
|
124
|
+
if (deleted.has(key)) {
|
|
125
|
+
state.held.delete(key);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (docKeys(peer, state).has(key))
|
|
129
|
+
continue;
|
|
130
|
+
const source = from ? `, on an update from ${from.name}` : "";
|
|
131
|
+
throw new LostKeyError(`${peer.name} lost the synced key ${formatPath([key])} at ${formatTime(at)} ms (seed ${seed})${source}: its store and document both lack it, and no peer deleted it.`, { seed, peer: peer.name, key, at });
|
|
132
|
+
}
|
|
133
|
+
const appeared = [...store].filter((key) => !state.store.has(key));
|
|
134
|
+
state.store = store;
|
|
135
|
+
hold(peer, state, appeared);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=lost-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lost-keys.js","sourceRoot":"","sources":["../src/lost-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,2FAA2F;AAC3F,MAAM,OAAO,YAAa,SAAQ,KAAK;IAQrC,YACE,OAAe,EACf,OA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AAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/network.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ export interface PeerSetup<S extends object = any> {
|
|
|
8
8
|
adapter: StoreAdapter<S>;
|
|
9
9
|
backend: CrdtBackend;
|
|
10
10
|
doc: PersistableDoc;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Passed to `createSyncEngine`, typed by the adapter's state; its `filter`, `keys` and `omit`
|
|
13
|
+
* also decide what convergence compares.
|
|
14
|
+
*/
|
|
15
|
+
config?: NoInfer<SyncEngineConfig<S>>;
|
|
13
16
|
/** Names the peer in convergence errors. Defaults to `peer-<index>`. */
|
|
14
17
|
name?: string;
|
|
15
18
|
/**
|
|
@@ -51,6 +54,17 @@ export interface NetworkOptions {
|
|
|
51
54
|
* as two peers writing in a loop. Defaults to 100 000.
|
|
52
55
|
*/
|
|
53
56
|
maxDeliveries?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Whether `advance` and `settle` reject with a `LostKeyError` when a peer's store and
|
|
59
|
+
* document both lose a synced top-level key that no peer deleted. Defaults to `true`.
|
|
60
|
+
*
|
|
61
|
+
* A peer holds a key once a checkpoint sees it in both its store's synced state and its
|
|
62
|
+
* document. A key is deleted for good once it leaves a store or document outside a delivery:
|
|
63
|
+
* in a step, or in a test's own change, between `advance` and `settle` calls. Checkpoints
|
|
64
|
+
* come after each delivery and when `advance` or `settle` returns. A key deleted during a
|
|
65
|
+
* delivery, such as by a store subscriber or a timer, is reported as lost: pass `false`.
|
|
66
|
+
*/
|
|
67
|
+
checkLostKeys?: boolean;
|
|
54
68
|
}
|
|
55
69
|
export interface NetworkStats {
|
|
56
70
|
/** Messages handed to the network, updates and the documents exchanged on connecting. */
|
|
@@ -68,6 +82,9 @@ export interface NetworkStats {
|
|
|
68
82
|
* document goes to every peer it is linked to, after the latency, unless it is dropped or its
|
|
69
83
|
* link is cut first. Linking two peers, as `connect` and `heal` do, makes them exchange their
|
|
70
84
|
* whole documents, as providers do on reconnecting, so what was lost on the way arrives.
|
|
85
|
+
*
|
|
86
|
+
* Unless `checkLostKeys` is `false`, `advance` and `settle` also check after each delivery
|
|
87
|
+
* that no peer's store and document both lost a synced key that no peer deleted.
|
|
71
88
|
*/
|
|
72
89
|
export interface Network {
|
|
73
90
|
/** The seed of this network's random choices. */
|
|
@@ -97,11 +114,21 @@ export interface Network {
|
|
|
97
114
|
/**
|
|
98
115
|
* Link every pair of peers and have each exchange documents, as if every peer reconnected,
|
|
99
116
|
* so that updates lost to drops and cut links arrive too.
|
|
117
|
+
*
|
|
118
|
+
* With a `dropRate`, the updates stores write in answer to that exchange, such as a key one
|
|
119
|
+
* derives from synced state, can be dropped too. Repeat `heal()` and `settle()` until
|
|
120
|
+
* `stats().dropped` stops growing before checking convergence.
|
|
100
121
|
*/
|
|
101
122
|
heal: () => void;
|
|
102
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Deliver the messages due within the next `ms` of virtual time, and move time on. Rejects
|
|
125
|
+
* with a `LostKeyError` when a peer lost a synced key; see `checkLostKeys`.
|
|
126
|
+
*/
|
|
103
127
|
advance: (ms: number) => Promise<void>;
|
|
104
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Deliver every message on its way, and those they lead to, until none are left. Rejects
|
|
130
|
+
* with a `LostKeyError` when a peer lost a synced key; see `checkLostKeys`.
|
|
131
|
+
*/
|
|
105
132
|
settle: () => Promise<void>;
|
|
106
133
|
stats: () => NetworkStats;
|
|
107
134
|
/**
|
|
@@ -110,7 +137,10 @@ export interface Network {
|
|
|
110
137
|
* document. Empty once the peers have converged.
|
|
111
138
|
*/
|
|
112
139
|
differences: () => string[];
|
|
113
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Throws a `ConvergenceError` unless `differences()` is empty. Its message also says how many
|
|
142
|
+
* messages are still on their way, and how many updates were dropped since the last `heal()`.
|
|
143
|
+
*/
|
|
114
144
|
expectConverged: () => void;
|
|
115
145
|
/** Disconnect every engine, stop listening to every document and drop what is on its way. */
|
|
116
146
|
destroy: () => void;
|
package/dist/network.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,gBAAgB,EAEtB,MAAM,kBAAkB,CAAC;AAK1B;;;;GAIG;AAGH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG;IAC/C,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,kGAAkG;AAElG,MAAM,WAAW,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG;IAC1C,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,wCAAwC;IACxC,WAAW,EAAE,MAAM,OAA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