@restura/core 0.1.0-alpha.35 → 0.1.0-alpha.36

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/dist/index.d.mts CHANGED
@@ -124,15 +124,16 @@ interface DatabaseActionData {
124
124
  queryMetadata: QueryMetadata;
125
125
  }
126
126
  interface ActionRowInsertData<T = DynamicObject> extends DatabaseActionData {
127
- insertId: number;
127
+ insertedId: number;
128
128
  insertObject: T;
129
129
  }
130
130
  interface ActionRowDeleteData<T = DynamicObject> extends DatabaseActionData {
131
+ deletedId: number;
131
132
  deletedRow: T;
132
133
  }
133
134
  interface ActionColumnChangeData<T = DynamicObject> extends DatabaseActionData {
134
135
  tableName: string;
135
- rowId: number;
136
+ changedId: number;
136
137
  newData: T;
137
138
  oldData: T;
138
139
  }
@@ -148,8 +149,10 @@ interface ActionColumnChangeFilter {
148
149
  }
149
150
  type TriggerResult = {
150
151
  table: string;
151
- insertId?: number;
152
- query: string;
152
+ insertedId?: number;
153
+ changedId?: number;
154
+ deletedId?: number;
155
+ queryMetadata: QueryMetadata;
153
156
  record: DynamicObject;
154
157
  previousRecord: DynamicObject;
155
158
  requesterId: number;
@@ -1091,6 +1094,7 @@ declare const tableDataSchema: z.ZodObject<{
1091
1094
  check: string;
1092
1095
  }>, "many">;
1093
1096
  roles: z.ZodArray<z.ZodString, "many">;
1097
+ notify: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"ALL">, z.ZodArray<z.ZodString, "many">]>>;
1094
1098
  }, "strict", z.ZodTypeAny, {
1095
1099
  name: string;
1096
1100
  roles: string[];
@@ -1126,6 +1130,7 @@ declare const tableDataSchema: z.ZodObject<{
1126
1130
  name: string;
1127
1131
  check: string;
1128
1132
  }[];
1133
+ notify?: string[] | "ALL" | undefined;
1129
1134
  }, {
1130
1135
  name: string;
1131
1136
  roles: string[];
@@ -1161,6 +1166,7 @@ declare const tableDataSchema: z.ZodObject<{
1161
1166
  name: string;
1162
1167
  check: string;
1163
1168
  }[];
1169
+ notify?: string[] | "ALL" | undefined;
1164
1170
  }>;
1165
1171
  type TableData = z.infer<typeof tableDataSchema>;
1166
1172
  declare const resturaSchema: z.ZodObject<{
@@ -1255,6 +1261,7 @@ declare const resturaSchema: z.ZodObject<{
1255
1261
  check: string;
1256
1262
  }>, "many">;
1257
1263
  roles: z.ZodArray<z.ZodString, "many">;
1264
+ notify: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"ALL">, z.ZodArray<z.ZodString, "many">]>>;
1258
1265
  }, "strict", z.ZodTypeAny, {
1259
1266
  name: string;
1260
1267
  roles: string[];
@@ -1290,6 +1297,7 @@ declare const resturaSchema: z.ZodObject<{
1290
1297
  name: string;
1291
1298
  check: string;
1292
1299
  }[];
1300
+ notify?: string[] | "ALL" | undefined;
1293
1301
  }, {
1294
1302
  name: string;
1295
1303
  roles: string[];
@@ -1325,6 +1333,7 @@ declare const resturaSchema: z.ZodObject<{
1325
1333
  name: string;
1326
1334
  check: string;
1327
1335
  }[];
1336
+ notify?: string[] | "ALL" | undefined;
1328
1337
  }>, "many">;
1329
1338
  endpoints: z.ZodArray<z.ZodObject<{
1330
1339
  name: z.ZodString;
@@ -2143,6 +2152,7 @@ declare const resturaSchema: z.ZodObject<{
2143
2152
  name: string;
2144
2153
  check: string;
2145
2154
  }[];
2155
+ notify?: string[] | "ALL" | undefined;
2146
2156
  }[];
2147
2157
  endpoints: {
2148
2158
  name: string;
@@ -2290,6 +2300,7 @@ declare const resturaSchema: z.ZodObject<{
2290
2300
  name: string;
2291
2301
  check: string;
2292
2302
  }[];
2303
+ notify?: string[] | "ALL" | undefined;
2293
2304
  }[];
2294
2305
  endpoints: {
2295
2306
  name: string;
package/dist/index.d.ts CHANGED
@@ -124,15 +124,16 @@ interface DatabaseActionData {
124
124
  queryMetadata: QueryMetadata;
125
125
  }
126
126
  interface ActionRowInsertData<T = DynamicObject> extends DatabaseActionData {
127
- insertId: number;
127
+ insertedId: number;
128
128
  insertObject: T;
129
129
  }
130
130
  interface ActionRowDeleteData<T = DynamicObject> extends DatabaseActionData {
131
+ deletedId: number;
131
132
  deletedRow: T;
132
133
  }
133
134
  interface ActionColumnChangeData<T = DynamicObject> extends DatabaseActionData {
134
135
  tableName: string;
135
- rowId: number;
136
+ changedId: number;
136
137
  newData: T;
137
138
  oldData: T;
138
139
  }
@@ -148,8 +149,10 @@ interface ActionColumnChangeFilter {
148
149
  }
149
150
  type TriggerResult = {
150
151
  table: string;
151
- insertId?: number;
152
- query: string;
152
+ insertedId?: number;
153
+ changedId?: number;
154
+ deletedId?: number;
155
+ queryMetadata: QueryMetadata;
153
156
  record: DynamicObject;
154
157
  previousRecord: DynamicObject;
155
158
  requesterId: number;
@@ -1091,6 +1094,7 @@ declare const tableDataSchema: z.ZodObject<{
1091
1094
  check: string;
1092
1095
  }>, "many">;
1093
1096
  roles: z.ZodArray<z.ZodString, "many">;
1097
+ notify: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"ALL">, z.ZodArray<z.ZodString, "many">]>>;
1094
1098
  }, "strict", z.ZodTypeAny, {
1095
1099
  name: string;
1096
1100
  roles: string[];
@@ -1126,6 +1130,7 @@ declare const tableDataSchema: z.ZodObject<{
1126
1130
  name: string;
1127
1131
  check: string;
1128
1132
  }[];
1133
+ notify?: string[] | "ALL" | undefined;
1129
1134
  }, {
1130
1135
  name: string;
1131
1136
  roles: string[];
@@ -1161,6 +1166,7 @@ declare const tableDataSchema: z.ZodObject<{
1161
1166
  name: string;
1162
1167
  check: string;
1163
1168
  }[];
1169
+ notify?: string[] | "ALL" | undefined;
1164
1170
  }>;
1165
1171
  type TableData = z.infer<typeof tableDataSchema>;
1166
1172
  declare const resturaSchema: z.ZodObject<{
@@ -1255,6 +1261,7 @@ declare const resturaSchema: z.ZodObject<{
1255
1261
  check: string;
1256
1262
  }>, "many">;
1257
1263
  roles: z.ZodArray<z.ZodString, "many">;
1264
+ notify: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"ALL">, z.ZodArray<z.ZodString, "many">]>>;
1258
1265
  }, "strict", z.ZodTypeAny, {
1259
1266
  name: string;
1260
1267
  roles: string[];
@@ -1290,6 +1297,7 @@ declare const resturaSchema: z.ZodObject<{
1290
1297
  name: string;
1291
1298
  check: string;
1292
1299
  }[];
1300
+ notify?: string[] | "ALL" | undefined;
1293
1301
  }, {
1294
1302
  name: string;
1295
1303
  roles: string[];
@@ -1325,6 +1333,7 @@ declare const resturaSchema: z.ZodObject<{
1325
1333
  name: string;
1326
1334
  check: string;
1327
1335
  }[];
1336
+ notify?: string[] | "ALL" | undefined;
1328
1337
  }>, "many">;
1329
1338
  endpoints: z.ZodArray<z.ZodObject<{
1330
1339
  name: z.ZodString;
@@ -2143,6 +2152,7 @@ declare const resturaSchema: z.ZodObject<{
2143
2152
  name: string;
2144
2153
  check: string;
2145
2154
  }[];
2155
+ notify?: string[] | "ALL" | undefined;
2146
2156
  }[];
2147
2157
  endpoints: {
2148
2158
  name: string;
@@ -2290,6 +2300,7 @@ declare const resturaSchema: z.ZodObject<{
2290
2300
  name: string;
2291
2301
  check: string;
2292
2302
  }[];
2303
+ notify?: string[] | "ALL" | undefined;
2293
2304
  }[];
2294
2305
  endpoints: {
2295
2306
  name: string;
package/dist/index.js CHANGED
@@ -176,7 +176,7 @@ var EventManager = class {
176
176
  if (!this.hasHandlersForEventType("DATABASE_ROW_INSERT", filter, triggerResult)) return;
177
177
  const insertData = {
178
178
  tableName: triggerResult.table,
179
- insertId: triggerResult.record.id,
179
+ insertedId: triggerResult.insertedId || 0,
180
180
  insertObject: triggerResult.record,
181
181
  queryMetadata: data.queryMetadata
182
182
  };
@@ -192,6 +192,7 @@ var EventManager = class {
192
192
  if (!this.hasHandlersForEventType("DATABASE_ROW_DELETE", filter, triggerResult)) return;
193
193
  const deleteData = {
194
194
  tableName: triggerResult.table,
195
+ deletedId: triggerResult.deletedId || 0,
195
196
  deletedRow: triggerResult.previousRecord,
196
197
  queryMetadata: data.queryMetadata
197
198
  };
@@ -207,7 +208,7 @@ var EventManager = class {
207
208
  if (!this.hasHandlersForEventType("DATABASE_COLUMN_UPDATE", filter, triggerResult)) return;
208
209
  const columnChangeData = {
209
210
  tableName: triggerResult.table,
210
- rowId: triggerResult.record.id,
211
+ changedId: triggerResult.changedId || 0,
211
212
  newData: triggerResult.record,
212
213
  oldData: triggerResult.previousRecord,
213
214
  queryMetadata: data.queryMetadata
@@ -551,7 +552,7 @@ var SqlUtils = class _SqlUtils {
551
552
  static convertDatabaseTypeToTypescript(type, value) {
552
553
  type = type.toLocaleLowerCase();
553
554
  if (type.startsWith("tinyint") || type.startsWith("boolean")) return "boolean";
554
- if (type.indexOf("int") > -1 || type.startsWith("decimal") || type.startsWith("double") || type.startsWith("float"))
555
+ if (type.indexOf("int") > -1 || type.startsWith("decimal") || type.startsWith("double") || type.startsWith("float") || type.indexOf("serial") > -1 || type.startsWith("decimal") || type.startsWith("real") || type.startsWith("double precision") || type.startsWith("numeric"))
555
556
  return "number";
556
557
  if (type === "json") {
557
558
  if (!value) return "object";
@@ -833,21 +834,28 @@ var ApiTree = class _ApiTree {
833
834
  return `export type Res = CustomTypes.${route.responseType}[]`;
834
835
  else return `export type Res = CustomTypes.${route.responseType}`;
835
836
  }
836
- return `export interface Res ${this.getFields(route.response)}`;
837
+ return `export interface Res ${this.getFields(route.response, route.table, route.joins)}`;
837
838
  }
838
- getFields(fields) {
839
- const nameFields = fields.map((f) => this.getNameAndType(f));
839
+ getFields(fields, routeBaseTable, joins) {
840
+ const nameFields = fields.map((f) => this.getNameAndType(f, routeBaseTable, joins));
840
841
  const nested = `{
841
842
  ${nameFields.join(";\n ")}${import_core_utils.ObjectUtils.isArrayWithData(nameFields) ? ";" : ""}
842
843
  }`;
843
844
  return nested;
844
845
  }
845
- getNameAndType(p) {
846
+ getNameAndType(p, routeBaseTable, joins) {
846
847
  let responseType = "any", isNullable = false, array = false;
847
848
  if (p.selector) {
848
849
  ({ responseType, isNullable } = this.getTypeFromTable(p.selector, p.name));
850
+ const selectorKey = p.selector.split(".")[0];
851
+ if (selectorKey !== routeBaseTable) {
852
+ const join = joins.find((j) => j.alias === selectorKey);
853
+ if (join && join.type !== "INNER") {
854
+ isNullable = true;
855
+ }
856
+ }
849
857
  } else if (p.subquery) {
850
- responseType = this.getFields(p.subquery.properties);
858
+ responseType = this.getFields(p.subquery.properties, p.subquery.table, p.subquery.joins);
851
859
  array = true;
852
860
  }
853
861
  return `${p.name}:${responseType}${array ? "[]" : ""}${isNullable ? " | null" : ""}`;
@@ -1313,7 +1321,8 @@ var tableDataSchema = import_zod3.z.object({
1313
1321
  indexes: import_zod3.z.array(indexDataSchema),
1314
1322
  foreignKeys: import_zod3.z.array(foreignKeyDataSchema),
1315
1323
  checkConstraints: import_zod3.z.array(checkConstraintDataSchema),
1316
- roles: import_zod3.z.array(import_zod3.z.string())
1324
+ roles: import_zod3.z.array(import_zod3.z.string()),
1325
+ notify: import_zod3.z.union([import_zod3.z.literal("ALL"), import_zod3.z.array(import_zod3.z.string())]).optional()
1317
1326
  }).strict();
1318
1327
  var endpointDataSchema = import_zod3.z.object({
1319
1328
  name: import_zod3.z.string(),
@@ -1986,16 +1995,8 @@ var PsqlEngine = class extends SqlEngine {
1986
1995
  });
1987
1996
  }
1988
1997
  async handleTrigger(payload, mutationType) {
1989
- const findRequesterDetailsRegex = /^--QUERY_METADATA\(\{.*\}\)/;
1990
- const match = payload.query.match(findRequesterDetailsRegex);
1991
- if (match) {
1992
- const jsonString = match[0].slice(match[0].indexOf("{"), match[0].lastIndexOf("}") + 1);
1993
- const queryMetadata = import_core_utils5.ObjectUtils.safeParse(jsonString);
1994
- const triggerFromThisInstance = queryMetadata.connectionInstanceId === this.psqlConnectionPool.instanceId;
1995
- if (!triggerFromThisInstance) {
1996
- return;
1997
- }
1998
- await eventManager_default.fireActionFromDbTrigger({ queryMetadata, mutationType }, payload);
1998
+ if (payload.queryMetadata && payload.queryMetadata.connectionInstanceId === this.psqlConnectionPool.instanceId) {
1999
+ await eventManager_default.fireActionFromDbTrigger({ queryMetadata: payload.queryMetadata, mutationType }, payload);
1999
2000
  }
2000
2001
  }
2001
2002
  async createDatabaseFromSchema(schema, connection) {
@@ -2008,9 +2009,11 @@ var PsqlEngine = class extends SqlEngine {
2008
2009
  const indexes = [];
2009
2010
  const triggers = [];
2010
2011
  for (const table of schema.database) {
2011
- triggers.push(this.createInsertTriggers(table.name));
2012
- triggers.push(this.createUpdateTrigger(table.name));
2013
- triggers.push(this.createDeleteTrigger(table.name));
2012
+ if (table.notify) {
2013
+ triggers.push(this.createInsertTriggers(table.name, table.notify));
2014
+ triggers.push(this.createUpdateTrigger(table.name, table.notify));
2015
+ triggers.push(this.createDeleteTrigger(table.name, table.notify));
2016
+ }
2014
2017
  let sql = `CREATE TABLE "${table.name}"
2015
2018
  ( `;
2016
2019
  const tableColumns = [];
@@ -2437,53 +2440,216 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
2437
2440
  }
2438
2441
  return whereClause;
2439
2442
  }
2440
- createUpdateTrigger(tableName) {
2441
- return `
2443
+ createUpdateTrigger(tableName, notify) {
2444
+ if (!notify) return "";
2445
+ if (notify === "ALL") {
2446
+ return `
2442
2447
  CREATE OR REPLACE FUNCTION notify_${tableName}_update()
2443
- RETURNS TRIGGER AS $$
2448
+ RETURNS TRIGGER AS $$
2449
+ DECLARE
2450
+ query_metadata JSON;
2444
2451
  BEGIN
2445
- PERFORM pg_notify('update', JSON_BUILD_OBJECT('table', '${tableName}', 'query', current_query(), 'record', NEW, 'previousRecord', OLD)::text);
2446
- RETURN NEW;
2452
+ SELECT INTO query_metadata
2453
+ (regexp_match(
2454
+ current_query(),
2455
+ '^--QUERY_METADATA\\(({.*})', 'n'
2456
+ ))[1]::json;
2457
+
2458
+ PERFORM pg_notify(
2459
+ 'update',
2460
+ json_build_object(
2461
+ 'table', '${tableName}',
2462
+ 'queryMetadata', query_metadata,
2463
+ 'changedId', NEW.id,
2464
+ 'record', NEW,
2465
+ 'previousRecord', OLD
2466
+ )::text
2467
+ );
2468
+ RETURN NEW;
2447
2469
  END;
2448
2470
  $$ LANGUAGE plpgsql;
2449
2471
 
2450
2472
  CREATE OR REPLACE TRIGGER ${tableName}_update
2451
- AFTER UPDATE ON "${tableName}"
2452
- FOR EACH ROW
2473
+ AFTER UPDATE ON "${tableName}"
2474
+ FOR EACH ROW
2475
+ EXECUTE FUNCTION notify_${tableName}_update();
2476
+ `;
2477
+ }
2478
+ const notifyColumnNewBuildString = notify.map((column) => `'${column}', NEW."${column}"`).join(",\n");
2479
+ const notifyColumnOldBuildString = notify.map((column) => `'${column}', OLD."${column}"`).join(",\n");
2480
+ return `
2481
+ CREATE OR REPLACE FUNCTION notify_${tableName}_update()
2482
+ RETURNS TRIGGER AS $$
2483
+ DECLARE
2484
+ query_metadata JSON;
2485
+ BEGIN
2486
+ SELECT INTO query_metadata
2487
+ (regexp_match(
2488
+ current_query(),
2489
+ '^--QUERY_METADATA\\(({.*})', 'n'
2490
+ ))[1]::json;
2491
+
2492
+ PERFORM pg_notify(
2493
+ 'update',
2494
+ json_build_object(
2495
+ 'table', '${tableName}',
2496
+ 'queryMetadata', query_metadata,
2497
+ 'changedId', NEW.id,
2498
+ 'record', json_build_object(
2499
+ ${notifyColumnNewBuildString}
2500
+ ),
2501
+ 'previousRecord', json_build_object(
2502
+ ${notifyColumnOldBuildString}
2503
+ )
2504
+ )::text
2505
+ );
2506
+ RETURN NEW;
2507
+ END;
2508
+ $$ LANGUAGE plpgsql;
2509
+
2510
+ CREATE OR REPLACE TRIGGER ${tableName}_update
2511
+ AFTER UPDATE ON "${tableName}"
2512
+ FOR EACH ROW
2453
2513
  EXECUTE FUNCTION notify_${tableName}_update();
2454
2514
  `;
2455
2515
  }
2456
- createDeleteTrigger(tableName) {
2516
+ createDeleteTrigger(tableName, notify) {
2517
+ if (!notify) return "";
2518
+ if (notify === "ALL") {
2519
+ return `
2520
+ CREATE OR REPLACE FUNCTION notify_${tableName}_delete()
2521
+ RETURNS TRIGGER AS $$
2522
+ DECLARE
2523
+ query_metadata JSON;
2524
+ BEGIN
2525
+ SELECT INTO query_metadata
2526
+ (regexp_match(
2527
+ current_query(),
2528
+ '^--QUERY_METADATA\\(({.*})', 'n'
2529
+ ))[1]::json;
2530
+
2531
+ PERFORM pg_notify(
2532
+ 'delete',
2533
+ json_build_object(
2534
+ 'table', '${tableName}',
2535
+ 'queryMetadata', query_metadata,
2536
+ 'deletedId', OLD.id,
2537
+ 'previousRecord', OLD
2538
+ )::text
2539
+ );
2540
+ RETURN NEW;
2541
+ END;
2542
+ $$ LANGUAGE plpgsql;
2543
+
2544
+ CREATE OR REPLACE TRIGGER "${tableName}_delete"
2545
+ AFTER DELETE ON "${tableName}"
2546
+ FOR EACH ROW
2547
+ EXECUTE FUNCTION notify_${tableName}_delete();
2548
+ `;
2549
+ }
2550
+ const notifyColumnOldBuildString = notify.map((column) => `'${column}', OLD."${column}"`).join(",\n");
2457
2551
  return `
2458
2552
  CREATE OR REPLACE FUNCTION notify_${tableName}_delete()
2459
- RETURNS TRIGGER AS $$
2553
+ RETURNS TRIGGER AS $$
2554
+ DECLARE
2555
+ query_metadata JSON;
2460
2556
  BEGIN
2461
- PERFORM pg_notify('delete', JSON_BUILD_OBJECT('table', '${tableName}', 'query', current_query(), 'record', NEW, 'previousRecord', OLD)::text);
2462
- RETURN NEW;
2557
+ SELECT INTO query_metadata
2558
+ (regexp_match(
2559
+ current_query(),
2560
+ '^--QUERY_METADATA\\(({.*})', 'n'
2561
+ ))[1]::json;
2562
+
2563
+ PERFORM pg_notify(
2564
+ 'delete',
2565
+ json_build_object(
2566
+ 'table', '${tableName}',
2567
+ 'queryMetadata', query_metadata,
2568
+ 'deletedId', OLD.id,
2569
+ 'previousRecord', json_build_object(
2570
+ ${notifyColumnOldBuildString}
2571
+ )
2572
+ )::text
2573
+ );
2574
+ RETURN NEW;
2463
2575
  END;
2464
2576
  $$ LANGUAGE plpgsql;
2465
2577
 
2466
2578
  CREATE OR REPLACE TRIGGER "${tableName}_delete"
2467
- AFTER DELETE ON "${tableName}"
2468
- FOR EACH ROW
2579
+ AFTER DELETE ON "${tableName}"
2580
+ FOR EACH ROW
2469
2581
  EXECUTE FUNCTION notify_${tableName}_delete();
2470
2582
  `;
2471
2583
  }
2472
- createInsertTriggers(tableName) {
2584
+ createInsertTriggers(tableName, notify) {
2585
+ if (!notify) return "";
2586
+ if (notify === "ALL") {
2587
+ return `
2588
+ CREATE OR REPLACE FUNCTION notify_${tableName}_insert()
2589
+ RETURNS TRIGGER AS $$
2590
+ DECLARE
2591
+ query_metadata JSON;
2592
+ BEGIN
2593
+ SELECT INTO query_metadata
2594
+ (regexp_match(
2595
+ current_query(),
2596
+ '^--QUERY_METADATA\\(({.*})', 'n'
2597
+ ))[1]::json;
2598
+
2599
+ PERFORM pg_notify(
2600
+ 'insert',
2601
+ json_build_object(
2602
+ 'table', '${tableName}',
2603
+ 'queryMetadata', query_metadata,
2604
+ 'insertedId', NEW.id,
2605
+ 'record', NEW
2606
+ )::text
2607
+ );
2608
+
2609
+ RETURN NEW;
2610
+ END;
2611
+ $$ LANGUAGE plpgsql;
2612
+
2613
+ CREATE OR REPLACE TRIGGER "${tableName}_insert"
2614
+ AFTER INSERT ON "${tableName}"
2615
+ FOR EACH ROW
2616
+ EXECUTE FUNCTION notify_${tableName}_insert();
2617
+ `;
2618
+ }
2619
+ const notifyColumnNewBuildString = notify.map((column) => `'${column}', NEW."${column}"`).join(",\n");
2473
2620
  return `
2474
2621
  CREATE OR REPLACE FUNCTION notify_${tableName}_insert()
2475
- RETURNS TRIGGER AS $$
2622
+ RETURNS TRIGGER AS $$
2623
+ DECLARE
2624
+ query_metadata JSON;
2476
2625
  BEGIN
2477
- PERFORM pg_notify('insert', JSON_BUILD_OBJECT('table', '${tableName}', 'query', current_query(), 'record', NEW, 'previousRecord', OLD)::text);
2478
- RETURN NEW;
2626
+ SELECT INTO query_metadata
2627
+ (regexp_match(
2628
+ current_query(),
2629
+ '^--QUERY_METADATA\\(({.*})', 'n'
2630
+ ))[1]::json;
2631
+
2632
+ PERFORM pg_notify(
2633
+ 'insert',
2634
+ json_build_object(
2635
+ 'table', '${tableName}',
2636
+ 'queryMetadata', query_metadata,
2637
+ 'insertedId', NEW.id,
2638
+ 'record', json_build_object(
2639
+ ${notifyColumnNewBuildString}
2640
+ )
2641
+ )::text
2642
+ );
2643
+
2644
+ RETURN NEW;
2479
2645
  END;
2480
2646
  $$ LANGUAGE plpgsql;
2481
2647
 
2482
- CREATE TRIGGER "${tableName}_insert"
2483
- AFTER INSERT ON "${tableName}"
2484
- FOR EACH ROW
2648
+ CREATE OR REPLACE TRIGGER "${tableName}_insert"
2649
+ AFTER INSERT ON "${tableName}"
2650
+ FOR EACH ROW
2485
2651
  EXECUTE FUNCTION notify_${tableName}_insert();
2486
- `;
2652
+ `;
2487
2653
  }
2488
2654
  schemaToPsqlType(column) {
2489
2655
  if (column.hasAutoIncrement) return "BIGSERIAL";
@@ -2493,15 +2659,6 @@ EXECUTE FUNCTION notify_${tableName}_insert();
2493
2659
  return column.type;
2494
2660
  }
2495
2661
  };
2496
- __decorateClass([
2497
- boundMethod
2498
- ], PsqlEngine.prototype, "createUpdateTrigger", 1);
2499
- __decorateClass([
2500
- boundMethod
2501
- ], PsqlEngine.prototype, "createDeleteTrigger", 1);
2502
- __decorateClass([
2503
- boundMethod
2504
- ], PsqlEngine.prototype, "createInsertTriggers", 1);
2505
2662
 
2506
2663
  // src/restura/utils/TempCache.ts
2507
2664
  var import_fs3 = __toESM(require("fs"));