@shaclmate/compiler 4.0.23 → 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.
- package/dist/ShapesGraphToAstTransformer.js +16 -16
- package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -5
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +4 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +11 -11
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +3 -3
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +6 -9
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +11 -12
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
- package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
- package/dist/ast/ListType.d.ts +1 -8
- package/dist/ast/ListType.js +1 -6
- package/dist/ast/ObjectType.d.ts +1 -8
- package/dist/ast/ObjectType.js +1 -7
- package/dist/generators/ts/AbstractUnionType.js +1 -1
- package/dist/generators/ts/ListType.d.ts +1 -5
- package/dist/generators/ts/ListType.js +8 -27
- package/dist/generators/ts/NamedObjectType.d.ts +1 -9
- package/dist/generators/ts/NamedObjectType.js +1 -29
- package/dist/generators/ts/NamedObjectUnionType.js +1 -1
- package/dist/generators/ts/TypeFactory.js +8 -46
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +10 -10
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +6 -0
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +1 -3
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +17 -5
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +5 -15
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +32 -202
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +1 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +10 -9
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js +4 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +5 -10
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +13 -9
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js +8 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +4 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +9 -5
- package/dist/generators/ts/_NamedObjectType/Property.d.ts +1 -2
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -3
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +3 -12
- package/dist/generators/ts/_snippets/snippets_LazyObject.js +2 -2
- package/dist/generators/ts/_snippets/snippets_LazyObjectOption.js +2 -2
- package/dist/generators/ts/_snippets/snippets_LazyObjectSet.js +2 -2
- package/dist/generators/ts/imports.d.ts +0 -2
- package/dist/generators/ts/imports.js +0 -2
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +1 -1
- package/dist/input/generated.d.ts +10 -47
- package/dist/input/generated.js +105 -154
- package/package.json +2 -2
- package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +0 -6
- package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +0 -32
- package/dist/enums/IdentifierMintingStrategy.d.ts +0 -9
- package/dist/enums/IdentifierMintingStrategy.js +0 -18
- package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.d.ts +0 -33
- package/dist/generators/ts/_NamedObjectType/IdentifierPrefixProperty.js +0 -92
|
@@ -12,14 +12,12 @@ import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
|
|
|
12
12
|
import { snippets } from "./snippets.js";
|
|
13
13
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
14
14
|
export class ListType extends AbstractCollectionType {
|
|
15
|
-
identifierMintingStrategy;
|
|
16
15
|
identifierNodeKind;
|
|
17
16
|
toRdfTypes;
|
|
18
17
|
kind = "ListType";
|
|
19
|
-
constructor({ identifierNodeKind,
|
|
18
|
+
constructor({ identifierNodeKind, toRdfTypes, ...superParameters }) {
|
|
20
19
|
super(superParameters);
|
|
21
20
|
this.identifierNodeKind = identifierNodeKind;
|
|
22
|
-
this.identifierMintingStrategy = identifierMintingStrategy.orDefault(identifierNodeKind === "BlankNode" ? "blankNode" : "sha256");
|
|
23
21
|
this.toRdfTypes = toRdfTypes;
|
|
24
22
|
}
|
|
25
23
|
get valueSparqlConstructTriplesFunction() {
|
|
@@ -48,43 +46,26 @@ export class ListType extends AbstractCollectionType {
|
|
|
48
46
|
return new AbstractCollectionType.JsonType(code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().name})[]`);
|
|
49
47
|
}
|
|
50
48
|
toRdfResourceValuesExpression({ variables, }) {
|
|
51
|
-
let
|
|
49
|
+
let mintListIdentifierFunction;
|
|
50
|
+
let mintSubListIdentifierFunction;
|
|
52
51
|
let resourceTypeName;
|
|
53
|
-
let subListIdentifier;
|
|
54
52
|
switch (this.identifierNodeKind) {
|
|
55
53
|
case "BlankNode": {
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
mintListIdentifierFunction =
|
|
55
|
+
mintSubListIdentifierFunction = code `(() => ${imports.dataFactory}.blankNode())`;
|
|
58
56
|
resourceTypeName = code `${imports.Resource}<${imports.BlankNode}>`;
|
|
59
57
|
break;
|
|
60
58
|
}
|
|
61
59
|
case "IRI": {
|
|
62
|
-
switch (this.identifierMintingStrategy) {
|
|
63
|
-
case "blankNode":
|
|
64
|
-
throw new RangeError(this.identifierMintingStrategy);
|
|
65
|
-
case "sha256":
|
|
66
|
-
listIdentifier = code `${imports.dataFactory}.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
|
|
67
|
-
(hasher, item) => {
|
|
68
|
-
${joinCode(this.itemType.hashStatements({ depth: 0, variables: { hasher: code `hasher`, value: code `item` } }).concat())}
|
|
69
|
-
return hasher;
|
|
70
|
-
},
|
|
71
|
-
${imports.sha256}.create(),
|
|
72
|
-
)}\`)`;
|
|
73
|
-
break;
|
|
74
|
-
case "uuidv4":
|
|
75
|
-
listIdentifier = code `${imports.dataFactory}.namedNode(\`urn:shaclmate:list:\${${imports.uuid}.v4()}\`)`;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
60
|
resourceTypeName = code `${imports.Resource}<${imports.NamedNode}>`;
|
|
79
|
-
|
|
80
|
-
break;
|
|
61
|
+
throw new RangeError("list IRI minting is unsupported");
|
|
81
62
|
}
|
|
82
63
|
}
|
|
83
64
|
return code `[${variables.value}.length > 0 ? ${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
|
|
84
65
|
if (itemIndex === 0) {
|
|
85
66
|
currentSubListResource = listResource;
|
|
86
67
|
} else {
|
|
87
|
-
const newSubListResource = ${variables.resourceSet}.resource(${
|
|
68
|
+
const newSubListResource = ${variables.resourceSet}.resource(${mintSubListIdentifierFunction}());
|
|
88
69
|
currentSubListResource!.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, newSubListResource.identifier, ${variables.graph});
|
|
89
70
|
currentSubListResource = newSubListResource;
|
|
90
71
|
}
|
|
@@ -101,7 +82,7 @@ export class ListType extends AbstractCollectionType {
|
|
|
101
82
|
},
|
|
102
83
|
{
|
|
103
84
|
currentSubListResource: null,
|
|
104
|
-
listResource: resourceSet.resource(${
|
|
85
|
+
listResource: resourceSet.resource(${mintListIdentifierFunction}()),
|
|
105
86
|
} as {
|
|
106
87
|
currentSubListResource: ${resourceTypeName} | null;
|
|
107
88
|
listResource: ${resourceTypeName};
|
|
@@ -3,7 +3,6 @@ import { Maybe, NonEmptyList } from "purify-ts";
|
|
|
3
3
|
import type { TsFeature } from "../../enums/TsFeature.js";
|
|
4
4
|
import type { TsObjectDeclarationType } from "../../enums/TsObjectDeclarationType.js";
|
|
5
5
|
import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
|
|
6
|
-
import { IdentifierPrefixProperty as _IdentifierPrefixProperty } from "./_NamedObjectType/IdentifierPrefixProperty.js";
|
|
7
6
|
import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
|
|
8
7
|
import type { Property as _Property } from "./_NamedObjectType/Property.js";
|
|
9
8
|
import { ShaclProperty as _ShaclProperty } from "./_NamedObjectType/ShaclProperty.js";
|
|
@@ -29,7 +28,7 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
29
28
|
readonly staticModuleName: string;
|
|
30
29
|
readonly synthetic: boolean;
|
|
31
30
|
readonly typeofs: NonEmptyList<"object">;
|
|
32
|
-
constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty,
|
|
31
|
+
constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }: {
|
|
33
32
|
abstract: boolean;
|
|
34
33
|
comment: Maybe<string>;
|
|
35
34
|
declarationType: TsObjectDeclarationType;
|
|
@@ -42,7 +41,6 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
42
41
|
lazyAncestorObjectTypes: () => readonly NamedObjectType[];
|
|
43
42
|
lazyChildObjectTypes: () => readonly NamedObjectType[];
|
|
44
43
|
lazyDiscriminantProperty: (namedObjectType: NamedObjectType) => NamedObjectType.DiscriminantProperty;
|
|
45
|
-
lazyIdentifierProperty: (namedObjectType: NamedObjectType) => NamedObjectType.IdentifierProperty;
|
|
46
44
|
lazyDescendantObjectTypes: () => readonly NamedObjectType[];
|
|
47
45
|
lazyParentObjectTypes: () => readonly NamedObjectType[];
|
|
48
46
|
lazyProperties: (namedObjectType: NamedObjectType) => readonly NamedObjectType.Property[];
|
|
@@ -67,12 +65,9 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
67
65
|
get filterType(): Code;
|
|
68
66
|
get fromRdfTypeVariable(): Maybe<Code>;
|
|
69
67
|
get graphqlType(): AbstractType.GraphqlType;
|
|
70
|
-
get identifierProperty(): NamedObjectType.IdentifierProperty;
|
|
71
68
|
get identifierTypeAlias(): Code;
|
|
72
69
|
get mutable(): boolean;
|
|
73
70
|
get objectSetMethodNames(): NamedObjectType.ObjectSetMethodNames;
|
|
74
|
-
get ownProperties(): readonly NamedObjectType.Property[];
|
|
75
|
-
get ownShaclProperties(): readonly NamedObjectType.ShaclProperty<Type>[];
|
|
76
71
|
get parentObjectTypes(): readonly NamedObjectType[];
|
|
77
72
|
get properties(): readonly NamedObjectType.Property[];
|
|
78
73
|
get schema(): Code;
|
|
@@ -104,13 +99,10 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
104
99
|
private readonly lazyChildObjectTypes;
|
|
105
100
|
private readonly lazyDescendantObjectTypes;
|
|
106
101
|
private readonly lazyDiscriminantProperty;
|
|
107
|
-
private readonly lazyIdentifierProperty;
|
|
108
102
|
private readonly lazyParentObjectTypes;
|
|
109
103
|
private readonly lazyProperties;
|
|
110
104
|
}
|
|
111
105
|
export declare namespace NamedObjectType {
|
|
112
|
-
const IdentifierPrefixProperty: typeof _IdentifierPrefixProperty;
|
|
113
|
-
type IdentifierPrefixProperty = _IdentifierPrefixProperty;
|
|
114
106
|
const IdentifierProperty: typeof _IdentifierProperty;
|
|
115
107
|
type IdentifierProperty = _IdentifierProperty;
|
|
116
108
|
type ObjectSetMethodNames = {
|
|
@@ -9,7 +9,6 @@ import { camelCase } from "change-case";
|
|
|
9
9
|
import { Maybe, NonEmptyList } from "purify-ts";
|
|
10
10
|
import { Memoize } from "typescript-memoize";
|
|
11
11
|
import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
|
|
12
|
-
import { IdentifierPrefixProperty as _IdentifierPrefixProperty } from "./_NamedObjectType/IdentifierPrefixProperty.js";
|
|
13
12
|
import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
|
|
14
13
|
import { identifierTypeDeclarations } from "./_NamedObjectType/identifierTypeDeclarations.js";
|
|
15
14
|
import { NamedObjectType_classDeclaration } from "./_NamedObjectType/NamedObjectType_classDeclaration.js";
|
|
@@ -63,7 +62,7 @@ export class NamedObjectType extends AbstractType {
|
|
|
63
62
|
staticModuleName;
|
|
64
63
|
synthetic;
|
|
65
64
|
typeofs = NonEmptyList(["object"]);
|
|
66
|
-
constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty,
|
|
65
|
+
constructor({ abstract, declarationType, extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
|
|
67
66
|
super(superParameters);
|
|
68
67
|
this.abstract = abstract;
|
|
69
68
|
this.declarationType = declarationType;
|
|
@@ -77,7 +76,6 @@ export class NamedObjectType extends AbstractType {
|
|
|
77
76
|
this.lazyChildObjectTypes = lazyChildObjectTypes;
|
|
78
77
|
this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
|
|
79
78
|
this.lazyDiscriminantProperty = lazyDiscriminantProperty;
|
|
80
|
-
this.lazyIdentifierProperty = lazyIdentifierProperty;
|
|
81
79
|
this.lazyParentObjectTypes = lazyParentObjectTypes;
|
|
82
80
|
this.lazyProperties = lazyProperties;
|
|
83
81
|
this.name = name;
|
|
@@ -189,9 +187,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
189
187
|
get graphqlType() {
|
|
190
188
|
return new AbstractType.GraphqlType(code `${this.staticModuleName}.${syntheticNamePrefix}GraphQL`);
|
|
191
189
|
}
|
|
192
|
-
get identifierProperty() {
|
|
193
|
-
return this.lazyIdentifierProperty(this);
|
|
194
|
-
}
|
|
195
190
|
get identifierTypeAlias() {
|
|
196
191
|
return code `${this.staticModuleName}.${syntheticNamePrefix}Identifier`;
|
|
197
192
|
}
|
|
@@ -201,18 +196,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
201
196
|
get objectSetMethodNames() {
|
|
202
197
|
return NamedObjectType_objectSetMethodNames.call(this);
|
|
203
198
|
}
|
|
204
|
-
get ownProperties() {
|
|
205
|
-
if (this.parentObjectTypes.length === 0) {
|
|
206
|
-
// Consider that a root of the object type hierarchy "owns" the identifier and type discriminant properties
|
|
207
|
-
// for all of its subtypes in the hierarchy.
|
|
208
|
-
// invariant(this.properties.length >= 2, this.name);
|
|
209
|
-
return this.properties;
|
|
210
|
-
}
|
|
211
|
-
return this.ownShaclProperties;
|
|
212
|
-
}
|
|
213
|
-
get ownShaclProperties() {
|
|
214
|
-
return this.properties.filter((property) => property.kind === "ShaclProperty");
|
|
215
|
-
}
|
|
216
199
|
get parentObjectTypes() {
|
|
217
200
|
return this.lazyParentObjectTypes();
|
|
218
201
|
}
|
|
@@ -335,7 +318,6 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
335
318
|
lazyChildObjectTypes;
|
|
336
319
|
lazyDescendantObjectTypes;
|
|
337
320
|
lazyDiscriminantProperty;
|
|
338
|
-
lazyIdentifierProperty;
|
|
339
321
|
lazyParentObjectTypes;
|
|
340
322
|
lazyProperties;
|
|
341
323
|
}
|
|
@@ -381,9 +363,6 @@ __decorate([
|
|
|
381
363
|
__decorate([
|
|
382
364
|
Memoize()
|
|
383
365
|
], NamedObjectType.prototype, "graphqlType", null);
|
|
384
|
-
__decorate([
|
|
385
|
-
Memoize()
|
|
386
|
-
], NamedObjectType.prototype, "identifierProperty", null);
|
|
387
366
|
__decorate([
|
|
388
367
|
Memoize()
|
|
389
368
|
], NamedObjectType.prototype, "identifierTypeAlias", null);
|
|
@@ -393,12 +372,6 @@ __decorate([
|
|
|
393
372
|
__decorate([
|
|
394
373
|
Memoize()
|
|
395
374
|
], NamedObjectType.prototype, "objectSetMethodNames", null);
|
|
396
|
-
__decorate([
|
|
397
|
-
Memoize()
|
|
398
|
-
], NamedObjectType.prototype, "ownProperties", null);
|
|
399
|
-
__decorate([
|
|
400
|
-
Memoize()
|
|
401
|
-
], NamedObjectType.prototype, "ownShaclProperties", null);
|
|
402
375
|
__decorate([
|
|
403
376
|
Memoize()
|
|
404
377
|
], NamedObjectType.prototype, "parentObjectTypes", null);
|
|
@@ -430,7 +403,6 @@ __decorate([
|
|
|
430
403
|
Memoize()
|
|
431
404
|
], NamedObjectType.prototype, "jsonType", null);
|
|
432
405
|
(function (NamedObjectType) {
|
|
433
|
-
NamedObjectType.IdentifierPrefixProperty = _IdentifierPrefixProperty;
|
|
434
406
|
NamedObjectType.IdentifierProperty = _IdentifierProperty;
|
|
435
407
|
NamedObjectType.ShaclProperty = _ShaclProperty;
|
|
436
408
|
NamedObjectType.DiscriminantProperty = _DiscriminantProperty;
|
|
@@ -142,7 +142,7 @@ export namespace ${syntheticNamePrefix}Identifier {
|
|
|
142
142
|
get schemaVariableStatement() {
|
|
143
143
|
const commonPropertiesByName = {};
|
|
144
144
|
this.concreteMembers.forEach((member, memberI) => {
|
|
145
|
-
for (const memberTypeProperty of member.type.
|
|
145
|
+
for (const memberTypeProperty of member.type.properties.concat(member.type.ancestorObjectTypes.flatMap((ancestorObjectType) => ancestorObjectType.properties))) {
|
|
146
146
|
if (memberTypeProperty.kind !== "ShaclProperty") {
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
@@ -2,7 +2,7 @@ import TermMap from "@rdfjs/term-map";
|
|
|
2
2
|
import TermSet from "@rdfjs/term-set";
|
|
3
3
|
import { LiteralDecoder, literalDatatypeDefinitions } from "@rdfx/literal";
|
|
4
4
|
import base62 from "@sindresorhus/base62";
|
|
5
|
-
import { rdf
|
|
5
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
6
6
|
import { Maybe } from "purify-ts";
|
|
7
7
|
import reservedTsIdentifiers_ from "reserved-identifiers";
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
@@ -112,16 +112,6 @@ export class TypeFactory {
|
|
|
112
112
|
visibility: "public",
|
|
113
113
|
});
|
|
114
114
|
},
|
|
115
|
-
lazyIdentifierProperty: (namedObjectType) => new NamedObjectType.IdentifierProperty({
|
|
116
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
117
|
-
identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
|
|
118
|
-
logger: this.logger,
|
|
119
|
-
name: `${syntheticNamePrefix}identifier`,
|
|
120
|
-
namedObjectType,
|
|
121
|
-
type: identifierType,
|
|
122
|
-
typeAlias: code `${staticModuleName}.${syntheticNamePrefix}Identifier`,
|
|
123
|
-
visibility: "public",
|
|
124
|
-
}),
|
|
125
115
|
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createNamedObjectType(astType)),
|
|
126
116
|
lazyProperties: (namedObjectType) => {
|
|
127
117
|
const properties = astType.properties
|
|
@@ -142,28 +132,17 @@ export class TypeFactory {
|
|
|
142
132
|
namedObjectType._discriminantProperty.type.descendantValues.length > 0) {
|
|
143
133
|
properties.splice(0, 0, namedObjectType._discriminantProperty);
|
|
144
134
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
properties.splice(0, 0, new NamedObjectType.
|
|
135
|
+
if (namedObjectType.declarationType === "interface" ||
|
|
136
|
+
namedObjectType.parentObjectTypes.length === 0) {
|
|
137
|
+
properties.splice(0, 0, new NamedObjectType.IdentifierProperty({
|
|
148
138
|
logger: this.logger,
|
|
149
|
-
name: `${syntheticNamePrefix}
|
|
139
|
+
name: `${syntheticNamePrefix}identifier`,
|
|
150
140
|
namedObjectType,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
datatype: xsd.string,
|
|
155
|
-
hasValues: [],
|
|
156
|
-
in_: [],
|
|
157
|
-
label: astType.label,
|
|
158
|
-
logger: this.logger,
|
|
159
|
-
languageIn: [],
|
|
160
|
-
primitiveIn: [],
|
|
161
|
-
}),
|
|
162
|
-
visibility: "protected",
|
|
141
|
+
type: identifierType,
|
|
142
|
+
typeAlias: code `${staticModuleName}.${syntheticNamePrefix}Identifier`,
|
|
143
|
+
visibility: "public",
|
|
163
144
|
}));
|
|
164
145
|
}
|
|
165
|
-
// Every NamedObjectType has an identifier property. Some are abstract.
|
|
166
|
-
properties.splice(0, 0, namedObjectType.identifierProperty);
|
|
167
146
|
return properties;
|
|
168
147
|
},
|
|
169
148
|
logger: this.logger,
|
|
@@ -321,7 +300,6 @@ export class TypeFactory {
|
|
|
321
300
|
logger: this.logger,
|
|
322
301
|
minCount: 0,
|
|
323
302
|
mutable: astType.mutable,
|
|
324
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
325
303
|
toRdfTypes: astType.toRdfTypes,
|
|
326
304
|
});
|
|
327
305
|
}
|
|
@@ -502,22 +480,6 @@ export class TypeFactory {
|
|
|
502
480
|
});
|
|
503
481
|
}
|
|
504
482
|
}
|
|
505
|
-
function namedObjectTypeNeedsIdentifierPrefixProperty(namedObjectType) {
|
|
506
|
-
return namedObjectType.identifierMintingStrategy
|
|
507
|
-
.map((identifierMintingStrategy) => {
|
|
508
|
-
switch (identifierMintingStrategy) {
|
|
509
|
-
case "blankNode":
|
|
510
|
-
return false;
|
|
511
|
-
case "sha256":
|
|
512
|
-
case "uuidv4":
|
|
513
|
-
return true;
|
|
514
|
-
default:
|
|
515
|
-
identifierMintingStrategy;
|
|
516
|
-
throw new RangeError(identifierMintingStrategy);
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
.orDefault(false);
|
|
520
|
-
}
|
|
521
483
|
function tsName(name, options) {
|
|
522
484
|
if (name[0] === "$") {
|
|
523
485
|
return name;
|
|
@@ -12,13 +12,9 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
12
12
|
*/
|
|
13
13
|
abstract readonly constructorParametersSignature: Maybe<Code>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Property declaration to include in a class or interface declaration of the object type.
|
|
16
16
|
*/
|
|
17
|
-
abstract readonly declaration:
|
|
18
|
-
/**
|
|
19
|
-
* Function declaration that takes two values of the property and compares them, returning an $EqualsResult.
|
|
20
|
-
*/
|
|
21
|
-
abstract readonly equalsFunction: Maybe<Code>;
|
|
17
|
+
abstract readonly declaration: Code;
|
|
22
18
|
/**
|
|
23
19
|
* Optional property in the object type's filter.
|
|
24
20
|
*/
|
|
@@ -26,10 +22,6 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
26
22
|
readonly name: string;
|
|
27
23
|
readonly type: Code;
|
|
28
24
|
}>;
|
|
29
|
-
/**
|
|
30
|
-
* Optional get accessor to include in a class declaration of the object type.
|
|
31
|
-
*/
|
|
32
|
-
abstract readonly getAccessorDeclaration: Maybe<Code>;
|
|
33
25
|
/**
|
|
34
26
|
* GraphQL.js field definition.
|
|
35
27
|
*/
|
|
@@ -92,6 +84,14 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
92
84
|
kind: Code;
|
|
93
85
|
type: Code;
|
|
94
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Expression to access the value of this property on an object instance. May evaluate a thunk.
|
|
89
|
+
*/
|
|
90
|
+
accessExpression({ variables }: {
|
|
91
|
+
variables: {
|
|
92
|
+
object: Code;
|
|
93
|
+
};
|
|
94
|
+
}): Code;
|
|
95
95
|
/**
|
|
96
96
|
* Statements to assign the parameter of described by constructorParametersSignature to a class or interface member.
|
|
97
97
|
*/
|
|
@@ -44,6 +44,12 @@ export class AbstractProperty {
|
|
|
44
44
|
type: code `() => (${this.type.schema})`,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Expression to access the value of this property on an object instance. May evaluate a thunk.
|
|
49
|
+
*/
|
|
50
|
+
accessExpression({ variables }) {
|
|
51
|
+
return code `${variables.object}.${this.name}`;
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
__decorate([
|
|
49
55
|
Memoize()
|
|
@@ -3,9 +3,7 @@ import { type Code } from "../ts-poet-wrapper.js";
|
|
|
3
3
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
4
4
|
export declare class DiscriminantProperty extends AbstractProperty<DiscriminantProperty.Type> {
|
|
5
5
|
readonly constructorParametersSignature: Maybe<Code>;
|
|
6
|
-
readonly equalsFunction: Maybe<Code>;
|
|
7
6
|
readonly filterProperty: AbstractProperty<DiscriminantProperty.Type>["filterProperty"];
|
|
8
|
-
readonly getAccessorDeclaration: Maybe<Code>;
|
|
9
7
|
readonly graphqlField: AbstractProperty<DiscriminantProperty.Type>["graphqlField"];
|
|
10
8
|
readonly kind = "DiscriminantProperty";
|
|
11
9
|
readonly mutable = false;
|
|
@@ -13,7 +11,7 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
|
|
|
13
11
|
constructor({ type, ...superParameters }: {
|
|
14
12
|
type: DiscriminantProperty.Type;
|
|
15
13
|
} & ConstructorParameters<typeof AbstractProperty>[0]);
|
|
16
|
-
get declaration():
|
|
14
|
+
get declaration(): Code;
|
|
17
15
|
get jsonSchema(): AbstractProperty<DiscriminantProperty.Type>["jsonSchema"];
|
|
18
16
|
get jsonSignature(): Maybe<Code>;
|
|
19
17
|
private get abstract();
|
|
@@ -9,14 +9,11 @@ import { invariant } from "ts-invariant";
|
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { imports } from "../imports.js";
|
|
11
11
|
import { removeUndefined } from "../removeUndefined.js";
|
|
12
|
-
import { snippets } from "../snippets.js";
|
|
13
12
|
import { arrayOf, code, literalOf } from "../ts-poet-wrapper.js";
|
|
14
13
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
15
14
|
export class DiscriminantProperty extends AbstractProperty {
|
|
16
15
|
constructorParametersSignature = Maybe.empty();
|
|
17
|
-
equalsFunction = Maybe.of(code `${snippets.strictEquals}`);
|
|
18
16
|
filterProperty = Maybe.empty();
|
|
19
|
-
getAccessorDeclaration = Maybe.empty();
|
|
20
17
|
graphqlField = Maybe.empty();
|
|
21
18
|
kind = "DiscriminantProperty";
|
|
22
19
|
mutable = false;
|
|
@@ -28,15 +25,18 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
28
25
|
get declaration() {
|
|
29
26
|
switch (this.namedObjectType.declarationType) {
|
|
30
27
|
case "class":
|
|
31
|
-
return
|
|
28
|
+
return code `${this.abstract ? "abstract " : ""}${this.override ? "override " : ""}readonly ${this.name}: ${this.type.name}${!this.abstract ? code ` = ${this.initializer};` : ";"}`;
|
|
32
29
|
case "interface":
|
|
33
|
-
return
|
|
30
|
+
return code `readonly ${this.name}: ${this.type.name};`;
|
|
34
31
|
default:
|
|
35
32
|
this.namedObjectType.declarationType;
|
|
36
33
|
throw new Error("should never reach this point");
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
get jsonSchema() {
|
|
37
|
+
if (this.override) {
|
|
38
|
+
return Maybe.empty();
|
|
39
|
+
}
|
|
40
40
|
return Maybe.of({
|
|
41
41
|
key: this.name,
|
|
42
42
|
schema: this.type.values.length > 1
|
|
@@ -45,6 +45,9 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
get jsonSignature() {
|
|
48
|
+
if (this.override) {
|
|
49
|
+
return Maybe.empty();
|
|
50
|
+
}
|
|
48
51
|
return Maybe.of(code `readonly ${this.name}: ${this.type.name}`);
|
|
49
52
|
}
|
|
50
53
|
get abstract() {
|
|
@@ -80,9 +83,15 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
80
83
|
: Maybe.empty();
|
|
81
84
|
}
|
|
82
85
|
hashStatements({ variables, }) {
|
|
86
|
+
if (this.override) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
83
89
|
return [code `${variables.hasher}.update(${variables.value});`];
|
|
84
90
|
}
|
|
85
91
|
jsonUiSchemaElement({ variables, }) {
|
|
92
|
+
if (this.override) {
|
|
93
|
+
return Maybe.empty();
|
|
94
|
+
}
|
|
86
95
|
const scope = code `\`\${${variables.scopePrefix}}/properties/${this.name}\``;
|
|
87
96
|
return Maybe.of(code `{ rule: { condition: { schema: { const: ${this.initializer} }, scope: ${scope} }, effect: "HIDE" }, scope: ${scope}, type: "Control" }`);
|
|
88
97
|
}
|
|
@@ -93,6 +102,9 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
93
102
|
return Maybe.empty();
|
|
94
103
|
}
|
|
95
104
|
toJsonObjectMemberExpression({ variables, }) {
|
|
105
|
+
if (this.override) {
|
|
106
|
+
return Maybe.empty();
|
|
107
|
+
}
|
|
96
108
|
return Maybe.of(code `${this.name}: ${variables.value}`);
|
|
97
109
|
}
|
|
98
110
|
toRdfRdfResourceValuesStatements() {
|
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import type { IdentifierMintingStrategy } from "../../../enums/IdentifierMintingStrategy.js";
|
|
3
2
|
import type { BlankNodeType } from "../BlankNodeType.js";
|
|
4
3
|
import type { IdentifierType } from "../IdentifierType.js";
|
|
5
4
|
import type { IriType } from "../IriType.js";
|
|
6
5
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
7
6
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
8
7
|
export declare class IdentifierProperty extends AbstractProperty<BlankNodeType | IdentifierType | IriType> {
|
|
9
|
-
private readonly identifierMintingStrategy;
|
|
10
|
-
private readonly identifierPrefixPropertyName;
|
|
11
8
|
private readonly typeAlias;
|
|
12
9
|
readonly kind = "IdentifierProperty";
|
|
13
10
|
readonly mutable = false;
|
|
14
11
|
readonly recursive = false;
|
|
15
|
-
constructor({
|
|
16
|
-
identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
17
|
-
identifierPrefixPropertyName: string;
|
|
12
|
+
constructor({ typeAlias, ...superParameters }: {
|
|
18
13
|
type: BlankNodeType | IdentifierType | IriType;
|
|
19
14
|
typeAlias: Code;
|
|
20
15
|
} & ConstructorParameters<typeof AbstractProperty>[0]);
|
|
21
16
|
get constructorParametersSignature(): Maybe<Code>;
|
|
22
|
-
get declaration():
|
|
23
|
-
get equalsFunction(): Maybe<Code>;
|
|
17
|
+
get declaration(): Code;
|
|
24
18
|
get filterProperty(): Maybe<{
|
|
25
19
|
name: string;
|
|
26
20
|
type: Code;
|
|
27
21
|
}>;
|
|
28
|
-
get getAccessorDeclaration(): Maybe<Code>;
|
|
29
22
|
get graphqlField(): AbstractProperty<IdentifierType>["graphqlField"];
|
|
30
|
-
get jsonSignature(): Maybe<Code>;
|
|
31
23
|
get jsonSchema(): AbstractProperty<IdentifierType>["jsonSchema"];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
private get declarationName();
|
|
35
|
-
private get override();
|
|
24
|
+
get jsonSignature(): Maybe<Code>;
|
|
25
|
+
accessExpression({ variables, }: Parameters<AbstractProperty<BlankNodeType | IdentifierType | IriType>["accessExpression"]>[0]): Code;
|
|
36
26
|
constructorStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["constructorStatements"]>[0]): readonly Code[];
|
|
37
27
|
fromJsonStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["fromJsonStatements"]>[0]): readonly Code[];
|
|
38
|
-
toStringExpression(parameters: Parameters<AbstractProperty<IdentifierType>["toStringExpression"]>[0]): Maybe<Code>;
|
|
39
28
|
fromRdfResourceValuesExpression({ variables, }: Parameters<AbstractProperty<IdentifierType>["fromRdfResourceValuesExpression"]>[0]): Maybe<Code>;
|
|
40
29
|
hashStatements({ variables, }: Parameters<AbstractProperty<IdentifierType>["hashStatements"]>[0]): readonly Code[];
|
|
41
30
|
jsonUiSchemaElement({ variables, }: Parameters<AbstractProperty<IdentifierType>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
@@ -46,5 +35,6 @@ export declare class IdentifierProperty extends AbstractProperty<BlankNodeType |
|
|
|
46
35
|
}>;
|
|
47
36
|
toJsonObjectMemberExpression({ variables, }: Parameters<AbstractProperty<IdentifierType>["toJsonObjectMemberExpression"]>[0]): Maybe<Code>;
|
|
48
37
|
toRdfRdfResourceValuesStatements(): readonly Code[];
|
|
38
|
+
toStringExpression(parameters: Parameters<AbstractProperty<IdentifierType>["toStringExpression"]>[0]): Maybe<Code>;
|
|
49
39
|
}
|
|
50
40
|
//# sourceMappingURL=IdentifierProperty.d.ts.map
|