@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
@@ -24,9 +24,69 @@ import { UnionType } from "./UnionType.js";
24
24
  import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
25
25
  import { tsName } from "./tsName.js";
26
26
  export class TypeFactory {
27
+ cachedBooleanType = new BooleanType({
28
+ defaultValue: Maybe.empty(),
29
+ hasValues: [],
30
+ in_: [],
31
+ languageIn: [],
32
+ primitiveDefaultValue: Maybe.empty(),
33
+ primitiveIn: [],
34
+ });
35
+ cachedDateType = new DateType({
36
+ defaultValue: Maybe.empty(),
37
+ hasValues: [],
38
+ in_: [],
39
+ languageIn: [],
40
+ primitiveDefaultValue: Maybe.empty(),
41
+ primitiveIn: [],
42
+ });
43
+ cachedDateTimeType = new DateTimeType({
44
+ defaultValue: Maybe.empty(),
45
+ hasValues: [],
46
+ in_: [],
47
+ languageIn: [],
48
+ primitiveDefaultValue: Maybe.empty(),
49
+ primitiveIn: [],
50
+ });
51
+ cachedFloatType = new FloatType({
52
+ defaultValue: Maybe.empty(),
53
+ hasValues: [],
54
+ in_: [],
55
+ languageIn: [],
56
+ primitiveDefaultValue: Maybe.empty(),
57
+ primitiveIn: [],
58
+ });
59
+ cachedIdentifierType = new IdentifierType({
60
+ defaultValue: Maybe.empty(),
61
+ hasValues: [],
62
+ in_: [],
63
+ nodeKinds: new Set(["BlankNode", "NamedNode"]),
64
+ });
65
+ cachedIntType = new IntType({
66
+ defaultValue: Maybe.empty(),
67
+ hasValues: [],
68
+ in_: [],
69
+ languageIn: [],
70
+ primitiveDefaultValue: Maybe.empty(),
71
+ primitiveIn: [],
72
+ });
73
+ cachedNamedIdentifierType = new IdentifierType({
74
+ defaultValue: Maybe.empty(),
75
+ hasValues: [],
76
+ in_: [],
77
+ nodeKinds: new Set(["NamedNode"]),
78
+ });
27
79
  cachedObjectTypePropertiesByIdentifier = new TermMap();
28
80
  cachedObjectTypesByIdentifier = new TermMap();
29
81
  cachedObjectUnionTypesByIdentifier = new TermMap();
82
+ cachedStringType = new StringType({
83
+ defaultValue: Maybe.empty(),
84
+ hasValues: [],
85
+ in_: [],
86
+ languageIn: [],
87
+ primitiveDefaultValue: Maybe.empty(),
88
+ primitiveIn: [],
89
+ });
30
90
  createObjectTypeFromAstType(astType) {
31
91
  {
32
92
  const cachedObjectType = this.cachedObjectTypesByIdentifier.get(astType.name.identifier);
@@ -106,21 +166,14 @@ export class TypeFactory {
106
166
  own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
107
167
  name: `${syntheticNamePrefix}identifierPrefix`,
108
168
  objectType,
109
- type: new StringType({
110
- defaultValue: Maybe.empty(),
111
- hasValues: [],
112
- in_: [],
113
- languageIn: [],
114
- primitiveDefaultValue: Maybe.empty(),
115
- primitiveIn: [],
116
- }),
169
+ type: this.cachedStringType,
117
170
  visibility: "protected",
118
171
  }));
119
172
  }
120
173
  // Every ObjectType has an identifier property. Some are abstract.
121
174
  properties.splice(0, 0, new ObjectType.IdentifierProperty({
122
175
  abstract: astType.abstract,
123
- classGetAccessorScope: (() => {
176
+ getAccessorScope: (() => {
124
177
  if (astType.abstract) {
125
178
  return Maybe.empty();
126
179
  }
@@ -130,7 +183,12 @@ export class TypeFactory {
130
183
  }
131
184
  return Maybe.empty();
132
185
  })(),
133
- classPropertyDeclarationVisibility: (() => {
186
+ identifierMintingStrategy: astType.identifierMintingStrategy,
187
+ identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
188
+ name: `${syntheticNamePrefix}identifier`,
189
+ objectType,
190
+ override: astType.parentObjectTypes.length > 0,
191
+ propertyDeclarationVisibility: (() => {
134
192
  if (astType.abstract) {
135
193
  // If the type is abstract, don't declare an identifier property.
136
194
  return Maybe.empty();
@@ -145,11 +203,6 @@ export class TypeFactory {
145
203
  }
146
204
  return Maybe.of("private");
147
205
  })(),
148
- identifierMintingStrategy: astType.identifierMintingStrategy,
149
- identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
150
- name: `${syntheticNamePrefix}identifier`,
151
- objectType,
152
- override: astType.parentObjectTypes.length > 0,
153
206
  type: identifierType,
154
207
  typeAlias: `${staticModuleName}.${syntheticNamePrefix}Identifier`,
155
208
  visibility: "public",
@@ -168,6 +221,17 @@ export class TypeFactory {
168
221
  createTypeFromAstType(astType) {
169
222
  switch (astType.kind) {
170
223
  case "IdentifierType":
224
+ if (astType.defaultValue.isNothing() &&
225
+ astType.hasValues.length === 0 &&
226
+ astType.in_.length === 0) {
227
+ if (astType.nodeKinds.size === 2) {
228
+ return this.cachedIdentifierType;
229
+ }
230
+ if (astType.nodeKinds.size === 1 &&
231
+ astType.nodeKinds.has("NamedNode")) {
232
+ return this.cachedNamedIdentifierType;
233
+ }
234
+ }
171
235
  return new IdentifierType({
172
236
  defaultValue: astType.defaultValue,
173
237
  hasValues: astType.hasValues,
@@ -201,6 +265,11 @@ export class TypeFactory {
201
265
  if (datatypes.size === 1) {
202
266
  const datatype = [...datatypes][0];
203
267
  if (datatype.equals(xsd.boolean)) {
268
+ if (astType.defaultValue.isNothing() &&
269
+ astType.hasValues.length === 0 &&
270
+ astType.in_.length === 0) {
271
+ return this.cachedBooleanType;
272
+ }
204
273
  return new BooleanType({
205
274
  defaultValue: astType.defaultValue,
206
275
  hasValues: astType.hasValues,
@@ -215,6 +284,13 @@ export class TypeFactory {
215
284
  });
216
285
  }
217
286
  if (datatype.equals(xsd.date) || datatype.equals(xsd.dateTime)) {
287
+ if (astType.defaultValue.isNothing() &&
288
+ astType.hasValues.length === 0 &&
289
+ astType.in_.length === 0) {
290
+ return datatype.equals(xsd.date)
291
+ ? this.cachedDateType
292
+ : this.cachedDateTimeType;
293
+ }
218
294
  return new (datatype.equals(xsd.date) ? DateType : DateTimeType)({
219
295
  defaultValue: astType.defaultValue,
220
296
  hasValues: astType.hasValues,
@@ -231,6 +307,13 @@ export class TypeFactory {
231
307
  for (const [floatOrInt, numberDatatypes_] of Object.entries(numberDatatypes)) {
232
308
  for (const numberDatatype of numberDatatypes_) {
233
309
  if (datatype.equals(numberDatatype)) {
310
+ if (astType.defaultValue.isNothing() &&
311
+ astType.hasValues.length === 0 &&
312
+ astType.in_.length === 0) {
313
+ return floatOrInt === "float"
314
+ ? this.cachedFloatType
315
+ : this.cachedIntType;
316
+ }
234
317
  return new (floatOrInt === "float" ? FloatType : IntType)({
235
318
  defaultValue: astType.defaultValue,
236
319
  hasValues: astType.hasValues,
@@ -247,6 +330,11 @@ export class TypeFactory {
247
330
  }
248
331
  }
249
332
  if (datatype.equals(xsd.anyURI) || datatype.equals(xsd.string)) {
333
+ if (astType.defaultValue.isNothing() &&
334
+ astType.hasValues.length === 0 &&
335
+ astType.in_.length === 0) {
336
+ return this.cachedStringType;
337
+ }
250
338
  return new StringType({
251
339
  defaultValue: astType.defaultValue,
252
340
  hasValues: astType.hasValues,
@@ -329,6 +417,14 @@ export class TypeFactory {
329
417
  stubType,
330
418
  });
331
419
  }
420
+ else if (resolvedType instanceof ObjectType ||
421
+ resolvedType instanceof ObjectUnionType) {
422
+ invariant(stubType instanceof ObjectType || stubType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
423
+ lazyType = new ObjectType.LazyShaclProperty.RequiredObjectType({
424
+ resolvedType: resolvedType,
425
+ stubType: stubType,
426
+ });
427
+ }
332
428
  else if (resolvedType instanceof SetType) {
333
429
  invariant(resolvedType.itemType instanceof ObjectType ||
334
430
  resolvedType.itemType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind} ${resolvedType.itemType.kind} items`);
@@ -339,13 +435,7 @@ export class TypeFactory {
339
435
  });
340
436
  }
341
437
  else {
342
- invariant(resolvedType instanceof ObjectType ||
343
- resolvedType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind}`);
344
- invariant(stubType instanceof ObjectType || stubType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
345
- lazyType = new ObjectType.LazyShaclProperty.RequiredObjectType({
346
- resolvedType,
347
- stubType,
348
- });
438
+ throw new Error(`lazy property ${name} on ${objectType.name} has ${resolvedType.kind}`);
349
439
  }
350
440
  property = new ObjectType.LazyShaclProperty({
351
441
  comment: astObjectTypeProperty.comment,
@@ -257,7 +257,7 @@ ${this.memberTypes
257
257
  if (this._discriminator.kind === "syntheticProperty") {
258
258
  typeExpression = `${typeExpression}.map(value => ({ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}" as const, value }) as (${this.name}))`;
259
259
  }
260
- typeExpression = `(${typeExpression} as purify.Either<Error, ${this.name}>)`;
260
+ typeExpression = `(${typeExpression} as purify.Either<Error, rdfjsResource.Resource.Values<${this.name}>>)`;
261
261
  return expression.length > 0
262
262
  ? `${expression}.altLazy(() => ${typeExpression})`
263
263
  : typeExpression;
@@ -17,9 +17,10 @@ export class EagerShaclProperty extends ShaclProperty {
17
17
  }
18
18
  get graphqlField() {
19
19
  return Maybe.of({
20
- description: this.comment.map(JSON.stringify).extract(),
20
+ args: Maybe.empty(),
21
+ description: this.comment.map(JSON.stringify),
21
22
  name: this.name,
22
- resolve: `(source) => ${this.type.graphqlResolveExpression({ variables: { value: `source.${this.name}` } })}`,
23
+ resolve: `(source, _args) => ${this.type.graphqlResolveExpression({ variables: { args: "_args", value: `source.${this.name}` } })}`,
23
24
  type: this.type.graphqlName.toString(),
24
25
  });
25
26
  }
@@ -7,7 +7,6 @@ import { Property } from "./Property.js";
7
7
  export declare class IdentifierPrefixProperty extends Property<StringType> {
8
8
  private readonly own;
9
9
  readonly declarationImports: readonly Import[];
10
- readonly equalsFunction = "$strictEquals";
11
10
  readonly graphqlField: Property<StringType>["graphqlField"];
12
11
  readonly propertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
13
12
  readonly jsonPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
@@ -18,6 +17,7 @@ export declare class IdentifierPrefixProperty extends Property<StringType> {
18
17
  type: StringType;
19
18
  } & ConstructorParameters<typeof Property>[0]);
20
19
  get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
20
+ get equalsFunction(): Maybe<string>;
21
21
  constructorStatements({ variables, }: Parameters<Property<IdentifierType>["constructorStatements"]>[0]): readonly string[];
22
22
  fromJsonStatements(): readonly string[];
23
23
  fromRdfStatements(): readonly string[];
@@ -1,13 +1,19 @@
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
+ };
1
7
  import { Maybe } from "purify-ts";
2
8
  import { invariant } from "ts-invariant";
3
9
  import { Scope, } from "ts-morph";
10
+ import { Memoize } from "typescript-memoize";
4
11
  import { SnippetDeclarations } from "../SnippetDeclarations.js";
5
12
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
13
  import { Property } from "./Property.js";
7
14
  export class IdentifierPrefixProperty extends Property {
8
15
  own;
9
16
  declarationImports = [];
10
- equalsFunction = `${syntheticNamePrefix}strictEquals`;
11
17
  graphqlField = Maybe.empty();
12
18
  propertySignature = Maybe.empty();
13
19
  jsonPropertySignature = Maybe.empty();
@@ -26,6 +32,11 @@ export class IdentifierPrefixProperty extends Property {
26
32
  type: this.type.name,
27
33
  });
28
34
  }
35
+ get equalsFunction() {
36
+ return this.objectType.declarationType === "class"
37
+ ? Maybe.of(`${syntheticNamePrefix}strictEquals`)
38
+ : Maybe.empty();
39
+ }
29
40
  constructorStatements({ variables, }) {
30
41
  switch (this.objectType.declarationType) {
31
42
  case "class":
@@ -94,4 +105,7 @@ export class IdentifierPrefixProperty extends Property {
94
105
  return [];
95
106
  }
96
107
  }
108
+ __decorate([
109
+ Memoize()
110
+ ], IdentifierPrefixProperty.prototype, "equalsFunction", null);
97
111
  //# sourceMappingURL=IdentifierPrefixProperty.js.map
@@ -5,20 +5,20 @@ import type { IdentifierType } from "../IdentifierType.js";
5
5
  import { Import } from "../Import.js";
6
6
  import { Property } from "./Property.js";
7
7
  export declare class IdentifierProperty extends Property<IdentifierType> {
8
- private readonly classGetAccessorScope;
9
- private readonly classPropertyDeclarationVisibility;
8
+ private readonly getAccessorScope;
10
9
  private readonly identifierMintingStrategy;
11
10
  private readonly identifierPrefixPropertyName;
12
11
  private readonly override;
12
+ private readonly propertyDeclarationVisibility;
13
13
  private readonly typeAlias;
14
14
  readonly abstract: boolean;
15
- readonly equalsFunction = "$booleanEquals";
15
+ readonly equalsFunction: Maybe<string>;
16
16
  readonly mutable = false;
17
17
  readonly recursive = false;
18
- constructor({ abstract, classGetAccessorScope, classPropertyDeclarationVisibility, identifierMintingStrategy, identifierPrefixPropertyName, override, typeAlias, ...superParameters }: {
18
+ constructor({ abstract, getAccessorScope, identifierMintingStrategy, identifierPrefixPropertyName, override, propertyDeclarationVisibility, typeAlias, ...superParameters }: {
19
19
  abstract: boolean;
20
- classGetAccessorScope: Maybe<Scope>;
21
- classPropertyDeclarationVisibility: Maybe<PropertyVisibility>;
20
+ getAccessorScope: Maybe<Scope>;
21
+ propertyDeclarationVisibility: Maybe<PropertyVisibility>;
22
22
  identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
23
23
  identifierPrefixPropertyName: string;
24
24
  override: boolean;
@@ -1,29 +1,29 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { invariant } from "ts-invariant";
4
+ import { logger } from "../../../logger.js";
4
5
  import { Import } from "../Import.js";
5
6
  import { SnippetDeclarations } from "../SnippetDeclarations.js";
6
7
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
7
8
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
8
9
  import { Property } from "./Property.js";
9
10
  export class IdentifierProperty extends Property {
10
- classGetAccessorScope;
11
- classPropertyDeclarationVisibility;
11
+ getAccessorScope;
12
12
  identifierMintingStrategy;
13
13
  identifierPrefixPropertyName;
14
14
  override;
15
+ propertyDeclarationVisibility;
15
16
  typeAlias;
16
17
  abstract;
17
- equalsFunction = `${syntheticNamePrefix}booleanEquals`;
18
+ equalsFunction = Maybe.of(`${syntheticNamePrefix}booleanEquals`);
18
19
  mutable = false;
19
20
  recursive = false;
20
- constructor({ abstract, classGetAccessorScope, classPropertyDeclarationVisibility, identifierMintingStrategy, identifierPrefixPropertyName, override, typeAlias, ...superParameters }) {
21
+ constructor({ abstract, getAccessorScope, identifierMintingStrategy, identifierPrefixPropertyName, override, propertyDeclarationVisibility, typeAlias, ...superParameters }) {
21
22
  super(superParameters);
22
23
  invariant(this.visibility === "public");
23
24
  this.abstract = abstract;
24
- this.classGetAccessorScope = classGetAccessorScope;
25
- this.classPropertyDeclarationVisibility =
26
- classPropertyDeclarationVisibility;
25
+ this.getAccessorScope = getAccessorScope;
26
+ this.propertyDeclarationVisibility = propertyDeclarationVisibility;
27
27
  this.identifierMintingStrategy = identifierMintingStrategy;
28
28
  this.identifierPrefixPropertyName = identifierPrefixPropertyName;
29
29
  this.override = override;
@@ -39,9 +39,21 @@ export class IdentifierProperty extends Property {
39
39
  typeNames.add(conversion.sourceTypeName);
40
40
  }
41
41
  }
42
+ let hasQuestionToken;
43
+ switch (this.objectType.declarationType) {
44
+ case "class":
45
+ hasQuestionToken = this.identifierMintingStrategy.isJust();
46
+ break;
47
+ case "interface": {
48
+ const identifierMintingStrategy = this.identifierMintingStrategy.extract();
49
+ hasQuestionToken =
50
+ typeof identifierMintingStrategy !== "undefined" &&
51
+ identifierMintingStrategy !== "sha256";
52
+ break;
53
+ }
54
+ }
42
55
  return Maybe.of({
43
- hasQuestionToken: this.objectType.declarationType === "class" &&
44
- this.identifierMintingStrategy.isJust(),
56
+ hasQuestionToken,
45
57
  isReadonly: true,
46
58
  name: this.name,
47
59
  type: [...typeNames].sort().join(" | "),
@@ -49,26 +61,23 @@ export class IdentifierProperty extends Property {
49
61
  }
50
62
  get declarationImports() {
51
63
  const imports = this.type.useImports().concat();
52
- if (this.objectType.features.has("hash") &&
53
- this.objectType.declarationType === "class") {
54
- this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
55
- switch (identifierMintingStrategy) {
56
- case "sha256":
57
- imports.push(Import.SHA256);
58
- break;
59
- case "uuidv4":
60
- imports.push(Import.UUID);
61
- break;
62
- }
63
- });
64
- }
64
+ this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
65
+ switch (identifierMintingStrategy) {
66
+ case "sha256":
67
+ imports.push(Import.SHA256);
68
+ break;
69
+ case "uuidv4":
70
+ imports.push(Import.UUID);
71
+ break;
72
+ }
73
+ });
65
74
  return imports;
66
75
  }
67
76
  get getAccessorDeclaration() {
68
- if (this.classGetAccessorScope.isNothing()) {
77
+ if (this.getAccessorScope.isNothing()) {
69
78
  return Maybe.empty();
70
79
  }
71
- invariant(this.classGetAccessorScope.unsafeCoerce() === "public");
80
+ invariant(this.getAccessorScope.unsafeCoerce() === "public");
72
81
  if (this.identifierMintingStrategy.isJust()) {
73
82
  let memoizeMintedIdentifier;
74
83
  let mintIdentifier;
@@ -109,6 +118,8 @@ export class IdentifierProperty extends Property {
109
118
  get graphqlField() {
110
119
  invariant(this.name.startsWith(syntheticNamePrefix));
111
120
  return Maybe.of({
121
+ args: Maybe.empty(),
122
+ description: Maybe.empty(),
112
123
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
113
124
  resolve: `(source) => ${this.typeAlias}.toString(source.${this.name})`,
114
125
  type: this.type.graphqlName.toString(),
@@ -153,9 +164,28 @@ export class IdentifierProperty extends Property {
153
164
  invariant(conversion.sourceTypeName !== "undefined");
154
165
  conversionBranches.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${lhs} = ${conversion.conversionExpression(variables.parameter)}; }`);
155
166
  }
156
- if (lhs.startsWith("this._")) {
157
- conversionBranches.push(`if (typeof ${variables.parameter} === "undefined") { }`);
158
- }
167
+ this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
168
+ switch (this.objectType.declarationType) {
169
+ case "class":
170
+ conversionBranches.push(`if (typeof ${variables.parameter} === "undefined") { }`);
171
+ break;
172
+ case "interface": {
173
+ let mintIdentifier;
174
+ switch (identifierMintingStrategy) {
175
+ case "blankNode":
176
+ mintIdentifier = "dataFactory.blankNode()";
177
+ break;
178
+ case "sha256":
179
+ logger.warn("minting %s identifiers with %s is unsupported", this.objectType.declarationType, identifierMintingStrategy);
180
+ return;
181
+ case "uuidv4":
182
+ mintIdentifier = `dataFactory.namedNode(\`\${${variables.parameters}.${this.identifierPrefixPropertyName} ?? "urn:shaclmate:${this.objectType.discriminatorValue}:"}\${uuid.v4()}\`)`;
183
+ break;
184
+ }
185
+ conversionBranches.push(`if (typeof ${variables.parameter} === "undefined") { ${lhs} = ${mintIdentifier}; }`);
186
+ }
187
+ }
188
+ });
159
189
  // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
160
190
  conversionBranches.push(`{ ${lhs} = (${variables.parameter}) satisfies never;\n }`);
161
191
  statements.push(conversionBranches.join(" else "));
@@ -217,7 +247,7 @@ export class IdentifierProperty extends Property {
217
247
  });
218
248
  }
219
249
  // See note in TypeFactory re: the logic of whether to declare the identifier in the class or not.
220
- if (!this.classPropertyDeclarationVisibility.isJust()) {
250
+ if (!this.propertyDeclarationVisibility.isJust()) {
221
251
  return Maybe.empty();
222
252
  }
223
253
  if (this.identifierMintingStrategy.isJust()) {
@@ -225,7 +255,7 @@ export class IdentifierProperty extends Property {
225
255
  return Maybe.of({
226
256
  hasQuestionToken: true,
227
257
  name: `_${this.name}`,
228
- scope: this.classPropertyDeclarationVisibility
258
+ scope: this.propertyDeclarationVisibility
229
259
  .map(Property.visibilityToScope)
230
260
  .unsafeCoerce(),
231
261
  type: `${this.typeAlias}`,
@@ -18,6 +18,9 @@ export declare namespace LazyShaclProperty {
18
18
  readonly discriminatorProperty: _Type["discriminatorProperty"];
19
19
  readonly mutable = false;
20
20
  readonly typeof = "object";
21
+ abstract readonly graphqlArgs: Maybe<Record<string, {
22
+ type: string;
23
+ }>>;
21
24
  protected readonly resolvedType: ResolvedTypeT;
22
25
  protected readonly runtimeClass: {
23
26
  readonly name: string;
@@ -34,7 +37,6 @@ export declare namespace LazyShaclProperty {
34
37
  get conversions(): readonly _Type.Conversion[];
35
38
  get equalsFunction(): string;
36
39
  get graphqlName(): _Type.GraphqlName;
37
- graphqlResolveExpression({ variables, }: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
38
40
  hashStatements({ depth, variables, }: Parameters<_Type["hashStatements"]>[0]): readonly string[];
39
41
  get jsonName(): _Type.JsonName;
40
42
  jsonUiSchemaElement(parameters: Parameters<_Type["jsonUiSchemaElement"]>[0]): Maybe<string>;
@@ -61,9 +63,20 @@ export declare namespace LazyShaclProperty {
61
63
  get conversions(): readonly _Type.Conversion[];
62
64
  fromJsonExpression(parameters: Parameters<_Type["fromJsonExpression"]>[0]): string;
63
65
  fromRdfExpression(parameters: Parameters<_Type["fromRdfExpression"]>[0]): string;
66
+ get graphqlArgs(): Maybe<{
67
+ limit: {
68
+ type: string;
69
+ };
70
+ offset: {
71
+ type: string;
72
+ };
73
+ }>;
74
+ graphqlResolveExpression({ variables, }: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
64
75
  }
65
76
  abstract class SingleObjectType<ResolvedTypeT extends Exclude<Type.ResolvedTypeConstraint, SetType<ObjectType | ObjectUnionType>>, StubTypeT extends Exclude<Type.StubTypeConstraint, SetType<ObjectType | ObjectUnionType>>> extends Type<ResolvedTypeT, StubTypeT> {
66
77
  fromJsonExpression(parameters: Parameters<_Type["fromJsonExpression"]>[0]): string;
78
+ get graphqlArgs(): Type<ResolvedTypeT, ObjectUnionType>["graphqlArgs"];
79
+ graphqlResolveExpression({ variables, }: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
67
80
  }
68
81
  export class OptionalObjectType<ResolvedTypeT extends OptionType<ObjectType | ObjectUnionType>, StubTypeT extends OptionType<ObjectType | ObjectUnionType>> extends SingleObjectType<ResolvedTypeT, StubTypeT> {
69
82
  constructor({ resolvedType, stubType, }: {