@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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-DBJa19a5.cjs';
2
- export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-DBJa19a5.cjs';
1
+ import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-D6WKeuhb.cjs';
2
+ export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-D6WKeuhb.cjs';
3
3
  import * as _event_driven_io_emmett from '@event-driven-io/emmett';
4
4
  import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ThenThrows } from '@event-driven-io/emmett';
5
5
  import { SQL, SQLExecutor, Dumbo, QueryResultRow } from '@event-driven-io/dumbo';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-DBJa19a5.js';
2
- export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-DBJa19a5.js';
1
+ import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-D6WKeuhb.js';
2
+ export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-D6WKeuhb.js';
3
3
  import * as _event_driven_io_emmett from '@event-driven-io/emmett';
4
4
  import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ThenThrows } from '@event-driven-io/emmett';
5
5
  import { SQL, SQLExecutor, Dumbo, QueryResultRow } from '@event-driven-io/dumbo';
package/dist/index.js CHANGED
@@ -47,12 +47,13 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
47
47
  };
48
48
 
49
49
  // ../emmett/dist/index.js
50
- import { v4 as uuid4 } from "uuid";
50
+ import { v4 as uuid5 } from "uuid";
51
+ import { v7 as uuid2 } from "uuid";
51
52
  import { v7 as uuid } from "uuid";
52
53
  import retry from "async-retry";
53
- import { v7 as uuid2 } from "uuid";
54
- import { v4 as uuid3 } from "uuid";
55
- import { v7 as uuid5 } from "uuid";
54
+ import { v7 as uuid3 } from "uuid";
55
+ import { v4 as uuid4 } from "uuid";
56
+ import { v7 as uuid6 } from "uuid";
56
57
  var emmettPrefix = "emt";
57
58
  var defaultTag = `${emmettPrefix}:default`;
58
59
  var unknownTag = `${emmettPrefix}:unknown`;
@@ -383,7 +384,7 @@ var bigIntProcessorCheckpoint = (value) => bigInt.toNormalizedString(value);
383
384
  var parseBigIntProcessorCheckpoint = (value) => BigInt(value);
384
385
  var defaultProcessorVersion = 1;
385
386
  var defaultProcessorPartition = defaultTag;
386
- var getProcessorInstanceId = (processorId) => `${processorId}:${uuid2()}`;
387
+ var getProcessorInstanceId = (processorId) => `${processorId}:${uuid3()}`;
387
388
  var getProjectorId = (options) => `emt:processor:projector:${options.projectionName}`;
388
389
  var reactor = (options) => {
389
390
  const {
@@ -772,7 +773,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
772
773
  ("metadata" in message2 && message2.metadata?.messageId ? (
773
774
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
774
775
  message2.metadata.messageId
775
- ) : void 0) ?? uuid5()
776
+ ) : void 0) ?? uuid6()
776
777
  );
777
778
  const messageWithMetadata = {
778
779
  ...message2,
@@ -988,7 +989,7 @@ var sqliteRawSQLProjection = (options) => {
988
989
 
989
990
  // src/eventStore/projections/sqliteProjectionSpec.ts
990
991
  import { dumbo } from "@event-driven-io/dumbo";
991
- import { v4 as uuid6 } from "uuid";
992
+ import { v4 as uuid7 } from "uuid";
992
993
  var SQLiteProjectionSpec = {
993
994
  for: (options) => {
994
995
  {
@@ -1013,8 +1014,8 @@ var SQLiteProjectionSpec = {
1013
1014
  checkpoint: bigIntProcessorCheckpoint(++globalPosition),
1014
1015
  globalPosition,
1015
1016
  streamPosition: globalPosition,
1016
- streamName: `test-${uuid6()}`,
1017
- messageId: uuid6()
1017
+ streamName: `test-${uuid7()}`,
1018
+ messageId: uuid7()
1018
1019
  };
1019
1020
  allEvents.push({
1020
1021
  ...event,
@@ -1129,7 +1130,7 @@ import {
1129
1130
  SQL,
1130
1131
  UniqueConstraintError
1131
1132
  } from "@event-driven-io/dumbo";
1132
- import { v4 as uuid7 } from "uuid";
1133
+ import { v4 as uuid8 } from "uuid";
1133
1134
 
1134
1135
  // src/eventStore/schema/typing.ts
1135
1136
  var emmettPrefix2 = "emt";
@@ -1179,7 +1180,7 @@ var appendToStream = async (connection, streamName, streamType, messages, option
1179
1180
  kind: m.kind ?? "Event",
1180
1181
  metadata: {
1181
1182
  streamName,
1182
- messageId: uuid7(),
1183
+ messageId: uuid8(),
1183
1184
  streamPosition: BigInt(i + 1),
1184
1185
  ..."metadata" in m ? m.metadata ?? {} : {}
1185
1186
  }
@@ -1538,9 +1539,7 @@ var readProcessorCheckpoint = async (execute, options) => {
1538
1539
  import { SQL as SQL8 } from "@event-driven-io/dumbo";
1539
1540
 
1540
1541
  // src/eventStore/SQLiteEventStore.ts
1541
- import {
1542
- dumbo as dumbo3
1543
- } from "@event-driven-io/dumbo";
1542
+ import { dumbo as dumbo3 } from "@event-driven-io/dumbo";
1544
1543
 
1545
1544
  // src/eventStore/consumers/messageBatchProcessing/index.ts
1546
1545
  var DefaultSQLiteEventStoreProcessorBatchSize = 100;
@@ -1612,7 +1611,7 @@ var zipSQLiteEventStoreMessageBatchPullerStartFrom = (options) => {
1612
1611
 
1613
1612
  // src/eventStore/consumers/sqliteEventStoreConsumer.ts
1614
1613
  import { dumbo as dumbo2 } from "@event-driven-io/dumbo";
1615
- import { v7 as uuid8 } from "uuid";
1614
+ import { v7 as uuid9 } from "uuid";
1616
1615
 
1617
1616
  // src/eventStore/consumers/sqliteCheckpointer.ts
1618
1617
  var sqliteCheckpointer = () => ({
@@ -1827,7 +1826,7 @@ var sqliteEventStoreConsumer = (options) => {
1827
1826
  isInitialized = true;
1828
1827
  };
1829
1828
  return {
1830
- consumerId: options.consumerId ?? uuid8(),
1829
+ consumerId: options.consumerId ?? uuid9(),
1831
1830
  get isRunning() {
1832
1831
  return isRunning;
1833
1832
  },
@@ -1927,10 +1926,6 @@ var getSQLiteEventStore = (options) => {
1927
1926
  let migrateSchema = void 0;
1928
1927
  const inlineProjections = (options.projections ?? []).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
1929
1928
  const onBeforeCommitHook = options.hooks?.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 = options.schema?.autoMigration === void 0 || options.schema?.autoMigration !== "None";
1936
1931
  }
@@ -1961,21 +1956,23 @@ var getSQLiteEventStore = (options) => {
1961
1956
  }
1962
1957
  return migrateSchema;
1963
1958
  };
1964
- const ensureSchemaExists = (connection) => {
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 = read?.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 withConnection(
1977
- ({ execute }) => readStream(execute, streamName, read),
1978
- { readonly: true }
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) => withConnection(
1997
- ({ execute }) => readStream(execute, streamName, options2),
1998
- { readonly: true }
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
- return withConnection(
2035
- ({ execute }) => streamExists(execute, streamName, options2),
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
  ...options ?? {},
2041
2041
  ...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: dumbo3({
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(""),