Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
subject: value => {
if (isEntityId(value)) {
return `wd:${value}`
} else {
errors_.exit(`invalid subject: ${value}`)
}
},
property: value => {
module.exports = (property, ids) => {
const useWdIdsAsKeys = isEntityId(ids[0])
ids = uniq(ids)
if (ids.length === 0) return output({})
const sparqlBuilder = useWdIdsAsKeys ? fromWdIds : fromExternalIds
const sparqlRequests = chunk(ids, 100).map(sparqlBuilder(property))
const results = initResultsObj(ids)
getResultsSequentially(sparqlRequests, results, useWdIdsAsKeys)
.then(output)
.catch(errors_.exit)
}
module.exports = input => {
const match = input.match(/(Q|P)\d+/)
if (match) {
const id = match[0]
if (isEntityId(id)) return id
}
if (isNumericId(input)) return `Q${input}`
throw errors_.new('invalid id', input)
}
entity: entity => {
if (!isEntityId(entity)) {
throw error_.new('invalid entity', { entity })
}
},
property: property => {
module.exports = data => {
const params = {}
const { id, clear, labels, aliases, descriptions, claims, sitelinks, summary } = data
if (id === 'create') {
params['new'] = 'item'
} else if (isEntityId(id)) {
params.id = id
} else {
throw error_.new('invalid entity id', 400, id)
}
if (_.isNonEmptyString(summary)) params.summary = summary
params.data = {}
if (labels) {
params.data.labels = format.values('label', labels)
}
if (aliases) {
params.data.aliases = format.values('alias', aliases)
}
if (descriptions) {
params.data.descriptions = format.values('description', descriptions)
if (type && type !== 'property' && type !== 'item') {
throw error_.new('invalid entity type', { type })
}
if (create) {
if (type === 'property') {
if (!datatype) throw error_.new('missing property datatype', { datatype })
params.new = 'property'
params.data.datatype = datatype
} else {
if (datatype) {
throw error_.new("an item can't have a datatype", { datatype })
}
params.new = 'item'
}
} else if (isEntityId(id)) {
params.id = id
} else {
throw error_.new('invalid entity id', { id })
}
const { labels, aliases, descriptions, claims, sitelinks, summary } = data
if (_.isNonEmptyString(summary)) params.summary = summary
if (labels) {
params.data.labels = format.values('label', labels)
}
if (aliases) {
params.data.aliases = format.values('alias', aliases)
}
if (descriptions) {
const formatValue = labels => value => {
return isEntityId(value) ? formatEntity(labels[value], value) : value
}
.then(prefixesMap => {
if (!isEntityId(title)) return
const idFirstLetter = title[0]
const prefix = prefixesMap[idFirstLetter]
return prefix === '' ? title : `${prefix}:${title}`
})
}