[overleaf-editor-core] Restructure TextOperation hierachy (#16582)

* [overleaf-editor-core] Restructure TextOperation hierachy

Restructures the hierachy of TextOperations to include a superclass
EditOperation. This superclass will later on contain other classes used
for tracked changes and comments.

* [overleaf-editor-core] Update json format of LazyStringFileData

* [history-v1+project-history] Fix TextOperation.fromJSON calls

* [overleaf-editor-core] Change EditOperationBuilder.fromRaw to fromJSON

* [overleaf-editor-core] Update apply and invert functions to accept FileData

* [overleaf-editor-core] Pass missing argument to store method

* [overleaf-editor-core] Remove unused method

* [overleaf-editor-core] User EditOperationTransformer

* [overleaf-editor-core] Clean up JSDoc comments

* [overleaf-editor-core] Add tests for EditOperation

* [overleaf-editor-core] Update JSDoc types

GitOrigin-RevId: 9c22a3a89b8483bdb87b43f329ddbdd887ffed42
This commit is contained in:
Mathias Jakobsen
2024-01-24 09:04:18 +00:00
committed by Copybot
parent fc90db231c
commit 43b2fe4a3a
21 changed files with 457 additions and 179 deletions
@@ -212,7 +212,12 @@ describe('overleaf ot', function () {
// edit the main file
.then(projectId => {
const change = new Change(
[Operation.editFile('main.tex', TextOperation.fromJSON(['hello']))],
[
Operation.editFile(
'main.tex',
TextOperation.fromJSON({ textOperation: ['hello'] })
),
],
new Date()
)
return basicAuthClient.apis.ProjectImport.importChanges1({
@@ -263,7 +268,7 @@ describe('overleaf ot', function () {
[
Operation.editFile(
'main.tex',
TextOperation.fromJSON([1, -4, 'i world'])
TextOperation.fromJSON({ textOperation: [1, -4, 'i world'] })
),
],
new Date()
@@ -49,8 +49,10 @@ describe('history import', function () {
const testProjectId = '1'
const testFilePathname = 'main.tex'
const testAuthors = [123, null]
const testTextOperation0 = TextOperation.fromJSON(['a'])
const testTextOperation1 = TextOperation.fromJSON([1, 'b'])
const testTextOperation0 = TextOperation.fromJSON({ textOperation: ['a'] })
const testTextOperation1 = TextOperation.fromJSON({
textOperation: [1, 'b'],
})
let testSnapshot
@@ -188,7 +190,9 @@ describe('history import', function () {
it('rejects invalid changes in history', function () {
const testProjectId = '1'
const testFilePathname = 'main.tex'
const testTextOperation = TextOperation.fromJSON(['a', 10])
const testTextOperation = TextOperation.fromJSON({
textOperation: ['a', 10],
})
let testSnapshot
@@ -286,7 +290,7 @@ describe('history import', function () {
const testProjectId = '1'
const mainFilePathname = 'main.tex'
const testFilePathname = 'test.tex'
const testTextOperation = TextOperation.fromJSON(['a'])
const testTextOperation = TextOperation.fromJSON({ textOperation: ['a'] })
const inexistentAuthors = [1234, 5678]
const projectVersion = '12345.0'
const v2DocVersions = new V2DocVersions({
@@ -447,7 +451,7 @@ describe('history import', function () {
it('rejects text operations on binary files', function () {
const testProjectId = '1'
const testFilePathname = 'main.tex'
const testTextOperation = TextOperation.fromJSON(['bb'])
const testTextOperation = TextOperation.fromJSON({ textOperation: ['bb'] })
let testSnapshot
@@ -517,7 +521,9 @@ describe('history import', function () {
it('accepts text operation on files with null characters if stringLength is present', function () {
const testProjectId = '1'
const mainFilePathname = 'main.tex'
const testTextOperation = TextOperation.fromJSON([3, 'a'])
const testTextOperation = TextOperation.fromJSON({
textOperation: [3, 'a'],
})
let testSnapshot
@@ -626,7 +632,7 @@ describe('history import', function () {
it('creates and returns changes with v2 author ids', function () {
const testFilePathname = 'test.tex'
const testTextOperation = TextOperation.fromJSON(['a'])
const testTextOperation = TextOperation.fromJSON({ textOperation: ['a'] })
const v2Authors = ['5a296963ad5e82432674c839', null]
let testProjectId
@@ -52,7 +52,9 @@ describe('chunkStore', function () {
describe('adding and editing a blank file', function () {
const testPathname = 'foo.txt'
const testTextOperation = TextOperation.fromJSON(['a']) // insert an a
const testTextOperation = TextOperation.fromJSON({
textOperation: ['a'],
}) // insert an a
let lastChangeTimestamp
beforeEach(async function () {
@@ -259,7 +261,9 @@ describe('chunkStore', function () {
it('does not create chunks', async function () {
const oldEndVersion = 0
const testPathname = 'foo.txt'
const testTextOperation = TextOperation.fromJSON(['a']) // insert an a
const testTextOperation = TextOperation.fromJSON({
textOperation: ['a'],
}) // insert an a
let chunk = await chunkStore.loadLatest(projectId)
expect(chunk.getEndVersion()).to.equal(oldEndVersion)
@@ -287,13 +291,13 @@ describe('chunkStore', function () {
makeChange(
Operation.editFile(
'main.tex',
TextOperation.fromJSON([3, 'def'])
TextOperation.fromJSON({ textOperation: [3, 'def'] })
)
),
makeChange(
Operation.editFile(
'main.tex',
TextOperation.fromJSON([6, 'ghi'])
TextOperation.fromJSON({ textOperation: [6, 'ghi'] })
)
),
],
@@ -6,7 +6,7 @@ describe('OperationsCompressor', function () {
function edit(pathname, textOperationJsonObject) {
return Core.Operation.editFile(
pathname,
Core.TextOperation.fromJSON(textOperationJsonObject)
Core.TextOperation.fromJSON({ textOperation: textOperationJsonObject })
)
}