@shaclmate/compiler 4.0.6 → 4.0.7

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 (50) hide show
  1. package/dist/generators/ts/ObjectType.js +17 -4
  2. package/dist/generators/ts/ObjectUnionType.js +21 -9
  3. package/dist/generators/ts/ZodGenerator.d.ts +7 -0
  4. package/dist/generators/ts/ZodGenerator.js +37 -0
  5. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.d.ts +4 -0
  6. package/dist/generators/ts/_ObjectType/{ObjectType_jsonFunctionDeclarations.js → ObjectType_fromJsonFunctionDeclarations.js} +8 -64
  7. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.d.ts +5 -0
  8. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.js +27 -0
  9. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
  10. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +14 -0
  11. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  12. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +18 -0
  13. package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  14. package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js +30 -0
  15. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.d.ts +5 -0
  16. package/dist/generators/ts/_ObjectType/{ObjectType_rdfFunctionDeclarations.js → ObjectType_propertiesFromRdfFunctionDeclaration.js} +5 -37
  17. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +4 -1
  18. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js +6 -2
  19. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +4 -1
  20. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +6 -2
  21. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  22. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.js +57 -0
  23. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.d.ts +5 -0
  24. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.js +106 -0
  25. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.d.ts +5 -0
  26. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.js +19 -0
  27. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.d.ts +5 -0
  28. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.js +20 -0
  29. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  30. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js +14 -0
  31. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  32. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js +15 -0
  33. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  34. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js +35 -0
  35. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.d.ts +5 -0
  36. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.js +26 -0
  37. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.d.ts +5 -0
  38. package/dist/generators/ts/_ObjectUnionType/{ObjectUnionType_rdfFunctionDeclarations.js → ObjectUnionType_toRdfFunctionDeclarations.js} +6 -23
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.js +1 -0
  41. package/package.json +2 -2
  42. package/dist/generators/ts/_ObjectType/ObjectType_jsonFunctionDeclarations.d.ts +0 -4
  43. package/dist/generators/ts/_ObjectType/ObjectType_rdfFunctionDeclarations.d.ts +0 -4
  44. package/dist/generators/ts/_ObjectType/ObjectType_sparqlFunctionDeclarations.d.ts +0 -4
  45. package/dist/generators/ts/_ObjectType/ObjectType_sparqlFunctionDeclarations.js +0 -140
  46. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonFunctionDeclarations.d.ts +0 -4
  47. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonFunctionDeclarations.js +0 -50
  48. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_rdfFunctionDeclarations.d.ts +0 -4
  49. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlFunctionDeclarations.d.ts +0 -4
  50. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlFunctionDeclarations.js +0 -44
@@ -0,0 +1,106 @@
1
+ import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
2
+ import { Maybe } from "purify-ts";
3
+ import { imports } from "../imports.js";
4
+ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
5
+ import { snippets } from "../snippets.js";
6
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
7
+ import { code, joinCode } from "../ts-poet-wrapper.js";
8
+ const variables = {
9
+ filter: code `parameters.filter`,
10
+ preferredLanguages: code `parameters.preferredLanguages`,
11
+ focusIdentifier: code `parameters.focusIdentifier`,
12
+ variablePrefix: code `parameters.variablePrefix`,
13
+ };
14
+ export function ObjectType_sparqlWherePatternsFunctionDeclaration() {
15
+ if (!this.features.has("sparql")) {
16
+ return Maybe.empty();
17
+ }
18
+ const rdfClassVariable = code `${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
19
+ const rdfTypeVariable = code `${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
20
+ let patternsVariableDeclarationKeyword = "const";
21
+ const statements = [];
22
+ for (const parentObjectType of this.parentObjectTypes) {
23
+ statements.push(code `\
24
+ patterns = patterns.concat(${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${{ filter: variables.filter, focusIdentifier: variables.focusIdentifier, ignoreRdfType: true, preferredLanguages: variables.preferredLanguages, variablePrefix: variables.variablePrefix }}));`);
25
+ patternsVariableDeclarationKeyword = "let";
26
+ }
27
+ if (this.fromRdfType.isJust()) {
28
+ const fromRdfTypeVariables = this.fromRdfTypeVariable
29
+ .toList()
30
+ .concat(this.descendantFromRdfTypeVariables);
31
+ statements.push(code `const rdfTypeVariable = ${rdfTypeVariable};`, code `\
32
+ if (!parameters?.ignoreRdfType) {
33
+ patterns.push(
34
+ ${fromRdfTypeVariables.length > 1
35
+ ? code `\
36
+ {
37
+ type: "values" as const,
38
+ values: [${joinCode(fromRdfTypeVariables, { on: "," })}].map((identifier) => {
39
+ const valuePatternRow: ${imports.sparqljs}.ValuePatternRow = {};
40
+ valuePatternRow[\`?\${${variables.variablePrefix}}FromRdfType\`] = identifier as ${imports.NamedNode};
41
+ return valuePatternRow;
42
+ }),
43
+ },
44
+ ${snippets.sparqlInstancesOfPattern}({ rdfType: ${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}FromRdfType\`), subject: ${variables.focusIdentifier} }),`
45
+ : code `${snippets.sparqlInstancesOfPattern}({ rdfType: ${fromRdfTypeVariables[0]}, subject: ${variables.focusIdentifier} }),`}
46
+ {
47
+ triples: [
48
+ {
49
+ subject: ${variables.focusIdentifier},
50
+ predicate: ${rdfjsTermExpression(rdf.type)},
51
+ object: rdfTypeVariable
52
+ }
53
+ ],
54
+ type: "bgp" as const
55
+ },
56
+ {
57
+ patterns: [
58
+ {
59
+ triples: [
60
+ {
61
+ subject: rdfTypeVariable,
62
+ predicate: {
63
+ items: [${rdfjsTermExpression(rdfs.subClassOf)}],
64
+ pathType: "+" as const,
65
+ type: "path" as const
66
+ },
67
+ object: ${rdfClassVariable}
68
+ }
69
+ ],
70
+ type: "bgp" as const
71
+ }
72
+ ],
73
+ type: "optional" as const
74
+ }
75
+ );
76
+ }`);
77
+ }
78
+ for (const property of this.ownProperties) {
79
+ if (property.recursive) {
80
+ continue;
81
+ }
82
+ property
83
+ .sparqlWherePatternsExpression({ variables })
84
+ .ifJust(({ condition, patterns }) => {
85
+ const concatStatement = code `patterns = patterns.concat(${patterns});`;
86
+ if (condition) {
87
+ statements.push(code `if (${condition}) { ${concatStatement} }`);
88
+ }
89
+ else {
90
+ statements.push(concatStatement);
91
+ }
92
+ patternsVariableDeclarationKeyword = "let";
93
+ });
94
+ }
95
+ return Maybe.of(code `\
96
+ export function ${syntheticNamePrefix}sparqlWherePatterns(${statements.length === 0 ? "_" : ""}parameters: { filter: ${this.filterType} | undefined; focusIdentifier: ${imports.NamedNode} | ${imports.Variable}; ignoreRdfType: boolean; preferredLanguages: readonly string[] | undefined; variablePrefix: string }): readonly ${snippets.SparqlPattern}[] {
97
+ ${statements.length > 0
98
+ ? joinCode([
99
+ code `${patternsVariableDeclarationKeyword} patterns: ${snippets.SparqlPattern}[] = [];`,
100
+ ...statements,
101
+ code `return patterns;`,
102
+ ])
103
+ : "return [];"}
104
+ }`);
105
+ }
106
+ //# sourceMappingURL=ObjectType_sparqlWherePatternsFunctionDeclarations.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { type Code } from "ts-poet";
3
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
4
+ export declare function ObjectUnionType_fromJsonFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_fromJsonFunctionDeclaration.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { code } from "ts-poet";
3
+ import { imports } from "../imports.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
+ export function ObjectUnionType_fromJsonFunctionDeclaration() {
6
+ if (!this.features.has("json")) {
7
+ return Maybe.empty();
8
+ }
9
+ return Maybe.of(code `\
10
+ export function ${syntheticNamePrefix}fromJson(json: unknown): ${imports.Either}<${imports.z}.ZodError, ${this.name}> {
11
+ return ${this.concreteMemberTypes.reduce((expression, memberType) => {
12
+ const memberTypeExpression = code `(${memberType.staticModuleName}.${syntheticNamePrefix}fromJson(json) as ${imports.Either}<${imports.z}.ZodError, ${this.name}>)`;
13
+ return expression !== null
14
+ ? code `${expression}.altLazy(() => ${memberTypeExpression})`
15
+ : memberTypeExpression;
16
+ }, null)};
17
+ }`);
18
+ }
19
+ //# sourceMappingURL=ObjectUnionType_fromJsonFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectUnionType_fromRdfFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_fromRdfFunctionDeclarations.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { imports } from "../imports.js";
3
+ import { snippets } from "../snippets.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
+ import { code } from "../ts-poet-wrapper.js";
6
+ export function ObjectUnionType_fromRdfFunctionDeclaration() {
7
+ if (!this.features.has("rdf")) {
8
+ return Maybe.empty();
9
+ }
10
+ return Maybe.of(code `\
11
+ export function ${syntheticNamePrefix}fromRdf(resource: ${imports.Resource}, options?: ${snippets.FromRdfOptions}): ${imports.Either}<Error, ${this.name}> {
12
+ return ${this.concreteMemberTypes.reduce((expression, memberType) => {
13
+ const memberTypeExpression = code `(${memberType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...options, ignoreRdfType: false }) as ${imports.Either}<Error, ${this.name}>)`;
14
+ return expression !== null
15
+ ? code `${expression}.altLazy(() => ${memberTypeExpression})`
16
+ : memberTypeExpression;
17
+ }, null)};
18
+ }`);
19
+ }
20
+ //# sourceMappingURL=ObjectUnionType_fromRdfFunctionDeclarations.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { type Code } from "ts-poet";
3
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
4
+ export declare function ObjectUnionType_jsonZodSchemaFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_jsonZodSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { code, joinCode } from "ts-poet";
3
+ import { imports } from "../imports.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
+ export function ObjectUnionType_jsonZodSchemaFunctionDeclaration() {
6
+ if (!this.features.has("json")) {
7
+ return Maybe.empty();
8
+ }
9
+ return Maybe.of(code `\
10
+ export function ${syntheticNamePrefix}jsonZodSchema() {
11
+ return ${imports.z}.discriminatedUnion("${this._discriminantProperty.name}", [${joinCode(this.concreteMemberTypes.map((memberType) => memberType.jsonZodSchema({ context: "type" })), { on: ", " })}]);
12
+ }`);
13
+ }
14
+ //# sourceMappingURL=ObjectUnionType_jsonZodSchemaFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectUnionType_sparqlConstructTriplesFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { pascalCase } from "change-case";
2
+ import { Maybe } from "purify-ts";
3
+ import { imports } from "../imports.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
+ import { code, joinCode } from "../ts-poet-wrapper.js";
6
+ export function ObjectUnionType_sparqlConstructTriplesFunctionDeclaration() {
7
+ if (!this.features.has("sparql")) {
8
+ return Maybe.empty();
9
+ }
10
+ return Maybe.of(code `\
11
+ export function ${syntheticNamePrefix}sparqlConstructTriples({ filter, focusIdentifier, variablePrefix }: { filter: ${this.filterType} | undefined; focusIdentifier: ${imports.NamedNode} | ${imports.Variable}; ignoreRdfType: boolean; variablePrefix: string }): readonly ${imports.sparqljs}.Triple[] {
12
+ return [${joinCode(this.concreteMemberTypes.map((memberType) => code `...${memberType.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({ filter: filter?.on?.${memberType.name}, focusIdentifier, ignoreRdfType: false, variablePrefix: \`\${variablePrefix}${pascalCase(memberType.name)}\` }).concat()`), { on: ", " })}];
13
+ }`);
14
+ }
15
+ //# sourceMappingURL=ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectUnionType_sparqlWherePatternsFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_sparqlWherePatternsFunctionDeclaration.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { pascalCase } from "change-case";
2
+ import { Maybe } from "purify-ts";
3
+ import { imports } from "../imports.js";
4
+ import { snippets } from "../snippets.js";
5
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
+ import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
7
+ export function ObjectUnionType_sparqlWherePatternsFunctionDeclaration() {
8
+ if (!this.features.has("sparql")) {
9
+ return Maybe.empty();
10
+ }
11
+ return Maybe.of(code `\
12
+ export function ${syntheticNamePrefix}sparqlWherePatterns({ filter, focusIdentifier, preferredLanguages, variablePrefix }: { filter: ${this.filterType} | undefined; focusIdentifier: ${imports.NamedNode} | ${imports.Variable}; ignoreRdfType: boolean; preferredLanguages: readonly string[] | undefined; variablePrefix: string }): readonly ${snippets.SparqlPattern}[] {
13
+ ${joinCode([
14
+ code `let patterns: ${snippets.SparqlPattern}[] = [];`,
15
+ code `\
16
+ if (focusIdentifier.termType === "Variable") {
17
+ patterns = patterns.concat(${this.identifierType.sparqlWherePatternsFunction}({
18
+ filter: filter?.${syntheticNamePrefix}identifier,
19
+ ignoreRdfType: false,
20
+ preferredLanguages,
21
+ propertyPatterns: [],
22
+ schema: ${this.identifierType.schema},
23
+ valueVariable: focusIdentifier,
24
+ variablePrefix,
25
+ }));
26
+ }`,
27
+ code `patterns.push({ patterns: [${joinCode(this.concreteMemberTypes.map((memberType) => code `${{
28
+ patterns: code `${memberType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ filter: filter?.on?.${memberType.name}, focusIdentifier, ignoreRdfType: false, preferredLanguages, variablePrefix: \`\${variablePrefix}${pascalCase(memberType.name)}\` }).concat()`,
29
+ type: literalOf("group"),
30
+ }}`), { on: ", " })}], type: "union" });`,
31
+ code `return patterns;`,
32
+ ])}
33
+ }`);
34
+ }
35
+ //# sourceMappingURL=ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { type Code } from "ts-poet";
3
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
4
+ export declare function ObjectUnionType_toJsonFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_toJsonFunctionDeclaration.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { code, joinCode } from "ts-poet";
3
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
+ export function ObjectUnionType_toJsonFunctionDeclaration() {
5
+ if (!this.features.has("json")) {
6
+ return Maybe.empty();
7
+ }
8
+ return Maybe.of(code `\
9
+ export function ${syntheticNamePrefix}toJson(${this.thisVariable}: ${this.name}): ${this.jsonType().name} {
10
+ ${joinCode(this.concreteMemberTypes
11
+ .map((memberType) => {
12
+ let returnExpression;
13
+ switch (memberType.declarationType) {
14
+ case "class":
15
+ returnExpression = code `${this.thisVariable}.${syntheticNamePrefix}toJson()`;
16
+ break;
17
+ case "interface":
18
+ returnExpression = code `${memberType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`;
19
+ break;
20
+ }
21
+ return code `if (${memberType.staticModuleName}.is${memberType.name}(${this.thisVariable})) { return ${returnExpression}; }`;
22
+ })
23
+ .concat(code `throw new Error("unrecognized type");`))}
24
+ }`);
25
+ }
26
+ //# sourceMappingURL=ObjectUnionType_toJsonFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectUnionType_toRdfFunctionDeclaration(this: ObjectUnionType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectUnionType_toRdfFunctionDeclarations.d.ts.map
@@ -1,29 +1,12 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { codeEquals } from "../codeEquals.js";
2
3
  import { imports } from "../imports.js";
3
- import { snippets } from "../snippets.js";
4
4
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
5
  import { code, joinCode } from "../ts-poet-wrapper.js";
6
- function ObjectUnionType_fromRdfFunctionDeclaration() {
7
- return code `\
8
- export function ${syntheticNamePrefix}fromRdf(resource: ${imports.Resource}, options?: ${snippets.FromRdfOptions}): ${imports.Either}<Error, ${this.name}> {
9
- return ${this.concreteMemberTypes.reduce((expression, memberType) => {
10
- const memberTypeExpression = code `(${memberType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...options, ignoreRdfType: false }) as ${imports.Either}<Error, ${this.name}>)`;
11
- return expression !== null
12
- ? code `${expression}.altLazy(() => ${memberTypeExpression})`
13
- : memberTypeExpression;
14
- }, null)};
15
- }`;
16
- }
17
- export function rdfFunctionDeclarations() {
6
+ export function ObjectUnionType_toRdfFunctionDeclaration() {
18
7
  if (!this.features.has("rdf")) {
19
- return [];
8
+ return Maybe.empty();
20
9
  }
21
- return [
22
- ObjectUnionType_fromRdfFunctionDeclaration.bind(this)(),
23
- ObjectUnionType_toRdfFunctionDeclaration.bind(this)(),
24
- ];
25
- }
26
- function ObjectUnionType_toRdfFunctionDeclaration() {
27
10
  const parametersVariable = "_parameters";
28
11
  const returnType = () => {
29
12
  let returnType;
@@ -39,7 +22,7 @@ function ObjectUnionType_toRdfFunctionDeclaration() {
39
22
  // The types agree
40
23
  return returnType;
41
24
  };
42
- return code `\
25
+ return Maybe.of(code `\
43
26
  export function ${syntheticNamePrefix}toRdf(${this.thisVariable}: ${this.name}, ${parametersVariable}?: { graph?: Exclude<${imports.Quad_Graph}, ${imports.Variable}>, resourceSet?: ${imports.ResourceSet} }): ${returnType()} {
44
27
  ${joinCode(this.concreteMemberTypes
45
28
  .map((memberType) => {
@@ -55,6 +38,6 @@ ${joinCode(this.concreteMemberTypes
55
38
  return code `if (${memberType.staticModuleName}.is${memberType.name}(${this.thisVariable})) { return ${returnExpression}; }`;
56
39
  })
57
40
  .concat(code `throw new Error("unrecognized type");`))}
58
- }`;
41
+ }`);
59
42
  }
60
- //# sourceMappingURL=ObjectUnionType_rdfFunctionDeclarations.js.map
43
+ //# sourceMappingURL=ObjectUnionType_toRdfFunctionDeclarations.js.map
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./Compiler.js";
3
3
  export type { Generator } from "./generators/Generator.js";
4
4
  export { AstJsonGenerator } from "./generators/json/AstJsonGenerator.js";
5
5
  export { TsGenerator } from "./generators/ts/TsGenerator.js";
6
+ export { ZodGenerator } from "./generators/ts/ZodGenerator.js";
6
7
  export * from "./input/ShapesGraph.js";
7
8
  export * from "./ShapesGraphToAstTransformer.js";
8
9
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * as ast from "./ast/index.js";
2
2
  export * from "./Compiler.js";
3
3
  export { AstJsonGenerator } from "./generators/json/AstJsonGenerator.js";
4
4
  export { TsGenerator } from "./generators/ts/TsGenerator.js";
5
+ export { ZodGenerator } from "./generators/ts/ZodGenerator.js";
5
6
  export * from "./input/ShapesGraph.js";
6
7
  export * from "./ShapesGraphToAstTransformer.js";
7
8
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.6",
3
+ "@shaclmate/shacl-ast": "4.0.7",
4
4
  "@rdfjs/data-model": "~2.1.1",
5
5
  "@rdfjs/dataset": "~2.0.2",
6
6
  "@rdfjs/prefix-map": "~0.1.2",
@@ -80,5 +80,5 @@
80
80
  },
81
81
  "type": "module",
82
82
  "types": "./dist/index.d.ts",
83
- "version": "4.0.6"
83
+ "version": "4.0.7"
84
84
  }
@@ -1,4 +0,0 @@
1
- import type { ObjectType } from "../ObjectType.js";
2
- import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function ObjectType_jsonFunctionDeclarations(this: ObjectType): readonly Code[];
4
- //# sourceMappingURL=ObjectType_jsonFunctionDeclarations.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { ObjectType } from "../ObjectType.js";
2
- import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function ObjectType_rdfFunctionDeclarations(this: ObjectType): readonly Code[];
4
- //# sourceMappingURL=ObjectType_rdfFunctionDeclarations.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { ObjectType } from "../ObjectType.js";
2
- import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function ObjectType_sparqlFunctionDeclarations(this: ObjectType): readonly Code[];
4
- //# sourceMappingURL=ObjectType_sparqlFunctionDeclarations.d.ts.map
@@ -1,140 +0,0 @@
1
- import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
2
- import { imports } from "../imports.js";
3
- import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
4
- import { snippets } from "../snippets.js";
5
- import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
- import { code, joinCode } from "../ts-poet-wrapper.js";
7
- import { ObjectType_sparqlConstructQueryFunctionDeclaration } from "./ObjectType_sparqlConstructQueryFunctionDeclaration.js";
8
- import { ObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./ObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
9
- export function ObjectType_sparqlFunctionDeclarations() {
10
- if (!this.features.has("sparql")) {
11
- return [];
12
- }
13
- const variables = {
14
- filter: code `parameters.filter`,
15
- preferredLanguages: code `parameters.preferredLanguages`,
16
- focusIdentifier: code `parameters.focusIdentifier`,
17
- variablePrefix: code `parameters.variablePrefix`,
18
- };
19
- const rdfClassVariable = code `${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
20
- const rdfTypeVariable = code `${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
21
- let patternsVariableDeclarationKeyword = "const";
22
- let triplesVariableDeclarationKeyword = "const";
23
- const sparqlConstructTriplesStatements = [];
24
- const sparqlWherePatternsStatements = [];
25
- for (const parentObjectType of this.parentObjectTypes) {
26
- sparqlConstructTriplesStatements.push(code `triples = triples.concat(${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples(${{ filter: variables.filter, focusIdentifier: variables.focusIdentifier, ignoreRdfType: true, variablePrefix: variables.variablePrefix }}));`);
27
- triplesVariableDeclarationKeyword = "let";
28
- sparqlWherePatternsStatements.push(code `\
29
- patterns = patterns.concat(${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${{ filter: variables.filter, focusIdentifier: variables.focusIdentifier, ignoreRdfType: true, preferredLanguages: variables.preferredLanguages, variablePrefix: variables.variablePrefix }}));`);
30
- patternsVariableDeclarationKeyword = "let";
31
- }
32
- if (this.fromRdfType.isJust()) {
33
- const fromRdfTypeVariables = this.fromRdfTypeVariable
34
- .toList()
35
- .concat(this.descendantFromRdfTypeVariables);
36
- sparqlConstructTriplesStatements.push(code `\
37
- if (!parameters?.ignoreRdfType) {
38
- triples.push(
39
- { subject: ${variables.focusIdentifier}, predicate: ${rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} },
40
- { subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
41
- );
42
- }`);
43
- sparqlWherePatternsStatements.push(code `const rdfTypeVariable = ${rdfTypeVariable};`, code `\
44
- if (!parameters?.ignoreRdfType) {
45
- patterns.push(
46
- ${fromRdfTypeVariables.length > 1
47
- ? code `\
48
- {
49
- type: "values" as const,
50
- values: [${joinCode(fromRdfTypeVariables, { on: "," })}].map((identifier) => {
51
- const valuePatternRow: ${imports.sparqljs}.ValuePatternRow = {};
52
- valuePatternRow[\`?\${${variables.variablePrefix}}FromRdfType\`] = identifier as ${imports.NamedNode};
53
- return valuePatternRow;
54
- }),
55
- },
56
- ${snippets.sparqlInstancesOfPattern}({ rdfType: ${imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}FromRdfType\`), subject: ${variables.focusIdentifier} }),`
57
- : code `${snippets.sparqlInstancesOfPattern}({ rdfType: ${fromRdfTypeVariables[0]}, subject: ${variables.focusIdentifier} }),`}
58
- {
59
- triples: [
60
- {
61
- subject: ${variables.focusIdentifier},
62
- predicate: ${rdfjsTermExpression(rdf.type)},
63
- object: rdfTypeVariable
64
- }
65
- ],
66
- type: "bgp" as const
67
- },
68
- {
69
- patterns: [
70
- {
71
- triples: [
72
- {
73
- subject: rdfTypeVariable,
74
- predicate: {
75
- items: [${rdfjsTermExpression(rdfs.subClassOf)}],
76
- pathType: "+" as const,
77
- type: "path" as const
78
- },
79
- object: ${rdfClassVariable}
80
- }
81
- ],
82
- type: "bgp" as const
83
- }
84
- ],
85
- type: "optional" as const
86
- }
87
- );
88
- }`);
89
- }
90
- for (const property of this.ownProperties) {
91
- if (property.recursive) {
92
- continue;
93
- }
94
- property
95
- .sparqlConstructTriplesExpression({
96
- variables,
97
- })
98
- .ifJust((propertyTriples) => {
99
- sparqlConstructTriplesStatements.push(code `triples = triples.concat(${propertyTriples});`);
100
- triplesVariableDeclarationKeyword = "let";
101
- });
102
- property
103
- .sparqlWherePatternsExpression({ variables })
104
- .ifJust(({ condition, patterns }) => {
105
- const concatStatement = code `patterns = patterns.concat(${patterns});`;
106
- if (condition) {
107
- sparqlWherePatternsStatements.push(code `if (${condition}) { ${concatStatement} }`);
108
- }
109
- else {
110
- sparqlWherePatternsStatements.push(concatStatement);
111
- }
112
- patternsVariableDeclarationKeyword = "let";
113
- });
114
- }
115
- return [
116
- ObjectType_sparqlConstructQueryFunctionDeclaration.bind(this)(),
117
- ObjectType_sparqlConstructQueryStringFunctionDeclaration.bind(this)(),
118
- code `\
119
- export function ${syntheticNamePrefix}sparqlConstructTriples(${sparqlConstructTriplesStatements.length === 0 ? "_" : ""}parameters: { filter: ${this.filterType} | undefined; focusIdentifier: ${imports.NamedNode} | ${imports.Variable}; ignoreRdfType: boolean; variablePrefix: string }): readonly ${imports.sparqljs}.Triple[] {
120
- ${sparqlConstructTriplesStatements.length > 0
121
- ? joinCode([
122
- code `${triplesVariableDeclarationKeyword} triples: ${imports.sparqljs}.Triple[] = [];`,
123
- ...sparqlConstructTriplesStatements,
124
- code `return triples;`,
125
- ])
126
- : "return [];"}
127
- }`,
128
- code `\
129
- export function ${syntheticNamePrefix}sparqlWherePatterns(${sparqlWherePatternsStatements.length === 0 ? "_" : ""}parameters: { filter: ${this.filterType} | undefined; focusIdentifier: ${imports.NamedNode} | ${imports.Variable}; ignoreRdfType: boolean; preferredLanguages: readonly string[] | undefined; variablePrefix: string }): readonly ${snippets.SparqlPattern}[] {
130
- ${sparqlWherePatternsStatements.length > 0
131
- ? joinCode([
132
- code `${patternsVariableDeclarationKeyword} patterns: ${snippets.SparqlPattern}[] = [];`,
133
- ...sparqlWherePatternsStatements,
134
- code `return patterns;`,
135
- ])
136
- : "return [];"}
137
- }`,
138
- ];
139
- }
140
- //# sourceMappingURL=ObjectType_sparqlFunctionDeclarations.js.map
@@ -1,4 +0,0 @@
1
- import { type Code } from "ts-poet";
2
- import type { ObjectUnionType } from "../ObjectUnionType.js";
3
- export declare function jsonFunctionDeclarations(this: ObjectUnionType): readonly Code[];
4
- //# sourceMappingURL=ObjectUnionType_jsonFunctionDeclarations.d.ts.map
@@ -1,50 +0,0 @@
1
- import { code, joinCode } from "ts-poet";
2
- import { imports } from "../imports.js";
3
- import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
- function ObjectUnionType_fromJsonFunctionDeclaration() {
5
- return code `\
6
- export function ${syntheticNamePrefix}fromJson(json: unknown): ${imports.Either}<${imports.z}.ZodError, ${this.name}> {
7
- return ${this.concreteMemberTypes.reduce((expression, memberType) => {
8
- const memberTypeExpression = code `(${memberType.staticModuleName}.${syntheticNamePrefix}fromJson(json) as ${imports.Either}<${imports.z}.ZodError, ${this.name}>)`;
9
- return expression !== null
10
- ? code `${expression}.altLazy(() => ${memberTypeExpression})`
11
- : memberTypeExpression;
12
- }, null)};
13
- }`;
14
- }
15
- export function jsonFunctionDeclarations() {
16
- if (!this.features.has("json")) {
17
- return [];
18
- }
19
- return [
20
- ObjectUnionType_fromJsonFunctionDeclaration.bind(this)(),
21
- jsonZodSchemaFunctionDeclaration.bind(this)(),
22
- toJsonFunctionDeclaration.bind(this)(),
23
- ];
24
- }
25
- function jsonZodSchemaFunctionDeclaration() {
26
- return code `\
27
- export function ${syntheticNamePrefix}jsonZodSchema() {
28
- return ${imports.z}.discriminatedUnion("${this._discriminantProperty.name}", [${joinCode(this.concreteMemberTypes.map((memberType) => memberType.jsonZodSchema({ context: "type" })), { on: ", " })}]);
29
- }`;
30
- }
31
- function toJsonFunctionDeclaration() {
32
- return code `\
33
- export function ${syntheticNamePrefix}toJson(${this.thisVariable}: ${this.name}): ${this.jsonType().name} {
34
- ${joinCode(this.concreteMemberTypes
35
- .map((memberType) => {
36
- let returnExpression;
37
- switch (memberType.declarationType) {
38
- case "class":
39
- returnExpression = code `${this.thisVariable}.${syntheticNamePrefix}toJson()`;
40
- break;
41
- case "interface":
42
- returnExpression = code `${memberType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`;
43
- break;
44
- }
45
- return code `if (${memberType.staticModuleName}.is${memberType.name}(${this.thisVariable})) { return ${returnExpression}; }`;
46
- })
47
- .concat(code `throw new Error("unrecognized type");`))}
48
- }`;
49
- }
50
- //# sourceMappingURL=ObjectUnionType_jsonFunctionDeclarations.js.map
@@ -1,4 +0,0 @@
1
- import type { ObjectUnionType } from "../ObjectUnionType.js";
2
- import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function rdfFunctionDeclarations(this: ObjectUnionType): readonly Code[];
4
- //# sourceMappingURL=ObjectUnionType_rdfFunctionDeclarations.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { ObjectUnionType } from "../ObjectUnionType.js";
2
- import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function ObjectUnionType_sparqlFunctionDeclarations(this: ObjectUnionType): readonly Code[];
4
- //# sourceMappingURL=ObjectUnionType_sparqlFunctionDeclarations.d.ts.map