@shaclmate/compiler 4.0.30 → 4.0.31
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/generators/ts/AbstractTermType.js +2 -1
- package/dist/generators/ts/AbstractType.d.ts +1 -0
- package/dist/generators/ts/AbstractUnionType.d.ts +3 -0
- package/dist/generators/ts/AbstractUnionType.js +20 -9
- package/dist/generators/ts/ListType.js +1 -1
- package/dist/generators/ts/NamedObjectType.js +2 -3
- package/dist/generators/ts/NamedObjectUnionType.js +2 -2
- package/dist/generators/ts/Snippets.d.ts +4 -1
- package/dist/generators/ts/Snippets.js +28 -7
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +3 -3
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +15 -21
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +1 -1
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +4 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +22 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +83 -7
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js +14 -20
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +3 -3
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +4 -4
- package/dist/generators/ts/_snippets/snippets_ToRdfResourceFunction.js +8 -2
- package/dist/generators/ts/_snippets/snippets__FromRdfResourceFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets__FromRdfResourceFunction.js +13 -0
- package/dist/generators/ts/_snippets/snippets__ToRdfResourceFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets__ToRdfResourceFunction.js +12 -0
- package/dist/generators/ts/_snippets/snippets_wrap_FromRdfResourceFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_wrap_FromRdfResourceFunction.js +10 -0
- package/dist/generators/ts/_snippets/snippets_wrap_ToRdfResourceFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_wrap_ToRdfResourceFunction.js +14 -0
- package/dist/input/generated.d.ts +34 -116
- package/dist/input/generated.js +385 -437
- package/package.json +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js +0 -38
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +0 -98
- package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.js +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@shaclmate/shacl-ast": "4.0.
|
|
3
|
+
"@shaclmate/shacl-ast": "4.0.31",
|
|
4
4
|
"@rdfjs/dataset": "~2.0.2",
|
|
5
5
|
"@rdfjs/prefix-map": "~0.1.2",
|
|
6
6
|
"@rdfjs/term-map": "~2.0.2",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
},
|
|
69
69
|
"type": "module",
|
|
70
70
|
"types": "./dist/index.d.ts",
|
|
71
|
-
"version": "4.0.
|
|
71
|
+
"version": "4.0.31"
|
|
72
72
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Maybe } from "purify-ts";
|
|
2
|
-
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
3
|
-
import { type Code } from "../ts-poet-wrapper.js";
|
|
4
|
-
export declare function NamedObjectType_propertiesFromJsonFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
|
|
5
|
-
//# sourceMappingURL=NamedObjectType_propertiesFromJsonFunctionDeclaration.d.ts.map
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Maybe } from "purify-ts";
|
|
2
|
-
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
|
-
import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
4
|
-
const variables = {
|
|
5
|
-
jsonObject: code `${syntheticNamePrefix}json`,
|
|
6
|
-
};
|
|
7
|
-
export function NamedObjectType_propertiesFromJsonFunctionDeclaration() {
|
|
8
|
-
if (!this.features.has("json")) {
|
|
9
|
-
return Maybe.empty();
|
|
10
|
-
}
|
|
11
|
-
const initializers = [];
|
|
12
|
-
const statements = [];
|
|
13
|
-
const propertyReturnTypeSignatures = [];
|
|
14
|
-
const returnType = [];
|
|
15
|
-
this.parentObjectTypes.forEach((parentObjectType) => {
|
|
16
|
-
initializers.push(code `...${parentObjectType.name}.propertiesFromJson(${variables.jsonObject})`);
|
|
17
|
-
returnType.push(code `ReturnType<typeof ${parentObjectType.name}.propertiesFromJson>`);
|
|
18
|
-
});
|
|
19
|
-
for (const property of this.properties) {
|
|
20
|
-
const propertyFromJsonStatements = property.fromJsonStatements({
|
|
21
|
-
variables,
|
|
22
|
-
});
|
|
23
|
-
if (propertyFromJsonStatements.length > 0) {
|
|
24
|
-
propertyReturnTypeSignatures.push(code `${property.name}: ${property.type.name};`);
|
|
25
|
-
initializers.push(code `${property.name}`);
|
|
26
|
-
statements.push(...propertyFromJsonStatements);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
statements.push(code `return { ${joinCode(initializers, { on: ", " })} };`);
|
|
30
|
-
if (propertyReturnTypeSignatures.length > 0) {
|
|
31
|
-
returnType.splice(0, 0, code `{ ${joinCode(propertyReturnTypeSignatures, { on: " " })} }`);
|
|
32
|
-
}
|
|
33
|
-
return Maybe.of(code `\
|
|
34
|
-
export function propertiesFromJson(${variables.jsonObject}: ${this.jsonType().name}): ${joinCode(returnType, { on: " & " })} {
|
|
35
|
-
${joinCode(statements)}
|
|
36
|
-
}`);
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=NamedObjectType_propertiesFromJsonFunctionDeclaration.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Maybe } from "purify-ts";
|
|
2
|
-
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
3
|
-
import { type Code } from "../ts-poet-wrapper.js";
|
|
4
|
-
export declare function NamedObjectType_propertiesFromRdfResourceFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
|
|
5
|
-
//# sourceMappingURL=NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts.map
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
-
import { Maybe } from "purify-ts";
|
|
3
|
-
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
4
|
-
import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
5
|
-
const optionsVariable = `_${syntheticNamePrefix}options`;
|
|
6
|
-
const variables = {
|
|
7
|
-
context: code `${optionsVariable}.context`,
|
|
8
|
-
graph: code `${optionsVariable}.graph`,
|
|
9
|
-
ignoreRdfType: code `${optionsVariable}.ignoreRdfType`,
|
|
10
|
-
objectSet: code `${optionsVariable}.objectSet`,
|
|
11
|
-
preferredLanguages: code `${optionsVariable}.preferredLanguages`,
|
|
12
|
-
resource: code `${syntheticNamePrefix}resource`,
|
|
13
|
-
};
|
|
14
|
-
export function NamedObjectType_propertiesFromRdfResourceFunctionDeclaration() {
|
|
15
|
-
if (!this.features.has("rdf")) {
|
|
16
|
-
return Maybe.empty();
|
|
17
|
-
}
|
|
18
|
-
const chains = [];
|
|
19
|
-
const initializers = [];
|
|
20
|
-
const propertySignatures = [];
|
|
21
|
-
const returnType = [];
|
|
22
|
-
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
23
|
-
chains.push({
|
|
24
|
-
expression: code `${parentObjectType.name}.propertiesFromRdfResource(${variables.resource}, { ...${optionsVariable}, ignoreRdfType: true })`,
|
|
25
|
-
variable: `${syntheticNamePrefix}super${parentObjectTypeI}`,
|
|
26
|
-
});
|
|
27
|
-
initializers.push(code `...${syntheticNamePrefix}super${parentObjectTypeI}`);
|
|
28
|
-
returnType.push(code `${this.reusables.snippets.UnwrapR}<ReturnType<typeof ${parentObjectType.name}.propertiesFromRdfResource>>`);
|
|
29
|
-
});
|
|
30
|
-
this.fromRdfType.ifJust((fromRdfType) => {
|
|
31
|
-
const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
|
|
32
|
-
const predicate = this.rdfjsTermExpression(rdf.type);
|
|
33
|
-
// Check the expected type and its known subtypes
|
|
34
|
-
const cases = new Set();
|
|
35
|
-
cases.add(fromRdfType.value);
|
|
36
|
-
for (const descendantFromRdfType of this.descendantFromRdfTypes) {
|
|
37
|
-
cases.add(descendantFromRdfType.value);
|
|
38
|
-
}
|
|
39
|
-
chains.push({
|
|
40
|
-
expression: code `!${variables.ignoreRdfType} ? ${variables.resource}.value(${predicate}, ${{ graph: variables.graph }})
|
|
41
|
-
.chain(actualRdfType => actualRdfType.toIri())
|
|
42
|
-
.chain((actualRdfType) => {
|
|
43
|
-
// Check the expected type and its known subtypes
|
|
44
|
-
switch (actualRdfType.value) {
|
|
45
|
-
${[...cases].map((fromRdfType) => `case "${fromRdfType}":`).join("\n")}
|
|
46
|
-
return ${this.reusables.imports.Right}(true as const);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Check arbitrary rdfs:subClassOf's of the expected type
|
|
50
|
-
if (${variables.resource}.isInstanceOf(${fromRdfTypeVariable}, ${{ graph: variables.graph }})) {
|
|
51
|
-
return ${this.reusables.imports.Right}(true as const);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return ${this.reusables.imports.Left}(new Error(\`\${${variables.resource}.identifier} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
|
|
55
|
-
}) : ${this.reusables.imports.Right}(true as const)`,
|
|
56
|
-
variable: "_rdfTypeCheck",
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
const propertyFromRdfVariables = {
|
|
60
|
-
context: variables.context,
|
|
61
|
-
graph: variables.graph,
|
|
62
|
-
preferredLanguages: variables.preferredLanguages,
|
|
63
|
-
objectSet: variables.objectSet,
|
|
64
|
-
resource: variables.resource,
|
|
65
|
-
};
|
|
66
|
-
for (const property of this.properties) {
|
|
67
|
-
property
|
|
68
|
-
.fromRdfResourceValuesExpression({
|
|
69
|
-
variables: propertyFromRdfVariables,
|
|
70
|
-
})
|
|
71
|
-
.ifJust((propertyFromRdfExpression) => {
|
|
72
|
-
chains.push({
|
|
73
|
-
expression: propertyFromRdfExpression,
|
|
74
|
-
variable: property.name,
|
|
75
|
-
});
|
|
76
|
-
initializers.push(code `${property.name}`);
|
|
77
|
-
propertySignatures.push(code `${property.name}: ${property.type.name};`);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
const statements = [];
|
|
81
|
-
const resultExpression = code `{ ${joinCode(initializers, { on: "," })} }`;
|
|
82
|
-
if (chains.length === 0) {
|
|
83
|
-
statements.push(code `return ${this.reusables.imports.Right}(${resultExpression});`);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
statements.push(code `return ${chains
|
|
87
|
-
.reverse()
|
|
88
|
-
.reduce((acc, { expression, variable }, chainI) => code `(${expression}).${chainI === 0 ? "map" : "chain"}(${variable} => ${acc})`, code `(${resultExpression})`)}`);
|
|
89
|
-
}
|
|
90
|
-
if (propertySignatures.length > 0) {
|
|
91
|
-
returnType.splice(0, 0, code `{ ${joinCode(propertySignatures, { on: " " })} }`);
|
|
92
|
-
}
|
|
93
|
-
return Maybe.of(code `\
|
|
94
|
-
export const propertiesFromRdfResource: ${this.reusables.snippets.PropertiesFromRdfResourceFunction}<${joinCode(returnType, { on: " & " })}> = (${syntheticNamePrefix}resource, ${optionsVariable}) => {
|
|
95
|
-
${joinCode(statements)}
|
|
96
|
-
};`);
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
|
-
export const snippets_PropertiesFromRdfResourceFunction = ({ imports, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}PropertiesFromRdfResourceFunction`, code `\
|
|
3
|
-
type ${syntheticNamePrefix}PropertiesFromRdfResourceFunction<T> = (
|
|
4
|
-
resource: ${imports.Resource},
|
|
5
|
-
options: {
|
|
6
|
-
context: undefined | unknown;
|
|
7
|
-
graph: Exclude<${imports.Quad_Graph}, ${imports.Variable}> | undefined;
|
|
8
|
-
ignoreRdfType: boolean;
|
|
9
|
-
objectSet: ${syntheticNamePrefix}ObjectSet;
|
|
10
|
-
preferredLanguages?: readonly string[];
|
|
11
|
-
}
|
|
12
|
-
) => ${imports.Either}<Error, T>;`);
|
|
13
|
-
//# sourceMappingURL=snippets_PropertiesFromRdfResourceFunction.js.map
|