@holochain/client 0.20.0-rc.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.
- package/lib/api/admin/types.d.ts +51 -3
- package/lib/api/admin/websocket.d.ts +1 -1
- package/lib/api/app/types.d.ts +2 -2
- package/lib/api/app/websocket.d.ts +2 -2
- package/lib/api/client.d.ts +0 -1
- package/lib/api/common.d.ts +0 -1
- package/lib/api/zome-call-signing.d.ts +1 -1
- package/lib/hdk/details.d.ts +19 -0
- package/lib/hdk/details.js +8 -0
- package/lib/hdk/entry.d.ts +19 -0
- package/lib/hdk/entry.js +8 -1
- package/lib/hdk/index.d.ts +2 -0
- package/lib/hdk/index.js +2 -0
- package/lib/hdk/record.d.ts +10 -0
- package/lib/hdk/validation-receipts.d.ts +18 -0
- package/lib/hdk/validation-receipts.js +9 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +34 -0
- package/lib/types.js +15 -1
- package/lib/utils/dna-holo-hash-map.d.ts +162 -0
- package/lib/utils/dna-holo-hash-map.js +235 -0
- package/lib/utils/hash-parts.d.ts +37 -11
- package/lib/utils/hash-parts.js +60 -6
- package/lib/utils/holo-hash-map.d.ts +247 -0
- package/lib/utils/holo-hash-map.js +312 -0
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +3 -1
- package/package.json +29 -27
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import flatMap from "lodash-es/flatMap.js";
|
|
2
|
+
import { HoloHashMap } from "./holo-hash-map.js";
|
|
3
|
+
/**
|
|
4
|
+
* A Map of DnaHash to HoloHashMap.
|
|
5
|
+
*
|
|
6
|
+
* i.e. A Map of DnaHash to a Map of HoloHash to a value.
|
|
7
|
+
*
|
|
8
|
+
* @param initialEntries - Optional array of `[[DnaHash, HoloHash], value]` to insert into the map.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export class DnaHoloHashMap {
|
|
13
|
+
_dnaMap = new HoloHashMap();
|
|
14
|
+
constructor(initialEntries) {
|
|
15
|
+
if (initialEntries) {
|
|
16
|
+
for (const [[dnaHash, key], value] of initialEntries) {
|
|
17
|
+
this.set([dnaHash, key], value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the value associated with a [DnaHash, HoloHash] key pair.
|
|
23
|
+
*
|
|
24
|
+
* @param key - Array of [DnaHash, HoloHash]
|
|
25
|
+
* @returns The value if found, undefined otherwise
|
|
26
|
+
*/
|
|
27
|
+
get([dnaHash, key]) {
|
|
28
|
+
return this._dnaMap.get(dnaHash)
|
|
29
|
+
? this._dnaMap.get(dnaHash)?.get(key)
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a [DnaHash, HoloHash] key pair exists in the map.
|
|
34
|
+
*
|
|
35
|
+
* @param cellKey - Array of [DnaHash, HoloHash] to check
|
|
36
|
+
* @returns True if the key exists, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
has([dnaHash, key]) {
|
|
39
|
+
const map = this._dnaMap.get(dnaHash);
|
|
40
|
+
return map ? map.has(key) : false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets a value for a [DnaHash, HoloHash] key pair.
|
|
44
|
+
*
|
|
45
|
+
* @param key - Tuple of [DnaHash, HoloHash]
|
|
46
|
+
* @param value - The value to store
|
|
47
|
+
* @returns This map instance for chaining
|
|
48
|
+
*/
|
|
49
|
+
set([dnaHash, key], value) {
|
|
50
|
+
const map = this._dnaMap.get(dnaHash);
|
|
51
|
+
if (map === undefined) {
|
|
52
|
+
this._dnaMap.set(dnaHash, new HoloHashMap([[key, value]]));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
map.set(key, value);
|
|
56
|
+
}
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Removes all entries from the map.
|
|
61
|
+
*/
|
|
62
|
+
clear() {
|
|
63
|
+
this._dnaMap.clear();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Deletes an entry from the map. If this was the last entry for a DNA, the DNA entry is also removed.
|
|
67
|
+
*
|
|
68
|
+
* @param key - Array of [DnaHash, HoloHash] to delete
|
|
69
|
+
* @returns True if the DNA entry was deleted (last entry for that DNA), false otherwise
|
|
70
|
+
*/
|
|
71
|
+
delete([dnaHash, key]) {
|
|
72
|
+
const map = this._dnaMap.get(dnaHash);
|
|
73
|
+
if (map) {
|
|
74
|
+
const wasDeleted = map.delete(key);
|
|
75
|
+
if (wasDeleted && Array.from(map.keys()).length === 0) {
|
|
76
|
+
this._dnaMap.delete(dnaHash);
|
|
77
|
+
}
|
|
78
|
+
return wasDeleted;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns all [DnaHash, HoloHash] key pairs in the map.
|
|
86
|
+
*
|
|
87
|
+
* @returns Array of all key tuples
|
|
88
|
+
*/
|
|
89
|
+
keys() {
|
|
90
|
+
const dnaHashes = Array.from(this._dnaMap.keys());
|
|
91
|
+
return flatMap(dnaHashes, (dnaHash) => {
|
|
92
|
+
const cell = this._dnaMap.get(dnaHash);
|
|
93
|
+
const keys = cell ? Array.from(cell.keys()) : [];
|
|
94
|
+
return keys.map((key) => [dnaHash, key]);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns all values in the map.
|
|
99
|
+
*
|
|
100
|
+
* @returns Array of all values
|
|
101
|
+
*/
|
|
102
|
+
values() {
|
|
103
|
+
return this.keys().map((dnaKey) => this.get(dnaKey));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns all entries as [[DnaHash, HoloHash], value] Arrays.
|
|
107
|
+
*
|
|
108
|
+
* @returns Array of all entries
|
|
109
|
+
*/
|
|
110
|
+
entries() {
|
|
111
|
+
return this.keys().map((dnaKey) => [dnaKey, this.get(dnaKey)]);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new DnaHoloHashMap containing only entries that match the filter predicate.
|
|
115
|
+
*
|
|
116
|
+
* @param fn - Predicate function to test each value
|
|
117
|
+
* @returns A new filtered map
|
|
118
|
+
*/
|
|
119
|
+
filter(fn) {
|
|
120
|
+
const entries = this.entries();
|
|
121
|
+
const mappedValues = entries.filter(([, v]) => fn(v));
|
|
122
|
+
return new DnaHoloHashMap(mappedValues);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new DnaHoloHashMap with values transformed by the mapping function.
|
|
126
|
+
*
|
|
127
|
+
* @param fn - Function to transform each value
|
|
128
|
+
* @returns A new mapped map
|
|
129
|
+
*/
|
|
130
|
+
map(fn) {
|
|
131
|
+
const entries = this.entries();
|
|
132
|
+
const mappedValues = entries.map(([id, v]) => [id, fn(v)]);
|
|
133
|
+
return new DnaHoloHashMap(mappedValues);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns all HoloHash keys for a specific DNA.
|
|
137
|
+
*
|
|
138
|
+
* @param dnaHash - The DNA hash to query
|
|
139
|
+
* @returns Array of HoloHash keys for this DNA
|
|
140
|
+
*/
|
|
141
|
+
keysForDna(dnaHash) {
|
|
142
|
+
const map = this._dnaMap.get(dnaHash);
|
|
143
|
+
return map ? Array.from(map.keys()) : [];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns all values for a specific DNA.
|
|
147
|
+
*
|
|
148
|
+
* @param dnaHash - The DNA hash to query
|
|
149
|
+
* @returns Array of values for this DNA
|
|
150
|
+
*/
|
|
151
|
+
valuesForDna(dnaHash) {
|
|
152
|
+
const map = this._dnaMap.get(dnaHash);
|
|
153
|
+
return map ? Array.from(map.values()) : [];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns all [HoloHash, value] entries for a specific DNA.
|
|
157
|
+
*
|
|
158
|
+
* @param dnaHash - The DNA hash to query
|
|
159
|
+
* @returns Array of entries for this DNA
|
|
160
|
+
*/
|
|
161
|
+
entriesForDna(dnaHash) {
|
|
162
|
+
const map = this._dnaMap.get(dnaHash);
|
|
163
|
+
return map ? Array.from(map.entries()) : [];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Removes all entries for a specific DNA.
|
|
167
|
+
*
|
|
168
|
+
* @param dnaHash - The DNA hash to clear
|
|
169
|
+
*/
|
|
170
|
+
clearForDna(dnaHash) {
|
|
171
|
+
const map = this._dnaMap.get(dnaHash);
|
|
172
|
+
if (map !== undefined) {
|
|
173
|
+
map.clear();
|
|
174
|
+
this._dnaMap.set(dnaHash, map);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The number of DNA entries in the map.
|
|
179
|
+
*
|
|
180
|
+
* @returns The number of unique DNAs
|
|
181
|
+
*/
|
|
182
|
+
get size() {
|
|
183
|
+
return this._dnaMap.size;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export class DnaAgentPubKeyMap extends DnaHoloHashMap {
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
export class DnaDnaHashMap extends DnaHoloHashMap {
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
export class DnaWasmHashMap extends DnaHoloHashMap {
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
export class DnaEntryHashMap extends DnaHoloHashMap {
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
export class DnaActionHashMap extends DnaHoloHashMap {
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export class DnaAnyDhtHashMap extends DnaHoloHashMap {
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
export class DnaExternalHashMap extends DnaHoloHashMap {
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
export class DnaDhtOpHashMap extends DnaHoloHashMap {
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
export class DnaWarrantHashMap extends DnaHoloHashMap {
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
export class CellMap extends DnaAgentPubKeyMap {
|
|
235
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HoloHash, HoloHashType } from "../types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Hash type labels
|
|
3
|
+
* Hash type labels mapped to their 3 byte values (forming the first 3 bytes of hash).
|
|
4
4
|
*
|
|
5
5
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
6
|
*
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
export declare const HASH_TYPE_PREFIX: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
agent: Uint8Array<ArrayBuffer>;
|
|
11
|
+
entry: Uint8Array<ArrayBuffer>;
|
|
12
|
+
dhtop: Uint8Array<ArrayBuffer>;
|
|
13
|
+
warrant: Uint8Array<ArrayBuffer>;
|
|
14
|
+
dna: Uint8Array<ArrayBuffer>;
|
|
15
|
+
action: Uint8Array<ArrayBuffer>;
|
|
16
|
+
wasm: Uint8Array<ArrayBuffer>;
|
|
17
|
+
external: Uint8Array<ArrayBuffer>;
|
|
15
18
|
};
|
|
16
19
|
/**
|
|
17
20
|
* Get hash type (initial 3 bytes) from a hash.
|
|
@@ -23,7 +26,7 @@ export declare const HASH_TYPE_PREFIX: {
|
|
|
23
26
|
*
|
|
24
27
|
* @public
|
|
25
28
|
*/
|
|
26
|
-
export declare function sliceHashType(hash:
|
|
29
|
+
export declare function sliceHashType(hash: HoloHash): Uint8Array;
|
|
27
30
|
/**
|
|
28
31
|
* Get core hash from a Holochain hash (32 bytes).
|
|
29
32
|
*
|
|
@@ -34,7 +37,7 @@ export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash
|
|
|
34
37
|
*
|
|
35
38
|
* @public
|
|
36
39
|
*/
|
|
37
|
-
export declare function sliceCore32(hash:
|
|
40
|
+
export declare function sliceCore32(hash: HoloHash): Uint8Array;
|
|
38
41
|
/**
|
|
39
42
|
* Get DHT location (last 4 bytes) from a hash.
|
|
40
43
|
*
|
|
@@ -45,7 +48,7 @@ export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash):
|
|
|
45
48
|
*
|
|
46
49
|
* @public
|
|
47
50
|
*/
|
|
48
|
-
export declare function sliceDhtLocation(hash:
|
|
51
|
+
export declare function sliceDhtLocation(hash: HoloHash): Uint8Array;
|
|
49
52
|
/**
|
|
50
53
|
* Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes).
|
|
51
54
|
*
|
|
@@ -57,6 +60,17 @@ export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionH
|
|
|
57
60
|
* @public
|
|
58
61
|
*/
|
|
59
62
|
export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* Get hash type of a hash, by reading the first 3 bytes.
|
|
65
|
+
*
|
|
66
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
67
|
+
*
|
|
68
|
+
* @param hash - The full 39 byte hash.
|
|
69
|
+
* @returns The HashType
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export declare function getHashType(hash: HoloHash): HoloHashType;
|
|
60
74
|
/**
|
|
61
75
|
* Generate full hash from a core hash (middle 32 bytes) and hash type label.
|
|
62
76
|
*
|
|
@@ -68,4 +82,16 @@ export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
|
|
|
68
82
|
*
|
|
69
83
|
* @public
|
|
70
84
|
*/
|
|
71
|
-
export declare function hashFrom32AndType(hashCore:
|
|
85
|
+
export declare function hashFrom32AndType(hashCore: HoloHash, hashType: HoloHashType): Uint8Array;
|
|
86
|
+
/**
|
|
87
|
+
* Generate full hash from some data content and hash type label.
|
|
88
|
+
*
|
|
89
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
90
|
+
*
|
|
91
|
+
* @param content - The data to hash.
|
|
92
|
+
* @param hashType - The type of the hash.
|
|
93
|
+
* @returns The full 39 byte hash.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare function hashFromContentAndType(content: any, hashType: HoloHashType): Uint8Array;
|
package/lib/utils/hash-parts.js
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
|
+
import { encode } from "@msgpack/msgpack";
|
|
2
|
+
import { HoloHashType } from "../types.js";
|
|
1
3
|
import blake2b from "@bitgo/blake2b";
|
|
4
|
+
import isEqual from "lodash-es/isEqual.js";
|
|
2
5
|
const HASH_TYPE_START = 0;
|
|
3
6
|
const HASH_TYPE_BYTE_LENGTH = 3;
|
|
4
7
|
const CORE_HASH_BYTE_LENGTH = 32;
|
|
5
8
|
const DHT_LOCATION_BYTE_LENGTH = 4;
|
|
9
|
+
const HASH_TYPE_PREFIX_U8 = {
|
|
10
|
+
[HoloHashType.Agent]: [132, 32, 36],
|
|
11
|
+
[HoloHashType.Entry]: [132, 33, 36],
|
|
12
|
+
[HoloHashType.DhtOp]: [132, 36, 36],
|
|
13
|
+
[HoloHashType.Warrant]: [132, 44, 36],
|
|
14
|
+
[HoloHashType.Dna]: [132, 45, 36],
|
|
15
|
+
[HoloHashType.Action]: [132, 41, 36],
|
|
16
|
+
[HoloHashType.Wasm]: [132, 42, 36],
|
|
17
|
+
[HoloHashType.External]: [132, 47, 36],
|
|
18
|
+
};
|
|
6
19
|
/**
|
|
7
|
-
* Hash type labels
|
|
20
|
+
* Hash type labels mapped to their 3 byte values (forming the first 3 bytes of hash).
|
|
8
21
|
*
|
|
9
22
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
10
23
|
*
|
|
11
24
|
* @public
|
|
12
25
|
*/
|
|
13
26
|
export const HASH_TYPE_PREFIX = {
|
|
14
|
-
Agent: Uint8Array.from([
|
|
15
|
-
Entry: Uint8Array.from([
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
[HoloHashType.Agent]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Agent]),
|
|
28
|
+
[HoloHashType.Entry]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Entry]),
|
|
29
|
+
[HoloHashType.DhtOp]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.DhtOp]),
|
|
30
|
+
[HoloHashType.Warrant]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Warrant]),
|
|
31
|
+
[HoloHashType.Dna]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Dna]),
|
|
32
|
+
[HoloHashType.Action]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Action]),
|
|
33
|
+
[HoloHashType.Wasm]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.Wasm]),
|
|
34
|
+
[HoloHashType.External]: Uint8Array.from(HASH_TYPE_PREFIX_U8[HoloHashType.External]),
|
|
19
35
|
};
|
|
20
36
|
/**
|
|
21
37
|
* Get hash type (initial 3 bytes) from a hash.
|
|
@@ -82,6 +98,24 @@ export function dhtLocationFrom32(hashCore) {
|
|
|
82
98
|
});
|
|
83
99
|
return out;
|
|
84
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Get hash type of a hash, by reading the first 3 bytes.
|
|
103
|
+
*
|
|
104
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
105
|
+
*
|
|
106
|
+
* @param hash - The full 39 byte hash.
|
|
107
|
+
* @returns The HashType
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export function getHashType(hash) {
|
|
112
|
+
const hashTypeBytes = Array.from(hash.slice(0, 3));
|
|
113
|
+
const res = Object.entries(HASH_TYPE_PREFIX_U8).find(([, val]) => isEqual(val, hashTypeBytes));
|
|
114
|
+
if (res === undefined) {
|
|
115
|
+
throw new Error("First 3 bytes of hash do not match any known HashType");
|
|
116
|
+
}
|
|
117
|
+
return res[0];
|
|
118
|
+
}
|
|
85
119
|
/**
|
|
86
120
|
* Generate full hash from a core hash (middle 32 bytes) and hash type label.
|
|
87
121
|
*
|
|
@@ -100,3 +134,23 @@ export function hashFrom32AndType(hashCore, hashType) {
|
|
|
100
134
|
...dhtLocationFrom32(hashCore),
|
|
101
135
|
]);
|
|
102
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Generate full hash from some data content and hash type label.
|
|
139
|
+
*
|
|
140
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
141
|
+
*
|
|
142
|
+
* @param content - The data to hash.
|
|
143
|
+
* @param hashType - The type of the hash.
|
|
144
|
+
* @returns The full 39 byte hash.
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
export function hashFromContentAndType(content, hashType) {
|
|
149
|
+
const hashCore = new Uint8Array(32);
|
|
150
|
+
blake2b(hashCore.length).update(encode(content)).digest(hashCore);
|
|
151
|
+
return Uint8Array.from([
|
|
152
|
+
...HASH_TYPE_PREFIX[hashType],
|
|
153
|
+
...hashCore,
|
|
154
|
+
...dhtLocationFrom32(hashCore),
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { ActionHash, ActionHashB64, AgentPubKey, AgentPubKeyB64, AnyDhtHash, AnyDhtHashB64, DhtOpHash, DhtOpHashB64, DnaHash, DnaHashB64, EntryHash, EntryHashB64, ExternalHash, ExternalHashB64, HoloHash, HoloHashB64, WarrantHash, WarrantHashB64, WasmHash, WasmHashB64 } from "../types.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 declare class HoloHashB64Map<K extends HoloHashB64, V> extends Map<K, V> {
|
|
10
|
+
constructor(initialEntries?: Array<[K, V]>);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare class AgentPubKeyB64Map<V> extends HoloHashB64Map<AgentPubKeyB64, V> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare class DnaHashB64Map<V> extends HoloHashB64Map<DnaHashB64, V> {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare class WasmHashB64Map<V> extends HoloHashB64Map<WasmHashB64, V> {
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare class EntryHashB64Map<V> extends HoloHashB64Map<EntryHashB64, V> {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare class ActionHashB64Map<V> extends HoloHashB64Map<ActionHashB64, V> {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare class AnyDhtHashB64Map<V> extends HoloHashB64Map<AnyDhtHashB64, V> {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare class ExternalHashB64Map<V> extends HoloHashB64Map<ExternalHashB64, V> {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare class DhtOpHashB64Map<V> extends HoloHashB64Map<DhtOpHashB64, V> {
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export declare class WarrantHashB64Map<V> extends HoloHashB64Map<WarrantHashB64, V> {
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A Map of HoloHash to a value.
|
|
59
|
+
*
|
|
60
|
+
* @param initialEntries - Optional array of [key, value] pairs to insert into the map.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare class HoloHashMap<K extends HoloHash, V> implements Map<K, V> {
|
|
65
|
+
private _map;
|
|
66
|
+
constructor(initialEntries?: Array<[K, V]>);
|
|
67
|
+
/**
|
|
68
|
+
* Removes all entries from the map.
|
|
69
|
+
*/
|
|
70
|
+
clear(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns an iterator of values in the map.
|
|
73
|
+
*
|
|
74
|
+
* @returns An iterator of all values
|
|
75
|
+
*/
|
|
76
|
+
values(): MapIterator<V>;
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a key exists in the map.
|
|
79
|
+
*
|
|
80
|
+
* @param key - The HoloHash key to check
|
|
81
|
+
* @returns True if the key exists, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
has(key: K): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the value associated with a key.
|
|
86
|
+
*
|
|
87
|
+
* @param key - The HoloHash key
|
|
88
|
+
* @returns The value if found, undefined otherwise
|
|
89
|
+
*/
|
|
90
|
+
get(key: K): V | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Sets a key-value pair in the map.
|
|
93
|
+
*
|
|
94
|
+
* @param key - The HoloHash key
|
|
95
|
+
* @param value - The value to store
|
|
96
|
+
* @returns This map instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
set(key: K, value: V): this;
|
|
99
|
+
/**
|
|
100
|
+
* Deletes an entry from the map.
|
|
101
|
+
*
|
|
102
|
+
* @param key - The HoloHash key to delete
|
|
103
|
+
* @returns True if the entry was deleted, false if it didn't exist
|
|
104
|
+
*/
|
|
105
|
+
delete(key: K): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Returns an iterator of keys in the map.
|
|
108
|
+
*
|
|
109
|
+
* @returns An iterator of all HoloHash keys
|
|
110
|
+
*/
|
|
111
|
+
keys(): MapIterator<K>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns an iterator of [key, value] pairs.
|
|
114
|
+
*
|
|
115
|
+
* @returns An iterator of all entries
|
|
116
|
+
*/
|
|
117
|
+
entries(): MapIterator<[K, V]>;
|
|
118
|
+
/**
|
|
119
|
+
* Executes a callback function for each entry in the map.
|
|
120
|
+
*
|
|
121
|
+
* @param callbackfn - Function to execute for each entry
|
|
122
|
+
* @param thisArg - Optional value to use as 'this' when executing the callback
|
|
123
|
+
*/
|
|
124
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
125
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
126
|
+
get [Symbol.toStringTag](): string;
|
|
127
|
+
/**
|
|
128
|
+
* The number of entries in the map.
|
|
129
|
+
*
|
|
130
|
+
* @returns The size of the map
|
|
131
|
+
*/
|
|
132
|
+
get size(): number;
|
|
133
|
+
private _encodeKey;
|
|
134
|
+
private _decodeKey;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
export declare class AgentPubKeyMap<V> extends HoloHashMap<AgentPubKey, V> {
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
export declare class DnaHashMap<V> extends HoloHashMap<DnaHash, V> {
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export declare class WasmHashMap<V> extends HoloHashMap<WasmHash, V> {
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export declare class EntryHashMap<V> extends HoloHashMap<EntryHash, V> {
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
export declare class ActionHashMap<V> extends HoloHashMap<ActionHash, V> {
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export declare class AnyDhtHashMap<V> extends HoloHashMap<AnyDhtHash, V> {
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
export declare class ExternalHashMap<V> extends HoloHashMap<ExternalHash, V> {
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
export declare class DhtOpHashMap<V> extends HoloHashMap<DhtOpHash, V> {
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
export declare class WarrantHashMap<V> extends HoloHashMap<WarrantHash, V> {
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A HoloHashMap that will fetch and store a value if it is not found in a 'get' call.
|
|
183
|
+
*
|
|
184
|
+
* @param fetchValue - A function that takes a key and fetches its value.
|
|
185
|
+
* @param initialEntries - Optional array of [key, value] pairs to insert into the map.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export declare class LazyHoloHashMap<K extends HoloHash, V> extends HoloHashMap<K, V> {
|
|
190
|
+
protected fetchValue: (key: K) => V | undefined;
|
|
191
|
+
constructor(fetchValue: (key: K) => V | undefined, initialEntries?: Array<[K, V]>);
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* Get a value for a key.
|
|
195
|
+
*
|
|
196
|
+
* If no value for a key is found, it is fetched, inserted into the Map, then returned.
|
|
197
|
+
*
|
|
198
|
+
* @param key - HoloHash key
|
|
199
|
+
* @returns value if found
|
|
200
|
+
*/
|
|
201
|
+
get(key: K): V | undefined;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
export declare class LazyAgentPubKeyMap<V> extends LazyHoloHashMap<AgentPubKey, V> {
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export declare class LazyDnaHashMap<V> extends LazyHoloHashMap<DnaHash, V> {
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
export declare class LazyWasmHashMap<V> extends LazyHoloHashMap<WasmHash, V> {
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
export declare class LazyEntryHashMap<V> extends LazyHoloHashMap<EntryHash, V> {
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
export declare class LazyActionHashMap<V> extends LazyHoloHashMap<ActionHash, V> {
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
export declare class LazyAnyDhtHashMap<V> extends LazyHoloHashMap<AnyDhtHash, V> {
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
export declare class LazyExternalHashMap<V> extends LazyHoloHashMap<ExternalHash, V> {
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export declare class LazyDhtOpHashMap<V> extends LazyHoloHashMap<DhtOpHash, V> {
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
export declare class LazyWarrantHashMap<V> extends LazyHoloHashMap<WarrantHash, V> {
|
|
247
|
+
}
|