@event-driven-io/emmett-sqlite 0.43.0-beta.4 → 0.43.0-beta.6
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/cloudflare.d.cts +1 -1
- package/dist/cloudflare.d.ts +1 -1
- package/dist/index.cjs +60 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +76 -65
- package/dist/index.js.map +1 -1
- package/dist/sqlite3.d.cts +1 -1
- package/dist/sqlite3.d.ts +1 -1
- package/dist/{sqliteProjection-DBJa19a5.d.cts → sqliteProjection-D6WKeuhb.d.cts} +2 -2
- package/dist/{sqliteProjection-DBJa19a5.d.ts → sqliteProjection-D6WKeuhb.d.ts} +2 -2
- package/package.json +4 -4
package/dist/cloudflare.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D1Database } from '@cloudflare/workers-types';
|
|
2
2
|
import { d1DumboDriver, D1PoolOptions } from '@event-driven-io/dumbo/cloudflare';
|
|
3
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
3
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-D6WKeuhb.cjs';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/sqlite';
|
|
6
6
|
import '@event-driven-io/emmett';
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D1Database } from '@cloudflare/workers-types';
|
|
2
2
|
import { d1DumboDriver, D1PoolOptions } from '@event-driven-io/dumbo/cloudflare';
|
|
3
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
3
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-D6WKeuhb.js';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/sqlite';
|
|
6
6
|
import '@event-driven-io/emmett';
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
49
49
|
// ../emmett/dist/index.js
|
|
50
50
|
var _uuid = require('uuid');
|
|
51
51
|
|
|
52
|
+
|
|
52
53
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
53
54
|
|
|
54
55
|
|
|
@@ -1540,10 +1541,6 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
1540
1541
|
// src/eventStore/SQLiteEventStore.ts
|
|
1541
1542
|
|
|
1542
1543
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
1544
|
// src/eventStore/consumers/messageBatchProcessing/index.ts
|
|
1548
1545
|
var DefaultSQLiteEventStoreProcessorBatchSize = 100;
|
|
1549
1546
|
var DefaultSQLiteEventStoreProcessorPullingFrequencyInMs = 50;
|
|
@@ -1929,10 +1926,6 @@ var getSQLiteEventStore = (options) => {
|
|
|
1929
1926
|
let migrateSchema = void 0;
|
|
1930
1927
|
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
1931
1928
|
const onBeforeCommitHook = _optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onBeforeCommit]);
|
|
1932
|
-
const withConnection = (handler) => pool.withConnection(async (connection) => {
|
|
1933
|
-
await ensureSchemaExists(connection);
|
|
1934
|
-
return await handler(connection);
|
|
1935
|
-
});
|
|
1936
1929
|
if (options) {
|
|
1937
1930
|
autoGenerateSchema = _optionalChain([options, 'access', _100 => _100.schema, 'optionalAccess', _101 => _101.autoMigration]) === void 0 || _optionalChain([options, 'access', _102 => _102.schema, 'optionalAccess', _103 => _103.autoMigration]) !== "None";
|
|
1938
1931
|
}
|
|
@@ -1963,20 +1956,23 @@ var getSQLiteEventStore = (options) => {
|
|
|
1963
1956
|
}
|
|
1964
1957
|
return migrateSchema;
|
|
1965
1958
|
};
|
|
1966
|
-
const ensureSchemaExists = (
|
|
1959
|
+
const ensureSchemaExists = () => {
|
|
1967
1960
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1968
|
-
return migrate(connection);
|
|
1961
|
+
return pool.withConnection((connection) => migrate(connection));
|
|
1969
1962
|
};
|
|
1970
1963
|
return {
|
|
1971
1964
|
async aggregateStream(streamName, options2) {
|
|
1965
|
+
await ensureSchemaExists();
|
|
1972
1966
|
const { evolve, initialState, read } = options2;
|
|
1973
1967
|
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _108 => _108.expectedStreamVersion]);
|
|
1974
1968
|
let state = initialState();
|
|
1975
1969
|
if (typeof streamName !== "string") {
|
|
1976
1970
|
throw new Error("Stream name is not string");
|
|
1977
1971
|
}
|
|
1978
|
-
const result = await
|
|
1979
|
-
|
|
1972
|
+
const result = await readStream(
|
|
1973
|
+
pool.execute,
|
|
1974
|
+
streamName,
|
|
1975
|
+
read
|
|
1980
1976
|
);
|
|
1981
1977
|
const currentStreamVersion = result.currentStreamVersion;
|
|
1982
1978
|
assertExpectedVersionMatchesCurrent(
|
|
@@ -1994,43 +1990,35 @@ var getSQLiteEventStore = (options) => {
|
|
|
1994
1990
|
streamExists: result.streamExists
|
|
1995
1991
|
};
|
|
1996
1992
|
},
|
|
1997
|
-
readStream: async (streamName, options2) =>
|
|
1998
|
-
|
|
1999
|
-
|
|
1993
|
+
readStream: async (streamName, options2) => {
|
|
1994
|
+
await ensureSchemaExists();
|
|
1995
|
+
return readStream(
|
|
1996
|
+
pool.execute,
|
|
1997
|
+
streamName,
|
|
1998
|
+
options2
|
|
1999
|
+
);
|
|
2000
|
+
},
|
|
2000
2001
|
appendToStream: async (streamName, events, appendOptions) => {
|
|
2002
|
+
await ensureSchemaExists();
|
|
2001
2003
|
const [firstPart, ...rest] = streamName.split("-");
|
|
2002
2004
|
const streamType = firstPart && rest.length > 0 ? firstPart : unknownTag2;
|
|
2003
|
-
const appendResult = await
|
|
2004
|
-
() =>
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
await onBeforeCommitHook(messages, context);
|
|
2018
|
-
}
|
|
2019
|
-
})
|
|
2020
|
-
),
|
|
2021
|
-
{
|
|
2022
|
-
retries: 3,
|
|
2023
|
-
minTimeout: 250,
|
|
2024
|
-
factor: 1.5,
|
|
2025
|
-
shouldRetryError: (error) => {
|
|
2026
|
-
return (
|
|
2027
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
2028
|
-
error.code === "SQLITE_BUSY" || _dumbo.DumboError.isInstanceOf(error, {
|
|
2029
|
-
errorType: _dumbo.LockNotAvailableError.ErrorType
|
|
2030
|
-
})
|
|
2031
|
-
);
|
|
2005
|
+
const appendResult = await pool.withConnection(
|
|
2006
|
+
(connection) => appendToStream(connection, streamName, streamType, events, {
|
|
2007
|
+
...appendOptions,
|
|
2008
|
+
onBeforeCommit: async (messages, context) => {
|
|
2009
|
+
if (inlineProjections.length > 0)
|
|
2010
|
+
await handleProjections({
|
|
2011
|
+
projections: inlineProjections,
|
|
2012
|
+
events: messages,
|
|
2013
|
+
execute: context.connection.execute,
|
|
2014
|
+
connection: context.connection,
|
|
2015
|
+
driverType: options.driver.driverType
|
|
2016
|
+
});
|
|
2017
|
+
if (onBeforeCommitHook)
|
|
2018
|
+
await onBeforeCommitHook(messages, context);
|
|
2032
2019
|
}
|
|
2033
|
-
}
|
|
2020
|
+
}),
|
|
2021
|
+
{ readonly: false }
|
|
2034
2022
|
);
|
|
2035
2023
|
if (!appendResult.success)
|
|
2036
2024
|
throw new ExpectedVersionConflictError(
|
|
@@ -2044,16 +2032,39 @@ var getSQLiteEventStore = (options) => {
|
|
|
2044
2032
|
createdNewStream: appendResult.nextStreamPosition >= BigInt(events.length)
|
|
2045
2033
|
};
|
|
2046
2034
|
},
|
|
2047
|
-
streamExists(streamName, options2) {
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
);
|
|
2035
|
+
async streamExists(streamName, options2) {
|
|
2036
|
+
await ensureSchemaExists();
|
|
2037
|
+
return streamExists(pool.execute, streamName, options2);
|
|
2051
2038
|
},
|
|
2052
2039
|
consumer: (consumerOptions) => sqliteEventStoreConsumer({
|
|
2053
2040
|
..._nullishCoalesce(options, () => ( {})),
|
|
2054
2041
|
..._nullishCoalesce(consumerOptions, () => ( {})),
|
|
2055
2042
|
pool
|
|
2056
2043
|
}),
|
|
2044
|
+
async withSession(callback) {
|
|
2045
|
+
return await pool.withConnection(async (connection) => {
|
|
2046
|
+
const sessionStore = getSQLiteEventStore({
|
|
2047
|
+
...options,
|
|
2048
|
+
pool: _dumbo.dumbo.call(void 0, {
|
|
2049
|
+
...options.driver.mapToDumboOptions(options),
|
|
2050
|
+
connection
|
|
2051
|
+
}),
|
|
2052
|
+
transactionOptions: {
|
|
2053
|
+
allowNestedTransactions: true,
|
|
2054
|
+
mode: "session_based"
|
|
2055
|
+
},
|
|
2056
|
+
schema: {
|
|
2057
|
+
...options.schema,
|
|
2058
|
+
autoMigration: "None"
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
await ensureSchemaExists();
|
|
2062
|
+
return callback({
|
|
2063
|
+
eventStore: sessionStore,
|
|
2064
|
+
close: () => Promise.resolve()
|
|
2065
|
+
});
|
|
2066
|
+
});
|
|
2067
|
+
},
|
|
2057
2068
|
close: () => pool.close(),
|
|
2058
2069
|
schema: {
|
|
2059
2070
|
sql: () => schemaSQL.join(""),
|