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