@ddd-qc/profiles-dvm 0.30.3 → 0.31.1
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 +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,EAAE,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAiBhG,MAAM,OAAO,sBAAsB;IAAnC;QAEE,aAAQ,GAAsC,IAAI,WAAW,EAAE,CAAC;QAEhE,mBAAc,GAAyB,IAAI,UAAU,EAAE,CAAC;QAIxD,gBAAW,GAA4B,EAAE,CAAC;IAkF5C,CAAC;IA7EC,IAAI,MAAM,KAAgB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAA,CAAA,CAAC;IACxE,IAAI,KAAK,KAAe,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAA,CAAC;IAG7D,eAAe,CAAC,SAAmB;QACjC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE;YAC7D,IAAI,SAAS,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE;gBAC/B,OAAO,OAAO,CAAC;aAChB;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAID,UAAU,CAAC,KAAuB;QAChC,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,CAAC,KAAK,EAAE;gBACV,OAAO;aACR;YACD,KAAK,GAAG,KAAK,CAAC;SACf;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,C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AC;QAC3C,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;CAEF","sourcesContent":["import {ActionId, ActionIdMap, AgentId, AgentIdMap, assertAllDefined} from \"@ddd-qc/cell-proxy\";\nimport {Profile} from \"./bindings/profiles.types\";\nimport {Timestamp} from \"@holochain/client\";\n\n\n/** */\nexport type ProfilesAltSnapshot = {\n all: [AgentId, ActionId, Profile, Timestamp][];\n}\n\n\nexport type ProfilesAltComparable = {\n profileCount: number,\n profiles: Profile[],\n}\n\n/** */\nexport class ProfilesAltPerspective {\n /* ActionId -> Profile */\n profiles: ActionIdMap<[Profile, Timestamp]> = new ActionIdMap();\n /* AgentId -> ActionId */\n profileByAgent: AgentIdMap<ActionId> = new AgentIdMap();\n\n /** -- Extra -- */\n /* Name -> AgentId */\n agentByName: Record<string, AgentId> = {};\n\n\n /** -- Getters -- */\n\n get agents(): AgentId[] { return Array.from(this.profileByAgent.keys())}\n get names(): string[] { return Object.keys(this.agentByName)}\n\n /** */\n getProfileAgent(profileId: ActionId): AgentId | undefined {\n for (const [agentId, profId] of this.profileByAgent.entries()) {\n if (profileId.b64 == profId.b64) {\n return agentId;\n }\n }\n return undefined;\n }\n\n\n /** AgentId or Name */\n getProfile(agent: AgentId | string): Profile | undefined {\n if (typeof agent == \"string\") {\n const maybe = this.agentByName[agent];\n if (!maybe) {\n return;\n }\n agent = maybe;\n }\n const profileAh = this.profileByAgent.get(agent);\n //console.log(\"ProfilesAltZvm.getProfile()\", agent, profileAh);\n if (!profileAh) {\n return undefined;\n }\n const pair = this.profiles.get(profileAh);\n //console.log(\"ProfilesAltZvm.getProfile() pair\", pair);\n if (!pair) {\n return undefined;\n }\n return pair[0];\n }\n\n\n /** */\n getProfileTs(agent: AgentId | string): Timestamp | undefined {\n if (typeof agent == \"string\") {\n const maybe = this.agentByName[agent];\n if (!maybe) {\n return;\n }\n agent = maybe;\n }\n const profileAh = this.profileByAgent.get(agent);\n if (!profileAh) {\n return undefined;\n }\n const pair = this.profiles.get(profileAh);\n if (!pair) {\n return undefined;\n }\n return pair[1];\n }\n\n /** */\n getAgent(nickname: string): AgentId | undefined {\n return this.agentByName[nickname];\n }\n\n\n /** -- Memento -- */\n\n /** TODO: deep copy */\n makeSnapshot(): ProfilesAltSnapshot {\n let all: [AgentId, ActionId, Profile, Timestamp][] = [];\n for (const [agentId, profileAh] of this.profileByAgent.entries()) {\n const pair = this.profiles.get(profileAh);\n if (pair) {\n all.push([agentId, profileAh, pair[0], pair[1]])\n }\n }\n /** */\n return {all};\n }\n}\n\n\n/** */\nexport class ProfilesAltPerspectiveMutable extends ProfilesAltPerspective {\n\n get readonly(): ProfilesAltPerspective {\n return this;\n }\n\n /** -- Store -- */\n\n /** */\n storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp) {\n console.debug(\"ProfilesAltZvm.storeProfile()\", profileAh.short, profile.nickname);\n assertAllDefined(profileAh, profile, ts);\n this.profiles.set(profileAh, [profile, ts]);\n const agentId = this.getProfileAgent(profileAh);\n if (agentId) {\n this.agentByName[profile.nickname] = agentId;\n }\n }\n\n /** */\n storeAgentProfile(agentId: AgentId, profileAh: ActionId) {\n console.debug(\"ProfilesAltZvm.storeAgentProfile()\", agentId.short, profileAh.short);\n assertAllDefined(agentId, profileAh);\n this.profileByAgent.set(agentId, profileAh);\n const pair = this.profiles.get(profileAh);\n if (pair) {\n this.agentByName[pair[0].nickname] = agentId;\n }\n }\n\n /** */\n unstoreAgentProfile(agentId: AgentId, profileAh: ActionId) {\n console.debug(\"ProfilesAltZvm.unstoreAgentProfile()\", agentId.short, profileAh.short);\n assertAllDefined(agentId, profileAh);\n this.profileByAgent.delete(agentId);\n const pair = this.profiles.get(profileAh);\n if (pair) {\n delete this.agentByName[pair[0].nickname];\n }\n }\n\n\n /** -- Memento -- */\n\n /** */\n restore(snapshot: ProfilesAltSnapshot) {\n /** Clear */\n this.profiles.clear();\n this.profileByAgent.clear();\n this.agentByName = {};\n /** Store */\n for (const [agentId, profileAh, profile, ts] of snapshot.all) {\n this.storeAgentProfile(agentId, profileAh);\n this.storeProfile(profileAh, profile, ts);\n }\n }\n\n\n /** -- Generate -- */\n\n /** */\n async generateRandomProfile(nickname: string, ts?: Timestamp, fields?: Record<string, string>) {\n const agentId = await AgentId.random();\n const profileAh = await ActionId.random();\n const profile: Profile = {nickname, fields: {}};\n if (fields) profile.fields = fields;\n this.storeAgentProfile(agentId, profileAh);\n this.storeProfile(profileAh, profile, ts? ts : 0);\n }\n\n}\n"]}
|
|
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,EAAE,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAiBhG,MAAM,OAAO,sBAAsB;IAAnC;QAEE,aAAQ,GAAsC,IAAI,WAAW,EAAE,CAAC;QAEhE,mBAAc,GAAyB,IAAI,UAAU,EAAE,CAAC;QAIxD,gBAAW,GAA4B,EAAE,CAAC;IAkF5C,CAAC;IA7EC,IAAI,MAAM,KAAgB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAA,CAAA,CAAC;IACxE,IAAI,KAAK,KAAe,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAA,CAAC;IAG7D,eAAe,CAAC,SAAmB;QACjC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE;YAC7D,IAAI,SAAS,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE;gBAC/B,OAAO,OAAO,CAAC;aAChB;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAID,UAAU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AAM,SAAS,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAY,EAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAC,CAAC;QAChD,IAAI,MAAM;YAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QACpC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;CAEF","sourcesContent":["import {ActionId, ActionIdMap, AgentId, AgentIdMap, assertAllDefined} from \"@ddd-qc/cell-proxy\";\r\nimport {Profile} from \"./bindings/profiles.types\";\r\nimport {Timestamp} from \"@holochain/client\";\r\n\r\n\r\n/** */\r\nexport type ProfilesAltSnapshot = {\r\n all: [AgentId, ActionId, Profile, Timestamp][];\r\n}\r\n\r\n\r\nexport type ProfilesAltComparable = {\r\n profileCount: number,\r\n profiles: Profile[],\r\n}\r\n\r\n/** */\r\nexport class ProfilesAltPerspective {\r\n /* ActionId -> Profile */\r\n profiles: ActionIdMap<[Profile, Timestamp]> = new ActionIdMap();\r\n /* AgentId -> ActionId */\r\n profileByAgent: AgentIdMap<ActionId> = new AgentIdMap();\r\n\r\n /** -- Extra -- */\r\n /* Name -> AgentId */\r\n agentByName: Record<string, AgentId> = {};\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 /** AgentId or Name */\r\n getProfile(agent: AgentId | string): Profile | undefined {\r\n if (typeof agent == \"string\") {\r\n const maybe = this.agentByName[agent];\r\n if (!maybe) {\r\n return;\r\n }\r\n agent = maybe;\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 const maybe = this.agentByName[agent];\r\n if (!maybe) {\r\n return;\r\n }\r\n agent = maybe;\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 if (!pair) {\r\n return undefined;\r\n }\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 /** -- Memento -- */\r\n\r\n /** TODO: deep copy */\r\n makeSnapshot(): ProfilesAltSnapshot {\r\n let all: [AgentId, ActionId, Profile, Timestamp][] = [];\r\n for (const [agentId, profileAh] of this.profileByAgent.entries()) {\r\n const pair = this.profiles.get(profileAh);\r\n if (pair) {\r\n all.push([agentId, profileAh, pair[0], pair[1]])\r\n }\r\n }\r\n /** */\r\n return {all};\r\n }\r\n}\r\n\r\n\r\n/** */\r\nexport class ProfilesAltPerspectiveMutable extends ProfilesAltPerspective {\r\n\r\n get readonly(): ProfilesAltPerspective {\r\n return this;\r\n }\r\n\r\n /** -- Store -- */\r\n\r\n /** */\r\n storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp) {\r\n console.debug(\"ProfilesAltZvm.storeProfile()\", profileAh.short, profile.nickname);\r\n assertAllDefined(profileAh, profile, ts);\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.debug(\"ProfilesAltZvm.storeAgentProfile()\", agentId.short, profileAh.short);\r\n assertAllDefined(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.debug(\"ProfilesAltZvm.unstoreAgentProfile()\", agentId.short, profileAh.short);\r\n assertAllDefined(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 /** */\r\n restore(snapshot: ProfilesAltSnapshot) {\r\n /** Clear */\r\n this.profiles.clear();\r\n this.profileByAgent.clear();\r\n this.agentByName = {};\r\n /** Store */\r\n for (const [agentId, profileAh, profile, ts] of snapshot.all) {\r\n this.storeAgentProfile(agentId, profileAh);\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 if (fields) profile.fields = fields;\r\n this.storeAgentProfile(agentId, profileAh);\r\n this.storeProfile(profileAh, profile, ts? ts : 0);\r\n }\r\n\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-qc/profiles-dvm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"description": "DnaViewModel implementation for the Profiles zome.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ddd-qc/lit-happ": "file:../lit-happ",
|
|
34
34
|
"@holochain-open-dev/core-types": "0.7.0",
|
|
35
|
-
"@holochain-open-dev/elements": "0.400.0
|
|
35
|
+
"@holochain-open-dev/elements": "=0.400.0",
|
|
36
36
|
"@holochain/client": "=0.18.0-rc.1",
|
|
37
37
|
"@msgpack/msgpack": "^2.7.2",
|
|
38
38
|
"lit": "3.0.2"
|