mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +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> {
|
||||
(operation: Operation, index: number, document: T, existingPathFragment: string): void
|
||||
(operation: Operation, index: number, doc: T, existingPathFragment: string): void
|
||||
}
|
||||
|
||||
export interface BaseOperation {
|
||||
@@ -24,18 +24,18 @@ export type Doc = { [key: string]: any }
|
||||
|
||||
export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any>
|
||||
|
||||
export function getValueByPointer (document: any, pointer: string): any {
|
||||
if (pointer === '/') return document
|
||||
export function getValueByPointer (doc: any, pointer: string): any {
|
||||
if (pointer === '/') return doc
|
||||
const pathArr = pointer.split('/')
|
||||
pathArr.shift()
|
||||
try {
|
||||
return pathArr.reduce((acc, next) => acc[next], document)
|
||||
return pathArr.reduce((acc, next) => acc[next], doc)
|
||||
} catch (e) {
|
||||
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
|
||||
const pathArr = op.path.split('/')
|
||||
pathArr.shift()
|
||||
@@ -75,7 +75,7 @@ export function applyOperation (document: Doc, op: Operation): Operation | null
|
||||
}
|
||||
}
|
||||
}
|
||||
}, document)
|
||||
}, doc)
|
||||
|
||||
return undo
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ export class Store<T extends { [key: string]: any }> {
|
||||
|
||||
while (stashEntry && stashEntry.revision.id > id) {
|
||||
stashEntry.undo.forEach(u => {
|
||||
applyOperation(document, u)
|
||||
applyOperation(this.cache.data, u)
|
||||
})
|
||||
stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1]
|
||||
}
|
||||
@@ -114,7 +114,7 @@ export class Store<T extends { [key: string]: any }> {
|
||||
success = true
|
||||
} catch (e) {
|
||||
undo.forEach(u => {
|
||||
applyOperation(document, u)
|
||||
applyOperation(this.cache.data, u)
|
||||
})
|
||||
undo = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user