@shaclmate/compiler 2.0.23 → 2.0.24

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 (96) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +5 -5
  2. package/dist/ShapesGraphToAstTransformer.js +5 -5
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  8. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +77 -29
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  11. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  20. package/dist/ast/OptionType.d.ts +0 -2
  21. package/dist/ast/SetType.d.ts +1 -6
  22. package/dist/ast/index.d.ts +1 -0
  23. package/dist/ast/index.js +1 -0
  24. package/dist/generators/json/AstJsonGenerator.js +7 -1
  25. package/dist/generators/ts/BooleanType.d.ts +1 -1
  26. package/dist/generators/ts/BooleanType.js +1 -1
  27. package/dist/generators/ts/DateTimeType.d.ts +1 -1
  28. package/dist/generators/ts/DateTimeType.js +1 -1
  29. package/dist/generators/ts/IdentifierType.d.ts +6 -1
  30. package/dist/generators/ts/IdentifierType.js +20 -14
  31. package/dist/generators/ts/ListType.js +16 -5
  32. package/dist/generators/ts/LiteralType.d.ts +9 -2
  33. package/dist/generators/ts/LiteralType.js +79 -15
  34. package/dist/generators/ts/NumberType.d.ts +1 -1
  35. package/dist/generators/ts/NumberType.js +1 -1
  36. package/dist/generators/ts/ObjectType.d.ts +1 -2
  37. package/dist/generators/ts/ObjectType.js +4 -5
  38. package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
  39. package/dist/generators/ts/ObjectUnionType.js +18 -9
  40. package/dist/generators/ts/OptionType.d.ts +1 -1
  41. package/dist/generators/ts/OptionType.js +6 -4
  42. package/dist/generators/ts/PrimitiveType.d.ts +19 -1
  43. package/dist/generators/ts/PrimitiveType.js +16 -3
  44. package/dist/generators/ts/SetType.d.ts +4 -4
  45. package/dist/generators/ts/SetType.js +15 -12
  46. package/dist/generators/ts/SnippetDeclarations.d.ts +1 -1
  47. package/dist/generators/ts/SnippetDeclarations.js +13 -2
  48. package/dist/generators/ts/StringType.d.ts +1 -1
  49. package/dist/generators/ts/StringType.js +8 -8
  50. package/dist/generators/ts/TermType.d.ts +7 -19
  51. package/dist/generators/ts/TermType.js +44 -51
  52. package/dist/generators/ts/TsGenerator.js +4 -1
  53. package/dist/generators/ts/Type.d.ts +12 -2
  54. package/dist/generators/ts/Type.js +1 -0
  55. package/dist/generators/ts/TypeFactory.d.ts +8 -0
  56. package/dist/generators/ts/TypeFactory.js +112 -22
  57. package/dist/generators/ts/UnionType.js +1 -1
  58. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
  59. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
  60. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
  61. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
  62. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
  63. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
  64. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
  65. package/dist/generators/ts/_ObjectType/Property.d.ts +9 -3
  66. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
  67. package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
  68. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
  69. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
  70. package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
  71. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
  72. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
  73. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
  74. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +71 -79
  75. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  76. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  77. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +6 -2
  78. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
  79. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +5 -5
  80. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
  81. package/dist/input/PropertyPath.d.ts +1 -2
  82. package/dist/input/PropertyPath.js +6 -8
  83. package/dist/input/ShapesGraph.js +4 -8
  84. package/dist/input/generated.d.ts +96 -54
  85. package/dist/input/generated.js +1350 -744
  86. package/package.json +5 -5
  87. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
  88. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
  89. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  90. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  91. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  92. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  93. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  94. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  95. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
  96. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
@@ -1,25 +1,76 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
+ import { invariant } from "ts-invariant";
3
4
  import { StructureKind } from "ts-morph";
4
5
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
5
6
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
7
  import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
7
- function fromRdfFunctionDeclarations() {
8
+ function fromRdfFunctionDeclaration() {
9
+ const statements = [];
10
+ statements.push("let { ignoreRdfType = false, languageIn, objectSet, ...context } = (options ?? {});", `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet({ dataset: resource.dataset }); }`);
11
+ let returnExpression;
12
+ if (this.childObjectTypes.length > 0) {
13
+ // Can't ignore the RDF type.
14
+ // Similar to an object union type, alt-chain the fromRdf of the different concrete subclasses together
15
+ returnExpression = this.childObjectTypes.reduce((expression, childObjectType) => {
16
+ const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...context, ignoreRdfType: false, objectSet }) as purify.Either<Error, ${this.name}>)`;
17
+ return expression.length > 0
18
+ ? `${expression}.altLazy(() => ${childObjectTypeExpression})`
19
+ : childObjectTypeExpression;
20
+ }, "");
21
+ }
22
+ if (!this.abstract) {
23
+ let propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...context, ignoreRdfType, languageIn, objectSet, resource })`;
24
+ if (this.declarationType === "class") {
25
+ propertiesFromRdfExpression = `${propertiesFromRdfExpression}.map(properties => new ${this.name}(properties))`;
26
+ }
27
+ if (this.childObjectTypes.length > 0) {
28
+ invariant(returnExpression);
29
+ returnExpression = `${returnExpression}.altLazy(() => ${propertiesFromRdfExpression})`;
30
+ }
31
+ else {
32
+ invariant(!returnExpression);
33
+ returnExpression = propertiesFromRdfExpression;
34
+ }
35
+ }
36
+ if (returnExpression) {
37
+ statements.push(`return ${returnExpression};`);
38
+ }
39
+ if (statements.length === 0) {
40
+ return Maybe.empty();
41
+ }
42
+ return Maybe.of({
43
+ isExported: true,
44
+ kind: StructureKind.Function,
45
+ name: `${syntheticNamePrefix}fromRdf`,
46
+ parameters: [
47
+ {
48
+ name: "resource",
49
+ type: "rdfjsResource.Resource",
50
+ },
51
+ {
52
+ hasQuestionToken: true,
53
+ name: "options",
54
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet; }`,
55
+ },
56
+ ],
57
+ returnType: `purify.Either<Error, ${this.name}>`,
58
+ statements: statements,
59
+ });
60
+ }
61
+ function propertiesFromRdfFunctionDeclaration() {
8
62
  const initializers = [];
9
63
  const propertySignatures = [];
10
- const propertiesFromRdfReturnType = [];
11
- const propertiesFromRdfStatements = [];
12
- if (this.ownProperties.length > 0 || this.parentObjectTypes.length > 0) {
13
- propertiesFromRdfStatements.push("// @ts-ignore", `const ${syntheticNamePrefix}objectSet = ${syntheticNamePrefix}objectSetParameter ?? new ${syntheticNamePrefix}RdfjsDatasetObjectSet({ dataset: ${variables.resource}.dataset });`);
14
- }
64
+ const returnType = [];
65
+ const statements = [];
15
66
  this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
16
- propertiesFromRdfStatements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource} });`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
67
+ statements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource} });`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
17
68
  initializers.push(`...${syntheticNamePrefix}super${parentObjectTypeI}`);
18
- propertiesFromRdfReturnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>>`);
69
+ returnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>>`);
19
70
  });
20
71
  this.fromRdfType.ifJust((rdfType) => {
21
72
  const predicate = rdfjsTermExpression(rdf.type);
22
- propertiesFromRdfStatements.push(`\
73
+ statements.push(`\
23
74
  if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${syntheticNamePrefix}fromRdfType)) {
24
75
  return ${variables.resource}.value(${predicate}).chain(actualRdfType => actualRdfType.toIri()).chain((actualRdfType) => purify.Left(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${rdfType.value})\`)));
25
76
  }`);
@@ -35,88 +86,28 @@ if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${synthet
35
86
  variables: propertyFromRdfVariables,
36
87
  });
37
88
  if (propertyFromRdfStatements.length > 0) {
38
- propertiesFromRdfStatements.push(...propertyFromRdfStatements);
89
+ statements.push(...propertyFromRdfStatements);
39
90
  initializers.push(property.name);
40
91
  propertySignatures.push(`${property.name}: ${property.type.name};`);
41
92
  }
42
93
  }
43
- propertiesFromRdfStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
94
+ statements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
44
95
  if (propertySignatures.length > 0) {
45
- propertiesFromRdfReturnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
96
+ returnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
46
97
  }
47
- const functionDeclarations = [];
48
- functionDeclarations.push({
98
+ return {
49
99
  isExported: true,
50
100
  kind: StructureKind.Function,
51
101
  name: `${syntheticNamePrefix}propertiesFromRdf`,
52
102
  parameters: [
53
103
  {
54
- name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, objectSet: ${syntheticNamePrefix}objectSetParameter, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
55
- type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet; resource: rdfjsResource.Resource; }`,
104
+ name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
105
+ type: `{ [_index: string]: any; ignoreRdfType: boolean; languageIn?: readonly string[]; objectSet: ${syntheticNamePrefix}ObjectSet; resource: rdfjsResource.Resource; }`,
56
106
  },
57
107
  ],
58
- returnType: `purify.Either<Error, ${propertiesFromRdfReturnType.join(" & ")}>`,
59
- statements: propertiesFromRdfStatements,
60
- });
61
- const fromRdfStatements = [];
62
- let fromRdfReturnStatement;
63
- if (this.abstract) {
64
- if (this.childObjectTypes.length > 0) {
65
- // Can't ignore the RDF type if we're doing a union.
66
- fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
67
- // Similar to an object union type, alt-chain the fromRdf of the different concrete subclasses together
68
- fromRdfReturnStatement = `return ${this.childObjectTypes.reduce((expression, childObjectType) => {
69
- const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
70
- return expression.length > 0
71
- ? `${expression}.altLazy(() => ${childObjectTypeExpression})`
72
- : childObjectTypeExpression;
73
- }, "")};`;
74
- }
75
- }
76
- else {
77
- let propertiesFromRdfExpression;
78
- switch (this.declarationType) {
79
- case "class":
80
- propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters).map(properties => new ${this.name}(properties))`;
81
- break;
82
- case "interface":
83
- propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters)`;
84
- break;
85
- }
86
- if (this.childObjectTypes.length > 0) {
87
- // Can't ignore the RDF type if we're trying the child object type.
88
- fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
89
- fromRdfReturnStatement = `${this.childObjectTypes.reduce((expression, childObjectType) => {
90
- const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
91
- return expression.length > 0
92
- ? `${expression}.altLazy(() => ${childObjectTypeExpression})`
93
- : childObjectTypeExpression;
94
- }, "")}.altLazy(() => ${propertiesFromRdfExpression})`;
95
- }
96
- else {
97
- fromRdfReturnStatement = propertiesFromRdfExpression;
98
- }
99
- fromRdfReturnStatement = `return ${fromRdfReturnStatement};`;
100
- }
101
- if (fromRdfReturnStatement) {
102
- fromRdfStatements.push(fromRdfReturnStatement);
103
- }
104
- if (fromRdfStatements.length > 0) {
105
- functionDeclarations.push({
106
- isExported: true,
107
- kind: StructureKind.Function,
108
- name: `${syntheticNamePrefix}fromRdf`,
109
- parameters: [
110
- {
111
- name: "parameters",
112
- type: `Parameters<typeof ${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>[0]`,
113
- },
114
- ],
115
- returnType: `purify.Either<Error, ${this.name}>`,
116
- statements: fromRdfStatements,
117
- });
118
- }
119
- return functionDeclarations;
108
+ returnType: `purify.Either<Error, ${returnType.join(" & ")}>`,
109
+ statements: statements,
110
+ };
120
111
  }
121
112
  export function rdfFunctionDeclarations() {
122
113
  if (!this.features.has("rdf")) {
@@ -126,7 +117,8 @@ export function rdfFunctionDeclarations() {
126
117
  return [];
127
118
  }
128
119
  return [
129
- ...fromRdfFunctionDeclarations.bind(this)(),
120
+ ...fromRdfFunctionDeclaration.bind(this)().toList(),
121
+ propertiesFromRdfFunctionDeclaration.bind(this)(),
130
122
  ...toRdfFunctionDeclaration.bind(this)().toList(),
131
123
  ];
132
124
  }
@@ -9,13 +9,13 @@ export function sparqlConstructQueryFunctionDeclaration() {
9
9
  {
10
10
  hasQuestionToken: true,
11
11
  name: "parameters",
12
- type: '{ ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
12
+ type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
13
13
  },
14
14
  ],
15
15
  returnType: "sparqljs.ConstructQuery",
16
16
  statements: [
17
- "const { ignoreRdfType, subject, ...queryParameters } = parameters ?? {}",
18
- `return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType, subject })) };`,
17
+ "const { ignoreRdfType, languageIn, subject, ...queryParameters } = parameters ?? {}",
18
+ `return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType, languageIn, subject })) };`,
19
19
  ],
20
20
  };
21
21
  }
@@ -9,7 +9,7 @@ export function sparqlConstructQueryStringFunctionDeclaration() {
9
9
  {
10
10
  hasQuestionToken: true,
11
11
  name: "parameters",
12
- type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
12
+ type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
13
13
  },
14
14
  ],
15
15
  returnType: "string",
@@ -12,7 +12,11 @@ export function sparqlFunctionDeclarations() {
12
12
  if (this.extern) {
13
13
  return [];
14
14
  }
15
- const variables = { subject: "subject", variablePrefix: "variablePrefix" };
15
+ const variables = {
16
+ languageIn: "parameters?.languageIn",
17
+ subject: "subject",
18
+ variablePrefix: "variablePrefix",
19
+ };
16
20
  const rdfClassVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
17
21
  const rdfTypeVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
18
22
  const subjectDefault = camelCase(this.name);
@@ -135,7 +139,7 @@ for (const pattern of propertyPatterns) {
135
139
  {
136
140
  hasQuestionToken: true,
137
141
  name: `${nop ? "_" : ""}parameters`,
138
- type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
142
+ type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
139
143
  },
140
144
  ],
141
145
  returnType: "readonly sparqljs.Pattern[]",
@@ -7,8 +7,23 @@ export function toRdfFunctionOrMethodDeclaration() {
7
7
  return Maybe.empty();
8
8
  }
9
9
  this.ensureAtMostOneSuperObjectType();
10
+ const parameters = [];
11
+ if (this.declarationType === "interface") {
12
+ parameters.push({
13
+ name: this.thisVariable,
14
+ type: this.name,
15
+ });
16
+ }
17
+ parameters.push({
18
+ hasQuestionToken: true,
19
+ name: "options",
20
+ type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}?: rdfjsResource.MutableResourceSet }`,
21
+ });
10
22
  let usedIgnoreRdfTypeVariable = false;
11
- const statements = [];
23
+ const statements = [
24
+ `const ${variables.mutateGraph} = options?.${variables.mutateGraph};`,
25
+ `const ${variables.resourceSet} = options?.${variables.resourceSet} ?? new rdfjsResource.MutableResourceSet({ dataFactory, dataset: datasetFactory.dataset() });`,
26
+ ];
12
27
  if (this.parentObjectTypes.length > 0) {
13
28
  const superToRdfOptions = `{ ${variables.ignoreRdfType}: true, ${variables.mutateGraph}, ${variables.resourceSet} }`;
14
29
  let superToRdfCall;
@@ -42,17 +57,9 @@ export function toRdfFunctionOrMethodDeclaration() {
42
57
  }));
43
58
  }
44
59
  statements.push(`return ${variables.resource};`);
45
- const parameters = [];
46
- if (this.declarationType === "interface") {
47
- parameters.push({
48
- name: this.thisVariable,
49
- type: this.name,
50
- });
60
+ if (usedIgnoreRdfTypeVariable) {
61
+ statements.unshift(`const ${variables.ignoreRdfType} = !!options?.ignoreRdfType;`);
51
62
  }
52
- parameters.push({
53
- name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType}, ` : ""}${variables.mutateGraph}, ${variables.resourceSet} }`,
54
- type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
55
- });
56
63
  return Maybe.of({
57
64
  name: `${syntheticNamePrefix}toRdf`,
58
65
  parameters,
@@ -63,7 +70,7 @@ export function toRdfFunctionOrMethodDeclaration() {
63
70
  const variables = {
64
71
  ignoreRdfType: "ignoreRdfType",
65
72
  mutateGraph: "mutateGraph",
66
- resource: "_resource",
73
+ resource: "resource",
67
74
  resourceSet: "resourceSet",
68
75
  };
69
76
  //# sourceMappingURL=toRdfFunctionOrMethodDeclaration.js.map
@@ -13,7 +13,7 @@ export function rdfjsDatasetObjectSetClassDeclaration({ objectTypes, objectUnion
13
13
  name: "ObjectIdentifierT",
14
14
  },
15
15
  };
16
- const fromRdfFunctionType = `(parameters: { objectSet: ${syntheticNamePrefix}ObjectSet, resource: rdfjsResource.Resource }) => purify.Either<Error, ${typeParameters.ObjectT.name}>`;
16
+ const fromRdfFunctionType = `(resource: rdfjsResource.Resource, options: { objectSet: ${syntheticNamePrefix}ObjectSet }) => purify.Either<Error, ${typeParameters.ObjectT.name}>`;
17
17
  const reusableMethodDeclarations = [];
18
18
  if (objectTypes.length > 0) {
19
19
  const parameters = {
@@ -84,7 +84,7 @@ if (query?.where) {
84
84
 
85
85
  const objects: ${typeParameters.ObjectT.name}[] = [];
86
86
  for (const identifier of identifiers) {
87
- const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this, resource: this.resourceSet.resource(identifier) });
87
+ const either = objectType.${syntheticNamePrefix}fromRdf(this.resourceSet.resource(identifier), { objectSet: this });
88
88
  if (either.isLeft()) {
89
89
  return either;
90
90
  }
@@ -104,7 +104,7 @@ resources.sort((left, right) => left.identifier.value.localeCompare(right.identi
104
104
  const objects: ${typeParameters.ObjectT.name}[] = [];
105
105
  let objectI = 0;
106
106
  for (const resource of resources) {
107
- const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this, resource });
107
+ const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
108
108
  if (either.isLeft()) {
109
109
  return either;
110
110
  }
@@ -209,7 +209,7 @@ if (query?.where) {
209
209
  const resource = this.resourceSet.resource(identifier);
210
210
  const lefts: purify.Either<Error, ${typeParameters.ObjectT.name}>[] = [];
211
211
  for (const objectType of objectTypes) {
212
- const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this, resource });
212
+ const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
213
213
  if (either.isRight()) {
214
214
  objects.push(either.unsafeCoerce());
215
215
  break;
@@ -241,7 +241,7 @@ resources.sort((left, right) => left.resource.identifier.value.localeCompare(rig
241
241
  let objectI = 0;
242
242
  const objects: ${typeParameters.ObjectT.name}[] = [];
243
243
  for (const { objectType, resource } of resources) {
244
- const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this, resource });
244
+ const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
245
245
  if (either.isLeft()) {
246
246
  return either;
247
247
  }
@@ -17,7 +17,7 @@ export function sparqlObjectSetClassDeclaration({ objectTypes, objectUnionTypes,
17
17
  constructObjectType: {
18
18
  name: "objectType",
19
19
  type: `{\
20
- ${syntheticNamePrefix}fromRdf: (parameters: { objectSet: ${syntheticNamePrefix}ObjectSet, resource: rdfjsResource.Resource }) => purify.Either<Error, ${typeParameters.ObjectT.name}>;
20
+ ${syntheticNamePrefix}fromRdf: (resource: rdfjsResource.Resource, options: { objectSet: ${syntheticNamePrefix}ObjectSet }) => purify.Either<Error, ${typeParameters.ObjectT.name}>;
21
21
  ${syntheticNamePrefix}sparqlConstructQueryString: (parameters?: { subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions) => string;
22
22
  ${syntheticNamePrefix}sparqlWherePatterns: ${sparqlWherePatternsFunctionType};
23
23
  }`,
@@ -248,13 +248,13 @@ try {
248
248
  return purify.Left(e as Error);
249
249
  }
250
250
 
251
- const dataset: rdfjs.DatasetCore = new N3.Store(quads.concat());
251
+ const dataset = datasetFactory.dataset(quads.concat());
252
252
  const objects: ${typeParameters.ObjectT.name}[] = [];
253
253
  for (const identifier of identifiers) {
254
- const objectEither = objectType.${syntheticNamePrefix}fromRdf({
255
- objectSet: this,
256
- resource: new rdfjsResource.Resource<rdfjs.NamedNode>({ dataset, identifier: identifier as rdfjs.NamedNode })
257
- });
254
+ const objectEither = objectType.${syntheticNamePrefix}fromRdf(
255
+ new rdfjsResource.Resource<rdfjs.NamedNode>({ dataset, identifier: identifier as rdfjs.NamedNode }),
256
+ { objectSet: this }
257
+ );
258
258
  if (objectEither.isLeft()) {
259
259
  return objectEither;
260
260
  }
@@ -31,11 +31,10 @@ export interface ZeroOrOnePath {
31
31
  }
32
32
  export type PropertyPath = AlternativePath | InversePath | OneOrMorePath | PredicatePath | SequencePath | ZeroOrMorePath | ZeroOrOnePath;
33
33
  export declare namespace PropertyPath {
34
- function $fromRdf({ resource, }: {
34
+ function $fromRdf(resource: Resource, _?: {
35
35
  [_index: string]: any;
36
36
  ignoreRdfType?: boolean;
37
37
  languageIn?: readonly string[];
38
- resource: Resource;
39
38
  }): Either<Error, PropertyPath>;
40
39
  function $toRdf(_propertyPath: PropertyPath, _options?: any): Resource;
41
40
  }
@@ -3,7 +3,7 @@ import { Either, Left } from "purify-ts";
3
3
  import { Resource } from "rdfjs-resource";
4
4
  export var PropertyPath;
5
5
  (function (PropertyPath) {
6
- function $fromRdf({ resource, }) {
6
+ function $fromRdf(resource, _) {
7
7
  // Predicate path
8
8
  // sh:path ex:parent
9
9
  if (resource.identifier.termType === "NamedNode") {
@@ -18,9 +18,7 @@ export var PropertyPath;
18
18
  if (memberResource.isNothing()) {
19
19
  return Left(new Error(`non-identifier in property path list ${Resource.Identifier.toString(listResource.identifier)}`));
20
20
  }
21
- const member = PropertyPath.$fromRdf({
22
- resource: memberResource.unsafeCoerce(),
23
- });
21
+ const member = PropertyPath.$fromRdf(memberResource.unsafeCoerce());
24
22
  if (member.isLeft()) {
25
23
  return member;
26
24
  }
@@ -52,14 +50,14 @@ export var PropertyPath;
52
50
  // Inverse path
53
51
  // sh:path: [ sh:inversePath ex:parent ]
54
52
  if (quad.predicate.equals(sh.inversePath)) {
55
- return PropertyPath.$fromRdf({ resource: objectResource }).map((path) => ({
53
+ return PropertyPath.$fromRdf(objectResource).map((path) => ({
56
54
  kind: "InversePath",
57
55
  path,
58
56
  }));
59
57
  }
60
58
  // One or more path
61
59
  if (quad.predicate.equals(sh.oneOrMorePath)) {
62
- return PropertyPath.$fromRdf({ resource: objectResource }).map((path) => ({
60
+ return PropertyPath.$fromRdf(objectResource).map((path) => ({
63
61
  kind: "OneOrMorePath",
64
62
  path,
65
63
  }));
@@ -74,13 +72,13 @@ export var PropertyPath;
74
72
  }
75
73
  // Zero or more path
76
74
  if (quad.predicate.equals(sh.zeroOrMorePath)) {
77
- return PropertyPath.$fromRdf({ resource: objectResource }).map((path) => ({
75
+ return PropertyPath.$fromRdf(objectResource).map((path) => ({
78
76
  kind: "ZeroOrMorePath",
79
77
  path,
80
78
  }));
81
79
  }
82
80
  if (quad.predicate.equals(sh.zeroOrOnePath)) {
83
- return PropertyPath.$fromRdf({ resource: objectResource }).map((path) => ({
81
+ return PropertyPath.$fromRdf(objectResource).map((path) => ({
84
82
  kind: "ZeroOrOnePath",
85
83
  path,
86
84
  }));
@@ -10,9 +10,8 @@ export class ShapesGraph extends RdfjsShapesGraph {
10
10
  dataset,
11
11
  factory: {
12
12
  nodeShapeFromRdf({ resource, shapesGraph, }) {
13
- return generated.ShaclmateNodeShape.$fromRdf({
13
+ return generated.ShaclmateNodeShape.$fromRdf(resource, {
14
14
  ignoreRdfType: true,
15
- resource,
16
15
  }).map((generatedShape) => new NodeShape({
17
16
  ancestorClassIris: ancestorClassIris(resource, Number.MAX_SAFE_INTEGER),
18
17
  childClassIris: descendantClassIris(resource, 1),
@@ -26,21 +25,18 @@ export class ShapesGraph extends RdfjsShapesGraph {
26
25
  }));
27
26
  },
28
27
  ontologyFromRdf({ resource, }) {
29
- return generated.ShaclmateOntology.$fromRdf({
28
+ return generated.ShaclmateOntology.$fromRdf(resource, {
30
29
  ignoreRdfType: true,
31
- resource,
32
30
  }).map((generatedOntology) => new Ontology(generatedOntology));
33
31
  },
34
32
  propertyGroupFromRdf({ resource, }) {
35
- return generated.ShaclCorePropertyGroup.$fromRdf({
33
+ return generated.ShaclCorePropertyGroup.$fromRdf(resource, {
36
34
  ignoreRdfType: true,
37
- resource,
38
35
  }).map((generatedPropertyGroup) => new PropertyGroup(generatedPropertyGroup));
39
36
  },
40
37
  propertyShapeFromRdf({ resource, shapesGraph, }) {
41
- return generated.ShaclmatePropertyShape.$fromRdf({
38
+ return generated.ShaclmatePropertyShape.$fromRdf(resource, {
42
39
  ignoreRdfType: true,
43
- resource,
44
40
  }).map((generatedShape) => new PropertyShape(generatedShape, shapesGraph));
45
41
  },
46
42
  },