deno.land / x / replicache@v10.0.0-beta.0 / persist / clients-test-helpers.ts

clients-test-helpers.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {Client, ClientMap, initClient, updateClients} from './clients';import type * as dag from '../dag/mod';import type * as sync from '../sync/mod';import type {Hash} from '../hash';
export function setClients( clients: ClientMap, dagStore: dag.Store,): Promise<ClientMap> { return updateClients(_ => { return Promise.resolve({ clients, }); }, dagStore);}
export type PartialClient = { heartbeatTimestampMs: number; headHash: Hash; mutationID?: number; lastServerAckdMutationID?: number;};
export function makeClient(partialClient: PartialClient): Client { return { mutationID: 0, lastServerAckdMutationID: 0, ...partialClient, };}
export function makeClientMap( obj: Record<sync.ClientID, PartialClient>,): ClientMap { return new Map( Object.entries(obj).map( ([id, client]) => [id, makeClient(client)] as const, ), );}
export async function deleteClientForTesting( clientID: sync.ClientID, dagStore: dag.Store,): Promise<void> { await updateClients(clients => { const clientsAfterGC = new Map(clients); clientsAfterGC.delete(clientID); return { clients: new Map(clientsAfterGC), }; }, dagStore);}
export async function initClientWithClientID( clientID: sync.ClientID, dagStore: dag.Store,): Promise<void> { const [generatedClientID, client, clientMap] = await initClient(dagStore); const newMap = new Map(clientMap); newMap.delete(generatedClientID); newMap.set(clientID, client); await setClients(newMap, dagStore);}
replicache

Version Info

Tagged at
2 years ago