Blockchain Commons Tags TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Interface TagsStore

    Tag registry implementation.

    Stores tags with their names and optional summarizer functions.

    interface TagsStore {
        insert(tag: Tag): void;
        insertAll(tags: Tag[]): void;
        setSummarizer(tagValue: CborNumber, summarizer: CborSummarizer): void;
        assignedNameForTag(tag: Tag): string | undefined;
        nameForTag(tag: Tag): string;
        tagForValue(value: CborNumber): Tag | undefined;
        tagForName(name: string): Tag | undefined;
        nameForValue(value: CborNumber): string;
        summarizer(tag: CborNumber): CborSummarizer | undefined;
    }

    Implements

    • TagsStoreTrait
    Index

    Methods

    • Insert a tag into the registry.

      Matches Rust's TagsStore::insert() behavior:

      • Throws if the tag name is undefined or empty
      • Throws if a tag with the same value exists with a different name
      • Allows re-registering the same tag value with the same name

      Parameters

      • tag: Tag

        The tag to register (must have a non-empty name)

      Returns void

      Error if tag has no name, empty name, or conflicts with existing registration

      const store = new TagsStore();
      store.insert(createTag(12345, 'myCustomTag'));
    • Insert multiple tags into the registry. Matches Rust's insert_all() method.

      Parameters

      • tags: Tag[]

        Array of tags to register

      Returns void

      const store = new TagsStore();
      store.insertAll([
      createTag(1, 'date'),
      createTag(100, 'custom')
      ]);
    • Register a custom summarizer function for a tag.

      Parameters

      • tagValue: CborNumber

        The numeric tag value

      • summarizer: CborSummarizer

        The summarizer function

      Returns void

      store.setSummarizer(1, (cbor, flat) => {
      // Custom date formatting
      return `Date(${extractCbor(cbor)})`;
      });
    • Get the assigned name for a tag, if any.

      Parameters

      • tag: Tag

        The tag to look up

      Returns string | undefined

      The assigned name, or undefined if no name is registered

    • Get a display name for a tag.

      Parameters

      • tag: Tag

        The tag to get a name for

      Returns string

      The assigned name if available, otherwise the tag value as a string

    • Look up a tag by its numeric value.

      Parameters

      • value: CborNumber

        The numeric tag value

      Returns Tag | undefined

      The Tag object if found, undefined otherwise

    • Look up a tag by its name.

      Parameters

      • name: string

        The tag name

      Returns Tag | undefined

      The Tag object if found, undefined otherwise

    • Get a display name for a tag value.

      Parameters

      • value: CborNumber

        The numeric tag value

      Returns string

      The tag name if registered, otherwise the value as a string

    • Get a custom summarizer function for a tag, if registered.

      Parameters

      • tag: CborNumber

        The numeric tag value

      Returns CborSummarizer | undefined

      The summarizer function if registered, undefined otherwise