@shaclmate/compiler 4.0.2 → 4.0.4

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 (34) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +4 -1
  2. package/dist/ShapesGraphToAstTransformer.js +5 -1
  3. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +4 -3
  4. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +58 -3
  5. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +3 -4
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +1 -1
  7. package/dist/ast/AbstractObjectCompoundType.d.ts +1 -1
  8. package/dist/ast/AbstractObjectCompoundType.js +1 -1
  9. package/dist/ast/ObjectType.d.ts +4 -1
  10. package/dist/enums/TsFeature.d.ts +2 -1
  11. package/dist/enums/TsFeature.js +9 -1
  12. package/dist/generators/codeName.d.ts +6 -0
  13. package/dist/generators/codeName.js +66 -0
  14. package/dist/generators/ts/AbstractDeclaredType.d.ts +1 -1
  15. package/dist/generators/ts/ListType.d.ts +1 -1
  16. package/dist/generators/ts/ObjectType.d.ts +2 -1
  17. package/dist/generators/ts/TypeFactory.js +14 -1
  18. package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +1 -1
  19. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +1 -1
  20. package/dist/generators/ts/_ObjectUnionType/MemberType.d.ts +1 -1
  21. package/dist/input/NodeShape.d.ts +4 -2
  22. package/dist/input/NodeShape.js +5 -6
  23. package/dist/input/Ontology.d.ts +3 -2
  24. package/dist/input/Ontology.js +5 -6
  25. package/dist/input/PropertyShape.d.ts +1 -1
  26. package/package.json +4 -3
  27. package/dist/enums/index.d.ts +0 -5
  28. package/dist/enums/index.js +0 -5
  29. package/dist/generators/ts/stringToValidTsIdentifier.d.ts +0 -2
  30. package/dist/generators/ts/stringToValidTsIdentifier.js +0 -14
  31. package/dist/generators/ts/tsName.d.ts +0 -12
  32. package/dist/generators/ts/tsName.js +0 -34
  33. package/dist/input/tsFeatures.d.ts +0 -11
  34. package/dist/input/tsFeatures.js +0 -67
@@ -5,6 +5,7 @@ import { Either } from "purify-ts";
5
5
  import { CurieFactory } from "./_ShapesGraphToAstTransformer/CurieFactory.js";
6
6
  import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
7
7
  import type * as ast from "./ast/index.js";
8
+ import type { TsFeature } from "./enums/TsFeature.js";
8
9
  import type * as input from "./input/index.js";
9
10
  export declare class ShapesGraphToAstTransformer {
10
11
  protected readonly curieFactory: CurieFactory;
@@ -14,9 +15,11 @@ export declare class ShapesGraphToAstTransformer {
14
15
  protected transformNodeShapeToAstType: typeof _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
15
16
  protected transformPropertyShapeToAstObjectTypeProperty: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
16
17
  protected transformShapeToAstType: typeof _ShapesGraphToAstTransformer.transformShapeToAstType;
17
- constructor({ iriPrefixMap, shapesGraph, }: {
18
+ protected tsFeaturesDefault: ReadonlySet<TsFeature>;
19
+ constructor({ iriPrefixMap, shapesGraph, tsFeaturesDefault, }: {
18
20
  iriPrefixMap: PrefixMap;
19
21
  shapesGraph: input.ShapesGraph;
22
+ tsFeaturesDefault?: ReadonlySet<TsFeature>;
20
23
  });
21
24
  transform(): Either<Error, ast.Ast>;
22
25
  }
@@ -12,9 +12,13 @@ export class ShapesGraphToAstTransformer {
12
12
  transformNodeShapeToAstType = _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
13
13
  transformPropertyShapeToAstObjectTypeProperty = _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
14
14
  transformShapeToAstType = _ShapesGraphToAstTransformer.transformShapeToAstType;
15
- constructor({ iriPrefixMap, shapesGraph, }) {
15
+ tsFeaturesDefault;
16
+ constructor({ iriPrefixMap, shapesGraph, tsFeaturesDefault, }) {
16
17
  this.curieFactory = new CurieFactory({ prefixMap: iriPrefixMap });
17
18
  this.shapesGraph = shapesGraph;
19
+ this.tsFeaturesDefault =
20
+ tsFeaturesDefault ??
21
+ new Set(["create", "equals", "hash", "json", "rdf"]);
18
22
  }
19
23
  transform() {
20
24
  const nodeShapeAstObjectIntersectionTypes = [];
@@ -1,5 +1,6 @@
1
- import { Either, type Maybe } from "purify-ts";
2
- import type { TsFeature } from "../enums/TsFeature.js";
1
+ import { Either } from "purify-ts";
2
+ import { type TsFeature } from "../enums/TsFeature.js";
3
3
  import type * as input from "../input/index.js";
4
- export declare function nodeShapeTsFeatures(nodeShape: input.NodeShape): Either<Error, Maybe<ReadonlySet<TsFeature>>>;
4
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
+ export declare function nodeShapeTsFeatures(this: ShapesGraphToAstTransformer, nodeShape: input.NodeShape): Either<Error, ReadonlySet<TsFeature>>;
5
6
  //# sourceMappingURL=nodeShapeTsFeatures.d.ts.map
@@ -1,8 +1,63 @@
1
1
  import { Either } from "purify-ts";
2
+ import { TS_FEATURES } from "../enums/TsFeature.js";
2
3
  export function nodeShapeTsFeatures(nodeShape) {
3
- if (nodeShape.tsFeatures.isJust()) {
4
- return Either.of(nodeShape.tsFeatures);
4
+ const tsFeaturesDefault = this.tsFeaturesDefault;
5
+ function iriToTsFeatures(iri) {
6
+ switch (iri.value) {
7
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_All":
8
+ return TS_FEATURES;
9
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Create":
10
+ return ["create"];
11
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_Default":
12
+ return [...tsFeaturesDefault];
13
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Equals":
14
+ return ["equals"];
15
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Graphql":
16
+ return ["graphql"];
17
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Json":
18
+ return ["json"];
19
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Rdf":
20
+ return ["rdf"];
21
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Hash":
22
+ return ["hash"];
23
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_None":
24
+ return [];
25
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Sparql":
26
+ return ["sparql"];
27
+ }
5
28
  }
6
- return nodeShape.isDefinedBy.map((ontology) => ontology.chain((ontology) => ontology.tsFeatures));
29
+ return nodeShape.isDefinedBy.chain((ontologyMaybe) => {
30
+ let tsFeatureExcludes = nodeShape.tsFeatureExcludes.flatMap(iriToTsFeatures);
31
+ let tsFeatureIncludes = nodeShape.tsFeatureIncludes.flatMap(iriToTsFeatures);
32
+ if (tsFeatureExcludes.length === 0 && tsFeatureIncludes.length === 0) {
33
+ ontologyMaybe.ifJust((ontology) => {
34
+ tsFeatureExcludes = ontology.tsFeatureExcludes.flatMap(iriToTsFeatures);
35
+ tsFeatureIncludes = ontology.tsFeatureIncludes.flatMap(iriToTsFeatures);
36
+ });
37
+ }
38
+ const tsFeatures = new Set();
39
+ if (tsFeatureIncludes.length > 0) {
40
+ for (const tsFeatureInclude of tsFeatureIncludes) {
41
+ tsFeatures.add(tsFeatureInclude);
42
+ }
43
+ }
44
+ else {
45
+ for (const tsFeature of this.tsFeaturesDefault) {
46
+ tsFeatures.add(tsFeature);
47
+ }
48
+ }
49
+ for (const tsFeatureExclude of tsFeatureExcludes) {
50
+ tsFeatures.delete(tsFeatureExclude);
51
+ }
52
+ if (tsFeatures.size === 0) {
53
+ for (const tsFeature of tsFeaturesDefault) {
54
+ tsFeatures.add(tsFeature);
55
+ }
56
+ }
57
+ if (tsFeatures.has("graphql")) {
58
+ tsFeatures.add("rdf");
59
+ }
60
+ return Either.of(tsFeatures);
61
+ });
7
62
  }
8
63
  //# sourceMappingURL=nodeShapeTsFeatures.js.map
@@ -4,7 +4,6 @@ import { Either, Left, Maybe } from "purify-ts";
4
4
  import { invariant } from "ts-invariant";
5
5
  import * as ast from "../ast/index.js";
6
6
  import { Eithers } from "../Eithers.js";
7
- import { tsFeaturesDefault } from "../input/tsFeatures.js";
8
7
  import { nodeShapeIdentifierMintingStrategy } from "./nodeShapeIdentifierMintingStrategy.js";
9
8
  import { nodeShapeTsFeatures } from "./nodeShapeTsFeatures.js";
10
9
  import { shapeNodeKinds } from "./shapeNodeKinds.js";
@@ -157,7 +156,7 @@ function transformNodeShapeToAstListType(nodeShape) {
157
156
  });
158
157
  }
159
158
  export function transformNodeShapeToAstObjectCompoundType({ export_, nodeShape, }) {
160
- return Eithers.chain3(nodeShape.constraints.and, nodeShapeTsFeatures(nodeShape), nodeShape.constraints.xone).chain(([andShapes, tsFeatures, xoneShapes]) => {
159
+ return Eithers.chain3(nodeShape.constraints.and, nodeShapeTsFeatures.bind(this)(nodeShape), nodeShape.constraints.xone).chain(([andShapes, tsFeatures, xoneShapes]) => {
161
160
  let compoundTypeShapes;
162
161
  let compoundTypeKind;
163
162
  if (andShapes.length > 0) {
@@ -210,7 +209,7 @@ export function transformNodeShapeToAstType(nodeShape) {
210
209
  if (nodeShape.isList) {
211
210
  return transformNodeShapeToAstListType.bind(this)(nodeShape);
212
211
  }
213
- return Eithers.chain11(nodeShape.ancestorNodeShapes, nodeShape.childNodeShapes, nodeShape.descendantNodeShapes, nodeShape.parentNodeShapes, nodeShape.constraints.and, nodeShapeIdentifierMintingStrategy(nodeShape), shapeNodeKinds(nodeShape, { defaultNodeShapeNodeKinds }), nodeShape.constraints.properties, nodeShapeTsFeatures(nodeShape), nodeShape.tsObjectDeclarationType.isJust()
212
+ return Eithers.chain11(nodeShape.ancestorNodeShapes, nodeShape.childNodeShapes, nodeShape.descendantNodeShapes, nodeShape.parentNodeShapes, nodeShape.constraints.and, nodeShapeIdentifierMintingStrategy(nodeShape), shapeNodeKinds(nodeShape, { defaultNodeShapeNodeKinds }), nodeShape.constraints.properties, nodeShapeTsFeatures.bind(this)(nodeShape), nodeShape.tsObjectDeclarationType.isJust()
214
213
  ? Either.of(nodeShape.tsObjectDeclarationType)
215
214
  : nodeShape.isDefinedBy.map((ontology) => ontology.chain((ontology) => ontology.tsObjectDeclarationType)), nodeShape.constraints.xone).chain(([ancestorNodeShapes, childNodeShapes, descendantNodeShapes, parentNodeShapes, andShapes, identifierMintingStrategy, nodeKinds, propertyShapes, tsFeatures, tsObjectDeclarationType, xoneShapes,]) => {
216
215
  const abstract = nodeShape.abstract.orDefault(false);
@@ -293,7 +292,7 @@ export function transformNodeShapeToAstType(nodeShape) {
293
292
  shapeIdentifier: this.shapeIdentifier(nodeShape),
294
293
  synthetic: false,
295
294
  toRdfTypes,
296
- tsFeatures: tsFeatures.orDefault(new Set(tsFeaturesDefault)),
295
+ tsFeatures,
297
296
  tsImports: nodeShape.tsImports,
298
297
  tsObjectDeclarationType: tsObjectDeclarationType.orDefault("class"),
299
298
  });
@@ -104,7 +104,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
104
104
  export_: true,
105
105
  name: shape.shaclmateName,
106
106
  shapeIdentifier: this.shapeIdentifier(shape),
107
- tsFeatures: Maybe.empty(),
107
+ tsFeatures: this.tsFeaturesDefault,
108
108
  });
109
109
  for (const memberType of memberTypes) {
110
110
  const addMemberTypeResult = compoundType.addMemberType(memberType);
@@ -33,7 +33,7 @@ export declare abstract class AbstractObjectCompoundType<ObjectCompoundTypeT ext
33
33
  export_: boolean;
34
34
  name: Maybe<string>;
35
35
  shapeIdentifier: BlankNode | NamedNode;
36
- tsFeatures: Maybe<ReadonlySet<TsFeature>>;
36
+ tsFeatures: ReadonlySet<TsFeature>;
37
37
  } & ConstructorParameters<typeof AbstractCompoundType<ObjectCompoundTypeT | ObjectType>>[0]);
38
38
  equals(other: AbstractObjectCompoundType<ObjectCompoundTypeT>): boolean;
39
39
  get identifierType(): BlankNodeType | IdentifierType | IriType;
@@ -135,7 +135,7 @@ export class AbstractObjectCompoundType extends AbstractCompoundType {
135
135
  }
136
136
  }
137
137
  }
138
- return this.#tsFeatures.orDefault(mergedMemberTsFeatures);
138
+ return this.#tsFeatures;
139
139
  }
140
140
  addMemberType(memberType) {
141
141
  return Either.encase(() => {
@@ -1,7 +1,10 @@
1
1
  import type { BlankNode, NamedNode } from "@rdfjs/types";
2
2
  import type { Maybe } from "purify-ts";
3
3
  import { PropertyPath } from "rdfjs-resource";
4
- import type { IdentifierMintingStrategy, PropertyVisibility, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
4
+ import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
5
+ import type { PropertyVisibility } from "../enums/PropertyVisibility.js";
6
+ import type { TsFeature } from "../enums/TsFeature.js";
7
+ import type { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
5
8
  import { AbstractType } from "./AbstractType.js";
6
9
  import type { BlankNodeType } from "./BlankNodeType.js";
7
10
  import type { Curie } from "./Curie.js";
@@ -1,2 +1,3 @@
1
- export type TsFeature = "create" | "equals" | "graphql" | "hash" | "json" | "rdf" | "sparql";
1
+ export type TsFeature = (typeof TS_FEATURES)[number];
2
+ export declare const TS_FEATURES: readonly ["create", "equals", "graphql", "hash", "json", "rdf", "sparql"];
2
3
  //# sourceMappingURL=TsFeature.d.ts.map
@@ -1,2 +1,10 @@
1
- export {};
1
+ export const TS_FEATURES = [
2
+ "create",
3
+ "equals",
4
+ "graphql",
5
+ "hash",
6
+ "json",
7
+ "rdf",
8
+ "sparql",
9
+ ];
2
10
  //# sourceMappingURL=TsFeature.js.map
@@ -0,0 +1,6 @@
1
+ import * as ast from "../ast/index.js";
2
+ /**
3
+ * Code-safe name from an AST construct such as an ast.ObjectType.
4
+ */
5
+ export declare function codeName(sanitize: (unsanitized: string) => string, syntheticNamePrefix: string): (astConstruct: ast.ObjectType | ast.ObjectUnionType | ast.ObjectType.Property) => string;
6
+ //# sourceMappingURL=codeName.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { Resource } from "rdfjs-resource";
2
+ import * as ast from "../ast/index.js";
3
+ /**
4
+ * Code-safe name from an AST construct such as an ast.ObjectType.
5
+ */
6
+ export function codeName(sanitize, syntheticNamePrefix) {
7
+ return (astConstruct) => {
8
+ // The order of checks determines the order of preference.
9
+ // Explicit shaclmate:name or sh:name
10
+ const name = astConstruct.name.extract();
11
+ if (name) {
12
+ if (astConstruct instanceof ast.ObjectType && astConstruct.synthetic) {
13
+ return `${syntheticNamePrefix}${name}`;
14
+ }
15
+ return sanitize(name);
16
+ }
17
+ // Explicit rdfs:label
18
+ const label = astConstruct.label.extract();
19
+ if (label) {
20
+ return sanitize(label.replace(" ", "_"));
21
+ }
22
+ let propertyPath;
23
+ if (astConstruct instanceof ast.ObjectType.Property) {
24
+ // Pick up the common pattern of a property shape identifier being the node shape's identifier -localName,
25
+ // like ex:NodeShape-property
26
+ if (astConstruct.objectType.shapeIdentifier.termType === "NamedNode" &&
27
+ astConstruct.shapeIdentifier.termType === "NamedNode") {
28
+ const propertyShapeIdentifierPrefix = `${astConstruct.objectType.shapeIdentifier.value}-`;
29
+ if (astConstruct.shapeIdentifier.value.startsWith(propertyShapeIdentifierPrefix) &&
30
+ astConstruct.shapeIdentifier.value.length >
31
+ propertyShapeIdentifierPrefix.length) {
32
+ return sanitize(astConstruct.shapeIdentifier.value.substring(propertyShapeIdentifierPrefix.length));
33
+ }
34
+ }
35
+ propertyPath = astConstruct.path;
36
+ }
37
+ // Unique reference part on a CURIE sh:path
38
+ if (propertyPath instanceof ast.Curie && propertyPath.hasUniqueReference) {
39
+ return sanitize(propertyPath.reference);
40
+ }
41
+ const shapeIdentifier = astConstruct.shapeIdentifier;
42
+ // Unique reference part on a CURIE shape identifier
43
+ if (shapeIdentifier instanceof ast.Curie &&
44
+ shapeIdentifier.hasUniqueReference) {
45
+ return sanitize(shapeIdentifier.reference);
46
+ }
47
+ // CURIE sh:path
48
+ if (propertyPath instanceof ast.Curie) {
49
+ return sanitize(`${propertyPath.prefix}_${propertyPath.reference}`);
50
+ }
51
+ // CURIE shape identifier
52
+ if (shapeIdentifier instanceof ast.Curie) {
53
+ return sanitize(`${shapeIdentifier.prefix}_${shapeIdentifier.reference}`);
54
+ }
55
+ // IRI shape identifier
56
+ if (shapeIdentifier.termType === "NamedNode") {
57
+ return sanitize(shapeIdentifier.value);
58
+ }
59
+ // IRI sh:path
60
+ if (propertyPath?.termType === "NamedNode") {
61
+ return sanitize(propertyPath.value);
62
+ }
63
+ throw new Error(`should never reach this point (shapeIdentifier=${Resource.Identifier.toString(shapeIdentifier)})`);
64
+ };
65
+ }
66
+ //# sourceMappingURL=codeName.js.map
@@ -1,4 +1,4 @@
1
- import type { TsFeature } from "../../enums/index.js";
1
+ import type { TsFeature } from "../../enums/TsFeature.js";
2
2
  import { AbstractType } from "./AbstractType.js";
3
3
  import type { Code } from "./ts-poet-wrapper.js";
4
4
  export declare abstract class AbstractDeclaredType extends AbstractType {
@@ -1,6 +1,6 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import type { Maybe } from "purify-ts";
3
- import type { IdentifierMintingStrategy } from "../../enums/index.js";
3
+ import type { IdentifierMintingStrategy } from "../../enums/IdentifierMintingStrategy.js";
4
4
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
5
5
  import type { BigDecimalType } from "./BigDecimalType.js";
6
6
  import type { BigIntType } from "./BigIntType.js";
@@ -1,6 +1,7 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe, NonEmptyList } from "purify-ts";
3
- import type { IdentifierMintingStrategy, TsObjectDeclarationType } from "../../enums/index.js";
3
+ import type { IdentifierMintingStrategy } from "../../enums/IdentifierMintingStrategy.js";
4
+ import type { TsObjectDeclarationType } from "../../enums/TsObjectDeclarationType.js";
4
5
  import { IdentifierPrefixProperty as _IdentifierPrefixProperty } from "./_ObjectType/IdentifierPrefixProperty.js";
5
6
  import { IdentifierProperty as _IdentifierProperty } from "./_ObjectType/IdentifierProperty.js";
6
7
  import type { Property as _Property } from "./_ObjectType/Property.js";
@@ -1,9 +1,12 @@
1
1
  import TermMap from "@rdfjs/term-map";
2
2
  import TermSet from "@rdfjs/term-set";
3
+ import base62 from "@sindresorhus/base62";
3
4
  import { rdf, xsd } from "@tpluscode/rdf-ns-builders";
4
5
  import { LiteralDecoder, literalDatatypeDefinitions } from "rdfjs-resource";
6
+ import reservedTsIdentifiers_ from "reserved-identifiers";
5
7
  import { invariant } from "ts-invariant";
6
8
  import { logger } from "../../logger.js";
9
+ import { codeName } from "../codeName.js";
7
10
  import { BigDecimalType } from "./BigDecimalType.js";
8
11
  import { BigIntType } from "./BigIntType.js";
9
12
  import { BlankNodeType } from "./BlankNodeType.js";
@@ -28,8 +31,18 @@ import { StringType } from "./StringType.js";
28
31
  import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
29
32
  import { TermType } from "./TermType.js";
30
33
  import { code } from "./ts-poet-wrapper.js";
31
- import { tsName } from "./tsName.js";
32
34
  import { UnionType } from "./UnionType.js";
35
+ const reservedTsIdentifiers = reservedTsIdentifiers_({
36
+ includeGlobalProperties: true,
37
+ });
38
+ const tsName = codeName((value) => {
39
+ // Adapted from https://github.com/sindresorhus/to-valid-identifier , MIT license
40
+ if (reservedTsIdentifiers.has(value)) {
41
+ // We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
42
+ return `$_${value}$`;
43
+ }
44
+ return value.replaceAll(/\P{ID_Continue}/gu, (x) => `$${base62.encodeInteger(x.codePointAt(0))}$`);
45
+ }, syntheticNamePrefix);
33
46
  export class TypeFactory {
34
47
  cachedObjectTypePropertiesByShapeIdentifier = new TermMap();
35
48
  cachedObjectTypesByShapeIdentifier = new TermMap();
@@ -1,5 +1,5 @@
1
1
  import type { Maybe } from "purify-ts";
2
- import type { PropertyVisibility } from "../../../enums/index.js";
2
+ import type { PropertyVisibility } from "../../../enums/PropertyVisibility.js";
3
3
  import type { ObjectType } from "../ObjectType.js";
4
4
  import type { Type } from "../Type.js";
5
5
  import { type Code } from "../ts-poet-wrapper.js";
@@ -1,5 +1,5 @@
1
1
  import { Maybe } from "purify-ts";
2
- import type { IdentifierMintingStrategy } from "../../../enums/index.js";
2
+ import type { IdentifierMintingStrategy } from "../../../enums/IdentifierMintingStrategy.js";
3
3
  import type { BlankNodeType } from "../BlankNodeType.js";
4
4
  import type { IdentifierType } from "../IdentifierType.js";
5
5
  import type { IriType } from "../IriType.js";
@@ -13,7 +13,7 @@ export declare class MemberType {
13
13
  get declarationType(): import("../../../enums/TsObjectDeclarationType.js").TsObjectDeclarationType;
14
14
  get descendantFromRdfTypeVariables(): readonly import("ts-poet").Code[];
15
15
  get discriminantPropertyValues(): readonly string[];
16
- get features(): ReadonlySet<import("../../../enums/TsFeature.js").TsFeature>;
16
+ get features(): ReadonlySet<"create" | "equals" | "graphql" | "hash" | "json" | "rdf" | "sparql">;
17
17
  get filterFunction(): import("ts-poet").Code;
18
18
  get filterType(): import("ts-poet").Code;
19
19
  get fromRdfType(): import("purify-ts").Maybe<import("@rdfjs/types").NamedNode<string>>;
@@ -1,7 +1,8 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { NodeShape as ShaclCoreNodeShape } from "@shaclmate/shacl-ast";
3
3
  import { Either, type Maybe } from "purify-ts";
4
- import type { IdentifierMintingStrategy, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
4
+ import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
5
+ import type { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
5
6
  import type * as generated from "./generated.js";
6
7
  import type { Ontology, PropertyGroup, PropertyShape, ShapesGraph } from "./index.js";
7
8
  import type { Shape } from "./Shape.js";
@@ -41,7 +42,8 @@ export declare class NodeShape extends ShaclCoreNodeShape<any, Ontology, Propert
41
42
  get rdfType(): Maybe<NamedNode>;
42
43
  get shaclmateName(): Maybe<string>;
43
44
  get toRdfTypes(): readonly NamedNode[];
44
- get tsFeatures(): Maybe<ReadonlySet<TsFeature>>;
45
+ get tsFeatureExcludes(): readonly NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
46
+ get tsFeatureIncludes(): readonly NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
45
47
  get tsImports(): readonly string[];
46
48
  get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
47
49
  }
@@ -9,7 +9,6 @@ import { rdf } from "@tpluscode/rdf-ns-builders";
9
9
  import { Either, List } from "purify-ts";
10
10
  import { invariant } from "ts-invariant";
11
11
  import { Memoize } from "typescript-memoize";
12
- import { tsFeatures } from "./tsFeatures.js";
13
12
  export class NodeShape extends ShaclCoreNodeShape {
14
13
  ancestorClassIris;
15
14
  childClassIris;
@@ -103,8 +102,11 @@ export class NodeShape extends ShaclCoreNodeShape {
103
102
  get toRdfTypes() {
104
103
  return this.generatedShaclmateNodeShape.toRdfTypes;
105
104
  }
106
- get tsFeatures() {
107
- return tsFeatures(this.generatedShaclmateNodeShape);
105
+ get tsFeatureExcludes() {
106
+ return this.generatedShaclmateNodeShape.tsFeatureExcludes;
107
+ }
108
+ get tsFeatureIncludes() {
109
+ return this.generatedShaclmateNodeShape.tsFeatureIncludes;
108
110
  }
109
111
  get tsImports() {
110
112
  return this.generatedShaclmateNodeShape.tsImports;
@@ -149,9 +151,6 @@ __decorate([
149
151
  __decorate([
150
152
  Memoize()
151
153
  ], NodeShape.prototype, "rdfType", null);
152
- __decorate([
153
- Memoize()
154
- ], NodeShape.prototype, "tsFeatures", null);
155
154
  __decorate([
156
155
  Memoize()
157
156
  ], NodeShape.prototype, "tsObjectDeclarationType", null);
@@ -1,11 +1,12 @@
1
1
  import { Ontology as OwlOntology } from "@shaclmate/shacl-ast";
2
2
  import type { Maybe } from "purify-ts";
3
- import type { TsFeature, TsObjectDeclarationType } from "../enums/index.js";
3
+ import type { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
4
4
  import type * as generated from "./generated.js";
5
5
  export declare class Ontology extends OwlOntology {
6
6
  private readonly generatedShaclmateOntology;
7
7
  constructor(generatedShaclmateOntology: generated.ShaclmateOntology);
8
- get tsFeatures(): Maybe<ReadonlySet<TsFeature>>;
8
+ get tsFeatureExcludes(): readonly import("@rdfjs/types").NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
9
+ get tsFeatureIncludes(): readonly import("@rdfjs/types").NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
9
10
  get tsImports(): readonly string[];
10
11
  get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
11
12
  }
@@ -6,15 +6,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Ontology as OwlOntology } from "@shaclmate/shacl-ast";
8
8
  import { Memoize } from "typescript-memoize";
9
- import { tsFeatures } from "./tsFeatures.js";
10
9
  export class Ontology extends OwlOntology {
11
10
  generatedShaclmateOntology;
12
11
  constructor(generatedShaclmateOntology) {
13
12
  super(generatedShaclmateOntology);
14
13
  this.generatedShaclmateOntology = generatedShaclmateOntology;
15
14
  }
16
- get tsFeatures() {
17
- return tsFeatures(this.generatedShaclmateOntology);
15
+ get tsFeatureExcludes() {
16
+ return this.generatedShaclmateOntology.tsFeatureExcludes;
17
+ }
18
+ get tsFeatureIncludes() {
19
+ return this.generatedShaclmateOntology.tsFeatureIncludes;
18
20
  }
19
21
  get tsImports() {
20
22
  return this.generatedShaclmateOntology.tsImports;
@@ -32,9 +34,6 @@ export class Ontology extends OwlOntology {
32
34
  });
33
35
  }
34
36
  }
35
- __decorate([
36
- Memoize()
37
- ], Ontology.prototype, "tsFeatures", null);
38
37
  __decorate([
39
38
  Memoize()
40
39
  ], Ontology.prototype, "tsObjectDeclarationType", null);
@@ -1,6 +1,6 @@
1
1
  import { PropertyShape as ShaclCorePropertyShape } from "@shaclmate/shacl-ast";
2
2
  import { Either, Maybe } from "purify-ts";
3
- import type { PropertyVisibility } from "../enums/index.js";
3
+ import type { PropertyVisibility } from "../enums/PropertyVisibility.js";
4
4
  import type * as generated from "./generated.js";
5
5
  import type { NodeShape, Ontology, PropertyGroup, ShapesGraph } from "./index.js";
6
6
  import type { Shape } from "./Shape.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.2",
3
+ "@shaclmate/shacl-ast": "4.0.4",
4
4
  "@rdfjs/data-model": "~2.1.1",
5
5
  "@rdfjs/dataset": "~2.0.2",
6
6
  "@rdfjs/prefix-map": "~0.1.2",
@@ -63,7 +63,7 @@
63
63
  "license": "Apache-2.0",
64
64
  "main": "./dist/index.js",
65
65
  "name": "@shaclmate/compiler",
66
- "packageManager": "npm@10.9.0",
66
+ "packageManager": "npm@11.11.0",
67
67
  "repository": {
68
68
  "type": "git",
69
69
  "url": "git+https://github.com/minorg/shaclmate.git"
@@ -74,10 +74,11 @@
74
74
  "depcheck": "depcheck .",
75
75
  "dev": "tsc -w --preserveWatchOutput",
76
76
  "dev:tests": "tsc -p __tests__ -w --preserveWatchOutput",
77
+ "test": "cd ../.. && vitest run --project @shaclmate/compiler",
77
78
  "typecheck": "tsc --noEmit",
78
79
  "typecheck:watch": "tsc --noEmit -w --preserveWatchOutput"
79
80
  },
80
81
  "type": "module",
81
82
  "types": "./dist/index.d.ts",
82
- "version": "4.0.2"
83
+ "version": "4.0.4"
83
84
  }
@@ -1,5 +0,0 @@
1
- export * from "./IdentifierMintingStrategy.js";
2
- export * from "./PropertyVisibility.js";
3
- export * from "./TsFeature.js";
4
- export * from "./TsObjectDeclarationType.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- export * from "./IdentifierMintingStrategy.js";
2
- export * from "./PropertyVisibility.js";
3
- export * from "./TsFeature.js";
4
- export * from "./TsObjectDeclarationType.js";
5
- //# sourceMappingURL=index.js.map
@@ -1,2 +0,0 @@
1
- export declare function stringToValidTsIdentifier(value: string): string;
2
- //# sourceMappingURL=stringToValidTsIdentifier.d.ts.map
@@ -1,14 +0,0 @@
1
- import base62 from "@sindresorhus/base62";
2
- import reservedTsIdentifiers_ from "reserved-identifiers";
3
- const reservedTsIdentifiers = reservedTsIdentifiers_({
4
- includeGlobalProperties: true,
5
- });
6
- // Adapted from https://github.com/sindresorhus/to-valid-identifier , MIT license
7
- export function stringToValidTsIdentifier(value) {
8
- if (reservedTsIdentifiers.has(value)) {
9
- // We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
10
- return `$_${value}$`;
11
- }
12
- return value.replaceAll(/\P{ID_Continue}/gu, (x) => `$${base62.encodeInteger(x.codePointAt(0))}$`);
13
- }
14
- //# sourceMappingURL=stringToValidTsIdentifier.js.map
@@ -1,12 +0,0 @@
1
- import type { BlankNode, NamedNode } from "@rdfjs/types";
2
- import type { Maybe } from "purify-ts";
3
- import { type PropertyPath } from "rdfjs-resource";
4
- import * as ast from "../../ast/index.js";
5
- export declare function tsName(astConstruct: {
6
- label: Maybe<string>;
7
- name: Maybe<string>;
8
- path?: ast.Curie | PropertyPath;
9
- synthetic?: boolean;
10
- shapeIdentifier: BlankNode | NamedNode;
11
- }): string;
12
- //# sourceMappingURL=tsName.d.ts.map
@@ -1,34 +0,0 @@
1
- import { Resource } from "rdfjs-resource";
2
- import * as ast from "../../ast/index.js";
3
- import { stringToValidTsIdentifier } from "./stringToValidTsIdentifier.js";
4
- import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
5
- export function tsName(astConstruct) {
6
- const name = astConstruct.name.extract();
7
- if (name) {
8
- if (astConstruct.synthetic) {
9
- return `${syntheticNamePrefix}${name}`;
10
- }
11
- return stringToValidTsIdentifier(name);
12
- }
13
- const label = astConstruct.label.extract();
14
- if (label) {
15
- return stringToValidTsIdentifier(label.replace(" ", "_"));
16
- }
17
- const path = astConstruct.path;
18
- if (path instanceof ast.Curie) {
19
- if (path.hasUniqueReference) {
20
- return stringToValidTsIdentifier(path.reference);
21
- }
22
- return stringToValidTsIdentifier(`${path.prefix}_${path.reference}`);
23
- }
24
- const shapeIdentifier = astConstruct.shapeIdentifier;
25
- if (shapeIdentifier.termType === "NamedNode" &&
26
- shapeIdentifier instanceof ast.Curie) {
27
- if (shapeIdentifier.hasUniqueReference) {
28
- return stringToValidTsIdentifier(shapeIdentifier.reference);
29
- }
30
- return stringToValidTsIdentifier(`${shapeIdentifier.prefix}_${shapeIdentifier.reference}`);
31
- }
32
- throw new Error(`should never reach this point (shapeIdentifier=${Resource.Identifier.toString(shapeIdentifier)})`);
33
- }
34
- //# sourceMappingURL=tsName.js.map
@@ -1,11 +0,0 @@
1
- import type * as rdfjs from "@rdfjs/types";
2
- import { Maybe } from "purify-ts";
3
- import type { TsFeature } from "../enums/index.js";
4
- type TsFeatureIri = rdfjs.NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">;
5
- export declare function tsFeatures(generated: {
6
- readonly tsFeatureExcludes: readonly TsFeatureIri[];
7
- readonly tsFeatureIncludes: readonly TsFeatureIri[];
8
- }): Maybe<ReadonlySet<TsFeature>>;
9
- export declare const tsFeaturesDefault: readonly TsFeature[];
10
- export {};
11
- //# sourceMappingURL=tsFeatures.d.ts.map
@@ -1,67 +0,0 @@
1
- import { Maybe } from "purify-ts";
2
- function iriToTsFeatures(iri) {
3
- switch (iri.value) {
4
- case "http://purl.org/shaclmate/ontology#_TsFeatures_All":
5
- return tsFeaturesAll;
6
- case "http://purl.org/shaclmate/ontology#_TsFeature_Create":
7
- return ["create"];
8
- case "http://purl.org/shaclmate/ontology#_TsFeatures_Default":
9
- return tsFeaturesDefault;
10
- case "http://purl.org/shaclmate/ontology#_TsFeature_Equals":
11
- return ["equals"];
12
- case "http://purl.org/shaclmate/ontology#_TsFeature_Graphql":
13
- return ["graphql"];
14
- case "http://purl.org/shaclmate/ontology#_TsFeature_Json":
15
- return ["json"];
16
- case "http://purl.org/shaclmate/ontology#_TsFeature_Rdf":
17
- return ["rdf"];
18
- case "http://purl.org/shaclmate/ontology#_TsFeature_Hash":
19
- return ["hash"];
20
- case "http://purl.org/shaclmate/ontology#_TsFeatures_None":
21
- return [];
22
- case "http://purl.org/shaclmate/ontology#_TsFeature_Sparql":
23
- return ["sparql"];
24
- }
25
- }
26
- export function tsFeatures(generated) {
27
- const tsFeatureIncludes = generated.tsFeatureIncludes.flatMap(iriToTsFeatures);
28
- const tsFeatureExcludes = generated.tsFeatureExcludes.flatMap(iriToTsFeatures);
29
- if (tsFeatureExcludes.length === 0 && tsFeatureIncludes.length === 0) {
30
- return Maybe.empty();
31
- }
32
- const tsFeatures = new Set();
33
- if (tsFeatureIncludes.length > 0) {
34
- for (const tsFeatureInclude of tsFeatureIncludes) {
35
- tsFeatures.add(tsFeatureInclude);
36
- }
37
- }
38
- else {
39
- for (const tsFeature of tsFeaturesDefault) {
40
- tsFeatures.add(tsFeature);
41
- }
42
- }
43
- for (const tsFeatureExclude of tsFeatureExcludes) {
44
- tsFeatures.delete(tsFeatureExclude);
45
- }
46
- if (tsFeatures.has("graphql")) {
47
- tsFeatures.add("rdf");
48
- }
49
- return Maybe.of(tsFeatures);
50
- }
51
- const tsFeaturesAll = [
52
- "create",
53
- "equals",
54
- "graphql",
55
- "hash",
56
- "json",
57
- "rdf",
58
- "sparql",
59
- ];
60
- export const tsFeaturesDefault = [
61
- "create",
62
- "equals",
63
- "hash",
64
- "json",
65
- "rdf",
66
- ];
67
- //# sourceMappingURL=tsFeatures.js.map