@shaclmate/compiler 4.0.98 → 4.0.99

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 (88) hide show
  1. package/dist/generators/ts/AbstractCollectionType.d.ts +2 -1
  2. package/dist/generators/ts/AbstractCollectionType.js +10 -5
  3. package/dist/generators/ts/AbstractCompoundType.d.ts +11 -8
  4. package/dist/generators/ts/AbstractCompoundType.js +5 -2
  5. package/dist/generators/ts/AbstractContainerType.d.ts +11 -11
  6. package/dist/generators/ts/AbstractContainerType.js +21 -15
  7. package/dist/generators/ts/AbstractDateType.d.ts +7 -6
  8. package/dist/generators/ts/AbstractDateType.js +16 -6
  9. package/dist/generators/ts/AbstractDiscriminatedUnionType.d.ts +2 -3
  10. package/dist/generators/ts/AbstractDiscriminatedUnionType.js +25 -7
  11. package/dist/generators/ts/AbstractIntersectionType.d.ts +2 -2
  12. package/dist/generators/ts/AbstractIntersectionType.js +19 -8
  13. package/dist/generators/ts/AbstractLazyType.d.ts +23 -23
  14. package/dist/generators/ts/AbstractLazyType.js +21 -19
  15. package/dist/generators/ts/AbstractNumericType.d.ts +4 -3
  16. package/dist/generators/ts/AbstractNumericType.js +12 -7
  17. package/dist/generators/ts/AbstractPrimitiveType.d.ts +2 -2
  18. package/dist/generators/ts/AbstractPrimitiveType.js +4 -4
  19. package/dist/generators/ts/AbstractTermType.d.ts +17 -16
  20. package/dist/generators/ts/AbstractTermType.js +21 -11
  21. package/dist/generators/ts/AbstractType.d.ts +6 -15
  22. package/dist/generators/ts/AbstractType.js +14 -33
  23. package/dist/generators/ts/AbstractTypedLiteralType.d.ts +2 -1
  24. package/dist/generators/ts/AbstractTypedLiteralType.js +20 -2
  25. package/dist/generators/ts/BigDecimalType.d.ts +12 -11
  26. package/dist/generators/ts/BigDecimalType.js +28 -11
  27. package/dist/generators/ts/BigIntType.js +6 -6
  28. package/dist/generators/ts/BlankNodeType.d.ts +11 -10
  29. package/dist/generators/ts/BlankNodeType.js +27 -10
  30. package/dist/generators/ts/BooleanType.d.ts +6 -5
  31. package/dist/generators/ts/BooleanType.js +18 -8
  32. package/dist/generators/ts/Callable.d.ts +2 -2
  33. package/dist/generators/ts/DateTimeType.d.ts +6 -6
  34. package/dist/generators/ts/DateTimeType.js +6 -6
  35. package/dist/generators/ts/DateType.d.ts +6 -6
  36. package/dist/generators/ts/DateType.js +6 -6
  37. package/dist/generators/ts/DefaultValueType.d.ts +2 -2
  38. package/dist/generators/ts/DefaultValueType.js +18 -8
  39. package/dist/generators/ts/FloatType.js +4 -4
  40. package/dist/generators/ts/IdentifierType.d.ts +11 -10
  41. package/dist/generators/ts/IdentifierType.js +27 -10
  42. package/dist/generators/ts/IntType.js +4 -4
  43. package/dist/generators/ts/IriType.d.ts +5 -5
  44. package/dist/generators/ts/IriType.js +27 -22
  45. package/dist/generators/ts/LangStringType.d.ts +10 -10
  46. package/dist/generators/ts/LangStringType.js +21 -13
  47. package/dist/generators/ts/ListType.js +7 -7
  48. package/dist/generators/ts/LiteralType.d.ts +10 -10
  49. package/dist/generators/ts/LiteralType.js +21 -13
  50. package/dist/generators/ts/ObjectType.d.ts +13 -15
  51. package/dist/generators/ts/ObjectType.js +32 -9
  52. package/dist/generators/ts/OptionType.d.ts +2 -1
  53. package/dist/generators/ts/OptionType.js +16 -11
  54. package/dist/generators/ts/SetType.d.ts +2 -1
  55. package/dist/generators/ts/SetType.js +22 -10
  56. package/dist/generators/ts/Snippets.d.ts +1 -0
  57. package/dist/generators/ts/Snippets.js +7 -0
  58. package/dist/generators/ts/StringType.d.ts +6 -6
  59. package/dist/generators/ts/StringType.js +20 -17
  60. package/dist/generators/ts/TermType.d.ts +7 -7
  61. package/dist/generators/ts/TermType.js +18 -13
  62. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_fromJsonObjectFunction.js +1 -1
  63. package/dist/generators/ts/_AbstractType/AbstractType_JsonType.d.ts +39 -16
  64. package/dist/generators/ts/_AbstractType/AbstractType_JsonType.js +49 -33
  65. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunction.js +1 -1
  66. package/dist/generators/ts/_ObjectIntersectionType/ObjectIntersectionType_fromRdfResourceValuesFunction.js +1 -1
  67. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.d.ts +4 -7
  68. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.js +1 -3
  69. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.d.ts +0 -1
  70. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.js +0 -1
  71. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.d.ts +3 -2
  72. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.js +30 -10
  73. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.d.ts +3 -2
  74. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.js +26 -10
  75. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.d.ts +3 -2
  76. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.js +46 -22
  77. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunction.js +1 -1
  78. package/package.json +2 -2
  79. package/dist/generators/ts/AbstractStructuredType.d.ts +0 -71
  80. package/dist/generators/ts/AbstractStructuredType.js +0 -273
  81. package/dist/generators/ts/ReferenceCallable.d.ts +0 -14
  82. package/dist/generators/ts/ReferenceCallable.js +0 -16
  83. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.d.ts +0 -5
  84. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.js +0 -11
  85. package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.d.ts +0 -4
  86. package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.js +0 -15
  87. package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.d.ts +0 -4
  88. package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.js +0 -15
@@ -19,21 +19,6 @@ class AbstractJsonType {
19
19
  this.reusables = reusables;
20
20
  this.snippet = snippet;
21
21
  }
22
- moduleDeclarations({ unqualifiedName, }) {
23
- const moduleDeclarations = [];
24
- if (this.configuration.features.has("Object.JSON.parse")) {
25
- moduleDeclarations.push(code `\
26
- export function parse(json: unknown): ${this.reusables.imports.Either}<Error, ${unqualifiedName}> {
27
- const jsonSafeParseResult = schema().safeParse(json);
28
- if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
29
- return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
30
- }`);
31
- }
32
- if (this.configuration.features.has("Object.JSON.schema")) {
33
- moduleDeclarations.push(code `export function schema() { return ${this.schemaExpression} satisfies ${this.reusables.imports.z}.ZodType<Json>; }`);
34
- }
35
- return moduleDeclarations;
36
- }
37
22
  get declaration() {
38
23
  if (this.name.isNothing() || this.snippet.isJust()) {
39
24
  return Maybe.empty();
@@ -67,6 +52,24 @@ export function parse(json: unknown): ${this.reusables.imports.Either}<Error, ${
67
52
  uiSchemaElement(_parameters) {
68
53
  return Maybe.empty();
69
54
  }
55
+ moduleDeclarations({ unqualifiedName, }) {
56
+ const moduleDeclarations = [];
57
+ if (this.configuration.features.has("Object.JSON.parse")) {
58
+ moduleDeclarations.push(code `\
59
+ export function parse(json: unknown): ${this.reusables.imports.Either}<Error, ${unqualifiedName}> {
60
+ const jsonSafeParseResult = schema().safeParse(json);
61
+ if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
62
+ return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
63
+ }`);
64
+ }
65
+ if (this.configuration.features.has("Object.JSON.schema")) {
66
+ moduleDeclarations.push(code `export function schema() { return ${this.schemaExpression} satisfies ${this.schemaTypeExpression({ unqualifiedName })}; }`);
67
+ }
68
+ return moduleDeclarations;
69
+ }
70
+ schemaTypeExpression({ unqualifiedName, }) {
71
+ return code `${this.reusables.imports.z}.ZodType<${unqualifiedName}>`;
72
+ }
70
73
  }
71
74
  __decorate([
72
75
  Memoize()
@@ -136,8 +139,8 @@ __decorate([
136
139
  Memoize()
137
140
  ], JsonArrayType.prototype, "schemaExpression", null);
138
141
  class JsonBooleanType extends AbstractJsonPrimitiveType {
139
- kind = "JsonBoolean";
140
142
  typeof = "boolean";
143
+ kind = "JsonBoolean";
141
144
  }
142
145
  class JsonDiscriminatedUnionType extends AbstractJsonType {
143
146
  kind = "JsonDiscriminatedUnion";
@@ -200,17 +203,19 @@ __decorate([
200
203
  Memoize()
201
204
  ], JsonIntersectionType.prototype, "schemaExpression", null);
202
205
  class JsonNumberType extends AbstractJsonPrimitiveType {
203
- kind = "JsonNumber";
204
206
  typeof = "number";
207
+ kind = "JsonNumber";
205
208
  }
206
209
  class JsonObjectType extends AbstractJsonType {
210
+ cachedMemberTypes;
211
+ shorthand;
207
212
  kind = "JsonObject";
208
213
  members;
209
- memberTypes;
210
- constructor({ members, ...superParameters }) {
214
+ constructor({ members, shorthand, ...superParameters }) {
211
215
  super(superParameters);
216
+ this.cachedMemberTypes = Array.from({ length: members.length }).map(() => null);
212
217
  this.members = members;
213
- this.memberTypes = Array.from({ length: members.length }).map(() => null);
218
+ this.shorthand = shorthand;
214
219
  }
215
220
  get inlineExpression() {
216
221
  return code `{ ${joinCode(this.members.map((member, memberI) => {
@@ -218,7 +223,7 @@ class JsonObjectType extends AbstractJsonType {
218
223
  }), { on: ", " })} }`;
219
224
  }
220
225
  get schemaExpression() {
221
- return code `${this.reusables.imports.z}.object({ ${joinCode(this.members.map((member, memberI) => {
226
+ const objectSchema = code `${this.reusables.imports.z}.object({ ${joinCode(this.members.map((member, memberI) => {
222
227
  const memberType = this.memberType(memberI);
223
228
  let schema = memberType.schema;
224
229
  if (member.recursive) {
@@ -241,6 +246,16 @@ class JsonObjectType extends AbstractJsonType {
241
246
  }
242
247
  return code `${literalOf(member.name)}: ${schema}`;
243
248
  }), { on: ", " })} })`;
249
+ return this.shorthand
250
+ .map((shorthand) => {
251
+ return code `${this.reusables.imports.z}.union([${objectSchema}, ${shorthand.type.schema}.transform(${shorthand.transformer.unannotatedUsage})])`;
252
+ })
253
+ .orDefault(objectSchema);
254
+ }
255
+ schemaTypeExpression({ unqualifiedName, }) {
256
+ return this.shorthand
257
+ .map((shorthand) => code `${this.reusables.imports.z}.ZodType<${unqualifiedName}, ${unqualifiedName} | ${shorthand.type.expression}>`)
258
+ .orDefault(super.schemaTypeExpression({ unqualifiedName }));
244
259
  }
245
260
  get uiSchemaFunctionExpression() {
246
261
  const variables = { scopePrefix: code `(_options?.scopePrefix ?? "#")` };
@@ -256,14 +271,10 @@ class JsonObjectType extends AbstractJsonType {
256
271
  return ${uiSchema};
257
272
  })`;
258
273
  }
259
- memberType(memberI) {
260
- if (this.memberTypes[memberI] === null) {
261
- this.memberTypes[memberI] =
262
- typeof this.members[memberI].type === "function"
263
- ? this.members[memberI].type()
264
- : this.members[memberI].type;
265
- }
266
- return this.memberTypes[memberI];
274
+ uiSchemaElement({ variables, }) {
275
+ return Maybe.of(code `${this.name
276
+ .map((name) => code `${name.join(".")}.uiSchema`)
277
+ .orDefaultLazy(() => this.uiSchemaFunctionExpression)}({ scopePrefix: ${variables.scopePrefix} })`);
267
278
  }
268
279
  moduleDeclarations(parameters) {
269
280
  const moduleDeclarations = super.moduleDeclarations(parameters);
@@ -272,10 +283,14 @@ class JsonObjectType extends AbstractJsonType {
272
283
  }
273
284
  return moduleDeclarations;
274
285
  }
275
- uiSchemaElement({ variables, }) {
276
- return Maybe.of(code `${this.name
277
- .map((name) => code `${name.join(".")}.uiSchema`)
278
- .orDefaultLazy(() => this.uiSchemaFunctionExpression)}({ scopePrefix: ${variables.scopePrefix} })`);
286
+ memberType(memberI) {
287
+ if (this.cachedMemberTypes[memberI] === null) {
288
+ this.cachedMemberTypes[memberI] =
289
+ typeof this.members[memberI].type === "function"
290
+ ? this.members[memberI].type()
291
+ : this.members[memberI].type;
292
+ }
293
+ return this.cachedMemberTypes[memberI];
279
294
  }
280
295
  }
281
296
  __decorate([
@@ -406,6 +421,7 @@ class JsonTypeFactory {
406
421
  : Maybe.fromNullable(member.uiSchemaElement),
407
422
  })),
408
423
  name: Maybe.fromNullable(options?.name),
424
+ shorthand: Maybe.fromNullable(options?.shorthand),
409
425
  snippet: Maybe.fromNullable(options?.snippet),
410
426
  });
411
427
  }
@@ -14,7 +14,7 @@ if (focusIdentifier.termType === "Variable") {
14
14
  ignoreRdfType: false,
15
15
  preferredLanguages,
16
16
  propertyPatterns: [],
17
- schema: ${this.identifierType.schema},
17
+ schema: ${this.identifierType.schema.expression},
18
18
  valueVariable: focusIdentifier,
19
19
  variablePrefix,
20
20
  }));
@@ -3,6 +3,6 @@ export function ObjectIntersectionType_fromRdfResourceValuesFunctionExpression()
3
3
  return code `(values, options) => values.chainMap(value => value.toResource().chain(resource => ${this.fromRdfResourceFunction.annotatedUsage}(resource, options)))`;
4
4
  }
5
5
  export function ObjectIntersectionType_fromRdfResourceValuesFunctionType() {
6
- return code `${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.discriminatedType.map((discriminatedType) => discriminatedType.expression).orDefault(this.expression)}, ${this.schemaType}>`;
6
+ return code `${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.discriminatedType.map((discriminatedType) => discriminatedType.expression).orDefault(this.expression)}, ${this.schema.type.expression}>`;
7
7
  }
8
8
  //# sourceMappingURL=ObjectIntersectionType_fromRdfResourceValuesFunction.js.map
@@ -3,6 +3,7 @@ import type { Maybe } from "purify-ts";
3
3
  import type { AbstractType } from "../AbstractType.js";
4
4
  import type { Reusables } from "../Reusables.js";
5
5
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
6
+ import type { SchemaObject } from "../SchemaObject.js";
6
7
  import type { TsGenerator } from "../TsGenerator.js";
7
8
  import type { Type } from "../Type.js";
8
9
  import { type Code } from "../ts-poet-wrapper.js";
@@ -83,13 +84,9 @@ export declare abstract class ObjectType_AbstractProperty {
83
84
  */
84
85
  abstract readonly recursive: boolean;
85
86
  /**
86
- * TypeScript object describing this type, for runtime use.
87
+ * TypeScript object describing this property, for runtime use.
87
88
  */
88
- abstract readonly schema: Maybe<Code>;
89
- /**
90
- * TypeScript type describing .schema.
91
- */
92
- abstract readonly schemaType: Maybe<Code>;
89
+ abstract readonly schema: Maybe<SchemaObject<SchemaObject.UserDefinedType>>;
93
90
  constructor({ configuration, jsonTypeFactory, logger, name, objectType, reusables, }: {
94
91
  configuration: TsGenerator.Configuration;
95
92
  jsonTypeFactory: AbstractType.JsonTypeFactory;
@@ -244,6 +241,6 @@ export declare abstract class ObjectType_AbstractProperty {
244
241
  };
245
242
  }): Maybe<Code>;
246
243
  protected readonly rdfjsTermExpression: (parameters: Parameters<typeof rdfjsTermExpression>[0]) => Code;
247
- protected get schemaVariable(): Code;
244
+ protected get schemaVariable(): Maybe<Code>;
248
245
  }
249
246
  //# sourceMappingURL=ObjectType_AbstractProperty.d.ts.map
@@ -32,9 +32,7 @@ export class ObjectType_AbstractProperty {
32
32
  }
33
33
  rdfjsTermExpression;
34
34
  get schemaVariable() {
35
- return this.objectType.name
36
- .map((name) => code `${name}.schema.properties.${this.name}`)
37
- .orDefaultLazy(() => this.schema.unsafeCoerce());
35
+ return this.objectType.name.map((name) => code `${name}.schema.properties.${this.name}`);
38
36
  }
39
37
  }
40
38
  __decorate([
@@ -15,7 +15,6 @@ export declare class ObjectType_DiscriminantProperty extends ObjectType_Abstract
15
15
  readonly mutable = false;
16
16
  readonly recursive = false;
17
17
  readonly schema: ObjectType_AbstractProperty["schema"];
18
- readonly schemaType: ObjectType_AbstractProperty["schemaType"];
19
18
  readonly value: string;
20
19
  constructor({ configuration, value, ...superParameters }: {
21
20
  value: string;
@@ -22,7 +22,6 @@ export class ObjectType_DiscriminantProperty extends ObjectType_AbstractProperty
22
22
  mutable = false;
23
23
  recursive = false;
24
24
  schema = Maybe.empty();
25
- schemaType = Maybe.empty();
26
25
  value;
27
26
  constructor({ configuration, value, ...superParameters }) {
28
27
  super({
@@ -2,6 +2,7 @@ import { Maybe } from "purify-ts";
2
2
  import type { BlankNodeType } from "../BlankNodeType.js";
3
3
  import type { IdentifierType } from "../IdentifierType.js";
4
4
  import type { IriType } from "../IriType.js";
5
+ import { SchemaObject } from "../SchemaObject.js";
5
6
  import { type Code } from "../ts-poet-wrapper.js";
6
7
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
7
8
  export declare class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
@@ -24,8 +25,8 @@ export declare class ObjectType_IdentifierProperty extends ObjectType_AbstractPr
24
25
  get graphqlField(): ObjectType_AbstractProperty["graphqlField"];
25
26
  get hashFunctionParameter(): Maybe<Code>;
26
27
  get jsonObjectMember(): ObjectType_AbstractProperty["jsonObjectMember"];
27
- get schema(): Maybe<Code>;
28
- get schemaType(): Maybe<Code>;
28
+ get schema(): Maybe<SchemaObject<SchemaObject.UserDefinedType>>;
29
+ private get _schema();
29
30
  private get typeExpression();
30
31
  private get typeSchemaVariable();
31
32
  createInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["createInitializer"]>[0]): Maybe<Code>;
@@ -9,6 +9,7 @@ import { rdf } from "@tpluscode/rdf-ns-builders";
9
9
  import { Maybe } from "purify-ts";
10
10
  import { invariant } from "ts-invariant";
11
11
  import { Memoize } from "typescript-memoize";
12
+ import { SchemaObject } from "../SchemaObject.js";
12
13
  import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
13
14
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
14
15
  export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
@@ -78,13 +79,23 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
78
79
  });
79
80
  }
80
81
  get schema() {
81
- return Maybe.of(code `{ ${joinCode([code `kind: ${literalOf(this.kind)}`, code `type: ${this.type.schema}`], { on: ", " })} }`);
82
- }
83
- get schemaType() {
84
- return Maybe.of(code `{ ${joinCode([
85
- code `readonly kind: ${literalOf(this.kind)}`,
86
- code `readonly type: ${this.type.schemaType}`,
87
- ], { on: ", " })} }`);
82
+ return Maybe.of(this._schema);
83
+ }
84
+ get _schema() {
85
+ return new SchemaObject({
86
+ properties: {
87
+ kind: code `kind: ${literalOf(this.kind)}`,
88
+ type: code `type: ${this.type.schema.expression}`,
89
+ },
90
+ type: new SchemaObject.UserDefinedType({
91
+ members: {
92
+ kind: code `readonly kind: ${literalOf(this.kind)}`,
93
+ type: code `readonly type: ${this.type.schema.type.expression}`,
94
+ },
95
+ name: Maybe.empty(),
96
+ }),
97
+ variable: this.schemaVariable,
98
+ });
88
99
  }
89
100
  get typeExpression() {
90
101
  return this.objectType.name
@@ -92,9 +103,9 @@ export class ObjectType_IdentifierProperty extends ObjectType_AbstractProperty {
92
103
  .orDefault(this.type.expression);
93
104
  }
94
105
  get typeSchemaVariable() {
95
- return this.objectType.name
96
- .map((name) => code `${name}.schema.properties.${this.name}.type`)
97
- .orDefaultLazy(() => this.type.schema);
106
+ return this.schemaVariable
107
+ .map((schemaVariable) => code `${schemaVariable}.type`)
108
+ .orDefault(this.type.schema.expression);
98
109
  }
99
110
  createInitializer({ variables, }) {
100
111
  const nodeKinds = this.type.nodeKinds;
@@ -203,7 +214,16 @@ __decorate([
203
214
  __decorate([
204
215
  Memoize()
205
216
  ], ObjectType_IdentifierProperty.prototype, "jsonObjectMember", null);
217
+ __decorate([
218
+ Memoize()
219
+ ], ObjectType_IdentifierProperty.prototype, "schema", null);
220
+ __decorate([
221
+ Memoize()
222
+ ], ObjectType_IdentifierProperty.prototype, "_schema", null);
206
223
  __decorate([
207
224
  Memoize()
208
225
  ], ObjectType_IdentifierProperty.prototype, "typeExpression", null);
226
+ __decorate([
227
+ Memoize()
228
+ ], ObjectType_IdentifierProperty.prototype, "typeSchemaVariable", null);
209
229
  //# sourceMappingURL=ObjectType_IdentifierProperty.js.map
@@ -1,5 +1,6 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
+ import { SchemaObject } from "../SchemaObject.js";
3
4
  import { type Code } from "../ts-poet-wrapper.js";
4
5
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
5
6
  export declare class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
@@ -17,9 +18,9 @@ export declare class ObjectType_RdfTypeProperty extends ObjectType_AbstractPrope
17
18
  fromRdfType: NamedNode;
18
19
  toRdfTypes: readonly NamedNode[];
19
20
  } & Omit<ConstructorParameters<typeof ObjectType_AbstractProperty>[0], "name">);
20
- get schema(): Maybe<Code>;
21
21
  get jsonObjectMember(): ObjectType_AbstractProperty["jsonObjectMember"];
22
- get schemaType(): Maybe<Code>;
22
+ get schema(): Maybe<SchemaObject<SchemaObject.UserDefinedType>>;
23
+ private get _schema();
23
24
  createInitializer(): Maybe<Code>;
24
25
  equalsExpression(): Maybe<Code>;
25
26
  filterExpression(): Maybe<Code>;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
8
8
  import { Maybe } from "purify-ts";
9
9
  import { Memoize } from "typescript-memoize";
10
+ import { SchemaObject } from "../SchemaObject.js";
10
11
  import { arrayOf, code, joinCode, literalOf, } from "../ts-poet-wrapper.js";
11
12
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
12
13
  export class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
@@ -29,9 +30,6 @@ export class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
29
30
  this.fromRdfType = fromRdfType;
30
31
  this.toRdfTypes = toRdfTypes;
31
32
  }
32
- get schema() {
33
- return Maybe.of(code `${{ fromRdfType: this.rdfjsTermExpression(this.fromRdfType), kind: this.kind, toRdfTypes: this.toRdfTypes.map((toRdfType) => this.rdfjsTermExpression(toRdfType)) }}`);
34
- }
35
33
  get jsonObjectMember() {
36
34
  return Maybe.of({
37
35
  description: Maybe.empty(),
@@ -47,8 +45,26 @@ export class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
47
45
  uiSchemaElement: Maybe.empty(),
48
46
  });
49
47
  }
50
- get schemaType() {
51
- return Maybe.of(code `${{ fromRdfType: code `${this.reusables.imports.NamedNode}`, kind: this.kind, toRdfTypes: code `readonly ${this.reusables.imports.NamedNode}[]` }}`);
48
+ get schema() {
49
+ return Maybe.of(this._schema);
50
+ }
51
+ get _schema() {
52
+ return new SchemaObject({
53
+ properties: {
54
+ fromRdfType: code `fromRdfType: ${this.rdfjsTermExpression(this.fromRdfType)}`,
55
+ kind: code `kind: ${literalOf(this.kind)}`,
56
+ toRdfTypes: code `toRdfTypes: ${arrayOf(...this.toRdfTypes.map((toRdfType) => this.rdfjsTermExpression(toRdfType)))}`,
57
+ },
58
+ type: new SchemaObject.UserDefinedType({
59
+ members: {
60
+ fromRdfType: code `fromRdfType: ${this.reusables.imports.NamedNode}`,
61
+ kind: code `kind: ${literalOf(this.kind)}`,
62
+ toRdfTypes: code `toRdfTypes: readonly ${this.reusables.imports.NamedNode}[]`,
63
+ },
64
+ name: Maybe.empty(),
65
+ }),
66
+ variable: this.schemaVariable,
67
+ });
52
68
  }
53
69
  createInitializer() {
54
70
  return Maybe.empty();
@@ -63,7 +79,7 @@ export class ObjectType_RdfTypeProperty extends ObjectType_AbstractProperty {
63
79
  return Maybe.empty();
64
80
  }
65
81
  fromRdfResourceValuesInitializer({ variables, }) {
66
- return Maybe.of(code `${this.name}: !${variables.ignoreRdfType} ? ${this.reusables.snippets.ensureRdfResourceType}(${variables.focusResource}, ${arrayOf(code `(${this.schemaVariable}).fromRdfType`)}, ${{ graph: variables.graph }}) : ${this.reusables.imports.Right}(true as const)`);
82
+ return Maybe.of(code `${this.name}: !${variables.ignoreRdfType} ? ${this.reusables.snippets.ensureRdfResourceType}(${variables.focusResource}, ${arrayOf(code `(${this._schema.expression}).fromRdfType`)}, ${{ graph: variables.graph }}) : ${this.reusables.imports.Right}(true as const)`);
67
83
  }
68
84
  hashStatements() {
69
85
  return [];
@@ -122,7 +138,7 @@ type: "optional" as const
122
138
  return [
123
139
  code `\
124
140
  if (!${variables.ignoreRdfType}) {
125
- ${variables.resource}.add(${this.rdfjsTermExpression(rdf.type)}, ${this.schemaVariable}.toRdfTypes, ${variables.graph});
141
+ ${variables.resource}.add(${this.rdfjsTermExpression(rdf.type)}, ${this._schema.expression}.toRdfTypes, ${variables.graph});
126
142
  }`,
127
143
  ];
128
144
  }
@@ -132,13 +148,13 @@ if (!${variables.ignoreRdfType}) {
132
148
  }
133
149
  __decorate([
134
150
  Memoize()
135
- ], ObjectType_RdfTypeProperty.prototype, "schema", null);
151
+ ], ObjectType_RdfTypeProperty.prototype, "jsonObjectMember", null);
136
152
  __decorate([
137
153
  Memoize()
138
- ], ObjectType_RdfTypeProperty.prototype, "jsonObjectMember", null);
154
+ ], ObjectType_RdfTypeProperty.prototype, "schema", null);
139
155
  __decorate([
140
156
  Memoize()
141
- ], ObjectType_RdfTypeProperty.prototype, "schemaType", null);
157
+ ], ObjectType_RdfTypeProperty.prototype, "_schema", null);
142
158
  __decorate([
143
159
  Memoize()
144
160
  ], ObjectType_RdfTypeProperty.prototype, "equalsExpression", null);
@@ -1,5 +1,6 @@
1
1
  import type { PropertyPath } from "@rdfx/resource";
2
2
  import { Maybe } from "purify-ts";
3
+ import { SchemaObject } from "../SchemaObject.js";
3
4
  import type { Type } from "../Type.js";
4
5
  import { type Code } from "../ts-poet-wrapper.js";
5
6
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
@@ -37,8 +38,8 @@ export declare class ObjectType_ShaclProperty<TypeT extends Type> extends Object
37
38
  get graphqlField(): ObjectType_AbstractProperty["graphqlField"];
38
39
  get hashFunctionParameter(): Maybe<Code>;
39
40
  get jsonObjectMember(): ObjectType_AbstractProperty["jsonObjectMember"];
40
- get schema(): Maybe<Code>;
41
- get schemaType(): Maybe<Code>;
41
+ get schema(): Maybe<SchemaObject<SchemaObject.UserDefinedType>>;
42
+ private get _schema();
42
43
  private get typeSchemaVariable();
43
44
  createInitializer({ variables, }: Parameters<ObjectType_AbstractProperty["createInitializer"]>[0]): Maybe<Code>;
44
45
  equalsExpression({ variables, }: Parameters<ObjectType_AbstractProperty["equalsExpression"]>[0]): Maybe<Code>;
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Maybe } from "purify-ts";
8
8
  import { Memoize } from "typescript-memoize";
9
+ import { SchemaObject } from "../SchemaObject.js";
9
10
  import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
10
11
  import { tsComment } from "../tsComment.js";
11
12
  import { ObjectType_AbstractProperty } from "./ObjectType_AbstractProperty.js";
@@ -106,33 +107,50 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
106
107
  });
107
108
  }
108
109
  get schema() {
109
- const initializers = [code `kind: ${literalOf(this.kind)}`];
110
+ return Maybe.of(this._schema);
111
+ }
112
+ get _schema() {
113
+ // if (
114
+ // this.objectType.name.extract() === "DirectRecursiveStruct" ||
115
+ // this.objectType.name.extract() === "IndirectRecursiveStruct"
116
+ // ) {
117
+ // console.log("test");
118
+ // }
119
+ const properties = {
120
+ kind: code `kind: ${literalOf(this.kind)}`,
121
+ };
122
+ const typeMembers = {
123
+ kind: code `readonly kind: ${literalOf(this.kind)}`,
124
+ };
110
125
  if (this.configuration.features.has("Object.fromRdf") ||
111
126
  this.configuration.features.has("Object.toRdf")) {
112
- initializers.push(code `path: ${this.propertyPathToCode(this.path)}`);
127
+ properties["path"] = code `path: ${this.propertyPathToCode(this.path)}`;
128
+ typeMembers["path"] =
129
+ code `readonly path: ${this.reusables.snippets.PropertyPath}`;
113
130
  }
114
131
  // Use a getter if the type is recursive or the type is an object type, which may have forward references in the file
115
132
  if (this.recursive || this.type.referencesNamedType) {
116
- initializers.push(code `get type() { return ${this.type.schema}; }`);
133
+ properties["type"] = () => code `get type() { return ${this.type.schema.expression}; }`;
134
+ typeMembers["type"] = () => code `readonly type: ${this.type.schema.type.expression}`;
117
135
  }
118
136
  else {
119
- initializers.push(code `type: ${this.type.schema}`);
120
- }
121
- return Maybe.of(code `{ ${joinCode(initializers, { on: ", " })} }`);
122
- }
123
- get schemaType() {
124
- const initializers = [code `readonly kind: ${literalOf(this.kind)}`];
125
- if (this.configuration.features.has("Object.fromRdf") ||
126
- this.configuration.features.has("Object.toRdf")) {
127
- initializers.push(code `readonly path: ${this.reusables.snippets.PropertyPath}`);
137
+ properties["type"] = code `type: ${this.type.schema.expression}`;
138
+ typeMembers["type"] =
139
+ code `readonly type: ${this.type.schema.type.expression}`;
128
140
  }
129
- initializers.push(code `readonly type: ${this.type.schemaType}`);
130
- return Maybe.of(code `{ ${joinCode(initializers, { on: ", " })} }`);
141
+ return new SchemaObject({
142
+ properties,
143
+ type: new SchemaObject.UserDefinedType({
144
+ members: typeMembers,
145
+ name: Maybe.empty(),
146
+ }),
147
+ variable: this.schemaVariable,
148
+ });
131
149
  }
132
150
  get typeSchemaVariable() {
133
- return this.objectType.name
134
- .map((name) => code `${name}.schema.properties.${this.name}.type`)
135
- .orDefaultLazy(() => this.type.schema);
151
+ return this.schemaVariable
152
+ .map((schemaVariable) => code `${schemaVariable}.type`)
153
+ .orDefaultLazy(() => this.type.schema.expression);
136
154
  }
137
155
  createInitializer({ variables, }) {
138
156
  const parameterVariable = code `${variables.parameters}.${this.name}`;
@@ -169,11 +187,11 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
169
187
  }
170
188
  fromRdfResourceValuesInitializer({ variables, }) {
171
189
  return Maybe.of(code `${this.name}:
172
- ${this.reusables.snippets.shaclPropertyFromRdf}<${this.type.expression}, ${this.type.schemaType}>({
190
+ ${this.reusables.snippets.shaclPropertyFromRdf}<${this.type.expression}, ${this.type.schema.type.expression}>({
173
191
  ...${variables.options},
174
192
  focusResource: ${variables.focusResource},
175
193
  ignoreRdfType: true,
176
- propertySchema: ${this.schemaVariable},
194
+ propertySchema: ${this._schema.expression},
177
195
  typeFromRdfResourceValues: ${this.type.fromRdfResourceValuesFunction.unannotatedUsage}
178
196
  })`);
179
197
  }
@@ -190,7 +208,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
190
208
  focusIdentifier: variables.focusIdentifier,
191
209
  ignoreRdfType: true,
192
210
  propertyName: this.name,
193
- propertySchema: this.schemaVariable,
211
+ propertySchema: this._schema.expression,
194
212
  typeSparqlConstructTriples: this.type.valueSparqlConstructTriplesFunction.unannotatedUsage,
195
213
  variablePrefix: variables.variablePrefix,
196
214
  }})`);
@@ -205,7 +223,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
205
223
  ignoreRdfType: true,
206
224
  preferredLanguages: variables.preferredLanguages,
207
225
  propertyName: this.name,
208
- propertySchema: this.schemaVariable,
226
+ propertySchema: this._schema.expression,
209
227
  typeSparqlWherePatterns: this.type.valueSparqlWherePatternsFunction.unannotatedUsage,
210
228
  variablePrefix: variables.variablePrefix,
211
229
  }})`,
@@ -231,7 +249,7 @@ export class ObjectType_ShaclProperty extends ObjectType_AbstractProperty {
231
249
  return [];
232
250
  }
233
251
  const propertyPath = this.objectType.name
234
- .map(() => code `${this.schemaVariable}.path`)
252
+ .map(() => code `${this._schema.expression}.path`)
235
253
  .orDefault(this.propertyPathToCode(this.path));
236
254
  const { object: objectVariable, ...otherVariables } = variables;
237
255
  return [
@@ -281,6 +299,12 @@ __decorate([
281
299
  __decorate([
282
300
  Memoize()
283
301
  ], ObjectType_ShaclProperty.prototype, "jsonObjectMember", null);
302
+ __decorate([
303
+ Memoize()
304
+ ], ObjectType_ShaclProperty.prototype, "schema", null);
305
+ __decorate([
306
+ Memoize()
307
+ ], ObjectType_ShaclProperty.prototype, "_schema", null);
284
308
  __decorate([
285
309
  Memoize()
286
310
  ], ObjectType_ShaclProperty.prototype, "typeSchemaVariable", null);
@@ -3,6 +3,6 @@ export function ObjectType_fromRdfResourceValuesFunctionExpression() {
3
3
  return code `(values, options) => values.chainMap(value => value.toResource().chain(resource => ${this.fromRdfResourceFunction.annotatedUsage}(resource, options)))`;
4
4
  }
5
5
  export function ObjectType_fromRdfResourceValuesFunctionType() {
6
- return code `${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.discriminatedType.map((discriminatedType) => discriminatedType.expression).orDefault(this.expression)}, ${this.schemaType}>`;
6
+ return code `${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.discriminatedType.map((discriminatedType) => discriminatedType.expression).orDefault(this.expression)}, ${this.schema.type.expression}>`;
7
7
  }
8
8
  //# sourceMappingURL=ObjectType_fromRdfResourceValuesFunction.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.98",
3
+ "@shaclmate/shacl-ast": "4.0.99",
4
4
  "@rdfjs/types": "~2.0.1",
5
5
  "@rdfx/collection": "0.0.59",
6
6
  "@rdfx/curie": "0.0.59",
@@ -976,5 +976,5 @@
976
976
  },
977
977
  "type": "module",
978
978
  "types": "./dist/index.d.ts",
979
- "version": "4.0.98"
979
+ "version": "4.0.99"
980
980
  }