@ddd-qc/cell-proxy 0.9.4 → 0.9.6

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.
Files changed (2) hide show
  1. package/README.md +52 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # cell-proxy
2
2
 
3
- Proxy classes and helpers for managing a Holochain AppWebsocket and calling zome functions on cells.
3
+ Proxy classes and helpers for managing a [Holochain](https://www.npmjs.com/package/@holochain/client) AppWebsocket and calling zome functions on cells.
4
4
  The intent is to make the development of web UI of Holochain apps in javascript / typescript faster & easier by providing a straightforward API for communicating with a Conductor, and some basic logging features.
5
5
 
6
6
 
@@ -59,20 +59,64 @@ A `ConductorAppProxy` can be created by providing an already existing `AppWebSoc
59
59
  A subclass is expected to provide all the zome functions of a zome as directly callable methods.
60
60
  Example: `profilesProxy.fetchAllProfiles()`
61
61
 
62
+ A `ZomeProxy` subclass must define the static field `DEFAULT_ZOME_NAME` which is the way to know at runtime for what zome this subclass is for.
62
63
 
63
- ## Example use
64
+
65
+ # Example
66
+
67
+ Imagine you have a happ that has a dna that uses a profile zome.
68
+
69
+ ## Example without subclassing ZomeProxy
70
+ ```typescript
71
+ /** HCL of the role we want to use */
72
+ const hcl = new HCL("myHapp", "myRole");
73
+ /** Create AppProxy from provided local port */
74
+ const appProxy = await ConductorAppProxy.new(Number(process.env.HC_PORT));
75
+ /** Map out all the runnings cells for a Role in a happ. Required before calling createCellProxy */
76
+ await appProxy.fetchCells(hcl);
77
+ /** Create a CellProxy for the "myRole" role */
78
+ const profilesCellProxy = appProxy.createCellProxy(hcl);
79
+ /** Call zome function on the "profiles" zome */
80
+ const handles = await profilesCellProxy.callZome("profiles", "fetch_all_handles", null);
81
+ /** Dump all logs to console */
82
+ appProxy.dumpLogs();
83
+ ```
84
+
85
+
86
+ ## Example with ZomeProxy subclass
87
+
88
+ #### ZomeProxy subclass
89
+
90
+ ```typescript
91
+ export class ProfileZomeProxy extends ZomeProxy {
92
+
93
+ static readonly DEFAULT_ZOME_NAME: string = "profiles";
94
+
95
+ async getMyHandle(): Promise<string> {
96
+ return this.call('get_my_handle', null);
97
+ }
98
+ async setMyHandle(value: string): Promise<EntryHash> {
99
+ return this.callBlocking('set_my_handle', value);
100
+ }
101
+ async fetchAllHandles(): Promise<string[]> {
102
+ return this.call('fetch_all_handles', null);
103
+ }
104
+ }
105
+ ```
106
+
107
+ #### Use
64
108
 
65
109
  ```typescript
66
110
  /** HCL of the cell we want to use */
67
- const profilesHcl = new HCL("where", "profiles");
111
+ const hcl = new HCL("myHapp", "myRole");
68
112
  /** Create AppProxy from provided local port */
69
113
  const appProxy = await ConductorAppProxy.new(Number(process.env.HC_PORT));
70
114
  /** Map out all the runnings cells for a Role in a happ. Required before calling createCellProxy */
71
- await appProxy.fetchCells(profilesHcl);
115
+ await appProxy.fetchCells(hcl);
72
116
  /** Create a CellProxy for the "profiles" role */
73
- const profilesCellProxy = appProxy.createCellProxy(profilesHcl);
117
+ const cellProxy = appProxy.createCellProxy(hcl);
118
+ /** Create ZomeProxy */
119
+ const zomeProxy = ProfileZomeProxy(cellProxy);
74
120
  /** Call zome function on the "profiles" zome */
75
- const profiles = await profilesCellProxy.callZome("profiles", "fetchAllProfiles", null);
76
- /** Dump all logs to console */
77
- appProxy.dumpLogs();
121
+ const handles = await zomeProxy.fetchAllHandles();
78
122
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ddd-qc/cell-proxy",
3
- "version": "0.9.4",
4
- "description": "Wrapper for AppWebsocket",
3
+ "version": "0.9.6",
4
+ "description": "Proxy classes and helpers for managing a Holochain AppWebsocket",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "type": "module",