@kanonak-protocol/sdk 4.12.0 → 4.14.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 (64) hide show
  1. package/dist/auth/CredentialBackend.d.ts +15 -6
  2. package/dist/auth/CredentialHelperBackend.d.ts +4 -4
  3. package/dist/auth/DeviceCertificateStore.d.ts +52 -0
  4. package/dist/auth/EncryptedFileBackend.d.ts +11 -7
  5. package/dist/auth/KeychainBackend.d.ts +10 -6
  6. package/dist/auth/SecretServiceBackend.d.ts +8 -6
  7. package/dist/auth/WinCredBackend.d.ts +13 -9
  8. package/dist/auth/index.d.ts +3 -1
  9. package/dist/browser.d.ts +1 -1
  10. package/dist/browser.js +2 -2
  11. package/dist/chunk-2HNPPYSK.js +1 -0
  12. package/dist/chunk-6U26UASC.js +1 -0
  13. package/dist/chunk-7BHDZHJY.js +1 -0
  14. package/dist/{chunk-V72IVYR4.js → chunk-H37TY5AQ.js} +4 -4
  15. package/dist/{chunk-VWS25JH4.js → chunk-HQQ4OAZ2.js} +1 -1
  16. package/dist/chunk-MRNELSJF.js +63 -0
  17. package/dist/{chunk-RGOBWOBB.js → chunk-OR3F4WIF.js} +1 -1
  18. package/dist/chunk-QDSN5VM3.js +2 -0
  19. package/dist/chunk-R73T4RUO.js +1 -0
  20. package/dist/{chunk-CR55WXIN.js → chunk-VDVJJ62W.js} +1 -1
  21. package/dist/chunk-WGKIRLMA.js +1 -0
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +26 -26
  24. package/dist/kanonaks/DefinedKanonak.d.ts +12 -0
  25. package/dist/parsing/KanonakObjectParser.d.ts +14 -1
  26. package/dist/parsing/index.js +1 -1
  27. package/dist/reasoning/index.js +1 -1
  28. package/dist/resolution/ResourceResolver.d.ts +0 -4
  29. package/dist/resolution/index.js +1 -1
  30. package/dist/search/index.js +1 -1
  31. package/dist/server/index.js +1 -1
  32. package/dist/transformations/index.js +1 -1
  33. package/dist/uri-helpers/index.js +1 -1
  34. package/dist/validation/ValidationCache.d.ts +34 -76
  35. package/dist/validation/documentModel.d.ts +47 -1
  36. package/dist/validation/index.d.ts +1 -1
  37. package/dist/validation/index.js +1 -1
  38. package/dist/validation/rules/repository/ClassDefinitionRule.d.ts +21 -6
  39. package/dist/validation/rules/repository/ClassHierarchyCycleRule.d.ts +9 -4
  40. package/dist/validation/rules/repository/EmbeddedKanonakTypeRule.d.ts +29 -90
  41. package/dist/validation/rules/repository/ObjectPropertyValueValidationRule.d.ts +20 -6
  42. package/dist/validation/rules/repository/PropertyDomainRule.d.ts +21 -17
  43. package/dist/validation/rules/repository/PropertyHierarchyCycleRule.d.ts +8 -4
  44. package/dist/validation/rules/repository/PropertyKindRangeConsistencyRule.d.ts +29 -0
  45. package/dist/validation/rules/repository/PropertyRangeReferenceRule.d.ts +14 -7
  46. package/dist/validation/rules/repository/PropertyRangeRequiredRule.d.ts +13 -2
  47. package/dist/validation/rules/repository/SubClassOfReferenceRule.d.ts +16 -13
  48. package/dist/validation/rules/repository/SubPropertyOfReferenceRule.d.ts +12 -5
  49. package/dist/validation/rules/repository/UnresolvedReferenceRule.d.ts +16 -4
  50. package/dist/validation/rules/repository/hierarchyCycle.d.ts +25 -0
  51. package/dist/validation/rules/repository/index.d.ts +1 -4
  52. package/package.json +2 -2
  53. package/dist/chunk-4UT2CLAT.js +0 -1
  54. package/dist/chunk-7HRKWTBB.js +0 -1
  55. package/dist/chunk-7TKJHKC2.js +0 -1
  56. package/dist/chunk-BKVPSPG4.js +0 -1
  57. package/dist/chunk-IEOSSSB5.js +0 -1
  58. package/dist/chunk-SHDHMKMJ.js +0 -1
  59. package/dist/chunk-U7LVFPEO.js +0 -2
  60. package/dist/chunk-UBBZWWRB.js +0 -86
  61. package/dist/validation/rules/repository/DefinitionPropertyReferenceRule.d.ts +0 -13
  62. package/dist/validation/rules/repository/ObjectPropertyImportRule.d.ts +0 -9
  63. package/dist/validation/rules/repository/PropertyValueTypeRule.d.ts +0 -11
  64. package/dist/validation/rules/repository/XsdImportRule.d.ts +0 -11
@@ -1,94 +1,52 @@
1
1
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
2
  import type { Kanonak } from '../kanonaks/Kanonak.js';
3
3
  /**
4
- * Per-validation-pass memoization shared across every repository rule
5
- * applied to documents in the same repository.
4
+ * Per-validation-pass memoization shared across every repository rule applied to
5
+ * documents in the same repository.
6
6
  *
7
- * Today the validator's caller (CLI single-file validation, or the
8
- * VS Code diagnostics provider validating every workspace document)
9
- * runs `KanonakObjectValidator.validateAsync(doc, repo)` once per
10
- * document. Each call re-executes 21 repository rules from scratch
11
- * against the same repository, and several of those rules redo
12
- * identical work for every document — walking the import closure
13
- * to collect class declarations, looking up the same package via
14
- * `getHighestCompatibleVersionAsync` over and over, or re-parsing
15
- * the entire repo through `KanonakObjectParser`.
7
+ * The expensive shared work is the full-repository `parseKanonaks`. Every
8
+ * repository rule reads the resolved object model (the merged catalog via
9
+ * {@link getKanonaks}, or the pre-merge per-document authored view via
10
+ * {@link getAuthoredKanonaks}); the cache parses the repo at most ONCE per pass
11
+ * and serves both views from that single parse. A batch caller
12
+ * (`KanonakObjectValidator.validateDocumentsAsync`) constructs one cache and
13
+ * threads it through every per-document `validateAsync`, so validating a whole
14
+ * directory is one parse, not O(documents x catalog).
16
15
  *
17
- * `ValidationCache` is the seam that lets a multi-document caller
18
- * share that work across calls. The cache's lifetime is one
19
- * validation pass over one repository; the diagnostics provider
20
- * constructs a fresh cache at the top of each refresh and passes
21
- * it to every per-document `validateAsync`. Rules opt in by
22
- * reading from the cache when present; without it they fall back
23
- * to their original logic (used by single-document callers like
24
- * the CLI's `kanonak validate <path>`).
25
- *
26
- * The cache also exposes a wrapped `repository` that memoizes
27
- * `getHighestCompatibleVersionAsync` and
28
- * `getDocumentsByNamespaceAsync` — both linear scans over the
29
- * in-memory repo. Rules that don't know about the cache still
30
- * benefit, because the validator passes `cache.repository` as the
31
- * repo argument so their existing lookup calls hit the cache
32
- * transparently.
16
+ * The cache also exposes a wrapped {@link repository} that memoizes the two
17
+ * linear-scan repository lookups (`getHighestCompatibleVersionAsync`,
18
+ * `getDocumentsByNamespaceAsync`); rules that call the repository directly hit
19
+ * the cache transparently because the validator passes `cache.repository` as the
20
+ * repo argument.
33
21
  */
34
22
  export declare class ValidationCache {
35
23
  private readonly underlying;
36
24
  /**
37
- * Repository wrapper that memoizes read-only lookups for the
38
- * lifetime of this cache. Pass this to every rule (instead of
39
- * the bare repository) so existing rule code that calls
40
- * `repository.getHighestCompatibleVersionAsync(...)` benefits
41
- * automatically without needing to know about the cache.
25
+ * Repository wrapper that memoizes read-only lookups for the lifetime of this
26
+ * cache. Pass this to every rule (instead of the bare repository) so existing
27
+ * rule code that calls `repository.getHighestCompatibleVersionAsync(...)`
28
+ * benefits automatically without needing to know about the cache.
42
29
  */
43
30
  readonly repository: IKanonakDocumentRepository;
44
- private kanonaksPromise;
45
- private importClosureCache;
46
- private classDeclarationsCache;
47
- private propertyNamesCache;
48
- private allDocumentsPromise;
31
+ private parsePromise;
49
32
  constructor(underlying: IKanonakDocumentRepository);
50
33
  /**
51
- * Full-repository `parseKanonaks` result, memoized for the cache's
52
- * lifetime. Used by rules that want the resolved-URI object model
53
- * (e.g. `MarkdownLinkRule`) instead of walking raw `document.body`.
54
- * Filter by `subject.namespace` to scope to a specific document.
34
+ * Full-repository `parseKanonaks` result (the open-world-merged catalog),
35
+ * memoized for the cache's lifetime. Filter by `subject.namespace` to scope to
36
+ * a specific document.
55
37
  */
56
38
  getKanonaks(): Promise<Kanonak[]>;
57
39
  /**
58
- * Identifier-keyed transitive-import closure for the given document.
59
- * Returns the set of `publisher/package@version` strings reachable
60
- * via `imports:` starting from `docId`, including `docId` itself.
61
- *
62
- * Rules that need to know "what does this document import,
63
- * recursively?" should call this once instead of walking the
64
- * imports graph themselves on every reference lookup. Per-doc
65
- * memoized; same doc validated multiple times in the pass
66
- * traverses the graph once.
67
- */
68
- getImportClosure(docId: string): Promise<Set<string>>;
69
- /**
70
- * subClassOf relationships declared inside the given document's
71
- * body (NOT in its imports). Map<className, parentClassName[]>.
72
- * Composed across an import closure to build the effective class
73
- * hierarchy a rule needs.
74
- *
75
- * Cached per-doc so two rules consulting the same document's
76
- * declarations (or the same document validated multiple times)
77
- * walk its body once.
78
- */
79
- getClassDeclarations(docId: string): Promise<Map<string, string[]>>;
80
- /**
81
- * Names of property-typed entities (`ObjectProperty`,
82
- * `DatatypeProperty`, `AnnotationProperty`, plain `Property`)
83
- * declared inside the given document's body. Used by reference-
84
- * resolution rules to answer "is property P defined here?" in O(1)
85
- * after a one-time scan.
40
+ * The PRE-MERGE, per-document parse from the SAME single full-repo parse as
41
+ * {@link getKanonaks}: each document's authored subjects (and embeddeds),
42
+ * stamped with their `sourceDoc`, before the open-world merge folds them onto
43
+ * shared URIs and dedups cross-document duplicates. A per-document rule that
44
+ * must validate exactly what a document authored including augmentations it
45
+ * asserts about imported entities, which the merge files under the imported
46
+ * namespace filters this by `sourceDoc`, instead of re-parsing the document
47
+ * (which would break the ≤1-parse contract). Resolution targets still come
48
+ * from the merged {@link getKanonaks}.
86
49
  */
87
- getPropertyNames(docId: string): Promise<Set<string>>;
88
- private getAllDocuments;
89
- private computeImportClosure;
90
- private buildDocsByIdIndex;
91
- private computeClassDeclarations;
92
- private computePropertyNames;
93
- private findDocById;
50
+ getAuthoredKanonaks(): Promise<Kanonak[]>;
51
+ private parseOnce;
94
52
  }
@@ -1,5 +1,5 @@
1
1
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
- import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
2
+ import type { KanonakDocument, Import, DocumentReference } from '@kanonak-protocol/types/document/models/types';
3
3
  import type { ValidationCache } from './ValidationCache.js';
4
4
  import type { Kanonak } from '../kanonaks/Kanonak.js';
5
5
  import { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
@@ -29,6 +29,24 @@ export declare function getCatalogKanonaks(document: KanonakDocument, repository
29
29
  * captured data.)
30
30
  */
31
31
  export declare function getDocumentKanonaks(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<Kanonak[]>;
32
+ /**
33
+ * The subjects THIS document authored — INCLUDING the open-world augmentations
34
+ * it asserts about imported entities. An augmentation (e.g. a look package
35
+ * adding `semanticSvg` to `rdfs.Resource`) is filed under the IMPORTED package's
36
+ * namespace by the open-world merge, so {@link getDocumentKanonaks} — which
37
+ * scopes by the document's own namespace — does not return it. This reads the
38
+ * parser's PRE-MERGE view (each subject + embedded stamped with its authoring
39
+ * `sourceDoc`) from the SAME single parse as {@link getCatalogKanonaks}, then
40
+ * keeps the subjects this document authored. Unlike a re-parse it preserves the
41
+ * ≤1-parse batch contract; unlike the merged catalog it does not lose a
42
+ * document's authored statements to cross-document de-duplication.
43
+ *
44
+ * Use this when a rule must validate what a document authored regardless of
45
+ * which namespace the merge files it under (e.g. an embedded `type:` on an
46
+ * augmentation). Resolution targets are still looked up against
47
+ * {@link getCatalogKanonaks}.
48
+ */
49
+ export declare function getAuthoredKanonaks(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<Kanonak[]>;
32
50
  /** A DefinedKanonak visited during a walk, with a human-facing locator path. */
33
51
  export interface WalkNode {
34
52
  readonly kanonak: DefinedKanonak;
@@ -46,3 +64,31 @@ export declare function walkDefinedKanonaks(roots: Kanonak[], visit: (node: Walk
46
64
  /** `publisher/package@major.minor.patch` — matches `SubjectKanonak.namespace`
47
65
  * and the parser's `sourceDoc`. Undefined for a document without a namespace. */
48
66
  export declare function namespaceOf(document: KanonakDocument): string | undefined;
67
+ /**
68
+ * Cacheless catalog source: exposes the target document PLUS every other
69
+ * document in the backing repository through `getAllDocumentsAsync` (and
70
+ * delegates all resolution lookups to the backing repository). This lets the
71
+ * single-document parse see the whole import closure — so cross-package
72
+ * references resolve to real imported subjects, matching the cached (batch)
73
+ * path. The target document is listed first and any same-namespace copy in the
74
+ * repository is excluded, so the in-hand document stays authoritative for its
75
+ * own namespace even when an older copy was saved. Unlike
76
+ * `SingleDocumentRepository` (which exposes ONLY the target document, by
77
+ * design, for parsing one entity in isolation), this includes the closure
78
+ * precisely because validation existence checks need it.
79
+ */
80
+ export declare class DocumentWithRepositoryCatalog implements IKanonakDocumentRepository {
81
+ private readonly document;
82
+ private readonly broader;
83
+ constructor(document: KanonakDocument, broader: IKanonakDocumentRepository);
84
+ getAllDocumentsAsync(): Promise<KanonakDocument[]>;
85
+ getDocumentAsync(identifier: string): Promise<KanonakDocument | null>;
86
+ getDocumentsByNamespaceAsync(publisher: string, package_: string): Promise<KanonakDocument[]>;
87
+ getHighestCompatibleVersionAsync(publisher: string, import_: Import): Promise<KanonakDocument | null>;
88
+ getAllDocumentReferencesAsync(): Promise<DocumentReference[]>;
89
+ getDocumentContentAsync(identifier: string): Promise<string | null>;
90
+ getDocumentUriAsync(identifier: string): Promise<string | null>;
91
+ saveDocumentAsync(): Promise<void>;
92
+ deleteDocumentAsync(): Promise<void>;
93
+ clearNamespaceAsync(): Promise<void>;
94
+ }
@@ -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, PackageHeaderRule } from './rules/document/index.js';
11
- export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
11
+ export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,L as J,M as K,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-UBBZWWRB.js";import"../chunk-SHDHMKMJ.js";import"../chunk-BKVPSPG4.js";import"../chunk-NJ3AZYQD.js";import"../chunk-IEOSSSB5.js";import"../chunk-7TKJHKC2.js";import"../chunk-7HRKWTBB.js";import"../chunk-4UT2CLAT.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{w as AmbiguousReferenceRule,C as ClassDefinitionRule,n as ClassHierarchyCycleRule,u as DefinitionPropertyReferenceRule,J as DiamondNameClashRule,E as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,K as KanonakObjectValidator,F as LookSemanticSvgPathRule,D as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,y as ObjectPropertyImportRule,z as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,I as OwlOneOfRule,j as PackageHeaderRule,A as PropertyDomainRule,o as PropertyHierarchyCycleRule,x as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,g as ResourceNamingRule,H as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,G as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,v as XsdImportRule};
1
+ import{A,B,C,D,E,F,I as G,J as H,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-MRNELSJF.js";import"../chunk-R73T4RUO.js";import"../chunk-NJ3AZYQD.js";import"../chunk-2HNPPYSK.js";import"../chunk-6U26UASC.js";import"../chunk-WGKIRLMA.js";import"../chunk-7BHDZHJY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{u as AmbiguousReferenceRule,z as ClassDefinitionRule,n as ClassHierarchyCycleRule,G as DiamondNameClashRule,B as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,H as KanonakObjectValidator,C as LookSemanticSvgPathRule,A as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,w as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,F as OwlOneOfRule,j as PackageHeaderRule,x as PropertyDomainRule,o as PropertyHierarchyCycleRule,y as PropertyKindRangeConsistencyRule,v as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,g as ResourceNamingRule,E as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,D as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
@@ -2,11 +2,26 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Every `type` target — the class an entity is declared an instance of — must
8
+ * resolve to a class-like resource. A built-in meta-class (`Class`,
9
+ * `ObjectProperty`, `Datatype`, `Package`, …) is itself a `type: Class` subject
10
+ * in the core packages, so it resolves the same way as a user-defined class —
11
+ * no hardcoded built-in allow-list is needed, and a real typo (`type: Conatiner`)
12
+ * is correctly flagged regardless of how it was aliased.
13
+ *
14
+ * Reads the resolved object model recursively ({@link walkDefinedKanonaks}), so
15
+ * a bad `type` on an embedded kanonak at any depth is caught, not just on
16
+ * top-level subjects (the #65 gap). The `type` target parses to a
17
+ * `ReferenceKanonak` whose `subject` URI the parser canonicalizes; existence +
18
+ * class-ness are checked by `findSubjectByUri` + `ResourceTypeClassifier`, never
19
+ * by a built-in-name set or `split('.')` alias extraction. (`type` is the
20
+ * structural predicate this rule owns — `UnresolvedReferenceRule` skips it.)
21
+ */
5
22
  export declare class ClassDefinitionRule implements IRepositoryValidationRule {
6
- private readonly builtInClasses;
7
- get ruleName(): string;
8
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
9
- private checkNestedTypes;
10
- private isClassEntity;
11
- private isDefinitionType;
23
+ readonly ruleName = "ClassDefinition";
24
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
25
+ private resolvesToClassLike;
26
+ private error;
12
27
  }
@@ -2,10 +2,15 @@ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/documen
2
2
  import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
3
3
  import { OntologyValidationError } from '../../OntologyValidationError.js';
4
4
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Detects a circular `subClassOf` hierarchy. Reads the resolved object model: the
8
+ * subClassOf graph is walked by canonical `KanonakUri` (resolved through the
9
+ * import closure) and compared by `uriKey` identity, so a cycle that closes
10
+ * across packages — where the same class is spelled with different aliases in
11
+ * each hop — is caught, where the old local-name hierarchy map would miss it.
12
+ */
5
13
  export declare class ClassHierarchyCycleRule implements IRepositoryValidationRule {
6
14
  readonly ruleName = "ClassHierarchyCycle";
7
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
8
- private buildClassHierarchy;
9
- private detectCycle;
10
- private detectCycleRecursive;
15
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
11
16
  }
@@ -2,101 +2,40 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
5
6
  /**
6
- * Validates `type:` declarations on embedded kanonaks.
7
+ * Validates an explicit `type:` on an embedded kanonak against the range of the
8
+ * parent property it is embedded under: the declared type must be the range
9
+ * itself (redundant — a Warning) or a `subClassOf` descendant of it (accepted),
10
+ * supporting discriminated-union modelling with real OWL semantics.
7
11
  *
8
- * An embedded object MAY declare a `type:` property. If declared, the
9
- * declared type must be a subclass of (or equal to) the range of the
10
- * parent property under which the object is embedded. This relaxes
11
- * the previous "no explicit type on embeddeds" rule so authors can
12
- * model tagged-union / discriminated-union hierarchies with proper
13
- * OWL `subClassOf` semantics instead of working around the validator
14
- * with a separate discriminator class and named-instance enumeration.
12
+ * Reads the resolved object model, NOT raw `document.body`. The parser has
13
+ * already resolved every embedding predicate to its canonical property URI, so
14
+ * the parent property is known directly from the `EmbeddedStatement`/`ListStatement`
15
+ * predicate collapsing the old local-name property-range map and its
16
+ * alias/parent-class disambiguation entirely. The subclass test is the single
17
+ * canonical `superClassChain` walk compared by `uriKey` identity, so a
18
+ * cross-package subclass resolves regardless of the alias spelling each document
19
+ * used (`fml.Expression` vs `Expression` both being `…/formula/Expression`) —
20
+ * fixing the string-comparison false-negative the old `isSubclassOfAsync` +
21
+ * local-name fallback produced (#65, comment 4). Coverage is recursive on
22
+ * embeddeds at any depth.
15
23
  *
16
- * - Equal-to-range declarations are accepted but emit a Warning
17
- * ("redundant"). Authors who want explicit redundancy can opt in
18
- * by ignoring the warning.
19
- * - Strict-subclass declarations are accepted (no diagnostic).
20
- * - Non-subclass declarations error with a suggestion to either
21
- * drop the type or add a matching `subClassOf:` to the declared
22
- * class.
23
- * - When the parent property has no `range:`, or the range is a
24
- * "universal" class (`Resource`, `Class`), no constraint is
25
- * enforced — every declared embedded type is accepted.
26
- *
27
- * Why this is a repository rule rather than a document rule: deciding
28
- * whether `cp.OrCondition` is a subclass of `Condition` requires
29
- * walking `subClassOf` across the importing document's transitive
30
- * imports, which the document-only validator interface can't reach.
31
- * The class hierarchy walk is delegated to
32
- * `ResourceResolver.isSubclassOfAsync`, the same helper other
33
- * range-aware rules already share.
24
+ * - A "universal" range (`rdfs.Resource`, `rdfs.Class`) imposes no constraint.
25
+ * - An embedded with no explicit `type:` is fine (the type is inferred).
26
+ * - An unresolved parent property or range is reported by the dedicated
27
+ * reference rules, not here.
34
28
  */
35
29
  export declare class EmbeddedKanonakTypeRule implements IRepositoryValidationRule {
36
- get ruleName(): string;
37
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
38
- /**
39
- * Pick the right property-range candidate when multiple packages
40
- * declare a property with the same local name (e.g. `tx.Not.operand`
41
- * range `Expression` vs. `wv.NotCondition.operand` range `Condition`).
42
- *
43
- * Disambiguation strategy, in priority order:
44
- *
45
- * 1. If the property name as authored is alias-prefixed
46
- * (`tx.operand`), match candidates whose declaring entity
47
- * shares the same alias prefix. This is the unambiguous case
48
- * most authors hit — the YAML key carries the disambiguator.
49
- * 2. Otherwise, if the parent dict has a `type:` declaration,
50
- * match candidates whose `domain` local-name equals the parent
51
- * class's local-name. The embedded under `type: tx.Not` only
52
- * reasonably refers to the `operand` property whose domain is
53
- * `tx.Not` (kanonak-protocol/typescript#17).
54
- * 3. Last resort: return the first candidate. Authors who hit this
55
- * branch have a genuinely ambiguous shape — bare property name,
56
- * no parent type, multiple matching properties — and the rule
57
- * can't tell which they meant.
58
- */
59
- private pickRange;
60
- /**
61
- * Recursively descend through a YAML dict, validating any `type:`
62
- * declarations encountered at depth > 0 against the closest known
63
- * parent-property range.
64
- *
65
- * `parentPropertyRange` flows down from the property under which
66
- * this dict sits. Two cases preserve it correctly:
67
- *
68
- * 1. **Single embedded under a property** — keys here are the
69
- * embedded's properties; we look up each key's own range and
70
- * pass it down for the next level.
71
- * 2. **Dict-keyed list of embeddeds** (e.g.
72
- * `hasArgument: { foo: {...}, bar: {...} }`) — keys are labels
73
- * rather than properties, so they resolve to no range. In that
74
- * case we propagate the OUTER property's range through the
75
- * label level so the embedded values still get checked.
76
- *
77
- * List items are handled identically: a list under property P
78
- * means each item is an embedded under P, regardless of whether
79
- * the list is positional (`- item`) or dict-keyed.
80
- */
81
- private checkEmbeddedTypes;
82
- private validateEmbeddedType;
83
- private localName;
30
+ readonly ruleName = "EmbeddedKanonakType";
31
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
84
32
  /**
85
- * Build a map from property local name list of candidate
86
- * declarations (range + domain + declaring alias). Multiple
87
- * candidates exist when more than one imported package declares a
88
- * property with the same local name (e.g. `tx.Not.operand` range
89
- * `Expression` AND `wv.NotCondition.operand` range `Condition`).
90
- *
91
- * Pre-#17, this map collapsed candidates by overwriting each prior
92
- * entry, so the last-loaded property won and silently shadowed the
93
- * others. Now all candidates are kept; `pickRange` picks the right
94
- * one at lookup time using alias-prefix and parent-class context.
95
- *
96
- * The local-name keying mirrors the lookup pattern in
97
- * `checkEmbeddedTypes` (which uses `localName(propertyName)` for
98
- * the lookup). Same convention as `PropertyValueTypeRule` and
99
- * `ObjectPropertyValueValidationRule`.
33
+ * Descend a node's statements: every embedded object (single or list item) is
34
+ * checked against its embedding property's range, then recursed into so a
35
+ * deeper embedded is checked against ITS own embedding property.
100
36
  */
101
- private buildPropertyRangeMap;
37
+ private walk;
38
+ private check;
39
+ private redundant;
40
+ private notSubclass;
102
41
  }
@@ -2,11 +2,25 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * When an ObjectProperty's range is a schema-level meta-class, a value that
8
+ * REFERENCES an entity must reference one of that nature — e.g. a property whose
9
+ * range is `rdfs.Class` must point at a class, not an instance. This is the
10
+ * named-reference analogue of {@link EmbeddedKanonakTypeRule} (which constrains
11
+ * the declared type of an EMBEDDED value against its property's range).
12
+ *
13
+ * Reads the resolved object model (recursive on embeddeds at any depth): the
14
+ * property and its range are canonical URIs, the referent's nature is decided by
15
+ * `ResourceTypeClassifier`, identity by `uriMatches` — never by local-name range
16
+ * matching. Ordinary (non-meta) ranges and unresolved references are out of
17
+ * scope here (the latter is owned by `UnresolvedReferenceRule`); value-shape
18
+ * (scalar-vs-reference) is enforced structurally by the parser.
19
+ */
5
20
  export declare class ObjectPropertyValueValidationRule implements IRepositoryValidationRule {
6
- private readonly standardProperties;
7
- get ruleName(): string;
8
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
9
- private scanEntityForObjectProperties;
10
- private validateRangeType;
11
- private buildPropertyMetadataAsync;
21
+ readonly ruleName = "ObjectPropertyValue";
22
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
23
+ private walk;
24
+ private check;
25
+ private warn;
12
26
  }
@@ -1,24 +1,28 @@
1
1
  import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
- import type { ValidationCache } from '../../ValidationCache.js';
5
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Every property used on an instance must be in scope for that instance's type:
8
+ * the property's `domain` must be the instance's type, an ancestor of it, or
9
+ * `rdfs.Resource` (which every resource is, so Resource-domain properties like
10
+ * `rdfs.label` apply universally). A property with no declared `domain` imposes
11
+ * no constraint.
12
+ *
13
+ * Reads the resolved object model (recursively, on embeddeds at any depth), NOT
14
+ * raw `document.body`: the predicate is the property's canonical URI, scope is
15
+ * the single canonical `superClassChain` walk, and domain membership is compared
16
+ * by `uriKey` identity — never by `lastIndexOf('.')` alias splitting or a
17
+ * local-name class-hierarchy map. Built-in predicates (`type`, `label`,
18
+ * `subClassOf`, …) are protocol-defined and skipped here. An unresolved
19
+ * predicate/property is reported by the dedicated predicate/reference rules.
20
+ */
6
21
  export declare class PropertyDomainRule implements IRepositoryValidationRule {
7
- private readonly standardProperties;
8
- get ruleName(): string;
22
+ readonly ruleName = "PropertyDomain";
9
23
  validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
10
- /**
11
- * Cache-driven hierarchy: union of `getClassDeclarations(docId)`
12
- * across the document's transitive import closure. Each closure
13
- * document's body is walked at most once per validation pass
14
- * regardless of how many workspace documents share that closure
15
- * member. Result shape matches `buildCompleteClassHierarchyAsync`
16
- * so downstream `isTypeCompatibleWithDomain` works unchanged.
17
- */
18
- private buildClassHierarchyViaCache;
19
- private buildCompleteClassHierarchyAsync;
20
- private validateEntityProperties;
21
- private isTypeCompatibleWithDomain;
22
- private getPropertyValue;
23
- private extractFirstValue;
24
+ private walk;
25
+ /** Check every non-built-in property used ON this node against its type's scope. */
26
+ private checkNode;
27
+ private error;
24
28
  }
@@ -2,10 +2,14 @@ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/documen
2
2
  import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
3
3
  import { OntologyValidationError } from '../../OntologyValidationError.js';
4
4
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Detects a circular `subPropertyOf` hierarchy. Reads the resolved object model:
8
+ * the subPropertyOf graph is walked by canonical `KanonakUri` and compared by
9
+ * `uriKey` identity, so a cycle that closes across packages with differing alias
10
+ * spellings is caught, where the old local-name hierarchy map would miss it.
11
+ */
5
12
  export declare class PropertyHierarchyCycleRule implements IRepositoryValidationRule {
6
13
  readonly ruleName = "PropertyHierarchyCycle";
7
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
8
- private buildPropertyHierarchy;
9
- private detectCycle;
10
- private detectCycleRecursive;
14
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
11
15
  }
@@ -0,0 +1,29 @@
1
+ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
2
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
+ import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
+ import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * A property's declared KIND must match the NATURE of its range (#65 Gap A):
8
+ *
9
+ * - `owl.DatatypeProperty` → a DATATYPE-valued range: an xsd type, `rdfs.Literal`,
10
+ * or a datatype-derived class (e.g. `prose.Markdown`, declared `Datatype` and
11
+ * ultimately `subClassOf` an xsd type).
12
+ * - `owl.ObjectProperty` → a plain `rdfs.Class` range that is NOT datatype-derived.
13
+ *
14
+ * Without this the mismatch only surfaces LATE at resolution time ("value could
15
+ * not be resolved" when an object property tries to resolve literal text as a
16
+ * reference). The decision MUST be made by walking the range's `subClassOf`
17
+ * chain, because a datatype-derived class is datatype-valued even though
18
+ * `rdfs.Datatype` is itself a kind of `rdfs.Class` — a naive "is the range an
19
+ * `rdfs.Class`?" test gets it exactly backwards. "Datatype-valued" here means a
20
+ * chain node whose OWN type is `Datatype` (so xsd types and every datatype-
21
+ * derived class qualify) or `rdfs.Literal`; identity by `KanonakUri`, no
22
+ * hardcoded xsd-name set. An unresolved range is owned by
23
+ * `PropertyRangeReferenceRule`, a missing range by `PropertyRangeRequiredRule`.
24
+ */
25
+ export declare class PropertyKindRangeConsistencyRule implements IRepositoryValidationRule {
26
+ readonly ruleName = "PropertyKindRangeConsistency";
27
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
28
+ private error;
29
+ }
@@ -2,12 +2,19 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Every Object/Datatype property `range` must resolve to a class-like resource:
8
+ * a Class, or a Datatype (core-xsd types — `string`, `integer`, … — and
9
+ * datatype-derived classes are all `type: Datatype` subjects). Reads the
10
+ * resolved object model: the range is a `ReferenceKanonak` resolved through the
11
+ * import closure (alias-agnostic), checked by `findSubjectByUri` +
12
+ * `ResourceTypeClassifier`, never by hardcoded primitive/built-in name sets or
13
+ * `split('.')` alias extraction. (Missing range is `PropertyRangeRequiredRule`.)
14
+ */
5
15
  export declare class PropertyRangeReferenceRule implements IRepositoryValidationRule {
6
- private readonly builtInClasses;
7
- private readonly primitiveTypes;
8
- get ruleName(): string;
9
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
10
- private isTypeAvailableInImports;
11
- private isTypeAvailableInImportsRecursive;
12
- private isValidRangeTargetType;
16
+ readonly ruleName = "PropertyRangeReference";
17
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
18
+ private resolvesToClassLike;
19
+ private error;
13
20
  }
@@ -2,7 +2,18 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Every Object/Datatype property must declare a `range`. Reads the resolved
8
+ * object model: presence is tested by the `range` predicate's canonical URI
9
+ * (`hasProperty`), so the aliased `rdfs.range` form is recognised exactly like
10
+ * the bare `range` — fixing the alias-blind raw-dict check that keyed off the
11
+ * literal `'range'` dict key and falsely reported "must have a range" for a
12
+ * property authored with `rdfs.range:` (#65 Gap B). Whether the declared range
13
+ * actually RESOLVES is `PropertyRangeReferenceRule`'s concern.
14
+ */
5
15
  export declare class PropertyRangeRequiredRule implements IRepositoryValidationRule {
6
- get ruleName(): string;
7
- validateAsync(document: KanonakDocument, _repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
16
+ readonly ruleName = "PropertyRangeRequired";
17
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
18
+ private error;
8
19
  }
@@ -2,18 +2,21 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
3
  import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
4
  import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ /**
7
+ * Every `subClassOf` target must resolve to a class-like resource. Per core-rdf
8
+ * (`Datatype subClassOf Class`) a Datatype is a Class, so datatype hierarchies
9
+ * (`xsd.integer subClassOf xsd.decimal`, `Markdown subClassOf SubstitutableString`)
10
+ * are well-formed — the target check accepts both.
11
+ *
12
+ * Reads the resolved object model: the parser turns each `subClassOf` value into
13
+ * a `ReferenceKanonak`, so the target is a `KanonakUri` resolved through the
14
+ * import closure (alias-agnostic) and existence is checked by `findSubjectByUri`,
15
+ * never by a hardcoded built-in-name list or `split('.')` alias extraction.
16
+ */
5
17
  export declare class SubClassOfReferenceRule implements IRepositoryValidationRule {
6
- private readonly builtInClasses;
7
- get ruleName(): string;
8
- /**
9
- * A valid `subClassOf` target is anything that is a Class — and per
10
- * core-rdf's `Datatype subClassOf Class`, a Datatype is a Class. So
11
- * datatype hierarchies (`xsd.integer subClassOf xsd.decimal`,
12
- * `Markdown subClassOf SubstitutableString`) are well-formed and the
13
- * target check must accept both `Class` and `Datatype` (aliased or not).
14
- */
15
- private isClassLikeType;
16
- validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
17
- private isClassAvailableInImports;
18
- private isClassAvailableInImportsRecursive;
18
+ readonly ruleName = "SubClassOfReference";
19
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
20
+ private resolvesToClassLike;
21
+ private error;
19
22
  }