UNPKG

@opra/common

Version:
69 lines (68 loc) 2.23 kB
import { omitUndefined } from '@jsopen/objects'; import { DocumentElement } from '../common/document-element.js'; import { DataType } from '../data-type/data-type.js'; /** * @class MQOperationResponse */ export class MQOperationResponse extends DocumentElement { channel; description; type; keyType; headers = []; designType; keyDesignType; constructor(owner, initArgs) { super(owner); this.channel = initArgs?.channel; this.description = initArgs?.description; if (initArgs?.type) { this.type = initArgs?.type instanceof DataType ? initArgs.type : this.owner.node.getDataType(initArgs.type); } else this.type = this.owner.node.getDataType('any'); if (initArgs?.keyType) { this.keyType = initArgs?.keyType instanceof DataType ? initArgs.keyType : this.owner.node.getDataType(initArgs.keyType); } this.designType = initArgs?.designType; this.keyDesignType = initArgs?.keyDesignType; } findHeader(paramName) { const paramNameLower = paramName.toLowerCase(); let prm; for (prm of this.headers) { if (typeof prm.name === 'string') { prm._nameLower = prm._nameLower || prm.name.toLowerCase(); if (prm._nameLower === paramNameLower) return prm; } if (prm.name instanceof RegExp && prm.name.test(paramName)) return prm; } } toJSON() { const out = omitUndefined({ description: this.description, channel: this.channel, type: this.type.name ? this.type.name : this.type.toJSON(), keyType: this.keyType ? this.keyType.name ? this.keyType.name : this.keyType.toJSON() : undefined, }); if (this.headers.length) { out.headers = []; for (const prm of this.headers) { out.headers.push(prm.toJSON()); } } return out; } }