@@ -46,8 +46,22 @@ type ByteRangeMapCollection = z.infer<typeof byteRangeMapCollectionValidator>;
46
46
* Metadata validator.
47
47
*/
48
48
const metadataValidator = z . object ( {
49
+ /**
50
+ * Byte range maps collection for all rulesets.
51
+ */
49
52
byteRangeMapsCollection : byteRangeMapCollectionValidator ,
53
+
54
+ /**
55
+ * Checksums for all rulesets.
56
+ */
50
57
checksums : checksumMapValidator ,
58
+
59
+ /**
60
+ * Additional properties.
61
+ * This field stores any extra information not covered by the other fields.
62
+ * The content of this field is not validated, but it must be JSON serializable.
63
+ * Validation should be performed by users.
64
+ */
51
65
additionalProperties : z . record ( z . unknown ( ) ) ,
52
66
} ) ;
53
67
@@ -66,20 +80,29 @@ const metadataRuleValidator = z.object({
66
80
type Metadata = z . infer < typeof metadataValidator > ;
67
81
68
82
/**
69
- * Metadata rule set.
70
- * Its a special rule set that contains only one rule - metadata rule, that holds metadata for all other rulesets.
83
+ * Represents a specialized metadata ruleset for managing and validating metadata associated
84
+ * with various rulesets.
85
+ *
86
+ * This class handles byte range maps, checksums, and additional properties,
87
+ * providing methods to manipulate and query this metadata.
71
88
*/
72
89
export class MetadataRuleSet {
73
90
private metadataRule : MetadataRule < Metadata > ;
74
91
75
92
/**
76
- * Constructor .
93
+ * Creates an instance of the MetadataRuleSet class .
77
94
*
78
- * @param byteRangeMapsCollection Byte range maps collection. Default is an empty object.
79
- * @param checksums Checksums. Default is an empty object.
80
- * @param additionalProperties Additional properties. Default is an empty object.
95
+ * @param byteRangeMapsCollection A map of byte range maps, where each key corresponds to a ruleset ID
96
+ * and each value is a map of byte ranges for that ruleset. Defaults to an empty object.
97
+ * @param checksums A map of checksums, where each key corresponds to a rule set ID and each value is the checksum
98
+ * for that ruleset. Defaults to an empty object.
99
+ * @param additionalProperties A collection of additional properties, where keys are property names and values are
100
+ * their associated data. These properties are JSON serializable but not validated by the class.
101
+ * Defaults to an empty object.
81
102
*
82
- * @note It takes values by reference. If ever needed, clone them before passing.
103
+ * @note
104
+ * This constructor uses references for the provided arguments. If immutability is required, ensure to clone the
105
+ * inputs before passing them.
83
106
*/
84
107
constructor (
85
108
byteRangeMapsCollection : ByteRangeMapCollection = { } ,
@@ -203,6 +226,26 @@ export class MetadataRuleSet {
203
226
this . metadataRule . metadata . additionalProperties [ key ] = value ;
204
227
}
205
228
229
+ /**
230
+ * Checks whether additional property exists.
231
+ *
232
+ * @param key Property key.
233
+ *
234
+ * @returns Whether the property exists.
235
+ */
236
+ public hasAdditionalProperty ( key : string ) : boolean {
237
+ return key in this . metadataRule . metadata . additionalProperties ;
238
+ }
239
+
240
+ /**
241
+ * Removes additional property.
242
+ *
243
+ * @param key Property key.
244
+ */
245
+ public removeAdditionalProperty ( key : string ) : void {
246
+ delete this . metadataRule . metadata . additionalProperties [ key ] ;
247
+ }
248
+
206
249
/**
207
250
* Serializes the ruleset to a string.
208
251
*
0 commit comments