@canon-protocol/sdk 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canons/Canon.d.ts +2 -0
- package/dist/canons/Canon.js +2 -0
- package/dist/canons/DefinedCanon.d.ts +5 -0
- package/dist/canons/DefinedCanon.js +4 -0
- package/dist/canons/EmbeddedCanon.d.ts +3 -0
- package/dist/canons/EmbeddedCanon.js +3 -0
- package/dist/canons/ReferenceCanon.d.ts +6 -0
- package/dist/canons/ReferenceCanon.js +10 -0
- package/dist/canons/SubjectCanon.d.ts +6 -0
- package/dist/canons/SubjectCanon.js +6 -0
- package/dist/canons/index.d.ts +5 -0
- package/dist/canons/index.js +5 -0
- package/dist/ctl/CtlCanonUri.d.ts +28 -0
- package/dist/ctl/CtlCanonUri.js +230 -0
- package/dist/ctl/CtlGraphResolver.d.ts +14 -0
- package/dist/ctl/CtlGraphResolver.js +411 -0
- package/dist/ctl/CtlMarkdownRenderer.d.ts +17 -0
- package/dist/ctl/CtlMarkdownRenderer.js +262 -0
- package/dist/ctl/CtlParser.d.ts +10 -0
- package/dist/ctl/CtlParser.js +331 -0
- package/dist/ctl/CtlValidator.d.ts +12 -0
- package/dist/ctl/CtlValidator.js +207 -0
- package/dist/ctl/ResourceTypeClassifier.d.ts +21 -0
- package/dist/ctl/ResourceTypeClassifier.js +126 -0
- package/dist/ctl/index.d.ts +12 -0
- package/dist/ctl/index.js +9 -0
- package/dist/filtering/GitIgnoreFilter.d.ts +7 -0
- package/dist/filtering/GitIgnoreFilter.js +32 -0
- package/dist/filtering/IGitIgnoreFilter.d.ts +3 -0
- package/dist/filtering/IGitIgnoreFilter.js +1 -0
- package/dist/filtering/index.d.ts +2 -0
- package/dist/filtering/index.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +8 -0
- package/dist/parsing/CanonObjectParser.d.ts +21 -0
- package/dist/parsing/CanonObjectParser.js +242 -0
- package/dist/parsing/CanonParser.d.ts +21 -0
- package/dist/parsing/CanonParser.js +457 -0
- package/dist/parsing/ICanonObjectParser.d.ts +7 -0
- package/dist/parsing/ICanonObjectParser.js +1 -0
- package/dist/parsing/PropertyMetadata.d.ts +7 -0
- package/dist/parsing/PropertyMetadata.js +7 -0
- package/dist/parsing/index.d.ts +6 -0
- package/dist/parsing/index.js +3 -0
- package/dist/repositories/CompositeCanonDocumentRepository.d.ts +28 -0
- package/dist/repositories/CompositeCanonDocumentRepository.js +125 -0
- package/dist/repositories/FileSystemCanonDocumentRepository.d.ts +28 -0
- package/dist/repositories/FileSystemCanonDocumentRepository.js +295 -0
- package/dist/repositories/HttpCanonDocumentRepository.d.ts +24 -0
- package/dist/repositories/HttpCanonDocumentRepository.js +79 -0
- package/dist/repositories/InMemoryCanonDocumentRepository.d.ts +23 -0
- package/dist/repositories/InMemoryCanonDocumentRepository.js +149 -0
- package/dist/repositories/PublisherConfig.d.ts +12 -0
- package/dist/repositories/PublisherConfig.js +62 -0
- package/dist/repositories/PublisherIndex.d.ts +20 -0
- package/dist/repositories/PublisherIndex.js +127 -0
- package/dist/repositories/RepositoryFactory.d.ts +6 -0
- package/dist/repositories/RepositoryFactory.js +13 -0
- package/dist/repositories/index.d.ts +9 -0
- package/dist/repositories/index.js +7 -0
- package/dist/resolution/CanonUri.d.ts +10 -0
- package/dist/resolution/CanonUri.js +55 -0
- package/dist/resolution/CanonUriBuilder.d.ts +12 -0
- package/dist/resolution/CanonUriBuilder.js +51 -0
- package/dist/resolution/ResourceResolutionResult.d.ts +9 -0
- package/dist/resolution/ResourceResolutionResult.js +1 -0
- package/dist/resolution/ResourceResolver.d.ts +27 -0
- package/dist/resolution/ResourceResolver.js +266 -0
- package/dist/resolution/TypeResolver.d.ts +15 -0
- package/dist/resolution/TypeResolver.js +110 -0
- package/dist/resolution/index.d.ts +6 -0
- package/dist/resolution/index.js +4 -0
- package/dist/statements/BooleanStatement.d.ts +3 -0
- package/dist/statements/BooleanStatement.js +3 -0
- package/dist/statements/EmbeddedStatement.d.ts +4 -0
- package/dist/statements/EmbeddedStatement.js +3 -0
- package/dist/statements/IStatement.d.ts +2 -0
- package/dist/statements/IStatement.js +1 -0
- package/dist/statements/ListStatement.d.ts +4 -0
- package/dist/statements/ListStatement.js +3 -0
- package/dist/statements/NumberStatement.d.ts +4 -0
- package/dist/statements/NumberStatement.js +10 -0
- package/dist/statements/ReferenceStatement.d.ts +5 -0
- package/dist/statements/ReferenceStatement.js +10 -0
- package/dist/statements/ScalarStatement.d.ts +3 -0
- package/dist/statements/ScalarStatement.js +3 -0
- package/dist/statements/Statement.d.ts +6 -0
- package/dist/statements/Statement.js +4 -0
- package/dist/statements/StringStatement.d.ts +4 -0
- package/dist/statements/StringStatement.js +10 -0
- package/dist/statements/index.d.ts +9 -0
- package/dist/statements/index.js +8 -0
- package/dist/validation/CanonObjectValidator.d.ts +21 -0
- package/dist/validation/CanonObjectValidator.js +150 -0
- package/dist/validation/ICanonObjectValidator.d.ts +7 -0
- package/dist/validation/ICanonObjectValidator.js +1 -0
- package/dist/validation/OntologyValidationError.d.ts +15 -0
- package/dist/validation/OntologyValidationError.js +25 -0
- package/dist/validation/OntologyValidationResult.d.ts +7 -0
- package/dist/validation/OntologyValidationResult.js +8 -0
- package/dist/validation/ValidationContext.d.ts +6 -0
- package/dist/validation/ValidationContext.js +10 -0
- package/dist/validation/ValidationSeverity.d.ts +4 -0
- package/dist/validation/ValidationSeverity.js +5 -0
- package/dist/validation/index.d.ts +10 -0
- package/dist/validation/index.js +7 -0
- package/dist/validation/rules/document/EmbeddedCanonNoExplicitTypeRule.d.ts +8 -0
- package/dist/validation/rules/document/EmbeddedCanonNoExplicitTypeRule.js +53 -0
- package/dist/validation/rules/document/IDocumentValidationRule.d.ts +6 -0
- package/dist/validation/rules/document/IDocumentValidationRule.js +1 -0
- package/dist/validation/rules/document/NamespacePrefixRule.d.ts +10 -0
- package/dist/validation/rules/document/NamespacePrefixRule.js +51 -0
- package/dist/validation/rules/document/PropertyTypeSpecificityRule.d.ts +11 -0
- package/dist/validation/rules/document/PropertyTypeSpecificityRule.js +89 -0
- package/dist/validation/rules/document/ResourceNamingRule.d.ts +12 -0
- package/dist/validation/rules/document/ResourceNamingRule.js +79 -0
- package/dist/validation/rules/document/SubjectCanonTypeRequiredRule.d.ts +7 -0
- package/dist/validation/rules/document/SubjectCanonTypeRequiredRule.js +33 -0
- package/dist/validation/rules/document/index.d.ts +6 -0
- package/dist/validation/rules/document/index.js +5 -0
- package/dist/validation/rules/normalizeToStringList.d.ts +1 -0
- package/dist/validation/rules/normalizeToStringList.js +9 -0
- package/dist/validation/rules/repository/AmbiguousReferenceRule.d.ts +14 -0
- package/dist/validation/rules/repository/AmbiguousReferenceRule.js +155 -0
- package/dist/validation/rules/repository/ClassDefinitionRule.d.ts +12 -0
- package/dist/validation/rules/repository/ClassDefinitionRule.js +205 -0
- package/dist/validation/rules/repository/ClassHierarchyCycleRule.d.ts +11 -0
- package/dist/validation/rules/repository/ClassHierarchyCycleRule.js +98 -0
- package/dist/validation/rules/repository/DefinitionPropertyReferenceRule.d.ts +13 -0
- package/dist/validation/rules/repository/DefinitionPropertyReferenceRule.js +162 -0
- package/dist/validation/rules/repository/IRepositoryValidationRule.d.ts +7 -0
- package/dist/validation/rules/repository/IRepositoryValidationRule.js +1 -0
- package/dist/validation/rules/repository/ImportExistenceRule.d.ts +12 -0
- package/dist/validation/rules/repository/ImportExistenceRule.js +124 -0
- package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +13 -0
- package/dist/validation/rules/repository/InstancePropertyReferenceRule.js +161 -0
- package/dist/validation/rules/repository/NamespaceImportCycleRule.d.ts +11 -0
- package/dist/validation/rules/repository/NamespaceImportCycleRule.js +85 -0
- package/dist/validation/rules/repository/ObjectPropertyImportRule.d.ts +9 -0
- package/dist/validation/rules/repository/ObjectPropertyImportRule.js +113 -0
- package/dist/validation/rules/repository/ObjectPropertyValueValidationRule.d.ts +12 -0
- package/dist/validation/rules/repository/ObjectPropertyValueValidationRule.js +281 -0
- package/dist/validation/rules/repository/PropertyDomainRule.d.ts +14 -0
- package/dist/validation/rules/repository/PropertyDomainRule.js +221 -0
- package/dist/validation/rules/repository/PropertyHierarchyCycleRule.d.ts +11 -0
- package/dist/validation/rules/repository/PropertyHierarchyCycleRule.js +104 -0
- package/dist/validation/rules/repository/PropertyRangeReferenceRule.d.ts +13 -0
- package/dist/validation/rules/repository/PropertyRangeReferenceRule.js +184 -0
- package/dist/validation/rules/repository/PropertyRangeRequiredRule.d.ts +8 -0
- package/dist/validation/rules/repository/PropertyRangeRequiredRule.js +40 -0
- package/dist/validation/rules/repository/PropertyValueTypeRule.d.ts +11 -0
- package/dist/validation/rules/repository/PropertyValueTypeRule.js +171 -0
- package/dist/validation/rules/repository/SubClassOfReferenceRule.d.ts +11 -0
- package/dist/validation/rules/repository/SubClassOfReferenceRule.js +133 -0
- package/dist/validation/rules/repository/SubPropertyOfReferenceRule.d.ts +11 -0
- package/dist/validation/rules/repository/SubPropertyOfReferenceRule.js +133 -0
- package/dist/validation/rules/repository/TypeAmbiguityRule.d.ts +10 -0
- package/dist/validation/rules/repository/TypeAmbiguityRule.js +104 -0
- package/dist/validation/rules/repository/UnresolvedReferenceRule.d.ts +11 -0
- package/dist/validation/rules/repository/UnresolvedReferenceRule.js +91 -0
- package/dist/validation/rules/repository/XsdImportRule.d.ts +11 -0
- package/dist/validation/rules/repository/XsdImportRule.js +125 -0
- package/dist/validation/rules/repository/index.d.ts +20 -0
- package/dist/validation/rules/repository/index.js +19 -0
- package/package.json +82 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const CORE_PACKAGES = new Set([
|
|
2
|
+
'canon-protocol.org/core-rdf',
|
|
3
|
+
'canon-protocol.org/core-rdfs',
|
|
4
|
+
'canon-protocol.org/core-owl',
|
|
5
|
+
'canon-protocol.org/core-xsd',
|
|
6
|
+
'canon-protocol.org/core-canon'
|
|
7
|
+
]);
|
|
8
|
+
const CORE_TYPE_MAP = {
|
|
9
|
+
'Class': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
10
|
+
'ObjectProperty': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
11
|
+
'DatatypeProperty': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
12
|
+
'AnnotationProperty': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
13
|
+
'Property': { publisher: 'canon-protocol.org', package_: 'core-rdf' },
|
|
14
|
+
'Datatype': { publisher: 'canon-protocol.org', package_: 'core-rdfs' },
|
|
15
|
+
'Resource': { publisher: 'canon-protocol.org', package_: 'core-rdfs' },
|
|
16
|
+
'Literal': { publisher: 'canon-protocol.org', package_: 'core-rdfs' },
|
|
17
|
+
'Thing': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
18
|
+
'Nothing': { publisher: 'canon-protocol.org', package_: 'core-owl' },
|
|
19
|
+
};
|
|
20
|
+
function getTypeUri(resource) {
|
|
21
|
+
const entityAny = resource;
|
|
22
|
+
if (entityAny.entity && typeof entityAny.entity === 'object') {
|
|
23
|
+
const typeVal = entityAny.entity['type'];
|
|
24
|
+
if (typeof typeVal === 'string') {
|
|
25
|
+
const coreMapping = CORE_TYPE_MAP[typeVal];
|
|
26
|
+
if (coreMapping) {
|
|
27
|
+
return { publisher: coreMapping.publisher, package_: coreMapping.package_, name: typeVal };
|
|
28
|
+
}
|
|
29
|
+
return { publisher: '', package_: '', name: typeVal };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (entityAny.statement && Array.isArray(entityAny.statement)) {
|
|
33
|
+
for (const stmt of entityAny.statement) {
|
|
34
|
+
if (stmt.predicate?.subject?.name === 'type' && stmt.object?.subject) {
|
|
35
|
+
const subject = stmt.object.subject;
|
|
36
|
+
if ((!subject.publisher && !subject.package_) || (subject.publisher === '' && subject.package_ === '')) {
|
|
37
|
+
const coreMapping = CORE_TYPE_MAP[subject.name];
|
|
38
|
+
if (coreMapping) {
|
|
39
|
+
return { publisher: coreMapping.publisher, package_: coreMapping.package_, name: subject.name };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return subject;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function isCorePackage(publisher, package_) {
|
|
49
|
+
return CORE_PACKAGES.has(`${publisher}/${package_}`);
|
|
50
|
+
}
|
|
51
|
+
export class ResourceTypeClassifier {
|
|
52
|
+
static getTypeUri(resource) {
|
|
53
|
+
return getTypeUri(resource);
|
|
54
|
+
}
|
|
55
|
+
static isCoreOntologyType(uri) {
|
|
56
|
+
return isCorePackage(uri.publisher, uri.package_);
|
|
57
|
+
}
|
|
58
|
+
static isClassType(resource) {
|
|
59
|
+
const typeUri = getTypeUri(resource);
|
|
60
|
+
if (!typeUri)
|
|
61
|
+
return false;
|
|
62
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'Class';
|
|
63
|
+
}
|
|
64
|
+
static isDatatypeType(resource) {
|
|
65
|
+
const typeUri = getTypeUri(resource);
|
|
66
|
+
if (!typeUri)
|
|
67
|
+
return false;
|
|
68
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'Datatype';
|
|
69
|
+
}
|
|
70
|
+
static isDatatypePropertyType(resource) {
|
|
71
|
+
const typeUri = getTypeUri(resource);
|
|
72
|
+
if (!typeUri)
|
|
73
|
+
return false;
|
|
74
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'DatatypeProperty';
|
|
75
|
+
}
|
|
76
|
+
static isObjectPropertyType(resource) {
|
|
77
|
+
const typeUri = getTypeUri(resource);
|
|
78
|
+
if (!typeUri)
|
|
79
|
+
return false;
|
|
80
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'ObjectProperty';
|
|
81
|
+
}
|
|
82
|
+
static isAnnotationPropertyType(resource) {
|
|
83
|
+
const typeUri = getTypeUri(resource);
|
|
84
|
+
if (!typeUri)
|
|
85
|
+
return false;
|
|
86
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'AnnotationProperty';
|
|
87
|
+
}
|
|
88
|
+
static isGenericPropertyType(resource) {
|
|
89
|
+
const typeUri = getTypeUri(resource);
|
|
90
|
+
if (!typeUri)
|
|
91
|
+
return false;
|
|
92
|
+
return isCorePackage(typeUri.publisher, typeUri.package_) && typeUri.name === 'Property';
|
|
93
|
+
}
|
|
94
|
+
static isAnyPropertyType(resource) {
|
|
95
|
+
const typeUri = getTypeUri(resource);
|
|
96
|
+
if (!typeUri)
|
|
97
|
+
return false;
|
|
98
|
+
if (!isCorePackage(typeUri.publisher, typeUri.package_))
|
|
99
|
+
return false;
|
|
100
|
+
return typeUri.name === 'Property' ||
|
|
101
|
+
typeUri.name === 'DatatypeProperty' ||
|
|
102
|
+
typeUri.name === 'ObjectProperty' ||
|
|
103
|
+
typeUri.name === 'AnnotationProperty';
|
|
104
|
+
}
|
|
105
|
+
static isSchemaDefinitionType(resource) {
|
|
106
|
+
const typeUri = getTypeUri(resource);
|
|
107
|
+
if (!typeUri)
|
|
108
|
+
return false;
|
|
109
|
+
if (!isCorePackage(typeUri.publisher, typeUri.package_))
|
|
110
|
+
return false;
|
|
111
|
+
return typeUri.name === 'Class' ||
|
|
112
|
+
typeUri.name === 'Property' ||
|
|
113
|
+
typeUri.name === 'DatatypeProperty' ||
|
|
114
|
+
typeUri.name === 'ObjectProperty' ||
|
|
115
|
+
typeUri.name === 'AnnotationProperty' ||
|
|
116
|
+
typeUri.name === 'Datatype';
|
|
117
|
+
}
|
|
118
|
+
static isInstanceOfKnownClass(resource, knownClassNames) {
|
|
119
|
+
if (ResourceTypeClassifier.isSchemaDefinitionType(resource))
|
|
120
|
+
return false;
|
|
121
|
+
const typeUri = getTypeUri(resource);
|
|
122
|
+
if (!typeUri)
|
|
123
|
+
return false;
|
|
124
|
+
return knownClassNames.has(typeUri.name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { CtlCanonUri } from './CtlCanonUri.js';
|
|
2
|
+
export { CtlParser } from './CtlParser.js';
|
|
3
|
+
export { ResourceTypeClassifier } from './ResourceTypeClassifier.js';
|
|
4
|
+
export { CtlValidator } from './CtlValidator.js';
|
|
5
|
+
export { CtlGraphResolver } from './CtlGraphResolver.js';
|
|
6
|
+
export { CtlMarkdownRenderer } from './CtlMarkdownRenderer.js';
|
|
7
|
+
export type { CtlDocument, CanonReference, CtlValidationResult, CtlValidationError } from '@canon-protocol/types/ctl/models/types';
|
|
8
|
+
export type { CtlCanonUri as ICtlCanonUri, PathSegment, ResolvedImport } from '@canon-protocol/types/ctl/parsing/types';
|
|
9
|
+
export type { ResolvedResourceGraph, ResolvedResource, ResolvedProperty, UnresolvedResource } from '@canon-protocol/types/ctl/resolution/types';
|
|
10
|
+
export { CtlValidationErrorType, CtlValidationSeverity } from '@canon-protocol/types/ctl/models/enums';
|
|
11
|
+
export { CtlCanonUriType, PathSegmentType } from '@canon-protocol/types/ctl/parsing/enums';
|
|
12
|
+
export { ResolvedResourceType } from '@canon-protocol/types/ctl/resolution/enums';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CtlCanonUri } from './CtlCanonUri.js';
|
|
2
|
+
export { CtlParser } from './CtlParser.js';
|
|
3
|
+
export { ResourceTypeClassifier } from './ResourceTypeClassifier.js';
|
|
4
|
+
export { CtlValidator } from './CtlValidator.js';
|
|
5
|
+
export { CtlGraphResolver } from './CtlGraphResolver.js';
|
|
6
|
+
export { CtlMarkdownRenderer } from './CtlMarkdownRenderer.js';
|
|
7
|
+
export { CtlValidationErrorType, CtlValidationSeverity } from '@canon-protocol/types/ctl/models/enums';
|
|
8
|
+
export { CtlCanonUriType, PathSegmentType } from '@canon-protocol/types/ctl/parsing/enums';
|
|
9
|
+
export { ResolvedResourceType } from '@canon-protocol/types/ctl/resolution/enums';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IGitIgnoreFilter } from './IGitIgnoreFilter.js';
|
|
2
|
+
export declare class GitIgnoreFilter implements IGitIgnoreFilter {
|
|
3
|
+
private readonly ignoreInstance;
|
|
4
|
+
private readonly basePath;
|
|
5
|
+
constructor(basePath: string);
|
|
6
|
+
shouldIgnore(absolutePath: string): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ignore from 'ignore';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
export class GitIgnoreFilter {
|
|
5
|
+
ignoreInstance;
|
|
6
|
+
basePath;
|
|
7
|
+
constructor(basePath) {
|
|
8
|
+
this.basePath = basePath;
|
|
9
|
+
const gitignorePath = path.join(basePath, '.gitignore');
|
|
10
|
+
if (fs.existsSync(gitignorePath)) {
|
|
11
|
+
try {
|
|
12
|
+
const gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
|
|
13
|
+
this.ignoreInstance = ignore();
|
|
14
|
+
this.ignoreInstance.add(gitignoreContent);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
this.ignoreInstance = null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.ignoreInstance = null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
shouldIgnore(absolutePath) {
|
|
25
|
+
if (!this.ignoreInstance) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const relativePath = path.relative(this.basePath, absolutePath);
|
|
29
|
+
const normalizedPath = relativePath.split(path.sep).join('/');
|
|
30
|
+
return this.ignoreInstance.ignores(normalizedPath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GitIgnoreFilter } from './GitIgnoreFilter.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { InMemoryCanonDocumentRepository, FileSystemCanonDocumentRepository, CompositeCanonDocumentRepository, RepositoryFactory, DocumentLocation, HttpCanonDocumentRepository, PublisherIndex, PublisherConfigResolver } from './repositories/index.js';
|
|
2
|
+
export type { PublisherConfig } from './repositories/index.js';
|
|
3
|
+
export { GitIgnoreFilter } from './filtering/index.js';
|
|
4
|
+
export type { IGitIgnoreFilter } from './filtering/index.js';
|
|
5
|
+
export { CanonParser, CanonObjectParser, PropertyMetadata } from './parsing/index.js';
|
|
6
|
+
export type { ICanonObjectParser } from './parsing/index.js';
|
|
7
|
+
export { ResourceResolver, CanonUri, CanonUriBuilder, TypeResolver } from './resolution/index.js';
|
|
8
|
+
export type { ResourceResolutionResult, ILogger } from './resolution/index.js';
|
|
9
|
+
export { Canon, DefinedCanon, SubjectCanon, EmbeddedCanon, ReferenceCanon } from './canons/index.js';
|
|
10
|
+
export type { IStatement } from './statements/index.js';
|
|
11
|
+
export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement } from './statements/index.js';
|
|
12
|
+
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, CanonObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectCanonTypeRequiredRule, EmbeddedCanonNoExplicitTypeRule, ImportExistenceRule, UnresolvedReferenceRule, TypeAmbiguityRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule } from './validation/index.js';
|
|
13
|
+
export type { ICanonObjectValidator, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
|
|
14
|
+
export type { ICanonDocumentRepository } from '@canon-protocol/types/document/models';
|
|
15
|
+
export type { ICanonParser } from '@canon-protocol/types/document/parsing';
|
|
16
|
+
export type { CanonDocument, CanonMetadata, Namespace, Import, Version, DocumentReference, ParseResult, ParseError } from '@canon-protocol/types/document/models/types';
|
|
17
|
+
export type { VersionOperator } from '@canon-protocol/types/document/models/enums';
|
|
18
|
+
export { CtlCanonUri, CtlParser, ResourceTypeClassifier, CtlValidator, CtlGraphResolver, CtlMarkdownRenderer, CtlValidationErrorType, CtlValidationSeverity, CtlCanonUriType, PathSegmentType, ResolvedResourceType } from './ctl/index.js';
|
|
19
|
+
export type { CtlDocument, CanonReference, CtlValidationResult, CtlValidationError, ResolvedResourceGraph, ResolvedResource, ResolvedProperty, UnresolvedResource } from './ctl/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { InMemoryCanonDocumentRepository, FileSystemCanonDocumentRepository, CompositeCanonDocumentRepository, RepositoryFactory, DocumentLocation, HttpCanonDocumentRepository, PublisherIndex, PublisherConfigResolver } from './repositories/index.js';
|
|
2
|
+
export { GitIgnoreFilter } from './filtering/index.js';
|
|
3
|
+
export { CanonParser, CanonObjectParser, PropertyMetadata } from './parsing/index.js';
|
|
4
|
+
export { ResourceResolver, CanonUri, CanonUriBuilder, TypeResolver } from './resolution/index.js';
|
|
5
|
+
export { Canon, DefinedCanon, SubjectCanon, EmbeddedCanon, ReferenceCanon } from './canons/index.js';
|
|
6
|
+
export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement } from './statements/index.js';
|
|
7
|
+
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, CanonObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectCanonTypeRequiredRule, EmbeddedCanonNoExplicitTypeRule, ImportExistenceRule, UnresolvedReferenceRule, TypeAmbiguityRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule } from './validation/index.js';
|
|
8
|
+
export { CtlCanonUri, CtlParser, ResourceTypeClassifier, CtlValidator, CtlGraphResolver, CtlMarkdownRenderer, CtlValidationErrorType, CtlValidationSeverity, CtlCanonUriType, PathSegmentType, ResolvedResourceType } from './ctl/index.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ICanonObjectParser } from './ICanonObjectParser.js';
|
|
2
|
+
import type { ICanonDocumentRepository } from '@canon-protocol/types/document/models';
|
|
3
|
+
import { Canon } from '../canons/Canon.js';
|
|
4
|
+
import type { ICanonParser } from '@canon-protocol/types/document/parsing';
|
|
5
|
+
export declare class CanonObjectParser implements ICanonObjectParser {
|
|
6
|
+
constructor(_canonParser?: ICanonParser);
|
|
7
|
+
parseCanons(documentRepository: ICanonDocumentRepository): Promise<Canon[]>;
|
|
8
|
+
private parseStatements;
|
|
9
|
+
private getPropertyMetadata;
|
|
10
|
+
private parsePropertyValue;
|
|
11
|
+
private parseDatatypeValue;
|
|
12
|
+
private parseObjectValue;
|
|
13
|
+
private parseListValue;
|
|
14
|
+
saveCanons(canons: Canon[], documentRepository: ICanonDocumentRepository): Promise<void>;
|
|
15
|
+
serializeToYaml(canons: Canon[], namespaceString: string): Promise<string>;
|
|
16
|
+
private convertCanonsToDocument;
|
|
17
|
+
private convertStatementToProperty;
|
|
18
|
+
private convertCanonListToValue;
|
|
19
|
+
private convertEmbeddedCanonToValue;
|
|
20
|
+
private collectImportsFromStatement;
|
|
21
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { SubjectCanon } from '../canons/SubjectCanon.js';
|
|
2
|
+
import { EmbeddedCanon } from '../canons/EmbeddedCanon.js';
|
|
3
|
+
import { ReferenceCanon } from '../canons/ReferenceCanon.js';
|
|
4
|
+
import { StringStatement } from '../statements/StringStatement.js';
|
|
5
|
+
import { NumberStatement } from '../statements/NumberStatement.js';
|
|
6
|
+
import { BooleanStatement } from '../statements/BooleanStatement.js';
|
|
7
|
+
import { ReferenceStatement } from '../statements/ReferenceStatement.js';
|
|
8
|
+
import { EmbeddedStatement } from '../statements/EmbeddedStatement.js';
|
|
9
|
+
import { ListStatement } from '../statements/ListStatement.js';
|
|
10
|
+
import { ResourceResolver } from '../resolution/ResourceResolver.js';
|
|
11
|
+
import { TypeResolver } from '../resolution/TypeResolver.js';
|
|
12
|
+
import { CanonParser } from './CanonParser.js';
|
|
13
|
+
export class CanonObjectParser {
|
|
14
|
+
constructor(_canonParser) {
|
|
15
|
+
}
|
|
16
|
+
async parseCanons(documentRepository) {
|
|
17
|
+
const canons = [];
|
|
18
|
+
const documents = await documentRepository.getAllDocumentsAsync();
|
|
19
|
+
const resourceResolver = new ResourceResolver(documentRepository);
|
|
20
|
+
const typeResolver = new TypeResolver(resourceResolver);
|
|
21
|
+
for (const document of documents) {
|
|
22
|
+
for (const [entityName, entityValue] of Object.entries(document.body)) {
|
|
23
|
+
const subject = new SubjectCanon();
|
|
24
|
+
subject.namespace = document.metadata.namespace_?.toString() ?? '';
|
|
25
|
+
subject.name = entityName;
|
|
26
|
+
subject.statement = [];
|
|
27
|
+
const statements = await this.parseStatements(entityValue, document, resourceResolver, typeResolver, documentRepository);
|
|
28
|
+
subject.statement.push(...statements);
|
|
29
|
+
canons.push(subject);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return canons;
|
|
33
|
+
}
|
|
34
|
+
async parseStatements(entityValue, document, resourceResolver, typeResolver, repository) {
|
|
35
|
+
const statements = [];
|
|
36
|
+
if (typeof entityValue !== 'object' || entityValue === null || Array.isArray(entityValue)) {
|
|
37
|
+
return statements;
|
|
38
|
+
}
|
|
39
|
+
for (const [propertyName, propertyValue] of Object.entries(entityValue)) {
|
|
40
|
+
try {
|
|
41
|
+
const metadata = await this.getPropertyMetadata(propertyName, document, resourceResolver, repository);
|
|
42
|
+
if (!metadata) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const statement = await this.parsePropertyValue(propertyName, propertyValue, metadata, document, resourceResolver, typeResolver);
|
|
46
|
+
if (statement) {
|
|
47
|
+
statements.push(statement);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(`Error parsing property ${propertyName}:`, error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return statements;
|
|
55
|
+
}
|
|
56
|
+
async getPropertyMetadata(propertyName, document, resourceResolver, _repository) {
|
|
57
|
+
const propertyResolution = await resourceResolver.resolveEntityAsync(propertyName, document);
|
|
58
|
+
if (!propertyResolution) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const propertyDef = propertyResolution.entity;
|
|
62
|
+
const type = propertyDef.type?.toString() ?? '';
|
|
63
|
+
const propertyType = type === 'ObjectProperty' ? 'ObjectProperty' : 'DatatypeProperty';
|
|
64
|
+
const range = propertyDef.range?.toString();
|
|
65
|
+
const metadata = {
|
|
66
|
+
propertyUri: propertyResolution.uri.toString(),
|
|
67
|
+
propertyType,
|
|
68
|
+
range,
|
|
69
|
+
isImported: propertyResolution.isImported,
|
|
70
|
+
definedInNamespace: propertyResolution.definedInNamespace
|
|
71
|
+
};
|
|
72
|
+
return metadata;
|
|
73
|
+
}
|
|
74
|
+
async parsePropertyValue(_propertyName, value, metadata, document, resourceResolver, typeResolver) {
|
|
75
|
+
const predicateUri = metadata.propertyUri;
|
|
76
|
+
if (value === null || value === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
return this.parseListValue(predicateUri, value, metadata, document, resourceResolver, typeResolver);
|
|
81
|
+
}
|
|
82
|
+
if (metadata.propertyType === 'DatatypeProperty') {
|
|
83
|
+
return this.parseDatatypeValue(predicateUri, value, metadata);
|
|
84
|
+
}
|
|
85
|
+
if (metadata.propertyType === 'ObjectProperty') {
|
|
86
|
+
return this.parseObjectValue(predicateUri, value, metadata, document, resourceResolver, typeResolver);
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
parseDatatypeValue(predicateUri, value, _metadata) {
|
|
91
|
+
if (typeof value === 'string') {
|
|
92
|
+
return StringStatement.parse(predicateUri, value);
|
|
93
|
+
}
|
|
94
|
+
else if (typeof value === 'number') {
|
|
95
|
+
return NumberStatement.parse(predicateUri, value);
|
|
96
|
+
}
|
|
97
|
+
else if (typeof value === 'boolean') {
|
|
98
|
+
const stmt = new BooleanStatement();
|
|
99
|
+
stmt.predicate = ReferenceCanon.parse(predicateUri);
|
|
100
|
+
stmt.object = value;
|
|
101
|
+
return stmt;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
async parseObjectValue(predicateUri, value, _metadata, document, resourceResolver, typeResolver) {
|
|
106
|
+
if (typeof value === 'string') {
|
|
107
|
+
return ReferenceStatement.parse(predicateUri, value);
|
|
108
|
+
}
|
|
109
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
110
|
+
const embedded = new EmbeddedCanon();
|
|
111
|
+
embedded.statement = await this.parseStatements(value, document, resourceResolver, typeResolver, {} // TODO: Pass actual repository
|
|
112
|
+
);
|
|
113
|
+
const stmt = new EmbeddedStatement();
|
|
114
|
+
stmt.predicate = ReferenceCanon.parse(predicateUri);
|
|
115
|
+
stmt.object = embedded;
|
|
116
|
+
return stmt;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
async parseListValue(predicateUri, values, _metadata, document, resourceResolver, typeResolver) {
|
|
121
|
+
const canons = [];
|
|
122
|
+
for (const item of values) {
|
|
123
|
+
if (typeof item === 'string') {
|
|
124
|
+
canons.push(ReferenceCanon.parse(item));
|
|
125
|
+
}
|
|
126
|
+
else if (typeof item === 'object' && !Array.isArray(item)) {
|
|
127
|
+
const embedded = new EmbeddedCanon();
|
|
128
|
+
embedded.statement = await this.parseStatements(item, document, resourceResolver, typeResolver, {} // TODO: Pass actual repository
|
|
129
|
+
);
|
|
130
|
+
canons.push(embedded);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const stmt = new ListStatement();
|
|
134
|
+
stmt.predicate = ReferenceCanon.parse(predicateUri);
|
|
135
|
+
stmt.object = canons;
|
|
136
|
+
return stmt;
|
|
137
|
+
}
|
|
138
|
+
async saveCanons(canons, documentRepository) {
|
|
139
|
+
const canonsByNamespace = new Map();
|
|
140
|
+
for (const canon of canons) {
|
|
141
|
+
if (canon instanceof SubjectCanon && canon.namespace) {
|
|
142
|
+
if (!canonsByNamespace.has(canon.namespace)) {
|
|
143
|
+
canonsByNamespace.set(canon.namespace, []);
|
|
144
|
+
}
|
|
145
|
+
canonsByNamespace.get(canon.namespace).push(canon);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const [namespace, groupCanons] of canonsByNamespace) {
|
|
149
|
+
const document = await this.convertCanonsToDocument(namespace, groupCanons);
|
|
150
|
+
const identifier = `${namespace.split('@')[0]}.yml`;
|
|
151
|
+
await documentRepository.saveDocumentAsync(document, identifier);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async serializeToYaml(canons, namespaceString) {
|
|
155
|
+
const filteredCanons = canons
|
|
156
|
+
.filter((c) => c instanceof SubjectCanon && c.namespace === namespaceString);
|
|
157
|
+
if (filteredCanons.length === 0) {
|
|
158
|
+
throw new Error(`No canons found with namespace '${namespaceString}'`);
|
|
159
|
+
}
|
|
160
|
+
const document = await this.convertCanonsToDocument(namespaceString, filteredCanons);
|
|
161
|
+
const parser = new CanonParser();
|
|
162
|
+
return parser.save(document);
|
|
163
|
+
}
|
|
164
|
+
async convertCanonsToDocument(namespaceString, canons) {
|
|
165
|
+
const metadata = {
|
|
166
|
+
namespace_: namespaceString, // Will be parsed properly
|
|
167
|
+
get allImports() {
|
|
168
|
+
if (!this.imports)
|
|
169
|
+
return [];
|
|
170
|
+
const result = [];
|
|
171
|
+
for (const importList of Object.values(this.imports)) {
|
|
172
|
+
result.push(...importList);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const document = {
|
|
178
|
+
metadata,
|
|
179
|
+
body: {}
|
|
180
|
+
};
|
|
181
|
+
const imports = new Map();
|
|
182
|
+
for (const canon of canons) {
|
|
183
|
+
const bodyEntry = {};
|
|
184
|
+
for (const statement of canon.statement) {
|
|
185
|
+
const [propertyName, propertyValue] = this.convertStatementToProperty(statement);
|
|
186
|
+
if (propertyName && propertyValue !== null && propertyValue !== undefined) {
|
|
187
|
+
bodyEntry[propertyName] = propertyValue;
|
|
188
|
+
}
|
|
189
|
+
this.collectImportsFromStatement(statement, namespaceString, imports);
|
|
190
|
+
}
|
|
191
|
+
document.body[canon.name] = bodyEntry;
|
|
192
|
+
}
|
|
193
|
+
return document;
|
|
194
|
+
}
|
|
195
|
+
convertStatementToProperty(statement) {
|
|
196
|
+
if (statement instanceof StringStatement) {
|
|
197
|
+
return [statement.predicate.subject.name, statement.object];
|
|
198
|
+
}
|
|
199
|
+
else if (statement instanceof NumberStatement) {
|
|
200
|
+
return [statement.predicate.subject.name, statement.object];
|
|
201
|
+
}
|
|
202
|
+
else if (statement instanceof BooleanStatement) {
|
|
203
|
+
return [statement.predicate.subject.name, statement.object];
|
|
204
|
+
}
|
|
205
|
+
else if (statement instanceof ReferenceStatement) {
|
|
206
|
+
return [statement.predicate.subject.name, statement.object.subject.name];
|
|
207
|
+
}
|
|
208
|
+
else if (statement instanceof ListStatement) {
|
|
209
|
+
const listValue = this.convertCanonListToValue(statement.object);
|
|
210
|
+
return [statement.predicate.subject.name, listValue];
|
|
211
|
+
}
|
|
212
|
+
else if (statement instanceof EmbeddedStatement) {
|
|
213
|
+
const embeddedValue = this.convertEmbeddedCanonToValue(statement.object);
|
|
214
|
+
return [statement.predicate.subject.name, embeddedValue];
|
|
215
|
+
}
|
|
216
|
+
return [null, null];
|
|
217
|
+
}
|
|
218
|
+
convertCanonListToValue(canonList) {
|
|
219
|
+
const result = [];
|
|
220
|
+
for (const canon of canonList) {
|
|
221
|
+
if (canon instanceof ReferenceCanon) {
|
|
222
|
+
result.push(canon.subject.name);
|
|
223
|
+
}
|
|
224
|
+
else if (canon instanceof EmbeddedCanon) {
|
|
225
|
+
result.push(this.convertEmbeddedCanonToValue(canon));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
convertEmbeddedCanonToValue(embeddedCanon) {
|
|
231
|
+
const result = {};
|
|
232
|
+
for (const statement of embeddedCanon.statement) {
|
|
233
|
+
const [propertyName, propertyValue] = this.convertStatementToProperty(statement);
|
|
234
|
+
if (propertyName && propertyValue !== null && propertyValue !== undefined) {
|
|
235
|
+
result[propertyName] = propertyValue;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
collectImportsFromStatement(_statement, _currentNamespace, _imports) {
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CanonDocument, ParseResult } from '@canon-protocol/types/document/models/types';
|
|
2
|
+
import type { ICanonParser } from '@canon-protocol/types/document/parsing';
|
|
3
|
+
export declare class CanonParser implements ICanonParser {
|
|
4
|
+
parse(yamlText: string): CanonDocument;
|
|
5
|
+
parseWithErrors(yamlText: string): ParseResult;
|
|
6
|
+
save(document: CanonDocument): string;
|
|
7
|
+
private createEmptyMetadata;
|
|
8
|
+
private addAllImportsGetter;
|
|
9
|
+
private createVersion;
|
|
10
|
+
private extractMetadata;
|
|
11
|
+
private extractBody;
|
|
12
|
+
private parseNamespace;
|
|
13
|
+
private parseVersion;
|
|
14
|
+
private parseImportsV3;
|
|
15
|
+
private parseImportsLegacy;
|
|
16
|
+
private parseImportFromEmbeddedObject;
|
|
17
|
+
private parseImport;
|
|
18
|
+
private parseVersionOperator;
|
|
19
|
+
private calculateMaxVersion;
|
|
20
|
+
private serializeImports;
|
|
21
|
+
}
|