@shaclmate/compiler 4.0.22 → 4.0.24

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 (87) hide show
  1. package/dist/ShapesGraphToAstTransformer.js +16 -16
  2. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -5
  3. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +1 -1
  4. package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +4 -3
  5. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +12 -11
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +3 -3
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +6 -9
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +11 -12
  9. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
  11. package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
  12. package/dist/ast/ListType.d.ts +1 -8
  13. package/dist/ast/ListType.js +1 -6
  14. package/dist/ast/ObjectType.d.ts +7 -9
  15. package/dist/ast/ObjectType.js +7 -8
  16. package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -0
  17. package/dist/generators/ts/AbstractLazyObjectType.js +7 -0
  18. package/dist/generators/ts/AbstractNamedUnionType.d.ts +3 -2
  19. package/dist/generators/ts/AbstractNamedUnionType.js +23 -9
  20. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  21. package/dist/generators/ts/AbstractTermType.js +3 -0
  22. package/dist/generators/ts/AbstractType.d.ts +12 -4
  23. package/dist/generators/ts/AbstractUnionType.d.ts +1 -0
  24. package/dist/generators/ts/AbstractUnionType.js +11 -1
  25. package/dist/generators/ts/AnonymousUnionType.d.ts +2 -1
  26. package/dist/generators/ts/AnonymousUnionType.js +6 -3
  27. package/dist/generators/ts/DefaultValueType.d.ts +2 -1
  28. package/dist/generators/ts/DefaultValueType.js +6 -3
  29. package/dist/generators/ts/ListType.d.ts +2 -5
  30. package/dist/generators/ts/ListType.js +11 -27
  31. package/dist/generators/ts/NamedObjectType.d.ts +2 -9
  32. package/dist/generators/ts/NamedObjectType.js +12 -29
  33. package/dist/generators/ts/NamedObjectUnionType.js +1 -1
  34. package/dist/generators/ts/OptionType.d.ts +1 -0
  35. package/dist/generators/ts/OptionType.js +3 -0
  36. package/dist/generators/ts/SetType.d.ts +1 -0
  37. package/dist/generators/ts/SetType.js +3 -0
  38. package/dist/generators/ts/TypeFactory.js +9 -46
  39. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +23 -15
  40. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +6 -0
  41. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +3 -4
  42. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +26 -11
  43. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +5 -14
  44. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +34 -201
  45. package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +3 -11
  46. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +10 -9
  47. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js +4 -4
  48. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
  49. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
  50. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -5
  51. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +5 -10
  52. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +13 -9
  53. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +1 -1
  54. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +11 -2
  55. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +2 -2
  56. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
  57. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
  58. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js +8 -4
  59. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +4 -2
  60. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.d.ts +4 -0
  61. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +66 -0
  62. package/dist/generators/ts/_NamedObjectType/Property.d.ts +1 -2
  63. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +6 -5
  64. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +26 -20
  65. package/dist/generators/ts/_snippets/snippets_LazyObject.js +2 -2
  66. package/dist/generators/ts/_snippets/snippets_LazyObjectOption.js +2 -2
  67. package/dist/generators/ts/_snippets/snippets_LazyObjectSet.js +2 -2
  68. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +5 -3
  69. package/dist/generators/ts/_snippets/snippets_compactRecord.d.ts +2 -0
  70. package/dist/generators/ts/_snippets/snippets_compactRecord.js +16 -0
  71. package/dist/generators/ts/_snippets/{parseIri.d.ts → snippets_parseIri.d.ts} +1 -1
  72. package/dist/generators/ts/_snippets/{parseIri.js → snippets_parseIri.js} +1 -1
  73. package/dist/generators/ts/imports.d.ts +1 -3
  74. package/dist/generators/ts/imports.js +1 -3
  75. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
  76. package/dist/generators/ts/snippets.d.ts +1 -0
  77. package/dist/generators/ts/snippets.js +3 -1
  78. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +1 -1
  79. package/dist/input/generated.d.ts +104 -50
  80. package/dist/input/generated.js +284 -171
  81. package/package.json +2 -2
  82. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +0 -6
  83. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +0 -32
  84. package/dist/enums/IdentifierMintingStrategy.d.ts +0 -9
  85. package/dist/enums/IdentifierMintingStrategy.js +0 -18
  86. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.d.ts +0 -32
  87. package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.js +0 -89
@@ -16,31 +16,18 @@ 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
25
  invariant(this.visibility === "public");
28
- this.identifierMintingStrategy = identifierMintingStrategy;
29
- this.identifierPrefixPropertyName = identifierPrefixPropertyName;
30
26
  this.typeAlias = typeAlias;
31
27
  }
32
28
  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 = [];
29
+ const hasQuestionToken = this.type.nodeKinds.has("BlankNode");
30
+ const typeNames = [code `(() => ${this.typeAlias})`];
44
31
  for (const conversion of this.type.conversions) {
45
32
  if (conversion.sourceTypeof !== "undefined" &&
46
33
  !typeNames.some((typeName) => codeEquals(typeName, conversion.sourceTypeName))) {
@@ -50,10 +37,7 @@ export class IdentifierProperty extends AbstractProperty {
50
37
  return Maybe.of(code `readonly ${this.name}${hasQuestionToken ? "?" : ""}: ${joinCode(typeNames, { on: "|" })};`);
51
38
  }
52
39
  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);
40
+ return code `readonly ${this.name}: () => ${this.typeAlias};`;
57
41
  }
58
42
  get filterProperty() {
59
43
  return Maybe.of({
@@ -61,93 +45,17 @@ export class IdentifierProperty extends AbstractProperty {
61
45
  type: this.type.filterType,
62
46
  });
63
47
  }
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
48
  get graphqlField() {
135
49
  invariant(this.name.startsWith(syntheticNamePrefix));
136
50
  return Maybe.of({
137
51
  args: Maybe.empty(),
138
52
  description: Maybe.empty(),
139
53
  name: `_${this.name.substring(syntheticNamePrefix.length)}`,
140
- resolve: code `(source) => ${this.typeAlias}.stringify(source.${this.name})`,
54
+ resolve: code `(source) => ${this.typeAlias}.stringify(${this.accessExpression({ variables: { object: code `source` } })})`,
141
55
  type: this.type.graphqlType.name,
142
56
  });
143
57
  }
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
- get jsonZchema() {
58
+ get jsonSchema() {
151
59
  let schema;
152
60
  if (this.type.in_.length > 0 && this.type.kind === "IriType") {
153
61
  // Treat sh:in as a union of the IRIs
@@ -162,115 +70,46 @@ export class IdentifierProperty extends AbstractProperty {
162
70
  schema,
163
71
  });
164
72
  }
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}`;
73
+ get jsonSignature() {
74
+ if (this.type.in_.length > 0) {
75
+ return Maybe.of(code `readonly "@id": ${this.type.in_.map((iri) => `"${iri.value}"`).join(" | ")}`);
216
76
  }
217
- return this.name;
77
+ return Maybe.of(code `readonly "@id": string`);
218
78
  }
219
- get override() {
220
- return this.namedObjectType.parentObjectTypes.length > 0;
79
+ accessExpression({ variables, }) {
80
+ return code `${variables.object}.${this.name}()`;
221
81
  }
222
82
  constructorStatements({ variables, }) {
223
- const constructorParametersSignature = this.constructorParametersSignature.extractNullable();
224
- if (constructorParametersSignature === null) {
225
- return [];
226
- }
227
83
  let lhs;
228
- const statements = [];
84
+ const parameterVariable = code `${this.name}Parameter`;
85
+ const statements = [
86
+ // Pull out the parameter so the function can capture it if necessary.
87
+ code `const ${parameterVariable} = ${variables.parameter};`,
88
+ ];
229
89
  const typeConversions = this.type.conversions;
230
90
  switch (this.namedObjectType.declarationType) {
231
91
  case "class": {
232
- if (this.declaration.isNothing()) {
233
- return [];
234
- }
235
- lhs = `this.${this.declarationName}`;
92
+ lhs = `this.${this.name}`;
236
93
  break;
237
94
  }
238
95
  case "interface":
239
96
  lhs = this.name;
240
- statements.push(code `let ${this.name}: ${this.typeAlias};`);
97
+ statements.push(code `let ${this.name}: () => ${this.typeAlias};`);
241
98
  break;
242
99
  }
243
- const conversionBranches = [];
100
+ const conversionBranches = [
101
+ code `if (typeof ${parameterVariable} === "function") { ${lhs} = ${parameterVariable}; }`,
102
+ ];
244
103
  for (const conversion of typeConversions) {
104
+ invariant(conversion.sourceTypeof !== "function");
245
105
  invariant(conversion.sourceTypeof !== "undefined");
246
- conversionBranches.push(code `if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${lhs} = ${conversion.conversionExpression(variables.parameter)}; }`);
106
+ conversionBranches.push(code `if (${conversion.sourceTypeCheckExpression(parameterVariable)}) { ${lhs} = () => ${conversion.conversionExpression(parameterVariable)}; }`);
107
+ }
108
+ if (this.type.nodeKinds.has("BlankNode")) {
109
+ conversionBranches.push(code `if (${parameterVariable} === undefined) { const ${syntheticNamePrefix}eagerIdentifier = ${imports.dataFactory}.blankNode(); ${lhs} = () => ${syntheticNamePrefix}eagerIdentifier; }`);
247
110
  }
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
111
  // 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 }`);
112
+ conversionBranches.push(code `{ ${lhs} = (${parameterVariable}) satisfies never;\n }`);
274
113
  statements.push(joinCode(conversionBranches, { on: " else " }));
275
114
  return statements;
276
115
  }
@@ -307,7 +146,7 @@ export class IdentifierProperty extends AbstractProperty {
307
146
  ignoreRdfType: true, // Unused
308
147
  preferredLanguages: variables.preferredLanguages,
309
148
  propertyPatterns: code `[]`,
310
- schema: code `${this.namedObjectType.staticModuleName}.${syntheticNamePrefix}schema.properties.${this.namedObjectType.identifierProperty.name}.type()`,
149
+ schema: code `${this.namedObjectType.staticModuleName}.${syntheticNamePrefix}schema.properties.${this.name}.type()`,
311
150
  valueVariable: variables.focusIdentifier,
312
151
  variablePrefix: variables.variablePrefix, // Unused
313
152
  }})`,
@@ -334,6 +173,9 @@ export class IdentifierProperty extends AbstractProperty {
334
173
  toRdfRdfResourceValuesStatements() {
335
174
  return [];
336
175
  }
176
+ toStringExpression(parameters) {
177
+ return Maybe.of(this.type.toStringExpression(parameters));
178
+ }
337
179
  }
338
180
  __decorate([
339
181
  Memoize()
@@ -341,25 +183,16 @@ __decorate([
341
183
  __decorate([
342
184
  Memoize()
343
185
  ], IdentifierProperty.prototype, "declaration", null);
344
- __decorate([
345
- Memoize()
346
- ], IdentifierProperty.prototype, "equalsFunction", null);
347
186
  __decorate([
348
187
  Memoize()
349
188
  ], IdentifierProperty.prototype, "filterProperty", null);
350
- __decorate([
351
- Memoize()
352
- ], IdentifierProperty.prototype, "getAccessorDeclaration", null);
353
189
  __decorate([
354
190
  Memoize()
355
191
  ], IdentifierProperty.prototype, "graphqlField", null);
356
192
  __decorate([
357
193
  Memoize()
358
- ], IdentifierProperty.prototype, "jsonSignature", null);
194
+ ], IdentifierProperty.prototype, "jsonSchema", null);
359
195
  __decorate([
360
196
  Memoize()
361
- ], IdentifierProperty.prototype, "jsonZchema", null);
362
- __decorate([
363
- Memoize()
364
- ], IdentifierProperty.prototype, "declarationModifiers", null);
197
+ ], IdentifierProperty.prototype, "jsonSignature", null);
365
198
  //# sourceMappingURL=IdentifierProperty.js.map
@@ -1,11 +1,10 @@
1
- import { Maybe } from "purify-ts";
2
- import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
3
1
  import { code, def, joinCode } from "../ts-poet-wrapper.js";
4
2
  import { tsComment } from "../tsComment.js";
5
3
  import { NamedObjectType_equalsFunctionOrMethodDeclaration } from "./NamedObjectType_equalsFunctionOrMethodDeclaration.js";
6
4
  import { NamedObjectType_hashFunctionOrMethodDeclarations } from "./NamedObjectType_hashFunctionOrMethodDeclarations.js";
7
5
  import { NamedObjectType_toJsonFunctionOrMethodDeclaration } from "./NamedObjectType_toJsonFunctionOrMethodDeclaration.js";
8
6
  import { NamedObjectType_toRdfResourceFunctionOrMethodDeclaration } from "./NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js";
7
+ import { NamedObjectType_toStringFunctionOrMethodDeclarations } from "./NamedObjectType_toStringFunctionOrMethodDeclaration.js";
9
8
  function NamedObjectType_constructorDeclaration() {
10
9
  const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersSignature.toList());
11
10
  const parametersType = [];
@@ -49,21 +48,14 @@ ${this.comment
49
48
  .map(tsComment)
50
49
  .orDefault("")}export ${this.abstract ? "abstract " : ""}class ${def(this.name)}${this.parentObjectTypes.length > 0 ? ` extends ${this.parentObjectTypes[0].name}` : ""} {
51
50
  ${joinCode([
52
- ...this.properties.flatMap((property) => property.declaration.toList()),
51
+ ...this.properties.flatMap((property) => property.declaration),
53
52
  NamedObjectType_constructorDeclaration.call(this),
54
- ...this.properties.flatMap((property) => property.getAccessorDeclaration.toList()),
55
53
  ...NamedObjectType_equalsFunctionOrMethodDeclaration.call(this).toList(),
56
54
  ...NamedObjectType_hashFunctionOrMethodDeclarations.call(this),
57
55
  ...NamedObjectType_toJsonFunctionOrMethodDeclaration.call(this).toList(),
58
56
  ...NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.call(this).toList(),
59
- ...NamedObjectType_toStringMethodDeclaration.call(this).toList(),
57
+ ...NamedObjectType_toStringFunctionOrMethodDeclarations.call(this),
60
58
  ], { on: "\n\n" })}
61
59
  }`;
62
60
  }
63
- function NamedObjectType_toStringMethodDeclaration() {
64
- if (!this.features.has("json")) {
65
- return Maybe.empty();
66
- }
67
- return Maybe.of(code `${this.parentObjectTypes.length > 0 ? "override " : ""}toString(): string { return JSON.stringify(this.${syntheticNamePrefix}toJson()); }`);
68
- }
69
61
  //# sourceMappingURL=NamedObjectType_classDeclaration.js.map
@@ -13,11 +13,11 @@ export function NamedObjectType_equalsFunctionOrMethodDeclaration() {
13
13
  let rightVariable;
14
14
  switch (this.declarationType) {
15
15
  case "class":
16
- if (this.ownProperties.length === 0) {
16
+ if (this.properties.length === 0) {
17
17
  // If there's a parent class and no properties in this class, can skip overriding equals
18
18
  return Maybe.empty();
19
19
  }
20
- leftVariable = "this";
20
+ leftVariable = code `this`;
21
21
  parameters = code `other: ${this.name}`;
22
22
  if (this.parentObjectTypes.length > 0) {
23
23
  chain.push(code `super.${syntheticNamePrefix}equals(other)`);
@@ -26,22 +26,23 @@ export function NamedObjectType_equalsFunctionOrMethodDeclaration() {
26
26
  else {
27
27
  preamble = "";
28
28
  }
29
- rightVariable = "other";
29
+ rightVariable = code `other`;
30
30
  break;
31
31
  case "interface":
32
32
  // For every parent, find the nearest equals implementation
33
33
  for (const parentObjectType of this.parentObjectTypes) {
34
34
  chain.push(code `${parentObjectType.staticModuleName}.${syntheticNamePrefix}equals(left, right)`);
35
35
  }
36
- leftVariable = "left";
36
+ leftVariable = code `left`;
37
37
  parameters = code `left: ${this.name}, right: ${this.name}`;
38
38
  preamble = "export function ";
39
- rightVariable = "right";
39
+ rightVariable = code `right`;
40
40
  }
41
- for (const property of this.ownProperties) {
42
- property.equalsFunction.ifJust((equalsFunction) => {
43
- chain.push(code `(${equalsFunction})(${leftVariable}.${property.name}, ${rightVariable}.${property.name}).mapLeft(propertyValuesUnequal => ({ left: ${leftVariable}, right: ${rightVariable}, propertyName: "${property.name}", propertyValuesUnequal, type: "property" as const }))`);
44
- });
41
+ for (const property of this.properties) {
42
+ if (property.kind === "DiscriminantProperty") {
43
+ continue;
44
+ }
45
+ chain.push(code `(${property.type.equalsFunction})(${property.accessExpression({ variables: { object: leftVariable } })}, ${property.accessExpression({ variables: { object: rightVariable } })}).mapLeft(propertyValuesUnequal => ({ left: ${leftVariable}, right: ${rightVariable}, propertyName: "${property.name}", propertyValuesUnequal, type: "property" as const }))`);
45
46
  }
46
47
  return Maybe.of(code `\
47
48
  ${preamble}${syntheticNamePrefix}equals(${parameters}): ${snippets.EqualsResult} {
@@ -5,10 +5,10 @@ export function NamedObjectType_filterFunctionDeclaration() {
5
5
  for (const parentObjectType of this.parentObjectTypes) {
6
6
  statements.push(code `if (!${parentObjectType.filterFunction}(filter, value)) { return false; }`);
7
7
  }
8
- if (this.ownProperties.length > 0) {
9
- for (const ownProperty of this.ownProperties) {
10
- ownProperty.filterProperty.ifJust(({ name }) => {
11
- statements.push(code `if (filter.${name} !== undefined && !${ownProperty.type.filterFunction}(filter.${name}, value.${ownProperty.name})) { return false; }`);
8
+ if (this.properties.length > 0) {
9
+ for (const property of this.properties) {
10
+ property.filterProperty.ifJust(({ name }) => {
11
+ statements.push(code `if (filter.${name} !== undefined && !${property.type.filterFunction}(filter.${name}, ${property.accessExpression({ variables: { object: code `value` } })})) { return false; }`);
12
12
  });
13
13
  }
14
14
  }
@@ -31,7 +31,7 @@ if (!parameters?.ignoreRdfType) {
31
31
  );
32
32
  }`);
33
33
  }
34
- for (const property of this.ownProperties) {
34
+ for (const property of this.properties) {
35
35
  if (property.recursive) {
36
36
  continue;
37
37
  }
@@ -75,7 +75,7 @@ if (!parameters?.ignoreRdfType) {
75
75
  );
76
76
  }`);
77
77
  }
78
- for (const property of this.ownProperties) {
78
+ for (const property of this.properties) {
79
79
  if (property.recursive) {
80
80
  continue;
81
81
  }
@@ -8,13 +8,9 @@ export function NamedObjectType_fromJsonFunctionDeclaration() {
8
8
  if (this.abstract) {
9
9
  return Maybe.empty();
10
10
  }
11
- let returnExpression = code `${syntheticNamePrefix}propertiesFromJson(json)`;
12
- if (this.declarationType === "class") {
13
- returnExpression = code `new ${this.name}(${returnExpression})`;
14
- }
15
11
  return Maybe.of(code `\
16
12
  export function ${syntheticNamePrefix}fromJson(json: ${this.jsonType().name}): ${this.name} {
17
- return ${returnExpression};
13
+ return ${this.newExpression({ parameters: code `${syntheticNamePrefix}propertiesFromJson(json)` })};
18
14
  }`);
19
15
  }
20
16
  //# sourceMappingURL=NamedObjectType_fromJsonFunctionDeclaration.js.map
@@ -9,18 +9,13 @@ export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
9
9
  if (this.abstract) {
10
10
  return Maybe.empty();
11
11
  }
12
- const statements = [
13
- code `let { context, graph, ignoreRdfType = false, objectSet, preferredLanguages } = (options ?? {});`,
14
- code `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet(resource.dataset); }`,
15
- ];
16
- let propertiesFromRdfExpression = code `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdfResource(resource, { context, graph, ignoreRdfType, objectSet, preferredLanguages })`;
17
- if (this.declarationType === "class") {
18
- propertiesFromRdfExpression = code `${propertiesFromRdfExpression}.map(properties => new ${this.name}(properties))`;
19
- }
20
- statements.push(code `return ${propertiesFromRdfExpression};`);
21
12
  return Maybe.of(code `\
22
13
  export const ${syntheticNamePrefix}fromRdfResource: ${snippets.FromRdfResourceFunction}<${this.name}> = (resource, options) => {
23
- ${joinCode(statements)}
14
+ ${joinCode([
15
+ code `let { context, graph, ignoreRdfType = false, objectSet, preferredLanguages } = (options ?? {});`,
16
+ code `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet(resource.dataset); }`,
17
+ code `return ${code `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdfResource(resource, { context, graph, ignoreRdfType, objectSet, preferredLanguages }).map(${this.declarationType === "interface" ? code `${syntheticNamePrefix}create` : code `properties => ${this.newExpression({ parameters: code `properties` })}`})`};`,
18
+ ])}
24
19
  };`);
25
20
  }
26
21
  //# sourceMappingURL=NamedObjectType_fromRdfResourceFunctionDeclaration.js.map
@@ -6,13 +6,17 @@ export function NamedObjectType_hashFunctionOrMethodDeclarations() {
6
6
  if (!this.features.has("hash")) {
7
7
  return [];
8
8
  }
9
- const hashOwnShaclPropertiesStatements = this.ownShaclProperties.flatMap((property) => property.hashStatements({
10
- depth: 0,
11
- variables: {
12
- hasher: hasherVariable,
13
- value: code `${this.thisVariable}.${property.name}`,
14
- },
15
- }));
9
+ const hashOwnShaclPropertiesStatements = this.properties.flatMap((property) => property.kind === "ShaclProperty"
10
+ ? property.hashStatements({
11
+ depth: 0,
12
+ variables: {
13
+ hasher: hasherVariable,
14
+ value: property.accessExpression({
15
+ variables: { object: this.thisVariable },
16
+ }),
17
+ },
18
+ })
19
+ : []);
16
20
  if (this.declarationType === "class" &&
17
21
  this.parentObjectTypes.length > 0 &&
18
22
  hashOwnShaclPropertiesStatements.length === 0) {
@@ -49,13 +53,13 @@ export function NamedObjectType_hashFunctionOrMethodDeclarations() {
49
53
  const parametersCode = joinCode(parameters, { on: "," });
50
54
  hashShaclPropertiesStatements.push(...hashOwnShaclPropertiesStatements);
51
55
  hashShaclPropertiesStatements.push(code `return ${hasherVariable};`);
52
- hashStatements.push(...this.ownProperties
56
+ hashStatements.push(...this.properties
53
57
  .filter((property) => property.kind !== "ShaclProperty")
54
58
  .flatMap((property) => property.hashStatements({
55
59
  depth: 0,
56
60
  variables: {
57
61
  hasher: hasherVariable,
58
- value: code `${this.thisVariable}.${property.name}`,
62
+ value: code `${property.accessExpression({ variables: { object: this.thisVariable } })}`,
59
63
  },
60
64
  })));
61
65
  hashStatements.push(code `return ${hasherVariable};`);
@@ -10,7 +10,7 @@ ${this.comment
10
10
  .map((parentObjectType) => parentObjectType.name)
11
11
  .join(", ")}`
12
12
  : ""} {
13
- ${joinCode(this.properties.flatMap((property) => property.declaration.toList()))}
13
+ ${joinCode(this.properties.map((property) => property.declaration))}
14
14
  }`;
15
15
  }
16
16
  //# sourceMappingURL=NamedObjectType_interfaceDeclaration.js.map
@@ -12,13 +12,22 @@ export function NamedObjectType_jsonSchemaFunctionDeclaration() {
12
12
  }
13
13
  if (this.properties.length > 0) {
14
14
  properties = properties.concat(this.properties
15
- .flatMap((property) => property.jsonZchema.toList())
15
+ .flatMap((property) => property.jsonSchema.toList())
16
16
  .map(({ key, schema }) => code `"${key}": ${schema}`));
17
17
  }
18
+ const meta = {
19
+ id: this.name,
20
+ };
21
+ this.comment.ifJust((description) => {
22
+ meta["description"] = description;
23
+ });
24
+ this.label.ifJust((label) => {
25
+ meta["title"] = label;
26
+ });
18
27
  // ${this.properties.every((property) => !property.mutable) ? `.readonly()` : ""}
19
28
  return Maybe.of(code `\
20
29
  export function schema() {
21
- return ${imports.z}.object({${joinCode(properties, { on: "," })}}) satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
30
+ return ${imports.z}.object({${joinCode(properties, { on: "," })}}).meta(${meta}) satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
22
31
  }`);
23
32
  }
24
33
  //# sourceMappingURL=NamedObjectType_jsonSchemaFunctionDeclaration.js.map
@@ -6,8 +6,8 @@ export function NamedObjectType_jsonTypeAliasDeclaration() {
6
6
  return Maybe.empty();
7
7
  }
8
8
  const members = [];
9
- if (this.ownProperties.length > 0) {
10
- members.push(code `{ ${joinCode(this.ownProperties.flatMap((property) => property.jsonSignature.toList()), { on: ";" })} }`);
9
+ if (this.properties.length > 0) {
10
+ members.push(code `{ ${joinCode(this.properties.flatMap((property) => property.jsonSignature.toList()), { on: ";" })} }`);
11
11
  }
12
12
  for (const parentObjectType of this.parentObjectTypes) {
13
13
  members.push(code `${parentObjectType.jsonType().name}`);
@@ -8,7 +8,7 @@ export function NamedObjectType_jsonUiSchemaFunctionDeclaration() {
8
8
  const variables = { scopePrefix: code `scopePrefix` };
9
9
  const elements = this.parentObjectTypes
10
10
  .map((parentObjectType) => code `${parentObjectType.staticModuleName}.${syntheticNamePrefix}Json.uiSchema({ scopePrefix })`)
11
- .concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
11
+ .concat(this.properties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
12
12
  return Maybe.of(code `\
13
13
  export function uiSchema(parameters?: { scopePrefix?: string }): any {
14
14
  const scopePrefix = parameters?.scopePrefix ?? "#";
@@ -4,6 +4,6 @@ export function NamedObjectType_schemaVariableStatement() {
4
4
  return code `\
5
5
  export const ${syntheticNamePrefix}schema = { properties: { ${joinCode(this.parentObjectTypes
6
6
  .map((parentObjectType) => code `...${parentObjectType.staticModuleName}.${syntheticNamePrefix}schema.properties`)
7
- .concat(this.ownProperties.map((property) => code `${property.name}: ${property.schema}`)), { on: ", " })} } } as const;`;
7
+ .concat(this.properties.map((property) => code `${property.name}: ${property.schema}`)), { on: ", " })} } } as const;`;
8
8
  }
9
9
  //# sourceMappingURL=NamedObjectType_schemaVariableStatement.js.map
@@ -6,7 +6,7 @@ export function NamedObjectType_toJsonFunctionOrMethodDeclaration() {
6
6
  return Maybe.empty();
7
7
  }
8
8
  if (this.declarationType === "class" &&
9
- this.ownProperties.length === 0 &&
9
+ this.properties.length === 0 &&
10
10
  this.parentObjectTypes.length > 0) {
11
11
  return Maybe.empty();
12
12
  }
@@ -31,10 +31,14 @@ export function NamedObjectType_toJsonFunctionOrMethodDeclaration() {
31
31
  preamble = "export function ";
32
32
  break;
33
33
  }
34
- if (this.ownProperties.length > 0) {
35
- jsonObjectMembers.push(...this.ownProperties.flatMap((property) => property
34
+ if (this.properties.length > 0) {
35
+ jsonObjectMembers.push(...this.properties.flatMap((property) => property
36
36
  .toJsonObjectMemberExpression({
37
- variables: { value: code `${this.thisVariable}.${property.name}` },
37
+ variables: {
38
+ value: property.accessExpression({
39
+ variables: { object: this.thisVariable },
40
+ }),
41
+ },
38
42
  })
39
43
  .toList()));
40
44
  }
@@ -37,7 +37,7 @@ export function NamedObjectType_toRdfResourceFunctionOrMethodDeclaration() {
37
37
  statements.push(code `const ${variables.resource} = ${superToRdfCall};`);
38
38
  }
39
39
  else {
40
- statements.push(code `const ${variables.resource} = ${variables.resourceSet}.resource(${this.thisVariable}.${this.identifierProperty.name});`);
40
+ statements.push(code `const ${variables.resource} = ${variables.resourceSet}.resource(${this.thisVariable}.${syntheticNamePrefix}identifier());`);
41
41
  }
42
42
  if (this.toRdfTypes.length > 0) {
43
43
  statements.push(code `if (!options?.${variables.ignoreRdfType}) { ${joinCode(this.toRdfTypes.map((toRdfType) => code `${variables.resource}.add(${rdfjsTermExpression(rdf.type, { logger: this.logger })}, ${imports.dataFactory}.namedNode("${toRdfType.value}"), options?.${variables.graph});`), { on: " " })} }`);
@@ -48,7 +48,9 @@ export function NamedObjectType_toRdfResourceFunctionOrMethodDeclaration() {
48
48
  graph: code `options?.${variables.graph}`,
49
49
  resource: variables.resource,
50
50
  resourceSet: variables.resourceSet,
51
- value: code `${this.thisVariable}.${property.name}`,
51
+ value: property.accessExpression({
52
+ variables: { object: this.thisVariable },
53
+ }),
52
54
  },
53
55
  }));
54
56
  }