Skip to content

Commit 3382b03

Browse files
committed
add setAPiKey
1 parent c69e857 commit 3382b03

File tree

4 files changed

+126
-163
lines changed

4 files changed

+126
-163
lines changed

lib/query/woqlLibrary.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ const WOQLQuery = require('./woqlCore')
55
* Library Functions
66
**/
77
function WOQLLibrary() {
8-
//this.mode = mode || 'query'
9-
//this.user_variables = []
10-
//this.user_values = []
11-
//this.default_variables = []
12-
//this.parameters = []
138
this.default_schema_resource = 'schema/main'
149
this.default_commit_resource = '_commits'
1510
this.default_meta_resource = '_meta'
@@ -22,7 +17,7 @@ function WOQLLibrary() {
2217
* (if present, new branches have no commits)
2318
*/
2419
WOQLLibrary.prototype.branches = function(){//values, variables, cresource) {
25-
const woql = new WOQLQuery().triple("v:Branch","rdf:type","@schema:Branch").
20+
const woql = new WOQLQuery().using("_commits").triple("v:Branch","rdf:type","@schema:Branch").
2621
triple("v:Branch","@schema:name","v:Name").
2722
opt().triple("v:Branch","@schema:head","v:Head").
2823
triple("v:Head","@schema:identifier","v:commit_identifier").
@@ -81,8 +76,12 @@ WOQLLibrary.prototype.previousCommits = function(commit_id,limit=10){
8176
*/
8277
WOQLLibrary.prototype.first_commit = function() {
8378
let noparent = new WOQLQuery()
84-
.using('_commits')
85-
.and(
79+
.using('_commits').select("v:Any Commit IRI")
80+
.and(
81+
new WOQLQuery().triple("v:Branch", "name", new WOQLQuery().string('main'))
82+
.triple("v:Branch", "head", "v:Active Commit ID")
83+
.path("v:Active Commit ID", "parent*", "v:Any Commit IRI", "v:Path"),
84+
8685
new WOQLQuery().triple(
8786
'v:Any Commit IRI',
8887
'@schema:identifier',

lib/woql.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ WOQL.json = function(JSON_LD) {
10791079
* //return the commits of a specific branch starting from the head
10801080
* //if a timestamp is given, gets the commits before the specified timestamp
10811081
* const query = WOQL.lib().commits('main',10,1630683082.9278786)
1082+
*
1083+
* //return the branches list with the timestamp and commits id
1084+
* const query = WOQL.lib().branches()
10821085
*/
10831086
WOQL.lib = function() {
10841087
return new WOQLQuery().lib()
@@ -1220,17 +1223,4 @@ WOQL.link = function(subject, predicate, object, graphRef) {
12201223
}
12211224

12221225

1223-
1224-
/**
1225-
* Called to load Terminus Predefined libraries:
1226-
* @param {*} libs xsd,xdd,box
1227-
* @param {*} parent
1228-
* @param {*} graph --graph ref
1229-
* @param {*} prefix --prefix you want use
1230-
*/
1231-
WOQL.libs = function(libs, parent, graph, prefix) {
1232-
return new WOQLQuery().libs(libs, parent, graph, prefix)
1233-
}
1234-
1235-
12361226
module.exports = WOQL

lib/woqlClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ function WOQLClient(serverUrl, params) {
4545
this.databaseList = []
4646
}
4747

48+
WOQLClient.prototype.setApiKey = function (accessToken){
49+
this.localAuth({key: accessToken, type: "jwt"})
50+
}
51+
4852
/**
4953
* add extra headers to your request
5054
* @param {object} customHeaders

query.json

Lines changed: 112 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,167 +2,137 @@
22
"@type": "Using",
33
"collection": "_commits",
44
"query": {
5-
"@type": "Limit",
6-
"limit": 20,
5+
"@type": "Select",
6+
"variables": [
7+
"Any Commit IRI"
8+
],
79
"query": {
8-
"@type": "Select",
9-
"variables": [
10-
"Parent ID",
11-
"Commit ID",
12-
"Time",
13-
"Author",
14-
"Branch ID",
15-
"Message"
16-
],
17-
"query": {
18-
"@type": "And",
19-
"and": [
20-
{
21-
"@type": "Triple",
22-
"subject": {
23-
"@type": "NodeValue",
24-
"variable": "Branch"
25-
},
26-
"predicate": {
27-
"@type": "NodeValue",
28-
"node": "name"
29-
},
30-
"object": {
31-
"@type": "Value",
32-
"data": {
33-
"@type": "xsd:string",
34-
"@value": "main"
35-
}
36-
}
10+
"@type": "And",
11+
"and": [
12+
{
13+
"@type": "Triple",
14+
"subject": {
15+
"@type": "NodeValue",
16+
"variable": "Branch"
3717
},
38-
{
39-
"@type": "And",
40-
"and": [
41-
{
42-
"@type": "Triple",
43-
"subject": {
44-
"@type": "NodeValue",
45-
"variable": "Branch"
46-
},
47-
"predicate": {
48-
"@type": "NodeValue",
49-
"node": "head"
50-
},
51-
"object": {
52-
"@type": "Value",
53-
"variable": "Active Commit ID"
54-
}
18+
"predicate": {
19+
"@type": "NodeValue",
20+
"node": "name"
21+
},
22+
"object": {
23+
"@type": "Value",
24+
"data": {
25+
"@type": "xsd:string",
26+
"@value": "main"
27+
}
28+
}
29+
},
30+
{
31+
"@type": "And",
32+
"and": [
33+
{
34+
"@type": "Triple",
35+
"subject": {
36+
"@type": "NodeValue",
37+
"variable": "Branch"
5538
},
56-
{
57-
"@type": "And",
58-
"and": [
59-
{
60-
"@type": "Path",
61-
"subject": {
62-
"@type": "NodeValue",
63-
"variable": "Active Commit ID"
64-
},
65-
"pattern": {
66-
"@type": "PathStar",
67-
"star": {
68-
"@type": "PathPredicate",
69-
"predicate": "parent"
70-
}
71-
},
72-
"object": {
73-
"@type": "Value",
74-
"variable": "Parent"
75-
},
76-
"path": {
77-
"@type": "Value",
78-
"variable": "Path"
79-
}
80-
},
81-
{
82-
"@type": "Triple",
83-
"subject": {
84-
"@type": "NodeValue",
85-
"variable": "Parent"
86-
},
87-
"predicate": {
88-
"@type": "NodeValue",
89-
"node": "timestamp"
90-
},
91-
"object": {
92-
"@type": "Value",
93-
"variable": "Time"
94-
}
95-
}
96-
]
39+
"predicate": {
40+
"@type": "NodeValue",
41+
"node": "head"
42+
},
43+
"object": {
44+
"@type": "Value",
45+
"variable": "Active Commit ID"
9746
}
98-
]
99-
},
100-
{
101-
"@type": "Less",
102-
"left": {
103-
"@type": "DataValue",
104-
"variable": "Time"
10547
},
106-
"right": {
107-
"@type": "DataValue",
108-
"data": {
109-
"@type": "xsd:decimal",
110-
"@value": 1630683082.9278786
48+
{
49+
"@type": "Path",
50+
"subject": {
51+
"@type": "NodeValue",
52+
"variable": "Active Commit ID"
53+
},
54+
"pattern": {
55+
"@type": "PathStar",
56+
"star": {
57+
"@type": "PathPredicate",
58+
"predicate": "parent"
59+
}
60+
},
61+
"object": {
62+
"@type": "Value",
63+
"variable": "Any Commit IRI"
64+
},
65+
"path": {
66+
"@type": "Value",
67+
"variable": "Path"
11168
}
11269
}
70+
]
71+
},
72+
{
73+
"@type": "Triple",
74+
"subject": {
75+
"@type": "NodeValue",
76+
"variable": "Any Commit IRI"
77+
},
78+
"predicate": {
79+
"@type": "NodeValue",
80+
"node": "@schema:identifier"
11381
},
114-
{
82+
"object": {
83+
"@type": "Value",
84+
"variable": "Commit ID"
85+
}
86+
},
87+
{
88+
"@type": "Triple",
89+
"subject": {
90+
"@type": "NodeValue",
91+
"variable": "Any Commit IRI"
92+
},
93+
"predicate": {
94+
"@type": "NodeValue",
95+
"node": "@schema:author"
96+
},
97+
"object": {
98+
"@type": "Value",
99+
"variable": "Author"
100+
}
101+
},
102+
{
103+
"@type": "Triple",
104+
"subject": {
105+
"@type": "NodeValue",
106+
"variable": "Any Commit IRI"
107+
},
108+
"predicate": {
109+
"@type": "NodeValue",
110+
"node": "@schema:message"
111+
},
112+
"object": {
113+
"@type": "Value",
114+
"variable": "Message"
115+
}
116+
},
117+
{
118+
"@type": "Not",
119+
"query": {
115120
"@type": "Triple",
116121
"subject": {
117122
"@type": "NodeValue",
118-
"variable": "Parent"
123+
"variable": "Any Commit IRI"
119124
},
120125
"predicate": {
121126
"@type": "NodeValue",
122-
"node": "identifier"
127+
"node": "@schema:parent"
123128
},
124129
"object": {
125130
"@type": "Value",
126-
"variable": "Commit ID"
131+
"variable": "Parent IRI"
127132
}
128-
},
129-
{
130-
"@type": "And",
131-
"and": [
132-
{
133-
"@type": "Triple",
134-
"subject": {
135-
"@type": "NodeValue",
136-
"variable": "Parent"
137-
},
138-
"predicate": {
139-
"@type": "NodeValue",
140-
"node": "author"
141-
},
142-
"object": {
143-
"@type": "Value",
144-
"variable": "Author"
145-
}
146-
},
147-
{
148-
"@type": "Triple",
149-
"subject": {
150-
"@type": "NodeValue",
151-
"variable": "Parent"
152-
},
153-
"predicate": {
154-
"@type": "NodeValue",
155-
"node": "message"
156-
},
157-
"object": {
158-
"@type": "Value",
159-
"variable": "Message"
160-
}
161-
}
162-
]
163133
}
164-
]
165-
}
134+
}
135+
]
166136
}
167137
}
168138
}

0 commit comments

Comments
 (0)