tuil
ReferencePackages@mwillbanks/tuil-registryAPI

FileRegistrySource

class exported by @mwillbanks/tuil-registry.

View rawEdit

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

MemberTypeRequiredDescriptionRelated types
__constructoranyYesThe __constructor member uses the any contract.
get(name: string) => Promise<RegistryItem | undefined>YesThe get member uses the (name: string) => Promise<RegistryItem | undefined> contract.RegistryItem
list() => Promise<readonly RegistryIndexEntry[]>YesThe 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.

Source

View the secondary source reference

Package

@mwillbanks/tuil-registry

On this page