@shaclmate/compiler 4.0.95 → 4.0.97

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 (31) hide show
  1. package/dist/_ShapesGraphToAstTransformer/synthesizePartialAstStructType.d.ts +6 -0
  2. package/dist/_ShapesGraphToAstTransformer/synthesizePartialAstStructType.js +38 -0
  3. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstStructTypeField.js +114 -145
  4. package/dist/_ShapesGraphToAstTransformer/transformShapeNodeConstraintToAstType.d.ts +7 -0
  5. package/dist/_ShapesGraphToAstTransformer/transformShapeNodeConstraintToAstType.js +13 -0
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstStructType.d.ts +1 -1
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstStructType.js +0 -52
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +2 -0
  9. package/dist/ast/StructCompoundType.d.ts +3 -2
  10. package/dist/ast/StructCompoundType.js +29 -46
  11. package/dist/ast/StructDiscriminatedUnionType.d.ts +5 -1
  12. package/dist/ast/StructIntersectionType.d.ts +4 -1
  13. package/dist/generators/ts/AbstractLazyType.d.ts +12 -5
  14. package/dist/generators/ts/AbstractLazyType.js +35 -22
  15. package/dist/generators/ts/LazyOptionType.d.ts +5 -7
  16. package/dist/generators/ts/LazyOptionType.js +2 -2
  17. package/dist/generators/ts/LazySetType.d.ts +1 -5
  18. package/dist/generators/ts/LazySetType.js +2 -2
  19. package/dist/generators/ts/LazyType.d.ts +1 -5
  20. package/dist/generators/ts/LazyType.js +2 -2
  21. package/dist/generators/ts/ObjectDiscriminatedUnionType.d.ts +7 -4
  22. package/dist/generators/ts/ObjectDiscriminatedUnionType.js +18 -2
  23. package/dist/generators/ts/ObjectIntersectionType.d.ts +7 -4
  24. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +21 -10
  25. package/dist/generators/ts/TypeFactory.js +19 -33
  26. package/dist/input/input.shaclmate.d.ts +2474 -2124
  27. package/dist/input/input.shaclmate.js +558 -1292
  28. package/dist/input/input.shaclmate.ttl +9 -5
  29. package/package.json +6 -4
  30. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.d.ts +0 -4
  31. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.js +0 -37
@@ -23,23 +23,23 @@ export declare abstract class AbstractLazyType<PartialTypeT extends AbstractLazy
23
23
  partialType: PartialTypeT;
24
24
  resolveType: ResolveTypeT;
25
25
  } & ConstructorParameters<typeof AbstractType>[0]);
26
- get jsonValueType(): AbstractType["jsonValueType"];
27
26
  get equalsFunction(): Callable;
28
- get jsonObjectType(): AbstractType["jsonObjectType"];
29
27
  get filterFunction(): Callable;
30
28
  get filterType(): Code;
31
- get fromJsonValueFunction(): AbstractType["fromJsonValueFunction"];
32
29
  get fromJsonObjectFunction(): AbstractType["fromJsonObjectFunction"];
30
+ get fromJsonValueFunction(): AbstractType["fromJsonValueFunction"];
33
31
  get fromRdfResourceValuesFunction(): Callable;
34
32
  get graphqlType(): AbstractType.GraphqlType;
35
33
  get hashFunction(): Callable;
36
34
  get inlineExpression(): Code;
37
35
  get jsTypes(): readonly AbstractType.JsType[];
36
+ get jsonObjectType(): AbstractType["jsonObjectType"];
37
+ get jsonValueType(): AbstractType["jsonValueType"];
38
38
  get recursive(): boolean;
39
39
  get referencesNamedType(): boolean;
40
40
  get schemaType(): Code;
41
- get toJsonValueFunction(): AbstractType["toJsonValueFunction"];
42
41
  get toJsonObjectFunction(): AbstractType["toJsonObjectFunction"];
42
+ get toJsonValueFunction(): AbstractType["toJsonValueFunction"];
43
43
  get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
44
44
  get valueSparqlConstructTriplesFunction(): Callable;
45
45
  get valueSparqlWherePatternsFunction(): Callable;
@@ -47,9 +47,11 @@ export declare abstract class AbstractLazyType<PartialTypeT extends AbstractLazy
47
47
  toLoggableExpression({ variables, }: Parameters<AbstractType["toLoggableExpression"]>[0]): Code;
48
48
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
49
49
  toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
50
- protected abstract objectSetResolverFunctionExpressions(parameters: {
50
+ protected abstract objectSetResolveExpression(parameters: {
51
51
  variables: {
52
52
  objectSet: Code;
53
+ partial: Code;
54
+ resolverOptions: Code;
53
55
  };
54
56
  }): Code;
55
57
  protected resolveToPartialFunction<ObjectTypeT extends AbstractLazyType.ItemTypeConstraint>({ partialType, resolveType, }: {
@@ -63,6 +65,11 @@ export declare abstract class AbstractLazyType<PartialTypeT extends AbstractLazy
63
65
  resolvedObjectDiscriminatedUnion: Code;
64
66
  };
65
67
  }): Code;
68
+ protected resolverFunctionExpression({ variables, }: {
69
+ variables: {
70
+ factoryFunctionOptions: Code;
71
+ };
72
+ }): Code;
66
73
  }
67
74
  export declare namespace AbstractLazyType {
68
75
  type ItemTypeConstraint = ObjectType | ObjectDiscriminatedUnionType;
@@ -21,17 +21,11 @@ export class AbstractLazyType extends AbstractType {
21
21
  this.partialType = partialType;
22
22
  this.resolveType = resolveType;
23
23
  }
24
- get jsonValueType() {
25
- return this.partialType.jsonValueType;
26
- }
27
24
  get equalsFunction() {
28
25
  return new InlineCallable(code `(left, right) => ${this.partialType.equalsFunction.annotatedUsage}(left.${this.runtimeClass.partialPropertyName}, right.${this.runtimeClass.partialPropertyName})`, {
29
26
  type: code `${this.reusables.snippets.EqualsFunction}<${this.expression}>`,
30
27
  });
31
28
  }
32
- get jsonObjectType() {
33
- return this.partialType.jsonObjectType;
34
- }
35
29
  get filterFunction() {
36
30
  return new InlineCallable(code `(filter, value) => ${this.partialType.filterFunction.annotatedUsage}(filter, value.${this.runtimeClass.partialPropertyName})`, {
37
31
  type: code `${this.reusables.snippets.FilterFunction}<${this.filterType}, ${this.expression}>`,
@@ -40,23 +34,23 @@ export class AbstractLazyType extends AbstractType {
40
34
  get filterType() {
41
35
  return this.partialType.filterType;
42
36
  }
43
- get fromJsonValueFunction() {
44
- return new InlineCallable(code `(jsonValue, { objectSet, schema, ...otherOptions }) => ${this.partialType.fromJsonValueFunction.annotatedUsage}(jsonValue, { objectSet, schema: schema.partialType, ...otherOptions })
45
- .map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: objectSet ? ${this.objectSetResolverFunctionExpressions({ variables: { objectSet: code `objectSet` } })} : ${this.reusables.snippets.missingResolver} }))`, {
46
- type: code `${this.reusables.snippets.FromJsonValueFunction}<${this.jsonValueType.expression}, ${this.expression}, ${this.schema}>`,
47
- });
48
- }
49
37
  get fromJsonObjectFunction() {
50
- return new InlineCallable(code `(jsonObject, { objectSet, schema, ...otherOptions }) => ${this.partialType.fromJsonObjectFunction.annotatedUsage}(jsonObject, { objectSet, schema: schema.partialType, ...otherOptions })
51
- .map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: objectSet ? ${this.objectSetResolverFunctionExpressions({ variables: { objectSet: code `objectSet` } })} : ${this.reusables.snippets.missingResolver} }))`, {
38
+ return new InlineCallable(code `(jsonObject, fromJsonObjectOptions) => ${this.partialType.fromJsonObjectFunction.annotatedUsage}(jsonObject, { ...fromJsonObjectOptions, schema: fromJsonObjectOptions.schema.partialType })
39
+ .map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: ${this.resolverFunctionExpression({ variables: { factoryFunctionOptions: code `fromJsonObjectOptions` } })} }))`, {
52
40
  type: code `${this.reusables.snippets.FromJsonObjectFunction}<${this.jsonObjectType.expression}, ${this.expression}, ${this.schema}>`,
53
41
  });
54
42
  }
43
+ get fromJsonValueFunction() {
44
+ return new InlineCallable(code `(jsonValue, fromJsonValueOptions) => ${this.partialType.fromJsonValueFunction.annotatedUsage}(jsonValue, { ...fromJsonValueOptions, schema: fromJsonValueOptions.schema.partialType })
45
+ .map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: ${this.resolverFunctionExpression({ variables: { factoryFunctionOptions: code `fromJsonValueOptions` } })} }))`, {
46
+ type: code `${this.reusables.snippets.FromJsonValueFunction}<${this.jsonValueType.expression}, ${this.expression}, ${this.schema}>`,
47
+ });
48
+ }
55
49
  get fromRdfResourceValuesFunction() {
56
50
  return new InlineCallable(code `\
57
- (values, { objectSet, schema, ...otherOptions }) =>
58
- ${this.partialType.fromRdfResourceValuesFunction.annotatedUsage}(values, { objectSet, schema: schema.partialType, ...otherOptions })
59
- .map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: ${this.objectSetResolverFunctionExpressions({ variables: { objectSet: code `objectSet` } })} })))`, {
51
+ (values, fromRdfResourceValuesOptions) =>
52
+ ${this.partialType.fromRdfResourceValuesFunction.annotatedUsage}(values, { ...fromRdfResourceValuesOptions, schema: fromRdfResourceValuesOptions.schema.partialType })
53
+ .map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: ${this.resolverFunctionExpression({ variables: { factoryFunctionOptions: code `fromRdfResourceValuesOptions` } })} })))`, {
60
54
  type: code `${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}, ${this.schemaType}>`,
61
55
  });
62
56
  }
@@ -78,6 +72,12 @@ export class AbstractLazyType extends AbstractType {
78
72
  },
79
73
  ];
80
74
  }
75
+ get jsonObjectType() {
76
+ return this.partialType.jsonObjectType;
77
+ }
78
+ get jsonValueType() {
79
+ return this.partialType.jsonValueType;
80
+ }
81
81
  get recursive() {
82
82
  return this.partialType.recursive;
83
83
  }
@@ -90,16 +90,16 @@ export class AbstractLazyType extends AbstractType {
90
90
  partialType: this.partialType.schemaType,
91
91
  }}`;
92
92
  }
93
- get toJsonValueFunction() {
94
- return new InlineCallable(code `(value) => ${this.partialType.toJsonValueFunction.unannotatedUsage}(value.${this.runtimeClass.partialPropertyName})`, {
95
- type: code `${this.reusables.snippets.ToJsonValueFunction}<${this.expression}, ${this.jsonValueType.expression}>`,
96
- });
97
- }
98
93
  get toJsonObjectFunction() {
99
94
  return new InlineCallable(code `(value) => ${this.partialType.toJsonObjectFunction.unannotatedUsage}(value.${this.runtimeClass.partialPropertyName})`, {
100
95
  type: code `${this.reusables.snippets.ToJsonObjectFunction}<${this.expression}, ${this.jsonValueType.expression}>`,
101
96
  });
102
97
  }
98
+ get toJsonValueFunction() {
99
+ return new InlineCallable(code `(value) => ${this.partialType.toJsonValueFunction.unannotatedUsage}(value.${this.runtimeClass.partialPropertyName})`, {
100
+ type: code `${this.reusables.snippets.ToJsonValueFunction}<${this.expression}, ${this.jsonValueType.expression}>`,
101
+ });
102
+ }
103
103
  get toRdfResourceValueTypes() {
104
104
  return this.partialType.toRdfResourceValueTypes;
105
105
  }
@@ -160,6 +160,19 @@ export class AbstractLazyType extends AbstractType {
160
160
  caseBlocks.push(code `default: ${variables.resolvedObjectDiscriminatedUnion} satisfies never; throw new Error("unrecognized type");`);
161
161
  return code `switch (${variables.resolvedObjectDiscriminatedUnion}.${resolvedObjectDiscriminatedUnionType.discriminatedType.unsafeCoerce().discriminantProperty.name}) { ${joinCode(caseBlocks)} }`;
162
162
  }
163
+ resolverFunctionExpression({ variables, }) {
164
+ if (!this.configuration.features.has("ObjectSet")) {
165
+ return code `${this.reusables.snippets.missingResolver}`;
166
+ }
167
+ return code `\
168
+ (partial, resolverOptions) => {
169
+ const objectSet = ${variables.factoryFunctionOptions}?.objectSet;
170
+ if (!objectSet) {
171
+ return ${this.reusables.snippets.missingResolver}();
172
+ }
173
+ return ${this.objectSetResolveExpression({ variables: { objectSet: code `objectSet`, partial: code `partial`, resolverOptions: code `resolverOptions` } })};
174
+ }`;
175
+ }
163
176
  }
164
177
  __decorate([
165
178
  Memoize()
@@ -5,7 +5,7 @@ import { type Code } from "./ts-poet-wrapper.js";
5
5
  export declare class LazyOptionType extends AbstractLazyType<OptionType<AbstractLazyType.ItemTypeConstraint>, OptionType<AbstractLazyType.ItemTypeConstraint>> {
6
6
  protected readonly partialItemType: AbstractLazyType.ItemTypeConstraint;
7
7
  protected readonly resolveItemType: AbstractLazyType.ItemTypeConstraint;
8
- readonly graphqlArgs: AbstractLazyType<OptionType<AbstractLazyType.ItemTypeConstraint>, OptionType<AbstractLazyType.ItemTypeConstraint>>["graphqlArgs"];
8
+ readonly graphqlArgs: Super["graphqlArgs"];
9
9
  readonly kind = "LazyOption";
10
10
  get conversionFunction(): Maybe<AbstractLazyType.ConversionFunction>;
11
11
  protected get runtimeClass(): {
@@ -13,11 +13,9 @@ export declare class LazyOptionType extends AbstractLazyType<OptionType<Abstract
13
13
  partialPropertyName: string;
14
14
  rawName: Code;
15
15
  };
16
- protected objectSetResolverFunctionExpressions({ variables, }: {
17
- variables: {
18
- objectSet: Code;
19
- };
20
- }): Code;
21
- graphqlResolveExpression({ variables, }: Parameters<AbstractLazyType<OptionType<AbstractLazyType.ItemTypeConstraint>, OptionType<AbstractLazyType.ItemTypeConstraint>>["graphqlResolveExpression"]>[0]): Code;
16
+ protected objectSetResolveExpression({ variables, }: Parameters<Super["objectSetResolveExpression"]>[0]): Code;
17
+ graphqlResolveExpression({ variables, }: Parameters<Super["graphqlResolveExpression"]>[0]): Code;
22
18
  }
19
+ type Super = AbstractLazyType<OptionType<AbstractLazyType.ItemTypeConstraint>, OptionType<AbstractLazyType.ItemTypeConstraint>>;
20
+ export {};
23
21
  //# sourceMappingURL=LazyOptionType.d.ts.map
@@ -53,8 +53,8 @@ ${this.reusables.snippets.convertToLazyOption}<
53
53
  rawName: code `${this.reusables.snippets.LazyOption}`,
54
54
  };
55
55
  }
56
- objectSetResolverFunctionExpressions({ variables, }) {
57
- return code `(partial, options) => ${variables.objectSet}.${this.resolveItemType.objectSetMethodNames.object}(partial.${this.partialItemType.identifierProperty.unsafeCoerce().name}(), options)`;
56
+ objectSetResolveExpression({ variables, }) {
57
+ return code `${variables.objectSet}.${this.resolveItemType.objectSetMethodNames.object}(${variables.partial}.${this.partialItemType.identifierProperty.unsafeCoerce().name}(), ${variables.resolverOptions})`;
58
58
  }
59
59
  graphqlResolveExpression({ variables, }) {
60
60
  return code `${variables.value}.resolve().then(either => either.unsafeCoerce().extractNullable())`;
@@ -8,11 +8,7 @@ export declare class LazySetType extends AbstractLazyType<SetType<AbstractLazyTy
8
8
  readonly graphqlArgs: Super["graphqlArgs"];
9
9
  readonly kind = "LazySet";
10
10
  get conversionFunction(): Maybe<AbstractLazyType.ConversionFunction>;
11
- protected objectSetResolverFunctionExpressions({ variables, }: {
12
- variables: {
13
- objectSet: Code;
14
- };
15
- }): Code;
11
+ protected objectSetResolveExpression({ variables, }: Parameters<Super["objectSetResolveExpression"]>[0]): Code;
16
12
  protected get runtimeClass(): {
17
13
  name: Code;
18
14
  partialPropertyName: string;
@@ -52,8 +52,8 @@ ${this.reusables.snippets.convertToLazySet}<
52
52
  ],
53
53
  });
54
54
  }
55
- objectSetResolverFunctionExpressions({ variables, }) {
56
- return code `(partials, options) => ${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.objects}({ identifiers: partials.map(partial => partial.${this.partialItemType.identifierProperty.unsafeCoerce().name}()), ...options })`;
55
+ objectSetResolveExpression({ variables, }) {
56
+ return code `${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.objects}({ identifiers: ${variables.partial}.map(partial => partial.${this.partialItemType.identifierProperty.unsafeCoerce().name}()), ...${variables.resolverOptions} })`;
57
57
  }
58
58
  get runtimeClass() {
59
59
  return {
@@ -13,11 +13,7 @@ export declare class LazyType extends AbstractLazyType<AbstractLazyType.ItemType
13
13
  rawName: Code;
14
14
  };
15
15
  graphqlResolveExpression({ variables, }: Parameters<Super["graphqlResolveExpression"]>[0]): Code;
16
- protected objectSetResolverFunctionExpressions({ variables, }: {
17
- variables: {
18
- objectSet: Code;
19
- };
20
- }): Code;
16
+ protected objectSetResolveExpression({ variables, }: Parameters<Super["objectSetResolveExpression"]>[0]): Code;
21
17
  }
22
18
  type Super = AbstractLazyType<AbstractLazyType.ItemTypeConstraint, AbstractLazyType.ItemTypeConstraint>;
23
19
  export {};
@@ -47,8 +47,8 @@ ${this.reusables.snippets.convertToLazy}<
47
47
  graphqlResolveExpression({ variables, }) {
48
48
  return code `${variables.value}.resolve().then(either => either.unsafeCoerce())`;
49
49
  }
50
- objectSetResolverFunctionExpressions({ variables, }) {
51
- return code `(partial, options) => ${variables.objectSet}.${this.resolveItemType.objectSetMethodNames.object}(partial.${this.partialItemType.identifierProperty.unsafeCoerce().name}(), options)`;
50
+ objectSetResolveExpression({ variables, }) {
51
+ return code `${variables.objectSet}.${this.resolveItemType.objectSetMethodNames.object}(${variables.partial}.${this.partialItemType.identifierProperty.unsafeCoerce().name}(), ${variables.resolverOptions})`;
52
52
  }
53
53
  }
54
54
  __decorate([
@@ -1,22 +1,22 @@
1
1
  import type { Maybe } from "purify-ts";
2
- import { ObjectDiscriminatedUnionType_schemaExpression } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.js";
3
2
  import { AbstractDiscriminatedUnionType } from "./AbstractDiscriminatedUnionType.js";
4
3
  import type { BlankNodeType } from "./BlankNodeType.js";
5
4
  import type { Callable } from "./Callable.js";
6
5
  import type { IdentifierType } from "./IdentifierType.js";
7
6
  import type { IriType } from "./IriType.js";
7
+ import type { ObjectIntersectionType } from "./ObjectIntersectionType.js";
8
8
  import type { ObjectType } from "./ObjectType.js";
9
9
  import { type Code } from "./ts-poet-wrapper.js";
10
- export declare class ObjectDiscriminatedUnionType extends AbstractDiscriminatedUnionType<ObjectType> {
11
- protected schemaExpression: typeof ObjectDiscriminatedUnionType_schemaExpression;
10
+ export declare class ObjectDiscriminatedUnionType extends AbstractDiscriminatedUnionType<ObjectDiscriminatedUnionType.MemberType> {
12
11
  readonly identifierType: BlankNodeType | IdentifierType | IriType;
13
12
  readonly kind = "ObjectDiscriminatedUnion";
14
13
  constructor({ identifierType, ...superParameters }: {
15
14
  identifierType: BlankNodeType | IdentifierType | IriType;
16
- } & ConstructorParameters<typeof AbstractDiscriminatedUnionType<ObjectType>>[0]);
15
+ } & ConstructorParameters<typeof AbstractDiscriminatedUnionType<ObjectDiscriminatedUnionType.MemberType>>[0]);
17
16
  get focusSparqlConstructTriplesFunction(): Callable;
18
17
  get focusSparqlWherePatternsFunction(): Callable;
19
18
  get fromRdfResourceFunction(): Callable;
19
+ get fromRdfTypeVariables(): readonly Code[];
20
20
  get identifierTypeAlias(): Code;
21
21
  get objectSetMethodNames(): ObjectType.ObjectSetMethodNames;
22
22
  get sparqlConstructQueryFunction(): Callable;
@@ -26,4 +26,7 @@ export declare class ObjectDiscriminatedUnionType extends AbstractDiscriminatedU
26
26
  protected get inlineExpression(): Code;
27
27
  protected staticModuleDeclarations(name: string): Record<string, Code>;
28
28
  }
29
+ export declare namespace ObjectDiscriminatedUnionType {
30
+ type MemberType = ObjectDiscriminatedUnionType | ObjectIntersectionType | ObjectType;
31
+ }
29
32
  //# sourceMappingURL=ObjectDiscriminatedUnionType.d.ts.map
@@ -10,7 +10,6 @@ import { ObjectDiscriminatedUnionType_focusSparqlConstructTriplesFunction } from
10
10
  import { ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunction } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunction.js";
11
11
  import { ObjectDiscriminatedUnionType_fromRdfResourceFunction } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_fromRdfResourceFunction.js";
12
12
  import { ObjectDiscriminatedUnionType_graphqlTypeExpression } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_graphqlTypeExpression.js";
13
- import { ObjectDiscriminatedUnionType_schemaExpression } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.js";
14
13
  import { ObjectDiscriminatedUnionType_toRdfResourceFunction } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_toRdfResourceFunction.js";
15
14
  import { ObjectDiscriminatedUnionType_typeGuardFunction } from "./_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_typeGuardFunction.js";
16
15
  import { ObjectType_identifierTypeDeclarations } from "./_ObjectType/ObjectType_identifierTypeDeclarations.js";
@@ -21,7 +20,6 @@ import { AbstractDiscriminatedUnionType } from "./AbstractDiscriminatedUnionType
21
20
  import { DeclaredCallable } from "./DeclaredCallable.js";
22
21
  import { code, joinCode } from "./ts-poet-wrapper.js";
23
22
  export class ObjectDiscriminatedUnionType extends AbstractDiscriminatedUnionType {
24
- schemaExpression = ObjectDiscriminatedUnionType_schemaExpression;
25
23
  identifierType;
26
24
  kind = "ObjectDiscriminatedUnion";
27
25
  constructor({ identifierType, ...superParameters }) {
@@ -37,6 +35,21 @@ export class ObjectDiscriminatedUnionType extends AbstractDiscriminatedUnionType
37
35
  get fromRdfResourceFunction() {
38
36
  return ObjectDiscriminatedUnionType_fromRdfResourceFunction.call(this);
39
37
  }
38
+ get fromRdfTypeVariables() {
39
+ return this.members.flatMap((member) => {
40
+ switch (member.type.kind) {
41
+ case "Object":
42
+ return member.type.fromRdfTypeVariable.toList();
43
+ case "ObjectDiscriminatedUnion":
44
+ return member.type.fromRdfTypeVariables;
45
+ case "ObjectIntersection":
46
+ return [];
47
+ default:
48
+ member.type;
49
+ throw new RangeError("should never reach this point");
50
+ }
51
+ });
52
+ }
40
53
  get identifierTypeAlias() {
41
54
  return this.name.map((name) => code `${name}.Identifier`).unsafeCoerce();
42
55
  }
@@ -121,6 +134,9 @@ __decorate([
121
134
  __decorate([
122
135
  Memoize()
123
136
  ], ObjectDiscriminatedUnionType.prototype, "fromRdfResourceFunction", null);
137
+ __decorate([
138
+ Memoize()
139
+ ], ObjectDiscriminatedUnionType.prototype, "fromRdfTypeVariables", null);
124
140
  __decorate([
125
141
  Memoize()
126
142
  ], ObjectDiscriminatedUnionType.prototype, "identifierTypeAlias", null);
@@ -10,7 +10,7 @@ import type { IdentifierType } from "./IdentifierType.js";
10
10
  import type { IriType } from "./IriType.js";
11
11
  import type { ObjectType } from "./ObjectType.js";
12
12
  import { type Code } from "./ts-poet-wrapper.js";
13
- export declare class ObjectIntersectionType extends AbstractIntersectionType<ObjectType> {
13
+ export declare class ObjectIntersectionType extends AbstractIntersectionType<ObjectIntersectionType.MemberType> {
14
14
  protected fromJsonObjectFunctionExpression: typeof ObjectIntersectionType_fromJsonObjectFunctionExpression;
15
15
  protected fromJsonObjectFunctionType: typeof ObjectIntersectionType_fromJsonObjectFunctionType;
16
16
  protected fromRdfResourceValuesFunctionExpression: typeof ObjectIntersectionType_fromRdfResourceValuesFunctionExpression;
@@ -22,7 +22,7 @@ export declare class ObjectIntersectionType extends AbstractIntersectionType<Obj
22
22
  readonly kind = "ObjectIntersection";
23
23
  constructor({ identifierType, ...superParameters }: {
24
24
  identifierType: BlankNodeType | IdentifierType | IriType;
25
- } & ConstructorParameters<typeof AbstractIntersectionType<ObjectType>>[0]);
25
+ } & ConstructorParameters<typeof AbstractIntersectionType<ObjectIntersectionType.MemberType>>[0]);
26
26
  get _fromRdfResourceFunction(): Callable;
27
27
  get _toRdfResourceFunction(): Callable;
28
28
  get createFunction(): Callable;
@@ -31,8 +31,8 @@ export declare class ObjectIntersectionType extends AbstractIntersectionType<Obj
31
31
  get focusSparqlWherePatternsFunction(): Callable;
32
32
  get fromRdfResourceFunction(): Callable;
33
33
  get identifierTypeAlias(): Code;
34
- get jsonObjectType(): AbstractIntersectionType<ObjectType>["jsonObjectType"];
35
- get jsonValueType(): AbstractIntersectionType<ObjectType>["jsonValueType"];
34
+ get jsonObjectType(): AbstractIntersectionType<ObjectIntersectionType.MemberType>["jsonObjectType"];
35
+ get jsonValueType(): AbstractIntersectionType<ObjectIntersectionType.MemberType>["jsonValueType"];
36
36
  get objectSetMethodNames(): ObjectType.ObjectSetMethodNames;
37
37
  get sparqlConstructQueryFunction(): Callable;
38
38
  get sparqlConstructQueryStringFunction(): Callable;
@@ -41,4 +41,7 @@ export declare class ObjectIntersectionType extends AbstractIntersectionType<Obj
41
41
  protected get createUnsafeFunction(): Callable;
42
42
  protected staticModuleDeclarations(name: string): Record<string, Code>;
43
43
  }
44
+ export declare namespace ObjectIntersectionType {
45
+ type MemberType = ObjectIntersectionType | ObjectType;
46
+ }
44
47
  //# sourceMappingURL=ObjectIntersectionType.d.ts.map
@@ -4,10 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { Maybe } from "purify-ts";
8
7
  import { Memoize } from "typescript-memoize";
9
8
  import { AbstractObjectSetType } from "./AbstractObjectSetType.js";
10
- import { code, joinCode } from "./ts-poet-wrapper.js";
9
+ import { arrayOf, code, joinCode } from "./ts-poet-wrapper.js";
11
10
  export class RdfjsDatasetObjectSetType extends AbstractObjectSetType {
12
11
  get declaration() {
13
12
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
@@ -87,30 +86,42 @@ async ${methodSignatures.objects.name}(${methodSignatures.objects.parameters}):
87
86
  }`,
88
87
  // objectsSync has per-object type logic, not just forwarding
89
88
  ];
90
- const runtimeObjectType = (filterFunction, namedObjectType) => {
91
- return code `{ filter: ${filterFunction.annotatedUsage}, fromRdfResource: ${namedObjectType.expression}.fromRdfResource, fromRdfTypes: ${namedObjectType.fromRdfTypeVariable.map((fromRdfTypeVariable) => code `[${fromRdfTypeVariable}]`).orDefault(code `[]`)} }`;
89
+ const runtimeObjectType = (namedObjectType, options) => {
90
+ let fromRdfTypeVariables;
91
+ switch (namedObjectType.kind) {
92
+ case "Object":
93
+ fromRdfTypeVariables =
94
+ namedObjectType.fromRdfTypeVariable.toList();
95
+ break;
96
+ case "ObjectDiscriminatedUnion":
97
+ fromRdfTypeVariables = namedObjectType.fromRdfTypeVariables;
98
+ break;
99
+ case "ObjectIntersection":
100
+ fromRdfTypeVariables = [];
101
+ break;
102
+ }
103
+ return code `{ filter: ${(options?.filterFunction ?? namedObjectType.filterFunction).annotatedUsage}, fromRdfResource: ${namedObjectType.expression}.fromRdfResource, fromRdfTypes: ${arrayOf(...fromRdfTypeVariables)} }`;
92
104
  };
93
105
  switch (namedObjectType.kind) {
94
106
  case "Object": {
95
107
  return delegatingMethods.concat(code `\
96
108
  ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.expression}[]> {
97
- return this.#objectsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType.filterFunction, namedObjectType)}, query);
109
+ return this.#objectsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType)}, query);
98
110
  }`);
99
111
  }
100
112
  case "ObjectDiscriminatedUnion":
101
113
  return delegatingMethods.concat(code `\
102
114
  ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.expression}[]> {
103
115
  return this.#objectDiscriminatedUnionsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>([
104
- ${joinCode(namedObjectType.members.map((member) => runtimeObjectType(namedObjectType.filterFunction, member.type)), { on: ", " })}
116
+ ${joinCode(namedObjectType.members.map((member) => runtimeObjectType(member.type, {
117
+ filterFunction: namedObjectType.filterFunction,
118
+ })), { on: ", " })}
105
119
  ], query);
106
120
  }`);
107
121
  case "ObjectIntersection":
108
122
  return delegatingMethods.concat(code `\
109
123
  ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.expression}[]> {
110
- return this.#objectsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType.filterFunction, {
111
- expression: namedObjectType.expression,
112
- fromRdfTypeVariable: Maybe.empty(),
113
- })}, query);
124
+ return this.#objectsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType)}, query);
114
125
  }`);
115
126
  default:
116
127
  namedObjectType;
@@ -86,23 +86,12 @@ export class TypeFactory {
86
86
  return cachedType;
87
87
  }
88
88
  }
89
- const objectDiscriminatedUnionIdentifierType = this.createIdentifierType(ast.StructCompoundType.identifierType(astType));
89
+ const objectDiscriminatedUnionIdentifierType = this.createIdentifierType(ast.StructCompoundType.identifierType(astType).unsafeCoerce());
90
90
  const objectDiscriminatedUnionTypeName = astType.name.map((name) => this.tsName(name));
91
91
  const objectDiscriminatedUnionType = new ObjectDiscriminatedUnionType({
92
92
  ...this.constructorParameters,
93
93
  comment: astType.comment,
94
- identifierProperty: astType.isStructDiscriminatedUnionType() &&
95
- astType.members.every((member) => {
96
- switch (member.type.kind) {
97
- case "DiscriminatedUnion":
98
- return member.type.members.every((member) => member.type.identifierField.isJust());
99
- case "Struct":
100
- return member.type.identifierField.isJust();
101
- default:
102
- member.type;
103
- throw new Error("should never reach this point");
104
- }
105
- })
94
+ identifierProperty: ast.StructCompoundType.hasIdentifierField(astType)
106
95
  ? Maybe.of(new ObjectType.IdentifierProperty({
107
96
  ...this.constructorParameters,
108
97
  name: `${this.configuration.syntheticNamePrefix}identifier`,
@@ -112,10 +101,16 @@ export class TypeFactory {
112
101
  : Maybe.empty(),
113
102
  identifierType: objectDiscriminatedUnionIdentifierType,
114
103
  label: astType.label,
115
- members: ast.StructCompoundType.memberStructTypes(astType).map((astStructType) => ({
116
- discriminantValue: Maybe.empty(),
117
- type: this.createObjectType(astStructType),
118
- })),
104
+ members: astType.members.map((member) => {
105
+ const type = this.createType(member.type);
106
+ invariant(type.kind === "ObjectDiscriminatedUnion" ||
107
+ type.kind === "ObjectIntersection" ||
108
+ type.kind === "Object", type.kind);
109
+ return {
110
+ discriminantValue: Maybe.empty(),
111
+ type: type,
112
+ };
113
+ }),
119
114
  name: objectDiscriminatedUnionTypeName,
120
115
  recursive: astType.recursive,
121
116
  shapeIdentifier: astType.shapeIdentifier,
@@ -132,23 +127,12 @@ export class TypeFactory {
132
127
  return cachedType;
133
128
  }
134
129
  }
135
- const objectIntersectionIdentifierType = this.createIdentifierType(ast.StructCompoundType.identifierType(astType));
130
+ const objectIntersectionIdentifierType = this.createIdentifierType(ast.StructCompoundType.identifierType(astType).unsafeCoerce());
136
131
  const objectIntersectionTypeName = astType.name.map((name) => this.tsName(name));
137
132
  const objectIntersectionType = new ObjectIntersectionType({
138
133
  ...this.constructorParameters,
139
134
  comment: astType.comment,
140
- identifierProperty: astType.isStructIntersectionType() &&
141
- astType.members.every((member) => {
142
- switch (member.type.kind) {
143
- case "Intersection":
144
- return member.type.members.every((member) => member.type.identifierField.isJust());
145
- case "Struct":
146
- return member.type.identifierField.isJust();
147
- default:
148
- member.type;
149
- throw new Error("should never reach this point");
150
- }
151
- })
135
+ identifierProperty: ast.StructCompoundType.hasIdentifierField(astType)
152
136
  ? Maybe.of(new ObjectType.IdentifierProperty({
153
137
  ...this.constructorParameters,
154
138
  name: `${this.configuration.syntheticNamePrefix}identifier`,
@@ -158,9 +142,11 @@ export class TypeFactory {
158
142
  : Maybe.empty(),
159
143
  identifierType: objectIntersectionIdentifierType,
160
144
  label: astType.label,
161
- members: ast.StructCompoundType.memberStructTypes(astType).map((astStructType) => ({
162
- type: this.createObjectType(astStructType),
163
- })),
145
+ members: astType.members.map((member) => {
146
+ const type = this.createType(member.type);
147
+ invariant(type.kind === "ObjectIntersection" || type.kind === "Object", type.kind);
148
+ return { type };
149
+ }),
164
150
  name: objectIntersectionTypeName,
165
151
  recursive: astType.recursive,
166
152
  shapeIdentifier: astType.shapeIdentifier,