@kitelev/exocortex-cli 15.32.7 → 15.32.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v15.32.7
2
+ // @kitelev/exocortex-cli v15.32.8
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -312,7 +312,7 @@ ${r})`;case"extend":return`${r}Extend (?${e.variable} = ${this.expressionToStrin
312
312
  ${this.toString(e.input,t+1)}
313
313
  ${r})`;case"subquery":return`${r}Subquery(
314
314
  ${this.toString(e.query,t+1)}
315
- ${r})`;default:return`${r}Unknown(${e.type})`}}tripleToString(e){return`${this.elementToString(e.subject)} ${this.predicateToString(e.predicate)} ${this.elementToString(e.object)}`}predicateToString(e){return this.isPropertyPath(e)?this.propertyPathToString(e):this.elementToString(e)}isPropertyPath(e){return e.type==="path"}propertyPathToString(e){let t=e.items.map(r=>r.type==="path"?`(${this.propertyPathToString(r)})`:`<${r.value}>`);switch(e.pathType){case"/":return t.join("/");case"|":return t.join("|");case"^":return`^${t[0]}`;case"+":return`${t[0]}+`;case"*":return`${t[0]}*`;case"?":return`${t[0]}?`}}elementToString(e){switch(e.type){case"variable":return`?${e.value}`;case"iri":return`<${e.value}>`;case"literal":let t=`"${e.value}"`;return e.language&&(t+=`@${e.language}`),e.datatype&&(t+=`^^<${e.datatype}>`),t;case"blank":return`_:${e.value}`;default:return String(e)}}expressionToString(e){switch(e.type){case"variable":return`?${e.name}`;case"literal":return typeof e.value=="string"?`"${e.value}"`:String(e.value);case"comparison":return`(${this.expressionToString(e.left)} ${e.operator} ${this.expressionToString(e.right)})`;case"logical":return e.operator==="!"?`!(${this.expressionToString(e.operands[0])})`:`(${e.operands.map(t=>this.expressionToString(t)).join(` ${e.operator} `)})`;case"arithmetic":return`(${this.expressionToString(e.left)} ${e.operator} ${this.expressionToString(e.right)})`;case"function":return`${e.function}(${e.args.map(t=>this.expressionToString(t)).join(", ")})`;case"exists":return`${e.negated?"NOT EXISTS":"EXISTS"} { ${this.toString(e.pattern,0)} }`;default:return"unknown"}}toJSON(e){return JSON.stringify(e,null,2)}};gh.AlgebraSerializer=My});var es=v(yh=>{"use strict";Object.defineProperty(yh,"__esModule",{value:!0});yh.SolutionMapping=void 0;var Aw=mt(),Cw=We(),Iw=kt(),jy=class n{static{o(this,"SolutionMapping")}constructor(e){this.bindings=e?new Map(e):new Map}get(e){return this.bindings.get(e)}set(e,t){this.bindings.set(e,t)}has(e){return this.bindings.has(e)}variables(){return Array.from(this.bindings.keys())}getBindings(){return new Map(this.bindings)}isCompatibleWith(e){for(let[t,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof Aw.Literal&&t instanceof Aw.Literal?e.equals(t):e instanceof Cw.IRI&&t instanceof Cw.IRI?e.value===t.value:e instanceof Iw.BlankNode&&t instanceof Iw.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,r]of this.bindings.entries())e[t]=r.toString();return e}size(){return this.bindings.size}};yh.SolutionMapping=jy});var Ow=v(wo=>{"use strict";Object.defineProperty(wo,"__esModule",{value:!0});wo.PropertyPathExecutor=wo.PropertyPathExecutorError=void 0;var oL=es(),vh=We(),Pw=kt(),sl=class extends Error{static{o(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};wo.PropertyPathExecutorError=sl;var $y=class{static{o(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){let i=await this.resolveElement(e),s=this.isVariable(r)?null:await this.resolveElement(r);for(let a of i){let c=await this.evaluatePath(a,t,s);for(let l of c){let u=new oL.SolutionMapping;this.isVariable(e)&&u.set(e.value,a),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new sl("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let a=t.merge(s);a!==null&&(yield a)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let a=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,a,c?r:null);for(let h of f)l.add(h)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,r){let i=new Set;for(let s of t){let a=await this.evaluatePathItem(e,s,r);for(let c of a)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new vh.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&a.add(c.subject);return a}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){let i=new Set,s=new Set,a=[{node:e,depth:0}];for(;a.length>0;){let{node:c,depth:l}=a.shift();if(l>=this.MAX_DEPTH)continue;let u=await this.evaluatePathItem(c,t,null);for(let f of u){let h=this.nodeToKey(f);(r===null||this.nodeInSet(f,r))&&s.add(f),i.has(h)||(i.add(h),a.push({node:f,depth:l+1}))}}return s}async evaluateZeroOrMorePath(e,t,r){let i=await this.evaluateOneOrMorePath(e,t,r);return(r===null||this.nodeInSet(e,r))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,r){let i=new Set;(r===null||this.nodeInSet(e,r))&&i.add(e);let s=await this.evaluatePathItem(e,t,r);for(let a of s)i.add(a);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new vh.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&a.add(c.object);return a}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(r=>r.type==="iri"?{type:"path",pathType:"^",items:[r]}:this.invertPath(r))};case"|":return{type:"path",pathType:"|",items:e.items.map(r=>r.type==="iri"?{type:"path",pathType:"^",items:[r]}:this.invertPath(r))};case"+":case"*":case"?":let t=e.items[0].type==="iri"?{type:"path",pathType:"^",items:[e.items[0]]}:this.invertPath(e.items[0]);return{type:"path",pathType:e.pathType,items:[t]}}}async resolveElement(e){if(this.isVariable(e)){let r=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)r.add(s.subject),r.add(s.object);return r}let t=new Set;switch(e.type){case"iri":t.add(new vh.IRI(e.value));break;case"blank":t.add(new Pw.BlankNode(e.value));break;default:throw new sl(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r){if(r instanceof vh.IRI)return{type:"iri",value:r.value};if(r instanceof Pw.BlankNode)return{type:"blank",value:r.id}}}return e}isVariable(e){return e.type==="variable"}isPropertyPath(e){return e.type==="path"}nodeToKey(e){return e.toString()}nodeInSet(e,t){let r=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===r)return!0;return!1}};wo.PropertyPathExecutor=$y});var By=v(Eo=>{"use strict";Object.defineProperty(Eo,"__esModule",{value:!0});Eo.BGPExecutor=Eo.BGPExecutorError=void 0;var _h=es(),Es=We(),Vy=mt(),bh=kt(),Sh=Lc(),cL=Ow(),vr=class extends Error{static{o(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Eo.BGPExecutorError=vr;var Uy=class{static{o(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new cL.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new _h.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let r=1;r<e.triples.length;r++)t=this.joinWithPattern(t,e.triples[r]);for await(let r of t)yield r}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new _h.SolutionMapping;return}let r=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)r=this.joinWithPatternInGraph(r,e.triples[i],t);for await(let i of r)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new vr("Property paths within named graphs are not yet supported");let r=e.predicate,i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(r)?void 0:this.toRDFTermAsPredicate(r),a=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new vr("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,a,t);for(let l of c){let u=new _h.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let a=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(a,r)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){yield*this.propertyPathExecutor.execute(e.subject,e.predicate,e.object);return}let t=e.predicate,r=this.isVariable(e.subject)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),i=this.isVariable(t)?void 0:this.toRDFTermAsPredicate(t),s=this.isVariable(e.object)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object)?void 0:this.toRDFTerm(e.object),a=await this.tripleStore.match(r,i,s);for(let c of a){let l=new _h.SolutionMapping;if(this.isVariable(e.subject))l.set(e.subject.value,c.subject);else if(this.isQuotedTriple(e.subject)){let u=this.matchQuotedTriplePattern(e.subject,c.subject);if(u===null)continue;for(let[f,h]of u.entries())l.set(f,h)}if(this.isVariable(t)&&l.set(t.value,c.predicate),this.isVariable(e.object))l.set(e.object.value,c.object);else if(this.isQuotedTriple(e.object)){let u=this.matchQuotedTriplePattern(e.object,c.object);if(u===null)continue;for(let[f,h]of u.entries())l.set(f,h)}yield l}}hasVariablesInQuotedTriple(e){return!!(this.isVariable(e.subject)||e.predicate.type==="variable"||this.isVariable(e.object)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object))}matchQuotedTriplePattern(e,t){if(!(t instanceof Sh.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof Es.IRI&&e.value===t.value;case"literal":return!(!(t instanceof Vy.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof bh.BlankNode&&e.value===t.id;case"quoted":return t instanceof Sh.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let a of this.matchTriplePattern(s)){let c=i.merge(a);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof Es.IRI?{type:"iri",value:r.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}toRDFTermAsSubject(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"blank":return new bh.BlankNode(e.value);case"literal":throw new vr("Literals cannot appear in subject position");case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vr(`Unknown element type: ${e.type}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new Es.IRI(e.predicate.value):(()=>{throw new vr("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new Sh.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"literal":throw new vr("Literals cannot appear in predicate position");case"blank":throw new vr("Blank nodes cannot appear in predicate position");case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);default:throw new vr(`Unknown element type: ${e.type}`)}}toRDFTerm(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"literal":return new Vy.Literal(e.value,e.datatype?new Es.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new bh.BlankNode(e.value);case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vr(`Unknown element type: ${e.type}`)}}toAlgebraElement(e){if(e instanceof Es.IRI)return{type:"iri",value:e.value};if(e instanceof Vy.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof bh.BlankNode)return{type:"blank",value:e.id};if(e instanceof Sh.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new vr(`Unknown RDF term type: ${e.constructor?.name||"unknown"}`)}toAlgebraQuotedTriple(e){return{type:"quoted",subject:this.toAlgebraElement(e.subject),predicate:{type:"iri",value:e.predicate.value},object:this.toAlgebraElement(e.object)}}};Eo.BGPExecutor=Uy});var Eh=v(wh=>{"use strict";Object.defineProperty(wh,"__esModule",{value:!0});wh.BuiltInFunctions=void 0;var be=We(),R=mt(),Lr=kt(),To=Lc(),qy=Or(),al=class{static{o(this,"BuiltInFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof be.IRI||e instanceof R.Literal?e.value:e instanceof Lr.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof R.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof R.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=this.parseDirectionalLangTag(e),[s,a]=this.parseDirectionalLangTag(t),c=r.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":a&&i!==a?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof R.Literal)return e.datatype?e.datatype:e.language?new be.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new be.IRI("http://www.w3.org/2001/XMLSchema#string");throw new Error("DATATYPE: argument must be a literal")}static bound(e){return e!==void 0}static isIRI(e){return e===void 0?!1:e instanceof be.IRI}static isBlank(e){return e===void 0?!1:e instanceof Lr.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof R.Literal}static isTriple(e){return e===void 0?!1:e instanceof To.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof R.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof R.Literal))return!1;let t=e.datatype?.value;return t?["http://www.w3.org/2001/XMLSchema#integer","http://www.w3.org/2001/XMLSchema#decimal","http://www.w3.org/2001/XMLSchema#float","http://www.w3.org/2001/XMLSchema#double","http://www.w3.org/2001/XMLSchema#nonPositiveInteger","http://www.w3.org/2001/XMLSchema#negativeInteger","http://www.w3.org/2001/XMLSchema#long","http://www.w3.org/2001/XMLSchema#int","http://www.w3.org/2001/XMLSchema#short","http://www.w3.org/2001/XMLSchema#byte","http://www.w3.org/2001/XMLSchema#nonNegativeInteger","http://www.w3.org/2001/XMLSchema#unsignedLong","http://www.w3.org/2001/XMLSchema#unsignedInt","http://www.w3.org/2001/XMLSchema#unsignedShort","http://www.w3.org/2001/XMLSchema#unsignedByte","http://www.w3.org/2001/XMLSchema#positiveInteger"].includes(t):!1}static regex(e,t,r){try{let i=r?r.includes("u")?r:r+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}static compare(e,t,r){if(this.isDayTimeDurationValue(e)&&this.isDayTimeDurationValue(t))return this.compareDurations(e instanceof R.Literal?e:String(e),t instanceof R.Literal?t:String(t),r);if(this.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return this.compareDurations(e instanceof R.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&this.isDayTimeDurationValue(t))return this.compareDurations(e,t instanceof R.Literal?t:String(t),r);let i=this.toComparableValue(e),s=this.toComparableValue(t);switch(r){case"=":return i===s;case"!=":return i!==s;case"<":return i<s;case">":return i>s;case"<=":return i<=s;case">=":return i>=s;default:throw new Error(`Unknown comparison operator: ${r}`)}}static isDayTimeDurationValue(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static toComparableValue(e){if(typeof e=="string"||typeof e=="number")return e;if(e instanceof R.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let r=parseFloat(e.value);if(!isNaN(r))return r}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return this.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof be.IRI?e.value:e instanceof Lr.BlankNode?e.id:String(e)}static contains(e,t){return e.includes(t)}static strStarts(e,t){return e.startsWith(t)}static strEnds(e,t){return e.endsWith(t)}static strlen(e){return e.length}static ucase(e){return e.toUpperCase()}static lcase(e){return e.toLowerCase()}static substr(e,t,r){let i=t-1;if(i<0){if(r!==void 0){let s=r+i;return s<=0?"":e.substring(0,s)}return e}return r!==void 0?e.substring(i,i+r):e.substring(i)}static strBefore(e,t){if(t==="")return"";let r=e.indexOf(t);return r===-1?"":e.substring(0,r)}static strAfter(e,t){if(t==="")return e;let r=e.indexOf(t);return r===-1?"":e.substring(r+t.length)}static concat(...e){return e.join("")}static replace(e,t,r,i){try{let s=i||"g",a=s.includes("u")?s:s+"u",c=new RegExp(t,a);return e.replace(c,r)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static parseDate(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`PARSEDATE: invalid date string '${e}'`);return t.getTime()}static dateBefore(e,t){let r=this.parseDate(e),i=this.parseDate(t);return r<i}static dateAfter(e,t){let r=this.parseDate(e),i=this.parseDate(t);return r>i}static dateInRange(e,t,r){let i=this.parseDate(e),s=this.parseDate(t),a=this.parseDate(r);return i>=s&&i<=a}static dateDiffMinutes(e,t){let r=this.parseDate(e),i=this.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=this.parseDate(e),i=this.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60*60)*100)/100}static logicalAnd(e){return e.every(t=>t===!0)}static logicalOr(e){return e.some(t=>t===!0)}static logicalNot(e){return!e}static year(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return t.getFullYear()}static month(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return t.getMonth()+1}static day(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return t.getDate()}static hours(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return t.getHours()}static minutes(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return t.getMinutes()}static seconds(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return t.getSeconds()+t.getMilliseconds()/1e3}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let r;if(e.endsWith("Z"))r="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),a=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);a===0?r=`${c}PT${l}H`:r=`${c}PT${l}H${a}M`}else{let s=-t.getTimezoneOffset(),a=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?r=`${l}PT${a}H`:r=`${l}PT${a}H${c}M`}}return new R.Literal(r,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static tz(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TZ: invalid date string '${e}'`);if(e.endsWith("Z"))return"Z";let r=e.match(/([+-]\d{2}:\d{2})$/);if(r)return r[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static now(){return new Date().toISOString()}static msToMinutes(e){return Math.round(e/(1e3*60))}static msToHours(e){return Math.round(e/(1e3*60*60)*100)/100}static msToSeconds(e){return Math.round(e/1e3)}static abs(e){return Math.abs(e)}static round(e){return Math.round(e)}static ceil(e){return Math.ceil(e)}static floor(e){return Math.floor(e)}static rand(){return Math.random()}static coalesce(e){for(let t of e)if(t!=null)return t}static if(e,t,r){return e?t:r}static xsdDateTime(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`xsd:dateTime: invalid date string '${e}'`);return new R.Literal(t.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static xsdInteger(e){let t=parseInt(e,10);if(isNaN(t))throw new Error(`xsd:integer: cannot convert '${e}' to integer`);return new R.Literal(String(t),new be.IRI("http://www.w3.org/2001/XMLSchema#integer"))}static xsdDecimal(e){let t=parseFloat(e);if(isNaN(t))throw new Error(`xsd:decimal: cannot convert '${e}' to decimal`);return new R.Literal(String(t),new be.IRI("http://www.w3.org/2001/XMLSchema#decimal"))}static encodeForUri(e){return encodeURIComponent(e)}static md5(e){return require("crypto").createHash("md5").update(e).digest("hex")}static sha1(e){return require("crypto").createHash("sha1").update(e).digest("hex")}static sha256(e){return require("crypto").createHash("sha256").update(e).digest("hex")}static sha384(e){return require("crypto").createHash("sha384").update(e).digest("hex")}static sha512(e){return require("crypto").createHash("sha512").update(e).digest("hex")}static sameTerm(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0||e.constructor!==t.constructor)return!1;if(e instanceof be.IRI&&t instanceof be.IRI)return e.value===t.value;if(e instanceof Lr.BlankNode&&t instanceof Lr.BlankNode)return e.id===t.id;if(e instanceof R.Literal&&t instanceof R.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let r=e.datatype?.value,i=t.datatype?.value;return r===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof be.IRI)return e;if(e instanceof R.Literal)return new be.IRI(e.value);throw e instanceof Lr.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return this.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,qy.v4)().replace(/-/g,"").substring(0,12)}`;return new Lr.BlankNode(t)}if(e instanceof R.Literal)return new Lr.BlankNode(e.value);if(e instanceof Lr.BlankNode)return e;throw new Error("BNODE: argument must be a string literal or omitted")}static strdt(e,t){if(e===void 0)throw new Error("STRDT: lexical form is undefined");if(t===void 0)throw new Error("STRDT: datatype IRI is undefined");let r;if(e instanceof R.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof be.IRI)i=t;else if(t instanceof R.Literal)i=new be.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new R.Literal(r,i)}static strlang(e,t){if(e===void 0)throw new Error("STRLANG: lexical form is undefined");if(t===void 0)throw new Error("STRLANG: language tag is undefined");let r;if(e instanceof R.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof R.Literal)i=t.value;else if(typeof t=="string")i=t;else throw new Error("STRLANG: language tag must be a string literal");if(i==="")throw new Error("STRLANG: language tag cannot be empty");return new R.Literal(r,void 0,i)}static strlangdir(e,t,r){if(e===void 0)throw new Error("STRLANGDIR: lexical form is undefined");if(t===void 0)throw new Error("STRLANGDIR: language tag is undefined");if(r===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof R.Literal){if(e.language)throw new Error("STRLANGDIR: lexical form must not already have a language tag");i=e.value}else if(typeof e=="string")i=e;else throw new Error("STRLANGDIR: lexical form must be a string literal");let s;if(t instanceof R.Literal)s=t.value;else if(typeof t=="string")s=t;else throw new Error("STRLANGDIR: language tag must be a string literal");if(s==="")throw new Error("STRLANGDIR: language tag cannot be empty");let a;if(r instanceof R.Literal)a=r.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(a!=="ltr"&&a!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${a}'. Must be 'ltr' or 'rtl'`);return new R.Literal(i,void 0,s,a)}static uuid(){let e=(0,qy.v4)();return new be.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,qy.v4)();return new R.Literal(e)}static parseDayTimeDuration(e){if(!e)throw new Error("parseDayTimeDuration: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=r.indexOf("T"),a="",c="";if(s===-1?a=r:(a=r.substring(0,s),c=r.substring(s+1)),a){let l=a.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(a!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${a}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let d=parseFloat(u[1]);i+=d*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let d=parseFloat(f[1]);i+=d*60*1e3,l=l.substring(f[0].length)}let h=l.match(/^(\d+(?:\.\d+)?)S$/);if(h){let d=parseFloat(h[1]);i+=d*1e3,l=l.substring(h[0].length)}if(l!=="")throw new Error(`parseDayTimeDuration: invalid time component: '${l}' in '${e}'`)}return t?-i:i}static formatDayTimeDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/(1440*60*1e3));r=r%(1440*60*1e3);let s=Math.floor(r/(3600*1e3));r=r%(3600*1e3);let a=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||a>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),a>0&&(l+=`${a}M`),(c>0||s===0&&a===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return this.parseDayTimeDuration(e),new R.Literal(e,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static compareDurations(e,t,r){let i=e instanceof R.Literal?e.value:e,s=t instanceof R.Literal?t.value:t,a=this.parseDayTimeDuration(i),c=this.parseDayTimeDuration(s);switch(r){case"=":return a===c;case"!=":return a!==c;case"<":return a<c;case">":return a>c;case"<=":return a<=c;case">=":return a>=c;default:throw new Error(`compareDurations: unknown operator: ${r}`)}}static isDayTimeDuration(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static dateDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r),a=this.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);if(a===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-a.getTime(),l=Math.round(c/(1440*60*1e3)),u=this.formatDateDuration(l);return new R.Literal(u,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,a=parseInt(r[3],10),c=r[4],l=new Date(Date.UTC(i,s,a));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,h=parseInt(u[2],10),d=parseInt(u[3],10),p=f*(h*60+d)*60*1e3;l=new Date(l.getTime()-p)}}return l}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,r=Math.abs(e);return t?`-P${r}D`:`P${r}D`}static dateTimeDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r),a=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(a.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-a.getTime(),l=this.formatDayTimeDuration(c);return new R.Literal(l,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c);return new R.Literal(l.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c);return new R.Literal(l.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),h=String(l.getUTCDate()).padStart(2,"0"),d=`${u}-${f}-${h}`;return new R.Literal(d,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),h=String(l.getUTCDate()).padStart(2,"0"),d=`${u}-${f}-${h}`;return new R.Literal(d,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+a;return i?-c:c}static isYearMonthDuration(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static dateTimeAddYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0),new R.Literal(s.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0),new R.Literal(s.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),h=`${l}-${u}-${f}`;return new R.Literal(h,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),h=`${l}-${u}-${f}`;return new R.Literal(h,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseDayTimeDuration(r),a=this.parseDayTimeDuration(i),c=this.formatDayTimeDuration(s+a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseDayTimeDuration(r),a=this.parseDayTimeDuration(i),c=this.formatDayTimeDuration(s-a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof R.Literal?e.value:e,i=this.parseDayTimeDuration(r),s=this.formatDayTimeDuration(i*t);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let r=e instanceof R.Literal?e.value:e,i=this.parseDayTimeDuration(r),s=this.formatDayTimeDuration(i/t);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static formatYearMonthDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/12),s=r%12,a=t?"-P":"P";return i>0&&(a+=`${i}Y`),(s>0||i===0)&&(a+=`${s}M`),a}static yearMonthDurationAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseYearMonthDuration(r),a=this.parseYearMonthDuration(i),c=this.formatYearMonthDuration(s+a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseYearMonthDuration(r),a=this.parseYearMonthDuration(i),c=this.formatYearMonthDuration(s-a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:a,negative:i}}static durationYears(e){let t=e instanceof R.Literal?e.value:e,r=this.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof R.Literal?e.value:e,r=this.parseYearMonthDurationComponents(t);return r.negative?-r.months:r.months}static durationToDays(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/1e3}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,a=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let h=u.match(/^(\d+(?:\.\d+)?)D$/);if(h)i=parseFloat(h[1]);else if(u!=="")throw new Error(`parseDurationComponents: invalid day component: '${u}' in '${e}'`)}if(f){let h=f,d=h.match(/^(\d+(?:\.\d+)?)H/);d&&(s=parseFloat(d[1]),h=h.substring(d[0].length));let p=h.match(/^(\d+(?:\.\d+)?)M/);p&&(a=parseFloat(p[1]),h=h.substring(p[0].length));let _=h.match(/^(\d+(?:\.\d+)?)S$/);if(_&&(c=parseFloat(_[1]),h=h.substring(_[0].length)),h!=="")throw new Error(`parseDurationComponents: invalid time component: '${h}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:a,seconds:c}}static durationDays(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static adjust(e,t){let r=e instanceof R.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let $=i.getUTCFullYear(),re=String(i.getUTCMonth()+1).padStart(2,"0"),De=String(i.getUTCDate()).padStart(2,"0"),N=String(i.getUTCHours()).padStart(2,"0"),q=String(i.getUTCMinutes()).padStart(2,"0"),ge=String(i.getUTCSeconds()).padStart(2,"0"),ot=i.getUTCMilliseconds(),Ke=`${$}-${re}-${De}T${N}:${q}:${ge}`;return ot>0&&(Ke+=`.${String(ot).padStart(3,"0")}`),new R.Literal(Ke,new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof R.Literal?t.value:t,a=this.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(a)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+a),f=u.getUTCFullYear(),h=String(u.getUTCMonth()+1).padStart(2,"0"),d=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),_=String(u.getUTCMinutes()).padStart(2,"0"),b=String(u.getUTCSeconds()).padStart(2,"0"),E=u.getUTCMilliseconds(),A=a>=0?"+":"-",C=Math.floor(Math.abs(a)/(3600*1e3)),j=Math.floor(Math.abs(a)%(3600*1e3)/(60*1e3)),Q=`${A}${String(C).padStart(2,"0")}:${String(j).padStart(2,"0")}`,K=`${f}-${h}-${d}T${p}:${_}:${b}`;return E>0&&(K+=`.${String(E).padStart(3,"0")}`),K+=Q,new R.Literal(K,new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static normalize(e,t){if(e===void 0)throw new Error("NORMALIZE: string argument is undefined");let r;if(e instanceof R.Literal)r=e.value;else if(e instanceof be.IRI)r=e.value;else if(e instanceof Lr.BlankNode)r=e.id;else if(typeof e=="string")r=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof R.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof be.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!this.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=r.normalize(i);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#string"))}static fold(e){if(e===void 0)throw new Error("FOLD: string argument is undefined");let t;if(e instanceof R.Literal)t=e.value;else if(e instanceof be.IRI)t=e.value;else if(e instanceof Lr.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let r=this.unicodeCaseFold(t);return new R.Literal(r,new be.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let r of e){let i=this.CASE_FOLDING_MAP.get(r);i!==void 0?t+=i:t+=r.toLowerCase()}return t}static isTime(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static timeDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDTime(r),a=this.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(a===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-a,l=this.formatDayTimeDuration(c);return new R.Literal(l,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r)return null;let i=parseInt(r[1],10),s=parseInt(r[2],10),a=parseInt(r[3],10),c=r[4],l=r[5];if(i<0||i>24||s<0||s>59||a<0||a>59||i===24&&(s!==0||a!==0))return null;let u=0;if(c){let h=c.padEnd(3,"0").slice(0,3);u=parseInt(h,10)}let f=i*60*60*1e3+s*60*1e3+a*1e3+u;if(i===24&&(f=1440*60*1e3),l&&l!=="Z"){let h=l.match(/([+-])(\d{2}):(\d{2})/);if(h){let d=h[1]==="+"?1:-1,p=parseInt(h[2],10),_=parseInt(h[3],10),b=d*(p*60+_)*60*1e3;f-=b}}return f}static triple(e,t,r){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(r===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof R.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof be.IRI)){let c=t instanceof R.Literal?"Literal":t instanceof Lr.BlankNode?"BlankNode":t instanceof To.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,a=r;return new To.QuotedTriple(i,s,a)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`SUBJECT: argument must be QuotedTriple, got ${t}`)}return e.subject}static predicate(e){if(e===void 0)throw new Error("PREDICATE: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`PREDICATE: argument must be QuotedTriple, got ${t}`)}return e.predicate}static object(e){if(e===void 0)throw new Error("OBJECT: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};wh.BuiltInFunctions=al;al.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];al.CASE_FOLDING_MAP=new Map([["\xDF","ss"],["\u1E9E","ss"],["\u03A3","\u03C3"],["\u03C2","\u03C3"],["\u0130","i\u0307"],["I","i"],["\u0587","\u0565\u0582"],["\uFB00","ff"],["\uFB01","fi"],["\uFB02","fl"],["\uFB03","ffi"],["\uFB04","ffl"],["\uFB05","st"],["\uFB06","st"],["\u0390","\u03B9\u0308\u0301"],["\u03B0","\u03C5\u0308\u0301"],["\u017F","s"],["\u1E9B","\u1E61"],["\u212A","k"],["\u212B","\xE5"]])});var $w=v(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.functionHandlers=void 0;var L=Eh();k.functionHandlers=new Map;k.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.str(t)});k.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.lang(t)});k.functionHandlers.set("langmatches",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.langMatches(t,r)});k.functionHandlers.set("contains",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.contains(t,r)});k.functionHandlers.set("strstarts",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strStarts(t,r)});k.functionHandlers.set("strends",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strEnds(t,r)});k.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.strlen(t)});k.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.ucase(t)});k.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.lcase(t)});k.functionHandlers.set("substr",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=Number(e.evaluateExpression(n[1],e.solution));if(n[2]){let i=Number(e.evaluateExpression(n[2],e.solution));return L.BuiltInFunctions.substr(t,r,i)}return L.BuiltInFunctions.substr(t,r)});k.functionHandlers.set("strbefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strBefore(t,r)});k.functionHandlers.set("strafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strAfter(t,r)});k.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return L.BuiltInFunctions.concat(...t)});k.functionHandlers.set("replace",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution)),s=n[3]?e.getStringValue(e.evaluateExpression(n[3],e.solution)):void 0;return L.BuiltInFunctions.replace(t,r,i,s)});k.functionHandlers.set("regex",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=n[2]?e.getStringValue(e.evaluateExpression(n[2],e.solution)):void 0;return L.BuiltInFunctions.regex(t,r,i)});k.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.encodeForUri(t)});k.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.datatype(t).value});k.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return L.BuiltInFunctions.bound(r)}return!0});var Rw=o((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isIRI(t)},"isIriHandler");k.functionHandlers.set("isiri",Rw);k.functionHandlers.set("isuri",Rw);k.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isBlank(t)});k.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isLiteral(t)});k.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isNumeric(t)});k.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.hasLangdir(t)});k.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isTriple(t)});k.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return L.BuiltInFunctions.sameTerm(t,r)});k.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.abs(t)});k.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.round(t)});k.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.ceil(t)});k.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.floor(t)});k.functionHandlers.set("rand",()=>L.BuiltInFunctions.rand());k.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.parseDate(t)});k.functionHandlers.set("datebefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateBefore(t,r)});k.functionHandlers.set("dateafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateAfter(t,r)});k.functionHandlers.set("dateinrange",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution));return L.BuiltInFunctions.dateInRange(t,r,i)});k.functionHandlers.set("datediffminutes",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateDiffMinutes(t,r)});k.functionHandlers.set("datediffhours",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateDiffHours(t,r)});var xo=o((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),Fw=xo(L.BuiltInFunctions.year.bind(L.BuiltInFunctions),L.BuiltInFunctions.durationYears.bind(L.BuiltInFunctions),null);k.functionHandlers.set("year",Fw);k.functionHandlers.set("years",Fw);var Dw=xo(L.BuiltInFunctions.month.bind(L.BuiltInFunctions),L.BuiltInFunctions.durationMonths.bind(L.BuiltInFunctions),null);k.functionHandlers.set("month",Dw);k.functionHandlers.set("months",Dw);var Nw=xo(L.BuiltInFunctions.day.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationDays.bind(L.BuiltInFunctions));k.functionHandlers.set("day",Nw);k.functionHandlers.set("days",Nw);k.functionHandlers.set("hours",xo(L.BuiltInFunctions.hours.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationHours.bind(L.BuiltInFunctions)));k.functionHandlers.set("minutes",xo(L.BuiltInFunctions.minutes.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationMinutes.bind(L.BuiltInFunctions)));k.functionHandlers.set("seconds",xo(L.BuiltInFunctions.seconds.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationSeconds.bind(L.BuiltInFunctions)));k.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.timezone(t)});k.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.tz(t)});k.functionHandlers.set("adjust",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=n.length>1?e.evaluateExpression(n[1],e.solution):void 0;return L.BuiltInFunctions.adjust(t,r)});k.functionHandlers.set("now",()=>L.BuiltInFunctions.now());var Lw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");k.functionHandlers.set("datetime",Lw);k.functionHandlers.set("xsd:datetime",Lw);var kw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");k.functionHandlers.set("integer",kw);k.functionHandlers.set("xsd:integer",kw);var Mw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");k.functionHandlers.set("decimal",Mw);k.functionHandlers.set("xsd:decimal",Mw);var jw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");k.functionHandlers.set("daytimeduration",jw);k.functionHandlers.set("xsd:daytimeduration",jw);k.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToDays(t)});k.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToHours(t)});k.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToMinutes(t)});k.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToSeconds(t)});k.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationDays(t)});k.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationHours(t)});k.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationMinutes(t)});k.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationSeconds(t)});k.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationYears(t)});k.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationMonths(t)});k.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeDiff(t,r)});k.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeAdd(t,r)});k.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeSubtract(t,r)});k.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToMinutes(t)});k.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToHours(t)});k.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToSeconds(t)});k.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.md5(t)});k.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha1(t)});k.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha256(t)});k.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha384(t)});k.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha512(t)});k.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.subject(t)});k.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.predicate(t)});k.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.object(t)});k.functionHandlers.set("triple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution),i=e.getTermFromExpression(n[2],e.solution);return L.BuiltInFunctions.triple(t,r,i)})});var Th=v(Ao=>{"use strict";Object.defineProperty(Ao,"__esModule",{value:!0});Ao.FilterExecutor=Ao.FilterExecutorError=void 0;var ht=Eh(),lL=$w(),va=mt(),sr=class extends Error{static{o(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Ao.FilterExecutorError=sr;var Gy=class{static{o(this,"FilterExecutor")}constructor(){this.existsEvaluator=null,this.tripleStore=null,this.uuidCache=new Map}setExistsEvaluator(e){this.existsEvaluator=e}setTripleStore(e){this.tripleStore=e,this.uuidCache.clear()}async*execute(e,t){let r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(e.type==="exists")return!0;if(e.type==="logical")return e.operands.some(t=>this.expressionContainsExists(t));if(e.type==="comparison")return this.expressionContainsExists(e.left)||this.expressionContainsExists(e.right);if(e.type==="in"){let t=e;return this.expressionContainsExists(t.expression)||t.list.some(r=>this.expressionContainsExists(r))}return!1}async executeAll(e,t){let r=[];async function*i(){for(let s of t)yield s}o(i,"generator");for await(let s of this.execute(e,i()))r.push(s);return r}evaluateExpression(e,t){let r=e;if(r.termType)switch(r.termType){case"Variable":return t.get(r.value);case"Literal":return r.value;case"NamedNode":return r.value;default:throw new sr(`Unsupported termType: ${r.termType}`)}switch(e.type){case"comparison":return this.evaluateComparison(e,t);case"logical":return this.evaluateLogical(e,t);case"arithmetic":return this.evaluateArithmetic(e,t);case"function":case"functionCall":return this.evaluateFunction(e,t);case"variable":return t.get(e.name);case"literal":return e.value;case"in":return this.evaluateIn(e,t);case"exists":throw new sr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new sr(`Unsupported expression type: ${e.type}, expr.termType=${r.termType}`)}}async evaluateExpressionAsync(e,t){return e.type==="exists"?this.evaluateExists(e,t):e.type==="logical"?this.evaluateLogicalAsync(e,t):this.evaluateExpression(e,t)}async evaluateExists(e,t){if(!this.existsEvaluator)throw new sr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let r=await this.existsEvaluator(e.pattern,t);return e.negated?!r:r}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let i=await this.evaluateExpressionAsync(e.operands[0],t);return ht.BuiltInFunctions.logicalNot(i)}let r=[];for(let i of e.operands){let s=await this.evaluateExpressionAsync(i,t);r.push(s)}if(e.operator==="&&")return ht.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return ht.BuiltInFunctions.logicalOr(r);throw new sr(`Unknown logical operator: ${e.operator}`)}evaluateComparison(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return ht.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return ht.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return ht.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return ht.BuiltInFunctions.logicalOr(r);throw new sr(`Unknown logical operator: ${e.operator}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let a=this.evaluateExpression(s,t);return ht.BuiltInFunctions.compare(r,a,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return ht.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return ht.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return ht.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return ht.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return ht.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new sr("Division by zero");return ht.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),a=this.toNumericValue(i);switch(e.operator){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":if(a===0)throw new sr("Division by zero");return s/a;default:throw new sr(`Unknown arithmetic operator: ${e.operator}`)}}isDayTimeDurationValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof va.Literal){let t=e.datatype?.value||"";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let i=parseFloat(e.value);if(!isNaN(i))return i}let r=parseFloat(e.value);if(!isNaN(r))return r}if(typeof e=="string"){let t=parseFloat(e);if(!isNaN(t))return t}if(e&&typeof e=="object"&&"value"in e){let t=parseFloat(String(e.value));if(!isNaN(t))return t}throw new sr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof va.Literal){let t=e.datatype?.value||"";return t.includes("#dateTime")||t.includes("#date")?!0:/^\d{4}-\d{2}-\d{2}(T|\s)/.test(e.value)}return typeof e=="string"?/^\d{4}-\d{2}-\d{2}(T|\s)/.test(e):!1}isDateValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let a=lL.functionHandlers.get(i);if(!a)throw new sr(`Unknown function: ${i}`);let c={evaluateExpression:o((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:o((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:o(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:o(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:o(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return a(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new sr(`Unknown function format: ${e}`)}evaluateSpecialFunction(e,t,r){switch(e){case"coalesce":for(let c of t)try{let l=this.evaluateExpression(c,r);if(l!=null)return{value:l}}catch{continue}return{value:void 0};case"if":if(!t||t.length!==3)throw new sr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],r);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],r):this.evaluateExpression(t[2],r)};case"byuuid":return{value:this.evaluateByUUID({args:t},r)};default:return}}getTermFromExpression(e,t){let r=e;if(r.type==="variable"&&r.name)return t.get(r.name)}getStringValue(e){return e==null?"":typeof e=="object"&&"value"in e?String(e.value):String(e)}toBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="number")return!isNaN(e)&&e!==0;if(typeof e=="string")return e.length>0;if(e instanceof va.Literal){let t=e.datatype?.value||"";if(t.includes("#boolean"))return e.value==="true"||e.value==="1";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let r=parseFloat(e.value);return!isNaN(r)&&r!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new sr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let a=this.tripleStore.findSubjectsByUUIDSync(s);if(a.length===0){this.uuidCache.set(s,null);return}let c=a[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Ao.FilterExecutor=Gy});var Hy=v(xh=>{"use strict";Object.defineProperty(xh,"__esModule",{value:!0});xh.OptionalExecutor=void 0;var Wy=class{static{o(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let a="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,a),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,a),f=c.get(u),h=!1;if(f)for(let d of f){let p=l.merge(d);p!==null&&(yield p,h=!0)}h||(yield l)}}computeHashKey(e,t,r){let i=[];for(let s of t){let a=e.get(s);i.push(a!==void 0?a.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let a=r.merge(s);a!==null&&(yield a,i=!0)}i||(yield r)}}};xh.OptionalExecutor=Wy});var Qy=v(Ah=>{"use strict";Object.defineProperty(Ah,"__esModule",{value:!0});Ah.UnionExecutor=void 0;var zy=class{static{o(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Ah.UnionExecutor=zy});var Jy=v(Ch=>{"use strict";Object.defineProperty(Ch,"__esModule",{value:!0});Ch.ConstructExecutor=void 0;var uL=_i(),_a=We(),Yy=mt(),Ky=kt(),fL=Lc(),Xy=class{static{o(this,"ConstructExecutor")}async execute(e,t){let r=[],i=new Set;for(let s of t)for(let a of e)try{let c=this.instantiateTriple(a,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new uL.Triple(r,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable: ${e.value}`);return r}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="literal")return new Yy.Literal(e.value,e.datatype?new _a.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let r=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new fL.QuotedTriple(r,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(r instanceof Yy.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Invalid element type for quoted triple subject: ${e.type}`)}instantiateQuotedPredicate(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(r instanceof _a.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new _a.IRI(e.value)}instantiateQuotedObject(e,t){if(e.type==="variable"){let i=t.get(e.value);if(!i)throw new Error(`Unbound variable in quoted triple object: ${e.value}`);return i}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="literal")return new Yy.Literal(e.value,e.datatype?new _a.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let r=e;throw new Error(`Invalid element type for quoted triple object: ${r.type}`)}};Ch.ConstructExecutor=Xy});var Uw=v(Ih=>{"use strict";Object.defineProperty(Ih,"__esModule",{value:!0});Ih.DescribeExecutor=void 0;var Vw=We(),Zy=class{static{o(this,"DescribeExecutor")}constructor(e){this.tripleStore=e}async execute(e,t){let r=[],i=new Set,s=new Set,a=t?.depth;for(let c of e)await this.describeResourceWithDepth(c,a,1,t?.symmetric??!0,r,i,s);return r}async describeResourceWithDepth(e,t,r,i,s,a,c){let l=e.toString();if(c.has(l)||(c.add(l),t!==void 0&&r>t))return;let u=[],f=await this.tripleStore.match(e,void 0,void 0);if(u.push(...f),i){let d=await this.tripleStore.match(void 0,void 0,e);u.push(...d)}let h=[];for(let d of u){let p=`${d.subject.toString()}|${d.predicate.toString()}|${d.object.toString()}`;a.has(p)||(a.add(p),s.push(d),(t===void 0||r<t)&&(this.isIRI(d.subject)&&d.subject.toString()!==l&&h.push(d.subject),this.isIRI(d.object)&&d.object.toString()!==l&&h.push(d.object)))}for(let d of h)await this.describeResourceWithDepth(d,t,r+1,i,s,a,c)}isIRI(e){return e?e instanceof Vw.IRI||e.termType==="NamedNode"||typeof e.value=="string"&&e.value.startsWith("http"):!1}async describeByIRI(e,t){let r=new Vw.IRI(e);return this.execute([r],t)}};Ih.DescribeExecutor=Zy});var Bw=v(Ph=>{"use strict";Object.defineProperty(Ph,"__esModule",{value:!0});Ph.MinusExecutor=void 0;var e1=class{static{o(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let a=!1;for(let c of i)if(this.areCompatible(s,c)){a=!0;break}a||(yield s)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.filter(a=>i.has(a));if(s.length===0)return!1;for(let a of s){let c=e.get(a),l=t.get(a);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};Ph.MinusExecutor=e1});var Gw=v(Co=>{"use strict";Object.defineProperty(Co,"__esModule",{value:!0});Co.ValuesExecutor=Co.ValuesExecutorError=void 0;var hL=es(),qw=We(),dL=mt(),Oh=class extends Error{static{o(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Co.ValuesExecutorError=Oh;var t1=class{static{o(this,"ValuesExecutor")}async*execute(e){if(e.bindings.length!==0)for(let t of e.bindings)yield this.createSolutionMapping(t)}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new hL.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(r,s)}return t}toRDFTerm(e){if(e.type==="iri")return new qw.IRI(e.value);if(e.type==="literal")return new dL.Literal(e.value,e.datatype?new qw.IRI(e.datatype):void 0,e.language,e.direction);throw new Oh(`Unknown term type: ${e.type}`)}};Co.ValuesExecutor=t1});var r1=v(Po=>{"use strict";Object.defineProperty(Po,"__esModule",{value:!0});Po.CustomAggregateRegistry=Po.CustomAggregateError=void 0;var Io=class extends Error{static{o(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};Po.CustomAggregateError=Io;var Rh=class n{static{o(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new Io("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new Io("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new Io(`Aggregate with IRI "${e}" is already registered`,e);this.aggregates.set(e,t)}unregister(e){return this.aggregates.delete(e)}get(e){return this.aggregates.get(e)}has(e){return this.aggregates.has(e)}getRegisteredIris(){return Array.from(this.aggregates.keys())}clear(){this.aggregates.clear()}get size(){return this.aggregates.size}};Po.CustomAggregateRegistry=Rh;Rh.instance=null});var n1=v(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.BUILT_IN_AGGREGATES=qe.modeAggregate=qe.stddevAggregate=qe.varianceAggregate=qe.medianAggregate=qe.EXO_AGGREGATE_NS=void 0;qe.getNumericValue=Fh;qe.createDecimalLiteral=ri;qe.createDoubleLiteral=gL;qe.createPercentileAggregate=ba;var Sa=mt(),Oo=We(),pL=new Oo.IRI("http://www.w3.org/2001/XMLSchema#decimal"),mL=new Oo.IRI("http://www.w3.org/2001/XMLSchema#double");qe.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Fh(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof Sa.Literal?parseFloat(n.value):n instanceof Oo.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}o(Fh,"getNumericValue");function ri(n){return new Sa.Literal(String(n),pL)}o(ri,"createDecimalLiteral");function gL(n){return new Sa.Literal(String(n),mL)}o(gL,"createDoubleLiteral");qe.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Fh(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=[...t].sort((a,c)=>a-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return ri(s)}};qe.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Fh(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ri(i)}};qe.stddevAggregate={init(){return{values:[]}},step(n,e){qe.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ri(Math.sqrt(i))}};qe.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof Sa.Literal||e instanceof Oo.IRI?e.value:e),i=t.counts.get(r)||0;t.counts.set(r,i+1),t.values.set(r,e)},finalize(n){let e=n;if(e.counts.size===0)return new Sa.Literal(" ",new Oo.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[a,c]of e.counts)c>r&&(r=c,t=a);let i=e.values.get(t);if(i instanceof Sa.Literal)return i;let s=parseFloat(t);return isNaN(s)?new Sa.Literal(t,new Oo.IRI("http://www.w3.org/2001/XMLSchema#string")):ri(s)}};function ba(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Fh(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return ri(0);let s=[...i].sort((h,d)=>h-d),a=r.percentile*(s.length-1),c=Math.floor(a),l=Math.ceil(a);if(c===l)return ri(s[c]);let u=a-c,f=s[c]*(1-u)+s[l]*u;return ri(f)}}}o(ba,"createPercentileAggregate");qe.BUILT_IN_AGGREGATES={[`${qe.EXO_AGGREGATE_NS}median`]:qe.medianAggregate,[`${qe.EXO_AGGREGATE_NS}variance`]:qe.varianceAggregate,[`${qe.EXO_AGGREGATE_NS}stddev`]:qe.stddevAggregate,[`${qe.EXO_AGGREGATE_NS}mode`]:qe.modeAggregate,[`${qe.EXO_AGGREGATE_NS}percentile25`]:ba(25),[`${qe.EXO_AGGREGATE_NS}percentile50`]:ba(50),[`${qe.EXO_AGGREGATE_NS}percentile75`]:ba(75),[`${qe.EXO_AGGREGATE_NS}percentile90`]:ba(90),[`${qe.EXO_AGGREGATE_NS}percentile95`]:ba(95),[`${qe.EXO_AGGREGATE_NS}percentile99`]:ba(99)}});var zw=v(Ro=>{"use strict";Object.defineProperty(Ro,"__esModule",{value:!0});Ro.AggregateExecutor=Ro.AggregateExecutorError=void 0;var jt=mt(),s1=We(),yL=Th(),vL=r1(),_L=n1(),Ww=new s1.IRI("http://www.w3.org/2001/XMLSchema#integer"),wa=new s1.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Ai=new s1.IRI("http://www.w3.org/2001/XMLSchema#string");function Hw(n){return typeof n=="object"&&n.type==="custom"}o(Hw,"isCustomAggregation");var ol=class extends Error{static{o(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};Ro.AggregateExecutorError=ol;var i1=class{static{o(this,"AggregateExecutor")}constructor(){this.filterExecutor=new yL.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,a]of r.entries()){let c=new Map;for(let f of e.variables)if(a.length>0){let h=a[0].get(f);h&&c.set(f,h)}for(let f of e.aggregates){let h=this.computeAggregate(f.expression,a);c.set(f.variable,h)}let{SolutionMapping:l}=es(),u=new l;for(let[f,h]of c.entries())u.set(f,h);i.push(u)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let r=new Map;if(t.length===0)return r.set("",e),r;for(let i of e){let s=this.computeGroupKey(i,t),a=r.get(s);a?a.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if(Hw(e.aggregation))return this.computeCustomAggregate(e,t);let r=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(r,e.distinct);return new jt.Literal(String(s),Ww)}case"sum":{let s=this.computeSum(r);return new jt.Literal(String(s),wa)}case"avg":{let s=this.computeAvg(r);return new jt.Literal(String(s),wa)}case"min":{let s=this.computeMin(r);return s===void 0?new jt.Literal("",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}case"max":{let s=this.computeMax(r);return s===void 0?new jt.Literal("",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new jt.Literal(s||" ",Ai)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new jt.Literal(" ",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}default:{let s=i;throw new ol(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,a=vL.CustomAggregateRegistry.getInstance().get(i);if(a||(a=_L.BUILT_IN_AGGREGATES[i]),!a)throw new ol(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=a.init();for(let l of t){let u=null;if(e.expression){let f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;a.step(c,u)}return a.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let a=s[0],c=parseFloat(a);return isNaN(c)?a:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=es(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if(Hw(s)){r.set(i.variable,new jt.Literal("0",wa));continue}switch(s){case"count":r.set(i.variable,new jt.Literal("0",Ww));break;case"sum":case"avg":r.set(i.variable,new jt.Literal("0",wa));break;case"group_concat":r.set(i.variable,new jt.Literal(" ",Ai));break;case"min":case"max":case"sample":r.set(i.variable,new jt.Literal("",Ai));break;default:r.set(i.variable,new jt.Literal("",Ai))}}return r}};Ro.AggregateExecutor=i1});var Yw=v(Fo=>{"use strict";Object.defineProperty(Fo,"__esModule",{value:!0});Fo.ServiceExecutor=Fo.ServiceExecutorError=void 0;var bL=es(),Qw=We(),SL=mt(),wL=kt(),Ea=class extends Error{static{o(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Fo.ServiceExecutorError=Ea;var a1=class{static{o(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,a=setTimeout(()=>s.abort(),this.timeout);try{let c=await this.httpClient(e,{method:"POST",headers:{"Content-Type":"application/sparql-query",Accept:"application/sparql-results+json"},body:t,signal:s.signal});if(!c.ok)throw new Ea(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(a)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new Ea(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new Ea(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,r)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new bL.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(r,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new Qw.IRI(e.value);case"literal":{let t=e.datatype?new Qw.IRI(e.datatype):void 0;return new SL.Literal(e.value,t,e["xml:lang"])}case"bnode":return new wL.BlankNode(e.value);default:throw new Ea(`Unknown RDF term type: ${e.type}`)}}isRetryableError(e){let t=e.message.toLowerCase();return!!(e.name==="AbortError"||t.includes("network")||t.includes("econnreset")||t.includes("econnrefused")||t.includes("etimedout")||t.includes("returned 5"))}delay(e){return new Promise(t=>setTimeout(t,e))}};Fo.ServiceExecutor=a1});var Xw=v(Do=>{"use strict";Object.defineProperty(Do,"__esModule",{value:!0});Do.GraphExecutor=Do.GraphExecutorError=void 0;var Kw=We(),Dh=class extends Error{static{o(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Do.GraphExecutorError=Dh;var o1=class{static{o(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new Dh(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new Kw.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let a=i.get(t.value);if(a&&a instanceof Kw.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:a.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let a of s)for await(let c of r(e.pattern,a)){let l=c.clone();l.set(t.value,a),yield l}}};Do.GraphExecutor=o1});var Jw=v(Lo=>{"use strict";Object.defineProperty(Lo,"__esModule",{value:!0});Lo.SPARQLGenerator=Lo.SPARQLGeneratorError=void 0;var No=class extends Error{static{o(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};Lo.SPARQLGeneratorError=No;var c1=class{static{o(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
315
+ ${r})`;default:return`${r}Unknown(${e.type})`}}tripleToString(e){return`${this.elementToString(e.subject)} ${this.predicateToString(e.predicate)} ${this.elementToString(e.object)}`}predicateToString(e){return this.isPropertyPath(e)?this.propertyPathToString(e):this.elementToString(e)}isPropertyPath(e){return e.type==="path"}propertyPathToString(e){let t=e.items.map(r=>r.type==="path"?`(${this.propertyPathToString(r)})`:`<${r.value}>`);switch(e.pathType){case"/":return t.join("/");case"|":return t.join("|");case"^":return`^${t[0]}`;case"+":return`${t[0]}+`;case"*":return`${t[0]}*`;case"?":return`${t[0]}?`}}elementToString(e){switch(e.type){case"variable":return`?${e.value}`;case"iri":return`<${e.value}>`;case"literal":let t=`"${e.value}"`;return e.language&&(t+=`@${e.language}`),e.datatype&&(t+=`^^<${e.datatype}>`),t;case"blank":return`_:${e.value}`;default:return String(e)}}expressionToString(e){switch(e.type){case"variable":return`?${e.name}`;case"literal":return typeof e.value=="string"?`"${e.value}"`:String(e.value);case"comparison":return`(${this.expressionToString(e.left)} ${e.operator} ${this.expressionToString(e.right)})`;case"logical":return e.operator==="!"?`!(${this.expressionToString(e.operands[0])})`:`(${e.operands.map(t=>this.expressionToString(t)).join(` ${e.operator} `)})`;case"arithmetic":return`(${this.expressionToString(e.left)} ${e.operator} ${this.expressionToString(e.right)})`;case"function":return`${e.function}(${e.args.map(t=>this.expressionToString(t)).join(", ")})`;case"exists":return`${e.negated?"NOT EXISTS":"EXISTS"} { ${this.toString(e.pattern,0)} }`;default:return"unknown"}}toJSON(e){return JSON.stringify(e,null,2)}};gh.AlgebraSerializer=My});var es=v(yh=>{"use strict";Object.defineProperty(yh,"__esModule",{value:!0});yh.SolutionMapping=void 0;var Aw=mt(),Cw=We(),Iw=kt(),jy=class n{static{o(this,"SolutionMapping")}constructor(e){this.bindings=e?new Map(e):new Map}get(e){return this.bindings.get(e)}set(e,t){this.bindings.set(e,t)}has(e){return this.bindings.has(e)}variables(){return Array.from(this.bindings.keys())}getBindings(){return new Map(this.bindings)}isCompatibleWith(e){for(let[t,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof Aw.Literal&&t instanceof Aw.Literal?e.equals(t):e instanceof Cw.IRI&&t instanceof Cw.IRI?e.value===t.value:e instanceof Iw.BlankNode&&t instanceof Iw.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,r]of this.bindings.entries())e[t]=r.toString();return e}size(){return this.bindings.size}};yh.SolutionMapping=jy});var Ow=v(wo=>{"use strict";Object.defineProperty(wo,"__esModule",{value:!0});wo.PropertyPathExecutor=wo.PropertyPathExecutorError=void 0;var oL=es(),vh=We(),Pw=kt(),sl=class extends Error{static{o(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};wo.PropertyPathExecutorError=sl;var $y=class{static{o(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){let i=await this.resolveElement(e),s=this.isVariable(r)?null:await this.resolveElement(r);for(let a of i){let c=await this.evaluatePath(a,t,s);for(let l of c){let u=new oL.SolutionMapping;this.isVariable(e)&&u.set(e.value,a),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new sl("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let a=t.merge(s);a!==null&&(yield a)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let a=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,a,c?r:null);for(let h of f)l.add(h)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,r){let i=new Set;for(let s of t){let a=await this.evaluatePathItem(e,s,r);for(let c of a)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new vh.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&a.add(c.subject);return a}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){let i=new Set,s=new Set,a=[{node:e,depth:0}];for(;a.length>0;){let{node:c,depth:l}=a.shift();if(l>=this.MAX_DEPTH)continue;let u=await this.evaluatePathItem(c,t,null);for(let f of u){let h=this.nodeToKey(f);(r===null||this.nodeInSet(f,r))&&s.add(f),i.has(h)||(i.add(h),a.push({node:f,depth:l+1}))}}return s}async evaluateZeroOrMorePath(e,t,r){let i=await this.evaluateOneOrMorePath(e,t,r);return(r===null||this.nodeInSet(e,r))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,r){let i=new Set;(r===null||this.nodeInSet(e,r))&&i.add(e);let s=await this.evaluatePathItem(e,t,r);for(let a of s)i.add(a);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new vh.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&a.add(c.object);return a}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(r=>r.type==="iri"?{type:"path",pathType:"^",items:[r]}:this.invertPath(r))};case"|":return{type:"path",pathType:"|",items:e.items.map(r=>r.type==="iri"?{type:"path",pathType:"^",items:[r]}:this.invertPath(r))};case"+":case"*":case"?":let t=e.items[0].type==="iri"?{type:"path",pathType:"^",items:[e.items[0]]}:this.invertPath(e.items[0]);return{type:"path",pathType:e.pathType,items:[t]}}}async resolveElement(e){if(this.isVariable(e)){let r=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)r.add(s.subject),r.add(s.object);return r}let t=new Set;switch(e.type){case"iri":t.add(new vh.IRI(e.value));break;case"blank":t.add(new Pw.BlankNode(e.value));break;default:throw new sl(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r){if(r instanceof vh.IRI)return{type:"iri",value:r.value};if(r instanceof Pw.BlankNode)return{type:"blank",value:r.id}}}return e}isVariable(e){return e.type==="variable"}isPropertyPath(e){return e.type==="path"}nodeToKey(e){return e.toString()}nodeInSet(e,t){let r=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===r)return!0;return!1}};wo.PropertyPathExecutor=$y});var By=v(Eo=>{"use strict";Object.defineProperty(Eo,"__esModule",{value:!0});Eo.BGPExecutor=Eo.BGPExecutorError=void 0;var _h=es(),Es=We(),Vy=mt(),bh=kt(),Sh=Lc(),cL=Ow(),vr=class extends Error{static{o(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Eo.BGPExecutorError=vr;var Uy=class{static{o(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new cL.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new _h.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let r=1;r<e.triples.length;r++)t=this.joinWithPattern(t,e.triples[r]);for await(let r of t)yield r}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new _h.SolutionMapping;return}let r=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)r=this.joinWithPatternInGraph(r,e.triples[i],t);for await(let i of r)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new vr("Property paths within named graphs are not yet supported");let r=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(r))return;let i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(r)?void 0:this.toRDFTermAsPredicate(r),a=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new vr("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,a,t);for(let l of c){let u=new _h.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let a=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(a,r)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){yield*this.propertyPathExecutor.execute(e.subject,e.predicate,e.object);return}let t=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(t))return;let r=this.isVariable(e.subject)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),i=this.isVariable(t)?void 0:this.toRDFTermAsPredicate(t),s=this.isVariable(e.object)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object)?void 0:this.toRDFTerm(e.object),a=await this.tripleStore.match(r,i,s);for(let c of a){let l=new _h.SolutionMapping;if(this.isVariable(e.subject))l.set(e.subject.value,c.subject);else if(this.isQuotedTriple(e.subject)){let u=this.matchQuotedTriplePattern(e.subject,c.subject);if(u===null)continue;for(let[f,h]of u.entries())l.set(f,h)}if(this.isVariable(t)&&l.set(t.value,c.predicate),this.isVariable(e.object))l.set(e.object.value,c.object);else if(this.isQuotedTriple(e.object)){let u=this.matchQuotedTriplePattern(e.object,c.object);if(u===null)continue;for(let[f,h]of u.entries())l.set(f,h)}yield l}}hasVariablesInQuotedTriple(e){return!!(this.isVariable(e.subject)||e.predicate.type==="variable"||this.isVariable(e.object)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object))}matchQuotedTriplePattern(e,t){if(!(t instanceof Sh.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof Es.IRI&&e.value===t.value;case"literal":return!(!(t instanceof Vy.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof bh.BlankNode&&e.value===t.id;case"quoted":return t instanceof Sh.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let a of this.matchTriplePattern(s)){let c=i.merge(a);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof Es.IRI?{type:"iri",value:r.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}isLiteral(e){return e.type==="literal"}toRDFTermAsSubject(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"blank":return new bh.BlankNode(e.value);case"literal":throw new vr("Literals cannot appear in subject position");case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vr(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new Es.IRI(e.predicate.value):(()=>{throw new vr("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new Sh.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"literal":throw new vr("Literals cannot appear in predicate position");case"blank":throw new vr("Blank nodes cannot appear in predicate position");case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);default:throw new vr(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new Es.IRI(e.value);case"literal":return new Vy.Literal(e.value,e.datatype?new Es.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new bh.BlankNode(e.value);case"variable":throw new vr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vr(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof Es.IRI)return{type:"iri",value:e.value};if(e instanceof Vy.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof bh.BlankNode)return{type:"blank",value:e.id};if(e instanceof Sh.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new vr(`Unknown RDF term type: ${String(e)}`)}toAlgebraQuotedTriple(e){return{type:"quoted",subject:this.toAlgebraElement(e.subject),predicate:{type:"iri",value:e.predicate.value},object:this.toAlgebraElement(e.object)}}};Eo.BGPExecutor=Uy});var Eh=v(wh=>{"use strict";Object.defineProperty(wh,"__esModule",{value:!0});wh.BuiltInFunctions=void 0;var be=We(),R=mt(),Lr=kt(),To=Lc(),qy=Or(),al=class{static{o(this,"BuiltInFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof be.IRI||e instanceof R.Literal?e.value:e instanceof Lr.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof R.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof R.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=this.parseDirectionalLangTag(e),[s,a]=this.parseDirectionalLangTag(t),c=r.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":a&&i!==a?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof R.Literal)return e.datatype?e.datatype:e.language?new be.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new be.IRI("http://www.w3.org/2001/XMLSchema#string");throw new Error("DATATYPE: argument must be a literal")}static bound(e){return e!==void 0}static isIRI(e){return e===void 0?!1:e instanceof be.IRI}static isBlank(e){return e===void 0?!1:e instanceof Lr.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof R.Literal}static isTriple(e){return e===void 0?!1:e instanceof To.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof R.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof R.Literal))return!1;let t=e.datatype?.value;return t?["http://www.w3.org/2001/XMLSchema#integer","http://www.w3.org/2001/XMLSchema#decimal","http://www.w3.org/2001/XMLSchema#float","http://www.w3.org/2001/XMLSchema#double","http://www.w3.org/2001/XMLSchema#nonPositiveInteger","http://www.w3.org/2001/XMLSchema#negativeInteger","http://www.w3.org/2001/XMLSchema#long","http://www.w3.org/2001/XMLSchema#int","http://www.w3.org/2001/XMLSchema#short","http://www.w3.org/2001/XMLSchema#byte","http://www.w3.org/2001/XMLSchema#nonNegativeInteger","http://www.w3.org/2001/XMLSchema#unsignedLong","http://www.w3.org/2001/XMLSchema#unsignedInt","http://www.w3.org/2001/XMLSchema#unsignedShort","http://www.w3.org/2001/XMLSchema#unsignedByte","http://www.w3.org/2001/XMLSchema#positiveInteger"].includes(t):!1}static regex(e,t,r){try{let i=r?r.includes("u")?r:r+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}static compare(e,t,r){if(this.isDayTimeDurationValue(e)&&this.isDayTimeDurationValue(t))return this.compareDurations(e instanceof R.Literal?e:String(e),t instanceof R.Literal?t:String(t),r);if(this.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return this.compareDurations(e instanceof R.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&this.isDayTimeDurationValue(t))return this.compareDurations(e,t instanceof R.Literal?t:String(t),r);let i=this.toComparableValue(e),s=this.toComparableValue(t);switch(r){case"=":return i===s;case"!=":return i!==s;case"<":return i<s;case">":return i>s;case"<=":return i<=s;case">=":return i>=s;default:throw new Error(`Unknown comparison operator: ${r}`)}}static isDayTimeDurationValue(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static toComparableValue(e){if(typeof e=="string"||typeof e=="number")return e;if(e instanceof R.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let r=parseFloat(e.value);if(!isNaN(r))return r}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return this.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof be.IRI?e.value:e instanceof Lr.BlankNode?e.id:String(e)}static contains(e,t){return e.includes(t)}static strStarts(e,t){return e.startsWith(t)}static strEnds(e,t){return e.endsWith(t)}static strlen(e){return e.length}static ucase(e){return e.toUpperCase()}static lcase(e){return e.toLowerCase()}static substr(e,t,r){let i=t-1;if(i<0){if(r!==void 0){let s=r+i;return s<=0?"":e.substring(0,s)}return e}return r!==void 0?e.substring(i,i+r):e.substring(i)}static strBefore(e,t){if(t==="")return"";let r=e.indexOf(t);return r===-1?"":e.substring(0,r)}static strAfter(e,t){if(t==="")return e;let r=e.indexOf(t);return r===-1?"":e.substring(r+t.length)}static concat(...e){return e.join("")}static replace(e,t,r,i){try{let s=i||"g",a=s.includes("u")?s:s+"u",c=new RegExp(t,a);return e.replace(c,r)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static parseDate(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`PARSEDATE: invalid date string '${e}'`);return t.getTime()}static dateBefore(e,t){let r=this.parseDate(e),i=this.parseDate(t);return r<i}static dateAfter(e,t){let r=this.parseDate(e),i=this.parseDate(t);return r>i}static dateInRange(e,t,r){let i=this.parseDate(e),s=this.parseDate(t),a=this.parseDate(r);return i>=s&&i<=a}static dateDiffMinutes(e,t){let r=this.parseDate(e),i=this.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=this.parseDate(e),i=this.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60*60)*100)/100}static logicalAnd(e){return e.every(t=>t===!0)}static logicalOr(e){return e.some(t=>t===!0)}static logicalNot(e){return!e}static year(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return t.getFullYear()}static month(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return t.getMonth()+1}static day(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return t.getDate()}static hours(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return t.getHours()}static minutes(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return t.getMinutes()}static seconds(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return t.getSeconds()+t.getMilliseconds()/1e3}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let r;if(e.endsWith("Z"))r="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),a=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);a===0?r=`${c}PT${l}H`:r=`${c}PT${l}H${a}M`}else{let s=-t.getTimezoneOffset(),a=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?r=`${l}PT${a}H`:r=`${l}PT${a}H${c}M`}}return new R.Literal(r,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static tz(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TZ: invalid date string '${e}'`);if(e.endsWith("Z"))return"Z";let r=e.match(/([+-]\d{2}:\d{2})$/);if(r)return r[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static now(){return new Date().toISOString()}static msToMinutes(e){return Math.round(e/(1e3*60))}static msToHours(e){return Math.round(e/(1e3*60*60)*100)/100}static msToSeconds(e){return Math.round(e/1e3)}static abs(e){return Math.abs(e)}static round(e){return Math.round(e)}static ceil(e){return Math.ceil(e)}static floor(e){return Math.floor(e)}static rand(){return Math.random()}static coalesce(e){for(let t of e)if(t!=null)return t}static if(e,t,r){return e?t:r}static xsdDateTime(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`xsd:dateTime: invalid date string '${e}'`);return new R.Literal(t.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static xsdInteger(e){let t=parseInt(e,10);if(isNaN(t))throw new Error(`xsd:integer: cannot convert '${e}' to integer`);return new R.Literal(String(t),new be.IRI("http://www.w3.org/2001/XMLSchema#integer"))}static xsdDecimal(e){let t=parseFloat(e);if(isNaN(t))throw new Error(`xsd:decimal: cannot convert '${e}' to decimal`);return new R.Literal(String(t),new be.IRI("http://www.w3.org/2001/XMLSchema#decimal"))}static encodeForUri(e){return encodeURIComponent(e)}static md5(e){return require("crypto").createHash("md5").update(e).digest("hex")}static sha1(e){return require("crypto").createHash("sha1").update(e).digest("hex")}static sha256(e){return require("crypto").createHash("sha256").update(e).digest("hex")}static sha384(e){return require("crypto").createHash("sha384").update(e).digest("hex")}static sha512(e){return require("crypto").createHash("sha512").update(e).digest("hex")}static sameTerm(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0||e.constructor!==t.constructor)return!1;if(e instanceof be.IRI&&t instanceof be.IRI)return e.value===t.value;if(e instanceof Lr.BlankNode&&t instanceof Lr.BlankNode)return e.id===t.id;if(e instanceof R.Literal&&t instanceof R.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let r=e.datatype?.value,i=t.datatype?.value;return r===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof be.IRI)return e;if(e instanceof R.Literal)return new be.IRI(e.value);throw e instanceof Lr.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return this.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,qy.v4)().replace(/-/g,"").substring(0,12)}`;return new Lr.BlankNode(t)}if(e instanceof R.Literal)return new Lr.BlankNode(e.value);if(e instanceof Lr.BlankNode)return e;throw new Error("BNODE: argument must be a string literal or omitted")}static strdt(e,t){if(e===void 0)throw new Error("STRDT: lexical form is undefined");if(t===void 0)throw new Error("STRDT: datatype IRI is undefined");let r;if(e instanceof R.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof be.IRI)i=t;else if(t instanceof R.Literal)i=new be.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new R.Literal(r,i)}static strlang(e,t){if(e===void 0)throw new Error("STRLANG: lexical form is undefined");if(t===void 0)throw new Error("STRLANG: language tag is undefined");let r;if(e instanceof R.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof R.Literal)i=t.value;else if(typeof t=="string")i=t;else throw new Error("STRLANG: language tag must be a string literal");if(i==="")throw new Error("STRLANG: language tag cannot be empty");return new R.Literal(r,void 0,i)}static strlangdir(e,t,r){if(e===void 0)throw new Error("STRLANGDIR: lexical form is undefined");if(t===void 0)throw new Error("STRLANGDIR: language tag is undefined");if(r===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof R.Literal){if(e.language)throw new Error("STRLANGDIR: lexical form must not already have a language tag");i=e.value}else if(typeof e=="string")i=e;else throw new Error("STRLANGDIR: lexical form must be a string literal");let s;if(t instanceof R.Literal)s=t.value;else if(typeof t=="string")s=t;else throw new Error("STRLANGDIR: language tag must be a string literal");if(s==="")throw new Error("STRLANGDIR: language tag cannot be empty");let a;if(r instanceof R.Literal)a=r.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(a!=="ltr"&&a!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${a}'. Must be 'ltr' or 'rtl'`);return new R.Literal(i,void 0,s,a)}static uuid(){let e=(0,qy.v4)();return new be.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,qy.v4)();return new R.Literal(e)}static parseDayTimeDuration(e){if(!e)throw new Error("parseDayTimeDuration: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=r.indexOf("T"),a="",c="";if(s===-1?a=r:(a=r.substring(0,s),c=r.substring(s+1)),a){let l=a.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(a!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${a}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let d=parseFloat(u[1]);i+=d*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let d=parseFloat(f[1]);i+=d*60*1e3,l=l.substring(f[0].length)}let h=l.match(/^(\d+(?:\.\d+)?)S$/);if(h){let d=parseFloat(h[1]);i+=d*1e3,l=l.substring(h[0].length)}if(l!=="")throw new Error(`parseDayTimeDuration: invalid time component: '${l}' in '${e}'`)}return t?-i:i}static formatDayTimeDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/(1440*60*1e3));r=r%(1440*60*1e3);let s=Math.floor(r/(3600*1e3));r=r%(3600*1e3);let a=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||a>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),a>0&&(l+=`${a}M`),(c>0||s===0&&a===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return this.parseDayTimeDuration(e),new R.Literal(e,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static compareDurations(e,t,r){let i=e instanceof R.Literal?e.value:e,s=t instanceof R.Literal?t.value:t,a=this.parseDayTimeDuration(i),c=this.parseDayTimeDuration(s);switch(r){case"=":return a===c;case"!=":return a!==c;case"<":return a<c;case">":return a>c;case"<=":return a<=c;case">=":return a>=c;default:throw new Error(`compareDurations: unknown operator: ${r}`)}}static isDayTimeDuration(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static dateDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r),a=this.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);if(a===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-a.getTime(),l=Math.round(c/(1440*60*1e3)),u=this.formatDateDuration(l);return new R.Literal(u,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,a=parseInt(r[3],10),c=r[4],l=new Date(Date.UTC(i,s,a));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,h=parseInt(u[2],10),d=parseInt(u[3],10),p=f*(h*60+d)*60*1e3;l=new Date(l.getTime()-p)}}return l}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,r=Math.abs(e);return t?`-P${r}D`:`P${r}D`}static dateTimeDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r),a=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(a.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-a.getTime(),l=this.formatDayTimeDuration(c);return new R.Literal(l,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c);return new R.Literal(l.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c);return new R.Literal(l.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),h=String(l.getUTCDate()).padStart(2,"0"),d=`${u}-${f}-${h}`;return new R.Literal(d,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let a=this.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),h=String(l.getUTCDate()).padStart(2,"0"),d=`${u}-${f}-${h}`;return new R.Literal(d,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+a;return i?-c:c}static isYearMonthDuration(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static dateTimeAddYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0),new R.Literal(s.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0),new R.Literal(s.toISOString(),new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),h=`${l}-${u}-${f}`;return new R.Literal(h,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let a=this.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),h=`${l}-${u}-${f}`;return new R.Literal(h,new be.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseDayTimeDuration(r),a=this.parseDayTimeDuration(i),c=this.formatDayTimeDuration(s+a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseDayTimeDuration(r),a=this.parseDayTimeDuration(i),c=this.formatDayTimeDuration(s-a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof R.Literal?e.value:e,i=this.parseDayTimeDuration(r),s=this.formatDayTimeDuration(i*t);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let r=e instanceof R.Literal?e.value:e,i=this.parseDayTimeDuration(r),s=this.formatDayTimeDuration(i/t);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static formatYearMonthDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/12),s=r%12,a=t?"-P":"P";return i>0&&(a+=`${i}Y`),(s>0||i===0)&&(a+=`${s}M`),a}static yearMonthDurationAdd(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseYearMonthDuration(r),a=this.parseYearMonthDuration(i),c=this.formatYearMonthDuration(s+a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseYearMonthDuration(r),a=this.parseYearMonthDuration(i),c=this.formatYearMonthDuration(s-a);return new R.Literal(c,new be.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:a,negative:i}}static durationYears(e){let t=e instanceof R.Literal?e.value:e,r=this.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof R.Literal?e.value:e,r=this.parseYearMonthDurationComponents(t);return r.negative?-r.months:r.months}static durationToDays(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof R.Literal?e.value:e;return this.parseDayTimeDuration(t)/1e3}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,a=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let h=u.match(/^(\d+(?:\.\d+)?)D$/);if(h)i=parseFloat(h[1]);else if(u!=="")throw new Error(`parseDurationComponents: invalid day component: '${u}' in '${e}'`)}if(f){let h=f,d=h.match(/^(\d+(?:\.\d+)?)H/);d&&(s=parseFloat(d[1]),h=h.substring(d[0].length));let p=h.match(/^(\d+(?:\.\d+)?)M/);p&&(a=parseFloat(p[1]),h=h.substring(p[0].length));let _=h.match(/^(\d+(?:\.\d+)?)S$/);if(_&&(c=parseFloat(_[1]),h=h.substring(_[0].length)),h!=="")throw new Error(`parseDurationComponents: invalid time component: '${h}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:a,seconds:c}}static durationDays(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof R.Literal?e.value:e,r=this.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static adjust(e,t){let r=e instanceof R.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let $=i.getUTCFullYear(),re=String(i.getUTCMonth()+1).padStart(2,"0"),De=String(i.getUTCDate()).padStart(2,"0"),N=String(i.getUTCHours()).padStart(2,"0"),q=String(i.getUTCMinutes()).padStart(2,"0"),ge=String(i.getUTCSeconds()).padStart(2,"0"),ot=i.getUTCMilliseconds(),Ke=`${$}-${re}-${De}T${N}:${q}:${ge}`;return ot>0&&(Ke+=`.${String(ot).padStart(3,"0")}`),new R.Literal(Ke,new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof R.Literal?t.value:t,a=this.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(a)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+a),f=u.getUTCFullYear(),h=String(u.getUTCMonth()+1).padStart(2,"0"),d=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),_=String(u.getUTCMinutes()).padStart(2,"0"),b=String(u.getUTCSeconds()).padStart(2,"0"),E=u.getUTCMilliseconds(),A=a>=0?"+":"-",C=Math.floor(Math.abs(a)/(3600*1e3)),j=Math.floor(Math.abs(a)%(3600*1e3)/(60*1e3)),Q=`${A}${String(C).padStart(2,"0")}:${String(j).padStart(2,"0")}`,K=`${f}-${h}-${d}T${p}:${_}:${b}`;return E>0&&(K+=`.${String(E).padStart(3,"0")}`),K+=Q,new R.Literal(K,new be.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static normalize(e,t){if(e===void 0)throw new Error("NORMALIZE: string argument is undefined");let r;if(e instanceof R.Literal)r=e.value;else if(e instanceof be.IRI)r=e.value;else if(e instanceof Lr.BlankNode)r=e.id;else if(typeof e=="string")r=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof R.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof be.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!this.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=r.normalize(i);return new R.Literal(s,new be.IRI("http://www.w3.org/2001/XMLSchema#string"))}static fold(e){if(e===void 0)throw new Error("FOLD: string argument is undefined");let t;if(e instanceof R.Literal)t=e.value;else if(e instanceof be.IRI)t=e.value;else if(e instanceof Lr.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let r=this.unicodeCaseFold(t);return new R.Literal(r,new be.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let r of e){let i=this.CASE_FOLDING_MAP.get(r);i!==void 0?t+=i:t+=r.toLowerCase()}return t}static isTime(e){return e instanceof R.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static timeDiff(e,t){let r=e instanceof R.Literal?e.value:e,i=t instanceof R.Literal?t.value:t,s=this.parseXSDTime(r),a=this.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(a===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-a,l=this.formatDayTimeDuration(c);return new R.Literal(l,new be.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r)return null;let i=parseInt(r[1],10),s=parseInt(r[2],10),a=parseInt(r[3],10),c=r[4],l=r[5];if(i<0||i>24||s<0||s>59||a<0||a>59||i===24&&(s!==0||a!==0))return null;let u=0;if(c){let h=c.padEnd(3,"0").slice(0,3);u=parseInt(h,10)}let f=i*60*60*1e3+s*60*1e3+a*1e3+u;if(i===24&&(f=1440*60*1e3),l&&l!=="Z"){let h=l.match(/([+-])(\d{2}):(\d{2})/);if(h){let d=h[1]==="+"?1:-1,p=parseInt(h[2],10),_=parseInt(h[3],10),b=d*(p*60+_)*60*1e3;f-=b}}return f}static triple(e,t,r){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(r===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof R.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof be.IRI)){let c=t instanceof R.Literal?"Literal":t instanceof Lr.BlankNode?"BlankNode":t instanceof To.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,a=r;return new To.QuotedTriple(i,s,a)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`SUBJECT: argument must be QuotedTriple, got ${t}`)}return e.subject}static predicate(e){if(e===void 0)throw new Error("PREDICATE: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`PREDICATE: argument must be QuotedTriple, got ${t}`)}return e.predicate}static object(e){if(e===void 0)throw new Error("OBJECT: argument is undefined");if(!(e instanceof To.QuotedTriple)){let t=e instanceof be.IRI?"IRI":e instanceof R.Literal?"Literal":e instanceof Lr.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};wh.BuiltInFunctions=al;al.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];al.CASE_FOLDING_MAP=new Map([["\xDF","ss"],["\u1E9E","ss"],["\u03A3","\u03C3"],["\u03C2","\u03C3"],["\u0130","i\u0307"],["I","i"],["\u0587","\u0565\u0582"],["\uFB00","ff"],["\uFB01","fi"],["\uFB02","fl"],["\uFB03","ffi"],["\uFB04","ffl"],["\uFB05","st"],["\uFB06","st"],["\u0390","\u03B9\u0308\u0301"],["\u03B0","\u03C5\u0308\u0301"],["\u017F","s"],["\u1E9B","\u1E61"],["\u212A","k"],["\u212B","\xE5"]])});var $w=v(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.functionHandlers=void 0;var L=Eh();k.functionHandlers=new Map;k.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.str(t)});k.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.lang(t)});k.functionHandlers.set("langmatches",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.langMatches(t,r)});k.functionHandlers.set("contains",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.contains(t,r)});k.functionHandlers.set("strstarts",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strStarts(t,r)});k.functionHandlers.set("strends",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strEnds(t,r)});k.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.strlen(t)});k.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.ucase(t)});k.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.lcase(t)});k.functionHandlers.set("substr",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=Number(e.evaluateExpression(n[1],e.solution));if(n[2]){let i=Number(e.evaluateExpression(n[2],e.solution));return L.BuiltInFunctions.substr(t,r,i)}return L.BuiltInFunctions.substr(t,r)});k.functionHandlers.set("strbefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strBefore(t,r)});k.functionHandlers.set("strafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.strAfter(t,r)});k.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return L.BuiltInFunctions.concat(...t)});k.functionHandlers.set("replace",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution)),s=n[3]?e.getStringValue(e.evaluateExpression(n[3],e.solution)):void 0;return L.BuiltInFunctions.replace(t,r,i,s)});k.functionHandlers.set("regex",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=n[2]?e.getStringValue(e.evaluateExpression(n[2],e.solution)):void 0;return L.BuiltInFunctions.regex(t,r,i)});k.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.encodeForUri(t)});k.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.datatype(t).value});k.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return L.BuiltInFunctions.bound(r)}return!0});var Rw=o((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isIRI(t)},"isIriHandler");k.functionHandlers.set("isiri",Rw);k.functionHandlers.set("isuri",Rw);k.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isBlank(t)});k.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isLiteral(t)});k.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isNumeric(t)});k.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.hasLangdir(t)});k.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.isTriple(t)});k.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return L.BuiltInFunctions.sameTerm(t,r)});k.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.abs(t)});k.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.round(t)});k.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.ceil(t)});k.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return L.BuiltInFunctions.floor(t)});k.functionHandlers.set("rand",()=>L.BuiltInFunctions.rand());k.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.parseDate(t)});k.functionHandlers.set("datebefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateBefore(t,r)});k.functionHandlers.set("dateafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateAfter(t,r)});k.functionHandlers.set("dateinrange",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution));return L.BuiltInFunctions.dateInRange(t,r,i)});k.functionHandlers.set("datediffminutes",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateDiffMinutes(t,r)});k.functionHandlers.set("datediffhours",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return L.BuiltInFunctions.dateDiffHours(t,r)});var xo=o((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),Fw=xo(L.BuiltInFunctions.year.bind(L.BuiltInFunctions),L.BuiltInFunctions.durationYears.bind(L.BuiltInFunctions),null);k.functionHandlers.set("year",Fw);k.functionHandlers.set("years",Fw);var Dw=xo(L.BuiltInFunctions.month.bind(L.BuiltInFunctions),L.BuiltInFunctions.durationMonths.bind(L.BuiltInFunctions),null);k.functionHandlers.set("month",Dw);k.functionHandlers.set("months",Dw);var Nw=xo(L.BuiltInFunctions.day.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationDays.bind(L.BuiltInFunctions));k.functionHandlers.set("day",Nw);k.functionHandlers.set("days",Nw);k.functionHandlers.set("hours",xo(L.BuiltInFunctions.hours.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationHours.bind(L.BuiltInFunctions)));k.functionHandlers.set("minutes",xo(L.BuiltInFunctions.minutes.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationMinutes.bind(L.BuiltInFunctions)));k.functionHandlers.set("seconds",xo(L.BuiltInFunctions.seconds.bind(L.BuiltInFunctions),null,L.BuiltInFunctions.durationSeconds.bind(L.BuiltInFunctions)));k.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.timezone(t)});k.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.tz(t)});k.functionHandlers.set("adjust",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=n.length>1?e.evaluateExpression(n[1],e.solution):void 0;return L.BuiltInFunctions.adjust(t,r)});k.functionHandlers.set("now",()=>L.BuiltInFunctions.now());var Lw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");k.functionHandlers.set("datetime",Lw);k.functionHandlers.set("xsd:datetime",Lw);var kw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");k.functionHandlers.set("integer",kw);k.functionHandlers.set("xsd:integer",kw);var Mw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");k.functionHandlers.set("decimal",Mw);k.functionHandlers.set("xsd:decimal",Mw);var jw=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");k.functionHandlers.set("daytimeduration",jw);k.functionHandlers.set("xsd:daytimeduration",jw);k.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToDays(t)});k.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToHours(t)});k.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToMinutes(t)});k.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationToSeconds(t)});k.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationDays(t)});k.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationHours(t)});k.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationMinutes(t)});k.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationSeconds(t)});k.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationYears(t)});k.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return L.BuiltInFunctions.durationMonths(t)});k.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeDiff(t,r)});k.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeAdd(t,r)});k.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return L.BuiltInFunctions.dateTimeSubtract(t,r)});k.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToMinutes(t)});k.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToHours(t)});k.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.msToSeconds(t)});k.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.md5(t)});k.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha1(t)});k.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha256(t)});k.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha384(t)});k.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return L.BuiltInFunctions.sha512(t)});k.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.subject(t)});k.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.predicate(t)});k.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return L.BuiltInFunctions.object(t)});k.functionHandlers.set("triple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution),i=e.getTermFromExpression(n[2],e.solution);return L.BuiltInFunctions.triple(t,r,i)})});var Th=v(Ao=>{"use strict";Object.defineProperty(Ao,"__esModule",{value:!0});Ao.FilterExecutor=Ao.FilterExecutorError=void 0;var ht=Eh(),lL=$w(),va=mt(),sr=class extends Error{static{o(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Ao.FilterExecutorError=sr;var Gy=class{static{o(this,"FilterExecutor")}constructor(){this.existsEvaluator=null,this.tripleStore=null,this.uuidCache=new Map}setExistsEvaluator(e){this.existsEvaluator=e}setTripleStore(e){this.tripleStore=e,this.uuidCache.clear()}async*execute(e,t){let r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(e.type==="exists")return!0;if(e.type==="logical")return e.operands.some(t=>this.expressionContainsExists(t));if(e.type==="comparison")return this.expressionContainsExists(e.left)||this.expressionContainsExists(e.right);if(e.type==="in"){let t=e;return this.expressionContainsExists(t.expression)||t.list.some(r=>this.expressionContainsExists(r))}return!1}async executeAll(e,t){let r=[];async function*i(){for(let s of t)yield s}o(i,"generator");for await(let s of this.execute(e,i()))r.push(s);return r}evaluateExpression(e,t){let r=e;if(r.termType)switch(r.termType){case"Variable":return t.get(r.value);case"Literal":return r.value;case"NamedNode":return r.value;default:throw new sr(`Unsupported termType: ${r.termType}`)}switch(e.type){case"comparison":return this.evaluateComparison(e,t);case"logical":return this.evaluateLogical(e,t);case"arithmetic":return this.evaluateArithmetic(e,t);case"function":case"functionCall":return this.evaluateFunction(e,t);case"variable":return t.get(e.name);case"literal":return e.value;case"in":return this.evaluateIn(e,t);case"exists":throw new sr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new sr(`Unsupported expression type: ${e.type}, expr.termType=${r.termType}`)}}async evaluateExpressionAsync(e,t){return e.type==="exists"?this.evaluateExists(e,t):e.type==="logical"?this.evaluateLogicalAsync(e,t):this.evaluateExpression(e,t)}async evaluateExists(e,t){if(!this.existsEvaluator)throw new sr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let r=await this.existsEvaluator(e.pattern,t);return e.negated?!r:r}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let i=await this.evaluateExpressionAsync(e.operands[0],t);return ht.BuiltInFunctions.logicalNot(i)}let r=[];for(let i of e.operands){let s=await this.evaluateExpressionAsync(i,t);r.push(s)}if(e.operator==="&&")return ht.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return ht.BuiltInFunctions.logicalOr(r);throw new sr(`Unknown logical operator: ${e.operator}`)}evaluateComparison(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return ht.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return ht.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return ht.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return ht.BuiltInFunctions.logicalOr(r);throw new sr(`Unknown logical operator: ${e.operator}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let a=this.evaluateExpression(s,t);return ht.BuiltInFunctions.compare(r,a,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return ht.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return ht.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return ht.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return ht.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return ht.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return ht.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new sr("Division by zero");return ht.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return ht.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),a=this.toNumericValue(i);switch(e.operator){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":if(a===0)throw new sr("Division by zero");return s/a;default:throw new sr(`Unknown arithmetic operator: ${e.operator}`)}}isDayTimeDurationValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof va.Literal){let t=e.datatype?.value||"";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let i=parseFloat(e.value);if(!isNaN(i))return i}let r=parseFloat(e.value);if(!isNaN(r))return r}if(typeof e=="string"){let t=parseFloat(e);if(!isNaN(t))return t}if(e&&typeof e=="object"&&"value"in e){let t=parseFloat(String(e.value));if(!isNaN(t))return t}throw new sr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof va.Literal){let t=e.datatype?.value||"";return t.includes("#dateTime")||t.includes("#date")?!0:/^\d{4}-\d{2}-\d{2}(T|\s)/.test(e.value)}return typeof e=="string"?/^\d{4}-\d{2}-\d{2}(T|\s)/.test(e):!1}isDateValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof va.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let a=lL.functionHandlers.get(i);if(!a)throw new sr(`Unknown function: ${i}`);let c={evaluateExpression:o((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:o((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:o(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:o(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:o(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return a(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new sr(`Unknown function format: ${e}`)}evaluateSpecialFunction(e,t,r){switch(e){case"coalesce":for(let c of t)try{let l=this.evaluateExpression(c,r);if(l!=null)return{value:l}}catch{continue}return{value:void 0};case"if":if(!t||t.length!==3)throw new sr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],r);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],r):this.evaluateExpression(t[2],r)};case"byuuid":return{value:this.evaluateByUUID({args:t},r)};default:return}}getTermFromExpression(e,t){let r=e;if(r.type==="variable"&&r.name)return t.get(r.name)}getStringValue(e){return e==null?"":typeof e=="object"&&"value"in e?String(e.value):String(e)}toBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="number")return!isNaN(e)&&e!==0;if(typeof e=="string")return e.length>0;if(e instanceof va.Literal){let t=e.datatype?.value||"";if(t.includes("#boolean"))return e.value==="true"||e.value==="1";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let r=parseFloat(e.value);return!isNaN(r)&&r!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new sr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let a=this.tripleStore.findSubjectsByUUIDSync(s);if(a.length===0){this.uuidCache.set(s,null);return}let c=a[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Ao.FilterExecutor=Gy});var Hy=v(xh=>{"use strict";Object.defineProperty(xh,"__esModule",{value:!0});xh.OptionalExecutor=void 0;var Wy=class{static{o(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let a="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,a),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,a),f=c.get(u),h=!1;if(f)for(let d of f){let p=l.merge(d);p!==null&&(yield p,h=!0)}h||(yield l)}}computeHashKey(e,t,r){let i=[];for(let s of t){let a=e.get(s);i.push(a!==void 0?a.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let a=r.merge(s);a!==null&&(yield a,i=!0)}i||(yield r)}}};xh.OptionalExecutor=Wy});var Qy=v(Ah=>{"use strict";Object.defineProperty(Ah,"__esModule",{value:!0});Ah.UnionExecutor=void 0;var zy=class{static{o(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Ah.UnionExecutor=zy});var Jy=v(Ch=>{"use strict";Object.defineProperty(Ch,"__esModule",{value:!0});Ch.ConstructExecutor=void 0;var uL=_i(),_a=We(),Yy=mt(),Ky=kt(),fL=Lc(),Xy=class{static{o(this,"ConstructExecutor")}async execute(e,t){let r=[],i=new Set;for(let s of t)for(let a of e)try{let c=this.instantiateTriple(a,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new uL.Triple(r,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable: ${e.value}`);return r}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="literal")return new Yy.Literal(e.value,e.datatype?new _a.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let r=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new fL.QuotedTriple(r,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(r instanceof Yy.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Invalid element type for quoted triple subject: ${e.type}`)}instantiateQuotedPredicate(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(r instanceof _a.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new _a.IRI(e.value)}instantiateQuotedObject(e,t){if(e.type==="variable"){let i=t.get(e.value);if(!i)throw new Error(`Unbound variable in quoted triple object: ${e.value}`);return i}if(e.type==="iri")return new _a.IRI(e.value);if(e.type==="blank")return new Ky.BlankNode(e.value);if(e.type==="literal")return new Yy.Literal(e.value,e.datatype?new _a.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let r=e;throw new Error(`Invalid element type for quoted triple object: ${r.type}`)}};Ch.ConstructExecutor=Xy});var Uw=v(Ih=>{"use strict";Object.defineProperty(Ih,"__esModule",{value:!0});Ih.DescribeExecutor=void 0;var Vw=We(),Zy=class{static{o(this,"DescribeExecutor")}constructor(e){this.tripleStore=e}async execute(e,t){let r=[],i=new Set,s=new Set,a=t?.depth;for(let c of e)await this.describeResourceWithDepth(c,a,1,t?.symmetric??!0,r,i,s);return r}async describeResourceWithDepth(e,t,r,i,s,a,c){let l=e.toString();if(c.has(l)||(c.add(l),t!==void 0&&r>t))return;let u=[],f=await this.tripleStore.match(e,void 0,void 0);if(u.push(...f),i){let d=await this.tripleStore.match(void 0,void 0,e);u.push(...d)}let h=[];for(let d of u){let p=`${d.subject.toString()}|${d.predicate.toString()}|${d.object.toString()}`;a.has(p)||(a.add(p),s.push(d),(t===void 0||r<t)&&(this.isIRI(d.subject)&&d.subject.toString()!==l&&h.push(d.subject),this.isIRI(d.object)&&d.object.toString()!==l&&h.push(d.object)))}for(let d of h)await this.describeResourceWithDepth(d,t,r+1,i,s,a,c)}isIRI(e){return e?e instanceof Vw.IRI||e.termType==="NamedNode"||typeof e.value=="string"&&e.value.startsWith("http"):!1}async describeByIRI(e,t){let r=new Vw.IRI(e);return this.execute([r],t)}};Ih.DescribeExecutor=Zy});var Bw=v(Ph=>{"use strict";Object.defineProperty(Ph,"__esModule",{value:!0});Ph.MinusExecutor=void 0;var e1=class{static{o(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let a=!1;for(let c of i)if(this.areCompatible(s,c)){a=!0;break}a||(yield s)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.filter(a=>i.has(a));if(s.length===0)return!1;for(let a of s){let c=e.get(a),l=t.get(a);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};Ph.MinusExecutor=e1});var Gw=v(Co=>{"use strict";Object.defineProperty(Co,"__esModule",{value:!0});Co.ValuesExecutor=Co.ValuesExecutorError=void 0;var hL=es(),qw=We(),dL=mt(),Oh=class extends Error{static{o(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Co.ValuesExecutorError=Oh;var t1=class{static{o(this,"ValuesExecutor")}async*execute(e){if(e.bindings.length!==0)for(let t of e.bindings)yield this.createSolutionMapping(t)}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new hL.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(r,s)}return t}toRDFTerm(e){if(e.type==="iri")return new qw.IRI(e.value);if(e.type==="literal")return new dL.Literal(e.value,e.datatype?new qw.IRI(e.datatype):void 0,e.language,e.direction);throw new Oh(`Unknown term type: ${e.type}`)}};Co.ValuesExecutor=t1});var r1=v(Po=>{"use strict";Object.defineProperty(Po,"__esModule",{value:!0});Po.CustomAggregateRegistry=Po.CustomAggregateError=void 0;var Io=class extends Error{static{o(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};Po.CustomAggregateError=Io;var Rh=class n{static{o(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new Io("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new Io("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new Io(`Aggregate with IRI "${e}" is already registered`,e);this.aggregates.set(e,t)}unregister(e){return this.aggregates.delete(e)}get(e){return this.aggregates.get(e)}has(e){return this.aggregates.has(e)}getRegisteredIris(){return Array.from(this.aggregates.keys())}clear(){this.aggregates.clear()}get size(){return this.aggregates.size}};Po.CustomAggregateRegistry=Rh;Rh.instance=null});var n1=v(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.BUILT_IN_AGGREGATES=qe.modeAggregate=qe.stddevAggregate=qe.varianceAggregate=qe.medianAggregate=qe.EXO_AGGREGATE_NS=void 0;qe.getNumericValue=Fh;qe.createDecimalLiteral=ri;qe.createDoubleLiteral=gL;qe.createPercentileAggregate=ba;var Sa=mt(),Oo=We(),pL=new Oo.IRI("http://www.w3.org/2001/XMLSchema#decimal"),mL=new Oo.IRI("http://www.w3.org/2001/XMLSchema#double");qe.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Fh(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof Sa.Literal?parseFloat(n.value):n instanceof Oo.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}o(Fh,"getNumericValue");function ri(n){return new Sa.Literal(String(n),pL)}o(ri,"createDecimalLiteral");function gL(n){return new Sa.Literal(String(n),mL)}o(gL,"createDoubleLiteral");qe.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Fh(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=[...t].sort((a,c)=>a-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return ri(s)}};qe.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Fh(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ri(i)}};qe.stddevAggregate={init(){return{values:[]}},step(n,e){qe.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ri(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ri(Math.sqrt(i))}};qe.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof Sa.Literal||e instanceof Oo.IRI?e.value:e),i=t.counts.get(r)||0;t.counts.set(r,i+1),t.values.set(r,e)},finalize(n){let e=n;if(e.counts.size===0)return new Sa.Literal(" ",new Oo.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[a,c]of e.counts)c>r&&(r=c,t=a);let i=e.values.get(t);if(i instanceof Sa.Literal)return i;let s=parseFloat(t);return isNaN(s)?new Sa.Literal(t,new Oo.IRI("http://www.w3.org/2001/XMLSchema#string")):ri(s)}};function ba(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Fh(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return ri(0);let s=[...i].sort((h,d)=>h-d),a=r.percentile*(s.length-1),c=Math.floor(a),l=Math.ceil(a);if(c===l)return ri(s[c]);let u=a-c,f=s[c]*(1-u)+s[l]*u;return ri(f)}}}o(ba,"createPercentileAggregate");qe.BUILT_IN_AGGREGATES={[`${qe.EXO_AGGREGATE_NS}median`]:qe.medianAggregate,[`${qe.EXO_AGGREGATE_NS}variance`]:qe.varianceAggregate,[`${qe.EXO_AGGREGATE_NS}stddev`]:qe.stddevAggregate,[`${qe.EXO_AGGREGATE_NS}mode`]:qe.modeAggregate,[`${qe.EXO_AGGREGATE_NS}percentile25`]:ba(25),[`${qe.EXO_AGGREGATE_NS}percentile50`]:ba(50),[`${qe.EXO_AGGREGATE_NS}percentile75`]:ba(75),[`${qe.EXO_AGGREGATE_NS}percentile90`]:ba(90),[`${qe.EXO_AGGREGATE_NS}percentile95`]:ba(95),[`${qe.EXO_AGGREGATE_NS}percentile99`]:ba(99)}});var zw=v(Ro=>{"use strict";Object.defineProperty(Ro,"__esModule",{value:!0});Ro.AggregateExecutor=Ro.AggregateExecutorError=void 0;var jt=mt(),s1=We(),yL=Th(),vL=r1(),_L=n1(),Ww=new s1.IRI("http://www.w3.org/2001/XMLSchema#integer"),wa=new s1.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Ai=new s1.IRI("http://www.w3.org/2001/XMLSchema#string");function Hw(n){return typeof n=="object"&&n.type==="custom"}o(Hw,"isCustomAggregation");var ol=class extends Error{static{o(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};Ro.AggregateExecutorError=ol;var i1=class{static{o(this,"AggregateExecutor")}constructor(){this.filterExecutor=new yL.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,a]of r.entries()){let c=new Map;for(let f of e.variables)if(a.length>0){let h=a[0].get(f);h&&c.set(f,h)}for(let f of e.aggregates){let h=this.computeAggregate(f.expression,a);c.set(f.variable,h)}let{SolutionMapping:l}=es(),u=new l;for(let[f,h]of c.entries())u.set(f,h);i.push(u)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let r=new Map;if(t.length===0)return r.set("",e),r;for(let i of e){let s=this.computeGroupKey(i,t),a=r.get(s);a?a.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if(Hw(e.aggregation))return this.computeCustomAggregate(e,t);let r=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(r,e.distinct);return new jt.Literal(String(s),Ww)}case"sum":{let s=this.computeSum(r);return new jt.Literal(String(s),wa)}case"avg":{let s=this.computeAvg(r);return new jt.Literal(String(s),wa)}case"min":{let s=this.computeMin(r);return s===void 0?new jt.Literal("",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}case"max":{let s=this.computeMax(r);return s===void 0?new jt.Literal("",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new jt.Literal(s||" ",Ai)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new jt.Literal(" ",Ai):typeof s=="number"?new jt.Literal(String(s),wa):new jt.Literal(String(s),Ai)}default:{let s=i;throw new ol(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,a=vL.CustomAggregateRegistry.getInstance().get(i);if(a||(a=_L.BUILT_IN_AGGREGATES[i]),!a)throw new ol(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=a.init();for(let l of t){let u=null;if(e.expression){let f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;a.step(c,u)}return a.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let a=s[0],c=parseFloat(a);return isNaN(c)?a:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=es(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if(Hw(s)){r.set(i.variable,new jt.Literal("0",wa));continue}switch(s){case"count":r.set(i.variable,new jt.Literal("0",Ww));break;case"sum":case"avg":r.set(i.variable,new jt.Literal("0",wa));break;case"group_concat":r.set(i.variable,new jt.Literal(" ",Ai));break;case"min":case"max":case"sample":r.set(i.variable,new jt.Literal("",Ai));break;default:r.set(i.variable,new jt.Literal("",Ai))}}return r}};Ro.AggregateExecutor=i1});var Yw=v(Fo=>{"use strict";Object.defineProperty(Fo,"__esModule",{value:!0});Fo.ServiceExecutor=Fo.ServiceExecutorError=void 0;var bL=es(),Qw=We(),SL=mt(),wL=kt(),Ea=class extends Error{static{o(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Fo.ServiceExecutorError=Ea;var a1=class{static{o(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,a=setTimeout(()=>s.abort(),this.timeout);try{let c=await this.httpClient(e,{method:"POST",headers:{"Content-Type":"application/sparql-query",Accept:"application/sparql-results+json"},body:t,signal:s.signal});if(!c.ok)throw new Ea(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(a)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new Ea(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new Ea(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,r)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new bL.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(r,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new Qw.IRI(e.value);case"literal":{let t=e.datatype?new Qw.IRI(e.datatype):void 0;return new SL.Literal(e.value,t,e["xml:lang"])}case"bnode":return new wL.BlankNode(e.value);default:throw new Ea(`Unknown RDF term type: ${e.type}`)}}isRetryableError(e){let t=e.message.toLowerCase();return!!(e.name==="AbortError"||t.includes("network")||t.includes("econnreset")||t.includes("econnrefused")||t.includes("etimedout")||t.includes("returned 5"))}delay(e){return new Promise(t=>setTimeout(t,e))}};Fo.ServiceExecutor=a1});var Xw=v(Do=>{"use strict";Object.defineProperty(Do,"__esModule",{value:!0});Do.GraphExecutor=Do.GraphExecutorError=void 0;var Kw=We(),Dh=class extends Error{static{o(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Do.GraphExecutorError=Dh;var o1=class{static{o(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new Dh(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new Kw.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let a=i.get(t.value);if(a&&a instanceof Kw.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:a.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let a of s)for await(let c of r(e.pattern,a)){let l=c.clone();l.set(t.value,a),yield l}}};Do.GraphExecutor=o1});var Jw=v(Lo=>{"use strict";Object.defineProperty(Lo,"__esModule",{value:!0});Lo.SPARQLGenerator=Lo.SPARQLGeneratorError=void 0;var No=class extends Error{static{o(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};Lo.SPARQLGeneratorError=No;var c1=class{static{o(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
316
316
  ${i}
317
317
  }`}generateWhereClause(e,t=2){let r=" ".repeat(t);switch(e.type){case"bgp":return this.generateBGP(e,t);case"filter":return`${this.generateWhereClause(e.input,t)}
318
318
  ${r}FILTER(${this.generateExpression(e.expression)})`;case"join":return`${this.generateWhereClause(e.left,t)}
@@ -603,7 +603,7 @@ Available classes: ${t.join(", ")}`),super(r),this.name="ClassNotFoundError"}},g
603
603
  `));let i=new Mi(e),s=new gp(i),a=new yp(i),l=await new vp(i,s,a).create({classShortName:n.class,label:n.label,aliases:n.aliases,properties:Object.keys(t).length>0?t:void 0,body:r,vault:e,dryRun:n.dryRun,createdBy:n.createdBy,timezone:n.timezone,skipWikilinkValidation:n.skipWikilinkValidation});if(n.dryRun){let f=TU(l.frontmatter,r);process.stderr.write(f+`
604
604
  `)}let u={uuid:l.uuid,path:l.path,label:l.label};process.stdout.write(JSON.stringify(u)+`
605
605
  `),process.exit(0)}catch(e){H.handle(e)}})}o(iI,"createCommand");function EU(n,e){return e.concat([n])}o(EU,"collect");function TU(n,e){let t=["--- DRY RUN PREVIEW ---","---"];for(let[r,i]of Object.entries(n))if(Array.isArray(i)){t.push(`${r}:`);for(let s of i)t.push(` - ${s}`)}else t.push(`${r}: ${i}`);return t.push("---"),e&&(t.push(""),t.push(e)),t.push("--- END PREVIEW ---"),t.join(`
606
- `)}o(TU,"formatFrontmatterPreview");var un=new st;un.name("exocortex").description("CLI tool for Exocortex knowledge management system").version("15.32.7");var bv=un.command("sparql").description("SPARQL query execution and cache management");bv.addCommand(vA());bv.addCommand(wA());bv.addCommand(EA());un.addCommand(RC());un.addCommand(NC());un.addCommand(LC());un.addCommand(MC());un.addCommand(jC());un.addCommand(qC());un.addCommand(zC());un.addCommand(KC());un.addCommand(ZC());un.addCommand(iI());un.parse();
606
+ `)}o(TU,"formatFrontmatterPreview");var un=new st;un.name("exocortex").description("CLI tool for Exocortex knowledge management system").version("15.32.8");var bv=un.command("sparql").description("SPARQL query execution and cache management");bv.addCommand(vA());bv.addCommand(wA());bv.addCommand(EA());un.addCommand(RC());un.addCommand(NC());un.addCommand(LC());un.addCommand(MC());un.addCommand(jC());un.addCommand(qC());un.addCommand(zC());un.addCommand(KC());un.addCommand(ZC());un.addCommand(iI());un.parse();
607
607
  /*! Bundled license information:
608
608
 
609
609
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "15.32.7",
3
+ "version": "15.32.8",
4
4
  "description": "CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more",
5
5
  "main": "dist/index.js",
6
6
  "bin": {