@shaclmate/compiler 2.0.20 → 2.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +1 -0
  2. package/dist/ShapesGraphToAstTransformer.js +56 -12
  3. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  4. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  5. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  6. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  8. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
  10. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
  12. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
  13. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
  15. package/dist/ast/Ast.d.ts +0 -1
  16. package/dist/ast/Curie.d.ts +14 -0
  17. package/dist/ast/Curie.js +21 -0
  18. package/dist/ast/IdentifierType.d.ts +3 -2
  19. package/dist/ast/ListType.d.ts +2 -1
  20. package/dist/ast/LiteralType.d.ts +1 -1
  21. package/dist/ast/Name.d.ts +40 -5
  22. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  23. package/dist/ast/ObjectType.d.ts +18 -13
  24. package/dist/ast/ObjectUnionType.d.ts +0 -11
  25. package/dist/ast/OptionType.d.ts +2 -2
  26. package/dist/ast/SetType.d.ts +2 -2
  27. package/dist/ast/TermType.d.ts +12 -4
  28. package/dist/ast/Type.d.ts +1 -1
  29. package/dist/enums/TsFeature.d.ts +1 -4
  30. package/dist/enums/TsFeature.js +1 -15
  31. package/dist/generators/json/AstJsonGenerator.js +19 -3
  32. package/dist/generators/ts/BooleanType.d.ts +3 -1
  33. package/dist/generators/ts/BooleanType.js +11 -2
  34. package/dist/generators/ts/DateTimeType.d.ts +8 -7
  35. package/dist/generators/ts/DateTimeType.js +31 -7
  36. package/dist/generators/ts/DateType.d.ts +5 -2
  37. package/dist/generators/ts/DateType.js +15 -1
  38. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  39. package/dist/generators/ts/DeclaredType.js +2 -2
  40. package/dist/generators/ts/FloatType.d.ts +6 -0
  41. package/dist/generators/ts/FloatType.js +18 -0
  42. package/dist/generators/ts/IdentifierType.d.ts +12 -7
  43. package/dist/generators/ts/IdentifierType.js +94 -6
  44. package/dist/generators/ts/Import.d.ts +2 -0
  45. package/dist/generators/ts/Import.js +10 -0
  46. package/dist/generators/ts/IntType.d.ts +6 -0
  47. package/dist/generators/ts/IntType.js +18 -0
  48. package/dist/generators/ts/ListType.d.ts +15 -12
  49. package/dist/generators/ts/ListType.js +98 -57
  50. package/dist/generators/ts/LiteralType.d.ts +10 -9
  51. package/dist/generators/ts/LiteralType.js +13 -2
  52. package/dist/generators/ts/NumberType.d.ts +2 -1
  53. package/dist/generators/ts/NumberType.js +7 -2
  54. package/dist/generators/ts/ObjectType.d.ts +66 -43
  55. package/dist/generators/ts/ObjectType.js +144 -123
  56. package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
  57. package/dist/generators/ts/ObjectUnionType.js +290 -97
  58. package/dist/generators/ts/OptionType.d.ts +14 -10
  59. package/dist/generators/ts/OptionType.js +60 -34
  60. package/dist/generators/ts/PrimitiveType.d.ts +4 -4
  61. package/dist/generators/ts/PrimitiveType.js +18 -3
  62. package/dist/generators/ts/SetType.d.ts +16 -12
  63. package/dist/generators/ts/SetType.js +69 -40
  64. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  65. package/dist/generators/ts/SnippetDeclarations.js +215 -101
  66. package/dist/generators/ts/StringType.d.ts +3 -1
  67. package/dist/generators/ts/StringType.js +14 -2
  68. package/dist/generators/ts/TermType.d.ts +22 -14
  69. package/dist/generators/ts/TermType.js +53 -25
  70. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  71. package/dist/generators/ts/TsGenerator.js +23 -12
  72. package/dist/generators/ts/Type.d.ts +89 -31
  73. package/dist/generators/ts/Type.js +57 -54
  74. package/dist/generators/ts/TypeFactory.d.ts +4 -5
  75. package/dist/generators/ts/TypeFactory.js +290 -226
  76. package/dist/generators/ts/UnionType.d.ts +14 -10
  77. package/dist/generators/ts/UnionType.js +319 -142
  78. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  79. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
  80. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  81. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
  82. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
  84. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
  85. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
  86. package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
  87. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  88. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  89. package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
  90. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  91. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  92. package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
  93. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
  94. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
  95. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  96. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  97. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  98. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
  99. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  100. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  101. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  102. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  103. package/dist/generators/ts/_ObjectType/index.js +9 -7
  104. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  105. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  106. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  107. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  108. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  109. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  110. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  111. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  112. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  113. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
  115. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  116. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
  117. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  118. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
  119. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
  120. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  121. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
  122. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  123. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  124. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  125. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  126. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  127. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  128. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  129. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  130. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  131. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  132. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  133. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  134. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  135. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  136. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  137. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  138. package/dist/generators/ts/tsName.js +27 -13
  139. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  140. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  141. package/dist/input/NodeShape.d.ts +6 -8
  142. package/dist/input/NodeShape.js +20 -44
  143. package/dist/input/Ontology.d.ts +0 -3
  144. package/dist/input/Ontology.js +0 -9
  145. package/dist/input/PropertyPath.d.ts +6 -5
  146. package/dist/input/PropertyPath.js +14 -22
  147. package/dist/input/PropertyShape.d.ts +3 -1
  148. package/dist/input/PropertyShape.js +8 -2
  149. package/dist/input/ShapesGraph.js +4 -4
  150. package/dist/input/generated.d.ts +923 -105
  151. package/dist/input/generated.js +1865 -969
  152. package/dist/input/tsFeatures.d.ts +3 -2
  153. package/dist/input/tsFeatures.js +44 -27
  154. package/package.json +18 -16
  155. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  156. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  157. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  159. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  161. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  162. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  163. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  164. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  165. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  166. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  167. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  168. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  169. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  170. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  171. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  172. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -1,6 +1,4 @@
1
- import { Maybe } from "purify-ts";
2
1
  import { invariant } from "ts-invariant";
3
- import { rdfjsTermExpression } from "./_ObjectType/rdfjsTermExpression.js";
4
2
  import { objectInitializer } from "./objectInitializer.js";
5
3
  /**
6
4
  * Abstract base class for generating TypeScript expressions and statemenst in the TypeScript generator.
@@ -8,46 +6,19 @@ import { objectInitializer } from "./objectInitializer.js";
8
6
  * Subclasses are used for both property types (c.f., property* methods) and node/object types.
9
7
  */
10
8
  export class Type {
11
- dataFactoryVariable;
12
- constructor({ dataFactoryVariable, }) {
13
- this.dataFactoryVariable = dataFactoryVariable;
14
- }
15
- /**
16
- * A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
17
- */
18
- get discriminatorProperty() {
19
- return Maybe.empty();
20
- }
21
- /**
22
- * Element object for a JSON Forms UI schema.
23
- */
24
- jsonUiSchemaElement(_parameters) {
25
- return Maybe.empty();
26
- }
27
- /**
28
- * Reusable function, type, and other declarations that are not particular to this type but that type-specific code
29
- * relies on. For example, the equals function/method of ObjectType has a custom return type that's the same across all
30
- * ObjectType's. Instead of re-declaring the return type anonymously on every equals function, declare a named type
31
- * as a snippet and reference it.
32
- *
33
- * The generator deduplicates snippet declarations across all types before adding them to the source.
34
- */
35
- snippetDeclarations(_features) {
36
- return [];
37
- }
38
9
  /**
39
10
  * An array of SPARQL.js CONSTRUCT template triples for a value of this type, as strings (so they can incorporate runtime calls).
40
11
  *
41
12
  * This method is called in two contexts:
42
- * (1) By an ObjectType.Property. The property expects a basic graph pattern (subject, property path, property object). The property calls this method to get additional triples in which the propertyObject is the subject. For example, if the type is a nested object, it would include (propertyObject, nestedPredicate, nestedObject) triples.
43
- * (2) By another Type. For example, ListType calls this method to with the item variable as a subject in order to chain additional patterns on items.
44
- *
45
- * Term types with no additional properties should return an empty array.
13
+ * (1) When an instance of the type is an "object" of a property.
14
+ * This method should return a BGP (variables.subject, variables.predicate, variables.object) and recursively call itself with the variables.object as a "subject" context.
15
+ * (2) When an instance of the type is a "subject".
16
+ * For example, ListType calls this method to with the item variable as a subject in order to chain additional patterns on items. Term types with no additional patterns should return an empty array.
46
17
  */
47
- sparqlConstructTemplateTriples({ context, variables, }) {
18
+ sparqlConstructTemplateTriples({ allowIgnoreRdfType, context, variables, }) {
48
19
  switch (context) {
49
- case "property": {
50
- const objectPrefix = `${this.dataFactoryVariable}.variable!(`;
20
+ case "object": {
21
+ const objectPrefix = "dataFactory.variable!(";
51
22
  const objectSuffix = ")";
52
23
  invariant(variables.object.startsWith(objectPrefix));
53
24
  invariant(variables.object.endsWith(objectSuffix));
@@ -58,14 +29,15 @@ export class Type {
58
29
  subject: variables.subject,
59
30
  }),
60
31
  ].concat(this.sparqlConstructTemplateTriples({
61
- context: "type",
32
+ allowIgnoreRdfType,
33
+ context: "subject",
62
34
  variables: {
63
35
  subject: variables.object,
64
36
  variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
65
37
  },
66
38
  }));
67
39
  }
68
- case "type":
40
+ case "subject":
69
41
  return [];
70
42
  }
71
43
  }
@@ -74,10 +46,10 @@ export class Type {
74
46
  *
75
47
  * See note in sparqlConstructTemplateTriples re: how this method is used.
76
48
  */
77
- sparqlWherePatterns({ context, variables, }) {
49
+ sparqlWherePatterns({ allowIgnoreRdfType, context, variables, }) {
78
50
  switch (context) {
79
- case "property": {
80
- const objectPrefix = `${this.dataFactoryVariable}.variable!(`;
51
+ case "object": {
52
+ const objectPrefix = "dataFactory.variable!(";
81
53
  const objectSuffix = ")";
82
54
  invariant(variables.object.startsWith(objectPrefix));
83
55
  invariant(variables.object.endsWith(objectSuffix));
@@ -91,28 +63,59 @@ export class Type {
91
63
  type: '"bgp"',
92
64
  }),
93
65
  ].concat(this.sparqlWherePatterns({
94
- context: "type",
66
+ allowIgnoreRdfType,
67
+ context: "subject",
95
68
  variables: {
96
69
  subject: variables.object,
97
70
  variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
98
71
  },
99
72
  }));
100
73
  }
101
- case "type":
74
+ case "subject":
102
75
  return [];
103
76
  }
104
77
  }
105
- /**
106
- * Imports necessary to use this type.
107
- */
108
- useImports(_features) {
109
- return [];
78
+ }
79
+ (function (Type) {
80
+ class JsonName {
81
+ /**
82
+ * Is the type optional in JSON? Equivalent to ? in TypeScript or | undefined.
83
+ */
84
+ optional;
85
+ /**
86
+ * The name of the type when it's required i.e. -- so it should never include "| undefined".
87
+ */
88
+ requiredName;
89
+ constructor(requiredName, parameters) {
90
+ this.optional = !!parameters?.optional;
91
+ this.requiredName = requiredName;
92
+ }
93
+ toString() {
94
+ return this.optional
95
+ ? `(${this.requiredName}) | undefined`
96
+ : this.requiredName;
97
+ }
110
98
  }
111
- rdfjsTermExpression(rdfjsTerm) {
112
- return rdfjsTermExpression({
113
- dataFactoryVariable: this.dataFactoryVariable,
114
- rdfjsTerm,
115
- });
99
+ Type.JsonName = JsonName;
100
+ class GraphqlName {
101
+ /**
102
+ * Is the type nullable in GraphQL?
103
+ */
104
+ nullable;
105
+ /**
106
+ * The name of the type when it's nullable -- so it should never include "new graphql.GraphQLNonNull(...)" around it.
107
+ */
108
+ nullableName;
109
+ constructor(nullableName, parameters) {
110
+ this.nullable = !!parameters?.nullable;
111
+ this.nullableName = nullableName;
112
+ }
113
+ toString() {
114
+ return this.nullable
115
+ ? this.nullableName
116
+ : `new graphql.GraphQLNonNull(${this.nullableName})`;
117
+ }
116
118
  }
117
- }
119
+ Type.GraphqlName = GraphqlName;
120
+ })(Type || (Type = {}));
118
121
  //# sourceMappingURL=Type.js.map
@@ -1,14 +1,13 @@
1
1
  import type * as ast from "../../ast/index.js";
2
+ import { ObjectType } from "./ObjectType.js";
2
3
  import type { Type } from "./Type.js";
3
4
  export declare class TypeFactory {
4
5
  private cachedObjectTypePropertiesByIdentifier;
5
6
  private cachedObjectTypesByIdentifier;
6
- private readonly dataFactoryVariable;
7
- constructor({ dataFactoryVariable }: {
8
- dataFactoryVariable: string;
9
- });
7
+ private cachedObjectUnionTypesByIdentifier;
8
+ createObjectTypeFromAstType(astType: ast.ObjectType): ObjectType;
10
9
  createTypeFromAstType(astType: ast.Type): Type;
11
- private createObjectTypeFromAstType;
12
10
  private createObjectTypePropertyFromAstProperty;
11
+ private createObjectUnionTypeFromAstType;
13
12
  }
14
13
  //# sourceMappingURL=TypeFactory.d.ts.map