@event-driven-io/emmett 0.20.1-alpha.3 → 0.20.1-alpha.5
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/cli.cjs +251 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +1552 -13
- package/dist/index.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-CJZAVRMT.cjs +0 -2
- package/dist/chunk-CJZAVRMT.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,1556 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _class; var _class2; var _class3; var _class4; var _class5; var _class6;var _chunkCJZAVRMTcjs = require('./chunk-CJZAVRMT.cjs');var K=t=>"withSession"in t,X= exports.nulloSessionFactory =t=>({withSession:e=>e({eventStore:t,close:()=>Promise.resolve()})});var pt=(t,e,r)=>({type:t,data:e,metadata:r});var L=(t,e,r)=>({type:t,data:e,metadata:r});var ut=t=>({kind:"Reply",message:t}),ft= exports.send =t=>({kind:"Send",message:t}),yt= exports.publish =t=>({kind:"Publish",message:t}),vt= exports.schedule =(t,e)=>({kind:"Schedule",message:t,when:e}),Et= exports.complete =()=>({kind:"Complete"}),St= exports.ignore =t=>({kind:"Ignore",reason:t}),Tt= exports.error =t=>({kind:"Error",reason:t}),xt= exports.accept =()=>({kind:"Accept"});var H="__emt:GlobalStreamCaughtUp",Y= exports.isGlobalStreamCaughtUp =t=>t.type===H,Mt= exports.caughtUpEventFrom =t=>e=>e.type===H&&_optionalChain([e, 'access', _2 => _2.metadata, 'optionalAccess', _3 => _3.globalPosition])>=t,j= exports.globalStreamCaughtUp =t=>L(H,t,{globalPosition:t.globalPosition}),Vt= exports.isSubscriptionEvent =t=>Y(t),Pt= exports.isNotInternalEvent =t=>!Y(t);var xe="STREAM_EXISTS",F= exports.STREAM_DOES_NOT_EXIST ="STREAM_DOES_NOT_EXIST",D= exports.NO_CONCURRENCY_CHECK ="NO_CONCURRENCY_CHECK",ge= exports.matchesExpectedVersion =(t,e,r)=>e===D?!0:e==F?t===r:e==xe?t!==r:t===e,N= exports.assertExpectedVersionMatchesCurrent =(t,e,r)=>{if(e??=D,!ge(t,e,r))throw new b(t,e)},b= exports.ExpectedVersionConflictError =class t extends _chunkCJZAVRMTcjs.l{constructor(e,r){super(_optionalChain([e, 'optionalAccess', _4 => _4.toString, 'call', _5 => _5()]),_optionalChain([r, 'optionalAccess', _6 => _6.toString, 'call', _7 => _7()])),Object.setPrototypeOf(this,t.prototype)}},z= exports.isExpectedVersionConflictError =t=>t instanceof b;var _uuid = require('uuid');var _webstreamspolyfill = require('web-streams-polyfill');var Q=t=>new _(t),_= exports.CaughtUpTransformStream =class extends _webstreamspolyfill.TransformStream{constructor(e){super({start:r=>{let n=0n;for(let o of e)r.enqueue(o),n=o.metadata.globalPosition;r.enqueue(j({globalPosition:n}))},transform:(r,n)=>{this._currentPosition=r.metadata.globalPosition,n.enqueue(r),!(this._currentPosition<this._logPosition)&&n.enqueue(j({globalPosition:this._currentPosition}))}}),this._currentPosition=this._logPosition=e.length>0?e[e.length-1].metadata.globalPosition:0n}set logPosition(e){this._logPosition=e}};var O=(t,e={})=>new S(t,e),S= (_class =class extends _webstreamspolyfill.TransformStream{constructor(r,n={}){super({cancel:o=>{console.log("Stream was canceled. Reason:",o),this.stopChecking()}});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;this.onNoActiveReaderCallback=r;this.streamId=_nullishCoalesce(_optionalChain([n, 'optionalAccess', _8 => _8.streamId]), () => (_uuid.v4.call(void 0, ))),this.onNoActiveReaderCallback=r,this.startChecking(_nullishCoalesce(_optionalChain([n, 'optionalAccess', _9 => _9.intervalCheckInMs]), () => (20)))}__init() {this.checkInterval=null}__init2() {this._isStopped=!1}get hasActiveSubscribers(){return!this._isStopped}startChecking(r){this.checkInterval=setInterval(()=>{this.checkNoActiveReader()},r)}stopChecking(){this.checkInterval&&(clearInterval(this.checkInterval),this.checkInterval=null,this._isStopped=!0,this.onNoActiveReaderCallback(this))}checkNoActiveReader(){!this.readable.locked&&!this._isStopped&&this.stopChecking()}}, _class);var Z=async(t,e)=>{if(t.writable.locked)return!1;let r=t.writable.getWriter();if(await r.ready,!t.readable.locked)return!1;try{for(let n of e)await r.write(n)}catch(n){console.log(n)}finally{await r.close()}return!0};var ee=()=>{let t=[],e=new Map;return{notify:async r=>{if(r.length!==0){t.push(...r);for(let n of e.values())n.logPosition=r[r.length-1].metadata.globalPosition,await Z(n,r)}},stream:()=>{let r=_uuid.v4.call(void 0, ),n=Q(t);return e.set(r,n),n.readable.pipeThrough(O(o=>{e.has(o.streamId)&&e.delete(o.streamId)},{streamId:r}))}}};var T=0n,ir= exports.getInMemoryEventStore =()=>{let t=new Map,e=ee(),r=()=>Array.from(t.values()).map(n=>n.length).reduce((n,o)=>n+o,0);return{async aggregateStream(n,o){let{evolve:a,initialState:i,read:m}=o,l=await this.readStream(n,m),y=_nullishCoalesce(_optionalChain([l, 'optionalAccess', _10 => _10.events]), () => ([]));return{currentStreamVersion:BigInt(y.length),state:y.reduce(a,i()),streamExists:l.streamExists}},readStream:(n,o)=>{let a=t.get(n),i=a?BigInt(a.length):T;N(i,_optionalChain([o, 'optionalAccess', _11 => _11.expectedStreamVersion]),T);let m=Number(o&&"from"in o?o.from:0),l=Number(o&&"to"in o?o.to:o&&"maxCount"in o&&o.maxCount?o.from+o.maxCount:_nullishCoalesce(_optionalChain([a, 'optionalAccess', _12 => _12.length]), () => (1))),y=a!==void 0&&a.length>0?a.map(f=>f).slice(m,l):[],E={currentStreamVersion:i,events:y,streamExists:a!==void 0&&a.length>0};return Promise.resolve(E)},appendToStream:async(n,o,a)=>{let i=_nullishCoalesce(t.get(n), () => ([])),m=i.length>0?BigInt(i.length):T;N(m,_optionalChain([a, 'optionalAccess', _13 => _13.expectedStreamVersion]),T);let l=o.map((f,v)=>({...f,metadata:{..._nullishCoalesce(f.metadata, () => ({})),streamName:n,eventId:_uuid.v4.call(void 0, ),streamPosition:BigInt(i.length+v+1),globalPosition:BigInt(r()+v+1)}})),y=BigInt(l.slice(-1)[0].metadata.streamPosition);return t.set(n,[...i,...l]),await e.notify(l),{nextExpectedStreamVersion:y,createdNewStream:m===T}}}};var d=(t,e)=>{if(Oe(t))return t.equals(e);if(Array.isArray(t))return Array.isArray(e)&&t.length===e.length&&t.every((o,a)=>d(o,e[a]));if(typeof t!="object"||typeof e!="object"||t===null||e===null)return t===e;if(Array.isArray(e))return!1;let r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length||!r.every(o=>n.includes(o)))return!1;for(let o in t){if(t[o]instanceof Function&&e[o]instanceof Function)continue;if(!d(t[o],e[o]))return!1}return!0},Oe= exports.isEquatable =t=>t&&typeof t=="object"&&"equals"in t&&typeof t.equals=="function";var vr=t=>{let e,r,n=0;do({value:e,done:r}=t.next()),n+=e||0;while(!r);return n};var Sr=(t,e,r,n,o=()=>{})=>{let a=!1,i=t.map(m=>r(m)?(a=!0,n(m)):m).filter(m=>m!==void 0).map(m=>{if(!m)throw Error("That should not happen");return m});return!a&&o()!==void 0?[...t,e]:i};var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);var te={retries:0},w= exports.asyncRetry =async(t,e)=>e===void 0||e.retries===0?t():_asyncretry2.default.call(void 0, async r=>{try{return await t()}catch(n){throw _optionalChain([e, 'optionalAccess', _14 => _14.shouldRetryError])&&!e.shouldRetryError(n)&&r(n),n}},_nullishCoalesce(e, () => ({retries:0})));var re={retries:3,minTimeout:100,factor:1.5,shouldRetryError:z},Me=t=>t===void 0?te:"onVersionConflict"in t?typeof t.onVersionConflict=="boolean"?re:typeof t.onVersionConflict=="number"?{...re,retries:t.onVersionConflict}:t.onVersionConflict:t,ne= exports.CommandHandler =t=>async(e,r,n,o)=>w(async()=>await Ve(e,async({eventStore:i})=>{let{evolve:m,initialState:l}=t,E=(_nullishCoalesce(t.mapToStreamId, () => ((Te=>Te))))(r),f=await i.aggregateStream(E,{evolve:m,initialState:l,read:{expectedStreamVersion:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _15 => _15.expectedStreamVersion]), () => (D))}}),v=f.state,B=f.currentStreamVersion,A=await n(v),R=Array.isArray(A)?A:[A];if(R.length===0)return{newEvents:[],newState:v,nextExpectedStreamVersion:B,createdNewStream:!1};let Se=_nullishCoalesce(_optionalChain([o, 'optionalAccess', _16 => _16.expectedStreamVersion]), () => ((f.streamExists?B:F)));return{...await i.appendToStream(E,R,{...o,expectedStreamVersion:Se}),newEvents:R,newState:R.reduce(m,v)}}),Me(o&&"retry"in o?o.retry:t.retry)),Ve=(t,e)=>(K(t)?t:X(t)).withSession(e);var Pr=t=>async(e,r,n,o)=>{let{decide:a,...i}=t;return ne(i)(e,r,m=>a(n,m),o)};var Nr=()=>{let t=new Map,e=[];return{send:async r=>{let n=t.get(r.type);if(n===void 0||n.length===0)throw new (0, _chunkCJZAVRMTcjs.k)(`No handler registered for command ${r.type}!`);let o=n[0];await o(r)},publish:async r=>{let n=_nullishCoalesce(t.get(r.type), () => ([]));for(let o of n)await o(r)},schedule:(r,n)=>{e=[...e,{message:r,options:n}]},handle:(r,...n)=>{let o=[...t.keys()].filter(a=>n.includes(a));if(o.length>0)throw new (0, _chunkCJZAVRMTcjs.k)(`Cannot register handler for commands ${o.join(", ")} as they're already registered!`);for(let a of n)t.set(a,[r])},subscribe(r,...n){for(let o of n)t.has(o)||t.set(o,[]),t.set(o,[..._nullishCoalesce(t.get(o), () => ([])),r])},dequeue:()=>{let r=e;return e=[],r}}};var Wr=t=>t,Pe= exports.inlineProjections =t=>t.map(e=>({type:"inline",projection:e})),ke= exports.asyncProjections =t=>t.map(e=>({type:"async",projection:e})),Gr= exports.projections ={inline:Pe,async:ke};var W=class extends Error{constructor(e){super(`Cannot parse! ${e}`)}},c= exports.JSONParser ={stringify:(t,e)=>JSON.stringify(_optionalChain([e, 'optionalAccess', _17 => _17.map])?e.map(t):t,(r,n)=>typeof n=="bigint"?n.toString():n),parse:(t,e)=>{let r=JSON.parse(t,_optionalChain([e, 'optionalAccess', _18 => _18.reviver]));if(_optionalChain([e, 'optionalAccess', _19 => _19.typeCheck])&&!_optionalChain([e, 'optionalAccess', _20 => _20.typeCheck, 'call', _21 => _21(r)]))throw new W(t);return _optionalChain([e, 'optionalAccess', _22 => _22.map])?e.map(r):r}};var G=t=>{let e=t.reduce((o,a)=>o+a.length,0),r=new Uint8Array(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r};var Lr=async t=>{let e=[];for await(let r of t)e.push(r);return e};var M= (_class2 =class{constructor() { _class2.prototype.__init3.call(this); }__init3() {this.buffer=[]}addToBuffer(e){this.buffer.push(e)}clearBuffer(){this.buffer=[]}hasCompleteMessage(){let e=G(this.buffer);return new TextDecoder().decode(e).includes(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
AssertionError: () => AssertionError,
|
|
34
|
+
BinaryJsonDecoder: () => BinaryJsonDecoder,
|
|
35
|
+
CaughtUpTransformStream: () => CaughtUpTransformStream,
|
|
36
|
+
CommandHandler: () => CommandHandler,
|
|
37
|
+
CommandHandlerStreamVersionConflictRetryOptions: () => CommandHandlerStreamVersionConflictRetryOptions,
|
|
38
|
+
CompositeDecoder: () => CompositeDecoder,
|
|
39
|
+
ConcurrencyError: () => ConcurrencyError,
|
|
40
|
+
DeciderCommandHandler: () => DeciderCommandHandler,
|
|
41
|
+
DeciderSpecification: () => DeciderSpecification,
|
|
42
|
+
DefaultDecoder: () => DefaultDecoder,
|
|
43
|
+
EmmettError: () => EmmettError,
|
|
44
|
+
ExpectedVersionConflictError: () => ExpectedVersionConflictError,
|
|
45
|
+
GlobalStreamCaughtUpType: () => GlobalStreamCaughtUpType,
|
|
46
|
+
IllegalStateError: () => IllegalStateError,
|
|
47
|
+
InMemoryEventStoreDefaultStreamVersion: () => InMemoryEventStoreDefaultStreamVersion,
|
|
48
|
+
JSONParser: () => JSONParser,
|
|
49
|
+
JsonDecoder: () => JsonDecoder,
|
|
50
|
+
NO_CONCURRENCY_CHECK: () => NO_CONCURRENCY_CHECK,
|
|
51
|
+
NoRetries: () => NoRetries,
|
|
52
|
+
NotFoundError: () => NotFoundError,
|
|
53
|
+
ObjectDecoder: () => ObjectDecoder,
|
|
54
|
+
ParseError: () => ParseError,
|
|
55
|
+
STREAM_DOES_NOT_EXIST: () => STREAM_DOES_NOT_EXIST,
|
|
56
|
+
STREAM_EXISTS: () => STREAM_EXISTS,
|
|
57
|
+
StreamingCoordinator: () => StreamingCoordinator,
|
|
58
|
+
StringDecoder: () => StringDecoder,
|
|
59
|
+
ValidationError: () => ValidationError,
|
|
60
|
+
ValidationErrors: () => ValidationErrors,
|
|
61
|
+
WrapEventStore: () => WrapEventStore,
|
|
62
|
+
accept: () => accept,
|
|
63
|
+
argMatches: () => argMatches,
|
|
64
|
+
argValue: () => argValue,
|
|
65
|
+
assertDeepEqual: () => assertDeepEqual,
|
|
66
|
+
assertEqual: () => assertEqual,
|
|
67
|
+
assertExpectedVersionMatchesCurrent: () => assertExpectedVersionMatchesCurrent,
|
|
68
|
+
assertFails: () => assertFails,
|
|
69
|
+
assertFalse: () => assertFalse,
|
|
70
|
+
assertIsNotNull: () => assertIsNotNull,
|
|
71
|
+
assertIsNull: () => assertIsNull,
|
|
72
|
+
assertMatches: () => assertMatches,
|
|
73
|
+
assertNotDeepEqual: () => assertNotDeepEqual,
|
|
74
|
+
assertNotEmptyString: () => assertNotEmptyString,
|
|
75
|
+
assertNotEqual: () => assertNotEqual,
|
|
76
|
+
assertOk: () => assertOk,
|
|
77
|
+
assertPositiveNumber: () => assertPositiveNumber,
|
|
78
|
+
assertRejects: () => assertRejects,
|
|
79
|
+
assertThat: () => assertThat,
|
|
80
|
+
assertThatArray: () => assertThatArray,
|
|
81
|
+
assertThrows: () => assertThrows,
|
|
82
|
+
assertThrowsAsync: () => assertThrowsAsync,
|
|
83
|
+
assertTrue: () => assertTrue,
|
|
84
|
+
assertUnsignedBigInt: () => assertUnsignedBigInt,
|
|
85
|
+
asyncProjections: () => asyncProjections,
|
|
86
|
+
asyncRetry: () => asyncRetry,
|
|
87
|
+
canCreateEventStoreSession: () => canCreateEventStoreSession,
|
|
88
|
+
caughtUpEventFrom: () => caughtUpEventFrom,
|
|
89
|
+
collect: () => collect,
|
|
90
|
+
command: () => command,
|
|
91
|
+
complete: () => complete,
|
|
92
|
+
concatUint8Arrays: () => concatUint8Arrays,
|
|
93
|
+
deepEquals: () => deepEquals,
|
|
94
|
+
error: () => error,
|
|
95
|
+
event: () => event,
|
|
96
|
+
formatDateToUtcYYYYMMDD: () => formatDateToUtcYYYYMMDD,
|
|
97
|
+
getInMemoryEventStore: () => getInMemoryEventStore,
|
|
98
|
+
getInMemoryMessageBus: () => getInMemoryMessageBus,
|
|
99
|
+
globalStreamCaughtUp: () => globalStreamCaughtUp,
|
|
100
|
+
ignore: () => ignore,
|
|
101
|
+
inlineProjections: () => inlineProjections,
|
|
102
|
+
isEquatable: () => isEquatable,
|
|
103
|
+
isErrorConstructor: () => isErrorConstructor,
|
|
104
|
+
isExpectedVersionConflictError: () => isExpectedVersionConflictError,
|
|
105
|
+
isGlobalStreamCaughtUp: () => isGlobalStreamCaughtUp,
|
|
106
|
+
isNotInternalEvent: () => isNotInternalEvent,
|
|
107
|
+
isNumber: () => isNumber,
|
|
108
|
+
isPluginConfig: () => isPluginConfig,
|
|
109
|
+
isString: () => isString,
|
|
110
|
+
isSubscriptionEvent: () => isSubscriptionEvent,
|
|
111
|
+
isSubset: () => isSubset,
|
|
112
|
+
isValidYYYYMMDD: () => isValidYYYYMMDD,
|
|
113
|
+
matchesExpectedVersion: () => matchesExpectedVersion,
|
|
114
|
+
merge: () => merge,
|
|
115
|
+
nulloSessionFactory: () => nulloSessionFactory,
|
|
116
|
+
parseDateFromUtcYYYYMMDD: () => parseDateFromUtcYYYYMMDD,
|
|
117
|
+
projection: () => projection,
|
|
118
|
+
projections: () => projections,
|
|
119
|
+
publish: () => publish,
|
|
120
|
+
reply: () => reply,
|
|
121
|
+
restream: () => restream,
|
|
122
|
+
schedule: () => schedule,
|
|
123
|
+
send: () => send,
|
|
124
|
+
streamGenerators: () => streamGenerators,
|
|
125
|
+
streamTrackingGlobalPosition: () => streamTrackingGlobalPosition,
|
|
126
|
+
streamTransformations: () => streamTransformations,
|
|
127
|
+
sum: () => sum,
|
|
128
|
+
verifyThat: () => verifyThat
|
|
129
|
+
});
|
|
130
|
+
module.exports = __toCommonJS(src_exports);
|
|
131
|
+
|
|
132
|
+
// src/eventStore/eventStore.ts
|
|
133
|
+
var canCreateEventStoreSession = (eventStore) => "withSession" in eventStore;
|
|
134
|
+
var nulloSessionFactory = (eventStore) => ({
|
|
135
|
+
withSession: (callback) => {
|
|
136
|
+
const nulloSession = {
|
|
137
|
+
eventStore,
|
|
138
|
+
close: () => Promise.resolve()
|
|
139
|
+
};
|
|
140
|
+
return callback(nulloSession);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// src/typing/command.ts
|
|
145
|
+
var command = (type, data, metadata) => {
|
|
146
|
+
return {
|
|
147
|
+
type,
|
|
148
|
+
data,
|
|
149
|
+
metadata
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/typing/event.ts
|
|
154
|
+
var event = (type, data, metadata) => {
|
|
155
|
+
return {
|
|
156
|
+
type,
|
|
157
|
+
data,
|
|
158
|
+
metadata
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/typing/workflow.ts
|
|
163
|
+
var reply = (message) => {
|
|
164
|
+
return {
|
|
165
|
+
kind: "Reply",
|
|
166
|
+
message
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
var send = (message) => {
|
|
170
|
+
return {
|
|
171
|
+
kind: "Send",
|
|
172
|
+
message
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
var publish = (message) => {
|
|
176
|
+
return {
|
|
177
|
+
kind: "Publish",
|
|
178
|
+
message
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
var schedule = (message, when) => {
|
|
182
|
+
return {
|
|
183
|
+
kind: "Schedule",
|
|
184
|
+
message,
|
|
185
|
+
when
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
var complete = () => {
|
|
189
|
+
return {
|
|
190
|
+
kind: "Complete"
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
var ignore = (reason) => {
|
|
194
|
+
return {
|
|
195
|
+
kind: "Ignore",
|
|
196
|
+
reason
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
var error = (reason) => {
|
|
200
|
+
return {
|
|
201
|
+
kind: "Error",
|
|
202
|
+
reason
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
var accept = () => {
|
|
206
|
+
return { kind: "Accept" };
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/eventStore/events/index.ts
|
|
210
|
+
var GlobalStreamCaughtUpType = "__emt:GlobalStreamCaughtUp";
|
|
211
|
+
var isGlobalStreamCaughtUp = (event2) => event2.type === GlobalStreamCaughtUpType;
|
|
212
|
+
var caughtUpEventFrom = (position) => (event2) => event2.type === GlobalStreamCaughtUpType && event2.metadata?.globalPosition >= position;
|
|
213
|
+
var globalStreamCaughtUp = (data) => event(GlobalStreamCaughtUpType, data, {
|
|
214
|
+
globalPosition: data.globalPosition
|
|
215
|
+
});
|
|
216
|
+
var isSubscriptionEvent = (event2) => isGlobalStreamCaughtUp(event2);
|
|
217
|
+
var isNotInternalEvent = (event2) => !isGlobalStreamCaughtUp(event2);
|
|
218
|
+
|
|
219
|
+
// src/validation/dates.ts
|
|
220
|
+
var formatDateToUtcYYYYMMDD = (date) => {
|
|
221
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
222
|
+
timeZone: "UTC",
|
|
223
|
+
year: "numeric",
|
|
224
|
+
month: "2-digit",
|
|
225
|
+
day: "2-digit"
|
|
226
|
+
});
|
|
227
|
+
return formatter.format(date);
|
|
228
|
+
};
|
|
229
|
+
var isValidYYYYMMDD = (dateString) => {
|
|
230
|
+
const regex = /^\d{4}-\d{2}-\d{2}$/;
|
|
231
|
+
return regex.test(dateString);
|
|
232
|
+
};
|
|
233
|
+
var parseDateFromUtcYYYYMMDD = (dateString) => {
|
|
234
|
+
const date = /* @__PURE__ */ new Date(dateString + "T00:00:00Z");
|
|
235
|
+
if (!isValidYYYYMMDD(dateString)) {
|
|
236
|
+
throw new ValidationError("Invalid date format, must be yyyy-mm-dd");
|
|
237
|
+
}
|
|
238
|
+
if (isNaN(date.getTime())) {
|
|
239
|
+
throw new ValidationError("Invalid date format");
|
|
240
|
+
}
|
|
241
|
+
return date;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/validation/index.ts
|
|
245
|
+
var ValidationErrors = /* @__PURE__ */ ((ValidationErrors2) => {
|
|
246
|
+
ValidationErrors2["NOT_A_NONEMPTY_STRING"] = "NOT_A_NONEMPTY_STRING";
|
|
247
|
+
ValidationErrors2["NOT_A_POSITIVE_NUMBER"] = "NOT_A_POSITIVE_NUMBER";
|
|
248
|
+
ValidationErrors2["NOT_AN_UNSIGNED_BIGINT"] = "NOT_AN_UNSIGNED_BIGINT";
|
|
249
|
+
return ValidationErrors2;
|
|
250
|
+
})(ValidationErrors || {});
|
|
251
|
+
var isNumber = (val) => typeof val === "number" && val === val;
|
|
252
|
+
var isString = (val) => typeof val === "string";
|
|
253
|
+
var assertNotEmptyString = (value) => {
|
|
254
|
+
if (!isString(value) || value.length === 0) {
|
|
255
|
+
throw new ValidationError("NOT_A_NONEMPTY_STRING" /* NOT_A_NONEMPTY_STRING */);
|
|
256
|
+
}
|
|
257
|
+
return value;
|
|
258
|
+
};
|
|
259
|
+
var assertPositiveNumber = (value) => {
|
|
260
|
+
if (!isNumber(value) || value <= 0) {
|
|
261
|
+
throw new ValidationError("NOT_A_POSITIVE_NUMBER" /* NOT_A_POSITIVE_NUMBER */);
|
|
262
|
+
}
|
|
263
|
+
return value;
|
|
264
|
+
};
|
|
265
|
+
var assertUnsignedBigInt = (value) => {
|
|
266
|
+
const number = BigInt(value);
|
|
267
|
+
if (number < 0) {
|
|
268
|
+
throw new ValidationError("NOT_AN_UNSIGNED_BIGINT" /* NOT_AN_UNSIGNED_BIGINT */);
|
|
269
|
+
}
|
|
270
|
+
return number;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/errors/index.ts
|
|
274
|
+
var isErrorConstructor = (expect) => {
|
|
275
|
+
return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
276
|
+
expect.prototype.constructor === expect;
|
|
277
|
+
};
|
|
278
|
+
var EmmettError = class _EmmettError extends Error {
|
|
279
|
+
errorCode;
|
|
280
|
+
constructor(options) {
|
|
281
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
|
|
282
|
+
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
283
|
+
super(message);
|
|
284
|
+
this.errorCode = errorCode;
|
|
285
|
+
Object.setPrototypeOf(this, _EmmettError.prototype);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
289
|
+
constructor(current, expected, message) {
|
|
290
|
+
super({
|
|
291
|
+
errorCode: 412,
|
|
292
|
+
message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
|
|
293
|
+
});
|
|
294
|
+
this.current = current;
|
|
295
|
+
this.expected = expected;
|
|
296
|
+
Object.setPrototypeOf(this, _ConcurrencyError.prototype);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
var ValidationError = class _ValidationError extends EmmettError {
|
|
300
|
+
constructor(message) {
|
|
301
|
+
super({
|
|
302
|
+
errorCode: 400,
|
|
303
|
+
message: message ?? `Validation Error ocurred during Emmett processing`
|
|
304
|
+
});
|
|
305
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var IllegalStateError = class _IllegalStateError extends EmmettError {
|
|
309
|
+
constructor(message) {
|
|
310
|
+
super({
|
|
311
|
+
errorCode: 403,
|
|
312
|
+
message: message ?? `Illegal State ocurred during Emmett processing`
|
|
313
|
+
});
|
|
314
|
+
Object.setPrototypeOf(this, _IllegalStateError.prototype);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var NotFoundError = class _NotFoundError extends EmmettError {
|
|
318
|
+
constructor(options) {
|
|
319
|
+
super({
|
|
320
|
+
errorCode: 404,
|
|
321
|
+
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")
|
|
322
|
+
});
|
|
323
|
+
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/eventStore/expectedVersion.ts
|
|
328
|
+
var STREAM_EXISTS = "STREAM_EXISTS";
|
|
329
|
+
var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
|
|
330
|
+
var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
|
|
331
|
+
var matchesExpectedVersion = (current, expected, defaultVersion) => {
|
|
332
|
+
if (expected === NO_CONCURRENCY_CHECK) return true;
|
|
333
|
+
if (expected == STREAM_DOES_NOT_EXIST) return current === defaultVersion;
|
|
334
|
+
if (expected == STREAM_EXISTS) return current !== defaultVersion;
|
|
335
|
+
return current === expected;
|
|
336
|
+
};
|
|
337
|
+
var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) => {
|
|
338
|
+
expected ??= NO_CONCURRENCY_CHECK;
|
|
339
|
+
if (!matchesExpectedVersion(current, expected, defaultVersion))
|
|
340
|
+
throw new ExpectedVersionConflictError(current, expected);
|
|
341
|
+
};
|
|
342
|
+
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
343
|
+
constructor(current, expected) {
|
|
344
|
+
super(current?.toString(), expected?.toString());
|
|
345
|
+
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var isExpectedVersionConflictError = (error2) => error2 instanceof ExpectedVersionConflictError;
|
|
349
|
+
|
|
350
|
+
// src/eventStore/inMemoryEventStore.ts
|
|
351
|
+
var import_uuid3 = require("uuid");
|
|
352
|
+
|
|
353
|
+
// src/eventStore/subscriptions/caughtUpTransformStream.ts
|
|
354
|
+
var import_web_streams_polyfill = require("web-streams-polyfill");
|
|
355
|
+
var streamTrackingGlobalPosition = (currentEvents) => new CaughtUpTransformStream(currentEvents);
|
|
356
|
+
var CaughtUpTransformStream = class extends import_web_streams_polyfill.TransformStream {
|
|
357
|
+
_currentPosition;
|
|
358
|
+
_logPosition;
|
|
359
|
+
constructor(events) {
|
|
360
|
+
super({
|
|
361
|
+
start: (controller) => {
|
|
362
|
+
let globalPosition = 0n;
|
|
363
|
+
for (const event2 of events) {
|
|
364
|
+
controller.enqueue(event2);
|
|
365
|
+
globalPosition = event2.metadata.globalPosition;
|
|
366
|
+
}
|
|
367
|
+
controller.enqueue(globalStreamCaughtUp({ globalPosition }));
|
|
368
|
+
},
|
|
369
|
+
transform: (event2, controller) => {
|
|
370
|
+
this._currentPosition = event2.metadata.globalPosition;
|
|
371
|
+
controller.enqueue(event2);
|
|
372
|
+
if (this._currentPosition < this._logPosition) return;
|
|
373
|
+
controller.enqueue(
|
|
374
|
+
globalStreamCaughtUp({ globalPosition: this._currentPosition })
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
this._currentPosition = this._logPosition = events.length > 0 ? events[events.length - 1].metadata.globalPosition : 0n;
|
|
379
|
+
}
|
|
380
|
+
set logPosition(value) {
|
|
381
|
+
this._logPosition = value;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// src/eventStore/subscriptions/streamingCoordinator.ts
|
|
386
|
+
var import_uuid2 = require("uuid");
|
|
387
|
+
|
|
388
|
+
// src/streaming/transformations/notifyAboutNoActiveReaders.ts
|
|
389
|
+
var import_uuid = require("uuid");
|
|
390
|
+
var import_web_streams_polyfill2 = require("web-streams-polyfill");
|
|
391
|
+
var notifyAboutNoActiveReadersStream = (onNoActiveReaderCallback, options = {}) => new NotifyAboutNoActiveReadersStream(onNoActiveReaderCallback, options);
|
|
392
|
+
var NotifyAboutNoActiveReadersStream = class extends import_web_streams_polyfill2.TransformStream {
|
|
393
|
+
constructor(onNoActiveReaderCallback, options = {}) {
|
|
394
|
+
super({
|
|
395
|
+
cancel: (reason) => {
|
|
396
|
+
console.log("Stream was canceled. Reason:", reason);
|
|
397
|
+
this.stopChecking();
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
401
|
+
this.streamId = options?.streamId ?? (0, import_uuid.v4)();
|
|
402
|
+
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
403
|
+
this.startChecking(options?.intervalCheckInMs ?? 20);
|
|
404
|
+
}
|
|
405
|
+
checkInterval = null;
|
|
406
|
+
streamId;
|
|
407
|
+
_isStopped = false;
|
|
408
|
+
get hasActiveSubscribers() {
|
|
409
|
+
return !this._isStopped;
|
|
410
|
+
}
|
|
411
|
+
startChecking(interval) {
|
|
412
|
+
this.checkInterval = setInterval(() => {
|
|
413
|
+
this.checkNoActiveReader();
|
|
414
|
+
}, interval);
|
|
415
|
+
}
|
|
416
|
+
stopChecking() {
|
|
417
|
+
if (!this.checkInterval) return;
|
|
418
|
+
clearInterval(this.checkInterval);
|
|
419
|
+
this.checkInterval = null;
|
|
420
|
+
this._isStopped = true;
|
|
421
|
+
this.onNoActiveReaderCallback(this);
|
|
422
|
+
}
|
|
423
|
+
checkNoActiveReader() {
|
|
424
|
+
if (!this.readable.locked && !this._isStopped) {
|
|
425
|
+
this.stopChecking();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// src/streaming/writers/writeToStream.ts
|
|
431
|
+
var writeToStream = async (stream, items) => {
|
|
432
|
+
if (stream.writable.locked) return false;
|
|
433
|
+
const writer = stream.writable.getWriter();
|
|
434
|
+
await writer.ready;
|
|
435
|
+
if (!stream.readable.locked) return false;
|
|
436
|
+
try {
|
|
437
|
+
for (const item of items) {
|
|
438
|
+
await writer.write(item);
|
|
439
|
+
}
|
|
440
|
+
} catch (error2) {
|
|
441
|
+
console.log(error2);
|
|
442
|
+
} finally {
|
|
443
|
+
await writer.close();
|
|
444
|
+
}
|
|
445
|
+
return true;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/eventStore/subscriptions/streamingCoordinator.ts
|
|
449
|
+
var StreamingCoordinator = () => {
|
|
450
|
+
const allEvents = [];
|
|
451
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
452
|
+
return {
|
|
453
|
+
notify: async (events) => {
|
|
454
|
+
if (events.length === 0) return;
|
|
455
|
+
allEvents.push(...events);
|
|
456
|
+
for (const listener of listeners.values()) {
|
|
457
|
+
listener.logPosition = events[events.length - 1].metadata.globalPosition;
|
|
458
|
+
await writeToStream(listener, events);
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
stream: () => {
|
|
462
|
+
const streamId = (0, import_uuid2.v4)();
|
|
463
|
+
const transformStream = streamTrackingGlobalPosition(allEvents);
|
|
464
|
+
listeners.set(streamId, transformStream);
|
|
465
|
+
return transformStream.readable.pipeThrough(
|
|
466
|
+
notifyAboutNoActiveReadersStream(
|
|
467
|
+
(stream) => {
|
|
468
|
+
if (listeners.has(stream.streamId))
|
|
469
|
+
listeners.delete(stream.streamId);
|
|
470
|
+
},
|
|
471
|
+
{ streamId }
|
|
472
|
+
)
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/eventStore/inMemoryEventStore.ts
|
|
479
|
+
var InMemoryEventStoreDefaultStreamVersion = 0n;
|
|
480
|
+
var getInMemoryEventStore = () => {
|
|
481
|
+
const streams = /* @__PURE__ */ new Map();
|
|
482
|
+
const streamingCoordinator = StreamingCoordinator();
|
|
483
|
+
const getAllEventsCount = () => {
|
|
484
|
+
return Array.from(streams.values()).map((s) => s.length).reduce((p, c) => p + c, 0);
|
|
485
|
+
};
|
|
486
|
+
return {
|
|
487
|
+
async aggregateStream(streamName, options) {
|
|
488
|
+
const { evolve, initialState, read } = options;
|
|
489
|
+
const result = await this.readStream(streamName, read);
|
|
490
|
+
const events = result?.events ?? [];
|
|
491
|
+
return {
|
|
492
|
+
currentStreamVersion: BigInt(events.length),
|
|
493
|
+
state: events.reduce(evolve, initialState()),
|
|
494
|
+
streamExists: result.streamExists
|
|
495
|
+
};
|
|
496
|
+
},
|
|
497
|
+
readStream: (streamName, options) => {
|
|
498
|
+
const events = streams.get(streamName);
|
|
499
|
+
const currentStreamVersion = events ? BigInt(events.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
500
|
+
assertExpectedVersionMatchesCurrent(
|
|
501
|
+
currentStreamVersion,
|
|
502
|
+
options?.expectedStreamVersion,
|
|
503
|
+
InMemoryEventStoreDefaultStreamVersion
|
|
504
|
+
);
|
|
505
|
+
const from = Number(options && "from" in options ? options.from : 0);
|
|
506
|
+
const to = Number(
|
|
507
|
+
options && "to" in options ? options.to : options && "maxCount" in options && options.maxCount ? options.from + options.maxCount : events?.length ?? 1
|
|
508
|
+
);
|
|
509
|
+
const resultEvents = events !== void 0 && events.length > 0 ? events.map(
|
|
510
|
+
(e) => e
|
|
511
|
+
).slice(from, to) : [];
|
|
512
|
+
const result = {
|
|
513
|
+
currentStreamVersion,
|
|
514
|
+
events: resultEvents,
|
|
515
|
+
streamExists: events !== void 0 && events.length > 0
|
|
516
|
+
};
|
|
517
|
+
return Promise.resolve(result);
|
|
518
|
+
},
|
|
519
|
+
appendToStream: async (streamName, events, options) => {
|
|
520
|
+
const currentEvents = streams.get(streamName) ?? [];
|
|
521
|
+
const currentStreamVersion = currentEvents.length > 0 ? BigInt(currentEvents.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
522
|
+
assertExpectedVersionMatchesCurrent(
|
|
523
|
+
currentStreamVersion,
|
|
524
|
+
options?.expectedStreamVersion,
|
|
525
|
+
InMemoryEventStoreDefaultStreamVersion
|
|
526
|
+
);
|
|
527
|
+
const newEvents = events.map((event2, index) => {
|
|
528
|
+
return {
|
|
529
|
+
...event2,
|
|
530
|
+
metadata: {
|
|
531
|
+
...event2.metadata ?? {},
|
|
532
|
+
streamName,
|
|
533
|
+
eventId: (0, import_uuid3.v4)(),
|
|
534
|
+
streamPosition: BigInt(currentEvents.length + index + 1),
|
|
535
|
+
globalPosition: BigInt(getAllEventsCount() + index + 1)
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
});
|
|
539
|
+
const positionOfLastEventInTheStream = BigInt(
|
|
540
|
+
newEvents.slice(-1)[0].metadata.streamPosition
|
|
541
|
+
);
|
|
542
|
+
streams.set(streamName, [...currentEvents, ...newEvents]);
|
|
543
|
+
await streamingCoordinator.notify(newEvents);
|
|
544
|
+
const result = {
|
|
545
|
+
nextExpectedStreamVersion: positionOfLastEventInTheStream,
|
|
546
|
+
createdNewStream: currentStreamVersion === InMemoryEventStoreDefaultStreamVersion
|
|
547
|
+
};
|
|
548
|
+
return result;
|
|
549
|
+
}
|
|
550
|
+
//streamEvents: streamingCoordinator.stream,
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// src/utils/deepEquals.ts
|
|
555
|
+
var deepEquals = (left, right) => {
|
|
556
|
+
if (isEquatable(left)) {
|
|
557
|
+
return left.equals(right);
|
|
558
|
+
}
|
|
559
|
+
if (Array.isArray(left)) {
|
|
560
|
+
return Array.isArray(right) && left.length === right.length && left.every((val, index) => deepEquals(val, right[index]));
|
|
561
|
+
}
|
|
562
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
|
|
563
|
+
return left === right;
|
|
564
|
+
}
|
|
565
|
+
if (Array.isArray(right)) return false;
|
|
566
|
+
const keys1 = Object.keys(left);
|
|
567
|
+
const keys2 = Object.keys(right);
|
|
568
|
+
if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key)))
|
|
569
|
+
return false;
|
|
570
|
+
for (const key in left) {
|
|
571
|
+
if (left[key] instanceof Function && right[key] instanceof Function)
|
|
572
|
+
continue;
|
|
573
|
+
const isEqual = deepEquals(left[key], right[key]);
|
|
574
|
+
if (!isEqual) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return true;
|
|
579
|
+
};
|
|
580
|
+
var isEquatable = (left) => {
|
|
581
|
+
return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// src/utils/iterators.ts
|
|
585
|
+
var sum = (iterator) => {
|
|
586
|
+
let value, done, sum2 = 0;
|
|
587
|
+
do {
|
|
588
|
+
({ value, done } = iterator.next());
|
|
589
|
+
sum2 += value || 0;
|
|
590
|
+
} while (!done);
|
|
591
|
+
return sum2;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// src/utils/merge.ts
|
|
595
|
+
var merge = (array, item, where, onExisting, onNotFound = () => void 0) => {
|
|
596
|
+
let wasFound = false;
|
|
597
|
+
const result = array.map((p) => {
|
|
598
|
+
if (!where(p)) return p;
|
|
599
|
+
wasFound = true;
|
|
600
|
+
return onExisting(p);
|
|
601
|
+
}).filter((p) => p !== void 0).map((p) => {
|
|
602
|
+
if (!p) throw Error("That should not happen");
|
|
603
|
+
return p;
|
|
604
|
+
});
|
|
605
|
+
if (!wasFound) {
|
|
606
|
+
const result2 = onNotFound();
|
|
607
|
+
if (result2 !== void 0) return [...array, item];
|
|
608
|
+
}
|
|
609
|
+
return result;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/utils/retry.ts
|
|
613
|
+
var import_async_retry = __toESM(require("async-retry"), 1);
|
|
614
|
+
var NoRetries = { retries: 0 };
|
|
615
|
+
var asyncRetry = async (fn, opts) => {
|
|
616
|
+
if (opts === void 0 || opts.retries === 0) return fn();
|
|
617
|
+
return (0, import_async_retry.default)(
|
|
618
|
+
async (bail) => {
|
|
619
|
+
try {
|
|
620
|
+
return await fn();
|
|
621
|
+
} catch (error2) {
|
|
622
|
+
if (opts?.shouldRetryError && !opts.shouldRetryError(error2)) {
|
|
623
|
+
bail(error2);
|
|
624
|
+
}
|
|
625
|
+
throw error2;
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
opts ?? { retries: 0 }
|
|
629
|
+
);
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// src/commandHandling/handleCommand.ts
|
|
633
|
+
var CommandHandlerStreamVersionConflictRetryOptions = {
|
|
634
|
+
retries: 3,
|
|
635
|
+
minTimeout: 100,
|
|
636
|
+
factor: 1.5,
|
|
637
|
+
shouldRetryError: isExpectedVersionConflictError
|
|
638
|
+
};
|
|
639
|
+
var fromCommandHandlerRetryOptions = (retryOptions) => {
|
|
640
|
+
if (retryOptions === void 0) return NoRetries;
|
|
641
|
+
if ("onVersionConflict" in retryOptions) {
|
|
642
|
+
if (typeof retryOptions.onVersionConflict === "boolean")
|
|
643
|
+
return CommandHandlerStreamVersionConflictRetryOptions;
|
|
644
|
+
else if (typeof retryOptions.onVersionConflict === "number")
|
|
645
|
+
return {
|
|
646
|
+
...CommandHandlerStreamVersionConflictRetryOptions,
|
|
647
|
+
retries: retryOptions.onVersionConflict
|
|
648
|
+
};
|
|
649
|
+
else return retryOptions.onVersionConflict;
|
|
650
|
+
}
|
|
651
|
+
return retryOptions;
|
|
652
|
+
};
|
|
653
|
+
var CommandHandler = (options) => async (store, id, handle, handleOptions) => asyncRetry(
|
|
654
|
+
async () => {
|
|
655
|
+
const result = await withSession(store, async ({ eventStore }) => {
|
|
656
|
+
const { evolve, initialState } = options;
|
|
657
|
+
const mapToStreamId = options.mapToStreamId ?? ((id2) => id2);
|
|
658
|
+
const streamName = mapToStreamId(id);
|
|
659
|
+
const aggregationResult = await eventStore.aggregateStream(streamName, {
|
|
660
|
+
evolve,
|
|
661
|
+
initialState,
|
|
662
|
+
read: {
|
|
663
|
+
// expected stream version is passed to fail fast
|
|
664
|
+
// if stream is in the wrong state
|
|
665
|
+
expectedStreamVersion: handleOptions?.expectedStreamVersion ?? NO_CONCURRENCY_CHECK
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
const state = aggregationResult.state;
|
|
669
|
+
const currentStreamVersion = aggregationResult.currentStreamVersion;
|
|
670
|
+
const result2 = await handle(state);
|
|
671
|
+
const newEvents = Array.isArray(result2) ? result2 : [result2];
|
|
672
|
+
if (newEvents.length === 0) {
|
|
673
|
+
return {
|
|
674
|
+
newEvents: [],
|
|
675
|
+
newState: state,
|
|
676
|
+
nextExpectedStreamVersion: currentStreamVersion,
|
|
677
|
+
createdNewStream: false
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
const expectedStreamVersion = handleOptions?.expectedStreamVersion ?? (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST);
|
|
681
|
+
const appendResult = await eventStore.appendToStream(
|
|
682
|
+
streamName,
|
|
683
|
+
newEvents,
|
|
684
|
+
{
|
|
685
|
+
...handleOptions,
|
|
686
|
+
expectedStreamVersion
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
return {
|
|
690
|
+
...appendResult,
|
|
691
|
+
newEvents,
|
|
692
|
+
newState: newEvents.reduce(evolve, state)
|
|
693
|
+
};
|
|
694
|
+
});
|
|
695
|
+
return result;
|
|
696
|
+
},
|
|
697
|
+
fromCommandHandlerRetryOptions(
|
|
698
|
+
handleOptions && "retry" in handleOptions ? handleOptions.retry : options.retry
|
|
699
|
+
)
|
|
700
|
+
);
|
|
701
|
+
var withSession = (eventStore, callback) => {
|
|
702
|
+
const sessionFactory = canCreateEventStoreSession(eventStore) ? eventStore : nulloSessionFactory(eventStore);
|
|
703
|
+
return sessionFactory.withSession(callback);
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
// src/commandHandling/handleCommandWithDecider.ts
|
|
707
|
+
var DeciderCommandHandler = (options) => async (eventStore, id, command2, handleOptions) => {
|
|
708
|
+
const { decide, ...rest } = options;
|
|
709
|
+
return CommandHandler(rest)(
|
|
710
|
+
eventStore,
|
|
711
|
+
id,
|
|
712
|
+
(state) => decide(command2, state),
|
|
713
|
+
handleOptions
|
|
714
|
+
);
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// src/config/plugins/index.ts
|
|
718
|
+
var import_commander = require("commander");
|
|
719
|
+
var isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
|
|
720
|
+
|
|
721
|
+
// src/messageBus/index.ts
|
|
722
|
+
var getInMemoryMessageBus = () => {
|
|
723
|
+
const allHandlers = /* @__PURE__ */ new Map();
|
|
724
|
+
let pendingMessages = [];
|
|
725
|
+
return {
|
|
726
|
+
send: async (command2) => {
|
|
727
|
+
const handlers = allHandlers.get(command2.type);
|
|
728
|
+
if (handlers === void 0 || handlers.length === 0)
|
|
729
|
+
throw new EmmettError(
|
|
730
|
+
`No handler registered for command ${command2.type}!`
|
|
731
|
+
);
|
|
732
|
+
const commandHandler = handlers[0];
|
|
733
|
+
await commandHandler(command2);
|
|
734
|
+
},
|
|
735
|
+
publish: async (event2) => {
|
|
736
|
+
const handlers = allHandlers.get(event2.type) ?? [];
|
|
737
|
+
for (const handler of handlers) {
|
|
738
|
+
const eventHandler = handler;
|
|
739
|
+
await eventHandler(event2);
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
schedule: (message, when) => {
|
|
743
|
+
pendingMessages = [...pendingMessages, { message, options: when }];
|
|
744
|
+
},
|
|
745
|
+
handle: (commandHandler, ...commandTypes) => {
|
|
746
|
+
const alreadyRegistered = [...allHandlers.keys()].filter(
|
|
747
|
+
(registered) => commandTypes.includes(registered)
|
|
748
|
+
);
|
|
749
|
+
if (alreadyRegistered.length > 0)
|
|
750
|
+
throw new EmmettError(
|
|
751
|
+
`Cannot register handler for commands ${alreadyRegistered.join(", ")} as they're already registered!`
|
|
752
|
+
);
|
|
753
|
+
for (const commandType of commandTypes) {
|
|
754
|
+
allHandlers.set(commandType, [commandHandler]);
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
subscribe(eventHandler, ...eventTypes) {
|
|
758
|
+
for (const eventType of eventTypes) {
|
|
759
|
+
if (!allHandlers.has(eventType)) allHandlers.set(eventType, []);
|
|
760
|
+
allHandlers.set(eventType, [
|
|
761
|
+
...allHandlers.get(eventType) ?? [],
|
|
762
|
+
eventHandler
|
|
763
|
+
]);
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
dequeue: () => {
|
|
767
|
+
const pending = pendingMessages;
|
|
768
|
+
pendingMessages = [];
|
|
769
|
+
return pending;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
// src/projections/index.ts
|
|
775
|
+
var projection = (definition) => definition;
|
|
776
|
+
var inlineProjections = (definitions) => definitions.map((projection2) => ({ type: "inline", projection: projection2 }));
|
|
777
|
+
var asyncProjections = (definitions) => definitions.map((projection2) => ({ type: "async", projection: projection2 }));
|
|
778
|
+
var projections = {
|
|
779
|
+
inline: inlineProjections,
|
|
780
|
+
async: asyncProjections
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
// src/serialization/json/JSONParser.ts
|
|
784
|
+
var ParseError = class extends Error {
|
|
785
|
+
constructor(text) {
|
|
786
|
+
super(`Cannot parse! ${text}`);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
var JSONParser = {
|
|
790
|
+
stringify: (value, options) => {
|
|
791
|
+
return JSON.stringify(
|
|
792
|
+
options?.map ? options.map(value) : value,
|
|
793
|
+
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
794
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
795
|
+
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
796
|
+
);
|
|
797
|
+
},
|
|
798
|
+
parse: (text, options) => {
|
|
799
|
+
const parsed = JSON.parse(text, options?.reviver);
|
|
800
|
+
if (options?.typeCheck && !options?.typeCheck(parsed))
|
|
801
|
+
throw new ParseError(text);
|
|
802
|
+
return options?.map ? options.map(parsed) : parsed;
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
// src/streaming/binaryArrays.ts
|
|
807
|
+
var concatUint8Arrays = (chunks) => {
|
|
808
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
809
|
+
const result = new Uint8Array(totalLength);
|
|
810
|
+
let offset = 0;
|
|
811
|
+
for (const chunk of chunks) {
|
|
812
|
+
result.set(chunk, offset);
|
|
813
|
+
offset += chunk.length;
|
|
814
|
+
}
|
|
815
|
+
return result;
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// src/streaming/collectors/collect.ts
|
|
819
|
+
var collect = async (stream) => {
|
|
820
|
+
const results = [];
|
|
821
|
+
for await (const value of stream) {
|
|
822
|
+
results.push(value);
|
|
823
|
+
}
|
|
824
|
+
return results;
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// src/streaming/decoders/binary.ts
|
|
828
|
+
var BinaryJsonDecoder = class {
|
|
829
|
+
buffer = [];
|
|
830
|
+
addToBuffer(data) {
|
|
831
|
+
this.buffer.push(data);
|
|
832
|
+
}
|
|
833
|
+
clearBuffer() {
|
|
834
|
+
this.buffer = [];
|
|
835
|
+
}
|
|
836
|
+
hasCompleteMessage() {
|
|
837
|
+
const combined = concatUint8Arrays(this.buffer);
|
|
838
|
+
const text = new TextDecoder().decode(combined);
|
|
839
|
+
return text.includes("\n");
|
|
840
|
+
}
|
|
841
|
+
decode() {
|
|
842
|
+
if (!this.hasCompleteMessage()) {
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
const combined = concatUint8Arrays(this.buffer);
|
|
846
|
+
const text = new TextDecoder().decode(combined);
|
|
847
|
+
const delimiterIndex = text.indexOf("\n");
|
|
848
|
+
if (delimiterIndex === -1) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
const jsonString = text.slice(0, delimiterIndex);
|
|
852
|
+
const remaining = new Uint8Array(combined.buffer, delimiterIndex + 1);
|
|
853
|
+
this.buffer = remaining.byteLength > 0 ? [remaining] : [];
|
|
854
|
+
return JSON.parse(jsonString);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
// src/streaming/decoders/string.ts
|
|
859
|
+
var StringDecoder = class {
|
|
860
|
+
constructor(transform) {
|
|
861
|
+
this.transform = transform;
|
|
862
|
+
this.transform = transform;
|
|
863
|
+
}
|
|
864
|
+
buffer = [];
|
|
865
|
+
addToBuffer(data) {
|
|
866
|
+
this.buffer.push(data);
|
|
867
|
+
}
|
|
868
|
+
clearBuffer() {
|
|
869
|
+
this.buffer = [];
|
|
870
|
+
}
|
|
871
|
+
hasCompleteMessage() {
|
|
872
|
+
return this.buffer.some((chunk) => chunk.includes("\n"));
|
|
873
|
+
}
|
|
874
|
+
decode() {
|
|
875
|
+
const completeString = this.buffer.join("");
|
|
876
|
+
if (!this.hasCompleteMessage()) {
|
|
877
|
+
if (completeString.trim().length > 0) {
|
|
878
|
+
throw new Error("Unterminated string in JSON at position");
|
|
879
|
+
}
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
const delimiterIndex = completeString.indexOf("\n");
|
|
883
|
+
const message = completeString.slice(0, delimiterIndex).trim();
|
|
884
|
+
this.buffer = [completeString.slice(delimiterIndex + 1)];
|
|
885
|
+
return this.transform(message);
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
// src/streaming/decoders/json.ts
|
|
890
|
+
var JsonDecoder = class extends StringDecoder {
|
|
891
|
+
constructor() {
|
|
892
|
+
super((jsonString) => JSON.parse(jsonString));
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
// src/streaming/decoders/object.ts
|
|
897
|
+
var ObjectDecoder = class {
|
|
898
|
+
buffer = null;
|
|
899
|
+
addToBuffer(data) {
|
|
900
|
+
this.buffer = data;
|
|
901
|
+
}
|
|
902
|
+
clearBuffer() {
|
|
903
|
+
this.buffer = null;
|
|
904
|
+
}
|
|
905
|
+
hasCompleteMessage() {
|
|
906
|
+
return this.buffer !== null;
|
|
907
|
+
}
|
|
908
|
+
decode() {
|
|
909
|
+
if (!this.hasCompleteMessage() || !this.buffer) {
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
const data = this.buffer;
|
|
913
|
+
this.clearBuffer();
|
|
914
|
+
return data;
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// src/streaming/decoders/composite.ts
|
|
919
|
+
var CompositeDecoder = class {
|
|
920
|
+
constructor(decoders) {
|
|
921
|
+
this.decoders = decoders;
|
|
922
|
+
}
|
|
923
|
+
decoderFor(data) {
|
|
924
|
+
const decoder = this.decoders.find((d) => d[0](data));
|
|
925
|
+
if (!decoder) return null;
|
|
926
|
+
return decoder[1];
|
|
927
|
+
}
|
|
928
|
+
addToBuffer(data) {
|
|
929
|
+
this.decoderFor(data)?.addToBuffer(data);
|
|
930
|
+
}
|
|
931
|
+
clearBuffer() {
|
|
932
|
+
for (const decoder of this.decoders.map((d) => d[1])) {
|
|
933
|
+
decoder.clearBuffer();
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
hasCompleteMessage() {
|
|
937
|
+
return this.decoders.some((d) => d[1].hasCompleteMessage());
|
|
938
|
+
}
|
|
939
|
+
decode() {
|
|
940
|
+
const decoder = this.decoders.map((d) => d[1]).find((d) => d.hasCompleteMessage());
|
|
941
|
+
return decoder?.decode() ?? null;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
var DefaultDecoder = class extends CompositeDecoder {
|
|
945
|
+
constructor() {
|
|
946
|
+
super([
|
|
947
|
+
[(data) => typeof data === "string", new JsonDecoder()],
|
|
948
|
+
[(data) => data instanceof Uint8Array, new BinaryJsonDecoder()],
|
|
949
|
+
[(data) => typeof data === "object", new ObjectDecoder()]
|
|
950
|
+
]);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
// src/streaming/generators/fromArray.ts
|
|
955
|
+
var import_web_streams_polyfill3 = require("web-streams-polyfill");
|
|
956
|
+
var fromArray = (chunks) => new import_web_streams_polyfill3.ReadableStream({
|
|
957
|
+
start(controller) {
|
|
958
|
+
for (const chunk of chunks) controller.enqueue(chunk);
|
|
959
|
+
controller.close();
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// src/streaming/generators/index.ts
|
|
964
|
+
var streamGenerators = { fromArray };
|
|
965
|
+
|
|
966
|
+
// src/streaming/restream.ts
|
|
967
|
+
var import_web_streams_polyfill13 = require("web-streams-polyfill");
|
|
968
|
+
|
|
969
|
+
// src/streaming/transformations/filter.ts
|
|
970
|
+
var import_web_streams_polyfill4 = require("web-streams-polyfill");
|
|
971
|
+
var filter = (filter2) => new import_web_streams_polyfill4.TransformStream({
|
|
972
|
+
transform(chunk, controller) {
|
|
973
|
+
if (filter2(chunk)) {
|
|
974
|
+
controller.enqueue(chunk);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
// src/streaming/transformations/map.ts
|
|
980
|
+
var import_web_streams_polyfill5 = require("web-streams-polyfill");
|
|
981
|
+
var map = (map2) => new import_web_streams_polyfill5.TransformStream({
|
|
982
|
+
transform(chunk, controller) {
|
|
983
|
+
controller.enqueue(map2(chunk));
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
// src/streaming/transformations/reduce.ts
|
|
988
|
+
var import_web_streams_polyfill6 = require("web-streams-polyfill");
|
|
989
|
+
var reduce = (reducer, initialValue) => new ReduceTransformStream(reducer, initialValue);
|
|
990
|
+
var ReduceTransformStream = class extends import_web_streams_polyfill6.TransformStream {
|
|
991
|
+
accumulator;
|
|
992
|
+
reducer;
|
|
993
|
+
constructor(reducer, initialValue) {
|
|
994
|
+
super({
|
|
995
|
+
transform: (chunk) => {
|
|
996
|
+
this.accumulator = this.reducer(this.accumulator, chunk);
|
|
997
|
+
},
|
|
998
|
+
flush: (controller) => {
|
|
999
|
+
controller.enqueue(this.accumulator);
|
|
1000
|
+
controller.terminate();
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
this.accumulator = initialValue;
|
|
1004
|
+
this.reducer = reducer;
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// src/streaming/transformations/retry.ts
|
|
1009
|
+
var import_web_streams_polyfill7 = require("web-streams-polyfill");
|
|
1010
|
+
var retryStream = (createSourceStream, handleChunk2, retryOptions = { forever: true, minTimeout: 25 }) => new import_web_streams_polyfill7.TransformStream({
|
|
1011
|
+
start(controller) {
|
|
1012
|
+
asyncRetry(
|
|
1013
|
+
() => onRestream(createSourceStream, handleChunk2, controller),
|
|
1014
|
+
retryOptions
|
|
1015
|
+
).catch((error2) => {
|
|
1016
|
+
controller.error(error2);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
var onRestream = async (createSourceStream, handleChunk2, controller) => {
|
|
1021
|
+
const sourceStream = createSourceStream();
|
|
1022
|
+
const reader = sourceStream.getReader();
|
|
1023
|
+
try {
|
|
1024
|
+
let done;
|
|
1025
|
+
do {
|
|
1026
|
+
const result = await reader.read();
|
|
1027
|
+
done = result.done;
|
|
1028
|
+
await handleChunk2(result, controller);
|
|
1029
|
+
if (done) {
|
|
1030
|
+
controller.terminate();
|
|
1031
|
+
}
|
|
1032
|
+
} while (!done);
|
|
1033
|
+
} finally {
|
|
1034
|
+
reader.releaseLock();
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
// src/streaming/transformations/skip.ts
|
|
1039
|
+
var import_web_streams_polyfill8 = require("web-streams-polyfill");
|
|
1040
|
+
var skip = (limit) => new SkipTransformStream(limit);
|
|
1041
|
+
var SkipTransformStream = class extends import_web_streams_polyfill8.TransformStream {
|
|
1042
|
+
count = 0;
|
|
1043
|
+
skip;
|
|
1044
|
+
constructor(skip2) {
|
|
1045
|
+
super({
|
|
1046
|
+
transform: (chunk, controller) => {
|
|
1047
|
+
this.count++;
|
|
1048
|
+
if (this.count > this.skip) {
|
|
1049
|
+
controller.enqueue(chunk);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
this.skip = skip2;
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
// src/streaming/transformations/stopAfter.ts
|
|
1058
|
+
var import_web_streams_polyfill9 = require("web-streams-polyfill");
|
|
1059
|
+
var stopAfter = (stopCondition) => new import_web_streams_polyfill9.TransformStream({
|
|
1060
|
+
transform(chunk, controller) {
|
|
1061
|
+
controller.enqueue(chunk);
|
|
1062
|
+
if (stopCondition(chunk)) {
|
|
1063
|
+
controller.terminate();
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// src/streaming/transformations/stopOn.ts
|
|
1069
|
+
var import_web_streams_polyfill10 = require("web-streams-polyfill");
|
|
1070
|
+
var stopOn = (stopCondition) => new import_web_streams_polyfill10.TransformStream({
|
|
1071
|
+
async transform(chunk, controller) {
|
|
1072
|
+
if (!stopCondition(chunk)) {
|
|
1073
|
+
controller.enqueue(chunk);
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
await Promise.resolve();
|
|
1077
|
+
controller.terminate();
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
// src/streaming/transformations/take.ts
|
|
1082
|
+
var import_web_streams_polyfill11 = require("web-streams-polyfill");
|
|
1083
|
+
var take = (limit) => new TakeTransformStream(limit);
|
|
1084
|
+
var TakeTransformStream = class extends import_web_streams_polyfill11.TransformStream {
|
|
1085
|
+
count = 0;
|
|
1086
|
+
limit;
|
|
1087
|
+
constructor(limit) {
|
|
1088
|
+
super({
|
|
1089
|
+
transform: (chunk, controller) => {
|
|
1090
|
+
if (this.count < this.limit) {
|
|
1091
|
+
this.count++;
|
|
1092
|
+
controller.enqueue(chunk);
|
|
1093
|
+
} else {
|
|
1094
|
+
controller.terminate();
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
this.limit = limit;
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
// src/streaming/transformations/waitAtMost.ts
|
|
1103
|
+
var import_web_streams_polyfill12 = require("web-streams-polyfill");
|
|
1104
|
+
var waitAtMost = (waitTimeInMs) => new import_web_streams_polyfill12.TransformStream({
|
|
1105
|
+
start(controller) {
|
|
1106
|
+
const timeoutId = setTimeout(() => {
|
|
1107
|
+
controller.terminate();
|
|
1108
|
+
}, waitTimeInMs);
|
|
1109
|
+
const originalTerminate = controller.terminate.bind(controller);
|
|
1110
|
+
controller.terminate = () => {
|
|
1111
|
+
clearTimeout(timeoutId);
|
|
1112
|
+
originalTerminate();
|
|
1113
|
+
};
|
|
1114
|
+
},
|
|
1115
|
+
transform(chunk, controller) {
|
|
1116
|
+
controller.enqueue(chunk);
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
// src/streaming/transformations/index.ts
|
|
1121
|
+
var streamTransformations = {
|
|
1122
|
+
filter,
|
|
1123
|
+
take,
|
|
1124
|
+
TakeTransformStream,
|
|
1125
|
+
skip,
|
|
1126
|
+
SkipTransformStream,
|
|
1127
|
+
map,
|
|
1128
|
+
notifyAboutNoActiveReadersStream,
|
|
1129
|
+
NotifyAboutNoActiveReadersStream,
|
|
1130
|
+
reduce,
|
|
1131
|
+
ReduceTransformStream,
|
|
1132
|
+
retry: retryStream,
|
|
1133
|
+
stopAfter,
|
|
1134
|
+
stopOn,
|
|
1135
|
+
waitAtMost
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// src/streaming/restream.ts
|
|
1139
|
+
var { retry: retry2 } = streamTransformations;
|
|
1140
|
+
var restream = (createSourceStream, transform = (source) => source, retryOptions = { forever: true, minTimeout: 25 }, decoder = new DefaultDecoder()) => retry2(createSourceStream, handleChunk(transform, decoder), retryOptions).readable;
|
|
1141
|
+
var handleChunk = (transform = (source) => source, decoder = new DefaultDecoder()) => (readResult, controller) => {
|
|
1142
|
+
const { done: isDone, value } = readResult;
|
|
1143
|
+
if (value) decoder.addToBuffer(value);
|
|
1144
|
+
if (!isDone && !decoder.hasCompleteMessage()) return;
|
|
1145
|
+
decodeAndTransform(decoder, transform, controller);
|
|
1146
|
+
};
|
|
1147
|
+
var decodeAndTransform = (decoder, transform, controller) => {
|
|
1148
|
+
try {
|
|
1149
|
+
const decoded = decoder.decode();
|
|
1150
|
+
if (!decoded) return;
|
|
1151
|
+
const transformed = transform(decoded);
|
|
1152
|
+
controller.enqueue(transformed);
|
|
1153
|
+
} catch (error2) {
|
|
1154
|
+
controller.error(new Error(`Decoding error: ${error2?.toString()}`));
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
// src/testing/assertions.ts
|
|
1159
|
+
var AssertionError = class extends Error {
|
|
1160
|
+
constructor(message) {
|
|
1161
|
+
super(message);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
var isSubset = (superObj, subObj) => {
|
|
1165
|
+
const sup = superObj;
|
|
1166
|
+
const sub = subObj;
|
|
1167
|
+
assertOk(sup);
|
|
1168
|
+
assertOk(sub);
|
|
1169
|
+
return Object.keys(sub).every((ele) => {
|
|
1170
|
+
if (typeof sub[ele] == "object") {
|
|
1171
|
+
return isSubset(sup[ele], sub[ele]);
|
|
1172
|
+
}
|
|
1173
|
+
return sub[ele] === sup[ele];
|
|
1174
|
+
});
|
|
1175
|
+
};
|
|
1176
|
+
var assertFails = (message) => {
|
|
1177
|
+
throw new AssertionError(message ?? "That should not ever happened, right?");
|
|
1178
|
+
};
|
|
1179
|
+
var assertThrowsAsync = async (fun, errorCheck) => {
|
|
1180
|
+
try {
|
|
1181
|
+
await fun();
|
|
1182
|
+
throw new AssertionError("Function didn't throw expected error");
|
|
1183
|
+
} catch (error2) {
|
|
1184
|
+
const typedError = error2;
|
|
1185
|
+
if (errorCheck) assertTrue(errorCheck(typedError));
|
|
1186
|
+
return typedError;
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
var assertThrows = (fun, errorCheck) => {
|
|
1190
|
+
try {
|
|
1191
|
+
fun();
|
|
1192
|
+
throw new AssertionError("Function didn't throw expected error");
|
|
1193
|
+
} catch (error2) {
|
|
1194
|
+
const typedError = error2;
|
|
1195
|
+
if (errorCheck) assertTrue(errorCheck(typedError));
|
|
1196
|
+
return typedError;
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
var assertRejects = async (promise, errorCheck) => {
|
|
1200
|
+
try {
|
|
1201
|
+
await promise;
|
|
1202
|
+
throw new AssertionError("Function didn't throw expected error");
|
|
1203
|
+
} catch (error2) {
|
|
1204
|
+
if (!errorCheck) return;
|
|
1205
|
+
if (errorCheck instanceof Error) assertDeepEqual(error2, errorCheck);
|
|
1206
|
+
else assertTrue(errorCheck(error2));
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
var assertMatches = (actual, expected, message) => {
|
|
1210
|
+
if (!isSubset(actual, expected))
|
|
1211
|
+
throw new AssertionError(
|
|
1212
|
+
message ?? `subObj:
|
|
1213
|
+
${JSONParser.stringify(expected)}
|
|
7
1214
|
is not subset of
|
|
8
|
-
${
|
|
9
|
-
|
|
1215
|
+
${JSONParser.stringify(actual)}`
|
|
1216
|
+
);
|
|
1217
|
+
};
|
|
1218
|
+
var assertDeepEqual = (actual, expected, message) => {
|
|
1219
|
+
if (!deepEquals(actual, expected))
|
|
1220
|
+
throw new AssertionError(
|
|
1221
|
+
message ?? `subObj:
|
|
1222
|
+
${JSONParser.stringify(expected)}
|
|
10
1223
|
is not equal to
|
|
11
|
-
${
|
|
12
|
-
|
|
1224
|
+
${JSONParser.stringify(actual)}`
|
|
1225
|
+
);
|
|
1226
|
+
};
|
|
1227
|
+
var assertNotDeepEqual = (actual, expected, message) => {
|
|
1228
|
+
if (deepEquals(actual, expected))
|
|
1229
|
+
throw new AssertionError(
|
|
1230
|
+
message ?? `subObj:
|
|
1231
|
+
${JSONParser.stringify(expected)}
|
|
13
1232
|
is equals to
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
|
|
1233
|
+
${JSONParser.stringify(actual)}`
|
|
1234
|
+
);
|
|
1235
|
+
};
|
|
1236
|
+
var assertThat = (item) => {
|
|
1237
|
+
return {
|
|
1238
|
+
isEqualTo: (other) => assertTrue(deepEquals(item, other))
|
|
1239
|
+
};
|
|
1240
|
+
};
|
|
1241
|
+
function assertFalse(condition, message) {
|
|
1242
|
+
if (condition) throw new AssertionError(message ?? `Condition is false`);
|
|
1243
|
+
}
|
|
1244
|
+
function assertTrue(condition, message) {
|
|
1245
|
+
if (!condition) throw new AssertionError(message ?? `Condition is false`);
|
|
1246
|
+
}
|
|
1247
|
+
function assertOk(obj, message) {
|
|
1248
|
+
if (!obj) throw new AssertionError(message ?? `Condition is not truthy`);
|
|
1249
|
+
}
|
|
1250
|
+
function assertEqual(expected, actual, message) {
|
|
1251
|
+
if (expected !== actual)
|
|
1252
|
+
throw new AssertionError(
|
|
1253
|
+
`${message ?? "Objects are not equal"}:
|
|
1254
|
+
Expected: ${JSONParser.stringify(expected)}
|
|
1255
|
+
Actual:${JSONParser.stringify(actual)}`
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
function assertNotEqual(obj, other, message) {
|
|
1259
|
+
if (obj === other)
|
|
1260
|
+
throw new AssertionError(
|
|
1261
|
+
message ?? `Objects are equal: ${JSONParser.stringify(obj)}`
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
function assertIsNotNull(result) {
|
|
1265
|
+
assertNotEqual(result, null);
|
|
1266
|
+
assertOk(result);
|
|
1267
|
+
}
|
|
1268
|
+
function assertIsNull(result) {
|
|
1269
|
+
assertEqual(result, null);
|
|
1270
|
+
}
|
|
1271
|
+
var argValue = (value) => (arg) => deepEquals(arg, value);
|
|
1272
|
+
var argMatches = (matches) => (arg) => matches(arg);
|
|
1273
|
+
function verifyThat(fn) {
|
|
1274
|
+
return {
|
|
1275
|
+
calledTimes: (times) => {
|
|
1276
|
+
assertEqual(fn.mock?.calls?.length, times);
|
|
1277
|
+
},
|
|
1278
|
+
notCalled: () => {
|
|
1279
|
+
assertEqual(fn?.mock?.calls?.length, 0);
|
|
1280
|
+
},
|
|
1281
|
+
called: () => {
|
|
1282
|
+
assertTrue(
|
|
1283
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length > 0
|
|
1284
|
+
);
|
|
1285
|
+
},
|
|
1286
|
+
calledWith: (...args) => {
|
|
1287
|
+
assertTrue(
|
|
1288
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1289
|
+
);
|
|
1290
|
+
},
|
|
1291
|
+
calledOnceWith: (...args) => {
|
|
1292
|
+
assertTrue(
|
|
1293
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length === 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1294
|
+
);
|
|
1295
|
+
},
|
|
1296
|
+
calledWithArgumentMatching: (...matches) => {
|
|
1297
|
+
assertTrue(
|
|
1298
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length >= 1
|
|
1299
|
+
);
|
|
1300
|
+
assertTrue(
|
|
1301
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some(
|
|
1302
|
+
(call) => call.arguments && call.arguments.length >= matches.length && matches.every((match, index) => match(call.arguments[index]))
|
|
1303
|
+
)
|
|
1304
|
+
);
|
|
1305
|
+
},
|
|
1306
|
+
notCalledWithArgumentMatching: (...matches) => {
|
|
1307
|
+
assertFalse(
|
|
1308
|
+
fn.mock?.calls.length !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls[0].arguments && fn.mock.calls[0].arguments.length >= matches.length && matches.every(
|
|
1309
|
+
(match, index) => match(fn.mock.calls[0].arguments[index])
|
|
1310
|
+
)
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
var assertThatArray = (array) => {
|
|
1316
|
+
return {
|
|
1317
|
+
isEmpty: () => assertEqual(array.length, 0),
|
|
1318
|
+
isNotEmpty: () => assertNotEqual(array.length, 0),
|
|
1319
|
+
hasSize: (length) => assertEqual(array.length, length),
|
|
1320
|
+
containsElements: (...other) => {
|
|
1321
|
+
assertTrue(other.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
1322
|
+
},
|
|
1323
|
+
containsExactlyInAnyOrder: (...other) => {
|
|
1324
|
+
assertEqual(array.length, other.length);
|
|
1325
|
+
assertTrue(array.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
1326
|
+
},
|
|
1327
|
+
containsExactlyInAnyOrderElementsOf: (other) => {
|
|
1328
|
+
assertEqual(array.length, other.length);
|
|
1329
|
+
assertTrue(array.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
1330
|
+
},
|
|
1331
|
+
containsExactlyElementsOf: (other) => {
|
|
1332
|
+
assertEqual(array.length, other.length);
|
|
1333
|
+
for (let i = 0; i < array.length; i++) {
|
|
1334
|
+
assertTrue(deepEquals(array[i], other[i]));
|
|
1335
|
+
}
|
|
1336
|
+
},
|
|
1337
|
+
containsExactly: (elem) => {
|
|
1338
|
+
assertEqual(array.length, 1);
|
|
1339
|
+
assertTrue(deepEquals(array[0], elem));
|
|
1340
|
+
},
|
|
1341
|
+
contains: (elem) => {
|
|
1342
|
+
assertTrue(array.some((a) => deepEquals(a, elem)));
|
|
1343
|
+
},
|
|
1344
|
+
containsOnlyOnceElementsOf: (other) => {
|
|
1345
|
+
assertTrue(
|
|
1346
|
+
other.map((o) => array.filter((a) => deepEquals(a, o)).length).filter((a) => a === 1).length === other.length
|
|
1347
|
+
);
|
|
1348
|
+
},
|
|
1349
|
+
containsAnyOf: (...other) => {
|
|
1350
|
+
assertTrue(array.some((a) => other.some((o) => deepEquals(a, o))));
|
|
1351
|
+
},
|
|
1352
|
+
allMatch: (matches) => {
|
|
1353
|
+
assertTrue(array.every(matches));
|
|
1354
|
+
},
|
|
1355
|
+
anyMatches: (matches) => {
|
|
1356
|
+
assertTrue(array.some(matches));
|
|
1357
|
+
},
|
|
1358
|
+
allMatchAsync: async (matches) => {
|
|
1359
|
+
for (const item of array) {
|
|
1360
|
+
assertTrue(await matches(item));
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
// src/testing/deciderSpecification.ts
|
|
1367
|
+
var DeciderSpecification = {
|
|
1368
|
+
for: (decider) => {
|
|
1369
|
+
{
|
|
1370
|
+
return (givenEvents) => {
|
|
1371
|
+
return {
|
|
1372
|
+
when: (command2) => {
|
|
1373
|
+
const handle = () => {
|
|
1374
|
+
const existingEvents = Array.isArray(givenEvents) ? givenEvents : [givenEvents];
|
|
1375
|
+
const currentState = existingEvents.reduce(
|
|
1376
|
+
decider.evolve,
|
|
1377
|
+
decider.initialState()
|
|
1378
|
+
);
|
|
1379
|
+
return decider.decide(command2, currentState);
|
|
1380
|
+
};
|
|
1381
|
+
return {
|
|
1382
|
+
then: (expectedEvents) => {
|
|
1383
|
+
const resultEvents = handle();
|
|
1384
|
+
const resultEventsArray = Array.isArray(resultEvents) ? resultEvents : [resultEvents];
|
|
1385
|
+
const expectedEventsArray = Array.isArray(expectedEvents) ? expectedEvents : [expectedEvents];
|
|
1386
|
+
assertMatches(resultEventsArray, expectedEventsArray);
|
|
1387
|
+
},
|
|
1388
|
+
thenThrows: (...args) => {
|
|
1389
|
+
try {
|
|
1390
|
+
handle();
|
|
1391
|
+
throw new AssertionError("Handler did not fail as expected");
|
|
1392
|
+
} catch (error2) {
|
|
1393
|
+
if (error2 instanceof AssertionError) throw error2;
|
|
1394
|
+
if (args.length === 0) return;
|
|
1395
|
+
if (!isErrorConstructor(args[0])) {
|
|
1396
|
+
assertTrue(
|
|
1397
|
+
args[0](error2),
|
|
1398
|
+
`Error didn't match the error condition: ${error2?.toString()}`
|
|
1399
|
+
);
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
assertTrue(
|
|
1403
|
+
error2 instanceof args[0],
|
|
1404
|
+
`Caught error is not an instance of the expected type: ${error2?.toString()}`
|
|
1405
|
+
);
|
|
1406
|
+
if (args[1]) {
|
|
1407
|
+
assertTrue(
|
|
1408
|
+
args[1](error2),
|
|
1409
|
+
`Error didn't match the error condition: ${error2?.toString()}`
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
// src/testing/wrapEventStore.ts
|
|
1423
|
+
var WrapEventStore = (eventStore) => {
|
|
1424
|
+
const appendedEvents = /* @__PURE__ */ new Map();
|
|
1425
|
+
return {
|
|
1426
|
+
async aggregateStream(streamName, options) {
|
|
1427
|
+
return eventStore.aggregateStream(streamName, options);
|
|
1428
|
+
},
|
|
1429
|
+
readStream(streamName, options) {
|
|
1430
|
+
return eventStore.readStream(streamName, options);
|
|
1431
|
+
},
|
|
1432
|
+
appendToStream: async (streamName, events, options) => {
|
|
1433
|
+
const result = await eventStore.appendToStream(
|
|
1434
|
+
streamName,
|
|
1435
|
+
events,
|
|
1436
|
+
options
|
|
1437
|
+
);
|
|
1438
|
+
const currentStream = appendedEvents.get(streamName) ?? [streamName, []];
|
|
1439
|
+
appendedEvents.set(streamName, [
|
|
1440
|
+
streamName,
|
|
1441
|
+
[...currentStream[1], ...events]
|
|
1442
|
+
]);
|
|
1443
|
+
return result;
|
|
1444
|
+
},
|
|
1445
|
+
appendedEvents,
|
|
1446
|
+
setup: async (streamName, events) => {
|
|
1447
|
+
return eventStore.appendToStream(streamName, events);
|
|
1448
|
+
}
|
|
1449
|
+
// streamEvents: (): ReadableStream<
|
|
1450
|
+
// // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
1451
|
+
// ReadEvent<Event, ReadEventMetadataType> | GlobalSubscriptionEvent
|
|
1452
|
+
// > => {
|
|
1453
|
+
// return eventStore.streamEvents();
|
|
1454
|
+
// },
|
|
1455
|
+
};
|
|
1456
|
+
};
|
|
1457
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1458
|
+
0 && (module.exports = {
|
|
1459
|
+
AssertionError,
|
|
1460
|
+
BinaryJsonDecoder,
|
|
1461
|
+
CaughtUpTransformStream,
|
|
1462
|
+
CommandHandler,
|
|
1463
|
+
CommandHandlerStreamVersionConflictRetryOptions,
|
|
1464
|
+
CompositeDecoder,
|
|
1465
|
+
ConcurrencyError,
|
|
1466
|
+
DeciderCommandHandler,
|
|
1467
|
+
DeciderSpecification,
|
|
1468
|
+
DefaultDecoder,
|
|
1469
|
+
EmmettError,
|
|
1470
|
+
ExpectedVersionConflictError,
|
|
1471
|
+
GlobalStreamCaughtUpType,
|
|
1472
|
+
IllegalStateError,
|
|
1473
|
+
InMemoryEventStoreDefaultStreamVersion,
|
|
1474
|
+
JSONParser,
|
|
1475
|
+
JsonDecoder,
|
|
1476
|
+
NO_CONCURRENCY_CHECK,
|
|
1477
|
+
NoRetries,
|
|
1478
|
+
NotFoundError,
|
|
1479
|
+
ObjectDecoder,
|
|
1480
|
+
ParseError,
|
|
1481
|
+
STREAM_DOES_NOT_EXIST,
|
|
1482
|
+
STREAM_EXISTS,
|
|
1483
|
+
StreamingCoordinator,
|
|
1484
|
+
StringDecoder,
|
|
1485
|
+
ValidationError,
|
|
1486
|
+
ValidationErrors,
|
|
1487
|
+
WrapEventStore,
|
|
1488
|
+
accept,
|
|
1489
|
+
argMatches,
|
|
1490
|
+
argValue,
|
|
1491
|
+
assertDeepEqual,
|
|
1492
|
+
assertEqual,
|
|
1493
|
+
assertExpectedVersionMatchesCurrent,
|
|
1494
|
+
assertFails,
|
|
1495
|
+
assertFalse,
|
|
1496
|
+
assertIsNotNull,
|
|
1497
|
+
assertIsNull,
|
|
1498
|
+
assertMatches,
|
|
1499
|
+
assertNotDeepEqual,
|
|
1500
|
+
assertNotEmptyString,
|
|
1501
|
+
assertNotEqual,
|
|
1502
|
+
assertOk,
|
|
1503
|
+
assertPositiveNumber,
|
|
1504
|
+
assertRejects,
|
|
1505
|
+
assertThat,
|
|
1506
|
+
assertThatArray,
|
|
1507
|
+
assertThrows,
|
|
1508
|
+
assertThrowsAsync,
|
|
1509
|
+
assertTrue,
|
|
1510
|
+
assertUnsignedBigInt,
|
|
1511
|
+
asyncProjections,
|
|
1512
|
+
asyncRetry,
|
|
1513
|
+
canCreateEventStoreSession,
|
|
1514
|
+
caughtUpEventFrom,
|
|
1515
|
+
collect,
|
|
1516
|
+
command,
|
|
1517
|
+
complete,
|
|
1518
|
+
concatUint8Arrays,
|
|
1519
|
+
deepEquals,
|
|
1520
|
+
error,
|
|
1521
|
+
event,
|
|
1522
|
+
formatDateToUtcYYYYMMDD,
|
|
1523
|
+
getInMemoryEventStore,
|
|
1524
|
+
getInMemoryMessageBus,
|
|
1525
|
+
globalStreamCaughtUp,
|
|
1526
|
+
ignore,
|
|
1527
|
+
inlineProjections,
|
|
1528
|
+
isEquatable,
|
|
1529
|
+
isErrorConstructor,
|
|
1530
|
+
isExpectedVersionConflictError,
|
|
1531
|
+
isGlobalStreamCaughtUp,
|
|
1532
|
+
isNotInternalEvent,
|
|
1533
|
+
isNumber,
|
|
1534
|
+
isPluginConfig,
|
|
1535
|
+
isString,
|
|
1536
|
+
isSubscriptionEvent,
|
|
1537
|
+
isSubset,
|
|
1538
|
+
isValidYYYYMMDD,
|
|
1539
|
+
matchesExpectedVersion,
|
|
1540
|
+
merge,
|
|
1541
|
+
nulloSessionFactory,
|
|
1542
|
+
parseDateFromUtcYYYYMMDD,
|
|
1543
|
+
projection,
|
|
1544
|
+
projections,
|
|
1545
|
+
publish,
|
|
1546
|
+
reply,
|
|
1547
|
+
restream,
|
|
1548
|
+
schedule,
|
|
1549
|
+
send,
|
|
1550
|
+
streamGenerators,
|
|
1551
|
+
streamTrackingGlobalPosition,
|
|
1552
|
+
streamTransformations,
|
|
1553
|
+
sum,
|
|
1554
|
+
verifyThat
|
|
1555
|
+
});
|
|
17
1556
|
//# sourceMappingURL=index.cjs.map
|