@shaclmate/compiler 4.0.12 → 4.0.13
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/generators/ts/AbstractCollectionType.js +4 -1
- package/dist/generators/ts/AbstractUnionType.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +6 -12
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +1 -1
- package/package.json +2 -2
|
@@ -196,7 +196,10 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
196
196
|
schema = code `${schema}.nonempty().min(${this.minCount})`;
|
|
197
197
|
}
|
|
198
198
|
else {
|
|
199
|
-
schema = code `${schema}.
|
|
199
|
+
schema = code `${schema}.optional()`;
|
|
200
|
+
}
|
|
201
|
+
if (!this._mutable) {
|
|
202
|
+
schema = code `${schema}.readonly()`;
|
|
200
203
|
}
|
|
201
204
|
return schema;
|
|
202
205
|
}
|
|
@@ -296,9 +296,9 @@ ${joinCode(this.concreteMembers.map(({ jsonTypeCheck, type, unwrap, wrap }) => c
|
|
|
296
296
|
return code `${imports.z}.discriminatedUnion("${this.discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
297
297
|
includeDiscriminantProperty: true,
|
|
298
298
|
context: "type",
|
|
299
|
-
})), { on: "," })}])`;
|
|
299
|
+
})), { on: "," })}]).readonly()`;
|
|
300
300
|
case "typeof":
|
|
301
|
-
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}])`;
|
|
301
|
+
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
302
302
|
default:
|
|
303
303
|
throw this.discriminant;
|
|
304
304
|
}
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js
CHANGED
|
@@ -6,25 +6,19 @@ export function NamedObjectType_jsonSchemaFunctionDeclaration() {
|
|
|
6
6
|
if (!this.features.has("json")) {
|
|
7
7
|
return Maybe.empty();
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
let properties = [];
|
|
10
10
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
11
|
-
|
|
11
|
+
properties.push(code `...${parentObjectType.jsonSchema({ context: "type" })}.shape`);
|
|
12
12
|
}
|
|
13
13
|
if (this.properties.length > 0) {
|
|
14
|
-
|
|
14
|
+
properties = properties.concat(this.properties
|
|
15
15
|
.flatMap((property) => property.jsonZchema.toList())
|
|
16
|
-
.map(({ key, schema }) => code `"${key}": ${schema}`)
|
|
16
|
+
.map(({ key, schema }) => code `"${key}": ${schema}`));
|
|
17
17
|
}
|
|
18
|
+
// ${this.properties.every((property) => !property.mutable) ? `.readonly()` : ""}
|
|
18
19
|
return Maybe.of(code `\
|
|
19
20
|
export function schema() {
|
|
20
|
-
return ${
|
|
21
|
-
? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
|
|
22
|
-
if (merged === null) {
|
|
23
|
-
return zodObjectSchema;
|
|
24
|
-
}
|
|
25
|
-
return code `${merged}.merge(${zodObjectSchema})`;
|
|
26
|
-
}, null)
|
|
27
|
-
: `${imports.z}.object()`} satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
|
|
21
|
+
return ${imports.z}.object({${joinCode(properties, { on: "," })}}) satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
|
|
28
22
|
}`);
|
|
29
23
|
}
|
|
30
24
|
//# sourceMappingURL=NamedObjectType_jsonSchemaFunctionDeclaration.js.map
|
|
@@ -101,7 +101,7 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
101
101
|
}
|
|
102
102
|
get jsonSignature() {
|
|
103
103
|
const typeJsonType = this.type.jsonType();
|
|
104
|
-
return Maybe.of(code
|
|
104
|
+
return Maybe.of(code `${!this.mutable ? "readonly " : ""}${this.name}${typeJsonType.optional ? "?" : ""}: ${typeJsonType.requiredName}`);
|
|
105
105
|
}
|
|
106
106
|
get jsonZchema() {
|
|
107
107
|
let schema = this.type.jsonSchema({
|
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.13",
|
|
4
4
|
"@rdfjs/data-model": "~2.1.1",
|
|
5
5
|
"@rdfjs/dataset": "~2.0.2",
|
|
6
6
|
"@rdfjs/prefix-map": "~0.1.2",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
},
|
|
79
79
|
"type": "module",
|
|
80
80
|
"types": "./dist/index.d.ts",
|
|
81
|
-
"version": "4.0.
|
|
81
|
+
"version": "4.0.13"
|
|
82
82
|
}
|