@kanonak-protocol/sdk 5.27.0 → 5.29.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.
- package/dist/browser.js +1 -1
- package/dist/chunk-3DWEBQSD.js +68 -0
- package/dist/{chunk-4VLLX3MZ.js → chunk-4SMQ7G23.js} +1 -1
- package/dist/chunk-ANJAHB4N.js +155 -0
- package/dist/chunk-CJMVIOZX.js +1 -0
- package/dist/{chunk-M7LXZN47.js → chunk-F3SGXIDP.js} +1 -1
- package/dist/chunk-G3GKOJ5E.js +1 -0
- package/dist/{chunk-RWN5JZPU.js → chunk-GMK4YL3X.js} +1 -1
- package/dist/{chunk-KOV3AFBN.js → chunk-HBG6SC5L.js} +1 -1
- package/dist/chunk-ZRCJGTEV.js +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/introspection/OntologyModel.d.ts +11 -0
- package/dist/introspection/index.d.ts +1 -1
- package/dist/look/LookRenderer.d.ts +37 -0
- package/dist/look/displayValue.d.ts +3 -5
- package/dist/look/index.d.ts +1 -0
- package/dist/look/sequenceWalk.d.ts +94 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/resolution/TypeResolver.d.ts +11 -0
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/transformations/index.js +1 -1
- package/dist/uri-helpers/UriHelpers.d.ts +21 -0
- package/dist/uri-helpers/index.d.ts +1 -1
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/SequenceNarrativeRule.d.ts +44 -0
- package/dist/validation/rules/repository/TxExpressionCompilesRule.d.ts +18 -0
- package/dist/validation/rules/repository/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-4C7ZMXQT.js +0 -68
- package/dist/chunk-CZY6OOTM.js +0 -1
- package/dist/chunk-NOPFCGB7.js +0 -1
- package/dist/chunk-RVR25FWW.js +0 -2
- package/dist/chunk-ZZINR6NT.js +0 -152
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as G}from"./chunk-KOWDHKBN.js";import{a as H,aa as Y,b as J,ba as N,ca as A,ia as Z}from"./chunk-NOPFCGB7.js";import{a as X,b as q,c as w,d as g,g as R,h as T,i as M,j as D,k as K,l as P,m as x,n as _,s as Q}from"./chunk-CZY6OOTM.js";import{a as L}from"./chunk-FUUTGGJS.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends q{name};var j=class extends X{value;carrier;lexical};var I=class extends R{links=[]};var ae="kanonak.org",oe="transformations",Ke=3,e=p=>({publisher:ae,package_:oe,name:p}),E={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 h,carrierOf as se}from"@kanonak-protocol/canonical";function B(p){return se(`${p.publisher}/${p.package_}/${p.name}`)}var ie=/\[\[([^\[\]\n]+)\]\]/g,ce=/\[\[/g,ee=/```[\s\S]*?```|`[^`\n]*`/g;function pe(p){let t=[];for(let n of p.matchAll(ee))t.push([n.index,n.index+n[0].length]);return t}function ve(p){if(!p||!p.includes("[["))return[];let t=pe(p),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(V(p).map(s=>s.startOffset)),a=[];for(let s of p.matchAll(ce)){let o=s.index;if(n(o)||r.has(o))continue;let c=p.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function V(p){if(!p||!p.includes("[["))return[];let t=[];for(let a of p.matchAll(ee))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 p.matchAll(ie)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),m=(c===-1?o:o.slice(0,c)).trim();if(m.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:m,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}function ne(p,t){for(let n of p)n instanceof w&&U(n,n.name,t)}function U(p,t,n){n({kanonak:p,path:t});for(let r of p.statement){let a=r.predicate?.subject?.name;if(r instanceof K)U(r.object,te(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,te(t,a,o,s),n)}}}function te(p,t,n,r){let a=`${p}.${t??"<embedded>"}`,s=n instanceof b?n.name:void 0;return s?`${a}.${s}`:r===void 0?a:`${a}[${r}]`}var me={...N("range"),name:"range"};function fe(p){let t=p.lastIndexOf(".");return t===-1?p:p.slice(t+1)}var re=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new H(t),s=new J(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 m of n){let i=m.metadata.namespace_?.toString();i&&a.set(i,m)}let s=[],o=new Set;ne(t,({kanonak:m})=>{for(let i of m.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let m of s){let i=a.get(m.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(m.key,i);if(!u)continue;let d=x(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=Z(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[m,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(m,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}`),m=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);m.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,m);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(A(s,n,r),a instanceof D)a.object instanceof g&&A(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?A(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,m]of Object.entries(n.metadata.imports))for(let i of m)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 m=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;Y(l)||c.push({key:i,sourceDoc:m});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,m=c.type?.toString()??"",i=m.includes(".")?m.substring(m.lastIndexOf(".")+1):m,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(x(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(m),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,me,y,r),S=k==null?void 0:String(k),O;if(f==="ObjectProperty")O="ObjectProperty";else if(f==="DatatypeProperty")O="DatatypeProperty";else{let v=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S??"";(S?s.isKnownXsdDatatypeName(S):!1)||v==="Literal"?O="DatatypeProperty":O="ObjectProperty"}let z;return S&&(z=(await r.resolveEntityAsync(S,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:O,range:S,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>fe(i)===n.name);if(s.length===0)return;let o=await r(),c=N(n.name),m=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(_(u.uri,n))return t[i];continue}if(!i.includes(".")&&m)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let m=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(m,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(m,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(m,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?B(r.rangeUri):void 0;if(s===h.Boolean){let c=new M;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===h.Integer||s===h.Decimal||s===h.Double||s===h.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?B(n.rangeUri):void 0;return a===h.Boolean?r.value=t==="true"||t==="1":a===h.Integer||a===h.Decimal||a===h.Double||a===h.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 I;s.predicate=g.parse(t),s.object=n;for(let o of V(n)){let c=await a.resolveEntityAsync(o.reference,r),m;c&&(m=new g,m.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),m!==void 0&&(i.target=m),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&_(r.rangeUri,E.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let m=await this.resolveReference(n,a,s);if(!m)return;let i=new D;return i.predicate=g.parse(t),i.object=m,i}if(typeof n=="object"&&!Array.isArray(n)){let m=await this.parseStatements(n,a,s,o,c);if(m.statements.length>0){let d=new b;d.statement=m.statements,d.unresolvedPredicates=m.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 D,o=new g;o.subject=new L("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new L(r.publisher,r.package_,E.StringLiteral.name,r.version),s.object=c;let m=new R,i=new g;i.subject=new L(r.publisher,r.package_,E.stringLiteral.name,r.version),m.predicate=i,m.object=n,a.statement=[s,m];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let m=[],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);m.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,m.push(k)}else{let k=new j;k.value=f,m.push(k)}}else{let y=new j;y.value=f,m.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&m.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,m.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=m,d}async resolveReference(t,n,r){let a=await r.resolveEntityAsync(t,n);if(a){let o=new g;return o.subject=a.uri,o}let s=n.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let m=t.indexOf("."),i=t.substring(0,m),u=t.substring(m+1);if(n.metadata?.imports){for(let[d,f]of Object.entries(n.metadata.imports))for(let l of f)if((l.alias??l.packageName)===i){let k=new g;return k.subject=new o(d,l.packageName,u,l.version),k}}}let c=new g;return c.subject=new o(s.publisher,s.package_,t,s.version??void 0),c}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 G().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 m of o.statement){let[i,u]=this.convertStatementToProperty(m);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(m,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 M)return[t.predicate.subject.name,t.object];if(t instanceof D)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(p,t){p.sourceDoc=t;for(let n of p.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 $(p){let t=p.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ue(p)}function ue(p){return p instanceof I?"m:"+String(p.object):p instanceof R?"s:"+String(p.object):p instanceof T?"n:"+String(p.object):p instanceof M?"b:"+String(p.object):p instanceof D?"r:"+C(p.object):p instanceof K?"e:"+C(p.object):p instanceof P?"l:["+(p.object??[]).map(C).join("|")+"]":"x"}function C(p){if(!p)return"";if(p instanceof g){let t=p.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return p instanceof b?"E("+(p.statement??[]).map($).join(";")+")":p instanceof j?"L("+String(p.value)+")":"N"}export{b as a,j as b,I as c,ne as d,ae as e,oe as f,Ke as g,E as h,h as i,B as j,ve as k,V as l,re as m};
|
|
1
|
+
import{a as G}from"./chunk-KOWDHKBN.js";import{a as H,aa as Y,b as J,ba as N,ca as A,ia as Z}from"./chunk-G3GKOJ5E.js";import{a as X,b as q,c as w,d as g,g as R,h as T,i as M,j as D,k as K,l as P,m as x,n as _,t as Q}from"./chunk-CJMVIOZX.js";import{a as L}from"./chunk-FUUTGGJS.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends q{name};var j=class extends X{value;carrier;lexical};var I=class extends R{links=[]};var ae="kanonak.org",oe="transformations",Ke=3,e=p=>({publisher:ae,package_:oe,name:p}),E={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 h,carrierOf as se}from"@kanonak-protocol/canonical";function B(p){return se(`${p.publisher}/${p.package_}/${p.name}`)}var ie=/\[\[([^\[\]\n]+)\]\]/g,ce=/\[\[/g,ee=/```[\s\S]*?```|`[^`\n]*`/g;function pe(p){let t=[];for(let n of p.matchAll(ee))t.push([n.index,n.index+n[0].length]);return t}function ve(p){if(!p||!p.includes("[["))return[];let t=pe(p),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(V(p).map(s=>s.startOffset)),a=[];for(let s of p.matchAll(ce)){let o=s.index;if(n(o)||r.has(o))continue;let c=p.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function V(p){if(!p||!p.includes("[["))return[];let t=[];for(let a of p.matchAll(ee))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 p.matchAll(ie)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),m=(c===-1?o:o.slice(0,c)).trim();if(m.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:m,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}function ne(p,t){for(let n of p)n instanceof w&&U(n,n.name,t)}function U(p,t,n){n({kanonak:p,path:t});for(let r of p.statement){let a=r.predicate?.subject?.name;if(r instanceof K)U(r.object,te(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,te(t,a,o,s),n)}}}function te(p,t,n,r){let a=`${p}.${t??"<embedded>"}`,s=n instanceof b?n.name:void 0;return s?`${a}.${s}`:r===void 0?a:`${a}[${r}]`}var me={...N("range"),name:"range"};function fe(p){let t=p.lastIndexOf(".");return t===-1?p:p.slice(t+1)}var re=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new H(t),s=new J(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 m of n){let i=m.metadata.namespace_?.toString();i&&a.set(i,m)}let s=[],o=new Set;ne(t,({kanonak:m})=>{for(let i of m.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let m of s){let i=a.get(m.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(m.key,i);if(!u)continue;let d=x(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=Z(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[m,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(m,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}`),m=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);m.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,m);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(A(s,n,r),a instanceof D)a.object instanceof g&&A(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?A(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,m]of Object.entries(n.metadata.imports))for(let i of m)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 m=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;Y(l)||c.push({key:i,sourceDoc:m});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,m=c.type?.toString()??"",i=m.includes(".")?m.substring(m.lastIndexOf(".")+1):m,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(x(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(m),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,me,y,r),S=k==null?void 0:String(k),O;if(f==="ObjectProperty")O="ObjectProperty";else if(f==="DatatypeProperty")O="DatatypeProperty";else{let v=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S??"";(S?s.isKnownXsdDatatypeName(S):!1)||v==="Literal"?O="DatatypeProperty":O="ObjectProperty"}let z;return S&&(z=(await r.resolveEntityAsync(S,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:O,range:S,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>fe(i)===n.name);if(s.length===0)return;let o=await r(),c=N(n.name),m=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(_(u.uri,n))return t[i];continue}if(!i.includes(".")&&m)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let m=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(m,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(m,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(m,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?B(r.rangeUri):void 0;if(s===h.Boolean){let c=new M;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===h.Integer||s===h.Decimal||s===h.Double||s===h.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?B(n.rangeUri):void 0;return a===h.Boolean?r.value=t==="true"||t==="1":a===h.Integer||a===h.Decimal||a===h.Double||a===h.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 I;s.predicate=g.parse(t),s.object=n;for(let o of V(n)){let c=await a.resolveEntityAsync(o.reference,r),m;c&&(m=new g,m.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),m!==void 0&&(i.target=m),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&_(r.rangeUri,E.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let m=await this.resolveReference(n,a,s);if(!m)return;let i=new D;return i.predicate=g.parse(t),i.object=m,i}if(typeof n=="object"&&!Array.isArray(n)){let m=await this.parseStatements(n,a,s,o,c);if(m.statements.length>0){let d=new b;d.statement=m.statements,d.unresolvedPredicates=m.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 D,o=new g;o.subject=new L("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new L(r.publisher,r.package_,E.StringLiteral.name,r.version),s.object=c;let m=new R,i=new g;i.subject=new L(r.publisher,r.package_,E.stringLiteral.name,r.version),m.predicate=i,m.object=n,a.statement=[s,m];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let m=[],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);m.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,m.push(k)}else{let k=new j;k.value=f,m.push(k)}}else{let y=new j;y.value=f,m.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&m.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,m.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=m,d}async resolveReference(t,n,r){let a=await r.resolveEntityAsync(t,n);if(a){let o=new g;return o.subject=a.uri,o}let s=n.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let m=t.indexOf("."),i=t.substring(0,m),u=t.substring(m+1);if(n.metadata?.imports){for(let[d,f]of Object.entries(n.metadata.imports))for(let l of f)if((l.alias??l.packageName)===i){let k=new g;return k.subject=new o(d,l.packageName,u,l.version),k}}}let c=new g;return c.subject=new o(s.publisher,s.package_,t,s.version??void 0),c}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 G().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 m of o.statement){let[i,u]=this.convertStatementToProperty(m);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(m,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 M)return[t.predicate.subject.name,t.object];if(t instanceof D)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(p,t){p.sourceDoc=t;for(let n of p.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 $(p){let t=p.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ue(p)}function ue(p){return p instanceof I?"m:"+String(p.object):p instanceof R?"s:"+String(p.object):p instanceof T?"n:"+String(p.object):p instanceof M?"b:"+String(p.object):p instanceof D?"r:"+C(p.object):p instanceof K?"e:"+C(p.object):p instanceof P?"l:["+(p.object??[]).map(C).join("|")+"]":"x"}function C(p){if(!p)return"";if(p instanceof g){let t=p.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return p instanceof b?"E("+(p.statement??[]).map($).join(";")+")":p instanceof j?"L("+String(p.value)+")":"N"}export{b as a,j as b,I as c,ne as d,ae as e,oe as f,Ke as g,E as h,h as i,B as j,ve as k,V as l,re as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as q,c as B,d as G,m as S,n as X,t as Y,u as T,y as v,z as j}from"./chunk-CJMVIOZX.js";import{a as P}from"./chunk-FUUTGGJS.js";var W=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let r=t.metadata?.namespace_?.toString()??"unknown",o=this.cache.get(r);if(o){let i=o.get(e);if(i)return i}let a=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(r,a),a.get(e)??null}async resolveAllEntitiesAsync(e,t){let r=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let o=e.split("."),a=o[0],i=o[1],u=await this.findDocumentForAlias(t,a);return u?await this.resolveAllEntitiesAsync(i,u):[]}return r.filter(o=>o.entityName===e)}async buildAllEntitiesIndexAsync(e,t,r){let o=[],a=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${a}`),t.has(a))return this.logger?.debug?.(`Skipping ${a} - already visited (circular import prevention)`),o;t.add(a);let i=r.length===0?a:`${r} \u2192 ${a}`;for(let[u,c]of Object.entries(e.body))if(!u.includes(".")&&c&&typeof c=="object"&&!Array.isArray(c)){if(!e.metadata.namespace_)continue;let g=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};o.push({entityName:u,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,u,g),entity:c,definedInNamespace:a,isImported:r.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${o.length} entities from ${a}`),e.metadata?.imports){let u=Object.values(e.metadata.imports).reduce((c,g)=>c+g.length,0);this.logger?.debug?.(`Processing ${u} import(s) for ${a}`);for(let[c,g]of Object.entries(e.metadata.imports))for(let m of g)try{this.logger?.debug?.(`Resolving import: ${c}/${m.packageName}`);let d=await this.repository.getHighestCompatibleVersionAsync(c,m);if(d){this.logger?.debug?.(`Successfully loaded import: ${d.metadata?.namespace_?.toString()}`);let k=await this.buildAllEntitiesIndexAsync(d,t,i);o.push(...k),this.logger?.debug?.(`Added ${k.length} entities from import ${d.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${c}/${m.packageName}`)}catch(d){let k=d;throw this.logger?.error?.(`Failed to process import ${c}/${m.packageName} for namespace ${a}. Error: ${k.message}`,k),new Error(`Failed to process import ${c}/${m.packageName} for namespace ${a}. See inner exception for details.`,{cause:d})}}return o}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,r,o){let a=new Map,i=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${i}`),t.has(i))return this.logger?.debug?.(`Skipping ${i} - circular import in progress`),a;let u=o.get(i);if(u)return u;t.add(i);let c=r.length===0?i:`${r} \u2192 ${i}`,g=0;for(let[m,d]of Object.entries(e.body))if(!m.includes(".")&&d&&typeof d=="object"&&!Array.isArray(d)){if(!e.metadata.namespace_)continue;if(!a.has(m)){let k=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};a.set(m,{entityName:m,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,m,k),entity:d,definedInNamespace:i,isImported:r.length>0,importPath:c}),g++}}if(this.logger?.debug?.(`Indexed ${g} entities from ${i}`),e.metadata?.imports){let m=Object.values(e.metadata.imports).reduce((d,k)=>d+k.length,0);this.logger?.debug?.(`Processing ${m} import(s) for ${i}`);for(let[d,k]of Object.entries(e.metadata.imports))for(let K of k)try{this.logger?.debug?.(`Resolving import: ${d}/${K.packageName}`);let E=await this.repository.getHighestCompatibleVersionAsync(d,K);if(E){this.logger?.debug?.(`Successfully loaded import: ${E.metadata?.namespace_?.toString()}`);let U=await this.buildEntityIndexAsyncInternal(E,t,c,o),$=0;for(let[O,C]of U.entries()){let _=a.get(O);if(!_)a.set(O,C),$++;else if(_.isImported&&C.isImported&&(_.uri.publisher!==C.uri.publisher||_.uri.package_!==C.uri.package_)){let A=_.isAmbiguous?_:{..._,isAmbiguous:!0,ambiguousNamespaces:[_.definedInNamespace]};A.ambiguousNamespaces.includes(C.definedInNamespace)||A.ambiguousNamespaces.push(C.definedInNamespace),a.set(O,A),this.logger?.warn?.(`Ambiguous reference '${O}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(K.alias&&!O.includes(".")){let A=`${K.alias}.${O}`;a.has(A)||(a.set(A,C),$++)}}this.logger?.debug?.(`Merged ${$} entities from import ${E.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${d}/${K.packageName}`)}catch(E){let U=E;throw this.logger?.error?.(`Failed to process import ${d}/${K.packageName} for namespace ${i}. Error: ${U.message}`,U),new Error(`Failed to process import ${d}/${K.packageName} for namespace ${i}. See inner exception for details.`,{cause:E})}}return t.delete(i),o.set(i,a),a}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[r,o]of Object.entries(e.metadata.imports))for(let a of o){if(a.alias===t)return await this.repository.getHighestCompatibleVersionAsync(r,a);if(!a.alias&&a.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(r,a)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}};var z=class n{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&n.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return n.isSubstitutableDatatypeUri(e)}static isSubstitutableDatatypeUri(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return n.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let r=await this.resourceResolver.resolveEntityAsync(e,t);if(r){let o=r.entity.type;if(o){let a=String(o);return a==="Class"||a==="rdfs.Class"||a.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function J(n){if(!n||n.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let e=n.trim(),t=e.split("/");if(t.length===1){let r=t[0];if(!r)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(r.includes("@"))throw new Error(`Invalid Kanonak address: "${n}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:r}}if(t.length===2){let[r,o]=t;if(!r||!o)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let a=o.indexOf("@");if(a===-1)return{kind:"package",publisher:r,package_:o};let i=o.substring(0,a),u=o.substring(a+1);if(!i||!u)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let c=re(u);return{kind:"package",publisher:r,package_:i,version:c}}return{kind:"resource",uri:P.parse(e)}}function Oe(n){switch(n.kind){case"publisher":return n.publisher;case"package":return n.version?`${n.publisher}/${n.package_}@${n.version.major}.${n.version.minor}.${n.version.patch}`:`${n.publisher}/${n.package_}`;case"resource":return n.uri.toString()}}function re(n){let e=n.split(".").map(Number);return oe(e[0]||0,e[1]||0,e[2]||0)}function oe(n,e,t){return{major:n,minor:e,patch:t,toString:()=>`${n}.${e}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===n&&r.minor===e&&r.patch===t,getHashCode:()=>n<<20|e<<10|t,compareTo:r=>n!==r.major?n-r.major:e!==r.minor?e-r.minor:t-r.patch}}function Ne(n){return`${n.publisher}/${n.package_}/${n.name}`}function y(n,e,t){return`${n}/${e}/${t}`}function He(n){return`${n.s}|${n.p}|${ae(n.o)}`}function ae(n){switch(n.kind){case"uri":return`u:${n.key}`;case"literal":return`l:${n.datatype}:${n.lexical}`;case"blank":return`b:${n.id}`}}function Ie(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var se="kanonak.org",ie="core-shacl",s=n=>({publisher:se,package_:ie,name:n}),N=s("Shape"),H=s("NodeShape"),I=s("PropertyShape"),$e=s("targetClass"),Te=s("property"),ve=s("path"),je=s("minCount"),we=s("maxCount"),Me=s("datatype"),Le=s("class"),Ve=s("in"),Fe=s("pattern"),Be=s("flags"),Ge=s("minLength"),Xe=s("maxLength"),Ye=s("minInclusive"),qe=s("maxInclusive"),We=s("message"),ze=s("targetNode"),Je=s("targetSubjectsOf"),Qe=s("targetObjectsOf"),Ze=s("closed"),et=s("ignoredProperties"),tt=s("nodeKind"),nt=s("IRI"),rt=s("BlankNode"),ot=s("Literal"),at=s("severity"),st=s("Violation"),it=s("Warning"),pt=s("Info"),ct=s("ValidationReport"),lt=s("conforms"),ut=s("result"),yt=s("ValidationResult"),dt=s("focusNode"),gt=s("resultPath"),mt=s("resultMessage"),ft=s("resultSeverity"),kt=s("sourceShape"),bt=s("value"),St=s("sourceConstraintComponent"),ht=s("MinCountConstraintComponent"),_t=s("MaxCountConstraintComponent"),Pt=s("DatatypeConstraintComponent"),Kt=s("ClassConstraintComponent"),Et=s("InConstraintComponent"),Ct=s("PatternConstraintComponent"),At=s("MinLengthConstraintComponent"),xt=s("MaxLengthConstraintComponent"),Rt=s("MinInclusiveConstraintComponent"),Ot=s("MaxInclusiveConstraintComponent"),Ut=s("NodeKindConstraintComponent"),Nt=s("ClosedConstraintComponent");var l="kanonak.org",p="core-rdf",f="core-owl",Z="core-kanonak",M=new Map([["type",p],["subClassOf",p],["subPropertyOf",p],["domain",p],["range",p],["label",p],["comment",p],["seeAlso",p],["isDefinedBy",p],["member",p],["Resource",p],["Class",p],["Property",p],["Datatype",p],["Literal",p],["List",p],["ObjectProperty",f],["DatatypeProperty",f],["AnnotationProperty",f],["Thing",f],["Nothing",f],["Package",Z]]),pe=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function $t(n){return M.has(n)}function Tt(n){let e=M.get(n);return e?{publisher:l,package_:e}:void 0}function L(n,e,t){if(!n||!n.name)return;let r=M.get(n.name);if(!r)return;let o=()=>{n.publisher=l,n.package_=r,t&&(n.version=t.get(r))};if(pe.has(n.name)){let a=n.publisher===l&&n.package_===r;n.publisher=l,n.package_=r,!a&&t&&(n.version=t.get(r));return}n.publisher===l&&n.package_===r||n.publisher&&n.publisher.length>0&&(!e||e(n))||o()}var Q=class{type=y(l,p,"type");subClassOf=y(l,p,"subClassOf");subPropertyOf=y(l,p,"subPropertyOf");domain=y(l,p,"domain");range=y(l,p,"range");label=y(l,p,"label");comment=y(l,p,"comment");resource=y(l,p,"Resource");class_=y(l,p,"Class");datatype=y(l,p,"Datatype");literal=y(l,p,"Literal");equivalentClass=y(l,f,"equivalentClass");equivalentProperty=y(l,f,"equivalentProperty");inverseOf=y(l,f,"inverseOf");sameAs=y(l,f,"sameAs");transitiveProperty=y(l,f,"TransitiveProperty");symmetricProperty=y(l,f,"SymmetricProperty");objectProperty=y(l,f,"ObjectProperty");datatypeProperty=y(l,f,"DatatypeProperty");annotationProperty=y(l,f,"AnnotationProperty");package_=y(l,Z,"Package");shape=w(N);nodeShape=w(H);propertyShape=w(I)};function w(n){return y(n.publisher,n.package_,n.name)}var ce=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function b(n){let e=n;if(e.entity&&typeof e.entity=="object"){let t=e.entity.type;if(typeof t=="string"){let o={publisher:"",package_:"",name:t.includes(".")?t.substring(t.lastIndexOf(".")+1):t};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}if(e.statement&&Array.isArray(e.statement)){for(let t of e.statement)if(t.predicate?.subject?.name==="type"&&t.object?.subject){let r=t.object.subject,o={publisher:r.publisher??"",package_:r.package_??"",name:r.name};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}return null}var le=[N,H,I];function h(n,e){return ce.has(`${n}/${e}`)}var ue=new Set(["Property","ObjectProperty","DatatypeProperty","AnnotationProperty"]);function V(n){if(h(n.publisher,n.package_))return ue.has(n.name)?n.name:void 0}var ee=class n{static getTypeUri(e){return b(e)}static isCoreOntologyType(e){return h(e.publisher,e.package_)}static isClassType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Class":!1}static isDatatypeType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Datatype":!1}static isDatatypePropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="DatatypeProperty":!1}static isObjectPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="ObjectProperty":!1}static isAnnotationPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="AnnotationProperty":!1}static isGenericPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Property":!1}static isAnyPropertyType(e){let t=b(e);return!t||!h(t.publisher,t.package_)?!1:t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"}static isShapeType(e){let t=b(e);return t?le.some(r=>X(t,r)):!1}static isSchemaDefinitionType(e){if(n.isShapeType(e))return!0;let t=b(e);return!t||!h(t.publisher,t.package_)?!1:t.name==="Class"||t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"||t.name==="Datatype"}static isInstanceOfKnownClass(e,t){if(n.isSchemaDefinitionType(e))return!1;let r=b(e);return r?t.has(r.name):!1}};var x="kanonak.org",R="core-rdf",ye={publisher:x,package_:R,name:"domain"},de={publisher:x,package_:R,name:"range"},ge={publisher:x,package_:R,name:"subClassOf"},me={publisher:x,package_:R,name:"type"},fe={publisher:x,package_:R,name:"label"},ke={publisher:x,package_:R,name:"comment"},be=new P(x,R,"Resource");function Se(n){try{let e=J(`${n.namespace}/${n.name}`);return e.kind==="resource"?e.uri:void 0}catch{return}}function F(n,e){let t=j(n,e);if(t)return[t];let r=[];for(let o of q(n,e))o instanceof G&&r.push(o.subject);return r}function ne(n,e){let t=[],r=new Set,o="version"in e?e.version:void 0,a=[new P(e.publisher,e.package_,e.name,o??void 0)];for(;a.length>0;){let i=a.shift(),u=S(i);if(r.has(u))continue;r.add(u),t.push(i);let c=he(n,i);c&&a.push(...F(c,ge))}return t}function he(n,e){return e.version&&typeof e.version.major=="number"?Y(n,e)??T(n,e)[0]:T(n,e)[0]}function D(n,e){let t;for(let r of Ee(e)){let o=_e(n,r);if(o){if(o!=="Property")return o;t??=o}}return t}function _e(n,e){let t=V(e);if(t)return t;let r=te.get(n);r||(r=new Map,te.set(n,r));let o=e.version,a=o&&typeof o.major=="number"?`${S(e)}@${o.major}.${o.minor}.${o.patch}`:S(e),i=r.get(a);if(i!==void 0)return i??void 0;let u;for(let c of ne(n,e)){let g=V(c);if(g){if(g!=="Property"){u=g;break}u??="Property"}}return r.set(a,u??null),u}var te=new WeakMap;function qt(n,e){return D(n,e)!==void 0}function Wt(n,e){return D(n,e)==="ObjectProperty"}function zt(n,e){return D(n,e)==="DatatypeProperty"}function Pe(n,e){let t=new Set([S(be)]);for(let r of ne(n,e))t.add(S(r));return t}function Ke(n,e){let t=Pe(n,e),r=[],o=new Set;for(let a of n){if(!(a instanceof B))continue;let i=D(n,a);if(!i)continue;let u=F(a,ye);if(!u.some(m=>t.has(S(m))))continue;let c=Se(a);if(!c)continue;let g=S(c);o.has(g)||(o.add(g),r.push({uri:c,label:v(a,fe),comment:v(a,ke),kind:i==="ObjectProperty"?"object":i==="DatatypeProperty"?"datatype":"other",range:j(a,de),domains:u}))}return r}function Jt(n,e,t){let r=Ke(n,e).find(o=>S(o.uri)===S(t));return r?{ok:!0,descriptor:r}:{ok:!1,message:`Property ${t.publisher}/${t.package_}/${t.name} is not in scope for ${e.publisher}/${e.package_}/${e.name}.`}}function Ee(n){return F(n,me)}export{W as a,z as b,J as c,Oe as d,Ne as e,y as f,He as g,ae as h,Ie as i,se as j,ie as k,N as l,H as m,I as n,$e as o,Te as p,ve as q,je as r,we as s,Me as t,Le as u,Ve as v,Fe as w,Be as x,Ge as y,Xe as z,Ye as A,qe as B,We as C,ze as D,Je as E,Qe as F,Ze as G,et as H,tt as I,nt as J,rt as K,ot as L,at as M,st as N,it as O,pt as P,ht as Q,_t as R,Pt as S,Kt as T,Et as U,Ct as V,At as W,xt as X,Rt as Y,Ot as Z,Ut as _,Nt as $,$t as aa,Tt as ba,L as ca,Q as da,V as ea,ee as fa,Se as ga,ne as ha,D as ia,qt as ja,Wt as ka,zt as la,Ke as ma,Jt as na,Ee as oa};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as D}from"./chunk-
|
|
1
|
+
import{a as D}from"./chunk-F3SGXIDP.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-CJMVIOZX.js";import{c as b,g as u}from"./chunk-QILEJIFU.js";function F(a,e,n,t){let i=g(a);if(i.length>0){let s=v(i,e,n);return s?{transformation:s.transformation,source:"instance"}:void 0}let r=new Set,o=O(a);for(;o.length>0;){let s=o.shift(),f=_(s.subject);if(r.has(f))continue;r.add(f);let l=S(t,s.subject);if(l.length===0)continue;let U=l.flatMap(g),h=v(U,e,n);if(h)return{transformation:h.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let T of l)for(let P of $(T))o.push(P)}let c={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!r.has(_(c))){let s=S(t,c).flatMap(g),f=v(s,e,n);if(f)return{transformation:f.transformation,source:c}}}function g(a){let e=[];for(let n of a.statement)if(n instanceof k&&d(n,"kanonak.org","derivation","derivations"))for(let t of n.object??[]){if(!(t instanceof D))continue;let i=x(t);i&&e.push(i)}return e}function v(a,e,n){let t=a.filter(o=>E(o.format,e)&&E(o.variant,n));if(t.length<=1)return t[0];let i=t[0].transformation,r=t[0];for(let o of t){let c=o.transformation;if(c.publisher!==i.publisher||c.package_!==i.package_||c.name!==i.name)continue;let s=u(r.transformation.version),f=u(c.version);s&&f&&b(f,s)>0&&(r=o)}return r}function x(a){let e,n,t;for(let i of a.statement)i instanceof p?d(i,"kanonak.org","derivation","format")?e=y(i):d(i,"kanonak.org","derivation","variant")&&(n=y(i)):i instanceof K&&d(i,"kanonak.org","derivation","transformation")&&(t=C(i.object));if(!(!e||!t))return n||(n={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:e,variant:n,transformation:t}}function C(a){let e,n,t,i;for(let r of a.statement){if(!(r instanceof R))continue;let o=r.predicate?.subject?.name;o==="publisher"?e=r.object:o==="package"?n=r.object:o==="version"?t=r.object:o==="name"&&(i=r.object)}if(!(!e||!n||!t||!i))return{publisher:e,package_:n,version:t,name:i}}function O(a){let e=[];for(let n of a.statement)n instanceof p&&n.predicate?.subject?.name==="type"&&n.object instanceof m&&e.push(n.object);return e}function $(a){let e=[];for(let n of a.statement)if(n instanceof p){if(n.predicate?.subject?.name!=="subClassOf")continue;n.object instanceof m&&e.push(n.object)}else if(n instanceof k){if(n.predicate?.subject?.name!=="subClassOf")continue;for(let t of n.object??[])t instanceof m&&e.push(t)}return e}function S(a,e){let n=[];for(let t of a){if(!(t instanceof j)||t.name!==e.name)continue;(t.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(t)}return n.sort((t,i)=>{let r=u((t.namespace||"").split("@")[1]??""),o=u((i.namespace||"").split("@")[1]??"");return!r||!o?0:b(o,r)}),n}function d(a,e,n,t){let i=a.predicate?.subject;return i?i.publisher===e&&i.package_===n&&i.name===t:!1}function y(a){let e=a.object.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}function E(a,e){return a.publisher===e.publisher&&a.package_===e.package_&&a.name===e.name}function _(a){return`${a.publisher}/${a.package_}/${a.name}`}export{F as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{l as V}from"./chunk-
|
|
1
|
+
import{l as V}from"./chunk-F3SGXIDP.js";import{a as E}from"./chunk-KOWDHKBN.js";var L=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as O,LineCounter as R,isMap as h,isPair as f,isScalar as g,isSeq as I}from"yaml";var K=class i{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let t=new i,n=new R,r=O(e,{lineCounter:n});if(r.errors.length>0||!h(r.contents))return t;N(r.contents,[],n,t);for(let o of r.contents.items){if(!f(o)||!g(o.key))continue;let a=String(o.key.value),u=o.key.range;if(!u)continue;t.entities.set(a,d(u,n));let s=o.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?t.entityBlocks.set(a,d([u[0],u[1],c[2]],n)):t.entityBlocks.set(a,d(u,n)),h(o.value)){let k=new Map,m=new Map,l=new Map;for(let P of o.value.items){if(!f(P)||!g(P.key))continue;let b=String(P.key.value),p=P.key.range;p&&k.set(b,d(p,n));let S=P.value;if(S&&typeof S=="object"&&"range"in S&&Array.isArray(S.range)){let v=S.range;m.set(b,d(v,n))}if(I(S)){let v=[];for(let M of S.items)M&&typeof M=="object"&&"range"in M&&Array.isArray(M.range)&&v.push(d(M.range,n));v.length>0&&l.set(b,v)}}k.size>0&&t.properties.set(a,k),m.size>0&&t.propertyValues.set(a,m),l.size>0&&t.valueListItems.set(a,l);let y=j(o.value,n);y.length>0&&t.importPackages.set(a,y)}}return t}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,t){for(let[n,r]of this.entityBlocks)if(w(r,e,t))return n}findPropertyAtPosition(e,t){let n=this.findEntityAtPosition(e,t);if(!n)return;let r=this.properties.get(n),o=this.propertyValues.get(n);if(!r&&!o)return{entityName:n};let a,u;if(o)for(let[s,c]of o)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);if(r)for(let[s,c]of r)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);return a?{entityName:n,propertyName:a}:{entityName:n}}getPropertyPosition(e,t){return this.properties.get(e)?.get(t)}getPropertyValuePosition(e,t){return this.propertyValues.get(e)?.get(t)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[t,n]of this.importPackages)for(let r of n)e.push({entityName:t,entry:r});return e}findPropertySourceName(e,t){let n=this.properties.get(e);if(n){if(n.has(t))return t;for(let r of n.keys()){let o=r.lastIndexOf(".");if((o===-1?r:r.substring(o+1))===t)return r}}}getListItemPosition(e,t,n){let r=this.valueListItems.get(e)?.get(t);if(!(!r||n<0||n>=r.length))return r[n]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,t){this.nestedKeys.set(e,t)}setNestedValuePosition(e,t){this.nestedValues.set(e,t)}getMostSpecificPosition(e,t,n){if(e){if(t!==void 0){if(n!==void 0){let a=this.getListItemPosition(e,t,n);if(a)return a}let r=this.getPropertyValuePosition(e,t);if(r)return r;let o=this.getPropertyPosition(e,t);if(o)return o}return this.getEntityPosition(e)}}};function j(i,e){let t=[];if(!h(i))return t;let n=i.items.find(r=>f(r)&&g(r.key)&&String(r.key.value)==="imports");if(!n||!f(n)||!I(n.value))return t;for(let r of n.value.items){if(!h(r))continue;let o=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!o||!f(o)||!g(o.value))continue;let a=String(o.value.value),u=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!f(u)||!I(u.value)))for(let s of u.value.items){if(!h(s))continue;let c=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="package");if(!c||!f(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="version"),l=m&&f(m)&&g(m.value)?String(m.value.value):"",y=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="alias"),P=y&&f(y)&&g(y.value)?String(y.value.value):void 0,b=P!==void 0?{publisher:a,package_:k,version:l,alias:P,position:d(c.value.range,e)}:{publisher:a,package_:k,version:l,position:d(c.value.range,e)};t.push(b)}}return t}function w(i,e,t){return!(e<i.line||e>i.endLine||e===i.line&&t<i.column||e===i.endLine&&t>i.endColumn)}function C(i,e){let t=i.endLine-i.line,n=e.endLine-e.line;if(t!==n)return t<n;let r=i.endLine===i.line?i.endColumn-i.column:Number.MAX_SAFE_INTEGER,o=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return r<o}function N(i,e,t,n){if(h(i)){for(let r of i.items){if(!f(r)||!g(r.key))continue;let o=String(r.key.value),a=[...e,o],u=JSON.stringify(a);r.key.range&&n.setNestedKeyPosition(u,d(r.key.range,t));let s=r.value,c=D(s);c&&n.setNestedValuePosition(u,d(c,t)),N(s,a,t,n)}return}if(I(i)){for(let r=0;r<i.items.length;r++){let o=i.items[r],a=[...e,r],u=JSON.stringify(a),s=D(o);s&&n.setNestedValuePosition(u,d(s,t)),N(o,a,t,n)}return}}function D(i){if(!i||typeof i!="object"||!("range"in i))return;let e=i.range;return Array.isArray(e)&&e.length>=3?e:void 0}function d(i,e){let t=e.linePos(i[0]),n=e.linePos(i[2]);return{line:t.line-1,column:t.col-1,endLine:n.line-1,endColumn:n.col-1}}function x(i,e){let n=(e??new E).parse(i),r=K.fromContent(i);return{document:n,positions:r}}function W(i,e,t,n,r){if(e<n.line||e>n.endLine||e===n.line&&t<n.column||e===n.endLine&&t>=n.endColumn)return;let o=A(r,n.line,n.column),a=A(r,n.endLine,n.endColumn);if(o<0||a<0)return;let u=r.substring(o,a),s=V(u);if(s.length!==i.links.length)return;let c=e-n.line,k=e===n.line?t-n.column:t,m=A(u,c,k);if(!(m<0))for(let l=0;l<s.length;l++){let y=s[l];if(m>=y.startOffset&&m<y.endOffset)return i.links[l]}}function A(i,e,t){let n=0,r=0;for(let o=0;o<i.length;o++){if(n===e)return Math.min(r+t,i.length);i[o]===`
|
|
2
2
|
`&&(n++,r=o+1)}return n===e?Math.min(r+t,i.length):-1}export{L as a,K as b,x as c,W as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{e as R}from"./chunk-P5VQEDBS.js";import{a as H,b as B,c as Z,i as x,m as ne}from"./chunk-F3SGXIDP.js";import{ba as ee,fa as T,ia as N}from"./chunk-G3GKOJ5E.js";import{b as z,c as _,d as $,f as q,g as W,h as Y,i as J,j as X,k as Q,l as I}from"./chunk-CJMVIOZX.js";var oe=(o=>(o.Class="Class",o.DatatypeProperty="DatatypeProperty",o.ObjectProperty="ObjectProperty",o.AnnotationProperty="AnnotationProperty",o.Instance="Instance",o.Datatype="Datatype",o.Shape="Shape",o.Unknown="Unknown",o))(oe||{}),se=(o=>(o.InstanceOf="instanceOf",o.SubClassOf="subClassOf",o.Domain="domain",o.Range="range",o.ObjectRelationship="objectRelationship",o.SubPropertyOf="subPropertyOf",o.PropertyValue="propertyValue",o.EmbeddedLink="embeddedLink",o))(se||{}),D=class{static async buildFromRepository(n,t){let a=await new ne().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],i=[],o=new Set,d=new Set,y=new Map;for(let g of a){let p=g;if(p.name&&(T.isClassType(p)&&o.add(p.name),g instanceof _)){let l=N(a,g);(l==="ObjectProperty"||l==="Property")&&d.add(p.name)}}for(let g of s)for(let[p,l]of Object.entries(g.body))d.has(p)&&l?.range&&typeof l.range=="string"&&y.set(p,l.range);let f=new Map;for(let g of a){let p=g;p.name&&f.set(p.name,p)}for(let g of s){let p=g.metadata.namespace_,l=p?`${p.publisher}/${p.package_}`:"",m=p?.version?`${p.version.major}.${p.version.minor}.${p.version.patch}`:"",C=te(g);for(let[h,u]of Object.entries(g.body)){if(!u||typeof u!="object")continue;let b=f.get(h),k="Unknown";if(b){let A=b,P=b instanceof _?N(a,b):void 0;T.isClassType(A)?k="Class":P==="ObjectProperty"?k="ObjectProperty":P==="DatatypeProperty"?k="DatatypeProperty":P==="AnnotationProperty"?k="AnnotationProperty":T.isDatatypeType(A)?k="Datatype":P==="Property"?k="ObjectProperty":T.isShapeType(A)?k="Shape":T.isInstanceOfKnownClass(A,o)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,L={};for(let[A,P]of Object.entries(u))A!=="type"&&(typeof P!="object"||P===null)&&(L[A]=P);c.push({id:S,label:u.label??h,type:k,namespace:l,properties:L}),re(S,u,k,o,d,i,l,m,C,t),M(S,u,d,y,c,i,l,m,C),be(S,b,i)}}return{nodes:c,edges:i}}static buildFromDocument(n,t){let r=[],a=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",i=s?`${s.publisher}/${s.package_}`:"",o=new Set,d=new Set,y=new Map,f=te(n);for(let[l,m]of Object.entries(n.body)){let C=m?.type;C&&(he(C,f)&&o.add(l),me(C,f)&&(d.add(l),m.range&&typeof m.range=="string"&&y.set(l,m.range)))}for(let[l,m]of Object.entries(n.body)){if(!m||typeof m!="object")continue;let C=m.type,h=ke(C,l,o,f),u=i&&c?`${i}/${l}@${c}`:l,b={};for(let[k,S]of Object.entries(m))k!=="type"&&(typeof S!="object"||S===null)&&(b[k]=S);r.push({id:u,label:m.label??l,type:h,namespace:i,properties:b}),re(u,m,h,o,d,a,i,c,f,t),M(u,m,d,y,r,a,i,c,f)}let g=new Set(r.map(l=>l.id)),p=a.filter(l=>g.has(l.source)&&g.has(l.target));return{nodes:r,edges:p}}};function te(e,n){let t=new Map;if(e.metadata?.imports)for(let[r,a]of Object.entries(e.metadata.imports))for(let s of a){let c=s.alias??s.packageName,i=s.version,o=`${i.major}.${i.minor}.${i.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:o})}return t}var ae={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},ye=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function K(e,n){if(e.includes(".")){let t=e.indexOf("."),r=e.substring(0,t),a=e.substring(t+1),s=n.get(r);if(s)return`${s.publisher}/${s.package_}/${a}`}return null}function he(e,n){let t=K(e,n);return t?ae[t]==="Class":!1}function me(e,n){let t=K(e,n);return t?ye.has(t):!1}function ke(e,n,t,r){if(!e||e==="Package")return"Unknown";let a=K(e,r);if(a){let c=ae[a];if(c)return c;let i=a.split("/").pop()?.split("@")[0]??"";return t.has(i)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ie=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function re(e,n,t,r,a,s,c,i,o,d){let y=n.type,f=n.subClassOf;if(f){let h=Array.isArray(f)?f:[f];for(let u of h)typeof u=="string"&&s.push({source:e,target:w(u,c,i,o),type:"subClassOf",label:"subClassOf"})}let g=n.subPropertyOf;if(g){let h=Array.isArray(g)?g:[g];for(let u of h)typeof u=="string"&&s.push({source:e,target:w(u,c,i,o),type:"subPropertyOf",label:"subPropertyOf"})}let p=n.domain,l=n.range;if(d?.includePropertyEdges){let h=[[p,"domain","domain"],[l,"range","range"]];for(let[u,b,k]of h)if(u!=null)for(let S of Array.isArray(u)?u:[u])typeof S=="string"&&s.push({source:e,target:w(S,c,i,o),type:b,label:k})}if(t==="Instance"&&y){let h=y.split(".").pop()??y;s.push({source:e,target:w(h,c,i,o),type:"instanceOf",label:"type"})}if(t==="Instance")for(let[h,u]of Object.entries(n)){if(ie.has(h)||!a.has(h))continue;let b=Array.isArray(u)?u:[u];for(let k of b)typeof k=="string"&&Ce(k)&&s.push({source:e,target:w(k,c,i,o),type:"propertyValue",label:h,propertyId:w(h,c,i,o)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||p&&l)&&p&&l){let h=typeof p=="string"?p:null,u=typeof l=="string"?l:null;h&&u&&s.push({source:w(h,c,i,o),target:w(u,c,i,o),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function M(e,n,t,r,a,s,c,i,o){for(let[d,y]of Object.entries(n)){if(ie.has(d)||typeof y!="object"||y===null||Array.isArray(y))continue;let f=y,g=`${e}/${d}`,p=r.get(d),l=p?p.split(".").pop()??p:"Unknown",m={};for(let[h,u]of Object.entries(f))(typeof u!="object"||u===null)&&(m[h]=u);a.push({id:g,label:`${l} (embedded)`,type:"Instance",namespace:c,properties:m});let C=c&&i?`${c}/${d}@${i}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?C:void 0}),p&&s.push({source:g,target:w(l,c,i,o),type:"instanceOf",label:"type (inferred)"}),M(g,f,t,r,a,s,c,i,o)}}function be(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let a of r){if(!(a instanceof Z))continue;let s=a.predicate?.subject?.name??"";for(let c of a.links){let i=c.target?.subject;if(!i)continue;let o=i.version,d=o&&typeof o.major=="number"?`@${o.major}.${o.minor}.${o.patch}`:"";t.push({source:e,target:`${i.publisher}/${i.package_}/${i.name}${d}`,type:"embeddedLink",label:s})}}}function Ce(e){return!(!e||e.includes(" ")||e.includes(`
|
|
2
|
+
`)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function w(e,n,t,r){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let a=e.indexOf("."),s=e.substring(0,a),c=e.substring(a+1);if(r){let i=r.get(s);if(i)return`${i.publisher}/${i.package_}/${c}@${i.version}`}return n&&t?`${n}/${c}@${t}`:c}return n&&t?`${n}/${e}@${t}`:e}import{canonicalForm as Se,canonicalHash as we}from"@kanonak-protocol/canonical";function F(e){return typeof e=="object"&&e!==null&&Array.isArray(e.subjects)}import{CANONICAL_FORM_VERSION as $e}from"@kanonak-protocol/canonical";function Oe(e){return Se(F(e)?e:pe(e))}function ve(e){return we(F(e)?e:pe(e))}function pe(e){let n=[];for(let t of e)t instanceof _&&n.push({uri:Re(t),statements:U(t.statement)});return{subjects:n}}function U(e){let n=[];for(let t of e){let r=Ee(t);if(!r)continue;if(t instanceof I&&Pe(t.predicate.subject)){n.push(...Te(t,r));continue}let a=je(t);a&&n.push({predicate:r,value:a})}return n}function Pe(e){let n=ee("type");return n!==void 0&&e.name==="type"&&e.publisher===n.publisher&&e.package_===n.package_}var ce=new TextEncoder;function Ae(e,n){let t=ce.encode(e),r=ce.encode(n),a=Math.min(t.length,r.length);for(let s=0;s<a;s++)if(t[s]!==r[s])return t[s]-r[s];return t.length-r.length}function Te(e,n){let t=[];for(let r of e.object){if(!(r instanceof $))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(G(r))}t.sort(Ae);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:n,value:{ref:r}}))}function je(e){if(e instanceof q&&e.carrier)return{lit:e.lexical??String(e.object),datatype:ue(e.carrier)};if(e instanceof W)return{raw:e.object};if(e instanceof Y)return{raw:e.lexical??String(e.object)};if(e instanceof J)return{raw:e.lexical??String(e.object)};if(e instanceof X)return{ref:G(e.object)};if(e instanceof Q)return le(e.object);if(e instanceof I)return{list:e.object.map(_e)}}function le(e){let n=U(e.statement);return e.name&&e.name.length>0?{embed:{name:e.name,statements:n}}:{embed:{statements:n}}}function _e(e){if(e instanceof $)return{ref:G(e)};if(e instanceof H)return le(e);if(e instanceof B){if(e.carrier)return{lit:e.lexical??String(e.value),datatype:ue(e.carrier)};let n=e.value;if(typeof n=="string")return{raw:n};if(typeof n=="number")return{raw:String(n)};if(typeof n=="boolean")return{raw:String(n)}}if(e instanceof z)return{embed:{statements:U(e.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${e.constructor?.name??typeof e}); add canonicalization support before hashing data that contains it`)}function ue(e){return e===x.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${e}`}function Ee(e){let n=e.predicate;if(n)return de(n.subject)}function Re(e){let n=e.namespace??"",t=e.name??"";return`${n}/${t}`}function G(e){return de(e.subject)}function de(e){let n=e.version;return n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}/${e.name}`:`${e.publisher}/${e.package_}/${e.name}`}function j(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}var Ie="key_thumbprint",E=class{cache=new Map;prCache=new Map;async discoverProtectedResource(n){let t=j(n);if(this.prCache.has(t))return this.prCache.get(t);let r=`https://${t}/.well-known/oauth-protected-resource`,a=await Ne(r),s=a&&Array.isArray(a.authorization_servers)?a.authorization_servers.filter(i=>typeof i=="string"):[],c=s.length>0?s:null;return this.prCache.set(t,c),c}async discover(n){let t=j(n);if(this.cache.has(t))return this.cache.get(t);let r=`https://${t}/.well-known/oauth-authorization-server`,a=await this.tryEndpoint(r);if(!a){let s=`https://${t}/.well-known/openid-configuration`;a=await this.tryEndpoint(s)}return this.cache.set(t,a),a}async supportsOAuth(n){return await this.discover(n)!==null}static supportsPkceS256(n){return n.codeChallengeMethodsSupported?.some(t=>t.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(n){return!!n.registrationEndpoint}static supportsAuthorizationCode(n){return n.responseTypesSupported?.some(t=>t.toLowerCase()==="code")??!1}static supportsEnrollment(n){return!!n.enrollmentEndpoint}static supportsSession(n){return!!n.sessionEndpoint}async tryEndpoint(n){let t;try{t=await fetch(n)}catch(a){let s=a instanceof Error?a.message:String(a);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${n} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${n} \u2014 TLS error (${s})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${n} \u2014 network error: ${s}`),null}if(!t.ok)return t.status===404||(t.status===403?(console.error(` OAuth discovery: ${n} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):t.status>=500&&(console.error(` OAuth discovery: ${n} \u2014 HTTP ${t.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let r;try{r=await t.json()}catch{return console.error(` OAuth discovery: ${n} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:O(r.issuer),authorizationEndpoint:O(r.authorization_endpoint),tokenEndpoint:O(r.token_endpoint),registrationEndpoint:O(r.registration_endpoint),revocationEndpoint:O(r.revocation_endpoint),scopesSupported:v(r.scopes_supported),responseTypesSupported:v(r.response_types_supported),grantTypesSupported:v(r.grant_types_supported),codeChallengeMethodsSupported:v(r.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:v(r.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:v(r.dpop_signing_alg_values_supported),enrollmentEndpoint:O(r.enrollment_endpoint),enrollmentIssuanceProtocols:v(r.enrollment_issuance_protocols),enrollmentKeyTypes:v(r.enrollment_key_types),enrollmentScopesSupported:v(r.enrollment_scopes_supported),enrollmentConsentBindingParam:O(r.enrollment_consent_binding_param),sessionEndpoint:O(r.session_endpoint),sessionEndpointAuthMethod:O(r.session_endpoint_auth_method)}}};async function Ne(e){try{let n=await fetch(e);return n.ok?await n.json():null}catch{return null}}function O(e){return typeof e=="string"?e:null}function v(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):null}function fe(e){let n=e.headers.get("WWW-Authenticate")??void 0,t=e.headers.get("DPoP-Nonce")??void 0;if(!n&&!t)return;let r={wwwAuthenticate:n??""};if(t&&(r.nonce=t),n){let a=n.match(/acr_values\s*=\s*"([^"]*)"/i);a&&(r.acrValues=a[1])}return r}function xe(e){try{return new URL(e).host}catch{return null}}function De(e,n={}){let t=n.discovery??new E,r=new Map,a=new Map,s=async o=>{let d=r.get(o);if(d!==void 0)return d;let y=null,f=await t.discoverProtectedResource(o).catch(()=>null);return f&&f.length>0&&(y=xe(f[0])),r.set(o,y),y},c=async(o,d)=>{if(!e)return null;if(!(d.forceRefresh||d.challenge)&&a.has(o))return a.get(o);let f=await e.resolve(o,d).catch(()=>null);return a.set(o,f),f},i=async(o,d,y,f)=>{let g=await s(d);if(!g)return{res:await R(o,{method:y,redirect:"manual"}),authed:!1};let p=await c(g,{method:y,url:o,...f}),l=p?.headers??{};return{res:await R(o,{method:y,redirect:"manual",headers:l}),authed:!!p}};return async(o,d,y="GET")=>{let f=await i(o,d,y,{});if((f.res.status===401||f.res.status===403)&&f.authed){let g=fe(f.res),p={forceRefresh:g===void 0};return g&&(p.challenge=g),(await i(o,d,y,p)).res}return f.res}}var ge="KANONAK_TOKEN";function Me(){return typeof process<"u"&&process.env?process.env:{}}function Ke(e){return`${ge}_${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var V=class{tokens;env;constructor(n={}){this.tokens=n.tokens??{},this.env=n.env??Me()}async resolve(n,t){let r=j(n),a=this.tokens[r]??this.env[Ke(r)]??this.env[ge];return a?{headers:{Authorization:`Bearer ${a}`}}:null}};export{oe as a,se as b,D as c,Oe as d,ve as e,$e as f,j as g,Ie as h,E as i,fe as j,De as k,V as l};
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type { IStatement } from './statements/index.js';
|
|
|
15
15
|
export type { MarkdownLink } from './statements/index.js';
|
|
16
16
|
export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement, MarkdownStatement } from './statements/index.js';
|
|
17
17
|
export { extractMarkdownLinks, findMalformedReferences, type RawMarkdownLink, type MalformedMarkdownLink, } from './parsing/extractMarkdownLinks.js';
|
|
18
|
-
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ReservedNameShadowRule, ClassDefinitionRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionCompilesRule, LookBandPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './validation/index.js';
|
|
18
|
+
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ReservedNameShadowRule, ClassDefinitionRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionCompilesRule, SequenceNarrativeRule, LookBandPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './validation/index.js';
|
|
19
19
|
export { scopeFromRepositoryAsync, scopeFromCatalog, scopeFromDocumentAsync, buildShapesModel, lowerConstraint, foldFlagsIntoPattern, evaluateConformance, buildReportPackageAsync, SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, } from './shacl/index.js';
|
|
20
20
|
export type { ConformanceScope, ShaclNodeShapeModel, ShaclPropertyConstraint, ShaclNodeKind, ShaclSeverity, LoweredCheck, LoweredExprNode, ShaclConformanceResult, ShaclFinding, } from './shacl/index.js';
|
|
21
21
|
export type { IKanonakObjectValidator, DocumentValidationResult, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
|
|
@@ -32,6 +32,8 @@ export { findDerivation } from './derivation/index.js';
|
|
|
32
32
|
export type { DerivationEntityUri, TransformationReferenceTuple, DerivationLookupResult, } from './derivation/index.js';
|
|
33
33
|
export { LookRenderer, resolveDisplayValue, supportedBandKeys } from './look/index.js';
|
|
34
34
|
export type { ResolvedLook, DisplayValue } from './look/index.js';
|
|
35
|
+
export { walkSequence, readSequenceConnectors, LINE_STYLES } from './look/index.js';
|
|
36
|
+
export type { SequenceWalk, SequenceMessage, SequenceGap, SequenceConnector, LineStyle } from './look/index.js';
|
|
35
37
|
export { ViewMaterializer } from './view/index.js';
|
|
36
38
|
export type { MaterializeOptions, MaterializeResult } from './view/index.js';
|
|
37
39
|
export { PackageBuilder, ImportBook, contentAddressedName, sanitizeName, ProducerRepository, EntitlementProducer, EntitlementDeniedError, allowAllPolicy, noopMeter, } from './producer/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Zt,b as Qt,c as eo,d as no,e as H}from"./chunk-4VLLX3MZ.js";import{a as Vn,b as Nn,c as On}from"./chunk-D66LUZDB.js";import{a as Xt,b as Yt,c as Jt,d as Yo,e as we,f as Jo,g as Zo,h as Qo,i as er,j as nr,k as tr,l as or,m as ar}from"./chunk-RVR25FWW.js";import{a as rr}from"./chunk-RWN5JZPU.js";import{a as mt,b as ft,c as kt,d as yt,e as ht,f as Ct,g as It,h as _t,i as At}from"./chunk-JFBPQN6T.js";import{a as gt,b as St,c as bt,d as Pt,e as Rt,f as Et,h as Kt,i as De,j as Me,k as He,l as Te,m as xt,n as vt}from"./chunk-P5VQEDBS.js";import{a as oo,b as ro,c as ao,d as io}from"./chunk-KOV3AFBN.js";import{a as so}from"./chunk-PEB52US5.js";import{a as wt}from"./chunk-SC5M74NM.js";import{A as Oo,B as $o,C as Uo,D as Do,E as Mo,F as Ho,G as Wo,H as zo,I as Go,L as qo,M as Xo,a as uo,b as lo,c as po,d as mo,e as fo,f as ko,g as yo,h as ho,i as go,j as So,k as bo,l as Po,m as Ro,n as Eo,o as Ko,p as xo,q as wo,r as vo,s as Co,t as Io,u as _o,v as Ao,w as Lo,x as jo,y as Vo,z as No}from"./chunk-4C7ZMXQT.js";import"./chunk-BRCVOR7A.js";import{c as An,d as To,f as xe,h as Ln,i as jn,j as Fo,k as Bo}from"./chunk-ZZINR6NT.js";import{a as me}from"./chunk-6VIUXP4N.js";import{a as E,b as D,c as ge,i as V,j as Ke,k as Gt,l as qt,m as A}from"./chunk-M7LXZN47.js";import{a as j}from"./chunk-KOWDHKBN.js";import{a as co}from"./chunk-PEJALHXK.js";import{$ as Re,A as tn,B as on,C as rn,D as an,E as sn,F as cn,G as un,H as ln,I as pn,J as dn,K as mn,L as fn,M as Pe,N as kn,O as yn,P as hn,Q as gn,R as Sn,S as bn,T as Pn,U as Rn,V as En,W as Kn,X as xn,Y as wn,Z as vn,_ as Cn,a as $t,b as Ut,c as Se,d as Dt,da as Ft,e as M,f as Mt,fa as Bt,g as Ht,ga as h,ha as ee,i as Tt,j as X,k as Y,l as Fe,m as J,ma as Wt,n as Be,na as zt,o as We,oa as ne,p as ze,q as Ge,r as qe,s as Xe,t as Ye,u as Je,v as be,w as Ze,x as Qe,y as en,z as nn}from"./chunk-NOPFCGB7.js";import{A as Q,a as Lt,b as jt,c as g,d as k,e as Nt,f as Ot,g as fe,h as ke,i as ye,j as G,k as he,l as q,m as u,q as In,s as K,u as _n,v as I,w as Z,x as y,y as Ee,z as _}from"./chunk-CZY6OOTM.js";import{a as Vt}from"./chunk-FUUTGGJS.js";import{a as at,b as de,c as z,d as it,e as w,f as st,g as ct,h as ut,i as lt,j as pt,k as dt}from"./chunk-QILEJIFU.js";import{a as to}from"./chunk-ODIECDN7.js";async function $n(n){let e=await new A().parseKanonaks(n),o=await new H().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Un(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Dn(n,e){let o=e??new me(new j);return{kind:"standalone",catalog:await new A().parseKanonaks(new Q(n,o))}}function $(n){return typeof n=="number"?n:void 0}function ir(n){if(!n)return;let e=u(n);if(e===u(dn))return"IRI";if(e===u(mn))return"BlankNode";if(e===u(fn))return"Literal"}function Mn(n){if(!n)return;let e=u(n);if(e===u(kn))return"Violation";if(e===u(yn))return"Warning";if(e===u(hn))return"Info"}function ve(n,e){let o=y(n,e);if(o)return[o];let t=[];for(let r of _(n,e))r instanceof k&&t.push(r.subject);return t}function sr(n,e){let o=y(n,Ge);if(!o)return;let t={path:o},r=$(I(n,qe)),a=$(I(n,Xe));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=$(I(n,en)),i=$(I(n,nn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let c=$(I(n,tn)),p=$(I(n,on));c!==void 0&&(t.minInclusive=c),p!==void 0&&(t.maxInclusive=p);let d=Z(n,Ze);if(d!==void 0){let P=Z(n,Qe);t.pattern=P!==void 0?{regex:d,flags:P}:{regex:d}}if(_n(n,be)){let P=[],N=[];for(let O of _(n,be))O instanceof D?P.push(O.value):O instanceof k&&N.push(O.subject);P.length>0&&(t.inValues=P),N.length>0&&(t.inRefs=N)}let S=y(n,Ye);S&&(t.datatype=S);let b=y(n,Je);b&&(t.classRef=b);let l=ir(y(n,pn));l&&(t.nodeKind=l);let m=Z(n,rn);m!==void 0&&(t.message=m);let f=Mn(y(n,Pe))??e;return f&&(t.severity=f),t}function te(n){let e=[];for(let o of n){if(!(o instanceof g)||!In(o,J))continue;let t=Mn(y(o,Pe)),r={name:o.name,uri:h(o),targetClass:y(o,We),targetNodes:ve(o,an),targetSubjectsOf:ve(o,sn),targetObjectsOf:ve(o,cn),closed:I(o,un)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of _(o,ln))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of _(o,ze)){let s;if(a instanceof E?s=a:a instanceof k&&(s=K(n,a.subject)),!s)continue;let i=sr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var x="kanonak.org/transformations",oe="values";var re="allowed",v=n=>({type:`${x}/VarRef`,varName:n}),Ce=n=>({type:`${x}/IntegerLiteral`,integerLiteral:n}),cr=n=>({type:`${x}/DecimalLiteral`,decimalLiteral:n}),Hn=n=>Number.isInteger(n)?Ce(n):cr(n),Tn=n=>({type:`${x}/Count`,source:n}),Fn=(n,e)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Bn=(n,e)=>({type:`${x}/LessThanOrEqual`,compareLeft:n,compareRight:e});function Ie(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function ae(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Fn(Tn(v(oe)),Ce(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Bn(Tn(v(oe)),Ce(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:v(re),needle:v("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:v("v"),pattern:Ie(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:v("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:v("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Fn(v("v"),Hn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Bn(v("v"),Hn(n.maxInclusive))}),e}import{evaluate as lr,ExpressionError as pr}from"@kanonak-protocol/expression";function Gn(n,e){let o=dr(e)?e:te(e),t=[];for(let r of o)for(let a of mr(n,r))yr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function dr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function ie(n){let e=n.predicate;return e instanceof k?e:void 0}function mr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof g),r=a=>{let s=h(a);o.set(s?u(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=u(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let c=h(i);c&&s.has(u(c))&&r(i)}}else for(let s of t)ne(s).some(c=>u(c)===a||ee(n.catalog,c).some(p=>u(p)===a))&&r(s)}for(let a of e.targetNodes){let s=K(n.catalog,a);s instanceof g&&r(s)}for(let a of e.targetSubjectsOf){let s=u(a);for(let i of t)i.statement.some(c=>{let p=ie(c);return p&&u(p.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=u(a);for(let i of t)for(let c of i.statement){let p=ie(c);if(!(!p||u(p.subject)!==s))for(let d of fr(c)){let S=K(n.catalog,d);S instanceof g&&r(S)}}}return[...o.values()]}function fr(n){return n instanceof G?[n.object.subject]:n instanceof q?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function kr(n,e,o){let t=[];for(let r of n.statement){let a=ie(r);if(!(!a||u(a.subject)!==e)){if(r instanceof fe||r instanceof ge)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof ke)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof ye)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof G)t.push({kernel:{ref:u(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof he)t.push(Wn(r.object,o,t.length));else if(r instanceof q){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:u(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof E)t.push(Wn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Wn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function yr(n,e,o,t){let r=h(o),a=r?u(r):`${o.namespace}/${o.name}`;for(let s of e.properties)gr(n,e,o,a,r,s,t);e.closed&&Er(e,o,a,r,t)}function _e(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??qn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function qn(n){return n.severity??"Violation"}var hr={minCount:gn,maxCount:Sn,in:Rn,pattern:En,minLength:Kn,maxLength:xn,minInclusive:wn,maxInclusive:vn};function gr(n,e,o,t,r,a,s){let i=u(a.path),c=kr(o,i,t),p=a.severity??qn(e),d=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:u(l)}))],b=(l,m,f)=>{s.push(_e(e,t,r,l,a.message??m,{resultPath:a.path,value:f?.literal,valueRef:f?.ref},p))};for(let l of ae(a)){let m=hr[l.component];if(l.per==="node"){zn(l,{[oe]:c.map(P=>P.kernel),[re]:S})||b(m,l.component==="minCount"?`'${d}' has ${c.length} value(s); minCount is ${a.minCount}.`:`'${d}' has ${c.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let f of c){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&f.kind!=="string"){b(m,`'${d}' value is not a string; ${l.component} applies to string values.`,f);continue}zn(l,{v:f.kernel,[re]:S})||b(m,Sr(l,d,a,f),f)}}if(a.nodeKind)for(let l of c)br(a.nodeKind,l)||b(Cn,`'${d}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of c){let m=Pr(a.datatype,l);m&&b(bn,`'${d}' ${m}`,l)}if(a.classRef)for(let l of c){let m=Rr(n,a.classRef,l);m&&b(Pn,`'${d}' ${m}`,l)}}function Sr(n,e,o,t){let r=t.ref?u(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function zn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new pr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return lr(n.expr,void 0,o)===1}function br(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function Pr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Ke(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function Rr(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=u(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`;let r=K(n.catalog,o.ref);return r instanceof g?ne(r).some(s=>u(s)===t||ee(n.catalog,s).some(i=>u(i)===t))?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`:`value ${u(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function Er(n,e,o,t,r){let a=new Set([...n.properties.map(i=>u(i.path)),...n.ignoredProperties.map(i=>u(i))]),s=new Set;for(let i of e.statement){let c=ie(i);if(!c)continue;let p=u(c.subject);a.has(p)||s.has(p)||(s.add(p),r.push(_e(n,o,t,Re,`'${e.name}' carries undeclared property '${c.subject.name}' (closed shape).`,{resultPath:c.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(_e(n,o,t,Re,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Ae from"js-yaml";import{VersionOperator as Xn}from"@kanonak-protocol/types/document/models/enums";var Kr="0.0.0",L=class{constructor(e,o=new j,t){this.repository=e;this.parser=o;this.objectParser=t??new A(this.parser)}repository;parser;objectParser;imports(){return new T}serializeValue(e,o){return Zn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Le(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Jn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Jn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Ae.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Yn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Ae.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new Q(a,this.repository))).filter(p=>p instanceof g&&p.namespace===s&&p.name!==Yn);for(let p of c)p.namespace="ephemeral";return we(c)}},Yn="__pkgbuilder_probe__";function Jn(n){return new TextEncoder().encode(n).length}function Le(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var T=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=Xn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let c=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,w(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Kr,r??o,Xn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:de(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=F(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Zn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Zn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof E)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(xr(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function F(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function xr(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var wr="1.1.0";async function Qn(n){let e=new L(n.repository),o=e.imports(),t=o.ensure(X,Y,wr,"sh"),r=(i,c)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,w(i.version),i.package_)}.${i.name}`:c,a={},s=[];return n.result.results.forEach((i,c)=>{let p=`result-${c+1}`;s.push(p);let d={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(d[`${t}.resultPath`]=r(i.resultPath,u(i.resultPath))),i.sourceShapeUri&&(d[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?d[`${t}.value`]=r(i.valueRef,u(i.valueRef)):i.value!==void 0&&(d[`${t}.value`]=i.value),a[p]=d}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as Ci}from"@kanonak-protocol/types/document/models/enums";var se=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${w(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=Se(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var je={async authorize(){return{allowed:!0}}},Ve={async record(){}},B=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ce=class{inner;ctx;policy;meter;constructor(e,o,t=je,r=Ve){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new B(e,o.reason)}};var R="kanonak.org",C="view",et="core-kanonak",vr={publisher:R,package_:C,name:"rootView"},Cr={publisher:R,package_:C,name:"bind"},Ir={publisher:R,package_:C,name:"produces"},_r={publisher:R,package_:C,name:"projections"},Ar={publisher:R,package_:C,name:"where"},Lr={publisher:R,package_:C,name:"value"},jr={publisher:R,package_:C,name:"as"},ue=class{constructor(e,o=new j){this.repository=e;this.parser=o;this.objectParser=new A(this.parser),this.builder=new L(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=y(r,Cr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=y(r,Ir);if(!s)throw new Error(`View ${r.namespace}/${r.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Vr(r),c=nt(t,R,et),p=nt(t,R,C),d=this.builder.imports(),S=d.ensure(R,et,c,"ck"),b=d.ensure(R,C,p,"v"),l=d.ref(s),m=new jn(this.repository,this.parser,this.objectParser),f=new Ln(m,t),P=this.readProjections(t,r),N=$r(r,Ar),O=this.findInstances(t,a,await this.reason(o)),Ne={},ot=new Set;for(let W of O){if(!await this.passesWhere(f,t,N,W))continue;let pe={type:l};for(let $e of P){let rt=await this.evaluateValue(f,t,$e.value,W),Ue=this.builder.serializeValue(tt(rt),d);Ue!==void 0&&(pe[d.ref($e.as)]=Ue)}let Oe=h(W);Oe&&(pe[`${b}.derivedFrom`]=d.ref(Oe)),Ne[this.rowName(W,ot)]=pe}let le={};o.resolvedAt&&(le[`${S}.resolvedAt`]=o.resolvedAt),o.invocationId&&(le[`${S}.id`]=o.invocationId);let U=await this.builder.buildContentAddressed({publisher:i,book:d,body:Ne,contentHashProperty:`${S}.contentHash`,header:le});return{yaml:U.yaml,contentHash:U.contentHash,packageName:U.packageName,publisher:U.publisher,rowCount:U.resourceCount}}resolveView(e,o){let t=K(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=y(t,vr);if(r){let a=K(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of _(o,_r)){let a=r instanceof E?r:r instanceof k?K(e,r.subject):void 0;if(!a)continue;let s=Ee(a,Lr),i=y(a,jr);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new H({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Or(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let c=r.get(i);c&&a.push(c)}return a.sort((i,c)=>{let p=M(h(i)),d=M(h(c));return p<d?-1:p>d?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Ur(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=An(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=F(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function tt(n){return xe(n)?n.value:Array.isArray(n)?n.map(tt):n}function Vr(n){let e=h(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function nt(n,e,o){let t=Nr(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Nr(n,e,o){let t;for(let r of n){if(!(r instanceof g))continue;let a=h(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?w(t):void 0}function Or(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof g))continue;let r=h(t);if(!r||!r.version)continue;let a=M(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function $r(n,e){let o=Ee(n,e);return o?[o]:_(n,e).filter(t=>t instanceof E)}function Ur(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:xe(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{_o as AmbiguousReferenceRule,ye as BooleanStatement,Jo as CANONICAL_FORM_VERSION,V as Carrier,Oo as ClassDefinitionRule,Eo as ClassHierarchyCycleRule,kt as CompositeKanonakDocumentRepository,Qo as DEFAULT_CONSENT_BINDING_PARAM,jt as DefinedKanonak,qo as DiamondNameClashRule,Uo as DisplayLensScopeRule,ft as DocumentLocation,Yt as EdgeType,E as EmbeddedKanonak,bo as EmbeddedKanonakTypeRule,he as EmbeddedStatement,B as EntitlementDeniedError,ce as EntitlementProducer,mt as FileSystemKanonakDocumentRepository,to as GitIgnoreFilter,Jt as GraphBuilder,vt as HttpKanonakDocumentRepository,De as INTEGRITY_PREFIX,T as ImportBook,Po as ImportExistenceRule,me as InMemoryKanonakDocumentRepository,gt as KANONAK_USER_AGENT,Lt as Kanonak,ro as KanonakDocumentPositions,A as KanonakObjectParser,Xo as KanonakObjectValidator,j as KanonakParser,Vt as KanonakUri,so as KanonakUriBuilder,co as KanonakUrlResolver,Ft as KanonakVocabulary,q as ListStatement,D as LiteralKanonak,Ct as LocalFirstRepository,It as LockAwareRepository,Ho as LookBandPathRule,Fo as LookRenderer,Do as LookSemanticSvgPathRule,$o as MarkdownLinkRule,ge as MarkdownStatement,Co as NamespaceImportCycleRule,ko as NamespacePrefixRule,Xt as NodeType,ke as NumberStatement,er as OAuthDiscovery,eo as OWL_RL_CLASSIFICATION_RULES,Lo as ObjectPropertyValueValidationRule,po as OntologyValidationError,uo as OntologyValidationResult,Go as OwlOneOfRule,L as PackageBuilder,So as PackageHeaderRule,se as ProducerRepository,jo as PropertyDomainRule,Ko as PropertyHierarchyCycleRule,Vo as PropertyKindRangeConsistencyRule,oo as PropertyMetadata,Ao as PropertyRangeReferenceRule,xo as PropertyRangeRequiredRule,ho as PropertyTypeSpecificityRule,Kt as PublisherConfigResolver,xt as PublisherIndex,Qt as RDFS_RULES,H as Reasoner,no as ReasoningResult,k as ReferenceKanonak,G as ReferenceStatement,ht as RepositoryFactory,No as ReservedNameShadowRule,yo as ResourceNamingRule,$t as ResourceResolver,Bt as ResourceTypeClassifier,Y as SHACL_PACKAGE,X as SHACL_PUBLISHER,J as SH_NODE_SHAPE,Be as SH_PROPERTY_SHAPE,Fe as SH_SHAPE,Ot as ScalarStatement,zo as ShaclShapeRule,Nt as Statement,fe as StringStatement,wo as SubClassOfReferenceRule,vo as SubPropertyOfReferenceRule,g as SubjectKanonak,go as SubjectKanonakTypeRequiredRule,or as TokenCredentialProvider,Zt as TripleStore,Mo as TxExpressionCompilesRule,Wo as TxExpressionPathRule,Ut as TypeResolver,Io as UnresolvedPredicateRule,Ro as UnresolvedReferenceRule,fo as ValidationCache,mo as ValidationContext,lo as ValidationSeverity,Ci as VersionOperator,ue as ViewMaterializer,je as allowAllPolicy,Pt as assertHttpsUrl,wt as assertPackageIdentity,At as buildLocalFirstRepository,ar as buildOntologyModel,Qn as buildReportPackageAsync,te as buildShapesModel,Yo as canonicalForm,we as canonicalHash,Ke as carrierOf,_t as collectKanonakFiles,z as compareVersions,On as computeIntegrity,Te as computeIntegrityAsync,Le as contentAddressedName,ne as contextTypesOf,tr as createCredentialedFetch,st as createVersion,Gn as evaluateConformance,qt as extractMarkdownLinks,rr as findDerivation,Gt as findMalformedReferences,io as findMarkdownLinkAt,Ie as foldFlagsIntoPattern,Dt as formatKanonakAddress,w as formatVersion,yt as getGlobalCachePath,bt as getKanonakUserAgent,ut as isCompatibleVersion,lt as isMajorCompatible,Rt as kanonakFetch,Vn as loadLockFile,ae as lowerConstraint,Mt as makeUriKey,Ve as noopMeter,Zo as normalizeHost,nr as parseAuthChallenge,Se as parseKanonakAddress,Me as parseLockFile,ct as parseVersionString,ao as parseWithPositions,dt as pickHighestDocument,Wt as propertiesInScope,To as resolveDisplayValue,zt as resolvePropertyStep,F as sanitizeName,pt as satisfiesVersionOperator,Nn as saveLockFile,Un as scopeFromCatalog,Dn as scopeFromDocumentAsync,$n as scopeFromRepositoryAsync,He as serializeLockFile,Et as setKanonakFetchRetries,St as setKanonakUserAgent,h as subjectUri,ee as superClassChain,Bo as supportedBandKeys,Ht as tripleKey,M as uriKey,Tt as uriTriple,at as versionOperatorFromChar,de as versionOperatorToChar,it as versionsEqual};
|
|
1
|
+
import{a as Zt,b as Qt,c as eo,d as no,e as H}from"./chunk-4SMQ7G23.js";import{a as Vn,b as Nn,c as On}from"./chunk-D66LUZDB.js";import{a as Xt,b as Yt,c as Jt,d as nr,e as we,f as tr,g as or,h as rr,i as ar,j as ir,k as sr,l as cr}from"./chunk-ZRCJGTEV.js";import{a as ur}from"./chunk-GMK4YL3X.js";import{a as mt,b as ft,c as kt,d as yt,e as ht,f as vt,g as It,h as _t,i as Lt}from"./chunk-JFBPQN6T.js";import{a as gt,b as St,c as bt,d as Pt,e as Rt,f as Et,h as Kt,i as De,j as Me,k as He,l as Te,m as xt,n as Ct}from"./chunk-P5VQEDBS.js";import{a as oo,b as ro,c as ao,d as io}from"./chunk-HBG6SC5L.js";import{a as so}from"./chunk-PEB52US5.js";import{a as wt}from"./chunk-SC5M74NM.js";import{A as Oo,B as $o,C as Uo,D as Do,E as Mo,F as qo,G as Xo,H as Yo,I as Jo,J as Zo,K as Qo,L as er,a as uo,b as lo,c as po,d as mo,e as fo,f as ko,g as yo,h as ho,i as go,j as So,k as bo,l as Po,m as Ro,n as Eo,o as Ko,p as xo,q as wo,r as Co,s as vo,t as Io,u as _o,v as Lo,w as Ao,x as jo,y as Vo,z as No}from"./chunk-3DWEBQSD.js";import"./chunk-BRCVOR7A.js";import{c as Ln,d as Ho,e as To,g as Fo,h as Bo,k as Wo,m as xe,o as An,p as jn,r as zo,s as Go}from"./chunk-ANJAHB4N.js";import{a as me}from"./chunk-6VIUXP4N.js";import{a as E,b as D,c as ge,i as V,j as Ke,k as Gt,l as qt,m as L}from"./chunk-F3SGXIDP.js";import{a as j}from"./chunk-KOWDHKBN.js";import{a as co}from"./chunk-PEJALHXK.js";import{$ as Re,A as tn,B as on,C as rn,D as an,E as sn,F as cn,G as un,H as ln,I as pn,J as dn,K as mn,L as fn,M as Pe,N as kn,O as yn,P as hn,Q as gn,R as Sn,S as bn,T as Pn,U as Rn,V as En,W as Kn,X as xn,Y as wn,Z as Cn,_ as vn,a as $t,b as Ut,c as Se,d as Dt,da as Ft,e as M,f as Mt,fa as Bt,g as Ht,ga as h,ha as ee,i as Tt,j as X,k as Y,l as Fe,m as J,ma as Wt,n as Be,na as zt,o as We,oa as ne,p as ze,q as Ge,r as qe,s as Xe,t as Ye,u as Je,v as be,w as Ze,x as Qe,y as en,z as nn}from"./chunk-G3GKOJ5E.js";import{A as Ee,B as _,C as Q,a as At,b as jt,c as g,d as k,e as Nt,f as Ot,g as fe,h as ke,i as ye,j as G,k as he,l as q,m as u,r as In,t as K,w as _n,x as I,y as Z,z as y}from"./chunk-CJMVIOZX.js";import{a as Vt}from"./chunk-FUUTGGJS.js";import{a as at,b as de,c as z,d as it,e as w,f as st,g as ct,h as ut,i as lt,j as pt,k as dt}from"./chunk-QILEJIFU.js";import{a as to}from"./chunk-ODIECDN7.js";async function $n(n){let e=await new L().parseKanonaks(n),o=await new H().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Un(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Dn(n,e){let o=e??new me(new j);return{kind:"standalone",catalog:await new L().parseKanonaks(new Q(n,o))}}function $(n){return typeof n=="number"?n:void 0}function lr(n){if(!n)return;let e=u(n);if(e===u(dn))return"IRI";if(e===u(mn))return"BlankNode";if(e===u(fn))return"Literal"}function Mn(n){if(!n)return;let e=u(n);if(e===u(kn))return"Violation";if(e===u(yn))return"Warning";if(e===u(hn))return"Info"}function Ce(n,e){let o=y(n,e);if(o)return[o];let t=[];for(let r of _(n,e))r instanceof k&&t.push(r.subject);return t}function pr(n,e){let o=y(n,Ge);if(!o)return;let t={path:o},r=$(I(n,qe)),a=$(I(n,Xe));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=$(I(n,en)),i=$(I(n,nn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let c=$(I(n,tn)),p=$(I(n,on));c!==void 0&&(t.minInclusive=c),p!==void 0&&(t.maxInclusive=p);let d=Z(n,Ze);if(d!==void 0){let P=Z(n,Qe);t.pattern=P!==void 0?{regex:d,flags:P}:{regex:d}}if(_n(n,be)){let P=[],N=[];for(let O of _(n,be))O instanceof D?P.push(O.value):O instanceof k&&N.push(O.subject);P.length>0&&(t.inValues=P),N.length>0&&(t.inRefs=N)}let S=y(n,Ye);S&&(t.datatype=S);let b=y(n,Je);b&&(t.classRef=b);let l=lr(y(n,pn));l&&(t.nodeKind=l);let m=Z(n,rn);m!==void 0&&(t.message=m);let f=Mn(y(n,Pe))??e;return f&&(t.severity=f),t}function te(n){let e=[];for(let o of n){if(!(o instanceof g)||!In(o,J))continue;let t=Mn(y(o,Pe)),r={name:o.name,uri:h(o),targetClass:y(o,We),targetNodes:Ce(o,an),targetSubjectsOf:Ce(o,sn),targetObjectsOf:Ce(o,cn),closed:I(o,un)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of _(o,ln))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of _(o,ze)){let s;if(a instanceof E?s=a:a instanceof k&&(s=K(n,a.subject)),!s)continue;let i=pr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var x="kanonak.org/transformations",oe="values";var re="allowed",C=n=>({type:`${x}/VarRef`,varName:n}),ve=n=>({type:`${x}/IntegerLiteral`,integerLiteral:n}),dr=n=>({type:`${x}/DecimalLiteral`,decimalLiteral:n}),Hn=n=>Number.isInteger(n)?ve(n):dr(n),Tn=n=>({type:`${x}/Count`,source:n}),Fn=(n,e)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Bn=(n,e)=>({type:`${x}/LessThanOrEqual`,compareLeft:n,compareRight:e});function Ie(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function ae(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Fn(Tn(C(oe)),ve(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Bn(Tn(C(oe)),ve(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:C(re),needle:C("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:Ie(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Fn(C("v"),Hn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Bn(C("v"),Hn(n.maxInclusive))}),e}import{evaluate as fr,ExpressionError as kr}from"@kanonak-protocol/expression";function Gn(n,e){let o=yr(e)?e:te(e),t=[];for(let r of o)for(let a of hr(n,r))br(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function yr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function ie(n){let e=n.predicate;return e instanceof k?e:void 0}function hr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof g),r=a=>{let s=h(a);o.set(s?u(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=u(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let c=h(i);c&&s.has(u(c))&&r(i)}}else for(let s of t)ne(s).some(c=>u(c)===a||ee(n.catalog,c).some(p=>u(p)===a))&&r(s)}for(let a of e.targetNodes){let s=K(n.catalog,a);s instanceof g&&r(s)}for(let a of e.targetSubjectsOf){let s=u(a);for(let i of t)i.statement.some(c=>{let p=ie(c);return p&&u(p.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=u(a);for(let i of t)for(let c of i.statement){let p=ie(c);if(!(!p||u(p.subject)!==s))for(let d of gr(c)){let S=K(n.catalog,d);S instanceof g&&r(S)}}}return[...o.values()]}function gr(n){return n instanceof G?[n.object.subject]:n instanceof q?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function Sr(n,e,o){let t=[];for(let r of n.statement){let a=ie(r);if(!(!a||u(a.subject)!==e)){if(r instanceof fe||r instanceof ge)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof ke)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof ye)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof G)t.push({kernel:{ref:u(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof he)t.push(Wn(r.object,o,t.length));else if(r instanceof q){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:u(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof E)t.push(Wn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Wn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function br(n,e,o,t){let r=h(o),a=r?u(r):`${o.namespace}/${o.name}`;for(let s of e.properties)Rr(n,e,o,a,r,s,t);e.closed&&Cr(e,o,a,r,t)}function _e(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??qn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function qn(n){return n.severity??"Violation"}var Pr={minCount:gn,maxCount:Sn,in:Rn,pattern:En,minLength:Kn,maxLength:xn,minInclusive:wn,maxInclusive:Cn};function Rr(n,e,o,t,r,a,s){let i=u(a.path),c=Sr(o,i,t),p=a.severity??qn(e),d=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:u(l)}))],b=(l,m,f)=>{s.push(_e(e,t,r,l,a.message??m,{resultPath:a.path,value:f?.literal,valueRef:f?.ref},p))};for(let l of ae(a)){let m=Pr[l.component];if(l.per==="node"){zn(l,{[oe]:c.map(P=>P.kernel),[re]:S})||b(m,l.component==="minCount"?`'${d}' has ${c.length} value(s); minCount is ${a.minCount}.`:`'${d}' has ${c.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let f of c){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&f.kind!=="string"){b(m,`'${d}' value is not a string; ${l.component} applies to string values.`,f);continue}zn(l,{v:f.kernel,[re]:S})||b(m,Er(l,d,a,f),f)}}if(a.nodeKind)for(let l of c)Kr(a.nodeKind,l)||b(vn,`'${d}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of c){let m=xr(a.datatype,l);m&&b(bn,`'${d}' ${m}`,l)}if(a.classRef)for(let l of c){let m=wr(n,a.classRef,l);m&&b(Pn,`'${d}' ${m}`,l)}}function Er(n,e,o,t){let r=t.ref?u(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function zn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new kr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return fr(n.expr,void 0,o)===1}function Kr(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function xr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Ke(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function wr(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=u(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`;let r=K(n.catalog,o.ref);return r instanceof g?ne(r).some(s=>u(s)===t||ee(n.catalog,s).some(i=>u(i)===t))?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`:`value ${u(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function Cr(n,e,o,t,r){let a=new Set([...n.properties.map(i=>u(i.path)),...n.ignoredProperties.map(i=>u(i))]),s=new Set;for(let i of e.statement){let c=ie(i);if(!c)continue;let p=u(c.subject);a.has(p)||s.has(p)||(s.add(p),r.push(_e(n,o,t,Re,`'${e.name}' carries undeclared property '${c.subject.name}' (closed shape).`,{resultPath:c.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(_e(n,o,t,Re,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Le from"js-yaml";import{VersionOperator as Xn}from"@kanonak-protocol/types/document/models/enums";var vr="0.0.0",A=class{constructor(e,o=new j,t){this.repository=e;this.parser=o;this.objectParser=t??new L(this.parser)}repository;parser;objectParser;imports(){return new T}serializeValue(e,o){return Zn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Ae(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Jn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Jn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Le.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Yn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Le.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new Q(a,this.repository))).filter(p=>p instanceof g&&p.namespace===s&&p.name!==Yn);for(let p of c)p.namespace="ephemeral";return we(c)}},Yn="__pkgbuilder_probe__";function Jn(n){return new TextEncoder().encode(n).length}function Ae(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var T=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=Xn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let c=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,w(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,vr,r??o,Xn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:de(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=F(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Zn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Zn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof E)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(Ir(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function F(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Ir(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var _r="1.1.0";async function Qn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(X,Y,_r,"sh"),r=(i,c)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,w(i.version),i.package_)}.${i.name}`:c,a={},s=[];return n.result.results.forEach((i,c)=>{let p=`result-${c+1}`;s.push(p);let d={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(d[`${t}.resultPath`]=r(i.resultPath,u(i.resultPath))),i.sourceShapeUri&&(d[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?d[`${t}.value`]=r(i.valueRef,u(i.valueRef)):i.value!==void 0&&(d[`${t}.value`]=i.value),a[p]=d}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as Ai}from"@kanonak-protocol/types/document/models/enums";var se=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${w(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=Se(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var je={async authorize(){return{allowed:!0}}},Ve={async record(){}},B=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ce=class{inner;ctx;policy;meter;constructor(e,o,t=je,r=Ve){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new B(e,o.reason)}};var R="kanonak.org",v="view",et="core-kanonak",Lr={publisher:R,package_:v,name:"rootView"},Ar={publisher:R,package_:v,name:"bind"},jr={publisher:R,package_:v,name:"produces"},Vr={publisher:R,package_:v,name:"projections"},Nr={publisher:R,package_:v,name:"where"},Or={publisher:R,package_:v,name:"value"},$r={publisher:R,package_:v,name:"as"},ue=class{constructor(e,o=new j){this.repository=e;this.parser=o;this.objectParser=new L(this.parser),this.builder=new A(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=y(r,Ar);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=y(r,jr);if(!s)throw new Error(`View ${r.namespace}/${r.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Ur(r),c=nt(t,R,et),p=nt(t,R,v),d=this.builder.imports(),S=d.ensure(R,et,c,"ck"),b=d.ensure(R,v,p,"v"),l=d.ref(s),m=new jn(this.repository,this.parser,this.objectParser),f=new An(m,t),P=this.readProjections(t,r),N=Hr(r,Nr),O=this.findInstances(t,a,await this.reason(o)),Ne={},ot=new Set;for(let W of O){if(!await this.passesWhere(f,t,N,W))continue;let pe={type:l};for(let $e of P){let rt=await this.evaluateValue(f,t,$e.value,W),Ue=this.builder.serializeValue(tt(rt),d);Ue!==void 0&&(pe[d.ref($e.as)]=Ue)}let Oe=h(W);Oe&&(pe[`${b}.derivedFrom`]=d.ref(Oe)),Ne[this.rowName(W,ot)]=pe}let le={};o.resolvedAt&&(le[`${S}.resolvedAt`]=o.resolvedAt),o.invocationId&&(le[`${S}.id`]=o.invocationId);let U=await this.builder.buildContentAddressed({publisher:i,book:d,body:Ne,contentHashProperty:`${S}.contentHash`,header:le});return{yaml:U.yaml,contentHash:U.contentHash,packageName:U.packageName,publisher:U.publisher,rowCount:U.resourceCount}}resolveView(e,o){let t=K(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=y(t,Lr);if(r){let a=K(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of _(o,Vr)){let a=r instanceof E?r:r instanceof k?K(e,r.subject):void 0;if(!a)continue;let s=Ee(a,Or),i=y(a,$r);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new H({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Mr(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let c=r.get(i);c&&a.push(c)}return a.sort((i,c)=>{let p=M(h(i)),d=M(h(c));return p<d?-1:p>d?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Tr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=Ln(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=F(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function tt(n){return xe(n)?n.value:Array.isArray(n)?n.map(tt):n}function Ur(n){let e=h(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function nt(n,e,o){let t=Dr(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Dr(n,e,o){let t;for(let r of n){if(!(r instanceof g))continue;let a=h(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?w(t):void 0}function Mr(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof g))continue;let r=h(t);if(!r||!r.version)continue;let a=M(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Hr(n,e){let o=Ee(n,e);return o?[o]:_(n,e).filter(t=>t instanceof E)}function Tr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:xe(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{_o as AmbiguousReferenceRule,ye as BooleanStatement,tr as CANONICAL_FORM_VERSION,V as Carrier,Oo as ClassDefinitionRule,Eo as ClassHierarchyCycleRule,kt as CompositeKanonakDocumentRepository,rr as DEFAULT_CONSENT_BINDING_PARAM,jt as DefinedKanonak,Qo as DiamondNameClashRule,Uo as DisplayLensScopeRule,ft as DocumentLocation,Yt as EdgeType,E as EmbeddedKanonak,bo as EmbeddedKanonakTypeRule,he as EmbeddedStatement,B as EntitlementDeniedError,ce as EntitlementProducer,mt as FileSystemKanonakDocumentRepository,to as GitIgnoreFilter,Jt as GraphBuilder,Ct as HttpKanonakDocumentRepository,De as INTEGRITY_PREFIX,T as ImportBook,Po as ImportExistenceRule,me as InMemoryKanonakDocumentRepository,gt as KANONAK_USER_AGENT,At as Kanonak,ro as KanonakDocumentPositions,L as KanonakObjectParser,er as KanonakObjectValidator,j as KanonakParser,Vt as KanonakUri,so as KanonakUriBuilder,co as KanonakUrlResolver,Ft as KanonakVocabulary,To as LINE_STYLES,q as ListStatement,D as LiteralKanonak,vt as LocalFirstRepository,It as LockAwareRepository,Xo as LookBandPathRule,zo as LookRenderer,Do as LookSemanticSvgPathRule,$o as MarkdownLinkRule,ge as MarkdownStatement,vo as NamespaceImportCycleRule,ko as NamespacePrefixRule,Xt as NodeType,ke as NumberStatement,ar as OAuthDiscovery,eo as OWL_RL_CLASSIFICATION_RULES,Ao as ObjectPropertyValueValidationRule,po as OntologyValidationError,uo as OntologyValidationResult,Zo as OwlOneOfRule,A as PackageBuilder,So as PackageHeaderRule,se as ProducerRepository,jo as PropertyDomainRule,Ko as PropertyHierarchyCycleRule,Vo as PropertyKindRangeConsistencyRule,oo as PropertyMetadata,Lo as PropertyRangeReferenceRule,xo as PropertyRangeRequiredRule,ho as PropertyTypeSpecificityRule,Kt as PublisherConfigResolver,xt as PublisherIndex,Qt as RDFS_RULES,H as Reasoner,no as ReasoningResult,k as ReferenceKanonak,G as ReferenceStatement,ht as RepositoryFactory,No as ReservedNameShadowRule,yo as ResourceNamingRule,$t as ResourceResolver,Bt as ResourceTypeClassifier,Y as SHACL_PACKAGE,X as SHACL_PUBLISHER,J as SH_NODE_SHAPE,Be as SH_PROPERTY_SHAPE,Fe as SH_SHAPE,Ot as ScalarStatement,qo as SequenceNarrativeRule,Jo as ShaclShapeRule,Nt as Statement,fe as StringStatement,wo as SubClassOfReferenceRule,Co as SubPropertyOfReferenceRule,g as SubjectKanonak,go as SubjectKanonakTypeRequiredRule,cr as TokenCredentialProvider,Zt as TripleStore,Mo as TxExpressionCompilesRule,Yo as TxExpressionPathRule,Ut as TypeResolver,Io as UnresolvedPredicateRule,Ro as UnresolvedReferenceRule,fo as ValidationCache,mo as ValidationContext,lo as ValidationSeverity,Ai as VersionOperator,ue as ViewMaterializer,je as allowAllPolicy,Pt as assertHttpsUrl,wt as assertPackageIdentity,Lt as buildLocalFirstRepository,Wo as buildOntologyModel,Qn as buildReportPackageAsync,te as buildShapesModel,nr as canonicalForm,we as canonicalHash,Ke as carrierOf,_t as collectKanonakFiles,z as compareVersions,On as computeIntegrity,Te as computeIntegrityAsync,Ae as contentAddressedName,ne as contextTypesOf,sr as createCredentialedFetch,st as createVersion,Gn as evaluateConformance,qt as extractMarkdownLinks,ur as findDerivation,Gt as findMalformedReferences,io as findMarkdownLinkAt,Ie as foldFlagsIntoPattern,Dt as formatKanonakAddress,w as formatVersion,yt as getGlobalCachePath,bt as getKanonakUserAgent,ut as isCompatibleVersion,lt as isMajorCompatible,Rt as kanonakFetch,Vn as loadLockFile,ae as lowerConstraint,Mt as makeUriKey,Ve as noopMeter,or as normalizeHost,ir as parseAuthChallenge,Se as parseKanonakAddress,Me as parseLockFile,ct as parseVersionString,ao as parseWithPositions,dt as pickHighestDocument,Wt as propertiesInScope,Fo as readSequenceConnectors,Ho as resolveDisplayValue,zt as resolvePropertyStep,F as sanitizeName,pt as satisfiesVersionOperator,Nn as saveLockFile,Un as scopeFromCatalog,Dn as scopeFromDocumentAsync,$n as scopeFromRepositoryAsync,He as serializeLockFile,Et as setKanonakFetchRetries,St as setKanonakUserAgent,h as subjectUri,ee as superClassChain,Go as supportedBandKeys,Ht as tripleKey,M as uriKey,Tt as uriTriple,at as versionOperatorFromChar,de as versionOperatorToChar,it as versionsEqual,Bo as walkSequence};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Kanonak } from '../kanonaks/Kanonak.js';
|
|
1
2
|
import { KanonakUri } from '../resolution/KanonakUri.js';
|
|
3
|
+
import { type ShaclConstraintIndex } from './ShaclConstraints.js';
|
|
2
4
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
3
5
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
4
6
|
/** A reference to a class, by its durable canonical identity. */
|
|
@@ -106,6 +108,15 @@ export interface BuildOntologyModelOptions {
|
|
|
106
108
|
/** Flatten inherited properties (from ancestors + rdfs.Resource) into each class. */
|
|
107
109
|
includeInherited?: boolean;
|
|
108
110
|
}
|
|
111
|
+
/** Properties scoped to a class, resolved to durable schema definitions. */
|
|
112
|
+
/**
|
|
113
|
+
* The resolved, constraint-enriched property set of one class, from a parsed
|
|
114
|
+
* catalog. The catalog-scoped core that {@link buildOntologyModel} maps over a
|
|
115
|
+
* document's classes — exported so a renderer holding a catalog (the look
|
|
116
|
+
* layer's EntityRelationship band) draws the same model a generator consumes,
|
|
117
|
+
* rather than re-deriving property kind, range, and cardinality on its own.
|
|
118
|
+
*/
|
|
119
|
+
export declare function propertiesFor(catalog: Kanonak[], classUri: KanonakUri, includeInherited: boolean, shacl: ShaclConstraintIndex): PropertyDef[];
|
|
109
120
|
/**
|
|
110
121
|
* Build the resolved type-model of an ontology package.
|
|
111
122
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { buildOntologyModel } from './OntologyModel.js';
|
|
1
|
+
export { buildOntologyModel, propertiesFor } from './OntologyModel.js';
|
|
2
2
|
export type { OntologyModel, ClassDef, PropertyDef, ClassRef, TypeRef, EnumDef, EnumMember, BuildOntologyModelOptions, } from './OntologyModel.js';
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* stylesheet format; TransformationEngine integration.
|
|
22
22
|
*/
|
|
23
23
|
import { SubjectKanonak, EmbeddedKanonak, type Kanonak } from '../kanonaks/index.js';
|
|
24
|
+
/** nodeTier → the pixel size at which a node's responsive SemanticSvg shows that tier. */
|
|
25
|
+
export declare const DIAGRAM_TIER_SIZE: Record<string, number>;
|
|
24
26
|
type Uri = {
|
|
25
27
|
publisher: string;
|
|
26
28
|
package_: string;
|
|
@@ -593,6 +595,41 @@ export declare class LookRenderer {
|
|
|
593
595
|
*/
|
|
594
596
|
private renderDiagramDag;
|
|
595
597
|
/** One node tile: its identity SVG as an `<image>`, linked, with a title. */
|
|
598
|
+
/** One message in a Sequence, after the prose walk. */
|
|
599
|
+
private static readonly SEQ_COL_GAP;
|
|
600
|
+
private static readonly SEQ_ROW;
|
|
601
|
+
private static readonly SEQ_PAD;
|
|
602
|
+
/** Resolve a URI to its subject, version-agnostically (highest first). */
|
|
603
|
+
private subjectFor;
|
|
604
|
+
/**
|
|
605
|
+
* Render a Sequence band. See the band's own comment in look@2.4.0 for the
|
|
606
|
+
* authoring contract. The walk itself — prose order, graph edges, connector
|
|
607
|
+
* overlay — is `walkSequence` in sequenceWalk.ts, shared with the
|
|
608
|
+
* SequenceNarrativeRule so validate-time findings and the drawing agree.
|
|
609
|
+
* What the walk cannot draw is reported here as HTML comments, so a page
|
|
610
|
+
* never silently shows less than the prose says.
|
|
611
|
+
*
|
|
612
|
+
* Layout is deterministic and DOM-free: identity tiles across the top,
|
|
613
|
+
* dashed lifelines, one row per message at a fixed pitch.
|
|
614
|
+
*/
|
|
615
|
+
private renderSequence;
|
|
616
|
+
private static readonly ER_BOX_W;
|
|
617
|
+
private static readonly ER_HEAD_H;
|
|
618
|
+
private static readonly ER_ROW_H;
|
|
619
|
+
private static readonly ER_GAP;
|
|
620
|
+
private static readonly ER_PAD;
|
|
621
|
+
/** Classes in scope for an ER band: a Package page → every class it declares; a Class page → it plus the classes its object properties reach. */
|
|
622
|
+
private erScope;
|
|
623
|
+
/**
|
|
624
|
+
* Crow's-foot cardinality glyph at the range end of a relationship, from
|
|
625
|
+
* the constraints the closure states: min 0 → ring, min ≥1 → bar;
|
|
626
|
+
* max 1 → bar, unbounded → crow's foot. `owl.FunctionalProperty` reads as
|
|
627
|
+
* max 1 without SHACL. Drawn pointing along the line into the box.
|
|
628
|
+
*/
|
|
629
|
+
private erCardinalityGlyph;
|
|
630
|
+
/** Where a line from (fx,fy) toward the centre of a box exits that box's border. */
|
|
631
|
+
private erBorderPoint;
|
|
632
|
+
private renderEntityRelationship;
|
|
596
633
|
private diagramTile;
|
|
597
634
|
/**
|
|
598
635
|
* Render a StatRow band — a strip of labeled stats. `look.stats` is a
|
|
@@ -18,10 +18,8 @@ export interface DisplayValue {
|
|
|
18
18
|
* off the instance; the label falls back to the instance's local name so
|
|
19
19
|
* it is never empty.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `uri-helpers`; relies on built-in URIs already canonicalized at parse
|
|
25
|
-
* time (see KanonakVocabulary.canonicalizeBuiltinUri).
|
|
21
|
+
* Built entirely on the canonical object-model helpers in `uri-helpers`;
|
|
22
|
+
* relies on built-in URIs already canonicalized at parse time (see
|
|
23
|
+
* KanonakVocabulary.canonicalizeBuiltinUri).
|
|
26
24
|
*/
|
|
27
25
|
export declare function resolveDisplayValue(catalog: Kanonak[], instance: SubjectKanonak): DisplayValue;
|
package/dist/look/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { LookRenderer, supportedBandKeys, type ResolvedLook, type TokenProvenance, type BaseStylesheetStatus, type StylesheetExplanation, } from './LookRenderer.js';
|
|
2
2
|
export { resolveDisplayValue, type DisplayValue } from './displayValue.js';
|
|
3
|
+
export { walkSequence, readSequenceSource, readSequenceConnectors, readSequenceParticipants, edgeStyleFor, hasPropertyCharacteristic, LINE_STYLES, type LineStyle, type SequenceWalk, type SequenceMessage, type SequenceGap, type SequenceConnector, } from './sequenceWalk.js';
|