@kanonak-protocol/sdk 4.10.0 → 4.12.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.
Files changed (38) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +2 -2
  3. package/dist/canonical/CanonicalHash.d.ts +13 -17
  4. package/dist/canonical/Datatypes.d.ts +19 -93
  5. package/dist/canonical/InputModel.d.ts +9 -46
  6. package/dist/chunk-4UT2CLAT.js +1 -0
  7. package/dist/{chunk-VKTFLHCW.js → chunk-7HRKWTBB.js} +1 -1
  8. package/dist/{chunk-PBNVHBS3.js → chunk-7TKJHKC2.js} +1 -1
  9. package/dist/chunk-BKVPSPG4.js +1 -0
  10. package/dist/{chunk-RWEGPZ23.js → chunk-CR55WXIN.js} +1 -1
  11. package/dist/{chunk-UK2OIPAB.js → chunk-IEOSSSB5.js} +1 -1
  12. package/dist/{chunk-RYOZTXI7.js → chunk-RGOBWOBB.js} +1 -1
  13. package/dist/{chunk-KGWDV7FW.js → chunk-U7LVFPEO.js} +1 -1
  14. package/dist/chunk-UBBZWWRB.js +86 -0
  15. package/dist/{chunk-OOR5SVNQ.js → chunk-V72IVYR4.js} +1 -1
  16. package/dist/{chunk-NV63IOB7.js → chunk-VWS25JH4.js} +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +26 -26
  19. package/dist/kanonaks/DefinedKanonak.d.ts +25 -0
  20. package/dist/parsing/index.js +1 -1
  21. package/dist/reasoning/KanonakVocabulary.d.ts +8 -0
  22. package/dist/reasoning/index.js +1 -1
  23. package/dist/resolution/index.js +1 -1
  24. package/dist/search/index.js +1 -1
  25. package/dist/server/index.js +1 -1
  26. package/dist/transformations/index.js +1 -1
  27. package/dist/uri-helpers/index.js +1 -1
  28. package/dist/validation/documentModel.d.ts +48 -0
  29. package/dist/validation/index.d.ts +1 -1
  30. package/dist/validation/index.js +1 -1
  31. package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +3 -4
  32. package/dist/validation/rules/repository/UnresolvedPredicateRule.d.ts +25 -0
  33. package/dist/validation/rules/repository/index.d.ts +1 -1
  34. package/package.json +3 -2
  35. package/dist/chunk-DSHPAWJQ.js +0 -1
  36. package/dist/chunk-IZRPJCQW.js +0 -86
  37. package/dist/chunk-T3JR2SV6.js +0 -1
  38. package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +0 -35
@@ -1,5 +1,30 @@
1
1
  import { Kanonak } from './Kanonak.js';
2
2
  import type { IStatement } from '../statements/IStatement.js';
3
+ /**
4
+ * A property authored on an entity whose predicate did NOT resolve to a
5
+ * defined property in the document's import closure — captured instead of
6
+ * silently dropped, so validation can see it. This is the object model's
7
+ * record of "this key names no known property here" (a typo like
8
+ * `rdfs.lable`, an unimported namespace, or a name that resolves to a
9
+ * non-property). The owning kanonak (subject or embedded) carries its own
10
+ * list, so coverage is recursive at any embedding depth.
11
+ */
12
+ export interface UnresolvedPredicate {
13
+ /** The property key exactly as authored, e.g. `rdfs.lable`. */
14
+ readonly key: string;
15
+ /**
16
+ * Identifier (`publisher/package@version`) of the document that authored
17
+ * this property — for per-document error attribution after the open-world
18
+ * merge folds entities from several documents onto one subject URI.
19
+ */
20
+ readonly sourceDoc: string;
21
+ }
3
22
  export declare abstract class DefinedKanonak extends Kanonak {
4
23
  statement: IStatement[];
24
+ /**
25
+ * Authored properties whose predicate did not resolve to a defined property
26
+ * (see {@link UnresolvedPredicate}). Empty for a well-formed entity. The
27
+ * parser populates this where it would otherwise silently drop the property.
28
+ */
29
+ unresolvedPredicates: UnresolvedPredicate[];
5
30
  }
@@ -1 +1 @@
1
- import{a as c,b as d,c as e,d as f}from"../chunk-RYOZTXI7.js";import{i as b}from"../chunk-DSHPAWJQ.js";import{a}from"../chunk-NJ3AZYQD.js";import"../chunk-VKTFLHCW.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
1
+ import{a as c,b as d,c as e,d as f}from"../chunk-RGOBWOBB.js";import{h as b}from"../chunk-BKVPSPG4.js";import{a}from"../chunk-NJ3AZYQD.js";import"../chunk-7HRKWTBB.js";import"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
@@ -1,6 +1,14 @@
1
1
  import type { KanonakUri } from '../resolution/KanonakUri.js';
2
2
  import type { Version } from '@kanonak-protocol/types/document/models/types';
3
3
  import type { Vocabulary } from './Vocabulary.js';
4
+ /**
5
+ * True when `name` is a reserved built-in term (an RDF/RDFS/OWL/Kanonak
6
+ * structural predicate, annotation, class, or datatype — see
7
+ * {@link BUILTIN_HOMES}). Such a term is canonicalized to its core home by
8
+ * name, so it is always valid regardless of whether core-rdf/owl/kanonak is
9
+ * imported — and therefore must never be treated as an "unresolved predicate."
10
+ */
11
+ export declare function isBuiltinTerm(name: string): boolean;
4
12
  /**
5
13
  * Canonicalize a built-in URI in place against {@link BUILTIN_HOMES}.
6
14
  *
@@ -1 +1 @@
1
- import{a as g,b as h,c as i,d as j,e as k}from"../chunk-RWEGPZ23.js";import"../chunk-DSHPAWJQ.js";import"../chunk-NJ3AZYQD.js";import{d as a,e as b,f as c,h as d,i as e,j as f}from"../chunk-VKTFLHCW.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
1
+ import{a as g,b as h,c as i,d as j,e as k}from"../chunk-CR55WXIN.js";import"../chunk-BKVPSPG4.js";import"../chunk-NJ3AZYQD.js";import{d as a,e as b,f as c,h as d,j as e,k as f}from"../chunk-7HRKWTBB.js";import"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
@@ -1 +1 @@
1
- import{a as p,b as y}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-PEJALHXK.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w,h as x}from"../chunk-UK2OIPAB.js";import"../chunk-PBNVHBS3.js";import{b as m,c as n}from"../chunk-VKTFLHCW.js";import"../chunk-T3JR2SV6.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,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,x as contextTypesOf,f as createVersion,y as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,v as propertiesInScope,w as resolvePropertyStep,t as subjectUri,u as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
1
+ import{a as p,b as y}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-PEJALHXK.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w,h as x}from"../chunk-IEOSSSB5.js";import"../chunk-7TKJHKC2.js";import{b as m,c as n}from"../chunk-7HRKWTBB.js";import"../chunk-4UT2CLAT.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,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,x as contextTypesOf,f as createVersion,y as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,v as propertiesInScope,w as resolvePropertyStep,t as subjectUri,u as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
@@ -1,4 +1,4 @@
1
- import{a as g}from"../chunk-OOR5SVNQ.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import"../chunk-DSHPAWJQ.js";import"../chunk-NJ3AZYQD.js";import{d as m,h as S}from"../chunk-UK2OIPAB.js";import{a as p,f as E}from"../chunk-PBNVHBS3.js";import"../chunk-VKTFLHCW.js";import{c as v}from"../chunk-T3JR2SV6.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.
1
+ import{a as g}from"../chunk-V72IVYR4.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import"../chunk-BKVPSPG4.js";import"../chunk-NJ3AZYQD.js";import{d as m,h as S}from"../chunk-IEOSSSB5.js";import{a as p,f as E}from"../chunk-7TKJHKC2.js";import"../chunk-7HRKWTBB.js";import{c as v}from"../chunk-4UT2CLAT.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+`
@@ -1,4 +1,4 @@
1
- import{j as ee}from"../chunk-OOR5SVNQ.js";import"../chunk-QHABFCRC.js";import{a as he,d as z,f as ye,h as J}from"../chunk-GMEPM2QQ.js";import{d as me,e as fe,f as ke,g as O,h as Y}from"../chunk-JYBKSBB5.js";import{a as ge}from"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import{a as ve}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import{i as Q}from"../chunk-DSHPAWJQ.js";import{a as E}from"../chunk-NJ3AZYQD.js";import{b as X}from"../chunk-UK2OIPAB.js";import{g as Z}from"../chunk-PBNVHBS3.js";import"../chunk-VKTFLHCW.js";import{c as be}from"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import{c as M,e as F,f as L,g as ue}from"../chunk-2ACBWC7K.js";import{readFileSync as De,writeFileSync as _e,mkdirSync as je}from"fs";import{join as $e}from"path";function Se(t){let e=t.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function H(t,e){let n=new Set,r=[...t];for(;r.length>0;){let s=r.shift(),a=Se(s);if(!a||n.has(a))continue;n.add(a);let m=s.metadata?.imports;if(m)for(let[p,k]of Object.entries(m))for(let d of k)try{let u=await e.getHighestCompatibleVersionAsync(p,d);u&&r.push(u)}catch{}}return n}var V=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let r=Se(n);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var we=[{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 T(t){let e=t?.render;if(e&&e.length>0){let n=[];for(let r of e)try{let s=X(r);s.kind==="package"?n.push({publisher:s.publisher,package_:s.package_}):s.kind==="resource"&&n.push({publisher:s.uri.publisher,package_:s.uri.package_})}catch{}if(n.length>0)return n}return we}function C(t){return`${t.publisher}/${t.package_}`}function W(t){let e={"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"},n=[];for(let r of t)if(r.origin==="missing"){let s=C(r),a=e[s]??"whatever this package contributes to rendering is lost";n.push(`Render-stack package ${s} is MISSING (${r.reason??"unknown reason"}) \u2014 ${a}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${r.publisher}.`)}else r.resolvedButNotInCatalog&&n.push(`Render-stack package ${C(r)} resolved (${r.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);return n}function re(t){let{publisher:e,availablePublishers:n,catalog:r,lookRenderer:s,localNamespaces:a,rawByNsKey:m,renderStack:p,producers:k}=t,d=new Map,u=new Map,o=new Map,h=new Set;for(let y of r){if(!(y instanceof be))continue;let b=y.namespace||"";if(!a.has(b))continue;d.set(`${b}/${y.name}`,y);let $=b.split("/")[1]??"",[w,_]=$.split("@");if(!w||!_)continue;let I=ue(_);I&&(h.has($)||(h.add($),u.has(w)||u.set(w,[]),u.get(w).push({verStr:_,version:I})),y.name===w&&o.set($,y))}for(let y of u.values())y.sort((b,$)=>M($.version,b.version));return{publisher:e,availablePublishers:n,catalog:r,lookRenderer:s,localNamespaces:a,rawByNsKey:m,bySubject:d,pkgVersions:u,pkgSelfByVer:o,renderStack:p,...k?{producers:k}:{}}}async function se(t,e={}){let n=new E,r=new ge(n),s=[],a=[];for(let c of J(t)){let l;try{l=De(c,"utf-8")}catch{continue}let v;try{v=n.parse(l).metadata?.namespace_}catch{continue}if(!v?.version)continue;let N=v.version;a.push({publisher:v.publisher,package_:v.package_,verStr:F(N),version:N,source:l})}a.sort((c,l)=>M(l.version,c.version));for(let c of a)await r.saveDocumentAsync(n.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),s.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let m=[...new Set(s.map(c=>c.publisher))].sort(),p=e.publisher;if(p){if(!m.includes(p))throw new Error(`Publisher "${p}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)p=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 k=new Set,d=new Map;for(let c of s)c.publisher===p&&(k.add(`${c.publisher}/${c.package_}@${c.verStr}`),d.set(`${c.package_}@${c.verStr}`,c.source));let u=z(),o=new he(u,!0,n),h={};e.httpCache&&(h.getFromCache=e.httpCache.getFromCache,h.onFetch=e.httpCache.onFetch),e.fetchFn&&(h.fetchFn=e.fetchFn);let y=e.repository??new ye(r,o,new Y(h)),b=e.log??(()=>{}),$=T(void 0),w=[],_=c=>c.map(l=>l.metadata.namespace_?.version).filter(l=>l!==void 0).sort((l,v)=>M(v,l)).map(F);if(!e.repository){b(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${u}`);let c=e.fetchFn?new O({fetchFn:e.fetchFn}):new O;for(let l of $){let v=C(l),N=await r.getDocumentsByNamespaceAsync(l.publisher,l.package_);if(N.length>0){let S=_(N);w.push({...l,origin:"workspace",versions:S}),b(`[render-stack] ${v} \u2014 workspace (${S.join(", ")})`);continue}let U=await o.getDocumentsByNamespaceAsync(l.publisher,l.package_);if(U.length>0){let S=_(U);w.push({...l,origin:"cache",versions:S}),b(`[render-stack] ${v} \u2014 cache (${S.join(", ")})`);continue}try{let S=await c.getHighestVersion(l.publisher,l.package_);if(!S){let f=`publisher ${l.publisher} reachable but its index does not list ${l.package_}`;w.push({...l,origin:"missing",reason:f}),b(`[render-stack] ${v} \u2014 MISSING: ${f}`);continue}let j=await c.getPackageUrl(l.publisher,l.package_,S),i=await(e.fetchFn?e.fetchFn(j,l.publisher):me(j));if(!i.ok){let f=`fetch ${j} failed: HTTP ${i.status} ${i.statusText}`;w.push({...l,origin:"missing",reason:f}),b(`[render-stack] ${v} \u2014 MISSING: ${f}`);continue}let g=await i.text();await r.saveDocumentAsync(n.parse(g),`${l.publisher}/${l.package_}@${S}`);try{let f=$e(u,l.publisher);je(f,{recursive:!0}),_e($e(f,`${l.package_}@${S}.kan.yml`),g,"utf-8"),w.push({...l,origin:"fetched",versions:[S]}),b(`[render-stack] ${v}@${S} \u2014 fetched from ${j}, installed to cache`)}catch(f){w.push({...l,origin:"fetched",versions:[S]}),b(`[render-stack] ${v}@${S} \u2014 fetched from ${j}, but cache ${u} is NOT WRITABLE (${f.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(S){let j=`fetch failed: ${S.message}`;w.push({...l,origin:"missing",reason:j}),b(`[render-stack] ${v} \u2014 MISSING: ${j}`)}}}let I=y;if(!e.repository){let c=(await r.getAllDocumentsAsync()).filter(v=>v.metadata.namespace_?.publisher===p),l=await H(c,y);for(let v of $)l.add(C(v));I=new V(y,l)}let B=await new Q(n).parseKanonaks(I),oe=new ee(B),G=(c,l)=>Z(B,{publisher:c,package_:l,name:l}).length>0,A;if(e.repository){A=[];for(let c of $){let l=await y.getDocumentsByNamespaceAsync(c.publisher,c.package_);A.push(l.length>0?{...c,origin:"repository",versions:_(l)}:{...c,origin:"missing",reason:"not present in the caller-supplied repository"})}}else A=w.map(c=>c.origin==="missing"||G(c.publisher,c.package_)?c:{...c,resolvedButNotInCatalog:!0});let q=W(A);for(let c of q)b(`[render-stack] WARNING: ${c}`);return re({publisher:p,availablePublishers:m,catalog:B,lookRenderer:oe,localNamespaces:k,rawByNsKey:d,renderStack:{contractSource:"universal-default",cachePath:u,packages:A,warnings:q}})}import{existsSync as Ce,readFileSync as Ae,writeFileSync as Ie,mkdirSync as Ne}from"fs";import{join as Re}from"path";async function ae(t,e={}){let n=new E,r=X(t),s=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),m=e.cacheRoot??z(),p=(i,g,f)=>Re(m,i,`${g}@${f}.kan.yml`),k=new Set,d=new Set,u=new Map,o=new Y({getFromCache:(i,g,f)=>{let D=p(i,g,f),R=Ce(D)?Ae(D,"utf-8"):null;return R!==null&&k.add(`${i}/${g}`),R},onFetch:(i,g,f,D)=>{d.add(`${i}/${g}`);try{let R=Re(m,i);Ne(R,{recursive:!0}),Ie(p(i,g,f),D,"utf-8")}catch(R){u.set(`${i}/${g}`,R.message),a(`[render] fetched ${i}/${g}@${f} but cache ${m} is NOT WRITABLE (${R.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),h=new O(e.fetchFn?{fetchFn:e.fetchFn}:void 0),y;if(r.kind==="resource"){let i=r.uri.version;y=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;y=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else y=(await h.listLatestPackages(s)).map(g=>({package_:g.packageName}));let b=async(i,g,f)=>{try{let D=f?n.buildImport(g,"=",f,i):n.buildImport(g,"*","0.0.0",i),R=await o.getHighestCompatibleVersionAsync(i,D);return R?{doc:R}:{doc:null,error:`${i} did not resolve ${g}${f?`@${f}`:""} (not in its index, or unreachable)`}}catch(D){return{doc:null,error:D.message}}},$=[],w=[];for(let i of y){let{doc:g,error:f}=await b(s,i.package_,i.version);g?$.push(g):f&&w.push(f)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${s}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let _=await new ke(e.fetchFn).getConfig(s).catch(()=>{}),I=T(_),B=_?.render&&_.render.length>0?"publisher-well-known":"universal-default",oe=i=>i.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,f)=>M(f,g)).map(F);a(`[render-stack] resolving ${I.length} ambient look-stack package(s) (contract: ${B}); cache: ${m}`);let G=[],A=[];for(let i of I){let g=C(i),{doc:f,error:D}=await b(i.publisher,i.package_,void 0);if(f){G.push(f);let R=oe([f]),pe=d.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...i,origin:pe,versions:R}),a(`[render-stack] ${g} \u2014 ${pe} (${R.join(", ")})`+(u.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...i,origin:"missing",reason:D??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${D??"unresolved"}`)}let q=await H([...$,...G],o),de=new V(o,q),c=await new Q(n).parseKanonaks(de),l=new ee(c),v=A.map(i=>i.origin==="missing"||Z(c,{publisher:i.publisher,package_:i.package_,name:i.package_}).length>0?i:{...i,resolvedButNotInCatalog:!0}),N=W(v);for(let i of N)a(`[render-stack] WARNING: ${i}`);let U={contractSource:B,cachePath:m,packages:v,warnings:N},S=new Set,j=new Map;for(let i of await o.getAllDocumentsAsync()){let g=i.metadata.namespace_;if(!g?.version||g.publisher!==s)continue;let f=F(g.version),D=`${g.publisher}/${g.package_}@${f}`;S.add(D);let R=await o.getDocumentContentAsync(D);R!==null&&j.set(`${g.package_}@${f}`,R)}return re({publisher:s,availablePublishers:[s],catalog:c,lookRenderer:l,localNamespaces:S,rawByNsKey:j,renderStack:U})}import{VersionOperator as ne}from"@kanonak-protocol/types/document/models/enums";function te(t){let{lookRenderer:e,publisher:n,renderStack:r,catalog:s}=t,a=e.explainStylesheet(e.publisherSubject(n)),m=[...a.tokens.entries()].map(([o,h])=>({name:o,value:h.value,source:`${h.sourceNamespace}/${h.sourceName}`,level:h.level})),p=a.baseStylesheet,k={present:p.css!==void 0,...p.sourceNamespace!==void 0?{source:p.sourceNamespace}:{},...p.scope!==void 0?{scope:p.scope}:{},...p.css!==void 0?{bytes:p.css.length}:{},...p.problem!==void 0?{problem:p.problem}:{},candidates:p.candidates},d=new Map;for(let o of s){let h=o.namespace;h&&d.set(h,(d.get(h)??0)+1)}let u=[...d.entries()].map(([o,h])=>({namespace:o,resources:h})).sort((o,h)=>o.namespace.localeCompare(h.namespace));return{publisher:n,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(o=>({package_:C(o),origin:o.origin,...o.versions!==void 0?{versions:o.versions}:{},...o.reason!==void 0?{reason:o.reason}:{},...o.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:o.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},catalog:u,warnings:[...r.warnings,...a.warnings.filter(o=>!r.warnings.includes(o))]}}function Fe(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ie(t){let e=Fe,n=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(d=>`<div class="warn">\u26A0 ${e(d)}</div>`).join(`
1
+ import{j as ee}from"../chunk-V72IVYR4.js";import"../chunk-QHABFCRC.js";import{a as he,d as z,f as ye,h as J}from"../chunk-GMEPM2QQ.js";import{d as me,e as fe,f as ke,g as O,h as Y}from"../chunk-JYBKSBB5.js";import{a as ge}from"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import{a as ve}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import{h as Q}from"../chunk-BKVPSPG4.js";import{a as E}from"../chunk-NJ3AZYQD.js";import{b as X}from"../chunk-IEOSSSB5.js";import{g as Z}from"../chunk-7TKJHKC2.js";import"../chunk-7HRKWTBB.js";import{c as be}from"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import{c as M,e as F,f as L,g as ue}from"../chunk-2ACBWC7K.js";import{readFileSync as De,writeFileSync as _e,mkdirSync as je}from"fs";import{join as $e}from"path";function Se(t){let e=t.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function H(t,e){let n=new Set,r=[...t];for(;r.length>0;){let s=r.shift(),a=Se(s);if(!a||n.has(a))continue;n.add(a);let m=s.metadata?.imports;if(m)for(let[p,k]of Object.entries(m))for(let d of k)try{let u=await e.getHighestCompatibleVersionAsync(p,d);u&&r.push(u)}catch{}}return n}var V=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let r=Se(n);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var we=[{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 T(t){let e=t?.render;if(e&&e.length>0){let n=[];for(let r of e)try{let s=X(r);s.kind==="package"?n.push({publisher:s.publisher,package_:s.package_}):s.kind==="resource"&&n.push({publisher:s.uri.publisher,package_:s.uri.package_})}catch{}if(n.length>0)return n}return we}function C(t){return`${t.publisher}/${t.package_}`}function W(t){let e={"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"},n=[];for(let r of t)if(r.origin==="missing"){let s=C(r),a=e[s]??"whatever this package contributes to rendering is lost";n.push(`Render-stack package ${s} is MISSING (${r.reason??"unknown reason"}) \u2014 ${a}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${r.publisher}.`)}else r.resolvedButNotInCatalog&&n.push(`Render-stack package ${C(r)} resolved (${r.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);return n}function re(t){let{publisher:e,availablePublishers:n,catalog:r,lookRenderer:s,localNamespaces:a,rawByNsKey:m,renderStack:p,producers:k}=t,d=new Map,u=new Map,o=new Map,h=new Set;for(let y of r){if(!(y instanceof be))continue;let b=y.namespace||"";if(!a.has(b))continue;d.set(`${b}/${y.name}`,y);let $=b.split("/")[1]??"",[w,_]=$.split("@");if(!w||!_)continue;let I=ue(_);I&&(h.has($)||(h.add($),u.has(w)||u.set(w,[]),u.get(w).push({verStr:_,version:I})),y.name===w&&o.set($,y))}for(let y of u.values())y.sort((b,$)=>M($.version,b.version));return{publisher:e,availablePublishers:n,catalog:r,lookRenderer:s,localNamespaces:a,rawByNsKey:m,bySubject:d,pkgVersions:u,pkgSelfByVer:o,renderStack:p,...k?{producers:k}:{}}}async function se(t,e={}){let n=new E,r=new ge(n),s=[],a=[];for(let c of J(t)){let l;try{l=De(c,"utf-8")}catch{continue}let v;try{v=n.parse(l).metadata?.namespace_}catch{continue}if(!v?.version)continue;let N=v.version;a.push({publisher:v.publisher,package_:v.package_,verStr:F(N),version:N,source:l})}a.sort((c,l)=>M(l.version,c.version));for(let c of a)await r.saveDocumentAsync(n.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),s.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let m=[...new Set(s.map(c=>c.publisher))].sort(),p=e.publisher;if(p){if(!m.includes(p))throw new Error(`Publisher "${p}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)p=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 k=new Set,d=new Map;for(let c of s)c.publisher===p&&(k.add(`${c.publisher}/${c.package_}@${c.verStr}`),d.set(`${c.package_}@${c.verStr}`,c.source));let u=z(),o=new he(u,!0,n),h={};e.httpCache&&(h.getFromCache=e.httpCache.getFromCache,h.onFetch=e.httpCache.onFetch),e.fetchFn&&(h.fetchFn=e.fetchFn);let y=e.repository??new ye(r,o,new Y(h)),b=e.log??(()=>{}),$=T(void 0),w=[],_=c=>c.map(l=>l.metadata.namespace_?.version).filter(l=>l!==void 0).sort((l,v)=>M(v,l)).map(F);if(!e.repository){b(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${u}`);let c=e.fetchFn?new O({fetchFn:e.fetchFn}):new O;for(let l of $){let v=C(l),N=await r.getDocumentsByNamespaceAsync(l.publisher,l.package_);if(N.length>0){let S=_(N);w.push({...l,origin:"workspace",versions:S}),b(`[render-stack] ${v} \u2014 workspace (${S.join(", ")})`);continue}let U=await o.getDocumentsByNamespaceAsync(l.publisher,l.package_);if(U.length>0){let S=_(U);w.push({...l,origin:"cache",versions:S}),b(`[render-stack] ${v} \u2014 cache (${S.join(", ")})`);continue}try{let S=await c.getHighestVersion(l.publisher,l.package_);if(!S){let f=`publisher ${l.publisher} reachable but its index does not list ${l.package_}`;w.push({...l,origin:"missing",reason:f}),b(`[render-stack] ${v} \u2014 MISSING: ${f}`);continue}let j=await c.getPackageUrl(l.publisher,l.package_,S),i=await(e.fetchFn?e.fetchFn(j,l.publisher):me(j));if(!i.ok){let f=`fetch ${j} failed: HTTP ${i.status} ${i.statusText}`;w.push({...l,origin:"missing",reason:f}),b(`[render-stack] ${v} \u2014 MISSING: ${f}`);continue}let g=await i.text();await r.saveDocumentAsync(n.parse(g),`${l.publisher}/${l.package_}@${S}`);try{let f=$e(u,l.publisher);je(f,{recursive:!0}),_e($e(f,`${l.package_}@${S}.kan.yml`),g,"utf-8"),w.push({...l,origin:"fetched",versions:[S]}),b(`[render-stack] ${v}@${S} \u2014 fetched from ${j}, installed to cache`)}catch(f){w.push({...l,origin:"fetched",versions:[S]}),b(`[render-stack] ${v}@${S} \u2014 fetched from ${j}, but cache ${u} is NOT WRITABLE (${f.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(S){let j=`fetch failed: ${S.message}`;w.push({...l,origin:"missing",reason:j}),b(`[render-stack] ${v} \u2014 MISSING: ${j}`)}}}let I=y;if(!e.repository){let c=(await r.getAllDocumentsAsync()).filter(v=>v.metadata.namespace_?.publisher===p),l=await H(c,y);for(let v of $)l.add(C(v));I=new V(y,l)}let B=await new Q(n).parseKanonaks(I),oe=new ee(B),G=(c,l)=>Z(B,{publisher:c,package_:l,name:l}).length>0,A;if(e.repository){A=[];for(let c of $){let l=await y.getDocumentsByNamespaceAsync(c.publisher,c.package_);A.push(l.length>0?{...c,origin:"repository",versions:_(l)}:{...c,origin:"missing",reason:"not present in the caller-supplied repository"})}}else A=w.map(c=>c.origin==="missing"||G(c.publisher,c.package_)?c:{...c,resolvedButNotInCatalog:!0});let q=W(A);for(let c of q)b(`[render-stack] WARNING: ${c}`);return re({publisher:p,availablePublishers:m,catalog:B,lookRenderer:oe,localNamespaces:k,rawByNsKey:d,renderStack:{contractSource:"universal-default",cachePath:u,packages:A,warnings:q}})}import{existsSync as Ce,readFileSync as Ae,writeFileSync as Ie,mkdirSync as Ne}from"fs";import{join as Re}from"path";async function ae(t,e={}){let n=new E,r=X(t),s=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),m=e.cacheRoot??z(),p=(i,g,f)=>Re(m,i,`${g}@${f}.kan.yml`),k=new Set,d=new Set,u=new Map,o=new Y({getFromCache:(i,g,f)=>{let D=p(i,g,f),R=Ce(D)?Ae(D,"utf-8"):null;return R!==null&&k.add(`${i}/${g}`),R},onFetch:(i,g,f,D)=>{d.add(`${i}/${g}`);try{let R=Re(m,i);Ne(R,{recursive:!0}),Ie(p(i,g,f),D,"utf-8")}catch(R){u.set(`${i}/${g}`,R.message),a(`[render] fetched ${i}/${g}@${f} but cache ${m} is NOT WRITABLE (${R.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),h=new O(e.fetchFn?{fetchFn:e.fetchFn}:void 0),y;if(r.kind==="resource"){let i=r.uri.version;y=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;y=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else y=(await h.listLatestPackages(s)).map(g=>({package_:g.packageName}));let b=async(i,g,f)=>{try{let D=f?n.buildImport(g,"=",f,i):n.buildImport(g,"*","0.0.0",i),R=await o.getHighestCompatibleVersionAsync(i,D);return R?{doc:R}:{doc:null,error:`${i} did not resolve ${g}${f?`@${f}`:""} (not in its index, or unreachable)`}}catch(D){return{doc:null,error:D.message}}},$=[],w=[];for(let i of y){let{doc:g,error:f}=await b(s,i.package_,i.version);g?$.push(g):f&&w.push(f)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${s}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let _=await new ke(e.fetchFn).getConfig(s).catch(()=>{}),I=T(_),B=_?.render&&_.render.length>0?"publisher-well-known":"universal-default",oe=i=>i.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,f)=>M(f,g)).map(F);a(`[render-stack] resolving ${I.length} ambient look-stack package(s) (contract: ${B}); cache: ${m}`);let G=[],A=[];for(let i of I){let g=C(i),{doc:f,error:D}=await b(i.publisher,i.package_,void 0);if(f){G.push(f);let R=oe([f]),pe=d.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...i,origin:pe,versions:R}),a(`[render-stack] ${g} \u2014 ${pe} (${R.join(", ")})`+(u.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...i,origin:"missing",reason:D??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${D??"unresolved"}`)}let q=await H([...$,...G],o),de=new V(o,q),c=await new Q(n).parseKanonaks(de),l=new ee(c),v=A.map(i=>i.origin==="missing"||Z(c,{publisher:i.publisher,package_:i.package_,name:i.package_}).length>0?i:{...i,resolvedButNotInCatalog:!0}),N=W(v);for(let i of N)a(`[render-stack] WARNING: ${i}`);let U={contractSource:B,cachePath:m,packages:v,warnings:N},S=new Set,j=new Map;for(let i of await o.getAllDocumentsAsync()){let g=i.metadata.namespace_;if(!g?.version||g.publisher!==s)continue;let f=F(g.version),D=`${g.publisher}/${g.package_}@${f}`;S.add(D);let R=await o.getDocumentContentAsync(D);R!==null&&j.set(`${g.package_}@${f}`,R)}return re({publisher:s,availablePublishers:[s],catalog:c,lookRenderer:l,localNamespaces:S,rawByNsKey:j,renderStack:U})}import{VersionOperator as ne}from"@kanonak-protocol/types/document/models/enums";function te(t){let{lookRenderer:e,publisher:n,renderStack:r,catalog:s}=t,a=e.explainStylesheet(e.publisherSubject(n)),m=[...a.tokens.entries()].map(([o,h])=>({name:o,value:h.value,source:`${h.sourceNamespace}/${h.sourceName}`,level:h.level})),p=a.baseStylesheet,k={present:p.css!==void 0,...p.sourceNamespace!==void 0?{source:p.sourceNamespace}:{},...p.scope!==void 0?{scope:p.scope}:{},...p.css!==void 0?{bytes:p.css.length}:{},...p.problem!==void 0?{problem:p.problem}:{},candidates:p.candidates},d=new Map;for(let o of s){let h=o.namespace;h&&d.set(h,(d.get(h)??0)+1)}let u=[...d.entries()].map(([o,h])=>({namespace:o,resources:h})).sort((o,h)=>o.namespace.localeCompare(h.namespace));return{publisher:n,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(o=>({package_:C(o),origin:o.origin,...o.versions!==void 0?{versions:o.versions}:{},...o.reason!==void 0?{reason:o.reason}:{},...o.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:o.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},catalog:u,warnings:[...r.warnings,...a.warnings.filter(o=>!r.warnings.includes(o))]}}function Fe(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ie(t){let e=Fe,n=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(d=>`<div class="warn">\u26A0 ${e(d)}</div>`).join(`
2
2
  `),s=t.renderStack.packages.map(d=>{let u=d.origin!=="missing"&&!d.resolvedButNotInCatalog,o=d.origin==="missing"?'<span class="bad">MISSING</span>':d.resolvedButNotInCatalog?`<span class="bad">${e(d.origin)} (not in catalog)</span>`:`<span class="good">${e(d.origin)}</span>`,h=d.reason?e(d.reason):e((d.versions??[]).join(", "));return`<tr class="${u?"":"row-bad"}"><td><code>${e(d.package_)}</code></td><td>${o}</td><td>${h}</td></tr>`}).join(`
3
3
  `),a=t.stylesheet.baseStylesheet,m=a.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(a.source??"")}</code> (${a.bytes} bytes, ${e(a.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${a.problem?` \u2014 ${e(a.problem)}`:""}${a.candidates.length>0?`<br>candidates considered: ${a.candidates.map(d=>`<code>${e(d)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,p=t.stylesheet.tokens.map(d=>`<tr><td><code>--kan-${e(d.name)}</code></td><td><code>${e(d.value)}</code></td><td><code>${e(d.source)}</code></td><td>${e(d.level)}</td></tr>`).join(`
4
4
  `),k=t.catalog.map(d=>`<tr><td><code>${e(d.namespace)}</code></td><td>${d.resources}</td></tr>`).join(`
@@ -1,4 +1,4 @@
1
- import{b as Y,c as An,d as Sn,e as ce,f as Te,g as O,h as wn,i as X,j as q}from"../chunk-OOR5SVNQ.js";import{a as se}from"../chunk-NV63IOB7.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-RYOZTXI7.js";import"../chunk-PEJALHXK.js";import{a as kn,b as bn,c as hn,d as Dn}from"../chunk-SHDHMKMJ.js";import{i as ie}from"../chunk-DSHPAWJQ.js";import{a as ae}from"../chunk-NJ3AZYQD.js";import{b as L,c as A,f as S}from"../chunk-PBNVHBS3.js";import"../chunk-VKTFLHCW.js";import{b as N,c as D,d as K,g as M,h as P,i as F,j as W,l as H}from"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import{g as oe}from"../chunk-2ACBWC7K.js";var $e="kanonak.org",Ue="document-ast",i=e=>({publisher:$e,package_:Ue,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ue(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var j=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=xe(n.metadata,t),o=Le(n.children),s=["---",...r,"---","",o].join(`
1
+ import{b as Y,c as An,d as Sn,e as ce,f as Te,g as O,h as wn,i as X,j as q}from"../chunk-V72IVYR4.js";import{a as se}from"../chunk-VWS25JH4.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-RGOBWOBB.js";import"../chunk-PEJALHXK.js";import{a as kn,b as bn,c as hn,d as Dn}from"../chunk-SHDHMKMJ.js";import{h as ie}from"../chunk-BKVPSPG4.js";import{a as ae}from"../chunk-NJ3AZYQD.js";import{b as L,c as A,f as S}from"../chunk-7TKJHKC2.js";import"../chunk-7HRKWTBB.js";import{b as N,c as D,d as K,g as M,h as P,i as F,j as W,l as H}from"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import{g as oe}from"../chunk-2ACBWC7K.js";var $e="kanonak.org",Ue="document-ast",i=e=>({publisher:$e,package_:Ue,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ue(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var j=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=xe(n.metadata,t),o=Le(n.children),s=["---",...r,"---","",o].join(`
2
2
  `);return t?.trailingNewline&&(s.endsWith(`
3
3
  `)||(s+=`
4
4
  `)),s}};function xe(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(I(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(I(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(I),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=I(f??c),d=me(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function I(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function me(e,n){switch(e.kind){case"StringScalar":return Ve(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=me(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function Ve(e,n){return!n||ue(n,m.ESC_RAW)?e:ue(n,m.ESC_YAML_SAFE)?ve(e):e}function ve(e){return e.includes(`
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"../chunk-PBNVHBS3.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{n as SingleDocumentRepository,g as findAllResourcesByCanonicalUri,f as findSubjectByUri,e as findSubjectsByType,i as getDatatypeValue,l as getEmbeddedValue,m as getListValues,k as getReferenceUri,j as getStringValue,h as hasProperty,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"../chunk-7TKJHKC2.js";import"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{n as SingleDocumentRepository,g as findAllResourcesByCanonicalUri,f as findSubjectByUri,e as findSubjectsByType,i as getDatatypeValue,l as getEmbeddedValue,m as getListValues,k as getReferenceUri,j as getStringValue,h as hasProperty,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
@@ -0,0 +1,48 @@
1
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
+ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
3
+ import type { ValidationCache } from './ValidationCache.js';
4
+ import type { Kanonak } from '../kanonaks/Kanonak.js';
5
+ import { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
6
+ /**
7
+ * Shared object-model substrate for repository validation rules (#65).
8
+ *
9
+ * Every per-document rule wants the resolved object model walked recursively
10
+ * (subjects AND every embedded kanonak at any depth), instead of re-deriving it
11
+ * from raw `document.body`. These helpers provide that while preserving the
12
+ * batch performance contract: a multi-document pass parses the whole repo at
13
+ * most ONCE (the cache's memoized {@link ValidationCache.getKanonaks}); rules
14
+ * scope into that single parse rather than re-parsing per document.
15
+ */
16
+ /**
17
+ * The model to walk for one validation call: the whole-repo parse in a cached
18
+ * (batch) pass — shared across every document and rule — or a single-document
19
+ * parse for the cacheless CLI path. Returns ALL subjects in scope; the caller
20
+ * narrows to the document (by namespace, or by a statement's recorded source).
21
+ */
22
+ export declare function getCatalogKanonaks(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<Kanonak[]>;
23
+ /**
24
+ * The document's OWN-namespace subjects — the entities it authored under its
25
+ * own namespace, drawn from the single catalog parse. (Open-world
26
+ * augmentations an entity asserts about an IMPORTED URI live under that
27
+ * import's namespace and are out of scope here; a rule that must attribute
28
+ * those reads a statement's recorded source instead — see `sourceDoc` on
29
+ * captured data.)
30
+ */
31
+ export declare function getDocumentKanonaks(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<Kanonak[]>;
32
+ /** A DefinedKanonak visited during a walk, with a human-facing locator path. */
33
+ export interface WalkNode {
34
+ readonly kanonak: DefinedKanonak;
35
+ /** `subjectName` for a subject, `subjectName/childName/...` for embeddeds. */
36
+ readonly path: string;
37
+ }
38
+ /**
39
+ * Depth-first visit of every DefinedKanonak reachable from `roots`: each
40
+ * subject, then every embedded kanonak nested in its statements (single
41
+ * embeddeds and embedded list items), at any depth. The visitor sees one node
42
+ * at a time and should inspect only that node's OWN statements — the walk
43
+ * handles the recursion.
44
+ */
45
+ export declare function walkDefinedKanonaks(roots: Kanonak[], visit: (node: WalkNode) => void): void;
46
+ /** `publisher/package@major.minor.patch` — matches `SubjectKanonak.namespace`
47
+ * and the parser's `sourceDoc`. Undefined for a document without a namespace. */
48
+ export declare function namespaceOf(document: KanonakDocument): string | undefined;
@@ -8,4 +8,4 @@ export { KanonakObjectValidator } from './KanonakObjectValidator.js';
8
8
  export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
9
9
  export type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
10
10
  export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule } from './rules/document/index.js';
11
- export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
11
+ export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,L as J,M as K,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-IZRPJCQW.js";import"../chunk-SHDHMKMJ.js";import"../chunk-DSHPAWJQ.js";import"../chunk-NJ3AZYQD.js";import"../chunk-UK2OIPAB.js";import"../chunk-PBNVHBS3.js";import"../chunk-VKTFLHCW.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{w as AmbiguousReferenceRule,C as ClassDefinitionRule,n as ClassHierarchyCycleRule,u as DefinitionPropertyReferenceRule,J as DiamondNameClashRule,E as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,t as InstancePropertyReferenceRule,K as KanonakObjectValidator,F as LookSemanticSvgPathRule,D as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,y as ObjectPropertyImportRule,z as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,I as OwlOneOfRule,j as PackageHeaderRule,A as PropertyDomainRule,o as PropertyHierarchyCycleRule,x as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,g as ResourceNamingRule,H as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,G as TxExpressionPathRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,v as XsdImportRule};
1
+ import{A,B,C,D,E,F,G,H,I,L as J,M as K,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-UBBZWWRB.js";import"../chunk-SHDHMKMJ.js";import"../chunk-BKVPSPG4.js";import"../chunk-NJ3AZYQD.js";import"../chunk-IEOSSSB5.js";import"../chunk-7TKJHKC2.js";import"../chunk-7HRKWTBB.js";import"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{w as AmbiguousReferenceRule,C as ClassDefinitionRule,n as ClassHierarchyCycleRule,u as DefinitionPropertyReferenceRule,J as DiamondNameClashRule,E as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,K as KanonakObjectValidator,F as LookSemanticSvgPathRule,D as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,y as ObjectPropertyImportRule,z as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,I as OwlOneOfRule,j as PackageHeaderRule,A as PropertyDomainRule,o as PropertyHierarchyCycleRule,x as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,g as ResourceNamingRule,H as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,G as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,v as XsdImportRule};
@@ -20,11 +20,10 @@ export declare class MarkdownLinkRule implements IRepositoryValidationRule {
20
20
  readonly ruleName = "MarkdownLink";
21
21
  validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
22
22
  /**
23
- * Walk a defined kanonak's statements for `MarkdownStatement`s,
24
- * recursing through embedded kanonaks a Markdown-ranged property
25
- * may sit on an embedded object, not just a top-level subject.
23
+ * Check ONE kanonak's own statements for `MarkdownStatement`s — the walk
24
+ * handles recursion into embeddeds, so this inspects a single level.
26
25
  */
27
- private checkDefined;
26
+ private checkNode;
28
27
  private unresolvedLinkError;
29
28
  private malformedLinkError;
30
29
  }
@@ -0,0 +1,25 @@
1
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
+ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
3
+ import { OntologyValidationError } from '../../OntologyValidationError.js';
4
+ import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Reports any authored property whose predicate did not resolve to a defined
8
+ * property in the document's import closure — a typo (`rdfs.lable`), an
9
+ * unimported namespace, or a name that resolves to a non-property.
10
+ *
11
+ * It reads the resolved object model rather than walking raw `document.body`:
12
+ * `KanonakObjectParser` already attempts to resolve every predicate and, where
13
+ * it fails, records the property on the owning kanonak's `unresolvedPredicates`
14
+ * (see {@link DefinedKanonak}) instead of silently dropping the statement.
15
+ * Because the parser builds embedded kanonaks recursively and {@link
16
+ * walkDefinedKanonaks} visits them all, coverage is automatic at any embedding
17
+ * depth — closing the gap where the old raw-dict `InstancePropertyReference`
18
+ * rule only checked top-level entities. Reserved built-ins are never captured,
19
+ * so they never surface here.
20
+ */
21
+ export declare class UnresolvedPredicateRule implements IRepositoryValidationRule {
22
+ readonly ruleName = "UnresolvedPredicate";
23
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
24
+ private unresolvedPredicateError;
25
+ }
@@ -7,7 +7,7 @@ export { PropertyRangeRequiredRule } from './PropertyRangeRequiredRule.js';
7
7
  export { SubClassOfReferenceRule } from './SubClassOfReferenceRule.js';
8
8
  export { SubPropertyOfReferenceRule } from './SubPropertyOfReferenceRule.js';
9
9
  export { NamespaceImportCycleRule } from './NamespaceImportCycleRule.js';
10
- export { InstancePropertyReferenceRule } from './InstancePropertyReferenceRule.js';
10
+ export { UnresolvedPredicateRule } from './UnresolvedPredicateRule.js';
11
11
  export { DefinitionPropertyReferenceRule } from './DefinitionPropertyReferenceRule.js';
12
12
  export { XsdImportRule } from './XsdImportRule.js';
13
13
  export { AmbiguousReferenceRule } from './AmbiguousReferenceRule.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "4.10.0",
3
+ "version": "4.12.0",
4
4
  "description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -125,7 +125,8 @@
125
125
  "yaml-parser"
126
126
  ],
127
127
  "dependencies": {
128
- "@kanonak-protocol/types": "^4.10.0",
128
+ "@kanonak-protocol/canonical": "^0.1.1",
129
+ "@kanonak-protocol/types": "^4.12.0",
129
130
  "ignore": "^7.0.5",
130
131
  "js-yaml": "^4.1.0",
131
132
  "yaml": "^2.7.0"
@@ -1 +0,0 @@
1
- import{a as U}from"./chunk-NJ3AZYQD.js";import{b as F,c as V,i as P}from"./chunk-VKTFLHCW.js";import{a as B,b as _,c as x,d as k,g as $,h as T,i as E,j as K,k as w,l as j}from"./chunk-T3JR2SV6.js";import{j as L}from"./chunk-2ACBWC7K.js";var S=class extends _{name};var I=class extends B{value;carrier;lexical};var R=class extends ${links=[]};var W=n=>({publisher:"kanonak.org",package_:"core-xsd",name:n}),J=n=>({publisher:"kanonak.org",package_:"core-rdf",name:n}),Y=(p=>(p.Integer="integer",p.Decimal="decimal",p.Double="double",p.Float="float",p.Boolean="boolean",p.String="string",p.AnyUri="anyURI",p.LangString="langString",p.DateTime="dateTime",p.Date="date",p.Time="time",p.HexBinary="hexBinary",p.Base64Binary="base64Binary",p))(Y||{});function v(n){return`${n.publisher}/${n.package_}/${n.name}`}var Q=[["integer","integer"],["long","integer"],["int","integer"],["short","integer"],["byte","integer"],["unsignedLong","integer"],["unsignedInt","integer"],["unsignedShort","integer"],["unsignedByte","integer"],["nonNegativeInteger","integer"],["positiveInteger","integer"],["nonPositiveInteger","integer"],["negativeInteger","integer"],["decimal","decimal"],["double","double"],["float","float"],["boolean","boolean"],["string","string"],["normalizedString","string"],["token","string"],["anyURI","anyURI"],["dateTime","dateTime"],["date","date"],["time","time"],["hexBinary","hexBinary"],["base64Binary","base64Binary"]],ee=new Map(Q.map(([n,e])=>[v(W(n)),e])),ne=v(J("langString"));function M(n){let e=v(n);return e===ne?"langString":ee.get(e)}function te(n){let e=n.trim();if(!/^[+-]?\d+$/.test(e))throw new Error(`canonicalInteger: '${n}' is not a valid xsd:integer lexical`);return BigInt(e.replace(/^\+/,"")).toString()}function re(n){let e=n.trim(),t=/^([+-]?)(\d*)(?:\.(\d*))?$/.exec(e);if(!t||t[2]===""&&(t[3]??"")==="")throw new Error(`canonicalDecimal: '${n}' is not a valid xsd:decimal lexical`);let a=t[1]==="-"?"-":"",r=(t[2]??"").replace(/^0+/,"")||"0",i=(t[3]??"").replace(/0+$/,""),o=i.length>0?`${r}.${i}`:r;return o==="0"?"0":`${a}${o}`}function Z(n,e,t){let a=n.trim();if(a==="NaN")return"NaN";if(a==="INF")return"INF";if(a==="-INF")return"-INF";if(!/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(a))throw new Error(`canonical${t}: '${n}' is not a valid xsd:${t.toLowerCase()} lexical`);let r=e(Number(a));if(!Number.isFinite(r))throw new Error(`canonical${t}: '${n}' is out of the finite range`);return Object.is(r,-0)?"0":String(r)}function ae(n){return Z(n,e=>e,"Double")}function oe(n){return Z(n,e=>Math.fround(e),"Float")}function ie(n){let e=n.trim();if(e==="true"||e==="1")return"true";if(e==="false"||e==="0")return"false";throw new Error(`canonicalBoolean: '${n}' is not a valid xsd:boolean lexical`)}function z(n){return n.normalize("NFC")}function se(n){return n.normalize("NFC")}function ce(n){let e=n.trim();if(!/^([0-9A-Fa-f]{2})*$/.test(e))throw new Error(`canonicalHexBinary: '${n}' is not a valid xsd:hexBinary lexical`);return e.toUpperCase()}function fe(n){let e=n.replace(/\s+/g,"");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e)||e.length%4!==0)throw new Error(`canonicalBase64: '${n}' is not a valid xsd:base64Binary lexical`);return Buffer.from(e,"base64").toString("base64")}var D=n=>n<10?`0${n}`:`${n}`;function C(n){let e=n.startsWith("-"),t=(e?n.slice(1):n).replace(/^0+/,"")||"0",a=t.length<4?t.padStart(4,"0"):t;return`${e?"-":""}${a}`}function H(n){if(!n)return"";let e=n.replace(/^\./,"").replace(/0+$/,"");return e.length>0?`.${e}`:""}function X(n){return n?n==="Z"||n==="+00:00"||n==="-00:00"?"Z":n:""}function pe(n){return n==="Z"?0:(n[0]==="-"?-1:1)*(Number(n.slice(1,3))*60+Number(n.slice(4,6)))}var ue=/^(-?\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,le=/^(-?\d{4,})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,me=/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;function de(n){let e=ue.exec(n.trim());if(!e)throw new Error(`canonicalDateTime: '${n}' is not a valid xsd:dateTime lexical`);let[,t,a,r,i,o,c,f,u]=e,d=H(f);if(!u)return`${C(t)}-${a}-${r}T${i}:${o}:${c}${d}`;let l=new Date(0);l.setUTCFullYear(Number(t),Number(a)-1,Number(r)),l.setUTCHours(Number(i),Number(o),Number(c),0);let s=new Date(l.getTime()-pe(u)*6e4);return`${C(String(s.getUTCFullYear()))}-${D(s.getUTCMonth()+1)}-${D(s.getUTCDate())}T${D(s.getUTCHours())}:${D(s.getUTCMinutes())}:${D(s.getUTCSeconds())}${d}Z`}function ge(n){let e=le.exec(n.trim());if(!e)throw new Error(`canonicalDate: '${n}' is not a valid xsd:date lexical`);let[,t,a,r,i]=e;return`${C(t)}-${a}-${r}${X(i)}`}function ye(n){let e=me.exec(n.trim());if(!e)throw new Error(`canonicalTime: '${n}' is not a valid xsd:time lexical`);let[,t,a,r,i,o]=e,c=H(i),f=t;return t==="24"&&a==="00"&&r==="00"&&c===""&&(f="00"),`${f}:${a}:${r}${c}${X(o)}`}function Re(n,e){switch(n){case"integer":return te(e);case"decimal":return re(e);case"double":return ae(e);case"float":return oe(e);case"boolean":return ie(e);case"string":return z(e);case"anyURI":return se(e);case"langString":return z(e);case"dateTime":return de(e);case"date":return ge(e);case"time":return ye(e);case"hexBinary":return ce(e);case"base64Binary":return fe(e)}}var ke=/\[\[([^\[\]\n]+)\]\]/g,be=/\[\[/g,G=/```[\s\S]*?```|`[^`\n]*`/g;function he(n){let e=[];for(let t of n.matchAll(G))e.push([t.index,t.index+t[0].length]);return e}function Te(n){if(!n||!n.includes("[["))return[];let e=he(n),t=i=>e.some(([o,c])=>i>=o&&i<c),a=new Set(A(n).map(i=>i.startOffset)),r=[];for(let i of n.matchAll(be)){let o=i.index;if(t(o)||a.has(o))continue;let c=n.slice(o,o+48).replace(/\s+/g," ").trim();r.push({startOffset:o,snippet:c})}return r}function A(n){if(!n||!n.includes("[["))return[];let e=[];for(let r of n.matchAll(G))e.push([r.index,r.index+r[0].length]);let t=r=>e.some(([i,o])=>r>=i&&r<o),a=[];for(let r of n.matchAll(ke)){let i=r.index;if(t(i))continue;let o=r[1],c=o.indexOf("|"),f=(c===-1?o:o.slice(0,c)).trim();if(f.length===0)continue;let u=c===-1?"":o.slice(c+1).trim(),d={reference:f,startOffset:i,endOffset:i+r[0].length};u.length>0&&(d.displayText=u),a.push(d)}return a}var q=class{constructor(e){}async parseKanonaks(e){let t=[],a=await e.getAllDocumentsAsync(),r=new F(e),i=new V(r);for(let s of a){let p=s.metadata.namespace_?.toString()??"";for(let[m,g]of Object.entries(s.body)){let y=new x,b=this.resolveCanonicalEntity(m,s,p);y.namespace=b.namespace,y.name=b.name,y.statement=[];let h=await this.parseStatements(g,s,r,i,e);y.statement.push(...h),t.push(y)}}let o=new Map,c=new Map,f=[];for(let s of t)if(s instanceof x){let p=`${s.namespace}/${s.name}`,m=o.get(p);if(m){let g=c.get(p);for(let y of s.statement){let b=O(y);g.has(b)||(g.add(b),m.statement.push(y))}}else{let g=new Set,y=[];for(let b of s.statement){let h=O(b);g.has(h)||(g.add(h),y.push(b))}s.statement=y,c.set(p,g),o.set(p,s),f.push(s)}}else f.push(s);let u=new Set;for(let s of f)if(s instanceof x){let p=s.namespace||"",m=p.indexOf("/"),g=m>=0?p.slice(0,m):"",y=m>=0?p.slice(m+1):"",b=y.indexOf("@"),h=b>=0?y.slice(0,b):y;u.add(`${g}/${h}/${s.name}`)}let d=s=>u.has(`${s.publisher}/${s.package_}/${s.name}`),l=new Map;for(let s of["core-rdf","core-owl","core-kanonak"]){let p=await e.getDocumentsByNamespaceAsync("kanonak.org",s);l.set(s,L(p).chosen?.metadata.namespace_?.version??void 0)}for(let s of f)s instanceof x&&this.canonicalizeStatementBuiltins(s.statement,d,l);return f}canonicalizeStatementBuiltins(e,t,a){for(let r of e){let i=r.predicate?.subject;if(P(i,t,a),r instanceof K)r.object instanceof k&&P(r.object.subject,t,a);else if(r instanceof w)r.object&&this.canonicalizeStatementBuiltins(r.object.statement,t,a);else if(r instanceof j)for(let o of r.object??[])o instanceof k?P(o.subject,t,a):o instanceof S&&this.canonicalizeStatementBuiltins(o.statement,t,a)}}resolveCanonicalEntity(e,t,a){if(!e.includes(".")||!t.metadata?.imports)return{namespace:a,name:e};let r=e.indexOf("."),i=e.substring(0,r),o=e.substring(r+1);for(let[c,f]of Object.entries(t.metadata.imports))for(let u of f)if((u.alias??u.packageName)===i){let l=u.version;return{namespace:`${c}/${u.packageName}@${l.major}.${l.minor}.${l.patch}`,name:o}}return{namespace:a,name:e}}async parseStatements(e,t,a,r,i){let o=[];if(typeof e!="object"||e===null||Array.isArray(e))return o;for(let[c,f]of Object.entries(e))try{let u=await this.getPropertyMetadata(c,t,a,i,r);if(!u)continue;let d=await this.parsePropertyValue(c,f,u,t,a,r,i);d&&o.push(d)}catch(u){throw new Error(`Failed to parse property '${c}': ${u.message}`,{cause:u})}return o}async getPropertyMetadata(e,t,a,r,i){let o=await a.resolveEntityAsync(e,t);if(!o)return;let c=o.entity,f=c.type?.toString()??"",u=f.includes(".")?f.substring(f.lastIndexOf(".")+1):f;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(u))return;let l=i.getPropertyTypeClassification(f),s=c.range?.toString(),p;if(l==="ObjectProperty")p="ObjectProperty";else if(l==="DatatypeProperty")p="DatatypeProperty";else{let y=s&&s.includes(".")?s.substring(s.lastIndexOf(".")+1):s??"";(s?i.isKnownXsdDatatypeName(s):!1)||y==="Literal"?p="DatatypeProperty":p="ObjectProperty"}let m;if(s){let y=t;if(o.isImported&&o.definedInNamespace){if(typeof r.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${e}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let h=await r.getDocumentAsync(o.definedInNamespace);if(!h)throw new Error(`Cannot resolve the range of imported property '${e}': defining document '${o.definedInNamespace}' was not found in the repository.`);y=h}m=(await a.resolveEntityAsync(s,y))?.uri}return{propertyUri:o.uri.toString(),propertyType:p,range:s,rangeUri:m,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async parsePropertyValue(e,t,a,r,i,o,c){let f=a.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(f,t,a,r,i,o,c);if(a.propertyType==="DatatypeProperty")return this.parseDatatypeValue(f,t,a,r,i,o);if(a.propertyType==="ObjectProperty")return this.parseObjectValue(f,t,a,r,i,o,c)}}async parseDatatypeValue(e,t,a,r,i,o){let c;if(typeof t=="string"){if(o.isSubstitutableDatatype(a.rangeUri))return await this.parseSubstitutableValue(e,t,r,i);c=t}else if(typeof t=="number"||typeof t=="boolean")c=String(t);else return;return this.typedScalarStatement(e,c,a)}typedScalarStatement(e,t,a){let r=k.parse(e),i=a.rangeUri?M(a.rangeUri):void 0;if(i==="boolean"){let c=new E;return c.predicate=r,c.object=t==="true"||t==="1",c.carrier=i,c.lexical=t,c}if(i==="integer"||i==="decimal"||i==="double"||i==="float"){let c=new T;return c.predicate=r,c.object=Number(t),c.carrier=i,c.lexical=t,c}let o=$.parse(e,t);return i&&(o.carrier=i,o.lexical=t),o}typedListLiteral(e,t){let a=new I,r=t.rangeUri?M(t.rangeUri):void 0;return r==="boolean"?a.value=e==="true"||e==="1":r==="integer"||r==="decimal"||r==="double"||r==="float"?a.value=Number(e):a.value=e,r&&(a.carrier=r,a.lexical=e),a}async parseSubstitutableValue(e,t,a,r){let i=new R;i.predicate=k.parse(e),i.object=t;for(let o of A(t)){let c=await r.resolveEntityAsync(o.reference,a),f;c&&(f=new k,f.subject=c.uri);let u={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(u.displayText=o.displayText),f!==void 0&&(u.target=f),i.links.push(u)}return i}async parseObjectValue(e,t,a,r,i,o,c){if(typeof t=="string"){let f=await this.resolveReference(t,r,i);if(!f)return;let u=new K;return u.predicate=k.parse(e),u.object=f,u}if(typeof t=="object"&&!Array.isArray(t)){let f=new S;if(f.statement=await this.parseStatements(t,r,i,o,c),f.statement.length>0){let l=new w;return l.predicate=k.parse(e),l.object=f,l}let u=[];for(let[l,s]of Object.entries(t))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=new S;p.name=l,p.statement=await this.parseStatements(s,r,i,o,c),u.push(p)}else if(typeof s=="string"){let p=await this.resolveReference(s,r,i);p&&u.push(p)}if(u.length>0){let l=new j;return l.predicate=k.parse(e),l.object=u,l}let d=new w;return d.predicate=k.parse(e),d.object=f,d}}async parseListValue(e,t,a,r,i,o,c){let f=[],u=a.propertyType==="DatatypeProperty",d=a.rangeUri?.publisher==="kanonak.org"&&a.rangeUri?.package_==="core-rdf"&&a.rangeUri?.name==="List"||!a.rangeUri&&(a.range?.includes(".")?a.range.substring(a.range.lastIndexOf(".")+1):a.range)==="List";for(let s of t){let p=typeof s=="string"||typeof s=="number"||typeof s=="boolean";if(u&&p){let m=typeof s=="string"?s:String(s);f.push(this.typedListLiteral(m,a));continue}if(d&&p){if(typeof s=="string"){let m=await i.resolveEntityAsync(s,r);if(m){let g=new k;g.subject=m.uri,f.push(g)}else{let g=new I;g.value=s,f.push(g)}}else{let m=new I;m.value=s,f.push(m)}continue}if(typeof s=="string"){let m=await this.resolveReference(s,r,i);m&&f.push(m)}else if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let m=new S;m.statement=await this.parseStatements(s,r,i,o,c),f.push(m)}}let l=new j;return l.predicate=k.parse(e),l.object=f,l}async resolveReference(e,t,a){let r=await a.resolveEntityAsync(e,t);if(r){let o=new k;return o.subject=r.uri,o}let i=t.metadata?.namespace_;if(i){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(e.includes(".")){let f=e.indexOf("."),u=e.substring(0,f),d=e.substring(f+1);if(t.metadata?.imports){for(let[l,s]of Object.entries(t.metadata.imports))for(let p of s)if((p.alias??p.packageName)===u){let g=new k;return g.subject=new o(l,p.packageName,d,p.version),g}}}let c=new k;return c.subject=new o(i.publisher,i.package_,e,i.version??void 0),c}return null}async saveKanonaks(e,t){let a=new Map;for(let r of e)r instanceof x&&r.namespace&&(a.has(r.namespace)||a.set(r.namespace,[]),a.get(r.namespace).push(r));for(let[r,i]of a){let o=await this.convertKanonaksToDocument(r,i),c=`${r.split("@")[0]}.yml`;await t.saveDocumentAsync(o,c)}}async serializeToYaml(e,t){let a=e.filter(o=>o instanceof x&&o.namespace===t);if(a.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let r=await this.convertKanonaksToDocument(t,a);return new U().save(r)}async convertKanonaksToDocument(e,t){let r={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},i=new Map;for(let o of t){let c={};for(let f of o.statement){let[u,d]=this.convertStatementToProperty(f);u&&d!==null&&d!==void 0&&(c[u]=d),this.collectImportsFromStatement(f,e,i)}r.body[o.name]=c}return r}convertStatementToProperty(e){if(e instanceof $)return[e.predicate.subject.name,e.object];if(e instanceof T)return[e.predicate.subject.name,e.object];if(e instanceof E)return[e.predicate.subject.name,e.object];if(e instanceof K)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof w){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let a of e)a instanceof k?t.push(a.subject.name):a instanceof S&&t.push(this.convertEmbeddedKanonakToValue(a));return t}convertEmbeddedKanonakToValue(e){let t={};for(let a of e.statement){let[r,i]=this.convertStatementToProperty(a);r&&i!==null&&i!==void 0&&(t[r]=i)}return t}collectImportsFromStatement(e,t,a){}};function O(n){let e=n.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+Se(n)}function Se(n){return n instanceof R?"m:"+String(n.object):n instanceof $?"s:"+String(n.object):n instanceof T?"n:"+String(n.object):n instanceof E?"b:"+String(n.object):n instanceof K?"r:"+N(n.object):n instanceof w?"e:"+N(n.object):n instanceof j?"l:["+(n.object??[]).map(N).join("|")+"]":"x"}function N(n){if(!n)return"";if(n instanceof k){let e=n.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return n instanceof S?"E("+(n.statement??[]).map(O).join(";")+")":n instanceof I?"L("+String(n.value)+")":"N"}export{S as a,I as b,R as c,Y as d,M as e,Re as f,Te as g,A as h,q as i};