@event-driven-io/emmett-testcontainers 0.43.0-beta.3 → 0.43.0-beta.30

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,362 +1,343 @@
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
- var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
41
-
42
-
43
-
44
- var emmettPrefix = "emt";
45
- var defaultTag = `${emmettPrefix}:default`;
46
- var unknownTag = `${emmettPrefix}:unknown`;
47
- var TaskProcessor = (_class2 = class {
48
- 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);
49
- this.options = options;
50
- }
51
- __init() {this.queue = []}
52
- __init2() {this.isProcessing = false}
53
- __init3() {this.activeTasks = 0}
54
- __init4() {this.activeGroups = /* @__PURE__ */ new Set()}
55
- enqueue(task, options) {
56
- if (this.queue.length >= this.options.maxQueueSize) {
57
- return Promise.reject(
58
- new EmmettError(
59
- "Too many pending connections. Please try again later."
60
- )
61
- );
62
- }
63
- return this.schedule(task, options);
64
- }
65
- waitForEndOfProcessing() {
66
- return this.schedule(({ ack }) => Promise.resolve(ack()));
67
- }
68
- schedule(task, options) {
69
- return promiseWithDeadline(
70
- (resolve, reject) => {
71
- const taskWithContext = () => {
72
- return new Promise((resolveTask, failTask) => {
73
- const taskPromise = task({
74
- ack: resolveTask
75
- });
76
- taskPromise.then(resolve).catch((err) => {
77
- failTask(err);
78
- reject(err);
79
- });
80
- });
81
- };
82
- this.queue.push({ task: taskWithContext, options });
83
- if (!this.isProcessing) {
84
- this.ensureProcessing();
85
- }
86
- },
87
- { deadline: this.options.maxTaskIdleTime }
88
- );
89
- }
90
- ensureProcessing() {
91
- if (this.isProcessing) return;
92
- this.isProcessing = true;
93
- this.processQueue();
94
- }
95
- processQueue() {
96
- try {
97
- while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
98
- const item = this.takeFirstAvailableItem();
99
- if (item === null) return;
100
- const groupId = _optionalChain([item, 'access', _5 => _5.options, 'optionalAccess', _6 => _6.taskGroupId]);
101
- if (groupId) {
102
- this.activeGroups.add(groupId);
103
- }
104
- this.activeTasks++;
105
- void this.executeItem(item);
106
- }
107
- } catch (error) {
108
- console.error(error);
109
- throw error;
110
- } finally {
111
- this.isProcessing = false;
112
- if (this.hasItemsToProcess() && this.activeTasks < this.options.maxActiveTasks) {
113
- this.ensureProcessing();
114
- }
115
- }
116
- }
117
- async executeItem({ task, options }) {
118
- try {
119
- await task();
120
- } finally {
121
- this.activeTasks--;
122
- if (options && options.taskGroupId) {
123
- this.activeGroups.delete(options.taskGroupId);
124
- }
125
- this.ensureProcessing();
126
- }
127
- }
128
- __init5() {this.takeFirstAvailableItem = () => {
129
- const taskIndex = this.queue.findIndex(
130
- (item2) => !_optionalChain([item2, 'access', _7 => _7.options, 'optionalAccess', _8 => _8.taskGroupId]) || !this.activeGroups.has(item2.options.taskGroupId)
131
- );
132
- if (taskIndex === -1) {
133
- return null;
134
- }
135
- const [item] = this.queue.splice(taskIndex, 1);
136
- return _nullishCoalesce(item, () => ( null));
137
- }}
138
- __init6() {this.hasItemsToProcess = () => this.queue.findIndex(
139
- (item) => !_optionalChain([item, 'access', _9 => _9.options, 'optionalAccess', _10 => _10.taskGroupId]) || !this.activeGroups.has(item.options.taskGroupId)
140
- ) !== -1}
141
- }, _class2);
142
- var DEFAULT_PROMISE_DEADLINE = 2147483647;
143
- var promiseWithDeadline = (executor, options) => {
144
- return new Promise((resolve, reject) => {
145
- let taskStarted = false;
146
- const maxWaitingTime = options.deadline || DEFAULT_PROMISE_DEADLINE;
147
- let timeoutId = setTimeout(() => {
148
- if (!taskStarted) {
149
- reject(
150
- new Error("Task was not started within the maximum waiting time")
151
- );
152
- }
153
- }, maxWaitingTime);
154
- executor((value) => {
155
- taskStarted = true;
156
- if (timeoutId) {
157
- clearTimeout(timeoutId);
158
- }
159
- timeoutId = null;
160
- resolve(value);
161
- }, reject);
162
- });
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 ../almanac/dist/logger-DnrSjS8d.js
9
+ const LogLevel = {
10
+ default: "info",
11
+ silent: "silent",
12
+ trace: "trace",
13
+ debug: "debug",
14
+ info: "info",
15
+ warn: "warn",
16
+ error: "error",
17
+ fatal: "fatal"
163
18
  };
164
- var InProcessLock = () => {
165
- const taskProcessor = new TaskProcessor({
166
- maxActiveTasks: Number.MAX_VALUE,
167
- maxQueueSize: Number.MAX_VALUE
168
- });
169
- const locks = /* @__PURE__ */ new Map();
170
- return {
171
- async acquire({ lockId }) {
172
- await new Promise((resolve, reject) => {
173
- taskProcessor.enqueue(
174
- ({ ack }) => {
175
- locks.set(lockId, ack);
176
- resolve();
177
- return Promise.resolve();
178
- },
179
- { taskGroupId: lockId }
180
- ).catch(reject);
181
- });
182
- },
183
- async tryAcquire({ lockId }) {
184
- if (locks.has(lockId)) {
185
- return false;
186
- }
187
- await this.acquire({ lockId });
188
- return true;
189
- },
190
- release({ lockId }) {
191
- const ack = locks.get(lockId);
192
- if (ack === void 0) {
193
- return Promise.resolve(true);
194
- }
195
- locks.delete(lockId);
196
- ack();
197
- return Promise.resolve(true);
198
- },
199
- async withAcquire(handle, { lockId }) {
200
- return taskProcessor.enqueue(
201
- async ({ ack }) => {
202
- locks.set(lockId, ack);
203
- try {
204
- return await handle();
205
- } finally {
206
- locks.delete(lockId);
207
- ack();
208
- }
209
- },
210
- { taskGroupId: lockId }
211
- );
212
- }
213
- };
19
+ const shouldLog = (logLevel, definedLogLevel) => {
20
+ definedLogLevel ??= LogLevel.default;
21
+ switch (definedLogLevel) {
22
+ case "fatal": return logLevel === LogLevel.fatal;
23
+ case "error": return [LogLevel.fatal, LogLevel.error].includes(logLevel);
24
+ case "warn": return [
25
+ LogLevel.fatal,
26
+ LogLevel.error,
27
+ LogLevel.warn
28
+ ].includes(logLevel);
29
+ case "info": return [
30
+ LogLevel.fatal,
31
+ LogLevel.error,
32
+ LogLevel.warn,
33
+ LogLevel.info
34
+ ].includes(logLevel);
35
+ case "debug": return [
36
+ LogLevel.fatal,
37
+ LogLevel.error,
38
+ LogLevel.warn,
39
+ LogLevel.info,
40
+ LogLevel.debug
41
+ ].includes(logLevel);
42
+ case "trace": return [
43
+ LogLevel.fatal,
44
+ LogLevel.error,
45
+ LogLevel.warn,
46
+ LogLevel.info,
47
+ LogLevel.debug,
48
+ LogLevel.trace
49
+ ].includes(logLevel);
50
+ case "silent": return false;
51
+ }
214
52
  };
215
- var textEncoder = new TextEncoder();
216
-
217
- // src/eventStore/eventStoreDBContainer.ts
218
-
219
-
220
-
221
-
222
-
223
- var _testcontainers = require('testcontainers');
224
- var EVENTSTOREDB_PORT = 2113;
225
- var EVENTSTOREDB_IMAGE_NAME = "eventstore/eventstore";
226
- var EVENTSTOREDB_IMAGE_TAG = "24.10.0-bookworm-slim";
227
- var EVENTSTOREDB_ARM64_IMAGE_TAG = "24.10.0-alpha-arm64v8";
228
- var EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== "arm64" ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
229
- var defaultEventStoreDBContainerOptions = {
230
- disableProjections: false,
231
- isSecure: false,
232
- useFileStorage: false,
233
- withReuse: false
53
+ const logEvent = (eventName, data, eventMetadata) => {
54
+ return {
55
+ name: eventName,
56
+ data,
57
+ metadata: {
58
+ ...eventMetadata,
59
+ timestamp: eventMetadata.timestamp ?? Date.now()
60
+ }
61
+ };
234
62
  };
235
- var EventStoreDBContainer = class extends _testcontainers.GenericContainer {
236
- constructor(image = EVENTSTOREDB_DEFAULT_IMAGE, options = defaultEventStoreDBContainerOptions) {
237
- super(image);
238
- const environment = {
239
- ...!options.disableProjections ? {
240
- EVENTSTORE_RUN_PROJECTIONS: "ALL"
241
- } : {},
242
- ...!options.isSecure ? {
243
- EVENTSTORE_INSECURE: "true"
244
- } : {},
245
- ...options.useFileStorage ? {
246
- EVENTSTORE_MEM_DB: "false",
247
- EVENTSTORE_DB: "/data/integration-tests"
248
- } : {},
249
- EVENTSTORE_CLUSTER_SIZE: "1",
250
- EVENTSTORE_START_STANDARD_PROJECTIONS: "true",
251
- EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
252
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
253
- };
254
- this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
255
- if (options.withReuse) this.withReuse();
256
- this.withWaitStrategy(
257
- _testcontainers.Wait.forAll([_testcontainers.Wait.forHealthCheck(), _testcontainers.Wait.forListeningPorts()])
258
- );
259
- }
260
- async start() {
261
- return new StartedEventStoreDBContainer(await super.start());
262
- }
63
+ const message = (level, body, data, eventMetadata) => {
64
+ if (data === void 0) return logEvent(body, { body }, {
65
+ level,
66
+ ...eventMetadata
67
+ });
68
+ const eventData = { body };
69
+ if (data.error !== void 0) eventData.error = data.error;
70
+ if (data.attributes !== void 0) eventData.attributes = data.attributes;
71
+ return logEvent(body, eventData, {
72
+ level,
73
+ ...eventMetadata
74
+ });
263
75
  };
264
- var StartedEventStoreDBContainer = class extends _testcontainers.AbstractStartedContainer {
265
- constructor(container2) {
266
- super(container2);
267
- }
268
- getConnectionString() {
269
- return `esdb://${this.getHost()}:${this.getMappedPort(2113)}?tls=false`;
270
- }
271
- getClient() {
272
- return _dbclient.EventStoreDBClient.connectionString(this.getConnectionString());
273
- }
76
+ const forLevel = (level) => (msgOrObj, msgOrMetadata, eventMetadata) => {
77
+ if (typeof msgOrObj === "string") return logEvent(msgOrObj, { body: msgOrObj }, {
78
+ level,
79
+ ...typeof msgOrMetadata === "string" ? eventMetadata : msgOrMetadata
80
+ });
81
+ const msg = typeof msgOrMetadata === "string" ? msgOrMetadata : void 0;
82
+ const overrides = eventMetadata ?? (typeof msgOrMetadata === "string" ? void 0 : msgOrMetadata);
83
+ if (msgOrObj instanceof Error) return logEvent(msg ?? "", {
84
+ error: msgOrObj,
85
+ body: msg
86
+ }, {
87
+ level,
88
+ ...overrides
89
+ });
90
+ const { eventName, ...attributes } = msgOrObj;
91
+ return logEvent(typeof eventName === "string" ? eventName : msg ?? "", {
92
+ attributes,
93
+ body: msg
94
+ }, {
95
+ level,
96
+ ...overrides
97
+ });
274
98
  };
275
- var container = null;
276
- var startedContainer = null;
277
- var startedCount = 0;
278
- var lock = InProcessLock();
279
- var getSharedEventStoreDBTestContainer = () => lock.withAcquire(
280
- async () => {
281
- if (startedContainer) return startedContainer;
282
- if (!container)
283
- container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
284
- startedContainer = await container.start();
285
- startedCount++;
286
- container.withLogConsumer(
287
- (stream) => stream.on("data", (line) => console.log(line)).on("err", (line) => console.error(line)).on("end", () => console.log("Stream closed"))
288
- );
289
- return startedContainer;
290
- },
291
- { lockId: "SharedEventStoreDBTestContainer" }
292
- );
293
- var getSharedTestEventStoreDBClient = async () => {
294
- return (await getSharedEventStoreDBTestContainer()).getClient();
99
+ const LogEvent = Object.assign(logEvent, {
100
+ message,
101
+ fatal: forLevel("fatal"),
102
+ error: forLevel("error"),
103
+ warn: forLevel("warn"),
104
+ info: forLevel("info"),
105
+ debug: forLevel("debug"),
106
+ trace: forLevel("trace"),
107
+ silent: forLevel("silent")
108
+ });
109
+ const logger = (options) => {
110
+ const { event: sink, minLevel } = options;
111
+ return (event) => {
112
+ if (event.metadata.level === "silent" || !shouldLog(event.metadata.level, minLevel)) return;
113
+ sink(event);
114
+ };
295
115
  };
296
- var releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(
297
- async () => {
298
- const containerToStop = startedContainer;
299
- if (containerToStop && --startedCount === 0) {
300
- try {
301
- startedContainer = null;
302
- container = null;
303
- await containerToStop.stop();
304
- } catch (e) {
305
- }
306
- }
307
- },
308
- { lockId: "SharedEventStoreDBTestContainer" }
309
- );
116
+ const noopLogger = logger({ event: () => {} });
310
117
 
311
- // src/eventStore/index.ts
312
- var esdbContainer;
313
- var getEventStoreDBTestClient = async (useTestContainers = false) => {
314
- let connectionString;
315
- if (useTestContainers) {
316
- if (!esdbContainer)
317
- esdbContainer = await new EventStoreDBContainer().start();
318
- connectionString = esdbContainer.getConnectionString();
319
- } else {
320
- connectionString = "esdb://localhost:2113?tls=false";
321
- }
322
- return _dbclient.EventStoreDBClient.connectionString(connectionString);
118
+ //#endregion
119
+ //#region ../almanac/dist/spanLogEvent-ByQosuDu.js
120
+ const bigIntReplacer = (_key, value) => {
121
+ return typeof value === "bigint" ? value.toString() : value;
323
122
  };
324
-
325
- // src/mongodb/mongoDBContainer.ts
326
- var _mongodb = require('@testcontainers/mongodb');
327
- var getMongoDBContainer = (options = { version: "6.0.1" }) => {
328
- return new (0, _mongodb.MongoDBContainer)(`mongo:${options.version}`);
123
+ const dateReplacer = (_key, value) => {
124
+ return value instanceof Date ? value.toISOString() : value;
329
125
  };
330
- var getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
331
- const container2 = getMongoDBContainer(options);
332
- return container2.start();
126
+ const errorReplacer = (_key, value) => value instanceof Error ? {
127
+ type: value.constructor.name || "error",
128
+ message: value.message,
129
+ stack: value.stack
130
+ } : value;
131
+ const isFirstLetterNumeric = (str) => {
132
+ const c = str.charCodeAt(0);
133
+ return c >= 48 && c <= 57;
333
134
  };
334
-
335
- // src/postgresql/postgreSQLContainer.ts
336
- var _postgresql = require('@testcontainers/postgresql');
337
- var getPostgreSQLContainer = (options = { version: "18.1" }) => {
338
- return new (0, _postgresql.PostgreSqlContainer)(`postgres:${options.version}`);
135
+ const isFirstLetterNumericOrMinus = (str) => {
136
+ const c = str.charCodeAt(0);
137
+ return c >= 48 && c <= 57 || c === 45;
339
138
  };
340
- var getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
341
- const container2 = getPostgreSQLContainer(options);
342
- return container2.start();
139
+ const bigIntReviver = (_key, value, context) => {
140
+ if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) try {
141
+ return BigInt(context?.source ?? value.toString());
142
+ } catch {
143
+ return value;
144
+ }
145
+ if (typeof value === "string" && value.length > 15) {
146
+ if (isFirstLetterNumericOrMinus(value)) {
147
+ const num = Number(value);
148
+ if (Number.isFinite(num) && !Number.isSafeInteger(num)) try {
149
+ return BigInt(value);
150
+ } catch {}
151
+ }
152
+ }
153
+ return value;
154
+ };
155
+ const dateReviver = (_key, value) => {
156
+ if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
157
+ const date = new Date(value);
158
+ if (!isNaN(date.getTime())) return date;
159
+ }
160
+ return value;
161
+ };
162
+ const composeJSONReplacers = (...replacers) => {
163
+ const filteredReplacers = replacers.filter((r) => r !== void 0);
164
+ if (filteredReplacers.length === 0) return void 0;
165
+ return (key, value) => filteredReplacers.reduce((accValue, replacer) => replacer(key, accValue), value);
166
+ };
167
+ const composeJSONRevivers = (...revivers) => {
168
+ const filteredRevivers = revivers.filter((r) => r !== void 0);
169
+ if (filteredRevivers.length === 0) return void 0;
170
+ return (key, value, context) => filteredRevivers.reduce((accValue, reviver) => reviver(key, accValue, context), value);
171
+ };
172
+ const JSONReplacer = (opts) => composeJSONReplacers(opts?.replacer, opts?.failOnBigIntSerialization !== true ? JSONReplacers.bigInt : void 0, opts?.useDefaultDateSerialization !== true ? JSONReplacers.date : void 0, opts?.skipErrorSerialization !== true ? JSONReplacers.error : void 0);
173
+ const JSONReviver = (opts) => composeJSONRevivers(opts?.reviver, opts?.parseBigInts === true ? JSONRevivers.bigInt : void 0, opts?.parseDates === true ? JSONRevivers.date : void 0);
174
+ const JSONReplacers = {
175
+ bigInt: bigIntReplacer,
176
+ date: dateReplacer,
177
+ error: errorReplacer
178
+ };
179
+ const JSONRevivers = {
180
+ bigInt: bigIntReviver,
181
+ date: dateReviver
182
+ };
183
+ const jsonSerializer = (options) => {
184
+ const defaultReplacer = JSONReplacer(options);
185
+ const defaultReviver = JSONReviver(options);
186
+ const defaultFormat = options?.format ?? "compact";
187
+ const defaultSafe = options?.safe ?? false;
188
+ return {
189
+ serialize: (object, serializerOptions) => {
190
+ const replacer = serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer;
191
+ const indent = (serializerOptions?.format ?? defaultFormat) === "pretty" ? 2 : void 0;
192
+ if (serializerOptions?.safe ?? defaultSafe) try {
193
+ return JSON.stringify(object, replacer, indent);
194
+ } catch (e) {
195
+ return `{"__serializationError":${JSON.stringify(String(e))}}`;
196
+ }
197
+ return JSON.stringify(object, replacer, indent);
198
+ },
199
+ deserialize: (payload, deserializerOptions) => JSON.parse(payload, deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver)
200
+ };
201
+ };
202
+ const JSONSerializer = Object.assign(jsonSerializer(), { from: (options) => options?.serialization?.serializer ?? (options?.serialization?.options ? jsonSerializer(options?.serialization?.options) : JSONSerializer) });
203
+
204
+ //#endregion
205
+ //#region ../almanac/dist/console-Bn5yW7XZ.js
206
+ const consoleMethodFor = (level) => {
207
+ switch (level) {
208
+ case "fatal":
209
+ case "error": return console.error;
210
+ case "warn": return console.warn;
211
+ case "debug": return console.debug;
212
+ case "trace": return console.trace;
213
+ default: return console.log;
214
+ }
215
+ };
216
+ const consoleLogger = logger({ event: (event) => {
217
+ const write = consoleMethodFor(event.metadata.level);
218
+ const extra = event.data.error ?? (event.data.attributes && Object.keys(event.data.attributes).length ? event.data.attributes : void 0);
219
+ if (event.data.body !== void 0 && extra !== void 0) write(event.data.body, extra);
220
+ else if (event.data.body !== void 0) write(event.data.body);
221
+ else if (extra !== void 0) write(extra);
222
+ else write("");
223
+ } });
224
+
225
+ //#endregion
226
+ //#region src/eventStore/eventStoreDBContainer.ts
227
+ const EVENTSTOREDB_PORT = 2113;
228
+ const EVENTSTOREDB_IMAGE_NAME = "eventstore/eventstore";
229
+ const EVENTSTOREDB_IMAGE_TAG = "24.10.0-bookworm-slim";
230
+ const EVENTSTOREDB_ARM64_IMAGE_TAG = "24.10.0-alpha-arm64v8";
231
+ const EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== "arm64" ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
232
+ const defaultEventStoreDBContainerOptions = {
233
+ disableProjections: false,
234
+ isSecure: false,
235
+ useFileStorage: false,
236
+ withReuse: false
237
+ };
238
+ var EventStoreDBContainer = class extends testcontainers.GenericContainer {
239
+ constructor(image = EVENTSTOREDB_DEFAULT_IMAGE, options = defaultEventStoreDBContainerOptions) {
240
+ super(image);
241
+ const environment = {
242
+ ...!options.disableProjections ? { EVENTSTORE_RUN_PROJECTIONS: "ALL" } : {},
243
+ ...!options.isSecure ? { EVENTSTORE_INSECURE: "true" } : {},
244
+ ...options.useFileStorage ? {
245
+ EVENTSTORE_MEM_DB: "false",
246
+ EVENTSTORE_DB: "/data/integration-tests"
247
+ } : {},
248
+ EVENTSTORE_CLUSTER_SIZE: "1",
249
+ EVENTSTORE_START_STANDARD_PROJECTIONS: "true",
250
+ EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
251
+ EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
252
+ };
253
+ this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
254
+ if (options.withReuse) this.withReuse();
255
+ this.withWaitStrategy(testcontainers.Wait.forAll([testcontainers.Wait.forHealthCheck(), testcontainers.Wait.forListeningPorts()]));
256
+ }
257
+ async start() {
258
+ return new StartedEventStoreDBContainer(await super.start());
259
+ }
260
+ };
261
+ var StartedEventStoreDBContainer = class extends testcontainers.AbstractStartedContainer {
262
+ constructor(container) {
263
+ super(container);
264
+ }
265
+ getConnectionString() {
266
+ return `esdb://${this.getHost()}:${this.getMappedPort(2113)}?tls=false`;
267
+ }
268
+ getClient() {
269
+ return _eventstore_db_client.EventStoreDBClient.connectionString(this.getConnectionString());
270
+ }
271
+ };
272
+ let container = null;
273
+ let startedContainer = null;
274
+ let startedCount = 0;
275
+ const lock = (0, _event_driven_io_emmett.InProcessLock)();
276
+ const getSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
277
+ if (startedContainer) return startedContainer;
278
+ if (!container) container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
279
+ startedContainer = await container.start();
280
+ startedCount++;
281
+ container.withLogConsumer((stream) => stream.on("data", (line) => consoleLogger(LogEvent.info(String(line)))).on("err", (line) => consoleLogger(LogEvent.error(String(line)))).on("end", () => consoleLogger(LogEvent.info("Stream closed"))));
282
+ return startedContainer;
283
+ }, { lockId: "SharedEventStoreDBTestContainer" });
284
+ const getSharedTestEventStoreDBClient = async () => {
285
+ return (await getSharedEventStoreDBTestContainer()).getClient();
286
+ };
287
+ const releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
288
+ const containerToStop = startedContainer;
289
+ if (containerToStop && --startedCount === 0) try {
290
+ startedContainer = null;
291
+ container = null;
292
+ await containerToStop.stop();
293
+ } catch {}
294
+ }, { lockId: "SharedEventStoreDBTestContainer" });
295
+
296
+ //#endregion
297
+ //#region src/eventStore/index.ts
298
+ let esdbContainer;
299
+ const getEventStoreDBTestClient = async (useTestContainers = false) => {
300
+ let connectionString;
301
+ if (useTestContainers) {
302
+ if (!esdbContainer) esdbContainer = await new EventStoreDBContainer().start();
303
+ connectionString = esdbContainer.getConnectionString();
304
+ } else connectionString = "esdb://localhost:2113?tls=false";
305
+ return _eventstore_db_client.EventStoreDBClient.connectionString(connectionString);
343
306
  };
344
307
 
308
+ //#endregion
309
+ //#region src/mongodb/mongoDBContainer.ts
310
+ const getMongoDBContainer = (options = { version: "6.0.1" }) => {
311
+ return new _testcontainers_mongodb.MongoDBContainer(`mongo:${options.version}`);
312
+ };
313
+ const getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
314
+ return getMongoDBContainer(options).start();
315
+ };
345
316
 
317
+ //#endregion
318
+ //#region src/postgresql/postgreSQLContainer.ts
319
+ const getPostgreSQLContainer = (options = { version: "18.1" }) => {
320
+ return new _testcontainers_postgresql.PostgreSqlContainer(`postgres:${options.version}`);
321
+ };
322
+ const getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
323
+ return getPostgreSQLContainer(options).start();
324
+ };
346
325
 
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
- 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;
326
+ //#endregion
327
+ exports.EVENTSTOREDB_ARM64_IMAGE_TAG = EVENTSTOREDB_ARM64_IMAGE_TAG;
328
+ exports.EVENTSTOREDB_DEFAULT_IMAGE = EVENTSTOREDB_DEFAULT_IMAGE;
329
+ exports.EVENTSTOREDB_IMAGE_NAME = EVENTSTOREDB_IMAGE_NAME;
330
+ exports.EVENTSTOREDB_IMAGE_TAG = EVENTSTOREDB_IMAGE_TAG;
331
+ exports.EVENTSTOREDB_PORT = EVENTSTOREDB_PORT;
332
+ exports.EventStoreDBContainer = EventStoreDBContainer;
333
+ exports.StartedEventStoreDBContainer = StartedEventStoreDBContainer;
334
+ exports.defaultEventStoreDBContainerOptions = defaultEventStoreDBContainerOptions;
335
+ exports.getEventStoreDBTestClient = getEventStoreDBTestClient;
336
+ exports.getMongoDBContainer = getMongoDBContainer;
337
+ exports.getMongoDBStartedContainer = getMongoDBStartedContainer;
338
+ exports.getPostgreSQLContainer = getPostgreSQLContainer;
339
+ exports.getPostgreSQLStartedContainer = getPostgreSQLStartedContainer;
340
+ exports.getSharedEventStoreDBTestContainer = getSharedEventStoreDBTestContainer;
341
+ exports.getSharedTestEventStoreDBClient = getSharedTestEventStoreDBClient;
342
+ exports.releaseSharedEventStoreDBTestContainer = releaseSharedEventStoreDBTestContainer;
362
343
  //# sourceMappingURL=index.cjs.map