UNPKG

@kubiklabs/wasmkit

Version:

Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.

58 lines (57 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WasmkitContext = void 0; const extenders_1 = require("./core/config/extenders"); const errors_1 = require("./core/errors"); const errors_list_1 = require("./core/errors-list"); const dsl_1 = require("./core/tasks/dsl"); class WasmkitContext { constructor() { this.tasksDSL = new dsl_1.TasksDSL(); this.extendersManager = new extenders_1.ExtenderManager(); this.loadedPlugins = []; this.configExtenders = []; } static isCreated() { const globalWithWasmkitContext = global; return globalWithWasmkitContext.__WasmkitContext !== undefined; } static createWasmkitContext() { if (this.isCreated()) { throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED); } const globalWithWasmkitContext = global; const ctx = new WasmkitContext(); globalWithWasmkitContext.__WasmkitContext = ctx; return ctx; } static getWasmkitContext() { const globalWithWasmkitContext = global; const ctx = globalWithWasmkitContext.__WasmkitContext; if (ctx === undefined) { throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED); } return ctx; } static deleteWasmkitContext() { // eslint-disable-next-line const globalAsAny = global; globalAsAny.__WasmkitContext = undefined; } setRuntimeEnv(env) { if (this.environment !== undefined) { throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.CONTEXT_PRE_ALREADY_DEFINED); } this.environment = env; } getRuntimeEnv() { if (this.environment === undefined) { throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.CONTEXT_PRE_NOT_DEFINED); } return this.environment; } setPluginAsLoaded(pluginName) { this.loadedPlugins.push(pluginName); } } exports.WasmkitContext = WasmkitContext;