@etohq/index 1.0.0

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 (79) 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 +16 -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/models/index-data.d.ts +9 -0
  19. package/dist/models/index-data.d.ts.map +1 -0
  20. package/dist/models/index-data.js +39 -0
  21. package/dist/models/index-data.js.map +1 -0
  22. package/dist/models/index-relation.d.ts +22 -0
  23. package/dist/models/index-relation.d.ts.map +1 -0
  24. package/dist/models/index-relation.js +21 -0
  25. package/dist/models/index-relation.js.map +1 -0
  26. package/dist/models/index.d.ts +3 -0
  27. package/dist/models/index.d.ts.map +1 -0
  28. package/dist/models/index.js +11 -0
  29. package/dist/models/index.js.map +1 -0
  30. package/dist/services/index-module-service.d.ts +30 -0
  31. package/dist/services/index-module-service.d.ts.map +1 -0
  32. package/dist/services/index-module-service.js +71 -0
  33. package/dist/services/index-module-service.js.map +1 -0
  34. package/dist/services/index.d.ts +2 -0
  35. package/dist/services/index.d.ts.map +1 -0
  36. package/dist/services/index.js +9 -0
  37. package/dist/services/index.js.map +1 -0
  38. package/dist/services/postgres-provider.d.ts +132 -0
  39. package/dist/services/postgres-provider.d.ts.map +1 -0
  40. package/dist/services/postgres-provider.js +490 -0
  41. package/dist/services/postgres-provider.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/types/index.d.ts +22 -0
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/types/index.js +8 -0
  46. package/dist/types/index.js.map +1 -0
  47. package/dist/utils/build-config.d.ts +24 -0
  48. package/dist/utils/build-config.d.ts.map +1 -0
  49. package/dist/utils/build-config.js +472 -0
  50. package/dist/utils/build-config.js.map +1 -0
  51. package/dist/utils/create-partitions.d.ts +4 -0
  52. package/dist/utils/create-partitions.d.ts.map +1 -0
  53. package/dist/utils/create-partitions.js +31 -0
  54. package/dist/utils/create-partitions.js.map +1 -0
  55. package/dist/utils/default-schema.d.ts +2 -0
  56. package/dist/utils/default-schema.d.ts.map +1 -0
  57. package/dist/utils/default-schema.js +24 -0
  58. package/dist/utils/default-schema.js.map +1 -0
  59. package/dist/utils/flatten-object-keys.d.ts +23 -0
  60. package/dist/utils/flatten-object-keys.d.ts.map +1 -0
  61. package/dist/utils/flatten-object-keys.js +54 -0
  62. package/dist/utils/flatten-object-keys.js.map +1 -0
  63. package/dist/utils/gql-to-types.d.ts +2 -0
  64. package/dist/utils/gql-to-types.d.ts.map +1 -0
  65. package/dist/utils/gql-to-types.js +91 -0
  66. package/dist/utils/gql-to-types.js.map +1 -0
  67. package/dist/utils/index.d.ts +4 -0
  68. package/dist/utils/index.d.ts.map +1 -0
  69. package/dist/utils/index.js +20 -0
  70. package/dist/utils/index.js.map +1 -0
  71. package/dist/utils/normalize-fields-selection.d.ts +2 -0
  72. package/dist/utils/normalize-fields-selection.d.ts.map +1 -0
  73. package/dist/utils/normalize-fields-selection.js +10 -0
  74. package/dist/utils/normalize-fields-selection.js.map +1 -0
  75. package/dist/utils/query-builder.d.ts +42 -0
  76. package/dist/utils/query-builder.d.ts.map +1 -0
  77. package/dist/utils/query-builder.js +420 -0
  78. package/dist/utils/query-builder.js.map +1 -0
  79. package/package.json +65 -0
@@ -0,0 +1,472 @@
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("@etohq/framework/modules-sdk");
7
+ const utils_1 = require("@etohq/framework/utils");
8
+ const _types_1 = require("../types");
9
+ exports.CustomDirectives = {
10
+ Listeners: {
11
+ configurationPropertyName: "listeners",
12
+ isRequired: true,
13
+ name: "Listeners",
14
+ directive: "@Listeners",
15
+ definition: "directive @Listeners (values: [String!]) on OBJECT",
16
+ },
17
+ };
18
+ function makeSchemaExecutable(inputSchema) {
19
+ const { schema: cleanedSchema } = utils_1.GraphQLUtils.cleanGraphQLSchema(inputSchema);
20
+ return utils_1.GraphQLUtils.makeExecutableSchema({ typeDefs: cleanedSchema });
21
+ }
22
+ function extractNameFromAlias(alias) {
23
+ const alias_ = Array.isArray(alias) ? alias[0] : alias;
24
+ const names = Array.isArray(alias_?.name) ? alias_?.name : [alias_?.name];
25
+ return names[0];
26
+ }
27
+ function retrieveAliasForEntity(entityName, aliases) {
28
+ aliases = aliases ? (Array.isArray(aliases) ? aliases : [aliases]) : [];
29
+ for (const alias of aliases) {
30
+ const names = Array.isArray(alias.name) ? alias.name : [alias.name];
31
+ if (alias.entity === entityName) {
32
+ return names[0];
33
+ }
34
+ for (const name of names) {
35
+ if (name.toLowerCase() === entityName.toLowerCase()) {
36
+ return name;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ function retrieveModuleAndAlias(entityName, moduleJoinerConfigs) {
42
+ let relatedModule;
43
+ let alias;
44
+ for (const moduleJoinerConfig of moduleJoinerConfigs) {
45
+ const moduleSchema = moduleJoinerConfig.schema;
46
+ const moduleAliases = moduleJoinerConfig.alias;
47
+ /**
48
+ * If the entity exist in the module schema, then the current module is the
49
+ * one we are looking for.
50
+ *
51
+ * If the module does not have any schema, then we need to base the search
52
+ * on the provided aliases. in any case, we try to get both
53
+ */
54
+ if (moduleSchema) {
55
+ const executableSchema = makeSchemaExecutable(moduleSchema);
56
+ const entitiesMap = executableSchema.getTypeMap();
57
+ if (entitiesMap[entityName]) {
58
+ relatedModule = moduleJoinerConfig;
59
+ }
60
+ }
61
+ if (relatedModule && moduleAliases) {
62
+ alias = retrieveAliasForEntity(entityName, moduleJoinerConfig.alias);
63
+ }
64
+ if (relatedModule) {
65
+ break;
66
+ }
67
+ }
68
+ if (!relatedModule) {
69
+ return { relatedModule: null, alias: null };
70
+ }
71
+ if (!alias) {
72
+ 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.`);
73
+ }
74
+ return { relatedModule, alias };
75
+ }
76
+ // TODO: rename util
77
+ function retrieveLinkModuleAndAlias({ primaryEntity, primaryModuleConfig, foreignEntity, foreignModuleConfig, moduleJoinerConfigs, }) {
78
+ const linkModulesMetadata = [];
79
+ for (const linkModuleJoinerConfig of moduleJoinerConfigs.filter((config) => config.isLink && !config.isReadOnlyLink)) {
80
+ const linkPrimary = linkModuleJoinerConfig.relationships[0];
81
+ const linkForeign = linkModuleJoinerConfig.relationships[1];
82
+ if (linkPrimary.serviceName === primaryModuleConfig.serviceName &&
83
+ linkForeign.serviceName === foreignModuleConfig.serviceName) {
84
+ const primaryEntityLinkableKey = linkPrimary.foreignKey;
85
+ const isTheForeignKeyEntityEqualPrimaryEntity = primaryModuleConfig.linkableKeys?.[primaryEntityLinkableKey] ===
86
+ primaryEntity;
87
+ const foreignEntityLinkableKey = linkForeign.foreignKey;
88
+ const isTheForeignKeyEntityEqualForeignEntity = foreignModuleConfig.linkableKeys?.[foreignEntityLinkableKey] ===
89
+ foreignEntity;
90
+ const linkName = linkModuleJoinerConfig.extends?.find((extend) => {
91
+ return (extend.serviceName === primaryModuleConfig.serviceName &&
92
+ extend.relationship.primaryKey === primaryEntityLinkableKey);
93
+ })?.relationship.serviceName;
94
+ if (!linkName) {
95
+ 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`);
96
+ }
97
+ if (!linkModuleJoinerConfig.alias?.[0]?.entity) {
98
+ 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.`);
99
+ }
100
+ if (isTheForeignKeyEntityEqualPrimaryEntity &&
101
+ isTheForeignKeyEntityEqualForeignEntity) {
102
+ /**
103
+ * 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
104
+ */
105
+ linkModulesMetadata.push({
106
+ entityName: linkModuleJoinerConfig.alias[0].entity,
107
+ alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
108
+ linkModuleConfig: linkModuleJoinerConfig,
109
+ intermediateEntityNames: [],
110
+ });
111
+ }
112
+ else {
113
+ const intermediateEntityName = foreignModuleConfig.linkableKeys[foreignEntityLinkableKey];
114
+ if (!foreignModuleConfig.schema) {
115
+ 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.`);
116
+ }
117
+ const executableSchema = makeSchemaExecutable(foreignModuleConfig.schema);
118
+ const entitiesMap = executableSchema.getTypeMap();
119
+ let intermediateEntities = [];
120
+ let foundCount = 0;
121
+ const isForeignEntityChildOfIntermediateEntity = (entityName) => {
122
+ for (const entityType of Object.values(entitiesMap)) {
123
+ if (entityType.astNode?.kind === "ObjectTypeDefinition" &&
124
+ entityType.astNode?.fields?.some((field) => {
125
+ return field.type?.type?.name?.value === entityName;
126
+ })) {
127
+ if (entityType.name === intermediateEntityName) {
128
+ ++foundCount;
129
+ return true;
130
+ }
131
+ else {
132
+ const test = isForeignEntityChildOfIntermediateEntity(entityType.name);
133
+ if (test) {
134
+ intermediateEntities.push(entityType.name);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ return false;
140
+ };
141
+ isForeignEntityChildOfIntermediateEntity(foreignEntity);
142
+ if (foundCount !== 1) {
143
+ throw new Error(`Index Module error, unable to retrieve the intermediate entities for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName} between ${foreignEntity} and ${intermediateEntityName}. Multiple paths or no path found. Please check your schema in ${foreignModuleConfig.serviceName}`);
144
+ }
145
+ intermediateEntities.push(intermediateEntityName);
146
+ /**
147
+ * 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
148
+ */
149
+ linkModulesMetadata.push({
150
+ entityName: linkModuleJoinerConfig.alias[0].entity,
151
+ alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
152
+ linkModuleConfig: linkModuleJoinerConfig,
153
+ intermediateEntityNames: intermediateEntities,
154
+ });
155
+ }
156
+ }
157
+ }
158
+ if (!linkModulesMetadata.length) {
159
+ // TODO: change to use the logger
160
+ console.warn(`Index Module warning, unable to retrieve the link module that correspond to the entities ${primaryEntity} - ${foreignEntity}.`);
161
+ }
162
+ return linkModulesMetadata;
163
+ }
164
+ function getObjectRepresentationRef(entityName, { objectRepresentationRef }) {
165
+ return (objectRepresentationRef[entityName] ??= {
166
+ entity: entityName,
167
+ parents: [],
168
+ alias: "",
169
+ listeners: [],
170
+ moduleConfig: null,
171
+ fields: [],
172
+ });
173
+ }
174
+ function setCustomDirectives(currentObjectRepresentationRef, directives) {
175
+ for (const customDirectiveConfiguration of Object.values(exports.CustomDirectives)) {
176
+ const directive = directives.find((typeDirective) => typeDirective.name.value === customDirectiveConfiguration.name);
177
+ if (!directive) {
178
+ return;
179
+ }
180
+ // Only support array directive value for now
181
+ currentObjectRepresentationRef[customDirectiveConfiguration.configurationPropertyName] = (directive.arguments[0].value?.values ?? []).map((v) => v.value);
182
+ }
183
+ }
184
+ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRepresentationRef, }) {
185
+ /**
186
+ * Get the reference to the object representation for the current entity.
187
+ */
188
+ const currentObjectRepresentationRef = getObjectRepresentationRef(entityName, {
189
+ objectRepresentationRef,
190
+ });
191
+ /**
192
+ * Retrieve and set the custom directives for the current entity.
193
+ */
194
+ setCustomDirectives(currentObjectRepresentationRef, entitiesMap[entityName].astNode?.directives ?? []);
195
+ currentObjectRepresentationRef.fields =
196
+ utils_1.GraphQLUtils.gqlGetFieldsAndRelations(entitiesMap, entityName) ?? [];
197
+ /**
198
+ * Retrieve the module and alias for the current entity.
199
+ */
200
+ const { relatedModule: currentEntityModule, alias } = retrieveModuleAndAlias(entityName, moduleJoinerConfigs);
201
+ if (!currentEntityModule &&
202
+ currentObjectRepresentationRef.listeners.length > 0) {
203
+ const example = JSON.stringify({
204
+ alias: [
205
+ {
206
+ name: "entity-alias",
207
+ entity: entityName,
208
+ },
209
+ ],
210
+ });
211
+ 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}`);
212
+ }
213
+ if (currentEntityModule) {
214
+ objectRepresentationRef._serviceNameModuleConfigMap[currentEntityModule.serviceName] = currentEntityModule;
215
+ currentObjectRepresentationRef.moduleConfig = currentEntityModule;
216
+ currentObjectRepresentationRef.alias = alias;
217
+ }
218
+ /**
219
+ * Retrieve the parent entities for the current entity.
220
+ */
221
+ const schemaParentEntity = Object.values(entitiesMap).filter((value) => {
222
+ return (value.astNode &&
223
+ value.astNode.fields?.some((field) => {
224
+ let currentType = field.type;
225
+ while (currentType.type) {
226
+ currentType = currentType.type;
227
+ }
228
+ return currentType.name?.value === entityName;
229
+ }));
230
+ });
231
+ if (!schemaParentEntity.length) {
232
+ return;
233
+ }
234
+ /**
235
+ * If the current entity has parent entities, then we need to process them.
236
+ */
237
+ const parentEntityNames = schemaParentEntity.map((parent) => {
238
+ return parent.name;
239
+ });
240
+ for (const parent of parentEntityNames) {
241
+ /**
242
+ * Retrieve the parent entity field in the schema
243
+ */
244
+ const entityFieldInParent = entitiesMap[parent].astNode?.fields?.find((field) => {
245
+ let currentType = field.type;
246
+ while (currentType.type) {
247
+ currentType = currentType.type;
248
+ }
249
+ return currentType.name?.value === entityName;
250
+ });
251
+ const isEntityListInParent = entityFieldInParent.type.kind === utils_1.GraphQLUtils.Kind.LIST_TYPE;
252
+ const entityTargetPropertyNameInParent = entityFieldInParent.name.value;
253
+ /**
254
+ * Retrieve the parent entity object representation reference.
255
+ */
256
+ const parentObjectRepresentationRef = getObjectRepresentationRef(parent, {
257
+ objectRepresentationRef,
258
+ });
259
+ const parentModuleConfig = parentObjectRepresentationRef.moduleConfig;
260
+ // If the entity is not part of any module, just set the parent and continue
261
+ if (!currentObjectRepresentationRef.moduleConfig) {
262
+ currentObjectRepresentationRef.parents.push({
263
+ ref: parentObjectRepresentationRef,
264
+ targetProp: entityTargetPropertyNameInParent,
265
+ isList: isEntityListInParent,
266
+ });
267
+ continue;
268
+ }
269
+ /**
270
+ * If the parent entity and the current entity are part of the same servive then configure the parent and
271
+ * add the parent id as a field to the current entity.
272
+ */
273
+ if (currentObjectRepresentationRef.moduleConfig.serviceName ===
274
+ parentModuleConfig.serviceName ||
275
+ parentModuleConfig.isLink) {
276
+ currentObjectRepresentationRef.parents.push({
277
+ ref: parentObjectRepresentationRef,
278
+ targetProp: entityTargetPropertyNameInParent,
279
+ isList: isEntityListInParent,
280
+ });
281
+ currentObjectRepresentationRef.fields.push(parentObjectRepresentationRef.alias + ".id");
282
+ }
283
+ else {
284
+ /**
285
+ * If the parent entity and the current entity are not part of the same service then we need to
286
+ * find the link module that join them.
287
+ */
288
+ const linkModuleMetadatas = retrieveLinkModuleAndAlias({
289
+ primaryEntity: parentObjectRepresentationRef.entity,
290
+ primaryModuleConfig: parentModuleConfig,
291
+ foreignEntity: currentObjectRepresentationRef.entity,
292
+ foreignModuleConfig: currentEntityModule,
293
+ moduleJoinerConfigs,
294
+ });
295
+ for (const linkModuleMetadata of linkModuleMetadatas) {
296
+ const linkObjectRepresentationRef = getObjectRepresentationRef(linkModuleMetadata.entityName, { objectRepresentationRef });
297
+ objectRepresentationRef._serviceNameModuleConfigMap[linkModuleMetadata.linkModuleConfig.serviceName ||
298
+ linkModuleMetadata.entityName] = currentEntityModule;
299
+ /**
300
+ * Add the schema parent entity as a parent to the link module and configure it.
301
+ */
302
+ linkObjectRepresentationRef.parents = [
303
+ {
304
+ ref: parentObjectRepresentationRef,
305
+ targetProp: linkModuleMetadata.alias,
306
+ },
307
+ ];
308
+ linkObjectRepresentationRef.alias = linkModuleMetadata.alias;
309
+ linkObjectRepresentationRef.listeners = [
310
+ `${linkModuleMetadata.entityName}.${utils_1.CommonEvents.ATTACHED}`,
311
+ `${linkModuleMetadata.entityName}.${utils_1.CommonEvents.DETACHED}`,
312
+ ];
313
+ linkObjectRepresentationRef.moduleConfig =
314
+ linkModuleMetadata.linkModuleConfig;
315
+ linkObjectRepresentationRef.fields = [
316
+ "id",
317
+ ...linkModuleMetadata.linkModuleConfig
318
+ .relationships.map((relationship) => [
319
+ parentModuleConfig.serviceName,
320
+ currentEntityModule.serviceName,
321
+ ].includes(relationship.serviceName) && relationship.foreignKey)
322
+ .filter((v) => Boolean(v)),
323
+ ];
324
+ /**
325
+ * If the current entity is not the entity that is used to join the link module and the parent entity
326
+ * then we need to add the new entity that join them and then add the link as its parent
327
+ * before setting the new entity as the true parent of the current entity.
328
+ */
329
+ for (let i = linkModuleMetadata.intermediateEntityNames.length - 1; i >= 0; --i) {
330
+ const intermediateEntityName = linkModuleMetadata.intermediateEntityNames[i];
331
+ const isLastIntermediateEntity = i === linkModuleMetadata.intermediateEntityNames.length - 1;
332
+ const parentIntermediateEntityRef = isLastIntermediateEntity
333
+ ? linkObjectRepresentationRef
334
+ : objectRepresentationRef[linkModuleMetadata.intermediateEntityNames[i + 1]];
335
+ const { relatedModule: intermediateEntityModule, alias: intermediateEntityAlias, } = retrieveModuleAndAlias(intermediateEntityName, moduleJoinerConfigs);
336
+ const intermediateEntityObjectRepresentationRef = getObjectRepresentationRef(intermediateEntityName, {
337
+ objectRepresentationRef,
338
+ });
339
+ objectRepresentationRef._serviceNameModuleConfigMap[intermediateEntityModule.serviceName] = intermediateEntityModule;
340
+ intermediateEntityObjectRepresentationRef.parents.push({
341
+ ref: parentIntermediateEntityRef,
342
+ targetProp: intermediateEntityAlias,
343
+ isList: true, // TODO: check if it is a list in retrieveLinkModuleAndAlias and return the intermediate entity names + isList for each
344
+ });
345
+ intermediateEntityObjectRepresentationRef.alias =
346
+ intermediateEntityAlias;
347
+ intermediateEntityObjectRepresentationRef.listeners = [
348
+ intermediateEntityName + "." + utils_1.CommonEvents.CREATED,
349
+ intermediateEntityName + "." + utils_1.CommonEvents.UPDATED,
350
+ ];
351
+ intermediateEntityObjectRepresentationRef.moduleConfig =
352
+ intermediateEntityModule;
353
+ intermediateEntityObjectRepresentationRef.fields = ["id"];
354
+ /**
355
+ * We push the parent id only between intermediate entities but not between intermediate and link
356
+ */
357
+ if (!isLastIntermediateEntity) {
358
+ intermediateEntityObjectRepresentationRef.fields.push(parentIntermediateEntityRef.alias + ".id");
359
+ }
360
+ }
361
+ /**
362
+ * If there is any intermediate entity then we need to set the last one as the parent field for the current entity.
363
+ * otherwise there is not need to set the link id field into the current entity.
364
+ */
365
+ let currentParentIntermediateRef = linkObjectRepresentationRef;
366
+ if (linkModuleMetadata.intermediateEntityNames.length) {
367
+ currentParentIntermediateRef =
368
+ objectRepresentationRef[linkModuleMetadata.intermediateEntityNames[0]];
369
+ currentObjectRepresentationRef.fields.push(currentParentIntermediateRef.alias + ".id");
370
+ }
371
+ currentObjectRepresentationRef.parents.push({
372
+ ref: currentParentIntermediateRef,
373
+ inSchemaRef: parentObjectRepresentationRef,
374
+ targetProp: entityTargetPropertyNameInParent,
375
+ isList: isEntityListInParent,
376
+ });
377
+ }
378
+ }
379
+ }
380
+ }
381
+ /**
382
+ * Build a special object which will be used to retrieve the correct
383
+ * object representation using path tree
384
+ *
385
+ * @example
386
+ * {
387
+ * _schemaPropertiesMap: {
388
+ * "product": <ProductRef>
389
+ * "product.variants": <ProductVariantRef>
390
+ * }
391
+ * }
392
+ */
393
+ function buildAliasMap(objectRepresentation) {
394
+ const aliasMap = {};
395
+ function recursivelyBuildAliasPath(current, alias = "", aliases = []) {
396
+ if (current.parents?.length) {
397
+ for (const parentEntity of current.parents) {
398
+ /**
399
+ * Here we build the alias from child to parent to get it as parent to child
400
+ */
401
+ const _aliases = recursivelyBuildAliasPath(parentEntity.ref, `${parentEntity.targetProp}${alias ? "." + alias : ""}`).map((alias) => ({ alias: alias.alias }));
402
+ aliases.push(..._aliases);
403
+ /**
404
+ * Now if there is a inSchemaRef it means that we had inferred a link module
405
+ * and we want to get the alias path as it would be in the schema provided
406
+ * and it become the short cut path of the full path above
407
+ */
408
+ if (parentEntity.inSchemaRef) {
409
+ const shortCutOf = _aliases.map((a) => a.alias)[0];
410
+ const _aliasesShortCut = recursivelyBuildAliasPath(parentEntity.inSchemaRef, `${parentEntity.targetProp}${alias ? "." + alias : ""}`).map((alias_) => {
411
+ return {
412
+ alias: alias_.alias,
413
+ // It has to be the same entry point
414
+ shortCutOf: shortCutOf.split(".")[0] === alias_.alias.split(".")[0]
415
+ ? shortCutOf
416
+ : undefined,
417
+ };
418
+ });
419
+ aliases.push(..._aliasesShortCut);
420
+ }
421
+ }
422
+ }
423
+ aliases.push({ alias: current.alias + (alias ? "." + alias : "") });
424
+ return aliases;
425
+ }
426
+ for (const objectRepresentationKey of Object.keys(objectRepresentation).filter((key) => !_types_1.schemaObjectRepresentationPropertiesToOmit.includes(key))) {
427
+ const entityRepresentationRef = objectRepresentation[objectRepresentationKey];
428
+ const aliases = recursivelyBuildAliasPath(entityRepresentationRef);
429
+ for (const alias of aliases) {
430
+ aliasMap[alias.alias] = {
431
+ ref: entityRepresentationRef,
432
+ };
433
+ if (alias.shortCutOf) {
434
+ aliasMap[alias.alias]["shortCutOf"] = alias.shortCutOf;
435
+ }
436
+ }
437
+ }
438
+ return aliasMap;
439
+ }
440
+ /**
441
+ * This util build an internal representation object from the provided schema.
442
+ * It will resolve all modules, fields, link module representation to build
443
+ * the appropriate representation for the index module.
444
+ *
445
+ * This representation will be used to re construct the expected output object from a search
446
+ * but can also be used for anything since the relation tree is available through ref.
447
+ *
448
+ * @param schema
449
+ */
450
+ function buildSchemaObjectRepresentation(schema) {
451
+ const moduleJoinerConfigs = modules_sdk_1.EtoModule.getAllJoinerConfigs();
452
+ const augmentedSchema = exports.CustomDirectives.Listeners.definition + schema;
453
+ const executableSchema = makeSchemaExecutable(augmentedSchema);
454
+ const entitiesMap = executableSchema.getTypeMap();
455
+ const objectRepresentation = {
456
+ _serviceNameModuleConfigMap: {},
457
+ };
458
+ Object.entries(entitiesMap).forEach(([entityName, entityMapValue]) => {
459
+ if (!entityMapValue.astNode) {
460
+ return;
461
+ }
462
+ processEntity(entityName, {
463
+ entitiesMap,
464
+ moduleJoinerConfigs,
465
+ objectRepresentationRef: objectRepresentation,
466
+ });
467
+ });
468
+ objectRepresentation._schemaPropertiesMap =
469
+ buildAliasMap(objectRepresentation);
470
+ return [objectRepresentation, entitiesMap];
471
+ }
472
+ //# sourceMappingURL=build-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-config.js","sourceRoot":"","sources":["../../src/utils/build-config.ts"],"names":[],"mappings":";;;AAoBA,oDAIC;AAqqBD,0EA4BC;AAztBD,8DAAwD;AAOxD,kDAAmE;AACnE,mCAAmE;AAEtD,QAAA,gBAAgB,GAAG;IAC9B,SAAS,EAAE;QACT,yBAAyB,EAAE,WAAW;QACtC,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,YAAY;QACvB,UAAU,EAAE,oDAAoD;KACjE;CACF,CAAA;AAED,SAAgB,oBAAoB,CAAC,WAAmB;IACtD,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,oBAAY,CA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UAAU,EAAE,CAAA;IAEjD,MAAM,oBAAoB,GAAG;QAC3B,2BAA2B,EAAE,EAAE;KACS,CAAA;IAE1C,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,EAAE;QACnE,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAM;QACR,CAAC;QAED,aAAa,CAAC,UAAU,EAAE;YACxB,WAAW;YACX,mBAAmB;YACnB,uBAAuB,EAAE,oBAAoB;SAC9C,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,oBAAoB,CAAC,oBAAoB;QACvC,aAAa,CAAC,oBAAoB,CAAC,CAAA;IAErC,OAAO,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { SqlEntityManager } from "@mikro-orm/postgresql";
2
+ import { IndexTypes } from "@etohq/framework/types";
3
+ export declare function createPartitions(schemaObjectRepresentation: IndexTypes.SchemaObjectRepresentation, manager: SqlEntityManager): Promise<void>;
4
+ //# sourceMappingURL=create-partitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-partitions.d.ts","sourceRoot":"","sources":["../../src/utils/create-partitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,wBAAsB,gBAAgB,CACpC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,EACjE,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CAoCf"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPartitions = createPartitions;
4
+ const _types_1 = require("../types");
5
+ async function createPartitions(schemaObjectRepresentation, manager) {
6
+ const activeSchema = manager.config.get("schema")
7
+ ? `"${manager.config.get("schema")}".`
8
+ : "";
9
+ const partitions = Object.keys(schemaObjectRepresentation)
10
+ .filter((key) => !_types_1.schemaObjectRepresentationPropertiesToOmit.includes(key) &&
11
+ schemaObjectRepresentation[key].listeners.length > 0)
12
+ .map((key) => {
13
+ const cName = key.toLowerCase();
14
+ const part = [];
15
+ part.push(`CREATE TABLE IF NOT EXISTS ${activeSchema}cat_${cName} PARTITION OF ${activeSchema}index_data FOR VALUES IN ('${key}')`);
16
+ for (const parent of schemaObjectRepresentation[key].parents) {
17
+ const pKey = `${parent.ref.entity}-${key}`;
18
+ const pName = `${parent.ref.entity}${key}`.toLowerCase();
19
+ part.push(`CREATE TABLE IF NOT EXISTS ${activeSchema}cat_pivot_${pName} PARTITION OF ${activeSchema}index_relation FOR VALUES IN ('${pKey}')`);
20
+ }
21
+ return part;
22
+ })
23
+ .flat();
24
+ if (!partitions.length) {
25
+ return;
26
+ }
27
+ partitions.push(`analyse ${activeSchema}index_data`);
28
+ partitions.push(`analyse ${activeSchema}index_relation`);
29
+ await manager.execute(partitions.join("; "));
30
+ }
31
+ //# sourceMappingURL=create-partitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-partitions.js","sourceRoot":"","sources":["../../src/utils/create-partitions.ts"],"names":[],"mappings":";;AAIA,4CAuCC;AA1CD,mCAAmE;AAG5D,KAAK,UAAU,gBAAgB,CACpC,0BAAiE,EACjE,OAAyB;IAEzB,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/C,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI;QACtC,CAAC,CAAC,EAAE,CAAA;IACN,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC;SACvD,MAAM,CACL,CAAC,GAAG,EAAE,EAAE,CACN,CAAC,mDAA0C,CAAC,QAAQ,CAAC,GAAG,CAAC;QACzD,0BAA0B,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CACvD;SACA,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAC/B,MAAM,IAAI,GAAa,EAAE,CAAA;QACzB,IAAI,CAAC,IAAI,CACP,8BAA8B,YAAY,OAAO,KAAK,iBAAiB,YAAY,8BAA8B,GAAG,IAAI,CACzH,CAAA;QAED,KAAK,MAAM,MAAM,IAAI,0BAA0B,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7D,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE,CAAA;YAC1C,MAAM,KAAK,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;YACxD,IAAI,CAAC,IAAI,CACP,8BAA8B,YAAY,aAAa,KAAK,iBAAiB,YAAY,kCAAkC,IAAI,IAAI,CACpI,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,IAAI,EAAE,CAAA;IAET,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACvB,OAAM;IACR,CAAC;IAED,UAAU,CAAC,IAAI,CAAC,WAAW,YAAY,YAAY,CAAC,CAAA;IACpD,UAAU,CAAC,IAAI,CAAC,WAAW,YAAY,gBAAgB,CAAC,CAAA;IAExD,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const defaultSchema: string;
2
+ //# sourceMappingURL=default-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-schema.d.ts","sourceRoot":"","sources":["../../src/utils/default-schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,QAkBzB,CAAA"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultSchema = void 0;
4
+ const utils_1 = require("@etohq/utils");
5
+ exports.defaultSchema = `
6
+ type Product @Listeners(values: ["${utils_1.Modules.PRODUCT}.product.created", "${utils_1.Modules.PRODUCT}.product.updated", "${utils_1.Modules.PRODUCT}.product.deleted"]) {
7
+ id: String
8
+ title: String
9
+ variants: [ProductVariant]
10
+ }
11
+
12
+ type ProductVariant @Listeners(values: ["${utils_1.Modules.PRODUCT}.product-variant.created", "${utils_1.Modules.PRODUCT}.product-variant.updated", "${utils_1.Modules.PRODUCT}.product-variant.deleted"]) {
13
+ id: String
14
+ product_id: String
15
+ sku: String
16
+ prices: [Price]
17
+ }
18
+
19
+ type Price @Listeners(values: ["${utils_1.Modules.PRICING}.price.created", "${utils_1.Modules.PRICING}.price.updated", "${utils_1.Modules.PRICING}.price.deleted"]) {
20
+ amount: Int
21
+ currency_code: String
22
+ }
23
+ `;
24
+ //# sourceMappingURL=default-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-schema.js","sourceRoot":"","sources":["../../src/utils/default-schema.ts"],"names":[],"mappings":";;;AAAA,wCAAsC;AAEzB,QAAA,aAAa,GAAG;sCACS,eAAO,CAAC,OAAO,uBAAuB,eAAO,CAAC,OAAO,uBAAuB,eAAO,CAAC,OAAO;;;;;;6CAMpF,eAAO,CAAC,OAAO,+BAA+B,eAAO,CAAC,OAAO,+BAA+B,eAAO,CAAC,OAAO;;;;;;;oCAOpH,eAAO,CAAC,OAAO,qBAAqB,eAAO,CAAC,OAAO,qBAAqB,eAAO,CAAC,OAAO;;;;CAI1H,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Flatten object keys
3
+ * @example
4
+ * input: {
5
+ * a: 1,
6
+ * b: {
7
+ * c: 2,
8
+ * d: 3,
9
+ * },
10
+ * e: 4,
11
+ * }
12
+ *
13
+ * output: {
14
+ * a: 1,
15
+ * b.c: 2,
16
+ * b.d: 3,
17
+ * e: 4,
18
+ * }
19
+ *
20
+ * @param input
21
+ */
22
+ export declare function flattenObjectKeys(input: Record<string, any>): Record<string, any>;
23
+ //# sourceMappingURL=flatten-object-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-object-keys.d.ts","sourceRoot":"","sources":["../../src/utils/flatten-object-keys.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,uBAmC3D"}