@ddd-qc/profiles-dvm 0.23.1 → 0.23.3

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.
@@ -1,10 +1,11 @@
1
1
  import { ZomeViewModel } from "@ddd-qc/lit-happ";
2
2
  import { Profile as ProfileMat } from "./bindings/profiles.types";
3
- import { AgentPubKeyB64 } from "@holochain/client";
3
+ import { AgentPubKeyB64, Timestamp } from "@holochain/client";
4
4
  import { ProfilesAltProxy } from "./bindings/profilesAlt.proxy";
5
5
  /** */
6
6
  export interface ProfilesAltPerspective {
7
7
  profiles: Record<AgentPubKeyB64, ProfileMat>;
8
+ profileDates: Record<AgentPubKeyB64, Timestamp>;
8
9
  /** Nickname -> AgentPubKeyB64 */
9
10
  reversed: Record<string, AgentPubKeyB64>;
10
11
  }
@@ -22,9 +23,11 @@ export declare class ProfilesAltZvm extends ZomeViewModel {
22
23
  /** -- Perspective -- */
23
24
  get perspective(): ProfilesAltPerspective;
24
25
  private _profiles;
26
+ private _profileDates;
25
27
  private _reversed;
26
28
  getMyProfile(): ProfileMat | undefined;
27
29
  getProfile(agent: AgentPubKeyB64): ProfileMat | undefined;
30
+ getProfileDate(agent: AgentPubKeyB64): Timestamp | undefined;
28
31
  getAgents(): AgentPubKeyB64[];
29
32
  getNames(): string[];
30
33
  /** Dump perspective as JSON */
@@ -36,7 +39,7 @@ export declare class ProfilesAltZvm extends ZomeViewModel {
36
39
  /** */
37
40
  probeAllProfiles(): Promise<Record<AgentPubKeyB64, ProfileMat>>;
38
41
  /** */
39
- storeProfile(pubKeyB64: AgentPubKeyB64, profile: ProfileMat): void;
42
+ storeProfile(pubKeyB64: AgentPubKeyB64, profile: ProfileMat, ts: Timestamp): void;
40
43
  /** */
41
44
  probeProfile(pubKeyB64: AgentPubKeyB64): Promise<ProfileMat | undefined>;
42
45
  /** */
@@ -9,6 +9,7 @@ export class ProfilesAltZvm extends ZomeViewModel {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this._profiles = {};
12
+ this._profileDates = {};
12
13
  //private _profile_ahs: Record<AgentPubKeyB64, ActionHashB64> = {};
13
14
  this._reversed = {};
14
15
  }
@@ -31,12 +32,14 @@ export class ProfilesAltZvm extends ZomeViewModel {
31
32
  get perspective() {
32
33
  return {
33
34
  profiles: this._profiles,
35
+ profileDates: this._profileDates,
34
36
  reversed: this._reversed,
35
37
  //profile_ahs: this._profile_ahs,
36
38
  };
37
39
  }
38
40
  getMyProfile() { return this._profiles[this.cell.agentPubKey]; }
39
41
  getProfile(agent) { return this._profiles[agent]; }
42
+ getProfileDate(agent) { return this._profileDates[agent]; }
40
43
  //getProfileHash(agent: AgentPubKeyB64): ActionHashB64 | undefined {return this._profile_ahs[agent]}
41
44
  getAgents() { return Object.keys(this._profiles); }
42
45
  getNames() { return Object.keys(this._reversed); }
@@ -44,6 +47,7 @@ export class ProfilesAltZvm extends ZomeViewModel {
44
47
  exportPerspective() {
45
48
  //console.log("exportPerspective()", perspMat);
46
49
  return JSON.stringify(this._profiles, null, 2);
50
+ //return JSON.stringify(this.perspective, null, 2);
47
51
  }
48
52
  /** */
49
53
  async importPerspective(json, canPublish) {
@@ -55,7 +59,7 @@ export class ProfilesAltZvm extends ZomeViewModel {
55
59
  return;
56
60
  }
57
61
  for (const [pubKey, profileMat] of Object.entries(profiles)) {
58
- this.storeProfile(pubKey, profileMat);
62
+ this.storeProfile(pubKey, profileMat, Date.now());
59
63
  }
60
64
  }
61
65
  /** -- Methods -- */
@@ -80,56 +84,63 @@ export class ProfilesAltZvm extends ZomeViewModel {
80
84
  allAgents = await this.zomeProxy.getAgentsWithProfile();
81
85
  }
82
86
  for (const agentPubKey of allAgents) {
83
- const maybeProfile = await this.zomeProxy.getProfile(agentPubKey);
84
- if (!maybeProfile) {
87
+ const maybeProfileRecord = await this.zomeProxy.getProfile(agentPubKey);
88
+ if (!maybeProfileRecord) {
85
89
  continue;
86
90
  }
87
- const profile = decode(maybeProfile.entry.Present.entry);
88
- this.storeProfile(encodeHashToBase64(agentPubKey), profile);
91
+ const timestamp = maybeProfileRecord.signed_action.hashed.content.timestamp;
92
+ const profile = decode(maybeProfileRecord.entry.Present.entry);
93
+ this.storeProfile(encodeHashToBase64(agentPubKey), profile, timestamp);
89
94
  }
90
95
  this.notifySubscribers();
91
96
  return this._profiles;
92
97
  }
93
98
  /** */
94
- storeProfile(pubKeyB64, profile) {
99
+ storeProfile(pubKeyB64, profile, ts) {
95
100
  this._profiles[pubKeyB64] = profile;
101
+ this._profileDates[pubKeyB64] = ts;
96
102
  this._reversed[profile.nickname] = pubKeyB64;
97
103
  this.notifySubscribers();
98
104
  }
99
105
  /** */
100
106
  async probeProfile(pubKeyB64) {
101
- const maybeProfile = await this.zomeProxy.getProfile(decodeHashFromBase64(pubKeyB64));
102
- console.log("probeProfile() maybeProfile", maybeProfile);
103
- if (!maybeProfile) {
107
+ const maybeProfileRecord = await this.zomeProxy.getProfile(decodeHashFromBase64(pubKeyB64));
108
+ console.log("probeProfile() maybeProfile", maybeProfileRecord);
109
+ if (!maybeProfileRecord) {
104
110
  return;
105
111
  }
106
112
  // const profileEntry: any = decode((maybeProfile.entry as any).Present.entry);
107
113
  // console.log("probeProfile() profileEntry", profileEntry);
108
114
  //const profile: ProfileMat = decode(profileEntry.record.entry.Present.entry) as ProfileMat;
109
- const profile = decode(maybeProfile.entry.Present.entry);
115
+ const timestamp = maybeProfileRecord.signed_action.hashed.content.timestamp;
116
+ const profile = decode(maybeProfileRecord.entry.Present.entry);
110
117
  console.log("probeProfile() profile", profile);
111
- this.storeProfile(pubKeyB64, profile);
118
+ this.storeProfile(pubKeyB64, profile, timestamp);
112
119
  return profile;
113
120
  }
114
121
  /** */
115
122
  async createMyProfile(profile) {
116
- /*const record =*/ await this.zomeProxy.createProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);
117
- this.storeProfile(this.cell.agentPubKey, profile);
123
+ const record = await this.zomeProxy.createProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);
124
+ const timestamp = record.signed_action.hashed.content.timestamp;
125
+ this.storeProfile(this.cell.agentPubKey, profile, timestamp);
118
126
  }
119
127
  /** */
120
128
  async updateMyProfile(profile) {
121
- /*const record =*/ await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);
122
- this.storeProfile(this.cell.agentPubKey, profile);
129
+ const record = await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);
130
+ const timestamp = record.signed_action.hashed.content.timestamp;
131
+ this.storeProfile(this.cell.agentPubKey, profile, timestamp);
123
132
  }
124
133
  /** */
125
134
  async createProfile(profile, agent) {
126
- /*const record =*/ await this.zomeProxy.createProfile([profile, decodeHashFromBase64(agent)]);
127
- this.storeProfile(agent, profile);
135
+ const record = await this.zomeProxy.createProfile([profile, decodeHashFromBase64(agent)]);
136
+ const timestamp = record.signed_action.hashed.content.timestamp;
137
+ this.storeProfile(agent, profile, timestamp);
128
138
  }
129
139
  /** */
130
140
  async updateProfile(profile, agent) {
131
- /*const record =*/ await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(agent)]);
132
- this.storeProfile(agent, profile);
141
+ const record = await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(agent)]);
142
+ const timestamp = record.signed_action.hashed.content.timestamp;
143
+ this.storeProfile(agent, profile, timestamp);
133
144
  }
134
145
  }
135
146
  ProfilesAltZvm.ZOME_PROXY = ProfilesAltProxy;
@@ -1 +1 @@
1
- {"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.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,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAe9D;;GAEG;AACH,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,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,eAAe,CAAC,OAAmB;QACvC,kBAAkB,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC9G,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,aAAa,CAAC,OAAmB,EAAE,KAAqB;QAC5D,kBAAkB,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9F,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,aAAa,CAAC,OAAmB,EAAE,KAAqB;QAC5D,kBAAkB,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9F,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;;AA9Je,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {ZomeViewModel} from \"@ddd-qc/lit-happ\";\nimport {Profile as ProfileMat} from \"./bindings/profiles.types\";\nimport {AgentPubKeyB64, decodeHashFromBase64, encodeHashToBase64} from \"@holochain/client\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {ProfilesAltProxy} from \"./bindings/profilesAlt.proxy\";\n\n\n/** */\nexport interface ProfilesAltPerspective {\n /* AgentPubKeyB64 -> Profile */\n profiles: Record<AgentPubKeyB64, ProfileMat>,\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 ProfilesAltZvm extends ZomeViewModel {\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 {\n profiles: this._profiles,\n reversed: this._reversed,\n //profile_ahs: this._profile_ahs,\n };\n }\n\n private _profiles: Record<AgentPubKeyB64, ProfileMat> = {};\n //private _profile_ahs: Record<AgentPubKeyB64, ActionHashB64> = {};\n private _reversed: Record<string, AgentPubKeyB64> = {};\n\n\n getMyProfile(): ProfileMat | undefined { return this._profiles[this.cell.agentPubKey] }\n\n getProfile(agent: AgentPubKeyB64): ProfileMat | 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 async importPerspective(json: string, canPublish: boolean) {\n const profiles = JSON.parse(json) as Record<AgentPubKeyB64, ProfileMat>;\n\n if (canPublish) {\n for (const [pubKey, profileMat] of Object.entries(profiles)) {\n await this.createProfile(profileMat, pubKey);\n }\n return;\n }\n\n for (const [pubKey, profileMat] of Object.entries(profiles)) {\n this.storeProfile(pubKey, profileMat);\n }\n }\n\n\n /** -- Methods -- */\n\n /* */\n findProfiles(names: string[]): AgentPubKeyB64[] {\n let res = []\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(): Promise<Record<AgentPubKeyB64, ProfileMat>> {\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.getProfile(agentPubKey);\n if (!maybeProfile) {\n continue;\n }\n const profile: ProfileMat = decode((maybeProfile.entry as any).Present.entry) as ProfileMat;\n this.storeProfile(encodeHashToBase64(agentPubKey), profile);\n }\n this.notifySubscribers();\n return this._profiles;\n }\n\n\n /** */\n storeProfile(pubKeyB64: AgentPubKeyB64, profile: ProfileMat) {\n this._profiles[pubKeyB64] = profile;\n this._reversed[profile.nickname] = pubKeyB64;\n this.notifySubscribers();\n }\n\n\n /** */\n async probeProfile(pubKeyB64: AgentPubKeyB64): Promise<ProfileMat | undefined> {\n const maybeProfile = await this.zomeProxy.getProfile(decodeHashFromBase64(pubKeyB64));\n console.log(\"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: ProfileMat = decode(profileEntry.record.entry.Present.entry) as ProfileMat;\n const profile: ProfileMat = decode((maybeProfile.entry as any).Present.entry) as ProfileMat;\n console.log(\"probeProfile() profile\", profile);\n this.storeProfile(pubKeyB64, profile);\n return profile;\n }\n\n\n /** */\n async createMyProfile(profile: ProfileMat): Promise<void> {\n /*const record =*/ await this.zomeProxy.createProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);\n this.storeProfile(this.cell.agentPubKey, profile);\n }\n\n\n /** */\n async updateMyProfile(profile: ProfileMat): Promise<void> {\n /*const record =*/ await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);\n this.storeProfile(this.cell.agentPubKey, profile);\n }\n\n\n /** */\n async createProfile(profile: ProfileMat, agent: AgentPubKeyB64): Promise<void> {\n /*const record =*/ await this.zomeProxy.createProfile([profile, decodeHashFromBase64(agent)]);\n this.storeProfile(agent, profile);\n }\n\n\n /** */\n async updateProfile(profile: ProfileMat, agent: AgentPubKeyB64): Promise<void> {\n /*const record =*/ await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(agent)]);\n this.storeProfile(agent, profile);\n }\n\n}\n"]}
1
+ {"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAiB,oBAAoB,EAAE,kBAAkB,EAAY,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAgB9D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,aAAa;IAAjD;;QAmCU,cAAS,GAAuC,EAAE,CAAC;QACnD,kBAAa,GAAsC,EAAE,CAAC;QAC9D,mEAAmE;QAC3D,cAAS,GAAmC,EAAE,CAAC;IAuIzD,CAAC;IA1KC,IAAI,SAAS,KAAsB,OAAO,IAAI,CAAC,UAA8B,CAAC,CAAA,CAAC;IAG/E,KAAK;IACK,UAAU;QAClB,OAAO;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,2BAA2B;QAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAChC,CAAC;IAED,MAAM;IACN,aAAa;QACX,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,wBAAwB;IAExB,KAAK;IAC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K,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;;AAzKe,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {ZomeViewModel} from \"@ddd-qc/lit-happ\";\nimport {Profile as ProfileMat} from \"./bindings/profiles.types\";\nimport {AgentPubKeyB64, decodeHashFromBase64, encodeHashToBase64, Timestamp} from \"@holochain/client\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {ProfilesAltProxy} from \"./bindings/profilesAlt.proxy\";\n\n\n/** */\nexport interface ProfilesAltPerspective {\n /* AgentPubKeyB64 -> Profile */\n profiles: Record<AgentPubKeyB64, ProfileMat>,\n profileDates: Record<AgentPubKeyB64, Timestamp>,\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 ProfilesAltZvm extends ZomeViewModel {\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 {\n profiles: this._profiles,\n profileDates: this._profileDates,\n reversed: this._reversed,\n //profile_ahs: this._profile_ahs,\n };\n }\n\n private _profiles: Record<AgentPubKeyB64, ProfileMat> = {};\n private _profileDates: Record<AgentPubKeyB64, Timestamp> = {};\n //private _profile_ahs: Record<AgentPubKeyB64, ActionHashB64> = {};\n private _reversed: Record<string, AgentPubKeyB64> = {};\n\n\n getMyProfile(): ProfileMat | undefined { return this._profiles[this.cell.agentPubKey] }\n\n getProfile(agent: AgentPubKeyB64): ProfileMat | undefined {return this._profiles[agent]}\n\n getProfileDate(agent: AgentPubKeyB64): Timestamp | undefined {return this._profileDates[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 //return JSON.stringify(this.perspective, null, 2);\n }\n\n\n /** */\n async importPerspective(json: string, canPublish: boolean) {\n const profiles = JSON.parse(json) as ProfilesAltPerspective;\n if (canPublish) {\n for (const [pubKey, profileMat] of Object.entries(profiles)) {\n await this.createProfile(profileMat, pubKey);\n }\n return;\n }\n\n for (const [pubKey, profileMat] of Object.entries(profiles)) {\n this.storeProfile(pubKey, profileMat, Date.now());\n }\n }\n\n\n /** -- Methods -- */\n\n /* */\n findProfiles(names: string[]): AgentPubKeyB64[] {\n let res = []\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(): Promise<Record<AgentPubKeyB64, ProfileMat>> {\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 maybeProfileRecord = await this.zomeProxy.getProfile(agentPubKey);\n if (!maybeProfileRecord) {\n continue;\n }\n const timestamp = maybeProfileRecord.signed_action.hashed.content.timestamp;\n const profile: ProfileMat = decode((maybeProfileRecord.entry as any).Present.entry) as ProfileMat;\n this.storeProfile(encodeHashToBase64(agentPubKey), profile, timestamp);\n }\n this.notifySubscribers();\n return this._profiles;\n }\n\n\n /** */\n storeProfile(pubKeyB64: AgentPubKeyB64, profile: ProfileMat, ts: Timestamp) {\n this._profiles[pubKeyB64] = profile;\n this._profileDates[pubKeyB64] = ts;\n this._reversed[profile.nickname] = pubKeyB64;\n this.notifySubscribers();\n }\n\n\n /** */\n async probeProfile(pubKeyB64: AgentPubKeyB64): Promise<ProfileMat | undefined> {\n const maybeProfileRecord = await this.zomeProxy.getProfile(decodeHashFromBase64(pubKeyB64));\n console.log(\"probeProfile() maybeProfile\", maybeProfileRecord);\n if (!maybeProfileRecord) {\n return;\n }\n // const profileEntry: any = decode((maybeProfile.entry as any).Present.entry);\n // console.log(\"probeProfile() profileEntry\", profileEntry);\n //const profile: ProfileMat = decode(profileEntry.record.entry.Present.entry) as ProfileMat;\n const timestamp = maybeProfileRecord.signed_action.hashed.content.timestamp;\n const profile: ProfileMat = decode((maybeProfileRecord.entry as any).Present.entry) as ProfileMat;\n console.log(\"probeProfile() profile\", profile);\n this.storeProfile(pubKeyB64, profile, timestamp);\n return profile;\n }\n\n\n /** */\n async createMyProfile(profile: ProfileMat): Promise<void> {\n const record = await this.zomeProxy.createProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);\n const timestamp = record.signed_action.hashed.content.timestamp;\n this.storeProfile(this.cell.agentPubKey, profile, timestamp);\n }\n\n\n /** */\n async updateMyProfile(profile: ProfileMat): Promise<void> {\n const record = await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(this.cell.agentPubKey)]);\n const timestamp = record.signed_action.hashed.content.timestamp;\n this.storeProfile(this.cell.agentPubKey, profile, timestamp);\n }\n\n\n /** */\n async createProfile(profile: ProfileMat, agent: AgentPubKeyB64): Promise<void> {\n const record = await this.zomeProxy.createProfile([profile, decodeHashFromBase64(agent)]);\n const timestamp = record.signed_action.hashed.content.timestamp;\n this.storeProfile(agent, profile, timestamp);\n }\n\n\n /** */\n async updateProfile(profile: ProfileMat, agent: AgentPubKeyB64): Promise<void> {\n const record = await this.zomeProxy.updateProfile([profile, decodeHashFromBase64(agent)]);\n const timestamp = record.signed_action.hashed.content.timestamp;\n this.storeProfile(agent, profile, timestamp);\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-qc/profiles-dvm",
3
- "version": "0.23.1",
3
+ "version": "0.23.3",
4
4
  "description": "DnaViewModel implementation for the Profiles zome.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",