2023-01-13 12:42:29 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const assert = require('check-types').assert
|
|
|
|
|
|
|
|
const Change = require('./change')
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A `ChangeNote` is returned when the server has applied a {@link Change}.
|
|
|
|
*/
|
2023-08-22 14:48:04 +00:00
|
|
|
class ChangeNote {
|
|
|
|
/**
|
|
|
|
* @param {number} baseVersion the new base version for the change
|
|
|
|
* @param {?Change} change
|
|
|
|
*/
|
|
|
|
constructor(baseVersion, change) {
|
|
|
|
assert.integer(baseVersion, 'bad baseVersion')
|
|
|
|
assert.maybe.instance(change, Change, 'bad change')
|
|
|
|
|
|
|
|
this.baseVersion = baseVersion
|
|
|
|
this.change = change
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
/**
|
|
|
|
* For serialization.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
toRaw() {
|
|
|
|
return {
|
|
|
|
baseVersion: this.baseVersion,
|
|
|
|
change: this.change.toRaw(),
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
toRawWithoutChange() {
|
2023-01-13 12:42:29 +00:00
|
|
|
return {
|
|
|
|
baseVersion: this.baseVersion,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
static fromRaw(raw) {
|
|
|
|
assert.integer(raw.baseVersion, 'bad raw.baseVersion')
|
|
|
|
assert.maybe.object(raw.change, 'bad raw.changes')
|
2023-01-13 12:42:29 +00:00
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
return new ChangeNote(raw.baseVersion, Change.fromRaw(raw.change))
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
getBaseVersion() {
|
|
|
|
return this.baseVersion
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
getResultVersion() {
|
|
|
|
return this.baseVersion + 1
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
|
2023-08-22 14:48:04 +00:00
|
|
|
getChange() {
|
|
|
|
return this.change
|
|
|
|
}
|
2023-01-13 12:42:29 +00:00
|
|
|
}
|
2023-08-22 14:48:04 +00:00
|
|
|
|
|
|
|
module.exports = ChangeNote
|