Skip to content

Commit

Permalink
chore: ignore TextDecoder warning, editor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice committed Aug 26, 2024
1 parent f13c25d commit c0d8747
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 40 deletions.
63 changes: 44 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ const NULL = new ArrayBuffer(0);

// Provides access to data in Extism memory
export class MemoryView extends DataView {
// @ts-ignore: TextDecoder
static #decoder = new TextDecoder();

constructor(memory?: MemoryHandle) {
super(memory ? memory.readBytes() : NULL)
super(memory ? memory.readBytes() : NULL);
}

// Returns true when the underlying memory handle is empty or undefined.
Expand All @@ -38,7 +39,7 @@ export class MemoryView extends DataView {

// Get the string representation of a value stored in Extism memory
text(): string {
return MemoryView.#decoder.decode(this.buffer)
return MemoryView.#decoder.decode(this.buffer);
}

// Read bytes from Extism memory into an ArrayBuffer
Expand All @@ -47,43 +48,67 @@ export class MemoryView extends DataView {
}

setInt8(_byteOffset: number, _value: number): void {
throw new Error('Cannot set values on MemoryView');
throw new Error("Cannot set values on MemoryView");
}

setInt16(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
throw new Error("Cannot set values on MemoryView");
}

setInt32(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
throw new Error("Cannot set values on MemoryView");
}

setUint8(_byteOffset: number, _value: number): void {
throw new Error('Cannot set values on MemoryView');
throw new Error("Cannot set values on MemoryView");
}

setUint16(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setUint16(
_byteOffset: number,
_value: number,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}

setUint32(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setUint32(
_byteOffset: number,
_value: number,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}

setFloat32(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setFloat32(
_byteOffset: number,
_value: number,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}

setFloat64(_byteOffset: number, _value: number, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setFloat64(
_byteOffset: number,
_value: number,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}

setBigInt64(_byteOffset: number, _value: bigint, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setBigInt64(
_byteOffset: number,
_value: bigint,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}

setBigUint64(_byteOffset: number, _value: bigint, _littleEndian?: boolean): void {
throw new Error('Cannot set values on MemoryView');
setBigUint64(
_byteOffset: number,
_value: bigint,
_littleEndian?: boolean,
): void {
throw new Error("Cannot set values on MemoryView");
}
}

Expand Down Expand Up @@ -120,7 +145,7 @@ function convertInput(input: Input): MemoryHandle {
}

export class Test {
// call a function from the Extism plugin being tested, passing in `Input` and returning the output as `MemoryView`, which
// call a function from the Extism plugin being tested, passing in `Input` and returning the output as `MemoryView`, which
// can be used to convert the type to a JavaScript native value.
static call(
funcName: string,
Expand Down
42 changes: 21 additions & 21 deletions scripts/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { build, emptyDir } from "@deno/dnt";
await emptyDir("./npm");

await build({
entryPoints: ["./index.ts"],
outDir: "./npm",
shims: {
// see JS docs for overview and more options
entryPoints: ["./index.ts"],
outDir: "./npm",
shims: {
// see JS docs for overview and more options
},
package: {
// package.json properties
name: "@dylibso/xtp-test",
version: Deno.args[0],
description: "XTP test harness",
license: "BSD-3-Clause",
bugs: {
email: "[email protected]",
},
package: {
// package.json properties
name: "@dylibso/xtp-test",
version: Deno.args[0],
description: "XTP test harness",
license: "BSD-3-Clause",
bugs: {
email: "[email protected]"
},
},
test: false,
postBuild() {
// steps to run after building and before running the tests
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");
},
});
},
test: false,
postBuild() {
// steps to run after building and before running the tests
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");
},
});

0 comments on commit c0d8747

Please sign in to comment.