-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmeta.ts
53 lines (47 loc) · 1.14 KB
/
meta.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
/* 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;
}
}