Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(daemon,cli): Make and store at path #2281

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cli/src/commands/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import bundleSource from '@endo/bundle-source';
import { makeReaderRef } from '@endo/daemon';
import { E } from '@endo/far';
import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';
import { randomHex16 } from '../random.js';

const textEncoder = new TextEncoder();
Expand Down Expand Up @@ -38,6 +39,8 @@ export const makeCommand = async ({
return;
}

const resultPath = resultName && parsePetNamePath(resultName);

/** @type {import('@endo/eventual-send').FarRef<import('@endo/stream').Reader<string>> | undefined} */
let bundleReaderRef;
/** @type {string | undefined} */
Expand Down Expand Up @@ -68,9 +71,9 @@ export const makeCommand = async ({
workerName,
url.pathToFileURL(path.resolve(importPath)).href,
powersName,
resultName,
resultPath,
)
: E(agent).makeBundle(workerName, bundleName, powersName, resultName);
: E(agent).makeBundle(workerName, bundleName, powersName, resultPath);
const result = await resultP;
console.log(result);

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/endo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import url from 'url';

import { Command } from 'commander';
import { prompt } from './prompt.js';
import { parsePetNamePath } from './pet-name.js';

const packageDescriptorPath = url.fileURLToPath(
new URL('../package.json', import.meta.url),
Expand Down Expand Up @@ -370,7 +371,7 @@ export const main = async rawArgs => {
storeJson,
storeJsonStdin,
storeBigInt,
name,
name: parsePetNamePath(name),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really ought to be done in store.js to keep endo.js light and loosely coupled.

agentNames,
});
});
Expand Down
3 changes: 3 additions & 0 deletions packages/daemon/src/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export const makeDirectoryMaker = ({

/** @type {EndoDirectory['write']} */
const write = async (petNamePath, id) => {
if (typeof petNamePath === 'string') {
petNamePath = [petNamePath];
}
if (petNamePath.length === 1) {
const petName = petNamePath[0];
await petStore.write(petName, id);
Expand Down
12 changes: 5 additions & 7 deletions packages/daemon/src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ export const makeHostMaker = ({

/**
* @param {ERef<AsyncIterableIterator<string>>} readerRef
* @param {string} [petName]
* @param {string | string[]} [petName]
*/
const storeBlob = async (readerRef, petName) => {
/** @type {DeferredTasks<ReadableBlobDeferredTaskParams>} */
const tasks = makeDeferredTasks();

if (petName !== undefined) {
assertPetName(petName);
tasks.push(identifiers =>
petStore.write(petName, identifiers.readableBlobId),
E(directory).write(petName, identifiers.readableBlobId),
);
}

Expand All @@ -131,9 +130,8 @@ export const makeHostMaker = ({
const tasks = makeDeferredTasks();

if (petName !== undefined) {
assertPetName(petName);
tasks.push(identifiers =>
petStore.write(petName, identifiers.marshalId),
E(directory).write(petName, identifiers.marshalId),
);
}

Expand Down Expand Up @@ -244,7 +242,7 @@ export const makeHostMaker = ({
* Helper function for makeUnconfined and makeBundle.
* @param {string} powersName
* @param {string} workerName
* @param {string} [resultName]
* @param {string | string[]} [resultName]
*/
const prepareMakeCaplet = (powersName, workerName, resultName) => {
assertPowersName(powersName);
Expand All @@ -263,7 +261,7 @@ export const makeHostMaker = ({

if (resultName !== undefined) {
tasks.push(identifiers =>
petStore.write(resultName, identifiers.capletId),
E(directory).write(resultName, identifiers.capletId),
);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export interface NameHub {
): AsyncGenerator<PetStoreNameChange, undefined, undefined>;
lookup(...petNamePath: string[]): Promise<unknown>;
reverseLookup(value: unknown): Array<string>;
write(petNamePath: string[], id: string): Promise<void>;
write(petNamePath: string | string[], id: string): Promise<void>;
remove(...petNamePath: string[]): Promise<void>;
move(fromPetName: string[], toPetName: string[]): Promise<void>;
copy(fromPetName: string[], toPetName: string[]): Promise<void>;
Expand Down Expand Up @@ -568,7 +568,10 @@ export interface EndoHost extends EndoAgent {
readerRef: ERef<AsyncIterableIterator<string>>,
petName: string,
): Promise<FarRef<EndoReadable>>;
storeValue<T extends Passable>(value: T, petName: string): Promise<void>;
storeValue<T extends Passable>(
value: T,
petName: string | string[],
): Promise<void>;
provideGuest(
petName?: string,
opts?: MakeHostOrGuestOptions,
Expand Down
Loading