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