@event-driven-io/emmett 0.23.0-alpha.5 → 0.23.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +258 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -44
- package/dist/index.d.ts +138 -44
- package/dist/index.js +209 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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;
|
|
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 _class7;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -17,18 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
var _chunkFNITWKARcjs = require('./chunk-FNITWKAR.cjs');
|
|
19
19
|
|
|
20
|
-
// src/eventStore/eventStore.ts
|
|
21
|
-
var canCreateEventStoreSession = (eventStore) => "withSession" in eventStore;
|
|
22
|
-
var nulloSessionFactory = (eventStore) => ({
|
|
23
|
-
withSession: (callback) => {
|
|
24
|
-
const nulloSession = {
|
|
25
|
-
eventStore,
|
|
26
|
-
close: () => Promise.resolve()
|
|
27
|
-
};
|
|
28
|
-
return callback(nulloSession);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
20
|
// src/typing/command.ts
|
|
33
21
|
var command = (type, data, metadata) => {
|
|
34
22
|
return {
|
|
@@ -94,16 +82,47 @@ var accept = () => {
|
|
|
94
82
|
return { kind: "Accept" };
|
|
95
83
|
};
|
|
96
84
|
|
|
85
|
+
// src/eventStore/afterCommit/afterEventStoreCommitHandler.ts
|
|
86
|
+
async function tryPublishMessagesAfterCommit(messages, options, context) {
|
|
87
|
+
if (_optionalChain([options, 'optionalAccess', _2 => _2.onAfterCommit]) === void 0) return false;
|
|
88
|
+
try {
|
|
89
|
+
await _optionalChain([options, 'optionalAccess', _3 => _3.onAfterCommit, 'call', _4 => _4(messages, context)]);
|
|
90
|
+
return true;
|
|
91
|
+
} catch (error2) {
|
|
92
|
+
console.error(`Error in on after commit hook`, error2);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/eventStore/afterCommit/forwardToMessageBus.ts
|
|
98
|
+
var forwardToMessageBus = (eventPublisher) => async (messages) => {
|
|
99
|
+
for (const message of messages) {
|
|
100
|
+
await eventPublisher.publish(message);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
97
104
|
// src/eventStore/events/index.ts
|
|
98
105
|
var GlobalStreamCaughtUpType = "__emt:GlobalStreamCaughtUp";
|
|
99
106
|
var isGlobalStreamCaughtUp = (event2) => event2.type === GlobalStreamCaughtUpType;
|
|
100
|
-
var caughtUpEventFrom = (position) => (event2) => event2.type === GlobalStreamCaughtUpType && _optionalChain([event2, 'access',
|
|
107
|
+
var caughtUpEventFrom = (position) => (event2) => event2.type === GlobalStreamCaughtUpType && _optionalChain([event2, 'access', _5 => _5.metadata, 'optionalAccess', _6 => _6.globalPosition]) >= position;
|
|
101
108
|
var globalStreamCaughtUp = (data) => event(GlobalStreamCaughtUpType, data, {
|
|
102
109
|
globalPosition: data.globalPosition
|
|
103
110
|
});
|
|
104
111
|
var isSubscriptionEvent = (event2) => isGlobalStreamCaughtUp(event2);
|
|
105
112
|
var isNotInternalEvent = (event2) => !isGlobalStreamCaughtUp(event2);
|
|
106
113
|
|
|
114
|
+
// src/eventStore/eventStore.ts
|
|
115
|
+
var canCreateEventStoreSession = (eventStore) => "withSession" in eventStore;
|
|
116
|
+
var nulloSessionFactory = (eventStore) => ({
|
|
117
|
+
withSession: (callback) => {
|
|
118
|
+
const nulloSession = {
|
|
119
|
+
eventStore,
|
|
120
|
+
close: () => Promise.resolve()
|
|
121
|
+
};
|
|
122
|
+
return callback(nulloSession);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
107
126
|
// src/eventStore/expectedVersion.ts
|
|
108
127
|
var STREAM_EXISTS = "STREAM_EXISTS";
|
|
109
128
|
var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
|
|
@@ -121,7 +140,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
121
140
|
};
|
|
122
141
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends _chunkFNITWKARcjs.ConcurrencyError {
|
|
123
142
|
constructor(current, expected) {
|
|
124
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
143
|
+
super(_optionalChain([current, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()]), _optionalChain([expected, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]));
|
|
125
144
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
126
145
|
}
|
|
127
146
|
};
|
|
@@ -178,9 +197,9 @@ var NotifyAboutNoActiveReadersStream = (_class = class extends _webstreamspolyfi
|
|
|
178
197
|
}
|
|
179
198
|
});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
|
|
180
199
|
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
181
|
-
this.streamId = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
200
|
+
this.streamId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.streamId]), () => ( _uuid.v4.call(void 0, )));
|
|
182
201
|
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
183
|
-
this.startChecking(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
202
|
+
this.startChecking(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _12 => _12.intervalCheckInMs]), () => ( 20)));
|
|
184
203
|
}
|
|
185
204
|
__init() {this.checkInterval = null}
|
|
186
205
|
|
|
@@ -257,7 +276,7 @@ var StreamingCoordinator = () => {
|
|
|
257
276
|
|
|
258
277
|
// src/eventStore/inMemoryEventStore.ts
|
|
259
278
|
var InMemoryEventStoreDefaultStreamVersion = 0n;
|
|
260
|
-
var getInMemoryEventStore = () => {
|
|
279
|
+
var getInMemoryEventStore = (eventStoreOptions) => {
|
|
261
280
|
const streams = /* @__PURE__ */ new Map();
|
|
262
281
|
const streamingCoordinator = StreamingCoordinator();
|
|
263
282
|
const getAllEventsCount = () => {
|
|
@@ -267,7 +286,7 @@ var getInMemoryEventStore = () => {
|
|
|
267
286
|
async aggregateStream(streamName, options) {
|
|
268
287
|
const { evolve, initialState, read } = options;
|
|
269
288
|
const result = await this.readStream(streamName, read);
|
|
270
|
-
const events = _nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
289
|
+
const events = _nullishCoalesce(_optionalChain([result, 'optionalAccess', _13 => _13.events]), () => ( []));
|
|
271
290
|
return {
|
|
272
291
|
currentStreamVersion: BigInt(events.length),
|
|
273
292
|
state: events.reduce(evolve, initialState()),
|
|
@@ -279,12 +298,12 @@ var getInMemoryEventStore = () => {
|
|
|
279
298
|
const currentStreamVersion = events ? BigInt(events.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
280
299
|
assertExpectedVersionMatchesCurrent(
|
|
281
300
|
currentStreamVersion,
|
|
282
|
-
_optionalChain([options, 'optionalAccess',
|
|
301
|
+
_optionalChain([options, 'optionalAccess', _14 => _14.expectedStreamVersion]),
|
|
283
302
|
InMemoryEventStoreDefaultStreamVersion
|
|
284
303
|
);
|
|
285
304
|
const from = Number(options && "from" in options ? options.from : 0);
|
|
286
305
|
const to = Number(
|
|
287
|
-
options && "to" in options ? options.to : options && "maxCount" in options && options.maxCount ? options.from + options.maxCount : _nullishCoalesce(_optionalChain([events, 'optionalAccess',
|
|
306
|
+
options && "to" in options ? options.to : options && "maxCount" in options && options.maxCount ? options.from + options.maxCount : _nullishCoalesce(_optionalChain([events, 'optionalAccess', _15 => _15.length]), () => ( 1))
|
|
288
307
|
);
|
|
289
308
|
const resultEvents = events !== void 0 && events.length > 0 ? events.map(
|
|
290
309
|
(e) => e
|
|
@@ -301,7 +320,7 @@ var getInMemoryEventStore = () => {
|
|
|
301
320
|
const currentStreamVersion = currentEvents.length > 0 ? BigInt(currentEvents.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
302
321
|
assertExpectedVersionMatchesCurrent(
|
|
303
322
|
currentStreamVersion,
|
|
304
|
-
_optionalChain([options, 'optionalAccess',
|
|
323
|
+
_optionalChain([options, 'optionalAccess', _16 => _16.expectedStreamVersion]),
|
|
305
324
|
InMemoryEventStoreDefaultStreamVersion
|
|
306
325
|
);
|
|
307
326
|
const newEvents = events.map((event2, index) => {
|
|
@@ -325,6 +344,7 @@ var getInMemoryEventStore = () => {
|
|
|
325
344
|
nextExpectedStreamVersion: positionOfLastEventInTheStream,
|
|
326
345
|
createdNewStream: currentStreamVersion === InMemoryEventStoreDefaultStreamVersion
|
|
327
346
|
};
|
|
347
|
+
await tryPublishMessagesAfterCommit(newEvents, _optionalChain([eventStoreOptions, 'optionalAccess', _17 => _17.hooks]));
|
|
328
348
|
return result;
|
|
329
349
|
}
|
|
330
350
|
//streamEvents: streamingCoordinator.stream,
|
|
@@ -371,6 +391,178 @@ var sum = (iterator) => {
|
|
|
371
391
|
return sum2;
|
|
372
392
|
};
|
|
373
393
|
|
|
394
|
+
// src/taskProcessing/taskProcessor.ts
|
|
395
|
+
var TaskProcessor = (_class2 = class {
|
|
396
|
+
constructor(options) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);
|
|
397
|
+
this.options = options;
|
|
398
|
+
}
|
|
399
|
+
__init3() {this.queue = []}
|
|
400
|
+
__init4() {this.isProcessing = false}
|
|
401
|
+
__init5() {this.activeTasks = 0}
|
|
402
|
+
__init6() {this.activeGroups = /* @__PURE__ */ new Set()}
|
|
403
|
+
enqueue(task, options) {
|
|
404
|
+
if (this.queue.length >= this.options.maxQueueSize) {
|
|
405
|
+
return Promise.reject(
|
|
406
|
+
new (0, _chunkFNITWKARcjs.EmmettError)(
|
|
407
|
+
"Too many pending connections. Please try again later."
|
|
408
|
+
)
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
return this.schedule(task, options);
|
|
412
|
+
}
|
|
413
|
+
waitForEndOfProcessing() {
|
|
414
|
+
return this.schedule(({ ack }) => Promise.resolve(ack()));
|
|
415
|
+
}
|
|
416
|
+
schedule(task, options) {
|
|
417
|
+
return promiseWithDeadline(
|
|
418
|
+
(resolve, reject) => {
|
|
419
|
+
const taskWithContext = () => {
|
|
420
|
+
return new Promise((resolveTask, failTask) => {
|
|
421
|
+
const taskPromise = task({
|
|
422
|
+
ack: resolveTask
|
|
423
|
+
});
|
|
424
|
+
taskPromise.then(resolve).catch((err) => {
|
|
425
|
+
failTask(err);
|
|
426
|
+
reject(err);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
this.queue.push({ task: taskWithContext, options });
|
|
431
|
+
if (!this.isProcessing) {
|
|
432
|
+
this.ensureProcessing();
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{ deadline: this.options.maxTaskIdleTime }
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
ensureProcessing() {
|
|
439
|
+
if (this.isProcessing) return;
|
|
440
|
+
this.isProcessing = true;
|
|
441
|
+
this.processQueue();
|
|
442
|
+
}
|
|
443
|
+
processQueue() {
|
|
444
|
+
try {
|
|
445
|
+
while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
|
|
446
|
+
const item = this.takeFirstAvailableItem();
|
|
447
|
+
if (item === null) return;
|
|
448
|
+
const groupId = _optionalChain([item, 'access', _22 => _22.options, 'optionalAccess', _23 => _23.taskGroupId]);
|
|
449
|
+
if (groupId) {
|
|
450
|
+
this.activeGroups.add(groupId);
|
|
451
|
+
}
|
|
452
|
+
this.activeTasks++;
|
|
453
|
+
void this.executeItem(item);
|
|
454
|
+
}
|
|
455
|
+
} catch (error2) {
|
|
456
|
+
console.error(error2);
|
|
457
|
+
throw error2;
|
|
458
|
+
} finally {
|
|
459
|
+
this.isProcessing = false;
|
|
460
|
+
if (this.hasItemsToProcess() && this.activeTasks < this.options.maxActiveTasks) {
|
|
461
|
+
this.ensureProcessing();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async executeItem({ task, options }) {
|
|
466
|
+
try {
|
|
467
|
+
await task();
|
|
468
|
+
} finally {
|
|
469
|
+
this.activeTasks--;
|
|
470
|
+
if (options && options.taskGroupId) {
|
|
471
|
+
this.activeGroups.delete(options.taskGroupId);
|
|
472
|
+
}
|
|
473
|
+
this.ensureProcessing();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
__init7() {this.takeFirstAvailableItem = () => {
|
|
477
|
+
const taskIndex = this.queue.findIndex(
|
|
478
|
+
(item2) => !_optionalChain([item2, 'access', _24 => _24.options, 'optionalAccess', _25 => _25.taskGroupId]) || !this.activeGroups.has(item2.options.taskGroupId)
|
|
479
|
+
);
|
|
480
|
+
if (taskIndex === -1) {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
const [item] = this.queue.splice(taskIndex, 1);
|
|
484
|
+
return _nullishCoalesce(item, () => ( null));
|
|
485
|
+
}}
|
|
486
|
+
__init8() {this.hasItemsToProcess = () => this.queue.findIndex(
|
|
487
|
+
(item) => !_optionalChain([item, 'access', _26 => _26.options, 'optionalAccess', _27 => _27.taskGroupId]) || !this.activeGroups.has(item.options.taskGroupId)
|
|
488
|
+
) !== -1}
|
|
489
|
+
}, _class2);
|
|
490
|
+
var DEFAULT_PROMISE_DEADLINE = 2147483647;
|
|
491
|
+
var promiseWithDeadline = (executor, options) => {
|
|
492
|
+
return new Promise((resolve, reject) => {
|
|
493
|
+
let taskStarted = false;
|
|
494
|
+
const maxWaitingTime = options.deadline || DEFAULT_PROMISE_DEADLINE;
|
|
495
|
+
let timeoutId = setTimeout(() => {
|
|
496
|
+
if (!taskStarted) {
|
|
497
|
+
reject(
|
|
498
|
+
new Error("Task was not started within the maximum waiting time")
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
}, maxWaitingTime);
|
|
502
|
+
executor((value) => {
|
|
503
|
+
taskStarted = true;
|
|
504
|
+
if (timeoutId) {
|
|
505
|
+
clearTimeout(timeoutId);
|
|
506
|
+
}
|
|
507
|
+
timeoutId = null;
|
|
508
|
+
resolve(value);
|
|
509
|
+
}, reject);
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
// src/utils/locking/index.ts
|
|
514
|
+
var InProcessLock = () => {
|
|
515
|
+
const taskProcessor = new TaskProcessor({
|
|
516
|
+
maxActiveTasks: Number.MAX_VALUE,
|
|
517
|
+
maxQueueSize: Number.MAX_VALUE
|
|
518
|
+
});
|
|
519
|
+
const locks = /* @__PURE__ */ new Map();
|
|
520
|
+
return {
|
|
521
|
+
async acquire({ lockId }) {
|
|
522
|
+
await new Promise((resolve, reject) => {
|
|
523
|
+
taskProcessor.enqueue(
|
|
524
|
+
({ ack }) => {
|
|
525
|
+
locks.set(lockId, ack);
|
|
526
|
+
resolve();
|
|
527
|
+
return Promise.resolve();
|
|
528
|
+
},
|
|
529
|
+
{ taskGroupId: lockId }
|
|
530
|
+
).catch(reject);
|
|
531
|
+
});
|
|
532
|
+
},
|
|
533
|
+
async tryAcquire({ lockId }) {
|
|
534
|
+
if (locks.has(lockId)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
await this.acquire({ lockId });
|
|
538
|
+
return true;
|
|
539
|
+
},
|
|
540
|
+
release({ lockId }) {
|
|
541
|
+
const ack = locks.get(lockId);
|
|
542
|
+
if (ack === void 0) {
|
|
543
|
+
return Promise.resolve(true);
|
|
544
|
+
}
|
|
545
|
+
locks.delete(lockId);
|
|
546
|
+
ack();
|
|
547
|
+
return Promise.resolve(true);
|
|
548
|
+
},
|
|
549
|
+
async withAcquire(handle, { lockId }) {
|
|
550
|
+
return taskProcessor.enqueue(
|
|
551
|
+
async ({ ack }) => {
|
|
552
|
+
locks.set(lockId, ack);
|
|
553
|
+
try {
|
|
554
|
+
return await handle();
|
|
555
|
+
} finally {
|
|
556
|
+
locks.delete(lockId);
|
|
557
|
+
ack();
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
{ taskGroupId: lockId }
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
374
566
|
// src/utils/merge.ts
|
|
375
567
|
var merge = (array, item, where, onExisting, onNotFound = () => void 0) => {
|
|
376
568
|
let wasFound = false;
|
|
@@ -399,7 +591,7 @@ var asyncRetry = async (fn, opts) => {
|
|
|
399
591
|
try {
|
|
400
592
|
return await fn();
|
|
401
593
|
} catch (error2) {
|
|
402
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
594
|
+
if (_optionalChain([opts, 'optionalAccess', _28 => _28.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
403
595
|
bail(error2);
|
|
404
596
|
}
|
|
405
597
|
throw error2;
|
|
@@ -443,7 +635,7 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
|
|
|
443
635
|
// expected stream version is passed to fail fast
|
|
444
636
|
// if stream is in the wrong state
|
|
445
637
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
446
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
638
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _29 => _29.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
447
639
|
}
|
|
448
640
|
});
|
|
449
641
|
const {
|
|
@@ -465,7 +657,7 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
|
|
|
465
657
|
createdNewStream: false
|
|
466
658
|
};
|
|
467
659
|
}
|
|
468
|
-
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
660
|
+
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _30 => _30.expectedStreamVersion]), () => ( (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST)));
|
|
469
661
|
const appendResult = await eventStore.appendToStream(
|
|
470
662
|
streamName,
|
|
471
663
|
newEvents,
|
|
@@ -573,17 +765,17 @@ var ParseError = class extends Error {
|
|
|
573
765
|
var JSONParser = {
|
|
574
766
|
stringify: (value, options) => {
|
|
575
767
|
return JSON.stringify(
|
|
576
|
-
_optionalChain([options, 'optionalAccess',
|
|
768
|
+
_optionalChain([options, 'optionalAccess', _31 => _31.map]) ? options.map(value) : value,
|
|
577
769
|
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
578
770
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
579
771
|
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
580
772
|
);
|
|
581
773
|
},
|
|
582
774
|
parse: (text, options) => {
|
|
583
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess',
|
|
584
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
775
|
+
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _32 => _32.reviver]));
|
|
776
|
+
if (_optionalChain([options, 'optionalAccess', _33 => _33.typeCheck]) && !_optionalChain([options, 'optionalAccess', _34 => _34.typeCheck, 'call', _35 => _35(parsed)]))
|
|
585
777
|
throw new ParseError(text);
|
|
586
|
-
return _optionalChain([options, 'optionalAccess',
|
|
778
|
+
return _optionalChain([options, 'optionalAccess', _36 => _36.map]) ? options.map(parsed) : parsed;
|
|
587
779
|
}
|
|
588
780
|
};
|
|
589
781
|
|
|
@@ -609,8 +801,8 @@ var collect = async (stream) => {
|
|
|
609
801
|
};
|
|
610
802
|
|
|
611
803
|
// src/streaming/decoders/binary.ts
|
|
612
|
-
var BinaryJsonDecoder = (
|
|
613
|
-
|
|
804
|
+
var BinaryJsonDecoder = (_class3 = class {constructor() { _class3.prototype.__init9.call(this); }
|
|
805
|
+
__init9() {this.buffer = []}
|
|
614
806
|
addToBuffer(data) {
|
|
615
807
|
this.buffer.push(data);
|
|
616
808
|
}
|
|
@@ -637,15 +829,15 @@ var BinaryJsonDecoder = (_class2 = class {constructor() { _class2.prototype.__in
|
|
|
637
829
|
this.buffer = remaining.byteLength > 0 ? [remaining] : [];
|
|
638
830
|
return JSON.parse(jsonString);
|
|
639
831
|
}
|
|
640
|
-
},
|
|
832
|
+
}, _class3);
|
|
641
833
|
|
|
642
834
|
// src/streaming/decoders/string.ts
|
|
643
|
-
var StringDecoder = (
|
|
644
|
-
constructor(transform) {;
|
|
835
|
+
var StringDecoder = (_class4 = class {
|
|
836
|
+
constructor(transform) {;_class4.prototype.__init10.call(this);
|
|
645
837
|
this.transform = transform;
|
|
646
838
|
this.transform = transform;
|
|
647
839
|
}
|
|
648
|
-
|
|
840
|
+
__init10() {this.buffer = []}
|
|
649
841
|
addToBuffer(data) {
|
|
650
842
|
this.buffer.push(data);
|
|
651
843
|
}
|
|
@@ -668,7 +860,7 @@ var StringDecoder = (_class3 = class {
|
|
|
668
860
|
this.buffer = [completeString.slice(delimiterIndex + 1)];
|
|
669
861
|
return this.transform(message);
|
|
670
862
|
}
|
|
671
|
-
},
|
|
863
|
+
}, _class4);
|
|
672
864
|
|
|
673
865
|
// src/streaming/decoders/json.ts
|
|
674
866
|
var JsonDecoder = class extends StringDecoder {
|
|
@@ -678,8 +870,8 @@ var JsonDecoder = class extends StringDecoder {
|
|
|
678
870
|
};
|
|
679
871
|
|
|
680
872
|
// src/streaming/decoders/object.ts
|
|
681
|
-
var ObjectDecoder = (
|
|
682
|
-
|
|
873
|
+
var ObjectDecoder = (_class5 = class {constructor() { _class5.prototype.__init11.call(this); }
|
|
874
|
+
__init11() {this.buffer = null}
|
|
683
875
|
addToBuffer(data) {
|
|
684
876
|
this.buffer = data;
|
|
685
877
|
}
|
|
@@ -697,7 +889,7 @@ var ObjectDecoder = (_class4 = class {constructor() { _class4.prototype.__init5.
|
|
|
697
889
|
this.clearBuffer();
|
|
698
890
|
return data;
|
|
699
891
|
}
|
|
700
|
-
},
|
|
892
|
+
}, _class5);
|
|
701
893
|
|
|
702
894
|
// src/streaming/decoders/composite.ts
|
|
703
895
|
var CompositeDecoder = class {
|
|
@@ -710,7 +902,7 @@ var CompositeDecoder = class {
|
|
|
710
902
|
return decoder[1];
|
|
711
903
|
}
|
|
712
904
|
addToBuffer(data) {
|
|
713
|
-
_optionalChain([this, 'access',
|
|
905
|
+
_optionalChain([this, 'access', _37 => _37.decoderFor, 'call', _38 => _38(data), 'optionalAccess', _39 => _39.addToBuffer, 'call', _40 => _40(data)]);
|
|
714
906
|
}
|
|
715
907
|
clearBuffer() {
|
|
716
908
|
for (const decoder of this.decoders.map((d) => d[1])) {
|
|
@@ -722,7 +914,7 @@ var CompositeDecoder = class {
|
|
|
722
914
|
}
|
|
723
915
|
decode() {
|
|
724
916
|
const decoder = this.decoders.map((d) => d[1]).find((d) => d.hasCompleteMessage());
|
|
725
|
-
return _nullishCoalesce(_optionalChain([decoder, 'optionalAccess',
|
|
917
|
+
return _nullishCoalesce(_optionalChain([decoder, 'optionalAccess', _41 => _41.decode, 'call', _42 => _42()]), () => ( null));
|
|
726
918
|
}
|
|
727
919
|
};
|
|
728
920
|
var DefaultDecoder = class extends CompositeDecoder {
|
|
@@ -824,8 +1016,8 @@ var onRestream = async (createSourceStream, handleChunk2, controller) => {
|
|
|
824
1016
|
// src/streaming/transformations/skip.ts
|
|
825
1017
|
|
|
826
1018
|
var skip = (limit) => new SkipTransformStream(limit);
|
|
827
|
-
var SkipTransformStream = (
|
|
828
|
-
|
|
1019
|
+
var SkipTransformStream = (_class6 = class extends _webstreamspolyfill.TransformStream {
|
|
1020
|
+
__init12() {this.count = 0}
|
|
829
1021
|
|
|
830
1022
|
constructor(skip2) {
|
|
831
1023
|
super({
|
|
@@ -835,10 +1027,10 @@ var SkipTransformStream = (_class5 = class extends _webstreamspolyfill.Transform
|
|
|
835
1027
|
controller.enqueue(chunk);
|
|
836
1028
|
}
|
|
837
1029
|
}
|
|
838
|
-
});
|
|
1030
|
+
});_class6.prototype.__init12.call(this);;
|
|
839
1031
|
this.skip = skip2;
|
|
840
1032
|
}
|
|
841
|
-
},
|
|
1033
|
+
}, _class6);
|
|
842
1034
|
|
|
843
1035
|
// src/streaming/transformations/stopAfter.ts
|
|
844
1036
|
|
|
@@ -867,8 +1059,8 @@ var stopOn = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
|
|
|
867
1059
|
// src/streaming/transformations/take.ts
|
|
868
1060
|
|
|
869
1061
|
var take = (limit) => new TakeTransformStream(limit);
|
|
870
|
-
var TakeTransformStream = (
|
|
871
|
-
|
|
1062
|
+
var TakeTransformStream = (_class7 = class extends _webstreamspolyfill.TransformStream {
|
|
1063
|
+
__init13() {this.count = 0}
|
|
872
1064
|
|
|
873
1065
|
constructor(limit) {
|
|
874
1066
|
super({
|
|
@@ -880,10 +1072,10 @@ var TakeTransformStream = (_class6 = class extends _webstreamspolyfill.Transform
|
|
|
880
1072
|
controller.terminate();
|
|
881
1073
|
}
|
|
882
1074
|
}
|
|
883
|
-
});
|
|
1075
|
+
});_class7.prototype.__init13.call(this);;
|
|
884
1076
|
this.limit = limit;
|
|
885
1077
|
}
|
|
886
|
-
},
|
|
1078
|
+
}, _class7);
|
|
887
1079
|
|
|
888
1080
|
// src/streaming/transformations/waitAtMost.ts
|
|
889
1081
|
|
|
@@ -937,7 +1129,7 @@ var decodeAndTransform = (decoder, transform, controller) => {
|
|
|
937
1129
|
const transformed = transform(decoded);
|
|
938
1130
|
controller.enqueue(transformed);
|
|
939
1131
|
} catch (error2) {
|
|
940
|
-
controller.error(new Error(`Decoding error: ${_optionalChain([error2, 'optionalAccess',
|
|
1132
|
+
controller.error(new Error(`Decoding error: ${_optionalChain([error2, 'optionalAccess', _43 => _43.toString, 'call', _44 => _44()])}`));
|
|
941
1133
|
}
|
|
942
1134
|
};
|
|
943
1135
|
|
|
@@ -1098,39 +1290,39 @@ var argMatches = (matches) => (arg) => matches(arg);
|
|
|
1098
1290
|
function verifyThat(fn) {
|
|
1099
1291
|
return {
|
|
1100
1292
|
calledTimes: (times) => {
|
|
1101
|
-
assertEqual(_optionalChain([fn, 'access',
|
|
1293
|
+
assertEqual(_optionalChain([fn, 'access', _45 => _45.mock, 'optionalAccess', _46 => _46.calls, 'optionalAccess', _47 => _47.length]), times);
|
|
1102
1294
|
},
|
|
1103
1295
|
notCalled: () => {
|
|
1104
|
-
assertEqual(_optionalChain([fn, 'optionalAccess',
|
|
1296
|
+
assertEqual(_optionalChain([fn, 'optionalAccess', _48 => _48.mock, 'optionalAccess', _49 => _49.calls, 'optionalAccess', _50 => _50.length]), 0);
|
|
1105
1297
|
},
|
|
1106
1298
|
called: () => {
|
|
1107
1299
|
assertTrue(
|
|
1108
|
-
_optionalChain([fn, 'access',
|
|
1300
|
+
_optionalChain([fn, 'access', _51 => _51.mock, 'optionalAccess', _52 => _52.calls, 'access', _53 => _53.length]) !== void 0 && fn.mock.calls.length > 0
|
|
1109
1301
|
);
|
|
1110
1302
|
},
|
|
1111
1303
|
calledWith: (...args) => {
|
|
1112
1304
|
assertTrue(
|
|
1113
|
-
_optionalChain([fn, 'access',
|
|
1305
|
+
_optionalChain([fn, 'access', _54 => _54.mock, 'optionalAccess', _55 => _55.calls, 'access', _56 => _56.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1114
1306
|
);
|
|
1115
1307
|
},
|
|
1116
1308
|
calledOnceWith: (...args) => {
|
|
1117
1309
|
assertTrue(
|
|
1118
|
-
_optionalChain([fn, 'access',
|
|
1310
|
+
_optionalChain([fn, 'access', _57 => _57.mock, 'optionalAccess', _58 => _58.calls, 'access', _59 => _59.length]) !== void 0 && fn.mock.calls.length === 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1119
1311
|
);
|
|
1120
1312
|
},
|
|
1121
1313
|
calledWithArgumentMatching: (...matches) => {
|
|
1122
1314
|
assertTrue(
|
|
1123
|
-
_optionalChain([fn, 'access',
|
|
1315
|
+
_optionalChain([fn, 'access', _60 => _60.mock, 'optionalAccess', _61 => _61.calls, 'access', _62 => _62.length]) !== void 0 && fn.mock.calls.length >= 1
|
|
1124
1316
|
);
|
|
1125
1317
|
assertTrue(
|
|
1126
|
-
_optionalChain([fn, 'access',
|
|
1318
|
+
_optionalChain([fn, 'access', _63 => _63.mock, 'optionalAccess', _64 => _64.calls, 'access', _65 => _65.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some(
|
|
1127
1319
|
(call) => call.arguments && call.arguments.length >= matches.length && matches.every((match, index) => match(call.arguments[index]))
|
|
1128
1320
|
)
|
|
1129
1321
|
);
|
|
1130
1322
|
},
|
|
1131
1323
|
notCalledWithArgumentMatching: (...matches) => {
|
|
1132
1324
|
assertFalse(
|
|
1133
|
-
_optionalChain([fn, 'access',
|
|
1325
|
+
_optionalChain([fn, 'access', _66 => _66.mock, 'optionalAccess', _67 => _67.calls, 'access', _68 => _68.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls[0].arguments && fn.mock.calls[0].arguments.length >= matches.length && matches.every(
|
|
1134
1326
|
(match, index) => match(fn.mock.calls[0].arguments[index])
|
|
1135
1327
|
)
|
|
1136
1328
|
);
|
|
@@ -1238,18 +1430,18 @@ var DeciderSpecification = {
|
|
|
1238
1430
|
if (!_chunkFNITWKARcjs.isErrorConstructor.call(void 0, args[0])) {
|
|
1239
1431
|
assertTrue(
|
|
1240
1432
|
args[0](error2),
|
|
1241
|
-
`Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess',
|
|
1433
|
+
`Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess', _69 => _69.toString, 'call', _70 => _70()])}`
|
|
1242
1434
|
);
|
|
1243
1435
|
return;
|
|
1244
1436
|
}
|
|
1245
1437
|
assertTrue(
|
|
1246
1438
|
error2 instanceof args[0],
|
|
1247
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error2, 'optionalAccess',
|
|
1439
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error2, 'optionalAccess', _71 => _71.toString, 'call', _72 => _72()])}`
|
|
1248
1440
|
);
|
|
1249
1441
|
if (args[1]) {
|
|
1250
1442
|
assertTrue(
|
|
1251
1443
|
args[1](error2),
|
|
1252
|
-
`Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess',
|
|
1444
|
+
`Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess', _73 => _73.toString, 'call', _74 => _74()])}`
|
|
1253
1445
|
);
|
|
1254
1446
|
}
|
|
1255
1447
|
}
|
|
@@ -1399,5 +1591,9 @@ var WrapEventStore = (eventStore) => {
|
|
|
1399
1591
|
|
|
1400
1592
|
|
|
1401
1593
|
|
|
1402
|
-
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
exports.AssertionError = AssertionError; exports.BinaryJsonDecoder = BinaryJsonDecoder; exports.CaughtUpTransformStream = CaughtUpTransformStream; exports.CommandHandler = CommandHandler; exports.CommandHandlerStreamVersionConflictRetryOptions = CommandHandlerStreamVersionConflictRetryOptions; exports.CompositeDecoder = CompositeDecoder; exports.ConcurrencyError = _chunkFNITWKARcjs.ConcurrencyError; exports.DeciderCommandHandler = DeciderCommandHandler; exports.DeciderSpecification = DeciderSpecification; exports.DefaultDecoder = DefaultDecoder; exports.EmmettError = _chunkFNITWKARcjs.EmmettError; exports.ExpectedVersionConflictError = ExpectedVersionConflictError; exports.GlobalStreamCaughtUpType = GlobalStreamCaughtUpType; exports.IllegalStateError = _chunkFNITWKARcjs.IllegalStateError; exports.InMemoryEventStoreDefaultStreamVersion = InMemoryEventStoreDefaultStreamVersion; exports.InProcessLock = InProcessLock; exports.JSONParser = JSONParser; exports.JsonDecoder = JsonDecoder; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.NoRetries = NoRetries; exports.NotFoundError = _chunkFNITWKARcjs.NotFoundError; exports.ObjectDecoder = ObjectDecoder; exports.ParseError = ParseError; exports.STREAM_DOES_NOT_EXIST = STREAM_DOES_NOT_EXIST; exports.STREAM_EXISTS = STREAM_EXISTS; exports.StreamingCoordinator = StreamingCoordinator; exports.StringDecoder = StringDecoder; exports.TaskProcessor = TaskProcessor; exports.ValidationError = _chunkFNITWKARcjs.ValidationError; exports.ValidationErrors = _chunkFNITWKARcjs.ValidationErrors; exports.WrapEventStore = WrapEventStore; exports.accept = accept; exports.argMatches = argMatches; exports.argValue = argValue; exports.assertDeepEqual = assertDeepEqual; exports.assertDoesNotThrow = assertDoesNotThrow; exports.assertEqual = assertEqual; exports.assertExpectedVersionMatchesCurrent = assertExpectedVersionMatchesCurrent; exports.assertFails = assertFails; exports.assertFalse = assertFalse; exports.assertIsNotNull = assertIsNotNull; exports.assertIsNull = assertIsNull; exports.assertMatches = assertMatches; exports.assertNotDeepEqual = assertNotDeepEqual; exports.assertNotEmptyString = _chunkFNITWKARcjs.assertNotEmptyString; exports.assertNotEqual = assertNotEqual; exports.assertOk = assertOk; exports.assertPositiveNumber = _chunkFNITWKARcjs.assertPositiveNumber; exports.assertRejects = assertRejects; exports.assertThat = assertThat; exports.assertThatArray = assertThatArray; exports.assertThrows = assertThrows; exports.assertThrowsAsync = assertThrowsAsync; exports.assertTrue = assertTrue; exports.assertUnsignedBigInt = _chunkFNITWKARcjs.assertUnsignedBigInt; exports.asyncProjections = asyncProjections; exports.asyncRetry = asyncRetry; exports.canCreateEventStoreSession = canCreateEventStoreSession; exports.caughtUpEventFrom = caughtUpEventFrom; exports.collect = collect; exports.command = command; exports.complete = complete; exports.concatUint8Arrays = concatUint8Arrays; exports.deepEquals = deepEquals; exports.error = error; exports.event = event; exports.formatDateToUtcYYYYMMDD = _chunkFNITWKARcjs.formatDateToUtcYYYYMMDD; exports.forwardToMessageBus = forwardToMessageBus; exports.getInMemoryEventStore = getInMemoryEventStore; exports.getInMemoryMessageBus = getInMemoryMessageBus; exports.globalStreamCaughtUp = globalStreamCaughtUp; exports.ignore = ignore; exports.inlineProjections = inlineProjections; exports.isEquatable = isEquatable; exports.isErrorConstructor = _chunkFNITWKARcjs.isErrorConstructor; exports.isExpectedVersionConflictError = isExpectedVersionConflictError; exports.isGlobalStreamCaughtUp = isGlobalStreamCaughtUp; exports.isNotInternalEvent = isNotInternalEvent; exports.isNumber = _chunkFNITWKARcjs.isNumber; exports.isPluginConfig = _chunkFNITWKARcjs.isPluginConfig; exports.isString = _chunkFNITWKARcjs.isString; exports.isSubscriptionEvent = isSubscriptionEvent; exports.isSubset = isSubset; exports.isValidYYYYMMDD = _chunkFNITWKARcjs.isValidYYYYMMDD; exports.matchesExpectedVersion = matchesExpectedVersion; exports.merge = merge; exports.nulloSessionFactory = nulloSessionFactory; exports.parseDateFromUtcYYYYMMDD = _chunkFNITWKARcjs.parseDateFromUtcYYYYMMDD; exports.projection = projection; exports.projections = projections; exports.publish = publish; exports.reply = reply; exports.restream = restream; exports.schedule = schedule; exports.send = send; exports.streamGenerators = streamGenerators; exports.streamTrackingGlobalPosition = streamTrackingGlobalPosition; exports.streamTransformations = streamTransformations; exports.sum = sum; exports.tryPublishMessagesAfterCommit = tryPublishMessagesAfterCommit; exports.verifyThat = verifyThat;
|
|
1403
1599
|
//# sourceMappingURL=index.cjs.map
|