@semiont/graph 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -73
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -39,45 +39,45 @@ The examples below show direct usage for **testing, CLI tools, or standalone app
|
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
41
|
import { getGraphDatabase } from '@semiont/graph';
|
|
42
|
-
import
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
42
|
+
import { resourceId, annotationId } from '@semiont/core';
|
|
43
|
+
import type { GraphServiceConfig } from '@semiont/core';
|
|
44
|
+
|
|
45
|
+
// The `services.graph` block of an environment config
|
|
46
|
+
const graphConfig: GraphServiceConfig = {
|
|
47
|
+
platform: { type: 'container' },
|
|
48
|
+
type: 'neo4j',
|
|
49
|
+
uri: 'bolt://localhost:7687',
|
|
50
|
+
username: 'neo4j',
|
|
51
|
+
password: 'password',
|
|
52
|
+
database: 'neo4j'
|
|
54
53
|
};
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
await
|
|
55
|
+
// Singleton factory — connects automatically
|
|
56
|
+
const graph = await getGraphDatabase(graphConfig);
|
|
58
57
|
|
|
59
|
-
// Create a
|
|
60
|
-
const
|
|
61
|
-
|
|
58
|
+
// Create a resource (W3C ResourceDescriptor)
|
|
59
|
+
const resource = await graph.createResource({
|
|
60
|
+
'@context': 'https://www.w3.org/ns/ldp',
|
|
61
|
+
'@id': resourceId('doc-123'),
|
|
62
62
|
name: 'My Document',
|
|
63
|
-
format: 'text/plain',
|
|
64
63
|
entityTypes: ['Person', 'Organization'],
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
updatedAt: new Date().toISOString()
|
|
64
|
+
representations: [{ mediaType: 'text/plain' }],
|
|
65
|
+
dateCreated: new Date().toISOString()
|
|
68
66
|
});
|
|
69
67
|
|
|
70
|
-
// Create an annotation
|
|
68
|
+
// Create an annotation (W3C Web Annotation; highlights carry no body)
|
|
71
69
|
const annotation = await graph.createAnnotation({
|
|
72
|
-
id: 'anno-456',
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
id: annotationId('anno-456'),
|
|
71
|
+
motivation: 'highlighting',
|
|
72
|
+
target: {
|
|
73
|
+
source: 'doc-123',
|
|
74
|
+
selector: { type: 'TextQuoteSelector', exact: 'Important phrase', prefix: '', suffix: '' }
|
|
75
|
+
},
|
|
76
|
+
creator: { '@type': 'Person', name: 'user-123' }
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
// Query relationships
|
|
80
|
-
const annotations = await graph.
|
|
80
|
+
const annotations = await graph.getResourceAnnotations(resourceId('doc-123'));
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
## Features
|
|
@@ -92,58 +92,56 @@ const annotations = await graph.getAnnotationsForDocument('doc-123');
|
|
|
92
92
|
## Documentation
|
|
93
93
|
|
|
94
94
|
- [API Reference](./docs/API.md) - Complete API documentation
|
|
95
|
+
- [GraphDatabase Interface](./docs/GraphInterface.md) - The full interface contract
|
|
95
96
|
- [Architecture](./docs/ARCHITECTURE.md) - System design and principles
|
|
96
97
|
- [Eventual Consistency](./docs/EVENTUAL-CONSISTENCY.md) - Order-independent projections and race condition handling
|
|
97
98
|
|
|
98
99
|
## Supported Implementations
|
|
99
100
|
|
|
101
|
+
Each example below is the `services.graph` block of an environment config — pass it directly to `getGraphDatabase()`. (`platform` is required by the config schema but not used by this package.)
|
|
102
|
+
|
|
100
103
|
### Neo4j
|
|
101
104
|
Native graph database with Cypher query language.
|
|
102
105
|
|
|
103
106
|
```typescript
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
database: 'neo4j'
|
|
112
|
-
}
|
|
113
|
-
}
|
|
107
|
+
const graphConfig: GraphServiceConfig = {
|
|
108
|
+
platform: { type: 'container' },
|
|
109
|
+
type: 'neo4j',
|
|
110
|
+
uri: 'bolt://localhost:7687',
|
|
111
|
+
username: 'neo4j',
|
|
112
|
+
password: 'password',
|
|
113
|
+
database: 'neo4j'
|
|
114
114
|
};
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
`uri`, `username`, `password`, and `database` support `${ENV_VAR}` placeholders, evaluated at startup.
|
|
118
|
+
|
|
117
119
|
### AWS Neptune
|
|
118
120
|
Managed graph database supporting Gremlin.
|
|
119
121
|
|
|
120
122
|
```typescript
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
region: 'us-east-1'
|
|
128
|
-
}
|
|
129
|
-
}
|
|
123
|
+
const graphConfig: GraphServiceConfig = {
|
|
124
|
+
platform: { type: 'aws' },
|
|
125
|
+
type: 'neptune',
|
|
126
|
+
endpoint: 'wss://your-cluster.neptune.amazonaws.com:8182/gremlin',
|
|
127
|
+
port: 8182,
|
|
128
|
+
region: 'us-east-1'
|
|
130
129
|
};
|
|
131
130
|
```
|
|
132
131
|
|
|
132
|
+
If `endpoint` is omitted, the cluster endpoint is discovered via the AWS SDK using `region`.
|
|
133
|
+
|
|
133
134
|
### JanusGraph
|
|
134
135
|
Open-source distributed graph database.
|
|
135
136
|
|
|
136
137
|
```typescript
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
index: 'elasticsearch'
|
|
145
|
-
}
|
|
146
|
-
}
|
|
138
|
+
const graphConfig: GraphServiceConfig = {
|
|
139
|
+
platform: { type: 'container' },
|
|
140
|
+
type: 'janusgraph',
|
|
141
|
+
host: 'localhost',
|
|
142
|
+
port: 8182,
|
|
143
|
+
storage: 'cassandra',
|
|
144
|
+
index: 'elasticsearch'
|
|
147
145
|
};
|
|
148
146
|
```
|
|
149
147
|
|
|
@@ -151,12 +149,9 @@ const envConfig = {
|
|
|
151
149
|
In-memory implementation for development and testing.
|
|
152
150
|
|
|
153
151
|
```typescript
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
type: 'memory'
|
|
158
|
-
}
|
|
159
|
-
}
|
|
152
|
+
const graphConfig: GraphServiceConfig = {
|
|
153
|
+
platform: { type: 'posix' },
|
|
154
|
+
type: 'memory'
|
|
160
155
|
};
|
|
161
156
|
```
|
|
162
157
|
|
|
@@ -165,28 +160,38 @@ const envConfig = {
|
|
|
165
160
|
### Core Operations
|
|
166
161
|
|
|
167
162
|
```typescript
|
|
168
|
-
//
|
|
169
|
-
await graph.
|
|
170
|
-
await graph.
|
|
171
|
-
await graph.
|
|
172
|
-
await graph.
|
|
163
|
+
// Resource operations
|
|
164
|
+
await graph.createResource(resource);
|
|
165
|
+
await graph.getResource(id);
|
|
166
|
+
await graph.updateResource(id, updates);
|
|
167
|
+
await graph.deleteResource(id);
|
|
168
|
+
await graph.listResources({ entityTypes: ['Person'] });
|
|
169
|
+
await graph.searchResources('query');
|
|
173
170
|
|
|
174
171
|
// Annotation operations
|
|
175
|
-
await graph.createAnnotation(
|
|
172
|
+
await graph.createAnnotation(input);
|
|
176
173
|
await graph.getAnnotation(id);
|
|
177
174
|
await graph.updateAnnotation(id, updates);
|
|
178
175
|
await graph.deleteAnnotation(id);
|
|
176
|
+
await graph.listAnnotations({ resourceId });
|
|
179
177
|
|
|
180
|
-
//
|
|
181
|
-
await graph.
|
|
182
|
-
await graph.
|
|
183
|
-
await graph.
|
|
178
|
+
// Relationship queries
|
|
179
|
+
await graph.getResourceAnnotations(resourceId);
|
|
180
|
+
await graph.getHighlights(resourceId);
|
|
181
|
+
await graph.getReferences(resourceId);
|
|
182
|
+
await graph.getResourceReferencedBy(resourceId);
|
|
183
|
+
|
|
184
|
+
// Graph traversal
|
|
185
|
+
await graph.getResourceConnections(resourceId);
|
|
186
|
+
await graph.findPath(fromResourceId, toResourceId);
|
|
184
187
|
|
|
185
188
|
// Tag collections
|
|
186
189
|
await graph.getEntityTypes();
|
|
187
190
|
await graph.addEntityType('NewType');
|
|
188
191
|
```
|
|
189
192
|
|
|
193
|
+
See [GraphInterface.md](./docs/GraphInterface.md) for the full contract.
|
|
194
|
+
|
|
190
195
|
## Graph as Optional Projection
|
|
191
196
|
|
|
192
197
|
The graph database is designed as an **optional read-only projection**:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semiont/graph",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=24.0.0"
|
|
6
6
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"test:coverage": "vitest run --coverage"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@semiont/
|
|
30
|
+
"@semiont/http-transport": "*",
|
|
31
31
|
"@semiont/core": "*",
|
|
32
32
|
"@semiont/ontology": "*",
|
|
33
33
|
"uuid": "^14.0.0"
|