-
Notifications
You must be signed in to change notification settings - Fork 1
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
Update pinejs-client and make use of improved typings #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,15 +144,27 @@ export async function updateRelease( | |
id: number, | ||
body: Partial<models.ReleaseAttributes>, | ||
): Promise<void> { | ||
return models.update(api, 'release', id, body); | ||
await api | ||
.patch({ | ||
resource: 'release', | ||
id, | ||
body, | ||
} as const) | ||
.catch(models.wrapResponseError); | ||
} | ||
|
||
export async function updateImage( | ||
api: PinejsClientCore<unknown>, | ||
id: number, | ||
body: Partial<models.ImageAttributes>, | ||
): Promise<void> { | ||
return models.update(api, 'image', id, body); | ||
await api | ||
.patch({ | ||
resource: 'image', | ||
id, | ||
body, | ||
} as const) | ||
.catch(models.wrapResponseError); | ||
} | ||
|
||
// Helpers | ||
|
@@ -161,31 +173,62 @@ async function getUser( | |
api: PinejsClientCore<unknown>, | ||
id: number, | ||
): Promise<models.UserModel> { | ||
return models.get(api, 'user', id); | ||
const user = await api | ||
.get({ | ||
resource: 'user', | ||
id, | ||
options: { $select: 'id' }, | ||
} as const) | ||
.catch(models.wrapResponseError); | ||
if (user == null) { | ||
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. It could always be null but in the past it would have error'ed with something like |
||
throw new Error('Could not find user with id: ' + id); | ||
} | ||
return user; | ||
} | ||
|
||
async function getApplication( | ||
api: PinejsClientCore<unknown>, | ||
id: number, | ||
): Promise<models.ApplicationModel> { | ||
return models.get(api, 'application', id); | ||
const app = await api | ||
.get({ | ||
resource: 'application', | ||
id, | ||
options: { $select: 'id' }, | ||
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. This |
||
} as const) | ||
.catch(models.wrapResponseError); | ||
if (app == null) { | ||
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. It could always be null but in the past it would have error'ed with something like |
||
throw new Error('Could not find application with id: ' + id); | ||
} | ||
return app; | ||
} | ||
|
||
async function getOrCreateService( | ||
api: PinejsClientCore<unknown>, | ||
body: models.ServiceAttributes, | ||
): Promise<models.ServiceModel> { | ||
return models.getOrCreate(api, 'service', body, { | ||
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. I replaced this with the built in |
||
application: body.application, | ||
service_name: body.service_name, | ||
}); | ||
return (await api | ||
.getOrCreate({ | ||
resource: 'service', | ||
id: { | ||
application: body.application, | ||
service_name: body.service_name, | ||
}, | ||
body, | ||
} as const) | ||
.catch(models.wrapResponseError)) as models.ServiceModel; | ||
} | ||
|
||
async function createRelease( | ||
api: PinejsClientCore<unknown>, | ||
body: models.ReleaseAttributes, | ||
): Promise<models.ReleaseModel> { | ||
return models.create(api, 'release', body); | ||
return (await api | ||
.post({ | ||
resource: 'release', | ||
body, | ||
}) | ||
.catch(models.wrapResponseError)) as models.ReleaseModel; | ||
} | ||
|
||
async function createImage( | ||
|
@@ -195,29 +238,37 @@ async function createImage( | |
envvars: Dict<string> | undefined, | ||
body: models.ImageAttributes, | ||
): Promise<models.ImageModel> { | ||
const image = await models.create<models.ImageModel, models.ImageAttributes>( | ||
api, | ||
'image', | ||
body, | ||
); | ||
|
||
const releaseImage = await models.create< | ||
models.ReleaseImageModel, | ||
models.ReleaseImageAttributes | ||
>(api, 'image__is_part_of__release', { | ||
is_part_of__release: release, | ||
image: image.id, | ||
}); | ||
const image = (await api | ||
.post({ | ||
resource: 'image', | ||
body, | ||
} as const) | ||
.catch(models.wrapResponseError)) as models.ImageModel; | ||
|
||
const releaseImage = (await api | ||
.post({ | ||
resource: 'image__is_part_of__release', | ||
body: { | ||
is_part_of__release: release, | ||
image: image.id, | ||
}, | ||
} as const) | ||
.catch(models.wrapResponseError)) as models.ReleaseImageModel; | ||
|
||
if (labels) { | ||
await pMap( | ||
Object.entries(labels), | ||
([name, value]) => { | ||
return models.create(api, 'image_label', { | ||
release_image: releaseImage.id, | ||
label_name: name, | ||
value: (value || '').toString(), | ||
}); | ||
async ([name, value]) => { | ||
await api | ||
.post({ | ||
resource: 'image_label', | ||
body: { | ||
release_image: releaseImage.id, | ||
label_name: name, | ||
value: (value || '').toString(), | ||
}, | ||
} as const) | ||
.catch(models.wrapResponseError); | ||
}, | ||
{ | ||
concurrency: MAX_CONCURRENT_REQUESTS, | ||
|
@@ -228,12 +279,17 @@ async function createImage( | |
if (envvars) { | ||
await pMap( | ||
Object.entries(envvars), | ||
([name, value]) => { | ||
return models.create(api, 'image_environment_variable', { | ||
release_image: releaseImage.id, | ||
name, | ||
value: (value || '').toString(), | ||
}); | ||
async ([name, value]) => { | ||
await api | ||
.post({ | ||
resource: 'image_environment_variable', | ||
body: { | ||
release_image: releaseImage.id, | ||
name, | ||
value: (value || '').toString(), | ||
}, | ||
} as const) | ||
.catch(models.wrapResponseError); | ||
}, | ||
{ | ||
concurrency: MAX_CONCURRENT_REQUESTS, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
$select
was previously missing