From 90e756ae4358fb6618dc25cbbdad1639ce2dae93 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 26 Feb 2024 13:40:47 -0800 Subject: [PATCH] refactor(daemon,cli): Consolidate pet name list commands --- packages/cli/src/commands/list.js | 12 ++++-------- packages/cli/src/endo.js | 7 ++----- packages/daemon/src/guest.js | 4 ---- packages/daemon/src/host.js | 4 ---- packages/daemon/src/mail.js | 8 +------- packages/daemon/src/types.d.ts | 2 -- packages/daemon/test/test-endo.js | 16 +++++++++------- 7 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/cli/src/commands/list.js b/packages/cli/src/commands/list.js index 548b005ce3..111b601455 100644 --- a/packages/cli/src/commands/list.js +++ b/packages/cli/src/commands/list.js @@ -3,16 +3,12 @@ import os from 'os'; import { E } from '@endo/far'; import { withEndoHost } from '../context.js'; -export const list = async ({ directoryName, special, all }) => +export const list = async ({ directoryPath }) => withEndoHost({ os, process }, async ({ host: party }) => { - if (directoryName !== undefined) { - party = E(party).lookup(directoryName); + if (directoryPath !== undefined) { + party = E(party).lookup(...directoryPath.split('.')); } - const petNames = await (() => { - if (all) return E(party).listAll(); - if (special) return E(party).listSpecial(); - return E(party).list(); - })(); + const petNames = await E(party).list(); for await (const petName of petNames) { console.log(petName); } diff --git a/packages/cli/src/endo.js b/packages/cli/src/endo.js index 69444fb0de..8495ad2c20 100644 --- a/packages/cli/src/endo.js +++ b/packages/cli/src/endo.js @@ -256,12 +256,9 @@ export const main = async rawArgs => { program .command('list [directory]') .description('show names known to the current or specified directory') - .option('-s,--special', 'show special names') - .option('--all', 'show all names') - .action(async (directoryName, cmd) => { - const { special, all } = cmd.opts(); + .action(async (directoryPath, cmd) => { const { list } = await import('./commands/list.js'); - return list({ directoryName, special, all }); + return list({ directoryPath }); }); program diff --git a/packages/daemon/src/guest.js b/packages/daemon/src/guest.js index 7772652344..ef1738395b 100644 --- a/packages/daemon/src/guest.js +++ b/packages/daemon/src/guest.js @@ -56,8 +56,6 @@ export const makeGuestMaker = ({ rename, remove, list, - listSpecial, - listAll, } = makeMailbox({ petStore, selfFormulaIdentifier: guestFormulaIdentifier, @@ -78,8 +76,6 @@ export const makeGuestMaker = ({ request, send, list, - listSpecial, - listAll, followNames, listMessages, followMessages, diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index 29cb7c72ab..beedb412a8 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -61,8 +61,6 @@ export const makeHostMaker = ({ dismiss, adopt, list, - listAll, - listSpecial, rename, remove, cancel, @@ -511,8 +509,6 @@ export const makeHostMaker = ({ request, send, list, - listSpecial, - listAll, followNames, listEntries, followEntries, diff --git a/packages/daemon/src/mail.js b/packages/daemon/src/mail.js index 914969c984..d1a5bf82f5 100644 --- a/packages/daemon/src/mail.js +++ b/packages/daemon/src/mail.js @@ -85,11 +85,7 @@ export const makeMailboxMaker = ({ }; /** @type {import('./types.js').Mail['list']} */ - const list = () => harden(petStore.list()); - /** @type {import('./types.js').Mail['listSpecial']} */ - const listSpecial = () => harden(Object.keys(specialNames).sort()); - /** @type {import('./types.js').Mail['listAll']} */ - const listAll = () => + const list = () => harden([...Object.keys(specialNames).sort(), ...petStore.list()]); /** @type {import('./types.js').Mail['reverseLookupFormulaIdentifier']} */ @@ -538,8 +534,6 @@ export const makeMailboxMaker = ({ dismiss, adopt, list, - listSpecial, - listAll, rename, remove, cancel, diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index 05c4dbae08..82364c81d5 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -362,8 +362,6 @@ export interface Mail { reverseLookup(value: unknown): Array; // Extended methods: lookup(...petNamePath: string[]): Promise; - listSpecial(): Array; - listAll(): Array; reverseLookupFormulaIdentifier(formulaIdentifier: string): Array; cancel(petName: string, reason: Error): Promise; // Mail operations: diff --git a/packages/daemon/test/test-endo.js b/packages/daemon/test/test-endo.js index 3fad922c82..af8a9ca2e6 100644 --- a/packages/daemon/test/test-endo.js +++ b/packages/daemon/test/test-endo.js @@ -1178,15 +1178,17 @@ test('list special names', async t => { const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); await E(host).store(readerRef, 'hello-text'); - const names = await E(host).list(); /** @type {string[]} */ - const specialNames = await E(host).listSpecial(); - const allNames = await E(host).listAll(); + const names = await E(host).list(); - t.deepEqual(['hello-text'], names); - t.assert(specialNames.length > 0); - t.assert(specialNames.every(name => name.toUpperCase() === name)); - t.deepEqual([...specialNames, ...names], allNames); + // There should be special names, but they are in flux at time of writing and + // we don't need to update this test for every change, so just verify that + // there's at least one for now. + t.assert(names.length > 1); + t.deepEqual( + names.filter(name => name.toUpperCase() !== name), + ['hello-text'], + ); }); test('guest cannot access host methods', async t => {