This model manages distributed lists of data in so called 'channels'.

A channel is a list of objects stored as merkle-tree indexed by time. The list is sorted by creation time so that it can be distributed and merged.

Each channel is identified by a channelId (just a string) and the owner. In a distributed network only the owner can create channels. TODO: explain more about access rights and distribution and everything!

The structure is as follows: TODO: add PlantUml graph here

NOTE: This class manages one global one object called ChannelRegistry It therefore does not make sense to have multiple ChannelManager objects. We don't use a singleton, because it makes it harder to track where channels are used.

Constructors

Properties

defaultOwner: undefined | SHA256IdHash<Person>

The default owner when creating ot posting to a channel.

This also changes the default author of posted data.

If undefined, your main identity will be used.

onUpdated: OEvent<((channelInfoIdHash: SHA256IdHash<ChannelInfo>, channelId: string, channelOwner: null | SHA256IdHash<Person>, timeOfEarliestChange: Date, data: (RawChannelEntry & {
    isNew: boolean;
})[]) => void)> = ...

Methods

  • Returns the default author if set manually or my main identity if unset.

    Returns Promise<SHA256IdHash<Person>>

  • Converts the raw represantation to ObjectData representation.

    Parameters

    Returns Promise<ObjectData<OneObjectTypes>>

  • Create a new channel.

    If the channel already exists, this call is a noop.

    Parameters

    • channelId: string

      The id of the channel. See class description for more details on how ids and channels are handled.

    • Optionalowner: null | SHA256IdHash<Person>

      If the owner is not passed, then your own main identity is used. If the owner is NULL, then no owner is set. If a value is given, then the value will be used as an owner.

    Returns Promise<SHA256IdHash<ChannelInfo>>

  • Get the "AppendSenderProfile" setting for the specified channel.

    Parameters

    Returns boolean

  • Get the "maxSize" setting for the specified channel.

    Parameters

    Returns undefined | number

  • Get the "RegisterSenderProfileAtLeute" setting for the specified channel.

    Parameters

    Returns boolean

  • This returns the list of matching channel infos based on ChannelSelectionOptions.

    It usually returns the channel infos of the latest merged versions, not the latest version in the version maps. Only if the ChannelSelectionOptions reference a specific version this version is returned instead of the latest merged one.

    Parameters

    Returns Promise<ChannelInfo[]>

  • Obtain a specific object from a channel.

    This is a very inefficient implementation, because it iterates over the chain. In the future it would be better to just pick the object with the passed hash. But this only works when we have working reverse maps for getting the metadata. The other option would be to use the hash of the indexed metadata as id, then we don't have the reverse map problem.

    Type Parameters

    • T extends OneObjectTypeNames

    Parameters

    • id: string

      id of the object to extract

    • type: T

      Type of objects to retrieve. If type does not match an error is thrown.

    Returns Promise<ObjectData<OneObjectInterfaces[T]>>

  • Get all data from one or multiple channels.

    Note the behavior when using ascending ordering (default) and count. It will return the 'count' latest elements in ascending order, not the 'count' oldest elements. It is counter intuitive and should either be fixed or the iterator interface should be the mandatory

    Parameters

    Returns Promise<ObjectData<OneObjectTypes>[]>

  • Get all data from a channel.

    Type Parameters

    • T extends OneObjectTypeNames

    Parameters

    • type: T

      Type of objects to retrieve. If type does not match the object is skipped.

    • OptionalqueryOptions: QueryOptions

    Returns Promise<ObjectData<OneObjectInterfaces[T]>[]>

  • Check if passed channel exists.

    Parameters

    • channelId: string
    • owner: SHA256IdHash<Person>

    Returns Promise<boolean>

  • Init this instance.

    This will iterate over all channels and check whether all versions have been merged. If not it will merge the unmerged versions.

    Note: This has to be called after the one instance is initialized.

    Returns Promise<void>

  • Iterate over all objects in the channels matching the query options.

    Note that the sort order is not supported. It is silently ignored. Items are always returned in descending order regarding time. It is a single linked list underneath, so no way of efficiently iterating in the other direction.

    Parameters

    Returns AsyncIterableIterator<ObjectData<OneObjectTypes>>

  • Iterate over all objects in the channels matching the query options.

    This method also returns only the objects of a certain type.

    Type Parameters

    • T extends OneObjectTypeNames

    Parameters

    • type: T

      The type of the elements to iterate

    • OptionalqueryOptions: QueryOptions

    Returns AsyncIterableIterator<ObjectData<OneObjectInterfaces[T]>>

  • Post a new object to a channel.

    Type Parameters

    • T extends OneObjectTypes

    Parameters

    • channelId: string

      The id of the channel to post to

    • data: T

      The object to post to the channel

    • OptionalchannelOwner: null | SHA256IdHash<Person>

      If the owner is not passed, then your own main identity is used. If the owner is NULL, then no owner is set. If a value is given, then the value will be used as an owner.

    • Optionaltimestamp: number
    • Optionalauthor: SHA256IdHash<Person>

    Returns Promise<void>

  • Post a new object to a channel but only if it was not already posted to the channel

    Note: This will iterate over the whole tree if the object does not exist, so it might be slow.

    Type Parameters

    • T extends OneObjectTypes

    Parameters

    • channelId: string

      The id of the channel to post to

    • data: T

      The object to post to the channel

    • OptionalchannelOwner: null | SHA256IdHash<Person>

      If the owner it's not passed, then the this.defaultOwner is set. If the owner it's NULL, then no owner is set. If a value is given, then the value will be used as an owner.

    Returns Promise<void>

  • Enable appending the default profile of the sender to each channel entry.

    Default is disabled

    Parameters

    • channel: SHA256IdHash<ChannelInfo>
    • Optionalenable: boolean

    Returns void

  • If size is specified, then restrict the size of a channel to this amount.

    Excess data is deleted by the merge algorithms.

    Parameters

    • channel: SHA256IdHash<ChannelInfo>
    • OptionalmaxSize: number

    Returns void

  • Enable registering as metadata attached profiles with leute.

    Default is disabled

    Parameters

    • channel: SHA256IdHash<ChannelInfo>
    • Optionalenable: boolean

    Returns void

  • Find the differences in the chain starting from the common history

    Note: this only works when both channel infos are from the same channel.

    Parameters

    Returns AsyncIterableIterator<RawChannelEntry>

  • Iterate multiple iterators by returning always the most current element of all of them.

    It is assumed, that the iterators will return the elements sorted from highest to lowest value.

    Example:

    If you have multiple iterators (iter1, iter2, iter3) that would return these items:

    • iter1: 9, 5, 3
    • iter2: 8, 7, 6, 1
    • iter3: 4, 2

    Then this iterator implementation would return the items with these creation times: 9, 8, 7, 6, 5, 4, 3, 2, 1

    When two or more iterators reach the same history, then the first iterator in the iterator list will continue iterating. The other iterators will stop. This is relevant if one iterator is faster than the other (because one iterator iterates over cached values instead of one objects -> e.g. an element cache in ui elements.)

    Parameters

    • iterators: AsyncIterableIterator<RawChannelEntry>[]
    • terminateOnSingleIterator: boolean = false

      If true, then stop iteration when all but one iterator reached their end. The first element of the last iterator is still returned, but then iteration stops. This is very useful for merging algorithms, because they can use the last item as common history for merging. Because this iteration also removes redundant iterators (that iterate over the same history) it will stop when multiple iterators iterate the same history.

    • yieldCommonHistoryElement: boolean = true

      If true (default) the common history element will be yielded as last element

    • onlyDifferentElements: boolean = false

      If true (default false) only elements that are only in a single channel are yielded.

    Returns AsyncIterableIterator<RawChannelEntry & {
        activeIteratorCount: number;
        iterIndex: number;
    }>

    the RawChannelEntry, iterIndex (the index of the iterator in the iterators array that yielded this RawChannelEntry), activeIteratorCount (number of iterators that were active when this element was yielded)

  • This iterator just iterates the data elements of the passed channel.

    Note: If you want to start iterating from a specific point in the chain and not from the start, you can just construct your own ChannelInfo object and set the head to the ChannelEntry where you want to start iterating.

    Parameters

    • channelInfo: ChannelInfo

      iterate this channel

    • Optionalfrom: Date
    • Optionalto: Date
    • Optionalids: string[]
    • OptionalloadAuthor: boolean

    Returns AsyncIterableIterator<RawChannelEntry>