@shaclmate/compiler 2.0.14 → 2.0.15

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/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +17 -4
  2. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +3 -1
  3. package/generators/ts/DateTimeType.d.ts +3 -1
  4. package/generators/ts/DateTimeType.js +9 -1
  5. package/generators/ts/Import.d.ts +0 -1
  6. package/generators/ts/Import.js +0 -5
  7. package/generators/ts/ListType.d.ts +3 -2
  8. package/generators/ts/ListType.js +17 -9
  9. package/generators/ts/ObjectType.d.ts +3 -2
  10. package/generators/ts/ObjectType.js +20 -9
  11. package/generators/ts/ObjectUnionType.d.ts +1 -1
  12. package/generators/ts/ObjectUnionType.js +16 -47
  13. package/generators/ts/OptionType.d.ts +3 -1
  14. package/generators/ts/OptionType.js +12 -11
  15. package/generators/ts/PrimitiveType.d.ts +2 -2
  16. package/generators/ts/PrimitiveType.js +9 -4
  17. package/generators/ts/SetType.d.ts +3 -1
  18. package/generators/ts/SetType.js +12 -8
  19. package/generators/ts/SnippetDeclarations.d.ts +11 -0
  20. package/generators/ts/SnippetDeclarations.js +215 -0
  21. package/generators/ts/TermType.d.ts +3 -1
  22. package/generators/ts/TermType.js +16 -8
  23. package/generators/ts/TsGenerator.js +15 -1
  24. package/generators/ts/Type.d.ts +15 -5
  25. package/generators/ts/Type.js +17 -0
  26. package/generators/ts/TypeFactory.js +14 -4
  27. package/generators/ts/UnionType.d.ts +2 -1
  28. package/generators/ts/UnionType.js +3 -3
  29. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +4 -5
  30. package/generators/ts/_ObjectType/IdentifierProperty.js +16 -7
  31. package/generators/ts/_ObjectType/Property.d.ts +17 -3
  32. package/generators/ts/_ObjectType/Property.js +2 -1
  33. package/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -0
  34. package/generators/ts/_ObjectType/ShaclProperty.js +4 -1
  35. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +3 -5
  36. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +11 -4
  37. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +1 -1
  38. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +1 -1
  39. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +1 -1
  40. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
  41. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
  42. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
  43. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
  44. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +35 -58
  45. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +1 -1
  46. package/input/generated.d.ts +15 -14
  47. package/input/generated.js +20 -4
  48. package/input/tsFeatures.d.ts +1 -1
  49. package/input/tsFeatures.js +17 -13
  50. package/package.json +4 -4
@@ -1,7 +1,7 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Either, Left } from "purify-ts";
3
3
  import { invariant } from "ts-invariant";
4
- import { TsFeature } from "../enums/TsFeature.js";
4
+ import { TsFeature } from "../enums/index.js";
5
5
  import * as input from "../input/index.js";
6
6
  import { logger } from "../logger.js";
7
7
  import { pickLiteral } from "./pickLiteral.js";
@@ -106,9 +106,22 @@ export function transformNodeShapeToAstType(nodeShape) {
106
106
  tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
107
107
  };
108
108
  this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, compositeType);
109
- compositeType.memberTypes.push(...Either.rights(compositeTypeNodeShapes.map((nodeShape) => this.transformNodeShapeToAstType(nodeShape))).filter((nodeShapeAstType) => nodeShapeAstType.kind === "ObjectType"));
110
- if (compositeType.memberTypes.length < compositeTypeNodeShapes.length) {
111
- return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
109
+ for (const memberNodeShape of compositeTypeNodeShapes) {
110
+ const memberAstTypeEither = this.transformNodeShapeToAstType(memberNodeShape);
111
+ if (memberAstTypeEither.isLeft()) {
112
+ return memberAstTypeEither;
113
+ }
114
+ const memberAstType = memberAstTypeEither.unsafeCoerce();
115
+ switch (memberAstType.kind) {
116
+ case "ObjectType":
117
+ compositeType.memberTypes.push(memberAstType);
118
+ break;
119
+ case "ObjectUnionType":
120
+ compositeType.memberTypes.push(...memberAstType.memberTypes);
121
+ break;
122
+ default:
123
+ return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
124
+ }
112
125
  }
113
126
  return Either.of(compositeType);
114
127
  }
@@ -95,7 +95,9 @@ export function transformPropertyShapeToAstCompositeType(shape, inherited) {
95
95
  invariant(memberTypeEithers.length > 0);
96
96
  const memberTypes = Either.rights(memberTypeEithers);
97
97
  if (memberTypes.length !== memberTypeEithers.length) {
98
- logger.warn("shape %s composition did not map all member types successfully", shape);
98
+ logger.warn("shape %s composition did not map all member types successfully: %s", shape, Either.lefts(memberTypeEithers)
99
+ .map((left) => left.message)
100
+ .join("; "));
99
101
  return memberTypeEithers[0];
100
102
  }
101
103
  invariant(memberTypes.length > 0);
@@ -1,7 +1,8 @@
1
+ import type { TsFeature } from "../../enums/index.js";
1
2
  import { PrimitiveType } from "./PrimitiveType.js";
2
3
  import type { Type } from "./Type.js";
3
4
  export declare class DateTimeType extends PrimitiveType<Date> {
4
- readonly equalsFunction = "(left, right) => purifyHelpers.Equatable.EqualsResult.fromBooleanEqualsResult(left, right, left.getTime() === right.getTime())";
5
+ readonly equalsFunction = "dateEquals";
5
6
  readonly kind = "DateTimeType";
6
7
  readonly mutable = true;
7
8
  get conversions(): readonly Type.Conversion[];
@@ -11,6 +12,7 @@ export declare class DateTimeType extends PrimitiveType<Date> {
11
12
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
12
13
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
13
14
  propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["propertyFromRdfResourceValueExpression"]>[0]): string;
15
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
14
16
  toJsonExpression({ variables, }: Parameters<PrimitiveType<Date>["toJsonExpression"]>[0]): string;
15
17
  toRdfExpression({ variables, }: Parameters<PrimitiveType<Date>["toRdfExpression"]>[0]): string;
16
18
  }
@@ -1,9 +1,10 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
2
3
  import { objectInitializer } from "./objectInitializer.js";
3
4
  export class DateTimeType extends PrimitiveType {
4
5
  constructor() {
5
6
  super(...arguments);
6
- this.equalsFunction = "(left, right) => purifyHelpers.Equatable.EqualsResult.fromBooleanEqualsResult(left, right, left.getTime() === right.getTime())";
7
+ this.equalsFunction = "dateEquals";
7
8
  this.kind = "DateTimeType";
8
9
  this.mutable = true;
9
10
  }
@@ -46,6 +47,13 @@ export class DateTimeType extends PrimitiveType {
46
47
  }
47
48
  return expression;
48
49
  }
50
+ snippetDeclarations(features) {
51
+ const snippetDeclarations = [];
52
+ if (features.has("equals")) {
53
+ snippetDeclarations.push(SnippetDeclarations.dateEquals);
54
+ }
55
+ return snippetDeclarations;
56
+ }
49
57
  toJsonExpression({ variables, }) {
50
58
  return `${variables.value}.toISOString()`;
51
59
  }
@@ -5,7 +5,6 @@ export type Import = ImportDeclarationStructure | string;
5
5
  */
6
6
  export declare namespace Import {
7
7
  const PURIFY: Import;
8
- const PURIFY_HELPERS: Import;
9
8
  const RDF_LITERAL: Import;
10
9
  const RDFJS_RESOURCE: Import;
11
10
  const RDFJS_TYPES: Import;
@@ -9,11 +9,6 @@ export var Import;
9
9
  moduleSpecifier: "purify-ts",
10
10
  namespaceImport: "purify",
11
11
  };
12
- Import.PURIFY_HELPERS = {
13
- kind: StructureKind.ImportDeclaration,
14
- moduleSpecifier: "purify-ts-helpers",
15
- namespaceImport: "purifyHelpers",
16
- };
17
12
  Import.RDF_LITERAL = {
18
13
  kind: StructureKind.ImportDeclaration,
19
14
  moduleSpecifier: "rdf-literal",
@@ -1,6 +1,6 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
- import type { MintingStrategy } from "../../enums/index.js";
3
+ import type { MintingStrategy, TsFeature } from "../../enums/index.js";
4
4
  import { Import } from "./Import.js";
5
5
  import { Type } from "./Type.js";
6
6
  export declare class ListType extends Type {
@@ -22,15 +22,16 @@ export declare class ListType extends Type {
22
22
  get equalsFunction(): string;
23
23
  get jsonName(): string;
24
24
  get name(): string;
25
- get useImports(): readonly Import[];
26
25
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
27
26
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
28
27
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
29
28
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
30
29
  jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
30
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
31
31
  sparqlConstructTemplateTriples({ variables, context, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
32
32
  sparqlWherePatterns({ variables, context, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
33
33
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
34
34
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
35
+ useImports(features: Set<TsFeature>): readonly Import[];
35
36
  }
36
37
  //# sourceMappingURL=ListType.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { Import } from "./Import.js";
4
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
4
5
  import { Type } from "./Type.js";
5
6
  import { objectInitializer } from "./objectInitializer.js";
6
7
  export class ListType extends Type {
@@ -26,7 +27,7 @@ export class ListType extends Type {
26
27
  return Maybe.empty();
27
28
  }
28
29
  get equalsFunction() {
29
- return `((left, right) => purifyHelpers.Arrays.equals(left, right, ${this.itemType.equalsFunction}))`;
30
+ return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
30
31
  }
31
32
  get jsonName() {
32
33
  return `readonly (${this.itemType.jsonName})[]`;
@@ -34,13 +35,6 @@ export class ListType extends Type {
34
35
  get name() {
35
36
  return `${this.mutable ? "" : "readonly "}${this.itemType.name}[]`;
36
37
  }
37
- get useImports() {
38
- const imports = this.itemType.useImports.concat();
39
- if (this.identifierNodeKind === "NamedNode") {
40
- imports.push(Import.SHA256);
41
- }
42
- return imports;
43
- }
44
38
  fromJsonExpression({ variables, }) {
45
39
  return `${variables.value}.map(_item => (${this.itemType.fromJsonExpression({ variables: { value: "_item" } })}))`;
46
40
  }
@@ -62,6 +56,13 @@ export class ListType extends Type {
62
56
  jsonZodSchema(parameters) {
63
57
  return `${this.itemType.jsonZodSchema(parameters)}.array()`;
64
58
  }
59
+ snippetDeclarations(features) {
60
+ const snippetDeclarations = [];
61
+ if (features.has("equals")) {
62
+ snippetDeclarations.push(SnippetDeclarations.arrayEquals);
63
+ }
64
+ return snippetDeclarations;
65
+ }
65
66
  sparqlConstructTemplateTriples({ variables, context, }) {
66
67
  switch (context) {
67
68
  case "property":
@@ -170,7 +171,7 @@ export class ListType extends Type {
170
171
  subject: restNVariable,
171
172
  predicate: this.rdfjsTermExpression(rdf.first),
172
173
  object: itemNVariable,
173
- })}] }`, ...this.itemType.sparqlConstructTemplateTriples({
174
+ })}] }`, ...this.itemType.sparqlWherePatterns({
174
175
  context: "type",
175
176
  variables: {
176
177
  subject: itemNVariable,
@@ -269,5 +270,12 @@ export class ListType extends Type {
269
270
  },
270
271
  ).listResource.identifier`;
271
272
  }
273
+ useImports(features) {
274
+ const imports = this.itemType.useImports(features).concat();
275
+ if (features.has("hash") && this.identifierNodeKind === "NamedNode") {
276
+ imports.push(Import.SHA256);
277
+ }
278
+ return imports;
279
+ }
272
280
  }
273
281
  //# sourceMappingURL=ListType.js.map
@@ -1,7 +1,7 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { type ClassDeclarationStructure, type InterfaceDeclarationStructure, type ModuleDeclarationStructure } from "ts-morph";
4
- import type { MintingStrategy, TsObjectDeclarationType } from "../../enums/index.js";
4
+ import type { MintingStrategy, TsFeature, TsObjectDeclarationType } from "../../enums/index.js";
5
5
  import { DeclaredType } from "./DeclaredType.js";
6
6
  import type { IdentifierType } from "./IdentifierType.js";
7
7
  import { Import } from "./Import.js";
@@ -56,7 +56,6 @@ export declare class ObjectType extends DeclaredType {
56
56
  get ownProperties(): readonly ObjectType.Property[];
57
57
  get parentObjectTypes(): readonly ObjectType[];
58
58
  get properties(): readonly ObjectType.Property[];
59
- get useImports(): readonly Import[];
60
59
  protected get thisVariable(): string;
61
60
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
62
61
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
@@ -74,10 +73,12 @@ export declare class ObjectType extends DeclaredType {
74
73
  readonly name: string;
75
74
  readonly named: boolean;
76
75
  };
76
+ snippetDeclarations(): readonly string[];
77
77
  sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
78
78
  sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
79
79
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
80
80
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
81
+ useImports(_features: Set<TsFeature>): readonly Import[];
81
82
  protected ensureAtMostOneSuperObjectType(): void;
82
83
  }
83
84
  export declare namespace ObjectType {
@@ -11,6 +11,7 @@ import { StructureKind, } from "ts-morph";
11
11
  import { Memoize } from "typescript-memoize";
12
12
  import { DeclaredType } from "./DeclaredType.js";
13
13
  import { Import } from "./Import.js";
14
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
14
15
  import * as _ObjectType from "./_ObjectType/index.js";
15
16
  import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
16
17
  import { objectInitializer } from "./objectInitializer.js";
@@ -58,9 +59,6 @@ export class ObjectType extends DeclaredType {
58
59
  return [];
59
60
  }
60
61
  const imports = this.properties.flatMap((property) => property.declarationImports);
61
- if (this.features.has("equals")) {
62
- imports.push(Import.PURIFY_HELPERS);
63
- }
64
62
  if (this.features.has("fromJson") || this.features.has("jsonSchema")) {
65
63
  imports.push(Import.ZOD);
66
64
  }
@@ -69,7 +67,6 @@ export class ObjectType extends DeclaredType {
69
67
  }
70
68
  if (this.features.has("fromRdf") || this.features.has("toRdf")) {
71
69
  imports.push(Import.PURIFY);
72
- imports.push(Import.PURIFY_HELPERS);
73
70
  imports.push(Import.RDFJS_RESOURCE);
74
71
  }
75
72
  if (this.features.has("sparql")) {
@@ -117,7 +114,7 @@ export class ObjectType extends DeclaredType {
117
114
  get equalsFunction() {
118
115
  switch (this.declarationType) {
119
116
  case "class":
120
- return "purifyHelpers.Equatable.equals";
117
+ return "((left, right) => left.equals(right))";
121
118
  case "interface":
122
119
  return `${this.name}.equals`;
123
120
  default:
@@ -152,7 +149,7 @@ export class ObjectType extends DeclaredType {
152
149
  if (this.features.has("fromJson")) {
153
150
  return `Parameters<typeof ${this.name}.fromJson>[0]`;
154
151
  }
155
- throw new RangeError("jsonName called when neither fromJson nor toJson features are enabled");
152
+ throw new RangeError(`${this.name}: jsonName called when neither fromJson nor toJson features are enabled`);
156
153
  }
157
154
  get jsonUiSchemaFunctionName() {
158
155
  if (this.ancestorObjectTypes.length > 0 ||
@@ -194,9 +191,6 @@ export class ObjectType extends DeclaredType {
194
191
  }
195
192
  return properties;
196
193
  }
197
- get useImports() {
198
- return this.imports;
199
- }
200
194
  get thisVariable() {
201
195
  switch (this.declarationType) {
202
196
  case "class":
@@ -244,6 +238,20 @@ export class ObjectType extends DeclaredType {
244
238
  named: this.identifierType.isNamedNodeKind,
245
239
  };
246
240
  }
241
+ snippetDeclarations() {
242
+ const snippetDeclarations = [];
243
+ if (this.features.has("equals")) {
244
+ snippetDeclarations.push(SnippetDeclarations.EqualsResult);
245
+ }
246
+ if ((this.features.has("fromJson") || this.features.has("fromRdf")) &&
247
+ this.parentObjectTypes.length > 0) {
248
+ snippetDeclarations.push(SnippetDeclarations.UnwrapR);
249
+ }
250
+ for (const property of this.ownProperties) {
251
+ snippetDeclarations.push(...property.snippetDeclarations);
252
+ }
253
+ return snippetDeclarations;
254
+ }
247
255
  sparqlConstructTemplateTriples({ context, variables, }) {
248
256
  switch (context) {
249
257
  case "property":
@@ -288,6 +296,9 @@ export class ObjectType extends DeclaredType {
288
296
  return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
289
297
  }
290
298
  }
299
+ useImports(_features) {
300
+ return this.imports;
301
+ }
291
302
  ensureAtMostOneSuperObjectType() {
292
303
  if (this.parentObjectTypes.length > 1) {
293
304
  throw new RangeError(`object type '${this.name}' has multiple super object types`);
@@ -34,7 +34,6 @@ export declare class ObjectUnionType extends DeclaredType {
34
34
  get equalsFunction(): string;
35
35
  get jsonName(): string;
36
36
  get mutable(): boolean;
37
- get useImports(): readonly Import[];
38
37
  protected get thisVariable(): string;
39
38
  private get equalsFunctionDeclaration();
40
39
  private get fromJsonFunctionDeclaration();
@@ -53,6 +52,7 @@ export declare class ObjectUnionType extends DeclaredType {
53
52
  sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
54
53
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
55
54
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
55
+ useImports(): readonly Import[];
56
56
  private rdfjsResourceType;
57
57
  }
58
58
  //# sourceMappingURL=ObjectUnionType.d.ts.map
@@ -11,6 +11,8 @@ import { StructureKind, } from "ts-morph";
11
11
  import { Memoize } from "typescript-memoize";
12
12
  import { DeclaredType } from "./DeclaredType.js";
13
13
  import { hasherTypeConstraint } from "./_ObjectType/hashFunctionOrMethodDeclaration.js";
14
+ import { sparqlConstructQueryFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryFunctionDeclaration.js";
15
+ import { sparqlConstructQueryStringFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js";
14
16
  import { objectInitializer } from "./objectInitializer.js";
15
17
  import { tsComment } from "./tsComment.js";
16
18
  /**
@@ -53,7 +55,7 @@ export class ObjectUnionType extends DeclaredType {
53
55
  ];
54
56
  }
55
57
  get declarationImports() {
56
- return this.memberTypes.flatMap((memberType) => memberType.useImports);
58
+ return this.memberTypes.flatMap((memberType) => memberType.useImports(this.features));
57
59
  }
58
60
  get declarations() {
59
61
  const declarations = [this.typeAliasDeclaration];
@@ -91,9 +93,6 @@ export class ObjectUnionType extends DeclaredType {
91
93
  get mutable() {
92
94
  return this.memberTypes.some((memberType) => memberType.mutable);
93
95
  }
94
- get useImports() {
95
- return [];
96
- }
97
96
  get thisVariable() {
98
97
  return `_${camelCase(this.name)}`;
99
98
  }
@@ -127,9 +126,9 @@ export class ObjectUnionType extends DeclaredType {
127
126
  type: this.name,
128
127
  },
129
128
  ],
130
- returnType: "purifyHelpers.Equatable.EqualsResult",
129
+ returnType: "EqualsResult",
131
130
  statements: `\
132
- return purifyHelpers.Equatable.strictEquals(left.type, right.type).chain(() => {
131
+ return strictEquals(left.type, right.type).chain(() => {
133
132
  switch (left.${this._discriminatorProperty.name}) {
134
133
  ${caseBlocks.join(" ")}
135
134
  }
@@ -244,54 +243,22 @@ return purifyHelpers.Equatable.strictEquals(left.type, right.type).chain(() => {
244
243
  return [];
245
244
  }
246
245
  return [
247
- {
248
- isExported: true,
249
- kind: StructureKind.Function,
250
- name: "sparqlConstructQuery",
251
- parameters: [
252
- {
253
- hasQuestionToken: true,
254
- name: "parameters",
255
- type: '{ prefixes?: { [prefix: string]: string }; subject: rdfjs.Variable } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "template" | "where">',
256
- },
257
- ],
258
- returnType: "sparqljs.ConstructQuery",
259
- statements: [
260
- `const subject = parameters?.subject ?? ${this.dataFactoryVariable}.variable!("${camelCase(this.name)}");`,
261
- `return { ...parameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: ${this.name}.sparqlConstructTemplateTriples({ subject }).concat(), type: "query", where: ${this.name}.sparqlWherePatterns({ subject }).concat() };`,
262
- ],
263
- },
264
- {
265
- isExported: true,
266
- kind: StructureKind.Function,
267
- name: "sparqlConstructQueryString",
268
- parameters: [
269
- {
270
- hasQuestionToken: true,
271
- name: "parameters",
272
- type: '{ subject: rdfjs.Variable } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "template" | "where"> & sparqljs.GeneratorOptions',
273
- },
274
- ],
275
- returnType: "string",
276
- statements: [
277
- `return new sparqljs.Generator(parameters).stringify(${this.name}.sparqlConstructQuery(parameters));`,
278
- ],
279
- },
246
+ sparqlConstructQueryFunctionDeclaration.bind(this)(),
247
+ sparqlConstructQueryStringFunctionDeclaration.bind(this)(),
280
248
  {
281
249
  isExported: true,
282
250
  kind: StructureKind.Function,
283
251
  name: "sparqlConstructTemplateTriples",
284
252
  parameters: [
285
253
  {
286
- name: "{ subject, variablePrefix: variablePrefixParameter }",
287
- type: "{ subject: rdfjs.Variable, variablePrefix?: string }",
254
+ name: "parameters",
255
+ type: '{ ignoreRdfType?: boolean, subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
288
256
  },
289
257
  ],
290
258
  returnType: "readonly sparqljs.Triple[]",
291
259
  statements: [
292
- "const variablePrefix = variablePrefixParameter ?? subject.value;",
293
260
  `return [${this.memberTypes
294
- .map((memberType) => `...${memberType.name}.sparqlConstructTemplateTriples({ subject, variablePrefix: \`\${variablePrefix}${pascalCase(memberType.name)}\` }).concat()`)
261
+ .map((memberType) => `...${memberType.name}.sparqlConstructTemplateTriples({ ignoreRdfType: parameters?.ignoreRdfType, subject: parameters.subject ?? ${this.dataFactoryVariable}.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`)
295
262
  .join(", ")}];`,
296
263
  ],
297
264
  },
@@ -301,16 +268,15 @@ return purifyHelpers.Equatable.strictEquals(left.type, right.type).chain(() => {
301
268
  name: "sparqlWherePatterns",
302
269
  parameters: [
303
270
  {
304
- name: "{ subject, variablePrefix: variablePrefixParameter }",
305
- type: "{ subject: rdfjs.Variable, variablePrefix?: string }",
271
+ name: "parameters",
272
+ type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
306
273
  },
307
274
  ],
308
275
  returnType: "readonly sparqljs.Pattern[]",
309
276
  statements: [
310
- "const variablePrefix = variablePrefixParameter ?? subject.value;",
311
277
  `return [{ patterns: [${this.memberTypes
312
278
  .map((memberType) => objectInitializer({
313
- patterns: `${memberType.name}.sparqlWherePatterns({ subject, variablePrefix: \`\${variablePrefix}${pascalCase(memberType.name)}\` }).concat()`,
279
+ patterns: `${memberType.name}.sparqlWherePatterns({ ignoreRdfType: parameters?.ignoreRdfType, subject: parameters.subject ?? ${this.dataFactoryVariable}.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`,
314
280
  type: '"group"',
315
281
  }))
316
282
  .join(", ")}], type: "union" }];`,
@@ -456,6 +422,9 @@ return purifyHelpers.Equatable.strictEquals(left.type, right.type).chain(() => {
456
422
  return `${this.name}.toRdf(${variables.value}, ${options})`;
457
423
  }
458
424
  }
425
+ useImports() {
426
+ return [];
427
+ }
459
428
  rdfjsResourceType(options) {
460
429
  const memberRdfjsResourceTypes = [];
461
430
  for (const memberType of this.memberTypes) {
@@ -1,3 +1,4 @@
1
+ import type { TsFeature } from "../../enums/index.js";
1
2
  import { Import } from "./Import.js";
2
3
  import { Type } from "./Type.js";
3
4
  export declare class OptionType extends Type {
@@ -11,15 +12,16 @@ export declare class OptionType extends Type {
11
12
  get jsonName(): string;
12
13
  get mutable(): boolean;
13
14
  get name(): string;
14
- get useImports(): readonly Import[];
15
15
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
16
16
  fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
17
17
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
18
18
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
19
19
  jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
20
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
20
21
  sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
21
22
  sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
22
23
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
23
24
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
25
+ useImports(features: Set<TsFeature>): readonly Import[];
24
26
  }
25
27
  //# sourceMappingURL=OptionType.d.ts.map
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Memoize } from "typescript-memoize";
8
8
  import { Import } from "./Import.js";
9
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
9
10
  import { Type } from "./Type.js";
10
11
  export class OptionType extends Type {
11
12
  constructor({ itemType, ...superParameters }) {
@@ -36,14 +37,7 @@ export class OptionType extends Type {
36
37
  return conversions;
37
38
  }
38
39
  get equalsFunction() {
39
- const itemTypeEqualsFunction = this.itemType.equalsFunction;
40
- if (itemTypeEqualsFunction === "purifyHelpers.Equatable.equals") {
41
- return "purifyHelpers.Equatable.maybeEquals";
42
- }
43
- if (itemTypeEqualsFunction === "purifyHelpers.Equatable.strictEquals") {
44
- return "purifyHelpers.Equatable.booleanEquals"; // Use Maybe.equals
45
- }
46
- return `(left, right) => purifyHelpers.Maybes.equals(left, right, ${itemTypeEqualsFunction})`;
40
+ return `((left, right) => maybeEquals(left, right, ${this.itemType.equalsFunction}))`;
47
41
  }
48
42
  get jsonName() {
49
43
  return `(${this.itemType.jsonName}) | undefined`;
@@ -54,9 +48,6 @@ export class OptionType extends Type {
54
48
  get name() {
55
49
  return `purify.Maybe<${this.itemType.name}>`;
56
50
  }
57
- get useImports() {
58
- return [...this.itemType.useImports, Import.PURIFY];
59
- }
60
51
  fromJsonExpression({ variables, }) {
61
52
  const expression = `purify.Maybe.fromNullable(${variables.value})`;
62
53
  const itemFromJsonExpression = this.itemType.fromJsonExpression({
@@ -88,6 +79,13 @@ export class OptionType extends Type {
88
79
  jsonZodSchema(parameters) {
89
80
  return `${this.itemType.jsonZodSchema(parameters)}.optional()`;
90
81
  }
82
+ snippetDeclarations(features) {
83
+ const snippetDeclarations = [];
84
+ if (features.has("equals")) {
85
+ snippetDeclarations.push(SnippetDeclarations.maybeEquals);
86
+ }
87
+ return snippetDeclarations;
88
+ }
91
89
  sparqlConstructTemplateTriples({ context, variables, }) {
92
90
  switch (context) {
93
91
  case "property":
@@ -125,6 +123,9 @@ export class OptionType extends Type {
125
123
  }
126
124
  return `${variables.value}.map((_value) => ${itemTypeToRdfExpression})`;
127
125
  }
126
+ useImports(features) {
127
+ return [...this.itemType.useImports(features), Import.PURIFY];
128
+ }
128
129
  }
129
130
  __decorate([
130
131
  Memoize()
@@ -1,5 +1,5 @@
1
1
  import { Maybe } from "purify-ts";
2
- import type { Import } from "./Import.js";
2
+ import type { TsFeature } from "../../enums/index.js";
3
3
  import { LiteralType } from "./LiteralType.js";
4
4
  import type { Type } from "./Type.js";
5
5
  export declare abstract class PrimitiveType<ValueT extends boolean | Date | string | number> extends LiteralType {
@@ -12,9 +12,9 @@ export declare abstract class PrimitiveType<ValueT extends boolean | Date | stri
12
12
  } & ConstructorParameters<typeof LiteralType>[0]);
13
13
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
14
14
  get jsonName(): string;
15
- get useImports(): readonly Import[];
16
15
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
17
16
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
17
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
18
18
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
19
19
  protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<LiteralType["propertyFilterRdfResourceValuesExpression"]>[0]): string;
20
20
  }
@@ -1,9 +1,10 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { LiteralType } from "./LiteralType.js";
3
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
3
4
  export class PrimitiveType extends LiteralType {
4
5
  constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
5
6
  super(superParameters);
6
- this.equalsFunction = "purifyHelpers.Equatable.strictEquals";
7
+ this.equalsFunction = "strictEquals";
7
8
  this.primitiveDefaultValue = primitiveDefaultValue;
8
9
  this.primitiveIn = primitiveIn;
9
10
  }
@@ -13,15 +14,19 @@ export class PrimitiveType extends LiteralType {
13
14
  get jsonName() {
14
15
  return this.name;
15
16
  }
16
- get useImports() {
17
- return [];
18
- }
19
17
  fromJsonExpression({ variables, }) {
20
18
  return variables.value;
21
19
  }
22
20
  hashStatements({ variables, }) {
23
21
  return [`${variables.hasher}.update(${variables.value}.toString());`];
24
22
  }
23
+ snippetDeclarations(features) {
24
+ const snippetDeclarations = [];
25
+ if (features.has("equals")) {
26
+ snippetDeclarations.push(SnippetDeclarations.strictEquals);
27
+ }
28
+ return snippetDeclarations;
29
+ }
25
30
  toJsonExpression({ variables, }) {
26
31
  return variables.value;
27
32
  }
@@ -1,3 +1,4 @@
1
+ import type { TsFeature } from "../../enums/index.js";
1
2
  import type { Import } from "./Import.js";
2
3
  import { Type } from "./Type.js";
3
4
  export declare class SetType extends Type {
@@ -13,15 +14,16 @@ export declare class SetType extends Type {
13
14
  get jsonName(): string;
14
15
  get mutable(): boolean;
15
16
  get name(): string;
16
- get useImports(): readonly Import[];
17
17
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
18
18
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
19
19
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
20
20
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
21
21
  jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
22
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
22
23
  sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
23
24
  sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
24
25
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
25
26
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
27
+ useImports(features: Set<TsFeature>): readonly Import[];
26
28
  }
27
29
  //# sourceMappingURL=SetType.d.ts.map