@event-driven-io/emmett-testcontainers 0.43.0-beta.1 → 0.43.0-beta.11
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 +153 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +150 -22
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -37,26 +37,31 @@ var EmmettError = (_class = class _EmmettError extends Error {
|
|
|
37
37
|
// ../emmett/dist/index.js
|
|
38
38
|
var _uuid = require('uuid');
|
|
39
39
|
|
|
40
|
+
|
|
40
41
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
41
42
|
|
|
42
43
|
|
|
44
|
+
|
|
43
45
|
var emmettPrefix = "emt";
|
|
44
46
|
var defaultTag = `${emmettPrefix}:default`;
|
|
45
47
|
var unknownTag = `${emmettPrefix}:unknown`;
|
|
46
48
|
var TaskProcessor = (_class2 = class {
|
|
47
|
-
constructor(options) {;_class2.prototype.__init.call(this);_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);
|
|
48
|
-
this.options = options;
|
|
49
|
-
}
|
|
50
49
|
__init() {this.queue = []}
|
|
51
50
|
__init2() {this.isProcessing = false}
|
|
52
51
|
__init3() {this.activeTasks = 0}
|
|
53
52
|
__init4() {this.activeGroups = /* @__PURE__ */ new Set()}
|
|
53
|
+
|
|
54
|
+
__init5() {this.stopped = false}
|
|
55
|
+
constructor(options) {;_class2.prototype.__init.call(this);_class2.prototype.__init2.call(this);_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);
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
54
58
|
enqueue(task, options) {
|
|
59
|
+
if (this.stopped) {
|
|
60
|
+
return Promise.reject(new EmmettError("TaskProcessor has been stopped"));
|
|
61
|
+
}
|
|
55
62
|
if (this.queue.length >= this.options.maxQueueSize) {
|
|
56
63
|
return Promise.reject(
|
|
57
|
-
new EmmettError(
|
|
58
|
-
"Too many pending connections. Please try again later."
|
|
59
|
-
)
|
|
64
|
+
new EmmettError("Too many pending tasks. Please try again later.")
|
|
60
65
|
);
|
|
61
66
|
}
|
|
62
67
|
return this.schedule(task, options);
|
|
@@ -64,6 +69,15 @@ var TaskProcessor = (_class2 = class {
|
|
|
64
69
|
waitForEndOfProcessing() {
|
|
65
70
|
return this.schedule(({ ack }) => Promise.resolve(ack()));
|
|
66
71
|
}
|
|
72
|
+
async stop(options) {
|
|
73
|
+
if (this.stopped) return;
|
|
74
|
+
this.stopped = true;
|
|
75
|
+
this.queue.length = 0;
|
|
76
|
+
this.activeGroups.clear();
|
|
77
|
+
if (!_optionalChain([options, 'optionalAccess', _5 => _5.force])) {
|
|
78
|
+
await this.waitForEndOfProcessing();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
67
81
|
schedule(task, options) {
|
|
68
82
|
return promiseWithDeadline(
|
|
69
83
|
(resolve, reject) => {
|
|
@@ -96,16 +110,16 @@ var TaskProcessor = (_class2 = class {
|
|
|
96
110
|
while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
|
|
97
111
|
const item = this.takeFirstAvailableItem();
|
|
98
112
|
if (item === null) return;
|
|
99
|
-
const groupId = _optionalChain([item, 'access',
|
|
113
|
+
const groupId = _optionalChain([item, 'access', _6 => _6.options, 'optionalAccess', _7 => _7.taskGroupId]);
|
|
100
114
|
if (groupId) {
|
|
101
115
|
this.activeGroups.add(groupId);
|
|
102
116
|
}
|
|
103
117
|
this.activeTasks++;
|
|
104
118
|
void this.executeItem(item);
|
|
105
119
|
}
|
|
106
|
-
} catch (
|
|
107
|
-
console.error(
|
|
108
|
-
throw
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error);
|
|
122
|
+
throw error;
|
|
109
123
|
} finally {
|
|
110
124
|
this.isProcessing = false;
|
|
111
125
|
if (this.hasItemsToProcess() && this.activeTasks < this.options.maxActiveTasks) {
|
|
@@ -124,9 +138,9 @@ var TaskProcessor = (_class2 = class {
|
|
|
124
138
|
this.ensureProcessing();
|
|
125
139
|
}
|
|
126
140
|
}
|
|
127
|
-
|
|
141
|
+
__init6() {this.takeFirstAvailableItem = () => {
|
|
128
142
|
const taskIndex = this.queue.findIndex(
|
|
129
|
-
(item2) => !_optionalChain([item2, 'access',
|
|
143
|
+
(item2) => !_optionalChain([item2, 'access', _8 => _8.options, 'optionalAccess', _9 => _9.taskGroupId]) || !this.activeGroups.has(item2.options.taskGroupId)
|
|
130
144
|
);
|
|
131
145
|
if (taskIndex === -1) {
|
|
132
146
|
return null;
|
|
@@ -134,30 +148,41 @@ var TaskProcessor = (_class2 = class {
|
|
|
134
148
|
const [item] = this.queue.splice(taskIndex, 1);
|
|
135
149
|
return _nullishCoalesce(item, () => ( null));
|
|
136
150
|
}}
|
|
137
|
-
|
|
138
|
-
(item) => !_optionalChain([item, 'access',
|
|
151
|
+
__init7() {this.hasItemsToProcess = () => this.queue.findIndex(
|
|
152
|
+
(item) => !_optionalChain([item, 'access', _10 => _10.options, 'optionalAccess', _11 => _11.taskGroupId]) || !this.activeGroups.has(item.options.taskGroupId)
|
|
139
153
|
) !== -1}
|
|
140
154
|
}, _class2);
|
|
141
155
|
var DEFAULT_PROMISE_DEADLINE = 2147483647;
|
|
142
156
|
var promiseWithDeadline = (executor, options) => {
|
|
143
157
|
return new Promise((resolve, reject) => {
|
|
144
158
|
let taskStarted = false;
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
let timeoutId = null;
|
|
160
|
+
const deadline = _nullishCoalesce(options.deadline, () => ( DEFAULT_PROMISE_DEADLINE));
|
|
161
|
+
timeoutId = setTimeout(() => {
|
|
147
162
|
if (!taskStarted) {
|
|
148
163
|
reject(
|
|
149
164
|
new Error("Task was not started within the maximum waiting time")
|
|
150
165
|
);
|
|
151
166
|
}
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
}, deadline);
|
|
168
|
+
timeoutId.unref();
|
|
169
|
+
executor(
|
|
170
|
+
(value) => {
|
|
171
|
+
taskStarted = true;
|
|
172
|
+
if (timeoutId) {
|
|
173
|
+
clearTimeout(timeoutId);
|
|
174
|
+
}
|
|
175
|
+
timeoutId = null;
|
|
176
|
+
resolve(value);
|
|
177
|
+
},
|
|
178
|
+
(reason) => {
|
|
179
|
+
if (timeoutId) {
|
|
180
|
+
clearTimeout(timeoutId);
|
|
181
|
+
}
|
|
182
|
+
timeoutId = null;
|
|
183
|
+
reject(reason);
|
|
157
184
|
}
|
|
158
|
-
|
|
159
|
-
resolve(value);
|
|
160
|
-
}, reject);
|
|
185
|
+
);
|
|
161
186
|
});
|
|
162
187
|
};
|
|
163
188
|
var InProcessLock = () => {
|
|
@@ -211,6 +236,109 @@ var InProcessLock = () => {
|
|
|
211
236
|
}
|
|
212
237
|
};
|
|
213
238
|
};
|
|
239
|
+
var bigIntReplacer = (_key, value) => {
|
|
240
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
241
|
+
};
|
|
242
|
+
var dateReplacer = (_key, value) => {
|
|
243
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
244
|
+
};
|
|
245
|
+
var isFirstLetterNumeric = (str) => {
|
|
246
|
+
const c = str.charCodeAt(0);
|
|
247
|
+
return c >= 48 && c <= 57;
|
|
248
|
+
};
|
|
249
|
+
var isFirstLetterNumericOrMinus = (str) => {
|
|
250
|
+
const c = str.charCodeAt(0);
|
|
251
|
+
return c >= 48 && c <= 57 || c === 45;
|
|
252
|
+
};
|
|
253
|
+
var bigIntReviver = (_key, value, context) => {
|
|
254
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
255
|
+
try {
|
|
256
|
+
return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _12 => _12.source]), () => ( value.toString())));
|
|
257
|
+
} catch (e) {
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (typeof value === "string" && value.length > 15) {
|
|
262
|
+
if (isFirstLetterNumericOrMinus(value)) {
|
|
263
|
+
const num = Number(value);
|
|
264
|
+
if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
|
|
265
|
+
try {
|
|
266
|
+
return BigInt(value);
|
|
267
|
+
} catch (e2) {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return value;
|
|
273
|
+
};
|
|
274
|
+
var dateReviver = (_key, value) => {
|
|
275
|
+
if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
|
|
276
|
+
const date = new Date(value);
|
|
277
|
+
if (!isNaN(date.getTime())) {
|
|
278
|
+
return date;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return value;
|
|
282
|
+
};
|
|
283
|
+
var composeJSONReplacers = (...replacers) => {
|
|
284
|
+
const filteredReplacers = replacers.filter((r) => r !== void 0);
|
|
285
|
+
if (filteredReplacers.length === 0) return void 0;
|
|
286
|
+
return (key, value) => (
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
288
|
+
filteredReplacers.reduce(
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
290
|
+
(accValue, replacer) => replacer(key, accValue),
|
|
291
|
+
value
|
|
292
|
+
)
|
|
293
|
+
);
|
|
294
|
+
};
|
|
295
|
+
var composeJSONRevivers = (...revivers) => {
|
|
296
|
+
const filteredRevivers = revivers.filter((r) => r !== void 0);
|
|
297
|
+
if (filteredRevivers.length === 0) return void 0;
|
|
298
|
+
return (key, value, context) => (
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
300
|
+
filteredRevivers.reduce(
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
302
|
+
(accValue, reviver) => reviver(key, accValue, context),
|
|
303
|
+
value
|
|
304
|
+
)
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
var JSONReplacer = (opts) => composeJSONReplacers(
|
|
308
|
+
_optionalChain([opts, 'optionalAccess', _13 => _13.replacer]),
|
|
309
|
+
_optionalChain([opts, 'optionalAccess', _14 => _14.failOnBigIntSerialization]) !== true ? JSONReplacers.bigInt : void 0,
|
|
310
|
+
_optionalChain([opts, 'optionalAccess', _15 => _15.useDefaultDateSerialization]) !== true ? JSONReplacers.date : void 0
|
|
311
|
+
);
|
|
312
|
+
var JSONReviver = (opts) => composeJSONRevivers(
|
|
313
|
+
_optionalChain([opts, 'optionalAccess', _16 => _16.reviver]),
|
|
314
|
+
_optionalChain([opts, 'optionalAccess', _17 => _17.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
|
|
315
|
+
_optionalChain([opts, 'optionalAccess', _18 => _18.parseDates]) === true ? JSONRevivers.date : void 0
|
|
316
|
+
);
|
|
317
|
+
var JSONReplacers = {
|
|
318
|
+
bigInt: bigIntReplacer,
|
|
319
|
+
date: dateReplacer
|
|
320
|
+
};
|
|
321
|
+
var JSONRevivers = {
|
|
322
|
+
bigInt: bigIntReviver,
|
|
323
|
+
date: dateReviver
|
|
324
|
+
};
|
|
325
|
+
var jsonSerializer = (options) => {
|
|
326
|
+
const defaultReplacer = JSONReplacer(options);
|
|
327
|
+
const defaultReviver = JSONReviver(options);
|
|
328
|
+
return {
|
|
329
|
+
serialize: (object, serializerOptions) => JSON.stringify(
|
|
330
|
+
object,
|
|
331
|
+
serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
|
|
332
|
+
),
|
|
333
|
+
deserialize: (payload, deserializerOptions) => JSON.parse(
|
|
334
|
+
payload,
|
|
335
|
+
deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
|
|
336
|
+
)
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
var JSONSerializer = Object.assign(jsonSerializer(), {
|
|
340
|
+
from: (options) => _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.serialization, 'optionalAccess', _20 => _20.serializer]), () => ( (_optionalChain([options, 'optionalAccess', _21 => _21.serialization, 'optionalAccess', _22 => _22.options]) ? jsonSerializer(_optionalChain([options, 'optionalAccess', _23 => _23.serialization, 'optionalAccess', _24 => _24.options])) : JSONSerializer)))
|
|
341
|
+
});
|
|
214
342
|
var textEncoder = new TextEncoder();
|
|
215
343
|
|
|
216
344
|
// src/eventStore/eventStoreDBContainer.ts
|
|
@@ -300,7 +428,7 @@ var releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(
|
|
|
300
428
|
startedContainer = null;
|
|
301
429
|
container = null;
|
|
302
430
|
await containerToStop.stop();
|
|
303
|
-
} catch (
|
|
431
|
+
} catch (e3) {
|
|
304
432
|
}
|
|
305
433
|
}
|
|
306
434
|
},
|