From e0ab3ef95f8bc51d2e9055a1f822b8d340f0c587 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 10 Nov 2023 16:12:07 +0200 Subject: [PATCH] Allow injecting any PinejsClientCore compatible API client Change-type: minor --- lib/release/api.ts | 17 +++++++++-------- lib/release/models.ts | 18 +++++++++++------- package.json | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/release/api.ts b/lib/release/api.ts index 3928e94..4775989 100644 --- a/lib/release/api.ts +++ b/lib/release/api.ts @@ -1,4 +1,5 @@ import pMap = require('p-map'); +import type { PinejsClientCore } from 'pinejs-client-core'; import { PinejsClientRequest } from 'pinejs-client-request'; import * as models from './models'; import { Dict } from './types'; @@ -54,7 +55,7 @@ export interface Request { * You can use the `createClient` convenience function of this module to create * a client that can reused across requests. */ - client: PinejsClientRequest; + client: PinejsClientCore; /** * The ID of the user the release should belong to. The user authenticated via `client` @@ -169,7 +170,7 @@ export async function create(req: Request): Promise { } export async function updateRelease( - api: PinejsClientRequest, + api: PinejsClientCore, id: number, body: Partial, ): Promise { @@ -177,7 +178,7 @@ export async function updateRelease( } export async function updateImage( - api: PinejsClientRequest, + api: PinejsClientCore, id: number, body: Partial, ): Promise { @@ -187,21 +188,21 @@ export async function updateImage( // Helpers async function getUser( - api: PinejsClientRequest, + api: PinejsClientCore, id: number, ): Promise { return models.get(api, 'user', id); } async function getApplication( - api: PinejsClientRequest, + api: PinejsClientCore, id: number, ): Promise { return models.get(api, 'application', id); } async function getOrCreateService( - api: PinejsClientRequest, + api: PinejsClientCore, body: models.ServiceAttributes, ): Promise { return models.getOrCreate(api, 'service', body, { @@ -211,14 +212,14 @@ async function getOrCreateService( } async function createRelease( - api: PinejsClientRequest, + api: PinejsClientCore, body: models.ReleaseAttributes, ): Promise { return models.create(api, 'release', body); } async function createImage( - api: PinejsClientRequest, + api: PinejsClientCore, release: number, labels: Dict | undefined, envvars: Dict | undefined, diff --git a/lib/release/models.ts b/lib/release/models.ts index 27cbf23..37ea1cb 100644 --- a/lib/release/models.ts +++ b/lib/release/models.ts @@ -1,5 +1,9 @@ -import type { PinejsClientRequest } from 'pinejs-client-request'; -import type { Expand, Filter, ODataOptions } from 'pinejs-client-core'; +import type { + Expand, + Filter, + ODataOptions, + PinejsClientCore, +} from 'pinejs-client-core'; import type { Composition } from '../../lib/parse'; @@ -96,7 +100,7 @@ export interface ReleaseImageModel extends ReleaseImageAttributesBase { // Helpers export function getOrCreate( - api: PinejsClientRequest, + api: PinejsClientCore, resource: string, body: U, filter: V, @@ -115,7 +119,7 @@ export function getOrCreate( } export function create( - api: PinejsClientRequest, + api: PinejsClientCore, resource: string, body: U, ): Promise { @@ -123,7 +127,7 @@ export function create( } export function update( - api: PinejsClientRequest, + api: PinejsClientCore, resource: string, id: number, body: T, @@ -132,7 +136,7 @@ export function update( } export function find( - api: PinejsClientRequest, + api: PinejsClientCore, resource: string, options: ODataOptions, ): Promise { @@ -142,7 +146,7 @@ export function find( } export function get( - api: PinejsClientRequest, + api: PinejsClientCore, resource: string, id: number, expand?: Expand, diff --git a/package.json b/package.json index a57850f..c08739c 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "memoizee": "^0.4.15", "mz": "^2.7.0", "p-map": "^4.0.0", + "pinejs-client-core": "^6.13.0", "pinejs-client-request": "^7.3.5", "request": "^2.88.2", "semver": "^7.3.5",