@ddd-qc/profiles-dvm 0.33.3 → 0.34.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/dist/profiles.zvm.js
CHANGED
|
@@ -19,7 +19,7 @@ export class ProfilesZvm extends ZomeViewModel {
|
|
|
19
19
|
}
|
|
20
20
|
probeAllInner(strategy) {
|
|
21
21
|
this.probeAllProfiles(strategy)
|
|
22
|
-
.then((res) => console.
|
|
22
|
+
.then((res) => console.debug("ProfilesZvm.probeAllProfiles() finished: ", res.length));
|
|
23
23
|
}
|
|
24
24
|
get perspective() {
|
|
25
25
|
const pers = {
|
|
@@ -76,12 +76,12 @@ export class ProfilesZvm extends ZomeViewModel {
|
|
|
76
76
|
}
|
|
77
77
|
async probeProfile(pubKeyB64) {
|
|
78
78
|
const maybeProfile = await this.zomeProxy.getAgentProfile(decodeHashFromBase64(pubKeyB64));
|
|
79
|
-
console.
|
|
79
|
+
console.debug("ProfilesZvm.probeProfile() maybeProfile", maybeProfile);
|
|
80
80
|
if (!maybeProfile) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
const profile = decode(maybeProfile.entry.Present.entry);
|
|
84
|
-
console.log("probeProfile() profile", profile);
|
|
84
|
+
console.log("ProfilesZvm.probeProfile() profile", profile);
|
|
85
85
|
this.storeProfile(pubKeyB64, profile);
|
|
86
86
|
return profile;
|
|
87
87
|
}
|
package/dist/profiles.zvm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.zvm.js","sourceRoot":"","sources":["../src/profiles.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAiB,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,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,GAAG,OAAO,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;QAC7C,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAID,KAAK,CAAC,YAAY,CAAC,SAAyB;QAC1C,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3F,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;QACvE,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAID,MAAM,OAAO,GAAY,MAAM,CAAE,YAAY,CAAC,KAAa,CAAC,OAAO,CAAC,KAAK,CAAY,CAAC;QACtF,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,KAAK,CAAC,eAAe,CAAC,OAAgB;QACjB,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAID,KAAK,CAAC,eAAe,CAAC,OAAgB;QACjB,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC","sourcesContent":["import {ZomeViewModel} from \"@ddd-qc/lit-happ\";\nimport {Profile} from \"./bindings/profiles.types\";\nimport {AgentPubKeyB64, decodeHashFromBase64, encodeHashToBase64} from \"@holochain/client\";\nimport {ProfilesProxy} from \"./bindings/profiles.proxy\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {GetStrategy} from \"@holochain-open-dev/core-types\";\n\n\n/** */\nexport type ProfilesPerspective = {\n /* AgentPubKeyB64 -> Profile */\n profiles: Record<AgentPubKeyB64, Profile>,\n ///* AgentPubKeyB64 -> Profile hash */\n //profile_ahs: Record<AgentPubKeyB64, ActionHashB64>,\n\n /** Nickname -> AgentPubKeyB64 */\n reversed: Record<string, AgentPubKeyB64>,\n}\n\n\n/**\n *\n */\nexport class ProfilesZvm extends ZomeViewModel {\n\n static override readonly ZOME_PROXY = ProfilesProxy;\n get zomeProxy(): ProfilesProxy {return this._zomeProxy as ProfilesProxy;}\n\n\n /** */\n override async initializePerspectiveFromLocal(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Local);\n }\n\n /** */\n override async initializePerspectiveFromNetwork(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Network);\n }\n\n /** */\n override probeAllInner(strategy: GetStrategy) {\n this.probeAllProfiles(strategy)\n .then((res) => console.debug(\"ProfilesZvm.probeAllProfiles() finished: \", res.length))\n }\n\n /** -- Perspective -- */\n\n /* */\n get perspective(): ProfilesPerspective {\n const pers: ProfilesPerspective = {\n profiles: this._profiles,\n reversed: this._reversed,\n //profile_ahs: this._profile_ahs,\n };\n return pers;\n }\n\n private _profiles: Record<AgentPubKeyB64, Profile> = {};\n //private _profile_ahs: Record<AgentPubKeyB64, ActionHashB64> = {};\n private _reversed: Record<string, AgentPubKeyB64> = {};\n\n\n getMyProfile(): Profile | undefined { return this._profiles[this.cell.address.agentId.b64] }\n\n getProfile(agent: AgentPubKeyB64): Profile | undefined {return this._profiles[agent]}\n\n //getProfileHash(agent: AgentPubKeyB64): ActionHashB64 | undefined {return this._profile_ahs[agent]}\n\n getAgents(): AgentPubKeyB64[] { return Object.keys(this._profiles)}\n\n getNames(): string[] { return Object.keys(this._reversed)}\n\n\n /** Dump perspective as JSON */\n exportPerspective(): string {\n //console.log(\"exportPerspective()\", perspMat);\n return JSON.stringify(this._profiles, null, 2);\n }\n\n\n /** */\n importPerspective(json: string, _mapping?: Object) {\n const profiles = JSON.parse(json) as Record<AgentPubKeyB64, Profile>;\n for (const [pubKey, profileMat] of Object.entries(profiles)) {\n this.storeProfile(pubKey, profileMat);\n }\n }\n\n /** -- Methods -- */\n\n /* */\n findProfiles(names: string[]): AgentPubKeyB64[] {\n let res: AgentPubKeyB64[] = []\n for (const name of names) {\n if (this._reversed[name]) {\n res.push(this._reversed[name]!)\n }\n }\n return res;\n }\n\n\n /** */\n async probeAllProfiles(_strategy: GetStrategy): Promise<Record<AgentPubKeyB64, Profile>> {\n let allAgents;\n /** Attempt a retry on fail as this can create an entry (path anchor) and generate a 'head has moved' error */\n try {\n allAgents = await this.zomeProxy.getAgentsWithProfile();\n } catch(e) {\n allAgents = await this.zomeProxy.getAgentsWithProfile();\n }\n for (const agentPubKey of allAgents) {\n const maybeProfile = await this.zomeProxy.getAgentProfile(agentPubKey);\n if (!maybeProfile) {\n continue;\n }\n const profile: Profile = decode((maybeProfile.entry as any).Present.entry) as Profile;\n this.storeProfile(encodeHashToBase64(agentPubKey), profile);\n }\n this.notifySubscribers();\n return this._profiles;\n }\n\n\n /** */\n storeProfile(pubKeyB64: AgentPubKeyB64, profile: Profile) {\n this._profiles[pubKeyB64] = profile;\n this._reversed[profile.nickname] = pubKeyB64;\n this.notifySubscribers();\n }\n\n\n /** */\n async probeProfile(pubKeyB64: AgentPubKeyB64): Promise<Profile | undefined> {\n const maybeProfile = await this.zomeProxy.getAgentProfile(decodeHashFromBase64(pubKeyB64));\n console.debug(\"ProfilesZvm.probeProfile() maybeProfile\", maybeProfile);\n if (!maybeProfile) {\n return;\n }\n // const profileEntry: any = decode((maybeProfile.entry as any).Present.entry);\n // console.log(\"probeProfile() profileEntry\", profileEntry);\n //const profile: Profile = decode(profileEntry.record.entry.Present.entry) as Profile;\n const profile: Profile = decode((maybeProfile.entry as any).Present.entry) as Profile;\n console.log(\"ProfilesZvm.probeProfile() profile\", profile);\n this.storeProfile(pubKeyB64, profile);\n return profile;\n }\n\n\n /** */\n async createMyProfile(profile: Profile): Promise<void> {\n /*const record =*/ await this.zomeProxy.createProfile(profile);\n this.storeProfile(this.cell.address.agentId.b64, profile);\n }\n\n\n /** */\n async updateMyProfile(profile: Profile): Promise<void> {\n /*const record =*/ await this.zomeProxy.updateProfile(profile);\n this.storeProfile(this.cell.address.agentId.b64, profile);\n }\n\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profilesAlt.zvm.d.ts","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EAGP,YAAY,EAEZ,wBAAwB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAElD,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,aAAa,EAAC,MAAM,gDAAgD,CAAC;AAG7E,OAAO,EAEH,sBAAsB,EAGzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAC,WAAW,EAAC,MAAM,gCAAgC,CAAC;AAM3D,qBAAa,cAAe,SAAQ,wBAAwB;IAI1D,gBAAyB,UAAU,0BAAoB;IACvD,IAAI,SAAS,IAAI,gBAAgB,CAA8C;IAItE,UAAU,IAAI,MAAM;IASpB,UAAU,IAAI,OAAO;IAYf,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC;IAK/C,gCAAgC,IAAI,OAAO,CAAC,IAAI,CAAC;IAMvD,aAAa,CAAC,QAAQ,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"profilesAlt.zvm.d.ts","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EAGP,YAAY,EAEZ,wBAAwB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO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AC;IAQtE,MAAM,IAAI,MAAM;IAOhB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;CAoBzC"}
|
package/dist/profilesAlt.zvm.js
CHANGED
|
@@ -41,7 +41,8 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
41
41
|
await this.probeAllProfiles(GetStrategy.Network);
|
|
42
42
|
}
|
|
43
43
|
probeAllInner(strategy) {
|
|
44
|
-
this.probeAllProfiles(strategy)
|
|
44
|
+
this.probeAllProfiles(strategy)
|
|
45
|
+
.then(() => console.debug("ProfilesAltZvm.probeAllProfiles() finished."));
|
|
45
46
|
}
|
|
46
47
|
get perspective() {
|
|
47
48
|
return this._perspective.readonly;
|
|
@@ -95,14 +96,13 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
95
96
|
async findProfile(agentId) {
|
|
96
97
|
try {
|
|
97
98
|
const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);
|
|
98
|
-
console.
|
|
99
|
+
console.debug("ProfilesAltZvm.findProfile()", agentId, maybeProfilePair);
|
|
99
100
|
if (!maybeProfilePair) {
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
return maybeProfilePair[1];
|
|
103
104
|
}
|
|
104
105
|
catch (e) {
|
|
105
|
-
return undefined;
|
|
106
106
|
}
|
|
107
107
|
return undefined;
|
|
108
108
|
}
|
|
@@ -126,7 +126,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
|
|
|
126
126
|
const snapshot = JSON.parse(json, holoIdReviver);
|
|
127
127
|
if (canPublish) {
|
|
128
128
|
for (const [agentId, _profileAh, profile, _ts] of snapshot.all) {
|
|
129
|
-
console.
|
|
129
|
+
console.debug("ProfilesAltZvm.import() publish profile", agentId.short, profile.nickname);
|
|
130
130
|
const maybe = this._perspective.getProfile(agentId);
|
|
131
131
|
if (maybe) {
|
|
132
132
|
this.createProfile(profile, agentId);
|
|
@@ -1 +1 @@
|
|
|
1
|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OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAID,MAAM,CAAC,IAAY,EAAE,UAAmB;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAwB,CAAC;QACxE,IAAI,UAAU,EAAE;YACd,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,EAAE;gBAC9D,OAAO,CAAC,GAAG,CAAC,yCAAyC,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACxF,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACpD,IAAI,KAAK,EAAE;oBACC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;iBAChD;qBAAM;oBACL,IAAI,KAAK,IAAI,OAAO,EAAE;wBACpB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;qBACtC;iBACF;aACF;YACD,OAAO;SACR;QAED,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC","sourcesContent":["import {\n ActionId,\n AgentId,\n EntryId,\n holoIdReviver,\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 {\n ProfilesAltComparable,\n ProfilesAltPerspective,\n ProfilesAltPerspectiveMutable,\n ProfilesAltSnapshot\n} from \"./profilesAlt.perspective\";\nimport {GetStrategy} from \"@holochain-open-dev/core-types\";\n\n\n/**\n *\n */\nexport class ProfilesAltZvm extends ZomeViewModelWithSignals {\n\n /** -- Concret -- */\n\n static override readonly ZOME_PROXY = ProfilesAltProxy;\n get zomeProxy(): ProfilesAltProxy {return this._zomeProxy as ProfilesAltProxy;}\n\n\n /** */\n override comparable(): Object {\n const res: ProfilesAltComparable = {\n profileCount: this._perspective.profileByAgent.size,\n profiles: Array.from(this.perspective.profiles.values()).map((pair) => pair[0]),\n };\n return res;\n }\n\n /* */\n override hasChanged(): boolean {\n const current = this.comparable() as ProfilesAltComparable;\n const prev = this._previousPerspective as ProfilesAltComparable;\n if (!prev) { return true }\n if (current.profileCount != prev.profileCount) return true;\n for (let i = 0; i < current.profileCount; i+= 1) {\n if (JSON.stringify(current.profiles[i]) != JSON.stringify(prev.profiles[i])) { return true }\n }\n return false;\n }\n\n /** */\n override async initializePerspectiveFromLocal(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Local);\n }\n\n /** */\n override async initializePerspectiveFromNetwork(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Network);\n }\n\n\n /** */\n override probeAllInner(strategy: GetStrategy) {\n this.probeAllProfiles(strategy);\n }\n\n\n /* */\n get perspective(): ProfilesAltPerspective {\n return this._perspective.readonly;\n }\n\n\n /** -- */\n\n private _perspective: ProfilesAltPerspectiveMutable = new ProfilesAltPerspectiveMutable();\n\n\n /** -- Getters -- */\n\n getMyProfile(): Profile | undefined {\n return this._perspective.getProfile(this.cell.address.agentId);\n }\n\n\n\n /** -- Signals -- */\n\n /** */\n override async handleLinkPulse(pulse: LinkPulseMat, _from: AgentId): Promise<void> {\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 it's 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 override 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(strategy: GetStrategy)/*: Promise<Record<AgentPubKeyB64, ProfileMat>>*/ {\n try {\n await this.zomeProxy.probeProfiles(strategy);\n } catch(e) {}\n }\n\n\n /** */\n async findProfile(agentId: AgentId): Promise<Profile | undefined> {\n try {\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 } catch(e) {\n return undefined;\n }\n return undefined;\n }\n\n\n /** */\n async createMyProfile(profile: Profile): Promise<void> {\n await this.zomeProxy.createProfile([profile, this.cell.address.agentId.hash]);\n }\n\n\n /** */\n async updateMyProfile(profile: Profile): Promise<void> {\n await this.zomeProxy.updateProfile([profile, this.cell.address.agentId.hash]);\n }\n\n\n /** */\n async createProfile(profile: Profile, agentId: AgentId): Promise<void> {\n await this.zomeProxy.createProfile([profile, agentId.hash]);\n }\n\n\n /** */\n async updateProfile(profile: Profile, agentId: AgentId): Promise<void> {\n await this.zomeProxy.updateProfile([profile, agentId.hash]);\n }\n\n\n /** -- Import / Export -- */\n\n /** Dump perspective as JSON */\n export(): string {\n const snapshot = this._perspective.makeSnapshot();\n return JSON.stringify(snapshot, null, 2);\n }\n\n\n /** */\n import(json: string, canPublish: boolean) {\n const snapshot = JSON.parse(json, holoIdReviver) as ProfilesAltSnapshot;\n if (canPublish) {\n for (const [agentId, _profileAh, profile, _ts] of snapshot.all) {\n console.log(\"ProfilesAltZvm.import() publish profile\", agentId.short, profile.nickname);\n const maybe = this._perspective.getProfile(agentId);\n if (maybe) {\n /*await*/ this.createProfile(profile, agentId);\n } else {\n if (maybe != profile) {\n this.updateProfile(profile, agentId);\n }\n }\n }\n return;\n }\n /** */\n this._perspective.restore(snapshot);\n this.notifySubscribers();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,OAAO,EACP,OAAO,EACP,aAAa,EAEb,eAAe,EACf,wBAAwB,EAC3B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAGH,6BAA6B,EAEhC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAC,WAAW,EAAC,MAAM,gCAAgC,CAAC;AAM3D,MAAM,OAAO,cAAe,SAAQ,wBAAwB;IAA5D;;QAuDU,iBAAY,GAAkC,IAAI,6BAA6B,EAAE,CAAC;IAqI5F,CAAC;aAxL0B,eAAU,GAAG,gBAAgB,AAAnB,CAAoB;IACvD,IAAI,SAAS,KAAsB,OAAO,IAAI,CAAC,UAA8B,CAAC,CAAA,CAAC;IAItE,UAAU;QACjB,MAAM,GAAG,GAA0B;YACjC,YAAY,EAAE,IAAI,CAAC,YAAY,CA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AED,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC","sourcesContent":["import {\n ActionId,\n AgentId,\n EntryId,\n holoIdReviver,\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 {\n ProfilesAltComparable,\n ProfilesAltPerspective,\n ProfilesAltPerspectiveMutable,\n ProfilesAltSnapshot\n} from \"./profilesAlt.perspective\";\nimport {GetStrategy} from \"@holochain-open-dev/core-types\";\n\n\n/**\n *\n */\nexport class ProfilesAltZvm extends ZomeViewModelWithSignals {\n\n /** -- Concrete -- */\n\n static override readonly ZOME_PROXY = ProfilesAltProxy;\n get zomeProxy(): ProfilesAltProxy {return this._zomeProxy as ProfilesAltProxy;}\n\n\n /** */\n override comparable(): Object {\n const res: ProfilesAltComparable = {\n profileCount: this._perspective.profileByAgent.size,\n profiles: Array.from(this.perspective.profiles.values()).map((pair) => (pair as [Profile, Number])[0]),\n };\n return res;\n }\n\n /* */\n override hasChanged(): boolean {\n const current = this.comparable() as ProfilesAltComparable;\n const prev = this._previousPerspective as ProfilesAltComparable;\n if (!prev) { return true }\n if (current.profileCount != prev.profileCount) return true;\n for (let i = 0; i < current.profileCount; i+= 1) {\n if (JSON.stringify(current.profiles[i]) != JSON.stringify(prev.profiles[i])) { return true }\n }\n return false;\n }\n\n /** */\n override async initializePerspectiveFromLocal(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Local);\n }\n\n /** */\n override async initializePerspectiveFromNetwork(): Promise<void> {\n await this.probeAllProfiles(GetStrategy.Network);\n }\n\n\n /** */\n override probeAllInner(strategy: GetStrategy) {\n this.probeAllProfiles(strategy)\n .then(() => console.debug(\"ProfilesAltZvm.probeAllProfiles() finished.\"))\n }\n\n\n /* */\n get perspective(): ProfilesAltPerspective {\n return this._perspective.readonly;\n }\n\n\n /** -- */\n\n private _perspective: ProfilesAltPerspectiveMutable = new ProfilesAltPerspectiveMutable();\n\n\n /** -- Getters -- */\n\n getMyProfile(): Profile | undefined {\n return this._perspective.getProfile(this.cell.address.agentId);\n }\n\n\n\n /** -- Signals -- */\n\n /** */\n override async handleLinkPulse(pulse: LinkPulseMat, _from: AgentId): Promise<void> {\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 it's 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 override 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(strategy: GetStrategy)/*: Promise<Record<AgentPubKeyB64, ProfileMat>>*/ {\n try {\n await this.zomeProxy.probeProfiles(strategy);\n } catch(e) {}\n }\n\n\n /** */\n async findProfile(agentId: AgentId): Promise<Profile | undefined> {\n try {\n const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);\n console.debug(\"ProfilesAltZvm.findProfile()\", agentId, maybeProfilePair);\n if (!maybeProfilePair) {\n return;\n }\n return maybeProfilePair[1];\n } catch(e) {\n //return undefined;\n }\n return undefined;\n }\n\n\n /** */\n async createMyProfile(profile: Profile): Promise<void> {\n await this.zomeProxy.createProfile([profile, this.cell.address.agentId.hash]);\n }\n\n\n /** */\n async updateMyProfile(profile: Profile): Promise<void> {\n await this.zomeProxy.updateProfile([profile, this.cell.address.agentId.hash]);\n }\n\n\n /** */\n async createProfile(profile: Profile, agentId: AgentId): Promise<void> {\n await this.zomeProxy.createProfile([profile, agentId.hash]);\n }\n\n\n /** */\n async updateProfile(profile: Profile, agentId: AgentId): Promise<void> {\n await this.zomeProxy.updateProfile([profile, agentId.hash]);\n }\n\n\n /** -- Import / Export -- */\n\n /** Dump perspective as JSON */\n export(): string {\n const snapshot = this._perspective.makeSnapshot();\n return JSON.stringify(snapshot, null, 2);\n }\n\n\n /** */\n import(json: string, canPublish: boolean) {\n const snapshot = JSON.parse(json, holoIdReviver) as ProfilesAltSnapshot;\n if (canPublish) {\n for (const [agentId, _profileAh, profile, _ts] of snapshot.all) {\n console.debug(\"ProfilesAltZvm.import() publish profile\", agentId.short, profile.nickname);\n const maybe = this._perspective.getProfile(agentId);\n if (maybe) {\n /*await*/ this.createProfile(profile, agentId);\n } else {\n if (maybe != profile) {\n this.updateProfile(profile, agentId);\n }\n }\n }\n return;\n }\n /** */\n this._perspective.restore(snapshot);\n this.notifySubscribers();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-qc/profiles-dvm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "DnaViewModel implementation for the Profiles zome.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"homepage": "https://github.com/ddd-mtl/lit-happ/blob/main/dvms/profiles/",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^20.8.9",
|
|
29
|
-
"tslib": "^2.
|
|
29
|
+
"tslib": "^2.8",
|
|
30
30
|
"typescript": "~5.2.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@holochain/client": "
|
|
33
|
+
"@holochain/client": "=0.20.2",
|
|
34
34
|
"@ddd-qc/lit-happ": "file:../lit-happ",
|
|
35
|
-
"@holochain-open-dev/elements": "^0.600.0
|
|
35
|
+
"@holochain-open-dev/elements": "^0.600.0",
|
|
36
36
|
"@msgpack/msgpack": "^3.1.1",
|
|
37
37
|
"lit": "3.0.2"
|
|
38
38
|
},
|