@shaclmate/compiler 4.0.70 → 4.0.72

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 (50) hide show
  1. package/dist/generators/ts/AbstractCollectionType.d.ts +1 -1
  2. package/dist/generators/ts/AbstractCollectionType.js +6 -6
  3. package/dist/generators/ts/AbstractContainerType.d.ts +0 -2
  4. package/dist/generators/ts/AbstractContainerType.js +0 -2
  5. package/dist/generators/ts/AbstractLazyType.d.ts +1 -2
  6. package/dist/generators/ts/AbstractLazyType.js +1 -2
  7. package/dist/generators/ts/AbstractLiteralType.d.ts +0 -7
  8. package/dist/generators/ts/AbstractPrimitiveType.js +19 -6
  9. package/dist/generators/ts/AbstractTermType.d.ts +6 -3
  10. package/dist/generators/ts/AbstractTermType.js +11 -16
  11. package/dist/generators/ts/AbstractType.d.ts +11 -9
  12. package/dist/generators/ts/AbstractType.js +51 -2
  13. package/dist/generators/ts/AbstractTypedLiteralType.d.ts +3 -6
  14. package/dist/generators/ts/AbstractTypedLiteralType.js +1 -11
  15. package/dist/generators/ts/BigDecimalType.d.ts +1 -1
  16. package/dist/generators/ts/BigDecimalType.js +1 -1
  17. package/dist/generators/ts/BigIntType.d.ts +2 -1
  18. package/dist/generators/ts/BigIntType.js +11 -5
  19. package/dist/generators/ts/BooleanType.d.ts +1 -1
  20. package/dist/generators/ts/BooleanType.js +1 -1
  21. package/dist/generators/ts/DateTimeType.d.ts +1 -1
  22. package/dist/generators/ts/DateTimeType.js +1 -1
  23. package/dist/generators/ts/DateType.d.ts +1 -1
  24. package/dist/generators/ts/DateType.js +1 -1
  25. package/dist/generators/ts/DefaultValueType.d.ts +1 -1
  26. package/dist/generators/ts/DefaultValueType.js +4 -4
  27. package/dist/generators/ts/DiscriminatedUnionType.d.ts +2 -4
  28. package/dist/generators/ts/DiscriminatedUnionType.js +20 -56
  29. package/dist/generators/ts/FloatType.d.ts +1 -1
  30. package/dist/generators/ts/FloatType.js +1 -1
  31. package/dist/generators/ts/IntType.d.ts +1 -1
  32. package/dist/generators/ts/IntType.js +1 -1
  33. package/dist/generators/ts/IriType.d.ts +2 -0
  34. package/dist/generators/ts/IriType.js +43 -11
  35. package/dist/generators/ts/LangStringType.d.ts +1 -1
  36. package/dist/generators/ts/LangStringType.js +1 -4
  37. package/dist/generators/ts/LiteralType.d.ts +1 -1
  38. package/dist/generators/ts/LiteralType.js +1 -4
  39. package/dist/generators/ts/ObjectDiscriminatedUnionType.d.ts +1 -2
  40. package/dist/generators/ts/ObjectDiscriminatedUnionType.js +2 -11
  41. package/dist/generators/ts/ObjectType.d.ts +3 -3
  42. package/dist/generators/ts/ObjectType.js +134 -124
  43. package/dist/generators/ts/OptionType.d.ts +1 -1
  44. package/dist/generators/ts/OptionType.js +6 -6
  45. package/dist/generators/ts/StringType.d.ts +1 -1
  46. package/dist/generators/ts/StringType.js +10 -3
  47. package/dist/generators/ts/TypeFactory.js +7 -29
  48. package/dist/generators/ts/_ObjectType/ObjectType_identifierTypeDeclarations.d.ts +1 -1
  49. package/dist/generators/ts/_ObjectType/ObjectType_identifierTypeDeclarations.js +4 -5
  50. package/package.json +8 -8
@@ -12,7 +12,6 @@ export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractC
12
12
  mutable: boolean;
13
13
  } & ConstructorParameters<typeof AbstractContainerType<ItemTypeT>>[0]);
14
14
  get equalsFunction(): Code;
15
- get expression(): Code;
16
15
  get filterFunction(): Code;
17
16
  get filterType(): Code;
18
17
  get graphqlType(): AbstractContainerType.GraphqlType;
@@ -20,6 +19,7 @@ export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractC
20
19
  get mutable(): boolean;
21
20
  get schemaType(): Code;
22
21
  get validationFunction(): Maybe<Code>;
22
+ protected get inlineExpression(): Code;
23
23
  graphqlResolveExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["graphqlResolveExpression"]>[0]): Code;
24
24
  jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
25
25
  toJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toJsonExpression"]>[0]): Code;
@@ -22,9 +22,6 @@ export class AbstractCollectionType extends AbstractContainerType {
22
22
  get equalsFunction() {
23
23
  return code `((left, right) => ${this.reusables.snippets.arrayEquals}(left, right, ${this.itemType.equalsFunction}))`;
24
24
  }
25
- get expression() {
26
- return code `${!this._mutable ? "readonly " : ""}(${this.itemType.expression})[]`;
27
- }
28
25
  get filterFunction() {
29
26
  return code `${this.reusables.snippets.filterArray}<${this.itemType.expression}, ${this.itemType.filterType}>(${this.itemType.filterFunction})`;
30
27
  }
@@ -46,6 +43,9 @@ export class AbstractCollectionType extends AbstractContainerType {
46
43
  get validationFunction() {
47
44
  return Maybe.of(code `${this.reusables.snippets.validateArray}(${this.itemType.validationFunction.orDefault(this.itemValidationFunctionDefault)}, ${literalOf(!this._mutable)})`);
48
45
  }
46
+ get inlineExpression() {
47
+ return code `${!this._mutable ? "readonly " : ""}(${this.itemType.expression})[]`;
48
+ }
49
49
  graphqlResolveExpression({ variables, }) {
50
50
  return variables.value;
51
51
  }
@@ -59,9 +59,6 @@ export class AbstractCollectionType extends AbstractContainerType {
59
59
  __decorate([
60
60
  Memoize()
61
61
  ], AbstractCollectionType.prototype, "equalsFunction", null);
62
- __decorate([
63
- Memoize()
64
- ], AbstractCollectionType.prototype, "expression", null);
65
62
  __decorate([
66
63
  Memoize()
67
64
  ], AbstractCollectionType.prototype, "filterFunction", null);
@@ -80,6 +77,9 @@ __decorate([
80
77
  __decorate([
81
78
  Memoize()
82
79
  ], AbstractCollectionType.prototype, "validationFunction", null);
80
+ __decorate([
81
+ Memoize()
82
+ ], AbstractCollectionType.prototype, "inlineExpression", null);
83
83
  (function (AbstractCollectionType) {
84
84
  AbstractCollectionType.GraphqlType = AbstractContainerType.GraphqlType;
85
85
  AbstractCollectionType.isItemType = AbstractContainerType.isItemType;
@@ -1,4 +1,3 @@
1
- import { Maybe } from "purify-ts";
2
1
  import { AbstractType } from "./AbstractType.js";
3
2
  import type { BigDecimalType } from "./BigDecimalType.js";
4
3
  import type { BigIntType } from "./BigIntType.js";
@@ -24,7 +23,6 @@ import { type Code } from "./ts-poet-wrapper.js";
24
23
  * Abstract base class for types that contain other types e.g., ListType, OptionType, SetType.
25
24
  */
26
25
  export declare abstract class AbstractContainerType<ItemTypeT extends AbstractContainerType.ItemType> extends AbstractType {
27
- readonly declaration: Maybe<Code>;
28
26
  abstract readonly kind: "DefaultValue" | "List" | "Option" | "Set";
29
27
  /**
30
28
  * Container item type.
@@ -4,7 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { Maybe } from "purify-ts";
8
7
  import { Memoize } from "typescript-memoize";
9
8
  import { AbstractType } from "./AbstractType.js";
10
9
  import { code } from "./ts-poet-wrapper.js";
@@ -12,7 +11,6 @@ import { code } from "./ts-poet-wrapper.js";
12
11
  * Abstract base class for types that contain other types e.g., ListType, OptionType, SetType.
13
12
  */
14
13
  export class AbstractContainerType extends AbstractType {
15
- declaration = Maybe.empty();
16
14
  /**
17
15
  * Container item type.
18
16
  *
@@ -13,7 +13,6 @@ export declare abstract class AbstractLazyType<PartialTypeT extends AbstractLazy
13
13
  readonly partialPropertyName: string;
14
14
  readonly rawName: Code;
15
15
  };
16
- readonly declaration: Maybe<Code>;
17
16
  readonly discriminantProperty: AbstractType["discriminantProperty"];
18
17
  readonly mutable = false;
19
18
  readonly validationFunction: Maybe<Code>;
@@ -22,7 +21,7 @@ export declare abstract class AbstractLazyType<PartialTypeT extends AbstractLazy
22
21
  resolveType: ResolveTypeT;
23
22
  } & ConstructorParameters<typeof AbstractType>[0]);
24
23
  get equalsFunction(): Code;
25
- get expression(): Code;
24
+ get inlineExpression(): Code;
26
25
  get filterFunction(): Code;
27
26
  get filterType(): Code;
28
27
  get graphqlType(): AbstractType.GraphqlType;
@@ -12,7 +12,6 @@ import { code, joinCode } from "./ts-poet-wrapper.js";
12
12
  export class AbstractLazyType extends AbstractType {
13
13
  partialType;
14
14
  resolveType;
15
- declaration = Maybe.empty();
16
15
  discriminantProperty = Maybe.empty();
17
16
  mutable = false;
18
17
  validationFunction = Maybe.empty();
@@ -24,7 +23,7 @@ export class AbstractLazyType extends AbstractType {
24
23
  get equalsFunction() {
25
24
  return code `((left, right) => ${this.partialType.equalsFunction}(left.${this.runtimeClass.partialPropertyName}, right.${this.runtimeClass.partialPropertyName}))`;
26
25
  }
27
- get expression() {
26
+ get inlineExpression() {
28
27
  return this.runtimeClass.name;
29
28
  }
30
29
  get filterFunction() {
@@ -1,17 +1,10 @@
1
1
  import type { Literal } from "@rdfjs/types";
2
2
  import { AbstractTermType } from "./AbstractTermType.js";
3
- import type { Code } from "./ts-poet-wrapper.js";
4
3
  /**
5
4
  * Abstract base class of all types that are literals in RDF.
6
5
  */
7
6
  export declare abstract class AbstractLiteralType extends AbstractTermType<Literal, Literal> {
8
7
  readonly nodeKinds: ReadonlySet<"Literal">;
9
- /**
10
- * An expression that converts a compile-time RDF/JS Literal into a runtime TypeScript literal.
11
- *
12
- * For example, a string would be converted to "thestring".
13
- */
14
- abstract literalValueExpression(literal: Literal): Code;
15
8
  }
16
9
  export declare namespace AbstractLiteralType {
17
10
  type ConversionFunction = AbstractTermType.ConversionFunction;
@@ -16,8 +16,13 @@ export class AbstractPrimitiveType extends AbstractTypedLiteralType {
16
16
  conversionFunction = Maybe.empty();
17
17
  equalsFunction = code `${this.reusables.snippets.strictEquals}`;
18
18
  get inlineExpression() {
19
- if (this.decodedIn.length > 0) {
20
- return code `${joinCode(this.decodedIn.map((value) => this.literalValueExpression(value)), { on: " | " })}`;
19
+ if (this.in_.length > 0) {
20
+ const name = this.name.extract();
21
+ if (name && this.configuration.features.has("Object.schema")) {
22
+ // Reuse the type from schema to cut down code
23
+ return code `(typeof ${name}.schema)["in"][number]`;
24
+ }
25
+ return code `${joinCode(this.in_.map((value) => this.valueExpression(value)), { on: " | " })}`;
21
26
  }
22
27
  return code `${this.jsTypes[0].typeof}`;
23
28
  }
@@ -25,13 +30,21 @@ export class AbstractPrimitiveType extends AbstractTypedLiteralType {
25
30
  return code `${this.reusables.imports.Either}.of<Error, ${this.expression}>(${variables.value})`;
26
31
  }
27
32
  jsonSchema(_parameters) {
28
- switch (this.decodedIn.length) {
33
+ switch (this.in_.length) {
29
34
  case 0:
30
35
  return code `${this.reusables.imports.z}.${this.jsTypes[0].typeof}()`;
31
36
  case 1:
32
- return code `${this.reusables.imports.z}.literal(${this.literalValueExpression(this.decodedIn[0])})`;
33
- default:
34
- return code `${this.reusables.imports.z}.union(${arrayOf(...this.decodedIn.map((value) => code `${this.reusables.imports.z}.literal(${this.literalValueExpression(value)})`))})`;
37
+ return code `${this.reusables.imports.z}.literal(${this.valueExpression(this.in_[0])})`;
38
+ default: {
39
+ const name = this.name.extract();
40
+ if (name && this.configuration.features.has("Object.schema")) {
41
+ // Reuse the type from schema to cut down code
42
+ return code `${this.reusables.imports.z}.union(${name}.schema.in.map(_ => ${this.reusables.imports.z}.literal(_)))`;
43
+ }
44
+ else {
45
+ return code `${this.reusables.imports.z}.union(${arrayOf(...this.in_.map((value) => code `${this.reusables.imports.z}.literal(${this.valueExpression(value)})`))})`;
46
+ }
47
+ }
35
48
  }
36
49
  }
37
50
  jsonType() {
@@ -12,7 +12,6 @@ import { type Code } from "./ts-poet-wrapper.js";
12
12
  * The two are differentiated because identifiers can have BlankNode or NamedNode values at runtime but only NamedNode values for sh:hasValue and sh:in.
13
13
  */
14
14
  export declare abstract class AbstractTermType<ConstantTermT extends Literal | NamedNode = Literal | NamedNode, _RuntimeTermT extends BlankNode | Literal | NamedNode = BlankNode | Literal | NamedNode> extends AbstractType {
15
- protected abstract readonly inlineExpression: Code;
16
15
  readonly equalsFunction: Code;
17
16
  readonly graphqlArgs: AbstractType["graphqlArgs"];
18
17
  readonly hasValues: readonly ConstantTermT[];
@@ -26,9 +25,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
26
25
  hasValues: readonly ConstantTermT[];
27
26
  in_: readonly ConstantTermT[];
28
27
  } & ConstructorParameters<typeof AbstractType>[0]);
29
- get declaration(): Maybe<Code>;
30
28
  get discriminantProperty(): Maybe<AbstractType.DiscriminantProperty>;
31
- get expression(): Code;
32
29
  get referencesNamedType(): boolean;
33
30
  get termTypes(): ReadonlySet<"BlankNode" | "Literal" | "NamedNode">;
34
31
  get toRdfResourceValueTypes(): Set<"BlankNode" | "Literal" | "NamedNode">;
@@ -37,6 +34,12 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
37
34
  jsonUiSchemaElement(): Maybe<Code>;
38
35
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
39
36
  toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
37
+ /**
38
+ * An expression that converts a compile-time RDF/JS term into a runtime TypeScript value.
39
+ *
40
+ * For example, a string would be converted to "thestring".
41
+ */
42
+ valueExpression(term: ConstantTermT): Code;
40
43
  }
41
44
  export declare namespace AbstractTermType {
42
45
  type ConversionFunction = AbstractType.ConversionFunction;
@@ -31,9 +31,6 @@ export class AbstractTermType extends AbstractType {
31
31
  this.hasValues = hasValues;
32
32
  this.in_ = in_;
33
33
  }
34
- get declaration() {
35
- return this.name.map((name) => code `export type ${name} = ${this.inlineExpression};`);
36
- }
37
34
  get discriminantProperty() {
38
35
  return Maybe.of({
39
36
  jsonName: "termType",
@@ -41,13 +38,6 @@ export class AbstractTermType extends AbstractType {
41
38
  values: [...this.nodeKinds].map(NodeKind.toTermType),
42
39
  });
43
40
  }
44
- get expression() {
45
- const name = this.name.extract();
46
- if (name) {
47
- return code `${name}`;
48
- }
49
- return this.inlineExpression;
50
- }
51
41
  get referencesNamedType() {
52
42
  return this.name.isJust();
53
43
  }
@@ -65,6 +55,9 @@ export class AbstractTermType extends AbstractType {
65
55
  if (this.hasValues.length > 0) {
66
56
  initializers = initializers.concat(code `hasValues: ${arrayOf(...this.hasValues.map((hasValue) => this.rdfjsTermExpression(hasValue)))}`);
67
57
  }
58
+ if (this.in_.length > 0) {
59
+ initializers = initializers.concat(code `in: ${arrayOf(...this.in_.map((in_) => this.valueExpression(in_)))} as const`);
60
+ }
68
61
  return initializers;
69
62
  }
70
63
  jsonUiSchemaElement() {
@@ -76,16 +69,18 @@ export class AbstractTermType extends AbstractType {
76
69
  toStringExpression({ variables, }) {
77
70
  return code `${variables.value}.toString()`;
78
71
  }
72
+ /**
73
+ * An expression that converts a compile-time RDF/JS term into a runtime TypeScript value.
74
+ *
75
+ * For example, a string would be converted to "thestring".
76
+ */
77
+ valueExpression(term) {
78
+ return this.rdfjsTermExpression(term);
79
+ }
79
80
  }
80
- __decorate([
81
- Memoize()
82
- ], AbstractTermType.prototype, "declaration", null);
83
81
  __decorate([
84
82
  Memoize()
85
83
  ], AbstractTermType.prototype, "discriminantProperty", null);
86
- __decorate([
87
- Memoize()
88
- ], AbstractTermType.prototype, "expression", null);
89
84
  __decorate([
90
85
  Memoize()
91
86
  ], AbstractTermType.prototype, "termTypes", null);
@@ -1,5 +1,5 @@
1
1
  import type { BlankNode, NamedNode } from "@rdfjs/types";
2
- import type { Maybe } from "purify-ts";
2
+ import { Maybe } from "purify-ts";
3
3
  import type { Logger } from "ts-log";
4
4
  import type { AbstractType_ConversionFunction } from "./_AbstractType/AbstractType_ConversionFunction.js";
5
5
  import type { AbstractType_DiscriminantProperty } from "./_AbstractType/AbstractType_DiscriminantProperty.js";
@@ -15,6 +15,10 @@ import { type Code } from "./ts-poet-wrapper.js";
15
15
  */
16
16
  export declare abstract class AbstractType {
17
17
  protected readonly configuration: TsGenerator.Configuration;
18
+ /**
19
+ * Inline TypeScript type expression.
20
+ */
21
+ protected abstract readonly inlineExpression: Code;
18
22
  protected readonly logger: Logger;
19
23
  protected readonly reusables: Reusables;
20
24
  /**
@@ -31,10 +35,6 @@ export declare abstract class AbstractType {
31
35
  * If unspecified, uses an identity function (i.e., function identity(value: ThisType): Either<Error, ThisType>).
32
36
  */
33
37
  abstract readonly conversionFunction: Maybe<AbstractType.ConversionFunction>;
34
- /**
35
- * The declaration of named types.
36
- */
37
- abstract readonly declaration: Maybe<Code>;
38
38
  /**
39
39
  * A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
40
40
  */
@@ -44,10 +44,6 @@ export declare abstract class AbstractType {
44
44
  * $EqualsResult.
45
45
  */
46
46
  abstract readonly equalsFunction: Code;
47
- /**
48
- * TypeScript type expression.
49
- */
50
- abstract readonly expression: Code;
51
47
  /**
52
48
  * A function (reference or literal) that takes a filter of filterType (below) and a value of this type
53
49
  * and returns true if the value passes the filter.
@@ -176,6 +172,11 @@ export declare abstract class AbstractType {
176
172
  reusables: Reusables;
177
173
  shapeIdentifier: BlankNode | NamedNode;
178
174
  });
175
+ /**
176
+ * The declaration of named types.
177
+ */
178
+ get declaration(): Maybe<Code>;
179
+ get expression(): Code;
179
180
  /**
180
181
  * TypeScript object describing this type, for runtime use.
181
182
  */
@@ -268,6 +269,7 @@ export declare abstract class AbstractType {
268
269
  };
269
270
  }): Code;
270
271
  protected readonly rdfjsTermExpression: (parameters: Parameters<typeof rdfjsTermExpression>[0]) => Code;
272
+ protected staticModuleDeclarations(_name: string): Record<string, Code>;
271
273
  }
272
274
  export declare namespace AbstractType {
273
275
  type ConversionFunction = AbstractType_ConversionFunction;
@@ -4,12 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ import { Maybe } from "purify-ts";
7
8
  import { Memoize } from "typescript-memoize";
8
9
  import { AbstractType_GraphqlType } from "./_AbstractType/AbstractType_GraphqlType.js";
9
10
  import { AbstractType_JsonType } from "./_AbstractType/AbstractType_JsonType.js";
10
11
  import { AbstractType_JsType } from "./_AbstractType/AbstractType_JsType.js";
11
12
  import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
12
- import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
13
+ import { code, def, joinCode, literalOf, } from "./ts-poet-wrapper.js";
14
+ import { tsComment } from "./tsComment.js";
13
15
  /**
14
16
  * Abstract base class all types.
15
17
  */
@@ -47,11 +49,44 @@ export class AbstractType {
47
49
  });
48
50
  this.shapeIdentifier = shapeIdentifier;
49
51
  }
52
+ /**
53
+ * The declaration of named types.
54
+ */
55
+ get declaration() {
56
+ const name = this.name.extract();
57
+ if (!name) {
58
+ return Maybe.empty();
59
+ }
60
+ const declarations = [];
61
+ if (this.configuration.features.has("Object.type")) {
62
+ declarations.push(code `${this.comment
63
+ .alt(this.label)
64
+ .map(tsComment)
65
+ .orDefault("")}export type ${def(name)} = ${this.inlineExpression};`);
66
+ }
67
+ const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations(name));
68
+ if (staticModuleDeclarations.length > 0) {
69
+ declarations.push(code `\
70
+ export namespace ${def(name)} {
71
+ ${joinCode(staticModuleDeclarations
72
+ .sort((left, right) => left[0].localeCompare(right[0]))
73
+ .map((_) => _[1]), { on: "\n\n" })}
74
+ }`);
75
+ }
76
+ return Maybe.of(joinCode(declarations, { on: "\n\n" }));
77
+ }
78
+ get expression() {
79
+ return this.name
80
+ .map((name) => code `${name}`)
81
+ .orDefaultLazy(() => this.inlineExpression);
82
+ }
50
83
  /**
51
84
  * TypeScript object describing this type, for runtime use.
52
85
  */
53
86
  get schema() {
54
- return this.schemaExpression;
87
+ return this.name
88
+ .map((name) => code `${name}.schema`)
89
+ .orDefaultLazy(() => this.schemaExpression);
55
90
  }
56
91
  get schemaExpression() {
57
92
  return code `{ ${joinCode(this.schemaInitializers.concat(), { on: ", " })} }`;
@@ -63,7 +98,21 @@ export class AbstractType {
63
98
  return [code `kind: ${literalOf(this.kind)} as const`];
64
99
  }
65
100
  rdfjsTermExpression;
101
+ staticModuleDeclarations(_name) {
102
+ const staticModuleDeclarations = {};
103
+ if (this.configuration.features.has("Object.schema")) {
104
+ staticModuleDeclarations["schema"] =
105
+ code `export const schema = ${this.schemaExpression}`;
106
+ }
107
+ return staticModuleDeclarations;
108
+ }
66
109
  }
110
+ __decorate([
111
+ Memoize()
112
+ ], AbstractType.prototype, "declaration", null);
113
+ __decorate([
114
+ Memoize()
115
+ ], AbstractType.prototype, "expression", null);
67
116
  __decorate([
68
117
  Memoize()
69
118
  ], AbstractType.prototype, "schema", null);
@@ -2,7 +2,7 @@ import type { Literal, NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { AbstractLiteralType } from "./AbstractLiteralType.js";
4
4
  import { AbstractTermType } from "./AbstractTermType.js";
5
- import { type Code } from "./ts-poet-wrapper.js";
5
+ import type { Code } from "./ts-poet-wrapper.js";
6
6
  /**
7
7
  * Abstract base class of all types that are typed literals in RDF. In RDF every literal is either
8
8
  * - a language-tagged string literal (datatype = rdf:langString, language = not empty)
@@ -10,15 +10,12 @@ import { type Code } from "./ts-poet-wrapper.js";
10
10
  */
11
11
  export declare abstract class AbstractTypedLiteralType<ValueT> extends AbstractLiteralType {
12
12
  readonly datatype: NamedNode;
13
- readonly decodedIn: readonly ValueT[];
14
- constructor({ datatype, decodedIn, ...superParameters }: {
13
+ constructor({ datatype, ...superParameters }: {
15
14
  datatype: NamedNode;
16
- readonly decodedIn: readonly ValueT[];
17
15
  } & ConstructorParameters<typeof AbstractLiteralType>[0]);
18
16
  get discriminantProperty(): Maybe<AbstractLiteralType.DiscriminantProperty>;
19
- protected get schemaInitializers(): readonly Code[];
20
17
  graphqlResolveExpression({ variables, }: Parameters<AbstractLiteralType["graphqlResolveExpression"]>[0]): Code;
21
- abstract literalValueExpression(literal: Literal | ValueT): Code;
18
+ abstract valueExpression(literal: Literal | ValueT): Code;
22
19
  }
23
20
  export declare namespace AbstractTypedLiteralType {
24
21
  type ConversionFunction = AbstractTermType.ConversionFunction;
@@ -1,7 +1,6 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { AbstractLiteralType } from "./AbstractLiteralType.js";
3
3
  import { AbstractTermType } from "./AbstractTermType.js";
4
- import { arrayOf, code } from "./ts-poet-wrapper.js";
5
4
  /**
6
5
  * Abstract base class of all types that are typed literals in RDF. In RDF every literal is either
7
6
  * - a language-tagged string literal (datatype = rdf:langString, language = not empty)
@@ -9,22 +8,13 @@ import { arrayOf, code } from "./ts-poet-wrapper.js";
9
8
  */
10
9
  export class AbstractTypedLiteralType extends AbstractLiteralType {
11
10
  datatype;
12
- decodedIn;
13
- constructor({ datatype, decodedIn, ...superParameters }) {
11
+ constructor({ datatype, ...superParameters }) {
14
12
  super(superParameters);
15
13
  this.datatype = datatype;
16
- this.decodedIn = decodedIn;
17
14
  }
18
15
  get discriminantProperty() {
19
16
  return Maybe.empty();
20
17
  }
21
- get schemaInitializers() {
22
- let initializers = super.schemaInitializers;
23
- if (this.decodedIn.length > 0) {
24
- initializers = initializers.concat(code `in: ${arrayOf(...this.decodedIn.map((in_) => this.literalValueExpression(in_)))} as const`);
25
- }
26
- return initializers;
27
- }
28
18
  graphqlResolveExpression({ variables, }) {
29
19
  return variables.value;
30
20
  }
@@ -23,7 +23,7 @@ export declare class BigDecimalType extends AbstractTypedLiteralType<Decimal> {
23
23
  graphqlResolveExpression({ variables, }: Parameters<AbstractLiteralType["graphqlResolveExpression"]>[0]): Code;
24
24
  jsonSchema(): Code;
25
25
  jsonType(): AbstractLiteralType.JsonType;
26
- literalValueExpression(literal: Literal): Code;
26
+ valueExpression(literal: Literal): Code;
27
27
  toJsonExpression({ variables, }: Parameters<AbstractTypedLiteralType<Decimal>["toJsonExpression"]>[0]): Code;
28
28
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractLiteralType["toRdfResourceValuesExpression"]>[0]): Code;
29
29
  }
@@ -37,7 +37,7 @@ export class BigDecimalType extends AbstractTypedLiteralType {
37
37
  jsonType() {
38
38
  return new AbstractLiteralType.JsonType(code `{ readonly "@type": ${literalOf(this.datatype.value)}, readonly "@value": string }`);
39
39
  }
40
- literalValueExpression(literal) {
40
+ valueExpression(literal) {
41
41
  return code `new ${this.reusables.imports.BigDecimal}(${literalOf(literal.value)})`;
42
42
  }
43
43
  toJsonExpression({ variables, }) {
@@ -8,10 +8,11 @@ export declare class BigIntType extends AbstractNumericType<bigint> {
8
8
  readonly kind = "BigInt";
9
9
  get fromRdfResourceValuesFunction(): Code;
10
10
  get graphqlType(): import("./_AbstractType/AbstractType_GraphqlType.js").AbstractType_GraphqlType;
11
+ private get decodedIn();
11
12
  fromJsonExpression({ variables, }: Parameters<AbstractNumericType<bigint>["fromJsonExpression"]>[0]): Code;
12
13
  jsonSchema(_parameters: Parameters<AbstractNumericType<bigint>["jsonSchema"]>[0]): Code;
13
14
  jsonType(): AbstractNumericType.JsonType;
14
- literalValueExpression(literal: bigint | Literal): Code;
15
15
  toJsonExpression({ variables, }: Parameters<AbstractNumericType<bigint>["toJsonExpression"]>[0]): Code;
16
+ valueExpression(literal: bigint | Literal): Code;
16
17
  }
17
18
  //# sourceMappingURL=BigIntType.d.ts.map
@@ -17,9 +17,12 @@ export class BigIntType extends AbstractNumericType {
17
17
  get graphqlType() {
18
18
  return new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLBigInt}`, this.reusables);
19
19
  }
20
+ get decodedIn() {
21
+ return this.in_.map((in_) => LiteralDecoder.decodeBigIntLiteral(in_).unsafeCoerce());
22
+ }
20
23
  fromJsonExpression({ variables, }) {
21
24
  let expression = code `BigInt(${variables.value}["@value"])`;
22
- if (this.decodedIn.length > 0) {
25
+ if (this.in_.length > 0) {
23
26
  expression = code `${expression} as ${this.expression}`;
24
27
  }
25
28
  return code `${this.reusables.imports.Either}.encase<Error, ${this.expression}>(() => ${expression})`;
@@ -44,16 +47,16 @@ export class BigIntType extends AbstractNumericType {
44
47
  ? "string"
45
48
  : joinCode(this.decodedIn.map((in_) => code `${literalOf(in_.toString())}`), { on: " | " })} }`);
46
49
  }
47
- literalValueExpression(literal) {
48
- return code `${typeof literal === "bigint" ? literal : LiteralDecoder.decodeBigIntLiteral(literal).unsafeCoerce()}n`;
49
- }
50
50
  toJsonExpression({ variables, }) {
51
51
  let valueExpression = code `${variables.value}.toString()`;
52
- if (this.decodedIn.length > 0) {
52
+ if (this.in_.length > 0) {
53
53
  valueExpression = code `${valueExpression} as ${joinCode(this.decodedIn.map((in_) => code `${literalOf(in_.toString())}`), { on: " | " })}`;
54
54
  }
55
55
  return code `{ "@type": ${literalOf(this.datatype.value)} as const, "@value": ${valueExpression} }`;
56
56
  }
57
+ valueExpression(literal) {
58
+ return code `${typeof literal === "bigint" ? literal : LiteralDecoder.decodeBigIntLiteral(literal).unsafeCoerce()}n`;
59
+ }
57
60
  }
58
61
  __decorate([
59
62
  Memoize()
@@ -61,6 +64,9 @@ __decorate([
61
64
  __decorate([
62
65
  Memoize()
63
66
  ], BigIntType.prototype, "graphqlType", null);
67
+ __decorate([
68
+ Memoize()
69
+ ], BigIntType.prototype, "decodedIn", null);
64
70
  __decorate([
65
71
  Memoize()
66
72
  ], BigIntType.prototype, "jsonType", null);
@@ -13,7 +13,7 @@ export declare class BooleanType extends AbstractPrimitiveType<boolean> {
13
13
  readonly valueSparqlWherePatternsFunction: Code;
14
14
  get fromRdfResourceValuesFunction(): Code;
15
15
  get schemaType(): Code;
16
- literalValueExpression(literal: boolean | Literal): Code;
16
+ valueExpression(literal: boolean | Literal): Code;
17
17
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<boolean>["toRdfResourceValuesExpression"]>[0]): Code;
18
18
  }
19
19
  //# sourceMappingURL=BooleanType.d.ts.map
@@ -22,7 +22,7 @@ export class BooleanType extends AbstractPrimitiveType {
22
22
  get schemaType() {
23
23
  return code `${this.reusables.snippets.BooleanSchema}<${this.expression}>`;
24
24
  }
25
- literalValueExpression(literal) {
25
+ valueExpression(literal) {
26
26
  return code `${typeof literal === "boolean" ? literal : LiteralDecoder.decodeBooleanLiteral(literal).unsafeCoerce()}`;
27
27
  }
28
28
  toRdfResourceValuesExpression({ variables, }) {
@@ -7,7 +7,7 @@ export declare class DateTimeType extends AbstractDateType {
7
7
  readonly kind = "DateTime";
8
8
  get fromRdfResourceValuesFunction(): Code;
9
9
  jsonSchema(): Code;
10
- literalValueExpression(literal: Date | Literal): Code;
10
+ valueExpression(literal: Date | Literal): Code;
11
11
  toJsonExpression({ variables, }: Parameters<AbstractDateType["toJsonExpression"]>[0]): Code;
12
12
  }
13
13
  //# sourceMappingURL=DateTimeType.d.ts.map
@@ -18,7 +18,7 @@ export class DateTimeType extends AbstractDateType {
18
18
  jsonSchema() {
19
19
  return code `${this.reusables.imports.z}.object({ "@type": ${this.reusables.imports.z}.literal(${literalOf(this.datatype.value)}), "@value": ${this.reusables.imports.z}.iso.datetime() })`;
20
20
  }
21
- literalValueExpression(literal) {
21
+ valueExpression(literal) {
22
22
  return code `new Date("${(literal instanceof Date ? literal : LiteralDecoder.decodeDateTimeLiteral(literal).unsafeCoerce()).toISOString()}")`;
23
23
  }
24
24
  toJsonExpression({ variables, }) {
@@ -7,7 +7,7 @@ export declare class DateType extends AbstractDateType {
7
7
  readonly kind = "Date";
8
8
  get fromRdfResourceValuesFunction(): Code;
9
9
  jsonSchema(): Code;
10
- literalValueExpression(literal: Date | Literal): Code;
10
+ valueExpression(literal: Date | Literal): Code;
11
11
  toJsonExpression({ variables, }: Parameters<AbstractDateType["toJsonExpression"]>[0]): Code;
12
12
  }
13
13
  //# sourceMappingURL=DateType.d.ts.map
@@ -19,7 +19,7 @@ export class DateType extends AbstractDateType {
19
19
  jsonSchema() {
20
20
  return code `${this.reusables.imports.z}.object({ "@type": ${this.reusables.imports.z}.literal(${literalOf(this.datatype.value)}), "@value": ${this.reusables.imports.z}.iso.date() })`;
21
21
  }
22
- literalValueExpression(literal) {
22
+ valueExpression(literal) {
23
23
  return code `new Date("${(literal instanceof Date ? literal : LiteralDecoder.decodeDateLiteral(literal).unsafeCoerce()).toISOString()}")`;
24
24
  }
25
25
  toJsonExpression({ variables, }) {
@@ -57,7 +57,6 @@ export declare class DefaultValueType<ItemTypeT extends DefaultValueType.ItemTyp
57
57
  } & ConstructorParameters<typeof AbstractContainerType<ItemTypeT>>[0]);
58
58
  get conversionFunction(): Maybe<AbstractContainerType.ConversionFunction>;
59
59
  get equalsFunction(): Code;
60
- get expression(): Code;
61
60
  get filterFunction(): Code;
62
61
  get filterType(): Code;
63
62
  get fromRdfResourceValuesFunction(): Code;
@@ -68,6 +67,7 @@ export declare class DefaultValueType<ItemTypeT extends DefaultValueType.ItemTyp
68
67
  get toRdfResourceValueTypes(): AbstractContainerType<ItemTypeT>["toRdfResourceValueTypes"];
69
68
  get valueSparqlConstructTriplesFunction(): Code;
70
69
  get valueSparqlWherePatternsFunction(): Code;
70
+ protected get inlineExpression(): Code;
71
71
  protected get schemaInitializers(): Code[];
72
72
  private get defaultValueExpression();
73
73
  fromJsonExpression(parameters: Parameters<AbstractType["fromJsonExpression"]>[0]): Code;