@event-driven-io/emmett-postgresql 0.20.2-alpha.4 → 0.20.2-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/index.cjs +401 -232
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1201 -62
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -3,24 +3,32 @@
|
|
|
3
3
|
|
|
4
4
|
var _dumbo = require('@event-driven-io/dumbo');
|
|
5
5
|
|
|
6
|
-
// ../emmett/dist/chunk-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// ../emmett/dist/chunk-AEEEXE2R.js
|
|
7
|
+
var isNumber = (val) => typeof val === "number" && val === val;
|
|
8
|
+
var isString = (val) => typeof val === "string";
|
|
9
|
+
var isErrorConstructor = (expect) => {
|
|
10
|
+
return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
11
|
+
expect.prototype.constructor === expect;
|
|
12
|
+
};
|
|
13
|
+
var EmmettError = class _EmmettError extends Error {
|
|
12
14
|
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
constructor(options) {
|
|
16
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
|
|
17
|
+
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
18
|
+
super(message);
|
|
19
|
+
this.errorCode = errorCode;
|
|
20
|
+
Object.setPrototypeOf(this, _EmmettError.prototype);
|
|
16
21
|
}
|
|
17
22
|
};
|
|
18
|
-
var
|
|
19
|
-
constructor(
|
|
20
|
-
super({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
24
|
+
constructor(current, expected, message) {
|
|
25
|
+
super({
|
|
26
|
+
errorCode: 412,
|
|
27
|
+
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()])}`))
|
|
28
|
+
});
|
|
29
|
+
this.current = current;
|
|
30
|
+
this.expected = expected;
|
|
31
|
+
Object.setPrototypeOf(this, _ConcurrencyError.prototype);
|
|
24
32
|
}
|
|
25
33
|
};
|
|
26
34
|
|
|
@@ -42,27 +50,48 @@ var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefa
|
|
|
42
50
|
|
|
43
51
|
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
var event = (type, data, metadata) => {
|
|
56
|
+
return {
|
|
57
|
+
type,
|
|
58
|
+
data,
|
|
59
|
+
metadata
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var STREAM_EXISTS = "STREAM_EXISTS";
|
|
63
|
+
var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
|
|
64
|
+
var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
|
|
65
|
+
var matchesExpectedVersion = (current, expected, defaultVersion) => {
|
|
66
|
+
if (expected === NO_CONCURRENCY_CHECK) return true;
|
|
67
|
+
if (expected == STREAM_DOES_NOT_EXIST) return current === defaultVersion;
|
|
68
|
+
if (expected == STREAM_EXISTS) return current !== defaultVersion;
|
|
69
|
+
return current === expected;
|
|
52
70
|
};
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) => {
|
|
72
|
+
expected ??= NO_CONCURRENCY_CHECK;
|
|
73
|
+
if (!matchesExpectedVersion(current, expected, defaultVersion))
|
|
74
|
+
throw new ExpectedVersionConflictError(current, expected);
|
|
75
|
+
};
|
|
76
|
+
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
77
|
+
constructor(current, expected) {
|
|
78
|
+
super(_optionalChain([current, 'optionalAccess', _4 => _4.toString, 'call', _5 => _5()]), _optionalChain([expected, 'optionalAccess', _6 => _6.toString, 'call', _7 => _7()]));
|
|
79
|
+
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
56
80
|
}
|
|
57
81
|
};
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
constructor(
|
|
61
|
-
super({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
var notifyAboutNoActiveReadersStream = (onNoActiveReaderCallback, options = {}) => new NotifyAboutNoActiveReadersStream(onNoActiveReaderCallback, options);
|
|
83
|
+
var NotifyAboutNoActiveReadersStream = (_class = class extends _webstreamspolyfill.TransformStream {
|
|
84
|
+
constructor(onNoActiveReaderCallback, options = {}) {
|
|
85
|
+
super({
|
|
86
|
+
cancel: (reason) => {
|
|
87
|
+
console.log("Stream was canceled. Reason:", reason);
|
|
88
|
+
this.stopChecking();
|
|
89
|
+
}
|
|
90
|
+
});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
|
|
91
|
+
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
92
|
+
this.streamId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.streamId]), () => ( _uuid.v4.call(void 0, )));
|
|
93
|
+
this.onNoActiveReaderCallback = onNoActiveReaderCallback;
|
|
94
|
+
this.startChecking(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.intervalCheckInMs]), () => ( 20)));
|
|
66
95
|
}
|
|
67
96
|
__init() {this.checkInterval = null}
|
|
68
97
|
|
|
@@ -70,182 +99,322 @@ var S = (_class = class extends _webstreamspolyfill.TransformStream {
|
|
|
70
99
|
get hasActiveSubscribers() {
|
|
71
100
|
return !this._isStopped;
|
|
72
101
|
}
|
|
73
|
-
startChecking(
|
|
102
|
+
startChecking(interval) {
|
|
74
103
|
this.checkInterval = setInterval(() => {
|
|
75
104
|
this.checkNoActiveReader();
|
|
76
|
-
},
|
|
105
|
+
}, interval);
|
|
77
106
|
}
|
|
78
107
|
stopChecking() {
|
|
79
|
-
|
|
108
|
+
if (!this.checkInterval) return;
|
|
109
|
+
clearInterval(this.checkInterval);
|
|
110
|
+
this.checkInterval = null;
|
|
111
|
+
this._isStopped = true;
|
|
112
|
+
this.onNoActiveReaderCallback(this);
|
|
80
113
|
}
|
|
81
114
|
checkNoActiveReader() {
|
|
82
|
-
!this.readable.locked && !this._isStopped
|
|
115
|
+
if (!this.readable.locked && !this._isStopped) {
|
|
116
|
+
this.stopChecking();
|
|
117
|
+
}
|
|
83
118
|
}
|
|
84
119
|
}, _class);
|
|
85
|
-
var
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (Array.isArray(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
120
|
+
var deepEquals = (left, right) => {
|
|
121
|
+
if (isEquatable(left)) {
|
|
122
|
+
return left.equals(right);
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(left)) {
|
|
125
|
+
return Array.isArray(right) && left.length === right.length && left.every((val, index) => deepEquals(val, right[index]));
|
|
126
|
+
}
|
|
127
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
|
|
128
|
+
return left === right;
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(right)) return false;
|
|
131
|
+
const keys1 = Object.keys(left);
|
|
132
|
+
const keys2 = Object.keys(right);
|
|
133
|
+
if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key)))
|
|
134
|
+
return false;
|
|
135
|
+
for (const key in left) {
|
|
136
|
+
if (left[key] instanceof Function && right[key] instanceof Function)
|
|
137
|
+
continue;
|
|
138
|
+
const isEqual = deepEquals(left[key], right[key]);
|
|
139
|
+
if (!isEqual) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
95
142
|
}
|
|
96
143
|
return true;
|
|
97
144
|
};
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
var isEquatable = (left) => {
|
|
146
|
+
return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
147
|
+
};
|
|
148
|
+
var asyncRetry = async (fn, opts) => {
|
|
149
|
+
if (opts === void 0 || opts.retries === 0) return fn();
|
|
150
|
+
return _asyncretry2.default.call(void 0,
|
|
151
|
+
async (bail) => {
|
|
152
|
+
try {
|
|
153
|
+
return await fn();
|
|
154
|
+
} catch (error2) {
|
|
155
|
+
if (_optionalChain([opts, 'optionalAccess', _10 => _10.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
156
|
+
bail(error2);
|
|
157
|
+
}
|
|
158
|
+
throw error2;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
var projection = (definition) => definition;
|
|
165
|
+
var ParseError = class extends Error {
|
|
166
|
+
constructor(text) {
|
|
167
|
+
super(`Cannot parse! ${text}`);
|
|
104
168
|
}
|
|
105
|
-
}
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
169
|
+
};
|
|
170
|
+
var JSONParser = {
|
|
171
|
+
stringify: (value, options) => {
|
|
172
|
+
return JSON.stringify(
|
|
173
|
+
_optionalChain([options, 'optionalAccess', _11 => _11.map]) ? options.map(value) : value,
|
|
174
|
+
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
176
|
+
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
parse: (text, options) => {
|
|
180
|
+
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _12 => _12.reviver]));
|
|
181
|
+
if (_optionalChain([options, 'optionalAccess', _13 => _13.typeCheck]) && !_optionalChain([options, 'optionalAccess', _14 => _14.typeCheck, 'call', _15 => _15(parsed)]))
|
|
182
|
+
throw new ParseError(text);
|
|
183
|
+
return _optionalChain([options, 'optionalAccess', _16 => _16.map]) ? options.map(parsed) : parsed;
|
|
110
184
|
}
|
|
111
185
|
};
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var
|
|
186
|
+
var filter = (filter2) => new (0, _webstreamspolyfill.TransformStream)({
|
|
187
|
+
transform(chunk, controller) {
|
|
188
|
+
if (filter2(chunk)) {
|
|
189
|
+
controller.enqueue(chunk);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
var map = (map2) => new (0, _webstreamspolyfill.TransformStream)({
|
|
194
|
+
transform(chunk, controller) {
|
|
195
|
+
controller.enqueue(map2(chunk));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
var reduce = (reducer, initialValue) => new ReduceTransformStream(reducer, initialValue);
|
|
199
|
+
var ReduceTransformStream = class extends _webstreamspolyfill.TransformStream {
|
|
125
200
|
|
|
126
201
|
|
|
127
|
-
constructor(
|
|
128
|
-
super({
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
202
|
+
constructor(reducer, initialValue) {
|
|
203
|
+
super({
|
|
204
|
+
transform: (chunk) => {
|
|
205
|
+
this.accumulator = this.reducer(this.accumulator, chunk);
|
|
206
|
+
},
|
|
207
|
+
flush: (controller) => {
|
|
208
|
+
controller.enqueue(this.accumulator);
|
|
209
|
+
controller.terminate();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
this.accumulator = initialValue;
|
|
213
|
+
this.reducer = reducer;
|
|
133
214
|
}
|
|
134
215
|
};
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
216
|
+
var retryStream = (createSourceStream, handleChunk2, retryOptions = { forever: true, minTimeout: 25 }) => new (0, _webstreamspolyfill.TransformStream)({
|
|
217
|
+
start(controller) {
|
|
218
|
+
asyncRetry(
|
|
219
|
+
() => onRestream(createSourceStream, handleChunk2, controller),
|
|
220
|
+
retryOptions
|
|
221
|
+
).catch((error2) => {
|
|
222
|
+
controller.error(error2);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
var onRestream = async (createSourceStream, handleChunk2, controller) => {
|
|
227
|
+
const sourceStream = createSourceStream();
|
|
228
|
+
const reader = sourceStream.getReader();
|
|
142
229
|
try {
|
|
143
|
-
let
|
|
230
|
+
let done;
|
|
144
231
|
do {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
232
|
+
const result = await reader.read();
|
|
233
|
+
done = result.done;
|
|
234
|
+
await handleChunk2(result, controller);
|
|
235
|
+
if (done) {
|
|
236
|
+
controller.terminate();
|
|
237
|
+
}
|
|
238
|
+
} while (!done);
|
|
148
239
|
} finally {
|
|
149
|
-
|
|
240
|
+
reader.releaseLock();
|
|
150
241
|
}
|
|
151
242
|
};
|
|
152
|
-
var
|
|
153
|
-
var
|
|
243
|
+
var skip = (limit) => new SkipTransformStream(limit);
|
|
244
|
+
var SkipTransformStream = (_class2 = class extends _webstreamspolyfill.TransformStream {
|
|
154
245
|
__init3() {this.count = 0}
|
|
155
246
|
|
|
156
|
-
constructor(
|
|
157
|
-
super({
|
|
158
|
-
|
|
159
|
-
|
|
247
|
+
constructor(skip2) {
|
|
248
|
+
super({
|
|
249
|
+
transform: (chunk, controller) => {
|
|
250
|
+
this.count++;
|
|
251
|
+
if (this.count > this.skip) {
|
|
252
|
+
controller.enqueue(chunk);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});_class2.prototype.__init3.call(this);;
|
|
256
|
+
this.skip = skip2;
|
|
160
257
|
}
|
|
161
258
|
}, _class2);
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return;
|
|
259
|
+
var stopAfter = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
|
|
260
|
+
transform(chunk, controller) {
|
|
261
|
+
controller.enqueue(chunk);
|
|
262
|
+
if (stopCondition(chunk)) {
|
|
263
|
+
controller.terminate();
|
|
264
|
+
}
|
|
169
265
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
266
|
+
});
|
|
267
|
+
var stopOn = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
|
|
268
|
+
async transform(chunk, controller) {
|
|
269
|
+
if (!stopCondition(chunk)) {
|
|
270
|
+
controller.enqueue(chunk);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
await Promise.resolve();
|
|
274
|
+
controller.terminate();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
var take = (limit) => new TakeTransformStream(limit);
|
|
278
|
+
var TakeTransformStream = (_class3 = class extends _webstreamspolyfill.TransformStream {
|
|
174
279
|
__init4() {this.count = 0}
|
|
175
280
|
|
|
176
|
-
constructor(
|
|
177
|
-
super({
|
|
178
|
-
|
|
179
|
-
|
|
281
|
+
constructor(limit) {
|
|
282
|
+
super({
|
|
283
|
+
transform: (chunk, controller) => {
|
|
284
|
+
if (this.count < this.limit) {
|
|
285
|
+
this.count++;
|
|
286
|
+
controller.enqueue(chunk);
|
|
287
|
+
} else {
|
|
288
|
+
controller.terminate();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});_class3.prototype.__init4.call(this);;
|
|
292
|
+
this.limit = limit;
|
|
180
293
|
}
|
|
181
294
|
}, _class3);
|
|
182
|
-
var
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
constructor(e) {
|
|
196
|
-
super(e);
|
|
295
|
+
var waitAtMost = (waitTimeInMs) => new (0, _webstreamspolyfill.TransformStream)({
|
|
296
|
+
start(controller) {
|
|
297
|
+
const timeoutId = setTimeout(() => {
|
|
298
|
+
controller.terminate();
|
|
299
|
+
}, waitTimeInMs);
|
|
300
|
+
const originalTerminate = controller.terminate.bind(controller);
|
|
301
|
+
controller.terminate = () => {
|
|
302
|
+
clearTimeout(timeoutId);
|
|
303
|
+
originalTerminate();
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
transform(chunk, controller) {
|
|
307
|
+
controller.enqueue(chunk);
|
|
197
308
|
}
|
|
309
|
+
});
|
|
310
|
+
var streamTransformations = {
|
|
311
|
+
filter,
|
|
312
|
+
take,
|
|
313
|
+
TakeTransformStream,
|
|
314
|
+
skip,
|
|
315
|
+
SkipTransformStream,
|
|
316
|
+
map,
|
|
317
|
+
notifyAboutNoActiveReadersStream,
|
|
318
|
+
NotifyAboutNoActiveReadersStream,
|
|
319
|
+
reduce,
|
|
320
|
+
ReduceTransformStream,
|
|
321
|
+
retry: retryStream,
|
|
322
|
+
stopAfter,
|
|
323
|
+
stopOn,
|
|
324
|
+
waitAtMost
|
|
198
325
|
};
|
|
199
|
-
var
|
|
200
|
-
|
|
326
|
+
var { retry: retry2 } = streamTransformations;
|
|
327
|
+
var AssertionError = class extends Error {
|
|
328
|
+
constructor(message) {
|
|
329
|
+
super(message);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var assertFails = (message) => {
|
|
333
|
+
throw new AssertionError(_nullishCoalesce(message, () => ( "That should not ever happened, right?")));
|
|
201
334
|
};
|
|
202
|
-
var
|
|
203
|
-
if (!
|
|
204
|
-
|
|
335
|
+
var assertDeepEqual = (actual, expected, message) => {
|
|
336
|
+
if (!deepEquals(actual, expected))
|
|
337
|
+
throw new AssertionError(
|
|
338
|
+
_nullishCoalesce(message, () => ( `subObj:
|
|
339
|
+
${JSONParser.stringify(expected)}
|
|
205
340
|
is not equal to
|
|
206
|
-
${
|
|
341
|
+
${JSONParser.stringify(actual)}`))
|
|
342
|
+
);
|
|
207
343
|
};
|
|
208
|
-
function
|
|
209
|
-
if (!
|
|
344
|
+
function assertTrue(condition, message) {
|
|
345
|
+
if (!condition) throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is false`)));
|
|
210
346
|
}
|
|
211
|
-
function
|
|
212
|
-
if (!
|
|
347
|
+
function assertOk(obj, message) {
|
|
348
|
+
if (!obj) throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is not truthy`)));
|
|
213
349
|
}
|
|
214
|
-
function
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
|
|
350
|
+
function assertEqual(expected, actual, message) {
|
|
351
|
+
if (expected !== actual)
|
|
352
|
+
throw new AssertionError(
|
|
353
|
+
`${_nullishCoalesce(message, () => ( "Objects are not equal"))}:
|
|
354
|
+
Expected: ${JSONParser.stringify(expected)}
|
|
355
|
+
Actual:${JSONParser.stringify(actual)}`
|
|
356
|
+
);
|
|
218
357
|
}
|
|
219
|
-
function
|
|
220
|
-
if (
|
|
358
|
+
function assertNotEqual(obj, other, message) {
|
|
359
|
+
if (obj === other)
|
|
360
|
+
throw new AssertionError(
|
|
361
|
+
_nullishCoalesce(message, () => ( `Objects are equal: ${JSONParser.stringify(obj)}`))
|
|
362
|
+
);
|
|
221
363
|
}
|
|
222
|
-
function
|
|
223
|
-
|
|
364
|
+
function assertIsNotNull(result) {
|
|
365
|
+
assertNotEqual(result, null);
|
|
366
|
+
assertOk(result);
|
|
224
367
|
}
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
|
|
368
|
+
var assertThatArray = (array) => {
|
|
369
|
+
return {
|
|
370
|
+
isEmpty: () => assertEqual(array.length, 0),
|
|
371
|
+
isNotEmpty: () => assertNotEqual(array.length, 0),
|
|
372
|
+
hasSize: (length) => assertEqual(array.length, length),
|
|
373
|
+
containsElements: (...other) => {
|
|
374
|
+
assertTrue(other.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
375
|
+
},
|
|
376
|
+
containsExactlyInAnyOrder: (...other) => {
|
|
377
|
+
assertEqual(array.length, other.length);
|
|
378
|
+
assertTrue(array.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
379
|
+
},
|
|
380
|
+
containsExactlyInAnyOrderElementsOf: (other) => {
|
|
381
|
+
assertEqual(array.length, other.length);
|
|
382
|
+
assertTrue(array.every((ts) => other.some((o) => deepEquals(ts, o))));
|
|
383
|
+
},
|
|
384
|
+
containsExactlyElementsOf: (other) => {
|
|
385
|
+
assertEqual(array.length, other.length);
|
|
386
|
+
for (let i = 0; i < array.length; i++) {
|
|
387
|
+
assertTrue(deepEquals(array[i], other[i]));
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
containsExactly: (elem) => {
|
|
391
|
+
assertEqual(array.length, 1);
|
|
392
|
+
assertTrue(deepEquals(array[0], elem));
|
|
393
|
+
},
|
|
394
|
+
contains: (elem) => {
|
|
395
|
+
assertTrue(array.some((a) => deepEquals(a, elem)));
|
|
396
|
+
},
|
|
397
|
+
containsOnlyOnceElementsOf: (other) => {
|
|
398
|
+
assertTrue(
|
|
399
|
+
other.map((o) => array.filter((a) => deepEquals(a, o)).length).filter((a) => a === 1).length === other.length
|
|
400
|
+
);
|
|
401
|
+
},
|
|
402
|
+
containsAnyOf: (...other) => {
|
|
403
|
+
assertTrue(array.some((a) => other.some((o) => deepEquals(a, o))));
|
|
404
|
+
},
|
|
405
|
+
allMatch: (matches) => {
|
|
406
|
+
assertTrue(array.every(matches));
|
|
407
|
+
},
|
|
408
|
+
anyMatches: (matches) => {
|
|
409
|
+
assertTrue(array.some(matches));
|
|
410
|
+
},
|
|
411
|
+
allMatchAsync: async (matches) => {
|
|
412
|
+
for (const item of array) {
|
|
413
|
+
assertTrue(await matches(item));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
};
|
|
249
418
|
|
|
250
419
|
// src/eventStore/postgreSQLEventStore.ts
|
|
251
420
|
require('pg');
|
|
@@ -278,13 +447,13 @@ var withoutIdAndVersion = (doc) => {
|
|
|
278
447
|
};
|
|
279
448
|
var assertDocumentsEqual = (actual, expected) => {
|
|
280
449
|
if ("_id" in expected)
|
|
281
|
-
|
|
450
|
+
assertEqual(
|
|
282
451
|
expected._id,
|
|
283
452
|
actual._id,
|
|
284
453
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
285
454
|
`Document ids are not matching! Expected: ${expected._id}, actual: ${actual._id}`
|
|
286
455
|
);
|
|
287
|
-
return
|
|
456
|
+
return assertDeepEqual(
|
|
288
457
|
withoutIdAndVersion(actual),
|
|
289
458
|
withoutIdAndVersion(expected)
|
|
290
459
|
);
|
|
@@ -294,7 +463,7 @@ var documentExists = (document, options) => (assertOptions) => withCollection(
|
|
|
294
463
|
const result = await collection.findOne(
|
|
295
464
|
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
296
465
|
);
|
|
297
|
-
|
|
466
|
+
assertIsNotNull(result);
|
|
298
467
|
assertDocumentsEqual(result, document);
|
|
299
468
|
},
|
|
300
469
|
{ ...options, ...assertOptions }
|
|
@@ -304,13 +473,13 @@ var documentsAreTheSame = (documents, options) => (assertOptions) => withCollect
|
|
|
304
473
|
const result = await collection.find(
|
|
305
474
|
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
306
475
|
);
|
|
307
|
-
|
|
476
|
+
assertEqual(
|
|
308
477
|
documents.length,
|
|
309
478
|
result.length,
|
|
310
479
|
"Different Documents Count than expected"
|
|
311
480
|
);
|
|
312
481
|
for (let i = 0; i < documents.length; i++) {
|
|
313
|
-
|
|
482
|
+
assertThatArray(result).contains(documents[i]);
|
|
314
483
|
}
|
|
315
484
|
},
|
|
316
485
|
{ ...options, ...assertOptions }
|
|
@@ -320,7 +489,7 @@ var documentsMatchingHaveCount = (expectedCount, options) => (assertOptions) =>
|
|
|
320
489
|
const result = await collection.find(
|
|
321
490
|
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
322
491
|
);
|
|
323
|
-
|
|
492
|
+
assertEqual(
|
|
324
493
|
expectedCount,
|
|
325
494
|
result.length,
|
|
326
495
|
"Different Documents Count than expected"
|
|
@@ -333,7 +502,7 @@ var documentMatchingExists = (options) => (assertOptions) => withCollection(
|
|
|
333
502
|
const result = await collection.find(
|
|
334
503
|
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
335
504
|
);
|
|
336
|
-
|
|
505
|
+
assertThatArray(result).isNotEmpty();
|
|
337
506
|
},
|
|
338
507
|
{ ...options, ...assertOptions }
|
|
339
508
|
);
|
|
@@ -342,7 +511,7 @@ var documentDoesNotExist = (options) => (assertOptions) => withCollection(
|
|
|
342
511
|
const result = await collection.findOne(
|
|
343
512
|
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
344
513
|
);
|
|
345
|
-
|
|
514
|
+
assertIsNotNull(result);
|
|
346
515
|
},
|
|
347
516
|
{ ...options, ...assertOptions }
|
|
348
517
|
);
|
|
@@ -365,22 +534,22 @@ var expectPongoDocuments = {
|
|
|
365
534
|
})
|
|
366
535
|
};
|
|
367
536
|
},
|
|
368
|
-
matching: (
|
|
537
|
+
matching: (filter2) => {
|
|
369
538
|
return {
|
|
370
539
|
toBeTheSame: (documents) => documentsAreTheSame(documents, {
|
|
371
|
-
matchingFilter:
|
|
540
|
+
matchingFilter: filter2,
|
|
372
541
|
inCollection: collectionName
|
|
373
542
|
}),
|
|
374
543
|
toHaveCount: (expectedCount) => documentsMatchingHaveCount(expectedCount, {
|
|
375
|
-
matchingFilter:
|
|
544
|
+
matchingFilter: filter2,
|
|
376
545
|
inCollection: collectionName
|
|
377
546
|
}),
|
|
378
547
|
toExist: () => documentMatchingExists({
|
|
379
|
-
matchingFilter:
|
|
548
|
+
matchingFilter: filter2,
|
|
380
549
|
inCollection: collectionName
|
|
381
550
|
}),
|
|
382
551
|
notToExist: () => documentDoesNotExist({
|
|
383
|
-
matchingFilter:
|
|
552
|
+
matchingFilter: filter2,
|
|
384
553
|
inCollection: collectionName
|
|
385
554
|
})
|
|
386
555
|
};
|
|
@@ -414,14 +583,14 @@ var pongoMultiStreamProjection = (options) => {
|
|
|
414
583
|
return pongoProjection({
|
|
415
584
|
handle: async (events, { pongo }) => {
|
|
416
585
|
const collection = pongo.db().collection(collectionName);
|
|
417
|
-
for (const
|
|
418
|
-
await collection.handle(getDocumentId(
|
|
586
|
+
for (const event2 of events) {
|
|
587
|
+
await collection.handle(getDocumentId(event2), async (document) => {
|
|
419
588
|
return "initialState" in options ? await options.evolve(
|
|
420
589
|
_nullishCoalesce(document, () => ( options.initialState())),
|
|
421
|
-
|
|
590
|
+
event2
|
|
422
591
|
) : await options.evolve(
|
|
423
592
|
document,
|
|
424
|
-
|
|
593
|
+
event2
|
|
425
594
|
);
|
|
426
595
|
});
|
|
427
596
|
}
|
|
@@ -432,7 +601,7 @@ var pongoMultiStreamProjection = (options) => {
|
|
|
432
601
|
var pongoSingleStreamProjection = (options) => {
|
|
433
602
|
return pongoMultiStreamProjection({
|
|
434
603
|
...options,
|
|
435
|
-
getDocumentId: (
|
|
604
|
+
getDocumentId: (event2) => event2.metadata.streamName
|
|
436
605
|
});
|
|
437
606
|
};
|
|
438
607
|
|
|
@@ -444,7 +613,7 @@ var pongoSingleStreamProjection = (options) => {
|
|
|
444
613
|
var PostgreSQLProjectionSpec = {
|
|
445
614
|
for: (options) => {
|
|
446
615
|
{
|
|
447
|
-
const { projection, ...dumoOptions } = options;
|
|
616
|
+
const { projection: projection2, ...dumoOptions } = options;
|
|
448
617
|
const { connectionString } = dumoOptions;
|
|
449
618
|
return (givenEvents) => {
|
|
450
619
|
return {
|
|
@@ -452,13 +621,13 @@ var PostgreSQLProjectionSpec = {
|
|
|
452
621
|
const allEvents = [];
|
|
453
622
|
const run = async (pool) => {
|
|
454
623
|
let globalPosition = 0n;
|
|
455
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
456
|
-
for (const
|
|
624
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _17 => _17.numberOfTimes]), () => ( 1));
|
|
625
|
+
for (const event2 of [
|
|
457
626
|
...givenEvents,
|
|
458
627
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
459
628
|
]) {
|
|
460
629
|
allEvents.push({
|
|
461
|
-
...
|
|
630
|
+
...event2,
|
|
462
631
|
metadata: {
|
|
463
632
|
...{
|
|
464
633
|
globalPosition: ++globalPosition,
|
|
@@ -466,14 +635,14 @@ var PostgreSQLProjectionSpec = {
|
|
|
466
635
|
streamName: `test-${_uuid.v4.call(void 0, )}`,
|
|
467
636
|
eventId: _uuid.v4.call(void 0, )
|
|
468
637
|
},
|
|
469
|
-
..._nullishCoalesce(
|
|
638
|
+
..._nullishCoalesce(event2.metadata, () => ( {}))
|
|
470
639
|
}
|
|
471
640
|
});
|
|
472
641
|
}
|
|
473
642
|
await pool.withTransaction(
|
|
474
643
|
(transaction) => handleProjections({
|
|
475
644
|
events: allEvents,
|
|
476
|
-
projections: [
|
|
645
|
+
projections: [projection2],
|
|
477
646
|
connection: {
|
|
478
647
|
connectionString,
|
|
479
648
|
transaction
|
|
@@ -488,7 +657,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
488
657
|
await run(pool);
|
|
489
658
|
const succeeded = await assert({ pool, connectionString });
|
|
490
659
|
if (succeeded !== void 0 && succeeded === false)
|
|
491
|
-
|
|
660
|
+
assertFails(
|
|
492
661
|
_nullishCoalesce(message, () => ( "Projection specification didn't match the criteria"))
|
|
493
662
|
);
|
|
494
663
|
} finally {
|
|
@@ -499,25 +668,25 @@ var PostgreSQLProjectionSpec = {
|
|
|
499
668
|
const pool = _dumbo.dumbo.call(void 0, dumoOptions);
|
|
500
669
|
try {
|
|
501
670
|
await run(pool);
|
|
502
|
-
throw new
|
|
671
|
+
throw new AssertionError("Handler did not fail as expected");
|
|
503
672
|
} catch (error) {
|
|
504
|
-
if (error instanceof
|
|
673
|
+
if (error instanceof AssertionError) throw error;
|
|
505
674
|
if (args.length === 0) return;
|
|
506
|
-
if (!
|
|
507
|
-
|
|
675
|
+
if (!isErrorConstructor(args[0])) {
|
|
676
|
+
assertTrue(
|
|
508
677
|
args[0](error),
|
|
509
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
678
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _18 => _18.toString, 'call', _19 => _19()])}`
|
|
510
679
|
);
|
|
511
680
|
return;
|
|
512
681
|
}
|
|
513
|
-
|
|
682
|
+
assertTrue(
|
|
514
683
|
error instanceof args[0],
|
|
515
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
684
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _20 => _20.toString, 'call', _21 => _21()])}`
|
|
516
685
|
);
|
|
517
686
|
if (args[1]) {
|
|
518
|
-
|
|
687
|
+
assertTrue(
|
|
519
688
|
args[1](error),
|
|
520
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
689
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _22 => _22.toString, 'call', _23 => _23()])}`
|
|
521
690
|
);
|
|
522
691
|
}
|
|
523
692
|
} finally {
|
|
@@ -531,12 +700,12 @@ var PostgreSQLProjectionSpec = {
|
|
|
531
700
|
}
|
|
532
701
|
}
|
|
533
702
|
};
|
|
534
|
-
var eventInStream = (streamName,
|
|
703
|
+
var eventInStream = (streamName, event2) => {
|
|
535
704
|
return {
|
|
536
|
-
...
|
|
705
|
+
...event2,
|
|
537
706
|
metadata: {
|
|
538
|
-
..._nullishCoalesce(
|
|
539
|
-
streamName: _nullishCoalesce(_optionalChain([
|
|
707
|
+
..._nullishCoalesce(event2.metadata, () => ( {})),
|
|
708
|
+
streamName: _nullishCoalesce(_optionalChain([event2, 'access', _24 => _24.metadata, 'optionalAccess', _25 => _25.streamName]), () => ( streamName))
|
|
540
709
|
}
|
|
541
710
|
};
|
|
542
711
|
};
|
|
@@ -546,7 +715,7 @@ var eventsInStream = (streamName, events) => {
|
|
|
546
715
|
var newEventsInStream = eventsInStream;
|
|
547
716
|
var assertSQLQueryResultMatches = (sql3, rows) => async ({ pool: { execute } }) => {
|
|
548
717
|
const result = await execute.query(sql3);
|
|
549
|
-
|
|
718
|
+
assertThatArray(rows).containsExactlyInAnyOrder(...result.rows);
|
|
550
719
|
};
|
|
551
720
|
var expectSQL = {
|
|
552
721
|
query: (sql3) => ({
|
|
@@ -565,11 +734,11 @@ var handleProjections = async (options) => {
|
|
|
565
734
|
} = options;
|
|
566
735
|
const eventTypes = events.map((e) => e.type);
|
|
567
736
|
const projections = allProjections.filter(
|
|
568
|
-
(
|
|
737
|
+
(p) => p.canHandle.some((type) => eventTypes.includes(type))
|
|
569
738
|
);
|
|
570
739
|
const client = await transaction.connection.open();
|
|
571
|
-
for (const
|
|
572
|
-
await
|
|
740
|
+
for (const projection2 of projections) {
|
|
741
|
+
await projection2.handle(events, {
|
|
573
742
|
connectionString,
|
|
574
743
|
client,
|
|
575
744
|
transaction,
|
|
@@ -577,7 +746,7 @@ var handleProjections = async (options) => {
|
|
|
577
746
|
});
|
|
578
747
|
}
|
|
579
748
|
};
|
|
580
|
-
var postgreSQLProjection = (definition) =>
|
|
749
|
+
var postgreSQLProjection = (definition) => projection(definition);
|
|
581
750
|
var postgreSQLRawBatchSQLProjection = (handle, ...canHandle) => postgreSQLProjection({
|
|
582
751
|
canHandle,
|
|
583
752
|
handle: async (events, context) => {
|
|
@@ -588,8 +757,8 @@ var postgreSQLRawBatchSQLProjection = (handle, ...canHandle) => postgreSQLProjec
|
|
|
588
757
|
var postgreSQLRawSQLProjection = (handle, ...canHandle) => postgreSQLRawBatchSQLProjection(
|
|
589
758
|
async (events, context) => {
|
|
590
759
|
const sqls = [];
|
|
591
|
-
for (const
|
|
592
|
-
sqls.push(await handle(
|
|
760
|
+
for (const event2 of events) {
|
|
761
|
+
sqls.push(await handle(event2, context));
|
|
593
762
|
}
|
|
594
763
|
return sqls;
|
|
595
764
|
},
|
|
@@ -729,7 +898,7 @@ var appendToStream = (pool, streamName, streamType, events, options) => pool.wit
|
|
|
729
898
|
let appendResult;
|
|
730
899
|
try {
|
|
731
900
|
const expectedStreamVersion = toExpectedVersion(
|
|
732
|
-
_optionalChain([options, 'optionalAccess',
|
|
901
|
+
_optionalChain([options, 'optionalAccess', _26 => _26.expectedStreamVersion])
|
|
733
902
|
);
|
|
734
903
|
const eventsToAppend = events.map((e, i) => ({
|
|
735
904
|
...e,
|
|
@@ -749,7 +918,7 @@ var appendToStream = (pool, streamName, streamType, events, options) => pool.wit
|
|
|
749
918
|
expectedStreamVersion
|
|
750
919
|
}
|
|
751
920
|
);
|
|
752
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
921
|
+
if (_optionalChain([options, 'optionalAccess', _27 => _27.preCommitHook]))
|
|
753
922
|
await options.preCommitHook(eventsToAppend, { transaction });
|
|
754
923
|
} catch (error) {
|
|
755
924
|
if (!isOptimisticConcurrencyError(error)) throw error;
|
|
@@ -778,9 +947,9 @@ var appendToStream = (pool, streamName, streamType, events, options) => pool.wit
|
|
|
778
947
|
});
|
|
779
948
|
var toExpectedVersion = (expected) => {
|
|
780
949
|
if (expected === void 0) return null;
|
|
781
|
-
if (expected ===
|
|
782
|
-
if (expected ==
|
|
783
|
-
if (expected ==
|
|
950
|
+
if (expected === NO_CONCURRENCY_CHECK) return null;
|
|
951
|
+
if (expected == STREAM_DOES_NOT_EXIST) return null;
|
|
952
|
+
if (expected == STREAM_EXISTS) return null;
|
|
784
953
|
return expected;
|
|
785
954
|
};
|
|
786
955
|
var isOptimisticConcurrencyError = (error) => error instanceof Error && "code" in error && error.code === "23505";
|
|
@@ -799,14 +968,14 @@ var appendEventsRaw = (execute, streamId, streamType, events, options) => _dumbo
|
|
|
799
968
|
%L::text
|
|
800
969
|
)`,
|
|
801
970
|
events.map((e) => _dumbo.sql.call(void 0, "%L", e.metadata.eventId)).join(","),
|
|
802
|
-
events.map((e) => _dumbo.sql.call(void 0, "%L",
|
|
803
|
-
events.map((e) => _dumbo.sql.call(void 0, "%L",
|
|
971
|
+
events.map((e) => _dumbo.sql.call(void 0, "%L", JSONParser.stringify(e.data))).join(","),
|
|
972
|
+
events.map((e) => _dumbo.sql.call(void 0, "%L", JSONParser.stringify(_nullishCoalesce(e.metadata, () => ( {}))))).join(","),
|
|
804
973
|
events.map(() => `'1'`).join(","),
|
|
805
974
|
events.map((e) => _dumbo.sql.call(void 0, "%L", e.type)).join(","),
|
|
806
975
|
streamId,
|
|
807
976
|
streamType,
|
|
808
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
809
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
977
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _28 => _28.expectedStreamVersion]), () => ( "NULL")),
|
|
978
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _29 => _29.partition]), () => ( defaultTag))
|
|
810
979
|
)
|
|
811
980
|
)
|
|
812
981
|
);
|
|
@@ -1124,11 +1293,11 @@ var readStream = async (execute, streamId, options) => {
|
|
|
1124
1293
|
FROM ${eventsTable.name}
|
|
1125
1294
|
WHERE stream_id = %L AND partition = %L AND is_archived = FALSE ${fromCondition} ${toCondition}`,
|
|
1126
1295
|
streamId,
|
|
1127
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1296
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _30 => _30.partition]), () => ( defaultTag))
|
|
1128
1297
|
)
|
|
1129
1298
|
),
|
|
1130
1299
|
(row) => {
|
|
1131
|
-
const rawEvent =
|
|
1300
|
+
const rawEvent = event(
|
|
1132
1301
|
row.event_type,
|
|
1133
1302
|
row.event_data,
|
|
1134
1303
|
row.event_metadata
|
|
@@ -1188,7 +1357,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1188
1357
|
};
|
|
1189
1358
|
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
|
|
1190
1359
|
let migrateSchema;
|
|
1191
|
-
const autoGenerateSchema = _optionalChain([options, 'access',
|
|
1360
|
+
const autoGenerateSchema = _optionalChain([options, 'access', _31 => _31.schema, 'optionalAccess', _32 => _32.autoMigration]) === void 0 || _optionalChain([options, 'access', _33 => _33.schema, 'optionalAccess', _34 => _34.autoMigration]) !== "None";
|
|
1192
1361
|
const ensureSchemaExists = () => {
|
|
1193
1362
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1194
1363
|
if (!migrateSchema) {
|
|
@@ -1196,7 +1365,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1196
1365
|
}
|
|
1197
1366
|
return migrateSchema;
|
|
1198
1367
|
};
|
|
1199
|
-
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection }) =>
|
|
1368
|
+
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
1200
1369
|
const preCommitHook = inlineProjections.length > 0 ? (events, { transaction }) => handleProjections({
|
|
1201
1370
|
projections: inlineProjections,
|
|
1202
1371
|
connection: {
|
|
@@ -1215,18 +1384,18 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1215
1384
|
},
|
|
1216
1385
|
async aggregateStream(streamName, options2) {
|
|
1217
1386
|
const { evolve, initialState, read } = options2;
|
|
1218
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
1387
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _35 => _35.expectedStreamVersion]);
|
|
1219
1388
|
let state = initialState();
|
|
1220
1389
|
const result = await this.readStream(streamName, options2.read);
|
|
1221
1390
|
const currentStreamVersion = result.currentStreamVersion;
|
|
1222
|
-
|
|
1391
|
+
assertExpectedVersionMatchesCurrent(
|
|
1223
1392
|
currentStreamVersion,
|
|
1224
1393
|
expectedStreamVersion,
|
|
1225
1394
|
PostgreSQLEventStoreDefaultStreamVersion
|
|
1226
1395
|
);
|
|
1227
|
-
for (const
|
|
1228
|
-
if (!
|
|
1229
|
-
state = evolve(state,
|
|
1396
|
+
for (const event2 of result.events) {
|
|
1397
|
+
if (!event2) continue;
|
|
1398
|
+
state = evolve(state, event2);
|
|
1230
1399
|
}
|
|
1231
1400
|
return {
|
|
1232
1401
|
currentStreamVersion,
|
|
@@ -1253,10 +1422,10 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1253
1422
|
}
|
|
1254
1423
|
);
|
|
1255
1424
|
if (!appendResult.success)
|
|
1256
|
-
throw new
|
|
1425
|
+
throw new ExpectedVersionConflictError(
|
|
1257
1426
|
-1n,
|
|
1258
1427
|
//TODO: Return actual version in case of error
|
|
1259
|
-
_nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1428
|
+
_nullishCoalesce(_optionalChain([options2, 'optionalAccess', _36 => _36.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
1260
1429
|
);
|
|
1261
1430
|
return {
|
|
1262
1431
|
nextExpectedStreamVersion: appendResult.nextStreamPosition,
|