Skip to content

Commit d0b4806

Browse files
committed
fix: Updates the add method to support Uint8Array
1 parent 12c1703 commit d0b4806

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @taskless/loader
22

3+
## 0.0.37
4+
5+
### Patch Changes
6+
7+
- Switches pack add command to use Uint8Arrays instead of buffers
8+
39
## 0.0.36
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@taskless/loader",
33
"description": "Taskless Loader - Take control of your third party APIs",
4-
"version": "0.0.36",
4+
"version": "0.0.37",
55
"author": "Taskless",
66
"license": "Apache-2.0",
77
"repository": "taskless/loader-js",

src/lib/taskless.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { createClient, type NormalizeOAS } from "fets";
2222
import { glob } from "glob";
2323
import { setupServer } from "msw/node";
24+
import { toUint8Array } from "uint8array-extras";
2425
import { createHandler } from "./msw.js";
2526
import { entriesToNetworkJson } from "./util/entriesToNetworkJson.js";
2627
import { createErrorAPI, InitializationError } from "./util/error.js";
@@ -30,6 +31,7 @@ import { makeSynchronousRequest } from "./workers/makeRequest.js";
3031
import type openapi from "../__generated__/openapi.js";
3132

3233
export type * from "../types.js";
34+
export { toUint8Array } from "uint8array-extras";
3335

3436
/** Autoloading interface for Taskless, hides manual pack loading and automatically initializes */
3537
export const autoload = (secret?: string, options?: InitOptions) => {
@@ -292,7 +294,7 @@ export const taskless = (
292294
/** Packs are added programatically or during the init step */
293295
const packs: Pack[] = [];
294296

295-
const moduleSource = new Map<string, MaybePromise<ArrayBuffer>>();
297+
const moduleSource = new Map<string, MaybePromise<Uint8Array>>();
296298

297299
/** WASM modules are added programatically or during the init step */
298300
const modules = new Map<string, Promise<Plugin>>();
@@ -384,7 +386,7 @@ export const taskless = (
384386
configuration: Pack["configuration"];
385387
url: Pack["url"];
386388
};
387-
const wasmContents = readFile(wasmPath);
389+
const wasmContents = readFile(wasmPath) as Promise<Uint8Array>;
388390
const pack: Pack = {
389391
...config,
390392
...manifest,
@@ -423,7 +425,8 @@ export const taskless = (
423425
},
424426
});
425427
logger.trace(`Fetched ${ident} from ${pack.url.source}`);
426-
return data.arrayBuffer();
428+
const buffer = await data.arrayBuffer();
429+
return toUint8Array(buffer);
427430
})()
428431
);
429432
}
@@ -517,7 +520,7 @@ export const taskless = (
517520
logger,
518521

519522
/** add additional local packs programatically */
520-
add(manifest: Manifest, wasm: ArrayBuffer) {
523+
add(manifest: Manifest, wasm: Uint8Array) {
521524
if (initialized) {
522525
throw new Error("A pack was added after Taskless was initialized");
523526
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type InitOptions = {
7878

7979
export type TasklessAPI = {
8080
logger: Logger;
81-
add(pack: Pack, wasm: ArrayBuffer): void;
81+
add(pack: Pack, wasm: Uint8Array): void;
8282
shutdown(waitMs?: number): Promise<void>;
8383
load(): Promise<{
8484
network: boolean;

test/pack_methods/chunk.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type ConsolePayload, type Pack } from "@~/types.js";
44
import { http } from "msw";
55
import { setupServer } from "msw/node";
66
import { packageDirectorySync } from "package-directory";
7+
import { toUint8Array } from "uint8array-extras";
78
import { describe, test, vi } from "vitest";
89

910
// hold a reference to this package's root for loading local WASM files
@@ -70,7 +71,7 @@ describe("Chunked encoding using SSE", () => {
7071
{
7172
...(JSON.parse(manifest.toString()) as Pack),
7273
},
73-
wasm
74+
toUint8Array(wasm.buffer as ArrayBuffer)
7475
);
7576

7677
// load taskless and init

test/packs.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { http } from "msw";
1010
import { setupServer } from "msw/node";
1111
import { packageDirectorySync } from "package-directory";
12+
import { toUint8Array } from "uint8array-extras";
1213
import { describe, test, vi } from "vitest";
1314

1415
// hold a reference to this package's root for loading local WASM files
@@ -78,7 +79,7 @@ describe("Loading packs", () => {
7879
{
7980
...(JSON.parse(manifest.toString()) as Pack),
8081
},
81-
wasm
82+
toUint8Array(wasm.buffer as ArrayBuffer)
8283
);
8384

8485
// validate load

0 commit comments

Comments
 (0)