platformatic 0.11.0 → 0.12.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/.taprc +1 -0
- package/cli.js +24 -19
- package/fixtures/sqlite/db +0 -0
- package/fixtures/sqlite/migrations/001.do.sql +4 -0
- package/fixtures/sqlite/migrations/001.undo.sql +1 -0
- package/fixtures/sqlite/platformatic.db.json +17 -0
- package/package.json +11 -10
- package/test/platformatic.test.js +101 -1
package/.taprc
CHANGED
package/cli.js
CHANGED
|
@@ -12,22 +12,31 @@ import helpMe from 'help-me'
|
|
|
12
12
|
|
|
13
13
|
import { logo } from './lib/ascii.js'
|
|
14
14
|
|
|
15
|
-
const program = commist()
|
|
15
|
+
const program = commist({ maxDistance: 2 })
|
|
16
16
|
const help = helpMe({
|
|
17
17
|
dir: join(import.meta.url, 'help'),
|
|
18
18
|
// the default
|
|
19
19
|
ext: '.txt'
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const ensureCommand = async ({ output, help }) => {
|
|
23
|
+
if (!output) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (output.length) {
|
|
28
|
+
console.log('Command not found:', output.join(' '), '\n')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await help.toStdout()
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
program.register('db', async (args) => ensureCommand(await runDB(args)))
|
|
36
|
+
program.register('service', async (args) => ensureCommand(await runService(args)))
|
|
24
37
|
program.register('help', help.toStdout)
|
|
25
|
-
program.register('help db',
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
program.register('help service', function (args) {
|
|
29
|
-
runService(['help', ...args])
|
|
30
|
-
})
|
|
38
|
+
program.register('help db', async (args) => runDB(['help', ...args]))
|
|
39
|
+
program.register('help service', async (args) => runService(['help', ...args]))
|
|
31
40
|
program.register({ command: 'login', strict: true }, login)
|
|
32
41
|
|
|
33
42
|
const args = minimist(process.argv.slice(2), {
|
|
@@ -45,19 +54,15 @@ if (args.version) {
|
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
if (args.help) {
|
|
48
|
-
help.toStdout(['help'])
|
|
57
|
+
await help.toStdout(['help'])
|
|
49
58
|
} else if (process.argv.length > 2) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
console.log('Command not found:', result.join(' '))
|
|
54
|
-
process.exit(1)
|
|
55
|
-
}
|
|
59
|
+
const output = await program.parseAsync(process.argv.slice(2))
|
|
60
|
+
await ensureCommand({ output, help })
|
|
61
|
+
/* c8 ignore start */
|
|
56
62
|
} else {
|
|
57
|
-
/* c8 ignore next 3 */
|
|
58
63
|
if (isColorSupported && process.stdout.isTTY) {
|
|
59
64
|
console.log(logo)
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
help.toStdout(['help'])
|
|
66
|
+
await help.toStdout(['help'])
|
|
63
67
|
}
|
|
68
|
+
/* c8 ignore stop */
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DROP TABLE graphs;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"server": {
|
|
3
|
+
"hostname": "127.0.0.1",
|
|
4
|
+
"port": 0,
|
|
5
|
+
"logger": {
|
|
6
|
+
"level": "info"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"core": {
|
|
10
|
+
"connectionString": "sqlite://./db"
|
|
11
|
+
},
|
|
12
|
+
"migrations": {
|
|
13
|
+
"dir": "./migrations",
|
|
14
|
+
"table": "versions",
|
|
15
|
+
"autoApply": true
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Platformatic CLI",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,22 +27,23 @@
|
|
|
27
27
|
"mercurius"
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"c8": "^7.
|
|
30
|
+
"c8": "^7.12.0",
|
|
31
|
+
"desm": "^1.3.0",
|
|
31
32
|
"execa": "^6.1.0",
|
|
32
33
|
"snazzy": "^9.0.0",
|
|
33
34
|
"split2": "^4.1.0",
|
|
34
35
|
"standard": "^17.0.0",
|
|
35
|
-
"tap": "^16.
|
|
36
|
+
"tap": "^16.3.2",
|
|
37
|
+
"undici": "^5.14.0"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"colorette": "^2.0.19",
|
|
39
|
-
"commist": "^3.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"@platformatic/
|
|
44
|
-
"@platformatic/
|
|
45
|
-
"@platformatic/service": "0.11.0"
|
|
41
|
+
"commist": "^3.2.0",
|
|
42
|
+
"help-me": "^4.2.0",
|
|
43
|
+
"minimist": "^1.2.7",
|
|
44
|
+
"@platformatic/authenticate": "0.12.0",
|
|
45
|
+
"@platformatic/db": "0.12.0",
|
|
46
|
+
"@platformatic/service": "0.12.0"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"test": "standard | snazzy && c8 --100 tap --no-coverage test/*.test.js"
|
|
@@ -4,6 +4,17 @@ import { readFile } from 'fs/promises'
|
|
|
4
4
|
import { execa } from 'execa'
|
|
5
5
|
import { cliPath } from './helper.js'
|
|
6
6
|
import { EOL } from 'os'
|
|
7
|
+
import { Agent, setGlobalDispatcher, request } from 'undici'
|
|
8
|
+
import split from 'split2'
|
|
9
|
+
import { on } from 'events'
|
|
10
|
+
|
|
11
|
+
setGlobalDispatcher(new Agent({
|
|
12
|
+
keepAliveTimeout: 10,
|
|
13
|
+
keepAliveMaxTimeout: 10,
|
|
14
|
+
tls: {
|
|
15
|
+
rejectUnauthorized: false
|
|
16
|
+
}
|
|
17
|
+
}))
|
|
7
18
|
|
|
8
19
|
const version = JSON.parse(await readFile(join(import.meta.url, '..', 'package.json'))).version
|
|
9
20
|
const help = await readFile(join(import.meta.url, '..', 'help', 'help.txt'), 'utf8')
|
|
@@ -21,7 +32,7 @@ test('version', async (t) => {
|
|
|
21
32
|
|
|
22
33
|
test('db', async (t) => {
|
|
23
34
|
try {
|
|
24
|
-
await execa('node', [cliPath, 'db'])
|
|
35
|
+
await execa('node', [cliPath, 'db', 'start'])
|
|
25
36
|
t.fail('bug')
|
|
26
37
|
} catch (err) {
|
|
27
38
|
t.ok(err.stderr.includes('Missing config file'))
|
|
@@ -46,6 +57,34 @@ test('command not found', async (t) => {
|
|
|
46
57
|
}
|
|
47
58
|
})
|
|
48
59
|
|
|
60
|
+
test('subcommand not found', async (t) => {
|
|
61
|
+
try {
|
|
62
|
+
const rv = await execa('node', [cliPath, 'db', 'subfoo'])
|
|
63
|
+
console.log(rv.stdout)
|
|
64
|
+
t.fail('bug')
|
|
65
|
+
} catch (err) {
|
|
66
|
+
t.ok(err.stdout.includes('Command not found: subfoo'))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('allows for minor typos in commands', async (t) => {
|
|
71
|
+
try {
|
|
72
|
+
await execa('node', [cliPath, 'dbx', 'start'])
|
|
73
|
+
t.fail('bug')
|
|
74
|
+
} catch (err) {
|
|
75
|
+
t.ok(err.stderr.includes('Missing config file'))
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('prints the help if command requires a subcommand', async (t) => {
|
|
80
|
+
try {
|
|
81
|
+
await execa('node', [cliPath, 'db'])
|
|
82
|
+
t.fail('bug')
|
|
83
|
+
} catch (err) {
|
|
84
|
+
t.equal(err.stdout + EOL, helpDB)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
49
88
|
test('prints the help with help command', async (t) => {
|
|
50
89
|
const { stdout } = await execa('node', [cliPath, 'help'])
|
|
51
90
|
t.equal(stdout + EOL, help)
|
|
@@ -70,3 +109,64 @@ test('prints the help of service', async (t) => {
|
|
|
70
109
|
const { stdout } = await execa('node', [cliPath, 'help', 'service'])
|
|
71
110
|
t.equal(stdout + EOL, helpService)
|
|
72
111
|
})
|
|
112
|
+
|
|
113
|
+
async function start (...args) {
|
|
114
|
+
const { execa } = await import('execa')
|
|
115
|
+
const child = execa('node', [cliPath, ...args])
|
|
116
|
+
child.stderr.pipe(process.stdout)
|
|
117
|
+
const output = child.stdout.pipe(split(function (line) {
|
|
118
|
+
try {
|
|
119
|
+
const obj = JSON.parse(line)
|
|
120
|
+
return obj
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.log(line)
|
|
123
|
+
}
|
|
124
|
+
}))
|
|
125
|
+
child.ndj = output
|
|
126
|
+
|
|
127
|
+
const errorTimeout = setTimeout(() => {
|
|
128
|
+
throw new Error('Couldn\'t start server')
|
|
129
|
+
}, 10000)
|
|
130
|
+
|
|
131
|
+
for await (const messages of on(output, 'data')) {
|
|
132
|
+
for (const message of messages) {
|
|
133
|
+
const url = message.url
|
|
134
|
+
if (url !== undefined) {
|
|
135
|
+
clearTimeout(errorTimeout)
|
|
136
|
+
return { child, url, output }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
test('start the database and do a call', async ({ teardown, equal, match }) => {
|
|
143
|
+
const config = join(import.meta.url, '..', 'fixtures/sqlite/platformatic.db.json')
|
|
144
|
+
const { child, url } = await start('db', 'start', '-c', config)
|
|
145
|
+
teardown(() => {
|
|
146
|
+
child.kill('SIGINT')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const res = await request(`${url}/graphql`, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: { 'Content-Type': 'application/json' },
|
|
152
|
+
body: JSON.stringify({
|
|
153
|
+
query: `
|
|
154
|
+
mutation {
|
|
155
|
+
saveGraph(input: { name: "Hello" }) {
|
|
156
|
+
id
|
|
157
|
+
name
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
`
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
equal(res.statusCode, 200, 'saveGraph status code')
|
|
164
|
+
const body = await res.body.json()
|
|
165
|
+
match(body, {
|
|
166
|
+
data: {
|
|
167
|
+
saveGraph: {
|
|
168
|
+
name: 'Hello'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, 'saveGraph response')
|
|
172
|
+
})
|