Permission restricted imports for Deno.
import {
importw,
release,
worker,
} from "https://deno.land/x/importw@1.1.0/mod.ts";
// Import module from within a worker.
const { log, add, [release]: terminate, [worker]: workerRef } = await importw(
"https://deno.land/x/importw@1.1.0/examples/basic/exampleMod.ts",
{
name: "exampleWorker",
deno: false,
},
);
// Have access to the underlying Worker
console.log(workerRef.constructor.name); // Worker
// Run code within the Worker
await log(`add(40, 2) in a worker:`, await add(40, 2));
// Gracefully release Worker resources
await terminate();
This module allows users to import modules from within a Deno Worker and expose the methods to the main runtime.
This allows for a degree of isolation around the imported module, and allows consumers to restrict an imported module's access to the Deno namespace and / or privileged operations.
Note: this module does not provide full isolation as Workers run in-process. If your code is long running you may be vulnerable to side channel timing attacks.
This module consists of ports / adaptions of Comlink and import-from-worker to create the bridge between main runtime and Worker.
Please refer to examples README.
importw is licensed under the MIT License.
This module makes use of several ported sub-modules, each containing their original license.