@holochain-syn/client 0.0.1 → 0.0.4
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/{src/index.ts → dist/index.d.ts} +0 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/syn-client.d.ts +47 -0
- package/dist/syn-client.js +130 -0
- package/dist/syn-client.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1985 -0
- package/dist/types/change.d.ts +44 -0
- package/dist/types/change.js +2 -0
- package/dist/types/change.js.map +1 -0
- package/dist/types/commit.d.ts +27 -0
- package/dist/types/commit.js +2 -0
- package/dist/types/commit.js.map +1 -0
- package/dist/types/folks.d.ts +10 -0
- package/dist/types/folks.js +2 -0
- package/dist/types/folks.js.map +1 -0
- package/dist/types/heartbeat.d.ts +10 -0
- package/dist/types/heartbeat.js +2 -0
- package/dist/types/heartbeat.js.map +1 -0
- package/dist/types/session.d.ts +21 -0
- package/dist/types/session.js +2 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/signal.d.ts +27 -0
- package/dist/types/signal.js +24 -0
- package/dist/types/signal.js.map +1 -0
- package/dist/types/sync.d.ts +27 -0
- package/dist/types/sync.js +2 -0
- package/dist/types/sync.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +17 -0
- package/dist/utils.js.map +1 -0
- package/package.json +6 -3
- package/src/syn-client.ts +0 -227
- package/src/types/change.ts +0 -66
- package/src/types/commit.ts +0 -41
- package/src/types/folks.ts +0 -17
- package/src/types/heartbeat.ts +0 -15
- package/src/types/session.ts +0 -29
- package/src/types/signal.ts +0 -52
- package/src/types/sync.ts +0 -42
- package/src/utils.ts +0 -17
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentPubKeyB64, EntryHashB64, Dictionary } from '@holochain-open-dev/core-types';
|
|
2
|
+
export declare type Delta = any;
|
|
3
|
+
export interface FolkChanges {
|
|
4
|
+
atFolkIndex: number;
|
|
5
|
+
commitChanges: Array<number>;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthoredDelta {
|
|
8
|
+
author: AgentPubKeyB64;
|
|
9
|
+
delta: Delta;
|
|
10
|
+
}
|
|
11
|
+
export interface ChangeBundle {
|
|
12
|
+
deltas: Array<AuthoredDelta>;
|
|
13
|
+
authors: Dictionary<FolkChanges>;
|
|
14
|
+
}
|
|
15
|
+
export interface SendChangeRequestInput {
|
|
16
|
+
sessionHash: EntryHashB64;
|
|
17
|
+
scribe: AgentPubKeyB64;
|
|
18
|
+
lastDeltaSeen: LastDeltaSeen;
|
|
19
|
+
deltaChanges: DeltaChanges;
|
|
20
|
+
}
|
|
21
|
+
export interface DeltaChanges {
|
|
22
|
+
atFolkIndex: number;
|
|
23
|
+
deltas: Array<Delta>;
|
|
24
|
+
}
|
|
25
|
+
export interface LastDeltaSeen {
|
|
26
|
+
commitHash: EntryHashB64 | undefined;
|
|
27
|
+
deltaIndexInCommit: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ChangeRequest {
|
|
30
|
+
folk: AgentPubKeyB64;
|
|
31
|
+
scribe: AgentPubKeyB64;
|
|
32
|
+
lastDeltaSeen: LastDeltaSeen;
|
|
33
|
+
deltaChanges: DeltaChanges;
|
|
34
|
+
}
|
|
35
|
+
export interface SendChangeInput {
|
|
36
|
+
participants: Array<AgentPubKeyB64>;
|
|
37
|
+
sessionHash: EntryHashB64;
|
|
38
|
+
lastDeltaSeen: LastDeltaSeen;
|
|
39
|
+
deltaChanges: ChangeBundle;
|
|
40
|
+
}
|
|
41
|
+
export interface ChangeNotice {
|
|
42
|
+
lastDeltaSeen: LastDeltaSeen;
|
|
43
|
+
deltaChanges: ChangeBundle;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change.js","sourceRoot":"","sources":["../../src/types/change.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentPubKeyB64, EntryHashB64, HeaderHashB64 } from '@holochain-open-dev/core-types';
|
|
2
|
+
import type { ChangeBundle } from './change';
|
|
3
|
+
export interface CommitInput {
|
|
4
|
+
sessionHash: EntryHashB64;
|
|
5
|
+
commit: Commit;
|
|
6
|
+
participants: AgentPubKeyB64[];
|
|
7
|
+
}
|
|
8
|
+
export interface Commit {
|
|
9
|
+
changes: ChangeBundle;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
previousCommitHashes: Array<EntryHashB64>;
|
|
12
|
+
previousContentHash: EntryHashB64;
|
|
13
|
+
newContentHash: EntryHashB64;
|
|
14
|
+
meta: ChangeMeta;
|
|
15
|
+
}
|
|
16
|
+
export interface CommitNotice {
|
|
17
|
+
commitHash: HeaderHashB64;
|
|
18
|
+
committedDeltasCount: number;
|
|
19
|
+
previousContentHash: EntryHashB64;
|
|
20
|
+
newContentHash: EntryHashB64;
|
|
21
|
+
meta: ChangeMeta;
|
|
22
|
+
}
|
|
23
|
+
export interface ChangeMeta {
|
|
24
|
+
witnesses: AgentPubKeyB64[];
|
|
25
|
+
appSpecific: Content;
|
|
26
|
+
}
|
|
27
|
+
export declare type Content = any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../../src/types/commit.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentPubKeyB64, Dictionary, EntryHashB64 } from '@holochain-open-dev/core-types';
|
|
2
|
+
export interface SendFolkLoreInput {
|
|
3
|
+
sessionHash: EntryHashB64;
|
|
4
|
+
participants: Array<AgentPubKeyB64>;
|
|
5
|
+
folkLore: FolkLore;
|
|
6
|
+
}
|
|
7
|
+
export interface FolkInfo {
|
|
8
|
+
lastSeen: number;
|
|
9
|
+
}
|
|
10
|
+
export declare type FolkLore = Dictionary<FolkInfo>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folks.js","sourceRoot":"","sources":["../../src/types/folks.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentPubKeyB64, EntryHashB64 } from "@holochain-open-dev/core-types";
|
|
2
|
+
export interface SendHeartbeatInput {
|
|
3
|
+
sessionHash: EntryHashB64;
|
|
4
|
+
scribe: AgentPubKeyB64;
|
|
5
|
+
data: String;
|
|
6
|
+
}
|
|
7
|
+
export interface Heartbeat {
|
|
8
|
+
fromFolk: AgentPubKeyB64;
|
|
9
|
+
data: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/types/heartbeat.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentPubKeyB64, EntryHashB64 } from '@holochain-open-dev/core-types';
|
|
2
|
+
export interface Session {
|
|
3
|
+
initialCommitHash: EntryHashB64 | undefined;
|
|
4
|
+
scribe: AgentPubKeyB64;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SessionInfo {
|
|
8
|
+
sessionHash: EntryHashB64;
|
|
9
|
+
session: Session;
|
|
10
|
+
}
|
|
11
|
+
export interface NewSessionInput {
|
|
12
|
+
initialCommitHash: EntryHashB64 | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface CloseSessionInput {
|
|
15
|
+
sessionHash: EntryHashB64;
|
|
16
|
+
participants: AgentPubKeyB64[];
|
|
17
|
+
}
|
|
18
|
+
export interface NotifyLeaveSessionInput {
|
|
19
|
+
sessionHash: EntryHashB64;
|
|
20
|
+
scribe: AgentPubKeyB64;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CommitNotice } from './commit';
|
|
2
|
+
import type { ChangeNotice, ChangeRequest } from './change';
|
|
3
|
+
import type { FolkLore } from './folks';
|
|
4
|
+
import type { Heartbeat } from './heartbeat';
|
|
5
|
+
import type { RequestSyncInput, StateForSync } from './sync';
|
|
6
|
+
import type { AgentPubKeyB64 } from '@holochain-open-dev/core-types';
|
|
7
|
+
export declare enum SynMessageType {
|
|
8
|
+
SyncReq = "SyncReq",
|
|
9
|
+
SyncResp = "SyncResp",
|
|
10
|
+
ChangeReq = "ChangeReq",
|
|
11
|
+
ChangeNotice = "ChangeNotice",
|
|
12
|
+
CommitNotice = "CommitNotice",
|
|
13
|
+
Heartbeat = "Heartbeat",
|
|
14
|
+
FolkLore = "FolkLore",
|
|
15
|
+
SessionClosed = "SessionClosed",
|
|
16
|
+
LeaveSessionNotice = "LeaveSessionNotice"
|
|
17
|
+
}
|
|
18
|
+
export declare const allMessageTypes: SynMessageType[];
|
|
19
|
+
export declare type SynSignal = {
|
|
20
|
+
sessionHash: string;
|
|
21
|
+
message: SynMessage;
|
|
22
|
+
};
|
|
23
|
+
export interface MessageBody<TYPE, PAYLOAD> {
|
|
24
|
+
type: TYPE;
|
|
25
|
+
payload: PAYLOAD;
|
|
26
|
+
}
|
|
27
|
+
export declare type SynMessage = MessageBody<SynMessageType.SyncReq, RequestSyncInput> | MessageBody<SynMessageType.SyncResp, StateForSync> | MessageBody<SynMessageType.ChangeReq, ChangeRequest> | MessageBody<SynMessageType.ChangeNotice, ChangeNotice> | MessageBody<SynMessageType.CommitNotice, CommitNotice> | MessageBody<SynMessageType.Heartbeat, Heartbeat> | MessageBody<SynMessageType.FolkLore, FolkLore> | MessageBody<SynMessageType.LeaveSessionNotice, AgentPubKeyB64> | MessageBody<SynMessageType.SessionClosed, void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var SynMessageType;
|
|
2
|
+
(function (SynMessageType) {
|
|
3
|
+
SynMessageType["SyncReq"] = "SyncReq";
|
|
4
|
+
SynMessageType["SyncResp"] = "SyncResp";
|
|
5
|
+
SynMessageType["ChangeReq"] = "ChangeReq";
|
|
6
|
+
SynMessageType["ChangeNotice"] = "ChangeNotice";
|
|
7
|
+
SynMessageType["CommitNotice"] = "CommitNotice";
|
|
8
|
+
SynMessageType["Heartbeat"] = "Heartbeat";
|
|
9
|
+
SynMessageType["FolkLore"] = "FolkLore";
|
|
10
|
+
SynMessageType["SessionClosed"] = "SessionClosed";
|
|
11
|
+
SynMessageType["LeaveSessionNotice"] = "LeaveSessionNotice";
|
|
12
|
+
})(SynMessageType || (SynMessageType = {}));
|
|
13
|
+
export const allMessageTypes = [
|
|
14
|
+
SynMessageType.SyncReq,
|
|
15
|
+
SynMessageType.SyncResp,
|
|
16
|
+
SynMessageType.ChangeReq,
|
|
17
|
+
SynMessageType.ChangeNotice,
|
|
18
|
+
SynMessageType.CommitNotice,
|
|
19
|
+
SynMessageType.Heartbeat,
|
|
20
|
+
SynMessageType.FolkLore,
|
|
21
|
+
SynMessageType.SessionClosed,
|
|
22
|
+
SynMessageType.LeaveSessionNotice,
|
|
23
|
+
];
|
|
24
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/types/signal.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,+CAA6B,CAAA;IAC7B,+CAA6B,CAAA;IAC7B,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,iDAA+B,CAAA;IAC/B,2DAAyC,CAAA;AAC3C,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc,CAAC,OAAO;IACtB,cAAc,CAAC,QAAQ;IACvB,cAAc,CAAC,SAAS;IACxB,cAAc,CAAC,YAAY;IAC3B,cAAc,CAAC,YAAY;IAC3B,cAAc,CAAC,SAAS;IACxB,cAAc,CAAC,QAAQ;IACvB,cAAc,CAAC,aAAa;IAC5B,cAAc,CAAC,kBAAkB;CAClC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ChangeBundle, LastDeltaSeen } from './change';
|
|
2
|
+
import type { EntryHashB64, AgentPubKeyB64 } from '@holochain-open-dev/core-types';
|
|
3
|
+
import type { Commit, Content } from './commit';
|
|
4
|
+
export interface SendSyncRequestInput {
|
|
5
|
+
sessionHash: EntryHashB64;
|
|
6
|
+
scribe: AgentPubKeyB64;
|
|
7
|
+
lastDeltaSeen: LastDeltaSeen | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface RequestSyncInput {
|
|
10
|
+
folk: AgentPubKeyB64;
|
|
11
|
+
scribe: AgentPubKeyB64;
|
|
12
|
+
lastDeltaSeen: LastDeltaSeen;
|
|
13
|
+
}
|
|
14
|
+
export interface MissedCommit {
|
|
15
|
+
commitHash: EntryHashB64;
|
|
16
|
+
commit: Commit;
|
|
17
|
+
commitInitialSnapshot: Content;
|
|
18
|
+
}
|
|
19
|
+
export interface StateForSync {
|
|
20
|
+
folkMissedLastCommit: MissedCommit | undefined;
|
|
21
|
+
uncommittedChanges: ChangeBundle;
|
|
22
|
+
}
|
|
23
|
+
export interface SendSyncResponseInput {
|
|
24
|
+
sessionHash: EntryHashB64;
|
|
25
|
+
participant: AgentPubKeyB64;
|
|
26
|
+
state: StateForSync;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/types/sync.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deepDecodeUint8Arrays(object: any): any;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { decode } from "@msgpack/msgpack";
|
|
2
|
+
export function deepDecodeUint8Arrays(object) {
|
|
3
|
+
if (object === undefined || object === null)
|
|
4
|
+
return object;
|
|
5
|
+
if (object instanceof Uint8Array)
|
|
6
|
+
return decode(object);
|
|
7
|
+
if (typeof object !== "object")
|
|
8
|
+
return object;
|
|
9
|
+
if (Array.isArray(object))
|
|
10
|
+
return object.map(deepDecodeUint8Arrays);
|
|
11
|
+
const obj = {};
|
|
12
|
+
for (const key of Object.keys(object)) {
|
|
13
|
+
obj[key] = deepDecodeUint8Arrays(object[key]);
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,UAAU,qBAAqB,CAAC,MAAW;IAC/C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC3D,IAAI,MAAM,YAAY,UAAU;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IAExD,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAE9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAEpE,MAAM,GAAG,GAAG,EAAE,CAAC;IAEf,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,GAAG,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;KAC/C;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain-syn/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"type": "module",
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc",
|
|
@@ -16,9 +19,9 @@
|
|
|
16
19
|
"typescript": "^4.2.4"
|
|
17
20
|
},
|
|
18
21
|
"dependencies": {
|
|
19
|
-
"@holochain-open-dev/cell-client": "^0.3
|
|
22
|
+
"@holochain-open-dev/cell-client": "^0.5.3",
|
|
20
23
|
"@holochain-open-dev/core-types": "^0.2.0",
|
|
21
|
-
"@holochain/client": "^0.
|
|
24
|
+
"@holochain/client": "^0.4.1",
|
|
22
25
|
"@msgpack/msgpack": "^2.7.0",
|
|
23
26
|
"lodash-es": "^4.17.21"
|
|
24
27
|
},
|
package/src/syn-client.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import type { CellClient } from '@holochain-open-dev/cell-client';
|
|
2
|
-
import type {
|
|
3
|
-
EntryHashB64,
|
|
4
|
-
AgentPubKeyB64,
|
|
5
|
-
} from '@holochain-open-dev/core-types';
|
|
6
|
-
import { encode, decode } from '@msgpack/msgpack';
|
|
7
|
-
import isEqual from 'lodash-es/isEqual';
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
ChangeBundle,
|
|
11
|
-
SendChangeInput,
|
|
12
|
-
SendChangeRequestInput,
|
|
13
|
-
} from './types/change';
|
|
14
|
-
import type { Commit, CommitInput, Content } from './types/commit';
|
|
15
|
-
import type { SendFolkLoreInput } from './types/folks';
|
|
16
|
-
import type { SendHeartbeatInput } from './types/heartbeat';
|
|
17
|
-
import type {
|
|
18
|
-
CloseSessionInput,
|
|
19
|
-
NewSessionInput,
|
|
20
|
-
NotifyLeaveSessionInput,
|
|
21
|
-
Session,
|
|
22
|
-
SessionInfo,
|
|
23
|
-
} from './types/session';
|
|
24
|
-
import type { SendSyncRequestInput, SendSyncResponseInput } from './types/sync';
|
|
25
|
-
import { allMessageTypes, SynSignal } from './types/signal';
|
|
26
|
-
import { deepDecodeUint8Arrays } from './utils';
|
|
27
|
-
|
|
28
|
-
export class SynClient {
|
|
29
|
-
unsubscribe: () => void = () => {};
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
public cellClient: CellClient,
|
|
33
|
-
protected handleSignal: (synSignal: SynSignal) => void,
|
|
34
|
-
protected zomeName = 'syn'
|
|
35
|
-
) {
|
|
36
|
-
const { unsubscribe } = cellClient.addSignalHandler(signal => {
|
|
37
|
-
console.log(signal);
|
|
38
|
-
if (
|
|
39
|
-
isEqual(cellClient.cellId, signal.data.cellId) &&
|
|
40
|
-
signal.data.payload.message &&
|
|
41
|
-
allMessageTypes.includes(signal.data.payload.message.type)
|
|
42
|
-
) {
|
|
43
|
-
handleSignal(deepDecodeUint8Arrays(signal.data.payload));
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
this.unsubscribe = unsubscribe;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public close() {
|
|
51
|
-
return this.unsubscribe();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Session */
|
|
55
|
-
public async getSession(sessionHash: EntryHashB64): Promise<Session> {
|
|
56
|
-
return this.callZome('get_session', sessionHash);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public async newSession(
|
|
60
|
-
newSessionInput: NewSessionInput
|
|
61
|
-
): Promise<SessionInfo> {
|
|
62
|
-
return this.callZome('new_session', newSessionInput);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public async closeSession(input: CloseSessionInput): Promise<void> {
|
|
66
|
-
return this.callZome('close_session', input);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public getSessions(): Promise<Record<string, Session>> {
|
|
70
|
-
return this.callZome('get_sessions', null);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public notifyLeaveSession(input: NotifyLeaveSessionInput): Promise<void> {
|
|
74
|
-
return this.callZome('notify_leave_session', input);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Content */
|
|
78
|
-
public putSnapshot(content: Content): Promise<EntryHashB64> {
|
|
79
|
-
return this.callZome('put_snapshot', encode(content));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public async getSnapshot(
|
|
83
|
-
snapshotHash: EntryHashB64
|
|
84
|
-
): Promise<Content | undefined> {
|
|
85
|
-
const content = await this.callZome('get_snapshot', snapshotHash);
|
|
86
|
-
if (!content) return content;
|
|
87
|
-
return decode(content);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public hashSnapshot(content: Content): Promise<EntryHashB64> {
|
|
91
|
-
return this.callZome('hash_snapshot', encode(content));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Commits */
|
|
95
|
-
public commitChanges(commitInput: CommitInput): Promise<EntryHashB64> {
|
|
96
|
-
const commit = {
|
|
97
|
-
...commitInput,
|
|
98
|
-
commit: {
|
|
99
|
-
...commitInput.commit,
|
|
100
|
-
changes: this.encodeChangeBundle(commitInput.commit.changes),
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return this.callZome('commit_changes', commit);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public async getCommit(commitHash: EntryHashB64): Promise<Commit> {
|
|
108
|
-
const commit = await this.callZome('get_commit', commitHash);
|
|
109
|
-
return this.decodeCommit(commit);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public async getAllCommits(): Promise<Record<string, Commit>> {
|
|
113
|
-
const commits = await this.callZome('get_all_commits', null);
|
|
114
|
-
|
|
115
|
-
for (const key of Object.keys(commits)) {
|
|
116
|
-
commits[key] = this.decodeCommit(commits[key]);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return commits;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** Folks */
|
|
123
|
-
|
|
124
|
-
public getFolks(): Promise<Array<AgentPubKeyB64>> {
|
|
125
|
-
return this.callZome('get_folks', null);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public sendFolkLore(sendFolkLoreInput: SendFolkLoreInput): Promise<void> {
|
|
129
|
-
return this.callZome('send_folk_lore', sendFolkLoreInput);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Sync */
|
|
133
|
-
public sendSyncRequest(
|
|
134
|
-
syncRequestInput: SendSyncRequestInput
|
|
135
|
-
): Promise<void> {
|
|
136
|
-
return this.callZome('send_sync_request', syncRequestInput);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public sendSyncResponse(
|
|
140
|
-
syncResponseInput: SendSyncResponseInput
|
|
141
|
-
): Promise<void> {
|
|
142
|
-
const input = {
|
|
143
|
-
...syncResponseInput,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
if (input.state.folkMissedLastCommit) {
|
|
147
|
-
input.state.folkMissedLastCommit.commit = this.encodeCommit(
|
|
148
|
-
input.state.folkMissedLastCommit.commit
|
|
149
|
-
);
|
|
150
|
-
input.state.folkMissedLastCommit.commitInitialSnapshot = encode(
|
|
151
|
-
input.state.folkMissedLastCommit.commitInitialSnapshot
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
if (input.state.uncommittedChanges) {
|
|
155
|
-
input.state.uncommittedChanges = this.encodeChangeBundle(
|
|
156
|
-
syncResponseInput.state.uncommittedChanges
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return this.callZome('send_sync_response', input);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Changes */
|
|
164
|
-
public sendChangeRequest(
|
|
165
|
-
changeRequestInput: SendChangeRequestInput
|
|
166
|
-
): Promise<void> {
|
|
167
|
-
const input = { ...changeRequestInput };
|
|
168
|
-
if (input.deltaChanges) {
|
|
169
|
-
input.deltaChanges = {
|
|
170
|
-
...input.deltaChanges,
|
|
171
|
-
deltas: input.deltaChanges.deltas.map(d => encode(d)),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return this.callZome('send_change_request', input);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
public sendChange(sendChangeInput: SendChangeInput): Promise<void> {
|
|
179
|
-
const input = {
|
|
180
|
-
...sendChangeInput,
|
|
181
|
-
};
|
|
182
|
-
if (input.deltaChanges) {
|
|
183
|
-
input.deltaChanges = this.encodeChangeBundle(input.deltaChanges);
|
|
184
|
-
}
|
|
185
|
-
return this.callZome('send_change', input);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Heartbeat */
|
|
189
|
-
public sendHeartbeat(heartbeatInput: SendHeartbeatInput): Promise<void> {
|
|
190
|
-
return this.callZome('send_heartbeat', heartbeatInput);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Helpers */
|
|
194
|
-
private async callZome(fnName: string, payload: any): Promise<any> {
|
|
195
|
-
return this.cellClient.callZome(this.zomeName, fnName, payload);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private encodeCommit(commit: Commit) {
|
|
199
|
-
return {
|
|
200
|
-
...commit,
|
|
201
|
-
changes: this.encodeChangeBundle(commit.changes),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private encodeChangeBundle(changes: ChangeBundle) {
|
|
206
|
-
return {
|
|
207
|
-
...changes,
|
|
208
|
-
deltas: changes.deltas.map(d => ({
|
|
209
|
-
author: d.author,
|
|
210
|
-
delta: encode(d.delta),
|
|
211
|
-
})),
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private decodeCommit(commit: any): Commit {
|
|
216
|
-
return {
|
|
217
|
-
...commit,
|
|
218
|
-
changes: {
|
|
219
|
-
authors: commit.changes.authors,
|
|
220
|
-
deltas: commit.changes.deltas.map(d => ({
|
|
221
|
-
author: d.author,
|
|
222
|
-
delta: decode(d.delta),
|
|
223
|
-
})),
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
package/src/types/change.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentPubKeyB64,
|
|
3
|
-
EntryHashB64,
|
|
4
|
-
Dictionary,
|
|
5
|
-
} from '@holochain-open-dev/core-types';
|
|
6
|
-
|
|
7
|
-
export type Delta = any;
|
|
8
|
-
|
|
9
|
-
export interface FolkChanges {
|
|
10
|
-
atFolkIndex: number;
|
|
11
|
-
commitChanges: Array<number>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AuthoredDelta {
|
|
15
|
-
author: AgentPubKeyB64;
|
|
16
|
-
delta: Delta;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ChangeBundle {
|
|
20
|
-
// Indexed by commit index
|
|
21
|
-
deltas: Array<AuthoredDelta>;
|
|
22
|
-
// AgentPubKeyB64 -> folkIndex -> sessionIndex
|
|
23
|
-
authors: Dictionary<FolkChanges>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// From folk to scribe
|
|
27
|
-
export interface SendChangeRequestInput {
|
|
28
|
-
sessionHash: EntryHashB64;
|
|
29
|
-
scribe: AgentPubKeyB64;
|
|
30
|
-
lastDeltaSeen: LastDeltaSeen;
|
|
31
|
-
|
|
32
|
-
deltaChanges: DeltaChanges;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface DeltaChanges {
|
|
36
|
-
atFolkIndex: number;
|
|
37
|
-
deltas: Array<Delta>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface LastDeltaSeen {
|
|
41
|
-
commitHash: EntryHashB64 | undefined;
|
|
42
|
-
deltaIndexInCommit: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ChangeRequest {
|
|
46
|
-
folk: AgentPubKeyB64;
|
|
47
|
-
scribe: AgentPubKeyB64;
|
|
48
|
-
|
|
49
|
-
lastDeltaSeen: LastDeltaSeen;
|
|
50
|
-
|
|
51
|
-
deltaChanges: DeltaChanges;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface SendChangeInput {
|
|
55
|
-
participants: Array<AgentPubKeyB64>;
|
|
56
|
-
sessionHash: EntryHashB64;
|
|
57
|
-
lastDeltaSeen: LastDeltaSeen;
|
|
58
|
-
|
|
59
|
-
deltaChanges: ChangeBundle;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ChangeNotice {
|
|
63
|
-
lastDeltaSeen: LastDeltaSeen;
|
|
64
|
-
|
|
65
|
-
deltaChanges: ChangeBundle;
|
|
66
|
-
}
|
package/src/types/commit.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentPubKeyB64,
|
|
3
|
-
EntryHashB64,
|
|
4
|
-
HeaderHashB64,
|
|
5
|
-
} from '@holochain-open-dev/core-types';
|
|
6
|
-
import type { ChangeBundle } from './change';
|
|
7
|
-
|
|
8
|
-
export interface CommitInput {
|
|
9
|
-
sessionHash: EntryHashB64;
|
|
10
|
-
|
|
11
|
-
commit: Commit;
|
|
12
|
-
|
|
13
|
-
participants: AgentPubKeyB64[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Commit {
|
|
17
|
-
changes: ChangeBundle;
|
|
18
|
-
|
|
19
|
-
createdAt: number;
|
|
20
|
-
|
|
21
|
-
previousCommitHashes: Array<EntryHashB64>;
|
|
22
|
-
|
|
23
|
-
previousContentHash: EntryHashB64;
|
|
24
|
-
newContentHash: EntryHashB64;
|
|
25
|
-
meta: ChangeMeta;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface CommitNotice {
|
|
29
|
-
commitHash: HeaderHashB64;
|
|
30
|
-
committedDeltasCount: number;
|
|
31
|
-
previousContentHash: EntryHashB64;
|
|
32
|
-
newContentHash: EntryHashB64;
|
|
33
|
-
meta: ChangeMeta;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ChangeMeta {
|
|
37
|
-
witnesses: AgentPubKeyB64[];
|
|
38
|
-
appSpecific: Content;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type Content = any;
|
package/src/types/folks.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentPubKeyB64,
|
|
3
|
-
Dictionary,
|
|
4
|
-
EntryHashB64,
|
|
5
|
-
} from '@holochain-open-dev/core-types';
|
|
6
|
-
|
|
7
|
-
export interface SendFolkLoreInput {
|
|
8
|
-
sessionHash: EntryHashB64;
|
|
9
|
-
participants: Array<AgentPubKeyB64>;
|
|
10
|
-
folkLore: FolkLore;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface FolkInfo {
|
|
14
|
-
lastSeen: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type FolkLore = Dictionary<FolkInfo>;
|
package/src/types/heartbeat.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentPubKeyB64,
|
|
3
|
-
EntryHashB64,
|
|
4
|
-
} from "@holochain-open-dev/core-types";
|
|
5
|
-
|
|
6
|
-
export interface SendHeartbeatInput {
|
|
7
|
-
sessionHash: EntryHashB64;
|
|
8
|
-
scribe: AgentPubKeyB64;
|
|
9
|
-
data: String;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface Heartbeat {
|
|
13
|
-
fromFolk: AgentPubKeyB64;
|
|
14
|
-
data: string;
|
|
15
|
-
}
|