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(cli,daemon): Support dot-delimited petname paths for CLI eval command #2034

Merged
merged 4 commits into from
Feb 8, 2024

Conversation

rekmarks
Copy link
Contributor

@rekmarks rekmarks commented Feb 5, 2024

Ref: #2023

Description

Adds support for dot-delimited petname paths to the CLI eval command. This required modifications to the evaluate method of the daemon's host.js, and the introduction of a new formula type, lookup.

The lookup formula type is necessary because the names in a lookup path may have neither petnames nor formula identifiers associated with them. Consider:

> endo eval '10' --name ten
10
> endo eval 'foo' foo:INFO.ten.source
10

The only way retrieve the value for source is to call E(HOST).lookup('INFO', 'ten', 'source'), and since the eval formula expects its values to be mediated by formula identifiers, the lookup of INFO.ten.source must itself be stored as a formula.

The lookup formula is an -id512 formula with the following interface:

type LookupFormula = {
  type: 'lookup';

  /**
   * The formula identifier of the naming hub to call lookup on.
   * A "naming hub" is an object with a variadic `lookup()` method.
   */
  hub: string;

  /**
   * The pet name path.
   */
  path: Array<string>;
};

The lookup formula introduces the language of "naming hubs" into the daemon codebase. At present the only such objects are guests and hosts, which are also agents, but the category of naming hubs is expected to grow to include non-agent objects.

@rekmarks rekmarks force-pushed the rekmarks-dot-delimited-lookup branch from 716a073 to 42cdabc Compare February 5, 2024 21:23
Adds support for dot-delimited petname paths to the CLI
`eval` command. This required modifications to the `evaluate`
method of the daemon's `host.js`, and the introduction of a
new formula type, `lookup`, modeled on the `web-bundle`
formula. Also adds a unit test for this behavior.

The `lookup` formula type is necessary because the names
in a lookup path may have neither petnames nor formula
identifiers associated with them. Consider:

```text
> endo eval '10' --name ten
10
> endo eval 'foo' foo:INFO.ten.source
10
```

The only way retrieve the value for `source` is to call
`E(HOST).lookup('INFO', 'ten', 'source')`, and since the `eval`
formula expects its values to be mediated by formula identifiers,
the lookup of `INFO.ten.source` must itself be stored as
a formula.
@rekmarks rekmarks force-pushed the rekmarks-dot-delimited-lookup branch from 42cdabc to d35bbe2 Compare February 5, 2024 21:36
packages/daemon/src/daemon.js Outdated Show resolved Hide resolved
packages/daemon/src/daemon.js Outdated Show resolved Hide resolved
packages/daemon/src/pet-store.js Outdated Show resolved Hide resolved
@rekmarks rekmarks force-pushed the rekmarks-dot-delimited-lookup branch from 1abcb4f to f0aefd8 Compare February 7, 2024 03:13
Comment on lines +217 to +230
const petNamePath = petNamePathFrom(petNameOrPath);
if (petNamePath.length === 1) {
const formulaIdentifier = lookupFormulaIdentifierForName(
petNamePath[0],
);
if (formulaIdentifier === undefined) {
throw new Error(`Unknown pet name ${q(petNamePath[0])}`);
}
return formulaIdentifier;
}
return formulaIdentifier;

const { formulaIdentifier: lookupFormulaIdentifier } =
await provideLookupFormula(petNamePath);
return lookupFormulaIdentifier;
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to factor out a lookupFormulaIdentifierForPath function. This won’t be the last place we use it.

Copy link
Contributor Author

@rekmarks rekmarks Feb 8, 2024

Choose a reason for hiding this comment

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

We will do this later if necessary. Leaving this unresolved as a breadcrumb.

packages/daemon/src/mail.js Outdated Show resolved Hide resolved
Lookup formulas must be associated with the namespace for
which the pet name path is valid. In practice, this means
an object with a variadic `lookup()` method. Previously, these
objects were referred to as "agents", but in the future, not
all such object will be agents (i.e. guests or hosts). Therefore,
here we replace all references to "agent" with "hub", short
for "naming hub".
@rekmarks rekmarks force-pushed the rekmarks-dot-delimited-lookup branch from f0aefd8 to e6f36a1 Compare February 8, 2024 18:40
@rekmarks rekmarks changed the title feat(cli,daemon): Support dot-delimited petname paths for all CLI commands feat(cli,daemon): Support dot-delimited petname paths for eval CLI command Feb 8, 2024
@rekmarks rekmarks marked this pull request as ready for review February 8, 2024 18:57
@rekmarks rekmarks changed the title feat(cli,daemon): Support dot-delimited petname paths for eval CLI command feat(cli,daemon): Support dot-delimited petname paths for CLI eval command Feb 8, 2024
@rekmarks rekmarks merged commit 4a3c8c0 into endo Feb 8, 2024
14 checks passed
@rekmarks rekmarks deleted the rekmarks-dot-delimited-lookup branch February 8, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants