@shaclmate/compiler 4.0.23 → 4.0.25

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 (117) hide show
  1. package/dist/Compiler.d.ts +1 -1
  2. package/dist/ShapesGraphToAstTransformer.d.ts +1 -1
  3. package/dist/ShapesGraphToAstTransformer.js +16 -16
  4. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +1 -1
  5. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +5 -2
  6. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -5
  7. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +1 -1
  8. package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +4 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +11 -17
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +3 -3
  11. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +6 -11
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +21 -40
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
  15. package/dist/ast/AbstractCompoundType.d.ts +1 -1
  16. package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
  17. package/dist/ast/ListType.d.ts +1 -8
  18. package/dist/ast/ListType.js +1 -6
  19. package/dist/ast/ObjectType.d.ts +3 -30
  20. package/dist/ast/ObjectType.js +2 -26
  21. package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
  22. package/dist/generators/ts/AbstractContainerType.js +0 -1
  23. package/dist/generators/ts/AbstractLazyObjectType.d.ts +0 -1
  24. package/dist/generators/ts/AbstractLazyObjectType.js +2 -2
  25. package/dist/generators/ts/AbstractNamedUnionType.d.ts +1 -2
  26. package/dist/generators/ts/AbstractNamedUnionType.js +16 -19
  27. package/dist/generators/ts/AbstractTermType.d.ts +0 -1
  28. package/dist/generators/ts/AbstractTermType.js +0 -1
  29. package/dist/generators/ts/AbstractType.d.ts +0 -4
  30. package/dist/generators/ts/AbstractUnionType.d.ts +1 -10
  31. package/dist/generators/ts/AbstractUnionType.js +27 -40
  32. package/dist/generators/ts/LazyObjectOptionType.js +3 -2
  33. package/dist/generators/ts/LazyObjectSetType.js +2 -1
  34. package/dist/generators/ts/LazyObjectType.js +2 -1
  35. package/dist/generators/ts/ListType.d.ts +1 -5
  36. package/dist/generators/ts/ListType.js +8 -27
  37. package/dist/generators/ts/NamedObjectType.d.ts +2 -21
  38. package/dist/generators/ts/NamedObjectType.js +33 -132
  39. package/dist/generators/ts/NamedObjectUnionType.js +14 -25
  40. package/dist/generators/ts/TypeFactory.js +11 -67
  41. package/dist/generators/ts/ZodGenerator.js +2 -2
  42. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +11 -17
  43. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +7 -6
  44. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +1 -4
  45. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +19 -34
  46. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +5 -15
  47. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +31 -212
  48. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +2 -2
  49. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +5 -0
  50. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +25 -0
  51. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js +4 -4
  52. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.js +1 -1
  53. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +2 -2
  54. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +2 -2
  55. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -8
  56. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +5 -13
  57. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -4
  58. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +4 -0
  59. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +49 -0
  60. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +1 -1
  61. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +0 -3
  62. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
  63. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +2 -2
  64. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +2 -2
  65. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js +2 -2
  66. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
  67. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +2 -2
  68. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +1 -2
  69. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +2 -2
  70. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
  71. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +2 -2
  72. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +5 -0
  73. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +41 -0
  74. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
  75. package/dist/generators/ts/_NamedObjectType/{NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js → NamedObjectType_toRdfResourceFunctionDeclaration.js} +8 -27
  76. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +4 -0
  77. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +40 -0
  78. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
  79. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
  80. package/dist/generators/ts/_NamedObjectType/Property.d.ts +1 -2
  81. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -3
  82. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +8 -39
  83. package/dist/generators/ts/_snippets/snippets_LazyObject.js +2 -2
  84. package/dist/generators/ts/_snippets/snippets_LazyObjectOption.js +2 -2
  85. package/dist/generators/ts/_snippets/snippets_LazyObjectSet.js +2 -2
  86. package/dist/generators/ts/imports.d.ts +0 -2
  87. package/dist/generators/ts/imports.js +0 -2
  88. package/dist/generators/ts/objectSetDeclarations.js +1 -3
  89. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +4 -6
  90. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +2 -2
  91. package/dist/input/ShapesGraph.d.ts +1 -1
  92. package/dist/input/generated.d.ts +10 -181
  93. package/dist/input/generated.js +116 -392
  94. package/package.json +2 -4
  95. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +0 -6
  96. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +0 -32
  97. package/dist/enums/IdentifierMintingStrategy.d.ts +0 -9
  98. package/dist/enums/IdentifierMintingStrategy.js +0 -18
  99. package/dist/enums/TsObjectDeclarationType.d.ts +0 -9
  100. package/dist/enums/TsObjectDeclarationType.js +0 -16
  101. package/dist/enums/Visibility.d.ts +0 -6
  102. package/dist/enums/Visibility.js +0 -18
  103. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.d.ts +0 -33
  104. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.js +0 -92
  105. package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.d.ts +0 -4
  106. package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +0 -62
  107. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.d.ts +0 -5
  108. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +0 -51
  109. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.d.ts +0 -4
  110. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +0 -73
  111. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.d.ts +0 -5
  112. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js +0 -59
  113. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +0 -5
  114. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.d.ts +0 -4
  115. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +0 -62
  116. /package/dist/{enums → generators/ts}/TsFeature.d.ts +0 -0
  117. /package/dist/{enums → generators/ts}/TsFeature.js +0 -0
@@ -1,6 +1,5 @@
1
1
  import type { Maybe } from "purify-ts";
2
2
  import type { Logger } from "ts-log";
3
- import type { Visibility } from "../../../enums/Visibility.js";
4
3
  import type { NamedObjectType } from "../NamedObjectType.js";
5
4
  import type { Type } from "../Type.js";
6
5
  import { type Code } from "../ts-poet-wrapper.js";
@@ -12,13 +11,9 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
12
11
  */
13
12
  abstract readonly constructorParametersSignature: Maybe<Code>;
14
13
  /**
15
- * Optional property declaration to include in a class or interface declaration of the object type.
14
+ * Property declaration to include in a class or interface declaration of the object type.
16
15
  */
17
- abstract readonly declaration: Maybe<Code>;
18
- /**
19
- * Function declaration that takes two values of the property and compares them, returning an $EqualsResult.
20
- */
21
- abstract readonly equalsFunction: Maybe<Code>;
16
+ abstract readonly declaration: Code;
22
17
  /**
23
18
  * Optional property in the object type's filter.
24
19
  */
@@ -26,10 +21,6 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
26
21
  readonly name: string;
27
22
  readonly type: Code;
28
23
  }>;
29
- /**
30
- * Optional get accessor to include in a class declaration of the object type.
31
- */
32
- abstract readonly getAccessorDeclaration: Maybe<Code>;
33
24
  /**
34
25
  * GraphQL.js field definition.
35
26
  */
@@ -73,16 +64,11 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
73
64
  * Property type
74
65
  . */
75
66
  readonly type: TypeT;
76
- /**
77
- * Property visibility: private, protected, public.
78
- */
79
- readonly visibility: Visibility;
80
- constructor({ logger, name, namedObjectType, type, visibility, }: {
67
+ constructor({ logger, name, namedObjectType, type, }: {
81
68
  logger: Logger;
82
69
  name: string;
83
70
  namedObjectType: NamedObjectType;
84
71
  type: TypeT;
85
- visibility: Visibility;
86
72
  });
87
73
  /**
88
74
  * TypeScript object describing this type, for runtime use.
@@ -92,6 +78,14 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
92
78
  kind: Code;
93
79
  type: Code;
94
80
  };
81
+ /**
82
+ * Expression to access the value of this property on an object instance. May evaluate a thunk.
83
+ */
84
+ accessExpression({ variables }: {
85
+ variables: {
86
+ object: Code;
87
+ };
88
+ }): Code;
95
89
  /**
96
90
  * Statements to assign the parameter of described by constructorParametersSignature to a class or interface member.
97
91
  */
@@ -19,16 +19,11 @@ export class AbstractProperty {
19
19
  * Property type
20
20
  . */
21
21
  type;
22
- /**
23
- * Property visibility: private, protected, public.
24
- */
25
- visibility;
26
- constructor({ logger, name, namedObjectType, type, visibility, }) {
22
+ constructor({ logger, name, namedObjectType, type, }) {
27
23
  this.logger = logger;
28
24
  this.name = name;
29
25
  this.namedObjectType = namedObjectType;
30
26
  this.type = type;
31
- this.visibility = visibility;
32
27
  }
33
28
  /**
34
29
  * TypeScript object describing this type, for runtime use.
@@ -44,6 +39,12 @@ export class AbstractProperty {
44
39
  type: code `() => (${this.type.schema})`,
45
40
  };
46
41
  }
42
+ /**
43
+ * Expression to access the value of this property on an object instance. May evaluate a thunk.
44
+ */
45
+ accessExpression({ variables }) {
46
+ return code `${variables.object}.${this.name}`;
47
+ }
47
48
  }
48
49
  __decorate([
49
50
  Memoize()
@@ -3,9 +3,7 @@ import { type Code } from "../ts-poet-wrapper.js";
3
3
  import { AbstractProperty } from "./AbstractProperty.js";
4
4
  export declare class DiscriminantProperty extends AbstractProperty<DiscriminantProperty.Type> {
5
5
  readonly constructorParametersSignature: Maybe<Code>;
6
- readonly equalsFunction: Maybe<Code>;
7
6
  readonly filterProperty: AbstractProperty<DiscriminantProperty.Type>["filterProperty"];
8
- readonly getAccessorDeclaration: Maybe<Code>;
9
7
  readonly graphqlField: AbstractProperty<DiscriminantProperty.Type>["graphqlField"];
10
8
  readonly kind = "DiscriminantProperty";
11
9
  readonly mutable = false;
@@ -13,10 +11,9 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
13
11
  constructor({ type, ...superParameters }: {
14
12
  type: DiscriminantProperty.Type;
15
13
  } & ConstructorParameters<typeof AbstractProperty>[0]);
16
- get declaration(): Maybe<Code>;
14
+ get declaration(): Code;
17
15
  get jsonSchema(): AbstractProperty<DiscriminantProperty.Type>["jsonSchema"];
18
16
  get jsonSignature(): Maybe<Code>;
19
- private get abstract();
20
17
  private get initializer();
21
18
  private get override();
22
19
  constructorStatements(): readonly Code[];
@@ -5,38 +5,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Maybe } from "purify-ts";
8
- import { invariant } from "ts-invariant";
9
8
  import { Memoize } from "typescript-memoize";
10
9
  import { imports } from "../imports.js";
11
10
  import { removeUndefined } from "../removeUndefined.js";
12
- import { snippets } from "../snippets.js";
13
11
  import { arrayOf, code, literalOf } from "../ts-poet-wrapper.js";
14
12
  import { AbstractProperty } from "./AbstractProperty.js";
15
13
  export class DiscriminantProperty extends AbstractProperty {
16
14
  constructorParametersSignature = Maybe.empty();
17
- equalsFunction = Maybe.of(code `${snippets.strictEquals}`);
18
15
  filterProperty = Maybe.empty();
19
- getAccessorDeclaration = Maybe.empty();
20
16
  graphqlField = Maybe.empty();
21
17
  kind = "DiscriminantProperty";
22
18
  mutable = false;
23
19
  recursive = false;
24
20
  constructor({ type, ...superParameters }) {
25
21
  super({ ...superParameters, type });
26
- invariant(this.visibility === "public");
27
22
  }
28
23
  get declaration() {
29
- switch (this.namedObjectType.declarationType) {
30
- case "class":
31
- return Maybe.of(code `${this.abstract ? "abstract " : ""}${this.override ? "override " : ""}readonly ${this.name}: ${this.type.name}${!this.abstract ? code ` = ${this.initializer};` : ";"}`);
32
- case "interface":
33
- return Maybe.of(code `readonly ${this.name}: ${this.type.name};`);
34
- default:
35
- this.namedObjectType.declarationType;
36
- throw new Error("should never reach this point");
37
- }
24
+ return code `readonly ${this.name}: ${this.type.name};`;
38
25
  }
39
26
  get jsonSchema() {
27
+ if (this.override) {
28
+ return Maybe.empty();
29
+ }
40
30
  return Maybe.of({
41
31
  key: this.name,
42
32
  schema: this.type.values.length > 1
@@ -45,11 +35,11 @@ export class DiscriminantProperty extends AbstractProperty {
45
35
  });
46
36
  }
47
37
  get jsonSignature() {
38
+ if (this.override) {
39
+ return Maybe.empty();
40
+ }
48
41
  return Maybe.of(code `readonly ${this.name}: ${this.type.name}`);
49
42
  }
50
- get abstract() {
51
- return this.namedObjectType.abstract;
52
- }
53
43
  get initializer() {
54
44
  return code `${literalOf(this.namedObjectType.discriminantValue)} as const`;
55
45
  }
@@ -57,32 +47,24 @@ export class DiscriminantProperty extends AbstractProperty {
57
47
  return this.namedObjectType.parentObjectTypes.length > 0;
58
48
  }
59
49
  constructorStatements() {
60
- switch (this.namedObjectType.declarationType) {
61
- case "class":
62
- return [];
63
- case "interface":
64
- if (this.abstract) {
65
- return [];
66
- }
67
- return [code `const ${this.name} = ${this.initializer};`];
68
- }
50
+ return [code `const ${this.name} = ${this.initializer};`];
69
51
  }
70
52
  fromJsonStatements() {
71
- return !this.abstract &&
72
- this.namedObjectType.declarationType === "interface"
73
- ? [code `const ${this.name} = ${this.initializer};`]
74
- : [];
53
+ return [code `const ${this.name} = ${this.initializer};`];
75
54
  }
76
55
  fromRdfResourceValuesExpression() {
77
- return !this.abstract &&
78
- this.namedObjectType.declarationType === "interface"
79
- ? Maybe.of(code `${imports.Right}<${literalOf(this.namedObjectType.discriminantValue)}>(${this.initializer})`)
80
- : Maybe.empty();
56
+ return Maybe.of(code `${imports.Right}<${literalOf(this.namedObjectType.discriminantValue)}>(${this.initializer})`);
81
57
  }
82
58
  hashStatements({ variables, }) {
59
+ if (this.override) {
60
+ return [];
61
+ }
83
62
  return [code `${variables.hasher}.update(${variables.value});`];
84
63
  }
85
64
  jsonUiSchemaElement({ variables, }) {
65
+ if (this.override) {
66
+ return Maybe.empty();
67
+ }
86
68
  const scope = code `\`\${${variables.scopePrefix}}/properties/${this.name}\``;
87
69
  return Maybe.of(code `{ rule: { condition: { schema: { const: ${this.initializer} }, scope: ${scope} }, effect: "HIDE" }, scope: ${scope}, type: "Control" }`);
88
70
  }
@@ -93,6 +75,9 @@ export class DiscriminantProperty extends AbstractProperty {
93
75
  return Maybe.empty();
94
76
  }
95
77
  toJsonObjectMemberExpression({ variables, }) {
78
+ if (this.override) {
79
+ return Maybe.empty();
80
+ }
96
81
  return Maybe.of(code `${this.name}: ${variables.value}`);
97
82
  }
98
83
  toRdfRdfResourceValuesStatements() {
@@ -1,41 +1,30 @@
1
1
  import { Maybe } from "purify-ts";
2
- import type { IdentifierMintingStrategy } from "../../../enums/IdentifierMintingStrategy.js";
3
2
  import type { BlankNodeType } from "../BlankNodeType.js";
4
3
  import type { IdentifierType } from "../IdentifierType.js";
5
4
  import type { IriType } from "../IriType.js";
6
5
  import { type Code } from "../ts-poet-wrapper.js";
7
6
  import { AbstractProperty } from "./AbstractProperty.js";
8
7
  export declare class IdentifierProperty extends AbstractProperty<BlankNodeType | IdentifierType | IriType> {
9
- private readonly identifierMintingStrategy;
10
- private readonly identifierPrefixPropertyName;
11
8
  private readonly typeAlias;
12
9
  readonly kind = "IdentifierProperty";
13
10
  readonly mutable = false;
14
11
  readonly recursive = false;
15
- constructor({ identifierMintingStrategy, identifierPrefixPropertyName, typeAlias, ...superParameters }: {
16
- identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
17
- identifierPrefixPropertyName: string;
12
+ constructor({ typeAlias, ...superParameters }: {
18
13
  type: BlankNodeType | IdentifierType | IriType;
19
14
  typeAlias: Code;
20
15
  } & ConstructorParameters<typeof AbstractProperty>[0]);
21
16
  get constructorParametersSignature(): Maybe<Code>;
22
- get declaration(): Maybe<Code>;
23
- get equalsFunction(): Maybe<Code>;
17
+ get declaration(): Code;
24
18
  get filterProperty(): Maybe<{
25
19
  name: string;
26
20
  type: Code;
27
21
  }>;
28
- get getAccessorDeclaration(): Maybe<Code>;
29
22
  get graphqlField(): AbstractProperty<IdentifierType>["graphqlField"];
30
- get jsonSignature(): Maybe<Code>;
31
23
  get jsonSchema(): AbstractProperty<IdentifierType>["jsonSchema"];
32
- private get abstract();
33
- private get declarationModifiers();
34
- private get declarationName();
35
- private get override();
24
+ get jsonSignature(): Maybe<Code>;
25
+ accessExpression({ variables, }: Parameters<AbstractProperty<BlankNodeType | IdentifierType | IriType>["accessExpression"]>[0]): Code;
36
26
  constructorStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["constructorStatements"]>[0]): readonly Code[];
37
27
  fromJsonStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["fromJsonStatements"]>[0]): readonly Code[];
38
- toStringExpression(parameters: Parameters<AbstractProperty<IdentifierType>["toStringExpression"]>[0]): Maybe<Code>;
39
28
  fromRdfResourceValuesExpression({ variables, }: Parameters<AbstractProperty<IdentifierType>["fromRdfResourceValuesExpression"]>[0]): Maybe<Code>;
40
29
  hashStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["hashStatements"]>[0]): readonly Code[];
41
30
  jsonUiSchemaElement({ variables, }: Parameters<AbstractProperty<IdentifierType>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
@@ -46,5 +35,6 @@ export declare class IdentifierProperty extends AbstractProperty<BlankNodeType |
46
35
  }>;
47
36
  toJsonObjectMemberExpression({ variables, }: Parameters<AbstractProperty<IdentifierType>["toJsonObjectMemberExpression"]>[0]): Maybe<Code>;
48
37
  toRdfRdfResourceValuesStatements(): readonly Code[];
38
+ toStringExpression(parameters: Parameters<AbstractProperty<IdentifierType>["toStringExpression"]>[0]): Maybe<Code>;
49
39
  }
50
40
  //# sourceMappingURL=IdentifierProperty.d.ts.map
@@ -16,31 +16,17 @@ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
16
16
  import { arrayOf, code, joinCode } from "../ts-poet-wrapper.js";
17
17
  import { AbstractProperty } from "./AbstractProperty.js";
18
18
  export class IdentifierProperty extends AbstractProperty {
19
- identifierMintingStrategy;
20
- identifierPrefixPropertyName;
21
19
  typeAlias;
22
20
  kind = "IdentifierProperty";
23
21
  mutable = false;
24
22
  recursive = false;
25
- constructor({ identifierMintingStrategy, identifierPrefixPropertyName, typeAlias, ...superParameters }) {
23
+ constructor({ typeAlias, ...superParameters }) {
26
24
  super(superParameters);
27
- invariant(this.visibility === "public");
28
- this.identifierMintingStrategy = identifierMintingStrategy;
29
- this.identifierPrefixPropertyName = identifierPrefixPropertyName;
30
25
  this.typeAlias = typeAlias;
31
26
  }
32
27
  get constructorParametersSignature() {
33
- if (this.abstract) {
34
- const declarationModifiers = this.declarationModifiers.extractNullable();
35
- if (declarationModifiers === null || declarationModifiers.abstract) {
36
- // If the property is not declared or it's declared abstract, we just pass up parameters to super as-is.
37
- return Maybe.empty();
38
- }
39
- }
40
- const hasQuestionToken = this.identifierMintingStrategy.isJust() ||
41
- this.namedObjectType.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.identifierProperty.identifierMintingStrategy.isJust()) ||
42
- this.namedObjectType.descendantObjectTypes.some((descendantObjectType) => descendantObjectType.identifierProperty.identifierMintingStrategy.isJust());
43
- const typeNames = [];
28
+ const hasQuestionToken = this.type.nodeKinds.has("BlankNode");
29
+ const typeNames = [code `(() => ${this.typeAlias})`];
44
30
  for (const conversion of this.type.conversions) {
45
31
  if (conversion.sourceTypeof !== "undefined" &&
46
32
  !typeNames.some((typeName) => codeEquals(typeName, conversion.sourceTypeName))) {
@@ -50,10 +36,7 @@ export class IdentifierProperty extends AbstractProperty {
50
36
  return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeNames, { on: "|" })};`);
51
37
  }
52
38
  get declaration() {
53
- return this.declarationModifiers.map(({ abstract, hasQuestionToken, override, readonly, visibility }) => code `${visibility ? `${visibility} ` : ""}${abstract ? "abstract " : ""}${override ? "override " : ""}${readonly ? "readonly " : ""}${this.declarationName}${hasQuestionToken ? "?" : ""}: ${this.typeAlias};`);
54
- }
55
- get equalsFunction() {
56
- return Maybe.of(this.type.equalsFunction);
39
+ return code `readonly ${this.name}: () => ${this.typeAlias};`;
57
40
  }
58
41
  get filterProperty() {
59
42
  return Maybe.of({
@@ -61,92 +44,16 @@ export class IdentifierProperty extends AbstractProperty {
61
44
  type: this.type.filterType,
62
45
  });
63
46
  }
64
- get getAccessorDeclaration() {
65
- // If this, an ancestor, or a descendant has an identifier minting strategy then all classes in the hierarchy must
66
- // have get accessors.
67
- const checkIdentifierTermTypeStatements = (identifierVariable, identifierVariableNodeKinds) => {
68
- if (this.type.nodeKinds.size === 2) {
69
- return [];
70
- }
71
- const expectedNodeKind = this.type.kind === "IriType" ? "IRI" : "BlankNode";
72
- if (identifierVariableNodeKinds) {
73
- if (identifierVariableNodeKinds.size === 1 &&
74
- identifierVariableNodeKinds.has(expectedNodeKind)) {
75
- return [];
76
- }
77
- }
78
- return [
79
- code `if (${identifierVariable}.termType !== "${NodeKind.toTermType(expectedNodeKind)}") { throw new Error(\`expected identifier to be ${expectedNodeKind}, not \${${identifierVariable}.termType}\`); }`,
80
- ];
81
- };
82
- if (this.identifierMintingStrategy.isJust()) {
83
- // Mint the identifier lazily in the get accessor
84
- let memoizeMintedIdentifier;
85
- let mintIdentifier;
86
- switch (this.identifierMintingStrategy.unsafeCoerce()) {
87
- case "blankNode":
88
- memoizeMintedIdentifier = true;
89
- mintIdentifier = code `${imports.dataFactory}.blankNode()`;
90
- break;
91
- case "sha256":
92
- // If the object is mutable don't memoize the minted identifier, since the hash will change if the object mutates.
93
- memoizeMintedIdentifier = !this.namedObjectType.mutable;
94
- mintIdentifier = code `${imports.dataFactory}.namedNode(\`\${this.${this.identifierPrefixPropertyName}}\${this.${syntheticNamePrefix}hashShaclProperties(${imports.sha256}.create())}\`)`;
95
- break;
96
- case "uuidv4":
97
- memoizeMintedIdentifier = true;
98
- mintIdentifier = code `${imports.dataFactory}.namedNode(\`\${this.${this.identifierPrefixPropertyName}}\${${imports.uuid}.v4()}\`)`;
99
- break;
100
- }
101
- return Maybe.of(code `\
102
- ${this.override ? "override " : ""} get ${this.name}(): ${this.typeAlias} { ${joinCode([
103
- code `if (this._${this.name} === undefined) { ${memoizeMintedIdentifier ? code `this._${this.name} = ${mintIdentifier};` : code `return ${mintIdentifier};`} }`,
104
- ...checkIdentifierTermTypeStatements(`this._${this.name}`),
105
- code `return this._${this.name};`,
106
- ])} }`);
107
- }
108
- // If this object type has an ancestor or a descendant with an identifier minting strategy, declare a get accessor.
109
- if (this.namedObjectType.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.identifierProperty.identifierMintingStrategy.isJust()) ||
110
- this.namedObjectType.descendantObjectTypes.some((descendantObjectType) => descendantObjectType.identifierProperty.identifierMintingStrategy.isJust())) {
111
- if (this.namedObjectType.parentObjectTypes.length > 0) {
112
- // If this object type isn't the root, delegate up.
113
- const checkSuperIdentifierTermTypeStatements = checkIdentifierTermTypeStatements("identifier", this.namedObjectType.parentObjectTypes[0].identifierType.nodeKinds);
114
- if (checkSuperIdentifierTermTypeStatements.length === 0) {
115
- return Maybe.empty(); // Don't need a get accessor just to return super.identifier.
116
- }
117
- return Maybe.of(code `override get ${this.name}(): ${this.typeAlias} { ${joinCode([
118
- code `const identifier = super.${this.name};`,
119
- ...checkSuperIdentifierTermTypeStatements,
120
- code `return identifier;`,
121
- ])} }`);
122
- }
123
- // This object type is the root but it has no identifier minting strategy.
124
- // Just return the declared property in the get accessor.
125
- // Subclasses will override the get accessor.
126
- return Maybe.of(code `${this.override ? "override " : ""}get ${this.name}(): ${this.typeAlias} { ${joinCode([
127
- code `if (this.${this.declarationName} === undefined) { throw new Error("unable to mint identifier"); }`,
128
- code `return this.${this.declarationName};`,
129
- ])}`);
130
- }
131
- // None of the object type hierarchy has an identifier minting strategy, don't need a get accessor
132
- return Maybe.empty();
133
- }
134
47
  get graphqlField() {
135
48
  invariant(this.name.startsWith(syntheticNamePrefix));
136
49
  return Maybe.of({
137
50
  args: Maybe.empty(),
138
51
  description: Maybe.empty(),
139
52
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
140
- resolve: code `(source) => ${this.typeAlias}.stringify(source.${this.name})`,
53
+ resolve: code `(source) => ${this.typeAlias}.stringify(${this.accessExpression({ variables: { object: code `source` } })})`,
141
54
  type: this.type.graphqlType.name,
142
55
  });
143
56
  }
144
- get jsonSignature() {
145
- if (this.type.in_.length > 0) {
146
- return Maybe.of(code `readonly "@id": ${this.type.in_.map((iri) => `"${iri.value}"`).join(" | ")}`);
147
- }
148
- return Maybe.of(code `readonly "@id": string`);
149
- }
150
57
  get jsonSchema() {
151
58
  let schema;
152
59
  if (this.type.in_.length > 0 && this.type.kind === "IriType") {
@@ -162,115 +69,36 @@ export class IdentifierProperty extends AbstractProperty {
162
69
  schema,
163
70
  });
164
71
  }
165
- // protected override get schemaObject() {
166
- // return {
167
- // ...super.schemaObject,
168
- // identifierMintingStrategy: this.identifierMintingStrategy
169
- // .map((_) => code`${literalOf(_)} as const`)
170
- // .extract(),
171
- // };
172
- // }
173
- get abstract() {
174
- return this.namedObjectType.abstract;
175
- }
176
- get declarationModifiers() {
177
- if (this.namedObjectType.declarationType === "interface") {
178
- return Maybe.of({ readonly: true });
179
- }
180
- if (this.namedObjectType.parentObjectTypes.length > 0) {
181
- // An ancestor will declare the identifier property.
182
- return Maybe.empty();
183
- }
184
- if (this.identifierMintingStrategy.isJust() ||
185
- this.namedObjectType.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.identifierProperty.identifierMintingStrategy.isJust()) ||
186
- this.namedObjectType.descendantObjectTypes.some((descendantObjectType) => descendantObjectType.identifierProperty.identifierMintingStrategy.isJust())) {
187
- return Maybe.of({
188
- hasQuestionToken: true,
189
- visibility: this.namedObjectType.descendantObjectTypes.some((descendantObjectType) => descendantObjectType.identifierProperty.identifierMintingStrategy.isJust())
190
- ? "protected"
191
- : "private",
192
- });
193
- }
194
- if (this.abstract) {
195
- // Declare the property abstract and public
196
- return Maybe.of({
197
- abstract: true,
198
- override: this.override,
199
- readonly: true,
200
- });
201
- }
202
- // Declare the property public
203
- return Maybe.of({
204
- override: this.override,
205
- readonly: true,
206
- });
207
- }
208
- get declarationName() {
209
- if (this.namedObjectType.declarationType === "class" &&
210
- (this.identifierMintingStrategy.isJust() ||
211
- this.namedObjectType.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.identifierProperty.identifierMintingStrategy.isJust()) ||
212
- this.namedObjectType.descendantObjectTypes.some((descendantObjectType) => descendantObjectType.identifierProperty.identifierMintingStrategy.isJust()))) {
213
- // If this, an ancestor, or a descendant has an identifier minting strategy, declare the identifier property
214
- // private or protected and prefix its name with _ in order to avoid a conflict with the get accessor name.
215
- return `_${this.name}`;
72
+ get jsonSignature() {
73
+ if (this.type.in_.length > 0) {
74
+ return Maybe.of(code `readonly "@id": ${this.type.in_.map((iri) => `"${iri.value}"`).join(" | ")}`);
216
75
  }
217
- return this.name;
76
+ return Maybe.of(code `readonly "@id": string`);
218
77
  }
219
- get override() {
220
- return this.namedObjectType.parentObjectTypes.length > 0;
78
+ accessExpression({ variables, }) {
79
+ return code `${variables.object}.${this.name}()`;
221
80
  }
222
81
  constructorStatements({ variables, }) {
223
- const constructorParametersSignature = this.constructorParametersSignature.extractNullable();
224
- if (constructorParametersSignature === null) {
225
- return [];
226
- }
227
- let lhs;
228
- const statements = [];
82
+ const parameterVariable = code `${this.name}Parameter`;
83
+ const statements = [
84
+ // Pull out the parameter so the function can capture it if necessary.
85
+ code `const ${parameterVariable} = ${variables.parameter};`,
86
+ code `let ${this.name}: () => ${this.typeAlias};`,
87
+ ];
229
88
  const typeConversions = this.type.conversions;
230
- switch (this.namedObjectType.declarationType) {
231
- case "class": {
232
- if (this.declaration.isNothing()) {
233
- return [];
234
- }
235
- lhs = `this.${this.declarationName}`;
236
- break;
237
- }
238
- case "interface":
239
- lhs = this.name;
240
- statements.push(code `let ${this.name}: ${this.typeAlias};`);
241
- break;
242
- }
243
- const conversionBranches = [];
89
+ const conversionBranches = [
90
+ code `if (typeof ${parameterVariable} === "function") { ${this.name} = ${parameterVariable}; }`,
91
+ ];
244
92
  for (const conversion of typeConversions) {
93
+ invariant(conversion.sourceTypeof !== "function");
245
94
  invariant(conversion.sourceTypeof !== "undefined");
246
- conversionBranches.push(code `if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${lhs} = ${conversion.conversionExpression(variables.parameter)}; }`);
95
+ conversionBranches.push(code `if (${conversion.sourceTypeCheckExpression(parameterVariable)}) { ${this.name} = () => ${conversion.conversionExpression(parameterVariable)}; }`);
96
+ }
97
+ if (this.type.nodeKinds.has("BlankNode")) {
98
+ conversionBranches.push(code `if (${parameterVariable} === undefined) { const ${syntheticNamePrefix}eagerIdentifier = ${imports.dataFactory}.blankNode(); ${this.name} = () => ${syntheticNamePrefix}eagerIdentifier; }`);
247
99
  }
248
- this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
249
- switch (this.namedObjectType.declarationType) {
250
- case "class":
251
- // The identifier will be minted lazily in the get accessor
252
- invariant(this.getAccessorDeclaration.isJust());
253
- conversionBranches.push(code `if (${variables.parameter} === undefined) { }`);
254
- break;
255
- case "interface": {
256
- let mintIdentifier;
257
- switch (identifierMintingStrategy) {
258
- case "blankNode":
259
- mintIdentifier = code `${imports.dataFactory}.blankNode()`;
260
- break;
261
- case "sha256":
262
- this.logger.warn("minting %s identifiers with %s is unsupported", this.namedObjectType.declarationType, identifierMintingStrategy);
263
- return;
264
- case "uuidv4":
265
- mintIdentifier = code `${imports.dataFactory}.namedNode(\`\${${variables.parameters}.${this.identifierPrefixPropertyName} ?? "urn:shaclmate:${this.namedObjectType.discriminantValue}:"}\${${imports.uuid}.v4()}\`)`;
266
- break;
267
- }
268
- conversionBranches.push(code `if (${variables.parameter} === undefined) { ${lhs} = ${mintIdentifier}; }`);
269
- }
270
- }
271
- });
272
100
  // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
273
- conversionBranches.push(code `{ ${lhs} = (${variables.parameter}) satisfies never;\n }`);
101
+ conversionBranches.push(code `{ ${this.name} = (${parameterVariable}) satisfies never;\n }`);
274
102
  statements.push(joinCode(conversionBranches, { on: " else " }));
275
103
  return statements;
276
104
  }
@@ -279,9 +107,6 @@ export class IdentifierProperty extends AbstractProperty {
279
107
  code `const ${this.name} = ${this.type.fromJsonExpression({ variables: { value: variables.jsonObject } })};`,
280
108
  ];
281
109
  }
282
- toStringExpression(parameters) {
283
- return Maybe.of(this.type.toStringExpression(parameters));
284
- }
285
110
  fromRdfResourceValuesExpression({ variables, }) {
286
111
  return Maybe.of(code `${this.type.fromRdfResourceValuesExpression({
287
112
  variables: {
@@ -310,7 +135,7 @@ export class IdentifierProperty extends AbstractProperty {
310
135
  ignoreRdfType: true, // Unused
311
136
  preferredLanguages: variables.preferredLanguages,
312
137
  propertyPatterns: code `[]`,
313
- schema: code `${this.namedObjectType.staticModuleName}.${syntheticNamePrefix}schema.properties.${this.namedObjectType.identifierProperty.name}.type()`,
138
+ schema: code `${this.namedObjectType.name}.${syntheticNamePrefix}schema.properties.${this.name}.type()`,
314
139
  valueVariable: variables.focusIdentifier,
315
140
  variablePrefix: variables.variablePrefix, // Unused
316
141
  }})`,
@@ -337,6 +162,9 @@ export class IdentifierProperty extends AbstractProperty {
337
162
  toRdfRdfResourceValuesStatements() {
338
163
  return [];
339
164
  }
165
+ toStringExpression(parameters) {
166
+ return Maybe.of(this.type.toStringExpression(parameters));
167
+ }
340
168
  }
341
169
  __decorate([
342
170
  Memoize()
@@ -344,25 +172,16 @@ __decorate([
344
172
  __decorate([
345
173
  Memoize()
346
174
  ], IdentifierProperty.prototype, "declaration", null);
347
- __decorate([
348
- Memoize()
349
- ], IdentifierProperty.prototype, "equalsFunction", null);
350
175
  __decorate([
351
176
  Memoize()
352
177
  ], IdentifierProperty.prototype, "filterProperty", null);
353
- __decorate([
354
- Memoize()
355
- ], IdentifierProperty.prototype, "getAccessorDeclaration", null);
356
178
  __decorate([
357
179
  Memoize()
358
180
  ], IdentifierProperty.prototype, "graphqlField", null);
359
- __decorate([
360
- Memoize()
361
- ], IdentifierProperty.prototype, "jsonSignature", null);
362
181
  __decorate([
363
182
  Memoize()
364
183
  ], IdentifierProperty.prototype, "jsonSchema", null);
365
184
  __decorate([
366
185
  Memoize()
367
- ], IdentifierProperty.prototype, "declarationModifiers", null);
186
+ ], IdentifierProperty.prototype, "jsonSignature", null);
368
187
  //# sourceMappingURL=IdentifierProperty.js.map
@@ -12,7 +12,7 @@ export function NamedObjectType_createFunctionDeclaration() {
12
12
  parametersType.push(code `{ ${joinCode(parametersPropertySignatures)} }`);
13
13
  }
14
14
  for (const parentObjectType of this.parentObjectTypes) {
15
- parametersType.push(code `Parameters<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}create>[0]`);
15
+ parametersType.push(code `Parameters<typeof ${parentObjectType.name}.${syntheticNamePrefix}create>[0]`);
16
16
  }
17
17
  if (parametersType.length === 0) {
18
18
  parametersType.push(code `object`);
@@ -21,7 +21,7 @@ export function NamedObjectType_createFunctionDeclaration() {
21
21
  const omitPropertyNames = [];
22
22
  const propertyStatements = [];
23
23
  for (const parentObjectType of this.parentObjectTypes) {
24
- propertyInitializers.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}create(parameters)`);
24
+ propertyInitializers.push(`...${parentObjectType.name}.${syntheticNamePrefix}create(parameters)`);
25
25
  }
26
26
  const parametersHasQuestionToken = this.parentObjectTypes.length === 0 &&
27
27
  parametersPropertySignatures.every((propertySignature) => propertySignature.toCodeString([]).indexOf("?:") !== -1);
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { NamedObjectType } from "../NamedObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function NamedObjectType_equalsFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=NamedObjectType_equalsFunctionDeclaration.d.ts.map