Files
metabuilder/frontends/nextjs/src/lib/db/lua-scripts/serialization/deserialize-lua-script.ts

21 lines
956 B
TypeScript

import type { LuaScript } from '../../types/level-types'
import { normalizeAllowedGlobals } from '../../lua/functions/sandbox/normalize-allowed-globals'
import { parseJsonArray } from './parse-json-array'
export function deserializeLuaScript(raw: Record<string, unknown>): LuaScript {
const parameters = parseJsonArray(raw.parameters)
const allowedGlobals = parseJsonArray(raw.allowedGlobals)
return {
id: String(raw.id),
name: String(raw.name),
description: typeof raw.description === 'string' ? raw.description : undefined,
code: String(raw.code),
parameters: parameters as Array<{ name: string; type: string }>,
returnType: typeof raw.returnType === 'string' ? raw.returnType : undefined,
isSandboxed: typeof raw.isSandboxed === 'boolean' ? raw.isSandboxed : true,
allowedGlobals: normalizeAllowedGlobals(allowedGlobals as string[]),
timeoutMs: typeof raw.timeoutMs === 'number' ? raw.timeoutMs : 5000,
}
}