@shaclmate/compiler 4.0.19 → 4.0.20

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 (95) hide show
  1. package/dist/Compiler.d.ts +4 -1
  2. package/dist/Compiler.js +4 -1
  3. package/dist/ShapesGraphToAstTransformer.d.ts +4 -1
  4. package/dist/ShapesGraphToAstTransformer.js +9 -6
  5. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -1
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +1 -1
  7. package/dist/ast/AbstractCollectionType.d.ts +1 -1
  8. package/dist/ast/AbstractContainerType.d.ts +1 -1
  9. package/dist/ast/AbstractLazyObjectType.d.ts +19 -79
  10. package/dist/ast/AbstractTermType.d.ts +3 -33
  11. package/dist/ast/AbstractTermType.js +2 -3
  12. package/dist/ast/AbstractType.d.ts +1 -1
  13. package/dist/ast/AbstractType.js +1 -2
  14. package/dist/ast/BlankNodeType.d.ts +1 -1
  15. package/dist/ast/DefaultValueType.d.ts +2 -17
  16. package/dist/ast/DefaultValueType.js +1 -2
  17. package/dist/ast/IdentifierType.d.ts +1 -1
  18. package/dist/ast/LiteralType.d.ts +8 -98
  19. package/dist/ast/LiteralType.js +5 -7
  20. package/dist/ast/ObjectCompoundType.js +1 -2
  21. package/dist/ast/ObjectType.d.ts +9 -39
  22. package/dist/ast/ObjectType.js +9 -13
  23. package/dist/ast/SetType.d.ts +1 -1
  24. package/dist/ast/UnionType.d.ts +1 -1
  25. package/dist/generators/transformAstToLabeledPropertyGraph.js +3 -4
  26. package/dist/generators/ts/AbstractDateType.js +1 -1
  27. package/dist/generators/ts/AbstractIdentifierType.d.ts +2 -2
  28. package/dist/generators/ts/AbstractIdentifierType.js +2 -5
  29. package/dist/generators/ts/AbstractNamedUnionType.js +1 -1
  30. package/dist/generators/ts/AbstractNumericType.js +1 -1
  31. package/dist/generators/ts/AbstractTermType.js +2 -2
  32. package/dist/generators/ts/AbstractType.d.ts +17 -14
  33. package/dist/generators/ts/AbstractType.js +3 -1
  34. package/dist/generators/ts/BlankNodeType.d.ts +2 -2
  35. package/dist/generators/ts/BlankNodeType.js +1 -1
  36. package/dist/generators/ts/BooleanType.js +1 -1
  37. package/dist/generators/ts/DefaultValueType.js +1 -1
  38. package/dist/generators/ts/IdentifierType.d.ts +2 -2
  39. package/dist/generators/ts/IdentifierType.js +1 -1
  40. package/dist/generators/ts/IriType.d.ts +1 -1
  41. package/dist/generators/ts/IriType.js +8 -13
  42. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
  43. package/dist/generators/ts/LazyObjectOptionType.js +1 -1
  44. package/dist/generators/ts/LazyObjectType.js +1 -1
  45. package/dist/generators/ts/ListType.js +5 -5
  46. package/dist/generators/ts/NamedObjectUnionType.js +4 -1
  47. package/dist/generators/ts/SetType.js +1 -1
  48. package/dist/generators/ts/StringType.js +1 -1
  49. package/dist/generators/ts/TermType.js +3 -1
  50. package/dist/generators/ts/TsGenerator.d.ts +5 -0
  51. package/dist/generators/ts/TsGenerator.js +7 -1
  52. package/dist/generators/ts/TypeFactory.d.ts +5 -0
  53. package/dist/generators/ts/TypeFactory.js +35 -5
  54. package/dist/generators/ts/ZodGenerator.d.ts +4 -0
  55. package/dist/generators/ts/ZodGenerator.js +4 -1
  56. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +4 -1
  57. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +3 -1
  58. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -5
  59. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +2 -2
  60. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +2 -2
  61. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
  62. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
  63. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +1 -1
  64. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -0
  65. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +16 -16
  66. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +6 -2
  67. package/dist/generators/ts/_snippets/parseIri.d.ts +2 -0
  68. package/dist/generators/ts/_snippets/parseIri.js +12 -0
  69. package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +7 -5
  70. package/dist/generators/ts/_snippets/snippets_parseBlankNode.d.ts +2 -0
  71. package/dist/generators/ts/_snippets/snippets_parseBlankNode.js +12 -0
  72. package/dist/generators/ts/_snippets/snippets_parseIdentifier.d.ts +2 -0
  73. package/dist/generators/ts/_snippets/snippets_parseIdentifier.js +6 -0
  74. package/dist/generators/ts/graphqlSchemaVariableStatement.js +3 -3
  75. package/dist/generators/ts/imports.d.ts +2 -0
  76. package/dist/generators/ts/imports.js +3 -1
  77. package/dist/generators/ts/rdfjsTermExpression.d.ts +4 -1
  78. package/dist/generators/ts/rdfjsTermExpression.js +2 -3
  79. package/dist/generators/ts/snippets.d.ts +3 -2
  80. package/dist/generators/ts/snippets.js +6 -4
  81. package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -0
  82. package/dist/generators/ts/synthesizeUberObjectUnionType.js +4 -0
  83. package/dist/input/ShapesGraph.d.ts +4 -1
  84. package/dist/input/ShapesGraph.js +3 -2
  85. package/dist/input/generated.d.ts +323 -323
  86. package/dist/input/generated.js +19 -20
  87. package/package.json +6 -7
  88. package/dist/ast/termToJson.d.ts +0 -18
  89. package/dist/ast/termToJson.js +0 -18
  90. package/dist/generators/ts/_snippets/snippets_blankNodeFromString.d.ts +0 -2
  91. package/dist/generators/ts/_snippets/snippets_blankNodeFromString.js +0 -11
  92. package/dist/generators/ts/_snippets/snippets_identifierFromString.d.ts +0 -2
  93. package/dist/generators/ts/_snippets/snippets_identifierFromString.js +0 -8
  94. package/dist/logger.d.ts +0 -2
  95. package/dist/logger.js +0 -8
@@ -6,7 +6,12 @@ import { synthesizeUberObjectUnionType } from "./synthesizeUberObjectUnionType.j
6
6
  import { TypeFactory } from "./TypeFactory.js";
7
7
  import { code, joinCode } from "./ts-poet-wrapper.js";
8
8
  export class TsGenerator {
9
- typeFactory = new TypeFactory();
9
+ logger;
10
+ typeFactory;
11
+ constructor({ logger }) {
12
+ this.logger = logger;
13
+ this.typeFactory = new TypeFactory({ logger });
14
+ }
10
15
  generate(ast_) {
11
16
  let declarations = [];
12
17
  for (const astNamedUnionType of ast_.namedUnionTypes) {
@@ -29,6 +34,7 @@ export class TsGenerator {
29
34
  const namedObjectUnionTypesNameSorted = namedObjectUnionTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
30
35
  if (namedObjectTypesToposorted.length > 0) {
31
36
  const uberObjectUnionType = synthesizeUberObjectUnionType({
37
+ logger: this.logger,
32
38
  namedObjectTypes: namedObjectTypesToposorted.toReversed(), // Reverse topological order so children ane before parents
33
39
  });
34
40
  declarations = declarations.concat(uberObjectUnionType.declaration.toList());
@@ -1,4 +1,5 @@
1
1
  import type { Literal, NamedNode } from "@rdfjs/types";
2
+ import type { Logger } from "ts-log";
2
3
  import * as ast from "../../ast/index.js";
3
4
  import { AnonymousUnionType } from "./AnonymousUnionType.js";
4
5
  import { NamedObjectType } from "./NamedObjectType.js";
@@ -9,6 +10,10 @@ export declare class TypeFactory {
9
10
  private cachedNamedObjectUnionTypesByShapeIdentifier;
10
11
  private cachedObjectTypePropertiesByShapeIdentifier;
11
12
  private cachedObjectTypesByShapeIdentifier;
13
+ private readonly logger;
14
+ constructor({ logger }: {
15
+ logger: Logger;
16
+ });
12
17
  createNamedObjectUnionType(astType: ast.ObjectUnionType): NamedObjectUnionType;
13
18
  createNamedObjectType(astType: ast.ObjectType): NamedObjectType;
14
19
  createType(astType: ast.Type, parameters?: {
@@ -7,7 +7,6 @@ import { Maybe } from "purify-ts";
7
7
  import reservedTsIdentifiers_ from "reserved-identifiers";
8
8
  import { invariant } from "ts-invariant";
9
9
  import * as ast from "../../ast/index.js";
10
- import { logger } from "../../logger.js";
11
10
  import { AnonymousUnionType } from "./AnonymousUnionType.js";
12
11
  import { BigDecimalType } from "./BigDecimalType.js";
13
12
  import { BigIntType } from "./BigIntType.js";
@@ -38,6 +37,10 @@ export class TypeFactory {
38
37
  cachedNamedObjectUnionTypesByShapeIdentifier = new TermMap();
39
38
  cachedObjectTypePropertiesByShapeIdentifier = new TermMap();
40
39
  cachedObjectTypesByShapeIdentifier = new TermMap();
40
+ logger;
41
+ constructor({ logger }) {
42
+ this.logger = logger;
43
+ }
41
44
  createNamedObjectUnionType(astType) {
42
45
  {
43
46
  const cachedNamedObjectUnionType = this.cachedNamedObjectUnionTypesByShapeIdentifier.get(astType.shapeIdentifier);
@@ -50,6 +53,7 @@ export class TypeFactory {
50
53
  features: astType.tsFeatures,
51
54
  identifierType: this.createIdentifierType(ast.ObjectCompoundType.identifierType(astType)),
52
55
  label: astType.label,
56
+ logger: this.logger,
53
57
  members: ast.ObjectCompoundType.memberObjectTypes(astType).map((namedObjectType) => ({
54
58
  discriminantValue: Maybe.empty(),
55
59
  type: this.createNamedObjectType(namedObjectType),
@@ -97,6 +101,7 @@ export class TypeFactory {
97
101
  }
98
102
  }
99
103
  return new NamedObjectType.DiscriminantProperty({
104
+ logger: this.logger,
100
105
  name: `${syntheticNamePrefix}type`,
101
106
  namedObjectType,
102
107
  type: new NamedObjectType.DiscriminantProperty.Type({
@@ -110,6 +115,7 @@ export class TypeFactory {
110
115
  lazyIdentifierProperty: (namedObjectType) => new NamedObjectType.IdentifierProperty({
111
116
  identifierMintingStrategy: astType.identifierMintingStrategy,
112
117
  identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
118
+ logger: this.logger,
113
119
  name: `${syntheticNamePrefix}identifier`,
114
120
  namedObjectType,
115
121
  type: identifierType,
@@ -139,6 +145,7 @@ export class TypeFactory {
139
145
  // Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
140
146
  if (namedObjectTypeNeedsIdentifierPrefixProperty(astType)) {
141
147
  properties.splice(0, 0, new NamedObjectType.IdentifierPrefixProperty({
148
+ logger: this.logger,
142
149
  name: `${syntheticNamePrefix}identifierPrefix`,
143
150
  namedObjectType,
144
151
  own: !astType.ancestorObjectTypes.some(namedObjectTypeNeedsIdentifierPrefixProperty),
@@ -148,6 +155,7 @@ export class TypeFactory {
148
155
  hasValues: [],
149
156
  in_: [],
150
157
  label: astType.label,
158
+ logger: this.logger,
151
159
  languageIn: [],
152
160
  primitiveIn: [],
153
161
  }),
@@ -158,6 +166,7 @@ export class TypeFactory {
158
166
  properties.splice(0, 0, namedObjectType.identifierProperty);
159
167
  return properties;
160
168
  },
169
+ logger: this.logger,
161
170
  name,
162
171
  recursive: astType.recursive,
163
172
  staticModuleName,
@@ -211,6 +220,7 @@ export class TypeFactory {
211
220
  features: astType.tsFeatures,
212
221
  identifierType: Maybe.empty(),
213
222
  label: astType.label,
223
+ logger: this.logger,
214
224
  members: astType.members.map((member) => ({
215
225
  discriminantValue: member.discriminantValue,
216
226
  type: this.createType(member.type),
@@ -222,6 +232,7 @@ export class TypeFactory {
222
232
  comment: astType.comment,
223
233
  label: astType.label,
224
234
  identifierType: Maybe.empty(),
235
+ logger: this.logger,
225
236
  members: astType.members.map((member) => ({
226
237
  discriminantValue: member.discriminantValue,
227
238
  type: this.createType(member.type),
@@ -233,6 +244,7 @@ export class TypeFactory {
233
244
  return new BlankNodeType({
234
245
  comment: astType.comment,
235
246
  label: astType.label,
247
+ logger: this.logger,
236
248
  });
237
249
  }
238
250
  createDefaultValueType(astType) {
@@ -245,6 +257,7 @@ export class TypeFactory {
245
257
  defaultValue: astType.defaultValue,
246
258
  itemType,
247
259
  label: astType.label,
260
+ logger: this.logger,
248
261
  });
249
262
  }
250
263
  createIdentifierType(astType) {
@@ -255,6 +268,7 @@ export class TypeFactory {
255
268
  return new IdentifierType({
256
269
  comment: astType.comment,
257
270
  label: astType.label,
271
+ logger: this.logger,
258
272
  });
259
273
  case "IriType":
260
274
  return this.createIriType(astType);
@@ -266,12 +280,14 @@ export class TypeFactory {
266
280
  hasValues: astType.hasValues,
267
281
  in_: astType.in_,
268
282
  label: astType.label,
283
+ logger: this.logger,
269
284
  });
270
285
  }
271
286
  createLazyObjectOptionType(astType) {
272
287
  return new LazyObjectOptionType({
273
288
  comment: astType.comment,
274
289
  label: astType.label,
290
+ logger: this.logger,
275
291
  partialType: this.createOptionType(astType.partialType),
276
292
  resolveType: this.createOptionType(astType.resolveType),
277
293
  });
@@ -280,6 +296,7 @@ export class TypeFactory {
280
296
  return new LazyObjectSetType({
281
297
  comment: astType.comment,
282
298
  label: astType.label,
299
+ logger: this.logger,
283
300
  partialType: this.createSetType(astType.partialType),
284
301
  resolveType: this.createSetType(astType.resolveType),
285
302
  });
@@ -288,6 +305,7 @@ export class TypeFactory {
288
305
  return new LazyObjectType({
289
306
  comment: astType.comment,
290
307
  label: astType.label,
308
+ logger: this.logger,
291
309
  partialType: this.createType(astType.partialType),
292
310
  resolveType: this.createType(astType.resolveType),
293
311
  });
@@ -300,6 +318,7 @@ export class TypeFactory {
300
318
  identifierNodeKind: astType.identifierNodeKind,
301
319
  itemType,
302
320
  label: astType.label,
321
+ logger: this.logger,
303
322
  minCount: 0,
304
323
  mutable: astType.mutable,
305
324
  identifierMintingStrategy: astType.identifierMintingStrategy,
@@ -336,6 +355,7 @@ export class TypeFactory {
336
355
  in_: astType.in_,
337
356
  label: astType.label,
338
357
  languageIn: [],
358
+ logger: this.logger,
339
359
  });
340
360
  case "bigint":
341
361
  return new BigIntType({
@@ -345,6 +365,7 @@ export class TypeFactory {
345
365
  in_: astType.in_,
346
366
  label: astType.label,
347
367
  languageIn: [],
368
+ logger: this.logger,
348
369
  primitiveIn: astType.in_.map((value) => LiteralDecoder.decodeBigIntLiteral(value).unsafeCoerce()),
349
370
  });
350
371
  case "boolean":
@@ -355,6 +376,7 @@ export class TypeFactory {
355
376
  label: astType.label,
356
377
  languageIn: [],
357
378
  in_: astType.in_,
379
+ logger: this.logger,
358
380
  primitiveIn: astType.in_.map((value) => LiteralDecoder.decodeBooleanLiteral(value).unsafeCoerce()),
359
381
  });
360
382
  case "date":
@@ -366,6 +388,7 @@ export class TypeFactory {
366
388
  in_: astType.in_,
367
389
  label: astType.label,
368
390
  languageIn: [],
391
+ logger: this.logger,
369
392
  primitiveIn: astType.in_.map((value) => (datatypeDefinition.kind === "date"
370
393
  ? LiteralDecoder.decodeDateLiteral
371
394
  : LiteralDecoder.decodeDateTimeLiteral)(value).unsafeCoerce()),
@@ -379,6 +402,7 @@ export class TypeFactory {
379
402
  in_: astType.in_,
380
403
  label: astType.label,
381
404
  languageIn: [],
405
+ logger: this.logger,
382
406
  primitiveIn: astType.in_.map((value) => (datatypeDefinition.kind === "float"
383
407
  ? LiteralDecoder.decodeFloatLiteral
384
408
  : LiteralDecoder.decodeIntLiteral)(value).unsafeCoerce()),
@@ -389,9 +413,10 @@ export class TypeFactory {
389
413
  comment: astType.comment,
390
414
  datatype,
391
415
  hasValues: astType.hasValues,
416
+ in_: astType.in_,
392
417
  label: astType.label,
393
418
  languageIn: astType.languageIn,
394
- in_: astType.in_,
419
+ logger: this.logger,
395
420
  primitiveIn: astType.in_.map((value) => value.value),
396
421
  });
397
422
  }
@@ -402,14 +427,14 @@ export class TypeFactory {
402
427
  // Drop down
403
428
  }
404
429
  else {
405
- logger.warn("unrecognized literal datatype: %s", datatype.value);
430
+ this.logger.warn("unrecognized literal datatype: %s", datatype.value);
406
431
  }
407
432
  }
408
433
  else if (datatypes.size > 0) {
409
- logger.warn("literal type has multiple datatypes: %s", JSON.stringify([...datatypes].map((datatype) => datatype.value)));
434
+ this.logger.warn("literal type has multiple datatypes: %s", JSON.stringify([...datatypes].map((datatype) => datatype.value)));
410
435
  }
411
436
  else {
412
- logger.debug("literal type has no datatypes");
437
+ this.logger.debug("literal type has no datatypes");
413
438
  }
414
439
  return new LiteralType({
415
440
  comment: astType.comment,
@@ -417,6 +442,7 @@ export class TypeFactory {
417
442
  in_: astType.in_,
418
443
  label: astType.label,
419
444
  languageIn: astType.languageIn,
445
+ logger: this.logger,
420
446
  });
421
447
  }
422
448
  createObjectTypeProperty({ astObjectTypeProperty, namedObjectType, }) {
@@ -430,6 +456,7 @@ export class TypeFactory {
430
456
  comment: astObjectTypeProperty.comment,
431
457
  description: astObjectTypeProperty.description,
432
458
  label: astObjectTypeProperty.label,
459
+ logger: this.logger,
433
460
  mutable: astObjectTypeProperty.mutable,
434
461
  namedObjectType,
435
462
  name: tsName(astObjectTypeProperty.name),
@@ -448,6 +475,7 @@ export class TypeFactory {
448
475
  comment: astType.comment,
449
476
  itemType,
450
477
  label: astType.label,
478
+ logger: this.logger,
451
479
  });
452
480
  }
453
481
  createSetType(astType) {
@@ -457,6 +485,7 @@ export class TypeFactory {
457
485
  comment: astType.comment,
458
486
  itemType,
459
487
  label: astType.label,
488
+ logger: this.logger,
460
489
  mutable: astType.mutable,
461
490
  minCount: astType.minCount,
462
491
  });
@@ -467,6 +496,7 @@ export class TypeFactory {
467
496
  hasValues: astType.hasValues,
468
497
  in_: astType.in_,
469
498
  label: astType.label,
499
+ logger: this.logger,
470
500
  nodeKinds: astType.nodeKinds,
471
501
  });
472
502
  }
@@ -1,7 +1,11 @@
1
+ import type { Logger } from "ts-log";
1
2
  import * as ast from "../../ast/index.js";
2
3
  import type { Generator } from "../Generator.js";
3
4
  export declare class ZodGenerator implements Generator {
4
5
  private readonly typeFactory;
6
+ constructor({ logger }: {
7
+ logger: Logger;
8
+ });
5
9
  generate(ast_: ast.Ast): string;
6
10
  }
7
11
  //# sourceMappingURL=ZodGenerator.d.ts.map
@@ -7,7 +7,10 @@ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
7
7
  import { TypeFactory } from "./TypeFactory.js";
8
8
  import { code, joinCode } from "./ts-poet-wrapper.js";
9
9
  export class ZodGenerator {
10
- typeFactory = new TypeFactory();
10
+ typeFactory;
11
+ constructor({ logger }) {
12
+ this.typeFactory = new TypeFactory({ logger });
13
+ }
11
14
  generate(ast_) {
12
15
  const declarations = [];
13
16
  for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType))) {
@@ -1,9 +1,11 @@
1
1
  import type { Maybe } from "purify-ts";
2
+ import type { Logger } from "ts-log";
2
3
  import type { Visibility } from "../../../enums/Visibility.js";
3
4
  import type { NamedObjectType } from "../NamedObjectType.js";
4
5
  import type { Type } from "../Type.js";
5
6
  import { type Code } from "../ts-poet-wrapper.js";
6
7
  export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterFunction" | "mutable" | "name" | "schema">> {
8
+ protected readonly logger: Logger;
7
9
  protected readonly namedObjectType: NamedObjectType;
8
10
  /**
9
11
  * Optional property to include in the parameters object of a class constructor.
@@ -75,7 +77,8 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
75
77
  * Property visibility: private, protected, public.
76
78
  */
77
79
  readonly visibility: Visibility;
78
- constructor({ name, namedObjectType, type, visibility, }: {
80
+ constructor({ logger, name, namedObjectType, type, visibility, }: {
81
+ logger: Logger;
79
82
  name: string;
80
83
  namedObjectType: NamedObjectType;
81
84
  type: TypeT;
@@ -9,6 +9,7 @@ import { Memoize } from "typescript-memoize";
9
9
  import { removeUndefined } from "../removeUndefined.js";
10
10
  import { code, literalOf } from "../ts-poet-wrapper.js";
11
11
  export class AbstractProperty {
12
+ logger;
12
13
  namedObjectType;
13
14
  /**
14
15
  * TypeScript identifier-safe name of the property.
@@ -22,7 +23,8 @@ export class AbstractProperty {
22
23
  * Property visibility: private, protected, public.
23
24
  */
24
25
  visibility;
25
- constructor({ name, namedObjectType, type, visibility, }) {
26
+ constructor({ logger, name, namedObjectType, type, visibility, }) {
27
+ this.logger = logger;
26
28
  this.name = name;
27
29
  this.namedObjectType = namedObjectType;
28
30
  this.type = type;
@@ -9,7 +9,6 @@ import { rdf } from "@tpluscode/rdf-ns-builders";
9
9
  import { Maybe } from "purify-ts";
10
10
  import { invariant } from "ts-invariant";
11
11
  import { Memoize } from "typescript-memoize";
12
- import { logger } from "../../../logger.js";
13
12
  import { codeEquals } from "../codeEquals.js";
14
13
  import { imports } from "../imports.js";
15
14
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
@@ -138,7 +137,7 @@ export class IdentifierProperty extends AbstractProperty {
138
137
  args: Maybe.empty(),
139
138
  description: Maybe.empty(),
140
139
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
141
- resolve: code `(source) => ${this.typeAlias}.toString(source.${this.name})`,
140
+ resolve: code `(source) => ${this.typeAlias}.stringify(source.${this.name})`,
142
141
  type: this.type.graphqlType.name,
143
142
  });
144
143
  }
@@ -260,7 +259,7 @@ export class IdentifierProperty extends AbstractProperty {
260
259
  mintIdentifier = code `${imports.dataFactory}.blankNode()`;
261
260
  break;
262
261
  case "sha256":
263
- logger.warn("minting %s identifiers with %s is unsupported", this.namedObjectType.declarationType, identifierMintingStrategy);
262
+ this.logger.warn("minting %s identifiers with %s is unsupported", this.namedObjectType.declarationType, identifierMintingStrategy);
264
263
  return;
265
264
  case "uuidv4":
266
265
  mintIdentifier = code `${imports.dataFactory}.namedNode(\`\${${variables.parameters}.${this.identifierPrefixPropertyName} ?? "urn:shaclmate:${this.namedObjectType.discriminantValue}:"}\${${imports.uuid}.v4()}\`)`;
@@ -284,8 +283,10 @@ export class IdentifierProperty extends AbstractProperty {
284
283
  return Maybe.of(code `${this.type.fromRdfResourceValuesExpression({
285
284
  variables: {
286
285
  ...variables,
287
- propertyPath: rdfjsTermExpression(rdf.subject),
288
- resourceValues: code `${imports.Right}(new ${imports.Resource}.Value(${{ dataFactory: imports.dataFactory, focusResource: variables.resource, propertyPath: rdfjsTermExpression(rdf.subject), term: code `${variables.resource}.identifier` }}).toValues())`,
286
+ propertyPath: rdfjsTermExpression(rdf.subject, {
287
+ logger: this.logger,
288
+ }),
289
+ resourceValues: code `${imports.Right}(new ${imports.Resource}.Value(${{ dataFactory: imports.dataFactory, focusResource: variables.resource, propertyPath: rdfjsTermExpression(rdf.subject, { logger: this.logger }), term: code `${variables.resource}.identifier` }}).toValues())`,
289
290
  },
290
291
  })}.chain(values => values.head())`);
291
292
  }
@@ -26,8 +26,8 @@ export function NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration()
26
26
  statements.push(code `\
27
27
  if (!parameters?.ignoreRdfType) {
28
28
  triples.push(
29
- { subject: ${variables.focusIdentifier}, predicate: ${rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} },
30
- { subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
29
+ { subject: ${variables.focusIdentifier}, predicate: ${rdfjsTermExpression(rdf.type, { logger: this.logger })}, object: ${rdfTypeVariable} },
30
+ { subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf, { logger: this.logger })}, object: ${rdfClassVariable} }
31
31
  );
32
32
  }`);
33
33
  }
@@ -47,7 +47,7 @@ if (!parameters?.ignoreRdfType) {
47
47
  triples: [
48
48
  {
49
49
  subject: ${variables.focusIdentifier},
50
- predicate: ${rdfjsTermExpression(rdf.type)},
50
+ predicate: ${rdfjsTermExpression(rdf.type, { logger: this.logger })},
51
51
  object: rdfTypeVariable
52
52
  }
53
53
  ],
@@ -60,7 +60,7 @@ if (!parameters?.ignoreRdfType) {
60
60
  {
61
61
  subject: rdfTypeVariable,
62
62
  predicate: {
63
- items: [${rdfjsTermExpression(rdfs.subClassOf)}],
63
+ items: [${rdfjsTermExpression(rdfs.subClassOf, { logger: this.logger })}],
64
64
  pathType: "+" as const,
65
65
  type: "path" as const
66
66
  },
@@ -8,6 +8,6 @@ export function NamedObjectType_fromRdfTypeVariableStatement() {
8
8
  return Maybe.empty();
9
9
  }
10
10
  return this.fromRdfType.map((fromRdfType) => code `\
11
- export const ${syntheticNamePrefix}fromRdfType: ${imports.NamedNode}<string> = ${rdfjsTermExpression(fromRdfType)};`);
11
+ export const ${syntheticNamePrefix}fromRdfType: ${imports.NamedNode}<string> = ${rdfjsTermExpression(fromRdfType, { logger: this.logger })};`);
12
12
  }
13
13
  //# sourceMappingURL=NamedObjectType_fromRdfTypeVariableStatement.js.map
@@ -32,7 +32,7 @@ export function NamedObjectType_propertiesFromRdfResourceFunctionDeclaration() {
32
32
  });
33
33
  this.fromRdfType.ifJust((fromRdfType) => {
34
34
  const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
35
- const predicate = rdfjsTermExpression(rdf.type);
35
+ const predicate = rdfjsTermExpression(rdf.type, { logger: this.logger });
36
36
  // Check the expected type and its known subtypes
37
37
  const cases = new Set();
38
38
  cases.add(fromRdfType.value);
@@ -54,7 +54,7 @@ export function NamedObjectType_propertiesFromRdfResourceFunctionDeclaration() {
54
54
  return ${imports.Right}(true as const);
55
55
  }
56
56
 
57
- return ${imports.Left}(new Error(\`\${${imports.Resource}.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
57
+ return ${imports.Left}(new Error(\`\${${variables.resource}.identifier} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
58
58
  }) : ${imports.Right}(true as const)`,
59
59
  variable: "_rdfTypeCheck",
60
60
  });
@@ -40,7 +40,7 @@ export function NamedObjectType_toRdfResourceFunctionOrMethodDeclaration() {
40
40
  statements.push(code `const ${variables.resource} = ${variables.resourceSet}.resource(${this.thisVariable}.${this.identifierProperty.name});`);
41
41
  }
42
42
  if (this.toRdfTypes.length > 0) {
43
- statements.push(code `if (!options?.${variables.ignoreRdfType}) { ${joinCode(this.toRdfTypes.map((toRdfType) => code `${variables.resource}.add(${rdfjsTermExpression(rdf.type)}, ${imports.dataFactory}.namedNode("${toRdfType.value}"), options?.${variables.graph});`), { on: " " })} }`);
43
+ statements.push(code `if (!options?.${variables.ignoreRdfType}) { ${joinCode(this.toRdfTypes.map((toRdfType) => code `${variables.resource}.add(${rdfjsTermExpression(rdf.type, { logger: this.logger })}, ${imports.dataFactory}.namedNode("${toRdfType.value}"), options?.${variables.graph});`), { on: " " })} }`);
44
44
  }
45
45
  for (const property of this.properties) {
46
46
  statements.push(...property.toRdfRdfResourceValuesStatements({
@@ -44,5 +44,6 @@ export declare class ShaclProperty<TypeT extends Type> extends AbstractProperty<
44
44
  sparqlWherePatternsExpression({ variables, }: Parameters<AbstractProperty<TypeT>["sparqlWherePatternsExpression"]>[0]): ReturnType<AbstractProperty<TypeT>["sparqlWherePatternsExpression"]>;
45
45
  toJsonObjectMemberExpression(parameters: Parameters<AbstractProperty<TypeT>["toJsonObjectMemberExpression"]>[0]): Maybe<Code>;
46
46
  toRdfRdfResourceValuesStatements({ variables, }: Parameters<AbstractProperty<TypeT>["toRdfRdfResourceValuesStatements"]>[0]): readonly Code[];
47
+ private propertyPathToCode;
47
48
  }
48
49
  //# sourceMappingURL=ShaclProperty.d.ts.map
@@ -13,20 +13,6 @@ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
13
13
  import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
14
14
  import { tsComment } from "../tsComment.js";
15
15
  import { AbstractProperty } from "./AbstractProperty.js";
16
- function propertyPathToCode(propertyPath) {
17
- switch (propertyPath.termType) {
18
- case "AlternativePath":
19
- case "SequencePath":
20
- return code `{ members: [${joinCode(propertyPath.members.map(propertyPathToCode), { on: "," })}] as const, termType: ${literalOf(propertyPath.termType)} as const }`;
21
- case "InversePath":
22
- case "OneOrMorePath":
23
- case "ZeroOrMorePath":
24
- case "ZeroOrOnePath":
25
- return code `{ path: ${propertyPathToCode(propertyPath.path)}, termType: ${literalOf(propertyPath.termType)} as const }`;
26
- case "NamedNode":
27
- return rdfjsTermExpression(propertyPath);
28
- }
29
- }
30
16
  export class ShaclProperty extends AbstractProperty {
31
17
  comment;
32
18
  description;
@@ -121,7 +107,7 @@ export class ShaclProperty extends AbstractProperty {
121
107
  // comment: this.comment.map(JSON.stringify).extract(),
122
108
  // description: this.description.map(JSON.stringify).extract(),
123
109
  path: this.namedObjectType.features.has("rdf")
124
- ? propertyPathToCode(this.path)
110
+ ? this.propertyPathToCode(this.path)
125
111
  : undefined,
126
112
  // label: this.label.map(JSON.stringify).extract(),
127
113
  // mutable: this.mutable ? true : undefined,
@@ -235,13 +221,27 @@ export class ShaclProperty extends AbstractProperty {
235
221
  default:
236
222
  return [];
237
223
  }
238
- const propertyPath = propertyPathToCode(this.path);
224
+ const propertyPath = this.propertyPathToCode(this.path);
239
225
  return [
240
226
  code `${variables.resource}.add(${propertyPath}, ${this.type.toRdfResourceValuesExpression({
241
227
  variables: { ...variables, propertyPath },
242
228
  })}, ${variables.graph});`,
243
229
  ];
244
230
  }
231
+ propertyPathToCode(propertyPath) {
232
+ switch (propertyPath.termType) {
233
+ case "AlternativePath":
234
+ case "SequencePath":
235
+ return code `{ members: [${joinCode(propertyPath.members.map((member) => this.propertyPathToCode(member)), { on: "," })}] as const, termType: ${literalOf(propertyPath.termType)} as const }`;
236
+ case "InversePath":
237
+ case "OneOrMorePath":
238
+ case "ZeroOrMorePath":
239
+ case "ZeroOrOnePath":
240
+ return code `{ path: ${this.propertyPathToCode(propertyPath.path)}, termType: ${literalOf(propertyPath.termType)} as const }`;
241
+ case "NamedNode":
242
+ return rdfjsTermExpression(propertyPath, { logger: this.logger });
243
+ }
244
+ }
245
245
  }
246
246
  __decorate([
247
247
  Memoize()
@@ -1,5 +1,5 @@
1
1
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
2
- import { code, joinCode } from "../ts-poet-wrapper.js";
2
+ import { code } from "../ts-poet-wrapper.js";
3
3
  export function identifierTypeDeclarations() {
4
4
  const ancestorObjectTypeWithSameIdentifierType = this.ancestorObjectTypes.find((ancestorObjectType) => ancestorObjectType.identifierType.name === this.identifierType.name);
5
5
  if (ancestorObjectTypeWithSameIdentifierType) {
@@ -13,7 +13,11 @@ export function identifierTypeDeclarations() {
13
13
  // Bespoke identifier type and associated functions
14
14
  return [
15
15
  code `export type ${syntheticNamePrefix}Identifier = ${this.identifierType.name};`,
16
- code `export namespace ${syntheticNamePrefix}Identifier { ${joinCode([this.identifierType.fromStringFunction, this.identifierType.toStringFunction])} }`,
16
+ code `\
17
+ export namespace ${syntheticNamePrefix}Identifier {
18
+ export const parse = ${this.identifierType.parseFunction};
19
+ export const stringify = ${this.identifierType.stringifyFunction};
20
+ }`,
17
21
  ];
18
22
  }
19
23
  //# sourceMappingURL=identifierTypeDeclarations.js.map
@@ -0,0 +1,2 @@
1
+ export declare const snippets_parseIri: import("ts-poet/build/ConditionalOutput.js").ConditionalOutput;
2
+ //# sourceMappingURL=parseIri.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { imports } from "../imports.js";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
3
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
4
+ import { snippets_parseIdentifier } from "./snippets_parseIdentifier.js";
5
+ export const snippets_parseIri = conditionalOutput(`${syntheticNamePrefix}parseIri`, code `\
6
+ export function ${syntheticNamePrefix}parseIri(identifier: string): ${imports.Either}<Error, ${imports.NamedNode}> {
7
+ return \
8
+ ${snippets_parseIdentifier}(identifier)\
9
+ .chain((identifier) => (identifier.termType === "NamedNode") ? ${imports.Right}(identifier) : ${imports.Left}(new Error("expected identifier to be NamedNode"))) \
10
+ as ${imports.Either}<Error, ${imports.NamedNode}>;
11
+ }`);
12
+ //# sourceMappingURL=parseIri.js.map
@@ -1,4 +1,5 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
+ import { dummyLogger } from "ts-log";
2
3
  import { imports } from "../imports.js";
3
4
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
4
5
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
@@ -7,6 +8,7 @@ import { snippets_CollectionFilter } from "./snippets_CollectionFilter.js";
7
8
  import { snippets_CollectionSchema } from "./snippets_CollectionSchema.js";
8
9
  import { snippets_SparqlPattern } from "./snippets_SparqlPattern.js";
9
10
  import { snippets_ValueSparqlWherePatternsFunction } from "./snippets_ValueSparqlWherePatternsFunction.js";
11
+ const logger = dummyLogger;
10
12
  export const snippets_listSparqlWherePatterns = conditionalOutput(`${syntheticNamePrefix}listSparqlWherePatterns`, code `\
11
13
  function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>(itemSparqlWherePatternsFunction: ${snippets_ValueSparqlWherePatternsFunction}<ItemFilterT, ItemSchemaT>): ${snippets_ValueSparqlWherePatternsFunction}<${snippets_CollectionFilter}<ItemFilterT>, ${snippets_CollectionSchema}<ItemSchemaT>> {
12
14
  return (parameters) => {
@@ -28,7 +30,7 @@ function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>
28
30
  triples: [
29
31
  {
30
32
  subject: listVariable,
31
- predicate: ${rdfjsTermExpression(rdf.first)},
33
+ predicate: ${rdfjsTermExpression(rdf.first, { logger })},
32
34
  object: item0Variable,
33
35
  },
34
36
  ],
@@ -53,7 +55,7 @@ function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>
53
55
  triples: [
54
56
  {
55
57
  subject: listVariable,
56
- predicate: ${rdfjsTermExpression(rdf.rest)},
58
+ predicate: ${rdfjsTermExpression(rdf.rest, { logger })},
57
59
  object: rest0Variable,
58
60
  },
59
61
  ],
@@ -70,7 +72,7 @@ function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>
70
72
  triples: [
71
73
  {
72
74
  subject: listVariable,
73
- predicate: { type: "path", pathType: "*", items: [${rdfjsTermExpression(rdf.rest)}] },
75
+ predicate: { type: "path", pathType: "*", items: [${rdfjsTermExpression(rdf.rest, { logger })}] },
74
76
  object: restNVariable,
75
77
  },
76
78
  ],
@@ -84,7 +86,7 @@ function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>
84
86
  triples: [
85
87
  {
86
88
  subject: restNVariable,
87
- predicate: ${rdfjsTermExpression(rdf.first)},
89
+ predicate: ${rdfjsTermExpression(rdf.first, { logger })},
88
90
  object: itemNVariable,
89
91
  },
90
92
  ],
@@ -107,7 +109,7 @@ function ${syntheticNamePrefix}listSparqlWherePatterns<ItemFilterT, ItemSchemaT>
107
109
  triples: [
108
110
  {
109
111
  subject: restNVariable,
110
- predicate: ${rdfjsTermExpression(rdf.rest)},
112
+ predicate: ${rdfjsTermExpression(rdf.rest, { logger })},
111
113
  object: variable("RestNBasic"),
112
114
  },
113
115
  ],
@@ -0,0 +1,2 @@
1
+ export declare const snippets_parseBlankNode: import("ts-poet/build/ConditionalOutput.js").ConditionalOutput;
2
+ //# sourceMappingURL=snippets_parseBlankNode.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { imports } from "../imports.js";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
3
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
4
+ import { snippets_parseIdentifier } from "./snippets_parseIdentifier.js";
5
+ export const snippets_parseBlankNode = conditionalOutput(`${syntheticNamePrefix}parseBlankNode`, code `\
6
+ export function ${syntheticNamePrefix}parseBlankNode(identifier: string): ${imports.Either}<Error, ${imports.BlankNode}> {
7
+ return \
8
+ ${snippets_parseIdentifier}(identifier)\
9
+ .chain((identifier) => (identifier.termType === "BlankNode") ? ${imports.Right}(identifier) : ${imports.Left}(new Error("expected identifier to be BlankNode"))) \
10
+ as ${imports.Either}<Error, ${imports.BlankNode}>;
11
+ }`);
12
+ //# sourceMappingURL=snippets_parseBlankNode.js.map
@@ -0,0 +1,2 @@
1
+ export declare const snippets_parseIdentifier: import("ts-poet/build/ConditionalOutput.js").ConditionalOutput;
2
+ //# sourceMappingURL=snippets_parseIdentifier.d.ts.map