first commit

This commit is contained in:
2025-04-24 13:11:28 +08:00
commit ff9c54d5e4
5960 changed files with 834111 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
'use strict'
const assert = require('check-types').assert
// Dependencies are loaded at the bottom of the file to mitigate circular
// dependency
let RestoreOrigin = null
let RestoreFileOrigin = null
let RestoreProjectOrigin = null
/**
* An Origin records where a {@link Change} came from. The Origin class handles
* simple tag origins, like "it came from rich text mode", or "it came from
* uploading files". Its subclasses record more detailed data for Changes such
* as restoring a version.
*/
class Origin {
/**
* @param {string} kind
*/
constructor(kind) {
assert.string(kind, 'Origin: bad kind')
this.kind = kind
}
/**
* Create an Origin from its raw form.
*
* @param {Object} [raw]
* @return {Origin | null}
*/
static fromRaw(raw) {
if (!raw) return null
if (raw.kind === RestoreOrigin.KIND) return RestoreOrigin.fromRaw(raw)
if (raw.kind === RestoreFileOrigin.KIND)
return RestoreFileOrigin.fromRaw(raw)
if (raw.kind === RestoreProjectOrigin.KIND)
return RestoreProjectOrigin.fromRaw(raw)
return new Origin(raw.kind)
}
/**
* Convert the Origin to raw form for storage or transmission.
*
* @return {Object}
*/
toRaw() {
return { kind: this.kind }
}
/**
* @return {string}
*/
getKind() {
return this.kind
}
}
module.exports = Origin
RestoreOrigin = require('./restore_origin')
RestoreFileOrigin = require('./restore_file_origin')
RestoreProjectOrigin = require('./restore_project_origin')

View File

@@ -0,0 +1,62 @@
'use strict'
const assert = require('check-types').assert
const Origin = require('.')
class RestoreFileOrigin extends Origin {
/**
* @param {number} version that was restored
* @param {string} path that was restored
* @param {Date} timestamp from the restored version
*/
constructor(version, path, timestamp) {
assert.integer(version, 'RestoreFileOrigin: bad version')
assert.string(path, 'RestoreFileOrigin: bad path')
assert.date(timestamp, 'RestoreFileOrigin: bad timestamp')
super(RestoreFileOrigin.KIND)
this.version = version
this.path = path
this.timestamp = timestamp
}
static fromRaw(raw) {
return new RestoreFileOrigin(raw.version, raw.path, new Date(raw.timestamp))
}
/** @inheritdoc */
toRaw() {
return {
kind: RestoreFileOrigin.KIND,
version: this.version,
path: this.path,
timestamp: this.timestamp.toISOString(),
}
}
/**
* @return {number}
*/
getVersion() {
return this.version
}
/**
* @return {string}
*/
getPath() {
return this.path
}
/**
* @return {Date}
*/
getTimestamp() {
return this.timestamp
}
}
RestoreFileOrigin.KIND = 'file-restore'
module.exports = RestoreFileOrigin

View File

@@ -0,0 +1,62 @@
'use strict'
const assert = require('check-types').assert
const Origin = require('./')
/**
* When a {@link Change} is generated by restoring a previous version, this
* records the original version. We also store the timestamp of the restored
* version for display; technically, this is redundant, because we could
* recover it using the version ID. However, it would be very expensive to
* recover all referenced versions, and it is also possible that the change
* for the restored version will no longer exist, either because it was merged
* with other changes or was deleted.
*
* @see Origin
*/
class RestoreOrigin extends Origin {
/**
* @param {number} version that was restored
* @param {Date} timestamp from the restored version
*/
constructor(version, timestamp) {
assert.integer(version, 'RestoreOrigin: bad version')
assert.date(timestamp, 'RestoreOrigin: bad timestamp')
super(RestoreOrigin.KIND)
this.version = version
this.timestamp = timestamp
}
static fromRaw(raw) {
return new RestoreOrigin(raw.version, new Date(raw.timestamp))
}
/** @inheritdoc */
toRaw() {
return {
kind: RestoreOrigin.KIND,
version: this.version,
timestamp: this.timestamp.toISOString(),
}
}
/**
* @return {number}
*/
getVersion() {
return this.version
}
/**
* @return {Date}
*/
getTimestamp() {
return this.timestamp
}
}
RestoreOrigin.KIND = 'restore'
module.exports = RestoreOrigin

View File

@@ -0,0 +1,51 @@
'use strict'
const assert = require('check-types').assert
const Origin = require('.')
class RestoreProjectOrigin extends Origin {
/**
* @param {number} version that was restored
* @param {Date} timestamp from the restored version
*/
constructor(version, timestamp) {
assert.integer(version, 'RestoreProjectOrigin: bad version')
assert.date(timestamp, 'RestoreProjectOrigin: bad timestamp')
super(RestoreProjectOrigin.KIND)
this.version = version
this.timestamp = timestamp
}
static fromRaw(raw) {
return new RestoreProjectOrigin(raw.version, new Date(raw.timestamp))
}
/** @inheritdoc */
toRaw() {
return {
kind: RestoreProjectOrigin.KIND,
version: this.version,
timestamp: this.timestamp.toISOString(),
}
}
/**
* @return {number}
*/
getVersion() {
return this.version
}
/**
* @return {Date}
*/
getTimestamp() {
return this.timestamp
}
}
RestoreProjectOrigin.KIND = 'project-restore'
module.exports = RestoreProjectOrigin