diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index 830acc55bf..660d35c29d 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -208,9 +208,8 @@ export async function fetchAppDefinition( export async function fetchAppPackage( ctx: UserCtx ) { - const db = context.getAppDB() const appId = context.getAppId() - let application = await db.get(DocumentType.APP_METADATA) + const application = await sdk.appMetadata.get() const layouts = await getLayouts() let screens = await getScreens() const license = await licensing.cache.getCachedLicense() @@ -315,7 +314,7 @@ async function performAppCreate(ctx: UserCtx) { // If we used a template or imported an app there will be an existing doc. // Fetch and migrate some metadata from the existing app. try { - const existing: App = await db.get(DocumentType.APP_METADATA) + const existing = await sdk.appMetadata.get() const keys: (keyof App)[] = [ "_rev", "navigation", @@ -489,8 +488,7 @@ export async function update( export async function updateClient(ctx: UserCtx) { // Get current app version - const db = context.getAppDB() - const application = await db.get(DocumentType.APP_METADATA) + const application = await sdk.appMetadata.get() const currentVersion = application.version let manifest @@ -518,8 +516,7 @@ export async function updateClient(ctx: UserCtx) { export async function revertClient(ctx: UserCtx) { // Check app can be reverted - const db = context.getAppDB() - const application = await db.get(DocumentType.APP_METADATA) + const application = await sdk.appMetadata.get() if (!application.revertableVersion) { ctx.throw(400, "There is no version to revert to") } @@ -577,7 +574,7 @@ async function destroyApp(ctx: UserCtx) { const db = dbCore.getDB(devAppId) // standard app deletion flow - const app = await db.get(DocumentType.APP_METADATA) + const app = await sdk.appMetadata.get() const result = await db.destroy() await quotas.removeApp() await events.app.deleted(app) @@ -728,7 +725,7 @@ export async function updateAppPackage( ) { return context.doInAppContext(appId, async () => { const db = context.getAppDB() - const application = await db.get(DocumentType.APP_METADATA) + const application = await sdk.appMetadata.get() const newAppPackage: App = { ...application, ...appPackage } if (appPackage._rev !== application._rev) { @@ -754,7 +751,7 @@ export async function setRevertableVersion( return } const db = context.getAppDB() - const app = await db.get(DocumentType.APP_METADATA) + const app = await sdk.appMetadata.get() app.revertableVersion = ctx.request.body.revertableVersion await db.put(app) @@ -763,7 +760,7 @@ export async function setRevertableVersion( async function migrateAppNavigation() { const db = context.getAppDB() - const existing: App = await db.get(DocumentType.APP_METADATA) + const existing = await sdk.appMetadata.get() const layouts: Layout[] = await getLayouts() const screens: Screen[] = await getScreens() diff --git a/packages/server/src/sdk/app/appMetadata/index.ts b/packages/server/src/sdk/app/appMetadata/index.ts new file mode 100644 index 0000000000..267899a214 --- /dev/null +++ b/packages/server/src/sdk/app/appMetadata/index.ts @@ -0,0 +1,5 @@ +import * as metadata from "./metadata" + +export default { + ...metadata, +} diff --git a/packages/server/src/sdk/app/appMetadata/metadata.ts b/packages/server/src/sdk/app/appMetadata/metadata.ts new file mode 100644 index 0000000000..78d2a040b9 --- /dev/null +++ b/packages/server/src/sdk/app/appMetadata/metadata.ts @@ -0,0 +1,8 @@ +import { context, DocumentType } from "@budibase/backend-core" +import { App } from "@budibase/types" + +export async function get() { + const db = context.getAppDB() + const application = await db.get(DocumentType.APP_METADATA) + return application +} diff --git a/packages/server/src/sdk/index.ts b/packages/server/src/sdk/index.ts index a871546b60..44df8b50fb 100644 --- a/packages/server/src/sdk/index.ts +++ b/packages/server/src/sdk/index.ts @@ -11,6 +11,7 @@ import { default as plugins } from "./plugins" import * as views from "./app/views" import * as permissions from "./app/permissions" import * as rowActions from "./app/rowActions" +import { default as appMetadata } from "./app/appMetadata" const sdk = { backups, @@ -26,6 +27,7 @@ const sdk = { permissions, links, rowActions, + appMetadata, } // default export for TS