Skip to content

Commit

Permalink
feat(daemon): NameHubs expose listIdentifiers method
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Mar 3, 2024
1 parent bd762c3 commit fc4c179
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/daemon/src/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ export const makeDirectoryMaker = ({
return hub.list();
};

/** @type {import('./types.js').EndoDirectory['listIdentifiers']} */
const listIdentifiers = async (...petNamePath) => {
const names = await list(...petNamePath);
const identities = new Set();
await Promise.all(
names.map(async name => {
const formulaIdentifier = await identify(...petNamePath, name);
if (formulaIdentifier !== undefined) {
identities.add(formulaIdentifier);
}
}),
);
return Array.from(identities);
};

/** @type {import('./types.js').EndoDirectory['followChanges']} */
const followChanges = async function* followChanges(...petNamePath) {
if (petNamePath.length === 0) {
Expand Down Expand Up @@ -179,6 +194,7 @@ export const makeDirectoryMaker = ({
has,
identify,
list,
listIdentifiers,
followChanges,
lookup,
reverseLookup,
Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const makeGuestMaker = ({
has,
identify,
list,
listIdentifiers,
followChanges,
lookup,
reverseLookup,
Expand Down Expand Up @@ -97,6 +98,7 @@ export const makeGuestMaker = ({
has,
identify,
list,
listIdentifiers,
followChanges,
lookup,
reverseLookup,
Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export const makeHostMaker = ({
has,
identify,
list,
listIdentifiers,
followChanges,
lookup,
reverseLookup,
Expand Down Expand Up @@ -546,6 +547,7 @@ export const makeHostMaker = ({
has,
identify,
list,
listIdentifiers,
followChanges,
lookup,
reverseLookup,
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export interface NameHub {
has(...petNamePath: string[]): Promise<boolean>;
identify(...petNamePath: string[]): Promise<string | undefined>;
list(...petNamePath: string[]): Promise<Array<string>>;
listIdentifiers(...petNamePath: string[]): Promise<Array<string>>;
followChanges(
...petNamePath: string[]
): AsyncGenerator<PetStoreNameDiff, undefined, undefined>;
Expand Down

0 comments on commit fc4c179

Please sign in to comment.