@event-driven-io/emmett 0.1.7 → 0.2.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/commandHandling/handleCommand.d.mts +5 -2
- package/dist/commandHandling/handleCommand.d.ts +5 -2
- package/dist/commandHandling/handleCommand.js +23 -8
- package/dist/commandHandling/handleCommand.js.map +1 -1
- package/dist/commandHandling/handleCommand.mjs +23 -8
- package/dist/commandHandling/handleCommand.mjs.map +1 -1
- package/dist/commandHandling/handleCommandWithDecider.d.mts +5 -2
- package/dist/commandHandling/handleCommandWithDecider.d.ts +5 -2
- package/dist/commandHandling/handleCommandWithDecider.js +7 -13
- package/dist/commandHandling/handleCommandWithDecider.js.map +1 -1
- package/dist/commandHandling/handleCommandWithDecider.mjs +6 -12
- package/dist/commandHandling/handleCommandWithDecider.mjs.map +1 -1
- package/dist/commandHandling/index.d.mts +2 -1
- package/dist/commandHandling/index.d.ts +2 -1
- package/dist/errors/index.d.mts +27 -0
- package/dist/errors/index.d.ts +27 -0
- package/dist/errors/index.js +57 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/index.mjs +57 -0
- package/dist/errors/index.mjs.map +1 -0
- package/dist/eventStore/eventStore.d.mts +3 -12
- package/dist/eventStore/eventStore.d.ts +3 -12
- package/dist/eventStore/expectedVersion.d.mts +3 -0
- package/dist/eventStore/expectedVersion.d.ts +3 -0
- package/dist/eventStore/expectedVersion.js +33 -0
- package/dist/eventStore/expectedVersion.js.map +1 -0
- package/dist/eventStore/expectedVersion.mjs +33 -0
- package/dist/eventStore/expectedVersion.mjs.map +1 -0
- package/dist/eventStore/expectedVersion.unit.spec.d.mts +2 -0
- package/dist/eventStore/expectedVersion.unit.spec.d.ts +2 -0
- package/dist/eventStore/expectedVersion.unit.spec.js +62 -0
- package/dist/eventStore/expectedVersion.unit.spec.js.map +1 -0
- package/dist/eventStore/expectedVersion.unit.spec.mjs +62 -0
- package/dist/eventStore/expectedVersion.unit.spec.mjs.map +1 -0
- package/dist/eventStore/inMemoryEventStore.d.mts +17 -0
- package/dist/eventStore/inMemoryEventStore.d.ts +17 -0
- package/dist/eventStore/inMemoryEventStore.js +66 -0
- package/dist/eventStore/inMemoryEventStore.js.map +1 -0
- package/dist/eventStore/inMemoryEventStore.mjs +66 -0
- package/dist/eventStore/inMemoryEventStore.mjs.map +1 -0
- package/dist/eventStore/index.d.mts +3 -1
- package/dist/eventStore/index.d.ts +3 -1
- package/dist/eventStore/index.js +2 -0
- package/dist/eventStore/index.js.map +1 -1
- package/dist/eventStore/index.mjs +2 -0
- package/dist/eventStore/index.mjs.map +1 -1
- package/dist/eventStore-DZdVGdmg.d.ts +54 -0
- package/dist/eventStore-HpGTcwOC.d.mts +54 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/testing/assertions.d.mts +4 -0
- package/dist/testing/assertions.d.ts +4 -0
- package/dist/testing/assertions.js +27 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/assertions.mjs +27 -0
- package/dist/testing/assertions.mjs.map +1 -0
- package/dist/testing/index.d.mts +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +2 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +1 -0
- package/dist/testing/index.mjs.map +1 -1
- package/dist/testing/placeholder.e2e.spec.d.mts +2 -0
- package/dist/testing/placeholder.e2e.spec.d.ts +2 -0
- package/dist/testing/placeholder.e2e.spec.js +8 -0
- package/dist/testing/placeholder.e2e.spec.js.map +1 -0
- package/dist/testing/placeholder.e2e.spec.mjs +8 -0
- package/dist/testing/placeholder.e2e.spec.mjs.map +1 -0
- package/dist/validation/index.d.mts +3 -1
- package/dist/validation/index.d.ts +3 -1
- package/dist/validation/index.js +12 -7
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/index.mjs +11 -6
- package/dist/validation/index.mjs.map +1 -1
- package/dist/validation/validation.spec.d.mts +2 -0
- package/dist/validation/validation.spec.d.ts +2 -0
- package/dist/validation/validation.spec.js +13 -0
- package/dist/validation/validation.spec.js.map +1 -0
- package/dist/validation/validation.spec.mjs +13 -0
- package/dist/validation/validation.spec.mjs.map +1 -0
- package/package.json +13 -9
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { EventStore } from '../eventStore
|
|
1
|
+
import { E as EventStore, e as ExpectedStreamVersion, d as AppendToStreamResult } from '../eventStore-HpGTcwOC.mjs';
|
|
2
2
|
import { Event } from '../typing/index.mjs';
|
|
3
|
+
import '../errors/index.mjs';
|
|
3
4
|
|
|
4
|
-
declare const CommandHandler: <State, StreamEvent extends Event>(evolve: (state: State, event: StreamEvent) => State, getInitialState: () => State, mapToStreamId
|
|
5
|
+
declare const CommandHandler: <State, StreamEvent extends Event, StreamVersion = bigint>(evolve: (state: State, event: StreamEvent) => State, getInitialState: () => State, mapToStreamId?: (id: string) => string) => (eventStore: EventStore<StreamVersion>, id: string, handle: (state: State) => StreamEvent | StreamEvent[], options?: {
|
|
6
|
+
expectedStreamVersion?: ExpectedStreamVersion<StreamVersion> | undefined;
|
|
7
|
+
} | undefined) => Promise<AppendToStreamResult<StreamVersion>>;
|
|
5
8
|
|
|
6
9
|
export { CommandHandler };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { EventStore } from '../eventStore
|
|
1
|
+
import { E as EventStore, e as ExpectedStreamVersion, d as AppendToStreamResult } from '../eventStore-DZdVGdmg.js';
|
|
2
2
|
import { Event } from '../typing/index.js';
|
|
3
|
+
import '../errors/index.js';
|
|
3
4
|
|
|
4
|
-
declare const CommandHandler: <State, StreamEvent extends Event>(evolve: (state: State, event: StreamEvent) => State, getInitialState: () => State, mapToStreamId
|
|
5
|
+
declare const CommandHandler: <State, StreamEvent extends Event, StreamVersion = bigint>(evolve: (state: State, event: StreamEvent) => State, getInitialState: () => State, mapToStreamId?: (id: string) => string) => (eventStore: EventStore<StreamVersion>, id: string, handle: (state: State) => StreamEvent | StreamEvent[], options?: {
|
|
6
|
+
expectedStreamVersion?: ExpectedStreamVersion<StreamVersion> | undefined;
|
|
7
|
+
} | undefined) => Promise<AppendToStreamResult<StreamVersion>>;
|
|
5
8
|
|
|
6
9
|
export { CommandHandler };
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }const
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _eventStore = require('../eventStore');
|
|
5
|
+
const CommandHandler = (evolve, getInitialState, mapToStreamId = (id) => id) => async (eventStore, id, handle, options) => {
|
|
2
6
|
const streamName = mapToStreamId(id);
|
|
3
|
-
const
|
|
7
|
+
const aggregationResult = await eventStore.aggregateStream(streamName, {
|
|
4
8
|
evolve,
|
|
5
|
-
getInitialState
|
|
9
|
+
getInitialState,
|
|
10
|
+
read: {
|
|
11
|
+
// expected stream version is passed to fail fast
|
|
12
|
+
// if stream is in the wrong state
|
|
13
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.expectedStreamVersion]), () => ( _eventStore.NO_CONCURRENCY_CHECK))
|
|
14
|
+
}
|
|
6
15
|
});
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
const state = _nullishCoalesce(_optionalChain([aggregationResult, 'optionalAccess', _2 => _2.state]), () => ( getInitialState()));
|
|
17
|
+
const currentStreamVersion = _optionalChain([aggregationResult, 'optionalAccess', _3 => _3.currentStreamVersion]);
|
|
18
|
+
const result = handle(state);
|
|
19
|
+
const expectedStreamVersion = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.expectedStreamVersion]), () => ( currentStreamVersion)), () => ( _eventStore.STREAM_DOES_NOT_EXIST));
|
|
20
|
+
return eventStore.appendToStream(
|
|
21
|
+
streamName,
|
|
22
|
+
Array.isArray(result) ? result : [result],
|
|
23
|
+
{
|
|
24
|
+
expectedStreamVersion
|
|
25
|
+
}
|
|
26
|
+
);
|
|
12
27
|
};
|
|
13
28
|
|
|
14
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commandHandling/handleCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/commandHandling/handleCommand.ts"],"names":[],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAIA,MAAM,iBACX,CACE,QACA,iBACA,gBAAwC,CAAC,OAAO,OAElD,OACE,YACA,IACA,QACA,YAGG;AACH,QAAM,aAAa,cAAc,EAAE;AAGnC,QAAM,oBAAoB,MAAM,WAAW,gBAGzC,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,MAAM;AAAA;AAAA;AAAA,MAGJ,uBACE,SAAS,yBAAyB;AAAA,IACtC;AAAA,EACF,CAAC;AAGD,QAAM,QAAQ,mBAAmB,SAAS,gBAAgB;AAC1D,QAAM,uBAAuB,mBAAmB;AAGhD,QAAM,SAAS,OAAO,KAAK;AAM3B,QAAM,wBACJ,SAAS,yBACT,wBACA;AAGF,SAAO,WAAW;AAAA,IAChB;AAAA,IACA,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAAA,IACxC;AAAA,MACE;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import {\n NO_CONCURRENCY_CHECK,\n STREAM_DOES_NOT_EXIST,\n type DefaultStreamVersionType,\n type EventStore,\n type ExpectedStreamVersion,\n} from '../eventStore';\nimport type { Event } from '../typing';\n\n// #region command-handler\nexport const CommandHandler =\n <State, StreamEvent extends Event, StreamVersion = DefaultStreamVersionType>(\n evolve: (state: State, event: StreamEvent) => State,\n getInitialState: () => State,\n mapToStreamId: (id: string) => string = (id) => id,\n ) =>\n async (\n eventStore: EventStore<StreamVersion>,\n id: string,\n handle: (state: State) => StreamEvent | StreamEvent[],\n options?: {\n expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;\n },\n ) => {\n const streamName = mapToStreamId(id);\n\n // 1. Aggregate the stream\n const aggregationResult = await eventStore.aggregateStream<\n State,\n StreamEvent\n >(streamName, {\n evolve,\n getInitialState,\n read: {\n // expected stream version is passed to fail fast\n // if stream is in the wrong state\n expectedStreamVersion:\n options?.expectedStreamVersion ?? NO_CONCURRENCY_CHECK,\n },\n });\n\n // 2. Use the aggregate state or the initial one (when e.g. stream does not exist)\n const state = aggregationResult?.state ?? getInitialState();\n const currentStreamVersion = aggregationResult?.currentStreamVersion;\n\n // 3. Run business logic\n const result = handle(state);\n\n // Either use:\n // - provided expected stream version,\n // - current stream version got from stream aggregation,\n // - or expect stream not to exists otherwise.\n const expectedStreamVersion: ExpectedStreamVersion<StreamVersion> =\n options?.expectedStreamVersion ??\n currentStreamVersion ??\n STREAM_DOES_NOT_EXIST;\n\n // 4. Append result to the stream\n return eventStore.appendToStream(\n streamName,\n Array.isArray(result) ? result : [result],\n {\n expectedStreamVersion,\n },\n );\n };\n// #endregion command-handler\n"]}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
NO_CONCURRENCY_CHECK,
|
|
3
|
+
STREAM_DOES_NOT_EXIST
|
|
4
|
+
} from "../eventStore";
|
|
5
|
+
const CommandHandler = (evolve, getInitialState, mapToStreamId = (id) => id) => async (eventStore, id, handle, options) => {
|
|
2
6
|
const streamName = mapToStreamId(id);
|
|
3
|
-
const
|
|
7
|
+
const aggregationResult = await eventStore.aggregateStream(streamName, {
|
|
4
8
|
evolve,
|
|
5
|
-
getInitialState
|
|
9
|
+
getInitialState,
|
|
10
|
+
read: {
|
|
11
|
+
// expected stream version is passed to fail fast
|
|
12
|
+
// if stream is in the wrong state
|
|
13
|
+
expectedStreamVersion: options?.expectedStreamVersion ?? NO_CONCURRENCY_CHECK
|
|
14
|
+
}
|
|
6
15
|
});
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
const state = aggregationResult?.state ?? getInitialState();
|
|
17
|
+
const currentStreamVersion = aggregationResult?.currentStreamVersion;
|
|
18
|
+
const result = handle(state);
|
|
19
|
+
const expectedStreamVersion = options?.expectedStreamVersion ?? currentStreamVersion ?? STREAM_DOES_NOT_EXIST;
|
|
20
|
+
return eventStore.appendToStream(
|
|
21
|
+
streamName,
|
|
22
|
+
Array.isArray(result) ? result : [result],
|
|
23
|
+
{
|
|
24
|
+
expectedStreamVersion
|
|
25
|
+
}
|
|
26
|
+
);
|
|
12
27
|
};
|
|
13
28
|
export {
|
|
14
29
|
CommandHandler
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commandHandling/handleCommand.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"sources":["../../src/commandHandling/handleCommand.ts"],"sourcesContent":["import {\n NO_CONCURRENCY_CHECK,\n STREAM_DOES_NOT_EXIST,\n type DefaultStreamVersionType,\n type EventStore,\n type ExpectedStreamVersion,\n} from '../eventStore';\nimport type { Event } from '../typing';\n\n// #region command-handler\nexport const CommandHandler =\n <State, StreamEvent extends Event, StreamVersion = DefaultStreamVersionType>(\n evolve: (state: State, event: StreamEvent) => State,\n getInitialState: () => State,\n mapToStreamId: (id: string) => string = (id) => id,\n ) =>\n async (\n eventStore: EventStore<StreamVersion>,\n id: string,\n handle: (state: State) => StreamEvent | StreamEvent[],\n options?: {\n expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;\n },\n ) => {\n const streamName = mapToStreamId(id);\n\n // 1. Aggregate the stream\n const aggregationResult = await eventStore.aggregateStream<\n State,\n StreamEvent\n >(streamName, {\n evolve,\n getInitialState,\n read: {\n // expected stream version is passed to fail fast\n // if stream is in the wrong state\n expectedStreamVersion:\n options?.expectedStreamVersion ?? NO_CONCURRENCY_CHECK,\n },\n });\n\n // 2. Use the aggregate state or the initial one (when e.g. stream does not exist)\n const state = aggregationResult?.state ?? getInitialState();\n const currentStreamVersion = aggregationResult?.currentStreamVersion;\n\n // 3. Run business logic\n const result = handle(state);\n\n // Either use:\n // - provided expected stream version,\n // - current stream version got from stream aggregation,\n // - or expect stream not to exists otherwise.\n const expectedStreamVersion: ExpectedStreamVersion<StreamVersion> =\n options?.expectedStreamVersion ??\n currentStreamVersion ??\n STREAM_DOES_NOT_EXIST;\n\n // 4. Append result to the stream\n return eventStore.appendToStream(\n streamName,\n Array.isArray(result) ? result : [result],\n {\n expectedStreamVersion,\n },\n );\n };\n// #endregion command-handler\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAIA,MAAM,iBACX,CACE,QACA,iBACA,gBAAwC,CAAC,OAAO,OAElD,OACE,YACA,IACA,QACA,YAGG;AACH,QAAM,aAAa,cAAc,EAAE;AAGnC,QAAM,oBAAoB,MAAM,WAAW,gBAGzC,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,MAAM;AAAA;AAAA;AAAA,MAGJ,uBACE,SAAS,yBAAyB;AAAA,IACtC;AAAA,EACF,CAAC;AAGD,QAAM,QAAQ,mBAAmB,SAAS,gBAAgB;AAC1D,QAAM,uBAAuB,mBAAmB;AAGhD,QAAM,SAAS,OAAO,KAAK;AAM3B,QAAM,wBACJ,SAAS,yBACT,wBACA;AAGF,SAAO,WAAW;AAAA,IAChB;AAAA,IACA,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAAA,IACxC;AAAA,MACE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { EventStore } from '../eventStore
|
|
1
|
+
import { E as EventStore, e as ExpectedStreamVersion, d as AppendToStreamResult } from '../eventStore-HpGTcwOC.mjs';
|
|
2
2
|
import { Command, Event, Decider } from '../typing/index.mjs';
|
|
3
|
+
import '../errors/index.mjs';
|
|
3
4
|
|
|
4
|
-
declare const DeciderCommandHandler: <State, CommandType extends Command, StreamEvent extends Event>({ decide, evolve, getInitialState, }: Decider<State, CommandType, StreamEvent>, mapToStreamId
|
|
5
|
+
declare const DeciderCommandHandler: <State, CommandType extends Command, StreamEvent extends Event, StreamVersion = bigint>({ decide, evolve, getInitialState, }: Decider<State, CommandType, StreamEvent>, mapToStreamId?: (id: string) => string) => (eventStore: EventStore<StreamVersion>, id: string, command: CommandType, options?: {
|
|
6
|
+
expectedStreamVersion?: ExpectedStreamVersion<StreamVersion> | undefined;
|
|
7
|
+
} | undefined) => Promise<AppendToStreamResult<StreamVersion>>;
|
|
5
8
|
|
|
6
9
|
export { DeciderCommandHandler };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { EventStore } from '../eventStore
|
|
1
|
+
import { E as EventStore, e as ExpectedStreamVersion, d as AppendToStreamResult } from '../eventStore-DZdVGdmg.js';
|
|
2
2
|
import { Command, Event, Decider } from '../typing/index.js';
|
|
3
|
+
import '../errors/index.js';
|
|
3
4
|
|
|
4
|
-
declare const DeciderCommandHandler: <State, CommandType extends Command, StreamEvent extends Event>({ decide, evolve, getInitialState, }: Decider<State, CommandType, StreamEvent>, mapToStreamId
|
|
5
|
+
declare const DeciderCommandHandler: <State, CommandType extends Command, StreamEvent extends Event, StreamVersion = bigint>({ decide, evolve, getInitialState, }: Decider<State, CommandType, StreamEvent>, mapToStreamId?: (id: string) => string) => (eventStore: EventStore<StreamVersion>, id: string, command: CommandType, options?: {
|
|
6
|
+
expectedStreamVersion?: ExpectedStreamVersion<StreamVersion> | undefined;
|
|
7
|
+
} | undefined) => Promise<AppendToStreamResult<StreamVersion>>;
|
|
5
8
|
|
|
6
9
|
export { DeciderCommandHandler };
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _handleCommand = require('./handleCommand');
|
|
2
|
+
const DeciderCommandHandler = ({
|
|
2
3
|
decide,
|
|
3
4
|
evolve,
|
|
4
5
|
getInitialState
|
|
5
|
-
}, mapToStreamId) => async (eventStore, id, command) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
const result = decide(command, _nullishCoalesce(state, () => ( getInitialState())));
|
|
12
|
-
if (Array.isArray(result))
|
|
13
|
-
return eventStore.appendToStream(streamName, ...result);
|
|
14
|
-
else
|
|
15
|
-
return eventStore.appendToStream(streamName, result);
|
|
16
|
-
};
|
|
6
|
+
}, mapToStreamId = (id) => id) => async (eventStore, id, command, options) => _handleCommand.CommandHandler.call(void 0,
|
|
7
|
+
evolve,
|
|
8
|
+
getInitialState,
|
|
9
|
+
mapToStreamId
|
|
10
|
+
)(eventStore, id, (state) => decide(command, state), options);
|
|
17
11
|
|
|
18
12
|
|
|
19
13
|
exports.DeciderCommandHandler = DeciderCommandHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commandHandling/handleCommandWithDecider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/commandHandling/handleCommandWithDecider.ts"],"names":[],"mappings":"AAOA,SAAS,sBAAsB;AAGxB,MAAM,wBACX,CAME;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF,GACA,gBAAwC,CAAC,OAAO,OAElD,OACE,YACA,IACA,SACA,YAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF,EAAE,YAAY,IAAI,CAAC,UAAU,OAAO,SAAS,KAAK,GAAG,OAAO","sourcesContent":["import type {\n DefaultStreamVersionType,\n EventStore,\n ExpectedStreamVersion,\n} from '../eventStore';\nimport type { Command, Event } from '../typing';\nimport type { Decider } from '../typing/decider';\nimport { CommandHandler } from './handleCommand';\n\n// #region command-handler\nexport const DeciderCommandHandler =\n <\n State,\n CommandType extends Command,\n StreamEvent extends Event,\n StreamVersion = DefaultStreamVersionType,\n >(\n {\n decide,\n evolve,\n getInitialState,\n }: Decider<State, CommandType, StreamEvent>,\n mapToStreamId: (id: string) => string = (id) => id,\n ) =>\n async (\n eventStore: EventStore<StreamVersion>,\n id: string,\n command: CommandType,\n options?: {\n expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;\n },\n ) =>\n CommandHandler<State, StreamEvent, StreamVersion>(\n evolve,\n getInitialState,\n mapToStreamId,\n )(eventStore, id, (state) => decide(command, state), options);\n// #endregion command-handler\n"]}
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
+
import { CommandHandler } from "./handleCommand";
|
|
1
2
|
const DeciderCommandHandler = ({
|
|
2
3
|
decide,
|
|
3
4
|
evolve,
|
|
4
5
|
getInitialState
|
|
5
|
-
}, mapToStreamId) => async (eventStore, id, command) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
const result = decide(command, state ?? getInitialState());
|
|
12
|
-
if (Array.isArray(result))
|
|
13
|
-
return eventStore.appendToStream(streamName, ...result);
|
|
14
|
-
else
|
|
15
|
-
return eventStore.appendToStream(streamName, result);
|
|
16
|
-
};
|
|
6
|
+
}, mapToStreamId = (id) => id) => async (eventStore, id, command, options) => CommandHandler(
|
|
7
|
+
evolve,
|
|
8
|
+
getInitialState,
|
|
9
|
+
mapToStreamId
|
|
10
|
+
)(eventStore, id, (state) => decide(command, state), options);
|
|
17
11
|
export {
|
|
18
12
|
DeciderCommandHandler
|
|
19
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commandHandling/handleCommandWithDecider.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/commandHandling/handleCommandWithDecider.ts"],"sourcesContent":["import type {\n DefaultStreamVersionType,\n EventStore,\n ExpectedStreamVersion,\n} from '../eventStore';\nimport type { Command, Event } from '../typing';\nimport type { Decider } from '../typing/decider';\nimport { CommandHandler } from './handleCommand';\n\n// #region command-handler\nexport const DeciderCommandHandler =\n <\n State,\n CommandType extends Command,\n StreamEvent extends Event,\n StreamVersion = DefaultStreamVersionType,\n >(\n {\n decide,\n evolve,\n getInitialState,\n }: Decider<State, CommandType, StreamEvent>,\n mapToStreamId: (id: string) => string = (id) => id,\n ) =>\n async (\n eventStore: EventStore<StreamVersion>,\n id: string,\n command: CommandType,\n options?: {\n expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;\n },\n ) =>\n CommandHandler<State, StreamEvent, StreamVersion>(\n evolve,\n getInitialState,\n mapToStreamId,\n )(eventStore, id, (state) => decide(command, state), options);\n// #endregion command-handler\n"],"mappings":"AAOA,SAAS,sBAAsB;AAGxB,MAAM,wBACX,CAME;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF,GACA,gBAAwC,CAAC,OAAO,OAElD,OACE,YACA,IACA,SACA,YAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF,EAAE,YAAY,IAAI,CAAC,UAAU,OAAO,SAAS,KAAK,GAAG,OAAO;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CommandHandler } from './handleCommand.mjs';
|
|
2
2
|
export { DeciderCommandHandler } from './handleCommandWithDecider.mjs';
|
|
3
|
-
import '../eventStore
|
|
3
|
+
import '../eventStore-HpGTcwOC.mjs';
|
|
4
4
|
import '../typing/index.mjs';
|
|
5
|
+
import '../errors/index.mjs';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare class EmmettError extends Error {
|
|
2
|
+
errorCode: number;
|
|
3
|
+
constructor(options?: {
|
|
4
|
+
errorCode: number;
|
|
5
|
+
message?: string;
|
|
6
|
+
} | string | number);
|
|
7
|
+
}
|
|
8
|
+
declare class ConcurrencyError extends EmmettError {
|
|
9
|
+
current: string | undefined;
|
|
10
|
+
expected: string;
|
|
11
|
+
constructor(current: string | undefined, expected: string, message?: string);
|
|
12
|
+
}
|
|
13
|
+
declare class ValidationError extends EmmettError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
declare class IllegalStateError extends EmmettError {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
declare class NotFoundError extends EmmettError {
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { ConcurrencyError, EmmettError, IllegalStateError, NotFoundError, ValidationError };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare class EmmettError extends Error {
|
|
2
|
+
errorCode: number;
|
|
3
|
+
constructor(options?: {
|
|
4
|
+
errorCode: number;
|
|
5
|
+
message?: string;
|
|
6
|
+
} | string | number);
|
|
7
|
+
}
|
|
8
|
+
declare class ConcurrencyError extends EmmettError {
|
|
9
|
+
current: string | undefined;
|
|
10
|
+
expected: string;
|
|
11
|
+
constructor(current: string | undefined, expected: string, message?: string);
|
|
12
|
+
}
|
|
13
|
+
declare class ValidationError extends EmmettError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
declare class IllegalStateError extends EmmettError {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
declare class NotFoundError extends EmmettError {
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { ConcurrencyError, EmmettError, IllegalStateError, NotFoundError, ValidationError };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _validation = require('../validation');
|
|
2
|
+
class EmmettError extends Error {
|
|
3
|
+
|
|
4
|
+
constructor(options) {
|
|
5
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : _validation.isNumber.call(void 0, options) ? options : 500;
|
|
6
|
+
const message = options && typeof options === "object" && "message" in options ? options.message : _validation.isString.call(void 0, options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
7
|
+
super(message);
|
|
8
|
+
this.errorCode = errorCode;
|
|
9
|
+
Object.setPrototypeOf(this, EmmettError.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class ConcurrencyError extends EmmettError {
|
|
13
|
+
constructor(current, expected, message) {
|
|
14
|
+
super({
|
|
15
|
+
errorCode: 412,
|
|
16
|
+
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])}`))
|
|
17
|
+
});
|
|
18
|
+
this.current = current;
|
|
19
|
+
this.expected = expected;
|
|
20
|
+
Object.setPrototypeOf(this, ConcurrencyError.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class ValidationError extends EmmettError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super({
|
|
26
|
+
errorCode: 400,
|
|
27
|
+
message: _nullishCoalesce(message, () => ( `Validation Error ocurred during Emmett processing`))
|
|
28
|
+
});
|
|
29
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class IllegalStateError extends EmmettError {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super({
|
|
35
|
+
errorCode: 403,
|
|
36
|
+
message: _nullishCoalesce(message, () => ( `Illegal State ocurred during Emmett processing`))
|
|
37
|
+
});
|
|
38
|
+
Object.setPrototypeOf(this, IllegalStateError.prototype);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class NotFoundError extends EmmettError {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super({
|
|
44
|
+
errorCode: 404,
|
|
45
|
+
message: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.message]), () => ( (_optionalChain([options, 'optionalAccess', _4 => _4.id]) ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : _optionalChain([options, 'optionalAccess', _5 => _5.type]) ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")))
|
|
46
|
+
});
|
|
47
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
exports.ConcurrencyError = ConcurrencyError; exports.EmmettError = EmmettError; exports.IllegalStateError = IllegalStateError; exports.NotFoundError = NotFoundError; exports.ValidationError = ValidationError;
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,SAAS,UAAU,gBAAgB;AAE5B,MAAM,oBAAoB,MAAM;AAAA,EAC9B;AAAA,EAEP,YACE,SACA;AACA,UAAM,YACJ,WAAW,OAAO,YAAY,YAAY,eAAe,UACrD,QAAQ,YACR,SAAS,OAAO,IACd,UACA;AACR,UAAM,UACJ,WAAW,OAAO,YAAY,YAAY,aAAa,UACnD,QAAQ,UACR,SAAS,OAAO,IACd,UACA,2BAA2B,SAAS;AAE5C,UAAM,OAAO;AACb,SAAK,YAAY;AAGjB,WAAO,eAAe,MAAM,YAAY,SAAS;AAAA,EACnD;AACF;AAEO,MAAM,yBAAyB,YAAY;AAAA,EAChD,YACS,SACA,UACP,SACA;AACA,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SACE,WACA,oBAAoB,SAAS,SAAS,CAAC,2BAA2B,SAAS,SAAS,CAAC;AAAA,IACzF,CAAC;AATM;AACA;AAWP,WAAO,eAAe,MAAM,iBAAiB,SAAS;AAAA,EACxD;AACF;AAEO,MAAM,wBAAwB,YAAY;AAAA,EAC/C,YAAY,SAAkB;AAC5B,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SAAS,WAAW;AAAA,IACtB,CAAC;AAGD,WAAO,eAAe,MAAM,gBAAgB,SAAS;AAAA,EACvD;AACF;AAEO,MAAM,0BAA0B,YAAY;AAAA,EACjD,YAAY,SAAkB;AAC5B,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SAAS,WAAW;AAAA,IACtB,CAAC;AAGD,WAAO,eAAe,MAAM,kBAAkB,SAAS;AAAA,EACzD;AACF;AAEO,MAAM,sBAAsB,YAAY;AAAA,EAC7C,YAAY,SAA0D;AACpE,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SACE,SAAS,YACR,SAAS,KACN,QAAQ,OACN,GAAG,QAAQ,IAAI,SAAS,QAAQ,EAAE,4CAClC,cAAc,QAAQ,EAAE,4CAC1B,SAAS,OACP,GAAG,QAAQ,IAAI,4CACf;AAAA,IACV,CAAC;AAGD,WAAO,eAAe,MAAM,cAAc,SAAS;AAAA,EACrD;AACF","sourcesContent":["import { isNumber, isString } from '../validation';\n\nexport class EmmettError extends Error {\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : 500;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: 412,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 400,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 403,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: 404,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isNumber, isString } from "../validation";
|
|
2
|
+
class EmmettError extends Error {
|
|
3
|
+
errorCode;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
|
|
6
|
+
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
7
|
+
super(message);
|
|
8
|
+
this.errorCode = errorCode;
|
|
9
|
+
Object.setPrototypeOf(this, EmmettError.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class ConcurrencyError extends EmmettError {
|
|
13
|
+
constructor(current, expected, message) {
|
|
14
|
+
super({
|
|
15
|
+
errorCode: 412,
|
|
16
|
+
message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
|
|
17
|
+
});
|
|
18
|
+
this.current = current;
|
|
19
|
+
this.expected = expected;
|
|
20
|
+
Object.setPrototypeOf(this, ConcurrencyError.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class ValidationError extends EmmettError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super({
|
|
26
|
+
errorCode: 400,
|
|
27
|
+
message: message ?? `Validation Error ocurred during Emmett processing`
|
|
28
|
+
});
|
|
29
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class IllegalStateError extends EmmettError {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super({
|
|
35
|
+
errorCode: 403,
|
|
36
|
+
message: message ?? `Illegal State ocurred during Emmett processing`
|
|
37
|
+
});
|
|
38
|
+
Object.setPrototypeOf(this, IllegalStateError.prototype);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class NotFoundError extends EmmettError {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super({
|
|
44
|
+
errorCode: 404,
|
|
45
|
+
message: options?.message ?? (options?.id ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : options?.type ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")
|
|
46
|
+
});
|
|
47
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
ConcurrencyError,
|
|
52
|
+
EmmettError,
|
|
53
|
+
IllegalStateError,
|
|
54
|
+
NotFoundError,
|
|
55
|
+
ValidationError
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/errors/index.ts"],"sourcesContent":["import { isNumber, isString } from '../validation';\n\nexport class EmmettError extends Error {\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : 500;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: 412,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 400,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 403,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: 404,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n"],"mappings":"AAAA,SAAS,UAAU,gBAAgB;AAE5B,MAAM,oBAAoB,MAAM;AAAA,EAC9B;AAAA,EAEP,YACE,SACA;AACA,UAAM,YACJ,WAAW,OAAO,YAAY,YAAY,eAAe,UACrD,QAAQ,YACR,SAAS,OAAO,IACd,UACA;AACR,UAAM,UACJ,WAAW,OAAO,YAAY,YAAY,aAAa,UACnD,QAAQ,UACR,SAAS,OAAO,IACd,UACA,2BAA2B,SAAS;AAE5C,UAAM,OAAO;AACb,SAAK,YAAY;AAGjB,WAAO,eAAe,MAAM,YAAY,SAAS;AAAA,EACnD;AACF;AAEO,MAAM,yBAAyB,YAAY;AAAA,EAChD,YACS,SACA,UACP,SACA;AACA,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SACE,WACA,oBAAoB,SAAS,SAAS,CAAC,2BAA2B,SAAS,SAAS,CAAC;AAAA,IACzF,CAAC;AATM;AACA;AAWP,WAAO,eAAe,MAAM,iBAAiB,SAAS;AAAA,EACxD;AACF;AAEO,MAAM,wBAAwB,YAAY;AAAA,EAC/C,YAAY,SAAkB;AAC5B,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SAAS,WAAW;AAAA,IACtB,CAAC;AAGD,WAAO,eAAe,MAAM,gBAAgB,SAAS;AAAA,EACvD;AACF;AAEO,MAAM,0BAA0B,YAAY;AAAA,EACjD,YAAY,SAAkB;AAC5B,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SAAS,WAAW;AAAA,IACtB,CAAC;AAGD,WAAO,eAAe,MAAM,kBAAkB,SAAS;AAAA,EACzD;AACF;AAEO,MAAM,sBAAsB,YAAY;AAAA,EAC7C,YAAY,SAA0D;AACpE,UAAM;AAAA,MACJ,WAAW;AAAA,MACX,SACE,SAAS,YACR,SAAS,KACN,QAAQ,OACN,GAAG,QAAQ,IAAI,SAAS,QAAQ,EAAE,4CAClC,cAAc,QAAQ,EAAE,4CAC1B,SAAS,OACP,GAAG,QAAQ,IAAI,4CACf;AAAA,IACV,CAAC;AAGD,WAAO,eAAe,MAAM,cAAc,SAAS;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
aggregateStream<Entity, E extends Event>(streamName: string, options: {
|
|
5
|
-
evolve: (currentState: Entity, event: E) => Entity;
|
|
6
|
-
getInitialState: () => Entity;
|
|
7
|
-
}): Promise<Entity | null>;
|
|
8
|
-
readStream<E extends Event>(streamName: string): Promise<E[]>;
|
|
9
|
-
appendToStream<E extends Event, NextExpectedVersion = bigint>(streamId: string, ...events: E[]): Promise<NextExpectedVersion>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type { EventStore };
|
|
1
|
+
import '../typing/index.mjs';
|
|
2
|
+
export { A as AggregateStreamOptions, b as AggregateStreamResult, c as AppendToStreamOptions, d as AppendToStreamResult, D as DefaultStreamVersionType, E as EventStore, R as ReadStreamOptions, a as ReadStreamResult } from '../eventStore-HpGTcwOC.mjs';
|
|
3
|
+
import '../errors/index.mjs';
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
aggregateStream<Entity, E extends Event>(streamName: string, options: {
|
|
5
|
-
evolve: (currentState: Entity, event: E) => Entity;
|
|
6
|
-
getInitialState: () => Entity;
|
|
7
|
-
}): Promise<Entity | null>;
|
|
8
|
-
readStream<E extends Event>(streamName: string): Promise<E[]>;
|
|
9
|
-
appendToStream<E extends Event, NextExpectedVersion = bigint>(streamId: string, ...events: E[]): Promise<NextExpectedVersion>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type { EventStore };
|
|
1
|
+
import '../typing/index.js';
|
|
2
|
+
export { A as AggregateStreamOptions, b as AggregateStreamResult, c as AppendToStreamOptions, d as AppendToStreamResult, D as DefaultStreamVersionType, E as EventStore, R as ReadStreamOptions, a as ReadStreamResult } from '../eventStore-DZdVGdmg.js';
|
|
3
|
+
import '../errors/index.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import '../errors/index.mjs';
|
|
2
|
+
import '../typing/index.mjs';
|
|
3
|
+
export { e as ExpectedStreamVersion, g as ExpectedStreamVersionGeneral, f as ExpectedStreamVersionWithValue, j as ExpectedVersionConflictError, N as NO_CONCURRENCY_CHECK, h as STREAM_DOES_NOT_EXIST, S as STREAM_EXISTS, i as assertExpectedVersionMatchesCurrent, m as matchesExpectedVersion } from '../eventStore-HpGTcwOC.mjs';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import '../errors/index.js';
|
|
2
|
+
import '../typing/index.js';
|
|
3
|
+
export { e as ExpectedStreamVersion, g as ExpectedStreamVersionGeneral, f as ExpectedStreamVersionWithValue, j as ExpectedVersionConflictError, N as NO_CONCURRENCY_CHECK, h as STREAM_DOES_NOT_EXIST, S as STREAM_EXISTS, i as assertExpectedVersionMatchesCurrent, m as matchesExpectedVersion } from '../eventStore-DZdVGdmg.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _errors = require('../errors');
|
|
2
|
+
const STREAM_EXISTS = "STREAM_EXISTS";
|
|
3
|
+
const STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
|
|
4
|
+
const NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
|
|
5
|
+
const matchesExpectedVersion = (current, expected) => {
|
|
6
|
+
if (expected === NO_CONCURRENCY_CHECK)
|
|
7
|
+
return true;
|
|
8
|
+
if (expected == STREAM_DOES_NOT_EXIST)
|
|
9
|
+
return current === void 0;
|
|
10
|
+
if (expected == STREAM_EXISTS)
|
|
11
|
+
return current !== void 0;
|
|
12
|
+
return current === expected;
|
|
13
|
+
};
|
|
14
|
+
const assertExpectedVersionMatchesCurrent = (current, expected) => {
|
|
15
|
+
expected ??= NO_CONCURRENCY_CHECK;
|
|
16
|
+
if (!matchesExpectedVersion(current, expected))
|
|
17
|
+
throw new ExpectedVersionConflictError(current, expected);
|
|
18
|
+
};
|
|
19
|
+
class ExpectedVersionConflictError extends _errors.ConcurrencyError {
|
|
20
|
+
constructor(current, expected) {
|
|
21
|
+
super(_optionalChain([current, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]), _optionalChain([expected, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]));
|
|
22
|
+
Object.setPrototypeOf(this, ExpectedVersionConflictError.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.ExpectedVersionConflictError = ExpectedVersionConflictError; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.STREAM_DOES_NOT_EXIST = STREAM_DOES_NOT_EXIST; exports.STREAM_EXISTS = STREAM_EXISTS; exports.assertExpectedVersionMatchesCurrent = assertExpectedVersionMatchesCurrent; exports.matchesExpectedVersion = matchesExpectedVersion;
|
|
33
|
+
//# sourceMappingURL=expectedVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/eventStore/expectedVersion.ts"],"names":[],"mappings":"AAAA,SAAS,wBAAwB;AAiB1B,MAAM,gBAAgB;AACtB,MAAM,wBACX;AACK,MAAM,uBACX;AAEK,MAAM,yBAAyB,CAGpC,SACA,aACY;AACZ,MAAI,aAAa;AAAsB,WAAO;AAE9C,MAAI,YAAY;AAAuB,WAAO,YAAY;AAE1D,MAAI,YAAY;AAAe,WAAO,YAAY;AAElD,SAAO,YAAY;AACrB;AAEO,MAAM,sCAAsC,CAGjD,SACA,aACS;AACT,eAAa;AAEb,MAAI,CAAC,uBAAuB,SAAS,QAAQ;AAC3C,UAAM,IAAI,6BAA6B,SAAS,QAAQ;AAC5D;AAEO,MAAM,qCAEH,iBAAiB;AAAA,EACzB,YACE,SACA,UACA;AACA,UAAM,SAAS,SAAS,GAAG,UAAU,SAAS,CAAC;AAG/C,WAAO,eAAe,MAAM,6BAA6B,SAAS;AAAA,EACpE;AACF","sourcesContent":["import { ConcurrencyError } from '../errors';\nimport type { Flavour } from '../typing';\nimport type { DefaultStreamVersionType } from './eventStore';\n\nexport type ExpectedStreamVersion<VersionType = DefaultStreamVersionType> =\n | ExpectedStreamVersionWithValue<VersionType>\n | ExpectedStreamVersionGeneral;\n\nexport type ExpectedStreamVersionWithValue<\n VersionType = DefaultStreamVersionType,\n> = Flavour<VersionType, 'StreamVersion'>;\n\nexport type ExpectedStreamVersionGeneral = Flavour<\n 'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK',\n 'StreamVersion'\n>;\n\nexport const STREAM_EXISTS = 'STREAM_EXISTS' as ExpectedStreamVersionGeneral;\nexport const STREAM_DOES_NOT_EXIST =\n 'STREAM_DOES_NOT_EXIST' as ExpectedStreamVersionGeneral;\nexport const NO_CONCURRENCY_CHECK =\n 'NO_CONCURRENCY_CHECK' as ExpectedStreamVersionGeneral;\n\nexport const matchesExpectedVersion = <\n StreamVersion = DefaultStreamVersionType,\n>(\n current: StreamVersion | undefined,\n expected: ExpectedStreamVersion<StreamVersion>,\n): boolean => {\n if (expected === NO_CONCURRENCY_CHECK) return true;\n\n if (expected == STREAM_DOES_NOT_EXIST) return current === undefined;\n\n if (expected == STREAM_EXISTS) return current !== undefined;\n\n return current === expected;\n};\n\nexport const assertExpectedVersionMatchesCurrent = <\n StreamVersion = DefaultStreamVersionType,\n>(\n current: StreamVersion | undefined,\n expected: ExpectedStreamVersion<StreamVersion> | undefined,\n): void => {\n expected ??= NO_CONCURRENCY_CHECK;\n\n if (!matchesExpectedVersion(current, expected))\n throw new ExpectedVersionConflictError(current, expected);\n};\n\nexport class ExpectedVersionConflictError<\n VersionType = DefaultStreamVersionType,\n> extends ConcurrencyError {\n constructor(\n current: VersionType | undefined,\n expected: ExpectedStreamVersion<VersionType>,\n ) {\n super(current?.toString(), expected?.toString());\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ExpectedVersionConflictError.prototype);\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConcurrencyError } from "../errors";
|
|
2
|
+
const STREAM_EXISTS = "STREAM_EXISTS";
|
|
3
|
+
const STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
|
|
4
|
+
const NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
|
|
5
|
+
const matchesExpectedVersion = (current, expected) => {
|
|
6
|
+
if (expected === NO_CONCURRENCY_CHECK)
|
|
7
|
+
return true;
|
|
8
|
+
if (expected == STREAM_DOES_NOT_EXIST)
|
|
9
|
+
return current === void 0;
|
|
10
|
+
if (expected == STREAM_EXISTS)
|
|
11
|
+
return current !== void 0;
|
|
12
|
+
return current === expected;
|
|
13
|
+
};
|
|
14
|
+
const assertExpectedVersionMatchesCurrent = (current, expected) => {
|
|
15
|
+
expected ??= NO_CONCURRENCY_CHECK;
|
|
16
|
+
if (!matchesExpectedVersion(current, expected))
|
|
17
|
+
throw new ExpectedVersionConflictError(current, expected);
|
|
18
|
+
};
|
|
19
|
+
class ExpectedVersionConflictError extends ConcurrencyError {
|
|
20
|
+
constructor(current, expected) {
|
|
21
|
+
super(current?.toString(), expected?.toString());
|
|
22
|
+
Object.setPrototypeOf(this, ExpectedVersionConflictError.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
ExpectedVersionConflictError,
|
|
27
|
+
NO_CONCURRENCY_CHECK,
|
|
28
|
+
STREAM_DOES_NOT_EXIST,
|
|
29
|
+
STREAM_EXISTS,
|
|
30
|
+
assertExpectedVersionMatchesCurrent,
|
|
31
|
+
matchesExpectedVersion
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=expectedVersion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/eventStore/expectedVersion.ts"],"sourcesContent":["import { ConcurrencyError } from '../errors';\nimport type { Flavour } from '../typing';\nimport type { DefaultStreamVersionType } from './eventStore';\n\nexport type ExpectedStreamVersion<VersionType = DefaultStreamVersionType> =\n | ExpectedStreamVersionWithValue<VersionType>\n | ExpectedStreamVersionGeneral;\n\nexport type ExpectedStreamVersionWithValue<\n VersionType = DefaultStreamVersionType,\n> = Flavour<VersionType, 'StreamVersion'>;\n\nexport type ExpectedStreamVersionGeneral = Flavour<\n 'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK',\n 'StreamVersion'\n>;\n\nexport const STREAM_EXISTS = 'STREAM_EXISTS' as ExpectedStreamVersionGeneral;\nexport const STREAM_DOES_NOT_EXIST =\n 'STREAM_DOES_NOT_EXIST' as ExpectedStreamVersionGeneral;\nexport const NO_CONCURRENCY_CHECK =\n 'NO_CONCURRENCY_CHECK' as ExpectedStreamVersionGeneral;\n\nexport const matchesExpectedVersion = <\n StreamVersion = DefaultStreamVersionType,\n>(\n current: StreamVersion | undefined,\n expected: ExpectedStreamVersion<StreamVersion>,\n): boolean => {\n if (expected === NO_CONCURRENCY_CHECK) return true;\n\n if (expected == STREAM_DOES_NOT_EXIST) return current === undefined;\n\n if (expected == STREAM_EXISTS) return current !== undefined;\n\n return current === expected;\n};\n\nexport const assertExpectedVersionMatchesCurrent = <\n StreamVersion = DefaultStreamVersionType,\n>(\n current: StreamVersion | undefined,\n expected: ExpectedStreamVersion<StreamVersion> | undefined,\n): void => {\n expected ??= NO_CONCURRENCY_CHECK;\n\n if (!matchesExpectedVersion(current, expected))\n throw new ExpectedVersionConflictError(current, expected);\n};\n\nexport class ExpectedVersionConflictError<\n VersionType = DefaultStreamVersionType,\n> extends ConcurrencyError {\n constructor(\n current: VersionType | undefined,\n expected: ExpectedStreamVersion<VersionType>,\n ) {\n super(current?.toString(), expected?.toString());\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ExpectedVersionConflictError.prototype);\n }\n}\n"],"mappings":"AAAA,SAAS,wBAAwB;AAiB1B,MAAM,gBAAgB;AACtB,MAAM,wBACX;AACK,MAAM,uBACX;AAEK,MAAM,yBAAyB,CAGpC,SACA,aACY;AACZ,MAAI,aAAa;AAAsB,WAAO;AAE9C,MAAI,YAAY;AAAuB,WAAO,YAAY;AAE1D,MAAI,YAAY;AAAe,WAAO,YAAY;AAElD,SAAO,YAAY;AACrB;AAEO,MAAM,sCAAsC,CAGjD,SACA,aACS;AACT,eAAa;AAEb,MAAI,CAAC,uBAAuB,SAAS,QAAQ;AAC3C,UAAM,IAAI,6BAA6B,SAAS,QAAQ;AAC5D;AAEO,MAAM,qCAEH,iBAAiB;AAAA,EACzB,YACE,SACA,UACA;AACA,UAAM,SAAS,SAAS,GAAG,UAAU,SAAS,CAAC;AAG/C,WAAO,eAAe,MAAM,6BAA6B,SAAS;AAAA,EACpE;AACF;","names":[]}
|