@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.js
CHANGED
|
@@ -1,489 +1,109 @@
|
|
|
1
|
-
// src/eventStore/index.ts
|
|
2
|
-
import { EventStoreDBClient as EventStoreDBClient2 } from "@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 _EmmettError extends Error {
|
|
8
|
-
static Codes = {
|
|
9
|
-
ValidationError: 400,
|
|
10
|
-
IllegalStateError: 403,
|
|
11
|
-
NotFoundError: 404,
|
|
12
|
-
ConcurrencyError: 412,
|
|
13
|
-
InternalServerError: 500
|
|
14
|
-
};
|
|
15
|
-
errorCode;
|
|
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: 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
|
-
};
|
|
36
|
-
|
|
37
|
-
// ../emmett/dist/index.js
|
|
38
|
-
import { v4 as uuid5 } from "uuid";
|
|
39
|
-
import { v7 as uuid2 } from "uuid";
|
|
40
|
-
import { v7 as uuid } from "uuid";
|
|
41
|
-
import retry from "async-retry";
|
|
42
|
-
import { v7 as uuid3 } from "uuid";
|
|
43
|
-
import { v4 as uuid4 } from "uuid";
|
|
44
|
-
import { v7 as uuid6 } from "uuid";
|
|
45
|
-
var emmettPrefix = "emt";
|
|
46
|
-
var defaultTag = `${emmettPrefix}:default`;
|
|
47
|
-
var unknownTag = `${emmettPrefix}:unknown`;
|
|
48
|
-
var TaskProcessor = class {
|
|
49
|
-
queue = [];
|
|
50
|
-
isProcessing = false;
|
|
51
|
-
activeTasks = 0;
|
|
52
|
-
activeGroups = /* @__PURE__ */ new Set();
|
|
53
|
-
options;
|
|
54
|
-
stopped = false;
|
|
55
|
-
constructor(options) {
|
|
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 (!options?.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 = item.options?.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
|
-
takeFirstAvailableItem = () => {
|
|
142
|
-
const taskIndex = this.queue.findIndex(
|
|
143
|
-
(item2) => !item2.options?.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 item ?? null;
|
|
150
|
-
};
|
|
151
|
-
hasItemsToProcess = () => this.queue.findIndex(
|
|
152
|
-
(item) => !item.options?.taskGroupId || !this.activeGroups.has(item.options.taskGroupId)
|
|
153
|
-
) !== -1;
|
|
154
|
-
};
|
|
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 = 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(context?.source ?? value.toString());
|
|
257
|
-
} catch {
|
|
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 {
|
|
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
|
-
opts?.replacer,
|
|
309
|
-
opts?.failOnBigIntSerialization !== true ? JSONReplacers.bigInt : void 0,
|
|
310
|
-
opts?.useDefaultDateSerialization !== true ? JSONReplacers.date : void 0
|
|
311
|
-
);
|
|
312
|
-
var JSONReviver = (opts) => composeJSONRevivers(
|
|
313
|
-
opts?.reviver,
|
|
314
|
-
opts?.parseBigInts === true ? JSONRevivers.bigInt : void 0,
|
|
315
|
-
opts?.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) => options?.serialization?.serializer ?? (options?.serialization?.options ? jsonSerializer(options?.serialization?.options) : JSONSerializer)
|
|
341
|
-
});
|
|
342
|
-
var textEncoder = new TextEncoder();
|
|
343
|
-
|
|
344
|
-
// src/eventStore/eventStoreDBContainer.ts
|
|
345
1
|
import { EventStoreDBClient } from "@eventstore/db-client";
|
|
346
|
-
import {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
2
|
+
import { InProcessLock } from "@event-driven-io/emmett";
|
|
3
|
+
import { AbstractStartedContainer, GenericContainer, Wait } from "testcontainers";
|
|
4
|
+
import { MongoDBContainer } from "@testcontainers/mongodb";
|
|
5
|
+
import { PostgreSqlContainer } from "@testcontainers/postgresql";
|
|
6
|
+
|
|
7
|
+
//#region src/eventStore/eventStoreDBContainer.ts
|
|
8
|
+
const EVENTSTOREDB_PORT = 2113;
|
|
9
|
+
const EVENTSTOREDB_IMAGE_NAME = "eventstore/eventstore";
|
|
10
|
+
const EVENTSTOREDB_IMAGE_TAG = "24.10.0-bookworm-slim";
|
|
11
|
+
const EVENTSTOREDB_ARM64_IMAGE_TAG = "24.10.0-alpha-arm64v8";
|
|
12
|
+
const EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== "arm64" ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
|
|
13
|
+
const defaultEventStoreDBContainerOptions = {
|
|
14
|
+
disableProjections: false,
|
|
15
|
+
isSecure: false,
|
|
16
|
+
useFileStorage: false,
|
|
17
|
+
withReuse: false
|
|
361
18
|
};
|
|
362
19
|
var EventStoreDBContainer = class extends GenericContainer {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
Wait.forAll([Wait.forHealthCheck(), Wait.forListeningPorts()])
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
async start() {
|
|
388
|
-
return new StartedEventStoreDBContainer(await super.start());
|
|
389
|
-
}
|
|
20
|
+
constructor(image = EVENTSTOREDB_DEFAULT_IMAGE, options = defaultEventStoreDBContainerOptions) {
|
|
21
|
+
super(image);
|
|
22
|
+
const environment = {
|
|
23
|
+
...!options.disableProjections ? { EVENTSTORE_RUN_PROJECTIONS: "ALL" } : {},
|
|
24
|
+
...!options.isSecure ? { EVENTSTORE_INSECURE: "true" } : {},
|
|
25
|
+
...options.useFileStorage ? {
|
|
26
|
+
EVENTSTORE_MEM_DB: "false",
|
|
27
|
+
EVENTSTORE_DB: "/data/integration-tests"
|
|
28
|
+
} : {},
|
|
29
|
+
EVENTSTORE_CLUSTER_SIZE: "1",
|
|
30
|
+
EVENTSTORE_START_STANDARD_PROJECTIONS: "true",
|
|
31
|
+
EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
|
|
32
|
+
EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
|
|
33
|
+
};
|
|
34
|
+
this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
|
|
35
|
+
if (options.withReuse) this.withReuse();
|
|
36
|
+
this.withWaitStrategy(Wait.forAll([Wait.forHealthCheck(), Wait.forListeningPorts()]));
|
|
37
|
+
}
|
|
38
|
+
async start() {
|
|
39
|
+
return new StartedEventStoreDBContainer(await super.start());
|
|
40
|
+
}
|
|
390
41
|
};
|
|
391
42
|
var StartedEventStoreDBContainer = class extends AbstractStartedContainer {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const containerToStop = startedContainer;
|
|
426
|
-
if (containerToStop && --startedCount === 0) {
|
|
427
|
-
try {
|
|
428
|
-
startedContainer = null;
|
|
429
|
-
container = null;
|
|
430
|
-
await containerToStop.stop();
|
|
431
|
-
} catch {
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
{ lockId: "SharedEventStoreDBTestContainer" }
|
|
436
|
-
);
|
|
43
|
+
constructor(container) {
|
|
44
|
+
super(container);
|
|
45
|
+
}
|
|
46
|
+
getConnectionString() {
|
|
47
|
+
return `esdb://${this.getHost()}:${this.getMappedPort(2113)}?tls=false`;
|
|
48
|
+
}
|
|
49
|
+
getClient() {
|
|
50
|
+
return EventStoreDBClient.connectionString(this.getConnectionString());
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
let container = null;
|
|
54
|
+
let startedContainer = null;
|
|
55
|
+
let startedCount = 0;
|
|
56
|
+
const lock = InProcessLock();
|
|
57
|
+
const getSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
|
|
58
|
+
if (startedContainer) return startedContainer;
|
|
59
|
+
if (!container) container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
|
|
60
|
+
startedContainer = await container.start();
|
|
61
|
+
startedCount++;
|
|
62
|
+
container.withLogConsumer((stream) => stream.on("data", (line) => console.log(line)).on("err", (line) => console.error(line)).on("end", () => console.log("Stream closed")));
|
|
63
|
+
return startedContainer;
|
|
64
|
+
}, { lockId: "SharedEventStoreDBTestContainer" });
|
|
65
|
+
const getSharedTestEventStoreDBClient = async () => {
|
|
66
|
+
return (await getSharedEventStoreDBTestContainer()).getClient();
|
|
67
|
+
};
|
|
68
|
+
const releaseSharedEventStoreDBTestContainer = () => lock.withAcquire(async () => {
|
|
69
|
+
const containerToStop = startedContainer;
|
|
70
|
+
if (containerToStop && --startedCount === 0) try {
|
|
71
|
+
startedContainer = null;
|
|
72
|
+
container = null;
|
|
73
|
+
await containerToStop.stop();
|
|
74
|
+
} catch {}
|
|
75
|
+
}, { lockId: "SharedEventStoreDBTestContainer" });
|
|
437
76
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
return EventStoreDBClient2.connectionString(connectionString);
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/eventStore/index.ts
|
|
79
|
+
let esdbContainer;
|
|
80
|
+
const getEventStoreDBTestClient = async (useTestContainers = false) => {
|
|
81
|
+
let connectionString;
|
|
82
|
+
if (useTestContainers) {
|
|
83
|
+
if (!esdbContainer) esdbContainer = await new EventStoreDBContainer().start();
|
|
84
|
+
connectionString = esdbContainer.getConnectionString();
|
|
85
|
+
} else connectionString = "esdb://localhost:2113?tls=false";
|
|
86
|
+
return EventStoreDBClient.connectionString(connectionString);
|
|
450
87
|
};
|
|
451
88
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/mongodb/mongoDBContainer.ts
|
|
91
|
+
const getMongoDBContainer = (options = { version: "6.0.1" }) => {
|
|
92
|
+
return new MongoDBContainer(`mongo:${options.version}`);
|
|
456
93
|
};
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return container2.start();
|
|
94
|
+
const getMongoDBStartedContainer = async (options = { version: "6.0.1" }) => {
|
|
95
|
+
return getMongoDBContainer(options).start();
|
|
460
96
|
};
|
|
461
97
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
};
|
|
467
|
-
var getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
|
|
468
|
-
const container2 = getPostgreSQLContainer(options);
|
|
469
|
-
return container2.start();
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/postgresql/postgreSQLContainer.ts
|
|
100
|
+
const getPostgreSQLContainer = (options = { version: "18.1" }) => {
|
|
101
|
+
return new PostgreSqlContainer(`postgres:${options.version}`);
|
|
470
102
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
EVENTSTOREDB_DEFAULT_IMAGE,
|
|
474
|
-
EVENTSTOREDB_IMAGE_NAME,
|
|
475
|
-
EVENTSTOREDB_IMAGE_TAG,
|
|
476
|
-
EVENTSTOREDB_PORT,
|
|
477
|
-
EventStoreDBContainer,
|
|
478
|
-
StartedEventStoreDBContainer,
|
|
479
|
-
defaultEventStoreDBContainerOptions,
|
|
480
|
-
getEventStoreDBTestClient,
|
|
481
|
-
getMongoDBContainer,
|
|
482
|
-
getMongoDBStartedContainer,
|
|
483
|
-
getPostgreSQLContainer,
|
|
484
|
-
getPostgreSQLStartedContainer,
|
|
485
|
-
getSharedEventStoreDBTestContainer,
|
|
486
|
-
getSharedTestEventStoreDBClient,
|
|
487
|
-
releaseSharedEventStoreDBTestContainer
|
|
103
|
+
const getPostgreSQLStartedContainer = async (options = { version: "18.1" }) => {
|
|
104
|
+
return getPostgreSQLContainer(options).start();
|
|
488
105
|
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { EVENTSTOREDB_ARM64_IMAGE_TAG, EVENTSTOREDB_DEFAULT_IMAGE, EVENTSTOREDB_IMAGE_NAME, EVENTSTOREDB_IMAGE_TAG, EVENTSTOREDB_PORT, EventStoreDBContainer, StartedEventStoreDBContainer, defaultEventStoreDBContainerOptions, getEventStoreDBTestClient, getMongoDBContainer, getMongoDBStartedContainer, getPostgreSQLContainer, getPostgreSQLStartedContainer, getSharedEventStoreDBTestContainer, getSharedTestEventStoreDBClient, releaseSharedEventStoreDBTestContainer };
|
|
489
109
|
//# sourceMappingURL=index.js.map
|