@shaclmate/compiler 2.0.22 → 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
@@ -0,0 +1,152 @@
1
+ import { rdf } from "@tpluscode/rdf-ns-builders";
2
+ import { Maybe } from "purify-ts";
3
+ import { StructureKind } from "ts-morph";
4
+ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
5
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
+ import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
7
+ function fromRdfFunctionDeclarations() {
8
+ const initializers = [];
9
+ const propertySignatures = [];
10
+ const propertiesFromRdfReturnType = [];
11
+ const propertiesFromRdfStatements = [];
12
+ if (this.ownProperties.length > 0 || this.parentObjectTypes.length > 0) {
13
+ propertiesFromRdfStatements.push("// @ts-ignore", `const ${syntheticNamePrefix}objectSet = ${syntheticNamePrefix}objectSetParameter ?? new ${syntheticNamePrefix}RdfjsDatasetObjectSet({ dataset: ${variables.resource}.dataset });`);
14
+ }
15
+ this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
16
+ propertiesFromRdfStatements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource} });`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
17
+ initializers.push(`...${syntheticNamePrefix}super${parentObjectTypeI}`);
18
+ propertiesFromRdfReturnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>>`);
19
+ });
20
+ this.fromRdfType.ifJust((rdfType) => {
21
+ const predicate = rdfjsTermExpression(rdf.type);
22
+ propertiesFromRdfStatements.push(`\
23
+ if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${syntheticNamePrefix}fromRdfType)) {
24
+ return ${variables.resource}.value(${predicate}).chain(actualRdfType => actualRdfType.toIri()).chain((actualRdfType) => purify.Left(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${rdfType.value})\`)));
25
+ }`);
26
+ });
27
+ const propertyFromRdfVariables = {
28
+ context: variables.context,
29
+ languageIn: variables.languageIn,
30
+ objectSet: variables.objectSet,
31
+ resource: variables.resource,
32
+ };
33
+ for (const property of this.properties) {
34
+ const propertyFromRdfStatements = property.fromRdfStatements({
35
+ variables: propertyFromRdfVariables,
36
+ });
37
+ if (propertyFromRdfStatements.length > 0) {
38
+ propertiesFromRdfStatements.push(...propertyFromRdfStatements);
39
+ initializers.push(property.name);
40
+ propertySignatures.push(`${property.name}: ${property.type.name};`);
41
+ }
42
+ }
43
+ propertiesFromRdfStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
44
+ if (propertySignatures.length > 0) {
45
+ propertiesFromRdfReturnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
46
+ }
47
+ const functionDeclarations = [];
48
+ functionDeclarations.push({
49
+ isExported: true,
50
+ kind: StructureKind.Function,
51
+ name: `${syntheticNamePrefix}propertiesFromRdf`,
52
+ parameters: [
53
+ {
54
+ name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, objectSet: ${syntheticNamePrefix}objectSetParameter, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
55
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet; resource: rdfjsResource.Resource; }`,
56
+ },
57
+ ],
58
+ returnType: `purify.Either<Error, ${propertiesFromRdfReturnType.join(" & ")}>`,
59
+ statements: propertiesFromRdfStatements,
60
+ });
61
+ const fromRdfStatements = [];
62
+ let fromRdfReturnStatement;
63
+ if (this.abstract) {
64
+ if (this.childObjectTypes.length > 0) {
65
+ // Can't ignore the RDF type if we're doing a union.
66
+ fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
67
+ // Similar to an object union type, alt-chain the fromRdf of the different concrete subclasses together
68
+ fromRdfReturnStatement = `return ${this.childObjectTypes.reduce((expression, childObjectType) => {
69
+ const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
70
+ return expression.length > 0
71
+ ? `${expression}.altLazy(() => ${childObjectTypeExpression})`
72
+ : childObjectTypeExpression;
73
+ }, "")};`;
74
+ }
75
+ }
76
+ else {
77
+ let propertiesFromRdfExpression;
78
+ switch (this.declarationType) {
79
+ case "class":
80
+ propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters).map(properties => new ${this.name}(properties))`;
81
+ break;
82
+ case "interface":
83
+ propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters)`;
84
+ break;
85
+ }
86
+ if (this.childObjectTypes.length > 0) {
87
+ // Can't ignore the RDF type if we're trying the child object type.
88
+ fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
89
+ fromRdfReturnStatement = `${this.childObjectTypes.reduce((expression, childObjectType) => {
90
+ const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
91
+ return expression.length > 0
92
+ ? `${expression}.altLazy(() => ${childObjectTypeExpression})`
93
+ : childObjectTypeExpression;
94
+ }, "")}.altLazy(() => ${propertiesFromRdfExpression})`;
95
+ }
96
+ else {
97
+ fromRdfReturnStatement = propertiesFromRdfExpression;
98
+ }
99
+ fromRdfReturnStatement = `return ${fromRdfReturnStatement};`;
100
+ }
101
+ if (fromRdfReturnStatement) {
102
+ fromRdfStatements.push(fromRdfReturnStatement);
103
+ }
104
+ if (fromRdfStatements.length > 0) {
105
+ functionDeclarations.push({
106
+ isExported: true,
107
+ kind: StructureKind.Function,
108
+ name: `${syntheticNamePrefix}fromRdf`,
109
+ parameters: [
110
+ {
111
+ name: "parameters",
112
+ type: `Parameters<typeof ${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>[0]`,
113
+ },
114
+ ],
115
+ returnType: `purify.Either<Error, ${this.name}>`,
116
+ statements: fromRdfStatements,
117
+ });
118
+ }
119
+ return functionDeclarations;
120
+ }
121
+ export function rdfFunctionDeclarations() {
122
+ if (!this.features.has("rdf")) {
123
+ return [];
124
+ }
125
+ if (this.extern) {
126
+ return [];
127
+ }
128
+ return [
129
+ ...fromRdfFunctionDeclarations.bind(this)(),
130
+ ...toRdfFunctionDeclaration.bind(this)().toList(),
131
+ ];
132
+ }
133
+ function toRdfFunctionDeclaration() {
134
+ if (this.declarationType !== "interface") {
135
+ return Maybe.empty();
136
+ }
137
+ return toRdfFunctionOrMethodDeclaration
138
+ .bind(this)()
139
+ .map((toRdfFunctionOrMethodDeclaration) => ({
140
+ ...toRdfFunctionOrMethodDeclaration,
141
+ isExported: true,
142
+ kind: StructureKind.Function,
143
+ }));
144
+ }
145
+ const variables = {
146
+ context: `${syntheticNamePrefix}context`,
147
+ ignoreRdfType: `${syntheticNamePrefix}ignoreRdfType`,
148
+ languageIn: `${syntheticNamePrefix}languageIn`,
149
+ objectSet: `${syntheticNamePrefix}objectSet`,
150
+ resource: `${syntheticNamePrefix}resource`,
151
+ };
152
+ //# sourceMappingURL=rdfFunctionDeclarations.js.map
@@ -1,5 +1,5 @@
1
1
  import { type FunctionDeclarationStructure } from "ts-morph";
2
2
  export declare function sparqlConstructQueryFunctionDeclaration(this: {
3
- readonly name: string;
3
+ readonly staticModuleName: string;
4
4
  }): FunctionDeclarationStructure;
5
5
  //# sourceMappingURL=sparqlConstructQueryFunctionDeclaration.d.ts.map
@@ -1,9 +1,10 @@
1
1
  import { StructureKind } from "ts-morph";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
2
3
  export function sparqlConstructQueryFunctionDeclaration() {
3
4
  return {
4
- isExported: true,
5
5
  kind: StructureKind.Function,
6
- name: "sparqlConstructQuery",
6
+ isExported: true,
7
+ name: `${syntheticNamePrefix}sparqlConstructQuery`,
7
8
  parameters: [
8
9
  {
9
10
  hasQuestionToken: true,
@@ -14,7 +15,7 @@ export function sparqlConstructQueryFunctionDeclaration() {
14
15
  returnType: "sparqljs.ConstructQuery",
15
16
  statements: [
16
17
  "const { ignoreRdfType, subject, ...queryParameters } = parameters ?? {}",
17
- `return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.name}.sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.name}.sparqlWherePatterns({ ignoreRdfType, subject })) };`,
18
+ `return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType, subject })) };`,
18
19
  ],
19
20
  };
20
21
  }
@@ -1,5 +1,5 @@
1
1
  import { type FunctionDeclarationStructure } from "ts-morph";
2
2
  export declare function sparqlConstructQueryStringFunctionDeclaration(this: {
3
- readonly name: string;
3
+ readonly staticModuleName: string;
4
4
  }): FunctionDeclarationStructure;
5
5
  //# sourceMappingURL=sparqlConstructQueryStringFunctionDeclaration.d.ts.map
@@ -1,9 +1,10 @@
1
1
  import { StructureKind } from "ts-morph";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
2
3
  export function sparqlConstructQueryStringFunctionDeclaration() {
3
4
  return {
4
5
  isExported: true,
5
6
  kind: StructureKind.Function,
6
- name: "sparqlConstructQueryString",
7
+ name: `${syntheticNamePrefix}sparqlConstructQueryString`,
7
8
  parameters: [
8
9
  {
9
10
  hasQuestionToken: true,
@@ -13,7 +14,7 @@ export function sparqlConstructQueryStringFunctionDeclaration() {
13
14
  ],
14
15
  returnType: "string",
15
16
  statements: [
16
- `return new sparqljs.Generator(parameters).stringify(${this.name}.sparqlConstructQuery(parameters));`,
17
+ `return new sparqljs.Generator(parameters).stringify(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructQuery(parameters));`,
17
18
  ],
18
19
  };
19
20
  }
@@ -1,6 +1,8 @@
1
- import { rdf } from "@tpluscode/rdf-ns-builders";
2
1
  import { camelCase } from "change-case";
3
2
  import { StructureKind } from "ts-morph";
3
+ import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
4
+ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
5
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
6
  import { sparqlConstructQueryFunctionDeclaration } from "./sparqlConstructQueryFunctionDeclaration.js";
5
7
  import { sparqlConstructQueryStringFunctionDeclaration } from "./sparqlConstructQueryStringFunctionDeclaration.js";
6
8
  export function sparqlFunctionDeclarations() {
@@ -11,67 +13,133 @@ export function sparqlFunctionDeclarations() {
11
13
  return [];
12
14
  }
13
15
  const variables = { subject: "subject", variablePrefix: "variablePrefix" };
14
- const rdfTypeVariable = `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
16
+ const rdfClassVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
17
+ const rdfTypeVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
15
18
  const subjectDefault = camelCase(this.name);
16
- const preambleStatements = [
17
- `const subject = parameters?.subject ?? ${this.dataFactoryVariable}.variable!("${subjectDefault}");`,
19
+ const sparqlConstructTemplateTriplesStatements = [
20
+ `const subject = parameters?.subject ?? dataFactory.variable!("${subjectDefault}");`,
21
+ "const triples: sparqljs.Triple[] = []",
18
22
  `const variablePrefix = parameters?.variablePrefix ?? (subject.termType === "Variable" ? subject.value : "${subjectDefault}");`,
19
23
  ];
20
- const sparqlConstructTemplateTriples = [
21
- ...this.parentObjectTypes.map((parentObjectType) => `...${parentObjectType.name}.sparqlConstructTemplateTriples({ ignoreRdfType: true, subject, variablePrefix })`),
22
- ...(this.fromRdfType.isJust()
23
- ? [
24
- `...(parameters?.ignoreRdfType ? [] : [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }])`,
25
- ]
26
- : []),
27
- ...this.ownProperties.flatMap((property) => property.sparqlConstructTemplateTriples({ variables })),
28
- ];
29
- const sparqlWherePatterns = [
30
- ...this.parentObjectTypes.map((parentObjectType) => `...${parentObjectType.name}.sparqlWherePatterns({ ignoreRdfType: true, subject, variablePrefix })`),
31
- ...(this.fromRdfType.isJust()
32
- ? [
33
- `...(parameters?.ignoreRdfType ? [] : [{ triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${this.rdfjsTermExpression(this.fromRdfType.unsafeCoerce())} }], type: "bgp" as const }, { triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }], type: "bgp" as const }])`,
34
- ]
35
- : []),
36
- ...this.ownProperties.flatMap((property) => property.sparqlWherePatterns({ variables })),
24
+ let nop = true;
25
+ const sparqlWherePatternsStatements = [
26
+ "const optionalPatterns: sparqljs.OptionalPattern[] = [];",
27
+ "const requiredPatterns: sparqljs.Pattern[] = [];",
28
+ `const subject = parameters?.subject ?? dataFactory.variable!("${subjectDefault}");`,
29
+ `const variablePrefix = parameters?.variablePrefix ?? (subject.termType === "Variable" ? subject.value : "${subjectDefault}");`,
37
30
  ];
31
+ for (const parentObjectType of this.parentObjectTypes) {
32
+ sparqlConstructTemplateTriplesStatements.push(`triples.push(...${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType: true, subject, variablePrefix }));`);
33
+ sparqlWherePatternsStatements.push(`\
34
+ for (const pattern of ${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType: true, subject, variablePrefix })) {
35
+ if (pattern.type === "optional") {
36
+ optionalPatterns.push(pattern);
37
+ } else {
38
+ requiredPatterns.push(pattern);
39
+ }
40
+ }`);
41
+ nop = false;
42
+ }
43
+ if (this.fromRdfType.isJust()) {
44
+ sparqlConstructTemplateTriplesStatements.push(`\
45
+ if (!parameters?.ignoreRdfType) {
46
+ triples.push(
47
+ { subject, predicate: ${rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} },
48
+ { subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
49
+ );
50
+ }`);
51
+ sparqlWherePatternsStatements.push(`\
52
+ if (!parameters?.ignoreRdfType) {
53
+ requiredPatterns.push(${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType: ${syntheticNamePrefix}fromRdfType, subject }));
54
+ requiredPatterns.push({
55
+ triples: [
56
+ {
57
+ subject,
58
+ predicate: ${rdfjsTermExpression(rdf.type)},
59
+ object: ${rdfTypeVariable}
60
+ }
61
+ ],
62
+ type: "bgp" as const
63
+ });
64
+ optionalPatterns.push({
65
+ patterns: [
66
+ {
67
+ triples: [
68
+ {
69
+ subject: ${rdfTypeVariable},
70
+ predicate: {
71
+ items: [${rdfjsTermExpression(rdfs.subClassOf)}],
72
+ pathType: "+" as const,
73
+ type: "path" as const
74
+ },
75
+ object: ${rdfClassVariable}
76
+ }
77
+ ],
78
+ type: "bgp" as const
79
+ }
80
+ ],
81
+ type: "optional" as const
82
+ });
83
+ }`);
84
+ nop = false;
85
+ }
86
+ const propertySparqlWherePatterns = [];
87
+ for (const property of this.ownProperties) {
88
+ if (property.recursive) {
89
+ continue;
90
+ }
91
+ for (const triple of property.sparqlConstructTemplateTriples({
92
+ variables,
93
+ })) {
94
+ sparqlConstructTemplateTriplesStatements.push(`triples.push(${triple});`);
95
+ nop = false;
96
+ }
97
+ propertySparqlWherePatterns.push(...property.sparqlWherePatterns({ variables }));
98
+ }
99
+ if (propertySparqlWherePatterns.length > 0) {
100
+ sparqlWherePatternsStatements.push(`\
101
+ const propertyPatterns: readonly sparqljs.Pattern[] = [${propertySparqlWherePatterns.join(", ")}];
102
+ for (const pattern of propertyPatterns) {
103
+ if (pattern.type === "optional") {
104
+ optionalPatterns.push(pattern);
105
+ } else {
106
+ requiredPatterns.push(pattern);
107
+ }
108
+ }`);
109
+ nop = false;
110
+ }
111
+ sparqlConstructTemplateTriplesStatements.push("return triples;");
112
+ sparqlWherePatternsStatements.push("return requiredPatterns.concat(optionalPatterns);");
38
113
  return [
39
114
  sparqlConstructQueryFunctionDeclaration.bind(this)(),
40
115
  sparqlConstructQueryStringFunctionDeclaration.bind(this)(),
41
116
  {
42
117
  isExported: true,
43
118
  kind: StructureKind.Function,
44
- name: "sparqlConstructTemplateTriples",
119
+ name: `${syntheticNamePrefix}sparqlConstructTemplateTriples`,
45
120
  parameters: [
46
121
  {
47
122
  hasQuestionToken: true,
48
- name: `${sparqlConstructTemplateTriples.length === 0 ? "_" : ""}parameters`,
123
+ name: `${nop ? "_" : ""}parameters`,
49
124
  type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
50
125
  },
51
126
  ],
52
127
  returnType: "readonly sparqljs.Triple[]",
53
- statements: [
54
- ...(sparqlConstructTemplateTriples.length > 0
55
- ? preambleStatements
56
- : []),
57
- `return [${sparqlConstructTemplateTriples.join(", ")}];`,
58
- ],
128
+ statements: nop ? "return [];" : sparqlConstructTemplateTriplesStatements,
59
129
  },
60
130
  {
61
131
  isExported: true,
62
132
  kind: StructureKind.Function,
63
- name: "sparqlWherePatterns",
133
+ name: `${syntheticNamePrefix}sparqlWherePatterns`,
64
134
  parameters: [
65
135
  {
66
- name: `${sparqlWherePatterns.length === 0 ? "_" : ""}parameters`,
136
+ hasQuestionToken: true,
137
+ name: `${nop ? "_" : ""}parameters`,
67
138
  type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
68
139
  },
69
140
  ],
70
141
  returnType: "readonly sparqljs.Pattern[]",
71
- statements: [
72
- ...(sparqlWherePatterns.length > 0 ? preambleStatements : []),
73
- `return [${sparqlWherePatterns.join(", ")}];`,
74
- ],
142
+ statements: nop ? "return [];" : sparqlWherePatternsStatements,
75
143
  },
76
144
  ];
77
145
  }
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
- import { toJsonReturnType } from "./toJsonReturnType.js";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
3
3
  export function toJsonFunctionOrMethodDeclaration() {
4
- if (!this.features.has("toJson")) {
4
+ if (!this.features.has("json")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  if (this.declarationType === "class" &&
@@ -14,12 +14,12 @@ export function toJsonFunctionOrMethodDeclaration() {
14
14
  switch (this.declarationType) {
15
15
  case "class":
16
16
  if (this.parentObjectTypes.length > 0) {
17
- jsonObjectMembers.push("...super.toJson()");
17
+ jsonObjectMembers.push(`...super.${syntheticNamePrefix}toJson()`);
18
18
  }
19
19
  break;
20
20
  case "interface":
21
21
  for (const parentObjectType of this.parentObjectTypes) {
22
- jsonObjectMembers.push(`...${parentObjectType.name}.toJson(${this.thisVariable})`);
22
+ jsonObjectMembers.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`);
23
23
  }
24
24
  parameters.push({
25
25
  name: this.thisVariable,
@@ -48,9 +48,9 @@ export function toJsonFunctionOrMethodDeclaration() {
48
48
  // break;
49
49
  // }
50
50
  return Maybe.of({
51
- name: "toJson",
51
+ name: `${syntheticNamePrefix}toJson`,
52
52
  parameters,
53
- returnType: toJsonReturnType.bind(this)(),
53
+ returnType: this.jsonName.toString(),
54
54
  statements: [
55
55
  `return JSON.parse(JSON.stringify({ ${jsonObjectMembers.join(",")} } satisfies ${this.jsonName}));`,
56
56
  ],
@@ -1,13 +1,9 @@
1
- import { rdf } from "@tpluscode/rdf-ns-builders";
2
1
  import { Maybe } from "purify-ts";
3
- const variables = {
4
- ignoreRdfType: "ignoreRdfType",
5
- mutateGraph: "mutateGraph",
6
- resource: "_resource",
7
- resourceSet: "resourceSet",
8
- };
2
+ import { rdf } from "@tpluscode/rdf-ns-builders";
3
+ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
9
5
  export function toRdfFunctionOrMethodDeclaration() {
10
- if (!this.features.has("toRdf")) {
6
+ if (!this.features.has("rdf")) {
11
7
  return Maybe.empty();
12
8
  }
13
9
  this.ensureAtMostOneSuperObjectType();
@@ -18,10 +14,10 @@ export function toRdfFunctionOrMethodDeclaration() {
18
14
  let superToRdfCall;
19
15
  switch (this.declarationType) {
20
16
  case "class":
21
- superToRdfCall = `super.toRdf(${superToRdfOptions})`;
17
+ superToRdfCall = `super.${syntheticNamePrefix}toRdf(${superToRdfOptions})`;
22
18
  break;
23
19
  case "interface":
24
- superToRdfCall = `${this.parentObjectTypes[0].name}.toRdf(${this.thisVariable}, ${superToRdfOptions})`;
20
+ superToRdfCall = `${this.parentObjectTypes[0].staticModuleName}.${syntheticNamePrefix}toRdf(${this.thisVariable}, ${superToRdfOptions})`;
25
21
  break;
26
22
  }
27
23
  statements.push(`const ${variables.resource} = ${superToRdfCall};`);
@@ -34,7 +30,7 @@ export function toRdfFunctionOrMethodDeclaration() {
34
30
  statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource(${this.thisVariable}.${this.identifierProperty.name}, { ${variables.mutateGraph} });`);
35
31
  }
36
32
  if (this.toRdfTypes.length > 0) {
37
- statements.push(`if (!${variables.ignoreRdfType}) { ${this.toRdfTypes.map((toRdfType) => `${variables.resource}.add(${variables.resource}.dataFactory.namedNode("${rdf.type.value}"), ${variables.resource}.dataFactory.namedNode("${toRdfType.value}"));`).join(" ")} }`);
33
+ statements.push(`if (!${variables.ignoreRdfType}) { ${this.toRdfTypes.map((toRdfType) => `${variables.resource}.add(${rdfjsTermExpression(rdf.type)}, ${variables.resource}.dataFactory.namedNode("${toRdfType.value}"));`).join(" ")} }`);
38
34
  usedIgnoreRdfTypeVariable = true;
39
35
  }
40
36
  for (const property of this.properties) {
@@ -58,10 +54,16 @@ export function toRdfFunctionOrMethodDeclaration() {
58
54
  type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
59
55
  });
60
56
  return Maybe.of({
61
- name: "toRdf",
57
+ name: `${syntheticNamePrefix}toRdf`,
62
58
  parameters,
63
- returnType: this.rdfjsResourceType({ mutable: true }).name,
59
+ returnType: this.toRdfjsResourceType,
64
60
  statements,
65
61
  });
66
62
  }
63
+ const variables = {
64
+ ignoreRdfType: "ignoreRdfType",
65
+ mutateGraph: "mutateGraph",
66
+ resource: "_resource",
67
+ resourceSet: "resourceSet",
68
+ };
67
69
  //# sourceMappingURL=toRdfFunctionOrMethodDeclaration.js.map
@@ -0,0 +1,9 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { OptionalKind, VariableStatementStructure } from "ts-morph";
3
+ import type { ObjectType } from "./ObjectType.js";
4
+ import type { ObjectUnionType } from "./ObjectUnionType.js";
5
+ export declare function graphqlSchemaVariableStatement(parameters: {
6
+ objectTypes: readonly ObjectType[];
7
+ objectUnionTypes: ObjectUnionType[];
8
+ }): Maybe<OptionalKind<VariableStatementStructure>>;
9
+ //# sourceMappingURL=graphqlSchemaVariableStatement.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { objectInitializer } from "./objectInitializer.js";
3
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
+ function graphqlQueryObjectType({ objectTypes, objectUnionTypes, }) {
5
+ return `new graphql.GraphQLObjectType<null, { objectSet: ${syntheticNamePrefix}ObjectSet }>({ name: "Query", fields: ${objectInitializer([...objectTypes, ...objectUnionTypes].reduce((fields, objectType) => {
6
+ fields[objectType.objectSetMethodNames.object] = objectInitializer({
7
+ args: objectInitializer({
8
+ identifier: objectInitializer({
9
+ type: "new graphql.GraphQLNonNull(graphql.GraphQLID)",
10
+ }),
11
+ }),
12
+ resolve: `\
13
+ async (_source, args: { identifier: string }, { objectSet }): Promise<${objectType.name}> =>
14
+ (await purify.EitherAsync<Error, ${objectType.name}>(async ({ liftEither }) =>
15
+ liftEither(await objectSet.${objectType.objectSetMethodNames.object}(await liftEither(${objectType.identifierTypeAlias}.fromString(args.identifier))))
16
+ )).unsafeCoerce()`,
17
+ type: objectType.graphqlName.toString(),
18
+ });
19
+ fields[objectType.objectSetMethodNames.objectIdentifiers] =
20
+ objectInitializer({
21
+ args: objectInitializer({
22
+ limit: objectInitializer({
23
+ type: "graphql.GraphQLInt",
24
+ }),
25
+ offset: objectInitializer({
26
+ type: "graphql.GraphQLInt",
27
+ }),
28
+ }),
29
+ resolve: `\
30
+ async (_source, args: { limit: number | null; offset: number | null; }, { objectSet }): Promise<readonly string[]> =>
31
+ (await objectSet.${objectType.objectSetMethodNames.objectIdentifiers}({ limit: args.limit !== null ? args.limit : undefined, offset: args.offset !== null ? args.offset : undefined })).unsafeCoerce().map(${objectType.identifierTypeAlias}.toString)`,
32
+ type: "new graphql.GraphQLNonNull(new graphql.GraphQLList(graphql.GraphQLString))",
33
+ });
34
+ fields[objectType.objectSetMethodNames.objects] = objectInitializer({
35
+ args: objectInitializer({
36
+ identifiers: objectInitializer({
37
+ type: "new graphql.GraphQLList(new graphql.GraphQLNonNull(graphql.GraphQLID))",
38
+ }),
39
+ limit: objectInitializer({
40
+ type: "graphql.GraphQLInt",
41
+ }),
42
+ offset: objectInitializer({
43
+ type: "graphql.GraphQLInt",
44
+ }),
45
+ }),
46
+ resolve: `\
47
+ async (_source, args: { identifiers: readonly string[] | null; limit: number | null; offset: number | null; }, { objectSet }): Promise<readonly ${objectType.name}[]> =>
48
+ (await purify.EitherAsync<Error, readonly ${objectType.name}[]>(async ({ liftEither }) => {
49
+ let where: $ObjectSet.Where<${objectType.identifierTypeAlias}> | undefined;
50
+ if (args.identifiers) {
51
+ const identifiers: ${objectType.identifierTypeAlias}[] = [];
52
+ for (const identifierArg of args.identifiers) {
53
+ identifiers.push(await liftEither(${objectType.identifierTypeAlias}.fromString(identifierArg)));
54
+ }
55
+ where = { identifiers, type: "identifiers" };
56
+ }
57
+ return await liftEither(await objectSet.${objectType.objectSetMethodNames.objects}({ limit: args.limit !== null ? args.limit : undefined, offset: args.offset !== null ? args.offset : undefined, where }));
58
+ })).unsafeCoerce()`,
59
+ type: `new graphql.GraphQLNonNull(new graphql.GraphQLList(${objectType.graphqlName}))`,
60
+ });
61
+ fields[objectType.objectSetMethodNames.objectsCount] =
62
+ objectInitializer({
63
+ resolve: `\
64
+ async (_source, _args, { objectSet }): Promise<number> => (await objectSet.${objectType.objectSetMethodNames.objectsCount}()).unsafeCoerce()`,
65
+ type: "new graphql.GraphQLNonNull(graphql.GraphQLInt)",
66
+ });
67
+ return fields;
68
+ }, {}))} })`;
69
+ }
70
+ export function graphqlSchemaVariableStatement(parameters) {
71
+ const objectTypes = parameters.objectTypes.filter((objectType) => objectType.features.has("graphql") && !objectType.synthetic);
72
+ const objectUnionTypes = parameters.objectUnionTypes.filter((objectUnionType) => objectUnionType.features.has("graphql"));
73
+ if (objectTypes.length === 0) {
74
+ return Maybe.empty();
75
+ }
76
+ return Maybe.of({
77
+ isExported: true,
78
+ declarations: [
79
+ {
80
+ name: "graphqlSchema",
81
+ initializer: `new graphql.GraphQLSchema({ query: ${graphqlQueryObjectType({ objectTypes, objectUnionTypes })} })`,
82
+ },
83
+ ],
84
+ });
85
+ }
86
+ //# sourceMappingURL=graphqlSchemaVariableStatement.js.map
@@ -0,0 +1,8 @@
1
+ import type { ClassDeclarationStructure, InterfaceDeclarationStructure, ModuleDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "./ObjectType.js";
3
+ import type { ObjectUnionType } from "./ObjectUnionType.js";
4
+ export declare function objectSetDeclarations({ objectUnionTypes, ...parameters }: {
5
+ objectTypes: readonly ObjectType[];
6
+ objectUnionTypes: readonly ObjectUnionType[];
7
+ }): readonly (ClassDeclarationStructure | InterfaceDeclarationStructure | ModuleDeclarationStructure)[];
8
+ //# sourceMappingURL=objectSetDeclarations.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { objectSetInterfaceDeclaration } from "./objectSetInterfaceDeclaration.js";
2
+ import { rdfjsDatasetObjectSetClassDeclaration } from "./rdfjsDatasetObjectSetClassDeclaration.js";
3
+ import { sparqlObjectSetClassDeclaration } from "./sparqlObjectSetClassDeclaration.js";
4
+ export function objectSetDeclarations({ objectUnionTypes, ...parameters }) {
5
+ const objectTypes = parameters.objectTypes.filter((objectType) => !objectType.abstract && !objectType.extern && !objectType.synthetic);
6
+ let objectTypesWithRdfFeatureCount = 0;
7
+ let objectTypesWithSparqlFeatureCount = 0;
8
+ for (const objectType of objectTypes) {
9
+ if (!objectType.features.has("rdf") && !objectType.features.has("sparql")) {
10
+ continue;
11
+ }
12
+ if (objectType.features.has("rdf")) {
13
+ objectTypesWithRdfFeatureCount++;
14
+ }
15
+ if (objectType.features.has("sparql")) {
16
+ objectTypesWithSparqlFeatureCount++;
17
+ }
18
+ }
19
+ let objectUnionTypesWithRdfFeatureCount = 0;
20
+ let objectUnionTypesWithSparqlFeatureCount = 0;
21
+ for (const objectUnionType of objectUnionTypes) {
22
+ if (!objectUnionType.features.has("rdf") &&
23
+ !objectUnionType.features.has("sparql")) {
24
+ continue;
25
+ }
26
+ if (objectUnionType.features.has("rdf")) {
27
+ objectUnionTypesWithRdfFeatureCount++;
28
+ }
29
+ if (objectUnionType.features.has("sparql")) {
30
+ objectUnionTypesWithSparqlFeatureCount++;
31
+ }
32
+ }
33
+ if (objectTypesWithRdfFeatureCount === 0 &&
34
+ objectTypesWithSparqlFeatureCount === 0 &&
35
+ objectUnionTypesWithRdfFeatureCount === 0 &&
36
+ objectUnionTypesWithSparqlFeatureCount === 0) {
37
+ return [];
38
+ }
39
+ const statements = [
40
+ ...objectSetInterfaceDeclaration({
41
+ objectTypes,
42
+ objectUnionTypes,
43
+ }),
44
+ ];
45
+ if (objectTypesWithRdfFeatureCount > 0) {
46
+ statements.push(rdfjsDatasetObjectSetClassDeclaration({
47
+ objectTypes,
48
+ objectUnionTypes,
49
+ }));
50
+ }
51
+ if (objectTypesWithSparqlFeatureCount > 0) {
52
+ statements.push(...sparqlObjectSetClassDeclaration({
53
+ objectTypes,
54
+ objectUnionTypes,
55
+ }));
56
+ }
57
+ return statements;
58
+ }
59
+ //# sourceMappingURL=objectSetDeclarations.js.map