@shaclmate/compiler 4.0.98 → 4.0.100

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 (96) hide show
  1. package/dist/generators/ts/AbstractBuiltinType.d.ts +23 -0
  2. package/dist/generators/ts/AbstractBuiltinType.js +18 -0
  3. package/dist/generators/ts/AbstractCollectionType.d.ts +2 -1
  4. package/dist/generators/ts/AbstractCollectionType.js +10 -5
  5. package/dist/generators/ts/AbstractCompoundType.d.ts +11 -8
  6. package/dist/generators/ts/AbstractCompoundType.js +5 -2
  7. package/dist/generators/ts/AbstractContainerType.d.ts +11 -11
  8. package/dist/generators/ts/AbstractContainerType.js +21 -15
  9. package/dist/generators/ts/AbstractDateType.d.ts +7 -6
  10. package/dist/generators/ts/AbstractDateType.js +16 -6
  11. package/dist/generators/ts/AbstractDiscriminatedUnionType.d.ts +2 -3
  12. package/dist/generators/ts/AbstractDiscriminatedUnionType.js +25 -7
  13. package/dist/generators/ts/AbstractIntersectionType.d.ts +2 -2
  14. package/dist/generators/ts/AbstractIntersectionType.js +19 -8
  15. package/dist/generators/ts/AbstractLazyType.d.ts +23 -23
  16. package/dist/generators/ts/AbstractLazyType.js +21 -19
  17. package/dist/generators/ts/AbstractNumericType.d.ts +4 -3
  18. package/dist/generators/ts/AbstractNumericType.js +12 -7
  19. package/dist/generators/ts/AbstractPrimitiveType.d.ts +2 -2
  20. package/dist/generators/ts/AbstractPrimitiveType.js +4 -4
  21. package/dist/generators/ts/AbstractTermType.d.ts +17 -16
  22. package/dist/generators/ts/AbstractTermType.js +21 -11
  23. package/dist/generators/ts/AbstractType.d.ts +6 -15
  24. package/dist/generators/ts/AbstractType.js +14 -33
  25. package/dist/generators/ts/AbstractTypedLiteralType.d.ts +2 -1
  26. package/dist/generators/ts/AbstractTypedLiteralType.js +20 -2
  27. package/dist/generators/ts/{AbstractStructuredType.d.ts → AbstractUserDefinedType.d.ts} +6 -6
  28. package/dist/generators/ts/{AbstractStructuredType.js → AbstractUserDefinedType.js} +38 -26
  29. package/dist/generators/ts/BigDecimalType.d.ts +12 -11
  30. package/dist/generators/ts/BigDecimalType.js +28 -11
  31. package/dist/generators/ts/BigIntType.js +6 -6
  32. package/dist/generators/ts/BlankNodeType.d.ts +11 -10
  33. package/dist/generators/ts/BlankNodeType.js +27 -10
  34. package/dist/generators/ts/BooleanType.d.ts +6 -5
  35. package/dist/generators/ts/BooleanType.js +18 -8
  36. package/dist/generators/ts/{ReferenceCallable.d.ts → BuiltinCallable.d.ts} +3 -3
  37. package/dist/generators/ts/{ReferenceCallable.js → BuiltinCallable.js} +3 -3
  38. package/dist/generators/ts/Callable.d.ts +2 -2
  39. package/dist/generators/ts/DateTimeType.d.ts +6 -6
  40. package/dist/generators/ts/DateTimeType.js +6 -6
  41. package/dist/generators/ts/DateType.d.ts +6 -6
  42. package/dist/generators/ts/DateType.js +6 -6
  43. package/dist/generators/ts/DefaultValueType.d.ts +2 -2
  44. package/dist/generators/ts/DefaultValueType.js +18 -8
  45. package/dist/generators/ts/FloatType.js +4 -4
  46. package/dist/generators/ts/IdentifierType.d.ts +11 -10
  47. package/dist/generators/ts/IdentifierType.js +27 -10
  48. package/dist/generators/ts/IntType.js +4 -4
  49. package/dist/generators/ts/IriType.d.ts +5 -5
  50. package/dist/generators/ts/IriType.js +27 -22
  51. package/dist/generators/ts/LangStringType.d.ts +10 -10
  52. package/dist/generators/ts/LangStringType.js +21 -13
  53. package/dist/generators/ts/ListType.js +7 -7
  54. package/dist/generators/ts/LiteralType.d.ts +10 -10
  55. package/dist/generators/ts/LiteralType.js +21 -13
  56. package/dist/generators/ts/ObjectType.d.ts +13 -15
  57. package/dist/generators/ts/ObjectType.js +32 -9
  58. package/dist/generators/ts/OptionType.d.ts +2 -1
  59. package/dist/generators/ts/OptionType.js +16 -11
  60. package/dist/generators/ts/SchemaObject.d.ts +98 -0
  61. package/dist/generators/ts/SchemaObject.js +143 -0
  62. package/dist/generators/ts/SetType.d.ts +2 -1
  63. package/dist/generators/ts/SetType.js +22 -10
  64. package/dist/generators/ts/Snippets.d.ts +1 -0
  65. package/dist/generators/ts/Snippets.js +7 -0
  66. package/dist/generators/ts/StringType.d.ts +6 -6
  67. package/dist/generators/ts/StringType.js +20 -17
  68. package/dist/generators/ts/TermType.d.ts +7 -7
  69. package/dist/generators/ts/TermType.js +18 -13
  70. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_fromJsonObjectFunction.js +1 -1
  71. package/dist/generators/ts/_AbstractType/AbstractType_JsonType.d.ts +39 -16
  72. package/dist/generators/ts/_AbstractType/AbstractType_JsonType.js +49 -33
  73. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunction.js +1 -1
  74. package/dist/generators/ts/_ObjectIntersectionType/ObjectIntersectionType_fromRdfResourceValuesFunction.js +1 -1
  75. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.d.ts +4 -7
  76. package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.js +1 -3
  77. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.d.ts +0 -1
  78. package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.js +0 -1
  79. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.d.ts +3 -2
  80. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.js +30 -10
  81. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.d.ts +3 -2
  82. package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.js +26 -10
  83. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.d.ts +3 -2
  84. package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.js +46 -22
  85. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunction.js +1 -1
  86. package/dist/generators/ts/_ObjectType/ObjectType_jsonObjectType.d.ts +4 -0
  87. package/dist/generators/ts/_ObjectType/ObjectType_jsonObjectType.js +26 -0
  88. package/dist/generators/ts/_snippets/snippets_LazySchema.d.ts +3 -0
  89. package/dist/generators/ts/_snippets/snippets_LazySchema.js +7 -0
  90. package/package.json +14 -12
  91. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.d.ts +0 -5
  92. package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.js +0 -11
  93. package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.d.ts +0 -4
  94. package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.js +0 -15
  95. package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.d.ts +0 -4
  96. package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.js +0 -15
@@ -10,22 +10,21 @@ import { ObjectType_IdentifierProperty } from "./_ObjectType/ObjectType_Identifi
10
10
  import type { ObjectType_Property } from "./_ObjectType/ObjectType_Property.js";
11
11
  import { ObjectType_RdfTypeProperty } from "./_ObjectType/ObjectType_RdfTypeProperty.js";
12
12
  import { ObjectType_ShaclProperty } from "./_ObjectType/ObjectType_ShaclProperty.js";
13
- import { ObjectType_schemaExpression } from "./_ObjectType/ObjectType_schemaExpression.js";
14
- import { ObjectType_schemaTypeExpression } from "./_ObjectType/ObjectType_schemaTypeExpression.js";
15
13
  import { ObjectType_toJsonObjectFunctionExpression, ObjectType_toJsonObjectFunctionType } from "./_ObjectType/ObjectType_toJsonObjectFunction.js";
16
14
  import { ObjectType_toLoggableFunctionExpression, ObjectType_toLoggableFunctionType } from "./_ObjectType/ObjectType_toLoggableFunction.js";
17
15
  import { ObjectType_toRdfResourceValuesFunctionExpression, ObjectType_toRdfResourceValuesFunctionType } from "./_ObjectType/ObjectType_toRdfResourceValuesFunction.js";
18
16
  import { ObjectType_toStringFunctionExpression, ObjectType_toStringFunctionType } from "./_ObjectType/ObjectType_toStringFunction.js";
19
17
  import { ObjectType_valueSparqlConstructTriplesFunctionExpression } from "./_ObjectType/ObjectType_valueSparqlConstructTriplesFunction.js";
20
18
  import { ObjectType_valueSparqlWherePatternsFunctionExpression } from "./_ObjectType/ObjectType_valueSparqlWherePatternsFunction.js";
21
- import { AbstractStructuredType } from "./AbstractStructuredType.js";
19
+ import { AbstractUserDefinedType } from "./AbstractUserDefinedType.js";
22
20
  import type { BlankNodeType } from "./BlankNodeType.js";
23
21
  import type { Callable } from "./Callable.js";
24
22
  import type { IdentifierType } from "./IdentifierType.js";
25
23
  import type { IriType } from "./IriType.js";
24
+ import { SchemaObject } from "./SchemaObject.js";
26
25
  import type { Type } from "./Type.js";
27
26
  import { type Code } from "./ts-poet-wrapper.js";
28
- export declare class ObjectType extends AbstractStructuredType {
27
+ export declare class ObjectType extends AbstractUserDefinedType {
29
28
  private readonly rdfTypeProperty;
30
29
  protected equalsFunctionExpression: typeof ObjectType_equalsFunctionExpression;
31
30
  protected equalsFunctionType: typeof ObjectType_equalsFunctionType;
@@ -38,8 +37,6 @@ export declare class ObjectType extends AbstractStructuredType {
38
37
  protected fromRdfResourceValuesFunctionType: typeof ObjectType_fromRdfResourceValuesFunctionType;
39
38
  protected hashFunctionExpression: typeof ObjectType_hashFunctionExpression;
40
39
  protected hashFunctionType: typeof ObjectType_hashFunctionType;
41
- protected schemaExpression: typeof ObjectType_schemaExpression;
42
- protected schemaTypeExpression: typeof ObjectType_schemaTypeExpression;
43
40
  protected toJsonObjectFunctionExpression: typeof ObjectType_toJsonObjectFunctionExpression;
44
41
  protected toJsonObjectFunctionType: typeof ObjectType_toJsonObjectFunctionType;
45
42
  protected toLoggableFunctionExpression: typeof ObjectType_toLoggableFunctionExpression;
@@ -50,9 +47,9 @@ export declare class ObjectType extends AbstractStructuredType {
50
47
  protected toStringFunctionType: typeof ObjectType_toStringFunctionType;
51
48
  protected valueSparqlConstructTriplesFunctionExpression: typeof ObjectType_valueSparqlConstructTriplesFunctionExpression;
52
49
  protected valueSparqlWherePatternsFunctionExpression: typeof ObjectType_valueSparqlWherePatternsFunctionExpression;
53
- readonly discriminatedType: Maybe<AbstractStructuredType.DiscriminatedType>;
50
+ readonly discriminatedType: Maybe<AbstractUserDefinedType.DiscriminatedType>;
54
51
  readonly extern: boolean;
55
- readonly graphqlArgs: AbstractStructuredType["graphqlArgs"];
52
+ readonly graphqlArgs: AbstractUserDefinedType["graphqlArgs"];
56
53
  readonly identifierProperty: Maybe<ObjectType.IdentifierProperty>;
57
54
  readonly identifierType: BlankNodeType | IdentifierType | IriType;
58
55
  readonly jsTypes: readonly [{
@@ -62,7 +59,7 @@ export declare class ObjectType extends AbstractStructuredType {
62
59
  readonly kind = "Object";
63
60
  readonly recursive: boolean;
64
61
  readonly synthetic: boolean;
65
- readonly validationFunction: AbstractStructuredType["validationFunction"];
62
+ readonly validationFunction: AbstractUserDefinedType["validationFunction"];
66
63
  constructor({ discriminantProperty, extern, identifierProperty, identifierType, lazyProperties, rdfTypeProperty, recursive, synthetic, ...superParameters }: {
67
64
  discriminantProperty: Maybe<ObjectType.DiscriminantProperty>;
68
65
  comment: Maybe<string>;
@@ -74,21 +71,22 @@ export declare class ObjectType extends AbstractStructuredType {
74
71
  rdfTypeProperty: Maybe<ObjectType.RdfTypeProperty>;
75
72
  recursive: boolean;
76
73
  synthetic: boolean;
77
- } & ConstructorParameters<typeof AbstractStructuredType>[0]);
74
+ } & ConstructorParameters<typeof AbstractUserDefinedType>[0]);
78
75
  get _fromRdfResourceFunction(): Callable;
79
76
  get _toRdfResourceFunction(): Callable;
80
- get jsonValueType(): AbstractStructuredType["jsonObjectType"];
81
- get conversionFunction(): Maybe<AbstractStructuredType.ConversionFunction>;
77
+ get jsonValueType(): AbstractUserDefinedType["jsonObjectType"];
78
+ get conversionFunction(): Maybe<AbstractUserDefinedType.ConversionFunction>;
82
79
  get createFunction(): Callable;
83
80
  get createFunctionParameters(): ObjectType.CreateFunctionParameters;
84
81
  get createUnsafeFunction(): Callable;
85
82
  get declaration(): Maybe<Code>;
86
- get jsonObjectType(): AbstractStructuredType["jsonObjectType"];
83
+ get jsonObjectType(): AbstractUserDefinedType["jsonObjectType"];
84
+ get schema(): SchemaObject<SchemaObject.UserDefinedType>;
87
85
  get focusSparqlConstructTriplesFunction(): Callable;
88
86
  get focusSparqlWherePatternsFunction(): Callable;
89
87
  get fromRdfResourceFunction(): Callable;
90
88
  get fromRdfTypeVariable(): Maybe<Code>;
91
- get graphqlType(): AbstractStructuredType.GraphqlType;
89
+ get graphqlType(): AbstractUserDefinedType.GraphqlType;
92
90
  get identifierTypeAlias(): Code;
93
91
  get mutable(): boolean;
94
92
  get objectSetMethodNames(): ObjectType.ObjectSetMethodNames;
@@ -97,7 +95,7 @@ export declare class ObjectType extends AbstractStructuredType {
97
95
  get sparqlConstructQueryFunction(): Callable;
98
96
  get sparqlConstructQueryStringFunction(): Callable;
99
97
  get toRdfResourceFunction(): Callable;
100
- get toRdfResourceValueTypes(): AbstractStructuredType["toRdfResourceValueTypes"];
98
+ get toRdfResourceValueTypes(): AbstractUserDefinedType["toRdfResourceValueTypes"];
101
99
  get toRdfjsResourceType(): Code;
102
100
  get toStringRecordFunction(): Callable;
103
101
  get typeGuardFunction(): Maybe<Callable>;
@@ -28,11 +28,10 @@ import { ObjectType_graphqlTypeExpression } from "./_ObjectType/ObjectType_graph
28
28
  import { ObjectType_hashFunctionExpression, ObjectType_hashFunctionType, } from "./_ObjectType/ObjectType_hashFunction.js";
29
29
  import { ObjectType_IdentifierProperty } from "./_ObjectType/ObjectType_IdentifierProperty.js";
30
30
  import { ObjectType_identifierTypeDeclarations } from "./_ObjectType/ObjectType_identifierTypeDeclarations.js";
31
+ import { ObjectType_jsonObjectType } from "./_ObjectType/ObjectType_jsonObjectType.js";
31
32
  import { ObjectType_objectSetMethodNames } from "./_ObjectType/ObjectType_objectSetMethodNames.js";
32
33
  import { ObjectType_RdfTypeProperty } from "./_ObjectType/ObjectType_RdfTypeProperty.js";
33
34
  import { ObjectType_ShaclProperty } from "./_ObjectType/ObjectType_ShaclProperty.js";
34
- import { ObjectType_schemaExpression } from "./_ObjectType/ObjectType_schemaExpression.js";
35
- import { ObjectType_schemaTypeExpression } from "./_ObjectType/ObjectType_schemaTypeExpression.js";
36
35
  import { ObjectType_sparqlConstructQueryFunction } from "./_ObjectType/ObjectType_sparqlConstructQueryFunction.js";
37
36
  import { ObjectType_sparqlConstructQueryStringFunction } from "./_ObjectType/ObjectType_sparqlConstructQueryStringFunction.js";
38
37
  import { ObjectType_toJsonObjectFunctionExpression, ObjectType_toJsonObjectFunctionType, } from "./_ObjectType/ObjectType_toJsonObjectFunction.js";
@@ -44,10 +43,11 @@ import { ObjectType_toStringRecordFunction } from "./_ObjectType/ObjectType_toSt
44
43
  import { ObjectType_typeGuardFunction } from "./_ObjectType/ObjectType_typeGuardFunction.js";
45
44
  import { ObjectType_valueSparqlConstructTriplesFunctionExpression } from "./_ObjectType/ObjectType_valueSparqlConstructTriplesFunction.js";
46
45
  import { ObjectType_valueSparqlWherePatternsFunctionExpression } from "./_ObjectType/ObjectType_valueSparqlWherePatternsFunction.js";
47
- import { AbstractStructuredType } from "./AbstractStructuredType.js";
46
+ import { AbstractUserDefinedType } from "./AbstractUserDefinedType.js";
48
47
  import { DeclaredCallable } from "./DeclaredCallable.js";
48
+ import { SchemaObject } from "./SchemaObject.js";
49
49
  import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
50
- export class ObjectType extends AbstractStructuredType {
50
+ export class ObjectType extends AbstractUserDefinedType {
51
51
  rdfTypeProperty;
52
52
  equalsFunctionExpression = ObjectType_equalsFunctionExpression;
53
53
  equalsFunctionType = ObjectType_equalsFunctionType;
@@ -60,8 +60,6 @@ export class ObjectType extends AbstractStructuredType {
60
60
  fromRdfResourceValuesFunctionType = ObjectType_fromRdfResourceValuesFunctionType;
61
61
  hashFunctionExpression = ObjectType_hashFunctionExpression;
62
62
  hashFunctionType = ObjectType_hashFunctionType;
63
- schemaExpression = ObjectType_schemaExpression;
64
- schemaTypeExpression = ObjectType_schemaTypeExpression;
65
63
  toJsonObjectFunctionExpression = ObjectType_toJsonObjectFunctionExpression;
66
64
  toJsonObjectFunctionType = ObjectType_toJsonObjectFunctionType;
67
65
  toLoggableFunctionExpression = ObjectType_toLoggableFunctionExpression;
@@ -125,8 +123,30 @@ export class ObjectType extends AbstractStructuredType {
125
123
  return !this.extern ? super.declaration : Maybe.empty();
126
124
  }
127
125
  get jsonObjectType() {
128
- return this.jsonTypeFactory.createJsonObjectType(this.properties.flatMap((property) => property.jsonObjectMember.toList()), {
129
- name: this.name.map((name) => [name, "Json"]).extract(),
126
+ return ObjectType_jsonObjectType.call(this);
127
+ }
128
+ get schema() {
129
+ return new SchemaObject({
130
+ properties: {
131
+ ...super.schema.properties,
132
+ properties: () => code `properties: { ${joinCode(this.properties.flatMap((property) => property.schema
133
+ .map((propertySchema) => [
134
+ code `${property.name}: ${propertySchema.literalExpression}`,
135
+ ])
136
+ .orDefault([])), { on: "," })} }`,
137
+ },
138
+ type: new SchemaObject.UserDefinedType({
139
+ members: {
140
+ ...super.schema.type.members,
141
+ properties: () => code `properties: { ${joinCode(this.properties.flatMap((property) => property.schema
142
+ .map((propertySchema) => [
143
+ code `${property.name}: ${propertySchema.type.literalExpression}`,
144
+ ])
145
+ .orDefault([])), { on: "," })} }`,
146
+ },
147
+ name: super.schema.type.name,
148
+ }),
149
+ variable: super.schema.variable,
130
150
  });
131
151
  }
132
152
  get focusSparqlConstructTriplesFunction() {
@@ -144,7 +164,7 @@ export class ObjectType extends AbstractStructuredType {
144
164
  .orDefaultLazy(() => this.rdfjsTermExpression(rdfTypeProperty.fromRdfType)));
145
165
  }
146
166
  get graphqlType() {
147
- return new AbstractStructuredType.GraphqlType(this.name
167
+ return new AbstractUserDefinedType.GraphqlType(this.name
148
168
  .map((name) => code `${name}.GraphQL`)
149
169
  .orDefaultLazy(() => ObjectType_graphqlTypeExpression.call(this)), this.reusables);
150
170
  }
@@ -343,6 +363,9 @@ __decorate([
343
363
  __decorate([
344
364
  Memoize()
345
365
  ], ObjectType.prototype, "jsonObjectType", null);
366
+ __decorate([
367
+ Memoize()
368
+ ], ObjectType.prototype, "schema", null);
346
369
  __decorate([
347
370
  Memoize()
348
371
  ], ObjectType.prototype, "focusSparqlConstructTriplesFunction", null);
@@ -1,6 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { AbstractContainerType } from "./AbstractContainerType.js";
3
3
  import type { Callable } from "./Callable.js";
4
+ import { SchemaObject } from "./SchemaObject.js";
4
5
  import { type Code } from "./ts-poet-wrapper.js";
5
6
  export declare class OptionType<ItemTypeT extends OptionType.ItemType> extends AbstractContainerType<ItemTypeT> {
6
7
  readonly graphqlArgs: AbstractContainerType<ItemTypeT>["graphqlArgs"];
@@ -21,7 +22,7 @@ export declare class OptionType<ItemTypeT extends OptionType.ItemType> extends A
21
22
  get graphqlType(): AbstractContainerType.GraphqlType;
22
23
  get hashFunction(): Callable;
23
24
  get mutable(): boolean;
24
- get schemaType(): Code;
25
+ get schema(): SchemaObject<SchemaObject.BuiltinType>;
25
26
  get toJsonValueFunction(): AbstractContainerType<ItemTypeT>["toJsonValueFunction"];
26
27
  get toJsonObjectFunction(): AbstractContainerType<ItemTypeT>["toJsonObjectFunction"];
27
28
  get toRdfResourceValueTypes(): AbstractContainerType<ItemTypeT>["toRdfResourceValueTypes"];
@@ -8,9 +8,10 @@ import { Maybe } from "purify-ts";
8
8
  import { invariant } from "ts-invariant";
9
9
  import { Memoize } from "typescript-memoize";
10
10
  import { AbstractContainerType } from "./AbstractContainerType.js";
11
+ import { BuiltinCallable } from "./BuiltinCallable.js";
11
12
  import { codeEquals } from "./codeEquals.js";
12
13
  import { InlineCallable } from "./InlineCallable.js";
13
- import { ReferenceCallable } from "./ReferenceCallable.js";
14
+ import { SchemaObject } from "./SchemaObject.js";
14
15
  import { code } from "./ts-poet-wrapper.js";
15
16
  export class OptionType extends AbstractContainerType {
16
17
  graphqlArgs = Maybe.empty();
@@ -47,13 +48,13 @@ export class OptionType extends AbstractContainerType {
47
48
  return code `${this.reusables.snippets.MaybeFilter}<${this.itemType.filterType}>`;
48
49
  }
49
50
  get fromJsonValueFunction() {
50
- return new ReferenceCallable(code `${this.reusables.snippets.maybeFromJsonValue}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
51
+ return new BuiltinCallable(code `${this.reusables.snippets.maybeFromJsonValue}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
51
52
  }
52
53
  get fromJsonObjectFunction() {
53
- return new ReferenceCallable(code `${this.reusables.snippets.maybeFromJsonObject}(${this.itemType.fromJsonObjectFunction.annotatedUsage})`);
54
+ return new BuiltinCallable(code `${this.reusables.snippets.maybeFromJsonObject}(${this.itemType.fromJsonObjectFunction.annotatedUsage})`);
54
55
  }
55
56
  get fromRdfResourceValuesFunction() {
56
- return new InlineCallable(code `${this.reusables.snippets.maybeFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schemaType}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
57
+ return new InlineCallable(code `${this.reusables.snippets.maybeFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schema.type.expression}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
57
58
  }
58
59
  get graphqlType() {
59
60
  invariant(!this.itemType.graphqlType.nullable);
@@ -67,14 +68,18 @@ export class OptionType extends AbstractContainerType {
67
68
  get mutable() {
68
69
  return this.itemType.mutable;
69
70
  }
70
- get schemaType() {
71
- return code `${this.reusables.snippets.MaybeSchema}<${this.itemType.schemaType}>`;
71
+ get schema() {
72
+ return new SchemaObject({
73
+ properties: super.schema.properties,
74
+ type: new SchemaObject.BuiltinType(code `${this.reusables.snippets.MaybeSchema}<${this.itemType.schema.type.expression}>`),
75
+ variable: super.schema.variable,
76
+ });
72
77
  }
73
78
  get toJsonValueFunction() {
74
- return new ReferenceCallable(code `${this.reusables.snippets.maybeToJsonValue}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
79
+ return new BuiltinCallable(code `${this.reusables.snippets.maybeToJsonValue}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
75
80
  }
76
81
  get toJsonObjectFunction() {
77
- return new ReferenceCallable(code `${this.reusables.snippets.maybeToJsonObject}(${this.itemType.toJsonObjectFunction.annotatedUsage})`);
82
+ return new BuiltinCallable(code `${this.reusables.snippets.maybeToJsonObject}(${this.itemType.toJsonObjectFunction.annotatedUsage})`);
78
83
  }
79
84
  get toRdfResourceValueTypes() {
80
85
  return this.itemType.toRdfResourceValueTypes;
@@ -85,10 +90,10 @@ export class OptionType extends AbstractContainerType {
85
90
  .orDefault(this.itemValidationFunctionDefault.annotatedUsage)})`));
86
91
  }
87
92
  get valueSparqlConstructTriplesFunction() {
88
- return new InlineCallable(code `${this.reusables.snippets.maybeSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
93
+ return new InlineCallable(code `${this.reusables.snippets.maybeSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
89
94
  }
90
95
  get valueSparqlWherePatternsFunction() {
91
- return new InlineCallable(code `${this.reusables.snippets.maybeSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
96
+ return new InlineCallable(code `${this.reusables.snippets.maybeSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
92
97
  }
93
98
  get inlineExpression() {
94
99
  return code `${this.reusables.imports.Maybe}<${this.itemType.expression}>`;
@@ -142,7 +147,7 @@ __decorate([
142
147
  ], OptionType.prototype, "hashFunction", null);
143
148
  __decorate([
144
149
  Memoize()
145
- ], OptionType.prototype, "schemaType", null);
150
+ ], OptionType.prototype, "schema", null);
146
151
  __decorate([
147
152
  Memoize()
148
153
  ], OptionType.prototype, "toJsonValueFunction", null);
@@ -0,0 +1,98 @@
1
+ import type { Maybe } from "purify-ts";
2
+ import { CodeThunk } from "./CodeThunk.js";
3
+ import type { Snippet } from "./Snippet.js";
4
+ import { type Code } from "./ts-poet-wrapper.js";
5
+ /**
6
+ * Runtime schema/metadata objects for types and properties.
7
+ */
8
+ export declare class SchemaObject<TypeT extends SchemaObject.Type> {
9
+ /**
10
+ * Object literal properties, usually property assignments like name: value
11
+ * without a terminating comma.
12
+ *
13
+ * Note the name is repeated between the key and the value:
14
+ * { name: code`name: value` }
15
+ * Only the value is incorporated into generated code. The keys are used to sort properties.
16
+ *
17
+ * This enables overwriting in the *Type tree while also supporting non-property assignments such as
18
+ * { name: code`get name() { return value; }` }
19
+ * or
20
+ * { shorthand: code `shorthand` }
21
+ */
22
+ readonly properties: Readonly<Record<string, CodeThunk>>;
23
+ /**
24
+ * Type of the schema object.
25
+ */
26
+ readonly type: TypeT;
27
+ /**
28
+ * Variable pointing to the schema object.
29
+ */
30
+ readonly variable: Maybe<Code>;
31
+ constructor({ properties, type, variable, }: {
32
+ properties: Readonly<Record<string, CodeThunk>>;
33
+ type: TypeT;
34
+ variable: Maybe<Code>;
35
+ });
36
+ /**
37
+ * Expression for this schema object, either the variable or a literal expression.
38
+ */
39
+ get expression(): Code;
40
+ /**
41
+ * Literal expression of the schema object e.g., { name1: value1, name2: value2 }
42
+ */
43
+ get literalExpression(): Code;
44
+ toString(): string;
45
+ }
46
+ export declare namespace SchemaObject {
47
+ /**
48
+ * Placeholder for abstract base classes.
49
+ */
50
+ class AbstractType {
51
+ private readonly ownerKind;
52
+ constructor(ownerKind: string);
53
+ get expression(): Code;
54
+ toString(): string;
55
+ }
56
+ /**
57
+ * A built-in schema object type from a snippet or import.
58
+ */
59
+ class BuiltinType {
60
+ readonly expression: Code;
61
+ constructor(expression: Code | Snippet);
62
+ toString(): string;
63
+ }
64
+ /**
65
+ * A user-defined schema object type, typically corresponding to user-defined types.
66
+ */
67
+ class UserDefinedType {
68
+ /**
69
+ * Members of the schema object type, usually property signatures like name: string.
70
+ *
71
+ * Note the name is repeated between the key and the value:
72
+ * { name: code`name: string` }
73
+ * This enables overwriting in the *Type tree. Unlike property assignments (above),
74
+ * we don't really need to support other member types (index signatures, methods, et al.).
75
+ * Rather, the name is repeated here for consistency with property assignments.
76
+ */
77
+ readonly members: Readonly<Record<string, CodeThunk>>;
78
+ /**
79
+ * Name of the type, can be used in type annotations.
80
+ */
81
+ readonly name: Maybe<Code>;
82
+ constructor({ members, name, }: {
83
+ members: Readonly<Record<string, CodeThunk>>;
84
+ name: Maybe<Code>;
85
+ });
86
+ /**
87
+ * Expression of the schema object type, either the name or a literal expression.
88
+ */
89
+ get expression(): Code;
90
+ /**
91
+ * Literal expression of the schema object type e.g., { name1: string, name2: string }.
92
+ */
93
+ get literalExpression(): Code;
94
+ toString(): string;
95
+ }
96
+ type Type = AbstractType | BuiltinType | UserDefinedType;
97
+ }
98
+ //# sourceMappingURL=SchemaObject.d.ts.map
@@ -0,0 +1,143 @@
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 { Memoize } from "typescript-memoize";
8
+ import { CodeThunk } from "./CodeThunk.js";
9
+ import { code, joinCode } from "./ts-poet-wrapper.js";
10
+ /**
11
+ * Runtime schema/metadata objects for types and properties.
12
+ */
13
+ export class SchemaObject {
14
+ /**
15
+ * Object literal properties, usually property assignments like name: value
16
+ * without a terminating comma.
17
+ *
18
+ * Note the name is repeated between the key and the value:
19
+ * { name: code`name: value` }
20
+ * Only the value is incorporated into generated code. The keys are used to sort properties.
21
+ *
22
+ * This enables overwriting in the *Type tree while also supporting non-property assignments such as
23
+ * { name: code`get name() { return value; }` }
24
+ * or
25
+ * { shorthand: code `shorthand` }
26
+ */
27
+ properties;
28
+ /**
29
+ * Type of the schema object.
30
+ */
31
+ type;
32
+ /**
33
+ * Variable pointing to the schema object.
34
+ */
35
+ variable;
36
+ constructor({ properties, type, variable, }) {
37
+ this.properties = properties;
38
+ this.type = type;
39
+ this.variable = variable;
40
+ }
41
+ /**
42
+ * Expression for this schema object, either the variable or a literal expression.
43
+ */
44
+ get expression() {
45
+ return this.variable.orDefaultLazy(() => this.literalExpression);
46
+ }
47
+ /**
48
+ * Literal expression of the schema object e.g., { name1: value1, name2: value2 }
49
+ */
50
+ get literalExpression() {
51
+ return code `{ ${joinCode(Object.keys(this.properties)
52
+ .sort()
53
+ .map((key) => CodeThunk.evaluate(this.properties[key])), { on: ", " })} } as const`;
54
+ }
55
+ toString() {
56
+ throw new Error("should never be called");
57
+ }
58
+ }
59
+ __decorate([
60
+ Memoize()
61
+ ], SchemaObject.prototype, "expression", null);
62
+ __decorate([
63
+ Memoize()
64
+ ], SchemaObject.prototype, "literalExpression", null);
65
+ (function (SchemaObject) {
66
+ /**
67
+ * Placeholder for abstract base classes.
68
+ */
69
+ class AbstractType {
70
+ ownerKind;
71
+ constructor(ownerKind) {
72
+ this.ownerKind = ownerKind;
73
+ }
74
+ get expression() {
75
+ throw new Error(`should never be called (instantiated by ${this.ownerKind})`);
76
+ }
77
+ toString() {
78
+ throw new Error("should never be called");
79
+ }
80
+ }
81
+ SchemaObject.AbstractType = AbstractType;
82
+ /**
83
+ * A built-in schema object type from a snippet or import.
84
+ */
85
+ class BuiltinType {
86
+ expression;
87
+ constructor(expression) {
88
+ this.expression = code `${expression}`;
89
+ }
90
+ toString() {
91
+ throw new Error("should never be called");
92
+ }
93
+ }
94
+ SchemaObject.BuiltinType = BuiltinType;
95
+ /**
96
+ * A user-defined schema object type, typically corresponding to user-defined types.
97
+ */
98
+ class UserDefinedType {
99
+ /**
100
+ * Members of the schema object type, usually property signatures like name: string.
101
+ *
102
+ * Note the name is repeated between the key and the value:
103
+ * { name: code`name: string` }
104
+ * This enables overwriting in the *Type tree. Unlike property assignments (above),
105
+ * we don't really need to support other member types (index signatures, methods, et al.).
106
+ * Rather, the name is repeated here for consistency with property assignments.
107
+ */
108
+ members;
109
+ /**
110
+ * Name of the type, can be used in type annotations.
111
+ */
112
+ name;
113
+ constructor({ members, name, }) {
114
+ this.members = members;
115
+ this.name = name;
116
+ }
117
+ /**
118
+ * Expression of the schema object type, either the name or a literal expression.
119
+ */
120
+ get expression() {
121
+ return this.name.orDefaultLazy(() => this.literalExpression);
122
+ }
123
+ /**
124
+ * Literal expression of the schema object type e.g., { name1: string, name2: string }.
125
+ */
126
+ get literalExpression() {
127
+ return code `{ ${joinCode(Object.keys(this.members)
128
+ .sort()
129
+ .map((key) => code `${CodeThunk.evaluate(this.members[key])};`))} }`;
130
+ }
131
+ toString() {
132
+ throw new Error("should never be called");
133
+ }
134
+ }
135
+ __decorate([
136
+ Memoize()
137
+ ], UserDefinedType.prototype, "expression", null);
138
+ __decorate([
139
+ Memoize()
140
+ ], UserDefinedType.prototype, "literalExpression", null);
141
+ SchemaObject.UserDefinedType = UserDefinedType;
142
+ })(SchemaObject || (SchemaObject = {}));
143
+ //# sourceMappingURL=SchemaObject.js.map
@@ -1,6 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
3
3
  import type { Callable } from "./Callable.js";
4
+ import { SchemaObject } from "./SchemaObject.js";
4
5
  import { type Code } from "./ts-poet-wrapper.js";
5
6
  export declare class SetType<ItemTypeT extends SetType.ItemType> extends AbstractCollectionType<ItemTypeT> {
6
7
  readonly graphqlArgs: AbstractCollectionType<ItemTypeT>["graphqlArgs"];
@@ -24,7 +25,7 @@ export declare class SetType<ItemTypeT extends SetType.ItemType> extends Abstrac
24
25
  get toRdfResourceValueTypes(): AbstractCollectionType<ItemTypeT>["toRdfResourceValueTypes"];
25
26
  get valueSparqlConstructTriplesFunction(): Callable;
26
27
  get valueSparqlWherePatternsFunction(): Callable;
27
- protected get schemaInitializers(): readonly Code[];
28
+ get schema(): SchemaObject<SchemaObject.BuiltinType>;
28
29
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
29
30
  toStringExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toStringExpression"]>[0]): Code;
30
31
  }
@@ -8,8 +8,9 @@ import { Maybe } from "purify-ts";
8
8
  import { invariant } from "ts-invariant";
9
9
  import { Memoize } from "typescript-memoize";
10
10
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
11
+ import { BuiltinCallable } from "./BuiltinCallable.js";
11
12
  import { InlineCallable } from "./InlineCallable.js";
12
- import { ReferenceCallable } from "./ReferenceCallable.js";
13
+ import { SchemaObject } from "./SchemaObject.js";
13
14
  import { code, joinCode } from "./ts-poet-wrapper.js";
14
15
  export class SetType extends AbstractCollectionType {
15
16
  graphqlArgs = Maybe.empty();
@@ -70,16 +71,16 @@ export class SetType extends AbstractCollectionType {
70
71
  throw new Error("should never be called");
71
72
  }
72
73
  get fromJsonValueFunction() {
73
- return new ReferenceCallable(code `${this.reusables.snippets.arrayFromJsonArray}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
74
+ return new BuiltinCallable(code `${this.reusables.snippets.arrayFromJsonArray}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
74
75
  }
75
76
  get fromJsonObjectFunction() {
76
77
  throw new Error("should never be called");
77
78
  }
78
79
  get fromRdfResourceValuesFunction() {
79
- return new InlineCallable(code `${this._mutable ? this.reusables.snippets.mutableSetFromRdfResourceValues : this.reusables.snippets.setFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schemaType}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
80
+ return new InlineCallable(code `${this._mutable ? this.reusables.snippets.mutableSetFromRdfResourceValues : this.reusables.snippets.setFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schema.type.expression}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
80
81
  }
81
82
  get toJsonValueFunction() {
82
- return new ReferenceCallable(code `${this.reusables.snippets.arrayToJsonArray}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
83
+ return new BuiltinCallable(code `${this.reusables.snippets.arrayToJsonArray}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
83
84
  }
84
85
  get toJsonObjectFunction() {
85
86
  throw new Error("should never be called");
@@ -88,17 +89,25 @@ export class SetType extends AbstractCollectionType {
88
89
  return this.itemType.toRdfResourceValueTypes;
89
90
  }
90
91
  get valueSparqlConstructTriplesFunction() {
91
- return new InlineCallable(code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
92
+ return new InlineCallable(code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
92
93
  }
93
94
  get valueSparqlWherePatternsFunction() {
94
- return new InlineCallable(code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
95
+ return new InlineCallable(code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
95
96
  }
96
- get schemaInitializers() {
97
- let schemaInitializers = super.schemaInitializers;
97
+ get schema() {
98
98
  if (this.minCount > 0n) {
99
- schemaInitializers = schemaInitializers.concat(code `minCount: ${Number(this.minCount)}`);
99
+ return new SchemaObject({
100
+ properties: {
101
+ ...super.schema.properties,
102
+ minCount: code `minCount: ${Number(this.minCount)}`,
103
+ },
104
+ type: super.schema.type,
105
+ variable: super.schema.variable,
106
+ });
107
+ }
108
+ else {
109
+ return super.schema;
100
110
  }
101
- return schemaInitializers;
102
111
  }
103
112
  toRdfResourceValuesExpression({ variables, }) {
104
113
  return code `${variables.value}.flatMap((item) => ${this.itemType.toRdfResourceValuesExpression({
@@ -130,6 +139,9 @@ __decorate([
130
139
  __decorate([
131
140
  Memoize()
132
141
  ], SetType.prototype, "valueSparqlWherePatternsFunction", null);
142
+ __decorate([
143
+ Memoize()
144
+ ], SetType.prototype, "schema", null);
133
145
  (function (SetType) {
134
146
  SetType.isItemType = AbstractCollectionType.isItemType;
135
147
  })(SetType || (SetType = {}));
@@ -45,6 +45,7 @@ export declare class Snippets {
45
45
  get LangStringSchema(): Snippet;
46
46
  get Lazy(): Snippet;
47
47
  get LazyOption(): Snippet;
48
+ get LazySchema(): Snippet;
48
49
  get LazySet(): Snippet;
49
50
  get LiteralFilter(): Snippet;
50
51
  get LiteralJsonObject(): Snippet;
@@ -39,6 +39,7 @@ import { snippets_LangStringJsonObject } from "./_snippets/snippets_LangStringJs
39
39
  import { snippets_LangStringSchema } from "./_snippets/snippets_LangStringSchema.js";
40
40
  import { snippets_Lazy } from "./_snippets/snippets_Lazy.js";
41
41
  import { snippets_LazyOption } from "./_snippets/snippets_LazyOption.js";
42
+ import { snippets_LazySchema } from "./_snippets/snippets_LazySchema.js";
42
43
  import { snippets_LazySet } from "./_snippets/snippets_LazySet.js";
43
44
  import { snippets_LiteralFilter } from "./_snippets/snippets_LiteralFilter.js";
44
45
  import { snippets_LiteralJsonObject } from "./_snippets/snippets_LiteralJsonObject.js";
@@ -359,6 +360,9 @@ export class Snippets {
359
360
  get LazyOption() {
360
361
  return this.snippet(snippets_LazyOption);
361
362
  }
363
+ get LazySchema() {
364
+ return this.snippet(snippets_LazySchema);
365
+ }
362
366
  get LazySet() {
363
367
  return this.snippet(snippets_LazySet);
364
368
  }
@@ -1166,6 +1170,9 @@ __decorate([
1166
1170
  __decorate([
1167
1171
  Memoize()
1168
1172
  ], Snippets.prototype, "LazyOption", null);
1173
+ __decorate([
1174
+ Memoize()
1175
+ ], Snippets.prototype, "LazySchema", null);
1169
1176
  __decorate([
1170
1177
  Memoize()
1171
1178
  ], Snippets.prototype, "LazySet", null);