@event-driven-io/emmett-sqlite 0.43.0-beta.5 → 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 +45 -21
- 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 +59 -35
- 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,8 +1541,6 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
1540
1541
|
// src/eventStore/SQLiteEventStore.ts
|
|
1541
1542
|
|
|
1542
1543
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
1544
|
// src/eventStore/consumers/messageBatchProcessing/index.ts
|
|
1546
1545
|
var DefaultSQLiteEventStoreProcessorBatchSize = 100;
|
|
1547
1546
|
var DefaultSQLiteEventStoreProcessorPullingFrequencyInMs = 50;
|
|
@@ -1927,10 +1926,6 @@ var getSQLiteEventStore = (options) => {
|
|
|
1927
1926
|
let migrateSchema = void 0;
|
|
1928
1927
|
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
1929
1928
|
const onBeforeCommitHook = _optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onBeforeCommit]);
|
|
1930
|
-
const withConnection = (handler, options2) => pool.withConnection(async (connection) => {
|
|
1931
|
-
await ensureSchemaExists(connection);
|
|
1932
|
-
return await handler(connection);
|
|
1933
|
-
}, options2);
|
|
1934
1929
|
if (options) {
|
|
1935
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";
|
|
1936
1931
|
}
|
|
@@ -1961,21 +1956,23 @@ var getSQLiteEventStore = (options) => {
|
|
|
1961
1956
|
}
|
|
1962
1957
|
return migrateSchema;
|
|
1963
1958
|
};
|
|
1964
|
-
const ensureSchemaExists = (
|
|
1959
|
+
const ensureSchemaExists = () => {
|
|
1965
1960
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1966
|
-
return migrate(connection);
|
|
1961
|
+
return pool.withConnection((connection) => migrate(connection));
|
|
1967
1962
|
};
|
|
1968
1963
|
return {
|
|
1969
1964
|
async aggregateStream(streamName, options2) {
|
|
1965
|
+
await ensureSchemaExists();
|
|
1970
1966
|
const { evolve, initialState, read } = options2;
|
|
1971
1967
|
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _108 => _108.expectedStreamVersion]);
|
|
1972
1968
|
let state = initialState();
|
|
1973
1969
|
if (typeof streamName !== "string") {
|
|
1974
1970
|
throw new Error("Stream name is not string");
|
|
1975
1971
|
}
|
|
1976
|
-
const result = await
|
|
1977
|
-
|
|
1978
|
-
|
|
1972
|
+
const result = await readStream(
|
|
1973
|
+
pool.execute,
|
|
1974
|
+
streamName,
|
|
1975
|
+
read
|
|
1979
1976
|
);
|
|
1980
1977
|
const currentStreamVersion = result.currentStreamVersion;
|
|
1981
1978
|
assertExpectedVersionMatchesCurrent(
|
|
@@ -1993,14 +1990,19 @@ var getSQLiteEventStore = (options) => {
|
|
|
1993
1990
|
streamExists: result.streamExists
|
|
1994
1991
|
};
|
|
1995
1992
|
},
|
|
1996
|
-
readStream: async (streamName, options2) =>
|
|
1997
|
-
|
|
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 withConnection(
|
|
2005
|
+
const appendResult = await pool.withConnection(
|
|
2004
2006
|
(connection) => appendToStream(connection, streamName, streamType, events, {
|
|
2005
2007
|
...appendOptions,
|
|
2006
2008
|
onBeforeCommit: async (messages, context) => {
|
|
@@ -2030,17 +2032,39 @@ var getSQLiteEventStore = (options) => {
|
|
|
2030
2032
|
createdNewStream: appendResult.nextStreamPosition >= BigInt(events.length)
|
|
2031
2033
|
};
|
|
2032
2034
|
},
|
|
2033
|
-
streamExists(streamName, options2) {
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
{ readonly: true }
|
|
2037
|
-
);
|
|
2035
|
+
async streamExists(streamName, options2) {
|
|
2036
|
+
await ensureSchemaExists();
|
|
2037
|
+
return streamExists(pool.execute, streamName, options2);
|
|
2038
2038
|
},
|
|
2039
2039
|
consumer: (consumerOptions) => sqliteEventStoreConsumer({
|
|
2040
2040
|
..._nullishCoalesce(options, () => ( {})),
|
|
2041
2041
|
..._nullishCoalesce(consumerOptions, () => ( {})),
|
|
2042
2042
|
pool
|
|
2043
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
|
+
},
|
|
2044
2068
|
close: () => pool.close(),
|
|
2045
2069
|
schema: {
|
|
2046
2070
|
sql: () => schemaSQL.join(""),
|