@event-driven-io/emmett 0.3.0 → 0.5.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 +6 -3
- package/dist/commandHandling/handleCommand.d.ts +6 -3
- package/dist/commandHandling/handleCommand.js +33 -29
- package/dist/commandHandling/handleCommand.js.map +1 -1
- package/dist/commandHandling/handleCommand.mjs +4 -2
- package/dist/commandHandling/handleCommand.mjs.map +1 -1
- package/dist/commandHandling/handleCommand.unit.spec.js +83 -0
- package/dist/commandHandling/handleCommand.unit.spec.js.map +1 -0
- package/dist/commandHandling/handleCommand.unit.spec.mjs +93 -0
- package/dist/commandHandling/handleCommand.unit.spec.mjs.map +1 -0
- package/dist/commandHandling/handleCommandWithDecider.d.mts +3 -2
- package/dist/commandHandling/handleCommandWithDecider.d.ts +3 -2
- package/dist/commandHandling/handleCommandWithDecider.js +4 -13
- package/dist/commandHandling/handleCommandWithDecider.js.map +1 -1
- package/dist/commandHandling/index.d.mts +1 -1
- package/dist/commandHandling/index.d.ts +1 -1
- package/dist/commandHandling/index.js +2 -2
- package/dist/commandHandling/index.js.map +1 -1
- package/dist/errors/index.js +67 -51
- package/dist/errors/index.js.map +1 -1
- package/dist/eventStore/eventStore.js +2 -1
- package/dist/eventStore/eventStore.js.map +1 -1
- package/dist/eventStore/expectedVersion.js +22 -29
- package/dist/eventStore/expectedVersion.js.map +1 -1
- package/dist/eventStore/expectedVersion.unit.spec.js +48 -60
- package/dist/eventStore/expectedVersion.unit.spec.js.map +1 -1
- package/dist/eventStore/inMemoryEventStore.js +65 -64
- package/dist/eventStore/inMemoryEventStore.js.map +1 -1
- package/dist/eventStore/inMemoryEventStore.mjs +6 -1
- package/dist/eventStore/inMemoryEventStore.mjs.map +1 -1
- package/dist/eventStore/inMemoryEventStore.unit.spec.d.mts +2 -0
- package/dist/eventStore/inMemoryEventStore.unit.spec.d.ts +2 -0
- package/dist/eventStore/inMemoryEventStore.unit.spec.js +85 -0
- package/dist/eventStore/inMemoryEventStore.unit.spec.js.map +1 -0
- package/dist/eventStore/inMemoryEventStore.unit.spec.mjs +81 -0
- package/dist/eventStore/inMemoryEventStore.unit.spec.mjs.map +1 -0
- package/dist/eventStore/index.js +3 -3
- package/dist/eventStore/index.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/serialization/index.js +1 -1
- package/dist/serialization/index.js.map +1 -1
- package/dist/serialization/json/JSONParser.js +16 -20
- package/dist/serialization/json/JSONParser.js.map +1 -1
- package/dist/serialization/json/index.js +1 -1
- package/dist/serialization/json/index.js.map +1 -1
- package/dist/testing/assertions.js +12 -24
- package/dist/testing/assertions.js.map +1 -1
- package/dist/testing/deciderSpecification.js +40 -39
- package/dist/testing/deciderSpecification.js.map +1 -1
- package/dist/testing/index.js +2 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/typing/command.js +2 -1
- package/dist/typing/command.js.map +1 -1
- package/dist/typing/decider.js +2 -1
- package/dist/typing/decider.js.map +1 -1
- package/dist/typing/event.js +2 -1
- package/dist/typing/event.js.map +1 -1
- package/dist/typing/index.js +4 -4
- package/dist/typing/index.js.map +1 -1
- package/dist/typing/workflow.d.ts +57 -1
- package/dist/typing/workflow.js +45 -55
- package/dist/typing/workflow.js.map +1 -1
- package/dist/utils/index.js +3 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/iterators.js +8 -10
- package/dist/utils/iterators.js.map +1 -1
- package/dist/utils/merge.js +27 -21
- package/dist/utils/merge.js.map +1 -1
- package/dist/validation/index.js +25 -33
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/validation.spec.js +14 -10
- package/dist/validation/validation.spec.js.map +1 -1
- package/package.json +1 -1
- package/dist/testing/placeholder.e2e.spec.js +0 -8
- package/dist/testing/placeholder.e2e.spec.js.map +0 -1
- package/dist/testing/placeholder.e2e.spec.mjs +0 -8
- package/dist/testing/placeholder.e2e.spec.mjs.map +0 -1
- /package/dist/{testing/placeholder.e2e.spec.d.mts → commandHandling/handleCommand.unit.spec.d.mts} +0 -0
- /package/dist/{testing/placeholder.e2e.spec.d.ts → commandHandling/handleCommand.unit.spec.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/eventStore/inMemoryEventStore.unit.spec.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-floating-promises */\nimport assert from 'node:assert';\nimport { randomUUID } from 'node:crypto';\nimport { describe, it } from 'node:test';\nimport { getInMemoryEventStore } from '../eventStore';\nimport { type Event } from '../typing';\n\n// Events & Entity\n\ntype PricedProductItem = { productId: string; quantity: number; price: number };\n\ntype ShoppingCart = {\n productItems: PricedProductItem[];\n totalAmount: number;\n};\n\ntype ProductItemAdded = Event<\n 'ProductItemAdded',\n { productItem: PricedProductItem }\n>;\ntype DiscountApplied = Event<'DiscountApplied', { percent: number }>;\n\ntype ShoppingCartEvent = ProductItemAdded | DiscountApplied;\n\nconst evolve = (\n state: ShoppingCart,\n { type, data }: ShoppingCartEvent,\n): ShoppingCart => {\n switch (type) {\n case 'ProductItemAdded': {\n const productItem = data.productItem;\n return {\n productItems: [...state.productItems, productItem],\n totalAmount:\n state.totalAmount + productItem.price * productItem.quantity,\n };\n }\n case 'DiscountApplied':\n return {\n ...state,\n totalAmount: state.totalAmount * (1 - data.percent),\n };\n }\n};\n\nconst getInitialState = (): ShoppingCart => {\n return { productItems: [], totalAmount: 0 };\n};\n\ndescribe('InMemoryEventStore', () => {\n const eventStore = getInMemoryEventStore();\n\n describe('aggregateStream', () => {\n it('When called with `to` allows time travelling', async () => {\n // Given\n const productItem: PricedProductItem = {\n productId: '123',\n quantity: 10,\n price: 3,\n };\n const discount = 10;\n const shoppingCartId = randomUUID();\n\n await eventStore.appendToStream<ShoppingCartEvent>(shoppingCartId, [\n { type: 'ProductItemAdded', data: { productItem } },\n ]);\n await eventStore.appendToStream<ShoppingCartEvent>(shoppingCartId, [\n { type: 'ProductItemAdded', data: { productItem } },\n ]);\n await eventStore.appendToStream<ShoppingCartEvent>(shoppingCartId, [\n { type: 'DiscountApplied', data: { percent: discount } },\n ]);\n\n // when\n const resultAt1 = await eventStore.aggregateStream(shoppingCartId, {\n evolve,\n getInitialState,\n read: { to: 1n },\n });\n const resultAt2 = await eventStore.aggregateStream(shoppingCartId, {\n evolve,\n getInitialState,\n read: { to: 2n },\n });\n const resultAt3 = await eventStore.aggregateStream(shoppingCartId, {\n evolve,\n getInitialState,\n read: { to: 3n },\n });\n\n // then\n assert.ok(resultAt1);\n assert.ok(resultAt2);\n assert.ok(resultAt3);\n\n assert.equal(resultAt1.currentStreamVersion, 1);\n assert.deepEqual(resultAt1.state, {\n productItems: [productItem],\n totalAmount: productItem.price * productItem.quantity,\n });\n\n assert.equal(resultAt2.currentStreamVersion, 2);\n assert.deepEqual(resultAt2.state, {\n productItems: [productItem, productItem],\n totalAmount: productItem.price * productItem.quantity * 2,\n });\n\n assert.equal(resultAt3.currentStreamVersion, 3);\n assert.deepEqual(resultAt3.state, {\n productItems: [productItem, productItem],\n totalAmount:\n productItem.price * productItem.quantity * 2 * (1 - discount),\n });\n });\n });\n});\n"],"mappings":"AACA,OAAO,YAAY;AACnB,SAAS,kBAAkB;AAC3B,SAAS,UAAU,UAAU;AAC7B,SAAS,6BAA6B;AACtC,eAA2B;AAmB3B,MAAM,SAAS,CACb,OACA,EAAE,MAAM,KAAK,MACI;AACjB,UAAQ,MAAM;AAAA,IACZ,KAAK,oBAAoB;AACvB,YAAM,cAAc,KAAK;AACzB,aAAO;AAAA,QACL,cAAc,CAAC,GAAG,MAAM,cAAc,WAAW;AAAA,QACjD,aACE,MAAM,cAAc,YAAY,QAAQ,YAAY;AAAA,MACxD;AAAA,IACF;AAAA,IACA,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,aAAa,MAAM,eAAe,IAAI,KAAK;AAAA,MAC7C;AAAA,EACJ;AACF;AAEA,MAAM,kBAAkB,MAAoB;AAC1C,SAAO,EAAE,cAAc,CAAC,GAAG,aAAa,EAAE;AAC5C;AAEA,SAAS,sBAAsB,MAAM;AACnC,QAAM,aAAa,sBAAsB;AAEzC,WAAS,mBAAmB,MAAM;AAChC,OAAG,gDAAgD,YAAY;AAE7D,YAAM,cAAiC;AAAA,QACrC,WAAW;AAAA,QACX,UAAU;AAAA,QACV,OAAO;AAAA,MACT;AACA,YAAM,WAAW;AACjB,YAAM,iBAAiB,WAAW;AAElC,YAAM,WAAW,eAAkC,gBAAgB;AAAA,QACjE,EAAE,MAAM,oBAAoB,MAAM,EAAE,YAAY,EAAE;AAAA,MACpD,CAAC;AACD,YAAM,WAAW,eAAkC,gBAAgB;AAAA,QACjE,EAAE,MAAM,oBAAoB,MAAM,EAAE,YAAY,EAAE;AAAA,MACpD,CAAC;AACD,YAAM,WAAW,eAAkC,gBAAgB;AAAA,QACjE,EAAE,MAAM,mBAAmB,MAAM,EAAE,SAAS,SAAS,EAAE;AAAA,MACzD,CAAC;AAGD,YAAM,YAAY,MAAM,WAAW,gBAAgB,gBAAgB;AAAA,QACjE;AAAA,QACA;AAAA,QACA,MAAM,EAAE,IAAI,GAAG;AAAA,MACjB,CAAC;AACD,YAAM,YAAY,MAAM,WAAW,gBAAgB,gBAAgB;AAAA,QACjE;AAAA,QACA;AAAA,QACA,MAAM,EAAE,IAAI,GAAG;AAAA,MACjB,CAAC;AACD,YAAM,YAAY,MAAM,WAAW,gBAAgB,gBAAgB;AAAA,QACjE;AAAA,QACA;AAAA,QACA,MAAM,EAAE,IAAI,GAAG;AAAA,MACjB,CAAC;AAGD,aAAO,GAAG,SAAS;AACnB,aAAO,GAAG,SAAS;AACnB,aAAO,GAAG,SAAS;AAEnB,aAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,aAAO,UAAU,UAAU,OAAO;AAAA,QAChC,cAAc,CAAC,WAAW;AAAA,QAC1B,aAAa,YAAY,QAAQ,YAAY;AAAA,MAC/C,CAAC;AAED,aAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,aAAO,UAAU,UAAU,OAAO;AAAA,QAChC,cAAc,CAAC,aAAa,WAAW;AAAA,QACvC,aAAa,YAAY,QAAQ,YAAY,WAAW;AAAA,MAC1D,CAAC;AAED,aAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,aAAO,UAAU,UAAU,OAAO;AAAA,QAChC,cAAc,CAAC,aAAa,WAAW;AAAA,QACvC,aACE,YAAY,QAAQ,YAAY,WAAW,KAAK,IAAI;AAAA,MACxD,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
package/dist/eventStore/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from './eventStore';
|
|
2
|
+
export * from './expectedVersion';
|
|
3
|
+
export * from './inMemoryEventStore';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/eventStore/index.ts"],"names":[],"mappings":"AAAA,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eventStore/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CommandHandler } from './commandHandling/handleCommand.mjs';
|
|
1
|
+
export { CommandHandler, CommandHandlerResult } from './commandHandling/handleCommand.mjs';
|
|
2
2
|
export { DeciderCommandHandler } from './commandHandling/handleCommandWithDecider.mjs';
|
|
3
3
|
export { ConcurrencyError, EmmettError, IllegalStateError, NotFoundError, ValidationError } from './errors/index.mjs';
|
|
4
4
|
export { A as AggregateStreamOptions, b as AggregateStreamResult, c as AppendToStreamOptions, d as AppendToStreamResult, D as DefaultStreamVersionType, E as EventStore, e as ExpectedStreamVersion, g as ExpectedStreamVersionGeneral, f as ExpectedStreamVersionWithValue, j as ExpectedVersionConflictError, N as NO_CONCURRENCY_CHECK, R as ReadStreamOptions, a as ReadStreamResult, h as STREAM_DOES_NOT_EXIST, S as STREAM_EXISTS, i as assertExpectedVersionMatchesCurrent, m as matchesExpectedVersion } from './eventStore-DLezSgsV.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CommandHandler } from './commandHandling/handleCommand.js';
|
|
1
|
+
export { CommandHandler, CommandHandlerResult } from './commandHandling/handleCommand.js';
|
|
2
2
|
export { DeciderCommandHandler } from './commandHandling/handleCommandWithDecider.js';
|
|
3
3
|
export { ConcurrencyError, EmmettError, IllegalStateError, NotFoundError, ValidationError } from './errors/index.js';
|
|
4
4
|
export { A as AggregateStreamOptions, b as AggregateStreamResult, c as AppendToStreamOptions, d as AppendToStreamResult, D as DefaultStreamVersionType, E as EventStore, e as ExpectedStreamVersion, g as ExpectedStreamVersionGeneral, f as ExpectedStreamVersionWithValue, j as ExpectedVersionConflictError, N as NO_CONCURRENCY_CHECK, R as ReadStreamOptions, a as ReadStreamResult, h as STREAM_DOES_NOT_EXIST, S as STREAM_EXISTS, i as assertExpectedVersionMatchesCurrent, m as matchesExpectedVersion } from './eventStore-N_YMFCDT.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export * from './commandHandling';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export * from './eventStore';
|
|
4
|
+
export * from './serialization';
|
|
5
|
+
export * from './testing';
|
|
6
|
+
export * from './typing';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
export * from './validation';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './json';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export class ParseError extends Error {
|
|
2
|
+
constructor(text) {
|
|
3
|
+
super(`Cannot parse! ${text}`);
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
|
-
const JSONParser = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
export const JSONParser = {
|
|
7
|
+
stringify: (value, options) => {
|
|
8
|
+
return JSON.stringify(options?.map ? options.map(value) : value);
|
|
9
|
+
},
|
|
10
|
+
parse: (text, options) => {
|
|
11
|
+
const parsed = JSON.parse(text, options?.reviver);
|
|
12
|
+
if (options?.typeCheck && !options?.typeCheck(parsed))
|
|
13
|
+
throw new ParseError(text);
|
|
14
|
+
return options?.map
|
|
15
|
+
? options.map(parsed)
|
|
16
|
+
: parsed;
|
|
17
|
+
},
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.JSONParser = JSONParser; exports.ParseError = ParseError;
|
|
23
19
|
//# sourceMappingURL=JSONParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/serialization/json/JSONParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JSONParser.js","sourceRoot":"","sources":["../../../src/serialization/json/JSONParser.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,IAAY;QACtB,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC;CACF;AA0BD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS,EAAE,CACT,KAAW,EACX,OAAoC,EACpC,EAAE;QACF,OAAO,IAAI,CAAC,SAAS,CACnB,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAA6B,CAAC,CAAC,CAAC,CAAC,KAAK,CAClE,CAAC;IACJ,CAAC;IACD,KAAK,EAAE,CACL,IAAY,EACZ,OAAgC,EAChB,EAAE;QAClB,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAE3D,IAAI,OAAO,EAAE,SAAS,IAAI,CAAC,OAAO,EAAE,SAAS,CAAK,MAAM,CAAC;YACvD,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAE7B,OAAO,OAAO,EAAE,GAAG;YACjB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAA8B,CAAC;YAC7C,CAAC,CAAE,MAAyB,CAAC;IACjC,CAAC;CACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './JSONParser';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/serialization/json/index.ts"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/serialization/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
sub[ele]
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return sub[ele] === sup[ele];
|
|
12
|
-
});
|
|
1
|
+
export const isSubset = (superObj, subObj) => {
|
|
2
|
+
const sup = superObj;
|
|
3
|
+
const sub = subObj;
|
|
4
|
+
return Object.keys(sub).every((ele) => {
|
|
5
|
+
if (typeof sub[ele] == 'object') {
|
|
6
|
+
return isSubset(sup[ele], sub[ele]);
|
|
7
|
+
}
|
|
8
|
+
return sub[ele] === sup[ele];
|
|
9
|
+
});
|
|
13
10
|
};
|
|
14
|
-
const assertMatches = (actual, expected) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`subObj:
|
|
18
|
-
${JSON.stringify(expected)}
|
|
19
|
-
is not subset of
|
|
20
|
-
${JSON.stringify(actual)}`
|
|
21
|
-
);
|
|
11
|
+
export const assertMatches = (actual, expected) => {
|
|
12
|
+
if (!isSubset(actual, expected))
|
|
13
|
+
throw Error(`subObj:\n${JSON.stringify(expected)}\nis not subset of\n${JSON.stringify(actual)}`);
|
|
22
14
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
exports.assertMatches = assertMatches; exports.isSubset = isSubset;
|
|
27
15
|
//# sourceMappingURL=assertions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/testing/assertions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../src/testing/assertions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,QAAiB,EAAE,MAAe,EAAW,EAAE;IACtE,MAAM,GAAG,GAAG,QAAmC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAiC,CAAC;IAE9C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAW,EAAE,EAAE;QAC5C,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,QAAQ,CACb,GAAG,CAAC,GAAG,CAA4B,EACnC,GAAG,CAAC,GAAG,CAA4B,CACpC,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAe,EAAE,QAAiB,EAAE,EAAE;IAClE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC7B,MAAM,KAAK,CACT,YAAY,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CACpF,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
const DeciderSpecification = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
export const DeciderSpecification = {
|
|
3
|
+
for: (decider) => {
|
|
4
|
+
{
|
|
5
|
+
return (givenEvents) => {
|
|
6
|
+
return {
|
|
7
|
+
when: (command) => {
|
|
8
|
+
const handle = () => {
|
|
9
|
+
const existingEvents = Array.isArray(givenEvents)
|
|
10
|
+
? givenEvents
|
|
11
|
+
: [givenEvents];
|
|
12
|
+
const currentState = existingEvents.reduce(decider.evolve, decider.initialState());
|
|
13
|
+
return decider.decide(command, currentState);
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
then: (expectedEvents) => {
|
|
17
|
+
const resultEvents = handle();
|
|
18
|
+
const resultEventsArray = Array.isArray(resultEvents)
|
|
19
|
+
? resultEvents
|
|
20
|
+
: [resultEvents];
|
|
21
|
+
const expectedEventsArray = Array.isArray(expectedEvents)
|
|
22
|
+
? expectedEvents
|
|
23
|
+
: [expectedEvents];
|
|
24
|
+
assert.deepEqual(resultEventsArray, expectedEventsArray);
|
|
25
|
+
},
|
|
26
|
+
thenThrows: (check) => {
|
|
27
|
+
try {
|
|
28
|
+
handle();
|
|
29
|
+
assert.fail('Handler did not fail as expected');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (check)
|
|
33
|
+
assert.ok(check(error));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
15
39
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const resultEvents = handle();
|
|
19
|
-
const resultEventsArray = Array.isArray(resultEvents) ? resultEvents : [resultEvents];
|
|
20
|
-
const expectedEventsArray = Array.isArray(expectedEvents) ? expectedEvents : [expectedEvents];
|
|
21
|
-
_assert2.default.deepEqual(resultEventsArray, expectedEventsArray);
|
|
22
|
-
},
|
|
23
|
-
thenThrows: (check) => {
|
|
24
|
-
try {
|
|
25
|
-
handle();
|
|
26
|
-
_assert2.default.fail("Handler did not fail as expected");
|
|
27
|
-
} catch (error) {
|
|
28
|
-
if (check)
|
|
29
|
-
_assert2.default.ok(check(error));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
38
42
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
exports.DeciderSpecification = DeciderSpecification;
|
|
42
43
|
//# sourceMappingURL=deciderSpecification.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/testing/deciderSpecification.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"deciderSpecification.js","sourceRoot":"","sources":["../../src/testing/deciderSpecification.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAW5B,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,GAAG,EAAE,CAAwB,OAI5B,EAAuC,EAAE;QACxC,CAAC;YACC,OAAO,CAAC,WAA4B,EAAE,EAAE;gBACtC,OAAO;oBACL,IAAI,EAAE,CAAC,OAAgB,EAAE,EAAE;wBACzB,MAAM,MAAM,GAAG,GAAG,EAAE;4BAClB,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;gCAC/C,CAAC,CAAC,WAAW;gCACb,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;4BAElB,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CACxC,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,YAAY,EAAE,CACvB,CAAC;4BAEF,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;wBAC/C,CAAC,CAAC;wBAEF,OAAO;4BACL,IAAI,EAAE,CAAC,cAA+B,EAAQ,EAAE;gCAC9C,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC;gCAE9B,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;oCACnD,CAAC,CAAC,YAAY;oCACd,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;gCAEnB,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;oCACvD,CAAC,CAAC,cAAc;oCAChB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;gCAErB,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;4BAC3D,CAAC;4BACD,UAAU,EAAE,CAAQ,KAAiC,EAAQ,EAAE;gCAC7D,IAAI,CAAC;oCACH,MAAM,EAAE,CAAC;oCACT,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;gCAClD,CAAC;gCAAC,OAAO,KAAK,EAAE,CAAC;oCACf,IAAI,KAAK;wCAAE,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,KAAc,CAAC,CAAC,CAAC;gCAC9C,CAAC;4BACH,CAAC;yBACF,CAAC;oBACJ,CAAC;iBACF,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * from './assertions';
|
|
2
|
+
export * from './deciderSpecification';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
|
package/dist/typing/command.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/typing/command.ts"],"names":[],"mappings":""}
|
package/dist/typing/decider.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=decider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"decider.js","sourceRoot":"","sources":["../../src/typing/decider.ts"],"names":[],"mappings":""}
|
package/dist/typing/event.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=event.js.map
|
package/dist/typing/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/typing/event.ts"],"names":[],"mappings":""}
|
package/dist/typing/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export * from './command';
|
|
2
|
+
export * from './event';
|
|
3
|
+
export * from './decider';
|
|
4
|
+
export * from './workflow';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/typing/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typing/index.ts"],"names":[],"mappings":"AAAA,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/typing/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AAExB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Command } from './command';
|
|
2
|
+
import type { Event } from './event';
|
|
3
|
+
export type Workflow<Input extends Event | Command, State, Output extends Event | Command> = {
|
|
4
|
+
decide: (command: Input, state: State) => WorkflowOutput<Output>[];
|
|
5
|
+
evolve: (currentState: State, event: WorkflowEvent<Output>) => State;
|
|
6
|
+
getInitialState: () => State;
|
|
7
|
+
};
|
|
8
|
+
export type WorkflowEvent<Output extends Command | Event> = Extract<Output, {
|
|
9
|
+
__brand?: 'Event';
|
|
10
|
+
}>;
|
|
11
|
+
export type WorkflowCommand<Output extends Command | Event> = Extract<Output, {
|
|
12
|
+
__brand?: 'Command';
|
|
13
|
+
}>;
|
|
14
|
+
export type WorkflowOutput<TOutput extends Command | Event> = {
|
|
15
|
+
kind: 'Reply';
|
|
16
|
+
message: TOutput;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'Send';
|
|
19
|
+
message: WorkflowCommand<TOutput>;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'Publish';
|
|
22
|
+
message: WorkflowEvent<TOutput>;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'Schedule';
|
|
25
|
+
message: TOutput;
|
|
26
|
+
when: {
|
|
27
|
+
afterInMs: number;
|
|
28
|
+
} | {
|
|
29
|
+
at: Date;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'Complete';
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'Accept';
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'Ignore';
|
|
37
|
+
reason: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'Error';
|
|
40
|
+
reason: string;
|
|
41
|
+
};
|
|
42
|
+
export declare const reply: <TOutput extends Event | Command>(message: TOutput) => WorkflowOutput<TOutput>;
|
|
43
|
+
export declare const send: <TOutput extends Event | Command>(message: Extract<TOutput, {
|
|
44
|
+
__brand?: "Command" | undefined;
|
|
45
|
+
}>) => WorkflowOutput<TOutput>;
|
|
46
|
+
export declare const publish: <TOutput extends Event | Command>(message: Extract<TOutput, {
|
|
47
|
+
__brand?: "Event" | undefined;
|
|
48
|
+
}>) => WorkflowOutput<TOutput>;
|
|
49
|
+
export declare const schedule: <TOutput extends Event | Command>(message: TOutput, when: {
|
|
50
|
+
afterInMs: number;
|
|
51
|
+
} | {
|
|
52
|
+
at: Date;
|
|
53
|
+
}) => WorkflowOutput<TOutput>;
|
|
54
|
+
export declare const complete: <TOutput extends Event | Command>() => WorkflowOutput<TOutput>;
|
|
55
|
+
export declare const ignore: <TOutput extends Event | Command>(reason: string) => WorkflowOutput<TOutput>;
|
|
56
|
+
export declare const error: <TOutput extends Event | Command>(reason: string) => WorkflowOutput<TOutput>;
|
|
57
|
+
export declare const accept: <TOutput extends Event | Command>() => WorkflowOutput<TOutput>;
|
package/dist/typing/workflow.js
CHANGED
|
@@ -1,56 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
const send = (message) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
const publish = (message) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
const schedule = (message, when) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
const complete = () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
const ignore = (reason) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
const error = (reason) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
const accept = () => {
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
exports.accept = accept; exports.complete = complete; exports.error = error; exports.ignore = ignore; exports.publish = publish; exports.reply = reply; exports.schedule = schedule; exports.send = send;
|
|
1
|
+
export const reply = (message) => {
|
|
2
|
+
return {
|
|
3
|
+
kind: 'Reply',
|
|
4
|
+
message,
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export const send = (message) => {
|
|
8
|
+
return {
|
|
9
|
+
kind: 'Send',
|
|
10
|
+
message,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export const publish = (message) => {
|
|
14
|
+
return {
|
|
15
|
+
kind: 'Publish',
|
|
16
|
+
message,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const schedule = (message, when) => {
|
|
20
|
+
return {
|
|
21
|
+
kind: 'Schedule',
|
|
22
|
+
message,
|
|
23
|
+
when,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const complete = () => {
|
|
27
|
+
return {
|
|
28
|
+
kind: 'Complete',
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const ignore = (reason) => {
|
|
32
|
+
return {
|
|
33
|
+
kind: 'Ignore',
|
|
34
|
+
reason,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export const error = (reason) => {
|
|
38
|
+
return {
|
|
39
|
+
kind: 'Error',
|
|
40
|
+
reason,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const accept = () => {
|
|
44
|
+
return { kind: 'Accept' };
|
|
45
|
+
};
|
|
56
46
|
//# sourceMappingURL=workflow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typing/workflow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/typing/workflow.ts"],"names":[],"mappings":"AAuCA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,OAAgB,EACS,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,OAAO;QACb,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,OAAiC,EACR,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,OAA+B,EACN,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,OAAgB,EAChB,IAA0C,EACjB,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,GAEK,EAAE;IAC7B,OAAO;QACL,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,MAAc,EACW,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAc,EACW,EAAE;IAC3B,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,GAEO,EAAE;IAC7B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.default = utils_default;
|
|
1
|
+
export * from './iterators';
|
|
2
|
+
export * from './merge';
|
|
3
|
+
export default {};
|
|
7
4
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AAExB,eAAe,EAAE,CAAC"}
|
package/dist/utils/iterators.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export const sum = (iterator) => {
|
|
2
|
+
let value, done, sum = 0;
|
|
3
|
+
do {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
5
|
+
({ value, done } = iterator.next());
|
|
6
|
+
sum += value || 0;
|
|
7
|
+
} while (!done);
|
|
8
|
+
return sum;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.sum = sum;
|
|
12
10
|
//# sourceMappingURL=iterators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/iterators.ts"],"names":[
|
|
1
|
+
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/utils/iterators.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,QAA6D,EAC7D,EAAE;IACF,IAAI,KAAK,EACP,IAAyB,EACzB,GAAG,GAAG,CAAC,CAAC;IACV,GAAG,CAAC;QACF,mEAAmE;QACnE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACpC,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC;IACpB,CAAC,QAAQ,CAAC,IAAI,EAAE;IAChB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|