Add db event emitter in twenty orm (#13167)

## Context
Add an eventEmitter instance to twenty datasources so we can emit DB
events.
Add input and output formatting to twenty orm (formatData, formatResult)
Those 2 elements simplified existing logic when we interact with the
ORM, input will be formatted by the ORM so we can directly use
field-like structure instead of column-like. The output will be
formatted, for builder queries it will be in `result.generatedMaps`
where `result.raw` preserves the previous column-like structure.

Important change: We now have an authContext that we can pass when we
get a repository, this will be used for the different events emitted in
the ORM. We also removed the caching for repositories as it was not
scaling well and not necessary imho

Note: An upcoming PR should handle the onDelete: cascade behavior where
we send DESTROY events in cascade when there is an onDelete: CASCADE on
the FK.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Weiko
2025-07-17 18:07:28 +02:00
committed by GitHub
parent 4a3139c9e0
commit 2deac9448e
79 changed files with 1061 additions and 2016 deletions

View File

@ -1,5 +1,5 @@
diff --git a/node_modules/typeorm/common/PickKeysByType.d.ts b/node_modules/typeorm/common/PickKeysByType.d.ts
index 55ad347..1a8a184 100644
diff --git a/common/PickKeysByType.d.ts b/common/PickKeysByType.d.ts
index 55ad347..4288c06 100644
--- a/common/PickKeysByType.d.ts
+++ b/common/PickKeysByType.d.ts
@@ -1,6 +1,6 @@
@ -12,3 +12,35 @@ index 55ad347..1a8a184 100644
+export type PickKeysByType<T, U> = string & {
+ [P in keyof T]: Exclude<T[P], null> extends U ? P : never;
+}[keyof T];
diff --git a/query-builder/result/DeleteResult.d.ts b/query-builder/result/DeleteResult.d.ts
index 9c98830..d0578f9 100644
--- a/query-builder/result/DeleteResult.d.ts
+++ b/query-builder/result/DeleteResult.d.ts
@@ -13,4 +13,9 @@ export declare class DeleteResult {
* Not all drivers support this
*/
affected?: number | null;
+ /**
+ * Generated values returned by a database.
+ * Has entity-like structure (not just column database name and values).
+ */
+ generatedMaps: ObjectLiteral[];
}
diff --git a/query-builder/result/DeleteResult.js b/query-builder/result/DeleteResult.js
index 6519c11..0bb344a 100644
--- a/query-builder/result/DeleteResult.js
+++ b/query-builder/result/DeleteResult.js
@@ -5,6 +5,13 @@ exports.DeleteResult = void 0;
* Result object returned by DeleteQueryBuilder execution.
*/
class DeleteResult {
+ constructor() {
+ /**
+ * Generated values returned by a database.
+ * Has entity-like structure (not just column database name and values).
+ */
+ this.generatedMaps = [];
+ }
static from(queryResult) {
const result = new this();
result.raw = queryResult.records;