logo logo
Design: Database: TID-Updated meta

Database TID-Updated
Purpose Notify clients when member first visits a topic.
Cardinality one TID-Updated database per topic
one TopicMemberItem for the topic creator.
one TopicMemberItem per other member who visited the topic.
Source Code
Items src/ts/dbitems/TID-Updated.ts
Zod Models
item TopicMemberItem
item.item TopicMemberRecord
TopicMemberItem
itemId member number invited to topic
item: TopicMemberRecord
    kind 'topicmember'
    tnum this topic's topic number
    mnum member number invited to topic (same as itemId)
    mtid MTID of member's MTID-Activity database with their comments

Description

The TID-Updated database is created when a member creates a new topic.
It holds one TopicMemberItem for the creator and each other member who visited the topic.

  (see userbase-js/types/index.d.ts)

  export interface Item {              userbase item
    itemId: string                    ╭────────────────────────────────────┐
    item: any ───────────────────────▶│ kind: 'topicmember'                │
    createdBy: Attribution            │ tnum: 1                            │
    updatedBy?: Attribution           │ mnum: 2                            │
    fileId?: string                   │ mtid: '01HPJFDKDXJCR2Z067PZGHF3YC' │
    fileName?: string                 ╰────────────────────────────────────┘
    fileSize?: number             
    fileUploadedBy?: Attribution  
    writeAccess?: AccessControl   
  }                                   

Need

The TID-Updated database solves a specific issue involving how clients are notified of updates when new comments are added to a topic.

When a member visits a topic page, Securepub sets up a source which queries the corresponding TID-Topic database. Then for each member in the topic Securepub sets up another source to query that member's MTID-Activity database in order to show that member's comments.

The problem is a member's MTID-Activity database is created "on demand" and may not exist at the time other members open the topic so it can't be subscribed to in advance - Userbase provides no means to notify clients when a database is created.

To address this Securepub uses a second TID-Updated database created along with TID-Topic when the topic is added. Unlike TID-Topic, TID-Updated is writable by all members invited to a topic.

When Securepub creates the MTID-Activity database for a member it also adds a TopicMemberItem to the TID-Updated database. Clients subscribed to TID-Updated database observe the change and know to subscribe to the new MTID-Activity database to access comments within.


TopicMemberItem

The TID-Updated database holds one TopicMemberItem for the creator of the topic and each member who visited the topic. The item's Attribution indicates the MTID-Activity database containing that member's comments exists.

Ownership and Access

The creator of the topic is the owner of the TID-Updated database for the topic.

The TID-Updated database is writable by all members of the topic.

Zod models

The following Zod models show how the Userbase items are represented in memory.

Note that in addition to the values specified by the Userbase Item interface the kind and database attributes are added during deserialization.


TopicMemberItem

See TopicMemberItem on the design page for the TID-Topic database.