@shaclmate/compiler 2.0.13 → 2.0.14
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/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +91 -19
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
|
@@ -1,53 +1,72 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
|
-
import {
|
|
3
|
+
import { type ClassDeclarationStructure, type InterfaceDeclarationStructure, type ModuleDeclarationStructure } from "ts-morph";
|
|
4
|
+
import type { MintingStrategy, TsObjectDeclarationType } from "../../enums/index.js";
|
|
5
|
+
import { DeclaredType } from "./DeclaredType.js";
|
|
4
6
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
7
|
+
import { Import } from "./Import.js";
|
|
8
|
+
import type { Type } from "./Type.js";
|
|
9
|
+
import * as _ObjectType from "./_ObjectType/index.js";
|
|
10
|
+
export declare class ObjectType extends DeclaredType {
|
|
8
11
|
readonly abstract: boolean;
|
|
9
|
-
|
|
10
|
-
equalsFunctionDeclaration: typeof _ObjectType.equalsFunctionDeclaration;
|
|
11
|
-
readonly export_: boolean;
|
|
12
|
-
fromRdfFunctionDeclaration: typeof _ObjectType.fromRdfFunctionDeclaration;
|
|
13
|
-
hashFunctionDeclaration: typeof _ObjectType.hashFunctionDeclaration;
|
|
14
|
-
readonly identifierType: IdentifierType;
|
|
15
|
-
interfaceDeclaration: typeof _ObjectType.interfaceDeclaration;
|
|
12
|
+
readonly declarationType: TsObjectDeclarationType;
|
|
16
13
|
readonly kind = "ObjectType";
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
protected readonly comment: Maybe<string>;
|
|
15
|
+
protected readonly extern: boolean;
|
|
16
|
+
protected readonly fromRdfType: Maybe<NamedNode>;
|
|
17
|
+
protected readonly label: Maybe<string>;
|
|
18
|
+
protected readonly mintingStrategy: Maybe<MintingStrategy>;
|
|
19
|
+
protected readonly toRdfTypes: readonly NamedNode[];
|
|
20
|
+
private readonly imports;
|
|
22
21
|
private readonly lazyAncestorObjectTypes;
|
|
23
22
|
private readonly lazyDescendantObjectTypes;
|
|
24
23
|
private readonly lazyParentObjectTypes;
|
|
25
24
|
private readonly lazyProperties;
|
|
26
|
-
constructor({ abstract,
|
|
25
|
+
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, mintingStrategy, toRdfTypes, ...superParameters }: {
|
|
27
26
|
abstract: boolean;
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
comment: Maybe<string>;
|
|
28
|
+
declarationType: TsObjectDeclarationType;
|
|
29
|
+
extern: boolean;
|
|
30
|
+
fromRdfType: Maybe<NamedNode>;
|
|
31
|
+
imports: readonly string[];
|
|
32
|
+
label: Maybe<string>;
|
|
30
33
|
lazyAncestorObjectTypes: () => readonly ObjectType[];
|
|
31
34
|
lazyDescendantObjectTypes: () => readonly ObjectType[];
|
|
32
35
|
lazyParentObjectTypes: () => readonly ObjectType[];
|
|
33
36
|
lazyProperties: () => readonly ObjectType.Property[];
|
|
34
37
|
mintingStrategy: Maybe<MintingStrategy>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
toRdfTypes: readonly NamedNode[];
|
|
39
|
+
} & ConstructorParameters<typeof DeclaredType>[0]);
|
|
40
|
+
get _discriminatorProperty(): Type.DiscriminatorProperty;
|
|
38
41
|
get ancestorObjectTypes(): readonly ObjectType[];
|
|
39
42
|
get conversions(): readonly Type.Conversion[];
|
|
43
|
+
get declarationImports(): readonly Import[];
|
|
44
|
+
get declarations(): (ClassDeclarationStructure | InterfaceDeclarationStructure | ModuleDeclarationStructure)[];
|
|
40
45
|
get descendantObjectTypes(): readonly ObjectType[];
|
|
41
46
|
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
42
47
|
get discriminatorValue(): string;
|
|
48
|
+
get equalsFunction(): string;
|
|
43
49
|
get hashFunctionName(): string;
|
|
44
|
-
get
|
|
50
|
+
get identifierProperty(): ObjectType.IdentifierProperty;
|
|
51
|
+
get identifierType(): IdentifierType;
|
|
52
|
+
get jsonName(): string;
|
|
53
|
+
get jsonUiSchemaFunctionName(): string;
|
|
54
|
+
get jsonZodSchemaFunctionName(): string;
|
|
55
|
+
get mutable(): boolean;
|
|
56
|
+
get ownProperties(): readonly ObjectType.Property[];
|
|
45
57
|
get parentObjectTypes(): readonly ObjectType[];
|
|
46
58
|
get properties(): readonly ObjectType.Property[];
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
get useImports(): readonly Import[];
|
|
60
|
+
protected get thisVariable(): string;
|
|
61
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
49
62
|
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
50
63
|
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
64
|
+
jsonUiSchemaElement({ variables, }: {
|
|
65
|
+
variables: {
|
|
66
|
+
scopePrefix: string;
|
|
67
|
+
};
|
|
68
|
+
}): Maybe<string>;
|
|
69
|
+
jsonZodSchema(_parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
51
70
|
rdfjsResourceType(options?: {
|
|
52
71
|
mutable?: boolean;
|
|
53
72
|
}): {
|
|
@@ -55,6 +74,9 @@ export declare class ObjectType extends Type {
|
|
|
55
74
|
readonly name: string;
|
|
56
75
|
readonly named: boolean;
|
|
57
76
|
};
|
|
77
|
+
sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
78
|
+
sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
79
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
58
80
|
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
59
81
|
protected ensureAtMostOneSuperObjectType(): void;
|
|
60
82
|
}
|
|
@@ -4,33 +4,42 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import { camelCase } from "change-case";
|
|
7
8
|
import { Maybe } from "purify-ts";
|
|
9
|
+
import { invariant } from "ts-invariant";
|
|
10
|
+
import { StructureKind, } from "ts-morph";
|
|
8
11
|
import { Memoize } from "typescript-memoize";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import * as _ObjectType from "./_ObjectType";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import { DeclaredType } from "./DeclaredType.js";
|
|
13
|
+
import { Import } from "./Import.js";
|
|
14
|
+
import * as _ObjectType from "./_ObjectType/index.js";
|
|
15
|
+
import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
|
|
16
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
17
|
+
export class ObjectType extends DeclaredType {
|
|
18
|
+
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, mintingStrategy, toRdfTypes, ...superParameters }) {
|
|
14
19
|
super(superParameters);
|
|
15
|
-
this.classDeclaration = _ObjectType.classDeclaration;
|
|
16
|
-
this.equalsFunctionDeclaration = _ObjectType.equalsFunctionDeclaration;
|
|
17
|
-
this.fromRdfFunctionDeclaration = _ObjectType.fromRdfFunctionDeclaration;
|
|
18
|
-
this.hashFunctionDeclaration = _ObjectType.hashFunctionDeclaration;
|
|
19
|
-
this.interfaceDeclaration = _ObjectType.interfaceDeclaration;
|
|
20
20
|
this.kind = "ObjectType";
|
|
21
|
-
this.sparqlGraphPatternsClassDeclaration = _ObjectType.sparqlGraphPatternsClassDeclaration;
|
|
22
|
-
this.toRdfFunctionDeclaration = _ObjectType.toRdfFunctionDeclaration;
|
|
23
21
|
this.abstract = abstract;
|
|
24
|
-
this.
|
|
22
|
+
this.comment = comment;
|
|
23
|
+
this.declarationType = declarationType;
|
|
24
|
+
this.extern = extern;
|
|
25
|
+
this.fromRdfType = fromRdfType;
|
|
26
|
+
this.imports = imports;
|
|
27
|
+
this.label = label;
|
|
25
28
|
// Lazily initialize some members in getters to avoid recursive construction
|
|
26
29
|
this.lazyAncestorObjectTypes = lazyAncestorObjectTypes;
|
|
27
30
|
this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
|
|
28
31
|
this.lazyParentObjectTypes = lazyParentObjectTypes;
|
|
29
32
|
this.lazyProperties = lazyProperties;
|
|
30
|
-
this.identifierType = identifierType;
|
|
31
33
|
this.mintingStrategy = mintingStrategy;
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
+
this.toRdfTypes = toRdfTypes;
|
|
35
|
+
}
|
|
36
|
+
get _discriminatorProperty() {
|
|
37
|
+
const discriminatorProperty = this.properties.find((property) => property instanceof ObjectType.TypeDiscriminatorProperty);
|
|
38
|
+
invariant(discriminatorProperty);
|
|
39
|
+
return {
|
|
40
|
+
name: discriminatorProperty.name,
|
|
41
|
+
values: [this.discriminatorValue],
|
|
42
|
+
};
|
|
34
43
|
}
|
|
35
44
|
get ancestorObjectTypes() {
|
|
36
45
|
return this.lazyAncestorObjectTypes();
|
|
@@ -44,39 +53,131 @@ export class ObjectType extends Type {
|
|
|
44
53
|
},
|
|
45
54
|
];
|
|
46
55
|
}
|
|
56
|
+
get declarationImports() {
|
|
57
|
+
if (this.extern) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const imports = this.properties.flatMap((property) => property.declarationImports);
|
|
61
|
+
if (this.features.has("equals")) {
|
|
62
|
+
imports.push(Import.PURIFY_HELPERS);
|
|
63
|
+
}
|
|
64
|
+
if (this.features.has("fromJson") || this.features.has("jsonSchema")) {
|
|
65
|
+
imports.push(Import.ZOD);
|
|
66
|
+
}
|
|
67
|
+
if (this.features.has("jsonSchema")) {
|
|
68
|
+
imports.push(Import.ZOD_TO_JSON_SCHEMA);
|
|
69
|
+
}
|
|
70
|
+
if (this.features.has("fromRdf") || this.features.has("toRdf")) {
|
|
71
|
+
imports.push(Import.PURIFY);
|
|
72
|
+
imports.push(Import.PURIFY_HELPERS);
|
|
73
|
+
imports.push(Import.RDFJS_RESOURCE);
|
|
74
|
+
}
|
|
75
|
+
if (this.features.has("sparql")) {
|
|
76
|
+
imports.push(Import.SPARQLJS);
|
|
77
|
+
}
|
|
78
|
+
return imports;
|
|
79
|
+
}
|
|
80
|
+
get declarations() {
|
|
81
|
+
const declarations = [
|
|
82
|
+
..._ObjectType.classDeclaration.bind(this)().toList(),
|
|
83
|
+
..._ObjectType.interfaceDeclaration.bind(this)().toList(),
|
|
84
|
+
];
|
|
85
|
+
const moduleStatements = [
|
|
86
|
+
..._ObjectType.createFunctionDeclaration.bind(this)().toList(),
|
|
87
|
+
..._ObjectType.equalsFunctionDeclaration.bind(this)().toList(),
|
|
88
|
+
..._ObjectType.fromJsonFunctionDeclarations.bind(this)(),
|
|
89
|
+
..._ObjectType.fromRdfFunctionDeclarations.bind(this)(),
|
|
90
|
+
..._ObjectType.jsonSchemaFunctionDeclaration.bind(this)().toList(),
|
|
91
|
+
..._ObjectType.jsonUiSchemaFunctionDeclaration.bind(this)().toList(),
|
|
92
|
+
..._ObjectType.jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
|
|
93
|
+
..._ObjectType.hashFunctionDeclaration.bind(this)().toList(),
|
|
94
|
+
..._ObjectType.sparqlFunctionDeclarations.bind(this)(),
|
|
95
|
+
..._ObjectType.toJsonFunctionDeclaration.bind(this)().toList(),
|
|
96
|
+
..._ObjectType.toRdfFunctionDeclaration.bind(this)().toList(),
|
|
97
|
+
];
|
|
98
|
+
if (moduleStatements.length > 0) {
|
|
99
|
+
declarations.push({
|
|
100
|
+
isExported: this.export,
|
|
101
|
+
kind: StructureKind.Module,
|
|
102
|
+
name: this.name,
|
|
103
|
+
statements: moduleStatements,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return declarations;
|
|
107
|
+
}
|
|
47
108
|
get descendantObjectTypes() {
|
|
48
109
|
return this.lazyDescendantObjectTypes();
|
|
49
110
|
}
|
|
50
111
|
get discriminatorProperty() {
|
|
51
|
-
return Maybe.of(
|
|
52
|
-
name: this.configuration.objectTypeDiscriminatorPropertyName,
|
|
53
|
-
type: "string",
|
|
54
|
-
values: [this.discriminatorValue],
|
|
55
|
-
});
|
|
112
|
+
return Maybe.of(this._discriminatorProperty);
|
|
56
113
|
}
|
|
57
114
|
get discriminatorValue() {
|
|
58
115
|
return this.name;
|
|
59
116
|
}
|
|
117
|
+
get equalsFunction() {
|
|
118
|
+
switch (this.declarationType) {
|
|
119
|
+
case "class":
|
|
120
|
+
return "purifyHelpers.Equatable.equals";
|
|
121
|
+
case "interface":
|
|
122
|
+
return `${this.name}.equals`;
|
|
123
|
+
default:
|
|
124
|
+
throw new RangeError(this.declarationType);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
60
127
|
get hashFunctionName() {
|
|
61
|
-
if (this.
|
|
62
|
-
this.
|
|
128
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
129
|
+
this.descendantObjectTypes.length > 0)
|
|
63
130
|
return `hash${this.name}`;
|
|
64
|
-
}
|
|
65
131
|
return "hash";
|
|
66
132
|
}
|
|
67
|
-
get
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
133
|
+
get identifierProperty() {
|
|
134
|
+
const identifierProperty = this.properties.find((property) => property instanceof ObjectType.IdentifierProperty);
|
|
135
|
+
invariant(identifierProperty);
|
|
136
|
+
return identifierProperty;
|
|
137
|
+
}
|
|
138
|
+
get identifierType() {
|
|
139
|
+
return this.identifierProperty.type;
|
|
140
|
+
}
|
|
141
|
+
get jsonName() {
|
|
142
|
+
if (this.features.has("toJson")) {
|
|
143
|
+
switch (this.declarationType) {
|
|
144
|
+
case "class":
|
|
145
|
+
return `ReturnType<${this.name}["toJson"]>`;
|
|
146
|
+
case "interface":
|
|
147
|
+
return `ReturnType<typeof ${this.name}.toJson>`;
|
|
148
|
+
default:
|
|
149
|
+
throw new RangeError(this.declarationType);
|
|
77
150
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
151
|
+
}
|
|
152
|
+
if (this.features.has("fromJson")) {
|
|
153
|
+
return `Parameters<typeof ${this.name}.fromJson>[0]`;
|
|
154
|
+
}
|
|
155
|
+
throw new RangeError("jsonName called when neither fromJson nor toJson features are enabled");
|
|
156
|
+
}
|
|
157
|
+
get jsonUiSchemaFunctionName() {
|
|
158
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
159
|
+
this.descendantObjectTypes.length > 0)
|
|
160
|
+
return `${camelCase(this.name)}JsonUiSchema`;
|
|
161
|
+
return "jsonUiSchema";
|
|
162
|
+
}
|
|
163
|
+
get jsonZodSchemaFunctionName() {
|
|
164
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
165
|
+
this.descendantObjectTypes.length > 0)
|
|
166
|
+
return `${camelCase(this.name)}JsonZodSchema`;
|
|
167
|
+
return "jsonZodSchema";
|
|
168
|
+
}
|
|
169
|
+
get mutable() {
|
|
170
|
+
return this.properties.some((property) => property.mutable);
|
|
171
|
+
}
|
|
172
|
+
get ownProperties() {
|
|
173
|
+
if (this.parentObjectTypes.length === 0) {
|
|
174
|
+
// Consider that a root of the object type hierarchy "owns" the identifier and type discriminator properties
|
|
175
|
+
// for all of its subtypes in the hierarchy.
|
|
176
|
+
invariant(this.properties.length >= 2, this.name);
|
|
177
|
+
return this.properties;
|
|
178
|
+
}
|
|
179
|
+
return this.properties.filter((property) => !(property instanceof IdentifierProperty) &&
|
|
180
|
+
!(property instanceof TypeDiscriminatorProperty));
|
|
80
181
|
}
|
|
81
182
|
get parentObjectTypes() {
|
|
82
183
|
return this.lazyParentObjectTypes();
|
|
@@ -93,24 +194,45 @@ export class ObjectType extends Type {
|
|
|
93
194
|
}
|
|
94
195
|
return properties;
|
|
95
196
|
}
|
|
96
|
-
|
|
97
|
-
return
|
|
197
|
+
get useImports() {
|
|
198
|
+
return this.imports;
|
|
98
199
|
}
|
|
99
|
-
|
|
100
|
-
switch (this.
|
|
200
|
+
get thisVariable() {
|
|
201
|
+
switch (this.declarationType) {
|
|
101
202
|
case "class":
|
|
102
|
-
return "
|
|
203
|
+
return "this";
|
|
103
204
|
case "interface":
|
|
104
|
-
return
|
|
205
|
+
return `_${camelCase(this.name)}`;
|
|
206
|
+
default:
|
|
207
|
+
throw new RangeError(this.declarationType);
|
|
105
208
|
}
|
|
106
209
|
}
|
|
210
|
+
fromJsonExpression({ variables, }) {
|
|
211
|
+
// Assumes the JSON object has been recursively validated already.
|
|
212
|
+
return `${this.name}.fromJson(${variables.value}).unsafeCoerce()`;
|
|
213
|
+
}
|
|
107
214
|
fromRdfExpression({ variables, }) {
|
|
108
|
-
|
|
215
|
+
// Ignore the rdf:type if the instance of this type is the object of another property.
|
|
216
|
+
// Instead, assume the property has the correct range.
|
|
217
|
+
// This also accommodates the case where the object of a property is a dangling identifier that's not the
|
|
218
|
+
// subject of any statements.
|
|
219
|
+
return `${variables.resourceValues}.head().chain(value => value.to${this.rdfjsResourceType().named ? "Named" : ""}Resource()).chain(_resource => ${this.name}.fromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: _resource }))`;
|
|
109
220
|
}
|
|
110
221
|
hashStatements({ variables, }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
222
|
+
switch (this.declarationType) {
|
|
223
|
+
case "class":
|
|
224
|
+
return [`${variables.value}.hash(${variables.hasher});`];
|
|
225
|
+
case "interface":
|
|
226
|
+
return [
|
|
227
|
+
`${this.name}.${this.hashFunctionName}(${variables.value}, ${variables.hasher});`,
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
jsonUiSchemaElement({ variables, }) {
|
|
232
|
+
return Maybe.of(`${this.name}.${this.jsonUiSchemaFunctionName}({ scopePrefix: ${variables.scopePrefix} })`);
|
|
233
|
+
}
|
|
234
|
+
jsonZodSchema(_parameters) {
|
|
235
|
+
return `${this.name}.${this.jsonZodSchemaFunctionName}()`;
|
|
114
236
|
}
|
|
115
237
|
rdfjsResourceType(options) {
|
|
116
238
|
if (this.parentObjectTypes.length > 0) {
|
|
@@ -122,12 +244,48 @@ export class ObjectType extends Type {
|
|
|
122
244
|
named: this.identifierType.isNamedNodeKind,
|
|
123
245
|
};
|
|
124
246
|
}
|
|
247
|
+
sparqlConstructTemplateTriples({ context, variables, }) {
|
|
248
|
+
switch (context) {
|
|
249
|
+
case "property":
|
|
250
|
+
return super.sparqlConstructTemplateTriples({ context, variables });
|
|
251
|
+
case "type":
|
|
252
|
+
return [
|
|
253
|
+
`...${this.name}.sparqlConstructTemplateTriples(${objectInitializer({
|
|
254
|
+
ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
|
|
255
|
+
subject: variables.subject,
|
|
256
|
+
variablePrefix: variables.variablePrefix,
|
|
257
|
+
})})`,
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
sparqlWherePatterns({ context, variables, }) {
|
|
262
|
+
switch (context) {
|
|
263
|
+
case "property":
|
|
264
|
+
return super.sparqlWherePatterns({ context, variables });
|
|
265
|
+
case "type":
|
|
266
|
+
return [
|
|
267
|
+
`...${this.name}.sparqlWherePatterns(${objectInitializer({
|
|
268
|
+
ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
|
|
269
|
+
subject: variables.subject,
|
|
270
|
+
variablePrefix: variables.variablePrefix,
|
|
271
|
+
})})`,
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
toJsonExpression({ variables, }) {
|
|
276
|
+
switch (this.declarationType) {
|
|
277
|
+
case "class":
|
|
278
|
+
return `${variables.value}.toJson()`;
|
|
279
|
+
case "interface":
|
|
280
|
+
return `${this.name}.toJson(${variables.value})`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
125
283
|
toRdfExpression({ variables, }) {
|
|
126
|
-
switch (this.
|
|
284
|
+
switch (this.declarationType) {
|
|
127
285
|
case "class":
|
|
128
|
-
return `${variables.value}.toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })
|
|
286
|
+
return `${variables.value}.toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
|
|
129
287
|
case "interface":
|
|
130
|
-
return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })
|
|
288
|
+
return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
|
|
131
289
|
}
|
|
132
290
|
}
|
|
133
291
|
ensureAtMostOneSuperObjectType() {
|
|
@@ -145,6 +303,21 @@ __decorate([
|
|
|
145
303
|
__decorate([
|
|
146
304
|
Memoize()
|
|
147
305
|
], ObjectType.prototype, "hashFunctionName", null);
|
|
306
|
+
__decorate([
|
|
307
|
+
Memoize()
|
|
308
|
+
], ObjectType.prototype, "identifierProperty", null);
|
|
309
|
+
__decorate([
|
|
310
|
+
Memoize()
|
|
311
|
+
], ObjectType.prototype, "identifierType", null);
|
|
312
|
+
__decorate([
|
|
313
|
+
Memoize()
|
|
314
|
+
], ObjectType.prototype, "jsonUiSchemaFunctionName", null);
|
|
315
|
+
__decorate([
|
|
316
|
+
Memoize()
|
|
317
|
+
], ObjectType.prototype, "jsonZodSchemaFunctionName", null);
|
|
318
|
+
__decorate([
|
|
319
|
+
Memoize()
|
|
320
|
+
], ObjectType.prototype, "ownProperties", null);
|
|
148
321
|
__decorate([
|
|
149
322
|
Memoize()
|
|
150
323
|
], ObjectType.prototype, "parentObjectTypes", null);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type ModuleDeclarationStructure, type TypeAliasDeclarationStructure } from "ts-morph";
|
|
3
|
+
import { DeclaredType } from "./DeclaredType.js";
|
|
4
|
+
import type { Import } from "./Import.js";
|
|
5
|
+
import type { ObjectType } from "./ObjectType.js";
|
|
6
|
+
import type { Type } from "./Type.js";
|
|
7
|
+
/**
|
|
8
|
+
* A union of object types, generated as a type alias
|
|
9
|
+
*
|
|
10
|
+
* type SomeUnion = Member1 | Member2 | ...
|
|
11
|
+
*
|
|
12
|
+
* with associated functions that switch on the type discriminator property and delegate to the appropriate
|
|
13
|
+
* member type code.
|
|
14
|
+
*
|
|
15
|
+
* It also generates SPARQL graph patterns that UNION the member object types.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ObjectUnionType extends DeclaredType {
|
|
18
|
+
readonly kind = "ObjectUnionType";
|
|
19
|
+
private readonly _discriminatorProperty;
|
|
20
|
+
private readonly comment;
|
|
21
|
+
private readonly label;
|
|
22
|
+
private readonly memberTypes;
|
|
23
|
+
constructor({ comment, label, memberTypes, ...superParameters }: ConstructorParameters<typeof DeclaredType>[0] & {
|
|
24
|
+
comment: Maybe<string>;
|
|
25
|
+
export_: boolean;
|
|
26
|
+
label: Maybe<string>;
|
|
27
|
+
memberTypes: readonly ObjectType[];
|
|
28
|
+
name: string;
|
|
29
|
+
});
|
|
30
|
+
get conversions(): readonly Type.Conversion[];
|
|
31
|
+
get declarationImports(): readonly Import[];
|
|
32
|
+
get declarations(): (ModuleDeclarationStructure | TypeAliasDeclarationStructure)[];
|
|
33
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
34
|
+
get equalsFunction(): string;
|
|
35
|
+
get jsonName(): string;
|
|
36
|
+
get mutable(): boolean;
|
|
37
|
+
get useImports(): readonly Import[];
|
|
38
|
+
protected get thisVariable(): string;
|
|
39
|
+
private get equalsFunctionDeclaration();
|
|
40
|
+
private get fromJsonFunctionDeclaration();
|
|
41
|
+
private get fromRdfFunctionDeclaration();
|
|
42
|
+
private get hashFunctionDeclaration();
|
|
43
|
+
private get jsonZodSchemaFunctionDeclaration();
|
|
44
|
+
private get sparqlFunctionDeclarations();
|
|
45
|
+
private get toJsonFunctionDeclaration();
|
|
46
|
+
private get toRdfFunctionDeclaration();
|
|
47
|
+
private get typeAliasDeclaration();
|
|
48
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
49
|
+
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
50
|
+
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
51
|
+
jsonZodSchema(): ReturnType<Type["jsonZodSchema"]>;
|
|
52
|
+
sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
53
|
+
sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
54
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
55
|
+
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
56
|
+
private rdfjsResourceType;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ObjectUnionType.d.ts.map
|