@ddd-qc/cell-proxy 0.26.1 → 0.26.3
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/ZomeProxy.d.ts +2 -0
- package/dist/ZomeProxy.js +12 -22
- package/dist/ZomeProxy.js.map +1 -1
- package/dist/hash.d.ts +27 -78
- package/dist/hash.js +61 -32
- package/dist/hash.js.map +1 -1
- package/dist/pretty.js.map +1 -1
- package/package.json +3 -2
package/dist/ZomeProxy.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare abstract class ZomeProxy extends ZomeProxy_base {
|
|
|
29
29
|
protected _cellProxy: CellProxy;
|
|
30
30
|
/** Ctor */
|
|
31
31
|
constructor(_cellProxy: CellProxy, zomeName?: ZomeName);
|
|
32
|
+
/** */
|
|
33
|
+
private validateFunctionName;
|
|
32
34
|
/** Helper for calling a zome function on its zome */
|
|
33
35
|
call(fnName: FunctionName, payload: any, maybeSecret?: CapSecret, timeout?: number): Promise<any>;
|
|
34
36
|
/** Helper for calling a zome function on its zome */
|
package/dist/ZomeProxy.js
CHANGED
|
@@ -18,42 +18,32 @@ export class ZomeProxy extends CellMixin(ZomeSpecific) {
|
|
|
18
18
|
}
|
|
19
19
|
this._cell = _cellProxy.cell;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
/** */
|
|
22
|
+
validateFunctionName(fnName) {
|
|
23
|
+
//const fnNames: FunctionName[] = this.fnNames.map(([a, b]) => b);
|
|
24
|
+
//if (!fnNames.includes(fnName)) {
|
|
25
|
+
if (!this.constructor.FN_NAMES.includes(fnName)) {
|
|
26
|
+
throw Error(`Function "${fnName}()" not part of zome "${this.zomeName}"`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
/** Helper for calling a zome function on its zome */
|
|
30
30
|
async call(fnName, payload, maybeSecret, timeout) {
|
|
31
31
|
//console.log("ZomeProxy.call", this.zomeName)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const cap_secret = maybeSecret
|
|
36
|
-
? maybeSecret
|
|
37
|
-
// : this._signingProps
|
|
38
|
-
// ? this._signingProps.capSecret
|
|
39
|
-
: null;
|
|
32
|
+
this.validateFunctionName(fnName);
|
|
33
|
+
const cap_secret = maybeSecret ? maybeSecret : null;
|
|
40
34
|
return this._cellProxy.callZome(this.zomeName, fnName, payload, cap_secret, timeout);
|
|
41
35
|
}
|
|
42
36
|
/** Helper for calling a zome function on its zome */
|
|
43
37
|
async callBlocking(fnName, payload, maybeSecret, timeout) {
|
|
44
38
|
//console.log("ZomeProxy.call", this.zomeName)
|
|
45
|
-
|
|
46
|
-
return Promise.reject(`Function "${fnName}()" not part of zome "${this.zomeName}"`);
|
|
47
|
-
}
|
|
39
|
+
this.validateFunctionName(fnName);
|
|
48
40
|
const cap_secret = maybeSecret ? maybeSecret : null;
|
|
49
41
|
return this._cellProxy.callZomeBlocking(this.zomeName, fnName, payload, cap_secret, timeout);
|
|
50
42
|
}
|
|
51
43
|
/** Helper for calling a zome function on its zome */
|
|
52
44
|
async callZomeBlockPostCommit(entryType, fnName, payload, maybeSecret, timeout) {
|
|
53
45
|
//console.log("ZomeProxy.call", this.zomeName)
|
|
54
|
-
|
|
55
|
-
return Promise.reject(`Function "${fnName}()" not part of zome "${this.zomeName}"`);
|
|
56
|
-
}
|
|
46
|
+
this.validateFunctionName(fnName);
|
|
57
47
|
const cap_secret = maybeSecret ? maybeSecret : null;
|
|
58
48
|
return this._cellProxy.callZomeBlockPostCommit(entryType, this.zomeName, fnName, payload, cap_secret, timeout);
|
|
59
49
|
}
|
package/dist/ZomeProxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZomeProxy.js","sourceRoot":"","sources":["../src/ZomeProxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EA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,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACjH,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,MAAM;IACN,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,MAAM;IACN,KAAK,CAAC,aAAa,CAAC,QAAkB;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["import {CapSecret, FunctionName, ZomeName} from \"@holochain/client\";\nimport {CellMixin, ZomeSpecific} from \"./mixins\";\nimport {CellProxy} from \"./CellProxy\";\nimport {DnaInfo, EntryDef, ZomeInfo} from \"./types\";\nimport {Dictionary} from \"./utils\";\n\nexport type ZomeProxyConstructor = {new(cellProxy: CellProxy, zomeName?: ZomeName): ZomeProxy} & typeof ZomeSpecific;\n\n\n/**\n * ABC for representing the zome function bindings of a Zome.\n * It holds the zomeName and reference to a CellProxy.\n */\nexport abstract class ZomeProxy extends CellMixin(ZomeSpecific) {\n\n /** Ctor */\n constructor(protected _cellProxy: CellProxy, zomeName?: ZomeName) {\n super();\n if (zomeName) {\n this.zomeName = zomeName;\n } else {\n if (!this.defaultZomeName) {\n throw Error(\"zomeName not defined in ZomeProxy subclass \" + this.constructor.name);\n }\n }\n this._cell = _cellProxy.cell;\n }\n\n\n /** */\n private validateFunctionName(fnName: FunctionName): void {\n //const fnNames: FunctionName[] = this.fnNames.map(([a, b]) => b);\n //if (!fnNames.includes(fnName)) {\n if (!(this.constructor as any).FN_NAMES.includes(fnName)) {\n throw Error(`Function \"${fnName}()\" not part of zome \"${this.zomeName}\"`);\n }\n }\n\n /** Helper for calling a zome function on its zome */\n async call(fnName: FunctionName, payload: any, maybeSecret?: CapSecret, timeout?: number): Promise<any> {\n //console.log(\"ZomeProxy.call\", this.zomeName)\n this.validateFunctionName(fnName);\n const cap_secret = maybeSecret ? maybeSecret : null;\n return this._cellProxy.callZome(this.zomeName, fnName, payload, cap_secret, timeout);\n }\n\n\n /** Helper for calling a zome function on its zome */\n protected async callBlocking(fnName: FunctionName, payload: any, maybeSecret?: CapSecret, timeout?: number): Promise<any> {\n //console.log(\"ZomeProxy.call\", this.zomeName)\n this.validateFunctionName(fnName);\n const cap_secret = maybeSecret ? maybeSecret : null;\n return this._cellProxy.callZomeBlocking(this.zomeName, fnName, payload, cap_secret, timeout);\n }\n\n\n /** Helper for calling a zome function on its zome */\n protected async callZomeBlockPostCommit(entryType: string, fnName: FunctionName, payload: any, maybeSecret?: CapSecret, timeout?: number): Promise<any> {\n //console.log(\"ZomeProxy.call\", this.zomeName)\n this.validateFunctionName(fnName);\n const cap_secret = maybeSecret ? maybeSecret : null;\n return this._cellProxy.callZomeBlockPostCommit(entryType, this.zomeName, fnName, payload, cap_secret, timeout);\n }\n\n\n /** */\n async zomeInfo(): Promise<ZomeInfo> {\n return this._cellProxy.callZomeInfo(this.zomeName);\n }\n\n /** */\n async dnaInfo(): Promise<DnaInfo> {\n return this._cellProxy.callDnaInfo(this.zomeName);\n }\n\n /** */\n async callEntryDefs(zomeName: ZomeName): Promise<Dictionary<EntryDef>> {\n return this._cellProxy.callEntryDefs(zomeName);\n }\n}\n"]}
|
package/dist/hash.d.ts
CHANGED
|
@@ -27,97 +27,45 @@ export declare function getHashType(hash: HoloHashB64): HoloHashType;
|
|
|
27
27
|
export declare function isHashTypeB64(hash: HoloHashB64, hashType: HoloHashType): boolean;
|
|
28
28
|
export declare function hasHoloHashType(hash: HoloHashB64): boolean;
|
|
29
29
|
/** */
|
|
30
|
-
export declare function validateHashB64(hash: HoloHashB64): void;
|
|
30
|
+
export declare function validateHashB64(hash: HoloHashB64, hashType?: HoloHashType): void;
|
|
31
31
|
export declare function dec64(hash: HoloHashB64): HoloHash;
|
|
32
32
|
export declare function enc64(hash: HoloHash): HoloHashB64;
|
|
33
33
|
/** HoloHash starts with 'u' has a type and is 53 chars long */
|
|
34
34
|
export declare abstract class HolochainId {
|
|
35
|
-
readonly type: HoloHashType;
|
|
36
35
|
readonly b64: HoloHashB64;
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
static readonly HASH_TYPE: HoloHashType;
|
|
37
|
+
get hashType(): HoloHashType;
|
|
38
|
+
/** ctor: validate */
|
|
39
|
+
constructor(input: HoloHashB64 | HoloHash);
|
|
40
|
+
/** */
|
|
41
|
+
static empty<T extends HolochainId>(this: any): T;
|
|
42
|
+
/** */
|
|
43
|
+
static from<T extends HolochainId, Z extends HolochainId>(this: new (input: HoloHashB64 | HoloHash) => Z, start: T): Z;
|
|
44
|
+
toString(): string;
|
|
39
45
|
get hash(): HoloHash;
|
|
40
46
|
/** First 8 chars of the Core */
|
|
41
47
|
get short(): string;
|
|
42
|
-
toString(): string;
|
|
43
48
|
print(): string;
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 {
|
|
50
|
+
export declare class ActionId extends HolochainId {
|
|
51
|
+
static readonly HASH_TYPE = HoloHashType.Action;
|
|
52
|
+
action(): void;
|
|
69
53
|
}
|
|
70
|
-
declare
|
|
71
|
-
|
|
72
|
-
|
|
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 {
|
|
54
|
+
export declare class AgentId extends HolochainId {
|
|
55
|
+
static readonly HASH_TYPE = HoloHashType.Agent;
|
|
56
|
+
agent(): void;
|
|
82
57
|
}
|
|
83
|
-
declare
|
|
84
|
-
|
|
85
|
-
|
|
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 {
|
|
58
|
+
export declare class EntryId extends HolochainId {
|
|
59
|
+
static readonly HASH_TYPE = HoloHashType.Entry;
|
|
60
|
+
entry(): void;
|
|
95
61
|
}
|
|
96
|
-
declare
|
|
97
|
-
|
|
98
|
-
|
|
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 {
|
|
62
|
+
export declare class DnaId extends HolochainId {
|
|
63
|
+
static readonly HASH_TYPE = HoloHashType.Dna;
|
|
64
|
+
dna(): void;
|
|
108
65
|
}
|
|
109
|
-
declare
|
|
110
|
-
|
|
111
|
-
|
|
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 {
|
|
66
|
+
export declare class ExternalId extends HolochainId {
|
|
67
|
+
static readonly HASH_TYPE = HoloHashType.External;
|
|
68
|
+
external(): void;
|
|
121
69
|
}
|
|
122
70
|
export type AnyDhtId = ActionId | EntryId;
|
|
123
71
|
export type AnyLinkableId = AnyDhtId | ExternalId;
|
|
@@ -125,4 +73,5 @@ export type AnyLinkableId = AnyDhtId | ExternalId;
|
|
|
125
73
|
export declare function intoDhtId(input: HoloHashB64 | HoloHash): AnyDhtId;
|
|
126
74
|
/** */
|
|
127
75
|
export declare function intoLinkableId(input: HoloHashB64 | HoloHash): AnyLinkableId;
|
|
128
|
-
|
|
76
|
+
/** */
|
|
77
|
+
export declare function testHoloId(): void;
|
package/dist/hash.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { decodeHashFromBase64, encodeHashToBase64 } from "@holochain/client";
|
|
2
|
-
//import {AbstractConstructor, CellMixin, Empty, GConstructor, ZomeMixin, ZomeSpecific} from "./mixins";
|
|
3
|
-
//import {Cell} from "./cell";
|
|
1
|
+
import { decodeHashFromBase64, dhtLocationFrom32, encodeHashToBase64, HASH_TYPE_PREFIX, } from "@holochain/client";
|
|
4
2
|
/**
|
|
5
3
|
* Checks if obj is a Hash or list of hashes and tries to convert it a B64 or list of B64
|
|
6
4
|
*/
|
|
@@ -76,14 +74,14 @@ export function hasHoloHashType(hash) {
|
|
|
76
74
|
return !!Object.values(HASH_TYPE_PREFIX_B64).find((prefix) => hash.startsWith(`${prefix}`));
|
|
77
75
|
}
|
|
78
76
|
/** */
|
|
79
|
-
export function validateHashB64(hash) {
|
|
77
|
+
export function validateHashB64(hash, hashType) {
|
|
80
78
|
if (!hash || typeof (hash) != 'string') {
|
|
81
79
|
throw new Error("The hash must be a valid string");
|
|
82
80
|
}
|
|
83
81
|
if (hash.length !== 53) {
|
|
84
|
-
throw new Error("The hash must be exactly 53 characters long.");
|
|
82
|
+
throw new Error("The hash must be exactly 53 characters long. Got: " + hash.length);
|
|
85
83
|
}
|
|
86
|
-
if (!hasHoloHashType(hash)) {
|
|
84
|
+
if ((hashType && !isHashTypeB64(hash, hashType)) || !hasHoloHashType(hash)) {
|
|
87
85
|
throw new Error("The hash must have a valid HoloHash type.");
|
|
88
86
|
}
|
|
89
87
|
}
|
|
@@ -98,46 +96,64 @@ export function enc64(hash) {
|
|
|
98
96
|
}
|
|
99
97
|
/** HoloHash starts with 'u' has a type and is 53 chars long */
|
|
100
98
|
export class HolochainId {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
get hashType() {
|
|
100
|
+
return this.constructor.HASH_TYPE;
|
|
101
|
+
}
|
|
102
|
+
/** ctor: validate */
|
|
103
|
+
constructor(input) {
|
|
105
104
|
if (typeof (input) != 'string') {
|
|
106
105
|
input = encodeHashToBase64(input);
|
|
107
106
|
}
|
|
108
|
-
validateHashB64(input);
|
|
107
|
+
validateHashB64(input, this.hashType);
|
|
109
108
|
this.b64 = input;
|
|
110
109
|
}
|
|
110
|
+
/** */
|
|
111
|
+
static empty() {
|
|
112
|
+
const empty = new Uint8Array(32);
|
|
113
|
+
const newHash = Uint8Array.from([
|
|
114
|
+
...HASH_TYPE_PREFIX[this.HASH_TYPE],
|
|
115
|
+
...empty,
|
|
116
|
+
...dhtLocationFrom32(empty),
|
|
117
|
+
]);
|
|
118
|
+
return new this(newHash);
|
|
119
|
+
}
|
|
120
|
+
/** */
|
|
121
|
+
static from(start) {
|
|
122
|
+
const core = Uint8Array.from(start.hash.slice(3, 35));
|
|
123
|
+
const hashType = this.HASH_TYPE;
|
|
124
|
+
const newHash = Uint8Array.from([
|
|
125
|
+
...HASH_TYPE_PREFIX[hashType],
|
|
126
|
+
...core,
|
|
127
|
+
...dhtLocationFrom32(core),
|
|
128
|
+
]);
|
|
129
|
+
return new this(newHash);
|
|
130
|
+
}
|
|
131
|
+
toString() { return this.b64; }
|
|
111
132
|
get hash() { return dec64(this.b64); }
|
|
112
133
|
/** First 8 chars of the Core */
|
|
113
134
|
get short() { return this.b64.slice(5, 13); }
|
|
114
|
-
|
|
115
|
-
print() { return `${this.short} (${this.type})`; }
|
|
116
|
-
}
|
|
117
|
-
/** Mixin */
|
|
118
|
-
export function createHolochainId(hashType) {
|
|
119
|
-
class AHoloId extends HolochainId {
|
|
120
|
-
constructor(input) {
|
|
121
|
-
super(input, hashType);
|
|
122
|
-
const type = getHashType(this.b64);
|
|
123
|
-
if (hashType != type) {
|
|
124
|
-
throw new Error('The hash does not have the correct type. Expected ' + hashType + ', got' + type);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** */
|
|
129
|
-
return AHoloId;
|
|
135
|
+
print() { return `${this.short} (${this.hashType})`; }
|
|
130
136
|
}
|
|
131
|
-
export class ActionId extends
|
|
137
|
+
export class ActionId extends HolochainId {
|
|
138
|
+
action() { }
|
|
132
139
|
}
|
|
133
|
-
|
|
140
|
+
ActionId.HASH_TYPE = HoloHashType.Action;
|
|
141
|
+
export class AgentId extends HolochainId {
|
|
142
|
+
agent() { }
|
|
134
143
|
}
|
|
135
|
-
|
|
144
|
+
AgentId.HASH_TYPE = HoloHashType.Agent;
|
|
145
|
+
export class EntryId extends HolochainId {
|
|
146
|
+
entry() { }
|
|
136
147
|
}
|
|
137
|
-
|
|
148
|
+
EntryId.HASH_TYPE = HoloHashType.Entry;
|
|
149
|
+
export class DnaId extends HolochainId {
|
|
150
|
+
dna() { }
|
|
138
151
|
}
|
|
139
|
-
|
|
152
|
+
DnaId.HASH_TYPE = HoloHashType.Dna;
|
|
153
|
+
export class ExternalId extends HolochainId {
|
|
154
|
+
external() { }
|
|
140
155
|
}
|
|
156
|
+
ExternalId.HASH_TYPE = HoloHashType.External;
|
|
141
157
|
/** */
|
|
142
158
|
export function intoDhtId(input) {
|
|
143
159
|
try {
|
|
@@ -160,4 +176,17 @@ export function intoLinkableId(input) {
|
|
|
160
176
|
return externalId;
|
|
161
177
|
}
|
|
162
178
|
}
|
|
179
|
+
/** */
|
|
180
|
+
export function testHoloId() {
|
|
181
|
+
console.log("testHoloId()");
|
|
182
|
+
const emptyAgent = AgentId.empty();
|
|
183
|
+
const emptyAction = ActionId.empty();
|
|
184
|
+
const emptyEntry = EntryId.from(emptyAgent);
|
|
185
|
+
console.log("testHoloId()", emptyAction);
|
|
186
|
+
/** */
|
|
187
|
+
function printEh(eh) {
|
|
188
|
+
console.log("printEh", eh);
|
|
189
|
+
}
|
|
190
|
+
printEh(emptyEntry);
|
|
191
|
+
}
|
|
163
192
|
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAwB,MAAM,mBAAmB,CAAC;AAClG,wGAAwG;AACxG,8BAA8B;AAG9B;;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,OAAO,KAAK,YAAY,UAAU,CAAC;gBACrC,CAAC,CAAC,CAAC;YACL,IAAI,YAAY,EAAE;gBAChB,IAAI,MAAM,GAAG,EAAE,CAAC;gBAChB,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;oBACrB,MAAM,CAAC,IA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Q,SAAQ,iBAAiB,CAAC,YAAY,CAAC,KAAK,CAAC;CAAG;AACrE,MAAM,OAAO,KAAM,SAAQ,iBAAiB,CAAC,YAAY,CAAC,GAAG,CAAC;CAAG;AACjE,MAAM,OAAO,OAAQ,SAAQ,iBAAiB,CAAC,YAAY,CAAC,KAAK,CAAC;CAAG;AACrE,MAAM,OAAO,UAAW,SAAQ,iBAAiB,CAAC,YAAY,CAAC,QAAQ,CAAC;CAAG;AAM3E,MAAM;AACN,MAAM,UAAU,SAAS,CAAC,KAA6B;IACrD,IAAI;QACF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC;KACjB;IAAC,OAAM,CAAC,EAAE;QACP,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,OAAO,CAAC;KAClB;AACH,CAAC;AAGD,MAAM;AACN,MAAM,UAAU,cAAc,CAAC,KAA6B;IAC1D,IAAI;QACF,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC;KACd;IAAC,OAAM,CAAC,EAAE;QACT,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC;KACnB;AACH,CAAC","sourcesContent":["import {decodeHashFromBase64, encodeHashToBase64, HoloHash, HoloHashB64} from \"@holochain/client\";\r\n//import {AbstractConstructor, CellMixin, Empty, GConstructor, ZomeMixin, ZomeSpecific} from \"./mixins\";\r\n//import {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"]}
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAAE,gBAAgB,GAGnC,MAAM,mBAAmB,CAAC;AAE7B;;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,OAAO,KAAK,YAAY,UAAU,CAAC;gBACrC,CAAC,CAAC,CAAC;YACL,IAAI,YAAY,EAAE;gBAChB,IAAI,MAAM,GAAG,EAAE,CAAC;gBAChB,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;oBACrB,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;iBACtC;gBACD,OAAO,MAAM,CAAC;aACf;SAC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KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC;KACd;IAAC,OAAM,CAAC,EAAE;QACT,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC;KACnB;AACH,CAAC;AAGD,MAAM;AACN,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IACnC,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACzC,MAAM;IACN,SAAS,OAAO,CAAC,EAAW;QAC1B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,UAAU,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import {\n decodeHashFromBase64,\n dhtLocationFrom32,\n encodeHashToBase64, HASH_TYPE_PREFIX,\n HoloHash,\n HoloHashB64,\n } from \"@holochain/client\";\n\n/**\n * Checks if obj is a Hash or list of hashes and tries to convert it a B64 or list of B64\n */\nexport function anyToB64(obj: any): any {\n /** Check if it's a hash */\n if (obj instanceof Uint8Array) {\n return encodeHashToBase64(obj);\n } else {\n /** Check if it's an array of hashes */\n if (Array.isArray(obj)) {\n const isUint8Array =\n obj.length > 0 &&\n obj.every((value) => {\n return value instanceof Uint8Array;\n });\n if (isUint8Array) {\n let result = [];\n for (const cur of obj) {\n result.push(encodeHashToBase64(cur));\n }\n return result;\n }\n }\n }\n return obj;\n}\n\n\n/** ------------------------------------------------------------------------------------------------------------------*/\n\nexport enum HoloHashType {\n Action = \"Action\",\n Agent = \"Agent\",\n //DhtOp = \"DhtOp\",\n Dna = \"Dna\",\n Entry = \"Entry\",\n External = \"External\",\n Network = \"Network\",\n //Warrent = \"Warrent\",\n Wasm = \"Wasm\",\n}\n\nexport const HASH_TYPE_PREFIX_B64 = {\n Action: \"uhCkk\",\n Agent: \"uhCAk\",\n Dna: \"uhC0k\",\n //DhtOp: \"hCQk\",\n Entry: \"uhCEk\",\n External: \"uhC8k\",\n Network: \"uhCIk\",\n //Warrent: \"Warrent\",\n Wasm: \"uhCok\",\n};\n\nexport function getHashType(hash: HoloHashB64): HoloHashType {\n const hashExt = hash.slice(0, 5);\n const hashPrefixes = Object.values(HASH_TYPE_PREFIX_B64)\n for (let i = 0; i < hashPrefixes.length; i+= 1) {\n if (hashPrefixes[i] == hashExt) {\n return Object.keys(HASH_TYPE_PREFIX_B64)[i] as HoloHashType;\n }\n }\n throw Error(\"Unknown hash type\");\n}\n\n\n/** */\nexport function isHashTypeB64(hash: HoloHashB64, hashType: HoloHashType) {\n const slice = hash.slice(0, 5);\n const prefix = HASH_TYPE_PREFIX_B64[hashType];\n for (let i = 0; i < prefix.length; i++) {\n if (slice[i] !== prefix[i]) {\n return false;\n }\n }\n return true;\n}\n\n\nexport function hasHoloHashType(hash: HoloHashB64): boolean {\n return !!Object.values(HASH_TYPE_PREFIX_B64).find((prefix) => hash.startsWith(`${prefix}`));\n}\n\n\n/** */\nexport function validateHashB64(hash: HoloHashB64, hashType?: HoloHashType) {\n if (!hash || typeof(hash) != 'string') {\n throw new Error(\"The hash must be a valid string\");\n }\n if (hash.length !== 53) {\n throw new Error(\"The hash must be exactly 53 characters long. Got: \" + hash.length);\n }\n if((hashType && !isHashTypeB64(hash, hashType)) || !hasHoloHashType(hash)) {\n throw new Error(\"The hash must have a valid HoloHash type.\");\n }\n}\n\n\nexport function dec64(hash: HoloHashB64): HoloHash {\n validateHashB64(hash);\n return decodeHashFromBase64(hash);\n}\nexport function enc64(hash: HoloHash): HoloHashB64 {\n let b64 = encodeHashToBase64(hash);\n validateHashB64(b64);\n return b64;\n}\n\n\n\n/** HoloHash starts with 'u' has a type and is 53 chars long */\nexport abstract class HolochainId {\n public readonly b64: HoloHashB64;\n\n static readonly HASH_TYPE: HoloHashType;\n\n get hashType(): HoloHashType {\n return (this.constructor as typeof HolochainId).HASH_TYPE;\n }\n\n /** ctor: validate */\n constructor(input: HoloHashB64 | HoloHash) {\n if (typeof(input) != 'string') {\n input = encodeHashToBase64(input);\n }\n validateHashB64(input, this.hashType);\n this.b64 = input;\n }\n\n /** */\n static empty<T extends HolochainId>(this: any): T {\n const empty = new Uint8Array(32);\n const newHash = Uint8Array.from([\n ...HASH_TYPE_PREFIX[this.HASH_TYPE],\n ...empty,\n ...dhtLocationFrom32(empty),\n ]);\n return new this(newHash);\n }\n\n /** */\n static from<T extends HolochainId, Z extends HolochainId>(this: new (input: HoloHashB64 | HoloHash) => Z, start: T): Z {\n const core = Uint8Array.from(start.hash.slice(3, 35));\n const hashType = (this as unknown as typeof HolochainId).HASH_TYPE;\n const newHash = Uint8Array.from([\n ...HASH_TYPE_PREFIX[hashType],\n ...core,\n ...dhtLocationFrom32(core),\n ]);\n return new this(newHash);\n }\n\n\n toString(): string {return this.b64;}\n\n get hash(): HoloHash { return dec64(this.b64) }\n /** First 8 chars of the Core */\n get short(): string { return this.b64.slice(5, 13); }\n\n print(): string { return `${this.short} (${this.hashType})`}\n}\n\n\nexport class ActionId extends HolochainId { static readonly HASH_TYPE = HoloHashType.Action; action() {} }\nexport class AgentId extends HolochainId { static readonly HASH_TYPE = HoloHashType.Agent; agent() {} }\nexport class EntryId extends HolochainId { static readonly HASH_TYPE = HoloHashType.Entry; entry() {} }\nexport class DnaId extends HolochainId { static readonly HASH_TYPE = HoloHashType.Dna; dna() {} }\nexport class ExternalId extends HolochainId { static readonly HASH_TYPE = HoloHashType.External; external() {} }\n\n\nexport type AnyDhtId = ActionId | EntryId;\nexport type AnyLinkableId = AnyDhtId | ExternalId;\n\n\n/** */\nexport function intoDhtId(input: HoloHashB64 | HoloHash): AnyDhtId {\n try {\n const actionId = new ActionId(input);\n return actionId;\n } catch(e) {\n const entryId = new EntryId(input);\n return entryId;\n }\n}\n\n\n/** */\nexport function intoLinkableId(input: HoloHashB64 | HoloHash): AnyLinkableId {\n try {\n const dhtId = intoDhtId(input);\n return dhtId;\n } catch(e) {\n const externalId = new ExternalId(input);\n return externalId;\n }\n}\n\n\n/** */\nexport function testHoloId() {\n console.log(\"testHoloId()\");\n const emptyAgent = AgentId.empty();\n const emptyAction = ActionId.empty();\n const emptyEntry = EntryId.from(emptyAgent);\n\n console.log(\"testHoloId()\", emptyAction);\n /** */\n function printEh(eh: EntryId) {\n console.log(\"printEh\", eh);\n }\n\n printEh(emptyEntry);\n}\n\n"]}
|
package/dist/pretty.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty.js","sourceRoot":"","sources":["../src/pretty.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAA6B,UAAU,EAAC,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAc,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAGjE,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAElF,MAAM,UAAU,cAAc,CAAC,IAAU;IACvC,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAA;AACrE,CAAC;AAED,MAAM;AACN,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,EAAE;UACL,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC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,KAAK,CAAC;IACzF,KAAK,IAAI,oBAAoB,KAAK,CAAC,WAAW,CAAC,IAAI,MAAM,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjG,KAAK,IAAI,gBAAgB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,IAAI,CAAC;IAChE,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QAC3D,KAAK,IAAI,UAAU,KAAK,CAAC,OAAO,CAAA,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KACrH;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAID,MAAM;AACN,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,EAAE;QACnC,OAAO,KAAK,CAAC,MAAM,CAAA,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC9C;IACD,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,EAAE;QACnC,OAAO,KAAK,CAAC,MAAM,CAAA,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC9C;IACD,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,EAAE;QACnC,OAAO,KAAK,CAAC,MAAM,CAAA,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC9C;IACD,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["\nimport {SignalLog} from \"./AppProxy\";\nimport {AppInfo, CellType} from \"@holochain/client\";\nimport {BaseRoleName, CellsForRole, str2CellId} from \"./types\";\nimport {intoStem} from \"./cell\";\nimport {enc64} from \"./hash\";\nimport {StateChange, StateChangeType} from \"./zomeSignals.types\";\n\n\nconst zeroPad = (num: number, places: number) => String(num).padStart(places, '0')\n\nexport function prettyDuration(date: Date): string {\n return date.getSeconds() + \".\" + zeroPad(date.getMilliseconds(), 3)\n}\n\n/** */\nexport function prettyDate(date: Date): string {\n return \"\"\n + zeroPad(date.getHours(), 2)\n + \":\" + zeroPad(date.getMinutes(), 2)\n + \":\" + zeroPad(date.getSeconds(), 2)\n + \".\" + zeroPad(date.getMilliseconds(), 3);\n}\n\n\nexport function prettySignalLogs(signalLogs: SignalLog[]) {\n return signalLogs.map((log) => {\n const dnaHash = enc64(str2CellId(log.cellId)[0]).slice(-8);\n return {timestamp: prettyDate(new Date(log.ts)), dnaHash, zome: log.zomeName, type: log.type, payload: log.zomeSignal};\n })\n}\n\n\n/** */\nexport function printAppInfo(appInfo: AppInfo): string {\n let print = `Happ \"${appInfo.installed_app_id}\" info: (status: ${JSON.stringify(appInfo.status)})`;\n for (const [roleName, cellInfos] of Object.entries(appInfo.cell_info)) {\n for (const cellInfo of Object.values(cellInfos)) {\n if (CellType.Stem in cellInfo) {\n const stem = intoStem(cellInfo)!;\n print += `\\n - ${roleName}.${stem.name? stem.name : \"unnamed\"}: ${enc64(stem.dna)} (stem)`;\n continue;\n }\n if (CellType.Provisioned in cellInfo) {\n const cell = cellInfo.provisioned;\n print += `\\n - ${roleName}: ${cell.name} | ${enc64(cell.cell_id[0])}`;\n continue;\n }\n if (CellType.Cloned in cellInfo) {\n const cell = cellInfo.cloned;\n print += `\\n - ${roleName}.${cell.clone_id}: ${cell.name} | ${enc64(cell.cell_id[0])}`;\n continue;\n }\n }\n }\n return print;\n}\n\n\n/** */\nexport function printCellsForRole(baseRoleName: BaseRoleName, cells: CellsForRole): string {\n let print = `CellsForRole \"${baseRoleName}\": (${enc64(cells.provisioned.cell_id[1])})\\n`;\n print += ` - Provisioned: ${cells.provisioned.name} | ${enc64(cells.provisioned.cell_id[0])}\\n`;\n print += ` - Clones : ${Object.values(cells.clones).length}\\n`;\n for (const [cloneId, clone] of Object.entries(cells.clones)) {\n print += ` - (${clone.enabled? \"enabled\" : \"disabled\"})${cloneId}: ${clone.name} | ${enc64(clone.cell_id[0])}\\n`;\n }\n return print;\n}\n\n\n\n/** */\nexport function prettyState(state: StateChange): string {\n if (StateChangeType.Create in state) {\n return state.Create? \"Create NEW\" : \"Create\";\n }\n if (StateChangeType.Update in state) {\n return state.Update? \"Update NEW\" : \"Update\";\n }\n if (StateChangeType.Delete in state) {\n return state.Delete? \"Delete NEW\" : \"Delete\";\n }\n throw Error(\"Unknown stateChange type\");\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-qc/cell-proxy",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.3",
|
|
4
4
|
"description": "Proxy classes and helpers for managing a Holochain AppWebsocket",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"lint": "eslint --ext .ts .",
|
|
13
|
-
"build": "rm -rf dist && tsc"
|
|
13
|
+
"build": "rm -rf dist && tsc",
|
|
14
|
+
"build:watch": "tsc -w --preserveWatchOutput"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|