@kanonak-protocol/sdk 3.69.0 → 3.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/chunk-4NO7MHS7.js +1 -0
  3. package/dist/{chunk-N224PFBI.js → chunk-BGQKZBNE.js} +1 -1
  4. package/dist/chunk-CRKSKIAL.js +1 -0
  5. package/dist/chunk-F5ANO7MJ.js +1 -0
  6. package/dist/chunk-FX7JDGL6.js +1 -0
  7. package/dist/chunk-G2DKKSZ4.js +1 -0
  8. package/dist/{chunk-7JZUJ2K4.js → chunk-GN2XODVC.js} +1 -1
  9. package/dist/chunk-HAR3BNTB.js +2 -0
  10. package/dist/chunk-IOMNZBK4.js +1 -0
  11. package/dist/chunk-MCU5IAMS.js +148 -0
  12. package/dist/chunk-OFSARZX6.js +1 -0
  13. package/dist/chunk-RRODBYIK.js +74 -0
  14. package/dist/chunk-SHDHMKMJ.js +1 -0
  15. package/dist/chunk-TJPQETHV.js +1 -0
  16. package/dist/chunk-Y7TGQ7UF.js +2 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +26 -26
  19. package/dist/look/LookRenderer.d.ts +29 -1
  20. package/dist/parsing/index.js +1 -1
  21. package/dist/reasoning/index.js +1 -1
  22. package/dist/repositories/browser.js +1 -1
  23. package/dist/repositories/index.js +1 -1
  24. package/dist/resolution/index.js +1 -1
  25. package/dist/search/index.js +1 -1
  26. package/dist/server/index.js +2 -2
  27. package/dist/server/route.d.ts +1 -1
  28. package/dist/transformations/index.js +47 -47
  29. package/dist/transformations/v3/CompiledTransformationV3.d.ts +6 -2
  30. package/dist/transformations/v3/ExpressionEngineV3.d.ts +13 -1
  31. package/dist/transformations/v3/TransformationLoaderV3.d.ts +19 -2
  32. package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +5 -0
  33. package/dist/uri-helpers/UriHelpers.d.ts +18 -0
  34. package/dist/uri-helpers/index.d.ts +1 -1
  35. package/dist/uri-helpers/index.js +1 -1
  36. package/dist/validation/TxExpressionPathChecker.d.ts +39 -0
  37. package/dist/validation/index.d.ts +1 -1
  38. package/dist/validation/index.js +1 -1
  39. package/dist/validation/rules/repository/LookSemanticSvgPathRule.d.ts +26 -0
  40. package/dist/validation/rules/repository/TxExpressionPathRule.d.ts +28 -0
  41. package/dist/validation/rules/repository/index.d.ts +2 -0
  42. package/dist/view/ViewMaterializer.d.ts +71 -0
  43. package/dist/view/index.d.ts +2 -0
  44. package/package.json +2 -2
  45. package/dist/chunk-64TVBQFR.js +0 -1
  46. package/dist/chunk-767XYRNU.js +0 -1
  47. package/dist/chunk-CA2EATJR.js +0 -1
  48. package/dist/chunk-FXKT6OI4.js +0 -148
  49. package/dist/chunk-H2LEQLVD.js +0 -1
  50. package/dist/chunk-KSTGTV35.js +0 -2
  51. package/dist/chunk-OIVACCMQ.js +0 -59
  52. package/dist/chunk-ORFSMEMM.js +0 -1
  53. package/dist/chunk-Q4DKP5DO.js +0 -1
  54. package/dist/chunk-Q6QTQWR2.js +0 -1
  55. package/dist/chunk-QHJ6EY3Y.js +0 -1
  56. package/dist/chunk-RSIZQAFL.js +0 -2
  57. /package/dist/{chunk-3NEUHF7E.js → chunk-QHABFCRC.js} +0 -0
@@ -86,6 +86,24 @@ export declare function findSubjectsByType(kanonaks: Kanonak[], target: EntityUr
86
86
  * bare-name references in single-version workspaces, etc).
87
87
  */
88
88
  export declare function findSubjectByUri(kanonaks: Kanonak[], uri: KanonakUri): SubjectKanonak | undefined;
89
+ /**
90
+ * Every version of a subject present in the catalog, matched by canonical
91
+ * URI (publisher/package/name, version-agnostic), HIGHEST VERSION FIRST.
92
+ *
93
+ * This is THE single place the "newest wins" multi-version rule lives, so
94
+ * every cascade that takes the first match (semanticSvg, tokens, the type
95
+ * chain, path/traversal resolution) resolves to the newest version's
96
+ * open-world augmentation — an archived older version can never shadow the
97
+ * current one — and all environments (serve, publish, validate, the VS Code
98
+ * server, the transformation engine) render identically without each
99
+ * reimplementing (or forgetting) the load-order sort. Do not duplicate this:
100
+ * import it.
101
+ */
102
+ export declare function findAllResourcesByCanonicalUri(catalog: Kanonak[], uri: {
103
+ publisher: string;
104
+ package_: string;
105
+ name: string;
106
+ }): SubjectKanonak[];
89
107
  /**
90
108
  * Read a datatype property value (string, number, boolean) off a defined
91
109
  * kanonak, by property URI. Returns `undefined` when the property is not
@@ -1,3 +1,3 @@
1
- export { uriKey, uriMatches, toCanonicalUrl, hasType, findSubjectsByType, findSubjectByUri, getDatatypeValue, getStringValue, getReferenceUri, getEmbeddedValue, getListValues, } from './UriHelpers.js';
1
+ export { uriKey, uriMatches, toCanonicalUrl, hasType, findSubjectsByType, findSubjectByUri, findAllResourcesByCanonicalUri, getDatatypeValue, getStringValue, getReferenceUri, getEmbeddedValue, getListValues, } from './UriHelpers.js';
2
2
  export type { EntityUri, CanonicalUriParts } from './UriHelpers.js';
3
3
  export { SingleDocumentRepository } from './SingleDocumentRepository.js';
@@ -1 +1 @@
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};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"../chunk-CRKSKIAL.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{m as SingleDocumentRepository,g as findAllResourcesByCanonicalUri,f as findSubjectByUri,e as findSubjectsByType,h as getDatatypeValue,k as getEmbeddedValue,l as getListValues,j as getReferenceUri,i as getStringValue,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
@@ -0,0 +1,39 @@
1
+ import type { Kanonak } from '../kanonaks/Kanonak.js';
2
+ import { EmbeddedKanonak } from '../kanonaks/EmbeddedKanonak.js';
3
+ import { type EntityUri } from '../uri-helpers/index.js';
4
+ /**
5
+ * One out-of-scope path step found while walking a `tx.Expression` tree.
6
+ * `contextClass` is the type the step was read against (the View's bound
7
+ * class for a top-level read, or an intermediate type reached after one
8
+ * or more traversals); `propertyUri` is the offending property; `via`
9
+ * records which step kind referenced it.
10
+ */
11
+ export interface TxPathFailure {
12
+ contextClass: EntityUri;
13
+ propertyUri: EntityUri;
14
+ via: 'PropertyRead' | 'Traverse';
15
+ }
16
+ /**
17
+ * Walk a `tx.Expression` tree and report every `tx.PropertyRead` /
18
+ * `tx.Traverse` step whose property is not in scope for the type it is
19
+ * read against. The bound instance is available as the `input` binding,
20
+ * typed `rootContext`. Context advances through each resolved property's
21
+ * declared `range`, so multi-step paths (a `tx.Traverse` whose `step`
22
+ * reads a property off the traversed-to subject, or a `tx.PropertyRead`
23
+ * whose `readSource` is itself a read) are validated step-by-step.
24
+ *
25
+ * This is the canonical path-chain checker behind both
26
+ * `LookSemanticSvgPathRule` (context = the class a `look.semanticSvg` is
27
+ * declared on) and `TxExpressionPathRule` (context = a `view.View`'s
28
+ * `view.bind`). It resolves every property through the object model via
29
+ * `resolvePropertyStep`, never by local name.
30
+ *
31
+ * Scope notes: a `VarRef` to any name other than a known class-typed
32
+ * binding (e.g. the pre-computed `label`/`uri` env strings, or an
33
+ * iterator's element variable) yields an unknown type, so reads rooted at
34
+ * it are left unchecked rather than falsely flagged — the same
35
+ * conservative stance the engine takes at render time. Traversing a step
36
+ * whose range is a datatype is not yet rejected here (the "can't traverse
37
+ * past a literal" refinement); only out-of-scope properties are reported.
38
+ */
39
+ export declare function checkTxExpressionPaths(catalog: Kanonak[], rootContext: EntityUri, expr: EmbeddedKanonak): TxPathFailure[];
@@ -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, DisplayLensScopeRule } 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, LookSemanticSvgPathRule, TxExpressionPathRule } from './rules/repository/index.js';
@@ -1 +1 @@
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-OIVACCMQ.js";import"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import"../chunk-ORFSMEMM.js";import"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.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};
1
+ import{A,B,C,D,E,F,G,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-RRODBYIK.js";import"../chunk-SHDHMKMJ.js";import"../chunk-G2DKKSZ4.js";import"../chunk-TJPQETHV.js";import"../chunk-BGQKZBNE.js";import"../chunk-CRKSKIAL.js";import"../chunk-IOMNZBK4.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.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,G as KanonakObjectValidator,E as LookSemanticSvgPathRule,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,F as TxExpressionPathRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
@@ -0,0 +1,26 @@
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 that `tx.PropertyRead` / `tx.Traverse` steps inside
8
+ * `look.semanticSvg` tier fragments reference properties in scope for the
9
+ * class on which the SemanticSvg is declared. When a tier authored on
10
+ * class C reads property P off the rendered instance, P's domain must
11
+ * cover C (the class itself, an ancestor, or rdfs.Resource); otherwise
12
+ * the read silently returns undefined at render time and the tier's
13
+ * substitution leaks empty.
14
+ *
15
+ * The path walk is the shared, context-advancing
16
+ * `checkTxExpressionPaths` — the same engine `TxExpressionPathRule` uses
17
+ * for `view.View` projections. This rule only supplies the look-specific
18
+ * root context (the declaring class) and the look-specific diagnostic
19
+ * wording.
20
+ */
21
+ export declare class LookSemanticSvgPathRule implements IRepositoryValidationRule {
22
+ readonly ruleName = "LookSemanticSvgPath";
23
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
24
+ private checkSemanticSvg;
25
+ private toError;
26
+ }
@@ -0,0 +1,28 @@
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 projection paths of a `view.View` against its bound
8
+ * class. A View declares `view.bind` (its context class) and a list of
9
+ * `view.Projection`s whose `view.value` is a `tx.Expression` computed
10
+ * against each bound instance, plus optional `view.where` predicate
11
+ * expressions. Every `tx.PropertyRead` / `tx.Traverse` step inside those
12
+ * expressions must reference a property in scope for the type it is read
13
+ * against (the bound class, or an intermediate type reached by an earlier
14
+ * traversal) — otherwise the read silently returns undefined when the
15
+ * View materializes.
16
+ *
17
+ * Shares the context-advancing path walker with `LookSemanticSvgPathRule`
18
+ * (`checkTxExpressionPaths`); the only difference is the root context —
19
+ * here the View's `view.bind`, there the class a `look.semanticSvg` is
20
+ * declared on. The generalized form tracked in typescript#48.
21
+ */
22
+ export declare class TxExpressionPathRule implements IRepositoryValidationRule {
23
+ readonly ruleName = "TxExpressionPath";
24
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
25
+ private checkView;
26
+ private asError;
27
+ private toError;
28
+ }
@@ -20,3 +20,5 @@ export { ClassDefinitionRule } from './ClassDefinitionRule.js';
20
20
  export { EmbeddedKanonakTypeRule } from './EmbeddedKanonakTypeRule.js';
21
21
  export { MarkdownLinkRule } from './MarkdownLinkRule.js';
22
22
  export { DisplayLensScopeRule } from './DisplayLensScopeRule.js';
23
+ export { LookSemanticSvgPathRule } from './LookSemanticSvgPathRule.js';
24
+ export { TxExpressionPathRule } from './TxExpressionPathRule.js';
@@ -0,0 +1,71 @@
1
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
+ import { KanonakParser } from '../parsing/KanonakParser.js';
3
+ import { type EntityUri } from '../uri-helpers/index.js';
4
+ export interface MaterializeOptions {
5
+ /**
6
+ * ISO-8601 timestamp recorded as the EphemeralPackage's `resolvedAt`.
7
+ * The SDK never reads the clock itself (it would make results
8
+ * non-deterministic and untestable); the caller supplies it. Omitted →
9
+ * no `resolvedAt` is written. It lives on the header, outside the hashed
10
+ * body, so two identical runs still share a content hash.
11
+ */
12
+ resolvedAt?: string;
13
+ /** Optional per-invocation id recorded as `id` (also header-only). */
14
+ invocationId?: string;
15
+ /** Reasoning profile used to find instances of `bind`. */
16
+ reasoningProfile?: 'rdfs' | 'owl-rl-classification';
17
+ }
18
+ export interface MaterializeResult {
19
+ /** The EphemeralPackage as `.kan.yml` text. */
20
+ yaml: string;
21
+ /** `sha256:` content hash of the body (the `ck.contentHash` value). */
22
+ contentHash: string;
23
+ /** Address-safe package name (`q-<hex16>`), derived from the hash. */
24
+ packageName: string;
25
+ /** Publisher the EphemeralPackage is minted under (the View's publisher). */
26
+ publisher: string;
27
+ /** Number of result instances produced. */
28
+ rowCount: number;
29
+ }
30
+ /**
31
+ * The in-graph producer for the View Language. Given a `view.View` (or a
32
+ * `view.ViewPackage` whose `rootView` is one), it resolves the View
33
+ * against the local catalog and materializes the result as a versionless
34
+ * `EphemeralPackage`:
35
+ *
36
+ * 1. find every instance of the View's `bind` class (subclass-aware,
37
+ * via the reasoner);
38
+ * 2. keep those for which every `where` predicate holds;
39
+ * 3. for each, mint one `produces` instance whose properties are the
40
+ * projections (`value` evaluated against the instance, stored under
41
+ * `as`), plus a `view.derivedFrom` reference back to the stable
42
+ * source — a reference, never a copy;
43
+ * 4. wrap the instances in an EphemeralPackage whose import closure makes
44
+ * the shape self-describing, with a content-hash identity.
45
+ *
46
+ * This is one producer behind a producer-agnostic contract: a backend
47
+ * binding (Polygon, DynamoDB, …) fulfils the same View by emitting the
48
+ * same EphemeralPackage shape. Selection views (no `produces`) are not yet
49
+ * materialized here and fail visibly rather than guessing a shape.
50
+ */
51
+ export declare class ViewMaterializer {
52
+ private readonly repository;
53
+ private readonly parser;
54
+ private readonly objectParser;
55
+ constructor(repository: IKanonakDocumentRepository, parser?: KanonakParser);
56
+ materialize(viewRef: EntityUri, opts?: MaterializeOptions): Promise<MaterializeResult>;
57
+ private resolveView;
58
+ private readProjections;
59
+ private reason;
60
+ private findInstances;
61
+ private passesWhere;
62
+ private evaluateValue;
63
+ private rowName;
64
+ /**
65
+ * Content hash of the body, independent of the EphemeralPackage's own
66
+ * (not-yet-assigned) name. Parses the rows under a fixed probe header,
67
+ * neutralizes each body subject's namespace to a constant, and hashes —
68
+ * so the same projected data always yields the same `sha256:`.
69
+ */
70
+ private hashBody;
71
+ }
@@ -0,0 +1,2 @@
1
+ export { ViewMaterializer } from './ViewMaterializer.js';
2
+ export type { MaterializeOptions, MaterializeResult } from './ViewMaterializer.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.69.0",
3
+ "version": "3.71.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",
@@ -122,7 +122,7 @@
122
122
  "yaml-parser"
123
123
  ],
124
124
  "dependencies": {
125
- "@kanonak-protocol/types": "^3.69.0",
125
+ "@kanonak-protocol/types": "^3.71.0",
126
126
  "ignore": "^7.0.5",
127
127
  "js-yaml": "^4.1.0",
128
128
  "yaml": "^2.7.0"
@@ -1 +0,0 @@
1
- import{a as P}from"./chunk-FUUTGGJS.js";function K(n){if(Array.isArray(n))return n.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=n?.toString();return e?[e]:[]}var S=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let a=t.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(a);if(s){let p=s.get(e);if(p)return p}let r=await this.buildEntityIndexAsyncInternal(t,new Set,"");return this.cache.set(a,r),r.get(e)??null}async resolveAllEntitiesAsync(e,t){let a=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let s=e.split("."),r=s[0],p=s[1],g=await this.findDocumentForAlias(t,r);return g?await this.resolveAllEntitiesAsync(p,g):[]}return a.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,t,a){let s=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),s;t.add(r);let p=a.length===0?r:`${a} \u2192 ${r}`;for(let[g,i]of Object.entries(e.body))if(!g.includes(".")&&i&&typeof i=="object"&&!Array.isArray(i)){let u=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.push({entityName:g,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,u),entity:i,definedInNamespace:r,isImported:a.length>0,importPath:p})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${r}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((i,u)=>i+u.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${r}`);for(let[i,u]of Object.entries(e.metadata.imports))for(let f of u)try{this.logger?.debug?.(`Resolving import: ${i}/${f.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(i,f);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(y,t,p);s.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${i}/${f.packageName}`)}catch(y){let m=y;throw this.logger?.error?.(`Failed to process import ${i}/${f.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${i}/${f.packageName} for namespace ${r}. See inner exception for details.`,{cause:y})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,t,a){let s=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)`),s;t.add(r);let p=a.length===0?r:`${a} \u2192 ${r}`,g=0;for(let[i,u]of Object.entries(e.body))if(!i.includes(".")&&u&&typeof u=="object"&&!Array.isArray(u)&&!s.has(i)){let f=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.set(i,{entityName:i,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,i,f),entity:u,definedInNamespace:r,isImported:a.length>0,importPath:p}),g++}if(this.logger?.debug?.(`Indexed ${g} entities from ${r}`),e.metadata?.imports){let i=Object.values(e.metadata.imports).reduce((u,f)=>u+f.length,0);this.logger?.debug?.(`Processing ${i} import(s) for ${r}`);for(let[u,f]of Object.entries(e.metadata.imports))for(let y of f)try{this.logger?.debug?.(`Resolving import: ${u}/${y.packageName}`);let m=await this.repository.getHighestCompatibleVersionAsync(u,y);if(m){this.logger?.debug?.(`Successfully loaded import: ${m.metadata?.namespace_?.toString()}`);let A=await this.buildEntityIndexAsyncInternal(m,t,p),$=0;for(let[R,h]of A.entries()){let b=s.get(R);if(!b)s.set(R,h),$++;else if(b.isImported&&h.isImported&&(b.uri.publisher!==h.uri.publisher||b.uri.package_!==h.uri.package_)){let k=b.isAmbiguous?b:{...b,isAmbiguous:!0,ambiguousNamespaces:[b.definedInNamespace]};k.ambiguousNamespaces.includes(h.definedInNamespace)||k.ambiguousNamespaces.push(h.definedInNamespace),s.set(R,k),this.logger?.warn?.(`Ambiguous reference '${R}': defined in ${k.ambiguousNamespaces.join(", ")}`)}if(y.alias&&!R.includes(".")){let k=`${y.alias}.${R}`;s.has(k)||(s.set(k,h),$++)}}this.logger?.debug?.(`Merged ${$} entities from import ${m.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${u}/${y.packageName}`)}catch(m){let A=m;throw this.logger?.error?.(`Failed to process import ${u}/${y.packageName} for namespace ${r}. Error: ${A.message}`,A),new Error(`Failed to process import ${u}/${y.packageName} for namespace ${r}. See inner exception for details.`,{cause:m})}}return s}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[a,s]of Object.entries(e.metadata.imports))for(let r of s){if(r.alias===t)return await this.repository.getHighestCompatibleVersionAsync(a,r);if(!r.alias&&r.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(a,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubclassOfRecursiveAsync(e,t,a,s)}async isSubclassOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let p=r.entity.subClassOf;if(p){let g=K(p);for(let i of g)if(i===t||await this.isSubclassOfRecursiveAsync(i,t,a,s))return!0}return!1}async isSubpropertyOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,a,s)}async isSubpropertyOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let p=r.entity.subPropertyOf;if(p){let g=K(p);for(let i of g)if(i===t||await this.isSubpropertyOfRecursiveAsync(i,t,a,s))return!0}return!1}};var v=class n{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"&&n.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return n.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let a=await this.resourceResolver.resolveEntityAsync(e,t);if(a){let s=a.entity.type;if(s){let r=String(s);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function T(n){return`${n.publisher}/${n.package_}/${n.name}`}function c(n,e,t){return`${n}/${e}/${t}`}function L(n){return`${n.s}|${n.p}|${O(n.o)}`}function O(n){switch(n.kind){case"uri":return`u:${n.key}`;case"literal":return`l:${n.datatype}:${n.lexical}`;case"blank":return`b:${n.id}`}}function N(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var l="kanonak.org",o="core-rdf",d="core-owl",D="core-kanonak",_=new Map([["type",o],["subClassOf",o],["subPropertyOf",o],["domain",o],["range",o],["label",o],["comment",o],["seeAlso",o],["isDefinedBy",o],["member",o],["Resource",o],["Class",o],["Property",o],["Datatype",o],["Literal",o],["List",o],["ObjectProperty",d],["DatatypeProperty",d],["AnnotationProperty",d],["Thing",d],["Nothing",d],["Package",D]]),x=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function F(n,e){if(!n||!n.name)return;let t=_.get(n.name);if(t){if(x.has(n.name)){n.publisher=l,n.package_=t;return}n.publisher===l&&n.package_===t||n.publisher&&n.publisher.length>0&&(!e||e(n))||(n.publisher=l,n.package_=t)}}var w=class{type=c(l,o,"type");subClassOf=c(l,o,"subClassOf");subPropertyOf=c(l,o,"subPropertyOf");domain=c(l,o,"domain");range=c(l,o,"range");label=c(l,o,"label");comment=c(l,o,"comment");resource=c(l,o,"Resource");class_=c(l,o,"Class");datatype=c(l,o,"Datatype");literal=c(l,o,"Literal");equivalentClass=c(l,d,"equivalentClass");equivalentProperty=c(l,d,"equivalentProperty");inverseOf=c(l,d,"inverseOf");sameAs=c(l,d,"sameAs");transitiveProperty=c(l,d,"TransitiveProperty");symmetricProperty=c(l,d,"SymmetricProperty");objectProperty=c(l,d,"ObjectProperty");datatypeProperty=c(l,d,"DatatypeProperty");annotationProperty=c(l,d,"AnnotationProperty");package_=c(l,D,"Package")};export{K as a,S as b,v as c,T as d,c as e,L as f,O as g,N as h,F as i,w as j};
@@ -1 +0,0 @@
1
- import{a as R}from"./chunk-H2LEQLVD.js";import{c as D,d as p,g,j as m,k as v,l as d}from"./chunk-W6T7MOKY.js";import{c as k,g as u}from"./chunk-2ACBWC7K.js";function re(i,e,n,t){let r=h(i);if(r.length>0){let s=S(r,e,n);return s?{transformation:s.transformation,source:"instance"}:void 0}let a=new Set,o=M(i);for(;o.length>0;){let s=o.shift(),f=_(s.subject);if(a.has(f))continue;a.add(f);let b=y(t,s.subject);if(b.length===0)continue;let U=b.flatMap(h),j=S(U,e,n);if(j)return{transformation:j.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let x of b)for(let T of w(x))o.push(T)}let c={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!a.has(_(c))){let s=y(t,c).flatMap(h),f=S(s,e,n);if(f)return{transformation:f.transformation,source:c}}}function h(i){let e=[];for(let n of i.statement)if(n instanceof d&&l(n,"kanonak.org","derivation","derivations"))for(let t of n.object??[]){if(!(t instanceof R))continue;let r=P(t);r&&e.push(r)}return e}function S(i,e,n){let t=i.filter(o=>K(o.format,e)&&K(o.variant,n));if(t.length<=1)return t[0];let r=t[0].transformation,a=t[0];for(let o of t){let c=o.transformation;if(c.publisher!==r.publisher||c.package_!==r.package_||c.name!==r.name)continue;let s=u(a.transformation.version),f=u(c.version);s&&f&&k(f,s)>0&&(a=o)}return a}function P(i){let e,n,t;for(let r of i.statement)r instanceof m?l(r,"kanonak.org","derivation","format")?e=E(r):l(r,"kanonak.org","derivation","variant")&&(n=E(r)):r instanceof v&&l(r,"kanonak.org","derivation","transformation")&&(t=I(r.object));if(!(!e||!t))return n||(n={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:e,variant:n,transformation:t}}function I(i){let e,n,t,r;for(let a of i.statement){if(!(a instanceof g))continue;let o=a.predicate?.subject?.name;o==="publisher"?e=a.object:o==="package"?n=a.object:o==="version"?t=a.object:o==="name"&&(r=a.object)}if(!(!e||!n||!t||!r))return{publisher:e,package_:n,version:t,name:r}}function M(i){let e=[];for(let n of i.statement)n instanceof m&&n.predicate?.subject?.name==="type"&&n.object instanceof p&&e.push(n.object);return e}function w(i){let e=[];for(let n of i.statement)if(n instanceof m){if(n.predicate?.subject?.name!=="subClassOf")continue;n.object instanceof p&&e.push(n.object)}else if(n instanceof d){if(n.predicate?.subject?.name!=="subClassOf")continue;for(let t of n.object??[])t instanceof p&&e.push(t)}return e}function y(i,e){let n=[];for(let t of i){if(!(t instanceof D)||t.name!==e.name)continue;(t.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(t)}return n.sort((t,r)=>{let a=u((t.namespace||"").split("@")[1]??""),o=u((r.namespace||"").split("@")[1]??"");return!a||!o?0:k(o,a)}),n}function l(i,e,n,t){let r=i.predicate?.subject;return r?r.publisher===e&&r.package_===n&&r.name===t:!1}function E(i){let e=i.object.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}function K(i,e){return i.publisher===e.publisher&&i.package_===e.package_&&i.name===e.name}function _(i){return`${i.publisher}/${i.package_}/${i.name}`}export{re as a};
@@ -1 +0,0 @@
1
- import{a as A,e as v}from"./chunk-RSIZQAFL.js";import{a as f}from"./chunk-ORFSMEMM.js";import{c as w,d as I,h as R,i as F}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";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=c.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=c.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=c.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;switch(t.versionOperator){case P.Exact:return I(r,t.version);case P.Compatible:return R(r,t.version);case P.Major:return F(r,t.version);case P.Any:return w(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return w(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],p=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,p)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.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 i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.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=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.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[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.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 i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.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 i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.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=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,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 i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.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 d from"fs";var S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;d.existsSync(e)||d.mkdirSync(e,{recursive:!0}),d.existsSync(t)||d.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 _}from"os";import{join as N}from"path";function g(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||N(_(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??g(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=g(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}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){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{readFileSync as B,readdirSync as H}from"fs";import{join as x}from"path";var $=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function K(u,e=[]){for(let t of H(u,{withFileTypes:!0}))t.isDirectory()?$.has(t.name)||K(x(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(x(u,t.name));return e}async function j(u,e=new f,t={}){let n=new A(e);for(let m of K(u))try{let l=e.parse(B(m,"utf-8")),h=l.metadata?.namespace_,p=h?.version;h&&p&&await n.saveDocumentAsync(l,`${h.publisher}/${h.package_}@${p.major}.${p.minor}.${p.patch}`)}catch{}let o=new y(g(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,h)=>s.get(`${m}|${l}|${h}`)??null,onFetch:(m,l,h,p)=>{s.set(`${m}|${l}|${h}`,p)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,S as b,k as c,g as d,C as e,D as f,K as g,j as h};