UNPKG

wikibase-edit

Version:

Edit Wikibase from NodeJS

31 lines 1.05 kB
import { buildSnak, buildReferenceFactory } from '../claim/snak.js'; import { validateGuid, validateHash, validatePropertyId, validateSnakValue } from '../validate.js'; export function setReference(params, properties, instance) { const { guid, property, value, hash } = params; const inputSnaks = params.snaks; let snaks; if (inputSnaks) { snaks = buildReferenceFactory(properties, instance)(inputSnaks).snaks; } else { // Legacy interface validateGuid(guid); validatePropertyId(property); const datatype = properties[property]; // @ts-expect-error validateSnakValue(property, datatype, value); snaks = {}; // @ts-expect-error snaks[property] = [buildSnak(property, datatype, value, instance)]; } const data = { statement: guid, snaks: JSON.stringify(snaks), }; if (hash) { validateHash(hash); data.reference = hash; } return { action: 'wbsetreference', data }; } //# sourceMappingURL=set.js.map