grafio-mongo 1.0.1 → 1.2.0
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/CODE_OF_CONDUCT.md +127 -0
- package/CONTRIBUTING.md +125 -0
- package/README.md +1 -1
- package/dist/MongoGraphFactory.d.ts +1 -0
- package/dist/MongoGraphFactory.js +20 -3
- package/dist/MongoStorageProvider.d.ts +5 -3
- package/dist/MongoStorageProvider.js +47 -5
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -1
- package/package.json +6 -5
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
8
|
+
level of experience, education, socio-economic status, nationality, personal
|
|
9
|
+
appearance, race, religion, or sexual identity and orientation.
|
|
10
|
+
|
|
11
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
12
|
+
diverse, inclusive, and healthy community.
|
|
13
|
+
|
|
14
|
+
## Our Standards
|
|
15
|
+
|
|
16
|
+
Examples of behavior that contributes to a positive environment for our
|
|
17
|
+
community include:
|
|
18
|
+
|
|
19
|
+
* Demonstrating empathy and kindness toward other people
|
|
20
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
21
|
+
* Giving and gracefully accepting constructive feedback
|
|
22
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
23
|
+
and learning from the experience
|
|
24
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
25
|
+
overall community
|
|
26
|
+
|
|
27
|
+
Examples of unacceptable behavior include:
|
|
28
|
+
|
|
29
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
30
|
+
advances of any kind
|
|
31
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
32
|
+
* Public or private harassment
|
|
33
|
+
* Publishing others' private information, such as a physical or email
|
|
34
|
+
address, without their explicit permission
|
|
35
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
36
|
+
professional setting
|
|
37
|
+
|
|
38
|
+
## Enforcement Responsibilities
|
|
39
|
+
|
|
40
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
41
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
42
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
43
|
+
or harmful.
|
|
44
|
+
|
|
45
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
46
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
47
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
48
|
+
decisions when appropriate.
|
|
49
|
+
|
|
50
|
+
## Scope
|
|
51
|
+
|
|
52
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
53
|
+
an individual is officially representing the community in public spaces.
|
|
54
|
+
Examples of representing our community include using an official e-mail
|
|
55
|
+
address, posting via an official social media account, or acting as an appointed
|
|
56
|
+
representative at an online or offline event.
|
|
57
|
+
|
|
58
|
+
## Enforcement
|
|
59
|
+
|
|
60
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
61
|
+
reported to the community leaders responsible for enforcement at
|
|
62
|
+
[INSERT CONTACT METHOD].
|
|
63
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
64
|
+
|
|
65
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
66
|
+
reporter of any incident.
|
|
67
|
+
|
|
68
|
+
## Enforcement Guidelines
|
|
69
|
+
|
|
70
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
71
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
72
|
+
|
|
73
|
+
### 1. Correction
|
|
74
|
+
|
|
75
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
76
|
+
unprofessional or unwelcome in the community.
|
|
77
|
+
|
|
78
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
79
|
+
clarity around the nature of the violation and an explanation of why the
|
|
80
|
+
behavior was inappropriate. A public apology may be requested.
|
|
81
|
+
|
|
82
|
+
### 2. Warning
|
|
83
|
+
|
|
84
|
+
**Community Impact**: A violation through a single incident or series
|
|
85
|
+
of actions.
|
|
86
|
+
|
|
87
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
88
|
+
interaction with the people involved, including unsolicited interaction with
|
|
89
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
90
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
91
|
+
like social media. Violating these terms may lead to a temporary or
|
|
92
|
+
permanent ban.
|
|
93
|
+
|
|
94
|
+
### 3. Temporary Ban
|
|
95
|
+
|
|
96
|
+
**Community Impact**: A serious violation of community standards, including
|
|
97
|
+
sustained inappropriate behavior.
|
|
98
|
+
|
|
99
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
100
|
+
communication with the community for a specified period of time. No public or
|
|
101
|
+
private interaction with the people involved, including unsolicited interaction
|
|
102
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
103
|
+
Violating these terms may lead to a permanent ban.
|
|
104
|
+
|
|
105
|
+
### 4. Permanent Ban
|
|
106
|
+
|
|
107
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
108
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
109
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
110
|
+
|
|
111
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
112
|
+
the community.
|
|
113
|
+
|
|
114
|
+
## Attribution
|
|
115
|
+
|
|
116
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
117
|
+
version 2.0, available at
|
|
118
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
119
|
+
|
|
120
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
121
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
122
|
+
|
|
123
|
+
[homepage]: https://www.contributor-covenant.org
|
|
124
|
+
|
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
126
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
127
|
+
https://www.contributor-covenant.org/translations.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Contributing to grafio-mongo
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to grafio-mongo! This document provides guidelines and instructions for contributing to the MongoDB storage backend for [grafio](https://github.com/witspry/grafio).
|
|
4
|
+
|
|
5
|
+
## Contributor License Agreement (CLA)
|
|
6
|
+
|
|
7
|
+
By submitting contributions to grafio, you grant **Satya Jugran** (the project owner) a perpetual, irrevocable, worldwide, non-exclusive, royalty-free license to use, reproduce, modify, distribute, and display your contributions for any purpose, including commercial use, under the terms of the GNU General Public License v3.0 (GPL-3.0).
|
|
8
|
+
|
|
9
|
+
As the copyright owner and project maintainer, I retain full commercial rights to all code in this repository. Contributors acknowledge that their contributions will be licensed under GPL-3.0 and agree that such licensing benefits the project while preserving my rights as the copyright holder.
|
|
10
|
+
|
|
11
|
+
This CLA ensures that contributions are submitted under GPL-3.0 licensing terms and grants me explicit rights to use contributed code in commercial projects without requiring additional approval from contributors.
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
1. **Fork the repository** on GitHub
|
|
16
|
+
2. **Clone your fork** locally:
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/satya-jugran/grafio-mongo.git
|
|
19
|
+
cd grafio-mongo
|
|
20
|
+
```
|
|
21
|
+
3. **Install dependencies**:
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Development Workflow
|
|
27
|
+
|
|
28
|
+
### Prerequisites
|
|
29
|
+
|
|
30
|
+
- Node.js >= 18
|
|
31
|
+
- npm >= 9
|
|
32
|
+
|
|
33
|
+
### Building
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Running Tests
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Run all tests
|
|
43
|
+
npm test
|
|
44
|
+
|
|
45
|
+
# Run tests in watch mode
|
|
46
|
+
npm run test:watch
|
|
47
|
+
|
|
48
|
+
# Run tests with coverage
|
|
49
|
+
npm run test:coverage
|
|
50
|
+
|
|
51
|
+
# Run performance benchmarks
|
|
52
|
+
npm run perf
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Code Style
|
|
56
|
+
|
|
57
|
+
- Use TypeScript for all new code
|
|
58
|
+
- Follow the existing code style (2-space indentation)
|
|
59
|
+
- Run `npm run build` before committing to ensure TypeScript compiles without errors
|
|
60
|
+
|
|
61
|
+
## Project Structure
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
grafio-mongo/
|
|
65
|
+
├── src/ # Source code
|
|
66
|
+
│ ├── index.ts # Main exports
|
|
67
|
+
│ ├── MongoGraphFactory.ts # Factory for creating Graph instances with MongoDB backend
|
|
68
|
+
│ └── MongoStorageProvider.ts # MongoDB storage provider implementing IStorageProvider
|
|
69
|
+
├── tests/ # Test files
|
|
70
|
+
│ ├── graph/ # Graph operation tests with MongoDB backend
|
|
71
|
+
│ ├── storage/ # Storage provider tests
|
|
72
|
+
│ ├── perf/ # Performance benchmarks
|
|
73
|
+
│ └── *.test.ts # Integration tests
|
|
74
|
+
├── CHANGELOG.md # Version history
|
|
75
|
+
└── CODE_OF_CONDUCT.md # Community guidelines
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Making Changes
|
|
79
|
+
|
|
80
|
+
1. **Create a branch** for your changes:
|
|
81
|
+
```bash
|
|
82
|
+
git checkout -b feature/your-feature-name
|
|
83
|
+
# or
|
|
84
|
+
git checkout -b fix/your-bug-fix
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
2. **Make your changes** following the code style guidelines
|
|
88
|
+
|
|
89
|
+
3. **Add tests** for new functionality (see [`tests/`](tests/))
|
|
90
|
+
|
|
91
|
+
4. **Ensure all tests pass**:
|
|
92
|
+
```bash
|
|
93
|
+
npm test
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
5. **Commit your changes** with a clear message:
|
|
97
|
+
```bash
|
|
98
|
+
git commit -m "feat: add new feature description"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Commit Message Format
|
|
102
|
+
|
|
103
|
+
Use conventional commit format:
|
|
104
|
+
- `feat:` for new features
|
|
105
|
+
- `fix:` for bug fixes
|
|
106
|
+
- `docs:` for documentation changes
|
|
107
|
+
- `test:` for test additions/changes
|
|
108
|
+
- `refactor:` for code refactoring
|
|
109
|
+
- `perf:` for performance improvements
|
|
110
|
+
|
|
111
|
+
## Pull Request Process
|
|
112
|
+
|
|
113
|
+
1. Update documentation if needed
|
|
114
|
+
2. Add tests for any new functionality
|
|
115
|
+
3. Ensure all tests pass
|
|
116
|
+
4. Update the [CHANGELOG.md](CHANGELOG.md) if applicable
|
|
117
|
+
5. Submit a pull request with a clear description of the changes
|
|
118
|
+
|
|
119
|
+
## Code of Conduct
|
|
120
|
+
|
|
121
|
+
Please read our [Code of Conduct](./CODE_OF_CONDUCT.md) before contributing to help keep our community welcoming and inclusive.
|
|
122
|
+
|
|
123
|
+
## Questions?
|
|
124
|
+
|
|
125
|
+
Feel free to open an issue on GitHub for questions about contributing.
|
package/README.md
CHANGED
|
@@ -157,7 +157,7 @@ try {
|
|
|
157
157
|
|
|
158
158
|
## Graph Operations
|
|
159
159
|
|
|
160
|
-
All graph operations from grafio are available when using MongoDB storage. See the [grafio documentation](https://github.com/
|
|
160
|
+
All graph operations from grafio are available when using MongoDB storage. See the [grafio documentation](https://github.com/satyajugran/grafio) for the complete API reference.
|
|
161
161
|
|
|
162
162
|
### Example Operations
|
|
163
163
|
|
|
@@ -15,19 +15,36 @@ class MongoGraphFactory {
|
|
|
15
15
|
await probe.ensureIndexes();
|
|
16
16
|
}
|
|
17
17
|
forGraph(graphId = 'default') {
|
|
18
|
-
const
|
|
18
|
+
const mongoProvider = new MongoStorageProvider_1.MongoStorageProvider(this._db, { ...this._opts, graphId });
|
|
19
|
+
const provider = this._wrapWithCacheIfEnabled(mongoProvider, graphId);
|
|
19
20
|
return new grafio_1.Graph(provider);
|
|
20
21
|
}
|
|
21
22
|
async fromGraphData(data, graphId = 'default') {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
23
|
+
const mongoProvider = new MongoStorageProvider_1.MongoStorageProvider(this._db, { ...this._opts, graphId });
|
|
24
|
+
const provider = this._wrapWithCacheIfEnabled(mongoProvider, graphId);
|
|
24
25
|
const filteredData = {
|
|
25
26
|
graphId,
|
|
26
27
|
nodes: data.graphId === undefined || data.graphId === graphId ? data.nodes : [],
|
|
27
28
|
edges: data.graphId === undefined || data.graphId === graphId ? data.edges : [],
|
|
28
29
|
};
|
|
30
|
+
const graph = new grafio_1.Graph(provider);
|
|
29
31
|
await grafio_1.Graph.importJSON(filteredData, provider);
|
|
30
32
|
return graph;
|
|
31
33
|
}
|
|
34
|
+
_wrapWithCacheIfEnabled(mongoProvider, graphId) {
|
|
35
|
+
if (!grafio_1.GraphManager.isInitialized()) {
|
|
36
|
+
return mongoProvider;
|
|
37
|
+
}
|
|
38
|
+
const manager = grafio_1.GraphManager.getInstance();
|
|
39
|
+
const cacheManager = manager.getCacheManager();
|
|
40
|
+
if (!cacheManager) {
|
|
41
|
+
return mongoProvider;
|
|
42
|
+
}
|
|
43
|
+
const cacheConfig = manager.getConfig()?.cache;
|
|
44
|
+
if (!cacheConfig) {
|
|
45
|
+
return mongoProvider;
|
|
46
|
+
}
|
|
47
|
+
return new grafio_1.CachedStorageProvider(mongoProvider, graphId, cacheManager, cacheConfig);
|
|
48
|
+
}
|
|
32
49
|
}
|
|
33
50
|
exports.MongoGraphFactory = MongoGraphFactory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Db } from 'mongodb';
|
|
2
|
-
import { IStorageProvider, NodeData, ITransactionHandle, EdgeData, GraphData } from 'grafio';
|
|
2
|
+
import { IStorageProvider, IOrderBy, NodeData, ITransactionHandle, EdgeData, GraphData } from 'grafio';
|
|
3
3
|
export interface MongoStorageProviderOptions {
|
|
4
4
|
graphId?: string;
|
|
5
5
|
nodesCollection?: string;
|
|
@@ -19,15 +19,17 @@ export declare class MongoStorageProvider implements IStorageProvider {
|
|
|
19
19
|
deleteNode(id: string, transaction?: ITransactionHandle): Promise<void>;
|
|
20
20
|
hasNode(id: string, transaction?: ITransactionHandle): Promise<boolean>;
|
|
21
21
|
getNode(id: string, transaction?: ITransactionHandle): Promise<NodeData | undefined>;
|
|
22
|
-
getAllNodes(limit?: number, transaction?: ITransactionHandle): Promise<NodeData[]>;
|
|
22
|
+
getAllNodes(limit?: number, orderBy?: IOrderBy, transaction?: ITransactionHandle): Promise<NodeData[]>;
|
|
23
23
|
getNodesByType(type: string, transaction?: ITransactionHandle): Promise<NodeData[]>;
|
|
24
24
|
getNodesByProperty(key: string, value: unknown, nodeType?: string, transaction?: ITransactionHandle): Promise<NodeData[]>;
|
|
25
|
+
getTotalNodeCount(transaction?: ITransactionHandle): Promise<number>;
|
|
25
26
|
getEdgesByProperty(key: string, value: unknown, edgeType?: string, transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
27
|
+
getTotalEdgeCount(transaction?: ITransactionHandle): Promise<number>;
|
|
26
28
|
insertEdge(edge: EdgeData, transaction?: ITransactionHandle): Promise<void>;
|
|
27
29
|
deleteEdge(id: string, transaction?: ITransactionHandle): Promise<void>;
|
|
28
30
|
hasEdge(id: string, transaction?: ITransactionHandle): Promise<boolean>;
|
|
29
31
|
getEdge(id: string, transaction?: ITransactionHandle): Promise<EdgeData | undefined>;
|
|
30
|
-
getAllEdges(transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
32
|
+
getAllEdges(limit?: number, orderBy?: IOrderBy, transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
31
33
|
getEdgesByType(type: string, transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
32
34
|
getEdgesBySource(nodeId: string, type?: string, transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
33
35
|
getEdgesByTarget(nodeId: string, type?: string, transaction?: ITransactionHandle): Promise<EdgeData[]>;
|
|
@@ -29,6 +29,8 @@ class MongoStorageProvider {
|
|
|
29
29
|
await this._nodes.createIndex({ graphId: 1, type: 1 }, { name: 'node_graph_type' });
|
|
30
30
|
await this._edges.createIndex({ graphId: 1, id: 1 }, { unique: true, name: 'edge_graph_id_unique' });
|
|
31
31
|
await this._edges.createIndex({ graphId: 1, type: 1 }, { name: 'edge_graph_type' });
|
|
32
|
+
await this._edges.createIndex({ graphId: 1, sourceId: 1 }, { name: 'edge_graph_source' });
|
|
33
|
+
await this._edges.createIndex({ graphId: 1, targetId: 1 }, { name: 'edge_graph_target' });
|
|
32
34
|
await this._edges.createIndex({ graphId: 1, sourceId: 1, type: 1 }, { name: 'edge_graph_source_type' });
|
|
33
35
|
await this._edges.createIndex({ graphId: 1, targetId: 1, type: 1 }, { name: 'edge_graph_target_type' });
|
|
34
36
|
}
|
|
@@ -39,12 +41,21 @@ class MongoStorageProvider {
|
|
|
39
41
|
]);
|
|
40
42
|
}
|
|
41
43
|
async insertNode(node, transaction) {
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
if (node.createdOn === undefined) {
|
|
46
|
+
node.createdOn = now;
|
|
47
|
+
}
|
|
48
|
+
if (node.updatedOn === undefined) {
|
|
49
|
+
node.updatedOn = now;
|
|
50
|
+
}
|
|
42
51
|
const session = transaction?.context;
|
|
43
52
|
try {
|
|
44
53
|
await this._nodes.insertOne({
|
|
45
54
|
id: node.id,
|
|
46
55
|
graphId: this._graphId,
|
|
47
56
|
type: node.type,
|
|
57
|
+
createdOn: node.createdOn,
|
|
58
|
+
updatedOn: node.updatedOn,
|
|
48
59
|
properties: node.properties,
|
|
49
60
|
}, { session });
|
|
50
61
|
}
|
|
@@ -68,10 +79,12 @@ class MongoStorageProvider {
|
|
|
68
79
|
const doc = await this._nodes.findOne({ graphId: this._graphId, id }, { session });
|
|
69
80
|
return doc ? this._docToNode(doc) : undefined;
|
|
70
81
|
}
|
|
71
|
-
async getAllNodes(limit, transaction) {
|
|
82
|
+
async getAllNodes(limit, orderBy, transaction) {
|
|
72
83
|
const session = transaction?.context;
|
|
73
84
|
const nodes = [];
|
|
74
85
|
const cursor = this._nodes.find({ graphId: this._graphId }, { session }).batchSize(this._batchSize);
|
|
86
|
+
if (orderBy)
|
|
87
|
+
cursor.sort(orderBy.field, orderBy.direction);
|
|
75
88
|
if (limit)
|
|
76
89
|
cursor.limit(limit);
|
|
77
90
|
for await (const doc of cursor) {
|
|
@@ -96,6 +109,10 @@ class MongoStorageProvider {
|
|
|
96
109
|
const docs = await this._nodes.find(filter, { session }).toArray();
|
|
97
110
|
return docs.map(d => this._docToNode(d));
|
|
98
111
|
}
|
|
112
|
+
async getTotalNodeCount(transaction) {
|
|
113
|
+
const session = transaction?.context;
|
|
114
|
+
return this._nodes.countDocuments({ graphId: this._graphId }, { session });
|
|
115
|
+
}
|
|
99
116
|
async getEdgesByProperty(key, value, edgeType, transaction) {
|
|
100
117
|
const session = transaction?.context;
|
|
101
118
|
const filter = {
|
|
@@ -108,7 +125,18 @@ class MongoStorageProvider {
|
|
|
108
125
|
const docs = await this._edges.find(filter, { session }).toArray();
|
|
109
126
|
return docs.map(d => this._docToEdge(d));
|
|
110
127
|
}
|
|
128
|
+
async getTotalEdgeCount(transaction) {
|
|
129
|
+
const session = transaction?.context;
|
|
130
|
+
return this._edges.countDocuments({ graphId: this._graphId }, { session });
|
|
131
|
+
}
|
|
111
132
|
async insertEdge(edge, transaction) {
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
if (edge.createdOn === undefined) {
|
|
135
|
+
edge.createdOn = now;
|
|
136
|
+
}
|
|
137
|
+
if (edge.updatedOn === undefined) {
|
|
138
|
+
edge.updatedOn = now;
|
|
139
|
+
}
|
|
112
140
|
const session = transaction?.context;
|
|
113
141
|
try {
|
|
114
142
|
await this._edges.insertOne({
|
|
@@ -117,6 +145,8 @@ class MongoStorageProvider {
|
|
|
117
145
|
sourceId: edge.sourceId,
|
|
118
146
|
targetId: edge.targetId,
|
|
119
147
|
type: edge.type,
|
|
148
|
+
createdOn: edge.createdOn,
|
|
149
|
+
updatedOn: edge.updatedOn,
|
|
120
150
|
properties: edge.properties,
|
|
121
151
|
}, { session });
|
|
122
152
|
}
|
|
@@ -140,10 +170,14 @@ class MongoStorageProvider {
|
|
|
140
170
|
const doc = await this._edges.findOne({ graphId: this._graphId, id }, { session });
|
|
141
171
|
return doc ? this._docToEdge(doc) : undefined;
|
|
142
172
|
}
|
|
143
|
-
async getAllEdges(transaction) {
|
|
173
|
+
async getAllEdges(limit, orderBy, transaction) {
|
|
144
174
|
const session = transaction?.context;
|
|
145
175
|
const edges = [];
|
|
146
176
|
const cursor = this._edges.find({ graphId: this._graphId }, { session }).batchSize(this._batchSize);
|
|
177
|
+
if (orderBy)
|
|
178
|
+
cursor.sort(orderBy.field, orderBy.direction);
|
|
179
|
+
if (limit)
|
|
180
|
+
cursor.limit(limit);
|
|
147
181
|
for await (const doc of cursor) {
|
|
148
182
|
edges.push(this._docToEdge(doc));
|
|
149
183
|
}
|
|
@@ -236,6 +270,8 @@ class MongoStorageProvider {
|
|
|
236
270
|
id: n.id,
|
|
237
271
|
graphId: this._graphId,
|
|
238
272
|
type: n.type,
|
|
273
|
+
createdOn: n.createdOn ?? Date.now(),
|
|
274
|
+
updatedOn: n.updatedOn ?? Date.now(),
|
|
239
275
|
properties: n.properties,
|
|
240
276
|
}));
|
|
241
277
|
for (let i = 0; i < nodeDocs.length; i += this._batchSize) {
|
|
@@ -249,6 +285,8 @@ class MongoStorageProvider {
|
|
|
249
285
|
sourceId: e.sourceId,
|
|
250
286
|
targetId: e.targetId,
|
|
251
287
|
type: e.type,
|
|
288
|
+
createdOn: e.createdOn ?? Date.now(),
|
|
289
|
+
updatedOn: e.updatedOn ?? Date.now(),
|
|
252
290
|
properties: e.properties,
|
|
253
291
|
}));
|
|
254
292
|
for (let i = 0; i < edgeDocs.length; i += this._batchSize) {
|
|
@@ -296,7 +334,7 @@ class MongoStorageProvider {
|
|
|
296
334
|
}
|
|
297
335
|
const session = transaction?.context;
|
|
298
336
|
const collection = target === 'node' ? this._nodes : this._edges;
|
|
299
|
-
const result = await collection.updateOne({ graphId: this._graphId, id, [`properties.${key}`]: { $exists: false } }, { $set: { [`properties.${key}`]: value } }, { session });
|
|
337
|
+
const result = await collection.updateOne({ graphId: this._graphId, id, [`properties.${key}`]: { $exists: false } }, { $set: { [`properties.${key}`]: value, updatedOn: Date.now() } }, { session });
|
|
300
338
|
if (result.matchedCount === 0) {
|
|
301
339
|
const record = target === 'node' ? await this.getNode(id, transaction) : await this.getEdge(id, transaction);
|
|
302
340
|
if (!record) {
|
|
@@ -311,7 +349,7 @@ class MongoStorageProvider {
|
|
|
311
349
|
}
|
|
312
350
|
const session = transaction?.context;
|
|
313
351
|
const collection = target === 'node' ? this._nodes : this._edges;
|
|
314
|
-
const result = await collection.updateOne({ graphId: this._graphId, id, [`properties.${key}`]: { $exists: true } }, { $set: { [`properties.${key}`]: value } }, { session });
|
|
352
|
+
const result = await collection.updateOne({ graphId: this._graphId, id, [`properties.${key}`]: { $exists: true } }, { $set: { [`properties.${key}`]: value, updatedOn: Date.now() } }, { session });
|
|
315
353
|
if (result.matchedCount === 0) {
|
|
316
354
|
const record = target === 'node' ? await this.getNode(id, transaction) : await this.getEdge(id, transaction);
|
|
317
355
|
if (!record) {
|
|
@@ -332,7 +370,7 @@ class MongoStorageProvider {
|
|
|
332
370
|
throw new errors_1.EdgeNotFoundError(id);
|
|
333
371
|
}
|
|
334
372
|
}
|
|
335
|
-
await collection.updateOne({ graphId: this._graphId, id }, { $unset: { [`properties.${key}`]: '' } }, { session });
|
|
373
|
+
await collection.updateOne({ graphId: this._graphId, id }, { $unset: { [`properties.${key}`]: '' }, $set: { updatedOn: Date.now() } }, { session });
|
|
336
374
|
}
|
|
337
375
|
async clearProperties(target, id, transaction) {
|
|
338
376
|
const session = transaction?.context;
|
|
@@ -398,6 +436,8 @@ class MongoStorageProvider {
|
|
|
398
436
|
return {
|
|
399
437
|
id: doc.id,
|
|
400
438
|
type: doc.type,
|
|
439
|
+
createdOn: doc.createdOn,
|
|
440
|
+
updatedOn: doc.updatedOn,
|
|
401
441
|
properties: doc.properties,
|
|
402
442
|
};
|
|
403
443
|
}
|
|
@@ -407,6 +447,8 @@ class MongoStorageProvider {
|
|
|
407
447
|
sourceId: doc.sourceId,
|
|
408
448
|
targetId: doc.targetId,
|
|
409
449
|
type: doc.type,
|
|
450
|
+
createdOn: doc.createdOn,
|
|
451
|
+
updatedOn: doc.updatedOn,
|
|
410
452
|
properties: doc.properties,
|
|
411
453
|
};
|
|
412
454
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export { MongoStorageProvider } from './MongoStorageProvider';
|
|
2
2
|
export type { MongoStorageProviderOptions } from './MongoStorageProvider';
|
|
3
3
|
export { MongoGraphFactory } from './MongoGraphFactory';
|
|
4
|
+
export { GraphManager } from 'grafio';
|
|
5
|
+
export type { GraphManagerConfig, CacheConfig, CacheStats } from 'grafio';
|
|
6
|
+
export { CachedStorageProvider, CacheManager } from 'grafio';
|
|
7
|
+
export type { EvictionStrategy, PreloadStrategy, CacheStoreType } from 'grafio';
|
|
8
|
+
export { InMemoryCache } from 'grafio';
|
|
9
|
+
export type { ICacheProvider } from 'grafio';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoGraphFactory = exports.MongoStorageProvider = void 0;
|
|
3
|
+
exports.InMemoryCache = exports.CacheManager = exports.CachedStorageProvider = exports.GraphManager = exports.MongoGraphFactory = exports.MongoStorageProvider = void 0;
|
|
4
4
|
var MongoStorageProvider_1 = require("./MongoStorageProvider");
|
|
5
5
|
Object.defineProperty(exports, "MongoStorageProvider", { enumerable: true, get: function () { return MongoStorageProvider_1.MongoStorageProvider; } });
|
|
6
6
|
var MongoGraphFactory_1 = require("./MongoGraphFactory");
|
|
7
7
|
Object.defineProperty(exports, "MongoGraphFactory", { enumerable: true, get: function () { return MongoGraphFactory_1.MongoGraphFactory; } });
|
|
8
|
+
var grafio_1 = require("grafio");
|
|
9
|
+
Object.defineProperty(exports, "GraphManager", { enumerable: true, get: function () { return grafio_1.GraphManager; } });
|
|
10
|
+
var grafio_2 = require("grafio");
|
|
11
|
+
Object.defineProperty(exports, "CachedStorageProvider", { enumerable: true, get: function () { return grafio_2.CachedStorageProvider; } });
|
|
12
|
+
Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return grafio_2.CacheManager; } });
|
|
13
|
+
var grafio_3 = require("grafio");
|
|
14
|
+
Object.defineProperty(exports, "InMemoryCache", { enumerable: true, get: function () { return grafio_3.InMemoryCache; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafio-mongo",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "MongoDB storage backend for grafio",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"grafio": ">=6.0
|
|
18
|
+
"grafio": ">=6.2.0",
|
|
19
19
|
"mongodb": ">=5.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/jest": "^29.5.0",
|
|
23
23
|
"@types/node": "^25.6.0",
|
|
24
|
-
"grafio": "^6.0
|
|
24
|
+
"grafio": "^6.2.0",
|
|
25
25
|
"cross-env": "^10.1.0",
|
|
26
26
|
"jest": "^29.5.0",
|
|
27
27
|
"rimraf": "^5.0.0",
|
|
@@ -39,9 +39,10 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"author": "Satya Jugran",
|
|
42
|
-
"license": "
|
|
42
|
+
"license": "GPL-3.0",
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|
|
45
45
|
"url": "https://github.com/satya-jugran/grafio-mongo"
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"funding": "https://ko-fi.com/satyajugran"
|
|
47
48
|
}
|