@event-driven-io/emmett-testcontainers 0.43.0-beta.2 → 0.43.0-beta.20

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,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
- 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
- });
163
- };
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
- };
214
- };
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
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
234
19
  };
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
- }
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
+ }
263
42
  };
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
- }
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
+ }
274
53
  };
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();
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();
295
68
  };
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
- );
310
-
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);
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);
323
88
  };
324
89
 
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}`);
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}`);
329
94
  };
330
- var getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
331
- const container2 = getMongoDBContainer(options);
332
- return container2.start();
95
+ const getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
96
+ return getMongoDBContainer(options).start();
333
97
  };
334
98
 
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}`);
99
+ //#endregion
100
+ //#region src/postgresql/postgreSQLContainer.ts
101
+ const getPostgreSQLContainer = (options = { version: "18.1" }) => {
102
+ return new _testcontainers_postgresql.PostgreSqlContainer(`postgres:${options.version}`);
339
103
  };
340
- var getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
341
- const container2 = getPostgreSQLContainer(options);
342
- return container2.start();
104
+ const getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
105
+ return getPostgreSQLContainer(options).start();
343
106
  };
344
107
 
345
-
346
-
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;
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;
362
125
  //# sourceMappingURL=index.cjs.map