@shaclmate/compiler 4.0.35 → 4.0.37

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 (76) hide show
  1. package/dist/ShapesGraphToAstTransformer.js +10 -0
  2. package/dist/ast/Ast.d.ts +1 -0
  3. package/dist/generators/ts/AbstractNamedUnionType.js +39 -22
  4. package/dist/generators/ts/AbstractObjectSetType.d.ts +35 -0
  5. package/dist/generators/ts/AbstractObjectSetType.js +44 -0
  6. package/dist/generators/ts/GraphqlSchema.d.ts +22 -0
  7. package/dist/generators/ts/GraphqlSchema.js +87 -0
  8. package/dist/generators/ts/NamedObjectType.js +13 -4
  9. package/dist/generators/ts/NamedObjectUnionType.js +14 -5
  10. package/dist/generators/ts/ObjectSetType.d.ts +6 -0
  11. package/dist/generators/ts/ObjectSetType.js +36 -0
  12. package/dist/generators/ts/RdfjsDatasetObjectSetType.d.ts +6 -0
  13. package/dist/generators/ts/{rdfjsDatasetObjectSetClassDeclaration.js → RdfjsDatasetObjectSetType.js} +73 -69
  14. package/dist/generators/ts/Snippets.d.ts +1 -0
  15. package/dist/generators/ts/Snippets.js +7 -0
  16. package/dist/generators/ts/SparqlObjectSetType.d.ts +6 -0
  17. package/dist/generators/ts/{sparqlObjectSetClassDeclaration.js → SparqlObjectSetType.js} +40 -35
  18. package/dist/generators/ts/TsFeature.d.ts +1 -1
  19. package/dist/generators/ts/TsFeature.js +25 -7
  20. package/dist/generators/ts/TsGenerator.d.ts +7 -8
  21. package/dist/generators/ts/TsGenerator.js +141 -52
  22. package/dist/generators/ts/ZodGenerator.d.ts +1 -2
  23. package/dist/generators/ts/ZodGenerator.js +12 -12
  24. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +18 -12
  25. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +1 -1
  26. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +2 -1
  27. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js +6 -2
  28. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +2 -1
  29. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.js +6 -2
  30. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
  31. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
  32. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -1
  33. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +1 -1
  34. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -1
  35. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
  36. package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js +1 -1
  37. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +1 -1
  38. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +2 -1
  39. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +6 -2
  40. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +1 -1
  41. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
  42. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +1 -1
  43. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
  44. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +2 -1
  45. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +6 -2
  46. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +1 -1
  47. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  48. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +3 -2
  49. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js +1 -1
  50. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +5 -4
  51. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
  52. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
  53. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +4 -2
  54. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +3 -0
  55. package/dist/generators/ts/_snippets/snippets_FromRdfResourceFunction.js +2 -2
  56. package/dist/generators/ts/_snippets/snippets_FromRdfResourceValuesFunction.js +2 -2
  57. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +12 -6
  58. package/dist/generators/ts/_snippets/snippets__FromRdfResourceFunction.js +2 -2
  59. package/dist/generators/ts/_snippets/snippets_monkeyPatchObject.d.ts +3 -0
  60. package/dist/generators/ts/_snippets/snippets_monkeyPatchObject.js +16 -0
  61. package/dist/generators/ts/_snippets/snippets_wrap_FromRdfResourceFunction.js +3 -4
  62. package/dist/input/generated.d.ts +1 -286
  63. package/dist/input/generated.js +104 -1093
  64. package/package.json +2 -2
  65. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +0 -10
  66. package/dist/generators/ts/graphqlSchemaVariableStatement.js +0 -84
  67. package/dist/generators/ts/objectSetDeclarations.d.ts +0 -9
  68. package/dist/generators/ts/objectSetDeclarations.js +0 -30
  69. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +0 -9
  70. package/dist/generators/ts/objectSetInterfaceDeclaration.js +0 -26
  71. package/dist/generators/ts/objectSetMethodSignatures.d.ts +0 -18
  72. package/dist/generators/ts/objectSetMethodSignatures.js +0 -31
  73. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +0 -9
  74. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +0 -9
  75. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +0 -12
  76. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +0 -21
@@ -2,39 +2,34 @@ import { Maybe } from "purify-ts";
2
2
  import { invariant } from "ts-invariant";
3
3
  import * as ast from "../../ast/index.js";
4
4
  import { BlankNodeType } from "./BlankNodeType.js";
5
- import { graphqlSchemaVariableStatement } from "./graphqlSchemaVariableStatement.js";
5
+ import { GraphqlSchema } from "./GraphqlSchema.js";
6
6
  import { IdentifierType } from "./IdentifierType.js";
7
7
  import { IriType } from "./IriType.js";
8
8
  import { NamedObjectUnionType } from "./NamedObjectUnionType.js";
9
- import { objectSetDeclarations } from "./objectSetDeclarations.js";
9
+ import { ObjectSetType } from "./ObjectSetType.js";
10
+ import { RdfjsDatasetObjectSetType } from "./RdfjsDatasetObjectSetType.js";
10
11
  import { Reusables } from "./Reusables.js";
12
+ import { SparqlObjectSetType } from "./SparqlObjectSetType.js";
11
13
  import { TypeFactory } from "./TypeFactory.js";
12
14
  import { code, joinCode } from "./ts-poet-wrapper.js";
13
15
  export class TsGenerator {
14
- typeFactory;
15
16
  configuration;
16
17
  logger;
17
- reusables;
18
18
  constructor({ configuration, logger, }) {
19
- if (!configuration) {
20
- configuration = TsGenerator.Configuration.default_;
21
- }
22
- this.configuration = {
23
- ...configuration,
24
- features: TsGenerator.Configuration.inferFeatures(configuration.features),
25
- };
19
+ this.configuration = configuration;
26
20
  this.logger = logger;
27
- this.reusables = new Reusables({
28
- configuration: this.configuration,
29
- logger,
30
- });
31
- this.typeFactory = new TypeFactory({
32
- configuration: this.configuration,
33
- logger,
34
- reusables: this.reusables,
35
- });
36
21
  }
37
22
  generate(ast_) {
23
+ const configuration = TsGenerator.Configuration.finalize(ast_, this.configuration);
24
+ const reusables = new Reusables({
25
+ configuration,
26
+ logger: this.logger,
27
+ });
28
+ const typeFactory = new TypeFactory({
29
+ configuration,
30
+ logger: this.logger,
31
+ reusables,
32
+ });
38
33
  let declarations = [];
39
34
  for (const namedObjectType of ast_.namedObjectTypes) {
40
35
  for (const tsImport of namedObjectType.tsImports) {
@@ -45,12 +40,12 @@ export class TsGenerator {
45
40
  if (astNamedUnionType.isObjectUnionType()) {
46
41
  continue;
47
42
  }
48
- declarations = declarations.concat(this.typeFactory.createType(astNamedUnionType).declaration.toList());
43
+ declarations = declarations.concat(typeFactory.createType(astNamedUnionType).declaration.toList());
49
44
  }
50
- const namedObjectTypesToposorted = ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType));
45
+ const namedObjectTypesToposorted = ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createNamedObjectType(astObjectType));
51
46
  const namedObjectUnionTypesToposorted = ast_.namedUnionTypes
52
47
  .filter((_) => _.isObjectUnionType())
53
- .map((astObjectUnionType) => this.typeFactory.createNamedObjectUnionType(astObjectUnionType));
48
+ .map((astObjectUnionType) => typeFactory.createNamedObjectUnionType(astObjectUnionType));
54
49
  for (const namedObjectType of namedObjectTypesToposorted) {
55
50
  declarations = declarations.concat(namedObjectType.declaration.toList());
56
51
  }
@@ -63,31 +58,64 @@ export class TsGenerator {
63
58
  case 0:
64
59
  break;
65
60
  case 1:
66
- declarations.push(code `type ${this.configuration.syntheticNamePrefix}Object = ${namedObjectTypesNameSorted[0].name};`);
61
+ declarations.push(code `type ${configuration.syntheticNamePrefix}Object = ${namedObjectTypesNameSorted[0].name};`);
67
62
  break;
68
63
  default: {
69
- const uberObjectUnionType = this.synthesizeUberObjectUnionType(namedObjectTypesToposorted.toReversed());
64
+ const uberObjectUnionType = this.synthesizeUberObjectUnionType({
65
+ configuration,
66
+ namedObjectTypes: namedObjectTypesToposorted.toReversed(), // Reverse topological order so children ane before parents
67
+ reusables,
68
+ });
70
69
  declarations = declarations.concat(uberObjectUnionType.declaration.toList());
71
70
  namedObjectUnionTypesNameSorted.push(uberObjectUnionType);
72
71
  }
73
72
  }
74
- declarations.push(...objectSetDeclarations.call(this, {
73
+ declarations.push(...this.objectSetTypeDeclarations({
74
+ configuration,
75
75
  namedObjectTypes: namedObjectTypesNameSorted,
76
76
  namedObjectUnionTypes: namedObjectUnionTypesNameSorted,
77
+ reusables,
77
78
  }));
78
- declarations.push(...graphqlSchemaVariableStatement
79
- .call(this, {
80
- namedObjectTypes: namedObjectTypesNameSorted,
81
- namedObjectUnionTypes: namedObjectUnionTypesNameSorted,
82
- })
83
- .toList());
84
- declarations.splice(0, 0, joinCode(this.reusables.snippets.ifUsed, { on: "\n\n" }));
79
+ if (configuration.features.has("GraphQL")) {
80
+ const graphqlNamedObjectTypes = namedObjectTypesNameSorted.filter((namedObjectType) => !namedObjectType.synthetic);
81
+ const graphqlNamedObjectUnionTypes = namedObjectUnionTypesNameSorted.filter((namedObjectUnionType) => !namedObjectUnionType.synthetic);
82
+ if (graphqlNamedObjectTypes.length > 0) {
83
+ declarations.push(new GraphqlSchema({
84
+ configuration,
85
+ logger: this.logger,
86
+ namedObjectTypes: graphqlNamedObjectTypes,
87
+ namedObjectUnionTypes: graphqlNamedObjectUnionTypes,
88
+ reusables,
89
+ }).declaration);
90
+ }
91
+ }
92
+ declarations.splice(0, 0, joinCode(reusables.snippets.ifUsed, { on: "\n\n" }));
85
93
  return joinCode(declarations).toString({});
86
94
  }
95
+ objectSetTypeDeclarations({ configuration, namedObjectTypes, namedObjectUnionTypes, reusables, }) {
96
+ const constructorParameters = {
97
+ configuration,
98
+ logger: this.logger,
99
+ namedObjectTypes: namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern && !namedObjectType.synthetic),
100
+ namedObjectUnionTypes,
101
+ reusables,
102
+ };
103
+ const declarations = [];
104
+ if (configuration.features.has("ObjectSet")) {
105
+ declarations.push(new ObjectSetType(constructorParameters).declaration);
106
+ }
107
+ if (configuration.features.has("RdfjsDatasetObjectSet")) {
108
+ declarations.push(new RdfjsDatasetObjectSetType(constructorParameters).declaration);
109
+ }
110
+ if (configuration.features.has("SparqlObjectSet")) {
111
+ declarations.push(new SparqlObjectSetType(constructorParameters).declaration);
112
+ }
113
+ return declarations;
114
+ }
87
115
  /**
88
116
  * Synthesize the $Object union.
89
117
  */
90
- synthesizeUberObjectUnionType(namedObjectTypes) {
118
+ synthesizeUberObjectUnionType({ configuration, namedObjectTypes, reusables, }) {
91
119
  const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern);
92
120
  invariant(filteredNamedObjectTypes.length > 0);
93
121
  const nodeKinds = filteredNamedObjectTypes.reduce((nodeKinds, namedObjectType) => {
@@ -100,10 +128,10 @@ export class TsGenerator {
100
128
  if (nodeKinds.size === 2) {
101
129
  identifierType = new IdentifierType({
102
130
  comment: Maybe.empty(),
103
- configuration: this.configuration,
131
+ configuration,
104
132
  label: Maybe.empty(),
105
133
  logger: this.logger,
106
- reusables: this.reusables,
134
+ reusables,
107
135
  });
108
136
  }
109
137
  else {
@@ -111,28 +139,28 @@ export class TsGenerator {
111
139
  case "BlankNode":
112
140
  identifierType = new BlankNodeType({
113
141
  comment: Maybe.empty(),
114
- configuration: this.configuration,
142
+ configuration,
115
143
  label: Maybe.empty(),
116
144
  logger: this.logger,
117
- reusables: this.reusables,
145
+ reusables,
118
146
  });
119
147
  break;
120
148
  case "IRI":
121
149
  identifierType = new IriType({
122
150
  comment: Maybe.empty(),
123
- configuration: this.configuration,
151
+ configuration,
124
152
  hasValues: [],
125
153
  in_: [],
126
154
  label: Maybe.empty(),
127
155
  logger: this.logger,
128
- reusables: this.reusables,
156
+ reusables,
129
157
  });
130
158
  break;
131
159
  }
132
160
  }
133
161
  return new NamedObjectUnionType({
134
162
  comment: Maybe.empty(),
135
- configuration: this.configuration,
163
+ configuration,
136
164
  identifierType,
137
165
  label: Maybe.empty(),
138
166
  logger: this.logger,
@@ -140,9 +168,9 @@ export class TsGenerator {
140
168
  discriminantValue: Maybe.empty(),
141
169
  type: namedObjectType,
142
170
  })),
143
- name: `${this.configuration.syntheticNamePrefix}Object`,
171
+ name: `${configuration.syntheticNamePrefix}Object`,
144
172
  recursive: false,
145
- reusables: this.reusables,
173
+ reusables,
146
174
  synthetic: true,
147
175
  });
148
176
  }
@@ -151,20 +179,81 @@ export class TsGenerator {
151
179
  let Configuration;
152
180
  (function (Configuration) {
153
181
  Configuration.default_ = {
154
- features: new Set(["create", "equals", "hash", "json", "rdf"]),
182
+ features: new Set([
183
+ "Object.create",
184
+ "Object.equals",
185
+ "Object.hash",
186
+ "JSON",
187
+ "RDF",
188
+ ]),
155
189
  syntheticNamePrefix: "$",
156
190
  };
157
- function inferFeatures(features) {
158
- const inferredFeatures = new Set(features);
159
- if (inferredFeatures.has("graphql") || inferredFeatures.has("sparql")) {
160
- inferredFeatures.add("rdf");
191
+ const featureDependenciesStatic = {
192
+ GraphQL: ["ObjectSet"],
193
+ // Alias for other features, not dependencies per se
194
+ JSON: ["Object.JSON"],
195
+ "Object.create": ["Object.schema", "Object.toString", "Object.type"],
196
+ "Object.equals": ["Object.type"],
197
+ "Object.filter": ["Object.type"],
198
+ "Object.fromJson": ["Object.create", "Object.JSON.type", "Object.type"],
199
+ "Object.fromRdf": ["Object.create", "Object.schema"],
200
+ "Object.hash": [],
201
+ // Alias for other features, not dependencies per se
202
+ "Object.JSON": [
203
+ "Object.fromJson",
204
+ "Object.JSON.parse",
205
+ "Object.JSON.schema",
206
+ "Object.JSON.type",
207
+ "Object.JSON.uiSchema",
208
+ "Object.toJson",
209
+ ],
210
+ "Object.JSON.parse": ["Object.JSON.schema", "Object.JSON.type"],
211
+ "Object.JSON.type": [],
212
+ "Object.JSON.schema": ["Object.JSON.type"],
213
+ "Object.JSON.uiSchema": [],
214
+ // Alias for other features, not dependencies per se
215
+ "Object.RDF": ["Object.fromRdf", "Object.toRdf"],
216
+ "Object.schema": [],
217
+ "Object.toJson": ["Object.JSON.type", "Object.type"],
218
+ "Object.toRdf": ["Object.schema", "Object.type"],
219
+ "Object.toString": ["Object.type"],
220
+ "Object.SPARQL": ["Object.schema"],
221
+ "Object.type": [], // Implies Object.Identifier
222
+ ObjectSet: ["Object.filter"],
223
+ // Alias for other features, not dependencies per se
224
+ RDF: ["Object.RDF", "RdfjsDatasetObjectSet"],
225
+ RdfjsDatasetObjectSet: ["Object.fromRdf", "ObjectSet"],
226
+ SPARQL: ["Object.SPARQL", "SparqlObjectSet"],
227
+ SparqlObjectSet: ["Object.SPARQL", "ObjectSet"],
228
+ };
229
+ function finalize(ast, partialConfiguration) {
230
+ const requestedFeatures = partialConfiguration?.features ?? Configuration.default_.features;
231
+ const featureDependencies = Object.fromEntries(Object.entries(featureDependenciesStatic).map(([k, v]) => [k, [...v]]));
232
+ if (ast.lazyTypesCount > 0) {
233
+ featureDependencies["Object.fromJson"].push("ObjectSet");
234
+ featureDependencies["Object.fromRdf"].push("ObjectSet", "RdfjsDatasetObjectSet");
161
235
  }
162
- if (inferredFeatures.has("json") || inferredFeatures.has("rdf")) {
163
- inferredFeatures.add("create");
236
+ const inferredFeatures = new Set(requestedFeatures);
237
+ {
238
+ const inferredFeaturesQueue = [...requestedFeatures];
239
+ while (inferredFeaturesQueue.length > 0) {
240
+ const feature = inferredFeaturesQueue.shift();
241
+ for (const featureDependency of featureDependencies[feature]) {
242
+ if (!inferredFeatures.has(featureDependency)) {
243
+ inferredFeatures.add(featureDependency);
244
+ inferredFeaturesQueue.push(featureDependency);
245
+ }
246
+ }
247
+ }
164
248
  }
165
- return inferredFeatures;
249
+ return {
250
+ features: inferredFeatures,
251
+ finalized: true,
252
+ syntheticNamePrefix: partialConfiguration?.syntheticNamePrefix ??
253
+ Configuration.default_.syntheticNamePrefix,
254
+ };
166
255
  }
167
- Configuration.inferFeatures = inferFeatures;
256
+ Configuration.finalize = finalize;
168
257
  })(Configuration = TsGenerator.Configuration || (TsGenerator.Configuration = {}));
169
258
  })(TsGenerator || (TsGenerator = {}));
170
259
  //# sourceMappingURL=TsGenerator.js.map
@@ -2,8 +2,7 @@ import type { Logger } from "ts-log";
2
2
  import * as ast from "../../ast/index.js";
3
3
  import type { Generator } from "../Generator.js";
4
4
  export declare class ZodGenerator implements Generator {
5
- private readonly reusables;
6
- private readonly typeFactory;
5
+ private readonly logger;
7
6
  constructor({ logger }: {
8
7
  logger: Logger;
9
8
  });
@@ -7,20 +7,20 @@ import { TsGenerator } from "./TsGenerator.js";
7
7
  import { TypeFactory } from "./TypeFactory.js";
8
8
  import { code, joinCode } from "./ts-poet-wrapper.js";
9
9
  export class ZodGenerator {
10
- reusables;
11
- typeFactory;
10
+ logger;
12
11
  constructor({ logger }) {
13
- const configuration = TsGenerator.Configuration.default_;
14
- this.reusables = new Reusables({ configuration, logger });
15
- this.typeFactory = new TypeFactory({
16
- configuration,
17
- logger,
18
- reusables: this.reusables,
19
- });
12
+ this.logger = logger;
20
13
  }
21
14
  generate(ast_) {
15
+ const configuration = TsGenerator.Configuration.finalize(ast_, TsGenerator.Configuration.default_);
16
+ const reusables = new Reusables({ configuration, logger: this.logger });
17
+ const typeFactory = new TypeFactory({
18
+ configuration,
19
+ logger: this.logger,
20
+ reusables,
21
+ });
22
22
  const declarations = [];
23
- for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType))) {
23
+ for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createNamedObjectType(astObjectType))) {
24
24
  declarations.push(code `\
25
25
  export namespace ${namedObjectType.name} {
26
26
  ${joinCode(NamedObjectType_jsonTypeAliasDeclaration.call(namedObjectType).toList())}
@@ -30,7 +30,7 @@ export namespace ${namedObjectType.name} {
30
30
  }
31
31
  }`);
32
32
  }
33
- for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => this.typeFactory.createUnionType(astNamedUnionType))) {
33
+ for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => typeFactory.createUnionType(astNamedUnionType))) {
34
34
  invariant(astNamedUnionType.kind !== "AnonymousUnionType");
35
35
  declarations.push(code `\
36
36
  export namespace ${astNamedUnionType.name} {
@@ -40,7 +40,7 @@ export namespace ${astNamedUnionType.name} {
40
40
  }
41
41
  }`);
42
42
  }
43
- declarations.splice(0, 0, joinCode(this.reusables.snippets.ifUsed, { on: "\n\n" }));
43
+ declarations.splice(0, 0, joinCode(reusables.snippets.ifUsed, { on: "\n\n" }));
44
44
  return joinCode(declarations, { on: "\n\n" }).toString({});
45
45
  }
46
46
  }
@@ -2,7 +2,7 @@ import { Maybe } from "purify-ts";
2
2
  import { invariant } from "ts-invariant";
3
3
  import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
4
4
  export function NamedObjectType_createFunctionDeclaration() {
5
- if (!this.configuration.features.has("create")) {
5
+ if (!this.configuration.features.has("Object.create")) {
6
6
  return Maybe.empty();
7
7
  }
8
8
  const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParameter.toList());
@@ -37,19 +37,25 @@ export function NamedObjectType_createFunctionDeclaration() {
37
37
  expression: code `${this.reusables.snippets.sequenceRecord}({ ${joinCode(propertyInitializers, { on: "," })} })`,
38
38
  variable: "properties",
39
39
  });
40
- const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
40
+ let returnExpression = code `{ ${chains
41
+ .map((chain) => `...${chain.variable}`)
42
+ .join(", ")}, ${this._discriminantProperty.name}: ${literalOf(this.discriminantValue)} as const }`;
43
+ const monkeyPatchMethods = [];
44
+ if (this.configuration.features.has("Object.toJson")) {
45
+ monkeyPatchMethods.push("toJson");
46
+ }
47
+ if (this.configuration.features.has("Object.toString")) {
48
+ monkeyPatchMethods.push(`${this.configuration.syntheticNamePrefix}toString`);
49
+ }
50
+ if (monkeyPatchMethods.length > 0) {
51
+ returnExpression = code `${this.reusables.snippets.monkeyPatchObject}(${returnExpression}, { ${monkeyPatchMethods.join(", ")} })`;
52
+ }
53
+ returnExpression = chains
54
+ .toReversed()
55
+ .reduce((acc, { expression, variable }, chainI) => code `(${expression}).${chainI === 0 ? "map" : "chain"}(${variable} => ${acc})`, returnExpression);
41
56
  return Maybe.of(code `\
42
57
  export function create(${parametersSignature}): ${this.reusables.imports.Either}<Error, ${this.name}> {
43
- return ${chains.toReversed().reduce((acc, { expression, variable }, chainI) => code `(${expression}).${chainI === 0 ? "map" : "chain"}(${variable} => ${acc})`, code `\
44
- {
45
- const finalObject = { ${chains
46
- .map((chain) => `...${chain.variable}`)
47
- .join(", ")}, ${this._discriminantProperty.name}: ${literalOf(this.discriminantValue)} as const };
48
- if (!globalThis.Object.prototype.hasOwnProperty.call(finalObject, "toString")) {
49
- (finalObject as any).toString = ${syntheticNamePrefix}toString;
50
- }
51
- return finalObject;
52
- }`)};
58
+ return ${returnExpression};
53
59
  }
54
60
 
55
61
  export function createUnsafe(${parametersSignature}): ${this.name} {
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_equalsFunctionDeclaration() {
4
- if (!this.configuration.features.has("equals")) {
4
+ if (!this.configuration.features.has("Object.equals")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const chain = [];
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import type { NamedObjectType } from "../NamedObjectType.js";
2
3
  import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function NamedObjectType_filterFunctionDeclaration(this: NamedObjectType): Code;
4
+ export declare function NamedObjectType_filterFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
4
5
  //# sourceMappingURL=NamedObjectType_filterFunctionDeclaration.d.ts.map
@@ -1,5 +1,9 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
2
3
  export function NamedObjectType_filterFunctionDeclaration() {
4
+ if (!this.configuration.features.has("Object.filter")) {
5
+ return Maybe.empty();
6
+ }
3
7
  const statements = [];
4
8
  for (const parentObjectType of this.parentObjectTypes) {
5
9
  statements.push(code `if (!${parentObjectType.filterFunction}(filter, value)) { return false; }`);
@@ -12,9 +16,9 @@ export function NamedObjectType_filterFunctionDeclaration() {
12
16
  }
13
17
  }
14
18
  statements.push(code `return true;`);
15
- return code `\
19
+ return Maybe.of(code `\
16
20
  export function filter(filter: ${this.filterType}, value: ${this.name}): boolean {
17
21
  ${joinCode(statements)}
18
- }`;
22
+ }`);
19
23
  }
20
24
  //# sourceMappingURL=NamedObjectType_filterFunctionDeclaration.js.map
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import type { NamedObjectType } from "../NamedObjectType.js";
2
3
  import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function NamedObjectType_filterTypeDeclaration(this: NamedObjectType): Code;
4
+ export declare function NamedObjectType_filterTypeDeclaration(this: NamedObjectType): Maybe<Code>;
4
5
  //# sourceMappingURL=NamedObjectType_filterTypeDeclaration.d.ts.map
@@ -1,5 +1,9 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
2
3
  export function NamedObjectType_filterTypeDeclaration() {
4
+ if (!this.configuration.features.has("Object.filter")) {
5
+ return Maybe.empty();
6
+ }
3
7
  const members = [];
4
8
  if (this.properties.length > 0) {
5
9
  const filterProperties = {};
@@ -15,7 +19,7 @@ export function NamedObjectType_filterTypeDeclaration() {
15
19
  for (const parentObjectType of this.parentObjectTypes) {
16
20
  members.push(code `${parentObjectType.name}.Filter`);
17
21
  }
18
- return code `\
19
- export type Filter = ${members.length > 0 ? joinCode(members, { on: " & " }) : "object"};`;
22
+ return Maybe.of(code `\
23
+ export type Filter = ${members.length > 0 ? joinCode(members, { on: " & " }) : "object"};`);
20
24
  }
21
25
  //# sourceMappingURL=NamedObjectType_filterTypeDeclaration.js.map
@@ -7,7 +7,7 @@ const variables = {
7
7
  variablePrefix: code `parameters.variablePrefix`,
8
8
  };
9
9
  export function NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration() {
10
- if (!this.configuration.features.has("sparql")) {
10
+ if (!this.configuration.features.has("Object.SPARQL")) {
11
11
  return Maybe.empty();
12
12
  }
13
13
  const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
@@ -8,7 +8,7 @@ const variables = {
8
8
  variablePrefix: code `parameters.variablePrefix`,
9
9
  };
10
10
  export function NamedObjectType_focusSparqlWherePatternsFunctionDeclaration() {
11
- if (!this.configuration.features.has("sparql")) {
11
+ if (!this.configuration.features.has("Object.SPARQL")) {
12
12
  return Maybe.empty();
13
13
  }
14
14
  const rdfClassVariable = code `${this.reusables.imports.dataFactory}.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_fromJsonFunctionDeclaration() {
4
- if (!this.configuration.features.has("json")) {
4
+ if (!this.configuration.features.has("Object.fromJson")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const variables = {
@@ -2,7 +2,7 @@ import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { code, joinCode } from "../ts-poet-wrapper.js";
4
4
  export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
5
- if (!this.configuration.features.has("rdf")) {
5
+ if (!this.configuration.features.has("Object.fromRdf")) {
6
6
  return Maybe.empty();
7
7
  }
8
8
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_fromRdfResourceValuesFunctionDeclaration() {
4
- if (!this.configuration.features.has("rdf")) {
4
+ if (!this.configuration.features.has("Object.fromRdf")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  return Maybe.of(code `\
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_fromRdfTypeVariableStatement() {
4
- if (!this.configuration.features.has("rdf")) {
4
+ if (!this.configuration.features.has("Object.fromRdf")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  return this.fromRdfType.map((fromRdfType) => code `\
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_graphqlTypeVariableStatement() {
4
- if (!this.configuration.features.has("graphql")) {
4
+ if (!this.configuration.features.has("GraphQL")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  if (this.synthetic) {
@@ -1,7 +1,7 @@
1
1
  import { code, joinCode } from "../ts-poet-wrapper.js";
2
2
  const hasherVariable = code `hasher`;
3
3
  export function NamedObjectType_hashFunctionDeclarations() {
4
- if (!this.configuration.features.has("hash")) {
4
+ if (!this.configuration.features.has("Object.hash")) {
5
5
  return [];
6
6
  }
7
7
  const hashOwnShaclPropertiesStatements = this.properties.flatMap((property) => property.kind === "ShaclProperty"
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import type { NamedObjectType } from "../NamedObjectType.js";
2
3
  import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function NamedObjectType_isTypeFunctionDeclaration(this: NamedObjectType): Code;
4
+ export declare function NamedObjectType_isTypeFunctionDeclaration(this: NamedObjectType): Maybe<Code>;
4
5
  //# sourceMappingURL=NamedObjectType_isTypeFunctionDeclaration.d.ts.map
@@ -1,6 +1,10 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { code } from "../ts-poet-wrapper.js";
2
3
  export function NamedObjectType_isTypeFunctionDeclaration() {
3
- return code `\
4
+ if (!this.configuration.features.has("Object.type")) {
5
+ return Maybe.empty();
6
+ }
7
+ return Maybe.of(code `\
4
8
  export function is${this.name}(object: ${this.configuration.syntheticNamePrefix}Object): object is ${this.name} {
5
9
  switch (object.${this._discriminantProperty.name}) {
6
10
  ${this._discriminantProperty.type.descendantValues
@@ -8,6 +12,6 @@ export function is${this.name}(object: ${this.configuration.syntheticNamePrefix}
8
12
  .map((value) => `case "${value}":`)
9
13
  .join("\n")} return true; default: return false;
10
14
  }
11
- }`;
15
+ }`);
12
16
  }
13
17
  //# sourceMappingURL=NamedObjectType_isTypeFunctionDeclaration.js.map
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_jsonParseFunctionDeclaration() {
4
- if (!this.configuration.features.has("json")) {
4
+ if (!this.configuration.features.has("Object.JSON.parse")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  return Maybe.of(code `\
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_jsonSchemaFunctionDeclaration() {
4
- if (!this.configuration.features.has("json")) {
4
+ if (!this.configuration.features.has("Object.JSON.schema")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  let properties = [];
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_jsonTypeAliasDeclaration() {
4
- if (!this.configuration.features.has("json")) {
4
+ if (!this.configuration.features.has("Object.JSON.type")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const members = [];
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
3
3
  export function NamedObjectType_jsonUiSchemaFunctionDeclaration() {
4
- if (!this.configuration.features.has("json")) {
4
+ if (!this.configuration.features.has("Object.JSON.uiSchema")) {
5
5
  return Maybe.empty();
6
6
  }
7
7
  const variables = { scopePrefix: code `scopePrefix` };
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import type { NamedObjectType } from "../NamedObjectType.js";
2
3
  import { type Code } from "../ts-poet-wrapper.js";
3
- export declare function NamedObjectType_schemaVariableStatement(this: NamedObjectType): Code;
4
+ export declare function NamedObjectType_schemaVariableStatement(this: NamedObjectType): Maybe<Code>;
4
5
  //# sourceMappingURL=NamedObjectType_schemaVariableStatement.d.ts.map
@@ -1,8 +1,12 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { code, joinCode } from "../ts-poet-wrapper.js";
2
3
  export function NamedObjectType_schemaVariableStatement() {
3
- return code `\
4
+ if (!this.configuration.features.has("Object.schema")) {
5
+ return Maybe.empty();
6
+ }
7
+ return Maybe.of(code `\
4
8
  export const schema = { properties: { ${joinCode(this.parentObjectTypes
5
9
  .map((parentObjectType) => code `...${parentObjectType.name}.schema.properties`)
6
- .concat(this.properties.map((property) => code `${property.name}: ${property.schema}`)), { on: ", " })} } } as const;`;
10
+ .concat(this.properties.map((property) => code `${property.name}: ${property.schema}`)), { on: ", " })} } } as const;`);
7
11
  }
8
12
  //# sourceMappingURL=NamedObjectType_schemaVariableStatement.js.map