@magek/adapter-event-store-nedb 0.0.6 → 0.0.7

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.
@@ -5,8 +5,9 @@ const path = require("path");
5
5
  exports.eventsDatabase = path.normalize(path.join('.', '.magek', 'events.json'));
6
6
  const DataStore = require('@seald-io/nedb');
7
7
  class EventRegistry {
8
+ events;
9
+ isLoaded = false;
8
10
  constructor() {
9
- this.isLoaded = false;
10
11
  this.events = new DataStore({ filename: exports.eventsDatabase });
11
12
  }
12
13
  async loadDatabaseIfNeeded() {
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ function notImplemented() {
16
16
  async function countAll(database) {
17
17
  await database.loadDatabaseAsync();
18
18
  const count = await database.countAsync({});
19
- return count !== null && count !== void 0 ? count : 0;
19
+ return count ?? 0;
20
20
  }
21
21
  // Function to get userApp from config or load it from standard location
22
22
  function getUserApp(config) {
@@ -51,10 +51,7 @@ async function storeEvents(userApp, eventRegistry, nonPersistedEventEnvelopes, c
51
51
  logger.debug('Storing the following event envelopes:', nonPersistedEventEnvelopes);
52
52
  const persistedEventEnvelopes = [];
53
53
  for (const nonPersistedEventEnvelope of nonPersistedEventEnvelopes) {
54
- const persistableEventEnvelope = {
55
- ...nonPersistedEventEnvelope,
56
- createdAt: new Date().toISOString(),
57
- };
54
+ const persistableEventEnvelope = nonPersistedEventEnvelope;
58
55
  await (0, common_1.retryIfError)(async () => await persistEvent(eventRegistry, persistableEventEnvelope), common_1.OptimisticConcurrencyUnexpectedVersionError);
59
56
  persistedEventEnvelopes.push(persistableEventEnvelope);
60
57
  }
@@ -68,7 +65,7 @@ async function storeSnapshot(eventRegistry, snapshotEnvelope, config) {
68
65
  const persistableEntitySnapshot = {
69
66
  ...snapshotEnvelope,
70
67
  createdAt: snapshotEnvelope.snapshottedEventCreatedAt,
71
- persistedAt: new Date().toISOString(),
68
+ persistedAt: (0, common_1.getTimestampGenerator)().next(),
72
69
  };
73
70
  await (0, common_1.retryIfError)(() => eventRegistry.store(persistableEntitySnapshot), common_1.OptimisticConcurrencyUnexpectedVersionError);
74
71
  logger.debug('Snapshot stored');
@@ -18,7 +18,6 @@ async function searchEvents(eventRegistry, config, parameters) {
18
18
  return eventsSearchResponses;
19
19
  }
20
20
  async function searchEntitiesIds(eventRegistry, config, limit, afterCursor, entityTypeName) {
21
- var _a;
22
21
  const logger = (0, common_1.getLogger)(config, 'events-searcher-adapter#searchEntitiesIds');
23
22
  logger.debug(`Initiating a paginated events search. limit: ${limit}, afterCursor: ${JSON.stringify(afterCursor)}, entityTypeName: ${entityTypeName}`);
24
23
  const filterQuery = {
@@ -30,15 +29,15 @@ async function searchEntitiesIds(eventRegistry, config, limit, afterCursor, enti
30
29
  entityID: 1,
31
30
  }));
32
31
  // Nedb doesn't support DISTINCT, so we need to paginate the results manually
33
- const entitiesIds = result ? result === null || result === void 0 ? void 0 : result.map((v) => v.entityID) : [];
32
+ const entitiesIds = result ? result?.map((v) => v.entityID) : [];
34
33
  const uniqueResult = (0, common_1.unique)(entitiesIds);
35
- const skipId = (afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.id) ? parseInt(afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.id) : 0;
34
+ const skipId = afterCursor?.id ? parseInt(afterCursor?.id) : 0;
36
35
  const paginated = uniqueResult.slice(skipId, skipId + limit);
37
36
  const paginatedResult = paginated.map((v) => ({ entityID: v }));
38
37
  logger.debug('Unique events search result', paginatedResult);
39
38
  return {
40
39
  items: paginatedResult,
41
- count: (_a = paginatedResult === null || paginatedResult === void 0 ? void 0 : paginatedResult.length) !== null && _a !== void 0 ? _a : 0,
40
+ count: paginatedResult?.length ?? 0,
42
41
  cursor: { id: ((limit ? limit : 1) + skipId).toString() },
43
42
  };
44
43
  }
@@ -50,7 +50,7 @@ function resultToEventSearchResponse(result) {
50
50
  deletedAt: item.deletedAt,
51
51
  };
52
52
  });
53
- return eventSearchResult !== null && eventSearchResult !== void 0 ? eventSearchResult : [];
53
+ return eventSearchResult ?? [];
54
54
  }
55
55
  function buildByEntityAndID(entityValue, entityIdValue) {
56
56
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magek/adapter-event-store-nedb",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Nedb-based event store adapter for the Magek framework",
5
5
  "keywords": [
6
6
  "event-store",
@@ -24,7 +24,7 @@
24
24
  "node": ">=22.0.0 <23.0.0"
25
25
  },
26
26
  "dependencies": {
27
- "@magek/common": "^0.0.6",
27
+ "@magek/common": "^0.0.7",
28
28
  "@seald-io/nedb": "4.1.2",
29
29
  "tslib": "2.8.1"
30
30
  },
@@ -32,7 +32,7 @@
32
32
  "url": "https://github.com/theam/magek/issues"
33
33
  },
34
34
  "devDependencies": {
35
- "@magek/eslint-config": "^0.0.6",
35
+ "@magek/eslint-config": "^0.0.7",
36
36
  "@types/chai": "5.2.3",
37
37
  "@types/chai-as-promised": "8.0.2",
38
38
  "@types/mocha": "10.0.10",