@@ -12,16 +12,17 @@ import type {
12
12
* application during production. These values are embedded via the Go server,
13
13
* so they will never exist when using a JavaScript runtime for the backend
14
14
*
15
- * If you need to add a new type of metadata value, add a new property to the
16
- * type alias here, and then rest of the file should light up with errors for
17
- * what else needs to be adjusted
15
+ * If you want to add new metadata in a type-safe way, add it to this type.
16
+ * Each key should the name of the "property" attribute that will be used on the
17
+ * HTML elements themselves, and the values should be the data you get back from
18
+ * parsing those element's text content
18
19
*/
19
20
type AvailableMetadata = Readonly < {
20
21
user : User ;
21
22
experiments : Experiments ;
22
- appearanceConfig : AppearanceConfig ;
23
- buildInfo : BuildInfoResponse ;
23
+ appearance : AppearanceConfig ;
24
24
entitlements : Entitlements ;
25
+ "build-info" : BuildInfoResponse ;
25
26
} > ;
26
27
27
28
type MetadataKey = keyof AvailableMetadata ;
@@ -71,10 +72,10 @@ export class MetadataManager implements MetadataManagerApi {
71
72
72
73
this . metadata = {
73
74
user : this . registerValue < User > ( "user" ) ,
74
- appearanceConfig : this . registerValue < AppearanceConfig > ( "appearance" ) ,
75
- buildInfo : this . registerValue < BuildInfoResponse > ( "build-info" ) ,
75
+ appearance : this . registerValue < AppearanceConfig > ( "appearance" ) ,
76
76
entitlements : this . registerValue < Entitlements > ( "entitlements" ) ,
77
77
experiments : this . registerValue < Experiments > ( "experiments" ) ,
78
+ "build-info" : this . registerValue < BuildInfoResponse > ( "build-info" ) ,
78
79
} ;
79
80
}
80
81
@@ -84,9 +85,9 @@ export class MetadataManager implements MetadataManagerApi {
84
85
}
85
86
86
87
private registerValue < T extends MetadataValue > (
87
- propertyName : string ,
88
+ key : MetadataKey ,
88
89
) : MetadataState < T > {
89
- const { value, node } = this . parseJson < T > ( propertyName ) ;
90
+ const { value, node } = this . parseJson < T > ( key ) ;
90
91
91
92
let newEntry : MetadataState < T > ;
92
93
if ( ! node || value === undefined ) {
@@ -101,7 +102,7 @@ export class MetadataManager implements MetadataManagerApi {
101
102
} ;
102
103
}
103
104
104
- this . trackedMetadataNodes . set ( propertyName , node ) ;
105
+ this . trackedMetadataNodes . set ( key , node ) ;
105
106
return newEntry ;
106
107
}
107
108
0 commit comments