Revert changes to updateAppPackage and attempt to do it another way

This commit is contained in:
Andrew Kingston 2025-03-13 11:37:02 +00:00
parent 3d2f75d00d
commit 9059cf83c5
No known key found for this signature in database
1 changed files with 22 additions and 26 deletions

View File

@ -199,13 +199,10 @@ async function addSampleDataScreen() {
} }
async function addSampleDataNavLinks() { async function addSampleDataNavLinks() {
const appId = context.getAppId() const db = context.getAppDB()
if (!appId) { let app = await sdk.applications.metadata.get()
throw "Missing app ID"
}
const addLinks = (app: App) => {
if (!app.navigation) { if (!app.navigation) {
return app return
} }
if (!app.navigation.links) { if (!app.navigation.links) {
app.navigation.links = [] app.navigation.links = []
@ -216,9 +213,11 @@ async function addSampleDataNavLinks() {
type: "link", type: "link",
roleId: roles.BUILTIN_ROLE_IDS.BASIC, roleId: roles.BUILTIN_ROLE_IDS.BASIC,
}) })
return app
} await db.put(app)
await updateAppPackage(addLinks, appId)
// remove any cached metadata, so that it will be updated
await cache.app.invalidateAppMetadata(app.appId)
} }
export const addSampleData = async ( export const addSampleData = async (
@ -854,20 +853,17 @@ export async function duplicateApp(
// which is required to update anything deeper than the top level without // which is required to update anything deeper than the top level without
// overwriting more than intended. // overwriting more than intended.
export async function updateAppPackage( export async function updateAppPackage(
update: Partial<App> | ((app: App) => App), appPackage: Partial<App>,
appId: string appId: string
) { ) {
return context.doInAppContext(appId, async () => { return context.doInAppContext(appId, async () => {
const db = context.getAppDB() const db = context.getAppDB()
const application = await sdk.applications.metadata.get() const application = await sdk.applications.metadata.get()
const newAppPackage: App = const newAppPackage: App = { ...application, ...appPackage }
typeof update === "function" if (appPackage._rev !== application._rev) {
? update(application)
: { ...application, ...update }
// Ensure our rev stays the same
newAppPackage._rev = application._rev newAppPackage._rev = application._rev
}
// the locked by property is attached by server but generated from // the locked by property is attached by server but generated from
// Redis, shouldn't ever store it // Redis, shouldn't ever store it