forked from supabase/fly-preview
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Upstream changes from Aspen Cloud #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matlin
wants to merge
24
commits into
supabase:main
Choose a base branch
from
aspen-cloud:upstream-to-supabase
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7ba8b94
update cross-fetch dependency to v4, bump version and add publish com…
wernst eebd256
update return type of API methods to {data, error}
wernst ff62db3
bump version
wernst da06f91
add machines to app detail response
wernst a909f95
bump version
wernst 1751462
Add lease deletion and using lease for updates
matlin ae0853a
Update types
matlin f40a532
Bump minor version
matlin f3cc555
NPM audit fix
matlin 5c927cf
Restore version
matlin b2bb276
1.7.0
matlin d399cde
Fix deleteLease path
matlin 0dc22f6
1.7.1
matlin 4d96913
add method for detailed app list
wernst 456e693
fixup typo
wernst 5cd5ad0
return apps array from listAppsDetailed
wernst 699aa8d
fixup types
wernst 28f608e
bump version
wernst b2c485c
fix naming
wernst 4edb135
Update package.json
IvanLisz 9a4d0b7
Merge pull request #1 from IvanLisz/main
wernst 68044c0
Reset package.json metadata to match upstream
matlin f34099f
Apply suggestion from @sweatybridge
matlin 59a7162
Apply suggestion from @sweatybridge
matlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import Client from '../client' | ||
| import { APIResponse } from './utils' | ||
|
|
||
| export type ListAppRequest = string | ||
|
|
||
|
|
@@ -11,9 +12,43 @@ export interface ListAppResponse { | |
| }[] | ||
| } | ||
|
|
||
| export interface ListAppDetailedResponse { | ||
| apps: AppDetailedResponse[] | ||
| } | ||
|
|
||
| export type GetAppRequest = string | ||
|
|
||
| const getAppQuery = `query($name: String!) { | ||
| const getOrganizationAppsDetailedQuery = `query($slug: String!) { | ||
| organization(slug: $slug) { | ||
| apps { | ||
| nodes { | ||
| name | ||
| status | ||
| organization { | ||
| name | ||
| slug | ||
| } | ||
| ipAddresses { | ||
| nodes { | ||
| type | ||
| region | ||
| address | ||
matlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| machines { | ||
| nodes { | ||
| id | ||
| name | ||
| state | ||
| region | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }` | ||
|
|
||
| const getAppDetailedQuery = `query($name: String!) { | ||
| app(name: $name) { | ||
| name | ||
| status | ||
|
|
@@ -28,6 +63,14 @@ const getAppQuery = `query($name: String!) { | |
| address | ||
| } | ||
| } | ||
| machines { | ||
| nodes { | ||
| id | ||
| name | ||
| state | ||
| region | ||
| } | ||
| } | ||
| } | ||
| }` | ||
|
|
||
|
|
@@ -44,7 +87,18 @@ export interface AppResponse { | |
| name: string | ||
| slug: string | ||
| } | ||
| } | ||
|
|
||
| export interface AppDetailedResponse extends AppResponse { | ||
| ipAddresses: IPAddress[] | ||
| machines: AppMachine[] | ||
| } | ||
|
|
||
| export interface AppMachine { | ||
| id: string | ||
| name: string | ||
| state: string | ||
| region: string | ||
| } | ||
|
|
||
| export interface IPAddress { | ||
|
|
@@ -67,37 +121,85 @@ export class App { | |
| this.client = client | ||
| } | ||
|
|
||
| async listApps(org_slug: ListAppRequest): Promise<ListAppResponse> { | ||
| async listApps( | ||
| org_slug: ListAppRequest | ||
| ): Promise<APIResponse<ListAppResponse>> { | ||
| const path = `apps?org_slug=${org_slug}` | ||
| return await this.client.restOrThrow(path) | ||
| return await this.client.safeRest(path) | ||
| } | ||
|
|
||
| async getApp(app_name: GetAppRequest): Promise<AppResponse> { | ||
| async listAppsDetailed( | ||
| org_slug: ListAppRequest | ||
| ): Promise<APIResponse<ListAppDetailedResponse>> { | ||
| const response = await this.client.safeGqlPost< | ||
| string, | ||
| { organization: any } | ||
| >({ | ||
| query: getOrganizationAppsDetailedQuery, | ||
| variables: { slug: org_slug }, | ||
| }) | ||
| if (response.error) { | ||
| return response | ||
| } | ||
| return { | ||
| data: parseOrgResponse(response.data.organization).apps, | ||
| error: undefined, | ||
| } | ||
| } | ||
|
|
||
| async getApp(app_name: GetAppRequest): Promise<APIResponse<AppResponse>> { | ||
| const path = `apps/${app_name}` | ||
| return await this.client.restOrThrow(path) | ||
| return await this.client.safeRest(path) | ||
| } | ||
|
|
||
| async getAppDetailed(app_name: GetAppRequest): Promise<AppResponse> { | ||
| const { app } = await this.client.gqlPostOrThrow({ | ||
| query: getAppQuery, | ||
| async getAppDetailed( | ||
| app_name: GetAppRequest | ||
| ): Promise<APIResponse<AppDetailedResponse>> { | ||
| const response = await this.client.safeGqlPost<string, { app: any }>({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid typing |
||
| query: getAppDetailedQuery, | ||
| variables: { name: app_name }, | ||
| }) as { app: AppResponse } | ||
| }) | ||
|
|
||
| const ipAddresses = app.ipAddresses as unknown as { nodes: IPAddress[] } | ||
| if (response.error) { | ||
| return response | ||
| } | ||
|
|
||
| return { | ||
| ...app, | ||
| ipAddresses: ipAddresses.nodes, | ||
| data: parseAppResponse(response.data.app), | ||
| error: undefined, | ||
| } | ||
| } | ||
|
|
||
| async createApp(payload: CreateAppRequest): Promise<void> { | ||
| async createApp(payload: CreateAppRequest): Promise<APIResponse<void>> { | ||
| const path = 'apps' | ||
| return await this.client.restOrThrow(path, 'POST', payload) | ||
| return await this.client.safeRest(path, 'POST', payload) | ||
| } | ||
|
|
||
| async deleteApp(app_name: DeleteAppRequest): Promise<void> { | ||
| async deleteApp(app_name: DeleteAppRequest): Promise<APIResponse<void>> { | ||
| const path = `apps/${app_name}` | ||
| return await this.client.restOrThrow(path, 'DELETE') | ||
| return await this.client.safeRest(path, 'DELETE') | ||
| } | ||
| } | ||
|
|
||
| function parseAppResponse(appData: any) { | ||
| const ipAddresses = parseNodes<IPAddress>(appData, 'ipAddresses') | ||
| const machines = parseNodes<AppMachine>(appData, 'machines') | ||
|
|
||
| return { | ||
| ...appData, | ||
| ipAddresses, | ||
| machines, | ||
| } | ||
| } | ||
|
|
||
| function parseOrgResponse(orgData: any) { | ||
| const apps = parseNodes(orgData, 'apps').map(parseAppResponse) | ||
| return { | ||
| ...orgData, | ||
| apps, | ||
| } | ||
| } | ||
|
|
||
| function parseNodes<T>(data: any, key: string): T[] { | ||
| return data[key].nodes | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.