@kitelev/exocortex-cli 15.174.3 → 15.174.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 v15.174.
|
|
2
|
+
// @kitelev/exocortex-cli v15.174.5
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -45,7 +45,7 @@ Expecting `+Jd.join(", ")+", got '"+(this.terminals_[dt]||dt)+"'":n0="Parse erro
|
|
|
45
45
|
`)+`
|
|
46
46
|
`+s.trimStart()),s}findPrefixStarDeclarations(e){let t=[],r=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(r.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 Lc(`Unclosed IRI in PREFIX* declaration at position ${o}`)}else throw new Lc(`Expected IRI after PREFIX* at position ${i}`)}else continue}i++}return t}findDeclarationEnd(e,t){let r=t;for(;r<e.length;){let i=e[r];if(i===`
|
|
47
47
|
`)return r+1;let s=e.substring(r).toUpperCase();if(s.startsWith("PREFIX")||s.startsWith("BASE")||s.startsWith("SELECT")||s.startsWith("CONSTRUCT")||s.startsWith("DESCRIBE")||s.startsWith("ASK"))return r;if(/\s/.test(i)){r++;continue}break}return r}extractPrefixFromUri(e){let t=e.replace(/^https?:\/\//,"");t=t.replace(/\/$/,"").replace(/#$/,"");let r=t.split(/[/.#]+/).filter(Boolean);if(r.length===0)return null;let i=r[r.length-1];return/^(ontology|vocab|schema|ns|core)$/i.test(i)&&r.length>1?r[r.length-2].toLowerCase():i.toLowerCase().replace(/[^a-z0-9]/g,"")}};ko.PrefixStarTransformer=c1;var Lc=class extends Error{static{a(this,"PrefixStarTransformerError")}constructor(e){super(`PREFIX* transformation error: ${e}`),this.name="PrefixStarTransformerError"}};ko.PrefixStarTransformerError=Lc});var l1=S(Mc=>{"use strict";Object.defineProperty(Mc,"__esModule",{value:!0});Mc.DescribeOptionsTransformer=Mc.DescribeOptionsTransformerError=void 0;var op=class extends Error{static{a(this,"DescribeOptionsTransformerError")}constructor(e){super(e),this.name="DescribeOptionsTransformerError"}};Mc.DescribeOptionsTransformerError=op;var kc=class n{static{a(this,"DescribeOptionsTransformer")}transform(e){if(!n.DESCRIBE_QUERY_PATTERN.test(e))return{query:e};let t=e,r={},i=!1,s=n.DEPTH_PATTERN.exec(e);if(s){let o=parseInt(s[1],10);if(o<0)throw new op(`DESCRIBE DEPTH must be a non-negative integer, got: ${o}`);r.depth=o,i=!0,n.DEPTH_PATTERN.lastIndex=0,t=t.replace(n.DEPTH_PATTERN,"")}return n.DEPTH_PATTERN.lastIndex=0,n.SYMMETRIC_PATTERN.test(e)&&(r.symmetric=!0,i=!0,n.SYMMETRIC_PATTERN.lastIndex=0,t=t.replace(n.SYMMETRIC_PATTERN,"")),n.SYMMETRIC_PATTERN.lastIndex=0,t=t.replace(/\s{2,}/g," ").trim(),{query:t,options:i?r:void 0}}hasDescribeOptions(e){let t=n.DEPTH_PATTERN.test(e);n.DEPTH_PATTERN.lastIndex=0;let r=n.SYMMETRIC_PATTERN.test(e);return n.SYMMETRIC_PATTERN.lastIndex=0,t||r}};Mc.DescribeOptionsTransformer=kc;kc.DEPTH_PATTERN=/\bDEPTH\s+(\d+)/gi;kc.SYMMETRIC_PATTERN=/\bSYMMETRIC\b/gi;kc.DESCRIBE_QUERY_PATTERN=/\bDESCRIBE\b/i});var nx=S(jc=>{"use strict";Object.defineProperty(jc,"__esModule",{value:!0});jc.DirectionalLangTagTransformerError=jc.DirectionalLangTagTransformer=void 0;var ap=class n{static{a(this,"DirectionalLangTagTransformer")}constructor(){this.directionMappings=new Map}transform(e){return this.directionMappings.clear(),e.replace(n.DIRECTIONAL_TAG_REGEX,(t,r,i,s,o)=>{let c=s.toLowerCase();return this.directionMappings.set(c,o),`${r}${i}${r}@${s}`})}getDirection(e){return this.directionMappings.get(e.toLowerCase())}getAllMappings(){return new Map(this.directionMappings)}hasDirectionalTags(e){return n.DIRECTIONAL_TAG_REGEX.lastIndex=0,n.DIRECTIONAL_TAG_REGEX.test(e)}clearMappings(){this.directionMappings.clear()}};jc.DirectionalLangTagTransformer=ap;ap.DIRECTIONAL_TAG_REGEX=/(["'])((?:[^\\]|\\.)*?)\1@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)--(ltr|rtl)/g;var u1=class extends Error{static{a(this,"DirectionalLangTagTransformerError")}constructor(e){super(`Directional language tag transformation error: ${e}`),this.name="DirectionalLangTagTransformerError"}};jc.DirectionalLangTagTransformerError=u1});var ix=S(Bc=>{"use strict";Object.defineProperty(Bc,"__esModule",{value:!0});Bc.TripleTermTransformerError=Bc.TripleTermTransformer=void 0;var f1=class{static{a(this,"TripleTermTransformer")}transform(e){let t=e,r,i=0,s=100;do if(r=t,t=this.transformSinglePass(t),i++,i>s)throw new $c("Too many nested triple terms (max 100 iterations)");while(t!==r);return t}hasTripleTermSyntax(e){return this.findTripleTermPositions(e).length>0}transformSinglePass(e){let t=this.findTripleTermPositions(e);if(t.length===0)return e;let r=e;for(let i=t.length-1;i>=0;i--){let s=t[i],o=this.extractTripleTerm(r,s);if(o){let c=this.convertToStandardSyntax(o.content);r=r.substring(0,s)+c+r.substring(s+o.length)}}return r}findTripleTermPositions(e){let t=[],r=0;for(;r<e.length;){if(e[r]==="'"){r=this.skipStringLiteral(e,r,"'");continue}if(e[r]==='"'){r=this.skipStringLiteral(e,r,'"');continue}if(e.substring(r,r+2)==="<<"&&this.isParenthesizedTripleTerm(e,r)){t.push(r),r+=2;continue}r++}return t}skipStringLiteral(e,t,r){let i=r.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]!==r;)e[t]==="\\"&&t++,t++;return t+1}isParenthesizedTripleTerm(e,t){let r=t+2;for(;r<e.length&&/\s/.test(e[r]);)r++;return e[r]==="("}extractTripleTerm(e,t){let r=t+2;for(;r<e.length&&/\s/.test(e[r]);)r++;if(e[r]!=="(")return null;r++;let i=1;for(;r<e.length&&i>0;){if(e[r]==="'"||e[r]==='"'){r=this.skipStringLiteral(e,r,e[r]);continue}if(e.substring(r,r+2)==="<<"&&this.isParenthesizedTripleTerm(e,r)){for(r+=2;r<e.length&&/\s/.test(e[r]);)r++;e[r]==="("&&(i++,r++);continue}if(e.substring(r,r+2)==="<<"){r+=2;let s=1;for(;r<e.length&&s>0;){if(e[r]==="'"||e[r]==='"'){r=this.skipStringLiteral(e,r,e[r]);continue}if(e.substring(r,r+2)==="<<"){s++,r+=2;continue}if(e.substring(r,r+2)===">>"){s--,r+=2;continue}r++}continue}if(e[r]==="("){i++,r++;continue}if(e[r]===")"){let s=r+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}}r=s+2;continue}r++;continue}r++}if(i>0)throw new $c(`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 $c(`Invalid triple term syntax: ${e.substring(0,50)}...`);return`<< ${t[1]} >>`}};Bc.TripleTermTransformer=f1;var $c=class extends Error{static{a(this,"TripleTermTransformerError")}constructor(e){super(`Triple term transformation error: ${e}`),this.name="TripleTermTransformerError"}};Bc.TripleTermTransformerError=$c});var h1=S(cp=>{"use strict";Object.defineProperty(cp,"__esModule",{value:!0});cp.VaultPrefixTransformer=void 0;var S9=/PREFIX\s+(\w+)\s*:/gi,v9=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"]),d1=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),r=[];for(let[o,c]of this.vaultPrefixes)!t.has(o.toLowerCase())&&!v9.has(o.toLowerCase())&&r.push({prefix:o,baseIRI:c});if(r.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(`
|
|
48
|
-
`,s);l!==-1?(i+=e.substring(s,l),s=l):(i+=e.substring(s),s=e.length);continue}let c=this.tryReplacePrefixedName(e,s,r);if(c){i+=c.iri,s=c.endIndex;continue}i+=o,s++}return i}tryReplacePrefixedName(e,t,r){if(t>0&&/[a-zA-Z0-9_]/.test(e[t-1]))return null;for(let{prefix:i,baseIRI:s}of r){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,r=new RegExp(S9.source,"gi"),i;for(;(i=r.exec(e))!==null;)t.add(i[1].toLowerCase());return t}skipLiteral(e,t){let r=e[t];if(t+2<e.length&&e.substring(t,t+3)===r+r+r){let s=e.indexOf(r+r+r,t+3);return s!==-1?s+3:e.length}let i=t+1;for(;i<e.length&&e[i]!==r;)e[i]==="\\"&&i++,i++;return i<e.length?i+1:e.length}};cp.VaultPrefixTransformer=d1});var Uc=S(Rn=>{"use strict";var b9=Rn&&Rn.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=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(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),w9=Rn&&Rn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),E9=Rn&&Rn.__importStar||(function(){var n=a(function(e){return n=Object.getOwnPropertyNames||function(t){var r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[r.length]=i);return r},n(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=n(e),i=0;i<r.length;i++)r[i]!=="default"&&b9(t,e,r[i]);return w9(t,e),t}})();Object.defineProperty(Rn,"__esModule",{value:!0});Rn.SPARQLParser=Rn.ExoQLParser=Rn.SPARQLParseError=void 0;var sx=E9(tx()),p1=o1(),m1=a1(),ox=rx(),g1=l1(),T9=nx(),y1=ix(),A9=h1(),ur=class extends Error{static{a(this,"SPARQLParseError")}constructor(e,t,r,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=r}};Rn.SPARQLParseError=ur;var lp=class{static{a(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new sx.Parser({sparqlStar:!0}),this.generator=new sx.Generator({sparqlStar:!0}),this.caseWhenTransformer=new p1.CaseWhenTransformer,this.lateralTransformer=new m1.LateralTransformer,this.prefixStarTransformer=new ox.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new g1.DescribeOptionsTransformer,this.directionalLangTagTransformer=new T9.DirectionalLangTagTransformer,this.tripleTermTransformer=new y1.TripleTermTransformer,this.vaultPrefixTransformer=new A9.VaultPrefixTransformer}setVaultPrefixes(e){this.vaultPrefixTransformer.setVaultPrefixes(e)}parse(e){try{let t=this.vaultPrefixTransformer.transform(e),r=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=r.options;let i=r.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 g1.DescribeOptionsTransformerError)throw new ur(t.message);if(t instanceof m1.LateralTransformerError)throw new ur(t.message);if(t instanceof p1.CaseWhenTransformerError)throw new ur(t.message);if(t instanceof y1.TripleTermTransformerError)throw new ur(t.message);if(t instanceof Error){let r=t.message.match(/line (\d+), column (\d+)/),i=r?parseInt(r[1],10):void 0,s=r?parseInt(r[2],10):void 0;throw new ur(`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),r=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=r.options;let i=r.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 g1.DescribeOptionsTransformerError)throw new ur(t.message);if(t instanceof ox.PrefixStarTransformerError)throw new ur(t.message);if(t instanceof m1.LateralTransformerError)throw new ur(t.message);if(t instanceof p1.CaseWhenTransformerError)throw new ur(t.message);if(t instanceof y1.TripleTermTransformerError)throw new ur(t.message);if(t instanceof Error){let r=t.message.match(/line (\d+), column (\d+)/),i=r?parseInt(r[1],10):void 0,s=r?parseInt(r[2],10):void 0;throw new ur(`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 ur(`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 ur("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 ur("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new ur(`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 ur(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};Rn.ExoQLParser=lp;Rn.SPARQLParser=lp});var Da=S(up=>{"use strict";Object.defineProperty(up,"__esModule",{value:!0});up.AlgebraTranslatorError=void 0;var _1=class extends Error{static{a(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};up.AlgebraTranslatorError=_1});var fp=S(ls=>{"use strict";Object.defineProperty(ls,"__esModule",{value:!0});ls.isVariableExpression=x9;ls.isVariableTerm=C9;ls.isNamedNode=R9;ls.isLiteral=I9;ls.isPropertyPath=P9;ls.isAggregateExpression=O9;ls.isOperationExpression=F9;ls.isFunctionCallExpression=D9;function x9(n){return typeof n=="object"&&n!==null&&"expression"in n&&"variable"in n}a(x9,"isVariableExpression");function C9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Variable"}a(C9,"isVariableTerm");function R9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="NamedNode"}a(R9,"isNamedNode");function I9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Literal"}a(I9,"isLiteral");function P9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="path"}a(P9,"isPropertyPath");function O9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="aggregate"}a(O9,"isAggregateExpression");function F9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="operation"}a(F9,"isOperationExpression");function D9(n){return typeof n=="object"&&n!==null&&"type"in n&&(n.type==="functionCall"||n.type==="functioncall")}a(D9,"isFunctionCallExpression")});var ax=S(dp=>{"use strict";Object.defineProperty(dp,"__esModule",{value:!0});dp.TripleTranslator=void 0;var dn=Da(),S1=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 dn.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 dn.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 dn.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new dn.AlgebraTranslatorError("Property path must have items array");let t=e.items.map(r=>this.translatePathItem(r));switch(e.pathType){case"/":return{type:"path",pathType:"/",items:t};case"|":return{type:"path",pathType:"|",items:t};case"^":if(t.length!==1)throw new dn.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new dn.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new dn.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new dn.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new dn.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 dn.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new dn.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 r=this.directionMappings.get(e.language.toLowerCase());r&&(t.direction=r)}return t}case"BlankNode":return{type:"blank",value:e.value};case"Quad":return this.translateQuotedTriple(e);default:throw new dn.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new dn.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 dn.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 dn.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};dp.TripleTranslator=S1});var cx=S(hp=>{"use strict";Object.defineProperty(hp,"__esModule",{value:!0});hp.ExpressionTranslator=void 0;var Vc=Da(),v1=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 Vc.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 r=e;return{type:"functionCall",function:r.function,args:r.args.map(i=>this.translateExpression(i))}}if("termType"in e)return this.translateTermExpression(e);throw new Vc.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Vc.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=["=","!=","<",">","<=",">="],r=["&&","||","!"],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])}:r.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 Vc.AlgebraTranslatorError("EXISTS/NOT EXISTS must have exactly one pattern argument");let t=e.args[0],r;return t.type==="group"&&"patterns"in t&&t.patterns?r=this.translateWhereFn(t.patterns):t.type==="bgp"?r=this.translateBGPFn(t):r=this.translatePatternFn(t),{type:"exists",negated:e.operator==="notexists",pattern:r}}translateInExpression(e){if(!e.args||e.args.length!==2)throw new Vc.AlgebraTranslatorError("IN/NOT IN must have exactly 2 arguments (expression and list)");let t=e.args[0],r=e.args[1];if(!Array.isArray(r))throw new Vc.AlgebraTranslatorError("IN/NOT IN second argument must be an array of values");return{type:"in",expression:this.translateExpression(t),list:r.map(i=>this.translateExpression(i)),negated:e.operator==="notin"}}};hp.ExpressionTranslator=v1});var fx=S(pp=>{"use strict";Object.defineProperty(pp,"__esModule",{value:!0});pp.PatternTranslator=void 0;var lx=a1(),kr=Da(),ux=fp(),b1=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 kr.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(o=>o.type==="filter"),r=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{let l=this.translatePattern(c);s={type:"join",left:s,right:l}}}}for(let o of r)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 kr.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 kr.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new kr.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 kr.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 kr.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"),r={type:"union",left:t(e.patterns[0]),right:t(e.patterns[1])};for(let i=2;i<e.patterns.length;i++)r={type:"union",left:r,right:t(e.patterns[i])};return r}translateMinus(e){if(!e.patterns||e.patterns.length===0)throw new kr.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 kr.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 r=e.values.map(i=>this.translateValuesBinding(i));return{type:"values",variables:Array.from(t),bindings:r}}translateValuesBinding(e){let t={};for(let[r,i]of Object.entries(e)){let s=r.startsWith("?")?r.slice(1):r,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 kr.AlgebraTranslatorError(`Unsupported VALUES term type: ${o.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new kr.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 kr.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 kr.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new kr.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 kr.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new kr.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 kr.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 kr.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,ux.isVariableTerm)(i)&&i.value===lx.LateralTransformer.LATERAL_MARKER)}removeLateralMarker(e){if(!("variables"in e)||!e.variables)return e;let t=e,r=t.variables;return{...t,variables:r.filter(i=>!((0,ux.isVariableTerm)(i)&&i.value===lx.LateralTransformer.LATERAL_MARKER))}}};pp.PatternTranslator=b1});var hx=S(mp=>{"use strict";Object.defineProperty(mp,"__esModule",{value:!0});mp.AggregateTranslator=void 0;var dx=Da(),N9=fp(),w1=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 r=[];for(let i of e)(0,N9.isVariableExpression)(i)&&("type"in i.expression&&i.expression.type==="aggregate"?(r.push({variable:i.variable.value,expression:this.translateAggregateExpression(i.expression)}),t.set(i.expression,i.variable.value)):this.collectNestedAggregates(i.expression,r,t));return r}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,r){if(!e||e.length===0)return[];for(let i of e)this.collectNestedAggregates(i,t,r);return e.map(i=>this.transformExpressionWithAggregateVars(i,r))}transformExpressionWithAggregateVars(e,t){let r=t.get(e);if(r!==void 0)return{type:"variable",name:r};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,r=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:r(),distinct:e.distinct||!1,separator:e.separator}:{type:"aggregate",aggregation:{type:"custom",iri:t},expression:r(),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 dx.AlgebraTranslatorError(`Invalid custom aggregate: expected IRI but got ${JSON.stringify(i)}`);return{type:"aggregate",aggregation:{type:"custom",iri:s},expression:r(),distinct:e.distinct||!1,separator:e.separator}}throw new dx.AlgebraTranslatorError(`Unknown aggregate format: ${JSON.stringify(t)}`)}collectNestedAggregates(e,t,r){if(e){if("type"in e&&e.type==="aggregate"){let i=`__agg${this.aggregateCounter++}`;t.push({variable:i,expression:this.translateAggregateExpression(e)}),r.set(e,i)}else if("type"in e&&e.type==="operation"&&"args"in e){let i=e;for(let s of i.args)!Array.isArray(s)&&"type"in s&&!("patterns"in s)?this.collectNestedAggregates(s,t,r):"termType"in s&&this.collectNestedAggregates(s,t,r)}}}};mp.AggregateTranslator=w1});var qc=S(Mo=>{"use strict";Object.defineProperty(Mo,"__esModule",{value:!0});Mo.AlgebraTranslator=Mo.ExoQLAlgebraTranslator=Mo.AlgebraTranslatorError=void 0;var gp=Da(),yp=fp(),L9=ax(),k9=cx(),M9=fx(),j9=hx(),$9=Da();Object.defineProperty(Mo,"AlgebraTranslatorError",{enumerable:!0,get:a(function(){return $9.AlgebraTranslatorError},"get")});var _p=class{static{a(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new L9.TripleTranslator,this.expressionTranslator=new k9.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 M9.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 j9.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 gp.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 gp.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new gp.AlgebraTranslatorError("SELECT query must have WHERE clause");let t=this.patternTranslator.translateWhere(e.where);this.aggregateTranslator.resetCounter();let r=new Map,i=Array.isArray(e.variables)?e.variables.filter(l=>!("termType"in l&&l.termType==="Wildcard")):[],s=this.aggregateTranslator.extractAggregatesWithMapping(i,r),o=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,r);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 u of i)if((0,yp.isVariableExpression)(u)){if("type"in u.expression&&u.expression.type==="aggregate")continue;let f=this.aggregateTranslator.transformExpressionWithAggregateVars(u.expression,r);t={type:"extend",variable:u.variable.value,expression:f,input:t}}let l=i.filter(u=>(0,yp.isVariableTerm)(u)||(0,yp.isVariableExpression)(u)).map(u=>(0,yp.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.order&&e.order.length>0&&(t={type:"orderby",comparators:e.order.map(l=>this.aggregateTranslator.translateOrderComparator(l)),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 gp.AlgebraTranslatorError("CONSTRUCT query must have WHERE clause");let r=this.patternTranslator.translateWhere(e.where),i=e;return(i.limit!==void 0||i.offset!==void 0)&&(r={type:"slice",limit:i.limit,offset:i.offset,input:r}),{type:"construct",template:t,where:r}}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 r;e.where&&e.where.length>0&&(r=this.patternTranslator.translateWhere(e.where));let i=e.describeOptions;return{type:"describe",resources:t,where:r,depth:i?.depth,symmetric:i?.symmetric}}};Mo.ExoQLAlgebraTranslator=_p;Mo.AlgebraTranslator=_p});var us=S(Sp=>{"use strict";Object.defineProperty(Sp,"__esModule",{value:!0});Sp.SolutionMapping=void 0;var px=Ne(),mx=Ae(),gx=qt(),E1=class n{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,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof px.Literal&&t instanceof px.Literal?e.equals(t):e instanceof mx.IRI&&t instanceof mx.IRI?e.value===t.value:e instanceof gx.BlankNode&&t instanceof gx.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,r]of this.bindings.entries())e[t]=r.toString();return e}size(){return this.bindings.size}};Sp.SolutionMapping=E1});var _x=S(Wc=>{"use strict";Object.defineProperty(Wc,"__esModule",{value:!0});Wc.PropertyPathExecutor=Wc.PropertyPathExecutorError=void 0;var B9=us(),vp=Ae(),yx=qt(),U9=Ne(),ef=class extends Error{static{a(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Wc.PropertyPathExecutorError=ef;var T1=class{static{a(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){if(this.isLiteralElement(e)||this.isLiteralElement(r)){let o=this.isLiteralElement(e)?"subject":"object",c=this.isLiteralElement(e)?e:r,l="value"in c?String(c.value):"<unknown>",u=l.length>80?`${l.slice(0,77)}...`:l;console.warn(`[PropertyPathExecutor] literal-safety guard fired: literal in ${o} position \u2014 yielding 0 solutions. value="${u}"`);return}let i=await this.resolveElement(e),s=this.isVariable(r)?null:await this.resolveElement(r);for(let o of i){let c=await this.evaluatePath(o,t,s);for(let l of c){let u=new B9.SolutionMapping;this.isVariable(e)&&u.set(e.value,o),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new ef("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let o=t.merge(s);o!==null&&(yield o)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let o=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,o,c?r:null);for(let d of f)l.add(d)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,r){let i=new Set;for(let s of t){let o=await this.evaluatePathItem(e,s,r);for(let c of o)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new vp.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),o=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&o.add(c.subject);return o}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){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 h=this.nodeToKey(d);(r===null||this.nodeInSet(d,r))&&s.add(d),i.has(h)||(i.add(h),o.push({node:d,depth:u+1}))}}return s}async evaluateZeroOrMorePath(e,t,r){let i=await this.evaluateOneOrMorePath(e,t,r);return(r===null||this.nodeInSet(e,r))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,r){let i=new Set;(r===null||this.nodeInSet(e,r))&&i.add(e);let s=await this.evaluatePathItem(e,t,r);for(let o of s)i.add(o);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new vp.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),o=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&o.add(c.object);return o}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(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 r=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)r.add(s.subject),r.add(s.object);return r}let t=new Set;switch(e.type){case"iri":t.add(new vp.IRI(e.value));break;case"blank":t.add(new yx.BlankNode(e.value));break;default:throw new ef(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r){if(r instanceof vp.IRI)return{type:"iri",value:r.value};if(r instanceof yx.BlankNode)return{type:"blank",value:r.id};if(r instanceof U9.Literal)return{type:"literal",value:r.value,datatype:r.datatype?.value,language:r.language,direction:r.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 r=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===r)return!0;return!1}};Wc.PropertyPathExecutor=T1});var C1=S(Gc=>{"use strict";Object.defineProperty(Gc,"__esModule",{value:!0});Gc.BGPExecutor=Gc.BGPExecutorError=void 0;var bp=us(),jo=Ae(),A1=Ne(),wp=qt(),Ep=ku(),V9=_x(),Hr=class extends Error{static{a(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Gc.BGPExecutorError=Hr;var x1=class{static{a(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new V9.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new bp.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let r=1;r<e.triples.length;r++)t=this.joinWithPattern(t,e.triples[r]);for await(let r of t)yield r}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new bp.SolutionMapping;return}let r=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)r=this.joinWithPatternInGraph(r,e.triples[i],t);for await(let i of r)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new Hr("Property paths within named graphs are not yet supported");let r=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(r)){this.warnLiteralGuard("matchTriplePatternInGraph",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:r);return}let i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(r)?void 0:this.toRDFTermAsPredicate(r),o=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new Hr("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 bp.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let o=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(o,r)){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 r=this.isVariable(e.subject)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),i=this.isVariable(t)?void 0:this.toRDFTermAsPredicate(t),s=this.isVariable(e.object)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object)?void 0:this.toRDFTerm(e.object),o=await this.tripleStore.match(r,i,s);for(let c of o){let l=new bp.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 Ep.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,o]of i)r.set(s,o)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,o]of i)r.set(s,o)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof jo.IRI&&e.value===t.value;case"literal":return!(!(t instanceof A1.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof wp.BlankNode&&e.value===t.id;case"quoted":return t instanceof Ep.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let o of this.matchTriplePattern(s)){let c=i.merge(o);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof jo.IRI?{type:"iri",value:r.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}isLiteral(e){return e.type==="literal"}warnLiteralGuard(e,t,r){let i="value"in r?String(r.value):"<unknown>",s=i.length>80?`${i.slice(0,77)}...`:i;console.warn(`[BGPExecutor] literal-safety guard fired in ${e}: literal in ${t} position \u2014 yielding 0 solutions. value="${s}"`)}toRDFTermAsSubject(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"blank":return new wp.BlankNode(e.value);case"literal":throw new Hr("Literals cannot appear in subject position");case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new jo.IRI(e.predicate.value):(()=>{throw new Hr("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new Ep.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"literal":throw new Hr("Literals cannot appear in predicate position");case"blank":throw new Hr("Blank nodes cannot appear in predicate position");case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"literal":return new A1.Literal(e.value,e.datatype?new jo.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new wp.BlankNode(e.value);case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof jo.IRI)return{type:"iri",value:e.value};if(e instanceof A1.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof wp.BlankNode)return{type:"blank",value:e.id};if(e instanceof Ep.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new Hr(`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)}}};Gc.BGPExecutor=x1});var Sx=S(Tp=>{"use strict";Object.defineProperty(Tp,"__esModule",{value:!0});Tp.StringFunctions=void 0;var zc=Ae(),$o=Ne(),R1=qt(),tf=class n{static{a(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof zc.IRI||e instanceof $o.Literal?e.value:e instanceof R1.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof $o.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof $o.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=n.parseDirectionalLangTag(e),[s,o]=n.parseDirectionalLangTag(t),c=r.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 r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static regex(e,t,r){try{let i=r?r.includes("u")?r:r+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}static contains(e,t){return e.includes(t)}static strStarts(e,t){return e.startsWith(t)}static strEnds(e,t){return e.endsWith(t)}static strlen(e){return e.length}static ucase(e){return e.toUpperCase()}static lcase(e){return e.toLowerCase()}static substr(e,t,r){let i=t-1;if(i<0){if(r!==void 0){let s=r+i;return s<=0?"":e.substring(0,s)}return e}return r!==void 0?e.substring(i,i+r):e.substring(i)}static strBefore(e,t){if(t==="")return"";let r=e.indexOf(t);return r===-1?"":e.substring(0,r)}static strAfter(e,t){if(t==="")return e;let r=e.indexOf(t);return r===-1?"":e.substring(r+t.length)}static concat(...e){return e.join("")}static replace(e,t,r,i){try{let s=i||"g",o=s.includes("u")?s:s+"u",c=new RegExp(t,o);return e.replace(c,r)}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 r;if(e instanceof $o.Literal)r=e.value;else if(e instanceof zc.IRI)r=e.value;else if(e instanceof R1.BlankNode)r=e.id;else if(typeof e=="string")r=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof $o.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof zc.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!n.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=r.normalize(i);return new $o.Literal(s,new zc.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 $o.Literal)t=e.value;else if(e instanceof zc.IRI)t=e.value;else if(e instanceof R1.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let r=n.unicodeCaseFold(t);return new $o.Literal(r,new zc.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let r of e){let i=n.CASE_FOLDING_MAP.get(r);i!==void 0?t+=i:t+=r.toLowerCase()}return t}};Tp.StringFunctions=tf;tf.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];tf.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 vx=S(Ap=>{"use strict";Object.defineProperty(Ap,"__esModule",{value:!0});Ap.MathFunctions=void 0;var I1=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()}};Ap.MathFunctions=I1});var Cp=S(xp=>{"use strict";Object.defineProperty(xp,"__esModule",{value:!0});xp.DateTimeParsing=void 0;var q9=Ae(),W9=Ne(),P1=class n{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,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=r.indexOf("T"),o="",c="";if(s===-1?o=r:(o=r.substring(0,s),c=r.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 h=parseFloat(u[1]);i+=h*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let h=parseFloat(f[1]);i+=h*60*1e3,l=l.substring(f[0].length)}let d=l.match(/^(\d+(?:\.\d+)?)S$/);if(d){let h=parseFloat(d[1]);i+=h*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,r=Math.abs(e),i=Math.floor(r/(1440*60*1e3));r=r%(1440*60*1e3);let s=Math.floor(r/(3600*1e3));r=r%(3600*1e3);let o=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||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 n.parseDayTimeDuration(e),new W9.Literal(e,new q9.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,o=parseInt(r[3],10),c=r[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),h=parseInt(u[3],10),p=f*(d*60+h)*60*1e3;l=new Date(l.getTime()-p)}}return l}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r)return null;let i=parseInt(r[1],10),s=parseInt(r[2],10),o=parseInt(r[3],10),c=r[4],l=r[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 h=d[1]==="+"?1:-1,p=parseInt(d[2],10),y=parseInt(d[3],10),v=h*(p*60+y)*60*1e3;f-=v}}return f}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,r=Math.abs(e);return t?`-P${r}D`:`P${r}D`}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),o=parseInt(r[3]||"0",10);if(!r[2]&&!r[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,r=Math.abs(e),i=Math.floor(r/12),s=r%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)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),o=parseInt(r[3]||"0",10);if(!r[2]&&!r[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,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,o=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let 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,h=d.match(/^(\d+(?:\.\d+)?)H/);h&&(s=parseFloat(h[1]),d=d.substring(h[0].length));let p=d.match(/^(\d+(?:\.\d+)?)M/);p&&(o=parseFloat(p[1]),d=d.substring(p[0].length));let y=d.match(/^(\d+(?:\.\d+)?)S$/);if(y&&(c=parseFloat(y[1]),d=d.substring(y[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:o,seconds:c}}};xp.DateTimeParsing=P1});var bx=S(Rp=>{"use strict";Object.defineProperty(Rp,"__esModule",{value:!0});Rp.DateTimeArithmetic=void 0;var hn=Ae(),xe=Ne(),Ze=Cp(),O1=class{static{a(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r),o=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(o.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-o.getTime(),l=Ze.DateTimeParsing.formatDayTimeDuration(c);return new xe.Literal(l,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c);return new xe.Literal(l.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c);return new xe.Literal(l.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let o=Ze.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"),h=`${u}-${f}-${d}`;return new xe.Literal(h,new hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let o=Ze.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"),h=`${u}-${f}-${d}`;return new xe.Literal(h,new hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+o),s.getUTCDate()!==c&&s.setUTCDate(0),new xe.Literal(s.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-o),s.getUTCDate()!==c&&s.setUTCDate(0),new xe.Literal(s.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let o=Ze.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 hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let o=Ze.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 hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseDayTimeDuration(r),o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=Ze.DateTimeParsing.formatDayTimeDuration(s+o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseDayTimeDuration(r),o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=Ze.DateTimeParsing.formatDayTimeDuration(s-o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof xe.Literal?e.value:e,i=Ze.DateTimeParsing.parseDayTimeDuration(r),s=Ze.DateTimeParsing.formatDayTimeDuration(i*t);return new xe.Literal(s,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let r=e instanceof xe.Literal?e.value:e,i=Ze.DateTimeParsing.parseDayTimeDuration(r),s=Ze.DateTimeParsing.formatDayTimeDuration(i/t);return new xe.Literal(s,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseYearMonthDuration(r),o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=Ze.DateTimeParsing.formatYearMonthDuration(s+o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseYearMonthDuration(r),o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=Ze.DateTimeParsing.formatYearMonthDuration(s-o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/1e3}};Rp.DateTimeArithmetic=O1});var wx=S(Ip=>{"use strict";Object.defineProperty(Ip,"__esModule",{value:!0});Ip.DateTimeAccessors=void 0;var rf=Ae(),$t=Ne(),At=Cp(),F1=class{static{a(this,"DateTimeAccessors")}static year(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return t.getFullYear()}static month(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return t.getMonth()+1}static day(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return t.getDate()}static hours(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return t.getHours()}static minutes(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return t.getMinutes()}static seconds(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return t.getSeconds()+t.getMilliseconds()/1e3}static durationDays(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static durationYears(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.months:r.months}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let r;if(e.endsWith("Z"))r="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),o=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);o===0?r=`${c}PT${l}H`:r=`${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?r=`${l}PT${o}H`:r=`${l}PT${o}H${c}M`}}return new $t.Literal(r,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static tz(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TZ: invalid date string '${e}'`);if(e.endsWith("Z"))return"Z";let r=e.match(/([+-]\d{2}:\d{2})$/);if(r)return r[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static adjust(e,t){let r=e instanceof $t.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let ce=i.getUTCFullYear(),B=String(i.getUTCMonth()+1).padStart(2,"0"),V=String(i.getUTCDate()).padStart(2,"0"),F=String(i.getUTCHours()).padStart(2,"0"),k=String(i.getUTCMinutes()).padStart(2,"0"),te=String(i.getUTCSeconds()).padStart(2,"0"),Ye=i.getUTCMilliseconds(),at=`${ce}-${B}-${V}T${F}:${k}:${te}`;return Ye>0&&(at+=`.${String(Ye).padStart(3,"0")}`),new $t.Literal(at,new rf.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof $t.Literal?t.value:t,o=At.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"),h=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),y=String(u.getUTCMinutes()).padStart(2,"0"),v=String(u.getUTCSeconds()).padStart(2,"0"),b=u.getUTCMilliseconds(),w=o>=0?"+":"-",T=Math.floor(Math.abs(o)/(3600*1e3)),I=Math.floor(Math.abs(o)%(3600*1e3)/(60*1e3)),$=`${w}${String(T).padStart(2,"0")}:${String(I).padStart(2,"0")}`,q=`${f}-${d}-${h}T${p}:${y}:${v}`;return b>0&&(q+=`.${String(b).padStart(3,"0")}`),q+=$,new $t.Literal(q,new rf.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t);return r<i}static dateAfter(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t);return r>i}static dateInRange(e,t,r){let i=At.DateTimeParsing.parseDate(e),s=At.DateTimeParsing.parseDate(t),o=At.DateTimeParsing.parseDate(r);return i>=s&&i<=o}static compareDurations(e,t,r){let i=e instanceof $t.Literal?e.value:e,s=t instanceof $t.Literal?t.value:t,o=At.DateTimeParsing.parseDayTimeDuration(i),c=At.DateTimeParsing.parseDayTimeDuration(s);switch(r){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: ${r}`)}}static dateDiffMinutes(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60*60)*100)/100}static timeDiff(e,t){let r=e instanceof $t.Literal?e.value:e,i=t instanceof $t.Literal?t.value:t,s=At.DateTimeParsing.parseXSDTime(r),o=At.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(o===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-o,l=At.DateTimeParsing.formatDayTimeDuration(c);return new $t.Literal(l,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let r=e instanceof $t.Literal?e.value:e,i=t instanceof $t.Literal?t.value:t,s=At.DateTimeParsing.parseXSDDate(r),o=At.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);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=At.DateTimeParsing.formatDateDuration(l);return new $t.Literal(u,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};Ip.DateTimeAccessors=F1});var Op=S(Pp=>{"use strict";Object.defineProperty(Pp,"__esModule",{value:!0});Pp.DateTimeFunctions=void 0;var Hc=Cp(),fr=bx(),yt=wx(),D1=class{static{a(this,"DateTimeFunctions")}static parseDate(e){return Hc.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return Hc.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return Hc.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return Hc.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return Hc.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return Hc.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return yt.DateTimeAccessors.year(e)}static month(e){return yt.DateTimeAccessors.month(e)}static day(e){return yt.DateTimeAccessors.day(e)}static hours(e){return yt.DateTimeAccessors.hours(e)}static minutes(e){return yt.DateTimeAccessors.minutes(e)}static seconds(e){return yt.DateTimeAccessors.seconds(e)}static durationDays(e){return yt.DateTimeAccessors.durationDays(e)}static durationHours(e){return yt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return yt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return yt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return yt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return yt.DateTimeAccessors.durationMonths(e)}static timezone(e){return yt.DateTimeAccessors.timezone(e)}static tz(e){return yt.DateTimeAccessors.tz(e)}static adjust(e,t){return yt.DateTimeAccessors.adjust(e,t)}static now(){return yt.DateTimeAccessors.now()}static dateBefore(e,t){return yt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return yt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,r){return yt.DateTimeAccessors.dateInRange(e,t,r)}static compareDurations(e,t,r){return yt.DateTimeAccessors.compareDurations(e,t,r)}static dateDiffMinutes(e,t){return yt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return yt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return yt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return yt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return yt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return yt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return yt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return yt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return fr.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return fr.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return fr.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return fr.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return fr.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return fr.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return fr.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return fr.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return fr.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return fr.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return fr.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return fr.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return fr.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return fr.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return fr.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return fr.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return fr.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return fr.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return fr.DateTimeArithmetic.durationToSeconds(e)}};Pp.DateTimeFunctions=D1});var Ex=S(Dp=>{"use strict";Object.defineProperty(Dp,"__esModule",{value:!0});Dp.LogicalFunctions=void 0;var G9=Ae(),Qc=Ne(),z9=qt(),Fp=Op(),N1=class n{static{a(this,"LogicalFunctions")}static compare(e,t,r){if(n.isDayTimeDurationValue(e)&&n.isDayTimeDurationValue(t))return Fp.DateTimeFunctions.compareDurations(e instanceof Qc.Literal?e:String(e),t instanceof Qc.Literal?t:String(t),r);if(n.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return Fp.DateTimeFunctions.compareDurations(e instanceof Qc.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&n.isDayTimeDurationValue(t))return Fp.DateTimeFunctions.compareDurations(e,t instanceof Qc.Literal?t:String(t),r);let i=n.toComparableValue(e),s=n.toComparableValue(t);switch(r){case"=":return i===s;case"!=":return i!==s;case"<":return i<s;case">":return i>s;case"<=":return i<=s;case">=":return i>=s;default:throw new Error(`Unknown comparison operator: ${r}`)}}static isDayTimeDurationValue(e){return e instanceof Qc.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 Qc.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let r=parseFloat(e.value);if(!isNaN(r))return r}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return Fp.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof G9.IRI?e.value:e instanceof z9.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,r){return e?t:r}};Dp.LogicalFunctions=N1});var Tx=S(Np=>{"use strict";Object.defineProperty(Np,"__esModule",{value:!0});Np.RDFTermFunctions=void 0;var Mr=Ae(),bt=Ne(),pi=qt(),Kc=ku(),L1=An(),k1=class n{static{a(this,"RDFTermFunctions")}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof bt.Literal)return e.datatype?e.datatype:e.language?new Mr.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Mr.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 Mr.IRI}static isBlank(e){return e===void 0?!1:e instanceof pi.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof bt.Literal}static isTriple(e){return e===void 0?!1:e instanceof Kc.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof bt.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof bt.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 bt.Literal(t.toISOString(),new Mr.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 bt.Literal(String(t),new Mr.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 bt.Literal(String(t),new Mr.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 Mr.IRI&&t instanceof Mr.IRI)return e.value===t.value;if(e instanceof pi.BlankNode&&t instanceof pi.BlankNode)return e.id===t.id;if(e instanceof bt.Literal&&t instanceof bt.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let r=e.datatype?.value,i=t.datatype?.value;return r===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof Mr.IRI)return e;if(e instanceof bt.Literal)return new Mr.IRI(e.value);throw e instanceof pi.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return n.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,L1.v4)().replace(/-/g,"").substring(0,12)}`;return new pi.BlankNode(t)}if(e instanceof bt.Literal)return new pi.BlankNode(e.value);if(e instanceof pi.BlankNode)return e;throw new Error("BNODE: argument must be a string literal or omitted")}static strdt(e,t){if(e===void 0)throw new Error("STRDT: lexical form is undefined");if(t===void 0)throw new Error("STRDT: datatype IRI is undefined");let r;if(e instanceof bt.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof Mr.IRI)i=t;else if(t instanceof bt.Literal)i=new Mr.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new bt.Literal(r,i)}static strlang(e,t){if(e===void 0)throw new Error("STRLANG: lexical form is undefined");if(t===void 0)throw new Error("STRLANG: language tag is undefined");let r;if(e instanceof bt.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof bt.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 bt.Literal(r,void 0,i)}static strlangdir(e,t,r){if(e===void 0)throw new Error("STRLANGDIR: lexical form is undefined");if(t===void 0)throw new Error("STRLANGDIR: language tag is undefined");if(r===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof bt.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 bt.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(r instanceof bt.Literal)o=r.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 bt.Literal(i,void 0,s,o)}static uuid(){let e=(0,L1.v4)();return new Mr.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,L1.v4)();return new bt.Literal(e)}static triple(e,t,r){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(r===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof bt.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof Mr.IRI)){let c=t instanceof bt.Literal?"Literal":t instanceof pi.BlankNode?"BlankNode":t instanceof Kc.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,o=r;return new Kc.QuotedTriple(i,s,o)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.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 Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.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 Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};Np.RDFTermFunctions=k1});var Ax=S(Lp=>{"use strict";Object.defineProperty(Lp,"__esModule",{value:!0});Lp.HashFunctions=void 0;var M1=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")}};Lp.HashFunctions=M1});var Mp=S(kp=>{"use strict";Object.defineProperty(kp,"__esModule",{value:!0});kp.BuiltInFunctions=void 0;var dr=Sx(),Bo=vx(),le=Op(),Yc=Ex(),Dt=Tx(),nf=Ax(),j1=class{static{a(this,"BuiltInFunctions")}static str(...e){return dr.StringFunctions.str(...e)}static lang(...e){return dr.StringFunctions.lang(...e)}static langdir(...e){return dr.StringFunctions.langdir(...e)}static langMatches(...e){return dr.StringFunctions.langMatches(...e)}static regex(...e){return dr.StringFunctions.regex(...e)}static contains(...e){return dr.StringFunctions.contains(...e)}static strStarts(...e){return dr.StringFunctions.strStarts(...e)}static strEnds(...e){return dr.StringFunctions.strEnds(...e)}static strlen(...e){return dr.StringFunctions.strlen(...e)}static ucase(...e){return dr.StringFunctions.ucase(...e)}static lcase(...e){return dr.StringFunctions.lcase(...e)}static substr(...e){return dr.StringFunctions.substr(...e)}static strBefore(...e){return dr.StringFunctions.strBefore(...e)}static strAfter(...e){return dr.StringFunctions.strAfter(...e)}static concat(...e){return dr.StringFunctions.concat(...e)}static replace(...e){return dr.StringFunctions.replace(...e)}static encodeForUri(...e){return dr.StringFunctions.encodeForUri(...e)}static normalize(...e){return dr.StringFunctions.normalize(...e)}static fold(...e){return dr.StringFunctions.fold(...e)}static abs(...e){return Bo.MathFunctions.abs(...e)}static round(...e){return Bo.MathFunctions.round(...e)}static ceil(...e){return Bo.MathFunctions.ceil(...e)}static floor(...e){return Bo.MathFunctions.floor(...e)}static rand(){return Bo.MathFunctions.rand()}static msToMinutes(...e){return Bo.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Bo.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Bo.MathFunctions.msToSeconds(...e)}static parseDate(...e){return le.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return le.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return le.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return le.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return le.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return le.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return le.DateTimeFunctions.year(...e)}static month(...e){return le.DateTimeFunctions.month(...e)}static day(...e){return le.DateTimeFunctions.day(...e)}static hours(...e){return le.DateTimeFunctions.hours(...e)}static minutes(...e){return le.DateTimeFunctions.minutes(...e)}static seconds(...e){return le.DateTimeFunctions.seconds(...e)}static timezone(...e){return le.DateTimeFunctions.timezone(...e)}static tz(...e){return le.DateTimeFunctions.tz(...e)}static now(){return le.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return le.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return le.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return le.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return le.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return le.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return le.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return le.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return le.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return le.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return le.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return le.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return le.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return le.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return le.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return le.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return le.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return le.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return le.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return le.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return le.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return le.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return le.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return le.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return le.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return le.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return le.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return le.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return le.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return le.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return le.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return le.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return le.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return le.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return le.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return le.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return le.DateTimeFunctions.adjust(...e)}static isTime(...e){return le.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return le.DateTimeFunctions.timeDiff(...e)}static compare(...e){return Yc.LogicalFunctions.compare(...e)}static logicalAnd(...e){return Yc.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return Yc.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return Yc.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return Yc.LogicalFunctions.coalesce(...e)}static if(...e){return Yc.LogicalFunctions.if(...e)}static datatype(...e){return Dt.RDFTermFunctions.datatype(...e)}static bound(...e){return Dt.RDFTermFunctions.bound(...e)}static isIRI(...e){return Dt.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return Dt.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return Dt.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return Dt.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return Dt.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return Dt.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return Dt.RDFTermFunctions.sameTerm(...e)}static iri(...e){return Dt.RDFTermFunctions.iri(...e)}static uri(...e){return Dt.RDFTermFunctions.uri(...e)}static bnode(...e){return Dt.RDFTermFunctions.bnode(...e)}static strdt(...e){return Dt.RDFTermFunctions.strdt(...e)}static strlang(...e){return Dt.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return Dt.RDFTermFunctions.strlangdir(...e)}static uuid(){return Dt.RDFTermFunctions.uuid()}static struuid(){return Dt.RDFTermFunctions.struuid()}static xsdDateTime(...e){return Dt.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return Dt.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return Dt.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return Dt.RDFTermFunctions.triple(...e)}static subject(...e){return Dt.RDFTermFunctions.subject(...e)}static predicate(...e){return Dt.RDFTermFunctions.predicate(...e)}static object(...e){return Dt.RDFTermFunctions.object(...e)}static md5(...e){return nf.HashFunctions.md5(...e)}static sha1(...e){return nf.HashFunctions.sha1(...e)}static sha256(...e){return nf.HashFunctions.sha256(...e)}static sha384(...e){return nf.HashFunctions.sha384(...e)}static sha512(...e){return nf.HashFunctions.sha512(...e)}};kp.BuiltInFunctions=j1});var sf=S(fs=>{"use strict";Object.defineProperty(fs,"__esModule",{value:!0});fs.ExoQLBudgetExceededError=fs.ExoQLCycleError=fs.ExoQLEvalDisabledError=fs.ExoQLForbiddenKeywordError=void 0;var $1=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}};fs.ExoQLForbiddenKeywordError=$1;var B1=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"}};fs.ExoQLEvalDisabledError=B1;var U1=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}};fs.ExoQLCycleError=U1;var V1=class extends Error{static{a(this,"ExoQLBudgetExceededError")}constructor(e,t,r,i){super(i??`ExoQLBudgetExceededError: ${e} budget exceeded (limit=${t}, observed=${r})`),this.name="ExoQLBudgetExceededError",this.budget=e,this.limit=t,this.observed=r}};fs.ExoQLBudgetExceededError=V1});var Nx=S(j=>{"use strict";Object.defineProperty(j,"__esModule",{value:!0});j.functionHandlers=void 0;var M=Mp();j.functionHandlers=new Map;j.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.str(t)});j.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.lang(t)});j.functionHandlers.set("langmatches",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.langMatches(t,r)});j.functionHandlers.set("contains",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.contains(t,r)});j.functionHandlers.set("strstarts",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strStarts(t,r)});j.functionHandlers.set("strends",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strEnds(t,r)});j.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.strlen(t)});j.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.ucase(t)});j.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.lcase(t)});j.functionHandlers.set("substr",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=Number(e.evaluateExpression(n[1],e.solution));if(n[2]){let i=Number(e.evaluateExpression(n[2],e.solution));return M.BuiltInFunctions.substr(t,r,i)}return M.BuiltInFunctions.substr(t,r)});j.functionHandlers.set("strbefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strBefore(t,r)});j.functionHandlers.set("strafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strAfter(t,r)});j.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return M.BuiltInFunctions.concat(...t)});j.functionHandlers.set("replace",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution)),s=n[3]?e.getStringValue(e.evaluateExpression(n[3],e.solution)):void 0;return M.BuiltInFunctions.replace(t,r,i,s)});j.functionHandlers.set("regex",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=n[2]?e.getStringValue(e.evaluateExpression(n[2],e.solution)):void 0;return M.BuiltInFunctions.regex(t,r,i)});j.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.encodeForUri(t)});j.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.datatype(t).value});j.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return M.BuiltInFunctions.bound(r)}return!0});var xx=a((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isIRI(t)},"isIriHandler");j.functionHandlers.set("isiri",xx);j.functionHandlers.set("isuri",xx);j.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isBlank(t)});j.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isLiteral(t)});j.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isNumeric(t)});j.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.hasLangdir(t)});j.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isTriple(t)});j.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return M.BuiltInFunctions.sameTerm(t,r)});j.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.abs(t)});j.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.round(t)});j.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.ceil(t)});j.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.floor(t)});j.functionHandlers.set("rand",()=>M.BuiltInFunctions.rand());j.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.parseDate(t)});j.functionHandlers.set("datebefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateBefore(t,r)});j.functionHandlers.set("dateafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateAfter(t,r)});j.functionHandlers.set("dateinrange",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution));return M.BuiltInFunctions.dateInRange(t,r,i)});j.functionHandlers.set("datediffminutes",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateDiffMinutes(t,r)});j.functionHandlers.set("datediffhours",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateDiffHours(t,r)});var Xc=a((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),Cx=Xc(M.BuiltInFunctions.year.bind(M.BuiltInFunctions),M.BuiltInFunctions.durationYears.bind(M.BuiltInFunctions),null);j.functionHandlers.set("year",Cx);j.functionHandlers.set("years",Cx);var Rx=Xc(M.BuiltInFunctions.month.bind(M.BuiltInFunctions),M.BuiltInFunctions.durationMonths.bind(M.BuiltInFunctions),null);j.functionHandlers.set("month",Rx);j.functionHandlers.set("months",Rx);var Ix=Xc(M.BuiltInFunctions.day.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationDays.bind(M.BuiltInFunctions));j.functionHandlers.set("day",Ix);j.functionHandlers.set("days",Ix);j.functionHandlers.set("hours",Xc(M.BuiltInFunctions.hours.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationHours.bind(M.BuiltInFunctions)));j.functionHandlers.set("minutes",Xc(M.BuiltInFunctions.minutes.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationMinutes.bind(M.BuiltInFunctions)));j.functionHandlers.set("seconds",Xc(M.BuiltInFunctions.seconds.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationSeconds.bind(M.BuiltInFunctions)));j.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.timezone(t)});j.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.tz(t)});j.functionHandlers.set("adjust",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=n.length>1?e.evaluateExpression(n[1],e.solution):void 0;return M.BuiltInFunctions.adjust(t,r)});j.functionHandlers.set("now",()=>M.BuiltInFunctions.now());var Px=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");j.functionHandlers.set("datetime",Px);j.functionHandlers.set("xsd:datetime",Px);var Ox=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");j.functionHandlers.set("integer",Ox);j.functionHandlers.set("xsd:integer",Ox);var Fx=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");j.functionHandlers.set("decimal",Fx);j.functionHandlers.set("xsd:decimal",Fx);var Dx=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");j.functionHandlers.set("daytimeduration",Dx);j.functionHandlers.set("xsd:daytimeduration",Dx);j.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToDays(t)});j.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToHours(t)});j.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToMinutes(t)});j.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToSeconds(t)});j.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationDays(t)});j.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationHours(t)});j.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationMinutes(t)});j.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationSeconds(t)});j.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationYears(t)});j.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationMonths(t)});j.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeDiff(t,r)});j.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeAdd(t,r)});j.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeSubtract(t,r)});j.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToMinutes(t)});j.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToHours(t)});j.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToSeconds(t)});j.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.md5(t)});j.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha1(t)});j.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha256(t)});j.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha384(t)});j.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha512(t)});j.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.subject(t)});j.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.predicate(t)});j.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.object(t)});j.functionHandlers.set("triple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution),i=e.getTermFromExpression(n[2],e.solution);return M.BuiltInFunctions.triple(t,r,i)});j.functionHandlers.set("days_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t),s=new Date(r);return Math.floor((s.getTime()-i.getTime())/(1440*60*1e3))});j.functionHandlers.set("minutes_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t),s=new Date(r);return Math.floor((s.getTime()-i.getTime())/(60*1e3))});j.functionHandlers.set("hours_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t);return(new Date(r).getTime()-i.getTime())/(3600*1e3)});j.functionHandlers.set("age_days",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=new Date(t);return Math.floor((new Date().getTime()-r.getTime())/(1440*60*1e3))});j.functionHandlers.set("week_number",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=new Date(t),i=new Date(Date.UTC(r.getFullYear(),r.getMonth(),r.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)});j.functionHandlers.set("format_date",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t);return r.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"))});j.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:n}=sf();throw new n})});var jp=S(Jc=>{"use strict";Object.defineProperty(Jc,"__esModule",{value:!0});Jc.FilterExecutor=Jc.FilterExecutorError=void 0;var _t=Mp(),H9=Nx(),q1=Ae(),ds=Ne(),vr=class extends Error{static{a(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Jc.FilterExecutorError=vr;var W1=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 r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||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(r=>this.expressionContainsExists(r))}if(e.type==="function"||e.type==="functionCall"){let t=e;return Array.isArray(t.args)?t.args.some(r=>this.expressionContainsExists(r)):!1}return!1}async executeAll(e,t){let r=[];async function*i(){for(let s of t)yield s}a(i,"generator");for await(let s of this.execute(e,i()))r.push(s);return r}evaluateExpression(e,t){let r=e;if("termType"in e)switch(r.termType){case"Variable":return t.get(r.value);case"Literal":{let i=r.value,s=r.datatype,o=typeof s=="string"?s:s?.value;return o&&i.length>0&&this.shouldPreserveDatatype(o)?new ds.Literal(i,new q1.IRI(o)):i}case"NamedNode":return r.value;default:throw new vr(`Unsupported termType: ${String(r.termType)}`)}switch(e.type){case"comparison":return this.evaluateComparison(e,t);case"logical":return this.evaluateLogical(e,t);case"arithmetic":return this.evaluateArithmetic(e,t);case"function":case"functionCall":return this.evaluateFunction(e,t);case"variable":return t.get(e.name);case"literal":{let i=e;return i.datatype&&i.value.length>0&&this.shouldPreserveDatatype(i.datatype)?new ds.Literal(i.value,new q1.IRI(i.datatype)):i.value}case"in":return this.evaluateIn(e,t);case"exists":throw new vr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new vr(`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 r=e,i=await this.evaluateExpressionAsync(r.left,t),s=await this.evaluateExpressionAsync(r.right,t);return _t.BuiltInFunctions.compare(i,s,r.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 vr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let r=await this.existsEvaluator(e.pattern,t);return e.negated?!r:r}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let i=await this.evaluateExpressionAsync(e.operands[0],t);return _t.BuiltInFunctions.logicalNot(i)}let r=[];for(let i of e.operands){let s=await this.evaluateExpressionAsync(i,t);r.push(s)}if(e.operator==="&&")return _t.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return _t.BuiltInFunctions.logicalOr(r);throw new vr(`Unknown logical operator: ${String(e.operator)}`)}async evaluateInAsync(e,t){let r=await this.evaluateExpressionAsync(e.expression,t),i=!1;for(let s of e.list){let o=await this.evaluateExpressionAsync(s,t);if(_t.BuiltInFunctions.compare(r,o,"=")){i=!0;break}}return e.negated?!i:i}async evaluateFunctionAsync(e,t){let r=e,i=this.extractFunctionName(r.function),s=r.args??[];if(i==="if"){if(s.length!==3)throw new vr("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={...r,args:o};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:e!==null&&typeof e=="object"&&"termType"in e?e:e instanceof q1.IRI||e instanceof ds.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 r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return _t.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return _t.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return _t.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return _t.BuiltInFunctions.logicalOr(r);throw new vr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let o=this.evaluateExpression(s,t);return _t.BuiltInFunctions.compare(r,o,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return _t.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return _t.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return _t.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return _t.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return _t.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new vr("Division by zero");return _t.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),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 vr("Division by zero");return s/o;default:throw new vr(`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 ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof ds.Literal){let t=e.datatype?.value||"";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let i=parseFloat(e.value);if(!isNaN(i))return i}let r=parseFloat(e.value);if(!isNaN(r))return r}if(typeof e=="string"){let t=parseFloat(e);if(!isNaN(t))return t}if(e&&typeof e=="object"&&"value"in e){let t=parseFloat(String(e.value));if(!isNaN(t))return t}throw new vr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof ds.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 ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let o=H9.functionHandlers.get(i);if(!o)throw new vr(`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(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new vr(`Unknown function format: ${String(e)}`)}evaluateSpecialFunction(e,t,r){switch(e){case"coalesce":for(let i of t)try{let s=this.evaluateExpression(i,r);if(s!=null)return{value:s}}catch{continue}return{value:void 0};case"if":{if(!t||t.length!==3)throw new vr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],r);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],r):this.evaluateExpression(t[2],r)}}case"byuuid":return{value:this.evaluateByUUID({type:"function",function:"byuuid",args:t},r)};default:return}}getTermFromExpression(e,t){let r=e;if(r.type==="variable"&&r.name)return t.get(r.name)}getStringValue(e){return e==null?"":typeof e=="object"&&"value"in e?String(e.value):String(e)}toBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="number")return!isNaN(e)&&e!==0;if(typeof e=="string")return e.length>0;if(e instanceof ds.Literal){let t=e.datatype?.value||"";if(t.includes("#boolean"))return e.value==="true"||e.value==="1";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let r=parseFloat(e.value);return!isNaN(r)&&r!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new vr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let 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 r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Jc.FilterExecutor=W1});var z1=S($p=>{"use strict";Object.defineProperty($p,"__esModule",{value:!0});$p.OptionalExecutor=void 0;var G1=class{static{a(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let 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 h of f){let p=l.merge(h);p!==null&&(yield p,d=!0)}d||(yield l)}}computeHashKey(e,t,r){let i=[];for(let s of t){let o=e.get(s);i.push(o!==void 0?o.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let o=r.merge(s);o!==null&&(yield o,i=!0)}i||(yield r)}}};$p.OptionalExecutor=G1});var Q1=S(Bp=>{"use strict";Object.defineProperty(Bp,"__esModule",{value:!0});Bp.UnionExecutor=void 0;var H1=class{static{a(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let 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()))r.push(o);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Bp.UnionExecutor=H1});var Lx=S(Up=>{"use strict";Object.defineProperty(Up,"__esModule",{value:!0});Up.MinusExecutor=void 0;var K1=class{static{a(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let o=!1;for(let c of i)if(this.areCompatible(s,c)){o=!0;break}o||(yield s)}}async executeAll(e,t){let r=[];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()))r.push(o);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.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}};Up.MinusExecutor=K1});var Mx=S(Zc=>{"use strict";Object.defineProperty(Zc,"__esModule",{value:!0});Zc.ValuesExecutor=Zc.ValuesExecutorError=void 0;var Q9=us(),kx=Ae(),K9=Ne(),Vp=class extends Error{static{a(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Zc.ValuesExecutorError=Vp;var Y1=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 r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new Q9.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(r,s)}return t}toRDFTerm(e){if(e.type==="iri")return new kx.IRI(e.value);if(e.type==="literal")return new K9.Literal(e.value,e.datatype?new kx.IRI(e.datatype):void 0,e.language,e.direction);throw new Vp(`Unknown term type: ${e.type}`)}};Zc.ValuesExecutor=Y1});var X1=S(tl=>{"use strict";Object.defineProperty(tl,"__esModule",{value:!0});tl.CustomAggregateRegistry=tl.CustomAggregateError=void 0;var el=class extends Error{static{a(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};tl.CustomAggregateError=el;var qp=class n{static{a(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new el("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new el("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new el(`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}};tl.CustomAggregateRegistry=qp;qp.instance=null});var J1=S(et=>{"use strict";Object.defineProperty(et,"__esModule",{value:!0});et.BUILT_IN_AGGREGATES=et.modeAggregate=et.stddevAggregate=et.varianceAggregate=et.medianAggregate=et.EXO_AGGREGATE_NS=void 0;et.getNumericValue=Wp;et.createDecimalLiteral=mi;et.createDoubleLiteral=J9;et.createPercentileAggregate=Na;var La=Ne(),rl=Ae(),Y9=new rl.IRI("http://www.w3.org/2001/XMLSchema#decimal"),X9=new rl.IRI("http://www.w3.org/2001/XMLSchema#double");et.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Wp(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof La.Literal?parseFloat(n.value):n instanceof rl.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}a(Wp,"getNumericValue");function mi(n){return new La.Literal(String(n),Y9)}a(mi,"createDecimalLiteral");function J9(n){return new La.Literal(String(n),X9)}a(J9,"createDoubleLiteral");et.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Wp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=[...t].sort((o,c)=>o-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return mi(s)}};et.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Wp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-r,2),0)/t.length;return mi(i)}};et.stddevAggregate={init(){return{values:[]}},step(n,e){et.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-r,2),0)/t.length;return mi(Math.sqrt(i))}};et.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof La.Literal||e instanceof rl.IRI?e.value:e),i=t.counts.get(r)||0;t.counts.set(r,i+1),t.values.set(r,e)},finalize(n){let e=n;if(e.counts.size===0)return new La.Literal(" ",new rl.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[o,c]of e.counts)c>r&&(r=c,t=o);let i=e.values.get(t);if(i instanceof La.Literal)return i;let s=parseFloat(t);return isNaN(s)?new La.Literal(t,new rl.IRI("http://www.w3.org/2001/XMLSchema#string")):mi(s)}};function Na(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Wp(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return mi(0);let s=[...i].sort((d,h)=>d-h),o=r.percentile*(s.length-1),c=Math.floor(o),l=Math.ceil(o);if(c===l)return mi(s[c]);let u=o-c,f=s[c]*(1-u)+s[l]*u;return mi(f)}}}a(Na,"createPercentileAggregate");et.BUILT_IN_AGGREGATES={[`${et.EXO_AGGREGATE_NS}median`]:et.medianAggregate,[`${et.EXO_AGGREGATE_NS}variance`]:et.varianceAggregate,[`${et.EXO_AGGREGATE_NS}stddev`]:et.stddevAggregate,[`${et.EXO_AGGREGATE_NS}mode`]:et.modeAggregate,[`${et.EXO_AGGREGATE_NS}percentile25`]:Na(25),[`${et.EXO_AGGREGATE_NS}percentile50`]:Na(50),[`${et.EXO_AGGREGATE_NS}percentile75`]:Na(75),[`${et.EXO_AGGREGATE_NS}percentile90`]:Na(90),[`${et.EXO_AGGREGATE_NS}percentile95`]:Na(95),[`${et.EXO_AGGREGATE_NS}percentile99`]:Na(99)}});var Bx=S(nl=>{"use strict";Object.defineProperty(nl,"__esModule",{value:!0});nl.AggregateExecutor=nl.AggregateExecutorError=void 0;var hr=Ne(),eS=Ae(),Z9=jp(),e5=X1(),t5=J1(),jx=new eS.IRI("http://www.w3.org/2001/XMLSchema#integer"),ka=new eS.IRI("http://www.w3.org/2001/XMLSchema#decimal"),hs=new eS.IRI("http://www.w3.org/2001/XMLSchema#string");function $x(n){return typeof n=="object"&&n.type==="custom"}a($x,"isCustomAggregation");var of=class extends Error{static{a(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};nl.AggregateExecutorError=of;var Z1=class{static{a(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Z9.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,o]of r.entries()){let c=new Map;for(let f of e.variables)if(o.length>0){let d=o[0].get(f);d&&c.set(f,d)}for(let f of e.aggregates){let d=this.computeAggregate(f.expression,o);c.set(f.variable,d)}let{SolutionMapping:l}=us(),u=new l;for(let[f,d]of c.entries())u.set(f,d);i.push(u)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let r=new Map;if(t.length===0)return r.set("",e),r;for(let i of e){let s=this.computeGroupKey(i,t),o=r.get(s);o?o.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if($x(e.aggregation))return this.computeCustomAggregate(e,t);let r=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(r,e.distinct);return new hr.Literal(String(s),jx)}case"sum":{let s=this.computeSum(r);return new hr.Literal(String(s),ka)}case"avg":{let s=this.computeAvg(r);return new hr.Literal(String(s),ka)}case"min":{let s=this.computeMin(r);return s===void 0?new hr.Literal("",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}case"max":{let s=this.computeMax(r);return s===void 0?new hr.Literal("",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new hr.Literal(s||" ",hs)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new hr.Literal(" ",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}default:{let s=i;throw new of(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,o=e5.CustomAggregateRegistry.getInstance().get(i);if(o||(o=t5.BUILT_IN_AGGREGATES[i]),!o)throw new of(`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 f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;o.step(c,u)}return o.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let o=s[0],c=parseFloat(o);return isNaN(c)?o:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=us(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if($x(s)){r.set(i.variable,new hr.Literal("0",ka));continue}switch(s){case"count":r.set(i.variable,new hr.Literal("0",jx));break;case"sum":case"avg":r.set(i.variable,new hr.Literal("0",ka));break;case"group_concat":r.set(i.variable,new hr.Literal(" ",hs));break;case"min":case"max":case"sample":r.set(i.variable,new hr.Literal("",hs));break;default:r.set(i.variable,new hr.Literal("",hs))}}return r}};nl.AggregateExecutor=Z1});var iS=S(Gp=>{"use strict";Object.defineProperty(Gp,"__esModule",{value:!0});Gp.ConstructExecutor=void 0;var r5=Yn(),Ma=Ae(),tS=Ne(),rS=qt(),n5=ku(),nS=class{static{a(this,"ConstructExecutor")}async execute(e,t){let r=[],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),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new r5.Triple(r,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable: ${e.value}`);return r}if(e.type==="iri")return new Ma.IRI(e.value);if(e.type==="literal")return new tS.Literal(e.value,e.datatype?new Ma.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let r=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new n5.QuotedTriple(r,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(r instanceof tS.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new Ma.IRI(e.value);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Invalid element type for quoted triple subject: ${e.type}`)}instantiateQuotedPredicate(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(r instanceof Ma.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new Ma.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 Ma.IRI(e.value);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="literal")return new tS.Literal(e.value,e.datatype?new Ma.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let r=e;throw new Error(`Invalid element type for quoted triple object: ${r.type}`)}};Gp.ConstructExecutor=nS});var Vx=S(il=>{"use strict";Object.defineProperty(il,"__esModule",{value:!0});il.ServiceExecutor=il.ServiceExecutorError=void 0;var i5=us(),Ux=Ae(),s5=Ne(),o5=qt(),ja=class extends Error{static{a(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};il.ServiceExecutorError=ja;var sS=class{static{a(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,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 ja(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(o)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new ja(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new ja(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,r)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new i5.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(r,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new Ux.IRI(e.value);case"literal":{let t=e.datatype?new Ux.IRI(e.datatype):void 0;return new s5.Literal(e.value,t,e["xml:lang"])}case"bnode":return new o5.BlankNode(e.value);default:throw new ja(`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))}};il.ServiceExecutor=sS});var Wx=S(sl=>{"use strict";Object.defineProperty(sl,"__esModule",{value:!0});sl.GraphExecutor=sl.GraphExecutorError=void 0;var qx=Ae(),zp=class extends Error{static{a(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};sl.GraphExecutorError=zp;var oS=class{static{a(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new zp(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new qx.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let o=i.get(t.value);if(o&&o instanceof qx.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:o.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let o of s)for await(let c of r(e.pattern,o)){let l=c.clone();l.set(t.value,o),yield l}}};sl.GraphExecutor=oS});var Gx=S(al=>{"use strict";Object.defineProperty(al,"__esModule",{value:!0});al.SPARQLGenerator=al.SPARQLGeneratorError=void 0;var ol=class extends Error{static{a(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};al.SPARQLGeneratorError=ol;var aS=class{static{a(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
|
|
48
|
+
`,s);l!==-1?(i+=e.substring(s,l),s=l):(i+=e.substring(s),s=e.length);continue}let c=this.tryReplacePrefixedName(e,s,r);if(c){i+=c.iri,s=c.endIndex;continue}i+=o,s++}return i}tryReplacePrefixedName(e,t,r){if(t>0&&/[a-zA-Z0-9_]/.test(e[t-1]))return null;for(let{prefix:i,baseIRI:s}of r){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,r=new RegExp(S9.source,"gi"),i;for(;(i=r.exec(e))!==null;)t.add(i[1].toLowerCase());return t}skipLiteral(e,t){let r=e[t];if(t+2<e.length&&e.substring(t,t+3)===r+r+r){let s=e.indexOf(r+r+r,t+3);return s!==-1?s+3:e.length}let i=t+1;for(;i<e.length&&e[i]!==r;)e[i]==="\\"&&i++,i++;return i<e.length?i+1:e.length}};cp.VaultPrefixTransformer=d1});var Uc=S(Rn=>{"use strict";var b9=Rn&&Rn.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=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(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),w9=Rn&&Rn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),E9=Rn&&Rn.__importStar||(function(){var n=a(function(e){return n=Object.getOwnPropertyNames||function(t){var r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[r.length]=i);return r},n(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=n(e),i=0;i<r.length;i++)r[i]!=="default"&&b9(t,e,r[i]);return w9(t,e),t}})();Object.defineProperty(Rn,"__esModule",{value:!0});Rn.SPARQLParser=Rn.ExoQLParser=Rn.SPARQLParseError=void 0;var sx=E9(tx()),p1=o1(),m1=a1(),ox=rx(),g1=l1(),T9=nx(),y1=ix(),A9=h1(),ur=class extends Error{static{a(this,"SPARQLParseError")}constructor(e,t,r,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=r}};Rn.SPARQLParseError=ur;var lp=class{static{a(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new sx.Parser({sparqlStar:!0}),this.generator=new sx.Generator({sparqlStar:!0}),this.caseWhenTransformer=new p1.CaseWhenTransformer,this.lateralTransformer=new m1.LateralTransformer,this.prefixStarTransformer=new ox.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new g1.DescribeOptionsTransformer,this.directionalLangTagTransformer=new T9.DirectionalLangTagTransformer,this.tripleTermTransformer=new y1.TripleTermTransformer,this.vaultPrefixTransformer=new A9.VaultPrefixTransformer}setVaultPrefixes(e){this.vaultPrefixTransformer.setVaultPrefixes(e)}parse(e){try{let t=this.vaultPrefixTransformer.transform(e),r=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=r.options;let i=r.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 g1.DescribeOptionsTransformerError)throw new ur(t.message);if(t instanceof m1.LateralTransformerError)throw new ur(t.message);if(t instanceof p1.CaseWhenTransformerError)throw new ur(t.message);if(t instanceof y1.TripleTermTransformerError)throw new ur(t.message);if(t instanceof Error){let r=t.message.match(/line (\d+), column (\d+)/),i=r?parseInt(r[1],10):void 0,s=r?parseInt(r[2],10):void 0;throw new ur(`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),r=this.describeOptionsTransformer.transform(t);this.lastDescribeOptions=r.options;let i=r.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 g1.DescribeOptionsTransformerError)throw new ur(t.message);if(t instanceof ox.PrefixStarTransformerError)throw new ur(t.message);if(t instanceof m1.LateralTransformerError)throw new ur(t.message);if(t instanceof p1.CaseWhenTransformerError)throw new ur(t.message);if(t instanceof y1.TripleTermTransformerError)throw new ur(t.message);if(t instanceof Error){let r=t.message.match(/line (\d+), column (\d+)/),i=r?parseInt(r[1],10):void 0,s=r?parseInt(r[2],10):void 0;throw new ur(`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 ur(`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 ur("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 ur("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new ur(`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 ur(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};Rn.ExoQLParser=lp;Rn.SPARQLParser=lp});var Da=S(up=>{"use strict";Object.defineProperty(up,"__esModule",{value:!0});up.AlgebraTranslatorError=void 0;var _1=class extends Error{static{a(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};up.AlgebraTranslatorError=_1});var fp=S(ls=>{"use strict";Object.defineProperty(ls,"__esModule",{value:!0});ls.isVariableExpression=x9;ls.isVariableTerm=C9;ls.isNamedNode=R9;ls.isLiteral=I9;ls.isPropertyPath=P9;ls.isAggregateExpression=O9;ls.isOperationExpression=F9;ls.isFunctionCallExpression=D9;function x9(n){return typeof n=="object"&&n!==null&&"expression"in n&&"variable"in n}a(x9,"isVariableExpression");function C9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Variable"}a(C9,"isVariableTerm");function R9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="NamedNode"}a(R9,"isNamedNode");function I9(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Literal"}a(I9,"isLiteral");function P9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="path"}a(P9,"isPropertyPath");function O9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="aggregate"}a(O9,"isAggregateExpression");function F9(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="operation"}a(F9,"isOperationExpression");function D9(n){return typeof n=="object"&&n!==null&&"type"in n&&(n.type==="functionCall"||n.type==="functioncall")}a(D9,"isFunctionCallExpression")});var ax=S(dp=>{"use strict";Object.defineProperty(dp,"__esModule",{value:!0});dp.TripleTranslator=void 0;var dn=Da(),S1=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 dn.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 dn.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 dn.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new dn.AlgebraTranslatorError("Property path must have items array");let t=e.items.map(r=>this.translatePathItem(r));switch(e.pathType){case"/":return{type:"path",pathType:"/",items:t};case"|":return{type:"path",pathType:"|",items:t};case"^":if(t.length!==1)throw new dn.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new dn.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new dn.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new dn.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new dn.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 dn.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new dn.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 r=this.directionMappings.get(e.language.toLowerCase());r&&(t.direction=r)}return t}case"BlankNode":return{type:"blank",value:e.value};case"Quad":return this.translateQuotedTriple(e);default:throw new dn.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new dn.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 dn.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 dn.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};dp.TripleTranslator=S1});var cx=S(hp=>{"use strict";Object.defineProperty(hp,"__esModule",{value:!0});hp.ExpressionTranslator=void 0;var Vc=Da(),v1=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 Vc.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 r=e;return{type:"functionCall",function:r.function,args:r.args.map(i=>this.translateExpression(i))}}if("termType"in e)return this.translateTermExpression(e);throw new Vc.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Vc.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=["=","!=","<",">","<=",">="],r=["&&","||","!"],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])}:r.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 Vc.AlgebraTranslatorError("EXISTS/NOT EXISTS must have exactly one pattern argument");let t=e.args[0],r;return t.type==="group"&&"patterns"in t&&t.patterns?r=this.translateWhereFn(t.patterns):t.type==="bgp"?r=this.translateBGPFn(t):r=this.translatePatternFn(t),{type:"exists",negated:e.operator==="notexists",pattern:r}}translateInExpression(e){if(!e.args||e.args.length!==2)throw new Vc.AlgebraTranslatorError("IN/NOT IN must have exactly 2 arguments (expression and list)");let t=e.args[0],r=e.args[1];if(!Array.isArray(r))throw new Vc.AlgebraTranslatorError("IN/NOT IN second argument must be an array of values");return{type:"in",expression:this.translateExpression(t),list:r.map(i=>this.translateExpression(i)),negated:e.operator==="notin"}}};hp.ExpressionTranslator=v1});var fx=S(pp=>{"use strict";Object.defineProperty(pp,"__esModule",{value:!0});pp.PatternTranslator=void 0;var lx=a1(),kr=Da(),ux=fp(),b1=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 kr.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(o=>o.type==="filter"),r=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{let l=this.translatePattern(c);s={type:"join",left:s,right:l}}}}for(let o of r)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 kr.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 kr.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new kr.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 kr.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 kr.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"),r={type:"union",left:t(e.patterns[0]),right:t(e.patterns[1])};for(let i=2;i<e.patterns.length;i++)r={type:"union",left:r,right:t(e.patterns[i])};return r}translateMinus(e){if(!e.patterns||e.patterns.length===0)throw new kr.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 kr.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 r=e.values.map(i=>this.translateValuesBinding(i));return{type:"values",variables:Array.from(t),bindings:r}}translateValuesBinding(e){let t={};for(let[r,i]of Object.entries(e)){let s=r.startsWith("?")?r.slice(1):r,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 kr.AlgebraTranslatorError(`Unsupported VALUES term type: ${o.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new kr.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 kr.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 kr.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new kr.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 kr.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new kr.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 kr.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 kr.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,ux.isVariableTerm)(i)&&i.value===lx.LateralTransformer.LATERAL_MARKER)}removeLateralMarker(e){if(!("variables"in e)||!e.variables)return e;let t=e,r=t.variables;return{...t,variables:r.filter(i=>!((0,ux.isVariableTerm)(i)&&i.value===lx.LateralTransformer.LATERAL_MARKER))}}};pp.PatternTranslator=b1});var hx=S(mp=>{"use strict";Object.defineProperty(mp,"__esModule",{value:!0});mp.AggregateTranslator=void 0;var dx=Da(),N9=fp(),w1=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 r=[];for(let i of e)(0,N9.isVariableExpression)(i)&&("type"in i.expression&&i.expression.type==="aggregate"?(r.push({variable:i.variable.value,expression:this.translateAggregateExpression(i.expression)}),t.set(i.expression,i.variable.value)):this.collectNestedAggregates(i.expression,r,t));return r}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,r){if(!e||e.length===0)return[];for(let i of e)this.collectNestedAggregates(i,t,r);return e.map(i=>this.transformExpressionWithAggregateVars(i,r))}transformExpressionWithAggregateVars(e,t){let r=t.get(e);if(r!==void 0)return{type:"variable",name:r};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,r=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:r(),distinct:e.distinct||!1,separator:e.separator}:{type:"aggregate",aggregation:{type:"custom",iri:t},expression:r(),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 dx.AlgebraTranslatorError(`Invalid custom aggregate: expected IRI but got ${JSON.stringify(i)}`);return{type:"aggregate",aggregation:{type:"custom",iri:s},expression:r(),distinct:e.distinct||!1,separator:e.separator}}throw new dx.AlgebraTranslatorError(`Unknown aggregate format: ${JSON.stringify(t)}`)}collectNestedAggregates(e,t,r){if(e){if("type"in e&&e.type==="aggregate"){let i=`__agg${this.aggregateCounter++}`;t.push({variable:i,expression:this.translateAggregateExpression(e)}),r.set(e,i)}else if("type"in e&&e.type==="operation"&&"args"in e){let i=e;for(let s of i.args)!Array.isArray(s)&&"type"in s&&!("patterns"in s)?this.collectNestedAggregates(s,t,r):"termType"in s&&this.collectNestedAggregates(s,t,r)}}}};mp.AggregateTranslator=w1});var qc=S(Mo=>{"use strict";Object.defineProperty(Mo,"__esModule",{value:!0});Mo.AlgebraTranslator=Mo.ExoQLAlgebraTranslator=Mo.AlgebraTranslatorError=void 0;var gp=Da(),yp=fp(),L9=ax(),k9=cx(),M9=fx(),j9=hx(),$9=Da();Object.defineProperty(Mo,"AlgebraTranslatorError",{enumerable:!0,get:a(function(){return $9.AlgebraTranslatorError},"get")});var _p=class{static{a(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new L9.TripleTranslator,this.expressionTranslator=new k9.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 M9.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 j9.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 gp.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 gp.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new gp.AlgebraTranslatorError("SELECT query must have WHERE clause");let t=this.patternTranslator.translateWhere(e.where);this.aggregateTranslator.resetCounter();let r=new Map,i=Array.isArray(e.variables)?e.variables.filter(l=>!("termType"in l&&l.termType==="Wildcard")):[],s=this.aggregateTranslator.extractAggregatesWithMapping(i,r),o=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,r);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 u of i)if((0,yp.isVariableExpression)(u)){if("type"in u.expression&&u.expression.type==="aggregate")continue;let f=this.aggregateTranslator.transformExpressionWithAggregateVars(u.expression,r);t={type:"extend",variable:u.variable.value,expression:f,input:t}}let l=i.filter(u=>(0,yp.isVariableTerm)(u)||(0,yp.isVariableExpression)(u)).map(u=>(0,yp.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.order&&e.order.length>0&&(t={type:"orderby",comparators:e.order.map(l=>this.aggregateTranslator.translateOrderComparator(l)),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 gp.AlgebraTranslatorError("CONSTRUCT query must have WHERE clause");let r=this.patternTranslator.translateWhere(e.where),i=e;return(i.limit!==void 0||i.offset!==void 0)&&(r={type:"slice",limit:i.limit,offset:i.offset,input:r}),{type:"construct",template:t,where:r}}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 r;e.where&&e.where.length>0&&(r=this.patternTranslator.translateWhere(e.where));let i=e.describeOptions;return{type:"describe",resources:t,where:r,depth:i?.depth,symmetric:i?.symmetric}}};Mo.ExoQLAlgebraTranslator=_p;Mo.AlgebraTranslator=_p});var us=S(Sp=>{"use strict";Object.defineProperty(Sp,"__esModule",{value:!0});Sp.SolutionMapping=void 0;var px=Ne(),mx=Ae(),gx=qt(),E1=class n{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,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof px.Literal&&t instanceof px.Literal?e.equals(t):e instanceof mx.IRI&&t instanceof mx.IRI?e.value===t.value:e instanceof gx.BlankNode&&t instanceof gx.BlankNode?e.id===t.id:!1}toJSON(){let e={};for(let[t,r]of this.bindings.entries())e[t]=r.toString();return e}size(){return this.bindings.size}};Sp.SolutionMapping=E1});var _x=S(Wc=>{"use strict";Object.defineProperty(Wc,"__esModule",{value:!0});Wc.PropertyPathExecutor=Wc.PropertyPathExecutorError=void 0;var B9=us(),vp=Ae(),yx=qt(),U9=Ne(),ef=class extends Error{static{a(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Wc.PropertyPathExecutorError=ef;var T1=class{static{a(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){if(this.isLiteralElement(e)||this.isLiteralElement(r)){let o=this.isLiteralElement(e)?"subject":"object",c=this.isLiteralElement(e)?e:r,l="value"in c?String(c.value):"<unknown>",u=l.length>80?`${l.slice(0,77)}...`:l;console.warn(`[PropertyPathExecutor] literal-safety guard fired: literal in ${o} position \u2014 yielding 0 solutions. value="${u}"`);return}let i=await this.resolveElement(e),s=this.isVariable(r)?null:await this.resolveElement(r);for(let o of i){let c=await this.evaluatePath(o,t,s);for(let l of c){let u=new B9.SolutionMapping;this.isVariable(e)&&u.set(e.value,o),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new ef("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let o=t.merge(s);o!==null&&(yield o)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let o=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,o,c?r:null);for(let d of f)l.add(d)}if(i=l,i.size===0)break}return i}async evaluateAlternativePath(e,t,r){let i=new Set;for(let s of t){let o=await this.evaluatePathItem(e,s,r);for(let c of o)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new vp.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),o=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&o.add(c.subject);return o}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){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 h=this.nodeToKey(d);(r===null||this.nodeInSet(d,r))&&s.add(d),i.has(h)||(i.add(h),o.push({node:d,depth:u+1}))}}return s}async evaluateZeroOrMorePath(e,t,r){let i=await this.evaluateOneOrMorePath(e,t,r);return(r===null||this.nodeInSet(e,r))&&i.add(e),i}async evaluateZeroOrOnePath(e,t,r){let i=new Set;(r===null||this.nodeInSet(e,r))&&i.add(e);let s=await this.evaluatePathItem(e,t,r);for(let o of s)i.add(o);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new vp.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),o=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&o.add(c.object);return o}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(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 r=new Set,i=await this.tripleStore.match(void 0,void 0,void 0);for(let s of i)r.add(s.subject),r.add(s.object);return r}let t=new Set;switch(e.type){case"iri":t.add(new vp.IRI(e.value));break;case"blank":t.add(new yx.BlankNode(e.value));break;default:throw new ef(`Unsupported element type in subject/object position: ${e.type}`)}return t}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r){if(r instanceof vp.IRI)return{type:"iri",value:r.value};if(r instanceof yx.BlankNode)return{type:"blank",value:r.id};if(r instanceof U9.Literal)return{type:"literal",value:r.value,datatype:r.datatype?.value,language:r.language,direction:r.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 r=this.nodeToKey(e);for(let i of t)if(this.nodeToKey(i)===r)return!0;return!1}};Wc.PropertyPathExecutor=T1});var C1=S(Gc=>{"use strict";Object.defineProperty(Gc,"__esModule",{value:!0});Gc.BGPExecutor=Gc.BGPExecutorError=void 0;var bp=us(),jo=Ae(),A1=Ne(),wp=qt(),Ep=ku(),V9=_x(),Hr=class extends Error{static{a(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Gc.BGPExecutorError=Hr;var x1=class{static{a(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new V9.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new bp.SolutionMapping;return}let t=this.matchTriplePattern(e.triples[0]);for(let r=1;r<e.triples.length;r++)t=this.joinWithPattern(t,e.triples[r]);for await(let r of t)yield r}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*executeInGraph(e,t){if(e.triples.length===0){yield new bp.SolutionMapping;return}let r=this.matchTriplePatternInGraph(e.triples[0],t);for(let i=1;i<e.triples.length;i++)r=this.joinWithPatternInGraph(r,e.triples[i],t);for await(let i of r)yield i}async*matchTriplePatternInGraph(e,t){if(this.isPropertyPath(e.predicate))throw new Hr("Property paths within named graphs are not yet supported");let r=e.predicate;if(this.isLiteral(e.subject)||this.isLiteral(r)){this.warnLiteralGuard("matchTriplePatternInGraph",this.isLiteral(e.subject)?"subject":"predicate",this.isLiteral(e.subject)?e.subject:r);return}let i=this.isVariable(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),s=this.isVariable(r)?void 0:this.toRDFTermAsPredicate(r),o=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new Hr("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 bp.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let o=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(o,r)){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 r=this.isVariable(e.subject)||this.isQuotedTriple(e.subject)&&this.hasVariablesInQuotedTriple(e.subject)?void 0:this.toRDFTermAsSubject(e.subject),i=this.isVariable(t)?void 0:this.toRDFTermAsPredicate(t),s=this.isVariable(e.object)||this.isQuotedTriple(e.object)&&this.hasVariablesInQuotedTriple(e.object)?void 0:this.toRDFTerm(e.object),o=await this.tripleStore.match(r,i,s);for(let c of o){let l=new bp.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 Ep.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,o]of i)r.set(s,o)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,o]of i)r.set(s,o)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof jo.IRI&&e.value===t.value;case"literal":return!(!(t instanceof A1.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof wp.BlankNode&&e.value===t.id;case"quoted":return t instanceof Ep.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let o of this.matchTriplePattern(s)){let c=i.merge(o);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof jo.IRI?{type:"iri",value:r.value}:e}isVariable(e){return e.type==="variable"}isQuotedTriple(e){return e.type==="quoted"}isLiteral(e){return e.type==="literal"}warnLiteralGuard(e,t,r){let i="value"in r?String(r.value):"<unknown>",s=i.length>80?`${i.slice(0,77)}...`:i;console.warn(`[BGPExecutor] literal-safety guard fired in ${e}: literal in ${t} position \u2014 yielding 0 solutions. value="${s}"`)}toRDFTermAsSubject(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"blank":return new wp.BlankNode(e.value);case"literal":throw new Hr("Literals cannot appear in subject position");case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new jo.IRI(e.predicate.value):(()=>{throw new Hr("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new Ep.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"literal":throw new Hr("Literals cannot appear in predicate position");case"blank":throw new Hr("Blank nodes cannot appear in predicate position");case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new jo.IRI(e.value);case"literal":return new A1.Literal(e.value,e.datatype?new jo.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new wp.BlankNode(e.value);case"variable":throw new Hr(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Hr(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof jo.IRI)return{type:"iri",value:e.value};if(e instanceof A1.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof wp.BlankNode)return{type:"blank",value:e.id};if(e instanceof Ep.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new Hr(`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)}}};Gc.BGPExecutor=x1});var Sx=S(Tp=>{"use strict";Object.defineProperty(Tp,"__esModule",{value:!0});Tp.StringFunctions=void 0;var zc=Ae(),$o=Ne(),R1=qt(),tf=class n{static{a(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof zc.IRI||e instanceof $o.Literal?e.value:e instanceof R1.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof $o.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof $o.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=n.parseDirectionalLangTag(e),[s,o]=n.parseDirectionalLangTag(t),c=r.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 r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static regex(e,t,r){try{let i=r?r.includes("u")?r:r+"u":"u";return new RegExp(t,i).test(e)}catch(i){throw new Error(`REGEX: invalid pattern '${t}': ${i.message}`)}}static contains(e,t){return e.includes(t)}static strStarts(e,t){return e.startsWith(t)}static strEnds(e,t){return e.endsWith(t)}static strlen(e){return e.length}static ucase(e){return e.toUpperCase()}static lcase(e){return e.toLowerCase()}static substr(e,t,r){let i=t-1;if(i<0){if(r!==void 0){let s=r+i;return s<=0?"":e.substring(0,s)}return e}return r!==void 0?e.substring(i,i+r):e.substring(i)}static strBefore(e,t){if(t==="")return"";let r=e.indexOf(t);return r===-1?"":e.substring(0,r)}static strAfter(e,t){if(t==="")return e;let r=e.indexOf(t);return r===-1?"":e.substring(r+t.length)}static concat(...e){return e.join("")}static replace(e,t,r,i){try{let s=i||"g",o=s.includes("u")?s:s+"u",c=new RegExp(t,o);return e.replace(c,r)}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 r;if(e instanceof $o.Literal)r=e.value;else if(e instanceof zc.IRI)r=e.value;else if(e instanceof R1.BlankNode)r=e.id;else if(typeof e=="string")r=e;else throw new Error("NORMALIZE: first argument must be a string or literal");let i="NFC";if(t!==void 0)if(t instanceof $o.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof zc.IRI)i=t.value.toUpperCase();else throw new Error("NORMALIZE: second argument must be a string literal");if(!n.VALID_NORMALIZATION_FORMS.includes(i))throw new Error(`NORMALIZE: invalid normalization form '${i}'. Valid forms are: NFC, NFD, NFKC, NFKD`);let s=r.normalize(i);return new $o.Literal(s,new zc.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 $o.Literal)t=e.value;else if(e instanceof zc.IRI)t=e.value;else if(e instanceof R1.BlankNode)t=e.id;else if(typeof e=="string")t=e;else throw new Error("FOLD: argument must be a string or literal");let r=n.unicodeCaseFold(t);return new $o.Literal(r,new zc.IRI("http://www.w3.org/2001/XMLSchema#string"))}static unicodeCaseFold(e){let t="";for(let r of e){let i=n.CASE_FOLDING_MAP.get(r);i!==void 0?t+=i:t+=r.toLowerCase()}return t}};Tp.StringFunctions=tf;tf.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];tf.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 vx=S(Ap=>{"use strict";Object.defineProperty(Ap,"__esModule",{value:!0});Ap.MathFunctions=void 0;var I1=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()}};Ap.MathFunctions=I1});var Cp=S(xp=>{"use strict";Object.defineProperty(xp,"__esModule",{value:!0});xp.DateTimeParsing=void 0;var q9=Ae(),W9=Ne(),P1=class n{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,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDayTimeDuration: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=r.indexOf("T"),o="",c="";if(s===-1?o=r:(o=r.substring(0,s),c=r.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 h=parseFloat(u[1]);i+=h*60*60*1e3,l=l.substring(u[0].length)}let f=l.match(/^(\d+(?:\.\d+)?)M/);if(f){let h=parseFloat(f[1]);i+=h*60*1e3,l=l.substring(f[0].length)}let d=l.match(/^(\d+(?:\.\d+)?)S$/);if(d){let h=parseFloat(d[1]);i+=h*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,r=Math.abs(e),i=Math.floor(r/(1440*60*1e3));r=r%(1440*60*1e3);let s=Math.floor(r/(3600*1e3));r=r%(3600*1e3);let o=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||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 n.parseDayTimeDuration(e),new W9.Literal(e,new q9.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,o=parseInt(r[3],10),c=r[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),h=parseInt(u[3],10),p=f*(d*60+h)*60*1e3;l=new Date(l.getTime()-p)}}return l}static parseXSDTime(e){let t=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r)return null;let i=parseInt(r[1],10),s=parseInt(r[2],10),o=parseInt(r[3],10),c=r[4],l=r[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 h=d[1]==="+"?1:-1,p=parseInt(d[2],10),y=parseInt(d[3],10),v=h*(p*60+y)*60*1e3;f-=v}}return f}static formatDateDuration(e){if(e===0)return"P0D";let t=e<0,r=Math.abs(e);return t?`-P${r}D`:`P${r}D`}static parseYearMonthDuration(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDuration: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),o=parseInt(r[3]||"0",10);if(!r[2]&&!r[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,r=Math.abs(e),i=Math.floor(r/12),s=r%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)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),o=parseInt(r[3]||"0",10);if(!r[2]&&!r[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,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,o=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let 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,h=d.match(/^(\d+(?:\.\d+)?)H/);h&&(s=parseFloat(h[1]),d=d.substring(h[0].length));let p=d.match(/^(\d+(?:\.\d+)?)M/);p&&(o=parseFloat(p[1]),d=d.substring(p[0].length));let y=d.match(/^(\d+(?:\.\d+)?)S$/);if(y&&(c=parseFloat(y[1]),d=d.substring(y[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:o,seconds:c}}};xp.DateTimeParsing=P1});var bx=S(Rp=>{"use strict";Object.defineProperty(Rp,"__esModule",{value:!0});Rp.DateTimeArithmetic=void 0;var hn=Ae(),xe=Ne(),Ze=Cp(),O1=class{static{a(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r),o=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(o.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-o.getTime(),l=Ze.DateTimeParsing.formatDayTimeDuration(c);return new xe.Literal(l,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+o,l=new Date(c);return new xe.Literal(l.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-o,l=new Date(c);return new xe.Literal(l.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let o=Ze.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"),h=`${u}-${f}-${d}`;return new xe.Literal(h,new hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let o=Ze.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"),h=`${u}-${f}-${d}`;return new xe.Literal(h,new hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+o),s.getUTCDate()!==c&&s.setUTCDate(0),new xe.Literal(s.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-o),s.getUTCDate()!==c&&s.setUTCDate(0),new xe.Literal(s.toISOString(),new hn.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let o=Ze.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 hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let o=Ze.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 hn.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseDayTimeDuration(r),o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=Ze.DateTimeParsing.formatDayTimeDuration(s+o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseDayTimeDuration(r),o=Ze.DateTimeParsing.parseDayTimeDuration(i),c=Ze.DateTimeParsing.formatDayTimeDuration(s-o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof xe.Literal?e.value:e,i=Ze.DateTimeParsing.parseDayTimeDuration(r),s=Ze.DateTimeParsing.formatDayTimeDuration(i*t);return new xe.Literal(s,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationDivide(e,t){if(t===0)throw new Error("durationDivide: division by zero");let r=e instanceof xe.Literal?e.value:e,i=Ze.DateTimeParsing.parseDayTimeDuration(r),s=Ze.DateTimeParsing.formatDayTimeDuration(i/t);return new xe.Literal(s,new hn.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseYearMonthDuration(r),o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=Ze.DateTimeParsing.formatYearMonthDuration(s+o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof xe.Literal?e.value:e,i=t instanceof xe.Literal?t.value:t,s=Ze.DateTimeParsing.parseYearMonthDuration(r),o=Ze.DateTimeParsing.parseYearMonthDuration(i),c=Ze.DateTimeParsing.formatYearMonthDuration(s-o);return new xe.Literal(c,new hn.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof xe.Literal?e.value:e;return Ze.DateTimeParsing.parseDayTimeDuration(t)/1e3}};Rp.DateTimeArithmetic=O1});var wx=S(Ip=>{"use strict";Object.defineProperty(Ip,"__esModule",{value:!0});Ip.DateTimeAccessors=void 0;var rf=Ae(),$t=Ne(),At=Cp(),F1=class{static{a(this,"DateTimeAccessors")}static year(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`YEAR: invalid date string '${e}'`);return t.getFullYear()}static month(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MONTH: invalid date string '${e}'`);return t.getMonth()+1}static day(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`DAY: invalid date string '${e}'`);return t.getDate()}static hours(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`HOURS: invalid date string '${e}'`);return t.getHours()}static minutes(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`MINUTES: invalid date string '${e}'`);return t.getMinutes()}static seconds(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`SECONDS: invalid date string '${e}'`);return t.getSeconds()+t.getMilliseconds()/1e3}static durationDays(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static durationYears(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof $t.Literal?e.value:e,r=At.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.months:r.months}static timezone(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TIMEZONE: invalid date string '${e}'`);let r;if(e.endsWith("Z"))r="PT0S";else{let i=e.match(/([+-]\d{2}):?(\d{2})$/);if(i){let s=parseInt(i[1],10),o=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);o===0?r=`${c}PT${l}H`:r=`${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?r=`${l}PT${o}H`:r=`${l}PT${o}H${c}M`}}return new $t.Literal(r,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static tz(e){let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`TZ: invalid date string '${e}'`);if(e.endsWith("Z"))return"Z";let r=e.match(/([+-]\d{2}:\d{2})$/);if(r)return r[1];let i=e.match(/([+-])(\d{2})(\d{2})$/);return i?`${i[1]}${i[2]}:${i[3]}`:""}static adjust(e,t){let r=e instanceof $t.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let ce=i.getUTCFullYear(),B=String(i.getUTCMonth()+1).padStart(2,"0"),V=String(i.getUTCDate()).padStart(2,"0"),F=String(i.getUTCHours()).padStart(2,"0"),k=String(i.getUTCMinutes()).padStart(2,"0"),te=String(i.getUTCSeconds()).padStart(2,"0"),Ye=i.getUTCMilliseconds(),at=`${ce}-${B}-${V}T${F}:${k}:${te}`;return Ye>0&&(at+=`.${String(Ye).padStart(3,"0")}`),new $t.Literal(at,new rf.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof $t.Literal?t.value:t,o=At.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"),h=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),y=String(u.getUTCMinutes()).padStart(2,"0"),v=String(u.getUTCSeconds()).padStart(2,"0"),b=u.getUTCMilliseconds(),w=o>=0?"+":"-",T=Math.floor(Math.abs(o)/(3600*1e3)),I=Math.floor(Math.abs(o)%(3600*1e3)/(60*1e3)),$=`${w}${String(T).padStart(2,"0")}:${String(I).padStart(2,"0")}`,q=`${f}-${d}-${h}T${p}:${y}:${v}`;return b>0&&(q+=`.${String(b).padStart(3,"0")}`),q+=$,new $t.Literal(q,new rf.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t);return r<i}static dateAfter(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t);return r>i}static dateInRange(e,t,r){let i=At.DateTimeParsing.parseDate(e),s=At.DateTimeParsing.parseDate(t),o=At.DateTimeParsing.parseDate(r);return i>=s&&i<=o}static compareDurations(e,t,r){let i=e instanceof $t.Literal?e.value:e,s=t instanceof $t.Literal?t.value:t,o=At.DateTimeParsing.parseDayTimeDuration(i),c=At.DateTimeParsing.parseDayTimeDuration(s);switch(r){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: ${r}`)}}static dateDiffMinutes(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=At.DateTimeParsing.parseDate(e),i=At.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60*60)*100)/100}static timeDiff(e,t){let r=e instanceof $t.Literal?e.value:e,i=t instanceof $t.Literal?t.value:t,s=At.DateTimeParsing.parseXSDTime(r),o=At.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(o===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-o,l=At.DateTimeParsing.formatDayTimeDuration(c);return new $t.Literal(l,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof $t.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let r=e instanceof $t.Literal?e.value:e,i=t instanceof $t.Literal?t.value:t,s=At.DateTimeParsing.parseXSDDate(r),o=At.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);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=At.DateTimeParsing.formatDateDuration(l);return new $t.Literal(u,new rf.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};Ip.DateTimeAccessors=F1});var Op=S(Pp=>{"use strict";Object.defineProperty(Pp,"__esModule",{value:!0});Pp.DateTimeFunctions=void 0;var Hc=Cp(),fr=bx(),yt=wx(),D1=class{static{a(this,"DateTimeFunctions")}static parseDate(e){return Hc.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return Hc.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return Hc.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return Hc.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return Hc.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return Hc.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return yt.DateTimeAccessors.year(e)}static month(e){return yt.DateTimeAccessors.month(e)}static day(e){return yt.DateTimeAccessors.day(e)}static hours(e){return yt.DateTimeAccessors.hours(e)}static minutes(e){return yt.DateTimeAccessors.minutes(e)}static seconds(e){return yt.DateTimeAccessors.seconds(e)}static durationDays(e){return yt.DateTimeAccessors.durationDays(e)}static durationHours(e){return yt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return yt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return yt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return yt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return yt.DateTimeAccessors.durationMonths(e)}static timezone(e){return yt.DateTimeAccessors.timezone(e)}static tz(e){return yt.DateTimeAccessors.tz(e)}static adjust(e,t){return yt.DateTimeAccessors.adjust(e,t)}static now(){return yt.DateTimeAccessors.now()}static dateBefore(e,t){return yt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return yt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,r){return yt.DateTimeAccessors.dateInRange(e,t,r)}static compareDurations(e,t,r){return yt.DateTimeAccessors.compareDurations(e,t,r)}static dateDiffMinutes(e,t){return yt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return yt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return yt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return yt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return yt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return yt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return yt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return yt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return fr.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return fr.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return fr.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return fr.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return fr.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return fr.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return fr.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return fr.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return fr.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return fr.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return fr.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return fr.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return fr.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return fr.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return fr.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return fr.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return fr.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return fr.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return fr.DateTimeArithmetic.durationToSeconds(e)}};Pp.DateTimeFunctions=D1});var Ex=S(Dp=>{"use strict";Object.defineProperty(Dp,"__esModule",{value:!0});Dp.LogicalFunctions=void 0;var G9=Ae(),Qc=Ne(),z9=qt(),Fp=Op(),N1=class n{static{a(this,"LogicalFunctions")}static compare(e,t,r){if(n.isDayTimeDurationValue(e)&&n.isDayTimeDurationValue(t))return Fp.DateTimeFunctions.compareDurations(e instanceof Qc.Literal?e:String(e),t instanceof Qc.Literal?t:String(t),r);if(n.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return Fp.DateTimeFunctions.compareDurations(e instanceof Qc.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&n.isDayTimeDurationValue(t))return Fp.DateTimeFunctions.compareDurations(e,t instanceof Qc.Literal?t:String(t),r);let i=n.toComparableValue(e),s=n.toComparableValue(t);switch(r){case"=":return i===s;case"!=":return i!==s;case"<":return i<s;case">":return i>s;case"<=":return i<=s;case">=":return i>=s;default:throw new Error(`Unknown comparison operator: ${r}`)}}static isDayTimeDurationValue(e){return e instanceof Qc.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 Qc.Literal){let t=e.datatype?.value;if(t?.includes("#integer")||t?.includes("#decimal")||t?.includes("#double")){let r=parseFloat(e.value);if(!isNaN(r))return r}if(t==="http://www.w3.org/2001/XMLSchema#dayTimeDuration")try{return Fp.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof G9.IRI?e.value:e instanceof z9.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,r){return e?t:r}};Dp.LogicalFunctions=N1});var Tx=S(Np=>{"use strict";Object.defineProperty(Np,"__esModule",{value:!0});Np.RDFTermFunctions=void 0;var Mr=Ae(),bt=Ne(),pi=qt(),Kc=ku(),L1=An(),k1=class n{static{a(this,"RDFTermFunctions")}static datatype(e){if(e===void 0)throw new Error("DATATYPE: argument is undefined");if(e instanceof bt.Literal)return e.datatype?e.datatype:e.language?new Mr.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Mr.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 Mr.IRI}static isBlank(e){return e===void 0?!1:e instanceof pi.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof bt.Literal}static isTriple(e){return e===void 0?!1:e instanceof Kc.QuotedTriple}static hasLangdir(e){return e===void 0||!(e instanceof bt.Literal)?!1:!!e.language&&!!e.direction}static isNumeric(e){if(e===void 0||!(e instanceof bt.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 bt.Literal(t.toISOString(),new Mr.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 bt.Literal(String(t),new Mr.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 bt.Literal(String(t),new Mr.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 Mr.IRI&&t instanceof Mr.IRI)return e.value===t.value;if(e instanceof pi.BlankNode&&t instanceof pi.BlankNode)return e.id===t.id;if(e instanceof bt.Literal&&t instanceof bt.Literal){if(e.value!==t.value||e.language!==t.language)return!1;let r=e.datatype?.value,i=t.datatype?.value;return r===i}return!1}static iri(e){if(e===void 0)throw new Error("IRI: argument is undefined");if(e instanceof Mr.IRI)return e;if(e instanceof bt.Literal)return new Mr.IRI(e.value);throw e instanceof pi.BlankNode?new Error("IRI: cannot convert blank node to IRI"):new Error("IRI: unsupported term type")}static uri(e){return n.iri(e)}static bnode(e){if(e===void 0){let t=`b${(0,L1.v4)().replace(/-/g,"").substring(0,12)}`;return new pi.BlankNode(t)}if(e instanceof bt.Literal)return new pi.BlankNode(e.value);if(e instanceof pi.BlankNode)return e;throw new Error("BNODE: argument must be a string literal or omitted")}static strdt(e,t){if(e===void 0)throw new Error("STRDT: lexical form is undefined");if(t===void 0)throw new Error("STRDT: datatype IRI is undefined");let r;if(e instanceof bt.Literal){if(e.language)throw new Error("STRDT: lexical form must not have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRDT: lexical form must be a string literal");let i;if(t instanceof Mr.IRI)i=t;else if(t instanceof bt.Literal)i=new Mr.IRI(t.value);else throw new Error("STRDT: datatype must be an IRI");return new bt.Literal(r,i)}static strlang(e,t){if(e===void 0)throw new Error("STRLANG: lexical form is undefined");if(t===void 0)throw new Error("STRLANG: language tag is undefined");let r;if(e instanceof bt.Literal){if(e.language)throw new Error("STRLANG: lexical form must not already have a language tag");r=e.value}else if(typeof e=="string")r=e;else throw new Error("STRLANG: lexical form must be a string literal");let i;if(t instanceof bt.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 bt.Literal(r,void 0,i)}static strlangdir(e,t,r){if(e===void 0)throw new Error("STRLANGDIR: lexical form is undefined");if(t===void 0)throw new Error("STRLANGDIR: language tag is undefined");if(r===void 0)throw new Error("STRLANGDIR: direction is undefined");let i;if(e instanceof bt.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 bt.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(r instanceof bt.Literal)o=r.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 bt.Literal(i,void 0,s,o)}static uuid(){let e=(0,L1.v4)();return new Mr.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,L1.v4)();return new bt.Literal(e)}static triple(e,t,r){if(e===void 0)throw new Error("TRIPLE: subject is undefined");if(t===void 0)throw new Error("TRIPLE: predicate is undefined");if(r===void 0)throw new Error("TRIPLE: object is undefined");if(e instanceof bt.Literal)throw new Error("TRIPLE: subject must be IRI, BlankNode, or QuotedTriple, got Literal");if(!(t instanceof Mr.IRI)){let c=t instanceof bt.Literal?"Literal":t instanceof pi.BlankNode?"BlankNode":t instanceof Kc.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,o=r;return new Kc.QuotedTriple(i,s,o)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.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 Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.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 Kc.QuotedTriple)){let t=e instanceof Mr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof pi.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};Np.RDFTermFunctions=k1});var Ax=S(Lp=>{"use strict";Object.defineProperty(Lp,"__esModule",{value:!0});Lp.HashFunctions=void 0;var M1=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")}};Lp.HashFunctions=M1});var Mp=S(kp=>{"use strict";Object.defineProperty(kp,"__esModule",{value:!0});kp.BuiltInFunctions=void 0;var dr=Sx(),Bo=vx(),le=Op(),Yc=Ex(),Dt=Tx(),nf=Ax(),j1=class{static{a(this,"BuiltInFunctions")}static str(...e){return dr.StringFunctions.str(...e)}static lang(...e){return dr.StringFunctions.lang(...e)}static langdir(...e){return dr.StringFunctions.langdir(...e)}static langMatches(...e){return dr.StringFunctions.langMatches(...e)}static regex(...e){return dr.StringFunctions.regex(...e)}static contains(...e){return dr.StringFunctions.contains(...e)}static strStarts(...e){return dr.StringFunctions.strStarts(...e)}static strEnds(...e){return dr.StringFunctions.strEnds(...e)}static strlen(...e){return dr.StringFunctions.strlen(...e)}static ucase(...e){return dr.StringFunctions.ucase(...e)}static lcase(...e){return dr.StringFunctions.lcase(...e)}static substr(...e){return dr.StringFunctions.substr(...e)}static strBefore(...e){return dr.StringFunctions.strBefore(...e)}static strAfter(...e){return dr.StringFunctions.strAfter(...e)}static concat(...e){return dr.StringFunctions.concat(...e)}static replace(...e){return dr.StringFunctions.replace(...e)}static encodeForUri(...e){return dr.StringFunctions.encodeForUri(...e)}static normalize(...e){return dr.StringFunctions.normalize(...e)}static fold(...e){return dr.StringFunctions.fold(...e)}static abs(...e){return Bo.MathFunctions.abs(...e)}static round(...e){return Bo.MathFunctions.round(...e)}static ceil(...e){return Bo.MathFunctions.ceil(...e)}static floor(...e){return Bo.MathFunctions.floor(...e)}static rand(){return Bo.MathFunctions.rand()}static msToMinutes(...e){return Bo.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Bo.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Bo.MathFunctions.msToSeconds(...e)}static parseDate(...e){return le.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return le.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return le.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return le.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return le.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return le.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return le.DateTimeFunctions.year(...e)}static month(...e){return le.DateTimeFunctions.month(...e)}static day(...e){return le.DateTimeFunctions.day(...e)}static hours(...e){return le.DateTimeFunctions.hours(...e)}static minutes(...e){return le.DateTimeFunctions.minutes(...e)}static seconds(...e){return le.DateTimeFunctions.seconds(...e)}static timezone(...e){return le.DateTimeFunctions.timezone(...e)}static tz(...e){return le.DateTimeFunctions.tz(...e)}static now(){return le.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return le.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return le.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return le.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return le.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return le.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return le.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return le.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return le.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return le.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return le.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return le.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return le.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return le.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return le.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return le.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return le.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return le.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return le.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return le.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return le.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return le.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return le.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return le.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return le.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return le.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return le.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return le.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return le.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return le.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return le.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return le.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return le.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return le.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return le.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return le.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return le.DateTimeFunctions.adjust(...e)}static isTime(...e){return le.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return le.DateTimeFunctions.timeDiff(...e)}static compare(...e){return Yc.LogicalFunctions.compare(...e)}static logicalAnd(...e){return Yc.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return Yc.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return Yc.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return Yc.LogicalFunctions.coalesce(...e)}static if(...e){return Yc.LogicalFunctions.if(...e)}static datatype(...e){return Dt.RDFTermFunctions.datatype(...e)}static bound(...e){return Dt.RDFTermFunctions.bound(...e)}static isIRI(...e){return Dt.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return Dt.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return Dt.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return Dt.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return Dt.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return Dt.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return Dt.RDFTermFunctions.sameTerm(...e)}static iri(...e){return Dt.RDFTermFunctions.iri(...e)}static uri(...e){return Dt.RDFTermFunctions.uri(...e)}static bnode(...e){return Dt.RDFTermFunctions.bnode(...e)}static strdt(...e){return Dt.RDFTermFunctions.strdt(...e)}static strlang(...e){return Dt.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return Dt.RDFTermFunctions.strlangdir(...e)}static uuid(){return Dt.RDFTermFunctions.uuid()}static struuid(){return Dt.RDFTermFunctions.struuid()}static xsdDateTime(...e){return Dt.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return Dt.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return Dt.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return Dt.RDFTermFunctions.triple(...e)}static subject(...e){return Dt.RDFTermFunctions.subject(...e)}static predicate(...e){return Dt.RDFTermFunctions.predicate(...e)}static object(...e){return Dt.RDFTermFunctions.object(...e)}static md5(...e){return nf.HashFunctions.md5(...e)}static sha1(...e){return nf.HashFunctions.sha1(...e)}static sha256(...e){return nf.HashFunctions.sha256(...e)}static sha384(...e){return nf.HashFunctions.sha384(...e)}static sha512(...e){return nf.HashFunctions.sha512(...e)}};kp.BuiltInFunctions=j1});var sf=S(fs=>{"use strict";Object.defineProperty(fs,"__esModule",{value:!0});fs.ExoQLBudgetExceededError=fs.ExoQLCycleError=fs.ExoQLEvalDisabledError=fs.ExoQLForbiddenKeywordError=void 0;var $1=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}};fs.ExoQLForbiddenKeywordError=$1;var B1=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"}};fs.ExoQLEvalDisabledError=B1;var U1=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}};fs.ExoQLCycleError=U1;var V1=class extends Error{static{a(this,"ExoQLBudgetExceededError")}constructor(e,t,r,i){super(i??`ExoQLBudgetExceededError: ${e} budget exceeded (limit=${t}, observed=${r})`),this.name="ExoQLBudgetExceededError",this.budget=e,this.limit=t,this.observed=r}};fs.ExoQLBudgetExceededError=V1});var Nx=S(j=>{"use strict";Object.defineProperty(j,"__esModule",{value:!0});j.functionHandlers=void 0;var M=Mp();j.functionHandlers=new Map;j.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.str(t)});j.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.lang(t)});j.functionHandlers.set("langmatches",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.langMatches(t,r)});j.functionHandlers.set("contains",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.contains(t,r)});j.functionHandlers.set("strstarts",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strStarts(t,r)});j.functionHandlers.set("strends",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strEnds(t,r)});j.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.strlen(t)});j.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.ucase(t)});j.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.lcase(t)});j.functionHandlers.set("substr",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=Number(e.evaluateExpression(n[1],e.solution));if(n[2]){let i=Number(e.evaluateExpression(n[2],e.solution));return M.BuiltInFunctions.substr(t,r,i)}return M.BuiltInFunctions.substr(t,r)});j.functionHandlers.set("strbefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strBefore(t,r)});j.functionHandlers.set("strafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.strAfter(t,r)});j.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return M.BuiltInFunctions.concat(...t)});j.functionHandlers.set("replace",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution)),s=n[3]?e.getStringValue(e.evaluateExpression(n[3],e.solution)):void 0;return M.BuiltInFunctions.replace(t,r,i,s)});j.functionHandlers.set("regex",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=n[2]?e.getStringValue(e.evaluateExpression(n[2],e.solution)):void 0;return M.BuiltInFunctions.regex(t,r,i)});j.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.encodeForUri(t)});j.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.datatype(t).value});j.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return M.BuiltInFunctions.bound(r)}return!0});var xx=a((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isIRI(t)},"isIriHandler");j.functionHandlers.set("isiri",xx);j.functionHandlers.set("isuri",xx);j.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isBlank(t)});j.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isLiteral(t)});j.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isNumeric(t)});j.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.hasLangdir(t)});j.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.isTriple(t)});j.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return M.BuiltInFunctions.sameTerm(t,r)});j.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.abs(t)});j.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.round(t)});j.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.ceil(t)});j.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return M.BuiltInFunctions.floor(t)});j.functionHandlers.set("rand",()=>M.BuiltInFunctions.rand());j.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.parseDate(t)});j.functionHandlers.set("datebefore",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateBefore(t,r)});j.functionHandlers.set("dateafter",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateAfter(t,r)});j.functionHandlers.set("dateinrange",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=e.getStringValue(e.evaluateExpression(n[2],e.solution));return M.BuiltInFunctions.dateInRange(t,r,i)});j.functionHandlers.set("datediffminutes",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateDiffMinutes(t,r)});j.functionHandlers.set("datediffhours",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution));return M.BuiltInFunctions.dateDiffHours(t,r)});var Xc=a((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),Cx=Xc(M.BuiltInFunctions.year.bind(M.BuiltInFunctions),M.BuiltInFunctions.durationYears.bind(M.BuiltInFunctions),null);j.functionHandlers.set("year",Cx);j.functionHandlers.set("years",Cx);var Rx=Xc(M.BuiltInFunctions.month.bind(M.BuiltInFunctions),M.BuiltInFunctions.durationMonths.bind(M.BuiltInFunctions),null);j.functionHandlers.set("month",Rx);j.functionHandlers.set("months",Rx);var Ix=Xc(M.BuiltInFunctions.day.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationDays.bind(M.BuiltInFunctions));j.functionHandlers.set("day",Ix);j.functionHandlers.set("days",Ix);j.functionHandlers.set("hours",Xc(M.BuiltInFunctions.hours.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationHours.bind(M.BuiltInFunctions)));j.functionHandlers.set("minutes",Xc(M.BuiltInFunctions.minutes.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationMinutes.bind(M.BuiltInFunctions)));j.functionHandlers.set("seconds",Xc(M.BuiltInFunctions.seconds.bind(M.BuiltInFunctions),null,M.BuiltInFunctions.durationSeconds.bind(M.BuiltInFunctions)));j.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.timezone(t)});j.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.tz(t)});j.functionHandlers.set("adjust",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=n.length>1?e.evaluateExpression(n[1],e.solution):void 0;return M.BuiltInFunctions.adjust(t,r)});j.functionHandlers.set("now",()=>M.BuiltInFunctions.now());var Px=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");j.functionHandlers.set("datetime",Px);j.functionHandlers.set("xsd:datetime",Px);var Ox=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");j.functionHandlers.set("integer",Ox);j.functionHandlers.set("xsd:integer",Ox);var Fx=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");j.functionHandlers.set("decimal",Fx);j.functionHandlers.set("xsd:decimal",Fx);var Dx=a((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");j.functionHandlers.set("daytimeduration",Dx);j.functionHandlers.set("xsd:daytimeduration",Dx);j.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToDays(t)});j.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToHours(t)});j.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToMinutes(t)});j.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationToSeconds(t)});j.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationDays(t)});j.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationHours(t)});j.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationMinutes(t)});j.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationSeconds(t)});j.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationYears(t)});j.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return M.BuiltInFunctions.durationMonths(t)});j.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeDiff(t,r)});j.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeAdd(t,r)});j.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return M.BuiltInFunctions.dateTimeSubtract(t,r)});j.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToMinutes(t)});j.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToHours(t)});j.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.msToSeconds(t)});j.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.md5(t)});j.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha1(t)});j.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha256(t)});j.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha384(t)});j.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return M.BuiltInFunctions.sha512(t)});j.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.subject(t)});j.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.predicate(t)});j.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return M.BuiltInFunctions.object(t)});j.functionHandlers.set("triple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution),i=e.getTermFromExpression(n[2],e.solution);return M.BuiltInFunctions.triple(t,r,i)});j.functionHandlers.set("days_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t),s=new Date(r);return Math.floor((s.getTime()-i.getTime())/(1440*60*1e3))});j.functionHandlers.set("minutes_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t),s=new Date(r);return Math.floor((s.getTime()-i.getTime())/(60*1e3))});j.functionHandlers.set("hours_between",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t);return(new Date(r).getTime()-i.getTime())/(3600*1e3)});j.functionHandlers.set("age_days",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=new Date(t);return Math.floor((new Date().getTime()-r.getTime())/(1440*60*1e3))});j.functionHandlers.set("week_number",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=new Date(t),i=new Date(Date.UTC(r.getFullYear(),r.getMonth(),r.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)});j.functionHandlers.set("format_date",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution)),r=e.getStringValue(e.evaluateExpression(n[1],e.solution)),i=new Date(t);return r.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"))});j.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:n}=sf();throw new n})});var jp=S(Jc=>{"use strict";Object.defineProperty(Jc,"__esModule",{value:!0});Jc.FilterExecutor=Jc.FilterExecutorError=void 0;var _t=Mp(),H9=Nx(),q1=Ae(),ds=Ne(),vr=class extends Error{static{a(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Jc.FilterExecutorError=vr;var W1=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 r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||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(r=>this.expressionContainsExists(r))}if(e.type==="function"||e.type==="functionCall"){let t=e;return Array.isArray(t.args)?t.args.some(r=>this.expressionContainsExists(r)):!1}return!1}async executeAll(e,t){let r=[];async function*i(){for(let s of t)yield s}a(i,"generator");for await(let s of this.execute(e,i()))r.push(s);return r}evaluateExpression(e,t){let r=e;if("termType"in e)switch(r.termType){case"Variable":return t.get(r.value);case"Literal":{let i=r.value,s=r.datatype,o=typeof s=="string"?s:s?.value;return o&&i.length>0&&this.shouldPreserveDatatype(o)?new ds.Literal(i,new q1.IRI(o)):i}case"NamedNode":return r.value;default:throw new vr(`Unsupported termType: ${String(r.termType)}`)}switch(e.type){case"comparison":return this.evaluateComparison(e,t);case"logical":return this.evaluateLogical(e,t);case"arithmetic":return this.evaluateArithmetic(e,t);case"function":case"functionCall":return this.evaluateFunction(e,t);case"variable":return t.get(e.name);case"literal":{let i=e;return i.datatype&&i.value.length>0&&this.shouldPreserveDatatype(i.datatype)?new ds.Literal(i.value,new q1.IRI(i.datatype)):i.value}case"in":return this.evaluateIn(e,t);case"exists":throw new vr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new vr(`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 r=e,i=await this.evaluateExpressionAsync(r.left,t),s=await this.evaluateExpressionAsync(r.right,t);return _t.BuiltInFunctions.compare(i,s,r.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 vr("EXISTS evaluator not set. Call setExistsEvaluator before evaluating EXISTS expressions.");let r=await this.existsEvaluator(e.pattern,t);return e.negated?!r:r}async evaluateLogicalAsync(e,t){if(e.operator==="!"){let i=await this.evaluateExpressionAsync(e.operands[0],t);return _t.BuiltInFunctions.logicalNot(i)}let r=[];for(let i of e.operands){let s=await this.evaluateExpressionAsync(i,t);r.push(s)}if(e.operator==="&&")return _t.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return _t.BuiltInFunctions.logicalOr(r);throw new vr(`Unknown logical operator: ${String(e.operator)}`)}async evaluateInAsync(e,t){let r=await this.evaluateExpressionAsync(e.expression,t),i=!1;for(let s of e.list){let o=await this.evaluateExpressionAsync(s,t);if(_t.BuiltInFunctions.compare(r,o,"=")){i=!0;break}}return e.negated?!i:i}async evaluateFunctionAsync(e,t){let r=e,i=this.extractFunctionName(r.function),s=r.args??[];if(i==="if"){if(s.length!==3)throw new vr("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={...r,args:o};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:typeof e=="object"&&"termType"in e?e:e instanceof q1.IRI||e instanceof ds.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 r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);return _t.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return _t.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return _t.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return _t.BuiltInFunctions.logicalOr(r);throw new vr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let o=this.evaluateExpression(s,t);return _t.BuiltInFunctions.compare(r,o,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return _t.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return _t.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return _t.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return _t.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return _t.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return _t.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new vr("Division by zero");return _t.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return _t.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),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 vr("Division by zero");return s/o;default:throw new vr(`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 ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof ds.Literal){let t=e.datatype?.value||"";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let i=parseFloat(e.value);if(!isNaN(i))return i}let r=parseFloat(e.value);if(!isNaN(r))return r}if(typeof e=="string"){let t=parseFloat(e);if(!isNaN(t))return t}if(e&&typeof e=="object"&&"value"in e){let t=parseFloat(String(e.value));if(!isNaN(t))return t}throw new vr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof ds.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 ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof ds.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let o=H9.functionHandlers.get(i);if(!o)throw new vr(`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(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new vr(`Unknown function format: ${String(e)}`)}evaluateSpecialFunction(e,t,r){switch(e){case"coalesce":for(let i of t)try{let s=this.evaluateExpression(i,r);if(s!=null)return{value:s}}catch{continue}return{value:void 0};case"if":{if(!t||t.length!==3)throw new vr("IF requires exactly 3 arguments");let i=this.evaluateExpression(t[0],r);return{value:this.toBoolean(i)?this.evaluateExpression(t[1],r):this.evaluateExpression(t[2],r)}}case"byuuid":return{value:this.evaluateByUUID({type:"function",function:"byuuid",args:t},r)};default:return}}getTermFromExpression(e,t){let r=e;if(r.type==="variable"&&r.name)return t.get(r.name)}getStringValue(e){return e==null?"":typeof e=="object"&&"value"in e?String(e.value):String(e)}toBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="number")return!isNaN(e)&&e!==0;if(typeof e=="string")return e.length>0;if(e instanceof ds.Literal){let t=e.datatype?.value||"";if(t.includes("#boolean"))return e.value==="true"||e.value==="1";if(t.includes("#integer")||t.includes("#decimal")||t.includes("#double")||t.includes("#float")){let r=parseFloat(e.value);return!isNaN(r)&&r!==0}return e.value.length>0}return!!e}evaluateByUUID(e,t){if(!e.args||e.args.length!==1)throw new vr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let 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 r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Jc.FilterExecutor=W1});var z1=S($p=>{"use strict";Object.defineProperty($p,"__esModule",{value:!0});$p.OptionalExecutor=void 0;var G1=class{static{a(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let 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 h of f){let p=l.merge(h);p!==null&&(yield p,d=!0)}d||(yield l)}}computeHashKey(e,t,r){let i=[];for(let s of t){let o=e.get(s);i.push(o!==void 0?o.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let o=r.merge(s);o!==null&&(yield o,i=!0)}i||(yield r)}}};$p.OptionalExecutor=G1});var Q1=S(Bp=>{"use strict";Object.defineProperty(Bp,"__esModule",{value:!0});Bp.UnionExecutor=void 0;var H1=class{static{a(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let 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()))r.push(o);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};Bp.UnionExecutor=H1});var Lx=S(Up=>{"use strict";Object.defineProperty(Up,"__esModule",{value:!0});Up.MinusExecutor=void 0;var K1=class{static{a(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let o=!1;for(let c of i)if(this.areCompatible(s,c)){o=!0;break}o||(yield s)}}async executeAll(e,t){let r=[];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()))r.push(o);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.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}};Up.MinusExecutor=K1});var Mx=S(Zc=>{"use strict";Object.defineProperty(Zc,"__esModule",{value:!0});Zc.ValuesExecutor=Zc.ValuesExecutorError=void 0;var Q9=us(),kx=Ae(),K9=Ne(),Vp=class extends Error{static{a(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Zc.ValuesExecutorError=Vp;var Y1=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 r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new Q9.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.toRDFTerm(i);t.set(r,s)}return t}toRDFTerm(e){if(e.type==="iri")return new kx.IRI(e.value);if(e.type==="literal")return new K9.Literal(e.value,e.datatype?new kx.IRI(e.datatype):void 0,e.language,e.direction);throw new Vp(`Unknown term type: ${e.type}`)}};Zc.ValuesExecutor=Y1});var X1=S(tl=>{"use strict";Object.defineProperty(tl,"__esModule",{value:!0});tl.CustomAggregateRegistry=tl.CustomAggregateError=void 0;var el=class extends Error{static{a(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};tl.CustomAggregateError=el;var qp=class n{static{a(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new el("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new el("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new el(`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}};tl.CustomAggregateRegistry=qp;qp.instance=null});var J1=S(et=>{"use strict";Object.defineProperty(et,"__esModule",{value:!0});et.BUILT_IN_AGGREGATES=et.modeAggregate=et.stddevAggregate=et.varianceAggregate=et.medianAggregate=et.EXO_AGGREGATE_NS=void 0;et.getNumericValue=Wp;et.createDecimalLiteral=mi;et.createDoubleLiteral=J9;et.createPercentileAggregate=Na;var La=Ne(),rl=Ae(),Y9=new rl.IRI("http://www.w3.org/2001/XMLSchema#decimal"),X9=new rl.IRI("http://www.w3.org/2001/XMLSchema#double");et.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Wp(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof La.Literal?parseFloat(n.value):n instanceof rl.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}a(Wp,"getNumericValue");function mi(n){return new La.Literal(String(n),Y9)}a(mi,"createDecimalLiteral");function J9(n){return new La.Literal(String(n),X9)}a(J9,"createDoubleLiteral");et.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Wp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=[...t].sort((o,c)=>o-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return mi(s)}};et.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Wp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-r,2),0)/t.length;return mi(i)}};et.stddevAggregate={init(){return{values:[]}},step(n,e){et.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return mi(0);let r=t.reduce((s,o)=>s+o,0)/t.length,i=t.reduce((s,o)=>s+Math.pow(o-r,2),0)/t.length;return mi(Math.sqrt(i))}};et.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof La.Literal||e instanceof rl.IRI?e.value:e),i=t.counts.get(r)||0;t.counts.set(r,i+1),t.values.set(r,e)},finalize(n){let e=n;if(e.counts.size===0)return new La.Literal(" ",new rl.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[o,c]of e.counts)c>r&&(r=c,t=o);let i=e.values.get(t);if(i instanceof La.Literal)return i;let s=parseFloat(t);return isNaN(s)?new La.Literal(t,new rl.IRI("http://www.w3.org/2001/XMLSchema#string")):mi(s)}};function Na(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Wp(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return mi(0);let s=[...i].sort((d,h)=>d-h),o=r.percentile*(s.length-1),c=Math.floor(o),l=Math.ceil(o);if(c===l)return mi(s[c]);let u=o-c,f=s[c]*(1-u)+s[l]*u;return mi(f)}}}a(Na,"createPercentileAggregate");et.BUILT_IN_AGGREGATES={[`${et.EXO_AGGREGATE_NS}median`]:et.medianAggregate,[`${et.EXO_AGGREGATE_NS}variance`]:et.varianceAggregate,[`${et.EXO_AGGREGATE_NS}stddev`]:et.stddevAggregate,[`${et.EXO_AGGREGATE_NS}mode`]:et.modeAggregate,[`${et.EXO_AGGREGATE_NS}percentile25`]:Na(25),[`${et.EXO_AGGREGATE_NS}percentile50`]:Na(50),[`${et.EXO_AGGREGATE_NS}percentile75`]:Na(75),[`${et.EXO_AGGREGATE_NS}percentile90`]:Na(90),[`${et.EXO_AGGREGATE_NS}percentile95`]:Na(95),[`${et.EXO_AGGREGATE_NS}percentile99`]:Na(99)}});var Bx=S(nl=>{"use strict";Object.defineProperty(nl,"__esModule",{value:!0});nl.AggregateExecutor=nl.AggregateExecutorError=void 0;var hr=Ne(),eS=Ae(),Z9=jp(),e5=X1(),t5=J1(),jx=new eS.IRI("http://www.w3.org/2001/XMLSchema#integer"),ka=new eS.IRI("http://www.w3.org/2001/XMLSchema#decimal"),hs=new eS.IRI("http://www.w3.org/2001/XMLSchema#string");function $x(n){return typeof n=="object"&&n.type==="custom"}a($x,"isCustomAggregation");var of=class extends Error{static{a(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};nl.AggregateExecutorError=of;var Z1=class{static{a(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Z9.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,o]of r.entries()){let c=new Map;for(let f of e.variables)if(o.length>0){let d=o[0].get(f);d&&c.set(f,d)}for(let f of e.aggregates){let d=this.computeAggregate(f.expression,o);c.set(f.variable,d)}let{SolutionMapping:l}=us(),u=new l;for(let[f,d]of c.entries())u.set(f,d);i.push(u)}if(i.length===0&&e.aggregates.length>0){let s=this.createEmptyAggregateResult(e);s&&i.push(s)}return i}groupSolutions(e,t){let r=new Map;if(t.length===0)return r.set("",e),r;for(let i of e){let s=this.computeGroupKey(i,t),o=r.get(s);o?o.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if($x(e.aggregation))return this.computeCustomAggregate(e,t);let r=this.extractValues(e,t),i=e.aggregation;switch(i){case"count":{let s=this.computeCount(r,e.distinct);return new hr.Literal(String(s),jx)}case"sum":{let s=this.computeSum(r);return new hr.Literal(String(s),ka)}case"avg":{let s=this.computeAvg(r);return new hr.Literal(String(s),ka)}case"min":{let s=this.computeMin(r);return s===void 0?new hr.Literal("",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}case"max":{let s=this.computeMax(r);return s===void 0?new hr.Literal("",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new hr.Literal(s||" ",hs)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new hr.Literal(" ",hs):typeof s=="number"?new hr.Literal(String(s),ka):new hr.Literal(String(s),hs)}default:{let s=i;throw new of(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,o=e5.CustomAggregateRegistry.getInstance().get(i);if(o||(o=t5.BUILT_IN_AGGREGATES[i]),!o)throw new of(`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 f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;o.step(c,u)}return o.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let o=s[0],c=parseFloat(o);return isNaN(c)?o:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=us(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if($x(s)){r.set(i.variable,new hr.Literal("0",ka));continue}switch(s){case"count":r.set(i.variable,new hr.Literal("0",jx));break;case"sum":case"avg":r.set(i.variable,new hr.Literal("0",ka));break;case"group_concat":r.set(i.variable,new hr.Literal(" ",hs));break;case"min":case"max":case"sample":r.set(i.variable,new hr.Literal("",hs));break;default:r.set(i.variable,new hr.Literal("",hs))}}return r}};nl.AggregateExecutor=Z1});var iS=S(Gp=>{"use strict";Object.defineProperty(Gp,"__esModule",{value:!0});Gp.ConstructExecutor=void 0;var r5=Yn(),Ma=Ae(),tS=Ne(),rS=qt(),n5=ku(),nS=class{static{a(this,"ConstructExecutor")}async execute(e,t){let r=[],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),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new r5.Triple(r,i,s)}isPropertyPath(e){return e.type==="path"}instantiateElement(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable: ${e.value}`);return r}if(e.type==="iri")return new Ma.IRI(e.value);if(e.type==="literal")return new tS.Literal(e.value,e.datatype?new Ma.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Unknown element type: ${e.type}`)}instantiateQuotedTriple(e,t){let r=this.instantiateQuotedSubject(e.subject,t),i=this.instantiateQuotedPredicate(e.predicate,t),s=this.instantiateQuotedObject(e.object,t);return new n5.QuotedTriple(r,i,s)}instantiateQuotedSubject(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple subject: ${e.value}`);if(r instanceof tS.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new Ma.IRI(e.value);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);throw new Error(`Invalid element type for quoted triple subject: ${e.type}`)}instantiateQuotedPredicate(e,t){if(e.type==="variable"){let r=t.get(e.value);if(!r)throw new Error(`Unbound variable in quoted triple predicate: ${e.value}`);if(!(r instanceof Ma.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new Ma.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 Ma.IRI(e.value);if(e.type==="blank")return new rS.BlankNode(e.value);if(e.type==="literal")return new tS.Literal(e.value,e.datatype?new Ma.IRI(e.datatype):void 0,e.language);if(e.type==="quoted")return this.instantiateQuotedTriple(e,t);let r=e;throw new Error(`Invalid element type for quoted triple object: ${r.type}`)}};Gp.ConstructExecutor=nS});var Vx=S(il=>{"use strict";Object.defineProperty(il,"__esModule",{value:!0});il.ServiceExecutor=il.ServiceExecutorError=void 0;var i5=us(),Ux=Ae(),s5=Ne(),o5=qt(),ja=class extends Error{static{a(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};il.ServiceExecutorError=ja;var sS=class{static{a(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,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 ja(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(o)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new ja(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new ja(`Failed to query remote SPARQL endpoint ${e} after ${this.maxRetries+1} attempts`,r)}parseJsonResults(e){return!e.results||!Array.isArray(e.results.bindings)?[]:e.results.bindings.map(t=>this.parseBinding(t))}parseBinding(e){let t=new i5.SolutionMapping;for(let[r,i]of Object.entries(e)){let s=this.parseRDFTerm(i);t.set(r,s)}return t}parseRDFTerm(e){switch(e.type){case"uri":return new Ux.IRI(e.value);case"literal":{let t=e.datatype?new Ux.IRI(e.datatype):void 0;return new s5.Literal(e.value,t,e["xml:lang"])}case"bnode":return new o5.BlankNode(e.value);default:throw new ja(`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))}};il.ServiceExecutor=sS});var Wx=S(sl=>{"use strict";Object.defineProperty(sl,"__esModule",{value:!0});sl.GraphExecutor=sl.GraphExecutorError=void 0;var qx=Ae(),zp=class extends Error{static{a(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};sl.GraphExecutorError=zp;var oS=class{static{a(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new zp(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new qx.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let o=i.get(t.value);if(o&&o instanceof qx.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:o.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let o of s)for await(let c of r(e.pattern,o)){let l=c.clone();l.set(t.value,o),yield l}}};sl.GraphExecutor=oS});var Gx=S(al=>{"use strict";Object.defineProperty(al,"__esModule",{value:!0});al.SPARQLGenerator=al.SPARQLGeneratorError=void 0;var ol=class extends Error{static{a(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};al.SPARQLGeneratorError=ol;var aS=class{static{a(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
|
|
49
49
|
${i}
|
|
50
50
|
}`}generateWhereClause(e,t=2){let r=" ".repeat(t);switch(e.type){case"bgp":return this.generateBGP(e,t);case"filter":return`${this.generateWhereClause(e.input,t)}
|
|
51
51
|
${r}FILTER(${this.generateExpression(e.expression)})`;case"join":return`${this.generateWhereClause(e.left,t)}
|
|
@@ -813,7 +813,7 @@ exo__BacklinksTableBlock_columns:${f==="[]"?" []":f}
|
|
|
813
813
|
`),console.log(`${"Rank".padEnd(6)}${"Term".padEnd(30)}${"Freq".padEnd(8)}Sample UIDs`),console.log("-".repeat(90)),c.forEach((u,f)=>{let d=`#${f+1}`.padEnd(6),h=u.term.padEnd(30),p=String(u.frequency).padEnd(8),y=u.sample_uids.join(", ");console.log(`${d}${h}${p}${y}`)})})}a(jN,"backfillOrphanTermsCommand");function $N(){let n=new se("backfill").description("Concept backfill tools for aiKnow assets");return n.addCommand(MN()),n.addCommand(jN()),n}a($N,"backfillCommand");var ky=require("path"),HN=require("fs"),QN=require("os");var Ny=require("child_process"),Ly=require("fs"),qN=require("path");var Zi=require("fs"),Dy=H(require("path")),UN=require("crypto");var LJ=/^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n([\s\S]*))?$/;function BN(n){let e=n.match(LJ);if(!e)return null;let[,t,r=""]=e,i=ar.load(t);if(i==null)return{frontmatter:{},body:r};if(typeof i!="object"||Array.isArray(i))throw new Error("frontmatter is not a YAML mapping");return{frontmatter:i,body:r}}a(BN,"parseFile");function kJ(n,e){let t=ar.dump(n,{lineWidth:-1,quotingType:'"',forceQuotes:!1,noRefs:!0}),r=e.length>0?e:"";return`---
|
|
814
814
|
${t}---
|
|
815
815
|
${r}`}a(kJ,"serializeFile");function VN(n,e,t={}){let r=Dy.default.dirname(n),i=Dy.default.basename(n),s=Dy.default.join(r,`.${i}.tmp.${process.pid}.${(0,UN.randomBytes)(6).toString("hex")}`);try{let o=(0,Zi.readFileSync)(n,"utf8"),c;try{c=BN(o)}catch(f){return{success:!1,verified:!1,reason:"parse-error",error:f.message}}if(!c)return{success:!1,verified:!1,reason:"no-frontmatter"};let l={...c.frontmatter,...e},u=kJ(l,c.body);if((0,Zi.writeFileSync)(s,u,"utf8"),(0,Zi.renameSync)(s,n),t.verifyKey!==void 0){let f=(0,Zi.readFileSync)(n,"utf8"),d;try{d=BN(f)}catch(p){return{success:!1,verified:!1,reason:"parse-error",error:p.message}}if(!d)return{success:!1,verified:!1,reason:"no-frontmatter"};let h=d.frontmatter[t.verifyKey];return h!==t.verifyValue?{success:!1,verified:!1,reason:"verify-mismatch",error:`expected ${t.verifyKey}=${String(t.verifyValue)}, got ${String(h)}`}:{success:!0,verified:!0}}return{success:!0,verified:!0}}catch(o){if((0,Zi.existsSync)(s))try{(0,Zi.unlinkSync)(s)}catch{}return{success:!1,verified:!1,reason:"fs-error",error:o.message}}}a(VN,"atomicUpdateFrontmatter");var MJ=/^claude-child-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,jJ=/^claude-child-([0-9a-f]{8})-(\d+)$/,$J="EffortStatusDoing";function WN(n){return e=>new Promise((t,r)=>{n(e,(i,s,o)=>{i?r(Object.assign(i,{stdout:s,stderr:o})):t(s)})})}a(WN,"makeExecPromise");async function BJ(n=Ny.exec){let e=WN(n),t;try{t=await e("tmux list-sessions -F '#{session_name}' 2>/dev/null")}catch{return[]}let r=[];for(let i of t.split(`
|
|
816
|
-
`).map(s=>s.trim()).filter(Boolean)){let s=MJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let o=jJ.exec(i);o&&r.push({sessionName:i,uuid:o[1],type:"short"})}return r}a(BJ,"listClaudeChildSessions");function UJ(n,e,t){let r=null,i=e.toLowerCase();function s(o){if(r)return;let c;try{c=(0,Ly.readdirSync)(o,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,qN.join)(o,l.name);if(l.isDirectory())s(u);else if(l.name.endsWith(".md")){let f=l.name.slice(0,-3).toLowerCase();(t==="full"&&f===i||t==="short"&&f.startsWith(i))&&(r=u)}}}return a(s,"walk"),s(n),r}a(UJ,"findVaultFile");function VJ(n,e){try{let i=(e??(s=>(0,Ly.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes($J):!1}catch{return!1}}a(VJ,"isTaskDoing");async function GN(n,e=Ny.exec,t){let r=await BJ(e),i=[];for(let s of r){let o=UJ(n,s.uuid,s.type);if(!o){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}VJ(o,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:o,reason:"vault task status != Doing"})}return i}a(GN,"detectOrphans");async function zN(n,e,t=Ny.exec,r=VN){let i=WN(t);if(e)return{ok:!0};let s=new Date().toISOString();if(n.taskFilePath)try{r(n.taskFilePath,{ems__Effort_status:"[[ems__EffortStatusFailed]]",aiTask__Task_lastError:`orphan recovery: ${n.reason}`,exo__Asset_updatedAt:s})}catch(o){return{ok:!1,error:`vault update failed: ${o.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}a(zN,"recoverOrphan");function qJ(){return process.env.EXOCORTEX_VAULT??(0,ky.join)((0,QN.homedir)(),"vault-2025")}a(qJ,"defaultVault");function KN(){return new se("recover").description("Detect and recover orphaned claude-child tmux sessions. A session is orphaned when the corresponding vault task is not in Doing status. Default mode: dry-run (no changes). Use --apply to perform recovery.").option("--vault <path>","Path to Obsidian vault",qJ()).option("--dry-run","List orphans without applying changes (default)",!1).option("--apply","Apply orphan recovery: set Failed + kill tmux session",!1).action(async n=>{let e=(0,ky.resolve)(n.vault);if(!(0,HN.existsSync)(e)){console.error(`[recover] vault not found: ${e}`),process.exitCode=1;return}let t=!n.apply;console.log(`[recover] vault=${e} mode=${t?"dry-run":"apply"}`);let r=await GN(e);if(r.length===0){console.log("[recover] No orphaned claude-child sessions found.");return}console.log(`[recover] Found ${r.length} orphan(s):`);for(let o of r){let c=o.taskFilePath??"(not found in vault)";console.log(` session=${o.sessionName} uuid=${o.taskUuid} reason=${o.reason}`),console.log(` file=${c}`)}if(t){console.log("[recover] Dry-run mode: no changes applied. Use --apply to recover.");return}let i=0,s=0;for(let o of r){let c=await zN(o,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${o.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${o.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}a(KN,"recoverCommand");function YN(n){n.addCommand(aD()),n.addCommand(fD()),n.addCommand(dD())}a(YN,"addQuerySubcommands");function XN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.174.
|
|
816
|
+
`).map(s=>s.trim()).filter(Boolean)){let s=MJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let o=jJ.exec(i);o&&r.push({sessionName:i,uuid:o[1],type:"short"})}return r}a(BJ,"listClaudeChildSessions");function UJ(n,e,t){let r=null,i=e.toLowerCase();function s(o){if(r)return;let c;try{c=(0,Ly.readdirSync)(o,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,qN.join)(o,l.name);if(l.isDirectory())s(u);else if(l.name.endsWith(".md")){let f=l.name.slice(0,-3).toLowerCase();(t==="full"&&f===i||t==="short"&&f.startsWith(i))&&(r=u)}}}return a(s,"walk"),s(n),r}a(UJ,"findVaultFile");function VJ(n,e){try{let i=(e??(s=>(0,Ly.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes($J):!1}catch{return!1}}a(VJ,"isTaskDoing");async function GN(n,e=Ny.exec,t){let r=await BJ(e),i=[];for(let s of r){let o=UJ(n,s.uuid,s.type);if(!o){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}VJ(o,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:o,reason:"vault task status != Doing"})}return i}a(GN,"detectOrphans");async function zN(n,e,t=Ny.exec,r=VN){let i=WN(t);if(e)return{ok:!0};let s=new Date().toISOString();if(n.taskFilePath)try{r(n.taskFilePath,{ems__Effort_status:"[[ems__EffortStatusFailed]]",aiTask__Task_lastError:`orphan recovery: ${n.reason}`,exo__Asset_updatedAt:s})}catch(o){return{ok:!1,error:`vault update failed: ${o.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}a(zN,"recoverOrphan");function qJ(){return process.env.EXOCORTEX_VAULT??(0,ky.join)((0,QN.homedir)(),"vault-2025")}a(qJ,"defaultVault");function KN(){return new se("recover").description("Detect and recover orphaned claude-child tmux sessions. A session is orphaned when the corresponding vault task is not in Doing status. Default mode: dry-run (no changes). Use --apply to perform recovery.").option("--vault <path>","Path to Obsidian vault",qJ()).option("--dry-run","List orphans without applying changes (default)",!1).option("--apply","Apply orphan recovery: set Failed + kill tmux session",!1).action(async n=>{let e=(0,ky.resolve)(n.vault);if(!(0,HN.existsSync)(e)){console.error(`[recover] vault not found: ${e}`),process.exitCode=1;return}let t=!n.apply;console.log(`[recover] vault=${e} mode=${t?"dry-run":"apply"}`);let r=await GN(e);if(r.length===0){console.log("[recover] No orphaned claude-child sessions found.");return}console.log(`[recover] Found ${r.length} orphan(s):`);for(let o of r){let c=o.taskFilePath??"(not found in vault)";console.log(` session=${o.sessionName} uuid=${o.taskUuid} reason=${o.reason}`),console.log(` file=${c}`)}if(t){console.log("[recover] Dry-run mode: no changes applied. Use --apply to recover.");return}let i=0,s=0;for(let o of r){let c=await zN(o,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${o.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${o.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}a(KN,"recoverCommand");function YN(n){n.addCommand(aD()),n.addCommand(fD()),n.addCommand(dD())}a(YN,"addQuerySubcommands");function XN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.174.5");let t=e.command("exoql").description("ExoQL query execution and cache management");YN(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return YN(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(vD()),e.addCommand(ED()),e.addCommand(TD()),e.addCommand(xD()),e.addCommand(CD()),e.addCommand(FD()),e.addCommand(kD()),e.addCommand(KD()),e.addCommand(JD()),e.addCommand(nN()),e.addCommand(oN()),e.addCommand(aN()),e.addCommand(lN()),e.addCommand(vN()),e.addCommand(TN()),e.addCommand(ON()),e.addCommand(FN()),e.addCommand($N()),e.addCommand(KN()),e}a(XN,"createProgram");XN().parse();0&&(module.exports={createProgram});
|
|
817
817
|
/*! Bundled license information:
|
|
818
818
|
|
|
819
819
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED