Skip to content

Commit 403e17c

Browse files
committed
Merge branch 'canary' into rc
2 parents 93b7451 + 94ce061 commit 403e17c

File tree

11 files changed

+212
-87
lines changed

11 files changed

+212
-87
lines changed

.github/workflows/production.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build and release on npm
2+
on:
3+
create:
4+
tags:
5+
- v*
6+
7+
jobs:
8+
setup-build-publish-deploy:
9+
name: Setup, Build, Publish, and Deploy
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
- name: Use Node.js ${{ matrix.node-version }}
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: 14
18+
registry-url: 'https://registry.npmjs.org'
19+
- run: npm install
20+
- run: npm run build
21+
- run: npm publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.travis.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/query/woqlLibrary.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,28 @@ WOQLLibrary.prototype.classesAndChoices = function(values, variables, schema_res
117117

118118

119119
let qpattern = new WOQLQuery().and(
120-
this.classes(values, variables, schema_resource),
121-
new WOQLQuery().opt().select("v:Choices").from("schema/main")
122-
.group_by("v:Class ID", ["v:choice id", "v:choice label", "v:choice description"], "v:Choices")
123-
.and(
124-
new WOQLQuery().select("v:choice id").distinct("v:choice id")
125-
.triple("v:Class ID", "owl:oneOf", "v:Choice")
126-
.path("v:Choice", "rdf:rest+", "v:Entry", "v:Path")
127-
.or(
120+
this.classes(values, variables, schema_resource),
121+
new WOQLQuery().opt().select("v:Choices").from("schema/main")
122+
.group_by("v:Class ID", ["v:choice id", "v:choice label", "v:choice description"], "v:Choices")
123+
.and(
124+
new WOQLQuery().select("v:choice id").distinct("v:choice id")
125+
.triple("v:Class ID", "owl:oneOf", "v:Choice")
126+
.path("v:Choice", "rdf:rest+", "v:Entry", "v:Path")
127+
.or(
128128
new WOQLQuery().triple("v:Choice", "rdf:first", "v:choice id"),
129129
new WOQLQuery().triple("v:Entry", "rdf:first", "v:choice id")
130-
),
131-
new WOQLQuery().triple("v:choice id", "label", "v:choice label")
132-
.triple("v:choice id", "comment", "v:choice description")
133-
)
134-
)
130+
),
131+
new WOQLQuery().triple("v:choice id", "label", "v:choice label"),
132+
new WOQLQuery().or(
133+
new WOQLQuery().and(
134+
new WOQLQuery().not().triple("v:choice id", "comment", "v:any_choice"),
135+
new WOQLQuery().eq("v:choice description", "v:choice label")
136+
),
137+
new WOQLQuery().triple("v:choice id", "comment", "v:choice description"),
138+
139+
)
140+
)
141+
)
135142

136143
return this._add_constraints(qpattern, values)
137144
}

lib/query/woqlSchema.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,47 @@ WOQLQuery.prototype._nuke_schema_element = function(elvar, graph) {
188188
/**
189189
* Experimental / Unstable API
190190
*/
191+
WOQLQuery.prototype.genEnum = function(prop, cls, clslabel, clsdesc, graph) {
192+
clslabel = clslabel || cls
193+
graph = this._sg(graph)
194+
195+
let add_class = new WOQLQuery()
196+
.add_quad(cls, "type", "owl:Class", graph)
197+
.add_quad(cls, "label", clslabel, graph)
198+
if(clsdesc){
199+
add_class.add_quad(cls, "comment", clsdesc, graph)
200+
}
201+
202+
this.and(
203+
new WOQLQuery().select("v:PV").distinct("v:PV").triple("v:A", prop, "v:PV"),
204+
new WOQLQuery().idgen(cls, ["v:PV"], "v:ChoiceID"),
205+
add_class,
206+
new WOQLQuery().add_quad("v:ChoiceID", "type", cls, graph)
207+
.add_quad("v:ChoiceID", "label", "v:PV", graph)
208+
)
209+
return this
210+
}
211+
212+
WOQLQuery.prototype.finishEnum = function(client, cls, graph) {
213+
graph = this._sg(graph)
214+
let q = new WOQLQuery().quad("v:ChoiceID", "type", cls, graph)
215+
return client.query(q).then((results) => {
216+
let ids = []
217+
for(var i = 0; i< results.bindings.length; i++){
218+
ids.push(results.bindings[i]["ChoiceID"])
219+
}
220+
return client.query(this._oneOfList(cls, ids, graph))
221+
})
222+
}
223+
224+
WOQLQuery.prototype.makeEnum = function(client, prop, cls, clslabel, clsdesc, graph) {
225+
client.query(new WOQLQuery().genEnum( prop, cls, clslabel, clsdesc, graph))
226+
.then(() => new WOQLQuery().finishEnum(client, cls, graph))
227+
graph = this._sg(graph)
228+
return new WOQLQuery().quad("v:Choice", "type", cls, graph)
229+
}
230+
231+
//makeEnum(client(), "", "scm:DealType", "Deal Type", "The stage of the deal")
191232

192233
/**
193234
* Generates a class representing a choice list - an enumerated list of specific options
@@ -235,6 +276,24 @@ WOQLQuery.prototype.generateChoiceList = function(cls, clslabel, clsdesc, choice
235276
return this.and(...confs, oneof)
236277
}
237278

279+
WOQLQuery.prototype._oneOfList = function(cls, ids, graph) {
280+
var listid = '_:' + (cls.indexOf(':') == -1 ? cls : cls.split(':')[1])
281+
var lastid = listid
282+
graph = this._sg(graph)
283+
let clist = []
284+
for (var i = 0; i < ids.length; i++) {
285+
var nextid = i < ids.length - 1 ? listid + '_' + i : 'rdf:nil'
286+
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:first', new WOQLQuery().iri(ids[i]), graph))
287+
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:rest', new WOQLQuery().iri(nextid), graph))
288+
lastid = nextid
289+
}
290+
return this.and(
291+
new WOQLQuery().add_quad(cls, 'owl:oneOf', new WOQLQuery().iri(listid), graph),
292+
...clist,
293+
)
294+
}
295+
296+
238297
WOQLQuery.prototype.deleteChoiceList = function(classId, graph) {
239298
graph = this._sg(graph)
240299
return new WOQLQuery().and(

lib/viewer/documentFrame.js

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,11 @@ DocumentFrame.prototype.loadData = function(jsonld, cls, classframes){
8383
}
8484
if(cls){
8585
if(!this.document){
86-
alert("Yo")
8786
this.document = new ObjectFrame(cls, jsonld, classframes);
8887
}
8988
else {
90-
alert("Yo2")
9189
this.document.loadJSONLDDocument(jsonld);
9290
}
93-
alert(this.document.subjid)
9491
}
9592
else {
9693
console.log("Missing Class" + " " + "Failed to add dataframes due to missing class");
@@ -130,7 +127,7 @@ DocumentFrame.prototype.filterFrame = function(loadRenderer){
130127
if(typeof rule.render() != "undefined"){
131128
frame.render = rule.render();
132129
}
133-
else {
130+
/* else {
134131
if(rule.renderer()){
135132
var renderer = loadRenderer(rule.renderer(), frame, rule.args);
136133
}
@@ -139,16 +136,59 @@ DocumentFrame.prototype.filterFrame = function(loadRenderer){
139136
return renderer(fframe);
140137
}
141138
}
142-
}
139+
}*/
143140
if(rule.compare()){
144141
frame.compare = rule.compare();
145142
}
143+
if(rule.errors()){
144+
frame.errors = frame.errors ? frame.errors.concat(rule.errors()) : rule.errors();
145+
}
146+
else if(rule.errors() === false) delete frame.errors
146147
}
147148
this.applyRules(false, false, myfilt);
148149
}
149150

151+
DocumentFrame.prototype.setErrors = function(errors, frameconf){
152+
this.clearErrors(frameconf)
153+
for(var i = 0; i<errors.length; i++){
154+
addRuleForVio(frameconf, errors[i])
155+
}
156+
var myfilt = function(frame, rule){
157+
if(rule.errors()){
158+
frame.errors = frame.errors ? frame.errors.concat(rule.errors()) : rule.errors();
159+
}
160+
}
161+
this.applyRules(false, frameconf, myfilt);
162+
}
163+
164+
DocumentFrame.prototype.clearErrors = function(frameconf){
165+
frameconf.all()
166+
var myfilt = function(frame, rule){
167+
if(frame.errors) delete(frame.errors)
168+
}
169+
this.applyRules(false, frameconf, myfilt)
170+
frameconf.rules = []
171+
}
172+
173+
function addRuleForVio(docview, error){
174+
let prop = (error['vio:property'] ? error['vio:property']["@value"] : false)
175+
let subj = (error['vio:subject'] ? error['vio:subject']["@value"] : false)
176+
let msg = (error['vio:message'] ? error['vio:message']["@value"] : false)
177+
let val = (error['api:value'] ? error['api:value'] : false)
178+
if(val && val[0] == '"' && val[val.length-1] == '"')
179+
val = val.substring(1, val.length-1)
180+
let type = (error['api:type'] ? error['api:type'] : false)
181+
if(type && val){ //api:BadCast
182+
docview.data().value(val).type(type).errors([error])
183+
}
184+
if(prop && subj){//untypedInstanceViolation
185+
let shrt = FrameHelper.shorten(subj)
186+
if(shrt.substring(0, 5) == "woql:") shrt == shrt.substring(5)
187+
docview.data().property(prop).value(shrt, subj).errors([error])
188+
}
189+
}
150190

151-
/*
191+
/*"
152192
* adds render and compare functions to object frames
153193
*/
154194
DocumentFrame.prototype.applyRules = function(doc, config, mymatch){
@@ -159,7 +199,7 @@ DocumentFrame.prototype.applyRules = function(doc, config, mymatch){
159199
config.setFrameDisplayOptions(frame, rule);
160200
if(mymatch) mymatch(frame, rule);
161201
};
162-
doc.filter(config.rules, onmatch);
202+
doc.mfilter(config.rules, onmatch);
163203
}
164204

165205
module.exports = DocumentFrame ;

lib/viewer/frameConfig.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ DocumentRule.prototype.header = function(m){
237237
return this;
238238
}
239239

240+
241+
DocumentRule.prototype.errors = function(errs){
242+
if(!errs) return this.rule.errors;
243+
this.rule.errors = errs;
244+
return this;
245+
}
246+
247+
240248
DocumentRule.prototype.headerStyle = function(m){
241249
if(!m) return this.rule.headerStyle;
242250
this.rule.headerStyle = m;
@@ -444,7 +452,10 @@ DocumentRule.prototype.prettyPrint = function(){
444452
if(typeof this.args() != "undefined"){
445453
str += ".args(" + JSON.stringify(this.args()) + ")";
446454
}
447-
if(typeof this.showEmpty() != "undefined"){
455+
if(typeof this.errors() != "undefined"){
456+
str += ".errors(" + JSON.stringify(this.errors()) + ")";
457+
}
458+
if(typeof this.showEmpty() != "undefined"){
448459
str += ".showEmpty(" + this.show_empty() + ")";
449460
}
450461
if(typeof this.dataviewer() != "undefined"){

lib/viewer/frameRule.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ FrameRule.prototype.range = function(...prop){
102102
return this;
103103
}
104104

105+
/**
106+
* Specifies that only one from among the list of range types will match
107+
*/
108+
FrameRule.prototype.value = function(...prop){
109+
if(!prop || prop.length == 0) return this.pattern.value;
110+
this.pattern.value = prop;
111+
return this;
112+
}
113+
114+
105115
/**
106116
* Specifies that only frames of the specified depth will match the rule
107117
*/
@@ -404,8 +414,8 @@ FramePattern.prototype.checkProperty = function (rtype, frame) {
404414
*/
405415
FramePattern.prototype.checkType = function (rtype, frame) {
406416
if(rtype == "object") var vs = frame.subjectClass();
407-
else var vs = frame.range();
408-
if(!Array.isArray(this.type)) this.type = [this.type];
417+
else var vs = typeof frame.range == "function" ? frame.range() : frame.range;
418+
if(!Array.isArray(this.type)) this.type = [this.type];
409419
if(this.type.indexOf(vs) === -1) return false;
410420
return true;
411421
}
@@ -423,7 +433,7 @@ FramePattern.prototype.checkValue = function (rtype, frame) {
423433
if (typeof this.value !== 'object' || !this.value.length) this.value = [this.value];
424434
for (let i = 0; i < this.value.length; i++) {
425435
if (rtype == 'data') {
426-
if (this.valuesMatch(frame.value(), this.value[i])) {
436+
if (this.valuesMatch(frame.get(), this.value[i])) {
427437
return true;
428438
}
429439
} else if (rtype == 'property') {

0 commit comments

Comments
 (0)