@shaclmate/compiler 4.0.24 → 4.0.26
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/Compiler.d.ts +1 -1
- package/dist/ShapesGraphToAstTransformer.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +5 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +0 -6
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +0 -2
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +14 -32
- package/dist/ast/AbstractCompoundType.d.ts +1 -1
- package/dist/ast/ObjectType.d.ts +3 -23
- package/dist/ast/ObjectType.js +2 -20
- package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
- package/dist/generators/ts/AbstractContainerType.js +0 -1
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +0 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +2 -2
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +1 -2
- package/dist/generators/ts/AbstractNamedUnionType.js +16 -19
- package/dist/generators/ts/AbstractTermType.d.ts +0 -1
- package/dist/generators/ts/AbstractTermType.js +0 -1
- package/dist/generators/ts/AbstractType.d.ts +0 -4
- package/dist/generators/ts/AbstractUnionType.d.ts +1 -10
- package/dist/generators/ts/AbstractUnionType.js +26 -39
- package/dist/generators/ts/LazyObjectOptionType.js +3 -2
- package/dist/generators/ts/LazyObjectSetType.js +2 -1
- package/dist/generators/ts/LazyObjectType.js +2 -1
- package/dist/generators/ts/NamedObjectType.d.ts +2 -13
- package/dist/generators/ts/NamedObjectType.js +33 -104
- package/dist/generators/ts/NamedObjectUnionType.js +13 -24
- package/dist/generators/ts/TsGenerator.js +15 -7
- package/dist/generators/ts/TypeFactory.js +10 -28
- package/dist/generators/ts/ZodGenerator.js +2 -2
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +1 -7
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +1 -6
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +0 -1
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +4 -31
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -17
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +25 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +49 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +0 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.js +8 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +1 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/{NamedObjectType_toJsonFunctionOrMethodDeclaration.js → NamedObjectType_toJsonFunctionDeclaration.js} +5 -27
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/{NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js → NamedObjectType_toRdfResourceFunctionDeclaration.js} +4 -25
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +40 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +6 -28
- package/dist/generators/ts/_snippets/snippets_compactRecord.js +1 -1
- package/dist/generators/ts/objectSetDeclarations.js +1 -3
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +6 -8
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +40 -37
- package/dist/input/ShapesGraph.d.ts +1 -1
- package/dist/input/generated.d.ts +0 -134
- package/dist/input/generated.js +12 -239
- package/package.json +2 -4
- package/dist/enums/TsObjectDeclarationType.d.ts +0 -9
- package/dist/enums/TsObjectDeclarationType.js +0 -16
- package/dist/enums/Visibility.d.ts +0 -6
- package/dist/enums/Visibility.js +0 -18
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +0 -61
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +0 -52
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +0 -77
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +0 -66
- /package/dist/{enums → generators/ts}/TsFeature.d.ts +0 -0
- /package/dist/{enums → generators/ts}/TsFeature.js +0 -0
package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js
CHANGED
|
@@ -7,7 +7,7 @@ export function NamedObjectType_jsonUiSchemaFunctionDeclaration() {
|
|
|
7
7
|
}
|
|
8
8
|
const variables = { scopePrefix: code `scopePrefix` };
|
|
9
9
|
const elements = this.parentObjectTypes
|
|
10
|
-
.map((parentObjectType) => code `${parentObjectType.
|
|
10
|
+
.map((parentObjectType) => code `${parentObjectType.name}.${syntheticNamePrefix}Json.uiSchema({ scopePrefix })`)
|
|
11
11
|
.concat(this.properties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
|
|
12
12
|
return Maybe.of(code `\
|
|
13
13
|
export function uiSchema(parameters?: { scopePrefix?: string }): any {
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { camelCase, trainCase } from "change-case";
|
|
2
2
|
import plur from "plur";
|
|
3
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
4
|
export function NamedObjectType_objectSetMethodNames() {
|
|
4
|
-
const prefixSingular = camelCase(this.name
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const prefixSingular = camelCase(this.name, {
|
|
6
|
+
prefixCharacters: syntheticNamePrefix,
|
|
7
|
+
});
|
|
8
|
+
const thisNameParts = trainCase(this.name, {
|
|
9
|
+
prefixCharacters: syntheticNamePrefix,
|
|
10
|
+
}).split("-");
|
|
11
|
+
let prefixPlural = camelCase(`${thisNameParts.slice(0, thisNameParts.length - 1).join("")}${plur(thisNameParts[thisNameParts.length - 1])}`, { prefixCharacters: syntheticNamePrefix });
|
|
7
12
|
if (prefixPlural === prefixSingular) {
|
|
8
13
|
// Happens with singular-s nouns like "series"
|
|
9
14
|
prefixPlural = `${prefixPlural}s`;
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js
CHANGED
|
@@ -13,8 +13,8 @@ export function NamedObjectType_propertiesFromJsonFunctionDeclaration() {
|
|
|
13
13
|
const propertyReturnTypeSignatures = [];
|
|
14
14
|
const returnType = [];
|
|
15
15
|
this.parentObjectTypes.forEach((parentObjectType) => {
|
|
16
|
-
initializers.push(code `...${parentObjectType.
|
|
17
|
-
returnType.push(code `ReturnType<typeof ${parentObjectType.
|
|
16
|
+
initializers.push(code `...${parentObjectType.name}.${syntheticNamePrefix}propertiesFromJson(${variables.jsonObject})`);
|
|
17
|
+
returnType.push(code `ReturnType<typeof ${parentObjectType.name}.${syntheticNamePrefix}propertiesFromJson>`);
|
|
18
18
|
});
|
|
19
19
|
for (const property of this.properties) {
|
|
20
20
|
const propertyFromJsonStatements = property.fromJsonStatements({
|
|
@@ -24,11 +24,11 @@ export function NamedObjectType_propertiesFromRdfResourceFunctionDeclaration() {
|
|
|
24
24
|
const returnType = [];
|
|
25
25
|
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
26
26
|
chains.push({
|
|
27
|
-
expression: code `${parentObjectType.
|
|
27
|
+
expression: code `${parentObjectType.name}.${syntheticNamePrefix}propertiesFromRdfResource(${variables.resource}, { ...${optionsVariable}, ignoreRdfType: true })`,
|
|
28
28
|
variable: `${syntheticNamePrefix}super${parentObjectTypeI}`,
|
|
29
29
|
});
|
|
30
30
|
initializers.push(code `...${syntheticNamePrefix}super${parentObjectTypeI}`);
|
|
31
|
-
returnType.push(code `${snippets.UnwrapR}<ReturnType<typeof ${parentObjectType.
|
|
31
|
+
returnType.push(code `${snippets.UnwrapR}<ReturnType<typeof ${parentObjectType.name}.${syntheticNamePrefix}propertiesFromRdfResource>>`);
|
|
32
32
|
});
|
|
33
33
|
this.fromRdfType.ifJust((fromRdfType) => {
|
|
34
34
|
const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
|
|
@@ -3,7 +3,7 @@ import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
|
3
3
|
export function NamedObjectType_schemaVariableStatement() {
|
|
4
4
|
return code `\
|
|
5
5
|
export const ${syntheticNamePrefix}schema = { properties: { ${joinCode(this.parentObjectTypes
|
|
6
|
-
.map((parentObjectType) => code `...${parentObjectType.
|
|
6
|
+
.map((parentObjectType) => code `...${parentObjectType.name}.${syntheticNamePrefix}schema.properties`)
|
|
7
7
|
.concat(this.properties.map((property) => code `${property.name}: ${property.schema}`)), { on: ", " })} } } as const;`;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=NamedObjectType_schemaVariableStatement.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import type { TsFeature } from "
|
|
2
|
+
import type { TsFeature } from "../TsFeature.js";
|
|
3
3
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
4
4
|
export declare function NamedObjectType_sparqlConstructQueryFunctionDeclaration(this: {
|
|
5
5
|
readonly features: ReadonlySet<TsFeature>;
|
|
6
6
|
readonly filterType: Code;
|
|
7
7
|
readonly name: string;
|
|
8
|
-
readonly staticModuleName: string;
|
|
9
8
|
}): Maybe<Code>;
|
|
10
9
|
//# sourceMappingURL=NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts.map
|
|
@@ -17,7 +17,7 @@ export function ${syntheticNamePrefix}sparqlConstructQuery({ filter, ignoreRdfTy
|
|
|
17
17
|
prefixes: prefixes ?? {},
|
|
18
18
|
queryType: "CONSTRUCT",
|
|
19
19
|
template: (queryParameters.template ?? []).concat(
|
|
20
|
-
${this.
|
|
20
|
+
${this.name}.${syntheticNamePrefix}focusSparqlConstructTriples({
|
|
21
21
|
filter,
|
|
22
22
|
focusIdentifier: subject,
|
|
23
23
|
ignoreRdfType: !!ignoreRdfType,
|
|
@@ -27,7 +27,7 @@ export function ${syntheticNamePrefix}sparqlConstructQuery({ filter, ignoreRdfTy
|
|
|
27
27
|
type: "query",
|
|
28
28
|
where: (queryParameters.where ?? []).concat(
|
|
29
29
|
${snippets.normalizeSparqlWherePatterns}(
|
|
30
|
-
${this.
|
|
30
|
+
${this.name}.${syntheticNamePrefix}focusSparqlWherePatterns({
|
|
31
31
|
filter,
|
|
32
32
|
focusIdentifier: subject,
|
|
33
33
|
ignoreRdfType: !!ignoreRdfType,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import type { TsFeature } from "
|
|
2
|
+
import type { TsFeature } from "../TsFeature.js";
|
|
3
3
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
4
4
|
export declare function NamedObjectType_sparqlConstructQueryStringFunctionDeclaration(this: {
|
|
5
5
|
readonly features: ReadonlySet<TsFeature>;
|
|
6
6
|
readonly filterType: Code;
|
|
7
|
-
readonly
|
|
7
|
+
readonly name: string;
|
|
8
8
|
}): Maybe<Code>;
|
|
9
9
|
//# sourceMappingURL=NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts.map
|
|
@@ -7,8 +7,8 @@ export function NamedObjectType_sparqlConstructQueryStringFunctionDeclaration()
|
|
|
7
7
|
return Maybe.empty();
|
|
8
8
|
}
|
|
9
9
|
return Maybe.of(code `\
|
|
10
|
-
export function ${syntheticNamePrefix}sparqlConstructQueryString(parameters: Parameters<typeof ${this.
|
|
11
|
-
return new ${imports.sparqljs}.Generator(parameters).stringify(${this.
|
|
10
|
+
export function ${syntheticNamePrefix}sparqlConstructQueryString(parameters: Parameters<typeof ${this.name}.${syntheticNamePrefix}sparqlConstructQuery>[0] & ${imports.sparqljs}.GeneratorOptions): string {
|
|
11
|
+
return new ${imports.sparqljs}.Generator(parameters).stringify(${this.name}.${syntheticNamePrefix}sparqlConstructQuery(parameters));
|
|
12
12
|
}`);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
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_toJsonFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
|
|
5
|
+
//# sourceMappingURL=NamedObjectType_toJsonFunctionDeclaration.d.ts.map
|
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
2
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
3
|
import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
4
|
-
export function
|
|
4
|
+
export function NamedObjectType_toJsonFunctionDeclaration() {
|
|
5
5
|
if (!this.features.has("json")) {
|
|
6
6
|
return Maybe.empty();
|
|
7
7
|
}
|
|
8
|
-
if (this.declarationType === "class" &&
|
|
9
|
-
this.properties.length === 0 &&
|
|
10
|
-
this.parentObjectTypes.length > 0) {
|
|
11
|
-
return Maybe.empty();
|
|
12
|
-
}
|
|
13
8
|
const jsonObjectMembers = [];
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
switch (this.declarationType) {
|
|
17
|
-
case "class":
|
|
18
|
-
if (this.parentObjectTypes.length > 0) {
|
|
19
|
-
jsonObjectMembers.push(code `...super.${syntheticNamePrefix}toJson()`);
|
|
20
|
-
preamble = "override ";
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
preamble = "";
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
case "interface":
|
|
27
|
-
for (const parentObjectType of this.parentObjectTypes) {
|
|
28
|
-
jsonObjectMembers.push(code `...${parentObjectType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`);
|
|
29
|
-
}
|
|
30
|
-
parameters.push(code `${this.thisVariable}: ${this.name}`);
|
|
31
|
-
preamble = "export function ";
|
|
32
|
-
break;
|
|
9
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
10
|
+
jsonObjectMembers.push(code `...${parentObjectType.name}.${syntheticNamePrefix}toJson(${this.thisVariable})`);
|
|
33
11
|
}
|
|
34
12
|
if (this.properties.length > 0) {
|
|
35
13
|
jsonObjectMembers.push(...this.properties.flatMap((property) => property
|
|
@@ -56,8 +34,8 @@ export function NamedObjectType_toJsonFunctionOrMethodDeclaration() {
|
|
|
56
34
|
// break;
|
|
57
35
|
// }
|
|
58
36
|
return Maybe.of(code `\
|
|
59
|
-
${
|
|
37
|
+
export function ${syntheticNamePrefix}toJson(${this.thisVariable}: ${this.name}): ${this.jsonType().name} {
|
|
60
38
|
return JSON.parse(JSON.stringify({ ${joinCode(jsonObjectMembers, { on: "," })} } satisfies ${this.jsonType().name}));
|
|
61
39
|
}`);
|
|
62
40
|
}
|
|
63
|
-
//# sourceMappingURL=
|
|
41
|
+
//# sourceMappingURL=NamedObjectType_toJsonFunctionDeclaration.js.map
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
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_toRdfResourceFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
|
|
5
|
+
//# sourceMappingURL=NamedObjectType_toRdfResourceFunctionDeclaration.d.ts.map
|
|
@@ -5,36 +5,15 @@ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
|
5
5
|
import { snippets } from "../snippets.js";
|
|
6
6
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
7
7
|
import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
8
|
-
export function
|
|
8
|
+
export function NamedObjectType_toRdfResourceFunctionDeclaration() {
|
|
9
9
|
if (!this.features.has("rdf")) {
|
|
10
10
|
return Maybe.empty();
|
|
11
11
|
}
|
|
12
|
-
this.ensureAtMostOneSuperObjectType();
|
|
13
|
-
let preamble = "";
|
|
14
|
-
if (this.declarationType === "interface") {
|
|
15
|
-
preamble = "export function ";
|
|
16
|
-
}
|
|
17
|
-
const parameters = [];
|
|
18
|
-
if (this.declarationType === "interface") {
|
|
19
|
-
parameters.push(code `${this.thisVariable}: ${this.name}`);
|
|
20
|
-
}
|
|
21
|
-
parameters.push(code `options?: Parameters<${snippets.ToRdfResourceFunction}<${this.name}>>[1]`);
|
|
22
12
|
const statements = [
|
|
23
13
|
code `const ${variables.resourceSet} = options?.${variables.resourceSet} ?? new ${imports.ResourceSet}({ dataFactory: ${imports.dataFactory}, dataset: ${imports.datasetFactory}.dataset() });`,
|
|
24
14
|
];
|
|
25
15
|
if (this.parentObjectTypes.length > 0) {
|
|
26
|
-
const
|
|
27
|
-
let superToRdfCall;
|
|
28
|
-
switch (this.declarationType) {
|
|
29
|
-
case "class":
|
|
30
|
-
preamble = "override ";
|
|
31
|
-
superToRdfCall = code `super.${syntheticNamePrefix}toRdfResource(${superToRdfOptions})`;
|
|
32
|
-
break;
|
|
33
|
-
case "interface":
|
|
34
|
-
superToRdfCall = code `${this.parentObjectTypes[0].staticModuleName}.${syntheticNamePrefix}toRdfResource(${this.thisVariable}, ${superToRdfOptions})`;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
statements.push(code `const ${variables.resource} = ${superToRdfCall};`);
|
|
16
|
+
statements.push(code `const ${variables.resource} = ${this.parentObjectTypes[0].name}.${syntheticNamePrefix}toRdfResource(${this.thisVariable}, { ${variables.ignoreRdfType}: true, ${variables.graph}: options?.${variables.graph}, ${variables.resourceSet} });`);
|
|
38
17
|
}
|
|
39
18
|
else {
|
|
40
19
|
statements.push(code `const ${variables.resource} = ${variables.resourceSet}.resource(${this.thisVariable}.${syntheticNamePrefix}identifier());`);
|
|
@@ -56,7 +35,7 @@ export function NamedObjectType_toRdfResourceFunctionOrMethodDeclaration() {
|
|
|
56
35
|
}
|
|
57
36
|
statements.push(code `return ${variables.resource};`);
|
|
58
37
|
return Maybe.of(code `\
|
|
59
|
-
${
|
|
38
|
+
export function ${syntheticNamePrefix}toRdfResource(${this.thisVariable}: ${this.name}, options?: Parameters<${snippets.ToRdfResourceFunction}<${this.name}>>[1]): ${this.toRdfjsResourceType} {
|
|
60
39
|
${joinCode(statements)}
|
|
61
40
|
}`);
|
|
62
41
|
}
|
|
@@ -66,4 +45,4 @@ const variables = {
|
|
|
66
45
|
resource: code `resource`,
|
|
67
46
|
resourceSet: code `resourceSet`,
|
|
68
47
|
};
|
|
69
|
-
//# sourceMappingURL=
|
|
48
|
+
//# sourceMappingURL=NamedObjectType_toRdfResourceFunctionDeclaration.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
2
|
+
import { type Code } from "../ts-poet-wrapper.js";
|
|
3
|
+
export declare function NamedObjectType_toStringFunctionDeclarations(this: NamedObjectType): readonly Code[];
|
|
4
|
+
//# sourceMappingURL=NamedObjectType_toStringFunctionDeclarations.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { snippets } from "../snippets.js";
|
|
2
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
|
+
import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
|
|
4
|
+
export function NamedObjectType_toStringFunctionDeclarations() {
|
|
5
|
+
const propertiesToStringRecordProperties = [];
|
|
6
|
+
if (this.parentObjectTypes.length > 0) {
|
|
7
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
8
|
+
propertiesToStringRecordProperties.push(code `...${parentObjectType.name}.${syntheticNamePrefix}propertiesToStrings(${this.thisVariable})`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (const property of this.properties) {
|
|
12
|
+
property
|
|
13
|
+
.toStringExpression({
|
|
14
|
+
variables: {
|
|
15
|
+
value: property.accessExpression({
|
|
16
|
+
variables: { object: this.thisVariable },
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
.ifJust((propertyToStringExpression) => {
|
|
21
|
+
propertiesToStringRecordProperties.push(code `${literalOf(property.name)}: ${propertyToStringExpression}`);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const propertiesToStringsReturnExpression = code `${snippets.compactRecord}({${joinCode(propertiesToStringRecordProperties, { on: "," })}})`;
|
|
25
|
+
const toStringReturnExpression = (propertiesToStrings) => code `\`${this.name}(\${JSON.stringify(${propertiesToStrings})})\``;
|
|
26
|
+
return [
|
|
27
|
+
// Use overloads to allow the function to be attached to an instance or used freestanding
|
|
28
|
+
code `\
|
|
29
|
+
export function ${syntheticNamePrefix}propertiesToStrings(${this.thisVariable}: ${this.name}): Record<string, string> {
|
|
30
|
+
return ${propertiesToStringsReturnExpression};
|
|
31
|
+
}`,
|
|
32
|
+
code `\
|
|
33
|
+
export function ${syntheticNamePrefix}toString(this: ${this.name}): string;
|
|
34
|
+
export function ${syntheticNamePrefix}toString(${this.thisVariable}: ${this.name}): string;
|
|
35
|
+
export function ${syntheticNamePrefix}toString(this: ${this.name} | undefined, ${this.thisVariable}?: ${this.name}): string {
|
|
36
|
+
return ${toStringReturnExpression(code `${syntheticNamePrefix}propertiesToStrings((${this.thisVariable} ?? this)!)`)};
|
|
37
|
+
}`,
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=NamedObjectType_toStringFunctionDeclarations.js.map
|
|
@@ -8,6 +8,6 @@ export function NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration()
|
|
|
8
8
|
}
|
|
9
9
|
return Maybe.of(code `\
|
|
10
10
|
export const ${syntheticNamePrefix}valueSparqlConstructTriples: ${snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ({ filter, ignoreRdfType, valueVariable, variablePrefix }) =>
|
|
11
|
-
${this.
|
|
11
|
+
${this.name}.${syntheticNamePrefix}focusSparqlConstructTriples({ filter, focusIdentifier: valueVariable, ignoreRdfType, variablePrefix });`);
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js.map
|
|
@@ -9,7 +9,7 @@ export function NamedObjectType_valueSparqlWherePatternsFunctionDeclaration() {
|
|
|
9
9
|
return Maybe.of(code `\
|
|
10
10
|
export const ${syntheticNamePrefix}valueSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ({ filter, ignoreRdfType, preferredLanguages, propertyPatterns, valueVariable, variablePrefix }) =>
|
|
11
11
|
(propertyPatterns as readonly ${snippets.SparqlPattern}[]).concat(
|
|
12
|
-
${this.
|
|
12
|
+
${this.name}.${syntheticNamePrefix}focusSparqlWherePatterns({ filter, focusIdentifier: valueVariable, ignoreRdfType, preferredLanguages, variablePrefix })
|
|
13
13
|
);`);
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js.map
|
|
@@ -47,10 +47,6 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
47
47
|
}
|
|
48
48
|
get declaration() {
|
|
49
49
|
const lhs = [];
|
|
50
|
-
if (this.namedObjectType.declarationType === "class" &&
|
|
51
|
-
this.visibility !== "public") {
|
|
52
|
-
lhs.push(code `${this.visibility}`);
|
|
53
|
-
}
|
|
54
50
|
if (!this.mutable) {
|
|
55
51
|
lhs.push(code `readonly`);
|
|
56
52
|
}
|
|
@@ -62,9 +58,6 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
62
58
|
.orDefault("")}${joinCode(lhs, { on: " " })}: ${this.type.name};`;
|
|
63
59
|
}
|
|
64
60
|
get filterProperty() {
|
|
65
|
-
if (this.visibility !== "public") {
|
|
66
|
-
return Maybe.empty();
|
|
67
|
-
}
|
|
68
61
|
return Maybe.of({
|
|
69
62
|
name: this.name,
|
|
70
63
|
type: this.type.filterType,
|
|
@@ -86,7 +79,7 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
86
79
|
context: "property",
|
|
87
80
|
});
|
|
88
81
|
const meta = {
|
|
89
|
-
|
|
82
|
+
// id: `${this.namedObjectType.name}-${this.name}`, // id's must be unique
|
|
90
83
|
};
|
|
91
84
|
this.comment.alt(this.description).ifJust((description) => {
|
|
92
85
|
meta["description"] = description;
|
|
@@ -124,28 +117,13 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
124
117
|
constructorStatements({ variables, }) {
|
|
125
118
|
const typeConversions = this.type.conversions;
|
|
126
119
|
if (typeConversions.length === 1) {
|
|
127
|
-
|
|
128
|
-
case "class":
|
|
129
|
-
return [code `this.${this.name} = ${variables.parameter};`];
|
|
130
|
-
case "interface":
|
|
131
|
-
return [code `const ${this.name} = ${variables.parameter};`];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
let lhs;
|
|
135
|
-
const statements = [];
|
|
136
|
-
switch (this.namedObjectType.declarationType) {
|
|
137
|
-
case "class":
|
|
138
|
-
lhs = `this.${this.name}`;
|
|
139
|
-
break;
|
|
140
|
-
case "interface":
|
|
141
|
-
lhs = `${this.name}`;
|
|
142
|
-
statements.push(code `let ${this.name}: ${this.type.name};`);
|
|
143
|
-
break;
|
|
120
|
+
return [code `const ${this.name} = ${variables.parameter};`];
|
|
144
121
|
}
|
|
122
|
+
const statements = [code `let ${this.name}: ${this.type.name};`];
|
|
145
123
|
statements.push(joinCode(typeConversions
|
|
146
|
-
.map((conversion) => code `if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${
|
|
124
|
+
.map((conversion) => code `if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${this.name} = ${conversion.conversionExpression(variables.parameter)}; }`)
|
|
147
125
|
// We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
|
|
148
|
-
.concat(code `{ ${
|
|
126
|
+
.concat(code `{ ${this.name} = (${variables.parameter}) satisfies never; }`), { on: " else " }));
|
|
149
127
|
return statements;
|
|
150
128
|
}
|
|
151
129
|
fromJsonStatements({ variables, }) {
|
|
@@ -165,7 +143,7 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
165
143
|
variables: {
|
|
166
144
|
...variables,
|
|
167
145
|
ignoreRdfType: true,
|
|
168
|
-
propertyPath: code `${this.namedObjectType.
|
|
146
|
+
propertyPath: code `${this.namedObjectType.name}.${syntheticNamePrefix}schema.properties.${this.name}.path`,
|
|
169
147
|
resourceValues: code `resourceValues`,
|
|
170
148
|
},
|
|
171
149
|
})})`,
|
|
@@ -6,7 +6,7 @@ export const snippets_compactRecord = conditionalOutput(`${syntheticNamePrefix}c
|
|
|
6
6
|
*/
|
|
7
7
|
function ${syntheticNamePrefix}compactRecord<KeyT extends string, ValueT extends {}>(record: Record<KeyT, ValueT | undefined>): Record<KeyT, ValueT> {
|
|
8
8
|
return \
|
|
9
|
-
Object.entries(record).reduce((definedProperties, [propertyName, propertyValue]) => {
|
|
9
|
+
globalThis.Object.entries(record).reduce((definedProperties, [propertyName, propertyValue]) => {
|
|
10
10
|
if (propertyValue !== undefined) {
|
|
11
11
|
definedProperties[propertyName as KeyT] = propertyValue as ValueT;
|
|
12
12
|
}
|
|
@@ -2,9 +2,7 @@ import { objectSetInterfaceDeclaration } from "./objectSetInterfaceDeclaration.j
|
|
|
2
2
|
import { rdfjsDatasetObjectSetClassDeclaration } from "./rdfjsDatasetObjectSetClassDeclaration.js";
|
|
3
3
|
import { sparqlObjectSetClassDeclaration } from "./sparqlObjectSetClassDeclaration.js";
|
|
4
4
|
export function objectSetDeclarations({ namedObjectUnionTypes, ...parameters }) {
|
|
5
|
-
const namedObjectTypes = parameters.namedObjectTypes.filter((namedObjectType) => !namedObjectType.
|
|
6
|
-
!namedObjectType.extern &&
|
|
7
|
-
!namedObjectType.synthetic);
|
|
5
|
+
const namedObjectTypes = parameters.namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern && !namedObjectType.synthetic);
|
|
8
6
|
let namedObjectTypesWithRdfFeatureCount = 0;
|
|
9
7
|
let namedObjectTypesWithSparqlFeatureCount = 0;
|
|
10
8
|
for (const namedObjectType of namedObjectTypes) {
|
|
@@ -92,22 +92,20 @@ async ${methodSignatures.objects.name}(${methodSignatures.objects.parameters}):
|
|
|
92
92
|
const fromRdfTypes = namedObjectType.fromRdfTypeVariable
|
|
93
93
|
.toList()
|
|
94
94
|
.concat(namedObjectType.descendantFromRdfTypeVariables);
|
|
95
|
-
return code `{ ${syntheticNamePrefix}filter: ${filterFunction}, ${syntheticNamePrefix}fromRdfResource: ${namedObjectType.
|
|
95
|
+
return code `{ ${syntheticNamePrefix}filter: ${filterFunction}, ${syntheticNamePrefix}fromRdfResource: ${namedObjectType.name}.${syntheticNamePrefix}fromRdfResource, ${syntheticNamePrefix}fromRdfTypes: ${fromRdfTypes.length > 0 ? code `[${joinCode(fromRdfTypes, { on: ", " })}]` : "[]"} }`;
|
|
96
96
|
};
|
|
97
97
|
switch (namedObjectType.kind) {
|
|
98
98
|
case "NamedObjectType": {
|
|
99
99
|
return delegatingMethods.concat(code `\
|
|
100
100
|
${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${imports.Either}<Error, readonly ${namedObjectType.name}[]> {
|
|
101
|
-
return this
|
|
101
|
+
return this.#objectsSync<${namedObjectType.name}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType.filterFunction, namedObjectType)}, query);
|
|
102
102
|
}`);
|
|
103
103
|
}
|
|
104
104
|
case "NamedObjectUnionType":
|
|
105
105
|
return delegatingMethods.concat(code `\
|
|
106
106
|
${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${imports.Either}<Error, readonly ${namedObjectType.name}[]> {
|
|
107
|
-
return this
|
|
108
|
-
${joinCode(namedObjectType.members
|
|
109
|
-
.filter((member) => !member.type.abstract)
|
|
110
|
-
.map((member) => runtimeObjectType(namedObjectType.filterFunction, member.type)), { on: ", " })}
|
|
107
|
+
return this.#objectUnionsSync<${namedObjectType.name}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>([
|
|
108
|
+
${joinCode(namedObjectType.members.map((member) => runtimeObjectType(namedObjectType.filterFunction, member.type)), { on: ", " })}
|
|
111
109
|
], query);
|
|
112
110
|
}`);
|
|
113
111
|
default:
|
|
@@ -118,7 +116,7 @@ ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${
|
|
|
118
116
|
...(namedObjectTypes.length > 0
|
|
119
117
|
? [
|
|
120
118
|
code `\
|
|
121
|
-
|
|
119
|
+
#objectsSync<${typeParameters.ObjectT}, ${typeParameters.ObjectFilterT}, ${typeParameters.ObjectIdentifierT}>(namedObjectType: ${namedObjectTypeType}, ${parameters.query}): ${imports.Either}<Error, readonly ObjectT[]> {
|
|
122
120
|
const graph = query?.graph ?? this.${syntheticNamePrefix}graph;
|
|
123
121
|
|
|
124
122
|
const limit = query?.limit ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -210,7 +208,7 @@ protected ${syntheticNamePrefix}objectsSync<${typeParameters.ObjectT}, ${typePar
|
|
|
210
208
|
...(namedObjectUnionTypes.length > 0
|
|
211
209
|
? [
|
|
212
210
|
code `\
|
|
213
|
-
|
|
211
|
+
#objectUnionsSync<${typeParameters.ObjectT}, ${typeParameters.ObjectFilterT}, ${typeParameters.ObjectIdentifierT}>(namedObjectTypes: readonly ${namedObjectTypeType}[], ${parameters.query}): ${imports.Either}<Error, readonly ObjectT[]> {
|
|
214
212
|
const graph = query?.graph ?? this.${syntheticNamePrefix}graph;
|
|
215
213
|
|
|
216
214
|
const limit = query?.limit ?? Number.MAX_SAFE_INTEGER;
|