dotbit-sdk-allin
Version:
A complete .bit SDK and utilities in TypeScript
42 lines • 1.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordsEditor = void 0;
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);
}
}
exports.RecordsEditor = RecordsEditor;
//# sourceMappingURL=RecordsEditor.js.map
;