@ddd-qc/lit-happ 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # lit-happ
2
2
 
3
3
  **Compatible with:**
4
- - **HDK v0.1.0-beta-rc.1** & **HDI v0.2.0-beta-rc.2**
5
- - **@holochain/client v0.11.2**
4
+ - **HDK v0.1.0-beta-rc.1** & **HDI v0.2.0-beta-rc.1**
5
+ - **@holochain/client v0.11.9**
6
6
  -
7
7
  Builds on the [cell-proxy](https://www.npmjs.com/package/@ddd-qc/cell-proxy) package to provide a MVVM framework for building web-UI in [Lit](https://www.npmjs.com/package/lit) for [holochain](https://www.npmjs.com/package/@holochain/client) apps.
8
8
 
@@ -1,39 +1,39 @@
1
- import { LitElement, PropertyValues } from "lit";
2
- import { DnaViewModel } from "./DnaViewModel";
3
- import { Cell } from "@holochain/client";
4
- import { BaseRoleName } from "@ddd-qc/cell-proxy";
5
- declare const DnaElement_base: (abstract new (...args: any[]) => {
6
- _cell?: Cell;
7
- readonly cell: Cell;
8
- readonly cellId: import("@holochain/client").CellId;
9
- readonly dnaHash: string;
10
- readonly agentPubKey: string;
11
- }) & ((abstract new (...args: any[]) => {
12
- baseRoleName: string;
13
- }) & {
14
- readonly DEFAULT_BASE_ROLE_NAME: string;
15
- }) & typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
16
- /**
17
- * A LitElement that is bound to a specific DnaViewModel, e.g. a View for the ViewModel
18
- */
19
- export declare class DnaElement<P, DVM extends DnaViewModel> extends DnaElement_base {
20
- /** if BaseRoleName is not provided, subclass must call requestDvm() in its Ctor */
21
- constructor(baseRoleName?: BaseRoleName);
22
- /** Provided by Context depending on BaseRoleName */
23
- protected _dvm: DVM;
24
- _cell_via_context: Cell;
25
- perspective: P;
26
- /** -- Methods -- */
27
- /** */
28
- protected requestDvm(): void;
29
- /**
30
- * To be overriden by subclasses
31
- * Example: Have a subclass unsubscribe to oldDvm's zvms and subscribe to the new ones
32
- */
33
- protected dvmUpdated(newDvm: DVM, oldDvm?: DVM): Promise<void>;
34
- /** */
35
- shouldUpdate(changedProperties: PropertyValues<this>): boolean;
36
- /** */
37
- protected willUpdate(changedProperties: PropertyValues<this>): void;
38
- }
39
- export {};
1
+ import { LitElement, PropertyValues } from "lit";
2
+ import { DnaViewModel } from "./DnaViewModel";
3
+ import { Cell } from "@holochain/client";
4
+ import { BaseRoleName } from "@ddd-qc/cell-proxy";
5
+ declare const DnaElement_base: (abstract new (...args: any[]) => {
6
+ _cell?: Cell;
7
+ readonly cell: Cell;
8
+ readonly cellId: import("@holochain/client").CellId;
9
+ readonly dnaHash: string;
10
+ readonly agentPubKey: string;
11
+ }) & ((abstract new (...args: any[]) => {
12
+ baseRoleName: string; /** if BaseRoleName is not provided, subclass must call requestDvm() in its Ctor */
13
+ }) & {
14
+ readonly DEFAULT_BASE_ROLE_NAME: string;
15
+ }) & typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
16
+ /**
17
+ * A LitElement that is bound to a specific DnaViewModel, e.g. a View for the ViewModel
18
+ */
19
+ export declare class DnaElement<P, DVM extends DnaViewModel> extends DnaElement_base {
20
+ /** if BaseRoleName is not provided, subclass must call requestDvm() in its Ctor */
21
+ constructor(baseRoleName?: BaseRoleName);
22
+ /** Provided by Context depending on BaseRoleName */
23
+ protected _dvm: DVM;
24
+ _cell_via_context: Cell;
25
+ perspective: P;
26
+ /** -- Methods -- */
27
+ /** */
28
+ protected requestDvm(): void;
29
+ /**
30
+ * To be overriden by subclasses
31
+ * Example: Have a subclass unsubscribe to oldDvm's zvms and subscribe to the new ones
32
+ */
33
+ protected dvmUpdated(newDvm: DVM, oldDvm?: DVM): Promise<void>;
34
+ /** */
35
+ shouldUpdate(changedProperties: PropertyValues<this>): boolean;
36
+ /** */
37
+ protected willUpdate(changedProperties: PropertyValues<this>): void;
38
+ }
39
+ export {};
@@ -1,75 +1,81 @@
1
- import { __awaiter, __decorate } from "tslib";
2
- import { ScopedElementsMixin } from "@open-wc/scoped-elements";
3
- import { LitElement } from "lit";
4
- import { property, state } from "lit/decorators.js";
5
- import { ContextConsumer, contextProvided, createContext } from "@lit-labs/context";
6
- import { CellMixin } from "@ddd-qc/cell-proxy";
7
- import { cellContext } from "./elements/cell-context";
8
- import { RoleMixin } from "./roleMixin";
9
- /**
10
- * A LitElement that is bound to a specific DnaViewModel, e.g. a View for the ViewModel
11
- */
12
- export class DnaElement extends CellMixin(RoleMixin(ScopedElementsMixin(LitElement))) {
13
- /** if BaseRoleName is not provided, subclass must call requestDvm() in its Ctor */
14
- constructor(baseRoleName) {
15
- super();
16
- if (baseRoleName) {
17
- this.baseRoleName = baseRoleName;
18
- this.requestDvm();
19
- }
20
- }
21
- /** -- Methods -- */
22
- /** */
23
- requestDvm() {
24
- /** Consume Context based on given dnaHash */
25
- const cellName = this._cell_via_context ? this._cell_via_context.name : this.baseRoleName;
26
- const contextType = createContext('dvm/' + cellName);
27
- console.log(`\t\t Requesting context "${contextType}"`);
28
- /*const consumer =*/ new ContextConsumer(this, contextType, (value, dispose) => {
29
- console.log(`\t\t Received value for context "${contextType}"`);
30
- this.dvmUpdated(value, this._dvm);
31
- if (this._dvm) {
32
- this._dvm.unsubscribe(this);
33
- }
34
- this._dvm = value;
35
- this._dvm.subscribe(this, 'perspective');
36
- }, false);
37
- //console.log({consumer})
38
- }
39
- /**
40
- * To be overriden by subclasses
41
- * Example: Have a subclass unsubscribe to oldDvm's zvms and subscribe to the new ones
42
- */
43
- dvmUpdated(newDvm, oldDvm) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- //console.log(`\t\t Default dvmUpdated() called`)
46
- });
47
- }
48
- /** */
49
- shouldUpdate(changedProperties) {
50
- if (changedProperties.has("_cell_via_context")) {
51
- this._cell = this._cell_via_context;
52
- }
53
- if (!this._dvm) {
54
- this.requestDvm();
55
- }
56
- return !!this._dvm;
57
- }
58
- /** */
59
- willUpdate(changedProperties) {
60
- if (changedProperties.has("_cell_via_context")) {
61
- this.requestDvm();
62
- }
63
- }
64
- }
65
- __decorate([
66
- state()
67
- ], DnaElement.prototype, "_dvm", void 0);
68
- __decorate([
69
- contextProvided({ context: cellContext, subscribe: true }),
70
- property({ type: Object, attribute: false })
71
- ], DnaElement.prototype, "_cell_via_context", void 0);
72
- __decorate([
73
- property({ type: Object, attribute: false, hasChanged: (_v, _old) => true })
74
- ], DnaElement.prototype, "perspective", void 0);
1
+ import { __awaiter, __decorate } from "tslib";
2
+ import { ScopedElementsMixin } from "@open-wc/scoped-elements";
3
+ import { LitElement } from "lit";
4
+ import { property, state } from "lit/decorators.js";
5
+ import { ContextConsumer, contextProvided, createContext } from "@lit-labs/context";
6
+ import { CellMixin } from "@ddd-qc/cell-proxy";
7
+ import { cellContext } from "./elements/cell-context";
8
+ import { RoleMixin } from "./roleMixin";
9
+ /**
10
+ * A LitElement that is bound to a specific DnaViewModel, e.g. a View for the ViewModel
11
+ */
12
+ export class DnaElement extends CellMixin(RoleMixin(ScopedElementsMixin(LitElement))) {
13
+ /** if BaseRoleName is not provided, subclass must call requestDvm() in its Ctor */
14
+ constructor(baseRoleName) {
15
+ super();
16
+ if (baseRoleName) {
17
+ this.baseRoleName = baseRoleName;
18
+ //this.requestDvm();
19
+ }
20
+ }
21
+ /** -- Methods -- */
22
+ /** */
23
+ requestDvm() {
24
+ /** Consume Context based on given dnaHash */
25
+ // const cellName = this._cell_via_context
26
+ // ? this._cell_via_context.name
27
+ // : this.baseRoleName;
28
+ if (!this._cell_via_context) {
29
+ console.warn("No Cell context found in DnaElement for ", this.baseRoleName);
30
+ return;
31
+ }
32
+ const contextType = createContext('dvm/' + this.cell.name);
33
+ console.log(`\t\t Requesting context "${contextType}"`);
34
+ /*const consumer =*/ new ContextConsumer(this, contextType, (value, dispose) => {
35
+ console.log(`\t\t Received value for context "${contextType}"`);
36
+ this.dvmUpdated(value, this._dvm);
37
+ if (this._dvm) {
38
+ this._dvm.unsubscribe(this);
39
+ }
40
+ this._dvm = value;
41
+ this._dvm.subscribe(this, 'perspective');
42
+ }, false);
43
+ //console.log({consumer})
44
+ }
45
+ /**
46
+ * To be overriden by subclasses
47
+ * Example: Have a subclass unsubscribe to oldDvm's zvms and subscribe to the new ones
48
+ */
49
+ dvmUpdated(newDvm, oldDvm) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ //console.log(`\t\t Default dvmUpdated() called`)
52
+ });
53
+ }
54
+ /** */
55
+ shouldUpdate(changedProperties) {
56
+ if (changedProperties.has("_cell_via_context")) {
57
+ this._cell = this._cell_via_context;
58
+ }
59
+ if (!this._dvm) {
60
+ this.requestDvm();
61
+ }
62
+ return !!this._dvm;
63
+ }
64
+ /** */
65
+ willUpdate(changedProperties) {
66
+ if (changedProperties.has("_cell_via_context")) {
67
+ this.requestDvm();
68
+ }
69
+ }
70
+ }
71
+ __decorate([
72
+ state()
73
+ ], DnaElement.prototype, "_dvm", void 0);
74
+ __decorate([
75
+ contextProvided({ context: cellContext, subscribe: true }),
76
+ property({ type: Object, attribute: false })
77
+ ], DnaElement.prototype, "_cell_via_context", void 0);
78
+ __decorate([
79
+ property({ type: Object, attribute: false, hasChanged: (_v, _old) => true })
80
+ ], DnaElement.prototype, "perspective", void 0);
75
81
  //# sourceMappingURL=DnaElement.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DnaElement.js","sourceRoot":"","sources":["../src/DnaElement.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAC,UAAU,EAAiB,MAAM,KAAK,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGlF,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,CAAC,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC3C,CAAC,EACD,KAAK,CACN,CAAC;QACF,yBAAyB;IAC3B,CAAC;IAGD;;;OAGG;IACa,UAAU,CAAC,MAAW,EAAE,MAAY;;YAClD,iDAAiD;QACnD,CAAC;KAAA;IAGD,MAAM;IACN,YAAY,CAAC,iBAAuC;QAClD,IAAI,iBAAiB,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE;YAC9C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC;SACrC;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,IAAI,CAAC,UAAU,EAAE,CAAC;SACnB;QACD,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAGD,MAAM;IACI,UAAU,CAAC,iBAAuC;QAC1D,IAAI,iBAAiB,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE;YAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;SACnB;IACH,CAAC;CACF;AArEU;IAAR,KAAK,EAAE;wCAAsB;AAI9B;IAFC,eAAe,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC;IACzD,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAC,CAAC;qDAClB;AAGzB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAC,CAAC;+CAC3D"}
@@ -1,65 +1,65 @@
1
- import { ZomeViewModel } from "./ZomeViewModel";
2
- import { ReactiveElement } from "lit";
3
- import { ViewModel } from "./ViewModel";
4
- import { AdminWebsocket, AppSignalCb, InstalledAppId, ZomeName } from "@holochain/client";
5
- import { DnaModifiersOptions, ZvmDef } from "./definitions";
6
- import { CellProxy, ConductorAppProxy, HCL, Dictionary } from "@ddd-qc/cell-proxy";
7
- import { RoleSpecific } from "./roleMixin";
8
- /** Interface specific to DnaViewModel class */
9
- interface IDnaViewModel {
10
- dumpLogs(zomeName?: ZomeName): void;
11
- fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;
12
- }
13
- export type DvmConstructor = typeof RoleSpecific & {
14
- DNA_MODIFIERS: DnaModifiersOptions;
15
- } & {
16
- new (host: ReactiveElement, proxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId): DnaViewModel;
17
- };
18
- declare const DnaViewModel_base: (abstract new (...args: any[]) => {
19
- _cell?: import("@holochain/client").Cell;
20
- readonly cell: import("@holochain/client").Cell;
21
- readonly cellId: import("@holochain/client").CellId;
22
- readonly dnaHash: string;
23
- readonly agentPubKey: string;
24
- }) & ((abstract new (...args: any[]) => {
25
- /** Interface specific to DnaViewModel class */
26
- baseRoleName: string;
27
- }) & {
28
- readonly DEFAULT_BASE_ROLE_NAME: string;
29
- }) & typeof ViewModel;
30
- /**
31
- * Abstract ViewModel for a DNA.
32
- * It holds the CellProxy and all the ZomeViewModels of the DNA.
33
- * A DNA is expected to derive this class and add extra logic at the DNA level.
34
- * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
35
- */
36
- export declare abstract class DnaViewModel extends DnaViewModel_base implements IDnaViewModel {
37
- static ZVM_DEFS: ZvmDef[];
38
- static DNA_MODIFIERS: DnaModifiersOptions;
39
- abstract signalHandler?: AppSignalCb;
40
- /** Ctor */
41
- constructor(host: ReactiveElement, conductorAppProxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId);
42
- /** -- Fields -- */
43
- protected _cellProxy: CellProxy;
44
- protected _zomeViewModels: Dictionary<ZomeViewModel>;
45
- protected _zomeNames: Dictionary<ZomeName>;
46
- private _allEntryDefs;
47
- readonly hcl: HCL;
48
- /** -- Getters -- */
49
- getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined;
50
- getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined;
51
- getZomeName(zvm: typeof ZomeViewModel): ZomeName | undefined;
52
- /** -- Methods -- */
53
- /** Override so we can provide context of all zvms */
54
- provideContext(host: ReactiveElement): void;
55
- getContext(): any;
56
- /** */
57
- authorizeZomeCalls(adminWs: AdminWebsocket): Promise<void>;
58
- /** */
59
- probeAll(): Promise<void>;
60
- /** Maybe useless since the entry defs are in the integrity zome which is not represented here */
61
- fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;
62
- /** */
63
- dumpLogs(zomeName?: ZomeName): void;
64
- }
65
- export {};
1
+ import { ZomeViewModel } from "./ZomeViewModel";
2
+ import { ReactiveElement } from "lit";
3
+ import { ViewModel } from "./ViewModel";
4
+ import { AdminWebsocket, AppSignalCb, InstalledAppId, ZomeName } from "@holochain/client";
5
+ import { DnaModifiersOptions, ZvmDef } from "./definitions";
6
+ import { CellProxy, ConductorAppProxy, HCL, Dictionary } from "@ddd-qc/cell-proxy";
7
+ import { RoleSpecific } from "./roleMixin";
8
+ /** Interface specific to DnaViewModel class */
9
+ interface IDnaViewModel {
10
+ dumpLogs(zomeName?: ZomeName): void;
11
+ fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;
12
+ }
13
+ export type DvmConstructor = typeof RoleSpecific & {
14
+ DNA_MODIFIERS: DnaModifiersOptions;
15
+ } & {
16
+ new (host: ReactiveElement, proxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId): DnaViewModel;
17
+ };
18
+ declare const DnaViewModel_base: (abstract new (...args: any[]) => {
19
+ _cell?: import("@holochain/client").Cell;
20
+ readonly cell: import("@holochain/client").Cell;
21
+ readonly cellId: import("@holochain/client").CellId;
22
+ readonly dnaHash: string;
23
+ readonly agentPubKey: string;
24
+ }) & ((abstract new (...args: any[]) => {
25
+ baseRoleName: string;
26
+ }) & {
27
+ readonly DEFAULT_BASE_ROLE_NAME: string;
28
+ }) & typeof ViewModel;
29
+ /**
30
+ * Abstract ViewModel for a DNA.
31
+ * It holds the CellProxy and all the ZomeViewModels of the DNA.
32
+ * A DNA is expected to derive this class and add extra logic at the DNA level.
33
+ * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
34
+ */
35
+ export declare abstract class DnaViewModel extends DnaViewModel_base implements IDnaViewModel {
36
+ readonly host: ReactiveElement;
37
+ static ZVM_DEFS: ZvmDef[];
38
+ static DNA_MODIFIERS: DnaModifiersOptions;
39
+ abstract signalHandler?: AppSignalCb;
40
+ /** Ctor */
41
+ constructor(host: ReactiveElement, conductorAppProxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId);
42
+ /** -- Fields -- */
43
+ protected _cellProxy: CellProxy;
44
+ protected _zomeViewModels: Dictionary<ZomeViewModel>;
45
+ protected _zomeNames: Dictionary<ZomeName>;
46
+ private _allEntryDefs;
47
+ readonly hcl: HCL;
48
+ /** -- Getters -- */
49
+ getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined;
50
+ getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined;
51
+ getZomeName(zvm: typeof ZomeViewModel): ZomeName | undefined;
52
+ /** -- Methods -- */
53
+ /** Override so we can provide context of all zvms */
54
+ provideContext(host: ReactiveElement): void;
55
+ getContext(): any;
56
+ /** */
57
+ authorizeZomeCalls(adminWs: AdminWebsocket): Promise<void>;
58
+ /** */
59
+ probeAll(): Promise<void>;
60
+ /** Maybe useless since the entry defs are in the integrity zome which is not represented here */
61
+ fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;
62
+ /** */
63
+ dumpLogs(zomeName?: ZomeName): void;
64
+ }
65
+ export {};
@@ -1,118 +1,120 @@
1
- import { __awaiter } from "tslib";
2
- import { ViewModel } from "./ViewModel";
3
- import { authorizeSigningCredentials, } from "@holochain/client";
4
- import { createContext } from "@lit-labs/context";
5
- import { HCL, CellMixin } from "@ddd-qc/cell-proxy";
6
- import { RoleMixin } from "./roleMixin";
7
- /**
8
- * Abstract ViewModel for a DNA.
9
- * It holds the CellProxy and all the ZomeViewModels of the DNA.
10
- * A DNA is expected to derive this class and add extra logic at the DNA level.
11
- * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
12
- */
13
- export class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) {
14
- /** Ctor */
15
- constructor(host, conductorAppProxy, idOrHcl) {
16
- super();
17
- /* ZomeName -> Zvm */
18
- this._zomeViewModels = {};
19
- /* ZvmCtorName -> ZomeName */
20
- this._zomeNames = {};
21
- this._allEntryDefs = {};
22
- if (typeof idOrHcl === 'object') {
23
- this.baseRoleName = idOrHcl.baseRoleName;
24
- this.hcl = idOrHcl;
25
- }
26
- else {
27
- this.hcl = new HCL(idOrHcl, this.baseRoleName);
28
- }
29
- const dvmCtor = this.constructor;
30
- const zvmDefs = dvmCtor.ZVM_DEFS;
31
- this._cellProxy = conductorAppProxy.getCellProxy(this.hcl); // WARN can throw error
32
- this._cell = this._cellProxy.cell;
33
- console.log(`DVM.ctor of ${this.baseRoleName}`, this._cellProxy.cell);
34
- /** Create all ZVMs for this DNA */
35
- for (const zvmDef of zvmDefs) {
36
- let zvm;
37
- if (Array.isArray(zvmDef)) {
38
- zvm = new zvmDef[0](this._cellProxy, zvmDef[1]);
39
- }
40
- else {
41
- zvm = new zvmDef(this._cellProxy);
42
- }
43
- // TODO check zvm.zomeName exists in _cellProxy
44
- this._zomeViewModels[zvm.zomeName] = zvm;
45
- this._zomeNames[zvmDef.constructor.name] = zvm.zomeName;
46
- }
47
- this.provideContext(host); // TODO move this to host.connectedCallback? e.g. change ViewModel to a ReactiveController
48
- }
49
- /** -- Getters -- */
50
- getZomeEntryDefs(zomeName) { return this._allEntryDefs[zomeName]; }
51
- getZomeViewModel(zomeName) { return this._zomeViewModels[zomeName]; }
52
- getZomeName(zvm) { return this._zomeNames[zvm.constructor.name]; }
53
- /** -- Methods -- */
54
- /** Override so we can provide context of all zvms */
55
- /*private*/ provideContext(host) {
56
- //console.log("DVM.provideContext()", host, this)
57
- super.provideContext(host);
58
- for (const zvm of Object.values(this._zomeViewModels)) {
59
- zvm.provideContext(host);
60
- }
61
- }
62
- getContext() { return createContext('dvm/' + this.cell.name); }
63
- ;
64
- /** */
65
- authorizeZomeCalls(adminWs) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- let allFnNames = [];
68
- for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {
69
- allFnNames = allFnNames.concat(zvm.zomeProxy.fnNames);
70
- }
71
- try {
72
- console.log("authorizeSigningCredentials: " + this.baseRoleName, allFnNames);
73
- yield authorizeSigningCredentials(adminWs, this.cellId, allFnNames);
74
- }
75
- catch (e) {
76
- console.warn("authorizeSigningCredentials FAILED.", e);
77
- }
78
- // this._signingProps = getSigningCredentials(this.cellId);
79
- // console.log({signProps: this._signingProps})
80
- //
81
- // for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {
82
- // zvm.zomeProxy.setSigningProps(this._signingProps);
83
- // }
84
- });
85
- }
86
- /** */
87
- probeAll() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- for (const [name, zvm] of Object.entries(this._zomeViewModels)) {
90
- //console.log("Dvm.probeAll()", name)
91
- yield zvm.probeAll();
92
- }
93
- });
94
- }
95
- /** Maybe useless since the entry defs are in the integrity zome which is not represented here */
96
- fetchAllEntryDefs() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- for (const zvm of Object.values(this._zomeViewModels)) {
99
- const zomeName = zvm.zomeName;
100
- try {
101
- const defs = yield this._cellProxy.callEntryDefs(zomeName); // TODO optimize
102
- this._allEntryDefs[zomeName] = defs;
103
- }
104
- catch (e) {
105
- console.warn(`Calling "entry_defs()" failed on zome "${zomeName}". Possibly because zome does not have any entry types defined.`);
106
- this._allEntryDefs[zomeName] = [];
107
- }
108
- }
109
- return this._allEntryDefs;
110
- });
111
- }
112
- /** */
113
- dumpLogs(zomeName) {
114
- this._cellProxy.dumpLogs(zomeName);
115
- this._cellProxy.dumpSignals();
116
- }
117
- }
1
+ import { __awaiter } from "tslib";
2
+ import { ViewModel } from "./ViewModel";
3
+ import { GrantedFunctionsType, } from "@holochain/client";
4
+ import { createContext } from "@lit-labs/context";
5
+ import { HCL, CellMixin } from "@ddd-qc/cell-proxy";
6
+ import { RoleMixin } from "./roleMixin";
7
+ /**
8
+ * Abstract ViewModel for a DNA.
9
+ * It holds the CellProxy and all the ZomeViewModels of the DNA.
10
+ * A DNA is expected to derive this class and add extra logic at the DNA level.
11
+ * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
12
+ */
13
+ export class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) {
14
+ /** Ctor */
15
+ constructor(host, conductorAppProxy, idOrHcl) {
16
+ super();
17
+ this.host = host;
18
+ /* ZomeName -> Zvm */
19
+ this._zomeViewModels = {};
20
+ /* ZvmCtorName -> ZomeName */
21
+ this._zomeNames = {};
22
+ this._allEntryDefs = {};
23
+ if (typeof idOrHcl === 'object') {
24
+ this.baseRoleName = idOrHcl.baseRoleName;
25
+ this.hcl = idOrHcl;
26
+ }
27
+ else {
28
+ this.hcl = new HCL(idOrHcl, this.baseRoleName);
29
+ }
30
+ const dvmCtor = this.constructor;
31
+ const zvmDefs = dvmCtor.ZVM_DEFS;
32
+ this._cellProxy = conductorAppProxy.getCellProxy(this.hcl); // WARN can throw error
33
+ this._cell = this._cellProxy.cell;
34
+ console.log(`DVM.ctor of ${this.baseRoleName}`, this._cellProxy.cell);
35
+ /** Create all ZVMs for this DNA */
36
+ for (const zvmDef of zvmDefs) {
37
+ let zvm;
38
+ if (Array.isArray(zvmDef)) {
39
+ zvm = new zvmDef[0](this._cellProxy, zvmDef[1]);
40
+ }
41
+ else {
42
+ zvm = new zvmDef(this._cellProxy);
43
+ }
44
+ // TODO check zvm.zomeName exists in _cellProxy
45
+ this._zomeViewModels[zvm.zomeName] = zvm;
46
+ this._zomeNames[zvmDef.constructor.name] = zvm.zomeName;
47
+ }
48
+ this.provideContext(host); // TODO move this to host.connectedCallback? e.g. change ViewModel to a ReactiveController
49
+ }
50
+ /** -- Getters -- */
51
+ getZomeEntryDefs(zomeName) { return this._allEntryDefs[zomeName]; }
52
+ getZomeViewModel(zomeName) { return this._zomeViewModels[zomeName]; }
53
+ getZomeName(zvm) { return this._zomeNames[zvm.constructor.name]; }
54
+ /** -- Methods -- */
55
+ /** Override so we can provide context of all zvms */
56
+ /*private*/ provideContext(host) {
57
+ //console.log("DVM.provideContext()", host, this)
58
+ super.provideContext(host);
59
+ for (const zvm of Object.values(this._zomeViewModels)) {
60
+ zvm.provideContext(host);
61
+ }
62
+ }
63
+ getContext() { return createContext('dvm/' + this.cell.name); }
64
+ ;
65
+ /** */
66
+ authorizeZomeCalls(adminWs) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ let allFnNames = [];
69
+ for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {
70
+ allFnNames = allFnNames.concat(zvm.zomeProxy.fnNames);
71
+ }
72
+ const grantedFns = { [GrantedFunctionsType.Listed]: allFnNames };
73
+ try {
74
+ console.log("authorizeSigningCredentials: " + this.baseRoleName, allFnNames);
75
+ yield adminWs.authorizeSigningCredentials(this.cellId, grantedFns);
76
+ }
77
+ catch (e) {
78
+ console.warn("authorizeSigningCredentials FAILED.", e);
79
+ }
80
+ // this._signingProps = getSigningCredentials(this.cellId);
81
+ // console.log({signProps: this._signingProps})
82
+ //
83
+ // for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {
84
+ // zvm.zomeProxy.setSigningProps(this._signingProps);
85
+ // }
86
+ });
87
+ }
88
+ /** */
89
+ probeAll() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ for (const [name, zvm] of Object.entries(this._zomeViewModels)) {
92
+ //console.log("Dvm.probeAll()", name)
93
+ yield zvm.probeAll();
94
+ }
95
+ });
96
+ }
97
+ /** Maybe useless since the entry defs are in the integrity zome which is not represented here */
98
+ fetchAllEntryDefs() {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ for (const zvm of Object.values(this._zomeViewModels)) {
101
+ const zomeName = zvm.zomeName;
102
+ try {
103
+ const defs = yield this._cellProxy.callEntryDefs(zomeName); // TODO optimize
104
+ this._allEntryDefs[zomeName] = defs;
105
+ }
106
+ catch (e) {
107
+ console.warn(`Calling "entry_defs()" failed on zome "${zomeName}". Possibly because zome does not have any entry types defined.`);
108
+ this._allEntryDefs[zomeName] = [];
109
+ }
110
+ }
111
+ return this._allEntryDefs;
112
+ });
113
+ }
114
+ /** */
115
+ dumpLogs(zomeName) {
116
+ this._cellProxy.dumpLogs(zomeName);
117
+ this._cellProxy.dumpSignals();
118
+ }
119
+ }
118
120
  //# sourceMappingURL=DnaViewModel.js.map