mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-30 16:54:57 +00:00
21 lines
956 B
TypeScript
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,
|
|
}
|
|
}
|