deno.land / x / replicache@v10.0.0-beta.0 / sync / client-id.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
import type * as kv from '../kv/mod';import {uuid as makeUuid} from '../uuid';import {assertString} from '../asserts';
// TODO: Make ClientID an opaque typeexport type ClientID = string;export const CID_KEY = 'sys/cid';
export async function init(store: kv.Store): Promise<ClientID> { const cid = await store.withRead(r => r.get(CID_KEY)); if (cid !== undefined) { assertString(cid); return cid; } const uuid = makeUuid(); await writeClientID(store, uuid); return uuid;}
function writeClientID(s: kv.Store, uuid: ClientID): Promise<void> { return s.withWrite(async wt => { await wt.put(CID_KEY, uuid); await wt.commit(); });}
replicache

Version Info

Tagged at
2 years ago