@kitelev/exocortex-cli 15.143.0 → 15.144.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v15.143.0
2
+ // @kitelev/exocortex-cli v15.144.1
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 `+Dd.join(", ")+", got '"+(this.terminals_[ut]||ut)+"'":Ay="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 a=i;for(;i<e.length&&e[i]!==">";)i++;if(e[i]===">"){let c=e.substring(a,i);i++;let l=this.findDeclarationEnd(e,i);t.push({uri:c,startPos:s,endPos:l}),i=l;continue}else throw new Tc(`Unclosed IRI in PREFIX* declaration at position ${a}`)}else throw new Tc(`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,"")}};ba.PrefixStarTransformer=O_;var Tc=class extends Error{static{o(this,"PrefixStarTransformerError")}constructor(e){super(`PREFIX* transformation error: ${e}`),this.name="PrefixStarTransformerError"}};ba.PrefixStarTransformerError=Tc});var P_=S(xc=>{"use strict";Object.defineProperty(xc,"__esModule",{value:!0});xc.DescribeOptionsTransformer=xc.DescribeOptionsTransformerError=void 0;var Vh=class extends Error{static{o(this,"DescribeOptionsTransformerError")}constructor(e){super(e),this.name="DescribeOptionsTransformerError"}};xc.DescribeOptionsTransformerError=Vh;var Ac=class n{static{o(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 a=parseInt(s[1],10);if(a<0)throw new Vh(`DESCRIBE DEPTH must be a non-negative integer, got: ${a}`);r.depth=a,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}};xc.DescribeOptionsTransformer=Ac;Ac.DEPTH_PATTERN=/\bDEPTH\s+(\d+)/gi;Ac.SYMMETRIC_PATTERN=/\bSYMMETRIC\b/gi;Ac.DESCRIBE_QUERY_PATTERN=/\bDESCRIBE\b/i});var oA=S(Cc=>{"use strict";Object.defineProperty(Cc,"__esModule",{value:!0});Cc.DirectionalLangTagTransformerError=Cc.DirectionalLangTagTransformer=void 0;var Uh=class n{static{o(this,"DirectionalLangTagTransformer")}constructor(){this.directionMappings=new Map}transform(e){return this.directionMappings.clear(),e.replace(n.DIRECTIONAL_TAG_REGEX,(t,r,i,s,a)=>{let c=s.toLowerCase();return this.directionMappings.set(c,a),`${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()}};Cc.DirectionalLangTagTransformer=Uh;Uh.DIRECTIONAL_TAG_REGEX=/(["'])((?:[^\\]|\\.)*?)\1@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)--(ltr|rtl)/g;var F_=class extends Error{static{o(this,"DirectionalLangTagTransformerError")}constructor(e){super(`Directional language tag transformation error: ${e}`),this.name="DirectionalLangTagTransformerError"}};Cc.DirectionalLangTagTransformerError=F_});var cA=S(Rc=>{"use strict";Object.defineProperty(Rc,"__esModule",{value:!0});Rc.TripleTermTransformerError=Rc.TripleTermTransformer=void 0;var D_=class{static{o(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 Ic("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],a=this.extractTripleTerm(r,s);if(a){let c=this.convertToStandardSyntax(a.content);r=r.substring(0,s)+c+r.substring(s+a.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 a=e.substring(t,s+2);return{content:a,length:a.length}}r=s+2;continue}r++;continue}r++}if(i>0)throw new Ic(`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 Ic(`Invalid triple term syntax: ${e.substring(0,50)}...`);return`<< ${t[1]} >>`}};Rc.TripleTermTransformer=D_;var Ic=class extends Error{static{o(this,"TripleTermTransformerError")}constructor(e){super(`Triple term transformation error: ${e}`),this.name="TripleTermTransformerError"}};Rc.TripleTermTransformerError=Ic});var L_=S(qh=>{"use strict";Object.defineProperty(qh,"__esModule",{value:!0});qh.VaultPrefixTransformer=void 0;var QM=/PREFIX\s+(\w+)\s*:/gi,YM=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"]),N_=class{static{o(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[a,c]of this.vaultPrefixes)!t.has(a.toLowerCase())&&!YM.has(a.toLowerCase())&&r.push({prefix:a,baseIRI:c});if(r.length===0)return e;let i="",s=0;for(;s<e.length;){let a=e[s];if(a==='"'||a==="'"){let l=this.skipLiteral(e,s);i+=e.substring(s,l),s=l;continue}if(a==="<"){let l=e.indexOf(">",s);l!==-1?(i+=e.substring(s,l+1),s=l+1):(i+=a,s++);continue}if(a==="#"){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+=a,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 a=t+i.length+1,c=a;for(;c<e.length&&/[a-zA-Z0-9_.%-]/.test(e[c]);)c++;if(c===a)continue;let l=e.substring(a,c);return{iri:`<${s}${l}.md>`,endIndex:c}}return null}findDeclaredPrefixes(e){let t=new Set,r=new RegExp(QM.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}};qh.VaultPrefixTransformer=N_});var Oc=S(wn=>{"use strict";var KM=wn&&wn.__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:o(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),XM=wn&&wn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),JM=wn&&wn.__importStar||(function(){var n=o(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"&&KM(t,e,r[i]);return XM(t,e),t}})();Object.defineProperty(wn,"__esModule",{value:!0});wn.SPARQLParser=wn.ExoQLParser=wn.SPARQLParseError=void 0;var lA=JM(sA()),k_=I_(),M_=R_(),uA=aA(),j_=P_(),ZM=oA(),$_=cA(),ej=L_(),nr=class extends Error{static{o(this,"SPARQLParseError")}constructor(e,t,r,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=r}};wn.SPARQLParseError=nr;var Wh=class{static{o(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new lA.Parser({sparqlStar:!0}),this.generator=new lA.Generator({sparqlStar:!0}),this.caseWhenTransformer=new k_.CaseWhenTransformer,this.lateralTransformer=new M_.LateralTransformer,this.prefixStarTransformer=new uA.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new j_.DescribeOptionsTransformer,this.directionalLangTagTransformer=new ZM.DirectionalLangTagTransformer,this.tripleTermTransformer=new $_.TripleTermTransformer,this.vaultPrefixTransformer=new ej.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 j_.DescribeOptionsTransformerError)throw new nr(t.message);if(t instanceof M_.LateralTransformerError)throw new nr(t.message);if(t instanceof k_.CaseWhenTransformerError)throw new nr(t.message);if(t instanceof $_.TripleTermTransformerError)throw new nr(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 nr(`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 j_.DescribeOptionsTransformerError)throw new nr(t.message);if(t instanceof uA.PrefixStarTransformerError)throw new nr(t.message);if(t instanceof M_.LateralTransformerError)throw new nr(t.message);if(t instanceof k_.CaseWhenTransformerError)throw new nr(t.message);if(t instanceof $_.TripleTermTransformerError)throw new nr(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 nr(`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 nr(`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 nr("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 nr("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new nr(`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 nr(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};wn.ExoQLParser=Wh;wn.SPARQLParser=Wh});var bo=S(Gh=>{"use strict";Object.defineProperty(Gh,"__esModule",{value:!0});Gh.AlgebraTranslatorError=void 0;var B_=class extends Error{static{o(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};Gh.AlgebraTranslatorError=B_});var zh=S(ts=>{"use strict";Object.defineProperty(ts,"__esModule",{value:!0});ts.isVariableExpression=tj;ts.isVariableTerm=rj;ts.isNamedNode=nj;ts.isLiteral=ij;ts.isPropertyPath=sj;ts.isAggregateExpression=aj;ts.isOperationExpression=oj;ts.isFunctionCallExpression=cj;function tj(n){return typeof n=="object"&&n!==null&&"expression"in n&&"variable"in n}o(tj,"isVariableExpression");function rj(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Variable"}o(rj,"isVariableTerm");function nj(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="NamedNode"}o(nj,"isNamedNode");function ij(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Literal"}o(ij,"isLiteral");function sj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="path"}o(sj,"isPropertyPath");function aj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="aggregate"}o(aj,"isAggregateExpression");function oj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="operation"}o(oj,"isOperationExpression");function cj(n){return typeof n=="object"&&n!==null&&"type"in n&&(n.type==="functionCall"||n.type==="functioncall")}o(cj,"isFunctionCallExpression")});var fA=S(Hh=>{"use strict";Object.defineProperty(Hh,"__esModule",{value:!0});Hh.TripleTranslator=void 0;var an=bo(),V_=class{static{o(this,"TripleTranslator")}constructor(){this.directionMappings=new Map}setDirectionMappings(e){this.directionMappings=e}translateBGP(e){if(!("triples"in e)||!Array.isArray(e.triples))throw new an.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 an.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 an.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new an.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 an.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new an.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new an.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new an.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new an.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 an.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new an.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 an.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new an.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 an.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 an.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};Hh.TripleTranslator=V_});var dA=S(Qh=>{"use strict";Object.defineProperty(Qh,"__esModule",{value:!0});Qh.ExpressionTranslator=void 0;var Pc=bo(),U_=class{static{o(this,"ExpressionTranslator")}constructor(e){this.translateWhereFn=e.translateWhere,this.translateBGPFn=e.translateBGP,this.translatePatternFn=e.translatePattern}translateExpression(e){if(!e)throw new Pc.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 Pc.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Pc.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(a=>!("patterns"in a)||"termType"in a);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(a=>this.translateExpression(a))}: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(a=>this.translateExpression(a))}}translateExistsExpression(e){if(!e.args||e.args.length!==1)throw new Pc.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 Pc.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 Pc.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"}}};Qh.ExpressionTranslator=U_});var mA=S(Yh=>{"use strict";Object.defineProperty(Yh,"__esModule",{value:!0});Yh.PatternTranslator=void 0;var hA=R_(),Pr=bo(),pA=zh(),q_=class{static{o(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 Pr.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(a=>a.type==="filter"),r=e.filter(a=>a.type==="bind"),i=e.filter(a=>a.type!=="filter"&&a.type!=="bind"),s;if(i.length===0)s={type:"bgp",triples:[]};else if(i.length===1)if(i[0].type==="optional"){let a=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:a?this.translateExpressionFn(a):void 0}}else s=this.translatePattern(i[0]);else{if(i[0].type==="optional"){let a=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:a?this.translateExpressionFn(a):void 0}}else s=this.translatePattern(i[0]);for(let a=1;a<i.length;a++){let c=i[a];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 a of r)s=this.translateBind(a,s);for(let a of t)s={type:"filter",expression:this.translateExpressionFn(a.expression),input:s};return s}translatePattern(e){if(!e||!e.type)throw new Pr.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 Pr.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new Pr.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 Pr.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 Pr.AlgebraTranslatorError("UNION pattern must have at least 2 patterns");let t=o(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 Pr.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 Pr.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 a=s.startsWith("?")?s.slice(1):s;t.add(a)}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,a=i;if(a)if(a.termType==="NamedNode")t[s]={type:"iri",value:a.value};else if(a.termType==="Literal"){let c=a,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 Pr.AlgebraTranslatorError(`Unsupported VALUES term type: ${a.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new Pr.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 Pr.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 Pr.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new Pr.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 Pr.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new Pr.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 Pr.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 Pr.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,pA.isVariableTerm)(i)&&i.value===hA.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,pA.isVariableTerm)(i)&&i.value===hA.LateralTransformer.LATERAL_MARKER))}}};Yh.PatternTranslator=q_});var yA=S(Kh=>{"use strict";Object.defineProperty(Kh,"__esModule",{value:!0});Kh.AggregateTranslator=void 0;var gA=bo(),lj=zh(),W_=class{static{o(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,lj.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)),a=["=","!=","<",">","<=",">="],c=["&&","||","!"],l=["+","-","*","/"];return a.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=o(()=>{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,a=i;if(a.termType==="NamedNode"&&typeof a.value=="string")s=a.value;else if("value"in a)s=String(a.value);else throw new gA.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 gA.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)}}}};Kh.AggregateTranslator=W_});var Fc=S(va=>{"use strict";Object.defineProperty(va,"__esModule",{value:!0});va.AlgebraTranslator=va.ExoQLAlgebraTranslator=va.AlgebraTranslatorError=void 0;var Xh=bo(),Jh=zh(),uj=fA(),fj=dA(),dj=mA(),hj=yA(),pj=bo();Object.defineProperty(va,"AlgebraTranslatorError",{enumerable:!0,get:o(function(){return pj.AlgebraTranslatorError},"get")});var Zh=class{static{o(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new uj.TripleTranslator,this.expressionTranslator=new fj.ExpressionTranslator({translateWhere:o(e=>this.patternTranslator.translateWhere(e),"translateWhere"),translateBGP:o(e=>this.tripleTranslator.translateBGP(e),"translateBGP"),translatePattern:o(e=>this.patternTranslator.translatePattern(e),"translatePattern")}),this.patternTranslator=new dj.PatternTranslator({translateExpression:o(e=>this.expressionTranslator.translateExpression(e),"translateExpression"),translateSelect:o(e=>this.translateSelect(e),"translateSelect"),translateBGP:o(e=>this.tripleTranslator.translateBGP(e),"translateBGP")}),this.aggregateTranslator=new hj.AggregateTranslator({translateExpression:o(e=>this.expressionTranslator.translateExpression(e),"translateExpression")})}setDirectionMappings(e){this.tripleTranslator.setDirectionMappings(e),this.patternTranslator.setDirectionMappings(e)}translate(e){if(e.type!=="query")throw new Xh.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 Xh.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new Xh.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),a=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,r);if((s.length>0||a.length>0||c.length>0)&&(t={type:"group",variables:a,aggregates:s,having:c.length>0?c:void 0,input:t}),i.length>0){for(let u of i)if((0,Jh.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,Jh.isVariableTerm)(u)||(0,Jh.isVariableExpression)(u)).map(u=>(0,Jh.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 Xh.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 a of s)a.termType==="Wildcard"||a.value==="*"||(a.termType==="Variable"?t.push({type:"variable",value:a.value}):a.termType==="NamedNode"&&t.push({type:"iri",value:a.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}}};va.ExoQLAlgebraTranslator=Zh;va.AlgebraTranslator=Zh});var rs=S(ep=>{"use strict";Object.defineProperty(ep,"__esModule",{value:!0});ep.SolutionMapping=void 0;var _A=Ve(),SA=Ce(),bA=Gt(),G_=class n{static{o(this,"SolutionMapping")}constructor(e){this.bindings=e?new Map(e):new Map}get(e){return this.bindings.get(e)}set(e,t){this.bindings.set(e,t)}has(e){return this.bindings.has(e)}variables(){return Array.from(this.bindings.keys())}getBindings(){return new Map(this.bindings)}isCompatibleWith(e){for(let[t,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof _A.Literal&&t instanceof _A.Literal?e.equals(t):e instanceof SA.IRI&&t instanceof SA.IRI?e.value===t.value:e instanceof bA.BlankNode&&t instanceof bA.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}};ep.SolutionMapping=G_});var wA=S(Dc=>{"use strict";Object.defineProperty(Dc,"__esModule",{value:!0});Dc.PropertyPathExecutor=Dc.PropertyPathExecutorError=void 0;var mj=rs(),tp=Ce(),vA=Gt(),gj=Ve(),ju=class extends Error{static{o(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Dc.PropertyPathExecutorError=ju;var z_=class{static{o(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){if(this.isLiteralElement(e)||this.isLiteralElement(r)){let a=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 ${a} 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 a of i){let c=await this.evaluatePath(a,t,s);for(let l of c){let u=new mj.SolutionMapping;this.isVariable(e)&&u.set(e.value,a),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new ju("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let a=t.merge(s);a!==null&&(yield a)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let a=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,a,c?r:null);for(let 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 a=await this.evaluatePathItem(e,s,r);for(let c of a)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new tp.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&a.add(c.subject);return a}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){let i=new Set,s=new Set,a=[{node:e,depth:0}];for(;a.length>0;){let c=a.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),a.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 a of s)i.add(a);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new tp.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&a.add(c.object);return a}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(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 tp.IRI(e.value));break;case"blank":t.add(new vA.BlankNode(e.value));break;default:throw new ju(`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 tp.IRI)return{type:"iri",value:r.value};if(r instanceof vA.BlankNode)return{type:"blank",value:r.id};if(r instanceof gj.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}};Dc.PropertyPathExecutor=z_});var Y_=S(Nc=>{"use strict";Object.defineProperty(Nc,"__esModule",{value:!0});Nc.BGPExecutor=Nc.BGPExecutorError=void 0;var rp=rs(),wa=Ce(),H_=Ve(),np=Gt(),ip=bu(),yj=wA(),Ur=class extends Error{static{o(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Nc.BGPExecutorError=Ur;var Q_=class{static{o(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new yj.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new rp.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 rp.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 Ur("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),a=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new Ur("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,a,t);for(let l of c){let u=new rp.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let a=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(a,r)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){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),a=await this.tripleStore.match(r,i,s);for(let c of a){let l=new rp.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 ip.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof wa.IRI&&e.value===t.value;case"literal":return!(!(t instanceof H_.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof np.BlankNode&&e.value===t.id;case"quoted":return t instanceof ip.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let a of this.matchTriplePattern(s)){let c=i.merge(a);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof wa.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 wa.IRI(e.value);case"blank":return new np.BlankNode(e.value);case"literal":throw new Ur("Literals cannot appear in subject position");case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new wa.IRI(e.predicate.value):(()=>{throw new Ur("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new ip.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new wa.IRI(e.value);case"literal":throw new Ur("Literals cannot appear in predicate position");case"blank":throw new Ur("Blank nodes cannot appear in predicate position");case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new wa.IRI(e.value);case"literal":return new H_.Literal(e.value,e.datatype?new wa.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new np.BlankNode(e.value);case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof wa.IRI)return{type:"iri",value:e.value};if(e instanceof H_.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof np.BlankNode)return{type:"blank",value:e.id};if(e instanceof ip.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new Ur(`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)}}};Nc.BGPExecutor=Q_});var EA=S(sp=>{"use strict";Object.defineProperty(sp,"__esModule",{value:!0});sp.StringFunctions=void 0;var Lc=Ce(),Ea=Ve(),K_=Gt(),$u=class n{static{o(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof Lc.IRI||e instanceof Ea.Literal?e.value:e instanceof K_.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof Ea.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof Ea.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=n.parseDirectionalLangTag(e),[s,a]=n.parseDirectionalLangTag(t),c=r.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":a&&i!==a?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static 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",a=s.includes("u")?s:s+"u",c=new RegExp(t,a);return e.replace(c,r)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static 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 Ea.Literal)r=e.value;else if(e instanceof Lc.IRI)r=e.value;else if(e instanceof K_.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 Ea.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof Lc.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 Ea.Literal(s,new Lc.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 Ea.Literal)t=e.value;else if(e instanceof Lc.IRI)t=e.value;else if(e instanceof K_.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 Ea.Literal(r,new Lc.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}};sp.StringFunctions=$u;$u.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];$u.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 TA=S(ap=>{"use strict";Object.defineProperty(ap,"__esModule",{value:!0});ap.MathFunctions=void 0;var X_=class{static{o(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=X_});var cp=S(op=>{"use strict";Object.defineProperty(op,"__esModule",{value:!0});op.DateTimeParsing=void 0;var _j=Ce(),Sj=Ve(),J_=class n{static{o(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"),a="",c="";if(s===-1?a=r:(a=r.substring(0,s),c=r.substring(s+1)),a){let l=a.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(a!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${a}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let 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 a=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||a>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),a>0&&(l+=`${a}M`),(c>0||s===0&&a===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return n.parseDayTimeDuration(e),new Sj.Literal(e,new _j.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,a=parseInt(r[3],10),c=r[4],l=new Date(Date.UTC(i,s,a));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,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),a=parseInt(r[3],10),c=r[4],l=r[5];if(i<0||i>24||s<0||s>59||a<0||a>59||i===24&&(s!==0||a!==0))return null;let u=0;if(c){let d=c.padEnd(3,"0").slice(0,3);u=parseInt(d,10)}let f=i*60*60*1e3+s*60*1e3+a*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),_=parseInt(d[3],10),b=h*(p*60+_)*60*1e3;f-=b}}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),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+a;return i?-c:c}static formatYearMonthDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/12),s=r%12,a=t?"-P":"P";return i>0&&(a+=`${i}Y`),(s>0||i===0)&&(a+=`${s}M`),a}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:a,negative:i}}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,a=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let 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&&(a=parseFloat(p[1]),d=d.substring(p[0].length));let _=d.match(/^(\d+(?:\.\d+)?)S$/);if(_&&(c=parseFloat(_[1]),d=d.substring(_[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:a,seconds:c}}};op.DateTimeParsing=J_});var AA=S(lp=>{"use strict";Object.defineProperty(lp,"__esModule",{value:!0});lp.DateTimeArithmetic=void 0;var on=Ce(),Te=Ve(),Xe=cp(),Z_=class{static{o(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r),a=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(a.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-a.getTime(),l=Xe.DateTimeParsing.formatDayTimeDuration(c);return new Te.Literal(l,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c);return new Te.Literal(l.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c);return new Te.Literal(l.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+a,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 Te.Literal(h,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-a,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 Te.Literal(h,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0),new Te.Literal(s.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0),new Te.Literal(s.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=`${l}-${u}-${f}`;return new Te.Literal(d,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=`${l}-${u}-${f}`;return new Te.Literal(d,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseDayTimeDuration(r),a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=Xe.DateTimeParsing.formatDayTimeDuration(s+a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseDayTimeDuration(r),a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=Xe.DateTimeParsing.formatDayTimeDuration(s-a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof Te.Literal?e.value:e,i=Xe.DateTimeParsing.parseDayTimeDuration(r),s=Xe.DateTimeParsing.formatDayTimeDuration(i*t);return new Te.Literal(s,new on.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 Te.Literal?e.value:e,i=Xe.DateTimeParsing.parseDayTimeDuration(r),s=Xe.DateTimeParsing.formatDayTimeDuration(i/t);return new Te.Literal(s,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseYearMonthDuration(r),a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=Xe.DateTimeParsing.formatYearMonthDuration(s+a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseYearMonthDuration(r),a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=Xe.DateTimeParsing.formatYearMonthDuration(s-a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/1e3}};lp.DateTimeArithmetic=Z_});var xA=S(up=>{"use strict";Object.defineProperty(up,"__esModule",{value:!0});up.DateTimeAccessors=void 0;var Bu=Ce(),Lt=Ve(),Tt=cp(),e1=class{static{o(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 Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static durationYears(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.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),a=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);a===0?r=`${c}PT${l}H`:r=`${c}PT${l}H${a}M`}else{let s=-t.getTimezoneOffset(),a=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?r=`${l}PT${a}H`:r=`${l}PT${a}H${c}M`}}return new Lt.Literal(r,new Bu.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 Lt.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let we=i.getUTCFullYear(),z=String(i.getUTCMonth()+1).padStart(2,"0"),G=String(i.getUTCDate()).padStart(2,"0"),F=String(i.getUTCHours()).padStart(2,"0"),j=String(i.getUTCMinutes()).padStart(2,"0"),te=String(i.getUTCSeconds()).padStart(2,"0"),Ye=i.getUTCMilliseconds(),st=`${we}-${z}-${G}T${F}:${j}:${te}`;return Ye>0&&(st+=`.${String(Ye).padStart(3,"0")}`),new Lt.Literal(st,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof Lt.Literal?t.value:t,a=Tt.DateTimeParsing.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(a)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+a),f=u.getUTCFullYear(),d=String(u.getUTCMonth()+1).padStart(2,"0"),h=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),_=String(u.getUTCMinutes()).padStart(2,"0"),b=String(u.getUTCSeconds()).padStart(2,"0"),E=u.getUTCMilliseconds(),v=a>=0?"+":"-",A=Math.floor(Math.abs(a)/(3600*1e3)),R=Math.floor(Math.abs(a)%(3600*1e3)/(60*1e3)),B=`${v}${String(A).padStart(2,"0")}:${String(R).padStart(2,"0")}`,W=`${f}-${d}-${h}T${p}:${_}:${b}`;return E>0&&(W+=`.${String(E).padStart(3,"0")}`),W+=B,new Lt.Literal(W,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t);return r<i}static dateAfter(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t);return r>i}static dateInRange(e,t,r){let i=Tt.DateTimeParsing.parseDate(e),s=Tt.DateTimeParsing.parseDate(t),a=Tt.DateTimeParsing.parseDate(r);return i>=s&&i<=a}static compareDurations(e,t,r){let i=e instanceof Lt.Literal?e.value:e,s=t instanceof Lt.Literal?t.value:t,a=Tt.DateTimeParsing.parseDayTimeDuration(i),c=Tt.DateTimeParsing.parseDayTimeDuration(s);switch(r){case"=":return a===c;case"!=":return a!==c;case"<":return a<c;case">":return a>c;case"<=":return a<=c;case">=":return a>=c;default:throw new Error(`compareDurations: unknown operator: ${r}`)}}static dateDiffMinutes(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.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 Lt.Literal?e.value:e,i=t instanceof Lt.Literal?t.value:t,s=Tt.DateTimeParsing.parseXSDTime(r),a=Tt.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(a===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-a,l=Tt.DateTimeParsing.formatDayTimeDuration(c);return new Lt.Literal(l,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let r=e instanceof Lt.Literal?e.value:e,i=t instanceof Lt.Literal?t.value:t,s=Tt.DateTimeParsing.parseXSDDate(r),a=Tt.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);if(a===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-a.getTime(),l=Math.round(c/(1440*60*1e3)),u=Tt.DateTimeParsing.formatDateDuration(l);return new Lt.Literal(u,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};up.DateTimeAccessors=e1});var r1=S(fp=>{"use strict";Object.defineProperty(fp,"__esModule",{value:!0});fp.DateTimeFunctions=void 0;var kc=cp(),ir=AA(),gt=xA(),t1=class{static{o(this,"DateTimeFunctions")}static parseDate(e){return kc.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return kc.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return kc.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return kc.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return kc.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return kc.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return gt.DateTimeAccessors.year(e)}static month(e){return gt.DateTimeAccessors.month(e)}static day(e){return gt.DateTimeAccessors.day(e)}static hours(e){return gt.DateTimeAccessors.hours(e)}static minutes(e){return gt.DateTimeAccessors.minutes(e)}static seconds(e){return gt.DateTimeAccessors.seconds(e)}static durationDays(e){return gt.DateTimeAccessors.durationDays(e)}static durationHours(e){return gt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return gt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return gt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return gt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return gt.DateTimeAccessors.durationMonths(e)}static timezone(e){return gt.DateTimeAccessors.timezone(e)}static tz(e){return gt.DateTimeAccessors.tz(e)}static adjust(e,t){return gt.DateTimeAccessors.adjust(e,t)}static now(){return gt.DateTimeAccessors.now()}static dateBefore(e,t){return gt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return gt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,r){return gt.DateTimeAccessors.dateInRange(e,t,r)}static compareDurations(e,t,r){return gt.DateTimeAccessors.compareDurations(e,t,r)}static dateDiffMinutes(e,t){return gt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return gt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return gt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return gt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return gt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return gt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return gt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return gt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return ir.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return ir.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return ir.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return ir.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return ir.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return ir.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return ir.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return ir.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return ir.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return ir.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return ir.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return ir.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return ir.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return ir.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return ir.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return ir.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return ir.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return ir.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return ir.DateTimeArithmetic.durationToSeconds(e)}};fp.DateTimeFunctions=t1});var CA=S(hp=>{"use strict";Object.defineProperty(hp,"__esModule",{value:!0});hp.LogicalFunctions=void 0;var bj=Ce(),Mc=Ve(),vj=Gt(),dp=r1(),n1=class n{static{o(this,"LogicalFunctions")}static compare(e,t,r){if(n.isDayTimeDurationValue(e)&&n.isDayTimeDurationValue(t))return dp.DateTimeFunctions.compareDurations(e instanceof Mc.Literal?e:String(e),t instanceof Mc.Literal?t:String(t),r);if(n.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return dp.DateTimeFunctions.compareDurations(e instanceof Mc.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&n.isDayTimeDurationValue(t))return dp.DateTimeFunctions.compareDurations(e,t instanceof Mc.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 Mc.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 Mc.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 dp.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof bj.IRI?e.value:e instanceof vj.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}};hp.LogicalFunctions=n1});var IA=S(pp=>{"use strict";Object.defineProperty(pp,"__esModule",{value:!0});pp.RDFTermFunctions=void 0;var Fr=Ce(),bt=Ve(),oi=Gt(),jc=bu(),i1=Sn(),s1=class n{static{o(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 Fr.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Fr.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 Fr.IRI}static isBlank(e){return e===void 0?!1:e instanceof oi.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof bt.Literal}static isTriple(e){return e===void 0?!1:e instanceof jc.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 Fr.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 Fr.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 Fr.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 Fr.IRI&&t instanceof Fr.IRI)return e.value===t.value;if(e instanceof oi.BlankNode&&t instanceof oi.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 Fr.IRI)return e;if(e instanceof bt.Literal)return new Fr.IRI(e.value);throw e instanceof oi.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,i1.v4)().replace(/-/g,"").substring(0,12)}`;return new oi.BlankNode(t)}if(e instanceof bt.Literal)return new oi.BlankNode(e.value);if(e instanceof oi.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 Fr.IRI)i=t;else if(t instanceof bt.Literal)i=new Fr.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 a;if(r instanceof bt.Literal)a=r.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(a!=="ltr"&&a!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${a}'. Must be 'ltr' or 'rtl'`);return new bt.Literal(i,void 0,s,a)}static uuid(){let e=(0,i1.v4)();return new Fr.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,i1.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 Fr.IRI)){let c=t instanceof bt.Literal?"Literal":t instanceof oi.BlankNode?"BlankNode":t instanceof jc.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,a=r;return new jc.QuotedTriple(i,s,a)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.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 jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.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 jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};pp.RDFTermFunctions=s1});var RA=S(mp=>{"use strict";Object.defineProperty(mp,"__esModule",{value:!0});mp.HashFunctions=void 0;var a1=class{static{o(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")}};mp.HashFunctions=a1});var yp=S(gp=>{"use strict";Object.defineProperty(gp,"__esModule",{value:!0});gp.BuiltInFunctions=void 0;var sr=EA(),Ta=TA(),oe=r1(),$c=CA(),Ot=IA(),Vu=RA(),o1=class{static{o(this,"BuiltInFunctions")}static str(...e){return sr.StringFunctions.str(...e)}static lang(...e){return sr.StringFunctions.lang(...e)}static langdir(...e){return sr.StringFunctions.langdir(...e)}static langMatches(...e){return sr.StringFunctions.langMatches(...e)}static regex(...e){return sr.StringFunctions.regex(...e)}static contains(...e){return sr.StringFunctions.contains(...e)}static strStarts(...e){return sr.StringFunctions.strStarts(...e)}static strEnds(...e){return sr.StringFunctions.strEnds(...e)}static strlen(...e){return sr.StringFunctions.strlen(...e)}static ucase(...e){return sr.StringFunctions.ucase(...e)}static lcase(...e){return sr.StringFunctions.lcase(...e)}static substr(...e){return sr.StringFunctions.substr(...e)}static strBefore(...e){return sr.StringFunctions.strBefore(...e)}static strAfter(...e){return sr.StringFunctions.strAfter(...e)}static concat(...e){return sr.StringFunctions.concat(...e)}static replace(...e){return sr.StringFunctions.replace(...e)}static encodeForUri(...e){return sr.StringFunctions.encodeForUri(...e)}static normalize(...e){return sr.StringFunctions.normalize(...e)}static fold(...e){return sr.StringFunctions.fold(...e)}static abs(...e){return Ta.MathFunctions.abs(...e)}static round(...e){return Ta.MathFunctions.round(...e)}static ceil(...e){return Ta.MathFunctions.ceil(...e)}static floor(...e){return Ta.MathFunctions.floor(...e)}static rand(){return Ta.MathFunctions.rand()}static msToMinutes(...e){return Ta.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Ta.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Ta.MathFunctions.msToSeconds(...e)}static parseDate(...e){return oe.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return oe.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return oe.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return oe.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return oe.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return oe.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return oe.DateTimeFunctions.year(...e)}static month(...e){return oe.DateTimeFunctions.month(...e)}static day(...e){return oe.DateTimeFunctions.day(...e)}static hours(...e){return oe.DateTimeFunctions.hours(...e)}static minutes(...e){return oe.DateTimeFunctions.minutes(...e)}static seconds(...e){return oe.DateTimeFunctions.seconds(...e)}static timezone(...e){return oe.DateTimeFunctions.timezone(...e)}static tz(...e){return oe.DateTimeFunctions.tz(...e)}static now(){return oe.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return oe.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return oe.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return oe.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return oe.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return oe.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return oe.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return oe.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return oe.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return oe.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return oe.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return oe.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return oe.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return oe.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return oe.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return oe.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return oe.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return oe.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return oe.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return oe.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return oe.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return oe.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return oe.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return oe.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return oe.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return oe.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return oe.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return oe.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return oe.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return oe.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return oe.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return oe.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return oe.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return oe.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return oe.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return oe.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return oe.DateTimeFunctions.adjust(...e)}static isTime(...e){return oe.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return oe.DateTimeFunctions.timeDiff(...e)}static compare(...e){return $c.LogicalFunctions.compare(...e)}static logicalAnd(...e){return $c.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return $c.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return $c.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return $c.LogicalFunctions.coalesce(...e)}static if(...e){return $c.LogicalFunctions.if(...e)}static datatype(...e){return Ot.RDFTermFunctions.datatype(...e)}static bound(...e){return Ot.RDFTermFunctions.bound(...e)}static isIRI(...e){return Ot.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return Ot.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return Ot.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return Ot.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return Ot.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return Ot.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return Ot.RDFTermFunctions.sameTerm(...e)}static iri(...e){return Ot.RDFTermFunctions.iri(...e)}static uri(...e){return Ot.RDFTermFunctions.uri(...e)}static bnode(...e){return Ot.RDFTermFunctions.bnode(...e)}static strdt(...e){return Ot.RDFTermFunctions.strdt(...e)}static strlang(...e){return Ot.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return Ot.RDFTermFunctions.strlangdir(...e)}static uuid(){return Ot.RDFTermFunctions.uuid()}static struuid(){return Ot.RDFTermFunctions.struuid()}static xsdDateTime(...e){return Ot.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return Ot.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return Ot.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return Ot.RDFTermFunctions.triple(...e)}static subject(...e){return Ot.RDFTermFunctions.subject(...e)}static predicate(...e){return Ot.RDFTermFunctions.predicate(...e)}static object(...e){return Ot.RDFTermFunctions.object(...e)}static md5(...e){return Vu.HashFunctions.md5(...e)}static sha1(...e){return Vu.HashFunctions.sha1(...e)}static sha256(...e){return Vu.HashFunctions.sha256(...e)}static sha384(...e){return Vu.HashFunctions.sha384(...e)}static sha512(...e){return Vu.HashFunctions.sha512(...e)}};gp.BuiltInFunctions=o1});var Uu=S(ns=>{"use strict";Object.defineProperty(ns,"__esModule",{value:!0});ns.ExoQLBudgetExceededError=ns.ExoQLCycleError=ns.ExoQLEvalDisabledError=ns.ExoQLForbiddenKeywordError=void 0;var c1=class extends Error{static{o(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}};ns.ExoQLForbiddenKeywordError=c1;var l1=class extends Error{static{o(this,"ExoQLEvalDisabledError")}constructor(e){super(e??"ExoQLEvalDisabledError: exoql.eval.enabled is false (default). Flip the feature flag to opt in."),this.name="ExoQLEvalDisabledError"}};ns.ExoQLEvalDisabledError=l1;var u1=class extends Error{static{o(this,"ExoQLCycleError")}constructor(e,t){super(t??`ExoQLCycleError: cycle detected in nested exo:eval invocations: ${e.join(" \u2192 ")}`),this.name="ExoQLCycleError",this.path=e}};ns.ExoQLCycleError=u1;var f1=class extends Error{static{o(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}};ns.ExoQLBudgetExceededError=f1});var jA=S(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.functionHandlers=void 0;var k=yp();M.functionHandlers=new Map;M.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.str(t)});M.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.lang(t)});M.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 k.BuiltInFunctions.langMatches(t,r)});M.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 k.BuiltInFunctions.contains(t,r)});M.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 k.BuiltInFunctions.strStarts(t,r)});M.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 k.BuiltInFunctions.strEnds(t,r)});M.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.strlen(t)});M.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.ucase(t)});M.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.lcase(t)});M.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 k.BuiltInFunctions.substr(t,r,i)}return k.BuiltInFunctions.substr(t,r)});M.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 k.BuiltInFunctions.strBefore(t,r)});M.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 k.BuiltInFunctions.strAfter(t,r)});M.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return k.BuiltInFunctions.concat(...t)});M.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 k.BuiltInFunctions.replace(t,r,i,s)});M.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 k.BuiltInFunctions.regex(t,r,i)});M.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.encodeForUri(t)});M.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.datatype(t).value});M.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return k.BuiltInFunctions.bound(r)}return!0});var OA=o((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isIRI(t)},"isIriHandler");M.functionHandlers.set("isiri",OA);M.functionHandlers.set("isuri",OA);M.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isBlank(t)});M.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isLiteral(t)});M.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isNumeric(t)});M.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.hasLangdir(t)});M.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isTriple(t)});M.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return k.BuiltInFunctions.sameTerm(t,r)});M.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.abs(t)});M.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.round(t)});M.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.ceil(t)});M.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.floor(t)});M.functionHandlers.set("rand",()=>k.BuiltInFunctions.rand());M.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.parseDate(t)});M.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 k.BuiltInFunctions.dateBefore(t,r)});M.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 k.BuiltInFunctions.dateAfter(t,r)});M.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 k.BuiltInFunctions.dateInRange(t,r,i)});M.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 k.BuiltInFunctions.dateDiffMinutes(t,r)});M.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 k.BuiltInFunctions.dateDiffHours(t,r)});var Bc=o((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),PA=Bc(k.BuiltInFunctions.year.bind(k.BuiltInFunctions),k.BuiltInFunctions.durationYears.bind(k.BuiltInFunctions),null);M.functionHandlers.set("year",PA);M.functionHandlers.set("years",PA);var FA=Bc(k.BuiltInFunctions.month.bind(k.BuiltInFunctions),k.BuiltInFunctions.durationMonths.bind(k.BuiltInFunctions),null);M.functionHandlers.set("month",FA);M.functionHandlers.set("months",FA);var DA=Bc(k.BuiltInFunctions.day.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationDays.bind(k.BuiltInFunctions));M.functionHandlers.set("day",DA);M.functionHandlers.set("days",DA);M.functionHandlers.set("hours",Bc(k.BuiltInFunctions.hours.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationHours.bind(k.BuiltInFunctions)));M.functionHandlers.set("minutes",Bc(k.BuiltInFunctions.minutes.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationMinutes.bind(k.BuiltInFunctions)));M.functionHandlers.set("seconds",Bc(k.BuiltInFunctions.seconds.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationSeconds.bind(k.BuiltInFunctions)));M.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.timezone(t)});M.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.tz(t)});M.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 k.BuiltInFunctions.adjust(t,r)});M.functionHandlers.set("now",()=>k.BuiltInFunctions.now());var NA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");M.functionHandlers.set("datetime",NA);M.functionHandlers.set("xsd:datetime",NA);var LA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");M.functionHandlers.set("integer",LA);M.functionHandlers.set("xsd:integer",LA);var kA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");M.functionHandlers.set("decimal",kA);M.functionHandlers.set("xsd:decimal",kA);var MA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");M.functionHandlers.set("daytimeduration",MA);M.functionHandlers.set("xsd:daytimeduration",MA);M.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToDays(t)});M.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToHours(t)});M.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToMinutes(t)});M.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToSeconds(t)});M.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationDays(t)});M.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationHours(t)});M.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationMinutes(t)});M.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationSeconds(t)});M.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationYears(t)});M.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationMonths(t)});M.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeDiff(t,r)});M.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeAdd(t,r)});M.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeSubtract(t,r)});M.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToMinutes(t)});M.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToHours(t)});M.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToSeconds(t)});M.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.md5(t)});M.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha1(t)});M.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha256(t)});M.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha384(t)});M.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha512(t)});M.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.subject(t)});M.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.predicate(t)});M.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.object(t)});M.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 k.BuiltInFunctions.triple(t,r,i)});M.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))});M.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))});M.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)});M.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))});M.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)});M.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"))});M.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:n}=Uu();throw new n})});var _p=S(Vc=>{"use strict";Object.defineProperty(Vc,"__esModule",{value:!0});Vc.FilterExecutor=Vc.FilterExecutorError=void 0;var yt=yp(),wj=jA(),Ej=Ce(),Aa=Ve(),hr=class extends Error{static{o(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Vc.FilterExecutorError=hr;var d1=class{static{o(this,"FilterExecutor")}constructor(){this.existsEvaluator=null,this.tripleStore=null,this.uuidCache=new Map}setExistsEvaluator(e){this.existsEvaluator=e}setTripleStore(e){this.tripleStore=e,this.uuidCache.clear()}async*execute(e,t){let r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||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}o(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":return r.value;case"NamedNode":return r.value;default:throw new hr(`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":return e.value;case"in":return this.evaluateIn(e,t);case"exists":throw new hr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new hr(`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 yt.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 hr("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 yt.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 yt.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return yt.BuiltInFunctions.logicalOr(r);throw new hr(`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 a=await this.evaluateExpressionAsync(s,t);if(yt.BuiltInFunctions.compare(r,a,"=")){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 hr("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 a=[];for(let l of s){let u=await this.evaluateExpressionAsync(l,t);a.push(this.wrapAsLiteralExpression(u))}let c={...r,args:a};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:typeof e=="object"&&e!==null&&"termType"in e?e:e instanceof Ej.IRI||e instanceof Aa.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 yt.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return yt.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return yt.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return yt.BuiltInFunctions.logicalOr(r);throw new hr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let a=this.evaluateExpression(s,t);return yt.BuiltInFunctions.compare(r,a,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return yt.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return yt.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return yt.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return yt.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return yt.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new hr("Division by zero");return yt.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),a=this.toNumericValue(i);switch(e.operator){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":if(a===0)throw new hr("Division by zero");return s/a;default:throw new hr(`Unknown arithmetic operator: ${String(e.operator)}`)}}isDayTimeDurationValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof Aa.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 hr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof Aa.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 Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let a=wj.functionHandlers.get(i);if(!a)throw new hr(`Unknown function: ${i}`);let c={evaluateExpression:o((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:o((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:o(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:o(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:o(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return a(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new hr(`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 hr("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 Aa.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 hr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let a=this.tripleStore.findSubjectsByUUIDSync(s);if(a.length===0){this.uuidCache.set(s,null);return}let c=a[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Vc.FilterExecutor=d1});var p1=S(Sp=>{"use strict";Object.defineProperty(Sp,"__esModule",{value:!0});Sp.OptionalExecutor=void 0;var h1=class{static{o(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let a="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,a),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,a),f=c.get(u),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 a=e.get(s);i.push(a!==void 0?a.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let a=r.merge(s);a!==null&&(yield a,i=!0)}i||(yield r)}}};Sp.OptionalExecutor=h1});var g1=S(bp=>{"use strict";Object.defineProperty(bp,"__esModule",{value:!0});bp.UnionExecutor=void 0;var m1=class{static{o(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};bp.UnionExecutor=m1});var $A=S(vp=>{"use strict";Object.defineProperty(vp,"__esModule",{value:!0});vp.MinusExecutor=void 0;var y1=class{static{o(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let a=!1;for(let c of i)if(this.areCompatible(s,c)){a=!0;break}a||(yield s)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.filter(a=>i.has(a));if(s.length===0)return!1;for(let a of s){let c=e.get(a),l=t.get(a);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};vp.MinusExecutor=y1});var VA=S(Uc=>{"use strict";Object.defineProperty(Uc,"__esModule",{value:!0});Uc.ValuesExecutor=Uc.ValuesExecutorError=void 0;var Tj=rs(),BA=Ce(),Aj=Ve(),wp=class extends Error{static{o(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Uc.ValuesExecutorError=wp;var _1=class{static{o(this,"ValuesExecutor")}async*execute(e){if(e.bindings.length!==0)for(let t of e.bindings)yield this.createSolutionMapping(t)}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new Tj.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 BA.IRI(e.value);if(e.type==="literal")return new Aj.Literal(e.value,e.datatype?new BA.IRI(e.datatype):void 0,e.language,e.direction);throw new wp(`Unknown term type: ${e.type}`)}};Uc.ValuesExecutor=_1});var S1=S(Wc=>{"use strict";Object.defineProperty(Wc,"__esModule",{value:!0});Wc.CustomAggregateRegistry=Wc.CustomAggregateError=void 0;var qc=class extends Error{static{o(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};Wc.CustomAggregateError=qc;var Ep=class n{static{o(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new qc("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new qc("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new qc(`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}};Wc.CustomAggregateRegistry=Ep;Ep.instance=null});var b1=S(Je=>{"use strict";Object.defineProperty(Je,"__esModule",{value:!0});Je.BUILT_IN_AGGREGATES=Je.modeAggregate=Je.stddevAggregate=Je.varianceAggregate=Je.medianAggregate=Je.EXO_AGGREGATE_NS=void 0;Je.getNumericValue=Tp;Je.createDecimalLiteral=ci;Je.createDoubleLiteral=Ij;Je.createPercentileAggregate=vo;var wo=Ve(),Gc=Ce(),xj=new Gc.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Cj=new Gc.IRI("http://www.w3.org/2001/XMLSchema#double");Je.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Tp(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof wo.Literal?parseFloat(n.value):n instanceof Gc.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}o(Tp,"getNumericValue");function ci(n){return new wo.Literal(String(n),xj)}o(ci,"createDecimalLiteral");function Ij(n){return new wo.Literal(String(n),Cj)}o(Ij,"createDoubleLiteral");Je.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Tp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=[...t].sort((a,c)=>a-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return ci(s)}};Je.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Tp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ci(i)}};Je.stddevAggregate={init(){return{values:[]}},step(n,e){Je.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ci(Math.sqrt(i))}};Je.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof wo.Literal||e instanceof Gc.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 wo.Literal(" ",new Gc.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[a,c]of e.counts)c>r&&(r=c,t=a);let i=e.values.get(t);if(i instanceof wo.Literal)return i;let s=parseFloat(t);return isNaN(s)?new wo.Literal(t,new Gc.IRI("http://www.w3.org/2001/XMLSchema#string")):ci(s)}};function vo(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Tp(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return ci(0);let s=[...i].sort((d,h)=>d-h),a=r.percentile*(s.length-1),c=Math.floor(a),l=Math.ceil(a);if(c===l)return ci(s[c]);let u=a-c,f=s[c]*(1-u)+s[l]*u;return ci(f)}}}o(vo,"createPercentileAggregate");Je.BUILT_IN_AGGREGATES={[`${Je.EXO_AGGREGATE_NS}median`]:Je.medianAggregate,[`${Je.EXO_AGGREGATE_NS}variance`]:Je.varianceAggregate,[`${Je.EXO_AGGREGATE_NS}stddev`]:Je.stddevAggregate,[`${Je.EXO_AGGREGATE_NS}mode`]:Je.modeAggregate,[`${Je.EXO_AGGREGATE_NS}percentile25`]:vo(25),[`${Je.EXO_AGGREGATE_NS}percentile50`]:vo(50),[`${Je.EXO_AGGREGATE_NS}percentile75`]:vo(75),[`${Je.EXO_AGGREGATE_NS}percentile90`]:vo(90),[`${Je.EXO_AGGREGATE_NS}percentile95`]:vo(95),[`${Je.EXO_AGGREGATE_NS}percentile99`]:vo(99)}});var WA=S(zc=>{"use strict";Object.defineProperty(zc,"__esModule",{value:!0});zc.AggregateExecutor=zc.AggregateExecutorError=void 0;var ar=Ve(),w1=Ce(),Rj=_p(),Oj=S1(),Pj=b1(),UA=new w1.IRI("http://www.w3.org/2001/XMLSchema#integer"),Eo=new w1.IRI("http://www.w3.org/2001/XMLSchema#decimal"),is=new w1.IRI("http://www.w3.org/2001/XMLSchema#string");function qA(n){return typeof n=="object"&&n.type==="custom"}o(qA,"isCustomAggregation");var qu=class extends Error{static{o(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};zc.AggregateExecutorError=qu;var v1=class{static{o(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Rj.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,a]of r.entries()){let c=new Map;for(let f of e.variables)if(a.length>0){let d=a[0].get(f);d&&c.set(f,d)}for(let f of e.aggregates){let d=this.computeAggregate(f.expression,a);c.set(f.variable,d)}let{SolutionMapping:l}=rs(),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),a=r.get(s);a?a.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if(qA(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 ar.Literal(String(s),UA)}case"sum":{let s=this.computeSum(r);return new ar.Literal(String(s),Eo)}case"avg":{let s=this.computeAvg(r);return new ar.Literal(String(s),Eo)}case"min":{let s=this.computeMin(r);return s===void 0?new ar.Literal("",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}case"max":{let s=this.computeMax(r);return s===void 0?new ar.Literal("",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new ar.Literal(s||" ",is)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new ar.Literal(" ",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}default:{let s=i;throw new qu(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,a=Oj.CustomAggregateRegistry.getInstance().get(i);if(a||(a=Pj.BUILT_IN_AGGREGATES[i]),!a)throw new qu(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=a.init();for(let l of t){let u=null;if(e.expression){let f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;a.step(c,u)}return a.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let a=s[0],c=parseFloat(a);return isNaN(c)?a:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=rs(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if(qA(s)){r.set(i.variable,new ar.Literal("0",Eo));continue}switch(s){case"count":r.set(i.variable,new ar.Literal("0",UA));break;case"sum":case"avg":r.set(i.variable,new ar.Literal("0",Eo));break;case"group_concat":r.set(i.variable,new ar.Literal(" ",is));break;case"min":case"max":case"sample":r.set(i.variable,new ar.Literal("",is));break;default:r.set(i.variable,new ar.Literal("",is))}}return r}};zc.AggregateExecutor=v1});var x1=S(Ap=>{"use strict";Object.defineProperty(Ap,"__esModule",{value:!0});Ap.ConstructExecutor=void 0;var Fj=ii(),To=Ce(),E1=Ve(),T1=Gt(),Dj=bu(),A1=class{static{o(this,"ConstructExecutor")}async execute(e,t){let r=[],i=new Set;for(let s of t)for(let a of e)try{let c=this.instantiateTriple(a,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new Fj.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 To.IRI(e.value);if(e.type==="literal")return new E1.Literal(e.value,e.datatype?new To.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new T1.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 Dj.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 E1.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new To.IRI(e.value);if(e.type==="blank")return new T1.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 To.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new To.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 To.IRI(e.value);if(e.type==="blank")return new T1.BlankNode(e.value);if(e.type==="literal")return new E1.Literal(e.value,e.datatype?new To.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}`)}};Ap.ConstructExecutor=A1});var zA=S(Hc=>{"use strict";Object.defineProperty(Hc,"__esModule",{value:!0});Hc.ServiceExecutor=Hc.ServiceExecutorError=void 0;var Nj=rs(),GA=Ce(),Lj=Ve(),kj=Gt(),Ao=class extends Error{static{o(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Hc.ServiceExecutorError=Ao;var C1=class{static{o(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,a=setTimeout(()=>s.abort(),this.timeout);try{let c=await this.httpClient(e,{method:"POST",headers:{"Content-Type":"application/sparql-query",Accept:"application/sparql-results+json"},body:t,signal:s.signal});if(!c.ok)throw new Ao(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(a)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new Ao(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new Ao(`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 Nj.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 GA.IRI(e.value);case"literal":{let t=e.datatype?new GA.IRI(e.datatype):void 0;return new Lj.Literal(e.value,t,e["xml:lang"])}case"bnode":return new kj.BlankNode(e.value);default:throw new Ao(`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))}};Hc.ServiceExecutor=C1});var QA=S(Qc=>{"use strict";Object.defineProperty(Qc,"__esModule",{value:!0});Qc.GraphExecutor=Qc.GraphExecutorError=void 0;var HA=Ce(),xp=class extends Error{static{o(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Qc.GraphExecutorError=xp;var I1=class{static{o(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new xp(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new HA.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let a=i.get(t.value);if(a&&a instanceof HA.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:a.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let a of s)for await(let c of r(e.pattern,a)){let l=c.clone();l.set(t.value,a),yield l}}};Qc.GraphExecutor=I1});var YA=S(Kc=>{"use strict";Object.defineProperty(Kc,"__esModule",{value:!0});Kc.SPARQLGenerator=Kc.SPARQLGeneratorError=void 0;var Yc=class extends Error{static{o(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};Kc.SPARQLGeneratorError=Yc;var R1=class{static{o(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
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+=a,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 a=t+i.length+1,c=a;for(;c<e.length&&/[a-zA-Z0-9_.%-]/.test(e[c]);)c++;if(c===a)continue;let l=e.substring(a,c);return{iri:`<${s}${l}.md>`,endIndex:c}}return null}findDeclaredPrefixes(e){let t=new Set,r=new RegExp(QM.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}};qh.VaultPrefixTransformer=N_});var Oc=S(wn=>{"use strict";var KM=wn&&wn.__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:o(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),XM=wn&&wn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),JM=wn&&wn.__importStar||(function(){var n=o(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"&&KM(t,e,r[i]);return XM(t,e),t}})();Object.defineProperty(wn,"__esModule",{value:!0});wn.SPARQLParser=wn.ExoQLParser=wn.SPARQLParseError=void 0;var lA=JM(sA()),k_=I_(),M_=R_(),uA=aA(),j_=P_(),ZM=oA(),$_=cA(),ej=L_(),nr=class extends Error{static{o(this,"SPARQLParseError")}constructor(e,t,r,i){super(e,i?{cause:i}:void 0),this.name="SPARQLParseError",this.line=t,this.column=r}};wn.SPARQLParseError=nr;var Wh=class{static{o(this,"ExoQLParser")}constructor(e){this.lastDirectionMappings=new Map,this.parser=new lA.Parser({sparqlStar:!0}),this.generator=new lA.Generator({sparqlStar:!0}),this.caseWhenTransformer=new k_.CaseWhenTransformer,this.lateralTransformer=new M_.LateralTransformer,this.prefixStarTransformer=new uA.PrefixStarTransformer(e?.vocabularyResolver),this.describeOptionsTransformer=new j_.DescribeOptionsTransformer,this.directionalLangTagTransformer=new ZM.DirectionalLangTagTransformer,this.tripleTermTransformer=new $_.TripleTermTransformer,this.vaultPrefixTransformer=new ej.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 j_.DescribeOptionsTransformerError)throw new nr(t.message);if(t instanceof M_.LateralTransformerError)throw new nr(t.message);if(t instanceof k_.CaseWhenTransformerError)throw new nr(t.message);if(t instanceof $_.TripleTermTransformerError)throw new nr(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 nr(`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 j_.DescribeOptionsTransformerError)throw new nr(t.message);if(t instanceof uA.PrefixStarTransformerError)throw new nr(t.message);if(t instanceof M_.LateralTransformerError)throw new nr(t.message);if(t instanceof k_.CaseWhenTransformerError)throw new nr(t.message);if(t instanceof $_.TripleTermTransformerError)throw new nr(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 nr(`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 nr(`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 nr("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 nr("Invalid query: not an object");if(e.type!=="query"&&e.type!=="update")throw new nr(`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 nr(`Invalid query type: expected one of ${t.join(", ")}, got "${e.queryType}"`)}}};wn.ExoQLParser=Wh;wn.SPARQLParser=Wh});var bo=S(Gh=>{"use strict";Object.defineProperty(Gh,"__esModule",{value:!0});Gh.AlgebraTranslatorError=void 0;var B_=class extends Error{static{o(this,"AlgebraTranslatorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AlgebraTranslatorError"}};Gh.AlgebraTranslatorError=B_});var zh=S(ts=>{"use strict";Object.defineProperty(ts,"__esModule",{value:!0});ts.isVariableExpression=tj;ts.isVariableTerm=rj;ts.isNamedNode=nj;ts.isLiteral=ij;ts.isPropertyPath=sj;ts.isAggregateExpression=aj;ts.isOperationExpression=oj;ts.isFunctionCallExpression=cj;function tj(n){return typeof n=="object"&&n!==null&&"expression"in n&&"variable"in n}o(tj,"isVariableExpression");function rj(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Variable"}o(rj,"isVariableTerm");function nj(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="NamedNode"}o(nj,"isNamedNode");function ij(n){return typeof n=="object"&&n!==null&&"termType"in n&&n.termType==="Literal"}o(ij,"isLiteral");function sj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="path"}o(sj,"isPropertyPath");function aj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="aggregate"}o(aj,"isAggregateExpression");function oj(n){return typeof n=="object"&&n!==null&&"type"in n&&n.type==="operation"}o(oj,"isOperationExpression");function cj(n){return typeof n=="object"&&n!==null&&"type"in n&&(n.type==="functionCall"||n.type==="functioncall")}o(cj,"isFunctionCallExpression")});var fA=S(Hh=>{"use strict";Object.defineProperty(Hh,"__esModule",{value:!0});Hh.TripleTranslator=void 0;var an=bo(),V_=class{static{o(this,"TripleTranslator")}constructor(){this.directionMappings=new Map}setDirectionMappings(e){this.directionMappings=e}translateBGP(e){if(!("triples"in e)||!Array.isArray(e.triples))throw new an.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 an.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 an.AlgebraTranslatorError("Property path must have pathType");if(!("items"in e)||!Array.isArray(e.items))throw new an.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 an.AlgebraTranslatorError("Inverse path must have exactly one item");return{type:"path",pathType:"^",items:[t[0]]};case"+":if(t.length!==1)throw new an.AlgebraTranslatorError("OneOrMore path must have exactly one item");return{type:"path",pathType:"+",items:[t[0]]};case"*":if(t.length!==1)throw new an.AlgebraTranslatorError("ZeroOrMore path must have exactly one item");return{type:"path",pathType:"*",items:[t[0]]};case"?":if(t.length!==1)throw new an.AlgebraTranslatorError("ZeroOrOne path must have exactly one item");return{type:"path",pathType:"?",items:[t[0]]};default:throw new an.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 an.AlgebraTranslatorError(`Unsupported path item type: ${String(t)}`)}translateTripleElement(e){if(!e||!("termType"in e))throw new an.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 an.AlgebraTranslatorError(`Unsupported term type: ${e.termType}`)}}translateQuotedTriple(e){if(!e.subject||!e.predicate||!e.object)throw new an.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 an.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 an.AlgebraTranslatorError(`Quoted triple predicate must be IRI or Variable, got: ${e.termType}`)}}};Hh.TripleTranslator=V_});var dA=S(Qh=>{"use strict";Object.defineProperty(Qh,"__esModule",{value:!0});Qh.ExpressionTranslator=void 0;var Pc=bo(),U_=class{static{o(this,"ExpressionTranslator")}constructor(e){this.translateWhereFn=e.translateWhere,this.translateBGPFn=e.translateBGP,this.translatePatternFn=e.translatePattern}translateExpression(e){if(!e)throw new Pc.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 Pc.AlgebraTranslatorError(`Unsupported expression structure: ${JSON.stringify(e)}`)}translateFilter(e){if(!e.expression)throw new Pc.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(a=>!("patterns"in a)||"termType"in a);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(a=>this.translateExpression(a))}: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(a=>this.translateExpression(a))}}translateExistsExpression(e){if(!e.args||e.args.length!==1)throw new Pc.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 Pc.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 Pc.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"}}};Qh.ExpressionTranslator=U_});var mA=S(Yh=>{"use strict";Object.defineProperty(Yh,"__esModule",{value:!0});Yh.PatternTranslator=void 0;var hA=R_(),Pr=bo(),pA=zh(),q_=class{static{o(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 Pr.AlgebraTranslatorError("Empty WHERE clause");let t=e.filter(a=>a.type==="filter"),r=e.filter(a=>a.type==="bind"),i=e.filter(a=>a.type!=="filter"&&a.type!=="bind"),s;if(i.length===0)s={type:"bgp",triples:[]};else if(i.length===1)if(i[0].type==="optional"){let a=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:a?this.translateExpressionFn(a):void 0}}else s=this.translatePattern(i[0]);else{if(i[0].type==="optional"){let a=i[0].expression;s={type:"leftjoin",left:{type:"bgp",triples:[]},right:this.translateWhere(i[0].patterns),expression:a?this.translateExpressionFn(a):void 0}}else s=this.translatePattern(i[0]);for(let a=1;a<i.length;a++){let c=i[a];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 a of r)s=this.translateBind(a,s);for(let a of t)s={type:"filter",expression:this.translateExpressionFn(a.expression),input:s};return s}translatePattern(e){if(!e||!e.type)throw new Pr.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 Pr.AlgebraTranslatorError(`Unsupported pattern type: ${e.type}`)}}translateFilter(e){if(!e.expression)throw new Pr.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 Pr.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 Pr.AlgebraTranslatorError("UNION pattern must have at least 2 patterns");let t=o(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 Pr.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 Pr.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 a=s.startsWith("?")?s.slice(1):s;t.add(a)}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,a=i;if(a)if(a.termType==="NamedNode")t[s]={type:"iri",value:a.value};else if(a.termType==="Literal"){let c=a,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 Pr.AlgebraTranslatorError(`Unsupported VALUES term type: ${a.termType}`)}return t}translateBind(e,t){if(!e.variable||!e.expression)throw new Pr.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 Pr.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 Pr.AlgebraTranslatorError("SERVICE pattern must have a NamedNode endpoint");if(!e.patterns||!Array.isArray(e.patterns))throw new Pr.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 Pr.AlgebraTranslatorError("GRAPH pattern must have a name (IRI or variable)");if(!e.patterns||!Array.isArray(e.patterns))throw new Pr.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 Pr.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 Pr.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,pA.isVariableTerm)(i)&&i.value===hA.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,pA.isVariableTerm)(i)&&i.value===hA.LateralTransformer.LATERAL_MARKER))}}};Yh.PatternTranslator=q_});var yA=S(Kh=>{"use strict";Object.defineProperty(Kh,"__esModule",{value:!0});Kh.AggregateTranslator=void 0;var gA=bo(),lj=zh(),W_=class{static{o(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,lj.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)),a=["=","!=","<",">","<=",">="],c=["&&","||","!"],l=["+","-","*","/"];return a.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=o(()=>{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,a=i;if(a.termType==="NamedNode"&&typeof a.value=="string")s=a.value;else if("value"in a)s=String(a.value);else throw new gA.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 gA.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)}}}};Kh.AggregateTranslator=W_});var Fc=S(va=>{"use strict";Object.defineProperty(va,"__esModule",{value:!0});va.AlgebraTranslator=va.ExoQLAlgebraTranslator=va.AlgebraTranslatorError=void 0;var Xh=bo(),Jh=zh(),uj=fA(),fj=dA(),dj=mA(),hj=yA(),pj=bo();Object.defineProperty(va,"AlgebraTranslatorError",{enumerable:!0,get:o(function(){return pj.AlgebraTranslatorError},"get")});var Zh=class{static{o(this,"ExoQLAlgebraTranslator")}constructor(){this.tripleTranslator=new uj.TripleTranslator,this.expressionTranslator=new fj.ExpressionTranslator({translateWhere:o(e=>this.patternTranslator.translateWhere(e),"translateWhere"),translateBGP:o(e=>this.tripleTranslator.translateBGP(e),"translateBGP"),translatePattern:o(e=>this.patternTranslator.translatePattern(e),"translatePattern")}),this.patternTranslator=new dj.PatternTranslator({translateExpression:o(e=>this.expressionTranslator.translateExpression(e),"translateExpression"),translateSelect:o(e=>this.translateSelect(e),"translateSelect"),translateBGP:o(e=>this.tripleTranslator.translateBGP(e),"translateBGP")}),this.aggregateTranslator=new hj.AggregateTranslator({translateExpression:o(e=>this.expressionTranslator.translateExpression(e),"translateExpression")})}setDirectionMappings(e){this.tripleTranslator.setDirectionMappings(e),this.patternTranslator.setDirectionMappings(e)}translate(e){if(e.type!=="query")throw new Xh.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 Xh.AlgebraTranslatorError(`Query type ${String(e.queryType)} not yet supported`)}translateSelect(e){if(!e.where||e.where.length===0)throw new Xh.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),a=this.aggregateTranslator.extractGroupVariables(e.group),c=this.aggregateTranslator.extractHavingExpressions(e.having,s,r);if((s.length>0||a.length>0||c.length>0)&&(t={type:"group",variables:a,aggregates:s,having:c.length>0?c:void 0,input:t}),i.length>0){for(let u of i)if((0,Jh.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,Jh.isVariableTerm)(u)||(0,Jh.isVariableExpression)(u)).map(u=>(0,Jh.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 Xh.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 a of s)a.termType==="Wildcard"||a.value==="*"||(a.termType==="Variable"?t.push({type:"variable",value:a.value}):a.termType==="NamedNode"&&t.push({type:"iri",value:a.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}}};va.ExoQLAlgebraTranslator=Zh;va.AlgebraTranslator=Zh});var rs=S(ep=>{"use strict";Object.defineProperty(ep,"__esModule",{value:!0});ep.SolutionMapping=void 0;var _A=Ve(),SA=Ce(),bA=Gt(),G_=class n{static{o(this,"SolutionMapping")}constructor(e){this.bindings=e?new Map(e):new Map}get(e){return this.bindings.get(e)}set(e,t){this.bindings.set(e,t)}has(e){return this.bindings.has(e)}variables(){return Array.from(this.bindings.keys())}getBindings(){return new Map(this.bindings)}isCompatibleWith(e){for(let[t,r]of this.bindings.entries()){let i=e.get(t);if(i!==void 0&&!this.areEqual(r,i))return!1}return!0}merge(e){if(!this.isCompatibleWith(e))return null;let t=new n(this.bindings);for(let[r,i]of e.getBindings().entries())t.set(r,i);return t}clone(){return new n(this.bindings)}areEqual(e,t){return e instanceof _A.Literal&&t instanceof _A.Literal?e.equals(t):e instanceof SA.IRI&&t instanceof SA.IRI?e.value===t.value:e instanceof bA.BlankNode&&t instanceof bA.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}};ep.SolutionMapping=G_});var wA=S(Dc=>{"use strict";Object.defineProperty(Dc,"__esModule",{value:!0});Dc.PropertyPathExecutor=Dc.PropertyPathExecutorError=void 0;var mj=rs(),tp=Ce(),vA=Gt(),gj=Ve(),ju=class extends Error{static{o(this,"PropertyPathExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="PropertyPathExecutorError"}};Dc.PropertyPathExecutorError=ju;var z_=class{static{o(this,"PropertyPathExecutor")}constructor(e){this.tripleStore=e,this.MAX_DEPTH=100}async*execute(e,t,r){if(this.isLiteralElement(e)||this.isLiteralElement(r)){let a=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 ${a} 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 a of i){let c=await this.evaluatePath(a,t,s);for(let l of c){let u=new mj.SolutionMapping;this.isVariable(e)&&u.set(e.value,a),this.isVariable(r)&&u.set(r.value,l),yield u}}}async*executeWithBindings(e,t){if(!this.isPropertyPath(e.predicate))throw new ju("Predicate is not a property path");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.object,t);for await(let s of this.execute(r,e.predicate,i)){let a=t.merge(s);a!==null&&(yield a)}}async evaluatePath(e,t,r){switch(t.pathType){case"/":return this.evaluateSequencePath(e,t.items,r);case"|":return this.evaluateAlternativePath(e,t.items,r);case"^":return this.evaluateInversePath(e,t.items[0],r);case"+":return this.evaluateOneOrMorePath(e,t.items[0],r);case"*":return this.evaluateZeroOrMorePath(e,t.items[0],r);case"?":return this.evaluateZeroOrOnePath(e,t.items[0],r)}}async evaluateSequencePath(e,t,r){let i=new Set([e]);for(let s=0;s<t.length;s++){let a=t[s],c=s===t.length-1,l=new Set;for(let u of i){let f=await this.evaluatePathItem(u,a,c?r:null);for(let 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 a=await this.evaluatePathItem(e,s,r);for(let c of a)i.add(c)}return i}async evaluateInversePath(e,t,r){if(t.type==="iri"){let i=new tp.IRI(t.value),s=await this.tripleStore.match(void 0,i,e),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.subject,r))&&a.add(c.subject);return a}else return this.evaluatePath(e,this.invertPath(t),r)}async evaluateOneOrMorePath(e,t,r){let i=new Set,s=new Set,a=[{node:e,depth:0}];for(;a.length>0;){let c=a.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),a.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 a of s)i.add(a);return i}async evaluatePathItem(e,t,r){if(t.type==="iri"){let i=new tp.IRI(t.value),s=await this.tripleStore.match(e,i,void 0),a=new Set;for(let c of s)(r===null||this.nodeInSet(c.object,r))&&a.add(c.object);return a}else return this.evaluatePath(e,t,r)}invertPath(e){switch(e.pathType){case"^":return e.items[0];case"/":return{type:"path",pathType:"/",items:[...e.items].reverse().map(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 tp.IRI(e.value));break;case"blank":t.add(new vA.BlankNode(e.value));break;default:throw new ju(`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 tp.IRI)return{type:"iri",value:r.value};if(r instanceof vA.BlankNode)return{type:"blank",value:r.id};if(r instanceof gj.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}};Dc.PropertyPathExecutor=z_});var Y_=S(Nc=>{"use strict";Object.defineProperty(Nc,"__esModule",{value:!0});Nc.BGPExecutor=Nc.BGPExecutorError=void 0;var rp=rs(),wa=Ce(),H_=Ve(),np=Gt(),ip=bu(),yj=wA(),Ur=class extends Error{static{o(this,"BGPExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="BGPExecutorError"}};Nc.BGPExecutorError=Ur;var Q_=class{static{o(this,"BGPExecutor")}constructor(e){this.tripleStore=e,this.propertyPathExecutor=new yj.PropertyPathExecutor(e)}async*execute(e){if(e.triples.length===0){yield new rp.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 rp.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 Ur("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),a=this.isVariable(e.object)?void 0:this.toRDFTerm(e.object);if(!this.tripleStore.matchInGraph)throw new Ur("Triple store does not support named graph operations");let c=await this.tripleStore.matchInGraph(i,s,a,t);for(let l of c){let u=new rp.SolutionMapping;this.isVariable(e.subject)&&u.set(e.subject.value,l.subject),this.isVariable(r)&&u.set(r.value,l.predicate),this.isVariable(e.object)&&u.set(e.object.value,l.object),yield u}}async*joinWithPatternInGraph(e,t,r){let i=[];for await(let s of e)i.push(s);for(let s of i){let a=this.instantiatePattern(t,s);for await(let c of this.matchTriplePatternInGraph(a,r)){let l=s.merge(c);l!==null&&(yield l)}}}async*matchTriplePattern(e){if(this.isPropertyPath(e.predicate)){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),a=await this.tripleStore.match(r,i,s);for(let c of a){let l=new rp.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 ip.QuotedTriple))return null;let r=new Map;if(this.isVariable(e.subject))r.set(e.subject.value,t.subject);else if(this.isQuotedTriple(e.subject)){let i=this.matchQuotedTriplePattern(e.subject,t.subject);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.subject,t.subject))return null;if(e.predicate.type==="variable")r.set(e.predicate.value,t.predicate);else if(e.predicate.value!==t.predicate.value)return null;if(this.isVariable(e.object))r.set(e.object.value,t.object);else if(this.isQuotedTriple(e.object)){let i=this.matchQuotedTriplePattern(e.object,t.object);if(i===null)return null;for(let[s,a]of i)r.set(s,a)}else if(!this.elementsMatch(e.object,t.object))return null;return r}elementsMatch(e,t){switch(e.type){case"iri":return t instanceof wa.IRI&&e.value===t.value;case"literal":return!(!(t instanceof H_.Literal)||e.value!==t.value||e.datatype!==t.datatype?.value||e.language!==t.language||e.direction!==t.direction);case"blank":return t instanceof np.BlankNode&&e.value===t.id;case"quoted":return t instanceof ip.QuotedTriple?this.toRDFQuotedTriple(e).equals(t):!1;default:return!1}}isPropertyPath(e){return e.type==="path"}async*joinWithPattern(e,t){let r=[];for await(let i of e)r.push(i);for(let i of r){let s=this.instantiatePattern(t,i);for await(let a of this.matchTriplePattern(s)){let c=i.merge(a);c!==null&&(yield c)}}}instantiatePattern(e,t){let r=this.isPropertyPath(e.predicate)?e.predicate:this.instantiateElement(e.predicate,t);return{subject:this.instantiateElement(e.subject,t),predicate:r,object:this.instantiateElement(e.object,t)}}instantiateElement(e,t){if(this.isVariable(e)){let r=t.get(e.value);if(r)return this.toAlgebraElement(r)}return this.isQuotedTriple(e)?this.instantiateQuotedTriple(e,t):e}instantiateQuotedTriple(e,t){let r=this.instantiateElement(e.subject,t),i=e.predicate.type==="variable"?this.instantiatePredicateVariable(e.predicate,t):e.predicate,s=this.instantiateElement(e.object,t);return{type:"quoted",subject:r,predicate:i,object:s}}instantiatePredicateVariable(e,t){let r=t.get(e.value);return r&&r instanceof wa.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 wa.IRI(e.value);case"blank":return new np.BlankNode(e.value);case"literal":throw new Ur("Literals cannot appear in subject position");case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toRDFQuotedTriple(e){let t=this.toRDFTermAsSubject(e.subject),r=e.predicate.type==="iri"?new wa.IRI(e.predicate.value):(()=>{throw new Ur("Quoted triple predicate must be IRI")})(),i=this.toRDFTerm(e.object);return new ip.QuotedTriple(t,r,i)}toRDFTermAsPredicate(e){switch(e.type){case"iri":return new wa.IRI(e.value);case"literal":throw new Ur("Literals cannot appear in predicate position");case"blank":throw new Ur("Blank nodes cannot appear in predicate position");case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toRDFTerm(e){switch(e.type){case"iri":return new wa.IRI(e.value);case"literal":return new H_.Literal(e.value,e.datatype?new wa.IRI(e.datatype):void 0,e.language,e.direction);case"blank":return new np.BlankNode(e.value);case"variable":throw new Ur(`Cannot convert variable to RDF term: ${e.value}`);case"quoted":return this.toRDFQuotedTriple(e);default:throw new Ur(`Unknown element type: ${String(e)}`)}}toAlgebraElement(e){if(e instanceof wa.IRI)return{type:"iri",value:e.value};if(e instanceof H_.Literal)return{type:"literal",value:e.value,datatype:e.datatype?.value,language:e.language,direction:e.direction};if(e instanceof np.BlankNode)return{type:"blank",value:e.id};if(e instanceof ip.QuotedTriple)return this.toAlgebraQuotedTriple(e);throw new Ur(`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)}}};Nc.BGPExecutor=Q_});var EA=S(sp=>{"use strict";Object.defineProperty(sp,"__esModule",{value:!0});sp.StringFunctions=void 0;var Lc=Ce(),Ea=Ve(),K_=Gt(),$u=class n{static{o(this,"StringFunctions")}static str(e){if(e===void 0)throw new Error("STR: argument is undefined");return e instanceof Lc.IRI||e instanceof Ea.Literal?e.value:e instanceof K_.BlankNode?e.id:String(e)}static lang(e){if(e===void 0)throw new Error("LANG: argument is undefined");return e instanceof Ea.Literal&&e.language?e.language:""}static langdir(e){if(e===void 0)throw new Error("LANGDIR: argument is undefined");return!(e instanceof Ea.Literal)||!e.language?"":e.direction?`${e.language}--${e.direction}`:e.language}static langMatches(e,t){let[r,i]=n.parseDirectionalLangTag(e),[s,a]=n.parseDirectionalLangTag(t),c=r.toLowerCase(),l=s.toLowerCase();return l==="*"?c!=="":c===""?l==="":a&&i!==a?!1:c===l?!0:c.startsWith(l+"-")}static parseDirectionalLangTag(e){let t=e.indexOf("--");if(t===-1)return[e,void 0];let r=e.substring(0,t),i=e.substring(t+2).toLowerCase();return[r,i]}static 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",a=s.includes("u")?s:s+"u",c=new RegExp(t,a);return e.replace(c,r)}catch(s){throw new Error(`REPLACE: invalid pattern '${t}': ${s.message}`)}}static 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 Ea.Literal)r=e.value;else if(e instanceof Lc.IRI)r=e.value;else if(e instanceof K_.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 Ea.Literal)i=t.value.toUpperCase();else if(typeof t=="string")i=t.toUpperCase();else if(t instanceof Lc.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 Ea.Literal(s,new Lc.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 Ea.Literal)t=e.value;else if(e instanceof Lc.IRI)t=e.value;else if(e instanceof K_.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 Ea.Literal(r,new Lc.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}};sp.StringFunctions=$u;$u.VALID_NORMALIZATION_FORMS=["NFC","NFD","NFKC","NFKD"];$u.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 TA=S(ap=>{"use strict";Object.defineProperty(ap,"__esModule",{value:!0});ap.MathFunctions=void 0;var X_=class{static{o(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=X_});var cp=S(op=>{"use strict";Object.defineProperty(op,"__esModule",{value:!0});op.DateTimeParsing=void 0;var _j=Ce(),Sj=Ve(),J_=class n{static{o(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"),a="",c="";if(s===-1?a=r:(a=r.substring(0,s),c=r.substring(s+1)),a){let l=a.match(/^(\d+(?:\.\d+)?)D$/);if(l){let u=parseFloat(l[1]);i+=u*24*60*60*1e3}else if(a!=="")throw new Error(`parseDayTimeDuration: invalid day component: '${a}' in '${e}'`)}if(c){let l=c,u=l.match(/^(\d+(?:\.\d+)?)H/);if(u){let 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 a=Math.floor(r/(60*1e3));r=r%(60*1e3);let c=r/1e3,l=t?"-P":"P";return i>0&&(l+=`${i}D`),(s>0||a>0||c>0||i===0)&&(l+="T",s>0&&(l+=`${s}H`),a>0&&(l+=`${a}M`),(c>0||s===0&&a===0)&&(Number.isInteger(c)?l+=`${c}S`:l+=`${parseFloat(c.toFixed(3))}S`)),l}static xsdDayTimeDuration(e){return n.parseDayTimeDuration(e),new Sj.Literal(e,new _j.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static parseXSDDate(e){let t=/^(-?\d{4})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,r=e.match(t);if(!r){let u=new Date(e);return isNaN(u.getTime())?null:new Date(Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate()))}let i=parseInt(r[1],10),s=parseInt(r[2],10)-1,a=parseInt(r[3],10),c=r[4],l=new Date(Date.UTC(i,s,a));if(c&&c!=="Z"){let u=c.match(/([+-])(\d{2}):(\d{2})/);if(u){let f=u[1]==="+"?1:-1,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),a=parseInt(r[3],10),c=r[4],l=r[5];if(i<0||i>24||s<0||s>59||a<0||a>59||i===24&&(s!==0||a!==0))return null;let u=0;if(c){let d=c.padEnd(3,"0").slice(0,3);u=parseInt(d,10)}let f=i*60*60*1e3+s*60*1e3+a*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),_=parseInt(d[3],10),b=h*(p*60+_)*60*1e3;f-=b}}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),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDuration: invalid format (no duration components): '${e}'`);let c=s*12+a;return i?-c:c}static formatYearMonthDuration(e){let t=e<0,r=Math.abs(e),i=Math.floor(r/12),s=r%12,a=t?"-P":"P";return i>0&&(a+=`${i}Y`),(s>0||i===0)&&(a+=`${s}M`),a}static parseYearMonthDurationComponents(e){let t=/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?$/,r=e.match(t);if(!r)throw new Error(`parseYearMonthDurationComponents: invalid format: '${e}'`);let i=r[1]==="-",s=parseInt(r[2]||"0",10),a=parseInt(r[3]||"0",10);if(!r[2]&&!r[3])throw new Error(`parseYearMonthDurationComponents: invalid format (no duration components): '${e}'`);return{years:s,months:a,negative:i}}static parseDurationComponents(e){if(!e)throw new Error("parseDurationComponents: duration string is empty");let t=!1,r=e.trim();if(r.startsWith("-")&&(t=!0,r=r.substring(1)),!r.startsWith("P"))throw new Error(`parseDurationComponents: invalid format, must start with 'P': '${e}'`);r=r.substring(1);let i=0,s=0,a=0,c=0,l=r.indexOf("T"),u="",f="";if(l===-1?u=r:(u=r.substring(0,l),f=r.substring(l+1)),u){let 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&&(a=parseFloat(p[1]),d=d.substring(p[0].length));let _=d.match(/^(\d+(?:\.\d+)?)S$/);if(_&&(c=parseFloat(_[1]),d=d.substring(_[0].length)),d!=="")throw new Error(`parseDurationComponents: invalid time component: '${d}' in '${e}'`)}return{negative:t,days:i,hours:s,minutes:a,seconds:c}}};op.DateTimeParsing=J_});var AA=S(lp=>{"use strict";Object.defineProperty(lp,"__esModule",{value:!0});lp.DateTimeArithmetic=void 0;var on=Ce(),Te=Ve(),Xe=cp(),Z_=class{static{o(this,"DateTimeArithmetic")}static dateTimeDiff(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r),a=new Date(i);if(isNaN(s.getTime()))throw new Error(`dateTimeDiff: invalid first dateTime: '${r}'`);if(isNaN(a.getTime()))throw new Error(`dateTimeDiff: invalid second dateTime: '${i}'`);let c=s.getTime()-a.getTime(),l=Xe.DateTimeParsing.formatDayTimeDuration(c);return new Te.Literal(l,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static dateTimeAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAdd: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+a,l=new Date(c);return new Te.Literal(l.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtract: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-a,l=new Date(c);return new Te.Literal(l.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAdd: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()+a,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 Te.Literal(h,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtract: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=s.getTime()-a,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 Te.Literal(h,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateTimeAddYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeAddYearMonth: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0),new Te.Literal(s.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateTimeSubtractYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=new Date(r);if(isNaN(s.getTime()))throw new Error(`dateTimeSubtractYearMonth: invalid dateTime: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();return s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0),new Te.Literal(s.toISOString(),new on.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static dateAddYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateAddYearMonth: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()+a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=`${l}-${u}-${f}`;return new Te.Literal(d,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static dateSubtractYearMonth(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseXSDDate(r);if(s===null)throw new Error(`dateSubtractYearMonth: invalid date: '${r}'`);let a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=s.getUTCDate();s.setUTCMonth(s.getUTCMonth()-a),s.getUTCDate()!==c&&s.setUTCDate(0);let l=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=`${l}-${u}-${f}`;return new Te.Literal(d,new on.IRI("http://www.w3.org/2001/XMLSchema#date"))}static durationAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseDayTimeDuration(r),a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=Xe.DateTimeParsing.formatDayTimeDuration(s+a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseDayTimeDuration(r),a=Xe.DateTimeParsing.parseDayTimeDuration(i),c=Xe.DateTimeParsing.formatDayTimeDuration(s-a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static durationMultiply(e,t){let r=e instanceof Te.Literal?e.value:e,i=Xe.DateTimeParsing.parseDayTimeDuration(r),s=Xe.DateTimeParsing.formatDayTimeDuration(i*t);return new Te.Literal(s,new on.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 Te.Literal?e.value:e,i=Xe.DateTimeParsing.parseDayTimeDuration(r),s=Xe.DateTimeParsing.formatDayTimeDuration(i/t);return new Te.Literal(s,new on.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static yearMonthDurationAdd(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseYearMonthDuration(r),a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=Xe.DateTimeParsing.formatYearMonthDuration(s+a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static yearMonthDurationSubtract(e,t){let r=e instanceof Te.Literal?e.value:e,i=t instanceof Te.Literal?t.value:t,s=Xe.DateTimeParsing.parseYearMonthDuration(r),a=Xe.DateTimeParsing.parseYearMonthDuration(i),c=Xe.DateTimeParsing.formatYearMonthDuration(s-a);return new Te.Literal(c,new on.IRI("http://www.w3.org/2001/XMLSchema#yearMonthDuration"))}static durationToDays(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(1440*60*1e3)}static durationToHours(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(3600*1e3)}static durationToMinutes(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/(60*1e3)}static durationToSeconds(e){let t=e instanceof Te.Literal?e.value:e;return Xe.DateTimeParsing.parseDayTimeDuration(t)/1e3}};lp.DateTimeArithmetic=Z_});var xA=S(up=>{"use strict";Object.defineProperty(up,"__esModule",{value:!0});up.DateTimeAccessors=void 0;var Bu=Ce(),Lt=Ve(),Tt=cp(),e1=class{static{o(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 Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.days);return r.negative?-i:i}static durationHours(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.hours);return r.negative?-i:i}static durationMinutes(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t),i=Math.floor(r.minutes);return r.negative?-i:i}static durationSeconds(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseDurationComponents(t);return r.negative?-r.seconds:r.seconds}static durationYears(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.DateTimeParsing.parseYearMonthDurationComponents(t);return r.negative?-r.years:r.years}static durationMonths(e){let t=e instanceof Lt.Literal?e.value:e,r=Tt.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),a=parseInt(i[2],10),c=s>=0?"":"-",l=Math.abs(s);a===0?r=`${c}PT${l}H`:r=`${c}PT${l}H${a}M`}else{let s=-t.getTimezoneOffset(),a=Math.floor(Math.abs(s)/60),c=Math.abs(s)%60,l=s>=0?"":"-";c===0?r=`${l}PT${a}H`:r=`${l}PT${a}H${c}M`}}return new Lt.Literal(r,new Bu.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 Lt.Literal?e.value:e,i=new Date(r);if(isNaN(i.getTime()))throw new Error(`ADJUST: invalid dateTime: '${r}'`);if(t==null){let we=i.getUTCFullYear(),z=String(i.getUTCMonth()+1).padStart(2,"0"),G=String(i.getUTCDate()).padStart(2,"0"),F=String(i.getUTCHours()).padStart(2,"0"),j=String(i.getUTCMinutes()).padStart(2,"0"),te=String(i.getUTCSeconds()).padStart(2,"0"),Ye=i.getUTCMilliseconds(),st=`${we}-${z}-${G}T${F}:${j}:${te}`;return Ye>0&&(st+=`.${String(Ye).padStart(3,"0")}`),new Lt.Literal(st,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}let s=t instanceof Lt.Literal?t.value:t,a=Tt.DateTimeParsing.parseDayTimeDuration(s),c=840*60*1e3;if(Math.abs(a)>c)throw new Error(`ADJUST: timezone offset out of range: '${s}'`);let l=i.getTime(),u=new Date(l+a),f=u.getUTCFullYear(),d=String(u.getUTCMonth()+1).padStart(2,"0"),h=String(u.getUTCDate()).padStart(2,"0"),p=String(u.getUTCHours()).padStart(2,"0"),_=String(u.getUTCMinutes()).padStart(2,"0"),b=String(u.getUTCSeconds()).padStart(2,"0"),E=u.getUTCMilliseconds(),v=a>=0?"+":"-",A=Math.floor(Math.abs(a)/(3600*1e3)),R=Math.floor(Math.abs(a)%(3600*1e3)/(60*1e3)),B=`${v}${String(A).padStart(2,"0")}:${String(R).padStart(2,"0")}`,W=`${f}-${d}-${h}T${p}:${_}:${b}`;return E>0&&(W+=`.${String(E).padStart(3,"0")}`),W+=B,new Lt.Literal(W,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dateTime"))}static now(){return new Date().toISOString()}static dateBefore(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t);return r<i}static dateAfter(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t);return r>i}static dateInRange(e,t,r){let i=Tt.DateTimeParsing.parseDate(e),s=Tt.DateTimeParsing.parseDate(t),a=Tt.DateTimeParsing.parseDate(r);return i>=s&&i<=a}static compareDurations(e,t,r){let i=e instanceof Lt.Literal?e.value:e,s=t instanceof Lt.Literal?t.value:t,a=Tt.DateTimeParsing.parseDayTimeDuration(i),c=Tt.DateTimeParsing.parseDayTimeDuration(s);switch(r){case"=":return a===c;case"!=":return a!==c;case"<":return a<c;case">":return a>c;case"<=":return a<=c;case">=":return a>=c;default:throw new Error(`compareDurations: unknown operator: ${r}`)}}static dateDiffMinutes(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.DateTimeParsing.parseDate(t),s=Math.abs(i-r);return Math.round(s/(1e3*60))}static dateDiffHours(e,t){let r=Tt.DateTimeParsing.parseDate(e),i=Tt.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 Lt.Literal?e.value:e,i=t instanceof Lt.Literal?t.value:t,s=Tt.DateTimeParsing.parseXSDTime(r),a=Tt.DateTimeParsing.parseXSDTime(i);if(s===null)throw new Error(`timeDiff: invalid first time: '${r}'`);if(a===null)throw new Error(`timeDiff: invalid second time: '${i}'`);let c=s-a,l=Tt.DateTimeParsing.formatDayTimeDuration(c);return new Lt.Literal(l,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}static isDayTimeDuration(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}static isDate(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}static isYearMonthDuration(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}static isTime(e){return e instanceof Lt.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}static dateDiff(e,t){let r=e instanceof Lt.Literal?e.value:e,i=t instanceof Lt.Literal?t.value:t,s=Tt.DateTimeParsing.parseXSDDate(r),a=Tt.DateTimeParsing.parseXSDDate(i);if(s===null)throw new Error(`dateDiff: invalid first date: '${r}'`);if(a===null)throw new Error(`dateDiff: invalid second date: '${i}'`);let c=s.getTime()-a.getTime(),l=Math.round(c/(1440*60*1e3)),u=Tt.DateTimeParsing.formatDateDuration(l);return new Lt.Literal(u,new Bu.IRI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))}};up.DateTimeAccessors=e1});var r1=S(fp=>{"use strict";Object.defineProperty(fp,"__esModule",{value:!0});fp.DateTimeFunctions=void 0;var kc=cp(),ir=AA(),gt=xA(),t1=class{static{o(this,"DateTimeFunctions")}static parseDate(e){return kc.DateTimeParsing.parseDate(e)}static parseDayTimeDuration(e){return kc.DateTimeParsing.parseDayTimeDuration(e)}static formatDayTimeDuration(e){return kc.DateTimeParsing.formatDayTimeDuration(e)}static xsdDayTimeDuration(e){return kc.DateTimeParsing.xsdDayTimeDuration(e)}static parseYearMonthDuration(e){return kc.DateTimeParsing.parseYearMonthDuration(e)}static formatYearMonthDuration(e){return kc.DateTimeParsing.formatYearMonthDuration(e)}static year(e){return gt.DateTimeAccessors.year(e)}static month(e){return gt.DateTimeAccessors.month(e)}static day(e){return gt.DateTimeAccessors.day(e)}static hours(e){return gt.DateTimeAccessors.hours(e)}static minutes(e){return gt.DateTimeAccessors.minutes(e)}static seconds(e){return gt.DateTimeAccessors.seconds(e)}static durationDays(e){return gt.DateTimeAccessors.durationDays(e)}static durationHours(e){return gt.DateTimeAccessors.durationHours(e)}static durationMinutes(e){return gt.DateTimeAccessors.durationMinutes(e)}static durationSeconds(e){return gt.DateTimeAccessors.durationSeconds(e)}static durationYears(e){return gt.DateTimeAccessors.durationYears(e)}static durationMonths(e){return gt.DateTimeAccessors.durationMonths(e)}static timezone(e){return gt.DateTimeAccessors.timezone(e)}static tz(e){return gt.DateTimeAccessors.tz(e)}static adjust(e,t){return gt.DateTimeAccessors.adjust(e,t)}static now(){return gt.DateTimeAccessors.now()}static dateBefore(e,t){return gt.DateTimeAccessors.dateBefore(e,t)}static dateAfter(e,t){return gt.DateTimeAccessors.dateAfter(e,t)}static dateInRange(e,t,r){return gt.DateTimeAccessors.dateInRange(e,t,r)}static compareDurations(e,t,r){return gt.DateTimeAccessors.compareDurations(e,t,r)}static dateDiffMinutes(e,t){return gt.DateTimeAccessors.dateDiffMinutes(e,t)}static dateDiffHours(e,t){return gt.DateTimeAccessors.dateDiffHours(e,t)}static timeDiff(e,t){return gt.DateTimeAccessors.timeDiff(e,t)}static dateDiff(e,t){return gt.DateTimeAccessors.dateDiff(e,t)}static isDayTimeDuration(e){return gt.DateTimeAccessors.isDayTimeDuration(e)}static isDate(e){return gt.DateTimeAccessors.isDate(e)}static isYearMonthDuration(e){return gt.DateTimeAccessors.isYearMonthDuration(e)}static isTime(e){return gt.DateTimeAccessors.isTime(e)}static dateTimeDiff(e,t){return ir.DateTimeArithmetic.dateTimeDiff(e,t)}static dateTimeAdd(e,t){return ir.DateTimeArithmetic.dateTimeAdd(e,t)}static dateTimeSubtract(e,t){return ir.DateTimeArithmetic.dateTimeSubtract(e,t)}static dateAdd(e,t){return ir.DateTimeArithmetic.dateAdd(e,t)}static dateSubtract(e,t){return ir.DateTimeArithmetic.dateSubtract(e,t)}static dateTimeAddYearMonth(e,t){return ir.DateTimeArithmetic.dateTimeAddYearMonth(e,t)}static dateTimeSubtractYearMonth(e,t){return ir.DateTimeArithmetic.dateTimeSubtractYearMonth(e,t)}static dateAddYearMonth(e,t){return ir.DateTimeArithmetic.dateAddYearMonth(e,t)}static dateSubtractYearMonth(e,t){return ir.DateTimeArithmetic.dateSubtractYearMonth(e,t)}static durationAdd(e,t){return ir.DateTimeArithmetic.durationAdd(e,t)}static durationSubtract(e,t){return ir.DateTimeArithmetic.durationSubtract(e,t)}static durationMultiply(e,t){return ir.DateTimeArithmetic.durationMultiply(e,t)}static durationDivide(e,t){return ir.DateTimeArithmetic.durationDivide(e,t)}static yearMonthDurationAdd(e,t){return ir.DateTimeArithmetic.yearMonthDurationAdd(e,t)}static yearMonthDurationSubtract(e,t){return ir.DateTimeArithmetic.yearMonthDurationSubtract(e,t)}static durationToDays(e){return ir.DateTimeArithmetic.durationToDays(e)}static durationToHours(e){return ir.DateTimeArithmetic.durationToHours(e)}static durationToMinutes(e){return ir.DateTimeArithmetic.durationToMinutes(e)}static durationToSeconds(e){return ir.DateTimeArithmetic.durationToSeconds(e)}};fp.DateTimeFunctions=t1});var CA=S(hp=>{"use strict";Object.defineProperty(hp,"__esModule",{value:!0});hp.LogicalFunctions=void 0;var bj=Ce(),Mc=Ve(),vj=Gt(),dp=r1(),n1=class n{static{o(this,"LogicalFunctions")}static compare(e,t,r){if(n.isDayTimeDurationValue(e)&&n.isDayTimeDurationValue(t))return dp.DateTimeFunctions.compareDurations(e instanceof Mc.Literal?e:String(e),t instanceof Mc.Literal?t:String(t),r);if(n.isDayTimeDurationValue(e)&&typeof t=="string"&&/^-?P/.test(t))return dp.DateTimeFunctions.compareDurations(e instanceof Mc.Literal?e:String(e),t,r);if(typeof e=="string"&&/^-?P/.test(e)&&n.isDayTimeDurationValue(t))return dp.DateTimeFunctions.compareDurations(e,t instanceof Mc.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 Mc.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 Mc.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 dp.DateTimeFunctions.parseDayTimeDuration(e.value)}catch{return e.value}return e.value}return e instanceof bj.IRI?e.value:e instanceof vj.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}};hp.LogicalFunctions=n1});var IA=S(pp=>{"use strict";Object.defineProperty(pp,"__esModule",{value:!0});pp.RDFTermFunctions=void 0;var Fr=Ce(),bt=Ve(),oi=Gt(),jc=bu(),i1=Sn(),s1=class n{static{o(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 Fr.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"):new Fr.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 Fr.IRI}static isBlank(e){return e===void 0?!1:e instanceof oi.BlankNode}static isLiteral(e){return e===void 0?!1:e instanceof bt.Literal}static isTriple(e){return e===void 0?!1:e instanceof jc.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 Fr.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 Fr.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 Fr.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 Fr.IRI&&t instanceof Fr.IRI)return e.value===t.value;if(e instanceof oi.BlankNode&&t instanceof oi.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 Fr.IRI)return e;if(e instanceof bt.Literal)return new Fr.IRI(e.value);throw e instanceof oi.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,i1.v4)().replace(/-/g,"").substring(0,12)}`;return new oi.BlankNode(t)}if(e instanceof bt.Literal)return new oi.BlankNode(e.value);if(e instanceof oi.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 Fr.IRI)i=t;else if(t instanceof bt.Literal)i=new Fr.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 a;if(r instanceof bt.Literal)a=r.value.toLowerCase();else throw new Error("STRLANGDIR: direction must be a string literal");if(a!=="ltr"&&a!=="rtl")throw new Error(`STRLANGDIR: invalid direction '${a}'. Must be 'ltr' or 'rtl'`);return new bt.Literal(i,void 0,s,a)}static uuid(){let e=(0,i1.v4)();return new Fr.IRI(`urn:uuid:${e}`)}static struuid(){let e=(0,i1.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 Fr.IRI)){let c=t instanceof bt.Literal?"Literal":t instanceof oi.BlankNode?"BlankNode":t instanceof jc.QuotedTriple?"QuotedTriple":typeof t;throw new Error(`TRIPLE: predicate must be IRI, got ${c}`)}let i=e,s=t,a=r;return new jc.QuotedTriple(i,s,a)}static subject(e){if(e===void 0)throw new Error("SUBJECT: argument is undefined");if(!(e instanceof jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.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 jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.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 jc.QuotedTriple)){let t=e instanceof Fr.IRI?"IRI":e instanceof bt.Literal?"Literal":e instanceof oi.BlankNode?"BlankNode":typeof e;throw new Error(`OBJECT: argument must be QuotedTriple, got ${t}`)}return e.object}};pp.RDFTermFunctions=s1});var RA=S(mp=>{"use strict";Object.defineProperty(mp,"__esModule",{value:!0});mp.HashFunctions=void 0;var a1=class{static{o(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")}};mp.HashFunctions=a1});var yp=S(gp=>{"use strict";Object.defineProperty(gp,"__esModule",{value:!0});gp.BuiltInFunctions=void 0;var sr=EA(),Ta=TA(),oe=r1(),$c=CA(),Ot=IA(),Vu=RA(),o1=class{static{o(this,"BuiltInFunctions")}static str(...e){return sr.StringFunctions.str(...e)}static lang(...e){return sr.StringFunctions.lang(...e)}static langdir(...e){return sr.StringFunctions.langdir(...e)}static langMatches(...e){return sr.StringFunctions.langMatches(...e)}static regex(...e){return sr.StringFunctions.regex(...e)}static contains(...e){return sr.StringFunctions.contains(...e)}static strStarts(...e){return sr.StringFunctions.strStarts(...e)}static strEnds(...e){return sr.StringFunctions.strEnds(...e)}static strlen(...e){return sr.StringFunctions.strlen(...e)}static ucase(...e){return sr.StringFunctions.ucase(...e)}static lcase(...e){return sr.StringFunctions.lcase(...e)}static substr(...e){return sr.StringFunctions.substr(...e)}static strBefore(...e){return sr.StringFunctions.strBefore(...e)}static strAfter(...e){return sr.StringFunctions.strAfter(...e)}static concat(...e){return sr.StringFunctions.concat(...e)}static replace(...e){return sr.StringFunctions.replace(...e)}static encodeForUri(...e){return sr.StringFunctions.encodeForUri(...e)}static normalize(...e){return sr.StringFunctions.normalize(...e)}static fold(...e){return sr.StringFunctions.fold(...e)}static abs(...e){return Ta.MathFunctions.abs(...e)}static round(...e){return Ta.MathFunctions.round(...e)}static ceil(...e){return Ta.MathFunctions.ceil(...e)}static floor(...e){return Ta.MathFunctions.floor(...e)}static rand(){return Ta.MathFunctions.rand()}static msToMinutes(...e){return Ta.MathFunctions.msToMinutes(...e)}static msToHours(...e){return Ta.MathFunctions.msToHours(...e)}static msToSeconds(...e){return Ta.MathFunctions.msToSeconds(...e)}static parseDate(...e){return oe.DateTimeFunctions.parseDate(...e)}static dateBefore(...e){return oe.DateTimeFunctions.dateBefore(...e)}static dateAfter(...e){return oe.DateTimeFunctions.dateAfter(...e)}static dateInRange(...e){return oe.DateTimeFunctions.dateInRange(...e)}static dateDiffMinutes(...e){return oe.DateTimeFunctions.dateDiffMinutes(...e)}static dateDiffHours(...e){return oe.DateTimeFunctions.dateDiffHours(...e)}static year(...e){return oe.DateTimeFunctions.year(...e)}static month(...e){return oe.DateTimeFunctions.month(...e)}static day(...e){return oe.DateTimeFunctions.day(...e)}static hours(...e){return oe.DateTimeFunctions.hours(...e)}static minutes(...e){return oe.DateTimeFunctions.minutes(...e)}static seconds(...e){return oe.DateTimeFunctions.seconds(...e)}static timezone(...e){return oe.DateTimeFunctions.timezone(...e)}static tz(...e){return oe.DateTimeFunctions.tz(...e)}static now(){return oe.DateTimeFunctions.now()}static parseDayTimeDuration(...e){return oe.DateTimeFunctions.parseDayTimeDuration(...e)}static formatDayTimeDuration(...e){return oe.DateTimeFunctions.formatDayTimeDuration(...e)}static xsdDayTimeDuration(...e){return oe.DateTimeFunctions.xsdDayTimeDuration(...e)}static compareDurations(...e){return oe.DateTimeFunctions.compareDurations(...e)}static isDayTimeDuration(...e){return oe.DateTimeFunctions.isDayTimeDuration(...e)}static isDate(...e){return oe.DateTimeFunctions.isDate(...e)}static dateDiff(...e){return oe.DateTimeFunctions.dateDiff(...e)}static dateTimeDiff(...e){return oe.DateTimeFunctions.dateTimeDiff(...e)}static dateTimeAdd(...e){return oe.DateTimeFunctions.dateTimeAdd(...e)}static dateTimeSubtract(...e){return oe.DateTimeFunctions.dateTimeSubtract(...e)}static dateAdd(...e){return oe.DateTimeFunctions.dateAdd(...e)}static dateSubtract(...e){return oe.DateTimeFunctions.dateSubtract(...e)}static parseYearMonthDuration(...e){return oe.DateTimeFunctions.parseYearMonthDuration(...e)}static isYearMonthDuration(...e){return oe.DateTimeFunctions.isYearMonthDuration(...e)}static dateTimeAddYearMonth(...e){return oe.DateTimeFunctions.dateTimeAddYearMonth(...e)}static dateTimeSubtractYearMonth(...e){return oe.DateTimeFunctions.dateTimeSubtractYearMonth(...e)}static dateAddYearMonth(...e){return oe.DateTimeFunctions.dateAddYearMonth(...e)}static dateSubtractYearMonth(...e){return oe.DateTimeFunctions.dateSubtractYearMonth(...e)}static durationAdd(...e){return oe.DateTimeFunctions.durationAdd(...e)}static durationSubtract(...e){return oe.DateTimeFunctions.durationSubtract(...e)}static durationMultiply(...e){return oe.DateTimeFunctions.durationMultiply(...e)}static durationDivide(...e){return oe.DateTimeFunctions.durationDivide(...e)}static formatYearMonthDuration(...e){return oe.DateTimeFunctions.formatYearMonthDuration(...e)}static yearMonthDurationAdd(...e){return oe.DateTimeFunctions.yearMonthDurationAdd(...e)}static yearMonthDurationSubtract(...e){return oe.DateTimeFunctions.yearMonthDurationSubtract(...e)}static durationYears(...e){return oe.DateTimeFunctions.durationYears(...e)}static durationMonths(...e){return oe.DateTimeFunctions.durationMonths(...e)}static durationToDays(...e){return oe.DateTimeFunctions.durationToDays(...e)}static durationToHours(...e){return oe.DateTimeFunctions.durationToHours(...e)}static durationToMinutes(...e){return oe.DateTimeFunctions.durationToMinutes(...e)}static durationToSeconds(...e){return oe.DateTimeFunctions.durationToSeconds(...e)}static durationDays(...e){return oe.DateTimeFunctions.durationDays(...e)}static durationHours(...e){return oe.DateTimeFunctions.durationHours(...e)}static durationMinutes(...e){return oe.DateTimeFunctions.durationMinutes(...e)}static durationSeconds(...e){return oe.DateTimeFunctions.durationSeconds(...e)}static adjust(...e){return oe.DateTimeFunctions.adjust(...e)}static isTime(...e){return oe.DateTimeFunctions.isTime(...e)}static timeDiff(...e){return oe.DateTimeFunctions.timeDiff(...e)}static compare(...e){return $c.LogicalFunctions.compare(...e)}static logicalAnd(...e){return $c.LogicalFunctions.logicalAnd(...e)}static logicalOr(...e){return $c.LogicalFunctions.logicalOr(...e)}static logicalNot(...e){return $c.LogicalFunctions.logicalNot(...e)}static coalesce(...e){return $c.LogicalFunctions.coalesce(...e)}static if(...e){return $c.LogicalFunctions.if(...e)}static datatype(...e){return Ot.RDFTermFunctions.datatype(...e)}static bound(...e){return Ot.RDFTermFunctions.bound(...e)}static isIRI(...e){return Ot.RDFTermFunctions.isIRI(...e)}static isBlank(...e){return Ot.RDFTermFunctions.isBlank(...e)}static isLiteral(...e){return Ot.RDFTermFunctions.isLiteral(...e)}static isTriple(...e){return Ot.RDFTermFunctions.isTriple(...e)}static isNumeric(...e){return Ot.RDFTermFunctions.isNumeric(...e)}static hasLangdir(...e){return Ot.RDFTermFunctions.hasLangdir(...e)}static sameTerm(...e){return Ot.RDFTermFunctions.sameTerm(...e)}static iri(...e){return Ot.RDFTermFunctions.iri(...e)}static uri(...e){return Ot.RDFTermFunctions.uri(...e)}static bnode(...e){return Ot.RDFTermFunctions.bnode(...e)}static strdt(...e){return Ot.RDFTermFunctions.strdt(...e)}static strlang(...e){return Ot.RDFTermFunctions.strlang(...e)}static strlangdir(...e){return Ot.RDFTermFunctions.strlangdir(...e)}static uuid(){return Ot.RDFTermFunctions.uuid()}static struuid(){return Ot.RDFTermFunctions.struuid()}static xsdDateTime(...e){return Ot.RDFTermFunctions.xsdDateTime(...e)}static xsdInteger(...e){return Ot.RDFTermFunctions.xsdInteger(...e)}static xsdDecimal(...e){return Ot.RDFTermFunctions.xsdDecimal(...e)}static triple(...e){return Ot.RDFTermFunctions.triple(...e)}static subject(...e){return Ot.RDFTermFunctions.subject(...e)}static predicate(...e){return Ot.RDFTermFunctions.predicate(...e)}static object(...e){return Ot.RDFTermFunctions.object(...e)}static md5(...e){return Vu.HashFunctions.md5(...e)}static sha1(...e){return Vu.HashFunctions.sha1(...e)}static sha256(...e){return Vu.HashFunctions.sha256(...e)}static sha384(...e){return Vu.HashFunctions.sha384(...e)}static sha512(...e){return Vu.HashFunctions.sha512(...e)}};gp.BuiltInFunctions=o1});var Uu=S(ns=>{"use strict";Object.defineProperty(ns,"__esModule",{value:!0});ns.ExoQLBudgetExceededError=ns.ExoQLCycleError=ns.ExoQLEvalDisabledError=ns.ExoQLForbiddenKeywordError=void 0;var c1=class extends Error{static{o(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}};ns.ExoQLForbiddenKeywordError=c1;var l1=class extends Error{static{o(this,"ExoQLEvalDisabledError")}constructor(e){super(e??"ExoQLEvalDisabledError: exoql.eval.enabled is false (default). Flip the feature flag to opt in."),this.name="ExoQLEvalDisabledError"}};ns.ExoQLEvalDisabledError=l1;var u1=class extends Error{static{o(this,"ExoQLCycleError")}constructor(e,t){super(t??`ExoQLCycleError: cycle detected in nested exo:eval invocations: ${e.join(" \u2192 ")}`),this.name="ExoQLCycleError",this.path=e}};ns.ExoQLCycleError=u1;var f1=class extends Error{static{o(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}};ns.ExoQLBudgetExceededError=f1});var jA=S(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.functionHandlers=void 0;var k=yp();M.functionHandlers=new Map;M.functionHandlers.set("str",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.str(t)});M.functionHandlers.set("lang",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.lang(t)});M.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 k.BuiltInFunctions.langMatches(t,r)});M.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 k.BuiltInFunctions.contains(t,r)});M.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 k.BuiltInFunctions.strStarts(t,r)});M.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 k.BuiltInFunctions.strEnds(t,r)});M.functionHandlers.set("strlen",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.strlen(t)});M.functionHandlers.set("ucase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.ucase(t)});M.functionHandlers.set("lcase",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.lcase(t)});M.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 k.BuiltInFunctions.substr(t,r,i)}return k.BuiltInFunctions.substr(t,r)});M.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 k.BuiltInFunctions.strBefore(t,r)});M.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 k.BuiltInFunctions.strAfter(t,r)});M.functionHandlers.set("concat",(n,e)=>{let t=n.map(r=>e.getStringValue(e.evaluateExpression(r,e.solution)));return k.BuiltInFunctions.concat(...t)});M.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 k.BuiltInFunctions.replace(t,r,i,s)});M.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 k.BuiltInFunctions.regex(t,r,i)});M.functionHandlers.set("encode_for_uri",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.encodeForUri(t)});M.functionHandlers.set("datatype",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.datatype(t).value});M.functionHandlers.set("bound",(n,e)=>{let t=n[0];if(t.type==="variable"&&t.name){let r=e.solution.get(t.name);return k.BuiltInFunctions.bound(r)}return!0});var OA=o((n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isIRI(t)},"isIriHandler");M.functionHandlers.set("isiri",OA);M.functionHandlers.set("isuri",OA);M.functionHandlers.set("isblank",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isBlank(t)});M.functionHandlers.set("isliteral",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isLiteral(t)});M.functionHandlers.set("isnumeric",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isNumeric(t)});M.functionHandlers.set("haslangdir",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.hasLangdir(t)});M.functionHandlers.set("istriple",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.isTriple(t)});M.functionHandlers.set("sameterm",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution),r=e.getTermFromExpression(n[1],e.solution);return k.BuiltInFunctions.sameTerm(t,r)});M.functionHandlers.set("abs",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.abs(t)});M.functionHandlers.set("round",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.round(t)});M.functionHandlers.set("ceil",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.ceil(t)});M.functionHandlers.set("floor",(n,e)=>{let t=Number(e.getStringValue(e.evaluateExpression(n[0],e.solution)));return k.BuiltInFunctions.floor(t)});M.functionHandlers.set("rand",()=>k.BuiltInFunctions.rand());M.functionHandlers.set("parsedate",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.parseDate(t)});M.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 k.BuiltInFunctions.dateBefore(t,r)});M.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 k.BuiltInFunctions.dateAfter(t,r)});M.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 k.BuiltInFunctions.dateInRange(t,r,i)});M.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 k.BuiltInFunctions.dateDiffMinutes(t,r)});M.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 k.BuiltInFunctions.dateDiffHours(t,r)});var Bc=o((n,e,t)=>(r,i)=>{let s=i.evaluateExpression(r[0],i.solution);return e&&i.isYearMonthDurationValue(s)?e(s):t&&i.isDayTimeDurationValue(s)?t(s):n(i.getStringValue(s))},"createDateTimeAccessor"),PA=Bc(k.BuiltInFunctions.year.bind(k.BuiltInFunctions),k.BuiltInFunctions.durationYears.bind(k.BuiltInFunctions),null);M.functionHandlers.set("year",PA);M.functionHandlers.set("years",PA);var FA=Bc(k.BuiltInFunctions.month.bind(k.BuiltInFunctions),k.BuiltInFunctions.durationMonths.bind(k.BuiltInFunctions),null);M.functionHandlers.set("month",FA);M.functionHandlers.set("months",FA);var DA=Bc(k.BuiltInFunctions.day.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationDays.bind(k.BuiltInFunctions));M.functionHandlers.set("day",DA);M.functionHandlers.set("days",DA);M.functionHandlers.set("hours",Bc(k.BuiltInFunctions.hours.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationHours.bind(k.BuiltInFunctions)));M.functionHandlers.set("minutes",Bc(k.BuiltInFunctions.minutes.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationMinutes.bind(k.BuiltInFunctions)));M.functionHandlers.set("seconds",Bc(k.BuiltInFunctions.seconds.bind(k.BuiltInFunctions),null,k.BuiltInFunctions.durationSeconds.bind(k.BuiltInFunctions)));M.functionHandlers.set("timezone",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.timezone(t)});M.functionHandlers.set("tz",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.tz(t)});M.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 k.BuiltInFunctions.adjust(t,r)});M.functionHandlers.set("now",()=>k.BuiltInFunctions.now());var NA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDateTime(e.getStringValue(t))},"dateTimeHandler");M.functionHandlers.set("datetime",NA);M.functionHandlers.set("xsd:datetime",NA);var LA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdInteger(e.getStringValue(t))},"integerHandler");M.functionHandlers.set("integer",LA);M.functionHandlers.set("xsd:integer",LA);var kA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDecimal(e.getStringValue(t))},"decimalHandler");M.functionHandlers.set("decimal",kA);M.functionHandlers.set("xsd:decimal",kA);var MA=o((n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.xsdDayTimeDuration(e.getStringValue(t))},"dayTimeDurationHandler");M.functionHandlers.set("daytimeduration",MA);M.functionHandlers.set("xsd:daytimeduration",MA);M.functionHandlers.set("durationtodays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToDays(t)});M.functionHandlers.set("durationtohours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToHours(t)});M.functionHandlers.set("durationtominutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToMinutes(t)});M.functionHandlers.set("durationtoseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationToSeconds(t)});M.functionHandlers.set("durationdays",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationDays(t)});M.functionHandlers.set("durationhours",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationHours(t)});M.functionHandlers.set("durationminutes",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationMinutes(t)});M.functionHandlers.set("durationseconds",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationSeconds(t)});M.functionHandlers.set("durationyears",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationYears(t)});M.functionHandlers.set("durationmonths",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution);return k.BuiltInFunctions.durationMonths(t)});M.functionHandlers.set("datetimediff",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeDiff(t,r)});M.functionHandlers.set("datetimeadd",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeAdd(t,r)});M.functionHandlers.set("datetimesubtract",(n,e)=>{let t=e.evaluateExpression(n[0],e.solution),r=e.evaluateExpression(n[1],e.solution);return k.BuiltInFunctions.dateTimeSubtract(t,r)});M.functionHandlers.set("mstominutes",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToMinutes(t)});M.functionHandlers.set("mstohours",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToHours(t)});M.functionHandlers.set("mstoseconds",(n,e)=>{let t=Number(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.msToSeconds(t)});M.functionHandlers.set("md5",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.md5(t)});M.functionHandlers.set("sha1",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha1(t)});M.functionHandlers.set("sha256",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha256(t)});M.functionHandlers.set("sha384",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha384(t)});M.functionHandlers.set("sha512",(n,e)=>{let t=e.getStringValue(e.evaluateExpression(n[0],e.solution));return k.BuiltInFunctions.sha512(t)});M.functionHandlers.set("subject",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.subject(t)});M.functionHandlers.set("predicate",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.predicate(t)});M.functionHandlers.set("object",(n,e)=>{let t=e.getTermFromExpression(n[0],e.solution);return k.BuiltInFunctions.object(t)});M.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 k.BuiltInFunctions.triple(t,r,i)});M.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))});M.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))});M.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)});M.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))});M.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)});M.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"))});M.functionHandlers.set("exo:eval",()=>{let{ExoQLEvalDisabledError:n}=Uu();throw new n})});var _p=S(Vc=>{"use strict";Object.defineProperty(Vc,"__esModule",{value:!0});Vc.FilterExecutor=Vc.FilterExecutorError=void 0;var yt=yp(),wj=jA(),Ej=Ce(),Aa=Ve(),hr=class extends Error{static{o(this,"FilterExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="FilterExecutorError"}};Vc.FilterExecutorError=hr;var d1=class{static{o(this,"FilterExecutor")}constructor(){this.existsEvaluator=null,this.tripleStore=null,this.uuidCache=new Map}setExistsEvaluator(e){this.existsEvaluator=e}setTripleStore(e){this.tripleStore=e,this.uuidCache.clear()}async*execute(e,t){let r=this.expressionContainsExists(e.expression);for await(let i of t)try{let s;r?s=await this.evaluateExpressionAsync(e.expression,i):s=this.evaluateExpression(e.expression,i),s===!0&&(yield i)}catch{continue}}expressionContainsExists(e){if(!e||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}o(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":return r.value;case"NamedNode":return r.value;default:throw new hr(`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":return e.value;case"in":return this.evaluateIn(e,t);case"exists":throw new hr("EXISTS expressions require async evaluation. Use evaluateExpressionAsync instead.");default:throw new hr(`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 yt.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 hr("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 yt.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 yt.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return yt.BuiltInFunctions.logicalOr(r);throw new hr(`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 a=await this.evaluateExpressionAsync(s,t);if(yt.BuiltInFunctions.compare(r,a,"=")){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 hr("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 a=[];for(let l of s){let u=await this.evaluateExpressionAsync(l,t);a.push(this.wrapAsLiteralExpression(u))}let c={...r,args:a};return this.evaluateFunction(c,t)}wrapAsLiteralExpression(e){return e==null?{type:"literal",value:""}:e!==null&&typeof e=="object"&&"termType"in e?e:e instanceof Ej.IRI||e instanceof Aa.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 yt.BuiltInFunctions.compare(r,i,e.operator)}evaluateLogical(e,t){if(e.operator==="!"){let i=this.evaluateExpression(e.operands[0],t);return yt.BuiltInFunctions.logicalNot(i)}let r=e.operands.map(i=>this.evaluateExpression(i,t));if(e.operator==="&&")return yt.BuiltInFunctions.logicalAnd(r);if(e.operator==="||")return yt.BuiltInFunctions.logicalOr(r);throw new hr(`Unknown logical operator: ${String(e.operator)}`)}evaluateIn(e,t){let r=this.evaluateExpression(e.expression,t),i=e.list.some(s=>{let a=this.evaluateExpression(s,t);return yt.BuiltInFunctions.compare(r,a,"=")});return e.negated?!i:i}evaluateArithmetic(e,t){let r=this.evaluateExpression(e.left,t),i=this.evaluateExpression(e.right,t);if(e.operator==="-"&&this.isDateValue(r)&&this.isDateValue(i))return yt.BuiltInFunctions.dateDiff(r,i);if(e.operator==="-"&&this.isTimeValue(r)&&this.isTimeValue(i))return yt.BuiltInFunctions.timeDiff(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDateTimeValue(i))return yt.BuiltInFunctions.dateTimeDiff(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateAdd(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateSubtract(r,i);if(e.operator==="+"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateAddYearMonth(r,i);if(e.operator==="-"&&this.isDateValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateTimeAdd(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.dateTimeSubtract(r,i);if(e.operator==="+"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateTimeAddYearMonth(r,i);if(e.operator==="-"&&this.isDateTimeValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.dateTimeSubtractYearMonth(r,i);if(e.operator==="+"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.durationAdd(r,i);if(e.operator==="-"&&this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i))return yt.BuiltInFunctions.durationSubtract(r,i);if(e.operator==="*"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);return yt.BuiltInFunctions.durationMultiply(r,c)}if(e.operator==="*"&&!this.isDayTimeDurationValue(r)&&this.isDayTimeDurationValue(i)){let c=this.toNumericValue(r);return yt.BuiltInFunctions.durationMultiply(i,c)}if(e.operator==="/"&&this.isDayTimeDurationValue(r)&&!this.isDayTimeDurationValue(i)){let c=this.toNumericValue(i);if(c===0)throw new hr("Division by zero");return yt.BuiltInFunctions.durationDivide(r,c)}if(e.operator==="+"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.yearMonthDurationAdd(r,i);if(e.operator==="-"&&this.isYearMonthDurationValue(r)&&this.isYearMonthDurationValue(i))return yt.BuiltInFunctions.yearMonthDurationSubtract(r,i);let s=this.toNumericValue(r),a=this.toNumericValue(i);switch(e.operator){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":if(a===0)throw new hr("Division by zero");return s/a;default:throw new hr(`Unknown arithmetic operator: ${String(e.operator)}`)}}isDayTimeDurationValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#dayTimeDuration":!1}isYearMonthDurationValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#yearMonthDuration":!1}toNumericValue(e){if(typeof e=="number")return e;if(e instanceof Aa.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 hr(`Cannot convert to number: ${e}`)}isDateTimeValue(e){if(e instanceof Aa.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 Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#date":!1}isTimeValue(e){return e instanceof Aa.Literal?(e.datatype?.value||"")==="http://www.w3.org/2001/XMLSchema#time":!1}evaluateFunction(e,t){let r=e,i=this.extractFunctionName(r.function),s=this.evaluateSpecialFunction(i,r.args,t);if(s!==void 0)return s.value;let a=wj.functionHandlers.get(i);if(!a)throw new hr(`Unknown function: ${i}`);let c={evaluateExpression:o((l,u)=>this.evaluateExpression(l,u),"evaluateExpression"),getTermFromExpression:o((l,u)=>this.getTermFromExpression(l,u),"getTermFromExpression"),getStringValue:o(l=>this.getStringValue(l),"getStringValue"),solution:t,isYearMonthDurationValue:o(l=>this.isYearMonthDurationValue(l),"isYearMonthDurationValue"),isDayTimeDurationValue:o(l=>this.isDayTimeDurationValue(l),"isDayTimeDurationValue")};return a(r.args,c)}extractFunctionName(e){if(typeof e=="string")return e.toLowerCase();if(e&&typeof e=="object"&&"value"in e){let t=e.value;return((t.includes("#")?t.split("#").pop():t.split("/").pop())||t).toLowerCase()}throw new hr(`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 hr("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 Aa.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 hr("exo:byUUID requires exactly 1 argument (UUID string)");let r=this.evaluateExpression(e.args[0],t),i=this.getStringValue(r);if(!i)return;let s=i.toLowerCase();if(this.uuidCache.has(s))return this.uuidCache.get(s)??void 0;if(!this.tripleStore){this.uuidCache.set(s,null);return}if(this.tripleStore.findSubjectsByUUIDSync){let a=this.tripleStore.findSubjectsByUUIDSync(s);if(a.length===0){this.uuidCache.set(s,null);return}let c=a[0];return this.uuidCache.set(s,c),c}this.uuidCache.set(s,null)}cacheUUIDResult(e,t){let r=e.toLowerCase();this.uuidCache.set(r,t)}getCachedUUID(e){let t=e.toLowerCase();if(this.uuidCache.has(t))return this.uuidCache.get(t)}};Vc.FilterExecutor=d1});var p1=S(Sp=>{"use strict";Object.defineProperty(Sp,"__esModule",{value:!0});Sp.OptionalExecutor=void 0;var h1=class{static{o(this,"OptionalExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);yield*this.hashJoin(r,i)}async executeAll(e,t){let r=[];for(let i of this.hashJoin(e,t))r.push(i);return r}*hashJoin(e,t){if(e.length===0)return;if(t.length===0){yield*e;return}let r=new Set;for(let l of e)for(let u of l.variables())r.add(u);let i=new Set;for(let l of t)for(let u of l.variables())i.add(u);let s=[];for(let l of r)i.has(l)&&s.push(l);if(s.sort(),s.length===0){yield*this.nestedLoopJoin(e,t);return}let a="\0",c=new Map;for(let l of t){let u=this.computeHashKey(l,s,a),f=c.get(u);f||(f=[],c.set(u,f)),f.push(l)}for(let l of e){let u=this.computeHashKey(l,s,a),f=c.get(u),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 a=e.get(s);i.push(a!==void 0?a.toString():"UNBOUND")}return i.join(r)}*nestedLoopJoin(e,t){for(let r of e){let i=!1;for(let s of t){let a=r.merge(s);a!==null&&(yield a,i=!0)}i||(yield r)}}};Sp.OptionalExecutor=h1});var g1=S(bp=>{"use strict";Object.defineProperty(bp,"__esModule",{value:!0});bp.UnionExecutor=void 0;var m1=class{static{o(this,"UnionExecutor")}async*execute(e,t){let r=new Set;for await(let i of e){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}for await(let i of t){let s=this.getSolutionKey(i);r.has(s)||(r.add(s),yield i)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}};bp.UnionExecutor=m1});var $A=S(vp=>{"use strict";Object.defineProperty(vp,"__esModule",{value:!0});vp.MinusExecutor=void 0;var y1=class{static{o(this,"MinusExecutor")}async*execute(e,t){let r=[];for await(let s of e)r.push(s);let i=[];for await(let s of t)i.push(s);for(let s of r){let a=!1;for(let c of i)if(this.areCompatible(s,c)){a=!0;break}a||(yield s)}}async executeAll(e,t){let r=[];async function*i(){for(let a of e)yield a}o(i,"generateLeft");async function*s(){for(let a of t)yield a}o(s,"generateRight");for await(let a of this.execute(i(),s()))r.push(a);return r}areCompatible(e,t){let r=e.variables(),i=new Set(t.variables()),s=r.filter(a=>i.has(a));if(s.length===0)return!1;for(let a of s){let c=e.get(a),l=t.get(a);if(c===void 0||l===void 0||c.toString()!==l.toString())return!1}return!0}};vp.MinusExecutor=y1});var VA=S(Uc=>{"use strict";Object.defineProperty(Uc,"__esModule",{value:!0});Uc.ValuesExecutor=Uc.ValuesExecutorError=void 0;var Tj=rs(),BA=Ce(),Aj=Ve(),wp=class extends Error{static{o(this,"ValuesExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ValuesExecutorError"}};Uc.ValuesExecutorError=wp;var _1=class{static{o(this,"ValuesExecutor")}async*execute(e){if(e.bindings.length!==0)for(let t of e.bindings)yield this.createSolutionMapping(t)}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}createSolutionMapping(e){let t=new Tj.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 BA.IRI(e.value);if(e.type==="literal")return new Aj.Literal(e.value,e.datatype?new BA.IRI(e.datatype):void 0,e.language,e.direction);throw new wp(`Unknown term type: ${e.type}`)}};Uc.ValuesExecutor=_1});var S1=S(Wc=>{"use strict";Object.defineProperty(Wc,"__esModule",{value:!0});Wc.CustomAggregateRegistry=Wc.CustomAggregateError=void 0;var qc=class extends Error{static{o(this,"CustomAggregateError")}constructor(e,t){super(e),this.iri=t,this.name="CustomAggregateError"}};Wc.CustomAggregateError=qc;var Ep=class n{static{o(this,"CustomAggregateRegistry")}constructor(){this.aggregates=new Map}static getInstance(){return n.instance||(n.instance=new n),n.instance}static resetInstance(){n.instance&&n.instance.clear(),n.instance=null}register(e,t){if(!e||typeof e!="string")throw new qc("Aggregate IRI must be a non-empty string");if(!t||typeof t.init!="function"||typeof t.step!="function"||typeof t.finalize!="function")throw new qc("Aggregate must implement init(), step(), and finalize() methods",e);if(this.aggregates.has(e))throw new qc(`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}};Wc.CustomAggregateRegistry=Ep;Ep.instance=null});var b1=S(Je=>{"use strict";Object.defineProperty(Je,"__esModule",{value:!0});Je.BUILT_IN_AGGREGATES=Je.modeAggregate=Je.stddevAggregate=Je.varianceAggregate=Je.medianAggregate=Je.EXO_AGGREGATE_NS=void 0;Je.getNumericValue=Tp;Je.createDecimalLiteral=ci;Je.createDoubleLiteral=Ij;Je.createPercentileAggregate=vo;var wo=Ve(),Gc=Ce(),xj=new Gc.IRI("http://www.w3.org/2001/XMLSchema#decimal"),Cj=new Gc.IRI("http://www.w3.org/2001/XMLSchema#double");Je.EXO_AGGREGATE_NS="https://exocortex.my/ontology/agg#";function Tp(n){return n==null?NaN:typeof n=="number"?n:typeof n=="string"?parseFloat(n):n instanceof wo.Literal?parseFloat(n.value):n instanceof Gc.IRI?NaN:typeof n=="boolean"?n?1:0:NaN}o(Tp,"getNumericValue");function ci(n){return new wo.Literal(String(n),xj)}o(ci,"createDecimalLiteral");function Ij(n){return new wo.Literal(String(n),Cj)}o(Ij,"createDoubleLiteral");Je.medianAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Tp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=[...t].sort((a,c)=>a-c),i=Math.floor(r.length/2),s=r.length%2!==0?r[i]:(r[i-1]+r[i])/2;return ci(s)}};Je.varianceAggregate={init(){return{values:[]}},step(n,e){let t=n,r=Tp(e);isNaN(r)||t.values.push(r)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ci(i)}};Je.stddevAggregate={init(){return{values:[]}},step(n,e){Je.varianceAggregate.step(n,e)},finalize(n){let e=n,{values:t}=e;if(t.length===0)return ci(0);let r=t.reduce((s,a)=>s+a,0)/t.length,i=t.reduce((s,a)=>s+Math.pow(a-r,2),0)/t.length;return ci(Math.sqrt(i))}};Je.modeAggregate={init(){return{counts:new Map,values:new Map}},step(n,e){if(e==null)return;let t=n,r=String(e instanceof wo.Literal||e instanceof Gc.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 wo.Literal(" ",new Gc.IRI("http://www.w3.org/2001/XMLSchema#string"));let t="",r=0;for(let[a,c]of e.counts)c>r&&(r=c,t=a);let i=e.values.get(t);if(i instanceof wo.Literal)return i;let s=parseFloat(t);return isNaN(s)?new wo.Literal(t,new Gc.IRI("http://www.w3.org/2001/XMLSchema#string")):ci(s)}};function vo(n){let e=Math.max(0,Math.min(100,n))/100;return{init(){return{values:[],percentile:e}},step(t,r){let i=t,s=Tp(r);isNaN(s)||i.values.push(s)},finalize(t){let r=t,{values:i}=r;if(i.length===0)return ci(0);let s=[...i].sort((d,h)=>d-h),a=r.percentile*(s.length-1),c=Math.floor(a),l=Math.ceil(a);if(c===l)return ci(s[c]);let u=a-c,f=s[c]*(1-u)+s[l]*u;return ci(f)}}}o(vo,"createPercentileAggregate");Je.BUILT_IN_AGGREGATES={[`${Je.EXO_AGGREGATE_NS}median`]:Je.medianAggregate,[`${Je.EXO_AGGREGATE_NS}variance`]:Je.varianceAggregate,[`${Je.EXO_AGGREGATE_NS}stddev`]:Je.stddevAggregate,[`${Je.EXO_AGGREGATE_NS}mode`]:Je.modeAggregate,[`${Je.EXO_AGGREGATE_NS}percentile25`]:vo(25),[`${Je.EXO_AGGREGATE_NS}percentile50`]:vo(50),[`${Je.EXO_AGGREGATE_NS}percentile75`]:vo(75),[`${Je.EXO_AGGREGATE_NS}percentile90`]:vo(90),[`${Je.EXO_AGGREGATE_NS}percentile95`]:vo(95),[`${Je.EXO_AGGREGATE_NS}percentile99`]:vo(99)}});var WA=S(zc=>{"use strict";Object.defineProperty(zc,"__esModule",{value:!0});zc.AggregateExecutor=zc.AggregateExecutorError=void 0;var ar=Ve(),w1=Ce(),Rj=_p(),Oj=S1(),Pj=b1(),UA=new w1.IRI("http://www.w3.org/2001/XMLSchema#integer"),Eo=new w1.IRI("http://www.w3.org/2001/XMLSchema#decimal"),is=new w1.IRI("http://www.w3.org/2001/XMLSchema#string");function qA(n){return typeof n=="object"&&n.type==="custom"}o(qA,"isCustomAggregation");var qu=class extends Error{static{o(this,"AggregateExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="AggregateExecutorError"}};zc.AggregateExecutorError=qu;var v1=class{static{o(this,"AggregateExecutor")}constructor(){this.filterExecutor=new Rj.FilterExecutor}execute(e,t){let r=this.groupSolutions(t,e.variables),i=[];for(let[s,a]of r.entries()){let c=new Map;for(let f of e.variables)if(a.length>0){let d=a[0].get(f);d&&c.set(f,d)}for(let f of e.aggregates){let d=this.computeAggregate(f.expression,a);c.set(f.variable,d)}let{SolutionMapping:l}=rs(),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),a=r.get(s);a?a.push(i):r.set(s,[i])}return r}computeGroupKey(e,t){return t.map(r=>{let i=e.get(r);return i?this.termToString(i):""}).join("|")}termToString(e){if(e&&typeof e=="object"){if("value"in e)return String(e.value);if("id"in e)return String(e.id)}return String(e)}computeAggregate(e,t){if(qA(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 ar.Literal(String(s),UA)}case"sum":{let s=this.computeSum(r);return new ar.Literal(String(s),Eo)}case"avg":{let s=this.computeAvg(r);return new ar.Literal(String(s),Eo)}case"min":{let s=this.computeMin(r);return s===void 0?new ar.Literal("",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}case"max":{let s=this.computeMax(r);return s===void 0?new ar.Literal("",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}case"group_concat":{let s=this.computeGroupConcat(r,e.separator||" ",e.distinct);return new ar.Literal(s||" ",is)}case"sample":{let s=this.computeSample(r,e.distinct);return s===void 0?new ar.Literal(" ",is):typeof s=="number"?new ar.Literal(String(s),Eo):new ar.Literal(String(s),is)}default:{let s=i;throw new qu(`Unknown aggregation function: ${s}`)}}}computeCustomAggregate(e,t){let i=e.aggregation.iri,a=Oj.CustomAggregateRegistry.getInstance().get(i);if(a||(a=Pj.BUILT_IN_AGGREGATES[i]),!a)throw new qu(`Unknown custom aggregate function: ${i}. Register it with CustomAggregateRegistry.getInstance().register() or use a built-in aggregate.`);let c=a.init();for(let l of t){let u=null;if(e.expression){let f=this.evaluateExpression(e.expression,l);f!==void 0&&(u=f)}else u=1;a.step(c,u)}return a.finalize(c)}extractValues(e,t){if(!e.expression)return t.map(()=>1);let r=[];for(let i of t){let s=this.evaluateExpression(e.expression,i);s!=null&&r.push(s)}return r}evaluateExpression(e,t){if(e.type==="variable"){let r=t.get(e.name);return r==null?void 0:typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:typeof r=="object"&&"value"in r?r.value:r}if(e.type==="literal")return e.value;try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}computeCount(e,t){return t?new Set(e.map(r=>String(r))).size:e.length}computeSum(e){return e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r)).reduce((r,i)=>r+i,0)}computeAvg(e){let t=e.map(r=>parseFloat(String(r))).filter(r=>!isNaN(r));return t.length===0?0:t.reduce((r,i)=>r+i,0)/t.length}computeMin(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.min(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s<i?s:i,r[0])}computeMax(e){if(e.length===0)return;let t=e.map(i=>parseFloat(String(i))).filter(i=>!isNaN(i));if(t.length>0)return Math.max(...t);let r=e.map(i=>String(i));return r.reduce((i,s)=>s>i?s:i,r[0])}computeGroupConcat(e,t,r){let i=e.map(s=>String(s));return r&&(i=[...new Set(i)]),i.join(t)}computeSample(e,t){if(e.length===0)return;if(t){let s=[...new Set(e.map(l=>String(l)))];if(s.length===0)return;let a=s[0],c=parseFloat(a);return isNaN(c)?a:c}let r=e[0];if(typeof r=="number")return r;let i=parseFloat(String(r));return isNaN(i)?String(r):i}createEmptyAggregateResult(e){let{SolutionMapping:t}=rs(),r=new t;for(let i of e.aggregates){let s=i.expression.aggregation;if(qA(s)){r.set(i.variable,new ar.Literal("0",Eo));continue}switch(s){case"count":r.set(i.variable,new ar.Literal("0",UA));break;case"sum":case"avg":r.set(i.variable,new ar.Literal("0",Eo));break;case"group_concat":r.set(i.variable,new ar.Literal(" ",is));break;case"min":case"max":case"sample":r.set(i.variable,new ar.Literal("",is));break;default:r.set(i.variable,new ar.Literal("",is))}}return r}};zc.AggregateExecutor=v1});var x1=S(Ap=>{"use strict";Object.defineProperty(Ap,"__esModule",{value:!0});Ap.ConstructExecutor=void 0;var Fj=ii(),To=Ce(),E1=Ve(),T1=Gt(),Dj=bu(),A1=class{static{o(this,"ConstructExecutor")}async execute(e,t){let r=[],i=new Set;for(let s of t)for(let a of e)try{let c=this.instantiateTriple(a,s),l=`${c.subject.toString()}|${c.predicate.toString()}|${c.object.toString()}`;i.has(l)||(i.add(l),r.push(c))}catch{continue}return r}instantiateTriple(e,t){if(this.isPropertyPath(e.predicate))throw new Error("Property paths are not supported in CONSTRUCT templates");let r=this.instantiateElement(e.subject,t),i=this.instantiateElement(e.predicate,t),s=this.instantiateElement(e.object,t);return new Fj.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 To.IRI(e.value);if(e.type==="literal")return new E1.Literal(e.value,e.datatype?new To.IRI(e.datatype):void 0,e.language);if(e.type==="blank")return new T1.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 Dj.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 E1.Literal)throw new Error("Literals cannot appear in quoted triple subject position");return r}if(e.type==="iri")return new To.IRI(e.value);if(e.type==="blank")return new T1.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 To.IRI))throw new Error("Quoted triple predicate must be an IRI");return r}return new To.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 To.IRI(e.value);if(e.type==="blank")return new T1.BlankNode(e.value);if(e.type==="literal")return new E1.Literal(e.value,e.datatype?new To.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}`)}};Ap.ConstructExecutor=A1});var zA=S(Hc=>{"use strict";Object.defineProperty(Hc,"__esModule",{value:!0});Hc.ServiceExecutor=Hc.ServiceExecutorError=void 0;var Nj=rs(),GA=Ce(),Lj=Ve(),kj=Gt(),Ao=class extends Error{static{o(this,"ServiceExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="ServiceExecutorError"}};Hc.ServiceExecutorError=Ao;var C1=class{static{o(this,"ServiceExecutor")}constructor(e={}){this.timeout=e.timeout??3e4,this.httpClient=e.httpClient??((t,r)=>fetch(t,r)),this.maxRetries=e.maxRetries??2,this.retryDelay=e.retryDelay??1e3}async*execute(e,t){try{let r=t(e.pattern),i=await this.executeRemoteQuery(e.endpoint,r);for(let s of i)yield s}catch(r){if(e.silent)return;throw r}}async executeRemoteQuery(e,t){let r;for(let i=0;i<=this.maxRetries;i++)try{let s=new AbortController,a=setTimeout(()=>s.abort(),this.timeout);try{let c=await this.httpClient(e,{method:"POST",headers:{"Content-Type":"application/sparql-query",Accept:"application/sparql-results+json"},body:t,signal:s.signal});if(!c.ok)throw new Ao(`Remote SPARQL endpoint returned ${c.status}: ${c.statusText}`);let l=await c.json();return this.parseJsonResults(l)}finally{clearTimeout(a)}}catch(s){if(r=s instanceof Error?s:new Error(String(s)),this.isRetryableError(r)&&i<this.maxRetries){await this.delay(this.retryDelay);continue}throw new Ao(`Failed to query remote SPARQL endpoint ${e}: ${r.message}`,r)}throw new Ao(`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 Nj.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 GA.IRI(e.value);case"literal":{let t=e.datatype?new GA.IRI(e.datatype):void 0;return new Lj.Literal(e.value,t,e["xml:lang"])}case"bnode":return new kj.BlankNode(e.value);default:throw new Ao(`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))}};Hc.ServiceExecutor=C1});var QA=S(Qc=>{"use strict";Object.defineProperty(Qc,"__esModule",{value:!0});Qc.GraphExecutor=Qc.GraphExecutorError=void 0;var HA=Ce(),xp=class extends Error{static{o(this,"GraphExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="GraphExecutorError"}};Qc.GraphExecutorError=xp;var I1=class{static{o(this,"GraphExecutor")}constructor(e){this.tripleStore=e}async*execute(e,t,r){let i=e.name;if(i.type==="iri")yield*this.executeWithGraph(e.pattern,i,t);else if(i.type==="variable")yield*this.executeWithGraphVariable(e,i,t,r);else throw new xp(`Invalid graph name type: ${i.type}`)}async*executeWithGraph(e,t,r){let i=new HA.IRI(t.value);this.tripleStore.hasGraph&&!await this.tripleStore.hasGraph(i)||(yield*r(e,i))}async*executeWithGraphVariable(e,t,r,i){if(i){let a=i.get(t.value);if(a&&a instanceof HA.IRI){yield*this.executeWithGraph(e.pattern,{type:"iri",value:a.value},r);return}}if(!this.tripleStore.getNamedGraphs)return;let s=await this.tripleStore.getNamedGraphs();for(let a of s)for await(let c of r(e.pattern,a)){let l=c.clone();l.set(t.value,a),yield l}}};Qc.GraphExecutor=I1});var YA=S(Kc=>{"use strict";Object.defineProperty(Kc,"__esModule",{value:!0});Kc.SPARQLGenerator=Kc.SPARQLGeneratorError=void 0;var Yc=class extends Error{static{o(this,"SPARQLGeneratorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="SPARQLGeneratorError"}};Kc.SPARQLGeneratorError=Yc;var R1=class{static{o(this,"SPARQLGenerator")}collectVariables(e){let t=new Set;return this.collectVariablesFromOperation(e,t),t}generateSelect(e){let t=this.collectVariables(e),r=t.size>0?Array.from(t).map(s=>`?${s}`).join(" "):"*",i=this.generateWhereClause(e);return`SELECT ${r} WHERE {
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)}
@@ -793,7 +793,7 @@ exo__BacklinksTableBlock_columns:${f==="[]"?" []":f}
793
793
  --- END PREVIEW ---
794
794
  `)}o(nK,"printDryRunReport");function iK(n,e){let r=[`--- MIGRATION ${e.apply?"APPLY":"DRY RUN"} ---`,`Migrated pairs: ${n.pairs.length}`,`Skipped configs: ${n.skipped.length}`];e.apply&&(r.push(`Files written to: ${e.outDir}/ (relative to vault root)`),r.push(`Total files written: ${n.pairs.length*2} (${n.pairs.length} Layout + ${n.pairs.length} Block)`));for(let i of n.skipped)r.push(` SKIPPED: ${i.sourcePath} \u2014 ${i.reason}`);return r.push(`--- END SUMMARY ---
795
795
  `),r.join(`
796
- `)}o(iK,"formatSummary");function sK(n,e){return{mode:e.apply?"apply":"dry-run",outDir:e.outDir,pairsCount:n.pairs.length,skippedCount:n.skipped.length,pairs:n.pairs.map(t=>({sourceUid:t.sourceUid,sourcePath:t.sourcePath,layoutUid:t.layout.uid,blockUid:t.block.uid,warnings:t.warnings})),skipped:n.skipped}}o(sK,"summariseResult");function AD(n){n.addCommand(sP()),n.addCommand(lP()),n.addCommand(uP())}o(AD,"addQuerySubcommands");function xD(n){let e=new xe;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.143.0");let t=e.command("exoql").description("ExoQL query execution and cache management");AD(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return AD(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(_F()),e.addCommand(vF()),e.addCommand(wF()),e.addCommand(TF()),e.addCommand(AF()),e.addCommand(OF()),e.addCommand(NF()),e.addCommand(HF()),e.addCommand(KF()),e.addCommand(tD()),e.addCommand(iD()),e.addCommand(sD()),e.addCommand(oD()),e.addCommand(hD()),e.addCommand(yD()),e.addCommand(TD()),e}o(xD,"createProgram");xD().parse();0&&(module.exports={createProgram});
796
+ `)}o(iK,"formatSummary");function sK(n,e){return{mode:e.apply?"apply":"dry-run",outDir:e.outDir,pairsCount:n.pairs.length,skippedCount:n.skipped.length,pairs:n.pairs.map(t=>({sourceUid:t.sourceUid,sourcePath:t.sourcePath,layoutUid:t.layout.uid,blockUid:t.block.uid,warnings:t.warnings})),skipped:n.skipped}}o(sK,"summariseResult");function AD(n){n.addCommand(sP()),n.addCommand(lP()),n.addCommand(uP())}o(AD,"addQuerySubcommands");function xD(n){let e=new xe;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.144.1");let t=e.command("exoql").description("ExoQL query execution and cache management");AD(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return AD(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(_F()),e.addCommand(vF()),e.addCommand(wF()),e.addCommand(TF()),e.addCommand(AF()),e.addCommand(OF()),e.addCommand(NF()),e.addCommand(HF()),e.addCommand(KF()),e.addCommand(tD()),e.addCommand(iD()),e.addCommand(sD()),e.addCommand(oD()),e.addCommand(hD()),e.addCommand(yD()),e.addCommand(TD()),e}o(xD,"createProgram");xD().parse();0&&(module.exports={createProgram});
797
797
  /*! Bundled license information:
798
798
 
799
799
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "15.143.0",
3
+ "version": "15.144.1",
4
4
  "description": "CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more",
5
5
  "main": "dist/index.js",
6
6
  "bin": {