@shaclmate/compiler 4.0.22 → 4.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 (87) hide show
  1. package/dist/ShapesGraphToAstTransformer.js +16 -16
  2. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -5
  3. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +1 -1
  4. package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +4 -3
  5. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +12 -11
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +3 -3
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +6 -9
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +11 -12
  9. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
  11. package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
  12. package/dist/ast/ListType.d.ts +1 -8
  13. package/dist/ast/ListType.js +1 -6
  14. package/dist/ast/ObjectType.d.ts +7 -9
  15. package/dist/ast/ObjectType.js +7 -8
  16. package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -0
  17. package/dist/generators/ts/AbstractLazyObjectType.js +7 -0
  18. package/dist/generators/ts/AbstractNamedUnionType.d.ts +3 -2
  19. package/dist/generators/ts/AbstractNamedUnionType.js +23 -9
  20. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  21. package/dist/generators/ts/AbstractTermType.js +3 -0
  22. package/dist/generators/ts/AbstractType.d.ts +12 -4
  23. package/dist/generators/ts/AbstractUnionType.d.ts +1 -0
  24. package/dist/generators/ts/AbstractUnionType.js +11 -1
  25. package/dist/generators/ts/AnonymousUnionType.d.ts +2 -1
  26. package/dist/generators/ts/AnonymousUnionType.js +6 -3
  27. package/dist/generators/ts/DefaultValueType.d.ts +2 -1
  28. package/dist/generators/ts/DefaultValueType.js +6 -3
  29. package/dist/generators/ts/ListType.d.ts +2 -5
  30. package/dist/generators/ts/ListType.js +11 -27
  31. package/dist/generators/ts/NamedObjectType.d.ts +2 -9
  32. package/dist/generators/ts/NamedObjectType.js +12 -29
  33. package/dist/generators/ts/NamedObjectUnionType.js +1 -1
  34. package/dist/generators/ts/OptionType.d.ts +1 -0
  35. package/dist/generators/ts/OptionType.js +3 -0
  36. package/dist/generators/ts/SetType.d.ts +1 -0
  37. package/dist/generators/ts/SetType.js +3 -0
  38. package/dist/generators/ts/TypeFactory.js +9 -46
  39. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +23 -15
  40. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +6 -0
  41. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +3 -4
  42. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +26 -11
  43. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +5 -14
  44. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +34 -201
  45. package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +3 -11
  46. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +10 -9
  47. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js +4 -4
  48. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
  49. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
  50. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -5
  51. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +5 -10
  52. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +13 -9
  53. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +1 -1
  54. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +11 -2
  55. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +2 -2
  56. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
  57. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
  58. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js +8 -4
  59. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +4 -2
  60. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.d.ts +4 -0
  61. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +66 -0
  62. package/dist/generators/ts/_NamedObjectType/Property.d.ts +1 -2
  63. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +6 -5
  64. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +26 -20
  65. package/dist/generators/ts/_snippets/snippets_LazyObject.js +2 -2
  66. package/dist/generators/ts/_snippets/snippets_LazyObjectOption.js +2 -2
  67. package/dist/generators/ts/_snippets/snippets_LazyObjectSet.js +2 -2
  68. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +5 -3
  69. package/dist/generators/ts/_snippets/snippets_compactRecord.d.ts +2 -0
  70. package/dist/generators/ts/_snippets/snippets_compactRecord.js +16 -0
  71. package/dist/generators/ts/_snippets/{parseIri.d.ts → snippets_parseIri.d.ts} +1 -1
  72. package/dist/generators/ts/_snippets/{parseIri.js → snippets_parseIri.js} +1 -1
  73. package/dist/generators/ts/imports.d.ts +1 -3
  74. package/dist/generators/ts/imports.js +1 -3
  75. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
  76. package/dist/generators/ts/snippets.d.ts +1 -0
  77. package/dist/generators/ts/snippets.js +3 -1
  78. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +1 -1
  79. package/dist/input/generated.d.ts +104 -50
  80. package/dist/input/generated.js +284 -171
  81. package/package.json +2 -2
  82. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +0 -6
  83. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +0 -32
  84. package/dist/enums/IdentifierMintingStrategy.d.ts +0 -9
  85. package/dist/enums/IdentifierMintingStrategy.js +0 -18
  86. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.d.ts +0 -32
  87. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.js +0 -89
@@ -47,12 +47,21 @@ ${joinCode(staticModuleDeclarations
47
47
  get filterType() {
48
48
  return code `${this.staticModuleName}.${syntheticNamePrefix}Filter`;
49
49
  }
50
+ get jsonSchemaFunctionDeclaration() {
51
+ const meta = {
52
+ id: this.name,
53
+ };
54
+ this.comment.ifJust((description) => {
55
+ meta["description"] = description;
56
+ });
57
+ this.label.ifJust((label) => {
58
+ meta["title"] = label;
59
+ });
60
+ return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
61
+ }
50
62
  get jsonTypeAliasDeclaration() {
51
63
  return code `export type ${syntheticNamePrefix}Json = ${this.inlineJsonType.name}`;
52
64
  }
53
- get jsonSchemaFunctionDeclaration() {
54
- return code `export const schema = () => ${this.inlineJsonSchema};`;
55
- }
56
65
  get name() {
57
66
  return this._name;
58
67
  }
@@ -115,6 +124,8 @@ export namespace ${syntheticNamePrefix}Json {
115
124
  staticModuleDeclarations[`${syntheticNamePrefix}valueSparqlWherePatterns`] =
116
125
  code `export const ${syntheticNamePrefix}valueSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
117
126
  }
127
+ staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
128
+ code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
118
129
  return staticModuleDeclarations;
119
130
  }
120
131
  fromJsonExpression({ variables, }) {
@@ -138,12 +149,6 @@ export namespace ${syntheticNamePrefix}Json {
138
149
  }
139
150
  return this.inlineHashStatements({ depth, variables });
140
151
  }
141
- jsonType() {
142
- if (this.features.has("json")) {
143
- return new AbstractType.JsonType(`${this.staticModuleName}.${syntheticNamePrefix}Json`);
144
- }
145
- return this.inlineJsonType;
146
- }
147
152
  jsonSchema({ context, }) {
148
153
  if (this.features.has("json")) {
149
154
  const expression = code `${this.staticModuleName}.${syntheticNamePrefix}Json.schema()`;
@@ -154,6 +159,12 @@ export namespace ${syntheticNamePrefix}Json {
154
159
  }
155
160
  return this.inlineJsonSchema;
156
161
  }
162
+ jsonType() {
163
+ if (this.features.has("json")) {
164
+ return new AbstractType.JsonType(`${this.staticModuleName}.${syntheticNamePrefix}Json`);
165
+ }
166
+ return this.inlineJsonType;
167
+ }
157
168
  toJsonExpression({ variables, }) {
158
169
  if (this.features.has("json")) {
159
170
  return code `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
@@ -167,6 +178,9 @@ export namespace ${syntheticNamePrefix}Json {
167
178
  }
168
179
  return code `${this.inlineToRdfResourceValuesFunction}(${valueVariable}, ${otherVariables})`;
169
180
  }
181
+ toStringExpression({ variables, }) {
182
+ return code `${this.staticModuleName}.${syntheticNamePrefix}toString(${variables.value})`;
183
+ }
170
184
  }
171
185
  __decorate([
172
186
  Memoize()
@@ -38,6 +38,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
38
38
  hashStatements({ variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
39
39
  jsonUiSchemaElement(): Maybe<Code>;
40
40
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
41
+ toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
41
42
  /**
42
43
  * The fromRdfExpression for a term type can be decomposed into multiple sub-expressions with different purposes:
43
44
  *
@@ -127,6 +127,9 @@ export class AbstractTermType extends AbstractType {
127
127
  toRdfResourceValuesExpression({ variables, }) {
128
128
  return code `[${variables.value}]`;
129
129
  }
130
+ toStringExpression({ variables, }) {
131
+ return code `${variables.value}.toString()`;
132
+ }
130
133
  /**
131
134
  * The fromRdfExpression for a term type can be decomposed into multiple sub-expressions with different purposes:
132
135
  *
@@ -79,6 +79,10 @@ export declare abstract class AbstractType {
79
79
  * TypeScript type describing .schema.
80
80
  */
81
81
  abstract readonly schemaType: Code;
82
+ /**
83
+ * The type(s) of the array elements produced by the toRdfResourceValuesExpression.
84
+ */
85
+ abstract readonly toRdfResourceValueTypes: ReadonlySet<"BlankNode" | "NamedNode" | "Literal">;
82
86
  /**
83
87
  * JavaScript typeof(s) the type.
84
88
  */
@@ -217,10 +221,6 @@ export declare abstract class AbstractType {
217
221
  value: Code;
218
222
  };
219
223
  }): Code;
220
- /**
221
- * The type(s) of the array elements produced by the toRdfResourceValuesExpression.
222
- */
223
- abstract readonly toRdfResourceValueTypes: ReadonlySet<"BlankNode" | "NamedNode" | "Literal">;
224
224
  /**
225
225
  * An expression that converts a property value of this type to a value or an array of values that can be .add'd to a Resource with
226
226
  * resource.add(predicate, convertedValue, graph)
@@ -241,6 +241,14 @@ export declare abstract class AbstractType {
241
241
  value: Code;
242
242
  };
243
243
  }): Code;
244
+ /**
245
+ * An expression that converts a value of this type to a human-readable string (toString).
246
+ */
247
+ abstract toStringExpression(parameters: {
248
+ variables: {
249
+ value: Code;
250
+ };
251
+ }): Code;
244
252
  }
245
253
  export declare namespace AbstractType {
246
254
  interface Conversion {
@@ -37,6 +37,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
37
37
  protected get inlineName(): Code;
38
38
  protected get inlineToJsonFunction(): Code;
39
39
  protected get inlineToRdfResourceValuesFunction(): Code;
40
+ protected get inlineToStringFunction(): Code;
40
41
  protected get inlineValueSparqlConstructTriplesFunction(): Code;
41
42
  protected get inlineValueSparqlWherePatternsFunction(): Code;
42
43
  protected get schemaObject(): {
@@ -239,7 +239,7 @@ ${joinCode(this.concreteMembers.map(({ type, typeCheck, unwrap }) => code `if ($
239
239
  ${joinCode([
240
240
  ...this.identifierType
241
241
  .map((identifierType) => code `\
242
- if (filter.${syntheticNamePrefix}identifier !== undefined && !${identifierType.filterFunction}(filter.${syntheticNamePrefix}identifier, value.${syntheticNamePrefix}identifier)) {
242
+ if (filter.${syntheticNamePrefix}identifier !== undefined && !${identifierType.filterFunction}(filter.${syntheticNamePrefix}identifier, value.${syntheticNamePrefix}identifier())) {
243
243
  return false;
244
244
  }`)
245
245
  .toList(),
@@ -430,6 +430,16 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
430
430
 
431
431
  throw new Error("unable to serialize to RDF");
432
432
  }) satisfies ${snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
433
+ }
434
+ get inlineToStringFunction() {
435
+ return code `\
436
+ ((value: ${this.name}): string => {
437
+ ${joinCode(this.concreteMembers.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
438
+ variables: { value: unwrap(code `value`) },
439
+ })}; }`))}
440
+
441
+ throw new Error("unable to serialize to string");
442
+ })`;
433
443
  }
434
444
  get inlineValueSparqlConstructTriplesFunction() {
435
445
  return code `\
@@ -18,9 +18,10 @@ export declare class AnonymousUnionType extends AbstractUnionType<Type> {
18
18
  fromRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["fromRdfResourceValuesExpression"]>[0]): Code;
19
19
  graphqlResolveExpression(_parameters: Parameters<AbstractType["graphqlResolveExpression"]>[0]): Code;
20
20
  hashStatements(parameters: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
21
- jsonType(): AbstractType.JsonType;
22
21
  jsonSchema(_parameters: Parameters<AbstractType["jsonSchema"]>[0]): Code;
22
+ jsonType(): AbstractType.JsonType;
23
23
  toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
24
24
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
25
+ toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
25
26
  }
26
27
  //# sourceMappingURL=AnonymousUnionType.d.ts.map
@@ -39,12 +39,12 @@ export class AnonymousUnionType extends AbstractUnionType {
39
39
  hashStatements(parameters) {
40
40
  return this.inlineHashStatements(parameters);
41
41
  }
42
- jsonType() {
43
- return this.inlineJsonType;
44
- }
45
42
  jsonSchema(_parameters) {
46
43
  return this.inlineJsonSchema;
47
44
  }
45
+ jsonType() {
46
+ return this.inlineJsonType;
47
+ }
48
48
  toJsonExpression({ variables, }) {
49
49
  return code `${this.inlineToJsonFunction}(${variables.value})`;
50
50
  }
@@ -52,5 +52,8 @@ export class AnonymousUnionType extends AbstractUnionType {
52
52
  const { value: valueVariable, ...otherVariables } = variables;
53
53
  return code `${this.inlineToRdfResourceValuesFunction}(${valueVariable}, ${otherVariables})`;
54
54
  }
55
+ toStringExpression({ variables, }) {
56
+ return code `${this.inlineToStringFunction}(${variables.value})`;
57
+ }
55
58
  }
56
59
  //# sourceMappingURL=AnonymousUnionType.js.map
@@ -35,11 +35,12 @@ export declare class DefaultValueType<ItemTypeT extends DefaultValueType.ItemTyp
35
35
  fromRdfResourceValuesExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["fromRdfResourceValuesExpression"]>[0]): Code;
36
36
  graphqlResolveExpression(parameters: Parameters<AbstractContainerType<ItemTypeT>["graphqlResolveExpression"]>[0]): Code;
37
37
  hashStatements(parameters: Parameters<AbstractContainerType<ItemTypeT>["hashStatements"]>[0]): readonly Code[];
38
+ jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
38
39
  jsonType(parameters?: Parameters<AbstractContainerType<ItemTypeT>["jsonType"]>[0]): AbstractType.JsonType;
39
40
  jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
40
- jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
41
41
  toJsonExpression(parameters: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
42
42
  toRdfResourceValuesExpression(parameters: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
43
+ toStringExpression(parameters: Parameters<AbstractType["toStringExpression"]>[0]): Code;
43
44
  }
44
45
  export declare namespace DefaultValueType {
45
46
  type ItemType = Exclude<AbstractContainerType.ItemType, BlankNodeType>;
@@ -133,15 +133,15 @@ export class DefaultValueType extends AbstractContainerType {
133
133
  hashStatements(parameters) {
134
134
  return this.itemType.hashStatements(parameters);
135
135
  }
136
+ jsonSchema(parameters) {
137
+ return this.itemType.jsonSchema(parameters);
138
+ }
136
139
  jsonType(parameters) {
137
140
  return this.itemType.jsonType(parameters);
138
141
  }
139
142
  jsonUiSchemaElement(parameters) {
140
143
  return this.itemType.jsonUiSchemaElement(parameters);
141
144
  }
142
- jsonSchema(parameters) {
143
- return this.itemType.jsonSchema(parameters);
144
- }
145
145
  toJsonExpression(parameters) {
146
146
  return this.itemType.toJsonExpression(parameters);
147
147
  }
@@ -151,6 +151,9 @@ export class DefaultValueType extends AbstractContainerType {
151
151
  .map((defaultValuePrimitiveExpression) => code `${this.itemType.equalsFunction}(${variables.value}, ${defaultValuePrimitiveExpression}).isLeft() ? ${this.itemType.toRdfResourceValuesExpression(parameters)} : []`)
152
152
  .orDefault(code `${this.itemType.toRdfResourceValuesExpression(parameters)}.filter(value => !value.equals(${this.defaultValueTermExpression}))`);
153
153
  }
154
+ toStringExpression(parameters) {
155
+ return this.itemType.toStringExpression(parameters);
156
+ }
154
157
  }
155
158
  __decorate([
156
159
  Memoize()
@@ -1,6 +1,4 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
- import type { Maybe } from "purify-ts";
3
- import type { IdentifierMintingStrategy } from "../../enums/IdentifierMintingStrategy.js";
4
2
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
5
3
  import type { AnonymousUnionType } from "./AnonymousUnionType.js";
6
4
  import type { BigDecimalType } from "./BigDecimalType.js";
@@ -22,13 +20,11 @@ import type { TermType } from "./TermType.js";
22
20
  import type { Type } from "./Type.js";
23
21
  import { type Code } from "./ts-poet-wrapper.js";
24
22
  export declare class ListType<ItemTypeT extends ListType.ItemType> extends AbstractCollectionType<ItemTypeT> {
25
- private readonly identifierMintingStrategy;
26
23
  private readonly identifierNodeKind;
27
24
  private readonly toRdfTypes;
28
25
  readonly kind = "ListType";
29
- constructor({ identifierNodeKind, identifierMintingStrategy, toRdfTypes, ...superParameters }: {
26
+ constructor({ identifierNodeKind, toRdfTypes, ...superParameters }: {
30
27
  identifierNodeKind: ListType<ItemTypeT>["identifierNodeKind"];
31
- identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
32
28
  toRdfTypes: readonly NamedNode[];
33
29
  } & ConstructorParameters<typeof AbstractCollectionType<ItemTypeT>>[0]);
34
30
  get valueSparqlConstructTriplesFunction(): Code;
@@ -36,6 +32,7 @@ export declare class ListType<ItemTypeT extends ListType.ItemType> extends Abstr
36
32
  fromRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["fromRdfResourceValuesExpression"]>[0]): Code;
37
33
  jsonType(): AbstractCollectionType.JsonType;
38
34
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
35
+ toStringExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toStringExpression"]>[0]): Code;
39
36
  }
40
37
  export declare namespace ListType {
41
38
  type ItemType = AnonymousUnionType | BigDecimalType | BigIntType | BlankNodeType | BooleanType | DateTimeType | DateType | FloatType | IdentifierType | IntType | IriType | LiteralType | NamedObjectUnionType | NamedUnionType | NamedObjectType | StringType | TermType;
@@ -12,14 +12,12 @@ import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
12
12
  import { snippets } from "./snippets.js";
13
13
  import { code, joinCode } from "./ts-poet-wrapper.js";
14
14
  export class ListType extends AbstractCollectionType {
15
- identifierMintingStrategy;
16
15
  identifierNodeKind;
17
16
  toRdfTypes;
18
17
  kind = "ListType";
19
- constructor({ identifierNodeKind, identifierMintingStrategy, toRdfTypes, ...superParameters }) {
18
+ constructor({ identifierNodeKind, toRdfTypes, ...superParameters }) {
20
19
  super(superParameters);
21
20
  this.identifierNodeKind = identifierNodeKind;
22
- this.identifierMintingStrategy = identifierMintingStrategy.orDefault(identifierNodeKind === "BlankNode" ? "blankNode" : "sha256");
23
21
  this.toRdfTypes = toRdfTypes;
24
22
  }
25
23
  get valueSparqlConstructTriplesFunction() {
@@ -48,43 +46,26 @@ export class ListType extends AbstractCollectionType {
48
46
  return new AbstractCollectionType.JsonType(code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().name})[]`);
49
47
  }
50
48
  toRdfResourceValuesExpression({ variables, }) {
51
- let listIdentifier;
49
+ let mintListIdentifierFunction;
50
+ let mintSubListIdentifierFunction;
52
51
  let resourceTypeName;
53
- let subListIdentifier;
54
52
  switch (this.identifierNodeKind) {
55
53
  case "BlankNode": {
56
- listIdentifier =
57
- subListIdentifier = code `${imports.dataFactory}.blankNode()`;
54
+ mintListIdentifierFunction =
55
+ mintSubListIdentifierFunction = code `(() => ${imports.dataFactory}.blankNode())`;
58
56
  resourceTypeName = code `${imports.Resource}<${imports.BlankNode}>`;
59
57
  break;
60
58
  }
61
59
  case "IRI": {
62
- switch (this.identifierMintingStrategy) {
63
- case "blankNode":
64
- throw new RangeError(this.identifierMintingStrategy);
65
- case "sha256":
66
- listIdentifier = code `${imports.dataFactory}.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
67
- (hasher, item) => {
68
- ${joinCode(this.itemType.hashStatements({ depth: 0, variables: { hasher: code `hasher`, value: code `item` } }).concat())}
69
- return hasher;
70
- },
71
- ${imports.sha256}.create(),
72
- )}\`)`;
73
- break;
74
- case "uuidv4":
75
- listIdentifier = code `${imports.dataFactory}.namedNode(\`urn:shaclmate:list:\${${imports.uuid}.v4()}\`)`;
76
- break;
77
- }
78
60
  resourceTypeName = code `${imports.Resource}<${imports.NamedNode}>`;
79
- subListIdentifier = code `${imports.dataFactory}.namedNode(\`\${listResource.identifier.value}:\${itemIndex}\`)`;
80
- break;
61
+ throw new RangeError("list IRI minting is unsupported");
81
62
  }
82
63
  }
83
64
  return code `[${variables.value}.length > 0 ? ${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
84
65
  if (itemIndex === 0) {
85
66
  currentSubListResource = listResource;
86
67
  } else {
87
- const newSubListResource = ${variables.resourceSet}.resource(${subListIdentifier});
68
+ const newSubListResource = ${variables.resourceSet}.resource(${mintSubListIdentifierFunction}());
88
69
  currentSubListResource!.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, newSubListResource.identifier, ${variables.graph});
89
70
  currentSubListResource = newSubListResource;
90
71
  }
@@ -101,13 +82,16 @@ export class ListType extends AbstractCollectionType {
101
82
  },
102
83
  {
103
84
  currentSubListResource: null,
104
- listResource: resourceSet.resource(${listIdentifier}),
85
+ listResource: resourceSet.resource(${mintListIdentifierFunction}()),
105
86
  } as {
106
87
  currentSubListResource: ${resourceTypeName} | null;
107
88
  listResource: ${resourceTypeName};
108
89
  },
109
90
  ).listResource.identifier : ${rdfjsTermExpression(rdf.nil, { logger: this.logger })}]`;
110
91
  }
92
+ toStringExpression({ variables, }) {
93
+ return code `\`[\${${variables.value}.map(item => (${this.itemType.toStringExpression({ variables: { value: code `item` } })}))}]\``;
94
+ }
111
95
  }
112
96
  __decorate([
113
97
  Memoize()
@@ -3,7 +3,6 @@ import { Maybe, NonEmptyList } from "purify-ts";
3
3
  import type { TsFeature } from "../../enums/TsFeature.js";
4
4
  import type { TsObjectDeclarationType } from "../../enums/TsObjectDeclarationType.js";
5
5
  import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
6
- import { IdentifierPrefixProperty as _IdentifierPrefixProperty } from "./_NamedObjectType/IdentifierPrefixProperty.js";
7
6
  import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
8
7
  import type { Property as _Property } from "./_NamedObjectType/Property.js";
9
8
  import { ShaclProperty as _ShaclProperty } from "./_NamedObjectType/ShaclProperty.js";
@@ -29,7 +28,7 @@ export declare class NamedObjectType extends AbstractType {
29
28
  readonly staticModuleName: string;
30
29
  readonly synthetic: boolean;
31
30
  readonly typeofs: NonEmptyList<"object">;
32
- constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyIdentifierProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }: {
31
+ constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }: {
33
32
  abstract: boolean;
34
33
  comment: Maybe<string>;
35
34
  declarationType: TsObjectDeclarationType;
@@ -42,7 +41,6 @@ export declare class NamedObjectType extends AbstractType {
42
41
  lazyAncestorObjectTypes: () => readonly NamedObjectType[];
43
42
  lazyChildObjectTypes: () => readonly NamedObjectType[];
44
43
  lazyDiscriminantProperty: (namedObjectType: NamedObjectType) => NamedObjectType.DiscriminantProperty;
45
- lazyIdentifierProperty: (namedObjectType: NamedObjectType) => NamedObjectType.IdentifierProperty;
46
44
  lazyDescendantObjectTypes: () => readonly NamedObjectType[];
47
45
  lazyParentObjectTypes: () => readonly NamedObjectType[];
48
46
  lazyProperties: (namedObjectType: NamedObjectType) => readonly NamedObjectType.Property[];
@@ -67,12 +65,9 @@ export declare class NamedObjectType extends AbstractType {
67
65
  get filterType(): Code;
68
66
  get fromRdfTypeVariable(): Maybe<Code>;
69
67
  get graphqlType(): AbstractType.GraphqlType;
70
- get identifierProperty(): NamedObjectType.IdentifierProperty;
71
68
  get identifierTypeAlias(): Code;
72
69
  get mutable(): boolean;
73
70
  get objectSetMethodNames(): NamedObjectType.ObjectSetMethodNames;
74
- get ownProperties(): readonly NamedObjectType.Property[];
75
- get ownShaclProperties(): readonly NamedObjectType.ShaclProperty<Type>[];
76
71
  get parentObjectTypes(): readonly NamedObjectType[];
77
72
  get properties(): readonly NamedObjectType.Property[];
78
73
  get schema(): Code;
@@ -97,19 +92,17 @@ export declare class NamedObjectType extends AbstractType {
97
92
  parameters: Code;
98
93
  }): Code;
99
94
  toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
95
+ toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
100
96
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
101
97
  protected ensureAtMostOneSuperObjectType(): void;
102
98
  private readonly lazyAncestorObjectTypes;
103
99
  private readonly lazyChildObjectTypes;
104
100
  private readonly lazyDescendantObjectTypes;
105
101
  private readonly lazyDiscriminantProperty;
106
- private readonly lazyIdentifierProperty;
107
102
  private readonly lazyParentObjectTypes;
108
103
  private readonly lazyProperties;
109
104
  }
110
105
  export declare namespace NamedObjectType {
111
- const IdentifierPrefixProperty: typeof _IdentifierPrefixProperty;
112
- type IdentifierPrefixProperty = _IdentifierPrefixProperty;
113
106
  const IdentifierProperty: typeof _IdentifierProperty;
114
107
  type IdentifierProperty = _IdentifierProperty;
115
108
  type ObjectSetMethodNames = {
@@ -9,7 +9,6 @@ import { camelCase } from "change-case";
9
9
  import { Maybe, NonEmptyList } from "purify-ts";
10
10
  import { Memoize } from "typescript-memoize";
11
11
  import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
12
- import { IdentifierPrefixProperty as _IdentifierPrefixProperty } from "./_NamedObjectType/IdentifierPrefixProperty.js";
13
12
  import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
14
13
  import { identifierTypeDeclarations } from "./_NamedObjectType/identifierTypeDeclarations.js";
15
14
  import { NamedObjectType_classDeclaration } from "./_NamedObjectType/NamedObjectType_classDeclaration.js";
@@ -39,6 +38,7 @@ import { NamedObjectType_sparqlConstructQueryFunctionDeclaration } from "./_Name
39
38
  import { NamedObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
40
39
  import { NamedObjectType_toJsonFunctionOrMethodDeclaration } from "./_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js";
41
40
  import { NamedObjectType_toRdfResourceFunctionOrMethodDeclaration } from "./_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js";
41
+ import { NamedObjectType_toStringFunctionOrMethodDeclarations } from "./_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js";
42
42
  import { NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js";
43
43
  import { NamedObjectType_valueSparqlWherePatternsFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js";
44
44
  import { ShaclProperty as _ShaclProperty } from "./_NamedObjectType/ShaclProperty.js";
@@ -62,7 +62,7 @@ export class NamedObjectType extends AbstractType {
62
62
  staticModuleName;
63
63
  synthetic;
64
64
  typeofs = NonEmptyList(["object"]);
65
- constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyIdentifierProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
65
+ constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
66
66
  super(superParameters);
67
67
  this.abstract = abstract;
68
68
  this.declarationType = declarationType;
@@ -76,7 +76,6 @@ export class NamedObjectType extends AbstractType {
76
76
  this.lazyChildObjectTypes = lazyChildObjectTypes;
77
77
  this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
78
78
  this.lazyDiscriminantProperty = lazyDiscriminantProperty;
79
- this.lazyIdentifierProperty = lazyIdentifierProperty;
80
79
  this.lazyParentObjectTypes = lazyParentObjectTypes;
81
80
  this.lazyProperties = lazyProperties;
82
81
  this.name = name;
@@ -135,6 +134,8 @@ export class NamedObjectType extends AbstractType {
135
134
  ? NamedObjectType_toJsonFunctionOrMethodDeclaration.call(this).toList()
136
135
  : []), ...(this.declarationType === "interface"
137
136
  ? NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.call(this).toList()
137
+ : []), ...(this.declarationType === "interface"
138
+ ? NamedObjectType_toStringFunctionOrMethodDeclarations.call(this)
138
139
  : []), ...NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.bind(this)().toList());
139
140
  if (staticModuleDeclarations.length > 0) {
140
141
  declarations.push(code `\
@@ -186,9 +187,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
186
187
  get graphqlType() {
187
188
  return new AbstractType.GraphqlType(code `${this.staticModuleName}.${syntheticNamePrefix}GraphQL`);
188
189
  }
189
- get identifierProperty() {
190
- return this.lazyIdentifierProperty(this);
191
- }
192
190
  get identifierTypeAlias() {
193
191
  return code `${this.staticModuleName}.${syntheticNamePrefix}Identifier`;
194
192
  }
@@ -198,18 +196,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
198
196
  get objectSetMethodNames() {
199
197
  return NamedObjectType_objectSetMethodNames.call(this);
200
198
  }
201
- get ownProperties() {
202
- if (this.parentObjectTypes.length === 0) {
203
- // Consider that a root of the object type hierarchy "owns" the identifier and type discriminant properties
204
- // for all of its subtypes in the hierarchy.
205
- // invariant(this.properties.length >= 2, this.name);
206
- return this.properties;
207
- }
208
- return this.ownShaclProperties;
209
- }
210
- get ownShaclProperties() {
211
- return this.properties.filter((property) => property.kind === "ShaclProperty");
212
- }
213
199
  get parentObjectTypes() {
214
200
  return this.lazyParentObjectTypes();
215
201
  }
@@ -307,6 +293,14 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
307
293
  return code `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
308
294
  }
309
295
  }
296
+ toStringExpression({ variables, }) {
297
+ switch (this.declarationType) {
298
+ case "class":
299
+ return code `${variables.value}.toString()`;
300
+ case "interface":
301
+ return code `${this.staticModuleName}.${syntheticNamePrefix}toString(${variables.value})`;
302
+ }
303
+ }
310
304
  toRdfResourceValuesExpression({ variables, }) {
311
305
  switch (this.declarationType) {
312
306
  case "class":
@@ -324,7 +318,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
324
318
  lazyChildObjectTypes;
325
319
  lazyDescendantObjectTypes;
326
320
  lazyDiscriminantProperty;
327
- lazyIdentifierProperty;
328
321
  lazyParentObjectTypes;
329
322
  lazyProperties;
330
323
  }
@@ -370,9 +363,6 @@ __decorate([
370
363
  __decorate([
371
364
  Memoize()
372
365
  ], NamedObjectType.prototype, "graphqlType", null);
373
- __decorate([
374
- Memoize()
375
- ], NamedObjectType.prototype, "identifierProperty", null);
376
366
  __decorate([
377
367
  Memoize()
378
368
  ], NamedObjectType.prototype, "identifierTypeAlias", null);
@@ -382,12 +372,6 @@ __decorate([
382
372
  __decorate([
383
373
  Memoize()
384
374
  ], NamedObjectType.prototype, "objectSetMethodNames", null);
385
- __decorate([
386
- Memoize()
387
- ], NamedObjectType.prototype, "ownProperties", null);
388
- __decorate([
389
- Memoize()
390
- ], NamedObjectType.prototype, "ownShaclProperties", null);
391
375
  __decorate([
392
376
  Memoize()
393
377
  ], NamedObjectType.prototype, "parentObjectTypes", null);
@@ -419,7 +403,6 @@ __decorate([
419
403
  Memoize()
420
404
  ], NamedObjectType.prototype, "jsonType", null);
421
405
  (function (NamedObjectType) {
422
- NamedObjectType.IdentifierPrefixProperty = _IdentifierPrefixProperty;
423
406
  NamedObjectType.IdentifierProperty = _IdentifierProperty;
424
407
  NamedObjectType.ShaclProperty = _ShaclProperty;
425
408
  NamedObjectType.DiscriminantProperty = _DiscriminantProperty;
@@ -142,7 +142,7 @@ export namespace ${syntheticNamePrefix}Identifier {
142
142
  get schemaVariableStatement() {
143
143
  const commonPropertiesByName = {};
144
144
  this.concreteMembers.forEach((member, memberI) => {
145
- for (const memberTypeProperty of member.type.ownProperties.concat(member.type.ancestorObjectTypes.flatMap((ancestorObjectType) => ancestorObjectType.ownProperties))) {
145
+ for (const memberTypeProperty of member.type.properties.concat(member.type.ancestorObjectTypes.flatMap((ancestorObjectType) => ancestorObjectType.properties))) {
146
146
  if (memberTypeProperty.kind !== "ShaclProperty") {
147
147
  continue;
148
148
  }
@@ -29,6 +29,7 @@ export declare class OptionType<ItemTypeT extends OptionType.ItemType> extends A
29
29
  jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
30
30
  toJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toJsonExpression"]>[0]): Code;
31
31
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
32
+ toStringExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toStringExpression"]>[0]): Code;
32
33
  }
33
34
  export declare namespace OptionType {
34
35
  type ItemType = AbstractContainerType.ItemType;
@@ -138,6 +138,9 @@ export class OptionType extends AbstractContainerType {
138
138
  }
139
139
  return toRdfExpression;
140
140
  }
141
+ toStringExpression({ variables, }) {
142
+ return code `${variables.value}.map(item => (${this.itemType.toStringExpression({ variables: { value: code `item` } })})).extract()`;
143
+ }
141
144
  }
142
145
  __decorate([
143
146
  Memoize()
@@ -9,6 +9,7 @@ export declare class SetType<ItemTypeT extends SetType.ItemType> extends Abstrac
9
9
  fromRdfResourceValuesExpression(parameters: Parameters<AbstractCollectionType<ItemTypeT>["fromRdfResourceValuesExpression"]>[0]): Code;
10
10
  jsonType(): AbstractCollectionType.JsonType;
11
11
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
12
+ toStringExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toStringExpression"]>[0]): Code;
12
13
  }
13
14
  export declare namespace SetType {
14
15
  type ItemType = AbstractCollectionType.ItemType;
@@ -57,6 +57,9 @@ export class SetType extends AbstractCollectionType {
57
57
  variables: { ...variables, value: code `item` },
58
58
  })})`;
59
59
  }
60
+ toStringExpression({ variables, }) {
61
+ return code `(${variables.value}.length > 0 ? \`[\${${variables.value}.map(item => (${this.itemType.toStringExpression({ variables: { value: code `item` } })}))}]\` : undefined)`;
62
+ }
60
63
  }
61
64
  __decorate([
62
65
  Memoize()