@yaks/sync 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +729 -2
- package/_dist/coverage.d.ts +7 -0
- package/_dist/coverage.d.ts.map +1 -0
- package/_dist/inbound.d.ts +43 -0
- package/_dist/inbound.d.ts.map +1 -0
- package/_dist/mark.d.ts +29 -0
- package/_dist/mark.d.ts.map +1 -0
- package/_dist/mod.d.ts +78 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/outbound.d.ts +55 -0
- package/_dist/outbound.d.ts.map +1 -0
- package/_dist/outbox.d.ts +48 -0
- package/_dist/outbox.d.ts.map +1 -0
- package/_dist/pace.d.ts +9 -0
- package/_dist/pace.d.ts.map +1 -0
- package/_dist/port.d.ts +31 -0
- package/_dist/port.d.ts.map +1 -0
- package/_dist/revision.d.ts +60 -0
- package/_dist/revision.d.ts.map +1 -0
- package/_dist/saying.d.ts +12 -0
- package/_dist/saying.d.ts.map +1 -0
- package/_dist/socket.d.ts +151 -0
- package/_dist/socket.d.ts.map +1 -0
- package/_dist/sync.d.ts +97 -0
- package/_dist/sync.d.ts.map +1 -0
- package/_dist/tier.d.ts +62 -0
- package/_dist/tier.d.ts.map +1 -0
- package/clock.js +43 -0
- package/clock.js.map +1 -0
- package/clock.ts +56 -0
- package/coverage.js +13 -0
- package/coverage.js.map +1 -0
- package/coverage.ts +26 -0
- package/deno.json +1 -0
- package/inbound.js +217 -0
- package/inbound.js.map +1 -0
- package/inbound.ts +251 -0
- package/mark.js +87 -0
- package/mark.js.map +1 -0
- package/mark.ts +108 -0
- package/mod.js +78 -0
- package/mod.js.map +1 -0
- package/mod.ts +153 -0
- package/outbound.js +170 -0
- package/outbound.js.map +1 -0
- package/outbound.ts +221 -0
- package/outbox.js +281 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +343 -0
- package/pace.js +96 -0
- package/pace.js.map +1 -0
- package/pace.ts +91 -0
- package/package.json +32 -4
- package/port.js +128 -0
- package/port.js.map +1 -0
- package/port.ts +176 -0
- package/rebase.js +93 -0
- package/rebase.js.map +1 -0
- package/rebase.ts +77 -0
- package/revision.js +104 -0
- package/revision.js.map +1 -0
- package/revision.ts +146 -0
- package/saying.js +62 -0
- package/saying.js.map +1 -0
- package/saying.ts +69 -0
- package/socket.js +694 -0
- package/socket.js.map +1 -0
- package/socket.ts +927 -0
- package/sync.js +542 -0
- package/sync.js.map +1 -0
- package/sync.ts +705 -0
- package/tier.js +176 -0
- package/tier.js.map +1 -0
- package/tier.ts +211 -0
package/_dist/sync.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Bundle, Eid, Graph, Plugin } from "@yaks/graph";
|
|
2
|
+
import { type Fetch, type Refusal, type Report } from "./outbound.js";
|
|
3
|
+
import { type OutboxStore, type Pending } from "./outbox.js";
|
|
4
|
+
import { type Mine } from "./saying.js";
|
|
5
|
+
import { type Ask, type Connect, type Frame, type Tab, type Timer, type WireOpts } from "./socket.js";
|
|
6
|
+
/** Optional working-set policy. The client supplies retention here, rather
|
|
7
|
+
* than intercepting sockets or building a second sync/readiness registry. */ export type Replica = {
|
|
8
|
+
subscribe: (id: string, query: Ask, opts?: SubscribeOpts) => void;
|
|
9
|
+
unsubscribe: (id: string) => void;
|
|
10
|
+
/** apply one frame; `mine` is what this node is saying itself, which a
|
|
11
|
+
* reset frame leaves out (inbound.ts `hear`) */ land: (frame: Frame, mine?: Mine) => Bundle[] | Promise<Bundle[]>;
|
|
12
|
+
/** Hold these rows as a local write left them until it is answered. What
|
|
13
|
+
* it returns lets go, and names the subscriptions whose answers it held a
|
|
14
|
+
* row back from, which are asked again. */ protect: (eids: Eid[]) => (accepted?: boolean) => string[];
|
|
15
|
+
};
|
|
16
|
+
/** Local priming is optional: an authoritative server query may not be
|
|
17
|
+
* evaluable over the client's incomplete graph (search, ranking, walks). */ export type SubscribeOpts = {
|
|
18
|
+
/** Seed ownership from a local query before the first answer (default true). */ prime?: boolean;
|
|
19
|
+
/** Exact app semantic identity, including query options, for bounded reopen. */ answerKey?: string;
|
|
20
|
+
/** Deliver frames directly on the same socket, bypassing the graph replica
|
|
21
|
+
* and its persistence. A receiver owns its snapshot and updates. */ receive?: (frame: Frame) => void;
|
|
22
|
+
};
|
|
23
|
+
/** How a graph is connected to a server. Only `url` is required; both
|
|
24
|
+
* transports default to the platform's own. */ export type SyncOpts = {
|
|
25
|
+
/** Durable intent storage; defaults to IndexedDB in a browser. */ outbox?: OutboxStore<Bundle[]>;
|
|
26
|
+
/** Isolate apps/identities sharing an origin. Defaults to URL + headers. */ outboxScope?: string;
|
|
27
|
+
/** the server's base URL — the origin `/apply`, `/query` and `/ws` sit under */ url: string;
|
|
28
|
+
/** Working-set ownership, retention and pending-write protection. */ replica?: Replica;
|
|
29
|
+
/** how a write is sent (default: the global `fetch`) */ fetch?: Fetch;
|
|
30
|
+
/** Writes and subscription snapshots may use a host's own wire envelope. */ request?: (key: string, sent: Bundle[]) => Promise<Bundle[]>;
|
|
31
|
+
initial?: (query: string) => Promise<Omit<Frame, 'id'>>;
|
|
32
|
+
frame?: (frame: Frame) => void;
|
|
33
|
+
/** Keep a hosted writer's receipt open during transient delivery failures. */ retryWrites?: boolean;
|
|
34
|
+
cancelTimer?: (handle: unknown) => void;
|
|
35
|
+
/** Local epoch milliseconds for clock measurement (default: monotonic epoch). */ time?: () => number;
|
|
36
|
+
/** how the socket is opened (default: the global `WebSocket`) */ connect?: Connect;
|
|
37
|
+
/** how a reconnect, and a relayed value's pace, is timed (default:
|
|
38
|
+
* `setTimeout`) */ timer?: Timer;
|
|
39
|
+
/** headers on every `POST /apply` — an authorization, say */ headers?: Record<string, string>;
|
|
40
|
+
/** where a refusal or a transport failure is surfaced (default: a warning) */ report?: Report;
|
|
41
|
+
} & Pick<WireOpts, 'wait' | 'most' | 'held' | 'spread' | 'random'>;
|
|
42
|
+
/** A graph's connection to a server: its subscriptions, and the state of the
|
|
43
|
+
* socket they are held on. */ export type Sync = {
|
|
44
|
+
/** the plugin this registered on the graph */ plugin: Plugin;
|
|
45
|
+
/** open the socket without subscribing to anything */ open: () => void;
|
|
46
|
+
/** subscribe to a query (or `true` for every committed write) */ subscribe: (query: Ask, id?: string, opts?: SubscribeOpts) => string;
|
|
47
|
+
/** drop one subscription */ unsubscribe: (id: string) => void;
|
|
48
|
+
/** Ask one subscription, or every subscription, for a fresh full frame from
|
|
49
|
+
* the server. */ refresh: (id?: string) => void;
|
|
50
|
+
/** Store epoch milliseconds, calibrated over the socket on first use. Starts
|
|
51
|
+
* locally until a reply; retains its last offset while disconnected. */ now: () => number;
|
|
52
|
+
/** whether the socket is open right now */ connected: () => boolean;
|
|
53
|
+
/** say whether this page's tab is visible and focused, now and on every
|
|
54
|
+
* connection */ tab: (tab: Tab) => void;
|
|
55
|
+
/** be called with true each time the socket opens, and with false each
|
|
56
|
+
* time an open one closes; not called immediately */ onConnection: (fn: (open: boolean) => void) => () => void;
|
|
57
|
+
/** whether this subscription has successfully applied an answer on the
|
|
58
|
+
* current connection. Cached rows alone never make it ready. */ ready: (id: string) => boolean;
|
|
59
|
+
/** be called when readiness changes (including on an empty first answer),
|
|
60
|
+
* and when the server refuses a subscription; not called immediately. The
|
|
61
|
+
* returned function removes the listener. */ onReady: (fn: (id: string, ready: boolean) => void) => () => void;
|
|
62
|
+
/** why the server refused this subscription, until it answers it again */ refusal: (id: string) => Refusal | undefined;
|
|
63
|
+
reopen: () => void;
|
|
64
|
+
/** Send an input batch whose identity the server must resolve before this
|
|
65
|
+
* graph can hold it. The caller has separated browser-owned components.
|
|
66
|
+
* `key` names the write, so a send after a `WriteUnknown` under the same key
|
|
67
|
+
* is answered as the first one was, never applied twice. */ submit: (sent: Bundle[], key?: string) => Promise<Bundle[]>;
|
|
68
|
+
/** Apply optimistically, but answer only after server acceptance. Local-only
|
|
69
|
+
* writes stay synchronous. Refusals and unknown outcomes reject. */ apply: (bundles: Bundle[], key?: string) => Bundle[] | Promise<Bundle[]>;
|
|
70
|
+
outboxReady: Promise<void>;
|
|
71
|
+
closeOutbox: () => void;
|
|
72
|
+
refuse: (bundles: Bundle[], error: unknown, key?: string) => Promise<never>;
|
|
73
|
+
pending: () => Pending<Bundle[]>[];
|
|
74
|
+
onPending: (fn: () => void) => () => void;
|
|
75
|
+
retry: (key: string) => Promise<void>;
|
|
76
|
+
forget: (key: string) => Promise<void>;
|
|
77
|
+
/** resolves when every write in flight has been answered */ idle: () => Promise<void>;
|
|
78
|
+
/** close the socket and stop reconnecting */ close: () => void;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Connect a client graph to a server. The plugin registers itself on the graph
|
|
82
|
+
* you pass in, so one line is the whole setup:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { graph } from '@yaks/graph'
|
|
86
|
+
* import { ram } from '@yaks/ram'
|
|
87
|
+
* import { sync } from '@yaks/sync'
|
|
88
|
+
*
|
|
89
|
+
* // let g = graph({ storage: ram(vocab, { adopt: true }), vocab })
|
|
90
|
+
* // let link = sync(g, { url: 'https://recipes.example' })
|
|
91
|
+
* // link.subscribe('.recipe.course=dinner&.recipe.serves>4')
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* From then on every write through `g.apply()` is applied locally at once and
|
|
95
|
+
* then sent to the server; everything the server pushes is applied locally too.
|
|
96
|
+
*/ export declare let sync: (graph: Graph, opts: SyncOpts) => Sync;
|
|
97
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sources":["../sync.ts"],"names":[],"mappings":"AAyBA,cAAc,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,2BAAoC;AAgB5E,SAEE,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,MAAM,wBAGS;AAEtB,SAAwB,KAAK,WAAW,EAAE,KAAK,OAAO,sBAAqB;AAE3E,SAAS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durableOf, syncOf, type Vocab } from "@yaks/vocab";
|
|
3
|
+
export { durableOf, syncOf };
|
|
4
|
+
/** Whether a component's writes leave this node at all — a `sync: none`
|
|
5
|
+
* component is never sent anywhere. */ export declare let outbound: (vocab: Vocab, comp: string) => boolean;
|
|
6
|
+
/** Whether the server keeps a component, so a row it answers is the whole
|
|
7
|
+
* truth about its saved value. Peer components with a save query also ride
|
|
8
|
+
* stored snapshots; their live values still arrive through the relay. */ export declare let stored: (vocab: Vocab, comp: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Where a component's state has to be kept on this node, for the components no
|
|
11
|
+
* server will ever send back: the vault when it is durable forever (it
|
|
12
|
+
* survives a reload), process memory otherwise (it goes with the tab, or with
|
|
13
|
+
* its timer). A component that is sent to the server is neither, because the
|
|
14
|
+
* server is what sends it back.
|
|
15
|
+
*/ export declare let local: (vocab: Vocab, comp: string) => 'vault' | 'memory' | null;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a row is this node's own: it holds a component that stays here, and
|
|
18
|
+
* nothing a server keeps besides the stamps this graph wrote on it. No server
|
|
19
|
+
* ever answers for such a row, so a watch that waits for the server's answer
|
|
20
|
+
* would never show it.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { equal } from '@yaks/testing'
|
|
24
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
25
|
+
* import { stays } from '@yaks/sync'
|
|
26
|
+
* let open = { type: 'boolean' }
|
|
27
|
+
* let v = loadVocab({ $defs: {
|
|
28
|
+
* doc: { component: true, properties: { title: { type: 'string' } } },
|
|
29
|
+
* Panel: { component: true, sync: 'none', properties: { open } },
|
|
30
|
+
* } })
|
|
31
|
+
* equal(stays(v, { entity: { eid: 'm' }, Panel: { open: true } }), true)
|
|
32
|
+
* equal(stays(v, { entity: { eid: 'm' }, Panel: {}, doc: {} }), false)
|
|
33
|
+
* ```
|
|
34
|
+
*/ export declare let stays: (vocab: Vocab, b: Bundle) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* One committed list of bundles, reduced to what the server should be told —
|
|
37
|
+
* the `sync: server` components, the ones it owns and stores. A write that is
|
|
38
|
+
* entirely local returns an empty list and nothing is posted at all.
|
|
39
|
+
*
|
|
40
|
+
* The `$was` precondition is sent with it, so the check the local graph just
|
|
41
|
+
* made is made again against the server's copy; the identity is sent as the
|
|
42
|
+
* `eid` alone, because `num` belongs to whoever is storing it.
|
|
43
|
+
*/ export declare let outward: (bundles: Bundle[], vocab: Vocab) => Bundle[];
|
|
44
|
+
/**
|
|
45
|
+
* The inverse of one committed list of bundles, as far as the server's
|
|
46
|
+
* refusal reaches: what to patch back when it refuses. What the caller sent is
|
|
47
|
+
* restored from the copy {@link before} took of it; its local and relayed
|
|
48
|
+
* values were not in the refused request, so they stay as they are. What the
|
|
49
|
+
* write's rules added is restored whole, since the write they followed from
|
|
50
|
+
* never happened.
|
|
51
|
+
*
|
|
52
|
+
* A DELETE gets no inverse here: a write that deletes is never applied
|
|
53
|
+
* optimistically — it waits for the server (sync.ts), so there is never a
|
|
54
|
+
* tombstone to lift.
|
|
55
|
+
*/ export declare let inverse: (bundles: Bundle[], vocab: Vocab) => Bundle[];
|
|
56
|
+
/**
|
|
57
|
+
* What the write's rules guessed about the components the server keeps, put
|
|
58
|
+
* back: the server ran the same rules over the whole graph, and its answer
|
|
59
|
+
* replaces the guess, so the guess is undone just before the answer lands. A
|
|
60
|
+
* rule's `sync: none` components are the page's own, and stay.
|
|
61
|
+
*/ export declare let guessed: (bundles: Bundle[], vocab: Vocab) => Bundle[];
|
|
62
|
+
//# sourceMappingURL=tier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tier.d.ts","sources":["../tier.ts"],"names":[],"mappings":"AAyBA,cAAc,MAAM,2BAAsC;AAE1D,SAAS,SAAS,EAAqB,MAAM,EAAE,KAAK,KAAK,2BAAgC;AAGzF,SAAS,SAAS,EAAa,MAAM,GAAE;AAEvC;qCACqC,GACrC,OAAO,YAAI,WAAY,OAAO,OAAO,MAAM,MAAM,KAAG,OAAO,CAC5B;AAE/B;;uEAEuE,GACvE,OAAO,YAAI,SAAU,OAAO,OAAO,MAAM,MAAM,KAAG,OAAO,CACO;AAEhE;;;;;;CAMC,GACD,OAAO,YAAI,QAAS,OAAO,OAAO,MAAM,MAAM,KAAG,UAAU,WAAW,IAAI,CAK5D;AAkBd;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,YAAI,QAAS,OAAO,OAAO,GAAG,WAAS,OAAO,CAMpD;AA8BD;;;;;;;;CAQC,GACD,OAAO,YAAI,UAAW,SAAS,UAAU,OAAO,UAAQ,SACf;AAwCzC;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,UAAW,SAAS,UAAU,OAAO,UAAQ,SAMpD;AAEJ;;;;;CAKC,GACD,OAAO,YAAI,UAAW,SAAS,UAAU,OAAO,UAAQ,SAMpD"}
|
package/clock.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Four timestamps, all in milliseconds: client departure, server receipt,
|
|
2
|
+
// server departure, client receipt. Server work isn't network delay.
|
|
3
|
+
/** One measured round trip on the store's epoch clock. */ /** NTP's offset and network round trip, or no sample for impossible times. */ export let estimate = (departure, received, sent, arrival)=>{
|
|
4
|
+
if (![
|
|
5
|
+
departure,
|
|
6
|
+
received,
|
|
7
|
+
sent,
|
|
8
|
+
arrival
|
|
9
|
+
].every(Number.isFinite)) return;
|
|
10
|
+
let delay = arrival - departure - (sent - received);
|
|
11
|
+
if (arrival < departure || sent < received || delay < 0) return;
|
|
12
|
+
return {
|
|
13
|
+
offset: (received - departure + (sent - arrival)) / 2,
|
|
14
|
+
delay
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** A clock anchored to the local epoch once, then advanced monotonically.
|
|
18
|
+
* Wall-clock adjustments on the page cannot corrupt round-trip measurements. */ export let epoch = ()=>{
|
|
19
|
+
let wall = Date.now();
|
|
20
|
+
let start = performance.now();
|
|
21
|
+
return ()=>wall + performance.now() - start;
|
|
22
|
+
};
|
|
23
|
+
/** A short clock-filter window: prefer the least delayed of the last eight
|
|
24
|
+
* trips. Queued packets don't pull the estimate around; aging admits drift. */ export let clock = (time = epoch())=>{
|
|
25
|
+
let samples = [];
|
|
26
|
+
let offset = 0;
|
|
27
|
+
return {
|
|
28
|
+
read: time,
|
|
29
|
+
now: ()=>time() + offset,
|
|
30
|
+
sample: (departure, received, sent)=>{
|
|
31
|
+
let sample = estimate(departure, received, sent, time());
|
|
32
|
+
if (!sample) return;
|
|
33
|
+
samples.push(sample);
|
|
34
|
+
if (samples.length > 8) samples.shift();
|
|
35
|
+
offset = samples.reduce((a, b)=>a.delay < b.delay ? a : b).offset;
|
|
36
|
+
},
|
|
37
|
+
// Keep the last offset through an outage, but prefer the new route's trips.
|
|
38
|
+
reset: ()=>{
|
|
39
|
+
samples = [];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=clock.js.map
|
package/clock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sources":["./clock.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AAErE,wDAAwD,GAMxD,4EAA4E,GAC5E,OAAO,IAAI,WAAW,CACpB,WACA,UACA,MACA;EAEA,IAAI,CAAC;IAAC;IAAW;IAAU;IAAM;GAAQ,CAAC,KAAK,CAAC,OAAO,QAAQ,GAAG;EAClE,IAAI,QAAQ,AAAC,UAAU,YAAa,CAAC,OAAO,QAAQ;EACpD,IAAI,UAAU,aAAa,OAAO,YAAY,QAAQ,GAAG;EACzD,OAAO;IAAE,QAAQ,CAAC,AAAC,WAAW,YAAa,CAAC,OAAO,OAAO,CAAC,IAAI;IAAG;EAAM;AAC1E,EAAC;AAED;8EAC8E,GAC9E,OAAO,IAAI,QAAQ;EACjB,IAAI,OAAO,KAAK,GAAG;EACnB,IAAI,QAAQ,YAAY,GAAG;EAC3B,OAAO,IAAM,OAAO,YAAY,GAAG,KAAK;AAC1C,EAAC;AAED;6EAC6E,GAC7E,OAAO,IAAI,QAAQ,CAAC,OAAqB,OAAO;EAM9C,IAAI,UAAyB,EAAE;EAC/B,IAAI,SAAS;EACb,OAAO;IACL,MAAM;IACN,KAAK,IAAM,SAAS;IACpB,QAAQ,CAAC,WAAW,UAAU;MAC5B,IAAI,SAAS,SAAS,WAAW,UAAU,MAAM;MACjD,IAAI,CAAC,QAAQ;MACb,QAAQ,IAAI,CAAC;MACb,IAAI,QAAQ,MAAM,GAAG,GAAG,QAAQ,KAAK;MACrC,SAAS,QAAQ,MAAM,CAAC,CAAC,GAAG,IAAM,EAAE,KAAK,GAAG,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM;IACrE;IACA,4EAA4E;IAC5E,OAAO;MACL,UAAU,EAAE;IACd;EACF;AACF,EAAC"}
|
package/clock.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Four timestamps, all in milliseconds: client departure, server receipt,
|
|
2
|
+
// server departure, client receipt. Server work isn't network delay.
|
|
3
|
+
|
|
4
|
+
/** One measured round trip on the store's epoch clock. */
|
|
5
|
+
export type ClockSample = {
|
|
6
|
+
offset: number
|
|
7
|
+
delay: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** NTP's offset and network round trip, or no sample for impossible times. */
|
|
11
|
+
export let estimate = (
|
|
12
|
+
departure: number,
|
|
13
|
+
received: number,
|
|
14
|
+
sent: number,
|
|
15
|
+
arrival: number,
|
|
16
|
+
): ClockSample | undefined => {
|
|
17
|
+
if (![departure, received, sent, arrival].every(Number.isFinite)) return
|
|
18
|
+
let delay = (arrival - departure) - (sent - received)
|
|
19
|
+
if (arrival < departure || sent < received || delay < 0) return
|
|
20
|
+
return { offset: ((received - departure) + (sent - arrival)) / 2, delay }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A clock anchored to the local epoch once, then advanced monotonically.
|
|
24
|
+
* Wall-clock adjustments on the page cannot corrupt round-trip measurements. */
|
|
25
|
+
export let epoch = (): () => number => {
|
|
26
|
+
let wall = Date.now()
|
|
27
|
+
let start = performance.now()
|
|
28
|
+
return () => wall + performance.now() - start
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A short clock-filter window: prefer the least delayed of the last eight
|
|
32
|
+
* trips. Queued packets don't pull the estimate around; aging admits drift. */
|
|
33
|
+
export let clock = (time: () => number = epoch()): {
|
|
34
|
+
now: () => number
|
|
35
|
+
read: () => number
|
|
36
|
+
sample: (departure: number, received: number, sent: number) => void
|
|
37
|
+
reset: () => void
|
|
38
|
+
} => {
|
|
39
|
+
let samples: ClockSample[] = []
|
|
40
|
+
let offset = 0
|
|
41
|
+
return {
|
|
42
|
+
read: time,
|
|
43
|
+
now: () => time() + offset,
|
|
44
|
+
sample: (departure, received, sent) => {
|
|
45
|
+
let sample = estimate(departure, received, sent, time())
|
|
46
|
+
if (!sample) return
|
|
47
|
+
samples.push(sample)
|
|
48
|
+
if (samples.length > 8) samples.shift()
|
|
49
|
+
offset = samples.reduce((a, b) => a.delay < b.delay ? a : b).offset
|
|
50
|
+
},
|
|
51
|
+
// Keep the last offset through an outage, but prefer the new route's trips.
|
|
52
|
+
reset: () => {
|
|
53
|
+
samples = []
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
package/coverage.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Coverage records which components and properties a delivery actually carried.
|
|
2
|
+
// It is not a second copy of the data: a property missing from a bundle but
|
|
3
|
+
// outside the delivery's coverage has simply not been loaded, and must not be
|
|
4
|
+
// read as a null the server asserted.
|
|
5
|
+
import { comps } from "@yaks/graph/bundle";
|
|
6
|
+
/** Whether a delivery covers a component's presence or a particular
|
|
7
|
+
* property. */ export let covers = (scope, name, prop)=>scope === true || (prop === undefined ? Object.hasOwn(scope, name) : scope[name] === true || (scope[name] || []).includes(prop));
|
|
8
|
+
/** The coverage of a rider bundle that declared none: exactly what it
|
|
9
|
+
* carried. */ export let delivered = (b)=>Object.fromEntries(comps(b).map(([name, comp])=>[
|
|
10
|
+
name,
|
|
11
|
+
comp === null ? true : Object.keys(comp)
|
|
12
|
+
]));
|
|
13
|
+
//# sourceMappingURL=coverage.js.map
|
package/coverage.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","sources":["./coverage.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,sCAAsC;AAEtC,SAAS,KAAK,kCAAuC;AAIrD;aACa,GACb,OAAO,IAAI,SAAS,CAAC,OAAiB,MAAc,OAClD,UAAU,QACV,CAAC,SAAS,YACN,OAAO,MAAM,CAAC,OAAO,QACrB,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,QAAQ,CAAC,KAAK,EAAC;AAEjE;YACY,GACZ,OAAO,IAAI,YAAY,CAAC,IACtB,OAAO,WAAW,CAChB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,GAAK;MAC7B;MACA,SAAS,OAAO,OAAO,OAAO,IAAI,CAAC;KACpC,GACF"}
|
package/coverage.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Coverage records which components and properties a delivery actually carried.
|
|
2
|
+
// It is not a second copy of the data: a property missing from a bundle but
|
|
3
|
+
// outside the delivery's coverage has simply not been loaded, and must not be
|
|
4
|
+
// read as a null the server asserted.
|
|
5
|
+
import type { Bundle, Coverage } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { comps } from '@yaks/graph/bundle'
|
|
7
|
+
|
|
8
|
+
export type { Coverage }
|
|
9
|
+
|
|
10
|
+
/** Whether a delivery covers a component's presence or a particular
|
|
11
|
+
* property. */
|
|
12
|
+
export let covers = (scope: Coverage, name: string, prop?: string): boolean =>
|
|
13
|
+
scope === true ||
|
|
14
|
+
(prop === undefined
|
|
15
|
+
? Object.hasOwn(scope, name)
|
|
16
|
+
: scope[name] === true || (scope[name] || []).includes(prop))
|
|
17
|
+
|
|
18
|
+
/** The coverage of a rider bundle that declared none: exactly what it
|
|
19
|
+
* carried. */
|
|
20
|
+
export let delivered = (b: Bundle): Coverage =>
|
|
21
|
+
Object.fromEntries(
|
|
22
|
+
comps(b).map(([name, comp]) => [
|
|
23
|
+
name,
|
|
24
|
+
comp === null ? true : Object.keys(comp),
|
|
25
|
+
]),
|
|
26
|
+
)
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"compilerOptions":{"lib":["dom","esnext"]},"publish":{"exclude":["**/*_test.ts","testing.ts"]},"name":"@yaks/sync","version":"0.2.36","license":"Apache-2.0","description":"Synchronizes a client graph with a server, applies live query updates, and reconciles optimistic writes or reverts them when refused.","exports":{".":"./mod.ts","./port":"./port.ts","./socket":"./socket.ts","./outbox":"./outbox.ts"},"imports":{"@yaks/sync":"./mod.ts","@yaks/sync/port":"./port.ts","@yaks/sync/socket":"./socket.ts","@yaks/sync/outbox":"./outbox.ts"}}
|
package/inbound.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// What the server pushes, applied to the local graph. An incoming frame goes
|
|
2
|
+
// through the same `apply()` a local write goes through — trusted, because the
|
|
3
|
+
// server is where the stamped properties and the numbers were written — and
|
|
4
|
+
// marked as an echo so the outbound hook does not send it straight back.
|
|
5
|
+
//
|
|
6
|
+
// `gone` is the part no client could work out for itself: an entity that left a
|
|
7
|
+
// subscription's set, whether it was deleted or merely stopped matching. The
|
|
8
|
+
// frame does not distinguish the two, so this module removes the entity's
|
|
9
|
+
// components rather than tombstoning it: an entity with no components matches
|
|
10
|
+
// no query — which is what leaving the set means — and it can come back whole
|
|
11
|
+
// when it matches again, where a tombstone could never be lifted. A deletion
|
|
12
|
+
// still tombstones, because a deletion arrives as a `tombstone` component in
|
|
13
|
+
// the frame's bundles.
|
|
14
|
+
//
|
|
15
|
+
// `relay` is the other half no client could work out: a peer's `sync: peers`
|
|
16
|
+
// values, somebody's cursor, which the server forwards without keeping. They
|
|
17
|
+
// land in the local graph like anything else the server sends, so a query
|
|
18
|
+
// finds them beside the entity they belong to.
|
|
19
|
+
import { after, same } from "@yaks/fp";
|
|
20
|
+
import { comps, dead } from "@yaks/graph/bundle";
|
|
21
|
+
import { transient } from "@yaks/graph/read";
|
|
22
|
+
import { replicate } from "./mark.js";
|
|
23
|
+
import { covers } from "./coverage.js";
|
|
24
|
+
import { outbound, stored, syncOf } from "./tier.js";
|
|
25
|
+
// A patch that removes an entity's server-owned components, leaving its local
|
|
26
|
+
// state alone. The entity is then invisible to every query, which is what "no
|
|
27
|
+
// longer in the set" looks like locally.
|
|
28
|
+
let bare = (graph, b)=>{
|
|
29
|
+
if (dead(b)) return [] // already tombstoned; nothing left to remove
|
|
30
|
+
;
|
|
31
|
+
let out = {
|
|
32
|
+
entity: {
|
|
33
|
+
eid: b.entity.eid
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
for (let [name] of comps(b)){
|
|
37
|
+
if (outbound(graph.vocab, name)) out[name] = null;
|
|
38
|
+
}
|
|
39
|
+
return comps(out).length ? [
|
|
40
|
+
out
|
|
41
|
+
] : [];
|
|
42
|
+
};
|
|
43
|
+
// A saved peer snapshot can lag this node's own paced relay. It initializes
|
|
44
|
+
// a reader, but cannot move a writer back behind what it is already saying.
|
|
45
|
+
let incoming = (graph, bundles, mine)=>bundles.map((b)=>{
|
|
46
|
+
let out = {
|
|
47
|
+
...b
|
|
48
|
+
};
|
|
49
|
+
for (let [name] of comps(b)){
|
|
50
|
+
if (syncOf(graph.vocab, name) == 'peers' && mine(b.entity.eid, name)) {
|
|
51
|
+
delete out[name];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Take these entities out of the local graph: their server-owned components are
|
|
58
|
+
* dropped, their identity stays. This is what a subscription's `gone` list
|
|
59
|
+
* means.
|
|
60
|
+
*/ export let strip = (graph, eids)=>after(graph.get(eids), (held)=>{
|
|
61
|
+
let out = held.flatMap((b)=>bare(graph, b));
|
|
62
|
+
return out.length ? replicate(graph, out) : [];
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* One frame from the server, applied: the bundles it carries go in whole and
|
|
66
|
+
* trusted, and the entities it lists as gone have their components removed. A
|
|
67
|
+
* frame with `coverage` is a {@link snapshot} within it, so what the answer
|
|
68
|
+
* covers and no longer carries is cleared. Riders need a Replica to own them.
|
|
69
|
+
* A refused subscription changes nothing in the graph — it is reported, not
|
|
70
|
+
* applied. `mine` is what this node is saying itself, as {@link hear} takes it.
|
|
71
|
+
*/ export let land = (graph, frame, mine = none)=>{
|
|
72
|
+
if (frame.refused) return [];
|
|
73
|
+
if (frame.peerCoverage || frame.peers || frame.peerGone) {
|
|
74
|
+
throw new Error('rider delivery requires a working-set replica');
|
|
75
|
+
}
|
|
76
|
+
const live = transient(graph);
|
|
77
|
+
let bundles = frame.bundles ?? [], coverage = frame.coverage;
|
|
78
|
+
let gone = frame.gone ?? [];
|
|
79
|
+
live.forget([
|
|
80
|
+
...gone,
|
|
81
|
+
...frame.transientReset ?? []
|
|
82
|
+
]);
|
|
83
|
+
return after(!bundles.length ? [] : coverage ? snapshot(graph, bundles, {
|
|
84
|
+
coverage,
|
|
85
|
+
mine
|
|
86
|
+
}) : replicate(graph, incoming(graph, bundles, mine)), (applied)=>{
|
|
87
|
+
for (const update of frame.transient ?? [])live.receive(update);
|
|
88
|
+
return after(gone.length ? strip(graph, gone) : [], (out)=>after(hear(graph, frame, mine), (heard)=>[
|
|
89
|
+
...applied,
|
|
90
|
+
...out,
|
|
91
|
+
...heard
|
|
92
|
+
]));
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
// Saying nothing: a graph whose sync is not relaying anything of its own.
|
|
96
|
+
let none = ()=>false;
|
|
97
|
+
/**
|
|
98
|
+
* The relayed values a frame carries, applied: each peer's `sync: peers`
|
|
99
|
+
* components, and nothing else, as the patches they were sent as. A reset
|
|
100
|
+
* frame is the whole set as it now stands, relay included, so a peer value
|
|
101
|
+
* this copy still holds for one of its members and the frame does not repeat
|
|
102
|
+
* went away while this connection was not listening, and is cleared. What
|
|
103
|
+
* this node is saying itself (`mine`) is the exception: a connection is never
|
|
104
|
+
* told its own values, so the frame leaving them out says nothing about them.
|
|
105
|
+
*/ export let hear = (graph, frame, mine = none)=>{
|
|
106
|
+
let peer = (name)=>syncOf(graph.vocab, name) == 'peers';
|
|
107
|
+
let said = [];
|
|
108
|
+
let seen = new Map();
|
|
109
|
+
for (let b of frame.bundles ?? []){
|
|
110
|
+
for (let [name, patch] of comps(b)){
|
|
111
|
+
if (peer(name) && stored(graph.vocab, name) && patch != null) {
|
|
112
|
+
let names = seen.get(b.entity.eid) ?? new Set();
|
|
113
|
+
names.add(name);
|
|
114
|
+
seen.set(b.entity.eid, names);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (let b of frame.relay ?? []){
|
|
119
|
+
let out = {
|
|
120
|
+
entity: {
|
|
121
|
+
eid: b.entity.eid
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
for (let [name, patch] of comps(b)){
|
|
125
|
+
if (!peer(name)) continue;
|
|
126
|
+
out[name] = patch;
|
|
127
|
+
let names = seen.get(b.entity.eid) ?? new Set();
|
|
128
|
+
names.add(name);
|
|
129
|
+
seen.set(b.entity.eid, names);
|
|
130
|
+
}
|
|
131
|
+
if (comps(out).length) said.push(out);
|
|
132
|
+
}
|
|
133
|
+
let landed = ()=>said.length ? replicate(graph, said) : [];
|
|
134
|
+
if (!frame.reset || !frame.bundles?.length) return landed();
|
|
135
|
+
return after(graph.get(frame.bundles.map((b)=>b.entity.eid)), (held)=>{
|
|
136
|
+
for (let b of held){
|
|
137
|
+
let eid = b.entity.eid;
|
|
138
|
+
let out = {
|
|
139
|
+
entity: {
|
|
140
|
+
eid
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
for (let [name] of comps(b)){
|
|
144
|
+
if (!peer(name) || mine(eid, name)) continue;
|
|
145
|
+
if (seen.get(eid)?.has(name)) continue;
|
|
146
|
+
out[name] = null;
|
|
147
|
+
}
|
|
148
|
+
if (comps(out).length) said.push(out);
|
|
149
|
+
}
|
|
150
|
+
return landed();
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
/** Whether a patch would change the row held: an entity field, component or
|
|
154
|
+
* property it sets that does not already read so, or one it clears that is
|
|
155
|
+
* there. A whole answer heard again after a reconnect is mostly rows that did
|
|
156
|
+
* not move, and applying those would redo every reader's work for nothing. */ export let changes = (held, patch)=>{
|
|
157
|
+
if (!held || dead(held) || dead(patch)) return true;
|
|
158
|
+
for (let [key, value] of Object.entries(patch.entity)){
|
|
159
|
+
if (!same(held.entity[key], value)) return true;
|
|
160
|
+
}
|
|
161
|
+
for (let [name, comp] of comps(patch)){
|
|
162
|
+
let was = held[name];
|
|
163
|
+
if (comp == null ? was != null : was == null) return true;
|
|
164
|
+
for (let [prop, value] of Object.entries(comp ?? {})){
|
|
165
|
+
if (value == null ? was[prop] != null : !same(was[prop], value)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
};
|
|
172
|
+
/** Replace the components the server stores with a query's whole rows,
|
|
173
|
+
* including the properties it reports as absent. A raw feed carries patches
|
|
174
|
+
* instead, and must use land(). Local components and unsaved peer components
|
|
175
|
+
* never ride a stored row, so a snapshot never removes them. Saved peer values
|
|
176
|
+
* initialize readers while this node's own live writes remain ahead of them.
|
|
177
|
+
* A row that already reads as its snapshot says is left alone, and is not in
|
|
178
|
+
* what this returns: landing a whole answer again costs a comparison per row,
|
|
179
|
+
* and only what moved is applied. */ export let snapshot = (graph, bundles, opts = {})=>after(graph.get(bundles.map((b)=>b.entity.eid)), (held)=>{
|
|
180
|
+
let previous = new Map(held.map((b)=>[
|
|
181
|
+
b.entity.eid,
|
|
182
|
+
b
|
|
183
|
+
]));
|
|
184
|
+
let mine = opts.mine ?? none;
|
|
185
|
+
let patches = incoming(graph, bundles, mine).map((b)=>{
|
|
186
|
+
if (dead(b)) return b;
|
|
187
|
+
let out = {
|
|
188
|
+
entity: b.entity
|
|
189
|
+
};
|
|
190
|
+
let scope = opts.coverage?.[b.entity.eid] ?? true;
|
|
191
|
+
let keep = (name, prop)=>opts.preserve?.(b.entity.eid, name, prop) ?? false;
|
|
192
|
+
for (let [name, comp] of comps(previous.get(b.entity.eid) ?? out)){
|
|
193
|
+
if (!stored(graph.vocab, name)) continue;
|
|
194
|
+
if (syncOf(graph.vocab, name) == 'peers' && mine(b.entity.eid, name)) continue;
|
|
195
|
+
if (!covers(scope, name)) continue;
|
|
196
|
+
if (b[name] == null && (scope === true || scope[name] === true) && !keep(name)) {
|
|
197
|
+
out[name] = null;
|
|
198
|
+
} else {
|
|
199
|
+
let cut = Object.fromEntries(Object.keys(comp ?? {}).filter((key)=>covers(scope, name, key) && !keep(name, key)).map((key)=>[
|
|
200
|
+
key,
|
|
201
|
+
null
|
|
202
|
+
]));
|
|
203
|
+
if (Object.keys(cut).length) out[name] = cut;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (let [name, comp] of comps(b)){
|
|
207
|
+
if (!stored(graph.vocab, name) || !covers(scope, name)) continue;
|
|
208
|
+
out[name] = comp == null ? null : {
|
|
209
|
+
...out[name] ?? {},
|
|
210
|
+
...Object.fromEntries(Object.entries(comp).filter(([key])=>covers(scope, name, key)))
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}).filter((patch)=>changes(previous.get(patch.entity.eid), patch));
|
|
215
|
+
return patches.length ? replicate(graph, patches) : [];
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=inbound.js.map
|
package/inbound.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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