@kanonak-protocol/sdk 5.29.0 → 5.30.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-7UYXTYXC.js +1 -0
- package/dist/{chunk-HBG6SC5L.js → chunk-BS7RRG7D.js} +1 -1
- package/dist/chunk-BZ3YTI3C.js +2 -0
- package/dist/chunk-CR5QY3LJ.js +68 -0
- package/dist/{chunk-4SMQ7G23.js → chunk-EVMSO7HJ.js} +1 -1
- package/dist/chunk-F67UH4FD.js +1 -0
- package/dist/chunk-HF5FJBS2.js +1 -0
- package/dist/{chunk-JFBPQN6T.js → chunk-IS3AQKB4.js} +1 -1
- package/dist/{chunk-ZRCJGTEV.js → chunk-J4ZD6IF6.js} +1 -1
- package/dist/chunk-KIBR3HAT.js +1 -0
- package/dist/{chunk-GMK4YL3X.js → chunk-L2J7WD7E.js} +1 -1
- package/dist/chunk-PVUBHIU2.js +1 -0
- package/dist/{chunk-D66LUZDB.js → chunk-V3DH67P3.js} +1 -1
- package/dist/{chunk-ANJAHB4N.js → chunk-Z5Y4MCW5.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parsing/KanonakObjectParser.d.ts +9 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/PublisherIndex.d.ts +13 -1
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/buildLocalFirstRepository.d.ts +1 -0
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/ResourceTypeClassifier.d.ts +9 -0
- package/dist/resolution/importMode.d.ts +26 -0
- package/dist/resolution/index.d.ts +1 -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/validation/KanonakObjectValidator.d.ts +5 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/LinkTargetRule.d.ts +42 -0
- package/dist/validation/rules/repository/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-3DWEBQSD.js +0 -68
- package/dist/chunk-BRCVOR7A.js +0 -1
- package/dist/chunk-F3SGXIDP.js +0 -1
- package/dist/chunk-G3GKOJ5E.js +0 -1
- package/dist/chunk-KOWDHKBN.js +0 -1
- package/dist/chunk-P5VQEDBS.js +0 -2
- /package/dist/{chunk-PEB52US5.js → chunk-XK24CN3C.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as X}from"./chunk-HF5FJBS2.js";import{a as J,aa as Z,b as Y,ba as _,ca as E,ia as ee}from"./chunk-7UYXTYXC.js";import{a as q,b as H,c as w,d as g,g as R,h as T,i as N,j as O,k as K,l as P,m as A,n as x,t as Q}from"./chunk-CJMVIOZX.js";import{a as I}from"./chunk-FUUTGGJS.js";import{b as G}from"./chunk-F67UH4FD.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends H{name};var j=class extends q{value;carrier;lexical};var L=class extends R{links=[]};var oe="kanonak.org",se="transformations",Re=3,e=m=>({publisher:oe,package_:se,name:m}),M={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),NumberFormat:e("NumberFormat"),numberSource:e("numberSource"),numberStyle:e("numberStyle"),fractionDigits:e("fractionDigits"),currencyCode:e("currencyCode"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as S,carrierOf as ie}from"@kanonak-protocol/canonical";function V(m){return ie(`${m.publisher}/${m.package_}/${m.name}`)}var ce=/\[\[([^\[\]\n]+)\]\]/g,pe=/\[\[/g,te=/```[\s\S]*?```|`[^`\n]*`/g;function me(m){let t=[];for(let n of m.matchAll(te))t.push([n.index,n.index+n[0].length]);return t}function De(m){if(!m||!m.includes("[["))return[];let t=me(m),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(B(m).map(s=>s.startOffset)),a=[];for(let s of m.matchAll(pe)){let o=s.index;if(n(o)||r.has(o))continue;let c=m.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function B(m){if(!m||!m.includes("[["))return[];let t=[];for(let a of m.matchAll(te))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of m.matchAll(ce)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),p=(c===-1?o:o.slice(0,c)).trim();if(p.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:p,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}import{VersionOperator as fe}from"@kanonak-protocol/types/document/models/enums";function re(m,t){for(let n of m)n instanceof w&&U(n,n.name,t)}function U(m,t,n){n({kanonak:m,path:t});for(let r of m.statement){let a=r.predicate?.subject?.name;if(r instanceof K)U(r.object,ne(t,a,r.object),n);else if(r instanceof P)for(let s=0;s<r.object.length;s++){let o=r.object[s];o instanceof b&&U(o,ne(t,a,o,s),n)}}}function ne(m,t,n,r){let a=`${m}.${t??"<embedded>"}`,s=n instanceof b?n.name:void 0;return s?`${a}.${s}`:r===void 0?a:`${a}[${r}]`}var ue={..._("range"),name:"range"};function de(m){let t=m.lastIndexOf(".");return t===-1?m:m.slice(t+1)}var ae=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new J(t),s=new Y(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let p of n){let i=p.metadata.namespace_?.toString();i&&a.set(i,p)}let s=[],o=new Set;re(t,({kanonak:p})=>{for(let i of p.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let p of s){let i=a.get(p.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(p.key,i);if(!u)continue;let d=A(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=ee(t,f);l&&(this.knownPropertyClasses.set(d,l),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[p,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(p,o,c);u.namespace=d.namespace,u.name=d.name,u.statement=[];let f=await this.parseStatements(i,o,n,r,a);u.statement.push(...f.statements),u.unresolvedPredicates=f.unresolved,F(u,c),s.push(u)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof w){let u=`${i.namespace}/${i.name}`,d=r.get(u);if(d){let f=a.get(u);for(let l of i.statement){let y=$(l);f.has(y)||(f.add(y),d.statement.push(l))}for(let l of i.unresolvedPredicates)d.unresolvedPredicates.some(y=>y.key===l.key&&y.sourceDoc===l.sourceDoc)||d.unresolvedPredicates.push(l)}else{let f=new w;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let l=new Set;for(let y of i.statement){let k=$(y);l.has(k)||(l.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(u,l),r.set(u,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof w){let u=i.namespace||"",d=u.indexOf("/"),f=d>=0?u.slice(0,d):"",l=d>=0?u.slice(d+1):"",y=l.indexOf("@"),k=y>=0?l.slice(0,y):l;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),p=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);p.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,p);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(E(s,n,r),a instanceof O)a.object instanceof g&&E(a.object.subject,n,r);else if(a instanceof K)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof P)for(let o of a.object??[])o instanceof g?E(o.subject,n,r):o instanceof b&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,p]of Object.entries(n.metadata.imports))for(let i of p)if((i.alias??i.packageName)===s){let d=i.version;return{namespace:`${c}/${i.packageName}@${d.major}.${d.minor}.${d.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let p=n.metadata.namespace_?.toString()??"";for(let[i,u]of Object.entries(t))try{let d=await this.getPropertyMetadata(i,n,r,s,a);if(!d){let l=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;Z(l)||c.push({key:i,sourceDoc:p});continue}let f=await this.parsePropertyValue(i,u,d,n,r,a,s);f&&o.push(f)}catch(d){throw new Error(`Failed to parse property '${i}': ${d.message}`,{cause:d})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,p=c.type?.toString()??"",i=p.includes(".")?p.substring(p.lastIndexOf(".")+1):p,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(A(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(p),l,y=async()=>{if(l)return l;if(!(o.isImported&&o.definedInNamespace))return l=n,n;if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let v=await a.getDocumentAsync(o.definedInNamespace);if(!v)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);return l=v,v},k=await this.readDefinitionSlot(c,ue,y,r),h=k==null?void 0:String(k),D;if(f==="ObjectProperty")D="ObjectProperty";else if(f==="DatatypeProperty")D="DatatypeProperty";else{let v=h&&h.includes(".")?h.substring(h.lastIndexOf(".")+1):h??"";(h?s.isKnownXsdDatatypeName(h):!1)||v==="Literal"?D="DatatypeProperty":D="ObjectProperty"}let z;return h&&(z=(await r.resolveEntityAsync(h,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:D,range:h,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>de(i)===n.name);if(s.length===0)return;let o=await r(),c=_(n.name),p=c!==void 0&&c.publisher===n.publisher&&c.package_===n.package_;for(let i of s){let u=await a.resolveEntityAsync(i,o);if(u){if(x(u.uri,n))return t[i];continue}if(!i.includes(".")&&p)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let p=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(p,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(p,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(p,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?V(r.rangeUri):void 0;if(s===S.Boolean){let c=new N;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===S.Integer||s===S.Decimal||s===S.Double||s===S.Float){let c=new T;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=R.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new j,a=n.rangeUri?V(n.rangeUri):void 0;return a===S.Boolean?r.value=t==="true"||t==="1":a===S.Integer||a===S.Decimal||a===S.Double||a===S.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new L;s.predicate=g.parse(t),s.object=n;for(let o of B(n)){let c=this.linkReference(o.reference,r);if(!c){let i=await a.resolveEntityAsync(o.reference,r);i&&(c=new g,c.subject=i.uri)}let p={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(p.displayText=o.displayText),c!==void 0&&(p.target=c),s.links.push(p)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&x(r.rangeUri,M.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let p=await this.resolveReference(n,a,s);if(!p)return;let i=new O;return i.predicate=g.parse(t),i.object=p,i}if(typeof n=="object"&&!Array.isArray(n)){let p=await this.parseStatements(n,a,s,o,c);if(p.statements.length>0){let d=new b;d.statement=p.statements,d.unresolvedPredicates=p.unresolved;let f=new K;return f.predicate=g.parse(t),f.object=d,f}let i=[];for(let[d,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let l=new b;l.name=d;let y=await this.parseStatements(f,a,s,o,c);l.statement=y.statements,l.unresolvedPredicates=y.unresolved,i.push(l)}else if(typeof f=="string"){let l=await this.resolveReference(f,a,s);l&&i.push(l)}if(i.length>0){let d=new P;return d.predicate=g.parse(t),d.object=i,d}let u=new K;return u.predicate=g.parse(t),u.object=new b,u}}coerceExpressionLiteral(t,n,r){let a=new b,s=new O,o=new g;o.subject=new I("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new I(r.publisher,r.package_,M.StringLiteral.name,r.version),s.object=c;let p=new R,i=new g;i.subject=new I(r.publisher,r.package_,M.stringLiteral.name,r.version),p.predicate=i,p.object=n,a.statement=[s,p];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let p=[],i=r.propertyType==="DatatypeProperty",u=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let f of n){let l=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&l){let y=typeof f=="string"?f:String(f);p.push(this.typedListLiteral(y,r));continue}if(u&&l){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,p.push(k)}else{let k=new j;k.value=f,p.push(k)}}else{let y=new j;y.value=f,p.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&p.push(y)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let y=new b,k=await this.parseStatements(f,a,s,o,c);y.statement=k.statements,y.unresolvedPredicates=k.unresolved,p.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=p,d}linkReference(t,n){let r=t.indexOf(".");if(r<=0||!n.metadata?.imports)return;let a=t.substring(0,r),s=t.substring(r+1);for(let[o,c]of Object.entries(n.metadata.imports))for(let p of c){if(!G(p)||(p.alias??p.packageName)!==a)continue;let i=new g,u=p.versionOperator===fe.Exact?p.version:void 0;return i.subject=new I(o,p.packageName,s,u),i}}async resolveReference(t,n,r){let a=this.linkReference(t,n);if(a)return a;let s=await r.resolveEntityAsync(t,n);if(s){let c=new g;return c.subject=s.uri,c}let o=n.metadata?.namespace_;if(o){let{KanonakUri:c}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let i=t.indexOf("."),u=t.substring(0,i),d=t.substring(i+1);if(n.metadata?.imports){for(let[f,l]of Object.entries(n.metadata.imports))for(let y of l)if((y.alias??y.packageName)===u){let h=new g;return h.subject=new c(f,y.packageName,d,y.version),h}}}let p=new g;return p.subject=new c(o.publisher,o.package_,t,o.version??void 0),p}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof w&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof w&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new X().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let p of o.statement){let[i,u]=this.convertStatementToProperty(p);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(p,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof R)return[t.predicate.subject.name,t.object];if(t instanceof T)return[t.predicate.subject.name,t.object];if(t instanceof N)return[t.predicate.subject.name,t.object];if(t instanceof O)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof P){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof K){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof b&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function F(m,t){m.sourceDoc=t;for(let n of m.statement)if(n instanceof K)F(n.object,t);else if(n instanceof P)for(let r of n.object)r instanceof b&&F(r,t)}function $(m){let t=m.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+le(m)}function le(m){return m instanceof L?"m:"+String(m.object):m instanceof R?"s:"+String(m.object):m instanceof T?"n:"+String(m.object):m instanceof N?"b:"+String(m.object):m instanceof O?"r:"+C(m.object):m instanceof K?"e:"+C(m.object):m instanceof P?"l:["+(m.object??[]).map(C).join("|")+"]":"x"}function C(m){if(!m)return"";if(m instanceof g){let t=m.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return m instanceof b?"E("+(m.statement??[]).map($).join(";")+")":m instanceof j?"L("+String(m.value)+")":"N"}export{b as a,j as b,L as c,re as d,oe as e,se as f,Re as g,M as h,S as i,V as j,De as k,B as l,ae as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i,j as o,k as r}from"./chunk-
|
|
1
|
+
import{i,j as o,k as r}from"./chunk-BZ3YTI3C.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ot}from"./chunk-6VIUXP4N.js";import{a as N,b as ln,c as Te,h as d,m as $n}from"./chunk-F3SGXIDP.js";import{a as it}from"./chunk-KOWDHKBN.js";import{a as gt}from"./chunk-PEJALHXK.js";import{fa as en,ga as _e,ha as nn,ia as vn,ma as mt}from"./chunk-G3GKOJ5E.js";import{A as ft,B as Pe,C as pt,b as Ce,c as Y,d as L,g as Q,h as ge,i as de,j as H,k as J,l as D,m as ne,n as ie,o as ct,p as lt,q as Fe,r as w,t as Be,u as le,v as ut,w as dt,x as We,y as xe,z as je}from"./chunk-CJMVIOZX.js";import{a as yn}from"./chunk-FUUTGGJS.js";import{c as hn,d as rt,e as bn,g as st}from"./chunk-QILEJIFU.js";var Z=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function fi(r,e){let n=r.name,t=La(e),a={catalog:e,depth:0};if(w(r,d.InstanceTransformation))return ya(r,n,a,t);if(w(r,d.SetTransformation))return va(r,n,a,t);throw new Z("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function ya(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:St(r,e),rule:Sn(r,d.rule,`${e}.rule`,n),artifactName:Sn(r,d.artifactName,`${e}.artifactName`,n),outputs:wt(r,`${e}.outputs`),overrides:jt(r,`${e}.formatOverrides`,n),fragments:t}}function va(r,e,n,t){let a=Me(r,d.partitionBy);return{kind:"set",name:r.name,inputPattern:St(r,e),rule:Sn(r,d.rule,`${e}.rule`,n),artifactName:Sn(r,d.artifactName,`${e}.artifactName`,n),outputs:wt(r,`${e}.outputs`),overrides:jt(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function St(r,e){let n=un(r,d.inputPattern);if(!n)throw new Z("inputPattern is required",e);return $a(n,`${e}.inputPattern`)}function $a(r,e){let n=Me(r,d.matchesClass);if(!n)throw new Z("matchesClass is required",e);let t=[];for(let o of we(r,d.requires))if(o instanceof H)t.push(Dn(o.object.subject));else if(o instanceof D)for(let i of o.object)i instanceof L&&t.push(Dn(i.subject));let a=[],s=0;for(let o of we(r,d.sortBy))if(o instanceof D)for(let i of o.object)i instanceof N&&a.push(kt(i,`${e}.sortBy[${s++}]`));else o instanceof J&&a.push(kt(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function kt(r,e){let n=Me(r,d.byProperty);if(!n)throw new Z("SortKey.byProperty is required",e);let t=Me(r,d.order);if(!t)throw new Z("SortKey.order is required",e);if(ie(t,d.ascending))return{byProperty:n,order:"ascending"};if(ie(t,d.descending))return{byProperty:n,order:"descending"};throw new Z(`SortKey.order must reference tx.ascending or tx.descending; got ${t.publisher}/${t.package_}/${t.name}`,e)}function Sn(r,e,n,t){let a=un(r,e);if(!a)throw new Z("expression is required",n);return Ve(a,n,t)}function Ve(r,e,n){if(w(r,d.StringLiteral))return{kind:"string-literal",value:$e(r,d.stringLiteral,e)};if(w(r,d.IntegerLiteral))return{kind:"integer-literal",value:$t(r,d.integerLiteral,e)};if(w(r,d.DecimalLiteral))return{kind:"decimal-literal",value:$t(r,d.decimalLiteral,e)};if(w(r,d.BooleanLiteral))return{kind:"boolean-literal",value:Ua(r,d.booleanLiteral,e)};if(w(r,d.VarRef))return{kind:"var-ref",varName:$e(r,d.varName,e)};if(w(r,d.PropertyRead))return{kind:"property-read",source:S(r,d.readSource,`${e}.readSource`,n),readProp:He(r,d.readProp,e,"readProp")};if(w(r,d.Traverse))return{kind:"traverse",source:S(r,d.traverseSource,`${e}.traverseSource`,n),through:He(r,d.through,e,"through"),step:S(r,d.step,`${e}.step`,n)};if(w(r,d.BuildAstNode))return{kind:"build-ast-node",astClass:He(r,d.astClass,e,"astClass"),set:wa(r,`${e}.set`,n)};if(w(r,d.When))return{kind:"when",condition:S(r,d.condition,`${e}.condition`,n),thenBuild:S(r,d.thenBuild,`${e}.thenBuild`,n),elseBuild:Sa(r,d.elseBuild,`${e}.elseBuild`,n)};if(w(r,d.Concat))return{kind:"concat",parts:Mn(r,d.parts,`${e}.parts`,n)};if(w(r,d.Fallback))return{kind:"fallback",primary:S(r,d.primary,`${e}.primary`,n),alternate:S(r,d.alternate,`${e}.alternate`,n)};if(w(r,d.UriName))return{kind:"uri-name",source:S(r,d.uriNameOf,`${e}.uriNameOf`,n)};if(w(r,d.UriPublisher))return{kind:"uri-publisher",source:S(r,d.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(w(r,d.UriPackage))return{kind:"uri-package",source:S(r,d.uriPackageOf,`${e}.uriPackageOf`,n)};if(w(r,d.UriVersion))return{kind:"uri-version",source:S(r,d.uriVersionOf,`${e}.uriVersionOf`,n)};if(w(r,d.SubjectUri))return{kind:"subject-uri",source:S(r,d.subjectOf,`${e}.subjectOf`,n)};if(w(r,d.UriLiteral))return{kind:"uri-literal",refTo:He(r,d.refTo,e,"refTo")};if(w(r,d.DisplayLabel))return{kind:"display-label",labelTarget:He(r,d.labelTarget,e,"labelTarget"),labelSource:He(r,d.labelSource,e,"labelSource")};if(w(r,d.ResolveRef))return{kind:"resolve-ref",source:S(r,d.resolveSource,`${e}.resolveSource`,n)};if(w(r,d.Normalize))return{kind:"normalize",source:S(r,d.normSource,`${e}.normSource`,n),normKind:ja(r,e)};if(w(r,d.UnescapedString))return{kind:"unescaped-string",source:S(r,d.unescapedSource,`${e}.unescapedSource`,n)};if(w(r,d.RenderMarkdown))return{kind:"render-markdown",source:S(r,d.renderSource,`${e}.renderSource`,n),readProp:He(r,d.renderProp,e,"renderProp"),format:_a(r,e)};if(w(r,d.IsSet))return{kind:"is-set",check:S(r,d.checkExpr,`${e}.checkExpr`,n)};if(w(r,d.CallFragment))return Ea(r,e,n);if(w(r,d.Join))return{kind:"join",source:S(r,d.source,`${e}.source`,n),separator:$e(r,d.separator,e)};if(w(r,d.Count))return{kind:"count",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Sum))return{kind:"sum",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Min))return{kind:"min",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Max))return{kind:"max",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Average))return{kind:"average",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.ForEach))return{kind:"for-each",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),emit:S(r,d.emit,`${e}.emit`,n)};if(w(r,d.ListMap))return{kind:"list-map",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),mapBody:S(r,d.mapBody,`${e}.mapBody`,n)};if(w(r,d.Filter))return{kind:"filter",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),predicate:S(r,d.predicate,`${e}.predicate`,n)};if(w(r,d.PartitionBy))return{kind:"partition-by",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),partitionKey:S(r,d.partitionKey,`${e}.partitionKey`,n)};if(w(r,d.DistinctBy))return{kind:"distinct-by",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),distinctKey:S(r,d.distinctKey,`${e}.distinctKey`,n)};if(w(r,d.AllStatements))return{kind:"all-statements",source:S(r,d.statementsOf,`${e}.statementsOf`,n)};if(w(r,d.StatementPredicate))return{kind:"statement-predicate",source:S(r,d.predicateOf,`${e}.predicateOf`,n)};if(w(r,d.StatementValue))return{kind:"statement-value",source:S(r,d.valueOf,`${e}.valueOf`,n)};if(w(r,d.DateFormat))return{kind:"date-format",source:S(r,d.dateSource,`${e}.dateSource`,n),format:Ra(r,e)};if(w(r,d.NumberFormat)){let t=An(r,d.fractionDigits);if(t!==void 0&&(!Number.isInteger(t)||t<0||t>20))throw new Z(`fractionDigits must be an integer between 0 and 20; got ${t}`,e);let a=qe(r,d.currencyCode);return{kind:"number-format",source:S(r,d.numberSource,`${e}.numberSource`,n),style:Ka(r,e),...t!==void 0?{fractionDigits:t}:{},...a!==void 0?{currencyCode:a}:{}}}if(w(r,d.Add))return{kind:"add",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Subtract))return{kind:"subtract",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Multiply))return{kind:"multiply",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Divide))return{kind:"divide",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Reverse))return{kind:"reverse",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.WindowedMap)){let t=An(r,d.windowSize);if(t===void 0||!Number.isInteger(t)||t<1)throw new Z("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:S(r,d.source,`${e}.source`,n),windowSize:t,windowVar:$e(r,d.windowVar,e),windowBody:S(r,d.windowBody,`${e}.windowBody`,n)}}if(w(r,d.PairwiseMap))return{kind:"pairwise-map",source:S(r,d.source,`${e}.source`,n),firstVar:$e(r,d.firstVar,e),secondVar:$e(r,d.secondVar,e),pairBody:S(r,d.pairBody,`${e}.pairBody`,n)};if(w(r,d.Scan))return{kind:"scan",source:S(r,d.source,`${e}.source`,n),initialState:S(r,d.initialState,`${e}.initialState`,n),stateVar:$e(r,d.stateVar,e),elementVar:$e(r,d.elementVar,e),accumulate:S(r,d.accumulate,`${e}.accumulate`,n)};if(w(r,d.ListItemAt))return{kind:"list-item-at",source:S(r,d.source,`${e}.source`,n),itemIndex:S(r,d.itemIndex,`${e}.itemIndex`,n)};if(w(r,d.Equals))return{kind:"equals",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.GreaterThan))return{kind:"greater-than",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.LessThan))return{kind:"less-than",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.LessThanOrEqual))return{kind:"less-than-or-equal",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.Not))return{kind:"not",operand:S(r,d.operand,`${e}.operand`,n)};if(w(r,d.And))return{kind:"and",operands:Mn(r,d.operands,`${e}.operands`,n)};if(w(r,d.Or))return{kind:"or",operands:Mn(r,d.operands,`${e}.operands`,n)};if(w(r,d.Contains))return{kind:"contains",haystack:S(r,d.haystack,`${e}.haystack`,n),needle:S(r,d.needle,`${e}.needle`,n)};if(w(r,d.Abs))return{kind:"abs",value:S(r,d.value,`${e}.value`,n)};if(w(r,d.Negate))return{kind:"negate",value:S(r,d.value,`${e}.value`,n)};if(w(r,d.IsReference))return{kind:"is-reference",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsEmbedded))return{kind:"is-embedded",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsList))return{kind:"is-list",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsString))return{kind:"is-string",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsNumber))return{kind:"is-number",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsBoolean))return{kind:"is-boolean",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.StatementObject))return{kind:"statement-object",source:S(r,d.statementSource,`${e}.statementSource`,n)};if(w(r,d.Let))return{kind:"let",bindName:$e(r,d.letName,e),bindValue:S(r,d.letValue,`${e}.letValue`,n),body:S(r,d.letBody,`${e}.letBody`,n)};if(w(r,d.GetStatementByName))return{kind:"get-statement-by-name",inSubject:S(r,d.inSubject,`${e}.inSubject`,n),byName:S(r,d.byName,`${e}.byName`,n)};throw new Z("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}function S(r,e,n,t){let a=un(r,e);if(!a)throw new Z("child expression is required",n);return Ve(a,n,t)}function Sa(r,e,n,t){let a=un(r,e);if(a)return Ve(a,n,t)}function Mn(r,e,n,t){let a=[],s=0;for(let o of we(r,e))if(o instanceof D)for(let i of o.object)i instanceof N&&a.push(Ve(i,`${n}[${s++}]`,t));else o instanceof J&&a.push(Ve(o.object,`${n}[${s++}]`,t));return a}function wa(r,e,n){let t=[],a=0;for(let s of we(r,d.set))if(s instanceof D)for(let o of s.object)o instanceof N&&t.push(ht(o,`${e}[${a++}]`,n));else s instanceof J&&t.push(ht(s.object,`${e}[${a++}]`,n));return t}function ht(r,e,n){return{field:He(r,d.field,e,"field"),value:S(r,d.bindValue,`${e}.bindValue`,n)}}function ja(r,e){let n=Me(r,d.normKind);if(!n)throw new Z("normKind is required",e);if(ie(n,d.NORM_TRIM_END))return"trim-end";if(ie(n,d.NORM_TO_UPPER))return"to-upper";if(ie(n,d.NORM_TO_LOWER))return"to-lower";if(ie(n,d.NORM_FIRST_CHAR))return"first-char";throw new Z(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function _a(r,e){let n=Me(r,d.renderFormat);if(!n)throw new Z("renderFormat is required",e);if(ie(n,d.RENDER_HTML))return"html";if(ie(n,d.RENDER_MARKDOWN))return"markdown";throw new Z(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var bt=new Set(["decimal","percent","basis-points","currency","compact"]);function Ka(r,e){let n=qe(r,d.numberStyle);if(n===void 0)throw new Z("numberStyle is required",e);if(!bt.has(n))throw new Z(`Unknown numberStyle "${n}"; supported: ${[...bt].join(", ")}`,e);return n}var yt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Ra(r,e){let n=qe(r,d.dateFormat);if(!n)throw new Z("dateFormat is required",e);if(!yt.has(n))throw new Z(`Unknown dateFormat "${n}"; supported: ${[...yt].join(", ")}`,e);return n}function Ea(r,e,n){let t=Me(r,d.fragmentRef);if(!t)throw new Z("fragmentRef is required",e);if(!Ca(n.catalog,t))throw new Z(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:xa(t)}}function xa(r){return`${r.publisher}/${r.package_}/${r.name}`}function La(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!w(t,d.ExpressionFragment))continue;let a=un(t,d.body);if(!a)continue;let s=(t.namespace||"").split("@")[0]||"",o=s.indexOf("/");if(o<0)continue;let i=s.substring(0,o),c=s.substring(o+1),l=`${i}/${c}/${t.name}`;n.push({key:l,subject:t,bodyEmb:a,pubPkgName:`${s}/${t.name}`})}for(let t of n){let a=Ve(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Ca(r,e){for(let n of r)if(!(!(n instanceof Y)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&w(n,d.ExpressionFragment))return n}function wt(r,e){let n=new Set;for(let t of we(r,d.outputs))if(t instanceof H)n.add(t.object.subject.name);else if(t instanceof D)for(let a of t.object)a instanceof L&&n.add(a.subject.name);if(n.size===0)throw new Z("outputs is required (at least one OutputFormat)",e);return n}function jt(r,e,n){let t=new Map,a=0;for(let s of we(r,d.formatOverrides))if(s instanceof D){for(let o of s.object)if(o instanceof N){let[i,c]=vt(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof J){let[o,i]=vt(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function vt(r,e){let n=Me(r,d.formatTarget);if(!n)throw new Z("formatTarget is required",e);let t=[];for(let i of we(r,d.metadataKeys))if(i instanceof Q)t.push(i.object);else if(i instanceof D)for(let c of i.object){let l=c.value;typeof l=="string"&&t.push(l)}let a=new Map;for(let i of we(r,d.metadataRenames))if(i instanceof D){for(let c of i.object)if(c instanceof N){let l=qe(c,d.fromKey),u=qe(c,d.toKey);l&&u&&a.set(l,u)}}else if(i instanceof J){let c=i.object,l=qe(c,d.fromKey),u=qe(c,d.toKey);l&&u&&a.set(l,u)}let s=Nn(r,d.trailingNewline),o=Nn(r,d.omitWrapper);return[n.name,{metadataKeys:t.length>0?t:void 0,metadataRenames:a,trailingNewline:s,omitWrapper:o}]}function Oa(r){return r.predicate?.subject}function we(r,e){let n=[];for(let t of r.statement){let a=Oa(t);a&&ie(a,e)&&n.push(t)}return n}function un(r,e){for(let n of we(r,e))if(n instanceof J)return n.object}function Me(r,e){for(let n of we(r,e))if(n instanceof H)return Dn(n.object.subject)}function qe(r,e){for(let n of we(r,e))if(n instanceof Q)return n.object}function An(r,e){for(let n of we(r,e))if(n instanceof ge)return n.object}function Nn(r,e){for(let n of we(r,e))if(n instanceof de)return n.object}function $e(r,e,n){let t=qe(r,e);if(t===void 0)throw new Z(`${e.name} (string) is required`,n);return t}function $t(r,e,n){let t=An(r,e);if(t===void 0)throw new Z(`${e.name} (number) is required`,n);return t}function Ua(r,e,n){let t=Nn(r,e);if(t===void 0)throw new Z(`${e.name} (boolean) is required`,n);return t}function He(r,e,n,t){let a=Me(r,e);if(!a)throw new Z(`${t} (URI reference) is required`,n);return a}function Dn(r){return{publisher:r.publisher,package_:r.package_,name:r.name}}var Ye="kanonak.org",xt="look",dn="core-rdf",Ia={publisher:Ye,package_:xt,name:"displayLabel"},Ta={publisher:Ye,package_:xt,name:"displaySummary"},Fa={publisher:Ye,package_:dn,name:"subClassOf"},Pa={publisher:Ye,package_:dn,name:"label"},Va={publisher:Ye,package_:dn,name:"comment"},_t=new yn(Ye,dn,"Resource"),Ma=8;function G(r,e){return Lt(r,e,new Set)}function Lt(r,e,n){let t=Et(r,e,Ia)??Pa,a=Et(r,e,Ta)??Va,s=Kt(r,e,t,n)??e.name,o=Kt(r,e,a,n);return{label:s,summary:o}}function Kt(r,e,n,t){for(let a of e.statement){let s=a.predicate;if(!(!s?.subject||!ie(s.subject,n))){if(a instanceof Q)return a.object;if(a instanceof ge||a instanceof de)return String(a.object);if(a instanceof H)return Rt(r,a.object.subject,t);if(a instanceof D){let o=[];for(let i of a.object??[])if(i instanceof L){let c=Rt(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function Rt(r,e,n){let t=ne(e);if(n.has(t)||n.size>=Ma)return e.name;let[a]=le(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),Lt(r,a,s).label}function Et(r,e,n){let t=je(e,n);if(t)return t;let a=new Set,s=Fe(e,Aa);for(;s.length>0;){let o=s.shift(),i=ne(o);if(a.has(i))continue;a.add(i);let c=le(r,o);for(let l of c){let u=je(l,n);if(u)return u}for(let l of c)s.push(...Fe(l,Fa))}if(!a.has(ne(_t)))for(let o of le(r,_t)){let i=je(o,n);if(i)return i}}var Aa={publisher:Ye,package_:dn,name:"type"};var Na="kanonak.org",Xe=(r,e)=>({publisher:Na,package_:r,name:e}),Da=Xe("look","source"),Ct=Xe("look","connectors"),Ba=Xe("look","relation"),Ha=Xe("look","lineStyle"),qa=Xe("look","participants"),Ga=Xe("core-owl","SymmetricProperty"),za=Xe("core-owl","inverseOf"),Ot=new Set(["solid","dotted","open","thick"]);function Ut(r){return je(r,Da)}function It(r,e){let n=ft(e,Ct),t=n?[n]:Pe(e,Ct),a=[];for(let s of t){if(!(s instanceof N))continue;let o=je(s,Ba);if(!o)continue;let i=xe(s,Ha),c=i!==void 0&&Ot.has(i);a.push({relation:o,subject:le(r,o)[0],declaredStyle:c?i:void 0,invalidStyle:i!==void 0&&!c?i:void 0})}return a}function Tt(r,e){let n=[];for(let t of Pe(e,qa)){if(!(t instanceof L))continue;let a=le(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of lt(e))if(ie(t,n)||nn(r,t).some(a=>ie(a,n)))return!0;return!1}function Ft(r,e,n){let t=!!e.subject&&fn(r,e.subject,Ga);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&Fe(e.subject,za).some(s=>n.some(o=>ie(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function Bn(r,e,n){let t=Ut(n);if(!t)return wn("the band declares no look.source");let a=It(r,n);if(a.length===0)return wn("the band declares no look.connectors \u2014 nothing can be a message");let s=ut(e,t);if(!s)return{...wn(),sourceAbsent:!0};if(!(s instanceof Te))return wn(`look.source ${ne(t)} is not a Markdown-ranged property \u2014 the order of a sequence comes from prose [[references]]`);let o=[],i=[],c=0;for(let m of s.links){if(!m.target)continue;let b=m.target.subject,k=le(r,b)[0];k&&(vn(r,k)!==void 0?a.some($=>ie(b,$.relation))?o.push({kind:"selector",relation:b}):i.push(b):(o.push({kind:"participant",subject:k}),c++))}let l=[],u=[],f,p;for(let m of o){if(m.kind==="selector"){p=m.relation;continue}let b=m.subject;if(f){let k=p?a.filter(C=>ie(p,C.relation)):a,$=_e(b),y=_e(f),K=[],E=[];for(let C of k){let{style:F,undirected:j}=Ft(r,C,a);$&&Fe(f,C.relation).some(W=>ne(W)===ne($))?K.push({from:f,to:b,relation:C.relation,style:F,undirected:j}):y&&Fe(b,C.relation).some(W=>ne(W)===ne(y))&&E.push({from:b,to:f,relation:C.relation,style:F,undirected:j})}let U=K.length>0?K:E;l.push(...U),U.length===0&&Ae(f)!==Ae(b)&&u.push({prev:f,next:b,selected:p}),p=void 0}f=b}let h=new Map;for(let m of Tt(r,n))h.set(Ae(m),m);for(let m of l)h.has(Ae(m.from))||h.set(Ae(m.from),m.from),h.has(Ae(m.to))||h.set(Ae(m.to),m.to);return{messages:l,gaps:u,lifelines:[...h.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ae(r){return`${r.namespace}/${r.name}`}function wn(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var Wa="kanonak.org",Ya="core-shacl",Se=r=>({publisher:Wa,package_:Ya,name:r}),Xa=Se("NodeShape"),Qa=Se("targetClass"),Ja=Se("property"),Za=Se("path"),er=Se("minCount"),nr=Se("maxCount"),tr=Se("in"),ar=Se("pattern"),rr=Se("flags"),sr=Se("minLength"),or=Se("maxLength"),ir=Se("minInclusive"),cr=Se("maxInclusive"),lr=Se("message");function tn(r){return typeof r=="number"?r:void 0}function ur(r){let e={},n=tn(We(r,er)),t=tn(We(r,nr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=tn(We(r,sr)),s=tn(We(r,or));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=tn(We(r,ir)),i=tn(We(r,cr));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,ar);if(c!==void 0){let f=xe(r,rr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Pe(r,tr).filter(f=>f instanceof ln).map(f=>f.value);l.length>0&&(e.enumValues=l);let u=xe(r,lr);return u!==void 0&&(e.message=u),e}function dr(r,e){let n=[];for(let t of Pe(e,Ja))if(t instanceof N)n.push(t);else if(t instanceof L){let a=Be(r,t.subject);a&&n.push(a)}return n}function pn(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!w(n,Xa))continue;let t=je(n,Qa);if(!t)continue;let a=ne(t);for(let s of dr(r,n)){let o=je(s,Za);if(!o)continue;let i={pathKey:ne(o),constraints:ur(s)},c=e.get(a);c?c.push(i):e.set(a,[i])}}return e}function fr(r,e){e.minCount!==void 0&&(r.minCount=e.minCount),e.maxCount!==void 0&&(r.maxCount=e.maxCount),e.minLength!==void 0&&(r.minLength=e.minLength),e.maxLength!==void 0&&(r.maxLength=e.maxLength),e.minInclusive!==void 0&&(r.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(r.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(r.pattern=e.pattern),e.enumValues!==void 0&&(r.enumValues=e.enumValues),e.message!==void 0&&(r.message=e.message)}function Pt(r,e,n){let t=ne(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(ne(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,fr(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Qe="kanonak.org",_n="core-rdf",Mt="core-xsd",Vt={publisher:Qe,package_:_n,name:"subClassOf"},At={publisher:Qe,package_:_n,name:"label"},Nt={publisher:Qe,package_:_n,name:"comment"},Dt={publisher:Qe,package_:"core-owl",name:"oneOf"},Bt=r=>r;function pr(r){let e=je(r,Vt);if(e)return[e];let n=[];for(let t of Pe(r,Vt))t instanceof L&&n.push(t.subject);return n}function mr(r,e,n){if(e.publisher===Qe&&e.package_===_n&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Be(r,e);if(a){let s=Bt(a);if(en.isDatatypeType(s))return{kind:"datatype",uri:e};if(en.isClassType(s))return{kind:"class",uri:_e(a)??e,localName:a.name}}return e.publisher===Qe&&e.package_===Mt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function gr(r,e,n){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let t=mr(r,e.range,e.kind),a=e.kind==="object"?"object":e.kind==="datatype"?"datatype":t.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:a,range:t,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...n??{}}}var jn=r=>new yn(Qe,Mt,r);function kr(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function hr(r,e){let n=[];for(let t of Pe(e,Dt))if(t instanceof L){let a=Be(r,t.subject),s=(a?_e(a):void 0)??t.subject,o=a?xe(a,At):void 0,i=a?xe(a,Nt):void 0;n.push({kind:"individual",uri:s,localName:s.name,...o!==void 0?{label:o}:{},...i!==void 0?{comment:i}:{}})}else t instanceof ln&&n.push({kind:"literal",value:t.value,datatype:kr(t.value)});return n}function Kn(r,e,n,t){let a=nn(r,e),s=ne(e);return mt(r,e).filter(i=>n?!0:i.domains.some(c=>ne(c)===s)).map(i=>gr(r,i,Pt(t,a,i.uri)))}async function qi(r,e,n){let t=r.metadata?.namespace_;if(!t)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let a=n?.includeInherited??!1,s=await new $n().parseKanonaks(e),o=pn(s),i=[],c=[],l=new Set;for(let u of s){if(!(u instanceof Y)||!en.isClassType(Bt(u)))continue;let f=_e(u);if(!f||f.publisher!==t.publisher||f.package_!==t.package_||f.version&&t.version&&!rt(f.version,t.version))continue;let p=ne(f);if(l.has(p))continue;l.add(p);let h=pr(u).map(k=>({uri:k,localName:k.name})),m=xe(u,At),b=xe(u,Nt);i.push({uri:f,localName:f.name,superClasses:h,properties:Kn(s,f,a,o),...m!==void 0?{label:m}:{},...b!==void 0?{comment:b}:{}}),dt(u,Dt)&&c.push({uri:f,localName:f.name,members:hr(s,u),...m!==void 0?{label:m}:{},...b!==void 0?{comment:b}:{}})}return{classes:i,enums:c}}function mn(r,e={}){let n=r.replace(/\r\n/g,`
|
|
1
|
+
import{a as ot}from"./chunk-6VIUXP4N.js";import{a as N,b as ln,c as Te,h as d,m as $n}from"./chunk-PVUBHIU2.js";import{a as it}from"./chunk-HF5FJBS2.js";import{a as gt}from"./chunk-PEJALHXK.js";import{fa as en,ga as _e,ha as nn,ia as vn,ma as mt}from"./chunk-7UYXTYXC.js";import{A as ft,B as Pe,C as pt,b as Ce,c as Y,d as L,g as Q,h as ge,i as de,j as H,k as J,l as D,m as ne,n as ie,o as ct,p as lt,q as Fe,r as w,t as Be,u as le,v as ut,w as dt,x as We,y as xe,z as je}from"./chunk-CJMVIOZX.js";import{a as yn}from"./chunk-FUUTGGJS.js";import{c as hn,d as rt,e as bn,g as st}from"./chunk-QILEJIFU.js";var Z=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function fi(r,e){let n=r.name,t=La(e),a={catalog:e,depth:0};if(w(r,d.InstanceTransformation))return ya(r,n,a,t);if(w(r,d.SetTransformation))return va(r,n,a,t);throw new Z("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function ya(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:St(r,e),rule:Sn(r,d.rule,`${e}.rule`,n),artifactName:Sn(r,d.artifactName,`${e}.artifactName`,n),outputs:wt(r,`${e}.outputs`),overrides:jt(r,`${e}.formatOverrides`,n),fragments:t}}function va(r,e,n,t){let a=Me(r,d.partitionBy);return{kind:"set",name:r.name,inputPattern:St(r,e),rule:Sn(r,d.rule,`${e}.rule`,n),artifactName:Sn(r,d.artifactName,`${e}.artifactName`,n),outputs:wt(r,`${e}.outputs`),overrides:jt(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function St(r,e){let n=un(r,d.inputPattern);if(!n)throw new Z("inputPattern is required",e);return $a(n,`${e}.inputPattern`)}function $a(r,e){let n=Me(r,d.matchesClass);if(!n)throw new Z("matchesClass is required",e);let t=[];for(let o of we(r,d.requires))if(o instanceof H)t.push(Dn(o.object.subject));else if(o instanceof D)for(let i of o.object)i instanceof L&&t.push(Dn(i.subject));let a=[],s=0;for(let o of we(r,d.sortBy))if(o instanceof D)for(let i of o.object)i instanceof N&&a.push(kt(i,`${e}.sortBy[${s++}]`));else o instanceof J&&a.push(kt(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function kt(r,e){let n=Me(r,d.byProperty);if(!n)throw new Z("SortKey.byProperty is required",e);let t=Me(r,d.order);if(!t)throw new Z("SortKey.order is required",e);if(ie(t,d.ascending))return{byProperty:n,order:"ascending"};if(ie(t,d.descending))return{byProperty:n,order:"descending"};throw new Z(`SortKey.order must reference tx.ascending or tx.descending; got ${t.publisher}/${t.package_}/${t.name}`,e)}function Sn(r,e,n,t){let a=un(r,e);if(!a)throw new Z("expression is required",n);return Ve(a,n,t)}function Ve(r,e,n){if(w(r,d.StringLiteral))return{kind:"string-literal",value:$e(r,d.stringLiteral,e)};if(w(r,d.IntegerLiteral))return{kind:"integer-literal",value:$t(r,d.integerLiteral,e)};if(w(r,d.DecimalLiteral))return{kind:"decimal-literal",value:$t(r,d.decimalLiteral,e)};if(w(r,d.BooleanLiteral))return{kind:"boolean-literal",value:Ua(r,d.booleanLiteral,e)};if(w(r,d.VarRef))return{kind:"var-ref",varName:$e(r,d.varName,e)};if(w(r,d.PropertyRead))return{kind:"property-read",source:S(r,d.readSource,`${e}.readSource`,n),readProp:He(r,d.readProp,e,"readProp")};if(w(r,d.Traverse))return{kind:"traverse",source:S(r,d.traverseSource,`${e}.traverseSource`,n),through:He(r,d.through,e,"through"),step:S(r,d.step,`${e}.step`,n)};if(w(r,d.BuildAstNode))return{kind:"build-ast-node",astClass:He(r,d.astClass,e,"astClass"),set:wa(r,`${e}.set`,n)};if(w(r,d.When))return{kind:"when",condition:S(r,d.condition,`${e}.condition`,n),thenBuild:S(r,d.thenBuild,`${e}.thenBuild`,n),elseBuild:Sa(r,d.elseBuild,`${e}.elseBuild`,n)};if(w(r,d.Concat))return{kind:"concat",parts:Mn(r,d.parts,`${e}.parts`,n)};if(w(r,d.Fallback))return{kind:"fallback",primary:S(r,d.primary,`${e}.primary`,n),alternate:S(r,d.alternate,`${e}.alternate`,n)};if(w(r,d.UriName))return{kind:"uri-name",source:S(r,d.uriNameOf,`${e}.uriNameOf`,n)};if(w(r,d.UriPublisher))return{kind:"uri-publisher",source:S(r,d.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(w(r,d.UriPackage))return{kind:"uri-package",source:S(r,d.uriPackageOf,`${e}.uriPackageOf`,n)};if(w(r,d.UriVersion))return{kind:"uri-version",source:S(r,d.uriVersionOf,`${e}.uriVersionOf`,n)};if(w(r,d.SubjectUri))return{kind:"subject-uri",source:S(r,d.subjectOf,`${e}.subjectOf`,n)};if(w(r,d.UriLiteral))return{kind:"uri-literal",refTo:He(r,d.refTo,e,"refTo")};if(w(r,d.DisplayLabel))return{kind:"display-label",labelTarget:He(r,d.labelTarget,e,"labelTarget"),labelSource:He(r,d.labelSource,e,"labelSource")};if(w(r,d.ResolveRef))return{kind:"resolve-ref",source:S(r,d.resolveSource,`${e}.resolveSource`,n)};if(w(r,d.Normalize))return{kind:"normalize",source:S(r,d.normSource,`${e}.normSource`,n),normKind:ja(r,e)};if(w(r,d.UnescapedString))return{kind:"unescaped-string",source:S(r,d.unescapedSource,`${e}.unescapedSource`,n)};if(w(r,d.RenderMarkdown))return{kind:"render-markdown",source:S(r,d.renderSource,`${e}.renderSource`,n),readProp:He(r,d.renderProp,e,"renderProp"),format:_a(r,e)};if(w(r,d.IsSet))return{kind:"is-set",check:S(r,d.checkExpr,`${e}.checkExpr`,n)};if(w(r,d.CallFragment))return Ea(r,e,n);if(w(r,d.Join))return{kind:"join",source:S(r,d.source,`${e}.source`,n),separator:$e(r,d.separator,e)};if(w(r,d.Count))return{kind:"count",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Sum))return{kind:"sum",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Min))return{kind:"min",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Max))return{kind:"max",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.Average))return{kind:"average",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.ForEach))return{kind:"for-each",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),emit:S(r,d.emit,`${e}.emit`,n)};if(w(r,d.ListMap))return{kind:"list-map",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),mapBody:S(r,d.mapBody,`${e}.mapBody`,n)};if(w(r,d.Filter))return{kind:"filter",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),predicate:S(r,d.predicate,`${e}.predicate`,n)};if(w(r,d.PartitionBy))return{kind:"partition-by",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),partitionKey:S(r,d.partitionKey,`${e}.partitionKey`,n)};if(w(r,d.DistinctBy))return{kind:"distinct-by",source:S(r,d.source,`${e}.source`,n),loopVar:$e(r,d.loopVar,e),distinctKey:S(r,d.distinctKey,`${e}.distinctKey`,n)};if(w(r,d.AllStatements))return{kind:"all-statements",source:S(r,d.statementsOf,`${e}.statementsOf`,n)};if(w(r,d.StatementPredicate))return{kind:"statement-predicate",source:S(r,d.predicateOf,`${e}.predicateOf`,n)};if(w(r,d.StatementValue))return{kind:"statement-value",source:S(r,d.valueOf,`${e}.valueOf`,n)};if(w(r,d.DateFormat))return{kind:"date-format",source:S(r,d.dateSource,`${e}.dateSource`,n),format:Ra(r,e)};if(w(r,d.NumberFormat)){let t=An(r,d.fractionDigits);if(t!==void 0&&(!Number.isInteger(t)||t<0||t>20))throw new Z(`fractionDigits must be an integer between 0 and 20; got ${t}`,e);let a=qe(r,d.currencyCode);return{kind:"number-format",source:S(r,d.numberSource,`${e}.numberSource`,n),style:Ka(r,e),...t!==void 0?{fractionDigits:t}:{},...a!==void 0?{currencyCode:a}:{}}}if(w(r,d.Add))return{kind:"add",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Subtract))return{kind:"subtract",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Multiply))return{kind:"multiply",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Divide))return{kind:"divide",left:S(r,d.arithLeft,`${e}.arithLeft`,n),right:S(r,d.arithRight,`${e}.arithRight`,n)};if(w(r,d.Reverse))return{kind:"reverse",source:S(r,d.source,`${e}.source`,n)};if(w(r,d.WindowedMap)){let t=An(r,d.windowSize);if(t===void 0||!Number.isInteger(t)||t<1)throw new Z("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:S(r,d.source,`${e}.source`,n),windowSize:t,windowVar:$e(r,d.windowVar,e),windowBody:S(r,d.windowBody,`${e}.windowBody`,n)}}if(w(r,d.PairwiseMap))return{kind:"pairwise-map",source:S(r,d.source,`${e}.source`,n),firstVar:$e(r,d.firstVar,e),secondVar:$e(r,d.secondVar,e),pairBody:S(r,d.pairBody,`${e}.pairBody`,n)};if(w(r,d.Scan))return{kind:"scan",source:S(r,d.source,`${e}.source`,n),initialState:S(r,d.initialState,`${e}.initialState`,n),stateVar:$e(r,d.stateVar,e),elementVar:$e(r,d.elementVar,e),accumulate:S(r,d.accumulate,`${e}.accumulate`,n)};if(w(r,d.ListItemAt))return{kind:"list-item-at",source:S(r,d.source,`${e}.source`,n),itemIndex:S(r,d.itemIndex,`${e}.itemIndex`,n)};if(w(r,d.Equals))return{kind:"equals",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.GreaterThan))return{kind:"greater-than",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.LessThan))return{kind:"less-than",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.LessThanOrEqual))return{kind:"less-than-or-equal",left:S(r,d.compareLeft,`${e}.compareLeft`,n),right:S(r,d.compareRight,`${e}.compareRight`,n)};if(w(r,d.Not))return{kind:"not",operand:S(r,d.operand,`${e}.operand`,n)};if(w(r,d.And))return{kind:"and",operands:Mn(r,d.operands,`${e}.operands`,n)};if(w(r,d.Or))return{kind:"or",operands:Mn(r,d.operands,`${e}.operands`,n)};if(w(r,d.Contains))return{kind:"contains",haystack:S(r,d.haystack,`${e}.haystack`,n),needle:S(r,d.needle,`${e}.needle`,n)};if(w(r,d.Abs))return{kind:"abs",value:S(r,d.value,`${e}.value`,n)};if(w(r,d.Negate))return{kind:"negate",value:S(r,d.value,`${e}.value`,n)};if(w(r,d.IsReference))return{kind:"is-reference",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsEmbedded))return{kind:"is-embedded",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsList))return{kind:"is-list",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsString))return{kind:"is-string",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsNumber))return{kind:"is-number",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.IsBoolean))return{kind:"is-boolean",check:S(r,d.kindCheck,`${e}.kindCheck`,n)};if(w(r,d.StatementObject))return{kind:"statement-object",source:S(r,d.statementSource,`${e}.statementSource`,n)};if(w(r,d.Let))return{kind:"let",bindName:$e(r,d.letName,e),bindValue:S(r,d.letValue,`${e}.letValue`,n),body:S(r,d.letBody,`${e}.letBody`,n)};if(w(r,d.GetStatementByName))return{kind:"get-statement-by-name",inSubject:S(r,d.inSubject,`${e}.inSubject`,n),byName:S(r,d.byName,`${e}.byName`,n)};throw new Z("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}function S(r,e,n,t){let a=un(r,e);if(!a)throw new Z("child expression is required",n);return Ve(a,n,t)}function Sa(r,e,n,t){let a=un(r,e);if(a)return Ve(a,n,t)}function Mn(r,e,n,t){let a=[],s=0;for(let o of we(r,e))if(o instanceof D)for(let i of o.object)i instanceof N&&a.push(Ve(i,`${n}[${s++}]`,t));else o instanceof J&&a.push(Ve(o.object,`${n}[${s++}]`,t));return a}function wa(r,e,n){let t=[],a=0;for(let s of we(r,d.set))if(s instanceof D)for(let o of s.object)o instanceof N&&t.push(ht(o,`${e}[${a++}]`,n));else s instanceof J&&t.push(ht(s.object,`${e}[${a++}]`,n));return t}function ht(r,e,n){return{field:He(r,d.field,e,"field"),value:S(r,d.bindValue,`${e}.bindValue`,n)}}function ja(r,e){let n=Me(r,d.normKind);if(!n)throw new Z("normKind is required",e);if(ie(n,d.NORM_TRIM_END))return"trim-end";if(ie(n,d.NORM_TO_UPPER))return"to-upper";if(ie(n,d.NORM_TO_LOWER))return"to-lower";if(ie(n,d.NORM_FIRST_CHAR))return"first-char";throw new Z(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function _a(r,e){let n=Me(r,d.renderFormat);if(!n)throw new Z("renderFormat is required",e);if(ie(n,d.RENDER_HTML))return"html";if(ie(n,d.RENDER_MARKDOWN))return"markdown";throw new Z(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var bt=new Set(["decimal","percent","basis-points","currency","compact"]);function Ka(r,e){let n=qe(r,d.numberStyle);if(n===void 0)throw new Z("numberStyle is required",e);if(!bt.has(n))throw new Z(`Unknown numberStyle "${n}"; supported: ${[...bt].join(", ")}`,e);return n}var yt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Ra(r,e){let n=qe(r,d.dateFormat);if(!n)throw new Z("dateFormat is required",e);if(!yt.has(n))throw new Z(`Unknown dateFormat "${n}"; supported: ${[...yt].join(", ")}`,e);return n}function Ea(r,e,n){let t=Me(r,d.fragmentRef);if(!t)throw new Z("fragmentRef is required",e);if(!Ca(n.catalog,t))throw new Z(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:xa(t)}}function xa(r){return`${r.publisher}/${r.package_}/${r.name}`}function La(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!w(t,d.ExpressionFragment))continue;let a=un(t,d.body);if(!a)continue;let s=(t.namespace||"").split("@")[0]||"",o=s.indexOf("/");if(o<0)continue;let i=s.substring(0,o),c=s.substring(o+1),l=`${i}/${c}/${t.name}`;n.push({key:l,subject:t,bodyEmb:a,pubPkgName:`${s}/${t.name}`})}for(let t of n){let a=Ve(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Ca(r,e){for(let n of r)if(!(!(n instanceof Y)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&w(n,d.ExpressionFragment))return n}function wt(r,e){let n=new Set;for(let t of we(r,d.outputs))if(t instanceof H)n.add(t.object.subject.name);else if(t instanceof D)for(let a of t.object)a instanceof L&&n.add(a.subject.name);if(n.size===0)throw new Z("outputs is required (at least one OutputFormat)",e);return n}function jt(r,e,n){let t=new Map,a=0;for(let s of we(r,d.formatOverrides))if(s instanceof D){for(let o of s.object)if(o instanceof N){let[i,c]=vt(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof J){let[o,i]=vt(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function vt(r,e){let n=Me(r,d.formatTarget);if(!n)throw new Z("formatTarget is required",e);let t=[];for(let i of we(r,d.metadataKeys))if(i instanceof Q)t.push(i.object);else if(i instanceof D)for(let c of i.object){let l=c.value;typeof l=="string"&&t.push(l)}let a=new Map;for(let i of we(r,d.metadataRenames))if(i instanceof D){for(let c of i.object)if(c instanceof N){let l=qe(c,d.fromKey),u=qe(c,d.toKey);l&&u&&a.set(l,u)}}else if(i instanceof J){let c=i.object,l=qe(c,d.fromKey),u=qe(c,d.toKey);l&&u&&a.set(l,u)}let s=Nn(r,d.trailingNewline),o=Nn(r,d.omitWrapper);return[n.name,{metadataKeys:t.length>0?t:void 0,metadataRenames:a,trailingNewline:s,omitWrapper:o}]}function Oa(r){return r.predicate?.subject}function we(r,e){let n=[];for(let t of r.statement){let a=Oa(t);a&&ie(a,e)&&n.push(t)}return n}function un(r,e){for(let n of we(r,e))if(n instanceof J)return n.object}function Me(r,e){for(let n of we(r,e))if(n instanceof H)return Dn(n.object.subject)}function qe(r,e){for(let n of we(r,e))if(n instanceof Q)return n.object}function An(r,e){for(let n of we(r,e))if(n instanceof ge)return n.object}function Nn(r,e){for(let n of we(r,e))if(n instanceof de)return n.object}function $e(r,e,n){let t=qe(r,e);if(t===void 0)throw new Z(`${e.name} (string) is required`,n);return t}function $t(r,e,n){let t=An(r,e);if(t===void 0)throw new Z(`${e.name} (number) is required`,n);return t}function Ua(r,e,n){let t=Nn(r,e);if(t===void 0)throw new Z(`${e.name} (boolean) is required`,n);return t}function He(r,e,n,t){let a=Me(r,e);if(!a)throw new Z(`${t} (URI reference) is required`,n);return a}function Dn(r){return{publisher:r.publisher,package_:r.package_,name:r.name}}var Ye="kanonak.org",xt="look",dn="core-rdf",Ia={publisher:Ye,package_:xt,name:"displayLabel"},Ta={publisher:Ye,package_:xt,name:"displaySummary"},Fa={publisher:Ye,package_:dn,name:"subClassOf"},Pa={publisher:Ye,package_:dn,name:"label"},Va={publisher:Ye,package_:dn,name:"comment"},_t=new yn(Ye,dn,"Resource"),Ma=8;function G(r,e){return Lt(r,e,new Set)}function Lt(r,e,n){let t=Et(r,e,Ia)??Pa,a=Et(r,e,Ta)??Va,s=Kt(r,e,t,n)??e.name,o=Kt(r,e,a,n);return{label:s,summary:o}}function Kt(r,e,n,t){for(let a of e.statement){let s=a.predicate;if(!(!s?.subject||!ie(s.subject,n))){if(a instanceof Q)return a.object;if(a instanceof ge||a instanceof de)return String(a.object);if(a instanceof H)return Rt(r,a.object.subject,t);if(a instanceof D){let o=[];for(let i of a.object??[])if(i instanceof L){let c=Rt(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function Rt(r,e,n){let t=ne(e);if(n.has(t)||n.size>=Ma)return e.name;let[a]=le(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),Lt(r,a,s).label}function Et(r,e,n){let t=je(e,n);if(t)return t;let a=new Set,s=Fe(e,Aa);for(;s.length>0;){let o=s.shift(),i=ne(o);if(a.has(i))continue;a.add(i);let c=le(r,o);for(let l of c){let u=je(l,n);if(u)return u}for(let l of c)s.push(...Fe(l,Fa))}if(!a.has(ne(_t)))for(let o of le(r,_t)){let i=je(o,n);if(i)return i}}var Aa={publisher:Ye,package_:dn,name:"type"};var Na="kanonak.org",Xe=(r,e)=>({publisher:Na,package_:r,name:e}),Da=Xe("look","source"),Ct=Xe("look","connectors"),Ba=Xe("look","relation"),Ha=Xe("look","lineStyle"),qa=Xe("look","participants"),Ga=Xe("core-owl","SymmetricProperty"),za=Xe("core-owl","inverseOf"),Ot=new Set(["solid","dotted","open","thick"]);function Ut(r){return je(r,Da)}function It(r,e){let n=ft(e,Ct),t=n?[n]:Pe(e,Ct),a=[];for(let s of t){if(!(s instanceof N))continue;let o=je(s,Ba);if(!o)continue;let i=xe(s,Ha),c=i!==void 0&&Ot.has(i);a.push({relation:o,subject:le(r,o)[0],declaredStyle:c?i:void 0,invalidStyle:i!==void 0&&!c?i:void 0})}return a}function Tt(r,e){let n=[];for(let t of Pe(e,qa)){if(!(t instanceof L))continue;let a=le(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of lt(e))if(ie(t,n)||nn(r,t).some(a=>ie(a,n)))return!0;return!1}function Ft(r,e,n){let t=!!e.subject&&fn(r,e.subject,Ga);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&Fe(e.subject,za).some(s=>n.some(o=>ie(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function Bn(r,e,n){let t=Ut(n);if(!t)return wn("the band declares no look.source");let a=It(r,n);if(a.length===0)return wn("the band declares no look.connectors \u2014 nothing can be a message");let s=ut(e,t);if(!s)return{...wn(),sourceAbsent:!0};if(!(s instanceof Te))return wn(`look.source ${ne(t)} is not a Markdown-ranged property \u2014 the order of a sequence comes from prose [[references]]`);let o=[],i=[],c=0;for(let m of s.links){if(!m.target)continue;let b=m.target.subject,k=le(r,b)[0];k&&(vn(r,k)!==void 0?a.some($=>ie(b,$.relation))?o.push({kind:"selector",relation:b}):i.push(b):(o.push({kind:"participant",subject:k}),c++))}let l=[],u=[],f,p;for(let m of o){if(m.kind==="selector"){p=m.relation;continue}let b=m.subject;if(f){let k=p?a.filter(C=>ie(p,C.relation)):a,$=_e(b),y=_e(f),K=[],E=[];for(let C of k){let{style:F,undirected:j}=Ft(r,C,a);$&&Fe(f,C.relation).some(W=>ne(W)===ne($))?K.push({from:f,to:b,relation:C.relation,style:F,undirected:j}):y&&Fe(b,C.relation).some(W=>ne(W)===ne(y))&&E.push({from:b,to:f,relation:C.relation,style:F,undirected:j})}let U=K.length>0?K:E;l.push(...U),U.length===0&&Ae(f)!==Ae(b)&&u.push({prev:f,next:b,selected:p}),p=void 0}f=b}let h=new Map;for(let m of Tt(r,n))h.set(Ae(m),m);for(let m of l)h.has(Ae(m.from))||h.set(Ae(m.from),m.from),h.has(Ae(m.to))||h.set(Ae(m.to),m.to);return{messages:l,gaps:u,lifelines:[...h.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ae(r){return`${r.namespace}/${r.name}`}function wn(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var Wa="kanonak.org",Ya="core-shacl",Se=r=>({publisher:Wa,package_:Ya,name:r}),Xa=Se("NodeShape"),Qa=Se("targetClass"),Ja=Se("property"),Za=Se("path"),er=Se("minCount"),nr=Se("maxCount"),tr=Se("in"),ar=Se("pattern"),rr=Se("flags"),sr=Se("minLength"),or=Se("maxLength"),ir=Se("minInclusive"),cr=Se("maxInclusive"),lr=Se("message");function tn(r){return typeof r=="number"?r:void 0}function ur(r){let e={},n=tn(We(r,er)),t=tn(We(r,nr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=tn(We(r,sr)),s=tn(We(r,or));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=tn(We(r,ir)),i=tn(We(r,cr));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,ar);if(c!==void 0){let f=xe(r,rr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Pe(r,tr).filter(f=>f instanceof ln).map(f=>f.value);l.length>0&&(e.enumValues=l);let u=xe(r,lr);return u!==void 0&&(e.message=u),e}function dr(r,e){let n=[];for(let t of Pe(e,Ja))if(t instanceof N)n.push(t);else if(t instanceof L){let a=Be(r,t.subject);a&&n.push(a)}return n}function pn(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!w(n,Xa))continue;let t=je(n,Qa);if(!t)continue;let a=ne(t);for(let s of dr(r,n)){let o=je(s,Za);if(!o)continue;let i={pathKey:ne(o),constraints:ur(s)},c=e.get(a);c?c.push(i):e.set(a,[i])}}return e}function fr(r,e){e.minCount!==void 0&&(r.minCount=e.minCount),e.maxCount!==void 0&&(r.maxCount=e.maxCount),e.minLength!==void 0&&(r.minLength=e.minLength),e.maxLength!==void 0&&(r.maxLength=e.maxLength),e.minInclusive!==void 0&&(r.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(r.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(r.pattern=e.pattern),e.enumValues!==void 0&&(r.enumValues=e.enumValues),e.message!==void 0&&(r.message=e.message)}function Pt(r,e,n){let t=ne(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(ne(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,fr(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Qe="kanonak.org",_n="core-rdf",Mt="core-xsd",Vt={publisher:Qe,package_:_n,name:"subClassOf"},At={publisher:Qe,package_:_n,name:"label"},Nt={publisher:Qe,package_:_n,name:"comment"},Dt={publisher:Qe,package_:"core-owl",name:"oneOf"},Bt=r=>r;function pr(r){let e=je(r,Vt);if(e)return[e];let n=[];for(let t of Pe(r,Vt))t instanceof L&&n.push(t.subject);return n}function mr(r,e,n){if(e.publisher===Qe&&e.package_===_n&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Be(r,e);if(a){let s=Bt(a);if(en.isDatatypeType(s))return{kind:"datatype",uri:e};if(en.isClassType(s))return{kind:"class",uri:_e(a)??e,localName:a.name}}return e.publisher===Qe&&e.package_===Mt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function gr(r,e,n){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let t=mr(r,e.range,e.kind),a=e.kind==="object"?"object":e.kind==="datatype"?"datatype":t.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:a,range:t,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...n??{}}}var jn=r=>new yn(Qe,Mt,r);function kr(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function hr(r,e){let n=[];for(let t of Pe(e,Dt))if(t instanceof L){let a=Be(r,t.subject),s=(a?_e(a):void 0)??t.subject,o=a?xe(a,At):void 0,i=a?xe(a,Nt):void 0;n.push({kind:"individual",uri:s,localName:s.name,...o!==void 0?{label:o}:{},...i!==void 0?{comment:i}:{}})}else t instanceof ln&&n.push({kind:"literal",value:t.value,datatype:kr(t.value)});return n}function Kn(r,e,n,t){let a=nn(r,e),s=ne(e);return mt(r,e).filter(i=>n?!0:i.domains.some(c=>ne(c)===s)).map(i=>gr(r,i,Pt(t,a,i.uri)))}async function qi(r,e,n){let t=r.metadata?.namespace_;if(!t)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let a=n?.includeInherited??!1,s=await new $n().parseKanonaks(e),o=pn(s),i=[],c=[],l=new Set;for(let u of s){if(!(u instanceof Y)||!en.isClassType(Bt(u)))continue;let f=_e(u);if(!f||f.publisher!==t.publisher||f.package_!==t.package_||f.version&&t.version&&!rt(f.version,t.version))continue;let p=ne(f);if(l.has(p))continue;l.add(p);let h=pr(u).map(k=>({uri:k,localName:k.name})),m=xe(u,At),b=xe(u,Nt);i.push({uri:f,localName:f.name,superClasses:h,properties:Kn(s,f,a,o),...m!==void 0?{label:m}:{},...b!==void 0?{comment:b}:{}}),dt(u,Dt)&&c.push({uri:f,localName:f.name,members:hr(s,u),...m!==void 0?{label:m}:{},...b!==void 0?{comment:b}:{}})}return{classes:i,enums:c}}function mn(r,e={}){let n=r.replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),t=[],a=0;for(;a<n.length;){let s=n[a];if(s.trim()===""){a++;continue}let o=/^(\s*)```(\S*)\s*$/.exec(s);if(o){let l=o[2],u=[];for(a++;a<n.length&&!/^(\s*)```\s*$/.test(n[a]);)u.push(n[a]),a++;a++;let f=u.join(`
|
|
4
4
|
`),p=l&&e.highlight?e.highlight(l,f):rn(f),h=l?` class="language-${qt(l)}"`:"";t.push(`<pre class="kan-code"><code${h}>${p}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,u=an(i[2].trim());t.push(`<h${l}>${u}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&Ht(n[a+1])){let l=Hn(s),u=br(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(Hn(n[a])),a++;t.push(yr(l,u,f));continue}if(/^\s*[-*]\s+/.test(s)){let l=[];for(;a<n.length&&/^\s*[-*]\s+/.test(n[a]);){let u=[n[a].replace(/^\s*[-*]\s+/,"")];for(a++;a<n.length&&n[a].trim()!==""&&!/^\s*[-*]\s+/.test(n[a])&&!/^\s*\d+\.\s+/.test(n[a]);)u.push(n[a]),a++;a<n.length&&n[a].trim()===""&&a++,l.push(`<li>${an(u.join(" ").trim())}</li>`)}t.push(`<ul>
|
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, SequenceNarrativeRule, 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, LinkTargetRule, 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';
|
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-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
|
+
import{a as Zt,b as Qt,c as eo,d as no,e as H}from"./chunk-EVMSO7HJ.js";import{a as Vn,b as Nn,c as On}from"./chunk-V3DH67P3.js";import{a as Xt,b as Yt,c as Jt,d as tr,e as we,f as or,g as rr,h as ar,i as ir,j as sr,k as cr,l as ur}from"./chunk-J4ZD6IF6.js";import{a as lr}from"./chunk-L2J7WD7E.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-IS3AQKB4.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-BZ3YTI3C.js";import{a as oo,b as ro,c as ao,d as io}from"./chunk-BS7RRG7D.js";import{a as so}from"./chunk-XK24CN3C.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 Xo,H as Yo,I as Jo,J as Zo,K as Qo,L as er,M as nr,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-CR5QY3LJ.js";import"./chunk-KIBR3HAT.js";import{c as Ln,d as To,e as Fo,g as Bo,h as Wo,k as zo,m as xe,o as An,p as jn,r as Go,s as qo}from"./chunk-Z5Y4MCW5.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-PVUBHIU2.js";import{a as j}from"./chunk-HF5FJBS2.js";import{a as co}from"./chunk-PEJALHXK.js";import{$ as Ee,A as rn,B as an,C as sn,D as cn,E as un,F as ln,G as pn,H as dn,I as mn,J as fn,K as kn,L as yn,M as Re,N as hn,O as gn,P as Sn,Q as bn,R as Pn,S as Rn,T as En,U as Kn,V as xn,W as wn,X as Cn,Y as vn,Z as In,_ as _n,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 Y,k as J,l as We,m as Z,ma as Wt,n as ze,na as zt,o as Ge,oa as ne,p as qe,q as Xe,r as Ye,s as Je,t as Ze,u as Qe,v as Pe,w as en,x as nn,y as tn,z as on}from"./chunk-7UYXTYXC.js";import{A as be,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 Fe,t as K,w as Be,x as I,y as X,z as y}from"./chunk-CJMVIOZX.js";import{a as Vt}from"./chunk-FUUTGGJS.js";import"./chunk-F67UH4FD.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 pr(n){if(!n)return;let e=u(n);if(e===u(fn))return"IRI";if(e===u(kn))return"BlankNode";if(e===u(yn))return"Literal"}function Mn(n){if(!n)return;let e=u(n);if(e===u(hn))return"Violation";if(e===u(gn))return"Warning";if(e===u(Sn))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 dr(n,e){let o=y(n,Xe);if(!o)return;let t={path:o},r=$(I(n,Ye)),a=$(I(n,Je));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=$(I(n,tn)),i=$(I(n,on));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let c=$(I(n,rn)),p=$(I(n,an));c!==void 0&&(t.minInclusive=c),p!==void 0&&(t.maxInclusive=p);let d=X(n,en);if(d!==void 0){let P=X(n,nn);t.pattern=P!==void 0?{regex:d,flags:P}:{regex:d}}if(Be(n,Pe)){let P=[],N=[];for(let O of _(n,Pe))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,Ze);S&&(t.datatype=S);let b=y(n,Qe);b&&(t.classRef=b);let l=pr(y(n,mn));l&&(t.nodeKind=l);let m=X(n,sn);m!==void 0&&(t.message=m);let f=Mn(y(n,Re))??e;return f&&(t.severity=f),t}function te(n){let e=[];for(let o of n){if(!(o instanceof g)||!Fe(o,Z))continue;let t=Mn(y(o,Re)),r={name:o.name,uri:h(o),targetClass:y(o,Ge),targetNodes:Ce(o,cn),targetSubjectsOf:Ce(o,un),targetObjectsOf:Ce(o,ln),closed:I(o,pn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of _(o,dn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of _(o,qe)){let s;if(a instanceof E?s=a:a instanceof k&&(s=K(n,a.subject)),!s)continue;let i=dr(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}),mr=n=>({type:`${x}/DecimalLiteral`,decimalLiteral:n}),Hn=n=>Number.isInteger(n)?ve(n):mr(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 kr,ExpressionError as yr}from"@kanonak-protocol/expression";function Gn(n,e){let o=hr(e)?e:te(e),t=[];for(let r of o)for(let a of gr(n,r))Pr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function hr(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 gr(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 Sr(c)){let S=K(n.catalog,d);S instanceof g&&r(S)}}}return[...o.values()]}function Sr(n){return n instanceof G?[n.object.subject]:n instanceof q?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function br(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 Pr(n,e,o,t){let r=h(o),a=r?u(r):`${o.namespace}/${o.name}`;for(let s of e.properties)Er(n,e,o,a,r,s,t);e.closed&&vr(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 Rr={minCount:bn,maxCount:Pn,in:Kn,pattern:xn,minLength:wn,maxLength:Cn,minInclusive:vn,maxInclusive:In};function Er(n,e,o,t,r,a,s){let i=u(a.path),c=br(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=Rr[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,Kr(l,d,a,f),f)}}if(a.nodeKind)for(let l of c)xr(a.nodeKind,l)||b(_n,`'${d}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of c){let m=wr(a.datatype,l);m&&b(Rn,`'${d}' ${m}`,l)}if(a.classRef)for(let l of c){let m=Cr(n,a.classRef,l);m&&b(En,`'${d}' ${m}`,l)}}function Kr(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 yr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return kr(n.expr,void 0,o)===1}function xr(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 wr(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 Cr(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 vr(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,Ee,`'${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,Ee,`'${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 Ir="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,Ir,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(_r(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 _r(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var Lr="1.1.0";async function Qn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Y,J,Lr,"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 ji}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",Ar={publisher:R,package_:v,name:"rootView"},jr={publisher:R,package_:v,name:"bind"},Vr={publisher:R,package_:v,name:"produces"},Nr={publisher:R,package_:v,name:"projections"},Or={publisher:R,package_:v,name:"where"},$r={publisher:R,package_:v,name:"value"},Ur={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,jr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=y(r,Vr);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=Dr(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=Tr(r,Or),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,Ar);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,Nr)){let a=r instanceof E?r:r instanceof k?K(e,r.subject):void 0;if(!a)continue;let s=be(a,$r),i=y(a,Ur);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=Hr(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(!Fr(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 Dr(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=Mr(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 Mr(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 Hr(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 Tr(n,e){let o=be(n,e);return o?[o]:_(n,e).filter(t=>t instanceof E)}function Fr(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{Lo as AmbiguousReferenceRule,ye as BooleanStatement,or as CANONICAL_FORM_VERSION,V as Carrier,$o as ClassDefinitionRule,Ko as ClassHierarchyCycleRule,kt as CompositeKanonakDocumentRepository,ar as DEFAULT_CONSENT_BINDING_PARAM,jt as DefinedKanonak,er as DiamondNameClashRule,Do as DisplayLensScopeRule,ft as DocumentLocation,Yt as EdgeType,E as EmbeddedKanonak,Po 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,Ro as ImportExistenceRule,me as InMemoryKanonakDocumentRepository,gt as KANONAK_USER_AGENT,At as Kanonak,ro as KanonakDocumentPositions,L as KanonakObjectParser,nr as KanonakObjectValidator,j as KanonakParser,Vt as KanonakUri,so as KanonakUriBuilder,co as KanonakUrlResolver,Ft as KanonakVocabulary,Fo as LINE_STYLES,ko as LinkTargetRule,q as ListStatement,D as LiteralKanonak,vt as LocalFirstRepository,It as LockAwareRepository,Yo as LookBandPathRule,Go as LookRenderer,Mo as LookSemanticSvgPathRule,Uo as MarkdownLinkRule,ge as MarkdownStatement,Io as NamespaceImportCycleRule,yo as NamespacePrefixRule,Xt as NodeType,ke as NumberStatement,ir as OAuthDiscovery,eo as OWL_RL_CLASSIFICATION_RULES,jo as ObjectPropertyValueValidationRule,po as OntologyValidationError,uo as OntologyValidationResult,Qo as OwlOneOfRule,A as PackageBuilder,bo as PackageHeaderRule,se as ProducerRepository,Vo as PropertyDomainRule,xo as PropertyHierarchyCycleRule,No as PropertyKindRangeConsistencyRule,oo as PropertyMetadata,Ao as PropertyRangeReferenceRule,wo as PropertyRangeRequiredRule,go 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,Oo as ReservedNameShadowRule,ho as ResourceNamingRule,$t as ResourceResolver,Bt as ResourceTypeClassifier,J as SHACL_PACKAGE,Y as SHACL_PUBLISHER,Z as SH_NODE_SHAPE,ze as SH_PROPERTY_SHAPE,We as SH_SHAPE,Ot as ScalarStatement,Xo as SequenceNarrativeRule,Zo as ShaclShapeRule,Nt as Statement,fe as StringStatement,Co as SubClassOfReferenceRule,vo as SubPropertyOfReferenceRule,g as SubjectKanonak,So as SubjectKanonakTypeRequiredRule,ur as TokenCredentialProvider,Zt as TripleStore,Ho as TxExpressionCompilesRule,Jo as TxExpressionPathRule,Ut as TypeResolver,_o as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,fo as ValidationCache,mo as ValidationContext,lo as ValidationSeverity,ji as VersionOperator,ue as ViewMaterializer,je as allowAllPolicy,Pt as assertHttpsUrl,wt as assertPackageIdentity,Lt as buildLocalFirstRepository,zo as buildOntologyModel,Qn as buildReportPackageAsync,te as buildShapesModel,tr 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,cr as createCredentialedFetch,st as createVersion,Gn as evaluateConformance,qt as extractMarkdownLinks,lr 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,rr as normalizeHost,sr as parseAuthChallenge,Se as parseKanonakAddress,Me as parseLockFile,ct as parseVersionString,ao as parseWithPositions,dt as pickHighestDocument,Wt as propertiesInScope,Bo as readSequenceConnectors,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,qo as supportedBandKeys,Ht as tripleKey,M as uriKey,Tt as uriTriple,at as versionOperatorFromChar,de as versionOperatorToChar,it as versionsEqual,Wo as walkSequence};
|
|
@@ -129,6 +129,15 @@ export declare class KanonakObjectParser implements IKanonakObjectParser {
|
|
|
129
129
|
* Matches the C# ResolveReference approach — uses ResourceResolver
|
|
130
130
|
* to build full Kanonak URIs from names like "forest" or "rdfs.Class".
|
|
131
131
|
*/
|
|
132
|
+
/**
|
|
133
|
+
* A reference through a LINK import (typescript#111): `alias.name` where
|
|
134
|
+
* the alias names an import with `mode: link`. The target is addressed, not
|
|
135
|
+
* loaded — so the URI is built from the import declaration alone, with no
|
|
136
|
+
* fetch: versionless (a data link floats to latest) unless the author
|
|
137
|
+
* pinned the import with `=`. `LinkTargetRule` verifies it one hop out at
|
|
138
|
+
* validate time. Returns undefined when the reference is not a link.
|
|
139
|
+
*/
|
|
140
|
+
private linkReference;
|
|
132
141
|
private resolveReference;
|
|
133
142
|
saveKanonaks(kanonaks: Kanonak[], documentRepository: IKanonakDocumentRepository): Promise<void>;
|
|
134
143
|
serializeToYaml(kanonaks: Kanonak[], namespaceString: string): Promise<string>;
|
package/dist/parsing/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as c,b as d,c as e,d as f}from"../chunk-
|
|
1
|
+
import{a as c,b as d,c as e,d as f}from"../chunk-BS7RRG7D.js";import{m as b}from"../chunk-PVUBHIU2.js";import{a}from"../chunk-HF5FJBS2.js";import"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
|
package/dist/reasoning/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-
|
|
1
|
+
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-EVMSO7HJ.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import{ca as e,da as f,e as a,f as b,g as c,i as d}from"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublisherConfigResolver, type PublisherConfig } from './PublisherConfig.js';
|
|
2
2
|
import type { AuthenticatedFetchFn } from '../auth/index.js';
|
|
3
|
-
import { type LockFile } from '../lock/LockFile.js';
|
|
3
|
+
import { type LockFile, type LockEntry } from '../lock/LockFile.js';
|
|
4
4
|
/**
|
|
5
5
|
* The client for a publisher's SERVED metadata: its `.well-known/kanonak.json`
|
|
6
6
|
* discovery config, its `kanonak.lock` (the resolution + integrity source for
|
|
@@ -20,6 +20,7 @@ export declare class PublisherIndex {
|
|
|
20
20
|
private readonly configResolver;
|
|
21
21
|
private readonly fetchFn;
|
|
22
22
|
private readonly lockCache;
|
|
23
|
+
private readonly packageLockCache;
|
|
23
24
|
constructor(options?: {
|
|
24
25
|
configResolver?: PublisherConfigResolver;
|
|
25
26
|
fetchFn?: AuthenticatedFetchFn;
|
|
@@ -36,5 +37,16 @@ export declare class PublisherIndex {
|
|
|
36
37
|
* then resolve such packages by direct fetch.
|
|
37
38
|
*/
|
|
38
39
|
getLock(publisher: string): Promise<LockFile | null>;
|
|
40
|
+
/**
|
|
41
|
+
* The package's own served lock — `https://{publisher}/{package}/kanonak.lock`
|
|
42
|
+
* — the SHARDED form of the root lock (typescript#111). A publisher with
|
|
43
|
+
* millions of packages cannot serve one lock for all of them (hundreds of
|
|
44
|
+
* megabytes before the first entity resolves), so the root lock is optional
|
|
45
|
+
* for such a publisher and each package carries its own pin at a URL that
|
|
46
|
+
* costs one small request. Same LockFile shape, one entry; returns that
|
|
47
|
+
* entry, or null when the package serves no lock. Fetched once per package
|
|
48
|
+
* and memoized like the root lock.
|
|
49
|
+
*/
|
|
50
|
+
getPackageLockEntry(publisher: string, packageName: string): Promise<LockEntry | null>;
|
|
39
51
|
private fetchLock;
|
|
40
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,m as r,n}from"../chunk-
|
|
1
|
+
import{h as e,m as r,n}from"../chunk-BZ3YTI3C.js";import"../chunk-SC5M74NM.js";import{a as o}from"../chunk-6VIUXP4N.js";import"../chunk-HF5FJBS2.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{n as HttpKanonakDocumentRepository,o as InMemoryKanonakDocumentRepository,e as PublisherConfigResolver,r as PublisherIndex};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as c,c as d,d as e,e as f,f as k,g as l,h as m,i as n}from"../chunk-
|
|
1
|
+
import{a as b,b as c,c as d,d as e,e as f,f as k,g as l,h as m,i as n}from"../chunk-IS3AQKB4.js";import{g,h,m as i,n as j}from"../chunk-BZ3YTI3C.js";import"../chunk-SC5M74NM.js";import{a}from"../chunk-6VIUXP4N.js";import"../chunk-HF5FJBS2.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,j as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,k as LocalFirstRepository,l as LockAwareRepository,h as PublisherConfigResolver,i as PublisherIndex,f as RepositoryFactory,n as buildLocalFirstRepository,m as collectKanonakFiles,g as defaultPublisherConfig,e as getGlobalCachePath};
|
|
@@ -33,6 +33,15 @@ export declare class ResourceTypeClassifier {
|
|
|
33
33
|
publisher: string;
|
|
34
34
|
package_: string;
|
|
35
35
|
}): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Does ANY of the resource's declared types name the core term `name`?
|
|
38
|
+
* A resource may carry several types (punning: `[rdfs.Class, OlympicSport]`
|
|
39
|
+
* — a class that is also an instance, which Wikidata does for every sport,
|
|
40
|
+
* profession and gender identity; typescript#111). Reading only the first
|
|
41
|
+
* type made such an entity not-a-class, so it failed `subClassOf` and was
|
|
42
|
+
* refused as an `owl.oneOf` member. The classifier answers over all of them.
|
|
43
|
+
*/
|
|
44
|
+
private static hasCoreType;
|
|
36
45
|
static isClassType(resource: SubjectKanonak): boolean;
|
|
37
46
|
static isDatatypeType(resource: SubjectKanonak): boolean;
|
|
38
47
|
static isDatatypePropertyType(resource: SubjectKanonak): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Import, KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
2
|
+
/**
|
|
3
|
+
* The two things an import can be (typescript#111).
|
|
4
|
+
*
|
|
5
|
+
* A DEPENDENCY is schema: the classes a `type` names, the properties and their
|
|
6
|
+
* ranges, the `subClassOf` chain. A document is meaningless without them, they
|
|
7
|
+
* are in its closure, and a cycle among them is an error.
|
|
8
|
+
*
|
|
9
|
+
* A LINK is data: an object-property value pointing at a resource in another
|
|
10
|
+
* package. It must resolve to a URI and be dereferenceable on demand, but the
|
|
11
|
+
* document is complete without loading it. Links are NOT in the closure, are
|
|
12
|
+
* exempt from the import-cycle rule, resolve version-agnostically unless the
|
|
13
|
+
* author pins with `=`, and are verified one hop out — the target package,
|
|
14
|
+
* never its closure — by `LinkTargetRule`. Any graph with mutual references
|
|
15
|
+
* (spouse ↔ spouse, part ↔ whole) is representable only this way.
|
|
16
|
+
*
|
|
17
|
+
* THE one place the distinction is read. Every seam that walks imports —
|
|
18
|
+
* resolver, closure, cycle rule, existence rule, the reference rules — asks
|
|
19
|
+
* this predicate rather than reading `mode` itself.
|
|
20
|
+
*/
|
|
21
|
+
export declare const IMPORT_MODES: readonly ["dependency", "link"];
|
|
22
|
+
export type ImportMode = (typeof IMPORT_MODES)[number];
|
|
23
|
+
/** True when the import is a data LINK rather than a schema dependency. */
|
|
24
|
+
export declare function isLinkImport(import_: Import): boolean;
|
|
25
|
+
/** The `publisher/package` keys this document LINKS (not depends on). */
|
|
26
|
+
export declare function linkedPackages(document: KanonakDocument): Set<string>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { ResourceResolver } from './ResourceResolver.js';
|
|
2
|
+
export { isLinkImport, linkedPackages, IMPORT_MODES, type ImportMode } from './importMode.js';
|
|
2
3
|
export type { ILogger } from './ResourceResolver.js';
|
|
3
4
|
export { assertPackageIdentity } from './assertPackageIdentity.js';
|
|
4
5
|
export { KanonakUri } from './KanonakUri.js';
|
package/dist/resolution/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as F}from"../chunk-XK24CN3C.js";import{a as o}from"../chunk-SC5M74NM.js";import{a as G}from"../chunk-PEJALHXK.js";import{a as q,b as r,c as s,d as t,ea as u,fa as v,ga as w,ha as x,ia as y,ja as z,ka as A,la as B,ma as C,na as D,oa as E}from"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import{a as p}from"../chunk-FUUTGGJS.js";import{a as l,b as m,c as n}from"../chunk-F67UH4FD.js";import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-QILEJIFU.js";export{l as IMPORT_MODES,p as KanonakUri,F as KanonakUriBuilder,G as KanonakUrlResolver,q as ResourceResolver,v as ResourceTypeClassifier,r as TypeResolver,o as assertPackageIdentity,c as compareVersions,E as contextTypesOf,u as corePropertyClassOf,f as createVersion,t as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,B as isDatatypePropertySubject,m as isLinkImport,i as isMajorCompatible,A as isObjectPropertySubject,z as isPropertySubject,n as linkedPackages,s as parseKanonakAddress,g as parseVersionString,k as pickHighestDocument,C as propertiesInScope,y as propertyClassOf,D as resolvePropertyStep,j as satisfiesVersionOperator,w as subjectUri,x as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
|
package/dist/search/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{d as g}from"../chunk-Z5Y4MCW5.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{ga as m,oa as S}from"../chunk-7UYXTYXC.js";import{c as v,m as p,t as E}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
|
|
2
2
|
Install it with:
|
|
3
3
|
npm install @huggingface/transformers
|
|
4
4
|
(underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
|