@giteeteam/apps-runtime-vm
Advanced tools
Comparing version 0.1.5 to 0.1.6
import { Context } from 'isolated-vm'; | ||
import type { RuntimeApis } from '../../types'; | ||
export declare const injectRuntimeApis: (context: Context, runtimeApis: RuntimeApis) => Promise<void>; | ||
export declare const injectAppRuntimeApis: (context: Context, runtimeApis?: RuntimeApis) => Promise<void>; |
@@ -6,18 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.injectAppRuntimeApis = exports.injectRuntimeApis = void 0; | ||
exports.injectRuntimeApis = void 0; | ||
const isolated_vm_1 = __importDefault(require("isolated-vm")); | ||
const logger_1 = __importDefault(require("./logger")); | ||
// TODO 根据插件类型注入不同的api | ||
// 插件runtime api | ||
const createAppRuntimeApis = () => { | ||
const logger = new logger_1.default(); | ||
const console = { | ||
debug: (data) => logger.debug(...data.copySync()), | ||
log: (data) => logger.log(...data.copySync()), | ||
info: (data) => logger.info(...data.copySync()), | ||
warn: (data) => logger.warn(...data.copySync()), | ||
error: (data) => logger.error(...data.copySync()), | ||
}; | ||
return { console }; | ||
}; | ||
// 注入单个方法 | ||
@@ -38,13 +24,4 @@ const injectApiFunctions = async (context, globalName, apiFunctions) => { | ||
const injectRuntimeApis = async (context, runtimeApis) => { | ||
const apiKeys = Object.keys(runtimeApis); | ||
for (let i = 0; i < apiKeys.length; ++i) { | ||
await injectApiFunctions(context, apiKeys[i], runtimeApis[apiKeys[i]]); | ||
} | ||
await Promise.all(Object.keys(runtimeApis).map(apiKey => injectApiFunctions(context, apiKey, runtimeApis[apiKey]))); | ||
}; | ||
exports.injectRuntimeApis = injectRuntimeApis; | ||
// 注入插件全局方法 | ||
const injectAppRuntimeApis = async (context, runtimeApis) => { | ||
const commonRuntimeApis = createAppRuntimeApis(); | ||
await (0, exports.injectRuntimeApis)(context, { ...commonRuntimeApis, ...runtimeApis }); | ||
}; | ||
exports.injectAppRuntimeApis = injectAppRuntimeApis; |
@@ -173,3 +173,3 @@ "use strict"; | ||
`, [isolated_vm_1.default, (fn, timeout) => void setTimeout(() => fn.applySync(), timeout), new isolated_vm_1.default.Reference(axios_1.default)]); | ||
await (0, api_1.injectAppRuntimeApis)(context, runtimeApis); | ||
await (0, api_1.injectRuntimeApis)(context, runtimeApis); | ||
return context; | ||
@@ -176,0 +176,0 @@ } |
@@ -12,4 +12,4 @@ export declare type Params = Record<string, any>; | ||
params?: Params; | ||
runtimeApis?: RuntimeApis; | ||
runtimeApis: RuntimeApis; | ||
timeout: number; | ||
} |
{ | ||
"name": "@giteeteam/apps-runtime-vm", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Giteeteam Apps Runtime VM", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "63aa645e12ebcd0519c98fcf46e5ad6338a79c07" | ||
"gitHead": "a404a1b964620a9c1147b0b464dddf02352a88c6" | ||
} |
17209
16
423