UNPKG

truffle

Version:

Truffle - Simple development framework for Ethereum

1,148 lines (1,116 loc) 153 kB
#!/usr/bin/env node exports.id = 553; exports.ids = [553]; exports.modules = { /***/ 69203: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.configProps = exports.getInitialConfig = void 0; const path = __importStar(__webpack_require__(71017)); const provider_1 = __importDefault(__webpack_require__(509)); const getInitialConfig = ({ truffleDirectory, workingDirectory, network }) => { const truffle_directory = truffleDirectory || path.resolve(path.join(__dirname, "../")); const working_directory = workingDirectory || process.cwd(); return { truffle_directory, working_directory, network, networks: { dashboard: { network_id: "*", networkCheckTimeout: 120000, url: "http://localhost:24012/rpc", skipDryRun: true } }, verboseRpc: false, solidityLog: { displayPrefix: "", preventConsoleLogMigration: false }, debugGlobal: "debug", gas: null, gasPrice: null, maxFeePerGas: null, maxPriorityFeePerGas: null, type: undefined, from: null, confirmations: 0, timeoutBlocks: 0, production: false, skipDryRun: false, build: null, resolver: null, artifactor: null, quiet: false, dashboard: { host: "localhost", port: 24012, autoOpen: true, verbose: false }, ens: { enabled: false, registryAddress: undefined }, mocha: { bail: false, grep: null }, compilers: { solc: { settings: { //Note: The default solc version is *not* set here! //It's set in compilerSupplier/index.js in compile-solidity optimizer: { enabled: false, runs: 200 }, remappings: [] } }, vyper: { settings: {} } }, console: { require: null }, logger: console }; }; exports.getInitialConfig = getInitialConfig; const configProps = ({ configObject }) => { const resolveDirectory = (value) => path.resolve(configObject.working_directory, value); return { // These are already set. truffle_directory() { }, working_directory() { }, network() { }, networks() { }, verboseRpc() { }, solidityLog() { }, build() { }, resolver() { }, artifactor() { }, dashboard() { }, logger() { }, compilers() { }, ens() { }, console() { }, mocha() { }, quiet() { }, debugGlobal() { }, build_directory: { default: () => path.join(configObject.working_directory, "build"), transform: resolveDirectory }, contracts_directory: { default: () => path.join(configObject.working_directory, "contracts"), transform: resolveDirectory }, contracts_build_directory: { default: () => path.join(configObject.build_directory, "contracts"), transform: resolveDirectory }, migrations_directory: { default: () => path.join(configObject.working_directory, "migrations"), transform: resolveDirectory }, migrations_file_extension_regexp() { return /^\.(js|ts|es6?)$/; }, test_directory: { default: () => path.join(configObject.working_directory, "test"), transform: resolveDirectory }, test_file_extension_regexp() { return /.*\.(js|ts|es|es6|jsx|sol)$/; }, example_project_directory: { default: () => path.join(configObject.truffle_directory, "example"), transform: resolveDirectory }, network_id: { get() { try { return configObject.network_config.network_id; } catch (e) { return null; } }, set() { throw new Error("Do not set config.network_id. Instead, set config.networks and then config.networks[<network name>].network_id"); } }, network_config: { get() { const network = configObject.network; if (network === null || network === undefined) { throw new Error("Network not set. Cannot determine network to use."); } let config = configObject.networks[network]; if (config === null || config === undefined) { config = {}; } if (network === "dashboard") { const { host: configuredHost, port } = configObject.dashboard; const host = configuredHost === "0.0.0.0" ? "localhost" : configuredHost; const userOverrides = config; config = Object.assign(Object.assign({ network_id: "*", networkCheckTimeout: 120000 }, userOverrides), { url: `http://${host}:${port}/rpc`, skipDryRun: true }); } return config; }, set() { throw new Error("Don't set config.network_config. Instead, set config.networks with the desired values."); } }, from: { get() { try { return configObject.network_config.from; } catch (e) { return null; } }, set() { throw new Error("Don't set config.from directly. Instead, set config.networks and then config.networks[<network name>].from"); } }, gas: { get() { try { return configObject.network_config.gas; } catch (e) { return null; } }, set() { throw new Error("Don't set config.gas directly. Instead, set config.networks and then config.networks[<network name>].gas"); } }, gasPrice: { get() { try { return configObject.network_config.gasPrice; } catch (e) { return null; } }, set() { throw new Error("Don't set config.gasPrice directly. Instead, set config.networks and then config.networks[<network name>].gasPrice"); } }, maxFeePerGas: { get() { try { return configObject.network_config.maxFeePerGas; } catch (e) { return null; } }, set() { throw new Error("Don't set config.maxFeePerGas directly. Instead, set config.networks and then config.networks[<network name>].maxFeePerGas"); } }, maxPriorityFeePerGas: { get() { try { return configObject.network_config.maxPriorityFeePerGas; } catch (e) { return null; } }, set() { throw new Error("Don't set config.maxPriorityFeePerGas directly. Instead, set config.networks and then config.networks[<network name>].maxPriorityFeePerGas"); } }, type: { get() { try { return configObject.network_config.type; } catch (e) { return null; } }, set() { throw new Error("Don't set config.type directly. Instead, set config.networks and then config.networks[<network name>].type"); } }, provider: { get() { if (!configObject.network) { return null; } const options = configObject.network_config; options.verboseRpc = configObject.verboseRpc; options.events = configObject.events; return provider_1.default.create(options); }, set() { throw new Error("Don't set config.provider directly. Instead, set config.networks and then set config.networks[<network name>].provider"); } }, confirmations: { get() { try { return configObject.network_config.confirmations; } catch (e) { return 0; } }, set() { throw new Error("Don't set config.confirmations directly. Instead, set config.networks and then config.networks[<network name>].confirmations"); } }, production: { get() { try { return configObject.network_config.production; } catch (e) { return false; } }, set() { throw new Error("Don't set config.production directly. Instead, set config.networks and then config.networks[<network name>].production"); } }, timeoutBlocks: { get() { try { return configObject.network_config.timeoutBlocks; } catch (e) { return 0; } }, set() { throw new Error("Don't set config.timeoutBlocks directly. Instead, set config.networks and then config.networks[<network name>].timeoutBlocks"); } }, ensRegistry: { get() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; let networkConfig; try { networkConfig = configObject.network_config; } catch (_w) { //if this throws, then there's no network config, whatever } //prefer specific over generic. if there are two specific and they conflict, //or two generic and they conflict (w/o specific to shadow), throw error. //note: we treat null as a legitimate value here. let address; if ((networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registry) !== undefined && ((_a = networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.ens) === null || _a === void 0 ? void 0 : _a.registry) !== undefined) { throw new Error("<network_config>.registry and <network_config>.ens.registry both defined"); } let specificAddressInsideRegistry = ((_c = (_b = networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.ens) === null || _b === void 0 ? void 0 : _b.registry) === null || _c === void 0 ? void 0 : _c.address) !== undefined ? (_e = (_d = networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.ens) === null || _d === void 0 ? void 0 : _d.registry) === null || _e === void 0 ? void 0 : _e.address : (_f = networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registry) === null || _f === void 0 ? void 0 : _f.address; if (specificAddressInsideRegistry !== undefined || (networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registryAddress) !== undefined) { if (specificAddressInsideRegistry !== undefined && (networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registryAddress) !== undefined) { if (specificAddressInsideRegistry === (networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registryAddress)) { //if both are defined and they're equal, use either one address = specificAddressInsideRegistry; } else { //if both are defined but they're unequal, throw an error throw new Error("Conflicting values for registry address found in network config"); } } else { //if only one is defined, use that one address = specificAddressInsideRegistry !== undefined ? specificAddressInsideRegistry : networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.registryAddress; } } else if (((_h = (_g = configObject.ens) === null || _g === void 0 ? void 0 : _g.registry) === null || _h === void 0 ? void 0 : _h.address) !== undefined || ((_j = configObject.ens) === null || _j === void 0 ? void 0 : _j.registryAddress) !== undefined) { if (((_l = (_k = configObject.ens) === null || _k === void 0 ? void 0 : _k.registry) === null || _l === void 0 ? void 0 : _l.address) !== undefined && ((_m = configObject.ens) === null || _m === void 0 ? void 0 : _m.registryAddress) !== undefined) { if (((_p = (_o = configObject.ens) === null || _o === void 0 ? void 0 : _o.registry) === null || _p === void 0 ? void 0 : _p.address) === ((_q = configObject.ens) === null || _q === void 0 ? void 0 : _q.registryAddress)) { //if both are defined and they're equal, use either one address = (_s = (_r = configObject.ens) === null || _r === void 0 ? void 0 : _r.registry) === null || _s === void 0 ? void 0 : _s.address; } else { //if both are defined but they're unequal, throw an error throw new Error("Conflicting values for registry address found in project ens config"); } } else { //if only one is defined, use that one address = ((_u = (_t = configObject.ens) === null || _t === void 0 ? void 0 : _t.registry) === null || _u === void 0 ? void 0 : _u.address) || ((_v = configObject.ens) === null || _v === void 0 ? void 0 : _v.registryAddress); } } //otherwise, address is just undefined return { address }; }, set() { throw new Error("Don't set config.ensRegistry directly. Instead, set config.networks[<network name>].registry, or config.networks[<network name>].registryAddress, or config.ens.registry, or config.ens.registryAddress."); } } }; }; exports.configProps = configProps; //# sourceMappingURL=configDefaults.js.map /***/ }), /***/ 20553: /***/ (function(module, __unused_webpack_exports, __webpack_require__) { "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; const path_1 = __importDefault(__webpack_require__(71017)); const merge_1 = __importDefault(__webpack_require__(82492)); const find_up_1 = __importDefault(__webpack_require__(16948)); const conf_1 = __importDefault(__webpack_require__(19658)); const error_1 = __importDefault(__webpack_require__(73321)); const original_require_1 = __importDefault(__webpack_require__(44516)); const configDefaults_1 = __webpack_require__(69203); const events_1 = __webpack_require__(38279); const debug_1 = __importDefault(__webpack_require__(15158)); const debug = (0, debug_1.default)("config"); const DEFAULT_CONFIG_FILENAME = "truffle-config.js"; const BACKUP_CONFIG_FILENAME = "truffle.js"; // old config filename class TruffleConfig { constructor(truffleDirectory, workingDirectory, network) { this._deepCopy = ["compilers", "mocha", "dashboard", "networks"]; this._values = (0, configDefaults_1.getInitialConfig)({ truffleDirectory, workingDirectory, network }); this.events = new events_1.EventManager(this); const props = (0, configDefaults_1.configProps)({ configObject: this }); Object.entries(props).forEach(([propName, descriptor]) => this.addProp(propName, descriptor)); } addProp(propertyName, descriptor) { // possible property descriptors // // supports `default` and `transform` in addition to `get` and `set` // // default: specify function to retrieve default value (used by get) // transform: specify function to transform value when (used by set) const self = this; Object.defineProperty(this, propertyName, { get: descriptor.get || function () { // value is specified if (propertyName in self._values) { return self._values[propertyName]; } // default getter is specified if (descriptor.default) { return descriptor.default(); } // descriptor is a function return descriptor(); }, set: descriptor.set || function (value) { self._values[propertyName] = descriptor.transform ? descriptor.transform(value) : value; }, configurable: true, enumerable: true }); } normalize(obj) { const clone = {}; Object.keys(obj).forEach(key => { try { clone[key] = obj[key]; } catch (e) { // Do nothing with values that throw. } }); return clone; } with(obj) { //Normalized, or shallow clowning only copies an object's own enumerable //properties ignoring properties up the prototype chain const current = this.normalize(this); const normalized = this.normalize(obj); const newConfig = Object.assign(Object.create(TruffleConfig.prototype), current, normalized); this.events.updateSubscriberOptions(newConfig); return newConfig; } merge(obj) { const clone = this.normalize(obj); // Only set keys for values that don't throw. const propertyNames = Object.keys(obj); propertyNames.forEach(key => { try { if (typeof clone[key] === "object" && this._deepCopy.includes(key)) { this[key] = (0, merge_1.default)(this[key], clone[key]); } else { debug("setting key -- %o -- to -- %o", key, clone[key]); this[key] = clone[key]; } } catch (e) { // ignore } }); this.events.updateSubscriberOptions(this); return this; } static default() { return new TruffleConfig(); } static search(options = {}, filename) { const searchOptions = { cwd: options.working_directory || options.workingDirectory }; if (!filename) { const isWin = process.platform === "win32"; const defaultConfig = find_up_1.default.sync(DEFAULT_CONFIG_FILENAME, searchOptions); const backupConfig = find_up_1.default.sync(BACKUP_CONFIG_FILENAME, searchOptions); if (defaultConfig && backupConfig) { console.warn(`Warning: Both ${DEFAULT_CONFIG_FILENAME} and ${BACKUP_CONFIG_FILENAME} were found. Using ${DEFAULT_CONFIG_FILENAME}.`); return defaultConfig; } else if (backupConfig && !defaultConfig) { if (isWin) console.warn(`Warning: Please rename ${BACKUP_CONFIG_FILENAME} to ${DEFAULT_CONFIG_FILENAME} to ensure Windows compatibility.`); return backupConfig; } else { return defaultConfig; } } return find_up_1.default.sync(filename, searchOptions); } static detect(options = {}, filename) { debug("callling Config.detect with filename -- %o", filename); let configFile; const configPath = options.config; if (configPath) { configFile = path_1.default.isAbsolute(configPath) ? configPath : path_1.default.resolve(configPath); } else { configFile = TruffleConfig.search(options, filename); } if (!configFile) { throw new error_1.default("Could not find suitable configuration file."); } return TruffleConfig.load(configFile, options); } static load(file, options = {}) { debug("calling Config.load with file -- %o", file); const workingDirectory = options.config ? process.cwd() : path_1.default.dirname(path_1.default.resolve(file)); const config = new TruffleConfig(undefined, workingDirectory, undefined); const staticConfig = (0, original_require_1.default)(file); debug("the static config is -- %o", staticConfig); config.merge(staticConfig); config.merge(options); // When loading a user's config, ensure their subscribers are initialized config.events.updateSubscriberOptions(config); config.events.initializeUserSubscribers(config); return config; } static getUserConfig() { return new conf_1.default({ projectName: "truffle" }); } static getTruffleDataDirectory() { const conf = TruffleConfig.getUserConfig(); return path_1.default.dirname(conf.path); } } module.exports = TruffleConfig; //# sourceMappingURL=index.js.map /***/ }), /***/ 96053: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.DashboardMessageBusClient = void 0; const dashboard_message_bus_common_1 = __webpack_require__(75756); const connection_1 = __webpack_require__(83806); const delay_1 = __importDefault(__webpack_require__(65780)); const debug_1 = __importDefault(__webpack_require__(15158)); const lifecycle_1 = __webpack_require__(47993); const promise_tracker_1 = __webpack_require__(16164); const debug = (0, debug_1.default)(`dashboard-message-bus-client:client`); class DashboardMessageBusClient { get options() { return Object.assign({}, this._options); } constructor(options) { this._subscriptions = []; this._options = Object.assign({ host: "localhost", port: 24012, maxRetries: 1, retryDelayMsec: 100 }, (options !== null && options !== void 0 ? options : {})); const { host, port, publishPort, subscribePort } = this._options; this._publishConnection = new connection_1.DashboardMessageBusConnection({ host, port, publishPort, connectionType: "publish" }); this._subscribeConnection = new connection_1.DashboardMessageBusConnection({ host, port, subscribePort, connectionType: "subscribe" }); this._subscribeConnection.on("message", this._messageHandler.bind(this)); } ready() { return __awaiter(this, void 0, void 0, function* () { yield this._withRetriesAsync(() => __awaiter(this, void 0, void 0, function* () { Promise.all([ this._publishConnection.connect(), this._subscribeConnection.connect() ]); })); }); } publish(options) { return __awaiter(this, void 0, void 0, function* () { const { type, payload } = options; let message = (0, dashboard_message_bus_common_1.createMessage)(type, payload); try { yield this.ready(); const lifecycle = new lifecycle_1.PublishMessageLifecycle({ message, connection: this._publishConnection }); return yield this._withRetriesAsync((() => __awaiter(this, void 0, void 0, function* () { debug("publisher sending message %o", message); yield this._publishConnection.send(message); return lifecycle; })).bind(this)); } catch (err) { debug("sending message %o failed due to error %s", message, err); throw err; } }); } subscribe(options) { const subscription = new lifecycle_1.DashboardMessageBusSubscription(options); this._subscriptions.push(subscription); return subscription; } close(force = false) { return __awaiter(this, void 0, void 0, function* () { if (!force) { yield this.waitForOutstandingPromises(); } this._subscriptions.map(sub => sub._end()); this._subscriptions = []; yield Promise.all([ this._subscribeConnection.close(), this._publishConnection.close() ]); }); } waitForOutstandingPromises() { return __awaiter(this, void 0, void 0, function* () { yield (0, promise_tracker_1.waitForOutstandingPromises)({ target: this }); return; }); } _messageHandler(message) { this._subscriptions.map(sub => sub._evaluateMessage({ message, connection: this._subscribeConnection })); } _withRetriesAsync(f) { return __awaiter(this, void 0, void 0, function* () { const { maxRetries, retryDelayMsec } = this._options; for (let tryCount = 0; tryCount <= maxRetries; tryCount++) { try { const result = f.call(this); if (result.then) { // ensure any promise rejections are handled here so we count them as // failures to retry return yield result; } else { return result; } } catch (err) { if (tryCount < maxRetries) { debug("Attempt failed, %s of %s attempts remaining, delaying %s msec before retrying.", maxRetries - tryCount, maxRetries + 1, retryDelayMsec); yield (0, delay_1.default)(retryDelayMsec); debug("Retrying failed operation now"); } else { debug("Operation failed after %s attempts", tryCount); throw err; } } } }); } } exports.DashboardMessageBusClient = DashboardMessageBusClient; //# sourceMappingURL=client.js.map /***/ }), /***/ 83806: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.DashboardMessageBusConnection = void 0; const isomorphic_ws_1 = __importDefault(__webpack_require__(47030)); // must polyfill AbortController to use axios >=0.20.0, <=0.27.2 on node <= v14.x __webpack_require__(26426); const axios_1 = __importDefault(__webpack_require__(43306)); const dashboard_message_bus_common_1 = __webpack_require__(75756); const debug_1 = __importDefault(__webpack_require__(15158)); const errors_1 = __webpack_require__(25338); const tiny_typed_emitter_1 = __webpack_require__(12527); const promise_tracker_1 = __webpack_require__(16164); const delay_1 = __importDefault(__webpack_require__(65780)); const debug = (0, debug_1.default)("dashboard-message-bus-client:connection"); const debugMessage = (0, debug_1.default)("dashboard-message-bus-client:message"); class DashboardMessageBusConnection extends tiny_typed_emitter_1.TypedEmitter { constructor({ host, port, publishPort, subscribePort, connectionType: socketType }) { super(); this._host = host; this._port = port; this._publishPort = publishPort; this._subscribePort = subscribePort; this._connectionType = socketType; } get isConnected() { return this._socket && this._socket.readyState === isomorphic_ws_1.default.OPEN; } get isConnecting() { return this._socket && this._socket.readyState === isomorphic_ws_1.default.CONNECTING; } get isClosing() { return this._socket && this._socket.readyState === isomorphic_ws_1.default.CLOSING; } connect() { var _a; return __awaiter(this, void 0, void 0, function* () { if (this._socket) { switch (this._socket.readyState) { case isomorphic_ws_1.default.CONNECTING: debug("connect: %s already attempting to connect (readyState switch)", this._connectionType); yield (0, delay_1.default)(10); return this.connect(); case isomorphic_ws_1.default.OPEN: // we're already connected, just return debug("connect: %s already connected", this._connectionType); return; case isomorphic_ws_1.default.CLOSING: case isomorphic_ws_1.default.CLOSED: debug("connect: %s was previously connected but has been closed", this._connectionType); // already closed or on our way there, so we'll just recreate it in a // moment delete this._socket; } } try { if (this._connecting) { debug("connect: %s already attempting to connect (_connecting flag)", this._connectionType); yield (0, delay_1.default)(10); return this.connect(); } this._connecting = true; const port = yield this._getMessageBusPort(); const url = `ws://${this._host}:${port}`; debug("connect: %s is attempting to connect to %s", this._connectionType, url); this._socket = new isomorphic_ws_1.default(url); (_a = this._socket) === null || _a === void 0 ? void 0 : _a.addEventListener("message", ((event) => { if (typeof event.data !== "string") { event.data = event.data.toString(); } const message = (0, dashboard_message_bus_common_1.base64ToJson)(event.data); debugMessage("%s connection received message %o", this._connectionType, message); this.emit("message", message); }).bind(this)); // connecting // we now have a socket that's in the process of opening, so return a // promise that resolves when it opens, or fails to open const connectPromise = this._createEventWrapperPromise((resolve, reject) => { return { open: () => { var _a, _b; debug("connect: %s connection succeeded to url %s", this._connectionType, (_a = this._socket) === null || _a === void 0 ? void 0 : _a.url); if (this._connectionType === "subscribe") { (_b = this._socket) === null || _b === void 0 ? void 0 : _b.send("ready"); } resolve(); this._connecting = false; }, error: (event) => { var _a; debug("connect: %s connection to url %s failed due to error %s", this._connectionType, (_a = this._socket) === null || _a === void 0 ? void 0 : _a.url, event.error); reject(new errors_1.MessageBusConnectionError({ message: event.error.message, cause: event.error })); this._connecting = false; }, close: (event) => { var _a; debug("connect: %s connection to url %s closed before successfully connecting due to code %s and reason %s", this._connectionType, (_a = this._socket) === null || _a === void 0 ? void 0 : _a.url, event.code, event.reason); reject(new errors_1.MessageBusConnectionError({ message: `Socket connection closed with code '${event.code}' and reason '${event.reason}'` })); this._connecting = false; } }; }); let timedout = false; yield Promise.race([ connectPromise, () => __awaiter(this, void 0, void 0, function* () { yield (0, delay_1.default)(350); timedout = true; }) ]); if (timedout) { debug("connect: %s connection to url %s timed out", this._connectionType, url); } } catch (_b) { this._connecting = false; } }); } send(dataOrMessage) { var _a; return __awaiter(this, void 0, void 0, function* () { const encodedMessage = typeof dataOrMessage === "string" ? dataOrMessage : (0, dashboard_message_bus_common_1.jsonToBase64)(dataOrMessage); yield this.connect(); debug("send: %s connection sending %o", this._connectionType, (0, dashboard_message_bus_common_1.base64ToJson)(encodedMessage)); (_a = this._socket) === null || _a === void 0 ? void 0 : _a.send(encodedMessage); }); } close() { return __awaiter(this, void 0, void 0, function* () { if (!this._socket) { return; } if (this._socket.readyState <= isomorphic_ws_1.default.CLOSING) { const promise = this._createEventWrapperPromise((resolve, reject) => { return { error: (event) => { reject(event.error); }, close: () => { debug("%s connection closed", this._connectionType); resolve(); } }; }); this._socket.close(); return promise; } }); } _getMessageBusPort() { return __awaiter(this, void 0, void 0, function* () { if (this._connectionType === "subscribe" && this._subscribePort) { return this._subscribePort; } if (this._connectionType === "publish" && this._publishPort) { return this._publishPort; } // otherwise, fetch it from the server try { debug("_getMessageBusPort: %s connection attempting to fetch ports", this._connectionType); const { data } = yield axios_1.default.get(`http://${this._host}:${this._port}/ports`, { timeout: 350 }); const port = this._connectionType === "subscribe" ? data.subscribePort : data.publishPort; debug("_getMessageBusPort: %s connection will use port %s", this._connectionType, port); return port; } catch (err) { debug("_getMessageBusPort: failed fetching ports for %s connection due to error %s", this._connectionType, err); throw err; } }); } _createEventWrapperPromise(handlerFactory) { return new Promise(((resolve, reject) => { this._registerEventHandlers(handlerFactory.call(this, resolve, reject)); }).bind(this)); } _registerEventHandlers(handlers) { var _a; let wrappedHandlers = {}; for (const eventType in handlers) { wrappedHandlers[eventType] = ((...args) => { handlers[eventType].call(this, ...args); this._cleanUpEventHandlers(wrappedHandlers); }).bind(this); (_a = this._socket) === null || _a === void 0 ? void 0 : _a.addEventListener(eventType, wrappedHandlers[eventType]); } } _cleanUpEventHandlers(handlers) { var _a; for (const eventType in handlers) { (_a = this._socket) === null || _a === void 0 ? void 0 : _a.removeEventListener(eventType, handlers[eventType]); } } } __decorate([ promise_tracker_1.tracked ], DashboardMessageBusConnection.prototype, "send", null); exports.DashboardMessageBusConnection = DashboardMessageBusConnection; //# sourceMappingURL=index.js.map /***/ }), /***/ 25338: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.MessageBusConnectionError = exports.AlreadyRespondedError = void 0; class AlreadyRespondedError extends Error { constructor({ serviceBusMessage }) { super(`A response has already been sent for message id ${serviceBusMessage.id} of type "${serviceBusMessage.type}".`); } } exports.AlreadyRespondedError = AlreadyRespondedError; class MessageBusConnectionError extends Error { constructor({ message, cause }) { super(message); this.cause = cause; } toString() { return this.cause ? `${super.toString()}\ncaused by: ${this.cause.toString()}` : super.toString(); } } exports.MessageBusConnectionError = MessageBusConnectionError; //# sourceMappingURL=errors.js.map /***/ }), /***/ 19602: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", ({ value: true })); __exportStar(__webpack_require__(96053), exports); __exportStar(__webpack_require__(82118), exports); __exportStar(__webpack_require__(47993), exports); //# sourceMappingURL=index.js.map /***/ }), /***/ 47993: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", ({ value: true })); __exportStar(__webpack_require__(35933), exports); __exportStar(__webpack_require__(71033), exports); //# sourceMappingURL=index.js.map /***/ }), /***/ 35933: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.PublishMessageLifecycle = void 0; const dashboard_message_bus_common_1 = __webpack_require__(75756); const debug_1 = __importDefault(__webpack_require__(15158)); const debug = (0, debug_1.default)(`dashboard-message-bus-client:publish`); class PublishMessageLifecycle { constructor({ message, connection }) { this._responseReceived = false; this._invalidated = false; this._abandoned = false; this.message = message; this._connection = connection; this._messageHandler = this._messageHandler.bind(this); this.response = new Promise(resolve => { this._responsePromiseResolve = resolve; }); connection.on("message", this._messageHandler); } /** * Notify other potential subscribers of this message that it has been * invalidated, and they therefore should not respond. */ invalidate() { return __awaiter(this, void 0, void 0, function* () { if (this._abandoned || this._invalidated || this._responseReceived) { return; } this._invalidated = true; this._connection.off("message", this._messageHandler); /* * Resolving the response promise with `null` is the best of the bad options * when a message is invalidated * * Other options included rejecting with an error, and simply letting the * promise go unresolved. * * Letting the promise go unresolved is worst option, as it prevents the * `finally` block/handler from ever running. * * Rejecting with an error is maybe okay, but there's nothing to prompt the * consumer of this library to know that they'll need to catch this error or * else they'll encounter terminations due to unresolved promises. * * Returning null means that authors writing TS code against this library * will at least have some indicator that the message invalidation mechanism * exists, and they may need to write code to handle it. * */ this._responsePromiseResolve(null); yield this._connection.send((0, dashboard_message_bus_common_1.createMessage)(dashboard_message_bus_common_1.invalidateMessageType, this.message.id)); }); } /** * Stop waiting for the response to this message, but don't invalidate it, * either. */ abandon() { return __awaiter(this, void 0, void 0, function* () { if (this._abandoned || this._invalidated || this._responseReceived) { return; } this._abandoned = true; this._connection.off("message", this._messageHandler); /* * Resolving the response promise with `null` is the best of the bad options * when a message is invalidated * * Other options included rejecting with an error, and simply letting the * promise go unresolved. * * Letting the promise go unresolved is worst option, as it prevents the * `finally` block/handler from ever running. * * Rejecting with an error is maybe okay, but there's nothing to prompt the * consumer of this library to know that they'll need to catch this error or * else they'll encounter terminations due to unresolved promises. * * Returning null means that authors writing TS code against this library * will at least have some indicator that the message invalidation mechanism * exists, and they may need to write code to handle it. * */ this._responsePromiseResolve(null); }); } _messageHandler(response) { if (response.id === this.message.id) { this._respons