|
1 | | -import { restrictToSchema, optional, required, Rule } from 'rulr'; |
| 1 | +import { composeRules, restrictToSchema, optional, required, Rule } from 'rulr'; |
| 2 | +import { isPlainObject } from 'lodash'; |
2 | 3 | import { iri, languageMap, imt, integerValue, stringValue } from '../factory'; |
| 4 | +import SignedContentTypeWarning from '../warnings/SignedContentTypeWarning'; |
3 | 5 |
|
4 | | -export default restrictToSchema({ |
5 | | - usageType: required(iri), |
6 | | - display: required(languageMap), |
7 | | - description: optional(languageMap), |
8 | | - contentType: required(imt), |
9 | | - length: required(integerValue), |
10 | | - sha2: required(stringValue), |
11 | | - fileUrl: optional(iri), |
12 | | -}) as Rule; |
| 6 | +export default composeRules([ |
| 7 | + restrictToSchema({ |
| 8 | + usageType: required(iri), |
| 9 | + display: required(languageMap), |
| 10 | + description: optional(languageMap), |
| 11 | + contentType: required(imt), |
| 12 | + length: required(integerValue), |
| 13 | + sha2: required(stringValue), |
| 14 | + fileUrl: optional(iri), |
| 15 | + }), |
| 16 | + (data, path) => { |
| 17 | + if (!isPlainObject(data)) return []; |
| 18 | + if ( |
| 19 | + data.usageType === 'http://adlnet.gov/expapi/attachments/signature' && |
| 20 | + data.contentType !== 'application/octet-stream' |
| 21 | + ) { |
| 22 | + return [new SignedContentTypeWarning(data, path, data.contentType)]; |
| 23 | + } |
| 24 | + return []; |
| 25 | + } |
| 26 | +]) as Rule; |
0 commit comments