@kanonak-protocol/sdk 6.8.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +1 -1
- package/dist/{chunk-IT37WOHT.js → chunk-4NTZY2KP.js} +1 -1
- package/dist/chunk-7PTZF5LK.js +1 -0
- package/dist/{chunk-AZFLKLPB.js → chunk-A4OVTNMT.js} +1 -1
- package/dist/{chunk-Q2ZUKZEU.js → chunk-A5EAI5ZU.js} +1 -1
- package/dist/chunk-AEH3NZLH.js +3 -0
- package/dist/chunk-BA5J2DKJ.js +0 -0
- package/dist/{chunk-2GV6GXRF.js → chunk-C5HHCD6P.js} +1 -1
- package/dist/{chunk-FKLZDYWF.js → chunk-IXCD4K3K.js} +1 -1
- package/dist/{chunk-FCRP7KXR.js → chunk-IZBZDLCX.js} +1 -1
- package/dist/chunk-PC3DHZGV.js +1 -0
- package/dist/{chunk-PXUSA72Q.js → chunk-RFSARH5S.js} +1 -1
- package/dist/chunk-RXIKK3KZ.js +1 -0
- package/dist/chunk-VAZY57HJ.js +1 -0
- package/dist/chunk-YEUSFSC7.js +1 -0
- package/dist/filtering/GitIgnoreFilter.d.ts +25 -1
- package/dist/filtering/IGitIgnoreFilter.d.ts +3 -0
- package/dist/filtering/index.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/lock/VersionIndex.d.ts +97 -0
- package/dist/lock/VersionIndexIO.d.ts +4 -0
- package/dist/lock/index.d.ts +3 -0
- package/dist/parsing/index.js +1 -1
- package/dist/producer/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/InMemoryKanonakDocumentRepository.d.ts +8 -1
- package/dist/repositories/PublisherIndex.d.ts +17 -10
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/buildLocalFirstRepository.d.ts +25 -3
- package/dist/repositories/index.d.ts +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/assembleModel.d.ts +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +19 -19
- package/dist/server/route.d.ts +1 -1
- package/dist/server/types.d.ts +6 -0
- package/dist/server/workspacePackages.d.ts +26 -0
- package/dist/server/workspaceVersionIndex.d.ts +23 -0
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-3ABGZHKM.js +0 -1
- package/dist/chunk-6CI3HTKF.js +0 -1
- package/dist/chunk-F4UHQVGA.js +0 -1
- package/dist/chunk-NYCGUDVW.js +0 -1
- package/dist/chunk-ODIECDN7.js +0 -1
- package/dist/chunk-X2URIXH7.js +0 -2
|
@@ -10,7 +10,14 @@ export declare class InMemoryKanonakDocumentRepository implements IKanonakDocume
|
|
|
10
10
|
getDocumentAsync(identifier: string): Promise<KanonakDocument | null>;
|
|
11
11
|
getDocumentsByNamespaceAsync(publisher: string, package_: string): Promise<KanonakDocument[]>;
|
|
12
12
|
getHighestCompatibleVersionAsync(publisher: string, import_: Import): Promise<KanonakDocument | null>;
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Hold `document` under `identifier`. `source` is the bytes it was parsed
|
|
15
|
+
* from, when there are any: `getDocumentContentAsync` then answers with
|
|
16
|
+
* exactly those bytes, so a lock's integrity can be checked against them
|
|
17
|
+
* (typescript#143). Without `source`, the repository was handed a document,
|
|
18
|
+
* never bytes, and its content is the document's serialization.
|
|
19
|
+
*/
|
|
20
|
+
saveDocumentAsync(document: KanonakDocument, identifier: string, source?: string): Promise<void>;
|
|
14
21
|
deleteDocumentAsync(identifier: string): Promise<void>;
|
|
15
22
|
clearNamespaceAsync(publisher: string, package_: string): Promise<void>;
|
|
16
23
|
getAllDocumentReferencesAsync(): Promise<DocumentReference[]>;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { PublisherConfigResolver, type PublisherConfig } from './PublisherConfig.js';
|
|
2
2
|
import type { AuthenticatedFetchFn } from '../auth/index.js';
|
|
3
3
|
import { type LockFile, type LockEntry } from '../lock/LockFile.js';
|
|
4
|
+
import { type VersionIndex } from '../lock/VersionIndex.js';
|
|
4
5
|
import { type PackageUrlTemplates } from './PackageUrlTemplates.js';
|
|
5
6
|
/**
|
|
6
7
|
* The client for a publisher's SERVED metadata: its `.well-known/kanonak.json`
|
|
7
8
|
* discovery config, its `kanonak.lock` (the resolution + integrity source for
|
|
8
|
-
* RANGE imports),
|
|
9
|
+
* RANGE imports), its `kanonak.index` (every version it has published, each
|
|
10
|
+
* with its sha256 and its yank), and the URLs of its raw package sources.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* an exact pin resolves directly against the archived
|
|
14
|
-
* `{package}/{version}.kan.yml` URL — published versions are immutable, so the
|
|
15
|
-
* URL space IS the archive (see `HttpKanonakDocumentRepository`).
|
|
12
|
+
* Range imports resolve against the lock's pin, while an exact pin resolves
|
|
13
|
+
* directly against the archived `{package}/{version}.kan.yml` URL (see
|
|
14
|
+
* `HttpKanonakDocumentRepository`).
|
|
16
15
|
*
|
|
17
16
|
* It is also THE place a package's source URL is chosen (#130). The
|
|
18
17
|
* consumer's {@link PackageUrlTemplates}, when given, win over everything a
|
|
@@ -26,9 +25,6 @@ import { type PackageUrlTemplates } from './PackageUrlTemplates.js';
|
|
|
26
25
|
* Discovery (`.well-known/kanonak.json`, the locks) is always read from the
|
|
27
26
|
* publisher, so the sha256 a pinned version is checked against is the
|
|
28
27
|
* publisher's, wherever the bytes come from.
|
|
29
|
-
*
|
|
30
|
-
* (The class name is historical; it indexes nothing. `PublisherSource` is the
|
|
31
|
-
* accurate name whenever a breaking rename is acceptable.)
|
|
32
28
|
*/
|
|
33
29
|
export declare class PublisherIndex {
|
|
34
30
|
private readonly configResolver;
|
|
@@ -36,6 +32,7 @@ export declare class PublisherIndex {
|
|
|
36
32
|
private readonly packageUrlTemplates;
|
|
37
33
|
private readonly lockCache;
|
|
38
34
|
private readonly packageLockCache;
|
|
35
|
+
private readonly versionIndexCache;
|
|
39
36
|
constructor(options?: {
|
|
40
37
|
configResolver?: PublisherConfigResolver;
|
|
41
38
|
fetchFn?: AuthenticatedFetchFn;
|
|
@@ -84,5 +81,15 @@ export declare class PublisherIndex {
|
|
|
84
81
|
* and memoized like the root lock.
|
|
85
82
|
*/
|
|
86
83
|
getPackageLockEntry(publisher: string, packageName: string): Promise<LockEntry | null>;
|
|
84
|
+
/**
|
|
85
|
+
* The publisher's served `kanonak.index`: every version of every package it
|
|
86
|
+
* has published, each with its sha256 and its yank. Fetched once and
|
|
87
|
+
* memoized. Null when the publisher serves none (404), as before its first
|
|
88
|
+
* publication with an index. Anything else that stops it being read throws:
|
|
89
|
+
* a failed fetch, an index that doesn't parse, or one that is another
|
|
90
|
+
* publisher's.
|
|
91
|
+
*/
|
|
92
|
+
getVersionIndex(publisher: string): Promise<VersionIndex | null>;
|
|
93
|
+
private fetchVersionIndex;
|
|
87
94
|
private fetchLock;
|
|
88
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as n,m as e,z as r}from"../chunk-AEH3NZLH.js";import"../chunk-SC5M74NM.js";import"../chunk-5FVUBF7N.js";import{a as o}from"../chunk-YEUSFSC7.js";import"../chunk-VAZY57HJ.js";import"../chunk-F67UH4FD.js";import"../chunk-7IMLHHSA.js";export{n as HttpKanonakDocumentRepository,o as InMemoryKanonakDocumentRepository,e as PublisherConfigResolver,r as PublisherIndex};
|
|
@@ -3,11 +3,33 @@ import { KanonakParser } from '../parsing/KanonakParser.js';
|
|
|
3
3
|
import { type HttpCacheRead, type HttpCacheWrite } from './HttpKanonakDocumentRepository.js';
|
|
4
4
|
import type { AuthenticatedFetchFn } from '../auth/CredentialProvider.js';
|
|
5
5
|
import type { PackageUrlTemplates } from './PackageUrlTemplates.js';
|
|
6
|
+
import type { IGitIgnoreFilter } from '../filtering/IGitIgnoreFilter.js';
|
|
7
|
+
/** A path that a `.gitignore` excludes from a collection, and how many `.kan.yml` files it holds. */
|
|
8
|
+
export interface IgnoredKanonakPath {
|
|
9
|
+
path: string;
|
|
10
|
+
isDirectory: boolean;
|
|
11
|
+
/** The `.kan.yml` files at or under `path`: 1 for an excluded file. */
|
|
12
|
+
kanonakFiles: number;
|
|
13
|
+
}
|
|
14
|
+
export interface CollectKanonakFilesOptions {
|
|
15
|
+
/**
|
|
16
|
+
* What `.gitignore` excludes. By default, the `.gitignore` files at `dir`
|
|
17
|
+
* and below; pass a filter rooted higher (a workspace root) to apply the
|
|
18
|
+
* files between that root and `dir` too.
|
|
19
|
+
*/
|
|
20
|
+
ignore?: IGitIgnoreFilter;
|
|
21
|
+
/** Receives each excluded path that holds at least one `.kan.yml` file. */
|
|
22
|
+
ignored?: IgnoredKanonakPath[];
|
|
23
|
+
}
|
|
6
24
|
/**
|
|
7
|
-
* Recursively collect every `.kan.yml` file under `dir
|
|
8
|
-
* and dependency directories
|
|
25
|
+
* Recursively collect every `.kan.yml` file under `dir` that is part of the
|
|
26
|
+
* workspace: build/output and dependency directories are skipped, and so is
|
|
27
|
+
* whatever the folder's `.gitignore` files exclude (typescript#142), so a
|
|
28
|
+
* repository can say which of its directories are not packages (an archive
|
|
29
|
+
* of published versions, fixtures that fail on purpose). Pure filesystem
|
|
30
|
+
* walk — no YAML parsing.
|
|
9
31
|
*/
|
|
10
|
-
export declare function collectKanonakFiles(dir: string, files?: string[]): string[];
|
|
32
|
+
export declare function collectKanonakFiles(dir: string, files?: string[], options?: CollectKanonakFilesOptions): string[];
|
|
11
33
|
/** Hook for persisting / reading HTTP-fetched documents (e.g. a disk cache). */
|
|
12
34
|
export interface HttpCacheHooks {
|
|
13
35
|
getFromCache: HttpCacheRead;
|
|
@@ -5,7 +5,7 @@ export { RepositoryFactory } from './RepositoryFactory.js';
|
|
|
5
5
|
export { HttpKanonakDocumentRepository, type HttpCacheRead, type HttpCacheWrite } from './HttpKanonakDocumentRepository.js';
|
|
6
6
|
export { LocalFirstRepository } from './LocalFirstRepository.js';
|
|
7
7
|
export { LockAwareRepository } from './LockAwareRepository.js';
|
|
8
|
-
export { buildLocalFirstRepository, collectKanonakFiles, type HttpCacheHooks, } from './buildLocalFirstRepository.js';
|
|
8
|
+
export { buildLocalFirstRepository, collectKanonakFiles, type HttpCacheHooks, type IgnoredKanonakPath, type CollectKanonakFilesOptions, } from './buildLocalFirstRepository.js';
|
|
9
9
|
export { PublisherIndex } from './PublisherIndex.js';
|
|
10
10
|
export { PublisherConfigResolver, defaultPublisherConfig } from './PublisherConfig.js';
|
|
11
11
|
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,f as p,g as q,h as r,i as s}from"../chunk-
|
|
1
|
+
import{a as b,b as c,c as d,d as e,e as f,f as p,g as q,h as r,i as s}from"../chunk-7PTZF5LK.js";import{A as o,g,h,i,j,k,l,m,z as n}from"../chunk-AEH3NZLH.js";import"../chunk-SC5M74NM.js";import"../chunk-5FVUBF7N.js";import{a}from"../chunk-YEUSFSC7.js";import"../chunk-VAZY57HJ.js";import"../chunk-F67UH4FD.js";import"../chunk-7IMLHHSA.js";import"../chunk-PC3DHZGV.js";export{g as ANY_PUBLISHER,d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,o as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,p as LocalFirstRepository,q as LockAwareRepository,m as PublisherConfigResolver,n as PublisherIndex,f as RepositoryFactory,s as buildLocalFirstRepository,i as checkPackageUrlTemplate,h as checkPackageUrlTemplates,r as collectKanonakFiles,l as defaultPublisherConfig,k as fillPackageUrlTemplate,e as getGlobalCachePath,j as packageUrlTemplateFor};
|
package/dist/search/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../chunk-TR7PC72M.js";import"../chunk-SC5M74NM.js";import{f as g}from"../chunk-
|
|
1
|
+
import"../chunk-TR7PC72M.js";import"../chunk-SC5M74NM.js";import{f as g}from"../chunk-A4OVTNMT.js";import"../chunk-QHABFCRC.js";import"../chunk-YEUSFSC7.js";import"../chunk-A5EAI5ZU.js";import"../chunk-VAZY57HJ.js";import"../chunk-PEJALHXK.js";import{pa as m,xa as S}from"../chunk-TVMOJ2QS.js";import{c as v,p,y as E}from"../chunk-6USORWEP.js";import"../chunk-F67UH4FD.js";import{c as x}from"../chunk-7IMLHHSA.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
|
|
2
2
|
Install it with:
|
|
3
3
|
npm install @huggingface/transformers
|
|
4
4
|
(underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export { loadServerModel } from './loadServerModel.js';
|
|
2
|
+
export { readWorkspacePackages, chooseServedPublisher } from './workspacePackages.js';
|
|
3
|
+
export type { WorkspacePackage } from './workspacePackages.js';
|
|
4
|
+
export { planWorkspaceVersionIndex } from './workspaceVersionIndex.js';
|
|
5
|
+
export type { WorkspaceVersionIndex } from './workspaceVersionIndex.js';
|
|
2
6
|
export { loadResourceModel } from './loadResourceModel.js';
|
|
3
7
|
export type { LoadResourceModelOptions } from './loadResourceModel.js';
|
|
4
8
|
export { route } from './route.js';
|
package/dist/server/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import{c as xe}from"../chunk-3ABGZHKM.js";import{a as ye,d as J,f as Se,h as Z}from"../chunk-F4UHQVGA.js";import{l as $e,t as X,u as Q}from"../chunk-X2URIXH7.js";import"../chunk-TR7PC72M.js";import"../chunk-SC5M74NM.js";import{a as O,b as W}from"../chunk-QRF7AT2M.js";import{u as te}from"../chunk-AZFLKLPB.js";import"../chunk-QHABFCRC.js";import"../chunk-5FVUBF7N.js";import{a as fe}from"../chunk-NYCGUDVW.js";import{k as re}from"../chunk-Q2ZUKZEU.js";import{a as B}from"../chunk-6CI3HTKF.js";import{a as Re}from"../chunk-PEJALHXK.js";import"../chunk-TVMOJ2QS.js";import{c as we,z as ee}from"../chunk-6USORWEP.js";import"../chunk-F67UH4FD.js";import{c as V,e as j,f as L,g as Y,l as be,m as ve}from"../chunk-7IMLHHSA.js";import{readFileSync as le,writeFileSync as Ie,mkdirSync as Fe}from"fs";import{join as ne}from"path";import Me from"js-yaml";var Pe=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(r){return Pe}function C(r){return`${r.publisher}/${r.package_}`}function H(r,e=[]){let i={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},t=[];for(let o of r)if(o.origin==="missing"){let a=C(o),u=i[a]??"whatever this package contributes to rendering is lost";t.push(`Render-stack package ${a} is MISSING (${o.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${a} (as the user running the render), or restore network access to ${o.publisher}.`)}else o.resolvedButNotInCatalog&&t.push(`Render-stack package ${C(o)} resolved (${o.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let o of e)t.push(`Import edge ${o.fromNamespace} \u2192 ${o.publisher}/${o.packageName} ${o.constraint} did NOT resolve (${o.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${o.fromNamespace} authors against ${o.publisher}/${o.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${o.constraint}-compatible version of ${o.publisher}/${o.packageName} to the workspace or cache (kanonak install ${o.publisher}/${o.packageName}), or bump the import in ${o.fromNamespace}.`);return t}function oe(r){let{publisher:e,availablePublishers:i,catalog:t,lookRenderer:o,localNamespaces:a,rawByNsKey:u,renderStack:p,producers:f,lockSource:y,configSource:s}=r,d=new Map,k=new Map,l=new Map,h=new Set;for(let S of t){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;d.set(`${w}/${S.name}`,S);let P=w.split("/")[1]??"",[_,M]=P.split("@");if(!_||!M)continue;let E=Y(M);E&&(h.has(P)||(h.add(P),k.has(_)||k.set(_,[]),k.get(_).push({verStr:M,version:E})),S.name===_&&l.set(P,S))}for(let S of k.values())S.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:i,catalog:t,lookRenderer:o,localNamespaces:a,rawByNsKey:u,bySubject:d,pkgVersions:k,pkgSelfByVer:l,renderStack:p,...f?{producers:f}:{},...y?{lockSource:y}:{},...s?{configSource:s}:{}}}async function de(r,e={}){let i=new B,t=new fe(i),o=[],a=[];for(let c of Z(r)){let m;try{m=le(c,"utf-8")}catch{continue}let n;try{n=i.parse(m).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:j(g),version:g,source:m})}a.sort((c,m)=>V(m.version,c.version));for(let c of a)await t.saveDocumentAsync(i.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),o.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let u=[...new Set(o.map(c=>c.publisher))].sort(),p=e.publisher;if(p){if(!u.includes(p))throw new Error(`Publisher "${p}" not found in workspace. Available: ${u.join(", ")||"(none)"}`)}else if(u.length===1)p=u[0];else throw u.length===0?new Error(`No Kanonak packages found under ${r}`):new Error(`Workspace has multiple publishers (${u.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,y=new Map;for(let c of o)c.publisher===p&&(f.add(`${c.publisher}/${c.package_}@${c.verStr}`),y.set(`${c.package_}@${c.verStr}`,c.source));let s=J(),d=new ye(s,!0,i),k={};e.httpCache&&(k.getFromCache=e.httpCache.getFromCache,k.onFetch=e.httpCache.onFetch),e.fetchFn&&(k.fetchFn=e.fetchFn),e.packageUrlTemplates&&(k.packageUrlTemplates=e.packageUrlTemplates);let l=e.repository??new Se(t,d,new Q(k)),h=e.log??(()=>{}),S=q(void 0),w=[],P=c=>c.map(m=>m.metadata.namespace_?.version).filter(m=>m!==void 0).sort((m,n)=>V(n,m)).map(j);if(!e.repository){h(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let c=new X({...e.fetchFn?{fetchFn:e.fetchFn}:{},...e.packageUrlTemplates?{packageUrlTemplates:e.packageUrlTemplates}:{}});for(let m of S){let n=C(m),g=await t.getDocumentsByNamespaceAsync(m.publisher,m.package_);if(g.length>0){let v=P(g);w.push({...m,origin:"workspace",versions:v}),h(`[render-stack] ${n} \u2014 workspace (${v.join(", ")})`);continue}let b=await d.getDocumentsByNamespaceAsync(m.publisher,m.package_);if(b.length>0){let v=P(b);w.push({...m,origin:"cache",versions:v}),h(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await c.getLock(m.publisher))?.packages[`${m.publisher}/${m.package_}`];if(!$){let K=`publisher ${m.publisher} reachable but its lock does not pin ${m.package_}`;w.push({...m,origin:"missing",reason:K}),h(`[render-stack] ${n} \u2014 MISSING: ${K}`);continue}let I=$.version,{url:he,content:ke}=await c.fetchLockedSource(m.publisher,m.package_,$);await t.saveDocumentAsync(i.parse(ke),`${m.publisher}/${m.package_}@${I}`);try{let K=ne(s,m.publisher);Fe(K,{recursive:!0}),Ie(ne(K,`${m.package_}@${I}.kan.yml`),ke,"utf-8"),w.push({...m,origin:"fetched",versions:[I]}),h(`[render-stack] ${n}@${I} \u2014 fetched from ${he}, installed to cache`)}catch(K){w.push({...m,origin:"fetched",versions:[I]}),h(`[render-stack] ${n}@${I} \u2014 fetched from ${he}, but cache ${s} is NOT WRITABLE (${K.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;w.push({...m,origin:"missing",reason:$}),h(`[render-stack] ${n} \u2014 MISSING: ${$}`)}}}let _=(await t.getAllDocumentsAsync()).filter(c=>c.metadata.namespace_?.publisher===p);for(let c of S)_.push(...await l.getDocumentsByNamespaceAsync(c.publisher,c.package_));let M=[],E=await O(_,l,{onUnresolvedEdge:c=>M.push(c)}),A=l;if(!e.repository){for(let c of S)E.add(C(c));A=new W(l,E)}let T=await new re(i).parseKanonaks(A),ie=new te(T),ce=(c,m)=>ee(T,{publisher:c,package_:m,name:m}).length>0,N;if(e.repository){N=[];for(let c of S){let m=await l.getDocumentsByNamespaceAsync(c.publisher,c.package_);N.push(m.length>0?{...c,origin:"repository",versions:P(m)}:{...c,origin:"missing",reason:"not present in the caller-supplied repository"})}}else N=w.map(c=>c.origin==="missing"||ce(c.publisher,c.package_)?c:{...c,resolvedButNotInCatalog:!0});let G=H(N,M);for(let c of G)h(`[render-stack] WARNING: ${c}`);let z={contractSource:"universal-default",cachePath:s,packages:N,warnings:G},D;try{D=le(ne(r,"kanonak.lock"),"utf-8")}catch{D=Ee(p,o,i)}let U;try{U=le(ne(r,".well-known","kanonak.json"),"utf-8")}catch{U=void 0}return oe({publisher:p,availablePublishers:u,catalog:T,lookRenderer:ie,localNamespaces:f,rawByNsKey:y,renderStack:z,...D?{lockSource:D}:{},...U?{configSource:U}:{}})}function Ee(r,e,i){let t=new Map;for(let a of e)a.publisher===r&&(t.has(a.package_)||t.set(a.package_,{verStr:a.verStr,source:a.source}));if(t.size===0)return;let o={};for(let a of[...t.keys()].sort()){let{verStr:u,source:p}=t.get(a),f={},y;try{y=i.parse(p).metadata?.imports}catch{y=void 0}for(let d of y?.[r]??[]){let k=t.get(d.packageName);k&&(f[`${r}/${d.packageName}`]=k.verStr)}let s={};for(let d of Object.keys(f).sort())s[d]=f[d];o[`${r}/${a}`]={version:u,resolved:`https://${r}/${a}/${u}.kan.yml`,integrity:xe(p),dependencies:s}}return Me.dump({version:"1",lastUpdated:"",packages:o},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as De,readFileSync as Ke,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as _e}from"path";async function pe(r,e={}){let i=new B,t=ve(r),o=t.kind==="resource"?t.uri.publisher:t.publisher,a=e.log??(()=>{}),u=e.cacheRoot??J(),p=(n,g,b)=>_e(u,n,`${g}@${b}.kan.yml`),f=new Set,y=new Set,s=new Map,d=new Q({getFromCache:(n,g,b)=>{let v=p(n,g,b),$=De(v)?Ke(v,"utf-8"):null;return $!==null&&f.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=_e(u,n);Ae($,{recursive:!0}),Ve(p(n,g,b),v,"utf-8")}catch($){s.set(`${n}/${g}`,$.message),a(`[render] fetched ${n}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{},...e.packageUrlTemplates?{packageUrlTemplates:e.packageUrlTemplates}:{}}),k=new X(e.fetchFn?{fetchFn:e.fetchFn}:void 0),l;if(t.kind==="resource"){let n=t.uri.version;l=[n?{package_:t.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:t.uri.package_}]}else if(t.kind==="package"){let n=t.version;l=[n?{package_:t.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:t.package_}]}else l=((await k.getConfig(o)).featured_packages??[]).map(g=>({package_:g}));let h=async(n,g,b)=>{try{let v=b?i.buildImport(g,"=",b,n):i.buildImport(g,"*","0.0.0",n),$=await d.getHighestCompatibleVersionAsync(n,v);return $?{doc:$}:{doc:null,error:`${n} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},S=[],w=[];for(let n of l){let{doc:g,error:b}=await h(o,n.package_,n.version);g?S.push(g):b&&w.push(b)}if(S.length===0)throw new Error(`Could not fetch any package for address "${r}" from publisher "${o}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",M=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(j);a(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${u}`);let E=[],A=[];for(let n of P){let g=C(n),{doc:b,error:v}=await h(n.publisher,n.package_,void 0);if(b){E.push(b);let $=M([b]),I=y.has(g)?"fetched":f.has(g)?"cache":"fetched";A.push({...n,origin:I,versions:$}),a(`[render-stack] ${g} \u2014 ${I} (${$.join(", ")})`+(s.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:v??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let T=[],ie=await O([...S,...E],d,{onUnresolvedEdge:n=>T.push(n)}),ce=new W(d,ie),N=await new re(i).parseKanonaks(ce),G=new te(N),z=A.map(n=>n.origin==="missing"||ee(N,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),D=H(z,T);for(let n of D)a(`[render-stack] WARNING: ${n}`);let U={contractSource:_,cachePath:u,packages:z,warnings:D},c=new Set,m=new Map;for(let n of await d.getAllDocumentsAsync()){let g=n.metadata.namespace_;if(!g?.version||g.publisher!==o)continue;let b=j(g.version),v=`${g.publisher}/${g.package_}@${b}`;c.add(v);let $=await d.getDocumentContentAsync(v);$!==null&&m.set(`${g.package_}@${b}`,$)}return oe({publisher:o,availablePublishers:[o],catalog:N,lookRenderer:G,localNamespaces:c,rawByNsKey:m,renderStack:U})}import{VersionOperator as ae}from"@kanonak-protocol/types/document/models/enums";function se(r){let{lookRenderer:e,publisher:i,renderStack:t,catalog:o}=r,a=e.explainStylesheet(e.publisherSubject(i)),u=[...a.tokens.entries()].map(([l,h])=>({name:l,value:h.value,source:`${h.sourceNamespace}/${h.sourceName}`,level:h.level})),p=a.baseStylesheet,f={present:p.css!==void 0,...p.sourceNamespace!==void 0?{source:p.sourceNamespace}:{},...p.scope!==void 0?{scope:p.scope}:{},...p.css!==void 0?{bytes:p.css.length}:{},...p.problem!==void 0?{problem:p.problem}:{},candidates:p.candidates},y=new Map;for(let l of o){let h=l.namespace;h&&y.set(h,(y.get(h)??0)+1)}let s=[...y.entries()].map(([l,h])=>({namespace:l,resources:h})).sort((l,h)=>l.namespace.localeCompare(h.namespace)),d=e.expressionFailures().map(l=>({carrier:l.carrier,stage:l.stage,reason:l.reason})),k=d.map(l=>l.stage==="compile"?`Expression carrier "${l.carrier}" did not compile: ${l.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`:`Expression carrier "${l.carrier}" failed to evaluate: ${l.reason} Consequence: that value renders as nothing. Fix: correct the expression, or make a value that may be absent explicitly optional.`);return{publisher:i,renderStack:{contractSource:t.contractSource,cachePath:t.cachePath,packages:t.packages.map(l=>({package_:C(l),origin:l.origin,...l.versions!==void 0?{versions:l.versions}:{},...l.reason!==void 0?{reason:l.reason}:{},...l.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:l.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:f,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},expressionCarriers:d,catalog:s,warnings:[...t.warnings,...a.warnings.filter(l=>!t.warnings.includes(l)),...k]}}function Te(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ue(r){let e=Te,i=r.warnings.length===0,t=r.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
|
|
2
|
-
`),o
|
|
3
|
-
`),
|
|
4
|
-
`),u=
|
|
5
|
-
`),
|
|
1
|
+
import{c as je,d as Ne}from"../chunk-RXIKK3KZ.js";import{a as $e,d as ee,f as Pe,h as ne}from"../chunk-7PTZF5LK.js";import{A as oe,l as Re,t as K,x as xe,z as re}from"../chunk-AEH3NZLH.js";import"../chunk-TR7PC72M.js";import"../chunk-SC5M74NM.js";import{a as H,b as q}from"../chunk-QRF7AT2M.js";import{u as ae}from"../chunk-A4OVTNMT.js";import"../chunk-QHABFCRC.js";import"../chunk-5FVUBF7N.js";import{a as ve}from"../chunk-YEUSFSC7.js";import{k as se}from"../chunk-A5EAI5ZU.js";import{a as C}from"../chunk-VAZY57HJ.js";import{a as _e}from"../chunk-PEJALHXK.js";import"../chunk-TVMOJ2QS.js";import{c as Ie,z as te}from"../chunk-6USORWEP.js";import"../chunk-F67UH4FD.js";import{c as D,e as I,f as B,g as Z,l as Se,m as we}from"../chunk-7IMLHHSA.js";import"../chunk-PC3DHZGV.js";import{readFileSync as ue,writeFileSync as Ke,mkdirSync as Ae}from"fs";import{join as J}from"path";import Te from"js-yaml";import{readFileSync as De}from"fs";function G(o,e=new C){let s=[];for(let r of ne(o)){let n;try{n=De(r,"utf-8")}catch{continue}let t;try{t=e.parse(n).metadata?.namespace_}catch{continue}t?.version&&s.push({publisher:t.publisher,package_:t.package_,verStr:I(t.version),version:t.version,source:n})}return s.sort((r,n)=>D(n.version,r.version))}function z(o,e,s){let r=[...new Set(o.map(n=>n.publisher))].sort();if(s){if(!r.includes(s))throw new Error(`Publisher "${s}" not found in workspace. Available: ${r.join(", ")||"(none)"}`);return{publisher:s,availablePublishers:r}}if(r.length===1)return{publisher:r[0],availablePublishers:r};throw r.length===0?new Error(`No Kanonak packages found under ${e}`):new Error(`Workspace has multiple publishers (${r.join(", ")}). Pass --publisher <domain> to choose which one to serve.`)}var Ce=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function X(o){return Ce}function E(o){return`${o.publisher}/${o.package_}`}function Y(o,e=[]){let s={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let n of o)if(n.origin==="missing"){let t=E(n),u=s[t]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${t} is MISSING (${n.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${t} (as the user running the render), or restore network access to ${n.publisher}.`)}else n.resolvedButNotInCatalog&&r.push(`Render-stack package ${E(n)} resolved (${n.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let n of e)r.push(`Import edge ${n.fromNamespace} \u2192 ${n.publisher}/${n.packageName} ${n.constraint} did NOT resolve (${n.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${n.fromNamespace} authors against ${n.publisher}/${n.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${n.constraint}-compatible version of ${n.publisher}/${n.packageName} to the workspace or cache (kanonak install ${n.publisher}/${n.packageName}), or bump the import in ${n.fromNamespace}.`);return r}function ie(o){let{publisher:e,availablePublishers:s,catalog:r,lookRenderer:n,localNamespaces:t,rawByNsKey:u,renderStack:p,producers:f,lockSource:h,indexSource:a,configSource:l}=o,y=new Map,c=new Map,k=new Map,R=new Set;for(let x of r){if(!(x instanceof Ie))continue;let _=x.namespace||"";if(!t.has(_))continue;y.set(`${_}/${x.name}`,x);let P=_.split("/")[1]??"",[j,F]=P.split("@");if(!j||!F)continue;let N=Z(F);N&&(R.has(P)||(R.add(P),c.has(j)||c.set(j,[]),c.get(j).push({verStr:F,version:N})),x.name===j&&k.set(P,x))}for(let x of c.values())x.sort((_,P)=>D(P.version,_.version));return{publisher:e,availablePublishers:s,catalog:r,lookRenderer:n,localNamespaces:t,rawByNsKey:u,bySubject:y,pkgVersions:c,pkgSelfByVer:k,renderStack:p,...f?{producers:f}:{},...h?{lockSource:h}:{},...a?{indexSource:a}:{},...l?{configSource:l}:{}}}async function ge(o,e={}){let s=new C,r=new ve(s),n=G(o,s);for(let d of n)await r.saveDocumentAsync(s.parse(d.source),`${d.publisher}/${d.package_}@${d.verStr}`);let{publisher:t,availablePublishers:u}=z(n,o,e.publisher),p=new Set,f=new Map;for(let d of n)d.publisher===t&&(p.add(`${d.publisher}/${d.package_}@${d.verStr}`),f.set(`${d.package_}@${d.verStr}`,d.source));let h=ee(),a=new $e(h,!0,s),l={};e.httpCache&&(l.getFromCache=e.httpCache.getFromCache,l.onFetch=e.httpCache.onFetch),e.fetchFn&&(l.fetchFn=e.fetchFn),e.packageUrlTemplates&&(l.packageUrlTemplates=e.packageUrlTemplates);let y=e.repository??new Pe(r,a,new oe(l)),c=e.log??(()=>{}),k=X(void 0),R=[],x=d=>d.map(m=>m.metadata.namespace_?.version).filter(m=>m!==void 0).sort((m,i)=>D(i,m)).map(I);if(!e.repository){c(`[render-stack] resolving ${k.length} ambient look-stack package(s); cache: ${h}`);let d=new re({...e.fetchFn?{fetchFn:e.fetchFn}:{},...e.packageUrlTemplates?{packageUrlTemplates:e.packageUrlTemplates}:{}});for(let m of k){let i=E(m),g=await r.getDocumentsByNamespaceAsync(m.publisher,m.package_);if(g.length>0){let v=x(g);R.push({...m,origin:"workspace",versions:v}),c(`[render-stack] ${i} \u2014 workspace (${v.join(", ")})`);continue}let b=await a.getDocumentsByNamespaceAsync(m.publisher,m.package_);if(b.length>0){let v=x(b);R.push({...m,origin:"cache",versions:v}),c(`[render-stack] ${i} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await d.getLock(m.publisher))?.packages[`${m.publisher}/${m.package_}`];if(!$){let L=`publisher ${m.publisher} reachable but its lock does not pin ${m.package_}`;R.push({...m,origin:"missing",reason:L}),c(`[render-stack] ${i} \u2014 MISSING: ${L}`);continue}let M=$.version,{url:ye,content:be}=await d.fetchLockedSource(m.publisher,m.package_,$);await r.saveDocumentAsync(s.parse(be),`${m.publisher}/${m.package_}@${M}`);try{let L=J(h,m.publisher);Ae(L,{recursive:!0}),Ke(J(L,`${m.package_}@${M}.kan.yml`),be,"utf-8"),R.push({...m,origin:"fetched",versions:[M]}),c(`[render-stack] ${i}@${M} \u2014 fetched from ${ye}, installed to cache`)}catch(L){R.push({...m,origin:"fetched",versions:[M]}),c(`[render-stack] ${i}@${M} \u2014 fetched from ${ye}, but cache ${h} is NOT WRITABLE (${L.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;R.push({...m,origin:"missing",reason:$}),c(`[render-stack] ${i} \u2014 MISSING: ${$}`)}}}let _=(await r.getAllDocumentsAsync()).filter(d=>d.metadata.namespace_?.publisher===t);for(let d of k)_.push(...await y.getDocumentsByNamespaceAsync(d.publisher,d.package_));let P=[],j=await H(_,y,{onUnresolvedEdge:d=>P.push(d)}),F=y;if(!e.repository){for(let d of k)j.add(E(d));F=new q(y,j)}let N=await new se(s).parseKanonaks(F),Q=new ae(N),de=(d,m)=>te(N,{publisher:d,package_:m,name:m}).length>0,A;if(e.repository){A=[];for(let d of k){let m=await y.getDocumentsByNamespaceAsync(d.publisher,d.package_);A.push(m.length>0?{...d,origin:"repository",versions:x(m)}:{...d,origin:"missing",reason:"not present in the caller-supplied repository"})}}else A=R.map(d=>d.origin==="missing"||de(d.publisher,d.package_)?d:{...d,resolvedButNotInCatalog:!0});let O=Y(A,P);for(let d of O)c(`[render-stack] WARNING: ${d}`);let pe={contractSource:"universal-default",cachePath:h,packages:A,warnings:O},T;try{T=ue(J(o,"kanonak.lock"),"utf-8")}catch{T=Ue(t,n,s)}let U;try{U=ue(J(o,K),"utf-8")}catch{U=void 0}let W;try{W=ue(J(o,".well-known","kanonak.json"),"utf-8")}catch{W=void 0}return ie({publisher:t,availablePublishers:u,catalog:N,lookRenderer:Q,localNamespaces:p,rawByNsKey:f,renderStack:pe,...T?{lockSource:T}:{},...U?{indexSource:U}:{},...W?{configSource:W}:{}})}function Ue(o,e,s){let r=new Map;for(let t of e)t.publisher===o&&(r.has(t.package_)||r.set(t.package_,{verStr:t.verStr,source:t.source}));if(r.size===0)return;let n={};for(let t of[...r.keys()].sort()){let{verStr:u,source:p}=r.get(t),f={},h;try{h=s.parse(p).metadata?.imports}catch{h=void 0}for(let l of h?.[o]??[]){let y=r.get(l.packageName);y&&(f[`${o}/${l.packageName}`]=y.verStr)}let a={};for(let l of Object.keys(f).sort())a[l]=f[l];n[`${o}/${t}`]={version:u,resolved:`https://${o}/${t}/${u}.kan.yml`,integrity:je(p),dependencies:a}}return Te.dump({version:"1",lastUpdated:"",packages:n},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{join as Le}from"path";async function Oe(o,e){let s=G(o,new C),{publisher:r}=z(s,o,e.publisher),n=Le(o,K),t=Ne(n),u=await e.publisherIndex.getVersionIndex(r),p=s.filter(h=>h.publisher===r).map(h=>({package_:h.package_,version:h.version,source:h.source})),f=await xe({publisher:r,current:t,sources:p,served:u});return{publisher:r,path:n,current:t,served:u,plan:f}}import{existsSync as We,readFileSync as Be,writeFileSync as He,mkdirSync as qe}from"fs";import{join as Ee}from"path";async function me(o,e={}){let s=new C,r=we(o),n=r.kind==="resource"?r.uri.publisher:r.publisher,t=e.log??(()=>{}),u=e.cacheRoot??ee(),p=(i,g,b)=>Ee(u,i,`${g}@${b}.kan.yml`),f=new Set,h=new Set,a=new Map,l=new oe({getFromCache:(i,g,b)=>{let v=p(i,g,b),$=We(v)?Be(v,"utf-8"):null;return $!==null&&f.add(`${i}/${g}`),$},onFetch:(i,g,b,v)=>{h.add(`${i}/${g}`);try{let $=Ee(u,i);qe($,{recursive:!0}),He(p(i,g,b),v,"utf-8")}catch($){a.set(`${i}/${g}`,$.message),t(`[render] fetched ${i}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{},...e.packageUrlTemplates?{packageUrlTemplates:e.packageUrlTemplates}:{}}),y=new re(e.fetchFn?{fetchFn:e.fetchFn}:void 0),c;if(r.kind==="resource"){let i=r.uri.version;c=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;c=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else c=((await y.getConfig(n)).featured_packages??[]).map(g=>({package_:g}));let k=async(i,g,b)=>{try{let v=b?s.buildImport(g,"=",b,i):s.buildImport(g,"*","0.0.0",i),$=await l.getHighestCompatibleVersionAsync(i,v);return $?{doc:$}:{doc:null,error:`${i} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},R=[],x=[];for(let i of c){let{doc:g,error:b}=await k(n,i.package_,i.version);g?R.push(g):b&&x.push(b)}if(R.length===0)throw new Error(`Could not fetch any package for address "${o}" from publisher "${n}".`+(x.length>0?` Reasons: ${x.join("; ")}`:""));let _=X(),P="universal-default",j=i=>i.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>D(b,g)).map(I);t(`[render-stack] resolving ${_.length} ambient look-stack package(s) (contract: ${P}); cache: ${u}`);let F=[],N=[];for(let i of _){let g=E(i),{doc:b,error:v}=await k(i.publisher,i.package_,void 0);if(b){F.push(b);let $=j([b]),M=h.has(g)?"fetched":f.has(g)?"cache":"fetched";N.push({...i,origin:M,versions:$}),t(`[render-stack] ${g} \u2014 ${M} (${$.join(", ")})`+(a.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else N.push({...i,origin:"missing",reason:v??"unresolved"}),t(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let Q=[],de=await H([...R,...F],l,{onUnresolvedEdge:i=>Q.push(i)}),A=new q(l,de),O=await new se(s).parseKanonaks(A),pe=new ae(O),T=N.map(i=>i.origin==="missing"||te(O,{publisher:i.publisher,package_:i.package_,name:i.package_}).length>0?i:{...i,resolvedButNotInCatalog:!0}),U=Y(T,Q);for(let i of U)t(`[render-stack] WARNING: ${i}`);let W={contractSource:P,cachePath:u,packages:T,warnings:U},d=new Set,m=new Map;for(let i of await l.getAllDocumentsAsync()){let g=i.metadata.namespace_;if(!g?.version||g.publisher!==n)continue;let b=I(g.version),v=`${g.publisher}/${g.package_}@${b}`;d.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&m.set(`${g.package_}@${b}`,$)}return ie({publisher:n,availablePublishers:[n],catalog:O,lookRenderer:pe,localNamespaces:d,rawByNsKey:m,renderStack:W})}import{VersionOperator as le}from"@kanonak-protocol/types/document/models/enums";function ce(o){let{lookRenderer:e,publisher:s,renderStack:r,catalog:n}=o,t=e.explainStylesheet(e.publisherSubject(s)),u=[...t.tokens.entries()].map(([c,k])=>({name:c,value:k.value,source:`${k.sourceNamespace}/${k.sourceName}`,level:k.level})),p=t.baseStylesheet,f={present:p.css!==void 0,...p.sourceNamespace!==void 0?{source:p.sourceNamespace}:{},...p.scope!==void 0?{scope:p.scope}:{},...p.css!==void 0?{bytes:p.css.length}:{},...p.problem!==void 0?{problem:p.problem}:{},candidates:p.candidates},h=new Map;for(let c of n){let k=c.namespace;k&&h.set(k,(h.get(k)??0)+1)}let a=[...h.entries()].map(([c,k])=>({namespace:c,resources:k})).sort((c,k)=>c.namespace.localeCompare(k.namespace)),l=e.expressionFailures().map(c=>({carrier:c.carrier,stage:c.stage,reason:c.reason})),y=l.map(c=>c.stage==="compile"?`Expression carrier "${c.carrier}" did not compile: ${c.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`:`Expression carrier "${c.carrier}" failed to evaluate: ${c.reason} Consequence: that value renders as nothing. Fix: correct the expression, or make a value that may be absent explicitly optional.`);return{publisher:s,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(c=>({package_:E(c),origin:c.origin,...c.versions!==void 0?{versions:c.versions}:{},...c.reason!==void 0?{reason:c.reason}:{},...c.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:c.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:f,...t.look?{look:{sourceClass:`${t.look.sourceClass.publisher}/${t.look.sourceClass.package_}/${t.look.sourceClass.name}`}}:{}},expressionCarriers:l,catalog:a,warnings:[...r.warnings,...t.warnings.filter(c=>!r.warnings.includes(c)),...y]}}function Ge(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function he(o){let e=Ge,s=o.warnings.length===0,r=o.expressionCarriers.map(a=>`<tr><td><code>${e(a.carrier)}</code></td><td>${e(a.reason)}</td></tr>`).join(`
|
|
2
|
+
`),n=o.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':o.warnings.map(a=>`<div class="warn">\u26A0 ${e(a)}</div>`).join(`
|
|
3
|
+
`),t=o.renderStack.packages.map(a=>{let l=a.origin!=="missing"&&!a.resolvedButNotInCatalog,y=a.origin==="missing"?'<span class="bad">MISSING</span>':a.resolvedButNotInCatalog?`<span class="bad">${e(a.origin)} (not in catalog)</span>`:`<span class="good">${e(a.origin)}</span>`,c=a.reason?e(a.reason):e((a.versions??[]).join(", "));return`<tr class="${l?"":"row-bad"}"><td><code>${e(a.package_)}</code></td><td>${y}</td><td>${c}</td></tr>`}).join(`
|
|
4
|
+
`),u=o.stylesheet.baseStylesheet,p=u.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(u.source??"")}</code> (${u.bytes} bytes, ${e(u.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${u.problem?` \u2014 ${e(u.problem)}`:""}${u.candidates.length>0?`<br>candidates considered: ${u.candidates.map(a=>`<code>${e(a)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,f=o.stylesheet.tokens.map(a=>`<tr><td><code>--kan-${e(a.name)}</code></td><td><code>${e(a.value)}</code></td><td><code>${e(a.source)}</code></td><td>${e(a.level)}</td></tr>`).join(`
|
|
5
|
+
`),h=o.catalog.map(a=>`<tr><td><code>${e(a.namespace)}</code></td><td>${a.resources}</td></tr>`).join(`
|
|
6
6
|
`);return`<!doctype html>
|
|
7
7
|
<html lang="en">
|
|
8
8
|
<head>
|
|
9
9
|
<meta charset="utf-8">
|
|
10
10
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
11
|
-
<title>Render diagnostics \u2014 ${e(
|
|
11
|
+
<title>Render diagnostics \u2014 ${e(o.publisher)}</title>
|
|
12
12
|
<style>
|
|
13
13
|
body { font-family: system-ui, sans-serif; max-width: 64rem; margin: 2rem auto; padding: 0 1rem; line-height: 1.5; color: #1a1a1a; background: #fff; }
|
|
14
14
|
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; margin-top: 2rem; border-bottom: 1px solid #ddd; padding-bottom: .25rem; }
|
|
@@ -22,23 +22,23 @@ import{c as xe}from"../chunk-3ABGZHKM.js";import{a as ye,d as J,f as Se,h as Z}f
|
|
|
22
22
|
.row-bad td { background: #fff5f5; }
|
|
23
23
|
.meta { color: #666; font-size: .85rem; }
|
|
24
24
|
.status-banner { font-size: 1.1rem; padding: .5rem 1rem; border-radius: 6px; display: inline-block; margin-bottom: 1rem;
|
|
25
|
-
background: ${
|
|
25
|
+
background: ${s?"#ecfdf3":"#fef2f2"}; border: 1px solid ${s?"#0a7d33":"#b91c1c"}; }
|
|
26
26
|
</style>
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
29
|
-
<h1>Render diagnostics \u2014 ${e(
|
|
30
|
-
<p class="status-banner">${
|
|
29
|
+
<h1>Render diagnostics \u2014 ${e(o.publisher)}</h1>
|
|
30
|
+
<p class="status-banner">${s?"\u2713 Healthy":`\u2717 ${o.warnings.length} problem(s) found`}</p>
|
|
31
31
|
<p class="meta">Machine-readable version: <a href="/.well-known/kanonak-render.json"><code>/.well-known/kanonak-render.json</code></a></p>
|
|
32
32
|
|
|
33
33
|
<h2>Problems</h2>
|
|
34
|
-
${
|
|
34
|
+
${n}
|
|
35
35
|
|
|
36
36
|
<h2>Ambient render stack</h2>
|
|
37
37
|
<p class="meta">The look stack is discovered, not imported \u2014 these packages must be resolvable for any publisher's pages to render styled.
|
|
38
|
-
Contract: <code>${e(
|
|
38
|
+
Contract: <code>${e(o.renderStack.contractSource)}</code> \xB7 Package cache: <code>${e(o.renderStack.cachePath)}</code></p>
|
|
39
39
|
<table>
|
|
40
40
|
<tr><th>Package</th><th>Origin</th><th>Versions / reason</th></tr>
|
|
41
|
-
${
|
|
41
|
+
${t}
|
|
42
42
|
</table>
|
|
43
43
|
|
|
44
44
|
<h2>Base stylesheet</h2>
|
|
@@ -47,26 +47,26 @@ ${p}
|
|
|
47
47
|
|
|
48
48
|
<h2>Design tokens (:root)</h2>
|
|
49
49
|
<p class="meta">Resolved for the publisher landing page. Each token shows which resource in the cascade supplied it.</p>
|
|
50
|
-
${
|
|
50
|
+
${o.stylesheet.tokens.length===0?'<p><span class="bad">\u2717 No tokens resolved</span></p>':`<table>
|
|
51
51
|
<tr><th>Token</th><th>Value</th><th>Declared by</th><th>Cascade level</th></tr>
|
|
52
52
|
${f}
|
|
53
53
|
</table>`}
|
|
54
54
|
|
|
55
55
|
<h2>Look (page body)</h2>
|
|
56
|
-
${
|
|
56
|
+
${o.stylesheet.look?`<p><span class="good">\u2713</span> Bands resolve from <code>${e(o.stylesheet.look.sourceClass)}</code></p>`:'<p><span class="bad">\u2717 No look resolved</span> \u2014 the page body renders as an empty comment.</p>'}
|
|
57
57
|
|
|
58
58
|
<h2>Expression carriers</h2>
|
|
59
59
|
<p class="meta">Authored <code>tx.Expression</code> carriers (band paths, <code>semanticSvg</code> tiers) that failed to compile while rendering this page. A carrier that does not compile contributes nothing to the output.</p>
|
|
60
|
-
${
|
|
60
|
+
${o.expressionCarriers.length===0?'<p><span class="good">\u2713</span> Every expression carrier on this page compiled.</p>':`<table>
|
|
61
61
|
<tr><th>Carrier</th><th>Reason</th></tr>
|
|
62
|
-
${
|
|
62
|
+
${r}
|
|
63
63
|
</table>`}
|
|
64
64
|
|
|
65
|
-
<h2>Render catalog (${
|
|
65
|
+
<h2>Render catalog (${o.catalog.length} package version(s))</h2>
|
|
66
66
|
<p class="meta">Everything the renderer can see for this publisher \u2014 the served packages, their import closure, and the ambient render stack.</p>
|
|
67
67
|
<table>
|
|
68
68
|
<tr><th>Package version</th><th>Resources</th></tr>
|
|
69
|
-
${
|
|
69
|
+
${h}
|
|
70
70
|
</table>
|
|
71
71
|
</body>
|
|
72
|
-
</html>`}var
|
|
72
|
+
</html>`}var S={".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"},w=(o,e,s,r)=>({status:o,headers:{"Content-Type":e,...r||{}},body:s}),V=o=>w(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${o}</p>`),ze=o=>({status:301,headers:{Location:o},body:""}),Xe=o=>({status:302,headers:{Location:o},body:""});function Ye(o){switch(o.kind){case"exact":return{operator:le.Exact,version:B(o.major,o.minor,o.patch)};case"minor-pin":return{operator:le.Compatible,version:B(o.major,o.minor,0)};case"major-pin":return{operator:le.Major,version:B(o.major,0,0)};default:return{operator:le.Any,version:B(0,0,0)}}}async function Je(o,e,s,r){if(!r)return null;let n=o.producers?.find(f=>f.canProduce(o.publisher,e));if(!n)return null;let t=await n.resolveVersion(o.publisher,e,Ye(s));if(!t)return null;let u=I(t);if(s.kind!=="exact")return Xe(`/${e}/${u}.kan.yml`);let{source:p}=await n.produce(o.publisher,e,t);return w(200,S[".kan.yml"],p)}function Ve(o,e,s){let r=o.pkgVersions.get(e);if(!r||r.length===0)return null;switch(s.kind){case"any":return r[0].verStr;case"major-pin":return r.find(n=>n.version.major===s.major)?.verStr??null;case"minor-pin":return r.find(n=>n.version.major===s.major&&n.version.minor===s.minor)?.verStr??null;case"exact":return r.find(n=>n.version.major===s.major&&n.version.minor===s.minor&&n.version.patch===s.patch)?.verStr??null;default:return null}}async function ke(o,e,s=""){let{lookRenderer:r,publisher:n}=o;if(e==="/.well-known/kanonak.json")return o.configSource?w(200,S[".json"],o.configSource):w(200,S[".json"],JSON.stringify(Re(),null,2));if(e==="/kanonak.lock")return o.lockSource?w(200,S[".kan.yml"],o.lockSource):V(e);if(e===`/${K}`)return o.indexSource?w(200,S[".kan.yml"],o.indexSource):V(e);if(e==="/.well-known/kanonak-render.json")return w(200,S[".json"],JSON.stringify(ce(o),null,2));if(e==="/.well-known/kanonak-render")return w(200,S[".html"],he(ce(o)));if(e==="/"||e==="/index.html"||e==="/index.css"){let l=r.publisherSubject(n);return e==="/index.css"?w(200,S[".css"],r.renderStylesheet(l)):w(200,S[".html"],await r.renderDocument(l,{rootIndex:!0}))}let t=".html",u=!1,p=e;for(let l of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(l)){t=l,u=!0,p=e.slice(0,-l.length);break}let f=!u&&/application\/yaml|text\/yaml/i.test(s),h=p.endsWith("/");h&&p!=="/"&&(p=p.slice(0,-1));let a=_e.parse(p,n);if(!a)return V(e);if(a.kind==="package"){let l=Ve(o,a.package_,a.versionSpec);if(!l)return await Je(o,a.package_,a.versionSpec,t===".kan.yml"||f)??V(e);if(t===".kan.yml"||f){let k=o.rawByNsKey.get(`${a.package_}@${l}`);return k!==void 0?w(200,S[".kan.yml"],k):V(e)}let y=o.pkgSelfByVer.get(`${a.package_}@${l}`);if(!y)return V(e);if(t===".css")return w(200,S[".css"],r.renderStylesheet(y));if(!h)return ze(p+"/");let c=a.versionSpec.kind==="any";if(c&&!r.hasDeclaredView(y)){let k=(o.pkgVersions.get(a.package_)||[]).map(R=>R.verStr);return w(200,S[".html"],r.renderPackageVersionList(a.package_,k,y))}return w(200,S[".html"],await r.renderDocument(y,c?{bareOverview:!0}:void 0))}if(a.kind==="resource"){let l=Ve(o,a.package_,a.versionSpec);if(!l)return V(e);let y=o.bySubject.get(`${n}/${a.package_}@${l}/${a.name}`);if(!y)return V(e);switch(t){case".css":return w(200,S[".css"],r.renderStylesheet(y));case".svg":return w(200,S[".svg"],await r.renderSvg(y));case".md":{let c=r.renderRawMarkdown(y);return c===void 0?V(e):w(200,S[".md"],c)}default:return w(200,S[".html"],await r.renderDocument(y))}}return V(e)}import{readFileSync as Qe}from"fs";var Fe=/^\d+\.\d+\.\d+$/,fe=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,s=new Set;if(this.options.root!==void 0){let r=new C;for(let n of ne(this.options.root))try{let t=r.parse(Qe(n,"utf-8")).metadata?.namespace_;if(!t?.version)continue;let u=t.version;e.add(`${t.publisher}/${t.package_}@${u.major}.${u.minor}.${u.patch}`),s.add(`${t.publisher}/${t.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:s},this.workspaceIndex}async modelFor(e,s,r){let n=this.getWorkspaceIndex(),t={...this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},...this.options.packageUrlTemplates?{packageUrlTemplates:this.options.packageUrlTemplates}:{},...this.options.log?{log:this.options.log}:{}},u=s?r?n.exact.has(`${e}/${s}@${r}`):n.pkgs.has(`${e}/${s}`):[...n.pkgs].some(l=>l.startsWith(`${e}/`)),p,f;if(u&&this.options.root!==void 0){let l=this.options.root;p=`ws:${e}`,f=()=>ge(l,{publisher:e,...t})}else{let l=s?r?`${e}/${s}@${r}`:`${e}/${s}`:e;p=`rm:${l}`,f=()=>me(l,t)}let h=this.models.get(p);if(h)return h;let a=await f();return a.lookRenderer.setLinkMode("open-world"),this.models.set(p,a),a}async handle(e,s=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:Me()};let n=r[0];if(!n.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let t=r.length>=2&&(r[1]==="index.html"||r[1]==="index.css"||r[1]==="kanonak.lock"||r[1]===K||r[1]===".well-known"),u=!t&&r.length>=2?r[1]:void 0,p=!t&&r.length>=3&&Fe.test(r[2])?r[2]:void 0,f=await this.modelFor(n,u,p),h=e.endsWith("/")&&r.length>1?"/":"",a="/"+r.slice(1).join("/")+h,l=await ke(f,a,s);return l.headers.Location?{...l,headers:{...l.headers,Location:`/${n}${l.headers.Location}`}}:l}};function Ze(o){switch(o.kind){case"publisher":return`/${o.publisher}/`;case"package":return o.version?`/${o.publisher}/${o.package_}/${I(o.version)}/`:`/${o.publisher}/${o.package_}/`;case"resource":{let e=o.uri;return e.version?`/${e.publisher}/${e.package_}/${I(e.version)}/${e.name}`:`/${e.publisher}/${e.package_}/${e.name}`}}}function er(o){let e=o.split("/").filter(Boolean),s=e[0];if(!s||!s.includes("."))return;let r=e[1];if(!r)return{kind:"publisher",publisher:s};let n=e[2]&&Fe.test(e[2])?Z(e[2])??void 0:void 0,t=n?e[3]:e[2];return t?{kind:"resource",uri:new Se(s,r,t,n)}:n?{kind:"package",publisher:s,package_:r,version:n}:{kind:"package",publisher:s,package_:r}}function Me(){return'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kanonak origin</title></head><body style="font-family:system-ui;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>Kanonak request-driven origin</h1><p>Open a resource by its address:</p><p><code>/{publisher}/{package}/{version}/{resource}</code></p><p>e.g. <code>/kanonak.org/capabilities/2.0.0/Capability</code></p></body></html>'}export{q as ClosureScopedRepository,fe as RequestRouter,Ce as UNIVERSAL_RENDER_BASE,er as addressForRequestPath,ce as buildRenderDiagnostics,Y as buildRenderStackWarnings,z as chooseServedPublisher,H as deriveImportClosure,Me as landingPage,me as loadResourceModel,ge as loadServerModel,Oe as planWorkspaceVersionIndex,G as readWorkspacePackages,he as renderDiagnosticsHtml,E as renderRefKey,Ze as requestPathFor,X as resolveRenderContract,ke as route};
|
package/dist/server/route.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ServerModel, RouteResponse } from './types.js';
|
|
|
3
3
|
* Map one request to a response, using the same `LookRenderer` calls
|
|
4
4
|
* `kanonak publish` makes — so a live response is byte-equivalent to the
|
|
5
5
|
* static page `publish` would write — plus the machine-facing endpoints
|
|
6
|
-
* (`/.well-known/kanonak.json`, `/kanonak.lock`, raw `.kan.yml`), which
|
|
6
|
+
* (`/.well-known/kanonak.json`, `/kanonak.lock`, `/kanonak.index`, raw `.kan.yml`), which
|
|
7
7
|
* `publish` freezes to disk rather than omitting.
|
|
8
8
|
*
|
|
9
9
|
* Pure: `pathname` in, response out. No filesystem or network I/O — raw
|
package/dist/server/types.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export interface ServerModel {
|
|
|
54
54
|
* pins no closure (the lock endpoint 404s).
|
|
55
55
|
*/
|
|
56
56
|
readonly lockSource?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The served publisher's `kanonak.index` source (verbatim YAML), when present
|
|
59
|
+
* in the workspace: every version it has published, each with its sha256 and
|
|
60
|
+
* its yank. Served at `/kanonak.index`; absent → that endpoint 404s.
|
|
61
|
+
*/
|
|
62
|
+
readonly indexSource?: string;
|
|
57
63
|
/**
|
|
58
64
|
* The served publisher's authored `.well-known/kanonak.json` source (verbatim),
|
|
59
65
|
* when present in the workspace. This is how a publisher DECLARES its bootstrap
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { KanonakParser } from '../parsing/KanonakParser.js';
|
|
2
|
+
import type { Version } from '@kanonak-protocol/types/document/models/types';
|
|
3
|
+
/** One versioned package a workspace holds, with its raw source. */
|
|
4
|
+
export interface WorkspacePackage {
|
|
5
|
+
publisher: string;
|
|
6
|
+
package_: string;
|
|
7
|
+
verStr: string;
|
|
8
|
+
version: Version;
|
|
9
|
+
source: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Every versioned package under `workspaceRoot`, highest version first: the
|
|
13
|
+
* set a publisher origin serves from, and its `kanonak.index` records. A file
|
|
14
|
+
* that can't be read or parsed, or that states no version, is not a package
|
|
15
|
+
* the workspace publishes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readWorkspacePackages(workspaceRoot: string, parser?: KanonakParser): WorkspacePackage[];
|
|
18
|
+
/**
|
|
19
|
+
* The one publisher a workspace origin serves: `requested` when given and
|
|
20
|
+
* present, else the workspace's only publisher. Throws for an empty workspace,
|
|
21
|
+
* a requested publisher it doesn't hold, or several publishers and no choice.
|
|
22
|
+
*/
|
|
23
|
+
export declare function chooseServedPublisher(packages: readonly WorkspacePackage[], workspaceRoot: string, requested?: string): {
|
|
24
|
+
publisher: string;
|
|
25
|
+
availablePublishers: string[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type VersionIndex, type VersionIndexPlan } from '../lock/VersionIndex.js';
|
|
2
|
+
import type { PublisherIndex } from '../repositories/PublisherIndex.js';
|
|
3
|
+
export interface WorkspaceVersionIndex {
|
|
4
|
+
publisher: string;
|
|
5
|
+
/** Where the workspace keeps its index: `{workspaceRoot}/kanonak.index`. */
|
|
6
|
+
path: string;
|
|
7
|
+
/** The index the workspace holds now, or null when it has none. */
|
|
8
|
+
current: VersionIndex | null;
|
|
9
|
+
/** The index the publisher's origin serves, or null when it serves none. */
|
|
10
|
+
served: VersionIndex | null;
|
|
11
|
+
plan: VersionIndexPlan;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Plan the `kanonak.index` of the publisher a workspace serves, chosen as
|
|
15
|
+
* `kanonak serve` chooses it: its versions are the ones the workspace holds,
|
|
16
|
+
* checked against what the publisher's origin already serves, read through
|
|
17
|
+
* `publisherIndex`. `kanonak index` writes the plan, and `kanonak publish`
|
|
18
|
+
* refuses to publish unless the workspace's index already is it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function planWorkspaceVersionIndex(workspaceRoot: string, options: {
|
|
21
|
+
publisher?: string;
|
|
22
|
+
publisherIndex: PublisherIndex;
|
|
23
|
+
}): Promise<WorkspaceVersionIndex>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pe}from"../chunk-FYAZ345F.js";import"../chunk-
|
|
1
|
+
import{a as pe}from"../chunk-FYAZ345F.js";import"../chunk-C5HHCD6P.js";import{a as ve,b as M,c as Vn,n as X,o as Rn,p as vn,q as le,r as Ln,s as q,u as G}from"../chunk-A4OVTNMT.js";import"../chunk-QHABFCRC.js";import"../chunk-YEUSFSC7.js";import{b as $n,c as Tn,d as Bn,e as xn,f as Un,k as fe}from"../chunk-A5EAI5ZU.js";import{a as se}from"../chunk-VAZY57HJ.js";import"../chunk-PEJALHXK.js";import{c as U}from"../chunk-TVMOJ2QS.js";import{b as Y,c as D,d as ce,e as E,f as ue,i as $,j as T,k as B,l as w,m as me,n as x,o as de,q as N,r as S,y as A}from"../chunk-6USORWEP.js";import"../chunk-F67UH4FD.js";import{g as ie}from"../chunk-7IMLHHSA.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
|
|
2
2
|
`);return t?.trailingNewline&&(s.endsWith(`
|
|
3
3
|
`)||(s+=`
|
|
4
4
|
`)),s}};function Ie(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(P(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(P(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(P),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=P(f??c),d=ye(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function P(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function ye(e,n){switch(e.kind){case"StringScalar":return _e(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=ye(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function _e(e,n){return!n||ge(n,m.ESC_RAW)?e:ge(n,m.ESC_YAML_SAFE)?Ce(e):e}function Ce(e){return e.includes(`
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as y,B as z,C as A,D as B,E as C,F as D,G as E,H as F,I as G,J as H,K as I,L as J,M as K,N as L,O as M,a,b,c,d,e,h as f,i as g,j as h,k as i,l as j,m as k,n as l,o as m,p as n,q as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"../chunk-
|
|
1
|
+
import{A as y,B as z,C as A,D as B,E as C,F as D,G as E,H as F,I as G,J as H,K as I,L as J,M as K,N as L,O as M,a,b,c,d,e,h as f,i as g,j as h,k as i,l as j,m as k,n as l,o as m,p as n,q as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"../chunk-IZBZDLCX.js";import"../chunk-QRF7AT2M.js";import"../chunk-A4OVTNMT.js";import"../chunk-QHABFCRC.js";import"../chunk-5FVUBF7N.js";import"../chunk-YEUSFSC7.js";import"../chunk-A5EAI5ZU.js";import"../chunk-VAZY57HJ.js";import"../chunk-PEJALHXK.js";import"../chunk-TVMOJ2QS.js";import"../chunk-6USORWEP.js";import"../chunk-F67UH4FD.js";import"../chunk-7IMLHHSA.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,o as ClassHierarchyCycleRule,L as DiamondNameClashRule,D as DisplayLensScopeRule,l as EmbeddedKanonakTypeRule,m as ImportExistenceRule,M as KanonakObjectValidator,f as LinkTargetRule,H as LookBandPathRule,E as LookSemanticSvgPathRule,C as MarkdownLinkRule,t as NamespaceImportCycleRule,g as NamespacePrefixRule,x as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,K as OwlOneOfRule,k as PackageHeaderRule,y as PropertyDomainRule,p as PropertyHierarchyCycleRule,z as PropertyKindRangeConsistencyRule,w as PropertyRangeReferenceRule,q as PropertyRangeRequiredRule,i as PropertyTypeSpecificityRule,A as ReservedNameShadowRule,h as ResourceNamingRule,G as SequenceNarrativeRule,J as ShaclShapeRule,r as SubClassOfReferenceRule,s as SubPropertyOfReferenceRule,j as SubjectKanonakTypeRequiredRule,F as TxExpressionCompilesRule,I as TxExpressionPathRule,u as UnresolvedPredicateRule,n as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
],
|
|
136
136
|
"dependencies": {
|
|
137
137
|
"@kanonak-protocol/canonical": "^0.1.3",
|
|
138
|
-
"@kanonak-protocol/types": "^
|
|
138
|
+
"@kanonak-protocol/types": "^7.0.0",
|
|
139
139
|
"ignore": "^7.0.5",
|
|
140
140
|
"js-yaml": "^4.1.0",
|
|
141
141
|
"yaml": "^2.7.0",
|
package/dist/chunk-3ABGZHKM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as i,p as o,q as r}from"./chunk-X2URIXH7.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
|
package/dist/chunk-6CI3HTKF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as d}from"./chunk-F67UH4FD.js";import{a as l,b as h}from"./chunk-7IMLHHSA.js";import*as c from"js-yaml";var y=new Set(["Package","EphemeralPackage"]);function f(m){return typeof m=="string"&&y.has(m)}var g=class{parse(e){let r=this.parseWithErrors(e);if(!r.isValid){let n=r.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return r.document}parseWithErrors(e){let r=[],n;try{e=e.replace(/^\uFEFF/,"");let a=c.load(e,{schema:c.FAILSAFE_SCHEMA});if(!a||typeof a!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:r,isValid:!0};let t=this.extractMetadata(a),o=this.extractBody(a,t);return n={metadata:t,body:o,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:r,isValid:!0}}catch(a){let t=a,o=t.mark?t.mark.line+1:0,i=t.mark?t.mark.column+1:0,s={message:t.message||"Unknown parse error",line:o,column:i,errorType:t.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${t.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${o}: ${t.message||"Unknown parse error"}`};return r.push(s),{document:void 0,errors:r,isValid:!1}}}save(e){let r={};if(e.metadata.namespace_){let n=e.metadata.namespace_,a={type:"Package",publisher:n.publisher};n.version&&(a.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(a.imports=this.serializeImports(e.metadata.imports)),r[n.package_]=a}return Object.assign(r,e.body),c.dump(r,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let r=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!r)return[];let n=[];for(let a of Object.values(r))n.push(...a);return n},enumerable:!0,configurable:!0}),e}createVersion(e,r,n){return{major:e,minor:r,patch:n,toString:()=>`${e}.${r}.${n}`,equals:t=>!t||typeof t!="object"?!1:t.major===e&&t.minor===r&&t.patch===n,getHashCode:()=>e<<20|r<<10|n,compareTo:t=>e!==t.major?e-t.major:r!==t.minor?r-t.minor:n-t.patch}}extractMetadata(e){let r=this.createEmptyMetadata();for(let[n,a]of Object.entries(e))if(a&&typeof a=="object"&&f(a.type)){r.type_=a.type;let t=n,o=a.publisher,i=a.version?this.parseVersion(a.version):void 0;return o&&t&&(r.namespace_={publisher:o,package_:t,version:i,toString:function(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}`:`${this.publisher}/${this.package_}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===o&&s.package_===t&&(!i||!s.version||i.equals(s.version)),getHashCode:()=>{let s=0;for(let p=0;p<o.length;p++)s=(s<<5)-s+o.charCodeAt(p);for(let p=0;p<t.length;p++)s=(s<<5)-s+t.charCodeAt(p);return s|0}}),a.imports&&Array.isArray(a.imports)&&(r.imports=this.parseImportsV3(a.imports)),this.addAllImportsGetter(r)}return r}extractBody(e,r){let n={};for(let[a,t]of Object.entries(e))if(t&&typeof t=="object"&&f(t.type)){let o={};for(let[i,s]of Object.entries(t))i==="publisher"||i==="version"||i==="imports"||(o[i]=s);n[a]=o}else n[a]=t;return n}parseVersion(e){if(typeof e=="string"){let r=e.split(".").map(Number);return this.createVersion(r[0]||0,r[1]||0,r[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let r={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let a=n.publisher;if(!a)throw new Error("PublisherImport requires 'publisher' property");r[a]||(r[a]=[]);for(let t of n.packages){if(!t||typeof t!="object")continue;let o=this.parseImportFromEmbeddedObject(t,a);r[a].push(o)}}else{let a=this.parseImportFromEmbeddedObject(n,n.publisher),t=a.publisher||"";r[t]||(r[t]=[]),r[t].push(a)}return r}parseImportFromEmbeddedObject(e,r){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let a=e.match;if(!a)throw new Error("Import requires 'match' property");let t=e.version;if(!t)throw new Error("Import requires 'version' property");let o;if(e.mode!==void 0&&e.mode!==null){if(!d.includes(e.mode))throw new Error(`Import '${n}' has an unknown mode '${e.mode}'; expected one of: ${d.join(", ")}`);o=e.mode}return this.makeImport(n,a,t,r,e.alias,o)}makeImport(e,r,n,a,t,o){let i=this.parseVersion(n),s=this.parseVersionOperator(r),p=this.calculateMaxVersion(r,i);return{package_:`${e} ${r} ${i.toString()}`,publisher:a,packageName:e,versionOperator:s,version:i,alias:t,...o?{mode:o}:{},minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let u={package:e,match:r,version:i.toString()};return t&&(u.alias=t),o&&(u.mode=o),u},toString:()=>t?`${e} ${r} ${i.toString()} as ${t}`:`${e} ${r} ${i.toString()}`}}buildImport(e,r,n,a){return this.makeImport(e,r,n,a)}parseVersionOperator(e){return l(e)}calculateMaxVersion(e,r){switch(e){case"~":return this.createVersion(r.major,r.minor+1,0);case"^":return r.major===0?this.createVersion(0,r.minor+1,0):this.createVersion(r.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let r=[];for(let[n,a]of Object.entries(e)){let t={publisher:n,packages:a.map(o=>{let i=h(o.versionOperator),s={package:o.packageName,match:i,version:`${o.version.major}.${o.version.minor}.${o.version.patch}`};return o.alias&&(s.alias=o.alias),s})};r.push(t)}return r}};export{g as a};
|
package/dist/chunk-F4UHQVGA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as F,u as A}from"./chunk-X2URIXH7.js";import{a as P}from"./chunk-NYCGUDVW.js";import{a as f}from"./chunk-6CI3HTKF.js";import{c as K,g as I,j as R}from"./chunk-7IMLHHSA.js";import*as m from"fs/promises";import*as i from"path";import{pathToFileURL as b}from"url";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=i.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=i.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=i.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;return R(r,t)});return s.length===0?null:(s.sort((a,r)=>{let l=a.metadata.namespace_.version,u=r.metadata.namespace_.version;return K(u,l)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let l=o.split("/"),u=l[0],h=l[1].replace("@","@")+".kan.yml";n=i.join(this.rootPath,u,h)}else n=i.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=i.dirname(n);await m.mkdir(s,{recursive:!0});let a=this.parser.save(e);await m.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=i.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await m.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=i.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=i.join(this.rootPath,e);try{let s=await m.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await m.unlink(i.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=b(n).toString(),s;for(let[l,u]of this.documentCache.entries())if(this.filePathsByIdentifier.get(l)===n&&u.metadata.namespace_){s=u.metadata.namespace_.toString();break}let a=s??i.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.access(n),t=n}catch{return null}}try{return await m.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.access(n),t=n}catch{return null}}return b(t).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 m.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await m.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=i.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let l=s.metadata.namespace_.toString();this.documentCache.set(l,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(l,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await m.readdir(e,{withFileTypes:!0});for(let s of o){let a=i.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),D=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as H}from"os";import{join as T}from"path";function d(){let c=process.env.KANONAK_PACKAGE_CACHE;return c||T(H(),".kanonak","packages")}var w=class c{static createComposite(e,t,n){let o=e??d(),s=t??".";return new D(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return c.createComposite(t,n,e)}};var k=class{repos;constructor(...e){this.repos=e}async firstAnswer(e,t,n){let o=[];for(let s of this.repos)try{let a=await e(s);if(t(a))return a}catch(a){o.push(a)}return x(o),n}async getHighestCompatibleVersionAsync(e,t){return this.firstAnswer(n=>n.getHighestCompatibleVersionAsync(e,t),n=>n!==null,null)}async getAllDocumentsAsync(){let e=[],t=new Set,n=[];for(let o of this.repos)try{for(let s of await o.getAllDocumentsAsync()){let a=s.metadata?.namespace_,r=a?a.version?`${a.publisher}/${a.package_}@${a.version.major}.${a.version.minor}.${a.version.patch}`:`${a.publisher}/${a.package_}`:void 0;if(r!==void 0){if(t.has(r))continue;t.add(r)}e.push(s)}}catch(s){n.push(s)}return x(n),e}async getDocumentAsync(e){return this.firstAnswer(t=>t.getDocumentAsync(e),t=>t!==null,null)}async getDocumentsByNamespaceAsync(e,t){return this.firstAnswer(n=>n.getDocumentsByNamespaceAsync(e,t),n=>n.length>0,[])}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){return this.firstAnswer(t=>t.getDocumentContentAsync(e),t=>!!t,null)}async getDocumentUriAsync(e){return this.firstAnswer(t=>t.getDocumentUriAsync(e),t=>!!t,null)}};function x(c){if(c.length===1)throw c[0];if(c.length>1)throw new Error(c.map(e=>e instanceof Error?e.message:String(e)).join("; "))}import{VersionOperator as N}from"@kanonak-protocol/types/document/models/enums";var v=class{constructor(e,t){this.base=e;this.lock=t}base;lock;pinnedVersion(e,t){return F(this.lock,e,t)}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator:N.Exact,version:o};return this.base.getHighestCompatibleVersionAsync(e,s)}}return this.base.getHighestCompatibleVersionAsync(e,t)}async getDocumentsByNamespaceAsync(e,t){let n=await this.base.getDocumentsByNamespaceAsync(e,t),o=this.pinnedVersion(e,t);return o?n.filter(s=>{let a=s.metadata.namespace_?.version;return a?`${a.major}.${a.minor}.${a.patch}`===o:!1}):n}getAllDocumentsAsync(){return this.base.getAllDocumentsAsync()}getDocumentAsync(e){return this.base.getDocumentAsync(e)}saveDocumentAsync(e,t){return this.base.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.base.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.base.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.base.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.base.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.base.getDocumentUriAsync(e)}};import{readFileSync as B,readdirSync as U}from"fs";import{join as _}from"path";var V=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(c,e=[]){for(let t of U(c,{withFileTypes:!0}))t.isDirectory()?V.has(t.name)||C(_(c,t.name),e):t.name.endsWith(".kan.yml")&&e.push(_(c,t.name));return e}async function $(c,e=new f,t={}){let n=new P(e);for(let l of C(c))try{let u=e.parse(B(l,"utf-8")),p=u.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(u,`${p.publisher}/${p.package_}@${h.major}.${h.minor}.${h.patch}`)}catch{}let o=new y(d(),!0,e);if(t.offline)return new k(n,o);let s=new Map,a=t.httpCache??{getFromCache:(l,u,p)=>s.get(`${l}|${u}|${p}`)??null,onFetch:(l,u,p,h)=>{s.set(`${l}|${u}|${p}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch,...t.fetchFn?{fetchFn:t.fetchFn}:{},...t.packageUrlTemplates?{packageUrlTemplates:t.packageUrlTemplates}:{}});return new k(n,o,r)}export{y as a,S as b,D as c,d,w as e,k as f,v as g,C as h,$ as i};
|
package/dist/chunk-NYCGUDVW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as m,j as i}from"./chunk-7IMLHHSA.js";var u=class{documents=new Map;documentContents=new Map;parser;constructor(e){this.parser=e}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,n){let t=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===n&&t.push(s);return t}async getHighestCompatibleVersionAsync(e,n){let t=[];for(let a of this.documents.values())a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===n.packageName&&a.metadata?.namespace_?.version!==void 0&&t.push(a);if(t.length===0)return null;let s=t.filter(a=>{let o=a.metadata.namespace_.version;return o?i(o,n):!1});return s.length===0?null:(s.sort((a,o)=>{let r=a.metadata.namespace_.version,c=o.metadata.namespace_.version;return!r&&!c?0:r?c?m(c,r):-1:1}),s[0])}async saveDocumentAsync(e,n){this.documents.set(n,e);let t=this.parser.save(e);this.documentContents.set(n,t)}async deleteDocumentAsync(e){this.documents.delete(e),this.documentContents.delete(e)}async clearNamespaceAsync(e,n){let t=[];for(let[s,a]of this.documents.entries())a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===n&&t.push(s);for(let s of t)this.documents.delete(s),this.documentContents.delete(s)}async getAllDocumentReferencesAsync(){let e=[];for(let n of this.documents.values())n.metadata?.namespace_&&e.push({identifier:n.metadata.namespace_.toString(),uri:`kanonak://${n.metadata.namespace_}`,hasParseError:!1});return e}async getDocumentContentAsync(e){let n=this.documentContents.get(e);if(n!==void 0)return n;let t=this.documents.get(e);return t!==void 0?this.parser.save(t):null}async getDocumentUriAsync(e){let n=this.documents.get(e);return n?n.metadata?.namespace_?`kanonak://${n.metadata.namespace_}`:`kanonak://${e}`:null}};export{u as a};
|
package/dist/chunk-ODIECDN7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import s from"ignore";import*as n from"fs";import*as t from"path";var o=class{ignoreInstance;basePath;constructor(e){this.basePath=e;let r=t.join(e,".gitignore");if(n.existsSync(r))try{let i=n.readFileSync(r,"utf8");this.ignoreInstance=s(),this.ignoreInstance.add(i)}catch{this.ignoreInstance=null}else this.ignoreInstance=null}shouldIgnore(e){if(!this.ignoreInstance)return!1;let i=t.relative(this.basePath,e).split(t.sep).join("/");return this.ignoreInstance.ignores(i)}};export{o as a};
|