@ddd-qc/profiles-dvm 0.26.3 → 0.26.5

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.
@@ -0,0 +1,20 @@
1
+ import { LitElement } from 'lit';
2
+ import '@holochain-open-dev/elements/dist/elements/select-avatar.js';
3
+ import { Profile } from "../bindings/profilesAlt.types";
4
+ /**
5
+ * @fires save-profile - Fired when the save profile button is clicked
6
+ */
7
+ export declare class EditProfile extends LitElement {
8
+ /** The profile to be edited. */
9
+ profile: Profile | undefined;
10
+ /** -- Methods -- */
11
+ /**
12
+ * Seperate Mailgun token from other fields as we don't want it to be saved in Profiles
13
+ */
14
+ fireSaveProfile(formFields: Record<string, string>): Promise<void>;
15
+ /** */
16
+ handleLangChange(_e: any): Promise<void>;
17
+ /** */
18
+ render(): import("lit-html").TemplateResult<1>;
19
+ static styles: (import("lit").CSSResult | import("lit").CSSResult[])[];
20
+ }
@@ -0,0 +1,163 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement } from 'lit';
3
+ import { customElement, property } from 'lit/decorators.js';
4
+ import { localized, msg, str } from '@lit/localize';
5
+ import { onSubmit, sharedStyles } from '@holochain-open-dev/elements';
6
+ import '@holochain-open-dev/elements/dist/elements/select-avatar.js';
7
+ //import "@shoelace-style/shoelace/dist/components/avatar/avatar.js";
8
+ //import "@shoelace-style/shoelace/dist/components/button/button.js";
9
+ //import "@shoelace-style/shoelace/dist/components/icon/icon.js";
10
+ //import "@shoelace-style/shoelace/dist/components/input/input.js";
11
+ //import "@shoelace-style/shoelace/dist/components/radio/radio.js";
12
+ //import "@shoelace-style/shoelace/dist/components/radio-group/radio-group.js";
13
+ //import "@shoelace-style/shoelace/dist/components/tooltip/tooltip.js";
14
+ const MIN_NICKNAME_LENGTH = 2;
15
+ /**
16
+ * @fires save-profile - Fired when the save profile button is clicked
17
+ */
18
+ let EditProfile = class EditProfile extends LitElement {
19
+ /** -- Methods -- */
20
+ /**
21
+ * Seperate Mailgun token from other fields as we don't want it to be saved in Profiles
22
+ */
23
+ async fireSaveProfile(formFields) {
24
+ console.log("fireSaveProfile()", formFields);
25
+ const nickname = formFields['nickname'];
26
+ delete formFields['nickname'];
27
+ const fields = {};
28
+ //fields['email'] = formFields['email'];
29
+ fields['avatar'] = formFields['avatar'] ? formFields['avatar'] : "";
30
+ fields['lang'] = formFields['option'] ? formFields['option'] : "";
31
+ /** */
32
+ this.dispatchEvent(new CustomEvent('save-profile', {
33
+ detail: { nickname, fields },
34
+ bubbles: true,
35
+ composed: true,
36
+ }));
37
+ }
38
+ /** */
39
+ async handleLangChange(_e) {
40
+ //console.log({langChangeEvent: e});
41
+ const langRadioGroup = this.shadowRoot.getElementById("langRadioGroup");
42
+ console.log({ langRadioGroup });
43
+ const lang = langRadioGroup.value;
44
+ console.log("handleLangChange: lang =", lang);
45
+ this.dispatchEvent(new CustomEvent('lang-selected', { detail: lang, bubbles: true, composed: true }));
46
+ }
47
+ /** */
48
+ render() {
49
+ var _a, _b, _c;
50
+ console.log("<profiles-edit-profile>.render()", this.profile);
51
+ /** */
52
+ return html `
53
+ <form id="profile-form" class="column"
54
+ ${onSubmit(fields => /*await*/ this.fireSaveProfile(fields))}>
55
+
56
+ <div class="row"
57
+ style="justify-content: center; align-self: start; margin-bottom: 16px; width: 100%;">
58
+ <select-avatar
59
+ style="cursor:pointer"
60
+ name="avatar"
61
+ .value=${((_a = this.profile) === null || _a === void 0 ? void 0 : _a.fields['avatar']) || undefined}
62
+ ></select-avatar>
63
+ <label for="nickname">Nickname:</label>
64
+ <input
65
+ type="text"
66
+ name="nickname"
67
+ .label=${msg('Nickname')}
68
+ required
69
+ minLength=${MIN_NICKNAME_LENGTH}
70
+ .value=${((_b = this.profile) === null || _b === void 0 ? void 0 : _b.nickname) || ''}
71
+ .helpText=${msg(str `Min. ${MIN_NICKNAME_LENGTH} characters`)}
72
+ style="margin-left: 16px;"
73
+ >
74
+ </div>
75
+
76
+ <div class="row" style="justify-content: center; margin-bottom: 8px; align-self: start;" >
77
+ <span style="font-size:18px;padding-right:10px;">${msg('Language')}:</span>
78
+ <sl-radio-group id="langRadioGroup" @click="${this.handleLangChange}" .value=${(_c = this.profile) === null || _c === void 0 ? void 0 : _c.fields['lang']}>
79
+ <sl-radio value="en">🇬🇧</sl-radio>
80
+ <sl-radio value="fr-fr">🇫🇷</sl-radio>
81
+ </sl-radio-group>
82
+ </div>
83
+
84
+ <div class="row" style="margin-top: 8px;">
85
+ <button style="flex: 1;" variant="primary" type="submit"
86
+ >${msg('Save Profile')}
87
+ </button>
88
+ </div>
89
+ </form>
90
+ `;
91
+ }
92
+ };
93
+ EditProfile.styles = [sharedStyles, css `
94
+
95
+ sl-radio {
96
+ font-size: larger;
97
+ }
98
+ .small-margin {
99
+ margin-top: 6px;
100
+ }
101
+ .big-margin {
102
+ margin-top: 23px;
103
+ }
104
+
105
+ .fill {
106
+ flex: 1;
107
+ height: 100%;
108
+ }
109
+
110
+ .title {
111
+ font-size: 20px;
112
+ }
113
+
114
+ .center-content {
115
+ align-items: center;
116
+ justify-content: center;
117
+ }
118
+
119
+ .placeholder {
120
+ color: rgba(0, 0, 0, 0.7);
121
+ }
122
+
123
+ .label {
124
+ color: var(--mdc-text-field-label-ink-color, rgba(0, 0, 0, 0.6));
125
+ font-family: var(
126
+ --mdc-typography-caption-font-family,
127
+ var(--mdc-typography-font-family, Roboto, sans-serif)
128
+ );
129
+ font-size: var(--mdc-typography-caption-font-size, 0.79rem);
130
+ font-weight: var(--mdc-typography-caption-font-weight, 400);
131
+ }
132
+
133
+ .flex-scrollable-parent {
134
+ position: relative;
135
+ display: flex;
136
+ flex: 1;
137
+ }
138
+
139
+ .flex-scrollable-container {
140
+ position: absolute;
141
+ top: 0;
142
+ left: 0;
143
+ right: 0;
144
+ bottom: 0;
145
+ }
146
+
147
+ .flex-scrollable-x {
148
+ max-width: 100%;
149
+ overflow-x: auto;
150
+ }
151
+ .flex-scrollable-y {
152
+ max-height: 100%;
153
+ overflow-y: auto;
154
+ }`];
155
+ __decorate([
156
+ property({ type: Object })
157
+ ], EditProfile.prototype, "profile", void 0);
158
+ EditProfile = __decorate([
159
+ localized(),
160
+ customElement('profiles-edit-profile')
161
+ ], EditProfile);
162
+ export { EditProfile };
163
+ //# sourceMappingURL=edit-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-profile.js","sourceRoot":"","sources":["../../src/elements/edit-profile.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAC,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,6DAA6D,CAAC;AAKrE,qEAAqE;AACrE,qEAAqE;AACrE,iEAAiE;AACjE,mEAAmE;AACnE,mEAAmE;AACnE,+EAA+E;AAC/E,uEAAuE;AAIvE,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAG7B;;GAEG;AAGI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAQzC,oBAAoB;IAEpB;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,UAAkC;QACtD,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC;QAE9B,MAAM,MAAM,GAAG,EAAE,CAAA;QACjB,wCAAwC;QACxC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,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AE,QAAQ,KAAI,EAAE;wBACzB,GAAG,CAAC,GAAG,CAAA,QAAQ,mBAAmB,aAAa,CAAC;;;;;;6DAMX,GAAG,CAAC,UAAU,CAAC;wDACpB,IAAI,CAAC,gBAAgB,YAAY,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC,MAAM,CAAC;;;;;;;;eAQtG,GAAG,CAAC,cAAc,CAAC;;;;KAI7B,CAAC;IACJ,CAAC;;AAGM,kBAAM,GAAG,CAAC,YAAY,EAAE,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA6D9B,CAAC,AA7DQ,CA6DP;AAtJN;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CACE;AALlB,WAAW;IAFvB,SAAS,EAAE;IACX,aAAa,CAAC,uBAAuB,CAAC;GAC1B,WAAW,CA4JvB","sourcesContent":["import {css, html, LitElement} from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { localized, msg, str } from '@lit/localize';\nimport { onSubmit, sharedStyles } from '@holochain-open-dev/elements';\n\nimport '@holochain-open-dev/elements/dist/elements/select-avatar.js';\nimport {Profile} from \"../bindings/profilesAlt.types\";\n\n\n\n//import \"@shoelace-style/shoelace/dist/components/avatar/avatar.js\";\n//import \"@shoelace-style/shoelace/dist/components/button/button.js\";\n//import \"@shoelace-style/shoelace/dist/components/icon/icon.js\";\n//import \"@shoelace-style/shoelace/dist/components/input/input.js\";\n//import \"@shoelace-style/shoelace/dist/components/radio/radio.js\";\n//import \"@shoelace-style/shoelace/dist/components/radio-group/radio-group.js\";\n//import \"@shoelace-style/shoelace/dist/components/tooltip/tooltip.js\";\n\n\n\nconst MIN_NICKNAME_LENGTH = 2\n\n\n/**\n * @fires save-profile - Fired when the save profile button is clicked\n */\n@localized()\n@customElement('profiles-edit-profile')\nexport class EditProfile extends LitElement {\n\n\n /** The profile to be edited. */\n @property({ type: Object })\n profile: Profile | undefined;\n\n\n /** -- Methods -- */\n\n /**\n * Seperate Mailgun token from other fields as we don't want it to be saved in Profiles\n */\n async fireSaveProfile(formFields: Record<string, string>) {\n console.log(\"fireSaveProfile()\", formFields);\n const nickname = formFields['nickname'];\n delete formFields['nickname'];\n\n const fields = {}\n //fields['email'] = formFields['email'];\n fields['avatar'] = formFields['avatar']? formFields['avatar'] : \"\";\n fields['lang'] = formFields['option']? formFields['option'] : \"\";\n\n\n /** */\n this.dispatchEvent(\n new CustomEvent<Profile>('save-profile', {\n detail: {nickname, fields} as Profile,\n bubbles: true,\n composed: true,\n })\n );\n\n }\n\n\n /** */\n async handleLangChange(_e: any) {\n //console.log({langChangeEvent: e});\n const langRadioGroup = this.shadowRoot!.getElementById(\"langRadioGroup\") as any;\n console.log({langRadioGroup});\n const lang = langRadioGroup.value;\n console.log(\"handleLangChange: lang =\", lang);\n this.dispatchEvent(new CustomEvent('lang-selected', { detail: lang, bubbles: true, composed: true }));\n }\n\n\n /** */\n render() {\n console.log(\"<profiles-edit-profile>.render()\", this.profile);\n\n /** */\n return html`\n <form id=\"profile-form\" class=\"column\"\n ${onSubmit(fields => /*await*/ this.fireSaveProfile(fields))}>\n \n <div class=\"row\"\n style=\"justify-content: center; align-self: start; margin-bottom: 16px; width: 100%;\">\n <select-avatar\n style=\"cursor:pointer\"\n name=\"avatar\"\n .value=${this.profile?.fields['avatar'] || undefined}\n ></select-avatar>\n <label for=\"nickname\">Nickname:</label>\n <input\n type=\"text\"\n name=\"nickname\"\n .label=${msg('Nickname')}\n required\n minLength=${MIN_NICKNAME_LENGTH}\n .value=${this.profile?.nickname || ''}\n .helpText=${msg(str`Min. ${MIN_NICKNAME_LENGTH} characters`)}\n style=\"margin-left: 16px;\"\n >\n </div>\n \n <div class=\"row\" style=\"justify-content: center; margin-bottom: 8px; align-self: start;\" >\n <span style=\"font-size:18px;padding-right:10px;\">${msg('Language')}:</span>\n <sl-radio-group id=\"langRadioGroup\" @click=\"${this.handleLangChange}\" .value=${this.profile?.fields['lang']}>\n <sl-radio value=\"en\">🇬🇧</sl-radio>\n <sl-radio value=\"fr-fr\">🇫🇷</sl-radio>\n </sl-radio-group>\n </div>\n \n <div class=\"row\" style=\"margin-top: 8px;\">\n <button style=\"flex: 1;\" variant=\"primary\" type=\"submit\"\n >${msg('Save Profile')}\n </button>\n </div>\n </form>\n `;\n }\n\n\n static styles = [sharedStyles, css`\n\n sl-radio {\n font-size: larger;\n }\n .small-margin {\n margin-top: 6px;\n }\n .big-margin {\n margin-top: 23px;\n }\n\n .fill {\n flex: 1;\n height: 100%;\n }\n\n .title {\n font-size: 20px;\n }\n\n .center-content {\n align-items: center;\n justify-content: center;\n }\n\n .placeholder {\n color: rgba(0, 0, 0, 0.7);\n }\n\n .label {\n color: var(--mdc-text-field-label-ink-color, rgba(0, 0, 0, 0.6));\n font-family: var(\n --mdc-typography-caption-font-family,\n var(--mdc-typography-font-family, Roboto, sans-serif)\n );\n font-size: var(--mdc-typography-caption-font-size, 0.79rem);\n font-weight: var(--mdc-typography-caption-font-weight, 400);\n }\n\n .flex-scrollable-parent {\n position: relative;\n display: flex;\n flex: 1;\n }\n\n .flex-scrollable-container {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n }\n\n .flex-scrollable-x {\n max-width: 100%;\n overflow-x: auto;\n }\n .flex-scrollable-y {\n max-height: 100%;\n overflow-y: auto;\n }`];\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export * from "./bindings/profiles.proxy";
3
3
  export * from "./profiles.zvm";
4
4
  export * from "./bindings/profilesAlt.proxy";
5
5
  export * from "./profilesAlt.zvm";
6
+ export * from "./elements/edit-profile";
6
7
  export * from "./profiles.dvm";
7
8
  export * from "./utils";
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from "./bindings/profiles.proxy";
3
3
  export * from "./profiles.zvm";
4
4
  export * from "./bindings/profilesAlt.proxy";
5
5
  export * from "./profilesAlt.zvm";
6
+ export * from "./elements/edit-profile";
6
7
  export * from "./profiles.dvm";
7
8
  export * from "./utils";
8
9
  //# sourceMappingURL=index.js.map
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,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 \"./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,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 +1 @@
1
- {"version":3,"file":"profiles.dvm.js","sourceRoot":"","sources":["../src/profiles.dvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAIrD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAG3C,MAAM;AACN,4CAA4C;AAC5C,4CAA4C;AAC5C,IAAI;AAGJ;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAA7C;;QAIW,kBAAa,GAAiB,IAAI,CAAC,YAAY,CAAC;IA8B3D,CAAC;IA3BC,kBAAkB;IAClB,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,iBAAiB,CAAgB,CAAA;IAC5E,CAAC;IAED,wBAAwB;IAEd,UAAU;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,WAAW;QACb,OAAO,EAAE,CAAA;IACX,CAAC;IAGD,sBAAsB;IAEtB,MAAM;IACN,YAAY,CAAC,MAAiB;QAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC,iBAAiB,EAAE;YACtD,OAAO;SACR;IACH,CAAC;;AA7Be,kCAAsB,GAAG,UAAU,AAAb,CAAc;AACpC,oBAAQ,GAAG,CAAC,WAAW,CAAC,AAAhB,CAAgB","sourcesContent":["import {delay, DnaViewModel} from \"@ddd-qc/lit-happ\";\nimport {\n AppSignal, AppSignalCb,\n} from \"@holochain/client\";\nimport {ProfilesZvm} from \"./profiles.zvm\";\nimport {ProfilesAltZvm} from \"./profilesAlt.zvm\";\n\n/** */\n// export interface ProfilesDnaPerspective {\n// agentPresences: Record<string, number>,\n// }\n\n\n/**\n * ViewModel fo a DNA holding a Profiles zome\n */\nexport class ProfilesDvm extends DnaViewModel {\n\n static readonly DEFAULT_BASE_ROLE_NAME = \"profiles\";\n static readonly ZVM_DEFS = [ProfilesZvm]\n readonly signalHandler?: AppSignalCb = this.handleSignal;\n\n\n /** QoL Helpers */\n get profilesZvm(): ProfilesZvm {\n return this.getZomeViewModel(ProfilesZvm.DEFAULT_ZOME_NAME) as ProfilesZvm\n }\n\n /** -- Perspective -- */\n\n protected hasChanged(): boolean {\n return true\n }\n\n get perspective(): unknown {\n return {}\n }\n\n\n /** -- Signaling -- */\n\n /** */\n handleSignal(signal: AppSignal) {\n console.log(\"Received Signal\", signal);\n if (signal.zome_name !== ProfilesZvm.DEFAULT_ZOME_NAME) {\n return;\n }\n }\n\n\n}\n"]}
1
+ {"version":3,"file":"profiles.dvm.js","sourceRoot":"","sources":["../src/profiles.dvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAIrD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAG3C,MAAM;AACN,4CAA4C;AAC5C,4CAA4C;AAC5C,IAAI;AAGJ;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAA7C;;QAIW,kBAAa,GAAiB,IAAI,CAAC,YAAY,CAAC;IA8B3D,CAAC;IA3BC,kBAAkB;IAClB,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,iBAAiB,CAAgB,CAAA;IAC5E,CAAC;IAED,wBAAwB;IAEd,UAAU;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,WAAW;QACb,OAAO,EAAE,CAAA;IACX,CAAC;IAGD,sBAAsB;IAEtB,MAAM;IACN,YAAY,CAAC,MAAiB;QAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC,iBAAiB,EAAE;YACtD,OAAO;SACR;IACH,CAAC;;AA7Be,kCAAsB,GAAG,UAAU,AAAb,CAAc;AACpC,oBAAQ,GAAG,CAAC,WAAW,CAAC,AAAhB,CAAgB","sourcesContent":["import {delay, DnaViewModel} from \"@ddd-qc/lit-happ\";\nimport {\n AppSignal, AppSignalCb,\n} from \"@holochain/client\";\nimport {ProfilesZvm} from \"./profiles.zvm\";\n\n\n/** */\n// export interface ProfilesDnaPerspective {\n// agentPresences: Record<string, number>,\n// }\n\n\n/**\n * ViewModel fo a DNA holding a Profiles zome\n */\nexport class ProfilesDvm extends DnaViewModel {\n\n static readonly DEFAULT_BASE_ROLE_NAME = \"profiles\";\n static readonly ZVM_DEFS = [ProfilesZvm]\n readonly signalHandler?: AppSignalCb = this.handleSignal;\n\n\n /** QoL Helpers */\n get profilesZvm(): ProfilesZvm {\n return this.getZomeViewModel(ProfilesZvm.DEFAULT_ZOME_NAME) as ProfilesZvm\n }\n\n /** -- Perspective -- */\n\n protected hasChanged(): boolean {\n return true\n }\n\n get perspective(): unknown {\n return {}\n }\n\n\n /** -- Signaling -- */\n\n /** */\n handleSignal(signal: AppSignal) {\n console.log(\"Received Signal\", signal);\n if (signal.zome_name !== ProfilesZvm.DEFAULT_ZOME_NAME) {\n return;\n }\n }\n\n\n}\n"]}
@@ -27,21 +27,18 @@ export declare class ProfilesAltZvm extends ZomeViewModelWithSignals {
27
27
  /** -- Perspective -- */
28
28
  get perspective(): ProfilesAltPerspective;
29
29
  private _perspective;
30
- getMyProfile(): Profile | undefined;
30
+ /** -- Getters -- */
31
31
  getProfileAgent(profileId: ActionId): AgentId | undefined;
32
+ getMyProfile(): Profile | undefined;
32
33
  getProfile(agent: AgentId): Profile | undefined;
33
34
  getProfileTs(agent: AgentId): Timestamp | undefined;
34
35
  getAgents(): AgentId[];
35
36
  getNames(): string[];
37
+ /** -- Signals -- */
36
38
  /** */
37
39
  handleLinkPulse(pulse: LinkPulseMat, from: AgentId): Promise<void>;
38
40
  /** */
39
41
  handleEntryPulse(pulse: EntryPulseMat, from: AgentId): Promise<void>;
40
- /** -- perspective -- */
41
- /** Dump perspective as JSON */
42
- exportPerspective(): string;
43
- /** */
44
- importPerspective(json: string, canPublish: boolean): Promise<void>;
45
42
  /** -- Store -- */
46
43
  /** */
47
44
  storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp): void;
@@ -62,4 +59,9 @@ export declare class ProfilesAltZvm extends ZomeViewModelWithSignals {
62
59
  createProfile(profile: Profile, agentId: AgentId): Promise<void>;
63
60
  /** */
64
61
  updateProfile(profile: Profile, agentId: AgentId): Promise<void>;
62
+ /** -- Import / Export -- */
63
+ /** Dump perspective as JSON */
64
+ exportPerspective(): string;
65
+ /** */
66
+ importPerspective(json: string, canPublish: boolean): Promise<void>;
65
67
  }
@@ -1,5 +1,4 @@
1
1
  import { ActionIdMap, AgentId, AgentIdMap, EntryId, ZomeViewModelWithSignals } from "@ddd-qc/lit-happ";
2
- import { hashFrom32AndType } from "@holochain/client";
3
2
  import { decode } from "@msgpack/msgpack";
4
3
  import { ProfilesAltProxy } from "./bindings/profilesAlt.proxy";
5
4
  import { EntryTypesType, StateChangeType, } from "./bindings/profilesAlt.types";
@@ -38,13 +37,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
38
37
  get perspective() {
39
38
  return this._perspective;
40
39
  }
41
- getMyProfile() {
42
- const pair = this._perspective.profiles.get(this.cell.agentId);
43
- if (!pair) {
44
- return undefined;
45
- }
46
- return pair[0];
47
- }
40
+ /** -- Getters -- */
48
41
  getProfileAgent(profileId) {
49
42
  for (const [agentId, profId] of this._perspective.profileByAgent.entries()) {
50
43
  if (profileId.b64 == profId.b64) {
@@ -53,12 +46,20 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
53
46
  }
54
47
  return undefined;
55
48
  }
49
+ getMyProfile() {
50
+ return this.getProfile(this.cell.agentId);
51
+ }
56
52
  getProfile(agent) {
57
53
  const profileAh = this._perspective.profileByAgent.get(agent);
54
+ console.log("ProfilesAltZvm.getProfile()", agent, profileAh);
58
55
  if (!profileAh) {
59
56
  return undefined;
60
57
  }
61
58
  const pair = this._perspective.profiles.get(profileAh);
59
+ console.log("ProfilesAltZvm.getProfile() pair", pair);
60
+ if (!pair) {
61
+ return undefined;
62
+ }
62
63
  return pair[0];
63
64
  }
64
65
  getProfileTs(agent) {
@@ -71,22 +72,31 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
71
72
  }
72
73
  getAgents() { return Array.from(this._perspective.profileByAgent.keys()); }
73
74
  getNames() { return Object.keys(this._perspective.agentByName); }
75
+ /** -- Signals -- */
74
76
  /** */
75
77
  async handleLinkPulse(pulse, from) {
76
78
  /** */
77
79
  switch (pulse.link_type) {
78
80
  case ProfilesLinkType.PrefixPath:
79
81
  case ProfilesLinkType.PathToAgent:
82
+ {
83
+ const agentEh = new EntryId(pulse.target.b64);
84
+ const agentId = AgentId.from(agentEh);
85
+ if (pulse.state != StateChangeType.Delete) {
86
+ await this.findProfile(agentId);
87
+ }
88
+ }
80
89
  break;
81
90
  case ProfilesLinkType.AgentToProfile:
82
- const _agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash
83
- const agentHash = hashFrom32AndType(pulse.base.hash, "Agent");
84
- const agentId = new AgentId(agentHash);
85
- if (pulse.state == StateChangeType.Delete) {
86
- this.unstoreAgentProfile(agentId, pulse.target);
87
- }
88
- else {
89
- this.storeAgentProfile(agentId, pulse.target);
91
+ {
92
+ const agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash
93
+ const agentId = AgentId.from(agentEh);
94
+ if (pulse.state == StateChangeType.Delete) {
95
+ this.unstoreAgentProfile(agentId, pulse.target);
96
+ }
97
+ else {
98
+ this.storeAgentProfile(agentId, pulse.target);
99
+ }
90
100
  }
91
101
  break;
92
102
  }
@@ -102,33 +112,10 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
102
112
  break;
103
113
  }
104
114
  }
105
- /** -- perspective -- */
106
- /** Dump perspective as JSON */
107
- exportPerspective() {
108
- //console.log("exportPerspective()", perspMat);
109
- const core = this._perspective; // FIXME: check if this actually works as expected
110
- return JSON.stringify(core, null, 2);
111
- }
112
- /** */
113
- async importPerspective(json, canPublish) {
114
- const perspective = JSON.parse(json);
115
- if (canPublish) {
116
- for (const [agentId, [profile, _ts]] of perspective.profiles.entries()) {
117
- await this.createProfile(profile, agentId);
118
- }
119
- return;
120
- }
121
- /** */
122
- for (const [actionId, [profile, ts]] of perspective.profiles.entries()) {
123
- this.storeProfile(actionId, profile, ts);
124
- }
125
- for (const [agentId, actionId] of perspective.profileByAgent.entries()) {
126
- this.storeAgentProfile(agentId, actionId);
127
- }
128
- }
129
115
  /** -- Store -- */
130
116
  /** */
131
117
  storeProfile(profileAh, profile, ts) {
118
+ console.log("ProfilesAltZvm.storeProfile()", profileAh, profile.nickname);
132
119
  this._perspective.profiles.set(profileAh, [profile, ts]);
133
120
  const agentId = this.getProfileAgent(profileAh);
134
121
  if (agentId) {
@@ -137,6 +124,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
137
124
  }
138
125
  /** */
139
126
  storeAgentProfile(agentId, profileAh) {
127
+ console.log("ProfilesAltZvm.storeAgentProfile()", agentId, profileAh);
140
128
  this._perspective.profileByAgent.set(agentId, profileAh);
141
129
  const pair = this._perspective.profiles.get(profileAh);
142
130
  if (pair) {
@@ -145,6 +133,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
145
133
  }
146
134
  /** */
147
135
  unstoreAgentProfile(agentId, profileAh) {
136
+ console.log("ProfilesAltZvm.unstoreAgentProfile()", agentId, profileAh);
148
137
  this._perspective.profileByAgent.delete(agentId);
149
138
  const pair = this._perspective.profiles.get(profileAh);
150
139
  if (pair) {
@@ -159,7 +148,7 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
159
148
  /** */
160
149
  async findProfile(agentId) {
161
150
  const maybeProfilePair = await this.zomeProxy.findProfile(agentId.hash);
162
- console.log("probeProfile() maybeProfilePair", maybeProfilePair);
151
+ console.log("findProfile() maybeProfilePair", maybeProfilePair);
163
152
  if (!maybeProfilePair) {
164
153
  return;
165
154
  }
@@ -181,6 +170,30 @@ export class ProfilesAltZvm extends ZomeViewModelWithSignals {
181
170
  async updateProfile(profile, agentId) {
182
171
  const _ah = await this.zomeProxy.updateProfile([profile, agentId.hash]);
183
172
  }
173
+ /** -- Import / Export -- */
174
+ /** Dump perspective as JSON */
175
+ exportPerspective() {
176
+ //console.log("exportPerspective()", perspMat);
177
+ const core = this._perspective; // FIXME: check if this actually works as expected
178
+ return JSON.stringify(core, null, 2);
179
+ }
180
+ /** */
181
+ async importPerspective(json, canPublish) {
182
+ const perspective = JSON.parse(json);
183
+ if (canPublish) {
184
+ for (const [agentId, [profile, _ts]] of perspective.profiles.entries()) {
185
+ await this.createProfile(profile, agentId);
186
+ }
187
+ return;
188
+ }
189
+ /** */
190
+ for (const [actionId, [profile, ts]] of perspective.profiles.entries()) {
191
+ this.storeProfile(actionId, profile, ts);
192
+ }
193
+ for (const [agentId, actionId] of perspective.profileByAgent.entries()) {
194
+ this.storeAgentProfile(agentId, actionId);
195
+ }
196
+ }
184
197
  }
185
198
  ProfilesAltZvm.ZOME_PROXY = ProfilesAltProxy;
186
199
  //# sourceMappingURL=profilesAlt.zvm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EACK,WAAW,EACrB,OAAO,EACP,UAAU,EAAE,OAAO,EAEnB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,iBAAiB,EAAY,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,eAAe,GAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAmB/D,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,E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AAC,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;;AA9Me,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {\n ActionId, ActionIdMap,\n AgentId,\n AgentIdMap, EntryId,\n LinkPulseMat,\n ZomeViewModelWithSignals\n} from \"@ddd-qc/lit-happ\";\nimport {Profile} from \"./bindings/profiles.types\";\nimport {hashFrom32AndType, Timestamp} from \"@holochain/client\";\nimport {decode} from \"@msgpack/msgpack\";\nimport {ProfilesAltProxy} from \"./bindings/profilesAlt.proxy\";\nimport {\n EntryTypesType,\n StateChangeType,\n} from \"./bindings/profilesAlt.types\";\nimport {EntryPulseMat} from \"@ddd-qc/lit-happ/dist/ZomeViewModelWithSignals\";\nimport {ProfilesLinkType} from \"./bindings/profiles.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 getMyProfile(): Profile | undefined {\n const pair = this._perspective.profiles.get(this.cell.agentId)\n if (!pair) {\n return undefined;\n }\n return pair[0];\n }\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 getProfile(agent: AgentId): Profile | 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[0];\n\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\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 break;\n case ProfilesLinkType.AgentToProfile:\n const _agentEh = new EntryId(pulse.base.b64); // Make sure its an EntryHash\n const agentHash = hashFrom32AndType(pulse.base.hash, \"Agent\");\n const agentId = new AgentId(agentHash);\n if (pulse.state == StateChangeType.Delete) {\n this.unstoreAgentProfile(agentId, pulse.target)\n } else {\n this.storeAgentProfile(agentId, pulse.target)\n }\n break;\n }\n }\n\n\n /** */\n async handleEntryPulse(pulse: EntryPulseMat, from: AgentId) {\n switch (pulse.entryType) {\n case EntryTypesType.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 /** -- perspective -- */\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 [agentId, [profile, _ts]] of perspective.profiles.entries()) {\n await this.createProfile(profile, agentId);\n }\n return;\n }\n /** */\n for (const [actionId, [profile, ts]] of perspective.profiles.entries()) {\n this.storeProfile(actionId, profile, ts);\n }\n for (const [agentId, actionId] of perspective.profileByAgent.entries()) {\n this.storeAgentProfile(agentId, actionId);\n }\n }\n\n\n /** -- Store -- */\n\n\n /** */\n storeProfile(profileAh: ActionId, profile: Profile, ts: Timestamp) {\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 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 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(\"probeProfile() 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"]}
1
+ {"version":3,"file":"profilesAlt.zvm.js","sourceRoot":"","sources":["../src/profilesAlt.zvm.ts"],"names":[],"mappings":"AAAA,OAAO,EACK,WAAW,EACrB,OAAO,EACP,UAAU,EAAE,OAAO,EAEnB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,eAAe,GAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAmB/D,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;IAmMhF,CAAC;IA9NC,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;I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AAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE;YACtE,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;SAC1C;QACD,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE;YACtE,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;SAC3C;IACH,CAAC;;AA5Ne,yBAAU,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["import {\n ActionId, ActionIdMap,\n AgentId,\n AgentIdMap, EntryId,\n LinkPulseMat,\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 {\n EntryTypesType,\n StateChangeType,\n} from \"./bindings/profilesAlt.types\";\nimport {EntryPulseMat} from \"@ddd-qc/lit-happ/dist/ZomeViewModelWithSignals\";\nimport {ProfilesLinkType} from \"./bindings/profiles.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 EntryTypesType.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 /** -- 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 [agentId, [profile, _ts]] of perspective.profiles.entries()) {\n await this.createProfile(profile, agentId);\n }\n return;\n }\n /** */\n for (const [actionId, [profile, ts]] of perspective.profiles.entries()) {\n this.storeProfile(actionId, profile, ts);\n }\n for (const [agentId, actionId] of perspective.profileByAgent.entries()) {\n this.storeAgentProfile(agentId, actionId);\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.3",
3
+ "version": "0.26.5",
4
4
  "description": "DnaViewModel implementation for the Profiles zome.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "ci:tsc": "tsc --version",
13
13
  "lint" : "eslint --ext .ts .",
14
- "build" : "rm -rf dist && tsc"
14
+ "build" : "rm -rf dist && tsc",
15
+ "build:watch": "tsc -w --preserveWatchOutput"
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",