Skip to content

Commit b02a901

Browse files
committed
feat: add generated types and more machine apis
1 parent f761aa7 commit b02a901

15 files changed

+1198
-405
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ async function deployApp() {
3737
- `fly.Machine.updateMachine()`
3838
- `fly.Machine.startMachine()`
3939
- `fly.Machine.stopMachine()`
40-
- `fly.Machine.restartMachine()`
4140
- `fly.Machine.deleteMachine()`
41+
- `fly.Machine.restartMachine()`
42+
- `fly.Machine.signalMachine()`
43+
- `fly.Machine.waitMachine()`
44+
- `fly.Machine.cordonMachine()`
45+
- `fly.Machine.uncordonMachine()`
46+
- `fly.Machine.listEvents()`
47+
- `fly.Machine.listVersions()`
48+
- `fly.Machine.listProcesses()`
49+
- `fly.Machine.getLease()`
50+
- `fly.Machine.acquireLease()`
4251

4352
**Networks**
4453

@@ -61,6 +70,15 @@ async function deployApp() {
6170
- `fly.Volume.createVolume()`
6271
- `fly.Volume.deleteVolume()`
6372
- `fly.Volume.extendVolume()`
73+
- `fly.Volume.listSnapshots()`
74+
75+
**TODO**
76+
77+
- [ ] `fly.Machine.execMachine()`
78+
- [ ] `fly.Machine.releaseLease()`
79+
- [ ] `fly.Machine.getMetadata()`
80+
- [ ] `fly.Machine.updateMetadata()`
81+
- [ ] `fly.Machine.deleteMetadata()`
6482

6583
## License
6684

__tests__/app.test.ts

+44-66
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,61 @@
11
import nock from 'nock'
22
import { describe, it } from '@jest/globals'
3-
import { FLY_API_GRAPHQL } from '../src/client'
3+
import { FLY_API_HOSTNAME } from '../src/client'
44
import { createClient } from '../src/main'
5+
import { AppResponse, AppStatus } from '../src/lib/app'
56

6-
const fly = createClient('test-token')
7+
const fly = createClient(process.env.FLY_API_TOKEN || 'test-token')
78

89
describe('app', () => {
9-
const organizationId = 'personal'
10+
const app: AppResponse = {
11+
name: 'fly-app',
12+
status: AppStatus.deployed,
13+
organization: {
14+
name: 'fly-org',
15+
slug: 'personal',
16+
},
17+
}
1018

11-
it('creates app', async () => {
12-
nock(FLY_API_GRAPHQL)
13-
.post('/graphql')
19+
it('lists apps', async () => {
20+
const org_slug = app.organization.slug
21+
nock(FLY_API_HOSTNAME)
22+
.get('/v1/apps')
23+
.query({ org_slug })
1424
.reply(200, {
15-
data: {
16-
createApp: {
17-
app: {
18-
id: 'ctwntjgykzxhfncfwrfo',
19-
name: 'ctwntjgykzxhfncfwrfo',
20-
organization: { slug: 'supabase-dev' },
21-
config: {
22-
definition: {
23-
kill_timeout: 5,
24-
kill_signal: 'SIGINT',
25-
processes: [],
26-
experimental: { auto_rollback: true },
27-
services: [
28-
{
29-
processes: ['app'],
30-
protocol: 'tcp',
31-
internal_port: 8080,
32-
concurrency: {
33-
soft_limit: 20,
34-
hard_limit: 25,
35-
type: 'connections',
36-
},
37-
ports: [
38-
{ port: 80, handlers: ['http'], force_https: true },
39-
{ port: 443, handlers: ['tls', 'http'] },
40-
],
41-
tcp_checks: [
42-
{
43-
interval: '15s',
44-
timeout: '2s',
45-
grace_period: '1s',
46-
restart_limit: 0,
47-
},
48-
],
49-
http_checks: [],
50-
script_checks: [],
51-
},
52-
],
53-
env: {},
54-
},
55-
},
56-
regions: [{ name: 'Hong Kong, Hong Kong', code: 'hkg' }],
57-
},
25+
total_apps: 1,
26+
apps: [
27+
{
28+
name: app.name,
29+
machine_count: 1,
30+
network: 'default',
5831
},
59-
},
32+
],
6033
})
61-
const data = await fly.App.createApp({
62-
name: 'ctwntjgykzxhfncfwrfo',
63-
organizationId,
64-
})
34+
const data = await fly.App.listApps(org_slug)
35+
console.dir(data, { depth: 10 })
36+
})
37+
38+
it('get app', async () => {
39+
const app_name = app.name
40+
nock(FLY_API_HOSTNAME).get(`/v1/apps/${app_name}`).reply(200, app)
41+
const data = await fly.App.getApp(app_name)
42+
console.dir(data, { depth: 10 })
43+
})
44+
45+
it('creates app', async () => {
46+
const body = {
47+
org_slug: app.organization.slug,
48+
app_name: app.name,
49+
}
50+
nock(FLY_API_HOSTNAME).post('/v1/apps', body).reply(201)
51+
const data = await fly.App.createApp(body)
6552
console.dir(data, { depth: 10 })
6653
})
6754

6855
it('deletes app', async () => {
69-
nock(FLY_API_GRAPHQL)
70-
.post('/graphql')
71-
.reply(200, {
72-
data: {
73-
deleteApp: {
74-
organization: {
75-
id: organizationId,
76-
},
77-
},
78-
},
79-
})
80-
const data = await fly.App.deleteApp('ctwntjgykzxhfncfwrfo')
56+
const app_name = app.name
57+
nock(FLY_API_HOSTNAME).delete(`/v1/apps/${app_name}`).reply(202)
58+
const data = await fly.App.deleteApp(app_name)
8159
console.dir(data, { depth: 10 })
8260
})
8361
})

0 commit comments

Comments
 (0)