blob: 6c70adc1d8506e39709fde9020b40b117e1d1aca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { ScriptingGlobals } from '../client/util/ScriptingGlobals';
import { Copy, FieldChanged, Parent, ToJavascriptString, ToScriptString, ToString } from './FieldSymbols';
import { RefField } from './RefField';
export abstract class ObjectField {
// prettier-ignore
public [FieldChanged]?: (diff?: { op: '$addToSet' | '$remFromSet' | '$set';
items: FieldType[] | undefined;
length: number | undefined;
hint?: any }, serverOp?: any) => void;
// eslint-disable-next-line no-use-before-define
public [Parent]?: RefField | ObjectField;
abstract [Copy](): ObjectField;
abstract [ToJavascriptString](): string;
abstract [ToScriptString](): string;
abstract [ToString](): string;
static MakeCopy<T extends ObjectField>(field: T) {
return field?.[Copy]();
}
}
export type FieldType = number | string | boolean | ObjectField | RefField; // bcz: hack for now .. must match the type definition in Doc.ts .. put here to avoid import cycles
// eslint-disable-next-line import/no-mutable-exports
export let ObjGetRefField: (id: string, force?: boolean) => Promise<RefField | undefined>;
// eslint-disable-next-line import/no-mutable-exports
export let ObjGetRefFields: (ids: string[]) => Promise<{ [id: string]: RefField | undefined }>;
export function SetObjGetRefField(func: (id: string, force?: boolean) => Promise<RefField | undefined>) {
ObjGetRefField = func;
}
export function SetObjGetRefFields(func: (ids: string[]) => Promise<{ [id: string]: RefField | undefined }>) {
ObjGetRefFields = func;
}
ScriptingGlobals.add(ObjectField);
|