2021-05-27 03:59:54 +00:00
|
|
|
import { database as db } from '../common/database';
|
|
|
|
import type { BaseModel } from './index';
|
|
|
|
import { generateId } from '../common/misc';
|
|
|
|
|
|
|
|
export const name = 'Space';
|
|
|
|
export const type = 'Space';
|
|
|
|
export const prefix = 'sp';
|
|
|
|
export const canDuplicate = false;
|
|
|
|
export const canSync = false;
|
|
|
|
|
2021-05-27 20:02:16 +00:00
|
|
|
// A base space represents "no" space, when viewing this base space fetch all workspaces with no parent.
|
|
|
|
// Using this instead of null.
|
|
|
|
export const BASE_SPACE_ID = 'base-space';
|
|
|
|
|
2021-05-27 03:59:54 +00:00
|
|
|
interface BaseSpace {
|
|
|
|
name: string;
|
2021-06-04 07:20:16 +00:00
|
|
|
remoteId: string | null;
|
2021-05-27 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Space = BaseModel & BaseSpace;
|
|
|
|
|
|
|
|
export function init(): BaseSpace {
|
|
|
|
return {
|
|
|
|
name: 'My Space',
|
2021-06-04 07:20:16 +00:00
|
|
|
remoteId: null, // `null` is necessary for the model init logic to work properly
|
2021-05-27 03:59:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function migrate(doc: Space) {
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createId() {
|
|
|
|
return generateId(prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function create(patch: Partial<Space> = {}) {
|
|
|
|
return db.docCreate<Space>(type, patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getById(_id: string) {
|
|
|
|
return db.getWhere<Space>(type, { _id });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function remove(obj: Space) {
|
|
|
|
return db.remove(obj);
|
|
|
|
}
|
|
|
|
|
2021-06-02 01:46:26 +00:00
|
|
|
export function update(space: Space, patch: Partial<Space>) {
|
|
|
|
return db.docUpdate(space, patch);
|
|
|
|
}
|
|
|
|
|
2021-05-27 03:59:54 +00:00
|
|
|
export function all() {
|
|
|
|
return db.all<Space>(type);
|
|
|
|
}
|