@shaclmate/compiler 2.0.24 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +1 -1
  2. package/dist/generators/ts/BooleanType.d.ts +2 -1
  3. package/dist/generators/ts/BooleanType.js +9 -4
  4. package/dist/generators/ts/DateTimeType.d.ts +2 -1
  5. package/dist/generators/ts/DateTimeType.js +9 -4
  6. package/dist/generators/ts/IdentifierType.d.ts +1 -6
  7. package/dist/generators/ts/IdentifierType.js +1 -1
  8. package/dist/generators/ts/Import.d.ts +2 -1
  9. package/dist/generators/ts/Import.js +29 -24
  10. package/dist/generators/ts/ListType.js +2 -2
  11. package/dist/generators/ts/LiteralType.d.ts +3 -7
  12. package/dist/generators/ts/LiteralType.js +53 -51
  13. package/dist/generators/ts/NumberType.d.ts +2 -1
  14. package/dist/generators/ts/NumberType.js +9 -4
  15. package/dist/generators/ts/ObjectType.d.ts +2 -0
  16. package/dist/generators/ts/ObjectType.js +14 -3
  17. package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
  18. package/dist/generators/ts/ObjectUnionType.js +7 -4
  19. package/dist/generators/ts/PrimitiveType.d.ts +1 -19
  20. package/dist/generators/ts/PrimitiveType.js +4 -14
  21. package/dist/generators/ts/SnippetDeclarations.d.ts +2 -1
  22. package/dist/generators/ts/SnippetDeclarations.js +28 -1
  23. package/dist/generators/ts/StringType.d.ts +2 -1
  24. package/dist/generators/ts/StringType.js +14 -7
  25. package/dist/generators/ts/TermType.d.ts +12 -1
  26. package/dist/generators/ts/TermType.js +11 -0
  27. package/dist/generators/ts/TsGenerator.js +24 -15
  28. package/dist/generators/ts/Type.d.ts +7 -8
  29. package/dist/generators/ts/Type.js +1 -1
  30. package/dist/generators/ts/TypeFactory.js +3 -2
  31. package/dist/generators/ts/_ObjectType/Property.d.ts +2 -2
  32. package/dist/generators/ts/_ObjectType/ShaclProperty.js +1 -1
  33. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
  34. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +30 -11
  35. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  36. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  37. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +31 -15
  38. package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
  39. package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
  40. package/dist/generators/ts/objectSetDeclarations.js +2 -0
  41. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +21 -14
  42. package/dist/generators/ts/rdfjsTermExpression.js +3 -3
  43. package/dist/input/PropertyPath.d.ts +1 -1
  44. package/package.json +5 -8
@@ -0,0 +1,29 @@
1
+ import { Scope, StructureKind } from "ts-morph";
2
+ import { objectSetMethodSignatures } from "./objectSetMethodSignatures.js";
3
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
+ export function forwardingObjectSetClassDeclaration({ objectTypes, objectUnionTypes, }) {
5
+ const delegateName = `${syntheticNamePrefix}delegate`;
6
+ return {
7
+ getAccessors: [
8
+ {
9
+ isAbstract: true,
10
+ name: delegateName,
11
+ scope: Scope.Protected,
12
+ returnType: `${syntheticNamePrefix}ObjectSet`,
13
+ },
14
+ ],
15
+ implements: [`${syntheticNamePrefix}ObjectSet`],
16
+ isAbstract: true,
17
+ isExported: true,
18
+ kind: StructureKind.Class,
19
+ name: `${syntheticNamePrefix}ForwardingObjectSet`,
20
+ methods: [...objectTypes, ...objectUnionTypes].flatMap((objectType) => Object.values(objectSetMethodSignatures({ objectType })).map((methodSignature) => ({
21
+ ...methodSignature,
22
+ kind: StructureKind.Method,
23
+ statements: [
24
+ `return this.${delegateName}.${methodSignature.name}(${methodSignature.parameters.map((parameter) => parameter.name).join(", ")});`,
25
+ ],
26
+ }))),
27
+ };
28
+ }
29
+ //# sourceMappingURL=forwardingObjectSetClassDeclaration.js.map
@@ -1,3 +1,4 @@
1
+ import { forwardingObjectSetClassDeclaration } from "./forwardingObjectSetClassDeclaration.js";
1
2
  import { objectSetInterfaceDeclaration } from "./objectSetInterfaceDeclaration.js";
2
3
  import { rdfjsDatasetObjectSetClassDeclaration } from "./rdfjsDatasetObjectSetClassDeclaration.js";
3
4
  import { sparqlObjectSetClassDeclaration } from "./sparqlObjectSetClassDeclaration.js";
@@ -41,6 +42,7 @@ export function objectSetDeclarations({ objectUnionTypes, ...parameters }) {
41
42
  objectTypes,
42
43
  objectUnionTypes,
43
44
  }),
45
+ forwardingObjectSetClassDeclaration({ objectTypes, objectUnionTypes }),
44
46
  ];
45
47
  if (objectTypesWithRdfFeatureCount > 0) {
46
48
  statements.push(rdfjsDatasetObjectSetClassDeclaration({
@@ -14,12 +14,13 @@ export function rdfjsDatasetObjectSetClassDeclaration({ objectTypes, objectUnion
14
14
  },
15
15
  };
16
16
  const fromRdfFunctionType = `(resource: rdfjsResource.Resource, options: { objectSet: ${syntheticNamePrefix}ObjectSet }) => purify.Either<Error, ${typeParameters.ObjectT.name}>`;
17
+ const objectTypeType = `{ ${syntheticNamePrefix}fromRdf: ${fromRdfFunctionType}; ${syntheticNamePrefix}fromRdfTypes: readonly rdfjs.NamedNode[] }`;
17
18
  const reusableMethodDeclarations = [];
18
19
  if (objectTypes.length > 0) {
19
20
  const parameters = {
20
21
  objectType: {
21
22
  name: "objectType",
22
- type: `{ ${syntheticNamePrefix}fromRdf: ${fromRdfFunctionType}; ${syntheticNamePrefix}fromRdfType?: rdfjs.NamedNode }`,
23
+ type: objectTypeType,
23
24
  },
24
25
  query: {
25
26
  hasQuestionToken: true,
@@ -93,11 +94,18 @@ if (query?.where) {
93
94
  return purify.Either.of(objects);
94
95
  }
95
96
 
96
- if (!objectType.${syntheticNamePrefix}fromRdfType) {
97
+ if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
97
98
  return purify.Either.of([]);
98
99
  }
99
100
 
100
- const resources = [...this.resourceSet.instancesOf(objectType.${syntheticNamePrefix}fromRdfType)];
101
+ const resources: rdfjsResource.Resource[] = [];
102
+ for (const fromRdfType of objectType.${syntheticNamePrefix}fromRdfTypes) {
103
+ for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
104
+ if (!resources.some(existingResource => existingResource.identifier.equals(resource.identifier))) {
105
+ resources.push(resource);
106
+ }
107
+ }
108
+ }
101
109
  // Sort resources by identifier so limit and offset are deterministic
102
110
  resources.sort((left, right) => left.identifier.value.localeCompare(right.identifier.value));
103
111
 
@@ -138,7 +146,6 @@ return purify.Either.of(objects);
138
146
  });
139
147
  }
140
148
  if (objectUnionTypes.length > 0) {
141
- const objectTypeType = `{ ${syntheticNamePrefix}fromRdf: ${fromRdfFunctionType}; ${syntheticNamePrefix}fromRdfType?: rdfjs.NamedNode }`;
142
149
  const parameters = {
143
150
  objectTypes: {
144
151
  name: "objectTypes",
@@ -226,15 +233,18 @@ if (query?.where) {
226
233
 
227
234
  const resources: { objectType: ${objectTypeType}, resource: rdfjsResource.Resource }[] = [];
228
235
  for (const objectType of objectTypes) {
229
- if (!objectType.${syntheticNamePrefix}fromRdfType) {
236
+ if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
230
237
  continue;
231
238
  }
232
239
 
233
- for (const resource of this.resourceSet.instancesOf(objectType.${syntheticNamePrefix}fromRdfType)) {
234
- resources.push({ objectType, resource });
240
+ for (const fromRdfType of objectType.${syntheticNamePrefix}fromRdfTypes) {
241
+ for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
242
+ if (!resources.some(({ resource: existingResource }) => existingResource.identifier.equals(resource.identifier))) {
243
+ resources.push({ objectType, resource });
244
+ }
245
+ }
235
246
  }
236
247
  }
237
-
238
248
  // Sort resources by identifier so limit and offset are deterministic
239
249
  resources.sort((left, right) => left.resource.identifier.value.localeCompare(right.resource.identifier.value));
240
250
 
@@ -300,16 +310,13 @@ return purify.Either.of(objects);
300
310
  }
301
311
  const methodSignatures = objectSetMethodSignatures({ objectType });
302
312
  let runtimeObjectType;
313
+ const runtimeObjectType_ = (objectType) => `{ ${syntheticNamePrefix}fromRdf: ${objectType.staticModuleName}.${syntheticNamePrefix}fromRdf, ${syntheticNamePrefix}fromRdfTypes: [${objectType.fromRdfTypeVariable.toList().concat(objectType.descendantFromRdfTypeVariables).join(", ")}] }`;
303
314
  switch (objectType.kind) {
304
315
  case "ObjectType":
305
- runtimeObjectType = objectType.fromRdfType.isJust()
306
- ? `${objectType.staticModuleName}`
307
- : `{ ...${objectType.staticModuleName}, ${syntheticNamePrefix}fromRdfType: undefined }`;
316
+ runtimeObjectType = runtimeObjectType_(objectType);
308
317
  break;
309
318
  case "ObjectUnionType":
310
- runtimeObjectType = `[${objectType.memberTypes.map((memberType) => memberType.fromRdfType.isJust()
311
- ? `${memberType.staticModuleName}`
312
- : `{ ...${memberType.staticModuleName}, ${syntheticNamePrefix}fromRdfType: undefined }`)}]`;
319
+ runtimeObjectType = `[${objectType.memberTypes.map((memberType) => runtimeObjectType_(memberType)).join(", ")}]`;
313
320
  break;
314
321
  }
315
322
  return [
@@ -8,11 +8,11 @@ export function rdfjsTermExpression(rdfjsTerm) {
8
8
  case "Literal":
9
9
  if (rdfjsTerm.datatype.equals(xsd.string)) {
10
10
  if (rdfjsTerm.language.length === 0) {
11
- return `dataFactory.literal("${rdfjsTerm.value}")`;
11
+ return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)})`;
12
12
  }
13
- return `dataFactory.literal("${rdfjsTerm.value}", "${rdfjsTerm.language}")`;
13
+ return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)}, "${rdfjsTerm.language}")`;
14
14
  }
15
- return `dataFactory.literal("${rdfjsTerm.value}", ${rdfjsTermExpression(rdfjsTerm.datatype)})`;
15
+ return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)}, ${rdfjsTermExpression(rdfjsTerm.datatype)})`;
16
16
  case "NamedNode": {
17
17
  if (rdfjsTerm.value.startsWith(rdf[""].value)) {
18
18
  const unqualifiedName = rdfjsTerm.value.substring(rdf[""].value.length);
@@ -34,7 +34,7 @@ export declare namespace PropertyPath {
34
34
  function $fromRdf(resource: Resource, _?: {
35
35
  [_index: string]: any;
36
36
  ignoreRdfType?: boolean;
37
- languageIn?: readonly string[];
37
+ preferredLanguages?: readonly string[];
38
38
  }): Either<Error, PropertyPath>;
39
39
  function $toRdf(_propertyPath: PropertyPath, _options?: any): Resource;
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "2.0.24",
3
+ "@shaclmate/shacl-ast": "3.0.0",
4
4
  "@rdfjs/prefix-map": "^0.1.2",
5
5
  "@rdfjs/term-map": "^2.0.2",
6
6
  "@rdfjs/term-set": "^2.0.3",
@@ -22,13 +22,10 @@
22
22
  "typescript-memoize": "^1.1.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@shaclmate/kitchen-sink-example": "2.0.24",
26
- "@shaclmate/runtime": "2.0.24",
25
+ "@shaclmate/kitchen-sink-example": "3.0.0",
26
+ "@shaclmate/runtime": "3.0.0",
27
27
  "@kos-kit/sparql-client": "2.0.115",
28
- "@types/n3": "^1.21.1",
29
- "oxigraph": "0.4.11",
30
- "n3": "^1.21.3",
31
- "rdfjs-resource": "1.0.22"
28
+ "oxigraph": "0.4.11"
32
29
  },
33
30
  "exports": {
34
31
  ".": {
@@ -79,5 +76,5 @@
79
76
  "unlink": "npm unlink -g @shaclmate/compiler"
80
77
  },
81
78
  "type": "module",
82
- "version": "2.0.24"
79
+ "version": "3.0.0"
83
80
  }