@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
53 lines (50 loc) • 1.72 kB
TypeScript
import { z } from 'zod';
/**
* Schema for validating granular marking objects.
*
* Granular markings allow applying different data markings to specific portions of
* an object, providing fine-grained control over data classification and handling.
*
* **Validation Rules:**
* - Exactly one of `lang` or `marking_ref` must be present (mutually exclusive)
* - If `lang` is present, `marking_ref` must NOT be present
* - If `marking_ref` is present, `lang` must NOT be present
* - `selectors` is always required
*
* @example
* ```typescript
* // Valid: marking_ref without lang
* granularMarkingSchema.parse({
* marking_ref: 'marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da',
* selectors: ['description', 'x_mitre_detection']
* });
*
* // Valid: lang without marking_ref
* granularMarkingSchema.parse({
* lang: 'en',
* selectors: ['name']
* });
*
* // Invalid: both lang and marking_ref present
* granularMarkingSchema.parse({
* lang: 'en',
* marking_ref: 'marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da',
* selectors: ['description']
* }); // Error: lang and marking_ref are mutually exclusive
*
* // Invalid: neither lang nor marking_ref present
* granularMarkingSchema.parse({
* selectors: ['description']
* }); // Error: one of lang or marking_ref must be present
* ```
*/
declare const granularMarkingSchema: z.ZodObject<{
lang: z.ZodOptional<z.ZodString>;
marking_ref: z.ZodOptional<z.ZodString>;
selectors: z.ZodArray<z.ZodString>;
}, z.core.$strip>;
/**
* Type representing a granular marking object.
*/
type GranularMarking = z.infer<typeof granularMarkingSchema>;
export { type GranularMarking, granularMarkingSchema };