@kravc/schema 2.7.6 → 2.8.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -14
- package/dist/CredentialFactory.d.ts +345 -0
- package/dist/CredentialFactory.d.ts.map +1 -0
- package/dist/CredentialFactory.js +381 -0
- package/dist/CredentialFactory.js.map +1 -0
- package/dist/Schema.d.ts +448 -0
- package/dist/Schema.d.ts.map +1 -0
- package/dist/Schema.js +506 -0
- package/dist/Schema.js.map +1 -0
- package/dist/ValidationError.d.ts +70 -0
- package/dist/ValidationError.d.ts.map +1 -0
- package/dist/ValidationError.js +78 -0
- package/dist/ValidationError.js.map +1 -0
- package/dist/Validator.d.ts +483 -0
- package/dist/Validator.d.ts.map +1 -0
- package/dist/Validator.js +570 -0
- package/dist/Validator.js.map +1 -0
- package/dist/helpers/JsonSchema.d.ts +99 -0
- package/dist/helpers/JsonSchema.d.ts.map +1 -0
- package/dist/helpers/JsonSchema.js +3 -0
- package/dist/helpers/JsonSchema.js.map +1 -0
- package/dist/helpers/cleanupAttributes.d.ts +34 -0
- package/dist/helpers/cleanupAttributes.d.ts.map +1 -0
- package/dist/helpers/cleanupAttributes.js +113 -0
- package/dist/helpers/cleanupAttributes.js.map +1 -0
- package/dist/helpers/cleanupNulls.d.ts +27 -0
- package/dist/helpers/cleanupNulls.d.ts.map +1 -0
- package/dist/helpers/cleanupNulls.js +96 -0
- package/dist/helpers/cleanupNulls.js.map +1 -0
- package/dist/helpers/createSchemasMap.d.ts +67 -0
- package/dist/helpers/createSchemasMap.d.ts.map +1 -0
- package/dist/helpers/createSchemasMap.js +200 -0
- package/dist/helpers/createSchemasMap.js.map +1 -0
- package/dist/helpers/getReferenceIds.d.ts +169 -0
- package/dist/helpers/getReferenceIds.d.ts.map +1 -0
- package/dist/helpers/getReferenceIds.js +241 -0
- package/dist/helpers/getReferenceIds.js.map +1 -0
- package/dist/helpers/got.d.ts +60 -0
- package/dist/helpers/got.d.ts.map +1 -0
- package/dist/helpers/got.js +72 -0
- package/dist/helpers/got.js.map +1 -0
- package/dist/helpers/mapObjectProperties.d.ts +150 -0
- package/dist/helpers/mapObjectProperties.d.ts.map +1 -0
- package/dist/helpers/mapObjectProperties.js +229 -0
- package/dist/helpers/mapObjectProperties.js.map +1 -0
- package/dist/helpers/normalizeAttributes.d.ts +213 -0
- package/dist/helpers/normalizeAttributes.d.ts.map +1 -0
- package/dist/helpers/normalizeAttributes.js +243 -0
- package/dist/helpers/normalizeAttributes.js.map +1 -0
- package/dist/helpers/normalizeProperties.d.ts +168 -0
- package/dist/helpers/normalizeProperties.d.ts.map +1 -0
- package/dist/helpers/normalizeProperties.js +223 -0
- package/dist/helpers/normalizeProperties.js.map +1 -0
- package/dist/helpers/normalizeRequired.d.ts +159 -0
- package/dist/helpers/normalizeRequired.d.ts.map +1 -0
- package/dist/helpers/normalizeRequired.js +206 -0
- package/dist/helpers/normalizeRequired.js.map +1 -0
- package/dist/helpers/normalizeType.d.ts +81 -0
- package/dist/helpers/normalizeType.d.ts.map +1 -0
- package/dist/helpers/normalizeType.js +210 -0
- package/dist/helpers/normalizeType.js.map +1 -0
- package/dist/helpers/nullifyEmptyValues.d.ts +139 -0
- package/dist/helpers/nullifyEmptyValues.d.ts.map +1 -0
- package/dist/helpers/nullifyEmptyValues.js +191 -0
- package/dist/helpers/nullifyEmptyValues.js.map +1 -0
- package/dist/helpers/removeRequiredAndDefault.d.ts +106 -0
- package/dist/helpers/removeRequiredAndDefault.d.ts.map +1 -0
- package/dist/helpers/removeRequiredAndDefault.js +138 -0
- package/dist/helpers/removeRequiredAndDefault.js.map +1 -0
- package/dist/helpers/validateId.d.ts +39 -0
- package/dist/helpers/validateId.d.ts.map +1 -0
- package/dist/helpers/validateId.js +51 -0
- package/dist/helpers/validateId.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/ld/documentLoader.d.ts +8 -0
- package/dist/ld/documentLoader.d.ts.map +1 -0
- package/dist/ld/documentLoader.js +24 -0
- package/dist/ld/documentLoader.js.map +1 -0
- package/dist/ld/getLinkedDataAttributeType.d.ts +10 -0
- package/dist/ld/getLinkedDataAttributeType.d.ts.map +1 -0
- package/dist/ld/getLinkedDataAttributeType.js +32 -0
- package/dist/ld/getLinkedDataAttributeType.js.map +1 -0
- package/dist/ld/getLinkedDataContext.d.ts +19 -0
- package/dist/ld/getLinkedDataContext.d.ts.map +1 -0
- package/dist/ld/getLinkedDataContext.js +50 -0
- package/dist/ld/getLinkedDataContext.js.map +1 -0
- package/eslint.config.mjs +32 -52
- package/examples/credentials/createAccountCredential.ts +27 -0
- package/examples/credentials/createMineSweeperScoreCredential.ts +115 -0
- package/examples/index.ts +7 -0
- package/examples/schemas/FavoriteItemSchema.ts +27 -0
- package/examples/{Preferences.yaml → schemas/Preferences.yaml} +2 -0
- package/examples/schemas/PreferencesSchema.ts +29 -0
- package/examples/schemas/ProfileSchema.ts +91 -0
- package/examples/schemas/Status.yaml +3 -0
- package/examples/schemas/StatusSchema.ts +12 -0
- package/jest.config.mjs +5 -0
- package/package.json +27 -20
- package/src/CredentialFactory.ts +392 -0
- package/src/Schema.ts +583 -0
- package/src/ValidationError.ts +90 -0
- package/src/Validator.ts +603 -0
- package/src/__tests__/CredentialFactory.test.ts +588 -0
- package/src/__tests__/Schema.test.ts +371 -0
- package/src/__tests__/ValidationError.test.ts +235 -0
- package/src/__tests__/Validator.test.ts +787 -0
- package/src/helpers/JsonSchema.ts +119 -0
- package/src/helpers/__tests__/cleanupAttributes.test.ts +943 -0
- package/src/helpers/__tests__/cleanupNulls.test.ts +772 -0
- package/src/helpers/__tests__/createSchemasMap.test.ts +238 -0
- package/src/helpers/__tests__/getReferenceIds.test.ts +975 -0
- package/src/helpers/__tests__/got.test.ts +193 -0
- package/src/helpers/__tests__/mapObjectProperties.test.ts +1126 -0
- package/src/helpers/__tests__/normalizeAttributes.test.ts +1435 -0
- package/src/helpers/__tests__/normalizeProperties.test.ts +727 -0
- package/src/helpers/__tests__/normalizeRequired.test.ts +669 -0
- package/src/helpers/__tests__/normalizeType.test.ts +772 -0
- package/src/helpers/__tests__/nullifyEmptyValues.test.ts +735 -0
- package/src/helpers/__tests__/removeRequiredAndDefault.test.ts +734 -0
- package/src/helpers/__tests__/validateId.test.ts +118 -0
- package/src/helpers/cleanupAttributes.ts +151 -0
- package/src/helpers/cleanupNulls.ts +106 -0
- package/src/helpers/createSchemasMap.ts +212 -0
- package/src/helpers/getReferenceIds.ts +273 -0
- package/src/helpers/got.ts +73 -0
- package/src/helpers/mapObjectProperties.ts +272 -0
- package/src/helpers/normalizeAttributes.ts +247 -0
- package/src/helpers/normalizeProperties.ts +249 -0
- package/src/helpers/normalizeRequired.ts +233 -0
- package/src/helpers/normalizeType.ts +235 -0
- package/src/helpers/nullifyEmptyValues.ts +207 -0
- package/src/helpers/removeRequiredAndDefault.ts +151 -0
- package/src/helpers/validateId.ts +53 -0
- package/src/index.ts +17 -0
- package/src/ld/__tests__/documentLoader.test.ts +57 -0
- package/src/ld/__tests__/getLinkedDataAttributeType.test.ts +212 -0
- package/src/ld/__tests__/getLinkedDataContext.test.ts +378 -0
- package/src/ld/documentLoader.ts +28 -0
- package/src/ld/getLinkedDataAttributeType.ts +46 -0
- package/src/ld/getLinkedDataContext.ts +80 -0
- package/tsconfig.json +27 -0
- package/types/credentials-context.d.ts +14 -0
- package/types/security-context.d.ts +6 -0
- package/examples/Status.yaml +0 -3
- package/examples/createAccountCredential.js +0 -27
- package/examples/createMineSweeperScoreCredential.js +0 -63
- package/examples/index.js +0 -9
- package/src/CredentialFactory.js +0 -67
- package/src/CredentialFactory.spec.js +0 -131
- package/src/Schema.js +0 -104
- package/src/Schema.spec.js +0 -172
- package/src/ValidationError.js +0 -31
- package/src/Validator.js +0 -128
- package/src/Validator.spec.js +0 -355
- package/src/helpers/cleanupAttributes.js +0 -71
- package/src/helpers/cleanupNulls.js +0 -42
- package/src/helpers/getReferenceIds.js +0 -71
- package/src/helpers/mapObject.js +0 -65
- package/src/helpers/normalizeAttributes.js +0 -28
- package/src/helpers/normalizeProperties.js +0 -61
- package/src/helpers/normalizeRequired.js +0 -37
- package/src/helpers/normalizeType.js +0 -41
- package/src/helpers/nullifyEmptyValues.js +0 -57
- package/src/helpers/removeRequiredAndDefault.js +0 -30
- package/src/helpers/validateId.js +0 -19
- package/src/index.d.ts +0 -25
- package/src/index.js +0 -8
- package/src/ld/documentLoader.js +0 -25
- package/src/ld/documentLoader.spec.js +0 -12
- package/src/ld/getLinkedDataContext.js +0 -63
- package/src/ld/getLinkedDataType.js +0 -38
- /package/examples/{FavoriteItem.yaml → schemas/FavoriteItem.yaml} +0 -0
- /package/examples/{Profile.yaml → schemas/Profile.yaml} +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const normalizeRequired = jsonSchema => {
|
|
4
|
-
const { properties } = jsonSchema
|
|
5
|
-
|
|
6
|
-
if (!properties) { return }
|
|
7
|
-
|
|
8
|
-
const required = []
|
|
9
|
-
for (const name in properties) {
|
|
10
|
-
const property = properties[name]
|
|
11
|
-
|
|
12
|
-
if (property.required) {
|
|
13
|
-
property['x-required'] = true
|
|
14
|
-
required.push(name)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
delete properties[name].required
|
|
18
|
-
|
|
19
|
-
const isObject = property.type === 'object'
|
|
20
|
-
const isArray = property.type === 'array'
|
|
21
|
-
|
|
22
|
-
if (isObject) {
|
|
23
|
-
normalizeRequired(property)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isArray) {
|
|
27
|
-
const { items: itemJsonSchema } = property
|
|
28
|
-
normalizeRequired(itemJsonSchema)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (required.length > 0) {
|
|
33
|
-
jsonSchema.required = required
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = normalizeRequired
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const BOOLEAN_STRING_TRUE_VALUES = ['yes', 'true', '1']
|
|
4
|
-
const BOOLEAN_STRING_FALSE_VALUES = ['no', 'false', '0']
|
|
5
|
-
|
|
6
|
-
const normalizeType = (type, value) => {
|
|
7
|
-
let normalizedValue = value
|
|
8
|
-
|
|
9
|
-
const isNumber = type === 'integer' || type === 'number'
|
|
10
|
-
const isBoolean = type === 'boolean'
|
|
11
|
-
|
|
12
|
-
if (isNumber) {
|
|
13
|
-
normalizedValue = Number(value) || value
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (isBoolean) {
|
|
17
|
-
const isNumberValue = typeof value === 'number'
|
|
18
|
-
const isStringValue = typeof value === 'string'
|
|
19
|
-
|
|
20
|
-
const shouldConvertValue = isNumberValue || isStringValue
|
|
21
|
-
|
|
22
|
-
if (shouldConvertValue) {
|
|
23
|
-
if (isNumberValue) {
|
|
24
|
-
normalizedValue = Boolean(value)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isStringValue) {
|
|
28
|
-
const isTrue = BOOLEAN_STRING_TRUE_VALUES.includes(value.toLowerCase())
|
|
29
|
-
const isFalse = BOOLEAN_STRING_FALSE_VALUES.includes(value.toLowerCase())
|
|
30
|
-
|
|
31
|
-
if (isTrue || isFalse) {
|
|
32
|
-
normalizedValue = isTrue ? true : false
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return normalizedValue
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = normalizeType
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { get, set } = require('lodash')
|
|
4
|
-
const { schemaSymbol, jsonSymbol } = require('z-schema')
|
|
5
|
-
|
|
6
|
-
const FORMAT_ERROR_CODES = [
|
|
7
|
-
'PATTERN',
|
|
8
|
-
'ENUM_MISMATCH',
|
|
9
|
-
'INVALID_FORMAT'
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
const EMPTY_VALUES = [
|
|
13
|
-
'',
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
const nullifyEmptyValues = (object, validationErrors) => {
|
|
17
|
-
const objectJson = JSON.stringify(object)
|
|
18
|
-
const result = JSON.parse(objectJson)
|
|
19
|
-
|
|
20
|
-
const otherValidationErrors = []
|
|
21
|
-
|
|
22
|
-
for (const error of validationErrors) {
|
|
23
|
-
const { code } = error
|
|
24
|
-
|
|
25
|
-
const isAttributeRequired = error[schemaSymbol]['x-required'] === true
|
|
26
|
-
const isFormatError = FORMAT_ERROR_CODES.includes(code)
|
|
27
|
-
|
|
28
|
-
if (isAttributeRequired) {
|
|
29
|
-
otherValidationErrors.push(error)
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!isFormatError) {
|
|
34
|
-
otherValidationErrors.push(error)
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const { path: pathString } = error
|
|
39
|
-
const path = pathString.replace('#/', '').split('/')
|
|
40
|
-
|
|
41
|
-
const json = error[jsonSymbol]
|
|
42
|
-
const value = get(json, path)
|
|
43
|
-
|
|
44
|
-
const isEmptyValue = EMPTY_VALUES.includes(value)
|
|
45
|
-
|
|
46
|
-
if (!isEmptyValue) {
|
|
47
|
-
otherValidationErrors.push(error)
|
|
48
|
-
continue
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
set(result, path, null)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return [ result, otherValidationErrors ]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = nullifyEmptyValues
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const removeRequiredAndDefault = jsonSchema => {
|
|
4
|
-
const { properties } = jsonSchema
|
|
5
|
-
|
|
6
|
-
if (!properties) { return }
|
|
7
|
-
|
|
8
|
-
for (const name in properties) {
|
|
9
|
-
const property = properties[name]
|
|
10
|
-
|
|
11
|
-
delete property.required
|
|
12
|
-
delete property.default
|
|
13
|
-
|
|
14
|
-
const isObject = property.type === 'object'
|
|
15
|
-
const isArray = property.type === 'array'
|
|
16
|
-
|
|
17
|
-
if (isObject) {
|
|
18
|
-
removeRequiredAndDefault(property)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (isArray) {
|
|
22
|
-
const { items: itemsJsonSchema } = property
|
|
23
|
-
removeRequiredAndDefault(itemsJsonSchema)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return { properties }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = removeRequiredAndDefault
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { isURL } = require('validator')
|
|
4
|
-
|
|
5
|
-
const validateId = (name, value) => {
|
|
6
|
-
if (!value) {
|
|
7
|
-
throw new Error(`Parameter "${name}" is required`)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const isURI = value.toLowerCase().startsWith('did:') || isURL(value)
|
|
11
|
-
|
|
12
|
-
if (isURI) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
throw new Error(`Parameter "${name}" must be a URL, received: "${value}"`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = validateId
|
package/src/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
declare type SchemaAttribute = object;
|
|
2
|
-
export declare type SchemaAttributes = Record<string, SchemaAttribute>;
|
|
3
|
-
declare type Enum = { enum: string[] };
|
|
4
|
-
declare type Source = Enum | SchemaAttributes;
|
|
5
|
-
|
|
6
|
-
export declare class Schema {
|
|
7
|
-
constructor(
|
|
8
|
-
source: Source,
|
|
9
|
-
id: string,
|
|
10
|
-
url?: string
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
get id(): string;
|
|
14
|
-
get source(): Source;
|
|
15
|
-
|
|
16
|
-
only(propertyNames: string[], id?: string): Schema;
|
|
17
|
-
wrap(propertyName: string, options?: Record<string, any>, id?: string): Schema;
|
|
18
|
-
extend(properties: Record<string, any>, id?: string): Schema;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export declare class Validator {
|
|
22
|
-
constructor(
|
|
23
|
-
schemas: Schema[]
|
|
24
|
-
)
|
|
25
|
-
}
|
package/src/index.js
DELETED
package/src/ld/documentLoader.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { contexts: securityContextsMap } = require('security-context')
|
|
4
|
-
const { contexts: credentialsContextsMap } = require('credentials-context')
|
|
5
|
-
|
|
6
|
-
const CONTEXTS = new Map([ ...securityContextsMap, ...credentialsContextsMap ])
|
|
7
|
-
|
|
8
|
-
const documentLoader = documentUrl => {
|
|
9
|
-
const contextUrl = null
|
|
10
|
-
const [ url ] = documentUrl.split('#')
|
|
11
|
-
|
|
12
|
-
const document = CONTEXTS.get(url)
|
|
13
|
-
|
|
14
|
-
if (!document) {
|
|
15
|
-
throw new Error(`Custom context "${documentUrl}" is not supported`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
document,
|
|
20
|
-
contextUrl,
|
|
21
|
-
documentUrl
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = documentLoader
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai')
|
|
4
|
-
const documentLoader = require('./documentLoader')
|
|
5
|
-
|
|
6
|
-
describe('documentLoader(documentUrl)', () => {
|
|
7
|
-
it('throws error if context not found', () => {
|
|
8
|
-
expect(
|
|
9
|
-
() => documentLoader('https://example.com')
|
|
10
|
-
).to.throw('Custom context "https://example.com')
|
|
11
|
-
})
|
|
12
|
-
})
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const getLinkedDataType = require('./getLinkedDataType')
|
|
4
|
-
|
|
5
|
-
const SCHEMA_ORG_URI = 'https://schema.org/'
|
|
6
|
-
|
|
7
|
-
const PROTECTED_PROPERTIES = [
|
|
8
|
-
'id',
|
|
9
|
-
'type',
|
|
10
|
-
'schema'
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
// TODO: Add support for embedded object, array and enum.
|
|
14
|
-
const getLinkedDataContext = (properties, vocabUri) => {
|
|
15
|
-
const context = {}
|
|
16
|
-
|
|
17
|
-
for (const key in properties) {
|
|
18
|
-
const schema = properties[key]
|
|
19
|
-
|
|
20
|
-
const isProtected = PROTECTED_PROPERTIES.includes(key) || key.startsWith('@')
|
|
21
|
-
|
|
22
|
-
if (isProtected) {
|
|
23
|
-
continue
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const { $ref } = schema
|
|
27
|
-
|
|
28
|
-
if ($ref) {
|
|
29
|
-
context[key] = { '@id': key }
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
context[key] = { '@id': key }
|
|
34
|
-
|
|
35
|
-
const linkedDataType = getLinkedDataType(schema)
|
|
36
|
-
|
|
37
|
-
if (linkedDataType) {
|
|
38
|
-
context[key]['@type'] = linkedDataType
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const vocab =
|
|
43
|
-
vocabUri.endsWith('/') || vocabUri.endsWith('#') ? vocabUri : `${vocabUri}#`
|
|
44
|
-
|
|
45
|
-
const contextHeader = {
|
|
46
|
-
'@vocab': vocab,
|
|
47
|
-
'@version': 1.1,
|
|
48
|
-
'@protected': true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const isSchemaOrgDomain = vocab === SCHEMA_ORG_URI
|
|
52
|
-
|
|
53
|
-
if (!isSchemaOrgDomain) {
|
|
54
|
-
contextHeader.schema = SCHEMA_ORG_URI
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
...contextHeader,
|
|
59
|
-
...context
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = getLinkedDataContext
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// TODO: Add support for all types and formats, extend schema library with
|
|
4
|
-
// support for additional formats, e.g. URL, Duration etc.
|
|
5
|
-
const getLinkedDataType = schema => {
|
|
6
|
-
const isOverriden = !!schema['@type']
|
|
7
|
-
|
|
8
|
-
if (isOverriden) {
|
|
9
|
-
return schema['@type']
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { type, format } = schema
|
|
13
|
-
|
|
14
|
-
const isDate = format === 'date'
|
|
15
|
-
const isNumber = type === 'number'
|
|
16
|
-
const isInteger = type === 'integer'
|
|
17
|
-
const isDateTime = format === 'date-time'
|
|
18
|
-
|
|
19
|
-
if (isInteger) {
|
|
20
|
-
return 'schema:Integer'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (isNumber) {
|
|
24
|
-
return 'schema:Number'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isDate) {
|
|
28
|
-
return 'schema:Date'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (isDateTime) {
|
|
32
|
-
return 'schema:DateTime'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = getLinkedDataType
|
|
File without changes
|
|
File without changes
|