1+ import { assertType } from '../../../utils/type-utils' ;
12import type { AttachmentProcessorExtractedProp } from '../../../database/attachment-processor-props' ;
23import { ENTITY_TYPE_INTERNAL_FILE } from '../../../schema/internalObject' ;
34import { schemaAttributesDefinition } from '../../../schema/schema-attributes' ;
@@ -12,47 +13,12 @@ import {
1213 refreshedAt ,
1314 standardId ,
1415 updatedAt ,
15- type MappingDefinition ,
16- type BasicStoreAttribute ,
1716} from '../../../schema/attribute-definition' ;
1817import { ENTITY_TYPE_MARKING_DEFINITION } from '../../../schema/stixMetaObject' ;
1918import { ABSTRACT_STIX_CORE_OBJECT } from '../../../schema/general' ;
2019import { UPLOAD_STATUS_VALUES } from './document-domain' ;
2120
22- export const ATTACHMENT_MAPPINGS = [
23- { name : 'author' , label : 'Author' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
24- { name : 'comments' , label : 'Comments' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
25- { name : 'content' , label : 'Content' , type : 'string' , format : 'text' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
26- { name : 'content_length' , label : 'Content length' , type : 'numeric' , precision : 'integer' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
27- { name : 'content_type' , label : 'Content type' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
28- { name : 'creator_tool' , label : 'Creator tool' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
29- { name : 'date' , label : 'Created date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
30- { name : 'description' , label : 'Description' , type : 'string' , format : 'text' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
31- { name : 'format' , label : 'Format' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
32- { name : 'keywords' , label : 'Keywords' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
33- { name : 'language' , label : 'Language' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
34- { name : 'metadata_date' , label : 'Metadata date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
35- { name : 'modified' , label : 'Modified date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
36- { name : 'modifier' , label : 'Modifier' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
37- { name : 'print_date' , label : 'Print date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
38- { name : 'title' , label : 'Title' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
39- ] satisfies ( {
40- name : AttachmentProcessorExtractedProp ;
41- } & MappingDefinition < BasicStoreAttribute > ) [ ] ;
42-
43- // Compile-time shenanigans to make sure we don't forget to update
44- // ATTACHMENT_MAPPINGS when/if we start extracting new fields
45- // via the ES/OS attachment ingest pipeline.
46- type AttachmentMappingsWithCheck = Exclude <
47- AttachmentProcessorExtractedProp ,
48- typeof ATTACHMENT_MAPPINGS [ number ] [ 'name' ]
49- > extends never
50- ? MappingDefinition < BasicStoreAttribute > [ ]
51- : 'Make sure ATTACHMENT_MAPPINGS defines one mapping for each AttachmentProcessorExtractedProp' ;
52-
53- const TYPE_CHECKED_ATTACHMENT_MAPPINGS : AttachmentMappingsWithCheck = ATTACHMENT_MAPPINGS ;
54-
55- const attributes : Array < AttributeDefinition > = [
21+ const attributes = [
5622 id ,
5723 internalId ,
5824 standardId ,
@@ -117,12 +83,40 @@ const attributes: Array<AttributeDefinition> = [
11783 multiple : false ,
11884 upsert : false ,
11985 isFilterable : false ,
120- mappings : TYPE_CHECKED_ATTACHMENT_MAPPINGS ,
86+ mappings : [
87+ { name : 'author' , label : 'Author' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
88+ { name : 'comments' , label : 'Comments' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
89+ { name : 'content' , label : 'Content' , type : 'string' , format : 'text' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
90+ { name : 'content_length' , label : 'Content length' , type : 'numeric' , precision : 'integer' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
91+ { name : 'content_type' , label : 'Content type' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
92+ { name : 'creator_tool' , label : 'Creator tool' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
93+ { name : 'date' , label : 'Created date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
94+ { name : 'description' , label : 'Description' , type : 'string' , format : 'text' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
95+ { name : 'format' , label : 'Format' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
96+ { name : 'keywords' , label : 'Keywords' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
97+ { name : 'language' , label : 'Language' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
98+ { name : 'metadata_date' , label : 'Metadata date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
99+ { name : 'modified' , label : 'Modified date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
100+ { name : 'modifier' , label : 'Modifier' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
101+ { name : 'print_date' , label : 'Print date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
102+ { name : 'title' , label : 'Title' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : true } ,
103+ ] ,
121104 } ,
122105 { name : 'uploaded_at' , label : 'Upload date' , type : 'date' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : false } ,
123106 { name : 'file_id' , label : 'File identifier' , type : 'string' , format : 'short' , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : false } ,
124107 { name : 'entity_id' , label : 'Related entity' , type : 'string' , format : 'id' , entityTypes : [ ABSTRACT_STIX_CORE_OBJECT ] , mandatoryType : 'internal' , editDefault : false , multiple : false , upsert : false , isFilterable : false } ,
125108 { name : 'removed' , label : 'Removed' , type : 'boolean' , mandatoryType : 'no' , editDefault : false , multiple : false , upsert : false , isFilterable : false } ,
126- ] ;
109+ ] as const satisfies Array < AttributeDefinition > ;
110+
111+ const attachmentAttributes = attributes [ 18 ] ;
112+
113+ type AttachmentAttributeMappingNames = typeof attachmentAttributes . mappings [ number ] [ 'name' ] [ ] ;
114+
115+ // Make sure there's an attachment mapping for each field extracted
116+ // by the `attachment` ingest processor, exhaustively.
117+ assertType <
118+ AttachmentAttributeMappingNames ,
119+ AttachmentProcessorExtractedProp [ ]
120+ > ( attachmentAttributes . mappings . map ( ( { name } ) => name ) ) ;
127121
128122schemaAttributesDefinition . registerAttributes ( ENTITY_TYPE_INTERNAL_FILE , attributes ) ;
0 commit comments