FileRegistrySource
class exported by @mwillbanks/tuil-registry.
class
Public class exported by @mwillbanks/tuil-registry.
export class FileRegistrySource implements RegistrySource {
constructor(
readonly id: string,
readonly directory: string,
) {}
async get(name: string): Promise<RegistryItem | undefined> {
try {
const itemPath = validateRegistryPath(name);
const value = JSON.parse(
await readFile(join(this.directory, `${itemPath}.json`), "utf8"),
) as unknown;
return parseRegistrySourceItem(value, this.id, name);
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
return undefined;
}
throw error;
}
}
async list(): Promise<readonly RegistryIndexEntry[]> {
const value = JSON.parse(
await readFile(join(this.directory, "registry.json"), "utf8"),
) as { items?: RegistryIndexEntry[] } | RegistryIndexEntry[];
const items = Array.isArray(value) ? value : (value.items ?? []);
return items.map((entry) => parseFileRegistryIndexEntry(entry, this.id));
}
}Members
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
__constructor | any | Yes | The __constructor member uses the any contract. | — |
get | (name: string) => Promise<RegistryItem | undefined> | Yes | The get member uses the (name: string) => Promise<RegistryItem | undefined> contract. | RegistryItem |
list | () => Promise<readonly RegistryIndexEntry[]> | Yes | The list member uses the () => Promise<readonly RegistryIndexEntry[]> contract. | RegistryIndexEntry |
Parameters
This declaration has no public members.
Returns
This declaration does not return a value.
Throws
No thrown errors are documented for this declaration.
Related types
Source
View the secondary source reference