@shaclmate/compiler 4.0.89 → 4.0.91

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 (26) hide show
  1. package/dist/generators/ts/ObjectType.d.ts +7 -6
  2. package/dist/generators/ts/ObjectType.js +19 -18
  3. package/dist/generators/ts/TypeFactory.js +12 -2
  4. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.d.ts +39 -21
  5. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.js +1 -13
  6. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.d.ts +14 -22
  7. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.js +27 -29
  8. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.d.ts +19 -14
  9. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.js +24 -12
  10. package/dist/generators/ts/_ObjectType/ObjectType_Property.d.ts +2 -1
  11. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.d.ts +37 -0
  12. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.js +118 -0
  13. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.d.ts +21 -17
  14. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.js +26 -8
  15. package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionExpression.js +6 -9
  16. package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionExpression.js +11 -2
  17. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionExpression.js +1 -12
  18. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionExpression.js +8 -46
  19. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionExpression.js +7 -3
  20. package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.js +1 -7
  21. package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.js +0 -3
  22. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionExpression.js +1 -3
  23. package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionExpression.js +1 -8
  24. package/dist/input/input.shaclmate.d.ts +45 -18
  25. package/dist/input/input.shaclmate.js +54 -32
  26. package/package.json +11 -9
@@ -15,6 +15,11 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
15
15
  kind = "Identifier";
16
16
  mutable = false;
17
17
  recursive = false;
18
+ type;
19
+ constructor({ type, ...superParameters }) {
20
+ super(superParameters);
21
+ this.type = type;
22
+ }
18
23
  get constructorParameter() {
19
24
  let hasQuestionToken = false;
20
25
  const typeExpressions = [code `(() => ${this.typeExpression})`];
@@ -33,7 +38,14 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
33
38
  });
34
39
  }
35
40
  get declaration() {
36
- return code `readonly ${this.name}: () => ${this.typeExpression};`;
41
+ return Maybe.of(code `readonly ${this.name}: () => ${this.typeExpression};`);
42
+ }
43
+ equalsExpression({ variables, }) {
44
+ return Maybe.of(code `${this.reusables.snippets.propertyEquals}(
45
+ { equalsFunction: ${this.type.equalsFunction}, name: ${literalOf(this.name)} },
46
+ [left, ${variables.leftObject}.${this.name}()],
47
+ [right, ${variables.rightObject}.${this.name}()],
48
+ )`);
37
49
  }
38
50
  get filterProperty() {
39
51
  return Maybe.of({
@@ -41,6 +53,9 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
41
53
  type: this.type.filterType,
42
54
  });
43
55
  }
56
+ filterExpression({ variables, }) {
57
+ return Maybe.of(code `${this.type.filterFunction}(${variables.filter}.${this.name}, ${variables.object}.${this.name}())`);
58
+ }
44
59
  get graphqlField() {
45
60
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
46
61
  invariant(this.name.startsWith(syntheticNamePrefix));
@@ -48,12 +63,12 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
48
63
  args: Maybe.empty(),
49
64
  description: Maybe.empty(),
50
65
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
51
- resolve: code `(source) => ${this.type.stringifyFunction}(${this.accessExpression({ variables: { object: code `source` } })})`,
66
+ resolve: code `(source) => ${this.type.stringifyFunction}(source.${this.name}())`,
52
67
  type: this.type.graphqlType.expression,
53
68
  });
54
69
  }
55
70
  get hashFunctionParameter() {
56
- return code `readonly ${this.name}?: () => ${this.typeExpression};`;
71
+ return Maybe.of(code `readonly ${this.name}?: () => ${this.typeExpression};`);
57
72
  }
58
73
  get jsonSchema() {
59
74
  let schema;
@@ -95,9 +110,6 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
95
110
  .map((name) => code `${name}.schema.properties.${this.name}.type`)
96
111
  .orDefaultLazy(() => this.type.schema);
97
112
  }
98
- accessExpression({ variables, }) {
99
- return code `${variables.object}.${this.name}()`;
100
- }
101
113
  constructorInitializer({ variables, }) {
102
114
  const nodeKinds = this.type.nodeKinds;
103
115
  let conversionFunction;
@@ -131,7 +143,7 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
131
143
  }
132
144
  hashStatements({ variables, }) {
133
145
  return [
134
- code `if (${variables.value}) { ${variables.hasher}.update(${variables.value}().value); }`,
146
+ code `if (${variables.object}.${this.name}) { ${variables.hasher}.update(${variables.object}.${this.name}().value); }`,
135
147
  ];
136
148
  }
137
149
  jsonUiSchemaElement({ variables, }) {
@@ -159,9 +171,9 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
159
171
  const valueToNodeKinds = nodeKinds.map((nodeKind) => {
160
172
  switch (nodeKind) {
161
173
  case "BlankNode":
162
- return code `\`_:\${${variables.value}.value}\``;
174
+ return code `\`_:\${${variables.object}.${this.name}().value}\``;
163
175
  case "IRI":
164
- return code `${variables.value}.value`;
176
+ return code `${variables.object}.${this.name}().value`;
165
177
  default:
166
178
  throw new RangeError(nodeKind);
167
179
  }
@@ -170,13 +182,13 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
170
182
  return Maybe.of(code `"@id": ${valueToNodeKinds[0]}`);
171
183
  }
172
184
  invariant(valueToNodeKinds.length === 2);
173
- return Maybe.of(code `"@id": ${variables.value}.termType === "${NodeKind.toTermType(nodeKinds[0])}" ? ${valueToNodeKinds[0]} : ${valueToNodeKinds[1]}`);
185
+ return Maybe.of(code `"@id": ${variables.object}.${this.name}().termType === "${NodeKind.toTermType(nodeKinds[0])}" ? ${valueToNodeKinds[0]} : ${valueToNodeKinds[1]}`);
174
186
  }
175
187
  toRdfRdfResourceValuesStatements() {
176
188
  return [];
177
189
  }
178
- toStringInitializer(parameters) {
179
- return Maybe.of(code `${literalOf(this.name)}: ${this.type.toStringExpression(parameters)}`);
190
+ toStringInitializer({ variables, }) {
191
+ return Maybe.of(code `${literalOf(this.name)}: ${this.type.toStringExpression({ variables: { value: code `${variables.object}.${this.name}()` } })}`);
180
192
  }
181
193
  }
182
194
  __decorate([
@@ -1,6 +1,7 @@
1
1
  import type { Type } from "../Type.js";
2
2
  import type { ObjectType_DiscriminantProperty } from "./ObjectType_DiscriminantProperty.js";
3
3
  import type { ObjectType_IdentifierProperty } from "./ObjectType_IdentifierProperty.js";
4
+ import type { ObjectType_RdfTypeProperty } from "./ObjectType_RdfTypeProperty.js";
4
5
  import type { ObjectType_ShaclProperty } from "./ObjectType_ShaclProperty.js";
5
- export type ObjectType_Property = ObjectType_IdentifierProperty | ObjectType_ShaclProperty<Type> | ObjectType_DiscriminantProperty;
6
+ export type ObjectType_Property = ObjectType_IdentifierProperty | ObjectType_ShaclProperty<Type> | ObjectType_DiscriminantProperty | ObjectType_RdfTypeProperty;
6
7
  //# sourceMappingURL=ObjectType_Property.d.ts.map
@@ -0,0 +1,37 @@
1
+ import type { NamedNode } from "@rdfjs/types";
2
+ import { Maybe } from "purify-ts";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
5
+ export declare class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
6
+ readonly constructorParameter: ObjectType_AbstractProperty["constructorParameter"];
7
+ readonly declaration: ObjectType_AbstractProperty["declaration"];
8
+ readonly filterProperty: ObjectType_AbstractProperty["filterProperty"];
9
+ readonly fromRdfType: NamedNode;
10
+ readonly graphqlField: ObjectType_AbstractProperty["graphqlField"];
11
+ readonly hashFunctionParameter: ObjectType_AbstractProperty["hashFunctionParameter"];
12
+ readonly jsonSchema: ObjectType_AbstractProperty["jsonSchema"];
13
+ readonly jsonSignature: ObjectType_AbstractProperty["jsonSignature"];
14
+ readonly kind = "RdfType";
15
+ readonly mutable = false;
16
+ readonly recursive = false;
17
+ readonly toRdfTypes: readonly NamedNode[];
18
+ constructor({ configuration, fromRdfType, toRdfTypes, ...superParameters }: {
19
+ fromRdfType: NamedNode;
20
+ toRdfTypes: readonly NamedNode[];
21
+ } & Omit<ConstructorParameters<typeof ObjectType_AbstractProperty>[0], "name">);
22
+ get schema(): Maybe<Code>;
23
+ get schemaType(): Maybe<Code>;
24
+ constructorInitializer(): Maybe<Code>;
25
+ equalsExpression(): Maybe<Code>;
26
+ filterExpression(): Maybe<Code>;
27
+ fromJsonInitializer(): Maybe<Code>;
28
+ fromRdfResourceValuesInitializer(): Maybe<Code>;
29
+ hashStatements(): readonly Code[];
30
+ jsonUiSchemaElement(): Maybe<Code>;
31
+ sparqlConstructTriplesExpression({ variables, }: Parameters<ObjectType_AbstractProperty["sparqlConstructTriplesExpression"]>[0]): Maybe<Code>;
32
+ sparqlWherePatternsExpression({ variables, }: Parameters<ObjectType_AbstractProperty["sparqlWherePatternsExpression"]>[0]): ReturnType<ObjectType_AbstractProperty["sparqlWherePatternsExpression"]>;
33
+ toJsonInitializer(): Maybe<Code>;
34
+ toRdfRdfResourceValuesStatements(): readonly Code[];
35
+ toStringInitializer(): Maybe<Code>;
36
+ }
37
+ //# sourceMappingURL=ObjectType_RdfTypeProperty.d.ts.map
@@ -0,0 +1,118 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
8
+ import { Maybe } from "purify-ts";
9
+ import { Memoize } from "typescript-memoize";
10
+ import { code, joinCode } from "../ts-poet-wrapper.js";
11
+ import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
12
+ export class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
13
+ constructorParameter = Maybe.empty();
14
+ declaration = Maybe.empty();
15
+ filterProperty = Maybe.empty();
16
+ fromRdfType;
17
+ graphqlField = Maybe.empty();
18
+ hashFunctionParameter = Maybe.empty();
19
+ jsonSchema = Maybe.empty();
20
+ jsonSignature = Maybe.empty();
21
+ kind = "RdfType";
22
+ mutable = false;
23
+ recursive = false;
24
+ toRdfTypes;
25
+ constructor({ configuration, fromRdfType, toRdfTypes, ...superParameters }) {
26
+ super({
27
+ ...superParameters,
28
+ configuration,
29
+ name: `${configuration.syntheticNamePrefix}rdfType`,
30
+ });
31
+ this.fromRdfType = fromRdfType;
32
+ this.toRdfTypes = toRdfTypes;
33
+ }
34
+ get schema() {
35
+ return Maybe.of(code `${{ fromRdfType: this.rdfjsTermExpression(this.fromRdfType), kind: this.kind, toRdfTypes: this.toRdfTypes.map((toRdfType) => this.rdfjsTermExpression(toRdfType)) }}`);
36
+ }
37
+ get schemaType() {
38
+ return Maybe.of(code `${{ fromRdfType: code `${this.reusables.imports.NamedNode}`, kind: this.kind, toRdfTypes: code `readonly ${this.reusables.imports.NamedNode}[]` }}`);
39
+ }
40
+ constructorInitializer() {
41
+ return Maybe.empty();
42
+ }
43
+ equalsExpression() {
44
+ return Maybe.empty();
45
+ }
46
+ filterExpression() {
47
+ return Maybe.empty();
48
+ }
49
+ fromJsonInitializer() {
50
+ return Maybe.empty();
51
+ }
52
+ fromRdfResourceValuesInitializer() {
53
+ return Maybe.empty();
54
+ }
55
+ hashStatements() {
56
+ return [];
57
+ }
58
+ jsonUiSchemaElement() {
59
+ return Maybe.empty();
60
+ }
61
+ sparqlConstructTriplesExpression({ variables, }) {
62
+ const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
63
+ const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
64
+ return Maybe.of(code `${variables.ignoreRdfType} ? [] : [${joinCode([
65
+ code `{ subject: ${variables.focusIdentifier}, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }`,
66
+ code `{ subject: ${rdfTypeVariable}, predicate: ${this.rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }`,
67
+ ], {
68
+ on: ",",
69
+ })}]`);
70
+ }
71
+ sparqlWherePatternsExpression({ variables, }) {
72
+ const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
73
+ const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
74
+ return Maybe.of({
75
+ patterns: code `${variables.ignoreRdfType} ? [] : [${joinCode([
76
+ code `${this.reusables.snippets.sparqlInstancesOfPattern}({ rdfType: ${variables.schema.map((schema) => code `${schema}.properties.${this.name}.fromRdfType`).orDefault(this.rdfjsTermExpression(this.fromRdfType))}, subject: ${variables.focusIdentifier} })`,
77
+ code `{ triples: [{ subject: ${variables.focusIdentifier}, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }], type: "bgp" as const }`,
78
+ code `{
79
+ patterns: [
80
+ {
81
+ triples: [
82
+ {
83
+ subject: ${rdfTypeVariable},
84
+ predicate: {
85
+ items: [${this.rdfjsTermExpression(rdfs.subClassOf)}],
86
+ pathType: "+" as const,
87
+ type: "path" as const
88
+ },
89
+ object: ${rdfClassVariable}
90
+ }
91
+ ],
92
+ type: "bgp" as const
93
+ }
94
+ ],
95
+ type: "optional" as const
96
+ }`,
97
+ ], {
98
+ on: ",",
99
+ })}]`,
100
+ });
101
+ }
102
+ toJsonInitializer() {
103
+ return Maybe.empty();
104
+ }
105
+ toRdfRdfResourceValuesStatements() {
106
+ return [];
107
+ }
108
+ toStringInitializer() {
109
+ return Maybe.empty();
110
+ }
111
+ }
112
+ __decorate([
113
+ Memoize()
114
+ ], ObjectType_RdfTypeProperty.prototype, "equalsExpression", null);
115
+ __decorate([
116
+ Memoize()
117
+ ], ObjectType_RdfTypeProperty.prototype, "filterExpression", null);
118
+ //# sourceMappingURL=ObjectType_RdfTypeProperty.js.map
@@ -3,7 +3,7 @@ import { Maybe } from "purify-ts";
3
3
  import type { Type } from "../Type.js";
4
4
  import { type Code } from "../ts-poet-wrapper.js";
5
5
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
6
- export declare class ObjectType_ShaclProperty<TypeT extends Type> extends ObjectType_AbstractProperty<TypeT> {
6
+ export declare class ObjectType_ShaclProperty<TypeT extends Type> extends ObjectType_AbstractProperty {
7
7
  private readonly comment;
8
8
  private readonly description;
9
9
  private readonly display;
@@ -12,7 +12,8 @@ export declare class ObjectType_ShaclProperty<TypeT extends Type> extends Object
12
12
  readonly mutable: boolean;
13
13
  readonly path: PropertyPath;
14
14
  readonly recursive: boolean;
15
- constructor({ comment, description, display, label, mutable, path, recursive, ...superParameters }: {
15
+ readonly type: TypeT;
16
+ constructor({ comment, description, display, label, mutable, path, recursive, type, ...superParameters }: {
16
17
  comment: Maybe<string>;
17
18
  description: Maybe<string>;
18
19
  display: boolean;
@@ -20,34 +21,37 @@ export declare class ObjectType_ShaclProperty<TypeT extends Type> extends Object
20
21
  mutable: boolean;
21
22
  path: PropertyPath;
22
23
  recursive: boolean;
23
- } & ConstructorParameters<typeof ObjectType_AbstractProperty<TypeT>>[0]);
24
+ type: TypeT;
25
+ } & ConstructorParameters<typeof ObjectType_AbstractProperty>[0]);
24
26
  get constructorParameter(): Maybe<{
25
27
  hasQuestionToken: boolean;
26
28
  signature: Code;
27
29
  }>;
28
- get declaration(): Code;
30
+ get declaration(): Maybe<Code>;
29
31
  get filterProperty(): Maybe<{
30
32
  name: string;
31
33
  type: Code;
32
34
  }>;
33
- get graphqlField(): ObjectType_AbstractProperty<TypeT>["graphqlField"];
34
- get hashFunctionParameter(): Code;
35
- get jsonSchema(): ObjectType_AbstractProperty<TypeT>["jsonSchema"];
35
+ get graphqlField(): ObjectType_AbstractProperty["graphqlField"];
36
+ get hashFunctionParameter(): Maybe<Code>;
37
+ get jsonSchema(): ObjectType_AbstractProperty["jsonSchema"];
36
38
  get jsonSignature(): Maybe<Code>;
37
39
  get schema(): Maybe<Code>;
38
40
  get schemaType(): Maybe<Code>;
39
41
  private get schemaVariable();
40
42
  private get typeSchemaVariable();
41
- constructorInitializer({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["constructorInitializer"]>[0]): Maybe<Code>;
42
- fromJsonInitializer({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["fromJsonInitializer"]>[0]): Maybe<Code>;
43
- fromRdfResourceValuesInitializer({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["fromRdfResourceValuesInitializer"]>[0]): Maybe<Code>;
44
- hashStatements({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["hashStatements"]>[0]): readonly Code[];
45
- jsonUiSchemaElement({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
46
- sparqlConstructTriplesExpression({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["sparqlConstructTriplesExpression"]>[0]): Maybe<Code>;
47
- sparqlWherePatternsExpression({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["sparqlWherePatternsExpression"]>[0]): ReturnType<ObjectType_AbstractProperty<TypeT>["sparqlWherePatternsExpression"]>;
48
- toJsonInitializer(parameters: Parameters<ObjectType_AbstractProperty<TypeT>["toJsonInitializer"]>[0]): Maybe<Code>;
49
- toRdfRdfResourceValuesStatements({ variables, }: Parameters<ObjectType_AbstractProperty<TypeT>["toRdfRdfResourceValuesStatements"]>[0]): readonly Code[];
50
- toStringInitializer(parameters: Parameters<ObjectType_AbstractProperty<TypeT>["toStringInitializer"]>[0]): Maybe<Code>;
43
+ constructorInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["constructorInitializer"]>[0]): Maybe<Code>;
44
+ equalsExpression({ variables, }: Parameters<ObjectType_AbstractProperty["equalsExpression"]>[0]): Maybe<Code>;
45
+ filterExpression({ variables, }: Parameters<ObjectType_AbstractProperty["filterExpression"]>[0]): Maybe<Code>;
46
+ fromJsonInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["fromJsonInitializer"]>[0]): Maybe<Code>;
47
+ fromRdfResourceValuesInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["fromRdfResourceValuesInitializer"]>[0]): Maybe<Code>;
48
+ hashStatements({ variables, }: Parameters<ObjectType_AbstractProperty["hashStatements"]>[0]): readonly Code[];
49
+ jsonUiSchemaElement({ variables, }: Parameters<ObjectType_AbstractProperty["jsonUiSchemaElement"]>[0]): Maybe<Code>;
50
+ sparqlConstructTriplesExpression({ variables, }: Parameters<ObjectType_AbstractProperty["sparqlConstructTriplesExpression"]>[0]): Maybe<Code>;
51
+ sparqlWherePatternsExpression({ variables, }: Parameters<ObjectType_AbstractProperty["sparqlWherePatternsExpression"]>[0]): ReturnType<ObjectType_AbstractProperty["sparqlWherePatternsExpression"]>;
52
+ toJsonInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["toJsonInitializer"]>[0]): Maybe<Code>;
53
+ toRdfRdfResourceValuesStatements({ variables, }: Parameters<ObjectType_AbstractProperty["toRdfRdfResourceValuesStatements"]>[0]): readonly Code[];
54
+ toStringInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["toStringInitializer"]>[0]): Maybe<Code>;
51
55
  private propertyPathToCode;
52
56
  }
53
57
  //# sourceMappingURL=ObjectType_ShaclProperty.d.ts.map
@@ -18,7 +18,8 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
18
18
  mutable;
19
19
  path;
20
20
  recursive;
21
- constructor({ comment, description, display, label, mutable, path, recursive, ...superParameters }) {
21
+ type;
22
+ constructor({ comment, description, display, label, mutable, path, recursive, type, ...superParameters }) {
22
23
  super(superParameters);
23
24
  this.comment = comment;
24
25
  this.description = description;
@@ -27,6 +28,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
27
28
  this.mutable = mutable;
28
29
  this.path = path;
29
30
  this.recursive = recursive;
31
+ this.type = type;
30
32
  }
31
33
  get constructorParameter() {
32
34
  const conversionFunction = this.type.conversionFunction.extract();
@@ -60,7 +62,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
60
62
  .ifJust((comment) => {
61
63
  declaration = code `${comment}${declaration}`;
62
64
  });
63
- return declaration;
65
+ return Maybe.of(declaration);
64
66
  }
65
67
  get filterProperty() {
66
68
  return Maybe.of({
@@ -161,6 +163,16 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
161
163
  }
162
164
  return Maybe.of(code `${this.name}: ${rhs}`);
163
165
  }
166
+ equalsExpression({ variables, }) {
167
+ return Maybe.of(code `${this.reusables.snippets.propertyEquals}(
168
+ { equalsFunction: ${this.type.equalsFunction}, name: ${literalOf(this.name)} },
169
+ [left, ${variables.leftObject}.${this.name}],
170
+ [right, ${variables.rightObject}.${this.name}],
171
+ )`);
172
+ }
173
+ filterExpression({ variables, }) {
174
+ return Maybe.of(code `${this.type.filterFunction}(${variables.filter}.${this.name}, ${variables.object}.${this.name})`);
175
+ }
164
176
  fromJsonInitializer({ variables, }) {
165
177
  return Maybe.of(code `${this.name}: ${this.type.fromJsonExpression({
166
178
  variables: { value: code `${variables.jsonObject}["${this.name}"]` },
@@ -178,7 +190,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
178
190
  }
179
191
  hashStatements({ variables, }) {
180
192
  return [
181
- code `${this.type.hashFunction}(${variables.hasher}, ${variables.value});`,
193
+ code `${this.type.hashFunction}(${variables.hasher}, ${variables.object}.${this.name});`,
182
194
  ];
183
195
  }
184
196
  jsonUiSchemaElement({ variables, }) {
@@ -216,8 +228,8 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
216
228
  }})`,
217
229
  });
218
230
  }
219
- toJsonInitializer(parameters) {
220
- return Maybe.of(code `${this.name}: ${this.type.toJsonExpression(parameters)}`);
231
+ toJsonInitializer({ variables, }) {
232
+ return Maybe.of(code `${this.name}: ${this.type.toJsonExpression({ variables: { value: code `${variables.object}.${this.name}` } })}`);
221
233
  }
222
234
  toRdfRdfResourceValuesStatements({ variables, }) {
223
235
  switch (this.path.termType) {
@@ -234,17 +246,23 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
234
246
  const propertyPath = this.objectType.name
235
247
  .map(() => code `${this.schemaVariable}.path`)
236
248
  .orDefault(this.propertyPathToCode(this.path));
249
+ const { object: objectVariable, ...otherVariables } = variables;
237
250
  return [
238
251
  code `${variables.resource}.add(${propertyPath}, ${this.type.toRdfResourceValuesExpression({
239
- variables: { ...variables, propertyPath },
252
+ variables: {
253
+ ...otherVariables,
254
+ propertyPath,
255
+ value: code `${objectVariable}.${this.name}`,
256
+ },
240
257
  })}, ${variables.graph});`,
241
258
  ];
242
259
  }
243
- toStringInitializer(parameters) {
260
+ toStringInitializer({ variables, }) {
244
261
  if (!this.display) {
245
262
  return Maybe.empty();
246
263
  }
247
- return Maybe.of(code `${literalOf(this.name)}: ${this.type.toStringExpression(parameters)}`);
264
+ const { object: objectVariable, ...otherVariables } = variables;
265
+ return Maybe.of(code `${literalOf(this.name)}: ${this.type.toStringExpression({ variables: { ...otherVariables, value: code `${objectVariable}.${this.name}` } })}`);
248
266
  }
249
267
  propertyPathToCode(propertyPath) {
250
268
  switch (propertyPath.termType) {
@@ -1,15 +1,12 @@
1
- import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
1
+ import { code, joinCode } from "../ts-poet-wrapper.js";
2
+ const variables = {
3
+ leftObject: code `left`,
4
+ rightObject: code `right`,
5
+ };
2
6
  export function ObjectType_equalsFunctionExpression() {
3
7
  const chain = [];
4
8
  for (const property of this.properties) {
5
- if (property.kind === "Discriminant") {
6
- continue;
7
- }
8
- chain.push(code `${this.reusables.snippets.propertyEquals}(
9
- { equalsFunction: ${property.type.equalsFunction}, name: ${literalOf(property.name)} },
10
- [left, ${property.accessExpression({ variables: { object: code `left` } })}],
11
- [right, ${property.accessExpression({ variables: { object: code `right` } })}],
12
- )`);
9
+ chain.push(...property.equalsExpression({ variables }).toList());
13
10
  }
14
11
  return code `\
15
12
  ((left, right) =>
@@ -1,9 +1,18 @@
1
1
  import { code, joinCode } from "../ts-poet-wrapper.js";
2
+ const variables = {
3
+ filter: code `filter`,
4
+ object: code `value`,
5
+ };
2
6
  export function ObjectType_filterFunctionExpression() {
3
7
  const statements = [];
4
8
  for (const property of this.properties) {
5
- property.filterProperty.ifJust(({ name }) => {
6
- statements.push(code `if (filter.${name} !== undefined && !${property.type.filterFunction}(filter.${name}, ${property.accessExpression({ variables: { object: code `value` } })})) { return false; }`);
9
+ property
10
+ .filterExpression({
11
+ variables,
12
+ })
13
+ .ifJust((filterExpression) => {
14
+ const filterProperty = property.filterProperty.unsafeCoerce();
15
+ statements.push(code `if (${variables.filter}.${filterProperty.name} !== undefined && !${filterExpression}) { return false; }`);
7
16
  });
8
17
  }
9
18
  statements.push(code `return true;`);
@@ -1,24 +1,13 @@
1
- import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
2
1
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
2
  const variables = {
4
3
  filter: code `parameters.filter`,
5
4
  focusIdentifier: code `parameters.focusIdentifier`,
5
+ ignoreRdfType: code `parameters.ignoreRdfType`,
6
6
  variablePrefix: code `parameters.variablePrefix`,
7
7
  };
8
8
  export function ObjectType_focusSparqlConstructTriplesFunctionExpression() {
9
- const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
10
- const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
11
9
  let triplesVariableDeclarationKeyword = "const";
12
10
  const statements = [];
13
- if (this.fromRdfType.isJust()) {
14
- statements.push(code `\
15
- if (!parameters?.ignoreRdfType) {
16
- triples.push(
17
- { subject: ${variables.focusIdentifier}, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} },
18
- { subject: ${rdfTypeVariable}, predicate: ${this.rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
19
- );
20
- }`);
21
- }
22
11
  for (const property of this.properties) {
23
12
  if (property.recursive) {
24
13
  continue;
@@ -1,53 +1,15 @@
1
- import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
2
1
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
- const variables = {
4
- filter: code `parameters.filter`,
5
- preferredLanguages: code `parameters.preferredLanguages`,
6
- focusIdentifier: code `parameters.focusIdentifier`,
7
- variablePrefix: code `parameters.variablePrefix`,
8
- };
9
2
  export function ObjectType_focusSparqlWherePatternsFunctionExpression() {
10
- const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
11
- const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
12
3
  let patternsVariableDeclarationKeyword = "const";
13
4
  const statements = [];
14
- this.fromRdfTypeVariable.ifJust((fromRdfTypeVariable) => {
15
- statements.push(code `const rdfTypeVariable = ${rdfTypeVariable};`, code `\
16
- if (!parameters?.ignoreRdfType) {
17
- patterns.push(
18
- ${code `${this.reusables.snippets.sparqlInstancesOfPattern}({ rdfType: ${fromRdfTypeVariable}, subject: ${variables.focusIdentifier} }),`}
19
- {
20
- triples: [
21
- {
22
- subject: ${variables.focusIdentifier},
23
- predicate: ${this.rdfjsTermExpression(rdf.type)},
24
- object: rdfTypeVariable
25
- }
26
- ],
27
- type: "bgp" as const
28
- },
29
- {
30
- patterns: [
31
- {
32
- triples: [
33
- {
34
- subject: rdfTypeVariable,
35
- predicate: {
36
- items: [${this.rdfjsTermExpression(rdfs.subClassOf)}],
37
- pathType: "+" as const,
38
- type: "path" as const
39
- },
40
- object: ${rdfClassVariable}
41
- }
42
- ],
43
- type: "bgp" as const
44
- }
45
- ],
46
- type: "optional" as const
47
- }
48
- );
49
- }`);
50
- });
5
+ const variables = {
6
+ filter: code `parameters.filter`,
7
+ preferredLanguages: code `parameters.preferredLanguages`,
8
+ focusIdentifier: code `parameters.focusIdentifier`,
9
+ ignoreRdfType: code `parameters.ignoreRdfType`,
10
+ schema: this.name.map((name) => code `${name}.schema`),
11
+ variablePrefix: code `parameters.variablePrefix`,
12
+ };
51
13
  for (const property of this.properties) {
52
14
  if (property.recursive) {
53
15
  continue;
@@ -8,16 +8,20 @@ export function ObjectType_hashFunctionExpression() {
8
8
  const propertyHashStatements = property.hashStatements({
9
9
  variables: {
10
10
  hasher: hasherVariable,
11
- value: code `${this.thisVariable}.${property.name}`,
11
+ object: code `${this.thisVariable}`,
12
12
  },
13
13
  });
14
14
  if (propertyHashStatements.length === 0) {
15
15
  continue;
16
16
  }
17
17
  statements = statements.concat(propertyHashStatements);
18
- if (!codeEquals(property.hashFunctionParameter, property.declaration)) {
18
+ const declaration = property.declaration.extract();
19
+ const hashFunctionParameter = property.hashFunctionParameter.extract();
20
+ if (declaration &&
21
+ hashFunctionParameter &&
22
+ !codeEquals(hashFunctionParameter, declaration)) {
19
23
  replacePropertyDeclarations[property.name] =
20
- code `${property.hashFunctionParameter}`;
24
+ code `${hashFunctionParameter}`;
21
25
  }
22
26
  }
23
27
  statements.push(code `return ${hasherVariable};`);
@@ -1,10 +1,7 @@
1
1
  import { invariant } from "ts-invariant";
2
- import { arrayOf, code } from "../ts-poet-wrapper.js";
2
+ import { code } from "../ts-poet-wrapper.js";
3
3
  export function ObjectType_schemaExpression() {
4
4
  const schema = {};
5
- this.fromRdfType.ifJust((fromRdfType) => {
6
- schema["fromRdfType"] = this.rdfjsTermExpression(fromRdfType);
7
- });
8
5
  const properties = {};
9
6
  for (const property of this.properties) {
10
7
  property.schema.ifJust((propertySchema) => {
@@ -13,9 +10,6 @@ export function ObjectType_schemaExpression() {
13
10
  }
14
11
  invariant(Object.keys(properties).length > 0);
15
12
  schema["properties"] = properties;
16
- if (this.toRdfTypes.length > 0) {
17
- schema["toRdfTypes"] = arrayOf(...this.toRdfTypes.map((toRdfType) => this.rdfjsTermExpression(toRdfType)));
18
- }
19
13
  return code `${schema} as const`;
20
14
  }
21
15
  //# sourceMappingURL=ObjectType_schemaExpression.js.map
@@ -2,9 +2,6 @@ import { invariant } from "ts-invariant";
2
2
  import { code } from "../ts-poet-wrapper.js";
3
3
  export function ObjectType_schemaTypeExpression() {
4
4
  const schemaType = {};
5
- this.fromRdfType.ifJust(() => {
6
- schemaType["fromRdfType"] = code `${this.reusables.imports.NamedNode}`;
7
- });
8
5
  const properties = {};
9
6
  for (const property of this.properties) {
10
7
  property.schemaType.ifJust((propertySchemaType) => {
@@ -4,9 +4,7 @@ export function ObjectType_toJsonFunctionExpression() {
4
4
  ((${this.thisVariable}) => JSON.parse(JSON.stringify({ ${joinCode(this.properties.flatMap((property) => property
5
5
  .toJsonInitializer({
6
6
  variables: {
7
- value: property.accessExpression({
8
- variables: { object: this.thisVariable },
9
- }),
7
+ object: this.thisVariable,
10
8
  },
11
9
  })
12
10
  .toList()), { on: "," })} } satisfies ${this.jsonType().expression})))`;
@@ -7,14 +7,7 @@ export function ObjectType_toRdfResourceFunctionExpression() {
7
7
  });
8
8
  for (const property of this.properties) {
9
9
  statements.push(...property.toRdfRdfResourceValuesStatements({
10
- variables: {
11
- graph: variables.graph,
12
- resource: variables.resource,
13
- resourceSet: variables.resourceSet,
14
- value: property.accessExpression({
15
- variables: { object: variables.object },
16
- }),
17
- },
10
+ variables,
18
11
  }));
19
12
  }
20
13
  statements.push(code `return ${variables.resource};`);