Skip to content

Commit c69e857

Browse files
committed
review docs
1 parent 1827b98 commit c69e857

File tree

5 files changed

+195
-72
lines changed

5 files changed

+195
-72
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
- [nuke](api/woql.js?id=nuke)
146146
- [query](api/woql.js?id=query)
147147
- [json](api/woql.js?id=json)
148+
- [lib](api/woql.js?id=lib)
148149
- [string](api/woql.js?id=string)
149150
- [literal](api/woql.js?id=literal)
150151
- [iri](api/woql.js?id=iri)

docs/api/woql.js.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,21 @@ json version of query for passing to api
12041204
| [JSON_LD] | <code>object</code> | JSON-LD woql document encoding a query |
12051205

12061206

1207+
### lib
1208+
#### WOQL.lib() ⇒ <code>WOQLQuery</code>
1209+
get the predefined library query
1210+
1211+
**Returns**: <code>WOQLQuery</code> - WOQLQuery object
1212+
**Example**
1213+
```js
1214+
//get commits older than the specified commit id
1215+
const query = WOQL.lib().previousCommits('m8vpxewh2aovfauebfkbzwmj4qwr5lb')
1216+
1217+
//return the commits of a specific branch starting from the head
1218+
//if a timestamp is given, gets the commits before the specified timestamp
1219+
const query = WOQL.lib().commits('main',10,1630683082.9278786)
1220+
```
1221+
12071222
### string
12081223
#### WOQL.string(val) ⇒ <code>object</code>
12091224
Generates explicitly a JSON-LD string literal from the input

lib/query/woqlLibrary.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const WOQLQuery = require('./woqlCore')
44
/**
55
* Library Functions
66
**/
7-
function WOQLLibrary(mode) {
8-
this.mode = mode || 'query'
9-
this.user_variables = []
10-
this.user_values = []
11-
this.default_variables = []
12-
this.parameters = []
7+
function WOQLLibrary() {
8+
//this.mode = mode || 'query'
9+
//this.user_variables = []
10+
//this.user_values = []
11+
//this.default_variables = []
12+
//this.parameters = []
1313
this.default_schema_resource = 'schema/main'
1414
this.default_commit_resource = '_commits'
1515
this.default_meta_resource = '_meta'
@@ -32,13 +32,13 @@ WOQLLibrary.prototype.branches = function(){//values, variables, cresource) {
3232

3333
/**
3434
* get all the commits of a specific branch
35-
* if a timestamp is given, gets all the commits before the given timestamp
35+
* if a timestamp is given, gets all the commits before the specified timestamp
3636
* @param {string} branch - the branch name
3737
* @param {number} limit - the max number of result
3838
* @param {number} timestamp - Unix timestamp in seconds
3939
*/
4040

41-
WOQLLibrary.prototype.commits = function (branch="main",limit=10,timestamp=null){
41+
WOQLLibrary.prototype.commits = function (branch="main",limit=10,timestamp=0){
4242
const woql = new WOQLQuery().using("_commits").limit(limit)
4343
.select("v:Parent ID","v:Commit ID","v:Time","v:Author", "v:Branch ID","v:Message")
4444

lib/woql.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,19 @@ WOQL.json = function(JSON_LD) {
10691069
return new WOQLQuery().json(JSON_LD)
10701070
}
10711071

1072-
WOQL.lib = function(mode) {
1073-
return new WOQLQuery().lib(mode)
1072+
/**
1073+
* get the predefined library query
1074+
* @returns {WOQLQuery} WOQLQuery object
1075+
* @example
1076+
* //get commits older than the specified commit id
1077+
* const query = WOQL.lib().previousCommits('m8vpxewh2aovfauebfkbzwmj4qwr5lb')
1078+
*
1079+
* //return the commits of a specific branch starting from the head
1080+
* //if a timestamp is given, gets the commits before the specified timestamp
1081+
* const query = WOQL.lib().commits('main',10,1630683082.9278786)
1082+
*/
1083+
WOQL.lib = function() {
1084+
return new WOQLQuery().lib()
10741085
}
10751086

10761087
/**

query.json

Lines changed: 158 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,167 @@
22
"@type": "Using",
33
"collection": "_commits",
44
"query": {
5-
"@type": "And",
6-
"and": [
7-
{
8-
"@type": "Triple",
9-
"subject": {
10-
"@type": "NodeValue",
11-
"variable": "Any Commit IRI"
12-
},
13-
"predicate": {
14-
"@type": "NodeValue",
15-
"node": "@schema:identifier"
16-
},
17-
"object": {
18-
"@type": "Value",
19-
"variable": "Commit ID"
20-
}
21-
},
22-
{
23-
"@type": "Triple",
24-
"subject": {
25-
"@type": "NodeValue",
26-
"variable": "Any Commit IRI"
27-
},
28-
"predicate": {
29-
"@type": "NodeValue",
30-
"node": "@schema:author"
31-
},
32-
"object": {
33-
"@type": "Value",
34-
"variable": "Author"
35-
}
36-
},
37-
{
38-
"@type": "Triple",
39-
"subject": {
40-
"@type": "NodeValue",
41-
"variable": "Any Commit IRI"
42-
},
43-
"predicate": {
44-
"@type": "NodeValue",
45-
"node": "@schema:message"
46-
},
47-
"object": {
48-
"@type": "Value",
49-
"variable": "Message"
50-
}
51-
},
52-
{
53-
"@type": "Not",
54-
"query": {
55-
"@type": "Triple",
56-
"subject": {
57-
"@type": "NodeValue",
58-
"variable": "Any Commit IRI"
5+
"@type": "Limit",
6+
"limit": 20,
7+
"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+
}
5937
},
60-
"predicate": {
61-
"@type": "NodeValue",
62-
"node": "@schema:parent"
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+
}
55+
},
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+
]
97+
}
98+
]
6399
},
64-
"object": {
65-
"@type": "Value",
66-
"variable": "Parent IRI"
100+
{
101+
"@type": "Less",
102+
"left": {
103+
"@type": "DataValue",
104+
"variable": "Time"
105+
},
106+
"right": {
107+
"@type": "DataValue",
108+
"data": {
109+
"@type": "xsd:decimal",
110+
"@value": 1630683082.9278786
111+
}
112+
}
113+
},
114+
{
115+
"@type": "Triple",
116+
"subject": {
117+
"@type": "NodeValue",
118+
"variable": "Parent"
119+
},
120+
"predicate": {
121+
"@type": "NodeValue",
122+
"node": "identifier"
123+
},
124+
"object": {
125+
"@type": "Value",
126+
"variable": "Commit ID"
127+
}
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+
]
67163
}
68-
}
164+
]
69165
}
70-
]
166+
}
71167
}
72168
}

0 commit comments

Comments
 (0)