@event-driven-io/emmett-postgresql 0.42.0-rc.2 → 0.43.0-alpha.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.
package/dist/index.cjs CHANGED
@@ -44,14 +44,11 @@ var projectionsTable = {
44
44
  var readLastMessageGlobalPosition = async (execute, options) => {
45
45
  const result = await _dumbo.singleOrNull.call(void 0,
46
46
  execute.query(
47
- _dumbo.sql.call(void 0,
48
- `SELECT global_position
49
- FROM ${messagesTable.name}
50
- WHERE partition = %L AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
47
+ _dumbo.SQL`SELECT global_position
48
+ FROM ${_dumbo.SQL.identifier(messagesTable.name)}
49
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.partition]), () => ( defaultTag))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
51
50
  ORDER BY transaction_id, global_position
52
- LIMIT 1`,
53
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.partition]), () => ( defaultTag))
54
- )
51
+ LIMIT 1`
55
52
  )
56
53
  );
57
54
  return {
@@ -774,14 +771,12 @@ var readMessagesBatch = async (execute, options) => {
774
771
  const limitCondition = "batchSize" in options ? `LIMIT ${options.batchSize}` : "";
775
772
  const messages = await _dumbo.mapRows.call(void 0,
776
773
  execute.query(
777
- _dumbo.sql.call(void 0,
778
- `SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
779
- FROM ${messagesTable.name}
780
- WHERE partition = %L AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${fromCondition} ${toCondition}
774
+ _dumbo.SQL`
775
+ SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
776
+ FROM ${_dumbo.SQL.identifier(messagesTable.name)}
777
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.partition]), () => ( defaultTag))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
781
778
  ORDER BY transaction_id, global_position
782
- ${limitCondition}`,
783
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.partition]), () => ( defaultTag))
784
- )
779
+ ${_dumbo.SQL.plain(limitCondition)}`
785
780
  ),
786
781
  (row) => {
787
782
  const rawEvent = {
@@ -888,8 +883,7 @@ var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
888
883
 
889
884
  // src/eventStore/consumers/postgreSQLProcessor.ts
890
885
 
891
-
892
-
886
+ require('@event-driven-io/dumbo/pg');
893
887
  require('pg');
894
888
 
895
889
  // src/eventStore/projections/locks/tryAcquireProcessorLock.ts
@@ -900,27 +894,25 @@ require('pg');
900
894
 
901
895
  // src/eventStore/schema/createFunctionIfDoesNotExist.ts
902
896
 
903
- var createFunctionIfDoesNotExistSQL = (functionName, functionDefinition) => _dumbo.rawSql.call(void 0,
904
- `
897
+ var createFunctionIfDoesNotExistSQL = (functionName, functionDefinition) => _dumbo.SQL`
905
898
  DO $$
906
899
  BEGIN
907
- IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname = '${functionName}') THEN
900
+ IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname = '${_dumbo.SQL.plain(functionName)}') THEN
908
901
  ${functionDefinition}
909
902
  END IF;
910
903
  END $$;
911
- `
912
- );
904
+ `;
913
905
 
914
906
  // src/eventStore/schema/processors/processorsLocks.ts
915
907
  var tryAcquireProcessorLockSQL = createFunctionIfDoesNotExistSQL(
916
908
  "emt_try_acquire_processor_lock",
917
- `
909
+ _dumbo.SQL`
918
910
  CREATE OR REPLACE FUNCTION emt_try_acquire_processor_lock(
919
911
  p_lock_key BIGINT,
920
912
  p_processor_id TEXT,
921
913
  p_version INT,
922
- p_partition TEXT DEFAULT '${defaultTag}',
923
- p_processor_instance_id TEXT DEFAULT '${unknownTag}',
914
+ p_partition TEXT DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
915
+ p_processor_instance_id TEXT DEFAULT '${_dumbo.SQL.plain(unknownTag)}',
924
916
  p_projection_name TEXT DEFAULT NULL,
925
917
  p_projection_type VARCHAR(1) DEFAULT NULL,
926
918
  p_projection_kind TEXT DEFAULT NULL,
@@ -935,7 +927,7 @@ BEGIN
935
927
  SELECT pg_try_advisory_xact_lock(p_lock_key) AS lock_acquired
936
928
  ),
937
929
  ownership_check AS (
938
- INSERT INTO ${processorsTable.name} (
930
+ INSERT INTO ${_dumbo.SQL.plain(processorsTable.name)} (
939
931
  processor_id,
940
932
  partition,
941
933
  version,
@@ -946,20 +938,20 @@ BEGIN
946
938
  created_at,
947
939
  last_updated
948
940
  )
949
- SELECT p_processor_id, p_partition, p_version, p_processor_instance_id, 'running', '${bigInt.toNormalizedString(0n)}', '0'::xid8, now(), now()
941
+ SELECT p_processor_id, p_partition, p_version, p_processor_instance_id, 'running', '${_dumbo.SQL.plain(bigInt.toNormalizedString(0n))}', '0'::xid8, now(), now()
950
942
  WHERE (SELECT lock_acquired FROM lock_check) = true
951
943
  ON CONFLICT (processor_id, partition, version) DO UPDATE
952
944
  SET processor_instance_id = p_processor_instance_id,
953
945
  status = 'running',
954
946
  last_updated = now()
955
- WHERE ${processorsTable.name}.processor_instance_id = p_processor_instance_id
956
- OR ${processorsTable.name}.processor_instance_id = '${unknownTag}'
957
- OR ${processorsTable.name}.status = 'stopped'
958
- OR ${processorsTable.name}.last_updated < now() - (p_lock_timeout_seconds || ' seconds')::interval
947
+ WHERE ${_dumbo.SQL.plain(processorsTable.name)}.processor_instance_id = p_processor_instance_id
948
+ OR ${_dumbo.SQL.plain(processorsTable.name)}.processor_instance_id = '${_dumbo.SQL.plain(unknownTag)}'
949
+ OR ${_dumbo.SQL.plain(processorsTable.name)}.status = 'stopped'
950
+ OR ${_dumbo.SQL.plain(processorsTable.name)}.last_updated < now() - (p_lock_timeout_seconds || ' seconds')::interval
959
951
  RETURNING last_processed_checkpoint
960
952
  ),
961
953
  projection_status AS (
962
- INSERT INTO ${projectionsTable.name} (
954
+ INSERT INTO ${_dumbo.SQL.plain(projectionsTable.name)} (
963
955
  name,
964
956
  partition,
965
957
  version,
@@ -984,13 +976,13 @@ $emt_try_acquire_processor_lock$;
984
976
  );
985
977
  var releaseProcessorLockSQL = createFunctionIfDoesNotExistSQL(
986
978
  "emt_release_processor_lock",
987
- `
979
+ _dumbo.SQL`
988
980
  CREATE OR REPLACE FUNCTION emt_release_processor_lock(
989
981
  p_lock_key BIGINT,
990
982
  p_processor_id TEXT,
991
983
  p_partition TEXT,
992
984
  p_version INT,
993
- p_processor_instance_id TEXT DEFAULT '${unknownTag}',
985
+ p_processor_instance_id TEXT DEFAULT '${_dumbo.SQL.plain(unknownTag)}',
994
986
  p_projection_name TEXT DEFAULT NULL
995
987
  )
996
988
  RETURNS BOOLEAN
@@ -1000,7 +992,7 @@ DECLARE
1000
992
  v_rows_updated INT;
1001
993
  BEGIN
1002
994
  IF p_projection_name IS NOT NULL THEN
1003
- UPDATE ${projectionsTable.name}
995
+ UPDATE ${_dumbo.SQL.plain(projectionsTable.name)}
1004
996
  SET status = 'active',
1005
997
  last_updated = now()
1006
998
  WHERE partition = p_partition
@@ -1008,9 +1000,9 @@ BEGIN
1008
1000
  AND version = p_version;
1009
1001
  END IF;
1010
1002
 
1011
- UPDATE ${processorsTable.name}
1003
+ UPDATE ${_dumbo.SQL.plain(processorsTable.name)}
1012
1004
  SET status = 'stopped',
1013
- processor_instance_id = '${unknownTag}',
1005
+ processor_instance_id = '${_dumbo.SQL.plain(unknownTag)}',
1014
1006
  last_updated = now()
1015
1007
  WHERE processor_id = p_processor_id
1016
1008
  AND partition = p_partition
@@ -1026,27 +1018,27 @@ END;
1026
1018
  $emt_release_processor_lock$;
1027
1019
  `
1028
1020
  );
1029
- var callTryAcquireProcessorLock = (params) => _dumbo.sql.call(void 0,
1030
- `SELECT * FROM emt_try_acquire_processor_lock(%s::BIGINT, %L, %s, %L, %L, %L, %L, %L, %s);`,
1031
- params.lockKey,
1032
- params.processorId,
1033
- params.version,
1034
- params.partition,
1035
- params.processorInstanceId,
1036
- params.projectionName,
1037
- params.projectionType,
1038
- params.projectionKind,
1039
- params.lockTimeoutSeconds
1040
- );
1041
- var callReleaseProcessorLock = (params) => _dumbo.sql.call(void 0,
1042
- `SELECT emt_release_processor_lock(%s::BIGINT, %L, %L, %s, %L, %L) as result;`,
1043
- params.lockKey,
1044
- params.processorId,
1045
- params.partition,
1046
- params.version,
1047
- params.processorInstanceId,
1048
- params.projectionName
1049
- );
1021
+ var callTryAcquireProcessorLock = (params) => _dumbo.SQL`
1022
+ SELECT * FROM emt_try_acquire_processor_lock(
1023
+ ${params.lockKey},
1024
+ ${params.processorId},
1025
+ ${params.version},
1026
+ ${params.partition},
1027
+ ${params.processorInstanceId},
1028
+ ${params.projectionName},
1029
+ ${params.projectionType},
1030
+ ${params.projectionKind},
1031
+ ${params.lockTimeoutSeconds}
1032
+ );
1033
+ `;
1034
+ var callReleaseProcessorLock = (params) => _dumbo.SQL`SELECT emt_release_processor_lock(
1035
+ ${params.lockKey},
1036
+ ${params.processorId},
1037
+ ${params.partition},
1038
+ ${params.version},
1039
+ ${params.processorInstanceId},
1040
+ ${params.projectionName}
1041
+ ) as result;`;
1050
1042
 
1051
1043
  // src/eventStore/projections/locks/tryAcquireProcessorLock.ts
1052
1044
  var PROCESSOR_LOCK_DEFAULT_TIMEOUT_SECONDS = 300;
@@ -1105,7 +1097,7 @@ var releaseProcessorLock = async (execute, options) => {
1105
1097
 
1106
1098
  var tryAcquireProjectionLockSQL = createFunctionIfDoesNotExistSQL(
1107
1099
  "emt_try_acquire_projection_lock",
1108
- `
1100
+ _dumbo.SQL`
1109
1101
  CREATE OR REPLACE FUNCTION emt_try_acquire_projection_lock(
1110
1102
  p_lock_key BIGINT,
1111
1103
  p_partition TEXT,
@@ -1122,7 +1114,7 @@ BEGIN
1122
1114
  ),
1123
1115
  status_check AS (
1124
1116
  SELECT status = 'active' AS is_active
1125
- FROM ${projectionsTable.name}
1117
+ FROM ${_dumbo.SQL.plain(projectionsTable.name)}
1126
1118
  WHERE partition = p_partition AND name = p_name AND version = p_version
1127
1119
  )
1128
1120
  SELECT
@@ -1132,13 +1124,7 @@ END;
1132
1124
  $emt_try_acquire_projection_lock$;
1133
1125
  `
1134
1126
  );
1135
- var callTryAcquireProjectionLock = (params) => _dumbo.sql.call(void 0,
1136
- `SELECT * FROM emt_try_acquire_projection_lock(%s::BIGINT, %L, %L, %s);`,
1137
- params.lockKey,
1138
- params.partition,
1139
- params.name,
1140
- params.version
1141
- );
1127
+ var callTryAcquireProjectionLock = (params) => _dumbo.SQL`SELECT * FROM emt_try_acquire_projection_lock(${params.lockKey}, ${params.partition}, ${params.name}, ${params.version});`;
1142
1128
 
1143
1129
  // src/eventStore/projections/locks/tryAcquireProjectionLock.ts
1144
1130
  var tryAcquireProjectionLock = async (execute, {
@@ -1247,7 +1233,7 @@ var toProcessorLockKey = ({
1247
1233
 
1248
1234
  var registerProjectionSQL = createFunctionIfDoesNotExistSQL(
1249
1235
  "emt_register_projection",
1250
- `
1236
+ _dumbo.SQL`
1251
1237
  CREATE OR REPLACE FUNCTION emt_register_projection(
1252
1238
  p_lock_key BIGINT,
1253
1239
  p_name TEXT,
@@ -1268,7 +1254,7 @@ BEGIN
1268
1254
  SELECT pg_try_advisory_xact_lock(p_lock_key) AS lock_acquired
1269
1255
  ),
1270
1256
  upsert_result AS (
1271
- INSERT INTO ${projectionsTable.name} (
1257
+ INSERT INTO ${_dumbo.SQL.identifier(projectionsTable.name)} (
1272
1258
  name, partition, version, type, kind, status, definition, created_at, last_updated
1273
1259
  )
1274
1260
  SELECT p_name, p_partition, p_version, p_type, p_kind, p_status, p_definition, now(), now()
@@ -1287,7 +1273,7 @@ $emt_register_projection$;
1287
1273
  );
1288
1274
  var activateProjectionSQL = createFunctionIfDoesNotExistSQL(
1289
1275
  "emt_activate_projection",
1290
- `
1276
+ _dumbo.SQL`
1291
1277
  CREATE OR REPLACE FUNCTION emt_activate_projection(
1292
1278
  p_lock_key BIGINT,
1293
1279
  p_name TEXT,
@@ -1304,7 +1290,7 @@ BEGIN
1304
1290
  SELECT pg_try_advisory_xact_lock(p_lock_key) AS lock_acquired
1305
1291
  ),
1306
1292
  update_result AS (
1307
- UPDATE ${projectionsTable.name}
1293
+ UPDATE ${_dumbo.SQL.identifier(projectionsTable.name)}
1308
1294
  SET status = 'active',
1309
1295
  last_updated = now()
1310
1296
  WHERE name = p_name
@@ -1322,7 +1308,7 @@ $emt_activate_projection$;
1322
1308
  );
1323
1309
  var deactivateProjectionSQL = createFunctionIfDoesNotExistSQL(
1324
1310
  "emt_deactivate_projection",
1325
- `
1311
+ _dumbo.SQL`
1326
1312
  CREATE OR REPLACE FUNCTION emt_deactivate_projection(
1327
1313
  p_lock_key BIGINT,
1328
1314
  p_name TEXT,
@@ -1339,7 +1325,7 @@ BEGIN
1339
1325
  SELECT pg_try_advisory_xact_lock(p_lock_key) AS lock_acquired
1340
1326
  ),
1341
1327
  update_result AS (
1342
- UPDATE ${projectionsTable.name}
1328
+ UPDATE ${_dumbo.SQL.identifier(projectionsTable.name)}
1343
1329
  SET status = 'inactive',
1344
1330
  last_updated = now()
1345
1331
  WHERE name = p_name
@@ -1355,31 +1341,11 @@ END;
1355
1341
  $emt_deactivate_projection$;
1356
1342
  `
1357
1343
  );
1358
- var callRegisterProjection = (params) => _dumbo.sql.call(void 0,
1359
- `SELECT emt_register_projection(%s, %L, %L, %s, %L, %L, %L, %L) AS registered`,
1360
- params.lockKey,
1361
- params.name,
1362
- params.partition,
1363
- params.version,
1364
- params.type,
1365
- params.kind,
1366
- params.status,
1367
- params.definition
1368
- );
1369
- var callActivateProjection = (params) => _dumbo.sql.call(void 0,
1370
- `SELECT emt_activate_projection(%s, %L, %L, %s) AS activated`,
1371
- params.lockKey,
1372
- params.name,
1373
- params.partition,
1374
- params.version
1375
- );
1376
- var callDeactivateProjection = (params) => _dumbo.sql.call(void 0,
1377
- `SELECT emt_deactivate_projection(%s, %L, %L, %s) AS deactivated`,
1378
- params.lockKey,
1379
- params.name,
1380
- params.partition,
1381
- params.version
1382
- );
1344
+ var callRegisterProjection = (params) => _dumbo.SQL`
1345
+ SELECT emt_register_projection(${params.lockKey}, ${params.name}, ${params.partition}, ${params.version}, ${params.type}, ${params.kind}, ${params.status}, ${params.definition}) AS registered
1346
+ `;
1347
+ var callActivateProjection = (params) => _dumbo.SQL`SELECT emt_activate_projection(${params.lockKey}, ${params.name}, ${params.partition}, ${params.version}) AS activated`;
1348
+ var callDeactivateProjection = (params) => _dumbo.SQL`SELECT emt_deactivate_projection(${params.lockKey}, ${params.name}, ${params.partition}, ${params.version}) AS deactivated`;
1383
1349
 
1384
1350
  // src/eventStore/projections/management/projectionManagement.ts
1385
1351
  var registerProjection = async (execute, options) => {
@@ -1458,14 +1424,9 @@ var readProjectionInfo = async (execute, {
1458
1424
  }) => {
1459
1425
  const row = await _dumbo.singleOrNull.call(void 0,
1460
1426
  execute.query(
1461
- _dumbo.sql.call(void 0,
1462
- `SELECT name, version, type, kind, status, definition, created_at, last_updated
1463
- FROM ${projectionsTable.name}
1464
- WHERE name = %L AND partition = %L AND version = %s`,
1465
- name,
1466
- partition,
1467
- version
1468
- )
1427
+ _dumbo.SQL`SELECT name, version, type, kind, status, definition, created_at, last_updated
1428
+ FROM ${_dumbo.SQL.identifier(projectionsTable.name)}
1429
+ WHERE name = ${name} AND partition = ${partition} AND version = ${version}`
1469
1430
  )
1470
1431
  );
1471
1432
  return row ? {
@@ -1489,6 +1450,7 @@ var readProjectionInfo = async (execute, {
1489
1450
 
1490
1451
 
1491
1452
  var _pongo = require('@event-driven-io/pongo');
1453
+ var _pg = require('@event-driven-io/pongo/pg');
1492
1454
  var pongoProjection = ({
1493
1455
  name,
1494
1456
  kind,
@@ -1507,7 +1469,9 @@ var pongoProjection = ({
1507
1469
  const {
1508
1470
  connection: { connectionString, client, pool }
1509
1471
  } = context;
1510
- const pongo = _pongo.pongoClient.call(void 0, connectionString, {
1472
+ const pongo = _pongo.pongoClient.call(void 0, {
1473
+ connectionString,
1474
+ driver: _pg.pgDriver,
1511
1475
  connectionOptions: { client, pool }
1512
1476
  });
1513
1477
  try {
@@ -1523,7 +1487,9 @@ var pongoProjection = ({
1523
1487
  const {
1524
1488
  connection: { connectionString, client, pool }
1525
1489
  } = context;
1526
- const pongo = _pongo.pongoClient.call(void 0, connectionString, {
1490
+ const pongo = _pongo.pongoClient.call(void 0, {
1491
+ connectionString,
1492
+ driver: _pg.pgDriver,
1527
1493
  connectionOptions: { client, pool }
1528
1494
  });
1529
1495
  try {
@@ -1566,7 +1532,9 @@ var pongoMultiStreamProjection = (options) => {
1566
1532
  const {
1567
1533
  connection: { connectionString, client, pool }
1568
1534
  } = context;
1569
- const pongo = _pongo.pongoClient.call(void 0, connectionString, {
1535
+ const pongo = _pongo.pongoClient.call(void 0, {
1536
+ connectionString,
1537
+ driver: _pg.pgDriver,
1570
1538
  connectionOptions: { client, pool }
1571
1539
  });
1572
1540
  try {
@@ -1582,7 +1550,9 @@ var pongoMultiStreamProjection = (options) => {
1582
1550
  const {
1583
1551
  connection: { connectionString, client, pool }
1584
1552
  } = context;
1585
- const pongo = _pongo.pongoClient.call(void 0, connectionString, {
1553
+ const pongo = _pongo.pongoClient.call(void 0, {
1554
+ connectionString,
1555
+ driver: _pg.pgDriver,
1586
1556
  connectionOptions: { client, pool }
1587
1557
  });
1588
1558
  try {
@@ -1609,11 +1579,14 @@ var pongoSingleStreamProjection = (options) => {
1609
1579
 
1610
1580
 
1611
1581
 
1582
+
1612
1583
  var withCollection = (handle, options) => {
1613
1584
  const { pool, connectionString, inDatabase, inCollection } = options;
1614
1585
  return pool.withConnection(async (connection) => {
1615
- const pongo = _pongo.pongoClient.call(void 0, connectionString, {
1616
- connectionOptions: { connection }
1586
+ const pongo = _pongo.pongoClient.call(void 0, {
1587
+ connectionString,
1588
+ connectionOptions: { connection },
1589
+ driver: _pg.pgDriver
1617
1590
  });
1618
1591
  try {
1619
1592
  const collection = pongo.db(inDatabase).collection(inCollection);
@@ -1746,28 +1719,31 @@ var expectPongoDocuments = {
1746
1719
 
1747
1720
 
1748
1721
 
1722
+
1749
1723
  // src/eventStore/postgreSQLEventStore.ts
1750
1724
 
1751
1725
 
1752
1726
 
1753
1727
 
1754
1728
 
1755
- // src/eventStore/schema/index.ts
1756
1729
 
1757
1730
 
1758
1731
 
1759
1732
 
1733
+ // src/eventStore/schema/index.ts
1760
1734
 
1761
1735
 
1762
- // src/eventStore/schema/appendToStream.ts
1763
1736
 
1764
1737
 
1765
1738
 
1766
1739
 
1740
+ // src/eventStore/schema/appendToStream.ts
1741
+
1742
+
1767
1743
 
1768
1744
  var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1769
1745
  "emt_append_to_stream",
1770
- `CREATE OR REPLACE FUNCTION emt_append_to_stream(
1746
+ _dumbo.SQL`CREATE OR REPLACE FUNCTION emt_append_to_stream(
1771
1747
  v_message_ids text[],
1772
1748
  v_messages_data jsonb[],
1773
1749
  v_messages_metadata jsonb[],
@@ -1797,7 +1773,7 @@ var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1797
1773
  IF v_expected_stream_position IS NULL THEN
1798
1774
  SELECT COALESCE(
1799
1775
  (SELECT stream_position
1800
- FROM ${streamsTable.name}
1776
+ FROM ${_dumbo.SQL.identifier(streamsTable.name)}
1801
1777
  WHERE stream_id = v_stream_id
1802
1778
  AND partition = v_partition
1803
1779
  AND is_archived = FALSE
@@ -1809,12 +1785,12 @@ var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1809
1785
  v_next_stream_position := v_expected_stream_position + array_upper(v_messages_data, 1);
1810
1786
 
1811
1787
  IF v_expected_stream_position = 0 THEN
1812
- INSERT INTO ${streamsTable.name}
1788
+ INSERT INTO ${_dumbo.SQL.identifier(streamsTable.name)}
1813
1789
  (stream_id, stream_position, partition, stream_type, stream_metadata, is_archived)
1814
1790
  VALUES
1815
1791
  (v_stream_id, v_next_stream_position, v_partition, v_stream_type, '{}', FALSE);
1816
1792
  ELSE
1817
- UPDATE ${streamsTable.name} as s
1793
+ UPDATE ${_dumbo.SQL.identifier(streamsTable.name)} as s
1818
1794
  SET stream_position = v_next_stream_position
1819
1795
  WHERE stream_id = v_stream_id AND stream_position = v_expected_stream_position AND partition = v_partition AND is_archived = FALSE;
1820
1796
 
@@ -1842,7 +1818,7 @@ var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1842
1818
  ) AS message
1843
1819
  ),
1844
1820
  all_messages_insert AS (
1845
- INSERT INTO ${messagesTable.name}
1821
+ INSERT INTO ${_dumbo.SQL.identifier(messagesTable.name)}
1846
1822
  (stream_id, stream_position, partition, message_data, message_metadata, message_schema_version, message_type, message_kind, message_id, transaction_id)
1847
1823
  SELECT
1848
1824
  v_stream_id, ev.stream_position, v_partition, ev.message_data, ev.message_metadata, ev.schema_version, ev.message_type, ev.message_kind, ev.message_id, v_transaction_id
@@ -1859,30 +1835,18 @@ var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1859
1835
  $emt_append_to_stream$;
1860
1836
  `
1861
1837
  );
1862
- var callAppendToStream = (params) => _dumbo.sql.call(void 0,
1863
- `SELECT * FROM emt_append_to_stream(
1864
- ARRAY[%s]::text[],
1865
- ARRAY[%s]::jsonb[],
1866
- ARRAY[%s]::jsonb[],
1867
- ARRAY[%s]::text[],
1868
- ARRAY[%s]::text[],
1869
- ARRAY[%s]::text[],
1870
- %L::text,
1871
- %L::text,
1872
- %s::bigint,
1873
- %L::text
1874
- )`,
1875
- params.messageIds,
1876
- params.messagesData,
1877
- params.messagesMetadata,
1878
- params.schemaVersions,
1879
- params.messageTypes,
1880
- params.messageKinds,
1881
- params.streamId,
1882
- params.streamType,
1883
- params.expectedStreamPosition,
1884
- params.partition
1885
- );
1838
+ var callAppendToStream = (params) => _dumbo.SQL`SELECT * FROM emt_append_to_stream(
1839
+ ${params.messageIds},
1840
+ ${params.messagesData},
1841
+ ${params.messagesMetadata},
1842
+ ${params.schemaVersions},
1843
+ ${params.messageTypes},
1844
+ ${params.messageKinds},
1845
+ ${params.streamId}::text,
1846
+ ${params.streamType}::text,
1847
+ ${params.expectedStreamPosition},
1848
+ ${params.partition}::text
1849
+ )`;
1886
1850
  var appendToStream = (pool, streamName, streamType, messages, options) => pool.withTransaction(async (transaction) => {
1887
1851
  const { execute } = transaction;
1888
1852
  if (messages.length === 0)
@@ -1959,29 +1923,25 @@ var isOptimisticConcurrencyError = (error) => error instanceof Error && "code" i
1959
1923
  var appendEventsRaw = (execute, streamId, streamType, messages, options) => _dumbo.single.call(void 0,
1960
1924
  execute.command(
1961
1925
  callAppendToStream({
1962
- messageIds: messages.map((e) => _dumbo.sql.call(void 0, "%L", e.metadata.messageId)).join(","),
1963
- messagesData: messages.map((e) => _dumbo.sql.call(void 0, "%L", JSONParser.stringify(e.data))).join(","),
1926
+ messageIds: messages.map((e) => e.metadata.messageId),
1927
+ messagesData: messages.map((e) => e.data),
1964
1928
  messagesMetadata: messages.map((e) => {
1965
1929
  const { messageId: _messageId, ...rawMetadata } = e.metadata;
1966
- return _dumbo.sql.call(void 0, "%L", JSONParser.stringify(rawMetadata));
1967
- }).join(","),
1968
- schemaVersions: messages.map(() => `'1'`).join(","),
1969
- messageTypes: messages.map((e) => _dumbo.sql.call(void 0, "%L", e.type)).join(","),
1970
- messageKinds: messages.map((e) => _dumbo.sql.call(void 0, "%L", e.kind === "Event" ? "E" : "C")).join(","),
1930
+ return rawMetadata;
1931
+ }),
1932
+ schemaVersions: messages.map(() => `'1'`),
1933
+ messageTypes: messages.map((e) => e.type),
1934
+ messageKinds: messages.map((e) => e.kind === "Event" ? "E" : "C"),
1971
1935
  streamId,
1972
1936
  streamType,
1973
- expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _50 => _50.expectedStreamVersion, 'optionalAccess', _51 => _51.toString, 'call', _52 => _52()]), () => ( "NULL")),
1974
- partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _53 => _53.partition]), () => ( defaultTag))
1937
+ expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _50 => _50.expectedStreamVersion]), () => ( null)),
1938
+ partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.partition]), () => ( defaultTag))
1975
1939
  })
1976
1940
  )
1977
1941
  );
1978
1942
 
1979
1943
  // src/eventStore/schema/migrations/0_38_7/0_38_7.migration.ts
1980
1944
 
1981
-
1982
-
1983
-
1984
-
1985
1945
  var dropFutureConceptModuleAndTenantFunctions = _dumbo.SQL`
1986
1946
  DO $$
1987
1947
  BEGIN
@@ -2026,7 +1986,7 @@ var dropOldAppendToSQLWithoutGlobalPositions = _dumbo.SQL`
2026
1986
  END IF;
2027
1987
  END $$;
2028
1988
  `;
2029
- var migrationFromEventsToMessagesSQL = _dumbo.rawSql.call(void 0, `
1989
+ var migrationFromEventsToMessagesSQL = _dumbo.SQL`
2030
1990
  DO $$
2031
1991
  DECLARE
2032
1992
  partition_record RECORD;
@@ -2072,7 +2032,7 @@ BEGIN
2072
2032
  SET DEFAULT nextval('emt_global_message_position');
2073
2033
  END IF;
2074
2034
  END IF;
2075
- END $$;`);
2035
+ END $$;`;
2076
2036
  var migration_0_38_7_and_older = _dumbo.sqlMigration.call(void 0,
2077
2037
  "emt:postgresql:eventstore:0.38.7:migrate-events-to-messages",
2078
2038
  [
@@ -2413,10 +2373,7 @@ $$ LANGUAGE plpgsql;
2413
2373
 
2414
2374
  // src/eventStore/schema/migrations/0_42_0/0_42_0.migration.ts
2415
2375
 
2416
-
2417
-
2418
-
2419
- var migration_0_42_0_FromSubscriptionsToProcessorsSQL = _dumbo.rawSql.call(void 0, `
2376
+ var migration_0_42_0_FromSubscriptionsToProcessorsSQL = _dumbo.SQL`
2420
2377
  DO $$
2421
2378
  BEGIN
2422
2379
  IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'emt_subscriptions') THEN
@@ -2473,7 +2430,7 @@ BEGIN
2473
2430
  END;
2474
2431
  $fnpar$ LANGUAGE plpgsql;
2475
2432
 
2476
- PERFORM emt_add_partition('${defaultTag}');
2433
+ PERFORM emt_add_partition('${_dumbo.SQL.plain(defaultTag)}');
2477
2434
 
2478
2435
  -- 3. Copy data from old table to new table
2479
2436
  INSERT INTO "emt_processors"
@@ -2589,7 +2546,7 @@ BEGIN
2589
2546
  p_position TEXT,
2590
2547
  p_check_position TEXT,
2591
2548
  p_transaction_id xid8,
2592
- p_partition TEXT DEFAULT '${defaultTag}',
2549
+ p_partition TEXT DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
2593
2550
  p_processor_instance_id TEXT DEFAULT 'emt:unknown'
2594
2551
  ) RETURNS INT AS $fn2$
2595
2552
  DECLARE
@@ -2671,12 +2628,12 @@ BEGIN
2671
2628
  $fn2$ LANGUAGE plpgsql;
2672
2629
  END IF;
2673
2630
  END $$;
2674
- `);
2631
+ `;
2675
2632
  var migration_0_42_0_FromSubscriptionsToProcessors = _dumbo.sqlMigration.call(void 0,
2676
2633
  "emt:postgresql:eventstore:0.42.0:from-subscriptions-to-processors",
2677
2634
  [migration_0_42_0_FromSubscriptionsToProcessorsSQL]
2678
2635
  );
2679
- var migration_0_42_0_2_AddProcessorProjectionFunctionsSQL = _dumbo.rawSql.call(void 0, `
2636
+ var migration_0_42_0_2_AddProcessorProjectionFunctionsSQL = _dumbo.SQL`
2680
2637
  DO $$
2681
2638
  BEGIN
2682
2639
  IF EXISTS (
@@ -2724,7 +2681,7 @@ CREATE OR REPLACE FUNCTION emt_try_acquire_processor_lock(
2724
2681
  p_lock_key BIGINT,
2725
2682
  p_processor_id TEXT,
2726
2683
  p_version INT,
2727
- p_partition TEXT DEFAULT '${defaultTag}',
2684
+ p_partition TEXT DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
2728
2685
  p_processor_instance_id TEXT DEFAULT 'emt:unknown',
2729
2686
  p_projection_name TEXT DEFAULT NULL,
2730
2687
  p_projection_type VARCHAR(1) DEFAULT NULL,
@@ -2948,7 +2905,7 @@ BEGIN
2948
2905
  RETURN v_result;
2949
2906
  END;
2950
2907
  $emt_deactivate_projection$;
2951
- `);
2908
+ `;
2952
2909
  var migration_0_42_0_2_AddProcessorProjectionFunctions = _dumbo.sqlMigration.call(void 0,
2953
2910
  "emt:postgresql:eventstore:0.42.0-2:add-processor-projection-functions",
2954
2911
  [migration_0_42_0_2_AddProcessorProjectionFunctionsSQL]
@@ -3496,15 +3453,15 @@ $emt_deactivate_projection$;
3496
3453
 
3497
3454
  var storeSubscriptionCheckpointSQL = createFunctionIfDoesNotExistSQL(
3498
3455
  "store_processor_checkpoint",
3499
- `
3456
+ _dumbo.SQL`
3500
3457
  CREATE OR REPLACE FUNCTION store_processor_checkpoint(
3501
3458
  p_processor_id TEXT,
3502
3459
  p_version BIGINT,
3503
3460
  p_position TEXT,
3504
3461
  p_check_position TEXT,
3505
3462
  p_transaction_id xid8,
3506
- p_partition TEXT DEFAULT '${defaultTag}',
3507
- p_processor_instance_id TEXT DEFAULT '${unknownTag}'
3463
+ p_partition TEXT DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3464
+ p_processor_instance_id TEXT DEFAULT '${_dumbo.SQL.plain(unknownTag)}'
3508
3465
  ) RETURNS INT AS $spc$
3509
3466
  DECLARE
3510
3467
  current_position TEXT;
@@ -3512,7 +3469,7 @@ BEGIN
3512
3469
  -- Handle the case when p_check_position is provided
3513
3470
  IF p_check_position IS NOT NULL THEN
3514
3471
  -- Try to update if the position matches p_check_position
3515
- UPDATE "${processorsTable.name}"
3472
+ UPDATE "${_dumbo.SQL.plain(processorsTable.name)}"
3516
3473
  SET
3517
3474
  "last_processed_checkpoint" = p_position,
3518
3475
  "last_processed_transaction_id" = p_transaction_id,
@@ -3528,7 +3485,7 @@ BEGIN
3528
3485
 
3529
3486
  -- Retrieve the current position
3530
3487
  SELECT "last_processed_checkpoint" INTO current_position
3531
- FROM "${processorsTable.name}"
3488
+ FROM "${_dumbo.SQL.plain(processorsTable.name)}"
3532
3489
  WHERE "processor_id" = p_processor_id
3533
3490
  AND "partition" = p_partition
3534
3491
  AND "version" = p_version;
@@ -3545,13 +3502,13 @@ BEGIN
3545
3502
 
3546
3503
  -- Handle the case when p_check_position is NULL: Insert if not exists
3547
3504
  BEGIN
3548
- INSERT INTO "${processorsTable.name}"("processor_id", "version", "last_processed_checkpoint", "partition", "last_processed_transaction_id", "created_at", "last_updated")
3505
+ INSERT INTO "${_dumbo.SQL.plain(processorsTable.name)}"("processor_id", "version", "last_processed_checkpoint", "partition", "last_processed_transaction_id", "created_at", "last_updated")
3549
3506
  VALUES (p_processor_id, p_version, p_position, p_partition, p_transaction_id, now(), now());
3550
3507
  RETURN 1; -- Successfully inserted
3551
3508
  EXCEPTION WHEN unique_violation THEN
3552
3509
  -- If insertion failed, it means the row already exists
3553
3510
  SELECT "last_processed_checkpoint" INTO current_position
3554
- FROM "${processorsTable.name}"
3511
+ FROM "${_dumbo.SQL.plain(processorsTable.name)}"
3555
3512
  WHERE "processor_id" = p_processor_id
3556
3513
  AND "partition" = p_partition
3557
3514
  AND "version" = p_version;
@@ -3568,15 +3525,16 @@ END;
3568
3525
  $spc$ LANGUAGE plpgsql;
3569
3526
  `
3570
3527
  );
3571
- var callStoreProcessorCheckpoint = (params) => _dumbo.sql.call(void 0,
3572
- `SELECT store_processor_checkpoint(%L, %s, %L, %L, pg_current_xact_id(), %L, %L) as result;`,
3573
- params.processorId,
3574
- params.version,
3575
- params.position,
3576
- params.checkPosition,
3577
- params.partition,
3578
- params.processorInstanceId
3579
- );
3528
+ var callStoreProcessorCheckpoint = (params) => _dumbo.SQL`
3529
+ SELECT store_processor_checkpoint(
3530
+ ${params.processorId},
3531
+ ${params.version},
3532
+ ${params.position},
3533
+ ${params.checkPosition},
3534
+ pg_current_xact_id(),
3535
+ ${params.partition},
3536
+ ${params.processorInstanceId}
3537
+ ) as result;`;
3580
3538
  var storeProcessorCheckpoint = async (execute, options) => {
3581
3539
  try {
3582
3540
  const { result } = await _dumbo.single.call(void 0,
@@ -3610,26 +3568,26 @@ var storeProcessorCheckpoint = async (execute, options) => {
3610
3568
 
3611
3569
 
3612
3570
 
3613
- var migration_0_43_0_cleanupLegacySubscriptionSQL = _dumbo.rawSql.call(void 0, `
3571
+ var migration_0_43_0_cleanupLegacySubscriptionSQL = _dumbo.SQL`
3614
3572
  DO $$
3615
3573
  BEGIN
3616
3574
  IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'emt_subscriptions') THEN
3617
3575
  -- Restore clean emt_add_partition (remove creation of emt_subscriptions partitions)
3618
3576
  CREATE OR REPLACE FUNCTION emt_add_partition(partition_name TEXT) RETURNS void AS $fnpar$
3619
3577
  BEGIN
3620
- PERFORM emt_add_table_partition('${messagesTable.name}', partition_name);
3621
- PERFORM emt_add_table_partition('${streamsTable.name}', partition_name);
3578
+ PERFORM emt_add_table_partition('${_dumbo.SQL.plain(messagesTable.name)}', partition_name);
3579
+ PERFORM emt_add_table_partition('${_dumbo.SQL.plain(streamsTable.name)}', partition_name);
3622
3580
 
3623
3581
  EXECUTE format('
3624
3582
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3625
3583
  FOR VALUES IN (%L);',
3626
- emt_sanitize_name('${processorsTable.name}' || '_' || partition_name), '${processorsTable.name}', partition_name
3584
+ emt_sanitize_name('${_dumbo.SQL.plain(processorsTable.name)}' || '_' || partition_name), '${_dumbo.SQL.plain(processorsTable.name)}', partition_name
3627
3585
  );
3628
3586
 
3629
3587
  EXECUTE format('
3630
3588
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3631
3589
  FOR VALUES IN (%L);',
3632
- emt_sanitize_name('${projectionsTable.name}' || '_' || partition_name), '${projectionsTable.name}', partition_name
3590
+ emt_sanitize_name('${_dumbo.SQL.plain(projectionsTable.name)}' || '_' || partition_name), '${_dumbo.SQL.plain(projectionsTable.name)}', partition_name
3633
3591
  );
3634
3592
  END;
3635
3593
  $fnpar$ LANGUAGE plpgsql;
@@ -3647,7 +3605,7 @@ IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'emt_subscriptions') THEN
3647
3605
  p_position TEXT,
3648
3606
  p_check_position TEXT,
3649
3607
  p_transaction_id xid8,
3650
- p_partition TEXT DEFAULT '${defaultTag}',
3608
+ p_partition TEXT DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3651
3609
  p_processor_instance_id TEXT DEFAULT 'emt:unknown'
3652
3610
  ) RETURNS INT AS $fn$
3653
3611
  DECLARE
@@ -3704,7 +3662,7 @@ IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'emt_subscriptions') THEN
3704
3662
  $fn$ LANGUAGE plpgsql;
3705
3663
  END IF;
3706
3664
  END $$;
3707
- `);
3665
+ `;
3708
3666
  var migration_0_43_0_cleanupLegacySubscription = _dumbo.sqlMigration.call(void 0, "emt:postgresql:eventstore:0.43.0:cleanup-legacy-subscription", [
3709
3667
  migration_0_43_0_cleanupLegacySubscriptionSQL
3710
3668
  ]);
@@ -3720,11 +3678,11 @@ var cleanupLegacySubscriptionTables = async (connectionString) => {
3720
3678
  };
3721
3679
 
3722
3680
  // src/eventStore/schema/tables.ts
3723
- var streamsTableSQL = _dumbo.rawSql.call(void 0,
3724
- `CREATE TABLE IF NOT EXISTS ${streamsTable.name}(
3681
+ var streamsTableSQL = _dumbo.SQL`
3682
+ CREATE TABLE IF NOT EXISTS ${_dumbo.SQL.identifier(streamsTable.name)}(
3725
3683
  stream_id TEXT NOT NULL,
3726
3684
  stream_position BIGINT NOT NULL,
3727
- partition TEXT NOT NULL DEFAULT '${defaultTag}',
3685
+ partition TEXT NOT NULL DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3728
3686
  stream_type TEXT NOT NULL,
3729
3687
  stream_metadata JSONB NOT NULL,
3730
3688
  is_archived BOOLEAN NOT NULL DEFAULT FALSE,
@@ -3732,14 +3690,12 @@ var streamsTableSQL = _dumbo.rawSql.call(void 0,
3732
3690
  ) PARTITION BY LIST (partition);
3733
3691
 
3734
3692
  CREATE UNIQUE INDEX IF NOT EXISTS idx_streams_unique
3735
- ON ${streamsTable.name}(stream_id, partition, is_archived)
3736
- INCLUDE (stream_position);`
3737
- );
3738
- var messagesTableSQL = _dumbo.rawSql.call(void 0,
3739
- `
3693
+ ON ${_dumbo.SQL.identifier(streamsTable.name)}(stream_id, partition, is_archived)
3694
+ INCLUDE (stream_position);`;
3695
+ var messagesTableSQL = _dumbo.SQL`
3740
3696
  CREATE SEQUENCE IF NOT EXISTS emt_global_message_position;
3741
3697
 
3742
- CREATE TABLE IF NOT EXISTS ${messagesTable.name}(
3698
+ CREATE TABLE IF NOT EXISTS ${_dumbo.SQL.identifier(messagesTable.name)}(
3743
3699
  stream_position BIGINT NOT NULL,
3744
3700
  global_position BIGINT DEFAULT nextval('emt_global_message_position'),
3745
3701
  transaction_id XID8 NOT NULL,
@@ -3747,38 +3703,34 @@ var messagesTableSQL = _dumbo.rawSql.call(void 0,
3747
3703
  is_archived BOOLEAN NOT NULL DEFAULT FALSE,
3748
3704
  message_kind VARCHAR(1) NOT NULL DEFAULT 'E',
3749
3705
  stream_id TEXT NOT NULL,
3750
- partition TEXT NOT NULL DEFAULT '${defaultTag}',
3706
+ partition TEXT NOT NULL DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3751
3707
  message_schema_version TEXT NOT NULL,
3752
3708
  message_id TEXT NOT NULL,
3753
3709
  message_type TEXT NOT NULL,
3754
3710
  message_data JSONB NOT NULL,
3755
3711
  message_metadata JSONB NOT NULL,
3756
3712
  PRIMARY KEY (stream_id, stream_position, partition, is_archived)
3757
- ) PARTITION BY LIST (partition);`
3758
- );
3759
- var processorsTableSQL = _dumbo.rawSql.call(void 0,
3760
- `
3761
- CREATE TABLE IF NOT EXISTS ${processorsTable.name}(
3713
+ ) PARTITION BY LIST (partition);`;
3714
+ var processorsTableSQL = _dumbo.SQL`
3715
+ CREATE TABLE IF NOT EXISTS ${_dumbo.SQL.identifier(processorsTable.name)}(
3762
3716
  last_processed_transaction_id XID8 NOT NULL,
3763
3717
  version INT NOT NULL DEFAULT 1,
3764
3718
  processor_id TEXT NOT NULL,
3765
- partition TEXT NOT NULL DEFAULT '${defaultTag}',
3719
+ partition TEXT NOT NULL DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3766
3720
  status TEXT NOT NULL DEFAULT 'stopped',
3767
3721
  last_processed_checkpoint TEXT NOT NULL,
3768
- processor_instance_id TEXT DEFAULT '${unknownTag}',
3722
+ processor_instance_id TEXT DEFAULT '${_dumbo.SQL.plain(unknownTag)}',
3769
3723
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
3770
3724
  last_updated TIMESTAMPTZ NOT NULL DEFAULT now(),
3771
3725
  PRIMARY KEY (processor_id, partition, version)
3772
3726
  ) PARTITION BY LIST (partition);
3773
- `
3774
- );
3775
- var projectionsTableSQL = _dumbo.rawSql.call(void 0,
3776
- `
3777
- CREATE TABLE IF NOT EXISTS ${projectionsTable.name}(
3727
+ `;
3728
+ var projectionsTableSQL = _dumbo.SQL`
3729
+ CREATE TABLE IF NOT EXISTS ${_dumbo.SQL.identifier(projectionsTable.name)}(
3778
3730
  version INT NOT NULL DEFAULT 1,
3779
3731
  type VARCHAR(1) NOT NULL,
3780
3732
  name TEXT NOT NULL,
3781
- partition TEXT NOT NULL DEFAULT '${defaultTag}',
3733
+ partition TEXT NOT NULL DEFAULT '${_dumbo.SQL.plain(defaultTag)}',
3782
3734
  kind TEXT NOT NULL,
3783
3735
  status TEXT NOT NULL,
3784
3736
  definition JSONB NOT NULL DEFAULT '{}'::jsonb,
@@ -3786,11 +3738,10 @@ var projectionsTableSQL = _dumbo.rawSql.call(void 0,
3786
3738
  last_updated TIMESTAMPTZ NOT NULL DEFAULT now(),
3787
3739
  PRIMARY KEY (name, partition, version)
3788
3740
  ) PARTITION BY LIST (partition);
3789
- `
3790
- );
3741
+ `;
3791
3742
  var sanitizeNameSQL = createFunctionIfDoesNotExistSQL(
3792
3743
  "emt_sanitize_name",
3793
- `CREATE OR REPLACE FUNCTION emt_sanitize_name(input_name TEXT) RETURNS TEXT AS $emt_sanitize_name$
3744
+ _dumbo.SQL`CREATE OR REPLACE FUNCTION emt_sanitize_name(input_name TEXT) RETURNS TEXT AS $emt_sanitize_name$
3794
3745
  BEGIN
3795
3746
  RETURN REGEXP_REPLACE(input_name, '[^a-zA-Z0-9_]', '_', 'g');
3796
3747
  END;
@@ -3798,7 +3749,7 @@ var sanitizeNameSQL = createFunctionIfDoesNotExistSQL(
3798
3749
  );
3799
3750
  var addTablePartitions = createFunctionIfDoesNotExistSQL(
3800
3751
  "emt_add_table_partition",
3801
- `
3752
+ _dumbo.SQL`
3802
3753
  CREATE OR REPLACE FUNCTION emt_add_table_partition(tableName TEXT, partition_name TEXT) RETURNS void AS $emt_add_table_partition$
3803
3754
  DECLARE
3804
3755
  v_main_partiton_name TEXT;
@@ -3833,236 +3784,221 @@ var addTablePartitions = createFunctionIfDoesNotExistSQL(
3833
3784
  );
3834
3785
  var addPartitionSQL = createFunctionIfDoesNotExistSQL(
3835
3786
  "emt_add_partition",
3836
- `
3787
+ _dumbo.SQL`
3837
3788
  CREATE OR REPLACE FUNCTION emt_add_partition(partition_name TEXT) RETURNS void AS $emt_add_partition$
3838
3789
  BEGIN
3839
- PERFORM emt_add_table_partition('${messagesTable.name}', partition_name);
3840
- PERFORM emt_add_table_partition('${streamsTable.name}', partition_name);
3790
+ PERFORM emt_add_table_partition('${_dumbo.SQL.plain(messagesTable.name)}', partition_name);
3791
+ PERFORM emt_add_table_partition('${_dumbo.SQL.plain(streamsTable.name)}', partition_name);
3841
3792
 
3842
3793
  EXECUTE format('
3843
3794
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3844
3795
  FOR VALUES IN (%L);',
3845
- emt_sanitize_name('${processorsTable.name}' || '_' || partition_name), '${processorsTable.name}', partition_name
3796
+ emt_sanitize_name('${_dumbo.SQL.plain(processorsTable.name)}' || '_' || partition_name), '${_dumbo.SQL.plain(processorsTable.name)}', partition_name
3846
3797
  );
3847
3798
 
3848
3799
  EXECUTE format('
3849
3800
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3850
3801
  FOR VALUES IN (%L);',
3851
- emt_sanitize_name('${projectionsTable.name}' || '_' || partition_name), '${projectionsTable.name}', partition_name
3802
+ emt_sanitize_name('${_dumbo.SQL.plain(projectionsTable.name)}' || '_' || partition_name), '${_dumbo.SQL.plain(projectionsTable.name)}', partition_name
3852
3803
  );
3853
3804
  END;
3854
3805
  $emt_add_partition$ LANGUAGE plpgsql;`
3855
3806
  );
3856
- var addModuleSQL = _dumbo.rawSql.call(void 0,
3857
- `
3807
+ var addModuleSQL = _dumbo.SQL`
3858
3808
  CREATE OR REPLACE FUNCTION add_module(new_module TEXT) RETURNS void AS $$
3859
3809
  BEGIN
3860
- -- For ${messagesTable.name} table
3810
+ -- For ${_dumbo.SQL.plain(messagesTable.name)} table
3861
3811
  EXECUTE format('
3862
3812
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3863
3813
  FOR VALUES IN (emt_sanitize_name(%L || ''__'' || %L)) PARTITION BY LIST (is_archived);',
3864
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || '${globalTag}'), '${messagesTable.name}', new_module, '${globalTag}'
3814
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}'), '${_dumbo.SQL.plain(messagesTable.name)}', new_module, '${_dumbo.SQL.plain(globalTag)}'
3865
3815
  );
3866
3816
 
3867
3817
  EXECUTE format('
3868
3818
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3869
3819
  FOR VALUES IN (FALSE);',
3870
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || '${globalTag}' || '_active'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || '${globalTag}')
3820
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}' || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}')
3871
3821
  );
3872
3822
 
3873
3823
  EXECUTE format('
3874
3824
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3875
3825
  FOR VALUES IN (TRUE);',
3876
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || '${globalTag}' || '_archived'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || '${globalTag}')
3826
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}' || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}')
3877
3827
  );
3878
3828
 
3879
- -- For ${streamsTable.name} table
3829
+ -- For ${_dumbo.SQL.plain(streamsTable.name)} table
3880
3830
  EXECUTE format('
3881
3831
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3882
3832
  FOR VALUES IN (emt_sanitize_name(%L || ''__'' || %L)) PARTITION BY LIST (is_archived);',
3883
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || '${globalTag}'), '${streamsTable.name}', new_module, '${globalTag}'
3833
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}'), '${_dumbo.SQL.plain(streamsTable.name)}', new_module, '${_dumbo.SQL.plain(globalTag)}'
3884
3834
  );
3885
3835
 
3886
3836
  EXECUTE format('
3887
3837
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3888
3838
  FOR VALUES IN (FALSE);',
3889
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || '${globalTag}' || '_active'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || '${globalTag}')
3839
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}' || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}')
3890
3840
  );
3891
3841
 
3892
3842
  EXECUTE format('
3893
3843
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3894
3844
  FOR VALUES IN (TRUE);',
3895
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || '${globalTag}' || '_archived'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || '${globalTag}')
3845
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}' || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || '${_dumbo.SQL.plain(globalTag)}')
3896
3846
  );
3897
3847
  END;
3898
3848
  $$ LANGUAGE plpgsql;
3899
- `
3900
- );
3901
- var addTenantSQL = _dumbo.rawSql.call(void 0,
3902
- `
3849
+ `;
3850
+ var addTenantSQL = _dumbo.SQL`
3903
3851
  CREATE OR REPLACE FUNCTION add_tenant(new_module TEXT, new_tenant TEXT) RETURNS void AS $$
3904
3852
  BEGIN
3905
- -- For ${messagesTable.name} table
3853
+ -- For ${_dumbo.SQL.plain(messagesTable.name)} table
3906
3854
  EXECUTE format('
3907
3855
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3908
3856
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
3909
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || new_tenant), '${messagesTable.name}', new_module, new_tenant
3857
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || new_tenant), '${_dumbo.SQL.plain(messagesTable.name)}', new_module, new_tenant
3910
3858
  );
3911
3859
 
3912
3860
  EXECUTE format('
3913
3861
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3914
3862
  FOR VALUES IN (FALSE);',
3915
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || new_tenant || '_active'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || new_tenant)
3863
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || new_tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || new_tenant)
3916
3864
  );
3917
3865
 
3918
3866
  EXECUTE format('
3919
3867
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3920
3868
  FOR VALUES IN (TRUE);',
3921
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || new_tenant || '_archived'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || new_tenant)
3869
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || new_tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || new_tenant)
3922
3870
  );
3923
3871
 
3924
- -- For ${streamsTable.name} table
3872
+ -- For ${_dumbo.SQL.plain(streamsTable.name)} table
3925
3873
  EXECUTE format('
3926
3874
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3927
3875
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
3928
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || new_tenant), '${streamsTable.name}', new_module, new_tenant
3876
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || new_tenant), '${_dumbo.SQL.plain(streamsTable.name)}', new_module, new_tenant
3929
3877
  );
3930
3878
 
3931
3879
  EXECUTE format('
3932
3880
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3933
3881
  FOR VALUES IN (FALSE);',
3934
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || new_tenant || '_active'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || new_tenant)
3882
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || new_tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || new_tenant)
3935
3883
  );
3936
3884
 
3937
3885
  EXECUTE format('
3938
3886
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3939
3887
  FOR VALUES IN (TRUE);',
3940
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || new_tenant || '_archived'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || new_tenant)
3888
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || new_tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || new_tenant)
3941
3889
  );
3942
3890
  END;
3943
3891
  $$ LANGUAGE plpgsql;
3944
- `
3945
- );
3946
- var addModuleForAllTenantsSQL = _dumbo.rawSql.call(void 0,
3947
- `
3892
+ `;
3893
+ var addModuleForAllTenantsSQL = _dumbo.SQL`
3948
3894
  CREATE OR REPLACE FUNCTION add_module_for_all_tenants(new_module TEXT) RETURNS void AS $$
3949
3895
  DECLARE
3950
3896
  tenant_record RECORD;
3951
3897
  BEGIN
3952
3898
  PERFORM add_module(new_module);
3953
3899
 
3954
- FOR tenant_record IN SELECT DISTINCT tenant FROM ${messagesTable.name}
3900
+ FOR tenant_record IN SELECT DISTINCT tenant FROM ${_dumbo.SQL.plain(messagesTable.name)}
3955
3901
  LOOP
3956
- -- For ${messagesTable.name} table
3902
+ -- For ${_dumbo.SQL.plain(messagesTable.name)} table
3957
3903
  EXECUTE format('
3958
3904
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3959
3905
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
3960
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || tenant_record.tenant), '${messagesTable.name}', new_module, tenant_record.tenant
3906
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || tenant_record.tenant), '${_dumbo.SQL.plain(messagesTable.name)}', new_module, tenant_record.tenant
3961
3907
  );
3962
3908
 
3963
3909
  EXECUTE format('
3964
3910
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3965
3911
  FOR VALUES IN (FALSE);',
3966
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || tenant_record.tenant || '_active'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || tenant_record.tenant)
3912
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || tenant_record.tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || tenant_record.tenant)
3967
3913
  );
3968
3914
 
3969
3915
  EXECUTE format('
3970
3916
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3971
3917
  FOR VALUES IN (TRUE);',
3972
- emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || tenant_record.tenant || '_archived'), emt_sanitize_name('${messagesTable.name}_' || new_module || '__' || tenant_record.tenant)
3918
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || tenant_record.tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || new_module || '__' || tenant_record.tenant)
3973
3919
  );
3974
3920
 
3975
- -- For ${streamsTable.name} table
3921
+ -- For ${_dumbo.SQL.plain(streamsTable.name)} table
3976
3922
  EXECUTE format('
3977
3923
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
3978
3924
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
3979
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || tenant_record.tenant), '${streamsTable.name}', new_module, tenant_record.tenant
3925
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || tenant_record.tenant), '${_dumbo.SQL.plain(streamsTable.name)}', new_module, tenant_record.tenant
3980
3926
  );
3981
3927
 
3982
3928
  EXECUTE format('
3983
3929
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
3984
3930
  FOR VALUES IN (FALSE);',
3985
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || tenant_record.tenant || '_active'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || tenant_record.tenant)
3931
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || tenant_record.tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || tenant_record.tenant)
3986
3932
  );
3987
3933
 
3988
3934
  EXECUTE format('
3989
3935
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
3990
3936
  FOR VALUES IN (TRUE);',
3991
- emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || tenant_record.tenant || '_archived'), emt_sanitize_name('${streamsTable.name}_' || new_module || '__' || tenant_record.tenant)
3937
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || tenant_record.tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || new_module || '__' || tenant_record.tenant)
3992
3938
  );
3993
3939
  END LOOP;
3994
3940
  END;
3995
3941
  $$ LANGUAGE plpgsql;
3996
- `
3997
- );
3998
- var addTenantForAllModulesSQL = _dumbo.rawSql.call(void 0,
3999
- `
3942
+ `;
3943
+ var addTenantForAllModulesSQL = _dumbo.SQL`
4000
3944
  CREATE OR REPLACE FUNCTION add_tenant_for_all_modules(new_tenant TEXT) RETURNS void AS $$
4001
3945
  DECLARE
4002
3946
  module_record RECORD;
4003
3947
  BEGIN
4004
- FOR module_record IN SELECT DISTINCT partitionname FROM pg_partman.part_config WHERE parent_table = '${messagesTable.name}'
3948
+ FOR module_record IN SELECT DISTINCT partitionname FROM pg_partman.part_config WHERE parent_table = '${_dumbo.SQL.plain(messagesTable.name)}'
4005
3949
  LOOP
4006
- -- For ${messagesTable.name} table
3950
+ -- For ${_dumbo.SQL.plain(messagesTable.name)} table
4007
3951
  EXECUTE format('
4008
3952
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
4009
3953
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
4010
- emt_sanitize_name('${messagesTable.name}_' || module_record.partitionname || '__' || new_tenant), '${messagesTable.name}', module_record.partitionname, new_tenant
3954
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || module_record.partitionname || '__' || new_tenant), '${_dumbo.SQL.plain(messagesTable.name)}', module_record.partitionname, new_tenant
4011
3955
  );
4012
3956
 
4013
3957
  EXECUTE format('
4014
3958
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
4015
3959
  FOR VALUES IN (FALSE);',
4016
- emt_sanitize_name('${messagesTable.name}_' || module_record.partitionname || '__' || new_tenant || '_active'), emt_sanitize_name('${messagesTable.name}_' || module_record.partitionname || '__' || new_tenant)
3960
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || module_record.partitionname || '__' || new_tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || module_record.partitionname || '__' || new_tenant)
4017
3961
  );
4018
3962
 
4019
3963
  EXECUTE format('
4020
3964
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
4021
3965
  FOR VALUES IN (TRUE);',
4022
- emt_sanitize_name('${messagesTable.name}_' || module_record.partitionname || '__' || new_tenant || '_archived'), emt_sanitize_name('${messagesTable.name}_' || module_record.partitionname || '__' || new_tenant)
3966
+ emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || module_record.partitionname || '__' || new_tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(messagesTable.name)}_' || module_record.partitionname || '__' || new_tenant)
4023
3967
  );
4024
3968
 
4025
- -- For ${streamsTable.name} table
3969
+ -- For ${_dumbo.SQL.plain(streamsTable.name)} table
4026
3970
  EXECUTE format('
4027
3971
  CREATE TABLE IF NOT EXISTS %I PARTITION OF %I
4028
3972
  FOR VALUES IN (emt_sanitize_name(''%s__%s'')) PARTITION BY LIST (is_archived);',
4029
- emt_sanitize_name('${streamsTable.name}_' || module_record.partitionname || '__' || new_tenant), '${streamsTable.name}', module_record.partitionname, new_tenant
3973
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || module_record.partitionname || '__' || new_tenant), '${_dumbo.SQL.plain(streamsTable.name)}', module_record.partitionname, new_tenant
4030
3974
  );
4031
3975
 
4032
3976
  EXECUTE format('
4033
3977
  CREATE TABLE IF NOT EXISTS %I_active PARTITION OF %I
4034
3978
  FOR VALUES IN (FALSE);',
4035
- emt_sanitize_name('${streamsTable.name}_' || module_record.partitionname || '__' || new_tenant || '_active'), emt_sanitize_name('${streamsTable.name}_' || module_record.partitionname || '__' || new_tenant)
3979
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || module_record.partitionname || '__' || new_tenant || '_active'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || module_record.partitionname || '__' || new_tenant)
4036
3980
  );
4037
3981
 
4038
3982
  EXECUTE format('
4039
3983
  CREATE TABLE IF NOT EXISTS %I_archived PARTITION OF %I
4040
3984
  FOR VALUES IN (TRUE);',
4041
- emt_sanitize_name('${streamsTable.name}_' || module_record.partitionname || '__' || new_tenant || '_archived'), emt_sanitize_name('${streamsTable.name}_' || module_record.partitionname || '__' || new_tenant)
3985
+ emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || module_record.partitionname || '__' || new_tenant || '_archived'), emt_sanitize_name('${_dumbo.SQL.plain(streamsTable.name)}_' || module_record.partitionname || '__' || new_tenant)
4042
3986
  );
4043
3987
  END LOOP;
4044
3988
  END;
4045
3989
  $$ LANGUAGE plpgsql;
4046
- `
4047
- );
4048
- var addDefaultPartitionSQL = _dumbo.rawSql.call(void 0,
4049
- `SELECT emt_add_partition('${defaultTag}');`
4050
- );
3990
+ `;
3991
+ var addDefaultPartitionSQL = _dumbo.SQL`SELECT emt_add_partition('${_dumbo.SQL.plain(defaultTag)}');`;
4051
3992
 
4052
3993
  // src/eventStore/schema/readProcessorCheckpoint.ts
4053
3994
 
4054
3995
  var readProcessorCheckpoint = async (execute, options) => {
4055
3996
  const result = await _dumbo.singleOrNull.call(void 0,
4056
3997
  execute.query(
4057
- _dumbo.sql.call(void 0,
4058
- `SELECT last_processed_checkpoint
4059
- FROM ${processorsTable.name}
4060
- WHERE partition = %L AND processor_id = %L AND version = %s
4061
- LIMIT 1`,
4062
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.partition]), () => ( defaultTag)),
4063
- options.processorId,
4064
- _nullishCoalesce(options.version, () => ( 1))
4065
- )
3998
+ _dumbo.SQL`SELECT last_processed_checkpoint
3999
+ FROM ${_dumbo.SQL.identifier(processorsTable.name)}
4000
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.partition]), () => ( defaultTag))} AND processor_id = ${options.processorId} AND version = ${_nullishCoalesce(options.version, () => ( 1))}
4001
+ LIMIT 1`
4066
4002
  )
4067
4003
  );
4068
4004
  return {
@@ -4073,21 +4009,17 @@ var readProcessorCheckpoint = async (execute, options) => {
4073
4009
  // src/eventStore/schema/readStream.ts
4074
4010
 
4075
4011
  var readStream = async (execute, streamId, options) => {
4076
- const fromCondition = _optionalChain([options, 'optionalAccess', _55 => _55.from]) ? `AND stream_position >= ${options.from}` : "";
4012
+ const fromCondition = _optionalChain([options, 'optionalAccess', _53 => _53.from]) ? `AND stream_position >= ${options.from}` : "";
4077
4013
  const to = Number(
4078
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _56 => _56.to]), () => ( (_optionalChain([options, 'optionalAccess', _57 => _57.maxCount]) ? (_nullishCoalesce(options.from, () => ( 0n))) + options.maxCount : NaN)))
4014
+ _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.to]), () => ( (_optionalChain([options, 'optionalAccess', _55 => _55.maxCount]) ? (_nullishCoalesce(options.from, () => ( 0n))) + options.maxCount : NaN)))
4079
4015
  );
4080
4016
  const toCondition = !isNaN(to) ? `AND stream_position <= ${to}` : "";
4081
4017
  const events = await _dumbo.mapRows.call(void 0,
4082
4018
  execute.query(
4083
- _dumbo.sql.call(void 0,
4084
- `SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
4085
- FROM ${messagesTable.name}
4086
- WHERE stream_id = %L AND partition = %L AND is_archived = FALSE ${fromCondition} ${toCondition}
4087
- ORDER BY stream_position ASC`,
4088
- streamId,
4089
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _58 => _58.partition]), () => ( defaultTag))
4090
- )
4019
+ _dumbo.SQL`SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
4020
+ FROM ${_dumbo.SQL.identifier(messagesTable.name)}
4021
+ WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _56 => _56.partition]), () => ( defaultTag))} AND is_archived = FALSE ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
4022
+ ORDER BY stream_position ASC`
4091
4023
  ),
4092
4024
  (row) => {
4093
4025
  const rawEvent = {
@@ -4107,7 +4039,7 @@ var readStream = async (execute, streamId, options) => {
4107
4039
  kind: "Event",
4108
4040
  metadata
4109
4041
  };
4110
- return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess', _59 => _59.schema, 'optionalAccess', _60 => _60.versioning]));
4042
+ return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess', _57 => _57.schema, 'optionalAccess', _58 => _58.versioning]));
4111
4043
  }
4112
4044
  );
4113
4045
  return events.length > 0 ? {
@@ -4125,17 +4057,13 @@ var readStream = async (execute, streamId, options) => {
4125
4057
 
4126
4058
  var streamExists = async (execute, streamId, options) => {
4127
4059
  const queryResult = await execute.query(
4128
- _dumbo.sql.call(void 0,
4129
- `SELECT EXISTS (
4060
+ _dumbo.SQL`SELECT EXISTS (
4130
4061
  SELECT 1
4131
- from ${streamsTable.name}
4132
- WHERE stream_id = %L AND partition = %L AND is_archived = FALSE)
4133
- `,
4134
- streamId,
4135
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.partition]), () => ( defaultTag))
4136
- )
4062
+ from ${_dumbo.SQL.identifier(streamsTable.name)}
4063
+ WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _59 => _59.partition]), () => ( defaultTag))} AND is_archived = FALSE)
4064
+ `
4137
4065
  );
4138
- return _nullishCoalesce(_optionalChain([queryResult, 'access', _62 => _62.rows, 'access', _63 => _63[0], 'optionalAccess', _64 => _64.exists]), () => ( false));
4066
+ return _nullishCoalesce(_optionalChain([queryResult, 'access', _60 => _60.rows, 'access', _61 => _61[0], 'optionalAccess', _62 => _62.exists]), () => ( false));
4139
4067
  };
4140
4068
 
4141
4069
  // src/eventStore/schema/index.ts
@@ -4168,27 +4096,22 @@ var eventStoreSchemaMigrations = [
4168
4096
  ];
4169
4097
  var createEventStoreSchema = (connectionString, pool, hooks, options) => {
4170
4098
  return pool.withTransaction(async (tx) => {
4171
- const client = await tx.connection.open();
4172
- const context = {
4173
- execute: tx.execute,
4174
- connection: {
4175
- connectionString,
4176
- client,
4177
- transaction: tx,
4178
- pool
4179
- }
4180
- };
4099
+ const context = await transactionToPostgreSQLProjectionHandlerContext(
4100
+ connectionString,
4101
+ pool,
4102
+ tx
4103
+ );
4181
4104
  const nestedPool = _dumbo.dumbo.call(void 0, { connectionString, connection: tx.connection });
4182
4105
  try {
4183
- if (_optionalChain([hooks, 'optionalAccess', _65 => _65.onBeforeSchemaCreated])) {
4106
+ if (_optionalChain([hooks, 'optionalAccess', _63 => _63.onBeforeSchemaCreated])) {
4184
4107
  await hooks.onBeforeSchemaCreated(context);
4185
4108
  }
4186
- const result = await _dumbo.runPostgreSQLMigrations.call(void 0,
4109
+ const result = await _dumbo.runSQLMigrations.call(void 0,
4187
4110
  nestedPool,
4188
4111
  eventStoreSchemaMigrations,
4189
4112
  options
4190
4113
  );
4191
- if (_optionalChain([hooks, 'optionalAccess', _66 => _66.onAfterSchemaCreated])) {
4114
+ if (_optionalChain([hooks, 'optionalAccess', _64 => _64.onAfterSchemaCreated])) {
4192
4115
  await hooks.onAfterSchemaCreated(context);
4193
4116
  }
4194
4117
  return result;
@@ -4202,9 +4125,12 @@ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
4202
4125
 
4203
4126
  var truncateTables = async (execute, options) => {
4204
4127
  await execute.command(
4205
- _dumbo.rawSql.call(void 0,
4206
- `TRUNCATE TABLE ${streamsTable.name}, ${messagesTable.name}, ${processorsTable.name}, ${projectionsTable.name} CASCADE${_optionalChain([options, 'optionalAccess', _67 => _67.resetSequences]) ? "; ALTER SEQUENCE emt_global_message_position RESTART WITH 1" : ""};`
4207
- )
4128
+ _dumbo.SQL`TRUNCATE TABLE
4129
+ ${_dumbo.SQL.identifier(streamsTable.name)},
4130
+ ${_dumbo.SQL.identifier(messagesTable.name)},
4131
+ ${_dumbo.SQL.identifier(processorsTable.name)},
4132
+ ${_dumbo.SQL.identifier(projectionsTable.name)}
4133
+ CASCADE${_dumbo.SQL.plain(_optionalChain([options, 'optionalAccess', _65 => _65.resetSequences]) ? "; ALTER SEQUENCE emt_global_message_position RESTART WITH 1" : "")};`
4208
4134
  );
4209
4135
  };
4210
4136
 
@@ -4221,7 +4147,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4221
4147
  };
4222
4148
  const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
4223
4149
  let migrateSchema = void 0;
4224
- const autoGenerateSchema = _optionalChain([options, 'access', _68 => _68.schema, 'optionalAccess', _69 => _69.autoMigration]) === void 0 || _optionalChain([options, 'access', _70 => _70.schema, 'optionalAccess', _71 => _71.autoMigration]) !== "None";
4150
+ const autoGenerateSchema = _optionalChain([options, 'access', _66 => _66.schema, 'optionalAccess', _67 => _67.autoMigration]) === void 0 || _optionalChain([options, 'access', _68 => _68.schema, 'optionalAccess', _69 => _69.autoMigration]) !== "None";
4225
4151
  const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
4226
4152
  const migrate = async (migrationOptions) => {
4227
4153
  if (!migrateSchema) {
@@ -4230,7 +4156,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4230
4156
  pool,
4231
4157
  {
4232
4158
  onBeforeSchemaCreated: async (context) => {
4233
- if (_optionalChain([options, 'access', _72 => _72.hooks, 'optionalAccess', _73 => _73.onBeforeSchemaCreated])) {
4159
+ if (_optionalChain([options, 'access', _70 => _70.hooks, 'optionalAccess', _71 => _71.onBeforeSchemaCreated])) {
4234
4160
  await options.hooks.onBeforeSchemaCreated(context);
4235
4161
  }
4236
4162
  },
@@ -4245,7 +4171,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4245
4171
  });
4246
4172
  }
4247
4173
  }
4248
- if (_optionalChain([options, 'access', _74 => _74.hooks, 'optionalAccess', _75 => _75.onAfterSchemaCreated])) {
4174
+ if (_optionalChain([options, 'access', _72 => _72.hooks, 'optionalAccess', _73 => _73.onAfterSchemaCreated])) {
4249
4175
  await options.hooks.onAfterSchemaCreated(context);
4250
4176
  }
4251
4177
  }
@@ -4259,33 +4185,41 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4259
4185
  if (!autoGenerateSchema) return Promise.resolve();
4260
4186
  return migrate();
4261
4187
  };
4262
- const beforeCommitHook = inlineProjections.length > 0 ? (events, { transaction }) => handleProjections({
4188
+ const beforeCommitHook = inlineProjections.length > 0 ? async (events, { transaction }) => handleProjections({
4263
4189
  projections: inlineProjections,
4264
- connection: {
4190
+ // TODO: Add proper handling of global data
4191
+ // Currently it's not available as append doesn't return array of global position but just the last one
4192
+ events,
4193
+ ...await transactionToPostgreSQLProjectionHandlerContext(
4265
4194
  connectionString,
4266
4195
  pool,
4267
4196
  transaction
4268
- },
4269
- // TODO: Add proper handling of global data
4270
- // Currently it's not available as append doesn't return array of global position but just the last one
4271
- events
4197
+ )
4272
4198
  }) : void 0;
4273
4199
  return {
4274
4200
  schema: {
4275
- sql: () => schemaSQL.join(""),
4276
- print: () => console.log(schemaSQL.join("")),
4201
+ sql: () => _dumbo.SQL.describe(
4202
+ schemaSQL,
4203
+ _dumbo.getFormatter.call(void 0, _dumbo.fromDatabaseDriverType.call(void 0, pool.driverType).databaseType)
4204
+ ),
4205
+ print: () => console.log(
4206
+ _dumbo.SQL.describe(
4207
+ schemaSQL,
4208
+ _dumbo.getFormatter.call(void 0, _dumbo.fromDatabaseDriverType.call(void 0, pool.driverType).databaseType)
4209
+ )
4210
+ ),
4277
4211
  migrate,
4278
4212
  dangerous: {
4279
4213
  truncate: (truncateOptions) => pool.withTransaction(async (transaction) => {
4280
4214
  await ensureSchemaExists();
4281
4215
  await truncateTables(transaction.execute, truncateOptions);
4282
- if (_optionalChain([truncateOptions, 'optionalAccess', _76 => _76.truncateProjections])) {
4216
+ if (_optionalChain([truncateOptions, 'optionalAccess', _74 => _74.truncateProjections])) {
4283
4217
  const projectionContext = await transactionToPostgreSQLProjectionHandlerContext(
4284
4218
  connectionString,
4285
4219
  pool,
4286
4220
  transaction
4287
4221
  );
4288
- for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.projections]), () => ( []))) {
4222
+ for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.projections]), () => ( []))) {
4289
4223
  if (projection2.projection.truncate)
4290
4224
  await projection2.projection.truncate(projectionContext);
4291
4225
  }
@@ -4295,7 +4229,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4295
4229
  },
4296
4230
  async aggregateStream(streamName, options2) {
4297
4231
  const { evolve, initialState, read } = options2;
4298
- const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _78 => _78.expectedStreamVersion]);
4232
+ const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _76 => _76.expectedStreamVersion]);
4299
4233
  let state = initialState();
4300
4234
  const result = await this.readStream(
4301
4235
  streamName,
@@ -4330,10 +4264,11 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4330
4264
  const [firstPart, ...rest] = streamName.split("-");
4331
4265
  const streamType = firstPart && rest.length > 0 ? firstPart : unknownTag;
4332
4266
  const appendResult = await appendToStream(
4267
+ // TODO: Fix this when introducing more drivers
4333
4268
  pool,
4334
4269
  streamName,
4335
4270
  streamType,
4336
- downcastRecordedMessages(events, _optionalChain([options2, 'optionalAccess', _79 => _79.schema, 'optionalAccess', _80 => _80.versioning])),
4271
+ downcastRecordedMessages(events, _optionalChain([options2, 'optionalAccess', _77 => _77.schema, 'optionalAccess', _78 => _78.versioning])),
4337
4272
  {
4338
4273
  ...options2,
4339
4274
  beforeCommitHook
@@ -4343,7 +4278,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4343
4278
  throw new ExpectedVersionConflictError(
4344
4279
  -1n,
4345
4280
  //TODO: Return actual version in case of error
4346
- _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _81 => _81.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
4281
+ _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _79 => _79.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
4347
4282
  );
4348
4283
  return {
4349
4284
  nextExpectedStreamVersion: appendResult.nextStreamPosition,
@@ -4397,6 +4332,7 @@ var PostgreSQLProjectionSpec = {
4397
4332
  let wasInitialised = false;
4398
4333
  const initialize = async (pool) => {
4399
4334
  const eventStore = getPostgreSQLEventStore(connectionString, {
4335
+ // TODO: This will need to change when we support other drivers
4400
4336
  connectionOptions: { dumbo: pool }
4401
4337
  });
4402
4338
  if (wasInitialised) return;
@@ -4408,15 +4344,11 @@ var PostgreSQLProjectionSpec = {
4408
4344
  registrationType: "async",
4409
4345
  version: _nullishCoalesce(projection2.version, () => ( 1)),
4410
4346
  status: "active",
4411
- context: {
4412
- execute: transaction.execute,
4413
- connection: {
4414
- connectionString,
4415
- client: await transaction.connection.open(),
4416
- transaction,
4417
- pool
4418
- }
4419
- }
4347
+ context: await transactionToPostgreSQLProjectionHandlerContext(
4348
+ connectionString,
4349
+ pool,
4350
+ transaction
4351
+ )
4420
4352
  });
4421
4353
  });
4422
4354
  };
@@ -4426,7 +4358,7 @@ var PostgreSQLProjectionSpec = {
4426
4358
  const allEvents = [];
4427
4359
  const run = async (pool) => {
4428
4360
  let globalPosition = 0n;
4429
- const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _82 => _82.numberOfTimes]), () => ( 1));
4361
+ const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _80 => _80.numberOfTimes]), () => ( 1));
4430
4362
  for (const event of [
4431
4363
  ...givenEvents,
4432
4364
  ...Array.from({ length: numberOfTimes }).flatMap(() => events)
@@ -4451,11 +4383,11 @@ var PostgreSQLProjectionSpec = {
4451
4383
  await handleProjections({
4452
4384
  events: allEvents,
4453
4385
  projections: [projection2],
4454
- connection: {
4455
- pool,
4386
+ ...await transactionToPostgreSQLProjectionHandlerContext(
4456
4387
  connectionString,
4388
+ pool,
4457
4389
  transaction
4458
- }
4390
+ )
4459
4391
  });
4460
4392
  });
4461
4393
  };
@@ -4484,18 +4416,18 @@ var PostgreSQLProjectionSpec = {
4484
4416
  if (!isErrorConstructor(args[0])) {
4485
4417
  assertTrue(
4486
4418
  args[0](error),
4487
- `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _83 => _83.toString, 'call', _84 => _84()])}`
4419
+ `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _81 => _81.toString, 'call', _82 => _82()])}`
4488
4420
  );
4489
4421
  return;
4490
4422
  }
4491
4423
  assertTrue(
4492
4424
  error instanceof args[0],
4493
- `Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _85 => _85.toString, 'call', _86 => _86()])}`
4425
+ `Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _83 => _83.toString, 'call', _84 => _84()])}`
4494
4426
  );
4495
4427
  if (args[1]) {
4496
4428
  assertTrue(
4497
4429
  args[1](error),
4498
- `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _87 => _87.toString, 'call', _88 => _88()])}`
4430
+ `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _85 => _85.toString, 'call', _86 => _86()])}`
4499
4431
  );
4500
4432
  }
4501
4433
  } finally {
@@ -4514,7 +4446,7 @@ var eventInStream = (streamName, event) => {
4514
4446
  ...event,
4515
4447
  metadata: {
4516
4448
  ..._nullishCoalesce(event.metadata, () => ( {})),
4517
- streamName: _nullishCoalesce(_optionalChain([event, 'access', _89 => _89.metadata, 'optionalAccess', _90 => _90.streamName]), () => ( streamName))
4449
+ streamName: _nullishCoalesce(_optionalChain([event, 'access', _87 => _87.metadata, 'optionalAccess', _88 => _88.streamName]), () => ( streamName))
4518
4450
  }
4519
4451
  };
4520
4452
  };
@@ -4522,20 +4454,21 @@ var eventsInStream = (streamName, events) => {
4522
4454
  return events.map((e) => eventInStream(streamName, e));
4523
4455
  };
4524
4456
  var newEventsInStream = eventsInStream;
4525
- var assertSQLQueryResultMatches = (sql12, rows) => async ({ pool: { execute } }) => {
4526
- const result = await execute.query(sql12);
4457
+ var assertSQLQueryResultMatches = (sql, rows) => async ({ pool: { execute } }) => {
4458
+ const result = await execute.query(sql);
4527
4459
  assertThatArray(rows).containsExactlyInAnyOrder(result.rows);
4528
4460
  };
4529
4461
  var expectSQL = {
4530
- query: (sql12) => ({
4462
+ query: (sql) => ({
4531
4463
  resultRows: {
4532
- toBeTheSame: (rows) => assertSQLQueryResultMatches(sql12, rows)
4464
+ toBeTheSame: (rows) => assertSQLQueryResultMatches(sql, rows)
4533
4465
  }
4534
4466
  })
4535
4467
  };
4536
4468
 
4537
4469
  // src/eventStore/projections/postgreSQLProjection.ts
4538
4470
 
4471
+
4539
4472
  var transactionToPostgreSQLProjectionHandlerContext = async (connectionString, pool, transaction) => ({
4540
4473
  execute: transaction.execute,
4541
4474
  connection: {
@@ -4643,7 +4576,7 @@ var postgreSQLRawSQLProjection = (options) => {
4643
4576
  var postgreSQLCheckpointer = () => ({
4644
4577
  read: async (options, context) => {
4645
4578
  const result = await readProcessorCheckpoint(context.execute, options);
4646
- return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _91 => _91.lastProcessedCheckpoint]) };
4579
+ return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _89 => _89.lastProcessedCheckpoint]) };
4647
4580
  },
4648
4581
  store: async (options, context) => {
4649
4582
  const newPosition = getCheckpoint(options.message);
@@ -4661,13 +4594,13 @@ var postgreSQLProcessingScope = (options) => {
4661
4594
  const processorConnectionString = options.connectionString;
4662
4595
  const processorPool = options.pool;
4663
4596
  const processingScope = async (handler, partialContext) => {
4664
- const connection = _optionalChain([partialContext, 'optionalAccess', _92 => _92.connection]);
4665
- const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _93 => _93.connectionString])));
4597
+ const connection = _optionalChain([partialContext, 'optionalAccess', _90 => _90.connection]);
4598
+ const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _91 => _91.connectionString])));
4666
4599
  if (!connectionString)
4667
4600
  throw new EmmettError(
4668
4601
  `PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
4669
4602
  );
4670
- const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _94 => _94.pool]) : processorPool), () => ( processorPool));
4603
+ const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _92 => _92.pool]) : processorPool), () => ( processorPool));
4671
4604
  if (!pool)
4672
4605
  throw new EmmettError(
4673
4606
  `PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
@@ -4708,11 +4641,11 @@ var wrapHooksWithProcessorLocks = (hooks, processorLock) => ({
4708
4641
  ..._nullishCoalesce(hooks, () => ( {})),
4709
4642
  onStart: async (context) => {
4710
4643
  await processorLock.tryAcquire({ execute: context.execute });
4711
- if (_optionalChain([hooks, 'optionalAccess', _95 => _95.onStart])) await hooks.onStart(context);
4644
+ if (_optionalChain([hooks, 'optionalAccess', _93 => _93.onStart])) await hooks.onStart(context);
4712
4645
  },
4713
- onClose: _optionalChain([hooks, 'optionalAccess', _96 => _96.onClose]) || processorLock ? async (context) => {
4646
+ onClose: _optionalChain([hooks, 'optionalAccess', _94 => _94.onClose]) || processorLock ? async (context) => {
4714
4647
  await processorLock.release({ execute: context.execute });
4715
- if (_optionalChain([hooks, 'optionalAccess', _97 => _97.onClose])) await hooks.onClose(context);
4648
+ if (_optionalChain([hooks, 'optionalAccess', _95 => _95.onClose])) await hooks.onClose(context);
4716
4649
  } : void 0
4717
4650
  });
4718
4651
  var postgreSQLProjector = (options) => {
@@ -4744,7 +4677,7 @@ var postgreSQLProjector = (options) => {
4744
4677
  const hooks = wrapHooksWithProcessorLocks(
4745
4678
  {
4746
4679
  ..._nullishCoalesce(options.hooks, () => ( {})),
4747
- onInit: options.projection.init !== void 0 || _optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onInit]) ? async (context) => {
4680
+ onInit: options.projection.init !== void 0 || _optionalChain([options, 'access', _96 => _96.hooks, 'optionalAccess', _97 => _97.onInit]) ? async (context) => {
4748
4681
  if (options.projection.init)
4749
4682
  await options.projection.init({
4750
4683
  version: _nullishCoalesce(options.projection.version, () => ( version)),
@@ -4755,16 +4688,16 @@ var postgreSQLProjector = (options) => {
4755
4688
  migrationOptions: options.migrationOptions
4756
4689
  }
4757
4690
  });
4758
- if (_optionalChain([options, 'access', _100 => _100.hooks, 'optionalAccess', _101 => _101.onInit]))
4691
+ if (_optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onInit]))
4759
4692
  await options.hooks.onInit({
4760
4693
  ...context,
4761
4694
  migrationOptions: options.migrationOptions
4762
4695
  });
4763
- } : _optionalChain([options, 'access', _102 => _102.hooks, 'optionalAccess', _103 => _103.onInit]),
4696
+ } : _optionalChain([options, 'access', _100 => _100.hooks, 'optionalAccess', _101 => _101.onInit]),
4764
4697
  onClose: close ? async (context) => {
4765
- if (_optionalChain([options, 'access', _104 => _104.hooks, 'optionalAccess', _105 => _105.onClose])) await _optionalChain([options, 'access', _106 => _106.hooks, 'optionalAccess', _107 => _107.onClose, 'call', _108 => _108(context)]);
4698
+ if (_optionalChain([options, 'access', _102 => _102.hooks, 'optionalAccess', _103 => _103.onClose])) await _optionalChain([options, 'access', _104 => _104.hooks, 'optionalAccess', _105 => _105.onClose, 'call', _106 => _106(context)]);
4766
4699
  if (close) await close();
4767
- } : _optionalChain([options, 'access', _109 => _109.hooks, 'optionalAccess', _110 => _110.onClose])
4700
+ } : _optionalChain([options, 'access', _107 => _107.hooks, 'optionalAccess', _108 => _108.onClose])
4768
4701
  },
4769
4702
  processorLock
4770
4703
  );
@@ -4806,9 +4739,9 @@ var postgreSQLReactor = (options) => {
4806
4739
  {
4807
4740
  ..._nullishCoalesce(options.hooks, () => ( {})),
4808
4741
  onClose: close ? async (context) => {
4809
- if (_optionalChain([options, 'access', _111 => _111.hooks, 'optionalAccess', _112 => _112.onClose])) await _optionalChain([options, 'access', _113 => _113.hooks, 'optionalAccess', _114 => _114.onClose, 'call', _115 => _115(context)]);
4742
+ if (_optionalChain([options, 'access', _109 => _109.hooks, 'optionalAccess', _110 => _110.onClose])) await _optionalChain([options, 'access', _111 => _111.hooks, 'optionalAccess', _112 => _112.onClose, 'call', _113 => _113(context)]);
4810
4743
  if (close) await close();
4811
- } : _optionalChain([options, 'access', _116 => _116.hooks, 'optionalAccess', _117 => _117.onClose])
4744
+ } : _optionalChain([options, 'access', _114 => _114.hooks, 'optionalAccess', _115 => _115.onClose])
4812
4745
  },
4813
4746
  processorLock
4814
4747
  );
@@ -4865,7 +4798,7 @@ var postgreSQLEventStoreConsumer = (options) => {
4865
4798
  })
4866
4799
  );
4867
4800
  return result.some(
4868
- (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _118 => _118.value, 'optionalAccess', _119 => _119.type]) !== "STOP"
4801
+ (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _116 => _116.value, 'optionalAccess', _117 => _117.type]) !== "STOP"
4869
4802
  ) ? void 0 : {
4870
4803
  type: "STOP"
4871
4804
  };
@@ -4884,7 +4817,7 @@ var postgreSQLEventStoreConsumer = (options) => {
4884
4817
  if (!isRunning) return;
4885
4818
  isRunning = false;
4886
4819
  if (messagePuller) {
4887
- _optionalChain([abortController, 'optionalAccess', _120 => _120.abort, 'call', _121 => _121()]);
4820
+ _optionalChain([abortController, 'optionalAccess', _118 => _118.abort, 'call', _119 => _119()]);
4888
4821
  await messagePuller.stop();
4889
4822
  messagePuller = void 0;
4890
4823
  abortController = null;
@@ -4937,8 +4870,8 @@ var postgreSQLEventStoreConsumer = (options) => {
4937
4870
  stopWhen: options.stopWhen,
4938
4871
  executor: pool.execute,
4939
4872
  eachBatch,
4940
- batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _122 => _122.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
4941
- pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _123 => _123.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs)),
4873
+ batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _120 => _120.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
4874
+ pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _121 => _121.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs)),
4942
4875
  signal: abortController.signal
4943
4876
  });
4944
4877
  start = (async () => {