@platformatic/sql-events 3.71.1-alpha.0 → 4.0.0-alpha.1
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/index.js +17 -10
- package/package.json +3 -3
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) &&
|
|
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) &&
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Emit events via MQEmitter",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"neostandard": "^0.12.0",
|
|
23
23
|
"tstyche": "^7.0.0",
|
|
24
24
|
"typescript": "~6.0.3",
|
|
25
|
-
"@platformatic/sql-mapper": "
|
|
25
|
+
"@platformatic/sql-mapper": "4.0.0-alpha.1"
|
|
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": ">=
|
|
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",
|