From ad8097878e7680f2de2019fdd286d94b8b43e38c Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Tue, 30 Apr 2024 18:40:29 -0700 Subject: [PATCH 1/3] feat(daemon,cli): Make caplets in pet name paths --- packages/cli/src/commands/make.js | 7 +++++-- packages/daemon/src/directory.js | 3 +++ packages/daemon/src/host.js | 4 ++-- packages/daemon/src/types.d.ts | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/make.js b/packages/cli/src/commands/make.js index af8274c2d8..a26484d500 100644 --- a/packages/cli/src/commands/make.js +++ b/packages/cli/src/commands/make.js @@ -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(); @@ -38,6 +39,8 @@ export const makeCommand = async ({ return; } + const resultPath = resultName && parsePetNamePath(resultName); + /** @type {import('@endo/eventual-send').FarRef> | undefined} */ let bundleReaderRef; /** @type {string | undefined} */ @@ -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); diff --git a/packages/daemon/src/directory.js b/packages/daemon/src/directory.js index 114dac1dc1..974b896def 100644 --- a/packages/daemon/src/directory.js +++ b/packages/daemon/src/directory.js @@ -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); diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index 297ab01d79..9f646ef020 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -244,7 +244,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); @@ -263,7 +263,7 @@ export const makeHostMaker = ({ if (resultName !== undefined) { tasks.push(identifiers => - petStore.write(resultName, identifiers.capletId), + E(directory).write(resultName, identifiers.capletId), ); } diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index c8d5633783..0325e3389f 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -446,7 +446,7 @@ export interface NameHub { ): AsyncGenerator; lookup(...petNamePath: string[]): Promise; reverseLookup(value: unknown): Array; - write(petNamePath: string[], id: string): Promise; + write(petNamePath: string | string[], id: string): Promise; remove(...petNamePath: string[]): Promise; move(fromPetName: string[], toPetName: string[]): Promise; copy(fromPetName: string[], toPetName: string[]): Promise; From d54402da91b23b4e00bf6fa03550ea7b04ec659c Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 9 May 2024 12:50:07 -0700 Subject: [PATCH 2/3] feat(daemon,cli): Store at pet name path --- packages/daemon/src/host.js | 8 +++----- packages/daemon/src/types.d.ts | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index 9f646ef020..adefd34b47 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -108,16 +108,15 @@ export const makeHostMaker = ({ /** * @param {ERef>} readerRef - * @param {string} [petName] + * @param {string | string[]} [petName] */ const storeBlob = async (readerRef, petName) => { /** @type {DeferredTasks} */ const tasks = makeDeferredTasks(); if (petName !== undefined) { - assertPetName(petName); tasks.push(identifiers => - petStore.write(petName, identifiers.readableBlobId), + E(directory).write(petName, identifiers.readableBlobId), ); } @@ -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), ); } diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index 0325e3389f..ca24959d01 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -568,7 +568,10 @@ export interface EndoHost extends EndoAgent { readerRef: ERef>, petName: string, ): Promise>; - storeValue(value: T, petName: string): Promise; + storeValue( + value: T, + petName: string | string[], + ): Promise; provideGuest( petName?: string, opts?: MakeHostOrGuestOptions, From 33c70b35b77691bbbeff77dd55c1eb559602fed4 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Wed, 15 May 2024 11:03:14 -0700 Subject: [PATCH 3/3] feat(cli): Support pet name paths for store command --- packages/cli/src/endo.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/endo.js b/packages/cli/src/endo.js index 54b01d692b..2b1d318df7 100644 --- a/packages/cli/src/endo.js +++ b/packages/cli/src/endo.js @@ -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), @@ -370,7 +371,7 @@ export const main = async rawArgs => { storeJson, storeJsonStdin, storeBigInt, - name, + name: parsePetNamePath(name), agentNames, }); });