@platformatic/sql-events 3.72.0 → 4.0.0-alpha.2

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.
Files changed (3) hide show
  1. package/index.js +17 -10
  2. package/package.json +4 -4
  3. package/.npmignore +0 -2
package/index.js CHANGED
@@ -31,7 +31,7 @@ export function setupEmitter ({ log, mq, mapper, connectionString }) {
31
31
  // The publish topic requires the primary key, so make sure it is always
32
32
  // retrieved even when the caller did not select it
33
33
  function ensurePrimaryKeyField (data) {
34
- if (Array.isArray(data.fields) && data.fields.length > 0 && !data.fields.includes(primaryKey)) {
34
+ if (Array.isArray(data.fields) && !data.fields.includes(primaryKey)) {
35
35
  return { ...data, fields: data.fields.concat(primaryKey) }
36
36
  }
37
37
  return data
@@ -39,7 +39,7 @@ export function setupEmitter ({ log, mq, mapper, connectionString }) {
39
39
 
40
40
  // Remove the primary key from the result when the caller did not select it
41
41
  function stripPrimaryKey (res, requestedFields) {
42
- if (Array.isArray(requestedFields) && requestedFields.length > 0 && !requestedFields.includes(primaryKey)) {
42
+ if (Array.isArray(requestedFields) && !requestedFields.includes(primaryKey)) {
43
43
  const { [primaryKey]: _, ...rest } = res
44
44
  return rest
45
45
  }
@@ -47,12 +47,23 @@ export function setupEmitter ({ log, mq, mapper, connectionString }) {
47
47
  }
48
48
 
49
49
  mapper.addEntityHooks(entityName, {
50
- async save (original, data) {
50
+ insert: singleElement('save'),
51
+ insertMany: multiElement('save'),
52
+ update: singleElement('save'),
53
+ updateMany: multiElement('save'),
54
+ delete: multiElement('delete')
55
+ })
56
+
57
+ function singleElement (action) {
58
+ return async function (original, data) {
51
59
  const ctx = data.ctx
52
60
  /* istanbul ignore next */
53
61
  const _log = ctx?.reply?.request?.log || log
54
62
  const res = await original(ensurePrimaryKeyField(data))
55
- const topic = await entity.getPublishTopic({ action: 'save', data: res, ctx })
63
+ if (!res) {
64
+ return res
65
+ }
66
+ const topic = await entity.getPublishTopic({ action, data: res, ctx })
56
67
  if (topic) {
57
68
  const payload = {
58
69
  [primaryKey]: res[primaryKey]
@@ -69,12 +80,8 @@ export function setupEmitter ({ log, mq, mapper, connectionString }) {
69
80
  })
70
81
  }
71
82
  return stripPrimaryKey(res, data.fields)
72
- },
73
-
74
- delete: multiElement('delete'),
75
- insert: multiElement('save'),
76
- updateMany: multiElement('save')
77
- })
83
+ }
84
+ }
78
85
 
79
86
  function multiElement (action) {
80
87
  return async function (original, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-events",
3
- "version": "3.72.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Emit events via MQEmitter",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,14 +15,14 @@
15
15
  },
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "devDependencies": {
18
- "@platformatic/sql-mapper": "3.72.0",
19
18
  "cleaner-spec-reporter": "^0.5.0",
20
19
  "eslint": "9",
21
20
  "fastify": "^5.0.0",
22
21
  "ioredis": "^5.3.2",
23
22
  "neostandard": "^0.12.0",
24
23
  "tstyche": "^7.0.0",
25
- "typescript": "~6.0.3"
24
+ "typescript": "~6.0.3",
25
+ "@platformatic/sql-mapper": "4.0.0-alpha.2"
26
26
  },
27
27
  "dependencies": {
28
28
  "@fastify/error": "^4.0.0",
@@ -32,7 +32,7 @@
32
32
  "mqemitter-redis": "^7.0.0"
33
33
  },
34
34
  "engines": {
35
- "node": ">=22.19.0"
35
+ "node": ">=24.20.0"
36
36
  },
37
37
  "scripts": {
38
38
  "test": "npm run test:types && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite",
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- test
2
- .nyc_output