@kanonak-protocol/sdk 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/canonical/CanonicalHash.d.ts +13 -17
- package/dist/canonical/Datatypes.d.ts +19 -93
- package/dist/canonical/InputModel.d.ts +9 -46
- package/dist/chunk-4UT2CLAT.js +1 -0
- package/dist/{chunk-VKTFLHCW.js → chunk-7HRKWTBB.js} +1 -1
- package/dist/{chunk-PBNVHBS3.js → chunk-7TKJHKC2.js} +1 -1
- package/dist/chunk-BKVPSPG4.js +1 -0
- package/dist/{chunk-RWEGPZ23.js → chunk-CR55WXIN.js} +1 -1
- package/dist/{chunk-UK2OIPAB.js → chunk-IEOSSSB5.js} +1 -1
- package/dist/{chunk-RYOZTXI7.js → chunk-RGOBWOBB.js} +1 -1
- package/dist/{chunk-KGWDV7FW.js → chunk-U7LVFPEO.js} +1 -1
- package/dist/chunk-UBBZWWRB.js +86 -0
- package/dist/{chunk-OOR5SVNQ.js → chunk-V72IVYR4.js} +1 -1
- package/dist/{chunk-NV63IOB7.js → chunk-VWS25JH4.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -26
- package/dist/kanonaks/DefinedKanonak.d.ts +25 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/KanonakVocabulary.d.ts +8 -0
- package/dist/reasoning/index.js +1 -1
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/transformations/index.js +1 -1
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/documentModel.d.ts +48 -0
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +3 -4
- package/dist/validation/rules/repository/UnresolvedPredicateRule.d.ts +25 -0
- package/dist/validation/rules/repository/index.d.ts +1 -1
- package/package.json +3 -2
- package/dist/chunk-DSHPAWJQ.js +0 -1
- package/dist/chunk-IZRPJCQW.js +0 -86
- package/dist/chunk-T3JR2SV6.js +0 -1
- package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +0 -35
package/dist/browser.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { KanonakParser, KanonakObjectParser, PropertyMetadata, KanonakDocumentPo
|
|
|
12
12
|
export type { IKanonakObjectParser, SourcePosition, ImportPackageEntry, ParsedDocumentWithPositions, } from './parsing/index.js';
|
|
13
13
|
export { GraphBuilder, NodeType, EdgeType } from './graph/index.js';
|
|
14
14
|
export type { GraphNode, GraphEdge, GraphData } from './graph/index.js';
|
|
15
|
-
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule,
|
|
15
|
+
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
|
|
16
16
|
export type { IKanonakObjectValidator, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
|
|
17
17
|
export { Kanonak, DefinedKanonak, SubjectKanonak, EmbeddedKanonak, ReferenceKanonak } from './kanonaks/index.js';
|
|
18
18
|
export type { IStatement } from './statements/index.js';
|
package/dist/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as we,b as ke,c as he,d as E,e as _,f as d,g as tr}from"./chunk-
|
|
2
|
-
Credential storage requires IndexedDB support in your browser.`))})}async function
|
|
1
|
+
import{a as we,b as ke,c as he,d as E,e as _,f as d,g as tr}from"./chunk-U7LVFPEO.js";import{a as rr}from"./chunk-VWS25JH4.js";import"./chunk-QHABFCRC.js";import{a as F,b as W,c as G,d as w,f as X,g as Q,h as Y}from"./chunk-JYBKSBB5.js";import{a as q}from"./chunk-4NO7MHS7.js";import{a as Ke,b as be,c as xe}from"./chunk-RGOBWOBB.js";import{a as Se,b as Re}from"./chunk-PEUTCG3B.js";import"./chunk-PEJALHXK.js";import"./chunk-SC5M74NM.js";import{A as Xe,B as Qe,C as Ye,D as Ze,M as er,a as De,b as Be,c as Ce,d as Ee,f as _e,g as je,h as ve,i as Ae,k as Te,l as Ie,m as Oe,n as Ue,o as Ve,p as $e,q as Me,r as Ne,s as ze,t as Je,u as He,v as qe,w as Le,x as Fe,y as We,z as Ge}from"./chunk-UBBZWWRB.js";import"./chunk-SHDHMKMJ.js";import{a as te,c as ye,h as me}from"./chunk-BKVPSPG4.js";import{a as L}from"./chunk-NJ3AZYQD.js";import{a as Pe}from"./chunk-IEOSSSB5.js";import"./chunk-7TKJHKC2.js";import{b as ge,c as fe}from"./chunk-7HRKWTBB.js";import{a as Z,b as ee,c as re,d as oe,e as se,f as ie,g as ae,h as ce,i as le,j as ue,k as de,l as pe}from"./chunk-4UT2CLAT.js";import{a as ne}from"./chunk-FUUTGGJS.js";import{c as U,d as V,e as $,f as M,g as N,h as z,i as J,j as H}from"./chunk-2ACBWC7K.js";var j="kanonak-credentials",u="credentials",nr=1,f=class{async get(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readonly"),i=s.objectStore(u).get(e);i.onsuccess=()=>o(i.result??null),i.onerror=()=>a(new Error(`IndexedDB read failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async store(r,e){let t=d(r),o=await h();return new Promise((a,s)=>{let l=o.transaction(u,"readwrite"),c=l.objectStore(u).put(e,t);c.onsuccess=()=>a(),c.onerror=()=>s(new Error(`IndexedDB write failed for '${t}': ${c.error?.message}`)),l.oncomplete=()=>o.close()})}async remove(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readwrite"),i=s.objectStore(u).delete(e);i.onsuccess=()=>o(),i.onerror=()=>a(new Error(`IndexedDB delete failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async list(){let r=await h();return new Promise((e,t)=>{let o=r.transaction(u,"readonly"),s=o.objectStore(u).getAllKeys();s.onsuccess=()=>e(s.result??[]),s.onerror=()=>t(new Error(`IndexedDB list failed: ${s.error?.message}`)),o.oncomplete=()=>r.close()})}};function h(){return new Promise((n,r)=>{let e=indexedDB.open(j,nr);e.onupgradeneeded=()=>{let t=e.result;t.objectStoreNames.contains(u)||t.createObjectStore(u)},e.onsuccess=()=>n(e.result),e.onerror=()=>r(new Error(`Failed to open IndexedDB '${j}': ${e.error?.message}
|
|
2
|
+
Credential storage requires IndexedDB support in your browser.`))})}async function A(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey);return{signingKey:n.privateKey,publicKeyJwk:r}}async function K(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey),e=await crypto.subtle.exportKey("jwk",n.privateKey);return{keys:{signingKey:n.privateKey,publicKeyJwk:r},dpopKeyPair:{publicKey:r,privateKey:e}}}async function b(n){return{signingKey:await crypto.subtle.importKey("jwk",n.privateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),publicKeyJwk:n.publicKey}}async function x(n,r,e,t,o){let a={alg:"ES256",typ:"dpop+jwt",jwk:{kty:n.publicKeyJwk.kty,crv:n.publicKeyJwk.crv,x:n.publicKeyJwk.x,y:n.publicKeyJwk.y}},s={jti:crypto.randomUUID(),htm:r.toUpperCase(),htu:e,iat:Math.floor(Date.now()/1e3)};return t&&(s.ath=await sr(t)),o&&(s.nonce=o),await or(a,s,n.signingKey)}function S(n){return!n||n.length===0?!1:n.some(r=>r.toUpperCase()==="ES256")}async function or(n,r,e){let t=v(JSON.stringify(n)),o=v(JSON.stringify(r)),a=new TextEncoder().encode(`${t}.${o}`),s=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,a),l=B(s);return`${t}.${o}.${l}`}async function sr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return B(e)}function v(n){let r=new TextEncoder().encode(n);return B(r.buffer)}function B(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ir=300*1e3,R=class{credentialBackend;callbackUrl;constructor(r){this.credentialBackend=new f,this.callbackUrl=r??`${window.location.origin}/browser/callback.html`}async authorize(r){let e=d(r),t=await this.discover(e);if(!t)return{success:!1,error:`No OAuth discovery endpoint found for '${e}'.`};if(!t.authorizationEndpoint||!t.tokenEndpoint)return{success:!1,error:`OAuth metadata incomplete for '${e}'.`};let o=S(t.dpopSigningAlgValuesSupported),a=null,s=null;if(o){let g=await K();a=g.keys,s=g.dpopKeyPair}let l=await this.credentialBackend.get(e),i=l?.clientId??null,c=l?.clientSecret??null;if(!i&&t.registrationEndpoint){let g=await this.registerClient(t.registrationEndpoint);if(!g)return{success:!1,error:`Dynamic client registration failed for '${e}'.`};i=g.clientId,c=g.clientSecret??null}if(!i)return{success:!1,error:`No OAuth client credentials for '${e}'.`};let m=ar(),p=await cr(m),D=lr(),I=ur(t.authorizationEndpoint,i,this.callbackUrl,D,p),y=await this.openAuthPopup(I,D);if(!y)return{success:!1,error:"Authorization timed out or was cancelled."};if(y.error)return{success:!1,error:`Authorization failed: ${y.error}`};if(!y.code)return{success:!1,error:"No authorization code received."};if(y.state!==D)return{success:!1,error:"State mismatch \u2014 possible CSRF attack."};let P=await this.exchangeCode(t.tokenEndpoint,i,c,y.code,this.callbackUrl,m,a);if(!P)return{success:!1,error:"Token exchange failed."};let O={clientId:i,clientSecret:c,accessToken:P.accessToken??null,refreshToken:P.refreshToken??null,expiresAt:P.expiresIn?new Date(Date.now()+P.expiresIn*1e3).toISOString():null,tokenEndpoint:t.tokenEndpoint,dpopKeyPair:s};return await this.credentialBackend.store(e,O),{success:!0,host:e}}async getCredentialWithKeys(r){let e=await this.credentialBackend.get(r);if(!e)return null;let t=null;return e.dpopKeyPair&&(t=await b(e.dpopKeyPair)),{credential:e,dpopKeys:t}}async logout(r){let e=d(r);return await this.credentialBackend.remove(e),{success:!0,host:e}}async listAuthenticated(){return this.credentialBackend.list()}async discover(r){for(let e of[`https://${r}/.well-known/oauth-authorization-server`,`https://${r}/.well-known/openid-configuration`])try{let t=await w(e);if(!t.ok)continue;let o=await t.json();return{issuer:k(o.issuer),authorizationEndpoint:k(o.authorization_endpoint),tokenEndpoint:k(o.token_endpoint),registrationEndpoint:k(o.registration_endpoint),revocationEndpoint:k(o.revocation_endpoint),dpopSigningAlgValuesSupported:T(o.dpop_signing_alg_values_supported),codeChallengeMethodsSupported:T(o.code_challenge_methods_supported)}}catch{continue}return null}async registerClient(r){try{let e=await w(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_name:"Kanonak Browser",redirect_uris:[this.callbackUrl],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none"})});if(!e.ok)return null;let t=await e.json(),o=t.client_id;return o?{clientId:o,clientSecret:t.client_secret}:null}catch{return null}}openAuthPopup(r,e){return new Promise(t=>{let o=window.open(r,"kanonak-auth","width=500,height=700,menubar=no,toolbar=no,location=yes,status=no");if(!o){t(null);return}let a=setTimeout(()=>{i(),t(null)},ir),s=c=>{c.origin===window.location.origin&&(!c.data||c.data.type!=="kanonak-auth-callback"||(i(),t({code:c.data.code??void 0,state:c.data.state??void 0,error:c.data.error??void 0})))},l=setInterval(()=>{o.closed&&(i(),t(null))},500),i=()=>{clearTimeout(a),clearInterval(l),window.removeEventListener("message",s);try{o.close()}catch{}};window.addEventListener("message",s)})}async exchangeCode(r,e,t,o,a,s,l){let i=new URLSearchParams({grant_type:"authorization_code",client_id:e,code:o,redirect_uri:a,code_verifier:s});t&&i.set("client_secret",t);let c={"Content-Type":"application/x-www-form-urlencoded"};l&&(c.DPoP=await x(l,"POST",r));try{let m=await w(r,{method:"POST",headers:c,body:i.toString()});if(!m.ok)return null;let p=await m.json();return{accessToken:p.access_token,refreshToken:p.refresh_token,expiresIn:typeof p.expires_in=="number"?p.expires_in:void 0}}catch{return null}}};function ar(){let n=new Uint8Array(32);return crypto.getRandomValues(n),C(n.buffer)}async function cr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return C(e)}function lr(){let n=new Uint8Array(16);return crypto.getRandomValues(n),C(n.buffer)}function ur(n,r,e,t,o){let a=new URLSearchParams({client_id:r,response_type:"code",redirect_uri:e,state:t,code_challenge:o,code_challenge_method:"S256"});return`${n}?${a}`}function C(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(n){return typeof n=="string"?n:null}function T(n){return Array.isArray(n)?n.filter(r=>typeof r=="string"):null}export{Le as AmbiguousReferenceRule,le as BooleanStatement,f as BrowserCredentialBackend,R as BrowserOAuthFlow,Ye as ClassDefinitionRule,Ue as ClassHierarchyCycleRule,ee as DefinedKanonak,He as DefinitionPropertyReferenceRule,ke as EdgeType,te as EmbeddedKanonak,Te as EmbeddedKanonakTypeRule,de as EmbeddedStatement,he as GraphBuilder,Y as HttpKanonakDocumentRepository,Ie as ImportExistenceRule,q as InMemoryKanonakDocumentRepository,F as KANONAK_USER_AGENT,Z as Kanonak,be as KanonakDocumentPositions,me as KanonakObjectParser,er as KanonakObjectValidator,L as KanonakParser,ne as KanonakUri,Se as KanonakUriBuilder,pe as ListStatement,Ze as MarkdownLinkRule,ye as MarkdownStatement,ze as NamespaceImportCycleRule,_e as NamespacePrefixRule,we as NodeType,ce as NumberStatement,We as ObjectPropertyImportRule,Ge as ObjectPropertyValueValidationRule,Ce as OntologyValidationError,De as OntologyValidationResult,Xe as PropertyDomainRule,Ve as PropertyHierarchyCycleRule,Ke as PropertyMetadata,Fe as PropertyRangeReferenceRule,$e as PropertyRangeRequiredRule,ve as PropertyTypeSpecificityRule,Qe as PropertyValueTypeRule,X as PublisherConfigResolver,Q as PublisherIndex,oe as ReferenceKanonak,ue as ReferenceStatement,je as ResourceNamingRule,ge as ResourceResolver,Pe as ResourceTypeClassifier,ie as ScalarStatement,se as Statement,ae as StringStatement,Me as SubClassOfReferenceRule,Ne as SubPropertyOfReferenceRule,re as SubjectKanonak,Ae as SubjectKanonakTypeRequiredRule,fe as TypeResolver,Je as UnresolvedPredicateRule,Oe as UnresolvedReferenceRule,Ee as ValidationContext,Be as ValidationSeverity,qe as XsdImportRule,S as browserServerSupportsDPoP,tr as buildOntologyModel,U as compareVersions,x as createBrowserDPoPProof,M as createVersion,rr as findDerivation,Re as findInstancesByType,$ as formatVersion,K as generateBrowserDPoPKeyPair,A as generateBrowserDPoPKeys,G as getKanonakUserAgent,_ as hasValidToken,b as importDPoPKeys,z as isCompatibleVersion,E as isExpired,J as isMajorCompatible,w as kanonakFetch,d as normalizeHost,N as parseVersionString,xe as parseWithPositions,H as pickHighestDocument,W as setKanonakUserAgent,V as versionsEqual};
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { type Kanonak } from '../kanonaks/index.js';
|
|
2
2
|
import { type CanonicalInput } from './InputModel.js';
|
|
3
3
|
/**
|
|
4
|
-
* The frozen canonical-form version
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* and lets a consumer record which form produced an address.
|
|
4
|
+
* The frozen canonical-form version, re-exported from the library so the SDK
|
|
5
|
+
* surface is unchanged. It is NOT part of the hashed bytes; it stamps the
|
|
6
|
+
* golden-vector fixtures and lets a consumer record which form produced an
|
|
7
|
+
* address.
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
9
|
+
export { CANONICAL_FORM_VERSION } from '@kanonak-protocol/canonical';
|
|
11
10
|
/**
|
|
12
11
|
* Render a parsed kanonak collection into its canonical JSON form.
|
|
13
12
|
*
|
|
14
|
-
* `kanonaks` should be the `SubjectKanonak` instances from a single
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Returns the JSON string (no trailing newline). Identical inputs
|
|
21
|
-
* always produce byte-identical output.
|
|
13
|
+
* `kanonaks` should be the `SubjectKanonak` instances from a single package —
|
|
14
|
+
* typically the result of `KanonakObjectParser.parseKanonaks` over a
|
|
15
|
+
* `SingleDocumentRepository`. Embedded, reference, and literal kanonaks are
|
|
16
|
+
* walked through subjects' statement trees; they don't count as top-level
|
|
17
|
+
* subjects. Identical inputs always produce byte-identical output.
|
|
22
18
|
*/
|
|
23
19
|
export declare function canonicalForm(kanonaks: Kanonak[]): string;
|
|
24
20
|
/**
|
|
@@ -28,9 +24,9 @@ export declare function canonicalForm(kanonaks: Kanonak[]): string;
|
|
|
28
24
|
*/
|
|
29
25
|
export declare function canonicalForm(input: CanonicalInput): string;
|
|
30
26
|
/**
|
|
31
|
-
* SHA-256 of the canonical form, prefixed `sha256:`. The output is
|
|
32
|
-
*
|
|
33
|
-
*
|
|
27
|
+
* SHA-256 of the canonical form, prefixed `sha256:`. The output is 71 characters
|
|
28
|
+
* (`sha256:` + 64 hex digits) and matches the convention used by `kanonak.lock`
|
|
29
|
+
* integrity entries.
|
|
34
30
|
*/
|
|
35
31
|
export declare function canonicalHash(kanonaks: Kanonak[]): string;
|
|
36
32
|
/** SHA-256 of the canonical form of a {@link CanonicalInput} model (issue #56). */
|
|
@@ -1,98 +1,24 @@
|
|
|
1
|
-
import type { EntityUri } from '../uri-helpers/index.js';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* SDK adapter over `@kanonak-protocol/canonical`'s datatype layer.
|
|
3
|
+
*
|
|
4
|
+
* The frozen carrier routing and the per-carrier canonical lexical forms — the
|
|
5
|
+
* normative heart of `canonicalFormVersion "1"` — now live in exactly one place,
|
|
6
|
+
* the published `@kanonak-protocol/canonical` library, verified byte-for-byte
|
|
7
|
+
* against the shared golden vectors. This module no longer carries a copy; it
|
|
8
|
+
* only re-exposes `Carrier` on the SDK surface and adds the SDK-shaped
|
|
9
|
+
* `carrierOf` that classifies a datatype given as an {@link EntityUri} object
|
|
10
|
+
* (the form the parser and resolver carry) by delegating to the library's
|
|
11
|
+
* string-keyed `carrierOf`.
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Double = "double",
|
|
11
|
-
Float = "float",
|
|
12
|
-
Boolean = "boolean",
|
|
13
|
-
String = "string",
|
|
14
|
-
AnyUri = "anyURI",
|
|
15
|
-
LangString = "langString",
|
|
16
|
-
DateTime = "dateTime",
|
|
17
|
-
Date = "date",
|
|
18
|
-
Time = "time",
|
|
19
|
-
HexBinary = "hexBinary",
|
|
20
|
-
Base64Binary = "base64Binary"
|
|
21
|
-
}
|
|
13
|
+
import type { EntityUri } from '../uri-helpers/index.js';
|
|
14
|
+
import { Carrier } from '@kanonak-protocol/canonical';
|
|
15
|
+
export { Carrier };
|
|
22
16
|
/**
|
|
23
|
-
* The carrier for a datatype, or `undefined`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* carrier.
|
|
17
|
+
* The carrier for a datatype identified by an {@link EntityUri}, or `undefined`
|
|
18
|
+
* if it is outside the canonicalized set. Builds the `publisher/package/name`
|
|
19
|
+
* key the library classifies on — a datatype's version never affects its
|
|
20
|
+
* carrier identity, so it is omitted. The routing itself (the whole integer
|
|
21
|
+
* tree → {@link Carrier.Integer}, `normalizedString`/`token` → {@link
|
|
22
|
+
* Carrier.String}, etc.) is the library's frozen contract.
|
|
27
23
|
*/
|
|
28
24
|
export declare function carrierOf(datatype: EntityUri): Carrier | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Canonical `xsd:integer` (and every derived integer): optional `-`, digits
|
|
31
|
-
* with no leading zeros, `0` for zero, never `-0`, never a leading `+`.
|
|
32
|
-
* Backed by `BigInt` so values beyond 2^53 (e.g. epoch-nanoseconds) are exact.
|
|
33
|
-
*/
|
|
34
|
-
export declare function canonicalInteger(raw: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Canonical `xsd:decimal`: value-based minimal form. Optional `-`, integer part
|
|
37
|
-
* with no leading zeros (`0` if zero), then `.`+fraction only when the fraction
|
|
38
|
-
* is non-zero, with no trailing zeros. `1.10 → 1.1`, `1.00 → 1`, `0.10 → 0.1`,
|
|
39
|
-
* `-0 → 0`, `-0.00 → 0`. Pure string arithmetic — never parsed to a double.
|
|
40
|
-
*/
|
|
41
|
-
export declare function canonicalDecimal(raw: string): string;
|
|
42
|
-
/** Canonical `xsd:double` — shortest round-tripping decimal; INF / -INF / NaN. */
|
|
43
|
-
export declare function canonicalDouble(raw: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Canonical `xsd:float` — like {@link canonicalDouble} but the value is first
|
|
46
|
-
* rounded to IEEE single precision (`Math.fround`). NOTE: exact cross-language
|
|
47
|
-
* agreement on shortest-float32 strings is a known sharp edge to lock against
|
|
48
|
-
* the golden vectors; representative values agree.
|
|
49
|
-
*/
|
|
50
|
-
export declare function canonicalFloat(raw: string): string;
|
|
51
|
-
/** Canonical `xsd:boolean`: `true` / `false`. Accepts the `1`/`0` lexicals. */
|
|
52
|
-
export declare function canonicalBoolean(raw: string): string;
|
|
53
|
-
/** Canonical string value: Unicode NFC. No whitespace collapse (that's a facet). */
|
|
54
|
-
export declare function canonicalString(raw: string): string;
|
|
55
|
-
/** Canonical `xsd:anyURI`: NFC (distinct carrier/tag from string, same lexical rule). */
|
|
56
|
-
export declare function canonicalAnyUri(raw: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Canonical `rdf:langString`: NFC value + BCP 47 canonical-CASE language tag
|
|
59
|
-
* (language lowercase, script titlecase, region uppercase) — `"hi"@EN-us`
|
|
60
|
-
* becomes `("hi", "en-US")`. Case only; no IANA registry / preferred-value
|
|
61
|
-
* substitution. Returns the pair; the canonical form serializes both.
|
|
62
|
-
*/
|
|
63
|
-
export declare function canonicalLangString(value: string, lang: string): {
|
|
64
|
-
value: string;
|
|
65
|
-
lang: string;
|
|
66
|
-
};
|
|
67
|
-
/** BCP 47 canonical case by subtag position. */
|
|
68
|
-
export declare function canonicalLanguageTag(tag: string): string;
|
|
69
|
-
/** Canonical `xsd:hexBinary`: uppercase hex digits, even length. */
|
|
70
|
-
export declare function canonicalHexBinary(raw: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* Canonical `xsd:base64Binary`: RFC 4648 standard alphabet, canonical padding,
|
|
73
|
-
* no line breaks. Decodes (tolerating XSD-permitted internal whitespace) then
|
|
74
|
-
* re-encodes, so any padding/line-wrap variant of the same bytes collapses.
|
|
75
|
-
*/
|
|
76
|
-
export declare function canonicalBase64(raw: string): string;
|
|
77
|
-
/**
|
|
78
|
-
* Canonical `xsd:dateTime`. Offset-bearing → shifted to UTC `Z` (instant
|
|
79
|
-
* equality, so `13:00:00+01:00` and `12:00:00Z` collide). Timezone-less →
|
|
80
|
-
* floating: canonical lexical form, no `Z`, distinct from any zoned instant.
|
|
81
|
-
* Fractional seconds are preserved at arbitrary precision (only trailing zeros
|
|
82
|
-
* trimmed) and never participate in the offset shift.
|
|
83
|
-
*/
|
|
84
|
-
export declare function canonicalDateTime(raw: string): string;
|
|
85
|
-
/**
|
|
86
|
-
* Canonical `xsd:date`: lexical only — canonical year width + canonical
|
|
87
|
-
* timezone spelling, NO UTC shift (a date is not an instant; shifting could
|
|
88
|
-
* cross midnight). Timezone-less stays distinct from a zoned date.
|
|
89
|
-
*/
|
|
90
|
-
export declare function canonicalDate(raw: string): string;
|
|
91
|
-
/**
|
|
92
|
-
* Canonical `xsd:time`: lexical only — arbitrary-precision fractional seconds,
|
|
93
|
-
* canonical timezone spelling, NO UTC shift. `24:00:00` normalizes to
|
|
94
|
-
* `00:00:00` (XSD value-space equivalence within a day).
|
|
95
|
-
*/
|
|
96
|
-
export declare function canonicalTime(raw: string): string;
|
|
97
|
-
/** Canonical lexical form of a raw token under a carrier. Throws on malformed input. */
|
|
98
|
-
export declare function canonicalScalarLexical(carrier: Carrier, raw: string): string;
|
|
@@ -1,54 +1,17 @@
|
|
|
1
|
-
import type { Kanonak } from '../kanonaks/Kanonak.js';
|
|
2
1
|
/**
|
|
3
2
|
* The language-neutral canonical INPUT model (issue #56) — the one
|
|
4
3
|
* cross-language contract a codec builds to content-address a typed object,
|
|
5
4
|
* carrying datatypes explicitly so canonicalization needs no parser. It is
|
|
6
5
|
* exactly the shape `full-form-vectors.json` is defined over and `kanonak hash
|
|
7
|
-
* -v` emits.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* -v` emits.
|
|
7
|
+
*
|
|
8
|
+
* The types are re-exported from `@kanonak-protocol/canonical`, the single home
|
|
9
|
+
* of the frozen canonical form, so the SDK surface is unchanged for existing
|
|
10
|
+
* consumers while the definition lives in exactly one place. The SDK keeps the
|
|
11
|
+
* {@link isCanonicalInput} discriminator the public `canonicalForm` /
|
|
12
|
+
* `canonicalHash` overloads use to tell a `CanonicalInput` from a `Kanonak[]`.
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export interface CanonicalInputSubject {
|
|
15
|
-
/** The subject's canonical URI, e.g. `publisher/package@1.0.0/Name`. */
|
|
16
|
-
uri: string;
|
|
17
|
-
statements: CanonicalInputStatement[];
|
|
18
|
-
}
|
|
19
|
-
export interface CanonicalInputStatement {
|
|
20
|
-
/** The predicate's canonical URI. */
|
|
21
|
-
predicate: string;
|
|
22
|
-
value: CanonicalInputValue;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A value: a typed scalar (`lit` + its `datatype` URI), an untyped/open-world
|
|
26
|
-
* scalar (`raw` token, no carrier), a reference, an embedded node, or a list.
|
|
27
|
-
*/
|
|
28
|
-
export type CanonicalInputValue = {
|
|
29
|
-
lit: string;
|
|
30
|
-
datatype: string;
|
|
31
|
-
} | {
|
|
32
|
-
raw: string;
|
|
33
|
-
} | {
|
|
34
|
-
ref: string;
|
|
35
|
-
} | {
|
|
36
|
-
embed: {
|
|
37
|
-
name?: string;
|
|
38
|
-
statements: CanonicalInputStatement[];
|
|
39
|
-
};
|
|
40
|
-
} | {
|
|
41
|
-
list: CanonicalInputValue[];
|
|
42
|
-
};
|
|
14
|
+
import type { CanonicalInput } from '@kanonak-protocol/canonical';
|
|
15
|
+
export type { CanonicalInput, CanonicalInputSubject, CanonicalInputStatement, CanonicalInputValue, } from '@kanonak-protocol/canonical';
|
|
43
16
|
/** Discriminate a `CanonicalInput` from a `Kanonak[]` (for the public overload). */
|
|
44
17
|
export declare function isCanonicalInput(arg: unknown): arg is CanonicalInput;
|
|
45
|
-
/**
|
|
46
|
-
* Build the SDK object model the canonical form consumes from a `CanonicalInput`.
|
|
47
|
-
* Datatypes are classified by their URI via {@link carrierOf} (the same routing
|
|
48
|
-
* the parser uses); predicate/reference URIs resolve through the canonical URI
|
|
49
|
-
* parser; a typed scalar carries `(carrier, lexical)`, an untyped one its raw
|
|
50
|
-
* token. The canonical form reads `(carrier, lexical)` off any scalar statement,
|
|
51
|
-
* so a single `StringStatement` faithfully represents every scalar carrier —
|
|
52
|
-
* producing bytes identical to the parsed-model path for equivalent content.
|
|
53
|
-
*/
|
|
54
|
-
export declare function buildModelFromInput(input: CanonicalInput): Kanonak[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as p}from"./chunk-FUUTGGJS.js";var m=class{};var c=class extends m{statement=[];unresolvedPredicates=[]};var i=class extends c{namespace;name;icon};var a=class e extends m{subject;static parse(o){let n=new e;return n.subject=p.parse(o),n}};var r=class{predicate;object};var s=class extends r{carrier;lexical};var d=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var f=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var k=class extends s{};var l=class e extends r{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=a.parse(n),t}};var x=class extends r{};var b=class extends r{};export{m as a,c as b,i as c,a as d,r as e,s as f,d as g,f as h,k as i,l as j,x as k,b as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as w}from"./chunk-FUUTGGJS.js";function K(n){if(Array.isArray(n))return n.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=n?.toString();return e?[e]:[]}var S=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let a=t.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(a);if(s){let o=s.get(e);if(o)return o}let r=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(a,r),r.get(e)??null}async resolveAllEntitiesAsync(e,t){let a=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let s=e.split("."),r=s[0],o=s[1],g=await this.findDocumentForAlias(t,r);return g?await this.resolveAllEntitiesAsync(o,g):[]}return a.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,t,a){let s=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),s;t.add(r);let o=a.length===0?r:`${a} \u2192 ${r}`;for(let[g,u]of Object.entries(e.body))if(!g.includes(".")&&u&&typeof u=="object"&&!Array.isArray(u)){if(!e.metadata.namespace_)continue;let f=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.push({entityName:g,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,f),entity:u,definedInNamespace:r,isImported:a.length>0,importPath:o})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${r}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((u,f)=>u+f.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${r}`);for(let[u,f]of Object.entries(e.metadata.imports))for(let d of f)try{this.logger?.debug?.(`Resolving import: ${u}/${d.packageName}`);let p=await this.repository.getHighestCompatibleVersionAsync(u,d);if(p){this.logger?.debug?.(`Successfully loaded import: ${p.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(p,t,o);s.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${p.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${u}/${d.packageName}`)}catch(p){let m=p;throw this.logger?.error?.(`Failed to process import ${u}/${d.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${u}/${d.packageName} for namespace ${r}. See inner exception for details.`,{cause:p})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,a,s){let r=new Map,o=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${o}`),t.has(o))return this.logger?.debug?.(`Skipping ${o} - circular import in progress`),r;let g=s.get(o);if(g)return g;t.add(o);let u=a.length===0?o:`${a} \u2192 ${o}`,f=0;for(let[d,p]of Object.entries(e.body))if(!d.includes(".")&&p&&typeof p=="object"&&!Array.isArray(p)){if(!e.metadata.namespace_)continue;if(!r.has(d)){let m=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};r.set(d,{entityName:d,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,d,m),entity:p,definedInNamespace:o,isImported:a.length>0,importPath:u}),f++}}if(this.logger?.debug?.(`Indexed ${f} entities from ${o}`),e.metadata?.imports){let d=Object.values(e.metadata.imports).reduce((p,m)=>p+m.length,0);this.logger?.debug?.(`Processing ${d} import(s) for ${o}`);for(let[p,m]of Object.entries(e.metadata.imports))for(let h of m)try{this.logger?.debug?.(`Resolving import: ${p}/${h.packageName}`);let k=await this.repository.getHighestCompatibleVersionAsync(p,h);if(k){this.logger?.debug?.(`Successfully loaded import: ${k.metadata?.namespace_?.toString()}`);let P=await this.buildEntityIndexAsyncInternal(k,t,u,s),v=0;for(let[$,R]of P.entries()){let b=r.get($);if(!b)r.set($,R),v++;else if(b.isImported&&R.isImported&&(b.uri.publisher!==R.uri.publisher||b.uri.package_!==R.uri.package_)){let A=b.isAmbiguous?b:{...b,isAmbiguous:!0,ambiguousNamespaces:[b.definedInNamespace]};A.ambiguousNamespaces.includes(R.definedInNamespace)||A.ambiguousNamespaces.push(R.definedInNamespace),r.set($,A),this.logger?.warn?.(`Ambiguous reference '${$}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(h.alias&&!$.includes(".")){let A=`${h.alias}.${$}`;r.has(A)||(r.set(A,R),v++)}}this.logger?.debug?.(`Merged ${v} entities from import ${k.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${h.packageName}`)}catch(k){let P=k;throw this.logger?.error?.(`Failed to process import ${p}/${h.packageName} for namespace ${o}. Error: ${P.message}`,P),new Error(`Failed to process import ${p}/${h.packageName} for namespace ${o}. See inner exception for details.`,{cause:k})}}return t.delete(o),s.set(o,r),r}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[a,s]of Object.entries(e.metadata.imports))for(let r of s){if(r.alias===t)return await this.repository.getHighestCompatibleVersionAsync(a,r);if(!r.alias&&r.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(a,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubclassOfRecursiveAsync(e,t,a,s)}async isSubclassOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let o=r.entity.subClassOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubclassOfRecursiveAsync(u,t,a,s))return!0}return!1}async isSubpropertyOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,a,s)}async isSubpropertyOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let o=r.entity.subPropertyOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubpropertyOfRecursiveAsync(u,t,a,s))return!0}return!1}};var D=class n{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&n.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return n.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let a=await this.resourceResolver.resolveEntityAsync(e,t);if(a){let s=a.entity.type;if(s){let r=String(s);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function L(n){return`${n.publisher}/${n.package_}/${n.name}`}function c(n,e,t){return`${n}/${e}/${t}`}function M(n){return`${n.s}|${n.p}|${x(n.o)}`}function x(n){switch(n.kind){case"uri":return`u:${n.key}`;case"literal":return`l:${n.datatype}:${n.lexical}`;case"blank":return`b:${n.id}`}}function F(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var l="kanonak.org",i="core-rdf",y="core-owl",_="core-kanonak",I=new Map([["type",i],["subClassOf",i],["subPropertyOf",i],["domain",i],["range",i],["label",i],["comment",i],["seeAlso",i],["isDefinedBy",i],["member",i],["Resource",i],["Class",i],["Property",i],["Datatype",i],["Literal",i],["List",i],["ObjectProperty",y],["DatatypeProperty",y],["AnnotationProperty",y],["Thing",y],["Nothing",y],["Package",_]]),E=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function X(n,e,t){if(!n||!n.name)return;let a=I.get(n.name);if(!a)return;let s=()=>{n.publisher=l,n.package_=a,t&&(n.version=t.get(a))};if(E.has(n.name)){let r=n.publisher===l&&n.package_===a;n.publisher=l,n.package_=a,!r&&t&&(n.version=t.get(a));return}n.publisher===l&&n.package_===a||n.publisher&&n.publisher.length>0&&(!e||e(n))||s()}var O=class{type=c(l,i,"type");subClassOf=c(l,i,"subClassOf");subPropertyOf=c(l,i,"subPropertyOf");domain=c(l,i,"domain");range=c(l,i,"range");label=c(l,i,"label");comment=c(l,i,"comment");resource=c(l,i,"Resource");class_=c(l,i,"Class");datatype=c(l,i,"Datatype");literal=c(l,i,"Literal");equivalentClass=c(l,y,"equivalentClass");equivalentProperty=c(l,y,"equivalentProperty");inverseOf=c(l,y,"inverseOf");sameAs=c(l,y,"sameAs");transitiveProperty=c(l,y,"TransitiveProperty");symmetricProperty=c(l,y,"SymmetricProperty");objectProperty=c(l,y,"ObjectProperty");datatypeProperty=c(l,y,"DatatypeProperty");annotationProperty=c(l,y,"AnnotationProperty");package_=c(l,_,"Package")};export{K as a,S as b,D as c,L as d,c as e,M as f,x as g,F as h,X as i,O as j};
|
|
1
|
+
import{a as w}from"./chunk-FUUTGGJS.js";function K(r){if(Array.isArray(r))return r.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=r?.toString();return e?[e]:[]}var S=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let a=t.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(a);if(s){let o=s.get(e);if(o)return o}let n=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(a,n),n.get(e)??null}async resolveAllEntitiesAsync(e,t){let a=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let s=e.split("."),n=s[0],o=s[1],g=await this.findDocumentForAlias(t,n);return g?await this.resolveAllEntitiesAsync(o,g):[]}return a.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,t,a){let s=[],n=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${n}`),t.has(n))return this.logger?.debug?.(`Skipping ${n} - already visited (circular import prevention)`),s;t.add(n);let o=a.length===0?n:`${a} \u2192 ${n}`;for(let[g,u]of Object.entries(e.body))if(!g.includes(".")&&u&&typeof u=="object"&&!Array.isArray(u)){if(!e.metadata.namespace_)continue;let f=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.push({entityName:g,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,f),entity:u,definedInNamespace:n,isImported:a.length>0,importPath:o})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${n}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((u,f)=>u+f.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${n}`);for(let[u,f]of Object.entries(e.metadata.imports))for(let d of f)try{this.logger?.debug?.(`Resolving import: ${u}/${d.packageName}`);let p=await this.repository.getHighestCompatibleVersionAsync(u,d);if(p){this.logger?.debug?.(`Successfully loaded import: ${p.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(p,t,o);s.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${p.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${u}/${d.packageName}`)}catch(p){let m=p;throw this.logger?.error?.(`Failed to process import ${u}/${d.packageName} for namespace ${n}. Error: ${m.message}`,m),new Error(`Failed to process import ${u}/${d.packageName} for namespace ${n}. See inner exception for details.`,{cause:p})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,a,s){let n=new Map,o=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${o}`),t.has(o))return this.logger?.debug?.(`Skipping ${o} - circular import in progress`),n;let g=s.get(o);if(g)return g;t.add(o);let u=a.length===0?o:`${a} \u2192 ${o}`,f=0;for(let[d,p]of Object.entries(e.body))if(!d.includes(".")&&p&&typeof p=="object"&&!Array.isArray(p)){if(!e.metadata.namespace_)continue;if(!n.has(d)){let m=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.set(d,{entityName:d,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,d,m),entity:p,definedInNamespace:o,isImported:a.length>0,importPath:u}),f++}}if(this.logger?.debug?.(`Indexed ${f} entities from ${o}`),e.metadata?.imports){let d=Object.values(e.metadata.imports).reduce((p,m)=>p+m.length,0);this.logger?.debug?.(`Processing ${d} import(s) for ${o}`);for(let[p,m]of Object.entries(e.metadata.imports))for(let h of m)try{this.logger?.debug?.(`Resolving import: ${p}/${h.packageName}`);let k=await this.repository.getHighestCompatibleVersionAsync(p,h);if(k){this.logger?.debug?.(`Successfully loaded import: ${k.metadata?.namespace_?.toString()}`);let P=await this.buildEntityIndexAsyncInternal(k,t,u,s),v=0;for(let[$,R]of P.entries()){let b=n.get($);if(!b)n.set($,R),v++;else if(b.isImported&&R.isImported&&(b.uri.publisher!==R.uri.publisher||b.uri.package_!==R.uri.package_)){let A=b.isAmbiguous?b:{...b,isAmbiguous:!0,ambiguousNamespaces:[b.definedInNamespace]};A.ambiguousNamespaces.includes(R.definedInNamespace)||A.ambiguousNamespaces.push(R.definedInNamespace),n.set($,A),this.logger?.warn?.(`Ambiguous reference '${$}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(h.alias&&!$.includes(".")){let A=`${h.alias}.${$}`;n.has(A)||(n.set(A,R),v++)}}this.logger?.debug?.(`Merged ${v} entities from import ${k.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${h.packageName}`)}catch(k){let P=k;throw this.logger?.error?.(`Failed to process import ${p}/${h.packageName} for namespace ${o}. Error: ${P.message}`,P),new Error(`Failed to process import ${p}/${h.packageName} for namespace ${o}. See inner exception for details.`,{cause:k})}}return t.delete(o),s.set(o,n),n}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[a,s]of Object.entries(e.metadata.imports))for(let n of s){if(n.alias===t)return await this.repository.getHighestCompatibleVersionAsync(a,n);if(!n.alias&&n.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(a,n)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubclassOfRecursiveAsync(e,t,a,s)}async isSubclassOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let n=await this.resolveEntityAsync(e,a);if(!n?.entity)return!1;let o=n.entity.subClassOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubclassOfRecursiveAsync(u,t,a,s))return!0}return!1}async isSubpropertyOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,a,s)}async isSubpropertyOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let n=await this.resolveEntityAsync(e,a);if(!n?.entity)return!1;let o=n.entity.subPropertyOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubpropertyOfRecursiveAsync(u,t,a,s))return!0}return!1}};var D=class r{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&r.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return r.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let a=await this.resourceResolver.resolveEntityAsync(e,t);if(a){let s=a.entity.type;if(s){let n=String(s);return n==="Class"||n==="rdfs.Class"||n.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function L(r){return`${r.publisher}/${r.package_}/${r.name}`}function c(r,e,t){return`${r}/${e}/${t}`}function M(r){return`${r.s}|${r.p}|${I(r.o)}`}function I(r){switch(r.kind){case"uri":return`u:${r.key}`;case"literal":return`l:${r.datatype}:${r.lexical}`;case"blank":return`b:${r.id}`}}function F(r,e,t){return{s:r,p:e,o:{kind:"uri",key:t}}}var l="kanonak.org",i="core-rdf",y="core-owl",_="core-kanonak",x=new Map([["type",i],["subClassOf",i],["subPropertyOf",i],["domain",i],["range",i],["label",i],["comment",i],["seeAlso",i],["isDefinedBy",i],["member",i],["Resource",i],["Class",i],["Property",i],["Datatype",i],["Literal",i],["List",i],["ObjectProperty",y],["DatatypeProperty",y],["AnnotationProperty",y],["Thing",y],["Nothing",y],["Package",_]]),E=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function X(r){return x.has(r)}function B(r,e,t){if(!r||!r.name)return;let a=x.get(r.name);if(!a)return;let s=()=>{r.publisher=l,r.package_=a,t&&(r.version=t.get(a))};if(E.has(r.name)){let n=r.publisher===l&&r.package_===a;r.publisher=l,r.package_=a,!n&&t&&(r.version=t.get(a));return}r.publisher===l&&r.package_===a||r.publisher&&r.publisher.length>0&&(!e||e(r))||s()}var O=class{type=c(l,i,"type");subClassOf=c(l,i,"subClassOf");subPropertyOf=c(l,i,"subPropertyOf");domain=c(l,i,"domain");range=c(l,i,"range");label=c(l,i,"label");comment=c(l,i,"comment");resource=c(l,i,"Resource");class_=c(l,i,"Class");datatype=c(l,i,"Datatype");literal=c(l,i,"Literal");equivalentClass=c(l,y,"equivalentClass");equivalentProperty=c(l,y,"equivalentProperty");inverseOf=c(l,y,"inverseOf");sameAs=c(l,y,"sameAs");transitiveProperty=c(l,y,"TransitiveProperty");symmetricProperty=c(l,y,"SymmetricProperty");objectProperty=c(l,y,"ObjectProperty");datatypeProperty=c(l,y,"DatatypeProperty");annotationProperty=c(l,y,"AnnotationProperty");package_=c(l,_,"Package")};export{K as a,S as b,D as c,L as d,c as e,M as f,I as g,F as h,X as i,B as j,O as k};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as y,c as s,g as l,h as g,i as b,j as u,k,l as K}from"./chunk-
|
|
1
|
+
import{b as y,c as s,g as l,h as g,i as b,j as u,k,l as K}from"./chunk-4UT2CLAT.js";import{c as d,g as m}from"./chunk-2ACBWC7K.js";function S(t){return`${t.publisher}/${t.package_}/${t.name}`}function f(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}function U(t){let e=t.version;return e&&typeof e.major=="number"?`https://${t.publisher}/${t.package_}/${e.major}.${e.minor}.${e.patch}/${t.name}`:`https://${t.publisher}/${t.package_}/${t.name}`}function h(t,e){if(!(t instanceof y))return!1;for(let n of t.statement)if(n.predicate?.subject?.name==="type"&&n instanceof u){let r=n.object;if(f(r.subject,e))return!0}return!1}function j(t,e){let n=[];for(let o of t)o instanceof s&&h(o,e)&&n.push(o);return n}function E(t,e){let n=e.version,o=n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}`:void 0;for(let r of t){if(!(r instanceof s)||r.name!==e.name)continue;let a=r.namespace||"";if(o!==void 0){if(a===o)return r}else if(a.startsWith(`${e.publisher}/${e.package_}@`))return r}}function $(t,e){let n=[];for(let o of t){if(!(o instanceof s)||o.name!==e.name)continue;(o.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(o)}return n.sort((o,r)=>{let a=m((o.namespace||"").split("@")[1]??""),c=m((r.namespace||"").split("@")[1]??"");return a?c?d(c,a):-1:c?1:0}),n}function i(t,e){for(let n of t.statement){let o=n.predicate;if(o?.subject&&f(o.subject,e))return n}}function x(t,e){return i(t,e)!==void 0}function D(t,e){let n=i(t,e);if(n&&(n instanceof l||n instanceof g||n instanceof b))return n.object}function A(t,e){let n=D(t,e);return typeof n=="string"?n:void 0}function R(t,e){let n=i(t,e);if(n instanceof u)return n.object.subject}function P(t,e){let n=i(t,e);if(n instanceof k)return n.object}function v(t,e){let n=i(t,e);return n instanceof K?n.object??[]:[]}var p=class{constructor(e,n){this.doc=e;this.broader=n}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,n){return this.broader.getDocumentsByNamespaceAsync(e,n)}async getHighestCompatibleVersionAsync(e,n){return this.broader.getHighestCompatibleVersionAsync(e,n)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{S as a,f as b,U as c,h as d,j as e,E as f,$ as g,x as h,D as i,A as j,R as k,P as l,v as m,p as n};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as N}from"./chunk-NJ3AZYQD.js";import{b as V,c as C,i as B,j as M}from"./chunk-7HRKWTBB.js";import{a as _,b as U,c as S,d as k,g as P,h as x,i as O,j as I,k as R,l as v}from"./chunk-4UT2CLAT.js";import{j as $}from"./chunk-2ACBWC7K.js";var w=class extends U{name};var K=class extends _{value;carrier;lexical};var D=class extends P{links=[]};import{Carrier as j,carrierOf as F}from"@kanonak-protocol/canonical";function T(p){return F(`${p.publisher}/${p.package_}/${p.name}`)}var Y=/\[\[([^\[\]\n]+)\]\]/g,G=/\[\[/g,z=/```[\s\S]*?```|`[^`\n]*`/g;function q(p){let e=[];for(let t of p.matchAll(z))e.push([t.index,t.index+t[0].length]);return e}function ae(p){if(!p||!p.includes("[["))return[];let e=q(p),t=s=>e.some(([r,i])=>s>=r&&s<i),a=new Set(E(p).map(s=>s.startOffset)),n=[];for(let s of p.matchAll(G)){let r=s.index;if(t(r)||a.has(r))continue;let i=p.slice(r,r+48).replace(/\s+/g," ").trim();n.push({startOffset:r,snippet:i})}return n}function E(p){if(!p||!p.includes("[["))return[];let e=[];for(let n of p.matchAll(z))e.push([n.index,n.index+n[0].length]);let t=n=>e.some(([s,r])=>n>=s&&n<r),a=[];for(let n of p.matchAll(Y)){let s=n.index;if(t(s))continue;let r=n[1],i=r.indexOf("|"),c=(i===-1?r:r.slice(0,i)).trim();if(c.length===0)continue;let f=i===-1?"":r.slice(i+1).trim(),g={reference:c,startOffset:s,endOffset:s+n[0].length};f.length>0&&(g.displayText=f),a.push(g)}return a}var X=class{constructor(e){}async parseKanonaks(e){let t=[],a=await e.getAllDocumentsAsync(),n=new V(e),s=new C(n);for(let o of a){let m=o.metadata.namespace_?.toString()??"";for(let[u,y]of Object.entries(o.body)){let d=new S,b=this.resolveCanonicalEntity(u,o,m);d.namespace=b.namespace,d.name=b.name,d.statement=[];let h=await this.parseStatements(y,o,n,s,e);d.statement.push(...h.statements),d.unresolvedPredicates=h.unresolved,t.push(d)}}let r=new Map,i=new Map,c=[];for(let o of t)if(o instanceof S){let m=`${o.namespace}/${o.name}`,u=r.get(m);if(u){let y=i.get(m);for(let d of o.statement){let b=L(d);y.has(b)||(y.add(b),u.statement.push(d))}for(let d of o.unresolvedPredicates)u.unresolvedPredicates.some(b=>b.key===d.key&&b.sourceDoc===d.sourceDoc)||u.unresolvedPredicates.push(d)}else{let y=new Set,d=[];for(let b of o.statement){let h=L(b);y.has(h)||(y.add(h),d.push(b))}o.statement=d,i.set(m,y),r.set(m,o),c.push(o)}}else c.push(o);let f=new Set;for(let o of c)if(o instanceof S){let m=o.namespace||"",u=m.indexOf("/"),y=u>=0?m.slice(0,u):"",d=u>=0?m.slice(u+1):"",b=d.indexOf("@"),h=b>=0?d.slice(0,b):d;f.add(`${y}/${h}/${o.name}`)}let g=o=>f.has(`${o.publisher}/${o.package_}/${o.name}`),l=new Map;for(let o of["core-rdf","core-owl","core-kanonak"]){let m=await e.getDocumentsByNamespaceAsync("kanonak.org",o);l.set(o,$(m).chosen?.metadata.namespace_?.version??void 0)}for(let o of c)o instanceof S&&this.canonicalizeStatementBuiltins(o.statement,g,l);return c}canonicalizeStatementBuiltins(e,t,a){for(let n of e){let s=n.predicate?.subject;if(M(s,t,a),n instanceof I)n.object instanceof k&&M(n.object.subject,t,a);else if(n instanceof R)n.object&&this.canonicalizeStatementBuiltins(n.object.statement,t,a);else if(n instanceof v)for(let r of n.object??[])r instanceof k?M(r.subject,t,a):r instanceof w&&this.canonicalizeStatementBuiltins(r.statement,t,a)}}resolveCanonicalEntity(e,t,a){if(!e.includes(".")||!t.metadata?.imports)return{namespace:a,name:e};let n=e.indexOf("."),s=e.substring(0,n),r=e.substring(n+1);for(let[i,c]of Object.entries(t.metadata.imports))for(let f of c)if((f.alias??f.packageName)===s){let l=f.version;return{namespace:`${i}/${f.packageName}@${l.major}.${l.minor}.${l.patch}`,name:r}}return{namespace:a,name:e}}async parseStatements(e,t,a,n,s){let r=[],i=[];if(typeof e!="object"||e===null||Array.isArray(e))return{statements:r,unresolved:i};let c=t.metadata.namespace_?.toString()??"";for(let[f,g]of Object.entries(e))try{let l=await this.getPropertyMetadata(f,t,a,s,n);if(!l){let m=f.includes(".")?f.slice(f.lastIndexOf(".")+1):f;B(m)||i.push({key:f,sourceDoc:c});continue}let o=await this.parsePropertyValue(f,g,l,t,a,n,s);o&&r.push(o)}catch(l){throw new Error(`Failed to parse property '${f}': ${l.message}`,{cause:l})}return{statements:r,unresolved:i}}async getPropertyMetadata(e,t,a,n,s){let r=await a.resolveEntityAsync(e,t);if(!r)return;let i=r.entity,c=i.type?.toString()??"",f=c.includes(".")?c.substring(c.lastIndexOf(".")+1):c;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(f))return;let l=s.getPropertyTypeClassification(c),o=i.range?.toString(),m;if(l==="ObjectProperty")m="ObjectProperty";else if(l==="DatatypeProperty")m="DatatypeProperty";else{let d=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o??"";(o?s.isKnownXsdDatatypeName(o):!1)||d==="Literal"?m="DatatypeProperty":m="ObjectProperty"}let u;if(o){let d=t;if(r.isImported&&r.definedInNamespace){if(typeof n.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${e}': the parse repository cannot fetch defining document '${r.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let h=await n.getDocumentAsync(r.definedInNamespace);if(!h)throw new Error(`Cannot resolve the range of imported property '${e}': defining document '${r.definedInNamespace}' was not found in the repository.`);d=h}u=(await a.resolveEntityAsync(o,d))?.uri}return{propertyUri:r.uri.toString(),propertyType:m,range:o,rangeUri:u,isImported:r.isImported,definedInNamespace:r.definedInNamespace}}async parsePropertyValue(e,t,a,n,s,r,i){let c=a.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(c,t,a,n,s,r,i);if(a.propertyType==="DatatypeProperty")return this.parseDatatypeValue(c,t,a,n,s,r);if(a.propertyType==="ObjectProperty")return this.parseObjectValue(c,t,a,n,s,r,i)}}async parseDatatypeValue(e,t,a,n,s,r){let i;if(typeof t=="string"){if(r.isSubstitutableDatatype(a.rangeUri))return await this.parseSubstitutableValue(e,t,n,s);i=t}else if(typeof t=="number"||typeof t=="boolean")i=String(t);else return;return this.typedScalarStatement(e,i,a)}typedScalarStatement(e,t,a){let n=k.parse(e),s=a.rangeUri?T(a.rangeUri):void 0;if(s===j.Boolean){let i=new O;return i.predicate=n,i.object=t==="true"||t==="1",i.carrier=s,i.lexical=t,i}if(s===j.Integer||s===j.Decimal||s===j.Double||s===j.Float){let i=new x;return i.predicate=n,i.object=Number(t),i.carrier=s,i.lexical=t,i}let r=P.parse(e,t);return s&&(r.carrier=s,r.lexical=t),r}typedListLiteral(e,t){let a=new K,n=t.rangeUri?T(t.rangeUri):void 0;return n===j.Boolean?a.value=e==="true"||e==="1":n===j.Integer||n===j.Decimal||n===j.Double||n===j.Float?a.value=Number(e):a.value=e,n&&(a.carrier=n,a.lexical=e),a}async parseSubstitutableValue(e,t,a,n){let s=new D;s.predicate=k.parse(e),s.object=t;for(let r of E(t)){let i=await n.resolveEntityAsync(r.reference,a),c;i&&(c=new k,c.subject=i.uri);let f={reference:r.reference,startOffset:r.startOffset,endOffset:r.endOffset};r.displayText!==void 0&&(f.displayText=r.displayText),c!==void 0&&(f.target=c),s.links.push(f)}return s}async parseObjectValue(e,t,a,n,s,r,i){if(typeof t=="string"){let c=await this.resolveReference(t,n,s);if(!c)return;let f=new I;return f.predicate=k.parse(e),f.object=c,f}if(typeof t=="object"&&!Array.isArray(t)){let c=await this.parseStatements(t,n,s,r,i);if(c.statements.length>0){let l=new w;l.statement=c.statements,l.unresolvedPredicates=c.unresolved;let o=new R;return o.predicate=k.parse(e),o.object=l,o}let f=[];for(let[l,o]of Object.entries(t))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let m=new w;m.name=l;let u=await this.parseStatements(o,n,s,r,i);m.statement=u.statements,m.unresolvedPredicates=u.unresolved,f.push(m)}else if(typeof o=="string"){let m=await this.resolveReference(o,n,s);m&&f.push(m)}if(f.length>0){let l=new v;return l.predicate=k.parse(e),l.object=f,l}let g=new R;return g.predicate=k.parse(e),g.object=new w,g}}async parseListValue(e,t,a,n,s,r,i){let c=[],f=a.propertyType==="DatatypeProperty",g=a.rangeUri?.publisher==="kanonak.org"&&a.rangeUri?.package_==="core-rdf"&&a.rangeUri?.name==="List"||!a.rangeUri&&(a.range?.includes(".")?a.range.substring(a.range.lastIndexOf(".")+1):a.range)==="List";for(let o of t){let m=typeof o=="string"||typeof o=="number"||typeof o=="boolean";if(f&&m){let u=typeof o=="string"?o:String(o);c.push(this.typedListLiteral(u,a));continue}if(g&&m){if(typeof o=="string"){let u=await s.resolveEntityAsync(o,n);if(u){let y=new k;y.subject=u.uri,c.push(y)}else{let y=new K;y.value=o,c.push(y)}}else{let u=new K;u.value=o,c.push(u)}continue}if(typeof o=="string"){let u=await this.resolveReference(o,n,s);u&&c.push(u)}else if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let u=new w,y=await this.parseStatements(o,n,s,r,i);u.statement=y.statements,u.unresolvedPredicates=y.unresolved,c.push(u)}}let l=new v;return l.predicate=k.parse(e),l.object=c,l}async resolveReference(e,t,a){let n=await a.resolveEntityAsync(e,t);if(n){let r=new k;return r.subject=n.uri,r}let s=t.metadata?.namespace_;if(s){let{KanonakUri:r}=await import("./KanonakUri-4VJGV3FN.js");if(e.includes(".")){let c=e.indexOf("."),f=e.substring(0,c),g=e.substring(c+1);if(t.metadata?.imports){for(let[l,o]of Object.entries(t.metadata.imports))for(let m of o)if((m.alias??m.packageName)===f){let y=new k;return y.subject=new r(l,m.packageName,g,m.version),y}}}let i=new k;return i.subject=new r(s.publisher,s.package_,e,s.version??void 0),i}return null}async saveKanonaks(e,t){let a=new Map;for(let n of e)n instanceof S&&n.namespace&&(a.has(n.namespace)||a.set(n.namespace,[]),a.get(n.namespace).push(n));for(let[n,s]of a){let r=await this.convertKanonaksToDocument(n,s),i=`${n.split("@")[0]}.yml`;await t.saveDocumentAsync(r,i)}}async serializeToYaml(e,t){let a=e.filter(r=>r instanceof S&&r.namespace===t);if(a.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let n=await this.convertKanonaksToDocument(t,a);return new N().save(n)}async convertKanonaksToDocument(e,t){let n={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let r=[];for(let i of Object.values(this.imports))r.push(...i);return r}},body:{}},s=new Map;for(let r of t){let i={};for(let c of r.statement){let[f,g]=this.convertStatementToProperty(c);f&&g!==null&&g!==void 0&&(i[f]=g),this.collectImportsFromStatement(c,e,s)}n.body[r.name]=i}return n}convertStatementToProperty(e){if(e instanceof P)return[e.predicate.subject.name,e.object];if(e instanceof x)return[e.predicate.subject.name,e.object];if(e instanceof O)return[e.predicate.subject.name,e.object];if(e instanceof I)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof v){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof R){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let a of e)a instanceof k?t.push(a.subject.name):a instanceof w&&t.push(this.convertEmbeddedKanonakToValue(a));return t}convertEmbeddedKanonakToValue(e){let t={};for(let a of e.statement){let[n,s]=this.convertStatementToProperty(a);n&&s!==null&&s!==void 0&&(t[n]=s)}return t}collectImportsFromStatement(e,t,a){}};function L(p){let e=p.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+H(p)}function H(p){return p instanceof D?"m:"+String(p.object):p instanceof P?"s:"+String(p.object):p instanceof x?"n:"+String(p.object):p instanceof O?"b:"+String(p.object):p instanceof I?"r:"+A(p.object):p instanceof R?"e:"+A(p.object):p instanceof v?"l:["+(p.object??[]).map(A).join("|")+"]":"x"}function A(p){if(!p)return"";if(p instanceof k){let e=p.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return p instanceof w?"E("+(p.statement??[]).map(L).join(";")+")":p instanceof K?"L("+String(p.value)+")":"N"}export{w as a,K as b,D as c,j as d,T as e,ae as f,E as g,X as h};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as j,b as x,
|
|
1
|
+
import{a as j,b as x,h as _}from"./chunk-BKVPSPG4.js";import{d as l,e as u,f as b,g as $,h as s,k as h}from"./chunk-7HRKWTBB.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-4UT2CLAT.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let t=b(e);return this.all.has(t)?!1:(this.all.add(t),this.tripleList.push(e),P(this.byPIdx,e.p,e),P(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&P(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let t=this.byPIdx.get(e);return t?t.slice():[]}bySubjectPredicate(e,t){let r=this.bySPIdx.get(`${e}|${t}`);return r?r.slice():[]}byPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);return r?r.slice():[]}subjectsWithPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)n.add(a.s);return Array.from(n)}uriObjectsOf(e,t){let r=this.bySPIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)a.o.kind==="uri"&&n.add(a.o.key);return Array.from(n)}hasUri(e,t,r){return this.all.has(`${e}|${t}|u:${r}`)}hasTriple(e,t,r){return this.all.has(`${e}|${t}|${$(r)}`)}};function P(o,e,t){let r=o.get(e);r?r.push(t):o.set(e,[t])}var w={name:"rdfs2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.domain)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},C={name:"rdfs3",apply(o,e){let t=!1;for(let r of o.byPredicate(e.range)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,e.type,a))&&(t=!0)}return t}},A={name:"rdfs5",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subPropertyOf))i.o.kind==="uri"&&o.add(s(n,e.subPropertyOf,i.o.key))&&(t=!0)}return t}},V={name:"rdfs7",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n)){let f={s:i.s,p:a,o:i.o};o.add(f)&&(t=!0)}}return t}},W={name:"rdfs9",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},F={name:"rdfs11",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subClassOf))i.o.kind==="uri"&&o.add(s(n,e.subClassOf,i.o.key))&&(t=!0)}return t}},k=[w,C,A,V,W,F];var N={name:"prp-trp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let n of r){let a=o.byPredicate(n);for(let i of a){if(i.o.kind!=="uri")continue;let f=i.o.key;for(let c of o.bySubjectPredicate(f,n))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(s(i.s,n,c.o.key))&&(t=!0)}}return t}},D={name:"prp-symp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let n of r)for(let a of o.byPredicate(n))a.o.kind==="uri"&&o.add(s(a.o.key,n,a.s))&&(t=!0);return t}},z={name:"prp-inv1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,a,i.s))&&(t=!0)}return t}},B={name:"prp-inv2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(a))i.o.kind==="uri"&&o.add(s(i.o.key,n,i.s))&&(t=!0)}return t}},M={name:"prp-eqp1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n))o.add({s:i.s,p:a,o:i.o})&&(t=!0)}return t}},G={name:"prp-eqp2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(a))o.add({s:i.s,p:n,o:i.o})&&(t=!0)}return t}},H={name:"cax-eqc1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},J={name:"cax-eqc2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,a))o.add(s(i.s,e.type,n))&&(t=!0)}return t}},Q={name:"eq-rep-s",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a){for(let i of o.snapshot())i.s===n&&o.add({s:a,p:i.p,o:i.o})&&(t=!0);for(let i of o.snapshot())i.s===a&&o.add({s:n,p:i.p,o:i.o})&&(t=!0)}}return t}},X={name:"eq-rep-o",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===n?o.add(s(i.s,i.p,a))&&(t=!0):i.o.key===a&&o.add(s(i.s,i.p,n))&&(t=!0))}return t}},K=[N,D,z,B,M,G,H,J,Q,X];var y=class{constructor(e,t){this.store=e;this.vocabulary=t}store;vocabulary;getInstancesOfClass(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,t)}getSubclasses(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,t).filter(n=>n!==t)}getSuperclasses(e){let t=p(e);return this.store.uriObjectsOf(t,this.vocabulary.subClassOf).filter(r=>r!==t)}getTypesOfIndividual(e){return this.store.uriObjectsOf(p(e),this.vocabulary.type)}isInstanceOf(e,t){return this.store.hasUri(p(e),this.vocabulary.type,p(t))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function p(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new h,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let t=new d,n=await new _().parseKanonaks(e),a=new U;for(let c of n)if(c instanceof S){let m=Y(c);if(!m)continue;for(let E of c.statement)this.emitStatement(m,E,t,a)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let f=0;for(;f<this.maxIterations;){let c=!1;for(let m of i)m.apply(t,this.vocabulary)&&(c=!0);if(!c)break;f++}return new y(t,this.vocabulary)}emitStatement(e,t,r,n){let a=Z(t);if(a){if(t instanceof I){r.add({s:e,p:a,o:{kind:"literal",lexical:t.object,datatype:"string"}});return}if(t instanceof T){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"number"}});return}if(t instanceof g){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"boolean"}});return}if(t instanceof v){let i=l(t.object.subject);r.add(s(e,a,i));return}if(t instanceof L){let i=n.next();r.add({s:e,p:a,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t.object,r,n);return}if(t instanceof q){for(let i of t.object??[])this.emitListItem(e,a,i,r,n);return}}}emitListItem(e,t,r,n,a){if(r instanceof O)n.add(s(e,t,l(r.subject)));else if(r instanceof j){let i=a.next();n.add({s:e,p:t,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r,n,a)}else if(r instanceof x){let i=typeof r.value=="number"?"number":typeof r.value=="boolean"?"boolean":"string";n.add({s:e,p:t,o:{kind:"literal",lexical:String(r.value),datatype:i}})}}emitEmbedded(e,t,r,n){let a=`_:${e}`;for(let i of t.statement)this.emitStatement(a,i,r,n)}},U=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",t=e.indexOf("@"),r=t===-1?e:e.substring(0,t),n=r.indexOf("/");if(n===-1)return null;let a=r.substring(0,n),i=r.substring(n+1);return!a||!i||!o.name?null:u(a,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as u,f as _,j as g,k as d,m as j}from"./chunk-
|
|
1
|
+
import{a as u,f as _,j as g,k as d,m as j}from"./chunk-7TKJHKC2.js";import{j as m}from"./chunk-7HRKWTBB.js";import{c as U,d as S}from"./chunk-4UT2CLAT.js";import{a as b}from"./chunk-FUUTGGJS.js";var $=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function i(r){let n=r;if(n.entity&&typeof n.entity=="object"){let e=n.entity.type;if(typeof e=="string"){let a={publisher:"",package_:"",name:e.includes(".")?e.substring(e.lastIndexOf(".")+1):e};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}if(n.statement&&Array.isArray(n.statement)){for(let e of n.statement)if(e.predicate?.subject?.name==="type"&&e.object?.subject){let t=e.object.subject,a={publisher:t.publisher??"",package_:t.package_??"",name:t.name};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}return null}function c(r,n){return $.has(`${r}/${n}`)}var y=class r{static getTypeUri(n){return i(n)}static isCoreOntologyType(n){return c(n.publisher,n.package_)}static isClassType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Class":!1}static isDatatypeType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Datatype":!1}static isDatatypePropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="DatatypeProperty":!1}static isObjectPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="ObjectProperty":!1}static isAnnotationPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="AnnotationProperty":!1}static isGenericPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Property":!1}static isAnyPropertyType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"}static isSchemaDefinitionType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Class"||e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"||e.name==="Datatype"}static isInstanceOfKnownClass(n,e){if(r.isSchemaDefinitionType(n))return!1;let t=i(n);return t?e.has(t.name):!1}};function P(r){if(!r||r.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let n=r.trim(),e=n.split("/");if(e.length===1){let t=e[0];if(!t)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(t.includes("@"))throw new Error(`Invalid Kanonak address: "${r}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:t}}if(e.length===2){let[t,a]=e;if(!t||!a)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let o=a.indexOf("@");if(o===-1)return{kind:"package",publisher:t,package_:a};let s=a.substring(0,o),p=a.substring(o+1);if(!s||!p)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let f=A(p);return{kind:"package",publisher:t,package_:s,version:f}}return{kind:"resource",uri:b.parse(n)}}function G(r){switch(r.kind){case"publisher":return r.publisher;case"package":return r.version?`${r.publisher}/${r.package_}@${r.version.major}.${r.version.minor}.${r.version.patch}`:`${r.publisher}/${r.package_}`;case"resource":return r.uri.toString()}}function A(r){let n=r.split(".").map(Number);return w(n[0]||0,n[1]||0,n[2]||0)}function w(r,n,e){return{major:r,minor:n,patch:e,toString:()=>`${r}.${n}.${e}`,equals:t=>!t||typeof t!="object"?!1:t.major===r&&t.minor===n&&t.patch===e,getHashCode:()=>r<<20|n<<10|e,compareTo:t=>r!==t.major?r-t.major:n!==t.minor?n-t.minor:e-t.patch}}var k="kanonak.org",l="core-rdf",T={publisher:k,package_:l,name:"domain"},C={publisher:k,package_:l,name:"range"},R={publisher:k,package_:l,name:"subClassOf"},v={publisher:k,package_:l,name:"type"},x={publisher:k,package_:l,name:"label"},D={publisher:k,package_:l,name:"comment"},O=new b(k,l,"Resource"),I=r=>r;function V(r){try{let n=P(`${r.namespace}/${r.name}`);return n.kind==="resource"?n.uri:void 0}catch{return}}function h(r,n){let e=d(r,n);if(e)return[e];let t=[];for(let a of j(r,n))a instanceof S&&t.push(a.subject);return t}function N(r,n){let e=[],t=new Set,a=[new b(n.publisher,n.package_,n.name)];for(;a.length>0;){let o=a.shift(),s=u(o);if(t.has(s))continue;t.add(s),e.push(o);let p=_(r,o);p&&a.push(...h(p,R))}return e}function B(r,n){let e=new Set([u(O)]);for(let t of N(r,n))e.add(u(t));return e}function F(r,n){let e=B(r,n),t=[],a=new Set;for(let o of r){if(!(o instanceof U))continue;let s=I(o);if(!y.isAnyPropertyType(s))continue;let p=h(o,T);if(!p.some(E=>e.has(u(E))))continue;let f=V(o);if(!f)continue;let K=u(f);a.has(K)||(a.add(K),t.push({uri:f,label:g(o,x),comment:g(o,D),kind:y.isObjectPropertyType(s)?"object":y.isDatatypePropertyType(s)?"datatype":"other",range:d(o,C),domains:p}))}return t}function Z(r,n,e){let t=F(r,n).find(a=>u(a.uri)===u(e));return t?{ok:!0,descriptor:t}:{ok:!1,message:`Property ${e.publisher}/${e.package_}/${e.name} is not in scope for ${n.publisher}/${n.package_}/${n.name}.`}}function ee(r){return h(r,v)}export{y as a,P as b,G as c,V as d,N as e,F as f,Z as g,ee as h};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as V}from"./chunk-BKVPSPG4.js";import{a as E}from"./chunk-NJ3AZYQD.js";var L=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as O,LineCounter as R,isMap as h,isPair as f,isScalar as g,isSeq as I}from"yaml";var K=class i{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let t=new i,n=new R,r=O(e,{lineCounter:n});if(r.errors.length>0||!h(r.contents))return t;N(r.contents,[],n,t);for(let o of r.contents.items){if(!f(o)||!g(o.key))continue;let a=String(o.key.value),u=o.key.range;if(!u)continue;t.entities.set(a,d(u,n));let s=o.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?t.entityBlocks.set(a,d([u[0],u[1],c[2]],n)):t.entityBlocks.set(a,d(u,n)),h(o.value)){let k=new Map,m=new Map,l=new Map;for(let P of o.value.items){if(!f(P)||!g(P.key))continue;let b=String(P.key.value),p=P.key.range;p&&k.set(b,d(p,n));let S=P.value;if(S&&typeof S=="object"&&"range"in S&&Array.isArray(S.range)){let v=S.range;m.set(b,d(v,n))}if(I(S)){let v=[];for(let M of S.items)M&&typeof M=="object"&&"range"in M&&Array.isArray(M.range)&&v.push(d(M.range,n));v.length>0&&l.set(b,v)}}k.size>0&&t.properties.set(a,k),m.size>0&&t.propertyValues.set(a,m),l.size>0&&t.valueListItems.set(a,l);let y=j(o.value,n);y.length>0&&t.importPackages.set(a,y)}}return t}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,t){for(let[n,r]of this.entityBlocks)if(w(r,e,t))return n}findPropertyAtPosition(e,t){let n=this.findEntityAtPosition(e,t);if(!n)return;let r=this.properties.get(n),o=this.propertyValues.get(n);if(!r&&!o)return{entityName:n};let a,u;if(o)for(let[s,c]of o)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);if(r)for(let[s,c]of r)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);return a?{entityName:n,propertyName:a}:{entityName:n}}getPropertyPosition(e,t){return this.properties.get(e)?.get(t)}getPropertyValuePosition(e,t){return this.propertyValues.get(e)?.get(t)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[t,n]of this.importPackages)for(let r of n)e.push({entityName:t,entry:r});return e}findPropertySourceName(e,t){let n=this.properties.get(e);if(n){if(n.has(t))return t;for(let r of n.keys()){let o=r.lastIndexOf(".");if((o===-1?r:r.substring(o+1))===t)return r}}}getListItemPosition(e,t,n){let r=this.valueListItems.get(e)?.get(t);if(!(!r||n<0||n>=r.length))return r[n]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,t){this.nestedKeys.set(e,t)}setNestedValuePosition(e,t){this.nestedValues.set(e,t)}getMostSpecificPosition(e,t,n){if(e){if(t!==void 0){if(n!==void 0){let a=this.getListItemPosition(e,t,n);if(a)return a}let r=this.getPropertyValuePosition(e,t);if(r)return r;let o=this.getPropertyPosition(e,t);if(o)return o}return this.getEntityPosition(e)}}};function j(i,e){let t=[];if(!h(i))return t;let n=i.items.find(r=>f(r)&&g(r.key)&&String(r.key.value)==="imports");if(!n||!f(n)||!I(n.value))return t;for(let r of n.value.items){if(!h(r))continue;let o=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!o||!f(o)||!g(o.value))continue;let a=String(o.value.value),u=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!f(u)||!I(u.value)))for(let s of u.value.items){if(!h(s))continue;let c=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="package");if(!c||!f(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="version"),l=m&&f(m)&&g(m.value)?String(m.value.value):"",y=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="alias"),P=y&&f(y)&&g(y.value)?String(y.value.value):void 0,b=P!==void 0?{publisher:a,package_:k,version:l,alias:P,position:d(c.value.range,e)}:{publisher:a,package_:k,version:l,position:d(c.value.range,e)};t.push(b)}}return t}function w(i,e,t){return!(e<i.line||e>i.endLine||e===i.line&&t<i.column||e===i.endLine&&t>i.endColumn)}function C(i,e){let t=i.endLine-i.line,n=e.endLine-e.line;if(t!==n)return t<n;let r=i.endLine===i.line?i.endColumn-i.column:Number.MAX_SAFE_INTEGER,o=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return r<o}function N(i,e,t,n){if(h(i)){for(let r of i.items){if(!f(r)||!g(r.key))continue;let o=String(r.key.value),a=[...e,o],u=JSON.stringify(a);r.key.range&&n.setNestedKeyPosition(u,d(r.key.range,t));let s=r.value,c=D(s);c&&n.setNestedValuePosition(u,d(c,t)),N(s,a,t,n)}return}if(I(i)){for(let r=0;r<i.items.length;r++){let o=i.items[r],a=[...e,r],u=JSON.stringify(a),s=D(o);s&&n.setNestedValuePosition(u,d(s,t)),N(o,a,t,n)}return}}function D(i){if(!i||typeof i!="object"||!("range"in i))return;let e=i.range;return Array.isArray(e)&&e.length>=3?e:void 0}function d(i,e){let t=e.linePos(i[0]),n=e.linePos(i[2]);return{line:t.line-1,column:t.col-1,endLine:n.line-1,endColumn:n.col-1}}function x(i,e){let n=(e??new E).parse(i),r=K.fromContent(i);return{document:n,positions:r}}function W(i,e,t,n,r){if(e<n.line||e>n.endLine||e===n.line&&t<n.column||e===n.endLine&&t>=n.endColumn)return;let o=A(r,n.line,n.column),a=A(r,n.endLine,n.endColumn);if(o<0||a<0)return;let u=r.substring(o,a),s=V(u);if(s.length!==i.links.length)return;let c=e-n.line,k=e===n.line?t-n.column:t,m=A(u,c,k);if(!(m<0))for(let l=0;l<s.length;l++){let y=s[l];if(m>=y.startOffset&&m<y.endOffset)return i.links[l]}}function A(i,e,t){let n=0,r=0;for(let o=0;o<i.length;o++){if(n===e)return Math.min(r+t,i.length);i[o]===`
|
|
2
2
|
`&&(n++,r=o+1)}return n===e?Math.min(r+t,i.length):-1}export{L as a,K as b,x as c,W as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{J as W,K as X}from"./chunk-
|
|
1
|
+
import{J as W,K as X}from"./chunk-UBBZWWRB.js";import{b as B,c as V,h as w}from"./chunk-BKVPSPG4.js";import{a as b,d as K,e as q,f as z}from"./chunk-IEOSSSB5.js";import{a as D,f as E,h as F,j as N,k as Y,m as v}from"./chunk-7TKJHKC2.js";import{c as G,d as x}from"./chunk-4UT2CLAT.js";import{a as L}from"./chunk-FUUTGGJS.js";import{d as U}from"./chunk-2ACBWC7K.js";var Q=(t=>(t.Class="Class",t.DatatypeProperty="DatatypeProperty",t.ObjectProperty="ObjectProperty",t.AnnotationProperty="AnnotationProperty",t.Instance="Instance",t.Datatype="Datatype",t.Unknown="Unknown",t))(Q||{}),Z=(p=>(p.InstanceOf="instanceOf",p.SubClassOf="subClassOf",p.Domain="domain",p.Range="range",p.ObjectRelationship="objectRelationship",p.SubPropertyOf="subPropertyOf",p.PropertyValue="propertyValue",p.EmbeddedLink="embeddedLink",p))(Z||{}),I=class{static async buildFromRepository(e){let a=await new w().parseKanonaks(e),o=await e.getAllDocumentsAsync(),s=[],i=[],t=new Set,p=new Set,g=new Map;for(let u of a){let l=u;l.name&&(b.isClassType(l)&&t.add(l.name),(b.isObjectPropertyType(l)||b.isGenericPropertyType(l))&&p.add(l.name))}for(let u of o)for(let[l,f]of Object.entries(u.body))p.has(l)&&f?.range&&typeof f.range=="string"&&g.set(l,f.range);let y=new Map;for(let u of a){let l=u;l.name&&y.set(l.name,l)}for(let u of o){let l=u.metadata.namespace_,f=l?`${l.publisher}/${l.package_}`:"",c=l?.version?`${l.version.major}.${l.version.minor}.${l.version.patch}`:"",d=H(u);for(let[k,m]of Object.entries(u.body)){if(!m||typeof m!="object")continue;let P=y.get(k),h="Unknown";if(P){let T=P;b.isClassType(T)?h="Class":b.isObjectPropertyType(T)?h="ObjectProperty":b.isDatatypePropertyType(T)?h="DatatypeProperty":b.isAnnotationPropertyType(T)?h="AnnotationProperty":b.isDatatypeType(T)?h="Datatype":b.isGenericPropertyType(T)?h="ObjectProperty":b.isInstanceOfKnownClass(T,t)&&(h="Instance")}let j=f&&c?`${f}/${k}@${c}`:k,A={};for(let[T,$]of Object.entries(m))T!=="type"&&(typeof $!="object"||$===null)&&(A[T]=$);s.push({id:j,label:m.label??k,type:h,namespace:f,properties:A}),J(j,m,h,t,p,i,f,c,d),_(j,m,p,g,s,i,f,c,d),ue(j,P,i)}}return{nodes:s,edges:i}}static buildFromDocument(e){let r=[],a=[],o=e.metadata.namespace_,s=o?.version?`${o.version.major}.${o.version.minor}.${o.version.patch}`:"",i=o?`${o.publisher}/${o.package_}`:"",t=new Set,p=new Set,g=new Map,y=H(e);for(let[f,c]of Object.entries(e.body)){let d=c?.type;d&&(pe(d,y)&&t.add(f),ce(d,y)&&(p.add(f),c.range&&typeof c.range=="string"&&g.set(f,c.range)))}for(let[f,c]of Object.entries(e.body)){if(!c||typeof c!="object")continue;let d=c.type,k=le(d,f,t,y),m=i&&s?`${i}/${f}@${s}`:f,P={};for(let[h,j]of Object.entries(c))h!=="type"&&(typeof j!="object"||j===null)&&(P[h]=j);r.push({id:m,label:c.label??f,type:k,namespace:i,properties:P}),J(m,c,k,t,p,a,i,s,y),_(m,c,p,g,r,a,i,s,y)}let u=new Set(r.map(f=>f.id)),l=a.filter(f=>u.has(f.source)&&u.has(f.target));return{nodes:r,edges:l}}};function H(n,e){let r=new Map;if(n.metadata?.imports)for(let[a,o]of Object.entries(n.metadata.imports))for(let s of o){let i=s.alias??s.packageName,t=s.version,p=`${t.major}.${t.minor}.${t.patch}`;r.set(i,{publisher:a,package_:s.packageName,version:p})}return r}var ee={"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"},ie=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function M(n,e){if(n.includes(".")){let r=n.indexOf("."),a=n.substring(0,r),o=n.substring(r+1),s=e.get(a);if(s)return`${s.publisher}/${s.package_}/${o}`}return null}function pe(n,e){let r=M(n,e);return r?ee[r]==="Class":!1}function ce(n,e){let r=M(n,e);return r?ie.has(r):!1}function le(n,e,r,a){if(!n||n==="Package")return"Unknown";let o=M(n,a);if(o){let i=ee[o];if(i)return i;let t=o.split("/").pop()?.split("@")[0]??"";return r.has(t)?"Instance":"Unknown"}let s=n.split(".").pop()??n;return r.has(s)?"Instance":"Unknown"}var ne=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function J(n,e,r,a,o,s,i,t,p){let g=e.type,y=e.subClassOf;if(y){let c=Array.isArray(y)?y:[y];for(let d of c)typeof d=="string"&&s.push({source:n,target:O(d,i,t,p),type:"subClassOf",label:"subClassOf"})}let u=e.subPropertyOf;if(u){let c=Array.isArray(u)?u:[u];for(let d of c)typeof d=="string"&&s.push({source:n,target:O(d,i,t,p),type:"subPropertyOf",label:"subPropertyOf"})}if(r==="Instance"&&g){let c=g.split(".").pop()??g;s.push({source:n,target:O(c,i,t,p),type:"instanceOf",label:"type"})}if(r==="Instance")for(let[c,d]of Object.entries(e)){if(ne.has(c)||!o.has(c))continue;let k=Array.isArray(d)?d:[d];for(let m of k)typeof m=="string"&&fe(m)&&s.push({source:n,target:O(m,i,t,p),type:"propertyValue",label:c,propertyId:O(c,i,t,p)})}let l=r==="ObjectProperty"||r==="DatatypeProperty",f=e.domain&&e.range;if((l||f)&&e.domain&&e.range){let c=typeof e.domain=="string"?e.domain:null,d=typeof e.range=="string"?e.range:null;c&&d&&s.push({source:O(c,i,t,p),target:O(d,i,t,p),type:"objectRelationship",label:e.label??n.split("/").pop()??"",propertyId:n})}}function _(n,e,r,a,o,s,i,t,p){for(let[g,y]of Object.entries(e)){if(ne.has(g)||typeof y!="object"||y===null||Array.isArray(y))continue;let u=y,l=`${n}/${g}`,f=a.get(g),c=f?f.split(".").pop()??f:"Unknown",d={};for(let[m,P]of Object.entries(u))(typeof P!="object"||P===null)&&(d[m]=P);o.push({id:l,label:`${c} (embedded)`,type:"Instance",namespace:i,properties:d});let k=i&&t?`${i}/${g}@${t}`:g;s.push({source:n,target:l,type:"propertyValue",label:g,propertyId:r.has(g)?k:void 0}),f&&s.push({source:l,target:O(c,i,t,p),type:"instanceOf",label:"type (inferred)"}),_(l,u,r,a,o,s,i,t,p)}}function ue(n,e,r){let a=e?.statement;if(Array.isArray(a))for(let o of a){if(!(o instanceof V))continue;let s=o.predicate?.subject?.name??"";for(let i of o.links){let t=i.target?.subject;if(!t)continue;let p=t.version,g=p&&typeof p.major=="number"?`@${p.major}.${p.minor}.${p.patch}`:"";r.push({source:n,target:`${t.publisher}/${t.package_}/${t.name}${g}`,type:"embeddedLink",label:s})}}}function fe(n){return!(!n||n.includes(" ")||n.includes(`
|
|
2
2
|
`)||n.startsWith("http://")||n.startsWith("https://")||/^\d{4}-\d{2}/.test(n)||/^\d+(\.\d+)?$/.test(n))}function O(n,e,r,a){if(n.includes("@")&&n.includes("/"))return n;if(n.includes(".")){let o=n.indexOf("."),s=n.substring(0,o),i=n.substring(o+1);if(a){let t=a.get(s);if(t)return`${t.publisher}/${t.package_}/${i}@${t.version}`}return e&&r?`${e}/${i}@${r}`:i}return e&&r?`${e}/${n}@${r}`:n}function de(n){if(!n.expiresAt)return!1;let e=new Date(n.expiresAt),r=300*1e3;return e.getTime()<=Date.now()+r}function Re(n){return!!n.accessToken&&!de(n)}function Se(n){let e=n.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!e)throw new Error("Publisher host cannot be empty");return e}var C="kanonak.org",S="core-rdf",re="core-xsd",te={publisher:C,package_:S,name:"subClassOf"},oe={publisher:C,package_:S,name:"label"},ye={publisher:C,package_:S,name:"comment"},se={publisher:C,package_:"core-owl",name:"oneOf"},ae=n=>n;function ge(n){let e=Y(n,te);if(e)return[e];let r=[];for(let a of v(n,te))a instanceof x&&r.push(a.subject);return r}function me(n,e,r){if(e.publisher===C&&e.package_===S&&e.name==="Literal")return{kind:"datatype",uri:e};let o=E(n,e);if(o){let s=ae(o);if(b.isDatatypeType(s))return{kind:"datatype",uri:e};if(b.isClassType(s))return{kind:"class",uri:K(o)??e,localName:o.name}}return e.publisher===C&&e.package_===re?{kind:"datatype",uri:e}:r==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function be(n,e,r){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let a=me(n,e.range,e.kind),o=e.kind==="object"?"object":e.kind==="datatype"?"datatype":a.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:o,range:a,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...r??{}}}var R=n=>new L(C,re,n);function ke(n){return typeof n=="boolean"?R("boolean"):typeof n=="number"?Number.isInteger(n)?R("integer"):R("decimal"):R("string")}function he(n,e){let r=[];for(let a of v(e,se))if(a instanceof x){let o=E(n,a.subject),s=(o?K(o):void 0)??a.subject,i=o?N(o,oe):void 0;r.push({kind:"individual",uri:s,localName:s.name,...i!==void 0?{label:i}:{}})}else a instanceof B&&r.push({kind:"literal",value:a.value,datatype:ke(a.value)});return r}function Pe(n,e,r,a){let o=q(n,e),s=D(e);return z(n,e).filter(t=>r?!0:t.domains.some(p=>D(p)===s)).map(t=>be(n,t,X(a,o,t.uri)))}async function Te(n,e,r){let a=n.metadata?.namespace_;if(!a)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let o=r?.includeInherited??!1,s=await new w().parseKanonaks(e),i=W(s),t=[],p=[],g=new Set;for(let y of s){if(!(y instanceof G)||!b.isClassType(ae(y)))continue;let u=K(y);if(!u||u.publisher!==a.publisher||u.package_!==a.package_||u.version&&a.version&&!U(u.version,a.version))continue;let l=D(u);if(g.has(l))continue;g.add(l);let f=ge(y).map(k=>({uri:k,localName:k.name})),c=N(y,oe),d=N(y,ye);t.push({uri:u,localName:u.name,superClasses:f,properties:Pe(s,u,o,i),...c!==void 0?{label:c}:{},...d!==void 0?{comment:d}:{}}),F(y,se)&&p.push({uri:u,localName:u.name,members:he(s,y),...c!==void 0?{label:c}:{},...d!==void 0?{comment:d}:{}})}return{classes:t,enums:p}}export{Q as a,Z as b,I as c,de as d,Re as e,Se as f,Te as g};
|