@shaclmate/compiler 2.0.24 → 3.0.1
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/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +1 -1
- package/dist/generators/ts/BooleanType.d.ts +2 -1
- package/dist/generators/ts/BooleanType.js +9 -4
- package/dist/generators/ts/DateTimeType.d.ts +2 -1
- package/dist/generators/ts/DateTimeType.js +9 -4
- package/dist/generators/ts/IdentifierType.d.ts +1 -6
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/Import.d.ts +2 -1
- package/dist/generators/ts/Import.js +29 -24
- package/dist/generators/ts/ListType.js +2 -2
- package/dist/generators/ts/LiteralType.d.ts +3 -7
- package/dist/generators/ts/LiteralType.js +53 -51
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +9 -4
- package/dist/generators/ts/ObjectType.d.ts +2 -0
- package/dist/generators/ts/ObjectType.js +14 -3
- package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
- package/dist/generators/ts/ObjectUnionType.js +7 -4
- package/dist/generators/ts/PrimitiveType.d.ts +1 -19
- package/dist/generators/ts/PrimitiveType.js +4 -14
- package/dist/generators/ts/SnippetDeclarations.d.ts +2 -1
- package/dist/generators/ts/SnippetDeclarations.js +28 -1
- package/dist/generators/ts/StringType.d.ts +2 -1
- package/dist/generators/ts/StringType.js +14 -7
- package/dist/generators/ts/TermType.d.ts +12 -1
- package/dist/generators/ts/TermType.js +11 -0
- package/dist/generators/ts/TsGenerator.js +24 -15
- package/dist/generators/ts/Type.d.ts +7 -8
- package/dist/generators/ts/Type.js +1 -1
- package/dist/generators/ts/TypeFactory.js +3 -2
- package/dist/generators/ts/_ObjectType/Property.d.ts +2 -2
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +30 -11
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +31 -15
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
- package/dist/generators/ts/objectSetDeclarations.js +2 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +21 -14
- package/dist/generators/ts/rdfjsTermExpression.js +3 -3
- package/dist/input/PropertyPath.d.ts +1 -1
- package/package.json +7 -14
|
@@ -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:
|
|
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 (
|
|
97
|
+
if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
|
|
97
98
|
return purify.Either.of([]);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
const resources = [
|
|
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 (
|
|
236
|
+
if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
|
|
230
237
|
continue;
|
|
231
238
|
}
|
|
232
239
|
|
|
233
|
-
for (const
|
|
234
|
-
|
|
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
|
|
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.
|
|
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(
|
|
11
|
+
return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)})`;
|
|
12
12
|
}
|
|
13
|
-
return `dataFactory.literal(
|
|
13
|
+
return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)}, "${rdfjsTerm.language}")`;
|
|
14
14
|
}
|
|
15
|
-
return `dataFactory.literal(
|
|
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
|
-
|
|
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": "
|
|
3
|
+
"@shaclmate/shacl-ast": "3.0.1",
|
|
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,19 +22,10 @@
|
|
|
22
22
|
"typescript-memoize": "^1.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@shaclmate/kitchen-sink-example": "
|
|
26
|
-
"@shaclmate/runtime": "
|
|
25
|
+
"@shaclmate/kitchen-sink-example": "3.0.1",
|
|
26
|
+
"@shaclmate/runtime": "3.0.1",
|
|
27
27
|
"@kos-kit/sparql-client": "2.0.115",
|
|
28
|
-
"
|
|
29
|
-
"oxigraph": "0.4.11",
|
|
30
|
-
"n3": "^1.21.3",
|
|
31
|
-
"rdfjs-resource": "1.0.22"
|
|
32
|
-
},
|
|
33
|
-
"exports": {
|
|
34
|
-
".": {
|
|
35
|
-
"types": "./dist/index.d.ts",
|
|
36
|
-
"default": "./dist/index.js"
|
|
37
|
-
}
|
|
28
|
+
"oxigraph": "0.4.11"
|
|
38
29
|
},
|
|
39
30
|
"files": [
|
|
40
31
|
"dist/*.d.ts",
|
|
@@ -57,6 +48,7 @@
|
|
|
57
48
|
"dist/input/*.js"
|
|
58
49
|
],
|
|
59
50
|
"license": "Apache-2.0",
|
|
51
|
+
"main": "./dist/index.js",
|
|
60
52
|
"name": "@shaclmate/compiler",
|
|
61
53
|
"packageManager": "npm@10.9.0",
|
|
62
54
|
"repository": {
|
|
@@ -79,5 +71,6 @@
|
|
|
79
71
|
"unlink": "npm unlink -g @shaclmate/compiler"
|
|
80
72
|
},
|
|
81
73
|
"type": "module",
|
|
82
|
-
"
|
|
74
|
+
"types": "./dist/index.d.ts",
|
|
75
|
+
"version": "3.0.1"
|
|
83
76
|
}
|