importw icon indicating copy to clipboard operation
importw copied to clipboard

Permission restricted imports for Deno.

importw

Permission restricted imports for Deno.

Current version Current test status Deno docs PRs are welcome importw issues importw stars importw forks importw license importw is maintained Published on nest.land

importw latest /x/ version importw dependency count importw dependency outdatedness importw cached size


import {
  importw,
  release,
  worker,
} from "https://deno.land/x/[email protected]/mod.ts";

// Import module from within a worker.
const { log, add, [release]: terminate, [worker]: workerRef } = await importw(
  "https://deno.land/x/[email protected]/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();

About

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.

Examples

Please refer to examples README.

Contributing

Contributing guide


License

importw is licensed under the MIT License.

This module makes use of several ported sub-modules, each containing their original license.