-
Notifications
You must be signed in to change notification settings - Fork 1
/
vcsObject.ts
75 lines (61 loc) · 1.53 KB
/
vcsObject.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { v4 as uuidv4 } from 'uuid';
import { getLogger, type Logger } from '@vcsuite/logger';
import { moduleIdSymbol } from './moduleIdSymbol.js';
export type VcsObjectOptions = {
/**
* the type of object, typically only used in configs
*/
type?: string;
/**
* name of the object, if not given a uuid is generated, is used for the framework functions getObjectByName
*/
name?: string;
/**
* key value store for framework independent values per Object
*/
properties?: Record<string, unknown>;
};
/**
* baseclass for all Objects
*/
class VcsObject {
static get className(): string {
return 'VcsObject';
}
/**
* unique Name
*/
readonly name: string;
properties: Record<string, unknown>;
isDestroyed: boolean;
[moduleIdSymbol]?: string;
constructor(options: VcsObjectOptions) {
this.name = options.name || uuidv4();
this.properties = options.properties || {};
this.isDestroyed = false;
}
get className(): string {
return (this.constructor as typeof VcsObject).className;
}
getLogger(): Logger {
return getLogger(this.className);
}
toJSON(): VcsObjectOptions {
const config: VcsObjectOptions = {
type: this.className,
name: this.name,
};
if (Object.keys(this.properties).length > 0) {
config.properties = JSON.parse(JSON.stringify(this.properties)) as Record<
string,
unknown
>;
}
return config;
}
destroy(): void {
this.isDestroyed = true;
this.properties = {};
}
}
export default VcsObject;