@ddd-qc/profiles-dvm 0.26.7 → 0.26.8

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,4 +1,4 @@
1
- import { ActionId, ActionIdMap, AgentId, AgentIdMap, LinkPulseMat, SignalLog, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
1
+ import { ActionId, ActionIdMap, AgentId, AgentIdMap, LinkPulseMat, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
2
2
  import { Profile } from "./bindings/profiles.types";
3
3
  import { Timestamp } from "@holochain/client";
4
4
  import { ProfilesAltProxy } from "./bindings/profilesAlt.proxy";
@@ -39,8 +39,6 @@ export declare class ProfilesAltZvm extends ZomeViewModelWithSignals {
39
39
  handleLinkPulse(pulse: LinkPulseMat, from: AgentId): Promise<void>;
40
40
  /** */
41
41
  handleEntryPulse(pulse: EntryPulseMat, from: AgentId): Promise<void>;
42
- /** */
43
- dumpSignalLogs(signalLogs: SignalLog[]): void;
44
42
  /** -- Store -- */
45
43
  /** */
46
44
  storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp): void;
@@ -1,8 +1,8 @@
1
- import { ActionIdMap, AgentId, AgentIdMap, enc64, EntryId, materializeEntryPulse, materializeLinkPulse, prettyDate, prettyState, SignalType, StateChangeType, ZomeSignalProtocolType, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
1
+ import { ActionId, ActionIdMap, AgentId, AgentIdMap, 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
- import { ProfilesAltLinkType, ProfilesAltUnitEnum } from "./bindings/profilesAlt.integrity";
5
+ import { ProfilesAltUnitEnum } from "./bindings/profilesAlt.integrity";
6
6
  function createProfilesAltPerspective() {
7
7
  return {
8
8
  profiles: new ActionIdMap(),
@@ -91,11 +91,12 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
91
91
  {
92
92
  const agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash
93
93
  const agentId = AgentId.from(agentEh);
94
+ const profileAh = ActionId.from(pulse.target);
94
95
  if (pulse.state == StateChangeType.Delete) {
95
- this.unstoreAgentProfile(agentId, pulse.target);
96
+ this.unstoreAgentProfile(agentId, profileAh);
96
97
  }
97
98
  else {
98
- this.storeAgentProfile(agentId, pulse.target);
99
+ this.storeAgentProfile(agentId, profileAh);
99
100
  }
100
101
  }
101
102
  break;
@@ -112,37 +113,37 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
112
113
  break;
113
114
  }
114
115
  }
115
- /** */
116
- dumpSignalLogs(signalLogs) {
117
- this.dumpCastLogs();
118
- console.warn(`Signals received from zome "${this.zomeName}"`);
119
- let appSignals = [];
120
- signalLogs
121
- .filter((log) => log.type == SignalType.Zome)
122
- .map((log) => {
123
- const signal = log.zomeSignal;
124
- const pulses = signal.pulses;
125
- const timestamp = prettyDate(new Date(log.ts));
126
- const from = enc64(signal.from) == this.cell.agentId.b64 ? "self" : new AgentId(signal.from);
127
- for (const pulse of pulses) {
128
- if (ZomeSignalProtocolType.Tip in pulse) {
129
- const tip = pulse.Tip;
130
- const type = Object.keys(tip)[0];
131
- appSignals.push({ timestamp, from, pulse: ZomeSignalProtocolType.Tip, type, payload: tip });
132
- }
133
- if (ZomeSignalProtocolType.Entry in pulse) {
134
- const entryPulse = materializeEntryPulse(pulse.Entry, Object.values(ProfilesAltUnitEnum));
135
- const typedEntry = decode(entryPulse.bytes);
136
- 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 });
137
- }
138
- if (ZomeSignalProtocolType.Link in pulse) {
139
- const linkPulse = materializeLinkPulse(pulse.Link, Object.values(ProfilesAltLinkType));
140
- 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() });
141
- }
142
- }
143
- });
144
- console.table(appSignals);
145
- }
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
+ // }
146
147
  /** -- Store -- */
147
148
  /** */
148
149
  storeProfile(profileAh, profile, ts) {
@@ -1 +1 @@
1
- {"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,OAAO,EACP,UAAU,EACV,KAAK,EACL,OAAO,EACO,qBAAqB,EAAE,oBAAoB,EACzD,UAAU,EACV,WAAW,EAEX,UAAU,EAAE,eAAe,EAI3B,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAG1B,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,EAAE,mBAAmB,EAAC,MAAM,kCAAkC,CAAC;AAmB1F,SAAS,4BAA4B;IACnC,OAAO;QACL,QAAQ,EAAE,IAAI,WAAW,EAAE;QAC3B,cAAc,EAAE,IAAI,UAAU,EAAE;QAChC,WAAW,EAAE,EAAE;KAChB,CAAA;AACH,CAAC;AAGD;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,wBAAwB;IAA5D;;QA8BU,iBAAY,GAA2B,4BAA4B,EAAE,CAAC;IAmOhF,CAAC;IA9PC,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;IACL,IAAI,WAAW;QACb,O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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 if (pulse.state == StateChangeType.Delete) {\n this.unstoreAgentProfile(agentId, pulse.target)\n } else {\n this.storeAgentProfile(agentId, pulse.target)\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,WAAW,EACX,OAAO,EACP,UAAU,EAEV,OAAO,EAKK,eAAe,EAK3B,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAG1B,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,EAAsB,mBAAmB,EAAC,MAAM,kCAAkC,CAAC;AAmB1F,SAAS,4BAA4B;IACnC,OAAO;QACL,QAAQ,EAAE,IAAI,WAAW,EAAE;QAC3B,cAAc,EAAE,IAAI,UAAU,EAAE;QAChC,WAAW,EAAE,EAAE;KAChB,CAAA;AACH,CAAC;AAGD;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,wBAAwB;IAA5D;;QA8BU,iBAAY,GAA2B,4BAA4B,EAAE,CAAC;IAoOhF,CAAC;IA/PC,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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0C,CAAC,CAAE,kDAAkD;QACjH,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,iBAAiB,CAAC,IAAY,EAAE,WAAoB;QACxD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-qc/profiles-dvm",
3
- "version": "0.26.7",
3
+ "version": "0.26.8",
4
4
  "description": "DnaViewModel implementation for the Profiles zome.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",