@event-driven-io/emmett-testcontainers 0.43.0-beta.13 → 0.43.0-beta.15

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 CHANGED
@@ -1,489 +1,125 @@
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;// src/eventStore/index.ts
2
- var _dbclient = require('@eventstore/db-client');
3
-
4
- // ../emmett/dist/chunk-AZDDB5SF.js
5
- var isNumber = (val) => typeof val === "number" && val === val;
6
- var isString = (val) => typeof val === "string";
7
- var EmmettError = (_class = class _EmmettError extends Error {
8
- static __initStatic() {this.Codes = {
9
- ValidationError: 400,
10
- IllegalStateError: 403,
11
- NotFoundError: 404,
12
- ConcurrencyError: 412,
13
- InternalServerError: 500
14
- }}
15
-
16
- constructor(options) {
17
- const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
18
- const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
19
- super(message);
20
- this.errorCode = errorCode;
21
- Object.setPrototypeOf(this, _EmmettError.prototype);
22
- }
23
- static mapFrom(error) {
24
- if (_EmmettError.isInstanceOf(error)) {
25
- return error;
26
- }
27
- return new _EmmettError({
28
- errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
29
- message: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
30
- });
31
- }
32
- static isInstanceOf(error, errorCode) {
33
- return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
34
- }
35
- }, _class.__initStatic(), _class);
36
-
37
- // ../emmett/dist/index.js
38
- var _uuid = require('uuid');
39
-
40
-
41
- var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
42
-
43
-
44
-
45
- var emmettPrefix = "emt";
46
- var defaultTag = `${emmettPrefix}:default`;
47
- var unknownTag = `${emmettPrefix}:unknown`;
48
- var TaskProcessor = (_class2 = class {
49
- __init() {this.queue = []}
50
- __init2() {this.isProcessing = false}
51
- __init3() {this.activeTasks = 0}
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
- }
58
- enqueue(task, options) {
59
- if (this.stopped) {
60
- return Promise.reject(new EmmettError("TaskProcessor has been stopped"));
61
- }
62
- if (this.queue.length >= this.options.maxQueueSize) {
63
- return Promise.reject(
64
- new EmmettError("Too many pending tasks. Please try again later.")
65
- );
66
- }
67
- return this.schedule(task, options);
68
- }
69
- waitForEndOfProcessing() {
70
- return this.schedule(({ ack }) => Promise.resolve(ack()));
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
- }
81
- schedule(task, options) {
82
- return promiseWithDeadline(
83
- (resolve, reject) => {
84
- const taskWithContext = () => {
85
- return new Promise((resolveTask, failTask) => {
86
- const taskPromise = task({
87
- ack: resolveTask
88
- });
89
- taskPromise.then(resolve).catch((err) => {
90
- failTask(err);
91
- reject(err);
92
- });
93
- });
94
- };
95
- this.queue.push({ task: taskWithContext, options });
96
- if (!this.isProcessing) {
97
- this.ensureProcessing();
98
- }
99
- },
100
- { deadline: this.options.maxTaskIdleTime }
101
- );
102
- }
103
- ensureProcessing() {
104
- if (this.isProcessing) return;
105
- this.isProcessing = true;
106
- this.processQueue();
107
- }
108
- processQueue() {
109
- try {
110
- while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
111
- const item = this.takeFirstAvailableItem();
112
- if (item === null) return;
113
- const groupId = _optionalChain([item, 'access', _6 => _6.options, 'optionalAccess', _7 => _7.taskGroupId]);
114
- if (groupId) {
115
- this.activeGroups.add(groupId);
116
- }
117
- this.activeTasks++;
118
- void this.executeItem(item);
119
- }
120
- } catch (error) {
121
- console.error(error);
122
- throw error;
123
- } finally {
124
- this.isProcessing = false;
125
- if (this.hasItemsToProcess() && this.activeTasks < this.options.maxActiveTasks) {
126
- this.ensureProcessing();
127
- }
128
- }
129
- }
130
- async executeItem({ task, options }) {
131
- try {
132
- await task();
133
- } finally {
134
- this.activeTasks--;
135
- if (options && options.taskGroupId) {
136
- this.activeGroups.delete(options.taskGroupId);
137
- }
138
- this.ensureProcessing();
139
- }
140
- }
141
- __init6() {this.takeFirstAvailableItem = () => {
142
- const taskIndex = this.queue.findIndex(
143
- (item2) => !_optionalChain([item2, 'access', _8 => _8.options, 'optionalAccess', _9 => _9.taskGroupId]) || !this.activeGroups.has(item2.options.taskGroupId)
144
- );
145
- if (taskIndex === -1) {
146
- return null;
147
- }
148
- const [item] = this.queue.splice(taskIndex, 1);
149
- return _nullishCoalesce(item, () => ( null));
150
- }}
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)
153
- ) !== -1}
154
- }, _class2);
155
- var DEFAULT_PROMISE_DEADLINE = 2147483647;
156
- var promiseWithDeadline = (executor, options) => {
157
- return new Promise((resolve, reject) => {
158
- let taskStarted = false;
159
- let timeoutId = null;
160
- const deadline = _nullishCoalesce(options.deadline, () => ( DEFAULT_PROMISE_DEADLINE));
161
- timeoutId = setTimeout(() => {
162
- if (!taskStarted) {
163
- reject(
164
- new Error("Task was not started within the maximum waiting time")
165
- );
166
- }
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);
184
- }
185
- );
186
- });
187
- };
188
- var InProcessLock = () => {
189
- const taskProcessor = new TaskProcessor({
190
- maxActiveTasks: Number.MAX_VALUE,
191
- maxQueueSize: Number.MAX_VALUE
192
- });
193
- const locks = /* @__PURE__ */ new Map();
194
- return {
195
- async acquire({ lockId }) {
196
- await new Promise((resolve, reject) => {
197
- taskProcessor.enqueue(
198
- ({ ack }) => {
199
- locks.set(lockId, ack);
200
- resolve();
201
- return Promise.resolve();
202
- },
203
- { taskGroupId: lockId }
204
- ).catch(reject);
205
- });
206
- },
207
- async tryAcquire({ lockId }) {
208
- if (locks.has(lockId)) {
209
- return false;
210
- }
211
- await this.acquire({ lockId });
212
- return true;
213
- },
214
- release({ lockId }) {
215
- const ack = locks.get(lockId);
216
- if (ack === void 0) {
217
- return Promise.resolve(true);
218
- }
219
- locks.delete(lockId);
220
- ack();
221
- return Promise.resolve(true);
222
- },
223
- async withAcquire(handle, { lockId }) {
224
- return taskProcessor.enqueue(
225
- async ({ ack }) => {
226
- locks.set(lockId, ack);
227
- try {
228
- return await handle();
229
- } finally {
230
- locks.delete(lockId);
231
- ack();
232
- }
233
- },
234
- { taskGroupId: lockId }
235
- );
236
- }
237
- };
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
- });
342
- var textEncoder = new TextEncoder();
343
-
344
- // src/eventStore/eventStoreDBContainer.ts
345
-
346
-
347
-
348
-
349
-
350
- var _testcontainers = require('testcontainers');
351
- var EVENTSTOREDB_PORT = 2113;
352
- var EVENTSTOREDB_IMAGE_NAME = "eventstore/eventstore";
353
- var EVENTSTOREDB_IMAGE_TAG = "24.10.0-bookworm-slim";
354
- var EVENTSTOREDB_ARM64_IMAGE_TAG = "24.10.0-alpha-arm64v8";
355
- var EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== "arm64" ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
356
- var defaultEventStoreDBContainerOptions = {
357
- disableProjections: false,
358
- isSecure: false,
359
- useFileStorage: false,
360
- withReuse: false
361
- };
362
- var EventStoreDBContainer = class extends _testcontainers.GenericContainer {
363
- constructor(image = EVENTSTOREDB_DEFAULT_IMAGE, options = defaultEventStoreDBContainerOptions) {
364
- super(image);
365
- const environment = {
366
- ...!options.disableProjections ? {
367
- EVENTSTORE_RUN_PROJECTIONS: "ALL"
368
- } : {},
369
- ...!options.isSecure ? {
370
- EVENTSTORE_INSECURE: "true"
371
- } : {},
372
- ...options.useFileStorage ? {
373
- EVENTSTORE_MEM_DB: "false",
374
- EVENTSTORE_DB: "/data/integration-tests"
375
- } : {},
376
- EVENTSTORE_CLUSTER_SIZE: "1",
377
- EVENTSTORE_START_STANDARD_PROJECTIONS: "true",
378
- EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
379
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
380
- };
381
- this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
382
- if (options.withReuse) this.withReuse();
383
- this.withWaitStrategy(
384
- _testcontainers.Wait.forAll([_testcontainers.Wait.forHealthCheck(), _testcontainers.Wait.forListeningPorts()])
385
- );
386
- }
387
- async start() {
388
- return new StartedEventStoreDBContainer(await super.start());
389
- }
390
- };
391
- var StartedEventStoreDBContainer = class extends _testcontainers.AbstractStartedContainer {
392
- constructor(container2) {
393
- super(container2);
394
- }
395
- getConnectionString() {
396
- return `esdb://${this.getHost()}:${this.getMappedPort(2113)}?tls=false`;
397
- }
398
- getClient() {
399
- return _dbclient.EventStoreDBClient.connectionString(this.getConnectionString());
400
- }
401
- };
402
- var container = null;
403
- var startedContainer = null;
404
- var startedCount = 0;
405
- var lock = InProcessLock();
406
- var getSharedEventStoreDBTestContainer = () => lock.withAcquire(
407
- async () => {
408
- if (startedContainer) return startedContainer;
409
- if (!container)
410
- container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
411
- startedContainer = await container.start();
412
- startedCount++;
413
- container.withLogConsumer(
414
- (stream) => stream.on("data", (line) => console.log(line)).on("err", (line) => console.error(line)).on("end", () => console.log("Stream closed"))
415
- );
416
- return startedContainer;
417
- },
418
- { lockId: "SharedEventStoreDBTestContainer" }
419
- );
420
- var getSharedTestEventStoreDBClient = async () => {
421
- return (await getSharedEventStoreDBTestContainer()).getClient();
422
- };
423
- var releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(
424
- async () => {
425
- const containerToStop = startedContainer;
426
- if (containerToStop && --startedCount === 0) {
427
- try {
428
- startedContainer = null;
429
- container = null;
430
- await containerToStop.stop();
431
- } catch (e3) {
432
- }
433
- }
434
- },
435
- { lockId: "SharedEventStoreDBTestContainer" }
436
- );
437
-
438
- // src/eventStore/index.ts
439
- var esdbContainer;
440
- var getEventStoreDBTestClient = async (useTestContainers = false) => {
441
- let connectionString;
442
- if (useTestContainers) {
443
- if (!esdbContainer)
444
- esdbContainer = await new EventStoreDBContainer().start();
445
- connectionString = esdbContainer.getConnectionString();
446
- } else {
447
- connectionString = "esdb://localhost:2113?tls=false";
448
- }
449
- return _dbclient.EventStoreDBClient.connectionString(connectionString);
450
- };
451
-
452
- // src/mongodb/mongoDBContainer.ts
453
- var _mongodb = require('@testcontainers/mongodb');
454
- var getMongoDBContainer = (options = { version: "6.0.1" }) => {
455
- return new (0, _mongodb.MongoDBContainer)(`mongo:${options.version}`);
456
- };
457
- var getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
458
- const container2 = getMongoDBContainer(options);
459
- return container2.start();
460
- };
461
-
462
- // src/postgresql/postgreSQLContainer.ts
463
- var _postgresql = require('@testcontainers/postgresql');
464
- var getPostgreSQLContainer = (options = { version: "18.1" }) => {
465
- return new (0, _postgresql.PostgreSqlContainer)(`postgres:${options.version}`);
466
- };
467
- var getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
468
- const container2 = getPostgreSQLContainer(options);
469
- return container2.start();
470
- };
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
- exports.EVENTSTOREDB_ARM64_IMAGE_TAG = EVENTSTOREDB_ARM64_IMAGE_TAG; exports.EVENTSTOREDB_DEFAULT_IMAGE = EVENTSTOREDB_DEFAULT_IMAGE; exports.EVENTSTOREDB_IMAGE_NAME = EVENTSTOREDB_IMAGE_NAME; exports.EVENTSTOREDB_IMAGE_TAG = EVENTSTOREDB_IMAGE_TAG; exports.EVENTSTOREDB_PORT = EVENTSTOREDB_PORT; exports.EventStoreDBContainer = EventStoreDBContainer; exports.StartedEventStoreDBContainer = StartedEventStoreDBContainer; exports.defaultEventStoreDBContainerOptions = defaultEventStoreDBContainerOptions; exports.getEventStoreDBTestClient = getEventStoreDBTestClient; exports.getMongoDBContainer = getMongoDBContainer; exports.getMongoDBStartedContainer = getMongoDBStartedContainer; exports.getPostgreSQLContainer = getPostgreSQLContainer; exports.getPostgreSQLStartedContainer = getPostgreSQLStartedContainer; exports.getSharedEventStoreDBTestContainer = getSharedEventStoreDBTestContainer; exports.getSharedTestEventStoreDBClient = getSharedTestEventStoreDBClient; exports.releaseSharedEventStoreDBTestContainer = releaseSharedEventStoreDBTestContainer;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _eventstore_db_client = require("@eventstore/db-client");
3
+ let _event_driven_io_emmett = require("@event-driven-io/emmett");
4
+ let testcontainers = require("testcontainers");
5
+ let _testcontainers_mongodb = require("@testcontainers/mongodb");
6
+ let _testcontainers_postgresql = require("@testcontainers/postgresql");
7
+
8
+ //#region src/eventStore/eventStoreDBContainer.ts
9
+ const EVENTSTOREDB_PORT = 2113;
10
+ const EVENTSTOREDB_IMAGE_NAME = "eventstore/eventstore";
11
+ const EVENTSTOREDB_IMAGE_TAG = "24.10.0-bookworm-slim";
12
+ const EVENTSTOREDB_ARM64_IMAGE_TAG = "24.10.0-alpha-arm64v8";
13
+ const EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== "arm64" ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
14
+ const defaultEventStoreDBContainerOptions = {
15
+ disableProjections: false,
16
+ isSecure: false,
17
+ useFileStorage: false,
18
+ withReuse: false
19
+ };
20
+ var EventStoreDBContainer = class extends testcontainers.GenericContainer {
21
+ constructor(image = EVENTSTOREDB_DEFAULT_IMAGE, options = defaultEventStoreDBContainerOptions) {
22
+ super(image);
23
+ const environment = {
24
+ ...!options.disableProjections ? { EVENTSTORE_RUN_PROJECTIONS: "ALL" } : {},
25
+ ...!options.isSecure ? { EVENTSTORE_INSECURE: "true" } : {},
26
+ ...options.useFileStorage ? {
27
+ EVENTSTORE_MEM_DB: "false",
28
+ EVENTSTORE_DB: "/data/integration-tests"
29
+ } : {},
30
+ EVENTSTORE_CLUSTER_SIZE: "1",
31
+ EVENTSTORE_START_STANDARD_PROJECTIONS: "true",
32
+ EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
33
+ EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
34
+ };
35
+ this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
36
+ if (options.withReuse) this.withReuse();
37
+ this.withWaitStrategy(testcontainers.Wait.forAll([testcontainers.Wait.forHealthCheck(), testcontainers.Wait.forListeningPorts()]));
38
+ }
39
+ async start() {
40
+ return new StartedEventStoreDBContainer(await super.start());
41
+ }
42
+ };
43
+ var StartedEventStoreDBContainer = class extends testcontainers.AbstractStartedContainer {
44
+ constructor(container) {
45
+ super(container);
46
+ }
47
+ getConnectionString() {
48
+ return `esdb://${this.getHost()}:${this.getMappedPort(2113)}?tls=false`;
49
+ }
50
+ getClient() {
51
+ return _eventstore_db_client.EventStoreDBClient.connectionString(this.getConnectionString());
52
+ }
53
+ };
54
+ let container = null;
55
+ let startedContainer = null;
56
+ let startedCount = 0;
57
+ const lock = (0, _event_driven_io_emmett.InProcessLock)();
58
+ const getSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
59
+ if (startedContainer) return startedContainer;
60
+ if (!container) container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
61
+ startedContainer = await container.start();
62
+ startedCount++;
63
+ container.withLogConsumer((stream) => stream.on("data", (line) => console.log(line)).on("err", (line) => console.error(line)).on("end", () => console.log("Stream closed")));
64
+ return startedContainer;
65
+ }, { lockId: "SharedEventStoreDBTestContainer" });
66
+ const getSharedTestEventStoreDBClient = async () => {
67
+ return (await getSharedEventStoreDBTestContainer()).getClient();
68
+ };
69
+ const releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
70
+ const containerToStop = startedContainer;
71
+ if (containerToStop && --startedCount === 0) try {
72
+ startedContainer = null;
73
+ container = null;
74
+ await containerToStop.stop();
75
+ } catch {}
76
+ }, { lockId: "SharedEventStoreDBTestContainer" });
77
+
78
+ //#endregion
79
+ //#region src/eventStore/index.ts
80
+ let esdbContainer;
81
+ const getEventStoreDBTestClient = async (useTestContainers = false) => {
82
+ let connectionString;
83
+ if (useTestContainers) {
84
+ if (!esdbContainer) esdbContainer = await new EventStoreDBContainer().start();
85
+ connectionString = esdbContainer.getConnectionString();
86
+ } else connectionString = "esdb://localhost:2113?tls=false";
87
+ return _eventstore_db_client.EventStoreDBClient.connectionString(connectionString);
88
+ };
89
+
90
+ //#endregion
91
+ //#region src/mongodb/mongoDBContainer.ts
92
+ const getMongoDBContainer = (options = { version: "6.0.1" }) => {
93
+ return new _testcontainers_mongodb.MongoDBContainer(`mongo:${options.version}`);
94
+ };
95
+ const getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
96
+ return getMongoDBContainer(options).start();
97
+ };
98
+
99
+ //#endregion
100
+ //#region src/postgresql/postgreSQLContainer.ts
101
+ const getPostgreSQLContainer = (options = { version: "18.1" }) => {
102
+ return new _testcontainers_postgresql.PostgreSqlContainer(`postgres:${options.version}`);
103
+ };
104
+ const getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
105
+ return getPostgreSQLContainer(options).start();
106
+ };
107
+
108
+ //#endregion
109
+ exports.EVENTSTOREDB_ARM64_IMAGE_TAG = EVENTSTOREDB_ARM64_IMAGE_TAG;
110
+ exports.EVENTSTOREDB_DEFAULT_IMAGE = EVENTSTOREDB_DEFAULT_IMAGE;
111
+ exports.EVENTSTOREDB_IMAGE_NAME = EVENTSTOREDB_IMAGE_NAME;
112
+ exports.EVENTSTOREDB_IMAGE_TAG = EVENTSTOREDB_IMAGE_TAG;
113
+ exports.EVENTSTOREDB_PORT = EVENTSTOREDB_PORT;
114
+ exports.EventStoreDBContainer = EventStoreDBContainer;
115
+ exports.StartedEventStoreDBContainer = StartedEventStoreDBContainer;
116
+ exports.defaultEventStoreDBContainerOptions = defaultEventStoreDBContainerOptions;
117
+ exports.getEventStoreDBTestClient = getEventStoreDBTestClient;
118
+ exports.getMongoDBContainer = getMongoDBContainer;
119
+ exports.getMongoDBStartedContainer = getMongoDBStartedContainer;
120
+ exports.getPostgreSQLContainer = getPostgreSQLContainer;
121
+ exports.getPostgreSQLStartedContainer = getPostgreSQLStartedContainer;
122
+ exports.getSharedEventStoreDBTestContainer = getSharedEventStoreDBTestContainer;
123
+ exports.getSharedTestEventStoreDBClient = getSharedTestEventStoreDBClient;
124
+ exports.releaseSharedEventStoreDBTestContainer = releaseSharedEventStoreDBTestContainer;
489
125
  //# sourceMappingURL=index.cjs.map