@jcbuisson/express-x 1.0.9 → 1.0.11
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/package.json +1 -1
- package/src/index.mjs +46 -26
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -21,30 +21,50 @@ function expressX(app) {
|
|
|
21
21
|
*/
|
|
22
22
|
function createDatabaseService(name, { entity=name, client='prisma' }) {
|
|
23
23
|
return createService(name, {
|
|
24
|
-
create: (data) =>
|
|
25
|
-
data
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
create: (data) => {
|
|
25
|
+
if (isDebug) console.log('create', name, data)
|
|
26
|
+
return prisma[entity].create({
|
|
27
|
+
data,
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
get: (id) => {
|
|
32
|
+
if (isDebug) console.log('get', name, id)
|
|
33
|
+
return prisma[entity].findUnique({
|
|
34
|
+
where: {
|
|
35
|
+
id,
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
patch: (id, data) => {
|
|
41
|
+
if (isDebug) console.log('patch', name, id, data)
|
|
42
|
+
return prisma[entity].update({
|
|
43
|
+
where: {
|
|
44
|
+
id,
|
|
45
|
+
},
|
|
46
|
+
data,
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
remove: (id) => {
|
|
51
|
+
if (isDebug) console.log('remove', name, id)
|
|
52
|
+
return prisma[entity].delete({
|
|
53
|
+
where: {
|
|
54
|
+
id,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
find: (options) => {
|
|
60
|
+
if (isDebug) console.log('find', name, options)
|
|
61
|
+
return prisma[entity].findMany(options)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
upsert: (options) => {
|
|
65
|
+
if (isDebug) console.log('upsert', name, options)
|
|
66
|
+
return prisma[entity].upsert(options)
|
|
67
|
+
},
|
|
48
68
|
})
|
|
49
69
|
}
|
|
50
70
|
|
|
@@ -169,7 +189,7 @@ function expressX(app) {
|
|
|
169
189
|
}
|
|
170
190
|
// store connection in cache
|
|
171
191
|
connections[connection.id] = connection
|
|
172
|
-
if (isDebug) console.log('active connections',
|
|
192
|
+
if (isDebug) console.log('active connections', Object.keys(connections))
|
|
173
193
|
|
|
174
194
|
// emit 'connection' event for app (expressjs extends EventEmitter)
|
|
175
195
|
app.emit('connection', connection)
|
|
@@ -216,7 +236,7 @@ function expressX(app) {
|
|
|
216
236
|
if (isDebug) console.log('service-event', name, action, channelName)
|
|
217
237
|
const connectionList = Object.values(connections).filter(cnx => cnx.channelNames.has(channelName))
|
|
218
238
|
for (const connection of connectionList) {
|
|
219
|
-
if (isDebug) console.log('emit to', connection.id)
|
|
239
|
+
if (isDebug) console.log('emit to', connection.id, name, action, result)
|
|
220
240
|
connection.socket.emit('service-event', {
|
|
221
241
|
name,
|
|
222
242
|
action,
|