@kanonak-protocol/sdk 5.33.0 → 5.34.0

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.
@@ -1 +0,0 @@
1
- import{a as X}from"./chunk-HF5FJBS2.js";import{a as J,aa as Z,b as Y,ba as _,ca as E,ia as ee}from"./chunk-7UYXTYXC.js";import{a as q,b as H,c as w,d as g,g as R,h as T,i as N,j as O,k as K,l as P,m as A,n as x,t as Q}from"./chunk-CJMVIOZX.js";import{a as I}from"./chunk-FUUTGGJS.js";import{b as G}from"./chunk-F67UH4FD.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends H{name};var j=class extends q{value;carrier;lexical};var L=class extends R{links=[]};var oe="kanonak.org",se="transformations",Re=3,e=m=>({publisher:oe,package_:se,name:m}),M={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),NumberFormat:e("NumberFormat"),numberSource:e("numberSource"),numberStyle:e("numberStyle"),fractionDigits:e("fractionDigits"),currencyCode:e("currencyCode"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as S,carrierOf as ie}from"@kanonak-protocol/canonical";function V(m){return ie(`${m.publisher}/${m.package_}/${m.name}`)}var ce=/\[\[([^\[\]\n]+)\]\]/g,pe=/\[\[/g,te=/```[\s\S]*?```|`[^`\n]*`/g;function me(m){let t=[];for(let n of m.matchAll(te))t.push([n.index,n.index+n[0].length]);return t}function De(m){if(!m||!m.includes("[["))return[];let t=me(m),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(B(m).map(s=>s.startOffset)),a=[];for(let s of m.matchAll(pe)){let o=s.index;if(n(o)||r.has(o))continue;let c=m.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function B(m){if(!m||!m.includes("[["))return[];let t=[];for(let a of m.matchAll(te))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of m.matchAll(ce)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),p=(c===-1?o:o.slice(0,c)).trim();if(p.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:p,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}import{VersionOperator as fe}from"@kanonak-protocol/types/document/models/enums";function re(m,t){for(let n of m)n instanceof w&&U(n,n.name,t)}function U(m,t,n){n({kanonak:m,path:t});for(let r of m.statement){let a=r.predicate?.subject?.name;if(r instanceof K)U(r.object,ne(t,a,r.object),n);else if(r instanceof P)for(let s=0;s<r.object.length;s++){let o=r.object[s];o instanceof b&&U(o,ne(t,a,o,s),n)}}}function ne(m,t,n,r){let a=`${m}.${t??"<embedded>"}`,s=n instanceof b?n.name:void 0;return s?`${a}.${s}`:r===void 0?a:`${a}[${r}]`}var ue={..._("range"),name:"range"};function de(m){let t=m.lastIndexOf(".");return t===-1?m:m.slice(t+1)}var ae=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new J(t),s=new Y(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let p of n){let i=p.metadata.namespace_?.toString();i&&a.set(i,p)}let s=[],o=new Set;re(t,({kanonak:p})=>{for(let i of p.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let p of s){let i=a.get(p.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(p.key,i);if(!u)continue;let d=A(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=ee(t,f);l&&(this.knownPropertyClasses.set(d,l),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[p,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(p,o,c);u.namespace=d.namespace,u.name=d.name,u.statement=[];let f=await this.parseStatements(i,o,n,r,a);u.statement.push(...f.statements),u.unresolvedPredicates=f.unresolved,F(u,c),s.push(u)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof w){let u=`${i.namespace}/${i.name}`,d=r.get(u);if(d){let f=a.get(u);for(let l of i.statement){let y=$(l);f.has(y)||(f.add(y),d.statement.push(l))}for(let l of i.unresolvedPredicates)d.unresolvedPredicates.some(y=>y.key===l.key&&y.sourceDoc===l.sourceDoc)||d.unresolvedPredicates.push(l)}else{let f=new w;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let l=new Set;for(let y of i.statement){let k=$(y);l.has(k)||(l.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(u,l),r.set(u,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof w){let u=i.namespace||"",d=u.indexOf("/"),f=d>=0?u.slice(0,d):"",l=d>=0?u.slice(d+1):"",y=l.indexOf("@"),k=y>=0?l.slice(0,y):l;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),p=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);p.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,p);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(E(s,n,r),a instanceof O)a.object instanceof g&&E(a.object.subject,n,r);else if(a instanceof K)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof P)for(let o of a.object??[])o instanceof g?E(o.subject,n,r):o instanceof b&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,p]of Object.entries(n.metadata.imports))for(let i of p)if((i.alias??i.packageName)===s){let d=i.version;return{namespace:`${c}/${i.packageName}@${d.major}.${d.minor}.${d.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let p=n.metadata.namespace_?.toString()??"";for(let[i,u]of Object.entries(t))try{let d=await this.getPropertyMetadata(i,n,r,s,a);if(!d){let l=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;Z(l)||c.push({key:i,sourceDoc:p});continue}let f=await this.parsePropertyValue(i,u,d,n,r,a,s);f&&o.push(f)}catch(d){throw new Error(`Failed to parse property '${i}': ${d.message}`,{cause:d})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,p=c.type?.toString()??"",i=p.includes(".")?p.substring(p.lastIndexOf(".")+1):p,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(A(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(p),l,y=async()=>{if(l)return l;if(!(o.isImported&&o.definedInNamespace))return l=n,n;if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let v=await a.getDocumentAsync(o.definedInNamespace);if(!v)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);return l=v,v},k=await this.readDefinitionSlot(c,ue,y,r),h=k==null?void 0:String(k),D;if(f==="ObjectProperty")D="ObjectProperty";else if(f==="DatatypeProperty")D="DatatypeProperty";else{let v=h&&h.includes(".")?h.substring(h.lastIndexOf(".")+1):h??"";(h?s.isKnownXsdDatatypeName(h):!1)||v==="Literal"?D="DatatypeProperty":D="ObjectProperty"}let z;return h&&(z=(await r.resolveEntityAsync(h,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:D,range:h,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>de(i)===n.name);if(s.length===0)return;let o=await r(),c=_(n.name),p=c!==void 0&&c.publisher===n.publisher&&c.package_===n.package_;for(let i of s){let u=await a.resolveEntityAsync(i,o);if(u){if(x(u.uri,n))return t[i];continue}if(!i.includes(".")&&p)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let p=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(p,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(p,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(p,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?V(r.rangeUri):void 0;if(s===S.Boolean){let c=new N;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===S.Integer||s===S.Decimal||s===S.Double||s===S.Float){let c=new T;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=R.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new j,a=n.rangeUri?V(n.rangeUri):void 0;return a===S.Boolean?r.value=t==="true"||t==="1":a===S.Integer||a===S.Decimal||a===S.Double||a===S.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new L;s.predicate=g.parse(t),s.object=n;for(let o of B(n)){let c=this.linkReference(o.reference,r);if(!c){let i=await a.resolveEntityAsync(o.reference,r);i&&(c=new g,c.subject=i.uri)}let p={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(p.displayText=o.displayText),c!==void 0&&(p.target=c),s.links.push(p)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&x(r.rangeUri,M.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let p=await this.resolveReference(n,a,s);if(!p)return;let i=new O;return i.predicate=g.parse(t),i.object=p,i}if(typeof n=="object"&&!Array.isArray(n)){let p=await this.parseStatements(n,a,s,o,c);if(p.statements.length>0){let d=new b;d.statement=p.statements,d.unresolvedPredicates=p.unresolved;let f=new K;return f.predicate=g.parse(t),f.object=d,f}let i=[];for(let[d,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let l=new b;l.name=d;let y=await this.parseStatements(f,a,s,o,c);l.statement=y.statements,l.unresolvedPredicates=y.unresolved,i.push(l)}else if(typeof f=="string"){let l=await this.resolveReference(f,a,s);l&&i.push(l)}if(i.length>0){let d=new P;return d.predicate=g.parse(t),d.object=i,d}let u=new K;return u.predicate=g.parse(t),u.object=new b,u}}coerceExpressionLiteral(t,n,r){let a=new b,s=new O,o=new g;o.subject=new I("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new I(r.publisher,r.package_,M.StringLiteral.name,r.version),s.object=c;let p=new R,i=new g;i.subject=new I(r.publisher,r.package_,M.stringLiteral.name,r.version),p.predicate=i,p.object=n,a.statement=[s,p];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let p=[],i=r.propertyType==="DatatypeProperty",u=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let f of n){let l=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&l){let y=typeof f=="string"?f:String(f);p.push(this.typedListLiteral(y,r));continue}if(u&&l){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,p.push(k)}else{let k=new j;k.value=f,p.push(k)}}else{let y=new j;y.value=f,p.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&p.push(y)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let y=new b,k=await this.parseStatements(f,a,s,o,c);y.statement=k.statements,y.unresolvedPredicates=k.unresolved,p.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=p,d}linkReference(t,n){let r=t.indexOf(".");if(r<=0||!n.metadata?.imports)return;let a=t.substring(0,r),s=t.substring(r+1);for(let[o,c]of Object.entries(n.metadata.imports))for(let p of c){if(!G(p)||(p.alias??p.packageName)!==a)continue;let i=new g,u=p.versionOperator===fe.Exact?p.version:void 0;return i.subject=new I(o,p.packageName,s,u),i}}async resolveReference(t,n,r){let a=this.linkReference(t,n);if(a)return a;let s=await r.resolveEntityAsync(t,n);if(s){let c=new g;return c.subject=s.uri,c}let o=n.metadata?.namespace_;if(o){let{KanonakUri:c}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let i=t.indexOf("."),u=t.substring(0,i),d=t.substring(i+1);if(n.metadata?.imports){for(let[f,l]of Object.entries(n.metadata.imports))for(let y of l)if((y.alias??y.packageName)===u){let h=new g;return h.subject=new c(f,y.packageName,d,y.version),h}}}let p=new g;return p.subject=new c(o.publisher,o.package_,t,o.version??void 0),p}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof w&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof w&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new X().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let p of o.statement){let[i,u]=this.convertStatementToProperty(p);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(p,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof R)return[t.predicate.subject.name,t.object];if(t instanceof T)return[t.predicate.subject.name,t.object];if(t instanceof N)return[t.predicate.subject.name,t.object];if(t instanceof O)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof P){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof K){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof b&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function F(m,t){m.sourceDoc=t;for(let n of m.statement)if(n instanceof K)F(n.object,t);else if(n instanceof P)for(let r of n.object)r instanceof b&&F(r,t)}function $(m){let t=m.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+le(m)}function le(m){return m instanceof L?"m:"+String(m.object):m instanceof R?"s:"+String(m.object):m instanceof T?"n:"+String(m.object):m instanceof N?"b:"+String(m.object):m instanceof O?"r:"+C(m.object):m instanceof K?"e:"+C(m.object):m instanceof P?"l:["+(m.object??[]).map(C).join("|")+"]":"x"}function C(m){if(!m)return"";if(m instanceof g){let t=m.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return m instanceof b?"E("+(m.statement??[]).map($).join(";")+")":m instanceof j?"L("+String(m.value)+")":"N"}export{b as a,j as b,L as c,re as d,oe as e,se as f,Re as g,M as h,S as i,V as j,De as k,B as l,ae as m};