UNPKG

dotbit-sdk-allin

Version:

A complete .bit SDK and utilities in TypeScript

38 lines 1.2 kB
export class RecordsEditor { constructor(initialRecords, bitAccount) { this.initialRecords = initialRecords; this.bitAccount = bitAccount; this.records = initialRecords; } add(records) { if (!Array.isArray(records)) { records = [records]; } records = records.map(record => Object.assign({ ttl: '300', label: '', }, record)); this.records = this.records.concat(records); return this; } delete(recordMatcher) { const fields = []; recordMatcher.key && fields.push('key'); recordMatcher.value && fields.push('value'); recordMatcher.label && fields.push('label'); this.records = this.records.filter(record => !fields.every(field => record[field] === recordMatcher[field])); return this; } change(recordMatcher, record) { this.delete(recordMatcher); this.add(record); return this; } empty() { this.records = []; } execute() { return this.bitAccount.updateRecords(this.records); } } //# sourceMappingURL=RecordsEditor.js.map