-
Notifications
You must be signed in to change notification settings - Fork 0
feat: WEIGHTED milestone (v7.3.0) — edge properties #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
78918be
feat: implement edge property key encoding (WT/EPKEY/1)
flyingrobots c7d30fa
feat: add setEdgeProperty to PatchBuilderV2 (WT/OPS/1)
flyingrobots 375f752
feat: define schema v3 format for edge properties (WT/SCHEMA/1)
flyingrobots b1b0039
test: verify LWW semantics for edge properties in JoinReducer (WT/OPS/2)
flyingrobots e86666b
feat: surface edge properties in getEdges and getEdgeProps (WT/OPS/3)
flyingrobots 4ad63b0
feat: mixed-version sync safety with E_SCHEMA_UNSUPPORTED (WT/SCHEMA/2)
flyingrobots 7dae867
feat: gate edge property visibility on edge aliveness (WT/VIS/1)
flyingrobots 45bb7ab
docs: update CHANGELOG, README, GUIDE, types, and add example for WEI…
flyingrobots 73ebef6
fix: address PR review feedback for WEIGHTED milestone
flyingrobots 1f23be2
fix: address second round of PR review feedback
flyingrobots File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * edge-properties.js - Edge property demonstration | ||
| * | ||
| * Demonstrates: | ||
| * - Setting and reading edge properties | ||
| * - Listing edges with their props via getEdges() | ||
| * - Multi-writer LWW conflict resolution on edge props | ||
| * - Clean-slate semantics: removing and re-adding an edge clears old props | ||
| * | ||
| * Run: node edge-properties.js | ||
| */ | ||
|
|
||
| import { execSync } from 'child_process'; | ||
| const modulePath = process.env.WARPGRAPH_MODULE || '../index.js'; | ||
| const { default: WarpGraph, GitGraphAdapter } = await import(modulePath); | ||
| import Plumbing from '@git-stunts/plumbing'; | ||
|
|
||
| async function main() { | ||
| console.log('WarpGraph Edge Properties Example\n'); | ||
|
|
||
| // ============================================================================ | ||
| // Step 1: Set up git repository and persistence | ||
| // ============================================================================ | ||
|
|
||
| try { | ||
| execSync('git rev-parse --git-dir', { stdio: 'pipe' }); | ||
| console.log('[1] Git repo already initialized'); | ||
| } catch { | ||
| console.log('[1] Initializing git repo...'); | ||
| execSync('git init', { stdio: 'inherit' }); | ||
| execSync('git config user.email "demo@example.com"', { stdio: 'pipe' }); | ||
| execSync('git config user.name "Demo User"', { stdio: 'pipe' }); | ||
| } | ||
|
|
||
| const plumbing = Plumbing.createDefault({ cwd: process.cwd() }); | ||
| const persistence = new GitGraphAdapter({ plumbing }); | ||
|
|
||
| // ============================================================================ | ||
| // Step 2: Open graph with autoMaterialize | ||
| // ============================================================================ | ||
|
|
||
| const graph = await WarpGraph.open({ | ||
| persistence, | ||
| graphName: 'edge-props-demo', | ||
| writerId: 'writer-1', | ||
| autoMaterialize: true, | ||
| }); | ||
|
|
||
| console.log(`[2] Opened graph "${graph.graphName}" (autoMaterialize: on)`); | ||
|
|
||
| // ============================================================================ | ||
| // Step 3: Create nodes and edges with properties | ||
| // ============================================================================ | ||
|
|
||
| await (await graph.createPatch()) | ||
| .addNode('user:alice') | ||
| .addNode('user:bob') | ||
| .addEdge('user:alice', 'user:bob', 'follows') | ||
| .setEdgeProperty('user:alice', 'user:bob', 'follows', 'since', '2025-06-01') | ||
| .setEdgeProperty('user:alice', 'user:bob', 'follows', 'weight', 0.9) | ||
| .commit(); | ||
|
|
||
| console.log('\n[3] Created nodes and edge with properties'); | ||
|
|
||
| // ============================================================================ | ||
| // Step 4: Read edge properties with getEdgeProps() | ||
| // ============================================================================ | ||
|
|
||
| const props = await graph.getEdgeProps('user:alice', 'user:bob', 'follows'); | ||
| console.log('\n[4] getEdgeProps(alice, bob, follows):'); | ||
| console.log(` since = ${props.since}`); | ||
| console.log(` weight = ${props.weight}`); | ||
|
|
||
| // ============================================================================ | ||
| // Step 5: List all edges with props via getEdges() | ||
| // ============================================================================ | ||
|
|
||
| const edges = await graph.getEdges(); | ||
| console.log('\n[5] getEdges() — all edges with their props:'); | ||
| for (const edge of edges) { | ||
| const p = Object.keys(edge.props).length > 0 ? JSON.stringify(edge.props) : '(none)'; | ||
| console.log(` ${edge.from} --${edge.label}--> ${edge.to} props: ${p}`); | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Step 6: Multi-writer conflict resolution (LWW) | ||
| // ============================================================================ | ||
|
|
||
| console.log('\n[6] Multi-writer edge property conflict (LWW)...'); | ||
|
|
||
| const writer2 = await WarpGraph.open({ | ||
| persistence, | ||
| graphName: 'edge-props-demo', | ||
| writerId: 'writer-2', | ||
| autoMaterialize: true, | ||
| }); | ||
|
|
||
| // writer-1 sets weight to 0.5 | ||
| await (await graph.createPatch()) | ||
| .setEdgeProperty('user:alice', 'user:bob', 'follows', 'weight', 0.5) | ||
| .commit(); | ||
|
|
||
| // writer-2 sets weight to 0.8 (higher Lamport clock wins) | ||
| await (await writer2.createPatch()) | ||
| .setEdgeProperty('user:alice', 'user:bob', 'follows', 'weight', 0.8) | ||
| .commit(); | ||
|
|
||
| // Materialize from writer-1's perspective — both writers' patches merge | ||
| await graph.materialize(); | ||
| const merged = await graph.getEdgeProps('user:alice', 'user:bob', 'follows'); | ||
| console.log(` writer-1 set weight=0.5, writer-2 set weight=0.8`); | ||
| console.log(` After LWW merge: weight = ${merged.weight}`); | ||
|
|
||
| // ============================================================================ | ||
| // Step 7: Edge removal hides props; re-add gives clean slate | ||
| // ============================================================================ | ||
|
|
||
| console.log('\n[7] Edge removal hides props, re-add gives clean slate...'); | ||
|
|
||
| // Remove the edge | ||
| await (await graph.createPatch()) | ||
| .removeEdge('user:alice', 'user:bob', 'follows') | ||
| .commit(); | ||
|
|
||
| await graph.materialize(); | ||
| const afterRemove = await graph.getEdgeProps('user:alice', 'user:bob', 'follows'); | ||
| console.log(` After removeEdge: getEdgeProps => ${afterRemove}`); | ||
|
|
||
| // Re-add the same edge (no old props carry over) | ||
| await (await graph.createPatch()) | ||
| .addEdge('user:alice', 'user:bob', 'follows') | ||
| .setEdgeProperty('user:alice', 'user:bob', 'follows', 'note', 'fresh start') | ||
| .commit(); | ||
|
|
||
| await graph.materialize(); | ||
| const afterReAdd = await graph.getEdgeProps('user:alice', 'user:bob', 'follows'); | ||
| console.log(` After re-addEdge: props = ${JSON.stringify(afterReAdd)}`); | ||
| console.log(' Old props (since, weight) are gone — clean slate!'); | ||
|
|
||
| console.log('\nEdge properties example complete!'); | ||
| } | ||
|
|
||
| main().catch(err => { | ||
| console.error('Error:', err.message); | ||
| if (err.stack) { | ||
| console.error(err.stack); | ||
| } | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.