@shaclmate/compiler 2.0.17 → 2.0.19

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 (48) hide show
  1. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +10 -0
  2. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -0
  3. package/dist/ast/ObjectType.d.ts +8 -0
  4. package/dist/enums/IdentifierMintingStrategy.d.ts +1 -1
  5. package/dist/generators/ts/ListType.js +3 -2
  6. package/dist/generators/ts/ObjectType.d.ts +4 -0
  7. package/dist/generators/ts/ObjectType.js +46 -7
  8. package/dist/generators/ts/ObjectUnionType.js +1 -1
  9. package/dist/generators/ts/TypeFactory.js +84 -35
  10. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +34 -0
  11. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +98 -0
  12. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +4 -6
  13. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +53 -71
  14. package/dist/generators/ts/_ObjectType/Property.d.ts +7 -6
  15. package/dist/generators/ts/_ObjectType/Property.js +0 -6
  16. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +3 -3
  17. package/dist/generators/ts/_ObjectType/ShaclProperty.js +7 -7
  18. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +6 -4
  19. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +12 -9
  20. package/dist/generators/ts/_ObjectType/classDeclaration.js +4 -9
  21. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +5 -5
  22. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +6 -6
  23. package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.d.ts +4 -0
  24. package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.js +18 -0
  25. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.d.ts +13 -0
  26. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +97 -0
  27. package/dist/generators/ts/_ObjectType/index.d.ts +2 -1
  28. package/dist/generators/ts/_ObjectType/index.js +2 -1
  29. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  30. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +1 -1
  31. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +5 -5
  32. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +2 -4
  33. package/dist/input/NodeShape.d.ts +1 -0
  34. package/dist/input/NodeShape.js +11 -8
  35. package/dist/input/Ontology.d.ts +2 -0
  36. package/dist/input/Ontology.js +8 -2
  37. package/dist/input/PropertyPath.d.ts +41 -0
  38. package/dist/input/PropertyPath.js +105 -0
  39. package/dist/input/PropertyShape.js +3 -3
  40. package/dist/input/generated.d.ts +68 -64
  41. package/dist/input/generated.js +182 -160
  42. package/dist/input/tsFeatures.d.ts +1 -1
  43. package/dist/input/tsFeatures.js +14 -14
  44. package/package.json +7 -7
  45. package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +0 -5
  46. package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.js +0 -20
  47. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +0 -11
  48. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +0 -64
@@ -10,44 +10,39 @@ export class IdentifierProperty extends Property {
10
10
  mutable = false;
11
11
  classDeclarationVisibility;
12
12
  identifierMintingStrategy;
13
- lazyObjectTypeMutable;
14
13
  override;
15
- constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, identifierMintingStrategy, override, ...superParameters }) {
14
+ constructor({ abstract, classDeclarationVisibility, identifierMintingStrategy, override, ...superParameters }) {
16
15
  super(superParameters);
17
16
  invariant(this.visibility === "public");
18
17
  this.abstract = abstract;
19
18
  this.classDeclarationVisibility = classDeclarationVisibility;
20
- if (identifierMintingStrategy.isJust()) {
21
- this.identifierMintingStrategy = identifierMintingStrategy.unsafeCoerce();
22
- }
23
- else if (this.type.nodeKinds.has("BlankNode")) {
24
- this.identifierMintingStrategy = "blankNode";
25
- }
26
- else {
27
- this.identifierMintingStrategy = "none";
28
- }
29
- this.lazyObjectTypeMutable = lazyObjectTypeMutable;
19
+ this.identifierMintingStrategy = identifierMintingStrategy;
30
20
  this.override = override;
31
21
  }
32
22
  get classGetAccessorDeclaration() {
33
23
  if (this.abstract) {
34
24
  return Maybe.empty();
35
25
  }
26
+ if (this.identifierMintingStrategy.isNothing()) {
27
+ return Maybe.empty();
28
+ }
29
+ let memoizeMintedIdentifier;
36
30
  let mintIdentifier;
37
- switch (this.identifierMintingStrategy) {
31
+ switch (this.identifierMintingStrategy.unsafeCoerce()) {
38
32
  case "blankNode":
33
+ memoizeMintedIdentifier = true;
39
34
  mintIdentifier = "dataFactory.blankNode()";
40
35
  break;
41
- case "none":
42
- // If there's no minting strategy the identifier will be required by the constructor and assigned to a public property.
43
- return Maybe.empty();
44
36
  case "sha256":
37
+ // If the object is mutable don't memoize the minted identifier, since the hash will change if the object mutates.
38
+ memoizeMintedIdentifier = !this.objectType.mutable();
45
39
  mintIdentifier =
46
- "dataFactory.namedNode(`urn:shaclmate:object:${this.type}:${this.hash(sha256.create())}`)";
40
+ "dataFactory.namedNode(`${this.identifierPrefix}${this.hashShaclProperties(sha256.create())}`)";
47
41
  break;
48
42
  case "uuidv4":
43
+ memoizeMintedIdentifier = true;
49
44
  mintIdentifier =
50
- "dataFactory.namedNode(`urn:shaclmate:object:${this.type}:${uuid.v4()}`)";
45
+ "dataFactory.namedNode(`${this.identifierPrefix}${uuid.v4()}`)";
51
46
  break;
52
47
  }
53
48
  return Maybe.of({
@@ -55,9 +50,9 @@ export class IdentifierProperty extends Property {
55
50
  name: this.name,
56
51
  returnType: this.type.name,
57
52
  statements: [
58
- this.lazyObjectTypeMutable()
59
- ? `return (typeof this._${this.name} !== "undefined") ? this._${this.name} : ${mintIdentifier}`
60
- : `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`,
53
+ memoizeMintedIdentifier
54
+ ? `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`
55
+ : `return (typeof this._${this.name} !== "undefined") ? this._${this.name} : ${mintIdentifier}`,
61
56
  ],
62
57
  });
63
58
  }
@@ -78,24 +73,22 @@ export class IdentifierProperty extends Property {
78
73
  if (!this.classDeclarationVisibility.isJust()) {
79
74
  return Maybe.empty();
80
75
  }
81
- switch (this.identifierMintingStrategy) {
82
- case "none":
83
- // Immutable, public identifier property, no getter
84
- return Maybe.of({
85
- isReadonly: true,
86
- name: this.name,
87
- type: this.type.name,
88
- });
89
- default:
90
- // Mutable _identifier property that will be lazily initialized by the getter to mint the identifier
91
- return Maybe.of({
92
- name: `_${this.name}`,
93
- scope: this.classDeclarationVisibility
94
- .map(Property.visibilityToScope)
95
- .unsafeCoerce(),
96
- type: `${this.type.name} | undefined`,
97
- });
76
+ if (this.identifierMintingStrategy.isJust()) {
77
+ // Mutable _identifier property that will be lazily initialized by the getter to mint the identifier
78
+ return Maybe.of({
79
+ name: `_${this.name}`,
80
+ scope: this.classDeclarationVisibility
81
+ .map(Property.visibilityToScope)
82
+ .unsafeCoerce(),
83
+ type: `${this.type.name} | undefined`,
84
+ });
98
85
  }
86
+ // Immutable, public identifier property, no getter
87
+ return Maybe.of({
88
+ isReadonly: true,
89
+ name: this.name,
90
+ type: this.type.name,
91
+ });
99
92
  }
100
93
  get constructorParametersPropertySignature() {
101
94
  if (this.objectType.declarationType === "class" && this.abstract) {
@@ -109,7 +102,7 @@ export class IdentifierProperty extends Property {
109
102
  }
110
103
  return Maybe.of({
111
104
  hasQuestionToken: this.objectType.declarationType === "class" &&
112
- this.identifierMintingStrategy !== "none",
105
+ this.identifierMintingStrategy.isJust(),
113
106
  isReadonly: true,
114
107
  name: this.name,
115
108
  type: [...typeNames].sort().join(" | "),
@@ -119,30 +112,32 @@ export class IdentifierProperty extends Property {
119
112
  const imports = this.type.useImports().concat();
120
113
  if (this.objectType.features.has("hash") &&
121
114
  this.objectType.declarationType === "class") {
122
- switch (this.identifierMintingStrategy) {
123
- case "sha256":
124
- imports.push(Import.SHA256);
125
- break;
126
- case "uuidv4":
127
- imports.push(Import.UUID);
128
- break;
129
- }
115
+ this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
116
+ switch (identifierMintingStrategy) {
117
+ case "sha256":
118
+ imports.push(Import.SHA256);
119
+ break;
120
+ case "uuidv4":
121
+ imports.push(Import.UUID);
122
+ break;
123
+ }
124
+ });
130
125
  }
131
126
  return imports;
132
127
  }
133
128
  get interfacePropertySignature() {
134
- return {
129
+ return Maybe.of({
135
130
  isReadonly: true,
136
131
  name: this.name,
137
132
  type: this.type.name,
138
- };
133
+ });
139
134
  }
140
135
  get jsonPropertySignature() {
141
- return {
136
+ return Maybe.of({
142
137
  isReadonly: true,
143
138
  name: "@id",
144
139
  type: "string",
145
- };
140
+ });
146
141
  }
147
142
  get snippetDeclarations() {
148
143
  const snippetDeclarations = [];
@@ -194,20 +189,7 @@ export class IdentifierProperty extends Property {
194
189
  return [`const ${this.name} = ${variables.resource}.identifier`];
195
190
  }
196
191
  hashStatements({ variables, }) {
197
- if (this.abstract) {
198
- // Identifier will only be hashed by a concrete class.
199
- return [];
200
- }
201
- switch (this.identifierMintingStrategy) {
202
- case "blankNode":
203
- case "none":
204
- case "uuidv4":
205
- // The identifier minting won't call hash, so we should hash the identifier.
206
- return [`${variables.hasher}.update(${variables.value}.value);`];
207
- case "sha256":
208
- // The identifier minting will call hash, so we can't hash the identifier.
209
- return [];
210
- }
192
+ return [`${variables.hasher}.update(${variables.value}.value);`];
211
193
  }
212
194
  interfaceConstructorStatements({ variables, }) {
213
195
  const typeConversions = this.type.conversions;
@@ -225,7 +207,7 @@ export class IdentifierProperty extends Property {
225
207
  return statements;
226
208
  }
227
209
  jsonUiSchemaElement({ variables, }) {
228
- return Maybe.of(`{ label: "Identifier", scope: \`\${${variables.scopePrefix}}/properties/${this.jsonPropertySignature.name}\`, type: "Control" }`);
210
+ return Maybe.of(`{ label: "Identifier", scope: \`\${${variables.scopePrefix}}/properties/${this.jsonPropertySignature.unsafeCoerce().name}\`, type: "Control" }`);
229
211
  }
230
212
  jsonZodSchema({ variables, }) {
231
213
  let schema;
@@ -237,10 +219,10 @@ export class IdentifierProperty extends Property {
237
219
  else {
238
220
  schema = `${variables.zod}.string().min(1)`;
239
221
  }
240
- return {
241
- key: this.jsonPropertySignature.name,
222
+ return Maybe.of({
223
+ key: this.jsonPropertySignature.unsafeCoerce().name,
242
224
  schema,
243
- };
225
+ });
244
226
  }
245
227
  sparqlConstructTemplateTriples() {
246
228
  return [];
@@ -261,10 +243,10 @@ export class IdentifierProperty extends Property {
261
243
  }
262
244
  });
263
245
  if (valueToNodeKinds.length === 1) {
264
- return `"@id": ${valueToNodeKinds[0]}`;
246
+ return Maybe.of(`"@id": ${valueToNodeKinds[0]}`);
265
247
  }
266
248
  invariant(valueToNodeKinds.length === 2);
267
- return `"@id": ${variables.value}.termType === "${nodeKinds[0]}" ? ${valueToNodeKinds[0]} : ${valueToNodeKinds[1]}`;
249
+ return Maybe.of(`"@id": ${variables.value}.termType === "${nodeKinds[0]}" ? ${valueToNodeKinds[0]} : ${valueToNodeKinds[1]}`);
268
250
  }
269
251
  toRdfStatements() {
270
252
  return [];
@@ -27,11 +27,11 @@ export declare abstract class Property<TypeT extends {
27
27
  /**
28
28
  * Signature of the property in an interface version of the object.
29
29
  */
30
- abstract readonly interfacePropertySignature: OptionalKind<PropertySignatureStructure>;
30
+ abstract readonly interfacePropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
31
31
  /**
32
32
  * Signature of the property when serialized to JSON (the type of toJsonObjectMember).
33
33
  */
34
- abstract readonly jsonPropertySignature: OptionalKind<PropertySignatureStructure>;
34
+ abstract readonly jsonPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
35
35
  /**
36
36
  * Is the property reassignable?
37
37
  */
@@ -61,6 +61,7 @@ export declare abstract class Property<TypeT extends {
61
61
  protected readonly objectType: {
62
62
  readonly declarationType: TsObjectDeclarationType;
63
63
  readonly features: Set<TsFeature>;
64
+ readonly mutable: () => boolean;
64
65
  };
65
66
  constructor({ dataFactoryVariable, name, objectType, type, visibility, }: {
66
67
  dataFactoryVariable: string;
@@ -72,7 +73,7 @@ export declare abstract class Property<TypeT extends {
72
73
  /**
73
74
  * Imports this property requires when declared in an object.
74
75
  */
75
- get declarationImports(): readonly Import[];
76
+ abstract get declarationImports(): readonly Import[];
76
77
  protected static visibilityToScope(visibility: PropertyVisibility): Scope | undefined;
77
78
  /**
78
79
  * Statements to assign the parameter of described by constructorParametersPropertySignature to a class member.
@@ -127,10 +128,10 @@ export declare abstract class Property<TypeT extends {
127
128
  variables: {
128
129
  zod: string;
129
130
  };
130
- }): {
131
+ }): Maybe<{
131
132
  readonly key: string;
132
133
  readonly schema: string;
133
- };
134
+ }>;
134
135
  /**
135
136
  * An array of SPARQL.js CONSTRUCT template triples for this property as strings (so they can incorporate runtime calls).
136
137
  */
@@ -156,7 +157,7 @@ export declare abstract class Property<TypeT extends {
156
157
  variables: {
157
158
  value: string;
158
159
  };
159
- }): string;
160
+ }): Maybe<string>;
160
161
  /**
161
162
  * Statements to serialize this property to an RDF resource.
162
163
  */
@@ -22,12 +22,6 @@ export class Property {
22
22
  this.type = type;
23
23
  this.visibility = visibility;
24
24
  }
25
- /**
26
- * Imports this property requires when declared in an object.
27
- */
28
- get declarationImports() {
29
- return [];
30
- }
31
25
  static visibilityToScope(visibility) {
32
26
  switch (visibility) {
33
27
  case "private":
@@ -24,8 +24,8 @@ export declare class ShaclProperty extends Property<Type> {
24
24
  get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
25
25
  get declarationImports(): readonly Import[];
26
26
  get equalsFunction(): string;
27
- get interfacePropertySignature(): OptionalKind<PropertySignatureStructure>;
28
- get jsonPropertySignature(): OptionalKind<PropertySignatureStructure>;
27
+ get interfacePropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
28
+ get jsonPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
29
29
  get snippetDeclarations(): readonly string[];
30
30
  private get declarationComment();
31
31
  private get pathExpression();
@@ -38,7 +38,7 @@ export declare class ShaclProperty extends Property<Type> {
38
38
  jsonZodSchema(parameters: Parameters<Property<Type>["jsonZodSchema"]>[0]): ReturnType<Property<Type>["jsonZodSchema"]>;
39
39
  sparqlConstructTemplateTriples({ variables, }: Parameters<Property<Type>["sparqlConstructTemplateTriples"]>[0]): readonly string[];
40
40
  sparqlWherePatterns({ variables, }: Parameters<Property<Type>["sparqlWherePatterns"]>[0]): readonly string[];
41
- toJsonObjectMember(parameters: Parameters<Property<Type>["toJsonObjectMember"]>[0]): string;
41
+ toJsonObjectMember(parameters: Parameters<Property<Type>["toJsonObjectMember"]>[0]): Maybe<string>;
42
42
  toRdfStatements({ variables, }: Parameters<Property<Type>["toRdfStatements"]>[0]): readonly string[];
43
43
  }
44
44
  //# sourceMappingURL=ShaclProperty.d.ts.map
@@ -61,19 +61,19 @@ export class ShaclProperty extends Property {
61
61
  return this.type.equalsFunction;
62
62
  }
63
63
  get interfacePropertySignature() {
64
- return {
64
+ return Maybe.of({
65
65
  isReadonly: !this.mutable,
66
66
  leadingTrivia: this.declarationComment,
67
67
  name: this.name,
68
68
  type: this.type.name,
69
- };
69
+ });
70
70
  }
71
71
  get jsonPropertySignature() {
72
- return {
72
+ return Maybe.of({
73
73
  isReadonly: true,
74
74
  name: this.name,
75
75
  type: this.type.jsonName,
76
- };
76
+ });
77
77
  }
78
78
  get snippetDeclarations() {
79
79
  return this.type.snippetDeclarations(this.objectType.features);
@@ -142,10 +142,10 @@ export class ShaclProperty extends Property {
142
142
  this.comment.alt(this.description).ifJust((description) => {
143
143
  schema = `${schema}.describe(${JSON.stringify(description)})`;
144
144
  });
145
- return {
145
+ return Maybe.of({
146
146
  key: this.name,
147
147
  schema,
148
- };
148
+ });
149
149
  }
150
150
  sparqlConstructTemplateTriples({ variables, }) {
151
151
  const objectString = `\`\${${variables.variablePrefix}}${pascalCase(this.name)}\``;
@@ -172,7 +172,7 @@ export class ShaclProperty extends Property {
172
172
  });
173
173
  }
174
174
  toJsonObjectMember(parameters) {
175
- return `${this.name}: ${this.type.toJsonExpression(parameters)}`;
175
+ return Maybe.of(`${this.name}: ${this.type.toJsonExpression(parameters)}`);
176
176
  }
177
177
  toRdfStatements({ variables, }) {
178
178
  return [
@@ -1,3 +1,4 @@
1
+ import type { Import } from "generators/ts/Import.js";
1
2
  import { Maybe } from "purify-ts";
2
3
  import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
3
4
  import { Property } from "./Property.js";
@@ -16,19 +17,20 @@ export declare class TypeDiscriminatorProperty extends Property<TypeDiscriminato
16
17
  get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
17
18
  get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
18
19
  get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
19
- get interfacePropertySignature(): OptionalKind<PropertySignatureStructure>;
20
- get jsonPropertySignature(): OptionalKind<PropertySignatureStructure>;
20
+ get declarationImports(): readonly Import[];
21
+ get interfacePropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
22
+ get jsonPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
21
23
  get snippetDeclarations(): readonly string[];
22
24
  classConstructorStatements(): readonly string[];
23
25
  fromJsonStatements(): readonly string[];
24
26
  fromRdfStatements(): readonly string[];
25
- hashStatements(): readonly string[];
27
+ hashStatements({ variables, }: Parameters<Property<TypeDiscriminatorProperty>["hashStatements"]>[0]): readonly string[];
26
28
  interfaceConstructorStatements(): readonly string[];
27
29
  jsonUiSchemaElement({ variables, }: Parameters<Property<TypeDiscriminatorProperty.Type>["jsonUiSchemaElement"]>[0]): Maybe<string>;
28
30
  jsonZodSchema({ variables, }: Parameters<Property<TypeDiscriminatorProperty.Type>["jsonZodSchema"]>[0]): ReturnType<Property<TypeDiscriminatorProperty.Type>["jsonZodSchema"]>;
29
31
  sparqlConstructTemplateTriples(): readonly string[];
30
32
  sparqlWherePatterns(): readonly string[];
31
- toJsonObjectMember({ variables, }: Parameters<Property<TypeDiscriminatorProperty.Type>["toJsonObjectMember"]>[0]): string;
33
+ toJsonObjectMember({ variables, }: Parameters<Property<TypeDiscriminatorProperty.Type>["toJsonObjectMember"]>[0]): Maybe<string>;
32
34
  toRdfStatements(): readonly string[];
33
35
  }
34
36
  export declare namespace TypeDiscriminatorProperty {
@@ -42,19 +42,22 @@ export class TypeDiscriminatorProperty extends Property {
42
42
  get constructorParametersPropertySignature() {
43
43
  return Maybe.empty();
44
44
  }
45
+ get declarationImports() {
46
+ return [];
47
+ }
45
48
  get interfacePropertySignature() {
46
- return {
49
+ return Maybe.of({
47
50
  isReadonly: true,
48
51
  name: this.name,
49
52
  type: this.type.name,
50
- };
53
+ });
51
54
  }
52
55
  get jsonPropertySignature() {
53
- return {
56
+ return Maybe.of({
54
57
  isReadonly: true,
55
58
  name: this.name,
56
59
  type: this.type.name,
57
- };
60
+ });
58
61
  }
59
62
  get snippetDeclarations() {
60
63
  const snippetDeclarations = [];
@@ -74,8 +77,8 @@ export class TypeDiscriminatorProperty extends Property {
74
77
  ? [`const ${this.name} = "${this.value}" as const`]
75
78
  : [];
76
79
  }
77
- hashStatements() {
78
- return [];
80
+ hashStatements({ variables, }) {
81
+ return [`${variables.hasher}.update(${variables.value});`];
79
82
  }
80
83
  interfaceConstructorStatements() {
81
84
  return !this.abstract
@@ -87,12 +90,12 @@ export class TypeDiscriminatorProperty extends Property {
87
90
  return Maybe.of(`{ rule: { condition: { schema: { const: "${this.value}" }, scope: ${scope} }, effect: "HIDE" }, scope: ${scope}, type: "Control" }`);
88
91
  }
89
92
  jsonZodSchema({ variables, }) {
90
- return {
93
+ return Maybe.of({
91
94
  key: this.name,
92
95
  schema: this.type.values.length > 1
93
96
  ? `${variables.zod}.enum(${JSON.stringify(this.type.values)})`
94
97
  : `${variables.zod}.literal("${this.type.values[0]}")`,
95
- };
98
+ });
96
99
  }
97
100
  sparqlConstructTemplateTriples() {
98
101
  return [];
@@ -101,7 +104,7 @@ export class TypeDiscriminatorProperty extends Property {
101
104
  return [];
102
105
  }
103
106
  toJsonObjectMember({ variables, }) {
104
- return `${this.name}: ${variables.value}`;
107
+ return Maybe.of(`${this.name}: ${variables.value}`);
105
108
  }
106
109
  toRdfStatements() {
107
110
  return [];
@@ -2,7 +2,7 @@ import { Maybe } from "purify-ts";
2
2
  import { StructureKind, } from "ts-morph";
3
3
  import { tsComment } from "../tsComment.js";
4
4
  import { equalsFunctionOrMethodDeclaration } from "./equalsFunctionOrMethodDeclaration.js";
5
- import { hashFunctionOrMethodDeclaration } from "./hashFunctionOrMethodDeclaration.js";
5
+ import { hashFunctionOrMethodDeclarations } from "./hashFunctionOrMethodDeclarations.js";
6
6
  import { toJsonFunctionOrMethodDeclaration } from "./toJsonFunctionOrMethodDeclaration.js";
7
7
  import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
8
8
  function constructorDeclaration() {
@@ -72,7 +72,7 @@ export function classDeclaration() {
72
72
  leadingTrivia: this.comment.alt(this.label).map(tsComment).extract(),
73
73
  methods: [
74
74
  ...equalsMethodDeclaration.bind(this)().toList(),
75
- ...hashMethodDeclaration.bind(this)().toList(),
75
+ ...hashMethodDeclarations.bind(this)(),
76
76
  ...toJsonMethodDeclaration.bind(this)().toList(),
77
77
  ...toRdfMethodDeclaration.bind(this)().toList(),
78
78
  ...toStringMethodDeclaration.bind(this)().toList(),
@@ -84,13 +84,8 @@ export function classDeclaration() {
84
84
  function equalsMethodDeclaration() {
85
85
  return equalsFunctionOrMethodDeclaration.bind(this)();
86
86
  }
87
- function hashMethodDeclaration() {
88
- return hashFunctionOrMethodDeclaration
89
- .bind(this)()
90
- .map((hashFunctionOrMethodDeclaration) => ({
91
- ...hashFunctionOrMethodDeclaration,
92
- name: "hash",
93
- }));
87
+ function hashMethodDeclarations() {
88
+ return hashFunctionOrMethodDeclarations.bind(this)();
94
89
  }
95
90
  function toJsonMethodDeclaration() {
96
91
  return toJsonFunctionOrMethodDeclaration
@@ -15,9 +15,9 @@ export function fromJsonFunctionDeclarations() {
15
15
  const propertiesFromJsonFunctionStatements = [];
16
16
  propertiesFromJsonFunctionStatements.push(`const _jsonSafeParseResult = ${this.jsonZodSchemaFunctionName}().safeParse(_json);`, "if (!_jsonSafeParseResult.success) { return purify.Left(_jsonSafeParseResult.error); }", `const ${variables.jsonObject} = _jsonSafeParseResult.data;`);
17
17
  this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
18
- propertiesFromJsonFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromJson(${variables.jsonObject});`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
18
+ propertiesFromJsonFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}._propertiesFromJson(${variables.jsonObject});`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
19
19
  initializers.push(`..._super${parentObjectTypeI}`);
20
- propertiesFromJsonFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromJson>>`);
20
+ propertiesFromJsonFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}._propertiesFromJson>>`);
21
21
  });
22
22
  for (const property of this.properties) {
23
23
  const propertyFromJsonStatements = property.fromJsonStatements({
@@ -37,7 +37,7 @@ export function fromJsonFunctionDeclarations() {
37
37
  fromJsonFunctionDeclarations.push({
38
38
  isExported: true,
39
39
  kind: StructureKind.Function,
40
- name: "propertiesFromJson",
40
+ name: "_propertiesFromJson",
41
41
  parameters: [
42
42
  {
43
43
  name: "_json",
@@ -52,11 +52,11 @@ export function fromJsonFunctionDeclarations() {
52
52
  switch (this.declarationType) {
53
53
  case "class":
54
54
  fromJsonStatements = [
55
- `return ${this.name}.propertiesFromJson(json).map(properties => new ${this.name}(properties));`,
55
+ `return ${this.name}._propertiesFromJson(json).map(properties => new ${this.name}(properties));`,
56
56
  ];
57
57
  break;
58
58
  case "interface":
59
- fromJsonStatements = [`return ${this.name}.propertiesFromJson(json);`];
59
+ fromJsonStatements = [`return ${this.name}._propertiesFromJson(json);`];
60
60
  break;
61
61
  }
62
62
  fromJsonFunctionDeclarations.push({
@@ -18,9 +18,9 @@ export function fromRdfFunctionDeclarations() {
18
18
  const propertiesFromRdfFunctionReturnType = [];
19
19
  const propertiesFromRdfFunctionStatements = [];
20
20
  this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
21
- propertiesFromRdfFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: ${variables.resource} });`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
21
+ propertiesFromRdfFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}._propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: ${variables.resource} });`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
22
22
  initializers.push(`..._super${parentObjectTypeI}`);
23
- propertiesFromRdfFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromRdf>>`);
23
+ propertiesFromRdfFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}._propertiesFromRdf>>`);
24
24
  });
25
25
  this.fromRdfType.ifJust((rdfType) => {
26
26
  propertiesFromRdfFunctionStatements.push(`if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${this.rdfjsTermExpression(rdfType)})) { return purify.Left(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type\``, predicate: this.rdfjsTermExpression(rdfType) })})); }`);
@@ -48,7 +48,7 @@ export function fromRdfFunctionDeclarations() {
48
48
  fromRdfFunctionDeclarations.push({
49
49
  isExported: true,
50
50
  kind: StructureKind.Function,
51
- name: "propertiesFromRdf",
51
+ name: "_propertiesFromRdf",
52
52
  parameters: [
53
53
  {
54
54
  name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
@@ -63,12 +63,12 @@ export function fromRdfFunctionDeclarations() {
63
63
  switch (this.declarationType) {
64
64
  case "class":
65
65
  fromRdfStatements = [
66
- `return ${this.name}.propertiesFromRdf(parameters).map(properties => new ${this.name}(properties));`,
66
+ `return ${this.name}._propertiesFromRdf(parameters).map(properties => new ${this.name}(properties));`,
67
67
  ];
68
68
  break;
69
69
  case "interface":
70
70
  fromRdfStatements = [
71
- `return ${this.name}.propertiesFromRdf(parameters);`,
71
+ `return ${this.name}._propertiesFromRdf(parameters);`,
72
72
  ];
73
73
  break;
74
74
  }
@@ -79,7 +79,7 @@ export function fromRdfFunctionDeclarations() {
79
79
  parameters: [
80
80
  {
81
81
  name: "parameters",
82
- type: `Parameters<typeof ${this.name}.propertiesFromRdf>[0]`,
82
+ type: `Parameters<typeof ${this.name}._propertiesFromRdf>[0]`,
83
83
  },
84
84
  ],
85
85
  returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>`,
@@ -0,0 +1,4 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ export declare function hashFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
4
+ //# sourceMappingURL=hashFunctionDeclarations.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { StructureKind } from "ts-morph";
2
+ import { hashFunctionOrMethodDeclarations } from "./hashFunctionOrMethodDeclarations.js";
3
+ export function hashFunctionDeclarations() {
4
+ if (this.declarationType !== "interface") {
5
+ return [];
6
+ }
7
+ if (this.extern) {
8
+ return [];
9
+ }
10
+ return hashFunctionOrMethodDeclarations
11
+ .bind(this)()
12
+ .map((hashFunctionOrMethodDeclaration) => ({
13
+ ...hashFunctionOrMethodDeclaration,
14
+ isExported: true,
15
+ kind: StructureKind.Function,
16
+ }));
17
+ }
18
+ //# sourceMappingURL=hashFunctionDeclarations.js.map
@@ -0,0 +1,13 @@
1
+ import { type OptionalKind, type ParameterDeclarationStructure, Scope, type TypeParameterDeclarationStructure } from "ts-morph";
2
+ import { ObjectType } from "../ObjectType.js";
3
+ export declare const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
4
+ export declare function hashFunctionOrMethodDeclarations(this: ObjectType): readonly {
5
+ hasOverrideKeyword?: boolean;
6
+ name: string;
7
+ parameters: OptionalKind<ParameterDeclarationStructure>[];
8
+ returnType: string;
9
+ scope?: Scope;
10
+ statements: string[];
11
+ typeParameters: OptionalKind<TypeParameterDeclarationStructure>[];
12
+ }[];
13
+ //# sourceMappingURL=hashFunctionOrMethodDeclarations.d.ts.map