wikibase-edit
Version:
Edit Wikibase from NodeJS
38 lines • 1.65 kB
JavaScript
import config from 'config';
import WBEdit from '../../../src/lib/index.js';
import { assert, randomString } from '../../unit/utils.js';
import { getSandboxItemId, getSandboxPropertyId, getSandboxClaimId } from './sandbox_entities.js';
const wbEdit = WBEdit(config);
export async function addClaim(params = {}) {
let { id, property, datatype = 'string', value = randomString(), qualifiers } = params;
id ??= await getSandboxItemId();
property ??= (await getSandboxPropertyId(datatype));
const res = await wbEdit.entity.edit({
id,
claims: {
[property]: {
value,
qualifiers,
},
},
});
assert('claims' in res.entity);
const claim = res.entity.claims[property].slice(-1)[0];
return { id, property, claim, guid: claim.id };
}
export async function addQualifier({ guid, property, datatype, value }) {
guid ??= (await getSandboxClaimId());
property ??= await getSandboxPropertyId(datatype);
const res = await wbEdit.qualifier.set({ guid, property, value });
const qualifier = res.claim.qualifiers[property].slice(-1)[0];
const { hash } = qualifier;
return { guid, property, qualifier, hash };
}
export async function addReference({ guid, property, datatype, value }) {
guid ??= await getSandboxClaimId();
property = property || (await getSandboxPropertyId(datatype));
const { reference } = await wbEdit.reference.set({ guid, property, value });
const referenceSnak = reference.snaks[property].slice(-1)[0];
return { guid, property, reference, referenceSnak };
}
//# sourceMappingURL=sandbox_snaks.js.map