@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.
- package/README.md +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/index.d.ts +4 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +27 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/migrations/Migration20231019174230.d.ts +5 -0
- package/dist/migrations/Migration20231019174230.d.ts.map +1 -0
- package/dist/migrations/Migration20231019174230.js +16 -0
- package/dist/migrations/Migration20231019174230.js.map +1 -0
- package/dist/migrations/Migration20241209173313.d.ts +6 -0
- package/dist/migrations/Migration20241209173313.d.ts.map +1 -0
- package/dist/migrations/Migration20241209173313.js +36 -0
- package/dist/migrations/Migration20241209173313.js.map +1 -0
- package/dist/models/index-data.d.ts +9 -0
- package/dist/models/index-data.d.ts.map +1 -0
- package/dist/models/index-data.js +39 -0
- package/dist/models/index-data.js.map +1 -0
- package/dist/models/index-relation.d.ts +22 -0
- package/dist/models/index-relation.d.ts.map +1 -0
- package/dist/models/index-relation.js +21 -0
- package/dist/models/index-relation.js.map +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +11 -0
- package/dist/models/index.js.map +1 -0
- package/dist/services/index-module-service.d.ts +30 -0
- package/dist/services/index-module-service.d.ts.map +1 -0
- package/dist/services/index-module-service.js +71 -0
- package/dist/services/index-module-service.js.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +9 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/postgres-provider.d.ts +132 -0
- package/dist/services/postgres-provider.d.ts.map +1 -0
- package/dist/services/postgres-provider.js +490 -0
- package/dist/services/postgres-provider.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/build-config.d.ts +24 -0
- package/dist/utils/build-config.d.ts.map +1 -0
- package/dist/utils/build-config.js +472 -0
- package/dist/utils/build-config.js.map +1 -0
- package/dist/utils/create-partitions.d.ts +4 -0
- package/dist/utils/create-partitions.d.ts.map +1 -0
- package/dist/utils/create-partitions.js +31 -0
- package/dist/utils/create-partitions.js.map +1 -0
- package/dist/utils/default-schema.d.ts +2 -0
- package/dist/utils/default-schema.d.ts.map +1 -0
- package/dist/utils/default-schema.js +24 -0
- package/dist/utils/default-schema.js.map +1 -0
- package/dist/utils/flatten-object-keys.d.ts +23 -0
- package/dist/utils/flatten-object-keys.d.ts.map +1 -0
- package/dist/utils/flatten-object-keys.js +54 -0
- package/dist/utils/flatten-object-keys.js.map +1 -0
- package/dist/utils/gql-to-types.d.ts +2 -0
- package/dist/utils/gql-to-types.d.ts.map +1 -0
- package/dist/utils/gql-to-types.js +91 -0
- package/dist/utils/gql-to-types.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/normalize-fields-selection.d.ts +2 -0
- package/dist/utils/normalize-fields-selection.d.ts.map +1 -0
- package/dist/utils/normalize-fields-selection.js +10 -0
- package/dist/utils/normalize-fields-selection.js.map +1 -0
- package/dist/utils/query-builder.d.ts +42 -0
- package/dist/utils/query-builder.d.ts.map +1 -0
- package/dist/utils/query-builder.js +420 -0
- package/dist/utils/query-builder.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
15
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
16
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
18
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
19
|
+
};
|
|
20
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
+
};
|
|
25
|
+
var _PostgresProvider_isReady_;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.PostgresProvider = void 0;
|
|
28
|
+
const types_1 = require("@etohq/framework/types");
|
|
29
|
+
const utils_1 = require("@etohq/framework/utils");
|
|
30
|
+
const _models_1 = require("../models");
|
|
31
|
+
const utils_2 = require("../utils");
|
|
32
|
+
const flatten_object_keys_1 = require("../utils/flatten-object-keys");
|
|
33
|
+
const normalize_fields_selection_1 = require("../utils/normalize-fields-selection");
|
|
34
|
+
class PostgresProvider {
|
|
35
|
+
constructor(container, options, moduleOptions) {
|
|
36
|
+
_PostgresProvider_isReady_.set(this, void 0);
|
|
37
|
+
this.eventActionToMethodMap_ = {
|
|
38
|
+
created: "onCreate",
|
|
39
|
+
updated: "onUpdate",
|
|
40
|
+
deleted: "onDelete",
|
|
41
|
+
attached: "onAttach",
|
|
42
|
+
detached: "onDetach",
|
|
43
|
+
};
|
|
44
|
+
this.manager_ = container.manager;
|
|
45
|
+
this.query_ = container.query;
|
|
46
|
+
this.moduleOptions_ = moduleOptions;
|
|
47
|
+
this.baseRepository_ = container.baseRepository;
|
|
48
|
+
this.schemaObjectRepresentation_ = options.schemaObjectRepresentation;
|
|
49
|
+
this.schemaEntitiesMap_ = options.entityMap;
|
|
50
|
+
// Add a new column for each key that can be found in the jsonb data column to perform indexes and query on it.
|
|
51
|
+
// So far, the execution time is about the same
|
|
52
|
+
/*;(async () => {
|
|
53
|
+
const query = [
|
|
54
|
+
...new Set(
|
|
55
|
+
Object.keys(this.schemaObjectRepresentation_)
|
|
56
|
+
.filter(
|
|
57
|
+
(key) =>
|
|
58
|
+
![
|
|
59
|
+
"_serviceNameModuleConfigMap",
|
|
60
|
+
"_schemaPropertiesMap",
|
|
61
|
+
].includes(key)
|
|
62
|
+
)
|
|
63
|
+
.map((key) => {
|
|
64
|
+
return this.schemaObjectRepresentation_[key].fields.filter(
|
|
65
|
+
(field) => !field.includes(".")
|
|
66
|
+
)
|
|
67
|
+
})
|
|
68
|
+
.flat()
|
|
69
|
+
),
|
|
70
|
+
].map(
|
|
71
|
+
(field) =>
|
|
72
|
+
"ALTER TABLE index_data ADD IF NOT EXISTS " +
|
|
73
|
+
field +
|
|
74
|
+
" text GENERATED ALWAYS AS (NEW.data->>'" +
|
|
75
|
+
field +
|
|
76
|
+
"') STORED"
|
|
77
|
+
)
|
|
78
|
+
await this.manager_.execute(query.join(";"))
|
|
79
|
+
})()*/
|
|
80
|
+
}
|
|
81
|
+
async onApplicationStart() {
|
|
82
|
+
let initalizedOk = () => { };
|
|
83
|
+
let initalizedNok = () => { };
|
|
84
|
+
__classPrivateFieldSet(this, _PostgresProvider_isReady_, new Promise((resolve, reject) => {
|
|
85
|
+
initalizedOk = resolve;
|
|
86
|
+
initalizedNok = reject;
|
|
87
|
+
}), "f");
|
|
88
|
+
await (0, utils_2.createPartitions)(this.schemaObjectRepresentation_, this.manager_.fork())
|
|
89
|
+
.then(initalizedOk)
|
|
90
|
+
.catch(initalizedNok);
|
|
91
|
+
}
|
|
92
|
+
static parseData(data, schemaEntityObjectRepresentation) {
|
|
93
|
+
const data_ = Array.isArray(data) ? data : [data];
|
|
94
|
+
// Always keep the id in the entity properties
|
|
95
|
+
const entityProperties = ["id"];
|
|
96
|
+
const parentsProperties = {};
|
|
97
|
+
/**
|
|
98
|
+
* Split fields into entity properties and parents properties
|
|
99
|
+
*/
|
|
100
|
+
schemaEntityObjectRepresentation.fields.forEach((field) => {
|
|
101
|
+
if (field.includes(".")) {
|
|
102
|
+
const parentAlias = field.split(".")[0];
|
|
103
|
+
const parentSchemaObjectRepresentation = schemaEntityObjectRepresentation.parents.find((parent) => parent.ref.alias === parentAlias);
|
|
104
|
+
if (!parentSchemaObjectRepresentation) {
|
|
105
|
+
throw new Error(`IndexModule error, unable to parse data for ${schemaEntityObjectRepresentation.entity}. The parent schema object representation could not be found for the alias ${parentAlias} for the entity ${schemaEntityObjectRepresentation.entity}.`);
|
|
106
|
+
}
|
|
107
|
+
parentsProperties[parentSchemaObjectRepresentation.ref.entity] ??= [];
|
|
108
|
+
parentsProperties[parentSchemaObjectRepresentation.ref.entity].push(field);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
entityProperties.push(field);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
data: data_,
|
|
116
|
+
entityProperties,
|
|
117
|
+
parentsProperties,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
static parseMessageData(message) {
|
|
121
|
+
const isExpectedFormat = (0, utils_1.isDefined)(message?.data) && (0, utils_1.isDefined)(message?.metadata?.action);
|
|
122
|
+
if (!isExpectedFormat) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const result = {
|
|
126
|
+
action: "",
|
|
127
|
+
data: [],
|
|
128
|
+
ids: [],
|
|
129
|
+
};
|
|
130
|
+
result.action = message.metadata.action;
|
|
131
|
+
result.data = message.data;
|
|
132
|
+
result.data = Array.isArray(result.data) ? result.data : [result.data];
|
|
133
|
+
result.ids = result.data.map((d) => d.id);
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
consumeEvent(schemaEntityObjectRepresentation) {
|
|
137
|
+
return async (data) => {
|
|
138
|
+
await __classPrivateFieldGet(this, _PostgresProvider_isReady_, "f");
|
|
139
|
+
const data_ = Array.isArray(data.data)
|
|
140
|
+
? data.data
|
|
141
|
+
: [data.data];
|
|
142
|
+
let ids = data_.map((d) => d.id);
|
|
143
|
+
let action = data.name.split(".").pop() || "";
|
|
144
|
+
const parsedMessage = PostgresProvider.parseMessageData(data);
|
|
145
|
+
if (parsedMessage) {
|
|
146
|
+
action = parsedMessage.action;
|
|
147
|
+
ids = parsedMessage.ids;
|
|
148
|
+
}
|
|
149
|
+
const { fields, alias } = schemaEntityObjectRepresentation;
|
|
150
|
+
const { data: entityData } = await this.query_.graph({
|
|
151
|
+
entity: alias,
|
|
152
|
+
filters: {
|
|
153
|
+
id: ids,
|
|
154
|
+
},
|
|
155
|
+
fields: [...new Set(["id", ...fields])],
|
|
156
|
+
});
|
|
157
|
+
const argument = {
|
|
158
|
+
entity: schemaEntityObjectRepresentation.entity,
|
|
159
|
+
data: entityData,
|
|
160
|
+
schemaEntityObjectRepresentation,
|
|
161
|
+
};
|
|
162
|
+
const targetMethod = this.eventActionToMethodMap_[action];
|
|
163
|
+
if (!targetMethod) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await this[targetMethod](argument);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async query(config, sharedContext = {}) {
|
|
170
|
+
await __classPrivateFieldGet(this, _PostgresProvider_isReady_, "f");
|
|
171
|
+
const { keepFilteredEntities, fields = [], filters = {}, joinFilters = {}, } = config;
|
|
172
|
+
const { take, skip, order: inputOrderBy = {} } = config.pagination ?? {};
|
|
173
|
+
const select = (0, normalize_fields_selection_1.normalizeFieldsSelection)(fields);
|
|
174
|
+
const where = (0, flatten_object_keys_1.flattenObjectKeys)(filters);
|
|
175
|
+
const joinWhere = (0, flatten_object_keys_1.flattenObjectKeys)(joinFilters);
|
|
176
|
+
const orderBy = (0, flatten_object_keys_1.flattenObjectKeys)(inputOrderBy);
|
|
177
|
+
const { manager } = sharedContext;
|
|
178
|
+
let hasPagination = false;
|
|
179
|
+
if ((0, utils_1.isDefined)(skip)) {
|
|
180
|
+
hasPagination = true;
|
|
181
|
+
}
|
|
182
|
+
const connection = manager.getConnection();
|
|
183
|
+
const qb = new utils_2.QueryBuilder({
|
|
184
|
+
schema: this.schemaObjectRepresentation_,
|
|
185
|
+
entityMap: this.schemaEntitiesMap_,
|
|
186
|
+
knex: connection.getKnex(),
|
|
187
|
+
selector: {
|
|
188
|
+
select,
|
|
189
|
+
where,
|
|
190
|
+
joinWhere,
|
|
191
|
+
},
|
|
192
|
+
options: {
|
|
193
|
+
skip,
|
|
194
|
+
take,
|
|
195
|
+
keepFilteredEntities,
|
|
196
|
+
orderBy,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
const sql = qb.buildQuery(hasPagination, !!keepFilteredEntities);
|
|
200
|
+
let resultSet = await manager.execute(sql);
|
|
201
|
+
const count = hasPagination ? +(resultSet[0]?.count ?? 0) : undefined;
|
|
202
|
+
if (keepFilteredEntities) {
|
|
203
|
+
const mainEntity = Object.keys(select)[0];
|
|
204
|
+
const ids = resultSet.map((r) => r[`${mainEntity}.id`]);
|
|
205
|
+
if (ids.length) {
|
|
206
|
+
return await this.query({
|
|
207
|
+
fields,
|
|
208
|
+
joinFilters,
|
|
209
|
+
filters: {
|
|
210
|
+
[mainEntity]: {
|
|
211
|
+
id: ids,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
pagination: undefined,
|
|
215
|
+
keepFilteredEntities: false,
|
|
216
|
+
}, sharedContext);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
data: qb.buildObjectFromResultset(resultSet),
|
|
221
|
+
metadata: hasPagination
|
|
222
|
+
? {
|
|
223
|
+
count: count,
|
|
224
|
+
skip,
|
|
225
|
+
take,
|
|
226
|
+
}
|
|
227
|
+
: undefined,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create the index entry and the index relation entry when this event is emitted.
|
|
232
|
+
* @param entity
|
|
233
|
+
* @param data
|
|
234
|
+
* @param schemaEntityObjectRepresentation
|
|
235
|
+
* @param sharedContext
|
|
236
|
+
* @protected
|
|
237
|
+
*/
|
|
238
|
+
async onCreate({ entity, data, schemaEntityObjectRepresentation, }, sharedContext = {}) {
|
|
239
|
+
const { transactionManager: em } = sharedContext;
|
|
240
|
+
const indexRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexData));
|
|
241
|
+
const indexRelationRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexRelation));
|
|
242
|
+
const { data: data_, entityProperties, parentsProperties, } = PostgresProvider.parseData(data, schemaEntityObjectRepresentation);
|
|
243
|
+
/**
|
|
244
|
+
* Loop through the data and create index entries for each entity as well as the
|
|
245
|
+
* index relation entries if the entity has parents
|
|
246
|
+
*/
|
|
247
|
+
for (const entityData of data_) {
|
|
248
|
+
/**
|
|
249
|
+
* Clean the entity data to only keep the properties that are defined in the schema
|
|
250
|
+
*/
|
|
251
|
+
const cleanedEntityData = entityProperties.reduce((acc, property) => {
|
|
252
|
+
acc[property] = entityData[property];
|
|
253
|
+
return acc;
|
|
254
|
+
}, {});
|
|
255
|
+
await indexRepository.upsert({
|
|
256
|
+
id: cleanedEntityData.id,
|
|
257
|
+
name: entity,
|
|
258
|
+
data: cleanedEntityData,
|
|
259
|
+
});
|
|
260
|
+
/**
|
|
261
|
+
* Retrieve the parents to attach it to the index entry.
|
|
262
|
+
*/
|
|
263
|
+
for (const [parentEntity, parentProperties] of Object.entries(parentsProperties)) {
|
|
264
|
+
const parentAlias = parentProperties[0].split(".")[0];
|
|
265
|
+
const parentData = entityData[parentAlias];
|
|
266
|
+
if (!parentData) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const parentDataCollection = Array.isArray(parentData)
|
|
270
|
+
? parentData
|
|
271
|
+
: [parentData];
|
|
272
|
+
for (const parentData_ of parentDataCollection) {
|
|
273
|
+
await indexRepository.upsert({
|
|
274
|
+
id: parentData_.id,
|
|
275
|
+
name: parentEntity,
|
|
276
|
+
data: parentData_,
|
|
277
|
+
});
|
|
278
|
+
const parentIndexRelationEntry = indexRelationRepository.create({
|
|
279
|
+
parent_id: parentData_.id,
|
|
280
|
+
parent_name: parentEntity,
|
|
281
|
+
child_id: cleanedEntityData.id,
|
|
282
|
+
child_name: entity,
|
|
283
|
+
pivot: `${parentEntity}-${entity}`,
|
|
284
|
+
});
|
|
285
|
+
indexRelationRepository.persist(parentIndexRelationEntry);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Update the index entry when this event is emitted.
|
|
292
|
+
* @param entity
|
|
293
|
+
* @param data
|
|
294
|
+
* @param schemaEntityObjectRepresentation
|
|
295
|
+
* @param sharedContext
|
|
296
|
+
* @protected
|
|
297
|
+
*/
|
|
298
|
+
async onUpdate({ entity, data, schemaEntityObjectRepresentation, }, sharedContext = {}) {
|
|
299
|
+
const { transactionManager: em } = sharedContext;
|
|
300
|
+
const indexRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexData));
|
|
301
|
+
const { data: data_, entityProperties } = PostgresProvider.parseData(data, schemaEntityObjectRepresentation);
|
|
302
|
+
await indexRepository.upsertMany(data_.map((entityData) => {
|
|
303
|
+
return {
|
|
304
|
+
id: entityData.id,
|
|
305
|
+
name: entity,
|
|
306
|
+
data: entityProperties.reduce((acc, property) => {
|
|
307
|
+
acc[property] = entityData[property];
|
|
308
|
+
return acc;
|
|
309
|
+
}, {}),
|
|
310
|
+
};
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Delete the index entry when this event is emitted.
|
|
315
|
+
* @param entity
|
|
316
|
+
* @param data
|
|
317
|
+
* @param schemaEntityObjectRepresentation
|
|
318
|
+
* @param sharedContext
|
|
319
|
+
* @protected
|
|
320
|
+
*/
|
|
321
|
+
async onDelete({ entity, data, schemaEntityObjectRepresentation, }, sharedContext = {}) {
|
|
322
|
+
const { transactionManager: em } = sharedContext;
|
|
323
|
+
const indexRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexData));
|
|
324
|
+
const indexRelationRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexRelation));
|
|
325
|
+
const { data: data_ } = PostgresProvider.parseData(data, schemaEntityObjectRepresentation);
|
|
326
|
+
const ids = data_.map((entityData) => entityData.id);
|
|
327
|
+
await indexRepository.nativeDelete({
|
|
328
|
+
id: { $in: ids },
|
|
329
|
+
name: entity,
|
|
330
|
+
});
|
|
331
|
+
await indexRelationRepository.nativeDelete({
|
|
332
|
+
$or: [
|
|
333
|
+
{
|
|
334
|
+
parent_id: { $in: ids },
|
|
335
|
+
parent_name: entity,
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
child_id: { $in: ids },
|
|
339
|
+
child_name: entity,
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* event emitted from the link modules to attach a link entity to its parent and child entities from the linked modules.
|
|
346
|
+
* @param entity
|
|
347
|
+
* @param data
|
|
348
|
+
* @param schemaEntityObjectRepresentation
|
|
349
|
+
* @protected
|
|
350
|
+
*/
|
|
351
|
+
async onAttach({ entity, data, schemaEntityObjectRepresentation, }, sharedContext = {}) {
|
|
352
|
+
const { transactionManager: em } = sharedContext;
|
|
353
|
+
const indexRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexData));
|
|
354
|
+
const indexRelationRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexRelation));
|
|
355
|
+
const { data: data_, entityProperties } = PostgresProvider.parseData(data, schemaEntityObjectRepresentation);
|
|
356
|
+
/**
|
|
357
|
+
* Retrieve the property that represent the foreign key related to the parent entity of the link entity.
|
|
358
|
+
* Then from the service name of the parent entity, retrieve the entity name using the linkable keys.
|
|
359
|
+
*/
|
|
360
|
+
const parentPropertyId = schemaEntityObjectRepresentation.moduleConfig.relationships[0].foreignKey;
|
|
361
|
+
const parentServiceName = schemaEntityObjectRepresentation.moduleConfig.relationships[0]
|
|
362
|
+
.serviceName;
|
|
363
|
+
const parentEntityName = this.schemaObjectRepresentation_._serviceNameModuleConfigMap[parentServiceName].linkableKeys?.[parentPropertyId];
|
|
364
|
+
if (!parentEntityName) {
|
|
365
|
+
throw new Error(`IndexModule error, unable to handle attach event for ${entity}. The parent entity name could not be found using the linkable keys from the module ${parentServiceName}.`);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Retrieve the property that represent the foreign key related to the child entity of the link entity.
|
|
369
|
+
* Then from the service name of the child entity, retrieve the entity name using the linkable keys.
|
|
370
|
+
*/
|
|
371
|
+
const childPropertyId = schemaEntityObjectRepresentation.moduleConfig.relationships[1].foreignKey;
|
|
372
|
+
const childServiceName = schemaEntityObjectRepresentation.moduleConfig.relationships[1]
|
|
373
|
+
.serviceName;
|
|
374
|
+
const childEntityName = this.schemaObjectRepresentation_._serviceNameModuleConfigMap[childServiceName].linkableKeys?.[childPropertyId];
|
|
375
|
+
if (!childEntityName) {
|
|
376
|
+
throw new Error(`IndexModule error, unable to handle attach event for ${entity}. The child entity name could not be found using the linkable keys from the module ${childServiceName}.`);
|
|
377
|
+
}
|
|
378
|
+
for (const entityData of data_) {
|
|
379
|
+
/**
|
|
380
|
+
* Clean the link entity data to only keep the properties that are defined in the schema
|
|
381
|
+
*/
|
|
382
|
+
const cleanedEntityData = entityProperties.reduce((acc, property) => {
|
|
383
|
+
acc[property] = entityData[property];
|
|
384
|
+
return acc;
|
|
385
|
+
}, {});
|
|
386
|
+
await indexRepository.upsert({
|
|
387
|
+
id: cleanedEntityData.id,
|
|
388
|
+
name: entity,
|
|
389
|
+
data: cleanedEntityData,
|
|
390
|
+
});
|
|
391
|
+
/**
|
|
392
|
+
* Create the index relation entries for the parent entity and the child entity
|
|
393
|
+
*/
|
|
394
|
+
const parentIndexRelationEntry = indexRelationRepository.create({
|
|
395
|
+
parent_id: entityData[parentPropertyId],
|
|
396
|
+
parent_name: parentEntityName,
|
|
397
|
+
child_id: cleanedEntityData.id,
|
|
398
|
+
child_name: entity,
|
|
399
|
+
pivot: `${parentEntityName}-${entity}`,
|
|
400
|
+
});
|
|
401
|
+
const childIndexRelationEntry = indexRelationRepository.create({
|
|
402
|
+
parent_id: cleanedEntityData.id,
|
|
403
|
+
parent_name: entity,
|
|
404
|
+
child_id: entityData[childPropertyId],
|
|
405
|
+
child_name: childEntityName,
|
|
406
|
+
pivot: `${entity}-${childEntityName}`,
|
|
407
|
+
});
|
|
408
|
+
indexRelationRepository.persist([
|
|
409
|
+
parentIndexRelationEntry,
|
|
410
|
+
childIndexRelationEntry,
|
|
411
|
+
]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Event emitted from the link modules to detach a link entity from its parent and child entities from the linked modules.
|
|
416
|
+
* @param entity
|
|
417
|
+
* @param data
|
|
418
|
+
* @param schemaEntityObjectRepresentation
|
|
419
|
+
* @param sharedContext
|
|
420
|
+
* @protected
|
|
421
|
+
*/
|
|
422
|
+
async onDetach({ entity, data, schemaEntityObjectRepresentation, }, sharedContext = {}) {
|
|
423
|
+
const { transactionManager: em } = sharedContext;
|
|
424
|
+
const indexRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexData));
|
|
425
|
+
const indexRelationRepository = em.getRepository((0, utils_1.toMikroORMEntity)(_models_1.IndexRelation));
|
|
426
|
+
const { data: data_ } = PostgresProvider.parseData(data, schemaEntityObjectRepresentation);
|
|
427
|
+
const ids = data_.map((entityData) => entityData.id);
|
|
428
|
+
await indexRepository.nativeDelete({
|
|
429
|
+
id: { $in: ids },
|
|
430
|
+
name: entity,
|
|
431
|
+
});
|
|
432
|
+
await indexRelationRepository.nativeDelete({
|
|
433
|
+
$or: [
|
|
434
|
+
{
|
|
435
|
+
parent_id: { $in: ids },
|
|
436
|
+
parent_name: entity,
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
child_id: { $in: ids },
|
|
440
|
+
child_name: entity,
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
exports.PostgresProvider = PostgresProvider;
|
|
447
|
+
_PostgresProvider_isReady_ = new WeakMap();
|
|
448
|
+
__decorate([
|
|
449
|
+
(0, utils_1.InjectManager)(),
|
|
450
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
451
|
+
__metadata("design:type", Function),
|
|
452
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
453
|
+
__metadata("design:returntype", Promise)
|
|
454
|
+
], PostgresProvider.prototype, "query", null);
|
|
455
|
+
__decorate([
|
|
456
|
+
(0, utils_1.InjectTransactionManager)(),
|
|
457
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
458
|
+
__metadata("design:type", Function),
|
|
459
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
460
|
+
__metadata("design:returntype", Promise)
|
|
461
|
+
], PostgresProvider.prototype, "onCreate", null);
|
|
462
|
+
__decorate([
|
|
463
|
+
(0, utils_1.InjectTransactionManager)(),
|
|
464
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
465
|
+
__metadata("design:type", Function),
|
|
466
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
467
|
+
__metadata("design:returntype", Promise)
|
|
468
|
+
], PostgresProvider.prototype, "onUpdate", null);
|
|
469
|
+
__decorate([
|
|
470
|
+
(0, utils_1.InjectTransactionManager)(),
|
|
471
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
472
|
+
__metadata("design:type", Function),
|
|
473
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
474
|
+
__metadata("design:returntype", Promise)
|
|
475
|
+
], PostgresProvider.prototype, "onDelete", null);
|
|
476
|
+
__decorate([
|
|
477
|
+
(0, utils_1.InjectTransactionManager)(),
|
|
478
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
479
|
+
__metadata("design:type", Function),
|
|
480
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
481
|
+
__metadata("design:returntype", Promise)
|
|
482
|
+
], PostgresProvider.prototype, "onAttach", null);
|
|
483
|
+
__decorate([
|
|
484
|
+
(0, utils_1.InjectTransactionManager)(),
|
|
485
|
+
__param(1, (0, utils_1.EtoContext)()),
|
|
486
|
+
__metadata("design:type", Function),
|
|
487
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
488
|
+
__metadata("design:returntype", Promise)
|
|
489
|
+
], PostgresProvider.prototype, "onDetach", null);
|
|
490
|
+
//# sourceMappingURL=postgres-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-provider.js","sourceRoot":"","sources":["../../src/services/postgres-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAM+B;AAC/B,kD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M,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;QAEpD,MAAM,eAAe,CAAC,YAAY,CAAC;YACjC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;YAChB,IAAI,EAAE,MAAM;SACb,CAAC,CAAA;QAEF,MAAM,uBAAuB,CAAC,YAAY,CAAC;YACzC,GAAG,EAAE;gBACH;oBACE,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;oBACvB,WAAW,EAAE,MAAM;iBACpB;gBACD;oBACE,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;oBACtB,UAAU,EAAE,MAAM;iBACnB;aACF;SACF,CAAC,CAAA;IACJ,CAAC;CACF;AAzpBD,4CAypBC;;AA9cO;IADL,IAAA,qBAAa,GAAE;IAGb,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;6CAgFd;AAWe;IADf,IAAA,gCAAwB,GAAE;IAaxB,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;gDAyEd;AAWe;IADf,IAAA,gCAAwB,GAAE;IAaxB,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;gDAwBd;AAWe;IADf,IAAA,gCAAwB,GAAE;IAaxB,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;gDAkCd;AAUe;IADf,IAAA,gCAAwB,GAAE;IAaxB,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;gDAoGd;AAWe;IADf,IAAA,gCAAwB,GAAE;IAaxB,WAAA,IAAA,kBAAU,GAAE,CAAA;;;;gDAkCd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/loaders/index.ts","../src/migrations/Migration20231019174230.ts","../src/migrations/Migration20241209173313.ts","../src/models/index-data.ts","../src/models/index-relation.ts","../src/models/index.ts","../src/services/index-module-service.ts","../src/services/index.ts","../src/services/postgres-provider.ts","../src/types/index.ts","../src/utils/build-config.ts","../src/utils/create-partitions.ts","../src/utils/default-schema.ts","../src/utils/flatten-object-keys.ts","../src/utils/gql-to-types.ts","../src/utils/index.ts","../src/utils/normalize-fields-selection.ts","../src/utils/query-builder.ts","../src/utils/__tests__/flatten-object-keys.spec.ts","../src/utils/__tests__/normalize-fields-selcetion.spec.ts"],"version":"5.6.2"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const schemaObjectRepresentationPropertiesToOmit: string[];
|
|
2
|
+
export type Select = {
|
|
3
|
+
[key: string]: boolean | Select | Select[];
|
|
4
|
+
};
|
|
5
|
+
export type Where = {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export type OrderBy = {
|
|
9
|
+
[path: string]: OrderBy | "ASC" | "DESC" | 1 | -1 | true | false;
|
|
10
|
+
};
|
|
11
|
+
export type QueryFormat = {
|
|
12
|
+
select: Select;
|
|
13
|
+
where?: Where;
|
|
14
|
+
joinWhere?: Where;
|
|
15
|
+
};
|
|
16
|
+
export type QueryOptions = {
|
|
17
|
+
skip?: number;
|
|
18
|
+
take?: number;
|
|
19
|
+
orderBy?: OrderBy | OrderBy[];
|
|
20
|
+
keepFilteredEntities?: boolean;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0CAA0C,UAGtD,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;CACjE,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,SAAS,CAAC,EAAE,KAAK,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,CAAA;IAC7B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaObjectRepresentationPropertiesToOmit = void 0;
|
|
4
|
+
exports.schemaObjectRepresentationPropertiesToOmit = [
|
|
5
|
+
"_schemaPropertiesMap",
|
|
6
|
+
"_serviceNameModuleConfigMap",
|
|
7
|
+
];
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,0CAA0C,GAAG;IACxD,sBAAsB;IACtB,6BAA6B;CAC9B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IndexTypes } from "@etohq/framework/types";
|
|
2
|
+
import { GraphQLUtils } from "@etohq/framework/utils";
|
|
3
|
+
export declare const CustomDirectives: {
|
|
4
|
+
Listeners: {
|
|
5
|
+
configurationPropertyName: string;
|
|
6
|
+
isRequired: boolean;
|
|
7
|
+
name: string;
|
|
8
|
+
directive: string;
|
|
9
|
+
definition: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function makeSchemaExecutable(inputSchema: string): GraphQLUtils.GraphQLSchema;
|
|
13
|
+
/**
|
|
14
|
+
* This util build an internal representation object from the provided schema.
|
|
15
|
+
* It will resolve all modules, fields, link module representation to build
|
|
16
|
+
* the appropriate representation for the index module.
|
|
17
|
+
*
|
|
18
|
+
* This representation will be used to re construct the expected output object from a search
|
|
19
|
+
* but can also be used for anything since the relation tree is available through ref.
|
|
20
|
+
*
|
|
21
|
+
* @param schema
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildSchemaObjectRepresentation(schema: any): [IndexTypes.SchemaObjectRepresentation, Record<string, any>];
|
|
24
|
+
//# sourceMappingURL=build-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-config.d.ts","sourceRoot":"","sources":["../../src/utils/build-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAIX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAgB,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGnE,eAAO,MAAM,gBAAgB;;;;;;;;CAQ5B,CAAA;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,8BAIvD;AA2pBD;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,KAAA,GACL,CAAC,UAAU,CAAC,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CA0B9D"}
|