@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
@@ -32,32 +32,11 @@ export class UnionType extends AbstractType {
32
32
  discriminantValues = [this.discriminant.memberValues[memberI]];
33
33
  break;
34
34
  case "Hybrid":
35
- discriminantValues =
36
- this.discriminant.memberValues[memberI].ownValues;
35
+ discriminantValues = this.discriminant.memberValues[memberI].values;
37
36
  break;
38
37
  case "Intrinsic": {
39
- // A member type's combined discriminant property values are its "own" values plus any descendant values that are
40
- // not the "own" values of some other member type.
41
- // So if you have type A, type B, and B inherits A, then
42
- // A has
43
- // own discriminant property values: ["A"]
44
- // descendant discriminant property values: ["B"]
45
- // and B has
46
- // own discriminant property values: ["B"]
47
- // descendant discriminant property values ["B"]
48
- // In this case A shouldn't have "B" as a combined discriminant property value since it's "claimed" by B.
49
- const memberOwnDiscriminantPropertyValues = new Set();
50
- for (const member of members) {
51
- for (const ownDiscriminantPropertyValue of member.type.discriminantProperty.unsafeCoerce()
52
- .ownValues) {
53
- memberOwnDiscriminantPropertyValues.add(ownDiscriminantPropertyValue);
54
- }
55
- }
56
- discriminantValues = member.type.discriminantProperty
57
- .unsafeCoerce()
58
- .ownValues.concat(member.type.discriminantProperty
59
- .unsafeCoerce()
60
- .descendantValues.filter((value) => !memberOwnDiscriminantPropertyValues.has(value)));
38
+ discriminantValues =
39
+ member.type.discriminantProperty.unsafeCoerce().values;
61
40
  break;
62
41
  }
63
42
  case "Typeof":
@@ -90,7 +69,7 @@ export class UnionType extends AbstractType {
90
69
  includeDiscriminantProperty: this.discriminant.kind === "Intrinsic" ||
91
70
  (this.discriminant.kind === "Hybrid" &&
92
71
  this.discriminant.memberValues[memberI].kind === "Intrinsic"),
93
- }).name,
72
+ }).expression,
94
73
  jsonTypeCheck: typeCheck(true),
95
74
  primaryDiscriminantValue: discriminantValues[0],
96
75
  type: member.type,
@@ -136,14 +115,17 @@ export class UnionType extends AbstractType {
136
115
  return Maybe.of({
137
116
  code: code `${this.reusables.snippets.identityConversionFunction}`,
138
117
  sourceTypes: this.discriminant.kind === "Typeof"
139
- ? this.members.map(({ primaryDiscriminantValue, type }) => ({
118
+ ? this.members.flatMap(({ type }) => type.jsTypes.map((jsType) => ({
140
119
  expression: type.expression,
141
- typeof: primaryDiscriminantValue,
142
- }))
120
+ jsType,
121
+ })))
143
122
  : [
144
123
  {
145
124
  expression: this.expression,
146
- typeof: "object",
125
+ jsType: {
126
+ instanceof: "Object",
127
+ typeof: "object",
128
+ },
147
129
  },
148
130
  ],
149
131
  });
@@ -174,22 +156,20 @@ ${joinCode(staticModuleDeclarations
174
156
  return Maybe.of({
175
157
  descendantValues: [],
176
158
  jsonName: this.discriminant.jsonName,
177
- ownValues: this.discriminant.memberValues,
178
159
  name: this.discriminant.name,
160
+ values: this.discriminant.memberValues,
179
161
  });
180
162
  case "Hybrid":
181
163
  return Maybe.of({
182
- descendantValues: [],
183
164
  jsonName: this.discriminant.jsonName,
184
- ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
185
165
  name: "termType",
166
+ values: this.discriminant.memberValues.flatMap((_) => _.values),
186
167
  });
187
168
  case "Intrinsic":
188
169
  return Maybe.of({
189
- descendantValues: this.discriminant.memberValues.flatMap((_) => _.descendantValues),
190
170
  jsonName: this.discriminant.jsonName,
191
171
  name: this.discriminant.name,
192
- ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
172
+ values: this.discriminant.memberValues,
193
173
  });
194
174
  case "Typeof":
195
175
  return Maybe.empty();
@@ -238,7 +218,7 @@ ${joinCode(staticModuleDeclarations
238
218
  return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
239
219
  }
240
220
  get jsonTypeAliasDeclaration() {
241
- return code `export type Json = ${this.inlineJsonType.name}`;
221
+ return code `export type Json = ${this.inlineJsonType.expression}`;
242
222
  }
243
223
  get members() {
244
224
  return this.lazyMembers();
@@ -272,8 +252,16 @@ ${joinCode(staticModuleDeclarations
272
252
  }
273
253
  return set;
274
254
  }
275
- get typeofs() {
276
- return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
255
+ get jsTypes() {
256
+ const jsTypes = [];
257
+ for (const member of this.members) {
258
+ for (const memberJsType of member.type.jsTypes) {
259
+ if (!jsTypes.some((jsType) => AbstractType.JsType.equals(jsType, memberJsType))) {
260
+ jsTypes.push(memberJsType);
261
+ }
262
+ }
263
+ }
264
+ return jsTypes;
277
265
  }
278
266
  get valueSparqlConstructTriplesFunction() {
279
267
  return this.alias
@@ -327,7 +315,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
327
315
  }
328
316
  get inlineFromJsonFunction() {
329
317
  return code `\
330
- ((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
318
+ ((value: ${this.jsonType().expression}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
331
319
  ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
332
320
  variables: {
333
321
  value: code `(${unwrap(code `value`)} as ${jsonType})`,
@@ -468,7 +456,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
468
456
  }
469
457
  get inlineToJsonFunction() {
470
458
  return code `\
471
- ((value: ${this.expression}): ${this.jsonType().name} => {
459
+ ((value: ${this.expression}): ${this.jsonType().expression} => {
472
460
  ${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
473
461
 
474
462
  throw new Error("unable to serialize to JSON");
@@ -621,13 +609,13 @@ export namespace Json {
621
609
  .map((alias) => code `${alias}.Json.schema()`)
622
610
  .orDefault(this.inlineJsonSchema);
623
611
  if (context === "property" && this.recursive) {
624
- return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().name}> => ${expression})`;
612
+ return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().expression}> => ${expression})`;
625
613
  }
626
614
  return expression;
627
615
  }
628
616
  jsonType() {
629
617
  return this.alias
630
- .map((alias) => new AbstractType.JsonType(`${alias}.Json`))
618
+ .map((alias) => new AbstractType.JsonType(code `${alias}.Json`))
631
619
  .orDefault(this.inlineJsonType);
632
620
  }
633
621
  jsonUiSchemaElement() {
@@ -683,7 +671,7 @@ __decorate([
683
671
  ], UnionType.prototype, "toRdfResourceValueTypes", null);
684
672
  __decorate([
685
673
  Memoize()
686
- ], UnionType.prototype, "typeofs", null);
674
+ ], UnionType.prototype, "jsTypes", null);
687
675
  __decorate([
688
676
  Memoize()
689
677
  ], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
@@ -743,7 +731,7 @@ export var Discriminant;
743
731
  // intrinsic
744
732
  {
745
733
  let inlineDiscriminantProperty;
746
- const memberValues = [];
734
+ let memberValues = [];
747
735
  for (const memberType of memberTypes) {
748
736
  const memberTypeDiscriminantProperty = memberType.discriminantProperty.extract();
749
737
  if (!memberTypeDiscriminantProperty) {
@@ -758,10 +746,7 @@ export var Discriminant;
758
746
  inlineDiscriminantProperty = undefined;
759
747
  break;
760
748
  }
761
- memberValues.push({
762
- descendantValues: memberTypeDiscriminantProperty.descendantValues,
763
- ownValues: memberTypeDiscriminantProperty.ownValues,
764
- });
749
+ memberValues = memberValues.concat(memberTypeDiscriminantProperty.values);
765
750
  }
766
751
  if (inlineDiscriminantProperty) {
767
752
  return {
@@ -774,15 +759,17 @@ export var Discriminant;
774
759
  }
775
760
  // typeof
776
761
  {
762
+ const memberTypeofs = [];
777
763
  const memberTypeofsSet = new Set();
778
764
  for (const memberType of memberTypes) {
779
- for (const memberTypeof of memberType.typeofs) {
780
- memberTypeofsSet.add(memberTypeof);
765
+ for (const memberJsType of memberType.jsTypes) {
766
+ memberTypeofs.push(memberJsType.typeof);
767
+ memberTypeofsSet.add(memberJsType.typeof);
781
768
  }
782
769
  }
783
770
  if (memberTypeofsSet.size === memberTypes.length) {
784
771
  return {
785
- memberValues: memberTypes.flatMap((memberType) => memberType.typeofs),
772
+ memberValues: memberTypeofs,
786
773
  kind: "Typeof",
787
774
  };
788
775
  }
@@ -790,7 +777,7 @@ export var Discriminant;
790
777
  // hybrid
791
778
  // If some member type is an RDF/JS term then reuse "termType" as the discriminant.
792
779
  if (memberTypes.some((memberType) => termTypes(memberType).size > 0)) {
793
- const extrinsicMemberTypeNamesSet = new Set();
780
+ const extrinsicMemberTypeAliasesSet = new Set();
794
781
  let extrinsicMemberTypeCount = 0;
795
782
  for (const memberType of memberTypes) {
796
783
  if (termTypes(memberType).size > 0) {
@@ -798,7 +785,7 @@ export var Discriminant;
798
785
  }
799
786
  extrinsicMemberTypeCount++;
800
787
  if (memberType.alias.isJust()) {
801
- extrinsicMemberTypeNamesSet.add(memberType.alias.extract());
788
+ extrinsicMemberTypeAliasesSet.add(memberType.alias.extract());
802
789
  }
803
790
  else {
804
791
  break;
@@ -812,12 +799,12 @@ export var Discriminant;
812
799
  if (memberTermTypes.size > 0) {
813
800
  return {
814
801
  kind: "Intrinsic",
815
- ownValues: [...memberTermTypes],
802
+ values: [...memberTermTypes],
816
803
  };
817
804
  }
818
805
  return {
819
806
  kind: "Extrinsic",
820
- ownValues: extrinsicMemberTypeNamesSet.size === extrinsicMemberTypeCount
807
+ values: extrinsicMemberTypeAliasesSet.size === extrinsicMemberTypeCount
821
808
  ? [memberType.alias.unsafeCoerce()]
822
809
  : [memberTypeI.toString()],
823
810
  };
@@ -829,7 +816,7 @@ export var Discriminant;
829
816
  {
830
817
  let memberValues;
831
818
  {
832
- const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.typeofs[0]));
819
+ const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.jsTypes[0].typeof));
833
820
  const memberTypeNamesSet = new Set(memberTypeNames);
834
821
  if (memberTypeNamesSet.size === memberTypeNames.length) {
835
822
  memberValues = memberTypeNames;
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from "ts-log";
2
- import * as ast from "../../ast/index.js";
2
+ import type * as ast from "../../ast/index.js";
3
3
  import type { Generator } from "../Generator.js";
4
4
  export declare class ZodGenerator implements Generator {
5
5
  private readonly logger;
@@ -1,4 +1,3 @@
1
- import * as ast from "../../ast/index.js";
2
1
  import { ObjectType_jsonSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js";
3
2
  import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
4
3
  import { Reusables } from "./Reusables.js";
@@ -19,24 +18,32 @@ export class ZodGenerator {
19
18
  reusables,
20
19
  });
21
20
  const declarations = [];
22
- for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createObjectType(astObjectType))) {
23
- declarations.push(code `\
24
- export namespace ${namedObjectType.alias.unsafeCoerce()} {
25
- ${joinCode(ObjectType_jsonTypeAliasDeclaration.call(namedObjectType).toList())}
21
+ for (const astNamedType of ast_.namedTypes) {
22
+ switch (astNamedType.kind) {
23
+ case "Object": {
24
+ const tsNamedObjectType = typeFactory.createObjectType(astNamedType);
25
+ declarations.push(code `\
26
+ export namespace ${tsNamedObjectType.alias.unsafeCoerce()} {
27
+ ${joinCode(ObjectType_jsonTypeAliasDeclaration.call(tsNamedObjectType).toList())}
26
28
 
27
29
  export namespace Json {
28
- ${joinCode(ObjectType_jsonSchemaFunctionDeclaration.call(namedObjectType).toList())}
30
+ ${joinCode(ObjectType_jsonSchemaFunctionDeclaration.call(tsNamedObjectType).toList())}
29
31
  }
30
32
  }`);
31
- }
32
- for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => typeFactory.createUnionType(astNamedUnionType))) {
33
- declarations.push(code `\
34
- export namespace ${astNamedUnionType.alias.unsafeCoerce()} {
35
- ${astNamedUnionType.jsonTypeAliasDeclaration}
33
+ break;
34
+ }
35
+ case "Union": {
36
+ const tsNamedUnionType = typeFactory.createUnionType(astNamedType);
37
+ declarations.push(code `\
38
+ export namespace ${tsNamedUnionType.alias.unsafeCoerce()} {
39
+ ${tsNamedUnionType.jsonTypeAliasDeclaration}
36
40
  export namespace Json {
37
- ${astNamedUnionType.jsonSchemaFunctionDeclaration}
41
+ ${tsNamedUnionType.jsonSchemaFunctionDeclaration}
38
42
  }
39
43
  }`);
44
+ break;
45
+ }
46
+ }
40
47
  }
41
48
  declarations.splice(0, 0, joinCode(reusables.snippets.ifUsed, { on: "\n\n" }));
42
49
  return joinCode(declarations, { on: "\n\n" }).toString({});
@@ -1,6 +1,5 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import type { Logger } from "ts-log";
3
- import type { ObjectType } from "../ObjectType.js";
4
3
  import type { Reusables } from "../Reusables.js";
5
4
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
6
5
  import type { TsGenerator } from "../TsGenerator.js";
@@ -9,7 +8,9 @@ import { type Code } from "../ts-poet-wrapper.js";
9
8
  export declare abstract class AbstractProperty<TypeT extends Pick<Type, "expression" | "filterFunction" | "mutable" | "schema">> {
10
9
  protected readonly configuration: TsGenerator.Configuration;
11
10
  protected readonly logger: Logger;
12
- protected readonly objectType: ObjectType;
11
+ protected readonly objectType: {
12
+ readonly alias: Maybe<string>;
13
+ };
13
14
  protected readonly reusables: Reusables;
14
15
  /**
15
16
  * Optional parameter to include in the parameters object of constructor function.
@@ -73,7 +74,9 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "express
73
74
  configuration: TsGenerator.Configuration;
74
75
  logger: Logger;
75
76
  name: string;
76
- objectType: ObjectType;
77
+ objectType: {
78
+ readonly alias: Maybe<string>;
79
+ };
77
80
  reusables: Reusables;
78
81
  type: TypeT;
79
82
  });
@@ -8,9 +8,10 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
8
8
  readonly kind = "Discriminant";
9
9
  readonly mutable = false;
10
10
  readonly recursive = false;
11
- constructor({ type, ...superParameters }: {
12
- type: DiscriminantProperty.Type;
13
- } & ConstructorParameters<typeof AbstractProperty>[0]);
11
+ readonly value: string;
12
+ constructor({ value, ...superParameters }: {
13
+ value: string;
14
+ } & Omit<ConstructorParameters<typeof AbstractProperty>[0], "type">);
14
15
  get declaration(): Code;
15
16
  get jsonName(): string;
16
17
  get jsonSchema(): AbstractProperty<DiscriminantProperty.Type>["jsonSchema"];
@@ -27,21 +28,16 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
27
28
  toJsonInitializer({ variables, }: Parameters<AbstractProperty<DiscriminantProperty.Type>["toJsonInitializer"]>[0]): Maybe<Code>;
28
29
  toRdfRdfResourceValuesStatements(): readonly Code[];
29
30
  toStringInitializer(): Maybe<Code>;
31
+ get values(): readonly string[];
30
32
  }
31
33
  export declare namespace DiscriminantProperty {
32
34
  class Type {
35
+ readonly value: string;
33
36
  readonly filterFunction: Code;
34
- readonly mutable: boolean;
35
- readonly descendantValues: readonly string[];
36
- readonly ownValues: readonly string[];
37
- constructor({ descendantValues, mutable, ownValues, }: {
38
- descendantValues: readonly string[];
39
- mutable: boolean;
40
- ownValues: readonly string[];
41
- });
37
+ readonly mutable = false;
38
+ constructor(value: string);
42
39
  get expression(): Code;
43
40
  get schema(): Code;
44
- get values(): string[];
45
41
  }
46
42
  }
47
43
  //# sourceMappingURL=DiscriminantProperty.d.ts.map
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Maybe } from "purify-ts";
8
8
  import { Memoize } from "typescript-memoize";
9
- import { arrayOf, code, literalOf } from "../ts-poet-wrapper.js";
9
+ import { code, literalOf } from "../ts-poet-wrapper.js";
10
10
  import { AbstractProperty } from "./AbstractProperty.js";
11
11
  export class DiscriminantProperty extends AbstractProperty {
12
12
  constructorParameter = Maybe.empty();
@@ -15,8 +15,10 @@ export class DiscriminantProperty extends AbstractProperty {
15
15
  kind = "Discriminant";
16
16
  mutable = false;
17
17
  recursive = false;
18
- constructor({ type, ...superParameters }) {
19
- super({ ...superParameters, type });
18
+ value;
19
+ constructor({ value, ...superParameters }) {
20
+ super({ ...superParameters, type: new DiscriminantProperty.Type(value) });
21
+ this.value = value;
20
22
  }
21
23
  get declaration() {
22
24
  return code `readonly ${this.name}: ${this.type.expression};`;
@@ -27,9 +29,7 @@ export class DiscriminantProperty extends AbstractProperty {
27
29
  get jsonSchema() {
28
30
  return Maybe.of({
29
31
  key: this.jsonName,
30
- schema: this.type.values.length > 1
31
- ? code `${this.reusables.imports.z}.enum(${arrayOf(...this.type.values)})`
32
- : code `${this.reusables.imports.z}.literal(${literalOf(this.type.values[0])})`,
32
+ schema: code `${this.reusables.imports.z}.literal(${literalOf(this.value)})`,
33
33
  });
34
34
  }
35
35
  get jsonSignature() {
@@ -42,7 +42,7 @@ export class DiscriminantProperty extends AbstractProperty {
42
42
  // return super.schemaInitializers.concat(code`type: ${this.type.schema}`);
43
43
  // }
44
44
  get constValue() {
45
- return code `${literalOf(this.objectType.discriminantValue)} as const`;
45
+ return code `${literalOf(this.value)} as const`;
46
46
  }
47
47
  constructorInitializer() {
48
48
  return Maybe.empty();
@@ -54,15 +54,9 @@ export class DiscriminantProperty extends AbstractProperty {
54
54
  return Maybe.empty();
55
55
  }
56
56
  hashStatements({ variables, }) {
57
- if (this.objectType.parentObjectTypes.length > 0) {
58
- return [];
59
- }
60
57
  return [code `${variables.hasher}.update(${variables.value});`];
61
58
  }
62
59
  jsonUiSchemaElement({ variables, }) {
63
- if (this.objectType.parentObjectTypes.length > 0) {
64
- return Maybe.empty();
65
- }
66
60
  const scope = code `\`\${${variables.scopePrefix}}/properties/${this.jsonName}\``;
67
61
  return Maybe.of(code `{ rule: { condition: { schema: { const: ${this.constValue} }, scope: ${scope} }, effect: "HIDE" }, scope: ${scope}, type: "Control" }`);
68
62
  }
@@ -81,6 +75,9 @@ export class DiscriminantProperty extends AbstractProperty {
81
75
  toStringInitializer() {
82
76
  return Maybe.empty();
83
77
  }
78
+ get values() {
79
+ return [this.value];
80
+ }
84
81
  }
85
82
  __decorate([
86
83
  Memoize()
@@ -91,33 +88,22 @@ __decorate([
91
88
  __decorate([
92
89
  Memoize()
93
90
  ], DiscriminantProperty.prototype, "jsonSignature", null);
91
+ __decorate([
92
+ Memoize()
93
+ ], DiscriminantProperty.prototype, "values", null);
94
94
  (function (DiscriminantProperty) {
95
95
  class Type {
96
+ value;
96
97
  filterFunction = code `nonextant`;
97
- mutable;
98
- descendantValues;
99
- ownValues;
100
- constructor({ descendantValues, mutable, ownValues, }) {
101
- this.descendantValues = descendantValues;
102
- this.mutable = mutable;
103
- this.ownValues = ownValues;
98
+ mutable = false;
99
+ constructor(value) {
100
+ this.value = value;
104
101
  }
105
102
  get expression() {
106
- return code `${this.values.map((name) => `"${name}"`).join(" | ")}`;
103
+ return code `${literalOf(this.value)}`;
107
104
  }
108
105
  get schema() {
109
106
  throw new Error("should never be called");
110
- // const initializers: Record<string, unknown> = {};
111
- // if (this.descendantValues.length > 0) {
112
- // initializers["descendantValues"] = this.descendantValues;
113
- // }
114
- // if (this.ownValues.length > 0) {
115
- // initializers["ownValues"] = this.ownValues;
116
- // }
117
- // return code`${initializers}`;
118
- }
119
- get values() {
120
- return this.ownValues.concat(this.descendantValues);
121
107
  }
122
108
  }
123
109
  __decorate([
@@ -126,9 +112,6 @@ __decorate([
126
112
  __decorate([
127
113
  Memoize()
128
114
  ], Type.prototype, "schema", null);
129
- __decorate([
130
- Memoize()
131
- ], Type.prototype, "values", null);
132
115
  DiscriminantProperty.Type = Type;
133
116
  })(DiscriminantProperty || (DiscriminantProperty = {}));
134
117
  //# sourceMappingURL=DiscriminantProperty.js.map
@@ -17,17 +17,17 @@ export class IdentifierProperty extends AbstractProperty {
17
17
  recursive = false;
18
18
  get constructorParameter() {
19
19
  let hasQuestionToken = false;
20
- const typeNames = [code `(() => ${this.typeExpression})`];
20
+ const typeExpressions = [code `(() => ${this.typeExpression})`];
21
21
  for (const type of this.type.conversionFunction.unsafeCoerce()
22
22
  .sourceTypes) {
23
- if (type.typeof === "undefined") {
23
+ if (type.jsType.typeof === "undefined") {
24
24
  hasQuestionToken = true;
25
25
  }
26
26
  else {
27
- typeNames.push(code `${type.expression}`);
27
+ typeExpressions.push(code `${type.expression}`);
28
28
  }
29
29
  }
30
- return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeNames, { on: "|" })};`);
30
+ return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeExpressions, { on: "|" })};`);
31
31
  }
32
32
  get declaration() {
33
33
  return code `readonly ${this.name}: () => ${this.typeExpression};`;
@@ -46,7 +46,7 @@ export class IdentifierProperty extends AbstractProperty {
46
46
  description: Maybe.empty(),
47
47
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
48
48
  resolve: code `(source) => ${this.typeExpression}.stringify(${this.accessExpression({ variables: { object: code `source` } })})`,
49
- type: this.type.graphqlType.name,
49
+ type: this.type.graphqlType.expression,
50
50
  });
51
51
  }
52
52
  get jsonSchema() {
@@ -6,40 +6,22 @@ export function ObjectType_createFunctionDeclaration() {
6
6
  return Maybe.empty();
7
7
  }
8
8
  const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParameter.toList());
9
- const parametersType = [];
10
- if (parametersPropertySignatures.length > 0) {
11
- parametersType.push(code `{ ${joinCode(parametersPropertySignatures)} }`);
12
- }
13
- for (const parentObjectType of this.parentObjectTypes) {
14
- parametersType.push(code `Parameters<typeof ${parentObjectType.alias.unsafeCoerce()}.create>[0]`);
15
- }
16
- if (parametersType.length === 0) {
17
- parametersType.push(code `object`);
18
- }
19
- const parametersHasQuestionToken = this.parentObjectTypes.length === 0 &&
20
- parametersPropertySignatures.every((propertySignature) => propertySignature.toCodeString([]).indexOf("?:") !== -1);
9
+ const parametersType = parametersPropertySignatures.length > 0
10
+ ? code `{ ${joinCode(parametersPropertySignatures)} }`
11
+ : code `object`;
12
+ const parametersHasQuestionToken = parametersPropertySignatures.every((propertySignature) => propertySignature.toCodeString([]).indexOf("?:") !== -1);
21
13
  const parametersVariable = code `parameters${parametersHasQuestionToken ? "?" : ""}`;
22
- const parametersSignature = code `parameters${parametersHasQuestionToken ? "?" : ""}: ${joinCode(parametersType, { on: " & " })}`;
23
- const chains = [];
24
- this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
25
- chains.push({
26
- expression: code `${parentObjectType.alias.unsafeCoerce()}.create(parameters)`,
27
- variable: `super${parentObjectTypeI}`,
28
- });
29
- });
14
+ const parametersSignature = code `parameters${parametersHasQuestionToken ? "?" : ""}: ${parametersType}`;
30
15
  const propertyInitializers = this.properties.flatMap((property) => property
31
16
  .constructorInitializer({
32
17
  variables: { parameters: parametersVariable },
33
18
  })
34
19
  .toList());
35
20
  invariant(propertyInitializers.length > 0);
36
- chains.push({
37
- expression: code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyInitializers, { on: "," })} })`,
38
- variable: "properties",
21
+ let returnExpression = code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyInitializers, { on: "," })} })`;
22
+ this.discriminantProperty.ifJust((discriminantProperty) => {
23
+ returnExpression = code `${returnExpression}.map(properties => ({ ...properties, ${discriminantProperty.name}: ${literalOf(discriminantProperty.value)} as const }))`;
39
24
  });
40
- let returnExpression = code `{ ${chains
41
- .map((chain) => `...${chain.variable}`)
42
- .join(", ")}, ${this._discriminantProperty.name}: ${literalOf(this.discriminantValue)} as const }`;
43
25
  const monkeyPatchMethods = [];
44
26
  if (this.configuration.features.has("Object.toJson")) {
45
27
  monkeyPatchMethods.push("toJson");
@@ -48,11 +30,8 @@ export function ObjectType_createFunctionDeclaration() {
48
30
  monkeyPatchMethods.push(`${this.configuration.syntheticNamePrefix}toString`);
49
31
  }
50
32
  if (monkeyPatchMethods.length > 0) {
51
- returnExpression = code `${this.reusables.snippets.monkeyPatchObject}(${returnExpression}, { ${monkeyPatchMethods.join(", ")} })`;
33
+ returnExpression = code `${returnExpression}.map(object => ${this.reusables.snippets.monkeyPatchObject}(object, { ${monkeyPatchMethods.join(", ")} }))`;
52
34
  }
53
- returnExpression = chains
54
- .toReversed()
55
- .reduce((acc, { expression, variable }, chainI) => code `(${expression}).${chainI === 0 ? "map" : "chain"}(${variable} => ${acc})`, returnExpression);
56
35
  return Maybe.of(code `\
57
36
  export function create(${parametersSignature}): ${this.reusables.imports.Either}<Error, ${this.expression}> {
58
37
  return ${returnExpression};
@@ -5,10 +5,6 @@ export function ObjectType_equalsFunctionDeclaration() {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const chain = [];
8
- // For every parent, find the nearest equals implementation
9
- for (const parentObjectType of this.parentObjectTypes) {
10
- chain.push(code `${parentObjectType.equalsFunction}(left, right)`);
11
- }
12
8
  for (const property of this.properties) {
13
9
  if (property.kind === "Discriminant") {
14
10
  continue;
@@ -5,9 +5,6 @@ export function ObjectType_filterFunctionDeclaration() {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const statements = [];
8
- for (const parentObjectType of this.parentObjectTypes) {
9
- statements.push(code `if (!${parentObjectType.filterFunction}(filter, value)) { return false; }`);
10
- }
11
8
  if (this.properties.length > 0) {
12
9
  for (const property of this.properties) {
13
10
  property.filterProperty.ifJust(({ name }) => {
@@ -16,9 +16,6 @@ export function ObjectType_filterTypeDeclaration() {
16
16
  members.push(code `{ ${joinCode(Object.entries(filterProperties).map(([name, type]) => code `readonly ${name}?: ${type}`), { on: ";" })} }`);
17
17
  }
18
18
  }
19
- for (const parentObjectType of this.parentObjectTypes) {
20
- members.push(code `${parentObjectType.alias.unsafeCoerce()}.Filter`);
21
- }
22
19
  return Maybe.of(code `\
23
20
  export type Filter = ${members.length > 0 ? joinCode(members, { on: " & " }) : "object"};`);
24
21
  }
@@ -14,10 +14,6 @@ export function ObjectType_focusSparqlConstructTriplesFunctionDeclaration() {
14
14
  const rdfTypeVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
15
15
  let triplesVariableDeclarationKeyword = "const";
16
16
  const statements = [];
17
- for (const parentObjectType of this.parentObjectTypes) {
18
- statements.push(code `triples = triples.concat(${parentObjectType.alias.unsafeCoerce()}.focusSparqlConstructTriples(${{ filter: variables.filter, focusIdentifier: variables.focusIdentifier, ignoreRdfType: true, variablePrefix: variables.variablePrefix }}));`);
19
- triplesVariableDeclarationKeyword = "let";
20
- }
21
17
  if (this.fromRdfType.isJust()) {
22
18
  statements.push(code `\
23
19
  if (!parameters?.ignoreRdfType) {