How to use the wikibase-sdk.simplify.claim function in wikibase-sdk

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 / 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-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 / 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()
        })
      })