@ddd-qc/profiles-dvm 0.26.9 → 0.26.11
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/profilesAlt.perspective.d.ts +39 -0
- package/dist/profilesAlt.perspective.js +131 -0
- package/dist/profilesAlt.perspective.js.map +1 -0
- package/dist/profilesAlt.zvm.d.ts +6 -28
- package/dist/profilesAlt.zvm.js +15 -116
- package/dist/profilesAlt.zvm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./bindings/profiles.types";
|
|
|
2
2
|
export * from "./bindings/profiles.proxy";
|
|
3
3
|
export * from "./profiles.zvm";
|
|
4
4
|
export * from "./bindings/profilesAlt.proxy";
|
|
5
|
+
export * from "./profilesAlt.perspective";
|
|
5
6
|
export * from "./profilesAlt.zvm";
|
|
6
7
|
export * from "./elements/edit-profile";
|
|
7
8
|
export * from "./profiles.dvm";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./bindings/profiles.types";
|
|
|
2
2
|
export * from "./bindings/profiles.proxy";
|
|
3
3
|
export * from "./profiles.zvm";
|
|
4
4
|
export * from "./bindings/profilesAlt.proxy";
|
|
5
|
+
export * from "./profilesAlt.perspective";
|
|
5
6
|
export * from "./profilesAlt.zvm";
|
|
6
7
|
export * from "./elements/edit-profile";
|
|
7
8
|
export * from "./profiles.dvm";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AAEjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA","sourcesContent":["export * from \"./bindings/profiles.types\"\nexport * from \"./bindings/profiles.proxy\"\nexport * from \"./profiles.zvm\"\n\nexport * from \"./bindings/profilesAlt.proxy\"\nexport * from \"./profilesAlt.zvm\"\n\nexport * from \"./elements/edit-profile\"\nexport * from \"./profiles.dvm\"\nexport * from \"./utils\"\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AAEjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA","sourcesContent":["export * from \"./bindings/profiles.types\"\nexport * from \"./bindings/profiles.proxy\"\nexport * from \"./profiles.zvm\"\n\nexport * from \"./bindings/profilesAlt.proxy\"\nexport * from \"./profilesAlt.perspective\"\nexport * from \"./profilesAlt.zvm\"\n\nexport * from \"./elements/edit-profile\"\nexport * from \"./profiles.dvm\"\nexport * from \"./utils\"\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ActionId, ActionIdMap, AgentId, AgentIdMap } from "@ddd-qc/cell-proxy";
|
|
2
|
+
import { Profile } from "./bindings/profiles.types";
|
|
3
|
+
import { Timestamp } from "@holochain/client";
|
|
4
|
+
/** */
|
|
5
|
+
export interface ProfilesAltPerspectiveCore {
|
|
6
|
+
profiles: ActionIdMap<[Profile, Timestamp]>;
|
|
7
|
+
profileByAgent: AgentIdMap<ActionId>;
|
|
8
|
+
}
|
|
9
|
+
export declare class ProfilesAltPerspective implements ProfilesAltPerspectiveCore {
|
|
10
|
+
profiles: ActionIdMap<[Profile, Timestamp]>;
|
|
11
|
+
profileByAgent: AgentIdMap<ActionId>;
|
|
12
|
+
/** Extra */
|
|
13
|
+
private _agentByName;
|
|
14
|
+
/** -- Getters -- */
|
|
15
|
+
get agents(): AgentId[];
|
|
16
|
+
get names(): string[];
|
|
17
|
+
/** */
|
|
18
|
+
getProfileAgent(profileId: ActionId): AgentId | undefined;
|
|
19
|
+
/** */
|
|
20
|
+
getProfile(agent: AgentId | string): Profile | undefined;
|
|
21
|
+
/** */
|
|
22
|
+
getProfileTs(agent: AgentId | string): Timestamp | undefined;
|
|
23
|
+
/** */
|
|
24
|
+
getAgent(nickname: string): AgentId | undefined;
|
|
25
|
+
/** -- Store -- */
|
|
26
|
+
/** */
|
|
27
|
+
storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp): void;
|
|
28
|
+
/** */
|
|
29
|
+
storeAgentProfile(agentId: AgentId, profileAh: ActionId): void;
|
|
30
|
+
/** */
|
|
31
|
+
unstoreAgentProfile(agentId: AgentId, profileAh: ActionId): void;
|
|
32
|
+
/** -- Memento -- */
|
|
33
|
+
/** TODO: deep copy */
|
|
34
|
+
makeSnapshot(): ProfilesAltPerspectiveCore;
|
|
35
|
+
restore(core: ProfilesAltPerspectiveCore): void;
|
|
36
|
+
/** -- Generate -- */
|
|
37
|
+
/** */
|
|
38
|
+
generateRandomProfile(nickname: string, ts?: Timestamp, fields?: Record<string, string>): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ActionId, ActionIdMap, AgentId, AgentIdMap } from "@ddd-qc/cell-proxy";
|
|
2
|
+
// export interface ProfilesAltPerspectiveExtra {
|
|
3
|
+
// /** Nickname -> AgentId */
|
|
4
|
+
// agentByName: Record<string, AgentId>,
|
|
5
|
+
// }
|
|
6
|
+
//
|
|
7
|
+
// export type ProfilesAltPerspectiveFull = ProfilesAltPerspectiveCore & ProfilesAltPerspectiveExtra;
|
|
8
|
+
export class ProfilesAltPerspective {
|
|
9
|
+
constructor() {
|
|
10
|
+
/* Core */
|
|
11
|
+
this.profiles = new ActionIdMap();
|
|
12
|
+
this.profileByAgent = new AgentIdMap();
|
|
13
|
+
/** Extra */
|
|
14
|
+
this._agentByName = {};
|
|
15
|
+
}
|
|
16
|
+
// /* */
|
|
17
|
+
// diff(core: ProfilesAltPerspectiveCore): boolean {
|
|
18
|
+
// // TODO
|
|
19
|
+
// return true;
|
|
20
|
+
// }
|
|
21
|
+
/** -- Getters -- */
|
|
22
|
+
get agents() { return Array.from(this.profileByAgent.keys()); }
|
|
23
|
+
get names() { return Object.keys(this._agentByName); }
|
|
24
|
+
/** */
|
|
25
|
+
getProfileAgent(profileId) {
|
|
26
|
+
for (const [agentId, profId] of this.profileByAgent.entries()) {
|
|
27
|
+
if (profileId.b64 == profId.b64) {
|
|
28
|
+
return agentId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
/** */
|
|
34
|
+
getProfile(agent) {
|
|
35
|
+
if (typeof agent == "string") {
|
|
36
|
+
agent = this._agentByName[agent];
|
|
37
|
+
if (!agent) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const profileAh = this.profileByAgent.get(agent);
|
|
42
|
+
//console.log("ProfilesAltZvm.getProfile()", agent, profileAh);
|
|
43
|
+
if (!profileAh) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const pair = this.profiles.get(profileAh);
|
|
47
|
+
//console.log("ProfilesAltZvm.getProfile() pair", pair);
|
|
48
|
+
if (!pair) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return pair[0];
|
|
52
|
+
}
|
|
53
|
+
/** */
|
|
54
|
+
getProfileTs(agent) {
|
|
55
|
+
if (typeof agent == "string") {
|
|
56
|
+
agent = this._agentByName[agent];
|
|
57
|
+
if (!agent) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const profileAh = this.profileByAgent.get(agent);
|
|
62
|
+
if (!profileAh) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const pair = this.profiles.get(profileAh);
|
|
66
|
+
return pair[1];
|
|
67
|
+
}
|
|
68
|
+
/** */
|
|
69
|
+
getAgent(nickname) {
|
|
70
|
+
return this._agentByName[nickname];
|
|
71
|
+
}
|
|
72
|
+
/** -- Store -- */
|
|
73
|
+
/** */
|
|
74
|
+
storeProfile(profileAh, profile, ts) {
|
|
75
|
+
//console.log("ProfilesAltZvm.storeProfile()", profileAh, profile.nickname);
|
|
76
|
+
this.profiles.set(profileAh, [profile, ts]);
|
|
77
|
+
const agentId = this.getProfileAgent(profileAh);
|
|
78
|
+
if (agentId) {
|
|
79
|
+
this._agentByName[profile.nickname] = agentId;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** */
|
|
83
|
+
storeAgentProfile(agentId, profileAh) {
|
|
84
|
+
//console.log("ProfilesAltZvm.storeAgentProfile()", agentId, profileAh);
|
|
85
|
+
this.profileByAgent.set(agentId, profileAh);
|
|
86
|
+
const pair = this.profiles.get(profileAh);
|
|
87
|
+
if (pair) {
|
|
88
|
+
this._agentByName[pair[0].nickname] = agentId;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** */
|
|
92
|
+
unstoreAgentProfile(agentId, profileAh) {
|
|
93
|
+
//console.log("ProfilesAltZvm.unstoreAgentProfile()", agentId, profileAh);
|
|
94
|
+
this.profileByAgent.delete(agentId);
|
|
95
|
+
const pair = this.profiles.get(profileAh);
|
|
96
|
+
if (pair) {
|
|
97
|
+
delete this._agentByName[pair[0].nickname];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** -- Memento -- */
|
|
101
|
+
/** TODO: deep copy */
|
|
102
|
+
makeSnapshot() {
|
|
103
|
+
return {
|
|
104
|
+
profiles: this.profiles,
|
|
105
|
+
profileByAgent: this.profileByAgent,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
restore(core) {
|
|
109
|
+
/** Clear */
|
|
110
|
+
this.profiles.clear();
|
|
111
|
+
this.profileByAgent.clear();
|
|
112
|
+
this._agentByName = {};
|
|
113
|
+
/** */
|
|
114
|
+
for (const [agentId, profileAh] of core.profileByAgent.entries()) {
|
|
115
|
+
this.storeAgentProfile(agentId, profileAh);
|
|
116
|
+
}
|
|
117
|
+
for (const [profileAh, [profile, ts]] of core.profiles.entries()) {
|
|
118
|
+
this.storeProfile(profileAh, profile, ts);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** -- Generate -- */
|
|
122
|
+
/** */
|
|
123
|
+
async generateRandomProfile(nickname, ts, fields) {
|
|
124
|
+
const agentId = await AgentId.random();
|
|
125
|
+
const profileAh = await ActionId.random();
|
|
126
|
+
const profile = { nickname, fields };
|
|
127
|
+
this.storeAgentProfile(agentId, profileAh);
|
|
128
|
+
this.storeProfile(profileAh, profile, ts ? ts : 0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=profilesAlt.perspective.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profilesAlt.perspective.js","sourceRoot":"","sources":["../src/profilesAlt.perspective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAY9E,iDAAiD;AACjD,+BAA+B;AAC/B,0CAA0C;AAC1C,IAAI;AACJ,EAAE;AACF,qGAAqG;AAGrG,MAAM,OAAO,sBAAsB;IAAnC;QAEE,UAAU;QACV,aAAQ,GAAsC,IAAI,WAAW,EAAE,CAAC;QAChE,mBAAc,GAAyB,IAAI,UAAU,EAAE,CAAC;QACxD,YAAY;QACJ,iBAAY,GAA4B,EAAE,CAAC;IA2IrD,CAAC;IAxIC,QAAQ;IACR,oDAAoD;IACpD,YAAY;IACZ,iBAAiB;IACjB,IAAI;IAGJ,oBAAoB;IAEpB,IAAI,MAAM,KAAgB,OAAO,KA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AAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;CAEF","sourcesContent":["import {ActionId, ActionIdMap, AgentId, AgentIdMap} from \"@ddd-qc/cell-proxy\";\r\nimport {Profile} from \"./bindings/profiles.types\";\r\nimport {Timestamp} from \"@holochain/client\";\r\n\r\n/** */\r\nexport interface ProfilesAltPerspectiveCore {\r\n /* ActionId -> Profile */\r\n profiles: ActionIdMap<[Profile, Timestamp]>,\r\n /* AgentId -> ActionId */\r\n profileByAgent: AgentIdMap<ActionId>,\r\n}\r\n\r\n// export interface ProfilesAltPerspectiveExtra {\r\n// /** Nickname -> AgentId */\r\n// agentByName: Record<string, AgentId>,\r\n// }\r\n//\r\n// export type ProfilesAltPerspectiveFull = ProfilesAltPerspectiveCore & ProfilesAltPerspectiveExtra;\r\n\r\n\r\nexport class ProfilesAltPerspective implements ProfilesAltPerspectiveCore {\r\n\r\n /* Core */\r\n profiles: ActionIdMap<[Profile, Timestamp]> = new ActionIdMap();\r\n profileByAgent: AgentIdMap<ActionId> = new AgentIdMap();\r\n /** Extra */\r\n private _agentByName: Record<string, AgentId> = {};\r\n\r\n\r\n // /* */\r\n // diff(core: ProfilesAltPerspectiveCore): boolean {\r\n // // TODO\r\n // return true;\r\n // }\r\n\r\n\r\n /** -- Getters -- */\r\n\r\n get agents(): AgentId[] { return Array.from(this.profileByAgent.keys())}\r\n get names(): string[] { return Object.keys(this._agentByName)}\r\n\r\n /** */\r\n getProfileAgent(profileId: ActionId): AgentId | undefined {\r\n for (const [agentId, profId] of this.profileByAgent.entries()) {\r\n if (profileId.b64 == profId.b64) {\r\n return agentId;\r\n }\r\n }\r\n return undefined;\r\n }\r\n\r\n\r\n /** */\r\n getProfile(agent: AgentId | string): Profile | undefined {\r\n if (typeof agent == \"string\") {\r\n agent = this._agentByName[agent];\r\n if (!agent) {\r\n return;\r\n }\r\n }\r\n const profileAh = this.profileByAgent.get(agent);\r\n //console.log(\"ProfilesAltZvm.getProfile()\", agent, profileAh);\r\n if (!profileAh) {\r\n return undefined;\r\n }\r\n const pair = this.profiles.get(profileAh);\r\n //console.log(\"ProfilesAltZvm.getProfile() pair\", pair);\r\n if (!pair) {\r\n return undefined;\r\n }\r\n return pair[0];\r\n }\r\n\r\n\r\n /** */\r\n getProfileTs(agent: AgentId | string): Timestamp | undefined {\r\n if (typeof agent == \"string\") {\r\n agent = this._agentByName[agent];\r\n if (!agent) {\r\n return;\r\n }\r\n }\r\n const profileAh = this.profileByAgent.get(agent);\r\n if (!profileAh) {\r\n return undefined;\r\n }\r\n const pair = this.profiles.get(profileAh);\r\n return pair[1];\r\n }\r\n\r\n /** */\r\n getAgent(nickname: string): AgentId | undefined {\r\n return this._agentByName[nickname];\r\n }\r\n\r\n\r\n /** -- Store -- */\r\n\r\n /** */\r\n storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp) {\r\n //console.log(\"ProfilesAltZvm.storeProfile()\", profileAh, profile.nickname);\r\n this.profiles.set(profileAh, [profile, ts]);\r\n const agentId = this.getProfileAgent(profileAh);\r\n if (agentId) {\r\n this._agentByName[profile.nickname] = agentId;\r\n }\r\n }\r\n\r\n /** */\r\n storeAgentProfile(agentId: AgentId, profileAh: ActionId) {\r\n //console.log(\"ProfilesAltZvm.storeAgentProfile()\", agentId, profileAh);\r\n this.profileByAgent.set(agentId, profileAh);\r\n const pair = this.profiles.get(profileAh);\r\n if (pair) {\r\n this._agentByName[pair[0].nickname] = agentId;\r\n }\r\n }\r\n\r\n /** */\r\n unstoreAgentProfile(agentId: AgentId, profileAh: ActionId) {\r\n //console.log(\"ProfilesAltZvm.unstoreAgentProfile()\", agentId, profileAh);\r\n this.profileByAgent.delete(agentId);\r\n const pair = this.profiles.get(profileAh);\r\n if (pair) {\r\n delete this._agentByName[pair[0].nickname];\r\n }\r\n }\r\n\r\n\r\n /** -- Memento -- */\r\n\r\n /** TODO: deep copy */\r\n makeSnapshot(): ProfilesAltPerspectiveCore {\r\n return {\r\n profiles: this.profiles,\r\n profileByAgent: this.profileByAgent,\r\n }\r\n }\r\n\r\n restore(core: ProfilesAltPerspectiveCore) {\r\n /** Clear */\r\n this.profiles.clear();\r\n this.profileByAgent.clear();\r\n this._agentByName = {};\r\n /** */\r\n for (const [agentId, profileAh] of core.profileByAgent.entries()) {\r\n this.storeAgentProfile(agentId, profileAh);\r\n }\r\n for (const [profileAh, [profile, ts]] of core.profiles.entries()) {\r\n this.storeProfile(profileAh, profile, ts);\r\n }\r\n }\r\n\r\n\r\n /** -- Generate -- */\r\n\r\n /** */\r\n async generateRandomProfile(nickname: string, ts?: Timestamp, fields?: Record<string, string>) {\r\n const agentId = await AgentId.random();\r\n const profileAh = await ActionId.random();\r\n const profile: Profile = {nickname, fields};\r\n this.storeAgentProfile(agentId, profileAh);\r\n this.storeProfile(profileAh, profile, ts? ts : 0);\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentId, LinkPulseMat, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
|
|
2
2
|
import { Profile } from "./bindings/profiles.types";
|
|
3
|
-
import { Timestamp } from "@holochain/client";
|
|
4
3
|
import { ProfilesAltProxy } from "./bindings/profilesAlt.proxy";
|
|
5
4
|
import { EntryPulseMat } from "@ddd-qc/lit-happ/dist/ZomeViewModelWithSignals";
|
|
6
|
-
|
|
7
|
-
export interface ProfilesAltPerspectiveCore {
|
|
8
|
-
profiles: ActionIdMap<[Profile, Timestamp]>;
|
|
9
|
-
profileByAgent: AgentIdMap<ActionId>;
|
|
10
|
-
}
|
|
11
|
-
export interface ProfilesAltPerspectiveLive {
|
|
12
|
-
/** Nickname -> AgentId */
|
|
13
|
-
agentByName: Record<string, AgentId>;
|
|
14
|
-
}
|
|
15
|
-
export type ProfilesAltPerspective = ProfilesAltPerspectiveCore & ProfilesAltPerspectiveLive;
|
|
5
|
+
import { ProfilesAltPerspective } from "./profilesAlt.perspective";
|
|
16
6
|
/**
|
|
17
7
|
*
|
|
18
8
|
*/
|
|
@@ -28,24 +18,12 @@ export declare class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
28
18
|
get perspective(): ProfilesAltPerspective;
|
|
29
19
|
private _perspective;
|
|
30
20
|
/** -- Getters -- */
|
|
31
|
-
getProfileAgent(profileId: ActionId): AgentId | undefined;
|
|
32
21
|
getMyProfile(): Profile | undefined;
|
|
33
|
-
getProfile(agent: AgentId): Profile | undefined;
|
|
34
|
-
getProfileTs(agent: AgentId): Timestamp | undefined;
|
|
35
|
-
getAgents(): AgentId[];
|
|
36
|
-
getNames(): string[];
|
|
37
22
|
/** -- Signals -- */
|
|
38
23
|
/** */
|
|
39
|
-
handleLinkPulse(pulse: LinkPulseMat,
|
|
40
|
-
/** */
|
|
41
|
-
handleEntryPulse(pulse: EntryPulseMat, from: AgentId): Promise<void>;
|
|
42
|
-
/** -- Store -- */
|
|
43
|
-
/** */
|
|
44
|
-
storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp): void;
|
|
45
|
-
/** */
|
|
46
|
-
storeAgentProfile(agentId: AgentId, profileAh: ActionId): void;
|
|
24
|
+
handleLinkPulse(pulse: LinkPulseMat, _from: AgentId): Promise<void>;
|
|
47
25
|
/** */
|
|
48
|
-
|
|
26
|
+
handleEntryPulse(pulse: EntryPulseMat, _from: AgentId): Promise<void>;
|
|
49
27
|
/** -- Methods -- */
|
|
50
28
|
/** */
|
|
51
29
|
probeAllProfiles(): Promise<void>;
|
|
@@ -61,7 +39,7 @@ export declare class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
61
39
|
updateProfile(profile: Profile, agentId: AgentId): Promise<void>;
|
|
62
40
|
/** -- Import / Export -- */
|
|
63
41
|
/** Dump perspective as JSON */
|
|
64
|
-
|
|
42
|
+
export(): string;
|
|
65
43
|
/** */
|
|
66
|
-
|
|
44
|
+
import(json: string, _canPublish: boolean): void;
|
|
67
45
|
}
|
package/dist/profilesAlt.zvm.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { ActionId,
|
|
1
|
+
import { ActionId, AgentId, EntryId, StateChangeType, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
|
|
2
2
|
import { decode } from "@msgpack/msgpack";
|
|
3
3
|
import { ProfilesAltProxy } from "./bindings/profilesAlt.proxy";
|
|
4
4
|
import { ProfilesLinkType } from "./bindings/profiles.integrity";
|
|
5
5
|
import { ProfilesAltUnitEnum } from "./bindings/profilesAlt.integrity";
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
profiles: new ActionIdMap(),
|
|
9
|
-
profileByAgent: new AgentIdMap(),
|
|
10
|
-
agentByName: {},
|
|
11
|
-
};
|
|
12
|
-
}
|
|
6
|
+
import { ProfilesAltPerspective } from "./profilesAlt.perspective";
|
|
13
7
|
/**
|
|
14
8
|
*
|
|
15
9
|
*/
|
|
16
10
|
export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
17
11
|
constructor() {
|
|
18
12
|
super(...arguments);
|
|
19
|
-
this._perspective =
|
|
13
|
+
this._perspective = new ProfilesAltPerspective();
|
|
20
14
|
}
|
|
21
15
|
get zomeProxy() { return this._zomeProxy; }
|
|
22
16
|
/* */
|
|
@@ -38,43 +32,12 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
38
32
|
return this._perspective;
|
|
39
33
|
}
|
|
40
34
|
/** -- Getters -- */
|
|
41
|
-
getProfileAgent(profileId) {
|
|
42
|
-
for (const [agentId, profId] of this._perspective.profileByAgent.entries()) {
|
|
43
|
-
if (profileId.b64 == profId.b64) {
|
|
44
|
-
return agentId;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
35
|
getMyProfile() {
|
|
50
|
-
return this.getProfile(this.cell.agentId);
|
|
51
|
-
}
|
|
52
|
-
getProfile(agent) {
|
|
53
|
-
const profileAh = this._perspective.profileByAgent.get(agent);
|
|
54
|
-
console.log("ProfilesAltZvm.getProfile()", agent, profileAh);
|
|
55
|
-
if (!profileAh) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
const pair = this._perspective.profiles.get(profileAh);
|
|
59
|
-
console.log("ProfilesAltZvm.getProfile() pair", pair);
|
|
60
|
-
if (!pair) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
return pair[0];
|
|
64
|
-
}
|
|
65
|
-
getProfileTs(agent) {
|
|
66
|
-
const profileAh = this._perspective.profileByAgent.get(agent);
|
|
67
|
-
if (!profileAh) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const pair = this._perspective.profiles.get(profileAh);
|
|
71
|
-
return pair[1];
|
|
36
|
+
return this._perspective.getProfile(this.cell.agentId);
|
|
72
37
|
}
|
|
73
|
-
getAgents() { return Array.from(this._perspective.profileByAgent.keys()); }
|
|
74
|
-
getNames() { return Object.keys(this._perspective.agentByName); }
|
|
75
38
|
/** -- Signals -- */
|
|
76
39
|
/** */
|
|
77
|
-
async handleLinkPulse(pulse,
|
|
40
|
+
async handleLinkPulse(pulse, _from) {
|
|
78
41
|
/** */
|
|
79
42
|
switch (pulse.link_type) {
|
|
80
43
|
case ProfilesLinkType.PrefixPath:
|
|
@@ -93,85 +56,26 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
93
56
|
const agentId = AgentId.from(agentEh);
|
|
94
57
|
const profileAh = ActionId.from(pulse.target);
|
|
95
58
|
if (pulse.state == StateChangeType.Delete) {
|
|
96
|
-
this.unstoreAgentProfile(agentId, profileAh);
|
|
59
|
+
this._perspective.unstoreAgentProfile(agentId, profileAh);
|
|
97
60
|
}
|
|
98
61
|
else {
|
|
99
|
-
this.storeAgentProfile(agentId, profileAh);
|
|
62
|
+
this._perspective.storeAgentProfile(agentId, profileAh);
|
|
100
63
|
}
|
|
101
64
|
}
|
|
102
65
|
break;
|
|
103
66
|
}
|
|
104
67
|
}
|
|
105
68
|
/** */
|
|
106
|
-
async handleEntryPulse(pulse,
|
|
69
|
+
async handleEntryPulse(pulse, _from) {
|
|
107
70
|
switch (pulse.entryType) {
|
|
108
71
|
case ProfilesAltUnitEnum.Profile:
|
|
109
72
|
const profile = decode(pulse.bytes);
|
|
110
73
|
if (pulse.state != StateChangeType.Delete) {
|
|
111
|
-
this.storeProfile(pulse.ah, profile, pulse.ts);
|
|
74
|
+
this._perspective.storeProfile(pulse.ah, profile, pulse.ts);
|
|
112
75
|
}
|
|
113
76
|
break;
|
|
114
77
|
}
|
|
115
78
|
}
|
|
116
|
-
// /** */
|
|
117
|
-
// dumpSignalLogs(signalLogs: SignalLog[]) {
|
|
118
|
-
// this.dumpCastLogs();
|
|
119
|
-
// console.warn(`Signals received from zome "${this.zomeName}"`);
|
|
120
|
-
// let appSignals: any[] = [];
|
|
121
|
-
// signalLogs
|
|
122
|
-
// .filter((log) => log.type == SignalType.Zome)
|
|
123
|
-
// .map((log) => {
|
|
124
|
-
// const signal = log.zomeSignal as ZomeSignal;
|
|
125
|
-
// const pulses = signal.pulses as ZomeSignalProtocol[];
|
|
126
|
-
// const timestamp = prettyDate(new Date(log.ts));
|
|
127
|
-
// const from = enc64(signal.from) == this.cell.agentId.b64? "self" : new AgentId(signal.from);
|
|
128
|
-
// for (const pulse of pulses) {
|
|
129
|
-
// if (ZomeSignalProtocolType.Tip in pulse) {
|
|
130
|
-
// const tip: TipProtocol = pulse.Tip;
|
|
131
|
-
// const type = Object.keys(tip)[0];
|
|
132
|
-
// appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Tip, type, payload: tip});
|
|
133
|
-
// }
|
|
134
|
-
// if (ZomeSignalProtocolType.Entry in pulse) {
|
|
135
|
-
// const entryPulse = materializeEntryPulse(pulse.Entry, Object.values(ProfilesAltUnitEnum));
|
|
136
|
-
// const typedEntry = decode(entryPulse.bytes);
|
|
137
|
-
// appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Entry, state: prettyState(pulse.Entry.state), type: entryPulse.entryType, payload: typedEntry, ah_base: entryPulse.ah.short, eh_target: entryPulse.eh.short});
|
|
138
|
-
// }
|
|
139
|
-
// if (ZomeSignalProtocolType.Link in pulse) {
|
|
140
|
-
// const linkPulse = materializeLinkPulse(pulse.Link, Object.values(ProfilesAltLinkType));
|
|
141
|
-
// appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Link, state: prettyState(pulse.Link.state), type: linkPulse.link_type, payload: linkPulse.tag, ah_base: linkPulse.base.print(), eh_target: linkPulse.target.print()});
|
|
142
|
-
// }
|
|
143
|
-
// }
|
|
144
|
-
// });
|
|
145
|
-
// console.table(appSignals);
|
|
146
|
-
// }
|
|
147
|
-
/** -- Store -- */
|
|
148
|
-
/** */
|
|
149
|
-
storeProfile(profileAh, profile, ts) {
|
|
150
|
-
console.log("ProfilesAltZvm.storeProfile()", profileAh, profile.nickname);
|
|
151
|
-
this._perspective.profiles.set(profileAh, [profile, ts]);
|
|
152
|
-
const agentId = this.getProfileAgent(profileAh);
|
|
153
|
-
if (agentId) {
|
|
154
|
-
this._perspective.agentByName[profile.nickname] = agentId;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/** */
|
|
158
|
-
storeAgentProfile(agentId, profileAh) {
|
|
159
|
-
console.log("ProfilesAltZvm.storeAgentProfile()", agentId, profileAh);
|
|
160
|
-
this._perspective.profileByAgent.set(agentId, profileAh);
|
|
161
|
-
const pair = this._perspective.profiles.get(profileAh);
|
|
162
|
-
if (pair) {
|
|
163
|
-
this._perspective.agentByName[pair[0].nickname] = agentId;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/** */
|
|
167
|
-
unstoreAgentProfile(agentId, profileAh) {
|
|
168
|
-
console.log("ProfilesAltZvm.unstoreAgentProfile()", agentId, profileAh);
|
|
169
|
-
this._perspective.profileByAgent.delete(agentId);
|
|
170
|
-
const pair = this._perspective.profiles.get(profileAh);
|
|
171
|
-
if (pair) {
|
|
172
|
-
delete this._perspective.agentByName[pair[0].nickname];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
79
|
/** -- Methods -- */
|
|
176
80
|
/** */
|
|
177
81
|
async probeAllProfiles() {
|
|
@@ -180,7 +84,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
180
84
|
/** */
|
|
181
85
|
async findProfile(agentId) {
|
|
182
86
|
const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);
|
|
183
|
-
console.log("findProfile()
|
|
87
|
+
console.log("findProfile()", agentId, maybeProfilePair);
|
|
184
88
|
if (!maybeProfilePair) {
|
|
185
89
|
return;
|
|
186
90
|
}
|
|
@@ -204,14 +108,14 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
204
108
|
}
|
|
205
109
|
/** -- Import / Export -- */
|
|
206
110
|
/** Dump perspective as JSON */
|
|
207
|
-
|
|
111
|
+
export() {
|
|
208
112
|
//console.log("exportPerspective()", perspMat);
|
|
209
|
-
const core = this._perspective;
|
|
113
|
+
const core = this._perspective.makeSnapshot();
|
|
210
114
|
return JSON.stringify(core, null, 2);
|
|
211
115
|
}
|
|
212
116
|
/** */
|
|
213
|
-
|
|
214
|
-
const
|
|
117
|
+
import(json, _canPublish) {
|
|
118
|
+
const core = JSON.parse(json);
|
|
215
119
|
// if (canPublish) {
|
|
216
120
|
// for (const [profileAh, [profile, _ts]] of perspective.profiles.entries()) {
|
|
217
121
|
// await this.createProfile(profile, agentId);
|
|
@@ -219,12 +123,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
219
123
|
// return;
|
|
220
124
|
// }
|
|
221
125
|
/** */
|
|
222
|
-
|
|
223
|
-
this.storeProfile(profileAh, profile, ts);
|
|
224
|
-
}
|
|
225
|
-
for (const [agentId, profileAh] of perspective.profileByAgent.entries()) {
|
|
226
|
-
this.storeAgentProfile(agentId, profileAh);
|
|
227
|
-
}
|
|
126
|
+
this._perspective.restore(core);
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AC,IAAI,CAA+B,CAAC;QACnE,oBAAoB;QACpB,gFAAgF;QAChF,kDAAkD;QAClD,MAAM;QACN,YAAY;QACZ,IAAI;QACJ,MAAM;QACN,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE;YACvE,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;SAC3C;QACD,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE;YACvE,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SAC5C;IACH,CAAC;;AA7Pe,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {\n ActionId,\n ActionIdMap,\n AgentId,\n AgentIdMap,\n enc64,\n EntryId,\n LinkPulseMat, materializeEntryPulse, materializeLinkPulse,\n prettyDate,\n prettyState,\n SignalLog,\n SignalType, StateChangeType,\n TipProtocol,\n ZomeSignal,\n ZomeSignalProtocol,\n ZomeSignalProtocolType,\n ZomeViewModelWithSignals\n} from \"@ddd-qc/lit-happ\";\nimport {Profile} from \"./bindings/profiles.types\";\nimport {Timestamp} from \"@holochain/client\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {ProfilesAltProxy} from \"./bindings/profilesAlt.proxy\";\nimport {EntryPulseMat} from \"@ddd-qc/lit-happ/dist/ZomeViewModelWithSignals\";\nimport {ProfilesLinkType} from \"./bindings/profiles.integrity\";\nimport {ProfilesAltLinkType, ProfilesAltUnitEnum} from \"./bindings/profilesAlt.integrity\";\n\n\n/** */\nexport interface ProfilesAltPerspectiveCore {\n /* ActionId -> Profile */\n profiles: ActionIdMap<[Profile, Timestamp]>,\n /* AgentId -> ActionId */\n profileByAgent: AgentIdMap<ActionId>,\n}\n\nexport interface ProfilesAltPerspectiveLive {\n /** Nickname -> AgentId */\n agentByName: Record<string, AgentId>,\n}\n\nexport type ProfilesAltPerspective = ProfilesAltPerspectiveCore & ProfilesAltPerspectiveLive;\n\n\nfunction createProfilesAltPerspective(): ProfilesAltPerspective {\n return {\n profiles: new ActionIdMap(),\n profileByAgent: new AgentIdMap(),\n agentByName: {},\n }\n}\n\n\n/**\n *\n */\nexport class ProfilesAltZvm extends ZomeViewModelWithSignals {\n\n static readonly ZOME_PROXY = ProfilesAltProxy;\n get zomeProxy(): ProfilesAltProxy {return this._zomeProxy as ProfilesAltProxy;}\n\n\n /* */\n protected hasChanged(): boolean {\n // TODO\n return true;\n }\n\n\n /** */\n async initializePerspectiveOnline(): Promise<void> {\n await this.probeAllProfiles();\n }\n\n /** */\n probeAllInner() {\n this.probeAllProfiles();\n }\n\n /** -- Perspective -- */\n\n /* */\n get perspective(): ProfilesAltPerspective {\n return this._perspective;\n }\n\n private _perspective: ProfilesAltPerspective = createProfilesAltPerspective();\n\n\n /** -- Getters -- */\n\n getProfileAgent(profileId: ActionId): AgentId | undefined {\n for (const [agentId, profId] of this._perspective.profileByAgent.entries()) {\n if (profileId.b64 == profId.b64) {\n return agentId;\n }\n }\n return undefined;\n }\n\n getMyProfile(): Profile | undefined {\n return this.getProfile(this.cell.agentId);\n }\n\n getProfile(agent: AgentId): Profile | undefined {\n const profileAh = this._perspective.profileByAgent.get(agent);\n console.log(\"ProfilesAltZvm.getProfile()\", agent, profileAh);\n if (!profileAh) {\n return undefined;\n }\n const pair = this._perspective.profiles.get(profileAh);\n console.log(\"ProfilesAltZvm.getProfile() pair\", pair);\n if (!pair) {\n return undefined;\n }\n return pair[0];\n }\n\n getProfileTs(agent: AgentId): Timestamp | undefined {\n const profileAh = this._perspective.profileByAgent.get(agent);\n if (!profileAh) {\n return undefined;\n }\n const pair = this._perspective.profiles.get(profileAh);\n return pair[1];\n }\n\n getAgents(): AgentId[] { return Array.from(this._perspective.profileByAgent.keys())}\n\n getNames(): string[] { return Object.keys(this._perspective.agentByName)}\n\n\n /** -- Signals -- */\n\n /** */\n async handleLinkPulse(pulse: LinkPulseMat, from: AgentId): Promise<void> {\n /** */\n switch (pulse.link_type) {\n case ProfilesLinkType.PrefixPath:\n case ProfilesLinkType.PathToAgent: {\n const agentEh = new EntryId(pulse.target.b64);\n const agentId = AgentId.from(agentEh);\n if (pulse.state != StateChangeType.Delete) {\n await this.findProfile(agentId);\n }\n }\n break;\n case ProfilesLinkType.AgentToProfile: {\n const agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash\n const agentId = AgentId.from(agentEh);\n const profileAh = ActionId.from(pulse.target);\n if (pulse.state == StateChangeType.Delete) {\n this.unstoreAgentProfile(agentId, profileAh)\n } else {\n this.storeAgentProfile(agentId, profileAh)\n }\n }\n break;\n }\n }\n\n\n /** */\n async handleEntryPulse(pulse: EntryPulseMat, from: AgentId) {\n switch (pulse.entryType) {\n case ProfilesAltUnitEnum.Profile:\n const profile = decode(pulse.bytes) as Profile;\n if (pulse.state != StateChangeType.Delete) {\n this.storeProfile(pulse.ah, profile, pulse.ts);\n }\n break;\n }\n }\n\n\n // /** */\n // dumpSignalLogs(signalLogs: SignalLog[]) {\n // this.dumpCastLogs();\n // console.warn(`Signals received from zome \"${this.zomeName}\"`);\n // let appSignals: any[] = [];\n // signalLogs\n // .filter((log) => log.type == SignalType.Zome)\n // .map((log) => {\n // const signal = log.zomeSignal as ZomeSignal;\n // const pulses = signal.pulses as ZomeSignalProtocol[];\n // const timestamp = prettyDate(new Date(log.ts));\n // const from = enc64(signal.from) == this.cell.agentId.b64? \"self\" : new AgentId(signal.from);\n // for (const pulse of pulses) {\n // if (ZomeSignalProtocolType.Tip in pulse) {\n // const tip: TipProtocol = pulse.Tip;\n // const type = Object.keys(tip)[0];\n // appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Tip, type, payload: tip});\n // }\n // if (ZomeSignalProtocolType.Entry in pulse) {\n // const entryPulse = materializeEntryPulse(pulse.Entry, Object.values(ProfilesAltUnitEnum));\n // const typedEntry = decode(entryPulse.bytes);\n // appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Entry, state: prettyState(pulse.Entry.state), type: entryPulse.entryType, payload: typedEntry, ah_base: entryPulse.ah.short, eh_target: entryPulse.eh.short});\n // }\n // if (ZomeSignalProtocolType.Link in pulse) {\n // const linkPulse = materializeLinkPulse(pulse.Link, Object.values(ProfilesAltLinkType));\n // appSignals.push({timestamp, from, pulse: ZomeSignalProtocolType.Link, state: prettyState(pulse.Link.state), type: linkPulse.link_type, payload: linkPulse.tag, ah_base: linkPulse.base.print(), eh_target: linkPulse.target.print()});\n // }\n // }\n // });\n // console.table(appSignals);\n // }\n\n\n /** -- Store -- */\n\n /** */\n storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp) {\n console.log(\"ProfilesAltZvm.storeProfile()\", profileAh, profile.nickname);\n this._perspective.profiles.set(profileAh, [profile, ts]);\n const agentId = this.getProfileAgent(profileAh);\n if (agentId) {\n this._perspective.agentByName[profile.nickname] = agentId;\n }\n }\n\n /** */\n storeAgentProfile(agentId: AgentId, profileAh: ActionId) {\n console.log(\"ProfilesAltZvm.storeAgentProfile()\", agentId, profileAh);\n this._perspective.profileByAgent.set(agentId, profileAh);\n const pair = this._perspective.profiles.get(profileAh);\n if (pair) {\n this._perspective.agentByName[pair[0].nickname] = agentId;\n }\n }\n\n /** */\n unstoreAgentProfile(agentId: AgentId, profileAh: ActionId) {\n console.log(\"ProfilesAltZvm.unstoreAgentProfile()\", agentId, profileAh);\n this._perspective.profileByAgent.delete(agentId);\n const pair = this._perspective.profiles.get(profileAh);\n if (pair) {\n delete this._perspective.agentByName[pair[0].nickname];\n }\n }\n\n\n /** -- Methods -- */\n\n /** */\n async probeAllProfiles()/*: Promise<Record<AgentPubKeyB64, ProfileMat>>*/ {\n await this.zomeProxy.probeProfiles();\n }\n\n\n /** */\n async findProfile(agentId: AgentId): Promise<Profile | undefined> {\n const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);\n console.log(\"findProfile() maybeProfilePair\", maybeProfilePair);\n if (!maybeProfilePair) {\n return;\n }\n return maybeProfilePair[1];\n }\n\n\n /** */\n async createMyProfile(profile: Profile): Promise<void> {\n const _ah = await this.zomeProxy.createProfile([profile, this.cell.agentId.hash]);\n }\n\n\n /** */\n async updateMyProfile(profile: Profile): Promise<void> {\n const _ah = await this.zomeProxy.updateProfile([profile, this.cell.agentId.hash]);\n }\n\n\n /** */\n async createProfile(profile: Profile, agentId: AgentId): Promise<void> {\n const _ah = await this.zomeProxy.createProfile([profile, agentId.hash]);\n }\n\n\n /** */\n async updateProfile(profile: Profile, agentId: AgentId): Promise<void> {\n const _ah = await this.zomeProxy.updateProfile([profile, agentId.hash]);\n }\n\n\n\n /** -- Import / Export -- */\n\n /** Dump perspective as JSON */\n exportPerspective(): string {\n //console.log(\"exportPerspective()\", perspMat);\n const core = this._perspective as ProfilesAltPerspectiveCore; // FIXME: check if this actually works as expected\n return JSON.stringify(core, null, 2);\n }\n\n\n /** */\n async importPerspective(json: string, _canPublish: boolean) {\n const perspective = JSON.parse(json) as ProfilesAltPerspectiveCore;\n // if (canPublish) {\n // for (const [profileAh, [profile, _ts]] of perspective.profiles.entries()) {\n // await this.createProfile(profile, agentId);\n // }\n // return;\n // }\n /** */\n for (const [profileAh, [profile, ts]] of perspective.profiles.entries()) {\n this.storeProfile(profileAh, profile, ts);\n }\n for (const [agentId, profileAh] of perspective.profileByAgent.entries()) {\n this.storeAgentProfile(agentId, profileAh);\n }\n }\n\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,OAAO,EACP,OAAO,EAEP,eAAe,EACf,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,M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AAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAGD,MAAM;IACN,MAAM,CAAC,IAAY,EAAE,WAAoB;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA+B,CAAC;QAC5D,oBAAoB;QACpB,gFAAgF;QAChF,kDAAkD;QAClD,MAAM;QACN,YAAY;QACZ,IAAI;QACJ,MAAM;QACN,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;;AAlJe,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {\n ActionId,\n AgentId,\n EntryId,\n LinkPulseMat,\n StateChangeType,\n ZomeViewModelWithSignals\n} from \"@ddd-qc/lit-happ\";\nimport {Profile} from \"./bindings/profiles.types\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {ProfilesAltProxy} from \"./bindings/profilesAlt.proxy\";\nimport {EntryPulseMat} from \"@ddd-qc/lit-happ/dist/ZomeViewModelWithSignals\";\nimport {ProfilesLinkType} from \"./bindings/profiles.integrity\";\nimport {ProfilesAltUnitEnum} from \"./bindings/profilesAlt.integrity\";\nimport {ProfilesAltPerspective, ProfilesAltPerspectiveCore} from \"./profilesAlt.perspective\";\n\n\n/**\n *\n */\nexport class ProfilesAltZvm extends ZomeViewModelWithSignals {\n\n static readonly ZOME_PROXY = ProfilesAltProxy;\n get zomeProxy(): ProfilesAltProxy {return this._zomeProxy as ProfilesAltProxy;}\n\n\n /* */\n protected hasChanged(): boolean {\n // TODO\n return true;\n }\n\n\n /** */\n async initializePerspectiveOnline(): Promise<void> {\n await this.probeAllProfiles();\n }\n\n /** */\n probeAllInner() {\n this.probeAllProfiles();\n }\n\n /** -- Perspective -- */\n\n /* */\n get perspective(): ProfilesAltPerspective {\n return this._perspective;\n }\n\n private _perspective: ProfilesAltPerspective = new ProfilesAltPerspective();\n\n\n /** -- Getters -- */\n\n getMyProfile(): Profile | undefined {\n return this._perspective.getProfile(this.cell.agentId);\n }\n\n\n\n /** -- Signals -- */\n\n /** */\n async handleLinkPulse(pulse: LinkPulseMat, _from: AgentId): Promise<void> {\n /** */\n switch (pulse.link_type) {\n case ProfilesLinkType.PrefixPath:\n case ProfilesLinkType.PathToAgent: {\n const agentEh = new EntryId(pulse.target.b64);\n const agentId = AgentId.from(agentEh);\n if (pulse.state != StateChangeType.Delete) {\n await this.findProfile(agentId);\n }\n }\n break;\n case ProfilesLinkType.AgentToProfile: {\n const agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash\n const agentId = AgentId.from(agentEh);\n const profileAh = ActionId.from(pulse.target);\n if (pulse.state == StateChangeType.Delete) {\n this._perspective.unstoreAgentProfile(agentId, profileAh)\n } else {\n this._perspective.storeAgentProfile(agentId, profileAh)\n }\n }\n break;\n }\n }\n\n\n /** */\n async handleEntryPulse(pulse: EntryPulseMat, _from: AgentId) {\n switch (pulse.entryType) {\n case ProfilesAltUnitEnum.Profile:\n const profile = decode(pulse.bytes) as Profile;\n if (pulse.state != StateChangeType.Delete) {\n this._perspective.storeProfile(pulse.ah, profile, pulse.ts);\n }\n break;\n }\n }\n\n\n /** -- Methods -- */\n\n /** */\n async probeAllProfiles()/*: Promise<Record<AgentPubKeyB64, ProfileMat>>*/ {\n await this.zomeProxy.probeProfiles();\n }\n\n\n /** */\n async findProfile(agentId: AgentId): Promise<Profile | undefined> {\n const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);\n console.log(\"findProfile()\", agentId, maybeProfilePair);\n if (!maybeProfilePair) {\n return;\n }\n return maybeProfilePair[1];\n }\n\n\n /** */\n async createMyProfile(profile: Profile): Promise<void> {\n const _ah = await this.zomeProxy.createProfile([profile, this.cell.agentId.hash]);\n }\n\n\n /** */\n async updateMyProfile(profile: Profile): Promise<void> {\n const _ah = await this.zomeProxy.updateProfile([profile, this.cell.agentId.hash]);\n }\n\n\n /** */\n async createProfile(profile: Profile, agentId: AgentId): Promise<void> {\n const _ah = await this.zomeProxy.createProfile([profile, agentId.hash]);\n }\n\n\n /** */\n async updateProfile(profile: Profile, agentId: AgentId): Promise<void> {\n const _ah = await this.zomeProxy.updateProfile([profile, agentId.hash]);\n }\n\n\n /** -- Import / Export -- */\n\n /** Dump perspective as JSON */\n export(): string {\n //console.log(\"exportPerspective()\", perspMat);\n const core = this._perspective.makeSnapshot();\n return JSON.stringify(core, null, 2);\n }\n\n\n /** */\n import(json: string, _canPublish: boolean) {\n const core = JSON.parse(json) as ProfilesAltPerspectiveCore;\n // if (canPublish) {\n // for (const [profileAh, [profile, _ts]] of perspective.profiles.entries()) {\n // await this.createProfile(profile, agentId);\n // }\n // return;\n // }\n /** */\n this._perspective.restore(core)\n }\n}\n"]}
|