Finishing link up of logs.

This commit is contained in:
mike12345567 2025-01-16 15:48:49 +00:00
parent 28958f5a1c
commit d3a2306787
3 changed files with 11 additions and 4 deletions

View File

@ -12,7 +12,7 @@
decodeJSBinding, decodeJSBinding,
encodeJSBinding, encodeJSBinding,
processObjectSync, processObjectSync,
processStringSync, processStringWithLogsSync,
} from "@budibase/string-templates" } from "@budibase/string-templates"
import { readableToRuntimeBinding } from "@/dataBinding" import { readableToRuntimeBinding } from "@/dataBinding"
import CodeEditor from "../CodeEditor/CodeEditor.svelte" import CodeEditor from "../CodeEditor/CodeEditor.svelte"
@ -41,6 +41,7 @@
InsertAtPositionFn, InsertAtPositionFn,
JSONValue, JSONValue,
} from "@budibase/types" } from "@budibase/types"
import type { Log } from "@budibase/string-templates"
import type { CompletionContext } from "@codemirror/autocomplete" import type { CompletionContext } from "@codemirror/autocomplete"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -66,6 +67,7 @@
let insertAtPos: InsertAtPositionFn | undefined let insertAtPos: InsertAtPositionFn | undefined
let targetMode: BindingMode | null = null let targetMode: BindingMode | null = null
let expressionResult: string | undefined let expressionResult: string | undefined
let expressionLogs: Log[] | undefined
let expressionError: string | undefined let expressionError: string | undefined
let evaluating = false let evaluating = false
@ -157,7 +159,7 @@
(expression: string | null, context: any, snippets: Snippet[]) => { (expression: string | null, context: any, snippets: Snippet[]) => {
try { try {
expressionError = undefined expressionError = undefined
expressionResult = processStringSync( const output = processStringWithLogsSync(
expression || "", expression || "",
{ {
...context, ...context,
@ -167,6 +169,8 @@
noThrow: false, noThrow: false,
} }
) )
expressionResult = output.result
expressionLogs = output.logs
} catch (err: any) { } catch (err: any) {
expressionResult = undefined expressionResult = undefined
expressionError = err expressionError = err
@ -421,6 +425,7 @@
<EvaluationSidePanel <EvaluationSidePanel
{expressionResult} {expressionResult}
{expressionError} {expressionError}
{expressionLogs}
{evaluating} {evaluating}
expression={editorValue ? editorValue : ""} expression={editorValue ? editorValue : ""}
/> />

View File

@ -4,20 +4,21 @@
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import { UserScriptError } from "@budibase/string-templates" import { UserScriptError } from "@budibase/string-templates"
import type { Log } from "@budibase/string-templates"
import type { JSONValue } from "@budibase/types" import type { JSONValue } from "@budibase/types"
// this can be essentially any primitive response from the JS function // this can be essentially any primitive response from the JS function
export let expressionResult: JSONValue | undefined = undefined export let expressionResult: JSONValue | undefined = undefined
export let expressionError: string | undefined = undefined export let expressionError: string | undefined = undefined
export let expressionLogs: Log[] = []
export let evaluating = false export let evaluating = false
export let expression: string | null = null export let expression: string | null = null
export let logging: { log: string; line?: number }[] = []
$: error = expressionError != null $: error = expressionError != null
$: empty = expression == null || expression?.trim() === "" $: empty = expression == null || expression?.trim() === ""
$: success = !error && !empty $: success = !error && !empty
$: highlightedResult = highlight(expressionResult) $: highlightedResult = highlight(expressionResult)
$: highlightedLogs = logging.map(l => ({ $: highlightedLogs = expressionLogs.map(l => ({
log: highlight(l.log), log: highlight(l.log),
line: l.line, line: l.line,
})) }))

View File

@ -18,6 +18,7 @@ import manifest from "./manifest.json"
import { Log, ProcessOptions } from "./types" import { Log, ProcessOptions } from "./types"
import { UserScriptError } from "./errors" import { UserScriptError } from "./errors"
export type { Log } from "./types"
export { helpersToRemoveForJs, getJsHelperList } from "./helpers/list" export { helpersToRemoveForJs, getJsHelperList } from "./helpers/list"
export { FIND_ANY_HBS_REGEX } from "./utilities" export { FIND_ANY_HBS_REGEX } from "./utilities"
export { setJSRunner, setOnErrorLog } from "./helpers/javascript" export { setJSRunner, setOnErrorLog } from "./helpers/javascript"