@shaclmate/compiler 4.0.19 → 4.0.21

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 (105) 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/AbstractContainerType.d.ts +1 -0
  27. package/dist/generators/ts/AbstractContainerType.js +3 -0
  28. package/dist/generators/ts/AbstractDateType.js +1 -1
  29. package/dist/generators/ts/AbstractIdentifierType.d.ts +2 -2
  30. package/dist/generators/ts/AbstractIdentifierType.js +2 -5
  31. package/dist/generators/ts/AbstractLazyObjectType.d.ts +2 -1
  32. package/dist/generators/ts/AbstractLazyObjectType.js +6 -3
  33. package/dist/generators/ts/AbstractNamedUnionType.js +2 -2
  34. package/dist/generators/ts/AbstractNumericType.js +1 -1
  35. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  36. package/dist/generators/ts/AbstractTermType.js +8 -2
  37. package/dist/generators/ts/AbstractType.d.ts +21 -14
  38. package/dist/generators/ts/AbstractType.js +3 -1
  39. package/dist/generators/ts/AbstractUnionType.d.ts +5 -4
  40. package/dist/generators/ts/AbstractUnionType.js +83 -59
  41. package/dist/generators/ts/BlankNodeType.d.ts +2 -2
  42. package/dist/generators/ts/BlankNodeType.js +1 -1
  43. package/dist/generators/ts/BooleanType.js +1 -1
  44. package/dist/generators/ts/DefaultValueType.js +1 -1
  45. package/dist/generators/ts/IdentifierType.d.ts +2 -2
  46. package/dist/generators/ts/IdentifierType.js +1 -1
  47. package/dist/generators/ts/IriType.d.ts +1 -1
  48. package/dist/generators/ts/IriType.js +8 -13
  49. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
  50. package/dist/generators/ts/LazyObjectOptionType.js +1 -1
  51. package/dist/generators/ts/LazyObjectType.js +1 -1
  52. package/dist/generators/ts/ListType.js +5 -5
  53. package/dist/generators/ts/NamedObjectType.d.ts +1 -0
  54. package/dist/generators/ts/NamedObjectType.js +7 -0
  55. package/dist/generators/ts/NamedObjectUnionType.js +4 -1
  56. package/dist/generators/ts/SetType.js +1 -1
  57. package/dist/generators/ts/StringType.js +1 -1
  58. package/dist/generators/ts/TermType.js +3 -1
  59. package/dist/generators/ts/TsGenerator.d.ts +5 -0
  60. package/dist/generators/ts/TsGenerator.js +7 -1
  61. package/dist/generators/ts/TypeFactory.d.ts +5 -0
  62. package/dist/generators/ts/TypeFactory.js +35 -5
  63. package/dist/generators/ts/ZodGenerator.d.ts +4 -0
  64. package/dist/generators/ts/ZodGenerator.js +4 -1
  65. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +4 -1
  66. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +3 -1
  67. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -5
  68. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +2 -2
  69. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +2 -2
  70. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
  71. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
  72. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +1 -1
  73. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -0
  74. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +16 -16
  75. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +6 -2
  76. package/dist/generators/ts/_snippets/parseIri.d.ts +2 -0
  77. package/dist/generators/ts/_snippets/parseIri.js +12 -0
  78. package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.js +4 -3
  79. package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +7 -5
  80. package/dist/generators/ts/_snippets/snippets_parseBlankNode.d.ts +2 -0
  81. package/dist/generators/ts/_snippets/snippets_parseBlankNode.js +12 -0
  82. package/dist/generators/ts/_snippets/snippets_parseIdentifier.d.ts +2 -0
  83. package/dist/generators/ts/_snippets/snippets_parseIdentifier.js +6 -0
  84. package/dist/generators/ts/graphqlSchemaVariableStatement.js +3 -3
  85. package/dist/generators/ts/imports.d.ts +2 -0
  86. package/dist/generators/ts/imports.js +3 -1
  87. package/dist/generators/ts/rdfjsTermExpression.d.ts +4 -1
  88. package/dist/generators/ts/rdfjsTermExpression.js +2 -3
  89. package/dist/generators/ts/snippets.d.ts +3 -2
  90. package/dist/generators/ts/snippets.js +6 -4
  91. package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -0
  92. package/dist/generators/ts/synthesizeUberObjectUnionType.js +4 -0
  93. package/dist/input/ShapesGraph.d.ts +4 -1
  94. package/dist/input/ShapesGraph.js +3 -2
  95. package/dist/input/generated.d.ts +323 -323
  96. package/dist/input/generated.js +19 -20
  97. package/package.json +6 -7
  98. package/dist/ast/termToJson.d.ts +0 -18
  99. package/dist/ast/termToJson.js +0 -18
  100. package/dist/generators/ts/_snippets/snippets_blankNodeFromString.d.ts +0 -2
  101. package/dist/generators/ts/_snippets/snippets_blankNodeFromString.js +0 -11
  102. package/dist/generators/ts/_snippets/snippets_identifierFromString.d.ts +0 -2
  103. package/dist/generators/ts/_snippets/snippets_identifierFromString.js +0 -8
  104. package/dist/logger.d.ts +0 -2
  105. 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
@@ -38,6 +38,7 @@ export declare abstract class AbstractContainerType<ItemTypeT extends AbstractCo
38
38
  } & ConstructorParameters<typeof AbstractType>[0]);
39
39
  get recursive(): boolean;
40
40
  get schema(): Code;
41
+ get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
41
42
  protected get schemaObject(): {
42
43
  item: Code;
43
44
  kind: Code;
@@ -31,6 +31,9 @@ export class AbstractContainerType extends AbstractType {
31
31
  get schema() {
32
32
  return code `${removeUndefined(this.schemaObject)}`;
33
33
  }
34
+ get toRdfResourceValueTypes() {
35
+ return this.itemType.toRdfResourceValueTypes;
36
+ }
34
37
  get schemaObject() {
35
38
  return {
36
39
  ...super.schemaObject,
@@ -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([
@@ -32,6 +32,7 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
32
32
  get recursive(): boolean;
33
33
  get schema(): Code;
34
34
  get schemaType(): Code;
35
+ get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
35
36
  get valueSparqlConstructTriplesFunction(): Code;
36
37
  get valueSparqlWherePatternsFunction(): Code;
37
38
  protected get schemaObject(): {
@@ -39,9 +40,9 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
39
40
  kind: Code;
40
41
  };
41
42
  hashStatements({ depth, variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
43
+ jsonSchema(parameters: Parameters<AbstractType["jsonSchema"]>[0]): Code;
42
44
  jsonType(parameters?: Parameters<AbstractType["jsonType"]>[0]): AbstractType.JsonType;
43
45
  jsonUiSchemaElement(parameters: Parameters<AbstractType["jsonUiSchemaElement"]>[0]): Maybe<Code>;
44
- jsonSchema(parameters: Parameters<AbstractType["jsonSchema"]>[0]): Code;
45
46
  toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
46
47
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
47
48
  protected resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType, partialNamedObjectUnionType, variables, }: {
@@ -63,6 +63,9 @@ export class AbstractLazyObjectType extends AbstractType {
63
63
  resolveType: this.resolveType.schemaType,
64
64
  }}`;
65
65
  }
66
+ get toRdfResourceValueTypes() {
67
+ return this.partialType.toRdfResourceValueTypes;
68
+ }
66
69
  get valueSparqlConstructTriplesFunction() {
67
70
  return code `(({ schema, ...otherParameters }) => ${this.partialType.valueSparqlConstructTriplesFunction}({ ...otherParameters, schema: schema.partial() }))`;
68
71
  }
@@ -86,15 +89,15 @@ export class AbstractLazyObjectType extends AbstractType {
86
89
  },
87
90
  });
88
91
  }
92
+ jsonSchema(parameters) {
93
+ return this.partialType.jsonSchema(parameters);
94
+ }
89
95
  jsonType(parameters) {
90
96
  return this.partialType.jsonType(parameters);
91
97
  }
92
98
  jsonUiSchemaElement(parameters) {
93
99
  return this.partialType.jsonUiSchemaElement(parameters);
94
100
  }
95
- jsonSchema(parameters) {
96
- return this.partialType.jsonSchema(parameters);
97
- }
98
101
  toJsonExpression({ variables, }) {
99
102
  return this.partialType.toJsonExpression({
100
103
  variables: {
@@ -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);
@@ -107,7 +107,7 @@ export namespace ${syntheticNamePrefix}Json {
107
107
  staticModuleDeclarations[`${syntheticNamePrefix}fromRdfResourceValues`] =
108
108
  code `export const ${syntheticNamePrefix}fromRdfResourceValues: ${snippets.FromRdfResourceValuesFunction}<${this.name}> = ${this.inlineFromRdfResourceValuesFunction};`;
109
109
  staticModuleDeclarations[`${syntheticNamePrefix}toRdfResourceValues`] =
110
- code `export const ${syntheticNamePrefix}toRdfResourceValues: ${snippets.ToRdfResourceValuesFunction}<${this.name}> = ${this.inlineToRdfResourceValuesFunction};`;
110
+ code `export const ${syntheticNamePrefix}toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
111
111
  }
112
112
  if (this.features.has("sparql")) {
113
113
  staticModuleDeclarations[`${syntheticNamePrefix}valueSparqlConstructTriples`] =
@@ -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 {
@@ -32,6 +32,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
32
32
  get discriminantProperty(): Maybe<AbstractType.DiscriminantProperty>;
33
33
  get schema(): Code;
34
34
  get termTypes(): ReadonlySet<"BlankNode" | "Literal" | "NamedNode">;
35
+ get toRdfResourceValueTypes(): Set<"BlankNode" | "Literal" | "NamedNode">;
35
36
  get valueSparqlConstructTriplesFunction(): Code;
36
37
  fromRdfResourceValuesExpression(parameters: Parameters<AbstractType["fromRdfResourceValuesExpression"]>[0]): Code;
37
38
  hashStatements({ variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
@@ -93,6 +93,9 @@ export class AbstractTermType extends AbstractType {
93
93
  get termTypes() {
94
94
  return new Set([...this.nodeKinds].map(NodeKind.toTermType));
95
95
  }
96
+ get toRdfResourceValueTypes() {
97
+ return new Set([...this.nodeKinds].map(NodeKind.toTermType));
98
+ }
96
99
  get valueSparqlConstructTriplesFunction() {
97
100
  return code `((_: object) => [])`;
98
101
  }
@@ -136,7 +139,7 @@ export class AbstractTermType extends AbstractType {
136
139
  fromRdfExpressionChain({ variables, }) {
137
140
  let valueToExpression;
138
141
  if (this.in_.length > 0) {
139
- valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_)), { on: ", " })}])`;
142
+ valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger })), { on: ", " })}])`;
140
143
  }
141
144
  else if (this.nodeKinds.size < 3) {
142
145
  const eitherTypeParameters = code `<Error, ${this.name}>`;
@@ -152,7 +155,7 @@ export class AbstractTermType extends AbstractType {
152
155
  return {
153
156
  hasValues: this.hasValues.length > 0
154
157
  ? code `\
155
- chain(values => ${imports.Either}.sequence([${joinCode(this.hasValues.map(rdfjsTermExpression), { on: ", " })}].map(hasValue => values.find(value => value.term.equals(hasValue)))).map(() => values))`
158
+ 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
159
  : undefined,
157
160
  valueTo: code `chain(values => values.chainMap(value => ${valueToExpression}))`,
158
161
  };
@@ -170,6 +173,9 @@ __decorate([
170
173
  __decorate([
171
174
  Memoize()
172
175
  ], AbstractTermType.prototype, "termTypes", null);
176
+ __decorate([
177
+ Memoize()
178
+ ], AbstractTermType.prototype, "toRdfResourceValueTypes", null);
173
179
  __decorate([
174
180
  Memoize()
175
181
  ], AbstractTermType.prototype, "valueSparqlConstructTriplesFunction", null);
@@ -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.
@@ -214,6 +217,10 @@ export declare abstract class AbstractType {
214
217
  value: Code;
215
218
  };
216
219
  }): Code;
220
+ /**
221
+ * The type(s) of the array elements produced by the toRdfResourceValuesExpression.
222
+ */
223
+ abstract readonly toRdfResourceValueTypes: ReadonlySet<"BlankNode" | "NamedNode" | "Literal">;
217
224
  /**
218
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
219
226
  * resource.add(predicate, convertedValue, graph)
@@ -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.
@@ -10,7 +10,6 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
10
10
  private readonly discriminant;
11
11
  private readonly identifierType;
12
12
  readonly abstract = false;
13
- private readonly lazyMembers;
14
13
  readonly recursive: boolean;
15
14
  constructor({ identifierType, members, recursive, ...superParameters }: {
16
15
  identifierType: Maybe<BlankNodeType | IdentifierType | IriType>;
@@ -25,6 +24,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
25
24
  get mutable(): boolean;
26
25
  get schema(): Code;
27
26
  get schemaType(): Code;
27
+ get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
28
28
  get typeofs(): AbstractType["typeofs"];
29
29
  protected get concreteMembers(): readonly AbstractUnionType.ConcreteMember<MemberTypeT>[];
30
30
  protected get inlineEqualsFunction(): Code;
@@ -32,19 +32,20 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
32
32
  protected get inlineFilterType(): Code;
33
33
  protected get inlineFromJsonFunction(): Code;
34
34
  protected get inlineFromRdfResourceValuesFunction(): Code;
35
- protected get inlineJsonType(): AbstractType.JsonType;
36
35
  protected get inlineJsonSchema(): Code;
36
+ protected get inlineJsonType(): AbstractType.JsonType;
37
37
  protected get inlineName(): Code;
38
- protected get inlineValueSparqlConstructTriplesFunction(): Code;
39
- protected get inlineValueSparqlWherePatternsFunction(): Code;
40
38
  protected get inlineToJsonFunction(): Code;
41
39
  protected get inlineToRdfResourceValuesFunction(): Code;
40
+ protected get inlineValueSparqlConstructTriplesFunction(): Code;
41
+ protected get inlineValueSparqlWherePatternsFunction(): Code;
42
42
  protected get schemaObject(): {
43
43
  kind: Code;
44
44
  members: Code;
45
45
  };
46
46
  jsonUiSchemaElement(): Maybe<Code>;
47
47
  protected inlineHashStatements({ depth, variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
48
+ private readonly lazyMembers;
48
49
  }
49
50
  type Discriminant = ExtrinsicDiscriminant | HybridDiscriminant | IntrinsicDiscriminant | TypeofDiscriminant;
50
51
  type ExtrinsicDiscriminant = {