@shaclmate/compiler 4.0.96 → 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 (23) 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/ObjectDiscriminatedUnionType.d.ts +7 -4
  14. package/dist/generators/ts/ObjectDiscriminatedUnionType.js +18 -2
  15. package/dist/generators/ts/ObjectIntersectionType.d.ts +7 -4
  16. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +21 -10
  17. package/dist/generators/ts/TypeFactory.js +19 -33
  18. package/dist/input/input.shaclmate.d.ts +2474 -2124
  19. package/dist/input/input.shaclmate.js +558 -1292
  20. package/dist/input/input.shaclmate.ttl +9 -5
  21. package/package.json +6 -4
  22. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.d.ts +0 -4
  23. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.js +0 -37
@@ -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,