@@ -2,11 +2,19 @@ import type { BlobType, LiteralUnion } from '../../shared'
2
2
3
3
import { err } from './err'
4
4
5
+ /**
6
+ * Tags Manager for result system. It's used to create a tag for a result.
7
+ * Use `Tags.create` to create a new instance. Use `Tags.add` to add a new tag.
8
+ * For better type inference, use with chaining `Tags.add(...).add(...)`.
9
+ */
5
10
export class Tags < U extends [ string , string ] , T extends string > {
6
11
tags = new Map < string , string > ( )
7
12
8
13
constructor ( protected base : T ) { }
9
14
15
+ /**
16
+ * Adds a new tag to the Tag Manager.
17
+ */
10
18
add < K extends string , V extends string = never > ( key : K , value ?: V ) {
11
19
const tag = `${ this . base } .${ value ?? key } `
12
20
@@ -17,6 +25,10 @@ export class Tags<U extends [string, string], T extends string> {
17
25
return this as Tags < U | [ K , V ] , T >
18
26
}
19
27
28
+ /**
29
+ * Gets a specific key (can be a tag or a value) from the Tag Manager.
30
+ * If the key is not found, an error is thrown.
31
+ */
20
32
get < K extends LiteralUnion < U [ '0' ] , `?${string } `> > ( key : K ) {
21
33
const found = this . tags . get ( key )
22
34
@@ -31,6 +43,9 @@ export class Tags<U extends [string, string], T extends string> {
31
43
return found as R extends never ? `${T } .${K } ` : `${T } .${R } `
32
44
}
33
45
46
+ /**
47
+ * Checks if the Tag Manager has a specific key (can be a tag or a value).
48
+ */
34
49
has < const K extends string > (
35
50
key : K
36
51
) : K extends Std . ExtractErrors < Tags < U , T > > ? true : K extends U [ '0' ] ? true : false {
0 commit comments