Skip to content

Commit

Permalink
Merge pull request #139 from dlozina-macrometa/JSDR-92-Update-Graph-E…
Browse files Browse the repository at this point in the history
…ndpoints

JSDR 92
  • Loading branch information
dlozina-macrometa committed Mar 27, 2023
2 parents a3c71cd + d8efebb commit b1a71d8
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 186 deletions.
138 changes: 126 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export class C8Client extends Fabric {
const stream = this.stream(streamName, local, isCollectionStream);
return stream;
}

//getStreams() { } // already present
getStreamStats(
streamName: string,
Expand Down Expand Up @@ -511,6 +512,11 @@ export class C8Client extends Fabric {
return streamApp.activateStreamApplication(active);
}

//------------ Graph ----------
getGraphs(): Promise<Graph[]> {
return this.graphs();
}

createGraph(graphName: string, properties: any = {}) {
const graph = this.graph(graphName);
return graph.create(properties);
Expand All @@ -521,25 +527,43 @@ export class C8Client extends Fabric {
return graph.drop(dropCollections);
}

hasGraph(graphName: string) {
getGraph(graphName: string) {
const graph = this.graph(graphName);
return graph.exists();
return graph.get();
}

getGraph(graphName: string) {
hasGraph(graphName: string) {
const graph = this.graph(graphName);
return graph.get();
return graph.exists();
}

getGraphs(): Promise<Graph[]> {
return this.graphs();
async getEdges(graphName: string) {
const graph = this.graph(graphName);
const graphDetails = await graph.get();
return graphDetails.edgeDefinitions;
}

insertEdge(graphName: string, definition: any) {
const graph = this.graph(graphName);
return graph.addEdgeDefinition(definition);
}

removeEdgeDefinition(graphName: string, edgeCollectionName: string) {
const graph = this.graph(graphName);
return graph.removeEdgeDefinition(edgeCollectionName);
}

getEdge(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
const graphEdgeCollection = graph.edgeCollection(collectionName);
return graphEdgeCollection.document(documentHandle, opts);
}

updateEdge(
graphName: string,
collectionName: string,
Expand Down Expand Up @@ -575,12 +599,6 @@ export class C8Client extends Fabric {
return graphEdgeCollection.remove(documentHandle, opts);
}

async getEdges(graphName: string) {
const graph = this.graph(graphName);
const graphDetails = await graph.get();
return graphDetails.edgeDefinitions;
}

linkEdge(
graphName: string,
collectionName: string,
Expand All @@ -599,6 +617,98 @@ export class C8Client extends Fabric {
});
}

addEdgeToEdgeCollection(
graphName: string,
collectionName: string,
properties: any = {},
returnNew: boolean = false
) {
const graph = this.graph(graphName);
return graph.addEdgeToEdgeCollection(collectionName, properties, returnNew);
}

async listVertexCollections(graphName: string) {
const graph = this.graph(graphName);
return graph.listVertexCollections();
}

async addVertexCollection(graphName: string, collectionName: string) {
const graph = this.graph(graphName);
return graph.addVertexCollection(collectionName);
}

async removeVertexCollection(
graphName: string,
collectionName: string,
dropCollection: boolean = false
) {
const graph = this.graph(graphName);
return graph.removeVertexCollection(collectionName, dropCollection);
}

addVertexToVertexCollection(
graphName: string,
collectionName: string,
properties: any = {},
returnNew: boolean = false
) {
const graph = this.graph(graphName);
return graph.addVertexToVertexCollection(
collectionName,
properties,
returnNew
);
}

removeVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph.vertexCollection(collectionName).remove(documentHandle, opts);
}

getVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.document(documentHandle, opts);
}

updateVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
newValue: any,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.update(documentHandle, newValue, opts);
}

replaceVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
newValue: any,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.replace(documentHandle, newValue, opts);
}

//------------ User ----------
hasUser(userName: string) {
const user = this.user(userName);
return user.hasUser();
Expand Down Expand Up @@ -803,6 +913,7 @@ export class C8Client extends Fabric {
const apiKeys = this.apiKeys(keyid);
return apiKeys.removeApiKey();
}

// ----------------------------------
listAccessibleDatabases(keyid: string, full?: boolean) {
const apiKeys = this.apiKeys(keyid);
Expand All @@ -827,6 +938,7 @@ export class C8Client extends Fabric {
const apiKeys = this.apiKeys(keyid, dbName);
return apiKeys.setDatabaseAccessLevel(permission);
}

// ----------------------------------
listAccessibleCollections(keyid: string, dbName: string, full?: boolean) {
const apiKeys = this.apiKeys(keyid, dbName);
Expand Down Expand Up @@ -860,6 +972,7 @@ export class C8Client extends Fabric {
const apiKeys = this.apiKeys(keyid, dbName);
return apiKeys.setCollectionAccessLevel(collectionName, permission);
}

// ----------------------------------
listAccessibleStreams(keyid: string, dbName: string, full?: boolean) {
const apiKeys = this.apiKeys(keyid, dbName);
Expand All @@ -885,6 +998,7 @@ export class C8Client extends Fabric {
const apiKeys = this.apiKeys(keyid, dbName);
return apiKeys.setStreamAccessLevel(streamName, permission);
}

// ----------------------------------
getBillingAccessLevel(keyid: string) {
const apiKeys = this.apiKeys(keyid);
Expand Down
41 changes: 41 additions & 0 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export class GraphEdgeCollection extends EdgeCollection {
}

const GRAPH_NOT_FOUND = 1924;

export class Graph {
name: string;

Expand Down Expand Up @@ -454,4 +455,44 @@ export class Graph {
(res) => res.body.graph
);
}

addVertexToVertexCollection(
collectionName: string,
properties: any = {},
returnNew: boolean = false
) {
return this._connection.request(
{
method: "POST",
path: `/_api/graph/${this.name}/vertex/${collectionName}`,
body: {
...properties,
},
qs: {
returnNew,
},
},
(res) => res.body
);
}

addEdgeToEdgeCollection(
edgeCollectionName: string,
properties: any = {},
returnNew: boolean = false
) {
return this._connection.request(
{
method: "POST",
path: `/_api/graph/${this.name}/edge/${edgeCollectionName}`,
body: {
...properties,
},
qs: {
returnNew,
},
},
(res) => res.body
);
}
}
Loading

0 comments on commit b1a71d8

Please sign in to comment.