UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

103 lines 3.06 kB
// SPDX-License-Identifier: Apache-2.0 export class SimpleConfigSourceFixture { name; ordinal; prefix; backend; _properties; // used for testing to fake a refresh props2 = new Map(); constructor(name, ordinal, prefix, backend, _properties = new Map()) { this.name = name; this.ordinal = ordinal; this.prefix = prefix; this.backend = backend; this._properties = _properties; } asBoolean(key) { const value = this._properties.get(key); if (value === null || value === undefined || typeof value !== 'string') { return undefined; } return value.toLowerCase() === 'true'; } asNumber(key) { const value = this._properties.get(key); if (value === null || value === undefined) { return undefined; } return Number(value); } asObject(cls, key) { const value = this._properties.get(key ?? ''); if (!value) { return undefined; } try { const parsedValue = JSON.parse(value); if (typeof parsedValue !== 'object' || parsedValue === null) { return undefined; } // Create a new instance and assign properties manually const instance = new cls(); Object.assign(instance, parsedValue); return instance; } catch { return undefined; } } asObjectArray(cls, key) { const value = this._properties.get(key ?? ''); if (!value) { return undefined; } try { const parsedValue = JSON.parse(value); if (!Array.isArray(parsedValue)) { return undefined; } return parsedValue .filter(item => typeof item === 'object' && item !== null) .map(item => { const instance = new cls(); Object.assign(instance, item); return instance; }); } catch { return undefined; } } asString(key) { const value = this._properties.get(key); if (value === null || value === undefined || typeof value !== 'string') { return undefined; } return value; } asStringArray(key) { const value = this._properties.get(key); if (value === null || value === undefined) { return undefined; } const parsedValue = JSON.parse(value); if (!Array.isArray(parsedValue) || parsedValue.length === 0 || typeof parsedValue[0] !== 'string') { return undefined; } return parsedValue; } async load() { } properties() { return this._properties; } propertyNames() { return new Set(this._properties.keys()); } async refresh() { this._properties = this.props2; } } //# sourceMappingURL=simple-config-source.fixture.js.map