diff --git a/docs/generated/changelog.html b/docs/generated/changelog.html
index 84aa5df4b..079b7ccdd 100644
--- a/docs/generated/changelog.html
+++ b/docs/generated/changelog.html
@@ -10,6 +10,10 @@
Agent-JS Changelog
+ Version 0.12.1
+
+ - Adds UTF-8 as an encoding option for CanisterStatus custom paths
+
Version 0.12.0
-
diff --git a/packages/agent/src/canisterStatus/__snapshots__/index.test.ts.snap b/packages/agent/src/canisterStatus/__snapshots__/index.test.ts.snap
index 098eeaeb6..745b0263b 100644
--- a/packages/agent/src/canisterStatus/__snapshots__/index.test.ts.snap
+++ b/packages/agent/src/canisterStatus/__snapshots__/index.test.ts.snap
@@ -60,9 +60,17 @@ exports[`Canister Status utility should support valid custom paths 1`] = `165299
exports[`Canister Status utility should support valid custom paths 2`] = `ArrayBuffer []`;
-exports[`Canister Status utility should support valid custom paths 3`] = `"80f485e1a4a6a7f816"`;
+exports[`Canister Status utility should support valid custom paths 3`] = `
+"type Example = text;
+service : {
+ greet: (Example) -> (text) query;
+}
+"
+`;
+
+exports[`Canister Status utility should support valid custom paths 4`] = `"80f485e1a4a6a7f816"`;
-exports[`Canister Status utility should support valid custom paths 4`] = `
+exports[`Canister Status utility should support valid custom paths 5`] = `
Array [
Uint8Array [
4,
diff --git a/packages/agent/src/canisterStatus/index.test.ts b/packages/agent/src/canisterStatus/index.test.ts
index 3994cf2b0..b10528c59 100644
--- a/packages/agent/src/canisterStatus/index.test.ts
+++ b/packages/agent/src/canisterStatus/index.test.ts
@@ -113,6 +113,14 @@ describe('Canister Status utility', () => {
decodeStrategy: 'raw',
},
]);
+ const statusUTF8 = await getStatus([
+ {
+ kind: 'metadata',
+ path: 'candid:service',
+ key: 'candid',
+ decodeStrategy: 'utf-8',
+ },
+ ]);
const statusHex = await getStatus([
{
key: 'time',
@@ -129,6 +137,7 @@ describe('Canister Status utility', () => {
]);
expect(status.get('time')).toMatchSnapshot();
expect(statusRaw.get('time')).toMatchSnapshot();
+ expect(statusUTF8.get('candid')).toMatchSnapshot();
expect(statusHex.get('time')).toMatchSnapshot();
expect(statusCBOR.get('Controller')).toMatchSnapshot();
});
diff --git a/packages/agent/src/canisterStatus/index.ts b/packages/agent/src/canisterStatus/index.ts
index 0f321b75b..5034d53cc 100644
--- a/packages/agent/src/canisterStatus/index.ts
+++ b/packages/agent/src/canisterStatus/index.ts
@@ -15,8 +15,8 @@ export type Status = string | ArrayBuffer | Date | ArrayBuffer[] | Principal[] |
*/
export interface CustomPath {
key: string;
- path: ArrayBuffer[];
- decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'raw';
+ path: ArrayBuffer[] | string;
+ decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
}
/**
@@ -28,7 +28,7 @@ export interface MetaData {
kind: 'metadata';
key: string;
path: string | ArrayBuffer;
- decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'raw';
+ decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
}
/**
@@ -139,6 +139,9 @@ export const request = async (options: {
status.set(path.key, decodeHex(data));
break;
}
+ case 'utf-8': {
+ status.set(path.key, decodeUtf8(data));
+ }
}
}
}
@@ -214,6 +217,10 @@ const decodeCbor = (buf: ArrayBuffer): ArrayBuffer[] => {
return Cbor.decode(buf);
};
+const decodeUtf8 = (buf: ArrayBuffer): string => {
+ return new TextDecoder().decode(buf);
+};
+
// time is a LEB128-encoded Nat
const decodeTime = (buf: ArrayBuffer): Date => {
const decoded = decodeLeb128(buf);