@ddd-qc/cell-proxy 0.25.0 → 0.25.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/dist/cell.js CHANGED
@@ -1,5 +1,6 @@
1
- import { CellType, encodeHashToBase64 } from "@holochain/client";
1
+ import { CellType } from "@holochain/client";
2
2
  import { HCL } from "./hcl";
3
+ import { AgentId, DnaId, enc64 } from "./hash";
3
4
  /**
4
5
  * Common interface between Provisioned and Cloned cells
5
6
  */
@@ -7,7 +8,7 @@ export class Cell {
7
8
  /** */
8
9
  static from(cellInfo, appId, baseRoleName) {
9
10
  if (CellType.Stem in cellInfo) {
10
- const id = cellInfo.stem.name ? cellInfo.stem.name : encodeHashToBase64(cellInfo.stem.dna);
11
+ const id = cellInfo.stem.name ? cellInfo.stem.name : enc64(cellInfo.stem.dna);
11
12
  throw Error("StemCell cannot be converted to Cell: " + id);
12
13
  }
13
14
  if (CellType.Cloned in cellInfo) {
@@ -23,8 +24,8 @@ export class Cell {
23
24
  }
24
25
  /** -- Getters -- */
25
26
  get id() { return this._cell.cell_id; }
26
- get dnaHash() { return encodeHashToBase64(this.id[0]); }
27
- get agentPubKey() { return encodeHashToBase64(this.id[1]); }
27
+ get dnaId() { return new DnaId(this.id[0]); }
28
+ get agentId() { return new AgentId(this.id[1]); }
28
29
  get name() { return this._cell.name; }
29
30
  get dnaModifiers() { return this._cell.dna_modifiers; }
30
31
  /** ex: rNamedInteger.0 */
@@ -45,7 +46,7 @@ export class Cell {
45
46
  }
46
47
  /** */
47
48
  print() {
48
- return `Cell "${this.name}${this.cloneId ? "." + this.cloneId : ""}": ${this.dnaHash}`;
49
+ return `Cell "${this.name}${this.cloneId ? "." + this.cloneId : ""}": ${this.dnaId.short}`;
49
50
  }
50
51
  }
51
52
  /** ... */
package/dist/cell.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cell.js","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA,O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;QAC/B,OAAO,QAAQ,CAAC,MAAM,CAAC;KACxB;IACD,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,EAAE;QACpC,OAAO,QAAQ,CAAC,WAAW,CAAC;KAC7B;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import {\n AgentPubKeyB64,\n CellId,\n CellInfo,\n CellType,\n DnaHashB64,\n DnaModifiers,\n encodeHashToBase64,\n ProvisionedCell, StemCell, ClonedCell, InstalledAppId\n} from \"@holochain/client\";\nimport {RoleName} from \"@holochain/client/lib/types\";\nimport {HCL} from \"./hcl\";\nimport {BaseRoleName} from \"./types\";\n\n\nexport type AnyCell = ProvisionedCell | ClonedCell;\n\n\n/**\n * Common interface between Provisioned and Cloned cells\n */\nexport class Cell {\n\n /** */\n static from(cellInfo: CellInfo, appId: InstalledAppId, baseRoleName: BaseRoleName): Cell {\n if (CellType.Stem in cellInfo) {\n const id = cellInfo.stem.name? cellInfo.stem.name : encodeHashToBase64(cellInfo.stem.dna);\n throw Error(\"StemCell cannot be converted to Cell: \" + id);\n }\n if (CellType.Cloned in cellInfo) {\n return new Cell(cellInfo.cloned, appId, baseRoleName);\n }\n return new Cell(cellInfo.provisioned, appId, baseRoleName);\n }\n\n\n /** Ctor */\n constructor(private readonly _cell: AnyCell, public readonly appId: InstalledAppId, public readonly baseRoleName: BaseRoleName) {}\n\n\n /** -- Getters -- */\n\n get id(): CellId { return (this._cell as any).cell_id }\n get dnaHash(): DnaHashB64 { return encodeHashToBase64(this.id[0]) }\n get agentPubKey(): AgentPubKeyB64 { return encodeHashToBase64(this.id[1]) }\n get name(): string {return (this._cell as any).name}\n get dnaModifiers(): DnaModifiers {return (this._cell as any).dna_modifiers}\n\n /** ex: rNamedInteger.0 */\n get cloneId(): RoleName | undefined { return (this._cell as any).clone_id }\n\n\n /** -- Methods -- */\n\n hcl(): HCL {return new HCL(this.appId, this.baseRoleName, this.cloneId)}\n\n asCloned(): ClonedCell | null {\n if (!this.cloneId) { return null}\n return this._cell as ClonedCell;\n }\n\n asProvisioned(): ProvisionedCell | null {\n if (this.cloneId) { return null}\n return this._cell as ProvisionedCell;\n }\n\n /** */\n print(): string {\n return `Cell \"${this.name}${this.cloneId? \".\" + this.cloneId: \"\"}\": ${this.dnaHash}`;\n }\n}\n\n\n\n/** ... */\nexport function intoStem(cellInfo: CellInfo): StemCell | undefined {\n if (CellType.Stem in cellInfo) {\n return cellInfo.stem;\n }\n return undefined\n}\n\n/** ... */\nexport function asCell(cellInfo: CellInfo): AnyCell | undefined {\n if (CellType.Stem in cellInfo) {\n return undefined;\n }\n if (CellType.Cloned in cellInfo) {\n return cellInfo.cloned;\n }\n if (CellType.Provisioned in cellInfo) {\n return cellInfo.provisioned;\n }\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"cell.js","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,QAAQ,CAAC;AAM7C;;GAEG;AACH,MAAM,OAAO,IAAI;IAEf,MAAM;IACN,MAAM,CAAC,IAAI,CAAC,QAAkB,EAAE,KAAqB,EAAE,YAA0B;QAC/E,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,EAAE;YAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAA,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7E,MAAM,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAC;SAC5D;QACD,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,EAAE;YAC/B,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,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QAChC,OAAO,IAAI,CAAC,KAAwB,CAAC;IACvC,CAAC;IAED,MAAM;IACN,KAAK;QACH,OAAO,SAAS,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3F,CAAC;CACF;AAID,UAAU;AACV,MAAM,UAAU,QAAQ,CAAC,QAAkB;IACzC,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,EAAE;QAC7B,OAAO,QAAQ,CAAC,IAAI,CAAC;KACtB;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,UAAU;AACV,MAAM,UAAU,MAAM,CAAC,QAAkB;IACvC,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,EAAE;QAC7B,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,EAAE;QAC/B,OAAO,QAAQ,CAAC,MAAM,CAAC;KACxB;IACD,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,EAAE;QACpC,OAAO,QAAQ,CAAC,WAAW,CAAC;KAC7B;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import {\n CellId,\n CellInfo,\n CellType,\n DnaModifiers,\n ProvisionedCell, StemCell, ClonedCell, InstalledAppId\n} from \"@holochain/client\";\nimport {RoleName} from \"@holochain/client/lib/types\";\nimport {HCL} from \"./hcl\";\nimport {BaseRoleName} from \"./types\";\nimport {AgentId, DnaId, enc64} from \"./hash\";\n\n\nexport type AnyCell = ProvisionedCell | ClonedCell;\n\n\n/**\n * Common interface between Provisioned and Cloned cells\n */\nexport class Cell {\n\n /** */\n static from(cellInfo: CellInfo, appId: InstalledAppId, baseRoleName: BaseRoleName): Cell {\n if (CellType.Stem in cellInfo) {\n const id = cellInfo.stem.name? cellInfo.stem.name : enc64(cellInfo.stem.dna);\n throw Error(\"StemCell cannot be converted to Cell: \" + id);\n }\n if (CellType.Cloned in cellInfo) {\n return new Cell(cellInfo.cloned, appId, baseRoleName);\n }\n return new Cell(cellInfo.provisioned, appId, baseRoleName);\n }\n\n\n /** Ctor */\n constructor(private readonly _cell: AnyCell, public readonly appId: InstalledAppId, public readonly baseRoleName: BaseRoleName) {}\n\n\n /** -- Getters -- */\n\n get id(): CellId { return (this._cell as any).cell_id }\n get dnaId(): DnaId { return new DnaId(this.id[0]) }\n get agentId(): AgentId { return new AgentId(this.id[1]) }\n get name(): string {return (this._cell as any).name}\n get dnaModifiers(): DnaModifiers {return (this._cell as any).dna_modifiers}\n\n /** ex: rNamedInteger.0 */\n get cloneId(): RoleName | undefined { return (this._cell as any).clone_id }\n\n\n /** -- Methods -- */\n\n hcl(): HCL {return new HCL(this.appId, this.baseRoleName, this.cloneId)}\n\n asCloned(): ClonedCell | null {\n if (!this.cloneId) { return null}\n return this._cell as ClonedCell;\n }\n\n asProvisioned(): ProvisionedCell | null {\n if (this.cloneId) { return null}\n return this._cell as ProvisionedCell;\n }\n\n /** */\n print(): string {\n return `Cell \"${this.name}${this.cloneId? \".\" + this.cloneId: \"\"}\": ${this.dnaId.short}`;\n }\n}\n\n\n\n/** ... */\nexport function intoStem(cellInfo: CellInfo): StemCell | undefined {\n if (CellType.Stem in cellInfo) {\n return cellInfo.stem;\n }\n return undefined\n}\n\n/** ... */\nexport function asCell(cellInfo: CellInfo): AnyCell | undefined {\n if (CellType.Stem in cellInfo) {\n return undefined;\n }\n if (CellType.Cloned in cellInfo) {\n return cellInfo.cloned;\n }\n if (CellType.Provisioned in cellInfo) {\n return cellInfo.provisioned;\n }\n return undefined;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { HoloHashB64 } from "@holochain/client";
2
+ /** */
3
+ export declare enum DatumValidity {
4
+ None = "None",
5
+ Self = "Self",
6
+ Network = "Network"
7
+ }
8
+ /** */
9
+ export declare enum DatumStorageLocations {
10
+ None = 0,
11
+ Memory = 1,
12
+ Disk = 2,
13
+ SourceChain = 4,
14
+ Cache = 8,
15
+ Dht = 16
16
+ }
17
+ /**
18
+ *
19
+ */
20
+ export declare class DatumMap<K extends HoloHashB64, V> {
21
+ _map: Map<K, [V, DatumValidity, DatumStorageLocations]>;
22
+ constructor(initialEntries?: Array<[K, V]>);
23
+ has(key: K): boolean;
24
+ getDetails(key: K): [V, DatumValidity, DatumStorageLocations];
25
+ get(key: K): V;
26
+ set(key: K, value: V, validity: DatumValidity, storage: DatumStorageLocations): void;
27
+ delete(key: K): boolean;
28
+ keys(): IterableIterator<K>;
29
+ values(): V[];
30
+ entries(): [K, V][];
31
+ clear(): void;
32
+ forEach(callbackfn: (value: V, key: K, map: Map<K, [V, DatumValidity, DatumStorageLocations]>) => void, thisArg?: any): void;
33
+ get size(): number;
34
+ get [Symbol.toStringTag](): string;
35
+ }
@@ -0,0 +1,77 @@
1
+ /** */
2
+ export var DatumValidity;
3
+ (function (DatumValidity) {
4
+ DatumValidity["None"] = "None";
5
+ DatumValidity["Self"] = "Self";
6
+ DatumValidity["Network"] = "Network";
7
+ })(DatumValidity || (DatumValidity = {}));
8
+ /** */
9
+ export var DatumStorageLocations;
10
+ (function (DatumStorageLocations) {
11
+ DatumStorageLocations[DatumStorageLocations["None"] = 0] = "None";
12
+ DatumStorageLocations[DatumStorageLocations["Memory"] = 1] = "Memory";
13
+ DatumStorageLocations[DatumStorageLocations["Disk"] = 2] = "Disk";
14
+ DatumStorageLocations[DatumStorageLocations["SourceChain"] = 4] = "SourceChain";
15
+ DatumStorageLocations[DatumStorageLocations["Cache"] = 8] = "Cache";
16
+ DatumStorageLocations[DatumStorageLocations["Dht"] = 16] = "Dht";
17
+ })(DatumStorageLocations || (DatumStorageLocations = {}));
18
+ /**
19
+ *
20
+ */
21
+ export class DatumMap {
22
+ constructor(initialEntries) {
23
+ this._map = new Map();
24
+ if (initialEntries) {
25
+ for (const [key, value] of initialEntries) {
26
+ this.set(key, value, DatumValidity.None, DatumStorageLocations.Memory);
27
+ }
28
+ }
29
+ }
30
+ has(key) {
31
+ return this._map.has(key);
32
+ }
33
+ getDetails(key) {
34
+ return this._map.get(key);
35
+ }
36
+ get(key) {
37
+ return this._map.get(key)[0];
38
+ }
39
+ set(key, value, validity, storage) {
40
+ this._map.set(key, [value, validity, storage]);
41
+ }
42
+ delete(key) {
43
+ return this._map.delete(key);
44
+ }
45
+ keys() {
46
+ return this._map.keys();
47
+ }
48
+ values() {
49
+ return Array.from(this._map.values()).map((tuple) => tuple[0]);
50
+ }
51
+ entries() {
52
+ return Array.from(this._map.entries())
53
+ .map(([h, v]) => [h, v[0]]);
54
+ }
55
+ clear() {
56
+ return this._map.clear();
57
+ }
58
+ forEach(callbackfn, thisArg) {
59
+ return this._map.forEach((value, key) => {
60
+ callbackfn(value[0], key, this._map);
61
+ }, thisArg);
62
+ }
63
+ get size() {
64
+ return this._map.size;
65
+ }
66
+ // [Symbol.iterator](): IterableIterator<[K, V]> {
67
+ // return this.entries();
68
+ // }
69
+ get [Symbol.toStringTag]() {
70
+ return this._map[Symbol.toStringTag];
71
+ }
72
+ }
73
+ // export class EntryHashMap<T> extends DatumMap<EntryHashB64, T> {}
74
+ // export class ActionHashMap<T> extends DatumMap<ActionHashB64, T> {}
75
+ // export class AgentPubKeyMap<T> extends DatumMap<AgentPubKeyB64, T> {}
76
+ // export class DnaHashMap<T> extends DatumMap<DnaHashB64, T> {}
77
+ //# sourceMappingURL=datum-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datum-map.js","sourceRoot":"","sources":["../src/datum-map.ts"],"names":[],"mappings":"AAMA,MAAM;AACN,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,8BAAa,CAAA;IACb,oCAAmB,CAAA;AACrB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAGD,MAAM;AACN,MAAM,CAAN,IAAY,qBAOX;AAPD,WAAY,qBAAqB;IAC/B,iE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AI,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,CACL,UAA8F,EAC9F,OAAa;QAEb,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACtC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC,EAAE,OAAO,CAAC,CAAC;IACd,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,kDAAkD;IAClD,2BAA2B;IAC3B,IAAI;IAEJ,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;CACF;AAED,oEAAoE;AACpE,sEAAsE;AACtE,wEAAwE;AACxE,gEAAgE","sourcesContent":["\nimport {\n HoloHashB64,\n} from \"@holochain/client\";\n\n\n/** */\nexport enum DatumValidity {\n None = \"None\",\n Self = \"Self\",\n Network = \"Network\",\n}\n\n\n/** */\nexport enum DatumStorageLocations {\n None = 0,\n Memory = 1 << 0,\n Disk = 1 << 1,\n SourceChain = 1 << 2,\n Cache = 1 << 3,\n Dht = 1 << 4,\n}\n\n\n/**\n *\n */\nexport class DatumMap<K extends HoloHashB64, V> {\n _map: Map<K, [V, DatumValidity, DatumStorageLocations]>;\n\n constructor(initialEntries?: Array<[K, V]>) {\n this._map = new Map();\n if (initialEntries) {\n for (const [key, value] of initialEntries) {\n this.set(key, value, DatumValidity.None, DatumStorageLocations.Memory);\n }\n }\n }\n\n has(key: K): boolean {\n return this._map.has(key);\n }\n\n getDetails(key: K): [V, DatumValidity, DatumStorageLocations] {\n return this._map.get(key);\n }\n\n get(key: K): V {\n return this._map.get(key)[0];\n }\n\n set(key: K, value: V, validity: DatumValidity, storage: DatumStorageLocations) {\n this._map.set(key, [value, validity, storage]);\n }\n\n delete(key: K) {\n return this._map.delete(key);\n }\n\n keys() {\n return this._map.keys()\n }\n\n values() {\n return Array.from(this._map.values()).map((tuple) => tuple[0]);\n }\n\n entries() {\n return Array.from(this._map.entries())\n .map(([h, v]) => [h, v[0]] as [K, V]);\n }\n\n clear() {\n return this._map.clear();\n }\n\n forEach(\n callbackfn: (value: V, key: K, map: Map<K, [V, DatumValidity, DatumStorageLocations]>) => void,\n thisArg?: any\n ): void {\n return this._map.forEach((value, key) => {\n callbackfn(value[0], key, this._map);\n }, thisArg);\n }\n\n get size() {\n return this._map.size;\n }\n\n // [Symbol.iterator](): IterableIterator<[K, V]> {\n // return this.entries();\n // }\n\n get [Symbol.toStringTag](): string {\n return this._map[Symbol.toStringTag];\n }\n}\n\n// export class EntryHashMap<T> extends DatumMap<EntryHashB64, T> {}\n// export class ActionHashMap<T> extends DatumMap<ActionHashB64, T> {}\n// export class AgentPubKeyMap<T> extends DatumMap<AgentPubKeyB64, T> {}\n// export class DnaHashMap<T> extends DatumMap<DnaHashB64, T> {}\n"]}
package/dist/hash.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ import { HoloHash, HoloHashB64 } from "@holochain/client";
2
+ /**
3
+ * Checks if obj is a Hash or list of hashes and tries to convert it a B64 or list of B64
4
+ */
5
+ export declare function anyToB64(obj: any): any;
6
+ /** ------------------------------------------------------------------------------------------------------------------*/
7
+ export declare enum HoloHashType {
8
+ Action = "Action",
9
+ Agent = "Agent",
10
+ Dna = "Dna",
11
+ Entry = "Entry",
12
+ External = "External",
13
+ Network = "Network",
14
+ Wasm = "Wasm"
15
+ }
16
+ export declare const HASH_TYPE_PREFIX_B64: {
17
+ Action: string;
18
+ Agent: string;
19
+ Dna: string;
20
+ Entry: string;
21
+ External: string;
22
+ Network: string;
23
+ Wasm: string;
24
+ };
25
+ export declare function getHashType(hash: HoloHashB64): HoloHashType;
26
+ /** */
27
+ export declare function isHashTypeB64(hash: HoloHashB64, hashType: HoloHashType): boolean;
28
+ export declare function hasHoloHashType(hash: HoloHashB64): boolean;
29
+ /** */
30
+ export declare function validateHashB64(hash: HoloHashB64): void;
31
+ export declare function dec64(hash: HoloHashB64): HoloHash;
32
+ export declare function enc64(hash: HoloHash): HoloHashB64;
33
+ /** HoloHash starts with 'u' has a type and is 53 chars long */
34
+ export declare abstract class HolochainId {
35
+ readonly type: HoloHashType;
36
+ readonly b64: HoloHashB64;
37
+ /** Validate */
38
+ constructor(input: HoloHashB64 | HoloHash, type: HoloHashType);
39
+ get hash(): HoloHash;
40
+ /** First 8 chars of the Core */
41
+ get short(): string;
42
+ toString(): string;
43
+ print(): string;
44
+ }
45
+ /** Mixin */
46
+ export declare function createHolochainId(hashType: HoloHashType): {
47
+ new (input: HoloHashB64 | HoloHash): {
48
+ readonly b64: string;
49
+ readonly type: HoloHashType;
50
+ readonly hash: Uint8Array;
51
+ /** First 8 chars of the Core */
52
+ readonly short: string;
53
+ toString(): string;
54
+ print(): string;
55
+ };
56
+ };
57
+ declare const ActionId_base: {
58
+ new (input: string | Uint8Array): {
59
+ readonly b64: string;
60
+ readonly type: HoloHashType;
61
+ readonly hash: Uint8Array;
62
+ /** First 8 chars of the Core */
63
+ readonly short: string;
64
+ toString(): string;
65
+ print(): string;
66
+ };
67
+ };
68
+ export declare class ActionId extends ActionId_base {
69
+ }
70
+ declare const AgentId_base: {
71
+ new (input: string | Uint8Array): {
72
+ readonly b64: string;
73
+ readonly type: HoloHashType;
74
+ readonly hash: Uint8Array;
75
+ /** First 8 chars of the Core */
76
+ readonly short: string;
77
+ toString(): string;
78
+ print(): string;
79
+ };
80
+ };
81
+ export declare class AgentId extends AgentId_base {
82
+ }
83
+ declare const DnaId_base: {
84
+ new (input: string | Uint8Array): {
85
+ readonly b64: string;
86
+ readonly type: HoloHashType;
87
+ readonly hash: Uint8Array;
88
+ /** First 8 chars of the Core */
89
+ readonly short: string;
90
+ toString(): string;
91
+ print(): string;
92
+ };
93
+ };
94
+ export declare class DnaId extends DnaId_base {
95
+ }
96
+ declare const EntryId_base: {
97
+ new (input: string | Uint8Array): {
98
+ readonly b64: string;
99
+ readonly type: HoloHashType;
100
+ readonly hash: Uint8Array;
101
+ /** First 8 chars of the Core */
102
+ readonly short: string;
103
+ toString(): string;
104
+ print(): string;
105
+ };
106
+ };
107
+ export declare class EntryId extends EntryId_base {
108
+ }
109
+ declare const ExternalId_base: {
110
+ new (input: string | Uint8Array): {
111
+ readonly b64: string;
112
+ readonly type: HoloHashType;
113
+ readonly hash: Uint8Array;
114
+ /** First 8 chars of the Core */
115
+ readonly short: string;
116
+ toString(): string;
117
+ print(): string;
118
+ };
119
+ };
120
+ export declare class ExternalId extends ExternalId_base {
121
+ }
122
+ export type AnyDhtId = ActionId | EntryId;
123
+ export type AnyLinkableId = AnyDhtId | ExternalId;
124
+ /** */
125
+ export declare function intoDhtId(input: HoloHashB64 | HoloHash): AnyDhtId;
126
+ /** */
127
+ export declare function intoLinkableId(input: HoloHashB64 | HoloHash): AnyLinkableId;
128
+ export {};
129
+ /** ------- */
package/dist/hash.js ADDED
@@ -0,0 +1,246 @@
1
+ import { decodeHashFromBase64, encodeHashToBase64 } from "@holochain/client";
2
+ /**
3
+ * Checks if obj is a Hash or list of hashes and tries to convert it a B64 or list of B64
4
+ */
5
+ export function anyToB64(obj) {
6
+ /** Check if it's a hash */
7
+ if (obj instanceof Uint8Array) {
8
+ return encodeHashToBase64(obj);
9
+ }
10
+ else {
11
+ /** Check if it's an array of hashes */
12
+ if (Array.isArray(obj)) {
13
+ const isUint8Array = obj.length > 0 &&
14
+ obj.every((value) => {
15
+ return value instanceof Uint8Array;
16
+ });
17
+ if (isUint8Array) {
18
+ let result = [];
19
+ for (const cur of obj) {
20
+ result.push(encodeHashToBase64(cur));
21
+ }
22
+ return result;
23
+ }
24
+ }
25
+ }
26
+ return obj;
27
+ }
28
+ /** ------------------------------------------------------------------------------------------------------------------*/
29
+ export var HoloHashType;
30
+ (function (HoloHashType) {
31
+ HoloHashType["Action"] = "Action";
32
+ HoloHashType["Agent"] = "Agent";
33
+ //DhtOp = "DhtOp",
34
+ HoloHashType["Dna"] = "Dna";
35
+ HoloHashType["Entry"] = "Entry";
36
+ HoloHashType["External"] = "External";
37
+ HoloHashType["Network"] = "Network";
38
+ //Warrent = "Warrent",
39
+ HoloHashType["Wasm"] = "Wasm";
40
+ })(HoloHashType || (HoloHashType = {}));
41
+ export const HASH_TYPE_PREFIX_B64 = {
42
+ Action: "uhCkk",
43
+ Agent: "uhCAk",
44
+ Dna: "uhC0k",
45
+ //DhtOp: "hCQk",
46
+ Entry: "uhCEk",
47
+ External: "uhC8k",
48
+ Network: "uhCIk",
49
+ //Warrent: "Warrent",
50
+ Wasm: "uhCok",
51
+ };
52
+ export function getHashType(hash) {
53
+ const hashExt = hash.slice(0, 5);
54
+ const hashPrefixes = Object.values(HASH_TYPE_PREFIX_B64);
55
+ for (let i = 0; i < hashPrefixes.length; i += 1) {
56
+ if (hashPrefixes[i] == hashExt) {
57
+ return Object.keys(HASH_TYPE_PREFIX_B64)[i];
58
+ }
59
+ }
60
+ throw Error("Unknown hash type");
61
+ }
62
+ /** */
63
+ export function isHashTypeB64(hash, hashType) {
64
+ const slice = hash.slice(0, 5);
65
+ const prefix = HASH_TYPE_PREFIX_B64[hashType];
66
+ for (let i = 0; i < prefix.length; i++) {
67
+ if (slice[i] !== prefix[i]) {
68
+ return false;
69
+ }
70
+ }
71
+ return true;
72
+ }
73
+ export function hasHoloHashType(hash) {
74
+ return !!Object.values(HASH_TYPE_PREFIX_B64).find((prefix) => hash.startsWith(`${prefix}`));
75
+ }
76
+ /** */
77
+ export function validateHashB64(hash) {
78
+ if (!hash || typeof (hash) != 'string') {
79
+ throw new Error("The hash must be a valid string");
80
+ }
81
+ if (hash.length !== 53) {
82
+ throw new Error("The hash must be exactly 53 characters long.");
83
+ }
84
+ if (!hasHoloHashType(hash)) {
85
+ throw new Error("The hash must have a valid HoloHash type.");
86
+ }
87
+ }
88
+ export function dec64(hash) {
89
+ validateHashB64(hash);
90
+ return decodeHashFromBase64(hash);
91
+ }
92
+ export function enc64(hash) {
93
+ let b64 = encodeHashToBase64(hash);
94
+ validateHashB64(b64);
95
+ return b64;
96
+ }
97
+ /** HoloHash starts with 'u' has a type and is 53 chars long */
98
+ export class HolochainId {
99
+ //private readonly hash: HoloHash;
100
+ /** Validate */
101
+ constructor(input, type) {
102
+ this.type = type;
103
+ if (typeof (input) != 'string') {
104
+ input = encodeHashToBase64(input);
105
+ }
106
+ validateHashB64(input);
107
+ this.b64 = input;
108
+ }
109
+ get hash() { return dec64(this.b64); }
110
+ /** First 8 chars of the Core */
111
+ get short() { return this.b64.slice(5, 13); }
112
+ toString() { return this.b64; }
113
+ print() { return `${this.short} (${this.type})`; }
114
+ }
115
+ /** Mixin */
116
+ export function createHolochainId(hashType) {
117
+ class AHoloId extends HolochainId {
118
+ constructor(input) {
119
+ super(input, hashType);
120
+ const type = getHashType(this.b64);
121
+ if (hashType != type) {
122
+ throw new Error('The hash does not have the correct type. Expected ' + hashType + ', got' + type);
123
+ }
124
+ }
125
+ }
126
+ /** */
127
+ return AHoloId;
128
+ }
129
+ export class ActionId extends createHolochainId(HoloHashType.Action) {
130
+ }
131
+ export class AgentId extends createHolochainId(HoloHashType.Agent) {
132
+ }
133
+ export class DnaId extends createHolochainId(HoloHashType.Dna) {
134
+ }
135
+ export class EntryId extends createHolochainId(HoloHashType.Entry) {
136
+ }
137
+ export class ExternalId extends createHolochainId(HoloHashType.External) {
138
+ }
139
+ /** */
140
+ export function intoDhtId(input) {
141
+ try {
142
+ const actionId = new ActionId(input);
143
+ return actionId;
144
+ }
145
+ catch (e) {
146
+ const entryId = new EntryId(input);
147
+ return entryId;
148
+ }
149
+ }
150
+ /** */
151
+ export function intoLinkableId(input) {
152
+ try {
153
+ const dhtId = intoDhtId(input);
154
+ return dhtId;
155
+ }
156
+ catch (e) {
157
+ const externalId = new ExternalId(input);
158
+ return externalId;
159
+ }
160
+ }
161
+ //
162
+ // /** */
163
+ // export class DnaId extends HoloId {
164
+ // constructor(input: HoloHashB64 | HoloHash) {
165
+ // super(input, HoloHashType.Dna);
166
+ // const type = getHashType(this.value);
167
+ // if (HoloHashType.Dna != type) {
168
+ // throw new Error('The hash does not have the "Dna" type');
169
+ // }
170
+ // }
171
+ // }
172
+ //
173
+ //
174
+ // /** */
175
+ // export class AgentId extends HoloId {
176
+ // constructor(input: HoloHashB64 | HoloHash) {
177
+ // super(input, HoloHashType.Agent);
178
+ // const type = getHashType(this.value);
179
+ // if (HoloHashType.Agent != type) {
180
+ // throw new Error('The hash does not have the "Agent" type');
181
+ // }
182
+ // }
183
+ // }
184
+ /** ------- */
185
+ // export type HoloIdConstructor<T = {}> = new (input: HoloHashB64 | HoloHash) => T;
186
+ //
187
+ // export function HoloIdMixin<TBase extends GConstructor>(Base: TBase) {
188
+ // class AHoloId extends Base {
189
+ // public readonly b64: HoloHashB64;
190
+ //
191
+ // //constructor(...args: any[]) {super(args[0])}
192
+ //
193
+ // /** Validate */
194
+ // constructor(...args: any[]) {
195
+ // super(args);
196
+ // if (args.length != 1) {
197
+ // throw new Error("HoloId ctor must have exactly 1 argument.");
198
+ // }
199
+ // let input = args[0];
200
+ // if (typeof (input) != 'string') {
201
+ // input = enc64(input);
202
+ // }
203
+ // this.b64 = input;
204
+ // if (this.b64.length !== 53) {
205
+ // throw new Error("The hash must be exactly 53 characters long.");
206
+ // }
207
+ // }
208
+ //
209
+ // get hash(): HoloHash {
210
+ // return dec64(this.b64)
211
+ // }
212
+ //
213
+ // /** First 8 chars of the Core */
214
+ // get short(): string {
215
+ // return this.b64.slice(5, 13);
216
+ // }
217
+ // }
218
+ // return AHoloId;
219
+ // }
220
+ //
221
+ // export const HoloId = HoloIdMixin(Empty);
222
+ //
223
+ //
224
+ // /** */
225
+ // export class AgentId extends HoloId {
226
+ // constructor(input: HoloHashB64 | HoloHash) {
227
+ // super(input, HoloHashType.Agent);
228
+ // const type = getHashType(this.b64);
229
+ // if (HoloHashType.Agent != type) {
230
+ // throw new Error('The hash does not have the correct type: ' + HoloHashType.Agent);
231
+ // }
232
+ // }
233
+ // }
234
+ //
235
+ //
236
+ // /** */
237
+ // export class DnaId extends HoloIdMixin(Empty) {
238
+ // constructor(input: HoloHashB64 | HoloHash) {
239
+ // super(input, HoloHashType.Dna);
240
+ // const type = getHashType(this.b64);
241
+ // if (HoloHashType.Dna != type) {
242
+ // throw new Error('The hash does not have the correct type: ' + HoloHashType.Dna);
243
+ // }
244
+ // }
245
+ // }
246
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAwB,MAAM,mBAAmB,CAAC;AAKlG;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAC/B,2BAA2B;IAC3B,IAAI,GAAG,YAAY,UAAU,EAAE;QAC7B,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;KAChC;SAAM;QACL,uCAAuC;QACvC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,MAAM,YAAY,GAChB,GAAG,CAAC,MAAM,GAAG,CAAC;gBACd,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBAClB,OA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C,4CAA4C;AAC5C,wCAAwC;AACxC,oEAAoE;AACpE,QAAQ;AACR,MAAM;AACN,IAAI;AAGJ,cAAc;AACd,oFAAoF;AACpF,EAAE;AACF,yEAAyE;AACzE,iCAAiC;AACjC,wCAAwC;AACxC,EAAE;AACF,qDAAqD;AACrD,EAAE;AACF,sBAAsB;AACtB,oCAAoC;AACpC,qBAAqB;AACrB,gCAAgC;AAChC,wEAAwE;AACxE,UAAU;AACV,6BAA6B;AAC7B,0CAA0C;AAC1C,gCAAgC;AAChC,UAAU;AACV,0BAA0B;AAC1B,sCAAsC;AACtC,2EAA2E;AAC3E,UAAU;AACV,QAAQ;AACR,EAAE;AACF,6BAA6B;AAC7B,+BAA+B;AAC/B,QAAQ;AACR,EAAE;AACF,uCAAuC;AACvC,4BAA4B;AAC5B,sCAAsC;AACtC,QAAQ;AACR,MAAM;AACN,oBAAoB;AACpB,IAAI;AACJ,EAAE;AACF,4CAA4C;AAC5C,EAAE;AACF,EAAE;AACF,SAAS;AACT,wCAAwC;AACxC,iDAAiD;AACjD,wCAAwC;AACxC,0CAA0C;AAC1C,wCAAwC;AACxC,2FAA2F;AAC3F,QAAQ;AACR,MAAM;AACN,IAAI;AACJ,EAAE;AACF,EAAE;AACF,SAAS;AACT,kDAAkD;AAClD,iDAAiD;AACjD,sCAAsC;AACtC,0CAA0C;AAC1C,sCAAsC;AACtC,yFAAyF;AACzF,QAAQ;AACR,MAAM;AACN,IAAI","sourcesContent":["import {decodeHashFromBase64, encodeHashToBase64, HoloHash, HoloHashB64} from \"@holochain/client\";\r\nimport {AbstractConstructor, CellMixin, Empty, GConstructor, ZomeMixin, ZomeSpecific} from \"./mixins\";\r\nimport {Cell} from \"./cell\";\r\n\r\n\r\n/**\r\n * Checks if obj is a Hash or list of hashes and tries to convert it a B64 or list of B64\r\n */\r\nexport function anyToB64(obj: any): any {\r\n /** Check if it's a hash */\r\n if (obj instanceof Uint8Array) {\r\n return encodeHashToBase64(obj);\r\n } else {\r\n /** Check if it's an array of hashes */\r\n if (Array.isArray(obj)) {\r\n const isUint8Array =\r\n obj.length > 0 &&\r\n obj.every((value) => {\r\n return value instanceof Uint8Array;\r\n });\r\n if (isUint8Array) {\r\n let result = [];\r\n for (const cur of obj) {\r\n result.push(encodeHashToBase64(cur));\r\n }\r\n return result;\r\n }\r\n }\r\n }\r\n return obj;\r\n}\r\n\r\n\r\n/** ------------------------------------------------------------------------------------------------------------------*/\r\n\r\nexport enum HoloHashType {\r\n Action = \"Action\",\r\n Agent = \"Agent\",\r\n //DhtOp = \"DhtOp\",\r\n Dna = \"Dna\",\r\n Entry = \"Entry\",\r\n External = \"External\",\r\n Network = \"Network\",\r\n //Warrent = \"Warrent\",\r\n Wasm = \"Wasm\",\r\n}\r\n\r\nexport const HASH_TYPE_PREFIX_B64 = {\r\n Action: \"uhCkk\",\r\n Agent: \"uhCAk\",\r\n Dna: \"uhC0k\",\r\n //DhtOp: \"hCQk\",\r\n Entry: \"uhCEk\",\r\n External: \"uhC8k\",\r\n Network: \"uhCIk\",\r\n //Warrent: \"Warrent\",\r\n Wasm: \"uhCok\",\r\n};\r\n\r\nexport function getHashType(hash: HoloHashB64): HoloHashType {\r\n const hashExt = hash.slice(0, 5);\r\n const hashPrefixes = Object.values(HASH_TYPE_PREFIX_B64)\r\n for (let i = 0; i < hashPrefixes.length; i+= 1) {\r\n if (hashPrefixes[i] == hashExt) {\r\n return Object.keys(HASH_TYPE_PREFIX_B64)[i] as HoloHashType;\r\n }\r\n }\r\n throw Error(\"Unknown hash type\");\r\n}\r\n\r\n\r\n/** */\r\nexport function isHashTypeB64(hash: HoloHashB64, hashType: HoloHashType) {\r\n const slice = hash.slice(0, 5);\r\n const prefix = HASH_TYPE_PREFIX_B64[hashType];\r\n for (let i = 0; i < prefix.length; i++) {\r\n if (slice[i] !== prefix[i]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\n\r\nexport function hasHoloHashType(hash: HoloHashB64): boolean {\r\n return !!Object.values(HASH_TYPE_PREFIX_B64).find((prefix) => hash.startsWith(`${prefix}`));\r\n}\r\n\r\n\r\n/** */\r\nexport function validateHashB64(hash: HoloHashB64) {\r\n if (!hash || typeof(hash) != 'string') {\r\n throw new Error(\"The hash must be a valid string\");\r\n }\r\n if (hash.length !== 53) {\r\n throw new Error(\"The hash must be exactly 53 characters long.\");\r\n }\r\n if (!hasHoloHashType(hash)) {\r\n throw new Error(\"The hash must have a valid HoloHash type.\");\r\n\r\n }\r\n}\r\n\r\n\r\nexport function dec64(hash: HoloHashB64): HoloHash {\r\n validateHashB64(hash);\r\n return decodeHashFromBase64(hash);\r\n}\r\nexport function enc64(hash: HoloHash): HoloHashB64 {\r\n let b64 = encodeHashToBase64(hash);\r\n validateHashB64(b64);\r\n return b64;\r\n}\r\n\r\n\r\n/** HoloHash starts with 'u' has a type and is 53 chars long */\r\nexport abstract class HolochainId {\r\n public readonly b64: HoloHashB64;\r\n //private readonly hash: HoloHash;\r\n\r\n /** Validate */\r\n constructor(input: HoloHashB64 | HoloHash, public readonly type: HoloHashType) {\r\n if (typeof(input) != 'string') {\r\n input = encodeHashToBase64(input);\r\n }\r\n validateHashB64(input);\r\n this.b64 = input;\r\n }\r\n\r\n get hash(): HoloHash { return dec64(this.b64) }\r\n /** First 8 chars of the Core */\r\n get short(): string { return this.b64.slice(5, 13); }\r\n\r\n toString(): string {return this.b64;}\r\n\r\n print(): string { return `${this.short} (${this.type})`}\r\n}\r\n\r\n\r\n/** Mixin */\r\nexport function createHolochainId(hashType: HoloHashType) {\r\n class AHoloId extends HolochainId {\r\n constructor(input: HoloHashB64 | HoloHash) {\r\n super(input, hashType);\r\n const type = getHashType(this.b64);\r\n if (hashType != type) {\r\n throw new Error('The hash does not have the correct type. Expected ' + hashType + ', got' + type);\r\n }\r\n }\r\n }\r\n /** */\r\n return AHoloId;\r\n}\r\n\r\nexport class ActionId extends createHolochainId(HoloHashType.Action) {}\r\nexport class AgentId extends createHolochainId(HoloHashType.Agent) {}\r\nexport class DnaId extends createHolochainId(HoloHashType.Dna) {}\r\nexport class EntryId extends createHolochainId(HoloHashType.Entry) {}\r\nexport class ExternalId extends createHolochainId(HoloHashType.External) {}\r\n\r\nexport type AnyDhtId = ActionId | EntryId;\r\nexport type AnyLinkableId = AnyDhtId | ExternalId;\r\n\r\n\r\n/** */\r\nexport function intoDhtId(input: HoloHashB64 | HoloHash): AnyDhtId {\r\n try {\r\n const actionId = new ActionId(input);\r\n return actionId;\r\n } catch(e) {\r\n const entryId = new EntryId(input);\r\n return entryId;\r\n }\r\n}\r\n\r\n\r\n/** */\r\nexport function intoLinkableId(input: HoloHashB64 | HoloHash): AnyLinkableId {\r\n try {\r\n const dhtId = intoDhtId(input);\r\n return dhtId;\r\n } catch(e) {\r\n const externalId = new ExternalId(input);\r\n return externalId;\r\n }\r\n}\r\n\r\n//\r\n// /** */\r\n// export class DnaId extends HoloId {\r\n// constructor(input: HoloHashB64 | HoloHash) {\r\n// super(input, HoloHashType.Dna);\r\n// const type = getHashType(this.value);\r\n// if (HoloHashType.Dna != type) {\r\n// throw new Error('The hash does not have the \"Dna\" type');\r\n// }\r\n// }\r\n// }\r\n//\r\n//\r\n// /** */\r\n// export class AgentId extends HoloId {\r\n// constructor(input: HoloHashB64 | HoloHash) {\r\n// super(input, HoloHashType.Agent);\r\n// const type = getHashType(this.value);\r\n// if (HoloHashType.Agent != type) {\r\n// throw new Error('The hash does not have the \"Agent\" type');\r\n// }\r\n// }\r\n// }\r\n\r\n\r\n/** ------- */\r\n// export type HoloIdConstructor<T = {}> = new (input: HoloHashB64 | HoloHash) => T;\r\n//\r\n// export function HoloIdMixin<TBase extends GConstructor>(Base: TBase) {\r\n// class AHoloId extends Base {\r\n// public readonly b64: HoloHashB64;\r\n//\r\n// //constructor(...args: any[]) {super(args[0])}\r\n//\r\n// /** Validate */\r\n// constructor(...args: any[]) {\r\n// super(args);\r\n// if (args.length != 1) {\r\n// throw new Error(\"HoloId ctor must have exactly 1 argument.\");\r\n// }\r\n// let input = args[0];\r\n// if (typeof (input) != 'string') {\r\n// input = enc64(input);\r\n// }\r\n// this.b64 = input;\r\n// if (this.b64.length !== 53) {\r\n// throw new Error(\"The hash must be exactly 53 characters long.\");\r\n// }\r\n// }\r\n//\r\n// get hash(): HoloHash {\r\n// return dec64(this.b64)\r\n// }\r\n//\r\n// /** First 8 chars of the Core */\r\n// get short(): string {\r\n// return this.b64.slice(5, 13);\r\n// }\r\n// }\r\n// return AHoloId;\r\n// }\r\n//\r\n// export const HoloId = HoloIdMixin(Empty);\r\n//\r\n//\r\n// /** */\r\n// export class AgentId extends HoloId {\r\n// constructor(input: HoloHashB64 | HoloHash) {\r\n// super(input, HoloHashType.Agent);\r\n// const type = getHashType(this.b64);\r\n// if (HoloHashType.Agent != type) {\r\n// throw new Error('The hash does not have the correct type: ' + HoloHashType.Agent);\r\n// }\r\n// }\r\n// }\r\n//\r\n//\r\n// /** */\r\n// export class DnaId extends HoloIdMixin(Empty) {\r\n// constructor(input: HoloHashB64 | HoloHash) {\r\n// super(input, HoloHashType.Dna);\r\n// const type = getHashType(this.b64);\r\n// if (HoloHashType.Dna != type) {\r\n// throw new Error('The hash does not have the correct type: ' + HoloHashType.Dna);\r\n// }\r\n// }\r\n// }\r\n"]}
@@ -0,0 +1,32 @@
1
+ import { HoloHashB64 } from "@holochain/client";
2
+ import { ActionId, AgentId, DnaId, EntryId, HolochainId } from "./hash";
3
+ import { GConstructor } from "./mixins";
4
+ export declare class HolochainIdMap<K extends HolochainId, V> implements Map<K, V> {
5
+ private _ctor;
6
+ _map: Map<HoloHashB64, V>;
7
+ constructor(_ctor: GConstructor<K>, initialEntries?: Array<[K, V]>);
8
+ has(key: K): boolean;
9
+ get(key: K): V;
10
+ set(key: K, value: V): this;
11
+ delete(key: K): boolean;
12
+ values(): IterableIterator<V>;
13
+ keys(): IterableIterator<K>;
14
+ entries(): IterableIterator<[K, V]>;
15
+ clear(): void;
16
+ forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
17
+ get size(): number;
18
+ [Symbol.iterator](): IterableIterator<[K, V]>;
19
+ get [Symbol.toStringTag](): string;
20
+ }
21
+ export declare class ActionIdMap<T> extends HolochainIdMap<ActionId, T> {
22
+ constructor(initialEntries?: Array<[ActionId, T]>);
23
+ }
24
+ export declare class AgentIdMap<T> extends HolochainIdMap<AgentId, T> {
25
+ constructor(initialEntries?: Array<[AgentId, T]>);
26
+ }
27
+ export declare class DnaIdMap<T> extends HolochainIdMap<DnaId, T> {
28
+ constructor(initialEntries?: Array<[DnaId, T]>);
29
+ }
30
+ export declare class EntryIdMap<T> extends HolochainIdMap<EntryId, T> {
31
+ constructor(initialEntries?: Array<[EntryId, T]>);
32
+ }