@acmekit/index 2.13.1

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 (151) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +13 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/loaders/index.d.ts +4 -0
  7. package/dist/loaders/index.d.ts.map +1 -0
  8. package/dist/loaders/index.js +27 -0
  9. package/dist/loaders/index.js.map +1 -0
  10. package/dist/migrations/Migration20231019174230.d.ts +5 -0
  11. package/dist/migrations/Migration20231019174230.d.ts.map +1 -0
  12. package/dist/migrations/Migration20231019174230.js +12 -0
  13. package/dist/migrations/Migration20231019174230.js.map +1 -0
  14. package/dist/migrations/Migration20241209173313.d.ts +6 -0
  15. package/dist/migrations/Migration20241209173313.d.ts.map +1 -0
  16. package/dist/migrations/Migration20241209173313.js +36 -0
  17. package/dist/migrations/Migration20241209173313.js.map +1 -0
  18. package/dist/migrations/Migration20250122154720.d.ts +6 -0
  19. package/dist/migrations/Migration20250122154720.d.ts.map +1 -0
  20. package/dist/migrations/Migration20250122154720.js +16 -0
  21. package/dist/migrations/Migration20250122154720.js.map +1 -0
  22. package/dist/migrations/Migration20250127105159.d.ts +6 -0
  23. package/dist/migrations/Migration20250127105159.d.ts.map +1 -0
  24. package/dist/migrations/Migration20250127105159.js +16 -0
  25. package/dist/migrations/Migration20250127105159.js.map +1 -0
  26. package/dist/migrations/Migration20250127144442.d.ts +6 -0
  27. package/dist/migrations/Migration20250127144442.d.ts.map +1 -0
  28. package/dist/migrations/Migration20250127144442.js +16 -0
  29. package/dist/migrations/Migration20250127144442.js.map +1 -0
  30. package/dist/migrations/Migration20250128132404.d.ts +6 -0
  31. package/dist/migrations/Migration20250128132404.d.ts.map +1 -0
  32. package/dist/migrations/Migration20250128132404.js +16 -0
  33. package/dist/migrations/Migration20250128132404.js.map +1 -0
  34. package/dist/migrations/Migration20250218132404.d.ts +6 -0
  35. package/dist/migrations/Migration20250218132404.d.ts.map +1 -0
  36. package/dist/migrations/Migration20250218132404.js +48 -0
  37. package/dist/migrations/Migration20250218132404.js.map +1 -0
  38. package/dist/migrations/Migration20250515161913.d.ts +6 -0
  39. package/dist/migrations/Migration20250515161913.d.ts.map +1 -0
  40. package/dist/migrations/Migration20250515161913.js +62 -0
  41. package/dist/migrations/Migration20250515161913.js.map +1 -0
  42. package/dist/models/index-data.d.ts +8 -0
  43. package/dist/models/index-data.d.ts.map +1 -0
  44. package/dist/models/index-data.js +12 -0
  45. package/dist/models/index-data.js.map +1 -0
  46. package/dist/models/index-metadata.d.ts +10 -0
  47. package/dist/models/index-metadata.d.ts.map +1 -0
  48. package/dist/models/index-metadata.js +23 -0
  49. package/dist/models/index-metadata.js.map +1 -0
  50. package/dist/models/index-relation.d.ts +11 -0
  51. package/dist/models/index-relation.d.ts.map +1 -0
  52. package/dist/models/index-relation.js +14 -0
  53. package/dist/models/index-relation.js.map +1 -0
  54. package/dist/models/index-sync.d.ts +7 -0
  55. package/dist/models/index-sync.d.ts.map +1 -0
  56. package/dist/models/index-sync.js +18 -0
  57. package/dist/models/index-sync.js.map +1 -0
  58. package/dist/models/index.d.ts +5 -0
  59. package/dist/models/index.d.ts.map +1 -0
  60. package/dist/models/index.js +15 -0
  61. package/dist/models/index.js.map +1 -0
  62. package/dist/services/data-synchronizer.d.ts +35 -0
  63. package/dist/services/data-synchronizer.d.ts.map +1 -0
  64. package/dist/services/data-synchronizer.js +238 -0
  65. package/dist/services/data-synchronizer.js.map +1 -0
  66. package/dist/services/index-data.d.ts +8 -0
  67. package/dist/services/index-data.d.ts.map +1 -0
  68. package/dist/services/index-data.js +9 -0
  69. package/dist/services/index-data.js.map +1 -0
  70. package/dist/services/index-metadata.d.ts +8 -0
  71. package/dist/services/index-metadata.d.ts.map +1 -0
  72. package/dist/services/index-metadata.js +9 -0
  73. package/dist/services/index-metadata.js.map +1 -0
  74. package/dist/services/index-module-service.d.ts +75 -0
  75. package/dist/services/index-module-service.d.ts.map +1 -0
  76. package/dist/services/index-module-service.js +340 -0
  77. package/dist/services/index-module-service.js.map +1 -0
  78. package/dist/services/index-relation.d.ts +8 -0
  79. package/dist/services/index-relation.d.ts.map +1 -0
  80. package/dist/services/index-relation.js +9 -0
  81. package/dist/services/index-relation.js.map +1 -0
  82. package/dist/services/index-sync.d.ts +8 -0
  83. package/dist/services/index-sync.d.ts.map +1 -0
  84. package/dist/services/index-sync.js +9 -0
  85. package/dist/services/index-sync.js.map +1 -0
  86. package/dist/services/index.d.ts +2 -0
  87. package/dist/services/index.d.ts.map +1 -0
  88. package/dist/services/index.js +9 -0
  89. package/dist/services/index.js.map +1 -0
  90. package/dist/services/postgres-provider.d.ts +132 -0
  91. package/dist/services/postgres-provider.d.ts.map +1 -0
  92. package/dist/services/postgres-provider.js +516 -0
  93. package/dist/services/postgres-provider.js.map +1 -0
  94. package/dist/tsconfig.tsbuildinfo +1 -0
  95. package/dist/types/index.d.ts +21 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/types/index.js +12 -0
  98. package/dist/types/index.js.map +1 -0
  99. package/dist/utils/base-graphql-schema.d.ts +2 -0
  100. package/dist/utils/base-graphql-schema.d.ts.map +1 -0
  101. package/dist/utils/base-graphql-schema.js +10 -0
  102. package/dist/utils/base-graphql-schema.js.map +1 -0
  103. package/dist/utils/build-config.d.ts +28 -0
  104. package/dist/utils/build-config.d.ts.map +1 -0
  105. package/dist/utils/build-config.js +840 -0
  106. package/dist/utils/build-config.js.map +1 -0
  107. package/dist/utils/create-partitions.d.ts +4 -0
  108. package/dist/utils/create-partitions.d.ts.map +1 -0
  109. package/dist/utils/create-partitions.js +80 -0
  110. package/dist/utils/create-partitions.js.map +1 -0
  111. package/dist/utils/default-schema.d.ts +2 -0
  112. package/dist/utils/default-schema.d.ts.map +1 -0
  113. package/dist/utils/default-schema.js +41 -0
  114. package/dist/utils/default-schema.js.map +1 -0
  115. package/dist/utils/flatten-object-keys.d.ts +23 -0
  116. package/dist/utils/flatten-object-keys.d.ts.map +1 -0
  117. package/dist/utils/flatten-object-keys.js +54 -0
  118. package/dist/utils/flatten-object-keys.js.map +1 -0
  119. package/dist/utils/gql-to-types.d.ts +3 -0
  120. package/dist/utils/gql-to-types.d.ts.map +1 -0
  121. package/dist/utils/gql-to-types.js +98 -0
  122. package/dist/utils/gql-to-types.js.map +1 -0
  123. package/dist/utils/index-metadata-status.d.ts +7 -0
  124. package/dist/utils/index-metadata-status.d.ts.map +1 -0
  125. package/dist/utils/index-metadata-status.js +11 -0
  126. package/dist/utils/index-metadata-status.js.map +1 -0
  127. package/dist/utils/index.d.ts +10 -0
  128. package/dist/utils/index.d.ts.map +1 -0
  129. package/dist/utils/index.js +26 -0
  130. package/dist/utils/index.js.map +1 -0
  131. package/dist/utils/normalize-fields-selection.d.ts +2 -0
  132. package/dist/utils/normalize-fields-selection.d.ts.map +1 -0
  133. package/dist/utils/normalize-fields-selection.js +10 -0
  134. package/dist/utils/normalize-fields-selection.js.map +1 -0
  135. package/dist/utils/normalze-table-name.d.ts +3 -0
  136. package/dist/utils/normalze-table-name.d.ts.map +1 -0
  137. package/dist/utils/normalze-table-name.js +13 -0
  138. package/dist/utils/normalze-table-name.js.map +1 -0
  139. package/dist/utils/query-builder.d.ts +61 -0
  140. package/dist/utils/query-builder.d.ts.map +1 -0
  141. package/dist/utils/query-builder.js +791 -0
  142. package/dist/utils/query-builder.js.map +1 -0
  143. package/dist/utils/sync/configuration.d.ts +17 -0
  144. package/dist/utils/sync/configuration.d.ts.map +1 -0
  145. package/dist/utils/sync/configuration.js +114 -0
  146. package/dist/utils/sync/configuration.js.map +1 -0
  147. package/dist/utils/sync/orchestrator.d.ts +33 -0
  148. package/dist/utils/sync/orchestrator.d.ts.map +1 -0
  149. package/dist/utils/sync/orchestrator.js +195 -0
  150. package/dist/utils/sync/orchestrator.js.map +1 -0
  151. package/package.json +45 -0
@@ -0,0 +1,840 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomDirectives = void 0;
4
+ exports.makeSchemaExecutable = makeSchemaExecutable;
5
+ exports.buildSchemaObjectRepresentation = buildSchemaObjectRepresentation;
6
+ const modules_sdk_1 = require("@acmekit/framework/modules-sdk");
7
+ const utils_1 = require("@acmekit/framework/utils");
8
+ const _types_1 = require("../types");
9
+ const base_graphql_schema_1 = require("./base-graphql-schema");
10
+ exports.CustomDirectives = {
11
+ Listeners: {
12
+ configurationPropertyName: "listeners",
13
+ isRequired: true,
14
+ name: "Listeners",
15
+ directive: "@Listeners",
16
+ definition: "directive @Listeners (values: [String!]) on OBJECT",
17
+ },
18
+ };
19
+ function makeSchemaExecutable(inputSchema) {
20
+ const { schema: cleanedSchema } = utils_1.GraphQLUtils.cleanGraphQLSchema(inputSchema);
21
+ if (!cleanedSchema) {
22
+ return;
23
+ }
24
+ return utils_1.GraphQLUtils.makeExecutableSchema({
25
+ typeDefs: cleanedSchema,
26
+ });
27
+ }
28
+ /**
29
+ * Retrieve the property name of the source entity that corresponds to the target entity
30
+ * @param sourceEntityName - The name of the source entity
31
+ * @param targetEntityName - The name of the target entity
32
+ * @param entitiesMap - The map of entities configured in the module
33
+ * @param servicesEntityMap - The map of entities configured in the services
34
+ * @param node - The node of the source entity
35
+ * @returns The property name and if it is an array of the source entity property that corresponds to the target entity
36
+ */
37
+ function retrieveEntityPropByType({ sourceEntityName, targetEntityName, entitiesMap, servicesEntityMap, node, }) {
38
+ if (!node && !entitiesMap && !servicesEntityMap) {
39
+ throw new Error("Index Module error, unable to retrieve the entity property by type. Please provide either the entitiesMap and servicesEntityMap or the node.");
40
+ }
41
+ const retrieveFieldNode = (node) => {
42
+ const astNode = node?.astNode;
43
+ const fields = astNode?.fields ?? [];
44
+ for (const field of fields) {
45
+ let type = field.type;
46
+ let isArray = false;
47
+ while (type.type) {
48
+ if (type.kind === utils_1.GraphQLUtils.Kind.LIST_TYPE) {
49
+ isArray = true;
50
+ }
51
+ type = type.type;
52
+ }
53
+ if (type.name?.value === targetEntityName) {
54
+ return { name: field.name?.value, isArray };
55
+ }
56
+ }
57
+ return;
58
+ };
59
+ let prop;
60
+ if (node) {
61
+ prop = retrieveFieldNode(node);
62
+ }
63
+ if (entitiesMap && !prop) {
64
+ prop = retrieveFieldNode(entitiesMap[sourceEntityName]);
65
+ }
66
+ if (servicesEntityMap && !prop) {
67
+ prop = retrieveFieldNode(servicesEntityMap[sourceEntityName]);
68
+ }
69
+ return (prop && {
70
+ name: prop?.name,
71
+ isArray: prop?.isArray,
72
+ });
73
+ }
74
+ function extractNameFromAlias(alias) {
75
+ const alias_ = Array.isArray(alias) ? alias[0] : alias;
76
+ const names = Array.isArray(alias_?.name) ? alias_?.name : [alias_?.name];
77
+ return names[0];
78
+ }
79
+ function retrieveAliasForEntity(entityName, aliases) {
80
+ aliases = aliases ? (Array.isArray(aliases) ? aliases : [aliases]) : [];
81
+ for (const alias of aliases) {
82
+ const names = Array.isArray(alias.name) ? alias.name : [alias.name];
83
+ if (alias.entity === entityName) {
84
+ return names[0];
85
+ }
86
+ for (const name of names) {
87
+ if (name.toLowerCase() === entityName.toLowerCase()) {
88
+ return name;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ function retrieveModuleAndAlias(entityName, moduleJoinerConfigs) {
94
+ let relatedModule;
95
+ let alias;
96
+ for (const moduleJoinerConfig of moduleJoinerConfigs) {
97
+ const moduleSchema = moduleJoinerConfig.schema;
98
+ const moduleAliases = moduleJoinerConfig.alias;
99
+ /**
100
+ * If the entity exist in the module schema, then the current module is the
101
+ * one we are looking for.
102
+ *
103
+ * If the module does not have any schema, then we need to base the search
104
+ * on the provided aliases. in any case, we try to get both
105
+ */
106
+ if (moduleSchema) {
107
+ const executableSchema = makeSchemaExecutable(moduleSchema);
108
+ const entitiesMap = executableSchema?.getTypeMap();
109
+ if (entitiesMap?.[entityName]) {
110
+ relatedModule = moduleJoinerConfig;
111
+ }
112
+ }
113
+ if (relatedModule && moduleAliases) {
114
+ alias = retrieveAliasForEntity(entityName, moduleJoinerConfig.alias);
115
+ }
116
+ if (relatedModule) {
117
+ break;
118
+ }
119
+ }
120
+ if (!relatedModule) {
121
+ return { relatedModule: null, alias: null };
122
+ }
123
+ if (!alias) {
124
+ throw new Error(`Index Module error, the module ${relatedModule?.serviceName} has a schema but does not have any alias for the entity ${entityName}. Please add an alias to the module configuration and the entity it correspond to in the args under the entity property.`);
125
+ }
126
+ return { relatedModule, alias };
127
+ }
128
+ // TODO: rename util
129
+ function retrieveLinkModuleAndAlias({ primaryEntity, primaryModuleConfig, foreignEntity, foreignModuleConfig, moduleJoinerConfigs, servicesEntityMap, entitiesMap, }) {
130
+ const linkModulesMetadata = [];
131
+ for (const linkModuleJoinerConfig of moduleJoinerConfigs.filter((config) => config.isLink && !config.isReadOnlyLink)) {
132
+ const linkPrimary = linkModuleJoinerConfig.relationships[0];
133
+ const linkForeign = linkModuleJoinerConfig.relationships[1];
134
+ const isDirectMatch = linkPrimary.serviceName === primaryModuleConfig.serviceName &&
135
+ linkForeign.serviceName === foreignModuleConfig.serviceName &&
136
+ linkPrimary.entity === primaryEntity;
137
+ const isInverseMatch = linkPrimary.serviceName === foreignModuleConfig.serviceName &&
138
+ linkForeign.serviceName === primaryModuleConfig.serviceName &&
139
+ linkPrimary.entity === foreignEntity;
140
+ if (!(isDirectMatch || isInverseMatch)) {
141
+ continue;
142
+ }
143
+ const primaryEntityLinkableKey = isDirectMatch
144
+ ? linkPrimary.foreignKey
145
+ : linkForeign.foreignKey;
146
+ const isTheForeignKeyEntityEqualPrimaryEntity = primaryModuleConfig.linkableKeys?.[primaryEntityLinkableKey] ===
147
+ primaryEntity;
148
+ const foreignEntityLinkableKey = isDirectMatch
149
+ ? linkForeign.foreignKey
150
+ : linkPrimary.foreignKey;
151
+ const isTheForeignKeyEntityEqualForeignEntity = foreignModuleConfig.linkableKeys?.[foreignEntityLinkableKey] ===
152
+ foreignEntity;
153
+ const relationshipsTypes = linkModuleJoinerConfig.relationships
154
+ ?.map((relationship) => relationship.entity)
155
+ .filter(Boolean) ?? [];
156
+ const filteredEntitiesMap = {
157
+ [linkModuleJoinerConfig.alias?.[0].entity]: entitiesMap[linkModuleJoinerConfig.alias?.[0].entity],
158
+ };
159
+ const filteredServicesEntityMap = {
160
+ [linkModuleJoinerConfig.alias?.[0].entity]: servicesEntityMap[linkModuleJoinerConfig.alias?.[0].entity],
161
+ };
162
+ for (const relationshipType of relationshipsTypes) {
163
+ filteredEntitiesMap[relationshipType] = entitiesMap[relationshipType];
164
+ filteredServicesEntityMap[relationshipType] =
165
+ servicesEntityMap[relationshipType];
166
+ }
167
+ const linkName = linkModuleJoinerConfig.extends?.find((extend) => {
168
+ return ((extend.serviceName === primaryModuleConfig.serviceName ||
169
+ extend.relationship.serviceName ===
170
+ foreignModuleConfig.serviceName) &&
171
+ (extend.relationship.primaryKey === primaryEntityLinkableKey ||
172
+ extend.relationship.primaryKey === foreignEntityLinkableKey));
173
+ })?.relationship.serviceName;
174
+ if (!linkName) {
175
+ throw new Error(`Index Module error, unable to retrieve the link module name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the extend relationship service name is set correctly`);
176
+ }
177
+ if (!linkModuleJoinerConfig.alias?.[0]?.entity) {
178
+ throw new Error(`Index Module error, unable to retrieve the link module entity name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the link module alias has an entity property in the args.`);
179
+ }
180
+ if (isTheForeignKeyEntityEqualPrimaryEntity &&
181
+ isTheForeignKeyEntityEqualForeignEntity) {
182
+ /**
183
+ * The link will become the parent of the foreign entity, that is why the alias must be the one that correspond to the extended foreign module
184
+ */
185
+ const inverseSideProp = retrieveEntityPropByType({
186
+ targetEntityName: primaryEntity,
187
+ sourceEntityName: linkModuleJoinerConfig.alias[0].entity,
188
+ servicesEntityMap: filteredServicesEntityMap,
189
+ entitiesMap: filteredEntitiesMap,
190
+ });
191
+ linkModulesMetadata.push({
192
+ entityName: linkModuleJoinerConfig.alias[0].entity,
193
+ alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
194
+ linkModuleConfig: linkModuleJoinerConfig,
195
+ intermediateEntityNames: [],
196
+ isInverse: isInverseMatch,
197
+ isList: inverseSideProp?.isArray,
198
+ inverseSideProp: inverseSideProp?.name,
199
+ });
200
+ }
201
+ else {
202
+ const intermediateEntityName = foreignModuleConfig.linkableKeys[foreignEntityLinkableKey];
203
+ const moduleSchema = isDirectMatch
204
+ ? foreignModuleConfig.schema
205
+ : primaryModuleConfig.schema;
206
+ if (!moduleSchema) {
207
+ throw new Error(`Index Module error, unable to retrieve the intermediate entity name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the foreign module ${foreignModuleConfig.serviceName} has a schema.`);
208
+ }
209
+ const entitiesMap = servicesEntityMap;
210
+ let intermediateEntities = [];
211
+ let foundCount = 0;
212
+ let foundName = null;
213
+ const isForeignEntityChildOfIntermediateEntity = (entityName, visited = new Set()) => {
214
+ if (visited.has(entityName)) {
215
+ return false;
216
+ }
217
+ visited.add(entityName);
218
+ for (const entityType of Object.values(entitiesMap)) {
219
+ const inverseSideProp = retrieveEntityPropByType({
220
+ node: entityType,
221
+ targetEntityName: entityName,
222
+ });
223
+ if (entityType.astNode?.kind === "ObjectTypeDefinition" &&
224
+ inverseSideProp) {
225
+ if (entityType.name === intermediateEntityName) {
226
+ foundName = entityType.name;
227
+ ++foundCount;
228
+ return true;
229
+ }
230
+ else {
231
+ const inverseSideProp = isForeignEntityChildOfIntermediateEntity(entityType.name, visited);
232
+ if (inverseSideProp) {
233
+ intermediateEntities.push(entityType.name);
234
+ return true;
235
+ }
236
+ }
237
+ }
238
+ }
239
+ return false;
240
+ };
241
+ isForeignEntityChildOfIntermediateEntity(isDirectMatch ? foreignEntity : primaryEntity);
242
+ if (foundCount !== 1) {
243
+ throw new Error(`Index Module error, unable to retrieve the intermediate entities for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName} between ${isDirectMatch ? foreignEntity : primaryEntity} and ${intermediateEntityName}. Multiple paths or no path found. Please check your schema in ${foreignModuleConfig.serviceName}`);
244
+ }
245
+ intermediateEntities.push(foundName);
246
+ /**
247
+ * The link will become the parent of the foreign entity, that is why the alias must be the one that correspond to the extended foreign module
248
+ */
249
+ const directInverseSideProp = retrieveEntityPropByType({
250
+ targetEntityName: isDirectMatch
251
+ ? primaryEntity
252
+ : linkModuleJoinerConfig.alias[0].entity,
253
+ sourceEntityName: isDirectMatch
254
+ ? linkModuleJoinerConfig.alias[0].entity
255
+ : primaryEntity,
256
+ servicesEntityMap: filteredServicesEntityMap,
257
+ entitiesMap: filteredEntitiesMap,
258
+ });
259
+ linkModulesMetadata.push({
260
+ entityName: linkModuleJoinerConfig.alias[0].entity,
261
+ alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
262
+ linkModuleConfig: linkModuleJoinerConfig,
263
+ intermediateEntityNames: intermediateEntities,
264
+ inverseSideProp: directInverseSideProp?.name,
265
+ isList: directInverseSideProp?.isArray,
266
+ isInverse: isInverseMatch,
267
+ });
268
+ }
269
+ }
270
+ if (!linkModulesMetadata.length) {
271
+ console.warn(`Index Module warning, unable to retrieve the link module that correspond to the entities ${primaryEntity} - ${foreignEntity}.`);
272
+ }
273
+ return linkModulesMetadata;
274
+ }
275
+ function getObjectRepresentationRef(entityName, { objectRepresentationRef }) {
276
+ return (objectRepresentationRef[entityName] ??= {
277
+ entity: entityName,
278
+ parents: [],
279
+ alias: "",
280
+ listeners: [],
281
+ moduleConfig: null,
282
+ fields: [],
283
+ });
284
+ }
285
+ function setCustomDirectives(currentObjectRepresentationRef, directives) {
286
+ for (const customDirectiveConfiguration of Object.values(exports.CustomDirectives)) {
287
+ const directive = directives.find((typeDirective) => typeDirective.name.value === customDirectiveConfiguration.name);
288
+ if (!directive) {
289
+ return;
290
+ }
291
+ // Only support array directive value for now
292
+ currentObjectRepresentationRef[customDirectiveConfiguration.configurationPropertyName] = (directive.arguments[0].value?.values ?? []).map((v) => v.value);
293
+ }
294
+ }
295
+ function processEntity(entityName, { entitiesMap, servicesEntityMap, moduleJoinerConfigs, objectRepresentationRef, }) {
296
+ /**
297
+ * Get the reference to the object representation for the current entity.
298
+ */
299
+ const currentObjectRepresentationRef = getObjectRepresentationRef(entityName, {
300
+ objectRepresentationRef,
301
+ });
302
+ /**
303
+ * Retrieve and set the custom directives for the current entity.
304
+ */
305
+ setCustomDirectives(currentObjectRepresentationRef, entitiesMap[entityName].astNode?.directives ?? []);
306
+ // Merge and deduplicate the fields
307
+ currentObjectRepresentationRef.fields ??= [];
308
+ currentObjectRepresentationRef.fields =
309
+ currentObjectRepresentationRef.fields.concat(...(utils_1.GraphQLUtils.gqlGetFieldsAndRelations(entitiesMap, entityName) ?? []));
310
+ currentObjectRepresentationRef.fields = Array.from(new Set(currentObjectRepresentationRef.fields));
311
+ /**
312
+ * Retrieve the module and alias for the current entity.
313
+ */
314
+ const { relatedModule: currentEntityModule, alias } = retrieveModuleAndAlias(entityName, moduleJoinerConfigs);
315
+ if (!currentEntityModule &&
316
+ currentObjectRepresentationRef.listeners.length > 0) {
317
+ const example = JSON.stringify({
318
+ alias: [
319
+ {
320
+ name: "entity-alias",
321
+ entity: entityName,
322
+ },
323
+ ],
324
+ });
325
+ throw new Error(`Index Module error, unable to retrieve the module that corresponds to the entity ${entityName}.\nPlease add the entity to the module schema or add an alias to the joiner config like the example below:\n${example}`);
326
+ }
327
+ if (currentEntityModule) {
328
+ objectRepresentationRef._serviceNameModuleConfigMap[currentEntityModule.serviceName] = currentEntityModule;
329
+ currentObjectRepresentationRef.moduleConfig = currentEntityModule;
330
+ currentObjectRepresentationRef.alias = alias;
331
+ }
332
+ /**
333
+ * Retrieve the parent entities for the current entity.
334
+ */
335
+ const schemaParentEntity = Object.values(entitiesMap).filter((value) => {
336
+ return (value.astNode &&
337
+ value.astNode.fields?.some((field) => {
338
+ let currentType = field.type;
339
+ while (currentType.type) {
340
+ currentType = currentType.type;
341
+ }
342
+ return currentType.name?.value === entityName;
343
+ }));
344
+ });
345
+ if (!schemaParentEntity.length) {
346
+ return;
347
+ }
348
+ /**
349
+ * If the current entity has parent entities, then we need to process them.
350
+ */
351
+ const parentEntityNames = schemaParentEntity.map((parent) => {
352
+ return parent.name;
353
+ });
354
+ for (const parent of parentEntityNames) {
355
+ /**
356
+ * Retrieve the parent entity field in the schema
357
+ */
358
+ const entityFieldInParent = retrieveEntityPropByType({
359
+ sourceEntityName: parent,
360
+ targetEntityName: entityName,
361
+ entitiesMap,
362
+ servicesEntityMap,
363
+ });
364
+ const entityTargetPropertyNameInParent = entityFieldInParent.name;
365
+ const entityTargetPropertyIsListInParent = entityFieldInParent.isArray;
366
+ /**
367
+ * Retrieve the parent entity object representation reference.
368
+ */
369
+ if (!objectRepresentationRef[parent]) {
370
+ processEntity(parent, {
371
+ entitiesMap,
372
+ servicesEntityMap,
373
+ moduleJoinerConfigs,
374
+ objectRepresentationRef,
375
+ });
376
+ }
377
+ const parentObjectRepresentationRef = getObjectRepresentationRef(parent, {
378
+ objectRepresentationRef,
379
+ });
380
+ const parentModuleConfig = parentObjectRepresentationRef.moduleConfig;
381
+ // If the entity is not part of any module, just set the parent and continue
382
+ if (!currentObjectRepresentationRef.moduleConfig) {
383
+ const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity === parentObjectRepresentationRef.entity &&
384
+ existingParent.targetProp === entityTargetPropertyNameInParent);
385
+ const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
386
+ sourceEntityName: entityName,
387
+ targetEntityName: parent,
388
+ entitiesMap,
389
+ servicesEntityMap,
390
+ });
391
+ if (!parentAlreadyExists) {
392
+ currentObjectRepresentationRef.parents.push({
393
+ ref: parentObjectRepresentationRef,
394
+ targetProp: entityTargetPropertyNameInParent,
395
+ inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
396
+ isList: entityTargetPropertyIsListInParent,
397
+ });
398
+ }
399
+ else {
400
+ return;
401
+ }
402
+ continue;
403
+ }
404
+ /**
405
+ * If the parent entity and the current entity are part of the same service then configure the parent and
406
+ * add the parent id as a field to the current entity.
407
+ */
408
+ if (currentObjectRepresentationRef.moduleConfig.serviceName ===
409
+ parentModuleConfig.serviceName ||
410
+ parentModuleConfig.isLink ||
411
+ currentObjectRepresentationRef.moduleConfig.isLink) {
412
+ const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
413
+ sourceEntityName: entityName,
414
+ targetEntityName: parent,
415
+ entitiesMap,
416
+ servicesEntityMap,
417
+ });
418
+ const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity === parentObjectRepresentationRef.entity &&
419
+ existingParent.targetProp === entityTargetPropertyNameInParent);
420
+ if (!parentAlreadyExists) {
421
+ currentObjectRepresentationRef.parents.push({
422
+ ref: parentObjectRepresentationRef,
423
+ targetProp: entityTargetPropertyNameInParent,
424
+ inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
425
+ isList: entityTargetPropertyIsListInParent,
426
+ });
427
+ }
428
+ const propertyToAdd = parentPropertyNameWithinCurrentEntity?.name + ".id";
429
+ if (parentPropertyNameWithinCurrentEntity &&
430
+ !currentObjectRepresentationRef.fields.includes(propertyToAdd)) {
431
+ currentObjectRepresentationRef.fields.push(propertyToAdd);
432
+ }
433
+ if (parentAlreadyExists) {
434
+ return;
435
+ }
436
+ }
437
+ else {
438
+ /**
439
+ * If the parent entity and the current entity are not part of the same service then we need to
440
+ * find the link module that join them.
441
+ */
442
+ const linkModuleMetadatas = retrieveLinkModuleAndAlias({
443
+ primaryEntity: parentObjectRepresentationRef.entity,
444
+ primaryModuleConfig: parentModuleConfig,
445
+ foreignEntity: currentObjectRepresentationRef.entity,
446
+ foreignModuleConfig: currentEntityModule,
447
+ moduleJoinerConfigs,
448
+ servicesEntityMap,
449
+ entitiesMap,
450
+ });
451
+ for (const linkModuleMetadata of linkModuleMetadatas) {
452
+ const linkObjectRepresentationRef = getObjectRepresentationRef(linkModuleMetadata.entityName, { objectRepresentationRef });
453
+ objectRepresentationRef._serviceNameModuleConfigMap[linkModuleMetadata.linkModuleConfig.serviceName ||
454
+ linkModuleMetadata.entityName] = linkModuleMetadata.linkModuleConfig;
455
+ /**
456
+ * Add the schema parent entity as a parent to the link module and configure it.
457
+ */
458
+ linkObjectRepresentationRef.parents ??= [];
459
+ if (!linkObjectRepresentationRef.parents.some((parent) => parent.ref.entity === parentObjectRepresentationRef.entity)) {
460
+ linkObjectRepresentationRef.parents.push({
461
+ ref: parentObjectRepresentationRef,
462
+ targetProp: linkModuleMetadata.alias,
463
+ inverseSideProp: linkModuleMetadata.inverseSideProp ?? "",
464
+ isList: linkModuleMetadata.isList,
465
+ isInverse: linkModuleMetadata.isInverse,
466
+ });
467
+ }
468
+ linkObjectRepresentationRef.alias = linkModuleMetadata.alias;
469
+ linkObjectRepresentationRef.listeners = [
470
+ `${linkModuleMetadata.entityName}.${utils_1.CommonEvents.ATTACHED}`,
471
+ `${linkModuleMetadata.entityName}.${utils_1.CommonEvents.DETACHED}`,
472
+ ];
473
+ linkObjectRepresentationRef.moduleConfig =
474
+ linkModuleMetadata.linkModuleConfig;
475
+ linkObjectRepresentationRef.fields = [
476
+ "id",
477
+ ...linkModuleMetadata.linkModuleConfig
478
+ .relationships.map((relationship) => [
479
+ parentModuleConfig.serviceName,
480
+ currentEntityModule.serviceName,
481
+ ].includes(relationship.serviceName) && relationship.foreignKey)
482
+ .filter((v) => Boolean(v)),
483
+ ];
484
+ /**
485
+ * If the current entity is not the entity that is used to join the link module and the parent entity
486
+ * then we need to add the new entity that join them and then add the link as its parent
487
+ * before setting the new entity as the true parent of the current entity.
488
+ */
489
+ for (let i = linkModuleMetadata.intermediateEntityNames.length - 1; i >= 0; --i) {
490
+ const intermediateEntityName = linkModuleMetadata.intermediateEntityNames[i];
491
+ const isLastIntermediateEntity = i === linkModuleMetadata.intermediateEntityNames.length - 1;
492
+ const parentIntermediateEntityRef = isLastIntermediateEntity
493
+ ? linkObjectRepresentationRef
494
+ : objectRepresentationRef[linkModuleMetadata.intermediateEntityNames[i + 1]];
495
+ const { relatedModule: intermediateEntityModule, alias: intermediateEntityAlias, } = retrieveModuleAndAlias(intermediateEntityName, moduleJoinerConfigs);
496
+ const intermediateEntityObjectRepresentationRef = getObjectRepresentationRef(intermediateEntityName, {
497
+ objectRepresentationRef,
498
+ });
499
+ objectRepresentationRef._serviceNameModuleConfigMap[intermediateEntityModule.serviceName] = intermediateEntityModule;
500
+ const parentPropertyNameWithinIntermediateEntity = retrieveEntityPropByType({
501
+ sourceEntityName: intermediateEntityName,
502
+ targetEntityName: parentIntermediateEntityRef.entity,
503
+ entitiesMap: entitiesMap,
504
+ servicesEntityMap: servicesEntityMap,
505
+ });
506
+ const intermediateEntityTargetPropertyIsListInParent = retrieveEntityPropByType({
507
+ sourceEntityName: parentIntermediateEntityRef.entity,
508
+ targetEntityName: intermediateEntityName,
509
+ entitiesMap: entitiesMap,
510
+ servicesEntityMap: servicesEntityMap,
511
+ })?.isArray;
512
+ const parentRef = {
513
+ ref: parentIntermediateEntityRef,
514
+ targetProp: intermediateEntityAlias,
515
+ inverseSideProp: parentPropertyNameWithinIntermediateEntity?.name,
516
+ isList: intermediateEntityTargetPropertyIsListInParent,
517
+ };
518
+ const parentAlreadyExists = intermediateEntityObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity ===
519
+ parentIntermediateEntityRef.entity &&
520
+ existingParent.targetProp === intermediateEntityAlias);
521
+ if (!parentAlreadyExists) {
522
+ intermediateEntityObjectRepresentationRef.parents.push(parentRef);
523
+ }
524
+ intermediateEntityObjectRepresentationRef.alias =
525
+ intermediateEntityAlias;
526
+ const kebabCasedServiceName = (0, utils_1.lowerCaseFirst)((0, utils_1.kebabCase)(intermediateEntityModule.serviceName));
527
+ intermediateEntityObjectRepresentationRef.listeners = [
528
+ (0, utils_1.buildModuleResourceEventName)({
529
+ action: utils_1.CommonEvents.CREATED,
530
+ objectName: intermediateEntityName,
531
+ prefix: kebabCasedServiceName,
532
+ }),
533
+ (0, utils_1.buildModuleResourceEventName)({
534
+ action: utils_1.CommonEvents.UPDATED,
535
+ objectName: intermediateEntityName,
536
+ prefix: kebabCasedServiceName,
537
+ }),
538
+ (0, utils_1.buildModuleResourceEventName)({
539
+ action: utils_1.CommonEvents.DELETED,
540
+ objectName: intermediateEntityName,
541
+ prefix: kebabCasedServiceName,
542
+ }),
543
+ ];
544
+ intermediateEntityObjectRepresentationRef.moduleConfig =
545
+ intermediateEntityModule;
546
+ if (!intermediateEntityObjectRepresentationRef.fields.includes("id")) {
547
+ intermediateEntityObjectRepresentationRef.fields.push("id");
548
+ }
549
+ /**
550
+ * We push the parent id only between intermediate entities but not between intermediate and link
551
+ */
552
+ if (!isLastIntermediateEntity) {
553
+ const propertyToAdd = parentPropertyNameWithinIntermediateEntity?.name + ".id";
554
+ if (parentPropertyNameWithinIntermediateEntity &&
555
+ !intermediateEntityObjectRepresentationRef.fields.includes(propertyToAdd)) {
556
+ intermediateEntityObjectRepresentationRef.fields.push(propertyToAdd);
557
+ }
558
+ }
559
+ }
560
+ /**
561
+ * If there is any intermediate entity then we need to set the last one as the parent field for the current entity.
562
+ * otherwise there is not need to set the link id field into the current entity.
563
+ */
564
+ let currentParentIntermediateRef = linkObjectRepresentationRef;
565
+ if (linkModuleMetadata.intermediateEntityNames.length) {
566
+ currentParentIntermediateRef =
567
+ objectRepresentationRef[linkModuleMetadata.intermediateEntityNames[0]];
568
+ const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
569
+ sourceEntityName: currentObjectRepresentationRef.entity,
570
+ targetEntityName: currentParentIntermediateRef.entity,
571
+ entitiesMap: servicesEntityMap,
572
+ });
573
+ const propertyToAdd = parentPropertyNameWithinCurrentEntity?.name + ".id";
574
+ if (parentPropertyNameWithinCurrentEntity &&
575
+ !currentObjectRepresentationRef.fields.includes(propertyToAdd)) {
576
+ currentObjectRepresentationRef.fields.push(propertyToAdd);
577
+ }
578
+ }
579
+ const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
580
+ sourceEntityName: currentObjectRepresentationRef.entity,
581
+ targetEntityName: currentParentIntermediateRef.entity,
582
+ entitiesMap: servicesEntityMap,
583
+ });
584
+ const entityTargetPropertyIsListInParent = retrieveEntityPropByType({
585
+ sourceEntityName: currentParentIntermediateRef.entity,
586
+ targetEntityName: currentObjectRepresentationRef.entity,
587
+ entitiesMap: entitiesMap,
588
+ servicesEntityMap: servicesEntityMap,
589
+ })?.isArray;
590
+ const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity ===
591
+ currentParentIntermediateRef.entity &&
592
+ existingParent.targetProp === entityTargetPropertyNameInParent);
593
+ if (!parentAlreadyExists) {
594
+ currentObjectRepresentationRef.parents.push({
595
+ ref: currentParentIntermediateRef,
596
+ inSchemaRef: parentObjectRepresentationRef,
597
+ targetProp: entityTargetPropertyNameInParent,
598
+ inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
599
+ isList: entityTargetPropertyIsListInParent,
600
+ });
601
+ }
602
+ }
603
+ }
604
+ }
605
+ }
606
+ function getServicesEntityMap(moduleJoinerConfigs, addtionalSchema = "") {
607
+ return makeSchemaExecutable(base_graphql_schema_1.baseGraphqlSchema +
608
+ "\n" +
609
+ moduleJoinerConfigs
610
+ .map((joinerConfig) => joinerConfig?.schema ?? "")
611
+ .join("\n") +
612
+ "\n" +
613
+ addtionalSchema).getTypeMap();
614
+ }
615
+ /**
616
+ * Build a special object which will be used to retrieve the correct
617
+ * object representation using path tree
618
+ *
619
+ * @example
620
+ * {
621
+ * _schemaPropertiesMap: {
622
+ * "product": <ProductRef>
623
+ * "product.variants": <ProductVariantRef>
624
+ * }
625
+ * }
626
+ */
627
+ function buildAliasMap(objectRepresentation) {
628
+ const aliasMap = {};
629
+ function recursivelyBuildAliasPath(current, parentPath = "", aliases = [], visited = new Set(), pathStack = []) {
630
+ const pathIdentifier = `${current.entity}:${parentPath}`;
631
+ if (pathStack.includes(pathIdentifier)) {
632
+ return [];
633
+ }
634
+ pathStack.push(pathIdentifier);
635
+ if (visited.has(current.entity)) {
636
+ pathStack.pop();
637
+ return [];
638
+ }
639
+ visited.add(current.entity);
640
+ for (const parentEntity of current.parents) {
641
+ const newParentPath = parentPath
642
+ ? `${parentEntity.targetProp}.${parentPath}`
643
+ : parentEntity.targetProp;
644
+ const newVisited = new Set(visited);
645
+ const newPathStack = [...pathStack];
646
+ const parentAliases = recursivelyBuildAliasPath(parentEntity.ref, newParentPath, [], newVisited, newPathStack).map((aliasObj) => ({
647
+ alias: aliasObj.alias,
648
+ isInverse: parentEntity.isInverse,
649
+ isList: parentEntity.isList,
650
+ }));
651
+ aliases.push(...parentAliases);
652
+ // Handle shortcut paths via inSchemaRef
653
+ if (parentEntity.inSchemaRef) {
654
+ const shortCutOf = parentAliases[0];
655
+ if (!shortCutOf) {
656
+ continue;
657
+ }
658
+ const shortcutAliases_ = recursivelyBuildAliasPath(parentEntity.inSchemaRef, newParentPath, [], new Set(visited), [...pathStack]);
659
+ // Assign all shortcut aliases to the parent aliases
660
+ const shortcutAliases = [];
661
+ shortcutAliases_.forEach((shortcutAlias) => {
662
+ parentAliases.forEach((aliasObj) => {
663
+ let isSamePath = aliasObj.alias.split(".")[0] === shortcutAlias.alias.split(".")[0];
664
+ if (!isSamePath) {
665
+ return;
666
+ }
667
+ shortcutAliases.push({
668
+ alias: shortcutAlias.alias,
669
+ shortCutOf: aliasObj.alias,
670
+ isList: parentEntity.isList ?? true,
671
+ isInverse: shortcutAlias.isInverse,
672
+ });
673
+ });
674
+ });
675
+ // Only add shortcut aliases if they don’t duplicate existing paths
676
+ for (const shortcut of shortcutAliases) {
677
+ if (!aliases.some((a) => a.alias === shortcut?.alias)) {
678
+ aliases.push(shortcut);
679
+ }
680
+ }
681
+ }
682
+ }
683
+ // Add the current entity's alias, avoiding duplication
684
+ const pathSegments = parentPath ? parentPath.split(".") : [];
685
+ const baseAlias = pathSegments.length && pathSegments[0] === current.alias
686
+ ? parentPath // If parentPath already starts with this alias, use it as-is
687
+ : `${current.alias}${parentPath ? `.${parentPath}` : ""}`;
688
+ if (!aliases.some((a) => a.alias === baseAlias)) {
689
+ aliases.push({
690
+ alias: baseAlias,
691
+ isInverse: false,
692
+ });
693
+ }
694
+ pathStack.pop();
695
+ visited.delete(current.entity);
696
+ return aliases;
697
+ }
698
+ for (const objectRepresentationKey of Object.keys(objectRepresentation).filter((key) => !_types_1.schemaObjectRepresentationPropertiesToOmit.includes(key))) {
699
+ const entityRepresentationRef = objectRepresentation[objectRepresentationKey];
700
+ const aliases = recursivelyBuildAliasPath(entityRepresentationRef);
701
+ for (const alias of aliases) {
702
+ if (aliasMap[alias.alias] && !alias.shortCutOf) {
703
+ continue;
704
+ }
705
+ aliasMap[alias.alias] = {
706
+ ref: entityRepresentationRef,
707
+ shortCutOf: alias.shortCutOf,
708
+ isList: alias.isList,
709
+ isInverse: alias.isInverse,
710
+ };
711
+ }
712
+ }
713
+ return aliasMap;
714
+ }
715
+ function buildSchemaFromFilterableLinks(moduleJoinerConfigs, servicesEntityMap) {
716
+ const allFilterable = moduleJoinerConfigs.flatMap((config) => {
717
+ const entities = [];
718
+ const schema = config.schema;
719
+ if (config.isLink) {
720
+ if (!config.relationships?.some((r) => r.filterable?.length)) {
721
+ return [];
722
+ }
723
+ for (const relationship of config.relationships) {
724
+ relationship.filterable ??= [];
725
+ if (!relationship.filterable?.length ||
726
+ !relationship.filterable?.includes("id")) {
727
+ relationship.filterable.push("id");
728
+ }
729
+ const fieldAliasMap = {};
730
+ for (const extend of config.extends ?? []) {
731
+ fieldAliasMap[extend.serviceName] = Object.keys(extend.fieldAlias ?? {});
732
+ fieldAliasMap[extend.serviceName].push(extend.relationship.alias);
733
+ }
734
+ const serviceName = relationship.serviceName;
735
+ entities.push({
736
+ serviceName,
737
+ entity: relationship.entity,
738
+ fields: Array.from(new Set(relationship.filterable.concat(fieldAliasMap[serviceName] ?? []))),
739
+ schema,
740
+ });
741
+ }
742
+ return entities;
743
+ }
744
+ let aliases = config.alias ?? [];
745
+ aliases = (Array.isArray(aliases) ? aliases : [aliases]).filter((a) => a.filterable?.length && a.entity);
746
+ for (const alias of aliases) {
747
+ entities.push({
748
+ serviceName: config.serviceName,
749
+ entity: alias.entity,
750
+ fields: Array.from(new Set(alias.filterable)),
751
+ schema,
752
+ });
753
+ }
754
+ return entities;
755
+ });
756
+ const getGqlType = (entity, field) => {
757
+ const fieldRef = servicesEntityMap[entity]?._fields?.[field];
758
+ if (!fieldRef) {
759
+ return;
760
+ }
761
+ const fieldType = fieldRef.type.toString();
762
+ const isArray = fieldType.startsWith("[");
763
+ let currentType = fieldType.replace(/\[|\]|\!/g, "");
764
+ const isEnum = fieldRef.type?.ofType?.astNode?.kind ===
765
+ utils_1.GraphQLUtils.Kind.ENUM_TYPE_DEFINITION;
766
+ if (isEnum) {
767
+ currentType = "String";
768
+ }
769
+ return isArray ? `[${currentType}]` : currentType;
770
+ };
771
+ const schema = allFilterable
772
+ .map(({ serviceName, entity, fields, schema }) => {
773
+ if (!schema) {
774
+ return;
775
+ }
776
+ const normalizedEntity = (0, utils_1.lowerCaseFirst)((0, utils_1.kebabCase)(entity));
777
+ const events = `@Listeners(values: ["${serviceName}.${normalizedEntity}.created", "${serviceName}.${normalizedEntity}.updated", "${serviceName}.${normalizedEntity}.deleted"])`;
778
+ const fieldDefinitions = fields
779
+ .map((field) => {
780
+ const type = getGqlType(entity, field) ?? "String";
781
+ return ` ${field}: ${type}`;
782
+ })
783
+ .join("\n");
784
+ return `
785
+ type ${entity} ${events} {
786
+ id: ID!
787
+ }
788
+
789
+ extend type ${entity} {
790
+ ${fieldDefinitions}
791
+ }`;
792
+ })
793
+ .join("\n\n");
794
+ return schema;
795
+ }
796
+ /**
797
+ * This util build an internal representation object from the provided schema.
798
+ * It will resolve all modules, fields, link module representation to build
799
+ * the appropriate representation for the index module.
800
+ *
801
+ * This representation will be used to re construct the expected output object from a search
802
+ * but can also be used for anything since the relation tree is available through ref.
803
+ *
804
+ * @param schema
805
+ */
806
+ function buildSchemaObjectRepresentation(schema) {
807
+ const moduleJoinerConfigs = modules_sdk_1.AcmeKitModule.getAllJoinerConfigs();
808
+ const servicesEntityMap = getServicesEntityMap(moduleJoinerConfigs);
809
+ const filterableEntities = buildSchemaFromFilterableLinks(moduleJoinerConfigs, servicesEntityMap);
810
+ const augmentedSchema = exports.CustomDirectives.Listeners.definition +
811
+ "\n" +
812
+ schema +
813
+ "\n" +
814
+ filterableEntities;
815
+ const executableSchema = makeSchemaExecutable(augmentedSchema);
816
+ const entitiesMap = executableSchema.getTypeMap();
817
+ const objectRepresentation = {
818
+ _serviceNameModuleConfigMap: {},
819
+ };
820
+ Object.entries(entitiesMap).forEach(([entityName, entityMapValue]) => {
821
+ if (!entityMapValue.astNode ||
822
+ entityMapValue.astNode.kind === utils_1.GraphQLUtils.Kind.SCALAR_TYPE_DEFINITION) {
823
+ return;
824
+ }
825
+ processEntity(entityName, {
826
+ entitiesMap,
827
+ servicesEntityMap,
828
+ moduleJoinerConfigs,
829
+ objectRepresentationRef: objectRepresentation,
830
+ });
831
+ });
832
+ objectRepresentation._schemaPropertiesMap =
833
+ buildAliasMap(objectRepresentation);
834
+ return {
835
+ objectRepresentation,
836
+ entitiesMap,
837
+ executableSchema,
838
+ };
839
+ }
840
+ //# sourceMappingURL=build-config.js.map