How to use wikibase-sdk - 10 common examples

To help you get started, we’ve selected a few wikibase-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maxlath / wikibase-edit / lib / datatype_tests.js View on Github external
quantity: amount => {
    var unit
    amount = amount.value || amount
    if (_.isPlainObject(amount)) {
      unit = amount.unit || amount.value.unit
      amount = amount.amount || amount.value.amount
      if (!isItemId(parseUnit(unit)) && unit !== '1') return false
    } else {
      unit = '1'
    }
    // Accepting both numbers or string numbers as the amount will be
    // turned as a string lib/claim/builders.js signAmount function anyway
    return _.isNumber(amount) || _.isStringNumber(amount)
  },
  globecoordinate: obj => {
github maxlath / wikibase-edit / lib / claim / update.js View on Github external
property = claim.mainsnak.property
    } else {
      const datatype = config.properties[property]
      claim = findSnak(property, datatype, claims[property], oldValue)
    }

    if (!claim) {
      throw error_.new('claim not found', 400, { id, property, oldValue, newValue, guid })
    }

    guid = claim.id

    claim.value = newValue

    const data = { id, claims: {} }
    const simplifiedClaim = simplify.claim(claim, simplifyOptions)
    simplifiedClaim.value = newValue
    data.claims[property] = simplifiedClaim

    // Use wbeditentity as the endpoint is more complete
    // Pass the reqConfig to avoid getting into errors of the kind
    // 'credentials should either be passed at initialization or per request'
    // as API.entity.edit is already bound to the generalConfig
    return API.entity.edit(data, reqConfig)
    .then(res => {
      const { entity, success } = res
      const updatedClaim = entity.claims[property].find(isGuidClaim(guid))
      // Mimick claim actions responses
      return { claim: updatedClaim, success }
    })
  })
}
github maxlath / wikibase-cli / lib / format_properties_data.js View on Github external
module.exports = (pattern, filter, includeAllDetails, includeTypes) => data => {
  // Special case: when the pattern is a property id, just log the property
  if (isPropertyId(pattern) && data[pattern] != null) {
    const prop = pattern
    const obj = {}
    obj[prop] = getValue(data[prop], includeAllDetails, includeTypes)
    return JSON.stringify(obj, null, 2)
  }

  const propsData = {}

  for (let prop in data) {
    let propData = data[prop]
    if (!filter || filter(propData)) {
      let value = getValue(data[prop], includeAllDetails, includeTypes)
      propsData[prop] = value
    }
  }
github maxlath / wikibase-edit / lib / claim / find_snak.js View on Github external
const { claim: simplifyClaim } = require('wikibase-sdk').simplify
const _ = require('../utils')
// const findPropertyDataType = require('../properties/find_datatype')
const { parseUnit } = require('./quantity')
const error_ = require('../error')

module.exports = (property, datatype, propSnaks, value) => {
  if (!propSnaks) return

  const matchingSnaks = propSnaks.filter(isMatchingSnak(datatype, value))

  if (matchingSnaks.length === 0) return
  if (matchingSnaks.length === 1) return matchingSnaks[0]

  const context = { property, propSnaks, value }
  throw error_.new('snak not found: too many matching snaks', 400, context)
}
github maxlath / wikibase-edit / test / claim / update.js View on Github external
.then(res2 => {
        res1.claim.id.should.equal(res2.claim.id)
        simplify.claim(res2.claim).split('T')[0].should.equal(newValue)
        done()
      })
    })
github maxlath / wikibase-edit / test / integration / claim / update.js View on Github external
.then(res => {
          res.claim.id.should.equal(guid)
          simplify.claim(res.claim).split('T')[0].should.equal(newValue)
          done()
        })
      })
github maxlath / wikibase-edit / test / claim / exists.js View on Github external
.then(matchingClaimsGuids => {
        matchingClaimsGuids.should.be.an.Array()
        matchingClaimsGuids[0].should.be.an.String()
        should(isItemId(matchingClaimsGuids[0].split('$')[0])).be.true()
        done()
      })
    })
github maxlath / wikibase-edit / test / integration / claim / update.js View on Github external
.then(resB => {
            const simplifiedClaim = simplify.claim(resB.claim, { keepIds: true, keepQualifiers: true, keepReferences: true })
            simplifiedClaim.id.should.equal(guid)
            simplifiedClaim.value.should.equal(newValue)
            simplifiedClaim.qualifiers[property][0].should.equal(qualifierValue)
            simplifiedClaim.references[0][property][0].should.equal(referenceValue)
            done()
          })
        })
github maxlath / wikibase-edit / test / claim / update.js View on Github external
.then(res2 => {
        res1.claim.id.should.equal(res2.claim.id)
        simplify.claim(res2.claim).should.equal(newValue.amount)
        done()
      })
    })
github maxlath / wikibase-edit / test / integration / claim / update.js View on Github external
.then(res => {
          res.claim.id.should.equal(guid)
          simplify.claim(res.claim, { keepRichValues: true }).should.deepEqual(newValue)
          done()
        })
      })