@interncom/diplomatic 0.0.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/README.md +34 -0
- package/dist/api.d.ts +3 -0
- package/dist/client.d.ts +34 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/eventEmitter.d.ts +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8600 -0
- package/dist/localStorageStore.d.ts +19 -0
- package/dist/ops.d.ts +2 -0
- package/dist/shared/client.d.ts +11 -0
- package/dist/shared/crypto/libsodium.d.ts +15 -0
- package/dist/shared/lib.d.ts +2 -0
- package/dist/shared/server.d.ts +11 -0
- package/dist/shared/types.d.ts +58 -0
- package/dist/state.d.ts +12 -0
- package/dist/sync.d.ts +2 -0
- package/dist/types.d.ts +18 -0
- package/dist/useClient.d.ts +8 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# diplomatic
|
|
2
|
+
|
|
3
|
+
Secure sync layer for web apps.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { useClient, StateManager, useStateWatcher } from '@interncom/diplomatic'
|
|
9
|
+
|
|
10
|
+
const appState = { count: 0 };
|
|
11
|
+
const stateMgr = new StateManager(async (op) => {
|
|
12
|
+
if (op.type === "count" && typeof op.body === "number") {
|
|
13
|
+
appState.count = op.body;
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export default function App() {
|
|
18
|
+
const [client] = useClient({
|
|
19
|
+
seed: "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
|
|
20
|
+
hostURL: "https://diplomatic-cloudflare-host.root-a00.workers.dev",
|
|
21
|
+
stateManager: stateMgr,
|
|
22
|
+
})
|
|
23
|
+
const count = useStateWatcher(stateMgr, "count", () => appState.count)
|
|
24
|
+
const inc = () => client.upsert("count", count + 1)
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<h1>COUNT</h1>
|
|
29
|
+
<h2>{count}</h2>
|
|
30
|
+
<button type="button" onClick={inc}>+1</button>
|
|
31
|
+
</>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
```
|
package/dist/api.d.ts
ADDED
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IOp, KeyPair } from "./shared/types";
|
|
2
|
+
import type { IClientStateStore, DiplomaticClientState, Applier } from "./types";
|
|
3
|
+
import type { StateManager } from "./state";
|
|
4
|
+
export interface IDiplomaticClientParams {
|
|
5
|
+
store: IClientStateStore;
|
|
6
|
+
stateManager: StateManager;
|
|
7
|
+
seed?: string | Uint8Array;
|
|
8
|
+
hostURL?: string;
|
|
9
|
+
hostID?: string;
|
|
10
|
+
}
|
|
11
|
+
export default class DiplomaticClient {
|
|
12
|
+
store: IClientStateStore;
|
|
13
|
+
applier: Applier;
|
|
14
|
+
listener?: (state: DiplomaticClientState) => void;
|
|
15
|
+
seed?: Uint8Array;
|
|
16
|
+
encKey?: Uint8Array;
|
|
17
|
+
hostURL?: URL;
|
|
18
|
+
hostKeyPair?: KeyPair;
|
|
19
|
+
lastFetchedAt?: string;
|
|
20
|
+
constructor(params: IDiplomaticClientParams);
|
|
21
|
+
init(params: IDiplomaticClientParams): Promise<void>;
|
|
22
|
+
loadSeed(): Promise<void>;
|
|
23
|
+
setSeed(seed: Uint8Array): Promise<void>;
|
|
24
|
+
loadHost(): Promise<void>;
|
|
25
|
+
register(hostURL: string): Promise<void>;
|
|
26
|
+
get state(): DiplomaticClientState;
|
|
27
|
+
private putDelta;
|
|
28
|
+
getDeltas(): Promise<IOp[]>;
|
|
29
|
+
processDeltas(): Promise<void>;
|
|
30
|
+
private pushQueuedOp;
|
|
31
|
+
pushQueuedOps(): Promise<void>;
|
|
32
|
+
apply(op: IOp): Promise<void>;
|
|
33
|
+
upsert<T>(type: string, body: T, version?: number): Promise<void>;
|
|
34
|
+
}
|
package/dist/crypto.d.ts
ADDED
package/dist/index.d.ts
ADDED