import { by_character, by_lurid } from '@andyburke/fsdb/organizers'; import { FSDB_COLLECTION } from '@andyburke/fsdb'; import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; /** * @typedef {object} TOPIC_PERMISSIONS * @property {string[]} read a list of user_ids with read permission for the topic * @property {string[]} write a list of user_ids with write permission for the topic * @property {string[]} read_events a list of user_ids with read_events permission for this topic * @property {string[]} write_events a list of user_ids with write_events permission for this topic */ /** * TOPIC * * @property {string} id - lurid (stable) * @property {string} name - channel name (max 64 characters, unique, unstable) * @property {string} creator_id - user id of the topic creator * @property {TOPIC_PERMISSIONS} permissions - permissions setup for the topic * @property {string} [icon_url] - optional url for topic icon * @property {string} [topic] - optional topic for the topic * @property {string} [rules] - optional topic rules (Markdown/text) * @property {string[]} [tags] - optional tags for the topic * @property {Record} [meta] - optional metadata about the topic * @property {Record} [emojis] - optional emojis table, eg: { 'rofl': 🤣, 'blap': 'https://somewhere.someplace/image.jpg' } */ export type TOPIC = { id: string; name: string; creator_id: string; permissions: { read: string[]; write: string[]; read_events: string[]; write_events: string[]; }; icon_url?: string; topic?: string; rules?: string; tags?: string[]; meta?: Record; emojis?: Record; // either: string: emoji eg: { 'rofl: 🤣, ... } or { 'rofl': 🤣, 'blap': 'https://somewhere.someplace/image.jpg' } timestamps: { created: string; updated: string; archived: string | undefined; }; }; export const TOPICS = new FSDB_COLLECTION({ name: 'topics', id_field: 'id', organize: by_lurid, indexers: { creator_id: new FSDB_INDEXER_SYMLINKS({ name: 'creator_id', field: 'creator_id', to_many: true, organize: by_lurid }), name: new FSDB_INDEXER_SYMLINKS({ name: 'name', get_values_to_index: (topic) => [topic.name.toLowerCase()], organize: by_character }), tags: new FSDB_INDEXER_SYMLINKS({ name: 'tags', get_values_to_index: (topic): string[] => { return (topic.tags ?? []).map((tag) => tag.toLowerCase()); }, to_many: true, organize: by_character }), topic: new FSDB_INDEXER_SYMLINKS({ name: 'topic', get_values_to_index: (topic): string[] => { return (topic.topic ?? '').split(/\W/); }, to_many: true, organize: by_character }) } });