• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terminusdb / terminusdb-client-js / 6914634008

18 Nov 2023 02:57PM UTC coverage: 30.12% (+0.09%) from 30.031%
6914634008

push

github

web-flow
Upgraded axios (#293)

870 of 4624 branches covered (0.0%)

Branch coverage included in aggregate %.

2480 of 6498 relevant lines covered (38.17%)

4.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.73
/lib/query/woqlLibrary.js
1
/// /@ts-check
2
// we can not import woqlBuilder because woqlBuilder import WOQLLibrary
3
const WOQLQuery = require('./woqlBuilder');
1✔
4

5
/**
6
 * @license Apache Version 2
7
 * @module WOQLLibrary
8
 * @constructor WOQLLibrary
9
 * @description Library Functions to manage the commits graph
10
 * @example
11
 *  const woqlLib = WOQLLibrary()
12
 *  woqlLib.branches()
13
 *
14
 *  //or you can call this functions using WOQL Class
15
 *  WOQL.lib().branches()
16
 * */
17
class WOQLLibrary {
1✔
18
  default_schema_resource = 'schema/main';
×
19

20
  default_commit_resource = '_commits';
×
21

22
  default_meta_resource = '_meta';
×
23

24
  masterdb_resource = '_system';
×
25

26
  empty = '';
27
}
28

29
/**
30
 * General Pattern 4: Retrieves Branches, Their ID, Head Commit ID, Head Commit Time
31
 * (if present, new branches have no commits)
32
 */
33
WOQLLibrary.prototype.branches = function () { // values, variables, cresource) {
1✔
34
  const woql = new WOQLQuery().using('_commits').triple('v:Branch', 'rdf:type', '@schema:Branch')
×
35
    .triple('v:Branch', '@schema:name', 'v:Name')
36
    .opt()
37
    .triple('v:Branch', '@schema:head', 'v:Head')
38
    .triple('v:Head', '@schema:identifier', 'v:commit_identifier')
39
    .triple('v:Head', '@schema:timestamp', 'v:Timestamp');
40
  return woql;
×
41
};
42

43
/**
44
 * get all the commits of a specific branch
45
 * if a timestamp is given, gets all the commits before the specified timestamp
46
 * @param {string} [branch] - the branch name
47
 * @param {number} [limit] - the max number of result
48
 * @param {number} [start] - the start of the pagination
49
 * @param {number} [timestamp] - Unix timestamp in seconds
50
 */
51

52
WOQLLibrary.prototype.commits = function (branch = 'main', limit = 0, start = 0, timestamp = 0) {
1!
53
  const woql = new WOQLQuery().using('_commits');
×
54
  if (limit) woql.limit(limit);
×
55
  if (start) woql.start(start);
×
56
  woql.select('v:Parent ID', 'v:Commit ID', 'v:Time', 'v:Author', 'v:Branch ID', 'v:Message');
×
57

58
  const andArr = [new WOQLQuery().triple('v:Branch', 'name', new WOQLQuery().string(branch))
×
59
    .triple('v:Branch', 'head', 'v:Active Commit ID')
60
    .path('v:Active Commit ID', 'parent*', 'v:Parent', 'v:Path')
61
    .triple('v:Parent', 'timestamp', 'v:Time')];
62
  if (timestamp) {
×
63
    andArr.push(new WOQLQuery().less('v:Time', timestamp));
×
64
  }
65
  andArr.push(new WOQLQuery().triple('v:Parent', 'identifier', 'v:Commit ID')
×
66
    .triple('v:Parent', 'author', 'v:Author')
67
    .triple('v:Parent', 'message', 'v:Message')
68
    .opt()
69
    .triple('v:Parent', 'parent', 'v:Parent ID'));
70
  return woql.and(...andArr);
×
71
};
72

73
/**
74
*get commits older than the specified commit id
75
* @param {string} [commit_id] - the commit id
76
* @param {number} [limit] - the max number of result
77
*/
78
// eslint-disable-next-line camelcase
79
WOQLLibrary.prototype.previousCommits = function (commit_id, limit = 10) {
1!
80
  return new WOQLQuery().using('_commits').limit(limit).select('v:Parent ID', 'v:Message', 'v:Commit ID', 'v:Time', 'v:Author')
×
81
    .and(
82
      new WOQLQuery().and(
83
        new WOQLQuery().triple('v:Active Commit ID', '@schema:identifier', new WOQLQuery().string(commit_id)),
84
        new WOQLQuery().path('v:Active Commit ID', '@schema:parent+', 'v:Parent', 'v:Path'),
85
        new WOQLQuery().triple('v:Parent', '@schema:identifier', 'v:Commit ID'),
86
        new WOQLQuery().triple('v:Parent', '@schema:timestamp', 'v:Time'),
87
        new WOQLQuery().triple('v:Parent', '@schema:author', 'v:Author'),
88
        new WOQLQuery().triple('v:Parent', '@schema:message', 'v:Message'),
89
        new WOQLQuery().triple('v:Parent', '@schema:parent', 'v:Parent ID'),
90
        new WOQLQuery().opt().triple('v:Parent', 'parent', 'v:Parent ID'),
91
      ),
92
    );
93
};
94

95
/**
96
 * Finds the id of the very first commit in a database's history
97
 *
98
 * This is useful for finding information about when, by who and why the database was created
99
 * The first commit is the only commit in the database that does not have a parent commit
100
 *
101
 */
102
WOQLLibrary.prototype.first_commit = function () {
1✔
103
  const noparent = new WOQLQuery()
×
104
    .using('_commits').select('v:Any Commit IRI')
105
    .and(
106
      new WOQLQuery().triple('v:Branch', 'name', new WOQLQuery().string('main'))
107
        .triple('v:Branch', 'head', 'v:Active Commit ID')
108
        .path('v:Active Commit ID', 'parent*', 'v:Any Commit IRI', 'v:Path'),
109

110
      new WOQLQuery().triple(
111
        'v:Any Commit IRI',
112
        '@schema:identifier',
113
        'v:Commit ID',
114
      ),
115
      new WOQLQuery().triple(
116
        'v:Any Commit IRI',
117
        '@schema:author',
118
        'v:Author',
119
      ),
120
      new WOQLQuery().triple(
121
        'v:Any Commit IRI',
122
        '@schema:message',
123
        'v:Message',
124
      ),
125
      new WOQLQuery()
126
        .not()
127
        .triple(
128
          'v:Any Commit IRI',
129
          '@schema:parent',
130
          'v:Parent IRI',
131
        ),
132

133
    );
134
  return noparent;
×
135
};
136

137
module.exports = WOQLLibrary;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc