mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
document bug fix
This commit is contained in:
committed by
Aiden McClelland
parent
a72c1c5499
commit
60320e3083
@@ -1,5 +1,5 @@
|
|||||||
export interface Validator<T> {
|
export interface Validator<T> {
|
||||||
(operation: Operation, index: number, document: T, existingPathFragment: string): void
|
(operation: Operation, index: number, doc: T, existingPathFragment: string): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseOperation {
|
export interface BaseOperation {
|
||||||
@@ -24,18 +24,18 @@ export type Doc = { [key: string]: any }
|
|||||||
|
|
||||||
export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any>
|
export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any>
|
||||||
|
|
||||||
export function getValueByPointer (document: any, pointer: string): any {
|
export function getValueByPointer (doc: any, pointer: string): any {
|
||||||
if (pointer === '/') return document
|
if (pointer === '/') return doc
|
||||||
const pathArr = pointer.split('/')
|
const pathArr = pointer.split('/')
|
||||||
pathArr.shift()
|
pathArr.shift()
|
||||||
try {
|
try {
|
||||||
return pathArr.reduce((acc, next) => acc[next], document)
|
return pathArr.reduce((acc, next) => acc[next], doc)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyOperation (document: Doc, op: Operation): Operation | null {
|
export function applyOperation (doc: Doc, op: Operation): Operation | null {
|
||||||
let undo: Operation | null = null
|
let undo: Operation | null = null
|
||||||
const pathArr = op.path.split('/')
|
const pathArr = op.path.split('/')
|
||||||
pathArr.shift()
|
pathArr.shift()
|
||||||
@@ -75,7 +75,7 @@ export function applyOperation (document: Doc, op: Operation): Operation | null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, document)
|
}, doc)
|
||||||
|
|
||||||
return undo
|
return undo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export class Store<T extends { [key: string]: any }> {
|
|||||||
|
|
||||||
while (stashEntry && stashEntry.revision.id > id) {
|
while (stashEntry && stashEntry.revision.id > id) {
|
||||||
stashEntry.undo.forEach(u => {
|
stashEntry.undo.forEach(u => {
|
||||||
applyOperation(document, u)
|
applyOperation(this.cache.data, u)
|
||||||
})
|
})
|
||||||
stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1]
|
stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1]
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ export class Store<T extends { [key: string]: any }> {
|
|||||||
success = true
|
success = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
undo.forEach(u => {
|
undo.forEach(u => {
|
||||||
applyOperation(document, u)
|
applyOperation(this.cache.data, u)
|
||||||
})
|
})
|
||||||
undo = []
|
undo = []
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user