@kanonak-protocol/sdk 5.19.0 → 5.22.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.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-RLQFTA5D.js → chunk-4YMGH5RR.js} +1 -1
- package/dist/{chunk-35A2VF5S.js → chunk-6AIRUIV5.js} +1 -1
- package/dist/chunk-AB42RUYY.js +63 -0
- package/dist/{chunk-W35FCNM7.js → chunk-CCVH7TCQ.js} +2 -2
- package/dist/{chunk-5TI4E6M7.js → chunk-LCUTS2KL.js} +1 -1
- package/dist/chunk-PEB52US5.js +1 -0
- package/dist/chunk-SYNN77GG.js +152 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/look/LookRenderer.d.ts +162 -9
- package/dist/look/index.d.ts +1 -1
- package/dist/repositories/PublisherIndex.d.ts +12 -5
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/index.d.ts +0 -2
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/loadServerModel.d.ts +1 -1
- package/dist/server/route.d.ts +2 -1
- package/dist/transformations/index.js +2 -2
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/UnrenderableBandRule.d.ts +33 -0
- package/dist/validation/rules/repository/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-P36E2UV6.js +0 -152
- package/dist/chunk-PEUTCG3B.js +0 -1
- package/dist/chunk-QHABFCRC.js +0 -0
- package/dist/chunk-UYSEO3OT.js +0 -63
- package/dist/resolution/InstanceSearch.d.ts +0 -32
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Yt,b as Jt,c as Zt,d as Qt,e as T}from"./chunk-V3IPBWWU.js";import{a as Ge,b as We,c as ze}from"./chunk-35A2VF5S.js";import{a as er,c as Ee,e as qe,h as Xe,i as Ye,j as nr}from"./chunk-P36E2UV6.js";import{a as zt,b as qt,c as Xt,d as Go,e as be,f as Wo,g as zo,h as qo,i as Xo,j as Yo,k as Jo,l as Zo,m as tr}from"./chunk-5TI4E6M7.js";import{a as Qo}from"./chunk-LYSCTQC2.js";import"./chunk-QHABFCRC.js";import{a as lt,b as dt,c as mt,d as ft,e as yt,f as Ct,g as It,h as Kt,i as vt}from"./chunk-RLQFTA5D.js";import{a as kt,b as ht,c as gt,d as St,e as bt,f as Et,h as Pt,i as Me,j as De,k as $e,l as Te,m as Rt,n as _t}from"./chunk-W35FCNM7.js";import{a as le}from"./chunk-4NO7MHS7.js";import{a as no,b as to,c as oo,d as ro}from"./chunk-5NH5XDGO.js";import{a as ao,b as so}from"./chunk-PEUTCG3B.js";import{a as io}from"./chunk-PEJALHXK.js";import{a as xt}from"./chunk-SC5M74NM.js";import{A as Vo,B as jo,C as Uo,D as Ho,E as Mo,F as Do,G as $o,H as To,K as Fo,L as Bo,a as co,b as uo,c as po,d as lo,e as mo,f as fo,g as yo,h as ko,i as ho,j as go,k as So,l as bo,m as Eo,n as Po,o as Ro,p as xo,q as _o,r as Co,s as Io,t as Ko,u as vo,v as wo,w as No,x as Oo,y as Ao,z as Lo}from"./chunk-UYSEO3OT.js";import"./chunk-M443OYKT.js";import{a as x,b as D,c as ke,i as V,j as Se,k as Gt,l as Wt,m as O}from"./chunk-V6KIDED2.js";import{a as L}from"./chunk-NJ3AZYQD.js";import{a as Vt,b as jt,c as he,d as Ut,e as $,f as Ht,g as Mt,i as Dt,m as $t,o as Tt,p as g,q as Z,v as Ft,w as Bt,x as Q}from"./chunk-SVUMCLK5.js";import{a as wt,b as Nt,c as S,d as k,e as At,f as Lt,g as de,h as me,i as fe,j as q,k as ye,l as X,m as p,p as Fe,r as _,t as Be,u as w,v as Y,w as h,x as ge,y as N,z as J}from"./chunk-YW6P24RF.js";import{a as Ot}from"./chunk-FUUTGGJS.js";import{a as rt,b as pe,c as z,d as at,e as I,f as it,g as st,h as ct,i as ut,j as pt}from"./chunk-2ACBWC7K.js";import{a as eo}from"./chunk-ODIECDN7.js";async function Je(n){let e=await new O().parseKanonaks(n),o=await new T().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Ze(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Qe(n,e){let o=e??new le(new L);return{kind:"standalone",catalog:await new O().parseKanonaks(new J(n,o))}}var Pe="kanonak.org",Re="core-shacl",c=n=>({publisher:Pe,package_:Re,name:n}),en=c("NodeShape"),Tr=c("PropertyShape"),nn=c("targetClass"),tn=c("property"),on=c("path"),rn=c("minCount"),an=c("maxCount"),sn=c("datatype"),cn=c("class"),xe=c("in"),un=c("pattern"),pn=c("flags"),ln=c("minLength"),dn=c("maxLength"),mn=c("minInclusive"),fn=c("maxInclusive"),yn=c("message"),kn=c("targetNode"),hn=c("targetSubjectsOf"),gn=c("targetObjectsOf"),Sn=c("closed"),bn=c("ignoredProperties"),En=c("nodeKind"),Pn=c("IRI"),Rn=c("BlankNode"),xn=c("Literal"),_e=c("severity"),_n=c("Violation"),Cn=c("Warning"),In=c("Info"),Fr=c("ValidationReport"),Br=c("conforms"),Gr=c("result"),Wr=c("ValidationResult"),zr=c("focusNode"),qr=c("resultPath"),Xr=c("resultMessage"),Yr=c("resultSeverity"),Jr=c("sourceShape"),Zr=c("value"),Qr=c("sourceConstraintComponent"),Kn=c("MinCountConstraintComponent"),vn=c("MaxCountConstraintComponent"),wn=c("DatatypeConstraintComponent"),Nn=c("ClassConstraintComponent"),On=c("InConstraintComponent"),An=c("PatternConstraintComponent"),Ln=c("MinLengthConstraintComponent"),Vn=c("MaxLengthConstraintComponent"),jn=c("MinInclusiveConstraintComponent"),Un=c("MaxInclusiveConstraintComponent"),Hn=c("NodeKindConstraintComponent"),Ce=c("ClosedConstraintComponent");function H(n){return typeof n=="number"?n:void 0}function or(n){if(!n)return;let e=p(n);if(e===p(Pn))return"IRI";if(e===p(Rn))return"BlankNode";if(e===p(xn))return"Literal"}function Mn(n){if(!n)return;let e=p(n);if(e===p(_n))return"Violation";if(e===p(Cn))return"Warning";if(e===p(In))return"Info"}function Ie(n,e){let o=h(n,e);if(o)return[o];let t=[];for(let r of N(n,e))r instanceof k&&t.push(r.subject);return t}function rr(n,e){let o=h(n,on);if(!o)return;let t={path:o},r=H(w(n,rn)),a=H(w(n,an));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=H(w(n,ln)),i=H(w(n,dn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let u=H(w(n,mn)),d=H(w(n,fn));u!==void 0&&(t.minInclusive=u),d!==void 0&&(t.maxInclusive=d);let m=Y(n,un);if(m!==void 0){let P=Y(n,pn);t.pattern=P!==void 0?{regex:m,flags:P}:{regex:m}}if(Be(n,xe)){let P=[],j=[];for(let U of N(n,xe))U instanceof D?P.push(U.value):U instanceof k&&j.push(U.subject);P.length>0&&(t.inValues=P),j.length>0&&(t.inRefs=j)}let b=h(n,sn);b&&(t.datatype=b);let E=h(n,cn);E&&(t.classRef=E);let l=or(h(n,En));l&&(t.nodeKind=l);let f=Y(n,yn);f!==void 0&&(t.message=f);let y=Mn(h(n,_e))??e;return y&&(t.severity=y),t}function ee(n){let e=[];for(let o of n){if(!(o instanceof S)||!Fe(o,en))continue;let t=Mn(h(o,_e)),r={name:o.name,uri:g(o),targetClass:h(o,nn),targetNodes:Ie(o,kn),targetSubjectsOf:Ie(o,hn),targetObjectsOf:Ie(o,gn),closed:w(o,Sn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of N(o,bn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of N(o,tn)){let s;if(a instanceof x?s=a:a instanceof k&&(s=_(n,a.subject)),!s)continue;let i=rr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var C="kanonak.org/transformations",ne="values";var te="allowed",K=n=>({type:`${C}/VarRef`,varName:n}),Ke=n=>({type:`${C}/IntegerLiteral`,integerLiteral:n}),ar=n=>({type:`${C}/DecimalLiteral`,decimalLiteral:n}),Dn=n=>Number.isInteger(n)?Ke(n):ar(n),$n=n=>({type:`${C}/Count`,source:n}),Tn=(n,e)=>({type:`${C}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Fn=(n,e)=>({type:`${C}/LessThanOrEqual`,compareLeft:n,compareRight:e});function ve(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 oe(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Tn($n(K(ne)),Ke(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Fn($n(K(ne)),Ke(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${C}/Contains`,haystack:K(te),needle:K("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:ve(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Tn(K("v"),Dn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Fn(K("v"),Dn(n.maxInclusive))}),e}import{evaluate as sr,ExpressionError as cr}from"@kanonak-protocol/expression";function Wn(n,e){let o=ur(e)?e:ee(e),t=[];for(let r of o)for(let a of pr(n,r))mr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function ur(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function re(n){let e=n.predicate;return e instanceof k?e:void 0}function pr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof S),r=a=>{let s=g(a);o.set(s?p(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=p(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let u=g(i);u&&s.has(p(u))&&r(i)}}else for(let s of t)Q(s).some(u=>p(u)===a||Z(n.catalog,u).some(d=>p(d)===a))&&r(s)}for(let a of e.targetNodes){let s=_(n.catalog,a);s instanceof S&&r(s)}for(let a of e.targetSubjectsOf){let s=p(a);for(let i of t)i.statement.some(u=>{let d=re(u);return d&&p(d.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=p(a);for(let i of t)for(let u of i.statement){let d=re(u);if(!(!d||p(d.subject)!==s))for(let m of lr(u)){let b=_(n.catalog,m);b instanceof S&&r(b)}}}return[...o.values()]}function lr(n){return n instanceof q?[n.object.subject]:n instanceof X?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function dr(n,e,o){let t=[];for(let r of n.statement){let a=re(r);if(!(!a||p(a.subject)!==e)){if(r instanceof de||r instanceof ke)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof me)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof fe)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof q)t.push({kernel:{ref:p(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof ye)t.push(Bn(r.object,o,t.length));else if(r instanceof X){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:p(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof x)t.push(Bn(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 Bn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function mr(n,e,o,t){let r=g(o),a=r?p(r):`${o.namespace}/${o.name}`;for(let s of e.properties)yr(n,e,o,a,r,s,t);e.closed&&br(e,o,a,r,t)}function we(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??zn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function zn(n){return n.severity??"Violation"}var fr={minCount:Kn,maxCount:vn,in:On,pattern:An,minLength:Ln,maxLength:Vn,minInclusive:jn,maxInclusive:Un};function yr(n,e,o,t,r,a,s){let i=p(a.path),u=dr(o,i,t),d=a.severity??zn(e),m=a.path.name,b=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:p(l)}))],E=(l,f,y)=>{s.push(we(e,t,r,l,a.message??f,{resultPath:a.path,value:y?.literal,valueRef:y?.ref},d))};for(let l of oe(a)){let f=fr[l.component];if(l.per==="node"){Gn(l,{[ne]:u.map(P=>P.kernel),[te]:b})||E(f,l.component==="minCount"?`'${m}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${m}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let y of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&y.kind!=="string"){E(f,`'${m}' value is not a string; ${l.component} applies to string values.`,y);continue}Gn(l,{v:y.kernel,[te]:b})||E(f,kr(l,m,a,y),y)}}if(a.nodeKind)for(let l of u)hr(a.nodeKind,l)||E(Hn,`'${m}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=gr(a.datatype,l);f&&E(wn,`'${m}' ${f}`,l)}if(a.classRef)for(let l of u){let f=Sr(n,a.classRef,l);f&&E(Nn,`'${m}' ${f}`,l)}}function kr(n,e,o,t){let r=t.ref?p(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 Gn(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 cr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return sr(n.expr,void 0,o)===1}function hr(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 gr(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=Se(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 Sr(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=p(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`;let r=_(n.catalog,o.ref);return r instanceof S?Q(r).some(s=>p(s)===t||Z(n.catalog,s).some(i=>p(i)===t))?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`:`value ${p(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function br(n,e,o,t,r){let a=new Set([...n.properties.map(i=>p(i.path)),...n.ignoredProperties.map(i=>p(i))]),s=new Set;for(let i of e.statement){let u=re(i);if(!u)continue;let d=p(u.subject);a.has(d)||s.has(d)||(s.add(d),r.push(we(n,o,t,Ce,`'${e.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(we(n,o,t,Ce,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Ne from"js-yaml";import{VersionOperator as qn}from"@kanonak-protocol/types/document/models/enums";var Er="0.0.0",A=class{constructor(e,o=new L,t){this.repository=e;this.parser=o;this.objectParser=t??new O(this.parser)}repository;parser;objectParser;imports(){return new F}serializeValue(e,o){return Jn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Oe(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:Yn(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:Yn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Ne.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Xn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Ne.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),u=(await this.objectParser.parseKanonaks(new J(a,this.repository))).filter(d=>d instanceof S&&d.namespace===s&&d.name!==Xn);for(let d of u)d.namespace="ephemeral";return be(u)}},Xn="__pkgbuilder_probe__";function Yn(n){return new TextEncoder().encode(n).length}function Oe(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var F=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=qn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let u=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:u,match:a}),u}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_,I(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Er,r??o,qn.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:pe(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=B(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Jn(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=>Jn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof x)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(Pr(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 B(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Pr(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var Rr="1.1.0";async function Zn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Pe,Re,Rr,"sh"),r=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,I(i.version),i.package_)}.${i.name}`:u,a={},s=[];return n.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let m={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&&(m[`${t}.resultPath`]=r(i.resultPath,p(i.resultPath))),i.sourceShapeUri&&(m[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?m[`${t}.value`]=r(i.valueRef,p(i.valueRef)):i.value!==void 0&&(m[`${t}.value`]=i.value),a[d]=m}),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 Ui}from"@kanonak-protocol/types/document/models/enums";var ae=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}@${I(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=he(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 Ae={async authorize(){return{allowed:!0}}},Le={async record(){}},G=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},ie=class{inner;ctx;policy;meter;constructor(e,o,t=Ae,r=Le){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 G(e,o.reason)}};var R="kanonak.org",v="view",Qn="core-kanonak",xr={publisher:R,package_:v,name:"rootView"},_r={publisher:R,package_:v,name:"bind"},Cr={publisher:R,package_:v,name:"produces"},Ir={publisher:R,package_:v,name:"projections"},Kr={publisher:R,package_:v,name:"where"},vr={publisher:R,package_:v,name:"value"},wr={publisher:R,package_:v,name:"as"},se=class{constructor(e,o=new L){this.repository=e;this.parser=o;this.objectParser=new O(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=h(r,_r);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=h(r,Cr);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=Nr(r),u=et(t,R,Qn),d=et(t,R,v),m=this.builder.imports(),b=m.ensure(R,Qn,u,"ck"),E=m.ensure(R,v,d,"v"),l=m.ref(s),f=new Ye(this.repository,this.parser,this.objectParser),y=new qe(f,t),P=this.readProjections(t,r),j=Lr(r,Kr),U=this.findInstances(t,a,await this.reason(o)),Ve={},tt=new Set;for(let W of U){if(!await this.passesWhere(y,t,j,W))continue;let ue={type:l};for(let Ue of P){let ot=await this.evaluateValue(y,t,Ue.value,W),He=this.builder.serializeValue(nt(ot),m);He!==void 0&&(ue[m.ref(Ue.as)]=He)}let je=g(W);je&&(ue[`${E}.derivedFrom`]=m.ref(je)),Ve[this.rowName(W,tt)]=ue}let ce={};o.resolvedAt&&(ce[`${b}.resolvedAt`]=o.resolvedAt),o.invocationId&&(ce[`${b}.id`]=o.invocationId);let M=await this.builder.buildContentAddressed({publisher:i,book:m,body:Ve,contentHashProperty:`${b}.contentHash`,header:ce});return{yaml:M.yaml,contentHash:M.contentHash,packageName:M.packageName,publisher:M.publisher,rowCount:M.resourceCount}}resolveView(e,o){let t=_(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=h(t,xr);if(r){let a=_(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 N(o,Ir)){let a=r instanceof x?r:r instanceof k?_(e,r.subject):void 0;if(!a)continue;let s=ge(a,vr),i=h(a,wr);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new T({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Ar(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let u=r.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=$(g(i)),m=$(g(u));return d<m?-1:d>m?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Vr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=Xe(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=B(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function nt(n){return Ee(n)?n.value:Array.isArray(n)?n.map(nt):n}function Nr(n){let e=g(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function et(n,e,o){let t=Or(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 Or(n,e,o){let t;for(let r of n){if(!(r instanceof S))continue;let a=g(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?I(t):void 0}function Ar(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof S))continue;let r=g(t);if(!r||!r.version)continue;let a=$(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Lr(n,e){let o=ge(n,e);return o?[o]:N(n,e).filter(t=>t instanceof x)}function Vr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:Ee(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{vo as AmbiguousReferenceRule,fe as BooleanStatement,Wo as CANONICAL_FORM_VERSION,V as Carrier,Vo as ClassDefinitionRule,Po as ClassHierarchyCycleRule,mt as CompositeKanonakDocumentRepository,qo as DEFAULT_CONSENT_BINDING_PARAM,Nt as DefinedKanonak,Fo as DiamondNameClashRule,Uo as DisplayLensScopeRule,dt as DocumentLocation,qt as EdgeType,x as EmbeddedKanonak,So as EmbeddedKanonakTypeRule,ye as EmbeddedStatement,G as EntitlementDeniedError,ie as EntitlementProducer,lt as FileSystemKanonakDocumentRepository,eo as GitIgnoreFilter,Xt as GraphBuilder,_t as HttpKanonakDocumentRepository,Me as INTEGRITY_PREFIX,F as ImportBook,bo as ImportExistenceRule,le as InMemoryKanonakDocumentRepository,kt as KANONAK_USER_AGENT,wt as Kanonak,to as KanonakDocumentPositions,O as KanonakObjectParser,Bo as KanonakObjectValidator,L as KanonakParser,Ot as KanonakUri,ao as KanonakUriBuilder,io as KanonakUrlResolver,$t as KanonakVocabulary,X as ListStatement,D as LiteralKanonak,Ct as LocalFirstRepository,It as LockAwareRepository,Mo as LookBandPathRule,nr as LookRenderer,Ho as LookSemanticSvgPathRule,jo as MarkdownLinkRule,ke as MarkdownStatement,Io as NamespaceImportCycleRule,fo as NamespacePrefixRule,zt as NodeType,me as NumberStatement,Xo as OAuthDiscovery,Zt as OWL_RL_CLASSIFICATION_RULES,No as ObjectPropertyValueValidationRule,po as OntologyValidationError,co as OntologyValidationResult,To as OwlOneOfRule,A as PackageBuilder,go as PackageHeaderRule,ae as ProducerRepository,Oo as PropertyDomainRule,Ro as PropertyHierarchyCycleRule,Ao as PropertyKindRangeConsistencyRule,no as PropertyMetadata,wo as PropertyRangeReferenceRule,xo as PropertyRangeRequiredRule,ko as PropertyTypeSpecificityRule,Pt as PublisherConfigResolver,Rt as PublisherIndex,Jt as RDFS_RULES,T as Reasoner,Qt as ReasoningResult,k as ReferenceKanonak,q as ReferenceStatement,yt as RepositoryFactory,Lo as ReservedNameShadowRule,yo as ResourceNamingRule,Vt as ResourceResolver,Tt as ResourceTypeClassifier,Lt as ScalarStatement,$o as ShaclShapeRule,At as Statement,de as StringStatement,_o as SubClassOfReferenceRule,Co as SubPropertyOfReferenceRule,S as SubjectKanonak,ho as SubjectKanonakTypeRequiredRule,Zo as TokenCredentialProvider,Yt as TripleStore,Do as TxExpressionPathRule,jt as TypeResolver,Ko as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,mo as ValidationCache,lo as ValidationContext,uo as ValidationSeverity,Ui as VersionOperator,se as ViewMaterializer,Ae as allowAllPolicy,St as assertHttpsUrl,xt as assertPackageIdentity,vt as buildLocalFirstRepository,tr as buildOntologyModel,Zn as buildReportPackageAsync,ee as buildShapesModel,Go as canonicalForm,be as canonicalHash,Se as carrierOf,Kt as collectKanonakFiles,z as compareVersions,ze as computeIntegrity,Te as computeIntegrityAsync,Oe as contentAddressedName,Q as contextTypesOf,Jo as createCredentialedFetch,it as createVersion,Wn as evaluateConformance,Wt as extractMarkdownLinks,Qo as findDerivation,so as findInstancesByType,Gt as findMalformedReferences,ro as findMarkdownLinkAt,ve as foldFlagsIntoPattern,Ut as formatKanonakAddress,I as formatVersion,ft as getGlobalCachePath,gt as getKanonakUserAgent,ct as isCompatibleVersion,ut as isMajorCompatible,bt as kanonakFetch,Ge as loadLockFile,oe as lowerConstraint,Ht as makeUriKey,Le as noopMeter,zo as normalizeHost,Yo as parseAuthChallenge,he as parseKanonakAddress,De as parseLockFile,st as parseVersionString,oo as parseWithPositions,pt as pickHighestDocument,Ft as propertiesInScope,er as resolveDisplayValue,Bt as resolvePropertyStep,B as sanitizeName,We as saveLockFile,Ze as scopeFromCatalog,Qe as scopeFromDocumentAsync,Je as scopeFromRepositoryAsync,$e as serializeLockFile,Et as setKanonakFetchRetries,ht as setKanonakUserAgent,g as subjectUri,Z as superClassChain,Mt as tripleKey,$ as uriKey,Dt as uriTriple,rt as versionOperatorFromChar,pe as versionOperatorToChar,at as versionsEqual};
|
|
1
|
+
import{a as Yt,b as Jt,c as Zt,d as Qt,e as T}from"./chunk-V3IPBWWU.js";import{a as qe,b as Xe,c as Ye}from"./chunk-6AIRUIV5.js";import{a as zt,b as qt,c as Xt,d as zo,e as Ee,f as qo,g as Xo,h as Yo,i as Jo,j as Zo,k as Qo,l as er,m as tr}from"./chunk-LCUTS2KL.js";import{a as nr}from"./chunk-LYSCTQC2.js";import{a as lt,b as dt,c as mt,d as ft,e as yt,f as Ct,g as It,h as Kt,i as vt}from"./chunk-4YMGH5RR.js";import{a as kt,b as ht,c as gt,d as St,e as bt,f as Et,h as Pt,i as Me,j as De,k as $e,l as Te,m as Rt,n as _t}from"./chunk-CCVH7TCQ.js";import{a as no,b as to,c as oo,d as ro}from"./chunk-5NH5XDGO.js";import{a as ao}from"./chunk-PEB52US5.js";import{a as xt}from"./chunk-SC5M74NM.js";import{A as Lo,B as Vo,C as jo,D as Uo,E as Ho,F as To,G as Fo,H as Bo,K as Go,L as Wo,a as so,b as co,c as uo,d as po,e as lo,f as mo,g as fo,h as yo,i as ko,j as ho,k as go,l as So,m as bo,n as Eo,o as Po,p as Ro,q as xo,r as _o,s as Co,t as Io,u as Ko,v as vo,w as wo,x as No,y as Oo,z as Ao}from"./chunk-AB42RUYY.js";import"./chunk-M443OYKT.js";import{a as Mo,c as be,e as Ge,h as We,i as ze,j as Do,k as $o}from"./chunk-SYNN77GG.js";import{a as le}from"./chunk-4NO7MHS7.js";import{a as x,b as D,c as ke,i as V,j as Se,k as Gt,l as Wt,m as O}from"./chunk-V6KIDED2.js";import{a as L}from"./chunk-NJ3AZYQD.js";import{a as io}from"./chunk-PEJALHXK.js";import{a as Vt,b as jt,c as he,d as Ut,e as $,f as Ht,g as Mt,i as Dt,m as $t,o as Tt,p as g,q as Z,v as Ft,w as Bt,x as Q}from"./chunk-SVUMCLK5.js";import{a as wt,b as Nt,c as S,d as k,e as At,f as Lt,g as de,h as me,i as fe,j as q,k as ye,l as X,m as p,p as Fe,r as _,t as Be,u as w,v as Y,w as h,x as ge,y as N,z as J}from"./chunk-YW6P24RF.js";import{a as Ot}from"./chunk-FUUTGGJS.js";import{a as rt,b as pe,c as z,d as at,e as I,f as it,g as st,h as ct,i as ut,j as pt}from"./chunk-2ACBWC7K.js";import{a as eo}from"./chunk-ODIECDN7.js";async function Je(n){let e=await new O().parseKanonaks(n),o=await new T().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Ze(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Qe(n,e){let o=e??new le(new L);return{kind:"standalone",catalog:await new O().parseKanonaks(new J(n,o))}}var Pe="kanonak.org",Re="core-shacl",c=n=>({publisher:Pe,package_:Re,name:n}),en=c("NodeShape"),Tr=c("PropertyShape"),nn=c("targetClass"),tn=c("property"),on=c("path"),rn=c("minCount"),an=c("maxCount"),sn=c("datatype"),cn=c("class"),xe=c("in"),un=c("pattern"),pn=c("flags"),ln=c("minLength"),dn=c("maxLength"),mn=c("minInclusive"),fn=c("maxInclusive"),yn=c("message"),kn=c("targetNode"),hn=c("targetSubjectsOf"),gn=c("targetObjectsOf"),Sn=c("closed"),bn=c("ignoredProperties"),En=c("nodeKind"),Pn=c("IRI"),Rn=c("BlankNode"),xn=c("Literal"),_e=c("severity"),_n=c("Violation"),Cn=c("Warning"),In=c("Info"),Fr=c("ValidationReport"),Br=c("conforms"),Gr=c("result"),Wr=c("ValidationResult"),zr=c("focusNode"),qr=c("resultPath"),Xr=c("resultMessage"),Yr=c("resultSeverity"),Jr=c("sourceShape"),Zr=c("value"),Qr=c("sourceConstraintComponent"),Kn=c("MinCountConstraintComponent"),vn=c("MaxCountConstraintComponent"),wn=c("DatatypeConstraintComponent"),Nn=c("ClassConstraintComponent"),On=c("InConstraintComponent"),An=c("PatternConstraintComponent"),Ln=c("MinLengthConstraintComponent"),Vn=c("MaxLengthConstraintComponent"),jn=c("MinInclusiveConstraintComponent"),Un=c("MaxInclusiveConstraintComponent"),Hn=c("NodeKindConstraintComponent"),Ce=c("ClosedConstraintComponent");function H(n){return typeof n=="number"?n:void 0}function or(n){if(!n)return;let e=p(n);if(e===p(Pn))return"IRI";if(e===p(Rn))return"BlankNode";if(e===p(xn))return"Literal"}function Mn(n){if(!n)return;let e=p(n);if(e===p(_n))return"Violation";if(e===p(Cn))return"Warning";if(e===p(In))return"Info"}function Ie(n,e){let o=h(n,e);if(o)return[o];let t=[];for(let r of N(n,e))r instanceof k&&t.push(r.subject);return t}function rr(n,e){let o=h(n,on);if(!o)return;let t={path:o},r=H(w(n,rn)),a=H(w(n,an));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=H(w(n,ln)),i=H(w(n,dn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let u=H(w(n,mn)),d=H(w(n,fn));u!==void 0&&(t.minInclusive=u),d!==void 0&&(t.maxInclusive=d);let m=Y(n,un);if(m!==void 0){let P=Y(n,pn);t.pattern=P!==void 0?{regex:m,flags:P}:{regex:m}}if(Be(n,xe)){let P=[],j=[];for(let U of N(n,xe))U instanceof D?P.push(U.value):U instanceof k&&j.push(U.subject);P.length>0&&(t.inValues=P),j.length>0&&(t.inRefs=j)}let b=h(n,sn);b&&(t.datatype=b);let E=h(n,cn);E&&(t.classRef=E);let l=or(h(n,En));l&&(t.nodeKind=l);let f=Y(n,yn);f!==void 0&&(t.message=f);let y=Mn(h(n,_e))??e;return y&&(t.severity=y),t}function ee(n){let e=[];for(let o of n){if(!(o instanceof S)||!Fe(o,en))continue;let t=Mn(h(o,_e)),r={name:o.name,uri:g(o),targetClass:h(o,nn),targetNodes:Ie(o,kn),targetSubjectsOf:Ie(o,hn),targetObjectsOf:Ie(o,gn),closed:w(o,Sn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of N(o,bn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of N(o,tn)){let s;if(a instanceof x?s=a:a instanceof k&&(s=_(n,a.subject)),!s)continue;let i=rr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var C="kanonak.org/transformations",ne="values";var te="allowed",K=n=>({type:`${C}/VarRef`,varName:n}),Ke=n=>({type:`${C}/IntegerLiteral`,integerLiteral:n}),ar=n=>({type:`${C}/DecimalLiteral`,decimalLiteral:n}),Dn=n=>Number.isInteger(n)?Ke(n):ar(n),$n=n=>({type:`${C}/Count`,source:n}),Tn=(n,e)=>({type:`${C}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Fn=(n,e)=>({type:`${C}/LessThanOrEqual`,compareLeft:n,compareRight:e});function ve(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 oe(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Tn($n(K(ne)),Ke(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Fn($n(K(ne)),Ke(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${C}/Contains`,haystack:K(te),needle:K("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:ve(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Tn(K("v"),Dn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Fn(K("v"),Dn(n.maxInclusive))}),e}import{evaluate as sr,ExpressionError as cr}from"@kanonak-protocol/expression";function Wn(n,e){let o=ur(e)?e:ee(e),t=[];for(let r of o)for(let a of pr(n,r))mr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function ur(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function re(n){let e=n.predicate;return e instanceof k?e:void 0}function pr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof S),r=a=>{let s=g(a);o.set(s?p(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=p(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let u=g(i);u&&s.has(p(u))&&r(i)}}else for(let s of t)Q(s).some(u=>p(u)===a||Z(n.catalog,u).some(d=>p(d)===a))&&r(s)}for(let a of e.targetNodes){let s=_(n.catalog,a);s instanceof S&&r(s)}for(let a of e.targetSubjectsOf){let s=p(a);for(let i of t)i.statement.some(u=>{let d=re(u);return d&&p(d.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=p(a);for(let i of t)for(let u of i.statement){let d=re(u);if(!(!d||p(d.subject)!==s))for(let m of lr(u)){let b=_(n.catalog,m);b instanceof S&&r(b)}}}return[...o.values()]}function lr(n){return n instanceof q?[n.object.subject]:n instanceof X?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function dr(n,e,o){let t=[];for(let r of n.statement){let a=re(r);if(!(!a||p(a.subject)!==e)){if(r instanceof de||r instanceof ke)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof me)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof fe)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof q)t.push({kernel:{ref:p(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof ye)t.push(Bn(r.object,o,t.length));else if(r instanceof X){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:p(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof x)t.push(Bn(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 Bn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function mr(n,e,o,t){let r=g(o),a=r?p(r):`${o.namespace}/${o.name}`;for(let s of e.properties)yr(n,e,o,a,r,s,t);e.closed&&br(e,o,a,r,t)}function we(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??zn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function zn(n){return n.severity??"Violation"}var fr={minCount:Kn,maxCount:vn,in:On,pattern:An,minLength:Ln,maxLength:Vn,minInclusive:jn,maxInclusive:Un};function yr(n,e,o,t,r,a,s){let i=p(a.path),u=dr(o,i,t),d=a.severity??zn(e),m=a.path.name,b=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:p(l)}))],E=(l,f,y)=>{s.push(we(e,t,r,l,a.message??f,{resultPath:a.path,value:y?.literal,valueRef:y?.ref},d))};for(let l of oe(a)){let f=fr[l.component];if(l.per==="node"){Gn(l,{[ne]:u.map(P=>P.kernel),[te]:b})||E(f,l.component==="minCount"?`'${m}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${m}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let y of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&y.kind!=="string"){E(f,`'${m}' value is not a string; ${l.component} applies to string values.`,y);continue}Gn(l,{v:y.kernel,[te]:b})||E(f,kr(l,m,a,y),y)}}if(a.nodeKind)for(let l of u)hr(a.nodeKind,l)||E(Hn,`'${m}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=gr(a.datatype,l);f&&E(wn,`'${m}' ${f}`,l)}if(a.classRef)for(let l of u){let f=Sr(n,a.classRef,l);f&&E(Nn,`'${m}' ${f}`,l)}}function kr(n,e,o,t){let r=t.ref?p(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 Gn(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 cr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return sr(n.expr,void 0,o)===1}function hr(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 gr(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=Se(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 Sr(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=p(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`;let r=_(n.catalog,o.ref);return r instanceof S?Q(r).some(s=>p(s)===t||Z(n.catalog,s).some(i=>p(i)===t))?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`:`value ${p(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function br(n,e,o,t,r){let a=new Set([...n.properties.map(i=>p(i.path)),...n.ignoredProperties.map(i=>p(i))]),s=new Set;for(let i of e.statement){let u=re(i);if(!u)continue;let d=p(u.subject);a.has(d)||s.has(d)||(s.add(d),r.push(we(n,o,t,Ce,`'${e.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(we(n,o,t,Ce,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Ne from"js-yaml";import{VersionOperator as qn}from"@kanonak-protocol/types/document/models/enums";var Er="0.0.0",A=class{constructor(e,o=new L,t){this.repository=e;this.parser=o;this.objectParser=t??new O(this.parser)}repository;parser;objectParser;imports(){return new F}serializeValue(e,o){return Jn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Oe(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:Yn(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:Yn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Ne.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Xn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Ne.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),u=(await this.objectParser.parseKanonaks(new J(a,this.repository))).filter(d=>d instanceof S&&d.namespace===s&&d.name!==Xn);for(let d of u)d.namespace="ephemeral";return Ee(u)}},Xn="__pkgbuilder_probe__";function Yn(n){return new TextEncoder().encode(n).length}function Oe(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var F=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=qn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let u=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:u,match:a}),u}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_,I(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Er,r??o,qn.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:pe(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=B(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Jn(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=>Jn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof x)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(Pr(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 B(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Pr(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var Rr="1.1.0";async function Zn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Pe,Re,Rr,"sh"),r=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,I(i.version),i.package_)}.${i.name}`:u,a={},s=[];return n.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let m={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&&(m[`${t}.resultPath`]=r(i.resultPath,p(i.resultPath))),i.sourceShapeUri&&(m[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?m[`${t}.value`]=r(i.valueRef,p(i.valueRef)):i.value!==void 0&&(m[`${t}.value`]=i.value),a[d]=m}),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 Ui}from"@kanonak-protocol/types/document/models/enums";var ae=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}@${I(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=he(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 Ae={async authorize(){return{allowed:!0}}},Le={async record(){}},G=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},ie=class{inner;ctx;policy;meter;constructor(e,o,t=Ae,r=Le){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 G(e,o.reason)}};var R="kanonak.org",v="view",Qn="core-kanonak",xr={publisher:R,package_:v,name:"rootView"},_r={publisher:R,package_:v,name:"bind"},Cr={publisher:R,package_:v,name:"produces"},Ir={publisher:R,package_:v,name:"projections"},Kr={publisher:R,package_:v,name:"where"},vr={publisher:R,package_:v,name:"value"},wr={publisher:R,package_:v,name:"as"},se=class{constructor(e,o=new L){this.repository=e;this.parser=o;this.objectParser=new O(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=h(r,_r);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=h(r,Cr);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=Nr(r),u=et(t,R,Qn),d=et(t,R,v),m=this.builder.imports(),b=m.ensure(R,Qn,u,"ck"),E=m.ensure(R,v,d,"v"),l=m.ref(s),f=new ze(this.repository,this.parser,this.objectParser),y=new Ge(f,t),P=this.readProjections(t,r),j=Lr(r,Kr),U=this.findInstances(t,a,await this.reason(o)),Ve={},tt=new Set;for(let W of U){if(!await this.passesWhere(y,t,j,W))continue;let ue={type:l};for(let Ue of P){let ot=await this.evaluateValue(y,t,Ue.value,W),He=this.builder.serializeValue(nt(ot),m);He!==void 0&&(ue[m.ref(Ue.as)]=He)}let je=g(W);je&&(ue[`${E}.derivedFrom`]=m.ref(je)),Ve[this.rowName(W,tt)]=ue}let ce={};o.resolvedAt&&(ce[`${b}.resolvedAt`]=o.resolvedAt),o.invocationId&&(ce[`${b}.id`]=o.invocationId);let M=await this.builder.buildContentAddressed({publisher:i,book:m,body:Ve,contentHashProperty:`${b}.contentHash`,header:ce});return{yaml:M.yaml,contentHash:M.contentHash,packageName:M.packageName,publisher:M.publisher,rowCount:M.resourceCount}}resolveView(e,o){let t=_(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=h(t,xr);if(r){let a=_(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 N(o,Ir)){let a=r instanceof x?r:r instanceof k?_(e,r.subject):void 0;if(!a)continue;let s=ge(a,vr),i=h(a,wr);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new T({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Ar(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let u=r.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=$(g(i)),m=$(g(u));return d<m?-1:d>m?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Vr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=We(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=B(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function nt(n){return be(n)?n.value:Array.isArray(n)?n.map(nt):n}function Nr(n){let e=g(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function et(n,e,o){let t=Or(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 Or(n,e,o){let t;for(let r of n){if(!(r instanceof S))continue;let a=g(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?I(t):void 0}function Ar(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof S))continue;let r=g(t);if(!r||!r.version)continue;let a=$(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Lr(n,e){let o=ge(n,e);return o?[o]:N(n,e).filter(t=>t instanceof x)}function Vr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:be(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{Ko as AmbiguousReferenceRule,fe as BooleanStatement,qo as CANONICAL_FORM_VERSION,V as Carrier,Lo as ClassDefinitionRule,Eo as ClassHierarchyCycleRule,mt as CompositeKanonakDocumentRepository,Yo as DEFAULT_CONSENT_BINDING_PARAM,Nt as DefinedKanonak,Go as DiamondNameClashRule,jo as DisplayLensScopeRule,dt as DocumentLocation,qt as EdgeType,x as EmbeddedKanonak,go as EmbeddedKanonakTypeRule,ye as EmbeddedStatement,G as EntitlementDeniedError,ie as EntitlementProducer,lt as FileSystemKanonakDocumentRepository,eo as GitIgnoreFilter,Xt as GraphBuilder,_t as HttpKanonakDocumentRepository,Me as INTEGRITY_PREFIX,F as ImportBook,So as ImportExistenceRule,le as InMemoryKanonakDocumentRepository,kt as KANONAK_USER_AGENT,wt as Kanonak,to as KanonakDocumentPositions,O as KanonakObjectParser,Wo as KanonakObjectValidator,L as KanonakParser,Ot as KanonakUri,ao as KanonakUriBuilder,io as KanonakUrlResolver,$t as KanonakVocabulary,X as ListStatement,D as LiteralKanonak,Ct as LocalFirstRepository,It as LockAwareRepository,Ho as LookBandPathRule,Do as LookRenderer,Uo as LookSemanticSvgPathRule,Vo as MarkdownLinkRule,ke as MarkdownStatement,Co as NamespaceImportCycleRule,mo as NamespacePrefixRule,zt as NodeType,me as NumberStatement,Jo as OAuthDiscovery,Zt as OWL_RL_CLASSIFICATION_RULES,wo as ObjectPropertyValueValidationRule,uo as OntologyValidationError,so as OntologyValidationResult,Bo as OwlOneOfRule,A as PackageBuilder,ho as PackageHeaderRule,ae as ProducerRepository,No as PropertyDomainRule,Po as PropertyHierarchyCycleRule,Oo as PropertyKindRangeConsistencyRule,no as PropertyMetadata,vo as PropertyRangeReferenceRule,Ro as PropertyRangeRequiredRule,yo as PropertyTypeSpecificityRule,Pt as PublisherConfigResolver,Rt as PublisherIndex,Jt as RDFS_RULES,T as Reasoner,Qt as ReasoningResult,k as ReferenceKanonak,q as ReferenceStatement,yt as RepositoryFactory,Ao as ReservedNameShadowRule,fo as ResourceNamingRule,Vt as ResourceResolver,Tt as ResourceTypeClassifier,Lt as ScalarStatement,Fo as ShaclShapeRule,At as Statement,de as StringStatement,xo as SubClassOfReferenceRule,_o as SubPropertyOfReferenceRule,S as SubjectKanonak,ko as SubjectKanonakTypeRequiredRule,er as TokenCredentialProvider,Yt as TripleStore,To as TxExpressionPathRule,jt as TypeResolver,Io as UnresolvedPredicateRule,bo as UnresolvedReferenceRule,lo as ValidationCache,po as ValidationContext,co as ValidationSeverity,Ui as VersionOperator,se as ViewMaterializer,Ae as allowAllPolicy,St as assertHttpsUrl,xt as assertPackageIdentity,vt as buildLocalFirstRepository,tr as buildOntologyModel,Zn as buildReportPackageAsync,ee as buildShapesModel,zo as canonicalForm,Ee as canonicalHash,Se as carrierOf,Kt as collectKanonakFiles,z as compareVersions,Ye as computeIntegrity,Te as computeIntegrityAsync,Oe as contentAddressedName,Q as contextTypesOf,Qo as createCredentialedFetch,it as createVersion,Wn as evaluateConformance,Wt as extractMarkdownLinks,nr as findDerivation,Gt as findMalformedReferences,ro as findMarkdownLinkAt,ve as foldFlagsIntoPattern,Ut as formatKanonakAddress,I as formatVersion,ft as getGlobalCachePath,gt as getKanonakUserAgent,ct as isCompatibleVersion,ut as isMajorCompatible,bt as kanonakFetch,qe as loadLockFile,oe as lowerConstraint,Ht as makeUriKey,Le as noopMeter,Xo as normalizeHost,Zo as parseAuthChallenge,he as parseKanonakAddress,De as parseLockFile,st as parseVersionString,oo as parseWithPositions,pt as pickHighestDocument,Ft as propertiesInScope,Mo as resolveDisplayValue,Bt as resolvePropertyStep,B as sanitizeName,Xe as saveLockFile,Ze as scopeFromCatalog,Qe as scopeFromDocumentAsync,Je as scopeFromRepositoryAsync,$e as serializeLockFile,Et as setKanonakFetchRetries,ht as setKanonakUserAgent,g as subjectUri,Z as superClassChain,$o as supportedBandKeys,Mt as tripleKey,$ as uriKey,Dt as uriTriple,rt as versionOperatorFromChar,pe as versionOperatorToChar,at as versionsEqual};
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* - look.ChipRow : inline labeled chips from a list of properties
|
|
17
17
|
* - look.ReferenceList : labeled definition list of cross-reference groups
|
|
18
18
|
*
|
|
19
|
-
* Still ahead:
|
|
19
|
+
* Still ahead:
|
|
20
20
|
* FeaturedResource bands; token cascade resolution; CSS output via the
|
|
21
21
|
* stylesheet format; TransformationEngine integration.
|
|
22
22
|
*/
|
|
@@ -46,7 +46,7 @@ export interface TokenProvenance {
|
|
|
46
46
|
/** Name of the declaring subject (the instance itself, a class, or `Resource`). */
|
|
47
47
|
readonly sourceName: string;
|
|
48
48
|
/** Which cascade level supplied it. */
|
|
49
|
-
readonly level: 'instance' | 'class' | 'resource-floor';
|
|
49
|
+
readonly level: 'instance' | 'variant' | 'class' | 'publisher' | 'resource-floor';
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* The base stylesheet (everything after the `:root` token block) and where it
|
|
@@ -157,13 +157,35 @@ export declare class LookRenderer {
|
|
|
157
157
|
*
|
|
158
158
|
* Resolution order:
|
|
159
159
|
* 1. Instance direct (`derivation.tokens` on the instance itself)
|
|
160
|
-
* 2.
|
|
161
|
-
* 3.
|
|
162
|
-
* 4.
|
|
160
|
+
* 2. Matching instance variants (`look.variants` on the resolved view)
|
|
161
|
+
* 3. First-declared type's chain (BFS through subClassOf)
|
|
162
|
+
* 4. Subsequent declared types' chains (already-visited classes skipped)
|
|
163
|
+
* 5. The Publisher resource (`derivation.tokens` on the site's
|
|
164
|
+
* `ck.Publisher`) — site-wide defaults
|
|
165
|
+
* 6. Universal floor (`rdfs.Resource` defaults from look-tokens)
|
|
163
166
|
*
|
|
164
167
|
* Tokens are keyed by their local name (e.g. `"accent"`, not the
|
|
165
168
|
* full URI), assumed globally unique by convention.
|
|
166
169
|
*/
|
|
170
|
+
/**
|
|
171
|
+
* The variants whose condition matches this instance, in declaration order.
|
|
172
|
+
*
|
|
173
|
+
* `look.variants` lives on the resolved VIEW, so the same declaration that
|
|
174
|
+
* styles a class also carries the state-driven overrides for its instances
|
|
175
|
+
* — which is what makes severity-driven or status-driven theming expressible
|
|
176
|
+
* without a second mechanism.
|
|
177
|
+
*
|
|
178
|
+
* v0.1 of WhenCondition is equality only, as the vocabulary states: a
|
|
179
|
+
* `property` to read on the instance and an `equals` it must match. The
|
|
180
|
+
* vocabulary ranges `equals` at rdfs.Resource, so the primary comparison is
|
|
181
|
+
* REFERENCE identity by canonical URI — `core.critical` means that member,
|
|
182
|
+
* not the string "critical". A literal on either side is compared as text so
|
|
183
|
+
* an author who writes one gets a match rather than silence.
|
|
184
|
+
*
|
|
185
|
+
* A condition naming a property the instance does not carry simply does not
|
|
186
|
+
* match; that is absence, not error.
|
|
187
|
+
*/
|
|
188
|
+
private matchingVariants;
|
|
167
189
|
findCascadedTokens(instance: SubjectKanonak): Map<string, string>;
|
|
168
190
|
/**
|
|
169
191
|
* The token cascade with provenance: same walk as
|
|
@@ -353,6 +375,38 @@ export declare class LookRenderer {
|
|
|
353
375
|
* `renderDocument` to decide whether to emit an `<img>` figure.
|
|
354
376
|
*/
|
|
355
377
|
private hasSvgDerivation;
|
|
378
|
+
/**
|
|
379
|
+
* THE band dispatch table — the single source of truth for which bands this
|
|
380
|
+
* renderer implements.
|
|
381
|
+
*
|
|
382
|
+
* A table rather than an if-chain so the SAME list can be exported and read
|
|
383
|
+
* by validation: a band declared in a look but absent here is a band that
|
|
384
|
+
* renders as an HTML comment nobody sees, which is exactly the failure #100
|
|
385
|
+
* exists to close. With one list, a band cannot be added to the renderer
|
|
386
|
+
* without becoming visible to the validator, or removed without the
|
|
387
|
+
* validator noticing.
|
|
388
|
+
*/
|
|
389
|
+
private static readonly BAND_DISPATCH;
|
|
390
|
+
/** The band-type URIs the dispatch table covers — read by validation. */
|
|
391
|
+
static bandDispatchUris(): readonly Uri[];
|
|
392
|
+
/**
|
|
393
|
+
* A subject's OWN canonical URI — publisher, package, name and the version
|
|
394
|
+
* its namespace carries.
|
|
395
|
+
*
|
|
396
|
+
* The one derivation in this file. Everything here previously reconstructed
|
|
397
|
+
* it inline with `namespace.split('/')[1].split('@')[0]`, twenty-odd times,
|
|
398
|
+
* each an independent chance to get an edge case wrong. This delegates to
|
|
399
|
+
* the SDK's `subjectUri`, which parses through `parseKanonakAddress` rather
|
|
400
|
+
* than slicing strings.
|
|
401
|
+
*
|
|
402
|
+
* The one case the parser cannot answer is a SYNTHESIZED subject — the
|
|
403
|
+
* placeholder Publisher created when none is authored carries a bare-domain
|
|
404
|
+
* namespace, which is not a resource address. That falls back to the domain
|
|
405
|
+
* with an empty package, which is what the inline slicing produced too, so
|
|
406
|
+
* the degenerate case keeps its existing behaviour instead of becoming a
|
|
407
|
+
* silent undefined.
|
|
408
|
+
*/
|
|
409
|
+
private uriOf;
|
|
356
410
|
private renderBand;
|
|
357
411
|
/**
|
|
358
412
|
* Render a Timeline band — enumerate the `look.source` class's instances,
|
|
@@ -512,6 +566,41 @@ export declare class LookRenderer {
|
|
|
512
566
|
* neutral: the publisher supplies both the labels and the paths.
|
|
513
567
|
*/
|
|
514
568
|
private renderStatRow;
|
|
569
|
+
/**
|
|
570
|
+
* The bar markup for a value in [0, 1] — a compact inline gauge.
|
|
571
|
+
*
|
|
572
|
+
* Shared by the BarMeter band and by a PropertyTable rendering its cells
|
|
573
|
+
* `cellAs: look.BarMeter`, so a bar looks the same however it was reached.
|
|
574
|
+
* Out-of-range values are CLAMPED for the bar's width but the original is
|
|
575
|
+
* still shown as text: a score of 1.4 is a data problem worth seeing, and
|
|
576
|
+
* silently drawing it as a full bar would hide it.
|
|
577
|
+
*/
|
|
578
|
+
private barMarkup;
|
|
579
|
+
/**
|
|
580
|
+
* Render a BarMeter band — a numeric value in [0, 1] as a horizontal bar.
|
|
581
|
+
* Reads `look.metricPath`, a tx.Expression evaluated against the page
|
|
582
|
+
* instance, exactly as the vocabulary describes.
|
|
583
|
+
*
|
|
584
|
+
* The band form is the standalone use; the documented common use is a
|
|
585
|
+
* PropertyTable `cellAs` override, which routes through `barMarkup` above
|
|
586
|
+
* with the cell's own value as the input.
|
|
587
|
+
*/
|
|
588
|
+
private renderBarMeter;
|
|
589
|
+
/**
|
|
590
|
+
* Render a ResourceCount band — per-class count aggregates. `look.counts`
|
|
591
|
+
* is a list of ResourceCountEntry specs, each naming one class via
|
|
592
|
+
* `look.source`; the count is derived at render time by counting that
|
|
593
|
+
* class's instances in the catalog, and the label comes from the class's
|
|
594
|
+
* own `rdfs.label` (never a hand-written string), so the band stays
|
|
595
|
+
* ontology-neutral in the same way StatRow is.
|
|
596
|
+
*
|
|
597
|
+
* Each cell links to the class, so a count is a way IN to what it counts
|
|
598
|
+
* rather than a dead number. Entries whose `source` does not resolve to a
|
|
599
|
+
* class in the catalog are omitted rather than rendered as zero: absent
|
|
600
|
+
* and empty are different facts, and showing "0" for a class this page
|
|
601
|
+
* cannot see would assert the stronger one.
|
|
602
|
+
*/
|
|
603
|
+
private renderResourceCount;
|
|
515
604
|
/**
|
|
516
605
|
* Render a Horizon band — the instance's structured condition tree
|
|
517
606
|
* (e.g. an invalidationCondition). `look.source` is the property holding
|
|
@@ -646,11 +735,23 @@ export declare class LookRenderer {
|
|
|
646
735
|
*/
|
|
647
736
|
private renderInstances;
|
|
648
737
|
/**
|
|
649
|
-
* The
|
|
650
|
-
*
|
|
651
|
-
*
|
|
738
|
+
* The canonical keys of `target` plus every class that (transitively)
|
|
739
|
+
* descends from it — the one descendant set in this renderer, shared by
|
|
740
|
+
* transitive instance matching and every band that opts in with
|
|
741
|
+
* `look.transitive`.
|
|
742
|
+
*
|
|
743
|
+
* Decided by asking `superClassChain` — the SDK's ONE subClassOf traversal
|
|
744
|
+
* — of each DISTINCT type actually declared in the catalog, rather than by
|
|
745
|
+
* iterating catalog-wide subClassOf edges to a fixpoint. A catalog holds
|
|
746
|
+
* thousands of subjects but only dozens of types, so this walks dozens of
|
|
747
|
+
* times; the fixpoint re-scanned every subject on every round.
|
|
748
|
+
*
|
|
749
|
+
* Membership is compared by CANONICAL key (version dropped), matching how
|
|
750
|
+
* the rest of this renderer resolves classes across a multi-version
|
|
751
|
+
* workspace, while the walk itself starts at the version the parser
|
|
752
|
+
* resolved — which is what `superClassChain` is careful to preserve.
|
|
652
753
|
*/
|
|
653
|
-
private
|
|
754
|
+
private descendantTypeKeys;
|
|
654
755
|
/**
|
|
655
756
|
* True if `subject` has a reference (in a ReferenceStatement or a
|
|
656
757
|
* ListStatement) whose target's canonical key equals `targetKey`. When
|
|
@@ -710,6 +811,30 @@ export declare class LookRenderer {
|
|
|
710
811
|
* stated full design ("renders the resource's own derivation.look in
|
|
711
812
|
* compact variant") is deferred — that requires a variant system.
|
|
712
813
|
*/
|
|
814
|
+
/**
|
|
815
|
+
* A `look.source` resolved to what it selects: the class, plus optional
|
|
816
|
+
* ordering and cap.
|
|
817
|
+
*
|
|
818
|
+
* Three authored forms, all documented and all honoured, because the
|
|
819
|
+
* vocabulary describes `source` as a ResourceQuery while the shorthand is
|
|
820
|
+
* what actually worked (#97):
|
|
821
|
+
*
|
|
822
|
+
* - an INLINE embedded ResourceQuery under `look.source`;
|
|
823
|
+
* - a REFERENCE to a named ResourceQuery resource;
|
|
824
|
+
* - a BARE CLASS reference — the shorthand, kept because it is what
|
|
825
|
+
* existing packages author and it reads well when no ordering is wanted.
|
|
826
|
+
*
|
|
827
|
+
* Returns undefined when `source` names something that is neither a query
|
|
828
|
+
* nor a class, so the caller can fall through to its property handling.
|
|
829
|
+
*/
|
|
830
|
+
private resolveResourceQuery;
|
|
831
|
+
/**
|
|
832
|
+
* Order and cap a query's results. Ordering reads the `orderBy` property's
|
|
833
|
+
* value as text and compares lexically — the same rule the Timeline band
|
|
834
|
+
* uses, so ISO dates and numbers-as-strings sort as authors expect and the
|
|
835
|
+
* two bands cannot disagree about what ordering means.
|
|
836
|
+
*/
|
|
837
|
+
private applyQueryShape;
|
|
713
838
|
private renderResourceGrid;
|
|
714
839
|
/**
|
|
715
840
|
* Find every SubjectKanonak in the catalog whose declared `rdf:type` set
|
|
@@ -717,6 +842,23 @@ export declare class LookRenderer {
|
|
|
717
842
|
* ResourceGrid to enumerate instances for the grid. Skips the class
|
|
718
843
|
* itself and other classes.
|
|
719
844
|
*/
|
|
845
|
+
/**
|
|
846
|
+
* Instances of `classUri`. DIRECT by default; `transitive` widens to every
|
|
847
|
+
* declared subclass.
|
|
848
|
+
*
|
|
849
|
+
* Direct is the default because it is the existing, deliberate contract of
|
|
850
|
+
* the `Instances` band — "transitive on rdfs.Resource would be every
|
|
851
|
+
* resource" — and a band that silently enumerated a whole catalog would be
|
|
852
|
+
* a worse failure than one that under-reports. Authors widen with
|
|
853
|
+
* `look.transitive`, the vocabulary term that already means this.
|
|
854
|
+
*/
|
|
855
|
+
/**
|
|
856
|
+
* Whether a band opted into transitive (subclass-inclusive) matching with
|
|
857
|
+
* `look.transitive`. One reader so every band answers it the same way —
|
|
858
|
+
* the boolean and the string spelling both count, since a YAML `true` may
|
|
859
|
+
* arrive either way depending on how the value was authored.
|
|
860
|
+
*/
|
|
861
|
+
private readTransitive;
|
|
720
862
|
private findInstancesOfClass;
|
|
721
863
|
/**
|
|
722
864
|
* Render a publisher → package → resource breadcrumb derived from the
|
|
@@ -926,4 +1068,15 @@ export declare class LookRenderer {
|
|
|
926
1068
|
*/
|
|
927
1069
|
private readCommentForUri;
|
|
928
1070
|
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Canonical keys (`publisher/package/name`) of every band the renderer
|
|
1073
|
+
* implements — derived from the dispatch table itself, so it cannot drift
|
|
1074
|
+
* from what actually renders.
|
|
1075
|
+
*
|
|
1076
|
+
* Validation reads this to warn on a band that is valid against the look
|
|
1077
|
+
* vocabulary but has no renderer: such a band emits an HTML comment, which a
|
|
1078
|
+
* browser does not display, so the page silently loses that region
|
|
1079
|
+
* (kanonak-protocol/typescript#100).
|
|
1080
|
+
*/
|
|
1081
|
+
export declare function supportedBandKeys(): ReadonlySet<string>;
|
|
929
1082
|
export {};
|
package/dist/look/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { LookRenderer, type ResolvedLook, type TokenProvenance, type BaseStylesheetStatus, type StylesheetExplanation, } from './LookRenderer.js';
|
|
1
|
+
export { LookRenderer, supportedBandKeys, type ResolvedLook, type TokenProvenance, type BaseStylesheetStatus, type StylesheetExplanation, } from './LookRenderer.js';
|
|
2
2
|
export { resolveDisplayValue, type DisplayValue } from './displayValue.js';
|
|
@@ -3,11 +3,18 @@ import type { AuthenticatedFetchFn } from '../auth/index.js';
|
|
|
3
3
|
import { type LockFile } from '../lock/LockFile.js';
|
|
4
4
|
/**
|
|
5
5
|
* The client for a publisher's SERVED metadata: its `.well-known/kanonak.json`
|
|
6
|
-
* discovery config, its `kanonak.lock` (the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* discovery config, its `kanonak.lock` (the resolution + integrity source for
|
|
7
|
+
* RANGE imports), and the URLs of its raw package sources.
|
|
8
|
+
*
|
|
9
|
+
* There is deliberately NO version enumeration here. A publisher states its
|
|
10
|
+
* current line in the lock; it does not publish a catalog of everything it has
|
|
11
|
+
* ever released. Range imports therefore resolve against the lock's pin, while
|
|
12
|
+
* an exact pin resolves directly against the archived
|
|
13
|
+
* `{package}/{version}.kan.yml` URL — published versions are immutable, so the
|
|
14
|
+
* URL space IS the archive (see `HttpKanonakDocumentRepository`).
|
|
15
|
+
*
|
|
16
|
+
* (The class name is historical; it indexes nothing. `PublisherSource` is the
|
|
17
|
+
* accurate name whenever a breaking rename is acceptable.)
|
|
11
18
|
*/
|
|
12
19
|
export declare class PublisherIndex {
|
|
13
20
|
private readonly configResolver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,m as r,n}from"../chunk-
|
|
1
|
+
import{h as e,m as r,n}from"../chunk-CCVH7TCQ.js";import"../chunk-SC5M74NM.js";import{a as o}from"../chunk-4NO7MHS7.js";import"../chunk-NJ3AZYQD.js";import"../chunk-2ACBWC7K.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-4YMGH5RR.js";import{g,h,m as i,n as j}from"../chunk-CCVH7TCQ.js";import"../chunk-SC5M74NM.js";import{a}from"../chunk-4NO7MHS7.js";import"../chunk-NJ3AZYQD.js";import"../chunk-2ACBWC7K.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};
|
|
@@ -13,7 +13,5 @@ export { propertiesInScope, resolvePropertyStep, contextTypesOf, subjectUri, sup
|
|
|
13
13
|
export type { PropertyDescriptor, PropertyKind, StepResolution } from './TypeDirectedResolver.js';
|
|
14
14
|
export { ResourceTypeClassifier, corePropertyClassOf } from './ResourceTypeClassifier.js';
|
|
15
15
|
export type { PropertyClassKind } from './ResourceTypeClassifier.js';
|
|
16
|
-
export { findInstancesByType } from './InstanceSearch.js';
|
|
17
|
-
export type { InstanceSearchResult } from './InstanceSearch.js';
|
|
18
16
|
export { compareVersions, versionsEqual, formatVersion, parseVersionString, createVersion, isCompatibleVersion, isMajorCompatible, pickHighestDocument, versionOperatorFromChar, versionOperatorToChar, } from './VersionUtils.js';
|
|
19
17
|
export type { DocumentVersionPick } from './VersionUtils.js';
|
package/dist/resolution/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as B
|
|
1
|
+
import{a as B}from"../chunk-PEB52US5.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as C}from"../chunk-PEJALHXK.js";import{a as m,b as n,c as o,d as p,n as q,o as r,p as s,q as t,r as u,s as v,t as w,u as x,v as y,w as z,x as A}from"../chunk-SVUMCLK5.js";import"../chunk-YW6P24RF.js";import{a as l}from"../chunk-FUUTGGJS.js";import{a,b,c,d,e,f,g,h,i,j}from"../chunk-2ACBWC7K.js";export{l as KanonakUri,B as KanonakUriBuilder,C as KanonakUrlResolver,m as ResourceResolver,r as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,A as contextTypesOf,q as corePropertyClassOf,f as createVersion,p as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,x as isDatatypePropertySubject,i as isMajorCompatible,w as isObjectPropertySubject,v as isPropertySubject,o as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,y as propertiesInScope,u as propertyClassOf,z as resolvePropertyStep,s as subjectUri,t as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
|
package/dist/search/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as g}from"../chunk-SYNN77GG.js";import"../chunk-4NO7MHS7.js";import"../chunk-V6KIDED2.js";import"../chunk-NJ3AZYQD.js";import"../chunk-PEJALHXK.js";import{p as m,x as S}from"../chunk-SVUMCLK5.js";import{c as v,m as p,r as E}from"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-2ACBWC7K.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+`
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Pe}from"../chunk-35A2VF5S.js";import{j as oe}from"../chunk-P36E2UV6.js";import"../chunk-QHABFCRC.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-RLQFTA5D.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-W35FCNM7.js";import{a as ye}from"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import{a as xe}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-M443OYKT.js";import{m as te}from"../chunk-V6KIDED2.js";import{a as O}from"../chunk-NJ3AZYQD.js";import{c as Re}from"../chunk-SVUMCLK5.js";import{c as we,s as re}from"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import{c as V,e as K,f as W,g as ke}from"../chunk-2ACBWC7K.js";import{readFileSync as de,writeFileSync as Ce,mkdirSync as Fe}from"fs";import{join as se}from"path";import Me from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(t){return _e}function N(t){return`${t.publisher}/${t.package_}`}function z(t,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let o of t)if(o.origin==="missing"){let s=N(o),m=c[s]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${s} is MISSING (${o.reason??"unknown reason"}) \u2014 ${m}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${o.publisher}.`)}else o.resolvedButNotInCatalog&&r.push(`Render-stack package ${N(o)} resolved (${o.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let o of e)r.push(`Import edge ${o.fromNamespace} \u2192 ${o.publisher}/${o.packageName} ${o.constraint} did NOT resolve (${o.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${o.fromNamespace} authors against ${o.publisher}/${o.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${o.constraint}-compatible version of ${o.publisher}/${o.packageName} to the workspace or cache (kanonak install ${o.publisher}/${o.packageName}), or bump the import in ${o.fromNamespace}.`);return r}function ne(t){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,renderStack:d,producers:f,lockSource:l,configSource:h}=t,a=new Map,g=new Map,S=new Map,v=new Set;for(let $ of r){if(!($ instanceof we))continue;let w=$.namespace||"";if(!s.has(w))continue;a.set(`${w}/${$.name}`,$);let P=w.split("/")[1]??"",[_,M]=P.split("@");if(!_||!M)continue;let D=ke(M);D&&(v.has(P)||(v.add(P),g.has(_)||g.set(_,[]),g.get(_).push({verStr:M,version:D})),$.name===_&&S.set(P,$))}for(let $ of g.values())$.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,bySubject:a,pkgVersions:g,pkgSelfByVer:S,renderStack:d,...f?{producers:f}:{},...l?{lockSource:l}:{},...h?{configSource:h}:{}}}async function pe(t,e={}){let c=new O,r=new ye(c),o=[],s=[];for(let i of ee(t)){let u;try{u=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(u).metadata?.namespace_}catch{continue}if(!n?.version)continue;let p=n.version;s.push({publisher:n.publisher,package_:n.package_,verStr:K(p),version:p,source:u})}s.sort((i,u)=>V(u.version,i.version));for(let i of s)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),o.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let m=[...new Set(o.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!m.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)d=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${t}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,l=new Map;for(let i of o)i.publisher===d&&(f.add(`${i.publisher}/${i.package_}@${i.verStr}`),l.set(`${i.package_}@${i.verStr}`,i.source));let h=X(),a=new be(h,!0,c),g={};e.httpCache&&(g.getFromCache=e.httpCache.getFromCache,g.onFetch=e.httpCache.onFetch),e.fetchFn&&(g.fetchFn=e.fetchFn);let S=e.repository??new Se(r,a,new Z(g)),v=e.log??(()=>{}),$=q(void 0),w=[],P=i=>i.map(u=>u.metadata.namespace_?.version).filter(u=>u!==void 0).sort((u,n)=>V(n,u)).map(K);if(!e.repository){v(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${h}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let u of $){let n=N(u),p=await r.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(p.length>0){let y=P(p);w.push({...u,origin:"workspace",versions:y}),v(`[render-stack] ${n} \u2014 workspace (${y.join(", ")})`);continue}let k=await a.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(k.length>0){let y=P(k);w.push({...u,origin:"cache",versions:y}),v(`[render-stack] ${n} \u2014 cache (${y.join(", ")})`);continue}try{let b=(await i.getLock(u.publisher))?.packages[`${u.publisher}/${u.package_}`];if(!b){let j=`publisher ${u.publisher} reachable but its lock does not pin ${u.package_}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let C=b.version,T=b.resolved,Q=await(e.fetchFn?e.fetchFn(T,u.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${u.publisher}/${u.package_}@${C}`);try{let j=se(h,u.publisher);Fe(j,{recursive:!0}),Ce(se(j,`${u.package_}@${C}.kan.yml`),fe,"utf-8"),w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, but cache ${h} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(y){let b=`fetch failed: ${y.message}`;w.push({...u,origin:"missing",reason:b}),v(`[render-stack] ${n} \u2014 MISSING: ${b}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of $)_.push(...await S.getDocumentsByNamespaceAsync(i.publisher,i.package_));let M=[],D=await H(_,S,{onUnresolvedEdge:i=>M.push(i)}),A=S;if(!e.repository){for(let i of $)D.add(N(i));A=new G(S,D)}let B=await new te(c).parseKanonaks(A),ce=new oe(B),le=(i,u)=>re(B,{publisher:i,package_:u,name:u}).length>0,I;if(e.repository){I=[];for(let i of $){let u=await S.getDocumentsByNamespaceAsync(i.publisher,i.package_);I.push(u.length>0?{...i,origin:"repository",versions:P(u)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else I=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(I,M);for(let i of Y)v(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:h,packages:I,warnings:Y},E;try{E=de(se(t,"kanonak.lock"),"utf-8")}catch{E=De(d,o,c)}let L;try{L=de(se(t,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:m,catalog:B,lookRenderer:ce,localNamespaces:f,rawByNsKey:l,renderStack:J,...E?{lockSource:E}:{},...L?{configSource:L}:{}})}function De(t,e,c){let r=new Map;for(let s of e)s.publisher===t&&(r.has(s.package_)||r.set(s.package_,{verStr:s.verStr,source:s.source}));if(r.size===0)return;let o={};for(let s of[...r.keys()].sort()){let{verStr:m,source:d}=r.get(s),f={},l;try{l=c.parse(d).metadata?.imports}catch{l=void 0}for(let a of l?.[t]??[]){let g=r.get(a.packageName);g&&(f[`${t}/${a.packageName}`]=g.verStr)}let h={};for(let a of Object.keys(f).sort())h[a]=f[a];o[`${t}/${s}`]={version:m,resolved:`https://${t}/${s}/${m}.kan.yml`,integrity:Pe(d),dependencies:h}}return Me.dump({version:"1",lastUpdated:"",packages:o},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ke,readFileSync as Ee,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(t,e={}){let c=new O,r=Re(t),o=r.kind==="resource"?r.uri.publisher:r.publisher,s=e.log??(()=>{}),m=e.cacheRoot??X(),d=(n,p,k)=>je(m,n,`${p}@${k}.kan.yml`),f=new Set,l=new Set,h=new Map,a=new Z({getFromCache:(n,p,k)=>{let y=d(n,p,k),b=Ke(y)?Ee(y,"utf-8"):null;return b!==null&&f.add(`${n}/${p}`),b},onFetch:(n,p,k,y)=>{l.add(`${n}/${p}`);try{let b=je(m,n);Ae(b,{recursive:!0}),Ve(d(n,p,k),y,"utf-8")}catch(b){h.set(`${n}/${p}`,b.message),s(`[render] fetched ${n}/${p}@${k} but cache ${m} is NOT WRITABLE (${b.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),S;if(r.kind==="resource"){let n=r.uri.version;S=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;S=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else S=((await g.getConfig(o)).featured_packages??[]).map(p=>({package_:p}));let v=async(n,p,k)=>{try{let y=k?c.buildImport(p,"=",k,n):c.buildImport(p,"*","0.0.0",n),b=await a.getHighestCompatibleVersionAsync(n,y);return b?{doc:b}:{doc:null,error:`${n} did not resolve ${p}${k?`@${k}`:""} (not in its index, or unreachable)`}}catch(y){return{doc:null,error:y.message}}},$=[],w=[];for(let n of S){let{doc:p,error:k}=await v(o,n.package_,n.version);p?$.push(p):k&&w.push(k)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${o}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",M=n=>n.map(p=>p.metadata.namespace_?.version).filter(p=>p!==void 0).sort((p,k)=>V(k,p)).map(K);s(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${m}`);let D=[],A=[];for(let n of P){let p=N(n),{doc:k,error:y}=await v(n.publisher,n.package_,void 0);if(k){D.push(k);let b=M([k]),C=l.has(p)?"fetched":f.has(p)?"cache":"fetched";A.push({...n,origin:C,versions:b}),s(`[render-stack] ${p} \u2014 ${C} (${b.join(", ")})`+(h.has(p)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:y??"unresolved"}),s(`[render-stack] ${p} \u2014 MISSING: ${y??"unresolved"}`)}let B=[],ce=await H([...$,...D],a,{onUnresolvedEdge:n=>B.push(n)}),le=new G(a,ce),I=await new te(c).parseKanonaks(le),Y=new oe(I),J=A.map(n=>n.origin==="missing"||re(I,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),E=z(J,B);for(let n of E)s(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:m,packages:J,warnings:E},i=new Set,u=new Map;for(let n of await a.getAllDocumentsAsync()){let p=n.metadata.namespace_;if(!p?.version||p.publisher!==o)continue;let k=K(p.version),y=`${p.publisher}/${p.package_}@${k}`;i.add(y);let b=await a.getDocumentContentAsync(y);b!==null&&u.set(`${p.package_}@${k}`,b)}return ne({publisher:o,availablePublishers:[o],catalog:I,lookRenderer:Y,localNamespaces:i,rawByNsKey:u,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(t){let{lookRenderer:e,publisher:c,renderStack:r,catalog:o}=t,s=e.explainStylesheet(e.publisherSubject(c)),m=[...s.tokens.entries()].map(([a,g])=>({name:a,value:g.value,source:`${g.sourceNamespace}/${g.sourceName}`,level:g.level})),d=s.baseStylesheet,f={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},l=new Map;for(let a of o){let g=a.namespace;g&&l.set(g,(l.get(g)??0)+1)}let h=[...l.entries()].map(([a,g])=>({namespace:a,resources:g})).sort((a,g)=>a.namespace.localeCompare(g.namespace));return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(a=>({package_:N(a),origin:a.origin,...a.versions!==void 0?{versions:a.versions}:{},...a.reason!==void 0?{reason:a.reason}:{},...a.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:a.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:f,...s.look?{look:{sourceClass:`${s.look.sourceClass.publisher}/${s.look.sourceClass.package_}/${s.look.sourceClass.name}`}}:{}},catalog:h,warnings:[...r.warnings,...s.warnings.filter(a=>!r.warnings.includes(a))]}}function Be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ge(t){let e=Be,c=t.warnings.length===0,r=t.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':t.warnings.map(l=>`<div class="warn">\u26A0 ${e(l)}</div>`).join(`
|
|
1
|
+
import{c as Pe}from"../chunk-6AIRUIV5.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-4YMGH5RR.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-CCVH7TCQ.js";import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-M443OYKT.js";import{j as oe}from"../chunk-SYNN77GG.js";import{a as ye}from"../chunk-4NO7MHS7.js";import{m as te}from"../chunk-V6KIDED2.js";import{a as O}from"../chunk-NJ3AZYQD.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-SVUMCLK5.js";import{c as we,s as re}from"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import{c as V,e as K,f as W,g as ke}from"../chunk-2ACBWC7K.js";import{readFileSync as de,writeFileSync as Ce,mkdirSync as Fe}from"fs";import{join as se}from"path";import Me from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(t){return _e}function N(t){return`${t.publisher}/${t.package_}`}function z(t,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let o of t)if(o.origin==="missing"){let s=N(o),m=c[s]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${s} is MISSING (${o.reason??"unknown reason"}) \u2014 ${m}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${o.publisher}.`)}else o.resolvedButNotInCatalog&&r.push(`Render-stack package ${N(o)} resolved (${o.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let o of e)r.push(`Import edge ${o.fromNamespace} \u2192 ${o.publisher}/${o.packageName} ${o.constraint} did NOT resolve (${o.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${o.fromNamespace} authors against ${o.publisher}/${o.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${o.constraint}-compatible version of ${o.publisher}/${o.packageName} to the workspace or cache (kanonak install ${o.publisher}/${o.packageName}), or bump the import in ${o.fromNamespace}.`);return r}function ne(t){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,renderStack:d,producers:f,lockSource:l,configSource:h}=t,a=new Map,g=new Map,S=new Map,v=new Set;for(let $ of r){if(!($ instanceof we))continue;let w=$.namespace||"";if(!s.has(w))continue;a.set(`${w}/${$.name}`,$);let P=w.split("/")[1]??"",[_,M]=P.split("@");if(!_||!M)continue;let D=ke(M);D&&(v.has(P)||(v.add(P),g.has(_)||g.set(_,[]),g.get(_).push({verStr:M,version:D})),$.name===_&&S.set(P,$))}for(let $ of g.values())$.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,bySubject:a,pkgVersions:g,pkgSelfByVer:S,renderStack:d,...f?{producers:f}:{},...l?{lockSource:l}:{},...h?{configSource:h}:{}}}async function pe(t,e={}){let c=new O,r=new ye(c),o=[],s=[];for(let i of ee(t)){let u;try{u=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(u).metadata?.namespace_}catch{continue}if(!n?.version)continue;let p=n.version;s.push({publisher:n.publisher,package_:n.package_,verStr:K(p),version:p,source:u})}s.sort((i,u)=>V(u.version,i.version));for(let i of s)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),o.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let m=[...new Set(o.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!m.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)d=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${t}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,l=new Map;for(let i of o)i.publisher===d&&(f.add(`${i.publisher}/${i.package_}@${i.verStr}`),l.set(`${i.package_}@${i.verStr}`,i.source));let h=X(),a=new be(h,!0,c),g={};e.httpCache&&(g.getFromCache=e.httpCache.getFromCache,g.onFetch=e.httpCache.onFetch),e.fetchFn&&(g.fetchFn=e.fetchFn);let S=e.repository??new Se(r,a,new Z(g)),v=e.log??(()=>{}),$=q(void 0),w=[],P=i=>i.map(u=>u.metadata.namespace_?.version).filter(u=>u!==void 0).sort((u,n)=>V(n,u)).map(K);if(!e.repository){v(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${h}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let u of $){let n=N(u),p=await r.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(p.length>0){let y=P(p);w.push({...u,origin:"workspace",versions:y}),v(`[render-stack] ${n} \u2014 workspace (${y.join(", ")})`);continue}let k=await a.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(k.length>0){let y=P(k);w.push({...u,origin:"cache",versions:y}),v(`[render-stack] ${n} \u2014 cache (${y.join(", ")})`);continue}try{let b=(await i.getLock(u.publisher))?.packages[`${u.publisher}/${u.package_}`];if(!b){let j=`publisher ${u.publisher} reachable but its lock does not pin ${u.package_}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let C=b.version,T=b.resolved,Q=await(e.fetchFn?e.fetchFn(T,u.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${u.publisher}/${u.package_}@${C}`);try{let j=se(h,u.publisher);Fe(j,{recursive:!0}),Ce(se(j,`${u.package_}@${C}.kan.yml`),fe,"utf-8"),w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, but cache ${h} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(y){let b=`fetch failed: ${y.message}`;w.push({...u,origin:"missing",reason:b}),v(`[render-stack] ${n} \u2014 MISSING: ${b}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of $)_.push(...await S.getDocumentsByNamespaceAsync(i.publisher,i.package_));let M=[],D=await H(_,S,{onUnresolvedEdge:i=>M.push(i)}),A=S;if(!e.repository){for(let i of $)D.add(N(i));A=new G(S,D)}let B=await new te(c).parseKanonaks(A),ce=new oe(B),le=(i,u)=>re(B,{publisher:i,package_:u,name:u}).length>0,I;if(e.repository){I=[];for(let i of $){let u=await S.getDocumentsByNamespaceAsync(i.publisher,i.package_);I.push(u.length>0?{...i,origin:"repository",versions:P(u)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else I=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(I,M);for(let i of Y)v(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:h,packages:I,warnings:Y},E;try{E=de(se(t,"kanonak.lock"),"utf-8")}catch{E=De(d,o,c)}let L;try{L=de(se(t,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:m,catalog:B,lookRenderer:ce,localNamespaces:f,rawByNsKey:l,renderStack:J,...E?{lockSource:E}:{},...L?{configSource:L}:{}})}function De(t,e,c){let r=new Map;for(let s of e)s.publisher===t&&(r.has(s.package_)||r.set(s.package_,{verStr:s.verStr,source:s.source}));if(r.size===0)return;let o={};for(let s of[...r.keys()].sort()){let{verStr:m,source:d}=r.get(s),f={},l;try{l=c.parse(d).metadata?.imports}catch{l=void 0}for(let a of l?.[t]??[]){let g=r.get(a.packageName);g&&(f[`${t}/${a.packageName}`]=g.verStr)}let h={};for(let a of Object.keys(f).sort())h[a]=f[a];o[`${t}/${s}`]={version:m,resolved:`https://${t}/${s}/${m}.kan.yml`,integrity:Pe(d),dependencies:h}}return Me.dump({version:"1",lastUpdated:"",packages:o},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ke,readFileSync as Ee,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(t,e={}){let c=new O,r=Re(t),o=r.kind==="resource"?r.uri.publisher:r.publisher,s=e.log??(()=>{}),m=e.cacheRoot??X(),d=(n,p,k)=>je(m,n,`${p}@${k}.kan.yml`),f=new Set,l=new Set,h=new Map,a=new Z({getFromCache:(n,p,k)=>{let y=d(n,p,k),b=Ke(y)?Ee(y,"utf-8"):null;return b!==null&&f.add(`${n}/${p}`),b},onFetch:(n,p,k,y)=>{l.add(`${n}/${p}`);try{let b=je(m,n);Ae(b,{recursive:!0}),Ve(d(n,p,k),y,"utf-8")}catch(b){h.set(`${n}/${p}`,b.message),s(`[render] fetched ${n}/${p}@${k} but cache ${m} is NOT WRITABLE (${b.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),S;if(r.kind==="resource"){let n=r.uri.version;S=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;S=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else S=((await g.getConfig(o)).featured_packages??[]).map(p=>({package_:p}));let v=async(n,p,k)=>{try{let y=k?c.buildImport(p,"=",k,n):c.buildImport(p,"*","0.0.0",n),b=await a.getHighestCompatibleVersionAsync(n,y);return b?{doc:b}:{doc:null,error:`${n} did not resolve ${p}${k?`@${k}`:""} (not in its index, or unreachable)`}}catch(y){return{doc:null,error:y.message}}},$=[],w=[];for(let n of S){let{doc:p,error:k}=await v(o,n.package_,n.version);p?$.push(p):k&&w.push(k)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${o}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",M=n=>n.map(p=>p.metadata.namespace_?.version).filter(p=>p!==void 0).sort((p,k)=>V(k,p)).map(K);s(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${m}`);let D=[],A=[];for(let n of P){let p=N(n),{doc:k,error:y}=await v(n.publisher,n.package_,void 0);if(k){D.push(k);let b=M([k]),C=l.has(p)?"fetched":f.has(p)?"cache":"fetched";A.push({...n,origin:C,versions:b}),s(`[render-stack] ${p} \u2014 ${C} (${b.join(", ")})`+(h.has(p)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:y??"unresolved"}),s(`[render-stack] ${p} \u2014 MISSING: ${y??"unresolved"}`)}let B=[],ce=await H([...$,...D],a,{onUnresolvedEdge:n=>B.push(n)}),le=new G(a,ce),I=await new te(c).parseKanonaks(le),Y=new oe(I),J=A.map(n=>n.origin==="missing"||re(I,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),E=z(J,B);for(let n of E)s(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:m,packages:J,warnings:E},i=new Set,u=new Map;for(let n of await a.getAllDocumentsAsync()){let p=n.metadata.namespace_;if(!p?.version||p.publisher!==o)continue;let k=K(p.version),y=`${p.publisher}/${p.package_}@${k}`;i.add(y);let b=await a.getDocumentContentAsync(y);b!==null&&u.set(`${p.package_}@${k}`,b)}return ne({publisher:o,availablePublishers:[o],catalog:I,lookRenderer:Y,localNamespaces:i,rawByNsKey:u,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(t){let{lookRenderer:e,publisher:c,renderStack:r,catalog:o}=t,s=e.explainStylesheet(e.publisherSubject(c)),m=[...s.tokens.entries()].map(([a,g])=>({name:a,value:g.value,source:`${g.sourceNamespace}/${g.sourceName}`,level:g.level})),d=s.baseStylesheet,f={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},l=new Map;for(let a of o){let g=a.namespace;g&&l.set(g,(l.get(g)??0)+1)}let h=[...l.entries()].map(([a,g])=>({namespace:a,resources:g})).sort((a,g)=>a.namespace.localeCompare(g.namespace));return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(a=>({package_:N(a),origin:a.origin,...a.versions!==void 0?{versions:a.versions}:{},...a.reason!==void 0?{reason:a.reason}:{},...a.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:a.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:f,...s.look?{look:{sourceClass:`${s.look.sourceClass.publisher}/${s.look.sourceClass.package_}/${s.look.sourceClass.name}`}}:{}},catalog:h,warnings:[...r.warnings,...s.warnings.filter(a=>!r.warnings.includes(a))]}}function Be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ge(t){let e=Be,c=t.warnings.length===0,r=t.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':t.warnings.map(l=>`<div class="warn">\u26A0 ${e(l)}</div>`).join(`
|
|
2
2
|
`),o=t.renderStack.packages.map(l=>{let h=l.origin!=="missing"&&!l.resolvedButNotInCatalog,a=l.origin==="missing"?'<span class="bad">MISSING</span>':l.resolvedButNotInCatalog?`<span class="bad">${e(l.origin)} (not in catalog)</span>`:`<span class="good">${e(l.origin)}</span>`,g=l.reason?e(l.reason):e((l.versions??[]).join(", "));return`<tr class="${h?"":"row-bad"}"><td><code>${e(l.package_)}</code></td><td>${a}</td><td>${g}</td></tr>`}).join(`
|
|
3
3
|
`),s=t.stylesheet.baseStylesheet,m=s.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(s.source??"")}</code> (${s.bytes} bytes, ${e(s.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${s.problem?` \u2014 ${e(s.problem)}`:""}${s.candidates.length>0?`<br>candidates considered: ${s.candidates.map(l=>`<code>${e(l)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,d=t.stylesheet.tokens.map(l=>`<tr><td><code>--kan-${e(l.name)}</code></td><td><code>${e(l.value)}</code></td><td><code>${e(l.source)}</code></td><td>${e(l.level)}</td></tr>`).join(`
|
|
4
4
|
`),f=t.catalog.map(l=>`<tr><td><code>${e(l.namespace)}</code></td><td>${l.resources}</td></tr>`).join(`
|
|
@@ -61,4 +61,4 @@ ${t.stylesheet.look?`<p><span class="good">\u2713</span> Bands resolve from <cod
|
|
|
61
61
|
${f}
|
|
62
62
|
</table>
|
|
63
63
|
</body>
|
|
64
|
-
</html>`}var R={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},x=(t,e,c,r)=>({status:t,headers:{"Content-Type":e,...r||{}},body:c}),F=t=>x(404,R[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${t}</p>`),Le=t=>({status:301,headers:{Location:t},body:""}),Oe=t=>({status:302,headers:{Location:t},body:""});function Te(t){switch(t.kind){case"exact":return{operator:ie.Exact,version:W(t.major,t.minor,t.patch)};case"minor-pin":return{operator:ie.Compatible,version:W(t.major,t.minor,0)};case"major-pin":return{operator:ie.Major,version:W(t.major,0,0)};default:return{operator:ie.Any,version:W(0,0,0)}}}async function We(t,e,c,r){if(!r)return null;let o=t.producers?.find(f=>f.canProduce(t.publisher,e));if(!o)return null;let s=await o.resolveVersion(t.publisher,e,Te(c));if(!s)return null;let m=K(s);if(c.kind!=="exact")return Oe(`/${e}/${m}.kan.yml`);let{source:d}=await o.produce(t.publisher,e,s);return x(200,R[".kan.yml"],d)}function Ne(t,e,c){let r=t.pkgVersions.get(e);if(!r||r.length===0)return null;switch(c.kind){case"any":return r[0].verStr;case"major-pin":return r.find(o=>o.version.major===c.major)?.verStr??null;case"minor-pin":return r.find(o=>o.version.major===c.major&&o.version.minor===c.minor)?.verStr??null;case"exact":return r.find(o=>o.version.major===c.major&&o.version.minor===c.minor&&o.version.patch===c.patch)?.verStr??null;default:return null}}async function he(t,e,c=""){let{lookRenderer:r,publisher:o}=t;if(e==="/.well-known/kanonak.json")return t.configSource?x(200,R[".json"],t.configSource):x(200,R[".json"],JSON.stringify($e(),null,2));if(e==="/kanonak.lock")return t.lockSource?x(200,R[".kan.yml"],t.lockSource):F(e);if(e==="/.well-known/kanonak-render.json")return x(200,R[".json"],JSON.stringify(ae(t),null,2));if(e==="/.well-known/kanonak-render")return x(200,R[".html"],ge(ae(t)));if(e==="/"||e==="/index.html"||e==="/index.css"){let a=r.publisherSubject(o);return e==="/index.css"?x(200,R[".css"],r.renderStylesheet(a)):x(200,R[".html"],await r.renderDocument(a,{rootIndex:!0}))}let s=".html",m=!1,d=e;for(let a of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(a)){s=a,m=!0,d=e.slice(0,-a.length);break}let f=!m&&/application\/yaml|text\/yaml/i.test(c),l=d.endsWith("/");l&&d!=="/"&&(d=d.slice(0,-1));let h=xe.parse(d,o);if(!h)return F(e);if(h.kind==="package"){let a=Ne(t,h.package_,h.versionSpec);if(!a)return await We(t,h.package_,h.versionSpec,s===".kan.yml"||f)??F(e);if(s===".kan.yml"||f){let v=t.rawByNsKey.get(`${h.package_}@${a}`);return v!==void 0?x(200,R[".kan.yml"],v):F(e)}let g=t.pkgSelfByVer.get(`${h.package_}@${a}`);if(!g)return F(e);if(s===".css")return x(200,R[".css"],r.renderStylesheet(g));if(!l)return Le(d+"/");let S=h.versionSpec.kind==="any";if(S&&!r.hasDeclaredView(g)){let v=(t.pkgVersions.get(h.package_)||[]).map($=>$.verStr);return x(200,R[".html"],r.renderPackageVersionList(h.package_,v,g))}return x(200,R[".html"],await r.renderDocument(g,S?{bareOverview:!0}:void 0))}if(h.kind==="resource"){let a=Ne(t,h.package_,h.versionSpec);if(!a)return F(e);let g=t.bySubject.get(`${o}/${h.package_}@${a}/${h.name}`);if(!g)return F(e);switch(s){case".css":return x(200,R[".css"],r.renderStylesheet(g));case".svg":return x(200,R[".svg"],await r.renderSvg(g));case".md":{let S=r.renderRawMarkdown(g);return S===void 0?F(e):x(200,R[".md"],S)}default:return x(200,R[".html"],await r.renderDocument(g))}}return F(e)}import{readFileSync as Ue}from"fs";var me=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,c=new Set;if(this.options.root!==void 0){let r=new O;for(let o of ee(this.options.root))try{let s=r.parse(Ue(o,"utf-8")).metadata?.namespace_;if(!s?.version)continue;let m=s.version;e.add(`${s.publisher}/${s.package_}@${m.major}.${m.minor}.${m.patch}`),c.add(`${s.publisher}/${s.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:c},this.workspaceIndex}async modelFor(e,c,r){let o=this.getWorkspaceIndex(),s={...this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},...this.options.log?{log:this.options.log}:{}},m=c?r?o.exact.has(`${e}/${c}@${r}`):o.pkgs.has(`${e}/${c}`):[...o.pkgs].some(a=>a.startsWith(`${e}/`)),d,f;if(m&&this.options.root!==void 0){let a=this.options.root;d=`ws:${e}`,f=()=>pe(a,{publisher:e,...this.options.log?{log:this.options.log}:{}})}else{let a=c?r?`${e}/${c}@${r}`:`${e}/${c}`:e;d=`rm:${a}`,f=()=>ue(a,s)}let l=this.models.get(d);if(l)return l;let h=await f();return h.lookRenderer.setLinkMode("open-world"),this.models.set(d,h),h}async handle(e,c=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:Ie()};let o=r[0];if(!o.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let s=r.length>=2&&(r[1]==="index.html"||r[1]==="index.css"||r[1]==="
|
|
64
|
+
</html>`}var R={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},x=(t,e,c,r)=>({status:t,headers:{"Content-Type":e,...r||{}},body:c}),F=t=>x(404,R[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${t}</p>`),Le=t=>({status:301,headers:{Location:t},body:""}),Oe=t=>({status:302,headers:{Location:t},body:""});function Te(t){switch(t.kind){case"exact":return{operator:ie.Exact,version:W(t.major,t.minor,t.patch)};case"minor-pin":return{operator:ie.Compatible,version:W(t.major,t.minor,0)};case"major-pin":return{operator:ie.Major,version:W(t.major,0,0)};default:return{operator:ie.Any,version:W(0,0,0)}}}async function We(t,e,c,r){if(!r)return null;let o=t.producers?.find(f=>f.canProduce(t.publisher,e));if(!o)return null;let s=await o.resolveVersion(t.publisher,e,Te(c));if(!s)return null;let m=K(s);if(c.kind!=="exact")return Oe(`/${e}/${m}.kan.yml`);let{source:d}=await o.produce(t.publisher,e,s);return x(200,R[".kan.yml"],d)}function Ne(t,e,c){let r=t.pkgVersions.get(e);if(!r||r.length===0)return null;switch(c.kind){case"any":return r[0].verStr;case"major-pin":return r.find(o=>o.version.major===c.major)?.verStr??null;case"minor-pin":return r.find(o=>o.version.major===c.major&&o.version.minor===c.minor)?.verStr??null;case"exact":return r.find(o=>o.version.major===c.major&&o.version.minor===c.minor&&o.version.patch===c.patch)?.verStr??null;default:return null}}async function he(t,e,c=""){let{lookRenderer:r,publisher:o}=t;if(e==="/.well-known/kanonak.json")return t.configSource?x(200,R[".json"],t.configSource):x(200,R[".json"],JSON.stringify($e(),null,2));if(e==="/kanonak.lock")return t.lockSource?x(200,R[".kan.yml"],t.lockSource):F(e);if(e==="/.well-known/kanonak-render.json")return x(200,R[".json"],JSON.stringify(ae(t),null,2));if(e==="/.well-known/kanonak-render")return x(200,R[".html"],ge(ae(t)));if(e==="/"||e==="/index.html"||e==="/index.css"){let a=r.publisherSubject(o);return e==="/index.css"?x(200,R[".css"],r.renderStylesheet(a)):x(200,R[".html"],await r.renderDocument(a,{rootIndex:!0}))}let s=".html",m=!1,d=e;for(let a of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(a)){s=a,m=!0,d=e.slice(0,-a.length);break}let f=!m&&/application\/yaml|text\/yaml/i.test(c),l=d.endsWith("/");l&&d!=="/"&&(d=d.slice(0,-1));let h=xe.parse(d,o);if(!h)return F(e);if(h.kind==="package"){let a=Ne(t,h.package_,h.versionSpec);if(!a)return await We(t,h.package_,h.versionSpec,s===".kan.yml"||f)??F(e);if(s===".kan.yml"||f){let v=t.rawByNsKey.get(`${h.package_}@${a}`);return v!==void 0?x(200,R[".kan.yml"],v):F(e)}let g=t.pkgSelfByVer.get(`${h.package_}@${a}`);if(!g)return F(e);if(s===".css")return x(200,R[".css"],r.renderStylesheet(g));if(!l)return Le(d+"/");let S=h.versionSpec.kind==="any";if(S&&!r.hasDeclaredView(g)){let v=(t.pkgVersions.get(h.package_)||[]).map($=>$.verStr);return x(200,R[".html"],r.renderPackageVersionList(h.package_,v,g))}return x(200,R[".html"],await r.renderDocument(g,S?{bareOverview:!0}:void 0))}if(h.kind==="resource"){let a=Ne(t,h.package_,h.versionSpec);if(!a)return F(e);let g=t.bySubject.get(`${o}/${h.package_}@${a}/${h.name}`);if(!g)return F(e);switch(s){case".css":return x(200,R[".css"],r.renderStylesheet(g));case".svg":return x(200,R[".svg"],await r.renderSvg(g));case".md":{let S=r.renderRawMarkdown(g);return S===void 0?F(e):x(200,R[".md"],S)}default:return x(200,R[".html"],await r.renderDocument(g))}}return F(e)}import{readFileSync as Ue}from"fs";var me=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,c=new Set;if(this.options.root!==void 0){let r=new O;for(let o of ee(this.options.root))try{let s=r.parse(Ue(o,"utf-8")).metadata?.namespace_;if(!s?.version)continue;let m=s.version;e.add(`${s.publisher}/${s.package_}@${m.major}.${m.minor}.${m.patch}`),c.add(`${s.publisher}/${s.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:c},this.workspaceIndex}async modelFor(e,c,r){let o=this.getWorkspaceIndex(),s={...this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},...this.options.log?{log:this.options.log}:{}},m=c?r?o.exact.has(`${e}/${c}@${r}`):o.pkgs.has(`${e}/${c}`):[...o.pkgs].some(a=>a.startsWith(`${e}/`)),d,f;if(m&&this.options.root!==void 0){let a=this.options.root;d=`ws:${e}`,f=()=>pe(a,{publisher:e,...this.options.log?{log:this.options.log}:{}})}else{let a=c?r?`${e}/${c}@${r}`:`${e}/${c}`:e;d=`rm:${a}`,f=()=>ue(a,s)}let l=this.models.get(d);if(l)return l;let h=await f();return h.lookRenderer.setLinkMode("open-world"),this.models.set(d,h),h}async handle(e,c=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:Ie()};let o=r[0];if(!o.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let s=r.length>=2&&(r[1]==="index.html"||r[1]==="index.css"||r[1]==="kanonak.lock"||r[1]===".well-known"),m=!s&&r.length>=2?r[1]:void 0,d=!s&&r.length>=3&&/^\d+\.\d+\.\d+$/.test(r[2])?r[2]:void 0,f=await this.modelFor(o,m,d),l=e.endsWith("/")&&r.length>1?"/":"",h="/"+r.slice(1).join("/")+l,a=await he(f,h,c);return a.headers.Location?{...a,headers:{...a.headers,Location:`/${o}${a.headers.Location}`}}:a}};function Ie(){return'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kanonak origin</title></head><body style="font-family:system-ui;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>Kanonak request-driven origin</h1><p>Open a resource by its address:</p><p><code>/{publisher}/{package}/{version}/{resource}</code></p><p>e.g. <code>/kanonak.org/capabilities/2.0.0/Capability</code></p></body></html>'}export{G as ClosureScopedRepository,me as RequestRouter,_e as UNIVERSAL_RENDER_BASE,ae as buildRenderDiagnostics,z as buildRenderStackWarnings,H as deriveImportClosure,Ie as landingPage,ue as loadResourceModel,pe as loadServerModel,ge as renderDiagnosticsHtml,N as renderRefKey,q as resolveRenderContract,he as route};
|
|
@@ -7,7 +7,7 @@ import type { ServerModel, LoadServerModelOptions } from './types.js';
|
|
|
7
7
|
* an empty one throws, and an ambiguous one throws with the candidate list.
|
|
8
8
|
* ALL local files are still loaded into the resolution repository regardless,
|
|
9
9
|
* so cross-publisher imports between local packages keep resolving — only the
|
|
10
|
-
* SERVED set (routing, `
|
|
10
|
+
* SERVED set (routing, `kanonak.lock`, package list, raw source) is scoped to the
|
|
11
11
|
* chosen publisher.
|
|
12
12
|
*
|
|
13
13
|
* Raw `.kan.yml` source is read here and held in the model so `route` performs
|
package/dist/server/route.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type { ServerModel, RouteResponse } from './types.js';
|
|
|
3
3
|
* Map one request to a response, using the same `LookRenderer` calls
|
|
4
4
|
* `kanonak publish` makes — so a live response is byte-equivalent to the
|
|
5
5
|
* static page `publish` would write — plus the machine-facing endpoints
|
|
6
|
-
*
|
|
6
|
+
* (`/.well-known/kanonak.json`, `/kanonak.lock`, raw `.kan.yml`), which
|
|
7
|
+
* `publish` freezes to disk rather than omitting.
|
|
7
8
|
*
|
|
8
9
|
* Pure: `pathname` in, response out. No filesystem or network I/O — raw
|
|
9
10
|
* sources are preloaded in the model. `accept` disambiguates the no-extension
|