/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import 'ses'; export interface JSRunnerOptions { timeoutMs?: number; globals?: Record; version?: string; /** * Enable RunJS template compatibility preprocessing for `{{ ... }}`. * When enabled (or falling back to version default), * the code will be rewritten to call `ctx.resolveJsonTemplate(...)` at runtime. */ preprocessTemplates?: boolean; } /** * Decide whether RunJS `{{ ... }}` compatibility preprocessing should run. * * Priority: * 1. Explicit `preprocessTemplates` option always wins. * 2. Otherwise, `version === 'v2'` disables preprocessing. * 3. Fallback keeps v1-compatible behavior (enabled). */ export declare function shouldPreprocessRunJSTemplates(options?: Pick): boolean; export declare const RUNJS_ALLOWED_BARE_GLOBAL_NAMES: readonly ["ctx", "console", "window", "document", "navigator", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "Array", "ArrayBuffer", "BigInt", "BigInt64Array", "BigUint64Array", "Boolean", "DataView", "Date", "Error", "EvalError", "FinalizationRegistry", "Float32Array", "Float64Array", "Int8Array", "Int16Array", "Int32Array", "Map", "Math", "Number", "Object", "Promise", "Proxy", "RangeError", "ReferenceError", "Reflect", "RegExp", "Set", "String", "Symbol", "SyntaxError", "TypeError", "URIError", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "WeakMap", "WeakRef", "WeakSet", "JSON", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isFinite", "isNaN", "parseFloat", "parseInt", "undefined", "NaN", "Infinity", "fetch", "localStorage", "sessionStorage", "XMLHttpRequest", "WebSocket", "Worker", "SharedWorker", "ServiceWorker", "BroadcastChannel", "EventSource", "indexedDB", "caches", "Function", "eval", "globalThis", "Intl", "Blob", "URL", "location"]; export declare class JSRunner { private globals; private timeoutMs; constructor(options?: JSRunnerOptions); /** * 注册单个变量或函数 */ register(name: string, value: any): void; /** * 异步运行代码,带错误处理和超时机制 */ run(code: string): Promise<{ success: boolean; value?: any; error?: any; timeout?: boolean; }>; }