refactor(compartment-mapper)!: Rename endowments to globals
MODIFY
packages/compartment-mapper/README.md
packages/compartment-mapper/README.md
@@ -13,7 +13,7 @@ many libraries and applications work in Compartments without modification.
The `importLocation` function runs a compartmentalized application off the file
system.
-The `endowments` are properties to add to the `globalThis` in the global scope
+The `globals` are properties to add to the `globalThis` in the global scope
of the application's main package compartment.
The `modules` are built-in modules to grant the application's main package
compartment.
@@ -25,7 +25,7 @@ import { importLocation } from "@agoric/compartment-mapper";
// ...
const modules = { fs };
-const endowments = { console };
+const globals = { console };
const read = async location =>
fs.promises.readFile(new URL(location).pathname);
@@ -34,7 +34,7 @@ const { namespace } = await importLocation(
read,
moduleLocation,
{
- endowments,
+ globals,
modules
}
);
@@ -52,14 +52,14 @@ have.
> TODO
>
> A future version will allow application authors to distribute their choices
-> of global endowments and granted built-in modules to third-party packages
-> within the application, as with [LavaMoat].
+> of globals and built-in modules to third-party packages within the
+> application, as with [LavaMoat].
The `importLocation` function uses `loadLocation`.
Using `loadLocation` directly allows for deferred execution or multiple runs
-with different endowments or modules in the same process.
+with different globals or modules in the same process.
Calling `loadLocation` returns an `Application` object with an
-`import({ endowments?, modules? })` method.
+`import({ globals?, modules? })` method.
Use `writeArchive` to capture an application in an archival format.
Archives are `zip` files with a `compartment-map.json` manifest file.
@@ -94,7 +94,7 @@ import { importArchive } from "@agoric/compartment-mapper";
// ...
const modules = { fs };
-const endowments = { console };
+const globals = { console };
const read = async location =>
fs.promises.readFile(new URL(location).pathname);
@@ -103,7 +103,7 @@ const { namespace } = await importArchive(
read,
archiveLocation,
{
- endowments,
+ globals,
modules
}
);
@@ -111,10 +111,10 @@ const { namespace } = await importArchive(
The `importArchive` function composes `loadArchive` and `parseArchive`.
Use `loadArchive` to defer execution or run multiple times with varying
-endowments.
+globals.
Use `parseArchive` to construct a runner from the bytes of an archive.
The `loadArchive` and `parseArchive` functions return an `Application`
-object with an `import({ endowments?, modules? })` method.
+object with an `import({ globals?, modules? })` method.
# Package Descriptors
@@ -331,7 +331,7 @@ one workflow to the beginning of another, either as bytes or a location.
map compartments -> * * * * .'.| | |' : :
read archive -> | | | | ' * * * : :
unpack archive -> | | | | : * * * : :
-assemble compartments -> * * * * : + + * : : <- endowments
+assemble compartments -> * * * * : + + * : : <- powers
load compartments -> * * * * : + + * : :
import modules -> * | | : + + * : :
pack archive -> * * ' : :

MODIFY
packages/compartment-mapper/src/assemble.js
packages/compartment-mapper/src/assemble.js
@@ -123,13 +123,13 @@ const makeModuleMapHook = (
// Does not load or execute any modules.
// Uses makeImportHook with the given "location" string of each compartment in
// the DAG.
-// Passes the given endowments and external modules into the root compartment
+// Passes the given globals and external modules into the root compartment
// only.
export const assemble = (
{ entry, compartments: compartmentDescriptors },
{
makeImportHook,
- endowments = {},
+ globals = {},
transforms = [],
modules: exitModules = {},
Compartment = defaultCompartment
@@ -164,8 +164,8 @@ export const assemble = (
);
const resolveHook = resolve;
- // TODO also thread endowments selectively.
- const compartment = new Compartment(endowments, exitModules, {
+ // TODO also thread powers selectively.
+ const compartment = new Compartment(globals, exitModules, {
resolveHook,
importHook,
moduleMapHook,

MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -39,7 +39,7 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
const compartmentMap = json.parse(compartmentMapText, "compartment-map.json");
const execute = options => {
- const { endowments, modules, transforms } = options;
+ const { globals, modules, transforms } = options;
const {
compartments,
entry: { module: moduleSpecifier }
@@ -47,7 +47,7 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
const makeImportHook = makeArchiveImportHookMaker(archive, compartments);
const compartment = assemble(compartmentMap, {
makeImportHook,
- endowments,
+ globals,
modules,
transforms
});

MODIFY
packages/compartment-mapper/src/import.js
packages/compartment-mapper/src/import.js
@@ -26,11 +26,11 @@ export const loadLocation = async (read, moduleLocation) => {
);
const execute = async (options = {}) => {
- const { endowments, modules, transforms } = options;
+ const { globals, modules, transforms } = options;
const makeImportHook = makeImportHookMaker(read, packageLocation);
const compartment = assemble(compartmentMap, {
makeImportHook,
- endowments,
+ globals,
modules,
transforms
});

MODIFY
packages/compartment-mapper/test/main.test.js
packages/compartment-mapper/test/main.test.js
@@ -18,7 +18,7 @@ const fixture = new URL("node_modules/app/main.js", import.meta.url).toString();
const read = async location => fs.promises.readFile(new URL(location).pathname);
-const endowments = {
+const globals = {
endowment: 42
};
@@ -43,7 +43,7 @@ const assertFixture = (t, namespace) => {
t.equal(builtin, "builtin", "exports builtin");
- t.equal(endowed, endowments.endowment, "exports endowment");
+ t.equal(endowed, globals.endowment, "exports endowment");
t.deepEqual(
typecommon,
[42, 42, 42, 42],
@@ -77,7 +77,7 @@ let modules;
test("create builtin", async t => {
const utility = await loadLocation(read, builtinLocation);
- const { namespace } = await utility.import({ endowments });
+ const { namespace } = await utility.import({ globals });
// We pass the builtin module into the module map.
modules = {
builtin: namespace
@@ -89,7 +89,7 @@ test("loadLocation", async t => {
t.plan(fixtureAssertionCount);
const application = await loadLocation(read, fixture);
- const { namespace } = await application.import({ endowments, modules });
+ const { namespace } = await application.import({ globals, modules });
assertFixture(t, namespace);
});
@@ -97,7 +97,7 @@ test("importLocation", async t => {
t.plan(fixtureAssertionCount);
const { namespace } = await importLocation(read, fixture, {
- endowments,
+ globals,
modules
});
assertFixture(t, namespace);
@@ -108,7 +108,7 @@ test("makeArchive / parseArchive", async t => {
const archive = await makeArchive(read, fixture);
const application = await parseArchive(archive);
- const { namespace } = await application.import({ endowments, modules });
+ const { namespace } = await application.import({ globals, modules });
assertFixture(t, namespace);
});
@@ -128,7 +128,7 @@ test("writeArchive / loadArchive", async t => {
await writeArchive(fakeWrite, read, "app.agar", fixture);
const application = await loadArchive(fakeRead, "app.agar");
- const { namespace } = await application.import({ endowments, modules });
+ const { namespace } = await application.import({ globals, modules });
assertFixture(t, namespace);
});
@@ -148,7 +148,7 @@ test("writeArchive / importArchive", async t => {
await writeArchive(fakeWrite, read, "app.agar", fixture);
const { namespace } = await importArchive(fakeRead, "app.agar", {
- endowments,
+ globals,
modules
});
assertFixture(t, namespace);

refactor(compartment-mapper)!: Rename endowments to globals