@holochain/client 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,312 @@
1
+ import { encodeHashToBase64, decodeHashFromBase64 } from "./base64.js";
2
+ /**
3
+ * A Map of HoloHashB64 to a value.
4
+ *
5
+ * @param initialEntries - Optional array of [key, value] pairs to insert into the map.
6
+ *
7
+ * @public
8
+ */
9
+ export class HoloHashB64Map extends Map {
10
+ constructor(initialEntries) {
11
+ super();
12
+ if (initialEntries) {
13
+ for (const [key, value] of initialEntries) {
14
+ this.set(key, value);
15
+ }
16
+ }
17
+ }
18
+ }
19
+ /**
20
+ * @public
21
+ */
22
+ export class AgentPubKeyB64Map extends HoloHashB64Map {
23
+ }
24
+ /**
25
+ * @public
26
+ */
27
+ export class DnaHashB64Map extends HoloHashB64Map {
28
+ }
29
+ /**
30
+ * @public
31
+ */
32
+ export class WasmHashB64Map extends HoloHashB64Map {
33
+ }
34
+ /**
35
+ * @public
36
+ */
37
+ export class EntryHashB64Map extends HoloHashB64Map {
38
+ }
39
+ /**
40
+ * @public
41
+ */
42
+ export class ActionHashB64Map extends HoloHashB64Map {
43
+ }
44
+ /**
45
+ * @public
46
+ */
47
+ export class AnyDhtHashB64Map extends HoloHashB64Map {
48
+ }
49
+ /**
50
+ * @public
51
+ */
52
+ export class ExternalHashB64Map extends HoloHashB64Map {
53
+ }
54
+ /**
55
+ * @public
56
+ */
57
+ export class DhtOpHashB64Map extends HoloHashB64Map {
58
+ }
59
+ /**
60
+ * @public
61
+ */
62
+ export class WarrantHashB64Map extends HoloHashB64Map {
63
+ }
64
+ /**
65
+ * A Map of HoloHash to a value.
66
+ *
67
+ * @param initialEntries - Optional array of [key, value] pairs to insert into the map.
68
+ *
69
+ * @public
70
+ */
71
+ export class HoloHashMap {
72
+ _map;
73
+ constructor(initialEntries) {
74
+ const encodedEntries = initialEntries?.map(([k, v]) => [this._encodeKey(k), v]);
75
+ this._map = new HoloHashB64Map(encodedEntries);
76
+ }
77
+ /**
78
+ * Removes all entries from the map.
79
+ */
80
+ clear() {
81
+ this._map.clear();
82
+ }
83
+ /**
84
+ * Returns an iterator of values in the map.
85
+ *
86
+ * @returns An iterator of all values
87
+ */
88
+ values() {
89
+ return this._map.values();
90
+ }
91
+ /**
92
+ * Checks if a key exists in the map.
93
+ *
94
+ * @param key - The HoloHash key to check
95
+ * @returns True if the key exists, false otherwise
96
+ */
97
+ has(key) {
98
+ const k = this._encodeKey(key);
99
+ return this._map.has(k);
100
+ }
101
+ /**
102
+ * Gets the value associated with a key.
103
+ *
104
+ * @param key - The HoloHash key
105
+ * @returns The value if found, undefined otherwise
106
+ */
107
+ get(key) {
108
+ const k = this._encodeKey(key);
109
+ return this._map.get(k);
110
+ }
111
+ /**
112
+ * Sets a key-value pair in the map.
113
+ *
114
+ * @param key - The HoloHash key
115
+ * @param value - The value to store
116
+ * @returns This map instance for chaining
117
+ */
118
+ set(key, value) {
119
+ const k = this._encodeKey(key);
120
+ this._map.set(k, value);
121
+ return this;
122
+ }
123
+ /**
124
+ * Deletes an entry from the map.
125
+ *
126
+ * @param key - The HoloHash key to delete
127
+ * @returns True if the entry was deleted, false if it didn't exist
128
+ */
129
+ delete(key) {
130
+ const k = this._encodeKey(key);
131
+ return this._map.delete(k);
132
+ }
133
+ /**
134
+ * Returns an iterator of keys in the map.
135
+ *
136
+ * @returns An iterator of all HoloHash keys
137
+ */
138
+ keys() {
139
+ return Array.from(this._map.keys())
140
+ .map((key) => this._decodeKey(key))[Symbol.iterator]();
141
+ }
142
+ /**
143
+ * Returns an iterator of [key, value] pairs.
144
+ *
145
+ * @returns An iterator of all entries
146
+ */
147
+ entries() {
148
+ return Array.from(this._map.entries())
149
+ .map(([key, v]) => [this._decodeKey(key), v])[Symbol.iterator]();
150
+ }
151
+ /**
152
+ * Executes a callback function for each entry in the map.
153
+ *
154
+ * @param callbackfn - Function to execute for each entry
155
+ * @param thisArg - Optional value to use as 'this' when executing the callback
156
+ */
157
+ forEach(callbackfn,
158
+ // This 'any' is inherited from the Map interface.
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
+ thisArg) {
161
+ this._map.forEach((v, k) => {
162
+ callbackfn(v, this._decodeKey(k), this);
163
+ }, thisArg);
164
+ }
165
+ [Symbol.iterator]() {
166
+ return this.entries();
167
+ }
168
+ get [Symbol.toStringTag]() {
169
+ return this._map[Symbol.toStringTag];
170
+ }
171
+ /**
172
+ * The number of entries in the map.
173
+ *
174
+ * @returns The size of the map
175
+ */
176
+ get size() {
177
+ return this._map.size;
178
+ }
179
+ _encodeKey(key) {
180
+ return encodeHashToBase64(key);
181
+ }
182
+ _decodeKey(encoded) {
183
+ return decodeHashFromBase64(encoded);
184
+ }
185
+ }
186
+ /**
187
+ * @public
188
+ */
189
+ export class AgentPubKeyMap extends HoloHashMap {
190
+ }
191
+ /**
192
+ * @public
193
+ */
194
+ export class DnaHashMap extends HoloHashMap {
195
+ }
196
+ /**
197
+ * @public
198
+ */
199
+ export class WasmHashMap extends HoloHashMap {
200
+ }
201
+ /**
202
+ * @public
203
+ */
204
+ export class EntryHashMap extends HoloHashMap {
205
+ }
206
+ /**
207
+ * @public
208
+ */
209
+ export class ActionHashMap extends HoloHashMap {
210
+ }
211
+ /**
212
+ * @public
213
+ */
214
+ export class AnyDhtHashMap extends HoloHashMap {
215
+ }
216
+ /**
217
+ * @public
218
+ */
219
+ export class ExternalHashMap extends HoloHashMap {
220
+ }
221
+ /**
222
+ * @public
223
+ */
224
+ export class DhtOpHashMap extends HoloHashMap {
225
+ }
226
+ /**
227
+ * @public
228
+ */
229
+ export class WarrantHashMap extends HoloHashMap {
230
+ }
231
+ /**
232
+ * A HoloHashMap that will fetch and store a value if it is not found in a 'get' call.
233
+ *
234
+ * @param fetchValue - A function that takes a key and fetches its value.
235
+ * @param initialEntries - Optional array of [key, value] pairs to insert into the map.
236
+ *
237
+ * @public
238
+ */
239
+ export class LazyHoloHashMap extends HoloHashMap {
240
+ fetchValue;
241
+ constructor(fetchValue, initialEntries) {
242
+ super(initialEntries);
243
+ this.fetchValue = fetchValue;
244
+ }
245
+ /**
246
+ *
247
+ * Get a value for a key.
248
+ *
249
+ * If no value for a key is found, it is fetched, inserted into the Map, then returned.
250
+ *
251
+ * @param key - HoloHash key
252
+ * @returns value if found
253
+ */
254
+ get(key) {
255
+ const currentVal = super.get(key);
256
+ if (currentVal !== undefined) {
257
+ return currentVal;
258
+ }
259
+ else {
260
+ const val = this.fetchValue(key);
261
+ if (val !== undefined) {
262
+ super.set(key, val);
263
+ }
264
+ return val;
265
+ }
266
+ }
267
+ }
268
+ /**
269
+ * @public
270
+ */
271
+ export class LazyAgentPubKeyMap extends LazyHoloHashMap {
272
+ }
273
+ /**
274
+ * @public
275
+ */
276
+ export class LazyDnaHashMap extends LazyHoloHashMap {
277
+ }
278
+ /**
279
+ * @public
280
+ */
281
+ export class LazyWasmHashMap extends LazyHoloHashMap {
282
+ }
283
+ /**
284
+ * @public
285
+ */
286
+ export class LazyEntryHashMap extends LazyHoloHashMap {
287
+ }
288
+ /**
289
+ * @public
290
+ */
291
+ export class LazyActionHashMap extends LazyHoloHashMap {
292
+ }
293
+ /**
294
+ * @public
295
+ */
296
+ export class LazyAnyDhtHashMap extends LazyHoloHashMap {
297
+ }
298
+ /**
299
+ * @public
300
+ */
301
+ export class LazyExternalHashMap extends LazyHoloHashMap {
302
+ }
303
+ /**
304
+ * @public
305
+ */
306
+ export class LazyDhtOpHashMap extends LazyHoloHashMap {
307
+ }
308
+ /**
309
+ * @public
310
+ */
311
+ export class LazyWarrantHashMap extends LazyHoloHashMap {
312
+ }
@@ -1,4 +1,6 @@
1
1
  export * from "./base64.js";
2
+ export * from "./cell.js";
3
+ export * from "./dna-holo-hash-map.js";
2
4
  export * from "./fake-hash.js";
3
5
  export * from "./hash-parts.js";
4
- export * from "./cell.js";
6
+ export * from "./holo-hash-map.js";
@@ -1,4 +1,6 @@
1
1
  export * from "./base64.js";
2
+ export * from "./cell.js";
3
+ export * from "./dna-holo-hash-map.js";
2
4
  export * from "./fake-hash.js";
3
5
  export * from "./hash-parts.js";
4
- export * from "./cell.js";
6
+ export * from "./holo-hash-map.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/client",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "A JavaScript client for the Holochain Conductor API",
5
5
  "author": "Holochain Foundation <info@holochain.org> (https://holochain.org)",
6
6
  "license": "CAL-1.0",
@@ -31,46 +31,48 @@
31
31
  "lib"
32
32
  ],
33
33
  "scripts": {
34
- "lint": "eslint --fix --ext .ts src test .eslintrc.cjs",
34
+ "lint": "eslint --fix --ext .ts src test eslint.config.cjs",
35
35
  "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
36
36
  "test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/app-websocket.ts",
37
37
  "test:utils": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/utils.ts",
38
38
  "test": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/index.ts",
39
39
  "build:lib": "rimraf ./lib && tsc -p tsconfig.build.json",
40
40
  "build:docs": "api-extractor run --local && api-documenter markdown -i docs/temp -o docs",
41
- "build": "npm run build:lib && npm run build:docs",
42
- "prepublishOnly": "npm run lint && npm run build"
41
+ "build": "npm run build:lib && npm run build:docs"
43
42
  },
44
43
  "dependencies": {
45
44
  "@bitgo/blake2b": "^3.2.4",
46
- "@msgpack/msgpack": "^3.1.1",
47
- "emittery": "^1.0.1",
45
+ "@msgpack/msgpack": "^3.1.2",
46
+ "emittery": "^1.2.0",
48
47
  "isomorphic-ws": "^5.0.0",
49
- "js-base64": "^3.7.5",
48
+ "js-base64": "^3.7.8",
50
49
  "js-sha512": "^0.9.0",
51
- "libsodium-wrappers": "^0.7.13",
50
+ "libsodium-wrappers": "^0.7.15",
52
51
  "lodash-es": "^4.17.21",
53
- "ws": "^8.14.2"
52
+ "ws": "^8.18.3"
54
53
  },
55
54
  "devDependencies": {
56
- "@microsoft/api-documenter": "^7.21.7",
57
- "@microsoft/api-extractor": "^7.34.4",
55
+ "@eslint/eslintrc": "^3.3.3",
56
+ "@eslint/js": "^9.39.1",
57
+ "@microsoft/api-documenter": "^7.28.1",
58
+ "@microsoft/api-extractor": "^7.55.1",
58
59
  "@types/js-yaml": "4.0.9",
59
- "@types/libsodium-wrappers": "^0.7.11",
60
- "@types/lodash-es": "^4.17.6",
61
- "@types/tape": "^4.13.2",
62
- "@types/ws": "^8.5.5",
63
- "@typescript-eslint/eslint-plugin": "^5.62.0",
64
- "@typescript-eslint/parser": "^5.62.0",
65
- "eslint": "^8.49.0",
66
- "eslint-config-prettier": "^8.10.0",
67
- "eslint-plugin-prettier": "^4.2.1",
68
- "eslint-plugin-tsdoc": "^0.2.17",
69
- "js-yaml": "^4.1.0",
70
- "prettier": "^2.8.8",
71
- "rimraf": "^3.0.2",
72
- "tape": "^5.6.6",
73
- "tsx": "^4.7.2",
74
- "typescript": "^4.9.5"
60
+ "@types/libsodium-wrappers": "^0.7.14",
61
+ "@types/lodash-es": "^4.17.12",
62
+ "@types/tape": "^5.8.1",
63
+ "@types/ws": "^8.18.1",
64
+ "@typescript-eslint/eslint-plugin": "^8.48.1",
65
+ "@typescript-eslint/parser": "^8.48.1",
66
+ "eslint": "^9.39.1",
67
+ "eslint-config-prettier": "^10.1.8",
68
+ "eslint-plugin-prettier": "^5.5.4",
69
+ "eslint-plugin-tsdoc": "^0.5.0",
70
+ "globals": "^16.5.0",
71
+ "js-yaml": "^4.1.1",
72
+ "prettier": "^3.7.3",
73
+ "rimraf": "^6.1.2",
74
+ "tape": "^5.9.0",
75
+ "tsx": "^4.21.0",
76
+ "typescript": "^5.9.3"
75
77
  }
76
78
  }