@platformatic/db-core 0.4.0 → 0.5.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 +21 -13
- package/package.json +7 -5
- package/test/basic.test.js +47 -0
- package/test/helper.js +0 -10
package/index.js
CHANGED
|
@@ -3,26 +3,34 @@
|
|
|
3
3
|
const fp = require('fastify-plugin')
|
|
4
4
|
const sqlMapper = require('@platformatic/sql-mapper')
|
|
5
5
|
|
|
6
|
+
const defaults = [{
|
|
7
|
+
module: '@platformatic/sql-events',
|
|
8
|
+
configKey: 'events'
|
|
9
|
+
}, {
|
|
10
|
+
module: '@platformatic/sql-graphql',
|
|
11
|
+
configKey: 'graphql'
|
|
12
|
+
}, {
|
|
13
|
+
module: '@platformatic/sql-openapi',
|
|
14
|
+
configKey: 'openapi'
|
|
15
|
+
}]
|
|
16
|
+
|
|
6
17
|
module.exports = fp(async function (app, opts) {
|
|
7
18
|
app.register(sqlMapper, {
|
|
8
19
|
...opts
|
|
9
20
|
})
|
|
10
21
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const graphqlConfig = typeof opts.graphql === 'object' ? opts.graphql : {}
|
|
14
|
-
app.register(sqlGraphQL, {
|
|
15
|
-
...graphqlConfig
|
|
16
|
-
})
|
|
22
|
+
for (const obj of defaults) {
|
|
23
|
+
registerAndConfig(obj)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
function registerAndConfig ({ module, configKey }) {
|
|
27
|
+
if (opts[configKey] !== false) {
|
|
28
|
+
const sqlModule = require(module)
|
|
29
|
+
const config = typeof opts[configKey] === 'object' ? opts[configKey] : {}
|
|
30
|
+
return app.register(sqlModule, {
|
|
31
|
+
...config
|
|
32
|
+
})
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
})
|
|
28
36
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/db-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
"mercurius": "^11.0.0",
|
|
19
19
|
"snazzy": "^9.0.0",
|
|
20
20
|
"standard": "^17.0.0",
|
|
21
|
-
"tap": "^16.0.0"
|
|
21
|
+
"tap": "^16.0.0",
|
|
22
|
+
"why-is-node-running": "^2.2.2"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@platformatic/sql-
|
|
25
|
-
"@platformatic/sql-
|
|
26
|
-
"@platformatic/sql-
|
|
25
|
+
"@platformatic/sql-events": "0.5.1",
|
|
26
|
+
"@platformatic/sql-graphql": "0.5.1",
|
|
27
|
+
"@platformatic/sql-mapper": "0.5.1",
|
|
28
|
+
"@platformatic/sql-openapi": "0.5.1",
|
|
27
29
|
"fastify-plugin": "^4.1.0"
|
|
28
30
|
},
|
|
29
31
|
"scripts": {
|
package/test/basic.test.js
CHANGED
|
@@ -4,6 +4,7 @@ const { test } = require('tap')
|
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const { clear, connInfo } = require('./helper')
|
|
6
6
|
const core = require('..')
|
|
7
|
+
const { once } = require('events')
|
|
7
8
|
|
|
8
9
|
async function createBasicPages (db, sql) {
|
|
9
10
|
if (module.exports.isSQLite) {
|
|
@@ -159,3 +160,49 @@ test('openapi with an object', async ({ equal, teardown }) => {
|
|
|
159
160
|
})
|
|
160
161
|
equal(res.statusCode, 200, '/pages status code')
|
|
161
162
|
})
|
|
163
|
+
|
|
164
|
+
test('mq is available', async ({ equal, same, teardown }) => {
|
|
165
|
+
const app = Fastify()
|
|
166
|
+
await app.register(core, {
|
|
167
|
+
...connInfo,
|
|
168
|
+
events: true,
|
|
169
|
+
onDatabaseLoad
|
|
170
|
+
})
|
|
171
|
+
teardown(() => app.close())
|
|
172
|
+
|
|
173
|
+
const queue = await app.platformatic.subscribe([
|
|
174
|
+
await app.platformatic.entities.page.getSubscriptionTopic({ action: 'save' })
|
|
175
|
+
])
|
|
176
|
+
|
|
177
|
+
const res = await app.inject({
|
|
178
|
+
method: 'POST',
|
|
179
|
+
url: '/graphql',
|
|
180
|
+
body: {
|
|
181
|
+
query: `
|
|
182
|
+
mutation {
|
|
183
|
+
savePage(input: { title: "Hello" }) {
|
|
184
|
+
id
|
|
185
|
+
title
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
`
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
equal(res.statusCode, 200, 'savePage status code')
|
|
192
|
+
same(res.json(), {
|
|
193
|
+
data: {
|
|
194
|
+
savePage: {
|
|
195
|
+
id: 1,
|
|
196
|
+
title: 'Hello'
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, 'savePage response')
|
|
200
|
+
|
|
201
|
+
const [ev] = await once(queue, 'data')
|
|
202
|
+
same(ev, {
|
|
203
|
+
topic: '/entity/page/save/1',
|
|
204
|
+
payload: {
|
|
205
|
+
id: 1
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
})
|
package/test/helper.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const why = require('why-is-node-running')
|
|
4
|
-
const { Agent, setGlobalDispatcher } = require('undici')
|
|
5
4
|
|
|
6
5
|
// This file must be required/imported as the first file
|
|
7
6
|
// in the test suite. It sets up the global environment
|
|
@@ -10,15 +9,6 @@ setInterval(() => {
|
|
|
10
9
|
why()
|
|
11
10
|
}, 10000).unref()
|
|
12
11
|
|
|
13
|
-
const agent = new Agent({
|
|
14
|
-
keepAliveTimeout: 10,
|
|
15
|
-
keepAliveMaxTimeout: 10,
|
|
16
|
-
tls: {
|
|
17
|
-
rejectUnauthorized: false
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
setGlobalDispatcher(agent)
|
|
21
|
-
|
|
22
12
|
// Needed to work with dates & postgresql
|
|
23
13
|
// See https://node-postgres.com/features/types/
|
|
24
14
|
process.env.TZ = 'UTC'
|