wikibase-edit
Version:
Edit Wikibase from NodeJS
32 lines • 1.2 kB
JavaScript
import { singleClaimBuilders as builders } from '../claim/builders.js';
import { hasSpecialSnaktype } from '../claim/special_snaktype.js';
import { newError } from '../error.js';
import { normalizeDatatype } from '../properties/datatypes_to_builder_datatypes.js';
import { validateGuid, validateHash, validatePropertyId, validateSnakValue } from '../validate.js';
export function setQualifier(params, properties, instance) {
const { guid, hash, property, value } = params;
validateGuid(guid);
validatePropertyId(property);
const datatype = properties[property];
if (!datatype)
throw newError('missing datatype', params);
validateSnakValue(property, datatype, value);
const data = {
claim: guid,
property,
};
if (hash != null) {
validateHash(hash);
data.snakhash = hash;
}
if (hasSpecialSnaktype(value)) {
data.snaktype = value.snaktype;
}
else {
data.snaktype = 'value';
const builderDatatype = normalizeDatatype(datatype) || datatype;
data.value = builders[builderDatatype](value, instance);
}
return { action: 'wbsetqualifier', data };
}
//# sourceMappingURL=set.js.map