-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmeta.ts
More file actions
63 lines (56 loc) · 1.36 KB
/
meta.ts
File metadata and controls
63 lines (56 loc) · 1.36 KB
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
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Stores meta data for the indexing process and search results.
*/
export class Meta {
/**
* The meta entries.
*/
private readonly entries: Map<string, any>;
/**
* Creates a new instance of the Meta class.
* @param entries The meta entries.
*/
public constructor(entries?: Map<string, any>) {
if (entries !== undefined) {
this.entries = entries;
} else {
this.entries = new Map<string, any>();
}
}
/**
* Adds a new meta entry.
* @param key The key of the entry.
* @param value The value of the entry.
*/
public add(key: string, value: any): void {
if (this.entries.has(key)) {
throw new Error(`A meta entry with key ${key} is already present.`);
}
this.entries.set(key, value);
}
/**
* Returns the meta entry with the given key.
* @param key
* @returns The meta entry.
*/
public get(key: string): any {
return this.entries.get(key);
}
/**
* Returns all meta entries.
* @returns All meta entries.
*/
public get allEntries(): ReadonlyMap<string, any> {
return this.entries;
}
/**
* Serializes the meta object to a JSON object.
* @returns The JSON representation of the meta object.
*/
public toJSON(): object {
return {
entries: Object.fromEntries(this.entries)
};
}
}