@kitelev/exocortex-cli 17.10.4 → 17.10.5
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.
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v17.10.
|
|
2
|
+
// @kitelev/exocortex-cli v17.10.5
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -100,7 +100,7 @@ Expecting `+Ty.join(", ")+", got '"+(this.terminals_[Mt]||Mt)+"'":tT="Parse erro
|
|
|
100
100
|
`)+`
|
|
101
101
|
`+s.trimStart()),s}findPrefixStarDeclarations(e){let t=[],n=e.toUpperCase(),i=0;for(;i<e.length;){if(e[i]==="'"||e[i]==='"'){let s=e[i];for(i++;i<e.length&&e[i]!==s;)e[i]==="\\"&&i++,i++;i++;continue}if(n.substring(i,i+6)==="PREFIX"){let s=i;for(i+=6;i<e.length&&/\s/.test(e[i]);)i++;if(e[i]==="*"){for(i++;i<e.length&&/\s/.test(e[i]);)i++;if(e[i]==="<"){i++;let o=i;for(;i<e.length&&e[i]!==">";)i++;if(e[i]===">"){let c=e.substring(o,i);i++;let l=this.findDeclarationEnd(e,i);t.push({uri:c,startPos:s,endPos:l}),i=l;continue}else throw new Rf(`Unclosed IRI in PREFIX* declaration at position ${o}`)}else throw new Rf(`Expected IRI after PREFIX* at position ${i}`)}else continue}i++}return t}findDeclarationEnd(e,t){let n=t;for(;n<e.length;){let i=e[n];if(i===`
|
|
102
102
|
`)return n+1;let s=e.substring(n).toUpperCase();if(s.startsWith("PREFIX")||s.startsWith("BASE")||s.startsWith("SELECT")||s.startsWith("CONSTRUCT")||s.startsWith("DESCRIBE")||s.startsWith("ASK"))return n;if(/\s/.test(i)){n++;continue}break}return n}extractPrefixFromUri(e){let t=e.replace(/^https?:\/\//,"");t=t.replace(/\/$/,"").replace(/#$/,"");let n=t.split(/[/.#]+/).filter(Boolean);if(n.length===0)return null;let i=n[n.length-1];return/^(ontology|vocab|schema|ns|core)$/i.test(i)&&n.length>1?n[n.length-2].toLowerCase():i.toLowerCase().replace(/[^a-z0-9]/g,"")}};Cc.PrefixStarTransformer=PA;var Rf=class extends Error{static{a(this,"PrefixStarTransformerError")}constructor(e){super(`PREFIX* transformation error: ${e}`),this.name="PrefixStarTransformerError"}};Cc.PrefixStarTransformerError=Rf});var FA=T(Of=>{"use strict";Object.defineProperty(Of,"__esModule",{value:!0});Of.DescribeOptionsTransformer=Of.DescribeOptionsTransformerError=void 0;var eb=class extends Error{static{a(this,"DescribeOptionsTransformerError")}constructor(e){super(e),this.name="DescribeOptionsTransformerError"}};Of.DescribeOptionsTransformerError=eb;var Cf=class r{static{a(this,"DescribeOptionsTransformer")}transform(e){if(!r.DESCRIBE_QUERY_PATTERN.test(e))return{query:e};let t=e,n={},i=!1,s=r.DEPTH_PATTERN.exec(e);if(s){let o=parseInt(s[1],10);if(o<0)throw new eb(`DESCRIBE DEPTH must be a non-negative integer, got: ${o}`);n.depth=o,i=!0,r.DEPTH_PATTERN.lastIndex=0,t=t.replace(r.DEPTH_PATTERN,"")}return r.DEPTH_PATTERN.lastIndex=0,r.SYMMETRIC_PATTERN.test(e)&&(n.symmetric=!0,i=!0,r.SYMMETRIC_PATTERN.lastIndex=0,t=t.replace(r.SYMMETRIC_PATTERN,"")),r.SYMMETRIC_PATTERN.lastIndex=0,t=t.replace(/\s{2,}/g," ").trim(),{query:t,options:i?n:void 0}}hasDescribeOptions(e){let t=r.DEPTH_PATTERN.test(e);r.DEPTH_PATTERN.lastIndex=0;let n=r.SYMMETRIC_PATTERN.test(e);return r.SYMMETRIC_PATTERN.lastIndex=0,t||n}};Of.DescribeOptionsTransformer=Cf;Cf.DEPTH_PATTERN=/\bDEPTH\s+(\d+)/gi;Cf.SYMMETRIC_PATTERN=/\bSYMMETRIC\b/gi;Cf.DESCRIBE_QUERY_PATTERN=/\bDESCRIBE\b/i});var Yk=T(xf=>{"use strict";Object.defineProperty(xf,"__esModule",{value:!0});xf.DirectionalLangTagTransformerError=xf.DirectionalLangTagTransformer=void 0;var tb=class r{static{a(this,"DirectionalLangTagTransformer")}constructor(){this.directionMappings=new Map}transform(e){return this.directionMappings.clear(),e.replace(r.DIRECTIONAL_TAG_REGEX,(t,n,i,s,o)=>{let c=s.toLowerCase();return this.directionMappings.set(c,o),`${n}${i}${n}@${s}`})}getDirection(e){return this.directionMappings.get(e.toLowerCase())}getAllMappings(){return new Map(this.directionMappings)}hasDirectionalTags(e){return r.DIRECTIONAL_TAG_REGEX.lastIndex=0,r.DIRECTIONAL_TAG_REGEX.test(e)}clearMappings(){this.directionMappings.clear()}};xf.DirectionalLangTagTransformer=tb;tb.DIRECTIONAL_TAG_REGEX=/(["'])((?:[^\\]|\\.)*?)\1@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)--(ltr|rtl)/g;var LA=class extends Error{static{a(this,"DirectionalLangTagTransformerError")}constructor(e){super(`Directional language tag transformation error: ${e}`),this.name="DirectionalLangTagTransformerError"}};xf.DirectionalLangTagTransformerError=LA});var Xk=T(Ff=>{"use strict";Object.defineProperty(Ff,"__esModule",{value:!0});Ff.TripleTermTransformerError=Ff.TripleTermTransformer=void 0;var DA=class{static{a(this,"TripleTermTransformer")}transform(e){let t=e,n,i=0,s=100;do if(n=t,t=this.transformSinglePass(t),i++,i>s)throw new Pf("Too many nested triple terms (max 100 iterations)");while(t!==n);return t}hasTripleTermSyntax(e){return this.findTripleTermPositions(e).length>0}transformSinglePass(e){let t=this.findTripleTermPositions(e);if(t.length===0)return e;let n=e;for(let i=t.length-1;i>=0;i--){let s=t[i],o=this.extractTripleTerm(n,s);if(o){let c=this.convertToStandardSyntax(o.content);n=n.substring(0,s)+c+n.substring(s+o.length)}}return n}findTripleTermPositions(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="'"){n=this.skipStringLiteral(e,n,"'");continue}if(e[n]==='"'){n=this.skipStringLiteral(e,n,'"');continue}if(e.substring(n,n+2)==="<<"&&this.isParenthesizedTripleTerm(e,n)){t.push(n),n+=2;continue}n++}return t}skipStringLiteral(e,t,n){let i=n.repeat(3);if(e.substring(t,t+3)===i){for(t+=3;t<e.length;){if(e.substring(t,t+3)===i)return t+3;e[t]==="\\"&&t++,t++}return t}for(t++;t<e.length&&e[t]!==n;)e[t]==="\\"&&t++,t++;return t+1}isParenthesizedTripleTerm(e,t){let n=t+2;for(;n<e.length&&/\s/.test(e[n]);)n++;return e[n]==="("}extractTripleTerm(e,t){let n=t+2;for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!=="(")return null;n++;let i=1;for(;n<e.length&&i>0;){if(e[n]==="'"||e[n]==='"'){n=this.skipStringLiteral(e,n,e[n]);continue}if(e.substring(n,n+2)==="<<"&&this.isParenthesizedTripleTerm(e,n)){for(n+=2;n<e.length&&/\s/.test(e[n]);)n++;e[n]==="("&&(i++,n++);continue}if(e.substring(n,n+2)==="<<"){n+=2;let s=1;for(;n<e.length&&s>0;){if(e[n]==="'"||e[n]==='"'){n=this.skipStringLiteral(e,n,e[n]);continue}if(e.substring(n,n+2)==="<<"){s++,n+=2;continue}if(e.substring(n,n+2)===">>"){s--,n+=2;continue}n++}continue}if(e[n]==="("){i++,n++;continue}if(e[n]===")"){let s=n+1;for(;s<e.length&&/\s/.test(e[s]);)s++;if(e.substring(s,s+2)===">>"){if(i--,i===0){let o=e.substring(t,s+2);return{content:o,length:o.length}}n=s+2;continue}n++;continue}n++}if(i>0)throw new Pf(`Unclosed triple term at position ${t}: missing )>>`);return null}convertToStandardSyntax(e){let t=e.match(/^<<\s*\(\s*([\s\S]*?)\s*\)\s*>>$/);if(!t)throw new Pf(`Invalid triple term syntax: ${e.substring(0,50)}...`);return`<< ${t[1]} >>`}};Ff.TripleTermTransformer=DA;var Pf=class extends Error{static{a(this,"TripleTermTransformerError")}constructor(e){super(`Triple term transformation error: ${e}`),this.name="TripleTermTransformerError"}};Ff.TripleTermTransformerError=Pf});var kA=T(rb=>{"use strict";Object.defineProperty(rb,"__esModule",{value:!0});rb.VaultPrefixTransformer=void 0;var QZ=/PREFIX\s+(\w+)\s*:/gi,JZ=new Set(["mailto","http","https","urn","ftp","prefix","base","select","construct","describe","ask","where","filter","optional","union","graph","order","group","having","limit","offset","values","bind","minus","service","insert","delete","load","clear","drop","create","move","copy","add"]),NA=class{static{a(this,"VaultPrefixTransformer")}constructor(){this.vaultPrefixes=new Map}setVaultPrefixes(e){this.vaultPrefixes=new Map(e)}getVaultPrefixes(){return new Map(this.vaultPrefixes)}transform(e){if(this.vaultPrefixes.size===0)return e;let t=this.findDeclaredPrefixes(e),n=[];for(let[o,c]of this.vaultPrefixes)!t.has(o.toLowerCase())&&!JZ.has(o.toLowerCase())&&n.push({prefix:o,baseIRI:c});if(n.length===0)return e;let i="",s=0;for(;s<e.length;){let o=e[s];if(o==='"'||o==="'"){let l=this.skipLiteral(e,s);i+=e.substring(s,l),s=l;continue}if(o==="<"){let l=e.indexOf(">",s);l!==-1?(i+=e.substring(s,l+1),s=l+1):(i+=o,s++);continue}if(o==="#"){let l=e.indexOf(`
|
|
103
|
-
`,s);l!==-1?(i+=e.substring(s,l),s=l):(i+=e.substring(s),s=e.length);continue}let c=this.tryReplacePrefixedName(e,s,n);if(c){i+=c.iri,s=c.endIndex;continue}i+=o,s++}return i}tryReplacePrefixedName(e,t,n){if(t>0&&/[a-zA-Z0-9_]/.test(e[t-1]))return null;for(let{prefix:i,baseIRI:s}of n){if(e.substring(t,t+i.length+1)!==i+":")continue;let o=t+i.length+1,c=o;for(;c<e.length&&/[a-zA-Z0-9_.%-]/.test(e[c]);)c++;if(c===o)continue;let l=e.substring(o,c);return{iri:`<${s}${l}.md>`,endIndex:c}}return null}findDeclaredPrefixes(e){let t=new Set,n=new RegExp(QZ.source,"gi"),i;for(;(i=n.exec(e))!==null;)t.add(i[1].toLowerCase());return t}skipLiteral(e,t){let n=e[t];if(t+2<e.length&&e.substring(t,t+3)===n+n+n){let s=e.indexOf(n+n+n,t+3);return s!==-1?s+3:e.length}let i=t+1;for(;i<e.length&&e[i]!==n;)e[i]==="\\"&&i++,i++;return i<e.length?i+1:e.length}};rb.VaultPrefixTransformer=NA});var Lf=T(Fi=>{"use strict";var ZZ=Fi&&Fi.__createBinding||(Object.create?(function(r,e,t,n){n===void 0&&(n=t);var i=Object.getOwnPropertyDescriptor(e,t);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:a(function(){return e[t]},"get")}),Object.defineProperty(r,n,i)}):(function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]})),eee=Fi&&Fi.__setModuleDefault||(Object.create?(function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}):function(r,e){r.default=e}),tee=Fi&&Fi.__importStar||(function(){var r=a(function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[n.length]=i);return n},r(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),i=0;i<n.length;i++)n[i]!=="default"&&ZZ(t,e,n[i]);return eee(t,e),t}})();Object.defineProperty(Fi,"__esModule",{value:!0});Fi.SPARQLParser=Fi.ExoQLParser=Fi.SPARQLParseError=void 0;var Qk=tee(Kk()),MA=OA(),$A=xA(),Jk=Hk(),jA=FA(),ree=Yk(),BA=Xk(),nee=kA(),zr=class extends Error{static{a(this,"SPARQLParseError")}constructor(e,t,n,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=n}};Fi.SPARQLParseError=zr;var nb=class{static{a(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new Qk.Parser({sparqlStar:!0}),this.generator=new Qk.Generator({sparqlStar:!0}),this.caseWhenTransformer=new MA.CaseWhenTransformer,this.lateralTransformer=new $A.LateralTransformer,this.prefixStarTransformer=new Jk.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new jA.DescribeOptionsTransformer,this.directionalLangTagTransformer=new ree.DirectionalLangTagTransformer,this.tripleTermTransformer=new BA.TripleTermTransformer,this.vaultPrefixTransformer=new nee.VaultPrefixTransformer}setVaultPrefixes(e){this.vaultPrefixTransformer.setVaultPrefixes(e)}parse(e){try{let t=this.vaultPrefixTransformer.transform(e),n=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=n.options;let i=n.query;i=this.directionalLangTagTransformer.transform(i),this.lastDirectionMappings=this.directionalLangTagTransformer.getAllMappings(),i=this.lateralTransformer.transform(i),i=this.caseWhenTransformer.transform(i),i=this.tripleTermTransformer.transform(i);let s=this.parser.parse(i);return this.validateQuery(s),this.lastDescribeOptions&&this.isDescribeQuery(s)&&(s.describeOptions=this.lastDescribeOptions),s}catch(t){if(t instanceof jA.DescribeOptionsTransformerError)throw new zr(t.message);if(t instanceof $A.LateralTransformerError)throw new zr(t.message);if(t instanceof MA.CaseWhenTransformerError)throw new zr(t.message);if(t instanceof BA.TripleTermTransformerError)throw new zr(t.message);if(t instanceof Error){let n=t.message.match(/line (\d+), column (\d+)/),i=n?parseInt(n[1],10):void 0,s=n?parseInt(n[2],10):void 0;throw new zr(`SPARQL syntax error: ${t.message}`,i,s,t)}throw t}}parseWithOptions(e){return{query:this.parse(e),describeOptions:this.lastDescribeOptions}}getLastDescribeOptions(){return this.lastDescribeOptions}async parseAsync(e){try{let t=this.vaultPrefixTransformer.transform(e),n=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=n.options;let i=n.query;i=this.directionalLangTagTransformer.transform(i),this.lastDirectionMappings=this.directionalLangTagTransformer.getAllMappings(),i=await this.prefixStarTransformer.transform(i),i=this.lateralTransformer.transform(i),i=this.caseWhenTransformer.transform(i),i=this.tripleTermTransformer.transform(i);let s=this.parser.parse(i);return this.validateQuery(s),this.lastDescribeOptions&&this.isDescribeQuery(s)&&(s.describeOptions=this.lastDescribeOptions),s}catch(t){if(t instanceof jA.DescribeOptionsTransformerError)throw new zr(t.message);if(t instanceof Jk.PrefixStarTransformerError)throw new zr(t.message);if(t instanceof $A.LateralTransformerError)throw new zr(t.message);if(t instanceof MA.CaseWhenTransformerError)throw new zr(t.message);if(t instanceof BA.TripleTermTransformerError)throw new zr(t.message);if(t instanceof Error){let n=t.message.match(/line (\d+), column (\d+)/),i=n?parseInt(n[1],10):void 0,s=n?parseInt(n[2],10):void 0;throw new zr(`SPARQL syntax error: ${t.message}`,i,s,t)}throw t}}async parseAsyncWithOptions(e){return{query:await this.parseAsync(e),describeOptions:this.lastDescribeOptions}}hasPrefixStar(e){return/PREFIX\s*\*/i.test(e)}hasLateral(e){return this.lateralTransformer.hasLateral(e)}hasDescribeOptions(e){return this.describeOptionsTransformer.hasDescribeOptions(e)}hasDirectionalLangTags(e){return this.directionalLangTagTransformer.hasDirectionalTags(e)}hasTripleTermSyntax(e){return this.tripleTermTransformer.hasTripleTermSyntax(e)}getLastDirectionMappings(){return new Map(this.lastDirectionMappings)}getDirectionForLanguage(e){return this.lastDirectionMappings.get(e.toLowerCase())}toString(e){try{return this.generator.stringify(e)}catch(t){throw t instanceof Error?new zr(`Failed to serialize SPARQL query: ${t.message}`,void 0,void 0,t):t}}getQueryType(e){if("queryType"in e&&e.type==="query")return e.queryType;throw new zr("Query does not have a valid queryType property")}isSelectQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="SELECT"}isConstructQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="CONSTRUCT"}isAskQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="ASK"}isDescribeQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="DESCRIBE"}isUpdateQuery(e){return e.type==="update"}isInsertDataOperation(e){return"updateType"in e&&e.updateType==="insert"}isDeleteDataOperation(e){return"updateType"in e&&e.updateType==="delete"}validateQuery(e){if(!e||typeof e!="object")throw new zr("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new zr(`Invalid type: expected "query" or "update", got "${e.type}"`);if(e.type==="query"){let t=["SELECT","CONSTRUCT","ASK","DESCRIBE"];if(!t.includes(e.queryType))throw new zr(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};Fi.ExoQLParser=nb;Fi.SPARQLParser=nb});var Ql=T(ib=>{"use strict";Object.defineProperty(ib,"__esModule",{value:!0});ib.AlgebraTranslatorError=void 0;var UA=class extends Error{static{a(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};ib.AlgebraTranslatorError=UA});var sb=T(xo=>{"use strict";Object.defineProperty(xo,"__esModule",{value:!0});xo.isVariableExpression=iee;xo.isVariableTerm=see;xo.isNamedNode=oee;xo.isLiteral=aee;xo.isPropertyPath=cee;xo.isAggregateExpression=lee;xo.isOperationExpression=uee;xo.isFunctionCallExpression=fee;function iee(r){return typeof r=="object"&&r!==null&&"expression"in r&&"variable"in r}a(iee,"isVariableExpression");function see(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="Variable"}a(see,"isVariableTerm");function oee(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="NamedNode"}a(oee,"isNamedNode");function aee(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="Literal"}a(aee,"isLiteral");function cee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="path"}a(cee,"isPropertyPath");function lee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="aggregate"}a(lee,"isAggregateExpression");function uee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="operation"}a(uee,"isOperationExpression");function fee(r){return typeof r=="object"&&r!==null&&"type"in r&&(r.type==="functionCall"||r.type==="functioncall")}a(fee,"isFunctionCallExpression")});var Zk=T(ob=>{"use strict";Object.defineProperty(ob,"__esModule",{value:!0});ob.TripleTranslator=void 0;var oi=Ql(),VA=class{static{a(this,"TripleTranslator")}constructor(){this.directionMappings=new Map}setDirectionMappings(e){this.directionMappings=e}translateBGP(e){if(!("triples"in e)||!Array.isArray(e.triples))throw new oi.AlgebraTranslatorError("BGP pattern must have triples array");return{type:"bgp",triples:e.triples.map(t=>this.translateTriple(t))}}translateTriple(e){if(!e.subject||!e.predicate||!e.object)throw new oi.AlgebraTranslatorError("Triple must have subject, predicate, and object");return{subject:this.translateTripleElement(e.subject),predicate:this.translatePredicate(e.predicate),object:this.translateTripleElement(e.object)}}translateConstructTemplate(e){return!e||!Array.isArray(e)?[]:e.map(t=>this.translateTriple(t))}translatePredicate(e){return"type"in e&&e.type==="path"?this.translatePropertyPath(e):this.translateTripleElement(e)}translatePropertyPath(e){if(!("pathType"in e)||!e.pathType)throw new oi.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new oi.AlgebraTranslatorError("Property path must have items array");let t=e.items.map(n=>this.translatePathItem(n));switch(e.pathType){case"/":return{type:"path",pathType:"/",items:t};case"|":return{type:"path",pathType:"|",items:t};case"^":if(t.length!==1)throw new oi.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new oi.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new oi.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new oi.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new oi.AlgebraTranslatorError(`Unsupported property path type: ${e.pathType}`)}}translatePathItem(e){if("type"in e&&e.type==="path")return this.translatePropertyPath(e);if("termType"in e&&e.termType==="NamedNode")return{type:"iri",value:e.value};let t="type"in e?e.type:"termType"in e?e.termType:"unknown";throw new oi.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new oi.AlgebraTranslatorError("Triple element must have termType");switch(e.termType){case"Variable":return{type:"variable",value:e.value};case"NamedNode":return{type:"iri",value:e.value};case"Literal":{let t={type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language};if(e.language){let n=this.directionMappings.get(e.language.toLowerCase());n&&(t.direction=n)}return t}case"BlankNode":return{type:"blank",value:e.value};case"Quad":return this.translateQuotedTriple(e);default:throw new oi.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new oi.AlgebraTranslatorError("Quoted triple must have subject, predicate, and object");return{type:"quoted",subject:this.translateTripleElement(e.subject),predicate:this.translateQuotedTriplePredicate(e.predicate),object:this.translateTripleElement(e.object)}}translateQuotedTriplePredicate(e){if(!e||!("termType"in e))throw new oi.AlgebraTranslatorError("Quoted triple predicate must have termType");switch(e.termType){case"Variable":return{type:"variable",value:e.value};case"NamedNode":return{type:"iri",value:e.value};default:throw new oi.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};ob.TripleTranslator=VA});var eM=T(ab=>{"use strict";Object.defineProperty(ab,"__esModule",{value:!0});ab.ExpressionTranslator=void 0;var Df=Ql(),GA=class{static{a(this,"ExpressionTranslator")}constructor(e){this.translateWhereFn=e.translateWhere,this.translateBGPFn=e.translateBGP,this.translatePatternFn=e.translatePattern}translateExpression(e){if(!e)throw new Df.AlgebraTranslatorError("Expression cannot be null or undefined");if("type"in e&&e.type==="operation")return this.translateOperationExpression(e);let t="type"in e?e.type:void 0;if(t==="functioncall"||t==="functionCall"){let n=e;return{type:"functionCall",function:n.function,args:n.args.map(i=>this.translateExpression(i))}}if("termType"in e)return this.translateTermExpression(e);throw new Df.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Df.AlgebraTranslatorError("Filter pattern must have expression");let t={type:"bgp",triples:[]};return{type:"filter",expression:this.translateExpression(e.expression),input:t}}translateTermExpression(e){if(e.termType==="Variable")return{type:"variable",name:e.value};if(e.termType==="Literal"){let t=e.value;return e.datatype&&(e.datatype.value.includes("#integer")||e.datatype.value.includes("#decimal")?t=parseFloat(e.value):e.datatype.value.includes("#boolean")&&(t=e.value==="true")),{type:"literal",value:t,datatype:e.datatype?.value}}return{type:"literal",value:String(e.value||e)}}translateOperationExpression(e){let t=["=","!=","<",">","<=",">="],n=["&&","||","!"],i=["+","-","*","/"],s=e.args.filter(o=>!("patterns"in o)||"termType"in o);return t.includes(e.operator)?{type:"comparison",operator:e.operator,left:this.translateExpression(s[0]),right:this.translateExpression(s[1])}:n.includes(e.operator)?{type:"logical",operator:e.operator,operands:s.map(o=>this.translateExpression(o))}:i.includes(e.operator)?{type:"arithmetic",operator:e.operator,left:this.translateExpression(s[0]),right:this.translateExpression(s[1])}:e.operator==="exists"||e.operator==="notexists"?this.translateExistsExpression(e):e.operator==="in"||e.operator==="notin"?this.translateInExpression(e):{type:"function",function:e.operator,args:s.map(o=>this.translateExpression(o))}}translateExistsExpression(e){if(!e.args||e.args.length!==1)throw new Df.AlgebraTranslatorError("EXISTS/NOT EXISTS must have exactly one pattern argument");let t=e.args[0],n;return t.type==="group"&&"patterns"in t&&t.patterns?n=this.translateWhereFn(t.patterns):t.type==="bgp"?n=this.translateBGPFn(t):n=this.translatePatternFn(t),{type:"exists",negated:e.operator==="notexists",pattern:n}}translateInExpression(e){if(!e.args||e.args.length!==2)throw new Df.AlgebraTranslatorError("IN/NOT IN must have exactly 2 arguments (expression and list)");let t=e.args[0],n=e.args[1];if(!Array.isArray(n))throw new Df.AlgebraTranslatorError("IN/NOT IN second argument must be an array of values");return{type:"in",expression:this.translateExpression(t),list:n.map(i=>this.translateExpression(i)),negated:e.operator==="notin"}}};ab.ExpressionTranslator=GA});var nM=T(cb=>{"use strict";Object.defineProperty(cb,"__esModule",{value:!0});cb.PatternTranslator=void 0;var tM=xA(),En=Ql(),rM=sb(),qA=class{static{a(this,"PatternTranslator")}constructor(e){this.directionMappings=new Map,this.translateExpressionFn=e.translateExpression,this.translateSelectFn=e.translateSelect,this.translateBGPFn=e.translateBGP}setDirectionMappings(e){this.directionMappings=e}translateWhere(e){if(e.length===0)throw new En.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(o=>o.type==="filter"),n=e.filter(o=>o.type==="bind"),i=e.filter(o=>o.type!=="filter"&&o.type!=="bind"),s;if(i.length===0)s={type:"bgp",triples:[]};else if(i.length===1)if(i[0].type==="optional"){let o=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:o?this.translateExpressionFn(o):void 0}}else s=this.translatePattern(i[0]);else{if(i[0].type==="optional"){let o=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:o?this.translateExpressionFn(o):void 0}}else s=this.translatePattern(i[0]);for(let o=1;o<i.length;o++){let c=i[o];if(this.isLateralPattern(c)){let l=this.extractLateralSubquery(c),u=this.removeLateralMarker(l),f=this.translateSelectFn(u);s={type:"lateraljoin",left:s,right:f}}else if(c.type==="optional"){let l=c.expression;s={type:"leftjoin",left:s,right:this.translateWhere(c.patterns),expression:l?this.translateExpressionFn(l):void 0}}else if(c.type==="minus")s={type:"minus",left:s,right:this.translateWhere(c.patterns)};else{let l=this.translatePattern(c);s={type:"join",left:s,right:l}}}}for(let o of n)s=this.translateBind(o,s);for(let o of t)s={type:"filter",expression:this.translateExpressionFn(o.expression),input:s};return s}translatePattern(e){if(!e||!e.type)throw new En.AlgebraTranslatorError("Invalid pattern: missing type");switch(e.type){case"bgp":return this.translateBGPFn(e);case"filter":return this.translateFilter(e);case"optional":return this.translateOptional(e);case"union":return this.translateUnion(e);case"minus":return this.translateMinus(e);case"values":return this.translateValues(e);case"group":return this.translateWhere(e.patterns);case"query":return this.translateSubquery(e);case"service":return this.translateService(e);case"graph":return this.translateGraph(e);default:throw new En.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new En.AlgebraTranslatorError("Filter pattern must have expression");let t={type:"bgp",triples:[]};return{type:"filter",expression:this.translateExpressionFn(e.expression),input:t}}translateOptional(e){if(!e.patterns||e.patterns.length===0)throw new En.AlgebraTranslatorError("OPTIONAL pattern must have patterns");let t=e.expression;return{type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(e.patterns),expression:t?this.translateExpressionFn(t):void 0}}translateUnion(e){if(!e.patterns||e.patterns.length<2)throw new En.AlgebraTranslatorError("UNION pattern must have at least 2 patterns");let t=a(i=>i.type==="graph"?this.translateGraph(i):i.type==="service"?this.translateService(i):"patterns"in i&&i.patterns&&Array.isArray(i.patterns)?this.translateWhere(i.patterns):this.translateWhere([i]),"translateBranch"),n={type:"union",left:t(e.patterns[0]),right:t(e.patterns[1])};for(let i=2;i<e.patterns.length;i++)n={type:"union",left:n,right:t(e.patterns[i])};return n}translateMinus(e){if(!e.patterns||e.patterns.length===0)throw new En.AlgebraTranslatorError("MINUS pattern must have patterns");return{type:"minus",left:{type:"bgp",triples:[]},right:this.translateWhere(e.patterns)}}translateValues(e){if(!e.values||!Array.isArray(e.values))throw new En.AlgebraTranslatorError("VALUES pattern must have values array");let t=new Set;for(let i of e.values)for(let s of Object.keys(i)){let o=s.startsWith("?")?s.slice(1):s;t.add(o)}let n=e.values.map(i=>this.translateValuesBinding(i));return{type:"values",variables:Array.from(t),bindings:n}}translateValuesBinding(e){let t={};for(let[n,i]of Object.entries(e)){let s=n.startsWith("?")?n.slice(1):n,o=i;if(o)if(o.termType==="NamedNode")t[s]={type:"iri",value:o.value};else if(o.termType==="Literal"){let c=o,l={type:"literal",value:c.value,datatype:c.datatype?.value,language:c.language||void 0};if(c.language){let u=this.directionMappings.get(c.language.toLowerCase());u&&(l.direction=u)}t[s]=l}else throw new En.AlgebraTranslatorError(`Unsupported VALUES term type: ${o.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new En.AlgebraTranslatorError("BIND pattern must have variable and expression");return{type:"extend",variable:e.variable.value,expression:this.translateExpressionFn(e.expression),input:t}}translateSubquery(e){if(e.queryType!=="SELECT")throw new En.AlgebraTranslatorError(`Only SELECT subqueries are supported, got: ${String(e.queryType)}`);let t=this.removeLateralMarker(e);return{type:"subquery",query:this.translateSelectFn(t)}}translateService(e){if(!e.name||e.name.termType!=="NamedNode")throw new En.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new En.AlgebraTranslatorError("SERVICE pattern must have patterns array");return{type:"service",endpoint:e.name.value,pattern:this.translateWhere(e.patterns),silent:e.silent||!1}}translateGraph(e){if(!e.name)throw new En.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new En.AlgebraTranslatorError("GRAPH pattern must have patterns array");let t;if(e.name.termType==="NamedNode")t={type:"iri",value:e.name.value};else if(e.name.termType==="Variable")t={type:"variable",value:e.name.value};else throw new En.AlgebraTranslatorError(`GRAPH pattern name must be NamedNode or Variable, got: ${e.name.termType}`);return{type:"graph",name:t,pattern:this.translateWhere(e.patterns)}}isLateralPattern(e){if(e.type==="query"&&this.isLateralSubquery(e))return!0;if(e.type==="group"&&e.patterns?.length===1){let t=e.patterns[0];if(t.type==="query"&&this.isLateralSubquery(t))return!0}return!1}extractLateralSubquery(e){if(e.type==="query")return e;if(e.type==="group"&&e.patterns?.length===1){let t=e.patterns[0];if(t.type==="query")return t}throw new En.AlgebraTranslatorError("Invalid lateral pattern structure")}isLateralSubquery(e){return!("queryType"in e)||e.queryType!=="SELECT"||!("variables"in e)||!e.variables?!1:e.variables.some(i=>(0,rM.isVariableTerm)(i)&&i.value===tM.LateralTransformer.LATERAL_MARKER)}removeLateralMarker(e){if(!("variables"in e)||!e.variables)return e;let t=e,n=t.variables;return{...t,variables:n.filter(i=>!((0,rM.isVariableTerm)(i)&&i.value===tM.LateralTransformer.LATERAL_MARKER))}}};cb.PatternTranslator=qA});var ub=T(kf=>{"use strict";Object.defineProperty(kf,"__esModule",{value:!0});kf.CustomAggregateRegistry=kf.CustomAggregateError=void 0;var Nf=class extends Error{static{a(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};kf.CustomAggregateError=Nf;var lb=class r{static{a(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return r.instance||(r.instance=new r),r.instance}static resetInstance(){r.instance&&r.instance.clear(),r.instance=null}register(e,t){if(!e||typeof e!="string")throw new Nf("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new Nf("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new Nf(`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}};kf.CustomAggregateRegistry=lb;lb.instance=null});var db=T(Je=>{"use strict";Object.defineProperty(Je,"__esModule",{value:!0});Je.BUILT_IN_AGGREGATES=Je.interceptAggregate=Je.slopeAggregate=Je.corrAggregate=Je.modeAggregate=Je.stddevAggregate=Je.varianceAggregate=Je.medianAggregate=Je.EXO_AGGREGATE_NS=void 0;Je.getNumericValue=$f;Je.createDecimalLiteral=Fs;Je.createDoubleLiteral=dee;Je.createPercentileAggregate=Jl;var Un=Ye(),Mf=Ne(),fb=new Mf.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Zl=new Mf.IRI("http://www.w3.org/2001/XMLSchema#double");Je.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function $f(r){return r==null?NaN:typeof r=="number"?r:typeof r=="string"?parseFloat(r):r instanceof Un.Literal?parseFloat(r.value):r instanceof Mf.IRI?NaN:typeof r=="boolean"?r?1:0:NaN}a($f,"getNumericValue");function Fs(r){return new Un.Literal(String(r),fb)}a(Fs,"createDecimalLiteral");function dee(r){return new Un.Literal(String(r),Zl)}a(dee,"createDoubleLiteral");Je.medianAggregate={init(){return{values:[]}},step(r,e){let t=r,n=$f(e);isNaN(n)||t.values.push(n)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=[...t].sort((o,c)=>o-c),i=Math.floor(n.length/2),s=n.length%2!==0?n[i]:(n[i-1]+n[i])/2;return Fs(s)}};Je.varianceAggregate={init(){return{values:[]}},step(r,e){let t=r,n=$f(e);isNaN(n)||t.values.push(n)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-n,2),0)/t.length;return Fs(i)}};Je.stddevAggregate={init(){return{values:[]}},step(r,e){Je.varianceAggregate.step(r,e)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-n,2),0)/t.length;return Fs(Math.sqrt(i))}};Je.modeAggregate={init(){return{counts:new Map,values:new Map}},step(r,e){if(e==null)return;let t=r,n=String(e instanceof Un.Literal||e instanceof Mf.IRI?e.value:e),i=t.counts.get(n)||0;t.counts.set(n,i+1),t.values.set(n,e)},finalize(r){let e=r;if(e.counts.size===0)return new Un.Literal(" ",new Mf.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",n=0;for(let[o,c]of e.counts)c>n&&(n=c,t=o);let i=e.values.get(t);if(i instanceof Un.Literal)return i;let s=parseFloat(t);return isNaN(s)?new Un.Literal(t,new Mf.IRI("http://www.w3.org/2001/XMLSchema#string")):Fs(s)}};function Jl(r){let e=Math.max(0,Math.min(100,r))/100;return{init(){return{values:[],percentile:e}},step(t,n){let i=t,s=$f(n);isNaN(s)||i.values.push(s)},finalize(t){let n=t,{values:i}=n;if(i.length===0)return Fs(0);let s=[...i].sort((d,p)=>d-p),o=n.percentile*(s.length-1),c=Math.floor(o),l=Math.ceil(o);if(c===l)return Fs(s[c]);let u=o-c,f=s[c]*(1-u)+s[l]*u;return Fs(f)}}}a(Jl,"createPercentileAggregate");function WA(){return{n:0,sx:0,sy:0,sxx:0,syy:0,sxy:0}}a(WA,"bivariateInit");function zA(r,e,t){let n=r,i=$f(e),s=$f(t);isNaN(i)||isNaN(s)||(n.n+=1,n.sx+=i,n.sy+=s,n.sxx+=i*i,n.syy+=s*s,n.sxy+=i*s)}a(zA,"bivariateStep");Je.corrAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,syy:s,sxy:o}=r;if(e<2)return new Un.Literal("NaN",Zl);let c=e*o-t*n,l=e*i-t*t,u=e*s-n*n;return l<=0||u<=0?new Un.Literal("NaN",Zl):new Un.Literal(String(c/Math.sqrt(l*u)),fb)}};Je.slopeAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,sxy:s}=r;if(e<2)return new Un.Literal("NaN",Zl);let o=e*i-t*t;return o<=0?new Un.Literal("NaN",Zl):new Un.Literal(String((e*s-t*n)/o),fb)}};Je.interceptAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,sxy:s}=r;if(e<2)return new Un.Literal("NaN",Zl);let o=e*i-t*t;if(o<=0)return new Un.Literal("NaN",Zl);let c=(e*s-t*n)/o;return new Un.Literal(String((n-c*t)/e),fb)}};Je.BUILT_IN_AGGREGATES={[`${Je.EXO_AGGREGATE_NS}median`]:Je.medianAggregate,[`${Je.EXO_AGGREGATE_NS}variance`]:Je.varianceAggregate,[`${Je.EXO_AGGREGATE_NS}stddev`]:Je.stddevAggregate,[`${Je.EXO_AGGREGATE_NS}mode`]:Je.modeAggregate,[`${Je.EXO_AGGREGATE_NS}percentile25`]:Jl(25),[`${Je.EXO_AGGREGATE_NS}percentile50`]:Jl(50),[`${Je.EXO_AGGREGATE_NS}percentile75`]:Jl(75),[`${Je.EXO_AGGREGATE_NS}percentile90`]:Jl(90),[`${Je.EXO_AGGREGATE_NS}percentile95`]:Jl(95),[`${Je.EXO_AGGREGATE_NS}percentile99`]:Jl(99),[`${Je.EXO_AGGREGATE_NS}corr`]:Je.corrAggregate,[`${Je.EXO_AGGREGATE_NS}slope`]:Je.slopeAggregate,[`${Je.EXO_AGGREGATE_NS}intercept`]:Je.interceptAggregate}});var oM=T(pb=>{"use strict";Object.defineProperty(pb,"__esModule",{value:!0});pb.AggregateTranslator=void 0;var iM=Ql(),sM=sb(),KA=ub(),Ta=db(),HA=class{static{a(this,"AggregateTranslator")}constructor(e){this.aggregateCounter=0,this.translateExpressionFn=e.translateExpression}resetCounter(){this.aggregateCounter=0}extractAggregatesWithMapping(e,t){if(!e)return[];let n=[];for(let i of e)if((0,sM.isVariableExpression)(i))if("type"in i.expression&&i.expression.type==="aggregate")n.push({variable:i.variable.value,expression:this.translateAggregateExpression(i.expression)}),t.set(i.expression,i.variable.value);else{let s=this.customAggregateIri(i.expression);s?(n.push({variable:i.variable.value,expression:this.translateCustomAggregateFunctionCall(i.expression,s)}),t.set(i.expression,i.variable.value)):this.collectNestedAggregates(i.expression,n,t)}return n}extractGroupVariables(e){return e?e.filter(t=>t.expression&&"termType"in t.expression&&t.expression.termType==="Variable").map(t=>t.expression.value):[]}extractHavingExpressions(e,t,n){if(!e||e.length===0)return[];for(let i of e)this.collectNestedAggregates(i,t,n);return e.map(i=>this.transformExpressionWithAggregateVars(i,n))}transformExpressionWithAggregateVars(e,t){let n=t.get(e);if(n!==void 0)return{type:"variable",name:n};if("type"in e&&e.type==="operation"&&"args"in e){let i=e,s=i.args.filter(u=>!Array.isArray(u)&&!("patterns"in u)).map(u=>this.transformExpressionWithAggregateVars(u,t)),o=["=","!=","<",">","<=",">="],c=["&&","||","!"],l=["+","-","*","/"];return o.includes(i.operator)?{type:"comparison",operator:i.operator,left:s[0],right:s[1]}:c.includes(i.operator)?{type:"logical",operator:i.operator,operands:s}:l.includes(i.operator)?{type:"arithmetic",operator:i.operator,left:s[0],right:s[1]}:{type:"function",function:i.operator,args:s}}return this.translateExpressionFn(e)}translateOrderComparator(e){return{expression:this.translateExpressionFn(e.expression),descending:e.descending||!1}}translateAggregateExpression(e){let t=e.aggregation,n=a(()=>{if(e.expression&&!("termType"in e.expression&&e.expression.termType==="Wildcard"))return this.translateExpressionFn(e.expression)},"translateInnerExpr");if(typeof t=="string"){let s=t.toLowerCase();return["count","sum","avg","min","max","group_concat","sample"].includes(s)?{type:"aggregate",aggregation:s,expression:n(),distinct:e.distinct||!1,separator:e.separator}:{type:"aggregate",aggregation:{type:"custom",iri:t},expression:n(),distinct:e.distinct||!1,separator:e.separator}}let i=t;if(i&&typeof i=="object"){let s,o=i;if(o.termType==="NamedNode"&&typeof o.value=="string")s=o.value;else if("value"in o)s=String(o.value);else throw new iM.AlgebraTranslatorError(`Invalid custom aggregate: expected IRI but got ${JSON.stringify(i)}`);return{type:"aggregate",aggregation:{type:"custom",iri:s},expression:n(),distinct:e.distinct||!1,separator:e.separator}}throw new iM.AlgebraTranslatorError(`Unknown aggregate format: ${JSON.stringify(t)}`)}customAggregateIri(e){if(!(0,sM.isFunctionCallExpression)(e))return null;let t=e.function,n=null;if(typeof t=="string"?n=t:t&&typeof t=="object"&&"value"in t&&(n=String(t.value)),!n)return null;if(n in Ta.BUILT_IN_AGGREGATES||KA.CustomAggregateRegistry.getInstance().get(n)!==void 0)return n;if(n.startsWith(Ta.EXO_AGGREGATE_NS)){let s=[...Object.keys(Ta.BUILT_IN_AGGREGATES),...KA.CustomAggregateRegistry.getInstance().getRegisteredIris()].filter(o=>o.startsWith(Ta.EXO_AGGREGATE_NS)).map(o=>o.slice(Ta.EXO_AGGREGATE_NS.length)).sort();throw new Error(`Unknown aggregate agg:${n.slice(Ta.EXO_AGGREGATE_NS.length)}. Registered: ${s.length>0?s.map(o=>`agg:${o}`).join(", "):"(none)"}.`)}return null}translateCustomAggregateFunctionCall(e,t){let n=e,s=(KA.CustomAggregateRegistry.getInstance().get(t)??Ta.BUILT_IN_AGGREGATES[t])?.arity??1,o=n.args?.length??0;if(o!==s){let u=t.startsWith(Ta.EXO_AGGREGATE_NS)?`agg:${t.slice(Ta.EXO_AGGREGATE_NS.length)}`:t;throw new Error(`${u} takes exactly ${s} argument${s===1?"":"s"}, got ${o}.`)}let c=o>0?n.args?.[0]:void 0,l=s===2?n.args?.[1]:void 0;return{type:"aggregate",aggregation:{type:"custom",iri:t},expression:c?this.translateExpressionFn(c):void 0,expression2:l?this.translateExpressionFn(l):void 0,distinct:n.distinct||!1}}collectNestedAggregates(e,t,n){if(!e)return;if("type"in e&&e.type==="aggregate"){let s=`__agg${this.aggregateCounter++}`;t.push({variable:s,expression:this.translateAggregateExpression(e)}),n.set(e,s);return}let i=this.customAggregateIri(e);if(i){let s=`__agg${this.aggregateCounter++}`;t.push({variable:s,expression:this.translateCustomAggregateFunctionCall(e,i)}),n.set(e,s);return}if("type"in e&&e.type==="operation"&&"args"in e){let s=e;for(let o of s.args)!Array.isArray(o)&&"type"in o&&!("patterns"in o)?this.collectNestedAggregates(o,t,n):"termType"in o&&this.collectNestedAggregates(o,t,n)}}};pb.AggregateTranslator=HA});var jf=T(Oc=>{"use strict";Object.defineProperty(Oc,"__esModule",{value:!0});Oc.AlgebraTranslator=Oc.ExoQLAlgebraTranslator=Oc.AlgebraTranslatorError=void 0;var hb=Ql(),mb=sb(),pee=Zk(),hee=eM(),mee=nM(),gee=oM(),yee=Ql();Object.defineProperty(Oc,"AlgebraTranslatorError",{enumerable:!0,get:a(function(){return yee.AlgebraTranslatorError},"get")});var gb=class{static{a(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new pee.TripleTranslator,this.expressionTranslator=new hee.ExpressionTranslator({translateWhere:a(e=>this.patternTranslator.translateWhere(e),"translateWhere"),translateBGP:a(e=>this.tripleTranslator.translateBGP(e),"translateBGP"),translatePattern:a(e=>this.patternTranslator.translatePattern(e),"translatePattern")}),this.patternTranslator=new mee.PatternTranslator({translateExpression:a(e=>this.expressionTranslator.translateExpression(e),"translateExpression"),translateSelect:a(e=>this.translateSelect(e),"translateSelect"),translateBGP:a(e=>this.tripleTranslator.translateBGP(e),"translateBGP")}),this.aggregateTranslator=new gee.AggregateTranslator({translateExpression:a(e=>this.expressionTranslator.translateExpression(e),"translateExpression")})}setDirectionMappings(e){this.tripleTranslator.setDirectionMappings(e),this.patternTranslator.setDirectionMappings(e)}translate(e){if(e.type!=="query")throw new hb.AlgebraTranslatorError("Only query operations are supported (not updates)");if(e.queryType==="SELECT")return this.translateSelect(e);if(e.queryType==="CONSTRUCT")return this.translateConstruct(e);if(e.queryType==="ASK")return this.translateAsk(e);if(e.queryType==="DESCRIBE")return this.translateDescribe(e);throw new hb.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new hb.AlgebraTranslatorError("SELECT query must have WHERE clause");let t=this.patternTranslator.translateWhere(e.where);this.aggregateTranslator.resetCounter();let n=new Map,i=Array.isArray(e.variables)?e.variables.filter(l=>!("termType"in l&&l.termType==="Wildcard")):[],s=this.aggregateTranslator.extractAggregatesWithMapping(i,n),o=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,n);if((s.length>0||o.length>0||c.length>0)&&(t={type:"group",variables:o,aggregates:s,having:c.length>0?c:void 0,input:t}),i.length>0){for(let l of i)if((0,mb.isVariableExpression)(l)){if("type"in l.expression&&l.expression.type==="aggregate")continue;let u=this.aggregateTranslator.transformExpressionWithAggregateVars(l.expression,n);t={type:"extend",variable:l.variable.value,expression:u,input:t}}}if(e.order&&e.order.length>0&&(t={type:"orderby",comparators:e.order.map(l=>this.aggregateTranslator.translateOrderComparator(l)),input:t}),i.length>0){let l=i.filter(u=>(0,mb.isVariableTerm)(u)||(0,mb.isVariableExpression)(u)).map(u=>(0,mb.isVariableTerm)(u)?u.value:u.variable.value);l.length>0&&(t={type:"project",variables:l,input:t})}return e.distinct&&(t={type:"distinct",input:t}),e.reduced&&(t={type:"reduced",input:t}),(e.limit!==void 0||e.offset!==void 0)&&(t={type:"slice",limit:e.limit,offset:e.offset,input:t}),t}translateConstruct(e){let t=this.tripleTranslator.translateConstructTemplate(e.template??[]);if(!e.where||e.where.length===0)throw new hb.AlgebraTranslatorError("CONSTRUCT query must have WHERE clause");let n=this.patternTranslator.translateWhere(e.where),i=e;return(i.limit!==void 0||i.offset!==void 0)&&(n={type:"slice",limit:i.limit,offset:i.offset,input:n}),{type:"construct",template:t,where:n}}translateAsk(e){return{type:"ask",where:e.where&&e.where.length>0?this.patternTranslator.translateWhere(e.where):{type:"bgp",triples:[]}}}translateDescribe(e){let t=[];if(e.variables&&Array.isArray(e.variables)){let s=e.variables;for(let o of s)o.termType==="Wildcard"||o.value==="*"||(o.termType==="Variable"?t.push({type:"variable",value:o.value}):o.termType==="NamedNode"&&t.push({type:"iri",value:o.value}))}let n;e.where&&e.where.length>0&&(n=this.patternTranslator.translateWhere(e.where));let i=e.describeOptions;return{type:"describe",resources:t,where:n,depth:i?.depth,symmetric:i?.symmetric}}};Oc.ExoQLAlgebraTranslator=gb;Oc.AlgebraTranslator=gb});var Aa=T(yb=>{"use strict";Object.defineProperty(yb,"__esModule",{value:!0});yb.SolutionMapping=void 0;var aM=Ye(),cM=Ne(),lM=dr(),YA=class r{static{a(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,n]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(n,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new r(this.bindings);for(let[n,i]of e.getBindings().entries())t.set(n,i);return t}clone(){return new r(this.bindings)}areEqual(e,t){return e instanceof aM.Literal&&t instanceof aM.Literal?e.equals(t):e instanceof cM.IRI&&t instanceof cM.IRI?e.value===t.value:e instanceof lM.BlankNode&&t instanceof lM.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,n]of this.bindings.entries())e[t]=n.toString();return e}size(){return this.bindings.size}};yb.SolutionMapping=YA});var fM=T(Uf=>{"use strict";Object.defineProperty(Uf,"__esModule",{value:!0});Uf.PropertyPathExecutor=Uf.PropertyPathExecutorError=void 0;var bee=Aa(),bb=Ne(),uM=dr(),_ee=Ye(),Bf=class extends Error{static{a(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Uf.PropertyPathExecutorError=Bf;var XA=class r{static{a(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,n){if(this.isLiteralElement(e)||this.isLiteralElement(n)){let o=this.isLiteralElement(e)?"subject":"object",c=this.isLiteralElement(e)?e:n,l="value"in c?String(c.value):"<unknown>",u=l.length>80?`${l.slice(0,77)}...`:l,f=this.describePath(t),d={position:o,value:u,path:f,hint:"Wikilink could not be resolved to IRI (likely label-form wikilink with no matching basename/alias). Check whether the target file exists in the queried vault, or add an alias. See issue #3282."};if(console.error(`[PropertyPathExecutor] literal-safety guard fired: literal in ${o} position \u2014 yielding 0 solutions. value="${u}" path=${f}`,d),r.isStrictModeEnabled())throw new Bf(`Literal subject in property path: "${u}" (path=${f}). Set EXOCORTEX_SPARQL_STRICT=0 or omit --strict to fall back to warn-and-empty behaviour.`);return}let i=await this.resolveElement(e),s=this.isVariable(n)?null:await this.resolveElement(n);for(let o of i){let c=await this.evaluatePath(o,t,s);for(let l of c){let u=new bee.SolutionMapping;this.isVariable(e)&&u.set(e.value,o),this.isVariable(n)&&u.set(n.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new Bf("Predicate is not a property path");let n=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(n,e.predicate,i)){let o=t.merge(s);o!==null&&(yield o)}}async evaluatePath(e,t,n){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,n);case"|":return this.evaluateAlternativePath(e,t.items,n);case"^":return this.evaluateInversePath(e,t.items[0],n);case"+":return this.evaluateOneOrMorePath(e,t.items[0],n);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],n);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],n)}}async evaluateSequencePath(e,t,n){let i=new Set([e]);for(let s=0;s<t.length;s++){let o=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,o,c?n:null);for(let d of f)l.add(d)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,n){let i=new Set;for(let s of t){let o=await this.evaluatePathItem(e,s,n);for(let c of o)i.add(c)}return i}async evaluateInversePath(e,t,n){if(t.type==="iri"){let i=new bb.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),o=new Set;for(let c of s)(n===null||this.nodeInSet(c.subject,n))&&o.add(c.subject);return o}else return this.evaluatePath(e,this.invertPath(t),n)}async evaluateOneOrMorePath(e,t,n){let i=new Set,s=new Set,o=[{node:e,depth:0}];for(;o.length>0;){let c=o.shift();if(!c)break;let{node:l,depth:u}=c;if(u>=this.MAX_DEPTH)continue;let f=await this.evaluatePathItem(l,t,null);for(let d of f){let p=this.nodeToKey(d);(n===null||this.nodeInSet(d,n))&&s.add(d),i.has(p)||(i.add(p),o.push({node:d,depth:u+1}))}}return s}async evaluateZeroOrMorePath(e,t,n){let i=await this.evaluateOneOrMorePath(e,t,n);return(n===null||this.nodeInSet(e,n))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,n){let i=new Set;(n===null||this.nodeInSet(e,n))&&i.add(e);let s=await this.evaluatePathItem(e,t,n);for(let o of s)i.add(o);return i}async evaluatePathItem(e,t,n){if(t.type==="iri"){let i=new bb.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),o=new Set;for(let c of s)(n===null||this.nodeInSet(c.object,n))&&o.add(c.object);return o}else return this.evaluatePath(e,t,n)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(t=>t.type==="iri"?{type:"path",pathType:"^",items:[t]}:this.invertPath(t))};case"|":return{type:"path",pathType:"|",items:e.items.map(t=>t.type==="iri"?{type:"path",pathType:"^",items:[t]}:this.invertPath(t))};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 n=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)n.add(s.subject),n.add(s.object);return n}let t=new Set;switch(e.type){case"iri":t.add(new bb.IRI(e.value));break;case"blank":t.add(new uM.BlankNode(e.value));break;default:throw new Bf(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let n=t.get(e.value);if(n){if(n instanceof bb.IRI)return{type:"iri",value:n.value};if(n instanceof uM.BlankNode)return{type:"blank",value:n.id};if(n instanceof _ee.Literal)return{type:"literal",value:n.value,datatype:n.datatype?.value,language:n.language,direction:n.direction}}}return e}isVariable(e){return e.type==="variable"}isLiteralElement(e){return e.type==="literal"}isPropertyPath(e){return e.type==="path"}nodeToKey(e){return e.toString()}nodeInSet(e,t){let n=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===n)return!0;return!1}describePath(e){try{let t=e.items,n=a(s=>{if(s&&typeof s=="object"&&"type"in s){let o=s;if(o.type==="iri")return`<${String(o.value)}>`;if(o.type==="path")return this.describePath(o)}return"?"},"renderItem");if(!Array.isArray(t)||t.length===0)return"(?)";if(t.length===1){let s=n(t[0]);return e.pathType==="^"?`(^${s})`:e.pathType==="+"||e.pathType==="*"||e.pathType==="?"?`(${s}${e.pathType})`:`(${s})`}return`(${t.map(n).join(` ${e.pathType} `)})`}catch{return"<unprintable-path>"}}static isStrictModeEnabled(){let t=(typeof process<"u"?process.env:void 0)?.EXOCORTEX_SPARQL_STRICT;if(!t)return!1;let n=t.trim().toLowerCase();return n==="1"||n==="true"||n==="yes"}};Uf.PropertyPathExecutor=XA});var ZA=T(Vf=>{"use strict";Object.defineProperty(Vf,"__esModule",{value:!0});Vf.BGPExecutor=Vf.BGPExecutorError=void 0;var _b=Aa(),xc=Ne(),QA=Ye(),Sb=dr(),wb=fh(),dM=fM(),vn=class extends Error{static{a(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Vf.BGPExecutorError=vn;var JA=class{static{a(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new dM.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new _b.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let n=1;n<e.triples.length;n++)t=this.joinWithPattern(t,e.triples[n]);for await(let n of t)yield n}async executeAll(e){let t=[];for await(let n of this.execute(e))t.push(n);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new _b.SolutionMapping;return}let n=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)n=this.joinWithPatternInGraph(n,e.triples[i],t);for await(let i of n)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new vn("Property paths within named graphs are not yet supported");let n=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(n)){this.warnLiteralGuard("matchTriplePatternInGraph",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:n);return}let i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(n)?void 0:this.toRDFTermAsPredicate(n),o=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new vn("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,o,t);for(let l of c){let u=new _b.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(n)&&u.set(n.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,n){let i=[];for await(let s of e)i.push(s);for(let s of i){let o=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(o,n)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){if(this.isLiteral(e.subject)||this.isLiteral(e.object)){this.warnLiteralGuard("matchTriplePattern.propertyPath",this.isLiteral(e.subject)?"subject":"object",this.isLiteral(e.subject)?e.subject:e.object);return}yield*this.propertyPathExecutor.execute(e.subject,e.predicate,e.object);return}let t=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(t)){this.warnLiteralGuard("matchTriplePattern",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:t);return}let n=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),o=await this.tripleStore.match(n,i,s);for(let c of o){let l=new _b.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,d]of u.entries())l.set(f,d)}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,d]of u.entries())l.set(f,d)}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 wb.QuotedTriple))return null;let n=new Map;if(this.isVariable(e.subject))n.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,o]of i)n.set(s,o)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")n.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))n.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,o]of i)n.set(s,o)}else if(!this.elementsMatch(e.object,t.object))return null;return n}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof xc.IRI&&e.value===t.value;case"literal":return!(!(t instanceof QA.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof Sb.BlankNode&&e.value===t.id;case"quoted":return t instanceof wb.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let n=[];for await(let i of e)n.push(i);for(let i of n){let s=this.instantiatePattern(t,i);for await(let o of this.matchTriplePattern(s)){let c=i.merge(o);c!==null&&(yield c)}}}instantiatePattern(e,t){let n=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:n,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let n=t.get(e.value);if(n)return this.toAlgebraElement(n)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let n=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:n,predicate:i,object:s}}instantiatePredicateVariable(e,t){let n=t.get(e.value);return n&&n instanceof xc.IRI?{type:"iri",value:n.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}isLiteral(e){return e.type==="literal"}warnLiteralGuard(e,t,n){let i="value"in n?String(n.value):"<unknown>",s=i.length>80?`${i.slice(0,77)}...`:i,o={executor:"BGPExecutor",context:e,position:t,value:s,hint:"Wikilink could not be resolved to IRI (likely label-form wikilink with no matching basename/alias). Check whether the target file exists in the queried vault, or add an alias. See issue #3282."};if(console.error(`[BGPExecutor] literal-safety guard fired in ${e}: literal in ${t} position \u2014 yielding 0 solutions. value="${s}"`,o),dM.PropertyPathExecutor.isStrictModeEnabled())throw new vn(`Literal in ${t} position (${e}): "${s}". Set EXOCORTEX_SPARQL_STRICT=0 or omit --strict to fall back to warn-and-empty behaviour.`)}toRDFTermAsSubject(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"blank":return new Sb.BlankNode(e.value);case"literal":throw new vn("Literals cannot appear in subject position");case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vn(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),n=e.predicate.type==="iri"?new xc.IRI(e.predicate.value):(()=>{throw new vn("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new wb.QuotedTriple(t,n,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"literal":throw new vn("Literals cannot appear in predicate position");case"blank":throw new vn("Blank nodes cannot appear in predicate position");case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);default:throw new vn(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"literal":return new QA.Literal(e.value,e.datatype?new xc.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new Sb.BlankNode(e.value);case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vn(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof xc.IRI)return{type:"iri",value:e.value};if(e instanceof QA.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof Sb.BlankNode)return{type:"blank",value:e.id};if(e instanceof wb.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new vn(`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)}}};Vf.BGPExecutor=JA});var pM=T(Eb=>{"use strict";Object.defineProperty(Eb,"__esModule",{value:!0});Eb.StringFunctions=void 0;var Gf=Ne(),Pc=Ye(),eI=dr(),jh=class r{static{a(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof Gf.IRI||e instanceof Pc.Literal?e.value:e instanceof eI.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof Pc.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof Pc.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[n,i]=r.parseDirectionalLangTag(e),[s,o]=r.parseDirectionalLangTag(t),c=n.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":o&&i!==o?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let n=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[n,i]}static regex(e,t,n){try{let i=n?n.includes("u")?n:n+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}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,n){let i=t-1;if(i<0){if(n!==void 0){let s=n+i;return s<=0?"":e.substring(0,s)}return e}return n!==void 0?e.substring(i,i+n):e.substring(i)}static strBefore(e,t){if(t==="")return"";let n=e.indexOf(t);return n===-1?"":e.substring(0,n)}static strAfter(e,t){if(t==="")return e;let n=e.indexOf(t);return n===-1?"":e.substring(n+t.length)}static concat(...e){return e.join("")}static replace(e,t,n,i){try{let s=i||"g",o=s.includes("u")?s:s+"u",c=new RegExp(t,o);return e.replace(c,n)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static encodeForUri(e){return encodeURIComponent(e)}static normalize(e,t){if(e===void 0)throw new Error("NORMALIZE: string argument is undefined");let n;if(e instanceof Pc.Literal)n=e.value;else if(e instanceof Gf.IRI)n=e.value;else if(e instanceof eI.BlankNode)n=e.id;else if(typeof e=="string")n=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof Pc.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof Gf.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!r.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=n.normalize(i);return new Pc.Literal(s,new Gf.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 Pc.Literal)t=e.value;else if(e instanceof Gf.IRI)t=e.value;else if(e instanceof eI.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let n=r.unicodeCaseFold(t);return new Pc.Literal(n,new Gf.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let n of e){let i=r.CASE_FOLDING_MAP.get(n);i!==void 0?t+=i:t+=n.toLowerCase()}return t}};Eb.StringFunctions=jh;jh.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];jh.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 hM=T(vb=>{"use strict";Object.defineProperty(vb,"__esModule",{value:!0});vb.MathFunctions=void 0;var tI=class{static{a(this,"MathFunctions")}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()}};vb.MathFunctions=tI});var Bh=T(Tb=>{"use strict";Object.defineProperty(Tb,"__esModule",{value:!0});Tb.DateTimeParsing=void 0;var See=Ne(),wee=Ye(),rI=class r{static{a(this,"DateTimeParsing")}static parseDate(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`PARSEDATE: invalid date string '${e}'`);return t.getTime()}static parseDayTimeDuration(e){if(!e)throw new Error("parseDayTimeDuration: duration string is empty");let t=!1,n=e.trim();if(n.startsWith("-")&&(t=!0,n=n.substring(1)),!n.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);n=n.substring(1);let i=0,s=n.indexOf("T"),o="",c="";if(s===-1?o=n:(o=n.substring(0,s),c=n.substring(s+1)),o){let l=o.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(o!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${o}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let p=parseFloat(u[1]);i+=p*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let p=parseFloat(f[1]);i+=p*60*1e3,l=l.substring(f[0].length)}let d=l.match(/^(\d+(?:\.\d+)?)S$/);if(d){let p=parseFloat(d[1]);i+=p*1e3,l=l.substring(d[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,n=Math.abs(e),i=Math.floor(n/(1440*60*1e3));n=n%(1440*60*1e3);let s=Math.floor(n/(3600*1e3));n=n%(3600*1e3);let o=Math.floor(n/(60*1e3));n=n%(60*1e3);let c=n/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||o>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),o>0&&(l+=`${o}M`),(c>0||s===0&&o===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return r.parseDayTimeDuration(e),new wee.Literal(e,new See.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,n=e.match(t);if(!n){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(n[1],10),s=parseInt(n[2],10)-1,o=parseInt(n[3],10),c=n[4],l=new Date(Date.UTC(i,s,o));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,d=parseInt(u[2],10),p=parseInt(u[3],10),h=f*(d*60+p)*60*1e3;l=new Date(l.getTime()-h)}}return l}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,n=e.match(t);if(!n)return null;let i=parseInt(n[1],10),s=parseInt(n[2],10),o=parseInt(n[3],10),c=n[4],l=n[5];if(i<0||i>24||s<0||s>59||o<0||o>59||i===24&&(s!==0||o!==0))return null;let u=0;if(c){let d=c.padEnd(3,"0").slice(0,3);u=parseInt(d,10)}let f=i*60*60*1e3+s*60*1e3+o*1e3+u;if(i===24&&(f=1440*60*1e3),l&&l!=="Z"){let d=l.match(/([+-])(\d{2}):(\d{2})/);if(d){let p=d[1]==="+"?1:-1,h=parseInt(d[2],10),m=parseInt(d[3],10),g=p*(h*60+m)*60*1e3;f-=g}}return f}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,n=Math.abs(e);return t?`-P${n}D`:`P${n}D`}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,n=e.match(t);if(!n)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=n[1]==="-",s=parseInt(n[2]||"0",10),o=parseInt(n[3]||"0",10);if(!n[2]&&!n[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+o;return i?-c:c}static formatYearMonthDuration(e){let t=e<0,n=Math.abs(e),i=Math.floor(n/12),s=n%12,o=t?"-P":"P";return i>0&&(o+=`${i}Y`),(s>0||i===0)&&(o+=`${s}M`),o}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,n=e.match(t);if(!n)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=n[1]==="-",s=parseInt(n[2]||"0",10),o=parseInt(n[3]||"0",10);if(!n[2]&&!n[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:o,negative:i}}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,n=e.trim();if(n.startsWith("-")&&(t=!0,n=n.substring(1)),!n.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);n=n.substring(1);let i=0,s=0,o=0,c=0,l=n.indexOf("T"),u="",f="";if(l===-1?u=n:(u=n.substring(0,l),f=n.substring(l+1)),u){let d=u.match(/^(\d+(?:\.\d+)?)D$/);if(d)i=parseFloat(d[1]);else if(u!=="")throw new Error(`parseDurationComponents: invalid day component: '${u}' in '${e}'`)}if(f){let d=f,p=d.match(/^(\d+(?:\.\d+)?)H/);p&&(s=parseFloat(p[1]),d=d.substring(p[0].length));let h=d.match(/^(\d+(?:\.\d+)?)M/);h&&(o=parseFloat(h[1]),d=d.substring(h[0].length));let m=d.match(/^(\d+(?:\.\d+)?)S$/);if(m&&(c=parseFloat(m[1]),d=d.substring(m[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:o,seconds:c}}};Tb.DateTimeParsing=rI});var mM=T(Ab=>{"use strict";Object.defineProperty(Ab,"__esModule",{value:!0});Ab.DateTimeArithmetic=void 0;var ai=Ne(),Xe=Ye(),_t=Bh(),nI=class{static{a(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n),o=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${n}'`);if(isNaN(o.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-o.getTime(),l=_t.DateTimeParsing.formatDayTimeDuration(c);return new Xe.Literal(l,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c);return new Xe.Literal(l.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c);return new Xe.Literal(l.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateAdd: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),d=String(l.getUTCDate()).padStart(2,"0"),p=`${u}-${f}-${d}`;return new Xe.Literal(p,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateSubtract: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),d=String(l.getUTCDate()).padStart(2,"0"),p=`${u}-${f}-${d}`;return new Xe.Literal(p,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+o),s.getUTCDate()!==c&&s.setUTCDate(0),new Xe.Literal(s.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-o),s.getUTCDate()!==c&&s.setUTCDate(0),new Xe.Literal(s.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+o),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"),d=`${l}-${u}-${f}`;return new Xe.Literal(d,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-o),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"),d=`${l}-${u}-${f}`;return new Xe.Literal(d,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseDayTimeDuration(n),o=_t.DateTimeParsing.parseDayTimeDuration(i),c=_t.DateTimeParsing.formatDayTimeDuration(s+o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseDayTimeDuration(n),o=_t.DateTimeParsing.parseDayTimeDuration(i),c=_t.DateTimeParsing.formatDayTimeDuration(s-o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let n=e instanceof Xe.Literal?e.value:e,i=_t.DateTimeParsing.parseDayTimeDuration(n),s=_t.DateTimeParsing.formatDayTimeDuration(i*t);return new Xe.Literal(s,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let n=e instanceof Xe.Literal?e.value:e,i=_t.DateTimeParsing.parseDayTimeDuration(n),s=_t.DateTimeParsing.formatDayTimeDuration(i/t);return new Xe.Literal(s,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseYearMonthDuration(n),o=_t.DateTimeParsing.parseYearMonthDuration(i),c=_t.DateTimeParsing.formatYearMonthDuration(s+o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseYearMonthDuration(n),o=_t.DateTimeParsing.parseYearMonthDuration(i),c=_t.DateTimeParsing.formatYearMonthDuration(s-o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/1e3}};Ab.DateTimeArithmetic=nI});var gM=T(Ib=>{"use strict";Object.defineProperty(Ib,"__esModule",{value:!0});Ib.DateTimeAccessors=void 0;var Uh=Ne(),pr=Ye(),Xt=Bh(),iI=class r{static{a(this,"DateTimeAccessors")}static lexicalComponents(e){let t=e.match(/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(?:Z|[+-]\d{2}:?\d{2})?$/);if(!t)return null;let n=parseInt(t[1],10),i=parseInt(t[2],10),s=parseInt(t[3],10),o=t[4]!==void 0?parseInt(t[4],10):0,c=t[5]!==void 0?parseInt(t[5],10):0,l=t[6]!==void 0?parseInt(t[6],10):0,u=t[7]?l+parseFloat(`0.${t[7]}`):l;return i<1||i>12||s<1||s>31||o>24||c>59||l>60?null:{year:n,month:i,day:s,hours:o,minutes:c,seconds:u}}static year(e){let t=r.lexicalComponents(e);if(t)return t.year;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return n.getFullYear()}static month(e){let t=r.lexicalComponents(e);if(t)return t.month;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return n.getMonth()+1}static day(e){let t=r.lexicalComponents(e);if(t)return t.day;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return n.getDate()}static hours(e){let t=r.lexicalComponents(e);if(t)return t.hours;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return n.getHours()}static minutes(e){let t=r.lexicalComponents(e);if(t)return t.minutes;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return n.getMinutes()}static seconds(e){let t=r.lexicalComponents(e);if(t)return t.seconds;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return n.getSeconds()+n.getMilliseconds()/1e3}static durationDays(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.days);return n.negative?-i:i}static durationHours(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.hours);return n.negative?-i:i}static durationMinutes(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.minutes);return n.negative?-i:i}static durationSeconds(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t);return n.negative?-n.seconds:n.seconds}static durationYears(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseYearMonthDurationComponents(t);return n.negative?-n.years:n.years}static durationMonths(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseYearMonthDurationComponents(t);return n.negative?-n.months:n.months}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let n;if(e.endsWith("Z"))n="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),o=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);o===0?n=`${c}PT${l}H`:n=`${c}PT${l}H${o}M`}else{let s=-t.getTimezoneOffset(),o=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?n=`${l}PT${o}H`:n=`${l}PT${o}H${c}M`}}return new pr.Literal(n,new Uh.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 n=e.match(/([+-]\d{2}:\d{2})$/);if(n)return n[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static adjust(e,t){let n=e instanceof pr.Literal?e.value:e,i=new Date(n);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${n}'`);if(t==null){let R=i.getUTCFullYear(),C=String(i.getUTCMonth()+1).padStart(2,"0"),O=String(i.getUTCDate()).padStart(2,"0"),N=String(i.getUTCHours()).padStart(2,"0"),F=String(i.getUTCMinutes()).padStart(2,"0"),M=String(i.getUTCSeconds()).padStart(2,"0"),H=i.getUTCMilliseconds(),ne=`${R}-${C}-${O}T${N}:${F}:${M}`;return H>0&&(ne+=`.${String(H).padStart(3,"0")}`),new pr.Literal(ne,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof pr.Literal?t.value:t,o=Xt.DateTimeParsing.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(o)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+o),f=u.getUTCFullYear(),d=String(u.getUTCMonth()+1).padStart(2,"0"),p=String(u.getUTCDate()).padStart(2,"0"),h=String(u.getUTCHours()).padStart(2,"0"),m=String(u.getUTCMinutes()).padStart(2,"0"),g=String(u.getUTCSeconds()).padStart(2,"0"),b=u.getUTCMilliseconds(),_=o>=0?"+":"-",w=Math.floor(Math.abs(o)/(3600*1e3)),v=Math.floor(Math.abs(o)%(3600*1e3)/(60*1e3)),E=`${_}${String(w).padStart(2,"0")}:${String(v).padStart(2,"0")}`,S=`${f}-${d}-${p}T${h}:${m}:${g}`;return b>0&&(S+=`.${String(b).padStart(3,"0")}`),S+=E,new pr.Literal(S,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t);return n<i}static dateAfter(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t);return n>i}static dateInRange(e,t,n){let i=Xt.DateTimeParsing.parseDate(e),s=Xt.DateTimeParsing.parseDate(t),o=Xt.DateTimeParsing.parseDate(n);return i>=s&&i<=o}static compareDurations(e,t,n){let i=e instanceof pr.Literal?e.value:e,s=t instanceof pr.Literal?t.value:t,o=Xt.DateTimeParsing.parseDayTimeDuration(i),c=Xt.DateTimeParsing.parseDayTimeDuration(s);switch(n){case"=":return o===c;case"!=":return o!==c;case"<":return o<c;case">":return o>c;case"<=":return o<=c;case">=":return o>=c;default:throw new Error(`compareDurations: unknown operator: ${n}`)}}static dateDiffMinutes(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t),s=Math.abs(i-n);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t),s=Math.abs(i-n);return Math.round(s/(1e3*60*60)*100)/100}static timeDiff(e,t){let n=e instanceof pr.Literal?e.value:e,i=t instanceof pr.Literal?t.value:t,s=Xt.DateTimeParsing.parseXSDTime(n),o=Xt.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${n}'`);if(o===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-o,l=Xt.DateTimeParsing.formatDayTimeDuration(c);return new pr.Literal(l,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let n=e instanceof pr.Literal?e.value:e,i=t instanceof pr.Literal?t.value:t,s=Xt.DateTimeParsing.parseXSDDate(n),o=Xt.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${n}'`);if(o===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-o.getTime(),l=Math.round(c/(1440*60*1e3)),u=Xt.DateTimeParsing.formatDateDuration(l);return new pr.Literal(u,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};Ib.DateTimeAccessors=iI});var Cb=T(Rb=>{"use strict";Object.defineProperty(Rb,"__esModule",{value:!0});Rb.DateTimeFunctions=void 0;var qf=Bh(),Kr=mM(),qt=gM(),sI=class{static{a(this,"DateTimeFunctions")}static parseDate(e){return qf.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return qf.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return qf.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return qf.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return qf.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return qf.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return qt.DateTimeAccessors.year(e)}static month(e){return qt.DateTimeAccessors.month(e)}static day(e){return qt.DateTimeAccessors.day(e)}static hours(e){return qt.DateTimeAccessors.hours(e)}static minutes(e){return qt.DateTimeAccessors.minutes(e)}static seconds(e){return qt.DateTimeAccessors.seconds(e)}static durationDays(e){return qt.DateTimeAccessors.durationDays(e)}static durationHours(e){return qt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return qt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return qt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return qt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return qt.DateTimeAccessors.durationMonths(e)}static timezone(e){return qt.DateTimeAccessors.timezone(e)}static tz(e){return qt.DateTimeAccessors.tz(e)}static adjust(e,t){return qt.DateTimeAccessors.adjust(e,t)}static now(){return qt.DateTimeAccessors.now()}static dateBefore(e,t){return qt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return qt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,n){return qt.DateTimeAccessors.dateInRange(e,t,n)}static compareDurations(e,t,n){return qt.DateTimeAccessors.compareDurations(e,t,n)}static dateDiffMinutes(e,t){return qt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return qt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return qt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return qt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return qt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return qt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return qt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return qt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return Kr.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return Kr.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return Kr.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return Kr.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return Kr.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return Kr.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return Kr.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return Kr.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return Kr.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return Kr.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return Kr.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return Kr.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return Kr.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return Kr.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return Kr.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return Kr.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return Kr.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return Kr.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return Kr.DateTimeArithmetic.durationToSeconds(e)}};Rb.DateTimeFunctions=sI});var yM=T(xb=>{"use strict";Object.defineProperty(xb,"__esModule",{value:!0});xb.LogicalFunctions=void 0;var Eee=Ne(),Wf=Ye(),vee=dr(),Ob=Cb(),oI=class r{static{a(this,"LogicalFunctions")}static compare(e,t,n){if(r.isDayTimeDurationValue(e)&&r.isDayTimeDurationValue(t))return Ob.DateTimeFunctions.compareDurations(e instanceof Wf.Literal?e:String(e),t instanceof Wf.Literal?t:String(t),n);if(r.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return Ob.DateTimeFunctions.compareDurations(e instanceof Wf.Literal?e:String(e),t,n);if(typeof e=="string"&&/^-?P/.test(e)&&r.isDayTimeDurationValue(t))return Ob.DateTimeFunctions.compareDurations(e,t instanceof Wf.Literal?t:String(t),n);let i=r.toComparableValue(e),s=r.toComparableValue(t);switch(n){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: ${n}`)}}static isDayTimeDurationValue(e){return e instanceof Wf.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 Wf.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let n=parseFloat(e.value);if(!isNaN(n))return n}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return Ob.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof Eee.IRI?e.value:e instanceof vee.BlankNode?e.id:String(e)}static logicalAnd(e){return e.every(t=>t===!0)}static logicalOr(e){return e.some(t=>t===!0)}static logicalNot(e){return!e}static coalesce(e){for(let t of e)if(t!=null)return t}static if(e,t,n){return e?t:n}};xb.LogicalFunctions=oI});var bM=T(Pb=>{"use strict";Object.defineProperty(Pb,"__esModule",{value:!0});Pb.RDFTermFunctions=void 0;var Tn=Ne(),Yt=Ye(),Ls=dr(),zf=fh(),aI=mf(),cI=class r{static{a(this,"RDFTermFunctions")}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof Yt.Literal)return e.datatype?e.datatype:e.language?new Tn.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Tn.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 Tn.IRI}static isBlank(e){return e===void 0?!1:e instanceof Ls.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof Yt.Literal}static isTriple(e){return e===void 0?!1:e instanceof zf.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof Yt.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof Yt.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 xsdDateTime(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`xsd:dateTime: invalid date string '${e}'`);return new Yt.Literal(t.toISOString(),new Tn.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 Yt.Literal(String(t),new Tn.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 Yt.Literal(String(t),new Tn.IRI("http://www.w3.org/2001/XMLSchema#decimal"))}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 Tn.IRI&&t instanceof Tn.IRI)return e.value===t.value;if(e instanceof Ls.BlankNode&&t instanceof Ls.BlankNode)return e.id===t.id;if(e instanceof Yt.Literal&&t instanceof Yt.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let n=e.datatype?.value,i=t.datatype?.value;return n===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof Tn.IRI)return e;if(e instanceof Yt.Literal)return new Tn.IRI(e.value);throw e instanceof Ls.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return r.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,aI.v4)().replace(/-/g,"").substring(0,12)}`;return new Ls.BlankNode(t)}if(e instanceof Yt.Literal)return new Ls.BlankNode(e.value);if(e instanceof Ls.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 n;if(e instanceof Yt.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");n=e.value}else if(typeof e=="string")n=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof Tn.IRI)i=t;else if(t instanceof Yt.Literal)i=new Tn.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new Yt.Literal(n,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 n;if(e instanceof Yt.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");n=e.value}else if(typeof e=="string")n=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof Yt.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 Yt.Literal(n,void 0,i)}static strlangdir(e,t,n){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(n===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof Yt.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 Yt.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 o;if(n instanceof Yt.Literal)o=n.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(o!=="ltr"&&o!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${o}'. Must be 'ltr' or 'rtl'`);return new Yt.Literal(i,void 0,s,o)}static uuid(){let e=(0,aI.v4)();return new Tn.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,aI.v4)();return new Yt.Literal(e)}static triple(e,t,n){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(n===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof Yt.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof Tn.IRI)){let c=t instanceof Yt.Literal?"Literal":t instanceof Ls.BlankNode?"BlankNode":t instanceof zf.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,o=n;return new zf.QuotedTriple(i,s,o)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.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 zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.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 zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};Pb.RDFTermFunctions=cI});var _M=T(Fb=>{"use strict";Object.defineProperty(Fb,"__esModule",{value:!0});Fb.HashFunctions=void 0;var lI=class{static{a(this,"HashFunctions")}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")}};Fb.HashFunctions=lI});var Db=T(Lb=>{"use strict";Object.defineProperty(Lb,"__esModule",{value:!0});Lb.BuiltInFunctions=void 0;var Hr=pM(),Fc=hM(),qe=Cb(),Kf=yM(),ir=bM(),Vh=_M(),uI=class{static{a(this,"BuiltInFunctions")}static str(...e){return Hr.StringFunctions.str(...e)}static lang(...e){return Hr.StringFunctions.lang(...e)}static langdir(...e){return Hr.StringFunctions.langdir(...e)}static langMatches(...e){return Hr.StringFunctions.langMatches(...e)}static regex(...e){return Hr.StringFunctions.regex(...e)}static contains(...e){return Hr.StringFunctions.contains(...e)}static strStarts(...e){return Hr.StringFunctions.strStarts(...e)}static strEnds(...e){return Hr.StringFunctions.strEnds(...e)}static strlen(...e){return Hr.StringFunctions.strlen(...e)}static ucase(...e){return Hr.StringFunctions.ucase(...e)}static lcase(...e){return Hr.StringFunctions.lcase(...e)}static substr(...e){return Hr.StringFunctions.substr(...e)}static strBefore(...e){return Hr.StringFunctions.strBefore(...e)}static strAfter(...e){return Hr.StringFunctions.strAfter(...e)}static concat(...e){return Hr.StringFunctions.concat(...e)}static replace(...e){return Hr.StringFunctions.replace(...e)}static encodeForUri(...e){return Hr.StringFunctions.encodeForUri(...e)}static normalize(...e){return Hr.StringFunctions.normalize(...e)}static fold(...e){return Hr.StringFunctions.fold(...e)}static abs(...e){return Fc.MathFunctions.abs(...e)}static round(...e){return Fc.MathFunctions.round(...e)}static ceil(...e){return Fc.MathFunctions.ceil(...e)}static floor(...e){return Fc.MathFunctions.floor(...e)}static rand(){return Fc.MathFunctions.rand()}static msToMinutes(...e){return Fc.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Fc.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Fc.MathFunctions.msToSeconds(...e)}static parseDate(...e){return qe.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return qe.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return qe.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return qe.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return qe.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return qe.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return qe.DateTimeFunctions.year(...e)}static month(...e){return qe.DateTimeFunctions.month(...e)}static day(...e){return qe.DateTimeFunctions.day(...e)}static hours(...e){return qe.DateTimeFunctions.hours(...e)}static minutes(...e){return qe.DateTimeFunctions.minutes(...e)}static seconds(...e){return qe.DateTimeFunctions.seconds(...e)}static timezone(...e){return qe.DateTimeFunctions.timezone(...e)}static tz(...e){return qe.DateTimeFunctions.tz(...e)}static now(){return qe.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return qe.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return qe.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return qe.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return qe.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return qe.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return qe.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return qe.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return qe.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return qe.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return qe.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return qe.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return qe.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return qe.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return qe.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return qe.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return qe.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return qe.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return qe.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return qe.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return qe.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return qe.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return qe.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return qe.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return qe.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return qe.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return qe.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return qe.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return qe.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return qe.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return qe.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return qe.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return qe.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return qe.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return qe.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return qe.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return qe.DateTimeFunctions.adjust(...e)}static isTime(...e){return qe.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return qe.DateTimeFunctions.timeDiff(...e)}static compare(...e){return Kf.LogicalFunctions.compare(...e)}static logicalAnd(...e){return Kf.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return Kf.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return Kf.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return Kf.LogicalFunctions.coalesce(...e)}static if(...e){return Kf.LogicalFunctions.if(...e)}static datatype(...e){return ir.RDFTermFunctions.datatype(...e)}static bound(...e){return ir.RDFTermFunctions.bound(...e)}static isIRI(...e){return ir.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return ir.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return ir.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return ir.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return ir.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return ir.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return ir.RDFTermFunctions.sameTerm(...e)}static iri(...e){return ir.RDFTermFunctions.iri(...e)}static uri(...e){return ir.RDFTermFunctions.uri(...e)}static bnode(...e){return ir.RDFTermFunctions.bnode(...e)}static strdt(...e){return ir.RDFTermFunctions.strdt(...e)}static strlang(...e){return ir.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return ir.RDFTermFunctions.strlangdir(...e)}static uuid(){return ir.RDFTermFunctions.uuid()}static struuid(){return ir.RDFTermFunctions.struuid()}static xsdDateTime(...e){return ir.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return ir.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return ir.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return ir.RDFTermFunctions.triple(...e)}static subject(...e){return ir.RDFTermFunctions.subject(...e)}static predicate(...e){return ir.RDFTermFunctions.predicate(...e)}static object(...e){return ir.RDFTermFunctions.object(...e)}static md5(...e){return Vh.HashFunctions.md5(...e)}static sha1(...e){return Vh.HashFunctions.sha1(...e)}static sha256(...e){return Vh.HashFunctions.sha256(...e)}static sha384(...e){return Vh.HashFunctions.sha384(...e)}static sha512(...e){return Vh.HashFunctions.sha512(...e)}};Lb.BuiltInFunctions=uI});var Gh=T(Po=>{"use strict";Object.defineProperty(Po,"__esModule",{value:!0});Po.ExoQLBudgetExceededError=Po.ExoQLCycleError=Po.ExoQLEvalDisabledError=Po.ExoQLForbiddenKeywordError=void 0;var fI=class extends Error{static{a(this,"ExoQLForbiddenKeywordError")}constructor(e,t){super(t??`ExoQLForbiddenKeywordError: keyword "${e}" is not permitted by the exoql__Query AST allowlist`),this.name="ExoQLForbiddenKeywordError",this.keyword=e}};Po.ExoQLForbiddenKeywordError=fI;var dI=class extends Error{static{a(this,"ExoQLEvalDisabledError")}constructor(e){super(e??"ExoQLEvalDisabledError: exoql.eval.enabled is false (default). Flip the feature flag to opt in."),this.name="ExoQLEvalDisabledError"}};Po.ExoQLEvalDisabledError=dI;var pI=class extends Error{static{a(this,"ExoQLCycleError")}constructor(e,t){super(t??`ExoQLCycleError: cycle detected in nested exo:eval invocations: ${e.join(" \u2192 ")}`),this.name="ExoQLCycleError",this.path=e}};Po.ExoQLCycleError=pI;var hI=class extends Error{static{a(this,"ExoQLBudgetExceededError")}constructor(e,t,n,i){super(i??`ExoQLBudgetExceededError: ${e} budget exceeded (limit=${t}, observed=${n})`),this.name="ExoQLBudgetExceededError",this.budget=e,this.limit=t,this.observed=n}};Po.ExoQLBudgetExceededError=hI});var CM=T(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.functionHandlers=void 0;var ae=Db();ce.functionHandlers=new Map;ce.functionHandlers.set("str",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.str(t)});ce.functionHandlers.set("lang",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.lang(t)});ce.functionHandlers.set("langmatches",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.langMatches(t,n)});ce.functionHandlers.set("contains",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.contains(t,n)});ce.functionHandlers.set("strstarts",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strStarts(t,n)});ce.functionHandlers.set("strends",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strEnds(t,n)});ce.functionHandlers.set("strlen",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.strlen(t)});ce.functionHandlers.set("ucase",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.ucase(t)});ce.functionHandlers.set("lcase",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.lcase(t)});ce.functionHandlers.set("substr",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=Number(e.evaluateExpression(r[1],e.solution));if(r[2]){let i=Number(e.evaluateExpression(r[2],e.solution));return ae.BuiltInFunctions.substr(t,n,i)}return ae.BuiltInFunctions.substr(t,n)});ce.functionHandlers.set("strbefore",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strBefore(t,n)});ce.functionHandlers.set("strafter",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strAfter(t,n)});ce.functionHandlers.set("concat",(r,e)=>{let t=r.map(n=>e.getStringValue(e.evaluateExpression(n,e.solution)));return ae.BuiltInFunctions.concat(...t)});ce.functionHandlers.set("replace",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=e.getStringValue(e.evaluateExpression(r[2],e.solution)),s=r[3]?e.getStringValue(e.evaluateExpression(r[3],e.solution)):void 0;return ae.BuiltInFunctions.replace(t,n,i,s)});ce.functionHandlers.set("regex",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=r[2]?e.getStringValue(e.evaluateExpression(r[2],e.solution)):void 0;return ae.BuiltInFunctions.regex(t,n,i)});ce.functionHandlers.set("encode_for_uri",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.encodeForUri(t)});ce.functionHandlers.set("datatype",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.datatype(t).value});ce.functionHandlers.set("bound",(r,e)=>{let t=r[0];if(t.type==="variable"&&t.name){let n=e.solution.get(t.name);return ae.BuiltInFunctions.bound(n)}return!0});var SM=a((r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isIRI(t)},"isIriHandler");ce.functionHandlers.set("isiri",SM);ce.functionHandlers.set("isuri",SM);ce.functionHandlers.set("isblank",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isBlank(t)});ce.functionHandlers.set("isliteral",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isLiteral(t)});ce.functionHandlers.set("isnumeric",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isNumeric(t)});ce.functionHandlers.set("haslangdir",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.hasLangdir(t)});ce.functionHandlers.set("istriple",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isTriple(t)});ce.functionHandlers.set("sameterm",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution),n=e.getTermFromExpression(r[1],e.solution);return ae.BuiltInFunctions.sameTerm(t,n)});ce.functionHandlers.set("abs",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.abs(t)});ce.functionHandlers.set("round",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.round(t)});ce.functionHandlers.set("ceil",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.ceil(t)});ce.functionHandlers.set("floor",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.floor(t)});ce.functionHandlers.set("rand",()=>ae.BuiltInFunctions.rand());ce.functionHandlers.set("parsedate",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.parseDate(t)});ce.functionHandlers.set("datebefore",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateBefore(t,n)});ce.functionHandlers.set("dateafter",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateAfter(t,n)});ce.functionHandlers.set("dateinrange",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=e.getStringValue(e.evaluateExpression(r[2],e.solution));return ae.BuiltInFunctions.dateInRange(t,n,i)});ce.functionHandlers.set("datediffminutes",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateDiffMinutes(t,n)});ce.functionHandlers.set("datediffhours",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateDiffHours(t,n)});var Hf=a((r,e,t)=>(n,i)=>{let s=i.evaluateExpression(n[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):r(i.getStringValue(s))},"createDateTimeAccessor"),wM=Hf(ae.BuiltInFunctions.year.bind(ae.BuiltInFunctions),ae.BuiltInFunctions.durationYears.bind(ae.BuiltInFunctions),null);ce.functionHandlers.set("year",wM);ce.functionHandlers.set("years",wM);var EM=Hf(ae.BuiltInFunctions.month.bind(ae.BuiltInFunctions),ae.BuiltInFunctions.durationMonths.bind(ae.BuiltInFunctions),null);ce.functionHandlers.set("month",EM);ce.functionHandlers.set("months",EM);var vM=Hf(ae.BuiltInFunctions.day.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationDays.bind(ae.BuiltInFunctions));ce.functionHandlers.set("day",vM);ce.functionHandlers.set("days",vM);ce.functionHandlers.set("hours",Hf(ae.BuiltInFunctions.hours.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationHours.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("minutes",Hf(ae.BuiltInFunctions.minutes.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationMinutes.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("seconds",Hf(ae.BuiltInFunctions.seconds.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationSeconds.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("timezone",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.timezone(t)});ce.functionHandlers.set("tz",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.tz(t)});ce.functionHandlers.set("adjust",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=r.length>1?e.evaluateExpression(r[1],e.solution):void 0;return ae.BuiltInFunctions.adjust(t,n)});ce.functionHandlers.set("now",()=>ae.BuiltInFunctions.now());var TM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");ce.functionHandlers.set("datetime",TM);ce.functionHandlers.set("xsd:datetime",TM);var AM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");ce.functionHandlers.set("integer",AM);ce.functionHandlers.set("xsd:integer",AM);var IM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");ce.functionHandlers.set("decimal",IM);ce.functionHandlers.set("xsd:decimal",IM);var RM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");ce.functionHandlers.set("daytimeduration",RM);ce.functionHandlers.set("xsd:daytimeduration",RM);ce.functionHandlers.set("durationtodays",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToDays(t)});ce.functionHandlers.set("durationtohours",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToHours(t)});ce.functionHandlers.set("durationtominutes",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToMinutes(t)});ce.functionHandlers.set("durationtoseconds",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToSeconds(t)});ce.functionHandlers.set("durationdays",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationDays(t)});ce.functionHandlers.set("durationhours",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationHours(t)});ce.functionHandlers.set("durationminutes",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationMinutes(t)});ce.functionHandlers.set("durationseconds",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationSeconds(t)});ce.functionHandlers.set("durationyears",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationYears(t)});ce.functionHandlers.set("durationmonths",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationMonths(t)});ce.functionHandlers.set("datetimediff",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeDiff(t,n)});ce.functionHandlers.set("datetimeadd",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeAdd(t,n)});ce.functionHandlers.set("datetimesubtract",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeSubtract(t,n)});ce.functionHandlers.set("mstominutes",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToMinutes(t)});ce.functionHandlers.set("mstohours",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToHours(t)});ce.functionHandlers.set("mstoseconds",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToSeconds(t)});ce.functionHandlers.set("md5",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.md5(t)});ce.functionHandlers.set("sha1",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha1(t)});ce.functionHandlers.set("sha256",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha256(t)});ce.functionHandlers.set("sha384",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha384(t)});ce.functionHandlers.set("sha512",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha512(t)});ce.functionHandlers.set("subject",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.subject(t)});ce.functionHandlers.set("predicate",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.predicate(t)});ce.functionHandlers.set("object",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.object(t)});ce.functionHandlers.set("triple",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution),n=e.getTermFromExpression(r[1],e.solution),i=e.getTermFromExpression(r[2],e.solution);return ae.BuiltInFunctions.triple(t,n,i)});ce.functionHandlers.set("days_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t),s=new Date(n);return Math.floor((s.getTime()-i.getTime())/(1440*60*1e3))});ce.functionHandlers.set("minutes_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t),s=new Date(n);return Math.floor((s.getTime()-i.getTime())/(60*1e3))});ce.functionHandlers.set("hours_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t);return(new Date(n).getTime()-i.getTime())/(3600*1e3)});ce.functionHandlers.set("age_days",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=new Date(t);return Math.floor((new Date().getTime()-n.getTime())/(1440*60*1e3))});ce.functionHandlers.set("week_number",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=new Date(t),i=new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()));i.setUTCDate(i.getUTCDate()+4-(i.getUTCDay()||7));let s=new Date(Date.UTC(i.getUTCFullYear(),0,1));return Math.ceil(((i.getTime()-s.getTime())/(1440*60*1e3)+1)/7)});ce.functionHandlers.set("format_date",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t);return n.replace("YYYY",String(i.getFullYear())).replace("MM",String(i.getMonth()+1).padStart(2,"0")).replace("DD",String(i.getDate()).padStart(2,"0")).replace("HH",String(i.getHours()).padStart(2,"0")).replace("mm",String(i.getMinutes()).padStart(2,"0")).replace("ss",String(i.getSeconds()).padStart(2,"0"))});ce.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:r}=Gh();throw new r})});var Nb=T(Yf=>{"use strict";Object.defineProperty(Yf,"__esModule",{value:!0});Yf.FilterExecutor=Yf.FilterExecutorError=void 0;var Wt=Db(),Tee=CM(),mI=Ne(),Fo=Ye(),wr=class extends Error{static{a(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Yf.FilterExecutorError=wr;var gI=class{static{a(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 n=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;n?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||typeof e!="object")return!1;if(e.type==="exists")return!0;if(e.type==="logical")return e.operands.some(t=>this.expressionContainsExists(t));if(e.type==="comparison"){let t=e;return this.expressionContainsExists(t.left)||this.expressionContainsExists(t.right)}if(e.type==="arithmetic"){let t=e;return this.expressionContainsExists(t.left)||this.expressionContainsExists(t.right)}if(e.type==="in"){let t=e;return this.expressionContainsExists(t.expression)||t.list.some(n=>this.expressionContainsExists(n))}if(e.type==="function"||e.type==="functionCall"){let t=e;return Array.isArray(t.args)?t.args.some(n=>this.expressionContainsExists(n)):!1}return!1}async executeAll(e,t){let n=[];async function*i(){for(let s of t)yield s}a(i,"generator");for await(let s of this.execute(e,i()))n.push(s);return n}evaluateExpression(e,t){let n=e;if("termType"in e)switch(n.termType){case"Variable":return t.get(n.value);case"Literal":{let i=n.value,s=n.datatype,o=typeof s=="string"?s:s?.value;return o&&i.length>0&&this.shouldPreserveDatatype(o)?new Fo.Literal(i,new mI.IRI(o)):i}case"NamedNode":return n.value;default:throw new wr(`Unsupported termType: ${String(n.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":{let i=e;return i.datatype&&i.value.length>0&&this.shouldPreserveDatatype(i.datatype)?new Fo.Literal(i.value,new mI.IRI(i.datatype)):i.value}case"in":return this.evaluateIn(e,t);case"exists":throw new wr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new wr(`Unsupported expression type: ${e.type}`)}}async evaluateExpressionAsync(e,t){if(!this.expressionContainsExists(e))return this.evaluateExpression(e,t);if(e.type==="exists")return this.evaluateExists(e,t);if(e.type==="logical")return this.evaluateLogicalAsync(e,t);if(e.type==="comparison"){let n=e,i=await this.evaluateExpressionAsync(n.left,t),s=await this.evaluateExpressionAsync(n.right,t);return Wt.BuiltInFunctions.compare(i,s,n.operator)}return e.type==="in"?this.evaluateInAsync(e,t):e.type==="function"||e.type==="functionCall"?this.evaluateFunctionAsync(e,t):this.evaluateExpression(e,t)}async evaluateExists(e,t){if(!this.existsEvaluator)throw new wr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let n=await this.existsEvaluator(e.pattern,t);return e.negated?!n:n}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let s=await this.evaluateExpressionAsync(e.operands[0],t);return Wt.BuiltInFunctions.logicalNot(s)}let n=[],i=!1;for(let s of e.operands)try{n.push(await this.evaluateExpressionAsync(s,t))}catch{i=!0}if(e.operator==="&&"){if(n.some(s=>s===!1))return!1;if(i)throw new wr("&& operand raised and no false absorbed it");return Wt.BuiltInFunctions.logicalAnd(n)}if(e.operator==="||"){if(n.some(s=>s===!0))return!0;if(i)throw new wr("|| operand raised and no true absorbed it");return Wt.BuiltInFunctions.logicalOr(n)}throw new wr(`Unknown logical operator: ${String(e.operator)}`)}async evaluateInAsync(e,t){let n=await this.evaluateExpressionAsync(e.expression,t),i=!1;for(let s of e.list){let o=await this.evaluateExpressionAsync(s,t);if(Wt.BuiltInFunctions.compare(n,o,"=")){i=!0;break}}return e.negated?!i:i}async evaluateFunctionAsync(e,t){let n=e,i=this.extractFunctionName(n.function),s=n.args??[];if(i==="if"){if(s.length!==3)throw new wr("IF requires exactly 3 arguments");let l=await this.evaluateExpressionAsync(s[0],t);return this.toBoolean(l)?this.evaluateExpressionAsync(s[1],t):this.evaluateExpressionAsync(s[2],t)}if(i==="coalesce"){for(let l of s)try{let u=await this.evaluateExpressionAsync(l,t);if(u!=null)return u}catch{continue}return}let o=[];for(let l of s){let u=await this.evaluateExpressionAsync(l,t);o.push(this.wrapAsLiteralExpression(u))}let c={...n,args:o};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:typeof e=="object"&&"termType"in e?e:e instanceof mI.IRI||e instanceof Fo.Literal?{type:"literal",value:e.value}:typeof e=="number"||typeof e=="boolean"||typeof e=="string"?{type:"literal",value:e}:{type:"literal",value:String(e)}}evaluateComparison(e,t){let n=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return Wt.BuiltInFunctions.compare(n,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let s=this.evaluateExpression(e.operands[0],t);return Wt.BuiltInFunctions.logicalNot(s)}let n=[],i=!1;for(let s of e.operands)try{n.push(this.evaluateExpression(s,t))}catch{i=!0}if(e.operator==="&&"){if(n.some(s=>s===!1))return!1;if(i)throw new wr("&& operand raised and no false absorbed it");return Wt.BuiltInFunctions.logicalAnd(n)}if(e.operator==="||"){if(n.some(s=>s===!0))return!0;if(i)throw new wr("|| operand raised and no true absorbed it");return Wt.BuiltInFunctions.logicalOr(n)}throw new wr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let n=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let o=this.evaluateExpression(s,t);return Wt.BuiltInFunctions.compare(n,o,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let n=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(n)&&this.isDateValue(i))return Wt.BuiltInFunctions.dateDiff(n,i);if(e.operator==="-"&&this.isTimeValue(n)&&this.isTimeValue(i))return Wt.BuiltInFunctions.timeDiff(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isDateTimeValue(i))return Wt.BuiltInFunctions.dateTimeDiff(n,i);if(e.operator==="+"&&this.isDateValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateAdd(n,i);if(e.operator==="-"&&this.isDateValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateSubtract(n,i);if(e.operator==="+"&&this.isDateValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateAddYearMonth(n,i);if(e.operator==="-"&&this.isDateValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateSubtractYearMonth(n,i);if(e.operator==="+"&&this.isDateTimeValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateTimeAdd(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateTimeSubtract(n,i);if(e.operator==="+"&&this.isDateTimeValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateTimeAddYearMonth(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateTimeSubtractYearMonth(n,i);if(e.operator==="+"&&this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.durationAdd(n,i);if(e.operator==="-"&&this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.durationSubtract(n,i);if(e.operator==="*"&&this.isDayTimeDurationValue(n)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return Wt.BuiltInFunctions.durationMultiply(n,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(n);return Wt.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(n)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new wr("Division by zero");return Wt.BuiltInFunctions.durationDivide(n,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.yearMonthDurationAdd(n,i);if(e.operator==="-"&&this.isYearMonthDurationValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.yearMonthDurationSubtract(n,i);let s=this.toNumericValue(n),o=this.toNumericValue(i);switch(e.operator){case"+":return s+o;case"-":return s-o;case"*":return s*o;case"/":if(o===0)throw new wr("Division by zero");return s/o;default:throw new wr(`Unknown arithmetic operator: ${String(e.operator)}`)}}shouldPreserveDatatype(e){return e==="http://www.w3.org/2001/XMLSchema#dateTime"||e==="http://www.w3.org/2001/XMLSchema#date"||e==="http://www.w3.org/2001/XMLSchema#time"||e==="http://www.w3.org/2001/XMLSchema#dayTimeDuration"||e==="http://www.w3.org/2001/XMLSchema#yearMonthDuration"||e==="http://www.w3.org/2001/XMLSchema#duration"}isDayTimeDurationValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof Fo.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 n=parseFloat(e.value);if(!isNaN(n))return n}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 wr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof Fo.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 Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let n=e,i=this.extractFunctionName(n.function),s=this.evaluateSpecialFunction(i,n.args,t);if(s!==void 0)return s.value;let o=Tee.functionHandlers.get(i);if(!o)throw new wr(`Unknown function: ${i}`);let c={evaluateExpression:a((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:a((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:a(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:a(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:a(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return o(n.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 wr(`Unknown function format: ${String(e)}`)}evaluateSpecialFunction(e,t,n){switch(e){case"coalesce":for(let i of t)try{let s=this.evaluateExpression(i,n);if(s!=null)return{value:s}}catch{continue}return{value:void 0};case"if":{if(!t||t.length!==3)throw new wr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],n);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],n):this.evaluateExpression(t[2],n)}}case"byuuid":return{value:this.evaluateByUUID({type:"function",function:"byuuid",args:t},n)};default:return}}getTermFromExpression(e,t){let n=e;if(n.type==="variable"&&n.name)return t.get(n.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 Fo.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 n=parseFloat(e.value);return!isNaN(n)&&n!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new wr("exo:byUUID requires exactly 1 argument (UUID string)");let n=this.evaluateExpression(e.args[0],t),i=this.getStringValue(n);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 o=this.tripleStore.findSubjectsByUUIDSync(s);if(o.length===0){this.uuidCache.set(s,null);return}let c=o[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let n=e.toLowerCase();this.uuidCache.set(n,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Yf.FilterExecutor=gI});var bI=T(kb=>{"use strict";Object.defineProperty(kb,"__esModule",{value:!0});kb.OptionalExecutor=void 0;var yI=class{static{a(this,"OptionalExecutor")}async*execute(e,t){let n=[];for await(let s of e)n.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(n,i)}async executeAll(e,t){let n=[];for(let i of this.hashJoin(e,t))n.push(i);return n}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let n=new Set;for(let l of e)for(let u of l.variables())n.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 n)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let o="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,o),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,o),f=c.get(u),d=!1;if(f)for(let p of f){let h=l.merge(p);h!==null&&(yield h,d=!0)}d||(yield l)}}computeHashKey(e,t,n){let i=[];for(let s of t){let o=e.get(s);i.push(o!==void 0?o.toString():"UNBOUND")}return i.join(n)}*nestedLoopJoin(e,t){for(let n of e){let i=!1;for(let s of t){let o=n.merge(s);o!==null&&(yield o,i=!0)}i||(yield n)}}};kb.OptionalExecutor=yI});var SI=T(Mb=>{"use strict";Object.defineProperty(Mb,"__esModule",{value:!0});Mb.UnionExecutor=void 0;var _I=class{static{a(this,"UnionExecutor")}async*execute(e,t){let n=new Set;for await(let i of e){let s=this.getSolutionKey(i);n.has(s)||(n.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);n.has(s)||(n.add(s),yield i)}}async executeAll(e,t){let n=[];async function*i(){for(let o of e)yield o}a(i,"generateLeft");async function*s(){for(let o of t)yield o}a(s,"generateRight");for await(let o of this.execute(i(),s()))n.push(o);return n}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Mb.UnionExecutor=_I});var OM=T($b=>{"use strict";Object.defineProperty($b,"__esModule",{value:!0});$b.MinusExecutor=void 0;var wI=class{static{a(this,"MinusExecutor")}async*execute(e,t){let n=[];for await(let s of e)n.push(s);let i=[];for await(let s of t)i.push(s);for(let s of n){let o=!1;for(let c of i)if(this.areCompatible(s,c)){o=!0;break}o||(yield s)}}async executeAll(e,t){let n=[];async function*i(){for(let o of e)yield o}a(i,"generateLeft");async function*s(){for(let o of t)yield o}a(s,"generateRight");for await(let o of this.execute(i(),s()))n.push(o);return n}areCompatible(e,t){let n=e.variables(),i=new Set(t.variables()),s=n.filter(o=>i.has(o));if(s.length===0)return!1;for(let o of s){let c=e.get(o),l=t.get(o);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};$b.MinusExecutor=wI});var PM=T(Xf=>{"use strict";Object.defineProperty(Xf,"__esModule",{value:!0});Xf.ValuesExecutor=Xf.ValuesExecutorError=void 0;var Aee=Aa(),xM=Ne(),Iee=Ye(),jb=class extends Error{static{a(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Xf.ValuesExecutorError=jb;var EI=class{static{a(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 n of this.execute(e))t.push(n);return t}createSolutionMapping(e){let t=new Aee.SolutionMapping;for(let[n,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(n,s)}return t}toRDFTerm(e){if(e.type==="iri")return new xM.IRI(e.value);if(e.type==="literal")return new Iee.Literal(e.value,e.datatype?new xM.IRI(e.datatype):void 0,e.language,e.direction);throw new jb(`Unknown term type: ${e.type}`)}};Xf.ValuesExecutor=EI});var NM=T(Qf=>{"use strict";Object.defineProperty(Qf,"__esModule",{value:!0});Qf.AggregateExecutor=Qf.AggregateExecutorError=void 0;var FM=Aa(),Yr=Ye(),TI=Ne(),Ree=Nb(),Cee=ub(),Oee=db(),LM=new TI.IRI("http://www.w3.org/2001/XMLSchema#integer"),eu=new TI.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Lo=new TI.IRI("http://www.w3.org/2001/XMLSchema#string");function DM(r){return typeof r=="object"&&r.type==="custom"}a(DM,"isCustomAggregation");var qh=class extends Error{static{a(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};Qf.AggregateExecutorError=qh;var vI=class{static{a(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Ree.FilterExecutor}execute(e,t){let n=this.groupSolutions(t,e.variables),i=[];for(let[s,o]of n.entries()){let c=new Map;for(let u of e.variables)if(o.length>0){let f=o[0].get(u);f&&c.set(u,f)}for(let u of e.aggregates){let f=this.computeAggregate(u.expression,o);c.set(u.variable,f)}let l=new FM.SolutionMapping;for(let[u,f]of c.entries())l.set(u,f);i.push(l)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let n=new Map;if(t.length===0)return n.set("",e),n;for(let i of e){let s=this.computeGroupKey(i,t),o=n.get(s);o?o.push(i):n.set(s,[i])}return n}computeGroupKey(e,t){return t.map(n=>{let i=e.get(n);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(DM(e.aggregation))return this.computeCustomAggregate(e,t);let n=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(n,e.distinct);return new Yr.Literal(String(s),LM)}case"sum":{let s=this.computeSum(n);return new Yr.Literal(String(s),eu)}case"avg":{let s=this.computeAvg(n);return new Yr.Literal(String(s),eu)}case"min":{let s=this.computeMin(n);return s===void 0?new Yr.Literal("",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}case"max":{let s=this.computeMax(n);return s===void 0?new Yr.Literal("",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}case"group_concat":{let s=this.computeGroupConcat(n,e.separator||" ",e.distinct);return new Yr.Literal(s||" ",Lo)}case"sample":{let s=this.computeSample(n,e.distinct);return s===void 0?new Yr.Literal(" ",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}default:{let s=i;throw new qh(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,o=Cee.CustomAggregateRegistry.getInstance().get(i);if(o||(o=Oee.BUILT_IN_AGGREGATES[i]),!o)throw new qh(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=o.init();for(let l of t){let u=null;if(e.expression){let d=this.evaluateExpression(e.expression,l);d!==void 0&&(u=d)}else u=1;let f;if(e.expression2){let d=this.evaluateExpression(e.expression2,l);f=d===void 0?null:d}o.step(c,u,f)}return o.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let n=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&n.push(s)}return n}evaluateExpression(e,t){if(e.type==="variable"){let n=t.get(e.name);return n==null?void 0:typeof n=="number"||typeof n=="string"||typeof n=="boolean"?n:typeof n=="object"&&"value"in n?n.value:n}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(n=>String(n))).size:e.length}computeSum(e){return e.map(n=>parseFloat(String(n))).filter(n=>!isNaN(n)).reduce((n,i)=>n+i,0)}computeAvg(e){let t=e.map(n=>parseFloat(String(n))).filter(n=>!isNaN(n));return t.length===0?0:t.reduce((n,i)=>n+i,0)/t.length}asAllNumeric(e){let t=[];for(let n of e){if(typeof n=="number"){t.push(n);continue}let i=String(n).trim();if(i==="")return null;let s=Number(i);if(Number.isNaN(s))return null;t.push(s)}return t.length>0?t:null}computeMin(e){if(e.length===0)return;let t=this.asAllNumeric(e);if(t)return Math.min(...t);let n=e.map(i=>String(i));return n.reduce((i,s)=>s<i?s:i,n[0])}computeMax(e){if(e.length===0)return;let t=this.asAllNumeric(e);if(t)return Math.max(...t);let n=e.map(i=>String(i));return n.reduce((i,s)=>s>i?s:i,n[0])}computeGroupConcat(e,t,n){let i=e.map(s=>String(s));return n&&(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 o=s[0],c=parseFloat(o);return isNaN(c)?o:c}let n=e[0];if(typeof n=="number")return n;let i=parseFloat(String(n));return isNaN(i)?String(n):i}createEmptyAggregateResult(e){let t=new FM.SolutionMapping;for(let n of e.aggregates){let i=n.expression.aggregation;if(DM(i)){t.set(n.variable,new Yr.Literal("0",eu));continue}switch(i){case"count":t.set(n.variable,new Yr.Literal("0",LM));break;case"sum":case"avg":t.set(n.variable,new Yr.Literal("0",eu));break;case"group_concat":t.set(n.variable,new Yr.Literal(" ",Lo));break;case"min":case"max":case"sample":t.set(n.variable,new Yr.Literal("",Lo));break;default:t.set(n.variable,new Yr.Literal("",Lo))}}return t}};Qf.AggregateExecutor=vI});var CI=T(Bb=>{"use strict";Object.defineProperty(Bb,"__esModule",{value:!0});Bb.ConstructExecutor=void 0;var xee=Ri(),tu=Ne(),AI=Ye(),II=dr(),Pee=fh(),RI=class{static{a(this,"ConstructExecutor")}async execute(e,t){let n=[],i=new Set;for(let s of t)for(let o of e)try{let c=this.instantiateTriple(o,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),n.push(c))}catch{continue}return n}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let n=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new xee.Triple(n,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let n=t.get(e.value);if(!n)throw new Error(`Unbound variable: ${e.value}`);return n}if(e.type==="iri")return new tu.IRI(e.value);if(e.type==="literal")return new AI.Literal(e.value,e.datatype?new tu.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new II.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let n=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new Pee.QuotedTriple(n,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let n=t.get(e.value);if(!n)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(n instanceof AI.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return n}if(e.type==="iri")return new tu.IRI(e.value);if(e.type==="blank")return new II.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 n=t.get(e.value);if(!n)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(n instanceof tu.IRI))throw new Error("Quoted triple predicate must be an IRI");return n}return new tu.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 tu.IRI(e.value);if(e.type==="blank")return new II.BlankNode(e.value);if(e.type==="literal")return new AI.Literal(e.value,e.datatype?new tu.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let n=e;throw new Error(`Invalid element type for quoted triple object: ${n.type}`)}};Bb.ConstructExecutor=RI});var MM=T(Jf=>{"use strict";Object.defineProperty(Jf,"__esModule",{value:!0});Jf.ServiceExecutor=Jf.ServiceExecutorError=void 0;var Fee=Aa(),kM=Ne(),Lee=Ye(),Dee=dr(),ru=class extends Error{static{a(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Jf.ServiceExecutorError=ru;var OI=class{static{a(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,n)=>fetch(t,n)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let n=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,n);for(let s of i)yield s}catch(n){if(e.silent)return;throw n}}async executeRemoteQuery(e,t){let n;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,o=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 ru(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(o)}}catch(s){if(n=s instanceof Error?s:new Error(String(s)),this.isRetryableError(n)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new ru(`Failed to query remote SPARQL endpoint ${e}: ${n.message}`,n)}throw new ru(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,n)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new Fee.SolutionMapping;for(let[n,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(n,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new kM.IRI(e.value);case"literal":{let t=e.datatype?new kM.IRI(e.datatype):void 0;return new Lee.Literal(e.value,t,e["xml:lang"])}case"bnode":return new Dee.BlankNode(e.value);default:throw new ru(`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))}};Jf.ServiceExecutor=OI});var jM=T(Zf=>{"use strict";Object.defineProperty(Zf,"__esModule",{value:!0});Zf.GraphExecutor=Zf.GraphExecutorError=void 0;var $M=Ne(),Ub=class extends Error{static{a(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Zf.GraphExecutorError=Ub;var xI=class{static{a(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,n){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,n);else throw new Ub(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,n){let i=new $M.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*n(e,i))}async*executeWithGraphVariable(e,t,n,i){if(i){let o=i.get(t.value);if(o&&o instanceof $M.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:o.value},n);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let o of s)for await(let c of n(e.pattern,o)){let l=c.clone();l.set(t.value,o),yield l}}};Zf.GraphExecutor=xI});var VM=T(ed=>{"use strict";Object.defineProperty(ed,"__esModule",{value:!0});ed.ClassHierarchyResolvingStore=ed.SymbolicClassAmbiguityError=void 0;var BM=Ri(),nu=Ne(),iu=Ct(),UM="\0",Vb=class extends Error{static{a(this,"SymbolicClassAmbiguityError")}constructor(e){super(`Ambiguous class reference '${e}' \u2014 two or more class files derive this symbolic form (a prefix collision). The prefix is an alias, not identity: reference the class by its uid, or narrow the ontology.`),this.symbolic=e,this.name="SymbolicClassAmbiguityError"}};ed.SymbolicClassAmbiguityError=Vb;var An=class r{static{a(this,"ClassHierarchyResolvingStore")}constructor(e){this.real=e,this.findSubjectsByUUID=e.findSubjectsByUUID?.bind(e),this.findSubjectsByUUIDSync=e.findSubjectsByUUIDSync?.bind(e),this.addToGraph=e.addToGraph?.bind(e),this.removeFromGraph=e.removeFromGraph?.bind(e),this.matchInGraph=e.matchInGraph?.bind(e),this.getNamedGraphs=e.getNamedGraphs?.bind(e),this.hasGraph=e.hasGraph?.bind(e),this.clearGraph=e.clearGraph?.bind(e),this.countInGraph=e.countInGraph?.bind(e)}async match(e,t,n){return t&&r.HIERARCHY_PREDICATES.has(t.value)&&e instanceof nu.IRI?this.matchHierarchySubject(e,t,n):t&&r.MEMBERSHIP_PREDICATES.has(t.value)&&n instanceof nu.IRI&&n.value.startsWith(r.ONTOLOGY_BASE)?this.matchMembershipObject(e,t,n):this.real.match(e,t,n)}async matchHierarchySubject(e,t,n){let i=await this.real.match(e,t,n);if(i.length>0)return i;let s=await this.resolveSymbolicToFileIri(e.value);if(!s)return i;let o=await this.real.match(s,t,n);return o.length===0?o:o.map(c=>new BM.Triple(e,c.predicate,c.object))}async matchMembershipObject(e,t,n){let i=await this.resolveSymbolicToFileIri(n.value),s=await this.real.match(e,t,n);if(!i)return s;let o=await this.real.match(e,t,i);if(o.length===0)return s;let c=o.map(l=>new BM.Triple(l.subject,l.predicate,n));return r.dedupTriples([...s,...c])}static dedupTriples(e){let t=new Set,n=[];for(let i of e){let s=`${r.termKey(i.subject)}${UM}${r.termKey(i.predicate)}${UM}${r.termKey(i.object)}`;t.has(s)||(t.add(s),n.push(i))}return n}static termKey(e){if(e instanceof nu.IRI)return`I:${e.value}`;if(e&&typeof e=="object"&&"value"in e){let t=e.value,n=e.datatype?.value??"";return`L:${String(t)}^${n}`}return`?:${String(e)}`}async resolveSymbolicToFileIri(e){let{index:t,ambiguous:n}=await this.getIndex();if(n.has(e))throw new Vb(e);return t.get(e)??null}async getIndex(){let e=await this.real.count(),t=r.INDEX_CACHE.get(this.real);if(t&&t.count===e)return{index:t.index,ambiguous:t.ambiguous};let{index:n,ambiguous:i}=await this.buildIndex();return r.INDEX_CACHE.set(this.real,{count:e,index:n,ambiguous:i}),{index:n,ambiguous:i}}async buildIndex(){let e=new Map,t=new Set,n=[...await this.real.match(void 0,new nu.IRI(r.EXO_ASSET_LABEL),void 0),...await this.real.match(void 0,new nu.IRI(r.RDFS_LABEL),void 0)];for(let i of n){if(!(i.subject instanceof nu.IRI))continue;let s=r.literalValue(i.object);if(s===null)continue;let o=r.labelToSymbolicIRI(s);if(!o)continue;let c=e.get(o);c?c.value!==i.subject.value&&t.add(o):e.set(o,i.subject)}return{index:e,ambiguous:t}}static literalValue(e){return typeof e=="object"&&e!==null&&"value"in e&&!(e instanceof nu.IRI)&&typeof e.value=="string"?e.value:null}static labelToSymbolicIRI(e){let t=iu.Namespace.fromPropertyKey(e);return!t||/[\s()]/.test(t.localName)?null:t.namespace.term(t.localName).value}add(e){return this.real.add(e)}remove(e){return this.real.remove(e)}has(e){return this.real.has(e)}addAll(e){return this.real.addAll(e)}removeAll(e){return this.real.removeAll(e)}clear(){return this.real.clear()}count(){return this.real.count()}subjects(){return this.real.subjects()}predicates(){return this.real.predicates()}objects(){return this.real.objects()}beginTransaction(){return this.real.beginTransaction()}};ed.ClassHierarchyResolvingStore=An;An.EXO_CLASS_SUPER_CLASS=iu.Namespace.EXO.term("Class_superClass").value;An.RDFS_SUBCLASS_OF=iu.Namespace.RDFS.term("subClassOf").value;An.RDFS_LABEL=iu.Namespace.RDFS.term("label").value;An.EXO_ASSET_LABEL=iu.Namespace.EXO.term("Asset_label").value;An.EXO_INSTANCE_CLASS=iu.Namespace.EXO.term("Instance_class").value;An.RDF_TYPE=iu.Namespace.RDF.term("type").value;An.ONTOLOGY_BASE="https://exocortex.my/ontology/";An.HIERARCHY_PREDICATES=new Set([An.EXO_CLASS_SUPER_CLASS,An.RDFS_SUBCLASS_OF]);An.MEMBERSHIP_PREDICATES=new Set([An.EXO_INSTANCE_CLASS,An.RDF_TYPE]);An.INDEX_CACHE=new WeakMap});var GM=T(rd=>{"use strict";Object.defineProperty(rd,"__esModule",{value:!0});rd.SPARQLGenerator=rd.SPARQLGeneratorError=void 0;var td=class extends Error{static{a(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};rd.SPARQLGeneratorError=td;var PI=class{static{a(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),n=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${n} WHERE {
|
|
103
|
+
`,s);l!==-1?(i+=e.substring(s,l),s=l):(i+=e.substring(s),s=e.length);continue}let c=this.tryReplacePrefixedName(e,s,n);if(c){i+=c.iri,s=c.endIndex;continue}i+=o,s++}return i}tryReplacePrefixedName(e,t,n){if(t>0&&/[a-zA-Z0-9_]/.test(e[t-1]))return null;for(let{prefix:i,baseIRI:s}of n){if(e.substring(t,t+i.length+1)!==i+":")continue;let o=t+i.length+1,c=o;for(;c<e.length&&/[a-zA-Z0-9_.%-]/.test(e[c]);)c++;if(c===o)continue;let l=e.substring(o,c);return{iri:`<${s}${l}.md>`,endIndex:c}}return null}findDeclaredPrefixes(e){let t=new Set,n=new RegExp(QZ.source,"gi"),i;for(;(i=n.exec(e))!==null;)t.add(i[1].toLowerCase());return t}skipLiteral(e,t){let n=e[t];if(t+2<e.length&&e.substring(t,t+3)===n+n+n){let s=e.indexOf(n+n+n,t+3);return s!==-1?s+3:e.length}let i=t+1;for(;i<e.length&&e[i]!==n;)e[i]==="\\"&&i++,i++;return i<e.length?i+1:e.length}};rb.VaultPrefixTransformer=NA});var Lf=T(Fi=>{"use strict";var ZZ=Fi&&Fi.__createBinding||(Object.create?(function(r,e,t,n){n===void 0&&(n=t);var i=Object.getOwnPropertyDescriptor(e,t);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:a(function(){return e[t]},"get")}),Object.defineProperty(r,n,i)}):(function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]})),eee=Fi&&Fi.__setModuleDefault||(Object.create?(function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}):function(r,e){r.default=e}),tee=Fi&&Fi.__importStar||(function(){var r=a(function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[n.length]=i);return n},r(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),i=0;i<n.length;i++)n[i]!=="default"&&ZZ(t,e,n[i]);return eee(t,e),t}})();Object.defineProperty(Fi,"__esModule",{value:!0});Fi.SPARQLParser=Fi.ExoQLParser=Fi.SPARQLParseError=void 0;var Qk=tee(Kk()),MA=OA(),$A=xA(),Jk=Hk(),jA=FA(),ree=Yk(),BA=Xk(),nee=kA(),zr=class extends Error{static{a(this,"SPARQLParseError")}constructor(e,t,n,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=n}};Fi.SPARQLParseError=zr;var nb=class{static{a(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new Qk.Parser({sparqlStar:!0}),this.generator=new Qk.Generator({sparqlStar:!0}),this.caseWhenTransformer=new MA.CaseWhenTransformer,this.lateralTransformer=new $A.LateralTransformer,this.prefixStarTransformer=new Jk.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new jA.DescribeOptionsTransformer,this.directionalLangTagTransformer=new ree.DirectionalLangTagTransformer,this.tripleTermTransformer=new BA.TripleTermTransformer,this.vaultPrefixTransformer=new nee.VaultPrefixTransformer}setVaultPrefixes(e){this.vaultPrefixTransformer.setVaultPrefixes(e)}parse(e){try{let t=this.vaultPrefixTransformer.transform(e),n=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=n.options;let i=n.query;i=this.directionalLangTagTransformer.transform(i),this.lastDirectionMappings=this.directionalLangTagTransformer.getAllMappings(),i=this.lateralTransformer.transform(i),i=this.caseWhenTransformer.transform(i),i=this.tripleTermTransformer.transform(i);let s=this.parser.parse(i);return this.validateQuery(s),this.lastDescribeOptions&&this.isDescribeQuery(s)&&(s.describeOptions=this.lastDescribeOptions),s}catch(t){if(t instanceof jA.DescribeOptionsTransformerError)throw new zr(t.message);if(t instanceof $A.LateralTransformerError)throw new zr(t.message);if(t instanceof MA.CaseWhenTransformerError)throw new zr(t.message);if(t instanceof BA.TripleTermTransformerError)throw new zr(t.message);if(t instanceof Error){let n=t.message.match(/line (\d+), column (\d+)/),i=n?parseInt(n[1],10):void 0,s=n?parseInt(n[2],10):void 0;throw new zr(`SPARQL syntax error: ${t.message}`,i,s,t)}throw t}}parseWithOptions(e){return{query:this.parse(e),describeOptions:this.lastDescribeOptions}}getLastDescribeOptions(){return this.lastDescribeOptions}async parseAsync(e){try{let t=this.vaultPrefixTransformer.transform(e),n=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=n.options;let i=n.query;i=this.directionalLangTagTransformer.transform(i),this.lastDirectionMappings=this.directionalLangTagTransformer.getAllMappings(),i=await this.prefixStarTransformer.transform(i),i=this.lateralTransformer.transform(i),i=this.caseWhenTransformer.transform(i),i=this.tripleTermTransformer.transform(i);let s=this.parser.parse(i);return this.validateQuery(s),this.lastDescribeOptions&&this.isDescribeQuery(s)&&(s.describeOptions=this.lastDescribeOptions),s}catch(t){if(t instanceof jA.DescribeOptionsTransformerError)throw new zr(t.message);if(t instanceof Jk.PrefixStarTransformerError)throw new zr(t.message);if(t instanceof $A.LateralTransformerError)throw new zr(t.message);if(t instanceof MA.CaseWhenTransformerError)throw new zr(t.message);if(t instanceof BA.TripleTermTransformerError)throw new zr(t.message);if(t instanceof Error){let n=t.message.match(/line (\d+), column (\d+)/),i=n?parseInt(n[1],10):void 0,s=n?parseInt(n[2],10):void 0;throw new zr(`SPARQL syntax error: ${t.message}`,i,s,t)}throw t}}async parseAsyncWithOptions(e){return{query:await this.parseAsync(e),describeOptions:this.lastDescribeOptions}}hasPrefixStar(e){return/PREFIX\s*\*/i.test(e)}hasLateral(e){return this.lateralTransformer.hasLateral(e)}hasDescribeOptions(e){return this.describeOptionsTransformer.hasDescribeOptions(e)}hasDirectionalLangTags(e){return this.directionalLangTagTransformer.hasDirectionalTags(e)}hasTripleTermSyntax(e){return this.tripleTermTransformer.hasTripleTermSyntax(e)}getLastDirectionMappings(){return new Map(this.lastDirectionMappings)}getDirectionForLanguage(e){return this.lastDirectionMappings.get(e.toLowerCase())}toString(e){try{return this.generator.stringify(e)}catch(t){throw t instanceof Error?new zr(`Failed to serialize SPARQL query: ${t.message}`,void 0,void 0,t):t}}getQueryType(e){if("queryType"in e&&e.type==="query")return e.queryType;throw new zr("Query does not have a valid queryType property")}isSelectQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="SELECT"}isConstructQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="CONSTRUCT"}isAskQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="ASK"}isDescribeQuery(e){return"queryType"in e&&e.type==="query"&&e.queryType==="DESCRIBE"}isUpdateQuery(e){return e.type==="update"}isInsertDataOperation(e){return"updateType"in e&&e.updateType==="insert"}isDeleteDataOperation(e){return"updateType"in e&&e.updateType==="delete"}validateQuery(e){if(!e||typeof e!="object")throw new zr("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new zr(`Invalid type: expected "query" or "update", got "${e.type}"`);if(e.type==="query"){let t=["SELECT","CONSTRUCT","ASK","DESCRIBE"];if(!t.includes(e.queryType))throw new zr(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};Fi.ExoQLParser=nb;Fi.SPARQLParser=nb});var Ql=T(ib=>{"use strict";Object.defineProperty(ib,"__esModule",{value:!0});ib.AlgebraTranslatorError=void 0;var UA=class extends Error{static{a(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};ib.AlgebraTranslatorError=UA});var sb=T(xo=>{"use strict";Object.defineProperty(xo,"__esModule",{value:!0});xo.isVariableExpression=iee;xo.isVariableTerm=see;xo.isNamedNode=oee;xo.isLiteral=aee;xo.isPropertyPath=cee;xo.isAggregateExpression=lee;xo.isOperationExpression=uee;xo.isFunctionCallExpression=fee;function iee(r){return typeof r=="object"&&r!==null&&"expression"in r&&"variable"in r}a(iee,"isVariableExpression");function see(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="Variable"}a(see,"isVariableTerm");function oee(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="NamedNode"}a(oee,"isNamedNode");function aee(r){return typeof r=="object"&&r!==null&&"termType"in r&&r.termType==="Literal"}a(aee,"isLiteral");function cee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="path"}a(cee,"isPropertyPath");function lee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="aggregate"}a(lee,"isAggregateExpression");function uee(r){return typeof r=="object"&&r!==null&&"type"in r&&r.type==="operation"}a(uee,"isOperationExpression");function fee(r){return typeof r=="object"&&r!==null&&"type"in r&&(r.type==="functionCall"||r.type==="functioncall")}a(fee,"isFunctionCallExpression")});var Zk=T(ob=>{"use strict";Object.defineProperty(ob,"__esModule",{value:!0});ob.TripleTranslator=void 0;var oi=Ql(),VA=class{static{a(this,"TripleTranslator")}constructor(){this.directionMappings=new Map}setDirectionMappings(e){this.directionMappings=e}translateBGP(e){if(!("triples"in e)||!Array.isArray(e.triples))throw new oi.AlgebraTranslatorError("BGP pattern must have triples array");return{type:"bgp",triples:e.triples.map(t=>this.translateTriple(t))}}translateTriple(e){if(!e.subject||!e.predicate||!e.object)throw new oi.AlgebraTranslatorError("Triple must have subject, predicate, and object");return{subject:this.translateTripleElement(e.subject),predicate:this.translatePredicate(e.predicate),object:this.translateTripleElement(e.object)}}translateConstructTemplate(e){return!e||!Array.isArray(e)?[]:e.map(t=>this.translateTriple(t))}translatePredicate(e){return"type"in e&&e.type==="path"?this.translatePropertyPath(e):this.translateTripleElement(e)}translatePropertyPath(e){if(!("pathType"in e)||!e.pathType)throw new oi.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new oi.AlgebraTranslatorError("Property path must have items array");let t=e.items.map(n=>this.translatePathItem(n));switch(e.pathType){case"/":return{type:"path",pathType:"/",items:t};case"|":return{type:"path",pathType:"|",items:t};case"^":if(t.length!==1)throw new oi.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new oi.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new oi.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new oi.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new oi.AlgebraTranslatorError(`Unsupported property path type: ${e.pathType}`)}}translatePathItem(e){if("type"in e&&e.type==="path")return this.translatePropertyPath(e);if("termType"in e&&e.termType==="NamedNode")return{type:"iri",value:e.value};let t="type"in e?e.type:"termType"in e?e.termType:"unknown";throw new oi.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new oi.AlgebraTranslatorError("Triple element must have termType");switch(e.termType){case"Variable":return{type:"variable",value:e.value};case"NamedNode":return{type:"iri",value:e.value};case"Literal":{let t={type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language};if(e.language){let n=this.directionMappings.get(e.language.toLowerCase());n&&(t.direction=n)}return t}case"BlankNode":return{type:"blank",value:e.value};case"Quad":return this.translateQuotedTriple(e);default:throw new oi.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new oi.AlgebraTranslatorError("Quoted triple must have subject, predicate, and object");return{type:"quoted",subject:this.translateTripleElement(e.subject),predicate:this.translateQuotedTriplePredicate(e.predicate),object:this.translateTripleElement(e.object)}}translateQuotedTriplePredicate(e){if(!e||!("termType"in e))throw new oi.AlgebraTranslatorError("Quoted triple predicate must have termType");switch(e.termType){case"Variable":return{type:"variable",value:e.value};case"NamedNode":return{type:"iri",value:e.value};default:throw new oi.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};ob.TripleTranslator=VA});var eM=T(ab=>{"use strict";Object.defineProperty(ab,"__esModule",{value:!0});ab.ExpressionTranslator=void 0;var Df=Ql(),GA=class{static{a(this,"ExpressionTranslator")}constructor(e){this.translateWhereFn=e.translateWhere,this.translateBGPFn=e.translateBGP,this.translatePatternFn=e.translatePattern}translateExpression(e){if(!e)throw new Df.AlgebraTranslatorError("Expression cannot be null or undefined");if("type"in e&&e.type==="operation")return this.translateOperationExpression(e);let t="type"in e?e.type:void 0;if(t==="functioncall"||t==="functionCall"){let n=e;return{type:"functionCall",function:n.function,args:n.args.map(i=>this.translateExpression(i))}}if("termType"in e)return this.translateTermExpression(e);throw new Df.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Df.AlgebraTranslatorError("Filter pattern must have expression");let t={type:"bgp",triples:[]};return{type:"filter",expression:this.translateExpression(e.expression),input:t}}translateTermExpression(e){if(e.termType==="Variable")return{type:"variable",name:e.value};if(e.termType==="Literal"){let t=e.value;return e.datatype&&(e.datatype.value.includes("#integer")||e.datatype.value.includes("#decimal")?t=parseFloat(e.value):e.datatype.value.includes("#boolean")&&(t=e.value==="true")),{type:"literal",value:t,datatype:e.datatype?.value}}return{type:"literal",value:String(e.value||e)}}translateOperationExpression(e){let t=["=","!=","<",">","<=",">="],n=["&&","||","!"],i=["+","-","*","/"],s=e.args.filter(o=>!("patterns"in o)||"termType"in o);return t.includes(e.operator)?{type:"comparison",operator:e.operator,left:this.translateExpression(s[0]),right:this.translateExpression(s[1])}:n.includes(e.operator)?{type:"logical",operator:e.operator,operands:s.map(o=>this.translateExpression(o))}:i.includes(e.operator)?{type:"arithmetic",operator:e.operator,left:this.translateExpression(s[0]),right:this.translateExpression(s[1])}:e.operator==="exists"||e.operator==="notexists"?this.translateExistsExpression(e):e.operator==="in"||e.operator==="notin"?this.translateInExpression(e):{type:"function",function:e.operator,args:s.map(o=>this.translateExpression(o))}}translateExistsExpression(e){if(!e.args||e.args.length!==1)throw new Df.AlgebraTranslatorError("EXISTS/NOT EXISTS must have exactly one pattern argument");let t=e.args[0],n;return t.type==="group"&&"patterns"in t&&t.patterns?n=this.translateWhereFn(t.patterns):t.type==="bgp"?n=this.translateBGPFn(t):n=this.translatePatternFn(t),{type:"exists",negated:e.operator==="notexists",pattern:n}}translateInExpression(e){if(!e.args||e.args.length!==2)throw new Df.AlgebraTranslatorError("IN/NOT IN must have exactly 2 arguments (expression and list)");let t=e.args[0],n=e.args[1];if(!Array.isArray(n))throw new Df.AlgebraTranslatorError("IN/NOT IN second argument must be an array of values");return{type:"in",expression:this.translateExpression(t),list:n.map(i=>this.translateExpression(i)),negated:e.operator==="notin"}}};ab.ExpressionTranslator=GA});var nM=T(cb=>{"use strict";Object.defineProperty(cb,"__esModule",{value:!0});cb.PatternTranslator=void 0;var tM=xA(),En=Ql(),rM=sb(),qA=class{static{a(this,"PatternTranslator")}constructor(e){this.directionMappings=new Map,this.translateExpressionFn=e.translateExpression,this.translateSelectFn=e.translateSelect,this.translateBGPFn=e.translateBGP}setDirectionMappings(e){this.directionMappings=e}translateWhere(e){if(e.length===0)throw new En.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(o=>o.type==="filter"),n=e.filter(o=>o.type==="bind"),i=e.filter(o=>o.type!=="filter"&&o.type!=="bind"),s;if(i.length===0)s={type:"bgp",triples:[]};else if(i.length===1)if(i[0].type==="optional"){let o=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:o?this.translateExpressionFn(o):void 0}}else s=this.translatePattern(i[0]);else{if(i[0].type==="optional"){let o=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:o?this.translateExpressionFn(o):void 0}}else s=this.translatePattern(i[0]);for(let o=1;o<i.length;o++){let c=i[o];if(this.isLateralPattern(c)){let l=this.extractLateralSubquery(c),u=this.removeLateralMarker(l),f=this.translateSelectFn(u);s={type:"lateraljoin",left:s,right:f}}else if(c.type==="optional"){let l=c.expression;s={type:"leftjoin",left:s,right:this.translateWhere(c.patterns),expression:l?this.translateExpressionFn(l):void 0}}else if(c.type==="minus")s={type:"minus",left:s,right:this.translateWhere(c.patterns)};else{let l=this.translatePattern(c);s={type:"join",left:s,right:l}}}}for(let o of n)s=this.translateBind(o,s);for(let o of t)s={type:"filter",expression:this.translateExpressionFn(o.expression),input:s};return s}translatePattern(e){if(!e||!e.type)throw new En.AlgebraTranslatorError("Invalid pattern: missing type");switch(e.type){case"bgp":return this.translateBGPFn(e);case"filter":return this.translateFilter(e);case"optional":return this.translateOptional(e);case"union":return this.translateUnion(e);case"minus":return this.translateMinus(e);case"values":return this.translateValues(e);case"group":return this.translateWhere(e.patterns);case"query":return this.translateSubquery(e);case"service":return this.translateService(e);case"graph":return this.translateGraph(e);default:throw new En.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new En.AlgebraTranslatorError("Filter pattern must have expression");let t={type:"bgp",triples:[]};return{type:"filter",expression:this.translateExpressionFn(e.expression),input:t}}translateOptional(e){if(!e.patterns||e.patterns.length===0)throw new En.AlgebraTranslatorError("OPTIONAL pattern must have patterns");let t=e.expression;return{type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(e.patterns),expression:t?this.translateExpressionFn(t):void 0}}translateUnion(e){if(!e.patterns||e.patterns.length<2)throw new En.AlgebraTranslatorError("UNION pattern must have at least 2 patterns");let t=a(i=>i.type==="graph"?this.translateGraph(i):i.type==="service"?this.translateService(i):"patterns"in i&&i.patterns&&Array.isArray(i.patterns)?this.translateWhere(i.patterns):this.translateWhere([i]),"translateBranch"),n={type:"union",left:t(e.patterns[0]),right:t(e.patterns[1])};for(let i=2;i<e.patterns.length;i++)n={type:"union",left:n,right:t(e.patterns[i])};return n}translateMinus(e){if(!e.patterns||e.patterns.length===0)throw new En.AlgebraTranslatorError("MINUS pattern must have patterns");return{type:"minus",left:{type:"bgp",triples:[]},right:this.translateWhere(e.patterns)}}translateValues(e){if(!e.values||!Array.isArray(e.values))throw new En.AlgebraTranslatorError("VALUES pattern must have values array");let t=new Set;for(let i of e.values)for(let s of Object.keys(i)){let o=s.startsWith("?")?s.slice(1):s;t.add(o)}let n=e.values.map(i=>this.translateValuesBinding(i));return{type:"values",variables:Array.from(t),bindings:n}}translateValuesBinding(e){let t={};for(let[n,i]of Object.entries(e)){let s=n.startsWith("?")?n.slice(1):n,o=i;if(o)if(o.termType==="NamedNode")t[s]={type:"iri",value:o.value};else if(o.termType==="Literal"){let c=o,l={type:"literal",value:c.value,datatype:c.datatype?.value,language:c.language||void 0};if(c.language){let u=this.directionMappings.get(c.language.toLowerCase());u&&(l.direction=u)}t[s]=l}else throw new En.AlgebraTranslatorError(`Unsupported VALUES term type: ${o.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new En.AlgebraTranslatorError("BIND pattern must have variable and expression");return{type:"extend",variable:e.variable.value,expression:this.translateExpressionFn(e.expression),input:t}}translateSubquery(e){if(e.queryType!=="SELECT")throw new En.AlgebraTranslatorError(`Only SELECT subqueries are supported, got: ${String(e.queryType)}`);let t=this.removeLateralMarker(e);return{type:"subquery",query:this.translateSelectFn(t)}}translateService(e){if(!e.name||e.name.termType!=="NamedNode")throw new En.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new En.AlgebraTranslatorError("SERVICE pattern must have patterns array");return{type:"service",endpoint:e.name.value,pattern:this.translateWhere(e.patterns),silent:e.silent||!1}}translateGraph(e){if(!e.name)throw new En.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new En.AlgebraTranslatorError("GRAPH pattern must have patterns array");let t;if(e.name.termType==="NamedNode")t={type:"iri",value:e.name.value};else if(e.name.termType==="Variable")t={type:"variable",value:e.name.value};else throw new En.AlgebraTranslatorError(`GRAPH pattern name must be NamedNode or Variable, got: ${e.name.termType}`);return{type:"graph",name:t,pattern:this.translateWhere(e.patterns)}}isLateralPattern(e){if(e.type==="query"&&this.isLateralSubquery(e))return!0;if(e.type==="group"&&e.patterns?.length===1){let t=e.patterns[0];if(t.type==="query"&&this.isLateralSubquery(t))return!0}return!1}extractLateralSubquery(e){if(e.type==="query")return e;if(e.type==="group"&&e.patterns?.length===1){let t=e.patterns[0];if(t.type==="query")return t}throw new En.AlgebraTranslatorError("Invalid lateral pattern structure")}isLateralSubquery(e){return!("queryType"in e)||e.queryType!=="SELECT"||!("variables"in e)||!e.variables?!1:e.variables.some(i=>(0,rM.isVariableTerm)(i)&&i.value===tM.LateralTransformer.LATERAL_MARKER)}removeLateralMarker(e){if(!("variables"in e)||!e.variables)return e;let t=e,n=t.variables;return{...t,variables:n.filter(i=>!((0,rM.isVariableTerm)(i)&&i.value===tM.LateralTransformer.LATERAL_MARKER))}}};cb.PatternTranslator=qA});var ub=T(kf=>{"use strict";Object.defineProperty(kf,"__esModule",{value:!0});kf.CustomAggregateRegistry=kf.CustomAggregateError=void 0;var Nf=class extends Error{static{a(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};kf.CustomAggregateError=Nf;var lb=class r{static{a(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return r.instance||(r.instance=new r),r.instance}static resetInstance(){r.instance&&r.instance.clear(),r.instance=null}register(e,t){if(!e||typeof e!="string")throw new Nf("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new Nf("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new Nf(`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}};kf.CustomAggregateRegistry=lb;lb.instance=null});var db=T(Je=>{"use strict";Object.defineProperty(Je,"__esModule",{value:!0});Je.BUILT_IN_AGGREGATES=Je.interceptAggregate=Je.slopeAggregate=Je.corrAggregate=Je.modeAggregate=Je.stddevAggregate=Je.varianceAggregate=Je.medianAggregate=Je.EXO_AGGREGATE_NS=void 0;Je.getNumericValue=$f;Je.createDecimalLiteral=Fs;Je.createDoubleLiteral=dee;Je.createPercentileAggregate=Jl;var Un=Ye(),Mf=Ne(),fb=new Mf.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Zl=new Mf.IRI("http://www.w3.org/2001/XMLSchema#double");Je.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function $f(r){return r==null?NaN:typeof r=="number"?r:typeof r=="string"?parseFloat(r):r instanceof Un.Literal?parseFloat(r.value):r instanceof Mf.IRI?NaN:typeof r=="boolean"?r?1:0:NaN}a($f,"getNumericValue");function Fs(r){return new Un.Literal(String(r),fb)}a(Fs,"createDecimalLiteral");function dee(r){return new Un.Literal(String(r),Zl)}a(dee,"createDoubleLiteral");Je.medianAggregate={init(){return{values:[]}},step(r,e){let t=r,n=$f(e);isNaN(n)||t.values.push(n)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=[...t].sort((o,c)=>o-c),i=Math.floor(n.length/2),s=n.length%2!==0?n[i]:(n[i-1]+n[i])/2;return Fs(s)}};Je.varianceAggregate={init(){return{values:[]}},step(r,e){let t=r,n=$f(e);isNaN(n)||t.values.push(n)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-n,2),0)/t.length;return Fs(i)}};Je.stddevAggregate={init(){return{values:[]}},step(r,e){Je.varianceAggregate.step(r,e)},finalize(r){let e=r,{values:t}=e;if(t.length===0)return Fs(0);let n=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-n,2),0)/t.length;return Fs(Math.sqrt(i))}};Je.modeAggregate={init(){return{counts:new Map,values:new Map}},step(r,e){if(e==null)return;let t=r,n=String(e instanceof Un.Literal||e instanceof Mf.IRI?e.value:e),i=t.counts.get(n)||0;t.counts.set(n,i+1),t.values.set(n,e)},finalize(r){let e=r;if(e.counts.size===0)return new Un.Literal(" ",new Mf.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",n=0;for(let[o,c]of e.counts)c>n&&(n=c,t=o);let i=e.values.get(t);if(i instanceof Un.Literal)return i;let s=parseFloat(t);return isNaN(s)?new Un.Literal(t,new Mf.IRI("http://www.w3.org/2001/XMLSchema#string")):Fs(s)}};function Jl(r){let e=Math.max(0,Math.min(100,r))/100;return{init(){return{values:[],percentile:e}},step(t,n){let i=t,s=$f(n);isNaN(s)||i.values.push(s)},finalize(t){let n=t,{values:i}=n;if(i.length===0)return Fs(0);let s=[...i].sort((d,p)=>d-p),o=n.percentile*(s.length-1),c=Math.floor(o),l=Math.ceil(o);if(c===l)return Fs(s[c]);let u=o-c,f=s[c]*(1-u)+s[l]*u;return Fs(f)}}}a(Jl,"createPercentileAggregate");function WA(){return{n:0,sx:0,sy:0,sxx:0,syy:0,sxy:0}}a(WA,"bivariateInit");function zA(r,e,t){let n=r,i=$f(e),s=$f(t);isNaN(i)||isNaN(s)||(n.n+=1,n.sx+=i,n.sy+=s,n.sxx+=i*i,n.syy+=s*s,n.sxy+=i*s)}a(zA,"bivariateStep");Je.corrAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,syy:s,sxy:o}=r;if(e<2)return new Un.Literal("NaN",Zl);let c=e*o-t*n,l=e*i-t*t,u=e*s-n*n;return l<=0||u<=0?new Un.Literal("NaN",Zl):new Un.Literal(String(c/Math.sqrt(l*u)),fb)}};Je.slopeAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,sxy:s}=r;if(e<2)return new Un.Literal("NaN",Zl);let o=e*i-t*t;return o<=0?new Un.Literal("NaN",Zl):new Un.Literal(String((e*s-t*n)/o),fb)}};Je.interceptAggregate={arity:2,init:WA,step:zA,finalize(r){let{n:e,sx:t,sy:n,sxx:i,sxy:s}=r;if(e<2)return new Un.Literal("NaN",Zl);let o=e*i-t*t;if(o<=0)return new Un.Literal("NaN",Zl);let c=(e*s-t*n)/o;return new Un.Literal(String((n-c*t)/e),fb)}};Je.BUILT_IN_AGGREGATES={[`${Je.EXO_AGGREGATE_NS}median`]:Je.medianAggregate,[`${Je.EXO_AGGREGATE_NS}variance`]:Je.varianceAggregate,[`${Je.EXO_AGGREGATE_NS}stddev`]:Je.stddevAggregate,[`${Je.EXO_AGGREGATE_NS}mode`]:Je.modeAggregate,[`${Je.EXO_AGGREGATE_NS}percentile25`]:Jl(25),[`${Je.EXO_AGGREGATE_NS}percentile50`]:Jl(50),[`${Je.EXO_AGGREGATE_NS}percentile75`]:Jl(75),[`${Je.EXO_AGGREGATE_NS}percentile90`]:Jl(90),[`${Je.EXO_AGGREGATE_NS}percentile95`]:Jl(95),[`${Je.EXO_AGGREGATE_NS}percentile99`]:Jl(99),[`${Je.EXO_AGGREGATE_NS}corr`]:Je.corrAggregate,[`${Je.EXO_AGGREGATE_NS}slope`]:Je.slopeAggregate,[`${Je.EXO_AGGREGATE_NS}intercept`]:Je.interceptAggregate}});var oM=T(pb=>{"use strict";Object.defineProperty(pb,"__esModule",{value:!0});pb.AggregateTranslator=void 0;var iM=Ql(),sM=sb(),KA=ub(),Ta=db(),HA=class{static{a(this,"AggregateTranslator")}constructor(e){this.aggregateCounter=0,this.translateExpressionFn=e.translateExpression}resetCounter(){this.aggregateCounter=0}extractAggregatesWithMapping(e,t){if(!e)return[];let n=[];for(let i of e)if((0,sM.isVariableExpression)(i))if("type"in i.expression&&i.expression.type==="aggregate")n.push({variable:i.variable.value,expression:this.translateAggregateExpression(i.expression)}),t.set(i.expression,i.variable.value);else{let s=this.customAggregateIri(i.expression);s?(n.push({variable:i.variable.value,expression:this.translateCustomAggregateFunctionCall(i.expression,s)}),t.set(i.expression,i.variable.value)):this.collectNestedAggregates(i.expression,n,t)}return n}extractGroupVariables(e){return e?e.filter(t=>t.expression&&"termType"in t.expression&&t.expression.termType==="Variable").map(t=>t.expression.value):[]}extractHavingExpressions(e,t,n){if(!e||e.length===0)return[];for(let i of e)this.collectNestedAggregates(i,t,n);return e.map(i=>this.transformExpressionWithAggregateVars(i,n))}transformExpressionWithAggregateVars(e,t){let n=t.get(e);if(n!==void 0)return{type:"variable",name:n};if("type"in e&&e.type==="operation"&&"args"in e){let i=e,s=i.args.filter(u=>!Array.isArray(u)&&!("patterns"in u)).map(u=>this.transformExpressionWithAggregateVars(u,t)),o=["=","!=","<",">","<=",">="],c=["&&","||","!"],l=["+","-","*","/"];return o.includes(i.operator)?{type:"comparison",operator:i.operator,left:s[0],right:s[1]}:c.includes(i.operator)?{type:"logical",operator:i.operator,operands:s}:l.includes(i.operator)?{type:"arithmetic",operator:i.operator,left:s[0],right:s[1]}:{type:"function",function:i.operator,args:s}}return this.translateExpressionFn(e)}translateOrderComparator(e){return{expression:this.translateExpressionFn(e.expression),descending:e.descending||!1}}translateAggregateExpression(e){let t=e.aggregation,n=a(()=>{if(e.expression&&!("termType"in e.expression&&e.expression.termType==="Wildcard"))return this.translateExpressionFn(e.expression)},"translateInnerExpr");if(typeof t=="string"){let s=t.toLowerCase();return["count","sum","avg","min","max","group_concat","sample"].includes(s)?{type:"aggregate",aggregation:s,expression:n(),distinct:e.distinct||!1,separator:e.separator}:{type:"aggregate",aggregation:{type:"custom",iri:t},expression:n(),distinct:e.distinct||!1,separator:e.separator}}let i=t;if(i&&typeof i=="object"){let s,o=i;if(o.termType==="NamedNode"&&typeof o.value=="string")s=o.value;else if("value"in o)s=String(o.value);else throw new iM.AlgebraTranslatorError(`Invalid custom aggregate: expected IRI but got ${JSON.stringify(i)}`);return{type:"aggregate",aggregation:{type:"custom",iri:s},expression:n(),distinct:e.distinct||!1,separator:e.separator}}throw new iM.AlgebraTranslatorError(`Unknown aggregate format: ${JSON.stringify(t)}`)}customAggregateIri(e){if(!(0,sM.isFunctionCallExpression)(e))return null;let t=e.function,n=null;if(typeof t=="string"?n=t:t&&typeof t=="object"&&"value"in t&&(n=String(t.value)),!n)return null;if(n in Ta.BUILT_IN_AGGREGATES||KA.CustomAggregateRegistry.getInstance().get(n)!==void 0)return n;if(n.startsWith(Ta.EXO_AGGREGATE_NS)){let s=[...Object.keys(Ta.BUILT_IN_AGGREGATES),...KA.CustomAggregateRegistry.getInstance().getRegisteredIris()].filter(o=>o.startsWith(Ta.EXO_AGGREGATE_NS)).map(o=>o.slice(Ta.EXO_AGGREGATE_NS.length)).sort();throw new Error(`Unknown aggregate agg:${n.slice(Ta.EXO_AGGREGATE_NS.length)}. Registered: ${s.length>0?s.map(o=>`agg:${o}`).join(", "):"(none)"}.`)}return null}translateCustomAggregateFunctionCall(e,t){let n=e,s=(KA.CustomAggregateRegistry.getInstance().get(t)??Ta.BUILT_IN_AGGREGATES[t])?.arity??1,o=n.args?.length??0;if(o!==s){let u=t.startsWith(Ta.EXO_AGGREGATE_NS)?`agg:${t.slice(Ta.EXO_AGGREGATE_NS.length)}`:t;throw new Error(`${u} takes exactly ${s} argument${s===1?"":"s"}, got ${o}.`)}let c=o>0?n.args?.[0]:void 0,l=s===2?n.args?.[1]:void 0;return{type:"aggregate",aggregation:{type:"custom",iri:t},expression:c?this.translateExpressionFn(c):void 0,expression2:l?this.translateExpressionFn(l):void 0,distinct:n.distinct||!1}}collectNestedAggregates(e,t,n){if(!e)return;if("type"in e&&e.type==="aggregate"){let s=`__agg${this.aggregateCounter++}`;t.push({variable:s,expression:this.translateAggregateExpression(e)}),n.set(e,s);return}let i=this.customAggregateIri(e);if(i){let s=`__agg${this.aggregateCounter++}`;t.push({variable:s,expression:this.translateCustomAggregateFunctionCall(e,i)}),n.set(e,s);return}if("type"in e&&e.type==="operation"&&"args"in e){let s=e;for(let o of s.args)!Array.isArray(o)&&"type"in o&&!("patterns"in o)?this.collectNestedAggregates(o,t,n):"termType"in o&&this.collectNestedAggregates(o,t,n)}}};pb.AggregateTranslator=HA});var jf=T(Oc=>{"use strict";Object.defineProperty(Oc,"__esModule",{value:!0});Oc.AlgebraTranslator=Oc.ExoQLAlgebraTranslator=Oc.AlgebraTranslatorError=void 0;var hb=Ql(),mb=sb(),pee=Zk(),hee=eM(),mee=nM(),gee=oM(),yee=Ql();Object.defineProperty(Oc,"AlgebraTranslatorError",{enumerable:!0,get:a(function(){return yee.AlgebraTranslatorError},"get")});var gb=class{static{a(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new pee.TripleTranslator,this.expressionTranslator=new hee.ExpressionTranslator({translateWhere:a(e=>this.patternTranslator.translateWhere(e),"translateWhere"),translateBGP:a(e=>this.tripleTranslator.translateBGP(e),"translateBGP"),translatePattern:a(e=>this.patternTranslator.translatePattern(e),"translatePattern")}),this.patternTranslator=new mee.PatternTranslator({translateExpression:a(e=>this.expressionTranslator.translateExpression(e),"translateExpression"),translateSelect:a(e=>this.translateSelect(e),"translateSelect"),translateBGP:a(e=>this.tripleTranslator.translateBGP(e),"translateBGP")}),this.aggregateTranslator=new gee.AggregateTranslator({translateExpression:a(e=>this.expressionTranslator.translateExpression(e),"translateExpression")})}setDirectionMappings(e){this.tripleTranslator.setDirectionMappings(e),this.patternTranslator.setDirectionMappings(e)}translate(e){if(e.type!=="query")throw new hb.AlgebraTranslatorError("Only query operations are supported (not updates)");if(e.queryType==="SELECT")return this.translateSelect(e);if(e.queryType==="CONSTRUCT")return this.translateConstruct(e);if(e.queryType==="ASK")return this.translateAsk(e);if(e.queryType==="DESCRIBE")return this.translateDescribe(e);throw new hb.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new hb.AlgebraTranslatorError("SELECT query must have WHERE clause");let t=this.patternTranslator.translateWhere(e.where);this.aggregateTranslator.resetCounter();let n=new Map,i=Array.isArray(e.variables)?e.variables.filter(l=>!("termType"in l&&l.termType==="Wildcard")):[],s=this.aggregateTranslator.extractAggregatesWithMapping(i,n),o=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,n);if((s.length>0||o.length>0||c.length>0)&&(t={type:"group",variables:o,aggregates:s,having:c.length>0?c:void 0,input:t}),i.length>0){for(let l of i)if((0,mb.isVariableExpression)(l)){if("type"in l.expression&&l.expression.type==="aggregate")continue;let u=this.aggregateTranslator.transformExpressionWithAggregateVars(l.expression,n);t={type:"extend",variable:l.variable.value,expression:u,input:t}}}if(e.order&&e.order.length>0&&(t={type:"orderby",comparators:e.order.map(l=>this.aggregateTranslator.translateOrderComparator(l)),input:t}),i.length>0){let l=i.filter(u=>(0,mb.isVariableTerm)(u)||(0,mb.isVariableExpression)(u)).map(u=>(0,mb.isVariableTerm)(u)?u.value:u.variable.value);l.length>0&&(t={type:"project",variables:l,input:t})}return e.distinct&&(t={type:"distinct",input:t}),e.reduced&&(t={type:"reduced",input:t}),(e.limit!==void 0||e.offset!==void 0)&&(t={type:"slice",limit:e.limit,offset:e.offset,input:t}),t}translateConstruct(e){let t=this.tripleTranslator.translateConstructTemplate(e.template??[]);if(!e.where||e.where.length===0)throw new hb.AlgebraTranslatorError("CONSTRUCT query must have WHERE clause");let n=this.patternTranslator.translateWhere(e.where),i=e;return(i.limit!==void 0||i.offset!==void 0)&&(n={type:"slice",limit:i.limit,offset:i.offset,input:n}),{type:"construct",template:t,where:n}}translateAsk(e){return{type:"ask",where:e.where&&e.where.length>0?this.patternTranslator.translateWhere(e.where):{type:"bgp",triples:[]}}}translateDescribe(e){let t=[];if(e.variables&&Array.isArray(e.variables)){let s=e.variables;for(let o of s)o.termType==="Wildcard"||o.value==="*"||(o.termType==="Variable"?t.push({type:"variable",value:o.value}):o.termType==="NamedNode"&&t.push({type:"iri",value:o.value}))}let n;e.where&&e.where.length>0&&(n=this.patternTranslator.translateWhere(e.where));let i=e.describeOptions;return{type:"describe",resources:t,where:n,depth:i?.depth,symmetric:i?.symmetric}}};Oc.ExoQLAlgebraTranslator=gb;Oc.AlgebraTranslator=gb});var Aa=T(yb=>{"use strict";Object.defineProperty(yb,"__esModule",{value:!0});yb.SolutionMapping=void 0;var aM=Ye(),cM=Ne(),lM=dr(),YA=class r{static{a(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,n]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(n,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new r(this.bindings);for(let[n,i]of e.getBindings().entries())t.set(n,i);return t}clone(){return new r(this.bindings)}areEqual(e,t){return e instanceof aM.Literal&&t instanceof aM.Literal?e.equals(t):e instanceof cM.IRI&&t instanceof cM.IRI?e.value===t.value:e instanceof lM.BlankNode&&t instanceof lM.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,n]of this.bindings.entries())e[t]=n.toString();return e}size(){return this.bindings.size}};yb.SolutionMapping=YA});var fM=T(Uf=>{"use strict";Object.defineProperty(Uf,"__esModule",{value:!0});Uf.PropertyPathExecutor=Uf.PropertyPathExecutorError=void 0;var bee=Aa(),bb=Ne(),uM=dr(),_ee=Ye(),Bf=class extends Error{static{a(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Uf.PropertyPathExecutorError=Bf;var XA=class r{static{a(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,n){if(this.isLiteralElement(e)||this.isLiteralElement(n)){let o=this.isLiteralElement(e)?"subject":"object",c=this.isLiteralElement(e)?e:n,l="value"in c?String(c.value):"<unknown>",u=l.length>80?`${l.slice(0,77)}...`:l,f=this.describePath(t),d={position:o,value:u,path:f,hint:"Wikilink could not be resolved to IRI (likely label-form wikilink with no matching basename/alias). Check whether the target file exists in the queried vault, or add an alias. See issue #3282."};if(console.error(`[PropertyPathExecutor] literal-safety guard fired: literal in ${o} position \u2014 yielding 0 solutions. value="${u}" path=${f}`,d),r.isStrictModeEnabled())throw new Bf(`Literal subject in property path: "${u}" (path=${f}). Set EXOCORTEX_SPARQL_STRICT=0 or omit --strict to fall back to warn-and-empty behaviour.`);return}let i=await this.resolveElement(e),s=this.isVariable(n)?null:await this.resolveElement(n);for(let o of i){let c=await this.evaluatePath(o,t,s);for(let l of c){let u=new bee.SolutionMapping;this.isVariable(e)&&u.set(e.value,o),this.isVariable(n)&&u.set(n.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new Bf("Predicate is not a property path");let n=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(n,e.predicate,i)){let o=t.merge(s);o!==null&&(yield o)}}async evaluatePath(e,t,n){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,n);case"|":return this.evaluateAlternativePath(e,t.items,n);case"^":return this.evaluateInversePath(e,t.items[0],n);case"+":return this.evaluateOneOrMorePath(e,t.items[0],n);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],n);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],n)}}async evaluateSequencePath(e,t,n){let i=new Set([e]);for(let s=0;s<t.length;s++){let o=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,o,c?n:null);for(let d of f)l.add(d)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,n){let i=new Set;for(let s of t){let o=await this.evaluatePathItem(e,s,n);for(let c of o)i.add(c)}return i}async evaluateInversePath(e,t,n){if(t.type==="iri"){let i=new bb.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),o=new Set;for(let c of s)(n===null||this.nodeInSet(c.subject,n))&&o.add(c.subject);return o}else return this.evaluatePath(e,this.invertPath(t),n)}async evaluateOneOrMorePath(e,t,n){let i=new Set,s=new Set,o=[{node:e,depth:0}];for(;o.length>0;){let c=o.shift();if(!c)break;let{node:l,depth:u}=c;if(u>=this.MAX_DEPTH)continue;let f=await this.evaluatePathItem(l,t,null);for(let d of f){let p=this.nodeToKey(d);(n===null||this.nodeInSet(d,n))&&s.add(d),i.has(p)||(i.add(p),o.push({node:d,depth:u+1}))}}return s}async evaluateZeroOrMorePath(e,t,n){let i=await this.evaluateOneOrMorePath(e,t,n);return(n===null||this.nodeInSet(e,n))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,n){let i=new Set;(n===null||this.nodeInSet(e,n))&&i.add(e);let s=await this.evaluatePathItem(e,t,n);for(let o of s)i.add(o);return i}async evaluatePathItem(e,t,n){if(t.type==="iri"){let i=new bb.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),o=new Set;for(let c of s)(n===null||this.nodeInSet(c.object,n))&&o.add(c.object);return o}else return this.evaluatePath(e,t,n)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(t=>t.type==="iri"?{type:"path",pathType:"^",items:[t]}:this.invertPath(t))};case"|":return{type:"path",pathType:"|",items:e.items.map(t=>t.type==="iri"?{type:"path",pathType:"^",items:[t]}:this.invertPath(t))};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 n=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)n.add(s.subject),n.add(s.object);return n}let t=new Set;switch(e.type){case"iri":t.add(new bb.IRI(e.value));break;case"blank":t.add(new uM.BlankNode(e.value));break;default:throw new Bf(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let n=t.get(e.value);if(n){if(n instanceof bb.IRI)return{type:"iri",value:n.value};if(n instanceof uM.BlankNode)return{type:"blank",value:n.id};if(n instanceof _ee.Literal)return{type:"literal",value:n.value,datatype:n.datatype?.value,language:n.language,direction:n.direction}}}return e}isVariable(e){return e.type==="variable"}isLiteralElement(e){return e.type==="literal"}isPropertyPath(e){return e.type==="path"}nodeToKey(e){return e.toString()}nodeInSet(e,t){let n=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===n)return!0;return!1}describePath(e){try{let t=e.items,n=a(s=>{if(s&&typeof s=="object"&&"type"in s){let o=s;if(o.type==="iri")return`<${String(o.value)}>`;if(o.type==="path")return this.describePath(o)}return"?"},"renderItem");if(!Array.isArray(t)||t.length===0)return"(?)";if(t.length===1){let s=n(t[0]);return e.pathType==="^"?`(^${s})`:e.pathType==="+"||e.pathType==="*"||e.pathType==="?"?`(${s}${e.pathType})`:`(${s})`}return`(${t.map(n).join(` ${e.pathType} `)})`}catch{return"<unprintable-path>"}}static isStrictModeEnabled(){let t=(typeof process<"u"?process.env:void 0)?.EXOCORTEX_SPARQL_STRICT;if(!t)return!1;let n=t.trim().toLowerCase();return n==="1"||n==="true"||n==="yes"}};Uf.PropertyPathExecutor=XA});var ZA=T(Vf=>{"use strict";Object.defineProperty(Vf,"__esModule",{value:!0});Vf.BGPExecutor=Vf.BGPExecutorError=void 0;var _b=Aa(),xc=Ne(),QA=Ye(),Sb=dr(),wb=fh(),dM=fM(),vn=class extends Error{static{a(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Vf.BGPExecutorError=vn;var JA=class{static{a(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new dM.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new _b.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let n=1;n<e.triples.length;n++)t=this.joinWithPattern(t,e.triples[n]);for await(let n of t)yield n}async executeAll(e){let t=[];for await(let n of this.execute(e))t.push(n);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new _b.SolutionMapping;return}let n=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)n=this.joinWithPatternInGraph(n,e.triples[i],t);for await(let i of n)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new vn("Property paths within named graphs are not yet supported");let n=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(n)){this.warnLiteralGuard("matchTriplePatternInGraph",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:n);return}let i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(n)?void 0:this.toRDFTermAsPredicate(n),o=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new vn("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,o,t);for(let l of c){let u=new _b.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(n)&&u.set(n.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,n){let i=[];for await(let s of e)i.push(s);for(let s of i){let o=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(o,n)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){if(this.isLiteral(e.subject)||this.isLiteral(e.object)){this.warnLiteralGuard("matchTriplePattern.propertyPath",this.isLiteral(e.subject)?"subject":"object",this.isLiteral(e.subject)?e.subject:e.object);return}yield*this.propertyPathExecutor.execute(e.subject,e.predicate,e.object);return}let t=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(t)){this.warnLiteralGuard("matchTriplePattern",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:t);return}let n=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),o=await this.tripleStore.match(n,i,s);for(let c of o){let l=new _b.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,d]of u.entries())l.set(f,d)}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,d]of u.entries())l.set(f,d)}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 wb.QuotedTriple))return null;let n=new Map;if(this.isVariable(e.subject))n.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,o]of i)n.set(s,o)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")n.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))n.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,o]of i)n.set(s,o)}else if(!this.elementsMatch(e.object,t.object))return null;return n}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof xc.IRI&&e.value===t.value;case"literal":return!(!(t instanceof QA.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof Sb.BlankNode&&e.value===t.id;case"quoted":return t instanceof wb.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let n=[];for await(let i of e)n.push(i);for(let i of n){let s=this.instantiatePattern(t,i);for await(let o of this.matchTriplePattern(s)){let c=i.merge(o);c!==null&&(yield c)}}}instantiatePattern(e,t){let n=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:n,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let n=t.get(e.value);if(n)return this.toAlgebraElement(n)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let n=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:n,predicate:i,object:s}}instantiatePredicateVariable(e,t){let n=t.get(e.value);return n&&n instanceof xc.IRI?{type:"iri",value:n.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}isLiteral(e){return e.type==="literal"}warnLiteralGuard(e,t,n){let i="value"in n?String(n.value):"<unknown>",s=i.length>80?`${i.slice(0,77)}...`:i,o={executor:"BGPExecutor",context:e,position:t,value:s,hint:"Wikilink could not be resolved to IRI (likely label-form wikilink with no matching basename/alias). Check whether the target file exists in the queried vault, or add an alias. See issue #3282."};if(console.error(`[BGPExecutor] literal-safety guard fired in ${e}: literal in ${t} position \u2014 yielding 0 solutions. value="${s}"`,o),dM.PropertyPathExecutor.isStrictModeEnabled())throw new vn(`Literal in ${t} position (${e}): "${s}". Set EXOCORTEX_SPARQL_STRICT=0 or omit --strict to fall back to warn-and-empty behaviour.`)}toRDFTermAsSubject(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"blank":return new Sb.BlankNode(e.value);case"literal":throw new vn("Literals cannot appear in subject position");case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vn(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),n=e.predicate.type==="iri"?new xc.IRI(e.predicate.value):(()=>{throw new vn("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new wb.QuotedTriple(t,n,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"literal":throw new vn("Literals cannot appear in predicate position");case"blank":throw new vn("Blank nodes cannot appear in predicate position");case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);default:throw new vn(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new xc.IRI(e.value);case"literal":return new QA.Literal(e.value,e.datatype?new xc.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new Sb.BlankNode(e.value);case"variable":throw new vn(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new vn(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof xc.IRI)return{type:"iri",value:e.value};if(e instanceof QA.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof Sb.BlankNode)return{type:"blank",value:e.id};if(e instanceof wb.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new vn(`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)}}};Vf.BGPExecutor=JA});var pM=T(Eb=>{"use strict";Object.defineProperty(Eb,"__esModule",{value:!0});Eb.StringFunctions=void 0;var Gf=Ne(),Pc=Ye(),eI=dr(),jh=class r{static{a(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof Gf.IRI||e instanceof Pc.Literal?e.value:e instanceof eI.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof Pc.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof Pc.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[n,i]=r.parseDirectionalLangTag(e),[s,o]=r.parseDirectionalLangTag(t),c=n.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":o&&i!==o?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let n=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[n,i]}static regex(e,t,n){try{let i=n?n.includes("u")?n:n+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}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,n){let i=t-1;if(i<0){if(n!==void 0){let s=n+i;return s<=0?"":e.substring(0,s)}return e}return n!==void 0?e.substring(i,i+n):e.substring(i)}static strBefore(e,t){if(t==="")return"";let n=e.indexOf(t);return n===-1?"":e.substring(0,n)}static strAfter(e,t){if(t==="")return e;let n=e.indexOf(t);return n===-1?"":e.substring(n+t.length)}static concat(...e){return e.join("")}static replace(e,t,n,i){try{let s=i||"g",o=s.includes("u")?s:s+"u",c=new RegExp(t,o);return e.replace(c,n)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static encodeForUri(e){return encodeURIComponent(e)}static normalize(e,t){if(e===void 0)throw new Error("NORMALIZE: string argument is undefined");let n;if(e instanceof Pc.Literal)n=e.value;else if(e instanceof Gf.IRI)n=e.value;else if(e instanceof eI.BlankNode)n=e.id;else if(typeof e=="string")n=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof Pc.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof Gf.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!r.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=n.normalize(i);return new Pc.Literal(s,new Gf.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 Pc.Literal)t=e.value;else if(e instanceof Gf.IRI)t=e.value;else if(e instanceof eI.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let n=r.unicodeCaseFold(t);return new Pc.Literal(n,new Gf.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let n of e){let i=r.CASE_FOLDING_MAP.get(n);i!==void 0?t+=i:t+=n.toLowerCase()}return t}};Eb.StringFunctions=jh;jh.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];jh.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 hM=T(vb=>{"use strict";Object.defineProperty(vb,"__esModule",{value:!0});vb.MathFunctions=void 0;var tI=class{static{a(this,"MathFunctions")}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()}};vb.MathFunctions=tI});var Bh=T(Tb=>{"use strict";Object.defineProperty(Tb,"__esModule",{value:!0});Tb.DateTimeParsing=void 0;var See=Ne(),wee=Ye(),rI=class r{static{a(this,"DateTimeParsing")}static parseDate(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`PARSEDATE: invalid date string '${e}'`);return t.getTime()}static parseDayTimeDuration(e){if(!e)throw new Error("parseDayTimeDuration: duration string is empty");let t=!1,n=e.trim();if(n.startsWith("-")&&(t=!0,n=n.substring(1)),!n.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);n=n.substring(1);let i=0,s=n.indexOf("T"),o="",c="";if(s===-1?o=n:(o=n.substring(0,s),c=n.substring(s+1)),o){let l=o.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(o!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${o}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let p=parseFloat(u[1]);i+=p*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let p=parseFloat(f[1]);i+=p*60*1e3,l=l.substring(f[0].length)}let d=l.match(/^(\d+(?:\.\d+)?)S$/);if(d){let p=parseFloat(d[1]);i+=p*1e3,l=l.substring(d[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,n=Math.abs(e),i=Math.floor(n/(1440*60*1e3));n=n%(1440*60*1e3);let s=Math.floor(n/(3600*1e3));n=n%(3600*1e3);let o=Math.floor(n/(60*1e3));n=n%(60*1e3);let c=n/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||o>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),o>0&&(l+=`${o}M`),(c>0||s===0&&o===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return r.parseDayTimeDuration(e),new wee.Literal(e,new See.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,n=e.match(t);if(!n){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(n[1],10),s=parseInt(n[2],10)-1,o=parseInt(n[3],10),c=n[4],l=new Date(Date.UTC(i,s,o));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,d=parseInt(u[2],10),p=parseInt(u[3],10),h=f*(d*60+p)*60*1e3;l=new Date(l.getTime()-h)}}return l}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,n=e.match(t);if(!n)return null;let i=parseInt(n[1],10),s=parseInt(n[2],10),o=parseInt(n[3],10),c=n[4],l=n[5];if(i<0||i>24||s<0||s>59||o<0||o>59||i===24&&(s!==0||o!==0))return null;let u=0;if(c){let d=c.padEnd(3,"0").slice(0,3);u=parseInt(d,10)}let f=i*60*60*1e3+s*60*1e3+o*1e3+u;if(i===24&&(f=1440*60*1e3),l&&l!=="Z"){let d=l.match(/([+-])(\d{2}):(\d{2})/);if(d){let p=d[1]==="+"?1:-1,h=parseInt(d[2],10),m=parseInt(d[3],10),g=p*(h*60+m)*60*1e3;f-=g}}return f}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,n=Math.abs(e);return t?`-P${n}D`:`P${n}D`}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,n=e.match(t);if(!n)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=n[1]==="-",s=parseInt(n[2]||"0",10),o=parseInt(n[3]||"0",10);if(!n[2]&&!n[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+o;return i?-c:c}static formatYearMonthDuration(e){let t=e<0,n=Math.abs(e),i=Math.floor(n/12),s=n%12,o=t?"-P":"P";return i>0&&(o+=`${i}Y`),(s>0||i===0)&&(o+=`${s}M`),o}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,n=e.match(t);if(!n)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=n[1]==="-",s=parseInt(n[2]||"0",10),o=parseInt(n[3]||"0",10);if(!n[2]&&!n[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:o,negative:i}}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,n=e.trim();if(n.startsWith("-")&&(t=!0,n=n.substring(1)),!n.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);n=n.substring(1);let i=0,s=0,o=0,c=0,l=n.indexOf("T"),u="",f="";if(l===-1?u=n:(u=n.substring(0,l),f=n.substring(l+1)),u){let d=u.match(/^(\d+(?:\.\d+)?)D$/);if(d)i=parseFloat(d[1]);else if(u!=="")throw new Error(`parseDurationComponents: invalid day component: '${u}' in '${e}'`)}if(f){let d=f,p=d.match(/^(\d+(?:\.\d+)?)H/);p&&(s=parseFloat(p[1]),d=d.substring(p[0].length));let h=d.match(/^(\d+(?:\.\d+)?)M/);h&&(o=parseFloat(h[1]),d=d.substring(h[0].length));let m=d.match(/^(\d+(?:\.\d+)?)S$/);if(m&&(c=parseFloat(m[1]),d=d.substring(m[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:o,seconds:c}}};Tb.DateTimeParsing=rI});var mM=T(Ab=>{"use strict";Object.defineProperty(Ab,"__esModule",{value:!0});Ab.DateTimeArithmetic=void 0;var ai=Ne(),Xe=Ye(),_t=Bh(),nI=class{static{a(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n),o=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${n}'`);if(isNaN(o.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-o.getTime(),l=_t.DateTimeParsing.formatDayTimeDuration(c);return new Xe.Literal(l,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c);return new Xe.Literal(l.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c);return new Xe.Literal(l.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateAdd: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),d=String(l.getUTCDate()).padStart(2,"0"),p=`${u}-${f}-${d}`;return new Xe.Literal(p,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateSubtract: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c),u=l.getUTCFullYear(),f=String(l.getUTCMonth()+1).padStart(2,"0"),d=String(l.getUTCDate()).padStart(2,"0"),p=`${u}-${f}-${d}`;return new Xe.Literal(p,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+o),s.getUTCDate()!==c&&s.setUTCDate(0),new Xe.Literal(s.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=new Date(n);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-o),s.getUTCDate()!==c&&s.setUTCDate(0),new Xe.Literal(s.toISOString(),new ai.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+o),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"),d=`${l}-${u}-${f}`;return new Xe.Literal(d,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseXSDDate(n);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${n}'`);let o=_t.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-o),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"),d=`${l}-${u}-${f}`;return new Xe.Literal(d,new ai.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseDayTimeDuration(n),o=_t.DateTimeParsing.parseDayTimeDuration(i),c=_t.DateTimeParsing.formatDayTimeDuration(s+o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseDayTimeDuration(n),o=_t.DateTimeParsing.parseDayTimeDuration(i),c=_t.DateTimeParsing.formatDayTimeDuration(s-o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let n=e instanceof Xe.Literal?e.value:e,i=_t.DateTimeParsing.parseDayTimeDuration(n),s=_t.DateTimeParsing.formatDayTimeDuration(i*t);return new Xe.Literal(s,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let n=e instanceof Xe.Literal?e.value:e,i=_t.DateTimeParsing.parseDayTimeDuration(n),s=_t.DateTimeParsing.formatDayTimeDuration(i/t);return new Xe.Literal(s,new ai.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseYearMonthDuration(n),o=_t.DateTimeParsing.parseYearMonthDuration(i),c=_t.DateTimeParsing.formatYearMonthDuration(s+o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let n=e instanceof Xe.Literal?e.value:e,i=t instanceof Xe.Literal?t.value:t,s=_t.DateTimeParsing.parseYearMonthDuration(n),o=_t.DateTimeParsing.parseYearMonthDuration(i),c=_t.DateTimeParsing.formatYearMonthDuration(s-o);return new Xe.Literal(c,new ai.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof Xe.Literal?e.value:e;return _t.DateTimeParsing.parseDayTimeDuration(t)/1e3}};Ab.DateTimeArithmetic=nI});var gM=T(Ib=>{"use strict";Object.defineProperty(Ib,"__esModule",{value:!0});Ib.DateTimeAccessors=void 0;var Uh=Ne(),pr=Ye(),Xt=Bh(),iI=class r{static{a(this,"DateTimeAccessors")}static lexicalComponents(e){let t=e.match(/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(?:Z|[+-]\d{2}:?\d{2})?$/);if(!t)return null;let n=parseInt(t[1],10),i=parseInt(t[2],10),s=parseInt(t[3],10),o=t[4]!==void 0?parseInt(t[4],10):0,c=t[5]!==void 0?parseInt(t[5],10):0,l=t[6]!==void 0?parseInt(t[6],10):0,u=t[7]?l+parseFloat(`0.${t[7]}`):l;return i<1||i>12||s<1||s>31||o>24||c>59||l>60?null:{year:n,month:i,day:s,hours:o,minutes:c,seconds:u}}static year(e){let t=r.lexicalComponents(e);if(t)return t.year;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return n.getFullYear()}static month(e){let t=r.lexicalComponents(e);if(t)return t.month;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return n.getMonth()+1}static day(e){let t=r.lexicalComponents(e);if(t)return t.day;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return n.getDate()}static hours(e){let t=r.lexicalComponents(e);if(t)return t.hours;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return n.getHours()}static minutes(e){let t=r.lexicalComponents(e);if(t)return t.minutes;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return n.getMinutes()}static seconds(e){let t=r.lexicalComponents(e);if(t)return t.seconds;let n=new Date(e);if(isNaN(n.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return n.getSeconds()+n.getMilliseconds()/1e3}static durationDays(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.days);return n.negative?-i:i}static durationHours(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.hours);return n.negative?-i:i}static durationMinutes(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(n.minutes);return n.negative?-i:i}static durationSeconds(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseDurationComponents(t);return n.negative?-n.seconds:n.seconds}static durationYears(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseYearMonthDurationComponents(t);return n.negative?-n.years:n.years}static durationMonths(e){let t=e instanceof pr.Literal?e.value:e,n=Xt.DateTimeParsing.parseYearMonthDurationComponents(t);return n.negative?-n.months:n.months}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let n;if(e.endsWith("Z"))n="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),o=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);o===0?n=`${c}PT${l}H`:n=`${c}PT${l}H${o}M`}else{let s=-t.getTimezoneOffset(),o=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?n=`${l}PT${o}H`:n=`${l}PT${o}H${c}M`}}return new pr.Literal(n,new Uh.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 n=e.match(/([+-]\d{2}:\d{2})$/);if(n)return n[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static adjust(e,t){let n=e instanceof pr.Literal?e.value:e,i=new Date(n);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${n}'`);if(t==null){let R=i.getUTCFullYear(),C=String(i.getUTCMonth()+1).padStart(2,"0"),O=String(i.getUTCDate()).padStart(2,"0"),N=String(i.getUTCHours()).padStart(2,"0"),F=String(i.getUTCMinutes()).padStart(2,"0"),M=String(i.getUTCSeconds()).padStart(2,"0"),H=i.getUTCMilliseconds(),ne=`${R}-${C}-${O}T${N}:${F}:${M}`;return H>0&&(ne+=`.${String(H).padStart(3,"0")}`),new pr.Literal(ne,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof pr.Literal?t.value:t,o=Xt.DateTimeParsing.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(o)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+o),f=u.getUTCFullYear(),d=String(u.getUTCMonth()+1).padStart(2,"0"),p=String(u.getUTCDate()).padStart(2,"0"),h=String(u.getUTCHours()).padStart(2,"0"),m=String(u.getUTCMinutes()).padStart(2,"0"),g=String(u.getUTCSeconds()).padStart(2,"0"),b=u.getUTCMilliseconds(),_=o>=0?"+":"-",w=Math.floor(Math.abs(o)/(3600*1e3)),v=Math.floor(Math.abs(o)%(3600*1e3)/(60*1e3)),E=`${_}${String(w).padStart(2,"0")}:${String(v).padStart(2,"0")}`,S=`${f}-${d}-${p}T${h}:${m}:${g}`;return b>0&&(S+=`.${String(b).padStart(3,"0")}`),S+=E,new pr.Literal(S,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t);return n<i}static dateAfter(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t);return n>i}static dateInRange(e,t,n){let i=Xt.DateTimeParsing.parseDate(e),s=Xt.DateTimeParsing.parseDate(t),o=Xt.DateTimeParsing.parseDate(n);return i>=s&&i<=o}static compareDurations(e,t,n){let i=e instanceof pr.Literal?e.value:e,s=t instanceof pr.Literal?t.value:t,o=Xt.DateTimeParsing.parseDayTimeDuration(i),c=Xt.DateTimeParsing.parseDayTimeDuration(s);switch(n){case"=":return o===c;case"!=":return o!==c;case"<":return o<c;case">":return o>c;case"<=":return o<=c;case">=":return o>=c;default:throw new Error(`compareDurations: unknown operator: ${n}`)}}static dateDiffMinutes(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t),s=Math.abs(i-n);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let n=Xt.DateTimeParsing.parseDate(e),i=Xt.DateTimeParsing.parseDate(t),s=Math.abs(i-n);return Math.round(s/(1e3*60*60)*100)/100}static timeDiff(e,t){let n=e instanceof pr.Literal?e.value:e,i=t instanceof pr.Literal?t.value:t,s=Xt.DateTimeParsing.parseXSDTime(n),o=Xt.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${n}'`);if(o===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-o,l=Xt.DateTimeParsing.formatDayTimeDuration(c);return new pr.Literal(l,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof pr.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let n=e instanceof pr.Literal?e.value:e,i=t instanceof pr.Literal?t.value:t,s=Xt.DateTimeParsing.parseXSDDate(n),o=Xt.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${n}'`);if(o===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-o.getTime(),l=Math.round(c/(1440*60*1e3)),u=Xt.DateTimeParsing.formatDateDuration(l);return new pr.Literal(u,new Uh.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};Ib.DateTimeAccessors=iI});var Cb=T(Rb=>{"use strict";Object.defineProperty(Rb,"__esModule",{value:!0});Rb.DateTimeFunctions=void 0;var qf=Bh(),Kr=mM(),qt=gM(),sI=class{static{a(this,"DateTimeFunctions")}static parseDate(e){return qf.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return qf.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return qf.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return qf.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return qf.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return qf.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return qt.DateTimeAccessors.year(e)}static month(e){return qt.DateTimeAccessors.month(e)}static day(e){return qt.DateTimeAccessors.day(e)}static hours(e){return qt.DateTimeAccessors.hours(e)}static minutes(e){return qt.DateTimeAccessors.minutes(e)}static seconds(e){return qt.DateTimeAccessors.seconds(e)}static durationDays(e){return qt.DateTimeAccessors.durationDays(e)}static durationHours(e){return qt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return qt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return qt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return qt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return qt.DateTimeAccessors.durationMonths(e)}static timezone(e){return qt.DateTimeAccessors.timezone(e)}static tz(e){return qt.DateTimeAccessors.tz(e)}static adjust(e,t){return qt.DateTimeAccessors.adjust(e,t)}static now(){return qt.DateTimeAccessors.now()}static dateBefore(e,t){return qt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return qt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,n){return qt.DateTimeAccessors.dateInRange(e,t,n)}static compareDurations(e,t,n){return qt.DateTimeAccessors.compareDurations(e,t,n)}static dateDiffMinutes(e,t){return qt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return qt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return qt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return qt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return qt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return qt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return qt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return qt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return Kr.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return Kr.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return Kr.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return Kr.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return Kr.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return Kr.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return Kr.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return Kr.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return Kr.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return Kr.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return Kr.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return Kr.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return Kr.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return Kr.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return Kr.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return Kr.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return Kr.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return Kr.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return Kr.DateTimeArithmetic.durationToSeconds(e)}};Rb.DateTimeFunctions=sI});var yM=T(xb=>{"use strict";Object.defineProperty(xb,"__esModule",{value:!0});xb.LogicalFunctions=void 0;var Eee=Ne(),Wf=Ye(),vee=dr(),Ob=Cb(),oI=class r{static{a(this,"LogicalFunctions")}static compare(e,t,n){if(r.isDayTimeDurationValue(e)&&r.isDayTimeDurationValue(t))return Ob.DateTimeFunctions.compareDurations(e instanceof Wf.Literal?e:String(e),t instanceof Wf.Literal?t:String(t),n);if(r.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return Ob.DateTimeFunctions.compareDurations(e instanceof Wf.Literal?e:String(e),t,n);if(typeof e=="string"&&/^-?P/.test(e)&&r.isDayTimeDurationValue(t))return Ob.DateTimeFunctions.compareDurations(e,t instanceof Wf.Literal?t:String(t),n);let i=r.toComparableValue(e),s=r.toComparableValue(t);switch(n){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: ${n}`)}}static isDayTimeDurationValue(e){return e instanceof Wf.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 Wf.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let n=parseFloat(e.value);if(!isNaN(n))return n}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return Ob.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof Eee.IRI?e.value:e instanceof vee.BlankNode?e.id:String(e)}static logicalAnd(e){return e.every(t=>t===!0)}static logicalOr(e){return e.some(t=>t===!0)}static logicalNot(e){return!e}static coalesce(e){for(let t of e)if(t!=null)return t}static if(e,t,n){return e?t:n}};xb.LogicalFunctions=oI});var bM=T(Pb=>{"use strict";Object.defineProperty(Pb,"__esModule",{value:!0});Pb.RDFTermFunctions=void 0;var Tn=Ne(),Yt=Ye(),Ls=dr(),zf=fh(),aI=mf(),cI=class r{static{a(this,"RDFTermFunctions")}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof Yt.Literal)return e.datatype?e.datatype:e.language?new Tn.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Tn.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 Tn.IRI}static isBlank(e){return e===void 0?!1:e instanceof Ls.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof Yt.Literal}static isTriple(e){return e===void 0?!1:e instanceof zf.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof Yt.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof Yt.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 xsdDateTime(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`xsd:dateTime: invalid date string '${e}'`);return new Yt.Literal(t.toISOString(),new Tn.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 Yt.Literal(String(t),new Tn.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 Yt.Literal(String(t),new Tn.IRI("http://www.w3.org/2001/XMLSchema#decimal"))}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 Tn.IRI&&t instanceof Tn.IRI)return e.value===t.value;if(e instanceof Ls.BlankNode&&t instanceof Ls.BlankNode)return e.id===t.id;if(e instanceof Yt.Literal&&t instanceof Yt.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let n=e.datatype?.value,i=t.datatype?.value;return n===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof Tn.IRI)return e;if(e instanceof Yt.Literal)return new Tn.IRI(e.value);throw e instanceof Ls.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return r.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,aI.v4)().replace(/-/g,"").substring(0,12)}`;return new Ls.BlankNode(t)}if(e instanceof Yt.Literal)return new Ls.BlankNode(e.value);if(e instanceof Ls.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 n;if(e instanceof Yt.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");n=e.value}else if(typeof e=="string")n=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof Tn.IRI)i=t;else if(t instanceof Yt.Literal)i=new Tn.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new Yt.Literal(n,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 n;if(e instanceof Yt.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");n=e.value}else if(typeof e=="string")n=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof Yt.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 Yt.Literal(n,void 0,i)}static strlangdir(e,t,n){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(n===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof Yt.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 Yt.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 o;if(n instanceof Yt.Literal)o=n.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(o!=="ltr"&&o!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${o}'. Must be 'ltr' or 'rtl'`);return new Yt.Literal(i,void 0,s,o)}static uuid(){let e=(0,aI.v4)();return new Tn.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,aI.v4)();return new Yt.Literal(e)}static triple(e,t,n){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(n===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof Yt.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof Tn.IRI)){let c=t instanceof Yt.Literal?"Literal":t instanceof Ls.BlankNode?"BlankNode":t instanceof zf.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,o=n;return new zf.QuotedTriple(i,s,o)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.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 zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.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 zf.QuotedTriple)){let t=e instanceof Tn.IRI?"IRI":e instanceof Yt.Literal?"Literal":e instanceof Ls.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};Pb.RDFTermFunctions=cI});var _M=T(Fb=>{"use strict";Object.defineProperty(Fb,"__esModule",{value:!0});Fb.HashFunctions=void 0;var lI=class{static{a(this,"HashFunctions")}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")}};Fb.HashFunctions=lI});var Db=T(Lb=>{"use strict";Object.defineProperty(Lb,"__esModule",{value:!0});Lb.BuiltInFunctions=void 0;var Hr=pM(),Fc=hM(),qe=Cb(),Kf=yM(),ir=bM(),Vh=_M(),uI=class{static{a(this,"BuiltInFunctions")}static str(...e){return Hr.StringFunctions.str(...e)}static lang(...e){return Hr.StringFunctions.lang(...e)}static langdir(...e){return Hr.StringFunctions.langdir(...e)}static langMatches(...e){return Hr.StringFunctions.langMatches(...e)}static regex(...e){return Hr.StringFunctions.regex(...e)}static contains(...e){return Hr.StringFunctions.contains(...e)}static strStarts(...e){return Hr.StringFunctions.strStarts(...e)}static strEnds(...e){return Hr.StringFunctions.strEnds(...e)}static strlen(...e){return Hr.StringFunctions.strlen(...e)}static ucase(...e){return Hr.StringFunctions.ucase(...e)}static lcase(...e){return Hr.StringFunctions.lcase(...e)}static substr(...e){return Hr.StringFunctions.substr(...e)}static strBefore(...e){return Hr.StringFunctions.strBefore(...e)}static strAfter(...e){return Hr.StringFunctions.strAfter(...e)}static concat(...e){return Hr.StringFunctions.concat(...e)}static replace(...e){return Hr.StringFunctions.replace(...e)}static encodeForUri(...e){return Hr.StringFunctions.encodeForUri(...e)}static normalize(...e){return Hr.StringFunctions.normalize(...e)}static fold(...e){return Hr.StringFunctions.fold(...e)}static abs(...e){return Fc.MathFunctions.abs(...e)}static round(...e){return Fc.MathFunctions.round(...e)}static ceil(...e){return Fc.MathFunctions.ceil(...e)}static floor(...e){return Fc.MathFunctions.floor(...e)}static rand(){return Fc.MathFunctions.rand()}static msToMinutes(...e){return Fc.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Fc.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Fc.MathFunctions.msToSeconds(...e)}static parseDate(...e){return qe.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return qe.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return qe.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return qe.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return qe.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return qe.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return qe.DateTimeFunctions.year(...e)}static month(...e){return qe.DateTimeFunctions.month(...e)}static day(...e){return qe.DateTimeFunctions.day(...e)}static hours(...e){return qe.DateTimeFunctions.hours(...e)}static minutes(...e){return qe.DateTimeFunctions.minutes(...e)}static seconds(...e){return qe.DateTimeFunctions.seconds(...e)}static timezone(...e){return qe.DateTimeFunctions.timezone(...e)}static tz(...e){return qe.DateTimeFunctions.tz(...e)}static now(){return qe.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return qe.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return qe.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return qe.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return qe.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return qe.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return qe.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return qe.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return qe.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return qe.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return qe.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return qe.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return qe.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return qe.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return qe.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return qe.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return qe.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return qe.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return qe.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return qe.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return qe.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return qe.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return qe.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return qe.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return qe.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return qe.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return qe.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return qe.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return qe.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return qe.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return qe.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return qe.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return qe.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return qe.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return qe.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return qe.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return qe.DateTimeFunctions.adjust(...e)}static isTime(...e){return qe.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return qe.DateTimeFunctions.timeDiff(...e)}static compare(...e){return Kf.LogicalFunctions.compare(...e)}static logicalAnd(...e){return Kf.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return Kf.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return Kf.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return Kf.LogicalFunctions.coalesce(...e)}static if(...e){return Kf.LogicalFunctions.if(...e)}static datatype(...e){return ir.RDFTermFunctions.datatype(...e)}static bound(...e){return ir.RDFTermFunctions.bound(...e)}static isIRI(...e){return ir.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return ir.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return ir.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return ir.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return ir.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return ir.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return ir.RDFTermFunctions.sameTerm(...e)}static iri(...e){return ir.RDFTermFunctions.iri(...e)}static uri(...e){return ir.RDFTermFunctions.uri(...e)}static bnode(...e){return ir.RDFTermFunctions.bnode(...e)}static strdt(...e){return ir.RDFTermFunctions.strdt(...e)}static strlang(...e){return ir.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return ir.RDFTermFunctions.strlangdir(...e)}static uuid(){return ir.RDFTermFunctions.uuid()}static struuid(){return ir.RDFTermFunctions.struuid()}static xsdDateTime(...e){return ir.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return ir.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return ir.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return ir.RDFTermFunctions.triple(...e)}static subject(...e){return ir.RDFTermFunctions.subject(...e)}static predicate(...e){return ir.RDFTermFunctions.predicate(...e)}static object(...e){return ir.RDFTermFunctions.object(...e)}static md5(...e){return Vh.HashFunctions.md5(...e)}static sha1(...e){return Vh.HashFunctions.sha1(...e)}static sha256(...e){return Vh.HashFunctions.sha256(...e)}static sha384(...e){return Vh.HashFunctions.sha384(...e)}static sha512(...e){return Vh.HashFunctions.sha512(...e)}};Lb.BuiltInFunctions=uI});var Gh=T(Po=>{"use strict";Object.defineProperty(Po,"__esModule",{value:!0});Po.ExoQLBudgetExceededError=Po.ExoQLCycleError=Po.ExoQLEvalDisabledError=Po.ExoQLForbiddenKeywordError=void 0;var fI=class extends Error{static{a(this,"ExoQLForbiddenKeywordError")}constructor(e,t){super(t??`ExoQLForbiddenKeywordError: keyword "${e}" is not permitted by the exoql__Query AST allowlist`),this.name="ExoQLForbiddenKeywordError",this.keyword=e}};Po.ExoQLForbiddenKeywordError=fI;var dI=class extends Error{static{a(this,"ExoQLEvalDisabledError")}constructor(e){super(e??"ExoQLEvalDisabledError: exoql.eval.enabled is false (default). Flip the feature flag to opt in."),this.name="ExoQLEvalDisabledError"}};Po.ExoQLEvalDisabledError=dI;var pI=class extends Error{static{a(this,"ExoQLCycleError")}constructor(e,t){super(t??`ExoQLCycleError: cycle detected in nested exo:eval invocations: ${e.join(" \u2192 ")}`),this.name="ExoQLCycleError",this.path=e}};Po.ExoQLCycleError=pI;var hI=class extends Error{static{a(this,"ExoQLBudgetExceededError")}constructor(e,t,n,i){super(i??`ExoQLBudgetExceededError: ${e} budget exceeded (limit=${t}, observed=${n})`),this.name="ExoQLBudgetExceededError",this.budget=e,this.limit=t,this.observed=n}};Po.ExoQLBudgetExceededError=hI});var CM=T(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.functionHandlers=void 0;var ae=Db();ce.functionHandlers=new Map;ce.functionHandlers.set("str",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.str(t)});ce.functionHandlers.set("lang",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.lang(t)});ce.functionHandlers.set("langmatches",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.langMatches(t,n)});ce.functionHandlers.set("contains",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.contains(t,n)});ce.functionHandlers.set("strstarts",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strStarts(t,n)});ce.functionHandlers.set("strends",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strEnds(t,n)});ce.functionHandlers.set("strlen",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.strlen(t)});ce.functionHandlers.set("ucase",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.ucase(t)});ce.functionHandlers.set("lcase",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.lcase(t)});ce.functionHandlers.set("substr",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=Number(e.evaluateExpression(r[1],e.solution));if(r[2]){let i=Number(e.evaluateExpression(r[2],e.solution));return ae.BuiltInFunctions.substr(t,n,i)}return ae.BuiltInFunctions.substr(t,n)});ce.functionHandlers.set("strbefore",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strBefore(t,n)});ce.functionHandlers.set("strafter",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.strAfter(t,n)});ce.functionHandlers.set("concat",(r,e)=>{let t=r.map(n=>e.getStringValue(e.evaluateExpression(n,e.solution)));return ae.BuiltInFunctions.concat(...t)});ce.functionHandlers.set("replace",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=e.getStringValue(e.evaluateExpression(r[2],e.solution)),s=r[3]?e.getStringValue(e.evaluateExpression(r[3],e.solution)):void 0;return ae.BuiltInFunctions.replace(t,n,i,s)});ce.functionHandlers.set("regex",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=r[2]?e.getStringValue(e.evaluateExpression(r[2],e.solution)):void 0;return ae.BuiltInFunctions.regex(t,n,i)});ce.functionHandlers.set("encode_for_uri",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.encodeForUri(t)});ce.functionHandlers.set("datatype",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.datatype(t).value});ce.functionHandlers.set("bound",(r,e)=>{let t=r[0];if(t.type==="variable"&&t.name){let n=e.solution.get(t.name);return ae.BuiltInFunctions.bound(n)}return!0});var SM=a((r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isIRI(t)},"isIriHandler");ce.functionHandlers.set("isiri",SM);ce.functionHandlers.set("isuri",SM);ce.functionHandlers.set("isblank",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isBlank(t)});ce.functionHandlers.set("isliteral",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isLiteral(t)});ce.functionHandlers.set("isnumeric",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isNumeric(t)});ce.functionHandlers.set("haslangdir",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.hasLangdir(t)});ce.functionHandlers.set("istriple",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.isTriple(t)});ce.functionHandlers.set("sameterm",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution),n=e.getTermFromExpression(r[1],e.solution);return ae.BuiltInFunctions.sameTerm(t,n)});ce.functionHandlers.set("abs",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.abs(t)});ce.functionHandlers.set("round",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.round(t)});ce.functionHandlers.set("ceil",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.ceil(t)});ce.functionHandlers.set("floor",(r,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(r[0],e.solution)));return ae.BuiltInFunctions.floor(t)});ce.functionHandlers.set("rand",()=>ae.BuiltInFunctions.rand());ce.functionHandlers.set("parsedate",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.parseDate(t)});ce.functionHandlers.set("datebefore",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateBefore(t,n)});ce.functionHandlers.set("dateafter",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateAfter(t,n)});ce.functionHandlers.set("dateinrange",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=e.getStringValue(e.evaluateExpression(r[2],e.solution));return ae.BuiltInFunctions.dateInRange(t,n,i)});ce.functionHandlers.set("datediffminutes",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateDiffMinutes(t,n)});ce.functionHandlers.set("datediffhours",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution));return ae.BuiltInFunctions.dateDiffHours(t,n)});var Hf=a((r,e,t)=>(n,i)=>{let s=i.evaluateExpression(n[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):r(i.getStringValue(s))},"createDateTimeAccessor"),wM=Hf(ae.BuiltInFunctions.year.bind(ae.BuiltInFunctions),ae.BuiltInFunctions.durationYears.bind(ae.BuiltInFunctions),null);ce.functionHandlers.set("year",wM);ce.functionHandlers.set("years",wM);var EM=Hf(ae.BuiltInFunctions.month.bind(ae.BuiltInFunctions),ae.BuiltInFunctions.durationMonths.bind(ae.BuiltInFunctions),null);ce.functionHandlers.set("month",EM);ce.functionHandlers.set("months",EM);var vM=Hf(ae.BuiltInFunctions.day.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationDays.bind(ae.BuiltInFunctions));ce.functionHandlers.set("day",vM);ce.functionHandlers.set("days",vM);ce.functionHandlers.set("hours",Hf(ae.BuiltInFunctions.hours.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationHours.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("minutes",Hf(ae.BuiltInFunctions.minutes.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationMinutes.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("seconds",Hf(ae.BuiltInFunctions.seconds.bind(ae.BuiltInFunctions),null,ae.BuiltInFunctions.durationSeconds.bind(ae.BuiltInFunctions)));ce.functionHandlers.set("timezone",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.timezone(t)});ce.functionHandlers.set("tz",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.tz(t)});ce.functionHandlers.set("adjust",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=r.length>1?e.evaluateExpression(r[1],e.solution):void 0;return ae.BuiltInFunctions.adjust(t,n)});ce.functionHandlers.set("now",()=>ae.BuiltInFunctions.now());var TM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");ce.functionHandlers.set("datetime",TM);ce.functionHandlers.set("xsd:datetime",TM);var AM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");ce.functionHandlers.set("integer",AM);ce.functionHandlers.set("xsd:integer",AM);var IM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");ce.functionHandlers.set("decimal",IM);ce.functionHandlers.set("xsd:decimal",IM);var RM=a((r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");ce.functionHandlers.set("daytimeduration",RM);ce.functionHandlers.set("xsd:daytimeduration",RM);ce.functionHandlers.set("durationtodays",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToDays(t)});ce.functionHandlers.set("durationtohours",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToHours(t)});ce.functionHandlers.set("durationtominutes",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToMinutes(t)});ce.functionHandlers.set("durationtoseconds",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationToSeconds(t)});ce.functionHandlers.set("durationdays",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationDays(t)});ce.functionHandlers.set("durationhours",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationHours(t)});ce.functionHandlers.set("durationminutes",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationMinutes(t)});ce.functionHandlers.set("durationseconds",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationSeconds(t)});ce.functionHandlers.set("durationyears",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationYears(t)});ce.functionHandlers.set("durationmonths",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution);return ae.BuiltInFunctions.durationMonths(t)});ce.functionHandlers.set("datetimediff",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeDiff(t,n)});ce.functionHandlers.set("datetimeadd",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeAdd(t,n)});ce.functionHandlers.set("datetimesubtract",(r,e)=>{let t=e.evaluateExpression(r[0],e.solution),n=e.evaluateExpression(r[1],e.solution);return ae.BuiltInFunctions.dateTimeSubtract(t,n)});ce.functionHandlers.set("mstominutes",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToMinutes(t)});ce.functionHandlers.set("mstohours",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToHours(t)});ce.functionHandlers.set("mstoseconds",(r,e)=>{let t=Number(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.msToSeconds(t)});ce.functionHandlers.set("md5",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.md5(t)});ce.functionHandlers.set("sha1",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha1(t)});ce.functionHandlers.set("sha256",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha256(t)});ce.functionHandlers.set("sha384",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha384(t)});ce.functionHandlers.set("sha512",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution));return ae.BuiltInFunctions.sha512(t)});ce.functionHandlers.set("subject",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.subject(t)});ce.functionHandlers.set("predicate",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.predicate(t)});ce.functionHandlers.set("object",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution);return ae.BuiltInFunctions.object(t)});ce.functionHandlers.set("triple",(r,e)=>{let t=e.getTermFromExpression(r[0],e.solution),n=e.getTermFromExpression(r[1],e.solution),i=e.getTermFromExpression(r[2],e.solution);return ae.BuiltInFunctions.triple(t,n,i)});ce.functionHandlers.set("days_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t),s=new Date(n);return Math.floor((s.getTime()-i.getTime())/(1440*60*1e3))});ce.functionHandlers.set("minutes_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t),s=new Date(n);return Math.floor((s.getTime()-i.getTime())/(60*1e3))});ce.functionHandlers.set("hours_between",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t);return(new Date(n).getTime()-i.getTime())/(3600*1e3)});ce.functionHandlers.set("age_days",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=new Date(t);return Math.floor((new Date().getTime()-n.getTime())/(1440*60*1e3))});ce.functionHandlers.set("week_number",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=new Date(t),i=new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()));i.setUTCDate(i.getUTCDate()+4-(i.getUTCDay()||7));let s=new Date(Date.UTC(i.getUTCFullYear(),0,1));return Math.ceil(((i.getTime()-s.getTime())/(1440*60*1e3)+1)/7)});ce.functionHandlers.set("format_date",(r,e)=>{let t=e.getStringValue(e.evaluateExpression(r[0],e.solution)),n=e.getStringValue(e.evaluateExpression(r[1],e.solution)),i=new Date(t);return n.replace("YYYY",String(i.getFullYear())).replace("MM",String(i.getMonth()+1).padStart(2,"0")).replace("DD",String(i.getDate()).padStart(2,"0")).replace("HH",String(i.getHours()).padStart(2,"0")).replace("mm",String(i.getMinutes()).padStart(2,"0")).replace("ss",String(i.getSeconds()).padStart(2,"0"))});ce.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:r}=Gh();throw new r})});var Nb=T(Yf=>{"use strict";Object.defineProperty(Yf,"__esModule",{value:!0});Yf.FilterExecutor=Yf.FilterExecutorError=void 0;var Wt=Db(),Tee=CM(),mI=Ne(),Fo=Ye(),wr=class extends Error{static{a(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Yf.FilterExecutorError=wr;var gI=class{static{a(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 n=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;n?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||typeof e!="object")return!1;if(e.type==="exists")return!0;if(e.type==="logical")return e.operands.some(t=>this.expressionContainsExists(t));if(e.type==="comparison"){let t=e;return this.expressionContainsExists(t.left)||this.expressionContainsExists(t.right)}if(e.type==="arithmetic"){let t=e;return this.expressionContainsExists(t.left)||this.expressionContainsExists(t.right)}if(e.type==="in"){let t=e;return this.expressionContainsExists(t.expression)||t.list.some(n=>this.expressionContainsExists(n))}if(e.type==="function"||e.type==="functionCall"){let t=e;return Array.isArray(t.args)?t.args.some(n=>this.expressionContainsExists(n)):!1}return!1}async executeAll(e,t){let n=[];async function*i(){for(let s of t)yield s}a(i,"generator");for await(let s of this.execute(e,i()))n.push(s);return n}evaluateExpression(e,t){let n=e;if("termType"in e)switch(n.termType){case"Variable":return t.get(n.value);case"Literal":{let i=n.value,s=n.datatype,o=typeof s=="string"?s:s?.value;return o&&i.length>0&&this.shouldPreserveDatatype(o)?new Fo.Literal(i,new mI.IRI(o)):i}case"NamedNode":return n.value;default:throw new wr(`Unsupported termType: ${String(n.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":{let i=e;return i.datatype&&i.value.length>0&&this.shouldPreserveDatatype(i.datatype)?new Fo.Literal(i.value,new mI.IRI(i.datatype)):i.value}case"in":return this.evaluateIn(e,t);case"exists":throw new wr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new wr(`Unsupported expression type: ${e.type}`)}}async evaluateExpressionAsync(e,t){if(!this.expressionContainsExists(e))return this.evaluateExpression(e,t);if(e.type==="exists")return this.evaluateExists(e,t);if(e.type==="logical")return this.evaluateLogicalAsync(e,t);if(e.type==="comparison"){let n=e,i=await this.evaluateExpressionAsync(n.left,t),s=await this.evaluateExpressionAsync(n.right,t);return Wt.BuiltInFunctions.compare(i,s,n.operator)}return e.type==="in"?this.evaluateInAsync(e,t):e.type==="function"||e.type==="functionCall"?this.evaluateFunctionAsync(e,t):this.evaluateExpression(e,t)}async evaluateExists(e,t){if(!this.existsEvaluator)throw new wr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let n=await this.existsEvaluator(e.pattern,t);return e.negated?!n:n}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let s=await this.evaluateExpressionAsync(e.operands[0],t);return Wt.BuiltInFunctions.logicalNot(s)}let n=[],i=!1;for(let s of e.operands)try{n.push(await this.evaluateExpressionAsync(s,t))}catch{i=!0}if(e.operator==="&&"){if(n.some(s=>s===!1))return!1;if(i)throw new wr("&& operand raised and no false absorbed it");return Wt.BuiltInFunctions.logicalAnd(n)}if(e.operator==="||"){if(n.some(s=>s===!0))return!0;if(i)throw new wr("|| operand raised and no true absorbed it");return Wt.BuiltInFunctions.logicalOr(n)}throw new wr(`Unknown logical operator: ${String(e.operator)}`)}async evaluateInAsync(e,t){let n=await this.evaluateExpressionAsync(e.expression,t),i=!1;for(let s of e.list){let o=await this.evaluateExpressionAsync(s,t);if(Wt.BuiltInFunctions.compare(n,o,"=")){i=!0;break}}return e.negated?!i:i}async evaluateFunctionAsync(e,t){let n=e,i=this.extractFunctionName(n.function),s=n.args??[];if(i==="if"){if(s.length!==3)throw new wr("IF requires exactly 3 arguments");let l=await this.evaluateExpressionAsync(s[0],t);return this.toBoolean(l)?this.evaluateExpressionAsync(s[1],t):this.evaluateExpressionAsync(s[2],t)}if(i==="coalesce"){for(let l of s)try{let u=await this.evaluateExpressionAsync(l,t);if(u!=null)return u}catch{continue}return}let o=[];for(let l of s){let u=await this.evaluateExpressionAsync(l,t);o.push(this.wrapAsLiteralExpression(u))}let c={...n,args:o};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:typeof e=="object"&&"termType"in e?e:e instanceof mI.IRI||e instanceof Fo.Literal?{type:"literal",value:e.value}:typeof e=="number"||typeof e=="boolean"||typeof e=="string"?{type:"literal",value:e}:{type:"literal",value:String(e)}}evaluateComparison(e,t){let n=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return Wt.BuiltInFunctions.compare(n,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let s=this.evaluateExpression(e.operands[0],t);return Wt.BuiltInFunctions.logicalNot(s)}let n=[],i=!1;for(let s of e.operands)try{n.push(this.evaluateExpression(s,t))}catch{i=!0}if(e.operator==="&&"){if(n.some(s=>s===!1))return!1;if(i)throw new wr("&& operand raised and no false absorbed it");return Wt.BuiltInFunctions.logicalAnd(n)}if(e.operator==="||"){if(n.some(s=>s===!0))return!0;if(i)throw new wr("|| operand raised and no true absorbed it");return Wt.BuiltInFunctions.logicalOr(n)}throw new wr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let n=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let o=this.evaluateExpression(s,t);return Wt.BuiltInFunctions.compare(n,o,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let n=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(n)&&this.isDateValue(i))return Wt.BuiltInFunctions.dateDiff(n,i);if(e.operator==="-"&&this.isTimeValue(n)&&this.isTimeValue(i))return Wt.BuiltInFunctions.timeDiff(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isDateTimeValue(i))return Wt.BuiltInFunctions.dateTimeDiff(n,i);if(e.operator==="+"&&this.isDateValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateAdd(n,i);if(e.operator==="-"&&this.isDateValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateSubtract(n,i);if(e.operator==="+"&&this.isDateValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateAddYearMonth(n,i);if(e.operator==="-"&&this.isDateValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateSubtractYearMonth(n,i);if(e.operator==="+"&&this.isDateTimeValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateTimeAdd(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.dateTimeSubtract(n,i);if(e.operator==="+"&&this.isDateTimeValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateTimeAddYearMonth(n,i);if(e.operator==="-"&&this.isDateTimeValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.dateTimeSubtractYearMonth(n,i);if(e.operator==="+"&&this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.durationAdd(n,i);if(e.operator==="-"&&this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i))return Wt.BuiltInFunctions.durationSubtract(n,i);if(e.operator==="*"&&this.isDayTimeDurationValue(n)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return Wt.BuiltInFunctions.durationMultiply(n,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(n)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(n);return Wt.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(n)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new wr("Division by zero");return Wt.BuiltInFunctions.durationDivide(n,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.yearMonthDurationAdd(n,i);if(e.operator==="-"&&this.isYearMonthDurationValue(n)&&this.isYearMonthDurationValue(i))return Wt.BuiltInFunctions.yearMonthDurationSubtract(n,i);let s=this.toNumericValue(n),o=this.toNumericValue(i);switch(e.operator){case"+":return s+o;case"-":return s-o;case"*":return s*o;case"/":if(o===0)throw new wr("Division by zero");return s/o;default:throw new wr(`Unknown arithmetic operator: ${String(e.operator)}`)}}shouldPreserveDatatype(e){return e==="http://www.w3.org/2001/XMLSchema#dateTime"||e==="http://www.w3.org/2001/XMLSchema#date"||e==="http://www.w3.org/2001/XMLSchema#time"||e==="http://www.w3.org/2001/XMLSchema#dayTimeDuration"||e==="http://www.w3.org/2001/XMLSchema#yearMonthDuration"||e==="http://www.w3.org/2001/XMLSchema#duration"}isDayTimeDurationValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof Fo.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 n=parseFloat(e.value);if(!isNaN(n))return n}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 wr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof Fo.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 Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof Fo.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let n=e,i=this.extractFunctionName(n.function),s=this.evaluateSpecialFunction(i,n.args,t);if(s!==void 0)return s.value;let o=Tee.functionHandlers.get(i);if(!o)throw new wr(`Unknown function: ${i}`);let c={evaluateExpression:a((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:a((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:a(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:a(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:a(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return o(n.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 wr(`Unknown function format: ${String(e)}`)}evaluateSpecialFunction(e,t,n){switch(e){case"coalesce":for(let i of t)try{let s=this.evaluateExpression(i,n);if(s!=null)return{value:s}}catch{continue}return{value:void 0};case"if":{if(!t||t.length!==3)throw new wr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],n);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],n):this.evaluateExpression(t[2],n)}}case"byuuid":return{value:this.evaluateByUUID({type:"function",function:"byuuid",args:t},n)};default:return}}getTermFromExpression(e,t){let n=e;if(n.type==="variable"&&n.name)return t.get(n.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 Fo.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 n=parseFloat(e.value);return!isNaN(n)&&n!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new wr("exo:byUUID requires exactly 1 argument (UUID string)");let n=this.evaluateExpression(e.args[0],t),i=this.getStringValue(n);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 o=this.tripleStore.findSubjectsByUUIDSync(s);if(o.length===0){this.uuidCache.set(s,null);return}let c=o[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let n=e.toLowerCase();this.uuidCache.set(n,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Yf.FilterExecutor=gI});var bI=T(kb=>{"use strict";Object.defineProperty(kb,"__esModule",{value:!0});kb.OptionalExecutor=void 0;var yI=class{static{a(this,"OptionalExecutor")}async*execute(e,t){let n=[];for await(let s of e)n.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(n,i)}async executeAll(e,t){let n=[];for(let i of this.hashJoin(e,t))n.push(i);return n}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let n=new Set;for(let l of e)for(let u of l.variables())n.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 n)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let o="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,o),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,o),f=c.get(u),d=!1;if(f)for(let p of f){let h=l.merge(p);h!==null&&(yield h,d=!0)}d||(yield l)}}computeHashKey(e,t,n){let i=[];for(let s of t){let o=e.get(s);i.push(o!==void 0?o.toString():"UNBOUND")}return i.join(n)}*nestedLoopJoin(e,t){for(let n of e){let i=!1;for(let s of t){let o=n.merge(s);o!==null&&(yield o,i=!0)}i||(yield n)}}};kb.OptionalExecutor=yI});var SI=T(Mb=>{"use strict";Object.defineProperty(Mb,"__esModule",{value:!0});Mb.UnionExecutor=void 0;var _I=class{static{a(this,"UnionExecutor")}async*execute(e,t){let n=new Set;for await(let i of e){let s=this.getSolutionKey(i);n.has(s)||(n.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);n.has(s)||(n.add(s),yield i)}}async executeAll(e,t){let n=[];async function*i(){for(let o of e)yield o}a(i,"generateLeft");async function*s(){for(let o of t)yield o}a(s,"generateRight");for await(let o of this.execute(i(),s()))n.push(o);return n}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Mb.UnionExecutor=_I});var OM=T($b=>{"use strict";Object.defineProperty($b,"__esModule",{value:!0});$b.MinusExecutor=void 0;var wI=class{static{a(this,"MinusExecutor")}async*execute(e,t){let n=[];for await(let s of e)n.push(s);let i=[];for await(let s of t)i.push(s);for(let s of n){let o=!1;for(let c of i)if(this.areCompatible(s,c)){o=!0;break}o||(yield s)}}async executeAll(e,t){let n=[];async function*i(){for(let o of e)yield o}a(i,"generateLeft");async function*s(){for(let o of t)yield o}a(s,"generateRight");for await(let o of this.execute(i(),s()))n.push(o);return n}areCompatible(e,t){let n=e.variables(),i=new Set(t.variables()),s=n.filter(o=>i.has(o));if(s.length===0)return!1;for(let o of s){let c=e.get(o),l=t.get(o);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};$b.MinusExecutor=wI});var PM=T(Xf=>{"use strict";Object.defineProperty(Xf,"__esModule",{value:!0});Xf.ValuesExecutor=Xf.ValuesExecutorError=void 0;var Aee=Aa(),xM=Ne(),Iee=Ye(),jb=class extends Error{static{a(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Xf.ValuesExecutorError=jb;var EI=class{static{a(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 n of this.execute(e))t.push(n);return t}createSolutionMapping(e){let t=new Aee.SolutionMapping;for(let[n,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(n,s)}return t}toRDFTerm(e){if(e.type==="iri")return new xM.IRI(e.value);if(e.type==="literal")return new Iee.Literal(e.value,e.datatype?new xM.IRI(e.datatype):void 0,e.language,e.direction);throw new jb(`Unknown term type: ${e.type}`)}};Xf.ValuesExecutor=EI});var NM=T(Qf=>{"use strict";Object.defineProperty(Qf,"__esModule",{value:!0});Qf.AggregateExecutor=Qf.AggregateExecutorError=void 0;var FM=Aa(),Yr=Ye(),TI=Ne(),Ree=Nb(),Cee=ub(),Oee=db(),LM=new TI.IRI("http://www.w3.org/2001/XMLSchema#integer"),eu=new TI.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Lo=new TI.IRI("http://www.w3.org/2001/XMLSchema#string");function DM(r){return typeof r=="object"&&r.type==="custom"}a(DM,"isCustomAggregation");var qh=class extends Error{static{a(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};Qf.AggregateExecutorError=qh;var vI=class{static{a(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Ree.FilterExecutor}execute(e,t){let n=this.groupSolutions(t,e.variables),i=[];for(let[s,o]of n.entries()){let c=new Map;for(let u of e.variables)if(o.length>0){let f=o[0].get(u);f&&c.set(u,f)}for(let u of e.aggregates){let f=this.computeAggregate(u.expression,o);c.set(u.variable,f)}let l=new FM.SolutionMapping;for(let[u,f]of c.entries())l.set(u,f);i.push(l)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let n=new Map;if(t.length===0)return n.set("",e),n;for(let i of e){let s=this.computeGroupKey(i,t),o=n.get(s);o?o.push(i):n.set(s,[i])}return n}computeGroupKey(e,t){return t.map(n=>{let i=e.get(n);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(DM(e.aggregation))return this.computeCustomAggregate(e,t);let n=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(n,e.distinct);return new Yr.Literal(String(s),LM)}case"sum":{let s=this.computeSum(n);return new Yr.Literal(String(s),eu)}case"avg":{let s=this.computeAvg(n);return new Yr.Literal(String(s),eu)}case"min":{let s=this.computeMin(n);return s===void 0?new Yr.Literal("",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}case"max":{let s=this.computeMax(n);return s===void 0?new Yr.Literal("",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}case"group_concat":{let s=this.computeGroupConcat(n,e.separator||" ",e.distinct);return new Yr.Literal(s||" ",Lo)}case"sample":{let s=this.computeSample(n,e.distinct);return s===void 0?new Yr.Literal(" ",Lo):typeof s=="number"?new Yr.Literal(String(s),eu):new Yr.Literal(String(s),Lo)}default:{let s=i;throw new qh(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,o=Cee.CustomAggregateRegistry.getInstance().get(i);if(o||(o=Oee.BUILT_IN_AGGREGATES[i]),!o)throw new qh(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=o.init();for(let l of t){let u=null;if(e.expression){let d=this.evaluateExpression(e.expression,l);d!==void 0&&(u=d)}else u=1;let f;if(e.expression2){let d=this.evaluateExpression(e.expression2,l);f=d===void 0?null:d}o.step(c,u,f)}return o.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let n=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&n.push(s)}return n}evaluateExpression(e,t){if(e.type==="variable"){let n=t.get(e.name);return n==null?void 0:typeof n=="number"||typeof n=="string"||typeof n=="boolean"?n:typeof n=="object"&&"value"in n?n.value:n}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(n=>String(n))).size:e.length}computeSum(e){return e.map(n=>parseFloat(String(n))).filter(n=>!isNaN(n)).reduce((n,i)=>n+i,0)}computeAvg(e){let t=e.map(n=>parseFloat(String(n))).filter(n=>!isNaN(n));return t.length===0?0:t.reduce((n,i)=>n+i,0)/t.length}asAllNumeric(e){let t=[];for(let n of e){if(typeof n=="number"){t.push(n);continue}let i=String(n).trim();if(i==="")return null;let s=Number(i);if(Number.isNaN(s))return null;t.push(s)}return t.length>0?t:null}computeMin(e){if(e.length===0)return;let t=this.asAllNumeric(e);if(t)return Math.min(...t);let n=e.map(i=>String(i));return n.reduce((i,s)=>s<i?s:i,n[0])}computeMax(e){if(e.length===0)return;let t=this.asAllNumeric(e);if(t)return Math.max(...t);let n=e.map(i=>String(i));return n.reduce((i,s)=>s>i?s:i,n[0])}computeGroupConcat(e,t,n){let i=e.map(s=>String(s));return n&&(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 o=s[0],c=parseFloat(o);return isNaN(c)?o:c}let n=e[0];if(typeof n=="number")return n;let i=parseFloat(String(n));return isNaN(i)?String(n):i}createEmptyAggregateResult(e){let t=new FM.SolutionMapping;for(let n of e.aggregates){let i=n.expression.aggregation;if(DM(i)){t.set(n.variable,new Yr.Literal("0",eu));continue}switch(i){case"count":t.set(n.variable,new Yr.Literal("0",LM));break;case"sum":case"avg":t.set(n.variable,new Yr.Literal("0",eu));break;case"group_concat":t.set(n.variable,new Yr.Literal(" ",Lo));break;case"min":case"max":case"sample":t.set(n.variable,new Yr.Literal("",Lo));break;default:t.set(n.variable,new Yr.Literal("",Lo))}}return t}};Qf.AggregateExecutor=vI});var CI=T(Bb=>{"use strict";Object.defineProperty(Bb,"__esModule",{value:!0});Bb.ConstructExecutor=void 0;var xee=Ri(),tu=Ne(),AI=Ye(),II=dr(),Pee=fh(),RI=class{static{a(this,"ConstructExecutor")}async execute(e,t){let n=[],i=new Set;for(let s of t)for(let o of e)try{let c=this.instantiateTriple(o,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),n.push(c))}catch{continue}return n}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let n=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new xee.Triple(n,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let n=t.get(e.value);if(!n)throw new Error(`Unbound variable: ${e.value}`);return n}if(e.type==="iri")return new tu.IRI(e.value);if(e.type==="literal")return new AI.Literal(e.value,e.datatype?new tu.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new II.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let n=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new Pee.QuotedTriple(n,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let n=t.get(e.value);if(!n)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(n instanceof AI.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return n}if(e.type==="iri")return new tu.IRI(e.value);if(e.type==="blank")return new II.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 n=t.get(e.value);if(!n)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(n instanceof tu.IRI))throw new Error("Quoted triple predicate must be an IRI");return n}return new tu.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 tu.IRI(e.value);if(e.type==="blank")return new II.BlankNode(e.value);if(e.type==="literal")return new AI.Literal(e.value,e.datatype?new tu.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let n=e;throw new Error(`Invalid element type for quoted triple object: ${n.type}`)}};Bb.ConstructExecutor=RI});var MM=T(Jf=>{"use strict";Object.defineProperty(Jf,"__esModule",{value:!0});Jf.ServiceExecutor=Jf.ServiceExecutorError=void 0;var Fee=Aa(),kM=Ne(),Lee=Ye(),Dee=dr(),ru=class extends Error{static{a(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Jf.ServiceExecutorError=ru;var OI=class{static{a(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,n)=>fetch(t,n)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let n=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,n);for(let s of i)yield s}catch(n){if(e.silent)return;throw n}}async executeRemoteQuery(e,t){let n;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,o=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 ru(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(o)}}catch(s){if(n=s instanceof Error?s:new Error(String(s)),this.isRetryableError(n)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new ru(`Failed to query remote SPARQL endpoint ${e}: ${n.message}`,n)}throw new ru(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,n)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new Fee.SolutionMapping;for(let[n,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(n,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new kM.IRI(e.value);case"literal":{let t=e.datatype?new kM.IRI(e.datatype):void 0;return new Lee.Literal(e.value,t,e["xml:lang"])}case"bnode":return new Dee.BlankNode(e.value);default:throw new ru(`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))}};Jf.ServiceExecutor=OI});var jM=T(Zf=>{"use strict";Object.defineProperty(Zf,"__esModule",{value:!0});Zf.GraphExecutor=Zf.GraphExecutorError=void 0;var $M=Ne(),Ub=class extends Error{static{a(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Zf.GraphExecutorError=Ub;var xI=class{static{a(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,n){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,n);else throw new Ub(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,n){let i=new $M.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*n(e,i))}async*executeWithGraphVariable(e,t,n,i){if(i){let o=i.get(t.value);if(o&&o instanceof $M.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:o.value},n);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let o of s)for await(let c of n(e.pattern,o)){let l=c.clone();l.set(t.value,o),yield l}}};Zf.GraphExecutor=xI});var VM=T(ed=>{"use strict";Object.defineProperty(ed,"__esModule",{value:!0});ed.ClassHierarchyResolvingStore=ed.SymbolicClassAmbiguityError=void 0;var BM=Ri(),nu=Ne(),iu=Ct(),UM="\0",Vb=class extends Error{static{a(this,"SymbolicClassAmbiguityError")}constructor(e){super(`Ambiguous class reference '${e}' \u2014 two or more class files derive this symbolic form (a prefix collision). The prefix is an alias, not identity: reference the class by its uid, or narrow the ontology.`),this.symbolic=e,this.name="SymbolicClassAmbiguityError"}};ed.SymbolicClassAmbiguityError=Vb;var An=class r{static{a(this,"ClassHierarchyResolvingStore")}constructor(e){this.real=e,this.findSubjectsByUUID=e.findSubjectsByUUID?.bind(e),this.findSubjectsByUUIDSync=e.findSubjectsByUUIDSync?.bind(e),this.addToGraph=e.addToGraph?.bind(e),this.removeFromGraph=e.removeFromGraph?.bind(e),this.matchInGraph=e.matchInGraph?.bind(e),this.getNamedGraphs=e.getNamedGraphs?.bind(e),this.hasGraph=e.hasGraph?.bind(e),this.clearGraph=e.clearGraph?.bind(e),this.countInGraph=e.countInGraph?.bind(e)}async match(e,t,n){return t&&r.HIERARCHY_PREDICATES.has(t.value)&&e instanceof nu.IRI?this.matchHierarchySubject(e,t,n):t&&r.MEMBERSHIP_PREDICATES.has(t.value)&&n instanceof nu.IRI&&n.value.startsWith(r.ONTOLOGY_BASE)?this.matchMembershipObject(e,t,n):this.real.match(e,t,n)}async matchHierarchySubject(e,t,n){let i=await this.real.match(e,t,n),s=await this.resolveSymbolicToFileIri(e.value);if(!s)return i;let o=await this.real.match(s,t,n);if(o.length===0)return i;let c=o.map(l=>new BM.Triple(e,l.predicate,l.object));return i.length===0?c:r.dedupTriples([...i,...c])}async matchMembershipObject(e,t,n){let i=await this.resolveSymbolicToFileIri(n.value),s=await this.real.match(e,t,n);if(!i)return s;let o=await this.real.match(e,t,i);if(o.length===0)return s;let c=o.map(l=>new BM.Triple(l.subject,l.predicate,n));return r.dedupTriples([...s,...c])}static dedupTriples(e){let t=new Set,n=[];for(let i of e){let s=`${r.termKey(i.subject)}${UM}${r.termKey(i.predicate)}${UM}${r.termKey(i.object)}`;t.has(s)||(t.add(s),n.push(i))}return n}static termKey(e){if(e instanceof nu.IRI)return`I:${e.value}`;if(e&&typeof e=="object"&&"value"in e){let t=e.value,n=e.datatype?.value??"";return`L:${String(t)}^${n}`}return`?:${String(e)}`}async resolveSymbolicToFileIri(e){let{index:t,ambiguous:n}=await this.getIndex();if(n.has(e))throw new Vb(e);return t.get(e)??null}async getIndex(){let e=await this.real.count(),t=r.INDEX_CACHE.get(this.real);if(t&&t.count===e)return{index:t.index,ambiguous:t.ambiguous};let{index:n,ambiguous:i}=await this.buildIndex();return r.INDEX_CACHE.set(this.real,{count:e,index:n,ambiguous:i}),{index:n,ambiguous:i}}async buildIndex(){let e=new Map,t=new Set,n=[...await this.real.match(void 0,new nu.IRI(r.EXO_ASSET_LABEL),void 0),...await this.real.match(void 0,new nu.IRI(r.RDFS_LABEL),void 0)];for(let i of n){if(!(i.subject instanceof nu.IRI))continue;let s=r.literalValue(i.object);if(s===null)continue;let o=r.labelToSymbolicIRI(s);if(!o)continue;let c=e.get(o);c?c.value!==i.subject.value&&t.add(o):e.set(o,i.subject)}return{index:e,ambiguous:t}}static literalValue(e){return typeof e=="object"&&e!==null&&"value"in e&&!(e instanceof nu.IRI)&&typeof e.value=="string"?e.value:null}static labelToSymbolicIRI(e){let t=iu.Namespace.fromPropertyKey(e);return!t||/[\s()]/.test(t.localName)?null:t.namespace.term(t.localName).value}add(e){return this.real.add(e)}remove(e){return this.real.remove(e)}has(e){return this.real.has(e)}addAll(e){return this.real.addAll(e)}removeAll(e){return this.real.removeAll(e)}clear(){return this.real.clear()}count(){return this.real.count()}subjects(){return this.real.subjects()}predicates(){return this.real.predicates()}objects(){return this.real.objects()}beginTransaction(){return this.real.beginTransaction()}};ed.ClassHierarchyResolvingStore=An;An.EXO_CLASS_SUPER_CLASS=iu.Namespace.EXO.term("Class_superClass").value;An.RDFS_SUBCLASS_OF=iu.Namespace.RDFS.term("subClassOf").value;An.RDFS_LABEL=iu.Namespace.RDFS.term("label").value;An.EXO_ASSET_LABEL=iu.Namespace.EXO.term("Asset_label").value;An.EXO_INSTANCE_CLASS=iu.Namespace.EXO.term("Instance_class").value;An.RDF_TYPE=iu.Namespace.RDF.term("type").value;An.ONTOLOGY_BASE="https://exocortex.my/ontology/";An.HIERARCHY_PREDICATES=new Set([An.EXO_CLASS_SUPER_CLASS,An.RDFS_SUBCLASS_OF]);An.MEMBERSHIP_PREDICATES=new Set([An.EXO_INSTANCE_CLASS,An.RDF_TYPE]);An.INDEX_CACHE=new WeakMap});var GM=T(rd=>{"use strict";Object.defineProperty(rd,"__esModule",{value:!0});rd.SPARQLGenerator=rd.SPARQLGeneratorError=void 0;var td=class extends Error{static{a(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};rd.SPARQLGeneratorError=td;var PI=class{static{a(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),n=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${n} WHERE {
|
|
104
104
|
${i}
|
|
105
105
|
}`}generateWhereClause(e,t=2){let n=" ".repeat(t);switch(e.type){case"bgp":return this.generateBGP(e,t);case"filter":return`${this.generateWhereClause(e.input,t)}
|
|
106
106
|
${n}FILTER(${this.generateExpression(e.expression)})`;case"join":return`${this.generateWhereClause(e.left,t)}
|
|
@@ -713,7 +713,7 @@ Next steps:
|
|
|
713
713
|
`).map(n=>n.trim()).filter(n=>n.length>0),t=e[e.length-1];if(t!==void 0)try{return JSON.parse(t)}catch{return}}a(q1e,"parseLastJsonLine");function TW(r,e){return e.filter(t=>{let n=r[t];return typeof n!="string"||n.trim().length===0})}a(TW,"missingStringFields");var Lv=class{constructor(e){this.deps=e}static{a(this,"McpServer")}async handle(e){if(typeof e!="object"||e===null||Array.isArray(e))return{jsonrpc:"2.0",id:null,error:{code:vW,message:"Invalid request: expected a JSON-RPC object"}};let t=e.id,n=t===void 0;if(typeof e.method!="string")return n?null:{jsonrpc:"2.0",id:t??null,error:{code:vW,message:"Invalid request: missing method"}};if(n)return null;let i=t??null;switch(e.method){case"initialize":return{jsonrpc:"2.0",id:i,result:{protocolVersion:V1e,capabilities:{tools:{}},serverInfo:{name:"exocortex",version:this.deps.version}}};case"ping":return{jsonrpc:"2.0",id:i,result:{}};case"tools/list":return{jsonrpc:"2.0",id:i,result:{tools:EW}};case"tools/call":return{jsonrpc:"2.0",id:i,result:await this.callTool(e.params??{})};default:return{jsonrpc:"2.0",id:i,error:{code:G1e,message:`Method not found: ${e.method}`}}}}async callTool(e){let t=e.name,n=e.arguments??{},i;if(t==="create_asset"){let c=TW(n,["vault","class","label"]);if(c.length>0)return Kp(`create_asset: missing required argument(s): ${c.join(", ")}`,!0);let l=_W(n);if(l!==null)return Kp(`create_asset: ${l}`,!0);i=SW(n)}else if(t==="create_effort"){let c=TW(n,["vault","command","target"]);if(c.length>0)return Kp(`create_effort: missing required argument(s): ${c.join(", ")}`,!0);i=wW(n)}else return Kp(`Unknown tool: ${String(t)}`,!0);let s=await this.deps.runCli(i);if(s.exitCode!==0){let c=s.stderr.trim()||s.stdout.trim()||"(no diagnostic output)";return Kp(`exocortex-cli exited ${s.exitCode}
|
|
714
714
|
${c}`,!0)}let o=q1e(s.stdout);return Kp(o===void 0?s.stdout.trim():JSON.stringify(o))}};var RW=require("child_process");var W1e=32*1024*1024;function CW(r){return e=>new Promise(t=>{(0,RW.execFile)(process.execPath,[r,...e],{maxBuffer:W1e},(n,i,s)=>{let o=0;if(n){let c=n.code;o=typeof c=="number"?c:1}t({stdout:i,stderr:s,exitCode:o})})})}a(CW,"createSelfCliRunner");async function z1e(r,e,t){let n=(0,OW.createInterface)({input:e,crlfDelay:1/0});for await(let i of n){let s=i.trim();if(s.length===0)continue;let o;try{o=JSON.parse(s)}catch{t(JSON.stringify({jsonrpc:"2.0",id:null,error:{code:AW,message:"Parse error: invalid JSON"}})+`
|
|
715
715
|
`);continue}let c;try{c=await r.handle(o)}catch(l){c={jsonrpc:"2.0",id:typeof o?.id=="string"||typeof o?.id=="number"?o.id:null,error:{code:IW,message:`Internal error: ${l instanceof Error?l.message:String(l)}`}}}c!==null&&t(JSON.stringify(c)+`
|
|
716
|
-
`)}}a(z1e,"runStdioServer");function xW(r){return new de("mcp").description("Run an MCP (Model Context Protocol) stdio server exposing create_asset / create_effort tools backed by this CLI").option("--entry <path>","Path to the CLI entry script the tools invoke (defaults to this process's script)").action(async e=>{let t=e.entry??process.argv[1],n=new Lv({runCli:CW(t),version:r??"unknown"});await z1e(n,process.stdin,i=>process.stdout.write(i))})}a(xW,"mcpCommand");function Dv(r){let e=new de;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(r??"17.10.
|
|
716
|
+
`)}}a(z1e,"runStdioServer");function xW(r){return new de("mcp").description("Run an MCP (Model Context Protocol) stdio server exposing create_asset / create_effort tools backed by this CLI").option("--entry <path>","Path to the CLI entry script the tools invoke (defaults to this process's script)").action(async e=>{let t=e.entry??process.argv[1],n=new Lv({runCli:CW(t),version:r??"unknown"});await z1e(n,process.stdin,i=>process.stdout.write(i))})}a(xW,"mcpCommand");function Dv(r){let e=new de;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(r??"17.10.5"),e.addCommand(JG()),e.addCommand(cq()),e.addCommand(PV()),e.addCommand(kV()),e.addCommand(nG()),e.addCommand(MV()),e.addCommand(VV()),e.addCommand(GV()),e.addCommand(fG()),e.addCommand(gG()),e.addCommand(kG()),e.addCommand(UG()),e.addCommand(WG()),e.addCommand(zG()),e.addCommand(KG()),e.addCommand(HG()),e.addCommand(YG()),e.addCommand(Fq()),e.addCommand(Nq()),e.addCommand(aW()),e.addCommand(lW()),e.addCommand(dW()),e.addCommand(pW()),e.addCommand(gW()),e.addCommand(Xq()),e.addCommand(iW()),e.addCommand(yW()),e.addCommand(xW(r??"17.10.5")),e}a(Dv,"createProgram");Dv().parse();0&&(module.exports={createProgram});
|
|
717
717
|
/*! Bundled license information:
|
|
718
718
|
|
|
719
719
|
reflect-metadata/Reflect.js:
|