@kanonak-protocol/sdk 3.47.0 → 3.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1 -1
- package/dist/chunk-2CLFEFQP.js +1 -0
- package/dist/chunk-3NEUHF7E.js +0 -0
- package/dist/chunk-64TVBQFR.js +1 -0
- package/dist/chunk-BHDXQKDP.js +1 -0
- package/dist/{chunk-RCI34BYO.js → chunk-D7A5HWZK.js} +1 -1
- package/dist/chunk-DC774EQL.js +1 -0
- package/dist/chunk-EDINPLEL.js +116 -0
- package/dist/{chunk-NIJV5UYW.js → chunk-GR5IXWKN.js} +1 -1
- package/dist/chunk-GYKITV44.js +1 -0
- package/dist/chunk-MOFATNEC.js +1 -0
- package/dist/chunk-N224PFBI.js +1 -0
- package/dist/chunk-Q4DKP5DO.js +1 -0
- package/dist/chunk-WDVGQCGC.js +59 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +13 -13
- package/dist/look/LookRenderer.d.ts +10 -2
- package/dist/look/displayValue.d.ts +27 -0
- package/dist/look/index.d.ts +1 -0
- package/dist/parsing/KanonakObjectParser.d.ts +6 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/KanonakVocabulary.d.ts +35 -8
- package/dist/reasoning/index.d.ts +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/LocalFirstRepository.d.ts +28 -0
- package/dist/repositories/buildLocalFirstRepository.d.ts +29 -0
- package/dist/repositories/index.d.ts +2 -0
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/TypeDirectedResolver.d.ts +36 -0
- package/dist/resolution/index.d.ts +2 -0
- package/dist/resolution/index.js +1 -1
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/server/loadServerModel.d.ts +16 -0
- package/dist/server/route.d.ts +12 -0
- package/dist/server/types.d.ts +62 -0
- package/dist/transformations/index.js +1 -1
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/DisplayLensScopeRule.d.ts +27 -0
- package/dist/validation/rules/repository/index.d.ts +1 -0
- package/package.json +6 -2
- package/dist/chunk-2JQMUZWN.js +0 -1
- package/dist/chunk-4TJZIM7A.js +0 -1
- package/dist/chunk-5AH6GIPO.js +0 -1
- package/dist/chunk-FJ35VIV6.js +0 -1
- package/dist/chunk-FMYLEPMC.js +0 -1
- package/dist/chunk-HEMBMX7T.js +0 -1
- package/dist/chunk-IOJMTW4T.js +0 -1
- package/dist/chunk-JGVDV6PM.js +0 -1
- package/dist/chunk-KPLFNUIL.js +0 -116
- package/dist/chunk-SKTXJV4T.js +0 -54
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
2
|
+
import { KanonakParser } from '../parsing/KanonakParser.js';
|
|
3
|
+
/**
|
|
4
|
+
* Recursively collect every `.kan.yml` file under `dir`, skipping build/output
|
|
5
|
+
* and dependency directories. Pure filesystem walk — no YAML parsing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectKanonakFiles(dir: string, files?: string[]): string[];
|
|
8
|
+
/** Hook for persisting / reading HTTP-fetched documents (e.g. a disk cache). */
|
|
9
|
+
export interface HttpCacheHooks {
|
|
10
|
+
getFromCache(publisher: string, packageName: string, version: string): string | null;
|
|
11
|
+
onFetch(publisher: string, packageName: string, version: string, content: string): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the canonical three-tier resolution repository, workspace-first:
|
|
15
|
+
*
|
|
16
|
+
* 1. **Workspace** — every `.kan.yml` under `workspaceRoot`, parsed into an
|
|
17
|
+
* in-memory repo (loaded first → returned first, so open-world
|
|
18
|
+
* augmentations merge in workspace order).
|
|
19
|
+
* 2. **Global cache** — `~/.kanonak/packages/` (`getGlobalCachePath()`).
|
|
20
|
+
* 3. **HTTP** — on-demand fetch from publisher origins, write-through to the
|
|
21
|
+
* caller-supplied `httpCache` (defaults to an in-memory map).
|
|
22
|
+
*
|
|
23
|
+
* This is the stack every Kanonak-aware tool should resolve through; it is the
|
|
24
|
+
* order that makes `LookRenderer` output deterministic. The CLI's
|
|
25
|
+
* `buildRepository` and the server core both build on this.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildLocalFirstRepository(workspaceRoot: string, parser?: KanonakParser, options?: {
|
|
28
|
+
httpCache?: HttpCacheHooks;
|
|
29
|
+
}): Promise<IKanonakDocumentRepository>;
|
|
@@ -3,6 +3,8 @@ export { FileSystemKanonakDocumentRepository } from './FileSystemKanonakDocument
|
|
|
3
3
|
export { CompositeKanonakDocumentRepository, DocumentLocation } from './CompositeKanonakDocumentRepository.js';
|
|
4
4
|
export { RepositoryFactory } from './RepositoryFactory.js';
|
|
5
5
|
export { HttpKanonakDocumentRepository } from './HttpKanonakDocumentRepository.js';
|
|
6
|
+
export { LocalFirstRepository } from './LocalFirstRepository.js';
|
|
7
|
+
export { buildLocalFirstRepository, collectKanonakFiles, type HttpCacheHooks, } from './buildLocalFirstRepository.js';
|
|
6
8
|
export { PublisherIndex } from './PublisherIndex.js';
|
|
7
9
|
export { PublisherConfigResolver } from './PublisherConfig.js';
|
|
8
10
|
export type { PublisherConfig } from './PublisherConfig.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as c,c as d,d as e,e as f}from"../chunk-
|
|
1
|
+
import{a as b,b as c,c as d,d as e,e as f,f as j,g as k,h as l}from"../chunk-MOFATNEC.js";import{a,b as g,c as h,d as i}from"../chunk-VHUJSHH7.js";import"../chunk-7CUTGGH3.js";import"../chunk-FQHALFRR.js";export{d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,i as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,j as LocalFirstRepository,g as PublisherConfigResolver,h as PublisherIndex,f as RepositoryFactory,l as buildLocalFirstRepository,k as collectKanonakFiles,e as getGlobalCachePath};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Kanonak } from '../kanonaks/Kanonak.js';
|
|
2
|
+
import { SubjectKanonak } from '../kanonaks/SubjectKanonak.js';
|
|
3
|
+
import { KanonakUri } from './KanonakUri.js';
|
|
4
|
+
import { type EntityUri } from '../uri-helpers/index.js';
|
|
5
|
+
export type PropertyKind = 'object' | 'datatype' | 'other';
|
|
6
|
+
export interface PropertyDescriptor {
|
|
7
|
+
/** The property's canonical URI. */
|
|
8
|
+
uri: KanonakUri;
|
|
9
|
+
/** The property's rdfs.label, if declared. */
|
|
10
|
+
label: string | undefined;
|
|
11
|
+
/** ObjectProperty / DatatypeProperty / other, classified by URI. */
|
|
12
|
+
kind: PropertyKind;
|
|
13
|
+
/** The property's declared range, if any. */
|
|
14
|
+
range: KanonakUri | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Build a subject's canonical URI from its namespace + name. */
|
|
17
|
+
export declare function subjectUri(subject: SubjectKanonak): KanonakUri | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Every property in scope for a class — those whose `domain` is the
|
|
20
|
+
* class, an ancestor, or rdfs.Resource. Scans the catalog once. Powers
|
|
21
|
+
* completion and single-hop path-step validation.
|
|
22
|
+
*/
|
|
23
|
+
export declare function propertiesInScope(catalog: Kanonak[], classUri: EntityUri): PropertyDescriptor[];
|
|
24
|
+
export interface StepResolution {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
descriptor?: PropertyDescriptor;
|
|
27
|
+
message?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate a single property step against a context class: is
|
|
31
|
+
* `propertyUri` a property in scope for `classUri`? Returns the
|
|
32
|
+
* descriptor on success, or a diagnostic message on failure.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolvePropertyStep(catalog: Kanonak[], classUri: EntityUri, propertyUri: EntityUri): StepResolution;
|
|
35
|
+
/** The type URIs declared on an instance — the completion context. */
|
|
36
|
+
export declare function contextTypesOf(instance: SubjectKanonak): KanonakUri[];
|
|
@@ -8,6 +8,8 @@ export { KanonakUrlResolver } from './KanonakUrlResolver.js';
|
|
|
8
8
|
export type { UrlAddress, PublisherUrlAddress, PackageUrlAddress, ResourceUrlAddress, VersionSpec, UrlForm, } from './KanonakUrlResolver.js';
|
|
9
9
|
export type { ResourceResolutionResult } from './ResourceResolutionResult.js';
|
|
10
10
|
export { TypeResolver } from './TypeResolver.js';
|
|
11
|
+
export { propertiesInScope, resolvePropertyStep, contextTypesOf, subjectUri, } from './TypeDirectedResolver.js';
|
|
12
|
+
export type { PropertyDescriptor, PropertyKind, StepResolution } from './TypeDirectedResolver.js';
|
|
11
13
|
export { ResourceTypeClassifier } from './ResourceTypeClassifier.js';
|
|
12
14
|
export { findInstancesByType } from './InstanceSearch.js';
|
|
13
15
|
export type { InstanceSearchResult } from './InstanceSearch.js';
|
package/dist/resolution/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as l,b as
|
|
1
|
+
import{a as m,b as u}from"../chunk-DC774EQL.js";import{a as p}from"../chunk-NIGFQYVA.js";import{a as l,b as n,c as o,d as q,e as r,f as s,g as t}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import{a,b,c,d,e,f,g,h}from"../chunk-FQHALFRR.js";import{b as j,c as k}from"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import{a as i}from"../chunk-FUUTGGJS.js";export{i as KanonakUri,m as KanonakUriBuilder,p as KanonakUrlResolver,j as ResourceResolver,l as ResourceTypeClassifier,k as TypeResolver,a as compareVersions,t as contextTypesOf,d as createVersion,u as findInstancesByType,o as formatKanonakAddress,c as formatVersion,f as isCompatibleVersion,g as isMajorCompatible,n as parseKanonakAddress,e as parseVersionString,h as pickHighestDocument,r as propertiesInScope,s as resolvePropertyStep,q as subjectUri,b as versionsEqual};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{c as O}from"../chunk-EDINPLEL.js";import"../chunk-3NEUHF7E.js";import{a as P,d as _,f as F,g as N}from"../chunk-MOFATNEC.js";import{a as V,d as K}from"../chunk-VHUJSHH7.js";import{a as L}from"../chunk-NIGFQYVA.js";import{f as D}from"../chunk-GYKITV44.js";import{a as M}from"../chunk-7CUTGGH3.js";import"../chunk-Q4DKP5DO.js";import{a as x,e as R}from"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import{c as C}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{readFileSync as B}from"fs";async function A(n,e={}){let a=new M,r=new V(a),c=[];for(let o of N(n)){let h;try{h=B(o,"utf-8")}catch{continue}let u;try{u=a.parse(h).metadata?.namespace_}catch{continue}if(!u?.version)continue;let v=u.version,w=`${v.major}.${v.minor}.${v.patch}`;await r.saveDocumentAsync(a.parse(h),`${u.publisher}/${u.package_}@${w}`),c.push({publisher:u.publisher,package_:u.package_,verStr:w,source:h})}let g=[...new Set(c.map(o=>o.publisher))].sort(),m=e.publisher;if(m){if(!g.includes(m))throw new Error(`Publisher "${m}" not found in workspace. Available: ${g.join(", ")||"(none)"}`)}else if(g.length===1)m=g[0];else throw g.length===0?new Error(`No Kanonak packages found under ${n}`):new Error(`Workspace has multiple publishers (${g.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let d=new Set,b=new Map;for(let o of c)o.publisher===m&&(d.add(`${o.publisher}/${o.package_}@${o.verStr}`),b.set(`${o.package_}@${o.verStr}`,o.source));let $=e.repository??new F(r,new P(_(),!0,a),new K(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),i=await new D(a).parseKanonaks($),s=new O(i),t=new Map,l=new Map,k=new Map,y=new Set;for(let o of i){if(!(o instanceof C))continue;let h=o.namespace||"";if(!d.has(h))continue;t.set(`${h}/${o.name}`,o);let u=h.split("/")[1]??"",[v,w]=u.split("@");if(!v||!w)continue;let j=R(w);j&&(y.has(u)||(y.add(u),l.has(v)||l.set(v,[]),l.get(v).push({verStr:w,version:j})),o.name===v&&k.set(u,o))}for(let o of l.values())o.sort((h,u)=>x(u.version,h.version));return{publisher:m,availablePublishers:g,catalog:i,lookRenderer:s,localNamespaces:d,rawByNsKey:b,bySubject:t,pkgVersions:l,pkgSelfByVer:k}}var p={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},f=(n,e,a,r)=>({status:n,headers:{"Content-Type":e,...r||{}},body:a}),S=n=>f(404,p[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${n}</p>`),I=n=>({status:301,headers:{Location:n},body:""});function E(n,e,a){let r=n.pkgVersions.get(e);if(!r||r.length===0)return null;switch(a.kind){case"any":return r[0].verStr;case"major-pin":return r.find(c=>c.version.major===a.major)?.verStr??null;case"minor-pin":return r.find(c=>c.version.major===a.major&&c.version.minor===a.minor)?.verStr??null;case"exact":return r.find(c=>c.version.major===a.major&&c.version.minor===a.minor&&c.version.patch===a.patch)?.verStr??null;default:return null}}function T(n,e,a=""){let{lookRenderer:r,publisher:c}=n;if(e==="/.well-known/kanonak.json")return f(200,p[".json"],JSON.stringify({version:1,auth:"none"},null,2));if(e==="/index.txt"){let s=[...n.localNamespaces].map(t=>t.split("/")[1].replace("@","/")).sort();return f(200,p[".txt"],s.join(`
|
|
2
|
+
`)+`
|
|
3
|
+
`)}if(e==="/"||e==="/index.html"||e==="/index.css"){let s=r.findPublisherRootView(c),t=[...n.pkgVersions.keys()].sort(),l=s??(t.length?n.pkgSelfByVer.get(`${t[0]}@${n.pkgVersions.get(t[0])[0].verStr}`):void 0);if(e==="/index.css")return f(200,p[".css"],s?r.renderStylesheet(s):r.renderPublisherIndexStylesheet(l));if(s)return f(200,p[".html"],r.renderDocument(s,{rootIndex:!0}));let k=t.map(y=>({label:y,href:`/${y}`}));return f(200,p[".html"],r.renderPublisherIndex(c,k,l))}let g=".html",m=!1,d=e;for(let s of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(s)){g=s,m=!0,d=e.slice(0,-s.length);break}let b=!m&&/application\/yaml|text\/yaml/i.test(a),$=d.endsWith("/");$&&d!=="/"&&(d=d.slice(0,-1));let i=L.parse(d,c);if(!i)return S(e);if(i.kind==="package"){let s=E(n,i.package_,i.versionSpec);if(!s)return S(e);if(g===".kan.yml"||b){let k=n.rawByNsKey.get(`${i.package_}@${s}`);return k!==void 0?f(200,p[".kan.yml"],k):S(e)}let t=n.pkgSelfByVer.get(`${i.package_}@${s}`);if(!t)return S(e);if(g===".css")return f(200,p[".css"],r.renderStylesheet(t));if(!$)return I(d+"/");let l=i.versionSpec.kind==="any";if(l&&!r.hasDeclaredView(t)){let k=(n.pkgVersions.get(i.package_)||[]).map(y=>y.verStr);return f(200,p[".html"],r.renderPackageVersionList(i.package_,k,t))}return f(200,p[".html"],r.renderDocument(t,l?{bareOverview:!0}:void 0))}if(i.kind==="resource"){let s=E(n,i.package_,i.versionSpec);if(!s)return S(e);let t=n.bySubject.get(`${c}/${i.package_}@${s}/${i.name}`);if(!t)return S(e);switch(g){case".css":return f(200,p[".css"],r.renderStylesheet(t));case".svg":return f(200,p[".svg"],r.renderSvg(t));case".md":{let l=r.renderRawMarkdown(t);return l===void 0?S(e):f(200,p[".md"],l)}default:return f(200,p[".html"],r.renderDocument(t))}}return S(e)}export{A as loadServerModel,T as route};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ServerModel, LoadServerModelOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Load a workspace into an in-memory {@link ServerModel} for {@link route}.
|
|
4
|
+
*
|
|
5
|
+
* A publisher origin serves exactly ONE publisher. With several publishers in
|
|
6
|
+
* the workspace, pass `{ publisher }`; a single-publisher workspace infers it,
|
|
7
|
+
* an empty one throws, and an ambiguous one throws with the candidate list.
|
|
8
|
+
* ALL local files are still loaded into the resolution repository regardless,
|
|
9
|
+
* so cross-publisher imports between local packages keep resolving — only the
|
|
10
|
+
* SERVED set (routing, `index.txt`, package list, raw source) is scoped to the
|
|
11
|
+
* chosen publisher.
|
|
12
|
+
*
|
|
13
|
+
* Raw `.kan.yml` source is read here and held in the model so `route` performs
|
|
14
|
+
* no filesystem I/O.
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadServerModel(workspaceRoot: string, options?: LoadServerModelOptions): Promise<ServerModel>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ServerModel, RouteResponse } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Map one request to a response, using the same `LookRenderer` calls
|
|
4
|
+
* `kanonak publish` makes — so a live response is byte-equivalent to the
|
|
5
|
+
* static page `publish` would write — plus the machine-facing endpoints
|
|
6
|
+
* `publish` omits (`/.well-known/kanonak.json`, `/index.txt`, raw `.kan.yml`).
|
|
7
|
+
*
|
|
8
|
+
* Pure: `pathname` in, response out. No filesystem or network I/O — raw
|
|
9
|
+
* sources are preloaded in the model. `accept` disambiguates the no-extension
|
|
10
|
+
* case (raw package YAML vs HTML).
|
|
11
|
+
*/
|
|
12
|
+
export declare function route(model: ServerModel, pathname: string, accept?: string): RouteResponse;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Version } from '@kanonak-protocol/types/document/models/types';
|
|
2
|
+
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
3
|
+
import type { Kanonak } from '../kanonaks/index.js';
|
|
4
|
+
import { SubjectKanonak } from '../kanonaks/index.js';
|
|
5
|
+
import type { LookRenderer } from '../look/index.js';
|
|
6
|
+
import type { HttpCacheHooks } from '../repositories/index.js';
|
|
7
|
+
/** A package version present in the served workspace. */
|
|
8
|
+
export interface PackageVersion {
|
|
9
|
+
/** "major.minor.patch" string form. */
|
|
10
|
+
readonly verStr: string;
|
|
11
|
+
/** Parsed Version (for comparison against a URL `VersionSpec`). */
|
|
12
|
+
readonly version: Version;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The in-memory render model for one served publisher: the parsed catalog, a
|
|
16
|
+
* `LookRenderer` over it, and the indexes `route` needs to map a path to a
|
|
17
|
+
* response without touching the filesystem. Built once by `loadServerModel`
|
|
18
|
+
* and held in memory; rebuilt on workspace change (the CLI's `--watch`).
|
|
19
|
+
*/
|
|
20
|
+
export interface ServerModel {
|
|
21
|
+
/** The publisher this model serves. */
|
|
22
|
+
readonly publisher: string;
|
|
23
|
+
/** Every publisher found in the workspace (for the ambiguity message). */
|
|
24
|
+
readonly availablePublishers: string[];
|
|
25
|
+
/** Parsed kanonaks across the full resolution closure. */
|
|
26
|
+
readonly catalog: Kanonak[];
|
|
27
|
+
/** Renderer over `catalog` — the same one `kanonak publish` uses. */
|
|
28
|
+
readonly lookRenderer: LookRenderer;
|
|
29
|
+
/** Namespaces (`publisher/pkg@ver`) of the SERVED publisher's local packages. */
|
|
30
|
+
readonly localNamespaces: Set<string>;
|
|
31
|
+
/** `pkg@ver` → raw `.kan.yml` source (preloaded so `route` stays fs-free). */
|
|
32
|
+
readonly rawByNsKey: Map<string, string>;
|
|
33
|
+
/** `publisher/pkg@ver/name` → subject, for resource lookup. */
|
|
34
|
+
readonly bySubject: Map<string, SubjectKanonak>;
|
|
35
|
+
/** package → versions present, sorted highest-first. */
|
|
36
|
+
readonly pkgVersions: Map<string, PackageVersion[]>;
|
|
37
|
+
/** `pkg@ver` → the package self-resource subject. */
|
|
38
|
+
readonly pkgSelfByVer: Map<string, SubjectKanonak>;
|
|
39
|
+
}
|
|
40
|
+
/** A routed response. `body` is always a string (HTML/CSS/SVG/MD/YAML/JSON). */
|
|
41
|
+
export interface RouteResponse {
|
|
42
|
+
status: number;
|
|
43
|
+
headers: Record<string, string>;
|
|
44
|
+
body: string;
|
|
45
|
+
}
|
|
46
|
+
export interface LoadServerModelOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Which publisher to serve. Required only when the workspace contains more
|
|
49
|
+
* than one publisher; a single-publisher workspace infers it.
|
|
50
|
+
*/
|
|
51
|
+
publisher?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Override the resolution repository. When omitted, the canonical
|
|
54
|
+
* workspace → cache → HTTP stack is built. A provided repository MUST cover
|
|
55
|
+
* the workspace's documents (it supplies the parsed catalog); raw-source
|
|
56
|
+
* serving and publisher scoping still come from the workspace scan.
|
|
57
|
+
*/
|
|
58
|
+
repository?: IKanonakDocumentRepository;
|
|
59
|
+
/** HTTP write-through cache hook for the default stack (e.g. a disk cache). */
|
|
60
|
+
httpCache?: HttpCacheHooks;
|
|
61
|
+
}
|
|
62
|
+
export { SubjectKanonak };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as X,c as ye}from"../chunk-EDINPLEL.js";import{a as Ne}from"../chunk-BHDXQKDP.js";import"../chunk-3NEUHF7E.js";import"../chunk-GR5IXWKN.js";import"../chunk-NIGFQYVA.js";import{a as C,c as Ce,f as Ue}from"../chunk-GYKITV44.js";import{a as Re}from"../chunk-7CUTGGH3.js";import{b as E,c as F,d as f,f as M,l as Oe}from"../chunk-Q4DKP5DO.js";import{e as Le}from"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";var yt="kanonak.org",kt="document-ast",m=t=>({publisher:yt,package_:kt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ie(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=ht(e.metadata,n),a=St(e.children),u=["---",...r,"---","",a].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
4
|
`)),u}};function ht(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let p=r.get(c),y=ue(p??c),h=Me(l.value,l.escapeHint);h!==void 0&&u.push(`${y}: ${h}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Me(t,e){switch(t.kind){case"StringScalar":return bt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Me(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function bt(t,e){return!e||Ie(e,k.ESC_RAW)?t:Ie(e,k.ESC_YAML_SAFE)?wt(t):t}function wt(t){return t.includes(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l}from"../chunk-Q4DKP5DO.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{l as SingleDocumentRepository,f as findSubjectByUri,e as findSubjectsByType,g as getDatatypeValue,j as getEmbeddedValue,k as getListValues,i as getReferenceUri,h as getStringValue,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
|
|
@@ -8,4 +8,4 @@ export { KanonakObjectValidator } from './KanonakObjectValidator.js';
|
|
|
8
8
|
export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
|
|
9
9
|
export type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
|
|
10
10
|
export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule } from './rules/document/index.js';
|
|
11
|
-
export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule } from './rules/repository/index.js';
|
|
11
|
+
export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule } from './rules/repository/index.js';
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-
|
|
1
|
+
import{A,B,C,D,E,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-WDVGQCGC.js";import"../chunk-GYKITV44.js";import"../chunk-7CUTGGH3.js";import"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,D as DisplayLensScopeRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,s as InstancePropertyReferenceRule,E as KanonakObjectValidator,C as MarkdownLinkRule,r as NamespaceImportCycleRule,f as NamespacePrefixRule,x as ObjectPropertyImportRule,y as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,z as PropertyDomainRule,n as PropertyHierarchyCycleRule,w as PropertyRangeReferenceRule,o as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,g as ResourceNamingRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
2
|
+
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
3
|
+
import { OntologyValidationError } from '../../OntologyValidationError.js';
|
|
4
|
+
import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
5
|
+
import type { ValidationCache } from '../../ValidationCache.js';
|
|
6
|
+
/**
|
|
7
|
+
* Validates the display-value lens slots `look.displayLabel` /
|
|
8
|
+
* `look.displaySummary`. Their value names the property that supplies a
|
|
9
|
+
* resource's label/summary, so that property must be IN SCOPE for the
|
|
10
|
+
* declaring resource — its `domain` must be the class (or an ancestor,
|
|
11
|
+
* or rdfs.Resource). A value that resolves to a real property of some
|
|
12
|
+
* OTHER class would silently fall back to the resource's name at render
|
|
13
|
+
* time, which is exactly the kind of quiet failure the lens exists to
|
|
14
|
+
* prevent.
|
|
15
|
+
*
|
|
16
|
+
* Object-model rule: it reads the resolved `displayLabel`/`displaySummary`
|
|
17
|
+
* reference and checks it through the SDK's `resolvePropertyStep` (the
|
|
18
|
+
* same type-directed engine behind completion), rather than re-scanning
|
|
19
|
+
* raw `document.body`. Mirrors `MarkdownLinkRule`'s use of the cache's
|
|
20
|
+
* full-repo parse.
|
|
21
|
+
*/
|
|
22
|
+
export declare class DisplayLensScopeRule implements IRepositoryValidationRule {
|
|
23
|
+
readonly ruleName = "DisplayLensScope";
|
|
24
|
+
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
|
|
25
|
+
private checkLens;
|
|
26
|
+
private scopeError;
|
|
27
|
+
}
|
|
@@ -19,3 +19,4 @@ export { PropertyValueTypeRule } from './PropertyValueTypeRule.js';
|
|
|
19
19
|
export { ClassDefinitionRule } from './ClassDefinitionRule.js';
|
|
20
20
|
export { EmbeddedKanonakTypeRule } from './EmbeddedKanonakTypeRule.js';
|
|
21
21
|
export { MarkdownLinkRule } from './MarkdownLinkRule.js';
|
|
22
|
+
export { DisplayLensScopeRule } from './DisplayLensScopeRule.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.49.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -78,6 +78,10 @@
|
|
|
78
78
|
"types": "./dist/transformations/index.d.ts",
|
|
79
79
|
"default": "./dist/transformations/index.js"
|
|
80
80
|
},
|
|
81
|
+
"./server": {
|
|
82
|
+
"types": "./dist/server/index.d.ts",
|
|
83
|
+
"default": "./dist/server/index.js"
|
|
84
|
+
},
|
|
81
85
|
"./browser": {
|
|
82
86
|
"types": "./dist/browser.d.ts",
|
|
83
87
|
"default": "./dist/browser.js"
|
|
@@ -113,7 +117,7 @@
|
|
|
113
117
|
"yaml-parser"
|
|
114
118
|
],
|
|
115
119
|
"dependencies": {
|
|
116
|
-
"@kanonak-protocol/types": "^3.
|
|
120
|
+
"@kanonak-protocol/types": "^3.49.0",
|
|
117
121
|
"ignore": "^7.0.5",
|
|
118
122
|
"js-yaml": "^4.1.0",
|
|
119
123
|
"yaml": "^2.7.0"
|
package/dist/chunk-2JQMUZWN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as u,c as i,g as m,h as p,i as d,j as f,k as b,l as k}from"./chunk-W6T7MOKY.js";function y(n){return`${n.publisher}/${n.package_}/${n.name}`}function s(n,t){return n.publisher===t.publisher&&n.package_===t.package_&&n.name===t.name}function S(n){let t=n.version;return t&&typeof t.major=="number"?`https://${n.publisher}/${n.package_}/${t.major}.${t.minor}.${t.patch}/${n.name}`:`https://${n.publisher}/${n.package_}/${n.name}`}function l(n,t){if(!(n instanceof u))return!1;for(let e of n.statement)if(e.predicate?.subject?.name==="type"&&e instanceof f){let a=e.object;if(s(a.subject,t))return!0}return!1}function j(n,t){let e=[];for(let r of n)r instanceof i&&l(r,t)&&e.push(r);return e}function K(n,t){let e=t.version,r=e&&typeof e.major=="number"?`${t.publisher}/${t.package_}@${e.major}.${e.minor}.${e.patch}`:void 0;for(let a of n){if(!(a instanceof i)||a.name!==t.name)continue;let c=a.namespace||"";if(r!==void 0){if(c===r)return a}else if(c.startsWith(`${t.publisher}/${t.package_}@`))return a}}function o(n,t){for(let e of n.statement){let r=e.predicate;if(r?.subject&&s(r.subject,t))return e}}function g(n,t){let e=o(n,t);if(e&&(e instanceof m||e instanceof p||e instanceof d))return e.object}function U(n,t){let e=g(n,t);return typeof e=="string"?e:void 0}function h(n,t){let e=o(n,t);if(e instanceof f)return e.object.subject}function $(n,t){let e=o(n,t);if(e instanceof b)return e.object}function x(n,t){let e=o(n,t);return e instanceof k?e.object??[]:[]}export{y as a,s as b,S as c,l as d,j as e,K as f,g,U as h,h as i,$ as j,x as k};
|
package/dist/chunk-4TJZIM7A.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as k}from"./chunk-FUUTGGJS.js";var m=class{resourceResolver;constructor(r){this.resourceResolver=r}async buildFromNameAsync(r,e){return(await this.resourceResolver.resolveEntityAsync(r,e))?.uri??null}buildFromName(r,e,t){if(r.includes(".")){let o=r.split("."),c=o[0],p=o[1],u=this.findPackageNameForAlias(t,c);if(u){for(let l of e.values())if(l.entityName===p&&l.uri.package_===u)return l.uri}return null}let a=e.get(r);return a?a.uri:null}create(r,e,t,a){return new k(r,e,t,a)}findPackageNameForAlias(r,e){if(!r.metadata.imports)return null;for(let[t,a]of Object.entries(r.metadata.imports))for(let o of a)if(o.alias===e||!o.alias&&o.packageName===e)return o.packageName;return null}};function h(n){if(!n||n.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let r=n.trim(),e=r.split("/");if(e.length===1){let t=e[0];if(!t)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(t.includes("@"))throw new Error(`Invalid Kanonak address: "${n}". 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: "${n}". Expected publisher/package[@version].`);let o=a.indexOf("@");if(o===-1)return{kind:"package",publisher:t,package_:a};let c=a.substring(0,o),p=a.substring(o+1);if(!c||!p)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let u=K(p);return{kind:"package",publisher:t,package_:c,version:u}}return{kind:"resource",uri:k.parse(r)}}function R(n){switch(n.kind){case"publisher":return n.publisher;case"package":return n.version?`${n.publisher}/${n.package_}@${n.version.major}.${n.version.minor}.${n.version.patch}`:`${n.publisher}/${n.package_}`;case"resource":return n.uri.toString()}}function K(n){let r=n.split(".").map(Number);return _(r[0]||0,r[1]||0,r[2]||0)}function _(n,r,e){return{major:n,minor:r,patch:e,toString:()=>`${n}.${r}.${e}`,equals:t=>!t||typeof t!="object"?!1:t.major===n&&t.minor===r&&t.patch===e,getHashCode:()=>n<<20|r<<10|e,compareTo:t=>n!==t.major?n-t.major:r!==t.minor?r-t.minor:e-t.patch}}var v=new Set(["kanonak.org/core-rdf","kanonak.org/core-rdfs","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]),b={Class:{publisher:"kanonak.org",package_:"core-owl"},ObjectProperty:{publisher:"kanonak.org",package_:"core-owl"},DatatypeProperty:{publisher:"kanonak.org",package_:"core-owl"},AnnotationProperty:{publisher:"kanonak.org",package_:"core-owl"},Property:{publisher:"kanonak.org",package_:"core-rdf"},Datatype:{publisher:"kanonak.org",package_:"core-rdfs"},Resource:{publisher:"kanonak.org",package_:"core-rdfs"},Literal:{publisher:"kanonak.org",package_:"core-rdfs"},Thing:{publisher:"kanonak.org",package_:"core-owl"},Nothing:{publisher:"kanonak.org",package_:"core-owl"}};function s(n){let r=n;if(r.entity&&typeof r.entity=="object"){let e=r.entity.type;if(typeof e=="string"){let t=b[e];return t?{publisher:t.publisher,package_:t.package_,name:e}:{publisher:"",package_:"",name:e}}}if(r.statement&&Array.isArray(r.statement)){for(let e of r.statement)if(e.predicate?.subject?.name==="type"&&e.object?.subject){let t=e.object.subject;if(!t.publisher&&!t.package_||t.publisher===""&&t.package_===""){let a=b[t.name];if(a)return{publisher:a.publisher,package_:a.package_,name:t.name}}return t}}return null}function i(n,r){return v.has(`${n}/${r}`)}var y=class n{static getTypeUri(r){return s(r)}static isCoreOntologyType(r){return i(r.publisher,r.package_)}static isClassType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="Class":!1}static isDatatypeType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="Datatype":!1}static isDatatypePropertyType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="DatatypeProperty":!1}static isObjectPropertyType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="ObjectProperty":!1}static isAnnotationPropertyType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="AnnotationProperty":!1}static isGenericPropertyType(r){let e=s(r);return e?i(e.publisher,e.package_)&&e.name==="Property":!1}static isAnyPropertyType(r){let e=s(r);return!e||!i(e.publisher,e.package_)?!1:e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"}static isSchemaDefinitionType(r){let e=s(r);return!e||!i(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(r,e){if(n.isSchemaDefinitionType(r))return!1;let t=s(r);return t?e.has(t.name):!1}};async function j(n,r){let e=[],t=await n.getAllDocumentsAsync();for(let a of t){let o=a.metadata.namespace_;if(!o)continue;let c=o.publisher,p=o.package_,u=o.version?`${o.version.major}.${o.version.minor}.${o.version.patch}`:"0.0.0";for(let[l,g]of Object.entries(a.body)){if(!g||typeof g!="object")continue;let f=g.type;!f||typeof f!="string"||f!=="Package"&&P(f,r)&&e.push({entityName:l,entity:g,documentNamespace:`${c}/${p}@${u}`,publisher:c,package_:p,version:u})}}return e}function P(n,r){let e=d(n),t=d(r);return e===t}function d(n){let r=n.lastIndexOf(".");if(r!==-1)return n.substring(r+1);let e=n.lastIndexOf("/");return e!==-1?n.substring(e+1):n}export{y as a,m as b,h as c,R as d,j as e};
|
package/dist/chunk-5AH6GIPO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as f}from"./chunk-7CUTGGH3.js";import{a as g,b as D,f as P,g as w}from"./chunk-FQHALFRR.js";import*as c from"fs/promises";import*as i from"path";import{pathToFileURL as v}from"url";var l=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(t,e=!0,n){if(!t||t.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=i.resolve(t),this.recursive=e,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let t=new Set(this.documentCache.values());return Array.from(t)}async getDocumentAsync(t){await this.ensureCacheInitialized();let e=this.documentCache.get(t);if(e)return e;let n=i.join(this.rootPath,t);if(e=this.documentCache.get(n),e)return e;for(let a of[".kan.yml",".yml",".yaml"])if(!t.endsWith(a)){let s=t+a;if(e=this.documentCache.get(s),e)return e;let o=i.join(this.rootPath,s);if(e=this.documentCache.get(o),e)return e}return null}async getDocumentsByNamespaceAsync(t,e){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(a=>a.metadata.namespace_?.publisher===t&&a.metadata.namespace_?.package_===e)}async getHighestCompatibleVersionAsync(t,e){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),a=Array.from(n).filter(o=>o.metadata?.namespace_?.publisher===t&&o.metadata?.namespace_?.package_===e.packageName&&o.metadata?.namespace_?.version!==void 0);if(a.length===0)return null;let s=a.filter(o=>{let r=o.metadata.namespace_.version;switch(e.versionOperator){case 0:return D(r,e.version);case 1:return P(r,e.version);case 2:return w(r,e.version);case 3:return g(r,e.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((o,r)=>{let m=o.metadata.namespace_.version,u=r.metadata.namespace_.version;return g(u,m)}),s[0])}async saveDocumentAsync(t,e){let n,a=t.metadata.namespace_?.toString();if(a&&a.includes("@")&&a.includes("/")){let m=a.split("/"),u=m[0],I=m[1].replace("@","@")+".kan.yml";n=i.join(this.rootPath,u,I)}else n=i.join(this.rootPath,e),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=i.dirname(n);await c.mkdir(s,{recursive:!0});let o=this.parser.save(t);await c.writeFile(n,o,"utf8"),a&&this.documentCache.set(a,t),this.documentCache.set(n,t);let r=i.relative(this.rootPath,n);this.documentCache.set(r,t)}async deleteDocumentAsync(t){let e=await this.getDocumentAsync(t);if(!e)return;let n=this.filePathsByIdentifier.get(t);if(!n)return;try{await c.unlink(n)}catch{}let a=e.metadata.namespace_?.toString();a&&this.documentCache.delete(a),this.documentCache.delete(t),this.documentCache.delete(n);let s=i.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(t,e){await this.ensureCacheInitialized();let n=[];for(let[s,o]of this.documentCache.entries()){let r=o.metadata.namespace_?.toString()||"";r.includes(t)&&r.includes(e)&&n.push([s,o])}let a=i.join(this.rootPath,t);try{let s=await c.readdir(a);for(let o of s)o.includes(e)&&o.endsWith(".kan.yml")&&await c.unlink(i.join(a,o))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let t=new Set(this.filePathsByIdentifier.values()),e=[];for(let n of t){let a=v(n).toString(),s;for(let[m,u]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&u.metadata.namespace_){s=u.metadata.namespace_.toString();break}let o=s??i.relative(this.rootPath,n),r=this.parsingErrors.has(n);e.push({identifier:o,uri:a,hasParseError:r})}return e}async getDocumentContentAsync(t){await this.ensureCacheInitialized();let e=this.filePathsByIdentifier.get(t);if(!e)try{await c.access(t),e=t}catch{let n=i.join(this.rootPath,t);try{await c.access(n),e=n}catch{return null}}try{return await c.readFile(e,"utf8")}catch{return null}}async getDocumentUriAsync(t){await this.ensureCacheInitialized();let e=this.filePathsByIdentifier.get(t);if(!e)try{await c.access(t),e=t}catch{let n=i.join(this.rootPath,t);try{await c.access(n),e=n}catch{return null}}return v(e).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await c.mkdir(this.rootPath,{recursive:!0})}catch{}let e=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async a=>{try{let s=await c.readFile(a,"utf8"),o=this.parser.parse(s);return{filePath:a,document:o,error:null}}catch(s){return{filePath:a,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(e);for(let{filePath:a,document:s,error:o}of n){let r=i.relative(this.rootPath,a);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(a,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,a),this.filePathsByIdentifier.set(a,a),this.filePathsByIdentifier.set(r,a)}else this.filePathsByIdentifier.set(a,a),this.filePathsByIdentifier.set(r,a);o&&this.parsingErrors.set(a,o)}}async findYamlFiles(t,e){let n=[];try{let a=await c.readdir(t,{withFileTypes:!0});for(let s of a){let o=i.join(t,s.name);if(s.isDirectory()&&e){let r=await this.findYamlFiles(o,e);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(o)}}catch{}return n}};import*as p from"fs";var A=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(A||{}),y=class{cache;workspace;constructor(t,e,n){let a=n??new f;p.existsSync(t)||p.mkdirSync(t,{recursive:!0}),p.existsSync(e)||p.mkdirSync(e,{recursive:!0}),this.cache=new l(t,!0,a),this.workspace=new l(e,!0,a)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let t=await this.workspace.getAllDocumentsAsync(),e=await this.cache.getAllDocumentsAsync(),n=new Map;for(let a of e)if(a.metadata.namespace_){let s=a.metadata.namespace_.toString();n.set(s,a)}for(let a of t)if(a.metadata.namespace_){let s=a.metadata.namespace_.toString();n.set(s,a)}return Array.from(n.values())}async getDocumentAsync(t){let e=await this.workspace.getDocumentAsync(t);return e||await this.cache.getDocumentAsync(t)}async getDocumentsByNamespaceAsync(t,e){let n=await this.workspace.getDocumentsByNamespaceAsync(t,e),a=await this.cache.getDocumentsByNamespaceAsync(t,e),s=new Map;for(let o of a)if(o.metadata.namespace_?.version){let r=o.metadata.namespace_.version.toString();s.set(r,o)}for(let o of n)if(o.metadata.namespace_?.version){let r=o.metadata.namespace_.version.toString();s.set(r,o)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(t,e){let n=await this.workspace.getHighestCompatibleVersionAsync(t,e);return n||await this.cache.getHighestCompatibleVersionAsync(t,e)}async saveDocumentAsync(t,e){await this.workspace.saveDocumentAsync(t,e)}async saveToCacheAsync(t,e){await this.cache.saveDocumentAsync(t,e)}async deleteDocumentAsync(t){await this.workspace.deleteDocumentAsync(t)}async clearNamespaceAsync(t,e){await this.workspace.clearNamespaceAsync(t,e)}async getAllDocumentReferencesAsync(){let t=await this.workspace.getAllDocumentReferencesAsync(),e=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...t),n.push(...e),n}async getDocumentContentAsync(t){let e=await this.workspace.getDocumentContentAsync(t);return e||await this.cache.getDocumentContentAsync(t)}async getDocumentUriAsync(t){let e=await this.workspace.getDocumentUriAsync(t);return e||await this.cache.getDocumentUriAsync(t)}async getDocumentLocationAsync(t){return await this.workspace.getDocumentAsync(t)?"Workspace":await this.cache.getDocumentAsync(t)?"Cache":"NotFound"}};import{homedir as K}from"os";import{join as R}from"path";function d(){let h=process.env.KANONAK_PACKAGE_CACHE;return h||R(K(),".kanonak","packages")}var k=class h{static createComposite(t,e,n){let a=t??d(),s=e??".";return new y(a,s,n)}static createFromEnvironment(t){let e=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return h.createComposite(e,n,t)}};export{l as a,A as b,y as c,d,k as e};
|
package/dist/chunk-FJ35VIV6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var o=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{o as a};
|
package/dist/chunk-FMYLEPMC.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as M,b as T,c as w,d,g,h as P,i as S,j as D,k as K,l as j}from"./chunk-W6T7MOKY.js";import{a as I}from"./chunk-7CUTGGH3.js";import{b as x,c as A}from"./chunk-HEMBMX7T.js";var k=class extends T{name};var h=class extends M{value};var R=class extends g{links=[]};var N=/\[\[([^\[\]\n]+)\]\]/g,V=/\[\[/g,E=/```[\s\S]*?```|`[^`\n]*`/g;function _(u){let e=[];for(let t of u.matchAll(E))e.push([t.index,t.index+t[0].length]);return e}function q(u){if(!u||!u.includes("[["))return[];let e=_(u),t=o=>e.some(([n,a])=>o>=n&&o<a),s=new Set(O(u).map(o=>o.startOffset)),r=[];for(let o of u.matchAll(V)){let n=o.index;if(t(n)||s.has(n))continue;let a=u.slice(n,n+48).replace(/\s+/g," ").trim();r.push({startOffset:n,snippet:a})}return r}function O(u){if(!u||!u.includes("[["))return[];let e=[];for(let r of u.matchAll(E))e.push([r.index,r.index+r[0].length]);let t=r=>e.some(([o,n])=>r>=o&&r<n),s=[];for(let r of u.matchAll(N)){let o=r.index;if(t(o))continue;let n=r[1],a=n.indexOf("|"),i=(a===-1?n:n.slice(0,a)).trim();if(i.length===0)continue;let p=a===-1?"":n.slice(a+1).trim(),c={reference:i,startOffset:o,endOffset:o+r[0].length};p.length>0&&(c.displayText=p),s.push(c)}return s}var v=class{constructor(e){}async parseKanonaks(e){let t=[],s=await e.getAllDocumentsAsync(),r=new x(e),o=new A(r);for(let i of s){let p=i.metadata.namespace_?.toString()??"";for(let[c,m]of Object.entries(i.body)){let f=new w,l=this.resolveCanonicalEntity(c,i,p);f.namespace=l.namespace,f.name=l.name,f.statement=[];let y=await this.parseStatements(m,i,r,o,e);f.statement.push(...y),t.push(f)}}let n=new Map,a=[];for(let i of t)if(i instanceof w){let p=`${i.namespace}/${i.name}`,c=n.get(p);c?c.statement.push(...i.statement):(n.set(p,i),a.push(i))}else a.push(i);return a}resolveCanonicalEntity(e,t,s){if(!e.includes(".")||!t.metadata?.imports)return{namespace:s,name:e};let r=e.indexOf("."),o=e.substring(0,r),n=e.substring(r+1);for(let[a,i]of Object.entries(t.metadata.imports))for(let p of i)if((p.alias??p.packageName)===o){let m=p.version;return{namespace:`${a}/${p.packageName}@${m.major}.${m.minor}.${m.patch}`,name:n}}return{namespace:s,name:e}}async parseStatements(e,t,s,r,o){let n=[];if(typeof e!="object"||e===null||Array.isArray(e))return n;for(let[a,i]of Object.entries(e))try{let p=await this.getPropertyMetadata(a,t,s,o,r);if(!p)continue;let c=await this.parsePropertyValue(a,i,p,t,s,r);c&&n.push(c)}catch(p){console.error(`Error parsing property ${a}:`,p)}return n}async getPropertyMetadata(e,t,s,r,o){let n=await s.resolveEntityAsync(e,t);if(!n)return;let a=n.entity,i=a.type?.toString()??"",p=i.includes(".")?i.substring(i.lastIndexOf(".")+1):i;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(p))return;let m=o.getPropertyTypeClassification(i),f=a.range?.toString(),l;if(m==="ObjectProperty")l="ObjectProperty";else if(m==="DatatypeProperty")l="DatatypeProperty";else{let b=f&&f.includes(".")?f.substring(f.lastIndexOf(".")+1):f??"";(f?o.isKnownXsdDatatypeName(f):!1)||b==="Literal"?l="DatatypeProperty":l="ObjectProperty"}let y;return f&&(y=(await s.resolveEntityAsync(f,t))?.uri),{propertyUri:n.uri.toString(),propertyType:l,range:f,rangeUri:y,isImported:n.isImported,definedInNamespace:n.definedInNamespace}}async parsePropertyValue(e,t,s,r,o,n){let a=s.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(a,t,s,r,o,n);if(s.propertyType==="DatatypeProperty")return this.parseDatatypeValue(a,t,s,r,o,n);if(s.propertyType==="ObjectProperty")return this.parseObjectValue(a,t,s,r,o,n)}}async parseDatatypeValue(e,t,s,r,o,n){if(t instanceof Date)return g.parse(e,t.toISOString());if(typeof t=="string")return n.isSubstitutableDatatype(s.rangeUri)?await this.parseSubstitutableValue(e,t,r,o):g.parse(e,t);if(typeof t=="number")return P.parse(e,t);if(typeof t=="boolean"){let a=new S;return a.predicate=d.parse(e),a.object=t,a}}async parseSubstitutableValue(e,t,s,r){let o=new R;o.predicate=d.parse(e),o.object=t;for(let n of O(t)){let a=await r.resolveEntityAsync(n.reference,s),i;a&&(i=new d,i.subject=a.uri);let p={reference:n.reference,startOffset:n.startOffset,endOffset:n.endOffset};n.displayText!==void 0&&(p.displayText=n.displayText),i!==void 0&&(p.target=i),o.links.push(p)}return o}async parseObjectValue(e,t,s,r,o,n){if(typeof t=="string"){let a=await this.resolveReference(t,r,o);if(!a)return;let i=new D;return i.predicate=d.parse(e),i.object=a,i}if(typeof t=="object"&&!Array.isArray(t)){let a=new k;if(a.statement=await this.parseStatements(t,r,o,n,{}),a.statement.length>0){let c=new K;return c.predicate=d.parse(e),c.object=a,c}let i=[];for(let[c,m]of Object.entries(t))if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=new k;f.name=c,f.statement=await this.parseStatements(m,r,o,n,{}),i.push(f)}else if(typeof m=="string"){let f=await this.resolveReference(m,r,o);f&&i.push(f)}if(i.length>0){let c=new j;return c.predicate=d.parse(e),c.object=i,c}let p=new K;return p.predicate=d.parse(e),p.object=a,p}}async parseListValue(e,t,s,r,o,n){let a=[],i=s.propertyType==="DatatypeProperty";for(let c of t){if(i&&(typeof c=="string"||typeof c=="number"||typeof c=="boolean")){let m=new h;m.value=c,a.push(m);continue}if(i&&c instanceof Date){let m=new h;m.value=c.toISOString(),a.push(m);continue}if(typeof c=="string"){let m=await this.resolveReference(c,r,o);m&&a.push(m)}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let m=new k;m.statement=await this.parseStatements(c,r,o,n,{}),a.push(m)}}let p=new j;return p.predicate=d.parse(e),p.object=a,p}async resolveReference(e,t,s){let r=await s.resolveEntityAsync(e,t);if(r){let n=new d;return n.subject=r.uri,n}let o=t.metadata?.namespace_;if(o){let{KanonakUri:n}=await import("./KanonakUri-4VJGV3FN.js"),a=o.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let p=e.indexOf("."),c=e.substring(0,p),m=e.substring(p+1);if(t.metadata?.imports){for(let[f,l]of Object.entries(t.metadata.imports))for(let y of l)if((y.alias??y.packageName)===c){let b=new d;return b.subject=new n(f,y.packageName,m,y.version),b}}}let i=new d;return i.subject=new n(o.publisher,o.package_,e,a),i}return null}async saveKanonaks(e,t){let s=new Map;for(let r of e)r instanceof w&&r.namespace&&(s.has(r.namespace)||s.set(r.namespace,[]),s.get(r.namespace).push(r));for(let[r,o]of s){let n=await this.convertKanonaksToDocument(r,o),a=`${r.split("@")[0]}.yml`;await t.saveDocumentAsync(n,a)}}async serializeToYaml(e,t){let s=e.filter(n=>n instanceof w&&n.namespace===t);if(s.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let r=await this.convertKanonaksToDocument(t,s);return new I().save(r)}async convertKanonaksToDocument(e,t){let r={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let n=[];for(let a of Object.values(this.imports))n.push(...a);return n}},body:{}},o=new Map;for(let n of t){let a={};for(let i of n.statement){let[p,c]=this.convertStatementToProperty(i);p&&c!==null&&c!==void 0&&(a[p]=c),this.collectImportsFromStatement(i,e,o)}r.body[n.name]=a}return r}convertStatementToProperty(e){if(e instanceof g)return[e.predicate.subject.name,e.object];if(e instanceof P)return[e.predicate.subject.name,e.object];if(e instanceof S)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof K){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let s of e)s instanceof d?t.push(s.subject.name):s instanceof k&&t.push(this.convertEmbeddedKanonakToValue(s));return t}convertEmbeddedKanonakToValue(e){let t={};for(let s of e.statement){let[r,o]=this.convertStatementToProperty(s);r&&o!==null&&o!==void 0&&(t[r]=o)}return t}collectImportsFromStatement(e,t,s){}};export{k as a,h as b,R as c,q as d,O as e,v as f};
|
package/dist/chunk-HEMBMX7T.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as k}from"./chunk-FUUTGGJS.js";function R(d){if(Array.isArray(d))return d.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=d?.toString();return e?[e]:[]}var A=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let s=t.metadata?.namespace_?.toString()??"unknown",n=this.cache.get(s);if(n){let a=n.get(e);if(a)return a}let r=await this.buildEntityIndexAsyncInternal(t,new Set,"");return this.cache.set(s,r),r.get(e)??null}async resolveAllEntitiesAsync(e,t){let s=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let n=e.split("."),r=n[0],a=n[1],c=await this.findDocumentForAlias(t,r);return c?await this.resolveAllEntitiesAsync(a,c):[]}return s.filter(n=>n.entityName===e)}async buildAllEntitiesIndexAsync(e,t,s){let n=[],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)`),n;t.add(r);let a=s.length===0?r:`${s} \u2192 ${r}`;for(let[c,o]of Object.entries(e.body))if(!c.includes(".")&&o&&typeof o=="object"&&!Array.isArray(o)){let i=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.push({entityName:c,uri:new k(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,c,i),entity:o,definedInNamespace:r,isImported:s.length>0,importPath:a})}if(this.logger?.debug?.(`Collected ${n.length} entities from ${r}`),e.metadata?.imports){let c=Object.values(e.metadata.imports).reduce((o,i)=>o+i.length,0);this.logger?.debug?.(`Processing ${c} import(s) for ${r}`);for(let[o,i]of Object.entries(e.metadata.imports))for(let g of i)try{this.logger?.debug?.(`Resolving import: ${o}/${g.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(o,g);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let u=await this.buildAllEntitiesIndexAsync(l,t,a);n.push(...u),this.logger?.debug?.(`Added ${u.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${o}/${g.packageName}`)}catch(l){let u=l;throw this.logger?.error?.(`Failed to process import ${o}/${g.packageName} for namespace ${r}. Error: ${u.message}`,u),new Error(`Failed to process import ${o}/${g.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return n}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,t,s){let n=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),n;t.add(r);let a=s.length===0?r:`${s} \u2192 ${r}`,c=0;for(let[o,i]of Object.entries(e.body))if(!o.includes(".")&&i&&typeof i=="object"&&!Array.isArray(i)&&!n.has(o)){let g=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.set(o,{entityName:o,uri:new k(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,o,g),entity:i,definedInNamespace:r,isImported:s.length>0,importPath:a}),c++}if(this.logger?.debug?.(`Indexed ${c} entities from ${r}`),e.metadata?.imports){let o=Object.values(e.metadata.imports).reduce((i,g)=>i+g.length,0);this.logger?.debug?.(`Processing ${o} import(s) for ${r}`);for(let[i,g]of Object.entries(e.metadata.imports))for(let l of g)try{this.logger?.debug?.(`Resolving import: ${i}/${l.packageName}`);let u=await this.repository.getHighestCompatibleVersionAsync(i,l);if(u){this.logger?.debug?.(`Successfully loaded import: ${u.metadata?.namespace_?.toString()}`);let h=await this.buildEntityIndexAsyncInternal(u,t,a),b=0;for(let[y,m]of h.entries()){let p=n.get(y);if(!p)n.set(y,m),b++;else if(p.isImported&&m.isImported&&(p.uri.publisher!==m.uri.publisher||p.uri.package_!==m.uri.package_)){let f=p.isAmbiguous?p:{...p,isAmbiguous:!0,ambiguousNamespaces:[p.definedInNamespace]};f.ambiguousNamespaces.includes(m.definedInNamespace)||f.ambiguousNamespaces.push(m.definedInNamespace),n.set(y,f),this.logger?.warn?.(`Ambiguous reference '${y}': defined in ${f.ambiguousNamespaces.join(", ")}`)}if(l.alias&&!y.includes(".")){let f=`${l.alias}.${y}`;n.has(f)||(n.set(f,m),b++)}}this.logger?.debug?.(`Merged ${b} entities from import ${u.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${i}/${l.packageName}`)}catch(u){let h=u;throw this.logger?.error?.(`Failed to process import ${i}/${l.packageName} for namespace ${r}. Error: ${h.message}`,h),new Error(`Failed to process import ${i}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:u})}}return n}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[s,n]of Object.entries(e.metadata.imports))for(let r of n){if(r.alias===t)return await this.repository.getHighestCompatibleVersionAsync(s,r);if(!r.alias&&r.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(s,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,s){if(e===t)return!0;let n=new Set;return await this.isSubclassOfRecursiveAsync(e,t,s,n)}async isSubclassOfRecursiveAsync(e,t,s,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,s);if(!r?.entity)return!1;let a=r.entity.subClassOf;if(a){let c=R(a);for(let o of c)if(o===t||await this.isSubclassOfRecursiveAsync(o,t,s,n))return!0}return!1}async isSubpropertyOfAsync(e,t,s){if(e===t)return!0;let n=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,s,n)}async isSubpropertyOfRecursiveAsync(e,t,s,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,s);if(!r?.entity)return!1;let a=r.entity.subPropertyOf;if(a){let c=R(a);for(let o of c)if(o===t||await this.isSubpropertyOfRecursiveAsync(o,t,s,n))return!0}return!1}};var w=class d{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","bool","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"&&d.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 d.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let s=await this.resourceResolver.resolveEntityAsync(e,t);if(s){let n=s.entity.type;if(n){let r=String(n);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))}};export{R as a,A as b,w as c};
|
package/dist/chunk-IOJMTW4T.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as S,b as j,f as w}from"./chunk-FMYLEPMC.js";import{c as x,d as g,g as T,h as I,i as v,j as $,k as q,l as L}from"./chunk-W6T7MOKY.js";function u(t){return`${t.publisher}/${t.package_}/${t.name}`}function c(t,e,r){return`${t}/${e}/${r}`}function k(t){return`${t.s}|${t.p}|${P(t.o)}`}function P(t){switch(t.kind){case"uri":return`u:${t.key}`;case"literal":return`l:${t.datatype}:${t.lexical}`;case"blank":return`b:${t.id}`}}function s(t,e,r){return{s:t,p:e,o:{kind:"uri",key:r}}}var y=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let r=k(e);return this.all.has(r)?!1:(this.all.add(r),this.tripleList.push(e),h(this.byPIdx,e.p,e),h(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&h(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(k(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let r=this.byPIdx.get(e);return r?r.slice():[]}bySubjectPredicate(e,r){let o=this.bySPIdx.get(`${e}|${r}`);return o?o.slice():[]}byPredicateObject(e,r){let o=this.byPOIdx.get(`${e}|${r}`);return o?o.slice():[]}subjectsWithPredicateObject(e,r){let o=this.byPOIdx.get(`${e}|${r}`);if(!o)return[];let i=new Set;for(let a of o)i.add(a.s);return Array.from(i)}uriObjectsOf(e,r){let o=this.bySPIdx.get(`${e}|${r}`);if(!o)return[];let i=new Set;for(let a of o)a.o.kind==="uri"&&i.add(a.o.key);return Array.from(i)}hasUri(e,r,o){return this.all.has(`${e}|${r}|u:${o}`)}hasTriple(e,r,o){return this.all.has(`${e}|${r}|${P(o)}`)}};function h(t,e,r){let o=t.get(e);o?o.push(r):t.set(e,[r])}var d=class{type=c("kanonak.org","core-rdf","type");subClassOf=c("kanonak.org","core-rdf","subClassOf");subPropertyOf=c("kanonak.org","core-rdf","subPropertyOf");domain=c("kanonak.org","core-rdf","domain");range=c("kanonak.org","core-rdf","range");equivalentClass=c("kanonak.org","core-owl","equivalentClass");equivalentProperty=c("kanonak.org","core-owl","equivalentProperty");inverseOf=c("kanonak.org","core-owl","inverseOf");sameAs=c("kanonak.org","core-owl","sameAs");transitiveProperty=c("kanonak.org","core-owl","TransitiveProperty");symmetricProperty=c("kanonak.org","core-owl","SymmetricProperty")};var _={name:"rdfs2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.domain)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},E={name:"rdfs3",apply(t,e){let r=!1;for(let o of t.byPredicate(e.range)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))n.o.kind==="uri"&&t.add(s(n.o.key,e.type,a))&&(r=!0)}return r}},A={name:"rdfs5",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subPropertyOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.bySubjectPredicate(a,e.subPropertyOf))n.o.kind==="uri"&&t.add(s(i,e.subPropertyOf,n.o.key))&&(r=!0)}return r}},V={name:"rdfs7",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subPropertyOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(i)){let p={s:n.s,p:a,o:n.o};t.add(p)&&(r=!0)}}return r}},W={name:"rdfs9",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subClassOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},F={name:"rdfs11",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subClassOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.bySubjectPredicate(a,e.subClassOf))n.o.kind==="uri"&&t.add(s(i,e.subClassOf,n.o.key))&&(r=!0)}return r}},K=[_,E,A,V,W,F];var N={name:"prp-trp",apply(t,e){let r=!1,o=t.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let i of o){let a=t.byPredicate(i);for(let n of a){if(n.o.kind!=="uri")continue;let p=n.o.key;for(let l of t.bySubjectPredicate(p,i))l.o.kind==="uri"&&n.s!==l.o.key&&t.add(s(n.s,i,l.o.key))&&(r=!0)}}return r}},D={name:"prp-symp",apply(t,e){let r=!1,o=t.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let i of o)for(let a of t.byPredicate(i))a.o.kind==="uri"&&t.add(s(a.o.key,i,a.s))&&(r=!0);return r}},M={name:"prp-inv1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.inverseOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))n.o.kind==="uri"&&t.add(s(n.o.key,a,n.s))&&(r=!0)}return r}},z={name:"prp-inv2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.inverseOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(a))n.o.kind==="uri"&&t.add(s(n.o.key,i,n.s))&&(r=!0)}return r}},B={name:"prp-eqp1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentProperty)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(i))t.add({s:n.s,p:a,o:n.o})&&(r=!0)}return r}},G={name:"prp-eqp2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentProperty)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(a))t.add({s:n.s,p:i,o:n.o})&&(r=!0)}return r}},H={name:"cax-eqc1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentClass)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},J={name:"cax-eqc2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentClass)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,a))t.add(s(n.s,e.type,i))&&(r=!0)}return r}},Q={name:"eq-rep-s",apply(t,e){let r=!1;for(let o of t.byPredicate(e.sameAs)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a){for(let n of t.snapshot())n.s===i&&t.add({s:a,p:n.p,o:n.o})&&(r=!0);for(let n of t.snapshot())n.s===a&&t.add({s:i,p:n.p,o:n.o})&&(r=!0)}}return r}},X={name:"eq-rep-o",apply(t,e){let r=!1;for(let o of t.byPredicate(e.sameAs)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.snapshot())n.o.kind==="uri"&&(n.o.key===i?t.add(s(n.s,n.p,a))&&(r=!0):n.o.key===a&&t.add(s(n.s,n.p,i))&&(r=!0))}return r}},U=[N,D,M,z,B,G,H,J,Q,X];var m=class{constructor(e,r){this.store=e;this.vocabulary=r}store;vocabulary;getInstancesOfClass(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,r)}getSubclasses(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,r).filter(i=>i!==r)}getSuperclasses(e){let r=f(e);return this.store.uriObjectsOf(r,this.vocabulary.subClassOf).filter(o=>o!==r)}getTypesOfIndividual(e){return this.store.uriObjectsOf(f(e),this.vocabulary.type)}isInstanceOf(e,r){return this.store.hasUri(f(e),this.vocabulary.type,f(r))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function f(t){return typeof t=="string"?t:c(t.publisher,t.package_,t.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new d,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let r=new y,i=await new w().parseKanonaks(e),a=new O;for(let l of i)if(l instanceof x){let b=Y(l);if(!b)continue;for(let C of l.statement)this.emitStatement(b,C,r,a)}let n=[...K];this.profile==="owl-rl-classification"&&n.push(...U);let p=0;for(;p<this.maxIterations;){let l=!1;for(let b of n)b.apply(r,this.vocabulary)&&(l=!0);if(!l)break;p++}return new m(r,this.vocabulary)}emitStatement(e,r,o,i){let a=Z(r);if(a){if(r instanceof T){o.add({s:e,p:a,o:{kind:"literal",lexical:r.object,datatype:"string"}});return}if(r instanceof I){o.add({s:e,p:a,o:{kind:"literal",lexical:String(r.object),datatype:"number"}});return}if(r instanceof v){o.add({s:e,p:a,o:{kind:"literal",lexical:String(r.object),datatype:"boolean"}});return}if(r instanceof $){let n=u(r.object.subject);o.add(s(e,a,n));return}if(r instanceof q){let n=i.next();o.add({s:e,p:a,o:{kind:"blank",id:n}}),this.emitEmbedded(n,r.object,o,i);return}if(r instanceof L){for(let n of r.object??[])this.emitListItem(e,a,n,o,i);return}}}emitListItem(e,r,o,i,a){if(o instanceof g)i.add(s(e,r,u(o.subject)));else if(o instanceof S){let n=a.next();i.add({s:e,p:r,o:{kind:"blank",id:n}}),this.emitEmbedded(n,o,i,a)}else if(o instanceof j){let n=typeof o.value=="number"?"number":typeof o.value=="boolean"?"boolean":"string";i.add({s:e,p:r,o:{kind:"literal",lexical:String(o.value),datatype:n}})}}emitEmbedded(e,r,o,i){let a=`_:${e}`;for(let n of r.statement)this.emitStatement(a,n,o,i)}},O=class{counter=0;next(){return`b${this.counter++}`}};function Y(t){let e=t.namespace??"",r=e.indexOf("@"),o=r===-1?e:e.substring(0,r),i=o.indexOf("/");if(i===-1)return null;let a=o.substring(0,i),n=o.substring(i+1);return!a||!n||!t.name?null:c(a,n,t.name)}function Z(t){let e=t.predicate;return e?.subject?u(e.subject):null}export{u as a,c as b,k as c,s as d,y as e,d as f,K as g,U as h,m as i,R as j};
|
package/dist/chunk-JGVDV6PM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as g}from"./chunk-FMYLEPMC.js";import{c as l,d as u,g as v,j as p,k as h,l as d}from"./chunk-W6T7MOKY.js";import{a as K,e as b}from"./chunk-FQHALFRR.js";function pe(t,n,e,i){let r=S(t);if(r.length>0){let s=j(r,n,e);return s?{transformation:s.transformation,source:"instance"}:void 0}let a=new Set,o=I(t);for(;o.length>0;){let s=o.shift(),c=x(s.subject);if(a.has(c))continue;a.add(c);let m=R(i,s.subject);if(!m)continue;let _=S(m),D=j(_,n,e);if(D)return{transformation:D.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let U of L(m))o.push(U)}let f={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!a.has(x(f))){let s=R(i,f);if(s){let c=S(s),m=j(c,n,e);if(m)return{transformation:m.transformation,source:f}}}}function S(t){let n=[];for(let e of t.statement)if(e instanceof d&&k(e,"kanonak.org","derivation","derivations"))for(let i of e.object??[]){if(!(i instanceof g))continue;let r=T(i);r&&n.push(r)}return n}function j(t,n,e){let i=t.filter(o=>E(o.format,n)&&E(o.variant,e));if(i.length<=1)return i[0];let r=i[0].transformation,a=i[0];for(let o of i){let f=o.transformation;if(f.publisher!==r.publisher||f.package_!==r.package_||f.name!==r.name)continue;let s=b(a.transformation.version),c=b(f.version);s&&c&&K(c,s)>0&&(a=o)}return a}function T(t){let n,e,i;for(let r of t.statement)r instanceof p?k(r,"kanonak.org","derivation","format")?n=y(r):k(r,"kanonak.org","derivation","variant")&&(e=y(r)):r instanceof h&&k(r,"kanonak.org","derivation","transformation")&&(i=P(r.object));if(!(!n||!i))return e||(e={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:n,variant:e,transformation:i}}function P(t){let n,e,i,r;for(let a of t.statement){if(!(a instanceof v))continue;let o=a.predicate?.subject?.name;o==="publisher"?n=a.object:o==="package"?e=a.object:o==="version"?i=a.object:o==="name"&&(r=a.object)}if(!(!n||!e||!i||!r))return{publisher:n,package_:e,version:i,name:r}}function I(t){let n=[];for(let e of t.statement)e instanceof p&&e.predicate?.subject?.name==="type"&&e.object instanceof u&&n.push(e.object);return n}function L(t){let n=[];for(let e of t.statement)if(e instanceof p){if(e.predicate?.subject?.name!=="subClassOf")continue;e.object instanceof u&&n.push(e.object)}else if(e instanceof d){if(e.predicate?.subject?.name!=="subClassOf")continue;for(let i of e.object??[])i instanceof u&&n.push(i)}return n}function R(t,n){for(let e of t){if(!(e instanceof l)||e.name!==n.name)continue;if((e.namespace||"").startsWith(`${n.publisher}/${n.package_}@`))return e}}function k(t,n,e,i){let r=t.predicate?.subject;return r?r.publisher===n&&r.package_===e&&r.name===i:!1}function y(t){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}function E(t,n){return t.publisher===n.publisher&&t.package_===n.package_&&t.name===n.name}function x(t){return`${t.publisher}/${t.package_}/${t.name}`}export{pe as a};
|