@dstanesc/o-o-o-o-o-o-o
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -283,3 +283,53 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
}); | ||
test('zero change version merge', async () => { | ||
const blockStore1 = memoryBlockStoreFactory(); | ||
/** | ||
* Build original data set | ||
*/ | ||
const versionStore = await versionStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}); | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}); | ||
const graph = new Graph(versionStore, graphStore); | ||
const tx = graph.tx(); | ||
await tx.start(); | ||
const v1 = tx.addVertex(ObjectTypes.FOLDER); | ||
const v2 = tx.addVertex(ObjectTypes.FOLDER); | ||
const v3 = tx.addVertex(ObjectTypes.FILE); | ||
const e1 = await tx.addEdge(v1, v2, RlshpTypes.CONTAINS); | ||
const e2 = await tx.addEdge(v1, v3, RlshpTypes.CONTAINS); | ||
await tx.addVertexProp(v1, KeyTypes.NAME, 'root-folder', PropTypes.META); | ||
await tx.addVertexProp(v2, KeyTypes.NAME, 'nested-folder', PropTypes.META); | ||
await tx.addVertexProp(v3, KeyTypes.NAME, 'nested-file', PropTypes.META); | ||
await tx.addVertexProp(v2, KeyTypes.CONTENT, 'hello world from v2', PropTypes.DATA); | ||
await tx.addVertexProp(v3, KeyTypes.CONTENT, 'hello world from v3', PropTypes.DATA); | ||
const { root: original } = await tx.commit({}); | ||
const versionStore1 = await versionStoreFactory({ | ||
versionRoot: original, | ||
storeRoot: versionStore.versionStoreRoot(), | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}); | ||
const versionStore2 = await versionStoreFactory({ | ||
versionRoot: original, | ||
storeRoot: versionStore.versionStoreRoot(), | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}); | ||
const { root: mergedRoot, index: mergedIndex, blocks: mergedBlocks, } = await versionStore1.mergeVersions(versionStore2); | ||
assert.equal(mergedRoot.toString(), original.toString()); | ||
}); | ||
}); | ||
//# sourceMappingURL=version-merge.test.js.map |
@@ -260,3 +260,3 @@ import { blockIndexFactory } from './block-index'; | ||
const { root: versionStoreRoot, index: versionStoreIndex, blocks: versionStoreBlocks, } = await restoreVersionStore(remoteVersionStoreBytes, transientStore); | ||
const versionStoreTransient = await versionStoreFactory({ | ||
const versionStoreRemote = await versionStoreFactory({ | ||
storeRoot: versionStoreRoot, | ||
@@ -268,4 +268,4 @@ chunk, | ||
}); | ||
const versions = versionStoreTransient.log(); | ||
for (const version of versions) { | ||
const remoteVersions = versionStoreRemote.log(); | ||
for (const version of remoteVersions) { | ||
try { | ||
@@ -281,22 +281,64 @@ await blockStore.get(version.root); | ||
} | ||
await transientStore.push(blockStore); | ||
const versionStore = await versionStoreFactory({ | ||
storeRoot: versionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graph = new Graph(versionStore, graphStore); | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
}; | ||
if (localVersionStoreRoot !== undefined) { | ||
const localVersionStoreBundle = await packVersionStore(localVersionStoreRoot, blockStore, chunk, valueCodec); | ||
const { root: storeRootExisting } = await restoreVersionStore(localVersionStoreBundle.bytes, transientStore); | ||
const versionStoreLocal = await versionStoreFactory({ | ||
storeRoot: localVersionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: transientStore, | ||
}); | ||
const localVersions = versionStoreLocal.log(); | ||
for (const version of localVersions) { | ||
const localGraphVersionBundle = await packGraphVersion(version.root, blockStore); | ||
await restoreGraphVersion(localGraphVersionBundle.bytes, transientStore); | ||
} | ||
const { root: mergedRoot, index: mergedIndex, blocks: mergedBlocks, } = await versionStoreLocal.mergeVersions(versionStoreRemote); | ||
await transientStore.push(blockStore); | ||
const mergedVersionRoot = versionStoreLocal.currentRoot(); | ||
const mergedVersionStoreRoot = versionStoreLocal.versionStoreRoot(); | ||
const versionStore = await versionStoreFactory({ | ||
storeRoot: mergedVersionStoreRoot, | ||
versionRoot: mergedVersionRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graph = new Graph(versionStore, graphStore); | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
}; | ||
} | ||
else { | ||
await transientStore.push(blockStore); | ||
const versionStore = await versionStoreFactory({ | ||
storeRoot: versionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}); | ||
const graph = new Graph(versionStore, graphStore); | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
}; | ||
} | ||
} | ||
@@ -303,0 +345,0 @@ else { |
@@ -213,4 +213,8 @@ import { chunkyStore } from '@dstanesc/store-chunky-bytes'; | ||
} | ||
else | ||
throw new Error(`Nothing to merge`); | ||
else { | ||
const { version, index } = await versionGet(); | ||
const { extractVersionBlocks } = graphPackerFactory(linkCodec); | ||
const blocks = await extractVersionBlocks({ root: version.root, index }, blockStore); | ||
return { root: version.root, index, blocks }; | ||
} | ||
}; | ||
@@ -217,0 +221,0 @@ await init(storeRoot); |
{ | ||
"name": "@dstanesc/o-o-o-o-o-o-o", | ||
"description": "O-O-O-O-O-O-O is a collection of content addressed persistent data structures", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/dstanesc/O-O-O-O-O-O-O", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/dstanesc/O-O-O-O-O-O-O", |
@@ -1,2 +0,2 @@ | ||
![](./img/OOOOOOO-W100.png) | ||
# O-O-O-O-O-O-O | ||
@@ -3,0 +3,0 @@ This library enables applications to author, revise, merge, navigate and share trusted, auditable and immutable graph-like data structures. Multi-local, granular and configurable persistence across technologies and providers. The individual persistence atoms (the blocks) are location independent and uniquely identified using cryptographic hashes. Each individual version of the graph data structure is location independent and uniquely identified using a cryptographic handle - _the root_. |
@@ -454,2 +454,84 @@ import { compute_chunks } from '@dstanesc/wasm-chunking-fastcdc-node' | ||
}) | ||
test('zero change version merge', async () => { | ||
const blockStore1: MemoryBlockStore = memoryBlockStoreFactory() | ||
/** | ||
* Build original data set | ||
*/ | ||
const versionStore: VersionStore = await versionStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}) | ||
const graphStore: GraphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}) | ||
const graph = new Graph(versionStore, graphStore) | ||
const tx = graph.tx() | ||
await tx.start() | ||
const v1 = tx.addVertex(ObjectTypes.FOLDER) | ||
const v2 = tx.addVertex(ObjectTypes.FOLDER) | ||
const v3 = tx.addVertex(ObjectTypes.FILE) | ||
const e1 = await tx.addEdge(v1, v2, RlshpTypes.CONTAINS) | ||
const e2 = await tx.addEdge(v1, v3, RlshpTypes.CONTAINS) | ||
await tx.addVertexProp(v1, KeyTypes.NAME, 'root-folder', PropTypes.META) | ||
await tx.addVertexProp( | ||
v2, | ||
KeyTypes.NAME, | ||
'nested-folder', | ||
PropTypes.META | ||
) | ||
await tx.addVertexProp(v3, KeyTypes.NAME, 'nested-file', PropTypes.META) | ||
await tx.addVertexProp( | ||
v2, | ||
KeyTypes.CONTENT, | ||
'hello world from v2', | ||
PropTypes.DATA | ||
) | ||
await tx.addVertexProp( | ||
v3, | ||
KeyTypes.CONTENT, | ||
'hello world from v3', | ||
PropTypes.DATA | ||
) | ||
const { root: original } = await tx.commit({}) | ||
const versionStore1: VersionStore = await versionStoreFactory({ | ||
versionRoot: original, | ||
storeRoot: versionStore.versionStoreRoot(), | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}) | ||
const versionStore2: VersionStore = await versionStoreFactory({ | ||
versionRoot: original, | ||
storeRoot: versionStore.versionStoreRoot(), | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: blockStore1, | ||
}) | ||
const { | ||
root: mergedRoot, | ||
index: mergedIndex, | ||
blocks: mergedBlocks, | ||
} = await versionStore1.mergeVersions(versionStore2) | ||
assert.equal(mergedRoot.toString(), original.toString()) | ||
}) | ||
}) |
@@ -470,3 +470,3 @@ import { blockIndexFactory } from './block-index' | ||
) | ||
const versionStoreTransient: VersionStore = | ||
const versionStoreRemote: VersionStore = | ||
await versionStoreFactory({ | ||
@@ -479,4 +479,4 @@ storeRoot: versionStoreRoot, | ||
}) | ||
const versions: Version[] = versionStoreTransient.log() | ||
for (const version of versions) { | ||
const remoteVersions: Version[] = versionStoreRemote.log() | ||
for (const version of remoteVersions) { | ||
try { | ||
@@ -496,21 +496,90 @@ await blockStore.get(version.root) | ||
} | ||
await transientStore.push(blockStore) | ||
const versionStore: VersionStore = await versionStoreFactory({ | ||
storeRoot: versionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graph = new Graph(versionStore, graphStore) | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
if (localVersionStoreRoot !== undefined) { | ||
const localVersionStoreBundle: Block = | ||
await packVersionStore( | ||
localVersionStoreRoot, | ||
blockStore, | ||
chunk, | ||
valueCodec | ||
) | ||
const { root: storeRootExisting } = | ||
await restoreVersionStore( | ||
localVersionStoreBundle.bytes, | ||
transientStore | ||
) | ||
const versionStoreLocal: VersionStore = | ||
await versionStoreFactory({ | ||
storeRoot: localVersionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore: transientStore, | ||
}) | ||
const localVersions: Version[] = versionStoreLocal.log() | ||
for (const version of localVersions) { | ||
const localGraphVersionBundle = await packGraphVersion( | ||
version.root, | ||
blockStore | ||
) | ||
await restoreGraphVersion( | ||
localGraphVersionBundle.bytes, | ||
transientStore | ||
) | ||
} | ||
const { | ||
root: mergedRoot, | ||
index: mergedIndex, | ||
blocks: mergedBlocks, | ||
} = await versionStoreLocal.mergeVersions( | ||
versionStoreRemote | ||
) | ||
await transientStore.push(blockStore) | ||
const mergedVersionRoot = versionStoreLocal.currentRoot() | ||
const mergedVersionStoreRoot = | ||
versionStoreLocal.versionStoreRoot() | ||
const versionStore: VersionStore = | ||
await versionStoreFactory({ | ||
storeRoot: mergedVersionStoreRoot, | ||
versionRoot: mergedVersionRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graph = new Graph(versionStore, graphStore) | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
} | ||
} else { | ||
await transientStore.push(blockStore) | ||
const versionStore: VersionStore = | ||
await versionStoreFactory({ | ||
storeRoot: versionStoreRoot, | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graphStore = graphStoreFactory({ | ||
chunk, | ||
linkCodec, | ||
valueCodec, | ||
blockStore, | ||
}) | ||
const graph = new Graph(versionStore, graphStore) | ||
return { | ||
versionStore, | ||
graphStore, | ||
graph, | ||
} | ||
} | ||
@@ -517,0 +586,0 @@ } else { |
@@ -369,3 +369,11 @@ import { BlockStore } from './block-store' | ||
} | ||
} else throw new Error(`Nothing to merge`) | ||
} else { | ||
const { version, index } = await versionGet() | ||
const { extractVersionBlocks } = graphPackerFactory(linkCodec) | ||
const blocks: Block[] = await extractVersionBlocks( | ||
{ root: version.root, index }, | ||
blockStore | ||
) | ||
return { root: version.root, index, blocks } | ||
} | ||
} | ||
@@ -372,0 +380,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1991436
26263