@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 +2 -2
- package/dist/DnaElement.d.ts +39 -39
- package/dist/DnaElement.js +80 -74
- package/dist/DnaElement.js.map +1 -1
- package/dist/DnaViewModel.d.ts +65 -65
- package/dist/DnaViewModel.js +119 -117
- package/dist/DnaViewModel.js.map +1 -1
- package/dist/HappElement.d.ts +28 -28
- package/dist/HappElement.js +49 -49
- package/dist/HappViewModel.d.ts +51 -51
- package/dist/HappViewModel.js +240 -240
- package/dist/ViewModel.d.ts +39 -39
- package/dist/ViewModel.js +59 -59
- package/dist/ZomeElement.d.ts +33 -33
- package/dist/ZomeElement.js +76 -76
- package/dist/ZomeElement.js.map +1 -1
- package/dist/ZomeViewModel.d.ts +37 -37
- package/dist/ZomeViewModel.js +52 -52
- package/dist/definitions.d.ts +25 -25
- package/dist/definitions.js +20 -20
- package/dist/elements/cell-context.d.ts +18 -18
- package/dist/elements/cell-context.js +45 -45
- package/dist/elements/entry-def-select.d.ts +21 -21
- package/dist/elements/entry-def-select.js +74 -74
- package/dist/elements/view-cell-context.d.ts +12 -12
- package/dist/elements/view-cell-context.js +24 -24
- package/dist/index.d.ts +12 -12
- package/dist/index.js +13 -13
- package/dist/roleMixin.d.ts +32 -32
- package/dist/roleMixin.js +30 -30
- package/package.json +2 -2
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.
|
|
5
|
-
- **@holochain/client v0.11.
|
|
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
|
|
package/dist/DnaElement.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/DnaElement.js
CHANGED
|
@@ -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
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
package/dist/DnaElement.js.map
CHANGED
|
@@ -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,OAAO,EAAe,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,UAAwC,SAAQ,SAAS,CAAC,SAAS,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;IAEhH,mFAAmF;IACnF,YAAY,YAA2B;QACrC,KAAK,EAAE,CAAC;QACR,IAAI,YAAY,EAAE;YAChB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;YACjC,
|
|
1
|
+
{"version":3,"file":"DnaElement.js","sourceRoot":"","sources":["../src/DnaElement.ts"],"names":[],"mappings":";AAAA,OAA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dist/DnaViewModel.d.ts
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 {};
|
package/dist/DnaViewModel.js
CHANGED
|
@@ -1,118 +1,120 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { ViewModel } from "./ViewModel";
|
|
3
|
-
import {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|