@shaclmate/compiler 4.0.99 → 4.0.101

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 (27) hide show
  1. package/dist/generators/ts/AbstractBuiltinType.d.ts +23 -0
  2. package/dist/generators/ts/AbstractBuiltinType.js +18 -0
  3. package/dist/generators/ts/AbstractUserDefinedType.d.ts +71 -0
  4. package/dist/generators/ts/AbstractUserDefinedType.js +285 -0
  5. package/dist/generators/ts/BuiltinCallable.d.ts +14 -0
  6. package/dist/generators/ts/BuiltinCallable.js +16 -0
  7. package/dist/generators/ts/Imports.d.ts +1 -0
  8. package/dist/generators/ts/Imports.js +1 -0
  9. package/dist/generators/ts/SchemaObject.d.ts +98 -0
  10. package/dist/generators/ts/SchemaObject.js +143 -0
  11. package/dist/generators/ts/Snippets.d.ts +0 -1
  12. package/dist/generators/ts/Snippets.js +0 -7
  13. package/dist/generators/ts/_ObjectType/ObjectType_jsonObjectType.d.ts +4 -0
  14. package/dist/generators/ts/_ObjectType/ObjectType_jsonObjectType.js +26 -0
  15. package/dist/generators/ts/_snippets/snippets_LazySchema.d.ts +3 -0
  16. package/dist/generators/ts/_snippets/snippets_LazySchema.js +7 -0
  17. package/dist/generators/ts/_snippets/snippets_convertToIdentifier.js +1 -1
  18. package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.js +1 -1
  19. package/dist/generators/ts/_snippets/snippets_convertToIri.js +1 -1
  20. package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.js +1 -1
  21. package/dist/generators/ts/_snippets/snippets_iriFromJsonString.js +1 -1
  22. package/dist/input/ShapesGraph.js +2 -2
  23. package/dist/input/input.shaclmate.d.ts +642 -616
  24. package/dist/input/input.shaclmate.js +155 -147
  25. package/package.json +22 -22
  26. package/dist/generators/ts/_snippets/snippets_iriFromString.d.ts +0 -3
  27. package/dist/generators/ts/_snippets/snippets_iriFromString.js +0 -76
@@ -0,0 +1,143 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Memoize } from "typescript-memoize";
8
+ import { CodeThunk } from "./CodeThunk.js";
9
+ import { code, joinCode } from "./ts-poet-wrapper.js";
10
+ /**
11
+ * Runtime schema/metadata objects for types and properties.
12
+ */
13
+ export class SchemaObject {
14
+ /**
15
+ * Object literal properties, usually property assignments like name: value
16
+ * without a terminating comma.
17
+ *
18
+ * Note the name is repeated between the key and the value:
19
+ * { name: code`name: value` }
20
+ * Only the value is incorporated into generated code. The keys are used to sort properties.
21
+ *
22
+ * This enables overwriting in the *Type tree while also supporting non-property assignments such as
23
+ * { name: code`get name() { return value; }` }
24
+ * or
25
+ * { shorthand: code `shorthand` }
26
+ */
27
+ properties;
28
+ /**
29
+ * Type of the schema object.
30
+ */
31
+ type;
32
+ /**
33
+ * Variable pointing to the schema object.
34
+ */
35
+ variable;
36
+ constructor({ properties, type, variable, }) {
37
+ this.properties = properties;
38
+ this.type = type;
39
+ this.variable = variable;
40
+ }
41
+ /**
42
+ * Expression for this schema object, either the variable or a literal expression.
43
+ */
44
+ get expression() {
45
+ return this.variable.orDefaultLazy(() => this.literalExpression);
46
+ }
47
+ /**
48
+ * Literal expression of the schema object e.g., { name1: value1, name2: value2 }
49
+ */
50
+ get literalExpression() {
51
+ return code `{ ${joinCode(Object.keys(this.properties)
52
+ .sort()
53
+ .map((key) => CodeThunk.evaluate(this.properties[key])), { on: ", " })} } as const`;
54
+ }
55
+ toString() {
56
+ throw new Error("should never be called");
57
+ }
58
+ }
59
+ __decorate([
60
+ Memoize()
61
+ ], SchemaObject.prototype, "expression", null);
62
+ __decorate([
63
+ Memoize()
64
+ ], SchemaObject.prototype, "literalExpression", null);
65
+ (function (SchemaObject) {
66
+ /**
67
+ * Placeholder for abstract base classes.
68
+ */
69
+ class AbstractType {
70
+ ownerKind;
71
+ constructor(ownerKind) {
72
+ this.ownerKind = ownerKind;
73
+ }
74
+ get expression() {
75
+ throw new Error(`should never be called (instantiated by ${this.ownerKind})`);
76
+ }
77
+ toString() {
78
+ throw new Error("should never be called");
79
+ }
80
+ }
81
+ SchemaObject.AbstractType = AbstractType;
82
+ /**
83
+ * A built-in schema object type from a snippet or import.
84
+ */
85
+ class BuiltinType {
86
+ expression;
87
+ constructor(expression) {
88
+ this.expression = code `${expression}`;
89
+ }
90
+ toString() {
91
+ throw new Error("should never be called");
92
+ }
93
+ }
94
+ SchemaObject.BuiltinType = BuiltinType;
95
+ /**
96
+ * A user-defined schema object type, typically corresponding to user-defined types.
97
+ */
98
+ class UserDefinedType {
99
+ /**
100
+ * Members of the schema object type, usually property signatures like name: string.
101
+ *
102
+ * Note the name is repeated between the key and the value:
103
+ * { name: code`name: string` }
104
+ * This enables overwriting in the *Type tree. Unlike property assignments (above),
105
+ * we don't really need to support other member types (index signatures, methods, et al.).
106
+ * Rather, the name is repeated here for consistency with property assignments.
107
+ */
108
+ members;
109
+ /**
110
+ * Name of the type, can be used in type annotations.
111
+ */
112
+ name;
113
+ constructor({ members, name, }) {
114
+ this.members = members;
115
+ this.name = name;
116
+ }
117
+ /**
118
+ * Expression of the schema object type, either the name or a literal expression.
119
+ */
120
+ get expression() {
121
+ return this.name.orDefaultLazy(() => this.literalExpression);
122
+ }
123
+ /**
124
+ * Literal expression of the schema object type e.g., { name1: string, name2: string }.
125
+ */
126
+ get literalExpression() {
127
+ return code `{ ${joinCode(Object.keys(this.members)
128
+ .sort()
129
+ .map((key) => code `${CodeThunk.evaluate(this.members[key])};`))} }`;
130
+ }
131
+ toString() {
132
+ throw new Error("should never be called");
133
+ }
134
+ }
135
+ __decorate([
136
+ Memoize()
137
+ ], UserDefinedType.prototype, "expression", null);
138
+ __decorate([
139
+ Memoize()
140
+ ], UserDefinedType.prototype, "literalExpression", null);
141
+ SchemaObject.UserDefinedType = UserDefinedType;
142
+ })(SchemaObject || (SchemaObject = {}));
143
+ //# sourceMappingURL=SchemaObject.js.map
@@ -190,7 +190,6 @@ export declare class Snippets {
190
190
  get iriFromJsonObject(): Snippet;
191
191
  get iriFromJsonString(): Snippet;
192
192
  get iriFromRdfResourceValues(): Snippet;
193
- get iriFromString(): Snippet;
194
193
  get iriLiteralFromJsonObject(): Snippet;
195
194
  get iriLiteralFromJsonString(): Snippet;
196
195
  get iriSparqlWherePatterns(): Snippet;
@@ -184,7 +184,6 @@ import { snippets_intFromRdfResourceValues } from "./_snippets/snippets_intFromR
184
184
  import { snippets_iriFromJsonObject } from "./_snippets/snippets_iriFromJsonObject.js";
185
185
  import { snippets_iriFromJsonString } from "./_snippets/snippets_iriFromJsonString.js";
186
186
  import { snippets_iriFromRdfResourceValues } from "./_snippets/snippets_iriFromRdfResourceValues.js";
187
- import { snippets_iriFromString } from "./_snippets/snippets_iriFromString.js";
188
187
  import { snippets_iriLiteralFromJsonObject } from "./_snippets/snippets_iriLiteralFromJsonObject.js";
189
188
  import { snippets_iriLiteralFromJsonString } from "./_snippets/snippets_iriLiteralFromJsonString.js";
190
189
  import { snippets_iriSparqlWherePatterns } from "./_snippets/snippets_iriSparqlWherePatterns.js";
@@ -795,9 +794,6 @@ export class Snippets {
795
794
  get iriFromRdfResourceValues() {
796
795
  return this.snippet(snippets_iriFromRdfResourceValues);
797
796
  }
798
- get iriFromString() {
799
- return this.snippet(snippets_iriFromString);
800
- }
801
797
  get iriLiteralFromJsonObject() {
802
798
  return this.snippet(snippets_iriLiteralFromJsonObject);
803
799
  }
@@ -1605,9 +1601,6 @@ __decorate([
1605
1601
  __decorate([
1606
1602
  Memoize()
1607
1603
  ], Snippets.prototype, "iriFromRdfResourceValues", null);
1608
- __decorate([
1609
- Memoize()
1610
- ], Snippets.prototype, "iriFromString", null);
1611
1604
  __decorate([
1612
1605
  Memoize()
1613
1606
  ], Snippets.prototype, "iriLiteralFromJsonObject", null);
@@ -0,0 +1,4 @@
1
+ import type { AbstractUserDefinedType } from "../AbstractUserDefinedType.js";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ export declare function ObjectType_jsonObjectType(this: ObjectType): AbstractUserDefinedType["jsonObjectType"];
4
+ //# sourceMappingURL=ObjectType_jsonObjectType.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { InlineCallable } from "../InlineCallable.js";
2
+ import { code, literalOf } from "../ts-poet-wrapper.js";
3
+ export function ObjectType_jsonObjectType() {
4
+ // If the JSON object type is { "@id": string }, allow a shorthand of string => that type.
5
+ let shorthand;
6
+ this.identifierProperty.ifJust((identifierProperty) => {
7
+ const fromJsonObjectInitializerParameters = {
8
+ variables: { context: code ``, jsonObject: code ``, options: code `` },
9
+ };
10
+ if (this.properties.some((property) => !Object.is(property, identifierProperty) &&
11
+ property
12
+ .fromJsonObjectInitializer(fromJsonObjectInitializerParameters)
13
+ .isJust())) {
14
+ return;
15
+ }
16
+ shorthand = {
17
+ transformer: new InlineCallable(code `(id) => ({ ${literalOf(identifierProperty.jsonObjectMember.unsafeCoerce().name)}: id })`),
18
+ type: identifierProperty.type.jsonValueType,
19
+ };
20
+ });
21
+ return this.jsonTypeFactory.createJsonObjectType(this.properties.flatMap((property) => property.jsonObjectMember.toList()), {
22
+ name: this.name.map((name) => [name, "Json"]).extract(),
23
+ shorthand,
24
+ });
25
+ }
26
+ //# sourceMappingURL=ObjectType_jsonObjectType.js.map
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_LazySchema: SnippetFactory;
3
+ //# sourceMappingURL=snippets_LazySchema.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_LazySchema = ({ syntheticNamePrefix }) => conditionalOutput(`${syntheticNamePrefix}LazySchema`, code `\
3
+ interface ${syntheticNamePrefix}LazySchema<PartialSchemaT>{
4
+ readonly kind: "Lazy" | "LazyOption" | "LazySet";
5
+ readonly partialType: PartialSchemaT;
6
+ }`);
7
+ //# sourceMappingURL=snippets_LazySchema.js.map
@@ -5,7 +5,7 @@ function ${syntheticNamePrefix}convertToIdentifier<DefaultNamespaceT extends ${s
5
5
  case "object":
6
6
  return ${imports.Either}.of(value);
7
7
  case "string":
8
- return ${snippets.iriFromString}(value, { defaultNamespace });
8
+ return ${imports.expandIri}(value, { dataFactory: ${imports.dataFactory}, defaultNamespace });
9
9
  case "undefined":
10
10
  return ${imports.Either}.of(${imports.dataFactory}.blankNode());
11
11
  }
@@ -9,7 +9,7 @@ function ${syntheticNamePrefix}convertToIdentifierProperty<DefaultNamespaceT ext
9
9
  return ${imports.Either}.of(() => captureIdentifier);
10
10
  }
11
11
  case "string":
12
- return ${snippets.iriFromString}(identifier, { defaultNamespace }).map(iri => (() => iri));
12
+ return ${imports.expandIri}(identifier, { dataFactory: ${imports.dataFactory}, defaultNamespace }).map(iri => (() => iri));
13
13
  case "undefined": {
14
14
  const captureIdentifier = ${imports.dataFactory}.blankNode();
15
15
  return ${imports.Either}.of(() => captureIdentifier);
@@ -5,7 +5,7 @@ function ${syntheticNamePrefix}convertToIri<DefaultNamespaceT extends ${snippets
5
5
  case "object":
6
6
  return ${imports.Either}.of(value);
7
7
  case "string":
8
- return ${snippets.iriFromString}(value, { defaultNamespace });
8
+ return ${imports.expandIri}(value, { dataFactory: ${imports.dataFactory}, defaultNamespace });
9
9
  }
10
10
  }`);
11
11
  //# sourceMappingURL=snippets_convertToIri.js.map
@@ -9,7 +9,7 @@ function ${syntheticNamePrefix}convertToIriIdentifierProperty<DefaultNamespaceT
9
9
  return ${imports.Either}.of(() => captureIdentifier);
10
10
  }
11
11
  case "string": {
12
- return ${snippets.iriFromString}(identifier, { defaultNamespace }).map(iri => (() => iri));
12
+ return ${imports.expandIri}(identifier, { dataFactory: ${imports.dataFactory}, defaultNamespace }).map(iri => (() => iri));
13
13
  }
14
14
  }
15
15
  }`);
@@ -1,6 +1,6 @@
1
1
  import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
2
  export const snippets_iriFromJsonString = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}iriFromJsonString`, code `\
3
3
  function ${syntheticNamePrefix}iriFromJsonString(jsonString: string, options: Parameters<${snippets.FromJsonFunction}<string, ${imports.NamedNode}, object>>[1]): ${imports.Either}<Error, ${imports.NamedNode}> {
4
- return ${snippets.iriFromString}(jsonString, options);
4
+ return ${imports.expandIri}(jsonString, { ...options, dataFactory: ${imports.dataFactory} });
5
5
  }`);
6
6
  //# sourceMappingURL=snippets_iriFromJsonString.js.map
@@ -1,5 +1,5 @@
1
1
  import { datasetFactory, TermMap } from "@rdfx/collection";
2
- import { Curie } from "@rdfx/curie";
2
+ import { shrinkIri } from "@rdfx/curie";
3
3
  import dataFactory from "@rdfx/data-factory";
4
4
  import { ResourceSet } from "@rdfx/resource";
5
5
  import { AbstractShapesGraph } from "@shaclmate/shacl-ast";
@@ -31,7 +31,7 @@ export class ShapesGraph extends AbstractShapesGraph {
31
31
  if (cachedCurie) {
32
32
  return cachedCurie;
33
33
  }
34
- const curie = Curie.fromIri(term, {
34
+ const curie = shrinkIri(term, {
35
35
  prefixMap: options.prefixMap,
36
36
  }).extract();
37
37
  if (curie) {