| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 'use strict'
- const _ = require('lodash')
- /**
- * @typedef {import("./file")} File
- * @typedef {import("./types").RawV2DocVersions} RawV2DocVersions
- */
- class V2DocVersions {
- /**
- * @param {RawV2DocVersions} data
- */
- constructor(data) {
- this.data = data || {}
- }
- static fromRaw(raw) {
- if (!raw) return undefined
- return new V2DocVersions(raw)
- }
- /**
- * @abstract
- */
- toRaw() {
- if (!this.data) return null
- const raw = _.clone(this.data)
- return raw
- }
- /**
- * Clone this object.
- *
- * @return {V2DocVersions} a new object of the same type
- */
- clone() {
- return V2DocVersions.fromRaw(this.toRaw())
- }
- applyTo(snapshot) {
- // Only update the snapshot versions if we have new versions
- if (!_.size(this.data)) return
- // Create v2DocVersions in snapshot if it does not exist
- // otherwise update snapshot v2docversions
- if (!snapshot.v2DocVersions) {
- snapshot.v2DocVersions = this.clone()
- } else {
- _.assign(snapshot.v2DocVersions.data, this.data)
- }
- }
- /**
- * Move or remove a doc.
- * Must be called after FileMap#moveFile, which validates the paths.
- */
- moveFile(pathname, newPathname) {
- for (const [id, v] of Object.entries(this.data)) {
- if (v.pathname !== pathname) continue
- if (newPathname === '') {
- delete this.data[id]
- } else {
- v.pathname = newPathname
- }
- break
- }
- }
- }
- module.exports = V2DocVersions
|