@shaclmate/compiler 4.0.66 → 4.0.67
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.
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { Logger } from "ts-log";
|
|
3
|
+
import type { ObjectType } from "./ObjectType.js";
|
|
4
|
+
import type { Reusables } from "./Reusables.js";
|
|
5
|
+
import type { TsGenerator } from "./TsGenerator.js";
|
|
6
|
+
import { type Code } from "./ts-poet-wrapper.js";
|
|
7
|
+
/**
|
|
8
|
+
* The $Object discriminated union used in type guard functions (isSomeObjectType(object: $Object)) and some convenience methods.
|
|
9
|
+
*/
|
|
10
|
+
export declare class UberObjectDiscriminatedUnionType {
|
|
11
|
+
private readonly configuration;
|
|
12
|
+
private readonly members;
|
|
13
|
+
private readonly reusables;
|
|
14
|
+
constructor({ configuration, members, reusables, }: {
|
|
15
|
+
configuration: TsGenerator.Configuration;
|
|
16
|
+
logger: Logger;
|
|
17
|
+
members: readonly ObjectType[];
|
|
18
|
+
reusables: Reusables;
|
|
19
|
+
});
|
|
20
|
+
get declaration(): Maybe<Code>;
|
|
21
|
+
private get equalsFunctionDeclaration();
|
|
22
|
+
private get name();
|
|
23
|
+
private get toJsonFunctionDeclaration();
|
|
24
|
+
private get toRdfResourceFunctionDeclaration();
|
|
25
|
+
private get hashFunctionDeclaration();
|
|
26
|
+
private get toStringFunctionDeclaration();
|
|
27
|
+
private memberTypeSwitch;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=UberObjectDiscriminatedUnionType.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
|
+
import { invariant } from "ts-invariant";
|
|
9
|
+
import { Memoize } from "typescript-memoize";
|
|
10
|
+
import { code, def, joinCode } from "./ts-poet-wrapper.js";
|
|
11
|
+
/**
|
|
12
|
+
* The $Object discriminated union used in type guard functions (isSomeObjectType(object: $Object)) and some convenience methods.
|
|
13
|
+
*/
|
|
14
|
+
export class UberObjectDiscriminatedUnionType {
|
|
15
|
+
configuration;
|
|
16
|
+
members;
|
|
17
|
+
reusables;
|
|
18
|
+
constructor({ configuration, members, reusables, }) {
|
|
19
|
+
this.configuration = configuration;
|
|
20
|
+
this.members = members.filter((member) => !member.extern);
|
|
21
|
+
invariant(this.members.every((member) => member.name.isJust()));
|
|
22
|
+
this.reusables = reusables;
|
|
23
|
+
}
|
|
24
|
+
get declaration() {
|
|
25
|
+
if (this.members.length === 0) {
|
|
26
|
+
return Maybe.empty();
|
|
27
|
+
}
|
|
28
|
+
const declarations = [];
|
|
29
|
+
if (this.configuration.features.has("Object.type")) {
|
|
30
|
+
declarations.push(code `export type ${def(this.name)} = ${this.members.map((member) => member.name.unsafeCoerce()).join(" | ")};`);
|
|
31
|
+
}
|
|
32
|
+
const staticModuleDeclarations = [
|
|
33
|
+
...this.equalsFunctionDeclaration.toList(),
|
|
34
|
+
...this.hashFunctionDeclaration.toList(),
|
|
35
|
+
...this.toJsonFunctionDeclaration.toList(),
|
|
36
|
+
...this.toRdfResourceFunctionDeclaration.toList(),
|
|
37
|
+
...this.toStringFunctionDeclaration.toList(),
|
|
38
|
+
];
|
|
39
|
+
if (staticModuleDeclarations.length > 0) {
|
|
40
|
+
declarations.push(code `\
|
|
41
|
+
export namespace ${def(this.name)} {
|
|
42
|
+
${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
43
|
+
}`);
|
|
44
|
+
}
|
|
45
|
+
if (declarations.length === 0) {
|
|
46
|
+
return Maybe.empty();
|
|
47
|
+
}
|
|
48
|
+
return Maybe.of(joinCode(declarations, { on: "\n\n" }));
|
|
49
|
+
}
|
|
50
|
+
get equalsFunctionDeclaration() {
|
|
51
|
+
if (!this.configuration.features.has("Object.equals")) {
|
|
52
|
+
return Maybe.empty();
|
|
53
|
+
}
|
|
54
|
+
if (this.members.length === 1) {
|
|
55
|
+
return Maybe.of(code `export const equals = ${this.members[0].name.unsafeCoerce()}.equals`);
|
|
56
|
+
}
|
|
57
|
+
return Maybe.of(code `\
|
|
58
|
+
export function equals(left: ${this.name}, right: ${this.name}): ${this.reusables.snippets.EqualsResult} {
|
|
59
|
+
if (left.${this.configuration.objectDiscriminantProperty.name} !== right.${this.configuration.objectDiscriminantProperty.name}) {
|
|
60
|
+
return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
${this.memberTypeSwitch({
|
|
64
|
+
caseBlock: (member) => code `return ${member.equalsFunction}(left, right as ${member.name.unsafeCoerce()});`,
|
|
65
|
+
variables: { value: code `left` },
|
|
66
|
+
})}
|
|
67
|
+
}`);
|
|
68
|
+
}
|
|
69
|
+
get name() {
|
|
70
|
+
return `${this.configuration.syntheticNamePrefix}Object`;
|
|
71
|
+
}
|
|
72
|
+
get toJsonFunctionDeclaration() {
|
|
73
|
+
if (!this.configuration.features.has("Object.toJson")) {
|
|
74
|
+
return Maybe.empty();
|
|
75
|
+
}
|
|
76
|
+
if (this.members.length === 1) {
|
|
77
|
+
return Maybe.of(code `export const toJson = ${this.members[0].name.unsafeCoerce()}.toJson;`);
|
|
78
|
+
}
|
|
79
|
+
return Maybe.of(code `\
|
|
80
|
+
export function toJson(object: ${this.name}) {
|
|
81
|
+
${this.memberTypeSwitch({
|
|
82
|
+
caseBlock: (member) => code `return ${member.toJsonExpression({ variables: { value: code `object` } })};`,
|
|
83
|
+
variables: { value: code `object` },
|
|
84
|
+
})}
|
|
85
|
+
}`);
|
|
86
|
+
}
|
|
87
|
+
get toRdfResourceFunctionDeclaration() {
|
|
88
|
+
if (!this.configuration.features.has("Object.toRdf")) {
|
|
89
|
+
return Maybe.empty();
|
|
90
|
+
}
|
|
91
|
+
if (this.members.length === 1) {
|
|
92
|
+
return Maybe.of(code `export const toRdfResource = ${this.members[0].name.unsafeCoerce()}.toRdfResource;`);
|
|
93
|
+
}
|
|
94
|
+
return Maybe.of(code `\
|
|
95
|
+
export const toRdfResource: ${this.reusables.snippets.ToRdfResourceFunction}<${this.name}> = (object, options) => {
|
|
96
|
+
${this.memberTypeSwitch({
|
|
97
|
+
caseBlock: (member) => code `return ${member.name.unsafeCoerce()}.toRdfResource(object, options);`,
|
|
98
|
+
variables: { value: code `object` },
|
|
99
|
+
})}
|
|
100
|
+
};`);
|
|
101
|
+
}
|
|
102
|
+
get hashFunctionDeclaration() {
|
|
103
|
+
if (!this.configuration.features.has("Object.hash")) {
|
|
104
|
+
return Maybe.empty();
|
|
105
|
+
}
|
|
106
|
+
if (this.members.length === 1) {
|
|
107
|
+
return Maybe.of(code `export const hash = ${this.members[0].name.unsafeCoerce()}.hash;`);
|
|
108
|
+
}
|
|
109
|
+
return Maybe.of(code `\
|
|
110
|
+
export function hash<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, object: ${this.name}): HasherT {
|
|
111
|
+
${this.memberTypeSwitch({
|
|
112
|
+
caseBlock: (member) => code `return ${member.hashFunction}(hasher, object);`,
|
|
113
|
+
variables: { value: code `object` },
|
|
114
|
+
})}
|
|
115
|
+
}`);
|
|
116
|
+
}
|
|
117
|
+
get toStringFunctionDeclaration() {
|
|
118
|
+
if (!this.configuration.features.has("Object.toString")) {
|
|
119
|
+
return Maybe.empty();
|
|
120
|
+
}
|
|
121
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
122
|
+
if (this.members.length === 1) {
|
|
123
|
+
return Maybe.of(code `export const ${syntheticNamePrefix}toString = ${this.members[0].name.unsafeCoerce()}.${syntheticNamePrefix}toString;`);
|
|
124
|
+
}
|
|
125
|
+
return Maybe.of(code `\
|
|
126
|
+
export function ${syntheticNamePrefix}toString(object: ${this.name}) {
|
|
127
|
+
${this.memberTypeSwitch({
|
|
128
|
+
caseBlock: (member) => code `return ${member.toStringExpression({ variables: { value: code `object` } })};`,
|
|
129
|
+
variables: { value: code `object` },
|
|
130
|
+
})}
|
|
131
|
+
}`);
|
|
132
|
+
}
|
|
133
|
+
memberTypeSwitch({ caseBlock, variables, }) {
|
|
134
|
+
return code `\
|
|
135
|
+
switch (${variables.value}.${this.configuration.objectDiscriminantProperty.name}) {
|
|
136
|
+
${joinCode(this.members.map((member) => code `case "${member.discriminantProperty.unsafeCoerce().value}": ${caseBlock(member)}`), { on: "\n" })}
|
|
137
|
+
default: ${variables.value} satisfies never; throw new Error("should never reach this point");
|
|
138
|
+
}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
__decorate([
|
|
142
|
+
Memoize()
|
|
143
|
+
], UberObjectDiscriminatedUnionType.prototype, "name", null);
|
|
144
|
+
//# sourceMappingURL=UberObjectDiscriminatedUnionType.js.map
|
|
@@ -19,6 +19,7 @@ namespace ${syntheticNamePrefix}RdfVocabularies {
|
|
|
19
19
|
byte: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#byte"),
|
|
20
20
|
date: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#date"),
|
|
21
21
|
dateTime: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"),
|
|
22
|
+
dateTimeStamp: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#dateTimeStamp"),
|
|
22
23
|
decimal: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#decimal"),
|
|
23
24
|
double: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#double"),
|
|
24
25
|
float: ${imports.dataFactory}.namedNode("http://www.w3.org/2001/XMLSchema#float"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@shaclmate/shacl-ast": "4.0.
|
|
3
|
+
"@shaclmate/shacl-ast": "4.0.67",
|
|
4
4
|
"@rdfjs/dataset": "~2.0.2",
|
|
5
5
|
"@rdfjs/prefix-map": "~0.1.2",
|
|
6
6
|
"@rdfjs/term-map": "~2.0.2",
|
|
@@ -227,6 +227,8 @@
|
|
|
227
227
|
"dist/generators/ts/TypeFactory.js",
|
|
228
228
|
"dist/generators/ts/Typeof.d.ts",
|
|
229
229
|
"dist/generators/ts/Typeof.js",
|
|
230
|
+
"dist/generators/ts/UberObjectDiscriminatedUnionType.d.ts",
|
|
231
|
+
"dist/generators/ts/UberObjectDiscriminatedUnionType.js",
|
|
230
232
|
"dist/generators/ts/ZodGenerator.d.ts",
|
|
231
233
|
"dist/generators/ts/ZodGenerator.js",
|
|
232
234
|
"dist/generators/ts/_AbstractType/AbstractType_ConversionFunction.d.ts",
|
|
@@ -721,5 +723,5 @@
|
|
|
721
723
|
},
|
|
722
724
|
"type": "module",
|
|
723
725
|
"types": "./dist/index.d.ts",
|
|
724
|
-
"version": "4.0.
|
|
726
|
+
"version": "4.0.67"
|
|
725
727
|
}
|