raw app improvements

This commit is contained in:
Ruben Fiszel
2026-01-20 08:37:11 +00:00
parent c143e78d7f
commit bb22fcb3a4
6 changed files with 47 additions and 5 deletions
+2
View File
@@ -35,6 +35,8 @@ function respecializeFields(fields: Record<string, any>) {
if (typeof v == "object") {
if (v.value !== undefined) {
fields[k] = { value: v.value, type: "static" };
} else if (v.ctx !== undefined) {
fields[k] = { ctx: v.ctx, type: "ctx" };
} else if (v.expr !== undefined) {
fields[k] = {
expr: v.expr,
+6 -2
View File
@@ -28,7 +28,7 @@ import * as wmill from "../../../gen/services.gen.ts";
import { resolveWorkspace } from "../../core/context.ts";
import { requireLogin } from "../../core/auth.ts";
import { GLOBAL_CONFIG_OPT } from "../../core/conf.ts";
import { replaceInlineScripts } from "./app.ts";
import { replaceInlineScripts, repopulateFields } from "./app.ts";
import { Runnable } from "./metadata.ts";
import {
APP_BACKEND_FOLDER,
@@ -1439,6 +1439,7 @@ async function loadRunnables(): Promise<Record<string, Runnable>> {
convertRunnablesToApiFormat(runnables);
replaceInlineScripts(runnables, backendPath + SEP, true);
repopulateFields(runnables);
return runnables;
} catch (error: any) {
@@ -1462,11 +1463,14 @@ async function executeRunnable(
force_viewer_allow_user_resources: [],
};
// Handle static fields
// Handle fields (static, ctx, user)
if (runnable.fields) {
for (const [key, field] of Object.entries(runnable.fields)) {
if (field?.type === "static") {
requestBody.force_viewer_static_fields[key] = field.value;
} else if (field?.type === "ctx" && field?.ctx) {
// Convert ctx fields to $ctx:property format for backend resolution
requestBody.args[key] = `$ctx:${field.ctx}`;
}
if (field?.type === "user" && field?.allowUserResources) {
requestBody.force_viewer_allow_user_resources.push(key);
+28
View File
@@ -932,6 +932,29 @@ function ZipFSElement(
};
}
// Helper to simplify fields for YAML output
// { type: 'static', value: X } -> { value: X }
// { type: 'ctx', ctx: X } -> { ctx: X }
function simplifyFields(fields: Record<string, any> | undefined) {
if (!fields) return undefined;
const simplified: Record<string, any> = {};
for (const [k, v] of Object.entries(fields)) {
if (typeof v === "object" && v !== null) {
if (v.type === "static" && v.value !== undefined) {
simplified[k] = { value: v.value };
} else if (v.type === "ctx" && v.ctx !== undefined) {
simplified[k] = { ctx: v.ctx };
} else {
// Keep other field types as-is
simplified[k] = v;
}
} else {
simplified[k] = v;
}
}
return simplified;
}
// Yield each runnable as a separate YAML file in the backend folder
// For inline scripts, simplify the YAML - inlineScript is not needed since
// content/lock/language can be derived from sibling files
@@ -969,6 +992,11 @@ function ZipFSElement(
simplifiedRunnable = runnableObj;
}
// Simplify fields for cleaner YAML output
if (simplifiedRunnable.fields) {
simplifiedRunnable.fields = simplifyFields(simplifiedRunnable.fields);
}
yield {
isDirectory: false,
path: path.join(