@shaclmate/compiler 4.0.40 → 4.0.41

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 (114) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +0 -8
  2. package/dist/ShapesGraphToAstTransformer.js +5 -85
  3. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
  4. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
  5. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
  6. package/dist/ast/AbstractCompoundType.d.ts +2 -1
  7. package/dist/ast/AbstractCompoundType.js +1 -1
  8. package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
  9. package/dist/ast/Ast.d.ts +1 -3
  10. package/dist/ast/ListType.d.ts +1 -1
  11. package/dist/ast/ListType.js +1 -1
  12. package/dist/ast/ObjectType.d.ts +0 -12
  13. package/dist/ast/ObjectType.js +0 -78
  14. package/dist/generators/AstJsonGenerator.js +7 -3
  15. package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
  16. package/dist/generators/ts/AbstractCollectionType.d.ts +4 -11
  17. package/dist/generators/ts/AbstractCollectionType.js +3 -62
  18. package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
  19. package/dist/generators/ts/AbstractContainerType.js +1 -4
  20. package/dist/generators/ts/AbstractDateType.d.ts +4 -1
  21. package/dist/generators/ts/AbstractDateType.js +6 -1
  22. package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
  23. package/dist/generators/ts/AbstractIdentifierType.js +3 -0
  24. package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -1
  25. package/dist/generators/ts/AbstractLazyObjectType.js +12 -1
  26. package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
  27. package/dist/generators/ts/AbstractNumericType.js +7 -7
  28. package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
  29. package/dist/generators/ts/AbstractTermType.d.ts +1 -2
  30. package/dist/generators/ts/AbstractTermType.js +1 -3
  31. package/dist/generators/ts/AbstractType.d.ts +46 -16
  32. package/dist/generators/ts/AbstractType.js +31 -16
  33. package/dist/generators/ts/BigDecimalType.d.ts +4 -0
  34. package/dist/generators/ts/BigDecimalType.js +4 -1
  35. package/dist/generators/ts/BigIntType.d.ts +3 -1
  36. package/dist/generators/ts/BigIntType.js +1 -1
  37. package/dist/generators/ts/BlankNodeType.d.ts +1 -1
  38. package/dist/generators/ts/BlankNodeType.js +3 -3
  39. package/dist/generators/ts/BooleanType.d.ts +3 -1
  40. package/dist/generators/ts/BooleanType.js +1 -1
  41. package/dist/generators/ts/DefaultValueType.d.ts +39 -1
  42. package/dist/generators/ts/DefaultValueType.js +6 -3
  43. package/dist/generators/ts/FloatType.d.ts +3 -1
  44. package/dist/generators/ts/FloatType.js +1 -1
  45. package/dist/generators/ts/GraphqlSchema.js +2 -2
  46. package/dist/generators/ts/IdentifierType.d.ts +1 -1
  47. package/dist/generators/ts/IdentifierType.js +7 -5
  48. package/dist/generators/ts/IntType.d.ts +3 -1
  49. package/dist/generators/ts/IntType.js +1 -1
  50. package/dist/generators/ts/IriType.js +4 -2
  51. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
  52. package/dist/generators/ts/LazyObjectOptionType.js +8 -4
  53. package/dist/generators/ts/LazyObjectSetType.js +9 -3
  54. package/dist/generators/ts/LazyObjectType.js +5 -2
  55. package/dist/generators/ts/ListType.d.ts +10 -1
  56. package/dist/generators/ts/ListType.js +45 -8
  57. package/dist/generators/ts/LiteralType.d.ts +4 -0
  58. package/dist/generators/ts/LiteralType.js +6 -3
  59. package/dist/generators/ts/ObjectType.d.ts +8 -22
  60. package/dist/generators/ts/ObjectType.js +6 -74
  61. package/dist/generators/ts/ObjectUnionType.js +2 -2
  62. package/dist/generators/ts/OptionType.d.ts +5 -1
  63. package/dist/generators/ts/OptionType.js +10 -5
  64. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +1 -4
  65. package/dist/generators/ts/SetType.d.ts +16 -1
  66. package/dist/generators/ts/SetType.js +80 -2
  67. package/dist/generators/ts/Snippets.d.ts +3 -1
  68. package/dist/generators/ts/Snippets.js +18 -4
  69. package/dist/generators/ts/StringType.d.ts +3 -1
  70. package/dist/generators/ts/StringType.js +5 -1
  71. package/dist/generators/ts/TermType.d.ts +4 -0
  72. package/dist/generators/ts/TermType.js +3 -0
  73. package/dist/generators/ts/TsGenerator.d.ts +1 -1
  74. package/dist/generators/ts/TsGenerator.js +53 -28
  75. package/dist/generators/ts/TypeFactory.js +12 -25
  76. package/dist/generators/ts/UnionType.d.ts +3 -6
  77. package/dist/generators/ts/UnionType.js +42 -55
  78. package/dist/generators/ts/ZodGenerator.d.ts +1 -1
  79. package/dist/generators/ts/ZodGenerator.js +19 -12
  80. package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +6 -3
  81. package/dist/generators/ts/_ObjectType/DiscriminantProperty.d.ts +8 -12
  82. package/dist/generators/ts/_ObjectType/DiscriminantProperty.js +18 -35
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +5 -5
  84. package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +9 -30
  85. package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.js +0 -4
  86. package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.js +0 -3
  87. package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.js +0 -3
  88. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +0 -4
  89. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js +3 -22
  90. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +4 -29
  91. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +10 -39
  92. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.js +25 -29
  93. package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +1 -5
  94. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +11 -8
  95. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +3 -9
  96. package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +1 -8
  97. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +1 -3
  98. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +2 -4
  99. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +10 -31
  100. package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js +1 -1
  101. package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.js +2 -9
  102. package/dist/generators/ts/_ObjectType/ShaclProperty.js +6 -6
  103. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +0 -11
  104. package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
  105. package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
  106. package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
  107. package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
  108. package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
  109. package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
  110. package/dist/input/generated.d.ts +756 -115
  111. package/dist/input/generated.js +634 -126
  112. package/package.json +2 -4
  113. package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
  114. package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
@@ -15,30 +15,11 @@ export function ObjectType_focusSparqlWherePatternsFunctionDeclaration() {
15
15
  const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
16
16
  let patternsVariableDeclarationKeyword = "const";
17
17
  const statements = [];
18
- for (const parentObjectType of this.parentObjectTypes) {
19
- statements.push(code `\
20
- patterns = patterns.concat(${parentObjectType.alias.unsafeCoerce()}.focusSparqlWherePatterns(${{ filter: variables.filter, focusIdentifier: variables.focusIdentifier, ignoreRdfType: true, preferredLanguages: variables.preferredLanguages, variablePrefix: variables.variablePrefix }}));`);
21
- patternsVariableDeclarationKeyword = "let";
22
- }
23
- if (this.fromRdfType.isJust()) {
24
- const fromRdfTypeVariables = this.fromRdfTypeVariable
25
- .toList()
26
- .concat(this.descendantFromRdfTypeVariables);
18
+ this.fromRdfTypeVariable.ifJust((fromRdfTypeVariable) => {
27
19
  statements.push(code `const rdfTypeVariable = ${rdfTypeVariable};`, code `\
28
20
  if (!parameters?.ignoreRdfType) {
29
21
  patterns.push(
30
- ${fromRdfTypeVariables.length > 1
31
- ? code `\
32
- {
33
- type: "values" as const,
34
- values: [${joinCode(fromRdfTypeVariables, { on: "," })}].map((identifier) => {
35
- const valuePatternRow: ${this.reusables.imports.sparqljs}.ValuePatternRow = {};
36
- valuePatternRow[\`?\${${variables.variablePrefix}}FromRdfType\`] = identifier as ${this.reusables.imports.NamedNode};
37
- return valuePatternRow;
38
- }),
39
- },
40
- ${this.reusables.snippets.sparqlInstancesOfPattern}({ rdfType: ${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}FromRdfType\`), subject: ${variables.focusIdentifier} }),`
41
- : code `${this.reusables.snippets.sparqlInstancesOfPattern}({ rdfType: ${fromRdfTypeVariables[0]}, subject: ${variables.focusIdentifier} }),`}
22
+ ${code `${this.reusables.snippets.sparqlInstancesOfPattern}({ rdfType: ${fromRdfTypeVariable}, subject: ${variables.focusIdentifier} }),`}
42
23
  {
43
24
  triples: [
44
25
  {
@@ -70,7 +51,7 @@ if (!parameters?.ignoreRdfType) {
70
51
  }
71
52
  );
72
53
  }`);
73
- }
54
+ });
74
55
  for (const property of this.properties) {
75
56
  if (property.recursive) {
76
57
  continue;
@@ -1,4 +1,5 @@
1
1
  import { Maybe } from "purify-ts";
2
+ import { invariant } from "ts-invariant";
2
3
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
4
  export function ObjectType_fromJsonFunctionDeclaration() {
4
5
  if (!this.configuration.features.has("Object.fromJson")) {
@@ -7,37 +8,11 @@ export function ObjectType_fromJsonFunctionDeclaration() {
7
8
  const variables = {
8
9
  jsonObject: code `${this.configuration.syntheticNamePrefix}json`,
9
10
  };
10
- const chains = [];
11
- this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
12
- chains.push({
13
- expression: code `${parentObjectType.alias.unsafeCoerce()}.fromJson(${variables.jsonObject})`,
14
- variable: `super${parentObjectTypeI}`,
15
- });
16
- });
17
11
  const propertyInitializers = this.properties.flatMap((property) => property.fromJsonInitializer({ variables }).toList());
18
- if (propertyInitializers.length > 0) {
19
- chains.push({
20
- expression: code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyInitializers, { on: "," })} })`,
21
- variable: "properties",
22
- });
23
- }
24
- let returnExpression;
25
- switch (chains.length) {
26
- case 0:
27
- returnExpression = code `create({})`;
28
- break;
29
- case 1:
30
- returnExpression = code `(${chains[0].expression}).chain(create)`;
31
- break;
32
- default:
33
- returnExpression = code `${chains
34
- .reverse()
35
- .reduce((acc, { expression, variable }) => code `(${expression}).chain(${variable} => ${acc})`, code `(create({ ${chains.map((chain) => `...${chain.variable}`).join(", ")} }))`)}`;
36
- break;
37
- }
12
+ invariant(propertyInitializers.length > 0);
38
13
  return Maybe.of(code `\
39
- export function fromJson(${variables.jsonObject}: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.expression}> {
40
- return ${returnExpression};
14
+ export function fromJson(${variables.jsonObject}: ${this.jsonType().expression}): ${this.reusables.imports.Either}<Error, ${this.expression}> {
15
+ return ${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyInitializers, { on: "," })} }).chain(create);
41
16
  }`);
42
17
  }
43
18
  //# sourceMappingURL=ObjectType_fromJsonFunctionDeclaration.js.map
@@ -1,4 +1,5 @@
1
1
  import { Maybe } from "purify-ts";
2
+ import { invariant } from "ts-invariant";
2
3
  import { arrayOf, code, joinCode } from "../ts-poet-wrapper.js";
3
4
  export function ObjectType_fromRdfResourceFunctionDeclaration() {
4
5
  if (!this.configuration.features.has("Object.fromRdf")) {
@@ -22,17 +23,9 @@ export function ObjectType_fromRdfResourceFunctionDeclaration() {
22
23
  resource: variables.resource,
23
24
  };
24
25
  const chains = [];
25
- const partials = [];
26
- this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
27
- chains.push({
28
- expression: code `${parentObjectType.alias.unsafeCoerce()}._fromRdfResource(${variables.resource}, { ...${optionsVariable}, ignoreRdfType: true })`,
29
- variable: `super${parentObjectTypeI}`,
30
- });
31
- partials.push(`super${parentObjectTypeI}`);
32
- });
33
26
  this.fromRdfTypeVariable.ifJust((fromRdfTypeVariable) => {
34
27
  chains.push({
35
- expression: code `!${variables.ignoreRdfType} ? ${this.reusables.snippets.ensureRdfResourceType}(${variables.resource}, ${arrayOf(fromRdfTypeVariable, ...this.descendantFromRdfTypeVariables)}, ${{ graph: variables.graph }}) : ${this.reusables.imports.Right}(true as const)`,
28
+ expression: code `!${variables.ignoreRdfType} ? ${this.reusables.snippets.ensureRdfResourceType}(${variables.resource}, ${arrayOf(fromRdfTypeVariable)}, ${{ graph: variables.graph }}) : ${this.reusables.imports.Right}(true as const)`,
36
29
  variable: `_rdfTypeCheck`,
37
30
  });
38
31
  });
@@ -41,38 +34,16 @@ export function ObjectType_fromRdfResourceFunctionDeclaration() {
41
34
  variables: propertyFromRdfResourceValuesExpressionVariable,
42
35
  })
43
36
  .toList());
44
- if (Object.keys(propertyFromRdfResourceValuesInitializers).length > 0) {
45
- chains.push({
46
- expression: code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyFromRdfResourceValuesInitializers, { on: ", " })} })`,
47
- variable: "properties",
48
- });
49
- partials.push("properties");
50
- }
51
- let partialsJoined;
52
- switch (partials.length) {
53
- case 0:
54
- partialsJoined = code `{}`;
55
- break;
56
- case 1:
57
- partialsJoined = code `${partials[0]}`;
58
- break;
59
- default:
60
- partialsJoined = code `{ ${partials.map((partial) => `...${partial}`).join(", ")} }`;
61
- break;
62
- }
63
- let returnExpression;
64
- const resultExpression = code `create(${partialsJoined})`;
65
- if (chains.length === 0) {
66
- returnExpression = code `${this.reusables.imports.Right}(${resultExpression})`;
67
- }
68
- else {
69
- returnExpression = code `${chains
70
- .reverse()
71
- .reduce((acc, { expression, variable }) => code `(${expression}).chain(${variable} => ${acc})`, code `(${resultExpression})`)}`;
72
- }
37
+ invariant(Object.keys(propertyFromRdfResourceValuesInitializers).length > 0);
38
+ chains.push({
39
+ expression: code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyFromRdfResourceValuesInitializers, { on: ", " })} })`,
40
+ variable: "properties",
41
+ });
73
42
  return Maybe.of(code `\
74
43
  export const _fromRdfResource: ${this.reusables.snippets._FromRdfResourceFunction}<${this.expression}> = (${variables.resource}, ${optionsVariable}) => {
75
- return ${returnExpression};
44
+ return ${chains
45
+ .reverse()
46
+ .reduce((acc, { expression, variable }) => code `(${expression}).chain(${variable} => ${acc})`, code `(create(properties))`)};
76
47
  }
77
48
 
78
49
  export const fromRdfResource = ${this.reusables.snippets.wrap_FromRdfResourceFunction}(_fromRdfResource);`);
@@ -4,41 +4,37 @@ export function ObjectType_hashFunctionDeclarations() {
4
4
  if (!this.configuration.features.has("Object.hash")) {
5
5
  return [];
6
6
  }
7
- const hashOwnShaclPropertiesStatements = this.properties.flatMap((property) => property.kind === "Shacl"
8
- ? property.hashStatements({
9
- variables: {
10
- hasher: hasherVariable,
11
- value: property.accessExpression({
12
- variables: { object: this.thisVariable },
13
- }),
14
- },
15
- })
16
- : []);
17
- const hashShaclPropertiesStatements = [];
18
- const hashStatements = [];
19
- for (const parentObjectType of this.parentObjectTypes) {
20
- hashShaclPropertiesStatements.push(code `${parentObjectType.alias.unsafeCoerce()}.hashShaclProperties(${hasherVariable}, ${this.thisVariable});`);
21
- }
22
- hashStatements.push(code `${this.alias.unsafeCoerce()}.hashShaclProperties(${hasherVariable}, ${this.thisVariable});`);
23
- hashShaclPropertiesStatements.push(...hashOwnShaclPropertiesStatements);
24
- hashShaclPropertiesStatements.push(code `return ${hasherVariable};`);
25
- hashStatements.push(...this.properties
26
- .filter((property) => property.kind !== "Shacl")
27
- .flatMap((property) => property.hashStatements({
28
- variables: {
29
- hasher: hasherVariable,
30
- value: code `${property.accessExpression({ variables: { object: this.thisVariable } })}`,
31
- },
32
- })));
33
- hashStatements.push(code `return ${hasherVariable};`);
34
7
  return [
35
8
  code `\
36
9
  export function hash<HasherT extends ${this.reusables.snippets.Hasher}>(${hasherVariable}: HasherT, ${this.thisVariable}: ${this.expression}): HasherT {
37
- ${joinCode(hashStatements)}
10
+ ${joinCode([
11
+ code `${this.alias.unsafeCoerce()}.hashShaclProperties(${hasherVariable}, ${this.thisVariable});`,
12
+ ...this.properties
13
+ .filter((property) => property.kind !== "Shacl")
14
+ .flatMap((property) => property.hashStatements({
15
+ variables: {
16
+ hasher: hasherVariable,
17
+ value: code `${property.accessExpression({ variables: { object: this.thisVariable } })}`,
18
+ },
19
+ })),
20
+ code `return ${hasherVariable};`,
21
+ ])}
38
22
  }`,
39
23
  code `\
40
24
  export function hashShaclProperties<HasherT extends ${this.reusables.snippets.Hasher}>(${hasherVariable}: HasherT, ${this.thisVariable}: ${this.expression}): HasherT {
41
- ${joinCode(hashShaclPropertiesStatements)}
25
+ ${joinCode([
26
+ ...this.properties.flatMap((property) => property.kind === "Shacl"
27
+ ? property.hashStatements({
28
+ variables: {
29
+ hasher: hasherVariable,
30
+ value: property.accessExpression({
31
+ variables: { object: this.thisVariable },
32
+ }),
33
+ },
34
+ })
35
+ : []),
36
+ code `return ${hasherVariable};`,
37
+ ])}
42
38
  }`,
43
39
  ];
44
40
  }
@@ -5,11 +5,7 @@ export function ObjectType_interfaceDeclaration() {
5
5
  ${this.comment
6
6
  .alt(this.label)
7
7
  .map(tsComment)
8
- .orDefault("")}export interface ${this.alias.unsafeCoerce()}${this.parentObjectTypes.length > 0
9
- ? ` extends ${this.parentObjectTypes
10
- .map((parentObjectType) => parentObjectType.alias.unsafeCoerce())
11
- .join(", ")}`
12
- : ""} {
8
+ .orDefault("")}export interface ${this.alias.unsafeCoerce()} {
13
9
  ${joinCode(this.properties.map((property) => property.declaration), { on: "\n\n" })}
14
10
  }`;
15
11
  }
@@ -1,17 +1,20 @@
1
1
  import { Maybe } from "purify-ts";
2
- import { code } from "../ts-poet-wrapper.js";
2
+ import { code, literalOf } from "../ts-poet-wrapper.js";
3
3
  export function ObjectType_isTypeFunctionDeclaration() {
4
4
  if (!this.configuration.features.has("Object.type")) {
5
5
  return Maybe.empty();
6
6
  }
7
+ if (this.synthetic) {
8
+ return Maybe.empty();
9
+ }
10
+ const alias = this.alias.extract();
11
+ const discriminantProperty = this.discriminantProperty.extract();
12
+ if (!alias || !discriminantProperty) {
13
+ return Maybe.empty();
14
+ }
7
15
  return Maybe.of(code `\
8
- export function is${this.alias.unsafeCoerce()}(object: ${this.configuration.syntheticNamePrefix}Object): object is ${this.alias.unsafeCoerce()} {
9
- switch (object.${this._discriminantProperty.name}) {
10
- ${this._discriminantProperty.type.descendantValues
11
- .concat(this._discriminantProperty.type.ownValues)
12
- .map((value) => `case "${value}":`)
13
- .join("\n")} return true; default: return false;
14
- }
16
+ export function is${alias}(object: ${this.configuration.syntheticNamePrefix}Object): object is ${alias} {
17
+ return object.${discriminantProperty.name} === ${literalOf(discriminantProperty.value)};
15
18
  }`);
16
19
  }
17
20
  //# sourceMappingURL=ObjectType_isTypeFunctionDeclaration.js.map
@@ -4,15 +4,9 @@ export function ObjectType_jsonSchemaFunctionDeclaration() {
4
4
  if (!this.configuration.features.has("Object.JSON.schema")) {
5
5
  return Maybe.empty();
6
6
  }
7
- let properties = [];
8
- for (const parentObjectType of this.parentObjectTypes) {
9
- properties.push(code `...${parentObjectType.jsonSchema({ context: "type" })}.shape`);
10
- }
11
- if (this.properties.length > 0) {
12
- properties = properties.concat(this.properties
13
- .flatMap((property) => property.jsonSchema.toList())
14
- .map(({ key, schema }) => code `"${key}": ${schema}`));
15
- }
7
+ const properties = this.properties
8
+ .flatMap((property) => property.jsonSchema.toList())
9
+ .map(({ key, schema }) => code `"${key}": ${schema}`);
16
10
  const meta = {
17
11
  // id: this.name,
18
12
  };
@@ -4,13 +4,6 @@ export function ObjectType_jsonTypeAliasDeclaration() {
4
4
  if (!this.configuration.features.has("Object.JSON.type")) {
5
5
  return Maybe.empty();
6
6
  }
7
- const members = [];
8
- if (this.properties.length > 0) {
9
- members.push(code `{ ${joinCode(this.properties.flatMap((property) => property.jsonSignature.toList()), { on: ";" })} }`);
10
- }
11
- for (const parentObjectType of this.parentObjectTypes) {
12
- members.push(code `${parentObjectType.jsonType().name}`);
13
- }
14
- return Maybe.of(code `export type Json = ${members.length > 0 ? joinCode(members, { on: " & " }) : "object"};`);
7
+ return Maybe.of(code `export type Json = { ${joinCode(this.properties.flatMap((property) => property.jsonSignature.toList()), { on: ";" })} }`);
15
8
  }
16
9
  //# sourceMappingURL=ObjectType_jsonTypeAliasDeclaration.js.map
@@ -5,9 +5,7 @@ export function ObjectType_jsonUiSchemaFunctionDeclaration() {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const variables = { scopePrefix: code `scopePrefix` };
8
- const elements = this.parentObjectTypes
9
- .map((parentObjectType) => code `${parentObjectType.alias.unsafeCoerce()}.Json.uiSchema({ scopePrefix })`)
10
- .concat(this.properties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
8
+ const elements = this.properties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList());
11
9
  return Maybe.of(code `\
12
10
  export function uiSchema(parameters?: { scopePrefix?: string }): any {
13
11
  const scopePrefix = parameters?.scopePrefix ?? "#";
@@ -5,10 +5,8 @@ export function ObjectType_schemaVariableStatement() {
5
5
  return Maybe.empty();
6
6
  }
7
7
  return Maybe.of(code `\
8
- export const schema = { properties: { ${joinCode(this.parentObjectTypes
9
- .map((parentObjectType) => code `...${parentObjectType.alias.unsafeCoerce()}.schema.properties`)
10
- .concat(this.properties.flatMap((property) => property.schema
8
+ export const schema = { properties: { ${joinCode(this.properties.flatMap((property) => property.schema
11
9
  .toList()
12
- .map((propertySchema) => code `${property.name}: ${propertySchema}`))), { on: ", " })} } } as const;`);
10
+ .map((propertySchema) => code `${property.name}: ${propertySchema}`)), { on: ", " })} } } as const;`);
13
11
  }
14
12
  //# sourceMappingURL=ObjectType_schemaVariableStatement.js.map
@@ -4,38 +4,17 @@ export function ObjectType_toJsonFunctionDeclaration() {
4
4
  if (!this.configuration.features.has("Object.toJson")) {
5
5
  return Maybe.empty();
6
6
  }
7
- const jsonObjectMembers = [];
8
- for (const parentObjectType of this.parentObjectTypes) {
9
- jsonObjectMembers.push(code `...${parentObjectType.alias.unsafeCoerce()}.toJson(${this.thisVariable})`);
10
- }
11
- if (this.properties.length > 0) {
12
- jsonObjectMembers.push(...this.properties.flatMap((property) => property
13
- .toJsonInitializer({
14
- variables: {
15
- value: property.accessExpression({
16
- variables: { object: this.thisVariable },
17
- }),
18
- },
19
- })
20
- .toList()));
21
- }
22
- const returnType = this.jsonType().name;
23
- // 20241220: don't add @type until we're doing JSON-LD
24
- // switch (this.toRdfTypes.length) {
25
- // case 0:
26
- // break;
27
- // case 1:
28
- // jsonObjectMembers.push(`"@type": "${this.toRdfTypes[0].value}"`);
29
- // break;
30
- // default:
31
- // jsonObjectMembers.push(
32
- // `"@type": ${JSON.stringify(this.toRdfTypes.map((rdfType) => rdfType.value))}`,
33
- // );
34
- // break;
35
- // }
36
7
  return Maybe.of(code `\
37
- export function toJson(${this.thisVariable}: ${this.expression}): ${returnType} {
38
- return JSON.parse(JSON.stringify({ ${joinCode(jsonObjectMembers, { on: "," })} } satisfies ${this.jsonType().name}));
8
+ export function toJson(${this.thisVariable}: ${this.expression}): ${this.jsonType().expression} {
9
+ return JSON.parse(JSON.stringify({ ${joinCode(this.properties.flatMap((property) => property
10
+ .toJsonInitializer({
11
+ variables: {
12
+ value: property.accessExpression({
13
+ variables: { object: this.thisVariable },
14
+ }),
15
+ },
16
+ })
17
+ .toList()), { on: "," })} } satisfies ${this.jsonType().expression}));
39
18
  }`);
40
19
  }
41
20
  //# sourceMappingURL=ObjectType_toJsonFunctionDeclaration.js.map
@@ -5,7 +5,7 @@ export function ObjectType_toRdfResourceFunctionDeclaration() {
5
5
  if (!this.configuration.features.has("Object.toRdf")) {
6
6
  return Maybe.empty();
7
7
  }
8
- const statements = this.parentObjectTypes.map((parentObjectType) => code `${parentObjectType.alias.unsafeCoerce()}._toRdfResource({ ...parameters, ignoreRdfType: true });`);
8
+ const statements = [];
9
9
  if (this.toRdfTypes.length > 0) {
10
10
  statements.push(code `if (!${variables.ignoreRdfType}) { ${joinCode(this.toRdfTypes.map((toRdfType) => code `${variables.resource}.add(${this.rdfjsTermExpression(rdf.type)}, ${this.reusables.imports.dataFactory}.namedNode("${toRdfType.value}"), ${variables.graph});`), { on: " " })} }`);
11
11
  }
@@ -3,13 +3,7 @@ export function ObjectType_toStringFunctionDeclarations() {
3
3
  if (!this.configuration.features.has("Object.toString")) {
4
4
  return [];
5
5
  }
6
- let propertiesToStringInitializers = [];
7
- if (this.parentObjectTypes.length > 0) {
8
- for (const parentObjectType of this.parentObjectTypes) {
9
- propertiesToStringInitializers.push(code `...${parentObjectType.alias.unsafeCoerce()}._propertiesToStrings(${this.thisVariable})`);
10
- }
11
- }
12
- propertiesToStringInitializers = propertiesToStringInitializers.concat(this.properties.flatMap((property) => property
6
+ const propertiesToStringsReturnExpression = code `${this.reusables.snippets.compactRecord}({${joinCode(this.properties.flatMap((property) => property
13
7
  .toStringInitializer({
14
8
  variables: {
15
9
  value: property.accessExpression({
@@ -17,8 +11,7 @@ export function ObjectType_toStringFunctionDeclarations() {
17
11
  }),
18
12
  },
19
13
  })
20
- .toList()));
21
- const propertiesToStringsReturnExpression = code `${this.reusables.snippets.compactRecord}({${joinCode(propertiesToStringInitializers, { on: "," })}})`;
14
+ .toList()), { on: "," })}})`;
22
15
  const toStringReturnExpression = (propertiesToStrings) => code `\`${this.alias.unsafeCoerce()}(\${JSON.stringify(${propertiesToStrings})})\``;
23
16
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
24
17
  return [
@@ -34,16 +34,16 @@ export class ShaclProperty extends AbstractProperty {
34
34
  return Maybe.of(code `readonly ${this.name}: ${this.type.expression};`);
35
35
  }
36
36
  let hasQuestionToken = false;
37
- const typeNames = [];
37
+ const typeExpressions = [];
38
38
  for (const type of conversionFunction.sourceTypes) {
39
- if (type.typeof === "undefined") {
39
+ if (type.jsType.typeof === "undefined") {
40
40
  hasQuestionToken = true;
41
41
  }
42
42
  else {
43
- typeNames.push(code `${type.expression}`);
43
+ typeExpressions.push(code `${type.expression}`);
44
44
  }
45
45
  }
46
- return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeNames, { on: "|" })};`);
46
+ return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeExpressions, { on: "|" })};`);
47
47
  }
48
48
  get declaration() {
49
49
  const lhs = [];
@@ -71,7 +71,7 @@ export class ShaclProperty extends AbstractProperty {
71
71
  description: this.comment.map(JSON.stringify),
72
72
  name: this.name,
73
73
  resolve: code `(source, ${argsVariable}) => ${this.type.graphqlResolveExpression({ variables: { args: argsVariable, value: code `source.${this.name}` } })}`,
74
- type: this.type.graphqlType.name,
74
+ type: this.type.graphqlType.expression,
75
75
  });
76
76
  }
77
77
  get jsonSchema() {
@@ -95,7 +95,7 @@ export class ShaclProperty extends AbstractProperty {
95
95
  }
96
96
  get jsonSignature() {
97
97
  const typeJsonType = this.type.jsonType();
98
- return Maybe.of(code `${!this.mutable ? "readonly " : ""}${this.name}${typeJsonType.optional ? "?" : ""}: ${typeJsonType.requiredName}`);
98
+ return Maybe.of(code `${!this.mutable ? "readonly " : ""}${this.name}${typeJsonType.optional ? "?" : ""}: ${typeJsonType.requiredExpression}`);
99
99
  }
100
100
  get schemaInitializers() {
101
101
  const initializers = super.schemaInitializers.concat();
@@ -1,19 +1,8 @@
1
- import { codeEquals } from "../codeEquals.js";
2
1
  import { code } from "../ts-poet-wrapper.js";
3
2
  export function identifierTypeDeclarations() {
4
3
  if (!this.configuration.features.has("Object.type")) {
5
4
  return [];
6
5
  }
7
- const ancestorObjectTypeWithSameIdentifierType = this.ancestorObjectTypes.find((ancestorObjectType) => ancestorObjectType.identifierType.kind === this.identifierType.kind &&
8
- codeEquals(ancestorObjectType.identifierType.expression, this.identifierType.expression));
9
- if (ancestorObjectTypeWithSameIdentifierType) {
10
- // This object type's identifier type has the same identifier type as an ancestor object type,
11
- // so just reuse the latter.
12
- return [
13
- code `export type Identifier = ${ancestorObjectTypeWithSameIdentifierType.identifierTypeAlias};`,
14
- code `export const Identifier = ${ancestorObjectTypeWithSameIdentifierType.identifierTypeAlias};`,
15
- ];
16
- }
17
6
  // Bespoke identifier type and associated functions
18
7
  return [
19
8
  code `export type Identifier = ${this.identifierType.expression};`,
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_convertToArraySet: SnippetFactory;
3
+ //# sourceMappingURL=snippets_convertToArraySet.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_convertToArraySet = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}convertToArraySet`, code `\
3
+ function ${syntheticNamePrefix}convertToArraySet<ItemSourceT, ItemTargetT, Readonly extends boolean>(convertToItem: ${snippets.ConversionFunction}<ItemSourceT, ItemTargetT>, _readonly: Readonly) {
4
+ type ItemTargetArrayT = Readonly extends true ? ReadonlyArray<ItemTargetT> : Array<ItemTargetT>;
5
+ return (value: readonly ItemSourceT[] | undefined): ${imports.Either}<Error, ItemTargetArrayT> =>
6
+ (typeof value === "undefined" ? ${imports.Either}.of([]) : ${imports.Either}.sequence(value.map(convertToItem))) as ${imports.Either}<Error, ItemTargetArrayT>;
7
+ }`);
8
+ //# sourceMappingURL=snippets_convertToArraySet.js.map
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_convertToList: SnippetFactory;
3
+ //# sourceMappingURL=snippets_convertToList.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_convertToList = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}convertToList`, code `\
3
+ function ${syntheticNamePrefix}convertToList<ItemSourceT, ItemTargetT, Readonly extends boolean>(convertToItem: ${snippets.ConversionFunction}<ItemSourceT, ItemTargetT>, _readonly: Readonly) {
4
+ type ItemTargetArrayT = Readonly extends true ? ReadonlyArray<ItemTargetT> : Array<ItemTargetT>;
5
+ return (value: readonly ItemSourceT[]): ${imports.Either}<Error, ItemTargetArrayT> => ${imports.Either}.sequence(value.map(convertToItem)) as ${imports.Either}<Error, ItemTargetArrayT>;
6
+ }`);
7
+ //# sourceMappingURL=snippets_convertToList.js.map
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_convertToScalarSet: SnippetFactory;
3
+ //# sourceMappingURL=snippets_convertToScalarSet.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_convertToScalarSet = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}convertToScalarSet`, code `\
3
+ function ${syntheticNamePrefix}convertToScalarSet<ItemSourceT, ItemTargetT, Readonly extends boolean>(convertToItem: ${snippets.ConversionFunction}<ItemSourceT, ItemTargetT>, _readonly: Readonly) {
4
+ type ItemTargetArrayT = Readonly extends true ? ReadonlyArray<ItemTargetT> : Array<ItemTargetT>;
5
+ return (value: ItemSourceT | readonly ItemSourceT[] | undefined): ${imports.Either}<Error, ItemTargetArrayT> => {
6
+ if (typeof value === "undefined") {
7
+ return ${imports.Either}.of<Error, ItemTargetArrayT>([] as unknown as ItemTargetArrayT);
8
+ }
9
+ if (Array.isArray(value)) {
10
+ return ${imports.Either}.sequence(value.map(convertToItem)) as ${imports.Either}<Error, ItemTargetArrayT>;
11
+ }
12
+ return convertToItem(value as ItemSourceT).map(value => [value]) as ${imports.Either}<Error, ItemTargetArrayT>;
13
+ };
14
+ }`);
15
+ //# sourceMappingURL=snippets_convertToScalarSet.js.map