@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
@@ -99,58 +99,28 @@ export declare class ObjectType extends AbstractType {
99
99
  equals(other: ObjectType): boolean;
100
100
  sortProperties(): void;
101
101
  toJSON(): {
102
- fromRdfType: string | undefined;
102
+ fromRdfType: NamedNode<string> | undefined;
103
103
  identifierMintingStrategy: "blankNode" | "sha256" | "uuidv4" | undefined;
104
104
  identifierType: {
105
- hasValues: ({
106
- termType: "BlankNode";
107
- value: string;
108
- datatype?: undefined;
109
- language?: undefined;
110
- } | {
111
- datatype: string;
112
- language: string;
113
- termType: "Literal";
114
- value: string;
115
- } | {
116
- termType: "NamedNode";
117
- value: string;
118
- datatype?: undefined;
119
- language?: undefined;
120
- })[] | undefined;
121
- in: ({
122
- termType: "BlankNode";
123
- value: string;
124
- datatype?: undefined;
125
- language?: undefined;
126
- } | {
127
- datatype: string;
128
- language: string;
129
- termType: "Literal";
130
- value: string;
131
- } | {
132
- termType: "NamedNode";
133
- value: string;
134
- datatype?: undefined;
135
- language?: undefined;
136
- })[] | undefined;
105
+ hasValues: readonly NamedNode<string>[] | undefined;
106
+ in: readonly NamedNode<string>[] | undefined;
137
107
  nodeKinds: NodeKind[];
138
108
  comment: string | undefined;
139
109
  kind: string;
140
110
  label: string | undefined;
141
111
  name: string | undefined;
142
112
  recursive: boolean | undefined;
143
- shapeIdentifier: string;
113
+ shapeIdentifier: BlankNode | NamedNode<string>;
144
114
  };
145
- parentObjectTypes: string[] | undefined;
115
+ parentObjectTypes: (string | BlankNode | NamedNode<string>)[] | undefined;
146
116
  synthetic: boolean | undefined;
147
- toRdfTypes: string[] | undefined;
117
+ toRdfTypes: readonly NamedNode<string>[] | undefined;
148
118
  comment: string | undefined;
149
119
  kind: string;
150
120
  label: string | undefined;
151
121
  name: string | undefined;
152
122
  recursive: boolean | undefined;
153
- shapeIdentifier: string;
123
+ shapeIdentifier: BlankNode | NamedNode<string>;
154
124
  };
155
125
  }
156
126
  export declare namespace ObjectType {
@@ -227,14 +197,14 @@ export declare namespace ObjectType {
227
197
  order: number;
228
198
  path: string;
229
199
  recursive: boolean | undefined;
230
- shapeIdentifier: string;
200
+ shapeIdentifier: BlankNode | NamedNode<string>;
231
201
  type: {
232
202
  comment: string | undefined;
233
203
  kind: string;
234
204
  label: string | undefined;
235
205
  name: string | undefined;
236
206
  recursive: boolean | undefined;
237
- shapeIdentifier: string;
207
+ shapeIdentifier: BlankNode | NamedNode<string>;
238
208
  };
239
209
  visibility: Visibility;
240
210
  };
@@ -4,7 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { PropertyPath, Resource } from "@rdfx/resource";
7
+ import { PropertyPath } from "@rdfx/resource";
8
+ import { NTriplesIdentifier } from "@rdfx/string";
8
9
  import genericToposort from "toposort";
9
10
  import { invariant } from "ts-invariant";
10
11
  import { Memoize } from "typescript-memoize";
@@ -169,16 +170,15 @@ export class ObjectType extends AbstractType {
169
170
  toJSON() {
170
171
  return {
171
172
  ...super.toJSON(),
172
- fromRdfType: this.fromRdfType.map(Resource.Identifier.toString).extract(),
173
+ fromRdfType: this.fromRdfType.extract(),
173
174
  identifierMintingStrategy: this.identifierMintingStrategy.extract(),
174
175
  identifierType: this.identifierType.toJSON(),
175
176
  parentObjectTypes: this.parentObjectTypes.length > 0
176
- ? this.parentObjectTypes.map((parentObjectType) => parentObjectType.name.orDefault(Resource.Identifier.toString(parentObjectType.shapeIdentifier)))
177
+ ? this.parentObjectTypes.map((parentObjectType) => parentObjectType.name.extract() ??
178
+ parentObjectType.shapeIdentifier)
177
179
  : undefined,
178
180
  synthetic: this.synthetic ? true : undefined,
179
- toRdfTypes: this.toRdfTypes.length > 0
180
- ? this.toRdfTypes.map(Resource.Identifier.toString)
181
- : undefined,
181
+ toRdfTypes: this.toRdfTypes.length > 0 ? this.toRdfTypes : undefined,
182
182
  };
183
183
  }
184
184
  }
@@ -372,7 +372,7 @@ const nodeKinds = new Set(["BlankNode", "IRI"]);
372
372
  order: this.order,
373
373
  path: PropertyPath.toString(this.path),
374
374
  recursive: this.recursive ? true : undefined,
375
- shapeIdentifier: Resource.Identifier.toString(this.shapeIdentifier),
375
+ shapeIdentifier: this.shapeIdentifier,
376
376
  type: this.type.toJSON(),
377
377
  visibility: this.visibility,
378
378
  };
@@ -392,18 +392,14 @@ const nodeKinds = new Set(["BlankNode", "IRI"]);
392
392
  const objectTypeGraphNodes = [];
393
393
  const objectTypeGraphEdges = [];
394
394
  for (const objectType of objectTypes) {
395
- const objectTypeShapeIdentifier = Resource.Identifier.toString(objectType.shapeIdentifier);
395
+ const objectTypeShapeIdentifier = NTriplesIdentifier.stringify(objectType.shapeIdentifier);
396
396
  invariant(!objectTypesByShapeIdentifier[objectTypeShapeIdentifier]);
397
397
  objectTypesByShapeIdentifier[objectTypeShapeIdentifier] = objectType;
398
398
  objectTypeGraphNodes.push(objectTypeShapeIdentifier);
399
399
  for (const parentAstObjectType of objectType.parentObjectTypes) {
400
- // console.log(
401
- // objectTypeShapeIdentifier,
402
- // Resource.Identifier.toString(parentAstObjectType.shapeIdentifier),
403
- // );
404
400
  objectTypeGraphEdges.push([
405
401
  objectTypeShapeIdentifier,
406
- Resource.Identifier.toString(parentAstObjectType.shapeIdentifier),
402
+ NTriplesIdentifier.stringify(parentAstObjectType.shapeIdentifier),
407
403
  ]);
408
404
  }
409
405
  }
@@ -21,7 +21,7 @@ export declare class SetType<ItemTypeT extends SetType.ItemType = SetType.ItemTy
21
21
  label: string | undefined;
22
22
  name: string | undefined;
23
23
  recursive: boolean | undefined;
24
- shapeIdentifier: string;
24
+ shapeIdentifier: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
25
25
  };
26
26
  }
27
27
  export declare namespace SetType {
@@ -17,7 +17,7 @@ export declare class UnionType<MemberTypeT extends UnionType.MemberType = UnionT
17
17
  label: string | undefined;
18
18
  name: string | undefined;
19
19
  recursive: boolean | undefined;
20
- shapeIdentifier: string;
20
+ shapeIdentifier: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
21
21
  };
22
22
  }
23
23
  export declare namespace UnionType {
@@ -1,4 +1,3 @@
1
- import { Resource } from "@rdfx/resource";
2
1
  import { Maybe } from "purify-ts";
3
2
  export function transformAstToLabeledPropertyGraph(ast) {
4
3
  const nodes = [];
@@ -34,7 +33,7 @@ export function transformAstToLabeledPropertyGraph(ast) {
34
33
  case "UnionType":
35
34
  if (itemType.name.isJust()) {
36
35
  relationships.push({
37
- id: Resource.Identifier.toString(namedObjectTypeProperty.shapeIdentifier),
36
+ id: namedObjectTypeProperty.shapeIdentifier.toString(),
38
37
  label: Maybe.of(namedObjectTypeProperty.name),
39
38
  properties: {},
40
39
  sourceNodeId: id,
@@ -68,9 +67,9 @@ export function transformAstToLabeledPropertyGraph(ast) {
68
67
  };
69
68
  }
70
69
  function typeId(type) {
71
- return type.name.orDefault(Resource.Identifier.toString(type.shapeIdentifier));
70
+ return type.name.orDefault(type.shapeIdentifier.toString());
72
71
  }
73
72
  function typeName(type) {
74
- return type.name.orDefault(Resource.Identifier.toString(type.shapeIdentifier));
73
+ return type.name.orDefault(type.shapeIdentifier.toString());
75
74
  }
76
75
  //# sourceMappingURL=transformAstToLabeledPropertyGraph.js.map
@@ -49,7 +49,7 @@ export class AbstractDateType extends AbstractPrimitiveType {
49
49
  return new AbstractPrimitiveType.JsonType(code `string`);
50
50
  }
51
51
  toRdfResourceValuesExpression({ variables, }) {
52
- return code `[${snippets.literalFactory}.date(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
52
+ return code `[${snippets.literalFactory}.date(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
53
53
  }
54
54
  fromRdfExpressionChain({ variables, }) {
55
55
  return {
@@ -3,11 +3,11 @@ import type { IdentifierNodeKind } from "@shaclmate/shacl-ast";
3
3
  import { AbstractTermType } from "./AbstractTermType.js";
4
4
  import { type Code } from "./ts-poet-wrapper.js";
5
5
  export declare abstract class AbstractIdentifierType<IdentifierT extends BlankNode | NamedNode> extends AbstractTermType<NamedNode, IdentifierT> {
6
- abstract readonly fromStringFunction: Code;
7
6
  readonly graphqlType: import("./AbstractType.js").AbstractType.GraphqlType;
8
7
  abstract readonly kind: "BlankNodeType" | "IdentifierType" | "IriType";
9
8
  abstract readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
10
- readonly toStringFunction: Code;
9
+ abstract readonly parseFunction: Code;
10
+ readonly stringifyFunction: Code;
11
11
  get conversions(): readonly AbstractTermType.Conversion[];
12
12
  graphqlResolveExpression({ variables: { value }, }: Parameters<AbstractTermType["graphqlResolveExpression"]>[0]): Code;
13
13
  }
@@ -10,10 +10,7 @@ import { imports } from "./imports.js";
10
10
  import { code } from "./ts-poet-wrapper.js";
11
11
  export class AbstractIdentifierType extends AbstractTermType {
12
12
  graphqlType = new AbstractTermType.GraphqlType(code `${imports.GraphQLString}`);
13
- toStringFunction = // Re-export rdfjsResource.Resource.Identifier.toString
14
- code `\
15
- // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
16
- export const toString = ${imports.Resource}.Identifier.toString`;
13
+ stringifyFunction = code `${imports.NTriplesTerm}.stringify`;
17
14
  get conversions() {
18
15
  const conversions = super.conversions.concat();
19
16
  if (this.nodeKinds.has("IRI")) {
@@ -29,7 +26,7 @@ export const toString = ${imports.Resource}.Identifier.toString`;
29
26
  return conversions;
30
27
  }
31
28
  graphqlResolveExpression({ variables: { value }, }) {
32
- return code `${imports.Resource}.Identifier.toString(${value})`;
29
+ return code `${imports.NTriplesTerm}.stringify(${value})`;
33
30
  }
34
31
  }
35
32
  __decorate([
@@ -92,7 +92,7 @@ ${this.jsonTypeAliasDeclaration}
92
92
  export namespace ${syntheticNamePrefix}Json {
93
93
  ${this.jsonSchemaFunctionDeclaration}
94
94
 
95
- export function ${syntheticNamePrefix}parse(json: unknown): ${imports.Either}<Error, ${syntheticNamePrefix}Json> {
95
+ export function parse(json: unknown): ${imports.Either}<Error, ${syntheticNamePrefix}Json> {
96
96
  const jsonSafeParseResult = schema().safeParse(json);
97
97
  if (!jsonSafeParseResult.success) { return ${imports.Left}(jsonSafeParseResult.error); }
98
98
  return ${imports.Right}(jsonSafeParseResult.data);
@@ -51,7 +51,7 @@ export class AbstractNumericType extends AbstractPrimitiveType {
51
51
  }
52
52
  }
53
53
  toRdfResourceValuesExpression({ variables, }) {
54
- return code `[${snippets.literalFactory}.${this.typeofs[0]}(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
54
+ return code `[${snippets.literalFactory}.${this.typeofs[0]}(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
55
55
  }
56
56
  fromRdfExpressionChain({ variables, }) {
57
57
  return {
@@ -136,7 +136,7 @@ export class AbstractTermType extends AbstractType {
136
136
  fromRdfExpressionChain({ variables, }) {
137
137
  let valueToExpression;
138
138
  if (this.in_.length > 0) {
139
- valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_)), { on: ", " })}])`;
139
+ valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger })), { on: ", " })}])`;
140
140
  }
141
141
  else if (this.nodeKinds.size < 3) {
142
142
  const eitherTypeParameters = code `<Error, ${this.name}>`;
@@ -152,7 +152,7 @@ export class AbstractTermType extends AbstractType {
152
152
  return {
153
153
  hasValues: this.hasValues.length > 0
154
154
  ? code `\
155
- chain(values => ${imports.Either}.sequence([${joinCode(this.hasValues.map(rdfjsTermExpression), { on: ", " })}].map(hasValue => values.find(value => value.term.equals(hasValue)))).map(() => values))`
155
+ chain(values => ${imports.Either}.sequence([${joinCode(this.hasValues.map((hasValue) => rdfjsTermExpression(hasValue, { logger: this.logger })), { on: ", " })}].map(hasValue => values.find(value => value.term.equals(hasValue)))).map(() => values))`
156
156
  : undefined,
157
157
  valueTo: code `chain(values => values.chainMap(value => ${valueToExpression}))`,
158
158
  };
@@ -1,10 +1,12 @@
1
1
  import type { Maybe, NonEmptyList } from "purify-ts";
2
+ import type { Logger } from "ts-log";
2
3
  import type { Typeof } from "./Typeof.js";
3
4
  import { type Code } from "./ts-poet-wrapper.js";
4
5
  /**
5
6
  * Abstract base class all types.
6
7
  */
7
8
  export declare abstract class AbstractType {
9
+ protected readonly logger: Logger;
8
10
  /**
9
11
  * Is the type abstract?
10
12
  */
@@ -104,9 +106,10 @@ export declare abstract class AbstractType {
104
106
  * - variablePrefix: string prefix to use for new variables
105
107
  */
106
108
  abstract readonly valueSparqlWherePatternsFunction: Code;
107
- constructor({ comment, label, }: {
109
+ constructor({ comment, label, logger, }: {
108
110
  comment: Maybe<string>;
109
111
  label: Maybe<string>;
112
+ logger: Logger;
110
113
  });
111
114
  /**
112
115
  * Helper to compose the result of schema along the type hierarchy.
@@ -177,6 +180,19 @@ export declare abstract class AbstractType {
177
180
  value: Code;
178
181
  };
179
182
  }): readonly Code[];
183
+ /**
184
+ * Zod schema for the JSON type of this type.
185
+ *
186
+ * This method is called in two contexts:
187
+ * "property": from a ShaclProperty, while generating the z.object properties of an NamedObjectType
188
+ * "type": from another Type e.g., an OptionType or UnionType
189
+ *
190
+ * z.lazy() should only be returned for "property".
191
+ */
192
+ abstract jsonSchema(parameters: {
193
+ includeDiscriminantProperty?: boolean;
194
+ context: "property" | "type";
195
+ }): Code;
180
196
  /**
181
197
  * JSON-compatible version of the type.
182
198
  */
@@ -191,19 +207,6 @@ export declare abstract class AbstractType {
191
207
  scopePrefix: Code;
192
208
  };
193
209
  }): Maybe<Code>;
194
- /**
195
- * Zod schema for the JSON type of this type.
196
- *
197
- * This method is called in two contexts:
198
- * "property": from a ShaclProperty, while generating the z.object properties of an NamedObjectType
199
- * "type": from another Type e.g., an OptionType or UnionType
200
- *
201
- * z.lazy() should only be returned for "property".
202
- */
203
- abstract jsonSchema(parameters: {
204
- includeDiscriminantProperty?: boolean;
205
- context: "property" | "type";
206
- }): Code;
207
210
  /**
208
211
  * An expression that converts a value of this type to a JSON-LD compatible value. It can assume the presence
209
212
  * of the correct JSON-LD context.
@@ -12,6 +12,7 @@ import { code, literalOf } from "./ts-poet-wrapper.js";
12
12
  * Abstract base class all types.
13
13
  */
14
14
  export class AbstractType {
15
+ logger;
15
16
  /**
16
17
  * Comment from rdfs:comment.
17
18
  */
@@ -20,9 +21,10 @@ export class AbstractType {
20
21
  * Label from rdfs:label.
21
22
  */
22
23
  label;
23
- constructor({ comment, label, }) {
24
+ constructor({ comment, label, logger, }) {
24
25
  this.comment = comment;
25
26
  this.label = label;
27
+ this.logger = logger;
26
28
  }
27
29
  /**
28
30
  * Helper to compose the result of schema along the type hierarchy.
@@ -5,13 +5,13 @@ import { type Code } from "./ts-poet-wrapper.js";
5
5
  export declare class BlankNodeType extends AbstractIdentifierType<BlankNode> {
6
6
  readonly filterFunction: Code;
7
7
  readonly filterType: Code;
8
- readonly fromStringFunction: Code;
8
+ readonly parseFunction: Code;
9
9
  readonly kind = "BlankNodeType";
10
10
  readonly name: Code;
11
11
  readonly nodeKinds: ReadonlySet<"BlankNode">;
12
12
  readonly schemaType: Code;
13
13
  readonly valueSparqlWherePatternsFunction: Code;
14
- constructor(superParameters: Pick<ConstructorParameters<typeof AbstractIdentifierType<BlankNode>>[0], "comment" | "label">);
14
+ constructor(superParameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode>>[0], "hasValues" | "in_">);
15
15
  fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
16
16
  jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
17
17
  jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
@@ -13,7 +13,7 @@ import { code } from "./ts-poet-wrapper.js";
13
13
  export class BlankNodeType extends AbstractIdentifierType {
14
14
  filterFunction = code `${snippets.filterBlankNode}`;
15
15
  filterType = code `${snippets.BlankNodeFilter}`;
16
- fromStringFunction = code `export const fromString = ${snippets.blankNodeFromString};`;
16
+ parseFunction = code `${snippets.parseBlankNode};`;
17
17
  kind = "BlankNodeType";
18
18
  name = code `${imports.BlankNode}`;
19
19
  nodeKinds = nodeKinds;
@@ -38,7 +38,7 @@ export class BooleanType extends AbstractPrimitiveType {
38
38
  return code `${imports.z}.boolean()`;
39
39
  }
40
40
  toRdfResourceValuesExpression({ variables, }) {
41
- return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
41
+ return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
42
42
  }
43
43
  fromRdfExpressionChain({ variables, }) {
44
44
  return {
@@ -114,7 +114,7 @@ export class DefaultValueType extends AbstractContainerType {
114
114
  }
115
115
  }
116
116
  get defaultValueTermExpression() {
117
- return rdfjsTermExpression(this.defaultValue);
117
+ return rdfjsTermExpression(this.defaultValue, { logger: this.logger });
118
118
  }
119
119
  fromJsonExpression(parameters) {
120
120
  return this.itemType.fromJsonExpression(parameters);
@@ -6,13 +6,13 @@ import { type Code } from "./ts-poet-wrapper.js";
6
6
  export declare class IdentifierType extends AbstractIdentifierType<BlankNode | NamedNode> {
7
7
  readonly filterFunction: Code;
8
8
  readonly filterType: Code;
9
- readonly fromStringFunction: Code;
9
+ readonly parseFunction: Code;
10
10
  readonly kind = "IdentifierType";
11
11
  readonly name: Code;
12
12
  readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
13
13
  readonly schemaType: Code;
14
14
  readonly valueSparqlWherePatternsFunction: Code;
15
- constructor(parameters: Pick<ConstructorParameters<typeof AbstractIdentifierType<BlankNode | NamedNode>>[0], "comment" | "label">);
15
+ constructor(parameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode | NamedNode>>[0], "hasValues" | "in_">);
16
16
  fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
17
17
  jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
18
18
  jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
@@ -14,7 +14,7 @@ import { arrayOf, code } from "./ts-poet-wrapper.js";
14
14
  export class IdentifierType extends AbstractIdentifierType {
15
15
  filterFunction = code `${snippets.filterIdentifier}`;
16
16
  filterType = code `${snippets.IdentifierFilter}`;
17
- fromStringFunction = code `export const fromString = ${snippets.identifierFromString};`;
17
+ parseFunction = code `${snippets.parseIdentifier};`;
18
18
  kind = "IdentifierType";
19
19
  name = code `(${imports.BlankNode} | ${imports.NamedNode})`;
20
20
  nodeKinds = nodeKinds;
@@ -9,7 +9,7 @@ export declare class IriType extends AbstractIdentifierType<NamedNode> {
9
9
  readonly nodeKinds: ReadonlySet<"IRI">;
10
10
  readonly schemaType: Code;
11
11
  readonly valueSparqlWherePatternsFunction: Code;
12
- get fromStringFunction(): Code;
12
+ get parseFunction(): Code;
13
13
  get name(): Code;
14
14
  protected get schemaObject(): {
15
15
  in: Code[] | undefined;
@@ -18,18 +18,11 @@ export class IriType extends AbstractIdentifierType {
18
18
  nodeKinds = nodeKinds;
19
19
  schemaType = code `${snippets.IriSchema}`;
20
20
  valueSparqlWherePatternsFunction = code `${snippets.iriSparqlWherePatterns}`;
21
- get fromStringFunction() {
22
- const expressions = [
23
- code `${imports.Either}.encase(() => ${imports.Resource}.Identifier.fromString({ ${imports.dataFactory}, identifier }))`,
24
- code `chain((identifier) => (identifier.termType === "NamedNode") ? ${imports.Right}(identifier) : ${imports.Left}(new Error("expected identifier to be NamedNode")))`,
25
- ];
21
+ get parseFunction() {
26
22
  if (this.in_.length > 0) {
27
- expressions.push(code `chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${imports.Right}(identifier as ${imports.NamedNode}<"${iri.value}">);`))} default: return ${imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`);
23
+ return code `(identifier: string) => ${snippets.parseIri}(identifier).chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${imports.Right}(identifier as ${this.name});`))} default: return ${imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`;
28
24
  }
29
- return code `\
30
- export function fromString(identifier: string): ${imports.Either}<Error, ${this.name}> {
31
- return ${joinCode(expressions, { on: "." })} as ${imports.Either}<Error, ${this.name}>;
32
- }`;
25
+ return code `${snippets.parseIri}`;
33
26
  }
34
27
  get name() {
35
28
  if (this.in_.length > 0) {
@@ -45,7 +38,9 @@ export function fromString(identifier: string): ${imports.Either}<Error, ${this.
45
38
  return {
46
39
  ...super.schemaObject,
47
40
  in: this.in_.length > 0
48
- ? this.in_.map(rdfjsTermExpression).concat()
41
+ ? this.in_
42
+ .map((in_) => rdfjsTermExpression(in_, { logger: this.logger }))
43
+ .concat()
49
44
  : undefined,
50
45
  };
51
46
  }
@@ -88,14 +83,14 @@ export function fromString(identifier: string): ${imports.Either}<Error, ${this.
88
83
  return {
89
84
  ...super.fromRdfExpressionChain({ variables }),
90
85
  valueTo: code `chain(values => values.chainMap(value => value.toIri(${this.in_.length > 0
91
- ? code `[${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_)), { on: ", " })}]`
86
+ ? code `[${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger })), { on: ", " })}]`
92
87
  : ""})))`,
93
88
  };
94
89
  }
95
90
  }
96
91
  __decorate([
97
92
  Memoize()
98
- ], IriType.prototype, "fromStringFunction", null);
93
+ ], IriType.prototype, "parseFunction", null);
99
94
  __decorate([
100
95
  Memoize()
101
96
  ], IriType.prototype, "name", null);
@@ -14,6 +14,7 @@ declare const Super: (abstract new ({ partialType, resolveType, runtimeClass, ..
14
14
  } & {
15
15
  comment: Maybe<string>;
16
16
  label: Maybe<string>;
17
+ logger: import("ts-log").Logger;
17
18
  }) => AbstractLazyObjectType<OptionType<AbstractLazyObjectType.ObjectTypeConstraint>, OptionType<AbstractLazyObjectType.ObjectTypeConstraint>>) & {
18
19
  readonly GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
19
20
  readonly JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
@@ -71,7 +71,7 @@ export class LazyObjectOptionType extends Super {
71
71
  return conversions;
72
72
  }
73
73
  fromJsonExpression(parameters) {
74
- return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${${imports.Resource}.Identifier.toString(identifier)} deserialized from JSON\`))) })`;
74
+ return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${identifier} deserialized from JSON\`))) })`;
75
75
  }
76
76
  fromRdfResourceValuesExpression(parameters) {
77
77
  const { variables } = parameters;
@@ -45,7 +45,7 @@ export class LazyObjectType extends AbstractLazyObjectType {
45
45
  return conversions;
46
46
  }
47
47
  fromJsonExpression(parameters) {
48
- return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${${imports.Resource}.Identifier.toString(identifier)} deserialized from JSON\`))) })`;
48
+ return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${identifier} deserialized from JSON\`))) })`;
49
49
  }
50
50
  fromRdfResourceValuesExpression(parameters) {
51
51
  const { variables } = parameters;
@@ -85,16 +85,16 @@ export class ListType extends AbstractCollectionType {
85
85
  currentSubListResource = listResource;
86
86
  } else {
87
87
  const newSubListResource = ${variables.resourceSet}.resource(${subListIdentifier});
88
- currentSubListResource!.add(${rdfjsTermExpression(rdf.rest)}, newSubListResource.identifier, ${variables.graph});
88
+ currentSubListResource!.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, newSubListResource.identifier, ${variables.graph});
89
89
  currentSubListResource = newSubListResource;
90
90
  }
91
91
 
92
- ${joinCode(this.toRdfTypes.map((rdfType) => code `currentSubListResource.add(${rdfjsTermExpression(rdf.type)}, ${imports.dataFactory}.namedNode("${rdfType.value}"), ${variables.graph})`))}
92
+ ${joinCode(this.toRdfTypes.map((rdfType) => code `currentSubListResource.add(${rdfjsTermExpression(rdf.type, { logger: this.logger })}, ${imports.dataFactory}.namedNode("${rdfType.value}"), ${variables.graph})`))}
93
93
 
94
- currentSubListResource.add(${rdfjsTermExpression(rdf.first)}, ${this.itemType.toRdfResourceValuesExpression({ variables: { graph: variables.graph, propertyPath: rdfjsTermExpression(rdf.first), resource: code `currentSubListResource`, resourceSet: variables.resourceSet, value: code `item` } })}, ${variables.graph});
94
+ currentSubListResource.add(${rdfjsTermExpression(rdf.first, { logger: this.logger })}, ${this.itemType.toRdfResourceValuesExpression({ variables: { graph: variables.graph, propertyPath: rdfjsTermExpression(rdf.first, { logger: this.logger }), resource: code `currentSubListResource`, resourceSet: variables.resourceSet, value: code `item` } })}, ${variables.graph});
95
95
 
96
96
  if (itemIndex + 1 === list.length) {
97
- currentSubListResource.add(${rdfjsTermExpression(rdf.rest)}, ${rdfjsTermExpression(rdf.nil)}, ${variables.graph});
97
+ currentSubListResource.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, ${rdfjsTermExpression(rdf.nil, { logger: this.logger })}, ${variables.graph});
98
98
  }
99
99
 
100
100
  return { currentSubListResource, listResource };
@@ -106,7 +106,7 @@ export class ListType extends AbstractCollectionType {
106
106
  currentSubListResource: ${resourceTypeName} | null;
107
107
  listResource: ${resourceTypeName};
108
108
  },
109
- ).listResource.identifier : ${rdfjsTermExpression(rdf.nil)}]`;
109
+ ).listResource.identifier : ${rdfjsTermExpression(rdf.nil, { logger: this.logger })}]`;
110
110
  }
111
111
  }
112
112
  __decorate([
@@ -125,7 +125,10 @@ export const ${syntheticNamePrefix}GraphQL = new ${imports.GraphQLUnionType}(${{
125
125
  get identifierTypeDeclarations() {
126
126
  return singleEntryRecord(`${syntheticNamePrefix}Identifier`, code `\
127
127
  export type ${syntheticNamePrefix}Identifier = ${this.#identifierType.name};
128
- export namespace ${syntheticNamePrefix}Identifier { ${joinCode([this.#identifierType.fromStringFunction, this.#identifierType.toStringFunction])} }`);
128
+ export namespace ${syntheticNamePrefix}Identifier {
129
+ export const parse = ${this.#identifierType.parseFunction};
130
+ export const stringify = ${this.#identifierType.stringifyFunction};
131
+ }`);
129
132
  }
130
133
  get isTypeFunctionDeclaration() {
131
134
  if (this._name === `${syntheticNamePrefix}Object`) {
@@ -40,7 +40,7 @@ export class SetType extends AbstractCollectionType {
40
40
  chain.push(code `map(values => values.toArray()${this._mutable ? ".concat()" : ""})`);
41
41
  }
42
42
  else {
43
- chain.push(code `chain(values => ${imports.NonEmptyList}.fromArray(values.toArray()).toEither(new Error(\`\${${imports.Resource}.Identifier.toString(${variables.resource}.identifier)} is an empty set\`)))`);
43
+ chain.push(code `chain(values => ${imports.NonEmptyList}.fromArray(values.toArray()).toEither(new Error(\`\${${variables.resource}.identifier} is an empty set\`)))`);
44
44
  }
45
45
  chain.push(code `map(valuesArray => ${imports.Resource}.Values.fromValue({ focusResource: ${variables.resource}, propertyPath: ${variables.propertyPath}, value: valuesArray }))`);
46
46
  return joinCode(chain, { on: "." });
@@ -48,7 +48,7 @@ export class StringType extends AbstractPrimitiveType {
48
48
  }
49
49
  }
50
50
  toRdfResourceValuesExpression({ variables, }) {
51
- return code `[${snippets.literalFactory}.string(${variables.value}${!this.datatype.equals(xsd.string) ? `, ${rdfjsTermExpression(this.datatype)}` : ""})]`;
51
+ return code `[${snippets.literalFactory}.string(${variables.value}${!this.datatype.equals(xsd.string) ? `, ${rdfjsTermExpression(this.datatype, { logger: this.logger })}` : ""})]`;
52
52
  }
53
53
  fromRdfExpressionChain({ variables, }) {
54
54
  return {
@@ -49,7 +49,9 @@ export class TermType extends AbstractTermType {
49
49
  get schemaObject() {
50
50
  return {
51
51
  ...super.schemaObject,
52
- in: this.in_.length > 0 ? this.in_.map(rdfjsTermExpression) : undefined,
52
+ in: this.in_.length > 0
53
+ ? this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger }))
54
+ : undefined,
53
55
  };
54
56
  }
55
57
  fromJsonExpression({ variables, }) {
@@ -1,7 +1,12 @@
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 TsGenerator implements Generator {
5
+ private readonly logger;
4
6
  private readonly typeFactory;
7
+ constructor({ logger }: {
8
+ logger: Logger;
9
+ });
5
10
  generate(ast_: ast.Ast): string;
6
11
  }
7
12
  //# sourceMappingURL=TsGenerator.d.ts.map