wikibase-sdk
Advanced tools
Comparing version 7.0.9 to 7.0.10
@@ -34,2 +34,3 @@ const { simplifyClaims } = require('./simplify_claims') | ||
const simplifyEntities = (entities, options = {}) => { | ||
if (entities.entities) entities = entities.entities | ||
const { entityPrefix } = options | ||
@@ -36,0 +37,0 @@ return Object.keys(entities).reduce((obj, key) => { |
const { isPlainObject, forceArray, shortLang } = require('../utils/utils') | ||
const validate = require('../helpers/validate') | ||
@@ -17,2 +18,4 @@ module.exports = buildUrl => (ids, languages, props, format, redirects) => { | ||
ids.forEach(validate.entityId) | ||
if (ids.length > 50) { | ||
@@ -19,0 +22,0 @@ console.warn(`getEntities accepts 50 ids max to match Wikidata API limitations: |
@@ -1,2 +0,2 @@ | ||
const { isEntityId, isRevisionId } = require('../helpers/helpers') | ||
const validate = require('../helpers/validate') | ||
const { isPlainObject } = require('../utils/utils') | ||
@@ -9,5 +9,5 @@ | ||
} | ||
if (!isEntityId(id)) throw new Error(`invalid entity id: ${id}`) | ||
if (!isRevisionId(revision)) throw new Error(`invalid revision id: ${revision}`) | ||
validate.entityId(id) | ||
validate.revisionId(revision) | ||
return `${instance}/w/index.php?title=Special:EntityData/${id}.json&oldid=${revision}` | ||
} |
@@ -1,2 +0,5 @@ | ||
const helpers = require('../helpers/helpers') | ||
const { forceArray } = require('../utils/utils') | ||
const { isItemId } = require('../helpers/helpers') | ||
const validate = require('../helpers/validate') | ||
// Fiter-out properties. Can't be filtered by | ||
@@ -15,9 +18,7 @@ // `?subject a wikibase:Item`, as those triples are omitted | ||
// Allow to request values for several properties at once | ||
if (property instanceof Array) { | ||
property = property.map(prefixifyProperty).join('|') | ||
} else { | ||
property = prefixifyProperty(property) | ||
} | ||
var properties = forceArray(property) | ||
properties.forEach(validate.propertyId) | ||
properties = properties.map(prefixifyProperty).join('|') | ||
const valueBlock = getValueBlock(value, valueFn, property, filter) | ||
const valueBlock = getValueBlock(value, valueFn, properties, filter) | ||
var sparql = `SELECT DISTINCT ?subject WHERE { ${valueBlock} }` | ||
@@ -29,5 +30,5 @@ if (limit) sparql += ` LIMIT ${limit}` | ||
const getValueBlock = (value, valueFn, property, filter) => { | ||
const getValueBlock = (value, valueFn, properties, filter) => { | ||
if (!(value instanceof Array)) { | ||
return valueFn(property, getValueString(value), filter) | ||
return valueFn(properties, getValueString(value), filter) | ||
} | ||
@@ -37,3 +38,3 @@ | ||
.map(getValueString) | ||
.map(valStr => valueFn(property, valStr, filter)) | ||
.map(valStr => valueFn(properties, valStr, filter)) | ||
@@ -44,3 +45,3 @@ return '{ ' + valuesBlocks.join('} UNION {') + ' }' | ||
const getValueString = value => { | ||
if (helpers.isItemId(value)) { | ||
if (isItemId(value)) { | ||
value = `wd:${value}` | ||
@@ -53,4 +54,4 @@ } else if (typeof value === 'string') { | ||
const directValueQuery = (property, value, filter, limit) => { | ||
return `?subject ${property} ${value} . | ||
const directValueQuery = (properties, value, filter, limit) => { | ||
return `?subject ${properties} ${value} . | ||
${filter}` | ||
@@ -61,4 +62,4 @@ } | ||
// http://stackoverflow.com/q/43073266/3324977 | ||
const caseInsensitiveValueQuery = (property, value, filter, limit) => { | ||
return `?subject ${property} ?value . | ||
const caseInsensitiveValueQuery = (properties, value, filter, limit) => { | ||
return `?subject ${properties} ?value . | ||
FILTER (lcase(?value) = ${value.toLowerCase()}) | ||
@@ -65,0 +66,0 @@ ${filter}` |
const { forceArray } = require('../utils/utils') | ||
const validate = require('../helpers/validate') | ||
module.exports = buildUrl => (ids, options = {}) => { | ||
ids = forceArray(ids) | ||
ids.forEach(validate.entityId) | ||
const uniqueId = ids.length === 1 | ||
@@ -6,0 +9,0 @@ const query = { |
{ | ||
"name": "wikibase-sdk", | ||
"version": "7.0.9", | ||
"version": "7.0.10", | ||
"description": "A javascript tool-suite to query wikibase and simplify its results", | ||
@@ -5,0 +5,0 @@ "main": "lib/wikibase-sdk.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62538
30
992