@event-driven-io/emmett-postgresql 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +91 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +155 -85
- package/dist/index.d.ts +155 -85
- package/dist/index.js +86 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -610,6 +610,9 @@ var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
|
610
610
|
// src/eventStore/consumers/postgreSQLProcessor.ts
|
|
611
611
|
|
|
612
612
|
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
613
616
|
// src/eventStore/schema/index.ts
|
|
614
617
|
|
|
615
618
|
|
|
@@ -1276,9 +1279,33 @@ var PostgreSQLProcessor = {
|
|
|
1276
1279
|
})
|
|
1277
1280
|
}
|
|
1278
1281
|
};
|
|
1279
|
-
var
|
|
1282
|
+
var genericPostgreSQLProcessor = (options) => {
|
|
1280
1283
|
const { eachMessage } = options;
|
|
1281
1284
|
let isActive = true;
|
|
1285
|
+
const poolOptions = {
|
|
1286
|
+
...options.connectionOptions ? options.connectionOptions : {}
|
|
1287
|
+
};
|
|
1288
|
+
const processorConnectionString = "connectionString" in poolOptions ? poolOptions.connectionString : null;
|
|
1289
|
+
const processorPool = "dumbo" in poolOptions ? poolOptions.dumbo : processorConnectionString ? _dumbo.dumbo.call(void 0, {
|
|
1290
|
+
connectionString: processorConnectionString,
|
|
1291
|
+
...poolOptions
|
|
1292
|
+
}) : null;
|
|
1293
|
+
const getPool = (context) => {
|
|
1294
|
+
const connectionString = _nullishCoalesce(processorConnectionString, () => ( context.connectionString));
|
|
1295
|
+
if (!connectionString)
|
|
1296
|
+
throw new EmmettError(
|
|
1297
|
+
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1298
|
+
);
|
|
1299
|
+
const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([context, 'optionalAccess', _25 => _25.pool]) : processorPool), () => ( processorPool));
|
|
1300
|
+
if (!pool)
|
|
1301
|
+
throw new EmmettError(
|
|
1302
|
+
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1303
|
+
);
|
|
1304
|
+
return {
|
|
1305
|
+
connectionString,
|
|
1306
|
+
pool
|
|
1307
|
+
};
|
|
1308
|
+
};
|
|
1282
1309
|
return {
|
|
1283
1310
|
id: options.processorId,
|
|
1284
1311
|
start: async (execute) => {
|
|
@@ -1294,15 +1321,25 @@ var postgreSQLProcessor = (options) => {
|
|
|
1294
1321
|
get isActive() {
|
|
1295
1322
|
return isActive;
|
|
1296
1323
|
},
|
|
1297
|
-
handle: async ({ messages },
|
|
1324
|
+
handle: async ({ messages }, context) => {
|
|
1298
1325
|
if (!isActive) return;
|
|
1299
|
-
|
|
1326
|
+
const { pool, connectionString } = getPool(context);
|
|
1327
|
+
return pool.withTransaction(async (transaction) => {
|
|
1300
1328
|
let result = void 0;
|
|
1301
1329
|
let lastProcessedPosition = null;
|
|
1302
1330
|
for (const message of messages) {
|
|
1303
1331
|
const typedMessage = message;
|
|
1304
|
-
const
|
|
1305
|
-
await
|
|
1332
|
+
const client = await transaction.connection.open();
|
|
1333
|
+
const messageProcessingResult = await eachMessage(typedMessage, {
|
|
1334
|
+
execute: transaction.execute,
|
|
1335
|
+
connection: {
|
|
1336
|
+
connectionString,
|
|
1337
|
+
pool,
|
|
1338
|
+
transaction,
|
|
1339
|
+
client
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
await storeProcessorCheckpoint(transaction.execute, {
|
|
1306
1343
|
processorId: options.processorId,
|
|
1307
1344
|
version: options.version,
|
|
1308
1345
|
lastProcessedPosition,
|
|
@@ -1328,6 +1365,23 @@ var postgreSQLProcessor = (options) => {
|
|
|
1328
1365
|
}
|
|
1329
1366
|
};
|
|
1330
1367
|
};
|
|
1368
|
+
var postgreSQLProjectionProcessor = (options) => {
|
|
1369
|
+
const projection2 = options.projection;
|
|
1370
|
+
return genericPostgreSQLProcessor({
|
|
1371
|
+
processorId: _nullishCoalesce(options.processorId, () => ( `projection:${projection2.name}`)),
|
|
1372
|
+
eachMessage: async (event, context) => {
|
|
1373
|
+
if (!projection2.canHandle.includes(event.type)) return;
|
|
1374
|
+
await projection2.handle([event], context);
|
|
1375
|
+
},
|
|
1376
|
+
...options
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1379
|
+
var postgreSQLProcessor = (options) => {
|
|
1380
|
+
if ("projection" in options) {
|
|
1381
|
+
return postgreSQLProjectionProcessor(options);
|
|
1382
|
+
}
|
|
1383
|
+
return genericPostgreSQLProcessor(options);
|
|
1384
|
+
};
|
|
1331
1385
|
|
|
1332
1386
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
1333
1387
|
var postgreSQLEventStoreConsumer = (options) => {
|
|
@@ -1336,7 +1390,7 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1336
1390
|
const processors = _nullishCoalesce(options.processors, () => ( []));
|
|
1337
1391
|
let start;
|
|
1338
1392
|
let currentMessagePuller;
|
|
1339
|
-
const pool =
|
|
1393
|
+
const pool = options.pool ? options.pool : _dumbo.dumbo.call(void 0, { connectionString: options.connectionString });
|
|
1340
1394
|
const eachBatch = async (messagesBatch) => {
|
|
1341
1395
|
const activeProcessors = processors.filter((s) => s.isActive);
|
|
1342
1396
|
if (activeProcessors.length === 0)
|
|
@@ -1346,11 +1400,14 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1346
1400
|
};
|
|
1347
1401
|
const result = await Promise.allSettled(
|
|
1348
1402
|
activeProcessors.map((s) => {
|
|
1349
|
-
return s.handle(messagesBatch, {
|
|
1403
|
+
return s.handle(messagesBatch, {
|
|
1404
|
+
pool,
|
|
1405
|
+
connectionString: options.connectionString
|
|
1406
|
+
});
|
|
1350
1407
|
})
|
|
1351
1408
|
);
|
|
1352
1409
|
return result.some(
|
|
1353
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
1410
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _26 => _26.value, 'optionalAccess', _27 => _27.type]) !== "STOP"
|
|
1354
1411
|
) ? void 0 : {
|
|
1355
1412
|
type: "STOP"
|
|
1356
1413
|
};
|
|
@@ -1358,8 +1415,8 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1358
1415
|
const messagePooler = currentMessagePuller = postgreSQLEventStoreMessageBatchPuller({
|
|
1359
1416
|
executor: pool.execute,
|
|
1360
1417
|
eachBatch,
|
|
1361
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1362
|
-
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1418
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _28 => _28.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
|
|
1419
|
+
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _29 => _29.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs))
|
|
1363
1420
|
});
|
|
1364
1421
|
const stop = async () => {
|
|
1365
1422
|
if (!isRunning) return;
|
|
@@ -1554,7 +1611,9 @@ var pongoProjection = ({
|
|
|
1554
1611
|
}) => postgreSQLProjection({
|
|
1555
1612
|
canHandle,
|
|
1556
1613
|
handle: async (events, context) => {
|
|
1557
|
-
const {
|
|
1614
|
+
const {
|
|
1615
|
+
connection: { connectionString, client }
|
|
1616
|
+
} = context;
|
|
1558
1617
|
const pongo = _pongo.pongoClient.call(void 0, connectionString, {
|
|
1559
1618
|
connectionOptions: { client }
|
|
1560
1619
|
});
|
|
@@ -1607,7 +1666,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1607
1666
|
const allEvents = [];
|
|
1608
1667
|
const run = async (pool) => {
|
|
1609
1668
|
let globalPosition = 0n;
|
|
1610
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1669
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _30 => _30.numberOfTimes]), () => ( 1));
|
|
1611
1670
|
for (const event of [
|
|
1612
1671
|
...givenEvents,
|
|
1613
1672
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
@@ -1631,6 +1690,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1631
1690
|
events: allEvents,
|
|
1632
1691
|
projections: [projection2],
|
|
1633
1692
|
connection: {
|
|
1693
|
+
pool,
|
|
1634
1694
|
connectionString,
|
|
1635
1695
|
transaction
|
|
1636
1696
|
}
|
|
@@ -1662,18 +1722,18 @@ var PostgreSQLProjectionSpec = {
|
|
|
1662
1722
|
if (!isErrorConstructor(args[0])) {
|
|
1663
1723
|
assertTrue(
|
|
1664
1724
|
args[0](error),
|
|
1665
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1725
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _31 => _31.toString, 'call', _32 => _32()])}`
|
|
1666
1726
|
);
|
|
1667
1727
|
return;
|
|
1668
1728
|
}
|
|
1669
1729
|
assertTrue(
|
|
1670
1730
|
error instanceof args[0],
|
|
1671
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
1731
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _33 => _33.toString, 'call', _34 => _34()])}`
|
|
1672
1732
|
);
|
|
1673
1733
|
if (args[1]) {
|
|
1674
1734
|
assertTrue(
|
|
1675
1735
|
args[1](error),
|
|
1676
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1736
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _35 => _35.toString, 'call', _36 => _36()])}`
|
|
1677
1737
|
);
|
|
1678
1738
|
}
|
|
1679
1739
|
} finally {
|
|
@@ -1692,7 +1752,7 @@ var eventInStream = (streamName, event) => {
|
|
|
1692
1752
|
...event,
|
|
1693
1753
|
metadata: {
|
|
1694
1754
|
..._nullishCoalesce(event.metadata, () => ( {})),
|
|
1695
|
-
streamName: _nullishCoalesce(_optionalChain([event, 'access',
|
|
1755
|
+
streamName: _nullishCoalesce(_optionalChain([event, 'access', _37 => _37.metadata, 'optionalAccess', _38 => _38.streamName]), () => ( streamName))
|
|
1696
1756
|
}
|
|
1697
1757
|
};
|
|
1698
1758
|
};
|
|
@@ -1717,7 +1777,7 @@ var handleProjections = async (options) => {
|
|
|
1717
1777
|
const {
|
|
1718
1778
|
projections: allProjections,
|
|
1719
1779
|
events,
|
|
1720
|
-
connection: { transaction, connectionString }
|
|
1780
|
+
connection: { pool, transaction, connectionString }
|
|
1721
1781
|
} = options;
|
|
1722
1782
|
const eventTypes = events.map((e) => e.type);
|
|
1723
1783
|
const projections = allProjections.filter(
|
|
@@ -1726,9 +1786,12 @@ var handleProjections = async (options) => {
|
|
|
1726
1786
|
const client = await transaction.connection.open();
|
|
1727
1787
|
for (const projection2 of projections) {
|
|
1728
1788
|
await projection2.handle(events, {
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1789
|
+
connection: {
|
|
1790
|
+
connectionString,
|
|
1791
|
+
pool,
|
|
1792
|
+
client,
|
|
1793
|
+
transaction
|
|
1794
|
+
},
|
|
1732
1795
|
execute: transaction.execute
|
|
1733
1796
|
});
|
|
1734
1797
|
}
|
|
@@ -1765,7 +1828,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1765
1828
|
};
|
|
1766
1829
|
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
|
|
1767
1830
|
let migrateSchema;
|
|
1768
|
-
const autoGenerateSchema = _optionalChain([options, 'access',
|
|
1831
|
+
const autoGenerateSchema = _optionalChain([options, 'access', _39 => _39.schema, 'optionalAccess', _40 => _40.autoMigration]) === void 0 || _optionalChain([options, 'access', _41 => _41.schema, 'optionalAccess', _42 => _42.autoMigration]) !== "None";
|
|
1769
1832
|
const ensureSchemaExists = () => {
|
|
1770
1833
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1771
1834
|
if (!migrateSchema) {
|
|
@@ -1778,6 +1841,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1778
1841
|
projections: inlineProjections,
|
|
1779
1842
|
connection: {
|
|
1780
1843
|
connectionString,
|
|
1844
|
+
pool,
|
|
1781
1845
|
transaction
|
|
1782
1846
|
},
|
|
1783
1847
|
// TODO: Add proper handling of global data
|
|
@@ -1794,7 +1858,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1794
1858
|
},
|
|
1795
1859
|
async aggregateStream(streamName, options2) {
|
|
1796
1860
|
const { evolve, initialState, read } = options2;
|
|
1797
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
1861
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _43 => _43.expectedStreamVersion]);
|
|
1798
1862
|
let state = initialState();
|
|
1799
1863
|
const result = await this.readStream(streamName, options2.read);
|
|
1800
1864
|
const currentStreamVersion = result.currentStreamVersion;
|
|
@@ -1835,7 +1899,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1835
1899
|
throw new ExpectedVersionConflictError(
|
|
1836
1900
|
-1n,
|
|
1837
1901
|
//TODO: Return actual version in case of error
|
|
1838
|
-
_nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1902
|
+
_nullishCoalesce(_optionalChain([options2, 'optionalAccess', _44 => _44.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
1839
1903
|
);
|
|
1840
1904
|
return {
|
|
1841
1905
|
nextExpectedStreamVersion: appendResult.nextStreamPosition,
|
|
@@ -1845,7 +1909,8 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1845
1909
|
},
|
|
1846
1910
|
consumer: (options2) => postgreSQLEventStoreConsumer({
|
|
1847
1911
|
..._nullishCoalesce(options2, () => ( {})),
|
|
1848
|
-
pool
|
|
1912
|
+
pool,
|
|
1913
|
+
connectionString
|
|
1849
1914
|
}),
|
|
1850
1915
|
close: () => pool.close(),
|
|
1851
1916
|
async withSession(callback) {
|
|
@@ -1926,5 +1991,6 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1926
1991
|
|
|
1927
1992
|
|
|
1928
1993
|
|
|
1929
|
-
|
|
1994
|
+
|
|
1995
|
+
exports.DefaultPostgreSQLEventStoreProcessorBatchSize = DefaultPostgreSQLEventStoreProcessorBatchSize; exports.DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs; exports.PostgreSQLEventStoreDefaultStreamVersion = PostgreSQLEventStoreDefaultStreamVersion; exports.PostgreSQLProcessor = PostgreSQLProcessor; exports.PostgreSQLProjectionSpec = PostgreSQLProjectionSpec; exports.addDefaultPartition = addDefaultPartition; exports.addEventsPartitions = addEventsPartitions; exports.addModuleForAllTenantsSQL = addModuleForAllTenantsSQL; exports.addModuleSQL = addModuleSQL; exports.addTablePartitions = addTablePartitions; exports.addTenantForAllModulesSQL = addTenantForAllModulesSQL; exports.addTenantSQL = addTenantSQL; exports.appendEventsSQL = appendEventsSQL; exports.appendToStream = appendToStream; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.createEventStoreSchema = createEventStoreSchema; exports.defaultPostgreSQLOptions = defaultPostgreSQLOptions; exports.defaultTag = defaultTag; exports.documentDoesNotExist = documentDoesNotExist; exports.documentExists = documentExists; exports.documentMatchingExists = documentMatchingExists; exports.documentsAreTheSame = documentsAreTheSame; exports.documentsMatchingHaveCount = documentsMatchingHaveCount; exports.emmettPrefix = emmettPrefix; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.eventsTable = eventsTable; exports.eventsTableSQL = eventsTableSQL; exports.expectPongoDocuments = expectPongoDocuments; exports.expectSQL = expectSQL; exports.getPostgreSQLEventStore = getPostgreSQLEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; exports.newEventsInStream = newEventsInStream; exports.pongoMultiStreamProjection = pongoMultiStreamProjection; exports.pongoProjection = pongoProjection; exports.pongoSingleStreamProjection = pongoSingleStreamProjection; exports.postgreSQLEventStoreConsumer = postgreSQLEventStoreConsumer; exports.postgreSQLEventStoreMessageBatchPuller = postgreSQLEventStoreMessageBatchPuller; exports.postgreSQLProcessor = postgreSQLProcessor; exports.postgreSQLProjection = postgreSQLProjection; exports.postgreSQLProjectionProcessor = postgreSQLProjectionProcessor; exports.postgreSQLRawBatchSQLProjection = postgreSQLRawBatchSQLProjection; exports.postgreSQLRawSQLProjection = postgreSQLRawSQLProjection; exports.readLastMessageGlobalPosition = readLastMessageGlobalPosition; exports.readMessagesBatch = readMessagesBatch; exports.readProcessorCheckpoint = readProcessorCheckpoint; exports.readStream = readStream; exports.sanitizeNameSQL = sanitizeNameSQL; exports.schemaSQL = schemaSQL; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.storeSubscriptionCheckpointSQL = storeSubscriptionCheckpointSQL; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL; exports.subscriptionsTable = subscriptionsTable; exports.subscriptionsTableSQL = subscriptionsTableSQL; exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
|
|
1930
1996
|
//# sourceMappingURL=index.cjs.map
|