@event-driven-io/emmett-testcontainers 0.43.0-beta.13 → 0.43.0-beta.14
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 +124 -488
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -26
- package/dist/index.d.ts +31 -26
- package/dist/index.js +95 -475
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,489 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|