fix type check for deleted app type
This commit is contained in:
parent
567c7fd485
commit
108d18df75
|
@ -5,6 +5,11 @@ import { Database, App } from "@budibase/types"
|
||||||
export enum AppState {
|
export enum AppState {
|
||||||
INVALID = "invalid",
|
INVALID = "invalid",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DeletedApp {
|
||||||
|
state: AppState
|
||||||
|
}
|
||||||
|
|
||||||
const EXPIRY_SECONDS = 3600
|
const EXPIRY_SECONDS = 3600
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,10 +29,6 @@ function isInvalid(metadata?: { state: string }) {
|
||||||
return !metadata || metadata.state === AppState.INVALID
|
return !metadata || metadata.state === AppState.INVALID
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DeletedAppMetadata {
|
|
||||||
state: AppState
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the requested app metadata by id.
|
* Get the requested app metadata by id.
|
||||||
* Use redis cache to first read the app metadata.
|
* Use redis cache to first read the app metadata.
|
||||||
|
@ -35,9 +36,7 @@ interface DeletedAppMetadata {
|
||||||
* @param {string} appId the id of the app to get metadata from.
|
* @param {string} appId the id of the app to get metadata from.
|
||||||
* @returns {object} the app metadata.
|
* @returns {object} the app metadata.
|
||||||
*/
|
*/
|
||||||
export async function getAppMetadata(
|
export async function getAppMetadata(appId: string): Promise<App | DeletedApp> {
|
||||||
appId: string
|
|
||||||
): Promise<App | DeletedAppMetadata> {
|
|
||||||
const client = await getAppClient()
|
const client = await getAppClient()
|
||||||
// try cache
|
// try cache
|
||||||
let metadata = await client.get(appId)
|
let metadata = await client.get(appId)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import env from "../environment"
|
||||||
import { DEFAULT_TENANT_ID, SEPARATOR, DocumentType } from "../constants"
|
import { DEFAULT_TENANT_ID, SEPARATOR, DocumentType } from "../constants"
|
||||||
import { getTenantId, getGlobalDBName } from "../context"
|
import { getTenantId, getGlobalDBName } from "../context"
|
||||||
import { doWithDB, directCouchAllDbs } from "./db"
|
import { doWithDB, directCouchAllDbs } from "./db"
|
||||||
import { AppState, getAppMetadata } from "../cache/appMetadata"
|
import { AppState, DeletedApp, getAppMetadata } from "../cache/appMetadata"
|
||||||
import { isDevApp, isDevAppID, getProdAppID } from "../docIds/conversions"
|
import { isDevApp, isDevAppID, getProdAppID } from "../docIds/conversions"
|
||||||
import { App, Database } from "@budibase/types"
|
import { App, Database } from "@budibase/types"
|
||||||
import { getStartEndKeyURL } from "../docIds"
|
import { getStartEndKeyURL } from "../docIds"
|
||||||
|
@ -131,7 +131,7 @@ export async function getAppsByIDs(appIds: string[]) {
|
||||||
.filter(
|
.filter(
|
||||||
promise =>
|
promise =>
|
||||||
promise.status === "fulfilled" &&
|
promise.status === "fulfilled" &&
|
||||||
promise.value?.state !== AppState.INVALID
|
(promise.value as DeletedApp).state !== AppState.INVALID
|
||||||
)
|
)
|
||||||
.map(promise => (promise as PromiseFulfilledResult<App>).value)
|
.map(promise => (promise as PromiseFulfilledResult<App>).value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue