@kanonak-protocol/sdk 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/KanonakUri-4VJGV3FN.js +1 -0
- package/dist/browser.js +2 -48
- package/dist/chunk-3JRHG2JH.js +1 -0
- package/dist/chunk-7M7XXZOV.js +1 -0
- package/dist/chunk-AFF2TQ7Y.js +2 -0
- package/dist/chunk-C54LRL2A.js +42 -0
- package/dist/chunk-CNM3SY5S.js +2 -0
- package/dist/chunk-CRR4BQKR.js +1 -0
- package/dist/chunk-FQHALFRR.js +1 -0
- package/dist/chunk-FUUTGGJS.js +1 -0
- package/dist/chunk-GKQVJITL.js +1 -0
- package/dist/chunk-MYITGTGJ.js +1 -0
- package/dist/chunk-NPWF35XZ.js +1 -0
- package/dist/chunk-ODIECDN7.js +1 -0
- package/dist/chunk-QJ66UBDY.js +1 -0
- package/dist/chunk-RGMZAKJV.js +1 -0
- package/dist/chunk-USLG7UIM.js +4 -0
- package/dist/chunk-W6T7MOKY.js +1 -0
- package/dist/chunk-YENGFI2R.js +1 -0
- package/dist/ctl/index.js +1 -4
- package/dist/filtering/index.js +1 -1
- package/dist/index.js +26 -72
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/browser.js +1 -2
- package/dist/repositories/index.js +1 -2
- package/dist/resolution/index.js +1 -1
- package/dist/transformations/DocAst.d.ts +120 -0
- package/dist/transformations/DocAstUriConstants.d.ts +65 -0
- package/dist/transformations/FormatOverride.d.ts +34 -0
- package/dist/transformations/ReferenceResolver.d.ts +23 -0
- package/dist/transformations/TransformationEngine.d.ts +72 -0
- package/dist/transformations/backends/HtmlBackend.d.ts +7 -0
- package/dist/transformations/backends/IDocumentAstBackend.d.ts +16 -0
- package/dist/transformations/backends/JsonBackend.d.ts +12 -0
- package/dist/transformations/backends/MarkdownFrontmatterBackend.d.ts +7 -0
- package/dist/transformations/backends/SimpleMarkdownRenderer.d.ts +17 -0
- package/dist/transformations/backends/SvgBackend.d.ts +7 -0
- package/dist/transformations/backends/TomlBackend.d.ts +7 -0
- package/dist/transformations/index.d.ts +18 -0
- package/dist/transformations/index.js +84 -0
- package/dist/transformations/v3/CompiledTransformationV3.d.ts +370 -0
- package/dist/transformations/v3/ExpressionEngineV3.d.ts +75 -0
- package/dist/transformations/v3/TransformationLoaderV3.d.ts +22 -0
- package/dist/transformations/v3/TransformationRunnerV3.d.ts +92 -0
- package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +200 -0
- package/dist/uri-helpers/SingleDocumentRepository.d.ts +28 -0
- package/dist/uri-helpers/UriHelpers.d.ts +89 -0
- package/dist/uri-helpers/index.d.ts +3 -0
- package/dist/uri-helpers/index.js +1 -0
- package/dist/validation/index.js +1 -42
- package/package.json +18 -2
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardcoded canonical URIs for the transformations@3.0.0 ontology.
|
|
3
|
+
*
|
|
4
|
+
* Versioned in the file path (`v3/`) and the symbol (`TX_V3`) so a
|
|
5
|
+
* future v4 ontology can ship a sibling `v4/TransformationUriConstantsV4.ts`
|
|
6
|
+
* and the runtime can dispatch by the resolved type's package version
|
|
7
|
+
* without forcing existing v3 transformations to upgrade.
|
|
8
|
+
*
|
|
9
|
+
* Per the typescript repo's CLAUDE.md rule 6, hardcoded URI constants
|
|
10
|
+
* are fine and expected — they are the ontology contract. String
|
|
11
|
+
* heuristics on aliases or suffixes are NOT.
|
|
12
|
+
*/
|
|
13
|
+
import type { EntityUri } from '../../uri-helpers/UriHelpers.js';
|
|
14
|
+
export declare const TX_V3_PUB = "kanonak.org";
|
|
15
|
+
export declare const TX_V3_PKG = "transformations";
|
|
16
|
+
export declare const TX_V3_VERSION_MAJOR = 3;
|
|
17
|
+
export declare const TX_V3: {
|
|
18
|
+
readonly Transformation: EntityUri;
|
|
19
|
+
readonly InstanceTransformation: EntityUri;
|
|
20
|
+
readonly SetTransformation: EntityUri;
|
|
21
|
+
readonly inputPattern: EntityUri;
|
|
22
|
+
readonly rule: EntityUri;
|
|
23
|
+
readonly artifactName: EntityUri;
|
|
24
|
+
readonly outputs: EntityUri;
|
|
25
|
+
readonly formatOverrides: EntityUri;
|
|
26
|
+
readonly partitionBy: EntityUri;
|
|
27
|
+
readonly InputPattern: EntityUri;
|
|
28
|
+
readonly matchesClass: EntityUri;
|
|
29
|
+
readonly requires: EntityUri;
|
|
30
|
+
readonly sortBy: EntityUri;
|
|
31
|
+
readonly SortKey: EntityUri;
|
|
32
|
+
readonly byProperty: EntityUri;
|
|
33
|
+
readonly order: EntityUri;
|
|
34
|
+
readonly SortOrder: EntityUri;
|
|
35
|
+
readonly ascending: EntityUri;
|
|
36
|
+
readonly descending: EntityUri;
|
|
37
|
+
readonly OutputFormat: EntityUri;
|
|
38
|
+
readonly backendUri: EntityUri;
|
|
39
|
+
readonly FormatOverride: EntityUri;
|
|
40
|
+
readonly formatTarget: EntityUri;
|
|
41
|
+
readonly metadataKeys: EntityUri;
|
|
42
|
+
readonly metadataRenames: EntityUri;
|
|
43
|
+
readonly trailingNewline: EntityUri;
|
|
44
|
+
readonly omitWrapper: EntityUri;
|
|
45
|
+
readonly RenameEntry: EntityUri;
|
|
46
|
+
readonly fromKey: EntityUri;
|
|
47
|
+
readonly toKey: EntityUri;
|
|
48
|
+
readonly FMT_MARKDOWN_FRONTMATTER: EntityUri;
|
|
49
|
+
readonly FMT_PLAIN_MARKDOWN: EntityUri;
|
|
50
|
+
readonly FMT_TOML: EntityUri;
|
|
51
|
+
readonly FMT_JSON: EntityUri;
|
|
52
|
+
readonly FMT_HTML: EntityUri;
|
|
53
|
+
readonly FMT_SVG: EntityUri;
|
|
54
|
+
readonly Expression: EntityUri;
|
|
55
|
+
readonly ListSourcedExpression: EntityUri;
|
|
56
|
+
readonly ListAggregate: EntityUri;
|
|
57
|
+
readonly IteratingExpression: EntityUri;
|
|
58
|
+
readonly BuildAstNode: EntityUri;
|
|
59
|
+
readonly astClass: EntityUri;
|
|
60
|
+
readonly set: EntityUri;
|
|
61
|
+
readonly AstFieldBinding: EntityUri;
|
|
62
|
+
readonly field: EntityUri;
|
|
63
|
+
readonly bindValue: EntityUri;
|
|
64
|
+
readonly When: EntityUri;
|
|
65
|
+
readonly condition: EntityUri;
|
|
66
|
+
readonly thenBuild: EntityUri;
|
|
67
|
+
readonly elseBuild: EntityUri;
|
|
68
|
+
readonly Concat: EntityUri;
|
|
69
|
+
readonly parts: EntityUri;
|
|
70
|
+
readonly Fallback: EntityUri;
|
|
71
|
+
readonly primary: EntityUri;
|
|
72
|
+
readonly alternate: EntityUri;
|
|
73
|
+
readonly StringLiteral: EntityUri;
|
|
74
|
+
readonly stringLiteral: EntityUri;
|
|
75
|
+
readonly IntegerLiteral: EntityUri;
|
|
76
|
+
readonly integerLiteral: EntityUri;
|
|
77
|
+
readonly DecimalLiteral: EntityUri;
|
|
78
|
+
readonly decimalLiteral: EntityUri;
|
|
79
|
+
readonly BooleanLiteral: EntityUri;
|
|
80
|
+
readonly booleanLiteral: EntityUri;
|
|
81
|
+
readonly VarRef: EntityUri;
|
|
82
|
+
readonly varName: EntityUri;
|
|
83
|
+
readonly PropertyRead: EntityUri;
|
|
84
|
+
readonly readSource: EntityUri;
|
|
85
|
+
readonly readProp: EntityUri;
|
|
86
|
+
readonly Traverse: EntityUri;
|
|
87
|
+
readonly traverseSource: EntityUri;
|
|
88
|
+
readonly through: EntityUri;
|
|
89
|
+
readonly step: EntityUri;
|
|
90
|
+
readonly UriName: EntityUri;
|
|
91
|
+
readonly uriNameOf: EntityUri;
|
|
92
|
+
readonly UriPublisher: EntityUri;
|
|
93
|
+
readonly uriPublisherOf: EntityUri;
|
|
94
|
+
readonly UriPackage: EntityUri;
|
|
95
|
+
readonly uriPackageOf: EntityUri;
|
|
96
|
+
readonly UriVersion: EntityUri;
|
|
97
|
+
readonly uriVersionOf: EntityUri;
|
|
98
|
+
readonly SubjectUri: EntityUri;
|
|
99
|
+
readonly subjectOf: EntityUri;
|
|
100
|
+
readonly UriLiteral: EntityUri;
|
|
101
|
+
readonly refTo: EntityUri;
|
|
102
|
+
readonly DisplayLabel: EntityUri;
|
|
103
|
+
readonly labelTarget: EntityUri;
|
|
104
|
+
readonly labelSource: EntityUri;
|
|
105
|
+
readonly ResolveRef: EntityUri;
|
|
106
|
+
readonly resolveSource: EntityUri;
|
|
107
|
+
readonly Normalize: EntityUri;
|
|
108
|
+
readonly normSource: EntityUri;
|
|
109
|
+
readonly normKind: EntityUri;
|
|
110
|
+
readonly NormalizeKind: EntityUri;
|
|
111
|
+
readonly NORM_TRIM_END: EntityUri;
|
|
112
|
+
readonly IsSet: EntityUri;
|
|
113
|
+
readonly checkExpr: EntityUri;
|
|
114
|
+
readonly ExpressionFragment: EntityUri;
|
|
115
|
+
readonly body: EntityUri;
|
|
116
|
+
readonly CallFragment: EntityUri;
|
|
117
|
+
readonly fragmentRef: EntityUri;
|
|
118
|
+
readonly source: EntityUri;
|
|
119
|
+
readonly Join: EntityUri;
|
|
120
|
+
readonly separator: EntityUri;
|
|
121
|
+
readonly Count: EntityUri;
|
|
122
|
+
readonly Sum: EntityUri;
|
|
123
|
+
readonly Min: EntityUri;
|
|
124
|
+
readonly Max: EntityUri;
|
|
125
|
+
readonly Average: EntityUri;
|
|
126
|
+
readonly loopVar: EntityUri;
|
|
127
|
+
readonly ForEach: EntityUri;
|
|
128
|
+
readonly emit: EntityUri;
|
|
129
|
+
readonly ListMap: EntityUri;
|
|
130
|
+
readonly mapBody: EntityUri;
|
|
131
|
+
readonly Filter: EntityUri;
|
|
132
|
+
readonly predicate: EntityUri;
|
|
133
|
+
readonly PartitionBy: EntityUri;
|
|
134
|
+
readonly partitionKey: EntityUri;
|
|
135
|
+
readonly DistinctBy: EntityUri;
|
|
136
|
+
readonly distinctKey: EntityUri;
|
|
137
|
+
readonly Partition: EntityUri;
|
|
138
|
+
readonly key: EntityUri;
|
|
139
|
+
readonly members: EntityUri;
|
|
140
|
+
readonly AllStatements: EntityUri;
|
|
141
|
+
readonly statementsOf: EntityUri;
|
|
142
|
+
readonly StatementPredicate: EntityUri;
|
|
143
|
+
readonly predicateOf: EntityUri;
|
|
144
|
+
readonly StatementValue: EntityUri;
|
|
145
|
+
readonly valueOf: EntityUri;
|
|
146
|
+
readonly DateFormat: EntityUri;
|
|
147
|
+
readonly dateSource: EntityUri;
|
|
148
|
+
readonly dateFormat: EntityUri;
|
|
149
|
+
readonly BinaryArithmetic: EntityUri;
|
|
150
|
+
readonly arithLeft: EntityUri;
|
|
151
|
+
readonly arithRight: EntityUri;
|
|
152
|
+
readonly Add: EntityUri;
|
|
153
|
+
readonly Subtract: EntityUri;
|
|
154
|
+
readonly Multiply: EntityUri;
|
|
155
|
+
readonly Divide: EntityUri;
|
|
156
|
+
readonly Reverse: EntityUri;
|
|
157
|
+
readonly WindowedMap: EntityUri;
|
|
158
|
+
readonly windowSize: EntityUri;
|
|
159
|
+
readonly windowVar: EntityUri;
|
|
160
|
+
readonly windowBody: EntityUri;
|
|
161
|
+
readonly PairwiseMap: EntityUri;
|
|
162
|
+
readonly firstVar: EntityUri;
|
|
163
|
+
readonly secondVar: EntityUri;
|
|
164
|
+
readonly pairBody: EntityUri;
|
|
165
|
+
readonly Scan: EntityUri;
|
|
166
|
+
readonly initialState: EntityUri;
|
|
167
|
+
readonly stateVar: EntityUri;
|
|
168
|
+
readonly elementVar: EntityUri;
|
|
169
|
+
readonly accumulate: EntityUri;
|
|
170
|
+
readonly ListItemAt: EntityUri;
|
|
171
|
+
readonly itemIndex: EntityUri;
|
|
172
|
+
readonly BinaryComparison: EntityUri;
|
|
173
|
+
readonly compareLeft: EntityUri;
|
|
174
|
+
readonly compareRight: EntityUri;
|
|
175
|
+
readonly Equals: EntityUri;
|
|
176
|
+
readonly GreaterThan: EntityUri;
|
|
177
|
+
readonly LessThan: EntityUri;
|
|
178
|
+
readonly GreaterThanOrEqual: EntityUri;
|
|
179
|
+
readonly LessThanOrEqual: EntityUri;
|
|
180
|
+
readonly Not: EntityUri;
|
|
181
|
+
readonly operand: EntityUri;
|
|
182
|
+
readonly BooleanLogic: EntityUri;
|
|
183
|
+
readonly operands: EntityUri;
|
|
184
|
+
readonly And: EntityUri;
|
|
185
|
+
readonly Or: EntityUri;
|
|
186
|
+
readonly Contains: EntityUri;
|
|
187
|
+
readonly haystack: EntityUri;
|
|
188
|
+
readonly needle: EntityUri;
|
|
189
|
+
readonly UnaryNumericOp: EntityUri;
|
|
190
|
+
readonly value: EntityUri;
|
|
191
|
+
readonly Abs: EntityUri;
|
|
192
|
+
readonly Negate: EntityUri;
|
|
193
|
+
readonly KindPredicate: EntityUri;
|
|
194
|
+
readonly IsReference: EntityUri;
|
|
195
|
+
readonly IsEmbedded: EntityUri;
|
|
196
|
+
readonly IsList: EntityUri;
|
|
197
|
+
readonly kindCheck: EntityUri;
|
|
198
|
+
readonly StatementObject: EntityUri;
|
|
199
|
+
readonly statementSource: EntityUri;
|
|
200
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KanonakDocument, Import, DocumentReference } from '@kanonak-protocol/types/document/models/types';
|
|
2
|
+
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
3
|
+
/**
|
|
4
|
+
* A repository that exposes exactly one target document through
|
|
5
|
+
* `getAllDocumentsAsync` but delegates every import-resolution lookup
|
|
6
|
+
* (`getHighestCompatibleVersionAsync`, `getDocumentAsync`, etc.) to a
|
|
7
|
+
* broader backing repository.
|
|
8
|
+
*
|
|
9
|
+
* This is what lets `KanonakObjectParser.parseKanonaks` parse a single
|
|
10
|
+
* capability or skill document with full URI resolution across its
|
|
11
|
+
* transitive imports, without inheriting every other cached document's
|
|
12
|
+
* entities.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SingleDocumentRepository implements IKanonakDocumentRepository {
|
|
15
|
+
private readonly doc;
|
|
16
|
+
private readonly broader;
|
|
17
|
+
constructor(doc: KanonakDocument, broader: IKanonakDocumentRepository);
|
|
18
|
+
getAllDocumentsAsync(): Promise<KanonakDocument[]>;
|
|
19
|
+
getDocumentAsync(identifier: string): Promise<KanonakDocument | null>;
|
|
20
|
+
getDocumentsByNamespaceAsync(publisher: string, package_: string): Promise<KanonakDocument[]>;
|
|
21
|
+
getHighestCompatibleVersionAsync(publisher: string, import_: Import): Promise<KanonakDocument | null>;
|
|
22
|
+
saveDocumentAsync(): Promise<void>;
|
|
23
|
+
deleteDocumentAsync(): Promise<void>;
|
|
24
|
+
clearNamespaceAsync(): Promise<void>;
|
|
25
|
+
getAllDocumentReferencesAsync(): Promise<DocumentReference[]>;
|
|
26
|
+
getDocumentContentAsync(identifier: string): Promise<string | null>;
|
|
27
|
+
getDocumentUriAsync(identifier: string): Promise<string | null>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { SubjectKanonak } from '../kanonaks/SubjectKanonak.js';
|
|
2
|
+
import { EmbeddedKanonak } from '../kanonaks/EmbeddedKanonak.js';
|
|
3
|
+
import { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
|
|
4
|
+
import { Kanonak } from '../kanonaks/Kanonak.js';
|
|
5
|
+
import { KanonakUri } from '../resolution/KanonakUri.js';
|
|
6
|
+
/**
|
|
7
|
+
* Canonical URI identity for an ontology entity.
|
|
8
|
+
*
|
|
9
|
+
* Version is intentionally omitted: the CLI compares against
|
|
10
|
+
* publisher + package + name so it can accept any backwards-compatible
|
|
11
|
+
* version of the ontology it was built against. If a new major version
|
|
12
|
+
* breaks semantics, a separate entry (or explicit version check) is
|
|
13
|
+
* added at that point.
|
|
14
|
+
*/
|
|
15
|
+
export interface EntityUri {
|
|
16
|
+
publisher: string;
|
|
17
|
+
package_: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert a `KanonakUri` or `EntityUri` into a stable map key.
|
|
22
|
+
* Version is dropped.
|
|
23
|
+
*/
|
|
24
|
+
export declare function uriKey(uri: KanonakUri | EntityUri): string;
|
|
25
|
+
/**
|
|
26
|
+
* True when a resolved `KanonakUri` matches the given publisher + package
|
|
27
|
+
* + local name (version ignored).
|
|
28
|
+
*/
|
|
29
|
+
export declare function uriMatches(uri: KanonakUri, target: EntityUri): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* True when a `Kanonak` is a `DefinedKanonak` whose `type` statement's
|
|
32
|
+
* object URI matches the given class URI.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasType(kanonak: Kanonak, target: EntityUri): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Filter a list of parsed kanonaks down to `SubjectKanonak`s whose type
|
|
37
|
+
* matches the given class URI.
|
|
38
|
+
*/
|
|
39
|
+
export declare function findSubjectsByType(kanonaks: Kanonak[], target: EntityUri): SubjectKanonak[];
|
|
40
|
+
/**
|
|
41
|
+
* Look up a `SubjectKanonak` by full URI across a list of kanonaks.
|
|
42
|
+
* Used for following a reference to its definition (e.g. to read a
|
|
43
|
+
* `License`'s `spdxId` or a `Tool`'s `label`).
|
|
44
|
+
*
|
|
45
|
+
* Version handling:
|
|
46
|
+
*
|
|
47
|
+
* - When `uri.version` is present (concrete `M.m.p`), the match
|
|
48
|
+
* is STRICT — only a subject whose `namespace` is exactly
|
|
49
|
+
* `<publisher>/<package>@<M.m.p>` qualifies. This is what
|
|
50
|
+
* `tx.ResolveRef` needs when walking inner references in a
|
|
51
|
+
* multi-scope SetTransformation: a reference to
|
|
52
|
+
* `pkg@1.0.1/foo` must resolve to the 1.0.1 instance, not
|
|
53
|
+
* collapse to whichever same-named instance was loaded first
|
|
54
|
+
* across versions (kanonak-protocol/typescript#12).
|
|
55
|
+
*
|
|
56
|
+
* - When `uri.version` is absent (an unversioned reference, e.g.
|
|
57
|
+
* authored as `pkg/foo` with no `@version` qualifier or coming
|
|
58
|
+
* from an `EntityUri` that carries no version), the match is
|
|
59
|
+
* LENIENT — any version of `<publisher>/<package>/<name>`
|
|
60
|
+
* qualifies. This preserves the historical behavior for
|
|
61
|
+
* callers that pass version-less URIs (UriLiteral, parsed
|
|
62
|
+
* bare-name references in single-version workspaces, etc).
|
|
63
|
+
*/
|
|
64
|
+
export declare function findSubjectByUri(kanonaks: Kanonak[], uri: KanonakUri): SubjectKanonak | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Read a datatype property value (string, number, boolean) off a defined
|
|
67
|
+
* kanonak, by property URI. Returns `undefined` when the property is not
|
|
68
|
+
* set or not a datatype value.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getDatatypeValue(defined: DefinedKanonak, property: EntityUri): string | number | boolean | undefined;
|
|
71
|
+
export declare function getStringValue(defined: DefinedKanonak, property: EntityUri): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Read the target `KanonakUri` of an ObjectProperty reference off a
|
|
74
|
+
* defined kanonak, by property URI. Returns `undefined` when the
|
|
75
|
+
* property is not set or not a reference statement.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getReferenceUri(defined: DefinedKanonak, property: EntityUri): KanonakUri | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Read an embedded kanonak off a defined kanonak, by property URI.
|
|
80
|
+
* Returns `undefined` when the property is not set or not an embedded
|
|
81
|
+
* statement.
|
|
82
|
+
*/
|
|
83
|
+
export declare function getEmbeddedValue(defined: DefinedKanonak, property: EntityUri): EmbeddedKanonak | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Read the list values off a ListStatement property. Each item is either
|
|
86
|
+
* a `ReferenceKanonak` (named reference) or an `EmbeddedKanonak` (inline).
|
|
87
|
+
* Returns an empty array when the property is unset or not a list.
|
|
88
|
+
*/
|
|
89
|
+
export declare function getListValues(defined: DefinedKanonak, property: EntityUri): Kanonak[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { uriKey, uriMatches, hasType, findSubjectsByType, findSubjectByUri, getDatatypeValue, getStringValue, getReferenceUri, getEmbeddedValue, getListValues, } from './UriHelpers.js';
|
|
2
|
+
export type { EntityUri } from './UriHelpers.js';
|
|
3
|
+
export { SingleDocumentRepository } from './SingleDocumentRepository.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-NPWF35XZ.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{k as SingleDocumentRepository,e as findSubjectByUri,d as findSubjectsByType,f as getDatatypeValue,i as getEmbeddedValue,j as getListValues,h as getReferenceUri,g as getStringValue,c as hasType,a as uriKey,b as uriMatches};
|
package/dist/validation/index.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(o=>(o.Warning="Warning",o.Error="Error",o))(R||{});var h=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var ee=class g{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new g;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};import*as G from"js-yaml";var Z=class{parse(e){let o=this.parseWithErrors(e);if(!o.isValid){let t=o.errors[0];throw new Error(`YAML parse error at line ${t.line}, column ${t.column}: ${t.message}`)}return o.document}parseWithErrors(e){let o=[],t;try{e=e.replace(/^\uFEFF/,"");let i=G.load(e);if(!i||typeof i!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:o,isValid:!0};let r=this.extractMetadata(i),n=this.extractBody(i,r);return t={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:t,errors:o,isValid:!0}}catch(i){let r=i,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return o.push(n),{document:void 0,errors:o,isValid:!1}}}save(e){let o={};if(e.metadata.namespace_){let t=e.metadata.namespace_,i={type:"Package",publisher:t.publisher};t.version&&(i.version=`${t.version.major}.${t.version.minor}.${t.version.patch}`),e.metadata.imports&&(i.imports=this.serializeImports(e.metadata.imports)),o[t.package_]=i}return Object.assign(o,e.body),G.dump(o,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let o=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!o)return[];let t=[];for(let i of Object.values(o))t.push(...i);return t},enumerable:!0,configurable:!0}),e}createVersion(e,o,t){return{major:e,minor:o,patch:t,toString:()=>`${e}.${o}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===o&&r.patch===t,getHashCode:()=>e<<20|o<<10|t,compareTo:r=>e!==r.major?e-r.major:o!==r.minor?o-r.minor:t-r.patch}}extractMetadata(e){let o=this.createEmptyMetadata();for(let[t,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){o.type_="Package";let r=t,n=i.publisher,a=i.version?this.parseVersion(i.version):void 0;return n&&r&&(o.namespace_={publisher:n,package_:r,version:a,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:c=>!c||typeof c!="object"?!1:c.publisher===n&&c.package_===r&&(!a||!c.version||a.equals(c.version)),getHashCode:()=>{let c=0;for(let s=0;s<n.length;s++)c=(c<<5)-c+n.charCodeAt(s);for(let s=0;s<r.length;s++)c=(c<<5)-c+r.charCodeAt(s);return c|0}}),i.imports&&Array.isArray(i.imports)&&(o.imports=this.parseImportsV3(i.imports)),this.addAllImportsGetter(o)}if(e.kanonak&&typeof e.kanonak=="object"){let t=e.kanonak;return(t.publisher||t.package||t.version)&&(o.namespace_=this.parseNamespace(t)),t.imports&&typeof t.imports=="object"&&(o.imports=this.parseImportsLegacy(t.imports)),this.addAllImportsGetter(o)}return o}extractBody(e,o){let t={},i;for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){i=r;break}for(let[r,n]of Object.entries(e))r!==i&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=n);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:a=>!a||typeof a!="object"?!1:a.publisher===r[1]&&a.package_===r[2]&&(!n||!a.version||n.equals(a.version)),getHashCode:()=>{let a=0;for(let c=0;c<r[1].length;c++)a=(a<<5)-a+r[1].charCodeAt(c);for(let c=0;c<r[2].length;c++)a=(a<<5)-a+r[2].charCodeAt(c);return a|0}}}}let o=e.publisher||"",t=e.package||"",i=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:o,package_:t,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===o&&r.package_===t&&(!i||!r.version||i.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<o.length;n++)r=(r<<5)-r+o.charCodeAt(n);for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let o=e.split(".").map(Number);return this.createVersion(o[0]||0,o[1]||0,o[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let o={};for(let t of e)if(!(!t||typeof t!="object"))if(t.packages&&Array.isArray(t.packages)){let i=t.publisher;if(!i)throw new Error("PublisherImport requires 'publisher' property");o[i]||(o[i]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,i);o[i].push(n)}}else{let i=this.parseImportFromEmbeddedObject(t,t.publisher),r=i.publisher||"";o[r]||(o[r]=[]),o[r].push(i)}return o}parseImportsLegacy(e){let o={};for(let[t,i]of Object.entries(e))Array.isArray(i)&&(o[t]=i.map(r=>this.parseImport(r,t)));return o}parseImportFromEmbeddedObject(e,o){let t=e.package;if(!t)throw new Error("Import requires 'package' property");let i=e.match;if(!i)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),a=this.parseVersionOperator(i),c=this.calculateMaxVersion(i,n),s=e.alias;return{package_:`${t} ${i} ${n.toString()}`,publisher:o,packageName:t,versionOperator:a,version:n,alias:s,minVersion:n,maxVersion:c,toEmbeddedObject:()=>{let p={package:t,match:i,version:n.toString()};return s&&(p.alias=s),p},toString:()=>s?`${t} ${i} ${n.toString()} as ${s}`:`${t} ${i} ${n.toString()}`}}parseImport(e,o){if(typeof e=="string"){let c=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(c){let p=c[1].trim(),l=c[2],y=this.parseVersion(c[3].trim()),u=c[4].trim(),m=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:p,versionOperator:m,version:y,alias:u,minVersion:y,maxVersion:f,toEmbeddedObject:()=>{let d={package:p,match:l,version:y.toString()};return u&&(d.alias=u),d},toString:()=>`${p} ${l} ${y.toString()} as ${u}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let p=s[1].trim(),l=s[2],y=this.parseVersion(s[3].trim()),u=this.parseVersionOperator(l),m=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:p,versionOperator:u,version:y,alias:void 0,minVersion:y,maxVersion:m,toEmbeddedObject:()=>({package:p,match:l,version:y.toString()}),toString:()=>`${p} ${l} ${y.toString()}`}}}let t=this.parseVersionOperator(e.operator||"~"),i=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=["=","~","^","*"][t],a=this.calculateMaxVersion(e.operator||"~",i);return{package_:e.package||"",publisher:o,packageName:r,versionOperator:t,version:i,alias:e.alias,minVersion:i,maxVersion:a,toEmbeddedObject:()=>{let c={package:r,match:n,version:i.toString()};return e.alias&&(c.alias=e.alias),c},toString:()=>`${r} ${n} ${i.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,o){switch(e){case"~":return this.createVersion(o.major,o.minor+1,0);case"^":return o.major===0?this.createVersion(0,o.minor+1,0):this.createVersion(o.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let o=[];for(let[t,i]of Object.entries(e)){let r={publisher:t,packages:i.map(n=>{let a=["=","~","^","*"][n.versionOperator],c={package:n.packageName,match:a,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(c.alias=n.alias),c})};o.push(r)}return o}};var I=class g{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,i]of Object.entries(e.body))i&&typeof i=="object"&&!Array.isArray(i)&&this.validateEntity(t,i,o);return o}validateEntity(e,o,t){for(let[i,r]of Object.entries(o)){let n=r?.toString()??"";if(n&&g.NAMESPACE_PREFIX_PATTERN.test(n)){let a=this.getSuggestionForPrefixedValue(n),c=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=i,s.expectedValue=a,s.message=`Invalid namespace prefix '${n}'. Use '${a}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${i}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var D=class g{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){let n=g.VALID_AUGMENTATION_PATTERN.test(i);if(!n&&!t&&g.RESERVED_WORDS.has(i.toLowerCase())){let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=i,a.message=`Entity name '${i}' is a reserved word and cannot be used.`,a.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(a);continue}if(!n&&!g.VALID_NAME_PATTERN.test(i)){let a;/^\d/.test(i)?a="Entity names must start with a letter, not a number.":i.includes(" ")?a="Entity names cannot contain spaces. Use camelCase or underscores instead.":a="Entity names must start with a letter and contain only letters, numbers, and underscores.";let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.message=`Invalid entity name '${i}'. ${a}`,c.suggestion=a,o.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(i,r,o)}return o}validatePropertyNames(e,o,t){for(let i of Object.keys(o))if(!g.VALID_PROPERTIES.has(i)&&!g.VALID_PROPERTY_NAME_PATTERN.test(i)){let r=new h;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=i,r.message=`Property name '${i}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var O=class g{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[i,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let n=r,a=n.type;if(a){let c=[];if(Array.isArray(a))for(let s of a){let p=s?.toString();p&&p==="Property"&&!t&&c.push(p)}else{let s=a?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){let p=this.getPropertyValue(n,"range"),l=this.determinePropertyType(p),y=new h;y.ruleType=this.ruleName,y.severity="Error",y.entityName=i,y.propertyName="type",y.actualValue=s,y.expectedValue=l,y.message=`Invalid property type '${s}'. Use '${l}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(y)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":g.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let i=o.type;if(i){let r=i.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i)||t.includes("."))continue;let r=i,n="type"in r,a=r.type?.toString().trim();if(!n||!a){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.suggestion=`Add a type statement like:
|
|
2
|
-
type: Scene
|
|
3
|
-
|
|
4
|
-
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,c.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(c)}}return o}};var Y=class g{constructor(e,o,t,i){this.publisher=e;this.package_=o;this.name=t;this.version=i}publisher;package_;name;version;static parse(e){if(!e||e.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");let o=e.split("/");if(o.length!==3)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let[t,i,r]=o;if(!t||!i||!r)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let n=i.indexOf("@");if(n===-1)return new g(t,i,r,void 0);let a=i.substring(0,n),c=i.substring(n+1);if(!a||!c)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let s=c.split(".").map(Number),p=oe(s[0]||0,s[1]||0,s[2]||0);return new g(t,a,r,p)}toString(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}/${this.name}`:`${this.publisher}/${this.package_}/${this.name}`}};function oe(g,e,o){return{major:g,minor:e,patch:o,toString:()=>`${g}.${e}.${o}`,equals:t=>!t||typeof t!="object"?!1:t.major===g&&t.minor===e&&t.patch===o,getHashCode:()=>g<<20|e<<10|o,compareTo:t=>g!==t.major?g-t.major:e!==t.minor?e-t.minor:o-t.patch}}function k(g){if(Array.isArray(g))return g.map(o=>o?.toString()??"").filter(o=>o.length>0);let e=g?.toString();return e?[e]:[]}var A=class{cache=new Map;repository;logger;constructor(e,o){this.repository=e,this.logger=o}async resolveEntityAsync(e,o){let t=o.metadata?.namespace_?.toString()??"unknown",i=this.cache.get(t);if(i){let n=i.get(e);if(n)return n}let r=await this.buildEntityIndexAsyncInternal(o,new Set,"");return this.cache.set(t,r),r.get(e)??null}async resolveAllEntitiesAsync(e,o){let t=await this.buildAllEntitiesIndexAsync(o,new Set,"");if(e.includes(".")){let i=e.split("."),r=i[0],n=i[1],a=await this.findDocumentForAlias(o,r);return a?await this.resolveAllEntitiesAsync(n,a):[]}return t.filter(i=>i.entityName===e)}async buildAllEntitiesIndexAsync(e,o,t){let i=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`;for(let[a,c]of Object.entries(e.body))if(!a.includes(".")&&c&&typeof c=="object"&&!Array.isArray(c)){let s=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.push({entityName:a,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,a,s),entity:c,definedInNamespace:r,isImported:t.length>0,importPath:n})}if(this.logger?.debug?.(`Collected ${i.length} entities from ${r}`),e.metadata?.imports){let a=Object.values(e.metadata.imports).reduce((c,s)=>c+s.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[c,s]of Object.entries(e.metadata.imports))for(let p of s)try{this.logger?.debug?.(`Resolving import: ${c}/${p.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(c,p);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let y=await this.buildAllEntitiesIndexAsync(l,o,n);i.push(...y),this.logger?.debug?.(`Added ${y.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${c}/${p.packageName}`)}catch(l){let y=l;throw this.logger?.error?.(`Failed to process import ${c}/${p.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${c}/${p.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return i}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,o,t){let i=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`,a=0;for(let[c,s]of Object.entries(e.body))if(!c.includes(".")&&s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(c)){let p=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(c,{entityName:c,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,c,p),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:n}),a++}if(this.logger?.debug?.(`Indexed ${a} entities from ${r}`),e.metadata?.imports){let c=Object.values(e.metadata.imports).reduce((s,p)=>s+p.length,0);this.logger?.debug?.(`Processing ${c} import(s) for ${r}`);for(let[s,p]of Object.entries(e.metadata.imports))for(let l of p)try{this.logger?.debug?.(`Resolving import: ${s}/${l.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(s,l);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let u=await this.buildEntityIndexAsyncInternal(y,o,n),m=0;for(let[f,d]of u.entries())if(i.has(f)||(i.set(f,d),m++),l.alias&&!f.includes(".")){let b=`${l.alias}.${f}`;i.has(b)||(i.set(b,d),m++)}this.logger?.debug?.(`Merged ${m} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${s}/${l.packageName}`)}catch(y){let u=y;throw this.logger?.error?.(`Failed to process import ${s}/${l.packageName} for namespace ${r}. Error: ${u.message}`,u),new Error(`Failed to process import ${s}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:y})}}return i}async findDocumentForAlias(e,o){if(!e.metadata?.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i){if(r.alias===o)return await this.repository.getHighestCompatibleVersionAsync(t,r);if(!r.alias&&r.packageName===o)return await this.repository.getHighestCompatibleVersionAsync(t,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubclassOfRecursiveAsync(e,o,t,i)}async isSubclassOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subClassOf;if(n){let a=k(n);for(let c of a)if(c===o||await this.isSubclassOfRecursiveAsync(c,o,t,i))return!0}return!1}async isSubpropertyOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubpropertyOfRecursiveAsync(e,o,t,i)}async isSubpropertyOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subPropertyOf;if(n){let a=k(n);for(let c of a)if(c===o||await this.isSubpropertyOfRecursiveAsync(c,o,t,i))return!0}return!1}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,o){let t=[],i=new A(o),r=await this.buildPropertyRangeMap(e,i);for(let[n,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&await this.checkEmbeddedTypes(n,a,void 0,r,i,e,t,0);return t}pickRange(e,o,t){if(e.length===0)return;if(e.length===1)return e[0].range;let i=o.indexOf(".");if(i>0){let r=o.substring(0,i),n=e.find(a=>a.declaringAlias===r);if(n)return n.range}if(t){let r=this.localName(t),n=e.find(a=>this.localName(a.domain)===r);if(n)return n.range}return e[0].range}async checkEmbeddedTypes(e,o,t,i,r,n,a,c){if(c>0){let p=o.type;if(p!=null){let l=await this.validateEmbeddedType(e,String(p),t,r,n);l&&a.push(l)}}let s=o.type!==void 0&&o.type!==null?String(o.type):void 0;for(let[p,l]of Object.entries(o)){let y=this.localName(p),u=i.get(y),f=(u!==void 0?this.pickRange(u,p,s):void 0)??t;if(typeof l=="object"&&l!==null)if(Array.isArray(l))for(let d=0;d<l.length;d++){let b=l[d];typeof b=="object"&&b!==null&&!Array.isArray(b)&&await this.checkEmbeddedTypes(`${e}.${p}[${d}]`,b,f,i,r,n,a,c+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,l,f,i,r,n,a,c+1)}}async validateEmbeddedType(e,o,t,i,r){if(o.length===0||!t)return null;let n=this.localName(o),a=this.localName(t);if(a==="Resource"||a==="Class")return null;let c=e.split(".")[0];if(n===a){let p=new h;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=c,p.propertyName=e,p.actualValue=o,p.expectedValue=t,p.message=`Embedded object at '${e}' declares 'type: ${o}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${o}' line, or keep it if explicitness is preferred over concision.`,p}if(await i.isSubclassOfAsync(o,t,r)||(n!==o||a!==t)&&await i.isSubclassOfAsync(n,a,r))return null;let s=new h;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=o,s.expectedValue=t,s.message=`Embedded object at '${e}' has 'type: ${o}', which is not a subclass of the parent property's range '${t}'.`,s.suggestion=`Either remove the 'type: ${o}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${o}' class definition so the relationship holds.`,s}localName(e){let o=e.lastIndexOf(".");return o<0||o===e.length-1?e:e.substring(o+1)}async buildPropertyRangeMap(e,o){let t=new Map,i=await o.buildEntityIndexAsync(e),r=new Map;for(let[n,a]of i){let c=a.entity.type;if(c==null)continue;let s=String(c),p=this.localName(s);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let y=a.entity.range;if(y==null)continue;let u=String(y);if(u.length===0)continue;let m=a.entity.domain,f=m!=null?String(m):"",d=a.uri.toString(),b=r.get(d),v=n.includes(".");(!b||v&&!b.entityName.includes("."))&&r.set(d,{entityName:n,domain:f,range:u})}for(let n of r.values()){let a=this.localName(n.entityName),c=n.entityName.indexOf("."),s=c>0?n.entityName.substring(0,c):void 0,p=t.get(a)??[];p.push({domain:n.domain,range:n.range,declaringAlias:s}),t.set(a,p)}return t}};var E=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let i=await o.getAllDocumentsAsync();for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n)if(!await o.getHighestCompatibleVersionAsync(r,a)){let s=await this.determineImportErrorAsync(o,r,a,i),p=new h;p.ruleType=this.ruleName,p.severity="Error",p.message=s.message,p.suggestion=s.suggestion,p.entityName=`Import: ${r}/${a.packageName}`,p.actualValue=a.toString(),p.expectedValue=s.expectedValue,t.push(p)}return t}async determineImportErrorAsync(e,o,t,i){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=i.filter(u=>u.metadata.namespace_?.publisher===o).map(u=>u.metadata.namespace_.package_).filter((u,m,f)=>f.indexOf(u)===m),p=this.findSimilarPackages(t.packageName,s),l=`Import '${o}/${t.package_}' not found - package does not exist`,y=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:l,suggestion:y,expectedValue:"Existing package"}}let a=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),c=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${a}. Required: ${c}`,expectedValue:c}}getAcceptableVersionRange(e){switch(e.versionOperator){case 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(n=>n.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(n.toLowerCase()));if(t.length>0)return t.sort((n,a)=>n.length-a.length);let i=o.map(n=>({package:n,distance:this.levenshteinDistance(e.toLowerCase(),n.toLowerCase())})).sort((n,a)=>n.distance-a.distance),r=Math.max(3,Math.floor(e.length*.4));return i.filter(n=>n.distance<=r).map(n=>n.package)}levenshteinDistance(e,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,i=o.length,r=Array(t+1).fill(null).map(()=>Array(i+1).fill(0));for(let n=0;n<=t;n++)r[n][0]=n;for(let n=0;n<=i;n++)r[0][n]=n;for(let n=1;n<=t;n++)for(let a=1;a<=i;a++){let c=e[n-1]===o[a-1]?0:1;r[n][a]=Math.min(Math.min(r[n-1][a]+1,r[n][a-1]+1),r[n-1][a-1]+c)}return r[t][i]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],i=new A(o),r=await i.buildEntityIndexAsync(e),n=new Set;for(let[a,c]of r.entries()){let s=c.entity.type;if(s){let p=s.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&n.add(a)}}for(let[a,c]of Object.entries(e.body)){if(!c||typeof c!="object"||Array.isArray(c))continue;let s=c,p=this.getPropertyValue(s,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[l,y]of Object.entries(s))l==="type"||l==="label"||l==="comment"||!(n.has(l)||Array.from(n).some(m=>m.endsWith(`.${l}`)))||await this.validateReferenceValue(a,l,y,e,i,t)}return t}async validateReferenceValue(e,o,t,i,r,n){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,i)||n.push(this.createUnresolvedReferenceError(e,o,t));else if(Array.isArray(t))for(let a=0;a<t.length;a++){let c=t[a];typeof c=="string"&&(await r.resolveEntityAsync(c,i)||n.push(this.createUnresolvedReferenceError(e,`${o}[${a}]`,c)))}}}createUnresolvedReferenceError(e,o,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
5
|
-
|
|
6
|
-
Possible solutions:
|
|
7
|
-
\u2022 Add import if the entity is defined in another namespace:
|
|
8
|
-
kanonak namespace add-import <publisher>/<package>@<version>
|
|
9
|
-
\u2022 Check for typos in the reference name '${t}'
|
|
10
|
-
\u2022 Define '${t}' in the current namespace or an appropriate namespace
|
|
11
|
-
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,r=new h;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t,r.message=`Reference to '${t}' could not be resolved`,r.suggestion=i,r.expectedValue="A valid entity reference that exists in the current document or imported namespaces",r}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}};var j=class{ruleName="TypeAmbiguity";async validateAsync(e,o){let t=[],i=new Map,r=[];if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){r.push({doc:s,import:c,publisher:n});let p=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...p.map(l=>({doc:l,import:null,publisher:n})))}}for(let{doc:n,import:a}of r){let c=n.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(n.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:c,import:a})}for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let c=a;this.checkAmbiguousReference(c,"type",i,n,t),this.checkAmbiguousReference(c,"subClassOf",i,n,t),this.checkAmbiguousReference(c,"subPropertyOf",i,n,t),this.checkAmbiguousReference(c,"domain",i,n,t),this.checkAmbiguousReference(c,"range",i,n,t)}return t}checkAmbiguousReference(e,o,t,i,r){let n=e[o];if(!n)return;let a=k(n);for(let c of a){if(c.includes("."))continue;let s=t.get(c);if(s&&s.length>1){let p=s.map(m=>m.namespace).join(", "),l=[];for(let{namespace:m,import:f}of s)if(f?.alias)l.push(`${f.alias}.${c}`);else{let d=m.split("/"),v=d[d.length-1]?.split("@")[0]??"alias";l.push(`${v}.${c}`)}let y=l.length>0?`Use one of: ${l.join(", ")}`:"Consider adding namespace aliases to your imports",u=new h;u.ruleType=this.ruleName,u.severity="Warning",u.entityName=i,u.propertyName=o,u.actualValue=c,u.message=`Type '${c}' is ambiguous. It's defined in: ${p}`,u.suggestion=y,r.push(u)}}}async getTransitiveImportsAsync(e,o,t){let i=[],r=o.metadata?.namespace_?.toString()??"";if(t.has(r))return i;if(t.add(r),o.metadata?.imports)for(let[n,a]of Object.entries(o.metadata.imports))for(let c of a){let s=await e.getHighestCompatibleVersionAsync(n,c);if(s){i.push(s);let p=await this.getTransitiveImportsAsync(e,s,t);i.push(...p)}}return i}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildClassHierarchy(e,o,i,r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let c=a,s=c.type,p=c.subClassOf;if(s?.toString()==="Class"&&p){let l=n,y=this.detectCycle(l,i);if(y){let u=y.join(" \u2192 "),m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular class hierarchy detected: ${u}`,m.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",m.entityName=l,m.propertyName="subClassOf",m.actualValue=u,t.push(m);break}}}return t}async buildClassHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let c=a,s=c.type,p=c.subClassOf;if(s?.toString()==="Class"&&p){let l=k(p);l.length>0&&t.set(n,l)}}if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);s&&await this.buildClassHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),a=t.slice(n);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let a=this.detectCycleRecursive(n,o,t,i);if(a)return a}return t.pop(),null}};var K=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildPropertyHierarchy(e,o,i,r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)&&a.subPropertyOf){let p=n,l=this.detectCycle(p,i);if(l){let y=l.join(" \u2192 "),u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular property hierarchy detected: ${y}`,u.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",u.entityName=p,u.propertyName="subPropertyOf",u.actualValue=y,t.push(u);break}}return t}async buildPropertyHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let c=a,s=c.type;if(s){let p=s.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let l=c.subPropertyOf;if(l){let y=k(l);y.length>0&&t.set(n,y)}}}}if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);s&&await this.buildPropertyHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),a=t.slice(n);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let a=this.detectCycleRecursive(n,o,t,i);if(a)return a}return t.pop(),null}};var x=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,o){let t=[];for(let[i,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let n=r,a=n.type?.toString();if(a==="DatatypeProperty"||a==="ObjectProperty"||a?.endsWith(".DatatypeProperty")||a?.endsWith(".ObjectProperty")){let c="range"in n,s=n.range?.toString().trim();if(!c||!s){let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=i,p.propertyName="range",p.message=`Property '${i}' must have a 'range' defined.`,p.suggestion=a==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=a==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var C=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=n.type?.toString();(c==="Class"||c&&c.endsWith(".Class"))&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=k(n.subClassOf);for(let s=0;s<c.length;s++){let p=c[s];if(this.builtInClasses.has(p)||i.has(p))continue;if(!await this.isClassAvailableInImports(e,o,p)){let y=c.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Class '${p}' referenced in subClassOf${y} is not defined or imported`,u.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,u.entityName=r,u.propertyName="subClassOf",u.actualValue=p,u.expectedValue="Defined or imported class",t.push(u)}}}return t}async isClassAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(m==="Class"||m&&m.endsWith(".Class"))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(s,o,p,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(y==="Class"||y&&y.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var T=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=n.type?.toString();(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty")&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=k(n.subPropertyOf);for(let s=0;s<c.length;s++){let p=c[s];if(this.builtInProperties.has(p)||i.has(p))continue;if(!await this.isPropertyAvailableInImports(e,o,p)){let y=c.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${p}' referenced in subPropertyOf${y} is not defined or imported`,u.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,u.entityName=r,u.propertyName="subPropertyOf",u.actualValue=p,u.expectedValue="Defined or imported property",t.push(u)}}}return t}async isPropertyAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,o,p,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],i=e.metadata.namespace_?.toString();if(!i)return t;let r=new Map,n=new Set;await this.buildImportGraph(e,o,r,n);let a=this.detectCycle(i,r);if(a){let c=a.join(" \u2192 "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${c}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=c,t.push(s)}return t}async buildImportGraph(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!(!r||i.has(r))&&(i.add(r),e.metadata.imports)){let n=[];for(let[a,c]of Object.entries(e.metadata.imports))for(let s of c){let p=`${a}/${s.packageName}@${s.version}`;n.push(p);let l=await o.getHighestCompatibleVersionAsync(a,s);l&&await this.buildImportGraph(l,o,t,i)}n.length>0&&t.set(r,n)}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){let r=t.indexOf(e);if(r>=0){let a=t.slice(r);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let n=o.get(e);if(n)for(let a of n){let c=this.detectCycleRecursive(a,o,t,i);if(c)return c}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=n.type?.toString();this.isPropertyType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(this.isPropertyType(c)||this.isClassType(c))continue;for(let[s,p]of Object.entries(a)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let m=s.lastIndexOf(".");y=s.substring(0,m),l=s.substring(m+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${s}' is not defined or imported`,m.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
|
|
12
|
-
1. Verify the namespace is imported with the correct alias
|
|
13
|
-
2. Check if the property name is spelled correctly
|
|
14
|
-
3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
|
|
15
|
-
1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
16
|
-
2. Import the namespace that contains '${s}', OR
|
|
17
|
-
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,m.entityName=r,m.propertyName=s,m.actualValue=p?.toString(),m.expectedValue="A defined or imported property",t.push(m)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){if(i!==null&&a.alias!==i)continue;let c=await o.getHighestCompatibleVersionAsync(r,a);if(c){let s=c.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,o,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var L=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=n.type?.toString();this.isPropertyType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(!this.isPropertyType(c)&&!this.isClassType(c))continue;for(let[s,p]of Object.entries(a)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let m=s.lastIndexOf(".");y=s.substring(0,m),l=s.substring(m+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let m=this.isClassType(c)?"class":"property",f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${s}' used on ${m} '${r}' is not defined or imported`,f.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
|
|
18
|
-
1. Verify the namespace is imported with the correct alias
|
|
19
|
-
2. Check if the property name is spelled correctly
|
|
20
|
-
3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
|
|
21
|
-
1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
22
|
-
2. Import the namespace that contains '${s}', OR
|
|
23
|
-
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=p?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){if(i!==null&&a.alias!==i)continue;let c=await o.getHighestCompatibleVersionAsync(r,a);if(c){let s=c.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,o,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var W=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"XsdImport"}async validateAsync(e,o){let t=[],i=new Set,r=[];for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,s=!1,p=c.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="DatatypeProperty"){s=!0;break}}else p?.toString()==="DatatypeProperty"&&(s=!0);if(s){r.push(n);let l=this.getPropertyValue(c,"range");l&&this.xsdTypes.has(l)&&i.add(l)}}if(i.size>0&&!await this.checkXsdImportAsync(e.metadata,o)){let a=Array.from(i).sort().join(", "),c=r.sort().join(", "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`XSD namespace not imported but XSD types are used: ${a}`,s.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${c}`,s.entityName="imports",t.push(s)}return t}async checkXsdImportAsync(e,o,t=new Set){if(!e?.imports)return!1;let i=e.namespace_?.toString()??"";if(i&&t.has(i))return!1;i&&t.add(i);for(let[,r]of Object.entries(e.imports))for(let n of r)if(n.packageName==="xsd"||n.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[r,n]of Object.entries(e.imports))for(let a of n){let c=await o.getHighestCompatibleVersionAsync(r,a);if(c?.metadata&&await this.checkXsdImportAsync(c.metadata,o,t))return!0}return!1}getPropertyValue(e,o){return e[o]?.toString()}};var H=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,o){let t=[],i=await this.buildEntitySourceMapAsync(e,o),r=await this.buildDatatypePropertyNamesAsync(e,o);for(let[n,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&this.validateEntityReferences(n,a,i,r,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,i=new Set;for(let r of Object.keys(e.body)){let n=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${n})`)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){let c=await o.getHighestCompatibleVersionAsync(r,a);c&&await this.collectEntitiesRecursivelyAsync(c,t,i,o)}return t}async collectEntitiesRecursivelyAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let n of Object.keys(e.body)){o.has(n)||o.set(n,[]);let a=o.get(n);a.includes(r)||a.push(r)}if(e.metadata.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await i.getHighestCompatibleVersionAsync(n,c);s&&await this.collectEntitiesRecursivelyAsync(s,o,t,i)}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,i=new Set;if(await this.collectDatatypePropertiesAsync(e,t,i,o),e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){let c=await o.getHighestCompatibleVersionAsync(r,a);c&&await this.collectDatatypePropertiesAsync(c,t,i,o)}return t}async collectDatatypePropertiesAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[n,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let c=a.type;if(typeof c!="string")continue;(c.includes(".")?c.substring(c.lastIndexOf(".")+1):c)==="DatatypeProperty"&&o.add(n)}if(e.metadata.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await i.getHighestCompatibleVersionAsync(n,c);s&&await this.collectDatatypePropertiesAsync(s,o,t,i)}}}validateEntityReferences(e,o,t,i,r,n){for(let[a,c]of Object.entries(o)){let s=a;if(s&&!s.includes(".")){let p=t.get(s);if(p&&p.length>1&&!p.some(y=>y.startsWith("(local:"))){let y=p.filter(u=>!u.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,c,t,i,r,n)}}validatePropertyValue(e,o,t,i,r,n,a){if(t==null)return;let c=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,s=!!c&&r.has(c);if(typeof t=="string"&&!t.includes(".")&&!s){let p=i.get(t);if(p&&p.length>1&&!p.some(y=>y.startsWith("(local:"))){let y=p.filter(u=>!u.startsWith("(local:"));y.length>1&&a.push(this.createAmbiguityError(e,o,`Reference '${t}'`,y,n,!1,t))}}else if(Array.isArray(t))for(let p=0;p<t.length;p++){let l=`${e}.${o}[${p}]`;this.validatePropertyValue(l,o,t[p],i,r,n,a)}else if(typeof t=="object"&&!Array.isArray(t)){let p=o?`${e}.${o}`:e;this.validateEntityReferences(p,t,i,r,n,a)}}createAmbiguityError(e,o,t,i,r,n,a){let c=[];for(let f of i){let d=this.findAliasForNamespace(r,f);if(d){let b=o?.split(".").pop()??o;c.push(`${d}.${b}`)}}let s=c.length>0?`Use one of: ${c.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,p=i.map(f=>` \u2022 ${f}`).join(`
|
|
24
|
-
`),l=e.split(".")[0],y=e.includes(".")?e:o,u=new h;u.ruleType=this.ruleName,u.severity="Error",u.entityName=l,y&&(u.propertyName=y);let m=a??o;return m&&(u.actualValue=m),u.message=`${t} is ambiguous - defined in multiple imported namespaces`,u.suggestion=`${s}
|
|
25
|
-
|
|
26
|
-
Defined in:
|
|
27
|
-
${p}`,u.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",u}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var U=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","dateTime","date","time","duration","anyURI","anySimpleType","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte","base64Binary","hexBinary","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=n.type?.toString();this.isValidRangeTargetType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(c!=="DatatypeProperty"&&c!=="ObjectProperty"&&!c?.endsWith(".DatatypeProperty")&&!c?.endsWith(".ObjectProperty"))continue;let s=a.range;if(!s)continue;let p=[];if(Array.isArray(s))for(let l of s){let y=l?.toString();y&&p.push(y)}else{let l=s?.toString();l&&p.push(l)}if(p.length===0)continue;for(let l of p){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||i.has(l))continue;if(!await this.isTypeAvailableInImports(e,o,l)){let u=c?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${r}' has range '${l}' which is not defined or imported`,m.suggestion=u==="ObjectProperty"?`For ObjectProperty:
|
|
28
|
-
1. Define '${l}' as a Class in this namespace, OR
|
|
29
|
-
2. Import the namespace that contains '${l}', OR
|
|
30
|
-
3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
|
|
31
|
-
1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
|
|
32
|
-
2. If '${l}' should be a class, change property type to ObjectProperty`,m.entityName=r,m.propertyName="range",m.actualValue=l,m.expectedValue=u==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(m)}}}return t}async isTypeAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(this.isValidRangeTargetType(m))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(s,o,p,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,o){let t=[],i=new Map,r=new A(o);await r.buildEntityIndexAsync(e);for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,s=!1,p=c.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="ObjectProperty"){s=!0;break}}else p?.toString()==="ObjectProperty"&&(s=!0);if(s){let l=c.range,y=[];if(Array.isArray(l))for(let u of l){let m=u?.toString();m&&y.push(m)}else{let u=l?.toString();u&&y.push(u)}for(let u of y)this.xsdTypes.has(u)||(i.has(u)||i.set(u,[]),i.get(u).push(n))}}for(let[n,a]of i)if(!await r.resolveEntityAsync(n,e))for(let s of a){let p=new h;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${n}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${n}' is imported, or define '${n}' in this document`,p.entityName=s,p.propertyName="range",p.actualValue=n,t.push(p)}return t}};var J=class g{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"&&g.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.rdf"&&e.name==="Literal":!1}isKnownXsdDatatypeName(e){let o=e.includes(".")?e.split(".")[1]:e;return g.KNOWN_XSD_DATATYPES.has(o.toLowerCase())}async isClassTypeAsync(e,o){if(this.isKnownXsdDatatypeName(e))return!1;let t=await this.resourceResolver.resolveEntityAsync(e,o);if(t){let i=t.entity.type;if(i){let r=String(i);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,o){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(o)||e==="Property"&&this.isLiteralType(o))}isEffectiveObjectProperty(e,o){return!!(e==="ObjectProperty"||e==="Property"&&o&&!this.isXsdDatatype(o)&&!this.isLiteralType(o))}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,o){let t=[],i=new A(o),r=new J(i),n=await i.buildEntityIndexAsync(e),a=await this.buildPropertyMetadataAsync(e,o,i,n);for(let[c,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,c,"",a,i,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,i,r,n,a,c){for(let[s,p]of Object.entries(e)){if(this.standardProperties.has(s))continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let u=i.get(l);if(u&&n.isEffectiveObjectProperty(u.propertyType,u.rangeUri)){let f=t?`${t}.${s}`:s;if(typeof p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let v=d.split(",").map(V=>V.trim()).filter(V=>V.length>0);c.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
|
|
33
|
-
${s}:
|
|
34
|
-
- ${v[0]}
|
|
35
|
-
${v.slice(1).map(V=>` - ${V}`).join(`
|
|
36
|
-
`)}`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${u.range??"an entity"} OR a YAML list`});continue}let b=await r.resolveEntityAsync(d,a);if(b)u.range&&(await this.validateRangeType(b,u.range,r,a)||c.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${u.range}, but '${d}' may not be a ${u.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:u.range}));else{let v=u.range??"entity";c.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${v}`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(p,o,d,i,r,n,a,c)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];if(typeof b=="string"&&b.trim().length>0){let v=b.trim(),V=await r.resolveEntityAsync(v,a);if(V){if(u.range&&!await this.validateRangeType(V,u.range,r,a)){let Q=t?`${t}.${s}[${d}]`:`${s}[${d}]`;c.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${u.range}, but '${v}' may not be a ${u.range}`,suggestion:`Ensure '${v}' is defined with appropriate type`,entityName:o,propertyName:`${s}[${d}]`,propertyPath:Q,actualValue:v,expectedValue:u.range})}}else{let re=u.range??"entity",Q=t?`${t}.${s}[${d}]`:`${s}[${d}]`;c.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${v}' which is not defined or imported`,suggestion:`Define '${v}' or import a namespace that contains it. Expected range: ${re}`,entityName:o,propertyName:`${s}[${d}]`,propertyPath:Q,actualValue:v,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let v=t?`${t}.${s}[${d}]`:`${s}[${d}]`;await this.scanEntityForObjectProperties(b,o,v,i,r,n,a,c)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!i.has(s)){let m=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(p,o,m,i,r,n,a,c)}else if(Array.isArray(p))for(let m=0;m<p.length;m++){let f=p[m];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=t?`${t}.${s}[${m}]`:`${s}[${m}]`;await this.scanEntityForObjectProperties(f,o,d,i,r,n,a,c)}}}}async validateRangeType(e,o,t,i){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(o))return!0;let n=e.entity.type;if(n){let a=[];if(Array.isArray(n))for(let c of n){let s=c?.toString();s&&s.trim().length>0&&a.push(s)}else{let c=n?.toString();c&&c.trim().length>0&&a.push(c)}for(let c of a){let s=c.includes(".")?c.split(".")[1]:c;if(s===o||o==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||o==="Class"&&s==="Class"||await t.isSubclassOfAsync(c,o,i))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,i){let r=new Map;for(let[n,a]of i){let c=a.entity.type;if(c){let s=[];if(Array.isArray(c))for(let y of c){let u=y?.toString();u&&u.trim().length>0&&s.push(u)}else{let y=c?.toString();y&&y.trim().length>0&&s.push(y)}let p=!1,l="Property";for(let y of s){let u=y.includes(".")?y.split(".")[1]:y;if(u==="Property"||u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty"){p=!0,l=y;break}}if(p){let y={propertyType:l},u=a.entity.range;if(u){let m=u?.toString();if(m&&m.trim().length>0){y.range=m;let f=await t.resolveEntityAsync(m,e);f&&(y.rangeUri=f.uri)}}r.set(n,y)}}}return r}};var X=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,o){let t=[],i=new Map;for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,s=this.getPropertyValue(c,"type");(s==="DatatypeProperty"||s?.endsWith(".DatatypeProperty")||s==="ObjectProperty"||s?.endsWith(".ObjectProperty")||s==="AnnotationProperty"||s?.endsWith(".AnnotationProperty"))&&i.set(n,c)}let r=await this.buildCompleteClassHierarchyAsync(e,o);for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,s=this.getPropertyValue(c,"type");if(!s||s==="Class"||s.endsWith(".Class")||s.endsWith("Property")||s==="AnnotationProperty")continue;this.validateEntityProperties(c,n,s,i,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,i=new Set,r=async(a,c)=>{if(!i.has(c)){i.add(c);for(let[s,p]of Object.entries(a.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let l=p,y=this.getPropertyValue(l,"type");if(y==="Class"||y?.endsWith(".Class")){let u=l.subClassOf;if(u===void 0){for(let f of Object.keys(l))if(f.endsWith(".subClassOf")){u=l[f];break}}let m=k(u);m.length>0&&t.set(s,m)}}if(a.metadata.imports)for(let[s,p]of Object.entries(a.metadata.imports))for(let l of p)try{let y=await o.getHighestCompatibleVersionAsync(s,l);if(y){let u=`${s}/${l.packageName}@${l.version}`;await r(y,u)}}catch{}}},n=e.metadata.namespace_?.toString()??"unknown";return await r(e,n),t}validateEntityProperties(e,o,t,i,r,n){for(let[a,c]of Object.entries(e)){if(this.standardProperties.has(a))continue;let s=a,p=a.lastIndexOf(".");p>0&&p<a.length-1&&(s=a.substring(p+1));let l=i.get(s);if(!l)continue;let y=this.getPropertyValue(l,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,r)){let u=o.split(".")[0];n.push({ruleType:this.ruleName,severity:"Error",entityName:u,propertyName:o,actualValue:a,message:`Property '${a}' has domain '${y}' but is used on '${t}' at '${o}'`,suggestion:`Either:
|
|
37
|
-
1. Use this property only on '${y}' instances
|
|
38
|
-
2. Change the property domain to include '${t}'
|
|
39
|
-
3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let u=c,m=this.getPropertyValue(u,"type");if(m){let f=`${o}.${a}`;this.validateEntityProperties(u,f,m,i,r,n)}else{let f=this.getPropertyValue(l,"range");if(f){let d=`${o}.${a}`;this.validateEntityProperties(u,d,f,i,r,n)}}}else if(Array.isArray(c))for(let u=0;u<c.length;u++){let m=c[u];if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=m,d=this.getPropertyValue(f,"type");if(d){let b=`${o}.${a}[${u}]`;this.validateEntityProperties(f,b,d,i,r,n)}else{let b=this.getPropertyValue(l,"range");if(b){let v=`${o}.${a}[${u}]`;this.validateEntityProperties(f,v,b,i,r,n)}}}}}}}isTypeCompatibleWithDomain(e,o,t){if(e===o)return!0;let i=new Set,r=[e];for(;r.length>0;){let n=r.shift();if(i.has(n))continue;i.add(n);let a=t.get(n);if(a)for(let c of a){if(c===o)return!0;r.push(c)}}return!1}getPropertyValue(e,o){if(o in e){let t=e[o];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${o}`)){let i=e[t];return this.extractFirstValue(i)}}extractFirstValue(e){if(Array.isArray(e)){let o=[];for(let t of e)o.push(t?.toString()??"");return o.length>0?o[0]:void 0}return e?.toString()}};var z=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,o){let t=[],i=new Map;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=this.getPropertyValue(a,"type");(c==="DatatypeProperty"||c==="ObjectProperty")&&i.set(r,a)}for(let[r,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let a=n,c=this.getPropertyValue(a,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[s,p]of Object.entries(a)){if(s==="type"||s==="label"||s==="comment")continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let u=i.get(l);if(!u)continue;let m=this.getPropertyValue(u,"type"),f=this.getPropertyValue(u,"range");if(m==="DatatypeProperty"){if(typeof p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' is a DatatypeProperty with range '${f}' but instance '${r}' has a complex object value`,suggestion:`Either:
|
|
40
|
-
1. Create a class for this data and change '${s}' to an ObjectProperty
|
|
41
|
-
2. Store as a JSON string to keep it as DatatypeProperty
|
|
42
|
-
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,p)){let d={ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${r}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(d.expectedValue=f),t.push(d)}}else if(m==="ObjectProperty")if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];typeof b!="string"&&(typeof b!="object"||b===null||Array.isArray(b))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:`${s}[${d}]`,message:`ObjectProperty '${s}' array item ${d} in instance '${r}' has invalid type '${this.getValueTypeName(b)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`ObjectProperty '${s}' in instance '${r}' has invalid value type '${this.getValueTypeName(p)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,o){switch(e?.toLowerCase()){case"string":return typeof o=="string";case"integer":case"int":return typeof o=="number"&&Number.isInteger(o);case"decimal":return typeof o=="number";case"boolean":return typeof o=="boolean";case"float":case"double":return typeof o=="number";default:return!0}}getValueTypeName(e){return typeof e=="string"?"string":typeof e=="number"?Number.isInteger(e)?"integer":"decimal":typeof e=="boolean"?"boolean":Array.isArray(e)?"array":typeof e=="object"&&e!==null?"object":e===null?"null":e===void 0?"undefined":typeof e}getPropertyValue(e,o){if(o in e){let t=e[o];if(Array.isArray(t)){let i=[];for(let r of t)i.push(r?.toString()??"");return i.length>0?i[0]:void 0}return t?.toString()}}};var B=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,o){let t=[],i=new Map,r=new Set;for(let[a,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c.type;if(p)if(Array.isArray(p))for(let l of p){let y=l?.toString();if(y==="Class"||y&&y.endsWith(".Class")){r.add(a);break}}else{let l=p?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&r.add(a)}}for(let[a,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let s=c,p=s.type;if(p)if(Array.isArray(p)){let l=!1;for(let y of p){let u=y?.toString();if(u&&this.isDefinitionType(u)){l=!0;break}}if(!l)for(let y of p){let u=y?.toString();u&&u.trim().length>0&&(i.has(u)||i.set(u,[]),i.get(u).push(a))}}else{let l=p?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(i.has(l)||i.set(l,[]),i.get(l).push(a)))}this.checkNestedTypes(s,a,i,a)}let n=new A(o);for(let[a,c]of i){if(this.builtInClasses.has(a)||r.has(a))continue;let s=await n.resolveEntityAsync(a,e);if(!(s&&this.isClassEntity(s.entity))){let l=Array.from(new Set(c)).sort();for(let y of l)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${a}' is not defined or imported`,suggestion:`Define '${a}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:a,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,o,t,i){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let r=e,n=r.type;if(n){let a=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(n))for(let c of n){let s=c?.toString();s&&s.trim().length>0&&!a.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(i))}else{let c=n?.toString();c&&c.trim().length>0&&!a.has(c)&&(t.has(c)||t.set(c,[]),t.get(c).push(i))}}for(let[a,c]of Object.entries(r))if(a!=="type"){let s=`${i}.${a}`;this.checkNestedTypes(c,o,t,s)}}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let n=`${i}[${r}]`;this.checkNestedTypes(e[r],o,t,n)}}isClassEntity(e){if(!e)return!1;let o=e.type;if(!o)return!1;if(Array.isArray(o))for(let t of o){let i=t?.toString();if(i==="Class"||i&&i.endsWith(".Class"))return!0}else{let t=o?.toString();if(t==="Class"||t&&t.endsWith(".Class"))return!0}return!1}isDefinitionType(e){return!e||e.trim().length===0?!1:new Set(["Class","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(e)?!0:e.endsWith(".Class")||e.endsWith(".Property")||e.endsWith(".DatatypeProperty")||e.endsWith(".ObjectProperty")||e.endsWith(".AnnotationProperty")}};var te=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new Z,this.documentRules=[new I,new D,new O,new $],this.repositoryRules=[new w,new E,new S,new j,new N,new K,new x,new C,new T,new _,new M,new L,new W,new H,new U,new F,new q,new X,new z,new B]}async validateAsync(e,o){let t=new P;for(let i of this.documentRules)try{let r=i.validate(e);this.addErrorsToResult(t,r)}catch(r){let n=new h;n.ruleType=i.ruleName,n.severity="Error",n.message=`Validation rule '${i.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,t.errors.push(n)}if(o){let i=[];for(let r of this.repositoryRules)try{let n=await r.validateAsync(e,o);this.addErrorsToResult(t,n)}catch(n){let a=n instanceof Error?n.message:String(n);i.push({ruleName:r.ruleName,cause:a})}if(i.length>0){let r=new Map;for(let{ruleName:n,cause:a}of i){let c=r.get(a);c?c.push(n):r.set(a,[n])}for(let[n,a]of r){let c=new h;c.ruleType=a[0],c.severity="Error",a.length===1?c.message=`Validation rule '${a[0]}' failed: ${n}`:c.message=`${n} (affects ${a.length} rules: ${a.join(", ")})`,t.errors.push(c)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,o){let t=this.parser.parseWithErrors(e);if(!t.isValid){let i=new P;i.isValid=!1;for(let r of t.errors){let n=new h;n.ruleType="ParseError",n.severity="Error",n.lineNumber=r.line,n.column=r.column,n.message=r.message,r.keyName&&(n.entityName=r.keyName),r.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),i.errors.push(n)}return i}return await this.validateAsync(t.document,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let o=this.documentRules.findIndex(t=>t instanceof e);o>=0&&this.documentRules.splice(o,1)}removeRepositoryRule(e){let o=this.repositoryRules.findIndex(t=>t instanceof e);o>=0&&this.repositoryRules.splice(o,1)}addErrorsToResult(e,o){for(let t of o)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{H as AmbiguousReferenceRule,B as ClassDefinitionRule,N as ClassHierarchyCycleRule,L as DefinitionPropertyReferenceRule,w as EmbeddedKanonakTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,F as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,U as PropertyRangeReferenceRule,x as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,z as PropertyValueTypeRule,D as ResourceNamingRule,C as SubClassOfReferenceRule,T as SubPropertyOfReferenceRule,$ as SubjectKanonakTypeRequiredRule,j as TypeAmbiguityRule,S as UnresolvedReferenceRule,ee as ValidationContext,R as ValidationSeverity,W as XsdImportRule};
|
|
1
|
+
import{A,B,C,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-C54LRL2A.js";import"../chunk-MYITGTGJ.js";import"../chunk-RGMZAKJV.js";import"../chunk-FUUTGGJS.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,i as EmbeddedKanonakTypeRule,j as ImportExistenceRule,s as InstancePropertyReferenceRule,C as KanonakObjectValidator,r as NamespaceImportCycleRule,e 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,g as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,f as ResourceNamingRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,h as SubjectKanonakTypeRequiredRule,l as TypeAmbiguityRule,k as UnresolvedReferenceRule,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -70,6 +70,22 @@
|
|
|
70
70
|
"types": "./dist/reasoning/index.d.ts",
|
|
71
71
|
"default": "./dist/reasoning/index.js"
|
|
72
72
|
},
|
|
73
|
+
"./uri-helpers": {
|
|
74
|
+
"browser": {
|
|
75
|
+
"types": "./dist/uri-helpers/index.d.ts",
|
|
76
|
+
"default": "./dist/uri-helpers/index.js"
|
|
77
|
+
},
|
|
78
|
+
"types": "./dist/uri-helpers/index.d.ts",
|
|
79
|
+
"default": "./dist/uri-helpers/index.js"
|
|
80
|
+
},
|
|
81
|
+
"./transformations": {
|
|
82
|
+
"browser": {
|
|
83
|
+
"types": "./dist/transformations/index.d.ts",
|
|
84
|
+
"default": "./dist/transformations/index.js"
|
|
85
|
+
},
|
|
86
|
+
"types": "./dist/transformations/index.d.ts",
|
|
87
|
+
"default": "./dist/transformations/index.js"
|
|
88
|
+
},
|
|
73
89
|
"./browser": {
|
|
74
90
|
"types": "./dist/browser.d.ts",
|
|
75
91
|
"default": "./dist/browser.js"
|
|
@@ -105,7 +121,7 @@
|
|
|
105
121
|
"yaml-parser"
|
|
106
122
|
],
|
|
107
123
|
"dependencies": {
|
|
108
|
-
"@kanonak-protocol/types": "^3.
|
|
124
|
+
"@kanonak-protocol/types": "^3.12.0",
|
|
109
125
|
"ignore": "^7.0.5",
|
|
110
126
|
"js-yaml": "^4.1.0",
|
|
111
127
|
"yaml": "^2.7.0"
|