@superhero/eventflow-db 4.1.2 → 4.2.0

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/README.md CHANGED
@@ -423,87 +423,87 @@ npm test
423
423
  ▶ @superhero/eventflow-db
424
424
  ▶ Setup table schemas
425
425
  ▶ Persist a hub
426
- ✔ Read online hubs (8.808208ms)
426
+ ✔ Read online hubs (6.657231ms)
427
427
 
428
428
  ▶ Persisting an event should generate an ID if not provided
429
- ✔ Read an event by id should return the same data as when persisted the event (9.057985ms)
429
+ ✔ Read an event by id should return the same data as when persisted the event (6.927063ms)
430
430
 
431
431
  ▶ Schedule a persisted event
432
- ✔ Read all scheduled events (5.28951ms)
433
- ✔ Update scheduled event as executed (11.686935ms)
434
- ✔ Update scheduled event as success (10.393756ms)
435
- ✔ Update scheduled event as failed (9.877872ms)
436
- ✔ Schedule a persisted event (50.493271ms)
432
+ ✔ Read all scheduled events (3.495457ms)
433
+ ✔ Update scheduled event as executed (8.137136ms)
434
+ ✔ Update scheduled event as success (4.61686ms)
435
+ ✔ Update scheduled event as failed (6.822805ms)
436
+ ✔ Schedule a persisted event (32.658117ms)
437
437
 
438
438
  ▶ Publish a persisted event
439
- ✔ Update published event to consumed by hub (8.985592ms)
440
- ✔ Update published event to consumed by spoke (10.847144ms)
441
- ✔ Update published event to success (8.945934ms)
442
- ✔ Update published event to failed (12.743366ms)
443
- ✔ Update published event to orphan (12.484305ms)
444
- ✔ Publish a persisted event (69.042999ms)
439
+ ✔ Update published event to consumed by hub (5.682705ms)
440
+ ✔ Update published event to consumed by spoke (6.462036ms)
441
+ ✔ Update published event to success (6.573691ms)
442
+ ✔ Update published event to failed (8.581383ms)
443
+ ✔ Update published event to orphan (6.094177ms)
444
+ ✔ Publish a persisted event (43.017241ms)
445
445
 
446
446
  ▶ Persist event cpid association
447
- ✔ Read events by domain and cpid (6.375096ms)
448
- ✔ Read associated cpid by event id (6.539711ms)
449
- ✔ Delete associated cpid by event id (35.785772ms)
450
- ✔ Read deleted associated cpid by event id returns empty (3.44164ms)
451
- ✔ Persist event cpid association (63.474382ms)
447
+ ✔ Read events by domain and cpid (3.71914ms)
448
+ ✔ Read associated cpid by event id (7.035953ms)
449
+ ✔ Delete associated cpid by event id (6.621011ms)
450
+ ✔ Read deleted associated cpid by event id returns empty (4.727825ms)
451
+ ✔ Persist event cpid association (34.125991ms)
452
452
 
453
453
  ▶ Persist event eid association
454
- ✔ Read events by eid (3.186193ms)
455
- ✔ Read events by domain and eid (3.211094ms)
456
- ✔ Read associated eid by event id (5.22712ms)
457
- ✔ Delete associated eid by event id (4.791241ms)
458
- ✔ Read deleted associated eid by event id returns empty (2.82022ms)
459
- ✔ Persist event eid association (25.839658ms)
454
+ ✔ Read events by eid (3.884999ms)
455
+ ✔ Read events by domain and eid (5.055002ms)
456
+ ✔ Read associated eid by event id (5.857354ms)
457
+ ✔ Delete associated eid by event id (6.000871ms)
458
+ ✔ Read deleted associated eid by event id returns empty (3.435941ms)
459
+ ✔ Persist event eid association (35.837834ms)
460
460
 
461
461
  ▶ Delete event
462
- ✔ Reading a deleted event rejects (2.870914ms)
463
- ✔ Delete event (12.001935ms)
462
+ ✔ Reading a deleted event rejects (3.54941ms)
463
+ ✔ Delete event (12.321329ms)
464
464
 
465
465
  ▶ By domain and pid
466
- ✔ Read event by domain and pid (4.653075ms)
467
- ✔ Delete event by domain and pid (6.649683ms)
468
- ✔ Read empty eventlog by domain and pid (2.870288ms)
469
- ✔ By domain and pid (19.564013ms)
470
- ✔ Persisting an event should generate an ID if not provided (257.977724ms)
471
-
472
- ✔ Persist log (8.236839ms)
473
- ✔ Update hub to quit (11.86896ms)
466
+ ✔ Read event by domain and pid (4.147919ms)
467
+ ✔ Delete event by domain and pid (6.651147ms)
468
+ ✔ Read empty eventlog by domain and pid (5.039975ms)
469
+ ✔ By domain and pid (24.294124ms)
470
+ ✔ Persisting an event should generate an ID if not provided (196.618539ms)
471
+
472
+ ✔ Persist log (9.773113ms)
473
+ ✔ Update hub to quit (6.745869ms)
474
474
 
475
475
  ▶ Certificate management
476
- ✔ Persist a certificate (9.410534ms)
477
- ✔ Persisting a duplicate certificate should return false (3.669139ms)
478
- ✔ Read a persisted certificate by id (9.817305ms)
479
- ✔ Reading a non-existing certificate should reject with an error (3.705119ms)
476
+ ✔ Persist a certificate (11.285064ms)
477
+ ✔ Persisting a duplicate certificate should return false (3.597549ms)
478
+ ✔ Read a persisted certificate by id (9.74682ms)
479
+ ✔ Reading a non-existing certificate should reject with an error (3.670532ms)
480
480
 
481
481
  ▶ Revoke a persisted certificate
482
- ✔ Reading a revoked certificate should reject with an error (3.894204ms)
483
- ✔ Revoke a persisted certificate (14.21005ms)
482
+ ✔ Reading a revoked certificate should reject with an error (2.507398ms)
483
+ ✔ Revoke a persisted certificate (10.427673ms)
484
484
 
485
485
  ▶ Revoke certificates that past there validity period
486
- ✔ Reading a revoked certificate should reject with an error (2.925027ms)
487
- ✔ Revoke certificates that past there validity period (13.092224ms)
488
- ✔ Certificate management (44.130336ms)
489
- ✔ Persist a hub (339.721847ms)
486
+ ✔ Reading a revoked certificate should reject with an error (2.622701ms)
487
+ ✔ Revoke certificates that past there validity period (15.182145ms)
488
+ ✔ Certificate management (58.006904ms)
489
+ ✔ Persist a hub (302.207468ms)
490
490
 
491
- ✔ Reading a non existing event should reject with an error (6.280731ms)
492
- ✔ Setup table schemas (431.031157ms)
493
- ✔ @superhero/eventflow-db (436.106715ms)
491
+ ✔ Reading a non existing event should reject with an error (3.189934ms)
492
+ ✔ Setup table schemas (516.946853ms)
493
+ ✔ @superhero/eventflow-db (519.11646ms)
494
494
 
495
- tests 43
495
+ tests 45
496
496
  suites 1
497
- pass 43
497
+ pass 45
498
498
 
499
499
  -------------------------------------------------------------------------------------------------------------------------
500
500
  file | line % | branch % | funcs % | uncovered lines
501
501
  -------------------------------------------------------------------------------------------------------------------------
502
502
  config.js | 100.00 | 100.00 | 100.00 |
503
- index.js | 69.41 | 56.25 | 97.92 | 43-48 58-62 73-77 88-92 103-107 118-122 133-137 148-153 186-191 203-207…
503
+ index.js | 69.26 | 56.57 | 97.96 | 43-48 58-62 73-77 88-92 103-107 118-122 133-137 148-153 186-191 203-207…
504
504
  index.test.js | 100.00 | 100.00 | 100.00 |
505
505
  -------------------------------------------------------------------------------------------------------------------------
506
- all files | 79.42 | 70.83 | 98.92 |
506
+ all files | 79.36 | 71.14 | 98.96 |
507
507
  -------------------------------------------------------------------------------------------------------------------------
508
508
  ```
509
509
 
package/index.js CHANGED
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url'
8
8
  export function locate(locator)
9
9
  {
10
10
  const
11
- config = locator('@superhero/config').find('eventflow/db', {}),
11
+ config = locator.config.find('eventflow/db', {}),
12
12
  adapterFactory = new AdapterFactory(),
13
13
  adapter = adapterFactory.create(mysql2, config),
14
14
  filePath = fileURLToPath(path.join(path.dirname(import.meta.url), 'sql')),
@@ -270,32 +270,51 @@ export default class DB
270
270
  return result
271
271
  }
272
272
 
273
- async persistEventCpid(event_id, cpid)
273
+ async readEventsByDomainAndPidAndNames(domain, pid, names)
274
274
  {
275
+ let result
276
+
275
277
  try
276
278
  {
277
- const result = await this.gateway.query('event_cpid/persist', [ event_id, cpid ])
279
+ result = await this.gateway.query('event/read-by-pid-domain-names', [ pid, domain, names ])
280
+ }
281
+ catch(reason)
282
+ {
283
+ const error = new Error(`could not read event by pid: ${pid} and domain: ${domain}`)
284
+ error.code = 'E_EVENTFLOW_DB_EVENT_READ_BY_PID'
285
+ error.cause = reason
286
+ throw error
287
+ }
288
+
289
+ return result
290
+ }
291
+
292
+ async persistEventCpid(event_id, domain, cpid)
293
+ {
294
+ try
295
+ {
296
+ const result = await this.gateway.query('event_cpid/persist', [ event_id, domain, cpid ])
278
297
  return result.affectedRows > 0
279
298
  }
280
299
  catch(reason)
281
300
  {
282
- const error = new Error(`Could not persist event (${event_id}) and cpid (${cpid}) association`)
301
+ const error = new Error(`Could not persist event (${event_id}) and cpid (${domain} › ${cpid}) association`)
283
302
  error.code = 'E_EVENTFLOW_DB_EVENT_CPID_PERSIST'
284
303
  error.cause = reason
285
304
  throw error
286
- }
305
+ }
287
306
  }
288
307
 
289
- async deleteEventCpid(event_id, cpid)
308
+ async deleteEventCpid(event_id, domain, cpid)
290
309
  {
291
310
  try
292
311
  {
293
- const result = await this.gateway.query('event_cpid/delete', [ event_id, cpid ])
312
+ const result = await this.gateway.query('event_cpid/delete', [ event_id, domain, cpid ])
294
313
  return result.affectedRows > 0
295
314
  }
296
315
  catch(reason)
297
316
  {
298
- const error = new Error(`Could not delete event (${event_id}) and cpid (${cpid}) association`)
317
+ const error = new Error(`Could not delete event (${event_id}) and cpid (${domain} › ${cpid}) association`)
299
318
  error.code = 'E_EVENTFLOW_DB_EVENT_CPID_DELETE'
300
319
  error.cause = reason
301
320
  throw error
@@ -318,7 +337,7 @@ export default class DB
318
337
  throw error
319
338
  }
320
339
 
321
- return result.map((row) => row.cpid)
340
+ return result.map(({ domain, cpid }) => ({ domain, cpid }))
322
341
  }
323
342
 
324
343
  async readEventsByDomainAndCpid(domain, cpid)
@@ -329,7 +348,7 @@ export default class DB
329
348
  }
330
349
  catch(reason)
331
350
  {
332
- const error = new Error(`could not read events by domain: ${domain} and cpid: ${cpid}`)
351
+ const error = new Error(`could not read events by: ${domain} ${cpid}`)
333
352
  error.code = 'E_EVENTFLOW_DB_EVENT_BY_DOMAIN_AND_CPID_READ'
334
353
  error.cause = reason
335
354
  throw error
package/index.test.js CHANGED
@@ -1,4 +1,3 @@
1
- import Config from '@superhero/config'
2
1
  import Locator from '@superhero/locator'
3
2
  import { locate } from '@superhero/eventflow-db'
4
3
  import assert from 'node:assert/strict'
@@ -7,10 +6,9 @@ import { after, suite, test } from 'node:test'
7
6
  suite('@superhero/eventflow-db', async () =>
8
7
  {
9
8
  const
10
- config = new Config(),
11
- locator = new Locator()
9
+ locator = new Locator(),
10
+ config = locator.config
12
11
 
13
- locator.set('@superhero/config', config)
14
12
  await config.add('./config.js')
15
13
  const db = locate(locator)
16
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-db",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "Eventflow db is a set of common database logic in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow"
@@ -15,8 +15,7 @@
15
15
  "@superhero/db": "^0.5.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@superhero/config": "4.1.3",
19
- "@superhero/locator": "4.2.1"
18
+ "@superhero/locator": "4.2.3"
20
19
  },
21
20
  "scripts": {
22
21
  "test-build": "docker ps -q -f name=eventflow-mysql | grep -q . && docker stop eventflow-mysql; docker run --rm --name eventflow-mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=eventflow -p 3306:3306 --health-cmd=\"mysqladmin ping -h 127.0.0.1 -uroot -proot --silent || exit 1\" --health-interval=10s --health-timeout=5s --health-retries=5 -d mysql:latest; until [ \"$(docker inspect --format='{{.State.Health.Status}}' eventflow-mysql)\" == \"healthy\" ]; do sleep 1; done",
@@ -0,0 +1,5 @@
1
+ SELECT *
2
+ FROM event
3
+ WHERE pid = ?
4
+ AND domain = ?
5
+ AND name IN (?)
@@ -1,12 +1,13 @@
1
1
  CREATE TABLE IF NOT EXISTS event_cpid
2
2
  (
3
3
  event_id VARCHAR(64) NOT NULL,
4
+ domain VARCHAR(64) NOT NULL,
4
5
  cpid VARCHAR(64) NOT NULL,
5
6
 
6
- PRIMARY KEY (event_id, cpid),
7
+ PRIMARY KEY (event_id, domain, cpid),
7
8
  FOREIGN KEY (event_id) REFERENCES event (id)
8
9
  ON UPDATE CASCADE
9
10
  ON DELETE CASCADE,
10
- INDEX idx_cpid (cpid)
11
+ INDEX idx_domain_cpid (domain, cpid)
11
12
  )
12
13
  ENGINE=InnoDB