@kanonak-protocol/sdk 5.31.0 → 5.32.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 -0
- package/dist/browser.js +1 -1
- package/dist/chunk-DD3TCFBT.js +155 -0
- package/dist/{chunk-AXQ4DBJD.js → chunk-LRVOGQI5.js} +1 -1
- package/dist/chunk-PRXC2HZ3.js +1 -0
- package/dist/chunk-PXS6XZ3V.js +2 -0
- package/dist/chunk-QHABFCRC.js +0 -0
- package/dist/index.js +1 -1
- package/dist/producer/index.js +1 -0
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +10 -2
- package/dist/chunk-J4ZD6IF6.js +0 -2
- package/dist/chunk-Z5Y4MCW5.js +0 -155
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Do}from"./chunk-KIBR3HAT.js";import{c as So,e as Io,f as oo,g as to,h as $o,i as jo,j as Oo,q as no,r as wo,s as Co}from"./chunk-Z5Y4MCW5.js";import{a as S,b as go,c as Ge,d as L,h as F,k as vo,m as j}from"./chunk-PVUBHIU2.js";import{a as fo}from"./chunk-HF5FJBS2.js";import{aa as ze,b as ko,ba as Ko,fa as $,ga as T,ha as H,ia as B,ja as Y,ma as Eo,na as W,oa as Vo}from"./chunk-7UYXTYXC.js";import{A as P,B as v,C as _,c as g,d as O,j as ee,k as G,l as M,m as b,n as q,p as ho,q as Ro,r as A,t as V,u as bo,w as oe,x as Z,y as z,z as h}from"./chunk-CJMVIOZX.js";import{a as yo}from"./chunk-FUUTGGJS.js";import{b as Q,c as uo}from"./chunk-F67UH4FD.js";import{e as C}from"./chunk-QILEJIFU.js";var te=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var R=(t=>(t.Info="Info",t.Warning="Warning",t.Error="Error",t))(R||{});var u=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var ro=class p{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new p;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};var ne=class{constructor(e){this.underlying=e;this.repository=new ao(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await Do(e,this.repository);let o={};return{merged:await new j().parseKanonaks(this.underlying,o),authored:o.authored??[]}})()),this.parsePromise}},ao=class{constructor(e){this.inner=e}inner;highestVersionCache=new Map;byNamespaceCache=new Map;getAllDocumentsAsync(){return this.inner.getAllDocumentsAsync()}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){let t=`${e}/${o}`,n=this.byNamespaceCache.get(t);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,o),this.byNamespaceCache.set(t,n),n)}getHighestCompatibleVersionAsync(e,o){let t=o.version,n=t?`${t.major}.${t.minor}.${t.patch}`:"",r=`${e}/${o.packageName}@${o.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,o),this.highestVersionCache.set(r,a),a)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};async function I(p,e,o){return o?o.getKanonaks():new j().parseKanonaks(new re(p,e))}async function w(p,e,o){let t=await I(p,e,o),n=Ze(p);return n?t.filter(r=>r instanceof g&&r.namespace===n):[]}async function ae(p,e,o){let t=Ze(p);if(!t)return[];let n;if(o)n=await o.getAuthoredKanonaks();else{let r={};await new j().parseKanonaks(new re(p,e),r),n=r.authored??[]}return n.filter(r=>r instanceof g&&r.sourceDoc===t)}function Ze(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var re=class{constructor(e,o){this.document=e;this.broader=o}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),o=(await this.broader.getAllDocumentsAsync()).filter(t=>t.metadata.namespace_?.toString()!==e);return[this.document,...o]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){return this.broader.getDocumentsByNamespaceAsync(e,o)}getHighestCompatibleVersionAsync(e,o){return this.broader.getHighestCompatibleVersionAsync(e,o)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var ie=class{constructor(e={}){this.options=e}options;ruleName="LinkTarget";async validateAsync(e,o,t){let n=[],r=new Map;for(let[s,l]of Object.entries(e.metadata?.imports??{}))for(let m of l)Q(m)&&r.set(`${s}/${m.packageName}`,{publisher:s,import_:m});if(r.size===0)return n;let a=new Map,i=(s,l,m)=>{let d=`${s.publisher}/${s.package_}`;if(!r.has(d))return;let f=a.get(d)??[];f.push({uri:s,where:l,predicate:m}),a.set(d,f)},c=await w(e,o,t);L(c,({kanonak:s,path:l})=>{for(let m of s.statement){let d=m.predicate?.subject?.name??"(unknown)";if(m instanceof ee)i(m.object.subject,l,d);else if(m instanceof M)for(let f of m.object)f instanceof O&&i(f.subject,l,d);else if(m instanceof Ge)for(let f of m.links)f.target&&i(f.target.subject,l,d)}});for(let[s,l]of a){let{publisher:m,import_:d}=r.get(s),f=null,y;try{f=await o.getHighestCompatibleVersionAsync(m,d)}catch(k){y=k instanceof Error?k.message:String(k)}if(!f){let k=l[0],K=`${l.length} reference${l.length===1?"":"s"}, first at '${k.where}.${k.predicate}'`;this.options.offline?n.push(this.finding("Warning",k.where,k.predicate,s,`Link target package '${s}' could not be resolved offline (${K}); the link is UNVERIFIED, not known to be broken.`,"Run without --offline to verify the link over HTTP, or add the package to the workspace or cache.")):n.push(this.finding("Error",k.where,k.predicate,s,`Link target package '${s}' could not be resolved${y?` (${y})`:""} \u2014 ${K}.`,"Check the publisher and package name of the link import; a link must dereference even though it is not a dependency. Use --offline to validate without the network (the link is then reported as unverified)."));continue}for(let{uri:k,where:K,predicate:E}of l)Object.prototype.hasOwnProperty.call(f.body,k.name)||n.push(this.finding("Error",K,E,`${s}/${k.name}`,`Link to '${k.name}' in '${E}' at '${K}' does not dereference: package '${s}' (resolved to ${f.metadata.namespace_?.toString()??s}) defines no resource named '${k.name}'.`,`Check for a typo, or a resource renamed or removed in '${s}'; a link addresses a resource by name in its package's current version unless the import is pinned with '='.`))}return n}finding(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.actualValue=n,i.expectedValue="A link that dereferences to a resource its target package defines",i.message=r,i.suggestion=a,i}};var se=class p{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):[A-Za-z_][A-Za-z0-9_.-]*$/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let a=r?.toString()??"";if(a&&p.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),c=e.split(".")[0],s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=n,s.expectedValue=i,s.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var ce=class p{static RESERVED_WORDS=new Set(["imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=p.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!t&&p.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(i);continue}if(!a&&!p.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=n,c.message=`Invalid entity name '${n}'. ${i}`,c.suggestion=i,o.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!p.VALID_PROPERTIES.has(n)&&!p.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var pe=class p{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let c=[];if(Array.isArray(i))for(let s of i){let l=s?.toString();l&&l==="Property"&&!t&&c.push(l)}else{let s=i?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=s,d.expectedValue=m,d.message=`Invalid property type '${s}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(d)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":p.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var le=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.suggestion=`Add a type statement like:
|
|
1
|
+
import{a as Do}from"./chunk-KIBR3HAT.js";import{c as So,e as Io,f as oo,g as to,h as $o,i as jo,j as Oo,q as no,r as wo,s as Co}from"./chunk-DD3TCFBT.js";import{a as S,b as go,c as Ge,d as L,h as F,k as vo,m as j}from"./chunk-PVUBHIU2.js";import{a as fo}from"./chunk-HF5FJBS2.js";import{aa as ze,b as ko,ba as Ko,fa as $,ga as T,ha as H,ia as B,ja as Y,ma as Eo,na as W,oa as Vo}from"./chunk-7UYXTYXC.js";import{A as P,B as v,C as _,c as g,d as O,j as ee,k as G,l as M,m as b,n as q,p as ho,q as Ro,r as A,t as V,u as bo,w as oe,x as Z,y as z,z as h}from"./chunk-CJMVIOZX.js";import{a as yo}from"./chunk-FUUTGGJS.js";import{b as Q,c as uo}from"./chunk-F67UH4FD.js";import{e as C}from"./chunk-QILEJIFU.js";var te=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var R=(t=>(t.Info="Info",t.Warning="Warning",t.Error="Error",t))(R||{});var u=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var ro=class p{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new p;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};var ne=class{constructor(e){this.underlying=e;this.repository=new ao(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await Do(e,this.repository);let o={};return{merged:await new j().parseKanonaks(this.underlying,o),authored:o.authored??[]}})()),this.parsePromise}},ao=class{constructor(e){this.inner=e}inner;highestVersionCache=new Map;byNamespaceCache=new Map;getAllDocumentsAsync(){return this.inner.getAllDocumentsAsync()}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){let t=`${e}/${o}`,n=this.byNamespaceCache.get(t);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,o),this.byNamespaceCache.set(t,n),n)}getHighestCompatibleVersionAsync(e,o){let t=o.version,n=t?`${t.major}.${t.minor}.${t.patch}`:"",r=`${e}/${o.packageName}@${o.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,o),this.highestVersionCache.set(r,a),a)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};async function I(p,e,o){return o?o.getKanonaks():new j().parseKanonaks(new re(p,e))}async function w(p,e,o){let t=await I(p,e,o),n=Ze(p);return n?t.filter(r=>r instanceof g&&r.namespace===n):[]}async function ae(p,e,o){let t=Ze(p);if(!t)return[];let n;if(o)n=await o.getAuthoredKanonaks();else{let r={};await new j().parseKanonaks(new re(p,e),r),n=r.authored??[]}return n.filter(r=>r instanceof g&&r.sourceDoc===t)}function Ze(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var re=class{constructor(e,o){this.document=e;this.broader=o}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),o=(await this.broader.getAllDocumentsAsync()).filter(t=>t.metadata.namespace_?.toString()!==e);return[this.document,...o]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){return this.broader.getDocumentsByNamespaceAsync(e,o)}getHighestCompatibleVersionAsync(e,o){return this.broader.getHighestCompatibleVersionAsync(e,o)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var ie=class{constructor(e={}){this.options=e}options;ruleName="LinkTarget";async validateAsync(e,o,t){let n=[],r=new Map;for(let[s,l]of Object.entries(e.metadata?.imports??{}))for(let m of l)Q(m)&&r.set(`${s}/${m.packageName}`,{publisher:s,import_:m});if(r.size===0)return n;let a=new Map,i=(s,l,m)=>{let d=`${s.publisher}/${s.package_}`;if(!r.has(d))return;let f=a.get(d)??[];f.push({uri:s,where:l,predicate:m}),a.set(d,f)},c=await w(e,o,t);L(c,({kanonak:s,path:l})=>{for(let m of s.statement){let d=m.predicate?.subject?.name??"(unknown)";if(m instanceof ee)i(m.object.subject,l,d);else if(m instanceof M)for(let f of m.object)f instanceof O&&i(f.subject,l,d);else if(m instanceof Ge)for(let f of m.links)f.target&&i(f.target.subject,l,d)}});for(let[s,l]of a){let{publisher:m,import_:d}=r.get(s),f=null,y;try{f=await o.getHighestCompatibleVersionAsync(m,d)}catch(k){y=k instanceof Error?k.message:String(k)}if(!f){let k=l[0],K=`${l.length} reference${l.length===1?"":"s"}, first at '${k.where}.${k.predicate}'`;this.options.offline?n.push(this.finding("Warning",k.where,k.predicate,s,`Link target package '${s}' could not be resolved offline (${K}); the link is UNVERIFIED, not known to be broken.`,"Run without --offline to verify the link over HTTP, or add the package to the workspace or cache.")):n.push(this.finding("Error",k.where,k.predicate,s,`Link target package '${s}' could not be resolved${y?` (${y})`:""} \u2014 ${K}.`,"Check the publisher and package name of the link import; a link must dereference even though it is not a dependency. Use --offline to validate without the network (the link is then reported as unverified)."));continue}for(let{uri:k,where:K,predicate:E}of l)Object.prototype.hasOwnProperty.call(f.body,k.name)||n.push(this.finding("Error",K,E,`${s}/${k.name}`,`Link to '${k.name}' in '${E}' at '${K}' does not dereference: package '${s}' (resolved to ${f.metadata.namespace_?.toString()??s}) defines no resource named '${k.name}'.`,`Check for a typo, or a resource renamed or removed in '${s}'; a link addresses a resource by name in its package's current version unless the import is pinned with '='.`))}return n}finding(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.actualValue=n,i.expectedValue="A link that dereferences to a resource its target package defines",i.message=r,i.suggestion=a,i}};var se=class p{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):[A-Za-z_][A-Za-z0-9_.-]*$/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let a=r?.toString()??"";if(a&&p.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),c=e.split(".")[0],s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=n,s.expectedValue=i,s.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var ce=class p{static RESERVED_WORDS=new Set(["imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=p.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!t&&p.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(i);continue}if(!a&&!p.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=n,c.message=`Invalid entity name '${n}'. ${i}`,c.suggestion=i,o.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!p.VALID_PROPERTIES.has(n)&&!p.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var pe=class p{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let c=[];if(Array.isArray(i))for(let s of i){let l=s?.toString();l&&l==="Property"&&!t&&c.push(l)}else{let s=i?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=s,d.expectedValue=m,d.message=`Invalid property type '${s}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(d)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":p.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var le=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.suggestion=`Add a type statement like:
|
|
2
2
|
type: Scene
|
|
3
3
|
|
|
4
4
|
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,c.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(c)}}return o}};var ot=new Set(["EphemeralPackage"]),me=class{get ruleName(){return"PackageHeader"}validate(e){let o=e.metadata;if(!o.type_)return[];let t=[],n=this.packageKey(e,o.type_);return o.namespace_?(!ot.has(o.type_)&&!o.namespace_.version&&t.push(this.error(n,"version",`Package resource '${n}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as m,b as E,i as U,m as B}from"./chunk-PVUBHIU2.js";import{a as K}from"./chunk-HF5FJBS2.js";import{ba as _,c as D}from"./chunk-7UYXTYXC.js";import{C as N,b as j,c as d,d as p,f as R,g as $,h as A,i as v,j as S,k as V,l as g}from"./chunk-CJMVIOZX.js";import{b as C,e as l}from"./chunk-QILEJIFU.js";import*as P from"js-yaml";import{canonicalForm as Y,canonicalHash as ee}from"@kanonak-protocol/canonical";function k(n){return typeof n=="object"&&n!==null&&Array.isArray(n.subjects)}import{CANONICAL_FORM_VERSION as Pe}from"@kanonak-protocol/canonical";function ke(n){return Y(k(n)?n:F(n))}function O(n){return ee(k(n)?n:F(n))}function F(n){let e=[];for(let t of n)t instanceof d&&e.push({uri:se(t),statements:h(t.statement)});return{subjects:e}}function h(n){let e=[];for(let t of n){let r=ie(t);if(!r)continue;if(t instanceof g&&ne(t.predicate.subject)){e.push(...re(t,r));continue}let o=oe(t);o&&e.push({predicate:r,value:o})}return e}function ne(n){let e=_("type");return e!==void 0&&n.name==="type"&&n.publisher===e.publisher&&n.package_===e.package_}var H=new TextEncoder;function te(n,e){let t=H.encode(n),r=H.encode(e),o=Math.min(t.length,r.length);for(let a=0;a<o;a++)if(t[a]!==r[a])return t[a]-r[a];return t.length-r.length}function re(n,e){let t=[];for(let r of n.object){if(!(r instanceof p))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(b(r))}t.sort(te);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:e,value:{ref:r}}))}function oe(n){if(n instanceof R&&n.carrier)return{lit:n.lexical??String(n.object),datatype:z(n.carrier)};if(n instanceof $)return{raw:n.object};if(n instanceof A)return{raw:n.lexical??String(n.object)};if(n instanceof v)return{raw:n.lexical??String(n.object)};if(n instanceof S)return{ref:b(n.object)};if(n instanceof V)return M(n.object);if(n instanceof g)return{list:n.object.map(ae)}}function M(n){let e=h(n.statement);return n.name&&n.name.length>0?{embed:{name:n.name,statements:e}}:{embed:{statements:e}}}function ae(n){if(n instanceof p)return{ref:b(n)};if(n instanceof m)return M(n);if(n instanceof E){if(n.carrier)return{lit:n.lexical??String(n.value),datatype:z(n.carrier)};let e=n.value;if(typeof e=="string")return{raw:e};if(typeof e=="number")return{raw:String(e)};if(typeof e=="boolean")return{raw:String(e)}}if(n instanceof j)return{embed:{statements:h(n.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${n.constructor?.name??typeof n}); add canonicalization support before hashing data that contains it`)}function z(n){return n===U.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${n}`}function ie(n){let e=n.predicate;if(e)return L(e.subject)}function se(n){let e=n.namespace??"",t=n.name??"";return`${e}/${t}`}function b(n){return L(n.subject)}function L(n){let e=n.version;return e&&typeof e.major=="number"?`${n.publisher}/${n.package_}@${e.major}.${e.minor}.${e.patch}/${n.name}`:`${n.publisher}/${n.package_}/${n.name}`}import{VersionOperator as T}from"@kanonak-protocol/types/document/models/enums";var ce="0.0.0",w=class{constructor(e,t=new K,r){this.repository=e;this.parser=t;this.objectParser=r??new B(this.parser)}repository;parser;objectParser;imports(){return new f}serializeValue(e,t){return G(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),r=await this.hashBody(e.publisher,t,e.body),o=Z(r),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=r),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:W(s),contentHash:r,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),r={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),r[e.contentHashProperty]=o),Object.assign(r,e.header??{}),r.imports=t;let a={[e.name]:r,...e.body},i=this.dump(a),s={yaml:i,byteCount:W(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return P.dump(e,{lineWidth:-1})}async hashBody(e,t,r){let o={[q]:{type:"EphemeralPackage",publisher:e,imports:t},...r},a=this.parser.parse(P.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new N(a,this.repository))).filter(u=>u instanceof d&&u.namespace===i&&u.name!==q);for(let u of c)u.namespace="ephemeral";return O(c)}},q="__pkgbuilder_probe__";function W(n){return new TextEncoder().encode(n).length}function Z(n){let e="sha256:",t=n.startsWith(e)?e.length:0;return`q-${n.slice(t,t+16)}`}var f=class{byKey=new Map;aliases=new Set;ensure(e,t,r,o,a=T.Major){let i=`${e}/${t}@${r}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:r,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,l(e.version),e.package_)}.${e.name}`}refLatest(e,t,r,o){return`${this.ensure(e,t,ce,o??t,T.Any)}.${r}`}toImports(){let e=new Map;for(let r of this.byKey.values()){let o=e.get(r.publisher)??[];o.push(r),e.set(r.publisher,o)}return[...e.keys()].sort().map(r=>({publisher:r,packages:e.get(r).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:C(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=J(e)||"pkg",r=t,o=2;for(;this.aliases.has(r);)r=`${t}${o++}`;return this.aliases.add(r),r}};function G(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof p)return e.ref(n.subject);if(Array.isArray(n)){let t=n.map(r=>G(r,e)).filter(r=>r!==void 0);return t.length>0?t:void 0}if(n instanceof m)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(ue(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 J(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function ue(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var I=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(r=>r.canProduce(e,t))}async produceCached(e,t,r,o){let a=`${t}/${r}@${l(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,r,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let r=this.producerFor(e,t.packageName);if(!r)return null;let o={operator:t.versionOperator,version:t.version},a=await r.resolveVersion(e,t.packageName,o);return a?this.produceCached(r,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=D(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let r=this.producerFor(t.publisher,t.package_);return r?this.produceCached(r,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(r=>{let o=r.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){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,t){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 Q={async authorize(){return{allowed:!0}}},X={async record(){}},y=class extends Error{constructor(t,r){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${r?`: ${r}`:""}`);this.address=t;this.reason=r;this.name="EntitlementDeniedError"}address;reason},x=class{inner;ctx;policy;meter;constructor(e,t,r=Q,o=X){this.inner=e,this.ctx=t,this.policy=r,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,r){return await this.assertAllowed({publisher:e,package_:t,version:r.version}),this.inner.resolveVersion(e,t,r)}async produce(e,t,r){let o={publisher:e,package_:t,version:r};await this.assertAllowed(o);let a=await this.inner.produce(e,t,r);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new y(e,t.reason)}};export{ke as a,O as b,Pe as c,w as d,Z as e,f,J as g,I as h,Q as i,X as j,y as k,x as l};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{e as R}from"./chunk-BZ3YTI3C.js";import{c as F,m as G}from"./chunk-PVUBHIU2.js";import{fa as S,ia as j}from"./chunk-7UYXTYXC.js";import{c as N}from"./chunk-CJMVIOZX.js";var z=(r=>(r.Class="Class",r.DatatypeProperty="DatatypeProperty",r.ObjectProperty="ObjectProperty",r.AnnotationProperty="AnnotationProperty",r.Instance="Instance",r.Datatype="Datatype",r.Shape="Shape",r.Unknown="Unknown",r))(z||{}),L=(r=>(r.InstanceOf="instanceOf",r.SubClassOf="subClassOf",r.Domain="domain",r.Range="range",r.ObjectRelationship="objectRelationship",r.SubPropertyOf="subPropertyOf",r.PropertyValue="propertyValue",r.EmbeddedLink="embeddedLink",r))(L||{}),$=class{static async buildFromRepository(e,n){let i=await new G().parseKanonaks(e),s=await e.getAllDocumentsAsync(),p=[],a=[],r=new Set,d=new Set,y=new Map;for(let f of i){let c=f;if(c.name&&(S.isClassType(c)&&r.add(c.name),f instanceof N)){let l=j(i,f);(l==="ObjectProperty"||l==="Property")&&d.add(c.name)}}for(let f of s)for(let[c,l]of Object.entries(f.body))d.has(c)&&l?.range&&typeof l.range=="string"&&y.set(c,l.range);let g=new Map;for(let f of i){let c=f;c.name&&g.set(c.name,c)}for(let f of s){let c=f.metadata.namespace_,l=c?`${c.publisher}/${c.package_}`:"",m=c?.version?`${c.version.major}.${c.version.minor}.${c.version.patch}`:"",O=U(f);for(let[h,u]of Object.entries(f.body)){if(!u||typeof u!="object")continue;let b=g.get(h),k="Unknown";if(b){let T=b,A=b instanceof N?j(i,b):void 0;S.isClassType(T)?k="Class":A==="ObjectProperty"?k="ObjectProperty":A==="DatatypeProperty"?k="DatatypeProperty":A==="AnnotationProperty"?k="AnnotationProperty":S.isDatatypeType(T)?k="Datatype":A==="Property"?k="ObjectProperty":S.isShapeType(T)?k="Shape":S.isInstanceOfKnownClass(T,r)&&(k="Instance")}let P=l&&m?`${l}/${h}@${m}`:h,I={};for(let[T,A]of Object.entries(u))T!=="type"&&(typeof A!="object"||A===null)&&(I[T]=A);p.push({id:P,label:u.label??h,type:k,namespace:l,properties:I}),K(P,u,k,r,d,a,l,m,O,n),D(P,u,d,y,p,a,l,m,O),Q(P,b,a)}}return{nodes:p,edges:a}}static buildFromDocument(e,n){let o=[],i=[],s=e.metadata.namespace_,p=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",r=new Set,d=new Set,y=new Map,g=U(e);for(let[l,m]of Object.entries(e.body)){let O=m?.type;O&&(Y(O,g)&&r.add(l),J(O,g)&&(d.add(l),m.range&&typeof m.range=="string"&&y.set(l,m.range)))}for(let[l,m]of Object.entries(e.body)){if(!m||typeof m!="object")continue;let O=m.type,h=X(O,l,r,g),u=a&&p?`${a}/${l}@${p}`:l,b={};for(let[k,P]of Object.entries(m))k!=="type"&&(typeof P!="object"||P===null)&&(b[k]=P);o.push({id:u,label:m.label??l,type:h,namespace:a,properties:b}),K(u,m,h,r,d,i,a,p,g,n),D(u,m,d,y,o,i,a,p,g)}let f=new Set(o.map(l=>l.id)),c=i.filter(l=>f.has(l.source)&&f.has(l.target));return{nodes:o,edges:c}}};function U(t,e){let n=new Map;if(t.metadata?.imports)for(let[o,i]of Object.entries(t.metadata.imports))for(let s of i){let p=s.alias??s.packageName,a=s.version,r=`${a.major}.${a.minor}.${a.patch}`;n.set(p,{publisher:o,package_:s.packageName,version:r})}return n}var B={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},W=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function M(t,e){if(t.includes(".")){let n=t.indexOf("."),o=t.substring(0,n),i=t.substring(n+1),s=e.get(o);if(s)return`${s.publisher}/${s.package_}/${i}`}return null}function Y(t,e){let n=M(t,e);return n?B[n]==="Class":!1}function J(t,e){let n=M(t,e);return n?W.has(n):!1}function X(t,e,n,o){if(!t||t==="Package")return"Unknown";let i=M(t,o);if(i){let p=B[i];if(p)return p;let a=i.split("/").pop()?.split("@")[0]??"";return n.has(a)?"Instance":"Unknown"}let s=t.split(".").pop()??t;return n.has(s)?"Instance":"Unknown"}var V=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function K(t,e,n,o,i,s,p,a,r,d){let y=e.type,g=e.subClassOf;if(g){let h=Array.isArray(g)?g:[g];for(let u of h)typeof u=="string"&&s.push({source:t,target:v(u,p,a,r),type:"subClassOf",label:"subClassOf"})}let f=e.subPropertyOf;if(f){let h=Array.isArray(f)?f:[f];for(let u of h)typeof u=="string"&&s.push({source:t,target:v(u,p,a,r),type:"subPropertyOf",label:"subPropertyOf"})}let c=e.domain,l=e.range;if(d?.includePropertyEdges){let h=[[c,"domain","domain"],[l,"range","range"]];for(let[u,b,k]of h)if(u!=null)for(let P of Array.isArray(u)?u:[u])typeof P=="string"&&s.push({source:t,target:v(P,p,a,r),type:b,label:k})}if(n==="Instance"&&y){let h=y.split(".").pop()??y;s.push({source:t,target:v(h,p,a,r),type:"instanceOf",label:"type"})}if(n==="Instance")for(let[h,u]of Object.entries(e)){if(V.has(h)||!i.has(h))continue;let b=Array.isArray(u)?u:[u];for(let k of b)typeof k=="string"&&Z(k)&&s.push({source:t,target:v(k,p,a,r),type:"propertyValue",label:h,propertyId:v(h,p,a,r)})}if((n==="ObjectProperty"||n==="DatatypeProperty"||c&&l)&&c&&l){let h=typeof c=="string"?c:null,u=typeof l=="string"?l:null;h&&u&&s.push({source:v(h,p,a,r),target:v(u,p,a,r),type:"objectRelationship",label:e.label??t.split("/").pop()??"",propertyId:t})}}function D(t,e,n,o,i,s,p,a,r){for(let[d,y]of Object.entries(e)){if(V.has(d)||typeof y!="object"||y===null||Array.isArray(y))continue;let g=y,f=`${t}/${d}`,c=o.get(d),l=c?c.split(".").pop()??c:"Unknown",m={};for(let[h,u]of Object.entries(g))(typeof u!="object"||u===null)&&(m[h]=u);i.push({id:f,label:`${l} (embedded)`,type:"Instance",namespace:p,properties:m});let O=p&&a?`${p}/${d}@${a}`:d;s.push({source:t,target:f,type:"propertyValue",label:d,propertyId:n.has(d)?O:void 0}),c&&s.push({source:f,target:v(l,p,a,r),type:"instanceOf",label:"type (inferred)"}),D(f,g,n,o,i,s,p,a,r)}}function Q(t,e,n){let o=e?.statement;if(Array.isArray(o))for(let i of o){if(!(i instanceof F))continue;let s=i.predicate?.subject?.name??"";for(let p of i.links){let a=p.target?.subject;if(!a)continue;let r=a.version,d=r&&typeof r.major=="number"?`@${r.major}.${r.minor}.${r.patch}`:"";n.push({source:t,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Z(t){return!(!t||t.includes(" ")||t.includes(`
|
|
2
|
+
`)||t.startsWith("http://")||t.startsWith("https://")||/^\d{4}-\d{2}/.test(t)||/^\d+(\.\d+)?$/.test(t))}function v(t,e,n,o){if(t.includes("@")&&t.includes("/"))return t;if(t.includes(".")){let i=t.indexOf("."),s=t.substring(0,i),p=t.substring(i+1);if(o){let a=o.get(s);if(a)return`${a.publisher}/${a.package_}/${p}@${a.version}`}return e&&n?`${e}/${p}@${n}`:p}return e&&n?`${e}/${t}@${n}`:t}function _(t){let e=t.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!e)throw new Error("Publisher host cannot be empty");return e}var ee="key_thumbprint",E=class{cache=new Map;prCache=new Map;async discoverProtectedResource(e){let n=_(e);if(this.prCache.has(n))return this.prCache.get(n);let o=`https://${n}/.well-known/oauth-protected-resource`,i=await te(o),s=i&&Array.isArray(i.authorization_servers)?i.authorization_servers.filter(a=>typeof a=="string"):[],p=s.length>0?s:null;return this.prCache.set(n,p),p}async discover(e){let n=_(e);if(this.cache.has(n))return this.cache.get(n);let o=`https://${n}/.well-known/oauth-authorization-server`,i=await this.tryEndpoint(o);if(!i){let s=`https://${n}/.well-known/openid-configuration`;i=await this.tryEndpoint(s)}return this.cache.set(n,i),i}async supportsOAuth(e){return await this.discover(e)!==null}static supportsPkceS256(e){return e.codeChallengeMethodsSupported?.some(n=>n.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(e){return!!e.registrationEndpoint}static supportsAuthorizationCode(e){return e.responseTypesSupported?.some(n=>n.toLowerCase()==="code")??!1}static supportsEnrollment(e){return!!e.enrollmentEndpoint}static supportsSession(e){return!!e.sessionEndpoint}async tryEndpoint(e){let n;try{n=await fetch(e)}catch(i){let s=i instanceof Error?i.message:String(i);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${e} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${e} \u2014 TLS error (${s})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${e} \u2014 network error: ${s}`),null}if(!n.ok)return n.status===404||(n.status===403?(console.error(` OAuth discovery: ${e} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):n.status>=500&&(console.error(` OAuth discovery: ${e} \u2014 HTTP ${n.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let o;try{o=await n.json()}catch{return console.error(` OAuth discovery: ${e} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:C(o.issuer),authorizationEndpoint:C(o.authorization_endpoint),tokenEndpoint:C(o.token_endpoint),registrationEndpoint:C(o.registration_endpoint),revocationEndpoint:C(o.revocation_endpoint),scopesSupported:w(o.scopes_supported),responseTypesSupported:w(o.response_types_supported),grantTypesSupported:w(o.grant_types_supported),codeChallengeMethodsSupported:w(o.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:w(o.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:w(o.dpop_signing_alg_values_supported),enrollmentEndpoint:C(o.enrollment_endpoint),enrollmentIssuanceProtocols:w(o.enrollment_issuance_protocols),enrollmentKeyTypes:w(o.enrollment_key_types),enrollmentScopesSupported:w(o.enrollment_scopes_supported),enrollmentConsentBindingParam:C(o.enrollment_consent_binding_param),sessionEndpoint:C(o.session_endpoint),sessionEndpointAuthMethod:C(o.session_endpoint_auth_method)}}};async function te(t){try{let e=await fetch(t);return e.ok?await e.json():null}catch{return null}}function C(t){return typeof t=="string"?t:null}function w(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"):null}function H(t){let e=t.headers.get("WWW-Authenticate")??void 0,n=t.headers.get("DPoP-Nonce")??void 0;if(!e&&!n)return;let o={wwwAuthenticate:e??""};if(n&&(o.nonce=n),e){let i=e.match(/acr_values\s*=\s*"([^"]*)"/i);i&&(o.acrValues=i[1])}return o}function ne(t){try{return new URL(t).host}catch{return null}}function re(t,e={}){let n=e.discovery??new E,o=new Map,i=new Map,s=async r=>{let d=o.get(r);if(d!==void 0)return d;let y=null,g=await n.discoverProtectedResource(r).catch(()=>null);return g&&g.length>0&&(y=ne(g[0])),o.set(r,y),y},p=async(r,d)=>{if(!t)return null;if(!(d.forceRefresh||d.challenge)&&i.has(r))return i.get(r);let g=await t.resolve(r,d).catch(()=>null);return i.set(r,g),g},a=async(r,d,y,g)=>{let f=await s(d);if(!f)return{res:await R(r,{method:y,redirect:"manual"}),authed:!1};let c=await p(f,{method:y,url:r,...g}),l=c?.headers??{};return{res:await R(r,{method:y,redirect:"manual",headers:l}),authed:!!c}};return async(r,d,y="GET")=>{let g=await a(r,d,y,{});if((g.res.status===401||g.res.status===403)&&g.authed){let f=H(g.res),c={forceRefresh:f===void 0};return f&&(c.challenge=f),(await a(r,d,y,c)).res}return g.res}}var q="KANONAK_TOKEN";function oe(){return typeof process<"u"&&process.env?process.env:{}}function se(t){return`${q}_${t.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var x=class{tokens;env;constructor(e={}){this.tokens=e.tokens??{},this.env=e.env??oe()}async resolve(e,n){let o=_(e),i=this.tokens[o]??this.env[se(o)]??this.env[q];return i?{headers:{Authorization:`Bearer ${i}`}}:null}};export{z as a,L as b,$ as c,_ as d,ee as e,E as f,H as g,re as h,x as i};
|
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Zt,b as Qt,c as eo,d as no,e as H}from"./chunk-EVMSO7HJ.js";import{a as Vn,b as Nn,c as On}from"./chunk-V3DH67P3.js";import{a as Xt,b as Yt,c as Jt,d as tr,e as we,f as or,g as rr,h as ar,i as ir,j as sr,k as cr,l as ur}from"./chunk-J4ZD6IF6.js";import{a as lr}from"./chunk-L2J7WD7E.js";import{a as mt,b as ft,c as kt,d as yt,e as ht,f as vt,g as It,h as _t,i as Lt}from"./chunk-IS3AQKB4.js";import{a as gt,b as St,c as bt,d as Pt,e as Rt,f as Et,h as Kt,i as De,j as Me,k as He,l as Te,m as xt,n as Ct}from"./chunk-BZ3YTI3C.js";import{a as oo,b as ro,c as ao,d as io}from"./chunk-BS7RRG7D.js";import{a as so}from"./chunk-XK24CN3C.js";import{a as wt}from"./chunk-SC5M74NM.js";import{A as Oo,B as $o,C as Uo,D as Do,E as Mo,F as Ho,G as Xo,H as Yo,I as Jo,J as Zo,K as Qo,L as er,M as nr,a as uo,b as lo,c as po,d as mo,e as fo,f as ko,g as yo,h as ho,i as go,j as So,k as bo,l as Po,m as Ro,n as Eo,o as Ko,p as xo,q as wo,r as Co,s as vo,t as Io,u as _o,v as Lo,w as Ao,x as jo,y as Vo,z as No}from"./chunk-AXQ4DBJD.js";import"./chunk-KIBR3HAT.js";import{c as Ln,d as To,e as Fo,g as Bo,h as Wo,k as zo,m as xe,o as An,p as jn,r as Go,s as qo}from"./chunk-Z5Y4MCW5.js";import{a as me}from"./chunk-6VIUXP4N.js";import{a as E,b as D,c as ge,i as V,j as Ke,k as Gt,l as qt,m as L}from"./chunk-PVUBHIU2.js";import{a as j}from"./chunk-HF5FJBS2.js";import{a as co}from"./chunk-PEJALHXK.js";import{$ as Ee,A as rn,B as an,C as sn,D as cn,E as un,F as ln,G as pn,H as dn,I as mn,J as fn,K as kn,L as yn,M as Re,N as hn,O as gn,P as Sn,Q as bn,R as Pn,S as Rn,T as En,U as Kn,V as xn,W as wn,X as Cn,Y as vn,Z as In,_ as _n,a as $t,b as Ut,c as Se,d as Dt,da as Ft,e as M,f as Mt,fa as Bt,g as Ht,ga as h,ha as ee,i as Tt,j as Y,k as J,l as We,m as Z,ma as Wt,n as ze,na as zt,o as Ge,oa as ne,p as qe,q as Xe,r as Ye,s as Je,t as Ze,u as Qe,v as Pe,w as en,x as nn,y as tn,z as on}from"./chunk-7UYXTYXC.js";import{A as be,B as _,C as Q,a as At,b as jt,c as g,d as k,e as Nt,f as Ot,g as fe,h as ke,i as ye,j as G,k as he,l as q,m as u,r as Fe,t as K,w as Be,x as I,y as X,z as y}from"./chunk-CJMVIOZX.js";import{a as Vt}from"./chunk-FUUTGGJS.js";import"./chunk-F67UH4FD.js";import{a as at,b as de,c as z,d as it,e as w,f as st,g as ct,h as ut,i as lt,j as pt,k as dt}from"./chunk-QILEJIFU.js";import{a as to}from"./chunk-ODIECDN7.js";async function $n(n){let e=await new L().parseKanonaks(n),o=await new H().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Un(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Dn(n,e){let o=e??new me(new j);return{kind:"standalone",catalog:await new L().parseKanonaks(new Q(n,o))}}function $(n){return typeof n=="number"?n:void 0}function pr(n){if(!n)return;let e=u(n);if(e===u(fn))return"IRI";if(e===u(kn))return"BlankNode";if(e===u(yn))return"Literal"}function Mn(n){if(!n)return;let e=u(n);if(e===u(hn))return"Violation";if(e===u(gn))return"Warning";if(e===u(Sn))return"Info"}function Ce(n,e){let o=y(n,e);if(o)return[o];let t=[];for(let r of _(n,e))r instanceof k&&t.push(r.subject);return t}function dr(n,e){let o=y(n,Xe);if(!o)return;let t={path:o},r=$(I(n,Ye)),a=$(I(n,Je));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=$(I(n,tn)),i=$(I(n,on));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let c=$(I(n,rn)),p=$(I(n,an));c!==void 0&&(t.minInclusive=c),p!==void 0&&(t.maxInclusive=p);let d=X(n,en);if(d!==void 0){let P=X(n,nn);t.pattern=P!==void 0?{regex:d,flags:P}:{regex:d}}if(Be(n,Pe)){let P=[],N=[];for(let O of _(n,Pe))O instanceof D?P.push(O.value):O instanceof k&&N.push(O.subject);P.length>0&&(t.inValues=P),N.length>0&&(t.inRefs=N)}let S=y(n,Ze);S&&(t.datatype=S);let b=y(n,Qe);b&&(t.classRef=b);let l=pr(y(n,mn));l&&(t.nodeKind=l);let m=X(n,sn);m!==void 0&&(t.message=m);let f=Mn(y(n,Re))??e;return f&&(t.severity=f),t}function te(n){let e=[];for(let o of n){if(!(o instanceof g)||!Fe(o,Z))continue;let t=Mn(y(o,Re)),r={name:o.name,uri:h(o),targetClass:y(o,Ge),targetNodes:Ce(o,cn),targetSubjectsOf:Ce(o,un),targetObjectsOf:Ce(o,ln),closed:I(o,pn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of _(o,dn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of _(o,qe)){let s;if(a instanceof E?s=a:a instanceof k&&(s=K(n,a.subject)),!s)continue;let i=dr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var x="kanonak.org/transformations",oe="values";var re="allowed",C=n=>({type:`${x}/VarRef`,varName:n}),ve=n=>({type:`${x}/IntegerLiteral`,integerLiteral:n}),mr=n=>({type:`${x}/DecimalLiteral`,decimalLiteral:n}),Hn=n=>Number.isInteger(n)?ve(n):mr(n),Tn=n=>({type:`${x}/Count`,source:n}),Fn=(n,e)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Bn=(n,e)=>({type:`${x}/LessThanOrEqual`,compareLeft:n,compareRight:e});function Ie(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function ae(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Fn(Tn(C(oe)),ve(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Bn(Tn(C(oe)),ve(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:C(re),needle:C("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:Ie(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Fn(C("v"),Hn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Bn(C("v"),Hn(n.maxInclusive))}),e}import{evaluate as kr,ExpressionError as yr}from"@kanonak-protocol/expression";function Gn(n,e){let o=hr(e)?e:te(e),t=[];for(let r of o)for(let a of gr(n,r))Pr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function hr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function ie(n){let e=n.predicate;return e instanceof k?e:void 0}function gr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof g),r=a=>{let s=h(a);o.set(s?u(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=u(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let c=h(i);c&&s.has(u(c))&&r(i)}}else for(let s of t)ne(s).some(c=>u(c)===a||ee(n.catalog,c).some(p=>u(p)===a))&&r(s)}for(let a of e.targetNodes){let s=K(n.catalog,a);s instanceof g&&r(s)}for(let a of e.targetSubjectsOf){let s=u(a);for(let i of t)i.statement.some(c=>{let p=ie(c);return p&&u(p.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=u(a);for(let i of t)for(let c of i.statement){let p=ie(c);if(!(!p||u(p.subject)!==s))for(let d of Sr(c)){let S=K(n.catalog,d);S instanceof g&&r(S)}}}return[...o.values()]}function Sr(n){return n instanceof G?[n.object.subject]:n instanceof q?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function br(n,e,o){let t=[];for(let r of n.statement){let a=ie(r);if(!(!a||u(a.subject)!==e)){if(r instanceof fe||r instanceof ge)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof ke)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof ye)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof G)t.push({kernel:{ref:u(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof he)t.push(Wn(r.object,o,t.length));else if(r instanceof q){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:u(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof E)t.push(Wn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Wn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function Pr(n,e,o,t){let r=h(o),a=r?u(r):`${o.namespace}/${o.name}`;for(let s of e.properties)Er(n,e,o,a,r,s,t);e.closed&&vr(e,o,a,r,t)}function _e(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??qn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function qn(n){return n.severity??"Violation"}var Rr={minCount:bn,maxCount:Pn,in:Kn,pattern:xn,minLength:wn,maxLength:Cn,minInclusive:vn,maxInclusive:In};function Er(n,e,o,t,r,a,s){let i=u(a.path),c=br(o,i,t),p=a.severity??qn(e),d=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:u(l)}))],b=(l,m,f)=>{s.push(_e(e,t,r,l,a.message??m,{resultPath:a.path,value:f?.literal,valueRef:f?.ref},p))};for(let l of ae(a)){let m=Rr[l.component];if(l.per==="node"){zn(l,{[oe]:c.map(P=>P.kernel),[re]:S})||b(m,l.component==="minCount"?`'${d}' has ${c.length} value(s); minCount is ${a.minCount}.`:`'${d}' has ${c.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let f of c){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&f.kind!=="string"){b(m,`'${d}' value is not a string; ${l.component} applies to string values.`,f);continue}zn(l,{v:f.kernel,[re]:S})||b(m,Kr(l,d,a,f),f)}}if(a.nodeKind)for(let l of c)xr(a.nodeKind,l)||b(_n,`'${d}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of c){let m=wr(a.datatype,l);m&&b(Rn,`'${d}' ${m}`,l)}if(a.classRef)for(let l of c){let m=Cr(n,a.classRef,l);m&&b(En,`'${d}' ${m}`,l)}}function Kr(n,e,o,t){let r=t.ref?u(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function zn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new yr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return kr(n.expr,void 0,o)===1}function xr(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function wr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Ke(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function Cr(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=u(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`;let r=K(n.catalog,o.ref);return r instanceof g?ne(r).some(s=>u(s)===t||ee(n.catalog,s).some(i=>u(i)===t))?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`:`value ${u(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function vr(n,e,o,t,r){let a=new Set([...n.properties.map(i=>u(i.path)),...n.ignoredProperties.map(i=>u(i))]),s=new Set;for(let i of e.statement){let c=ie(i);if(!c)continue;let p=u(c.subject);a.has(p)||s.has(p)||(s.add(p),r.push(_e(n,o,t,Ee,`'${e.name}' carries undeclared property '${c.subject.name}' (closed shape).`,{resultPath:c.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(_e(n,o,t,Ee,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Le from"js-yaml";import{VersionOperator as Xn}from"@kanonak-protocol/types/document/models/enums";var Ir="0.0.0",A=class{constructor(e,o=new j,t){this.repository=e;this.parser=o;this.objectParser=t??new L(this.parser)}repository;parser;objectParser;imports(){return new T}serializeValue(e,o){return Zn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Ae(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Jn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Jn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Le.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Yn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Le.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new Q(a,this.repository))).filter(p=>p instanceof g&&p.namespace===s&&p.name!==Yn);for(let p of c)p.namespace="ephemeral";return we(c)}},Yn="__pkgbuilder_probe__";function Jn(n){return new TextEncoder().encode(n).length}function Ae(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var T=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=Xn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let c=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,w(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Ir,r??o,Xn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:de(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=F(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Zn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Zn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof E)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(_r(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function F(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function _r(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var Lr="1.1.0";async function Qn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Y,J,Lr,"sh"),r=(i,c)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,w(i.version),i.package_)}.${i.name}`:c,a={},s=[];return n.result.results.forEach((i,c)=>{let p=`result-${c+1}`;s.push(p);let d={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(d[`${t}.resultPath`]=r(i.resultPath,u(i.resultPath))),i.sourceShapeUri&&(d[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?d[`${t}.value`]=r(i.valueRef,u(i.valueRef)):i.value!==void 0&&(d[`${t}.value`]=i.value),a[p]=d}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as ji}from"@kanonak-protocol/types/document/models/enums";var se=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${w(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=Se(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var je={async authorize(){return{allowed:!0}}},Ve={async record(){}},B=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ce=class{inner;ctx;policy;meter;constructor(e,o,t=je,r=Ve){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new B(e,o.reason)}};var R="kanonak.org",v="view",et="core-kanonak",Ar={publisher:R,package_:v,name:"rootView"},jr={publisher:R,package_:v,name:"bind"},Vr={publisher:R,package_:v,name:"produces"},Nr={publisher:R,package_:v,name:"projections"},Or={publisher:R,package_:v,name:"where"},$r={publisher:R,package_:v,name:"value"},Ur={publisher:R,package_:v,name:"as"},ue=class{constructor(e,o=new j){this.repository=e;this.parser=o;this.objectParser=new L(this.parser),this.builder=new A(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=y(r,jr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=y(r,Vr);if(!s)throw new Error(`View ${r.namespace}/${r.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Dr(r),c=nt(t,R,et),p=nt(t,R,v),d=this.builder.imports(),S=d.ensure(R,et,c,"ck"),b=d.ensure(R,v,p,"v"),l=d.ref(s),m=new jn(this.repository,this.parser,this.objectParser),f=new An(m,t),P=this.readProjections(t,r),N=Tr(r,Or),O=this.findInstances(t,a,await this.reason(o)),Ne={},ot=new Set;for(let W of O){if(!await this.passesWhere(f,t,N,W))continue;let pe={type:l};for(let $e of P){let rt=await this.evaluateValue(f,t,$e.value,W),Ue=this.builder.serializeValue(tt(rt),d);Ue!==void 0&&(pe[d.ref($e.as)]=Ue)}let Oe=h(W);Oe&&(pe[`${b}.derivedFrom`]=d.ref(Oe)),Ne[this.rowName(W,ot)]=pe}let le={};o.resolvedAt&&(le[`${S}.resolvedAt`]=o.resolvedAt),o.invocationId&&(le[`${S}.id`]=o.invocationId);let U=await this.builder.buildContentAddressed({publisher:i,book:d,body:Ne,contentHashProperty:`${S}.contentHash`,header:le});return{yaml:U.yaml,contentHash:U.contentHash,packageName:U.packageName,publisher:U.publisher,rowCount:U.resourceCount}}resolveView(e,o){let t=K(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=y(t,Ar);if(r){let a=K(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of _(o,Nr)){let a=r instanceof E?r:r instanceof k?K(e,r.subject):void 0;if(!a)continue;let s=be(a,$r),i=y(a,Ur);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new H({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Hr(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let c=r.get(i);c&&a.push(c)}return a.sort((i,c)=>{let p=M(h(i)),d=M(h(c));return p<d?-1:p>d?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Fr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=Ln(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=F(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function tt(n){return xe(n)?n.value:Array.isArray(n)?n.map(tt):n}function Dr(n){let e=h(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function nt(n,e,o){let t=Mr(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Mr(n,e,o){let t;for(let r of n){if(!(r instanceof g))continue;let a=h(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?w(t):void 0}function Hr(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof g))continue;let r=h(t);if(!r||!r.version)continue;let a=M(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Tr(n,e){let o=be(n,e);return o?[o]:_(n,e).filter(t=>t instanceof E)}function Fr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:xe(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{Lo as AmbiguousReferenceRule,ye as BooleanStatement,or as CANONICAL_FORM_VERSION,V as Carrier,$o as ClassDefinitionRule,Ko as ClassHierarchyCycleRule,kt as CompositeKanonakDocumentRepository,ar as DEFAULT_CONSENT_BINDING_PARAM,jt as DefinedKanonak,er as DiamondNameClashRule,Do as DisplayLensScopeRule,ft as DocumentLocation,Yt as EdgeType,E as EmbeddedKanonak,Po as EmbeddedKanonakTypeRule,he as EmbeddedStatement,B as EntitlementDeniedError,ce as EntitlementProducer,mt as FileSystemKanonakDocumentRepository,to as GitIgnoreFilter,Jt as GraphBuilder,Ct as HttpKanonakDocumentRepository,De as INTEGRITY_PREFIX,T as ImportBook,Ro as ImportExistenceRule,me as InMemoryKanonakDocumentRepository,gt as KANONAK_USER_AGENT,At as Kanonak,ro as KanonakDocumentPositions,L as KanonakObjectParser,nr as KanonakObjectValidator,j as KanonakParser,Vt as KanonakUri,so as KanonakUriBuilder,co as KanonakUrlResolver,Ft as KanonakVocabulary,Fo as LINE_STYLES,ko as LinkTargetRule,q as ListStatement,D as LiteralKanonak,vt as LocalFirstRepository,It as LockAwareRepository,Yo as LookBandPathRule,Go as LookRenderer,Mo as LookSemanticSvgPathRule,Uo as MarkdownLinkRule,ge as MarkdownStatement,Io as NamespaceImportCycleRule,yo as NamespacePrefixRule,Xt as NodeType,ke as NumberStatement,ir as OAuthDiscovery,eo as OWL_RL_CLASSIFICATION_RULES,jo as ObjectPropertyValueValidationRule,po as OntologyValidationError,uo as OntologyValidationResult,Qo as OwlOneOfRule,A as PackageBuilder,bo as PackageHeaderRule,se as ProducerRepository,Vo as PropertyDomainRule,xo as PropertyHierarchyCycleRule,No as PropertyKindRangeConsistencyRule,oo as PropertyMetadata,Ao as PropertyRangeReferenceRule,wo as PropertyRangeRequiredRule,go as PropertyTypeSpecificityRule,Kt as PublisherConfigResolver,xt as PublisherIndex,Qt as RDFS_RULES,H as Reasoner,no as ReasoningResult,k as ReferenceKanonak,G as ReferenceStatement,ht as RepositoryFactory,Oo as ReservedNameShadowRule,ho as ResourceNamingRule,$t as ResourceResolver,Bt as ResourceTypeClassifier,J as SHACL_PACKAGE,Y as SHACL_PUBLISHER,Z as SH_NODE_SHAPE,ze as SH_PROPERTY_SHAPE,We as SH_SHAPE,Ot as ScalarStatement,Xo as SequenceNarrativeRule,Zo as ShaclShapeRule,Nt as Statement,fe as StringStatement,Co as SubClassOfReferenceRule,vo as SubPropertyOfReferenceRule,g as SubjectKanonak,So as SubjectKanonakTypeRequiredRule,ur as TokenCredentialProvider,Zt as TripleStore,Ho as TxExpressionCompilesRule,Jo as TxExpressionPathRule,Ut as TypeResolver,_o as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,fo as ValidationCache,mo as ValidationContext,lo as ValidationSeverity,ji as VersionOperator,ue as ViewMaterializer,je as allowAllPolicy,Pt as assertHttpsUrl,wt as assertPackageIdentity,Lt as buildLocalFirstRepository,zo as buildOntologyModel,Qn as buildReportPackageAsync,te as buildShapesModel,tr as canonicalForm,we as canonicalHash,Ke as carrierOf,_t as collectKanonakFiles,z as compareVersions,On as computeIntegrity,Te as computeIntegrityAsync,Ae as contentAddressedName,ne as contextTypesOf,cr as createCredentialedFetch,st as createVersion,Gn as evaluateConformance,qt as extractMarkdownLinks,lr as findDerivation,Gt as findMalformedReferences,io as findMarkdownLinkAt,Ie as foldFlagsIntoPattern,Dt as formatKanonakAddress,w as formatVersion,yt as getGlobalCachePath,bt as getKanonakUserAgent,ut as isCompatibleVersion,lt as isMajorCompatible,Rt as kanonakFetch,Vn as loadLockFile,ae as lowerConstraint,Mt as makeUriKey,Ve as noopMeter,rr as normalizeHost,sr as parseAuthChallenge,Se as parseKanonakAddress,Me as parseLockFile,ct as parseVersionString,ao as parseWithPositions,dt as pickHighestDocument,Wt as propertiesInScope,Bo as readSequenceConnectors,To as resolveDisplayValue,zt as resolvePropertyStep,F as sanitizeName,pt as satisfiesVersionOperator,Nn as saveLockFile,Un as scopeFromCatalog,Dn as scopeFromDocumentAsync,$n as scopeFromRepositoryAsync,He as serializeLockFile,Et as setKanonakFetchRetries,St as setKanonakUserAgent,h as subjectUri,ee as superClassChain,qo as supportedBandKeys,Ht as tripleKey,M as uriKey,Tt as uriTriple,at as versionOperatorFromChar,de as versionOperatorToChar,it as versionsEqual,Wo as walkSequence};
|
|
1
|
+
import{a as Do,b as Ho,c as To,d as Fo,e as D}from"./chunk-EVMSO7HJ.js";import{a as Kn,b as xn,c as Cn}from"./chunk-V3DH67P3.js";import{a as Ao,b as $o,c as Mo,d as qt,e as Xt,f as Yt,g as Jt,h as Qt,i as Zt}from"./chunk-PXS6XZ3V.js";import{a as er}from"./chunk-L2J7WD7E.js";import{a as Ft,b as Bt,c as Wt,d as H,e as Gt,f as zt,g as ge,h as nr,i as or,j as tr,k as rr,l as ar}from"./chunk-PRXC2HZ3.js";import{a as Zn,b as eo,c as no,d as oo,e as to,f as ko,g as ho,h as So,i as go}from"./chunk-IS3AQKB4.js";import{a as ro,b as ao,c as io,d as so,e as co,f as uo,h as lo,i as ve,j as Le,k as _e,l as Ie,m as po,n as mo}from"./chunk-BZ3YTI3C.js";import{a as Wo,b as Go,c as zo,d as qo}from"./chunk-BS7RRG7D.js";import{a as Xo}from"./chunk-XK24CN3C.js";import{a as fo}from"./chunk-SC5M74NM.js";import{A as Kt,B as xt,C as Ct,D as Pt,E as vt,F as Lt,G as Ut,H as At,I as $t,J as Mt,K as Dt,L as Ht,M as Tt,a as Jo,b as Qo,c as Zo,d as et,e as nt,f as ot,g as tt,h as rt,i as at,j as it,k as st,l as ct,m as ut,n as lt,o as pt,p as dt,q as ft,r as mt,s as kt,t as ht,u as St,v as gt,w as yt,x as bt,y as Rt,z as Et}from"./chunk-LRVOGQI5.js";import"./chunk-KIBR3HAT.js";import{c as bn,d as _t,e as It,g as wt,h as Vt,k as Nt,m as Se,o as Rn,p as En,r as jt,s as Ot}from"./chunk-DD3TCFBT.js";import"./chunk-QHABFCRC.js";import{a as ie}from"./chunk-6VIUXP4N.js";import{a as v,b as $,c as pe,i as I,j as he,k as Oo,l as Uo,m as N}from"./chunk-PVUBHIU2.js";import{a as A}from"./chunk-HF5FJBS2.js";import{a as Yo}from"./chunk-PEJALHXK.js";import{$ as ke,A as Ge,B as ze,C as qe,D as Xe,E as Ye,F as Je,G as Qe,H as Ze,I as en,J as nn,K as on,L as tn,M as me,N as rn,O as an,P as sn,Q as cn,R as un,S as ln,T as pn,U as dn,V as fn,W as mn,X as kn,Y as hn,Z as Sn,_ as gn,a as xo,b as Co,c as Po,d as vo,da as wo,e as M,f as Lo,fa as Vo,g as _o,ga as h,ha as Y,i as Io,j as z,k as q,l as Ne,m as X,ma as No,n as je,na as jo,o as Oe,oa as J,p as Ue,q as Ae,r as $e,s as Me,t as De,u as He,v as fe,w as Te,x as Fe,y as Be,z as We}from"./chunk-7UYXTYXC.js";import{A as de,B as _,C as yn,a as yo,b as bo,c as R,d as g,e as Eo,f as Ko,g as se,h as ce,i as ue,j as B,k as le,l as W,m as c,r as we,t as K,w as Ve,x as L,y as G,z as k}from"./chunk-CJMVIOZX.js";import{a as Ro}from"./chunk-FUUTGGJS.js";import"./chunk-F67UH4FD.js";import{a as Bn,b as Wn,c as F,d as Gn,e as U,f as zn,g as qn,h as Xn,i as Yn,j as Jn,k as Qn}from"./chunk-QILEJIFU.js";import{a as Bo}from"./chunk-ODIECDN7.js";async function Pn(e){let n=await new N().parseKanonaks(e),r=await new D().reason(e);return{kind:"merged",catalog:n,reasoning:r}}function vn(e,n){return{kind:"merged",catalog:e,reasoning:n}}async function Ln(e,n){let r=n??new ie(new A);return{kind:"standalone",catalog:await new N().parseKanonaks(new yn(e,r))}}function j(e){return typeof e=="number"?e:void 0}function ir(e){if(!e)return;let n=c(e);if(n===c(nn))return"IRI";if(n===c(on))return"BlankNode";if(n===c(tn))return"Literal"}function _n(e){if(!e)return;let n=c(e);if(n===c(rn))return"Violation";if(n===c(an))return"Warning";if(n===c(sn))return"Info"}function ye(e,n){let r=k(e,n);if(r)return[r];let o=[];for(let t of _(e,n))t instanceof g&&o.push(t.subject);return o}function sr(e,n){let r=k(e,Ae);if(!r)return;let o={path:r},t=j(L(e,$e)),a=j(L(e,Me));t!==void 0&&(o.minCount=t),a!==void 0&&(o.maxCount=a);let s=j(L(e,Be)),i=j(L(e,We));s!==void 0&&(o.minLength=s),i!==void 0&&(o.maxLength=i);let u=j(L(e,Ge)),d=j(L(e,ze));u!==void 0&&(o.minInclusive=u),d!==void 0&&(o.maxInclusive=d);let p=G(e,Te);if(p!==void 0){let b=G(e,Fe);o.pattern=b!==void 0?{regex:p,flags:b}:{regex:p}}if(Ve(e,fe)){let b=[],w=[];for(let V of _(e,fe))V instanceof $?b.push(V.value):V instanceof g&&w.push(V.subject);b.length>0&&(o.inValues=b),w.length>0&&(o.inRefs=w)}let S=k(e,De);S&&(o.datatype=S);let y=k(e,He);y&&(o.classRef=y);let l=ir(k(e,en));l&&(o.nodeKind=l);let f=G(e,qe);f!==void 0&&(o.message=f);let m=_n(k(e,me))??n;return m&&(o.severity=m),o}function Q(e){let n=[];for(let r of e){if(!(r instanceof R)||!we(r,X))continue;let o=_n(k(r,me)),t={name:r.name,uri:h(r),targetClass:k(r,Oe),targetNodes:ye(r,Xe),targetSubjectsOf:ye(r,Ye),targetObjectsOf:ye(r,Je),closed:L(r,Qe)===!0,ignoredProperties:[],severity:o,properties:[]};for(let a of _(r,Ze))a instanceof g&&t.ignoredProperties.push(a.subject);for(let a of _(r,Ue)){let s;if(a instanceof v?s=a:a instanceof g&&(s=K(e,a.subject)),!s)continue;let i=sr(s,o);i&&t.properties.push(i)}n.push(t)}return n}var x="kanonak.org/transformations",Z="values";var ee="allowed",C=e=>({type:`${x}/VarRef`,varName:e}),be=e=>({type:`${x}/IntegerLiteral`,integerLiteral:e}),cr=e=>({type:`${x}/DecimalLiteral`,decimalLiteral:e}),In=e=>Number.isInteger(e)?be(e):cr(e),wn=e=>({type:`${x}/Count`,source:e}),Vn=(e,n)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:e,compareRight:n}),Nn=(e,n)=>({type:`${x}/LessThanOrEqual`,compareLeft:e,compareRight:n});function Re(e,n){if(!n||n.length===0)return e;let r=new Set(["i","m","s"]),o=[...new Set(n.split(""))];if(o.filter(a=>!r.has(a)).length>0)throw new Error(`sh:flags '${n}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${o.sort().join("")})${e}`}function ne(e){let n=[];return e.minCount!==void 0&&n.push({component:"minCount",per:"node",expr:Vn(wn(C(Z)),be(e.minCount))}),e.maxCount!==void 0&&n.push({component:"maxCount",per:"node",expr:Nn(wn(C(Z)),be(e.maxCount))}),(e.inValues!==void 0||e.inRefs!==void 0)&&n.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:C(ee),needle:C("v")}}),e.pattern!==void 0&&n.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:Re(e.pattern.regex,e.pattern.flags)}}),e.minLength!==void 0&&n.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{${e.minLength},}$`}}),e.maxLength!==void 0&&n.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{0,${e.maxLength}}$`}}),e.minInclusive!==void 0&&n.push({component:"minInclusive",per:"value",expr:Vn(C("v"),In(e.minInclusive))}),e.maxInclusive!==void 0&&n.push({component:"maxInclusive",per:"value",expr:Nn(C("v"),In(e.maxInclusive))}),n}import{evaluate as lr,ExpressionError as pr}from"@kanonak-protocol/expression";function Un(e,n){let r=dr(n)?n:Q(n),o=[];for(let t of r)for(let a of fr(e,t))hr(e,t,a,o);return{conforms:!o.some(t=>t.severity==="Violation"),results:o}}function dr(e){return e.length>0&&!(e[0]instanceof Object&&"statement"in e[0])&&typeof e[0].name=="string"&&"properties"in e[0]}function oe(e){let n=e.predicate;return n instanceof g?n:void 0}function fr(e,n){let r=new Map,o=e.catalog.filter(a=>a instanceof R),t=a=>{let s=h(a);r.set(s?c(s):`${a.namespace}/${a.name}`,a)};if(n.targetClass){let a=c(n.targetClass);if(e.reasoning){let s=new Set(e.reasoning.getInstancesOfClass(n.targetClass));for(let i of o){let u=h(i);u&&s.has(c(u))&&t(i)}}else for(let s of o)J(s).some(u=>c(u)===a||Y(e.catalog,u).some(d=>c(d)===a))&&t(s)}for(let a of n.targetNodes){let s=K(e.catalog,a);s instanceof R&&t(s)}for(let a of n.targetSubjectsOf){let s=c(a);for(let i of o)i.statement.some(u=>{let d=oe(u);return d&&c(d.subject)===s})&&t(i)}for(let a of n.targetObjectsOf){let s=c(a);for(let i of o)for(let u of i.statement){let d=oe(u);if(!(!d||c(d.subject)!==s))for(let p of mr(u)){let S=K(e.catalog,p);S instanceof R&&t(S)}}}return[...r.values()]}function mr(e){return e instanceof B?[e.object.subject]:e instanceof W?(e.object??[]).filter(n=>n instanceof g).map(n=>n.subject):[]}function kr(e,n,r){let o=[];for(let t of e.statement){let a=oe(t);if(!(!a||c(a.subject)!==n)){if(t instanceof se||t instanceof pe)o.push({kernel:t.object,kind:"string",literal:t.object});else if(t instanceof ce)o.push({kernel:t.object,kind:"number",literal:t.object});else if(t instanceof ue)o.push({kernel:t.object?1:0,kind:"boolean",literal:t.object});else if(t instanceof B)o.push({kernel:{ref:c(t.object.subject)},kind:"reference",ref:t.object.subject});else if(t instanceof le)o.push(jn(t.object,r,o.length));else if(t instanceof W){for(let s of t.object??[])if(s instanceof g)o.push({kernel:{ref:c(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof v)o.push(jn(s,r,o.length));else if(s instanceof $){let i=s.value;typeof i=="boolean"?o.push({kernel:i?1:0,kind:"boolean",literal:i}):o.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return o}function jn(e,n,r){let o=e.name&&e.name.length>0?e.name:String(r);return{kernel:{ref:`${n}#${o}`},kind:"embedded"}}function hr(e,n,r,o){let t=h(r),a=t?c(t):`${r.namespace}/${r.name}`;for(let s of n.properties)gr(e,n,r,a,t,s,o);n.closed&&Kr(n,r,a,t,o)}function Ee(e,n,r,o,t,a={},s){return{focusNode:n,focusUri:r,constraintComponent:o,severity:s??An(e),message:t,sourceShape:e.name,sourceShapeUri:e.uri,...a}}function An(e){return e.severity??"Violation"}var Sr={minCount:cn,maxCount:un,in:dn,pattern:fn,minLength:mn,maxLength:kn,minInclusive:hn,maxInclusive:Sn};function gr(e,n,r,o,t,a,s){let i=c(a.path),u=kr(r,i,o),d=a.severity??An(n),p=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:c(l)}))],y=(l,f,m)=>{s.push(Ee(n,o,t,l,a.message??f,{resultPath:a.path,value:m?.literal,valueRef:m?.ref},d))};for(let l of ne(a)){let f=Sr[l.component];if(l.per==="node"){On(l,{[Z]:u.map(b=>b.kernel),[ee]:S})||y(f,l.component==="minCount"?`'${p}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${p}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let m of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&m.kind!=="string"){y(f,`'${p}' value is not a string; ${l.component} applies to string values.`,m);continue}On(l,{v:m.kernel,[ee]:S})||y(f,yr(l,p,a,m),m)}}if(a.nodeKind)for(let l of u)br(a.nodeKind,l)||y(gn,`'${p}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=Rr(a.datatype,l);f&&y(ln,`'${p}' ${f}`,l)}if(a.classRef)for(let l of u){let f=Er(e,a.classRef,l);f&&y(pn,`'${p}' ${f}`,l)}}function yr(e,n,r,o){let t=o.ref?c(o.ref):JSON.stringify(o.literal);switch(e.component){case"in":return`'${n}' value ${t} is not in the permitted set.`;case"pattern":return`'${n}' value ${t} does not match pattern ${r.pattern?.regex}.`;case"minLength":return`'${n}' value ${t} is shorter than minLength ${r.minLength}.`;case"maxLength":return`'${n}' value ${t} is longer than maxLength ${r.maxLength}.`;case"minInclusive":return`'${n}' value ${t} is below minInclusive ${r.minInclusive} (or not numeric).`;case"maxInclusive":return`'${n}' value ${t} is above maxInclusive ${r.maxInclusive} (or not numeric).`;default:return`'${n}' value ${t} violates ${e.component}.`}}function On(e,n){let r=o=>{let t=o.varName;if(o.type==="kanonak.org/transformations/VarRef"&&typeof t=="string"&&t in n)return n[t];throw new pr(`Conformance lowering produced an unexpected leaf '${o.type}'`)};return lr(e.expr,void 0,r)===1}function br(e,n){switch(e){case"IRI":return n.kind==="reference";case"BlankNode":return n.kind==="embedded";case"Literal":return n.kind==="string"||n.kind==="number"||n.kind==="boolean"}}function Rr(e,n){if(n.kind==="reference"||n.kind==="embedded")return`value is a ${n.kind}; sh:datatype requires a literal of ${e.name}.`;let r=he(e);if(r!==void 0)switch(r){case I.Boolean:return n.kind==="boolean"?void 0:`value is not a boolean (${e.name}).`;case I.Integer:return n.kind!=="number"?`value is not a number (${e.name}).`:Number.isInteger(n.literal)?void 0:`value is not an integer (${e.name}).`;case I.Decimal:case I.Double:case I.Float:return n.kind==="number"?void 0:`value is not a number (${e.name}).`;default:return n.kind==="string"?void 0:`value is not a string-carried literal (${e.name}).`}}function Er(e,n,r){if(r.kind!=="reference"||!r.ref)return`value is not a reference; sh:class requires an instance of ${n.name}.`;let o=c(n);if(e.reasoning)return e.reasoning.isInstanceOf(r.ref,n)?void 0:`value ${c(r.ref)} is not an instance of ${n.name}.`;let t=K(e.catalog,r.ref);return t instanceof R?J(t).some(s=>c(s)===o||Y(e.catalog,s).some(i=>c(i)===o))?void 0:`value ${c(r.ref)} is not an instance of ${n.name}.`:`value ${c(r.ref)} does not resolve in this scope (sh:class ${n.name}).`}function Kr(e,n,r,o,t){let a=new Set([...e.properties.map(i=>c(i.path)),...e.ignoredProperties.map(i=>c(i))]),s=new Set;for(let i of n.statement){let u=oe(i);if(!u)continue;let d=c(u.subject);a.has(d)||s.has(d)||(s.add(d),t.push(Ee(e,r,o,ke,`'${n.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of n.unresolvedPredicates)s.has(i.key)||(s.add(i.key),t.push(Ee(e,r,o,ke,`'${n.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}var xr="1.1.0";async function $n(e){let n=new H(e.repository),r=n.imports(),o=r.ensure(z,q,xr,"sh"),t=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${r.ensure(i.publisher,i.package_,U(i.version),i.package_)}.${i.name}`:u,a={},s=[];return e.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let p={type:`${o}.ValidationResult`,[`${o}.focusNode`]:t(i.focusUri,i.focusNode),[`${o}.resultMessage`]:i.message,[`${o}.resultSeverity`]:`${o}.${i.severity}`,[`${o}.sourceConstraintComponent`]:`${o}.${i.constraintComponent.name}`};i.resultPath&&(p[`${o}.resultPath`]=t(i.resultPath,c(i.resultPath))),i.sourceShapeUri&&(p[`${o}.sourceShape`]=t(i.sourceShapeUri,i.sourceShape)),i.valueRef?p[`${o}.value`]=t(i.valueRef,c(i.valueRef)):i.value!==void 0&&(p[`${o}.value`]=i.value),a[d]=p}),a.report={type:`${o}.ValidationReport`,[`${o}.conforms`]:e.result.conforms,...s.length>0?{[`${o}.result`]:s}:{}},n.buildContentAddressed({publisher:e.publisher,book:r,body:a,...e.header!==void 0?{header:e.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as ci}from"@kanonak-protocol/types/document/models/enums";var E="kanonak.org",P="view",Mn="core-kanonak",Cr={publisher:E,package_:P,name:"rootView"},Pr={publisher:E,package_:P,name:"bind"},vr={publisher:E,package_:P,name:"produces"},Lr={publisher:E,package_:P,name:"projections"},_r={publisher:E,package_:P,name:"where"},Ir={publisher:E,package_:P,name:"value"},wr={publisher:E,package_:P,name:"as"},te=class{constructor(n,r=new A){this.repository=n;this.parser=r;this.objectParser=new N(this.parser),this.builder=new H(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(n,r={}){let o=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(o,n),a=k(t,Pr);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let s=k(t,vr);if(!s)throw new Error(`View ${t.namespace}/${t.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Vr(t),u=Dn(o,E,Mn),d=Dn(o,E,P),p=this.builder.imports(),S=p.ensure(E,Mn,u,"ck"),y=p.ensure(E,P,d,"v"),l=p.ref(s),f=new En(this.repository,this.parser,this.objectParser),m=new Rn(f,o),b=this.readProjections(o,t),w=Or(t,_r),V=this.findInstances(o,a,await this.reason(r)),Ke={},Tn=new Set;for(let T of V){if(!await this.passesWhere(m,o,w,T))continue;let ae={type:l};for(let Ce of b){let Fn=await this.evaluateValue(m,o,Ce.value,T),Pe=this.builder.serializeValue(Hn(Fn),p);Pe!==void 0&&(ae[p.ref(Ce.as)]=Pe)}let xe=h(T);xe&&(ae[`${y}.derivedFrom`]=p.ref(xe)),Ke[this.rowName(T,Tn)]=ae}let re={};r.resolvedAt&&(re[`${S}.resolvedAt`]=r.resolvedAt),r.invocationId&&(re[`${S}.id`]=r.invocationId);let O=await this.builder.buildContentAddressed({publisher:i,book:p,body:Ke,contentHashProperty:`${S}.contentHash`,header:re});return{yaml:O.yaml,contentHash:O.contentHash,packageName:O.packageName,publisher:O.publisher,rowCount:O.resourceCount}}resolveView(n,r){let o=K(n,r);if(!o)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=k(o,Cr);if(t){let a=K(n,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return o}readProjections(n,r){let o=[];for(let t of _(r,Lr)){let a=t instanceof v?t:t instanceof g?K(n,t.subject):void 0;if(!a)continue;let s=de(a,Ir),i=k(a,wr);s&&i&&o.push({value:s,as:i})}return o}async reason(n){return new D({profile:n.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(n,r,o){let t=jr(n),a=[],s=new Set;for(let i of o.getInstancesOfClass(r)){if(s.has(i))continue;s.add(i);let u=t.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=M(h(i)),p=M(h(u));return d<p?-1:d>p?1:0}),a}async passesWhere(n,r,o,t){for(let a of o){let s=await this.evaluateValue(n,r,a,t);if(!Ur(s))return!1}return!0}async evaluateValue(n,r,o,t){let a=bn(o,"view-projection",{catalog:r,depth:0}),s=new Map([["input",t]]);return n.evaluate(a,s)}rowName(n,r){let o=ge(n.name)||"row",t=o,a=2;for(;r.has(t);)t=`${o}-${a++}`;return r.add(t),t}};function Hn(e){return Se(e)?e.value:Array.isArray(e)?e.map(Hn):e}function Vr(e){let n=h(e);if(!n)throw new Error(`Could not derive a publisher from view ${e.namespace}/${e.name}.`);return n.publisher}function Dn(e,n,r){let o=Nr(e,n,r);if(!o)throw new Error(`Package ${n}/${r} is not in the catalog; it must be importable to materialize a view.`);return o}function Nr(e,n,r){let o;for(let t of e){if(!(t instanceof R))continue;let a=h(t);!a||a.publisher!==n||a.package_!==r||!a.version||(!o||F(a.version,o)>0)&&(o=a.version)}return o?U(o):void 0}function jr(e){let n=new Map,r=new Map;for(let o of e){if(!(o instanceof R))continue;let t=h(o);if(!t||!t.version)continue;let a=M(t),s=r.get(a);(!s||F(t.version,s)>0)&&(r.set(a,t.version),n.set(a,o))}return n}function Or(e,n){let r=de(e,n);return r?[r]:_(e,n).filter(o=>o instanceof v)}function Ur(e){return e===!0?!0:e===!1||e===void 0||e===null?!1:typeof e=="string"?e.length>0:typeof e=="number"?e!==0:Se(e)?e.value.length>0:Array.isArray(e)?e.length>0:!!e}export{gt as AmbiguousReferenceRule,ue as BooleanStatement,Wt as CANONICAL_FORM_VERSION,I as Carrier,xt as ClassDefinitionRule,pt as ClassHierarchyCycleRule,no as CompositeKanonakDocumentRepository,Xt as DEFAULT_CONSENT_BINDING_PARAM,bo as DefinedKanonak,Ht as DiamondNameClashRule,Pt as DisplayLensScopeRule,eo as DocumentLocation,$o as EdgeType,v as EmbeddedKanonak,ct as EmbeddedKanonakTypeRule,le as EmbeddedStatement,rr as EntitlementDeniedError,ar as EntitlementProducer,Zn as FileSystemKanonakDocumentRepository,Bo as GitIgnoreFilter,Mo as GraphBuilder,mo as HttpKanonakDocumentRepository,ve as INTEGRITY_PREFIX,zt as ImportBook,ut as ImportExistenceRule,ie as InMemoryKanonakDocumentRepository,ro as KANONAK_USER_AGENT,yo as Kanonak,Go as KanonakDocumentPositions,N as KanonakObjectParser,Tt as KanonakObjectValidator,A as KanonakParser,Ro as KanonakUri,Xo as KanonakUriBuilder,Yo as KanonakUrlResolver,wo as KanonakVocabulary,It as LINE_STYLES,ot as LinkTargetRule,W as ListStatement,$ as LiteralKanonak,ko as LocalFirstRepository,ho as LockAwareRepository,At as LookBandPathRule,jt as LookRenderer,vt as LookSemanticSvgPathRule,Ct as MarkdownLinkRule,pe as MarkdownStatement,ht as NamespaceImportCycleRule,tt as NamespacePrefixRule,Ao as NodeType,ce as NumberStatement,Yt as OAuthDiscovery,To as OWL_RL_CLASSIFICATION_RULES,bt as ObjectPropertyValueValidationRule,Zo as OntologyValidationError,Jo as OntologyValidationResult,Dt as OwlOneOfRule,H as PackageBuilder,st as PackageHeaderRule,nr as ProducerRepository,Rt as PropertyDomainRule,dt as PropertyHierarchyCycleRule,Et as PropertyKindRangeConsistencyRule,Wo as PropertyMetadata,yt as PropertyRangeReferenceRule,ft as PropertyRangeRequiredRule,at as PropertyTypeSpecificityRule,lo as PublisherConfigResolver,po as PublisherIndex,Ho as RDFS_RULES,D as Reasoner,Fo as ReasoningResult,g as ReferenceKanonak,B as ReferenceStatement,to as RepositoryFactory,Kt as ReservedNameShadowRule,rt as ResourceNamingRule,xo as ResourceResolver,Vo as ResourceTypeClassifier,q as SHACL_PACKAGE,z as SHACL_PUBLISHER,X as SH_NODE_SHAPE,je as SH_PROPERTY_SHAPE,Ne as SH_SHAPE,Ko as ScalarStatement,Ut as SequenceNarrativeRule,Mt as ShaclShapeRule,Eo as Statement,se as StringStatement,mt as SubClassOfReferenceRule,kt as SubPropertyOfReferenceRule,R as SubjectKanonak,it as SubjectKanonakTypeRequiredRule,Zt as TokenCredentialProvider,Do as TripleStore,Lt as TxExpressionCompilesRule,$t as TxExpressionPathRule,Co as TypeResolver,St as UnresolvedPredicateRule,lt as UnresolvedReferenceRule,nt as ValidationCache,et as ValidationContext,Qo as ValidationSeverity,ci as VersionOperator,te as ViewMaterializer,or as allowAllPolicy,so as assertHttpsUrl,fo as assertPackageIdentity,go as buildLocalFirstRepository,Nt as buildOntologyModel,$n as buildReportPackageAsync,Q as buildShapesModel,Ft as canonicalForm,Bt as canonicalHash,he as carrierOf,So as collectKanonakFiles,F as compareVersions,Cn as computeIntegrity,Ie as computeIntegrityAsync,Gt as contentAddressedName,J as contextTypesOf,Qt as createCredentialedFetch,zn as createVersion,Un as evaluateConformance,Uo as extractMarkdownLinks,er as findDerivation,Oo as findMalformedReferences,qo as findMarkdownLinkAt,Re as foldFlagsIntoPattern,vo as formatKanonakAddress,U as formatVersion,oo as getGlobalCachePath,io as getKanonakUserAgent,Xn as isCompatibleVersion,Yn as isMajorCompatible,co as kanonakFetch,Kn as loadLockFile,ne as lowerConstraint,Lo as makeUriKey,tr as noopMeter,qt as normalizeHost,Jt as parseAuthChallenge,Po as parseKanonakAddress,Le as parseLockFile,qn as parseVersionString,zo as parseWithPositions,Qn as pickHighestDocument,No as propertiesInScope,wt as readSequenceConnectors,_t as resolveDisplayValue,jo as resolvePropertyStep,ge as sanitizeName,Jn as satisfiesVersionOperator,xn as saveLockFile,vn as scopeFromCatalog,Ln as scopeFromDocumentAsync,Pn as scopeFromRepositoryAsync,_e as serializeLockFile,uo as setKanonakFetchRetries,ao as setKanonakUserAgent,h as subjectUri,Y as superClassChain,Ot as supportedBandKeys,_o as tripleKey,M as uriKey,Io as uriTriple,Bn as versionOperatorFromChar,Wn as versionOperatorToChar,Gn as versionsEqual,Vt as walkSequence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i}from"../chunk-PRXC2HZ3.js";import"../chunk-QHABFCRC.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{h as EntitlementDeniedError,i as EntitlementProducer,c as ImportBook,a as PackageBuilder,e as ProducerRepository,f as allowAllPolicy,b as contentAddressedName,g as noopMeter,d as sanitizeName};
|
package/dist/search/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{d as g}from"../chunk-
|
|
1
|
+
import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{d as g}from"../chunk-DD3TCFBT.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{ga as m,oa as S}from"../chunk-7UYXTYXC.js";import{c as v,m as p,t as E}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
|
|
2
2
|
Install it with:
|
|
3
3
|
npm install @huggingface/transformers
|
|
4
4
|
(underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Pe}from"../chunk-V3DH67P3.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-IS3AQKB4.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-BZ3YTI3C.js";import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-KIBR3HAT.js";import{r as te}from"../chunk-Z5Y4MCW5.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as oe}from"../chunk-PVUBHIU2.js";import{a as O}from"../chunk-HF5FJBS2.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-7UYXTYXC.js";import{c as we,u as re}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as V,e as E,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ie,mkdirSync as Me}from"fs";import{join as se}from"path";import Fe 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(o){return _e}function C(o){return`${o.publisher}/${o.package_}`}function z(o,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 t of o)if(t.origin==="missing"){let a=C(t),u=c[a]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${a} is MISSING (${t.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${a} (as the user running the render), or restore network access to ${t.publisher}.`)}else t.resolvedButNotInCatalog&&r.push(`Render-stack package ${C(t)} resolved (${t.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let t of e)r.push(`Import edge ${t.fromNamespace} \u2192 ${t.publisher}/${t.packageName} ${t.constraint} did NOT resolve (${t.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${t.fromNamespace} authors against ${t.publisher}/${t.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 ${t.constraint}-compatible version of ${t.publisher}/${t.packageName} to the workspace or cache (kanonak install ${t.publisher}/${t.packageName}), or bump the import in ${t.fromNamespace}.`);return r}function ne(o){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,renderStack:d,producers:k,lockSource:y,configSource:s}=o,l=new Map,f=new Map,p=new Map,m=new Set;for(let S of r){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;l.set(`${w}/${S.name}`,S);let P=w.split("/")[1]??"",[_,F]=P.split("@");if(!_||!F)continue;let D=ke(F);D&&(m.has(P)||(m.add(P),f.has(_)||f.set(_,[]),f.get(_).push({verStr:F,version:D})),S.name===_&&p.set(P,S))}for(let S of f.values())S.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,bySubject:l,pkgVersions:f,pkgSelfByVer:p,renderStack:d,...k?{producers:k}:{},...y?{lockSource:y}:{},...s?{configSource:s}:{}}}async function pe(o,e={}){let c=new O,r=new ye(c),t=[],a=[];for(let i of ee(o)){let h;try{h=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(h).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:E(g),version:g,source:h})}a.sort((i,h)=>V(h.version,i.version));for(let i of a)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),t.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let u=[...new Set(t.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!u.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${u.join(", ")||"(none)"}`)}else if(u.length===1)d=u[0];else throw u.length===0?new Error(`No Kanonak packages found under ${o}`):new Error(`Workspace has multiple publishers (${u.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let k=new Set,y=new Map;for(let i of t)i.publisher===d&&(k.add(`${i.publisher}/${i.package_}@${i.verStr}`),y.set(`${i.package_}@${i.verStr}`,i.source));let s=X(),l=new be(s,!0,c),f={};e.httpCache&&(f.getFromCache=e.httpCache.getFromCache,f.onFetch=e.httpCache.onFetch),e.fetchFn&&(f.fetchFn=e.fetchFn);let p=e.repository??new Se(r,l,new Z(f)),m=e.log??(()=>{}),S=q(void 0),w=[],P=i=>i.map(h=>h.metadata.namespace_?.version).filter(h=>h!==void 0).sort((h,n)=>V(n,h)).map(E);if(!e.repository){m(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let h of S){let n=C(h),g=await r.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(g.length>0){let v=P(g);w.push({...h,origin:"workspace",versions:v}),m(`[render-stack] ${n} \u2014 workspace (${v.join(", ")})`);continue}let b=await l.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(b.length>0){let v=P(b);w.push({...h,origin:"cache",versions:v}),m(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await i.getLock(h.publisher))?.packages[`${h.publisher}/${h.package_}`];if(!$){let j=`publisher ${h.publisher} reachable but its lock does not pin ${h.package_}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let I=$.version,T=$.resolved,Q=await(e.fetchFn?e.fetchFn(T,h.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${h.publisher}/${h.package_}@${I}`);try{let j=se(s,h.publisher);Me(j,{recursive:!0}),Ie(se(j,`${h.package_}@${I}.kan.yml`),fe,"utf-8"),w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, but cache ${s} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;w.push({...h,origin:"missing",reason:$}),m(`[render-stack] ${n} \u2014 MISSING: ${$}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of S)_.push(...await p.getDocumentsByNamespaceAsync(i.publisher,i.package_));let F=[],D=await H(_,p,{onUnresolvedEdge:i=>F.push(i)}),A=p;if(!e.repository){for(let i of S)D.add(C(i));A=new G(p,D)}let B=await new oe(c).parseKanonaks(A),ce=new te(B),le=(i,h)=>re(B,{publisher:i,package_:h,name:h}).length>0,N;if(e.repository){N=[];for(let i of S){let h=await p.getDocumentsByNamespaceAsync(i.publisher,i.package_);N.push(h.length>0?{...i,origin:"repository",versions:P(h)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else N=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(N,F);for(let i of Y)m(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:s,packages:N,warnings:Y},K;try{K=de(se(o,"kanonak.lock"),"utf-8")}catch{K=De(d,t,c)}let L;try{L=de(se(o,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:u,catalog:B,lookRenderer:ce,localNamespaces:k,rawByNsKey:y,renderStack:J,...K?{lockSource:K}:{},...L?{configSource:L}:{}})}function De(o,e,c){let r=new Map;for(let a of e)a.publisher===o&&(r.has(a.package_)||r.set(a.package_,{verStr:a.verStr,source:a.source}));if(r.size===0)return;let t={};for(let a of[...r.keys()].sort()){let{verStr:u,source:d}=r.get(a),k={},y;try{y=c.parse(d).metadata?.imports}catch{y=void 0}for(let l of y?.[o]??[]){let f=r.get(l.packageName);f&&(k[`${o}/${l.packageName}`]=f.verStr)}let s={};for(let l of Object.keys(k).sort())s[l]=k[l];t[`${o}/${a}`]={version:u,resolved:`https://${o}/${a}/${u}.kan.yml`,integrity:Pe(d),dependencies:s}}return Fe.dump({version:"1",lastUpdated:"",packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ee,readFileSync as Ke,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(o,e={}){let c=new O,r=Re(o),t=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),u=e.cacheRoot??X(),d=(n,g,b)=>je(u,n,`${g}@${b}.kan.yml`),k=new Set,y=new Set,s=new Map,l=new Z({getFromCache:(n,g,b)=>{let v=d(n,g,b),$=Ee(v)?Ke(v,"utf-8"):null;return $!==null&&k.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=je(u,n);Ae($,{recursive:!0}),Ve(d(n,g,b),v,"utf-8")}catch($){s.set(`${n}/${g}`,$.message),a(`[render] fetched ${n}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),p;if(r.kind==="resource"){let n=r.uri.version;p=[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;p=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else p=((await f.getConfig(t)).featured_packages??[]).map(g=>({package_:g}));let m=async(n,g,b)=>{try{let v=b?c.buildImport(g,"=",b,n):c.buildImport(g,"*","0.0.0",n),$=await l.getHighestCompatibleVersionAsync(n,v);return $?{doc:$}:{doc:null,error:`${n} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},S=[],w=[];for(let n of p){let{doc:g,error:b}=await m(t,n.package_,n.version);g?S.push(g):b&&w.push(b)}if(S.length===0)throw new Error(`Could not fetch any package for address "${o}" from publisher "${t}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",F=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(E);a(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${u}`);let D=[],A=[];for(let n of P){let g=C(n),{doc:b,error:v}=await m(n.publisher,n.package_,void 0);if(b){D.push(b);let $=F([b]),I=y.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...n,origin:I,versions:$}),a(`[render-stack] ${g} \u2014 ${I} (${$.join(", ")})`+(s.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:v??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let B=[],ce=await H([...S,...D],l,{onUnresolvedEdge:n=>B.push(n)}),le=new G(l,ce),N=await new oe(c).parseKanonaks(le),Y=new te(N),J=A.map(n=>n.origin==="missing"||re(N,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),K=z(J,B);for(let n of K)a(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:u,packages:J,warnings:K},i=new Set,h=new Map;for(let n of await l.getAllDocumentsAsync()){let g=n.metadata.namespace_;if(!g?.version||g.publisher!==t)continue;let b=E(g.version),v=`${g.publisher}/${g.package_}@${b}`;i.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&h.set(`${g.package_}@${b}`,$)}return ne({publisher:t,availablePublishers:[t],catalog:N,lookRenderer:Y,localNamespaces:i,rawByNsKey:h,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(o){let{lookRenderer:e,publisher:c,renderStack:r,catalog:t}=o,a=e.explainStylesheet(e.publisherSubject(c)),u=[...a.tokens.entries()].map(([p,m])=>({name:p,value:m.value,source:`${m.sourceNamespace}/${m.sourceName}`,level:m.level})),d=a.baseStylesheet,k={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},y=new Map;for(let p of t){let m=p.namespace;m&&y.set(m,(y.get(m)??0)+1)}let s=[...y.entries()].map(([p,m])=>({namespace:p,resources:m})).sort((p,m)=>p.namespace.localeCompare(m.namespace)),l=e.expressionFailures().map(p=>({carrier:p.carrier,reason:p.reason})),f=l.map(p=>`Expression carrier "${p.carrier}" did not compile: ${p.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`);return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(p=>({package_:C(p),origin:p.origin,...p.versions!==void 0?{versions:p.versions}:{},...p.reason!==void 0?{reason:p.reason}:{},...p.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:p.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},expressionCarriers:l,catalog:s,warnings:[...r.warnings,...a.warnings.filter(p=>!r.warnings.includes(p)),...f]}}function Be(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ge(o){let e=Be,c=o.warnings.length===0,r=o.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
|
|
1
|
+
import{c as Pe}from"../chunk-V3DH67P3.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-IS3AQKB4.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-BZ3YTI3C.js";import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-KIBR3HAT.js";import{r as te}from"../chunk-DD3TCFBT.js";import"../chunk-QHABFCRC.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as oe}from"../chunk-PVUBHIU2.js";import{a as O}from"../chunk-HF5FJBS2.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-7UYXTYXC.js";import{c as we,u as re}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as V,e as E,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ie,mkdirSync as Me}from"fs";import{join as se}from"path";import Fe 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(o){return _e}function C(o){return`${o.publisher}/${o.package_}`}function z(o,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 t of o)if(t.origin==="missing"){let a=C(t),u=c[a]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${a} is MISSING (${t.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${a} (as the user running the render), or restore network access to ${t.publisher}.`)}else t.resolvedButNotInCatalog&&r.push(`Render-stack package ${C(t)} resolved (${t.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let t of e)r.push(`Import edge ${t.fromNamespace} \u2192 ${t.publisher}/${t.packageName} ${t.constraint} did NOT resolve (${t.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${t.fromNamespace} authors against ${t.publisher}/${t.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 ${t.constraint}-compatible version of ${t.publisher}/${t.packageName} to the workspace or cache (kanonak install ${t.publisher}/${t.packageName}), or bump the import in ${t.fromNamespace}.`);return r}function ne(o){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,renderStack:d,producers:k,lockSource:y,configSource:s}=o,l=new Map,f=new Map,p=new Map,m=new Set;for(let S of r){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;l.set(`${w}/${S.name}`,S);let P=w.split("/")[1]??"",[_,F]=P.split("@");if(!_||!F)continue;let D=ke(F);D&&(m.has(P)||(m.add(P),f.has(_)||f.set(_,[]),f.get(_).push({verStr:F,version:D})),S.name===_&&p.set(P,S))}for(let S of f.values())S.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,bySubject:l,pkgVersions:f,pkgSelfByVer:p,renderStack:d,...k?{producers:k}:{},...y?{lockSource:y}:{},...s?{configSource:s}:{}}}async function pe(o,e={}){let c=new O,r=new ye(c),t=[],a=[];for(let i of ee(o)){let h;try{h=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(h).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:E(g),version:g,source:h})}a.sort((i,h)=>V(h.version,i.version));for(let i of a)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),t.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let u=[...new Set(t.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!u.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${u.join(", ")||"(none)"}`)}else if(u.length===1)d=u[0];else throw u.length===0?new Error(`No Kanonak packages found under ${o}`):new Error(`Workspace has multiple publishers (${u.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let k=new Set,y=new Map;for(let i of t)i.publisher===d&&(k.add(`${i.publisher}/${i.package_}@${i.verStr}`),y.set(`${i.package_}@${i.verStr}`,i.source));let s=X(),l=new be(s,!0,c),f={};e.httpCache&&(f.getFromCache=e.httpCache.getFromCache,f.onFetch=e.httpCache.onFetch),e.fetchFn&&(f.fetchFn=e.fetchFn);let p=e.repository??new Se(r,l,new Z(f)),m=e.log??(()=>{}),S=q(void 0),w=[],P=i=>i.map(h=>h.metadata.namespace_?.version).filter(h=>h!==void 0).sort((h,n)=>V(n,h)).map(E);if(!e.repository){m(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let h of S){let n=C(h),g=await r.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(g.length>0){let v=P(g);w.push({...h,origin:"workspace",versions:v}),m(`[render-stack] ${n} \u2014 workspace (${v.join(", ")})`);continue}let b=await l.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(b.length>0){let v=P(b);w.push({...h,origin:"cache",versions:v}),m(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await i.getLock(h.publisher))?.packages[`${h.publisher}/${h.package_}`];if(!$){let j=`publisher ${h.publisher} reachable but its lock does not pin ${h.package_}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let I=$.version,T=$.resolved,Q=await(e.fetchFn?e.fetchFn(T,h.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${h.publisher}/${h.package_}@${I}`);try{let j=se(s,h.publisher);Me(j,{recursive:!0}),Ie(se(j,`${h.package_}@${I}.kan.yml`),fe,"utf-8"),w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, but cache ${s} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;w.push({...h,origin:"missing",reason:$}),m(`[render-stack] ${n} \u2014 MISSING: ${$}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of S)_.push(...await p.getDocumentsByNamespaceAsync(i.publisher,i.package_));let F=[],D=await H(_,p,{onUnresolvedEdge:i=>F.push(i)}),A=p;if(!e.repository){for(let i of S)D.add(C(i));A=new G(p,D)}let B=await new oe(c).parseKanonaks(A),ce=new te(B),le=(i,h)=>re(B,{publisher:i,package_:h,name:h}).length>0,N;if(e.repository){N=[];for(let i of S){let h=await p.getDocumentsByNamespaceAsync(i.publisher,i.package_);N.push(h.length>0?{...i,origin:"repository",versions:P(h)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else N=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(N,F);for(let i of Y)m(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:s,packages:N,warnings:Y},K;try{K=de(se(o,"kanonak.lock"),"utf-8")}catch{K=De(d,t,c)}let L;try{L=de(se(o,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:u,catalog:B,lookRenderer:ce,localNamespaces:k,rawByNsKey:y,renderStack:J,...K?{lockSource:K}:{},...L?{configSource:L}:{}})}function De(o,e,c){let r=new Map;for(let a of e)a.publisher===o&&(r.has(a.package_)||r.set(a.package_,{verStr:a.verStr,source:a.source}));if(r.size===0)return;let t={};for(let a of[...r.keys()].sort()){let{verStr:u,source:d}=r.get(a),k={},y;try{y=c.parse(d).metadata?.imports}catch{y=void 0}for(let l of y?.[o]??[]){let f=r.get(l.packageName);f&&(k[`${o}/${l.packageName}`]=f.verStr)}let s={};for(let l of Object.keys(k).sort())s[l]=k[l];t[`${o}/${a}`]={version:u,resolved:`https://${o}/${a}/${u}.kan.yml`,integrity:Pe(d),dependencies:s}}return Fe.dump({version:"1",lastUpdated:"",packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ee,readFileSync as Ke,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(o,e={}){let c=new O,r=Re(o),t=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),u=e.cacheRoot??X(),d=(n,g,b)=>je(u,n,`${g}@${b}.kan.yml`),k=new Set,y=new Set,s=new Map,l=new Z({getFromCache:(n,g,b)=>{let v=d(n,g,b),$=Ee(v)?Ke(v,"utf-8"):null;return $!==null&&k.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=je(u,n);Ae($,{recursive:!0}),Ve(d(n,g,b),v,"utf-8")}catch($){s.set(`${n}/${g}`,$.message),a(`[render] fetched ${n}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),p;if(r.kind==="resource"){let n=r.uri.version;p=[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;p=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else p=((await f.getConfig(t)).featured_packages??[]).map(g=>({package_:g}));let m=async(n,g,b)=>{try{let v=b?c.buildImport(g,"=",b,n):c.buildImport(g,"*","0.0.0",n),$=await l.getHighestCompatibleVersionAsync(n,v);return $?{doc:$}:{doc:null,error:`${n} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},S=[],w=[];for(let n of p){let{doc:g,error:b}=await m(t,n.package_,n.version);g?S.push(g):b&&w.push(b)}if(S.length===0)throw new Error(`Could not fetch any package for address "${o}" from publisher "${t}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",F=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(E);a(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${u}`);let D=[],A=[];for(let n of P){let g=C(n),{doc:b,error:v}=await m(n.publisher,n.package_,void 0);if(b){D.push(b);let $=F([b]),I=y.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...n,origin:I,versions:$}),a(`[render-stack] ${g} \u2014 ${I} (${$.join(", ")})`+(s.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:v??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let B=[],ce=await H([...S,...D],l,{onUnresolvedEdge:n=>B.push(n)}),le=new G(l,ce),N=await new oe(c).parseKanonaks(le),Y=new te(N),J=A.map(n=>n.origin==="missing"||re(N,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),K=z(J,B);for(let n of K)a(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:u,packages:J,warnings:K},i=new Set,h=new Map;for(let n of await l.getAllDocumentsAsync()){let g=n.metadata.namespace_;if(!g?.version||g.publisher!==t)continue;let b=E(g.version),v=`${g.publisher}/${g.package_}@${b}`;i.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&h.set(`${g.package_}@${b}`,$)}return ne({publisher:t,availablePublishers:[t],catalog:N,lookRenderer:Y,localNamespaces:i,rawByNsKey:h,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(o){let{lookRenderer:e,publisher:c,renderStack:r,catalog:t}=o,a=e.explainStylesheet(e.publisherSubject(c)),u=[...a.tokens.entries()].map(([p,m])=>({name:p,value:m.value,source:`${m.sourceNamespace}/${m.sourceName}`,level:m.level})),d=a.baseStylesheet,k={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},y=new Map;for(let p of t){let m=p.namespace;m&&y.set(m,(y.get(m)??0)+1)}let s=[...y.entries()].map(([p,m])=>({namespace:p,resources:m})).sort((p,m)=>p.namespace.localeCompare(m.namespace)),l=e.expressionFailures().map(p=>({carrier:p.carrier,reason:p.reason})),f=l.map(p=>`Expression carrier "${p.carrier}" did not compile: ${p.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`);return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(p=>({package_:C(p),origin:p.origin,...p.versions!==void 0?{versions:p.versions}:{},...p.reason!==void 0?{reason:p.reason}:{},...p.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:p.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},expressionCarriers:l,catalog:s,warnings:[...r.warnings,...a.warnings.filter(p=>!r.warnings.includes(p)),...f]}}function Be(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ge(o){let e=Be,c=o.warnings.length===0,r=o.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
|
|
2
2
|
`),t=o.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':o.warnings.map(s=>`<div class="warn">\u26A0 ${e(s)}</div>`).join(`
|
|
3
3
|
`),a=o.renderStack.packages.map(s=>{let l=s.origin!=="missing"&&!s.resolvedButNotInCatalog,f=s.origin==="missing"?'<span class="bad">MISSING</span>':s.resolvedButNotInCatalog?`<span class="bad">${e(s.origin)} (not in catalog)</span>`:`<span class="good">${e(s.origin)}</span>`,p=s.reason?e(s.reason):e((s.versions??[]).join(", "));return`<tr class="${l?"":"row-bad"}"><td><code>${e(s.package_)}</code></td><td>${f}</td><td>${p}</td></tr>`}).join(`
|
|
4
4
|
`),u=o.stylesheet.baseStylesheet,d=u.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(u.source??"")}</code> (${u.bytes} bytes, ${e(u.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${u.problem?` \u2014 ${e(u.problem)}`:""}${u.candidates.length>0?`<br>candidates considered: ${u.candidates.map(s=>`<code>${e(s)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,k=o.stylesheet.tokens.map(s=>`<tr><td><code>--kan-${e(s.name)}</code></td><td><code>${e(s.value)}</code></td><td><code>${e(s.source)}</code></td><td>${e(s.level)}</td></tr>`).join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pe}from"../chunk-L2J7WD7E.js";import"../chunk-BS7RRG7D.js";import{a as ve,b as M,c as Un,l as X,m as Vn,n as Rn,o as le,p as q,r as G}from"../chunk-
|
|
1
|
+
import{a as pe}from"../chunk-L2J7WD7E.js";import"../chunk-BS7RRG7D.js";import{a as ve,b as M,c as Un,l as X,m as Vn,n as Rn,o as le,p as q,r as G}from"../chunk-DD3TCFBT.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-PVUBHIU2.js";import{a as se}from"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{e as U}from"../chunk-7UYXTYXC.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,t as A}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{g as ie}from"../chunk-QILEJIFU.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,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 ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
|
|
2
2
|
`);return t?.trailingNewline&&(s.endsWith(`
|
|
3
3
|
`)||(s+=`
|
|
4
4
|
`)),s}};function Ie(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(P(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(P(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(P),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=P(f??c),d=ye(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function P(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function ye(e,n){switch(e.kind){case"StringScalar":return _e(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=ye(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function _e(e,n){return!n||ge(n,m.ESC_RAW)?e:ge(n,m.ESC_YAML_SAFE)?Ce(e):e}function Ce(e){return e.includes(`
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,F,G,H,I,J,K,L,M,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-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,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-LRVOGQI5.js";import"../chunk-KIBR3HAT.js";import"../chunk-DD3TCFBT.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,o as ClassHierarchyCycleRule,L as DiamondNameClashRule,D as DisplayLensScopeRule,l as EmbeddedKanonakTypeRule,m as ImportExistenceRule,M as KanonakObjectValidator,f as LinkTargetRule,H as LookBandPathRule,E as LookSemanticSvgPathRule,C as MarkdownLinkRule,t as NamespaceImportCycleRule,g as NamespacePrefixRule,x as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,K as OwlOneOfRule,k as PackageHeaderRule,y as PropertyDomainRule,p as PropertyHierarchyCycleRule,z as PropertyKindRangeConsistencyRule,w as PropertyRangeReferenceRule,q as PropertyRangeRequiredRule,i as PropertyTypeSpecificityRule,A as ReservedNameShadowRule,h as ResourceNamingRule,G as SequenceNarrativeRule,J as ShaclShapeRule,r as SubClassOfReferenceRule,s as SubPropertyOfReferenceRule,j as SubjectKanonakTypeRequiredRule,F as TxExpressionCompilesRule,I as TxExpressionPathRule,u as UnresolvedPredicateRule,n as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.32.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",
|
|
@@ -78,6 +78,14 @@
|
|
|
78
78
|
"types": "./dist/transformations/index.d.ts",
|
|
79
79
|
"default": "./dist/transformations/index.js"
|
|
80
80
|
},
|
|
81
|
+
"./producer": {
|
|
82
|
+
"browser": {
|
|
83
|
+
"types": "./dist/producer/index.d.ts",
|
|
84
|
+
"default": "./dist/producer/index.js"
|
|
85
|
+
},
|
|
86
|
+
"types": "./dist/producer/index.d.ts",
|
|
87
|
+
"default": "./dist/producer/index.js"
|
|
88
|
+
},
|
|
81
89
|
"./server": {
|
|
82
90
|
"types": "./dist/server/index.d.ts",
|
|
83
91
|
"default": "./dist/server/index.js"
|
|
@@ -126,7 +134,7 @@
|
|
|
126
134
|
],
|
|
127
135
|
"dependencies": {
|
|
128
136
|
"@kanonak-protocol/canonical": "^0.1.3",
|
|
129
|
-
"@kanonak-protocol/types": "^5.
|
|
137
|
+
"@kanonak-protocol/types": "^5.32.0",
|
|
130
138
|
"ignore": "^7.0.5",
|
|
131
139
|
"js-yaml": "^4.1.0",
|
|
132
140
|
"yaml": "^2.7.0",
|
package/dist/chunk-J4ZD6IF6.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{e as R}from"./chunk-BZ3YTI3C.js";import{a as H,b as B,c as Z,i as x,m as ne}from"./chunk-PVUBHIU2.js";import{ba as ee,fa as T,ia as N}from"./chunk-7UYXTYXC.js";import{b as z,c as _,d as $,f as q,g as W,h as Y,i as J,j as X,k as Q,l as I}from"./chunk-CJMVIOZX.js";var oe=(o=>(o.Class="Class",o.DatatypeProperty="DatatypeProperty",o.ObjectProperty="ObjectProperty",o.AnnotationProperty="AnnotationProperty",o.Instance="Instance",o.Datatype="Datatype",o.Shape="Shape",o.Unknown="Unknown",o))(oe||{}),se=(o=>(o.InstanceOf="instanceOf",o.SubClassOf="subClassOf",o.Domain="domain",o.Range="range",o.ObjectRelationship="objectRelationship",o.SubPropertyOf="subPropertyOf",o.PropertyValue="propertyValue",o.EmbeddedLink="embeddedLink",o))(se||{}),D=class{static async buildFromRepository(n,t){let a=await new ne().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],i=[],o=new Set,d=new Set,y=new Map;for(let g of a){let p=g;if(p.name&&(T.isClassType(p)&&o.add(p.name),g instanceof _)){let l=N(a,g);(l==="ObjectProperty"||l==="Property")&&d.add(p.name)}}for(let g of s)for(let[p,l]of Object.entries(g.body))d.has(p)&&l?.range&&typeof l.range=="string"&&y.set(p,l.range);let f=new Map;for(let g of a){let p=g;p.name&&f.set(p.name,p)}for(let g of s){let p=g.metadata.namespace_,l=p?`${p.publisher}/${p.package_}`:"",m=p?.version?`${p.version.major}.${p.version.minor}.${p.version.patch}`:"",C=te(g);for(let[h,u]of Object.entries(g.body)){if(!u||typeof u!="object")continue;let b=f.get(h),k="Unknown";if(b){let A=b,P=b instanceof _?N(a,b):void 0;T.isClassType(A)?k="Class":P==="ObjectProperty"?k="ObjectProperty":P==="DatatypeProperty"?k="DatatypeProperty":P==="AnnotationProperty"?k="AnnotationProperty":T.isDatatypeType(A)?k="Datatype":P==="Property"?k="ObjectProperty":T.isShapeType(A)?k="Shape":T.isInstanceOfKnownClass(A,o)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,L={};for(let[A,P]of Object.entries(u))A!=="type"&&(typeof P!="object"||P===null)&&(L[A]=P);c.push({id:S,label:u.label??h,type:k,namespace:l,properties:L}),re(S,u,k,o,d,i,l,m,C,t),M(S,u,d,y,c,i,l,m,C),be(S,b,i)}}return{nodes:c,edges:i}}static buildFromDocument(n,t){let r=[],a=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",i=s?`${s.publisher}/${s.package_}`:"",o=new Set,d=new Set,y=new Map,f=te(n);for(let[l,m]of Object.entries(n.body)){let C=m?.type;C&&(he(C,f)&&o.add(l),me(C,f)&&(d.add(l),m.range&&typeof m.range=="string"&&y.set(l,m.range)))}for(let[l,m]of Object.entries(n.body)){if(!m||typeof m!="object")continue;let C=m.type,h=ke(C,l,o,f),u=i&&c?`${i}/${l}@${c}`:l,b={};for(let[k,S]of Object.entries(m))k!=="type"&&(typeof S!="object"||S===null)&&(b[k]=S);r.push({id:u,label:m.label??l,type:h,namespace:i,properties:b}),re(u,m,h,o,d,a,i,c,f,t),M(u,m,d,y,r,a,i,c,f)}let g=new Set(r.map(l=>l.id)),p=a.filter(l=>g.has(l.source)&&g.has(l.target));return{nodes:r,edges:p}}};function te(e,n){let t=new Map;if(e.metadata?.imports)for(let[r,a]of Object.entries(e.metadata.imports))for(let s of a){let c=s.alias??s.packageName,i=s.version,o=`${i.major}.${i.minor}.${i.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:o})}return t}var ae={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},ye=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function K(e,n){if(e.includes(".")){let t=e.indexOf("."),r=e.substring(0,t),a=e.substring(t+1),s=n.get(r);if(s)return`${s.publisher}/${s.package_}/${a}`}return null}function he(e,n){let t=K(e,n);return t?ae[t]==="Class":!1}function me(e,n){let t=K(e,n);return t?ye.has(t):!1}function ke(e,n,t,r){if(!e||e==="Package")return"Unknown";let a=K(e,r);if(a){let c=ae[a];if(c)return c;let i=a.split("/").pop()?.split("@")[0]??"";return t.has(i)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ie=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function re(e,n,t,r,a,s,c,i,o,d){let y=n.type,f=n.subClassOf;if(f){let h=Array.isArray(f)?f:[f];for(let u of h)typeof u=="string"&&s.push({source:e,target:w(u,c,i,o),type:"subClassOf",label:"subClassOf"})}let g=n.subPropertyOf;if(g){let h=Array.isArray(g)?g:[g];for(let u of h)typeof u=="string"&&s.push({source:e,target:w(u,c,i,o),type:"subPropertyOf",label:"subPropertyOf"})}let p=n.domain,l=n.range;if(d?.includePropertyEdges){let h=[[p,"domain","domain"],[l,"range","range"]];for(let[u,b,k]of h)if(u!=null)for(let S of Array.isArray(u)?u:[u])typeof S=="string"&&s.push({source:e,target:w(S,c,i,o),type:b,label:k})}if(t==="Instance"&&y){let h=y.split(".").pop()??y;s.push({source:e,target:w(h,c,i,o),type:"instanceOf",label:"type"})}if(t==="Instance")for(let[h,u]of Object.entries(n)){if(ie.has(h)||!a.has(h))continue;let b=Array.isArray(u)?u:[u];for(let k of b)typeof k=="string"&&Ce(k)&&s.push({source:e,target:w(k,c,i,o),type:"propertyValue",label:h,propertyId:w(h,c,i,o)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||p&&l)&&p&&l){let h=typeof p=="string"?p:null,u=typeof l=="string"?l:null;h&&u&&s.push({source:w(h,c,i,o),target:w(u,c,i,o),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function M(e,n,t,r,a,s,c,i,o){for(let[d,y]of Object.entries(n)){if(ie.has(d)||typeof y!="object"||y===null||Array.isArray(y))continue;let f=y,g=`${e}/${d}`,p=r.get(d),l=p?p.split(".").pop()??p:"Unknown",m={};for(let[h,u]of Object.entries(f))(typeof u!="object"||u===null)&&(m[h]=u);a.push({id:g,label:`${l} (embedded)`,type:"Instance",namespace:c,properties:m});let C=c&&i?`${c}/${d}@${i}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?C:void 0}),p&&s.push({source:g,target:w(l,c,i,o),type:"instanceOf",label:"type (inferred)"}),M(g,f,t,r,a,s,c,i,o)}}function be(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let a of r){if(!(a instanceof Z))continue;let s=a.predicate?.subject?.name??"";for(let c of a.links){let i=c.target?.subject;if(!i)continue;let o=i.version,d=o&&typeof o.major=="number"?`@${o.major}.${o.minor}.${o.patch}`:"";t.push({source:e,target:`${i.publisher}/${i.package_}/${i.name}${d}`,type:"embeddedLink",label:s})}}}function Ce(e){return!(!e||e.includes(" ")||e.includes(`
|
|
2
|
-
`)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function w(e,n,t,r){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let a=e.indexOf("."),s=e.substring(0,a),c=e.substring(a+1);if(r){let i=r.get(s);if(i)return`${i.publisher}/${i.package_}/${c}@${i.version}`}return n&&t?`${n}/${c}@${t}`:c}return n&&t?`${n}/${e}@${t}`:e}import{canonicalForm as Se,canonicalHash as we}from"@kanonak-protocol/canonical";function F(e){return typeof e=="object"&&e!==null&&Array.isArray(e.subjects)}import{CANONICAL_FORM_VERSION as $e}from"@kanonak-protocol/canonical";function Oe(e){return Se(F(e)?e:pe(e))}function ve(e){return we(F(e)?e:pe(e))}function pe(e){let n=[];for(let t of e)t instanceof _&&n.push({uri:Re(t),statements:U(t.statement)});return{subjects:n}}function U(e){let n=[];for(let t of e){let r=Ee(t);if(!r)continue;if(t instanceof I&&Pe(t.predicate.subject)){n.push(...Te(t,r));continue}let a=je(t);a&&n.push({predicate:r,value:a})}return n}function Pe(e){let n=ee("type");return n!==void 0&&e.name==="type"&&e.publisher===n.publisher&&e.package_===n.package_}var ce=new TextEncoder;function Ae(e,n){let t=ce.encode(e),r=ce.encode(n),a=Math.min(t.length,r.length);for(let s=0;s<a;s++)if(t[s]!==r[s])return t[s]-r[s];return t.length-r.length}function Te(e,n){let t=[];for(let r of e.object){if(!(r instanceof $))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(G(r))}t.sort(Ae);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:n,value:{ref:r}}))}function je(e){if(e instanceof q&&e.carrier)return{lit:e.lexical??String(e.object),datatype:ue(e.carrier)};if(e instanceof W)return{raw:e.object};if(e instanceof Y)return{raw:e.lexical??String(e.object)};if(e instanceof J)return{raw:e.lexical??String(e.object)};if(e instanceof X)return{ref:G(e.object)};if(e instanceof Q)return le(e.object);if(e instanceof I)return{list:e.object.map(_e)}}function le(e){let n=U(e.statement);return e.name&&e.name.length>0?{embed:{name:e.name,statements:n}}:{embed:{statements:n}}}function _e(e){if(e instanceof $)return{ref:G(e)};if(e instanceof H)return le(e);if(e instanceof B){if(e.carrier)return{lit:e.lexical??String(e.value),datatype:ue(e.carrier)};let n=e.value;if(typeof n=="string")return{raw:n};if(typeof n=="number")return{raw:String(n)};if(typeof n=="boolean")return{raw:String(n)}}if(e instanceof z)return{embed:{statements:U(e.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${e.constructor?.name??typeof e}); add canonicalization support before hashing data that contains it`)}function ue(e){return e===x.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${e}`}function Ee(e){let n=e.predicate;if(n)return de(n.subject)}function Re(e){let n=e.namespace??"",t=e.name??"";return`${n}/${t}`}function G(e){return de(e.subject)}function de(e){let n=e.version;return n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}/${e.name}`:`${e.publisher}/${e.package_}/${e.name}`}function j(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}var Ie="key_thumbprint",E=class{cache=new Map;prCache=new Map;async discoverProtectedResource(n){let t=j(n);if(this.prCache.has(t))return this.prCache.get(t);let r=`https://${t}/.well-known/oauth-protected-resource`,a=await Ne(r),s=a&&Array.isArray(a.authorization_servers)?a.authorization_servers.filter(i=>typeof i=="string"):[],c=s.length>0?s:null;return this.prCache.set(t,c),c}async discover(n){let t=j(n);if(this.cache.has(t))return this.cache.get(t);let r=`https://${t}/.well-known/oauth-authorization-server`,a=await this.tryEndpoint(r);if(!a){let s=`https://${t}/.well-known/openid-configuration`;a=await this.tryEndpoint(s)}return this.cache.set(t,a),a}async supportsOAuth(n){return await this.discover(n)!==null}static supportsPkceS256(n){return n.codeChallengeMethodsSupported?.some(t=>t.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(n){return!!n.registrationEndpoint}static supportsAuthorizationCode(n){return n.responseTypesSupported?.some(t=>t.toLowerCase()==="code")??!1}static supportsEnrollment(n){return!!n.enrollmentEndpoint}static supportsSession(n){return!!n.sessionEndpoint}async tryEndpoint(n){let t;try{t=await fetch(n)}catch(a){let s=a instanceof Error?a.message:String(a);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${n} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${n} \u2014 TLS error (${s})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${n} \u2014 network error: ${s}`),null}if(!t.ok)return t.status===404||(t.status===403?(console.error(` OAuth discovery: ${n} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):t.status>=500&&(console.error(` OAuth discovery: ${n} \u2014 HTTP ${t.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let r;try{r=await t.json()}catch{return console.error(` OAuth discovery: ${n} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:O(r.issuer),authorizationEndpoint:O(r.authorization_endpoint),tokenEndpoint:O(r.token_endpoint),registrationEndpoint:O(r.registration_endpoint),revocationEndpoint:O(r.revocation_endpoint),scopesSupported:v(r.scopes_supported),responseTypesSupported:v(r.response_types_supported),grantTypesSupported:v(r.grant_types_supported),codeChallengeMethodsSupported:v(r.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:v(r.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:v(r.dpop_signing_alg_values_supported),enrollmentEndpoint:O(r.enrollment_endpoint),enrollmentIssuanceProtocols:v(r.enrollment_issuance_protocols),enrollmentKeyTypes:v(r.enrollment_key_types),enrollmentScopesSupported:v(r.enrollment_scopes_supported),enrollmentConsentBindingParam:O(r.enrollment_consent_binding_param),sessionEndpoint:O(r.session_endpoint),sessionEndpointAuthMethod:O(r.session_endpoint_auth_method)}}};async function Ne(e){try{let n=await fetch(e);return n.ok?await n.json():null}catch{return null}}function O(e){return typeof e=="string"?e:null}function v(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):null}function fe(e){let n=e.headers.get("WWW-Authenticate")??void 0,t=e.headers.get("DPoP-Nonce")??void 0;if(!n&&!t)return;let r={wwwAuthenticate:n??""};if(t&&(r.nonce=t),n){let a=n.match(/acr_values\s*=\s*"([^"]*)"/i);a&&(r.acrValues=a[1])}return r}function xe(e){try{return new URL(e).host}catch{return null}}function De(e,n={}){let t=n.discovery??new E,r=new Map,a=new Map,s=async o=>{let d=r.get(o);if(d!==void 0)return d;let y=null,f=await t.discoverProtectedResource(o).catch(()=>null);return f&&f.length>0&&(y=xe(f[0])),r.set(o,y),y},c=async(o,d)=>{if(!e)return null;if(!(d.forceRefresh||d.challenge)&&a.has(o))return a.get(o);let f=await e.resolve(o,d).catch(()=>null);return a.set(o,f),f},i=async(o,d,y,f)=>{let g=await s(d);if(!g)return{res:await R(o,{method:y,redirect:"manual"}),authed:!1};let p=await c(g,{method:y,url:o,...f}),l=p?.headers??{};return{res:await R(o,{method:y,redirect:"manual",headers:l}),authed:!!p}};return async(o,d,y="GET")=>{let f=await i(o,d,y,{});if((f.res.status===401||f.res.status===403)&&f.authed){let g=fe(f.res),p={forceRefresh:g===void 0};return g&&(p.challenge=g),(await i(o,d,y,p)).res}return f.res}}var ge="KANONAK_TOKEN";function Me(){return typeof process<"u"&&process.env?process.env:{}}function Ke(e){return`${ge}_${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var V=class{tokens;env;constructor(n={}){this.tokens=n.tokens??{},this.env=n.env??Me()}async resolve(n,t){let r=j(n),a=this.tokens[r]??this.env[Ke(r)]??this.env[ge];return a?{headers:{Authorization:`Bearer ${a}`}}:null}};export{oe as a,se as b,D as c,Oe as d,ve as e,$e as f,j as g,Ie as h,E as i,fe as j,De as k,V as l};
|