@shaclmate/compiler 2.0.13 → 2.0.15
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 +178 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +200 -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 +19 -0
- package/generators/ts/DateTimeType.js +66 -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 +17 -0
- package/generators/ts/Import.js +54 -0
- package/generators/ts/ListType.d.ts +19 -8
- package/generators/ts/ListType.js +206 -44
- 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 +48 -25
- package/generators/ts/ObjectType.js +234 -50
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +450 -0
- package/generators/ts/OptionType.d.ts +14 -4
- package/generators/ts/OptionType.js +70 -20
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +27 -31
- package/generators/ts/SetType.d.ts +14 -4
- package/generators/ts/SetType.js +108 -30
- package/generators/ts/SnippetDeclarations.d.ts +11 -0
- package/generators/ts/SnippetDeclarations.js +215 -0
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +54 -0
- package/generators/ts/TermType.js +242 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +57 -99
- package/generators/ts/Type.d.ts +117 -46
- package/generators/ts/Type.js +93 -59
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +224 -91
- package/generators/ts/UnionType.d.ts +20 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -8
- package/generators/ts/_ObjectType/IdentifierProperty.js +153 -32
- package/generators/ts/_ObjectType/Property.d.ts +139 -9
- package/generators/ts/_ObjectType/Property.js +26 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +24 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +103 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +23 -7
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +83 -14
- 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/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +78 -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 +275 -0
- package/input/generated.js +1436 -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 +46 -0
- package/package.json +15 -9
- 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,71 @@
|
|
|
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, TsFeature, 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
|
+
protected get thisVariable(): string;
|
|
60
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
49
61
|
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
50
62
|
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
63
|
+
jsonUiSchemaElement({ variables, }: {
|
|
64
|
+
variables: {
|
|
65
|
+
scopePrefix: string;
|
|
66
|
+
};
|
|
67
|
+
}): Maybe<string>;
|
|
68
|
+
jsonZodSchema(_parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
51
69
|
rdfjsResourceType(options?: {
|
|
52
70
|
mutable?: boolean;
|
|
53
71
|
}): {
|
|
@@ -55,7 +73,12 @@ export declare class ObjectType extends Type {
|
|
|
55
73
|
readonly name: string;
|
|
56
74
|
readonly named: boolean;
|
|
57
75
|
};
|
|
76
|
+
snippetDeclarations(): readonly string[];
|
|
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;
|
|
81
|
+
useImports(_features: Set<TsFeature>): readonly Import[];
|
|
59
82
|
protected ensureAtMostOneSuperObjectType(): void;
|
|
60
83
|
}
|
|
61
84
|
export declare namespace ObjectType {
|
|
@@ -4,33 +4,43 @@ 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
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import { DeclaredType } from "./DeclaredType.js";
|
|
13
|
+
import { Import } from "./Import.js";
|
|
14
|
+
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
15
|
+
import * as _ObjectType from "./_ObjectType/index.js";
|
|
16
|
+
import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
|
|
17
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
18
|
+
export class ObjectType extends DeclaredType {
|
|
19
|
+
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, mintingStrategy, toRdfTypes, ...superParameters }) {
|
|
14
20
|
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
21
|
this.kind = "ObjectType";
|
|
21
|
-
this.sparqlGraphPatternsClassDeclaration = _ObjectType.sparqlGraphPatternsClassDeclaration;
|
|
22
|
-
this.toRdfFunctionDeclaration = _ObjectType.toRdfFunctionDeclaration;
|
|
23
22
|
this.abstract = abstract;
|
|
24
|
-
this.
|
|
23
|
+
this.comment = comment;
|
|
24
|
+
this.declarationType = declarationType;
|
|
25
|
+
this.extern = extern;
|
|
26
|
+
this.fromRdfType = fromRdfType;
|
|
27
|
+
this.imports = imports;
|
|
28
|
+
this.label = label;
|
|
25
29
|
// Lazily initialize some members in getters to avoid recursive construction
|
|
26
30
|
this.lazyAncestorObjectTypes = lazyAncestorObjectTypes;
|
|
27
31
|
this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
|
|
28
32
|
this.lazyParentObjectTypes = lazyParentObjectTypes;
|
|
29
33
|
this.lazyProperties = lazyProperties;
|
|
30
|
-
this.identifierType = identifierType;
|
|
31
34
|
this.mintingStrategy = mintingStrategy;
|
|
32
|
-
this.
|
|
33
|
-
|
|
35
|
+
this.toRdfTypes = toRdfTypes;
|
|
36
|
+
}
|
|
37
|
+
get _discriminatorProperty() {
|
|
38
|
+
const discriminatorProperty = this.properties.find((property) => property instanceof ObjectType.TypeDiscriminatorProperty);
|
|
39
|
+
invariant(discriminatorProperty);
|
|
40
|
+
return {
|
|
41
|
+
name: discriminatorProperty.name,
|
|
42
|
+
values: [this.discriminatorValue],
|
|
43
|
+
};
|
|
34
44
|
}
|
|
35
45
|
get ancestorObjectTypes() {
|
|
36
46
|
return this.lazyAncestorObjectTypes();
|
|
@@ -44,39 +54,127 @@ export class ObjectType extends Type {
|
|
|
44
54
|
},
|
|
45
55
|
];
|
|
46
56
|
}
|
|
57
|
+
get declarationImports() {
|
|
58
|
+
if (this.extern) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const imports = this.properties.flatMap((property) => property.declarationImports);
|
|
62
|
+
if (this.features.has("fromJson") || this.features.has("jsonSchema")) {
|
|
63
|
+
imports.push(Import.ZOD);
|
|
64
|
+
}
|
|
65
|
+
if (this.features.has("jsonSchema")) {
|
|
66
|
+
imports.push(Import.ZOD_TO_JSON_SCHEMA);
|
|
67
|
+
}
|
|
68
|
+
if (this.features.has("fromRdf") || this.features.has("toRdf")) {
|
|
69
|
+
imports.push(Import.PURIFY);
|
|
70
|
+
imports.push(Import.RDFJS_RESOURCE);
|
|
71
|
+
}
|
|
72
|
+
if (this.features.has("sparql")) {
|
|
73
|
+
imports.push(Import.SPARQLJS);
|
|
74
|
+
}
|
|
75
|
+
return imports;
|
|
76
|
+
}
|
|
77
|
+
get declarations() {
|
|
78
|
+
const declarations = [
|
|
79
|
+
..._ObjectType.classDeclaration.bind(this)().toList(),
|
|
80
|
+
..._ObjectType.interfaceDeclaration.bind(this)().toList(),
|
|
81
|
+
];
|
|
82
|
+
const moduleStatements = [
|
|
83
|
+
..._ObjectType.createFunctionDeclaration.bind(this)().toList(),
|
|
84
|
+
..._ObjectType.equalsFunctionDeclaration.bind(this)().toList(),
|
|
85
|
+
..._ObjectType.fromJsonFunctionDeclarations.bind(this)(),
|
|
86
|
+
..._ObjectType.fromRdfFunctionDeclarations.bind(this)(),
|
|
87
|
+
..._ObjectType.jsonSchemaFunctionDeclaration.bind(this)().toList(),
|
|
88
|
+
..._ObjectType.jsonUiSchemaFunctionDeclaration.bind(this)().toList(),
|
|
89
|
+
..._ObjectType.jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
|
|
90
|
+
..._ObjectType.hashFunctionDeclaration.bind(this)().toList(),
|
|
91
|
+
..._ObjectType.sparqlFunctionDeclarations.bind(this)(),
|
|
92
|
+
..._ObjectType.toJsonFunctionDeclaration.bind(this)().toList(),
|
|
93
|
+
..._ObjectType.toRdfFunctionDeclaration.bind(this)().toList(),
|
|
94
|
+
];
|
|
95
|
+
if (moduleStatements.length > 0) {
|
|
96
|
+
declarations.push({
|
|
97
|
+
isExported: this.export,
|
|
98
|
+
kind: StructureKind.Module,
|
|
99
|
+
name: this.name,
|
|
100
|
+
statements: moduleStatements,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return declarations;
|
|
104
|
+
}
|
|
47
105
|
get descendantObjectTypes() {
|
|
48
106
|
return this.lazyDescendantObjectTypes();
|
|
49
107
|
}
|
|
50
108
|
get discriminatorProperty() {
|
|
51
|
-
return Maybe.of(
|
|
52
|
-
name: this.configuration.objectTypeDiscriminatorPropertyName,
|
|
53
|
-
type: "string",
|
|
54
|
-
values: [this.discriminatorValue],
|
|
55
|
-
});
|
|
109
|
+
return Maybe.of(this._discriminatorProperty);
|
|
56
110
|
}
|
|
57
111
|
get discriminatorValue() {
|
|
58
112
|
return this.name;
|
|
59
113
|
}
|
|
114
|
+
get equalsFunction() {
|
|
115
|
+
switch (this.declarationType) {
|
|
116
|
+
case "class":
|
|
117
|
+
return "((left, right) => left.equals(right))";
|
|
118
|
+
case "interface":
|
|
119
|
+
return `${this.name}.equals`;
|
|
120
|
+
default:
|
|
121
|
+
throw new RangeError(this.declarationType);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
60
124
|
get hashFunctionName() {
|
|
61
|
-
if (this.
|
|
62
|
-
this.
|
|
125
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
126
|
+
this.descendantObjectTypes.length > 0)
|
|
63
127
|
return `hash${this.name}`;
|
|
64
|
-
}
|
|
65
128
|
return "hash";
|
|
66
129
|
}
|
|
67
|
-
get
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
130
|
+
get identifierProperty() {
|
|
131
|
+
const identifierProperty = this.properties.find((property) => property instanceof ObjectType.IdentifierProperty);
|
|
132
|
+
invariant(identifierProperty);
|
|
133
|
+
return identifierProperty;
|
|
134
|
+
}
|
|
135
|
+
get identifierType() {
|
|
136
|
+
return this.identifierProperty.type;
|
|
137
|
+
}
|
|
138
|
+
get jsonName() {
|
|
139
|
+
if (this.features.has("toJson")) {
|
|
140
|
+
switch (this.declarationType) {
|
|
141
|
+
case "class":
|
|
142
|
+
return `ReturnType<${this.name}["toJson"]>`;
|
|
143
|
+
case "interface":
|
|
144
|
+
return `ReturnType<typeof ${this.name}.toJson>`;
|
|
145
|
+
default:
|
|
146
|
+
throw new RangeError(this.declarationType);
|
|
77
147
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
148
|
+
}
|
|
149
|
+
if (this.features.has("fromJson")) {
|
|
150
|
+
return `Parameters<typeof ${this.name}.fromJson>[0]`;
|
|
151
|
+
}
|
|
152
|
+
throw new RangeError(`${this.name}: jsonName called when neither fromJson nor toJson features are enabled`);
|
|
153
|
+
}
|
|
154
|
+
get jsonUiSchemaFunctionName() {
|
|
155
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
156
|
+
this.descendantObjectTypes.length > 0)
|
|
157
|
+
return `${camelCase(this.name)}JsonUiSchema`;
|
|
158
|
+
return "jsonUiSchema";
|
|
159
|
+
}
|
|
160
|
+
get jsonZodSchemaFunctionName() {
|
|
161
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
162
|
+
this.descendantObjectTypes.length > 0)
|
|
163
|
+
return `${camelCase(this.name)}JsonZodSchema`;
|
|
164
|
+
return "jsonZodSchema";
|
|
165
|
+
}
|
|
166
|
+
get mutable() {
|
|
167
|
+
return this.properties.some((property) => property.mutable);
|
|
168
|
+
}
|
|
169
|
+
get ownProperties() {
|
|
170
|
+
if (this.parentObjectTypes.length === 0) {
|
|
171
|
+
// Consider that a root of the object type hierarchy "owns" the identifier and type discriminator properties
|
|
172
|
+
// for all of its subtypes in the hierarchy.
|
|
173
|
+
invariant(this.properties.length >= 2, this.name);
|
|
174
|
+
return this.properties;
|
|
175
|
+
}
|
|
176
|
+
return this.properties.filter((property) => !(property instanceof IdentifierProperty) &&
|
|
177
|
+
!(property instanceof TypeDiscriminatorProperty));
|
|
80
178
|
}
|
|
81
179
|
get parentObjectTypes() {
|
|
82
180
|
return this.lazyParentObjectTypes();
|
|
@@ -93,24 +191,42 @@ export class ObjectType extends Type {
|
|
|
93
191
|
}
|
|
94
192
|
return properties;
|
|
95
193
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
equalsFunction() {
|
|
100
|
-
switch (this.configuration.objectTypeDeclarationType) {
|
|
194
|
+
get thisVariable() {
|
|
195
|
+
switch (this.declarationType) {
|
|
101
196
|
case "class":
|
|
102
|
-
return "
|
|
197
|
+
return "this";
|
|
103
198
|
case "interface":
|
|
104
|
-
return
|
|
199
|
+
return `_${camelCase(this.name)}`;
|
|
200
|
+
default:
|
|
201
|
+
throw new RangeError(this.declarationType);
|
|
105
202
|
}
|
|
106
203
|
}
|
|
204
|
+
fromJsonExpression({ variables, }) {
|
|
205
|
+
// Assumes the JSON object has been recursively validated already.
|
|
206
|
+
return `${this.name}.fromJson(${variables.value}).unsafeCoerce()`;
|
|
207
|
+
}
|
|
107
208
|
fromRdfExpression({ variables, }) {
|
|
108
|
-
|
|
209
|
+
// Ignore the rdf:type if the instance of this type is the object of another property.
|
|
210
|
+
// Instead, assume the property has the correct range.
|
|
211
|
+
// This also accommodates the case where the object of a property is a dangling identifier that's not the
|
|
212
|
+
// subject of any statements.
|
|
213
|
+
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
214
|
}
|
|
110
215
|
hashStatements({ variables, }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
216
|
+
switch (this.declarationType) {
|
|
217
|
+
case "class":
|
|
218
|
+
return [`${variables.value}.hash(${variables.hasher});`];
|
|
219
|
+
case "interface":
|
|
220
|
+
return [
|
|
221
|
+
`${this.name}.${this.hashFunctionName}(${variables.value}, ${variables.hasher});`,
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
jsonUiSchemaElement({ variables, }) {
|
|
226
|
+
return Maybe.of(`${this.name}.${this.jsonUiSchemaFunctionName}({ scopePrefix: ${variables.scopePrefix} })`);
|
|
227
|
+
}
|
|
228
|
+
jsonZodSchema(_parameters) {
|
|
229
|
+
return `${this.name}.${this.jsonZodSchemaFunctionName}()`;
|
|
114
230
|
}
|
|
115
231
|
rdfjsResourceType(options) {
|
|
116
232
|
if (this.parentObjectTypes.length > 0) {
|
|
@@ -122,14 +238,67 @@ export class ObjectType extends Type {
|
|
|
122
238
|
named: this.identifierType.isNamedNodeKind,
|
|
123
239
|
};
|
|
124
240
|
}
|
|
241
|
+
snippetDeclarations() {
|
|
242
|
+
const snippetDeclarations = [];
|
|
243
|
+
if (this.features.has("equals")) {
|
|
244
|
+
snippetDeclarations.push(SnippetDeclarations.EqualsResult);
|
|
245
|
+
}
|
|
246
|
+
if ((this.features.has("fromJson") || this.features.has("fromRdf")) &&
|
|
247
|
+
this.parentObjectTypes.length > 0) {
|
|
248
|
+
snippetDeclarations.push(SnippetDeclarations.UnwrapR);
|
|
249
|
+
}
|
|
250
|
+
for (const property of this.ownProperties) {
|
|
251
|
+
snippetDeclarations.push(...property.snippetDeclarations);
|
|
252
|
+
}
|
|
253
|
+
return snippetDeclarations;
|
|
254
|
+
}
|
|
255
|
+
sparqlConstructTemplateTriples({ context, variables, }) {
|
|
256
|
+
switch (context) {
|
|
257
|
+
case "property":
|
|
258
|
+
return super.sparqlConstructTemplateTriples({ context, variables });
|
|
259
|
+
case "type":
|
|
260
|
+
return [
|
|
261
|
+
`...${this.name}.sparqlConstructTemplateTriples(${objectInitializer({
|
|
262
|
+
ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
|
|
263
|
+
subject: variables.subject,
|
|
264
|
+
variablePrefix: variables.variablePrefix,
|
|
265
|
+
})})`,
|
|
266
|
+
];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
sparqlWherePatterns({ context, variables, }) {
|
|
270
|
+
switch (context) {
|
|
271
|
+
case "property":
|
|
272
|
+
return super.sparqlWherePatterns({ context, variables });
|
|
273
|
+
case "type":
|
|
274
|
+
return [
|
|
275
|
+
`...${this.name}.sparqlWherePatterns(${objectInitializer({
|
|
276
|
+
ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
|
|
277
|
+
subject: variables.subject,
|
|
278
|
+
variablePrefix: variables.variablePrefix,
|
|
279
|
+
})})`,
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
toJsonExpression({ variables, }) {
|
|
284
|
+
switch (this.declarationType) {
|
|
285
|
+
case "class":
|
|
286
|
+
return `${variables.value}.toJson()`;
|
|
287
|
+
case "interface":
|
|
288
|
+
return `${this.name}.toJson(${variables.value})`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
125
291
|
toRdfExpression({ variables, }) {
|
|
126
|
-
switch (this.
|
|
292
|
+
switch (this.declarationType) {
|
|
127
293
|
case "class":
|
|
128
|
-
return `${variables.value}.toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })
|
|
294
|
+
return `${variables.value}.toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
|
|
129
295
|
case "interface":
|
|
130
|
-
return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })
|
|
296
|
+
return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
|
|
131
297
|
}
|
|
132
298
|
}
|
|
299
|
+
useImports(_features) {
|
|
300
|
+
return this.imports;
|
|
301
|
+
}
|
|
133
302
|
ensureAtMostOneSuperObjectType() {
|
|
134
303
|
if (this.parentObjectTypes.length > 1) {
|
|
135
304
|
throw new RangeError(`object type '${this.name}' has multiple super object types`);
|
|
@@ -145,6 +314,21 @@ __decorate([
|
|
|
145
314
|
__decorate([
|
|
146
315
|
Memoize()
|
|
147
316
|
], ObjectType.prototype, "hashFunctionName", null);
|
|
317
|
+
__decorate([
|
|
318
|
+
Memoize()
|
|
319
|
+
], ObjectType.prototype, "identifierProperty", null);
|
|
320
|
+
__decorate([
|
|
321
|
+
Memoize()
|
|
322
|
+
], ObjectType.prototype, "identifierType", null);
|
|
323
|
+
__decorate([
|
|
324
|
+
Memoize()
|
|
325
|
+
], ObjectType.prototype, "jsonUiSchemaFunctionName", null);
|
|
326
|
+
__decorate([
|
|
327
|
+
Memoize()
|
|
328
|
+
], ObjectType.prototype, "jsonZodSchemaFunctionName", null);
|
|
329
|
+
__decorate([
|
|
330
|
+
Memoize()
|
|
331
|
+
], ObjectType.prototype, "ownProperties", null);
|
|
148
332
|
__decorate([
|
|
149
333
|
Memoize()
|
|
150
334
|
], 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
|
+
protected get thisVariable(): string;
|
|
38
|
+
private get equalsFunctionDeclaration();
|
|
39
|
+
private get fromJsonFunctionDeclaration();
|
|
40
|
+
private get fromRdfFunctionDeclaration();
|
|
41
|
+
private get hashFunctionDeclaration();
|
|
42
|
+
private get jsonZodSchemaFunctionDeclaration();
|
|
43
|
+
private get sparqlFunctionDeclarations();
|
|
44
|
+
private get toJsonFunctionDeclaration();
|
|
45
|
+
private get toRdfFunctionDeclaration();
|
|
46
|
+
private get typeAliasDeclaration();
|
|
47
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
48
|
+
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
49
|
+
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
50
|
+
jsonZodSchema(): ReturnType<Type["jsonZodSchema"]>;
|
|
51
|
+
sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
52
|
+
sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
53
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
54
|
+
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
55
|
+
useImports(): readonly Import[];
|
|
56
|
+
private rdfjsResourceType;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ObjectUnionType.d.ts.map
|