@shaclmate/compiler 2.0.18 → 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.
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -0
- package/dist/ast/ObjectType.d.ts +8 -0
- package/dist/enums/IdentifierMintingStrategy.d.ts +1 -1
- package/dist/generators/ts/ListType.js +3 -2
- package/dist/generators/ts/ObjectType.d.ts +4 -0
- package/dist/generators/ts/ObjectType.js +46 -7
- package/dist/generators/ts/ObjectUnionType.js +1 -1
- package/dist/generators/ts/TypeFactory.js +84 -35
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +34 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +98 -0
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +4 -6
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +53 -71
- package/dist/generators/ts/_ObjectType/Property.d.ts +7 -6
- package/dist/generators/ts/_ObjectType/Property.js +0 -6
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +3 -3
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +7 -7
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +6 -4
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +12 -9
- package/dist/generators/ts/_ObjectType/classDeclaration.js +4 -9
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +5 -5
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +6 -6
- package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.js +18 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.d.ts +13 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +97 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +2 -1
- package/dist/generators/ts/_ObjectType/index.js +2 -1
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +5 -5
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +2 -4
- package/dist/input/NodeShape.d.ts +1 -0
- package/dist/input/NodeShape.js +11 -8
- package/dist/input/Ontology.d.ts +2 -0
- package/dist/input/Ontology.js +8 -2
- package/dist/input/PropertyShape.js +3 -3
- package/dist/input/generated.d.ts +67 -63
- package/dist/input/generated.js +181 -159
- package/dist/input/tsFeatures.d.ts +1 -1
- package/dist/input/tsFeatures.js +14 -14
- package/package.json +7 -7
- package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.js +0 -20
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +0 -11
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +0 -64
|
@@ -150,6 +150,7 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
150
150
|
parentObjectTypes: [], // This is mutable, we'll populate it below
|
|
151
151
|
toRdfTypes: nodeShape.toRdfTypes,
|
|
152
152
|
tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
|
|
153
|
+
tsIdentifierPrefixPropertyName: nodeShape.tsObjectIdentifierPrefixPropertyName.orDefault("identifierPrefix"),
|
|
153
154
|
tsIdentifierPropertyName: nodeShape.tsObjectIdentifierPropertyName.orDefault("identifier"),
|
|
154
155
|
tsImports: nodeShape.tsImports,
|
|
155
156
|
tsObjectDeclarationType: nodeShape.tsObjectDeclarationType.orDefault("class"),
|
|
@@ -177,6 +178,15 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
177
178
|
}
|
|
178
179
|
objectType.properties.push(propertyEither.unsafeCoerce());
|
|
179
180
|
}
|
|
181
|
+
objectType.properties.sort((left, right) => {
|
|
182
|
+
if (left.order < right.order) {
|
|
183
|
+
return -1;
|
|
184
|
+
}
|
|
185
|
+
if (left.order > right.order) {
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
return 0;
|
|
189
|
+
});
|
|
180
190
|
return Either.of(objectType);
|
|
181
191
|
}
|
|
182
192
|
//# sourceMappingURL=transformNodeShapeToAstType.js.map
|
|
@@ -21,6 +21,7 @@ export function transformPropertyShapeToAstObjectTypeProperty(propertyShape) {
|
|
|
21
21
|
label: pickLiteral(propertyShape.labels).map((literal) => literal.value),
|
|
22
22
|
mutable: propertyShape.mutable,
|
|
23
23
|
name: this.shapeAstName(propertyShape),
|
|
24
|
+
order: propertyShape.order.orDefault(0),
|
|
24
25
|
path,
|
|
25
26
|
type: type.extract(),
|
|
26
27
|
visibility: propertyShape.visibility,
|
package/dist/ast/ObjectType.d.ts
CHANGED
|
@@ -103,6 +103,10 @@ export interface ObjectType {
|
|
|
103
103
|
* TypeScript features to generate.
|
|
104
104
|
*/
|
|
105
105
|
readonly tsFeatures: Set<TsFeature>;
|
|
106
|
+
/**
|
|
107
|
+
* Name of the identifier prefix property in TypeScript-generated classes/interfaces.
|
|
108
|
+
*/
|
|
109
|
+
readonly tsIdentifierPrefixPropertyName: string;
|
|
106
110
|
/**
|
|
107
111
|
* Name of the identifier property in TypeScript-generated classes/interfaces.
|
|
108
112
|
*/
|
|
@@ -148,6 +152,10 @@ export declare namespace ObjectType {
|
|
|
148
152
|
* Name of this property.
|
|
149
153
|
*/
|
|
150
154
|
readonly name: Name;
|
|
155
|
+
/**
|
|
156
|
+
* Relative order of this property, derived from sh:order.
|
|
157
|
+
*/
|
|
158
|
+
readonly order: number;
|
|
151
159
|
/**
|
|
152
160
|
* SHACL property path (https://www.w3.org/TR/shacl/#property-paths)
|
|
153
161
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TypeScript enum corresponding to shaclmate:identifierMintingStrategy, for simpler manipulation.
|
|
3
3
|
*/
|
|
4
|
-
export type IdentifierMintingStrategy = "sha256" | "uuidv4";
|
|
4
|
+
export type IdentifierMintingStrategy = "blankNode" | "sha256" | "uuidv4";
|
|
5
5
|
//# sourceMappingURL=IdentifierMintingStrategy.d.ts.map
|
|
@@ -15,8 +15,7 @@ export class ListType extends Type {
|
|
|
15
15
|
super(superParameters);
|
|
16
16
|
this.identifierNodeKind = identifierNodeKind;
|
|
17
17
|
this.itemType = itemType;
|
|
18
|
-
this.identifierMintingStrategy =
|
|
19
|
-
identifierMintingStrategy.orDefault("sha256");
|
|
18
|
+
this.identifierMintingStrategy = identifierMintingStrategy.orDefault(identifierNodeKind === "BlankNode" ? "blankNode" : "sha256");
|
|
20
19
|
this._mutable = mutable;
|
|
21
20
|
this.toRdfTypes = toRdfTypes;
|
|
22
21
|
}
|
|
@@ -230,6 +229,8 @@ export class ListType extends Type {
|
|
|
230
229
|
}
|
|
231
230
|
case "NamedNode": {
|
|
232
231
|
switch (this.identifierMintingStrategy) {
|
|
232
|
+
case "blankNode":
|
|
233
|
+
throw new RangeError(this.identifierMintingStrategy);
|
|
233
234
|
case "sha256":
|
|
234
235
|
listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
|
|
235
236
|
(_hasher, _item) => {
|
|
@@ -47,6 +47,7 @@ export declare class ObjectType extends DeclaredType {
|
|
|
47
47
|
get discriminatorValue(): string;
|
|
48
48
|
get equalsFunction(): string;
|
|
49
49
|
get hashFunctionName(): string;
|
|
50
|
+
get hashShaclPropertiesFunctionName(): string;
|
|
50
51
|
get identifierProperty(): ObjectType.IdentifierProperty;
|
|
51
52
|
get identifierType(): IdentifierType;
|
|
52
53
|
get jsonName(): string;
|
|
@@ -54,6 +55,7 @@ export declare class ObjectType extends DeclaredType {
|
|
|
54
55
|
get jsonZodSchemaFunctionName(): string;
|
|
55
56
|
get mutable(): boolean;
|
|
56
57
|
get ownProperties(): readonly ObjectType.Property[];
|
|
58
|
+
get ownShaclProperties(): readonly ObjectType.Property[];
|
|
57
59
|
get parentObjectTypes(): readonly ObjectType[];
|
|
58
60
|
get properties(): readonly ObjectType.Property[];
|
|
59
61
|
protected get thisVariable(): string;
|
|
@@ -82,6 +84,8 @@ export declare class ObjectType extends DeclaredType {
|
|
|
82
84
|
protected ensureAtMostOneSuperObjectType(): void;
|
|
83
85
|
}
|
|
84
86
|
export declare namespace ObjectType {
|
|
87
|
+
const IdentifierPrefixProperty: typeof _ObjectType.IdentifierPrefixProperty;
|
|
88
|
+
type IdentifierPrefixProperty = _ObjectType.IdentifierPrefixProperty;
|
|
85
89
|
const IdentifierProperty: typeof _ObjectType.IdentifierProperty;
|
|
86
90
|
type IdentifierProperty = _ObjectType.IdentifierProperty;
|
|
87
91
|
const Property: typeof _ObjectType.Property;
|
|
@@ -13,7 +13,6 @@ import { DeclaredType } from "./DeclaredType.js";
|
|
|
13
13
|
import { Import } from "./Import.js";
|
|
14
14
|
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
15
15
|
import * as _ObjectType from "./_ObjectType/index.js";
|
|
16
|
-
import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
|
|
17
16
|
import { objectInitializer } from "./objectInitializer.js";
|
|
18
17
|
export class ObjectType extends DeclaredType {
|
|
19
18
|
abstract;
|
|
@@ -101,7 +100,7 @@ export class ObjectType extends DeclaredType {
|
|
|
101
100
|
..._ObjectType.jsonSchemaFunctionDeclaration.bind(this)().toList(),
|
|
102
101
|
..._ObjectType.jsonUiSchemaFunctionDeclaration.bind(this)().toList(),
|
|
103
102
|
..._ObjectType.jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
|
|
104
|
-
..._ObjectType.
|
|
103
|
+
..._ObjectType.hashFunctionDeclarations.bind(this)(),
|
|
105
104
|
..._ObjectType.sparqlFunctionDeclarations.bind(this)(),
|
|
106
105
|
..._ObjectType.toJsonFunctionDeclaration.bind(this)().toList(),
|
|
107
106
|
..._ObjectType.toRdfFunctionDeclaration.bind(this)().toList(),
|
|
@@ -141,6 +140,12 @@ export class ObjectType extends DeclaredType {
|
|
|
141
140
|
return `hash${this.name}`;
|
|
142
141
|
return "hash";
|
|
143
142
|
}
|
|
143
|
+
get hashShaclPropertiesFunctionName() {
|
|
144
|
+
if (this.ancestorObjectTypes.length > 0 ||
|
|
145
|
+
this.descendantObjectTypes.length > 0)
|
|
146
|
+
return `_hash${this.name}ShaclProperties`;
|
|
147
|
+
return "_hashShaclProperties";
|
|
148
|
+
}
|
|
144
149
|
get identifierProperty() {
|
|
145
150
|
const identifierProperty = this.properties.find((property) => property instanceof ObjectType.IdentifierProperty);
|
|
146
151
|
invariant(identifierProperty);
|
|
@@ -187,16 +192,16 @@ export class ObjectType extends DeclaredType {
|
|
|
187
192
|
invariant(this.properties.length >= 2, this.name);
|
|
188
193
|
return this.properties;
|
|
189
194
|
}
|
|
190
|
-
return this.
|
|
191
|
-
|
|
195
|
+
return this.ownShaclProperties;
|
|
196
|
+
}
|
|
197
|
+
get ownShaclProperties() {
|
|
198
|
+
return this.properties.filter((property) => property instanceof _ObjectType.ShaclProperty);
|
|
192
199
|
}
|
|
193
200
|
get parentObjectTypes() {
|
|
194
201
|
return this.lazyParentObjectTypes();
|
|
195
202
|
}
|
|
196
203
|
get properties() {
|
|
197
|
-
const properties = this.lazyProperties()
|
|
198
|
-
.concat()
|
|
199
|
-
.sort((left, right) => left.name.localeCompare(right.name));
|
|
204
|
+
const properties = this.lazyProperties();
|
|
200
205
|
const propertyNames = new Set();
|
|
201
206
|
for (const property of properties) {
|
|
202
207
|
if (propertyNames.has(property.name)) {
|
|
@@ -319,37 +324,71 @@ export class ObjectType extends DeclaredType {
|
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
}
|
|
327
|
+
__decorate([
|
|
328
|
+
Memoize()
|
|
329
|
+
], ObjectType.prototype, "_discriminatorProperty", null);
|
|
322
330
|
__decorate([
|
|
323
331
|
Memoize()
|
|
324
332
|
], ObjectType.prototype, "ancestorObjectTypes", null);
|
|
333
|
+
__decorate([
|
|
334
|
+
Memoize()
|
|
335
|
+
], ObjectType.prototype, "conversions", null);
|
|
336
|
+
__decorate([
|
|
337
|
+
Memoize()
|
|
338
|
+
], ObjectType.prototype, "declarationImports", null);
|
|
325
339
|
__decorate([
|
|
326
340
|
Memoize()
|
|
327
341
|
], ObjectType.prototype, "descendantObjectTypes", null);
|
|
342
|
+
__decorate([
|
|
343
|
+
Memoize()
|
|
344
|
+
], ObjectType.prototype, "discriminatorProperty", null);
|
|
345
|
+
__decorate([
|
|
346
|
+
Memoize()
|
|
347
|
+
], ObjectType.prototype, "discriminatorValue", null);
|
|
348
|
+
__decorate([
|
|
349
|
+
Memoize()
|
|
350
|
+
], ObjectType.prototype, "equalsFunction", null);
|
|
328
351
|
__decorate([
|
|
329
352
|
Memoize()
|
|
330
353
|
], ObjectType.prototype, "hashFunctionName", null);
|
|
354
|
+
__decorate([
|
|
355
|
+
Memoize()
|
|
356
|
+
], ObjectType.prototype, "hashShaclPropertiesFunctionName", null);
|
|
331
357
|
__decorate([
|
|
332
358
|
Memoize()
|
|
333
359
|
], ObjectType.prototype, "identifierProperty", null);
|
|
334
360
|
__decorate([
|
|
335
361
|
Memoize()
|
|
336
362
|
], ObjectType.prototype, "identifierType", null);
|
|
363
|
+
__decorate([
|
|
364
|
+
Memoize()
|
|
365
|
+
], ObjectType.prototype, "jsonName", null);
|
|
337
366
|
__decorate([
|
|
338
367
|
Memoize()
|
|
339
368
|
], ObjectType.prototype, "jsonUiSchemaFunctionName", null);
|
|
340
369
|
__decorate([
|
|
341
370
|
Memoize()
|
|
342
371
|
], ObjectType.prototype, "jsonZodSchemaFunctionName", null);
|
|
372
|
+
__decorate([
|
|
373
|
+
Memoize()
|
|
374
|
+
], ObjectType.prototype, "mutable", null);
|
|
343
375
|
__decorate([
|
|
344
376
|
Memoize()
|
|
345
377
|
], ObjectType.prototype, "ownProperties", null);
|
|
378
|
+
__decorate([
|
|
379
|
+
Memoize()
|
|
380
|
+
], ObjectType.prototype, "ownShaclProperties", null);
|
|
346
381
|
__decorate([
|
|
347
382
|
Memoize()
|
|
348
383
|
], ObjectType.prototype, "parentObjectTypes", null);
|
|
349
384
|
__decorate([
|
|
350
385
|
Memoize()
|
|
351
386
|
], ObjectType.prototype, "properties", null);
|
|
387
|
+
__decorate([
|
|
388
|
+
Memoize()
|
|
389
|
+
], ObjectType.prototype, "thisVariable", null);
|
|
352
390
|
(function (ObjectType) {
|
|
391
|
+
ObjectType.IdentifierPrefixProperty = _ObjectType.IdentifierPrefixProperty;
|
|
353
392
|
ObjectType.IdentifierProperty = _ObjectType.IdentifierProperty;
|
|
354
393
|
ObjectType.Property = _ObjectType.Property;
|
|
355
394
|
ObjectType.ShaclProperty = _ObjectType.ShaclProperty;
|
|
@@ -10,7 +10,7 @@ import { invariant } from "ts-invariant";
|
|
|
10
10
|
import { StructureKind, } from "ts-morph";
|
|
11
11
|
import { Memoize } from "typescript-memoize";
|
|
12
12
|
import { DeclaredType } from "./DeclaredType.js";
|
|
13
|
-
import { hasherTypeConstraint } from "./_ObjectType/
|
|
13
|
+
import { hasherTypeConstraint } from "./_ObjectType/hashFunctionOrMethodDeclarations.js";
|
|
14
14
|
import { sparqlConstructQueryFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryFunctionDeclaration.js";
|
|
15
15
|
import { sparqlConstructQueryStringFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js";
|
|
16
16
|
import { objectInitializer } from "./objectInitializer.js";
|
|
@@ -19,6 +19,19 @@ import { StringType } from "./StringType.js";
|
|
|
19
19
|
import { TermType } from "./TermType.js";
|
|
20
20
|
import { UnionType } from "./UnionType.js";
|
|
21
21
|
import { tsName } from "./tsName.js";
|
|
22
|
+
function objectTypeNeedsIdentifierPrefixProperty(objectType) {
|
|
23
|
+
return objectType.identifierMintingStrategy
|
|
24
|
+
.map((identifierMintingStrategy) => {
|
|
25
|
+
switch (identifierMintingStrategy) {
|
|
26
|
+
case "blankNode":
|
|
27
|
+
return false;
|
|
28
|
+
case "sha256":
|
|
29
|
+
case "uuidv4":
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.orDefault(false);
|
|
34
|
+
}
|
|
22
35
|
export class TypeFactory {
|
|
23
36
|
cachedObjectTypePropertiesByIdentifier = new TermMap();
|
|
24
37
|
cachedObjectTypesByIdentifier = new TermMap();
|
|
@@ -235,39 +248,18 @@ export class TypeFactory {
|
|
|
235
248
|
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
236
249
|
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
237
250
|
lazyProperties: () => {
|
|
238
|
-
const properties = astType.properties
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
identifierPropertyClassDeclarationVisibility = Maybe.of("protected");
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
identifierPropertyClassDeclarationVisibility = Maybe.of("private");
|
|
254
|
-
}
|
|
255
|
-
const identifierProperty = new ObjectType.IdentifierProperty({
|
|
256
|
-
abstract: astType.abstract,
|
|
257
|
-
classDeclarationVisibility: identifierPropertyClassDeclarationVisibility,
|
|
258
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
259
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
260
|
-
name: astType.tsIdentifierPropertyName,
|
|
261
|
-
lazyObjectTypeMutable: () => properties.some((property) => property.mutable || property.type.mutable),
|
|
262
|
-
objectType: {
|
|
263
|
-
declarationType: astType.tsObjectDeclarationType,
|
|
264
|
-
features: astType.tsFeatures,
|
|
265
|
-
},
|
|
266
|
-
override: astType.parentObjectTypes.length > 0,
|
|
267
|
-
type: identifierType,
|
|
268
|
-
visibility: "public",
|
|
269
|
-
});
|
|
270
|
-
properties.push(identifierProperty);
|
|
251
|
+
const properties = astType.properties
|
|
252
|
+
.toSorted((left, right) => {
|
|
253
|
+
if (left.order < right.order) {
|
|
254
|
+
return -1;
|
|
255
|
+
}
|
|
256
|
+
if (left.order > right.order) {
|
|
257
|
+
return 1;
|
|
258
|
+
}
|
|
259
|
+
return tsName(left.name).localeCompare(tsName(right.name));
|
|
260
|
+
})
|
|
261
|
+
.map((astProperty) => this.createObjectTypePropertyFromAstProperty(astType, astProperty));
|
|
262
|
+
const lazyMutable = () => properties.some((property) => property.mutable || property.type.mutable);
|
|
271
263
|
// Type discriminator property
|
|
272
264
|
const typeDiscriminatorValues = new Set();
|
|
273
265
|
if (!astType.abstract) {
|
|
@@ -279,13 +271,14 @@ export class TypeFactory {
|
|
|
279
271
|
}
|
|
280
272
|
}
|
|
281
273
|
if (typeDiscriminatorValues.size > 0) {
|
|
282
|
-
properties.
|
|
274
|
+
properties.splice(0, 0, new ObjectType.TypeDiscriminatorProperty({
|
|
283
275
|
abstract: astType.abstract,
|
|
284
276
|
dataFactoryVariable: this.dataFactoryVariable,
|
|
285
277
|
name: astType.tsTypeDiscriminatorPropertyName,
|
|
286
278
|
objectType: {
|
|
287
279
|
declarationType: astType.tsObjectDeclarationType,
|
|
288
280
|
features: astType.tsFeatures,
|
|
281
|
+
mutable: lazyMutable,
|
|
289
282
|
},
|
|
290
283
|
override: objectType.parentObjectTypes.length > 0,
|
|
291
284
|
type: new ObjectType.TypeDiscriminatorProperty.Type({
|
|
@@ -296,7 +289,60 @@ export class TypeFactory {
|
|
|
296
289
|
value: objectType.discriminatorValue,
|
|
297
290
|
}));
|
|
298
291
|
}
|
|
299
|
-
|
|
292
|
+
// Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
|
|
293
|
+
if (objectTypeNeedsIdentifierPrefixProperty(astType)) {
|
|
294
|
+
properties.splice(0, 0, new ObjectType.IdentifierPrefixProperty({
|
|
295
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
296
|
+
own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
|
|
297
|
+
name: astType.tsIdentifierPrefixPropertyName,
|
|
298
|
+
objectType: {
|
|
299
|
+
declarationType: astType.tsObjectDeclarationType,
|
|
300
|
+
features: astType.tsFeatures,
|
|
301
|
+
mutable: lazyMutable,
|
|
302
|
+
},
|
|
303
|
+
type: new StringType({
|
|
304
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
305
|
+
defaultValue: Maybe.empty(),
|
|
306
|
+
hasValues: [],
|
|
307
|
+
in_: [],
|
|
308
|
+
languageIn: [],
|
|
309
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
310
|
+
primitiveIn: [],
|
|
311
|
+
}),
|
|
312
|
+
visibility: "protected",
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
315
|
+
// Every ObjectType has an identifier property. Some are abstract.
|
|
316
|
+
properties.splice(0, 0, new ObjectType.IdentifierProperty({
|
|
317
|
+
abstract: astType.abstract,
|
|
318
|
+
classDeclarationVisibility: (() => {
|
|
319
|
+
if (astType.abstract) {
|
|
320
|
+
// If the type is abstract, don't declare an identifier property.
|
|
321
|
+
return Maybe.empty();
|
|
322
|
+
}
|
|
323
|
+
if (astType.ancestorObjectTypes.some((ancestorObjectType) => !ancestorObjectType.abstract)) {
|
|
324
|
+
// If the type has a non-abstract ancestor, that ancestor will declare the identifier property.
|
|
325
|
+
return Maybe.empty();
|
|
326
|
+
}
|
|
327
|
+
if (astType.descendantObjectTypes.some((descendantObjectType) => !descendantObjectType.abstract)) {
|
|
328
|
+
// If the type has a non-abstract descendant, declare the identifier property for it.
|
|
329
|
+
return Maybe.of("protected");
|
|
330
|
+
}
|
|
331
|
+
return Maybe.of("private");
|
|
332
|
+
})(),
|
|
333
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
334
|
+
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
335
|
+
name: astType.tsIdentifierPropertyName,
|
|
336
|
+
objectType: {
|
|
337
|
+
declarationType: astType.tsObjectDeclarationType,
|
|
338
|
+
features: astType.tsFeatures,
|
|
339
|
+
mutable: lazyMutable,
|
|
340
|
+
},
|
|
341
|
+
override: astType.parentObjectTypes.length > 0,
|
|
342
|
+
type: identifierType,
|
|
343
|
+
visibility: "public",
|
|
344
|
+
}));
|
|
345
|
+
return properties;
|
|
300
346
|
},
|
|
301
347
|
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
302
348
|
name: tsName(astType.name),
|
|
@@ -321,6 +367,9 @@ export class TypeFactory {
|
|
|
321
367
|
objectType: {
|
|
322
368
|
declarationType: astObjectType.tsObjectDeclarationType,
|
|
323
369
|
features: astObjectType.tsFeatures,
|
|
370
|
+
mutable: () => {
|
|
371
|
+
throw new Error("not implemented");
|
|
372
|
+
},
|
|
324
373
|
},
|
|
325
374
|
name: tsName(astObjectTypeProperty.name),
|
|
326
375
|
path: astObjectTypeProperty.path.iri,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IdentifierType } from "generators/ts/IdentifierType.js";
|
|
2
|
+
import type { Import } from "generators/ts/Import.js";
|
|
3
|
+
import { Maybe } from "purify-ts";
|
|
4
|
+
import { type GetAccessorDeclarationStructure, type OptionalKind, type PropertyDeclarationStructure, type PropertySignatureStructure } from "ts-morph";
|
|
5
|
+
import type { StringType } from "../StringType.js";
|
|
6
|
+
import { Property } from "./Property.js";
|
|
7
|
+
export declare class IdentifierPrefixProperty extends Property<StringType> {
|
|
8
|
+
readonly equalsFunction = "strictEquals";
|
|
9
|
+
readonly mutable = false;
|
|
10
|
+
private readonly own;
|
|
11
|
+
constructor({ own, ...superParameters }: {
|
|
12
|
+
own: boolean;
|
|
13
|
+
type: StringType;
|
|
14
|
+
} & ConstructorParameters<typeof Property>[0]);
|
|
15
|
+
get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
16
|
+
get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
17
|
+
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
18
|
+
get declarationImports(): readonly Import[];
|
|
19
|
+
get interfacePropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
20
|
+
get jsonPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
21
|
+
get snippetDeclarations(): readonly string[];
|
|
22
|
+
classConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["classConstructorStatements"]>[0]): readonly string[];
|
|
23
|
+
fromJsonStatements(): readonly string[];
|
|
24
|
+
fromRdfStatements(): readonly string[];
|
|
25
|
+
hashStatements(): readonly string[];
|
|
26
|
+
interfaceConstructorStatements(): readonly string[];
|
|
27
|
+
jsonUiSchemaElement(): Maybe<string>;
|
|
28
|
+
jsonZodSchema(): ReturnType<Property<IdentifierType>["jsonZodSchema"]>;
|
|
29
|
+
sparqlConstructTemplateTriples(): readonly string[];
|
|
30
|
+
sparqlWherePatterns(): readonly string[];
|
|
31
|
+
toJsonObjectMember(): Maybe<string>;
|
|
32
|
+
toRdfStatements(): readonly string[];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=IdentifierPrefixProperty.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { invariant } from "ts-invariant";
|
|
3
|
+
import { Scope, } from "ts-morph";
|
|
4
|
+
import { SnippetDeclarations } from "../SnippetDeclarations.js";
|
|
5
|
+
import { Property } from "./Property.js";
|
|
6
|
+
export class IdentifierPrefixProperty extends Property {
|
|
7
|
+
equalsFunction = "strictEquals";
|
|
8
|
+
mutable = false;
|
|
9
|
+
own;
|
|
10
|
+
constructor({ own, ...superParameters }) {
|
|
11
|
+
super(superParameters);
|
|
12
|
+
invariant(this.visibility === "protected");
|
|
13
|
+
this.own = own;
|
|
14
|
+
}
|
|
15
|
+
get classGetAccessorDeclaration() {
|
|
16
|
+
return Maybe.of({
|
|
17
|
+
leadingTrivia: `protected ${!this.own ? "override " : ""}`,
|
|
18
|
+
name: this.name,
|
|
19
|
+
returnType: this.type.name,
|
|
20
|
+
statements: [
|
|
21
|
+
`return (typeof this._${this.name} !== "undefined") ? this._${this.name} : \`urn:shaclmate:\${this.type}:\``,
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
get classPropertyDeclaration() {
|
|
26
|
+
return this.own
|
|
27
|
+
? Maybe.of({
|
|
28
|
+
hasQuestionToken: true,
|
|
29
|
+
isReadonly: true,
|
|
30
|
+
name: `_${this.name}`,
|
|
31
|
+
scope: Scope.Protected,
|
|
32
|
+
type: this.type.name,
|
|
33
|
+
})
|
|
34
|
+
: Maybe.empty();
|
|
35
|
+
}
|
|
36
|
+
get constructorParametersPropertySignature() {
|
|
37
|
+
return Maybe.of({
|
|
38
|
+
hasQuestionToken: true,
|
|
39
|
+
isReadonly: true,
|
|
40
|
+
name: this.name,
|
|
41
|
+
type: this.type.name,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
get declarationImports() {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
get interfacePropertySignature() {
|
|
48
|
+
return Maybe.empty();
|
|
49
|
+
}
|
|
50
|
+
get jsonPropertySignature() {
|
|
51
|
+
return Maybe.empty();
|
|
52
|
+
}
|
|
53
|
+
get snippetDeclarations() {
|
|
54
|
+
const snippetDeclarations = [];
|
|
55
|
+
if (this.objectType.features.has("equals")) {
|
|
56
|
+
snippetDeclarations.push(SnippetDeclarations.strictEquals);
|
|
57
|
+
}
|
|
58
|
+
return snippetDeclarations;
|
|
59
|
+
}
|
|
60
|
+
classConstructorStatements({ variables, }) {
|
|
61
|
+
return this.classPropertyDeclaration
|
|
62
|
+
.map((classPropertyDeclaration) => [
|
|
63
|
+
`this.${classPropertyDeclaration.name} = ${variables.parameter};`,
|
|
64
|
+
])
|
|
65
|
+
.orDefault([]);
|
|
66
|
+
}
|
|
67
|
+
fromJsonStatements() {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
fromRdfStatements() {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
hashStatements() {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
interfaceConstructorStatements() {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
jsonUiSchemaElement() {
|
|
80
|
+
return Maybe.empty();
|
|
81
|
+
}
|
|
82
|
+
jsonZodSchema() {
|
|
83
|
+
return Maybe.empty();
|
|
84
|
+
}
|
|
85
|
+
sparqlConstructTemplateTriples() {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
sparqlWherePatterns() {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
toJsonObjectMember() {
|
|
92
|
+
return Maybe.empty();
|
|
93
|
+
}
|
|
94
|
+
toRdfStatements() {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=IdentifierPrefixProperty.js.map
|
|
@@ -10,12 +10,10 @@ export declare class IdentifierProperty extends Property<IdentifierType> {
|
|
|
10
10
|
readonly mutable = false;
|
|
11
11
|
private readonly classDeclarationVisibility;
|
|
12
12
|
private readonly identifierMintingStrategy;
|
|
13
|
-
private readonly lazyObjectTypeMutable;
|
|
14
13
|
private readonly override;
|
|
15
|
-
constructor({ abstract, classDeclarationVisibility,
|
|
14
|
+
constructor({ abstract, classDeclarationVisibility, identifierMintingStrategy, override, ...superParameters }: {
|
|
16
15
|
abstract: boolean;
|
|
17
16
|
classDeclarationVisibility: Maybe<PropertyVisibility>;
|
|
18
|
-
lazyObjectTypeMutable: () => boolean;
|
|
19
17
|
identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
20
18
|
override: boolean;
|
|
21
19
|
type: IdentifierType;
|
|
@@ -24,8 +22,8 @@ export declare class IdentifierProperty extends Property<IdentifierType> {
|
|
|
24
22
|
get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
25
23
|
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
26
24
|
get declarationImports(): readonly Import[];
|
|
27
|
-
get interfacePropertySignature(): OptionalKind<PropertySignatureStructure
|
|
28
|
-
get jsonPropertySignature(): OptionalKind<PropertySignatureStructure
|
|
25
|
+
get interfacePropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
26
|
+
get jsonPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
29
27
|
get snippetDeclarations(): readonly string[];
|
|
30
28
|
classConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["classConstructorStatements"]>[0]): readonly string[];
|
|
31
29
|
fromJsonStatements({ variables, }: Parameters<Property<IdentifierType>["fromJsonStatements"]>[0]): readonly string[];
|
|
@@ -36,7 +34,7 @@ export declare class IdentifierProperty extends Property<IdentifierType> {
|
|
|
36
34
|
jsonZodSchema({ variables, }: Parameters<Property<IdentifierType>["jsonZodSchema"]>[0]): ReturnType<Property<IdentifierType>["jsonZodSchema"]>;
|
|
37
35
|
sparqlConstructTemplateTriples(): readonly string[];
|
|
38
36
|
sparqlWherePatterns(): readonly string[];
|
|
39
|
-
toJsonObjectMember({ variables, }: Parameters<Property<IdentifierType>["toJsonObjectMember"]>[0]): string
|
|
37
|
+
toJsonObjectMember({ variables, }: Parameters<Property<IdentifierType>["toJsonObjectMember"]>[0]): Maybe<string>;
|
|
40
38
|
toRdfStatements(): readonly string[];
|
|
41
39
|
}
|
|
42
40
|
//# sourceMappingURL=IdentifierProperty.d.ts.map
|